Merge pull request #751 from sausin/patch-2

Closes #688
This commit is contained in:
Cüneyt Şentürk 2019-03-07 11:49:01 +03:00 committed by GitHub
commit 183e3c86e0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 71 deletions

View File

@ -358,37 +358,12 @@ class Items extends Controller
} }
if ($inclusives) { if ($inclusives) {
if ($discount) {
$item_tax_total = 0;
if ($taxes) {
foreach ($taxes as $tax) {
$item_tax_amount = ($item_sub_total / 100) * $tax->rate;
$item_tax_total += $item_tax_amount;
}
}
foreach ($inclusives as $inclusive) {
$item_sub_and_tax_total = $item_sub_total + $item_tax_total;
$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_discount_total = $item_sub_total - ($item_sub_total * ($discount / 100));
}
} else {
foreach ($inclusives as $inclusive) {
$item_sub_and_tax_total = $item_discount_total + $item_tax_total; $item_sub_and_tax_total = $item_discount_total + $item_tax_total;
$item_tax_total = $item_sub_and_tax_total - ($item_sub_and_tax_total / (1 + ($inclusive->rate / 100))); $item_base_rate = $item_sub_and_tax_total / (1 + collect($inclusives)->sum('rate')/100);
$item_tax_total = $item_sub_and_tax_total - $item_base_rate;
$item_sub_total = $item_sub_and_tax_total - $item_tax_total; $item_sub_total = $item_base_rate + $discount;
$item_discount_total = $item_sub_total - ($item_sub_total * ($discount / 100));
}
}
} }
if ($compounds) { if ($compounds) {

View File

@ -103,23 +103,12 @@ 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;
$item_tax_total += $item_tax_amount;
}
}
foreach ($inclusives as $inclusive) { foreach ($inclusives as $inclusive) {
$item_sub_and_tax_total = $item_amount + $item_tax_total; $item_tax_total += $tax_amount = $item_base_rate * ($inclusive->rate / 100);
$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[] = [ $item_taxes[] = [
'company_id' => $this->bill->company_id, 'company_id' => $this->bill->company_id,
@ -128,26 +117,9 @@ class CreateBillItem
'name' => $inclusive->name, 'name' => $inclusive->name,
'amount' => $tax_amount, '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_amount = ($item_amount - $item_tax_total) / (1 - $this->discount / 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;
}
}
} }
if ($compounds) { if ($compounds) {