2026-02-11 10:24:39 +09:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Models\Finance;
|
|
|
|
|
|
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
|
|
|
|
|
|
class CorporateCardPrepayment extends Model
|
|
|
|
|
{
|
|
|
|
|
protected $table = 'corporate_card_prepayments';
|
|
|
|
|
|
2026-02-20 10:32:58 +09:00
|
|
|
protected $fillable = ['tenant_id', 'year_month', 'amount', 'memo', 'items'];
|
|
|
|
|
|
|
|
|
|
protected $casts = [
|
|
|
|
|
'items' => 'array',
|
|
|
|
|
];
|
2026-02-11 10:24:39 +09:00
|
|
|
|
|
|
|
|
public function scopeForTenant($query, int $tenantId)
|
|
|
|
|
{
|
|
|
|
|
return $query->where('tenant_id', $tenantId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static function getOrCreate(int $tenantId, string $yearMonth): self
|
|
|
|
|
{
|
|
|
|
|
return static::firstOrCreate(
|
|
|
|
|
['tenant_id' => $tenantId, 'year_month' => $yearMonth],
|
|
|
|
|
['amount' => 0, 'memo' => null]
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|