feat(sales): add discount support with ledger accounting
- Add discount_type column to transactions table via migration - Update Sale model to use fillable instead of guarded for better security - Implement discount account ledger creation when discount is applied - Fix net amount calculation to include discount in CreateSaleAction - Remove unused "Exempt" column from sale transaction table - Make discount_type required when discount is enabled in form - Update form data mutation to properly handle discount calculations
This commit is contained in:
@@ -96,7 +96,7 @@ class SaleResource extends Resource
|
||||
Header::make('Charge Account'),
|
||||
Header::make('Description'),
|
||||
Header::make('Gross Amount'),
|
||||
Header::make('Exempt'),
|
||||
// Header::make('Exempt'),
|
||||
Header::make('Vatable Amount'),
|
||||
Header::make('Output Tax'),
|
||||
Header::make('Withholding Tax'),
|
||||
@@ -110,7 +110,7 @@ class SaleResource extends Resource
|
||||
Header::make('Charge Account'),
|
||||
Header::make('Description'),
|
||||
Header::make('Gross Amount'),
|
||||
Header::make('Exempt'),
|
||||
// Header::make('Exempt'),
|
||||
Header::make('Vatable Amount'),
|
||||
Header::make('Output Tax'),
|
||||
Header::make('Withholding Tax'),
|
||||
@@ -133,6 +133,7 @@ class SaleResource extends Resource
|
||||
TextInput::make('exempt')
|
||||
->numeric()
|
||||
->live()
|
||||
->hidden()
|
||||
->afterStateUpdated(function (Get $get, Set $set, ?string $old, ?string $state) {
|
||||
static::setDefaultFormValues($get, $set, $old, $state);
|
||||
})->default(0),
|
||||
@@ -155,16 +156,16 @@ class SaleResource extends Resource
|
||||
->numeric()
|
||||
->live()
|
||||
->afterStateUpdated(function (Get $get, Set $set, ?string $old, ?string $state) {
|
||||
|
||||
static::setDefaultFormValues($get, $set, $old, $state);
|
||||
})->default(0),
|
||||
TextInput::make('discount')
|
||||
->numeric()
|
||||
->readOnly()
|
||||
// ->readOnly()
|
||||
->visible(fn (Get $get) => $get('../../with_discount'))
|
||||
->live(),
|
||||
Select::make('discount_type')
|
||||
->options(fn (Get $get) => static::getDiscountOptions($get))
|
||||
->required(fn (Get $get) => $get('../../with_discount'))
|
||||
->visible(fn (Get $get) => $get('../../with_discount')),
|
||||
TextInput::make('net_amount')->numeric()->default(0),
|
||||
];
|
||||
@@ -225,7 +226,7 @@ class SaleResource extends Resource
|
||||
}
|
||||
|
||||
$set('output_tax', number_format($outputTax, 2, '.', ''));
|
||||
$set('discount', number_format($discount, 2, '.', ''));
|
||||
// $set('discount', number_format($discount, 2, '.', ''));
|
||||
$set('vatable_amount', number_format($vatableAmount, 2, '.', ''));
|
||||
$set('net_amount', number_format($netAmount, 2, '.', ''));
|
||||
}
|
||||
|
||||
@@ -76,10 +76,11 @@ class CreateSale extends CreateRecord
|
||||
$data['vatable_amount'] = collect($transactions)->sum(fn (array $transaction) => (float) ($transaction['vatable_amount'] ?? 0));
|
||||
$data['output_tax'] = collect($transactions)->sum(fn (array $transaction) => (float) ($transaction['output_tax'] ?? 0));
|
||||
$data['payable_withholding_tax'] = collect($transactions)->sum(fn (array $transaction) => (float) ($transaction['payable_withholding_tax'] ?? 0));
|
||||
$data['discount'] = collect($transactions)->sum(fn (array $transaction) => (float) ($transaction['discount'] ?? 0));
|
||||
$data['net_amount'] = collect($transactions)->sum(fn (array $transaction) => (float) ($transaction['net_amount'] ?? 0));
|
||||
$discount = collect($transactions)->sum(fn (array $transaction) => (float) ($transaction['discount'] ?? 0));
|
||||
$data['discount'] = $discount;
|
||||
$data['net_amount'] = collect($transactions)->sum(fn (array $transaction) => (float) ($transaction['net_amount'] ?? 0)) + $discount;
|
||||
|
||||
return Arr::except($data, ['client', 'transactions', 'with_discount']);
|
||||
return Arr::except($data, ['client', 'transactions']);
|
||||
}
|
||||
|
||||
public function processCreate(array $data, array $transactions): Model
|
||||
|
||||
Reference in New Issue
Block a user