Skip to content

Commit

Permalink
Merge pull request #95 from khalidmaquilang/feature/si-104-display-ta…
Browse files Browse the repository at this point in the history
…xable-amount

SI-104 | Feature | show full amount of the tax
  • Loading branch information
khalidmaquilang authored Jun 22, 2024
2 parents a7c851e + 71695f3 commit 221f998
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
19 changes: 18 additions & 1 deletion app/Services/SaleService.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ public function generateInvoice(Sale $sale): BinaryFileResponse
});
$currency = $company->getCurrency();

$taxableAmount = $this->getTaxableAmount($sale->total_amount, $sale->vat);

$html = view('filament.invoice.invoice', [
'companyName' => $company->name,
'logo' => $company->getCompanyLogo(),
Expand All @@ -42,7 +44,8 @@ public function generateInvoice(Sale $sale): BinaryFileResponse
'subTotal' => $this->format($subTotal, $currency),
'shippingFee' => $this->format($sale->shipping_fee, $currency),
'discount' => $sale->formatted_discount,
'vat' => $sale->vat,
'vat' => $this->format($sale->total_amount - $taxableAmount, $currency),
'vatPercent' => $sale->vat,
'total' => $this->format($sale->total_amount, $currency),
'paidAmount' => $this->format($sale->paid_amount, $currency),
'remainingAmount' => $this->format($sale->remaining_amount, $currency),
Expand Down Expand Up @@ -73,4 +76,18 @@ protected function format(int|float $amount, string $currency): string
{
return number_format($amount, 2).' '.$currency;
}

/**
* @param float $totalAmount
* @param int $vat
* @return float
*/
protected function getTaxableAmount(float $totalAmount, int $vat): float
{
if ($vat <= 0) {
return 0;
}

return $totalAmount / (1 + ($vat / 100));
}
}
4 changes: 2 additions & 2 deletions resources/views/filament/invoice/invoice.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,8 @@
<td class="right-align">{{ $shippingFee }}</td>
</tr>
<tr>
<td colspan="3">VAT</td>
<td class="right-align">{{ $vat }}%</td>
<td colspan="3">VAT ({{ $vatPercent }}%)</td>
<td class="right-align">{{ $vat }}</td>
</tr>
<tr>
<td colspan="3">Total</td>
Expand Down

0 comments on commit 221f998

Please sign in to comment.