feat: add account linking and improve sales table
- Add many-to-many relationships between Sale/Expense and Account models - Create pivot tables for account_sale and account_expense with migrations - Implement account syncing during sale/expense creation and editing - Add accounts_list attribute to display comma-separated account names - Introduce SaleService with DTO for sale creation logic - Simplify sales table columns to show branch, reference, date, and creator - Calculate and store aggregated financial fields from transactions - Make series field read-only instead of disabled in sale form
This commit is contained in:
@@ -36,6 +36,16 @@ class EditSale extends EditRecord
|
||||
|
||||
public function getFormDataMutation(array $data): array
|
||||
{
|
||||
$transactions = $data['transactions'] ?? [];
|
||||
|
||||
$data['gross_amount'] = collect($transactions)->sum(fn (array $transaction) => (float) ($transaction['gross_amount'] ?? 0));
|
||||
$data['exempt'] = collect($transactions)->sum(fn (array $transaction) => (float) ($transaction['exempt'] ?? 0));
|
||||
$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));
|
||||
|
||||
return Arr::except($data, ['client', 'transactions', 'with_discount']);
|
||||
}
|
||||
|
||||
@@ -71,6 +81,16 @@ class EditSale extends EditRecord
|
||||
]
|
||||
)->thenReturn();
|
||||
}
|
||||
|
||||
$accountIds = collect($transactions)
|
||||
->pluck('account_id')
|
||||
->filter()
|
||||
->unique()
|
||||
->values()
|
||||
->all();
|
||||
|
||||
$record->accounts()->sync($accountIds);
|
||||
|
||||
DB::commit();
|
||||
} catch (\Exception $exception) {
|
||||
DB::rollBack();
|
||||
|
||||
Reference in New Issue
Block a user