m3 Security Fixes
This commit is contained in:
@@ -2,35 +2,35 @@
|
||||
|
||||
namespace Modules\M3\Services;
|
||||
|
||||
use Storage;
|
||||
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');
|
||||
$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;
|
||||
|
||||
$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);
|
||||
|
||||
// $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);
|
||||
@@ -42,7 +42,7 @@ class BillOfLadingService
|
||||
$pdf->SetXY(171, 44);
|
||||
$pdf->Write(0, $data['date']);
|
||||
}
|
||||
|
||||
|
||||
// Shipper No.
|
||||
if (isset($data['shipper_no'])) {
|
||||
$pdf->SetXY(126, 53);
|
||||
@@ -64,7 +64,7 @@ class BillOfLadingService
|
||||
$pdf->SetXY(194, 55);
|
||||
$pdf->Write(0, $data['master_bill_drops']);
|
||||
}
|
||||
|
||||
|
||||
// Consignor (FROM)
|
||||
if (isset($data['consignor_name'])) {
|
||||
$pdf->SetXY(21, 44);
|
||||
@@ -82,7 +82,7 @@ class BillOfLadingService
|
||||
$pdf->SetXY(21, 56);
|
||||
$pdf->Write(0, $data['consignor_address3']);
|
||||
}
|
||||
|
||||
|
||||
// Consignee (TO)
|
||||
if (isset($data['consignee_name'])) {
|
||||
$pdf->SetXY(21, 72);
|
||||
@@ -101,7 +101,7 @@ class BillOfLadingService
|
||||
$pdf->Write(0, $data['consignee_address3']);
|
||||
}
|
||||
|
||||
//Freight Collect
|
||||
// Freight Collect
|
||||
if (isset($data['freight_collect'])) {
|
||||
$pdf->SetXY(127, 90);
|
||||
$pdf->Write(0, $data['freight_collect']);
|
||||
@@ -112,13 +112,13 @@ class BillOfLadingService
|
||||
$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);
|
||||
@@ -136,19 +136,19 @@ class BillOfLadingService
|
||||
$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);
|
||||
@@ -166,7 +166,7 @@ class BillOfLadingService
|
||||
$pdf->SetXY(171, 44);
|
||||
$pdf->Write(0, $data['date']);
|
||||
}
|
||||
|
||||
|
||||
// Shipper No.
|
||||
if (isset($data['shipper_no'])) {
|
||||
$pdf->SetXY(126, 53);
|
||||
@@ -188,7 +188,7 @@ class BillOfLadingService
|
||||
$pdf->SetXY(194, 55);
|
||||
$pdf->Write(0, $data['master_bill_drops']);
|
||||
}
|
||||
|
||||
|
||||
// Consignor (FROM)
|
||||
if (isset($data['consignor_name'])) {
|
||||
$pdf->SetXY(21, 44);
|
||||
@@ -206,7 +206,7 @@ class BillOfLadingService
|
||||
$pdf->SetXY(21, 56);
|
||||
$pdf->Write(0, $data['consignor_address3']);
|
||||
}
|
||||
|
||||
|
||||
// Consignee (TO)
|
||||
if (isset($data['consignee_name'])) {
|
||||
$pdf->SetXY(21, 72);
|
||||
@@ -225,7 +225,7 @@ class BillOfLadingService
|
||||
$pdf->Write(0, $data['consignee_address3']);
|
||||
}
|
||||
|
||||
//Freight Collect
|
||||
// Freight Collect
|
||||
if (isset($data['freight_collect'])) {
|
||||
$pdf->SetXY(127, 90);
|
||||
$pdf->Write(0, $data['freight_collect']);
|
||||
@@ -236,12 +236,11 @@ class BillOfLadingService
|
||||
$pdf->SetXY(10, 100);
|
||||
$pdf->Write(0, $data['carrier_name']);
|
||||
}
|
||||
|
||||
|
||||
# KD : add fields as you need
|
||||
// KD : add fields as you need
|
||||
// Save the PDF
|
||||
$pdf->Output('F', $outputPath);
|
||||
|
||||
|
||||
return $outputPath;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@ use Illuminate\Support\Facades\Schema;
|
||||
class PostgresProgramBridge
|
||||
{
|
||||
private string $errorCode = '';
|
||||
|
||||
private string $errorMessage = '';
|
||||
|
||||
public function setOptions(array $options): self
|
||||
@@ -91,6 +92,7 @@ class PostgresProgramBridge
|
||||
$this->errorCode = (string) $e->getCode();
|
||||
$this->errorMessage = $e->getMessage();
|
||||
Log::error('Unable to queue M3 program request.', ['exception' => $e]);
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@ class SpreadsheetExport
|
||||
{
|
||||
$path = storage_path('app/m3-exports/' . uniqid('', true) . '-' . basename($filename));
|
||||
$this->write($rows, $path);
|
||||
|
||||
return response()->download($path, basename($filename))->deleteFileAfterSend(true);
|
||||
}
|
||||
|
||||
@@ -25,16 +26,16 @@ class SpreadsheetExport
|
||||
if ($disk && config("filesystems.disks.$disk")) {
|
||||
Storage::disk($disk)->put($filename, file_get_contents($tmp));
|
||||
@unlink($tmp);
|
||||
|
||||
return $filename;
|
||||
}
|
||||
|
||||
return $tmp;
|
||||
}
|
||||
|
||||
|
||||
public function storeSheets(array $sheets, string $filename, ?string $disk = null): string
|
||||
{
|
||||
$book = new Spreadsheet();
|
||||
$book = new Spreadsheet;
|
||||
$book->removeSheetByIndex(0);
|
||||
foreach ($sheets as $title => $rows) {
|
||||
$sheet = $book->createSheet();
|
||||
@@ -45,13 +46,17 @@ class SpreadsheetExport
|
||||
}
|
||||
}
|
||||
$tmp = storage_path('app/m3-exports/' . uniqid('', true) . '-' . basename($filename));
|
||||
if (! is_dir(dirname($tmp))) { mkdir(dirname($tmp), 0775, true); }
|
||||
if (! is_dir(dirname($tmp))) {
|
||||
mkdir(dirname($tmp), 0775, true);
|
||||
}
|
||||
(new Xlsx($book))->save($tmp);
|
||||
if ($disk && config("filesystems.disks.$disk")) {
|
||||
Storage::disk($disk)->put($filename, file_get_contents($tmp));
|
||||
@unlink($tmp);
|
||||
|
||||
return $filename;
|
||||
}
|
||||
|
||||
return $tmp;
|
||||
}
|
||||
|
||||
@@ -61,7 +66,7 @@ class SpreadsheetExport
|
||||
mkdir(dirname($path), 0775, true);
|
||||
}
|
||||
|
||||
$sheet = (new Spreadsheet())->getActiveSheet();
|
||||
$sheet = (new Spreadsheet)->getActiveSheet();
|
||||
$array = $rows->map(fn ($row) => (array) $row)->values();
|
||||
$headers = $array->first() ? array_keys($array->first()) : [];
|
||||
if ($headers) {
|
||||
|
||||
Reference in New Issue
Block a user