updates to M3 module
This commit is contained in:
@@ -0,0 +1,144 @@
|
||||
<?php
|
||||
|
||||
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 Modules\M3\Http\Controllers\API\CloseShipment;
|
||||
|
||||
class CallCloseAPI extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'command:CallCloseAPI {user?} {manifest?} {co?} {whs?} ';
|
||||
|
||||
protected $description = 'Call Close API';
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public function handle()
|
||||
{
|
||||
//$this->info('Start CallCloseAPI...');
|
||||
ini_set('max_execution_time', Config::get('arrays.PHPTimeOut'));
|
||||
ini_set('max_input_time', Config::get('arrays.PHPTimeOut'));
|
||||
ini_set('default_socket_timeout', Config::get('arrays.PHPTimeOut'));
|
||||
|
||||
try {
|
||||
# Get the Calling User
|
||||
$userId = $this->argument('user');
|
||||
$SHUSER = isset($userId) ? $userId : (m3_user() !== '' ? Str::upper(trim(m3_user())) : '');
|
||||
|
||||
# Get the Manifest Number
|
||||
$manifest = $this->argument('manifest');
|
||||
$MANIFESTNum = isset($manifest) ? $manifest : '';
|
||||
$co = $this->argument('co');
|
||||
$APCO = isset($co) ? $co : '';
|
||||
$whs = $this->argument('whs');
|
||||
$APWHS = isset($whs) ? $whs : '';
|
||||
|
||||
// if ($SHUSER!='') {
|
||||
// Log::channel('dailyCron')->info("Cron...Start CallCloseAPI...For Manifest#: ".$MANIFESTNum); // ".$SHUSER."
|
||||
|
||||
if( $MANIFESTNum==''){
|
||||
# Get Macpickers from ICM705M1
|
||||
$ICM705M1 = DB::connection(config('m3.connection', 'pgsql'))->table('icm705m1')
|
||||
->select('APMANIFEST','APCO','APWHS')
|
||||
->where('APSPARE2','')
|
||||
->where('APMANIFEST','!=','0')
|
||||
->whereRaw('EXTRACT(EPOCH FROM (CURRENT_TIMESTAMP - APLDCLOZ)) / 60 > 15')
|
||||
->orderBy('APMANIFEST','desc')
|
||||
->get();
|
||||
// dump($ICM705M1);
|
||||
|
||||
if (count($ICM705M1)>0) {
|
||||
# Loop the Results from $ICM705M1
|
||||
foreach ($ICM705M1 as $key => $ICM705M1R) {
|
||||
$MANIFESTNum = $ICM705M1R->APMANIFEST;
|
||||
|
||||
$USERCO = isset($ICM705M1R->APCO) ? $ICM705M1R->APCO : '';
|
||||
$USERWH = isset($ICM705M1R->APWHS) ? $ICM705M1R->APWHS : '';
|
||||
|
||||
# Update ICM705M1 and set APSPARE2 to P
|
||||
$ICM705M1U = DB::connection(config('m3.connection', 'pgsql'))->table('icm705m1')
|
||||
->where('APMANIFEST',$MANIFESTNum)
|
||||
->where('APCO',$USERCO)
|
||||
->where('APWHS',$USERWH)
|
||||
->update(["APSPARE2"=>"P"]);
|
||||
|
||||
$myRequest = new Request();
|
||||
$myRequest->setMethod('POST');
|
||||
$myRequest->request->add([
|
||||
'WHS' => $USERWH,
|
||||
'COMPANY' => $USERCO,
|
||||
'TRANSTYPE' => 'M',
|
||||
'MANIFEST' => $MANIFESTNum
|
||||
]);
|
||||
$callCloseShipment = CloseShipment::CloseShipmentCoChargeAPI($myRequest);
|
||||
$responseData = $callCloseShipment->getData();
|
||||
$jsonData = json_encode($responseData);
|
||||
Log::channel('dailyCron')->info("Close Shipment API Response for Manifest:".(string)(int)$MANIFESTNum.'-'.$jsonData);
|
||||
}
|
||||
}
|
||||
}
|
||||
# Call Closing for a specific Manifest
|
||||
else{
|
||||
# Get Macpickers from ICM705M1
|
||||
$ICM705M1 = DB::connection(config('m3.connection', 'pgsql'))->table('icm705m1')
|
||||
->select('APMANIFEST','APCO','APWHS')
|
||||
->where('APSPARE2','')
|
||||
->where('APCO',$APCO)
|
||||
->where('APWHS',$APWHS)
|
||||
->where('APMANIFEST','=',$MANIFESTNum)
|
||||
->first();
|
||||
|
||||
# Update ICM705M1 and set APSPARE2 to P
|
||||
$ICM705M1U = DB::connection(config('m3.connection', 'pgsql'))->table('icm705m1')
|
||||
->where('APMANIFEST',$MANIFESTNum)
|
||||
->where('APCO',$APCO)
|
||||
->where('APWHS',$APWHS)
|
||||
->update(["APSPARE2"=>"P"]);
|
||||
|
||||
$myRequest = new Request();
|
||||
$myRequest->setMethod('POST');
|
||||
|
||||
$myRequest->request->add([
|
||||
'WHS' => $APWHS ,
|
||||
'COMPANY' => $APCO,
|
||||
'TRANSTYPE' => 'M',
|
||||
'MANIFEST' => $MANIFESTNum
|
||||
]);
|
||||
|
||||
$callCloseShipment = CloseShipment::CloseShipmentCoChargeAPI($myRequest);
|
||||
$responseData = $callCloseShipment->getData();
|
||||
$jsonData = json_encode($responseData);
|
||||
Log::channel('dailyCron')->info("Close Shipment API Response for Manifest:".$MANIFESTNum.'-'.$jsonData);
|
||||
return 1;
|
||||
}
|
||||
// }
|
||||
// else{
|
||||
// Log::channel('dailyCron')->error('A user must be defined...');
|
||||
|
||||
// $this->error('A user must be defined...');
|
||||
// }
|
||||
|
||||
}
|
||||
catch (\Throwable $th) {
|
||||
// Log::error($th);
|
||||
Log::channel('dailyCron')->error($th);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,261 @@
|
||||
<?php
|
||||
|
||||
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 Excel;
|
||||
use Storage;
|
||||
|
||||
class ClosedOrderSaveXls extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'command:ClosedOrderSaveXls {user?} {co?} {whs?} {pl?}';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Save Orders Closed Lines to Excel';
|
||||
|
||||
/**
|
||||
* Create a new command instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
//$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");
|
||||
|
||||
# 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) : '';
|
||||
|
||||
# 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;
|
||||
|
||||
if ($WHS == '321') {
|
||||
$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);
|
||||
|
||||
# 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
|
||||
$ICM688M2 = DB::connection(config('m3.connection', 'pgsql'))
|
||||
->select("
|
||||
SELECT (SHDT || ' ' || SHTIME) AS DATECLOSED, A5MACPKR, A5ONO,
|
||||
A4OFSTRM,
|
||||
A5PMPWHT*A5PACKED AS WEIGHT,
|
||||
A4SCAC,
|
||||
A4SHIPTYPE,
|
||||
(SELECT A4REFORD FROM ICM688M1 WHERE A4MACPKR=A5MACPKR) AS A4REFORD,
|
||||
A5PART, A5RSVQTY, A5PACKED, A5RSVQTY - A5PACKED AS CALCULATED_COLUMN,
|
||||
A5SLUNPR * A5PACKED AS ANOTHER_CALCULATED_COLUMN,
|
||||
(SELECT A4SHSHNM FROM ICM688M1 WHERE A4MACPKR=A5MACPKR) AS A4SHSHNM ,
|
||||
CASE WHEN SHDT IS NULL THEN (SELECT SHDATA FROM ICM699M WHERE SHMACPKR=A5MACPKR AND SHTYPE='M3-Res-out' AND SHSOURCE='CloseShipmentCoChargeAPI' ORDER BY SHDT DESC, SHTIME DESC FETCH FIRST 1 ROWS ONLY) ELSE '' END AS REASON,
|
||||
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 ."
|
||||
END AS FREIGHT
|
||||
FROM ICM688M2
|
||||
LEFT JOIN ICM699M ON SHMACPKR=A5MACPKR AND SHTYPE='M3-Res-out' AND SHDATA LIKE 'Success%' AND SHSOURCE='CloseShipmentCoChargeAPI'
|
||||
LEFT JOIN ICM666M ON A1DELNO=A5MACPKR AND A1ONO=A5ONO AND A1PKLN=A5BRADLN
|
||||
LEFT JOIN ICM688M1 ON A4MACPKR=A5MACPKR
|
||||
WHERE A5MACPKR IN (
|
||||
SELECT DISTINCT AYMACPKR
|
||||
FROM ICM695M1
|
||||
WHERE AYSTATUS IN ('Z','z') AND AYAPR8N002 BETWEEN $reportDate AND $toreportDate
|
||||
)
|
||||
AND A5CO=$COMPANY AND A5WHS=$WHS AND A5PLANT=$PLANT
|
||||
");
|
||||
|
||||
// $newItem = ["A5MACPKR" => 'Delivery #', "A5ONO" => 'Order #', "A4REFORD" => 'Order Type',"A5PART" => 'Part #',"A5RSVQTY" => 'Reserved',
|
||||
// "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'];
|
||||
|
||||
$ICM688M2Col = collect($ICM688M2);
|
||||
$ICM688M2Col->prepend($newItem);
|
||||
|
||||
# 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));
|
||||
}
|
||||
}
|
||||
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");
|
||||
|
||||
# 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...");
|
||||
}
|
||||
|
||||
# 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');
|
||||
|
||||
if ($WHS == '321') {
|
||||
$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);
|
||||
|
||||
if($reportDate2!='' && $COMPANY!='' && $WHS!='' && $PLANT!=''){
|
||||
$this->info(">>> Proceed...");
|
||||
|
||||
# Case 729: Add Currency code A1SHCURR FROM ICM666M
|
||||
$ICM688M2 = DB::connection(config('m3.connection', 'pgsql'))
|
||||
->select("
|
||||
SELECT (SHDT || ' ' || SHTIME) AS DATECLOSED, A5MACPKR, A5ONO,
|
||||
A4OFSTRM,
|
||||
A5PMPWHT*A5PACKED AS WEIGHT,
|
||||
A4SCAC,
|
||||
A4SHIPTYPE,
|
||||
(SELECT A4REFORD FROM ICM688M1 WHERE A4MACPKR=A5MACPKR) AS A4REFORD,
|
||||
A5PART, A5RSVQTY, A5PACKED, A5RSVQTY - A5PACKED AS CALCULATED_COLUMN,
|
||||
A5SLUNPR * A5PACKED AS ANOTHER_CALCULATED_COLUMN,
|
||||
(SELECT A4SHSHNM FROM ICM688M1 WHERE A4MACPKR=A5MACPKR) AS A4SHSHNM ,
|
||||
CASE WHEN SHDT IS NULL THEN (SELECT SHDATA FROM ICM699M WHERE SHMACPKR=A5MACPKR AND SHTYPE='M3-Res-out' AND SHSOURCE='CloseShipmentCoChargeAPI' ORDER BY SHDT DESC, SHTIME DESC FETCH FIRST 1 ROWS ONLY) ELSE '' END AS REASON,
|
||||
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 ."
|
||||
END AS FREIGHT
|
||||
FROM ICM688M2
|
||||
LEFT JOIN ICM699M ON SHMACPKR=A5MACPKR AND SHTYPE='M3-Res-out' AND SHDATA LIKE 'Success%' AND SHSOURCE='CloseShipmentCoChargeAPI'
|
||||
LEFT JOIN ICM666M ON A1DELNO=A5MACPKR AND A1ONO=A5ONO AND A1PKLN=A5BRADLN
|
||||
LEFT JOIN ICM688M1 ON A4MACPKR=A5MACPKR
|
||||
WHERE A5MACPKR IN (
|
||||
SELECT DISTINCT AYMACPKR
|
||||
FROM ICM695M1
|
||||
WHERE AYSTATUS IN ('Z','z') AND AYAPR8N002 BETWEEN $reportDate2 AND $toreportDate2
|
||||
)
|
||||
AND A5CO=$COMPANY AND A5WHS=$WHS AND A5PLANT=$PLANT
|
||||
");
|
||||
|
||||
// $newItem2 = ["A5MACPKR" => 'Delivery #', "A5ONO" => 'Order #', "A4REFORD" => 'Order Type',"A5PART" => 'Part #',"A5RSVQTY" => 'Reserved',
|
||||
// "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'];
|
||||
|
||||
$ICM688M2Col2 = collect($ICM688M2);
|
||||
$ICM688M2Col2->prepend($newItem2);
|
||||
|
||||
# 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));
|
||||
}
|
||||
}
|
||||
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...");
|
||||
}
|
||||
|
||||
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) {
|
||||
// Log::error($th);
|
||||
Log::channel('dailyCron')->error($th);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,108 @@
|
||||
<?php
|
||||
|
||||
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 Storage;
|
||||
use File;
|
||||
|
||||
|
||||
class DeleteOldLabels extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'command:DeleteOldLabelsCmd';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Delete Old Labels Command';
|
||||
|
||||
/**
|
||||
* Create a new command instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function handle(): void
|
||||
{
|
||||
//$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 {
|
||||
$this->info("Start Delete Old Labels Command...");
|
||||
Log::channel('dailyCron')->info("Cron...Start Delete Old Labels Command...");
|
||||
|
||||
$labelsDirectoryTmp = '/www/sentm3live/htdocs/labels/';
|
||||
$subFolders = ['CarrierLabel/','ContentLabel/','PackingList/']; // ,'CarrierLabel/','ContentLabel','PackingList',''
|
||||
$daysOld = 180; // Number of days to consider a file old : 180 =Six Months
|
||||
$filesToDeleteArr = [];
|
||||
|
||||
foreach ($subFolders as $key => $subFolder) {
|
||||
$labelsDirectory = $labelsDirectoryTmp.$subFolder;
|
||||
|
||||
$this->info("Getting Files From Directory: ".$labelsDirectory);
|
||||
Log::channel('dailyCron')->info("Getting Files From Directory: ".$labelsDirectory);
|
||||
|
||||
exec('find '.$labelsDirectory.' -ctime +180 -type f -exec rm {} \;');
|
||||
# exec('find '.$labelsDirectory.' -ctime +190 -type f -print | wc -l');
|
||||
}
|
||||
|
||||
$labelsFolder = $labelsDirectoryTmp;
|
||||
# Get Files from the specified Directory
|
||||
$filesToDelete = File::allFiles($labelsFolder);
|
||||
|
||||
foreach ($filesToDelete as $file) {
|
||||
$lastAccessTime = new \DateTime("@".$file->getATime());
|
||||
$now = new \DateTime();
|
||||
$diff = $now->diff($lastAccessTime)->days;
|
||||
|
||||
if ($diff >= $daysOld) {
|
||||
$this->info("File: ".$file." is Days Old: ".$diff);
|
||||
// Log::channel('dailyCron')->info("File: ".$file." is Days Old: ".$diff);
|
||||
# Add the File to Array
|
||||
$filesToDeleteArr[] = $file;
|
||||
}
|
||||
}
|
||||
|
||||
// $this->info("Files to Delete...");
|
||||
// dump($filesToDeleteArr);
|
||||
|
||||
# Delete Old Files
|
||||
File::delete($filesToDeleteArr);
|
||||
|
||||
Log::channel('dailyCron')->info("Cron...End Delete Old Labels Command...");
|
||||
$this->info("End Delete Old Labels Command...");
|
||||
|
||||
}
|
||||
catch (\Throwable $th) {
|
||||
// Log::error($th);
|
||||
Log::channel('dailyCron')->error($th);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,289 @@
|
||||
<?php
|
||||
|
||||
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 File;
|
||||
use DateTime;
|
||||
|
||||
use Storage;
|
||||
use Cache;
|
||||
use Picqer\Barcode\BarcodeGeneratorPNG;
|
||||
use Dompdf\Dompdf;
|
||||
|
||||
use Ayeo\Barcode;
|
||||
use PDF;
|
||||
use App;
|
||||
|
||||
use Zebra\Client;
|
||||
use Zebra\Zpl\Image;
|
||||
use Zebra\Zpl\Builder;
|
||||
use Zebra\Zpl\GdDecoder;
|
||||
|
||||
class GenerateGS1Cmd extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'command:GenerateGS1Cmd {user?} {--gsarray=}';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Generate GS1-128 Label';
|
||||
|
||||
/**
|
||||
* Create a new command instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
//$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 {
|
||||
$this->info('>>> Run GS1 Label creation Command...');
|
||||
Log::channel('LabelCron')->info(">>> Run GS1 Label creation Command...");
|
||||
|
||||
# Get the Calling User
|
||||
$userId = $this->argument('user');
|
||||
$SHUSER = isset($userId) ? $userId : (m3_user() !== '' ? Str::upper(trim(m3_user())) : 'TWOSHIP');
|
||||
$this->info('User: '.$SHUSER);
|
||||
|
||||
# Get Manifest Array
|
||||
$GSArray1 = $this->option('gsarray');
|
||||
$GSArray = json_decode($GSArray1, true);
|
||||
// dump($GSArray);
|
||||
|
||||
# MAK : Used for debug only
|
||||
$GSArray = ["Macpkr"=> "55555","Recipient_Address1"=>"9571 Pan American DR", "Recipient_Address2"=>"C/O AEE Solar","Recipient_City"=>"El Paso",
|
||||
"Recipient_CompanyName"=>"SNAPRACK EL PASO PRODUCTION","Recipient_CountryCode"=>"US","Recipient_PostalCode"=>"79927","Recipient_State"=>"TX",
|
||||
"Sender_Address1"=>"6800 Arnold Miller Pkwy","Sender_Address2"=>"","Sender_City"=>"Solon",
|
||||
"Sender_CompanyName"=>"Erico International","Sender_Country"=>"US","Sender_PostalCode"=>"44139","Sender_State"=>"OH",
|
||||
"CarrierName"=>"R&L Carriers","trackingno"=>"306539838","BOLnumber"=>"693103848064454","ShipmentPONumber"=>"4523039092",
|
||||
"PackagesArray"=> ["package 1" , "package 2"]
|
||||
];
|
||||
|
||||
|
||||
if ($SHUSER!='') {
|
||||
# Get User CO & WH from Table ICM428M
|
||||
$ICM428M = DB::connection(config('m3.connection', 'pgsql'))->table('icm428m')
|
||||
->select('R428US','R428CO', 'R428WH','R428PL')
|
||||
->where('R428US','=',$SHUSER)
|
||||
->first();
|
||||
|
||||
$R428US = isset($ICM428M->R428US) ? $ICM428M->R428US : ''; # User
|
||||
$COMPANY = isset($ICM428M->R428CO) ? $ICM428M->R428CO : ''; # Company
|
||||
$PLANT = isset($ICM428M->R428PL) ? $ICM428M->R428PL : ''; # Plant
|
||||
$WHS = isset($ICM428M->R428WH) ? $ICM428M->R428WH : ''; # WareHouse
|
||||
|
||||
$Macpkr = $GSArray['Macpkr'];
|
||||
$packageType = '0';
|
||||
$manufactID = '0826528'; # MAK : get ID from Nvent and save to Config File
|
||||
$total_length = 9;
|
||||
|
||||
$html = '
|
||||
<html>
|
||||
<head>
|
||||
<style>
|
||||
.border_btm {
|
||||
border-bottom: 1px solid;
|
||||
}
|
||||
.border_rght {
|
||||
border-right: 1px solid;
|
||||
}
|
||||
|
||||
.margin_t {
|
||||
padding-top : 10px;
|
||||
}
|
||||
|
||||
.align_lft {
|
||||
text-align: left;
|
||||
}
|
||||
.align_center {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
@page { margin: 5px; }
|
||||
body { margin: 0px; }
|
||||
</style>
|
||||
</head>
|
||||
<body style="font-family: Arial, sans-serif;">';
|
||||
|
||||
# Get number of Pallets
|
||||
$packageCount = count($GSArray['PackagesArray']);
|
||||
$packageNum = 1;
|
||||
foreach ($GSArray['PackagesArray'] as $key => $value) {
|
||||
$table_style = $packageNum < $packageCount ? ' style="page-break-after: always;" ' : '';
|
||||
|
||||
if (Cache::has('GS1SEQUENCE')) {
|
||||
$GS1SEQUENCE = Cache::get('GS1SEQUENCE');
|
||||
$GS1SEQUENCE++;
|
||||
$GS1SEQUENCEID = str_pad($GS1SEQUENCE, $total_length, "0", STR_PAD_LEFT);
|
||||
}
|
||||
# Box Number Not Found Get it from DB
|
||||
else{
|
||||
$GS1SEQUENCE = 1;
|
||||
$GS1SEQUENCEID = str_pad($GS1SEQUENCE, $total_length, "0", STR_PAD_LEFT);
|
||||
}
|
||||
Cache::forever('GS1SEQUENCE', $GS1SEQUENCEID);
|
||||
$this->info(">>> GS1 sequence Id: ".$GS1SEQUENCEID);
|
||||
|
||||
$gs1_128_bc_1 = '00' .$packageType . $manufactID . $GS1SEQUENCEID;
|
||||
|
||||
# Calculate Check Digit
|
||||
$digits = str_split($gs1_128_bc_1);
|
||||
$sum = 0;
|
||||
$length = count($digits);
|
||||
|
||||
# Loop through each digit starting from the right
|
||||
for ($i = 0; $i < $length; $i++) {
|
||||
$digit = $digits[$length - $i - 1];
|
||||
# Assign a weight of 3 or 1 alternately
|
||||
$weight = ($i % 2 == 0) ? 3 : 1;
|
||||
# Add the product of the digit and its weight to the sum
|
||||
$sum += $digit * $weight;
|
||||
}
|
||||
# Calculate the remainder when sum is divided by 10
|
||||
$remainder = $sum % 10;
|
||||
# If remainder is 0, check digit is 0; otherwise, subtract remainder from 10
|
||||
$checkDigit = ($remainder == 0) ? 0 : 10 - $remainder;
|
||||
|
||||
$gs1_128_bc = $gs1_128_bc_1 . $checkDigit;
|
||||
$gs1_128_bc_desc = '(00)' .$packageType . $manufactID . $GS1SEQUENCEID .$checkDigit;
|
||||
|
||||
$data = [
|
||||
'ship_to' => $GSArray["Recipient_CompanyName"].'<br>'.$GSArray["Recipient_Address1"].'<br>'.
|
||||
$GSArray["Recipient_City"].','. $GSArray["Recipient_State"]
|
||||
.'<br>'.$GSArray["Recipient_PostalCode"] ,
|
||||
'from' => $GSArray["Sender_CompanyName"].'<br>'.$GSArray["Sender_Address1"].'<br>'.
|
||||
$GSArray["Sender_City"].','. $GSArray["Sender_State"]
|
||||
.'<br>'.$GSArray["Sender_PostalCode"] ,
|
||||
'ship_to_lbl' => '420'.$GSArray["Recipient_PostalCode"],
|
||||
'ship_to_desc' => '(420)'.$GSArray["Recipient_PostalCode"],
|
||||
'pro' => '190071217845706',
|
||||
'item_number' => '10000B',
|
||||
'upc' => '098506095310',
|
||||
'quantity' => '1',
|
||||
'serial_shipping_container' => $gs1_128_bc_desc
|
||||
];
|
||||
|
||||
# Initialize barcode generator
|
||||
$generator = new BarcodeGeneratorPNG();
|
||||
|
||||
# Generate barcodes
|
||||
$shipToPostalCodeBarcode = $generator->getBarcode($data['ship_to_lbl'], $generator::TYPE_CODE_128);
|
||||
$serialShippingContainerBarcode = $generator->getBarcode($data['serial_shipping_container'], $generator::TYPE_CODE_128, 2 ,50);
|
||||
|
||||
# HTML content for the label
|
||||
$html .= '
|
||||
<table '.$table_style.'>
|
||||
<tr>
|
||||
<td colspan="2" class="border_btm border_rght align_lft">
|
||||
FROM:<br>' . $data['from'] . '
|
||||
</td>
|
||||
<td colspan="2" class="border_btm align_lft">
|
||||
SHIP TO:<br>' . $data['ship_to'] . '
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="3" class="border_btm border_rght margin_t align_center">
|
||||
<img src="data:image/png;base64,' . base64_encode($shipToPostalCodeBarcode) . '"> <br>
|
||||
' . $data['ship_to_desc'] . '
|
||||
</td>
|
||||
<td class="border_btm margin_t align_lft">
|
||||
Carrier: '.$GSArray["CarrierName"].' <br>
|
||||
PRO #: '.$GSArray["ShipmentPONumber"].' <br>
|
||||
B/L #: '.$GSArray["BOLnumber"].'
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="2" class="border_btm margin_t align_lft border_rght">
|
||||
PURCHASE ORDER: '.$GSArray["Macpkr"].' <br>
|
||||
Vendor: ' . $manufactID . '
|
||||
</td>
|
||||
<td colspan="2" class="border_btm margin_t align_center">
|
||||
Pallet # : '.$packageNum.' of '.$packageCount.'
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="4" style="text-align: center;" class="margin_t">
|
||||
<img src="data:image/png;base64,' . base64_encode($serialShippingContainerBarcode) . '"><br>
|
||||
' . $data['serial_shipping_container'] . '
|
||||
</td>
|
||||
</tr>
|
||||
</table>';
|
||||
|
||||
$packageNum++;
|
||||
}
|
||||
|
||||
$html .='</body> </html>';
|
||||
// dump($html);
|
||||
// App::call('App\Http\Controllers\utilitiesContoller@generateGS128');
|
||||
|
||||
ob_start();
|
||||
|
||||
# Initialize Dompdf
|
||||
$dompdf = new Dompdf();
|
||||
$dompdf->loadHtml($html);
|
||||
$dompdf->setPaper('a6', 'portrait');
|
||||
# Render the HTML as PDF
|
||||
$dompdf->render();
|
||||
|
||||
# Output the generated PDF to Browser
|
||||
// $dompdf->stream();
|
||||
|
||||
$pdfContent = $dompdf->output();
|
||||
// dump($pdfContent);
|
||||
|
||||
$labelsPath = Config::get('arrays.PdfPath');
|
||||
# Put the PDF in labels/CarrierLabel
|
||||
$GSFolder = "GSLabel";
|
||||
$carrierFileName = $GSFolder.'_'.$Macpkr.'_'.$COMPANY.'_'.$WHS;
|
||||
file_put_contents($labelsPath.$GSFolder.'/'.$carrierFileName.'.pdf',$pdfContent);
|
||||
|
||||
# Check if the PDF was generated correctly
|
||||
// if (!file_exists($tempPdfPath) || filesize($tempPdfPath) === 0) {
|
||||
// throw new Exception('PDF generation failed.');
|
||||
// }
|
||||
|
||||
ob_end_clean();
|
||||
}
|
||||
|
||||
Log::channel('LabelCron')->info("<<< GS1-128...End of Label Creation");
|
||||
$this->info("<<< GS1-128...End of Label Creation");
|
||||
|
||||
}
|
||||
catch (\Throwable $th) {
|
||||
// Log::error($th);
|
||||
Log::channel('LabelCron')->error($th);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
|
||||
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 Modules\M3\Http\Controllers\utilitiesContoller;
|
||||
|
||||
class UtilitiesCmd extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'command:UtilitiesCmd';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Utilities Command';
|
||||
|
||||
/**
|
||||
* Create a new command instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function handle(): void
|
||||
{
|
||||
//$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 {
|
||||
$this->info("Start Utilities Command...");
|
||||
|
||||
// $this->info('User: '.$SHUSER);
|
||||
$myRequest = new Request();
|
||||
utilitiesContoller::fixICM799MSentPKR($myRequest);
|
||||
|
||||
// Log::channel('dailyCron')->info("Cron...End Save Orders Closed Lines to Excel");
|
||||
$this->info("End Utilities Command...");
|
||||
|
||||
}
|
||||
catch (\Throwable $th) {
|
||||
// Log::error($th);
|
||||
Log::channel('dailyCron')->error($th);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,195 @@
|
||||
<?php
|
||||
|
||||
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 Storage;
|
||||
|
||||
class WHSMetricsSaveXls extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'command:WHSMetricsSaveXls {user?} {co?} {whs?} {pl?}';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Save WHS Metrics to Excel';
|
||||
|
||||
/**
|
||||
* Create a new command instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
//$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 WHS Metrics to Excel");
|
||||
|
||||
# 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) : '110';
|
||||
$COMPANY = '110';
|
||||
$PWHS = $this->argument('whs');
|
||||
// $WHS = isset($PWHS) ? trim($PWHS) : '321';
|
||||
$WHS = '321';
|
||||
$PPL = $this->argument('pl');
|
||||
// $PLANT = isset($PPL) ? trim($PPL) : '143';
|
||||
$PLANT = '143';
|
||||
|
||||
$date = new \DateTime();
|
||||
$DateToday = $date->format('Y-m-d');
|
||||
|
||||
# Define File Name
|
||||
$whsPerfFile = 'WhsPerf/'.$WHS.'/WhsPerfMetrics_'.$DateToday.'-'.$WHS.'.xlsx';
|
||||
Log::channel('dailyCron')->info(">>> File Name:");
|
||||
Log::channel('dailyCron')->info($whsPerfFile);
|
||||
|
||||
$this->info("Generate Today WHS Performance Report...");
|
||||
|
||||
if( $COMPANY!='' && $WHS!='' && $PLANT!='' ){
|
||||
# Get Header Content
|
||||
$ICM700MHeadSel = DB::connection(config('m3.connection', 'pgsql'))
|
||||
->select("
|
||||
WITH TEMPFILE AS (
|
||||
SELECT A.*,A4TPCKWGHT,A4NOPICLNS,A4PICKSTS,
|
||||
CASE WHEN UPPER(A4PICKSTS)<>'A' THEN 'Open' ELSE 'Closed' END AS STATUS,
|
||||
CASE WHEN A4TPCKWGHT>16000 THEN 'FTL' ELSE A4SHIPTYPE END AS A4SHIPTYPE,
|
||||
(SELECT SUM(A5RSVQTY*A5SLUNPR) FROM ICM688M2 WHERE A4MACPKR=A5MACPKR) AS DOLLARS
|
||||
FROM ICM700M A LEFT JOIN ICM688M1 B ON A4MACPKR=A3MACPKR
|
||||
WHERE A3MSMTDATE= (SELECT MAX(A3MSMTDATE) FROM ICM700M) AND A3CO='$COMPANY' AND A3WHS='$WHS' AND A3PLT='$PLANT'
|
||||
)
|
||||
SELECT A4SHIPTYPE,STATUS,SOURCE,COUNT(*) AS PICKERS, SUM(A4TPCKWGHT) AS WEIGHT,SUM(A4NOPICLNS) AS LINES,SUM(DOLLARS) AS DOLLARS
|
||||
FROM TEMPFILE
|
||||
GROUP BY A4SHIPTYPE,STATUS,SOURCE
|
||||
ORDER BY 1,3,2
|
||||
");
|
||||
// dd($ICM700MHeadSel);
|
||||
|
||||
$newItem = ["A4SHIPTYPE" => 'Method', "STATUS" => 'Status', "SOURCE" => 'Source', "PICKERS" => 'Pickers',
|
||||
"WEIGHT" => 'Weight', "LINES" => 'Lines', "DOLLARS" => 'Dollars'];
|
||||
|
||||
# Trim All values
|
||||
$ICM700MHeadCol = collect($ICM700MHeadSel)->map(function ($item) {
|
||||
foreach ($item as $key => $value) {
|
||||
if (is_string($value)) {
|
||||
$item->{$key} = trim($value);
|
||||
}
|
||||
}
|
||||
return $item;
|
||||
});
|
||||
# Prepend Header to Collection
|
||||
$ICM700MHeadCol->prepend($newItem);
|
||||
|
||||
// $this->info($ICM700MHeadCol);
|
||||
// Log::channel('dailyCron')->info(">>> Header Content");
|
||||
// Log::channel('dailyCron')->info($ICM700MHeadCol);
|
||||
|
||||
# Count records before exporting to excel
|
||||
$ICM700MHeadCount = $ICM700MHeadCol->count();
|
||||
|
||||
# Get Details Content
|
||||
$ICM700MDetailsSel = DB::connection(config('m3.connection', 'pgsql'))
|
||||
->select("
|
||||
WITH TEMPFILE AS (
|
||||
SELECT A3CO,A3WHS,A3PLT,A3MACPKR,A4PICKCRTS,SOURCE,
|
||||
(SELECT TO_TIMESTAMP(CAST(SHDT AS TEXT) || ' ' || CAST(SHTIME AS TEXT), 'YYYY-MM-DD HH24:MI:SS') FROM ICM699M WHERE SHMACPKR=A4MACPKR AND SHTYPE='Lisnr-Hold' ORDER BY SHDT DESC, SHTIME DESC FETCH FIRST 1 ROWS ONLY) AS CARRIERASSIGNED,
|
||||
A4ONO,A4SHSHNM,A4SCAC,A42SSVCNAM,A4PICKSTS,
|
||||
CASE WHEN UPPER(A4PICKSTS)<>'A' THEN 'Open' ELSE 'Closed' END AS STATUS,
|
||||
CASE WHEN A4TPCKWGHT>16000 THEN 'FTL' ELSE A4SHIPTYPE END AS A4SHIPTYPE,
|
||||
A4TPCKWGHT,A4NOPICLNS,
|
||||
(SELECT SUM(A5RSVQTY*A5SLUNPR) FROM ICM688M2 WHERE A4MACPKR=A5MACPKR) AS DOLLARS
|
||||
FROM ICM700M A
|
||||
LEFT JOIN ICM688M1 B ON A4MACPKR=A3MACPKR
|
||||
WHERE A3MSMTDATE=(SELECT MAX(A3MSMTDATE) FROM ICM700M) AND A3CO='$COMPANY' AND A3WHS='$WHS' AND A3PLT='$PLANT'
|
||||
)
|
||||
SELECT * FROM TEMPFILE
|
||||
");
|
||||
|
||||
$newItem2 = ["A3CO" => 'Co', "A3WHS" => 'Whs', "A3PLT" => 'Plt', "A3MACPKR" => 'Delivery No', "A4PICKCRTS" => 'Date Time Arrived in Sentinel',
|
||||
"SOURCE" => 'Source', "CARRIERASSIGNED" => 'Date carrier Assigned', "A4ONO" => 'Order No', "A4SHSHNM" => 'Customer name',"A4SCAC" => 'Carrier',
|
||||
"A42SSVCNAM" => 'Service', "A4PICKSTS" => 'Picker Status', "STATUS" => 'Open or Closed', "A4SHIPTYPE" => 'Method',
|
||||
"A4TPCKWGHT" => 'Weight', "A4NOPICLNS" => 'Lines' , "DOLLARS" => 'Dollars' ];
|
||||
# Trim all values
|
||||
$ICM700MDetailsCol = collect($ICM700MDetailsSel)->map(function ($item) {
|
||||
foreach ($item as $key => $value) {
|
||||
if (is_string($value)) {
|
||||
$item->{$key} = trim($value);
|
||||
}
|
||||
}
|
||||
return $item;
|
||||
});
|
||||
|
||||
# Prepend Header
|
||||
$ICM700MDetailsCol->prepend($newItem2);
|
||||
|
||||
# Count records before exporting to excel
|
||||
$ICM700MDetailsCount = $ICM700MDetailsCol->count();
|
||||
}
|
||||
else{
|
||||
$ICM700MDetailsCol = collect();
|
||||
}
|
||||
// Log::channel('dailyCron')->info(">>> Detail Content");
|
||||
// Log::channel('dailyCron')->info($ICM700MDetailsCol);
|
||||
|
||||
# Save Head and Details to XLS file
|
||||
if ($ICM700MHeadCount>0 && $ICM700MDetailsCount>0) {
|
||||
$this->info("Saving Today WHS Performance Report to Disk...");
|
||||
Log::channel('dailyCron')->info("Saving Today WHS Performance Report to Disk...");
|
||||
|
||||
# Store both collections in one XLSX workbook using Core's PhpSpreadsheet dependency.
|
||||
app(\Modules\M3\Services\SpreadsheetExport::class)->storeSheets([
|
||||
'Summary' => $ICM700MHeadCol,
|
||||
'Details' => $ICM700MDetailsCol,
|
||||
], $whsPerfFile, 'publicLabels');
|
||||
|
||||
|
||||
}
|
||||
else{
|
||||
Log::channel('dailyCron')->info("Today WHS Performance Report, no records found: Nothing to save...");
|
||||
}
|
||||
|
||||
Log::channel('dailyCron')->info("Cron...End Save Today WHS Performance Report to Excel");
|
||||
$this->info("Cron...End Save Today WHS Performance Report to Excel");
|
||||
|
||||
}
|
||||
catch (\Throwable $th) {
|
||||
// Log::error($th);
|
||||
Log::channel('dailyCron')->error($th);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user