Introduce a complete workflow for managing shipment-related documents
and mandatory commitment forms between the Laravel backend and
WordPress frontend.
- Laravel:
- Add `ShipmentCommitmentForm` model and migration to track signed
forms per shipment.
- Implement `CommitmentFormController` to handle fetching available
forms and uploading signed documents.
- Add PDF download endpoints for AWB, labels, and invoices via
`ShipmentPdfController`.
- Extend `User` model with notification management methods.
- Add `FinanceOverviewWidget` for Filament dashboard.
- WordPress:
- Implement AJAX handlers in `user-bridge.php` for PDF downloads and
commitment form management.
- Update `shortcodes.php` to display document download grid and
dynamic commitment form upload interface in order details.
- Add styling for document buttons and form status indicators in
`ifnex-orders.css`.
105 lines
2.9 KiB
PHP
105 lines
2.9 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Foundation\Auth\User as Authenticatable;
|
|
use Illuminate\Notifications\DatabaseNotification;
|
|
use Illuminate\Notifications\Notifiable;
|
|
use Laravel\Sanctum\HasApiTokens;
|
|
use Spatie\Permission\Traits\HasRoles;
|
|
|
|
class User extends Authenticatable
|
|
{
|
|
use HasApiTokens, HasFactory, Notifiable, HasRoles;
|
|
|
|
protected $fillable = [
|
|
'name',
|
|
'email',
|
|
'password',
|
|
'phone',
|
|
'role', // فیلد قدیمی - بعداً حذف میکنیم
|
|
'credit_limit', // سقف اعتبار
|
|
'credit_used', // مبلغ استفاده شده از اعتبار
|
|
];
|
|
|
|
protected $hidden = [
|
|
'password',
|
|
'remember_token',
|
|
];
|
|
|
|
protected function casts(): array
|
|
{
|
|
return [
|
|
'email_verified_at' => 'datetime',
|
|
'password' => 'hashed',
|
|
'credit_limit' => 'decimal:2',
|
|
'credit_used' => 'decimal:2',
|
|
];
|
|
}
|
|
|
|
// ─── Relationships ───────────────────────────────
|
|
|
|
public function wallet()
|
|
{
|
|
return $this->hasOne(Wallet::class);
|
|
}
|
|
|
|
public function notifications()
|
|
{
|
|
return $this->morphMany(DatabaseNotification::class, 'notifiable')->orderByDesc('created_at');
|
|
}
|
|
|
|
// ─── Helper Methods (Role Checks) ────────────────
|
|
|
|
public function isSuperAdmin(): bool
|
|
{
|
|
return $this->hasRole('super_admin');
|
|
}
|
|
|
|
public function isAdmin(): bool
|
|
{
|
|
return $this->hasAnyRole(['super_admin', 'admin']);
|
|
}
|
|
|
|
public function isStaff(): bool
|
|
{
|
|
return $this->hasRole('staff');
|
|
}
|
|
|
|
public function isCustomer(): bool
|
|
{
|
|
return $this->hasRole('customer');
|
|
}
|
|
|
|
public function markNotificationRead(string $notificationId): bool
|
|
{
|
|
$notification = $this->notifications()->where('id', $notificationId)->first();
|
|
if ($notification) {
|
|
$notification->markAsRead();
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
// ─── Credit Methods ──────────────────────────────
|
|
|
|
public function getAvailableCreditAttribute(): float
|
|
{
|
|
return $this->credit_limit - $this->credit_used;
|
|
}
|
|
|
|
public function hasAvailableCredit(float $amount): bool
|
|
{
|
|
return $this->available_credit >= $amount;
|
|
}
|
|
|
|
// ─── Filament Panel Access ───────────────────────
|
|
|
|
public function canAccessPanel(\Filament\Panel $panel): bool
|
|
{
|
|
// فقط super_admin, admin, staff میتوانند به پنل ادمین دسترسی داشته باشند
|
|
// customer فقط از API استفاده میکند
|
|
return $this->hasAnyRole(['super_admin', 'admin', 'staff']);
|
|
}
|
|
} |