From 7eec7f5b2df6e6b88b427b8b1997369e886c8ec6 Mon Sep 17 00:00:00 2001 From: omair saleh Date: Fri, 11 Mar 2022 10:53:59 +0800 Subject: [PATCH] update xpo --- .../AutoPurchaseOrderFillLogic.php | 72 ++++++++++--------- 1 file changed, 38 insertions(+), 34 deletions(-) diff --git a/app/Classes/Modules/Bookings/ControllersLogic/AutoPurchaseOrderFillLogic.php b/app/Classes/Modules/Bookings/ControllersLogic/AutoPurchaseOrderFillLogic.php index c126fe6d..44aceebc 100644 --- a/app/Classes/Modules/Bookings/ControllersLogic/AutoPurchaseOrderFillLogic.php +++ b/app/Classes/Modules/Bookings/ControllersLogic/AutoPurchaseOrderFillLogic.php @@ -64,52 +64,56 @@ class AutoPurchaseOrderFillLogic extends AbstractControllerLogic */ public function logic(Request $request) : JsonResponse { - $bookings = Booking::whereMonth('created_at', 9) - ->whereYear('created_at', 2021) - ->whereDoesntHave('transactions', function($q){ - $q->where('type', TransactionType::PURCHASE_ORDER); - $q->whereIn('status', [ApprovalStatus::PENDING_VERIFICATION, ApprovalStatus::APPROVED]); - })->get(); + try { + $bookings = Booking::whereMonth('created_at', 9) + ->whereYear('created_at', 2021) + ->whereDoesntHave('transactions', function($q){ + $q->where('type', TransactionType::PURCHASE_ORDER); + $q->whereIn('status', [ApprovalStatus::PENDING_VERIFICATION, ApprovalStatus::APPROVED]); + })->get(); - foreach ($bookings as $booking) { - $po = Transaction::where('type', TransactionType::PURCHASE_ORDER) - ->where('status', ApprovalStatus::APPROVED)->where('issuer', $booking->company_id) - ->select('*', DB::raw('abs(amount - ' . $booking->fix_amount . ') as nearest_price'))->orderBy('nearest_price')->first(); - - - if (!$po) { + foreach ($bookings as $booking) { $po = Transaction::where('type', TransactionType::PURCHASE_ORDER) - ->where('status', ApprovalStatus::APPROVED)->select('*', DB::raw('abs(amount - ' . $booking->fix_amount . ') as nearest_price'))->orderBy('nearest_price')->first(); - } + ->where('status', ApprovalStatus::APPROVED)->where('issuer', $booking->company_id) + ->select('*', DB::raw('abs(amount - ' . $booking->fix_amount . ') as nearest_price'))->orderBy('nearest_price')->first(); - $products = $this->generatesPurchaseOrderProducts->execute($po, $booking->fix_amount); - $deference = $booking->fix_amount - $products->sum('total'); + if (!$po) { + $po = Transaction::where('type', TransactionType::PURCHASE_ORDER) + ->where('status', ApprovalStatus::APPROVED)->select('*', DB::raw('abs(amount - ' . $booking->fix_amount . ') as nearest_price'))->orderBy('nearest_price')->first(); + } - if($deference > -150 && $deference < 150 && $deference != 0) { + $products = $this->generatesPurchaseOrderProducts->execute($po, $booking->fix_amount); - $products->push([ - 'description' => $deference < 0 ? 'Discount':'Shipping Fee', - 'quantity' => 1, - 'stockCode' => '', - 'total' => $deference, - 'unit_price' => $deference - ]); - } + $deference = $booking->fix_amount - $products->sum('total'); - $billNumber = $this->generatesTransactionBillNumber->execute('XPO-'); + if($deference > -150 && $deference < 150 && $deference != 0) { - $total = $products->sum('total'); + $products->push([ + 'description' => $deference < 0 ? 'Discount':'Shipping Fee', + 'quantity' => 1, + 'stockCode' => '', + 'total' => $deference, + 'unit_price' => $deference + ]); + } - $object = new TransactionObject($billNumber, TransactionType::PURCHASE_ORDER, $booking->company->id, 1, - 1, PaymentMethodType::CASH, - $total, $total, $booking->fix_currency_id, $booking->fix_currency_id, - 1, 0, 0, null, ApprovalStatus::PENDING_SUBMISSION, $products->toArray()); + $billNumber = $this->generatesTransactionBillNumber->execute('XPO-'); + + $total = $products->sum('total'); + + $object = new TransactionObject($billNumber, TransactionType::PURCHASE_ORDER, $booking->company->id, 1, + 1, PaymentMethodType::CASH, + $total, $total, $booking->fix_currency_id, $booking->fix_currency_id, + 1, 0, 0, null, ApprovalStatus::PENDING_SUBMISSION, $products->toArray()); - dump($object); // $this->createPurchaseOrderTransactionProcessor->execute($booking, $object); + } + + return $this->response([]); + } catch (\Exception $exception){ + dd($exception); } - return $this->response([]); } } \ No newline at end of file