Edit Sales Settlement

@php $savedBatchesData = []; foreach ($settlement->items as $item) { foreach ($item->batches as $batch) { $savedBatchesData[$batch->stock_batch_id] = [ 'sold' => (float) $batch->quantity_sold, 'returned' => (float) $batch->quantity_returned, 'shortage' => (float) $batch->quantity_shortage, ]; } } $creditSalesData = $settlement->creditSales->map(function ($sale) { return [ 'customer_id' => $sale->customer_id, 'customer_name' => $sale->customer->customer_name ?? 'Unknown', 'invoice_number' => $sale->invoice_number, 'sale_amount' => (float) $sale->sale_amount, 'previous_balance' => (float) $sale->previous_balance, 'new_balance' => (float) $sale->new_balance, 'notes' => $sale->notes, ]; }); $creditSalesDecoded = old('credit_sales'); if (is_string($creditSalesDecoded)) { $decoded = json_decode($creditSalesDecoded, true); if (json_last_error() === JSON_ERROR_NONE) { $creditSalesDecoded = $decoded; } } if (!is_array($creditSalesDecoded) || empty($creditSalesDecoded)) { $creditSalesDecoded = $creditSalesData->toArray(); } $recoveriesData = $settlement->recoveries->map(function ($recovery) { return [ 'customer_id' => $recovery->customer_id, 'customer_name' => $recovery->customer->customer_name ?? 'Unknown', 'recovery_number' => $recovery->recovery_number, 'payment_method' => $recovery->payment_method, 'bank_account_id' => $recovery->bank_account_id, 'bank_account_name' => $recovery->bankAccount->account_name ?? null, 'previous_balance' => (float) $recovery->previous_balance, 'amount' => (float) $recovery->amount, 'new_balance' => (float) $recovery->new_balance, 'notes' => $recovery->notes, ]; }); $recoveriesDecoded = old('recoveries_entries'); if (is_string($recoveriesDecoded)) { $decoded = json_decode($recoveriesDecoded, true); if (json_last_error() === JSON_ERROR_NONE) { $recoveriesDecoded = $decoded; } } if (!is_array($recoveriesDecoded) || empty($recoveriesDecoded)) { $recoveriesDecoded = $recoveriesData->toArray(); } $recoveriesTotal = collect($recoveriesDecoded)->sum(function ($entry) { return floatval($entry['amount'] ?? 0); }); $bankTransfersData = $settlement->bankTransfers->map(function ($transfer) { return [ 'bank_account_id' => $transfer->bank_account_id, 'bank_account_name' => $transfer->bankAccount->account_name ?? 'Unknown', 'amount' => (float) $transfer->amount, 'reference_number' => $transfer->reference_number, 'transfer_date' => optional($transfer->transfer_date)->format('Y-m-d'), 'customer_id' => $transfer->customer_id, 'customer_name' => $transfer->customer->customer_name ?? null, 'notes' => $transfer->notes, ]; }); $bankTransfersDecoded = old('bank_transfers'); if (is_string($bankTransfersDecoded)) { $decoded = json_decode($bankTransfersDecoded, true); if (json_last_error() === JSON_ERROR_NONE) { $bankTransfersDecoded = $decoded; } } if (!is_array($bankTransfersDecoded) || empty($bankTransfersDecoded)) { $bankTransfersDecoded = $bankTransfersData->toArray(); } $chequesData = $settlement->cheques->map(function ($cheque) { return [ 'cheque_number' => $cheque->cheque_number, 'amount' => (float) $cheque->amount, 'bank_name' => $cheque->bank_name, 'bank_account_id' => $cheque->bank_account_id, 'bank_account_name' => $cheque->bankAccount->account_name ?? null, 'cheque_date' => optional($cheque->cheque_date)->format('Y-m-d'), 'customer_id' => $cheque->customer_id, 'customer_name' => $cheque->customer->customer_name ?? 'N/A', 'notes' => $cheque->notes, ]; }); $chequesDecoded = old('cheques'); if (is_string($chequesDecoded)) { $decoded = json_decode($chequesDecoded, true); if (json_last_error() === JSON_ERROR_NONE) { $chequesDecoded = $decoded; } } if (!is_array($chequesDecoded) || empty($chequesDecoded)) { $chequesDecoded = $chequesData->toArray(); } $cashDenom = $settlement->cashDenominations->first(); $savedExpensesData = $settlement->expenses->map(function ($expense) { return [ 'id' => 'saved_' . $expense->id, 'expense_account_id' => $expense->expense_account_id, 'amount' => (float) $expense->amount, 'description' => $expense->description, 'label' => $expense->expenseAccount->account_name ?? '', 'account_code' => $expense->expenseAccount->account_code ?? '', ]; }); $advanceTaxesData = $settlement->advanceTaxes->map(function ($tax) { return [ 'customer_id' => $tax->customer_id, 'customer_name' => $tax->customer->customer_name ?? 'Unknown', 'tax_amount' => (float) $tax->tax_amount, ]; }); $advanceTaxesDecoded = old('advance_taxes'); if (is_string($advanceTaxesDecoded)) { $decoded = json_decode($advanceTaxesDecoded, true); if (json_last_error() === JSON_ERROR_NONE) { $advanceTaxesDecoded = $decoded; } } if (!is_array($advanceTaxesDecoded) || empty($advanceTaxesDecoded)) { $advanceTaxesDecoded = $advanceTaxesData->toArray(); } @endphp
@csrf @method('PUT') {{-- Hidden input to store current employee ID for credit sales modal --}}
{{-- Section 1: Date & Goods Issue Selection --}}
{{-- Section 2: Combined Batch-wise Settlement Table --}}
{{-- Section 3: Side-by-Side Cash Detail, Expense Detail, and Sales Summary --}}
{{-- Section 8: Notes (MOVED TO BOTTOM) --}}
Cancel Update Settlement
@push('scripts') @endpush