filters update

This commit is contained in:
JiaSheng
2023-11-04 11:52:34 +08:00
parent c11f6dab7a
commit f98607bc32
3 changed files with 207 additions and 203 deletions
@@ -14,6 +14,7 @@ use App\Models\Booking;
use App\Models\Company;
use App\Models\Transaction;
use App\Models\Wallet;
use Carbon\Carbon;
use Illuminate\Support\Facades\DB;
class FetchCompanyTransactionStatementLogic extends AbstractControllerLogic
@@ -41,169 +42,196 @@ class FetchCompanyTransactionStatementLogic extends AbstractControllerLogic
$companyId = $request->route('id');
$filterArray = json_decode($request->input('filters'));
$transactions = Transaction::where(function ($query) use ($companyId) {
$query
->where('type', TransactionType::PAYMENT)
->where('owner_type', Booking::class)
->whereIn('status', [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED])
->where('payment_method', '!=', PaymentMethodType::WALLET)
->whereHas('booking', function ($q) use ($companyId) {
$q->where('company_id', $companyId);
});
})
->orWhere(function ($query) use ($companyId) {
$query->whereHas('owner', function ($q) use ($companyId) {
$q->where('owner_id', $companyId);
$q->where('owner_type', Company::class);
})
->where('owner_type', Wallet::class)
->whereIn('status', [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED]);
// ->where('type', '!=', TransactionType::PAYMENT);
})
->orWhere(function ($query) use ($companyId) {
$transactions = Transaction::where(function ($transactions) use ($companyId) {
$transactions->where(function ($query) use ($companyId) {
$query
->where('type', TransactionType::INVOICE)
->where('type', TransactionType::PAYMENT)
->where('owner_type', Booking::class)
->whereIn('status', [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED])
->where('payment_method', '!=', PaymentMethodType::WALLET)
->whereHas('booking', function ($q) use ($companyId) {
$q->where('company_id', $companyId);
});
})
->orWhere(function ($query) use ($companyId) {
$query->whereHas('owner', function ($q) use ($companyId) {
$q->where('owner_id', $companyId);
$q->where('owner_type', Company::class);
})
->where('owner_type', Wallet::class)
->whereIn('status', [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED]);
// ->where('type', '!=', TransactionType::PAYMENT);
})
->orWhere(function ($query) use ($companyId) {
$query
->where('type', TransactionType::INVOICE)
->where('owner_type', Booking::class)
->whereIn('status', [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED])
->where('payment_method', '!=', PaymentMethodType::WALLET)
->whereHas('booking', function ($q) use ($companyId) {
$q->where('company_id', $companyId);
});
});
})
->groupBy(
DB::raw(
'if (transactions.type = 2,transactions.owner_id,transactions.id)'
),
DB::raw(
'if (transactions.type = 2,transactions.type,transactions.id)'
)
})
->groupBy(
DB::raw(
'if (transactions.type = 2,transactions.owner_id,transactions.id)'
),
DB::raw(
'if (transactions.type = 2,transactions.type,transactions.id)'
)
->whereIn('status', [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED])
->orderBy('created_at', 'desc')
->paginate($filterArray->per_page);
)
->whereIn('status', [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED])
->orderBy('created_at', 'desc');
$total_incoming = Transaction::where(function ($query) use ($companyId, $transactions) {
$query->whereHas('owner', function ($q) use ($companyId) {
$q->where('owner_id', $companyId);
$q->where('owner_type', Company::class);
})
->where('owner_type', Wallet::class)
->whereIn('status', [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED])
->where('type', '!=', TransactionType::PAYMENT);
})
->orWhere(function ($query) use ($companyId, $transactions) {
$query
->where('type', TransactionType::INVOICE)
->where('owner_type', Booking::class)
->whereIn('status', [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED])
->where('payment_method', '!=', PaymentMethodType::WALLET)
->whereHas('booking', function ($q) use ($companyId) {
$q->where('company_id', $companyId);
});
})
->groupBy(
DB::raw(
'if (transactions.type = 2,transactions.owner_id,transactions.id)'
),
DB::raw(
'if (transactions.type = 2,transactions.type,transactions.id)'
)
)->get();
$total_incoming = $total_incoming->sum(function ($transaction) {
if ($transaction->type === TransactionType::INVOICE) {
return $transaction->amount / $transaction->currency_rate + $transaction->service_charge;
}
return $transaction->amount;
});
$total_outgoing = Transaction::where(function ($query) use ($companyId) {
$query
->where('type', TransactionType::PAYMENT)
->where('payment_method', '!=', PaymentMethodType::WALLET)
->where('owner_type', Booking::class)
->whereIn('status', [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED])
->whereHas('booking', function ($q) use ($companyId) {
$q->where('company_id', $companyId);
if (isset($filterArray->startDate)) {
$startDate = Carbon::createFromFormat('d-m-Y', $filterArray->startDate)->startOfDay();
$transactions = $transactions->where("created_at", '>=', $startDate);
}
if (isset($filterArray->endDate)) {
$endDate = Carbon::createFromFormat('d-m-Y', $filterArray->endDate)->endOfDay();
$transactions = $transactions->where("created_at", '<=', $endDate);
}
if (isset($filterArray->marking)) {
$transactions = $transactions->where('owner_type', Booking::class)
->whereHas('booking', function ($q) use ($filterArray) {
$q->where('marking', 'LIKE', '%'.$filterArray->marking.'%');
});
})
->orWhere(function ($query) use ($companyId, $transactions) {
}
$transactions = $transactions->paginate($filterArray->per_page);
if ($transactions->count() > 0) {
$total_incoming = Transaction::where(function ($query) use ($companyId) {
$query->whereHas('owner', function ($q) use ($companyId) {
$q->where('owner_id', $companyId);
$q->where('owner_type', Company::class);
})
->where('owner_type', Wallet::class)
->whereIn('status', [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED])
->where('type', TransactionType::PAYMENT);
->where('type', '!=', TransactionType::PAYMENT);
})
->sum('transactions.amount');
$currentBalance = $total_incoming - $total_outgoing;
$incoming = Transaction::where(function ($query) use ($companyId, $transactions) {
$query->whereHas('owner', function ($q) use ($companyId) {
$q->where('owner_id', $companyId);
$q->where('owner_type', Company::class);
})
->where('owner_type', Wallet::class)
->whereIn('status', [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED])
->where('id', '>', $transactions->first()->id)
->where('type', '!=', TransactionType::PAYMENT);
})
->orWhere(function ($query) use ($companyId, $transactions) {
->orWhere(function ($query) use ($companyId) {
$query
->where('type', TransactionType::INVOICE)
->where('owner_type', Booking::class)
->whereIn('status', [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED])
->where('payment_method', '!=', PaymentMethodType::WALLET)
->whereHas('booking', function ($q) use ($companyId) {
$q->where('company_id', $companyId);
});
})
->groupBy(
DB::raw(
'if (transactions.type = 2,transactions.owner_id,transactions.id)'
),
DB::raw(
'if (transactions.type = 2,transactions.type,transactions.id)'
)
)->get();
$total_incoming = $total_incoming->sum(function ($transaction) {
if ($transaction->type === TransactionType::INVOICE) {
return $transaction->amount / $transaction->currency_rate + $transaction->service_charge;
}
return $transaction->amount;
});
$total_outgoing = Transaction::where(function ($query) use ($companyId) {
$query
->where('type', TransactionType::INVOICE)
->where('type', TransactionType::PAYMENT)
->where('payment_method', '!=', PaymentMethodType::WALLET)
->where('owner_type', Booking::class)
->whereIn('status', [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED])
->where('payment_method', '!=', PaymentMethodType::WALLET)
->where('id', '>', $transactions->first()->id)
->whereHas('booking', function ($q) use ($companyId) {
$q->where('company_id', $companyId);
});
})
->groupBy(
DB::raw(
'if (transactions.type = 2,transactions.owner_id,transactions.id)'
),
DB::raw(
'if (transactions.type = 2,transactions.type,transactions.id)'
)
)->get();
->orWhere(function ($query) use ($companyId) {
$query->whereHas('owner', function ($q) use ($companyId) {
$q->where('owner_id', $companyId);
$q->where('owner_type', Company::class);
})
->where('owner_type', Wallet::class)
->whereIn('status', [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED])
->where('type', TransactionType::PAYMENT);
})
->sum('transactions.amount');
$incoming = $incoming->sum(function ($transaction) {
if ($transaction->type === TransactionType::INVOICE) {
return $transaction->amount / $transaction->currency_rate + $transaction->service_charge;
}
return $transaction->amount;
});
$outgoing = Transaction::where(function ($query) use ($companyId, $transactions) {
$query
->where('type', TransactionType::PAYMENT)
->where('payment_method', '!=', PaymentMethodType::WALLET)
->where('owner_type', Booking::class)
->whereIn('status', [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED])
->where('id', '>', $transactions->first()->id)
->whereHas('booking', function ($q) use ($companyId) {
$q->where('company_id', $companyId);
});
})
->orWhere(function ($query) use ($companyId, $transactions) {
$currentBalance = $total_incoming - $total_outgoing;
$incoming = Transaction::where(function ($query) use ($companyId, $transactions) {
$query->whereHas('owner', function ($q) use ($companyId) {
$q->where('owner_id', $companyId);
$q->where('owner_type', Company::class);
})
->where('owner_type', Wallet::class)
->whereIn('status', [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED])
->where('id', '>', $transactions->first()->id)
->where('type', TransactionType::PAYMENT);
->where('id', '>', $transactions->first()->id)
->where('type', '!=', TransactionType::PAYMENT);
})
->sum('transactions.amount');
$runningBalanceInReverse = $currentBalance - $incoming + $outgoing;
$request['running_balance'] = $runningBalanceInReverse;
->orWhere(function ($query) use ($companyId, $transactions) {
$query
->where('type', TransactionType::INVOICE)
->where('owner_type', Booking::class)
->whereIn('status', [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED])
->where('payment_method', '!=', PaymentMethodType::WALLET)
->where('id', '>', $transactions->first()->id)
->whereHas('booking', function ($q) use ($companyId) {
$q->where('company_id', $companyId);
});
})
->groupBy(
DB::raw(
'if (transactions.type = 2,transactions.owner_id,transactions.id)'
),
DB::raw(
'if (transactions.type = 2,transactions.type,transactions.id)'
)
)->get();
$incoming = $incoming->sum(function ($transaction) {
if ($transaction->type === TransactionType::INVOICE) {
return $transaction->amount / $transaction->currency_rate + $transaction->service_charge;
}
return $transaction->amount;
});
$outgoing = Transaction::where(function ($query) use ($companyId, $transactions) {
$query
->where('type', TransactionType::PAYMENT)
->where('payment_method', '!=', PaymentMethodType::WALLET)
->where('owner_type', Booking::class)
->whereIn('status', [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED])
->where('id', '>', $transactions->first()->id)
->whereHas('booking', function ($q) use ($companyId) {
$q->where('company_id', $companyId);
});
})
->orWhere(function ($query) use ($companyId, $transactions) {
$query->whereHas('owner', function ($q) use ($companyId) {
$q->where('owner_id', $companyId);
$q->where('owner_type', Company::class);
})
->where('owner_type', Wallet::class)
->whereIn('status', [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED])
->where('id', '>', $transactions->first()->id)
->where('type', TransactionType::PAYMENT);
})
->sum('transactions.amount');
$runningBalanceInReverse = $currentBalance - $incoming + $outgoing;
$request['running_balance'] = $runningBalanceInReverse;
if (isset($filterArray->marking)) {
$request['running_balance'] = 0;
}
}
return $this->collectionResponse(PaymentTransactionResource::collection($transactions));
}
@@ -37,6 +37,7 @@ class PaymentTransactionResource extends JsonResource
}
break;
case 2:
$booking_marking = $booking->marking;
$request['running_balance'] = bcsub($request['running_balance'], $this->amount / $this->currency_rate + $this->service_charge, 7);
break;
case 5:
@@ -12,7 +12,7 @@
<div class="row m-t-10 m-b-10">
<div class="col">
<div class="d-flex align-items-center h-100">
<span class="btn btn-md fs-11 bg-primary text-white fs-12 m-r-5" :class="[{'bg-primary-darker': showingPreciseAmount}]" @click="showingPreciseAmount=!showingPreciseAmount">{{ showingPreciseAmount ? 'Showing Precise Wallet Transaction' : 'Show Precise Wallet Transaction'}}</span>
<span class="btn btn-md fs-11 bg-primary text-white fs-12 m-r-5" :class="[{'bg-primary-darker': showingPreciseAmount}]" @click="showingPreciseAmount=!showingPreciseAmount">{{ showingPreciseAmount ? 'Showing Precise Transaction' : 'Show Precise Transaction'}}</span>
<a v-if="this.id" :href="route('company.transaction.export', this.id, 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>
@@ -23,6 +23,29 @@
</validation-wrapper-component>
</div>
</div>
<div class="row m-b-5" @keyup.enter="submitSearch">
<div class="col p-r-0">
<validation-wrapper-component :validator="$v.reference_no">
<label class="all-caps">Booking Reference</label>
<input type="text" class="form-control" v-model="reference_no">
</validation-wrapper-component>
</div>
<div class="col p-r-0">
<validation-wrapper-component :validator="$v.startDate">
<label class="all-caps">Start Date</label>
<date-picker-component v-model.lazy="startDate"></date-picker-component>
</validation-wrapper-component>
</div>
<div class="col p-r-0">
<validation-wrapper-component :validator="$v.endDate">
<label class="all-caps">End Date</label>
<date-picker-component v-model.lazy="endDate"></date-picker-component>
</validation-wrapper-component>
</div>
<div class="col col-md-auto d-flex justify-content-center align-items-center">
<button type="button" class="btn btn-lg btn-primary fs-11 w-100" @click="submitSearch()">Search</button>
</div>
</div>
<div class="row">
<div class="col">
<div class="row padding-10">
@@ -39,16 +62,6 @@
<customer-account-statement-transaction-section-component :data="data" :showingPreciseAmount="showingPreciseAmount" ></customer-account-statement-transaction-section-component>
</template>
</list-component>
<!-- <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">{{ convertTransactionType(item.type) }} {{ item.payment_reference ? ' - ' + item.payment_reference : '' }} <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 fs-12"><a :href="route('booking.details', item.booking_marking)">{{item.booking_marking}}</a></div>
<div class="col-2 text-success text-center" v-if="parseFloat(item.type) !== 2">{{[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-success text-center" v-if="parseFloat(item.type) === 2">{{(Math.round(((parseFloat(item.amount) / parseFloat(item.currency_rate) + parseFloat(item.service_charge)) + 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>
@@ -71,6 +84,9 @@ export default {
isLoading: false,
transaction: null,
attention: false,
reference_no: null,
startDate: null,
endDate: null,
showingPreciseAmount: false,
showingTransactionCount: 10,
options: {
@@ -78,17 +94,7 @@ export default {
}
}
},
computed: {
pendingQueue () {
// return this.$store.getters.isInCompleteQueue(this.section);
}
},
watch: {
pendingQueue(inComplete){
if(inComplete){
this.fetchTransaction();
}
},
showingTransactionCount() {
this.options.per_page = this.showingTransactionCount
this.key ++;
@@ -96,63 +102,32 @@ export default {
},
validations: {
showingTransactionCount: { },
},
created(){
this.$store.dispatch('updateListQueue', {'name': this.section});
reference_no: { },
startDate: { },
endDate: { },
},
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) {
if (transaction.type === 2) {
tempBalance += (transaction.amount / transaction.currency_rate + transaction.service_charge);
} else {
[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;
}
},
submitSearch() {
delete this.options.marking;
delete this.options.startDate;
delete this.options.endDate;
if (this.reference_no) {
this.options.marking = this.reference_no
}
if (this.startDate) {
this.options.startDate = this.startDate
}
if (this.endDate) {
this.options.endDate = this.endDate
}
this.key ++;
},
}
}
</script>