Version 2.0

This commit is contained in:
2026-05-12 09:23:05 +00:00
parent f2bc048219
commit f1b68e5e78
34 changed files with 564 additions and 283 deletions

View File

@@ -7,9 +7,30 @@ use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;
#[Fillable(['product_id', 'customer_id', 'type', 'start_date', 'end_date', 'status', 'printed_at', 'signed_status'])]
#[Fillable(['product_id', 'customer_id', 'type', 'category', 'start_date', 'end_date', 'status', 'printed_at', 'signed_status', 'representative_name', 'representative_phone', 'representative_email'])]
class Contract extends Model
{
protected static function booted(): void
{
static::saving(function (self $contract) {
if ($contract->status === 'active') {
$exists = self::where('product_id', $contract->product_id)
->where('category', $contract->category)
->where('status', 'active')
->when($contract->exists, fn ($q) => $q->where('id', '!=', $contract->id))
->exists();
if ($exists) {
throw new \RuntimeException(
__('feedback.contract_duplicate_body', [
'product' => $contract->product?->name ?? $contract->product_id,
'customer' => $contract->customer?->name ?? '?',
])
);
}
}
});
}
protected function casts(): array
{
return [