large changes

This commit is contained in:
Omair Saleh
2019-04-12 18:25:22 +08:00
parent 9a8634547b
commit a7cb7b5eb6
8 changed files with 41 additions and 16 deletions
@@ -32,7 +32,7 @@ class ListsCompanyCancelledOrders
try {
/** @var Order $orders */
$orders = $this->repository->where('company_id', $id)
->onlyTrashed()->get();
->onlyTrashed()->orderBy('created_at', 'desc')->get();
return OrderResource::collection($orders);
@@ -31,7 +31,7 @@ class ListsCompanyCompleteOrders
try {
/** @var Order $orders */
$orders = $this->repository->where('company_id', $id)
->where('complete', true)->get();
->where('complete', true)->orderBy('created_at', 'desc')->get();
return OrderResource::collection($orders);
@@ -27,7 +27,7 @@ class ListsCompanyOrdersCategory
try {
/** @var Order $orders */
$orders = $this->repository->where('company_id', $id)
->whereIn('current_step', $category)->get();
->whereIn('current_step', $category)->orderBy('created_at', 'desc')->get();
return OrderResource::collection($orders);
} catch (\Exception $exception){
@@ -1,10 +1,4 @@
<?php
/**
* Created by PhpStorm.
* User: user
* Date: 22/03/2019
* Time: 10:03 AM
*/
namespace App\Classes\Modules\Orders\Services;
@@ -4,8 +4,10 @@ namespace App\Classes\Modules\Orders\Services;
use App\Classes\Constants;
use App\Models\CustomIssues;
use App\Models\Order;
use Illuminate\Support\Carbon;
use Carbon\Carbon;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Collection;
class ListsOrderHistory
@@ -32,13 +34,26 @@ class ListsOrderHistory
$history->push(['date' => $step->updated_at->format('d-m-Y H:i'), 'description' => 'Your Order has been loaded into container']);
break;
case Constants::ORDER_WAREHOUSE_RECEIVING_STEP:
$history->push(['date' => $step->updated_at->format('d-m-Y H:i'), 'description' => 'Arrived at China\'s warehouse']);
$history->push(['date' => $step->updated_at->format('d-m-Y H:i'), 'description' => 'Arrived at China\'s warehouse on: ['.Carbon::parse($order->receiveNotes()->firstOrFail()->receive_date)->format('d-m-Y').']']);
break;
case Constants::ORDER_WAREHOUSE_PACKING_STEP:
$history->push(['date' => $step->updated_at->format('d-m-Y H:i'), 'description' => 'Your Order has been loaded into container']);
$packages = $order->packingLists()->firstOrFail()->packages()->selectRaw(DB::raw('((width/100) * (height/100) * (length/100)) * quantity as cbm, quantity'))->get();
$history->push(['date' => $step->updated_at->format('d-m-Y H:i'), 'description' => '['.$packages->sum('quantity').' Packages, '.number_format((float)$packages->sum('cbm'), 2, '.', '').' CBM] Your order has been loaded into container']);
$history->push(['date' => $step->updated_at->format('d-m-Y H:i'), 'description' => 'Invoice has been issued, waiting for shipping payment']);
break;
case Constants::ORDER_SHIPPING_STEP:
$shippingArrangment = $order->shippingArrangement()->first();
if($shippingArrangment){
$shippingSchedules = $shippingArrangment->shippingSchedule()->get();
foreach ($shippingSchedules as $schedule){
if($schedule->status === "2"){
$customeIssue = CustomIssues::where('schedule_id', $schedule->id)->firstOrFail();
$history->push(['date' => $step->updated_at->format('d-m-Y H:i'), 'description' => '[ETD: '.$schedule->ETD.', ETA: '.$schedule->ETA.'] Shipping Schedule failed due to: '.$customeIssue->remark]);
} else {
$history->push(['date' => $step->updated_at->format('d-m-Y H:i'), 'description' => '[ETD: '.$schedule->ETD.', ETA: '.$schedule->ETA.'] Your Order has been scheduled for shipping ']);
}
}
}
$history->push(['date' => $step->updated_at->format('d-m-Y H:i'), 'description' => 'Arrived to Malaysian port']);
$history->push(['date' => $step->updated_at->format('d-m-Y H:i'), 'description' => 'Custom clearance is successful']);
break;
@@ -54,6 +69,22 @@ class ListsOrderHistory
}
}
if($order->current_step === Constants::ORDER_SHIPPING_STEP){
$shippingArrangment = $order->shippingArrangement()->first();
if($shippingArrangment){
$shippingSchedules = $shippingArrangment->shippingSchedule()->get();
foreach ($shippingSchedules as $schedule){
if($schedule->status === "2"){
$customeIssue = CustomIssues::where('schedule_id', $schedule->id)->firstOrFail();
$history->push(['date' => $step->updated_at->format('d-m-Y H:i'), 'description' => '[ETD: '.$schedule->ETD.', ETA: '.$schedule->ETA.'] Shipping Schedule failed due to: '.$customeIssue->remark]);
} else {
$history->push(['date' => $step->updated_at->format('d-m-Y H:i'), 'description' => '[ETD: '.$schedule->ETD.', ETA: '.$schedule->ETA.'] Your Order has been scheduled for shipping ']);
}
}
}
}
if($complete){
$history->push(['date' => $lastUpdate->format('d-m-Y H:i'), 'description' => 'Your Order has successfully been delivered']);
}