79 lines
2.1 KiB
PHP
79 lines
2.1 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
namespace App\Models\Barobill;
|
||
|
|
|
||
|
|
use App\Traits\BelongsToTenant;
|
||
|
|
use Illuminate\Database\Eloquent\Model;
|
||
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||
|
|
|
||
|
|
class HometaxInvoiceJournal extends Model
|
||
|
|
{
|
||
|
|
use BelongsToTenant;
|
||
|
|
|
||
|
|
protected $table = 'hometax_invoice_journals';
|
||
|
|
|
||
|
|
protected $fillable = [
|
||
|
|
'tenant_id',
|
||
|
|
'hometax_invoice_id',
|
||
|
|
'nts_confirm_num',
|
||
|
|
'dc_type',
|
||
|
|
'account_code',
|
||
|
|
'account_name',
|
||
|
|
'debit_amount',
|
||
|
|
'credit_amount',
|
||
|
|
'description',
|
||
|
|
'sort_order',
|
||
|
|
'invoice_type',
|
||
|
|
'write_date',
|
||
|
|
'supply_amount',
|
||
|
|
'tax_amount',
|
||
|
|
'total_amount',
|
||
|
|
'trading_partner_name',
|
||
|
|
];
|
||
|
|
|
||
|
|
protected $casts = [
|
||
|
|
'debit_amount' => 'integer',
|
||
|
|
'credit_amount' => 'integer',
|
||
|
|
'sort_order' => 'integer',
|
||
|
|
'supply_amount' => 'integer',
|
||
|
|
'tax_amount' => 'integer',
|
||
|
|
'total_amount' => 'integer',
|
||
|
|
'write_date' => 'date',
|
||
|
|
];
|
||
|
|
|
||
|
|
// =========================================================================
|
||
|
|
// 관계 정의
|
||
|
|
// =========================================================================
|
||
|
|
|
||
|
|
public function tenant(): BelongsTo
|
||
|
|
{
|
||
|
|
return $this->belongsTo(\App\Models\Tenants\Tenant::class);
|
||
|
|
}
|
||
|
|
|
||
|
|
public function invoice(): BelongsTo
|
||
|
|
{
|
||
|
|
return $this->belongsTo(HometaxInvoice::class, 'hometax_invoice_id');
|
||
|
|
}
|
||
|
|
|
||
|
|
// =========================================================================
|
||
|
|
// 헬퍼 메서드
|
||
|
|
// =========================================================================
|
||
|
|
|
||
|
|
public static function getByInvoiceId(int $tenantId, int $invoiceId)
|
||
|
|
{
|
||
|
|
return static::where('tenant_id', $tenantId)
|
||
|
|
->where('hometax_invoice_id', $invoiceId)
|
||
|
|
->orderBy('sort_order')
|
||
|
|
->get();
|
||
|
|
}
|
||
|
|
|
||
|
|
public static function getJournaledInvoiceIds(int $tenantId, array $invoiceIds): array
|
||
|
|
{
|
||
|
|
return static::where('tenant_id', $tenantId)
|
||
|
|
->whereIn('hometax_invoice_id', $invoiceIds)
|
||
|
|
->distinct()
|
||
|
|
->pluck('hometax_invoice_id')
|
||
|
|
->toArray();
|
||
|
|
}
|
||
|
|
}
|