mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/shipping-portal.git
synced 2026-08-22 05:54:01 +00:00
Merge branch 'dillon/34.7-jenkins-vapor' into vapor/staging
This commit is contained in:
@@ -32,12 +32,12 @@ class UpdatePerfexCRMPrelude implements ShouldQueue
|
||||
|
||||
/**
|
||||
* UpdatePerfexCRMPrelude constructor.
|
||||
* @param $packingList
|
||||
* @param PackingList $packingList
|
||||
* @param Transaction $transaction
|
||||
* @param UpdatePerfexCRMObject $updatePerfexCRMObject
|
||||
* @param bool|null $shouldCreateInvoice
|
||||
*/
|
||||
public function __construct($packingList, $transaction, UpdatePerfexCRMObject $updatePerfexCRMObject, ?bool $shouldCreateInvoice = false)
|
||||
public function __construct(?PackingList $packingList, $transaction, UpdatePerfexCRMObject $updatePerfexCRMObject, ?bool $shouldCreateInvoice = false)
|
||||
{
|
||||
$this->packingList = $packingList;
|
||||
$this->transaction = $transaction;
|
||||
@@ -47,6 +47,16 @@ class UpdatePerfexCRMPrelude implements ShouldQueue
|
||||
|
||||
public function handle()
|
||||
{
|
||||
Log::info('packingList: ' . json_encode($this->packingList));
|
||||
Log::info('packingList owner: ' . json_encode($this->packingList->owner));
|
||||
Log::info('transaction: ' . json_encode($this->transaction));
|
||||
Log::info('updatePerfexCRMObject get tasks: ' . json_encode($this->updatePerfexCRMObject->getTasks()));
|
||||
Log::info('shouldCreateInvoice: ' . json_encode($this->shouldCreateInvoice));
|
||||
|
||||
if(env('APP_ENV') !== 'production'){
|
||||
return;
|
||||
}
|
||||
|
||||
if(is_null($this->packingList)){
|
||||
$this->packingList = $this->transaction->owner->owner;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Orders\ControllersLogic;
|
||||
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractControllerLogic;
|
||||
use App\Classes\Modules\Orders\Services\FetchesOrder;
|
||||
use App\Classes\Modules\Orders\Standards\Rules\CanFetchOrder;
|
||||
use App\Http\Resources\OrderPackagesBaseResource;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class FetchOrderPackagesLogic extends AbstractControllerLogic
|
||||
{
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function notification():array {
|
||||
return [
|
||||
'title' => 'Retrieved Order Packages',
|
||||
'message' => 'You have successfully retrieved an order packages'
|
||||
];
|
||||
}
|
||||
|
||||
/** @var CanFetchOrder */
|
||||
private $canFetchOrder;
|
||||
|
||||
/** @var FetchesOrder */
|
||||
private $fetchesOrder;
|
||||
|
||||
/**
|
||||
* FetchOrderPackagesLogic constructor.
|
||||
* @param CanFetchOrder $canFetchOrder
|
||||
* @param FetchesOrder $fetchesOrder
|
||||
*/
|
||||
public function __construct(CanFetchOrder $canFetchOrder, FetchesOrder $fetchesOrder)
|
||||
{
|
||||
$this->canFetchOrder = $canFetchOrder;
|
||||
$this->fetchesOrder = $fetchesOrder;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @return JsonResponse
|
||||
* @throws \App\Classes\Exceptions\AccessForbiddenException
|
||||
* @throws \App\Classes\Exceptions\RequestValidationException
|
||||
*/
|
||||
public function logic(Request $request) : JsonResponse
|
||||
{
|
||||
|
||||
$this->canFetchOrder->passes();
|
||||
|
||||
$query = $this->fetchesOrder->execute(['reference' => $request->route('id'), 'with_packing_lists' => true]);
|
||||
|
||||
return $this->resourceResponse(new OrderPackagesBaseResource($query));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -68,21 +68,32 @@ class ListPackingListsLogic extends AbstractControllerLogic
|
||||
}
|
||||
else{
|
||||
$filters = json_decode($request->input('filters'), true);
|
||||
if(isset($filters['include_packages'])){
|
||||
//'include_packages' filter is an attempt to reduce the request-response time to only load basic information unless explicitly indicated to be included
|
||||
foreach ($query->items() as $item) {
|
||||
$useNew = false;
|
||||
foreach ($query->items() as $item) {
|
||||
if(isset($filters['include_packages'])){
|
||||
//'include_packages' filter is an attempt to reduce the request-response time to only load basic information unless explicitly indicated to be included
|
||||
$item['include_packages'] = $filters['include_packages'];
|
||||
$useNew = true;
|
||||
}
|
||||
}
|
||||
|
||||
if(isset($filters['include_receive_packing_list'])){
|
||||
//'include_receive_packing_list' filter is an attempt to reduce the request-response time to only load basic information unless explicitly indicated to be included
|
||||
foreach ($query->items() as $item) {
|
||||
if(isset($filters['include_receive_packing_list'])){
|
||||
//'include_receive_packing_list' filter is an attempt to reduce the request-response time to only load basic information unless explicitly indicated to be included
|
||||
$item['include_receive_packing_list'] = $filters['include_receive_packing_list'];
|
||||
$useNew = true;
|
||||
}
|
||||
|
||||
if(isset($filters['include_shipping_transaction'])){
|
||||
$item['include_shipping_transaction'] = $filters['include_shipping_transaction'];
|
||||
$useNew = true;
|
||||
}
|
||||
|
||||
if(isset($filters['include_suspended_invoice'])){
|
||||
$item['include_suspended_invoice'] = $filters['include_suspended_invoice'];
|
||||
$useNew = true;
|
||||
}
|
||||
}
|
||||
|
||||
if(isset($filters['include_packages']) || isset($filters['include_receive_packing_list']) ){
|
||||
if($useNew){
|
||||
return $this->collectionResponse(PackingListBaseResource::collection($query));
|
||||
}
|
||||
|
||||
|
||||
@@ -142,4 +142,43 @@ class UpdatePerfexCRMObject implements DataTransferObject
|
||||
{
|
||||
$this->invoiceId = $invoiceId;
|
||||
}
|
||||
|
||||
public function toArray(): array
|
||||
{
|
||||
return [
|
||||
'companyName' => $this->companyName,
|
||||
'companyReference' => $this->companyReference,
|
||||
'contactName' => $this->contactName,
|
||||
'contactEmail' => $this->contactEmail,
|
||||
'bookingMarking' => $this->bookingMarking,
|
||||
'projectName' => $this->projectName,
|
||||
'projectStatus' => $this->projectStatus,
|
||||
'invoiceId' => $this->invoiceId,
|
||||
'milestoneNames' => $this->milestoneNames,
|
||||
'tasks' => $this->tasks,
|
||||
];
|
||||
}
|
||||
|
||||
public function toJson(): string
|
||||
{
|
||||
return json_encode($this->toArray());
|
||||
}
|
||||
|
||||
public static function fromJson(string $json): self
|
||||
{
|
||||
$data = json_decode($json, true);
|
||||
|
||||
return new self(
|
||||
$data['companyName'],
|
||||
$data['companyReference'],
|
||||
$data['contactName'],
|
||||
$data['contactEmail'],
|
||||
$data['bookingMarking'],
|
||||
$data['projectName'],
|
||||
$data['projectStatus'],
|
||||
$data['invoiceId'],
|
||||
$data['milestoneNames'],
|
||||
$data['tasks']
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ use App\Models\PackingList;
|
||||
use App\Classes\ValueObjects\Constants\PerfexCRMProjectStatus;
|
||||
use App\Classes\ValueObjects\Constants\PerfexCRMTasksYDStages;
|
||||
use App\Classes\ValueObjects\Constants\PerfexCRMTaskStatus;
|
||||
use App\Models\DelayedJob;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class PackingListToPerfexCRMProcessor
|
||||
@@ -92,6 +93,29 @@ class PackingListToPerfexCRMProcessor
|
||||
|
||||
private function dispatchUpdateJob(PackingList $packingList, UpdatePerfexCRMObject $updatePerfexCRMObject)
|
||||
{
|
||||
try {
|
||||
/**
|
||||
* UpdatePerfexCRMPrelude constructor.
|
||||
* @param $packingList
|
||||
* @param Transaction $transaction
|
||||
* @param UpdatePerfexCRMObject $updatePerfexCRMObject
|
||||
* @param bool|null $shouldCreateInvoice
|
||||
*/
|
||||
DelayedJob::create([
|
||||
'job_class' => UpdatePerfexCRMPrelude::class,
|
||||
'parameters' => json_encode([
|
||||
'packingList' => $packingList,
|
||||
'transaction' => null,
|
||||
'updatePerfexCRMObject' => $updatePerfexCRMObject->toArray(),
|
||||
'shouldCreateInvoice' => false,
|
||||
]),
|
||||
'execute_at' => now()->addMinute(1),
|
||||
]);
|
||||
|
||||
} catch (\Exception $e) {
|
||||
Log::info('An unexpected error occurred when DelayedJob::create: ' . $e->getMessage());
|
||||
}
|
||||
|
||||
UpdatePerfexCRMPrelude::dispatch($packingList, null, $updatePerfexCRMObject, false);
|
||||
}
|
||||
|
||||
|
||||
+44
-7
@@ -66,6 +66,8 @@ class CheckStorageInvoiceTransactionProcessor
|
||||
/** @var DeletesBillplzBill */
|
||||
private $deletesBillplzBill;
|
||||
|
||||
private $defaultPricePerCBM = 3;
|
||||
|
||||
/**
|
||||
* @param FetchesOrder $fetchesOrder
|
||||
* @param GeneratesTransactionBillNumber $generatesTransactionBillNumber
|
||||
@@ -90,6 +92,20 @@ class CheckStorageInvoiceTransactionProcessor
|
||||
$this->updatesTransactionStatus = $updatesTransactionStatus;
|
||||
$this->deletesGroup = $deletesGroup;
|
||||
$this->deletesBillplzBill = $deletesBillplzBill;
|
||||
|
||||
$targetDate = Carbon::create(2024, 9, 22, 0, 0, 0, 'Asia/Kuala_Lumpur');
|
||||
$nowMalaysia = Carbon::now('Asia/Kuala_Lumpur');
|
||||
LogHelper::channel('storage_invoices')->info('targetDateMalaysia: ' . $targetDate->toIso8601String());
|
||||
LogHelper::channel('storage_invoices')->info('nowMalaysia: ' . $nowMalaysia->toIso8601String());
|
||||
|
||||
if ($nowMalaysia->greaterThanOrEqualTo($targetDate)) {
|
||||
LogHelper::channel('storage_invoices')->info('true');
|
||||
$this->defaultPricePerCBM = 6;
|
||||
}
|
||||
else{
|
||||
LogHelper::channel('storage_invoices')->info('false');
|
||||
$this->defaultPricePerCBM = 6;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -176,11 +192,12 @@ class CheckStorageInvoiceTransactionProcessor
|
||||
}
|
||||
|
||||
private function processSingleTransactionOfTypeShippingInvoice($transaction, $destinationWarehousePackage, $company_module_id, $eta){
|
||||
$pricePerCBM = 3;
|
||||
$pricePerCBM = $this->defaultPricePerCBM;
|
||||
$resultNumberOfDaysFree = 10;
|
||||
$dt1 = $eta->copy()->addDay()->startOfDay();
|
||||
$dt2 = Carbon::now()->copy()->addDay()->startOfDay();
|
||||
$interval = Carbon::parse($dt2)->diff($dt1);
|
||||
|
||||
LogHelper::channel('storage_invoices')->info('eta: '.json_encode($eta));
|
||||
LogHelper::channel('storage_invoices')->info('dt1: '.json_encode($dt1));
|
||||
LogHelper::channel('storage_invoices')->info('dt2: '.json_encode($dt2));
|
||||
@@ -222,6 +239,8 @@ class CheckStorageInvoiceTransactionProcessor
|
||||
$this->createStorageInvoiceTransactionDetails($storageInvoice, $destinationWarehousePackage, $cbm, $pricePerCBM, $resultNumberOfDaysExceeded, $taxPercentage);
|
||||
}
|
||||
else if($storageInvoice){
|
||||
$amount = $storageInvoice->amount;
|
||||
|
||||
//Additional handling for giving selected storage invoice a waiver
|
||||
if(isset($storageInvoice->is_waived) && $storageInvoice->is_waived){
|
||||
$pricePerCBM = 0;
|
||||
@@ -236,6 +255,15 @@ class CheckStorageInvoiceTransactionProcessor
|
||||
$intervalRecalculate = Carbon::parse($dateStorageInvoicePaid)->diff($dt1);
|
||||
$resultNumberOfDaysExceeded = $intervalRecalculate->days - $resultNumberOfDaysFree;
|
||||
$price_cbm = $pricePerCBM * $cbm * $resultNumberOfDaysExceeded;
|
||||
|
||||
try{
|
||||
$auditPricePerCbm = floor($amount / ($cbm * $resultNumberOfDaysExceeded));
|
||||
LogHelper::channel('storage_invoices')->info('auditPricePerCbm: '.$auditPricePerCbm);
|
||||
$pricePerCBM = $auditPricePerCbm;
|
||||
}
|
||||
catch(\Exception $ex){
|
||||
LogHelper::channel('storage_invoices')->info('auditPricePerCbm: '.$ex);
|
||||
}
|
||||
}
|
||||
|
||||
if (Carbon::now()->isAfter($dateToCompare)) {
|
||||
@@ -244,7 +272,6 @@ class CheckStorageInvoiceTransactionProcessor
|
||||
$price_cbm = $price_cbm + $total_tax;
|
||||
}
|
||||
|
||||
$amount = $storageInvoice->amount;
|
||||
$epsilon = 0.0001; // Tolerance for the comparison
|
||||
LogHelper::channel('storage_invoices')->info('Update $transaction->id: '.$transaction->id);
|
||||
LogHelper::channel('storage_invoices')->info('$storageInvoice->status: '.$storageInvoice->status);
|
||||
@@ -296,7 +323,7 @@ class CheckStorageInvoiceTransactionProcessor
|
||||
}
|
||||
|
||||
private function isPaidOrWaivedStorageInvoiceExist($transaction, $packingList, $eta){
|
||||
$pricePerCBM = 3;
|
||||
$pricePerCBM = $this->defaultPricePerCBM;
|
||||
$resultNumberOfDaysFree = 10;
|
||||
$dt1 = $eta->copy()->addDay()->startOfDay();
|
||||
$resultStartDate = $dt1->format('Y-m-d');
|
||||
@@ -317,10 +344,6 @@ class CheckStorageInvoiceTransactionProcessor
|
||||
if($storageInvoice){
|
||||
$storageInvoiceId = $storageInvoice->id;
|
||||
|
||||
if(isset($storageInvoice->is_waived) && $storageInvoice->is_waived){
|
||||
$pricePerCBM = 0;
|
||||
}
|
||||
|
||||
$transactionDetailsItems = $transaction->transactionDetails()->get();
|
||||
$cbm = 0.00;
|
||||
foreach ($transactionDetailsItems as $tdItem){
|
||||
@@ -331,6 +354,20 @@ class CheckStorageInvoiceTransactionProcessor
|
||||
$cbm = $cbm + $quantity;
|
||||
}
|
||||
|
||||
if(isset($storageInvoice->is_waived) && $storageInvoice->is_waived){
|
||||
$pricePerCBM = 0;
|
||||
}
|
||||
else{
|
||||
try{
|
||||
$auditPricePerCbm = floor($storageInvoice->amount / ($cbm * $resultNumberOfDaysExceeded));
|
||||
LogHelper::channel('storage_invoices')->info('auditPricePerCbm: '.$auditPricePerCbm);
|
||||
$pricePerCBM = $auditPricePerCbm;
|
||||
}
|
||||
catch(\Exception $ex){
|
||||
LogHelper::channel('storage_invoices')->info('auditPricePerCbm: '.$ex);
|
||||
}
|
||||
}
|
||||
|
||||
if($storageInvoiceId !== 0){
|
||||
$result = [
|
||||
'parentInvoiceId' => $transaction->id,
|
||||
|
||||
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands\V2;
|
||||
|
||||
use App\Classes\Jobs\UpdatePerfexCRMPrelude;
|
||||
use App\Classes\Modules\PerfexCRM\DataTransferObjects\UpdatePerfexCRMObject;
|
||||
use Illuminate\Console\Command;
|
||||
use App\Models\DelayedJob;
|
||||
use App\Models\PackingList;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
|
||||
class ProcessDelayedJobsV2Command extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'process-delayed-jobs-command';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Process and dispatch delayed jobs';
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$jobs = DelayedJob::orderBy('execute_at')
|
||||
->limit(150)
|
||||
->get();
|
||||
|
||||
$count = 0;
|
||||
foreach ($jobs as $index => $delayedJob) {
|
||||
$jobClass = $delayedJob->job_class;
|
||||
if($jobClass === UpdatePerfexCRMPrelude::class){
|
||||
$params = json_decode($delayedJob->parameters, true);
|
||||
|
||||
Log::info('ProcessDelayedJobsV2Command packingList : ' . json_encode($params['packingList']));
|
||||
Log::info('ProcessDelayedJobsV2Command packingList id : ' . json_encode($params['packingList']['id']));
|
||||
Log::info('ProcessDelayedJobsV2Command transaction : ' . json_encode($params['transaction']));
|
||||
Log::info('ProcessDelayedJobsV2Command updatePerfexCRMObject : ' . json_encode($params['updatePerfexCRMObject']));
|
||||
Log::info('ProcessDelayedJobsV2Command shouldCreateInvoice : ' . json_encode($params['shouldCreateInvoice']));
|
||||
|
||||
$updatePerfexCRMObject = UpdatePerfexCRMObject::fromJson(json_encode($params['updatePerfexCRMObject']));
|
||||
$packingList = PackingList::where('id', $params['packingList']['id'])->first();
|
||||
|
||||
$singleDelayedJob = new $jobClass(
|
||||
$packingList,
|
||||
$params['transaction'],
|
||||
$updatePerfexCRMObject,
|
||||
$params['shouldCreateInvoice']
|
||||
);
|
||||
|
||||
$delayInSeconds = intdiv($index, 2) * 10 ;
|
||||
dispatch($singleDelayedJob)->delay(now()->addSeconds($delayInSeconds));
|
||||
$delayedJob->delete();
|
||||
$count++;
|
||||
}
|
||||
|
||||
}
|
||||
Log::info('ProcessDelayedJobsV2Command Total delayed jobs processed and dispatched: ' . $count);
|
||||
}
|
||||
}
|
||||
@@ -44,24 +44,25 @@ class ProcessYDPortalDataV2Command extends Command
|
||||
$jobs = [];
|
||||
$jobs = array_merge($jobs, $this->fetchPackingListsFromYdPortalV2CommandJobs());
|
||||
$jobs = array_merge($jobs, $this->fetchContainersFromYdPortalV2CommandJobs());
|
||||
$jobsWithDelay1 = $this->fetchContainersUpdatesFromYdPortalV2CommandJob();
|
||||
$jobsWithDelay2 = $this->fetchDeliveryUpdatesFromYdPortalV2CommandJobs();
|
||||
$jobs2 = $this->fetchContainersUpdatesFromYdPortalV2CommandJob();
|
||||
$jobs3 = $this->fetchDeliveryUpdatesFromYdPortalV2CommandJobs();
|
||||
|
||||
// The following job is intentionally excluded
|
||||
////$jobs = array_merge($jobs, $this->fetchOrderListsFromYdPortalV2CommandJob());
|
||||
|
||||
// Bus::chain($jobs)->dispatch();
|
||||
|
||||
foreach ($jobs as $job) {
|
||||
dispatch($job);
|
||||
foreach ($jobs as $index => $job) {
|
||||
dispatch($job)->delay(now()->addSeconds($index * 2));
|
||||
}
|
||||
|
||||
foreach ($jobsWithDelay1 as $index => $job) {
|
||||
foreach ($jobs2 as $index => $job) {
|
||||
dispatch($job)->delay(now()->addSeconds($index * 1));
|
||||
}
|
||||
|
||||
foreach ($jobsWithDelay2 as $index => $job) {
|
||||
dispatch($job)->delay(now()->addSeconds($index * 1));
|
||||
foreach ($jobs3 as $index => $job) {
|
||||
$delayInSeconds = intdiv($index, 2);
|
||||
dispatch($job)->delay(now()->addSeconds($delayInSeconds));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -146,7 +147,7 @@ class ProcessYDPortalDataV2Command extends Command
|
||||
|
||||
$count = 0;
|
||||
foreach ($packingLists as $packingList) {
|
||||
if ($count >= 500) {
|
||||
if ($count >= 1000) {
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
@@ -34,6 +34,10 @@ class Kernel extends ConsoleKernel
|
||||
->everyFiveMinutes()
|
||||
->withoutOverlapping();
|
||||
|
||||
$schedule->command('process-delayed-jobs-command')
|
||||
->everyFiveMinutes()
|
||||
->withoutOverlapping();
|
||||
|
||||
$schedule->command('housekeeping-s3-files-command')
|
||||
->dailyAt('01:00')
|
||||
->withoutOverlapping();
|
||||
|
||||
@@ -7,6 +7,7 @@ use App\Classes\ValueObjects\Response\ApiResponseObject;
|
||||
use Illuminate\Auth\AuthenticationException;
|
||||
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
|
||||
use Illuminate\Foundation\Http\Exceptions\MaintenanceModeException;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Throwable;
|
||||
|
||||
class Handler extends ExceptionHandler
|
||||
@@ -36,6 +37,13 @@ class Handler extends ExceptionHandler
|
||||
*/
|
||||
public function report(Throwable $exception)
|
||||
{
|
||||
if (env('LOG_STACK_TRACE', false)) {
|
||||
Log::error($exception->getMessage(), [
|
||||
'exception' => $exception,
|
||||
'stack_trace' => $exception->getTraceAsString(),
|
||||
]);
|
||||
}
|
||||
|
||||
parent::report($exception);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Orders;
|
||||
|
||||
use App\Classes\Modules\Orders\ControllersLogic\FetchOrderPackagesLogic;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class FetchOrderPackagesController
|
||||
{
|
||||
/**
|
||||
* @param Request $request
|
||||
* @param FetchOrderLogic $logic
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function fetch(Request $request, FetchOrderPackagesLogic $logic): JsonResponse
|
||||
{
|
||||
return $logic->execute($request);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,99 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources;
|
||||
|
||||
use App\Classes\ValueObjects\Constants\ApprovalStatus;
|
||||
use App\Classes\ValueObjects\Constants\OrderRoleTypes;
|
||||
use App\Classes\ValueObjects\Constants\PackingListType;
|
||||
use App\Classes\ValueObjects\Constants\TransactionType;
|
||||
use App\Classes\ValueObjects\Constants\TransportType;
|
||||
use App\Models\Transaction;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class OrderPackagesBaseResource extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return array
|
||||
*/
|
||||
public function toArray($request)
|
||||
{
|
||||
$orderId = $this->id;
|
||||
|
||||
$origin_warehouse_packages = $this->originWarehousePackages()->get();
|
||||
foreach ($origin_warehouse_packages as $item) {
|
||||
$item['include_shipping_transaction'] = false;
|
||||
$item['include_suspended_invoice'] = false;
|
||||
$item['include_packages'] = true;
|
||||
$item['include_receive_packing_list'] = true;
|
||||
$item['include_order_in_packages'] = true;
|
||||
}
|
||||
|
||||
$in_transit_packages = $this->inTransitPackages()->get();
|
||||
foreach ($in_transit_packages as $item) {
|
||||
$item['include_shipping_transaction'] = false;
|
||||
$item['include_suspended_invoice'] = false;
|
||||
$item['include_packages'] = true;
|
||||
$item['include_receive_packing_list'] = true;
|
||||
$item['include_order_in_packages'] = true;
|
||||
}
|
||||
|
||||
$destination_warehouse_packages = $this->destinationWarehousePackages()->get();
|
||||
foreach ($destination_warehouse_packages as $item) {
|
||||
$item['include_shipping_transaction'] = false;
|
||||
$item['include_suspended_invoice'] = false;
|
||||
$item['include_packages'] = true;
|
||||
$item['include_receive_packing_list'] = true;
|
||||
$item['include_order_in_packages'] = true;
|
||||
}
|
||||
|
||||
$delivered_packages = $this->deliveredPackages()->get();
|
||||
foreach ($delivered_packages as $item) {
|
||||
$item['include_shipping_transaction'] = false;
|
||||
$item['include_suspended_invoice'] = false;
|
||||
$item['include_packages'] = true;
|
||||
$item['include_receive_packing_list'] = true;
|
||||
$item['include_order_in_packages'] = true;
|
||||
}
|
||||
|
||||
$received_packages = $this->packingLists()->where('type', PackingListType::WAREHOUSE_RECEIVE_LIST)->whereHas('packages')->get();
|
||||
foreach ($received_packages as $item) {
|
||||
$item['include_shipping_transaction'] = false;
|
||||
$item['include_suspended_invoice'] = false;
|
||||
$item['include_packages'] = true;
|
||||
$item['include_receive_packing_list'] = true;
|
||||
$item['include_order_in_packages'] = true;
|
||||
}
|
||||
|
||||
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'reference' => $this->reference,
|
||||
'reference_contract' => (int) $this->type,
|
||||
'type' => (int) $this->type,
|
||||
'status' => (int) $this->status,
|
||||
//'company_module' => new CompanyModuleResource($this->companyModule),
|
||||
//'warehouse' => new CompanyModuleResource($this->orderRoles()->where('role_id', '=', OrderRoleTypes::ORIGIN_WAREHOUSE)->first()->appointee),
|
||||
// 'address' => new AddressResource($this->addresses()->where('status', '=', ApprovalStatus::APPROVED)->first()),
|
||||
// 'address_change_request' => new AddressResource($this->addressesPendingVerification()->first()),
|
||||
'parcels' => $this->whenLoaded('packingLists', function() use ($origin_warehouse_packages, $in_transit_packages, $destination_warehouse_packages, $delivered_packages, $received_packages) {
|
||||
return [
|
||||
'origin_warehouse_packages' => PackingListBaseResource::collection($origin_warehouse_packages),
|
||||
'in_transit_packages' => PackingListBaseResource::collection($in_transit_packages),
|
||||
'destination_warehouse_packages' => PackingListBaseResource::collection($destination_warehouse_packages),
|
||||
'delivered_packages' => PackingListBaseResource::collection($delivered_packages),
|
||||
'received_packages' => PackingListBaseResource::collection($received_packages),
|
||||
];
|
||||
}),
|
||||
// 'invoices' => $this->whenLoaded('packingLists', function() use ($orderId) {
|
||||
// return TransactionResource::collection($this->transactions()->whereNotIn('transactions.status', [0, 1])->where('transactions.type', TransactionType::SHIPPING_INVOICE)->get());
|
||||
// }),
|
||||
//'remarks' => RemarkResource::collection($this->remarks),
|
||||
'created_at' => $this->created_at->format('d-m-Y')
|
||||
];
|
||||
|
||||
}
|
||||
}
|
||||
@@ -16,7 +16,7 @@ class PackageBaseResource extends JsonResource
|
||||
*/
|
||||
public function toArray($request)
|
||||
{
|
||||
return [
|
||||
$data = [
|
||||
'id' => $this->id,
|
||||
'type' => $this->type,
|
||||
'description' => $this->description,
|
||||
@@ -28,11 +28,15 @@ class PackageBaseResource extends JsonResource
|
||||
'cbm' => (($this->width / 100) * ($this->height / 100) * ($this->length / 100)) * $this->quantity,
|
||||
'reference' => $this->packingList->reference,
|
||||
'status' => $this->status,
|
||||
// $this->mergeWhen($originalPackingList->owner instanceof Order, [
|
||||
// 'order' => New OrderResource($originalPackingList->owner)
|
||||
// ]),
|
||||
// 'container' => new ContainerResource($originalPackingList->containers()->first()),
|
||||
// 'transport' => new TransportResource($originalPackingList->transports()->first())
|
||||
];
|
||||
|
||||
if($this->include_order) {
|
||||
$originalPackingList = $this->packingList->owner instanceof PackingList ? $this->packingList->owner : $this->packingList;
|
||||
$data['order'] = new OrderResource($originalPackingList->owner);
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,12 +25,15 @@ class PackingListBaseResource extends JsonResource
|
||||
$receive_packing_list = null;
|
||||
if($this->include_packages){
|
||||
$packages = !$this->packingLists()->exists() || $exceptionUsers ? $this->packages : $this->packingLists->first()->packages;
|
||||
foreach ($packages as $item) {
|
||||
$item['include_order'] = $this->include_order_in_packages;
|
||||
}
|
||||
}
|
||||
if($this->include_receive_packing_list){
|
||||
$receive_packing_list = $this->when($this->type === PackingListType::SHIPPING_PACKING_LIST, new PackingListResource(PackingList::where('reference', $this->reference)->where('type', PackingListType::WAREHOUSE_RECEIVE_LIST)->first()));
|
||||
}
|
||||
|
||||
return [
|
||||
$data = [
|
||||
'id' => $this->id,
|
||||
'claimant_id' => $this->claimant_id,
|
||||
'reference' => $this->reference,
|
||||
@@ -43,9 +46,17 @@ class PackingListBaseResource extends JsonResource
|
||||
$this->mergeWhen($this->owner instanceof Order, [
|
||||
'order' => New OrderResource($this->owner)
|
||||
]),
|
||||
'shipping_transaction' => new TransactionResource($this->transactions()->where('type', TransactionType::SHIPPING_INVOICE)->whereNotIn('status', [ApprovalStatus::SUSPENDED, ApprovalStatus::EXPIRED])->first()),
|
||||
'suspended_invoice' => new TransactionResource($this->transactions()->where('type', TransactionType::SHIPPING_INVOICE)->whereIn('status', [ApprovalStatus::SUSPENDED])->first()),
|
||||
// 'suspended_invoices' => TransactionResource::collection($this->transactions()->where('type', TransactionType::SHIPPING_INVOICE)->whereIn('status', [ApprovalStatus::SUSPENDED])->get()),
|
||||
];
|
||||
|
||||
if($this->include_shipping_transaction){
|
||||
$data['shipping_transaction'] = new TransactionResource($this->transactions()->where('type', TransactionType::SHIPPING_INVOICE)->whereNotIn('status', [ApprovalStatus::SUSPENDED, ApprovalStatus::EXPIRED])->first());
|
||||
}
|
||||
if($this->include_suspended_invoice){
|
||||
$data['suspended_invoice'] = new TransactionResource($this->transactions()->where('type', TransactionType::SHIPPING_INVOICE)->whereIn('status', [ApprovalStatus::SUSPENDED])->first());
|
||||
}
|
||||
|
||||
return $data;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class DelayedJob extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $table = 'jobs_delayed';
|
||||
|
||||
protected $fillable = [
|
||||
'job_class',
|
||||
'parameters',
|
||||
'execute_at',
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class CreateJobsDelayedTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('jobs_delayed', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('job_class');
|
||||
$table->json('parameters');
|
||||
$table->timestamp('execute_at');
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::dropIfExists('jobs_delayed');
|
||||
}
|
||||
}
|
||||
@@ -333,7 +333,7 @@
|
||||
methods: {
|
||||
fetchCompany(){
|
||||
this.isLoading = true;
|
||||
this.submit(route('api.order.show', this.order_number), 'get', this.section, false, false)
|
||||
this.submit(route('api.order.packages', this.order_number), 'get', this.section, false, false)
|
||||
},
|
||||
successHandler(response){
|
||||
this.dataLoaded = true;
|
||||
|
||||
+4
-4
@@ -102,23 +102,23 @@
|
||||
<div class="col bg-master-lightest p-1 p-sm-4">
|
||||
<div class="row tabsContainer tabContent" tab-name="pendingInvoice" v-if="isActiveTab('pendingInvoice') || showTabContent('pendingInvoice')">
|
||||
<div class="col">
|
||||
<admin-payments-billing-with-search-component :options="{does_not_have_transaction_type: 1, type: 2, per_page: 5, priority: 2, include_packages: true, include_receive_packing_list: true}" section="pendingInvoiceSection" invoice_status="Pending Invoice"></admin-payments-billing-with-search-component>
|
||||
<admin-payments-billing-with-search-component :options="{does_not_have_transaction_type: 1, type: 2, per_page: 5, priority: 2, include_packages: true, include_receive_packing_list: true, include_shipping_transaction: true, include_suspended_invoice: true}" section="pendingInvoiceSection" invoice_status="Pending Invoice"></admin-payments-billing-with-search-component>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row tabsContainer tabContent hide" tab-name="pendingApproval" v-if="isActiveTab('pendingApproval') || showTabContent('pendingApproval')">
|
||||
<div class="col">
|
||||
<admin-payments-billing-with-search-component :options="{has_invoice_status_in: [0, 1], per_page: 5, priority: 2, include_packages: true, include_receive_packing_list: true}" section="pendingApprovalSection" invoice_status="Pending Approval"></admin-payments-billing-with-search-component>
|
||||
<admin-payments-billing-with-search-component :options="{has_invoice_status_in: [0, 1], per_page: 5, priority: 2, include_packages: true, include_receive_packing_list: true, include_shipping_transaction: true, include_suspended_invoice: true }" section="pendingApprovalSection" invoice_status="Pending Approval"></admin-payments-billing-with-search-component>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row tabsContainer tabContent hide" tab-name="pendingPayment" v-if="isActiveTab('pendingPayment') || showTabContent('pendingPayment')">
|
||||
<div class="col">
|
||||
<payment-filter-component :endpoint="route('api.packing_list.list')" :data="data"></payment-filter-component>
|
||||
<admin-payments-billing-with-search-component :options="{has_invoice_status_in: [2], packing_list_limit_one_by_type_ordered_by_invoice_date: true, per_page: 5, check_for_storage_invoice: 1, include_packages: false, include_receive_packing_list: true}" section="pendingPaymentSection" invoice_status="Pending Payment" :with_export="true"></admin-payments-billing-with-search-component>
|
||||
<admin-payments-billing-with-search-component :options="{has_invoice_status_in: [2], packing_list_limit_one_by_type_ordered_by_invoice_date: true, per_page: 5, check_for_storage_invoice: 1, include_packages: false, include_receive_packing_list: true, include_shipping_transaction: true, include_suspended_invoice: true }" section="pendingPaymentSection" invoice_status="Pending Payment" :with_export="true"></admin-payments-billing-with-search-component>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row tabsContainer tabContent hide" tab-name="paidInvoice" v-if="isActiveTab('paidInvoice') || showTabContent('paidInvoice')">
|
||||
<div class="col">
|
||||
<admin-payments-billing-with-search-component :options="{has_invoice_status_in: [3], per_page: 5, check_for_storage_invoice: 1, include_packages: false, include_receive_packing_list: true}" section="paidInvoiceSection" invoice_status="Paid Invoice" :with_export="true"></admin-payments-billing-with-search-component>
|
||||
<admin-payments-billing-with-search-component :options="{has_invoice_status_in: [3], per_page: 5, check_for_storage_invoice: 1, include_packages: false, include_receive_packing_list: true, include_shipping_transaction: true, include_suspended_invoice: true }" section="paidInvoiceSection" invoice_status="Paid Invoice" :with_export="true"></admin-payments-billing-with-search-component>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -21,4 +21,5 @@ Route::group(['prefix' => 'order', 'as' => 'order.', 'namespace' => 'Orders'], f
|
||||
|
||||
Route::put('/assign-remark/{id}', 'AssignOrderRemarkController@create')->name('assign.remark');
|
||||
Route::get('/{id}/shipping-cost', 'ShippingCostController@calculate')->name('shipping.cost');
|
||||
Route::get('/packages/{id}', 'FetchOrderPackagesController@fetch')->name('packages');
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user