ifnex/04_Laravel/app/Models/ShipmentChecklistTemplate.php
Kazem Alghasi b9b83ffecf feat(shipment): implement checklist templating and automated instantiation
Introduce a template-based system for shipment checklists to automate
the creation of required inspection items upon shipment approval.

- Add `ShipmentChecklistTemplate` model and migration to define reusable
  checklist structures.
- Extend `ShipmentChecklist` schema to support item titles, requirement
  flags, sorting, and attachment paths.
- Implement `instantiateChecklist` in `ShipmentReviewService` to
  automatically generate checklist items from active templates based on
  shipment direction (import/export).
- Refactor `ShipmentChecklistResource` and `ChecklistsRelationManager`
  in Filament to support the new data structure and improved UI.
- Update `ShipmentChecklist` model with helper methods for completion
  tracking and improved relationship handling.
2026-09-30 18:35:25 +03:30

46 lines
1.2 KiB
PHP

<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
class ShipmentChecklistTemplate extends Model
{
protected $fillable = [
'item_title',
'is_required',
'sort_order',
'direction',
'is_active',
'created_by',
];
protected $casts = [
'is_required' => 'boolean',
'is_active' => 'boolean',
'sort_order' => 'integer',
];
public function createdBy(): BelongsTo
{
return $this->belongsTo(User::class, 'created_by');
}
// ─── Scopes ───────────────────────────────────────
public function scopeActive($query)
{
return $query->where('is_active', true);
}
/**
* قالب‌هایی که به جهت مشخص (export/import/both) اعمال می‌شوند.
*/
public function scopeForDirection($query, string $direction)
{
return $query->where(function ($q) use ($direction) {
$q->where('direction', 'both')->orWhere('direction', $direction);
});
}
}