m3 Security Fixes

This commit is contained in:
Mark Gregory
2026-09-16 17:16:25 +01:00
parent d68687f062
commit 8f37245e13
64 changed files with 4247 additions and 4426 deletions
+93 -104
View File
@@ -2,18 +2,14 @@
namespace Modules\M3\Console;
use Illuminate\Console\Command;
use Modules\M3\Http\Controllers\Controller;
use DB;
use Config;
use Illuminate\Http\Request;
use Symfony\Component\HttpFoundation\Response;
use Log;
use Str;
use DB;
use Excel;
use Illuminate\Console\Command;
use Log;
use Modules\M3\Services\SpreadsheetExport;
use Storage;
use Str;
class ClosedOrderSaveXls extends Command
{
@@ -48,53 +44,52 @@ class ClosedOrderSaveXls extends Command
*/
public function handle()
{
//$this->info('Start CallCloseAPI...');
// $this->info('Start CallCloseAPI...');
ini_set('max_execution_time', Config::get('arrays.PHPTimeOutCL'));
ini_set('max_input_time', Config::get('arrays.PHPTimeOutCL'));
ini_set('default_socket_timeout', Config::get('arrays.PHPTimeOutCL'));
ini_set('memory_limit', '1024M');
try {
Log::channel('dailyCron')->info("Cron...Start Save Orders Closed Lines to Excel");
Log::channel('dailyCron')->info('Cron...Start Save Orders Closed Lines to Excel');
# Get the Calling User
$userId = $this->argument('user');
$SHUSER = isset($userId) ? $userId : (m3_user() !== '' ? Str::upper(trim(m3_user())) : '');
// Get the Calling User
$userId = $this->argument('user');
$SHUSER = isset($userId) ? $userId : (m3_user() !== '' ? Str::upper(trim(m3_user())) : '');
$CO = $this->argument('co');
$COMPANY = isset($CO) ? trim($CO) : '';
$PWHS = $this->argument('whs');
$WHS = isset($PWHS) ? trim($PWHS) : '';
$PPL = $this->argument('pl');
$PLANT = isset($PPL) ? trim($PPL) : '';
$CO = $this->argument('co');
$COMPANY = isset($CO) ? trim($CO) : '';
$PWHS = $this->argument('whs');
$WHS = isset($PWHS) ? trim($PWHS) : '';
$PPL = $this->argument('pl');
$PLANT = isset($PPL) ? trim($PPL) : '';
# Generate last Month Report
$date = new \DateTime('FIRST DAY OF THIS MONTH');
// Generate last Month Report
$date = new \DateTime('FIRST DAY OF THIS MONTH');
$date->modify('-1 month');
$fromPreviousMonth = $date->format('Y-m-d');
$toPreviousMonth = $date->modify('last day of this month')->format('Y-m-d');
$reportDate = \DateTime::createFromFormat('Y-m-d', $fromPreviousMonth )->format('Ymd');
$toreportDate = \DateTime::createFromFormat('Y-m-d', $toPreviousMonth )->format('Ymd');
$reportDateWD = $fromPreviousMonth;
$toreportDateWD = $toPreviousMonth;
$fromPreviousMonth = $date->format('Y-m-d');
$toPreviousMonth = $date->modify('last day of this month')->format('Y-m-d');
$reportDate = \DateTime::createFromFormat('Y-m-d', $fromPreviousMonth)->format('Ymd');
$toreportDate = \DateTime::createFromFormat('Y-m-d', $toPreviousMonth)->format('Ymd');
$reportDateWD = $fromPreviousMonth;
$toreportDateWD = $toPreviousMonth;
if ($WHS == '321') {
$prevMonthFile = 'Closedorderlinesreport_'.$reportDateWD.'-'.$toreportDateWD.'.xlsx';
}
else {
$prevMonthFile = $WHS.'/Closedorderlinesreport_'.$reportDateWD.'-'.$toreportDateWD.'-'.$WHS.'.xlsx';
$prevMonthFile = 'Closedorderlinesreport_' . $reportDateWD . '-' . $toreportDateWD . '.xlsx';
} else {
$prevMonthFile = $WHS . '/Closedorderlinesreport_' . $reportDateWD . '-' . $toreportDateWD . '-' . $WHS . '.xlsx';
}
$this->info("Generate Last Month Report...");
$this->info("From Date: ".$reportDate);
$this->info("To Date: ".$toreportDate);
$this->info('Generate Last Month Report...');
$this->info('From Date: ' . $reportDate);
$this->info('To Date: ' . $toreportDate);
# Check that the Excel file Exist
$prevMonthFileExist = Storage::disk('publicCL')->exists($prevMonthFile) ? false: true ;
$this->info("Prev Month File Exist: " .$prevMonthFileExist);
// Check that the Excel file Exist
$prevMonthFileExist = Storage::disk('publicCL')->exists($prevMonthFile) ? false : true;
$this->info('Prev Month File Exist: ' . $prevMonthFileExist);
if($reportDate!='' && $COMPANY!='' && $WHS!='' && $PLANT!='' && $prevMonthFileExist ){
# Case 729: Add Currency code A1SHCURR FROM ICM666M
if ($reportDate != '' && $COMPANY != '' && $WHS != '' && $PLANT != '' && $prevMonthFileExist) {
// Case 729: Add Currency code A1SHCURR FROM ICM666M
$ICM688M2 = DB::connection(config('m3.connection', 'pgsql'))
->select("
SELECT (SHDT || ' ' || SHTIME) AS DATECLOSED, A5MACPKR, A5ONO,
@@ -110,8 +105,8 @@ class ClosedOrderSaveXls extends Command
A1SHCURR,
CASE
WHEN (SELECT A4SHIPTYPE FROM ICM688M1 WHERE A4MACPKR=A5MACPKR) = 'LTL'
THEN (SELECT A4RATETCP FROM ICM688M1 WHERE A4MACPKR=A5MACPKR) * ".(100.00 - Config::get('arrays.misc.discountCarrierRateForCustomerPriceLTL'))/100 ."
ELSE (SELECT A4RATETCP FROM ICM688M1 WHERE A4MACPKR=A5MACPKR) * ".(100.00 - Config::get('arrays.misc.discountCarrierRateForCustomerPriceParcel') )/100 ."
THEN (SELECT A4RATETCP FROM ICM688M1 WHERE A4MACPKR=A5MACPKR) * " . (100.00 - Config::get('arrays.misc.discountCarrierRateForCustomerPriceLTL')) / 100 . '
ELSE (SELECT A4RATETCP FROM ICM688M1 WHERE A4MACPKR=A5MACPKR) * ' . (100.00 - Config::get('arrays.misc.discountCarrierRateForCustomerPriceParcel')) / 100 . "
END AS FREIGHT
FROM ICM688M2
LEFT JOIN ICM699M ON SHMACPKR=A5MACPKR AND SHTYPE='M3-Res-out' AND SHDATA LIKE 'Success%' AND SHSOURCE='CloseShipmentCoChargeAPI'
@@ -129,61 +124,58 @@ class ClosedOrderSaveXls extends Command
// "A5PACKED" => 'Packed',"CALCULATED_COLUMN" => 'Back Order Qty',"ANOTHER_CALCULATED_COLUMN" => 'Value Packed $',"A4SHSHNM" => 'Customer name',
// "SHDT" => 'Date',"SHTIME" => 'Time',"REASON" => 'Failure Reason','A1SHCURR'=> 'Currency Code','FREIGHT'=> 'Freight'];
$newItem = ["DATECLOSED" => 'Close Date',"A5MACPKR" => 'Delivery #', "A5ONO" => 'Order #',
"A4OFSTRM" => 'Terms',"WEIGHT" => 'Weight',"A4SCAC" => 'Carrier',"A4SHIPTYPE" => 'Mode (Parcel, Air, TL or LTL)',
"A4REFORD" => 'Order Type',"A5PART" => 'Part #',"A5RSVQTY" => 'Reserved',
"A5PACKED" => 'Packed',"CALCULATED_COLUMN" => 'Back Order Qty',"ANOTHER_CALCULATED_COLUMN" => 'Value Packed $',"A4SHSHNM" => 'Customer name',
"REASON" => 'Failure Reason','A1SHCURR'=> 'Currency Code','FREIGHT'=> 'Freight'];
$newItem = ['DATECLOSED' => 'Close Date', 'A5MACPKR' => 'Delivery #', 'A5ONO' => 'Order #',
'A4OFSTRM' => 'Terms', 'WEIGHT' => 'Weight', 'A4SCAC' => 'Carrier', 'A4SHIPTYPE' => 'Mode (Parcel, Air, TL or LTL)',
'A4REFORD' => 'Order Type', 'A5PART' => 'Part #', 'A5RSVQTY' => 'Reserved',
'A5PACKED' => 'Packed', 'CALCULATED_COLUMN' => 'Back Order Qty', 'ANOTHER_CALCULATED_COLUMN' => 'Value Packed $', 'A4SHSHNM' => 'Customer name',
'REASON' => 'Failure Reason', 'A1SHCURR' => 'Currency Code', 'FREIGHT' => 'Freight'];
$ICM688M2Col = collect($ICM688M2);
$ICM688M2Col->prepend($newItem);
# Count records before exporting to excel : Max 55K records are allowed
$ICM688M2Count = $ICM688M2Col->count();
# Set Max allowed records
// Count records before exporting to excel : Max 55K records are allowed
$ICM688M2Count = $ICM688M2Col->count();
// Set Max allowed records
$maxRecords = Config::get('arrays.maxRecCL');
if ($ICM688M2Count>$maxRecords) {
Log::channel('dailyCron')->info('Maximum allowed records for Excel export is: '.number_format($maxRecords).' current records: '.number_format($ICM688M2Count));
if ($ICM688M2Count > $maxRecords) {
Log::channel('dailyCron')->info('Maximum allowed records for Excel export is: ' . number_format($maxRecords) . ' current records: ' . number_format($ICM688M2Count));
}
}
else{
} else {
$ICM688M2Col = collect();
}
if ($ICM688M2Col->count()>0) {
$this->info("Saving Last Month Excel Report to Disk");
Log::channel('dailyCron')->info("Saving Last Month Excel Report to Disk");
if ($ICM688M2Col->count() > 0) {
$this->info('Saving Last Month Excel Report to Disk');
Log::channel('dailyCron')->info('Saving Last Month Excel Report to Disk');
# Store the File to Storage
app(\Modules\M3\Services\SpreadsheetExport::class)->store($ICM688M2Col, $prevMonthFile, 'publicCL');
# Other File Formats : \Maatwebsite\Excel\Excel::CSV , ,\Maatwebsite\Excel\Excel::ODS
}
else{
Log::channel('dailyCron')->info("Monthly report, no records found: Nothing to save...");
// Store the File to Storage
app(SpreadsheetExport::class)->store($ICM688M2Col, $prevMonthFile, 'publicCL');
// Other File Formats : \Maatwebsite\Excel\Excel::CSV , ,\Maatwebsite\Excel\Excel::ODS
} else {
Log::channel('dailyCron')->info('Monthly report, no records found: Nothing to save...');
}
# Generate current Month Report
$now = new \DateTime();
// Generate current Month Report
$now = new \DateTime;
$first_day_of_month = $now->format('Y-m-01');
$current_date = $now->format('Y-m-d');
$reportDate2 = \DateTime::createFromFormat('Y-m-d', $first_day_of_month )->format('Ymd');
$toreportDate2 = \DateTime::createFromFormat('Y-m-d', $current_date )->format('Ymd');
$current_date = $now->format('Y-m-d');
$reportDate2 = \DateTime::createFromFormat('Y-m-d', $first_day_of_month)->format('Ymd');
$toreportDate2 = \DateTime::createFromFormat('Y-m-d', $current_date)->format('Ymd');
if ($WHS == '321') {
$currentMonthFile = 'first_of_month_to_current_date.xlsx';
}
else{
$currentMonthFile = $WHS.'/first_of_month_to_current_date_'.$WHS.'.xlsx';
$currentMonthFile = 'first_of_month_to_current_date.xlsx';
} else {
$currentMonthFile = $WHS . '/first_of_month_to_current_date_' . $WHS . '.xlsx';
}
$this->info("Generate Current Month Report...");
$this->info("From Date: ".$reportDate2);
$this->info("To Date : ".$toreportDate2);
$this->info('Generate Current Month Report...');
$this->info('From Date: ' . $reportDate2);
$this->info('To Date : ' . $toreportDate2);
if($reportDate2!='' && $COMPANY!='' && $WHS!='' && $PLANT!=''){
$this->info(">>> Proceed...");
if ($reportDate2 != '' && $COMPANY != '' && $WHS != '' && $PLANT != '') {
$this->info('>>> Proceed...');
# Case 729: Add Currency code A1SHCURR FROM ICM666M
// Case 729: Add Currency code A1SHCURR FROM ICM666M
$ICM688M2 = DB::connection(config('m3.connection', 'pgsql'))
->select("
SELECT (SHDT || ' ' || SHTIME) AS DATECLOSED, A5MACPKR, A5ONO,
@@ -199,8 +191,8 @@ class ClosedOrderSaveXls extends Command
A1SHCURR,
CASE
WHEN (SELECT A4SHIPTYPE FROM ICM688M1 WHERE A4MACPKR=A5MACPKR) = 'LTL'
THEN (SELECT A4RATETCP FROM ICM688M1 WHERE A4MACPKR=A5MACPKR) * ".(100.00 - Config::get('arrays.misc.discountCarrierRateForCustomerPriceLTL'))/100 ."
ELSE (SELECT A4RATETCP FROM ICM688M1 WHERE A4MACPKR=A5MACPKR) * ".(100.00 - Config::get('arrays.misc.discountCarrierRateForCustomerPriceParcel') )/100 ."
THEN (SELECT A4RATETCP FROM ICM688M1 WHERE A4MACPKR=A5MACPKR) * " . (100.00 - Config::get('arrays.misc.discountCarrierRateForCustomerPriceLTL')) / 100 . '
ELSE (SELECT A4RATETCP FROM ICM688M1 WHERE A4MACPKR=A5MACPKR) * ' . (100.00 - Config::get('arrays.misc.discountCarrierRateForCustomerPriceParcel')) / 100 . "
END AS FREIGHT
FROM ICM688M2
LEFT JOIN ICM699M ON SHMACPKR=A5MACPKR AND SHTYPE='M3-Res-out' AND SHDATA LIKE 'Success%' AND SHSOURCE='CloseShipmentCoChargeAPI'
@@ -218,42 +210,39 @@ class ClosedOrderSaveXls extends Command
// "A5PACKED" => 'Packed',"CALCULATED_COLUMN" => 'Back Order Qty',"ANOTHER_CALCULATED_COLUMN" => 'Value Packed $',"A4SHSHNM" => 'Customer name',
// "SHDT" => 'Date',"SHTIME" => 'Time',"REASON" => 'Failure Reason','A1SHCURR'=> 'Currency Code','FREIGHT'=> 'Freight'];
$newItem2 = ["DATECLOSED" => 'Close Date',"A5MACPKR" => 'Delivery #', "A5ONO" => 'Order #',
"A4OFSTRM" => 'Terms',"WEIGHT" => 'Weight',"A4SCAC" => 'Carrier',"A4SHIPTYPE" => 'Mode (Parcel, Air, TL or LTL)',
"A4REFORD" => 'Order Type',"A5PART" => 'Part #',"A5RSVQTY" => 'Reserved',
"A5PACKED" => 'Packed',"CALCULATED_COLUMN" => 'Back Order Qty',"ANOTHER_CALCULATED_COLUMN" => 'Value Packed $',"A4SHSHNM" => 'Customer name',
"REASON" => 'Failure Reason','A1SHCURR'=> 'Currency Code','FREIGHT'=> 'Freight'];
$newItem2 = ['DATECLOSED' => 'Close Date', 'A5MACPKR' => 'Delivery #', 'A5ONO' => 'Order #',
'A4OFSTRM' => 'Terms', 'WEIGHT' => 'Weight', 'A4SCAC' => 'Carrier', 'A4SHIPTYPE' => 'Mode (Parcel, Air, TL or LTL)',
'A4REFORD' => 'Order Type', 'A5PART' => 'Part #', 'A5RSVQTY' => 'Reserved',
'A5PACKED' => 'Packed', 'CALCULATED_COLUMN' => 'Back Order Qty', 'ANOTHER_CALCULATED_COLUMN' => 'Value Packed $', 'A4SHSHNM' => 'Customer name',
'REASON' => 'Failure Reason', 'A1SHCURR' => 'Currency Code', 'FREIGHT' => 'Freight'];
$ICM688M2Col2 = collect($ICM688M2);
$ICM688M2Col2->prepend($newItem2);
# Count records before exporting to excel : Max 55K records are allowed
$ICM688M2Count = $ICM688M2Col2->count();
# Set Max allowed records
// Count records before exporting to excel : Max 55K records are allowed
$ICM688M2Count = $ICM688M2Col2->count();
// Set Max allowed records
$maxRecords = Config::get('arrays.maxRecCL');
if ($ICM688M2Count>$maxRecords) {
Log::channel('dailyCron')->info('Maximum allowed records for Excel export is: '.number_format($maxRecords).' current records: '.number_format($ICM688M2Count));
if ($ICM688M2Count > $maxRecords) {
Log::channel('dailyCron')->info('Maximum allowed records for Excel export is: ' . number_format($maxRecords) . ' current records: ' . number_format($ICM688M2Count));
}
}
else{
} else {
$ICM688M2Col2 = collect();
}
if ($ICM688M2Col2->count()>0) {
$this->info("Saving Current Month Excel Report to Disk");
Log::channel('dailyCron')->info("Saving Current Month Excel Report to Disk");
# Store the File to Storage
app(\Modules\M3\Services\SpreadsheetExport::class)->store($ICM688M2Col2, $currentMonthFile, 'publicCL');
}
else{
Log::channel('dailyCron')->info("Daily Report, no records found: Nothing to save...");
if ($ICM688M2Col2->count() > 0) {
$this->info('Saving Current Month Excel Report to Disk');
Log::channel('dailyCron')->info('Saving Current Month Excel Report to Disk');
// Store the File to Storage
app(SpreadsheetExport::class)->store($ICM688M2Col2, $currentMonthFile, 'publicCL');
} else {
Log::channel('dailyCron')->info('Daily Report, no records found: Nothing to save...');
}
Log::channel('dailyCron')->info("Cron...End Save Orders Closed Lines to Excel");
$this->info("Cron...End Save Orders Closed Lines to Excel");
Log::channel('dailyCron')->info('Cron...End Save Orders Closed Lines to Excel');
$this->info('Cron...End Save Orders Closed Lines to Excel');
}
catch (\Throwable $th) {
} catch (\Throwable $th) {
// Log::error($th);
Log::channel('dailyCron')->error($th);
}