automatically complete tasks

This commit is contained in:
Omair Saleh
2023-06-15 04:23:15 +08:00
parent f7796fe957
commit 2e9e7f9cc0
@@ -10,16 +10,16 @@ use App\Classes\Modules\Bookings\Services\CalculatesBookingOutstanding;
use App\Classes\Modules\Bookings\Services\FetchesBookingQuotation;
use App\Classes\Modules\Companies\Services\FetchesCompanyPaymentAttemptLimit;
use App\Classes\Modules\Currencies\DataTransferObjects\CurrencyConversionObject;
use App\Classes\Modules\Vouchers\DataTransferObjects\VoucherObject;
//use App\Classes\Modules\Vouchers\DataTransferObjects\VoucherObject;
use App\Classes\Modules\Transactions\DataTransferObjects\TransactionObject;
use App\Classes\Modules\Transactions\Services\CreatesTransaction;
use App\Classes\Modules\Transactions\Services\GeneratesTransactionBillNumber;
use App\Classes\Modules\Billplzs\Services\CreatesBillplzBill;
use App\Classes\Modules\Transactions\Services\UpdatesTransactionStatus;
use App\Classes\Modules\Vouchers\Services\FetchesVoucher;
use App\Classes\Modules\Vouchers\Services\CreatesVoucher;
use App\Classes\Modules\Vouchers\Services\CreatesVoucherRedemption;
use App\Classes\Modules\Vouchers\Services\RedeemsVoucher;
//use App\Classes\Modules\Vouchers\Services\FetchesVoucher;
//use App\Classes\Modules\Vouchers\Services\CreatesVoucher;
//use App\Classes\Modules\Vouchers\Services\CreatesVoucherRedemption;
//use App\Classes\Modules\Vouchers\Services\RedeemsVoucher;
use App\Classes\Modules\Wallets\Services\UpdatesWalletBalance;
use App\Classes\ValueObjects\Constants\ApprovalStatus;
use App\Classes\ValueObjects\Constants\PaymentMethodType;
@@ -35,6 +35,29 @@ use App\Classes\Modules\Wallets\Services\RecalculatesWalletBalance;
class CreateBookingPaymentLogic extends AbstractControllerLogic
{
/**
* @param FetchesBookingQuotation $fetchBookingQuotation
* @param FetchesCompanyPaymentAttemptLimit $fetchesCompanyPaymentAttemptLimit
* @param GeneratesTransactionBillNumber $generatesTransactionBillNumber
* @param CreatesTransaction $createsTransaction
* @param CalculatesBookingOutstanding $calculatesBookingOutstanding
* @param CreatesBillplzBill $createsBillplzBill
* @param UpdatesWalletBalance $updatesWalletBalance
* @param UpdatesTransactionStatus $updatesTransactionStatus
* @param RecalculatesWalletBalance $recalculatesWalletBalance
*/
public function __construct(FetchesBookingQuotation $fetchBookingQuotation, FetchesCompanyPaymentAttemptLimit $fetchesCompanyPaymentAttemptLimit, GeneratesTransactionBillNumber $generatesTransactionBillNumber, CreatesTransaction $createsTransaction, CalculatesBookingOutstanding $calculatesBookingOutstanding, CreatesBillplzBill $createsBillplzBill, UpdatesWalletBalance $updatesWalletBalance, UpdatesTransactionStatus $updatesTransactionStatus, RecalculatesWalletBalance $recalculatesWalletBalance)
{
$this->fetchBookingQuotation = $fetchBookingQuotation;
$this->fetchesCompanyPaymentAttemptLimit = $fetchesCompanyPaymentAttemptLimit;
$this->generatesTransactionBillNumber = $generatesTransactionBillNumber;
$this->createsTransaction = $createsTransaction;
$this->calculatesBookingOutstanding = $calculatesBookingOutstanding;
$this->createsBillplzBill = $createsBillplzBill;
$this->updatesWalletBalance = $updatesWalletBalance;
$this->updatesTransactionStatus = $updatesTransactionStatus;
$this->recalculatesWalletBalance = $recalculatesWalletBalance;
}
/**
@@ -74,51 +97,20 @@ class CreateBookingPaymentLogic extends AbstractControllerLogic
/** @var RecalculatesWalletBalance */
private $recalculatesWalletBalance;
/** @var FetchesVoucher */
private $fetchesVoucher;
/** @var CreatesVoucher */
private $createsVoucher;
/** @var CreatesVoucherRedemption */
private $createsVoucherRedemption;
/** @var RedeemsVoucher */
private $redeemsVoucher;
//
// /** @var FetchesVoucher */
// private $fetchesVoucher;
//
// /** @var CreatesVoucher */
// private $createsVoucher;
//
// /** @var CreatesVoucherRedemption */
// private $createsVoucherRedemption;
//
// /** @var RedeemsVoucher */
// private $redeemsVoucher;
/**
* @param FetchesBookingQuotation $fetchBookingQuotation
* @param FetchesCompanyPaymentAttemptLimit $fetchesCompanyPaymentAttemptLimit
* @param GeneratesTransactionBillNumber $generatesTransactionBillNumber
* @param CreatesTransaction $createsTransaction
* @param CalculatesBookingOutstanding $calculatesBookingOutstanding
* @param CreatesBillplzBill $createsBillplzBill
* @param UpdatesWalletBalance $updatesWalletBalance
* @param UpdatesTransactionStatus $updatesTransactionStatus
* @param RecalculatesWalletBalance $recalculatesWalletBalance
* @param FetchesVoucher $fetchesVoucher
* @param CreatesVoucher $createsVoucher
* @param CreatesVoucherRedemption $createsVoucherRedemption
* @param RedeemsVoucher $redeemsVoucher
*/
public function __construct(FetchesBookingQuotation $fetchBookingQuotation, FetchesCompanyPaymentAttemptLimit $fetchesCompanyPaymentAttemptLimit, GeneratesTransactionBillNumber $generatesTransactionBillNumber, CreatesTransaction $createsTransaction, CalculatesBookingOutstanding $calculatesBookingOutstanding, CreatesBillplzBill $createsBillplzBill, UpdatesWalletBalance $updatesWalletBalance, UpdatesTransactionStatus $updatesTransactionStatus, RecalculatesWalletBalance $recalculatesWalletBalance, FetchesVoucher $fetchesVoucher, CreatesVoucher $createsVoucher, CreatesVoucherRedemption $createsVoucherRedemption, RedeemsVoucher $redeemsVoucher)
{
$this->fetchBookingQuotation = $fetchBookingQuotation;
$this->fetchesCompanyPaymentAttemptLimit = $fetchesCompanyPaymentAttemptLimit;
$this->generatesTransactionBillNumber = $generatesTransactionBillNumber;
$this->createsTransaction = $createsTransaction;
$this->calculatesBookingOutstanding = $calculatesBookingOutstanding;
$this->createsBillplzBill = $createsBillplzBill;
$this->updatesWalletBalance = $updatesWalletBalance;
$this->updatesTransactionStatus = $updatesTransactionStatus;
$this->recalculatesWalletBalance = $recalculatesWalletBalance;
$this->fetchesVoucher = $fetchesVoucher;
$this->createsVoucher = $createsVoucher;
$this->createsVoucherRedemption = $createsVoucherRedemption;
$this->redeemsVoucher = $redeemsVoucher;
}
public function logic(Request $request) : JsonResponse
{
@@ -234,25 +226,25 @@ class CreateBookingPaymentLogic extends AbstractControllerLogic
);
}
private function handleVoucherCode(Request $request, Booking $booking, CalculationObject $configurations, Transaction $transaction): void
{
$voucherCode = $request->input('voucher_code');
if($voucherCode){
$employee = $booking->company->employees()->first();
$result = $this->redeemsVoucher->execute($voucherCode, $configurations->getSubTotal(), $employee);
$voucher = $result->voucher;
$redemptionId = $result->id;
$voucherValue = $voucher->discount->amount_off ?? ($voucher->discount->percent_off ?? 0.00);
$voucherObject = new VoucherObject($voucher->code, $voucher->metadata->name ?? "", $voucher->discount->type, $voucherValue);
$voucher = $this->createsVoucher->execute($voucherObject);
if(!$voucher)
$voucher = $this->fetchesVoucher->execute(['code' => $voucherObject->getCode()]);
$this->createsVoucherRedemption->execute($redemptionId, $voucher->id, $employee->id, $configurations->getVoucherDiscountAmount());
}
}
// private function handleVoucherCode(Request $request, Booking $booking, CalculationObject $configurations, Transaction $transaction): void
// {
// $voucherCode = $request->input('voucher_code');
// if($voucherCode){
// $employee = $booking->company->employees()->first();
//
// $result = $this->redeemsVoucher->execute($voucherCode, $configurations->getSubTotal(), $employee);
// $voucher = $result->voucher;
// $redemptionId = $result->id;
//
// $voucherValue = $voucher->discount->amount_off ?? ($voucher->discount->percent_off ?? 0.00);
// $voucherObject = new VoucherObject($voucher->code, $voucher->metadata->name ?? "", $voucher->discount->type, $voucherValue);
// $voucher = $this->createsVoucher->execute($voucherObject);
//
// if(!$voucher)
// $voucher = $this->fetchesVoucher->execute(['code' => $voucherObject->getCode()]);
//
// $this->createsVoucherRedemption->execute($redemptionId, $voucher->id, $employee->id, $configurations->getVoucherDiscountAmount());
// }
// }
}