The additional point about restricting the types of taxes is not covered here.
This commit is contained in:
sausin 2019-02-03 21:01:08 +05:30 committed by GitHub
parent 0939d60615
commit b135f0a57b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -103,51 +103,23 @@ class CreateBillItem
} }
if ($inclusives) { if ($inclusives) {
if ($this->discount) { $item_amount = $item_discount_amount + $item_tax_total;
$item_tax_total = 0;
if ($taxes) { $item_base_rate = $item_amount / (1 + collect($inclusives)->sum('rate')/100);
foreach ($taxes as $tax) {
$item_tax_amount = ($item_amount / 100) * $tax->rate; foreach ($inclusives as $inclusive) {
$item_tax_total += $tax_amount = $item_base_rate * ($inclusive->rate / 100);
$item_tax_total += $item_tax_amount; $item_taxes[] = [
} 'company_id' => $this->bill->company_id,
} 'bill_id' => $this->bill->id,
'tax_id' => $inclusive->id,
foreach ($inclusives as $inclusive) { 'name' => $inclusive->name,
$item_sub_and_tax_total = $item_amount + $item_tax_total; 'amount' => $tax_amount,
];
$item_tax_total = $item_sub_and_tax_total - ($item_sub_and_tax_total / (1 + ($inclusive->rate / 100)));
$item_sub_total = $item_sub_and_tax_total - $item_tax_total;
$item_taxes[] = [
'company_id' => $this->bill->company_id,
'bill_id' => $this->bill->id,
'tax_id' => $inclusive->id,
'name' => $inclusive->name,
'amount' => $tax_amount,
];
$item_discount_amount = $item_sub_total - ($item_sub_total * ($this->discount / 100));
}
} else {
foreach ($inclusives as $inclusive) {
$item_sub_and_tax_total = $item_discount_amount + $item_tax_total;
$item_tax_total = $tax_amount = $item_sub_and_tax_total - ($item_sub_and_tax_total / (1 + ($inclusive->rate / 100)));
$item_taxes[] = [
'company_id' => $this->bill->company_id,
'bill_id' => $this->bill->id,
'tax_id' => $inclusive->id,
'name' => $inclusive->name,
'amount' => $tax_amount,
];
$item_amount = $item_sub_and_tax_total - $item_tax_total;
}
} }
$item_amount = ($item_amount - $item_tax_total) / (1 - $this->discount / 100);
} }
if ($compounds) { if ($compounds) {