mirror of
https://gitlab.com/uldvstar/exchange-2.0.git
synced 2026-08-19 04:24:16 +00:00
clean up wallet
This commit is contained in:
@@ -82,46 +82,35 @@ class CreditWalletLogic extends AbstractControllerLogic
|
||||
/**
|
||||
* @param Request $request
|
||||
* @return JsonResponse
|
||||
* @throws ErrorException
|
||||
* @throws \App\Classes\Exceptions\MalformedRequestException
|
||||
*/
|
||||
public function logic(Request $request) : JsonResponse
|
||||
{
|
||||
$amount = floatval(str_replace(',', '', $request->input('amount')));
|
||||
|
||||
$company = $this->fetchesCompany->execute(['id' => $request->input('company_id')]);
|
||||
|
||||
$reference = $request->input('reference');
|
||||
|
||||
$type = $request->input('transaction_type');
|
||||
|
||||
if (!$company->wallets()->first()) {
|
||||
$object = new WalletObject($company->id, 1, $this->generatesWalletCode->execute());
|
||||
$wallet = $this->createsWallet->execute($object, $company);
|
||||
$this->createsWallet->execute($object, $company);
|
||||
}
|
||||
|
||||
$wallet = $company->wallets()->first();
|
||||
|
||||
$billNumber = $this->generatesTransactionBillNumber->execute('CREDIT-NOTE-');
|
||||
$billNumber = $this->generatesTransactionBillNumber->execute($type === 2 ? 'DEBIT-NOTE-' : 'CREDIT-NOTE-');
|
||||
|
||||
$transaction_object = new TransactionObject(
|
||||
$billNumber,
|
||||
TransactionType::CREDIT_NOTE,
|
||||
1,
|
||||
$wallet->company->id,
|
||||
1,
|
||||
PaymentMethodType::WALLET,
|
||||
$amount,
|
||||
$amount,
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
0,
|
||||
0,
|
||||
null,
|
||||
ApprovalStatus::PENDING_SUBMISSION,
|
||||
[]
|
||||
);
|
||||
|
||||
$transaction_object = new TransactionObject($billNumber, $type === 2 ? TransactionType::DEBIT_NOTE : TransactionType::CREDIT_NOTE, 1, $wallet->company->id, 1, PaymentMethodType::CASH, $amount, $amount, 1, 1, 1, 0, 0, null, ApprovalStatus::APPROVED, [], $reference);
|
||||
$transaction = $this->createsTransaction->execute($wallet, $transaction_object);
|
||||
$updateWalletAmount = $wallet->amount + $transaction->amount;
|
||||
|
||||
$walletOject = new WalletObject($wallet->company->id, $wallet->currency_id, $wallet->code, $updateWalletAmount);
|
||||
$updateWalletAmount = $type === 2 ? ($wallet->amount - $transaction->amount) : ($wallet->amount + $transaction->amount);
|
||||
|
||||
$wallet = $this->updatesWallet->execute($wallet, $walletOject);
|
||||
$walletObject = new WalletObject($wallet->company->id, $wallet->currency_id, $wallet->code, $updateWalletAmount);
|
||||
|
||||
$wallet = $this->updatesWallet->execute($wallet, $walletObject);
|
||||
|
||||
return $this->resourceResponse(new WalletResource($wallet));
|
||||
}
|
||||
|
||||
@@ -68,12 +68,14 @@ class DebitWalletLogic extends AbstractControllerLogic
|
||||
/**
|
||||
* @param Request $request
|
||||
* @return JsonResponse
|
||||
* @throws ErrorException
|
||||
* @throws \App\Classes\Exceptions\MalformedRequestException
|
||||
*/
|
||||
public function logic(Request $request) : JsonResponse
|
||||
{
|
||||
$amount = floatval(str_replace(',', '', $request->input('amount')));
|
||||
$company = $this->fetchesCompany->execute(['id' => $request->input('company_id')]);
|
||||
$reference = $request->input('reference');
|
||||
|
||||
if (!$company->wallets()->first()) {
|
||||
$object = new WalletObject($company->id, 1, $this->generatesWalletCode->execute());
|
||||
$wallet = $this->createsWallet->execute($object, $company);
|
||||
@@ -89,7 +91,7 @@ class DebitWalletLogic extends AbstractControllerLogic
|
||||
1,
|
||||
$wallet->company->id,
|
||||
1,
|
||||
PaymentMethodType::WALLET,
|
||||
PaymentMethodType::CASH,
|
||||
$amount,
|
||||
$amount,
|
||||
1,
|
||||
@@ -98,8 +100,9 @@ class DebitWalletLogic extends AbstractControllerLogic
|
||||
0,
|
||||
0,
|
||||
null,
|
||||
ApprovalStatus::PENDING_SUBMISSION,
|
||||
[]
|
||||
ApprovalStatus::APPROVED,
|
||||
[],
|
||||
$reference
|
||||
);
|
||||
|
||||
$transaction = $this->createsTransaction->execute($wallet, $transaction_object);
|
||||
|
||||
@@ -21,16 +21,8 @@ class WalletResource extends JsonResource
|
||||
'currency_id' => $this->currency_id,
|
||||
'amount' => (double) $this->amount,
|
||||
'company_id' => (int) $this->owner->id,
|
||||
'transactions' => $this->transactions()->whereIn('status', [2, 3])->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
|
||||
'transactions' => WalletTransactionResource::collection($this->transactions()->whereIn('status', [2, 3])->orderBy('id', 'DESC')->get()),
|
||||
'top_up_records' => WalletTransactionResource::collection($this->transactions()->where('type', TransactionType::TOP_UP)->orderBy('id', 'DESC')->get())
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,10 @@
|
||||
|
||||
namespace App\Http\Resources;
|
||||
|
||||
use App\Classes\General\Eloquent\Filters\TransactionServiceId;
|
||||
use App\Classes\ValueObjects\Constants\TransactionType;
|
||||
use App\Models\Transaction;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class WalletTransactionResource extends JsonResource
|
||||
@@ -14,17 +18,38 @@ class WalletTransactionResource extends JsonResource
|
||||
*/
|
||||
public function toArray($request)
|
||||
{
|
||||
$description = '';
|
||||
switch((int) $this->type){
|
||||
case 5:
|
||||
$description = (double) $this->amount.' Credit Top up';
|
||||
break;
|
||||
case 9:
|
||||
$description = 'Credit Voucher for '.$this->payment_reference;
|
||||
break;
|
||||
case 1:
|
||||
$marking = Transaction::where('payment_reference', $this->bill_no)->first()->owner->marking;
|
||||
$description = 'Payment For booking refs.'.'<a href="'.route('booking.details', $marking).'">'.$marking.'</a>';
|
||||
break;
|
||||
case 11:
|
||||
$description = 'Debit Voucher for '.$this->payment_reference;
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'wallet_id' => (int) $this->wallet_id,
|
||||
'bill_no' => (int) $this->bill_no,
|
||||
'trans_type'=>(int) $this->trans_type,
|
||||
'type' => (int) $this->type,
|
||||
'bill_no' => $this->bill_no,
|
||||
'reference' => $this->payment_reference,
|
||||
'payment_method' => (float) $this->payment_method,
|
||||
'issuer_name' => $this->issuerCompany->name,
|
||||
'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,
|
||||
'reference' => $this->payment_reference
|
||||
'service_charge' => (double) $this->service_charge,
|
||||
'tax' => (double) $this->tax,
|
||||
'status' => (int) $this->status,
|
||||
'description' => $description,
|
||||
'details' => TransactionDetailResource::collection($this->transactionDetails),
|
||||
'updated_at' => Carbon::parse($this->updated_at)->format('d-m-Y h:i:s A'),
|
||||
'created_at' => Carbon::parse($this->created_at)->format('d-m-Y h:i:s A')
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@
|
||||
<div class="col text-right">
|
||||
<div class="font-heading fs-10 muted all-caps">Amount</div>
|
||||
<div class="font-heading fs-14 text-success bold">
|
||||
{{(Math.round((item.original_amount + Number.EPSILON) * 100) / 100).toFixed(2).toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",")}}
|
||||
{{(Math.round((item.amount + Number.EPSILON) * 100) / 100).toFixed(2).toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",")}}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
+25
-13
@@ -9,23 +9,22 @@
|
||||
<h6>Transaction History</h6>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row" v-if="company.wallet">
|
||||
<div class="col">
|
||||
<div class="row padding-10">
|
||||
<div class="col-2 fs-10">Date</div>
|
||||
<div class="col-3 fs-10">Date</div>
|
||||
<div class="col fs-10">Description</div>
|
||||
<div class="col-2 fs-10">Incoming</div>
|
||||
<div class="col-2 fs-10">Outgoing</div>
|
||||
<div class="col-2 fs-10 d-none">Balance</div>
|
||||
<div class="col-2 fs-10 text-center">Incoming</div>
|
||||
<div class="col-2 fs-10 text-center">Outgoing</div>
|
||||
<div class="col-2 fs-10 text-right">Balance</div>
|
||||
</div>
|
||||
|
||||
<div class="row bg-white padding-10 m-b-10 rounded" v-for="item in company.wallet.transactions" v-bind:key="item.id" :data="item">
|
||||
<div class="col-2">{{item.created_at}}</div>
|
||||
<div class="col">{{[5, 9].includes(parseFloat(item.type)) ? 'Top Up' : 'Payment to bill'}} </div>
|
||||
<div class="col-2 text-success">{{[5].includes(parseFloat(item.type)) ? (Math.round((parseFloat(item.amount) + Number.EPSILON) * 100) / 100).toFixed(2).toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",") : ''}}</div>
|
||||
<div class="col-2 text-danger">{{[1].includes(parseFloat(item.type)) ? '- ' + (Math.round((parseFloat(item.amount) + Number.EPSILON) * 100) / 100).toFixed(2).toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",") : ''}}</div>
|
||||
<div class="col-2 d-none">Balance</div>
|
||||
<div class="row bg-white padding-10 m-b-10 rounded" v-for="(item, index) in company.wallet.transactions" v-bind:key="item.id" :data="item">
|
||||
<div class="col-3 fs-12">{{item.created_at}}</div>
|
||||
<div class="col fs-12" v-html="item.description"></div>
|
||||
<div class="col-2 text-success text-center">{{[5, 9].includes(parseFloat(item.type)) ? (Math.round((parseFloat(item.amount) + Number.EPSILON) * 100) / 100).toFixed(2).toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",") : ''}}</div>
|
||||
<div class="col-2 text-danger text-center">{{[1, 11].includes(parseFloat(item.type)) ? '- ' + (Math.round((parseFloat(item.amount) + Number.EPSILON) * 100) / 100).toFixed(2).toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",") : ''}}</div>
|
||||
<div class="col-2 text-right">{{remainingBalance(index)}}</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -64,11 +63,11 @@
|
||||
|
||||
<div class="row" v-if="company.wallet">
|
||||
<div class="col">
|
||||
<wallet-top-up-history-component v-for="item in company.wallet.topup_transactions" v-bind:key="item.id" :data="item"></wallet-top-up-history-component>
|
||||
<wallet-top-up-history-component v-for="item in company.wallet.top_up_records" v-bind:key="item.id" :data="item"></wallet-top-up-history-component>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row align-items-center justify-content-center p-t-50 p-b-50" v-if="!company.wallet || !company.wallet.topup_transactions.length">
|
||||
<div class="row align-items-center justify-content-center p-t-50 p-b-50" v-if="!company.wallet || !company.wallet.top_up_records.length">
|
||||
<div class="col-10">
|
||||
<div class="row align-items-center justify-content-center hint-text">
|
||||
<div class="col-4 hint-text"><img src="/images/not-found-illustration.png" class="w-100 hint-text"></div>
|
||||
@@ -132,6 +131,19 @@ export default {
|
||||
this.isLoading = true;
|
||||
this.submit(route('api.company.show', this.id), 'get', this.section, false, false)
|
||||
},
|
||||
remainingBalance(index) {
|
||||
let tempBalance = 0;
|
||||
|
||||
if(this.company.wallet){
|
||||
let transactions = this.company.wallet.transactions.slice().reverse();
|
||||
transactions.slice(0, transactions.length - index).map(function(transaction) {
|
||||
[1, 11].includes(transaction.type) ? tempBalance -= (transaction.amount) : tempBalance += (transaction.amount);
|
||||
return tempBalance
|
||||
}, 0);
|
||||
}
|
||||
|
||||
return (Math.round((tempBalance + Number.EPSILON) * 100) / 100).toFixed(2).toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
|
||||
},
|
||||
successHandler(response){
|
||||
this.isLoading = false;
|
||||
this.company = response.payload.data;
|
||||
|
||||
@@ -2,21 +2,33 @@
|
||||
<div class="row">
|
||||
<div class="col">
|
||||
<div class="row m-b-20 text-center" v-if="$store.getters.isSuperAdmin && creditable">
|
||||
<div class="col p-r-5">
|
||||
<div class="b-a b-grey bg-white p-t-20 p-b-20 p-l-45 p-r-45 pointer" :class="{ 'bg-success': transactionType === 1, 'text-white': transactionType === 1, 'b-grey': transactionType !== 1 }" @click="transactionType !== 1 ? transactionType = 1 : transactionType = 0">
|
||||
<p class="no-margin bold">Credit</p>
|
||||
<div class="col">
|
||||
<div class="row">
|
||||
<div class="col p-r-5">
|
||||
<div class="b-a b-grey bg-white p-t-20 p-b-20 p-l-45 p-r-45 pointer" :class="{ 'bg-success': parameters.transaction_type === 1, 'text-white': parameters.transaction_type === 1, 'b-grey': parameters.transaction_type !== 1 }" @click="parameters.transaction_type !== 1 ? parameters.transaction_type = 1 : parameters.transaction_type = 0">
|
||||
<p class="no-margin bold">Credit</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col p-l-5">
|
||||
<div class="b-a b-grey bg-white p-t-20 p-b-20 p-l-45 p-r-45 pointer" :class="{ 'bg-danger': parameters.transaction_type === 2, 'text-white': parameters.transaction_type === 2, 'b-grey': parameters.transaction_type !== 2 }" @click="parameters.transaction_type !== 2 ? parameters.transaction_type = 2 : parameters.transaction_type = 0">
|
||||
<p class="no-margin bold">Debit</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col p-l-5">
|
||||
<div class="b-a b-grey bg-white p-t-20 p-b-20 p-l-45 p-r-45 pointer" :class="{ 'bg-danger': transactionType === 2, 'text-white': transactionType === 2, 'b-grey': transactionType !== 2 }" @click="transactionType !== 2 ? transactionType = 2 : transactionType = 0">
|
||||
<p class="no-margin bold">Debit</p>
|
||||
<div class="row m-t-10" v-if="parameters.transaction_type !== 0">
|
||||
<div class="col text-left">
|
||||
<validation-wrapper-component :validator="$v.parameters.reference">
|
||||
<label>Reference</label>
|
||||
<input class="form-control" v-model="parameters.reference">
|
||||
</validation-wrapper-component>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col">
|
||||
<validation-wrapper-component :validator="$v.parameters.amount">
|
||||
<label>{{transactionType == 'debit' ? 'Withdraw' : 'Top Up'}} Amount (MYR)</label>
|
||||
<label>{{parameters.transaction_type == 'debit' ? 'Withdraw' : 'Top Up'}} Amount (MYR)</label>
|
||||
<input class="form-control" v-model.lazy="parameters.amount" v-money="{decimal: '.',thousands: ',', precision: 2}">
|
||||
</validation-wrapper-component>
|
||||
</div>
|
||||
@@ -75,7 +87,7 @@
|
||||
<script>
|
||||
import componentHandler from '../../../general/mixins/componentHandler';
|
||||
import {VMoney} from 'v-money'
|
||||
import { required, minValue} from "vuelidate/lib/validators";
|
||||
import { required, requiredIf, minValue} from "vuelidate/lib/validators";
|
||||
|
||||
export default {
|
||||
props: {
|
||||
@@ -91,10 +103,11 @@
|
||||
data(){
|
||||
return {
|
||||
isLoading: false,
|
||||
transactionType: 0,
|
||||
parameters: {
|
||||
company_id: this.data.id,
|
||||
amount: '0.00',
|
||||
transaction_type: 0,
|
||||
reference: ''
|
||||
}
|
||||
}
|
||||
},
|
||||
@@ -107,13 +120,16 @@
|
||||
amount: {
|
||||
required,
|
||||
minValue: 10.000,
|
||||
},
|
||||
reference: {
|
||||
required: requiredIf(function () { return this.parameters.transaction_type !== 0 })
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
successHandler(response){
|
||||
if (this.transactionType === 0) {
|
||||
if (this.parameters.transaction_type === 0) {
|
||||
window.location.href = this.route('billplz.bill', response.payload.data.reference) + '?auto_submit=true';
|
||||
return;
|
||||
}
|
||||
@@ -122,8 +138,8 @@
|
||||
submitForm() {
|
||||
this.isLoading = true;
|
||||
|
||||
if (this.transactionType !== 0 && this.creditable) {
|
||||
this.submit(this.route('api.wallet.'+(this.transactionType === 2 ? 'debit': 'credit')), 'post', '', true, true);
|
||||
if (this.parameters.transaction_type !== 0 && this.creditable) {
|
||||
this.submit(this.route('api.wallet.credit'), 'post', '', true, true);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -7,7 +7,6 @@ Route::group(['prefix' => 'wallets', 'namespace' => 'Wallets', 'as' => 'wallet.'
|
||||
Route::post('/create', 'CreateWalletController@create')->name('create');
|
||||
|
||||
Route::post('/topup', 'TopUpWalletController@topUp')->name('topup'); // user
|
||||
Route::post('/debit', 'DebitWalletController@debit')->name('debit'); //admin -
|
||||
Route::post('/credit', 'CreditWalletController@credit')->name('credit'); // admin +
|
||||
|
||||
Route::put('/{transaction_id}/update-status/{status}', 'UpdateStatusWalletController@updateStatus')->where('status', 'approve|reject')->name('approval');
|
||||
|
||||
Reference in New Issue
Block a user