diff --git a/app/Classes/Modules/Billplzs/ControllersLogic/CallbackBillplzLogic.php b/app/Classes/Modules/Billplzs/ControllersLogic/CallbackBillplzLogic.php index 85c9fe77..ae8ae28f 100644 --- a/app/Classes/Modules/Billplzs/ControllersLogic/CallbackBillplzLogic.php +++ b/app/Classes/Modules/Billplzs/ControllersLogic/CallbackBillplzLogic.php @@ -115,9 +115,8 @@ class CallbackBillplzLogic } } + $company_module_marking = $transaction->owner->owner->connections->first()->invitee_reference; - - - return $request->method() === 'POST' ? true : view('pages.payments_redirect', ['marking' => $order->reference, 'transaction' => $transaction, 'status' => $status]); + return $request->method() === 'POST' ? true : view('pages.payments_redirect', ['marking' => $order->reference ?? null, 'company_module_marking' => $company_module_marking ?? null, 'transaction' => $transaction, 'status' => $status]); } } diff --git a/app/Classes/Modules/Transactions/ControllersLogic/RegenerateShippingInvoiceTransactionLogic.php b/app/Classes/Modules/Transactions/ControllersLogic/RegenerateShippingInvoiceTransactionLogic.php new file mode 100644 index 00000000..8922e651 --- /dev/null +++ b/app/Classes/Modules/Transactions/ControllersLogic/RegenerateShippingInvoiceTransactionLogic.php @@ -0,0 +1,78 @@ + 'Regenerate Shipping Invoice', + 'message' => 'You have successfully regenerated shipping invoice' + ]; + } + + /** @var CreatesDocument */ + private $createsDocument; + + /** @var CreatesFiles */ + private $createsFiles; + + /** + * @param CreatesDocument $createsDocument + */ + public function __construct(CreatesDocument $createsDocument, CreatesFiles $createsFiles) + { + $this->createsDocument = $createsDocument; + $this->createsFiles = $createsFiles; + } + + public function logic(Request $request) : JsonResponse + { + + $orders = Order::where('company_module_id', $request->route('company_module_id'))->get(); + + foreach ($orders as $order){ + $invoices = $order->transactions()->where('transactions.type', TransactionType::SHIPPING_INVOICE)->get(); + foreach ($invoices as $invoice){ + + $invoice->documents()->delete(); + + $transaction_invoice_pdf = LaravelMpdf::loadView('pages.pdfs.shipping_invoice', ['invoice_transaction' => $invoice]); + + $document_object = new DocumentObject( + DocumentType::SHIPPING_INVOICE, + [chunk_split('data:application/pdf;base64,'.base64_encode($transaction_invoice_pdf->output()))], + '', + ApprovalStatus::COMPLETED, + 'shipping_invoice' + ); + + $document =$this->createsDocument->execute($invoice, $document_object); + + $this->createsFiles->execute($document, $document_object); + + // dump($document); + } + } + + return $this->response([]); + } + +} diff --git a/app/Classes/Modules/Transactions/Processors/UpdateWalletTransactionProcessor.php b/app/Classes/Modules/Transactions/Processors/UpdateWalletTransactionProcessor.php new file mode 100644 index 00000000..a016db80 --- /dev/null +++ b/app/Classes/Modules/Transactions/Processors/UpdateWalletTransactionProcessor.php @@ -0,0 +1,71 @@ +fetchesTransaction = $fetchesTransaction; + $this->updatesTransactionStatus = $updatesTransactionStatus; + $this->updatesWallet = $updatesWallet; + } + + + /** + * @param Booking $booking + * @return void + * @throws \App\Classes\Exceptions\MalformedRequestException + */ + public function execute(int $transactionId, int $transactionStatus) + { + + $transaction = $this->fetchesTransaction->execute(['id' => $transactionId]); + $wallet = $transaction->wallet; + + switch($transaction->type){ + case TransactionType::TOP_UP: + $updateWalletAmount = $transaction->amount + $wallet->amount; + break; + case TransactionType::WITHDRAW: + $updateWalletAmount = $wallet->amount - $transaction->amount; + break; + default: + break; + } + + $walletOject = new WalletObject( $wallet->company->id, $wallet->currency_id, $wallet->code, $updateWalletAmount); + + $this->updatesTransactionStatus->execute($transaction, $transactionStatus); + + $this->updatesWallet->execute($wallet, $walletOject); + + return $wallet; + } +} diff --git a/app/Classes/Modules/Transactions/Services/CreatesTransactionableTransaction.php b/app/Classes/Modules/Transactions/Services/CreatesTransactionableTransaction.php new file mode 100644 index 00000000..373343d6 --- /dev/null +++ b/app/Classes/Modules/Transactions/Services/CreatesTransactionableTransaction.php @@ -0,0 +1,40 @@ +bill_no = $object->getBillNo(); + $model->type = $object->getTransactionType(); + $model->issuer = $object->getIssuer(); + $model->receiver = $object->getReceiver(); + $model->recipient_bank_account_id = $object->getRecipientBankAccountId(); + $model->payment_method = $object->getPaymentMethod(); + $model->amount = $object->getAmount(); + $model->original_amount = $object->getOriginalAmount(); + $model->currency_id = $object->getCurrencyId(); + $model->original_currency_id = $object->getOriginalCurrencyId(); + $model->currency_rate = $object->getCurrencyRate(); + $model->tax = $object->getTax(); + $model->service_charge = $object->getServiceCharge(); + $model->expires_on = $object->getExpiresOn(); + $model->status = $object->getStatus(); + $model->payment_reference = $object->getPaymentReference(); + + return $this->handler($transactionable->transactions(), $model); + + } +} \ No newline at end of file diff --git a/app/Classes/Modules/Wallets/ControllersLogic/CreateWalletLogic.php b/app/Classes/Modules/Wallets/ControllersLogic/CreateWalletLogic.php new file mode 100644 index 00000000..b49cb46c --- /dev/null +++ b/app/Classes/Modules/Wallets/ControllersLogic/CreateWalletLogic.php @@ -0,0 +1,73 @@ + 'Created Company Wallet', + 'message' => 'You have successfully created a company wallet' + ]; + } + + /** @var CreatesWallet */ + private $createsWallet; + + /** @var GeneratesWalletCode */ + private $generatesWalletCode; + + /** @var CanCreateCompanyWallet */ + private $canCreateCompanyWallet; + + /** @var FetchesCompanyModule */ + private $fetchesCompanyModule; + + /** + * CreateWalletLogic constructor. + * @param CreatesWallet $createsWallet + * @param GeneratesWalletCode $generatesWalletCode + * @param CanCreateCompanyWallet $canCreateCompanyWallet + */ + public function __construct(CreatesWallet $createsWallet, GeneratesWalletCode $generatesWalletCode, CanCreateCompanyWallet $canCreateCompanyWallet, FetchesCompanyModule $fetchesCompanyModule) + { + $this->fetchesCompanyModule = $fetchesCompanyModule; + $this->createsWallet = $createsWallet; + $this->generatesWalletCode = $generatesWalletCode; + $this->canCreateCompanyWallet = $canCreateCompanyWallet; + } + + /** + * @param Request $request + * @return JsonResponse + * @throws ErrorException + */ + public function logic(Request $request) : JsonResponse + { + $object = new WalletObject($request->input('company_module_id'), $request->input('currency_id'), $this->generatesWalletCode->execute()); + + $this->canCreateCompanyWallet->passes($object); + + $company_module = $this->fetchesCompanyModule->execute(['id' => $request->input('company_id')]); + + $wallet = $this->createsWallet->execute($object, $company_module); + + return $this->resourceResponse(new WalletResource($wallet)); + } +} diff --git a/app/Classes/Modules/Wallets/ControllersLogic/CreateWalletTransactionLogic.php b/app/Classes/Modules/Wallets/ControllersLogic/CreateWalletTransactionLogic.php new file mode 100644 index 00000000..6fe72a52 --- /dev/null +++ b/app/Classes/Modules/Wallets/ControllersLogic/CreateWalletTransactionLogic.php @@ -0,0 +1,132 @@ + 'Created Wallet Transaction', + 'message' => 'You have successfully created a wallet transaction' + ]; + } + + /** @var CreatesWalletTransaction */ + private $createsWalletTransaction; + + /** @var GeneratesWalletTransactionBillNo */ + private $generatesWalletTransactionBillNo; + + /** @var CanCreateWalletTransaction */ + private $canCreateWalletTransaction; + + private $fetchesCurrency; + + private $rateCalculatesCurrency; + + private $fetchesWallet; + + /** + * CreateWalletLogic constructor. + * @param CreatesWalletTransaction $createsWalletTransaction + * @param GeneratesWalletTransactionBillNo $generatesWalletTransactionBillNo + * @param CanCreateWalletTransaction $canCreateWalletTransaction + * @param FetchesCurrency $fetchesCurrency + * @param RateCalculatesCurrency $rateCalculatesCurrency + * @param FetchesWallet $fetchesWallet + */ + public function __construct( + CreatesWalletTransaction $createsWalletTransaction, GeneratesWalletTransactionBillNo $generatesWalletTransactionBillNo, CanCreateWalletTransaction $canCreateWalletTransaction, + FetchesCurrency $fetchesCurrency,RateCalculatesCurrency $rateCalculatesCurrency, FetchesWallet $fetchesWallet + ) + { + $this->createsWalletTransaction = $createsWalletTransaction; + $this->generatesWalletTransactionBillNo = $generatesWalletTransactionBillNo; + $this->canCreateWalletTransaction = $canCreateWalletTransaction; + $this->fetchesCurrency = $fetchesCurrency; + $this->rateCalculatesCurrency = $rateCalculatesCurrency; + $this->fetchesWallet = $fetchesWallet; + } + + /** + * @param Request $request + * @return JsonResponse + * @throws ErrorException + */ + public function logic(Request $request) : JsonResponse + { + try { + + DB::beginTransaction(); + + $wallet = $this->fetchesWallet->execute(['id' => $request->route('id')]); + $conversion_currency = $this->fetchesCurrency->execute(['id' => $request->input('currency_id')]); + $convertable_currency = $this->fetchesCurrency->execute(['id' => $wallet->currency_id]);//MYR + + $convert_amount = $this->rateCalculatesCurrency->execute($conversion_currency, $convertable_currency, $request->input('amount')); + $convert_rate = $this->rateCalculatesCurrency->execute_rate($conversion_currency, $convertable_currency); + + + $object = new WalletTransactionObject( + $wallet->id, $this->generatesWalletTransactionBillNo->execute(),$request->input('trans_type'), + number_format( (float) $convert_amount, 5, '.', ''), $wallet->currency_id , number_format( (float) $request->input('amount'), 5, '.', ''), + $request->input('currency_id'),number_format( (float) $convert_rate, 5, '.', '') + ); + + $this->canCreateWalletTransaction->passes($object); + + $wallet_transaction = $this->createsWalletTransaction->execute($object); + + DB::commit(); + + return $this->resourceResponse(new WalletTransactionResource($wallet_transaction)); + + } catch (\Exception $exception) { + throw new ErrorException($exception->getMessage(), $exception->getCode()); + } + + } +} \ No newline at end of file diff --git a/app/Classes/Modules/Wallets/ControllersLogic/CreditWalletLogic.php b/app/Classes/Modules/Wallets/ControllersLogic/CreditWalletLogic.php new file mode 100644 index 00000000..8ed8aa08 --- /dev/null +++ b/app/Classes/Modules/Wallets/ControllersLogic/CreditWalletLogic.php @@ -0,0 +1,101 @@ + 'Credit into Company Wallet', + 'message' => 'You have successfully credit company wallet' + ]; + } + + + /** @var FetchesCompany */ + private $fetchesCompany; + + /** @var GeneratesWalletCode */ + private $generatesWalletCode; + + /** @var CreatesWallet */ + private $createsWallet; + + /** @var GeneratesTransactionBillNumber */ + private $generatesTransactionBillNumber; + + /** @var CreatesTransaction */ + private $createsTransaction; + + /** @var UpdatesWallet */ + private $updatesWallet; + + /** @var CreditWalletProcessor */ + private $creditWalletProcessor; + + /** + * CreateWalletLogic constructor. + * @param FetchesCompany $fetchesCompany + * @param GeneratesWalletCode $generatesWalletCode + * @param CreatesWallet $createsWallet + * @param GeneratesTransactionBillNumber $generatesTransactionBillNumber + * @param CreatesTransaction $createsTransaction + * @param UpdatesWallet $updatesWallet + * @param CreditWalletProcessor $creditWalletProcessor + */ + public function __construct( + FetchesCompany $fetchesCompany, + GeneratesWalletCode $generatesWalletCode, + CreatesWallet $createsWallet, + GeneratesTransactionBillNumber $generatesTransactionBillNumber, + CreatesTransaction $createsTransaction, + UpdatesWallet $updatesWallet, + CreditWalletProcessor $creditWalletProcessor + ) + { + $this->fetchesCompany = $fetchesCompany; + $this->generatesWalletCode = $generatesWalletCode; + $this->createsWallet = $createsWallet; + $this->generatesTransactionBillNumber = $generatesTransactionBillNumber; + $this->createsTransaction = $createsTransaction; + $this->updatesWallet = $updatesWallet; + $this->creditWalletProcessor = $creditWalletProcessor; + } + + /** + * @param Request $request + * @return JsonResponse + * @throws \App\Classes\Exceptions\MalformedRequestException + */ + public function logic(Request $request) : JsonResponse + { + $amount = floatval(str_replace(',', '', $request->input('amount'))); + + $company = $this->fetchesCompany->execute(['id' => $request->input('company_id')]); + + $reference = $request->input('reference'); + + $type = $request->input('transaction_type'); + + $wallet = $this->creditWalletProcessor->execute($company, $type, $amount, $reference); + + return $this->resourceResponse(new WalletResource($wallet)); + } +} diff --git a/app/Classes/Modules/Wallets/ControllersLogic/DebitWalletLogic.php b/app/Classes/Modules/Wallets/ControllersLogic/DebitWalletLogic.php new file mode 100644 index 00000000..682065c0 --- /dev/null +++ b/app/Classes/Modules/Wallets/ControllersLogic/DebitWalletLogic.php @@ -0,0 +1,117 @@ + 'Debit into Company Wallet', + 'message' => 'You have successfully debit company wallet' + ]; + } + + + /** @var FetchesCompany */ + private $fetchesCompany; + + /** @var GeneratesTransactionBillNumber */ + private $generatesTransactionBillNumber; + + /** @var CreatesTransaction */ + private $createsTransaction; + + /** @var UpdatesWallet */ + private $updatesWallet; + + /** + * CreateWalletLogic constructor. + * @param FetchesCompany $fetchesCompany + * @param GeneratesTransactionBillNumber $generatesTransactionBillNumber + * @param CreatesTransaction $createsTransaction + * @param UpdatesWallet $updatesWallet + */ + public function __construct( + FetchesCompany $fetchesCompany, + GeneratesTransactionBillNumber $generatesTransactionBillNumber, + CreatesTransaction $createsTransaction, + UpdatesWallet $updatesWallet + ) + { + $this->fetchesCompany = $fetchesCompany; + $this->generatesTransactionBillNumber = $generatesTransactionBillNumber; + $this->createsTransaction = $createsTransaction; + $this->updatesWallet = $updatesWallet; + } + + /** + * @param Request $request + * @return JsonResponse + * @throws \App\Classes\Exceptions\MalformedRequestException + */ + public function logic(Request $request) : JsonResponse + { + $amount = floatval(str_replace(',', '', $request->input('amount'))); + $company = $this->fetchesCompany->execute(['id' => $request->input('company_id')]); + $reference = $request->input('reference'); + + 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-'); + + $transaction_object = new TransactionObject( + $billNumber, + TransactionType::DEBIT_NOTE, + 1, + $wallet->company->id, + 1, + PaymentMethodType::CASH, + $amount, + $amount, + 1, + 1, + 1, + 0, + 0, + null, + ApprovalStatus::APPROVED, + [], + $reference + ); + + $transaction = $this->createsTransaction->execute($wallet, $transaction_object); + $updateWalletAmount = $wallet->amount - $transaction->amount; + + $walletOject = new WalletObject($wallet->company->id, $wallet->currency_id, $wallet->code, $updateWalletAmount); + + $wallet = $this->updatesWallet->execute($wallet, $walletOject); + + return $this->resourceResponse(new WalletResource($wallet)); + } +} diff --git a/app/Classes/Modules/Wallets/ControllersLogic/FetchWalletByCompanyModuleControllerLogic.php b/app/Classes/Modules/Wallets/ControllersLogic/FetchWalletByCompanyModuleControllerLogic.php new file mode 100644 index 00000000..8a97929c --- /dev/null +++ b/app/Classes/Modules/Wallets/ControllersLogic/FetchWalletByCompanyModuleControllerLogic.php @@ -0,0 +1,85 @@ + 'Retrieved Wallet', + 'message' => 'You have successfully created a wallet' + ]; + } + + /** @var FetchesWallet */ + private $fetchesWallet; + + /** @var CreatesWallet */ + private $createsWallet; + + /** @var GeneratesWalletCode */ + private $generatesWalletCode; + + /** @var CanCreateCompanyWallet */ + private $canCreateCompanyWallet; + + /** @var FetchesCompanyModule */ + private $fetchesCompanyModule; + + + /** + * CreateWalletLogic constructor. + * @param FetchesWallet $fetchesWallet + */ + public function __construct(FetchesWallet $fetchesWallet, CreatesWallet $createsWallet, GeneratesWalletCode $generatesWalletCode, CanCreateCompanyWallet $canCreateCompanyWallet, FetchesCompanyModule $fetchesCompanyModule) + { + $this->fetchesWallet = $fetchesWallet; + $this->fetchesCompanyModule = $fetchesCompanyModule; + $this->createsWallet = $createsWallet; + $this->generatesWalletCode = $generatesWalletCode; + $this->canCreateCompanyWallet = $canCreateCompanyWallet; + } + + /** + * @param Request $request + * @return JsonResponse + * @throws ErrorException + */ + public function logic(Request $request) : JsonResponse + { + // $this->canFetchWallet->passes(); + + if (!count(Wallet::where('owner_id', $request->route('company_module_id'))->get())) { + $object = new WalletObject($request->route('company_module_id'), $request->input('currency_id') ?? 1, $this->generatesWalletCode->execute()); + + $this->canCreateCompanyWallet->passes($object); + + $company_module = $this->fetchesCompanyModule->execute(['id' => $request->route('company_module_id')]); + + $wallet = $this->createsWallet->execute($object, $company_module); + + return $this->resourceResponse(new WalletResource($wallet)); + } + + $query = $this->fetchesWallet->execute(['owner_id' => $request->route('company_module_id')]); + + return $this->resourceResponse(new WalletResource($query)); + } +} diff --git a/app/Classes/Modules/Wallets/ControllersLogic/ListWalletLogic.php b/app/Classes/Modules/Wallets/ControllersLogic/ListWalletLogic.php new file mode 100644 index 00000000..cf6b86bb --- /dev/null +++ b/app/Classes/Modules/Wallets/ControllersLogic/ListWalletLogic.php @@ -0,0 +1,60 @@ + 'List Company Wallet', + 'message' => 'You have successfully list company wallet' + ]; + } + + /** @var ListWallet */ + private $listsWallet; + + /** @var CanCreateCompanyWallet */ + private $canListWallet; + + /** + * CreateWalletLogic constructor. + * @param CreatesWallet $createsWallet + * @param GeneratesWalletCode $generatesWalletCode + * @param CanCreateCompanyWallet $canCreateCompanyWallet + */ + public function __construct(CanListWallet $canListWallet, ListsWallet $listsWallet) + { + $this->canListWallet = $canListWallet; + $this->listsWallet = $listsWallet; + } + + /** + * @param Request $request + * @return JsonResponse + * @throws ErrorException + */ + public function logic(Request $request) : JsonResponse + { + //$this->canListWallet->passes(); + + $query = $this->listsWallet->execute($this->listsWallet->deserializeFilters($request->input('filters'))); + + return $this->collectionResponse(WalletResource::collection($query)); + } +} diff --git a/app/Classes/Modules/Wallets/ControllersLogic/TopUpWalletLogic.php b/app/Classes/Modules/Wallets/ControllersLogic/TopUpWalletLogic.php new file mode 100644 index 00000000..3d345c5c --- /dev/null +++ b/app/Classes/Modules/Wallets/ControllersLogic/TopUpWalletLogic.php @@ -0,0 +1,109 @@ + 'TopUp into Company Wallet', + 'message' => 'You have successfully created a topup request for company\'s wallet' + ]; + } + + + /** @var FetchesCompanyModule */ + private $fetchesCompanyModule; + + /** @var GeneratesWalletCode */ + private $generatesWalletCode; + + /** @var CreatesWallet */ + private $createsWallet; + + /** @var GeneratesTransactionBillNumber */ + private $generatesTransactionBillNumber; + + /** @var CreatesBillplzBill */ + private $createsBillplzBill; + + /** @var CreatesTransactionableTransaction */ + private $createsTransactionableTransaction; + + + /** + * TopUpWalletLogic constructor. + * @param FetchesCompanyModule $fetchesCompanyModule + * @param GeneratesWalletCode $generatesWalletCode + * @param CreatesWallet $createsWallet + * @param GeneratesTransactionBillNumber $generatesTransactionBillNumber + * @param CreatesBillplzBill $createsBillplzBill + * @param CreatesTransaction $createsTransaction + */ + public function __construct(FetchesCompanyModule $fetchesCompanyModule, GeneratesWalletCode $generatesWalletCode, CreatesWallet $createsWallet, GeneratesTransactionBillNumber $generatesTransactionBillNumber, CreatesBillplzBill $createsBillplzBill, CreatesTransactionableTransaction $createsTransactionableTransaction) + { + $this->fetchesCompanyModule = $fetchesCompanyModule; + $this->generatesWalletCode = $generatesWalletCode; + $this->createsWallet = $createsWallet; + $this->generatesTransactionBillNumber = $generatesTransactionBillNumber; + $this->createsBillplzBill = $createsBillplzBill; + $this->createsTransactionableTransaction = $createsTransactionableTransaction; + } + + /** + * @param Request $request + * @return JsonResponse + * @throws \App\Classes\Exceptions\MalformedRequestException + */ + public function logic(Request $request) : JsonResponse + { + $amount = floatval(str_replace(',', '', $request->input('amount'))); + $companyModule = $this->fetchesCompanyModule->execute(['id' => $request->input('company_module_id')]); + + /** @var Wallet $wallet */ + $wallet = $companyModule->wallets()->first(); + + if (!$wallet) { + $object = new WalletObject($companyModule->id, 1, $this->generatesWalletCode->execute()); + /** @var Wallet $wallet */ + $wallet = $this->createsWallet->execute($object, $companyModule); + } + + $user = $companyModule->employees()->first(); + $billNumber = $this->generatesTransactionBillNumber->execute('TOPUP-'); + + if($amount < 0) { + throw new MalformedRequestException('Top up credit value must be greater than zero.'); + } + + $billPlzBill = $this->createsBillplzBill->execute($companyModule->name, $user->email, 'This payment is credit topup for company ref. ' . $companyModule->reference, $amount, $billNumber, $request->input('bank_code'), true); + + $transaction_object = new TransactionObject($billNumber, TransactionType::TOP_UP, 1, $companyModule->id, 1, PaymentMethodType::PAYMENT_GATEWAY, $amount, $amount, 1, 1, 1, 0, 0, null, ApprovalStatus::PENDING_SUBMISSION, [], $billPlzBill->id); + + $transaction = $this->createsTransactionableTransaction->execute($wallet, $transaction_object); + + return $this->resourceResponse(new WalletTransactionResource($transaction)); + } +} diff --git a/app/Classes/Modules/Wallets/ControllersLogic/UpdateStatusWalletLogic.php b/app/Classes/Modules/Wallets/ControllersLogic/UpdateStatusWalletLogic.php new file mode 100644 index 00000000..b051d3e3 --- /dev/null +++ b/app/Classes/Modules/Wallets/ControllersLogic/UpdateStatusWalletLogic.php @@ -0,0 +1,69 @@ + 'Update Status Transaction Company Wallet', + 'message' => 'You have successfully status transaction company wallet' + ]; + } + + /** @var ListWallet */ + private $fetchesWallet; + + /** @var CanCreateCompanyWallet */ + private $canListWallet; + + /** @var UpdateWalletTransactionProcessor */ + private $updateWalletTransactionProcessor; + + /** + * CreateWalletLogic constructor. + * @param CreatesWallet $createsWallet + * @param GeneratesWalletCode $generatesWalletCode + * @param CanCreateCompanyWallet $canCreateCompanyWallet + */ + public function __construct(FetchesWallet $fetchesWallet, UpdateWalletTransactionProcessor $updateWalletTransactionProcessor) + { + $this->fetchesWallet = $fetchesWallet; + $this->updateWalletTransactionProcessor = $updateWalletTransactionProcessor; + } + + /** + * @param Request $request + * @return JsonResponse + * @throws ErrorException + */ + public function logic(Request $request) : JsonResponse + { + $status = ($request->route('status')=='approve') ? 2 : 4; + + $wallet = $this->updateWalletTransactionProcessor->execute($request->route('transaction_id'), $status); + + return $this->resourceResponse(new WalletResource($wallet)); + + } +} diff --git a/app/Classes/Modules/Wallets/ControllersLogic/WithdrawWalletLogic.php b/app/Classes/Modules/Wallets/ControllersLogic/WithdrawWalletLogic.php new file mode 100644 index 00000000..b1491ab7 --- /dev/null +++ b/app/Classes/Modules/Wallets/ControllersLogic/WithdrawWalletLogic.php @@ -0,0 +1,72 @@ + 'Withdraw from Company Wallet', + 'message' => 'You have successfully withdraw company wallet' + ]; + } + + /** @var FetchesWallet */ + private $fetchesWallet; + + /** @var CanWithdrawWallet */ + private $canWithdrawWallet; + + /** @var CreateWalletTransactionProcessor */ + private $createWalletTransactionProcessor; + + /** + * CreateWalletLogic constructor. + * @param CreatesWallet $createsWallet + * @param GeneratesWalletCode $generatesWalletCode + * @param CanCreateCompanyWallet $canCreateCompanyWallet + */ + public function __construct(CanWithdrawWallet $canWithdrawWallet, FetchesWallet $fetchesWallet, CreateWalletTransactionProcessor $createWalletTransactionProcessor) + { + $this->canWithdrawWallet = $canWithdrawWallet; + $this->fetchesWallet = $fetchesWallet; + $this->createWalletTransactionProcessor = $createWalletTransactionProcessor; + } + + /** + * @param Request $request + * @return JsonResponse + * @throws ErrorException + */ + public function logic(Request $request) : JsonResponse + { + $wallet = $this->fetchesWallet->execute(['id' => $request->input('wallet_id')]); + + $walletOject = new WalletObject( $wallet->company->id, $wallet->currency_id, $wallet->code, $request->input('amount')); + + $this->canWithdrawWallet->passes($walletOject); + + $transaction = $this->createWalletTransactionProcessor->execute($wallet, $walletOject, TransactionType::WITHDRAW); + + return $this->resourceResponse(new WalletResource($wallet)); + } +} diff --git a/app/Classes/Modules/Wallets/DataTransferObjects/WalletObject.php b/app/Classes/Modules/Wallets/DataTransferObjects/WalletObject.php new file mode 100644 index 00000000..cb01bb0c --- /dev/null +++ b/app/Classes/Modules/Wallets/DataTransferObjects/WalletObject.php @@ -0,0 +1,65 @@ +company_module_id = $company_module_id; + $this->currency_id = $currency; + $this->code = $code; + $this->amount = $amount; + } + + /** + * @return int + */ + public function getCompanyModuleId(): int + { + return $this->company_module_id; + } + + /** + * @return int + */ + public function getCurrency(): int + { + return $this->currency_id; + } + + /** + * @return int + */ + public function getCode(): int + { + return $this->code; + } + + public function getAmount(): float + { + return $this->amount; + } + + +} diff --git a/app/Classes/Modules/Wallets/DataTransferObjects/WalletTransactionObject.php b/app/Classes/Modules/Wallets/DataTransferObjects/WalletTransactionObject.php new file mode 100644 index 00000000..234c8f57 --- /dev/null +++ b/app/Classes/Modules/Wallets/DataTransferObjects/WalletTransactionObject.php @@ -0,0 +1,94 @@ +wallet_id = $wallet_id; + $this->bill_no = $bill_no; + $this->trans_type = $trans_type; + $this->amount= $amount; + $this->currency_id = $currency_id; + $this->original_amount = $original_amount; + $this->original_currency_id = $original_currency_id; + $this->currency_rate = $currency_rate; + } + + /** + * @return int + */ + public function getWalletId(): int + { + return $this->wallet_id; + } + + /** + * @return int + */ + public function getBillNo(): int + { + return $this->bill_no; + } + + /** + * @return int + */ + public function getTransType(): int + { + return $this->trans_type; + } + + + public function getAmount(): float + { + return $this->amount; + } + + /** + * @return int + */ + public function getCurrency(): int + { + return $this->currency_id; + } + + + public function getOriginalAmount(): float + { + return $this->original_amount; + } + + public function getOriginalCurrency(): int + { + return $this->original_currency_id; + } + + public function getCurrencyRate(): float + { + return $this->currency_rate; + } +} \ No newline at end of file diff --git a/app/Classes/Modules/Wallets/Processors/CreditWalletProcessor.php b/app/Classes/Modules/Wallets/Processors/CreditWalletProcessor.php new file mode 100644 index 00000000..65f3b9b6 --- /dev/null +++ b/app/Classes/Modules/Wallets/Processors/CreditWalletProcessor.php @@ -0,0 +1,90 @@ +generatesWalletCode = $generatesWalletCode; + $this->createsWallet = $createsWallet; + $this->generatesTransactionBillNumber = $generatesTransactionBillNumber; + $this->createsTransaction = $createsTransaction; + $this->updatesWallet = $updatesWallet; + } + + + /** + * @param Company $company + * @param int $transactionType + * @param float $amount + * @param string $reference + * @return \Illuminate\Database\Eloquent\Model + * @throws \App\Classes\Exceptions\MalformedRequestException + */ + public function execute(Company $company, int $transactionType, float $amount, string $reference) + { + if (!$company->wallets()->first()) { + $object = new WalletObject($company->id, 1, $this->generatesWalletCode->execute()); + $this->createsWallet->execute($object, $company); + } + + /** @var Wallet $wallet */ + $wallet = $company->wallets()->first(); + + $billNumber = $this->generatesTransactionBillNumber->execute($transactionType === 2 ? 'DEBIT-NOTE-' : 'CREDIT-NOTE-'); + + $transaction_object = new TransactionObject($billNumber, $transactionType === 2 ? TransactionType::DEBIT_NOTE : TransactionType::CREDIT_NOTE, 1, $wallet->owner->id, 1, PaymentMethodType::CASH, $amount, $amount, 1, 1, 1, 0, 0, null, ApprovalStatus::APPROVED, [], $reference); + $transaction = $this->createsTransaction->execute($wallet, $transaction_object); + + $updateWalletAmount = $transactionType === 2 ? ($wallet->amount - $transaction->amount) : ($wallet->amount + $transaction->amount); + + $walletObject = new WalletObject($wallet->owner->id, $wallet->currency_id, $wallet->code, $updateWalletAmount); + + $wallet = $this->updatesWallet->execute($wallet, $walletObject); + + return $wallet; + } +} diff --git a/app/Classes/Modules/Wallets/Services/ChecksIfWalletCodeExists.php b/app/Classes/Modules/Wallets/Services/ChecksIfWalletCodeExists.php new file mode 100644 index 00000000..4d00540a --- /dev/null +++ b/app/Classes/Modules/Wallets/Services/ChecksIfWalletCodeExists.php @@ -0,0 +1,28 @@ +repository = $repository; + } + + public function execute(int $code): bool { + return $this->repository->where('code', $code)->exists(); + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/Wallets/Services/ChecksIfWalletTransactionBillNoExists.php b/app/Classes/Modules/Wallets/Services/ChecksIfWalletTransactionBillNoExists.php new file mode 100644 index 00000000..43df87d4 --- /dev/null +++ b/app/Classes/Modules/Wallets/Services/ChecksIfWalletTransactionBillNoExists.php @@ -0,0 +1,22 @@ +repository = $repository; + } + + public function execute(int $bill_no): bool { + return $this->repository->where('bill_no', $bill_no)->exists(); + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/Wallets/Services/CreatesWallet.php b/app/Classes/Modules/Wallets/Services/CreatesWallet.php new file mode 100644 index 00000000..f3d71743 --- /dev/null +++ b/app/Classes/Modules/Wallets/Services/CreatesWallet.php @@ -0,0 +1,27 @@ +company_module_id = $object->getCompanyModuleId(); + $model->code = $object->getCode(); + $model->currency_id = $object->getCurrency(); + + return $this->handler($companyModule->wallets(), $model); + } +} diff --git a/app/Classes/Modules/Wallets/Services/CreatesWalletTransaction.php b/app/Classes/Modules/Wallets/Services/CreatesWalletTransaction.php new file mode 100644 index 00000000..0b40879c --- /dev/null +++ b/app/Classes/Modules/Wallets/Services/CreatesWalletTransaction.php @@ -0,0 +1,30 @@ +wallet_id = $object->getWalletId(); + $model->bill_no = $object->getBillNo(); + $model->trans_type = $object->getTransType(); + $model->amount = $object->getAmount(); + $model->currency_id = $object->getCurrency(); + $model->original_amount = $object->getOriginalAmount(); + $model->original_currency_id = $object->getOriginalCurrency(); + $model->currency_rate = $object->getCurrencyRate(); + + return $this->handler($model); + + } +} \ No newline at end of file diff --git a/app/Classes/Modules/Wallets/Services/FetchesWallet.php b/app/Classes/Modules/Wallets/Services/FetchesWallet.php new file mode 100644 index 00000000..c3542bb7 --- /dev/null +++ b/app/Classes/Modules/Wallets/Services/FetchesWallet.php @@ -0,0 +1,34 @@ +repository = $repository; + } + + + /** + * @return Builder + */ + public function getRepository(): Builder + { + return $this->repository->newQuery(); + } +} \ No newline at end of file diff --git a/app/Classes/Modules/Wallets/Services/GeneratesWalletCode.php b/app/Classes/Modules/Wallets/Services/GeneratesWalletCode.php new file mode 100644 index 00000000..af2bda7e --- /dev/null +++ b/app/Classes/Modules/Wallets/Services/GeneratesWalletCode.php @@ -0,0 +1,32 @@ +walletCodeExists = $walletCodeExists; + } + + + /** + * @return int + */ + public function execute(): int { + + $code = mt_rand(100000001, 999999999); + return !$this->walletCodeExists->execute($code) ? $code : self::execute(); + + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/Wallets/Services/GeneratesWalletTransactionBillNo.php b/app/Classes/Modules/Wallets/Services/GeneratesWalletTransactionBillNo.php new file mode 100644 index 00000000..d3758d72 --- /dev/null +++ b/app/Classes/Modules/Wallets/Services/GeneratesWalletTransactionBillNo.php @@ -0,0 +1,27 @@ +walletTransationBillNoExists = $walletTransationBillNoExists; + } + + + + public function execute(): int { + + $code = mt_rand(100000001, 999999999); + return !$this->walletTransationBillNoExists->execute($code) ? $code : self::execute(); + + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/Wallets/Services/ListsWallet.php b/app/Classes/Modules/Wallets/Services/ListsWallet.php new file mode 100644 index 00000000..c11e2063 --- /dev/null +++ b/app/Classes/Modules/Wallets/Services/ListsWallet.php @@ -0,0 +1,30 @@ +repository = $repository; + } + + /** + * @return Builder + */ + public function getRepository(): Builder + { + return $this->repository->newQuery(); + } +} diff --git a/app/Classes/Modules/Wallets/Services/UpdatesWallet.php b/app/Classes/Modules/Wallets/Services/UpdatesWallet.php new file mode 100644 index 00000000..8b268fab --- /dev/null +++ b/app/Classes/Modules/Wallets/Services/UpdatesWallet.php @@ -0,0 +1,27 @@ +amount = $object->getAmount(); + $model->code = $object->getCode(); + $model->currency_id = $object->getCurrency(); + + + return $this->handler($model); + + } +} diff --git a/app/Classes/Modules/Wallets/Services/UpdatesWalletBalance.php b/app/Classes/Modules/Wallets/Services/UpdatesWalletBalance.php new file mode 100644 index 00000000..a724cf24 --- /dev/null +++ b/app/Classes/Modules/Wallets/Services/UpdatesWalletBalance.php @@ -0,0 +1,25 @@ +amount = $model->amount + $amount; + return $this->handler($model); + + } +} diff --git a/app/Classes/Modules/Wallets/Standards/Rules/CanCreateCompanyWallet.php b/app/Classes/Modules/Wallets/Standards/Rules/CanCreateCompanyWallet.php new file mode 100644 index 00000000..0f1dd065 --- /dev/null +++ b/app/Classes/Modules/Wallets/Standards/Rules/CanCreateCompanyWallet.php @@ -0,0 +1,55 @@ +companyWalletValidation = $companyWalletValidation; + } + + + /** + * @return bool + */ + protected function authorized(): bool + { + // TODO Set Authorization rules + return true; + } + + /** + * @param WalletObject $object + * @return bool + * @throws \App\Classes\Exceptions\RequestValidationException + */ + protected function validators($object): bool + { + return $this->companyWalletValidation->validate($object); + } + + + /** + * @param WalletObject $object + * @return bool + */ + protected function criteria($object): bool + { + return true; + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/Wallets/Standards/Rules/CanCreateWalletTransaction.php b/app/Classes/Modules/Wallets/Standards/Rules/CanCreateWalletTransaction.php new file mode 100644 index 00000000..8beafb37 --- /dev/null +++ b/app/Classes/Modules/Wallets/Standards/Rules/CanCreateWalletTransaction.php @@ -0,0 +1,51 @@ +walletTransactionValidation = $walletTransactionValidation; + } + + + /** + * @return bool + */ + protected function authorized(): bool + { + // TODO Set Authorization rules + return true; + } + + /** + * @param WalletTransactionObject $object + * @return bool + * @throws \App\Classes\Exceptions\RequestValidationException + */ + protected function validators($object): bool + { + return $this->walletTransactionValidation->validate($object); + } + + /** + * @param WalletTransactionObject $object + * @return bool + */ + protected function criteria($object): bool + { + return true; + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/Wallets/Standards/Rules/CanListWallet.php b/app/Classes/Modules/Wallets/Standards/Rules/CanListWallet.php new file mode 100644 index 00000000..c87cb316 --- /dev/null +++ b/app/Classes/Modules/Wallets/Standards/Rules/CanListWallet.php @@ -0,0 +1,51 @@ +listWalletValidation = $listWalletValidation; + } + + + /** + * @return bool + */ + protected function authorized(): bool + { + // TODO Set Authorization rules + return true; + } + + /** + * @param WalletObject $object + * @return bool + * @throws \App\Classes\Exceptions\RequestValidationException + */ + protected function validators($object): bool + { + return $this->listWalletValidation->validate($object); + } + + /** + * @param WalletTransactionObject $object + * @return bool + */ + protected function criteria($object): bool + { + return true; + } + +} diff --git a/app/Classes/Modules/Wallets/Standards/Rules/CanTopUpWallet.php b/app/Classes/Modules/Wallets/Standards/Rules/CanTopUpWallet.php new file mode 100644 index 00000000..9a005498 --- /dev/null +++ b/app/Classes/Modules/Wallets/Standards/Rules/CanTopUpWallet.php @@ -0,0 +1,51 @@ +topUpWalletValidation = $topUpWalletValidation; + } + + + /** + * @return bool + */ + protected function authorized(): bool + { + // TODO Set Authorization rules + return true; + } + + /** + * @param WalletObject $object + * @return bool + * @throws \App\Classes\Exceptions\RequestValidationException + */ + protected function validators($object): bool + { + return $this->topUpWalletValidation->validate($object); + } + + /** + * @param WalletTransactionObject $object + * @return bool + */ + protected function criteria($object): bool + { + return true; + } + +} diff --git a/app/Classes/Modules/Wallets/Standards/Rules/CanWithdrawWallet.php b/app/Classes/Modules/Wallets/Standards/Rules/CanWithdrawWallet.php new file mode 100644 index 00000000..6fb4019d --- /dev/null +++ b/app/Classes/Modules/Wallets/Standards/Rules/CanWithdrawWallet.php @@ -0,0 +1,51 @@ +witdrawWalletValidation = $witdrawWalletValidation; + } + + + /** + * @return bool + */ + protected function authorized(): bool + { + // TODO Set Authorization rules + return true; + } + + /** + * @param WalletObject $object + * @return bool + * @throws \App\Classes\Exceptions\RequestValidationException + */ + protected function validators($object): bool + { + return $this->witdrawWalletValidation->validate($object); + } + + /** + * @param WalletTransactionObject $object + * @return bool + */ + protected function criteria($object): bool + { + return true; + } + +} diff --git a/app/Classes/Modules/Wallets/Standards/Validators/CompanyWalletValidation.php b/app/Classes/Modules/Wallets/Standards/Validators/CompanyWalletValidation.php new file mode 100644 index 00000000..2cb8628b --- /dev/null +++ b/app/Classes/Modules/Wallets/Standards/Validators/CompanyWalletValidation.php @@ -0,0 +1,40 @@ + $object->getCompanyModuleId(), + 'currency_id' => $object->getCurrency(), + ]; + } + + /** + * @return array + */ + protected function rules(): array + { + return [ + 'company_module_id' => 'required', + 'currency_id' => 'required', + ]; + } + + /** + * @return array + */ + protected function messages(): array + { + return []; + } +} \ No newline at end of file diff --git a/app/Classes/Modules/Wallets/Standards/Validators/ListWalletValidation.php b/app/Classes/Modules/Wallets/Standards/Validators/ListWalletValidation.php new file mode 100644 index 00000000..1f75aa54 --- /dev/null +++ b/app/Classes/Modules/Wallets/Standards/Validators/ListWalletValidation.php @@ -0,0 +1,30 @@ + $object->getWalletId(), + 'currency_id' => $object->getCurrency(), + 'amount' => $object->getAmount(), + 'trans_type'=>$object->getTransType() + ]; + } + + /** + * @return array + */ + protected function rules(): array + { + return [ + 'wallet_id' => 'required', + 'currency_id' => 'required', + 'amount' => 'required', + 'trans_type'=>'required' + ]; + } + + /** + * @return array + */ + protected function messages(): array + { + return []; + } +} \ No newline at end of file diff --git a/app/Classes/Modules/Wallets/Standards/Validators/WithdrawWalletValidation.php b/app/Classes/Modules/Wallets/Standards/Validators/WithdrawWalletValidation.php new file mode 100644 index 00000000..78660228 --- /dev/null +++ b/app/Classes/Modules/Wallets/Standards/Validators/WithdrawWalletValidation.php @@ -0,0 +1,30 @@ +execute($request); + } +} diff --git a/app/Http/Controllers/Wallets/CreateWalletController.php b/app/Http/Controllers/Wallets/CreateWalletController.php new file mode 100644 index 00000000..1aa71179 --- /dev/null +++ b/app/Http/Controllers/Wallets/CreateWalletController.php @@ -0,0 +1,15 @@ +execute($request); + } +} \ No newline at end of file diff --git a/app/Http/Controllers/Wallets/CreateWalletTransactionController.php b/app/Http/Controllers/Wallets/CreateWalletTransactionController.php new file mode 100644 index 00000000..70b94a03 --- /dev/null +++ b/app/Http/Controllers/Wallets/CreateWalletTransactionController.php @@ -0,0 +1,15 @@ +execute($request); + } +} \ No newline at end of file diff --git a/app/Http/Controllers/Wallets/CreditWalletController.php b/app/Http/Controllers/Wallets/CreditWalletController.php new file mode 100644 index 00000000..b3143588 --- /dev/null +++ b/app/Http/Controllers/Wallets/CreditWalletController.php @@ -0,0 +1,15 @@ +execute($request); + } +} diff --git a/app/Http/Controllers/Wallets/DebitWalletController.php b/app/Http/Controllers/Wallets/DebitWalletController.php new file mode 100644 index 00000000..7feafb39 --- /dev/null +++ b/app/Http/Controllers/Wallets/DebitWalletController.php @@ -0,0 +1,15 @@ +execute($request); + } +} diff --git a/app/Http/Controllers/Wallets/FetchWalletByCompanyModuleController.php b/app/Http/Controllers/Wallets/FetchWalletByCompanyModuleController.php new file mode 100644 index 00000000..d4c0ae71 --- /dev/null +++ b/app/Http/Controllers/Wallets/FetchWalletByCompanyModuleController.php @@ -0,0 +1,20 @@ +execute($request); + } + +} diff --git a/app/Http/Controllers/Wallets/ListWalletController.php b/app/Http/Controllers/Wallets/ListWalletController.php new file mode 100644 index 00000000..45b2f1d1 --- /dev/null +++ b/app/Http/Controllers/Wallets/ListWalletController.php @@ -0,0 +1,14 @@ +execute($request); + } +} diff --git a/app/Http/Controllers/Wallets/TopUpWalletController.php b/app/Http/Controllers/Wallets/TopUpWalletController.php new file mode 100644 index 00000000..aaa707bd --- /dev/null +++ b/app/Http/Controllers/Wallets/TopUpWalletController.php @@ -0,0 +1,15 @@ +execute($request); + } +} diff --git a/app/Http/Controllers/Wallets/UpdateStatusWalletController.php b/app/Http/Controllers/Wallets/UpdateStatusWalletController.php new file mode 100644 index 00000000..21eea924 --- /dev/null +++ b/app/Http/Controllers/Wallets/UpdateStatusWalletController.php @@ -0,0 +1,14 @@ +execute($request); + } +} diff --git a/app/Http/Controllers/Wallets/WalletReportController.php b/app/Http/Controllers/Wallets/WalletReportController.php new file mode 100644 index 00000000..998bba53 --- /dev/null +++ b/app/Http/Controllers/Wallets/WalletReportController.php @@ -0,0 +1,29 @@ + [ + 'walletSum' => (float) Wallet::all()->sum('amount'), + 'outgoingSum' => (float) Transaction::where('type', TransactionType::PAYMENT)->where('owner_type', Wallet::class)->sum('amount'), + 'incomingSum' => (float) Transaction::whereIn('type', [TransactionType::TOP_UP, TransactionType::CREDIT_NOTE])->where('owner_type', Wallet::class)->sum('amount'), + ]] + ))->handler(); + } +} diff --git a/app/Http/Controllers/Wallets/WithdrawWalletController.php b/app/Http/Controllers/Wallets/WithdrawWalletController.php new file mode 100644 index 00000000..7c7b944a --- /dev/null +++ b/app/Http/Controllers/Wallets/WithdrawWalletController.php @@ -0,0 +1,15 @@ +execute($request); + } +} diff --git a/app/Http/Resources/WalletResource.php b/app/Http/Resources/WalletResource.php new file mode 100644 index 00000000..0529e170 --- /dev/null +++ b/app/Http/Resources/WalletResource.php @@ -0,0 +1,29 @@ + $this->id, + 'code' => $this->code, + 'currency_id' => $this->currency_id, + 'amount' => (double) $this->amount, + 'company_id' => (int) $this->owner->id, + 'transactions' => $this->whenLoaded('transactions', WalletTransactionResource::collection($this->transactions()->whereIn('status', [2, 3])->orderBy('id', 'DESC')->get()), []), + 'top_up_records' => $this->whenLoaded('transactions', WalletTransactionResource::collection($this->transactions()->whereNotIn('status', [0])->where('type', TransactionType::TOP_UP)->orderBy('id', 'DESC')->get()), []), + 'company_module_marking' => $this->owner->connections->first()->invitee_reference, + ]; + } +} diff --git a/app/Http/Resources/WalletTransactionResource.php b/app/Http/Resources/WalletTransactionResource.php new file mode 100644 index 00000000..dbee29eb --- /dev/null +++ b/app/Http/Resources/WalletTransactionResource.php @@ -0,0 +1,64 @@ +type){ + case 5: + $description = (double) $this->amount.' Credit Top up'; + break; + case 9: + $description = 'Credit Voucher for '.$this->payment_reference; + break; + case 1: + $booking = Transaction::where('payment_reference', $this->bill_no)->first()->owner; + + if(!$booking) { + $description = 'Payment for unknown booking, please contact tech support.'; + break; + } + + $marking = $booking->marking; + $description = 'Payment For booking refs.'.''.$marking.''; + break; + case 11: + $description = 'Debit Voucher for '.$this->payment_reference; + break; + + } + + return [ + 'type' => (int) $this->type, + 'marking' => $this->owner->owner->reference, + 'bill_no' => $this->bill_no, + 'reference' => $this->payment_reference, + 'payment_method' => (float) $this->payment_method, + // 'issuer_name' => $this->issuerCompany->name, + 'amount' => (double) $this->amount, + 'service_charge' => (double) $this->service_charge, + 'tax' => (double) $this->tax, + 'status' => (int) $this->status, + 'description' => $description, + 'details' => TransactionDetailResource::collection($this->transactionDetails), + 'updated_at' => Carbon::parse($this->updated_at)->format('d-m-Y h:i:s A'), + 'created_at' => Carbon::parse($this->created_at)->format('d-m-Y h:i:s A') + ]; + } +} diff --git a/app/Models/CompanyModule.php b/app/Models/CompanyModule.php index 4e9c0526..c6253288 100644 --- a/app/Models/CompanyModule.php +++ b/app/Models/CompanyModule.php @@ -194,7 +194,11 @@ class CompanyModule extends AbstractModel implements Addressable, Documentable, return $this->hasManyDeep(Transaction::class, [Order::class], ['company_module_id', 'owner_id'], ['id', 'id']); } - - - + /** + * @return MorphMany + */ + public function wallets(): morphMany + { + return $this->morphMany(Wallet::class, 'owner'); + } } diff --git a/app/Models/Wallet.php b/app/Models/Wallet.php new file mode 100644 index 00000000..00677513 --- /dev/null +++ b/app/Models/Wallet.php @@ -0,0 +1,34 @@ +morphTo(); + } + + /** + * @return morphMany + */ + public function transactions(): morphMany + { + return $this->morphMany(Transaction::class, 'owner'); + } +} diff --git a/database/migrations/2023_03_11_212614_create_companies_wallet_table.php b/database/migrations/2023_03_11_212614_create_companies_wallet_table.php new file mode 100644 index 00000000..3837a0e1 --- /dev/null +++ b/database/migrations/2023_03_11_212614_create_companies_wallet_table.php @@ -0,0 +1,38 @@ +id(); + $table->morphs('owner'); + $table->string('code'); + $table->foreignId('currency_id')->unsigned(); + $table->decimal('amount', 20, 5)->default(0.00); + $table->softDeletes(); + $table->timestamps(); + + $table->foreign('currency_id')->references('id')->on('currencies'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('wallets'); + } +} diff --git a/resources/assets/vue/components/companies/elements/CustomerPaymentBillingInnerComponent.vue b/resources/assets/vue/components/companies/elements/CustomerPaymentBillingInnerComponent.vue new file mode 100644 index 00000000..1bbf3d5d --- /dev/null +++ b/resources/assets/vue/components/companies/elements/CustomerPaymentBillingInnerComponent.vue @@ -0,0 +1,126 @@ + + diff --git a/resources/assets/vue/components/companies/sections/CustomerPaymentBillingSectionComponent.vue b/resources/assets/vue/components/companies/sections/CustomerPaymentBillingSectionComponent.vue index 4a7f5422..4ebdffaa 100644 --- a/resources/assets/vue/components/companies/sections/CustomerPaymentBillingSectionComponent.vue +++ b/resources/assets/vue/components/companies/sections/CustomerPaymentBillingSectionComponent.vue @@ -1,6 +1,7 @@