26 lines
632 B
PHP
26 lines
632 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'];
|
||
|
|
|
||
|
|
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]
|
||
|
|
);
|
||
|
|
}
|
||
|
|
}
|