From c065c5cd6c7e8964b707c5c91d18d8dc91f93933 Mon Sep 17 00:00:00 2001 From: glovetleong Date: Sat, 5 Feb 2022 13:06:26 +0800 Subject: [PATCH] wallet --- .../ControllersLogic/CreditWalletLogic.php | 20 ++++++++++++------- .../ControllersLogic/DebitWalletLogic.php | 20 ++++++++++++------- .../ControllersLogic/TopUpWalletLogic.php | 2 ++ 3 files changed, 28 insertions(+), 14 deletions(-) diff --git a/app/Classes/Modules/Wallets/ControllersLogic/CreditWalletLogic.php b/app/Classes/Modules/Wallets/ControllersLogic/CreditWalletLogic.php index e2941c3c..8ad752c0 100644 --- a/app/Classes/Modules/Wallets/ControllersLogic/CreditWalletLogic.php +++ b/app/Classes/Modules/Wallets/ControllersLogic/CreditWalletLogic.php @@ -5,7 +5,7 @@ namespace App\Classes\Modules\Wallets\ControllersLogic; use App\Classes\General\Abstracts\AbstractControllerLogic; use App\Classes\Modules\Wallets\DataTransferObjects\WalletObject; use App\Classes\Modules\Transactions\DataTransferObjects\TransactionObject; -use App\Classes\Modules\Wallets\Services\FetchesWallet; +use App\Classes\Modules\Wallets\Services\FetchesCompany; use App\Classes\Modules\Transactions\Services\GeneratesTransactionBillNumber; use App\Classes\Modules\Transactions\Services\CreatesTransaction; use App\Classes\Modules\Wallets\Services\UpdatesWallet; @@ -33,8 +33,8 @@ class CreditWalletLogic extends AbstractControllerLogic } - /** @var FetchesWallet */ - private $fetchesWallet; + /** @var FetchesCompany */ + private $fetchesCompany; /** @var GeneratesTransactionBillNumber */ private $generatesTransactionBillNumber; @@ -47,19 +47,19 @@ class CreditWalletLogic extends AbstractControllerLogic /** * CreateWalletLogic constructor. - * @param FetchesWallet $fetchesWallet + * @param FetchesCompany $fetchesCompany * @param GeneratesTransactionBillNumber $generatesTransactionBillNumber * @param CreatesTransaction $createsTransaction * @param UpdatesWallet $updatesWallet */ public function __construct( - FetchesWallet $fetchesWallet, + FetchesCompany $fetchesCompany, GeneratesTransactionBillNumber $generatesTransactionBillNumber, CreatesTransaction $createsTransaction, UpdatesWallet $updatesWallet ) { - $this->fetchesWallet = $fetchesWallet; + $this->fetchesCompany = $fetchesCompany; $this->generatesTransactionBillNumber = $generatesTransactionBillNumber; $this->createsTransaction = $createsTransaction; $this->updatesWallet = $updatesWallet; @@ -72,7 +72,13 @@ class CreditWalletLogic extends AbstractControllerLogic */ public function logic(Request $request) : JsonResponse { - $wallet = $this->fetchesWallet->execute(['id' => $request->input('wallet_id')]); + $company = $this->fetchesCompany->execute(['id' => $request->input('company_id')]); + if (!$company->wallets()->first()) { + $object = new WalletObject($company->id, 1, $this->generatesWalletCode->execute()); + $wallet = $this->createsWallet->execute($object, $company); + } + + $wallet = $company->wallets()->first(); $billNumber = $this->generatesTransactionBillNumber->execute('DEBIT-NOTE-'); diff --git a/app/Classes/Modules/Wallets/ControllersLogic/DebitWalletLogic.php b/app/Classes/Modules/Wallets/ControllersLogic/DebitWalletLogic.php index 9437b320..9bc61684 100644 --- a/app/Classes/Modules/Wallets/ControllersLogic/DebitWalletLogic.php +++ b/app/Classes/Modules/Wallets/ControllersLogic/DebitWalletLogic.php @@ -5,7 +5,7 @@ namespace App\Classes\Modules\Wallets\ControllersLogic; use App\Classes\General\Abstracts\AbstractControllerLogic; use App\Classes\Modules\Wallets\DataTransferObjects\WalletObject; use App\Classes\Modules\Transactions\DataTransferObjects\TransactionObject; -use App\Classes\Modules\Wallets\Services\FetchesWallet; +use App\Classes\Modules\Wallets\Services\FetchesCompany; use App\Classes\Modules\Transactions\Services\GeneratesTransactionBillNumber; use App\Classes\Modules\Transactions\Services\CreatesTransaction; use App\Classes\Modules\Wallets\Services\UpdatesWallet; @@ -33,8 +33,8 @@ class DebitWalletLogic extends AbstractControllerLogic } - /** @var FetchesWallet */ - private $fetchesWallet; + /** @var FetchesCompany */ + private $fetchesCompany; /** @var GeneratesTransactionBillNumber */ private $generatesTransactionBillNumber; @@ -47,19 +47,19 @@ class DebitWalletLogic extends AbstractControllerLogic /** * CreateWalletLogic constructor. - * @param FetchesWallet $fetchesWallet + * @param FetchesCompany $fetchesCompany * @param GeneratesTransactionBillNumber $generatesTransactionBillNumber * @param CreatesTransaction $createsTransaction * @param UpdatesWallet $updatesWallet */ public function __construct( - FetchesWallet $fetchesWallet, + FetchesCompany $fetchesCompany, GeneratesTransactionBillNumber $generatesTransactionBillNumber, CreatesTransaction $createsTransaction, UpdatesWallet $updatesWallet ) { - $this->fetchesWallet = $fetchesWallet; + $this->fetchesCompany = $fetchesCompany; $this->generatesTransactionBillNumber = $generatesTransactionBillNumber; $this->createsTransaction = $createsTransaction; $this->updatesWallet = $updatesWallet; @@ -72,7 +72,13 @@ class DebitWalletLogic extends AbstractControllerLogic */ public function logic(Request $request) : JsonResponse { - $wallet = $this->fetchesWallet->execute(['id' => $request->input('wallet_id')]); + $company = $this->fetchesCompany->execute(['id' => $request->input('company_id')]); + if (!$company->wallets()->first()) { + $object = new WalletObject($company->id, 1, $this->generatesWalletCode->execute()); + $wallet = $this->createsWallet->execute($object, $company); + } + + $wallet = $company->wallets()->first(); $billNumber = $this->generatesTransactionBillNumber->execute('DEBIT-NOTE-'); diff --git a/app/Classes/Modules/Wallets/ControllersLogic/TopUpWalletLogic.php b/app/Classes/Modules/Wallets/ControllersLogic/TopUpWalletLogic.php index 0c51118a..cb7b0173 100644 --- a/app/Classes/Modules/Wallets/ControllersLogic/TopUpWalletLogic.php +++ b/app/Classes/Modules/Wallets/ControllersLogic/TopUpWalletLogic.php @@ -92,6 +92,8 @@ class TopUpWalletLogic extends AbstractControllerLogic $wallet = $this->createsWallet->execute($object, $company); } + $wallet = $company->wallets()->first(); + $user = $company->employees()->first(); $billNumber = $this->generatesTransactionBillNumber->execute('TOPUP-');