Files
sam-api/app/Models/Barobill/BarobillBankTransactionSplit.php

70 lines
1.9 KiB
PHP
Raw Normal View History

<?php
namespace App\Models\Barobill;
use App\Traits\BelongsToTenant;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
class BarobillBankTransactionSplit extends Model
{
use BelongsToTenant;
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(\App\Models\Tenants\Tenant::class);
}
// =========================================================================
// 헬퍼 메서드
// =========================================================================
public static function getByDateRange(int $tenantId, string $startDate, string $endDate)
{
return static::where('tenant_id', $tenantId)
->whereBetween('trans_date', [$startDate, $endDate])
->orderBy('original_unique_key')
->orderBy('sort_order')
->get()
->groupBy('original_unique_key');
}
public static function getByUniqueKey(int $tenantId, string $uniqueKey)
{
return static::where('tenant_id', $tenantId)
->where('original_unique_key', $uniqueKey)
->orderBy('sort_order')
->get();
}
}