| Server IP : 34.87.99.72 / Your IP : 216.73.217.31 Web Server : Apache/2.4.46 (Unix) OpenSSL/1.1.1n System : Linux zlock-bitnami-lamp-prod-v2-vm 4.19.0-16-cloud-amd64 #1 SMP Debian 4.19.181-1 (2021-03-19) x86_64 User : bitnami ( 1000) PHP Version : 7.4.18 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : OFF Directory : /opt/bitnami/apache/htdocs/app/app/Http/Controllers/ |
Upload File : |
<?php
namespace App\Http\Controllers;
use App\Http\Controllers\Controller;
use App\Http\Requests\BoxBookings\BookingRequest as BoxDeliveryBookingRequest;
use App\Http\Requests\BoxBookings\ListRequest as BoxBookingListRequest;
use App\Http\Requests\BoxBookings\OpenBoxRequest as BoxBookingOpenBoxRequest;
use App\Http\Requests\BoxBookings\OverviewListRequest as BoxDeliveryOverviewListRequest;
use App\Http\Requests\BoxBookings\ExpiredListRequest as BoxBookingExpiredListRequest;
use App\Http\Requests\BoxBookings\CheckParcelInfoRequest;
use App\Http\Requests\BoxBookings\CheckDeliveryDetailRequest;
use App\Http\Requests\BoxBookings\QrCodeRequest;
use App\Http\Requests\BoxBookings\SliderOpenBoxRequest;
use App\Http\Requests\BoxBookings\ForceCancelRequest;
use App\Http\Requests\IdOnlyRequest;
use App\Http\Requests\ParamIdRequest;
use App\Http\Services\BoxInventoryService;
use App\Http\Services\BoxDeliveryService;
use App\Http\Services\GeoZoneService;
use Auth;
use App\Models\User;
use App\Models\UserBoxDelivery;
use App\Models\UserBoxInventory;
use Illuminate\Validation\ValidationException;
use Pylon\Exceptions\BadRequestException;
class BoxBookingController extends Controller
{
public function __construct(
BoxInventoryService $boxInventoryService,
BoxDeliveryService $boxDeliveryService,
GeoZoneService $geoZoneService
)
{
$this->boxDeliveryService = $boxDeliveryService;
$this->boxInventoryService = $boxInventoryService;
$this->geoZoneService = $geoZoneService;
}
/**
* @OA\Get(
*
* path="/api/box-booking/list/{type}",
* operationId="BoxBookingList",
* tags={"Box Booking"},
* summary="BoxBooking List",
* security={
* {
* "open_key": {}
* },
* {
* "api_key": {}
* }
* },
* @OA\Parameter(
* name="type",
* description="type",
* in="path",
* @OA\Schema(
* type="enum",
* default="history",
* enum={"on-going-history"}
* )
* ),
* @OA\Response(
* response=200,
* description="Success",
* @OA\JsonContent()
* ),
* @OA\Response(response=400, description="Bad request"),
* @OA\Response(response=404, description="Resource Not Found"),
* @OA\Response(response=422, description="Unprocessable Entity"),
* @OA\Response(response=500, description="Internal Server Error"),
* )
*/
public function boxBookingList(BoxBookingListRequest $request)
{
$payload = $request->validated();
$user = Auth::user();
if(Auth::user()->isSuperAdmin()){
$user = User::withTrashed()->where('id',$payload['user_id'])->firstOr(function(){
throw ValidationException::withMessages([
"user_id" => "User ID is unavailable.",
]);
});
}
switch ($payload['type']) {
case 'history':
$payload['user_id'] = $user->id;
$payload['or_collector_num'] = $user->mobile_num;
$payload['paginate'] = false;
break;
case 'collect':
$payload['delivery_user_id'] = $payload['user_id'];
unset($payload['user_id']);
$payload['collector_num'] = $user->mobile_num;
$payload['uncollected'] = true;
$payload['paginate'] = false;
break;
case 'drop-off':
$payload['user_id'] = $user->id;
$payload['uncollected'] = true;
$payload['paginate'] = false;
break;
case 'on-going-history':
$payload['paginate'] = false;
unset($payload['user_id']);
$payload['user_uncollected'] = $user->id;
$payload['or_collector_num_uncollected'] = $user->mobile_num;
break;
case 'on-going-history-paginate':
unset($payload['user_id']);
$payload['user_uncollected'] = $user->id;
$payload['paginate'] = false;
$payload['or_collector_num_uncollected'] = $user->mobile_num;
break;
default:
break;
}
$boxDeliverys = $this->boxDeliveryService->boxDeliveryList( $payload );
// manual compute
$boxDeliverys->each(function($item, $key) use ($user, $payload){
$item->getInventoryType($user);
$item->getQrCode();
});
$boxDeliverys->append(['inventory_type','total_usage_time']);
$boxInventorys = $this->boxInventoryService->boxInventoryList( $payload );
// manual compute
$boxInventorys->each(function($item, $key) use ($user, $payload){
$item->getInventoryType($user);
$item->getQrCode();
});
$boxInventorys->append(['inventory_type','total_usage_time']);
$boxBookings = $boxDeliverys->merge($boxInventorys);
if($payload['type'] != 'on-going-history')
{
$boxBookings = $boxBookings->toPaginate($payload['itemsPerPage'] ?? null);
}
return self::successResponse('Success', $boxBookings);
}
public function boxDeliveryInfo(ParamIdRequest $request)
{
$payload = $request->validated();
$boxDelivery = $this->boxDeliveryService->boxDeliveryInfo( $payload );
// manual compute
$boxDelivery->getInventoryType($boxDelivery->dropper);
$boxDelivery->append(['inventory_type','total_usage_time']);
return self::successResponse('Success', $boxDelivery );
}
/**
* @OA\Post(
*
* path="/api/box-booking/open-box",
* operationId="boxBookingOpenBox",
* tags={"Box Booking"},
* summary="boxBookingOpenBox",
* security={
* {
* "open_key": {}
* },
* {
* "api_key": {}
* }
* },
* @OA\Parameter(
* name="type",
* description="type",
* in="query",
* @OA\Schema(
* type="enum",
* enum={"inventory", "delivery"}
* )
* ),
* @OA\Parameter(
* name="id",
* description="id",
* in="query",
* @OA\Schema(
* type="string",
* default=""
* )
* ),
* @OA\Response(
* response=200,
* description="Success",
* @OA\JsonContent()
* ),
* @OA\Response(response=400, description="Bad request"),
* @OA\Response(response=404, description="Resource Not Found"),
* @OA\Response(response=422, description="Unprocessable Entity"),
* @OA\Response(response=500, description="Internal Server Error"),
* )
*/
public function boxBookingOpenBox(BoxBookingOpenBoxRequest $request)
{
$payload = $request->validated();
$payload['user_id'] = Auth::id();
if($payload['type'] == "inventory")
$boxBooking = $this->boxInventoryService->boxInventoryOpenBox( $payload );
else if($payload['type'] == "delivery")
$boxBooking = $this->boxDeliveryService->boxDeliveryOpenBox( $payload );
return self::successResponse('Success',$boxBooking);
}
/**
* @OA\Post(
*
* path="/api/box-booking/qr-open-box",
* operationId="boxBookingQrOpenBox",
* tags={"Box Booking"},
* summary="boxBookingQrOpenBox",
* security={
* {
* "open_key": {}
* },
* {
* "api_key": {}
* }
* },
* @OA\Parameter(
* name="booking_type",
* description="booking_type",
* in="query",
* @OA\Schema(
* type="enum",
* enum={"inventory", "delivery"}
* )
* ),
* @OA\Parameter(
* name="id",
* description="id",
* in="query",
* @OA\Schema(
* type="string",
* default=""
* )
* ),
* @OA\Response(
* response=200,
* description="Success",
* @OA\JsonContent()
* ),
* @OA\Response(response=400, description="Bad request"),
* @OA\Response(response=404, description="Resource Not Found"),
* @OA\Response(response=422, description="Unprocessable Entity"),
* @OA\Response(response=500, description="Internal Server Error"),
* )
*/
public function boxBookingQrOpenBox(SliderOpenBoxRequest $request)
{
$payload = $request->validated();
$payload['user_id'] = Auth::id();
$payload['mobile_num'] = Auth::user()->mobile_num;
$payload['now'] = now();
if($payload['booking_type'] == "inventory")
{
$boxInventory = UserBoxInventory::find($payload['id']);
if($boxInventory->isDropOff($payload['user_id']))
$boxBooking = $this->boxInventoryService->boxInventoryOpenBox( $payload, $is_qr = true);
else if($boxInventory->isCollect($payload['mobile_num']))
$boxBooking = $this->boxInventoryService->boxInventoryCollect( $payload, $is_cancelling = false, $is_qr = true);
else if($boxInventory->isCancelQr($payload['user_id']))
$boxBooking = $this->boxInventoryService->boxInventoryCollect( $payload, $is_cancelling = true, $is_qr = true);
else
throw new BadRequestException("You are not authorized to drop off/collect this order!");
}
else if($payload['booking_type'] == "delivery")
{
$boxDelivery = UserBoxDelivery::find($payload['id']);
if($boxDelivery->isDropOff())
$boxBooking = $this->boxDeliveryService->boxDeliveryOpenBox( $payload, $is_qr = true);
else if($boxDelivery->isCancelQr())
$boxBooking = $this->boxDeliveryService->boxDeliveryCollect( $payload, $is_cancelling = true, $is_qr = true);
else {
throw new BadRequestException("Drop off/Collection is not yet ready for this order, please wait.");
}
}
else {
throw new BadRequestException("Drop off/Collection is not yet ready for this order, please wait.");
}
return self::successResponse('Success',$boxBooking);
}
/**
* @OA\Get(
*
* path="/api/box-booking/expired-list",
* operationId="boxBookingExpiredList",
* tags={"Box Booking"},
* summary="boxBookingExpiredList",
* security={
* {
* "open_key": {}
* },
* {
* "api_key": {}
* }
* },
* @OA\Parameter(
* name="terminal_id",
* description="terminal_id",
* in="query",
* @OA\Schema(
* type="string",
* default=""
* )
* ),
* @OA\Response(
* response=200,
* description="Success",
* @OA\JsonContent()
* ),
* @OA\Response(response=400, description="Bad request"),
* @OA\Response(response=404, description="Resource Not Found"),
* @OA\Response(response=422, description="Unprocessable Entity"),
* @OA\Response(response=500, description="Internal Server Error"),
* )
*/
public function boxBookingExpiredList(BoxBookingExpiredListRequest $request)
{
$payload = $request->validated();
$boxInventory = $this->boxInventoryService->boxInventoryExpiredList( $payload );
//$boxDelivery = $this->boxDeliveryService->boxDeliveryExpiredList( $payload );
//$boxBooking = $boxInventory->merge($boxDelivery);
$result = $boxInventory->toPaginate($payload['itemsPerPage'] ?? null);
return self::successResponse('Success',$result);
}
/**
* @OA\Post(
*
* path="/api/box-booking/force-cancel",
* operationId="forceCancel",
* tags={"Box Booking"},
* summary="forceCancel",
* security={
* {
* "open_key": {}
* },
* {
* "api_key": {}
* }
* },
* @OA\Parameter(
* name="booking_type",
* description="booking_type",
* in="query",
* @OA\Schema(
* type="enum",
* enum={"inventory", "delivery"}
* )
* ),
* @OA\Parameter(
* name="id",
* description="id",
* in="query",
* @OA\Schema(
* type="string",
* default=""
* )
* ),
* @OA\Response(
* response=200,
* description="Success",
* @OA\JsonContent()
* ),
* @OA\Response(response=400, description="Bad request"),
* @OA\Response(response=404, description="Resource Not Found"),
* @OA\Response(response=422, description="Unprocessable Entity"),
* @OA\Response(response=500, description="Internal Server Error"),
* )
*/
public function boxBookingForceCancel(ForceCancelRequest $request)
{
$payload = $request->validated();
$payload['user'] = Auth::user();
if($payload['booking_type'] == "inventory")
{
$result = $this->boxInventoryService->boxInventoryForceCancel( $payload );
}
else if($payload['booking_type'] == "delivery")
{
$result = $this->boxDeliveryService->boxDeliveryForceCancel( $payload );
}
return self::successResponse('Success',$result);
}
}