mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/exchange-2.0.git
synced 2026-08-19 04:23:55 +00:00
company wallet transaction pagination
This commit is contained in:
@@ -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));
|
||||
|
||||
}
|
||||
|
||||
@@ -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,17 +11,15 @@
|
||||
<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>
|
||||
<list-component key="2" section="topUp" :endpoint="route('api.transaction.wallet.list')" :options="{status_in: [2, 3], owner_type: 'App\\Models\\Wallet', owner_id: wallet_id, per_page: 30}">
|
||||
<template slot="list" slot-scope="{data}">
|
||||
<customer-wallet-transaction-component :data="data" :deciamls="deciamls"></customer-wallet-transaction-component>
|
||||
</template>
|
||||
</list-component>
|
||||
</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="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>
|
||||
@@ -41,43 +39,47 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div> -->
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
<script>
|
||||
export default {
|
||||
props: {
|
||||
company: {
|
||||
type: Object,
|
||||
// company: {
|
||||
// type: Object,
|
||||
// required: true
|
||||
// },
|
||||
deciamls: {
|
||||
type: Number,
|
||||
required: true
|
||||
},
|
||||
deciamls: {
|
||||
wallet_id: {
|
||||
type: Number,
|
||||
required: true
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
remainingBalance(index) {
|
||||
let tempBalance = 0;
|
||||
// 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);
|
||||
}
|
||||
// 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 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, ",")
|
||||
}
|
||||
// return (Math.round((parseFloat(value) + Number.EPSILON) * 100) / 100).toFixed(2).toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",")
|
||||
// }
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
+6
-2
@@ -16,10 +16,10 @@
|
||||
</div>
|
||||
</div>
|
||||
<div v-show="!showingPreciseAmount">
|
||||
<customer-transaction-component :company="company" :deciamls="2"></customer-transaction-component>
|
||||
<customer-transaction-component :company="company" :deciamls="2" :wallet_id="wallet_id"></customer-transaction-component>
|
||||
</div>
|
||||
<div v-show="showingPreciseAmount">
|
||||
<customer-transaction-component :company="company" :deciamls="5"></customer-transaction-component>
|
||||
<customer-transaction-component :company="company" :deciamls="5" :wallet_id="wallet_id"></customer-transaction-component>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-3 m-l-15">
|
||||
@@ -70,6 +70,10 @@ export default {
|
||||
id: {
|
||||
type: Number,
|
||||
required: true
|
||||
},
|
||||
wallet_id: {
|
||||
type: Number,
|
||||
required: true
|
||||
}
|
||||
},
|
||||
data(){
|
||||
|
||||
+35
@@ -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
@@ -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');
|
||||
|
||||
Reference in New Issue
Block a user