mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/shipping-portal.git
synced 2026-08-19 12:34:18 +00:00
Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 4faf3064d1 | |||
| 7b89a8bff8 | |||
| cc246046b5 | |||
| f3d502ea9b | |||
| 8f626230eb | |||
| d7ef783443 |
@@ -21,6 +21,7 @@ use App\Classes\Modules\Orders\Processors\UpdateDoFromVTPortalProcessor;
|
||||
use App\Classes\Modules\Orders\Processors\UpdateDoFromYDPortalProcessor;
|
||||
use App\Classes\Modules\Transactions\Services\UpdatesTransactionStatus;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use App\Classes\Modules\Wallets\Processors\CreditWalletProcessor;
|
||||
|
||||
class CreatePaymentTransactionProcessor
|
||||
{
|
||||
@@ -49,6 +50,9 @@ class CreatePaymentTransactionProcessor
|
||||
/** @var UpdatesTransactionStatus */
|
||||
private $updatesTransactionStatus ;
|
||||
|
||||
/** @var CreditWalletProcessor */
|
||||
private $creditWalletProcessor ;
|
||||
|
||||
/**
|
||||
* @param FetchesTransaction $fetchesTransaction,
|
||||
* @param GeneratesTransactionBillNumber $generatesTransactionBillNumber,
|
||||
@@ -60,6 +64,7 @@ class CreatePaymentTransactionProcessor
|
||||
* @param UpdateDoFromVTPortalProcessor $updateDoFromVTPortalProcessor
|
||||
* @param UpdateDoFromYDPortalProcessor $updateDoFromYDPortalProcessor
|
||||
* @param UpdatesTransactionStatus $updatesTransactionStatus
|
||||
* @param CreditWalletProcessor $creditWalletProcessor
|
||||
*/
|
||||
public function __construct(
|
||||
GeneratesTransactionBillNumber $generatesTransactionBillNumber,
|
||||
@@ -69,6 +74,7 @@ class CreatePaymentTransactionProcessor
|
||||
UpdatesWalletBalance $updatesWalletBalance,
|
||||
UpdateDoFromVTPortalProcessor $updateDoFromVTPortalProcessor,
|
||||
UpdateDoFromYDPortalProcessor $updateDoFromYDPortalProcessor,
|
||||
CreditWalletProcessor $creditWalletProcessor,
|
||||
UpdatesTransactionStatus $updatesTransactionStatus
|
||||
)
|
||||
{
|
||||
@@ -79,6 +85,7 @@ class CreatePaymentTransactionProcessor
|
||||
$this->updatesWalletBalance = $updatesWalletBalance;
|
||||
$this->updateDoFromVTPortalProcessor = $updateDoFromVTPortalProcessor;
|
||||
$this->updateDoFromYDPortalProcessor = $updateDoFromYDPortalProcessor;
|
||||
$this->creditWalletProcessor = $creditWalletProcessor;
|
||||
$this->updatesTransactionStatus = $updatesTransactionStatus;
|
||||
}
|
||||
|
||||
@@ -174,6 +181,11 @@ class CreatePaymentTransactionProcessor
|
||||
|
||||
$payment_transaction = $this->createsPaymentTransaction->execute($invoice, $object);
|
||||
|
||||
// cief coins
|
||||
if ($approvalStatus == ApprovalStatus::APPROVED) {
|
||||
$wallet = $this->creditWalletProcessor->execute($company_module, transactionType::CIEF_COINS_CREDIT, $amount, 'Cief Coins Credit', 3); // TODO-cief-coins: pls confirm the reference
|
||||
}
|
||||
|
||||
return $payment_transaction;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,16 +3,12 @@
|
||||
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\Standards\Rules\CanListWallet;
|
||||
use App\Http\Resources\WalletResource;
|
||||
|
||||
use ErrorException;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use App\Classes\Modules\Wallets\Services\ListsWallets;
|
||||
|
||||
class ListWalletLogic extends AbstractControllerLogic
|
||||
{
|
||||
@@ -26,8 +22,8 @@ class ListWalletLogic extends AbstractControllerLogic
|
||||
];
|
||||
}
|
||||
|
||||
/** @var ListWallet */
|
||||
private $listsWallet;
|
||||
/** @var ListsWallets */
|
||||
private $listsWallets;
|
||||
|
||||
/** @var CanCreateCompanyWallet */
|
||||
private $canListWallet;
|
||||
@@ -38,10 +34,10 @@ class ListWalletLogic extends AbstractControllerLogic
|
||||
* @param GeneratesWalletCode $generatesWalletCode
|
||||
* @param CanCreateCompanyWallet $canCreateCompanyWallet
|
||||
*/
|
||||
public function __construct(CanListWallet $canListWallet, ListsWallet $listsWallet)
|
||||
public function __construct(CanListWallet $canListWallet, ListsWallets $listsWallets)
|
||||
{
|
||||
$this->canListWallet = $canListWallet;
|
||||
$this->listsWallet = $listsWallet;
|
||||
$this->listsWallets = $listsWallets;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -53,7 +49,7 @@ class ListWalletLogic extends AbstractControllerLogic
|
||||
{
|
||||
//$this->canListWallet->passes();
|
||||
|
||||
$query = $this->listsWallet->execute($this->listsWallet->deserializeFilters($request->input('filters')));
|
||||
$query = $this->listsWallets->execute($this->listsWallets->deserializeFilters($request->input('filters')));
|
||||
|
||||
return $this->collectionResponse(WalletResource::collection($query));
|
||||
}
|
||||
|
||||
@@ -79,19 +79,40 @@ class CreditWalletProcessor
|
||||
* @return \Illuminate\Database\Eloquent\Model
|
||||
* @throws \App\Classes\Exceptions\MalformedRequestException
|
||||
*/
|
||||
public function execute(CompanyModule $companyModule, int $transactionType, float $amount, string $reference)
|
||||
public function execute(CompanyModule $companyModule, int $transactionType, float $amount, string $reference, ?int $currencyId = 1)
|
||||
{
|
||||
if (!$companyModule->wallets()->first()) {
|
||||
$object = new WalletObject($companyModule->id, 1, $this->generatesWalletCode->execute());
|
||||
/** @var Wallet $wallet */
|
||||
$wallet = $companyModule->wallets()->where('currency_id', $currencyId)->first();
|
||||
|
||||
if (!$wallet) {
|
||||
$object = new WalletObject($companyModule->id, $currencyId, $this->generatesWalletCode->execute());
|
||||
$this->createsWallet->execute($object, $companyModule);
|
||||
$wallet = $companyModule->wallets()->where('currency_id', $currencyId)->first();
|
||||
}
|
||||
|
||||
/** @var Wallet $wallet */
|
||||
$wallet = $companyModule->wallets()->first();
|
||||
$billNumberPrefix = null;
|
||||
$transaction_object_transaction_type = $transactionType;
|
||||
switch ($transactionType) {
|
||||
case TransactionType::PAYMENT:
|
||||
$billNumberPrefix = 'DEBIT-NOTE-';
|
||||
$transaction_object_transaction_type = TransactionType::DEBIT_NOTE;
|
||||
break;
|
||||
case TransactionType::CIEF_COINS_CREDIT:
|
||||
$billNumberPrefix = 'COINS-CREDIT-'; // TODO-cief-coins: pls confirm the prefix
|
||||
break;
|
||||
case TransactionType::CIEF_COINS_DEBIT:
|
||||
$billNumberPrefix = 'COINS-DEBIT-'; // TODO-cief-coins: pls confirm the prefix
|
||||
break;
|
||||
default:
|
||||
$billNumberPrefix = 'CREDIT-NOTE-';
|
||||
$transaction_object_transaction_type = TransactionType::CREDIT_NOTE;
|
||||
break;
|
||||
}
|
||||
|
||||
$billNumber = $this->generatesTransactionBillNumber->execute($transactionType === 2 ? 'DEBIT-NOTE-' : 'CREDIT-NOTE-');
|
||||
$billNumber = $this->generatesTransactionBillNumber->execute($billNumberPrefix);
|
||||
|
||||
$transaction_object = new TransactionObject($billNumber, $transaction_object_transaction_type, 1, $wallet->owner->id, 1, PaymentMethodType::CASH, $amount, $amount, 1, 1, 1, 0, 0, null, ApprovalStatus::APPROVED, [], $reference);
|
||||
|
||||
$transaction_object = new TransactionObject($billNumber, $transactionType === 2 ? TransactionType::DEBIT_NOTE : TransactionType::CREDIT_NOTE, 1, $wallet->owner->id, 1, PaymentMethodType::CASH, $amount, $amount, 1, 1, 1, 0, 0, null, ApprovalStatus::APPROVED, [], $reference);
|
||||
$transaction = $this->createsTransactionableTransaction->execute($wallet, $transaction_object);
|
||||
|
||||
$this->updatesWalletBalance->execute($wallet, $transaction->amount);
|
||||
|
||||
+9
-6
@@ -2,28 +2,31 @@
|
||||
|
||||
namespace App\Classes\Modules\Wallets\Services;
|
||||
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
|
||||
use App\Classes\General\Eloquent\AbstractListRecord;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use App\Models\Wallet;
|
||||
|
||||
class ListsWallet extends AbstractListRecord
|
||||
class ListsWallets extends AbstractListRecord
|
||||
{
|
||||
/** @var Booking */
|
||||
|
||||
/** @var Wallet */
|
||||
private $repository;
|
||||
|
||||
/**
|
||||
* ListsBookings constructor.
|
||||
* @param Booking $repository
|
||||
* Wallet constructor.
|
||||
* @param Wallet $repository
|
||||
*/
|
||||
public function __construct(Wallet $repository)
|
||||
{
|
||||
$this->repository = $repository;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return Builder
|
||||
*/
|
||||
public function getRepository(): Builder
|
||||
function getRepository(): Builder
|
||||
{
|
||||
return $this->repository->newQuery();
|
||||
}
|
||||
@@ -27,11 +27,15 @@ class UpdatesWalletBalance extends AbstractUpdateRecord
|
||||
|
||||
foreach ($model->transactions as $transaction) {
|
||||
if (!in_array((int) $transaction->status, [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED])) continue;
|
||||
if ((int) $transaction->type === TransactionType::TOP_UP) $topups += (float) $transaction->amount;
|
||||
if ((int) $transaction->type === TransactionType::GROUP_PAYMENT) $topups += (float) $transaction->amount;
|
||||
if ((int) $transaction->type === TransactionType::CREDIT_NOTE) $credit += (float) $transaction->amount;
|
||||
if ((int) $transaction->type === TransactionType::PAYMENT) $payments += (float) $transaction->amount;
|
||||
if ((int) $transaction->type === TransactionType::DEBIT_NOTE) $debit += (float) $transaction->amount;
|
||||
if ((int) $transaction->type === TransactionType::TOP_UP) $topups += (float) $transaction->amount;
|
||||
if ((int) $transaction->type === TransactionType::GROUP_PAYMENT) $topups += (float) $transaction->amount;
|
||||
if ((int) $transaction->type === TransactionType::CREDIT_NOTE) $credit += (float) $transaction->amount;
|
||||
if ((int) $transaction->type === TransactionType::PAYMENT) $payments += (float) $transaction->amount;
|
||||
if ((int) $transaction->type === TransactionType::DEBIT_NOTE) $debit += (float) $transaction->amount;
|
||||
|
||||
// cief coins
|
||||
if ((int) $transaction->type === TransactionType::CIEF_COINS_CREDIT) $credit += (float) $transaction->amount;
|
||||
if ((int) $transaction->type === TransactionType::CIEF_COINS_DEBIT) $debit += (float) $transaction->amount;
|
||||
}
|
||||
$auditBalance = ($topups + $credit) - ($payments + $debit);
|
||||
|
||||
|
||||
@@ -42,4 +42,9 @@ final class TransactionType {
|
||||
];
|
||||
|
||||
public const STORAGE_INVOICE = 16;
|
||||
|
||||
public const CIEF_COINS_DEBIT = 17;
|
||||
|
||||
public const CIEF_COINS_CREDIT = 18;
|
||||
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<div class="col">
|
||||
<loading-component style="height: 300px; top: 0;" key="1" color="success" v-show="isLoading" ></loading-component>
|
||||
<!-- <div class="row parentContainer" v-if="item.status === 2"> -->
|
||||
<div class="row parentContainer" v-if="!isLoading">
|
||||
<div class="row parentContainer" v-if="!isLoading && wallet.cashWallet">
|
||||
<div class="col">
|
||||
<div class="row" v-if="!reload && section !== 'customerPaidInvoiceComponent'">
|
||||
<div class="col">
|
||||
@@ -11,7 +11,7 @@
|
||||
<div class="row align-items-end">
|
||||
<div class="col-auto">
|
||||
<div class="text-primary-lighter fs-10 text-uppercase">Wallet Balance</div>
|
||||
<h5 class="text-white no-margin bold">MYR {{ wallet ? (Math.round((wallet.amount + Number.EPSILON) * 100) / 100).toFixed(2) : '0.00'}}</h5>
|
||||
<h5 class="text-white no-margin bold">MYR {{ wallet.cashWallet ? (Math.round((wallet.cashWallet.amount + Number.EPSILON) * 100) / 100).toFixed(2) : '0.00'}}</h5>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row m-t-10 d-flex align-items-center">
|
||||
@@ -19,9 +19,9 @@
|
||||
<div class="btn btn-xs p-l-15 p-r-20 b-rad-none font-heading btn-rounded bg-white" @click="reload = true"><i class="fa fa-plus fs-8 m-r-5"></i> Reload</div>
|
||||
</div>
|
||||
<div class="col-auto p-l-0" v-else="$store.getters.isSuperAdmin"></div>
|
||||
<div class="col-auto p-l-0" v-if="!mini && wallet && section!=='CompanyWalletTransactionSection'">
|
||||
<!-- <a class="text-white fs-10" :href="route('wallet.details', wallet.company_module_marking)" target="_blank">Transaction History<i class="fa fa-angle-right p-l-5"></i></a> -->
|
||||
<a class="text-white fs-10" :href="route('wallet.details', wallet.company_module_marking)">Transaction History<i class="fa fa-angle-right p-l-5"></i></a>
|
||||
<div class="col-auto p-l-0" v-if="!mini && wallet.cashWallet && section!=='CompanyWalletTransactionSection'">
|
||||
<!-- <a class="text-white fs-10" :href="route('wallet.details', wallet.cashWallet.company_module_marking)" target="_blank">Transaction History<i class="fa fa-angle-right p-l-5"></i></a> -->
|
||||
<a class="text-white fs-10" :href="route('wallet.details', wallet.cashWallet.company_module_marking)">Transaction History<i class="fa fa-angle-right p-l-5"></i></a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -34,7 +34,25 @@
|
||||
<label class="fs-10 text-white m-b-0 text-uppercase cursor" @click="reload = false"><i class="fa fa-angle-left p-r-15"></i>Top Up Wallet</label>
|
||||
</div>
|
||||
</div>
|
||||
<wallet-top-up-form-component :company_module_id="company_module_id" :amount="(!wallet ? amount : (Math.round((((amount - wallet.amount) < '0.00' ? '0.00' : (amount - wallet.amount)) + Number.EPSILON) * 100) / 100).toFixed(2))" :creditable="creditable"></wallet-top-up-form-component>
|
||||
<wallet-top-up-form-component :company_module_id="company_module_id" :amount="(!wallet.cashWallet ? amount : (Math.round((((amount - wallet.cashWallet.amount) < '0.00' ? '0.00' : (amount - wallet.cashWallet.amount)) + Number.EPSILON) * 100) / 100).toFixed(2))" :creditable="creditable"></wallet-top-up-form-component>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<br>
|
||||
|
||||
<div class="row parentContainer" v-if="!isLoading && wallet.coinWallet">
|
||||
<div class="col">
|
||||
<div class="row" v-if="!reload && section !== 'customerPaidInvoiceComponent'">
|
||||
<div class="col">
|
||||
<div style="background-color:#1fa67a !important" :class="[{'padding-25': !mini}, {'padding-15': mini}]">
|
||||
<div class="row align-items-end">
|
||||
<div class="col-auto">
|
||||
<div class="text-primary-lighter fs-10 text-uppercase">Coins Balance</div>
|
||||
<h5 class="text-white no-margin bold"><i class="fa fa-creative-commons m-r-5"></i> {{ wallet.coinWallet ? wallet.coinWallet.amount : '0.00'}}</h5>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -99,12 +117,18 @@
|
||||
methods: {
|
||||
fetchCompany(){
|
||||
this.isLoading = true;
|
||||
this.submit(route('api.wallet.company_module.show', this.company_module_id), 'get', this.section, false, false);
|
||||
var filters = {'owner_id': this.company_module_id};
|
||||
this.submit(route('api.wallet.list') + '?filters=' + JSON.stringify(filters), 'get', this.section, false, false);
|
||||
// this.submit(route('api.wallet.company_module.show', this.company_module_id), 'get', this.section, false, false);
|
||||
},
|
||||
successHandler(response){
|
||||
this.$store.dispatch('completeList', {'name': this.section, 'data': []});
|
||||
this.isLoading = false;
|
||||
this.wallet = response.payload.data;
|
||||
this.wallet = response.payload.data.reduce((acc, item) => {
|
||||
if (item.currency_id === 1) acc.cashWallet = item;
|
||||
else if (item.currency_id === 3) acc.coinWallet = item;
|
||||
return acc;
|
||||
}, {});
|
||||
},
|
||||
errorHandler(error){
|
||||
this.isLoading = false;
|
||||
|
||||
Reference in New Issue
Block a user