diff --git a/app/Models/Barobill/BankTransaction.php b/app/Models/Barobill/BankTransaction.php index a6d833e6..2d4d0a12 100644 --- a/app/Models/Barobill/BankTransaction.php +++ b/app/Models/Barobill/BankTransaction.php @@ -7,12 +7,14 @@ use App\Models\Tenants\Tenant; /** - * 계좌 입출금 내역 모델 + * 바로빌 계좌 입출금 내역 모델 * * 바로빌에서 조회한 입출금 내역에 계정과목을 추가하여 저장 */ class BankTransaction extends Model { + protected $table = 'barobill_bank_transactions'; + protected $fillable = [ 'tenant_id', 'bank_account_num', diff --git a/database/migrations/2026_01_23_130000_create_barobill_bank_transactions_table.php b/database/migrations/2026_01_23_130000_create_barobill_bank_transactions_table.php new file mode 100644 index 00000000..1079a552 --- /dev/null +++ b/database/migrations/2026_01_23_130000_create_barobill_bank_transactions_table.php @@ -0,0 +1,53 @@ +id(); + $table->foreignId('tenant_id')->constrained()->onDelete('cascade'); + $table->string('bank_account_num', 50)->comment('계좌번호'); + $table->string('bank_code', 10)->nullable()->comment('은행코드'); + $table->string('bank_name', 50)->nullable()->comment('은행명'); + $table->string('trans_date', 8)->comment('거래일 (YYYYMMDD)'); + $table->string('trans_time', 6)->nullable()->comment('거래시간 (HHMMSS)'); + $table->string('trans_dt', 20)->comment('거래일시 원본 (YYYYMMDDHHMMSS)'); + $table->decimal('deposit', 18, 2)->default(0)->comment('입금액'); + $table->decimal('withdraw', 18, 2)->default(0)->comment('출금액'); + $table->decimal('balance', 18, 2)->default(0)->comment('잔액'); + $table->string('summary', 255)->nullable()->comment('적요'); + $table->string('cast', 100)->nullable()->comment('상대방'); + $table->string('memo', 255)->nullable()->comment('메모'); + $table->string('trans_office', 100)->nullable()->comment('거래점'); + $table->string('account_code', 50)->nullable()->comment('계정과목 코드'); + $table->string('account_name', 100)->nullable()->comment('계정과목 명'); + $table->timestamps(); + + // 복합 유니크 인덱스: 같은 거래는 중복 저장 방지 + $table->unique( + ['tenant_id', 'bank_account_num', 'trans_dt', 'deposit', 'withdraw', 'balance'], + 'barobill_bank_trans_unique' + ); + + // 조회용 인덱스 + $table->index(['tenant_id', 'trans_date'], 'bb_trans_tenant_date_idx'); + $table->index(['tenant_id', 'bank_account_num', 'trans_date'], 'bb_trans_tenant_acct_date_idx'); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('barobill_bank_transactions'); + } +};