list all customer transactions

This commit is contained in:
edmondlang
2023-06-29 21:24:21 +08:00
parent 4d71abd8be
commit ed0bcb34c4
7 changed files with 261 additions and 0 deletions
@@ -0,0 +1,61 @@
<?php
namespace App\Classes\Modules\Transactions\ControllersLogic;
use Illuminate\Http\Request;
use Illuminate\Http\JsonResponse;
use App\Classes\General\Abstracts\AbstractControllerLogic;
use App\Classes\ValueObjects\Constants\TransactionType;
use App\Http\Resources\PaymentTransactionResource;
use App\Models\Booking;
use App\Models\Company;
use App\Models\Transaction;
use App\Models\Wallet;
class FetchCompanyTransactionStatementLogic extends AbstractControllerLogic
{
/**
* @return array
*/
protected function notification(): array
{
return [
'title' => 'Retrieved Company Balance Account',
'message' => 'You have successfully retrieved company balance account'
];
}
/**
* FetchCompanyAccountBalanceLogic constructor.
*/
public function __construct()
{
}
public function logic(Request $request): JsonResponse
{
$companyId = $request->route('id');
$transactions = Transaction::where(function ($query) use ($companyId) {
$query
->where('type', TransactionType::PAYMENT)
->where('owner_type', Booking::class)
->whereHas('booking', function ($query) use ($companyId) {
$query->where('company_id', $companyId);
});
})
->orWhere(function ($query) use ($companyId) {
$query->whereHas('owner', function ($query) use ($companyId) {
$query->where('owner_id', $companyId);
$query->where('owner_type', Company::class);
})
->where('owner_type', Wallet::class)
->where('type', '!=', TransactionType::PAYMENT);
})
->orderBy('created_at', 'desc')
->get();
return $this->collectionResponse(PaymentTransactionResource::collection($transactions));
}
}
@@ -0,0 +1,21 @@
<?php
namespace App\Http\Controllers\Transactions;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use App\Classes\Modules\Transactions\ControllersLogic\FetchCompanyTransactionStatementLogic;
class FetchCompanyTransactionStatementController
{
/**
* @param Request $request
* @param FetchCompanyAccountBalanceLogic $logic
* @return JsonResponse
*/
public function fetch(Request $request, FetchCompanyTransactionStatementLogic $logic) : JsonResponse {
return $logic->execute($request);
}
}
@@ -0,0 +1,45 @@
<?php
namespace App\Http\Resources;
use App\Classes\ValueObjects\Constants\TransactionType;
use App\Models\Booking;
use Carbon\Carbon;
use Illuminate\Http\Resources\Json\JsonResource;
class PaymentTransactionResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @param \Illuminate\Http\Request $request
* @return array
*/
public function toArray($request)
{
$booking = in_array((int)$this->type, [TransactionType::BILL, TransactionType::REFUND])? $this->owner->owner : $this->owner;
return [
'id' => $this->id,
'booking_marking' => $booking->marking,
'type' => (int) $this->type,
'bill_no' => $this->bill_no,
'payment_reference' => $this->payment_reference,
'payment_method' => (float) $this->payment_method,
'recipient_bank_account' => new BankResource($booking->bank),
'issuer_name' => $this->issuerCompany->name,
'issuer_id' => $this->issuerCompany->id,
'amount' => (double) $this->amount,
'original_amount' => (double) $this->original_amount,
'currency' => new CurrencyResource($this->currency),
'original_currency' => new CurrencyResource($this->original_currency),
'service_charge' => (double) $this->service_charge,
'tax' => (double) $this->tax,
'currency_rate' => (double) $this->currency_rate,
'status' => (int) $this->status,
'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')
];
}
}
@@ -0,0 +1,120 @@
<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="transaction">
<div class="col">
<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>Transaction History</h6>
</div>
</div>
<div class="row" v-if="transaction">
<div class="col">
<div class="row padding-10">
<div class="col-2 fs-10">Date</div>
<div class="col-3 fs-10">Description</div>
<div class="col fs-10">Type</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, index) in transaction" v-bind:key="item.id" :data="item">
<div class="col-2 fs-12">{{item.created_at}}</div>
<div class="col-3 fs-12">{{ item.payment_reference ? item.payment_reference + ' - ' : '' }} {{convertPaymentMethod(item.payment_method)}} - <a :href="route('booking.details', item.booking_marking)">{{item.booking_marking}}</a></div>
<div class="col fs-12">{{ convertTransactionType(item.type) }}</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>
</div>
</div>
</div>
</div>
</template>
<script>
export default {
props: {
id: {
type: Number,
required: true
}
},
data(){
return {
section: 'customerTransactionSection',
isLoading: true,
transaction: null,
attention: false
}
},
computed: {
pendingQueue () {
return this.$store.getters.isInCompleteQueue(this.section);
}
},
watch: {
pendingQueue(inComplete){
if(inComplete){
this.fetchTransaction();
}
}
},
created(){
this.$store.dispatch('updateListQueue', {'name': this.section});
},
methods: {
fetchTransaction(){
this.isLoading = true;
this.submit(route('api.transaction.company.transaction.fetch', this.id), 'get', this.section, false, false)
},
convertTransactionType(type){
var transactionTypeArray = [];
transactionTypeArray[0] = 'Payment Attempt';
transactionTypeArray[1] = 'Payment';
transactionTypeArray[2] = 'Invoice';
transactionTypeArray[3] = 'Bill';
transactionTypeArray[4] = 'Proforma';
transactionTypeArray[5] = 'Top Up';
transactionTypeArray[6] = 'Refund';
transactionTypeArray[7] = 'Purchase Order';
transactionTypeArray[8] = 'Supplier Deliver';
transactionTypeArray[9] = 'Credit Note';
transactionTypeArray[11] = 'Debit Note';
transactionTypeArray[10] = 'Withdraw';
transactionTypeArray[12] = 'Transfer Fee';
transactionTypeArray[13] = 'Cash Back';
return transactionTypeArray[type];
},
convertPaymentMethod(paymentMethod){
var paymentMethodArray = [];
paymentMethodArray[1] = 'Cash';
paymentMethodArray[2] = 'Cheque';
paymentMethodArray[3] = 'ba';
paymentMethodArray[4] = 'Wallet';
paymentMethodArray[5] = 'Payment Gateway';
return paymentMethodArray[paymentMethod];
},
remainingBalance(index) {
let tempBalance = 0;
if(this.transaction){
let transactions = this.transaction.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.transaction = response.payload.data;
}
}
}
</script>
@@ -0,0 +1,8 @@
@extends('layouts.base_portal')
@section('inner_content')
<div class="row">
<div class="col">
<customer-transaction-history-section-component :id="{{$id}}"></customer-transaction-history-section-component>
</div>
</div>
@endsection
+1
View File
@@ -22,6 +22,7 @@ Route::group(['prefix' => 'transactions', 'namespace' => 'Transactions', 'as' =>
Route::get('wallet/list', 'ListWalletTransactionsController@list')->name('wallet.list');
Route::get('/company/{id}/account/balance', 'FetchCompanyAccountBalanceController@fetch')->name('company.account.balance');
Route::get('/company/{id}/transaction/fetch', 'FetchCompanyTransactionStatementController@fetch')->name('company.transaction.fetch');
Route::get('/bank/{id}/account/balance', 'FetchBankAccountBalanceController@fetch')->name('bank.account.balance');
+5
View File
@@ -74,6 +74,11 @@ Route::get('/customer/{marking}', function ($marking) {
return view('pages.customers.profile', ['id' => $id]);
})->name('customer.profile');
Route::get('/customer/{marking}/transactions', function ($marking) {
$id = \App\Models\Company::where('reference', '=', $marking)->first()->id;
return view('pages.transactions.history', ['id' => $id]);
})->name('transactions.history');
Route::get('/payments', function () {
return view('pages.payments');
})->name('payments');