mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/shipping-portal.git
synced 2026-08-19 04:24:12 +00:00
Merge branch 'dillon/34.4-jenkins-vapor' into vapor/development
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\General;
|
||||
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class LogHelper
|
||||
{
|
||||
protected static $channelName;
|
||||
|
||||
public static function channel($channelName)
|
||||
{
|
||||
self::$channelName = $channelName;
|
||||
return new static;
|
||||
}
|
||||
|
||||
public static function info($message)
|
||||
{
|
||||
if(env('LARAVEL_VAPOR_ENABLED')){
|
||||
Log::channel(self::$channelName.'_vapor')->info($message);
|
||||
}
|
||||
else{
|
||||
Log::channel(self::$channelName)->info($message);
|
||||
}
|
||||
}
|
||||
}
|
||||
+19
-18
@@ -4,6 +4,7 @@
|
||||
namespace App\Classes\Modules\Transactions\Processors;
|
||||
|
||||
use App\Classes\Exceptions\MalformedRequestException;
|
||||
use App\Classes\General\LogHelper;
|
||||
use App\Classes\Modules\Orders\Services\FetchesOrder;
|
||||
use App\Classes\Modules\Transactions\Services\GeneratesTransactionBillNumber;
|
||||
use App\Classes\Modules\Transactions\Services\CreatesTransaction;
|
||||
@@ -104,13 +105,13 @@ class CheckStorageInvoiceTransactionProcessor
|
||||
$results = [];
|
||||
$marking = $order->companyModule->inviters()->withPivot('invitee_reference')->first()->pivot->invitee_reference;
|
||||
$is_credit_term = $order->companyModule->inviters()->withPivot('is_credit_term')->first()->pivot->is_credit_term;
|
||||
Log::channel('storage_invoices')->info('orderId: '.$order->id.', orderReference: '.$order->reference.', marking: '.$marking.', is_credit_term: '.$is_credit_term);
|
||||
LogHelper::channel('storage_invoices')->info('orderId: '.$order->id.', orderReference: '.$order->reference.', marking: '.$marking.', is_credit_term: '.$is_credit_term);
|
||||
$packingLists = $order->destinationWarehousePackages;
|
||||
|
||||
foreach ($packingLists as $packingList){
|
||||
$arrivalDateAtChinaWarehouse = $this->getArrivalDateAtChinaWarehoue($packingList);
|
||||
Log::channel('storage_invoices')->info('arrivalDateAtChinaWarehouse: '.json_encode($arrivalDateAtChinaWarehouse));
|
||||
Log::channel('storage_invoices')->info('destinationWarehousePackage: '.json_encode($packingList));
|
||||
LogHelper::channel('storage_invoices')->info('arrivalDateAtChinaWarehouse: '.json_encode($arrivalDateAtChinaWarehouse));
|
||||
LogHelper::channel('storage_invoices')->info('destinationWarehousePackage: '.json_encode($packingList));
|
||||
$eta = $this->getEtaFromPackingList($packingList);
|
||||
if($arrivalDateAtChinaWarehouse && $eta){
|
||||
$transactions = $packingList->transactions()->where('transactions.type', TransactionType::SHIPPING_INVOICE)->whereIn('transactions.status', [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED])->get();
|
||||
@@ -138,15 +139,15 @@ class CheckStorageInvoiceTransactionProcessor
|
||||
private function getArrivalDateAtChinaWarehoue($packingList){
|
||||
if($packingList->type === PackingListType::SHIPPING_PACKING_LIST){
|
||||
$receive_packing_list = PackingList::where('reference', $packingList->reference)->where('type', PackingListType::WAREHOUSE_RECEIVE_LIST)->first();
|
||||
Log::channel('storage_invoices')->info('receive_packing_list: '.json_encode($receive_packing_list->transports));
|
||||
LogHelper::channel('storage_invoices')->info('receive_packing_list: '.json_encode($receive_packing_list->transports));
|
||||
$transport = $receive_packing_list->transports->first();
|
||||
if ($transport) {
|
||||
$arrivalDateAtChinaWarehouse = Carbon::parse($transport->drop_date);
|
||||
$dateToCompare = Carbon::parse(env('STORAGE_FEE_LAUNCH_DATE', '2023-12-11 00:00:00'));
|
||||
// dd($dateToCompare);
|
||||
if ($arrivalDateAtChinaWarehouse->isAfter($dateToCompare)) {
|
||||
Log::channel('storage_invoices')->info('transport: '.json_encode($transport));
|
||||
Log::channel('storage_invoices')->info('dateToCompare: '.$dateToCompare.', arrivalDateAtChinaWarehouse: '.$arrivalDateAtChinaWarehouse);
|
||||
LogHelper::channel('storage_invoices')->info('transport: '.json_encode($transport));
|
||||
LogHelper::channel('storage_invoices')->info('dateToCompare: '.$dateToCompare.', arrivalDateAtChinaWarehouse: '.$arrivalDateAtChinaWarehouse);
|
||||
return $arrivalDateAtChinaWarehouse;
|
||||
}
|
||||
}
|
||||
@@ -202,9 +203,9 @@ class CheckStorageInvoiceTransactionProcessor
|
||||
$dateToCompare = Carbon::parse(env('SST_START_DATE', '2024-04-01 00:00:00'));
|
||||
$shippingInvoiceTransactionCreatedDate = Carbon::now();
|
||||
|
||||
Log::channel('storage_invoices')->info('storageInvoice: '.json_encode($storageInvoice).', $transaction->status: '.$transaction->status);
|
||||
LogHelper::channel('storage_invoices')->info('storageInvoice: '.json_encode($storageInvoice).', $transaction->status: '.$transaction->status);
|
||||
if(!$storageInvoice && $resultNumberOfDaysExceeded > 0 && $transaction->status != ApprovalStatus::COMPLETED){
|
||||
Log::channel('storage_invoices')->info('Created $transaction->id: '.$transaction->id);
|
||||
LogHelper::channel('storage_invoices')->info('Created $transaction->id: '.$transaction->id);
|
||||
$billNumber = $this->generatesTransactionBillNumber->execute('STOR-');
|
||||
|
||||
if ($shippingInvoiceTransactionCreatedDate->isAfter($dateToCompare)) {
|
||||
@@ -228,7 +229,7 @@ class CheckStorageInvoiceTransactionProcessor
|
||||
$paymentStorageTransaction = $storageInvoice->transactions()->where('transactions.type', TransactionType::PAYMENT)->where('transactions.status', ApprovalStatus::APPROVED)->first();
|
||||
if($paymentStorageTransaction){
|
||||
$dateStorageInvoicePaid = $paymentStorageTransaction->created_at->copy()->addDay()->startOfDay();
|
||||
Log::channel('storage_invoices')->info('dateStorageInvoicePaid: '.$dateStorageInvoicePaid.', resultCurrentDate: '.$resultCurrentDate);
|
||||
LogHelper::channel('storage_invoices')->info('dateStorageInvoicePaid: '.$dateStorageInvoicePaid.', resultCurrentDate: '.$resultCurrentDate);
|
||||
$intervalRecalculate = Carbon::parse($dateStorageInvoicePaid)->diff($dt1);
|
||||
$resultNumberOfDaysExceeded = $intervalRecalculate->days - $resultNumberOfDaysFree;
|
||||
$price_cbm = $pricePerCBM * $cbm * $resultNumberOfDaysExceeded;
|
||||
@@ -242,10 +243,10 @@ class CheckStorageInvoiceTransactionProcessor
|
||||
|
||||
$amount = $storageInvoice->amount;
|
||||
$epsilon = 0.0001; // Tolerance for the comparison
|
||||
Log::channel('storage_invoices')->info('Update $transaction->id: '.$transaction->id);
|
||||
Log::channel('storage_invoices')->info('$storageInvoice->status: '.$storageInvoice->status);
|
||||
Log::channel('storage_invoices')->info('price_cbm: '.$price_cbm."-".gettype($price_cbm));
|
||||
Log::channel('storage_invoices')->info('amount: '.$amount);
|
||||
LogHelper::channel('storage_invoices')->info('Update $transaction->id: '.$transaction->id);
|
||||
LogHelper::channel('storage_invoices')->info('$storageInvoice->status: '.$storageInvoice->status);
|
||||
LogHelper::channel('storage_invoices')->info('price_cbm: '.$price_cbm."-".gettype($price_cbm));
|
||||
LogHelper::channel('storage_invoices')->info('amount: '.$amount);
|
||||
|
||||
$proceedToUpdate = false;
|
||||
|
||||
@@ -264,7 +265,7 @@ class CheckStorageInvoiceTransactionProcessor
|
||||
}
|
||||
|
||||
if($proceedToUpdate || ($pricePerCBM == 0 && $amount != 0)){
|
||||
Log::channel('storage_invoices')->info('proceedToUpdate');
|
||||
LogHelper::channel('storage_invoices')->info('proceedToUpdate');
|
||||
|
||||
$storageInvoice = $this->updateStorageInvoiceTransaction($storageInvoice, $price_cbm, $total_tax);
|
||||
$invoiceTransactionDetails = $storageInvoice->transactionDetails()->first();
|
||||
@@ -347,7 +348,7 @@ class CheckStorageInvoiceTransactionProcessor
|
||||
}
|
||||
|
||||
private function updatePaymentTransactionViaGroupPayment($storageInvoice){
|
||||
Log::channel('storage_invoices')->info('updatePaymentTransactionViaGroupPayment');
|
||||
LogHelper::channel('storage_invoices')->info('updatePaymentTransactionViaGroupPayment');
|
||||
$groups = $storageInvoice->groups()->whereNotIn('status', [ApprovalStatus::COMPLETED, ApprovalStatus::SUSPENDED])->get();
|
||||
foreach ($groups as $grp){
|
||||
$groupReference = $grp->reference;
|
||||
@@ -359,19 +360,19 @@ class CheckStorageInvoiceTransactionProcessor
|
||||
$this->updatesTransactionStatus->execute($walletTransaction, ApprovalStatus::EXPIRED);
|
||||
if($walletTransaction->payment_reference){
|
||||
$deletedBillplzBill = $this->deletesBillplzBill->execute($walletTransaction->payment_reference);
|
||||
Log::channel('storage_invoices')->info('deletedBillplzBill TransactionType::WALLET: '.json_encode($deletedBillplzBill));
|
||||
LogHelper::channel('storage_invoices')->info('deletedBillplzBill TransactionType::WALLET: '.json_encode($deletedBillplzBill));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function updatePaymentTransactionViaNonGroupPayment($paymentTransactions){
|
||||
Log::channel('storage_invoices')->info('updatePaymentTransactionViaNonGroupPayment');
|
||||
LogHelper::channel('storage_invoices')->info('updatePaymentTransactionViaNonGroupPayment');
|
||||
foreach ($paymentTransactions as $paymentTransaction){
|
||||
$this->updatesTransactionStatus->execute($paymentTransaction, ApprovalStatus::EXPIRED);
|
||||
if($paymentTransaction->payment_reference){
|
||||
$deletedBillplzBill = $this->deletesBillplzBill->execute($paymentTransaction->payment_reference);
|
||||
Log::channel('storage_invoices')->info('deletedBillplzBill TransactionType::WALLET: '.json_encode($deletedBillplzBill));
|
||||
LogHelper::channel('storage_invoices')->info('deletedBillplzBill TransactionType::WALLET: '.json_encode($deletedBillplzBill));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ class PackingListWithStorageResource extends JsonResource
|
||||
public function toArray($request)
|
||||
{
|
||||
$exceptionUsers = in_array(Auth()->user()->type, [RoleTypes::SHADOW_ADMIN, RoleTypes::SUPER_ADMIN]);
|
||||
$packages = []; //!$this->packingLists()->exists() || $exceptionUsers ? $this->packages : $this->packingLists->first()->packages; //cief todo
|
||||
$packages = []; //!$this->packingLists()->exists() || $exceptionUsers ? $this->packages : $this->packingLists->first()->packages; //cief todo: Disable, some query may need it, e.g. pending approval tab
|
||||
$shippingTransaction = $this->transactions()->where('type', TransactionType::SHIPPING_INVOICE)->whereNotIn('status', [ApprovalStatus::SUSPENDED, ApprovalStatus::EXPIRED])->first();
|
||||
$transactions = $this->transactions()->whereNotIn('transactions.status', [0, 1])->whereIn('transactions.type', [TransactionType::SHIPPING_INVOICE, TransactionType::STORAGE_INVOICE])->get();
|
||||
$storages = [];
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
namespace App\Logging;
|
||||
|
||||
use Aws\CloudWatchLogs\CloudWatchLogsClient;
|
||||
use Maxbanton\Cwh\Handler\CloudWatch;
|
||||
use Monolog\Formatter\JsonFormatter;
|
||||
use Monolog\Logger;
|
||||
|
||||
class CloudWatchLoggerFactory
|
||||
{
|
||||
/**
|
||||
* Create a custom Monolog instance.
|
||||
*
|
||||
* @param array $config
|
||||
* @return \Monolog\Logger
|
||||
*/
|
||||
public function __invoke(array $config)
|
||||
{
|
||||
$sdkParams = $config["sdk"];
|
||||
$tags = $config["tags"] ?? [ ];
|
||||
$name = $config["name"] ?? 'cloudwatch';
|
||||
|
||||
// Instantiate AWS SDK CloudWatch Logs Client
|
||||
$client = new CloudWatchLogsClient($sdkParams);
|
||||
|
||||
// Log group name, will be created if none
|
||||
$groupName = config('app.name') . '-' . config('app.env');
|
||||
|
||||
// Log stream name, will be created if none
|
||||
// $streamName = config('app.hostname');
|
||||
$streamName = $config["cloudwatch_stream_name"];
|
||||
|
||||
// Days to keep logs, 14 by default. Set to `null` to allow indefinite retention.
|
||||
$retentionDays = $config["retention"];
|
||||
// Instantiate handler (tags are optional)
|
||||
$handler = new CloudWatch($client, $groupName, $streamName, $retentionDays, 10000, $tags);
|
||||
$handler->setFormatter(new JsonFormatter());
|
||||
// Create a log channel
|
||||
$logger = new Logger($name);
|
||||
// Set handler
|
||||
$logger->pushHandler($handler);
|
||||
//$logger->pushProcessor(new CompanyLogProcessor()); //Use this if you want to adjust the JSON output using a log processor
|
||||
return $logger;
|
||||
}
|
||||
}
|
||||
@@ -26,6 +26,7 @@
|
||||
"laravel/vapor-core": "^2.33",
|
||||
"maatwebsite/excel": "^3.1",
|
||||
"predis/predis": "^2.1",
|
||||
"maxbanton/cwh": "^2.0",
|
||||
"rinvex/countries": "^6.1",
|
||||
"spatie/laravel-activitylog": "^3.14",
|
||||
"spatie/laravel-fractal": "^5.8",
|
||||
|
||||
+19
-12
@@ -54,20 +54,27 @@ return [
|
||||
'days' => 14,
|
||||
],
|
||||
|
||||
// 'storage_invoices' => [
|
||||
// 'driver' => 'single',
|
||||
// 'path' => storage_path('logs/laravel_storage_invoices.log'),
|
||||
// 'level' => 'info',
|
||||
// ],
|
||||
|
||||
'storage_invoices' => [
|
||||
'driver' => 'monolog',
|
||||
'level' => env('LOG_LEVEL', 'debug'),
|
||||
'handler' => StreamHandler::class,
|
||||
'formatter' => env('LOG_STDERR_FORMATTER'),
|
||||
'with' => [
|
||||
'stream' => 'php://stderr',
|
||||
'driver' => 'single',
|
||||
'path' => storage_path('logs/laravel_storage_invoices.log'),
|
||||
'level' => 'info',
|
||||
],
|
||||
|
||||
'storage_invoices_vapor' => [
|
||||
'driver' => 'custom',
|
||||
'via' => \App\Logging\CloudWatchLoggerFactory::class,
|
||||
'formatter' => Monolog\Formatter\JsonFormatter::class,
|
||||
'cloudwatch_stream_name' => 'cief-test',
|
||||
'sdk' => [
|
||||
'region' => env('AWS_MY_REGION'),
|
||||
'version' => 'latest',
|
||||
'credentials' => [
|
||||
'key' => env('AWS_CW_ACCESS'),
|
||||
'secret' => env('AWS_CW_SECRET')
|
||||
]
|
||||
],
|
||||
'retention' => 3, //cief todo: to be updated
|
||||
'level' => 'debug',
|
||||
],
|
||||
|
||||
'slack' => [
|
||||
|
||||
Reference in New Issue
Block a user