From bc8ec2854accfd96637a43c1af63789013b603a0 Mon Sep 17 00:00:00 2001 From: Fairuz Date: Sun, 4 Jul 2021 11:52:31 +0800 Subject: [PATCH] Copied transaction, receipt & currecny module from Exchange --- .../ControllersLogic/CreateCurrencyLogic.php | 108 ++++++++ .../ControllersLogic/DeleteCurrencyLogic.php | 77 ++++++ .../FetchSystemPrimaryCurrencyLogic.php | 71 ++++++ .../ControllersLogic/ListCurrencyLogic.php | 62 +++++ .../RateCalculateCurrencyLogic.php | 60 +++++ .../Rates/CalculateRateLogic.php | 74 ++++++ .../Rates/CreateRateLogic.php | 96 ++++++++ .../Rates/DeleteRateLogic.php | 82 +++++++ .../ControllersLogic/Rates/FetchRateLogic.php | 66 +++++ .../ControllersLogic/Rates/ListRatesLogic.php | 70 ++++++ .../Rates/UpdateRateLogic.php | 97 ++++++++ .../CurrencyConversionObject.php | 86 +++++++ .../DataTransferObjects/RateObject.php | 45 ++++ .../Services/CreatesCurrencyLog.php | 23 ++ .../Currencies/Services/DeletesCurrency.php | 19 ++ .../Currencies/Services/ListsCurrency.php | 33 +++ .../Services/RateCalculatesCurrency.php | 20 ++ .../Services/Rates/CalculatesRate.php | 20 ++ .../Currencies/Services/Rates/CreatesRate.php | 29 +++ .../Services/Rates/CreatesRateLog.php | 24 ++ .../Services/Rates/CreatesRates.php | 24 ++ .../Currencies/Services/Rates/DeletesRate.php | 19 ++ .../Currencies/Services/Rates/FetchesRate.php | 33 +++ .../Currencies/Services/Rates/ListsRates.php | 33 +++ .../Currencies/Services/Rates/UpdatesRate.php | 24 ++ .../Standards/Rules/CanCreateCurrency.php | 51 ++++ .../Standards/Rules/CanDeleteCurrency.php | 39 +++ .../Standards/Rules/CanFetchCurrency.php | 40 +++ .../Standards/Rules/CanListCurrency.php | 41 ++++ .../Standards/Rules/CanUpdateCurrency.php | 54 ++++ .../Standards/Rules/Rates/CanCreateRate.php | 55 +++++ .../Standards/Rules/Rates/CanDeleteRate.php | 45 ++++ .../Standards/Rules/Rates/CanFetchRate.php | 43 ++++ .../Standards/Rules/Rates/CanListRates.php | 45 ++++ .../Standards/Rules/Rates/CanUpdateRate.php | 58 +++++ .../Validators/CurrencyValidation.php | 40 +++ .../Standards/Validators/RateValidation.php | 45 ++++ .../ControllersLogic/CreateReceiptLogic.php | 158 ++++++++++++ .../ReceiptDetailObject.php | 81 ++++++ .../DataTransferObjects/ReceiptObject.php | 150 +++++++++++ .../Services/ChecksIfReceiptBillNoExists.php | 22 ++ .../Receipts/Services/CreatesReceipt.php | 35 +++ .../Services/CreatesReceiptDetail.php | 29 +++ .../Services/GeneratesReceiptBillNo.php | 27 ++ .../Standards/Rules/CanCreateReceipt.php | 51 ++++ .../Rules/CanCreateReceiptDetail.php | 51 ++++ .../Validators/ReceiptDetailValidation.php | 58 +++++ .../Validators/ReceiptValidation.php | 54 ++++ .../CreateMakePaymentPOTransactionLogic.php | 208 ++++++++++++++++ .../CreatePaymentProofDocumentLogic.php | 93 +++++++ .../CreatePurchaseOrderTransactionLogic.php | 121 +++++++++ .../CreateSupplierTransactionLogic.php | 132 ++++++++++ .../CreateTransactionLogic.php | 153 ++++++++++++ .../ListTransactionsLogic.php | 50 ++++ .../SuspendTransactionLogic.php | 61 +++++ .../TransactionDetailObject.php | 73 ++++++ .../DataTransferObjects/TransactionObject.php | 232 ++++++++++++++++++ .../CreateInvoiceTransactionProcessor.php | 229 +++++++++++++++++ .../ChecksIfTransactionBillNumberExists.php | 22 ++ .../Services/CreatesTransaction.php | 40 +++ .../Services/CreatesTransactionDetail.php | 30 +++ .../Services/DeletesTransactionDetails.php | 19 ++ .../Services/FetchesTransaction.php | 34 +++ .../Services/FetchesTransactionDetail.php | 35 +++ .../GeneratesTransactionBillNumber.php | 37 +++ .../Services/ListsTransactions.php | 31 +++ .../Services/UpdatesTransaction.php | 33 +++ .../Services/UpdatesTransactionStatus.php | 22 ++ .../Standards/Rules/CanCreateTransaction.php | 51 ++++ .../Rules/CanCreateTransactionDetail.php | 51 ++++ .../TransactionDetailValidation.php | 62 +++++ .../Validators/TransactionValidation.php | 68 +++++ .../Constants/PaymentMethodType.php | 33 +++ .../Constants/TransactionStatus.php | 19 ++ .../Constants/TransactionType.php | 25 ++ .../Currencies/CreateCurrencyController.php | 19 ++ .../Currencies/DeleteCurrencyController.php | 19 ++ .../FetchSystemPrimaryCurrencyController.php | 19 ++ .../Currencies/ListCurrencyController.php | 20 ++ .../RateCalculateCurrencyController.php | 19 ++ .../Rates/CalculateRateController.php | 19 ++ .../Currencies/Rates/CreateRateController.php | 20 ++ .../Currencies/Rates/DeleteRateController.php | 20 ++ .../Currencies/Rates/FetchRateController.php | 20 ++ .../Currencies/Rates/ListRatesController.php | 20 ++ .../Currencies/Rates/UpdateRateController.php | 20 ++ .../Receipts/CreateReceiptController.php | 15 ++ ...eateMakePaymentPOTransactionController.php | 15 ++ .../CreatePaymentProofDocumentController.php | 21 ++ ...eatePurchaseOrderTransactionController.php | 21 ++ .../CreateSupplierTransactionController.php | 21 ++ .../CreateTransactionController.php | 15 ++ .../ListTransactionsController.php | 21 ++ .../SuspendTransactionController.php | 21 ++ .../Resources/CurrencyConversionResource.php | 26 ++ app/Http/Resources/CurrencyRateResource.php | 26 ++ app/Http/Resources/CurrencyResource.php | 26 ++ .../RateCalculateCurrencyResource.php | 32 +++ app/Http/Resources/ReceiptDetailResource.php | 29 +++ app/Http/Resources/ReceiptResource.php | 34 +++ .../Resources/TransactionDetailResource.php | 26 ++ app/Http/Resources/TransactionResource.php | 36 +++ app/Models/CurrencyLog.php | 9 + app/Models/CurrencyRate.php | 16 ++ app/Models/CurrencyRateLog.php | 10 + app/Models/Receipt.php | 27 ++ app/Models/ReceiptDetail.php | 22 ++ app/Models/Transaction.php | 111 +++++++++ app/Models/TransactionDetail.php | 37 +++ routes/api.php | 10 +- routes/currency.php | 10 + routes/receipt.php | 10 + routes/transaction.php | 15 ++ 113 files changed, 5403 insertions(+), 5 deletions(-) create mode 100644 app/Classes/Modules/Currencies/ControllersLogic/CreateCurrencyLogic.php create mode 100644 app/Classes/Modules/Currencies/ControllersLogic/DeleteCurrencyLogic.php create mode 100644 app/Classes/Modules/Currencies/ControllersLogic/FetchSystemPrimaryCurrencyLogic.php create mode 100644 app/Classes/Modules/Currencies/ControllersLogic/ListCurrencyLogic.php create mode 100644 app/Classes/Modules/Currencies/ControllersLogic/RateCalculateCurrencyLogic.php create mode 100644 app/Classes/Modules/Currencies/ControllersLogic/Rates/CalculateRateLogic.php create mode 100644 app/Classes/Modules/Currencies/ControllersLogic/Rates/CreateRateLogic.php create mode 100644 app/Classes/Modules/Currencies/ControllersLogic/Rates/DeleteRateLogic.php create mode 100644 app/Classes/Modules/Currencies/ControllersLogic/Rates/FetchRateLogic.php create mode 100644 app/Classes/Modules/Currencies/ControllersLogic/Rates/ListRatesLogic.php create mode 100644 app/Classes/Modules/Currencies/ControllersLogic/Rates/UpdateRateLogic.php create mode 100644 app/Classes/Modules/Currencies/DataTransferObjects/CurrencyConversionObject.php create mode 100644 app/Classes/Modules/Currencies/DataTransferObjects/RateObject.php create mode 100644 app/Classes/Modules/Currencies/Services/CreatesCurrencyLog.php create mode 100644 app/Classes/Modules/Currencies/Services/DeletesCurrency.php create mode 100644 app/Classes/Modules/Currencies/Services/ListsCurrency.php create mode 100644 app/Classes/Modules/Currencies/Services/RateCalculatesCurrency.php create mode 100644 app/Classes/Modules/Currencies/Services/Rates/CalculatesRate.php create mode 100644 app/Classes/Modules/Currencies/Services/Rates/CreatesRate.php create mode 100644 app/Classes/Modules/Currencies/Services/Rates/CreatesRateLog.php create mode 100644 app/Classes/Modules/Currencies/Services/Rates/CreatesRates.php create mode 100644 app/Classes/Modules/Currencies/Services/Rates/DeletesRate.php create mode 100644 app/Classes/Modules/Currencies/Services/Rates/FetchesRate.php create mode 100644 app/Classes/Modules/Currencies/Services/Rates/ListsRates.php create mode 100644 app/Classes/Modules/Currencies/Services/Rates/UpdatesRate.php create mode 100644 app/Classes/Modules/Currencies/Standards/Rules/CanCreateCurrency.php create mode 100644 app/Classes/Modules/Currencies/Standards/Rules/CanDeleteCurrency.php create mode 100644 app/Classes/Modules/Currencies/Standards/Rules/CanFetchCurrency.php create mode 100644 app/Classes/Modules/Currencies/Standards/Rules/CanListCurrency.php create mode 100644 app/Classes/Modules/Currencies/Standards/Rules/CanUpdateCurrency.php create mode 100644 app/Classes/Modules/Currencies/Standards/Rules/Rates/CanCreateRate.php create mode 100644 app/Classes/Modules/Currencies/Standards/Rules/Rates/CanDeleteRate.php create mode 100644 app/Classes/Modules/Currencies/Standards/Rules/Rates/CanFetchRate.php create mode 100644 app/Classes/Modules/Currencies/Standards/Rules/Rates/CanListRates.php create mode 100644 app/Classes/Modules/Currencies/Standards/Rules/Rates/CanUpdateRate.php create mode 100644 app/Classes/Modules/Currencies/Standards/Validators/CurrencyValidation.php create mode 100644 app/Classes/Modules/Currencies/Standards/Validators/RateValidation.php create mode 100644 app/Classes/Modules/Receipts/ControllersLogic/CreateReceiptLogic.php create mode 100644 app/Classes/Modules/Receipts/DataTransferObjects/ReceiptDetailObject.php create mode 100644 app/Classes/Modules/Receipts/DataTransferObjects/ReceiptObject.php create mode 100644 app/Classes/Modules/Receipts/Services/ChecksIfReceiptBillNoExists.php create mode 100644 app/Classes/Modules/Receipts/Services/CreatesReceipt.php create mode 100644 app/Classes/Modules/Receipts/Services/CreatesReceiptDetail.php create mode 100644 app/Classes/Modules/Receipts/Services/GeneratesReceiptBillNo.php create mode 100644 app/Classes/Modules/Receipts/Standards/Rules/CanCreateReceipt.php create mode 100644 app/Classes/Modules/Receipts/Standards/Rules/CanCreateReceiptDetail.php create mode 100644 app/Classes/Modules/Receipts/Standards/Validators/ReceiptDetailValidation.php create mode 100644 app/Classes/Modules/Receipts/Standards/Validators/ReceiptValidation.php create mode 100644 app/Classes/Modules/Transactions/ControllersLogic/CreateMakePaymentPOTransactionLogic.php create mode 100644 app/Classes/Modules/Transactions/ControllersLogic/CreatePaymentProofDocumentLogic.php create mode 100644 app/Classes/Modules/Transactions/ControllersLogic/CreatePurchaseOrderTransactionLogic.php create mode 100644 app/Classes/Modules/Transactions/ControllersLogic/CreateSupplierTransactionLogic.php create mode 100644 app/Classes/Modules/Transactions/ControllersLogic/CreateTransactionLogic.php create mode 100644 app/Classes/Modules/Transactions/ControllersLogic/ListTransactionsLogic.php create mode 100644 app/Classes/Modules/Transactions/ControllersLogic/SuspendTransactionLogic.php create mode 100644 app/Classes/Modules/Transactions/DataTransferObjects/TransactionDetailObject.php create mode 100644 app/Classes/Modules/Transactions/DataTransferObjects/TransactionObject.php create mode 100644 app/Classes/Modules/Transactions/Processors/CreateInvoiceTransactionProcessor.php create mode 100644 app/Classes/Modules/Transactions/Services/ChecksIfTransactionBillNumberExists.php create mode 100644 app/Classes/Modules/Transactions/Services/CreatesTransaction.php create mode 100644 app/Classes/Modules/Transactions/Services/CreatesTransactionDetail.php create mode 100644 app/Classes/Modules/Transactions/Services/DeletesTransactionDetails.php create mode 100644 app/Classes/Modules/Transactions/Services/FetchesTransaction.php create mode 100644 app/Classes/Modules/Transactions/Services/FetchesTransactionDetail.php create mode 100644 app/Classes/Modules/Transactions/Services/GeneratesTransactionBillNumber.php create mode 100644 app/Classes/Modules/Transactions/Services/ListsTransactions.php create mode 100644 app/Classes/Modules/Transactions/Services/UpdatesTransaction.php create mode 100644 app/Classes/Modules/Transactions/Services/UpdatesTransactionStatus.php create mode 100644 app/Classes/Modules/Transactions/Standards/Rules/CanCreateTransaction.php create mode 100644 app/Classes/Modules/Transactions/Standards/Rules/CanCreateTransactionDetail.php create mode 100644 app/Classes/Modules/Transactions/Standards/Validators/TransactionDetailValidation.php create mode 100644 app/Classes/Modules/Transactions/Standards/Validators/TransactionValidation.php create mode 100644 app/Classes/ValueObjects/Constants/PaymentMethodType.php create mode 100644 app/Classes/ValueObjects/Constants/TransactionStatus.php create mode 100644 app/Classes/ValueObjects/Constants/TransactionType.php create mode 100644 app/Http/Controllers/Currencies/CreateCurrencyController.php create mode 100644 app/Http/Controllers/Currencies/DeleteCurrencyController.php create mode 100644 app/Http/Controllers/Currencies/FetchSystemPrimaryCurrencyController.php create mode 100644 app/Http/Controllers/Currencies/ListCurrencyController.php create mode 100644 app/Http/Controllers/Currencies/RateCalculateCurrencyController.php create mode 100644 app/Http/Controllers/Currencies/Rates/CalculateRateController.php create mode 100644 app/Http/Controllers/Currencies/Rates/CreateRateController.php create mode 100644 app/Http/Controllers/Currencies/Rates/DeleteRateController.php create mode 100644 app/Http/Controllers/Currencies/Rates/FetchRateController.php create mode 100644 app/Http/Controllers/Currencies/Rates/ListRatesController.php create mode 100644 app/Http/Controllers/Currencies/Rates/UpdateRateController.php create mode 100644 app/Http/Controllers/Receipts/CreateReceiptController.php create mode 100644 app/Http/Controllers/Transactions/CreateMakePaymentPOTransactionController.php create mode 100644 app/Http/Controllers/Transactions/CreatePaymentProofDocumentController.php create mode 100644 app/Http/Controllers/Transactions/CreatePurchaseOrderTransactionController.php create mode 100644 app/Http/Controllers/Transactions/CreateSupplierTransactionController.php create mode 100644 app/Http/Controllers/Transactions/CreateTransactionController.php create mode 100644 app/Http/Controllers/Transactions/ListTransactionsController.php create mode 100644 app/Http/Controllers/Transactions/SuspendTransactionController.php create mode 100644 app/Http/Resources/CurrencyConversionResource.php create mode 100644 app/Http/Resources/CurrencyRateResource.php create mode 100644 app/Http/Resources/CurrencyResource.php create mode 100644 app/Http/Resources/RateCalculateCurrencyResource.php create mode 100644 app/Http/Resources/ReceiptDetailResource.php create mode 100644 app/Http/Resources/ReceiptResource.php create mode 100644 app/Http/Resources/TransactionDetailResource.php create mode 100644 app/Http/Resources/TransactionResource.php create mode 100644 app/Models/CurrencyLog.php create mode 100644 app/Models/CurrencyRate.php create mode 100644 app/Models/CurrencyRateLog.php create mode 100644 app/Models/Receipt.php create mode 100644 app/Models/ReceiptDetail.php create mode 100644 app/Models/Transaction.php create mode 100644 app/Models/TransactionDetail.php create mode 100644 routes/currency.php create mode 100644 routes/receipt.php create mode 100644 routes/transaction.php diff --git a/app/Classes/Modules/Currencies/ControllersLogic/CreateCurrencyLogic.php b/app/Classes/Modules/Currencies/ControllersLogic/CreateCurrencyLogic.php new file mode 100644 index 00000000..6fc8c43c --- /dev/null +++ b/app/Classes/Modules/Currencies/ControllersLogic/CreateCurrencyLogic.php @@ -0,0 +1,108 @@ + 'Create Currency', + 'message' => 'You have successfully created a new Currency' + ]; + } + + /** @var FetchesCountry */ + private $fetchesCountry; + + /** @var FetchesCurrency */ + private $fetchesCurrency; + + /** @var CreatesCountry */ + private $createsCountry; + + /** @var CanCreateCurrency */ + private $canCreateCurrency; + + /** @var CreatesCurrency */ + private $createsCurrency; + + /** @var CreatesCurrencyLog */ + private $createsCurrencyLog; + + /** + * CreateCurrencyLogic constructor. + * @param FetchesCountry $fetchesCountry + * @param FetchesCurrency $fetchesCurrency + * @param CreatesCountry $createsCountry + * @param CanCreateCurrency $canCreateCurrency + * @param CreatesCurrency $createsCurrency + * @param CreatesCurrencyLog $createsCurrencyLog + */ + public function __construct(FetchesCountry $fetchesCountry, FetchesCurrency $fetchesCurrency, CreatesCountry $createsCountry, CanCreateCurrency $canCreateCurrency, CreatesCurrency $createsCurrency, CreatesCurrencyLog $createsCurrencyLog) + { + $this->fetchesCountry = $fetchesCountry; + $this->fetchesCurrency = $fetchesCurrency; + $this->createsCountry = $createsCountry; + $this->canCreateCurrency = $canCreateCurrency; + $this->createsCurrency = $createsCurrency; + $this->createsCurrencyLog = $createsCurrencyLog; + } + + /** + * @param Request $request + * @return JsonResponse + * @throws MalformedRequestException + * @throws ResourceConflictException + * @throws \App\Classes\Exceptions\AccessForbiddenException + * @throws \App\Classes\Exceptions\RequestValidationException + */ + public function logic(Request $request) : JsonResponse + { + + $countryObject = Country($request->input('country_short_code')); + + /** @var Country $country */ + $country = $this->createsCountry->execute(new CountryObject($countryObject)); + + $currencyInfo = $countryObject->getCurrency(); + $currencyObject = new CurrencyObject($currencyInfo['iso_4217_name'], $currencyInfo['iso_4217_code']); + + $this->canCreateCurrency->passes($currencyObject); + + try { + $this->fetchesCurrency->execute(['country_id' => $country->id, 'short_code' => $currencyObject->getShortCode()]); + throw new ResourceConflictException('Duplicated Currency. This currency already exists in the system'); + } catch (ResourceNotFoundException $exception){ + /** @var Currency $currency */ + $currency = $this->createsCurrency->execute($country, $currencyObject); + $this->createsCurrencyLog->execute($currency); + } + + return $this->resourceResponse(new CurrencyResource($currency)); + + } +} \ No newline at end of file diff --git a/app/Classes/Modules/Currencies/ControllersLogic/DeleteCurrencyLogic.php b/app/Classes/Modules/Currencies/ControllersLogic/DeleteCurrencyLogic.php new file mode 100644 index 00000000..ed8e3745 --- /dev/null +++ b/app/Classes/Modules/Currencies/ControllersLogic/DeleteCurrencyLogic.php @@ -0,0 +1,77 @@ + 'Delete Currency', + 'message' => 'You have successfully deleted the Currency' + ]; + } + + /** @var CanDeleteCurrency */ + private $canDeleteCurrency; + + /** @var DeletesCurrency */ + private $deletesCurrency; + + /** @var FetchesCurrency */ + private $fetchesCurrency; + + + /** + * DeleteCurrencyLogic constructor. + * @param CanDeleteCurrency $canDeleteCurrency + * @param DeletesCurrency $deletesCurrency + * @param FetchesCurrency $fetchesCurrency + */ + public function __construct( + CanDeleteCurrency $canDeleteCurrency, + DeletesCurrency $deletesCurrency, + FetchesCurrency $fetchesCurrency + ) + { + $this->canDeleteCurrency = $canDeleteCurrency; + $this->deletesCurrency = $deletesCurrency; + $this->fetchesCurrency = $fetchesCurrency; + } + + /** + * @param Request $request + * @return JsonResponse + * @throws \App\Classes\Exceptions\AccessForbiddenException + * @throws \App\Classes\Exceptions\MalformedRequestException + * @throws \App\Classes\Exceptions\RequestValidationException + */ + public function logic(Request $request) : JsonResponse + { + $this->canDeleteCurrency->passes(); + + $currency_query = $this->fetchesCurrency->execute(['id' => $request->route('id')]); + + $this->deletesCurrency->execute($currency_query); + + return $this->response([]); + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/Currencies/ControllersLogic/FetchSystemPrimaryCurrencyLogic.php b/app/Classes/Modules/Currencies/ControllersLogic/FetchSystemPrimaryCurrencyLogic.php new file mode 100644 index 00000000..b9c7a75b --- /dev/null +++ b/app/Classes/Modules/Currencies/ControllersLogic/FetchSystemPrimaryCurrencyLogic.php @@ -0,0 +1,71 @@ + 'Fetch System\'s primary currency', + 'message' => 'You have successfully retrieved a Currency' + ]; + } + + + /** @var CanFetchCurrency */ + private $canFetchCurrency; + + /** @var FetchesConstant*/ + private $fetchesConstant; + + /** @var FetchesCurrency */ + private $fetchesCurrency; + + /** + * FetchSystemPrimaryCurrencyLogic constructor. + * @param CanFetchCurrency $canFetchCurrency + * @param FetchesConstant $fetchesConstant + * @param FetchesCurrency $fetchesCurrency + */ + public function __construct(CanFetchCurrency $canFetchCurrency, FetchesConstant $fetchesConstant, FetchesCurrency $fetchesCurrency) + { + $this->canFetchCurrency = $canFetchCurrency; + $this->fetchesConstant = $fetchesConstant; + $this->fetchesCurrency = $fetchesCurrency; + } + + /** + * @param Request $request + * @return JsonResponse + * @throws \App\Classes\Exceptions\AccessForbiddenException + * @throws \App\Classes\Exceptions\RequestValidationException + */ + public function logic(Request $request) : JsonResponse + { + + $this->canFetchCurrency->passes(); + + $constant = $this->fetchesConstant->execute(['reference' => SegmentConstants::SYSTEM_PRIMARY_CURRENCY]); + + /** @var Currency $currency */ + $currency = $this->fetchesCurrency->execute(['id' => $constant->detail->id]); + + return $this->resourceResponse(new CurrencyResource($currency)); + + } +} \ No newline at end of file diff --git a/app/Classes/Modules/Currencies/ControllersLogic/ListCurrencyLogic.php b/app/Classes/Modules/Currencies/ControllersLogic/ListCurrencyLogic.php new file mode 100644 index 00000000..e23f99db --- /dev/null +++ b/app/Classes/Modules/Currencies/ControllersLogic/ListCurrencyLogic.php @@ -0,0 +1,62 @@ + 'Retrieved Currency', + 'message' => 'You have successfully retrieved a list of Currency' + ]; + } + + /** @var CanListCurrency */ + private $canListCurrency; + + /** @var ListsCurrency */ + private $listsCurrency; + + /** + * ListCurrencyLogic constructor. + * @param CanListCurrency $canListCurrency + * @param ListsCurrency $listsCurrency + */ + public function __construct(CanListCurrency $canListCurrency, ListsCurrency $listsCurrency) + { + $this->canListCurrency = $canListCurrency; + $this->listsCurrency = $listsCurrency; + } + + + /** + * @param Request $request + * @return JsonResponse + * @throws \App\Classes\Exceptions\AccessForbiddenException + * @throws \App\Classes\Exceptions\MalformedRequestException + * @throws \App\Classes\Exceptions\RequestValidationException + */ + public function logic(Request $request) : JsonResponse + { + $this->canListCurrency->passes(); + + $query = $this->listsCurrency->execute($this->listsCurrency->deserializeFilters($request->input('filters'))); + + return $this->collectionResponse(CurrencyResource::collection($query)); + + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/Currencies/ControllersLogic/RateCalculateCurrencyLogic.php b/app/Classes/Modules/Currencies/ControllersLogic/RateCalculateCurrencyLogic.php new file mode 100644 index 00000000..ea3b0c64 --- /dev/null +++ b/app/Classes/Modules/Currencies/ControllersLogic/RateCalculateCurrencyLogic.php @@ -0,0 +1,60 @@ + 'Rate Calculated Currency', + 'message' => 'You have successfully rate calculated a Currency' + ]; + } + + /** @var FetchesCurrency */ + private $fetchesCurrency; + + /** @var RateCalculatesCurrency */ + private $rateCalculatesCurrency; + + /** + * @param FetchesCurrency $fetchesCurrency + * @param RateCalculatesCurrency $rateCalculatesCurrency + */ + public function __construct(FetchesCurrency $fetchesCurrency, RateCalculatesCurrency $rateCalculatesCurrency) + { + $this->fetchesCurrency = $fetchesCurrency; + $this->rateCalculatesCurrency = $rateCalculatesCurrency; + } + + /** + * @param Request $request + * @return JsonResponse + */ + public function logic(Request $request) : JsonResponse + { + + $amount = $request->input('amount'); + $conversion_currency = $this->fetchesCurrency->execute(['id' => $request->input('conversion_currency_id')]); + $convertable_currency = $this->fetchesCurrency->execute(['id' => $request->input('convertable_currency_id')]); + $this->rateCalculatesCurrency->execute($conversion_currency, $convertable_currency, $amount); + + return $this->resourceResponse(new RateCalculateCurrencyResource($conversion_currency, $convertable_currency, $amount)); + + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/Currencies/ControllersLogic/Rates/CalculateRateLogic.php b/app/Classes/Modules/Currencies/ControllersLogic/Rates/CalculateRateLogic.php new file mode 100644 index 00000000..023c5df9 --- /dev/null +++ b/app/Classes/Modules/Currencies/ControllersLogic/Rates/CalculateRateLogic.php @@ -0,0 +1,74 @@ + 'Calculated Currency Rate', + 'message' => 'You have successfully rate calculated a Currency' + ]; + } + + /** @var FetchesRate */ + private $fetchesRate; + + /** @var CalculatesRate */ + private $calculatesRate; + + /** + * @param FetchesRate $fetchesRate + * @param CalculatesRate $calculatesRate + */ + public function __construct(FetchesRate $fetchesRate, CalculatesRate $calculatesRate) + { + $this->fetchesRate = $fetchesRate; + $this->calculatesRate = $calculatesRate; + } + + /** + * @param Request $request + * @return JsonResponse + * @throws ErrorException + */ + public function logic(Request $request) : JsonResponse + { + try { + $amount = $request->input('amount'); + $conversion_currency_rate = $this->fetchesRate->execute( + [ + 'id' => $request->input('conversion_currency_rate_id'), + ] + ); + $convertable_currency_rate = $this->fetchesRate->execute( + [ + 'id' => $request->input('convertable_currency_rate_id') + ] + ); + + $convert_amount = $this->calculatesRate->execute($conversion_currency_rate, $convertable_currency_rate, $amount); + + return $this->resourceResponse(new CalculateCurrencyRateResource($conversion_currency_rate, $convertable_currency_rate, $convert_amount)); + + } catch (\Exception $exception){ + throw new ErrorException($exception->getMessage(), $exception->getCode()); + } + + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/Currencies/ControllersLogic/Rates/CreateRateLogic.php b/app/Classes/Modules/Currencies/ControllersLogic/Rates/CreateRateLogic.php new file mode 100644 index 00000000..3d697b8b --- /dev/null +++ b/app/Classes/Modules/Currencies/ControllersLogic/Rates/CreateRateLogic.php @@ -0,0 +1,96 @@ + 'Created Currency Rate', + 'message' => 'You have successfully created a new Currency Rate' + ]; + } + + /** @var CanCreateRate */ + private $canCreateRate; + + /** @var CreatesRate */ + private $createsRate; + + /** @var CreatesRateLog */ + private $createsRateLog; + + /** @var FetchesCurrency */ + private $fetchesCurrency; + + /** + * CreateRateLogic constructor. + * @param CanCreateRate $canCreateRate + * @param CreatesRate $createsRate + * @param CreatesRateLog $createsRateLog + * @param FetchesCurrency $fetchesCurrency + */ + public function __construct( + CanCreateRate $canCreateRate, + CreatesRate $createsRate, + CreatesRateLog $createsRateLog, + FetchesCurrency $fetchesCurrency + ) + { + $this->canCreateRate = $canCreateRate; + $this->createsRate = $createsRate; + $this->createsRateLog = $createsRateLog; + $this->fetchesCurrency = $fetchesCurrency; + } + + /** + * @param Request $request + * @return JsonResponse + * @throws ErrorException + */ + public function logic(Request $request) : JsonResponse + { + try { + DB::beginTransaction(); + + $currency_rate_object = new RateObject( + $request->input('currency_id'), + number_format( (float) $request->input('selling'), 5, '.', ''), + $request->input('payment_method_type') + ); + + $this->canCreateRate->passes($currency_rate_object); + + $currency_rate_query = $this->createsRate->execute($currency_rate_object); + + $this->createsRateLog->execute($currency_rate_query); + + DB::commit(); + + return $this->resourceResponse(new CurrencyRateResource($currency_rate_query)); + + } catch (\Exception $exception) { + throw new ErrorException($exception->getMessage(), $exception->getCode()); + } + + } +} \ No newline at end of file diff --git a/app/Classes/Modules/Currencies/ControllersLogic/Rates/DeleteRateLogic.php b/app/Classes/Modules/Currencies/ControllersLogic/Rates/DeleteRateLogic.php new file mode 100644 index 00000000..2cacb51d --- /dev/null +++ b/app/Classes/Modules/Currencies/ControllersLogic/Rates/DeleteRateLogic.php @@ -0,0 +1,82 @@ + 'Delete Currency Rate', + 'message' => 'You have successfully deleted the Currency Rate' + ]; + } + + /** @var CanDeleteRate */ + private $canDeleteRate; + + /** @var DeletesRate */ + private $deletesRate; + + /** @var FetchesRate */ + private $fetchesRate; + + + /** + * DeleteRateRateLogic constructor. + * @param CanDeleteRate $canDeleteRate + * @param DeletesRate $deletesRate + * @param FetchesRate $fetchesRate + */ + public function __construct( + CanDeleteRate $canDeleteRate, + DeletesRate $deletesRate, + FetchesRate $fetchesRate + ) + { + $this->canDeleteRate = $canDeleteRate; + $this->deletesRate = $deletesRate; + $this->fetchesRate = $fetchesRate; + } + + /** + * @param Request $request + * @return JsonResponse + * @throws ErrorException + */ + public function logic(Request $request) : JsonResponse + { + try { + DB::beginTransaction(); + + $currency_rate = $this->fetchesRate->execute(['id' => $request->route('id')]); + $this->canDeleteRate->passes(); + $this->deletesRate->execute($currency_rate); + + DB::commit(); + + return $this->resourceResponse(new CurrencyRateResource($currency_rate)); + + } catch (\Exception $exception){ + throw new ErrorException($exception->getMessage(), $exception->getCode()); + } + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/Currencies/ControllersLogic/Rates/FetchRateLogic.php b/app/Classes/Modules/Currencies/ControllersLogic/Rates/FetchRateLogic.php new file mode 100644 index 00000000..e691885e --- /dev/null +++ b/app/Classes/Modules/Currencies/ControllersLogic/Rates/FetchRateLogic.php @@ -0,0 +1,66 @@ + 'Retrieved Currency Rate', + 'message' => 'You have successfully retrieved a Currency Rate' + ]; + } + + /** @var CanFetchRate */ + private $canFetchRate; + + /** @var FetchesRate */ + private $fetchesRate; + + /** + * FetchRateControllersLogic constructor. + * @param CanFetchRate $canFetchRate + * @param FetchesRate $fetchesRate + */ + public function __construct(CanFetchRate $canFetchRate, FetchesRate $fetchesRate) + { + $this->canFetchRate = $canFetchRate; + $this->fetchesRate = $fetchesRate; + } + + + /** + * @param Request $request + * @return JsonResponse + * @throws ErrorException + */ + public function logic(Request $request) : JsonResponse + { + try { + + $this->canFetchRate->passes(); + + $query = $this->fetchesRate->execute(['id' => $request->route('id')]); + + return $this->resourceResponse(new CurrencyRateResource($query)); + + } catch (\Exception $exception){ + throw new ErrorException($exception->getMessage(), $exception->getCode()); + } + + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/Currencies/ControllersLogic/Rates/ListRatesLogic.php b/app/Classes/Modules/Currencies/ControllersLogic/Rates/ListRatesLogic.php new file mode 100644 index 00000000..c62ec605 --- /dev/null +++ b/app/Classes/Modules/Currencies/ControllersLogic/Rates/ListRatesLogic.php @@ -0,0 +1,70 @@ + 'Retrieved Currency Rate', + 'message' => 'You have successfully retrieved a list of Currency Rate' + ]; + } + + /** @var CanListRates */ + private $canListRates; + + /** @var ListsRates */ + private $listsRates; + + /** + * ListRatesLogic constructor. + * @param CanListRates $canListRates + * @param ListsRates $listsRates + */ + public function __construct(CanListRates $canListRates, ListsRates $listsRates) + { + $this->canListRates = $canListRates; + $this->listsRates = $listsRates; + } + + + /** + * @param Request $request + * @return JsonResponse + * @throws ErrorException + */ + public function logic(Request $request) : JsonResponse + { + try { + $this->canListRates->passes(); + + $query = $this->listsRates->execute( + [ + 'currency_id' => $request->input('currency_id'), + 'payment_method_type' => $request->input('payment_method_type') + ] + ); + + return $this->collectionResponse(CurrencyRateResource::collection($query)); + + } catch (\Exception $exception){ + throw new ErrorException($exception->getMessage(), $exception->getCode()); + } + + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/Currencies/ControllersLogic/Rates/UpdateRateLogic.php b/app/Classes/Modules/Currencies/ControllersLogic/Rates/UpdateRateLogic.php new file mode 100644 index 00000000..8aa61056 --- /dev/null +++ b/app/Classes/Modules/Currencies/ControllersLogic/Rates/UpdateRateLogic.php @@ -0,0 +1,97 @@ +canUpdateRate = $canUpdateRate; + $this->updatesRate = $updatesRate; + $this->createsRateLog = $createsRateLog; + $this->fetchesRate = $fetchesRate; + } + + /** + * @param Request $request + * @return JsonResponse + * @throws ErrorException + */ + public function logic(Request $request) : JsonResponse + { + try { + DB::beginTransaction(); + + $currency_rate_query = $this->fetchesRate->execute(['id' => $request->route('id')]); + + $currency_object_object = new RateObject( + $currency_rate_query->currency_id, + $request->input('selling', $currency_rate_query->selling), + $currency_rate_query->payment_method_type + ); + + $this->canUpdateRate->passes($currency_object_object); + $currency_rate_query = $this->updatesRate->execute($currency_rate_query, $currency_object_object); + + $this->createsRateLog->execute($currency_rate_query); + + DB::commit(); + + return $this->resourceResponse(new CurrencyRateResource($currency_rate_query)); + + } catch (\Exception $exception){ + throw new ErrorException($exception->getMessage(), $exception->getCode()); + } + } + + /** + * @return array + */ + protected function notification():array { + return [ + 'title' => 'Updated Currency Rate', + 'message' => 'You have successfully updated the Currency Rate' + ]; + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/Currencies/DataTransferObjects/CurrencyConversionObject.php b/app/Classes/Modules/Currencies/DataTransferObjects/CurrencyConversionObject.php new file mode 100644 index 00000000..c4e91b1e --- /dev/null +++ b/app/Classes/Modules/Currencies/DataTransferObjects/CurrencyConversionObject.php @@ -0,0 +1,86 @@ +amount = $amount; + $this->currencyId = $currencyId; + $this->serviceId = $serviceId; + $this->type = $type; + $this->paymentMethod = $paymentMethod; + } + + /** + * @return float + */ + public function getAmount(): float + { + return $this->amount; + } + + /** + * @return int + */ + public function getCurrencyId(): int + { + return $this->currencyId; + } + + /** + * @return int + */ + public function getServiceId(): int + { + return $this->serviceId; + } + + /** + * @return int + */ + public function getType(): int + { + return $this->type; + } + + /** + * @return int|null + */ + public function getPaymentMethod(): ?int + { + return $this->paymentMethod; + } + + + + +} \ No newline at end of file diff --git a/app/Classes/Modules/Currencies/DataTransferObjects/RateObject.php b/app/Classes/Modules/Currencies/DataTransferObjects/RateObject.php new file mode 100644 index 00000000..cde9dea9 --- /dev/null +++ b/app/Classes/Modules/Currencies/DataTransferObjects/RateObject.php @@ -0,0 +1,45 @@ +selling = $selling; + $this->payment_method_type = $payment_method_type; + } + + /** + * @return array + */ + public function getSelling(): array + { + return $this->selling; + } + + /** + * @return int + */ + public function getPaymentMethodType(): int + { + return PaymentMethodType::PAYMENT_METHODS[$this->payment_method_type]; + } + + +} \ No newline at end of file diff --git a/app/Classes/Modules/Currencies/Services/CreatesCurrencyLog.php b/app/Classes/Modules/Currencies/Services/CreatesCurrencyLog.php new file mode 100644 index 00000000..cf2541c5 --- /dev/null +++ b/app/Classes/Modules/Currencies/Services/CreatesCurrencyLog.php @@ -0,0 +1,23 @@ +currency_id = $object->id; + $model->created_by = Auth()->user()->id; + return $this->handler($model); + + } +} \ No newline at end of file diff --git a/app/Classes/Modules/Currencies/Services/DeletesCurrency.php b/app/Classes/Modules/Currencies/Services/DeletesCurrency.php new file mode 100644 index 00000000..3e4dd087 --- /dev/null +++ b/app/Classes/Modules/Currencies/Services/DeletesCurrency.php @@ -0,0 +1,19 @@ +handler($model); + } +} \ No newline at end of file diff --git a/app/Classes/Modules/Currencies/Services/ListsCurrency.php b/app/Classes/Modules/Currencies/Services/ListsCurrency.php new file mode 100644 index 00000000..8f5857c2 --- /dev/null +++ b/app/Classes/Modules/Currencies/Services/ListsCurrency.php @@ -0,0 +1,33 @@ +repository = $repository; + } + + + /** + * @return Builder + */ + function getRepository(): Builder + { + return $this->repository->newQuery(); + } +} \ No newline at end of file diff --git a/app/Classes/Modules/Currencies/Services/RateCalculatesCurrency.php b/app/Classes/Modules/Currencies/Services/RateCalculatesCurrency.php new file mode 100644 index 00000000..e51f3338 --- /dev/null +++ b/app/Classes/Modules/Currencies/Services/RateCalculatesCurrency.php @@ -0,0 +1,20 @@ +selling / $convertable_currency->selling) * $amount; + } + + public function execute_rate(Currency $conversion_currency, Currency $convertable_currency) + { + return $convert_rate = ($conversion_currency->selling / $convertable_currency->selling); + } +} \ No newline at end of file diff --git a/app/Classes/Modules/Currencies/Services/Rates/CalculatesRate.php b/app/Classes/Modules/Currencies/Services/Rates/CalculatesRate.php new file mode 100644 index 00000000..0751db76 --- /dev/null +++ b/app/Classes/Modules/Currencies/Services/Rates/CalculatesRate.php @@ -0,0 +1,20 @@ +selling / $convertable_currency_rate->selling) * $amount; + } + + public function execute_rate(CurrencyRate $conversion_currency_rate, CurrencyRate $convertable_currency_rate) + { + return $convert_rate = ($conversion_currency_rate->selling / $convertable_currency_rate->selling); + } +} \ No newline at end of file diff --git a/app/Classes/Modules/Currencies/Services/Rates/CreatesRate.php b/app/Classes/Modules/Currencies/Services/Rates/CreatesRate.php new file mode 100644 index 00000000..dce10b28 --- /dev/null +++ b/app/Classes/Modules/Currencies/Services/Rates/CreatesRate.php @@ -0,0 +1,29 @@ +selling = $object->getSelling(); + $model->payment_method_type = $object->getPaymentMethodType(); + $model->service_id = $object->getServiceId(); + + return $this->handler($currency->rates(), $model); + } +} \ No newline at end of file diff --git a/app/Classes/Modules/Currencies/Services/Rates/CreatesRateLog.php b/app/Classes/Modules/Currencies/Services/Rates/CreatesRateLog.php new file mode 100644 index 00000000..b8bf8275 --- /dev/null +++ b/app/Classes/Modules/Currencies/Services/Rates/CreatesRateLog.php @@ -0,0 +1,24 @@ +currency_rate_id = $object->id; + $model->selling = $object->selling; + $model->created_by = \Auth::user()->id; + return $this->handler($model); + + } +} \ No newline at end of file diff --git a/app/Classes/Modules/Currencies/Services/Rates/CreatesRates.php b/app/Classes/Modules/Currencies/Services/Rates/CreatesRates.php new file mode 100644 index 00000000..f28cd97f --- /dev/null +++ b/app/Classes/Modules/Currencies/Services/Rates/CreatesRates.php @@ -0,0 +1,24 @@ +update($rates)->save(); + } +} \ No newline at end of file diff --git a/app/Classes/Modules/Currencies/Services/Rates/DeletesRate.php b/app/Classes/Modules/Currencies/Services/Rates/DeletesRate.php new file mode 100644 index 00000000..30437c7e --- /dev/null +++ b/app/Classes/Modules/Currencies/Services/Rates/DeletesRate.php @@ -0,0 +1,19 @@ +handler($model); + } +} \ No newline at end of file diff --git a/app/Classes/Modules/Currencies/Services/Rates/FetchesRate.php b/app/Classes/Modules/Currencies/Services/Rates/FetchesRate.php new file mode 100644 index 00000000..f8c2a4cd --- /dev/null +++ b/app/Classes/Modules/Currencies/Services/Rates/FetchesRate.php @@ -0,0 +1,33 @@ +repository = $repository; + } + + + /** + * @return Builder + */ + public function getRepository(): Builder + { + return $this->repository->newQuery(); + } +} \ No newline at end of file diff --git a/app/Classes/Modules/Currencies/Services/Rates/ListsRates.php b/app/Classes/Modules/Currencies/Services/Rates/ListsRates.php new file mode 100644 index 00000000..b7d4579c --- /dev/null +++ b/app/Classes/Modules/Currencies/Services/Rates/ListsRates.php @@ -0,0 +1,33 @@ +repository = $repository; + } + + + /** + * @return Builder + */ + function getRepository(): Builder + { + return $this->repository->newQuery(); + } +} \ No newline at end of file diff --git a/app/Classes/Modules/Currencies/Services/Rates/UpdatesRate.php b/app/Classes/Modules/Currencies/Services/Rates/UpdatesRate.php new file mode 100644 index 00000000..f38f202a --- /dev/null +++ b/app/Classes/Modules/Currencies/Services/Rates/UpdatesRate.php @@ -0,0 +1,24 @@ +selling = $object->getSelling(); + + return $this->handler($model); + } +} \ No newline at end of file diff --git a/app/Classes/Modules/Currencies/Standards/Rules/CanCreateCurrency.php b/app/Classes/Modules/Currencies/Standards/Rules/CanCreateCurrency.php new file mode 100644 index 00000000..873e03ce --- /dev/null +++ b/app/Classes/Modules/Currencies/Standards/Rules/CanCreateCurrency.php @@ -0,0 +1,51 @@ +currencyValidation = $currencyValidation; + } + + /** + * @return bool + */ + protected function authorized(): bool + { + // TODO Set Authorization rules + return true; + } + + /** + * @param CurrencyObject $object + * @return bool + * @throws \App\Classes\Exceptions\RequestValidationException + */ + protected function validators($object): bool + { + return $this->currencyValidation->validate($object); + } + + /** + * @param CurrencyObject $object + * @return bool + */ + protected function criteria($object): bool + { + return true; + } +} \ No newline at end of file diff --git a/app/Classes/Modules/Currencies/Standards/Rules/CanDeleteCurrency.php b/app/Classes/Modules/Currencies/Standards/Rules/CanDeleteCurrency.php new file mode 100644 index 00000000..60820e79 --- /dev/null +++ b/app/Classes/Modules/Currencies/Standards/Rules/CanDeleteCurrency.php @@ -0,0 +1,39 @@ +currencyValidation = $currencyValidation; + } + + /** + * @return bool + */ + protected function authorized(): bool + { + // TODO Set Authorization rules + return true; + } + + /** + * @param CurrencyObject $object + * @return bool + * @throws \App\Classes\Exceptions\RequestValidationException + */ + protected function validators($object): bool + { + return $this->currencyValidation->validate($object); + } + + /** + * @param CurrencyObject $object + * @return bool + */ + protected function criteria($object): bool + { + return true; + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/Currencies/Standards/Rules/Rates/CanCreateRate.php b/app/Classes/Modules/Currencies/Standards/Rules/Rates/CanCreateRate.php new file mode 100644 index 00000000..842a548b --- /dev/null +++ b/app/Classes/Modules/Currencies/Standards/Rules/Rates/CanCreateRate.php @@ -0,0 +1,55 @@ +rateValidation = $rateValidation; + } + + /** + * @return bool + */ + protected function authorized(): bool + { + // TODO Set Authorization rules + if (!\Auth::user()->can('add currency_rate')) { + return false; + } + + return true; + } + + /** + * @param RateObject $object + * @return bool + * @throws \App\Classes\Exceptions\RequestValidationException + */ + protected function validators($object): bool + { + return $this->rateValidation->validate($object, 'POST'); + } + + /** + * @param RateObject $object + * @return bool + */ + protected function criteria($object): bool + { + return true; + } +} \ No newline at end of file diff --git a/app/Classes/Modules/Currencies/Standards/Rules/Rates/CanDeleteRate.php b/app/Classes/Modules/Currencies/Standards/Rules/Rates/CanDeleteRate.php new file mode 100644 index 00000000..4ebefb9e --- /dev/null +++ b/app/Classes/Modules/Currencies/Standards/Rules/Rates/CanDeleteRate.php @@ -0,0 +1,45 @@ +can('delete currency_rate')) { + return false; + } + + return true; + + } + + /** + * @param RateObject $object + * @return bool + */ + protected function validators($object): bool + { + return true; + + } + + + /** + * @param RateObject $object + * @return bool + */ + protected function criteria($object): bool + { + return true; + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/Currencies/Standards/Rules/Rates/CanFetchRate.php b/app/Classes/Modules/Currencies/Standards/Rules/Rates/CanFetchRate.php new file mode 100644 index 00000000..4006e36f --- /dev/null +++ b/app/Classes/Modules/Currencies/Standards/Rules/Rates/CanFetchRate.php @@ -0,0 +1,43 @@ +can('view currency_rate')) { + return false; + } + + return true; + + } + + /** + * @param CurrencyObject $object + * @return bool + */ + protected function validators($object): bool + { + return true; + + } + + + /** + * @param CurrencyObject $object + * @return bool + */ + protected function criteria($object): bool + { + return true; + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/Currencies/Standards/Rules/Rates/CanUpdateRate.php b/app/Classes/Modules/Currencies/Standards/Rules/Rates/CanUpdateRate.php new file mode 100644 index 00000000..59564725 --- /dev/null +++ b/app/Classes/Modules/Currencies/Standards/Rules/Rates/CanUpdateRate.php @@ -0,0 +1,58 @@ +rateValidation = $rateValidation; + } + + /** + * @return bool + */ + protected function authorized(): bool + { + // TODO Set Authorization rules + + if (!\Auth::user()->can('view currency_rate')) { + return false; + } + + return true; + } + + /** + * @param RateObject $object + * @return bool + * @throws \App\Classes\Exceptions\RequestValidationException + */ + protected function validators($object): bool + { + return $this->rateValidation->validate($object, 'PUT'); + } + + /** + * @param RateObject $object + * @return bool + */ + protected function criteria($object): bool + { + return true; + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/Currencies/Standards/Validators/CurrencyValidation.php b/app/Classes/Modules/Currencies/Standards/Validators/CurrencyValidation.php new file mode 100644 index 00000000..fd3b8ce5 --- /dev/null +++ b/app/Classes/Modules/Currencies/Standards/Validators/CurrencyValidation.php @@ -0,0 +1,40 @@ + $object->getName(), + 'short_code' => $object->getShortCode() + ]; + } + + /** + * @return array + */ + protected function rules(): array + { + return [ + 'name' => 'required', + 'short_code' => 'required' + ]; + } + + /** + * @return array + */ + protected function messages(): array + { + return []; + } +} \ No newline at end of file diff --git a/app/Classes/Modules/Currencies/Standards/Validators/RateValidation.php b/app/Classes/Modules/Currencies/Standards/Validators/RateValidation.php new file mode 100644 index 00000000..3372c28f --- /dev/null +++ b/app/Classes/Modules/Currencies/Standards/Validators/RateValidation.php @@ -0,0 +1,45 @@ + $object->getCurrencyId(), + 'selling' => $object->getSelling(), + 'payment_method_type' => $object->getPaymentMethodType(), + ]; + + return $data; + } + + /** + * @param null|string $type + * @return array + */ + protected function rules(?string $type = 'POST'): array { + return [ + 'currency_id' => $type == 'POST' ? 'required' : '', + 'selling' => 'required', + 'payment_method_type' => 'required', + ]; + } + + /** + * @return array + */ + protected function messages(): array { + return []; + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/Receipts/ControllersLogic/CreateReceiptLogic.php b/app/Classes/Modules/Receipts/ControllersLogic/CreateReceiptLogic.php new file mode 100644 index 00000000..6c9e935f --- /dev/null +++ b/app/Classes/Modules/Receipts/ControllersLogic/CreateReceiptLogic.php @@ -0,0 +1,158 @@ + 'Created Receipt', + 'message' => 'You have successfully created a receipt' + ]; + } + + + /** @var GeneratesReceiptBillNo */ + private $generatesReceiptBillNo; + + /** @var CanCreateReceipt */ + private $canCreateReceipt; + + private $fetchesCurrency; + + private $rateCalculatesCurrency; + + private $fetchesCompany; + + private $createsReceipt; + + private $canCreateReceiptDetail; + + private $createsReceiptDetail; + + private $fetchesTransaction; + + /** + * CreateWalletLogic constructor. + * @param GeneratesReceiptBillNo $generatesReceiptBillNo + * @param CanCreateReceipt $canCreateReceipt + * @param FetchesCurrency $fetchesCurrency + * @param RateCalculatesCurrency $rateCalculatesCurrency + * @param FetchesCompany $fetchesCompany + * @param CreatesReceipt $createsReceipt + * @param CanCreateReceiptDetail $canCreateReceiptDetail + * @param CreatesReceiptDetail $createsReceiptDetail + * @param FetchesTransaction $fetchesTransaction + */ + public function __construct( + GeneratesReceiptBillNo $generatesReceiptBillNo, CanCreateReceipt $canCreateReceipt, + FetchesCurrency $fetchesCurrency,RateCalculatesCurrency $rateCalculatesCurrency, FetchesCompany $fetchesCompany, + CreatesReceipt $createsReceipt, + CanCreateReceiptDetail $canCreateReceiptDetail, CreatesReceiptDetail $createsReceiptDetail, + FetchesTransaction $fetchesTransaction + ){ + $this->generatesReceiptBillNo = $generatesReceiptBillNo; + $this->canCreateReceipt = $canCreateReceipt; + $this->fetchesCurrency = $fetchesCurrency; + $this->rateCalculatesCurrency = $rateCalculatesCurrency; + $this->fetchesCompany = $fetchesCompany; + $this->createsReceipt =$createsReceipt; + $this->canCreateReceiptDetail =$canCreateReceiptDetail; + $this->createsReceiptDetail = $createsReceiptDetail; + $this->fetchesTransaction = $fetchesTransaction; + } + + /** + * @param Request $request + * @return JsonResponse + * @throws ErrorException + */ + public function logic(Request $request) : JsonResponse + { + try { + + DB::beginTransaction(); + $json_array = json_decode($request->getContent(), true); + $company = $this->fetchesCompany->execute(['id' => $json_array['company_id']]); + + $conversion_currency = $this->fetchesCurrency->execute(['id' => $json_array['currency_id']]); + $convertable_currency = $this->fetchesCurrency->execute(['id' => 1]);//MYR + $convert_amount = $this->rateCalculatesCurrency->execute($conversion_currency, $convertable_currency, $json_array['amount']); + $convert_rate = $this->rateCalculatesCurrency->execute_rate($conversion_currency, $convertable_currency); + + $object = new ReceiptObject( + $this->generatesReceiptBillNo->execute(),$json_array['trans_type1'],$json_array['trans_type2'], + number_format( (float) $convert_amount, 5, '.', ''), 1 , number_format( (float) $json_array['amount'], 5, '.', ''), + $json_array['currency_id'],number_format( (float) $convert_rate, 5, '.', ''), + $json_array['dt_transaction'],1,$request->route('id'), + $company->id + ); + + + $this->canCreateReceipt->passes($object); + + $receipt = $this->createsReceipt->execute($object); + + $receipt_array = new ReceiptResource($receipt); + $receipt_detail_array = array(); + + foreach ($json_array['receipt_detail'] as $key => $value) { + + $transaction_inv = $this->fetchesTransaction->execute(['id' => $value['transaction_id']]); + + $object_detail = new ReceiptDetailObject( + $json_array['trans_type1'],$json_array['trans_type2'], + $transaction_inv->id,$receipt->id, + number_format( (float) $convert_amount, 5, '.', ''), number_format( (float) $json_array['amount'], 5, '.', '') + ); + $this->canCreateReceiptDetail->passes($object_detail); + $transaction_detail = $this->createsReceiptDetail->execute($object_detail); + //array_push($stack, "apple", "raspberry"); + $receipt_detail_resource= new ReceiptDetailResource($transaction_detail); + $receipt_detail_array[]= $receipt_detail_resource->toArray($request); + + } + + //$transaction_array['transaction_detail']= $transaction_detail_array; + //print_r($transaction_detail_array); + //dd($transaction_detail_array); + DB::commit(); + + return $this->resourceResponse($receipt_array); + //return $this->resourceResponse($json_array); + + } catch (\Exception $exception) { + throw new ErrorException($exception->getMessage(), $exception->getCode()); + } + + } +} \ No newline at end of file diff --git a/app/Classes/Modules/Receipts/DataTransferObjects/ReceiptDetailObject.php b/app/Classes/Modules/Receipts/DataTransferObjects/ReceiptDetailObject.php new file mode 100644 index 00000000..4b234773 --- /dev/null +++ b/app/Classes/Modules/Receipts/DataTransferObjects/ReceiptDetailObject.php @@ -0,0 +1,81 @@ +trans_type1= $trans_type1; + $this->trans_type2 = $trans_type2; + $this->transaction_id = $transaction_id; + $this->receipt_id = $receipt_id; + $this->price = $price; + $this->amount = $amount; + + } + + + /** + * @return string + */ + public function getTransType1(): string + { + return $this->trans_type1; + } + + /** + * @return string + */ + public function getTransType2(): string + { + return $this->trans_type2; + } + + /** + * @return int + */ + public function getTransactionId(): int + { + return $this->transaction_id; + } + + /** + * @return int + */ + public function getReceiptId(): int + { + return $this->receipt_id; + } + + public function getPrice(): float + { + return $this->price; + } + + public function getAmount(): float + { + return $this->amount; + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/Receipts/DataTransferObjects/ReceiptObject.php b/app/Classes/Modules/Receipts/DataTransferObjects/ReceiptObject.php new file mode 100644 index 00000000..91107fc3 --- /dev/null +++ b/app/Classes/Modules/Receipts/DataTransferObjects/ReceiptObject.php @@ -0,0 +1,150 @@ + $this->id, + 'trans_type1' => $this->trans_type1, + 'trans_type2' => $this->trans_type2, + 'bill_no' => (int) $this->bill_no, + 'amount' => (double) $this->amount, + 'currency_id' => (int) $this->currency_id, + 'original_amount' => (double) $this->original_amount, + 'original_currency_id' => (int) $this->original_currency_id, + 'currency_rate' => (double) $this->currency_rate, + 'dt_transaction' => $this->dt_transaction, + 'status' => (int) $this->status, + 'booking_id' => (int) $this->booking_id, + 'company_id' => (int) $this->company_id + ]; + */ + private $trans_type1; + + private $trans_type2; + + private $bill_no; + + private $amount; + + private $currency_id; + + private $original_amount; + + private $original_currency_id; + + private $currency_rate; + + private $dt_transaction; + + private $status; + + private $booking_id; + + private $company_id; + + public function __construct( + int $bill_no,string $trans_type1,string $trans_type2, + float $amount, int $currency_id, int $original_amount, + int $original_currency_id, float $currency_rate, + string $dt_transaction,int $status,int $booking_id, + int $company_id + ){ + $this->bill_no = $bill_no; + $this->trans_type1= $trans_type1; + $this->trans_type2 = $trans_type2; + $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; + $this->dt_transaction = $dt_transaction; + $this->status = $status; + $this->booking_id = $booking_id; + $this->company_id = $company_id; + } + + + /** + * @return int + */ + public function getBillNo(): int + { + return $this->bill_no; + } + + /** + * @return string + */ + public function getTransType1(): string + { + return $this->trans_type1; + } + + /** + * @return string + */ + public function getTransType2(): string + { + return $this->trans_type2; + } + + + 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; + } + + /** + * @return string + */ + public function getDtTransaction(): string + { + return $this->dt_transaction; + } + + public function getStatus(): int + { + return $this->original_currency_id; + } + + public function getBookingId(): int + { + return $this->booking_id; + } + + public function getCompanyId(): int + { + return $this->company_id; + } +} \ No newline at end of file diff --git a/app/Classes/Modules/Receipts/Services/ChecksIfReceiptBillNoExists.php b/app/Classes/Modules/Receipts/Services/ChecksIfReceiptBillNoExists.php new file mode 100644 index 00000000..f175a1fd --- /dev/null +++ b/app/Classes/Modules/Receipts/Services/ChecksIfReceiptBillNoExists.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/Receipts/Services/CreatesReceipt.php b/app/Classes/Modules/Receipts/Services/CreatesReceipt.php new file mode 100644 index 00000000..c93d10d4 --- /dev/null +++ b/app/Classes/Modules/Receipts/Services/CreatesReceipt.php @@ -0,0 +1,35 @@ +bill_no = $object->getBillNo(); + $model->trans_type1 = $object->getTransType1(); + $model->trans_type2 = $object->getTransType2(); + $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(); + $model->dt_transaction = $object->getDtTransaction(); + $model->status = $object->getStatus(); + $model->booking_id = $object->getBookingId(); + $model->company_id = $object->getCompanyId(); + + + return $this->handler($model); + + } +} \ No newline at end of file diff --git a/app/Classes/Modules/Receipts/Services/CreatesReceiptDetail.php b/app/Classes/Modules/Receipts/Services/CreatesReceiptDetail.php new file mode 100644 index 00000000..dbee82eb --- /dev/null +++ b/app/Classes/Modules/Receipts/Services/CreatesReceiptDetail.php @@ -0,0 +1,29 @@ +trans_type1 = $object->getTransType1(); + $model->trans_type2 = $object->getTransType2(); + $model->transaction_id = $object->getTransactionId(); + $model->receipt_id = $object->getReceiptId(); + $model->price = $object->getPrice(); + $model->amount = $object->getAmount(); + + + return $this->handler($model); + + } +} \ No newline at end of file diff --git a/app/Classes/Modules/Receipts/Services/GeneratesReceiptBillNo.php b/app/Classes/Modules/Receipts/Services/GeneratesReceiptBillNo.php new file mode 100644 index 00000000..34e196a8 --- /dev/null +++ b/app/Classes/Modules/Receipts/Services/GeneratesReceiptBillNo.php @@ -0,0 +1,27 @@ +receiptBillNoExists = $receiptBillNoExists; + } + + + + public function execute(): int { + + $code = mt_rand(100000001, 999999999); + return !$this->receiptBillNoExists->execute($code) ? $code : self::execute(); + + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/Receipts/Standards/Rules/CanCreateReceipt.php b/app/Classes/Modules/Receipts/Standards/Rules/CanCreateReceipt.php new file mode 100644 index 00000000..ea6b4f02 --- /dev/null +++ b/app/Classes/Modules/Receipts/Standards/Rules/CanCreateReceipt.php @@ -0,0 +1,51 @@ +receiptValidation = $receiptValidation; + } + + + /** + * @return bool + */ + protected function authorized(): bool + { + // TODO Set Authorization rules + return true; + } + + /** + * @param ReceiptObject $object + * @return bool + * @throws \App\Classes\Exceptions\RequestValidationException + */ + protected function validators($object): bool + { + return $this->receiptValidation->validate($object); + } + + /** + * @param ReceiptObject $object + * @return bool + */ + protected function criteria($object): bool + { + return true; + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/Receipts/Standards/Rules/CanCreateReceiptDetail.php b/app/Classes/Modules/Receipts/Standards/Rules/CanCreateReceiptDetail.php new file mode 100644 index 00000000..71466752 --- /dev/null +++ b/app/Classes/Modules/Receipts/Standards/Rules/CanCreateReceiptDetail.php @@ -0,0 +1,51 @@ +receiptDetailValidation = $receiptDetailValidation; + } + + + /** + * @return bool + */ + protected function authorized(): bool + { + // TODO Set Authorization rules + return true; + } + + /** + * @param ReceiptDetailObject $object + * @return bool + * @throws \App\Classes\Exceptions\RequestValidationException + */ + protected function validators($object): bool + { + return $this->receiptDetailValidation->validate($object); + } + + /** + * @param ReceiptDetailObject $object + * @return bool + */ + protected function criteria($object): bool + { + return true; + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/Receipts/Standards/Validators/ReceiptDetailValidation.php b/app/Classes/Modules/Receipts/Standards/Validators/ReceiptDetailValidation.php new file mode 100644 index 00000000..8feac483 --- /dev/null +++ b/app/Classes/Modules/Receipts/Standards/Validators/ReceiptDetailValidation.php @@ -0,0 +1,58 @@ +bill_no = $bill_no; + $this->trans_type1= $trans_type1; + $this->trans_type2 = $trans_type2; + $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; + $this->dt_transaction = $dt_transaction; + $this->status = $status; + $this->booking_id = $booking_id; + $this->company_id = $company_id; + */ + protected function data($object): array + { + return [ + 'trans_type1' => $object->getTransType1(), + 'trans_type2' => $object->getTransType2(), + 'transaction_id' => $object->getTransactionId(), + 'receipt_id' => $object->getReceiptId(), + 'price'=>$object->getPrice(), + 'amount' => $object->getAmount() + ]; + } + + /** + * @return array + */ + protected function rules(): array + { + return [ + 'trans_type1' => 'required', + 'trans_type2' => 'required', + 'transaction_id' => 'required', + 'receipt_id' => 'required', + 'price'=>'required', + 'amount' => 'required' + ]; + } + + /** + * @return array + */ + protected function messages(): array + { + return []; + } +} \ No newline at end of file diff --git a/app/Classes/Modules/Receipts/Standards/Validators/ReceiptValidation.php b/app/Classes/Modules/Receipts/Standards/Validators/ReceiptValidation.php new file mode 100644 index 00000000..f0ab7bbe --- /dev/null +++ b/app/Classes/Modules/Receipts/Standards/Validators/ReceiptValidation.php @@ -0,0 +1,54 @@ + $object->getBillNo(), + 'trans_type1' => $object->getBillNo(), + 'trans_type2' => $object->getTransType2(), + 'amount' => $object->getAmount(), + 'currency_id' => $object->getCurrency(), + 'original_amount' => $object->getOriginalAmount(), + 'original_currency_id'=>$object->getOriginalCurrency(), + 'dt_transaction'=>$object->getDtTransaction(), + 'status'=>$object->getStatus(), + 'booking_id'=>$object->getBookingId(), + 'company_id'=>$object->getCompanyId() + ]; + } + + /** + * @return array + */ + protected function rules(): array + { + return [ + 'bill_no' => 'required', + 'trans_type1' => 'required', + 'trans_type2' => 'required', + 'amount' => 'required', + 'currency_id' => 'required', + 'original_amount' => 'required', + 'original_currency_id'=>'required', + 'dt_transaction'=>'required', + 'status'=>'required', + 'booking_id'=>'required', + 'company_id'=>'required' + ]; + } + + /** + * @return array + */ + protected function messages(): array + { + return []; + } +} \ No newline at end of file diff --git a/app/Classes/Modules/Transactions/ControllersLogic/CreateMakePaymentPOTransactionLogic.php b/app/Classes/Modules/Transactions/ControllersLogic/CreateMakePaymentPOTransactionLogic.php new file mode 100644 index 00000000..48616385 --- /dev/null +++ b/app/Classes/Modules/Transactions/ControllersLogic/CreateMakePaymentPOTransactionLogic.php @@ -0,0 +1,208 @@ + 'Created Transaction', + 'message' => 'You have successfully created a transaction' + ]; + } + + + /** @var GeneratesTransactionBillNumber */ + private $generatesTransactionBillNo; + + /** @var CanCreateTransaction */ + private $canCreateTransaction; + + private $fetchesCurrency; + + private $rateCalculatesCurrency; + + private $fetchesCompany; + + private $createsTransaction; + + private $canCreateTransactionDetail; + + private $createsTransactionDetail; + + private $fetchesTransaction; + + private $fetchesTransactionDetail; + + private $generatesReceiptBillNo; + + /** @var CanCreateReceipt */ + private $canCreateReceipt; + + private $createsReceipt; + + private $canCreateReceiptDetail; + + private $createsReceiptDetail; + + /** + * CreateWalletLogic constructor. + * @param GeneratesTransactionBillNumber $generatesTransactionBillNo + * @param CanCreateTransaction $canCreateTransaction + * @param FetchesCurrency $fetchesCurrency + * @param RateCalculatesCurrency $rateCalculatesCurrency + * @param FetchesCompany $fetchesCompany + * @param CreatesTransaction $createsTransaction + * @param CanCreateTransactionDetail $canCreateTransactionDetail + * @param CreatesTransactionDetail $createsTransactionDetail + * @param FetchesTransaction $fetchesTransaction + * @param FetchesTransactionDetail $fetchesTransactionDetail + * @param GeneratesReceiptBillNo $generatesReceiptBillNo + * @param CanCreateReceipt $canCreateReceipt + * @param CreatesReceipt $createsReceipt + * @param CanCreateReceiptDetail $canCreateReceiptDetail + * @param CreatesReceiptDetail $createsReceiptDetail + */ + public function __construct( + GeneratesTransactionBillNumber $generatesTransactionBillNo, CanCreateTransaction $canCreateTransaction, + FetchesCurrency $fetchesCurrency, RateCalculatesCurrency $rateCalculatesCurrency, FetchesCompany $fetchesCompany, + CreatesTransaction $createsTransaction, + CanCreateTransactionDetail $canCreateTransactionDetail, CreatesTransactionDetail $createsTransactionDetail, + FetchesTransaction $fetchesTransaction , FetchesTransactionDetail $fetchesTransactionDetail, + GeneratesReceiptBillNo $generatesReceiptBillNo, CanCreateReceipt $canCreateReceipt, + CreatesReceipt $createsReceipt, + CanCreateReceiptDetail $canCreateReceiptDetail, CreatesReceiptDetail $createsReceiptDetail + ){ + $this->generatesTransactionBillNo = $generatesTransactionBillNo; + $this->canCreateTransaction = $canCreateTransaction; + $this->fetchesCurrency = $fetchesCurrency; + $this->rateCalculatesCurrency = $rateCalculatesCurrency; + $this->fetchesCompany = $fetchesCompany; + $this->createsTransaction =$createsTransaction; + $this->canCreateTransactionDetail =$canCreateTransactionDetail; + $this->createsTransactionDetail = $createsTransactionDetail; + $this->fetchesTransaction = $fetchesTransaction; + $this->fetchesTransactionDetail = $fetchesTransactionDetail; + + $this->generatesReceiptBillNo = $generatesReceiptBillNo; + $this->canCreateReceipt = $canCreateReceipt; + $this->createsReceipt =$createsReceipt; + $this->canCreateReceiptDetail =$canCreateReceiptDetail; + $this->createsReceiptDetail = $createsReceiptDetail; + + } + + /** + * @param Request $request + * @return JsonResponse + * @throws ErrorException + */ + public function logic(Request $request) : JsonResponse + { + try { + + DB::beginTransaction(); + $json_array = json_decode($request->getContent(), true); + + $po_transaction = $this->fetchesTransaction->execute(['id' => $json_array['ref_po']]); + + $object = new TransactionObject( + $this->generatesTransactionBillNo->execute(),$po_transaction->trans_type1,'INV', + $po_transaction->amount, $po_transaction->currency_id , $po_transaction->original_amount, + $po_transaction->original_currency_id, $po_transaction->currency_rate , + $po_transaction->dt_transaction,1,$po_transaction->booking_id, + $po_transaction->company_id + ); + + $this->canCreateTransaction->passes($object); + $transaction = $this->createsTransaction->execute($object); + $transaction_array = new TransactionResource($transaction); + + $transaction_detail = $this->fetchesTransactionDetail->getRepository()->where('transaction_id', $json_array['ref_po'])->get(); + foreach ($transaction_detail as $key => $value) { + + $object_detail = new TransactionDetailObject( + $transaction->trans_type1,$transaction->trans_type2, + $transaction->id,$value->product_code,$value->product_name, + $value->qty,$value->price, $value->amount + ); + $this->canCreateTransactionDetail->passes($object_detail); + $transaction_detail = $this->createsTransactionDetail->execute($object_detail); + //array_push($stack, "apple", "raspberry"); + $transaction_detail_resource= new TransactionDetailResource($transaction_detail); + $transaction_detail_array[]= $transaction_detail_resource->toArray($request); + } + + + $object = new ReceiptObject( + $this->generatesReceiptBillNo->execute(),$transaction->trans_type1,"RECPT", + $po_transaction->amount, $po_transaction->currency_id , $po_transaction->original_amount, + $po_transaction->original_currency_id, $po_transaction->currency_rate , + $po_transaction->dt_transaction,1,$po_transaction->booking_id, + $po_transaction->company_id + ); + + + $this->canCreateReceipt->passes($object); + + $receipt = $this->createsReceipt->execute($object); + + + $object_detail = new ReceiptDetailObject( + $transaction->trans_type1,"RECPT", + $transaction->id,$receipt->id, + $transaction->amount, $transaction->amount + ); + $this->canCreateReceiptDetail->passes($object_detail); + $this->createsReceiptDetail->execute($object_detail); + + + DB::commit(); + + return $this->resourceResponse($transaction_array); + + + } catch (\Exception $exception) { + throw new ErrorException($exception->getMessage(), $exception->getCode()); + } + + } +} \ No newline at end of file diff --git a/app/Classes/Modules/Transactions/ControllersLogic/CreatePaymentProofDocumentLogic.php b/app/Classes/Modules/Transactions/ControllersLogic/CreatePaymentProofDocumentLogic.php new file mode 100644 index 00000000..111cd0db --- /dev/null +++ b/app/Classes/Modules/Transactions/ControllersLogic/CreatePaymentProofDocumentLogic.php @@ -0,0 +1,93 @@ + 'Payment Proof Document', + 'message' => 'You have successfully submitted your payment proof document' + ]; + } + + /** @var FetchesTransaction */ + private $fetchesTransaction; + + /** @var CreatesDocument */ + private $createsDocument; + + /** @var CreatesFiles */ + private $createsFile; + + /** @var UpdatesTransactionStatus */ + private $updatesTransactionStatus; + + /** @var CreateInvoiceTransactionProcessor */ + private $createInvoiceTransactionProcessor; + + /** + * CreatePaymentVerificationDocumentLogic constructor. + * @param FetchesTransaction $fetchesTransaction + * @param CreatesDocument $createsDocument + * @param CreatesFiles $createsFile + * @param UpdatesTransactionStatus $updatesTransactionStatus + */ + public function __construct(FetchesTransaction $fetchesTransaction, CreatesDocument $createsDocument, CreatesFiles $createsFile, UpdatesTransactionStatus $updatesTransactionStatus, CreateInvoiceTransactionProcessor $createInvoiceTransactionProcessor) + { + $this->fetchesTransaction = $fetchesTransaction; + $this->createsDocument = $createsDocument; + $this->createsFile = $createsFile; + $this->updatesTransactionStatus = $updatesTransactionStatus; + $this->createInvoiceTransactionProcessor = $createInvoiceTransactionProcessor; + } + + /** + * @param Request $request + * @return JsonResponse + * @throws \App\Classes\Exceptions\MalformedRequestException + */ + public function logic(Request $request) : JsonResponse + { + + $transaction = $this->fetchesTransaction->execute(['id' => $request->route('id')]); + + $object = new DocumentObject(DocumentType::CURRENCY_VENDOR_PAYMENT_PROOF, $request->input('files'), '', ApprovalStatus::APPROVED, 'china_bank_slip'); + + /** @var Document $document */ + $document = $this->createsDocument->execute($transaction, $object); + + $this->createsFile->execute($document, $object); + + $this->updatesTransactionStatus->execute($transaction, ApprovalStatus::COMPLETED); + + $this->createInvoiceTransactionProcessor->execute($transaction->booking); + + return $this->response([]); + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/Transactions/ControllersLogic/CreatePurchaseOrderTransactionLogic.php b/app/Classes/Modules/Transactions/ControllersLogic/CreatePurchaseOrderTransactionLogic.php new file mode 100644 index 00000000..25154301 --- /dev/null +++ b/app/Classes/Modules/Transactions/ControllersLogic/CreatePurchaseOrderTransactionLogic.php @@ -0,0 +1,121 @@ +fetchesBooking = $fetchesBooking; + $this->updatesTransactionStatus = $updatesTransactionStatus; + $this->createsTransaction = $createsTransaction; + $this->createsTransactionDetail = $createsTransactionDetail; + $this->updatesTransaction = $updatesTransaction; + $this->deletesTransactionDetails = $deletesTransactionDetails; + $this->generatesTransactionBillNumber = $generatesTransactionBillNumber; + } + + /** + * @return array + */ + protected function notification():array { + return [ + 'title' => 'Update Purchase Order', + 'message' => 'You have successfully updated you booking\'s purchase order' + ]; + } + + /** @var FetchesBooking */ + private $fetchesBooking; + + /** @var UpdatesTransactionStatus */ + private $updatesTransactionStatus; + + /** @var CreatesTransaction */ + private $createsTransaction; + + /** @var CreatesTransactionDetail */ + private $createsTransactionDetail; + + /** @var UpdatesTransaction */ + private $updatesTransaction; + + /** @var DeletesTransactionDetails */ + private $deletesTransactionDetails; + + /** @var GeneratesTransactionBillNumber */ + private $generatesTransactionBillNumber; + + + /** + * @param Request $request + * @return JsonResponse + * @throws \App\Classes\Exceptions\MalformedRequestException + */ + public function logic(Request $request) : JsonResponse + { + /** @var Booking $booking */ + $booking = $this->fetchesBooking->execute(['id' => $request->route('id')]); + + /** @var Transaction $transaction */ + $transaction = $booking->transactions()->where('type', TransactionType::PURCHASE_ORDER)->first(); + + $billNumber = $this->generatesTransactionBillNumber->execute('PO-'); + + $total = collect($request->input('products'))->sum(function($product){ + return $product['quantity'] * floatval(str_replace(',', '', $product['unit_price'])); + }); + + $object = new TransactionObject($billNumber, TransactionType::PURCHASE_ORDER, $booking->company->id, 1, + 1, PaymentMethodType::CASH, + $total, $total, $booking->fix_currency_id, $booking->fix_currency_id, + 1, 0, 0, null, ApprovalStatus::PENDING_SUBMISSION, $request->input('products')); + + !$transaction ? $transaction = $this->createsTransaction->execute($booking, $object) : $transaction = $this->updatesTransaction->execute($transaction, $object); + + $this->updatesTransactionStatus->execute($transaction, (float)number_format((float)$total , 2, '.', '') === (float)number_format((float)$booking->fix_amount, 2, '.', '') ? ApprovalStatus::PENDING_VERIFICATION : ApprovalStatus::PENDING_SUBMISSION); + + $this->deletesTransactionDetails->execute($transaction); + + foreach ($object->getDetails() as $product){ + $this->createsTransactionDetail->execute($transaction, $product); + } + + return $this->resourceResponse(new TransactionResource($transaction)); + + } + + + +} diff --git a/app/Classes/Modules/Transactions/ControllersLogic/CreateSupplierTransactionLogic.php b/app/Classes/Modules/Transactions/ControllersLogic/CreateSupplierTransactionLogic.php new file mode 100644 index 00000000..054513af --- /dev/null +++ b/app/Classes/Modules/Transactions/ControllersLogic/CreateSupplierTransactionLogic.php @@ -0,0 +1,132 @@ + 'Create Supplier Transactions', + 'message' => 'You have successfully created currency supplier transactions' + ]; + } + + /** @var FetchesCompany */ + private $fetchesCompany; + + /** @var FetchesTransaction */ + private $fetchesTransaction; + + /** @var UpdatesTransactionStatus */ + private $updatesTransactionStatus; + + /** @var CreatesTransaction */ + private $createsTransaction; + + /** @var CreatesDocument */ + private $createsDocument; + + /** @var CreatesFiles */ + private $createsFile; + + /** @var GeneratesTransactionBillNumber */ + private $generatesTransactionBillNumber; + + /** @var PDF */ + private $pdf; + + /** + * CreateSupplierTransactionLogic constructor. + * @param FetchesCompany $fetchesCompany + * @param FetchesTransaction $fetchesTransaction + * @param UpdatesTransactionStatus $updatesTransactionStatus + * @param CreatesTransaction $createsTransaction + * @param GeneratesTransactionBillNumber $generatesTransactionBillNumber + * @param PDF $pdf + */ + public function __construct(FetchesCompany $fetchesCompany, FetchesTransaction $fetchesTransaction, UpdatesTransactionStatus $updatesTransactionStatus, CreatesTransaction $createsTransaction, CreatesDocument $createsDocument, CreatesFiles $createsFile, GeneratesTransactionBillNumber $generatesTransactionBillNumber, PDF $pdf) + { + + $this->fetchesCompany = $fetchesCompany; + $this->fetchesTransaction = $fetchesTransaction; + $this->updatesTransactionStatus = $updatesTransactionStatus; + $this->createsTransaction = $createsTransaction; + $this->createsDocument = $createsDocument; + $this->createsFile = $createsFile; + $this->generatesTransactionBillNumber = $generatesTransactionBillNumber; + $this->pdf = $pdf; + } + + public function logic(Request $request) : JsonResponse + { + $supplier = $this->fetchesCompany->execute(['id' => $request->route('id')]); + + $rate = $request->input('rate'); + + $transactions = collect(); + + foreach($request->input('payments') as $payment){ + + /** @var Transaction $payment */ + $payment = $this->fetchesTransaction->execute(['id' => $payment['id']]); + $this->updatesTransactionStatus->execute($payment, ApprovalStatus::COMPLETED); + $billNumber = $this->generatesTransactionBillNumber->execute('SPLR-'); + $object = new TransactionObject($billNumber, TransactionType::BILL, $supplier->id, 1, + $supplier->banks()->where('default', true)->first()->id, PaymentMethodType::CASH, + $payment->original_amount * (1 / $rate), $payment->original_amount, 1, $payment->original_currency_id, + $rate, 0, 0, null, ApprovalStatus::APPROVED); + + $transactions[] = $this->createsTransaction->execute($payment->booking, $object); + } + + $pdf = LaravelMpdf::loadView('pages.pdfs.currency_vendor_order', ['transactions' => $transactions, 'supplier' => $supplier]); + + $path = Str::studly($supplier->name).'_'.Carbon::now()->format('Y_m_d_h_s_i').'.pdf'; + + $object = new DocumentObject( + DocumentType::CURRENCY_VENDOR_ORDER, + [chunk_split('data:application/pdf;base64,'.base64_encode($pdf->output()))], + '', + ApprovalStatus::COMPLETED, + 'currency_vendor_order' + ); + + /** @var Document $document */ + $document = $this->createsDocument->execute($supplier, $object); + $this->createsFile->execute($document, $object); + + return $this->response([]); + } +} diff --git a/app/Classes/Modules/Transactions/ControllersLogic/CreateTransactionLogic.php b/app/Classes/Modules/Transactions/ControllersLogic/CreateTransactionLogic.php new file mode 100644 index 00000000..02b69481 --- /dev/null +++ b/app/Classes/Modules/Transactions/ControllersLogic/CreateTransactionLogic.php @@ -0,0 +1,153 @@ + 'Created Transaction', + 'message' => 'You have successfully created a transaction' + ]; + } + + + /** @var GeneratesTransactionBillNumber */ + private $generatesTransactionBillNo; + + /** @var CanCreateTransaction */ + private $canCreateTransaction; + + private $fetchesCurrency; + + private $rateCalculatesCurrency; + + private $fetchesCompany; + + private $createsTransaction; + + private $canCreateTransactionDetail; + + private $createsTransactionDetail; + + /** + * CreateWalletLogic constructor. + * @param GeneratesTransactionBillNumber $generatesTransactionBillNo + * @param CanCreateTransaction $canCreateTransaction + * @param FetchesCurrency $fetchesCurrency + * @param RateCalculatesCurrency $rateCalculatesCurrency + * @param FetchesCompany $fetchesCompany + * @param CreatesTransaction $createsTransaction + * @param CanCreateTransactionDetail $canCreateTransactionDetail + * @param CreatesTransactionDetail $createsTransactionDetail + */ + public function __construct( + GeneratesTransactionBillNumber $generatesTransactionBillNo, CanCreateTransaction $canCreateTransaction, + FetchesCurrency $fetchesCurrency, RateCalculatesCurrency $rateCalculatesCurrency, FetchesCompany $fetchesCompany, + CreatesTransaction $createsTransaction, + CanCreateTransactionDetail $canCreateTransactionDetail, CreatesTransactionDetail $createsTransactionDetail + ){ + $this->generatesTransactionBillNo = $generatesTransactionBillNo; + $this->canCreateTransaction = $canCreateTransaction; + $this->fetchesCurrency = $fetchesCurrency; + $this->rateCalculatesCurrency = $rateCalculatesCurrency; + $this->fetchesCompany = $fetchesCompany; + $this->createsTransaction =$createsTransaction; + $this->canCreateTransactionDetail =$canCreateTransactionDetail; + $this->createsTransactionDetail = $createsTransactionDetail; + } + + /** + * @param Request $request + * @return JsonResponse + * @throws ErrorException + */ + public function logic(Request $request) : JsonResponse + { + try { + + DB::beginTransaction(); + $json_array = json_decode($request->getContent(), true); + $company = $this->fetchesCompany->execute(['id' => $json_array['company_id']]); + + $conversion_currency = $this->fetchesCurrency->execute(['id' => $json_array['currency_id']]); + $convertable_currency = $this->fetchesCurrency->execute(['id' => 1]);//MYR + $convert_amount = $this->rateCalculatesCurrency->execute($conversion_currency, $convertable_currency, $json_array['amount']); + $convert_rate = $this->rateCalculatesCurrency->execute_rate($conversion_currency, $convertable_currency); + /* + int $bill_no,string $trans_type1,string $trans_type2, + float $amount, int $currency_id, int $original_amount, + int $original_currency_id, float $currency_rate, + string $dt_transaction,int $status,int $booking_id, + int $company_id + */ + $object = new TransactionObject( + $this->generatesTransactionBillNo->execute(),$json_array['trans_type1'],$json_array['trans_type2'], + number_format( (float) $convert_amount, 5, '.', ''), 1 , number_format( (float) $json_array['amount'], 5, '.', ''), + $json_array['currency_id'],number_format( (float) $convert_rate, 5, '.', ''), + $json_array['dt_transaction'],1,$request->route('id'), + $company->id + ); + + $this->canCreateTransaction->passes($object); + + $transaction = $this->createsTransaction->execute($object); + + $transaction_array = new TransactionResource($transaction); + $transaction_detail_array = array(); + foreach ($json_array['transaction_detail'] as $key => $value) { + + $object_detail = new TransactionDetailObject( + $json_array['trans_type1'],$json_array['trans_type2'], + $transaction->id,$value['product_code'],$value['product_name'], + (int)$value['qty'],number_format( (float) $convert_amount, 5, '.', ''), number_format( (float) $json_array['amount'], 5, '.', '') + ); + $this->canCreateTransactionDetail->passes($object_detail); + $transaction_detail = $this->createsTransactionDetail->execute($object_detail); + //array_push($stack, "apple", "raspberry"); + $transaction_detail_resource= new TransactionDetailResource($transaction_detail); + $transaction_detail_array[]= $transaction_detail_resource->toArray($request); + + } + + //$transaction_array['transaction_detail']= $transaction_detail_array; + //print_r($transaction_detail_array); + //dd($transaction_detail_array); + DB::commit(); + + return $this->resourceResponse($transaction_array); + //return $this->resourceResponse($json_array); + + } catch (\Exception $exception) { + throw new ErrorException($exception->getMessage(), $exception->getCode()); + } + + } +} \ No newline at end of file diff --git a/app/Classes/Modules/Transactions/ControllersLogic/ListTransactionsLogic.php b/app/Classes/Modules/Transactions/ControllersLogic/ListTransactionsLogic.php new file mode 100644 index 00000000..15cb9bfc --- /dev/null +++ b/app/Classes/Modules/Transactions/ControllersLogic/ListTransactionsLogic.php @@ -0,0 +1,50 @@ +listsTransactions = $listsTransactions; + } + + /** + * @return array + */ + protected function notification():array { + return [ + 'title' => 'Retrieved Transactions', + 'message' => 'You have successfully retrieved a list of transactions' + ]; + } + + /** @var ListsTransactions */ + private $listsTransactions; + + + + public function logic(Request $request) : JsonResponse + { + + $query = $this->listsTransactions->execute($this->listsTransactions->deserializeFilters($request->input('filters'))); + + return $this->collectionResponse(TransactionResource::collection($query)); + + } + + + +} diff --git a/app/Classes/Modules/Transactions/ControllersLogic/SuspendTransactionLogic.php b/app/Classes/Modules/Transactions/ControllersLogic/SuspendTransactionLogic.php new file mode 100644 index 00000000..e824547e --- /dev/null +++ b/app/Classes/Modules/Transactions/ControllersLogic/SuspendTransactionLogic.php @@ -0,0 +1,61 @@ + 'Suspend Transaction', + 'message' => 'You have successfully suspended the payment booking' + ]; + } + + /** @var FetchesTransaction */ + private $fetchesTransaction; + + /** @var UpdatesTransactionStatus */ + private $updatesTransactionStatus; + + + /** + * SuspendTransactionLogic constructor. + * @param FetchesTransaction $fetchesTransaction + * @param UpdatesTransactionStatus $updatesTransactionStatus + */ + public function __construct(FetchesTransaction $fetchesTransaction, UpdatesTransactionStatus $updatesTransactionStatus) + { + $this->fetchesTransaction = $fetchesTransaction; + $this->updatesTransactionStatus = $updatesTransactionStatus; + } + + + public function logic(Request $request) : JsonResponse + { + + $transaction = $this->fetchesTransaction->execute(['id' => $request->route('id')]); + + $this->updatesTransactionStatus->execute($transaction, ApprovalStatus::SUSPENDED); + + return $this->response([]); + + } + + + +} diff --git a/app/Classes/Modules/Transactions/DataTransferObjects/TransactionDetailObject.php b/app/Classes/Modules/Transactions/DataTransferObjects/TransactionDetailObject.php new file mode 100644 index 00000000..9265f56b --- /dev/null +++ b/app/Classes/Modules/Transactions/DataTransferObjects/TransactionDetailObject.php @@ -0,0 +1,73 @@ +code = $code; + $this->name = $name; + $this->quantity = $quantity; + $this->price = $price; + } + + /** + * @return string + */ + public function getCode(): ?string + { + return $this->code; + } + + /** + * @return string + */ + public function getName(): ?string + { + return $this->name; + } + + /** + * @return int + */ + public function getQuantity(): ?int + { + return $this->quantity; + } + + /** + * @return float + */ + public function getPrice(): ?float + { + return $this->price; + } + + public function getAmount(): float + { + return $this->getQuantity() * $this->getPrice(); + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/Transactions/DataTransferObjects/TransactionObject.php b/app/Classes/Modules/Transactions/DataTransferObjects/TransactionObject.php new file mode 100644 index 00000000..8fcf4ece --- /dev/null +++ b/app/Classes/Modules/Transactions/DataTransferObjects/TransactionObject.php @@ -0,0 +1,232 @@ +billNo = $billNo; + $this->transactionType = $transactionType; + $this->issuer = $issuer; + $this->receiver = $receiver; + $this->recipientBankAccountId = $recipientBankAccountId; + $this->paymentMethod = $paymentMethod; + $this->amount = $amount; + $this->originalAmount = $originalAmount; + $this->currencyId = $currencyId; + $this->originalCurrencyId = $originalCurrencyId; + $this->currencyRate = $currencyRate; + $this->tax = $tax; + $this->serviceCharge = $serviceCharge; + $this->expiresOn = $expiresOn; + $this->status = $status; + $this->details = $details; + } + + /** + * @return string + */ + public function getBillNo(): string + { + return $this->billNo; + } + + /** + * @return string + */ + public function getTransactionType(): string + { + return $this->transactionType; + } + + /** + * @return int + */ + public function getIssuer(): int + { + return $this->issuer; + } + + /** + * @return int + */ + public function getReceiver(): int + { + return $this->receiver; + } + + /** + * @return int + */ + public function getRecipientBankAccountId(): int + { + return $this->recipientBankAccountId; + } + + /** + * @return int + */ + public function getPaymentMethod(): int + { + return $this->paymentMethod; + } + + /** + * @return float + */ + public function getAmount(): float + { + return $this->amount; + } + + /** + * @return float + */ + public function getOriginalAmount(): float + { + return $this->originalAmount; + } + + /** + * @return int + */ + public function getCurrencyId(): int + { + return $this->currencyId; + } + + /** + * @return int + */ + public function getOriginalCurrencyId(): int + { + return $this->originalCurrencyId; + } + + /** + * @return float + */ + public function getCurrencyRate(): float + { + return $this->currencyRate; + } + + /** + * @return float + */ + public function getTax(): float + { + return $this->tax; + } + + /** + * @return float + */ + public function getServiceCharge(): float + { + return $this->serviceCharge; + } + + /** + * @return Carbon|null + */ + public function getExpiresOn(): ?Carbon + { + return $this->expiresOn; + } + + /** + * @return int + */ + public function getStatus(): int + { + return $this->status; + } + + /** + * @return array + */ + public function getDetails(): array + { + return array_map(function($product){ + return new TransactionDetailObject($product['stockCode'] ?? '', $product['description'] ?? '', $product['quantity'] ?? '', floatval(str_replace(',', '', $product['unit_price']))); + }, $this->details); + } + + + + +} \ No newline at end of file diff --git a/app/Classes/Modules/Transactions/Processors/CreateInvoiceTransactionProcessor.php b/app/Classes/Modules/Transactions/Processors/CreateInvoiceTransactionProcessor.php new file mode 100644 index 00000000..54370591 --- /dev/null +++ b/app/Classes/Modules/Transactions/Processors/CreateInvoiceTransactionProcessor.php @@ -0,0 +1,229 @@ +listsTransactions = $listsTransactions; + $this->createsTransaction = $createsTransaction; + $this->generatesTransactionBillNumber = $generatesTransactionBillNumber; + $this->calculatesBookingPaidAmount = $calculatesBookingPaidAmount; + $this->calculatesBookingTransferredAmount = $calculatesBookingTransferredAmount; + $this->fetchesServiceConfigurations = $fetchesServiceConfigurations; + $this->calculatesBookingCurrencyAverageRate = $calculatesBookingCurrencyAverageRate; + $this->fetchesCompany = $fetchesCompany; + $this->createsDocument = $createsDocument; + $this->createsFile = $createsFile; + $this->updatesBookingStatus = $updatesBookingStatus; + } + + + /** + * @param Booking $booking + * @return void + * @throws \App\Classes\Exceptions\MalformedRequestException + */ + public function execute(Booking $booking) + { + $payment_amount = $this->calculatesBookingTransferredAmount->execute($booking, $booking->fix_currency_id); + $booking_amount = $booking->fix_amount; + + if ((float) $booking_amount !== (float) $payment_amount) { + return; + } + + $po_order_transaction = $booking->transactions() + ->where('type', TransactionType::PURCHASE_ORDER) + ->complete() + ->first(); + + $constants = SegmentConstant::where('reference', SegmentConstants::SERVICE_TYPE)->where('detail->id', $booking->service->id)->first(); + + if($constants->detail->is_billable && !$po_order_transaction) { + return; + } + + $transaction = $booking->transactions() + ->where('type', TransactionType::PAYMENT) + ->first(); + + $billNumber = $this->generatesTransactionBillNumber->execute('INV-'); + + $booking_currency_average_rate = $this->calculatesBookingCurrencyAverageRate->execute($booking, TransactionType::PAYMENT); + + $total_service_charge = $booking->transactions() + ->where('type', TransactionType::PAYMENT) + ->whereIn('status', [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED]) + ->sum('service_charge'); + + $total_tax = $booking->transactions() + ->where('type', TransactionType::PAYMENT) + ->whereIn('status', [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED]) + ->sum('tax'); + + $transaction_object = new TransactionObject( + $billNumber, + TransactionType::INVOICE, + $transaction->issuer, + $transaction->receiver, + $transaction->recipient_bank_account_id, + $transaction->payment_method, + $payment_amount, + $booking_amount, + $transaction->currency_id, + $transaction->original_currency_id, + $booking_currency_average_rate, + $total_tax, + $total_service_charge, + null, + ApprovalStatus::APPROVED + ); + $invoice_transaction = $this->createsTransaction->execute($po_order_transaction->booking, $transaction_object); + + $supplier = $this->fetchesCompany->execute(['id' => $transaction->receiver]); + + $purchase_order_pdf = LaravelMpdf::loadView('pages.pdfs.purchase_order', ['invoice_transaction' => $invoice_transaction, 'po_order_transaction' => $po_order_transaction, 'supplier' => $supplier]); + $document_object = new DocumentObject( + DocumentType::PURCHASE_ORDER, + [chunk_split('data:application/pdf;base64,'.base64_encode($purchase_order_pdf->output()))], + '', + ApprovalStatus::COMPLETED, + 'purchase_orders' + ); + $document = $this->createsDocument->execute($po_order_transaction->booking, $document_object); + $this->createsFile->execute($document, $document_object); + + $deliver_order_pdf = LaravelMpdf::loadView('pages.pdfs.deliver_order', ['invoice_transaction' => $invoice_transaction, 'po_order_transaction' => $po_order_transaction, 'supplier' => $supplier]); + $document_object = new DocumentObject( + DocumentType::DELIVER_ORDER, + [chunk_split('data:application/pdf;base64,'.base64_encode($deliver_order_pdf->output()))], + '', + ApprovalStatus::COMPLETED, + 'delivery_orders' + ); + + /** @var Document $document */ + $document = $this->createsDocument->execute($po_order_transaction->booking, $document_object); + $this->createsFile->execute($document, $document_object); + + + $invoice_pdf = LaravelMpdf::loadView('pages.pdfs.invoice', ['invoice_transaction' => $invoice_transaction, 'po_order_transaction' => $po_order_transaction, 'supplier' => $supplier]); + $document_object = new DocumentObject( + DocumentType::INVOICE, + [chunk_split('data:application/pdf;base64,'.base64_encode($invoice_pdf->output()))], + '', + ApprovalStatus::COMPLETED, + 'invoices' + ); + $document = $this->createsDocument->execute($po_order_transaction->booking, $document_object); + $this->createsFile->execute($document, $document_object); + + $billNumber = $this->generatesTransactionBillNumber->execute('SPDO-'); + + $booking_currency_average_rate = $this->calculatesBookingCurrencyAverageRate->execute($booking, TransactionType::BILL); + + $transaction_object = new TransactionObject( + $billNumber, + TransactionType::SUPPLIER_DELIVER, + $transaction->issuer, + $transaction->receiver, + $transaction->recipient_bank_account_id, + $transaction->payment_method, + $payment_amount, + $booking_amount, + $transaction->currency_id, + $transaction->original_currency_id, + $booking_currency_average_rate, + $total_tax, + $total_service_charge, + null, + ApprovalStatus::APPROVED + ); + $supplier_deliver_order_transaction = $this->createsTransaction->execute($po_order_transaction->booking, $transaction_object); + + $supplier_order_pdf = LaravelMpdf::loadView('pages.pdfs.supplier_deliver_order', ['supplier_deliver_order_transaction' => $supplier_deliver_order_transaction, 'po_order_transaction' => $po_order_transaction, 'supplier' => $supplier]); + $document_object = new DocumentObject( + DocumentType::SUPPLIER_DELIVER_ORDER, + [chunk_split('data:application/pdf;base64,'.base64_encode($supplier_order_pdf->output()))], + '', + ApprovalStatus::COMPLETED, + 'supplier_delivery_orders' + ); + $document = $this->createsDocument->execute($po_order_transaction->booking, $document_object); + $this->createsFile->execute($document, $document_object); + + $this->updatesBookingStatus->execute($booking, ApprovalStatus::COMPLETED); + } +} diff --git a/app/Classes/Modules/Transactions/Services/ChecksIfTransactionBillNumberExists.php b/app/Classes/Modules/Transactions/Services/ChecksIfTransactionBillNumberExists.php new file mode 100644 index 00000000..9b63985f --- /dev/null +++ b/app/Classes/Modules/Transactions/Services/ChecksIfTransactionBillNumberExists.php @@ -0,0 +1,22 @@ +repository = $repository; + } + + public function execute(string $bill_no): bool { + return $this->repository->where('bill_no', $bill_no)->exists(); + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/Transactions/Services/CreatesTransaction.php b/app/Classes/Modules/Transactions/Services/CreatesTransaction.php new file mode 100644 index 00000000..ddebf0d5 --- /dev/null +++ b/app/Classes/Modules/Transactions/Services/CreatesTransaction.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(); + + + return $this->handler($booking->transactions(), $model); + + } +} \ No newline at end of file diff --git a/app/Classes/Modules/Transactions/Services/CreatesTransactionDetail.php b/app/Classes/Modules/Transactions/Services/CreatesTransactionDetail.php new file mode 100644 index 00000000..0e852ddf --- /dev/null +++ b/app/Classes/Modules/Transactions/Services/CreatesTransactionDetail.php @@ -0,0 +1,30 @@ +product_code = $object->getCode(); + $model->product_name = $object->getName(); + $model->quantity = $object->getQuantity(); + $model->price = $object->getPrice(); + $model->amount = $object->getAmount(); + + return $this->handler($transaction->transactionDetails(), $model); + + } +} \ No newline at end of file diff --git a/app/Classes/Modules/Transactions/Services/DeletesTransactionDetails.php b/app/Classes/Modules/Transactions/Services/DeletesTransactionDetails.php new file mode 100644 index 00000000..42b16d77 --- /dev/null +++ b/app/Classes/Modules/Transactions/Services/DeletesTransactionDetails.php @@ -0,0 +1,19 @@ +transactionDetails()->delete(); + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/Transactions/Services/FetchesTransaction.php b/app/Classes/Modules/Transactions/Services/FetchesTransaction.php new file mode 100644 index 00000000..6777da5b --- /dev/null +++ b/app/Classes/Modules/Transactions/Services/FetchesTransaction.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/Transactions/Services/FetchesTransactionDetail.php b/app/Classes/Modules/Transactions/Services/FetchesTransactionDetail.php new file mode 100644 index 00000000..1f2f8c08 --- /dev/null +++ b/app/Classes/Modules/Transactions/Services/FetchesTransactionDetail.php @@ -0,0 +1,35 @@ +repository = $repository; + } + + + /** + * @return Builder + */ + public function getRepository(): Builder + { + return $this->repository->newQuery(); + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/Transactions/Services/GeneratesTransactionBillNumber.php b/app/Classes/Modules/Transactions/Services/GeneratesTransactionBillNumber.php new file mode 100644 index 00000000..7f92ab60 --- /dev/null +++ b/app/Classes/Modules/Transactions/Services/GeneratesTransactionBillNumber.php @@ -0,0 +1,37 @@ +checksIfTransactionBillNumberExists = $checksIfTransactionBillNumberExists; + } + + + /** + * @param string $prefix + * @return string + */ + public function execute(string $prefix): string { + $date = carbon::now(); + + $billNumber = $prefix.$date->format('Y').$date->format('m').'-'.mt_rand(10000, 99999); + + return !$this->checksIfTransactionBillNumberExists->execute($billNumber) ? $billNumber : self::execute($prefix); + + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/Transactions/Services/ListsTransactions.php b/app/Classes/Modules/Transactions/Services/ListsTransactions.php new file mode 100644 index 00000000..8d77171f --- /dev/null +++ b/app/Classes/Modules/Transactions/Services/ListsTransactions.php @@ -0,0 +1,31 @@ +repository = $repository; + } + + /** + * @return Builder + */ + public function getRepository(): Builder + { + return $this->repository->newQuery(); + } +} diff --git a/app/Classes/Modules/Transactions/Services/UpdatesTransaction.php b/app/Classes/Modules/Transactions/Services/UpdatesTransaction.php new file mode 100644 index 00000000..aba7b07a --- /dev/null +++ b/app/Classes/Modules/Transactions/Services/UpdatesTransaction.php @@ -0,0 +1,33 @@ +recipient_bank_account_id = $object->getRecipientBankAccountId(); + $transaction->payment_method = $object->getPaymentMethod(); + $transaction->amount = $object->getAmount(); + $transaction->original_amount = $object->getOriginalAmount(); + $transaction->currency_id = $object->getCurrencyId(); + $transaction->original_currency_id = $object->getOriginalCurrencyId(); + $transaction->currency_rate = $object->getCurrencyRate(); + $transaction->tax = $object->getTax(); + $transaction->service_charge = $object->getServiceCharge(); + + return $this->handler($transaction); + + } +} \ No newline at end of file diff --git a/app/Classes/Modules/Transactions/Services/UpdatesTransactionStatus.php b/app/Classes/Modules/Transactions/Services/UpdatesTransactionStatus.php new file mode 100644 index 00000000..769f2dc0 --- /dev/null +++ b/app/Classes/Modules/Transactions/Services/UpdatesTransactionStatus.php @@ -0,0 +1,22 @@ +status = $status; + return $this->handler($model); + } +} \ No newline at end of file diff --git a/app/Classes/Modules/Transactions/Standards/Rules/CanCreateTransaction.php b/app/Classes/Modules/Transactions/Standards/Rules/CanCreateTransaction.php new file mode 100644 index 00000000..39fdd05a --- /dev/null +++ b/app/Classes/Modules/Transactions/Standards/Rules/CanCreateTransaction.php @@ -0,0 +1,51 @@ +transactionValidation = $transactionValidation; + } + + + /** + * @return bool + */ + protected function authorized(): bool + { + // TODO Set Authorization rules + return true; + } + + /** + * @param TransactionObject $object + * @return bool + * @throws \App\Classes\Exceptions\RequestValidationException + */ + protected function validators($object): bool + { + return $this->transactionValidation->validate($object); + } + + /** + * @param TransactionObject $object + * @return bool + */ + protected function criteria($object): bool + { + return true; + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/Transactions/Standards/Rules/CanCreateTransactionDetail.php b/app/Classes/Modules/Transactions/Standards/Rules/CanCreateTransactionDetail.php new file mode 100644 index 00000000..2669ffbf --- /dev/null +++ b/app/Classes/Modules/Transactions/Standards/Rules/CanCreateTransactionDetail.php @@ -0,0 +1,51 @@ +transactionDetailValidation = $transactionDetailValidation; + } + + + /** + * @return bool + */ + protected function authorized(): bool + { + // TODO Set Authorization rules + return true; + } + + /** + * @param TransactionDetailObject $object + * @return bool + * @throws \App\Classes\Exceptions\RequestValidationException + */ + protected function validators($object): bool + { + return $this->transactionDetailValidation->validate($object); + } + + /** + * @param TransactionDetailObject $object + * @return bool + */ + protected function criteria($object): bool + { + return true; + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/Transactions/Standards/Validators/TransactionDetailValidation.php b/app/Classes/Modules/Transactions/Standards/Validators/TransactionDetailValidation.php new file mode 100644 index 00000000..35357060 --- /dev/null +++ b/app/Classes/Modules/Transactions/Standards/Validators/TransactionDetailValidation.php @@ -0,0 +1,62 @@ +bill_no = $bill_no; + $this->trans_type1= $trans_type1; + $this->trans_type2 = $trans_type2; + $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; + $this->dt_transaction = $dt_transaction; + $this->status = $status; + $this->booking_id = $booking_id; + $this->company_id = $company_id; + */ + protected function data($object): array + { + return [ + 'trans_type1' => $object->getTransType1(), + 'trans_type2' => $object->getTransType2(), + 'transaction_id' => $object->getTransactionId(), + 'product_code' => $object->getProductCode(), + 'product_name'=>$object->getProductName(), + 'qty'=>$object->getQty(), + 'price'=>$object->getPrice(), + 'amount' => $object->getAmount() + ]; + } + + /** + * @return array + */ + protected function rules(): array + { + return [ + 'trans_type1' => 'required', + 'trans_type2' => 'required', + 'transaction_id' => 'required', + 'product_code' => 'required', + 'product_name'=>'required', + 'qty'=>'required', + 'price'=>'required', + 'amount' => 'required' + ]; + } + + /** + * @return array + */ + protected function messages(): array + { + return []; + } +} \ No newline at end of file diff --git a/app/Classes/Modules/Transactions/Standards/Validators/TransactionValidation.php b/app/Classes/Modules/Transactions/Standards/Validators/TransactionValidation.php new file mode 100644 index 00000000..62443c3d --- /dev/null +++ b/app/Classes/Modules/Transactions/Standards/Validators/TransactionValidation.php @@ -0,0 +1,68 @@ +bill_no = $bill_no; + $this->trans_type1= $trans_type1; + $this->trans_type2 = $trans_type2; + $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; + $this->dt_transaction = $dt_transaction; + $this->status = $status; + $this->booking_id = $booking_id; + $this->company_id = $company_id; + */ + protected function data($object): array + { + return [ + 'bill_no' => $object->getBillNo(), + 'trans_type1' => $object->getBillNo(), + 'trans_type2' => $object->getTransType2(), + 'amount' => $object->getAmount(), + 'currency_id' => $object->getCurrency(), + 'original_amount' => $object->getOriginalAmount(), + 'original_currency_id'=>$object->getOriginalCurrency(), + 'dt_transaction'=>$object->getDtTransaction(), + 'status'=>$object->getStatus(), + 'booking_id'=>$object->getBookingId(), + 'company_id'=>$object->getCompanyId() + ]; + } + + /** + * @return array + */ + protected function rules(): array + { + return [ + 'bill_no' => 'required', + 'trans_type1' => 'required', + 'trans_type2' => 'required', + 'amount' => 'required', + 'currency_id' => 'required', + 'original_amount' => 'required', + 'original_currency_id'=>'required', + 'dt_transaction'=>'required', + 'status'=>'required', + 'booking_id'=>'required', + 'company_id'=>'required' + ]; + } + + /** + * @return array + */ + protected function messages(): array + { + return []; + } +} \ No newline at end of file diff --git a/app/Classes/ValueObjects/Constants/PaymentMethodType.php b/app/Classes/ValueObjects/Constants/PaymentMethodType.php new file mode 100644 index 00000000..4efec990 --- /dev/null +++ b/app/Classes/ValueObjects/Constants/PaymentMethodType.php @@ -0,0 +1,33 @@ + self::CASH, + 'cheque' => self::CHEQUE, + 'ba' => self::BA, + 'wallet' => self::WALLET, + 'payment gateway' => self::PAYMENT_GATEWAY, + ]; + + public const PAYMENT_METHODS_ID = [ + self::CASH => 'cash', + self::CHEQUE => 'cheque', + self::BA => 'ba', + self::WALLET => 'wallet', + self::PAYMENT_GATEWAY => 'payment gateway' + ]; + +} diff --git a/app/Classes/ValueObjects/Constants/TransactionStatus.php b/app/Classes/ValueObjects/Constants/TransactionStatus.php new file mode 100644 index 00000000..d0264fa2 --- /dev/null +++ b/app/Classes/ValueObjects/Constants/TransactionStatus.php @@ -0,0 +1,19 @@ +execute($request); + } +} \ No newline at end of file diff --git a/app/Http/Controllers/Currencies/DeleteCurrencyController.php b/app/Http/Controllers/Currencies/DeleteCurrencyController.php new file mode 100644 index 00000000..e4114c77 --- /dev/null +++ b/app/Http/Controllers/Currencies/DeleteCurrencyController.php @@ -0,0 +1,19 @@ +execute($request); + } +} \ No newline at end of file diff --git a/app/Http/Controllers/Currencies/FetchSystemPrimaryCurrencyController.php b/app/Http/Controllers/Currencies/FetchSystemPrimaryCurrencyController.php new file mode 100644 index 00000000..73b8b1e5 --- /dev/null +++ b/app/Http/Controllers/Currencies/FetchSystemPrimaryCurrencyController.php @@ -0,0 +1,19 @@ +execute($request); + } +} \ No newline at end of file diff --git a/app/Http/Controllers/Currencies/ListCurrencyController.php b/app/Http/Controllers/Currencies/ListCurrencyController.php new file mode 100644 index 00000000..211590a3 --- /dev/null +++ b/app/Http/Controllers/Currencies/ListCurrencyController.php @@ -0,0 +1,20 @@ +execute($request); + } + +} \ No newline at end of file diff --git a/app/Http/Controllers/Currencies/RateCalculateCurrencyController.php b/app/Http/Controllers/Currencies/RateCalculateCurrencyController.php new file mode 100644 index 00000000..6d96482b --- /dev/null +++ b/app/Http/Controllers/Currencies/RateCalculateCurrencyController.php @@ -0,0 +1,19 @@ +execute($request); + } +} \ No newline at end of file diff --git a/app/Http/Controllers/Currencies/Rates/CalculateRateController.php b/app/Http/Controllers/Currencies/Rates/CalculateRateController.php new file mode 100644 index 00000000..4ccd0923 --- /dev/null +++ b/app/Http/Controllers/Currencies/Rates/CalculateRateController.php @@ -0,0 +1,19 @@ +execute($request); + } +} \ No newline at end of file diff --git a/app/Http/Controllers/Currencies/Rates/CreateRateController.php b/app/Http/Controllers/Currencies/Rates/CreateRateController.php new file mode 100644 index 00000000..91a6f4d5 --- /dev/null +++ b/app/Http/Controllers/Currencies/Rates/CreateRateController.php @@ -0,0 +1,20 @@ +execute($request); + } + +} \ No newline at end of file diff --git a/app/Http/Controllers/Currencies/Rates/DeleteRateController.php b/app/Http/Controllers/Currencies/Rates/DeleteRateController.php new file mode 100644 index 00000000..b361ed84 --- /dev/null +++ b/app/Http/Controllers/Currencies/Rates/DeleteRateController.php @@ -0,0 +1,20 @@ +execute($request); + } + +} \ No newline at end of file diff --git a/app/Http/Controllers/Currencies/Rates/FetchRateController.php b/app/Http/Controllers/Currencies/Rates/FetchRateController.php new file mode 100644 index 00000000..b72b40df --- /dev/null +++ b/app/Http/Controllers/Currencies/Rates/FetchRateController.php @@ -0,0 +1,20 @@ +execute($request); + } + +} \ No newline at end of file diff --git a/app/Http/Controllers/Currencies/Rates/ListRatesController.php b/app/Http/Controllers/Currencies/Rates/ListRatesController.php new file mode 100644 index 00000000..04ba3162 --- /dev/null +++ b/app/Http/Controllers/Currencies/Rates/ListRatesController.php @@ -0,0 +1,20 @@ +execute($request); + } + +} \ No newline at end of file diff --git a/app/Http/Controllers/Currencies/Rates/UpdateRateController.php b/app/Http/Controllers/Currencies/Rates/UpdateRateController.php new file mode 100644 index 00000000..651854bc --- /dev/null +++ b/app/Http/Controllers/Currencies/Rates/UpdateRateController.php @@ -0,0 +1,20 @@ +execute($request); + } + +} \ No newline at end of file diff --git a/app/Http/Controllers/Receipts/CreateReceiptController.php b/app/Http/Controllers/Receipts/CreateReceiptController.php new file mode 100644 index 00000000..dadf87b3 --- /dev/null +++ b/app/Http/Controllers/Receipts/CreateReceiptController.php @@ -0,0 +1,15 @@ +execute($request); + } +} \ No newline at end of file diff --git a/app/Http/Controllers/Transactions/CreateMakePaymentPOTransactionController.php b/app/Http/Controllers/Transactions/CreateMakePaymentPOTransactionController.php new file mode 100644 index 00000000..592a891d --- /dev/null +++ b/app/Http/Controllers/Transactions/CreateMakePaymentPOTransactionController.php @@ -0,0 +1,15 @@ +execute($request); + } +} \ No newline at end of file diff --git a/app/Http/Controllers/Transactions/CreatePaymentProofDocumentController.php b/app/Http/Controllers/Transactions/CreatePaymentProofDocumentController.php new file mode 100644 index 00000000..c7a34bc4 --- /dev/null +++ b/app/Http/Controllers/Transactions/CreatePaymentProofDocumentController.php @@ -0,0 +1,21 @@ +execute($request); + } +} diff --git a/app/Http/Controllers/Transactions/CreatePurchaseOrderTransactionController.php b/app/Http/Controllers/Transactions/CreatePurchaseOrderTransactionController.php new file mode 100644 index 00000000..67a74537 --- /dev/null +++ b/app/Http/Controllers/Transactions/CreatePurchaseOrderTransactionController.php @@ -0,0 +1,21 @@ +execute($request); + } +} diff --git a/app/Http/Controllers/Transactions/CreateSupplierTransactionController.php b/app/Http/Controllers/Transactions/CreateSupplierTransactionController.php new file mode 100644 index 00000000..5c989ddb --- /dev/null +++ b/app/Http/Controllers/Transactions/CreateSupplierTransactionController.php @@ -0,0 +1,21 @@ +execute($request); + } +} diff --git a/app/Http/Controllers/Transactions/CreateTransactionController.php b/app/Http/Controllers/Transactions/CreateTransactionController.php new file mode 100644 index 00000000..c311ca19 --- /dev/null +++ b/app/Http/Controllers/Transactions/CreateTransactionController.php @@ -0,0 +1,15 @@ +execute($request); + } +} \ No newline at end of file diff --git a/app/Http/Controllers/Transactions/ListTransactionsController.php b/app/Http/Controllers/Transactions/ListTransactionsController.php new file mode 100644 index 00000000..64571485 --- /dev/null +++ b/app/Http/Controllers/Transactions/ListTransactionsController.php @@ -0,0 +1,21 @@ +execute($request); + } +} diff --git a/app/Http/Controllers/Transactions/SuspendTransactionController.php b/app/Http/Controllers/Transactions/SuspendTransactionController.php new file mode 100644 index 00000000..ad7eef91 --- /dev/null +++ b/app/Http/Controllers/Transactions/SuspendTransactionController.php @@ -0,0 +1,21 @@ +execute($request); + } +} diff --git a/app/Http/Resources/CurrencyConversionResource.php b/app/Http/Resources/CurrencyConversionResource.php new file mode 100644 index 00000000..0c87a9e7 --- /dev/null +++ b/app/Http/Resources/CurrencyConversionResource.php @@ -0,0 +1,26 @@ + $this->id, + 'country' => new CountryResource($this->country), + 'name' => $this->name, + 'short_code' => $this->short_code, + 'symbol' => $this->symbol, + ]; + } +} diff --git a/app/Http/Resources/CurrencyRateResource.php b/app/Http/Resources/CurrencyRateResource.php new file mode 100644 index 00000000..66d548f1 --- /dev/null +++ b/app/Http/Resources/CurrencyRateResource.php @@ -0,0 +1,26 @@ + PaymentMethodType::PAYMENT_METHODS_ID[$this->payment_method_type], + 'selling' => [ + 'type' => property_exists($this->selling, 'type') ? $this->selling->type : 'rate', + 'value' => property_exists($this->selling, 'value') ? $this->selling->value : $this->selling + ] + ]; + } +} diff --git a/app/Http/Resources/CurrencyResource.php b/app/Http/Resources/CurrencyResource.php new file mode 100644 index 00000000..e6265c67 --- /dev/null +++ b/app/Http/Resources/CurrencyResource.php @@ -0,0 +1,26 @@ + $this->id, + 'country' => new CountryResource($this->country), + 'name' => $this->name, + 'short_code' => $this->short_code, + 'symbol' => $this->symbol, + ]; + } +} diff --git a/app/Http/Resources/RateCalculateCurrencyResource.php b/app/Http/Resources/RateCalculateCurrencyResource.php new file mode 100644 index 00000000..24ae41d4 --- /dev/null +++ b/app/Http/Resources/RateCalculateCurrencyResource.php @@ -0,0 +1,32 @@ +conversion_currency = $conversion_currency; + $this->convertable_currency = $convertable_currency; + $this->convert_amount = $convert_amount; + } + + /** + * Transform the resource into an array. + * + * @param \Illuminate\Http\Request $request + * @return array + */ + public function toArray($request) + { + return [ + 'conversion_currency' => $this->conversion_currency->id, + 'convertable_currency' => $this->conversion_currency->id, + 'convert_amount' => $this->convert_amount, + ]; + } +} diff --git a/app/Http/Resources/ReceiptDetailResource.php b/app/Http/Resources/ReceiptDetailResource.php new file mode 100644 index 00000000..4c8850f8 --- /dev/null +++ b/app/Http/Resources/ReceiptDetailResource.php @@ -0,0 +1,29 @@ + $this->id, + 'trans_type1' => $this->trans_type1, + 'trans_type2' => $this->trans_type2, + 'transaction_id' => (int) $this->transaction_id, + 'receipt_id' => (int)$this->receipt_id, + 'price' => (double) $this->price, + 'amount' => (double) $this->amount + + ]; + } +} diff --git a/app/Http/Resources/ReceiptResource.php b/app/Http/Resources/ReceiptResource.php new file mode 100644 index 00000000..95573ef3 --- /dev/null +++ b/app/Http/Resources/ReceiptResource.php @@ -0,0 +1,34 @@ + $this->id, + 'trans_type1' => $this->trans_type1, + 'trans_type2' => $this->trans_type2, + 'bill_no' => (int) $this->bill_no, + 'amount' => (double) $this->amount, + 'currency_id' => (int) $this->currency_id, + 'original_amount' => (double) $this->original_amount, + 'original_currency_id' => (int) $this->original_currency_id, + 'currency_rate' => (double) $this->currency_rate, + 'dt_transaction' => $this->dt_transaction, + 'status' => (int) $this->status, + 'booking_id' => (int) $this->booking_id, + 'company_id' => (int) $this->company_id + ]; + } +} diff --git a/app/Http/Resources/TransactionDetailResource.php b/app/Http/Resources/TransactionDetailResource.php new file mode 100644 index 00000000..1b60cfce --- /dev/null +++ b/app/Http/Resources/TransactionDetailResource.php @@ -0,0 +1,26 @@ + $this->product_code, + 'description' => $this->product_name, + 'quantity' => $this->quantity, + 'unit_price' => (double) $this->price, + 'total' => (double) $this->amount + ]; + } +} diff --git a/app/Http/Resources/TransactionResource.php b/app/Http/Resources/TransactionResource.php new file mode 100644 index 00000000..ef652fd7 --- /dev/null +++ b/app/Http/Resources/TransactionResource.php @@ -0,0 +1,36 @@ + $this->id, + 'booking' => new BookingResource($this->booking), + 'type' => (int) $this->type, + 'bill_no' => $this->bill_no, + 'amount' => (double) $this->amount, + 'original_amount' => (double) $this->original_amount, + 'currency' => new CurrencyResource($this->currency), + 'original_currency' => new CurrencyResource($this->original_currency), + 'currency_rate' => (double) $this->currency_rate, + 'status' => (int) $this->status, + 'details' => TransactionDetailResource::collection($this->transactionDetails), + 'documents' => new DocumentResource($this->documents()->first()), + 'expires_on' => Carbon::parse($this->expires_on)->format('d-m-Y h:s:i'), + 'updated_at' => Carbon::parse($this->update_at)->format('d-m-Y h:s:i') + ]; + } +} diff --git a/app/Models/CurrencyLog.php b/app/Models/CurrencyLog.php new file mode 100644 index 00000000..ee519e8f --- /dev/null +++ b/app/Models/CurrencyLog.php @@ -0,0 +1,9 @@ +hasOne(Transaction::class, 'transaction_id', 'id'); + } + + public function currency(): HasOne + { + return $this->hasOne(Currency::class, 'currency_id', 'id'); + } + + public function original_currency(): HasOne + { + return $this->hasOne(Currency::class, 'original_currency_id', 'id'); + } + +} diff --git a/app/Models/ReceiptDetail.php b/app/Models/ReceiptDetail.php new file mode 100644 index 00000000..a6e53f24 --- /dev/null +++ b/app/Models/ReceiptDetail.php @@ -0,0 +1,22 @@ +hasOne(Transaction::class, 'transaction_id', 'id'); + } + + public function receipt(): HasOne + { + return $this->hasOne(Receipt::class, 'receipt_id', 'id'); + } + +} diff --git a/app/Models/Transaction.php b/app/Models/Transaction.php new file mode 100644 index 00000000..0e39c289 --- /dev/null +++ b/app/Models/Transaction.php @@ -0,0 +1,111 @@ +BelongsTo( Booking::class, 'booking_id', 'id'); + } + + /** + * @return MorphMany + */ + public function documents(): morphMany + { + return $this->morphMany(Document::class, 'owner'); + } + + /** + * @return BelongsTo + */ + public function currency(): BelongsTo + { + return $this->BelongsTo(Currency::class, 'currency_id', 'id'); + } + + /** + * @return BelongsTo + */ + public function original_currency(): BelongsTo + { + return $this->BelongsTo(Currency::class, 'original_currency_id', 'id'); + } + + /** + * @return HasMany + */ + public function transactionDetails(): HasMany + { + return $this->HasMany(TransactionDetail::class, 'transaction_id', 'id'); + } + + public function convert_original_amount() + { + if($this->booking()->first()->fix_currency_id !== 1) { + $currency_rate = $this->currency()->first()->rates()->where('payment_method_type', $this->payment_method)->first(); + + return number_format($this->original_amount / $currency_rate->selling, 2); + } + return $this->original_amount; + } + + /** + * @param Builder $query + * @return Builder + */ + public function scopePayments(Builder $query) + { + return $query->where('type', TransactionType::PAYMENT); + } + + /** + * @param Builder $query + * @return Builder + */ + public function scopeInComplete(Builder $query) + { + return $query->where(function(Builder $query){ + $query->where(function(Builder $query){ + $query->where('status', ApprovalStatus::PENDING_SUBMISSION) + ->whereDate('expires_on', '>=', Carbon::now()); + })->orWhere(function(Builder $query){ + $query->where('status', ApprovalStatus::PENDING_VERIFICATION); + }); + }); + } + + /** + * @param Builder $query + * @return Builder + */ + public function scopeComplete(Builder $query) + { + return $query->whereIn('status', [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED]); + } + + /** + * @param Builder $query + * @return Builder + */ + public function scopeTransferred(Builder $query) + { + return $query->whereIn('status', [ApprovalStatus::COMPLETED]); + } +} diff --git a/app/Models/TransactionDetail.php b/app/Models/TransactionDetail.php new file mode 100644 index 00000000..8e0a1613 --- /dev/null +++ b/app/Models/TransactionDetail.php @@ -0,0 +1,37 @@ +BelongsTo( Transaction::class, 'transaction_id', 'id'); + } + + public function convert_original_price() + { + if($this->transaction()->first()->booking()->first()->fix_currency_id !== 1) { + $currency_rate = $this->transaction()->first()->currency()->first()->rates()->where('payment_method_type', $this->transaction()->first()->payment_method)->first(); + return number_format($this->price / $currency_rate->selling, 2); + } + return $this->price; + } + + public function convert_original_amount() + { + if($this->transaction()->first()->booking()->first()->fix_currency_id !== 1) { + $currency_rate = $this->transaction()->first()->currency()->first()->rates()->where('payment_method_type', $this->transaction()->first()->payment_method)->first(); + return number_format($this->amount / $currency_rate->selling, 2); + } + return $this->amount; + } +} diff --git a/routes/api.php b/routes/api.php index f89014dd..3796f801 100644 --- a/routes/api.php +++ b/routes/api.php @@ -38,21 +38,21 @@ Route::group(['middleware' => 'api', 'prefix' => 'v1', 'as' => 'api.'], function // // require __DIR__ . '/segment.php'; // -// require __DIR__ . '/currency.php'; -// // require __DIR__ . '/bank.php'; // // require __DIR__ . '/booking.php'; // -// require __DIR__ . '/transaction.php'; + require __DIR__ . '/currency.php'; require __DIR__ . '/address.php'; -// require __DIR__ . '/announcement.php'; + require __DIR__ . '/transaction.php'; + require __DIR__ . '/receipt.php'; + +// require __DIR__ . '/announcement.php'; // require __DIR__ . '/wallet.php'; // require __DIR__ . '/rate.php'; -// require __DIR__ . '/receipt.php'; }); }); diff --git a/routes/currency.php b/routes/currency.php new file mode 100644 index 00000000..ba308402 --- /dev/null +++ b/routes/currency.php @@ -0,0 +1,10 @@ + 'Currencies', 'as' => 'currency.', 'prefix' => 'currency'], function () { + Route::get('/primary/show', 'FetchSystemPrimaryCurrencyController@fetch')->name('primary.show'); + Route::get('/list', 'ListCurrencyController@list')->name('list'); + Route::post('/create', 'CreateCurrencyController@create')->name('create'); + Route::delete('/delete/{id}', 'DeleteCurrencyController@delete')->name('delete'); +}); \ No newline at end of file diff --git a/routes/receipt.php b/routes/receipt.php new file mode 100644 index 00000000..aa532fe8 --- /dev/null +++ b/routes/receipt.php @@ -0,0 +1,10 @@ + 'receipt', 'namespace' => 'Receipts', 'as' => 'receipt.'], function () { + + Route::post('/create/{id}', 'CreateReceiptController@create')->name('create'); + //Route::post('/create-transaction/{id}', 'CreateWalletTransactionController@create')->name('create_transaction'); + +}); \ No newline at end of file diff --git a/routes/transaction.php b/routes/transaction.php new file mode 100644 index 00000000..cab4d241 --- /dev/null +++ b/routes/transaction.php @@ -0,0 +1,15 @@ + 'transactions', 'namespace' => 'Transactions', 'as' => 'transaction.'], function () { + + Route::get('/list', 'ListTransactionsController@list')->name('list'); + Route::delete('/suspend/{id}', 'SuspendTransactionController@suspend')->name('suspend'); + + route::post('/supplier/{id}/bill/create', 'CreateSupplierTransactionController@create')->name('supplier.create'); + route::post('{id}/bill/verification', 'CreatePaymentProofDocumentController@verify')->name('bill.verification'); + + Route::post('booking/{id}/details/update', 'CreatePurchaseOrderTransactionController@create')->name('po.create'); + +}); \ No newline at end of file