@@ -5,9 +5,15 @@ namespace App\Models;
|
||||
use App\Models\Concerns\BelongsToTenant;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
/** @property array{country:string,catalogue:string,record_id:string}|null $geography_reference */
|
||||
class Equipment extends Model
|
||||
{
|
||||
use BelongsToTenant;
|
||||
|
||||
protected $guarded = ['id'];
|
||||
|
||||
protected function casts(): array
|
||||
{
|
||||
return ['geography_reference' => 'array'];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Models\Concerns\BelongsToTenant;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use LogicException;
|
||||
|
||||
/** @property array<string,mixed> $snapshot */
|
||||
class OrderCancellation 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 (self $record) {
|
||||
if ($record->getRawOriginal('status') === 'pending' && (! in_array($record->status, ['approved', 'rejected'], true)
|
||||
|| $record->reviewed_by === null || $record->reviewed_at === null || trim((string) $record->review_reason) === '')) {
|
||||
throw new LogicException('Decisão completa e definitiva obrigatória.');
|
||||
}
|
||||
$allowed = $record->getRawOriginal('status') === 'pending' ? ['status', 'reviewed_by', 'review_reason', 'reviewed_at', 'updated_at']
|
||||
: ($record->getRawOriginal('status') === 'approved' && $record->getRawOriginal('revised_requisition_id') === null ? ['revised_requisition_id', 'updated_at'] : []);
|
||||
if (array_diff(array_keys($record->getDirty()), $allowed) !== []) {
|
||||
throw new LogicException('Preservar pedido e decisão de cancelamento.');
|
||||
}
|
||||
});
|
||||
static::deleting(fn () => throw new LogicException('Preservar cancelamento.'));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
class OrderCancellationPolicy extends PurchaseControlPolicy
|
||||
{
|
||||
protected $table = 'order_cancellation_policies';
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
class OrderCancellationPolicyReview extends PurchaseControlReview
|
||||
{
|
||||
protected $table = 'order_cancellation_policy_reviews';
|
||||
}
|
||||
@@ -7,6 +7,7 @@ use App\Models\Concerns\ImmutablePurchaseRecord;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
/**
|
||||
* @property int $id
|
||||
@@ -39,4 +40,15 @@ class PurchaseOrder extends Model
|
||||
{
|
||||
$query->whereIn('requisition_id', Requisition::query()->visibleTo($user)->select('id'));
|
||||
}
|
||||
|
||||
/** @param Builder<PurchaseOrder> $query */
|
||||
public function scopeOperational(Builder $query): void
|
||||
{
|
||||
$query->where('purchase_orders.status', 'issued');
|
||||
if (Schema::hasTable('order_cancellations')) {
|
||||
$query->whereNotExists(fn ($q) => $q->selectRaw('1')->from('order_cancellations as oc')
|
||||
->whereColumn('oc.purchase_order_id', 'purchase_orders.id')->whereColumn('oc.tenant_id', 'purchase_orders.tenant_id')
|
||||
->whereIn('oc.status', ['pending', 'approved']));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
/**
|
||||
* @property array{country:string,catalogue:string,record_id:string}|null $geography_reference
|
||||
* @property int $id
|
||||
* @property int $tenant_id
|
||||
* @property int $created_by
|
||||
@@ -23,7 +24,7 @@ class Supplier extends Model
|
||||
|
||||
protected function casts(): array
|
||||
{
|
||||
return ['blocked' => 'boolean', 'next_review' => 'date:Y-m-d'];
|
||||
return ['blocked' => 'boolean', 'next_review' => 'date:Y-m-d', 'geography_reference' => 'array'];
|
||||
}
|
||||
|
||||
public function eligible(): bool
|
||||
|
||||
@@ -5,6 +5,7 @@ namespace App\Models;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
/**
|
||||
* @property array{country:string,catalogue:string,record_id:string}|null $geography_reference
|
||||
* @property int $id
|
||||
* @property string $name
|
||||
* @property int $first_limit_minor
|
||||
@@ -22,6 +23,6 @@ class Tenant extends Model
|
||||
|
||||
protected function casts(): array
|
||||
{
|
||||
return ['work_context_policy' => 'array', 'approval_includes_tax' => 'boolean', 'rules_provisional' => 'boolean', 'default_tax_rate' => 'decimal:2', 'comparison_policy' => 'array', 'intelligence_policy' => 'array'];
|
||||
return ['geography_reference' => 'array', 'work_context_policy' => 'array', 'approval_includes_tax' => 'boolean', 'rules_provisional' => 'boolean', 'default_tax_rate' => 'decimal:2', 'comparison_policy' => 'array', 'intelligence_policy' => 'array'];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,9 +5,15 @@ namespace App\Models;
|
||||
use App\Models\Concerns\BelongsToTenant;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
/** @property array{country:string,catalogue:string,record_id:string}|null $geography_reference */
|
||||
class Warehouse extends Model
|
||||
{
|
||||
use BelongsToTenant;
|
||||
|
||||
protected $guarded = ['id'];
|
||||
|
||||
protected function casts(): array
|
||||
{
|
||||
return ['geography_reference' => 'array'];
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user