@@ -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}
0 commit comments