ifnex/04_Laravel/app/Exports/ShipmentsExport.php
Kazem Alghasi 8b0814230c feat(ui): implement unified design system and financial reporting
Introduce a comprehensive design system across WordPress and Laravel
to ensure visual consistency. Implement new financial reporting
capabilities and Excel export functionality within the Filament admin
panel.

- Add `DESIGN_SYSTEM.md` to define brand colors, typography, and spacing
- Implement `FinancialReport` page in Filament for transaction and
  shipment summaries
- Add Excel export support for `ShipmentResource` and
  `WalletTransactionResource` using Laravel Excel
- Refactor WordPress plugin and Filament CSS to utilize the new
  design system variables
- Update project status to reflect new reporting and design milestones
2026-08-08 06:13:09 +03:30

114 lines
3.4 KiB
PHP

<?php
namespace App\Exports;
use App\Models\Shipment;
use Maatwebsite\Excel\Concerns\FromQuery;
use Maatwebsite\Excel\Concerns\WithHeadings;
use Maatwebsite\Excel\Concerns\WithMapping;
use Maatwebsite\Excel\Concerns\WithStyles;
use Maatwebsite\Excel\Concerns\ShouldAutoSize;
use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
class ShipmentsExport implements FromQuery, WithHeadings, WithMapping, WithStyles, ShouldAutoSize
{
protected $filters;
public function __construct(array $filters = [])
{
$this->filters = $filters;
}
public function query()
{
$query = Shipment::query()
->with(['fromCountry', 'toCountry', 'carrierMappings', 'items'])
->orderByDesc('created_at');
if (!empty($this->filters['status'])) {
$query->where('status', $this->filters['status']);
}
if (!empty($this->filters['type'])) {
$query->where('type', $this->filters['type']);
}
if (!empty($this->filters['direction'])) {
$query->where('direction', $this->filters['direction']);
}
if (!empty($this->filters['from_date'])) {
$query->where('created_at', '>=', $this->filters['from_date']);
}
if (!empty($this->filters['to_date'])) {
$query->where('created_at', '<=', $this->filters['to_date']);
}
return $query;
}
public function headings(): array
{
return [
'AWB No.',
'جهت',
'نوع',
'وضعیت',
'کشور مبدا',
'کشور مقصد',
'وزن واقعی (kg)',
'وزن حجمی (kg)',
'وزن قابل پرداخت (kg)',
'قیمت حمل (درهم)',
'خدمات اضافی (درهم)',
'هزینه بسته‌بندی (ریال)',
'دریافت داخلی (ریال)',
'تحویل داخلی (ریال)',
'هزینه انبار (ریال)',
'تخفیف (ریال)',
'هزینه کل (ریال)',
'فرستنده',
'تلفن فرستنده',
'گیرنده',
'تلفن گیرنده',
'تاریخ ایجاد',
];
}
public function map($shipment): array
{
return [
$shipment->awb_no,
$shipment->direction->label(),
$shipment->type->label(),
$shipment->status->label(),
$shipment->fromCountry->name ?? '-',
$shipment->toCountry->name ?? '-',
$shipment->weight ?? 0,
$shipment->volumetric_weight ?? 0,
$shipment->chargeable_weight ?? 0,
$shipment->shipping_price ?? 0,
$shipment->extra_service ?? 0,
$shipment->packing_cost ?? 0,
$shipment->domestic_pickup ?? 0,
$shipment->domestic_delivery ?? 0,
$shipment->warehousing_cost ?? 0,
$shipment->discount ?? 0,
$shipment->total_fee ?? 0,
$shipment->sender_name ?? '-',
$shipment->sender_phone ?? '-',
$shipment->receiver_name ?? '-',
$shipment->receiver_phone ?? '-',
$shipment->created_at?->format('Y/m/d H:i'),
];
}
public function styles(Worksheet $sheet)
{
return [
1 => ['font' => ['bold' => true, 'size' => 12]],
];
}
}