mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/exchange-2.0.git
synced 2026-08-24 15:04:19 +00:00
103 lines
5.0 KiB
PHP
103 lines
5.0 KiB
PHP
<?php
|
|
|
|
namespace App\Classes\Modules\Questionnaires\Processors;
|
|
|
|
|
|
use App\Classes\Modules\Bookings\Processors\ApprovePurchaseOrderProcessor;
|
|
use App\Classes\Modules\Bookings\Processors\UploadPurchaseOrderProcessor;
|
|
use App\Classes\Modules\Bookings\Processors\CreateBookingPaymentProcessor;
|
|
use App\Classes\Modules\Transactions\Processors\CreatePaymentProofDocumentProcessor;
|
|
use App\Classes\Modules\Transactions\Services\FetchesTransaction;
|
|
use App\Classes\Modules\Bookings\Services\FetchesBookingQuotation;
|
|
use App\Classes\Modules\Currencies\DataTransferObjects\CurrencyConversionObject;
|
|
use App\Classes\ValueObjects\Constants\PaymentMethodType;
|
|
use App\Models\QAAnswerOptions;
|
|
|
|
class SaveAnswerActionV1AdminWFProcessor
|
|
{
|
|
/** @var ApprovePurchaseOrderProcessor */
|
|
private $approvePurchaseOrderProcessor;
|
|
|
|
/** @var UploadPurchaseOrderProcessor */
|
|
private $uploadPurchaseOrderProcessor;
|
|
|
|
/** @var CreatePaymentProofDocumentProcessor */
|
|
private $createPaymentProofDocumentProcessor;
|
|
|
|
/** @var FetchesTransaction */
|
|
private $fetchesTransaction;
|
|
|
|
/** @var FetchesBookingQuotation */
|
|
private $fetchBookingQuotation;
|
|
|
|
/** @var CreateBookingPaymentProcessor */
|
|
private $createBookingPaymentProcessor;
|
|
|
|
/**
|
|
* SaveAnswerActionV1AdminWFProcessor constructor.
|
|
* @param ApprovePurchaseOrderProcessor $approvePurchaseOrderProcessor
|
|
* @param UploadPurchaseOrderProcessor $uploadPurchaseOrderProcessor
|
|
* @param CreatePaymentProofDocumentProcessor $createPaymentProofDocumentProcessor
|
|
* @param FetchesTransaction $fetchesTransaction
|
|
* @param FetchesBookingQuotation $fetchBookingQuotation
|
|
* @param CreateBookingPaymentProcessor $createBookingPaymentProcessor
|
|
*/
|
|
public function __construct(ApprovePurchaseOrderProcessor $approvePurchaseOrderProcessor, UploadPurchaseOrderProcessor $uploadPurchaseOrderProcessor, CreatePaymentProofDocumentProcessor $createPaymentProofDocumentProcessor, FetchesTransaction $fetchesTransaction, FetchesBookingQuotation $fetchBookingQuotation, CreateBookingPaymentProcessor $createBookingPaymentProcessor)
|
|
{
|
|
$this->approvePurchaseOrderProcessor = $approvePurchaseOrderProcessor;
|
|
$this->uploadPurchaseOrderProcessor = $uploadPurchaseOrderProcessor;
|
|
$this->createPaymentProofDocumentProcessor = $createPaymentProofDocumentProcessor;
|
|
$this->fetchesTransaction = $fetchesTransaction;
|
|
$this->fetchBookingQuotation = $fetchBookingQuotation;
|
|
$this->createBookingPaymentProcessor = $createBookingPaymentProcessor;
|
|
}
|
|
|
|
/**
|
|
* @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')
|
|
{
|
|
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();
|
|
$processed = $questionMetadata['amount_processed'];
|
|
$amount = $questionMetadata['amount'];
|
|
if ($processed < $amount) {
|
|
$differenceUnder = $amount - $processed;
|
|
$conversionObject = new CurrencyConversionObject(floatval(str_replace(',', '', $differenceUnder)), $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);
|
|
$underpay = $configurations->getTotal();
|
|
|
|
if($wallet->amount > $underpay){
|
|
$company = $booking->company()->first();
|
|
$employee = $company->employees()->first();
|
|
$transaction = $this->createBookingPaymentProcessor->execute($booking, (string) $differenceUnder, 'wallet', "", "", $employee->email);
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|