service report

This commit is contained in:
omair saleh
2021-10-05 17:02:17 +08:00
parent 647103f387
commit 943ec5f7f7
5 changed files with 108 additions and 35 deletions
@@ -61,26 +61,22 @@ class MonthlyReportController
return (new ApiResponseObject('fetch service report Successful',
'',
HttpStatus::OK_WITH_MESSAGE, ['data' => [
'received' => Package::whereHas('packingList', function($query){
return $query->where('type', PackingListType::WAREHOUSE_RECEIVE_LIST);
'received' => Package::warehouseReceiveList()->sum('quantity'),
'pending_shipment' => Package::shippingList()->whereDoesntHave('shippingSchedules', function($schedule){
return $schedule->dispatched()->whereIn('schedules.status', [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED]);
})->sum('quantity'),
'pending_shipment' => Package::whereDoesntHave('shippingSchedules', function($schedule){
return $schedule->where('etd', '<', Carbon::now())->where('schedules.status', ApprovalStatus::APPROVED);
'in_transit' => Package::shippingList()->Shipping()->whereHas('shippingSchedules', function($schedule){
return $schedule->dispatched()->whereIn('schedules.status', [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED]);
})->whereDoesntHave('shippingSchedules', function($schedule){
return $schedule->dropped()->whereIn('schedules.status', [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED]);
})->sum('quantity'),
'in_transit' => Package::whereHas('shippingSchedules', function($schedule){
return $schedule->where('etd', '<', Carbon::now())->where('schedules.status', ApprovalStatus::APPROVED);
})->whereDoesntHave('shippingTransports', function($transport){
return $transport->where('transport_arrangements.status', ApprovalStatus::COMPLETED);
})->sum('quantity'),
'pending_delivery' => Package::whereHas('shippingTransports', function($transport){
return $transport->where('transport_arrangements.status', ApprovalStatus::COMPLETED);
'pending_delivery' => Package::shippingList()->whereHas('shippingSchedules', function($schedule){
return $schedule->dropped()->whereIn('schedules.status', [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED]);
})->whereDoesntHave('deliverySchedules', function($schedule){
return $schedule->where('etd', '<', Carbon::now())->where('schedules.status', ApprovalStatus::APPROVED);
return $schedule->dispatched()->whereIn('schedules.status', [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED]);
})->sum('quantity'),
'delivered' => Package::whereHas('shippingSchedules', function($schedule){
return $schedule->where('eta', '<', Carbon::now())->where('schedules.status', ApprovalStatus::APPROVED);
})->whereHas('deliverySchedules', function($schedule){
return $schedule->where('etd', '<', Carbon::now())->where('schedules.status', ApprovalStatus::APPROVED);
'delivered' => Package::shippingList()->whereHas('deliverySchedules', function($schedule){
return $schedule->dispatched()->whereIn('schedules.status', [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED]);
})->sum('quantity'),
]]))->handler();
}
+12 -16
View File
@@ -31,27 +31,23 @@ class OrderResource extends JsonResource
'address_change_request' => new AddressResource($this->addressesPendingVerification()->first()),
'parcels' => $this->whenLoaded('packingLists', function(){
return [
'origin_warehouse_packages' => PackageResource::collection($this->parcels()->whereDoesntHave('shippingSchedules', function($schedule){
return $schedule->where('etd', '<', Carbon::now())->where('schedules.status', ApprovalStatus::APPROVED);
'origin_warehouse_packages' => PackageResource::collection($this->parcels()->shippingList()->whereDoesntHave('shippingSchedules', function($schedule){
return $schedule->dispatched()->whereIn('schedules.status', [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED]);
})->get()),
'in_transit_packages' => PackageResource::collection($this->parcels()->whereHas('shippingSchedules', function($schedule){
return $schedule->where('etd', '<', Carbon::now())->where('schedules.status', ApprovalStatus::APPROVED);
})->whereDoesntHave('shippingTransports', function($transport){
return $transport->where('transport_arrangements.status', ApprovalStatus::COMPLETED);
'in_transit_packages' => PackageResource::collection($this->parcels()->shippingList()->Shipping()->whereHas('shippingSchedules', function($schedule){
return $schedule->dispatched()->whereIn('schedules.status', [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED]);
})->whereDoesntHave('shippingSchedules', function($schedule){
return $schedule->dropped()->whereIn('schedules.status', [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED]);
})->get()),
'destination_warehouse_packages' => PackageResource::collection($this->parcels()->whereHas('shippingTransports', function($transport){
return $transport->where('transport_arrangements.status', ApprovalStatus::COMPLETED);
'destination_warehouse_packages' => PackageResource::collection($this->parcels()->shippingList()->whereHas('shippingSchedules', function($schedule){
return $schedule->dropped()->whereIn('schedules.status', [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED]);
})->whereDoesntHave('deliverySchedules', function($schedule){
return $schedule->where('etd', '<', Carbon::now())->where('schedules.status', ApprovalStatus::APPROVED);
return $schedule->dispatched()->whereIn('schedules.status', [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED]);
})->get()),
'delivered_packages' => PackageResource::collection($this->parcels()->whereHas('shippingSchedules', function($schedule){
return $schedule->where('eta', '<', Carbon::now())->where('schedules.status', ApprovalStatus::APPROVED);
})->whereHas('deliverySchedules', function($schedule){
return $schedule->where('etd', '<', Carbon::now())->where('schedules.status', ApprovalStatus::APPROVED);
})->get()),
'received_packages' => PackageResource::collection($this->parcels()->whereHas('packingList', function($query){
return $query->where('type', PackingListType::WAREHOUSE_RECEIVE_LIST);
'delivered_packages' => PackageResource::collection($this->parcels()->shippingList()->whereHas('deliverySchedules', function($schedule){
return $schedule->dispatched()->whereIn('schedules.status', [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED]);
})->get()),
'received_packages' => PackageResource::collection($this->parcels()->warehouseReceiveList()->get()),
];
}),
'created_at' => $this->created_at->format('d-m-Y')
+48 -2
View File
@@ -2,10 +2,11 @@
namespace App\Models;
use App\Classes\ValueObjects\Constants\ApprovalStatus;
use App\Classes\ValueObjects\Constants\PackingListType;
use Carbon\Carbon;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasManyThrough;
use Illuminate\Database\Eloquent\Relations\HasOneThrough;
use Illuminate\Database\Eloquent\Relations\MorphTo;
use Illuminate\Database\Eloquent\SoftDeletes;
use Staudenmeir\EloquentHasManyDeep\HasOneDeep;
use Staudenmeir\EloquentHasManyDeep\HasRelationships;
@@ -25,6 +26,7 @@ class Package extends AbstractModel
return $this->belongsTo(PackingList::class, 'packing_list_id');
}
/**
* @return HasManyThrough
*/
@@ -73,4 +75,48 @@ class Package extends AbstractModel
return $this->hasOneDeep(Transport::class, [PackingList::class], ['id', ['owner_type', 'owner_id']], ['packing_list_id', null]);
}
/**
* @param $query
* @return mixed
*/
public function scopeShipping($query){
return $query->whereHas('shippingSchedules', function($schedule){
return $schedule->where('etd', '<', Carbon::now())->where('schedules.status', ApprovalStatus::APPROVED);
})->whereDoesntHave('shippingTransports', function($transport){
return $transport->where('transport_arrangements.status', ApprovalStatus::COMPLETED);
});
}
/**
* @param $query
* @return mixed
*/
public function scopeShipped($query){
return $query->whereHas('shippingSchedules', function($schedule){
return $schedule->where('etd', '<', Carbon::now())->where('schedules.status', ApprovalStatus::APPROVED);
})->whereDoesntHave('shippingTransports', function($transport){
return $transport->where('transport_arrangements.status', ApprovalStatus::COMPLETED);
});
}
/**
* @param $query
* @return mixed
*/
public function scopeShippingList($query){
return $query->whereHas('packingList', function($packingList){
return $packingList->where('type', PackingListType::SHIPPING_PACKING_LIST);
});
}
/**
* @param $query
* @return mixed
*/
public function scopeWarehouseReceiveList($query){
return $query->whereHas('packingList', function($packingList){
return $packingList->where('type', PackingListType::WAREHOUSE_RECEIVE_LIST);
});
}
}
+18
View File
@@ -2,6 +2,8 @@
namespace App\Models;
use App\Classes\ValueObjects\Constants\ApprovalStatus;
use Carbon\Carbon;
use Illuminate\Database\Eloquent\Relations\MorphTo;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
@@ -23,4 +25,20 @@ class Schedule extends AbstractModel
{
return $this->BelongsTo(Transport::class, 'transport_id', 'id');
}
/**
* @param $query
* @return mixed
*/
public function scopeDispatched($query){
return $query->where('etd', '<', Carbon::now());
}
/**
* @param $query
* @return mixed
*/
public function scopeDropped($query){
return $query->where('eta', '<', Carbon::now());
}
}
+18 -1
View File
@@ -2,9 +2,10 @@
namespace App\Models;
use App\Classes\ValueObjects\Constants\ApprovalStatus;
use Carbon\Carbon;
use Illuminate\Database\Eloquent\Relations\MorphTo;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\MorphMany;
class Transport extends AbstractModel
@@ -32,4 +33,20 @@ class Transport extends AbstractModel
{
return $this->morphMany(Schedule::class, 'owner');
}
/**
* @param $query
* @return mixed
*/
public function scopeDispatched($query){
return $query->where('dispatch_date', '<', Carbon::now())->whereIn('status', [ApprovalStatus::APPROVED]);
}
/**
* @param $query
* @return mixed
*/
public function scopeDropped($query){
return $query->where('drop_date', '<', Carbon::now())->whereIn('status', [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED]);
}
}