mirror of
https://github.com/crater-invoice/crater.git
synced 2025-10-27 11:41:09 -04:00
fix tax-per-item issue
This commit is contained in:
@ -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,
|
||||
]);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user