40 lines
1.2 KiB
PHP
40 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use App\Models\Concerns\BelongsToTenant;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
/** @property int $id
|
|
* @property int $tenant_id
|
|
* @property int $purchase_award_id
|
|
* @property int $purchase_control_policy_id
|
|
* @property int $created_by
|
|
* @property string $status
|
|
* @property string $basis_hash
|
|
* @property array<string,mixed> $snapshot
|
|
*/
|
|
class AwardCancellation extends Model
|
|
{
|
|
use BelongsToTenant;
|
|
|
|
protected $guarded = ['id'];
|
|
|
|
protected $attributes = ['status' => 'pending'];
|
|
|
|
protected function casts(): array
|
|
{
|
|
return ['snapshot' => 'array'];
|
|
}
|
|
|
|
protected static function booted(): void
|
|
{
|
|
static::updating(function (AwardCancellation $cancellation) {
|
|
if ($cancellation->getRawOriginal('status') !== 'pending' || array_diff(array_keys($cancellation->getDirty()), ['status', 'reviewed_by', 'review_reason', 'reviewed_at', 'updated_at']) !== []) {
|
|
throw new \LogicException('Preservar o pedido de cancelamento e a decisão.');
|
|
}
|
|
});
|
|
static::deleting(fn () => throw new \LogicException('Preservar o histórico de cancelamento.'));
|
|
}
|
|
}
|