Consolida recepcoes, stock, equipamentos e identidade SGC

This commit is contained in:
2026-10-28 13:54:53 +02:00
parent eb1c8b8074
commit 75ffdb395c
76 changed files with 6933 additions and 152 deletions
@@ -0,0 +1,14 @@
<?php
namespace App\Models\Concerns;
use LogicException;
trait AppendOnlyInventoryRecord
{
protected static function bootAppendOnlyInventoryRecord(): void
{
static::updating(fn () => throw new LogicException('O histórico de recepção e stock não pode ser reescrito.'));
static::deleting(fn () => throw new LogicException('O histórico de recepção e stock não pode ser eliminado.'));
}
}
+23
View File
@@ -0,0 +1,23 @@
<?php
namespace App\Models;
use App\Models\Concerns\AppendOnlyInventoryRecord;
use App\Models\Concerns\BelongsToTenant;
use Illuminate\Database\Eloquent\Model;
class CriticalityLevel extends Model
{
use AppendOnlyInventoryRecord;
use BelongsToTenant;
public $timestamps = false;
protected $guarded = ['id'];
/** @return array<string,string> */
protected function casts(): array
{
return ['is_critical' => 'boolean'];
}
}
+13
View File
@@ -0,0 +1,13 @@
<?php
namespace App\Models;
use App\Models\Concerns\BelongsToTenant;
use Illuminate\Database\Eloquent\Model;
class Equipment extends Model
{
use BelongsToTenant;
protected $guarded = ['id'];
}
+17
View File
@@ -0,0 +1,17 @@
<?php
namespace App\Models;
use App\Models\Concerns\AppendOnlyInventoryRecord;
use App\Models\Concerns\BelongsToTenant;
use Illuminate\Database\Eloquent\Model;
class EquipmentSparePart extends Model
{
use AppendOnlyInventoryRecord;
use BelongsToTenant;
public $timestamps = false;
protected $guarded = ['id'];
}
+36
View File
@@ -0,0 +1,36 @@
<?php
namespace App\Models;
use App\Models\Concerns\AppendOnlyInventoryRecord;
use App\Models\Concerns\BelongsToTenant;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;
/**
* @property int $id
* @property int $tenant_id
* @property int $purchase_order_id
* @property int $received_by
* @property string $payload_hash
* @property array<string, mixed> $snapshot
*/
class GoodsReceipt extends Model
{
use AppendOnlyInventoryRecord, BelongsToTenant;
public $timestamps = false;
protected $guarded = ['id'];
protected function casts(): array
{
return ['snapshot' => 'array', 'received_on' => 'date:Y-m-d', 'confirmed_at' => 'datetime'];
}
/** @return HasMany<GoodsReceiptItem, $this> */
public function items(): HasMany
{
return $this->hasMany(GoodsReceiptItem::class)->orderBy('id');
}
}
+21
View File
@@ -0,0 +1,21 @@
<?php
namespace App\Models;
use App\Models\Concerns\AppendOnlyInventoryRecord;
use App\Models\Concerns\BelongsToTenant;
use Illuminate\Database\Eloquent\Model;
class GoodsReceiptItem extends Model
{
use AppendOnlyInventoryRecord, BelongsToTenant;
public $timestamps = false;
protected $guarded = ['id'];
protected function casts(): array
{
return ['snapshot' => 'array'];
}
}
+5
View File
@@ -6,6 +6,11 @@ use App\Models\Concerns\BelongsToTenant;
use App\Models\Concerns\ImmutablePurchaseRecord;
use Illuminate\Database\Eloquent\Model;
/**
* @property string $quantity
* @property int|null $equipment_id
* @property int|null $spare_part_id
*/
class PurchaseOrderItem extends Model
{
use BelongsToTenant, ImmutablePurchaseRecord;
+2
View File
@@ -10,6 +10,8 @@ use Illuminate\Database\Eloquent\Model;
*
* @property string $quantity
* @property string $tax_rate
* @property int|null $equipment_id
* @property int|null $spare_part_id
*/
class RequisitionItem extends Model
{
+13
View File
@@ -0,0 +1,13 @@
<?php
namespace App\Models;
use App\Models\Concerns\BelongsToTenant;
use Illuminate\Database\Eloquent\Model;
class SparePart extends Model
{
use BelongsToTenant;
protected $guarded = ['id'];
}
+13
View File
@@ -0,0 +1,13 @@
<?php
namespace App\Models;
use App\Models\Concerns\BelongsToTenant;
use Illuminate\Database\Eloquent\Model;
class StockItem extends Model
{
use BelongsToTenant;
protected $guarded = ['id'];
}
+21
View File
@@ -0,0 +1,21 @@
<?php
namespace App\Models;
use App\Models\Concerns\AppendOnlyInventoryRecord;
use App\Models\Concerns\BelongsToTenant;
use Illuminate\Database\Eloquent\Model;
class StockMovement extends Model
{
use AppendOnlyInventoryRecord, BelongsToTenant;
public $timestamps = false;
protected $guarded = ['id'];
protected function casts(): array
{
return ['snapshot' => 'array', 'moved_at' => 'datetime'];
}
}
+27
View File
@@ -0,0 +1,27 @@
<?php
namespace App\Models;
use App\Models\Concerns\AppendOnlyInventoryRecord;
use App\Models\Concerns\BelongsToTenant;
use Illuminate\Database\Eloquent\Model;
/**
* @property array<string, mixed> $snapshot
* @property int|null $equipment_id
* @property int|null $spare_part_id
*/
class StockOperation extends Model
{
use AppendOnlyInventoryRecord, BelongsToTenant;
public $timestamps = false;
protected $guarded = ['id'];
/** @return array<string, string> */
protected function casts(): array
{
return ['snapshot' => 'array', 'recorded_at' => 'datetime', 'quantity_milli' => 'integer', 'theoretical_milli' => 'integer', 'ledger_version' => 'integer'];
}
}
+23
View File
@@ -0,0 +1,23 @@
<?php
namespace App\Models;
use App\Models\Concerns\AppendOnlyInventoryRecord;
use App\Models\Concerns\BelongsToTenant;
use Illuminate\Database\Eloquent\Model;
class TechnicalReview extends Model
{
use AppendOnlyInventoryRecord;
use BelongsToTenant;
public $timestamps = false;
protected $guarded = ['id'];
/** @return array<string,string> */
protected function casts(): array
{
return ['snapshot' => 'array', 'reviewed_at' => 'datetime'];
}
}
+13
View File
@@ -0,0 +1,13 @@
<?php
namespace App\Models;
use App\Models\Concerns\BelongsToTenant;
use Illuminate\Database\Eloquent\Model;
class Warehouse extends Model
{
use BelongsToTenant;
protected $guarded = ['id'];
}