- config/database.php에 codebridge connection 추가 - 78개 MNG 전용 모델에 $connection = 'codebridge' 설정 - Admin (15): PM, 로드맵, API Explorer - Sales (16): 영업파트너, 수수료, 가망고객 - Finance (9): 법인카드, 자금관리, 홈택스 - Barobill (12): 은행/카드 동기화 관리 - Interview (1), ESign (6), Equipment (2) - AI (3), Audit (3), 기타 (11)
127 lines
3.8 KiB
PHP
127 lines
3.8 KiB
PHP
<?php
|
|
|
|
namespace App\Models\Barobill;
|
|
|
|
use App\Models\Tenants\Tenant;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
|
|
/**
|
|
* 계좌 입출금 거래 분개 모델
|
|
* 하나의 입출금 거래를 여러 계정과목으로 분개하여 저장
|
|
*/
|
|
class BankTransactionSplit extends Model
|
|
{
|
|
protected $connection = 'codebridge';
|
|
protected $table = 'barobill_bank_transaction_splits';
|
|
|
|
protected $fillable = [
|
|
'tenant_id',
|
|
'original_unique_key',
|
|
'split_amount',
|
|
'account_code',
|
|
'account_name',
|
|
'description',
|
|
'memo',
|
|
'sort_order',
|
|
'bank_account_num',
|
|
'trans_dt',
|
|
'trans_date',
|
|
'original_deposit',
|
|
'original_withdraw',
|
|
'summary',
|
|
];
|
|
|
|
protected $casts = [
|
|
'split_amount' => 'decimal:2',
|
|
'original_deposit' => 'decimal:2',
|
|
'original_withdraw' => 'decimal:2',
|
|
'sort_order' => 'integer',
|
|
];
|
|
|
|
/**
|
|
* 테넌트 관계
|
|
*/
|
|
public function tenant(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Tenant::class);
|
|
}
|
|
|
|
/**
|
|
* 테넌트별 분개 내역 조회 (기간별)
|
|
* 고유키를 기준으로 그룹핑하여 반환
|
|
*/
|
|
public static function getByDateRange(int $tenantId, string $startDate, string $endDate): array
|
|
{
|
|
$splits = self::where('tenant_id', $tenantId)
|
|
->whereBetween('trans_date', [$startDate, $endDate])
|
|
->orderBy('original_unique_key')
|
|
->orderBy('sort_order')
|
|
->get();
|
|
|
|
// 고유키별로 그룹핑
|
|
$grouped = [];
|
|
foreach ($splits as $split) {
|
|
$key = $split->original_unique_key;
|
|
if (! isset($grouped[$key])) {
|
|
$grouped[$key] = [];
|
|
}
|
|
$grouped[$key][] = $split;
|
|
}
|
|
|
|
return $grouped;
|
|
}
|
|
|
|
/**
|
|
* 특정 거래의 분개 내역 조회
|
|
*/
|
|
public static function getByUniqueKey(int $tenantId, string $uniqueKey): \Illuminate\Database\Eloquent\Collection
|
|
{
|
|
return self::where('tenant_id', $tenantId)
|
|
->where('original_unique_key', $uniqueKey)
|
|
->orderBy('sort_order')
|
|
->get();
|
|
}
|
|
|
|
/**
|
|
* 특정 거래의 분개 내역 저장 (기존 분개 삭제 후 재생성)
|
|
*/
|
|
public static function saveSplits(int $tenantId, string $uniqueKey, array $originalData, array $splits): void
|
|
{
|
|
// 기존 분개 삭제
|
|
self::where('tenant_id', $tenantId)
|
|
->where('original_unique_key', $uniqueKey)
|
|
->delete();
|
|
|
|
// 새 분개 저장
|
|
foreach ($splits as $index => $split) {
|
|
self::create([
|
|
'tenant_id' => $tenantId,
|
|
'original_unique_key' => $uniqueKey,
|
|
'split_amount' => $split['amount'] ?? 0,
|
|
'account_code' => $split['accountCode'] ?? null,
|
|
'account_name' => $split['accountName'] ?? null,
|
|
'description' => $split['description'] ?? null,
|
|
'memo' => $split['memo'] ?? null,
|
|
'sort_order' => $index,
|
|
'bank_account_num' => $originalData['bankAccountNum'] ?? '',
|
|
'trans_dt' => $originalData['transDt'] ?? '',
|
|
'trans_date' => $originalData['transDate'] ?? '',
|
|
'original_deposit' => $originalData['originalDeposit'] ?? 0,
|
|
'original_withdraw' => $originalData['originalWithdraw'] ?? 0,
|
|
'summary' => $originalData['summary'] ?? '',
|
|
]);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 분개 내역 삭제 (원본으로 복원)
|
|
*/
|
|
public static function deleteSplits(int $tenantId, string $uniqueKey): int
|
|
{
|
|
return self::where('tenant_id', $tenantId)
|
|
->where('original_unique_key', $uniqueKey)
|
|
->delete();
|
|
}
|
|
}
|