Merge branch 'company-wallet-transaction-pagination' of gitlab.com:CIEFWorldwideSdnBhd/exchange-2.0

This commit is contained in:
edmondlang
2023-09-27 00:15:51 +08:00
8 changed files with 140 additions and 90 deletions
@@ -5,8 +5,12 @@ namespace App\Classes\Modules\Transactions\ControllersLogic;
use App\Classes\General\Abstracts\AbstractControllerLogic;
use App\Classes\Modules\Transactions\Services\ListsTransactions;
use App\Classes\ValueObjects\Constants\ApprovalStatus;
use App\Classes\ValueObjects\Constants\TransactionType;
use App\Http\Resources\BookingResource;
use App\Http\Resources\WalletTransactionResource ;
use App\Models\Transaction;
use App\Models\Wallet;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
@@ -39,6 +43,24 @@ class ListWalletTransactionsLogic extends AbstractControllerLogic
$query = $this->listsTransactions->execute($this->listsTransactions->deserializeFilters($request->input('filters')));
if (str_contains($request->input('filters'), "owner_id") && $query->count() > 0) {
$currentWalletBalance = Wallet::find($query->first()->owner_id)->amount;
$incoming = Transaction::where('owner_type', $query->first()->owner_type)
->where('owner_id', $query->first()->owner_id)
->whereIn('status', [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED])
->whereIn('type', [TransactionType::TOP_UP, TransactionType::CREDIT_NOTE])
->where('id', '>', $query->first()->id)
->sum('amount');
$outgoing = Transaction::where('owner_type', $query->first()->owner_type)
->where('owner_id', $query->first()->owner_id)
->whereIn('status', [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED])
->whereIn('type', [TransactionType::PAYMENT, TransactionType::DEBIT_NOTE])
->where('id', '>', $query->first()->id)
->sum('amount');
$runningBalanceInReverse = $currentWalletBalance - $incoming + $outgoing;
$request['running_balance'] = $runningBalanceInReverse;
}
return $this->collectionResponse(WalletTransactionResource::collection($query));
}
+1 -1
View File
@@ -21,7 +21,7 @@ class WalletResource extends JsonResource
'currency_id' => $this->currency_id,
'amount' => (double) $this->amount,
'company_id' => (int) $this->owner->id,
'transactions' => $this->whenLoaded('transactions', WalletTransactionResource::collection($this->transactions()->whereIn('status', [2, 3])->orderBy('id', 'DESC')->get()), []),
// 'transactions' => $this->whenLoaded('transactions', WalletTransactionResource::collection($this->transactions()->whereIn('status', [2, 3])->orderBy('id', 'DESC')->get()), []),
'top_up_records' => $this->whenLoaded('transactions', WalletTransactionResource::collection($this->transactions()->whereNotIn('status', [0])->where('type', TransactionType::TOP_UP)->orderBy('id', 'DESC')->get()), []),
];
}
@@ -20,12 +20,15 @@ class WalletTransactionResource extends JsonResource
public function toArray($request)
{
$description = '';
$current_running_balance = $request['running_balance'];
switch((int) $this->type){
case 5:
$description = (double) $this->amount.' Credit Top up';
$request['running_balance'] = bcsub($request['running_balance'], $this->amount, 5);
break;
case 9:
$description = 'Credit Voucher for '.$this->payment_reference;
$request['running_balance'] = bcsub($request['running_balance'], $this->amount, 5);
break;
case 1:
$booking = Transaction::where('payment_reference', $this->bill_no)->first()->owner;
@@ -35,11 +38,13 @@ class WalletTransactionResource extends JsonResource
break;
}
$request['running_balance'] = bcadd($request['running_balance'], $this->amount, 5);
$marking = $booking->marking;
$description = 'Payment For booking refs.'.'<a href="'.route('booking.details', $marking).'">'.$marking.'</a>';
break;
case 11:
$description = 'Debit Voucher for '.$this->payment_reference;
$request['running_balance'] = bcadd($request['running_balance'], $this->amount, 5);
break;
}
@@ -53,6 +58,7 @@ class WalletTransactionResource extends JsonResource
'payment_method' => (float) $this->payment_method,
'issuer_name' => $this->issuerCompany->name,
'amount' => (double) $this->amount,
'running_balance' => (double) $current_running_balance,
'service_charge' => (double) $this->service_charge,
'tax' => (double) $this->tax,
'status' => (int) $this->status,
@@ -1,7 +1,7 @@
<template>
<div class="row">
<div class="col">
<div class="row" v-if="company.wallet">
<div class="row">
<div class="col">
<div class="row padding-10">
<div class="col-3 fs-10">Date</div>
@@ -11,35 +11,11 @@
<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, 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"><span v-html="item.description"></span> <a target=”_blank” v-if="[9,11].includes(item.type) " :href="route('transaction.credit_note.download', item.id)"><i class="fa fa-download fs-11 m-l-5 text-secondary hover-primary"></i></a></div>
<div class="col-2 text-success text-center">{{[5, 9].includes(parseFloat(item.type)) ? formatValue(item.amount) : ''}}</div>
<div class="col-2 text-danger text-center">{{[1, 11].includes(parseFloat(item.type)) ? '- ' + (formatValue(item.amount)) : ''}}</div>
<div class="col-2 text-right">{{remainingBalance(index)}}</div>
</div>
</div>
</div>
<div class="row align-items-center justify-content-center p-t-50 p-b-50" v-if="!company.wallet || !company.wallet.transactions.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>
</div>
<div class="row text-center">
<div class="col">
<div class="row m-t-20">
<div class="col">
<p class="all-caps no-margin fs-11" style="letter-spacing: 2px;">Nothing To Show Here</p>
</div>
</div>
<div class="row m-t-5 align-items-center justify-content-center">
<div class="col">
<small class="fs-9 muted all-caps font-lato" style="letter-spacing: 2px">There is no results found, Try adjusting your filters to find what you are looking for.</small>
</div>
</div>
</div>
</div>
<list-component :key="key" section="topUp" :endpoint="route('api.transaction.wallet.list')" :options="{status_in: [2, 3], owner_type: 'App\\Models\\Wallet', owner_id: wallet_id, per_page: showingTransactionCount}">
<template slot="list" slot-scope="{data}">
<customer-wallet-transaction-component :data="data" :deciamls="deciamls"></customer-wallet-transaction-component>
</template>
</list-component>
</div>
</div>
</div>
@@ -48,35 +24,26 @@
<script>
export default {
props: {
company: {
type: Object,
deciamls: {
type: Number,
required: true
},
deciamls: {
showingTransactionCount: {
required: true
},
wallet_id: {
type: Number,
required: true
}
},
methods: {
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 this.formatValue(tempBalance);
},
formatValue(value) {
if (this.deciamls != 2) {
return (Math.round((parseFloat(value) + Number.EPSILON) * 100000) / 100000).toLocaleString('en-US', { minimumFractionDigits: 5, maximumFractionDigits: 5 });
}
return (Math.round((parseFloat(value) + Number.EPSILON) * 100) / 100).toFixed(2).toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",")
data(){
return {
key: 1,
}
},
watch: {
showingTransactionCount() {
this.key ++;
}
}
}
@@ -1,56 +1,65 @@
<template>
<div class="row">
<div class="col">
<loading-component style="height: 200px; top: 0;" key="1" color="success" v-show="isLoading"></loading-component>
<div class="row" v-if="company">
<div class="row">
<div class="col-8">
<div class="row p-b-5 b-b b-grey m-b-10 m-l-0 m-r-0">
<div class="col no-padding">
<h6>Wallet Transaction History</h6>
</div>
</div>
<div class="row m-t-15 m-b-15">
<div class="row m-t-10 m-b-10">
<div class="col">
<span class="btn btn-md fs-11 bg-primary text-white fs-12 bold" :class="[{'bg-primary-darker': showingPreciseAmount}]" @click="showingPreciseAmount=!showingPreciseAmount">{{ showingPreciseAmount ? 'Showing Precise Wallet Transaction' : 'Show Precise Wallet Transaction'}}</span>
<a :href="route('wallet.details-export', company.reference, showingPreciseAmount)" target="_blank" class="btn btn-md btn-primary fs-11"><i class="fa fa-download m-r-5"></i>{{ showingPreciseAmount ? 'Download Precise Transaction' : 'Download Transaction'}}</a>
<div class="d-flex align-items-center h-100">
<span class="btn btn-md fs-11 bg-primary text-white fs-12 bold m-r-5" :class="[{'bg-primary-darker': showingPreciseAmount}]" @click="showingPreciseAmount=!showingPreciseAmount">{{ showingPreciseAmount ? 'Showing Precise Wallet Transaction' : 'Show Precise Wallet Transaction'}}</span>
<a v-if="company" :href="route('wallet.details-export', company.reference, showingPreciseAmount)" target="_blank" class="btn btn-md btn-primary fs-11"><i class="fa fa-download m-r-5"></i>{{ showingPreciseAmount ? 'Download Precise Transaction' : 'Download Transaction'}}</a>
</div>
</div>
<div class="col-2">
<validation-wrapper-component selectable :validator="$v.showingTransactionCount">
<label>Showing Rows</label>
<select-component :options="[5, 10, 20, 30, 50]" v-model="showingTransactionCount"></select-component>
</validation-wrapper-component>
</div>
</div>
<div v-show="!showingPreciseAmount">
<customer-transaction-component :company="company" :deciamls="2"></customer-transaction-component>
<customer-transaction-component :deciamls="2" :wallet_id="wallet_id" :showingTransactionCount="showingTransactionCount"></customer-transaction-component>
</div>
<div v-show="showingPreciseAmount">
<customer-transaction-component :company="company" :deciamls="5"></customer-transaction-component>
<customer-transaction-component :deciamls="5" :wallet_id="wallet_id" :showingTransactionCount="showingTransactionCount"></customer-transaction-component>
</div>
</div>
<div class="col-3 m-l-15">
<wallet-component :data="company" :creditable=true></wallet-component>
<div class="row m-t-20">
<div class="col">
<div class="row m-b-10">
<div class="col">
<div class="font-head fs-10 all-caps">Top Up Records</div>
</div>
</div>
<div class="row" v-if="company.wallet">
<div class="col">
<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.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>
<div v-if="!isLoading">
<wallet-component :data="company" :creditable=true></wallet-component>
<div class="row m-t-20">
<div class="col">
<div class="row m-b-10">
<div class="col">
<div class="font-head fs-10 all-caps">Top Up Records</div>
</div>
<div class="row text-center">
<div class="col">
<div class="row m-t-20">
<div class="col">
<p class="all-caps no-margin fs-11" style="letter-spacing: 2px;">Nothing To Show Here</p>
</div>
<div class="row" v-if="company.wallet">
<div class="col">
<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.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>
</div>
<div class="row text-center">
<div class="col">
<div class="row m-t-20">
<div class="col">
<p class="all-caps no-margin fs-11" style="letter-spacing: 2px;">Nothing To Show Here</p>
</div>
</div>
</div>
<div class="row m-t-5 align-items-center justify-content-center">
<div class="col">
<small class="fs-9 muted all-caps font-lato" style="letter-spacing: 2px">There is no results found, Try adjusting your filters to find what you are looking for.</small>
<div class="row m-t-5 align-items-center justify-content-center">
<div class="col">
<small class="fs-9 muted all-caps font-lato" style="letter-spacing: 2px">There is no results found, Try adjusting your filters to find what you are looking for.</small>
</div>
</div>
</div>
</div>
@@ -59,6 +68,7 @@
</div>
</div>
</div>
<loading-component style="height: 200px; top: 0;" key="1" color="success" v-show="isLoading"></loading-component>
</div>
</div>
</div>
@@ -70,6 +80,10 @@ export default {
id: {
type: Number,
required: true
},
wallet_id: {
type: Number,
required: true
}
},
data(){
@@ -78,6 +92,7 @@ export default {
isLoading: true,
company: null,
showingPreciseAmount: false,
showingTransactionCount: 10,
attention: false
}
},
@@ -93,6 +108,9 @@ export default {
}
}
},
validations: {
showingTransactionCount: { },
},
created(){
this.$store.dispatch('updateListQueue', {'name': this.section});
},
@@ -0,0 +1,35 @@
<template>
<div class="row bg-white padding-10 m-b-10 rounded">
<div class="col-3 fs-12">{{data.created_at}}</div>
<div class="col fs-12"><span v-html="data.description"></span> <a target=”_blank” v-if="[9,11].includes(data.type) " :href="route('transaction.credit_note.download', data.id)"><i class="fa fa-download fs-11 m-l-5 text-secondary hover-primary"></i></a></div>
<div class="col-2 text-success text-center">{{[5, 9].includes(parseFloat(data.type)) ? formatValue(data.amount) : ''}}</div>
<div class="col-2 text-danger text-center">{{[1, 11].includes(parseFloat(data.type)) ? '- ' + (formatValue(data.amount)) : ''}}</div>
<div class="col-2 text-right">{{formatValue(data.running_balance)}}</div>
</div>
</template>
<script>
import componentHandler from '../../../general/mixins/componentHandler';
export default {
props: {
data: {
required: true,
type: Object
},
deciamls: {
type: Number,
required: true
},
},
methods: {
formatValue(value) {
if (this.deciamls != 2) {
return (Math.round((parseFloat(value) + Number.EPSILON) * 100000) / 100000).toLocaleString('en-US', { minimumFractionDigits: 5, maximumFractionDigits: 5 });
}
return (Math.round((parseFloat(value) + Number.EPSILON) * 100) / 100).toFixed(2).toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",")
}
},
mixins: [componentHandler],
}
</script>
@@ -1,5 +1,5 @@
<div class="row">
<div class="col">
<customer-transaction-section-component :id="{{$id}}"></customer-transaction-section-component>
<customer-transaction-section-component :id="{{$id}}" :wallet_id="{{$wallet_id}}"></customer-transaction-section-component>
</div>
</div>
+4 -2
View File
@@ -227,8 +227,10 @@ Route::get('/fix_bills', function () {
})->name('products.random');
Route::get('/wallet/{marking}/details', function ($marking) {
$id = \App\Models\Company::where('reference', '=', $marking)->first()->id;
return view('pages.wallet.index', ['id' => $id]);
$company = \App\Models\Company::where('reference', '=', $marking)->first();
$id = $company->id;
$wallet_id = $company->wallets()->first()->id;
return view('pages.wallet.index', ['id' => $id, 'wallet_id' => $wallet_id]);
})->name('wallet.details');
Route::get('/wallet/{marking}/{is_precise}/export', 'Exports\ExportCustomersWalletTransactionToExcelController@export')->name('wallet.details-export');