public static function updateLineTotal(Get $get, Set $set): void {
$lineTotal = $get('items.qty') * $get('items.rate');
if($get('items.discount_type') === 'fixed') {
$lineTotal -= $get('items.discount');
} else {
$lineTotal -= ($get('items.discount') / 100 * $lineTotal);
}
$set('line_total', number_format($lineTotal, 2, '.', ''));
}
public static function updateTotals(Get $get, Set $set): void {
$lineItems = collect($get('items'))->filter(fn($item) => !empty($item['qty']) && !empty($item['title']));
$subtotal = $lineItems->reduce(function($subtotal, $item) {
$linetotal = ($item['qty'] * $item['rate']);
if($item['discount_type'] === 'fixed') {
$linetotal -= $item['discount'];
} else {
$linetotal -= ($item['discount'] / 100 * $subtotal);
}
return $subtotal + $linetotal;
}, 0);
$set('sub_total', number_format($subtotal, 2, '.', ''));
$set('total', number_format($subtotal - ($subtotal - ($get('discount'))) + ($subtotal * ($get('tax') / 100)), 2, '.', ''));
}