mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/exchange-2.0.git
synced 2026-08-31 10:24:00 +00:00
dmin Workflow - Fix Reported Issues - Automatically deduct funds from customer wallet when customer underpaid
This commit is contained in:
+36
-3
@@ -5,10 +5,13 @@ 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;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class SaveAnswerActionV1AdminWFProcessor
|
||||
{
|
||||
@@ -24,19 +27,29 @@ class SaveAnswerActionV1AdminWFProcessor
|
||||
/** @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)
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -45,7 +58,7 @@ class SaveAnswerActionV1AdminWFProcessor
|
||||
public function execute($booking, $questionMetadata, $answerOptionId, $currentQuestion, $filesUpload){
|
||||
$isNoGoingBack = 0;
|
||||
$answerOption = QAAnswerOptions::where('id', $answerOptionId)->first();
|
||||
if($answerOption && $answerOption->value === "approve_po_approved"){
|
||||
if($currentQuestion['question_number'] === 'approve_po' && $answerOption && $answerOption->value === "approve_po_approved"){
|
||||
$this->approvePurchaseOrderProcessor->execute($questionMetadata['id']);
|
||||
$isNoGoingBack = 1;
|
||||
}
|
||||
@@ -69,6 +82,26 @@ class SaveAnswerActionV1AdminWFProcessor
|
||||
$isNoGoingBack = 1;
|
||||
}
|
||||
}
|
||||
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);
|
||||
$isNoGoingBack = 1;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return $isNoGoingBack;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user