ifnex/04_Laravel/app/Models/AuditLog.php
Kazem Alghasi 02c29db696 feat(core): implement order approval flow, credit system, and import invoicing
Introduce a comprehensive set of commercial features including a multi-step
order approval workflow, customer credit management, and specialized
import service invoicing.

Key changes:
- Implement `pending_approval` and `approved` shipment statuses to allow
  staff verification before customer payment.
- Add a credit system to `User` model with `credit_limit` and `credit_used`
  to manage customer balances and debts.
- Develop a new `importInvoice` PDF generation service following the
  "Sheet ENG Invoice" specification for import services.
- Add Filament resources for managing Audit Logs, Commitment Forms,
  Customer Credits, and Shipment Checklists.
- Implement staff-specific APIs for order approval/rejection and
  customer financial status monitoring.
- Integrate Kavenegar SMS service for mobile verification and notifications.
- Add bulk tracking import functionality via CSV/Excel.
- Update WordPress bridge assets (CSS/JS) to support the new multi-step
  order form UI and updated redirection logic.
- Update deployment configurations and documentation to reflect new
  production domains and feature sets.
2026-09-03 06:04:20 +03:30

66 lines
1.6 KiB
PHP

<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
class AuditLog extends Model
{
use HasFactory;
protected $table = 'audit_logs';
protected $fillable = [
'user_id',
'event',
'auditable_type',
'auditable_id',
'old_values',
'new_values',
'description',
'ip_address',
'user_agent',
];
protected $casts = [
'old_values' => 'array',
'new_values' => 'array',
];
// ─── Relationships ───────────────────────────────
public function user(): BelongsTo
{
return $this->belongsTo(User::class);
}
public function auditable()
{
return $this->morphTo();
}
// ─── Helper Methods ──────────────────────────────
public static function log(
string $event,
Model $model,
array $oldValues = [],
array $newValues = [],
?string $description = null
): self {
return static::create([
'user_id' => auth()->id(),
'event' => $event,
'auditable_type' => get_class($model),
'auditable_id' => $model->getKey(),
'old_values' => $oldValues,
'new_values' => $newValues,
'description' => $description,
'ip_address' => request()->ip(),
'user_agent' => request()->userAgent(),
]);
}
}