247 lines
7.3 KiB
PHP
247 lines
7.3 KiB
PHP
<?php
|
|
|
|
namespace Modules\M3\Services;
|
|
|
|
use setasign\Fpdi\Fpdi;
|
|
use Storage;
|
|
|
|
class BillOfLadingService
|
|
{
|
|
public function fillBillOfLading($data, $outputPath = null)
|
|
{
|
|
$templatePath = Storage::disk('public')->path('ETN-BOL2.pdf'); // storage_path('app/templates/ETN-BOL.pdf');
|
|
$newfile = 'BOL_' . $data['bol_number'] . '.pdf'; // was using time()
|
|
$outputPath = $outputPath ?? Storage::disk('public')->path($newfile); // storage_path('app/filled/BOL_' . $data['bol_number'] . '.pdf');
|
|
|
|
$pdf = new Fpdi;
|
|
|
|
// Set source file
|
|
$pageCount = $pdf->setSourceFile($templatePath);
|
|
|
|
// Import first page (you have 5 pages in your PDF)
|
|
$tplIdx = $pdf->importPage(1);
|
|
$pdf->AddPage();
|
|
$pdf->useTemplate($tplIdx);
|
|
|
|
// Set font
|
|
$pdf->SetFont('Helvetica', '', 10);
|
|
$pdf->SetTextColor(0, 0, 0);
|
|
// $pdf->SetLineWidth(50);
|
|
|
|
// Fill form fields at specific coordinates
|
|
// You'll need to adjust X,Y positions based on your PDF
|
|
|
|
// Bill of Lading No.
|
|
if (isset($data['bol_number'])) {
|
|
$pdf->SetXY(126, 44);
|
|
$pdf->Write(0, $data['bol_number']);
|
|
}
|
|
|
|
// Date
|
|
if (isset($data['date'])) {
|
|
$pdf->SetXY(171, 44);
|
|
$pdf->Write(0, $data['date']);
|
|
}
|
|
|
|
// Shipper No.
|
|
if (isset($data['shipper_no'])) {
|
|
$pdf->SetXY(126, 53);
|
|
$pdf->Write(0, $data['shipper_no']);
|
|
}
|
|
|
|
// Master Bill No
|
|
if (isset($data['master_bill_no'])) {
|
|
$pdf->SetXY(172, 54);
|
|
$pdf->Write(0, $data['master_bill_no']);
|
|
}
|
|
// Master Bill Yes
|
|
if (isset($data['master_bill_yes'])) {
|
|
$pdf->SetXY(183, 54);
|
|
$pdf->Write(0, $data['master_bill_yes']);
|
|
}
|
|
// Master Bill Drops
|
|
if (isset($data['master_bill_drops'])) {
|
|
$pdf->SetXY(194, 55);
|
|
$pdf->Write(0, $data['master_bill_drops']);
|
|
}
|
|
|
|
// Consignor (FROM)
|
|
if (isset($data['consignor_name'])) {
|
|
$pdf->SetXY(21, 44);
|
|
$pdf->Write(0, $data['consignor_name']);
|
|
}
|
|
if (isset($data['consignor_address1'])) {
|
|
$pdf->SetXY(21, 48);
|
|
$pdf->Write(0, $data['consignor_address1']);
|
|
}
|
|
if (isset($data['consignor_address2'])) {
|
|
$pdf->SetXY(21, 52);
|
|
$pdf->Write(0, $data['consignor_address2']);
|
|
}
|
|
if (isset($data['consignor_address3'])) {
|
|
$pdf->SetXY(21, 56);
|
|
$pdf->Write(0, $data['consignor_address3']);
|
|
}
|
|
|
|
// Consignee (TO)
|
|
if (isset($data['consignee_name'])) {
|
|
$pdf->SetXY(21, 72);
|
|
$pdf->Write(0, $data['consignee_name']);
|
|
}
|
|
if (isset($data['consignee_address1'])) {
|
|
$pdf->SetXY(21, 76);
|
|
$pdf->Write(0, $data['consignee_address1']);
|
|
}
|
|
if (isset($data['consignee_address2'])) {
|
|
$pdf->SetXY(21, 80);
|
|
$pdf->Write(0, $data['consignee_address2']);
|
|
}
|
|
if (isset($data['consignee_address3'])) {
|
|
$pdf->SetXY(21, 84);
|
|
$pdf->Write(0, $data['consignee_address3']);
|
|
}
|
|
|
|
// Freight Collect
|
|
if (isset($data['freight_collect'])) {
|
|
$pdf->SetXY(127, 90);
|
|
$pdf->Write(0, $data['freight_collect']);
|
|
}
|
|
|
|
// Carrier Name
|
|
if (isset($data['carrier_name'])) {
|
|
$pdf->SetXY(10, 100);
|
|
$pdf->Write(0, $data['carrier_name']);
|
|
}
|
|
|
|
// Pieces
|
|
if (isset($data['pieces'])) {
|
|
$pdf->SetXY(6, 142);
|
|
$pdf->Write(0, $data['pieces']);
|
|
}
|
|
|
|
// Line class
|
|
if (isset($data['line_class'])) {
|
|
$pdf->SetXY(145, 142);
|
|
$pdf->Write(0, $data['line_class']);
|
|
}
|
|
|
|
// Line weight
|
|
if (isset($data['line_weight'])) {
|
|
$pdf->SetXY(177, 142);
|
|
$pdf->Write(0, $data['line_weight']);
|
|
}
|
|
|
|
// Total pieces
|
|
if (isset($data['total_pieces'])) {
|
|
$pdf->SetXY(6, 244);
|
|
$pdf->Write(0, $data['total_pieces']);
|
|
}
|
|
|
|
// Total weight
|
|
if (isset($data['total_line_weight'])) {
|
|
$pdf->SetXY(177, 244);
|
|
$pdf->Write(0, $data['total_line_weight']);
|
|
}
|
|
|
|
// Description of articles
|
|
if (isset($data['description'])) {
|
|
$pdf->SetXY(28, 140);
|
|
$pdf->MultiCell(67, 4.5, $data['description'], 0, 'L');
|
|
}
|
|
|
|
// Add more pages if needed (pages 2-5)
|
|
// Repeat for other pages as needed
|
|
$tplIdx = $pdf->importPage(2);
|
|
$pdf->AddPage();
|
|
$pdf->useTemplate($tplIdx);
|
|
|
|
// Bill of Lading No.
|
|
if (isset($data['bol_number'])) {
|
|
$pdf->SetXY(126, 44);
|
|
$pdf->Write(0, $data['bol_number']);
|
|
}
|
|
|
|
// Date
|
|
if (isset($data['date'])) {
|
|
$pdf->SetXY(171, 44);
|
|
$pdf->Write(0, $data['date']);
|
|
}
|
|
|
|
// Shipper No.
|
|
if (isset($data['shipper_no'])) {
|
|
$pdf->SetXY(126, 53);
|
|
$pdf->Write(0, $data['shipper_no']);
|
|
}
|
|
|
|
// Master Bill No
|
|
if (isset($data['master_bill_no'])) {
|
|
$pdf->SetXY(172, 54);
|
|
$pdf->Write(0, $data['master_bill_no']);
|
|
}
|
|
// Master Bill Yes
|
|
if (isset($data['master_bill_yes'])) {
|
|
$pdf->SetXY(183, 54);
|
|
$pdf->Write(0, $data['master_bill_yes']);
|
|
}
|
|
// Master Bill Drops
|
|
if (isset($data['master_bill_drops'])) {
|
|
$pdf->SetXY(194, 55);
|
|
$pdf->Write(0, $data['master_bill_drops']);
|
|
}
|
|
|
|
// Consignor (FROM)
|
|
if (isset($data['consignor_name'])) {
|
|
$pdf->SetXY(21, 44);
|
|
$pdf->Write(0, $data['consignor_name']);
|
|
}
|
|
if (isset($data['consignor_address1'])) {
|
|
$pdf->SetXY(21, 48);
|
|
$pdf->Write(0, $data['consignor_address1']);
|
|
}
|
|
if (isset($data['consignor_address2'])) {
|
|
$pdf->SetXY(21, 52);
|
|
$pdf->Write(0, $data['consignor_address2']);
|
|
}
|
|
if (isset($data['consignor_address3'])) {
|
|
$pdf->SetXY(21, 56);
|
|
$pdf->Write(0, $data['consignor_address3']);
|
|
}
|
|
|
|
// Consignee (TO)
|
|
if (isset($data['consignee_name'])) {
|
|
$pdf->SetXY(21, 72);
|
|
$pdf->Write(0, $data['consignee_name']);
|
|
}
|
|
if (isset($data['consignee_address1'])) {
|
|
$pdf->SetXY(21, 76);
|
|
$pdf->Write(0, $data['consignee_address1']);
|
|
}
|
|
if (isset($data['consignee_address2'])) {
|
|
$pdf->SetXY(21, 80);
|
|
$pdf->Write(0, $data['consignee_address2']);
|
|
}
|
|
if (isset($data['consignee_address3'])) {
|
|
$pdf->SetXY(21, 84);
|
|
$pdf->Write(0, $data['consignee_address3']);
|
|
}
|
|
|
|
// Freight Collect
|
|
if (isset($data['freight_collect'])) {
|
|
$pdf->SetXY(127, 90);
|
|
$pdf->Write(0, $data['freight_collect']);
|
|
}
|
|
|
|
// Carrier Name
|
|
if (isset($data['carrier_name'])) {
|
|
$pdf->SetXY(10, 100);
|
|
$pdf->Write(0, $data['carrier_name']);
|
|
}
|
|
|
|
// KD : add fields as you need
|
|
// Save the PDF
|
|
$pdf->Output('F', $outputPath);
|
|
|
|
return $outputPath;
|
|
}
|
|
}
|