| Server IP : 103.161.17.216 / Your IP : 216.73.216.1 Web Server : nginx/1.18.0 System : Linux tipsysaigoncharming 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64 User : www-data ( 33) PHP Version : 7.4.3-4ubuntu2.29 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare, MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : ON Directory : /var/www/app.ansachsongkhoe.net/app/ |
Upload File : |
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
class TaxRate extends Model
{
use SoftDeletes;
/**
* The attributes that should be mutated to dates.
*
* @var array
*/
/**
* The attributes that aren't mass assignable.
*
* @var array
*/
protected $guarded = ['id'];
/**
* Return list of tax rate dropdown for a business
*
* @param $business_id int
* @param $prepend_none = true (boolean)
* @param $include_attributes = false (boolean)
*
* @return array['tax_rates', 'attributes']
*/
public static function forBusinessDropdown(
$business_id,
$prepend_none = true,
$include_attributes = false,
$exclude_for_tax_group = true
) {
$all_taxes = TaxRate::where('business_id', $business_id);
if ($exclude_for_tax_group) {
$all_taxes->ExcludeForTaxGroup();
}
$result = $all_taxes->get();
$tax_rates = $result->pluck('name', 'id');
//Prepend none
if ($prepend_none) {
$tax_rates = $tax_rates->prepend(__('lang_v1.none'), '');
}
//Add tax attributes
$tax_attributes = null;
if ($include_attributes) {
$tax_attributes = collect($result)->mapWithKeys(function ($item) {
return [$item->id => ['data-rate' => $item->amount]];
})->all();
}
$output = ['tax_rates' => $tax_rates, 'attributes' => $tax_attributes];
return $output;
}
/**
* Return list of tax rate for a business
*
* @return array
*/
public static function forBusiness($business_id)
{
$tax_rates = TaxRate::where('business_id', $business_id)
->select(['id', 'name', 'amount'])
->get()
->toArray();
return $tax_rates;
}
/**
* Return list of tax rates associated with the group_tax
*
* @return object
*/
public function sub_taxes()
{
return $this->belongsToMany(\App\TaxRate::class, 'group_sub_taxes', 'group_tax_id', 'tax_id');
}
/**
* Return list of group taxes for a business
*
* @return array
*/
public static function groupTaxes($business_id)
{
$tax_rates = TaxRate::where('business_id', $business_id)
->where('is_tax_group', 1)
->with(['sub_taxes'])
->get();
return $tax_rates;
}
public function scopeExcludeForTaxGroup($query)
{
return $query->where('for_tax_group', 0);
}
}