Introduce PDF generation capabilities for shipments using laravel-dompdf. This includes a new service layer, dedicated controller, and routes to handle the generation of Air Waybills (AWB), Invoices, and Shipping Labels. - Add `PdfService` to encapsulate PDF generation logic. - Add `ShipmentPdfController` to handle PDF download requests. - Integrate `barryvdh/laravel-dompdf` dependency. - Add Filament header actions to view shipment pages for quick PDF access. - Update order success view to provide direct download links for documents. - Add label methods to `ShipmentDirection` and `ShipmentType` enums. - Update project status documentation to reflect initial PDF implementation.
61 lines
2.1 KiB
PHP
61 lines
2.1 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Models\Shipment;
|
|
use App\Services\PdfService;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\Log;
|
|
|
|
class ShipmentPdfController extends Controller
|
|
{
|
|
public function __construct(protected PdfService $pdf) {}
|
|
|
|
public function awb(Shipment $shipment)
|
|
{
|
|
try {
|
|
Log::info('Generating AWB PDF', ['shipment_id' => $shipment->id]);
|
|
$content = $this->pdf->awb($shipment);
|
|
Log::info('AWB PDF generated successfully');
|
|
return response($content, 200, [
|
|
'Content-Type' => 'application/pdf',
|
|
'Content-Disposition' => 'attachment; filename="AWB-' . $shipment->awb_no . '.pdf"',
|
|
]);
|
|
} catch (\Throwable $e) {
|
|
Log::error('AWB PDF generation failed', [
|
|
'error' => $e->getMessage(),
|
|
'trace' => $e->getTraceAsString(),
|
|
]);
|
|
return response('PDF generation failed: ' . $e->getMessage(), 500);
|
|
}
|
|
}
|
|
|
|
public function invoice(Shipment $shipment)
|
|
{
|
|
try {
|
|
$content = $this->pdf->invoice($shipment);
|
|
return response($content, 200, [
|
|
'Content-Type' => 'application/pdf',
|
|
'Content-Disposition' => 'attachment; filename="INVOICE-' . $shipment->awb_no . '.pdf"',
|
|
]);
|
|
} catch (\Throwable $e) {
|
|
Log::error('Invoice PDF generation failed', ['error' => $e->getMessage()]);
|
|
return response('PDF generation failed: ' . $e->getMessage(), 500);
|
|
}
|
|
}
|
|
|
|
public function label(Shipment $shipment)
|
|
{
|
|
try {
|
|
$content = $this->pdf->label($shipment);
|
|
return response($content, 200, [
|
|
'Content-Type' => 'application/pdf',
|
|
'Content-Disposition' => 'attachment; filename="LABEL-' . $shipment->awb_no . '.pdf"',
|
|
]);
|
|
} catch (\Throwable $e) {
|
|
Log::error('Label PDF generation failed', ['error' => $e->getMessage()]);
|
|
return response('PDF generation failed: ' . $e->getMessage(), 500);
|
|
}
|
|
}
|
|
}
|