30 lines
702 B
PHP
30 lines
702 B
PHP
<?php
|
|
|
|
namespace App\Models\Finance;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
class CorporateCardPrepayment extends Model
|
|
{
|
|
protected $table = 'corporate_card_prepayments';
|
|
|
|
protected $fillable = ['tenant_id', 'year_month', 'amount', 'memo', 'items'];
|
|
|
|
protected $casts = [
|
|
'items' => 'array',
|
|
];
|
|
|
|
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]
|
|
);
|
|
}
|
|
}
|