diff --git a/app/Classes/Modules/Transactions/ControllersLogic/ImportPurchaseOrderTransactionLogic.php b/app/Classes/Modules/Transactions/ControllersLogic/ImportPurchaseOrderTransactionLogic.php new file mode 100644 index 00000000..3617bcfe --- /dev/null +++ b/app/Classes/Modules/Transactions/ControllersLogic/ImportPurchaseOrderTransactionLogic.php @@ -0,0 +1,111 @@ + 'Update Purchase Order', + 'message' => 'You have successfully updated you booking\'s purchase order' + ]; + } + + /** @var FetchesBooking */ + private $fetchesBooking; + + /** @var GeneratesTransactionBillNumber */ + private $generatesTransactionBillNumber; + + /** @var CreatePurchaseOrderTransactionProcessor */ + private $createPurchaseOrderTransactionProcessor; + + /** + * CreatePurchaseOrderTransactionLogic constructor. + * @param FetchesBooking $fetchesBooking + * @param GeneratesTransactionBillNumber $generatesTransactionBillNumber + * @param CreatePurchaseOrderTransactionProcessor $createPurchaseOrderTransactionProcessor + */ + public function __construct(FetchesBooking $fetchesBooking, GeneratesTransactionBillNumber $generatesTransactionBillNumber, CreatePurchaseOrderTransactionProcessor $createPurchaseOrderTransactionProcessor) + { + $this->fetchesBooking = $fetchesBooking; + $this->generatesTransactionBillNumber = $generatesTransactionBillNumber; + $this->createPurchaseOrderTransactionProcessor = $createPurchaseOrderTransactionProcessor; + } + + /** + * @param Request $request + * @param string $id + * @return JsonResponse + * @throws \App\Classes\Exceptions\MalformedRequestException + */ + public function logic(Request $request, $id = '') : JsonResponse + { + $files = $request->file('files'); + + $object = new DocumentObject('', $request->input('files'), '', ApprovalStatus::APPROVED, 'imports'); + foreach ($object->getFiles() as $file){ + $collection = Excel::toCollection(null, json_decode($file)->file_info->original->file, null, null, true); + + $sheet = $collection->first()->skip(1); + + $products = $sheet->map(function ($row) { + Log::info($row); + $stockCode = $row[0]; + $description = $row[1]; + $quantity = $row[2]; + $unit_price = $row[3]; + + return [ + 'stockCode' => $stockCode, + 'description' => $description, + 'quantity' => $quantity, + 'unit_price' => $unit_price + ]; + })->all(); + } + + // dd($products); + + /** @var Booking $booking */ + $booking = $this->fetchesBooking->execute(['id' => $request->route('id') ?? $id]); + + $billNumber = $this->generatesTransactionBillNumber->execute('PO-'); + + $total = collect($products)->sum(function($product){ + return $product['quantity'] * floatval(str_replace(',', '', $product['unit_price'])); + }); + + $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); + + + $transaction = $this->createPurchaseOrderTransactionProcessor->execute($booking, $object); + + return $this->resourceResponse(new TransactionResource($transaction)); + + } +} diff --git a/app/Http/Controllers/Transactions/ImportPurchaseOrderTransactionController.php b/app/Http/Controllers/Transactions/ImportPurchaseOrderTransactionController.php new file mode 100644 index 00000000..78caf5a4 --- /dev/null +++ b/app/Http/Controllers/Transactions/ImportPurchaseOrderTransactionController.php @@ -0,0 +1,21 @@ +execute($request); + } +} diff --git a/resources/assets/vue/components/bookings/forms/PurchaseOrderFormComponent.vue b/resources/assets/vue/components/bookings/forms/PurchaseOrderFormComponent.vue index 7b7ec3d4..1ea2ecf8 100644 --- a/resources/assets/vue/components/bookings/forms/PurchaseOrderFormComponent.vue +++ b/resources/assets/vue/components/bookings/forms/PurchaseOrderFormComponent.vue @@ -81,6 +81,24 @@ +