id(); // 基本資訊 $table->string('income_number')->unique(); // 收入編號:INC-2025-0001 $table->string('title'); // 收入標題 $table->text('description')->nullable(); // 說明 $table->date('income_date'); // 收入日期 $table->decimal('amount', 12, 2); // 金額 // 收入分類 $table->string('income_type'); // 收入類型 $table->foreignId('chart_of_account_id') // 會計科目 ->constrained('chart_of_accounts'); // 付款資訊 $table->string('payment_method'); // 付款方式 $table->string('bank_account')->nullable(); // 銀行帳戶 $table->string('payer_name')->nullable(); // 付款人姓名 $table->string('receipt_number')->nullable(); // 收據編號 $table->string('transaction_reference')->nullable(); // 銀行交易參考號 $table->string('attachment_path')->nullable(); // 附件路徑 // 會員關聯 $table->foreignId('member_id')->nullable() ->constrained()->nullOnDelete(); // 審核流程 $table->string('status')->default('pending'); // pending, confirmed, cancelled // 出納記錄 $table->foreignId('recorded_by_cashier_id') ->constrained('users'); $table->timestamp('recorded_at'); // 會計確認 $table->foreignId('confirmed_by_accountant_id')->nullable() ->constrained('users'); $table->timestamp('confirmed_at')->nullable(); // 關聯出納日記帳 $table->foreignId('cashier_ledger_entry_id')->nullable() ->constrained('cashier_ledger_entries')->nullOnDelete(); $table->text('notes')->nullable(); $table->timestamps(); // 索引 $table->index('income_date'); $table->index('income_type'); $table->index('status'); $table->index(['member_id', 'income_type']); }); // 在 accounting_entries 表新增 income_id 欄位 Schema::table('accounting_entries', function (Blueprint $table) { if (!Schema::hasColumn('accounting_entries', 'income_id')) { $table->foreignId('income_id')->nullable() ->after('finance_document_id') ->constrained('incomes')->nullOnDelete(); } }); } /** * Reverse the migrations. */ public function down(): void { Schema::table('accounting_entries', function (Blueprint $table) { if (Schema::hasColumn('accounting_entries', 'income_id')) { $table->dropForeign(['income_id']); $table->dropColumn('income_id'); } }); Schema::dropIfExists('incomes'); } };