fix tax-per-item issue

This commit is contained in:
Mohit Panjwani
2021-07-16 11:49:56 +05:30
parent 2b80082996
commit d3a745605e
2 changed files with 13 additions and 25 deletions

View File

@ -476,33 +476,22 @@ class Invoice extends Model implements HasMedia
public function getPDFData()
{
$taxTypes = [];
$taxes = [];
$labels = [];
$taxes = collect();
if ($this->tax_per_item === 'YES') {
foreach ($this->items as $item) {
foreach ($item->taxes as $tax) {
if (! in_array($tax->name, $taxTypes)) {
array_push($taxTypes, $tax->name);
array_push($labels, $tax->name.' ('.$tax->percent.'%)');
$found = $taxes->filter(function ($item) use ($tax) {
return $item->tax_type_id == $tax->tax_type_id;
})->first();
if ($found) {
$found->amount += $tax->amount;
} else {
$taxes->push($tax);
}
}
}
foreach ($taxTypes as $taxType) {
$total = 0;
foreach ($this->items as $item) {
foreach ($item->taxes as $tax) {
if ($tax->name == $taxType) {
$total += $tax->amount;
}
}
}
array_push($taxes, $total);
}
}
$invoiceTemplate = self::find($this->id)->template_name;
@ -521,7 +510,6 @@ class Invoice extends Model implements HasMedia
'billing_address' => $this->getCustomerBillingAddress(),
'notes' => $this->getNotes(),
'logo' => $logo ?? null,
'labels' => $labels,
'taxes' => $taxes,
]);