withholding tax
This commit is contained in:
parent
2b0c2e4846
commit
010d0bb3fb
@ -3,8 +3,7 @@
|
|||||||
namespace App\Abstracts;
|
namespace App\Abstracts;
|
||||||
|
|
||||||
use App\Abstracts\Model;
|
use App\Abstracts\Model;
|
||||||
use App\Models\Banking\Transaction;
|
use App\Models\Setting\Tax;
|
||||||
use App\Models\Setting\Currency;
|
|
||||||
use App\Traits\Currencies;
|
use App\Traits\Currencies;
|
||||||
use App\Traits\DateTime;
|
use App\Traits\DateTime;
|
||||||
use App\Traits\Media;
|
use App\Traits\Media;
|
||||||
@ -159,8 +158,14 @@ abstract class DocumentModel extends Model
|
|||||||
{
|
{
|
||||||
$amount = $this->amount;
|
$amount = $this->amount;
|
||||||
|
|
||||||
$this->totals->where('code', 'tax')->each(function ($tax) use(&$amount) {
|
$this->totals->where('code', 'tax')->each(function ($total) use(&$amount) {
|
||||||
$amount -= $tax->amount;
|
$tax = Tax::name($total->name)->first();
|
||||||
|
|
||||||
|
if (!empty($tax) && ($tax->type == 'withholding')) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$amount -= $total->amount;
|
||||||
});
|
});
|
||||||
|
|
||||||
return $amount;
|
return $amount;
|
||||||
|
@ -25,6 +25,7 @@ class Taxes extends Controller
|
|||||||
'fixed' => trans('taxes.fixed'),
|
'fixed' => trans('taxes.fixed'),
|
||||||
'normal' => trans('taxes.normal'),
|
'normal' => trans('taxes.normal'),
|
||||||
'inclusive' => trans('taxes.inclusive'),
|
'inclusive' => trans('taxes.inclusive'),
|
||||||
|
'withholding' => trans('taxes.withholding'),
|
||||||
'compound' => trans('taxes.compound'),
|
'compound' => trans('taxes.compound'),
|
||||||
];
|
];
|
||||||
|
|
||||||
@ -52,6 +53,7 @@ class Taxes extends Controller
|
|||||||
'fixed' => trans('taxes.fixed'),
|
'fixed' => trans('taxes.fixed'),
|
||||||
'normal' => trans('taxes.normal'),
|
'normal' => trans('taxes.normal'),
|
||||||
'inclusive' => trans('taxes.inclusive'),
|
'inclusive' => trans('taxes.inclusive'),
|
||||||
|
'withholding' => trans('taxes.withholding'),
|
||||||
'compound' => trans('taxes.compound'),
|
'compound' => trans('taxes.compound'),
|
||||||
];
|
];
|
||||||
|
|
||||||
@ -99,6 +101,7 @@ class Taxes extends Controller
|
|||||||
'fixed' => trans('taxes.fixed'),
|
'fixed' => trans('taxes.fixed'),
|
||||||
'normal' => trans('taxes.normal'),
|
'normal' => trans('taxes.normal'),
|
||||||
'inclusive' => trans('taxes.inclusive'),
|
'inclusive' => trans('taxes.inclusive'),
|
||||||
|
'withholding' => trans('taxes.withholding'),
|
||||||
'compound' => trans('taxes.compound'),
|
'compound' => trans('taxes.compound'),
|
||||||
];
|
];
|
||||||
|
|
||||||
|
@ -87,9 +87,23 @@ class CreateBillItem extends Job
|
|||||||
|
|
||||||
$item_tax_total += $tax_amount;
|
$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;
|
break;
|
||||||
default:
|
default:
|
||||||
$tax_amount = ($item_discounted_amount / 100) * $tax->rate;
|
$tax_amount = $item_discounted_amount * ($tax->rate / 100);
|
||||||
|
|
||||||
$item_taxes[] = [
|
$item_taxes[] = [
|
||||||
'company_id' => $this->bill->company_id,
|
'company_id' => $this->bill->company_id,
|
||||||
@ -167,7 +181,7 @@ class CreateBillItem extends Job
|
|||||||
|
|
||||||
foreach ($item_taxes as $item_tax) {
|
foreach ($item_taxes as $item_tax) {
|
||||||
$item_tax['bill_item_id'] = $bill_item->id;
|
$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);
|
BillItemTax::create($item_tax);
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,6 @@
|
|||||||
namespace App\Jobs\Purchase;
|
namespace App\Jobs\Purchase;
|
||||||
|
|
||||||
use App\Abstracts\Job;
|
use App\Abstracts\Job;
|
||||||
use App\Models\Purchase\Bill;
|
|
||||||
use App\Models\Purchase\BillTotal;
|
use App\Models\Purchase\BillTotal;
|
||||||
use App\Traits\Currencies;
|
use App\Traits\Currencies;
|
||||||
use App\Traits\DateTime;
|
use App\Traits\DateTime;
|
||||||
@ -96,7 +95,7 @@ class CreateBillItemsAndTotals extends Job
|
|||||||
'bill_id' => $this->bill->id,
|
'bill_id' => $this->bill->id,
|
||||||
'code' => 'tax',
|
'code' => 'tax',
|
||||||
'name' => $tax['name'],
|
'name' => $tax['name'],
|
||||||
'amount' => round($tax['amount'], $precision),
|
'amount' => round(abs($total['amount']), $precision),
|
||||||
'sort_order' => $sort_order,
|
'sort_order' => $sort_order,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
@ -117,7 +116,7 @@ class CreateBillItemsAndTotals extends Job
|
|||||||
$total['code'] = 'extra';
|
$total['code'] = 'extra';
|
||||||
}
|
}
|
||||||
|
|
||||||
$total['amount'] = round($total['amount'], $precision);
|
$total['amount'] = round(abs($total['amount']), $precision);
|
||||||
|
|
||||||
BillTotal::create($total);
|
BillTotal::create($total);
|
||||||
|
|
||||||
|
@ -87,9 +87,23 @@ class CreateInvoiceItem extends Job
|
|||||||
|
|
||||||
$item_tax_total += $tax_amount;
|
$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;
|
break;
|
||||||
default:
|
default:
|
||||||
$tax_amount = ($item_discounted_amount / 100) * $tax->rate;
|
$tax_amount = $item_discounted_amount * ($tax->rate / 100);
|
||||||
|
|
||||||
$item_taxes[] = [
|
$item_taxes[] = [
|
||||||
'company_id' => $this->invoice->company_id,
|
'company_id' => $this->invoice->company_id,
|
||||||
@ -167,7 +181,7 @@ class CreateInvoiceItem extends Job
|
|||||||
|
|
||||||
foreach ($item_taxes as $item_tax) {
|
foreach ($item_taxes as $item_tax) {
|
||||||
$item_tax['invoice_item_id'] = $invoice_item->id;
|
$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);
|
InvoiceItemTax::create($item_tax);
|
||||||
}
|
}
|
||||||
|
@ -95,7 +95,7 @@ class CreateInvoiceItemsAndTotals extends Job
|
|||||||
'invoice_id' => $this->invoice->id,
|
'invoice_id' => $this->invoice->id,
|
||||||
'code' => 'tax',
|
'code' => 'tax',
|
||||||
'name' => $tax['name'],
|
'name' => $tax['name'],
|
||||||
'amount' => round($tax['amount'], $precision),
|
'amount' => round(abs($tax['amount']), $precision),
|
||||||
'sort_order' => $sort_order,
|
'sort_order' => $sort_order,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
@ -116,7 +116,7 @@ class CreateInvoiceItemsAndTotals extends Job
|
|||||||
$total['code'] = 'extra';
|
$total['code'] = 'extra';
|
||||||
}
|
}
|
||||||
|
|
||||||
$total['amount'] = round($total['amount'], $precision);
|
$total['amount'] = round(abs($total['amount']), $precision);
|
||||||
|
|
||||||
InvoiceTotal::create($total);
|
InvoiceTotal::create($total);
|
||||||
|
|
||||||
|
@ -54,6 +54,50 @@ class Tax extends Model
|
|||||||
return $query->where('rate', '=', $rate);
|
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.
|
* Convert rate to double.
|
||||||
*
|
*
|
||||||
|
@ -32,7 +32,7 @@ class TaxSummary extends Report
|
|||||||
|
|
||||||
public function setTables()
|
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);
|
$this->tables = array_combine($taxes, $taxes);
|
||||||
}
|
}
|
||||||
|
787
composer.lock
generated
787
composer.lock
generated
File diff suppressed because it is too large
Load Diff
@ -10,7 +10,7 @@ $company = $user->companies()->first();
|
|||||||
$factory->define(Tax::class, function (Faker $faker) use ($company) {
|
$factory->define(Tax::class, function (Faker $faker) use ($company) {
|
||||||
setting()->setExtraColumns(['company_id' => $company->id]);
|
setting()->setExtraColumns(['company_id' => $company->id]);
|
||||||
|
|
||||||
$types = ['normal', 'inclusive', 'compound', 'fixed'];
|
$types = ['normal', 'inclusive', 'compound', 'fixed', 'withholding'];
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'company_id' => $company->id,
|
'company_id' => $company->id,
|
||||||
@ -32,3 +32,5 @@ $factory->state(Tax::class, 'inclusive', ['type' => 'inclusive']);
|
|||||||
$factory->state(Tax::class, 'compound', ['type' => 'compound']);
|
$factory->state(Tax::class, 'compound', ['type' => 'compound']);
|
||||||
|
|
||||||
$factory->state(Tax::class, 'fixed', ['type' => 'fixed']);
|
$factory->state(Tax::class, 'fixed', ['type' => 'fixed']);
|
||||||
|
|
||||||
|
$factory->state(Tax::class, 'withholding', ['type' => 'withholding']);
|
||||||
|
7
resources/assets/js/views/purchases/bills.js
vendored
7
resources/assets/js/views/purchases/bills.js
vendored
@ -176,10 +176,11 @@ const app = new Vue({
|
|||||||
case 'fixed':
|
case 'fixed':
|
||||||
item_tax_total += tax.rate * item.quantity;
|
item_tax_total += tax.rate * item.quantity;
|
||||||
break;
|
break;
|
||||||
|
case 'withholding':
|
||||||
|
item_tax_total += 0 - item_discounted_total * (tax.rate / 100);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
let item_tax_amount = (item_discounted_total / 100) * tax.rate;
|
item_tax_total += item_discounted_total * (tax.rate / 100);
|
||||||
|
|
||||||
item_tax_total += item_tax_amount;
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
9
resources/assets/js/views/sales/invoices.js
vendored
9
resources/assets/js/views/sales/invoices.js
vendored
@ -177,10 +177,11 @@ const app = new Vue({
|
|||||||
case 'fixed':
|
case 'fixed':
|
||||||
item_tax_total += tax.rate * item.quantity;
|
item_tax_total += tax.rate * item.quantity;
|
||||||
break;
|
break;
|
||||||
|
case 'withholding':
|
||||||
|
item_tax_total += 0 - item_discounted_total * (tax.rate / 100);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
let item_tax_amount = (item_discounted_total / 100) * tax.rate;
|
item_tax_total += item_discounted_total * (tax.rate / 100);
|
||||||
|
|
||||||
item_tax_total += item_tax_amount;
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -225,7 +226,7 @@ const app = new Vue({
|
|||||||
|
|
||||||
// set global total variable.
|
// set global total variable.
|
||||||
this.totals.sub = sub_total;
|
this.totals.sub = sub_total;
|
||||||
this.totals.tax = tax_total;
|
this.totals.tax = Math.abs(tax_total);
|
||||||
this.totals.item_discount = line_item_discount_total;
|
this.totals.item_discount = line_item_discount_total;
|
||||||
|
|
||||||
// Apply discount to total
|
// Apply discount to total
|
||||||
|
@ -8,4 +8,5 @@ return [
|
|||||||
'inclusive' => 'Inclusive',
|
'inclusive' => 'Inclusive',
|
||||||
'compound' => 'Compound',
|
'compound' => 'Compound',
|
||||||
'fixed' => 'Fixed',
|
'fixed' => 'Fixed',
|
||||||
|
'withholding' => 'Withholding',
|
||||||
];
|
];
|
||||||
|
Loading…
x
Reference in New Issue
Block a user