Skip to content

Commit 221f998

Browse files
Merge pull request #95 from khalidmaquilang/feature/si-104-display-taxable-amount
SI-104 | Feature | show full amount of the tax
2 parents a7c851e + 71695f3 commit 221f998

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

app/Services/SaleService.php

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ public function generateInvoice(Sale $sale): BinaryFileResponse
2525
});
2626
$currency = $company->getCurrency();
2727

28+
$taxableAmount = $this->getTaxableAmount($sale->total_amount, $sale->vat);
29+
2830
$html = view('filament.invoice.invoice', [
2931
'companyName' => $company->name,
3032
'logo' => $company->getCompanyLogo(),
@@ -42,7 +44,8 @@ public function generateInvoice(Sale $sale): BinaryFileResponse
4244
'subTotal' => $this->format($subTotal, $currency),
4345
'shippingFee' => $this->format($sale->shipping_fee, $currency),
4446
'discount' => $sale->formatted_discount,
45-
'vat' => $sale->vat,
47+
'vat' => $this->format($sale->total_amount - $taxableAmount, $currency),
48+
'vatPercent' => $sale->vat,
4649
'total' => $this->format($sale->total_amount, $currency),
4750
'paidAmount' => $this->format($sale->paid_amount, $currency),
4851
'remainingAmount' => $this->format($sale->remaining_amount, $currency),
@@ -73,4 +76,18 @@ protected function format(int|float $amount, string $currency): string
7376
{
7477
return number_format($amount, 2).' '.$currency;
7578
}
79+
80+
/**
81+
* @param float $totalAmount
82+
* @param int $vat
83+
* @return float
84+
*/
85+
protected function getTaxableAmount(float $totalAmount, int $vat): float
86+
{
87+
if ($vat <= 0) {
88+
return 0;
89+
}
90+
91+
return $totalAmount / (1 + ($vat / 100));
92+
}
7693
}

resources/views/filament/invoice/invoice.blade.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,8 @@
131131
<td class="right-align">{{ $shippingFee }}</td>
132132
</tr>
133133
<tr>
134-
<td colspan="3">VAT</td>
135-
<td class="right-align">{{ $vat }}%</td>
134+
<td colspan="3">VAT ({{ $vatPercent }}%)</td>
135+
<td class="right-align">{{ $vat }}</td>
136136
</tr>
137137
<tr>
138138
<td colspan="3">Total</td>

0 commit comments

Comments
 (0)