diff --git a/app/Classes/Modules/Billplzs/ControllersLogic/CallbackBillplzLogic.php b/app/Classes/Modules/Billplzs/ControllersLogic/CallbackBillplzLogic.php
index 590497bc..8c763460 100644
--- a/app/Classes/Modules/Billplzs/ControllersLogic/CallbackBillplzLogic.php
+++ b/app/Classes/Modules/Billplzs/ControllersLogic/CallbackBillplzLogic.php
@@ -2,6 +2,8 @@
namespace App\Classes\Modules\Billplzs\ControllersLogic;
+use App\Classes\Modules\Wallets\DataTransferObjects\WalletObject;
+use App\Classes\Modules\Wallets\Services\UpdatesWallet;
use App\Classes\Exceptions\ResourceNotFoundException;
use App\Http\Resources\TransactionResource;
@@ -32,6 +34,8 @@ class CallbackBillplzLogic
/** @var UpdatesTransactionStatus */
private $updatesTransactionStatus;
+ /** @var UpdatesWallet */
+ private $updatesWallet;
/**
* CreateBookingLogic constructor.
@@ -39,11 +43,12 @@ class CallbackBillplzLogic
* @param FetchesTransaction $fetchesTransaction
* @param UpdatesTransactionStatus $updatesTransactionStatus
*/
- public function __construct(GetBillplzBill $getBillplzBill, FetchesTransaction $fetchesTransaction, UpdatesTransactionStatus $updatesTransactionStatus)
+ public function __construct(GetBillplzBill $getBillplzBill, FetchesTransaction $fetchesTransaction, UpdatesTransactionStatus $updatesTransactionStatus, UpdatesWallet $updatesWallet)
{
$this->getBillplzBill = $getBillplzBill;
$this->fetchesTransaction = $fetchesTransaction;
$this->updatesTransactionStatus = $updatesTransactionStatus;
+ $this->updatesWallet = $updatesWallet;
}
@@ -55,7 +60,6 @@ class CallbackBillplzLogic
*/
public function execute(Request $request)
{
-
$billplzXSignatureObject = new BillplzXSignatureObject($request);
if(!$billplzXSignatureObject->isValidSignature()){
@@ -70,6 +74,16 @@ class CallbackBillplzLogic
if($billPlz->state === 'paid') {
$status = ApprovalStatus::APPROVED;
+ if (
+ $transaction->owner_type == 'App\Models\Wallet' &&
+ $transaction->status == ApprovalStatus::PENDING_VERIFICATION
+ ) {
+ $wallet = $transaction->owner;
+ $updateWalletAmount = $wallet->amount + $transaction->amount;
+ $walletOject = new WalletObject($wallet->company->id, $wallet->currency_id, $wallet->code, $updateWalletAmount);
+ $wallet = $this->updatesWallet->execute($wallet, $walletOject);
+ }
+
}
if($billPlz->state === 'due') {
diff --git a/app/Classes/Modules/Bookings/ControllersLogic/AutoPurchaseOrderFillLogic.php b/app/Classes/Modules/Bookings/ControllersLogic/AutoPurchaseOrderFillLogic.php
new file mode 100644
index 00000000..ed9ec6d8
--- /dev/null
+++ b/app/Classes/Modules/Bookings/ControllersLogic/AutoPurchaseOrderFillLogic.php
@@ -0,0 +1,113 @@
+generatesPurchaseOrderProducts = $generatesPurchaseOrderProducts;
+ $this->generatesTransactionBillNumber = $generatesTransactionBillNumber;
+ $this->createPurchaseOrderTransactionProcessor = $createPurchaseOrderTransactionProcessor;
+ }
+
+
+ /**
+ * @return array
+ */
+ protected function notification():array {
+ return [
+ 'title' => 'Purchase Order Approval',
+ 'message' => 'You have successfully updated the Purchase order status'
+ ];
+ }
+
+ /** @var GeneratesPurchaseOrderProducts */
+ private $generatesPurchaseOrderProducts;
+
+ /** @var GeneratesTransactionBillNumber */
+ private $generatesTransactionBillNumber;
+
+ /** @var CreatePurchaseOrderTransactionProcessor */
+ private $createPurchaseOrderTransactionProcessor;
+
+
+ /**
+ * @param Request $request
+ * @return JsonResponse
+ * @throws \App\Classes\Exceptions\MalformedRequestException
+ */
+ public function logic(Request $request) : JsonResponse
+ {
+ $bookings = Booking::whereMonth('created_at', 7)
+ ->whereYear('created_at', 2021)
+ ->whereDoesntHave('transactions', function($q){
+ $q->where('type', TransactionType::PURCHASE_ORDER);
+ $q->whereIn('status', [ApprovalStatus::PENDING_VERIFICATION, ApprovalStatus::APPROVED]);
+ })->get();
+ foreach ($bookings as $booking) {
+ $po = Transaction::where('type', TransactionType::PURCHASE_ORDER)
+ ->where('status', ApprovalStatus::APPROVED)->where('issuer', $booking->company_id)
+ ->select('*', DB::raw('abs(amount - ' . $booking->fix_amount . ') as nearest_price'))->orderBy('nearest_price')->first();
+
+
+ if (!$po) {
+ $po = Transaction::where('type', TransactionType::PURCHASE_ORDER)
+ ->where('status', ApprovalStatus::APPROVED)->select('*', DB::raw('abs(amount - ' . $booking->fix_amount . ') as nearest_price'))->orderBy('nearest_price')->first();
+ }
+
+ $products = $this->generatesPurchaseOrderProducts->execute($po, $booking->fix_amount);
+
+ $deference = $booking->fix_amount - $products->sum('total');
+
+ if($deference > -150 && $deference < 150 && $deference != 0) {
+
+ $products->push([
+ 'description' => $deference < 0 ? 'Discount':'Shipping Fee',
+ 'quantity' => 1,
+ 'stockCode' => '',
+ 'total' => $deference,
+ 'unit_price' => $deference
+ ]);
+ }
+
+ $billNumber = $this->generatesTransactionBillNumber->execute('XPO-');
+
+ $total = $products->sum('total');
+
+ $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, $products->toArray());
+
+ $this->createPurchaseOrderTransactionProcessor->execute($booking, $object);
+ }
+
+ 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
index aa4c6f4d..9bab107f 100644
--- a/app/Classes/Modules/Transactions/ControllersLogic/CreatePurchaseOrderTransactionLogic.php
+++ b/app/Classes/Modules/Transactions/ControllersLogic/CreatePurchaseOrderTransactionLogic.php
@@ -7,6 +7,7 @@ use App\Classes\General\Abstracts\AbstractControllerLogic;
use App\Classes\Modules\Bookings\Services\FetchesBooking;
use App\Classes\Modules\Companies\Services\FetchesCompany;
use App\Classes\Modules\Transactions\DataTransferObjects\TransactionObject;
+use App\Classes\Modules\Transactions\Processors\CreatePurchaseOrderTransactionProcessor;
use App\Classes\Modules\Transactions\Services\CreatesTransaction;
use App\Classes\Modules\Transactions\Services\CreatesTransactionDetail;
use App\Classes\Modules\Transactions\Services\DeletesTransactionDetails;
@@ -25,26 +26,6 @@ use Illuminate\Http\Request;
class CreatePurchaseOrderTransactionLogic extends AbstractControllerLogic
{
- /**
- * CreatePurchaseOrderTransactionLogic constructor.
- * @param FetchesBooking $fetchesBooking
- * @param UpdatesTransactionStatus $updatesTransactionStatus
- * @param CreatesTransaction $createsTransaction
- * @param CreatesTransactionDetail $createsTransactionDetail
- * @param UpdatesTransaction $updatesTransaction
- * @param DeletesTransactionDetails $deletesTransactionDetails
- * @param GeneratesTransactionBillNumber $generatesTransactionBillNumber
- */
- public function __construct(FetchesBooking $fetchesBooking, UpdatesTransactionStatus $updatesTransactionStatus, CreatesTransaction $createsTransaction, CreatesTransactionDetail $createsTransactionDetail, UpdatesTransaction $updatesTransaction, DeletesTransactionDetails $deletesTransactionDetails, GeneratesTransactionBillNumber $generatesTransactionBillNumber)
- {
- $this->fetchesBooking = $fetchesBooking;
- $this->updatesTransactionStatus = $updatesTransactionStatus;
- $this->createsTransaction = $createsTransaction;
- $this->createsTransactionDetail = $createsTransactionDetail;
- $this->updatesTransaction = $updatesTransaction;
- $this->deletesTransactionDetails = $deletesTransactionDetails;
- $this->generatesTransactionBillNumber = $generatesTransactionBillNumber;
- }
/**
* @return array
@@ -59,37 +40,35 @@ class CreatePurchaseOrderTransactionLogic extends AbstractControllerLogic
/** @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;
+ /** @var CreatePurchaseOrderTransactionProcessor */
+ private $createPurchaseOrderTransactionProcessor;
+
+ /**
+ * CreatePurchaseOrderTransactionLogic constructor.
+ * @param FetchesBooking $fetchesBooking
+ * @param GeneratesTransactionBillNumber $generatesTransactionBillNumber
+ * @param CreatePurchaseOrderTransactionProcessor $createPurchaseOrderTransactionProcessor
+ */
+ public function __construct(FetchesBooking $fetchesBooking, GeneratesTransactionBillNumber $generatesTransactionBillNumber, CreatePurchaseOrderTransactionProcessor $createPurchaseOrderTransactionProcessor)
+ {
+ $this->fetchesBooking = $fetchesBooking;
+ $this->generatesTransactionBillNumber = $generatesTransactionBillNumber;
+ $this->createPurchaseOrderTransactionProcessor = $createPurchaseOrderTransactionProcessor;
+ }
/**
* @param Request $request
+ * @param string $id
* @return JsonResponse
* @throws \App\Classes\Exceptions\MalformedRequestException
*/
- public function logic(Request $request) : JsonResponse
+ public function logic(Request $request, $id = '') : JsonResponse
{
/** @var Booking $booking */
- $booking = $this->fetchesBooking->execute(['id' => $request->route('id')]);
-
- /** @var Transaction $transaction */
- $transaction = $booking->transactions()->where('type', TransactionType::PURCHASE_ORDER)->first();
+ $booking = $this->fetchesBooking->execute(['id' => $request->route('id') ?? $id]);
$billNumber = $this->generatesTransactionBillNumber->execute('PO-');
@@ -102,15 +81,8 @@ class CreatePurchaseOrderTransactionLogic extends AbstractControllerLogic
$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($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);
- }
+ $transaction = $this->createPurchaseOrderTransactionProcessor->execute($booking, $object);
return $this->resourceResponse(new TransactionResource($transaction));
diff --git a/app/Classes/Modules/Transactions/ControllersLogic/UpdatePaymentTransactionStatusLogic.php b/app/Classes/Modules/Transactions/ControllersLogic/UpdatePaymentTransactionStatusLogic.php
new file mode 100644
index 00000000..11f0a377
--- /dev/null
+++ b/app/Classes/Modules/Transactions/ControllersLogic/UpdatePaymentTransactionStatusLogic.php
@@ -0,0 +1,76 @@
+ 'Updated Transaction',
+ 'message' => 'You have successfully updated a transaction'
+ ];
+ }
+
+ /** @var FetchesTransaction */
+ private $fetchesTransaction;
+
+ /** @var UpdatesTransactionStatus */
+ private $updatesTransactionStatus;
+
+ /** @var DeletesDocument */
+ private $deletesDocument;
+
+ /**
+ * CreatePaymentVerificationDocumentLogic constructor.
+ * @param FetchesTransaction $fetchesTransaction
+ * @param UpdatesTransactionStatus $updatesTransactionStatus
+ * @param DeletesDocument $deletesDocument
+ */
+ public function __construct(FetchesTransaction $fetchesTransaction, UpdatesTransactionStatus $updatesTransactionStatus, DeletesDocument $deletesDocument)
+ {
+ $this->fetchesTransaction = $fetchesTransaction;
+ $this->updatesTransactionStatus = $updatesTransactionStatus;
+ $this->deletesDocument = $deletesDocument;
+ }
+
+ /**
+ * @param Request $request
+ * @return JsonResponse
+ * @throws \App\Classes\Exceptions\MalformedRequestException
+ */
+ public function logic(Request $request) : JsonResponse
+ {
+ $transaction = $this->fetchesTransaction->execute(['id' => $request->route('id')]);
+ $status = $request->route('status');
+
+ $this->updatesTransactionStatus->execute($transaction, $status === 'pending' ? ApprovalStatus::PENDING_VERIFICATION : ApprovalStatus::COMPLETED);
+
+ if ($status == 'pending') {
+ $document = $transaction->documents()->first();
+ if ($document) {
+ $this->deletesDocument->execute($document);
+ }
+ }
+
+ return $this->response([]);
+ }
+}
\ No newline at end of file
diff --git a/app/Classes/Modules/Transactions/Processors/CreatePurchaseOrderTransactionProcessor.php b/app/Classes/Modules/Transactions/Processors/CreatePurchaseOrderTransactionProcessor.php
new file mode 100644
index 00000000..76773c75
--- /dev/null
+++ b/app/Classes/Modules/Transactions/Processors/CreatePurchaseOrderTransactionProcessor.php
@@ -0,0 +1,76 @@
+updatesTransactionStatus = $updatesTransactionStatus;
+ $this->createsTransaction = $createsTransaction;
+ $this->createsTransactionDetail = $createsTransactionDetail;
+ $this->updatesTransaction = $updatesTransaction;
+ $this->deletesTransactionDetails = $deletesTransactionDetails;
+ }
+
+
+ /**
+ * @param Booking $booking
+ * @param TransactionObject $object
+ * @return Transaction|\Illuminate\Database\Eloquent\Model
+ * @throws \App\Classes\Exceptions\MalformedRequestException
+ */
+ public function execute(Booking $booking, TransactionObject $object){
+ /** @var Transaction $transaction */
+ $transaction = $booking->transactions()->where('type', TransactionType::PURCHASE_ORDER)->first();
+
+ !$transaction ? $transaction = $this->createsTransaction->execute($booking, $object) : $transaction = $this->updatesTransaction->execute($transaction, $object);
+
+ $this->updatesTransactionStatus->execute($transaction, (float) number_format($object->getAmount(), 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 $transaction;
+ }
+
+}
\ No newline at end of file
diff --git a/app/Classes/Modules/Transactions/Services/GeneratesPurchaseOrderProducts.php b/app/Classes/Modules/Transactions/Services/GeneratesPurchaseOrderProducts.php
new file mode 100644
index 00000000..16d162eb
--- /dev/null
+++ b/app/Classes/Modules/Transactions/Services/GeneratesPurchaseOrderProducts.php
@@ -0,0 +1,72 @@
+products = $products;
+ }
+
+
+ public function execute(Transaction $transaction, float $amount){
+
+ $products = collect();
+
+ $amountDifference = $amount - $transaction->amount;
+ $transactionDetails = $transaction->transactionDetails()->select('*', DB::raw('abs(price - '.abs($amountDifference).') as nearest_price'))->orderBy('nearest_price')->get();
+ foreach ($transactionDetails as $product) {
+ $units = floor(abs($amountDifference) / $product->price);
+ $quantity = $product->quantity;
+
+ if($product->price <= 0){
+ $amountDifference = $amountDifference + ($product->price * $product->quantity);
+ continue;
+ }
+
+ if($amountDifference > 0){
+ $quantity = $product->quantity + $units;
+ $amountDifference = $amountDifference - ($product->price * $units);
+ }
+
+ if($amountDifference < 0) {
+ $units = ceil(abs($amountDifference) / $product->price);
+ $quantity = $product->quantity - $units;
+
+ if($quantity <= 0){
+ $amountDifference = $amountDifference + ($product->price * $product->quantity);
+ continue;
+ }
+
+ $amountDifference = $amountDifference + ($product->price * $quantity);
+ }
+
+ $products->push([
+ 'description' => $product->product_name,
+ 'quantity' => (int) $quantity,
+ 'stockCode' => $product->product_code,
+ 'total' => $product->price * $quantity,
+ 'unit_price' => (float) $product->price,
+ ]);
+
+ }
+
+ return $products;
+
+ }
+
+}
\ No newline at end of file
diff --git a/app/Classes/Modules/Wallets/ControllersLogic/CreditWalletLogic.php b/app/Classes/Modules/Wallets/ControllersLogic/CreditWalletLogic.php
new file mode 100644
index 00000000..e2941c3c
--- /dev/null
+++ b/app/Classes/Modules/Wallets/ControllersLogic/CreditWalletLogic.php
@@ -0,0 +1,107 @@
+ 'Credit into Company Wallet',
+ 'message' => 'You have successfully credit company wallet'
+ ];
+ }
+
+
+ /** @var FetchesWallet */
+ private $fetchesWallet;
+
+ /** @var GeneratesTransactionBillNumber */
+ private $generatesTransactionBillNumber;
+
+ /** @var CreatesTransaction */
+ private $createsTransaction;
+
+ /** @var UpdatesWallet */
+ private $updatesWallet;
+
+ /**
+ * CreateWalletLogic constructor.
+ * @param FetchesWallet $fetchesWallet
+ * @param GeneratesTransactionBillNumber $generatesTransactionBillNumber
+ * @param CreatesTransaction $createsTransaction
+ * @param UpdatesWallet $updatesWallet
+ */
+ public function __construct(
+ FetchesWallet $fetchesWallet,
+ GeneratesTransactionBillNumber $generatesTransactionBillNumber,
+ CreatesTransaction $createsTransaction,
+ UpdatesWallet $updatesWallet
+ )
+ {
+ $this->fetchesWallet = $fetchesWallet;
+ $this->generatesTransactionBillNumber = $generatesTransactionBillNumber;
+ $this->createsTransaction = $createsTransaction;
+ $this->updatesWallet = $updatesWallet;
+ }
+
+ /**
+ * @param Request $request
+ * @return JsonResponse
+ * @throws ErrorException
+ */
+ public function logic(Request $request) : JsonResponse
+ {
+ $wallet = $this->fetchesWallet->execute(['id' => $request->input('wallet_id')]);
+
+ $billNumber = $this->generatesTransactionBillNumber->execute('DEBIT-NOTE-');
+
+ $transaction_object = new TransactionObject(
+ $billNumber,
+ TransactionType::CREDIT_NOTE,
+ 1,
+ $wallet->company->id,
+ 1,
+ PaymentMethodType::WALLET,
+ $request->input('amount'),
+ $request->input('amount'),
+ 1,
+ 1,
+ 1,
+ 0,
+ 0,
+ null,
+ ApprovalStatus::PENDING_SUBMISSION,
+ []
+ );
+
+ $transaction = $this->createsTransaction->execute($wallet, $transaction_object);
+ $updateWalletAmount = $wallet->amount + $transaction->amount;
+
+ $walletOject = new WalletObject($wallet->company->id, $wallet->currency_id, $wallet->code, $updateWalletAmount);
+
+ $wallet = $this->updatesWallet->execute($wallet, $walletOject);
+
+ return $this->resourceResponse(new WalletResource($wallet));
+ }
+}
diff --git a/app/Classes/Modules/Wallets/ControllersLogic/DebitWalletLogic.php b/app/Classes/Modules/Wallets/ControllersLogic/DebitWalletLogic.php
new file mode 100644
index 00000000..9437b320
--- /dev/null
+++ b/app/Classes/Modules/Wallets/ControllersLogic/DebitWalletLogic.php
@@ -0,0 +1,107 @@
+ 'Debit into Company Wallet',
+ 'message' => 'You have successfully debit company wallet'
+ ];
+ }
+
+
+ /** @var FetchesWallet */
+ private $fetchesWallet;
+
+ /** @var GeneratesTransactionBillNumber */
+ private $generatesTransactionBillNumber;
+
+ /** @var CreatesTransaction */
+ private $createsTransaction;
+
+ /** @var UpdatesWallet */
+ private $updatesWallet;
+
+ /**
+ * CreateWalletLogic constructor.
+ * @param FetchesWallet $fetchesWallet
+ * @param GeneratesTransactionBillNumber $generatesTransactionBillNumber
+ * @param CreatesTransaction $createsTransaction
+ * @param UpdatesWallet $updatesWallet
+ */
+ public function __construct(
+ FetchesWallet $fetchesWallet,
+ GeneratesTransactionBillNumber $generatesTransactionBillNumber,
+ CreatesTransaction $createsTransaction,
+ UpdatesWallet $updatesWallet
+ )
+ {
+ $this->fetchesWallet = $fetchesWallet;
+ $this->generatesTransactionBillNumber = $generatesTransactionBillNumber;
+ $this->createsTransaction = $createsTransaction;
+ $this->updatesWallet = $updatesWallet;
+ }
+
+ /**
+ * @param Request $request
+ * @return JsonResponse
+ * @throws ErrorException
+ */
+ public function logic(Request $request) : JsonResponse
+ {
+ $wallet = $this->fetchesWallet->execute(['id' => $request->input('wallet_id')]);
+
+ $billNumber = $this->generatesTransactionBillNumber->execute('DEBIT-NOTE-');
+
+ $transaction_object = new TransactionObject(
+ $billNumber,
+ TransactionType::DEBIT_NOTE,
+ 1,
+ $wallet->company->id,
+ 1,
+ PaymentMethodType::WALLET,
+ $request->input('amount'),
+ $request->input('amount'),
+ 1,
+ 1,
+ 1,
+ 0,
+ 0,
+ null,
+ ApprovalStatus::PENDING_SUBMISSION,
+ []
+ );
+
+ $transaction = $this->createsTransaction->execute($wallet, $transaction_object);
+ $updateWalletAmount = $wallet->amount - $transaction->amount;
+
+ $walletOject = new WalletObject($wallet->company->id, $wallet->currency_id, $wallet->code, $updateWalletAmount);
+
+ $wallet = $this->updatesWallet->execute($wallet, $walletOject);
+
+ return $this->resourceResponse(new WalletResource($wallet));
+ }
+}
diff --git a/app/Classes/Modules/Wallets/ControllersLogic/TopUpWalletLogic.php b/app/Classes/Modules/Wallets/ControllersLogic/TopUpWalletLogic.php
index 8497ec32..6149d69d 100644
--- a/app/Classes/Modules/Wallets/ControllersLogic/TopUpWalletLogic.php
+++ b/app/Classes/Modules/Wallets/ControllersLogic/TopUpWalletLogic.php
@@ -3,16 +3,19 @@
namespace App\Classes\Modules\Wallets\ControllersLogic;
use App\Classes\General\Abstracts\AbstractControllerLogic;
-
use App\Classes\Modules\Wallets\DataTransferObjects\WalletObject;
-use App\Classes\Modules\Wallets\Services\ListsWallet;
-use App\Classes\Modules\Wallets\Services\FetchesWallet;
+use App\Classes\Modules\Transactions\DataTransferObjects\TransactionObject;
+use App\Classes\Modules\Companies\Services\FetchesCompany;
+use App\Classes\Modules\Wallets\Services\CreatesWallet;
+use App\Classes\Modules\Wallets\Services\GeneratesWalletCode;
+use App\Classes\Modules\Transactions\Services\GeneratesTransactionBillNumber;
+use App\Classes\Modules\Billplzs\Services\CreatesBillplzBill;
+use App\Classes\Modules\Transactions\Services\CreatesTransaction;
use App\Classes\ValueObjects\Constants\TransactionType;
-
-use App\Classes\Modules\Wallets\Standards\Rules\CanTopUpWallet;
+use App\Classes\ValueObjects\Constants\PaymentMethodType;
+use App\Classes\ValueObjects\Constants\ApprovalStatus;
use App\Http\Resources\WalletResource;
-use App\Classes\Modules\Transactions\Processors\CreateWalletTransactionProcessor;
-
+use App\Http\Resources\WalletTransactionResource;
use ErrorException;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
@@ -30,26 +33,50 @@ class TopUpWalletLogic extends AbstractControllerLogic
];
}
- /** @var FetchesWallet */
- private $fetchesWallet;
- /** @var CanTopUpWallet */
- private $canTopUpWallet;
+ /** @var FetchesCompany */
+ private $fetchesCompany;
- /** @var CreateWalletTransactionProcessor */
- private $createWalletTransactionProcessor;
+ /** @var GeneratesWalletCode */
+ private $generatesWalletCode;
+
+ /** @var CreatesWallet */
+ private $createsWallet;
+
+ /** @var GeneratesTransactionBillNumber */
+ private $generatesTransactionBillNumber;
+
+ /** @var CreatesWalletTransaction */
+ private $createsWalletTransaction;
+
+ /** @var CreatesBillplzBill */
+ private $createsBillplzBill;
+
+ /** @var CreatesTransaction */
+ private $createsTransaction;
/**
* CreateWalletLogic constructor.
- * @param CreatesWallet $createsWallet
+ * @param FetchesCompany $fetchesCompany
* @param GeneratesWalletCode $generatesWalletCode
- * @param CanCreateCompanyWallet $canCreateCompanyWallet
+ * @param CreatesWallet $createsWallet
+ * @param GeneratesTransactionBillNumber $generatesTransactionBillNumber
*/
- public function __construct(CanTopUpWallet $canTopUpWallet, FetchesWallet $fetchesWallet, CreateWalletTransactionProcessor $createWalletTransactionProcessor)
+ public function __construct(
+ FetchesCompany $fetchesCompany,
+ GeneratesWalletCode $generatesWalletCode,
+ CreatesWallet $createsWallet,
+ GeneratesTransactionBillNumber $generatesTransactionBillNumber,
+ CreatesBillplzBill $createsBillplzBill,
+ CreatesTransaction $createsTransaction
+ )
{
- $this->canTopUpWallet = $canTopUpWallet;
- $this->fetchesWallet = $fetchesWallet;
- $this->createWalletTransactionProcessor = $createWalletTransactionProcessor;
+ $this->fetchesCompany = $fetchesCompany;
+ $this->generatesWalletCode = $generatesWalletCode;
+ $this->createsWallet = $createsWallet;
+ $this->generatesTransactionBillNumber = $generatesTransactionBillNumber;
+ $this->createsBillplzBill = $createsBillplzBill;
+ $this->createsTransaction = $createsTransaction;
}
/**
@@ -59,14 +86,47 @@ class TopUpWalletLogic extends AbstractControllerLogic
*/
public function logic(Request $request) : JsonResponse
{
- $wallet = $this->fetchesWallet->execute(['id' => $request->input('wallet_id')]);
+ $amount = floatval(str_replace(',', '', $request->input('amount')));
+ $company = $this->fetchesCompany->execute(['id' => $request->input('company_id')]);
+ if (!$company->wallets()->first()) {
+ $object = new WalletObject($company->id, 1, $this->generatesWalletCode->execute());
+ $wallet = $this->createsWallet->execute($object, $company);
+ }
- $walletOject = new WalletObject( $wallet->company->id, $wallet->currency_id, $wallet->code, $request->input('amount'));
+ $user = $company->employees()->first();
+ $billNumber = $this->generatesTransactionBillNumber->execute('TOPUP-');
+
+ $billPlzBill = $this->createsBillplzBill->execute(
+ $user->name,
+ $user->email,
+ 'This payment is made for wallet topup. ' . $company->reference,
+ $amount,
+ $billNumber,
+ $request->input('bank_code')
+ );
- $this->canTopUpWallet->passes($walletOject);
+ $transaction_object = new TransactionObject(
+ $billNumber,
+ TransactionType::TOP_UP,
+ 1,
+ $company->id,
+ 1,
+ PaymentMethodType::PAYMENT_GATEWAY,
+ $amount,
+ $amount,
+ 1,
+ 1,
+ 1,
+ 0,
+ 0,
+ null,
+ ApprovalStatus::PENDING_SUBMISSION,
+ [],
+ $billPlzBill->id
+ );
- $transaction = $this->createWalletTransactionProcessor->execute($wallet, $walletOject, TransactionType::TOP_UP);
+ $transaction = $this->createsTransaction->execute($company->wallets()->first(), $transaction_object);
- return $this->resourceResponse(new WalletResource($wallet));
+ return $this->resourceResponse(new WalletTransactionResource($transaction));
}
}
diff --git a/app/Classes/Modules/Wallets/Services/CreatesWallet.php b/app/Classes/Modules/Wallets/Services/CreatesWallet.php
index c114b9de..2a927e6d 100644
--- a/app/Classes/Modules/Wallets/Services/CreatesWallet.php
+++ b/app/Classes/Modules/Wallets/Services/CreatesWallet.php
@@ -21,8 +21,6 @@ class CreatesWallet extends AbstractUpdateRelationshipRecord
$model->code = $object->getCode();
$model->currency_id = $object->getCurrency();
-
return $this->handler($company->wallets(), $model);
-
}
}
diff --git a/app/Classes/ValueObjects/Constants/TransactionType.php b/app/Classes/ValueObjects/Constants/TransactionType.php
index 698abd76..040f63fa 100644
--- a/app/Classes/ValueObjects/Constants/TransactionType.php
+++ b/app/Classes/ValueObjects/Constants/TransactionType.php
@@ -24,5 +24,7 @@ final class TransactionType {
public const CREDIT_NOTE = 9;
+ public const DEBIT_NOTE = 11;
+
public const WITHDRAW = 10;
}
diff --git a/app/Http/Controllers/Bookings/AutoPurchaseOrderFillController.php b/app/Http/Controllers/Bookings/AutoPurchaseOrderFillController.php
new file mode 100644
index 00000000..c92900bd
--- /dev/null
+++ b/app/Http/Controllers/Bookings/AutoPurchaseOrderFillController.php
@@ -0,0 +1,25 @@
+login(User::find(1));
+ return $logic->execute($request);
+ }
+
+}
\ No newline at end of file
diff --git a/app/Http/Controllers/Transactions/UpdatePaymentTransactionStatusController.php b/app/Http/Controllers/Transactions/UpdatePaymentTransactionStatusController.php
new file mode 100644
index 00000000..047bc1dc
--- /dev/null
+++ b/app/Http/Controllers/Transactions/UpdatePaymentTransactionStatusController.php
@@ -0,0 +1,14 @@
+execute($request);
+ }
+}
\ No newline at end of file
diff --git a/app/Http/Controllers/Wallets/CreditWalletController.php b/app/Http/Controllers/Wallets/CreditWalletController.php
new file mode 100644
index 00000000..b3143588
--- /dev/null
+++ b/app/Http/Controllers/Wallets/CreditWalletController.php
@@ -0,0 +1,15 @@
+execute($request);
+ }
+}
diff --git a/app/Http/Controllers/Wallets/DebitWalletController.php b/app/Http/Controllers/Wallets/DebitWalletController.php
new file mode 100644
index 00000000..7feafb39
--- /dev/null
+++ b/app/Http/Controllers/Wallets/DebitWalletController.php
@@ -0,0 +1,15 @@
+execute($request);
+ }
+}
diff --git a/app/Http/Resources/CompanyResource.php b/app/Http/Resources/CompanyResource.php
index 54ab047d..5488df0e 100644
--- a/app/Http/Resources/CompanyResource.php
+++ b/app/Http/Resources/CompanyResource.php
@@ -60,10 +60,8 @@ class CompanyResource extends JsonResource
$segment = SegmentConstant::where('reference', SegmentConstants::SUPPLIER_CURRENCIES)->where('detail->id', $this->id)->first();
return $segment ? CurrencyResource::collection(Currency::whereIn('id', $segment->detail->currencies)->get()) : [];
}),
+ 'wallet' => WalletResource::collection($this->wallets),
'created_at' => $this->created_at->format('d-m-Y')
-
-
];
-
}
}
diff --git a/app/Http/Resources/TransactionResource.php b/app/Http/Resources/TransactionResource.php
index 58175802..6de5d391 100644
--- a/app/Http/Resources/TransactionResource.php
+++ b/app/Http/Resources/TransactionResource.php
@@ -43,7 +43,11 @@ class TransactionResource extends JsonResource
})),
'expires_on' => Carbon::parse($this->expires_on)->format('d-m-Y h:i:s A'),
- 'updated_at' => Carbon::parse($this->updated_at)->format('d-m-Y h:i:s A')
+ 'updated_at' => Carbon::parse($this->updated_at)->format('d-m-Y h:i:s A'),
+ 'interval' => [
+ 'value' => (Carbon::parse($this->created_at)->addDays(3)->gt(Carbon::now()) ) ? '+' : '-' ,
+ 'duration' => Carbon::parse($this->created_at)->addDays(3)->diff(Carbon::now())->format('%d'),
+ ],
];
}
}
diff --git a/app/Http/Resources/WalletResource.php b/app/Http/Resources/WalletResource.php
index 37ff5dbd..39c634eb 100644
--- a/app/Http/Resources/WalletResource.php
+++ b/app/Http/Resources/WalletResource.php
@@ -2,6 +2,7 @@
namespace App\Http\Resources;
+use App\Classes\ValueObjects\Constants\TransactionType;
use Illuminate\Http\Resources\Json\JsonResource;
class WalletResource extends JsonResource
@@ -19,7 +20,17 @@ class WalletResource extends JsonResource
'code' => $this->code,
'currency_id' => $this->currency_id,
'amount' => (double) $this->amount,
- 'company_id' => (int) $this->company_id
+ 'company_id' => (int) $this->owner->id,
+ 'transactions' => $this->transactions()->orderBy('id', 'DESC')->get(),
+ 'topup_transactions' => $this->transactions()->where('type', TransactionType::TOP_UP)->orderBy('id', 'DESC')->get(),
+
+ // 'transaction' => $this->whenLoaded('transactions', function() {
+ // return [
+ // 'topup' => $this->transactions
+ // ];
+ // }),
+ // 'transaction' // all
+ // 'top_transaction' // only topup
];
}
}
diff --git a/app/Http/Resources/WalletTransactionResource.php b/app/Http/Resources/WalletTransactionResource.php
index 1d0037fe..af634f3b 100644
--- a/app/Http/Resources/WalletTransactionResource.php
+++ b/app/Http/Resources/WalletTransactionResource.php
@@ -23,7 +23,8 @@ class WalletTransactionResource extends JsonResource
'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
+ 'currency_rate' => (double) $this->currency_rate,
+ 'reference' => $this->payment_reference
];
}
}
diff --git a/app/Models/Wallet.php b/app/Models/Wallet.php
index 52d8f718..29c3ddc9 100644
--- a/app/Models/Wallet.php
+++ b/app/Models/Wallet.php
@@ -2,13 +2,14 @@
namespace App\Models;
+use App\Classes\General\Interfaces\Transactionable;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\MorphTo;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\MorphMany;
-class Wallet extends AbstractModel
+class Wallet extends AbstractModel implements Transactionable
{
use SoftDeletes;
diff --git a/resources/assets/vue/components/accounts/forms/TopUpAccountComponent.vue b/resources/assets/vue/components/accounts/forms/TopUpAccountComponent.vue
deleted file mode 100644
index af8a43b7..00000000
--- a/resources/assets/vue/components/accounts/forms/TopUpAccountComponent.vue
+++ /dev/null
@@ -1,196 +0,0 @@
-
-
- Maybank2u
-
- Cimb
-
Wallet
+
Nothing To Show Here
+
Nothing To Show Here
+