| 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\BoxInventories\BookingRequest as BoxInventoryBookingRequest;
use App\Http\Requests\BoxInventories\ListRequest as BoxInventoryListRequest;
use App\Http\Requests\BoxInventories\OverviewListRequest as BoxInventoryOverviewListRequest;
use App\Http\Requests\BoxInventories\ExpiredListRequest as BoxInventoryExpiredListRequest;
use App\Http\Requests\BoxInventories\LockerBookingRequest as BoxInventoryLockerBookingRequest;
use App\Http\Requests\BoxInventories\QrCodeRequest;
use App\Http\Requests\IdOnlyRequest;
use App\Http\Requests\ParamIdRequest;
use App\Http\Services\BoxInventoryService;
use Auth;
use App\Models\Locker;
use App\Models\User;
use App\Models\UserBoxInventory;
use Illuminate\Validation\ValidationException;
class BoxInventoryController extends Controller
{
public function __construct(
BoxInventoryService $boxInventoryService
)
{
$this->boxInventoryService = $boxInventoryService;
}
/**
* @OA\Get(
*
* path="/api/box-inventory/list/{type}",
* operationId="BoxInventoryList",
* tags={"Box Inventory"},
* summary="BoxInventory List",
* security={
* {
* "open_key": {}
* },
* {
* "api_key": {}
* }
* },
* @OA\Parameter(
* name="type",
* description="type",
* in="path",
* @OA\Schema(
* type="enum",
* default="history",
* enum={"history", "collect", "drop-off","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 boxInventoryList(BoxInventoryListRequest $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;
break;
case 'collect':
$payload['collector_num'] = $user->mobile_num;
$payload['uncollected'] = true;
break;
case 'drop-off':
$payload['user_id'] = $user->id;
$payload['uncollected'] = true;
break;
case 'on-going-history':
unset($payload['user_id']);
$payload['user_uncollected'] = $user->id;
$payload['or_collector_num_uncollected'] = $user->mobile_num;
$payload['paginate'] = true;
break;
default:
break;
}
$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']);
return self::successResponse('Success', $boxInventorys);
}
/**
* @OA\Get(
*
* path="/api/box-inventory/info/{id}",
* operationId="boxInventoryInfo",
* tags={"Box Inventory"},
* summary="BoxInventoryInfo",
* security={
* {
* "open_key": {}
* },
* {
* "api_key": {}
* }
* },
* @OA\Parameter(
* name="id",
* description="id",
* in="path",
* @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 boxInventoryInfo(ParamIdRequest $request)
{
$payload = $request->validated();
$boxInventory = $this->boxInventoryService->boxInventoryInfo( $payload );
// manual compute
$boxInventory->getInventoryType($boxInventory->dropper);
$boxInventory->append(['inventory_type','total_usage_time']);
return self::successResponse('Success', $boxInventory );
}
/**
* @OA\Get(
*
* path="/api/box-inventory/generate-qr-code",
* operationId="generateQrCode",
* tags={"Box Inventory"},
* summary="Generate QR Code",
* security={
* {
* "open_key": {}
* },
* {
* "api_key": {}
* }
* },
* @OA\Parameter(
* name="id",
* description="id",
* in="query",
* @OA\Schema(
* type="string",
* default=""
* )
* ),
* @OA\Parameter(
* name="type",
* description="Type of Qr Code",
* in="query",
* @OA\Schema(
* type="string",
* default="",
* enum={"dropper", "collector"},
* )
* ),
* @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 generateQrCode(QrCodeRequest $request)
{
$payload = $request->validated();
$payload['user_id'] = Auth::id();
$qrCode = $this->boxInventoryService->generateQrCode( $payload );
return self::successResponse('Success',$qrCode);
}
public function boxInventoryOverviewList(BoxInventoryOverviewListRequest $request)
{
$payload = $request->validated();
if(Auth::user()->isPartner()){
$payload['partner_id'] = Auth::id();
}
$boxInventorys = $this->boxInventoryService->boxInventoryList( $payload );
$boxInventorys->append(['total_booking_fee', 'total_booking_fee_partner']);
return self::successResponse('Success', $boxInventorys);
}
public function exportBoxInventoryOverviewList(BoxInventoryOverviewListRequest $request)
{
$payload = $request->validated();
if(Auth::user()->isPartner()){
$payload['partner_id'] = Auth::id();
}
$boxInventorys = $this->boxInventoryService->exportBoxInventoryList( $payload );
return self::successResponse('Success', $boxInventorys);
}
/**
* @OA\Post(
*
* path="/api/box-inventory/booking",
* operationId="boxInventoryBooking",
* tags={"Box Inventory"},
* summary="boxInventoryBooking",
* security={
* {
* "open_key": {}
* },
* {
* "api_key": {}
* }
* },
* @OA\Parameter(
* name="locker_id",
* description="locker_id",
* in="query",
* @OA\Schema(
* type="string",
* default=""
* )
* ),
* @OA\Parameter(
* name="box_size_id",
* description="box_size_id",
* in="query",
* @OA\Schema(
* type="string",
* default=""
* )
* ),
* @OA\Parameter(
* name="reserved_minute",
* description="reserved_minute",
* in="query",
* @OA\Schema(
* type="string",
* default=""
* )
* ),
* @OA\Parameter(
* name="collector_num",
* description="collector_num",
* in="query",
* @OA\Schema(
* type="string",
* default=""
* )
* ),
* @OA\Parameter(
* name="credit_amount",
* description="credit_amount",
* 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 boxInventoryBooking(BoxInventoryBookingRequest $request)
{
$payload = $request->validated();
$payload['user_id'] = Auth::id();
$payload['type'] = 'inventory_booking';
$boxInventory = $this->boxInventoryService->boxInventoryBooking( $payload );
return self::successResponse('Success',$boxInventory);
}
/**
* @OA\Post(
*
* path="/api/box-inventory/locker-booking",
* operationId="lockerInventoryBooking",
* tags={"Box Inventory"},
* summary="Perform inventory booking at the locker",
* security={
* {
* "open_key": {}
* },
* {
* "api_key": {}
* }
* },
* @OA\Parameter(
* name="terminal_id",
* description="terminal_id",
* in="query",
* @OA\Schema(
* type="string",
* default=""
* )
* ),
* @OA\Parameter(
* name="box_size_id",
* description="box_size_id",
* in="query",
* @OA\Schema(
* type="string",
* default=""
* )
* ),
* @OA\Parameter(
* name="shipment_id",
* description="shipment_id",
* in="query",
* @OA\Schema(
* type="string",
* default=""
* )
* ),
* @OA\Parameter(
* name="collector_num",
* description="collector_num",
* in="query",
* @OA\Schema(
* type="string",
* default=""
* )
* ),
* @OA\Parameter(
* name="recipient_name",
* description="recipient_name",
* 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 lockerBoxInventoryBooking(BoxInventoryLockerBookingRequest $request)
{
$payload = $request->validated();
$locker = Locker::where('terminal_id', $request['terminal_id'])
->withTrashed()
->first();
$payload['type'] = 'inventory_booking';
$payload['reserved_minute'] = UserBoxInventory::DEFAULT_RESERVED_MINUTES;
$payload['user_id'] = null;
$payload['locker_id'] = $locker->id;
$payload['dirty_at'] = now();
$boxInventory = $this->boxInventoryService->boxInventoryBooking( $payload );
return self::successResponse('Success',$boxInventory);
}
/**
* @OA\Post(
*
* path="/api/box-inventory/open-box",
* operationId="boxInventoryOpenBox",
* tags={"Box Inventory"},
* summary="boxInventoryOpenBox",
* security={
* {
* "open_key": {}
* },
* {
* "api_key": {}
* }
* },
* @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 boxInventoryOpenBox(IdOnlyRequest $request)
{
$payload = $request->validated();
$payload['user_id'] = Auth::id();
$boxInventory = $this->boxInventoryService->boxInventoryOpenBox( $payload );
return self::successResponse('Success',$boxInventory);
}
/**
* @OA\Post(
*
* path="/api/box-inventory/collect",
* operationId="boxInventoryCollect",
* tags={"Box Inventory"},
* summary="boxInventoryCollect",
* security={
* {
* "open_key": {}
* },
* {
* "api_key": {}
* }
* },
* @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 boxInventoryCollect(IdOnlyRequest $request)
{
$payload = $request->validated();
$boxInventory = $this->boxInventoryService->boxInventoryCollect( $payload );
return self::successResponse('Success',$boxInventory);
}
public function boxInventoryForceCancel(IdOnlyRequest $request)
{
$payload = $request->validated();
$boxInventory = $this->boxInventoryService->boxInventoryForceCancel( $payload );
return self::successResponse('Success',$boxInventory);
}
public function boxInventoryExpiredList(BoxInventoryExpiredListRequest $request)
{
$payload = $request->validated();
$boxInventory = $this->boxInventoryService->boxInventoryExpiredList( $payload );
return self::successResponse('Success',$boxInventory);
}
public function penalizeVault(BoxInventoryExpiredListRequest $request)
{
$payload = $request->validated();
$boxInventory = $this->boxInventoryService->penalizeVault( $payload );
return self::successResponse('Success',$boxInventory);
}
public function claimPenalizeVault(IdOnlyRequest $request)
{
$payload = $request->validated();
$boxInventory = $this->boxInventoryService->claimPenalizeVault( $payload );
return self::successResponse('Success',$boxInventory);
}
/**
* @OA\Post(
*
* path="/api/box-inventory/print-label",
* operationId="boxInventoryTestPrint",
* tags={"Box Inventory"},
* summary="boxInventoryTestPrint",
* security={
* {
* "open_key": {}
* },
* {
* "api_key": {}
* }
* },
* @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 BoxInventoryPrintLabel(IdOnlyRequest $request)
{
$payload = $request->validated();
$printingLabel = $this->boxInventoryService->testPrintLabel( $payload );
return self::successResponse('Success',$printingLabel);
}
/**
* @OA\Delete(
*
* path="/api/box-inventory/cancel",
* operationId="boxInventoryCancel",
* tags={"Box Inventory"},
* summary="boxInventoryCancel",
* security={
* {
* "open_key": {}
* },
* {
* "api_key": {}
* }
* },
* @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 boxInventoryCancel(IdOnlyRequest $request)
{
$payload = $request->validated();
$payload['user_id'] = Auth::id();
$boxInventory = $this->boxInventoryService->boxInventoryCollect( $payload , $is_canceling = true);
return self::successResponse('Success',$boxInventory);
}
}