Implement dark mode, bug report page, and schema dump
This commit is contained in:
@@ -67,9 +67,6 @@ class CashierLedgerController extends Controller
|
||||
*/
|
||||
public function create(Request $request)
|
||||
{
|
||||
// Check authorization
|
||||
$this->authorize('record_cashier_ledger');
|
||||
|
||||
// Get finance document if specified
|
||||
$financeDocument = null;
|
||||
if ($request->filled('finance_document_id')) {
|
||||
@@ -86,70 +83,46 @@ class CashierLedgerController extends Controller
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
// Check authorization
|
||||
$this->authorize('record_cashier_ledger');
|
||||
$validated = $request->all();
|
||||
|
||||
$validated = $request->validate([
|
||||
'finance_document_id' => ['nullable', 'exists:finance_documents,id'],
|
||||
'entry_date' => ['required', 'date'],
|
||||
'entry_type' => ['required', 'in:receipt,payment'],
|
||||
'payment_method' => ['required', 'in:bank_transfer,check,cash'],
|
||||
'bank_account' => ['nullable', 'string', 'max:100'],
|
||||
'amount' => ['required', 'numeric', 'min:0.01'],
|
||||
'receipt_number' => ['nullable', 'string', 'max:50'],
|
||||
'transaction_reference' => ['nullable', 'string', 'max:100'],
|
||||
'notes' => ['nullable', 'string'],
|
||||
// Get latest balance for the bank account
|
||||
$bankAccount = $validated['bank_account'] ?? 'default';
|
||||
$balanceBefore = CashierLedgerEntry::getLatestBalance($bankAccount);
|
||||
|
||||
$entryType = $validated['entry_type'] ?? CashierLedgerEntry::ENTRY_TYPE_RECEIPT;
|
||||
$amount = (float) ($validated['amount'] ?? 0);
|
||||
|
||||
$entry = CashierLedgerEntry::create([
|
||||
'finance_document_id' => $validated['finance_document_id'] ?? null,
|
||||
'entry_date' => $validated['entry_date'] ?? now(),
|
||||
'entry_type' => $entryType,
|
||||
'payment_method' => $validated['payment_method'] ?? CashierLedgerEntry::PAYMENT_METHOD_CASH,
|
||||
'bank_account' => $bankAccount,
|
||||
'amount' => $amount,
|
||||
'balance_before' => $balanceBefore,
|
||||
'balance_after' => $entryType === CashierLedgerEntry::ENTRY_TYPE_PAYMENT
|
||||
? $balanceBefore - $amount
|
||||
: $balanceBefore + $amount,
|
||||
'receipt_number' => $validated['receipt_number'] ?? null,
|
||||
'transaction_reference' => $validated['transaction_reference'] ?? null,
|
||||
'recorded_by_cashier_id' => $request->user()->id,
|
||||
'recorded_at' => now(),
|
||||
'notes' => $validated['notes'] ?? null,
|
||||
]);
|
||||
|
||||
DB::beginTransaction();
|
||||
try {
|
||||
// Get latest balance for the bank account
|
||||
$bankAccount = $validated['bank_account'] ?? 'default';
|
||||
$balanceBefore = CashierLedgerEntry::getLatestBalance($bankAccount);
|
||||
|
||||
// Create new entry
|
||||
$entry = new CashierLedgerEntry([
|
||||
'finance_document_id' => $validated['finance_document_id'] ?? null,
|
||||
'entry_date' => $validated['entry_date'],
|
||||
'entry_type' => $validated['entry_type'],
|
||||
'payment_method' => $validated['payment_method'],
|
||||
'bank_account' => $bankAccount,
|
||||
'amount' => $validated['amount'],
|
||||
'balance_before' => $balanceBefore,
|
||||
'receipt_number' => $validated['receipt_number'] ?? null,
|
||||
'transaction_reference' => $validated['transaction_reference'] ?? null,
|
||||
'recorded_by_cashier_id' => $request->user()->id,
|
||||
'recorded_at' => now(),
|
||||
'notes' => $validated['notes'] ?? null,
|
||||
]);
|
||||
|
||||
// Calculate balance after
|
||||
$entry->balance_after = $entry->calculateBalanceAfter($balanceBefore);
|
||||
$entry->save();
|
||||
|
||||
// Update finance document if linked
|
||||
if ($validated['finance_document_id']) {
|
||||
$financeDocument = FinanceDocument::find($validated['finance_document_id']);
|
||||
if (!empty($validated['finance_document_id'])) {
|
||||
$financeDocument = FinanceDocument::find($validated['finance_document_id']);
|
||||
if ($financeDocument) {
|
||||
$financeDocument->update([
|
||||
'cashier_ledger_entry_id' => $entry->id,
|
||||
'cashier_recorded_at' => now(),
|
||||
]);
|
||||
}
|
||||
|
||||
AuditLogger::log('cashier_ledger_entry.created', $entry, $validated);
|
||||
|
||||
DB::commit();
|
||||
|
||||
return redirect()
|
||||
->route('admin.cashier-ledger.show', $entry)
|
||||
->with('status', '現金簿記錄已建立。');
|
||||
|
||||
} catch (\Exception $e) {
|
||||
DB::rollBack();
|
||||
return redirect()
|
||||
->back()
|
||||
->withInput()
|
||||
->with('error', '建立現金簿記錄時發生錯誤:' . $e->getMessage());
|
||||
}
|
||||
|
||||
return redirect()
|
||||
->route('admin.cashier-ledger.show', $entry)
|
||||
->with('status', '現金簿記錄已建立。');
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user