Introduces a complete shipment review system allowing staff to request changes to customer orders and customers to resubmit corrected orders. - Add `ReviewState` enum and `ShipmentReview` model to track review history. - Implement `ShipmentReviewService` to handle approval and change request logic. - Add `resubmit` endpoint for customers to update orders when `changes_requested` state is active. - Add `request-changes` endpoint for staff to flag orders for correction. - Update `ShipmentResource` in Filament to display review states and manage approvals. - Implement WordPress bridge support for fetching and resubmitting orders via AJAX. - Add database migrations for `shipment_reviews` table and `review_state` column on shipments. - Add `StaffApiMiddleware` to secure staff-specific API routes.
54 lines
1.2 KiB
PHP
54 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
|
|
class ShipmentReview extends Model
|
|
{
|
|
protected $fillable = [
|
|
'shipment_id',
|
|
'revision_no',
|
|
'decision',
|
|
'reason',
|
|
'notes',
|
|
'reviewed_by',
|
|
'reviewed_at',
|
|
];
|
|
|
|
protected $casts = [
|
|
'revision_no' => 'integer',
|
|
'reviewed_at' => 'datetime',
|
|
];
|
|
|
|
protected static function booted(): void
|
|
{
|
|
static::creating(function (self $model) {
|
|
if (
|
|
$model->decision !== 'pending' &&
|
|
empty($model->reviewed_by) &&
|
|
auth()->check()
|
|
) {
|
|
$model->reviewed_by = auth()->id();
|
|
}
|
|
|
|
if (
|
|
$model->decision !== 'pending' &&
|
|
empty($model->reviewed_at)
|
|
) {
|
|
$model->reviewed_at = now();
|
|
}
|
|
});
|
|
}
|
|
|
|
public function shipment(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Shipment::class);
|
|
}
|
|
|
|
public function reviewedBy(): BelongsTo
|
|
{
|
|
return $this->belongsTo(User::class, 'reviewed_by');
|
|
}
|
|
} |