approvePurchaseOrderProcessor = $approvePurchaseOrderProcessor; $this->uploadPurchaseOrderProcessor = $uploadPurchaseOrderProcessor; $this->createPaymentProofDocumentProcessor = $createPaymentProofDocumentProcessor; $this->fetchesTransaction = $fetchesTransaction; $this->fetchBookingQuotation = $fetchBookingQuotation; $this->createBookingPaymentProcessor = $createBookingPaymentProcessor; $this->updateBookingAmountProcessor = $updateBookingAmountProcessor; $this->createsKeyValuePair = $createsKeyValuePair; } /** * @return */ public function execute($booking, $questionMetadata, $answerOptionId, $currentQuestion, $filesUpload){ $answerOption = QAAnswerOptions::where('id', $answerOptionId)->first(); if($currentQuestion['question_number'] === 'approve_po' && $answerOption && $answerOption->value === "approve_po_approved"){ $this->approvePurchaseOrderProcessor->execute($booking); } else if($currentQuestion['question_number'] === '1688_submit' || $currentQuestion['question_number'] === '1688_underpaid_documents_submission' || $currentQuestion['question_number'] === '1688_overpaid_documents_submission') { if($filesUpload){ if ($booking && isset($filesUpload['filesA']) && isset($filesUpload['filesB'])) { $mergedFilesUpload = array_merge( $filesUpload['filesA'] ?? [], $filesUpload['filesB'] ?? [] ); $this->uploadPurchaseOrderProcessor->execute($booking, $mergedFilesUpload); } if (isset($filesUpload['filesC']) && isset($questionMetadata['payment_history'][0]['transaction_bill']['id'])) { $transaction = $this->fetchesTransaction->execute(['id' =>$questionMetadata['payment_history'][0]['transaction_bill']['id']]); $this->createPaymentProofDocumentProcessor->execute($transaction, $filesUpload['filesC']); } } } else if($currentQuestion['question_number'] === '1688_underpaid_order_1') { $wallet = $booking->company->wallets()->first(); $amountProcessed = $questionMetadata['amount_processed']; $amountPaid = $questionMetadata['paid_amount']; if ($amountProcessed > $amountPaid) { $differenceUnderInCNY = $amountProcessed - $amountPaid; $conversionObject = new CurrencyConversionObject(floatval(str_replace(',', '', $differenceUnderInCNY)), $booking->convertible_currency_id, $booking->service_id, $booking->fix_currency_id === 1 ? 0:1, PaymentMethodType::PAYMENT_METHODS['wallet']); $configurations = $this->fetchBookingQuotation->execute($booking->company, $conversionObject); $amountUnderpay = $configurations->getTotal(); if($amountUnderpay != $differenceUnderInCNY){ $this->markBookingOriginalAmount($booking); $this->updateBookingAmountProcessor->execute($booking, $amountProcessed); } if($wallet->amount > $amountUnderpay){ $company = $booking->company()->first(); $employee = $company->employees()->first(); $transaction = $this->createBookingPaymentProcessor->execute($booking, (string) $differenceUnderInCNY, 'wallet', "", "", $employee->email, false); } } } } private function markBookingOriginalAmount(Booking $booking){ $key1 = "original_booking_amount_cny"; $kvp = $booking->attributesKVP()->where('key', $key1)->first(); if(!$kvp){ $keyValuePairObject = new KeyValuePairObject($key1, $booking->fix_amount); $this->createsKeyValuePair->execute($booking, $keyValuePairObject); } } }