mirror of
https://github.com/crater-invoice/crater.git
synced 2025-10-28 04:01:10 -04:00
fix tax-per-item issue display for estimates
This commit is contained in:
@ -395,33 +395,22 @@ class Estimate extends Model implements HasMedia
|
|||||||
|
|
||||||
public function getPDFData()
|
public function getPDFData()
|
||||||
{
|
{
|
||||||
$taxTypes = [];
|
$taxes = collect();
|
||||||
$taxes = [];
|
|
||||||
$labels = [];
|
|
||||||
|
|
||||||
if ($this->tax_per_item === 'YES') {
|
if ($this->tax_per_item === 'YES') {
|
||||||
foreach ($this->items as $item) {
|
foreach ($this->items as $item) {
|
||||||
foreach ($item->taxes as $tax) {
|
foreach ($item->taxes as $tax) {
|
||||||
if (! in_array($tax->name, $taxTypes)) {
|
$found = $taxes->filter(function ($item) use ($tax) {
|
||||||
array_push($taxTypes, $tax->name);
|
return $item->tax_type_id == $tax->tax_type_id;
|
||||||
array_push($labels, $tax->name.' ('.$tax->percent.'%)');
|
})->first();
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach ($taxTypes as $taxType) {
|
if ($found) {
|
||||||
$total = 0;
|
$found->amount += $tax->amount;
|
||||||
|
} else {
|
||||||
foreach ($this->items as $item) {
|
$taxes->push($tax);
|
||||||
foreach ($item->taxes as $tax) {
|
|
||||||
if ($tax->name == $taxType) {
|
|
||||||
$total += $tax->amount;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
array_push($taxes, $total);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$estimateTemplate = self::find($this->id)->template_name;
|
$estimateTemplate = self::find($this->id)->template_name;
|
||||||
@ -440,7 +429,6 @@ class Estimate extends Model implements HasMedia
|
|||||||
'shipping_address' => $this->getCustomerShippingAddress(),
|
'shipping_address' => $this->getCustomerShippingAddress(),
|
||||||
'billing_address' => $this->getCustomerBillingAddress(),
|
'billing_address' => $this->getCustomerBillingAddress(),
|
||||||
'notes' => $this->getNotes(),
|
'notes' => $this->getNotes(),
|
||||||
'labels' => $labels,
|
|
||||||
'taxes' => $taxes,
|
'taxes' => $taxes,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
|||||||
@ -72,16 +72,16 @@
|
|||||||
</tr>
|
</tr>
|
||||||
|
|
||||||
@if ($estimate->tax_per_item === 'YES')
|
@if ($estimate->tax_per_item === 'YES')
|
||||||
@for ($i = 0; $i < count($labels); $i++)
|
@foreach ($taxes as $tax)
|
||||||
<tr>
|
<tr>
|
||||||
<td class="border-0 total-table-attribute-label">
|
<td class="border-0 total-table-attribute-label">
|
||||||
{{$labels[$i]}}
|
{{$tax->name.' ('.$tax->percent.'%)'}}
|
||||||
</td>
|
</td>
|
||||||
<td class="border-0 item-cell total-table-attribute-value">
|
<td class="py-2 border-0 item-cell total-table-attribute-value">
|
||||||
{!! format_money_pdf($taxes[$i], $estimate->user->currency) !!}
|
{!! format_money_pdf($tax->amount, $estimate->user->currency) !!}
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
@endfor
|
@endforeach
|
||||||
@else
|
@else
|
||||||
@foreach ($estimate->taxes as $tax)
|
@foreach ($estimate->taxes as $tax)
|
||||||
<tr>
|
<tr>
|
||||||
|
|||||||
Reference in New Issue
Block a user