withholding tax
This commit is contained in:
@ -3,8 +3,7 @@
|
||||
namespace App\Abstracts;
|
||||
|
||||
use App\Abstracts\Model;
|
||||
use App\Models\Banking\Transaction;
|
||||
use App\Models\Setting\Currency;
|
||||
use App\Models\Setting\Tax;
|
||||
use App\Traits\Currencies;
|
||||
use App\Traits\DateTime;
|
||||
use App\Traits\Media;
|
||||
@ -159,8 +158,14 @@ abstract class DocumentModel extends Model
|
||||
{
|
||||
$amount = $this->amount;
|
||||
|
||||
$this->totals->where('code', 'tax')->each(function ($tax) use(&$amount) {
|
||||
$amount -= $tax->amount;
|
||||
$this->totals->where('code', 'tax')->each(function ($total) use(&$amount) {
|
||||
$tax = Tax::name($total->name)->first();
|
||||
|
||||
if (!empty($tax) && ($tax->type == 'withholding')) {
|
||||
return;
|
||||
}
|
||||
|
||||
$amount -= $total->amount;
|
||||
});
|
||||
|
||||
return $amount;
|
||||
|
@ -25,6 +25,7 @@ class Taxes extends Controller
|
||||
'fixed' => trans('taxes.fixed'),
|
||||
'normal' => trans('taxes.normal'),
|
||||
'inclusive' => trans('taxes.inclusive'),
|
||||
'withholding' => trans('taxes.withholding'),
|
||||
'compound' => trans('taxes.compound'),
|
||||
];
|
||||
|
||||
@ -52,6 +53,7 @@ class Taxes extends Controller
|
||||
'fixed' => trans('taxes.fixed'),
|
||||
'normal' => trans('taxes.normal'),
|
||||
'inclusive' => trans('taxes.inclusive'),
|
||||
'withholding' => trans('taxes.withholding'),
|
||||
'compound' => trans('taxes.compound'),
|
||||
];
|
||||
|
||||
@ -99,6 +101,7 @@ class Taxes extends Controller
|
||||
'fixed' => trans('taxes.fixed'),
|
||||
'normal' => trans('taxes.normal'),
|
||||
'inclusive' => trans('taxes.inclusive'),
|
||||
'withholding' => trans('taxes.withholding'),
|
||||
'compound' => trans('taxes.compound'),
|
||||
];
|
||||
|
||||
|
@ -87,9 +87,23 @@ class CreateBillItem extends Job
|
||||
|
||||
$item_tax_total += $tax_amount;
|
||||
|
||||
break;
|
||||
case 'withholding':
|
||||
$tax_amount = 0 - $item_discounted_amount * ($tax->rate / 100);
|
||||
|
||||
$item_taxes[] = [
|
||||
'company_id' => $this->bill->company_id,
|
||||
'bill_id' => $this->bill->id,
|
||||
'tax_id' => $tax_id,
|
||||
'name' => $tax->name,
|
||||
'amount' => $tax_amount,
|
||||
];
|
||||
|
||||
$item_tax_total += $tax_amount;
|
||||
|
||||
break;
|
||||
default:
|
||||
$tax_amount = ($item_discounted_amount / 100) * $tax->rate;
|
||||
$tax_amount = $item_discounted_amount * ($tax->rate / 100);
|
||||
|
||||
$item_taxes[] = [
|
||||
'company_id' => $this->bill->company_id,
|
||||
@ -167,7 +181,7 @@ class CreateBillItem extends Job
|
||||
|
||||
foreach ($item_taxes as $item_tax) {
|
||||
$item_tax['bill_item_id'] = $bill_item->id;
|
||||
$item_tax['amount'] = round($item_tax['amount'], $precision);
|
||||
$item_tax['amount'] = round(abs($item_tax['amount']), $precision);
|
||||
|
||||
BillItemTax::create($item_tax);
|
||||
}
|
||||
|
@ -3,7 +3,6 @@
|
||||
namespace App\Jobs\Purchase;
|
||||
|
||||
use App\Abstracts\Job;
|
||||
use App\Models\Purchase\Bill;
|
||||
use App\Models\Purchase\BillTotal;
|
||||
use App\Traits\Currencies;
|
||||
use App\Traits\DateTime;
|
||||
@ -96,7 +95,7 @@ class CreateBillItemsAndTotals extends Job
|
||||
'bill_id' => $this->bill->id,
|
||||
'code' => 'tax',
|
||||
'name' => $tax['name'],
|
||||
'amount' => round($tax['amount'], $precision),
|
||||
'amount' => round(abs($total['amount']), $precision),
|
||||
'sort_order' => $sort_order,
|
||||
]);
|
||||
|
||||
@ -117,7 +116,7 @@ class CreateBillItemsAndTotals extends Job
|
||||
$total['code'] = 'extra';
|
||||
}
|
||||
|
||||
$total['amount'] = round($total['amount'], $precision);
|
||||
$total['amount'] = round(abs($total['amount']), $precision);
|
||||
|
||||
BillTotal::create($total);
|
||||
|
||||
|
@ -87,9 +87,23 @@ class CreateInvoiceItem extends Job
|
||||
|
||||
$item_tax_total += $tax_amount;
|
||||
|
||||
break;
|
||||
case 'withholding':
|
||||
$tax_amount = 0 - $item_discounted_amount * ($tax->rate / 100);
|
||||
|
||||
$item_taxes[] = [
|
||||
'company_id' => $this->invoice->company_id,
|
||||
'invoice_id' => $this->invoice->id,
|
||||
'tax_id' => $tax_id,
|
||||
'name' => $tax->name,
|
||||
'amount' => $tax_amount,
|
||||
];
|
||||
|
||||
$item_tax_total += $tax_amount;
|
||||
|
||||
break;
|
||||
default:
|
||||
$tax_amount = ($item_discounted_amount / 100) * $tax->rate;
|
||||
$tax_amount = $item_discounted_amount * ($tax->rate / 100);
|
||||
|
||||
$item_taxes[] = [
|
||||
'company_id' => $this->invoice->company_id,
|
||||
@ -167,7 +181,7 @@ class CreateInvoiceItem extends Job
|
||||
|
||||
foreach ($item_taxes as $item_tax) {
|
||||
$item_tax['invoice_item_id'] = $invoice_item->id;
|
||||
$item_tax['amount'] = round($item_tax['amount'], $precision);
|
||||
$item_tax['amount'] = round(abs($item_tax['amount']), $precision);
|
||||
|
||||
InvoiceItemTax::create($item_tax);
|
||||
}
|
||||
|
@ -95,7 +95,7 @@ class CreateInvoiceItemsAndTotals extends Job
|
||||
'invoice_id' => $this->invoice->id,
|
||||
'code' => 'tax',
|
||||
'name' => $tax['name'],
|
||||
'amount' => round($tax['amount'], $precision),
|
||||
'amount' => round(abs($tax['amount']), $precision),
|
||||
'sort_order' => $sort_order,
|
||||
]);
|
||||
|
||||
@ -116,7 +116,7 @@ class CreateInvoiceItemsAndTotals extends Job
|
||||
$total['code'] = 'extra';
|
||||
}
|
||||
|
||||
$total['amount'] = round($total['amount'], $precision);
|
||||
$total['amount'] = round(abs($total['amount']), $precision);
|
||||
|
||||
InvoiceTotal::create($total);
|
||||
|
||||
|
@ -54,6 +54,50 @@ class Tax extends Model
|
||||
return $query->where('rate', '=', $rate);
|
||||
}
|
||||
|
||||
public function scopeNotRate($query, $rate)
|
||||
{
|
||||
return $query->where('rate', '<>', $rate);
|
||||
}
|
||||
|
||||
public function scopeType($query, $types)
|
||||
{
|
||||
if (empty($types)) {
|
||||
return $query;
|
||||
}
|
||||
|
||||
return $query->whereIn($this->table . '.type', (array) $types);
|
||||
}
|
||||
|
||||
public function scopeFixed($query)
|
||||
{
|
||||
return $query->where($this->table . '.type', '=', 'fixed');
|
||||
}
|
||||
|
||||
public function scopeNormal($query)
|
||||
{
|
||||
return $query->where($this->table . '.type', '=', 'normal');
|
||||
}
|
||||
|
||||
public function scopeInclusive($query)
|
||||
{
|
||||
return $query->where($this->table . '.type', '=', 'inclusive');
|
||||
}
|
||||
|
||||
public function scopeCompound($query)
|
||||
{
|
||||
return $query->where($this->table . '.type', '=', 'compound');
|
||||
}
|
||||
|
||||
public function scopeWithholding($query)
|
||||
{
|
||||
return $query->where($this->table . '.type', '=', 'withholding');
|
||||
}
|
||||
|
||||
public function scopeNotWithholding($query)
|
||||
{
|
||||
return $query->where($this->table . '.type', '<>', 'withholding');
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert rate to double.
|
||||
*
|
||||
|
@ -32,7 +32,7 @@ class TaxSummary extends Report
|
||||
|
||||
public function setTables()
|
||||
{
|
||||
$taxes = Tax::enabled()->where('rate', '<>', '0')->orderBy('name')->pluck('name')->toArray();
|
||||
$taxes = Tax::enabled()->notWithholding()->notRate(0)->orderBy('name')->pluck('name')->toArray();
|
||||
|
||||
$this->tables = array_combine($taxes, $taxes);
|
||||
}
|
||||
|
Reference in New Issue
Block a user