mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/exchange-2.0.git
synced 2026-08-19 04:23:55 +00:00
-show remark and categorized in export refund booking
-make refund function available for internal only, not for customer
This commit is contained in:
@@ -73,6 +73,10 @@ class CreateBookingRefundLogic extends AbstractControllerLogic
|
||||
public function logic(Request $request) : JsonResponse
|
||||
{
|
||||
|
||||
if(auth()->user()->type === 3) {
|
||||
throw new MalformedRequestException('You do not have the permission to refund the order.');
|
||||
}
|
||||
|
||||
$transaction = $this->fetchesTransaction->execute(['id' => $request->route('payment_id')]);
|
||||
|
||||
$booking = $transaction->owner;
|
||||
|
||||
@@ -9,7 +9,7 @@ class CalculatesBookingRefundAmount
|
||||
{
|
||||
public function execute(Booking $booking, int $type, ?string $payment_reference = null): float
|
||||
{
|
||||
$refundAmounts = $booking->transactions()->payments()->get()->map(function ($payment) use ($type) {
|
||||
$refundAmounts = $booking->transactions()->payments()->complete()->get()->map(function ($payment) use ($type) {
|
||||
return $this->calculateRefundAmount($payment, $type);
|
||||
});
|
||||
|
||||
|
||||
@@ -117,7 +117,7 @@
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col">
|
||||
<div class="row" v-if="(Math.round((poTotal + Number.EPSILON) * 1000) / 1000).toFixed(3) > (Math.round((data.amount - data.payment_history[0].refunded_amount + Number.EPSILON) * 1000) / 1000).toFixed(3)">
|
||||
<div class="row" v-if="(Math.round((poTotal + Number.EPSILON) * 1000) / 1000).toFixed(3) > (Math.round((data.paid_amount + Number.EPSILON) * 1000) / 1000).toFixed(3)">
|
||||
<div class="col">
|
||||
<div class="alert alert-warning padding-15" role="alert" v-if="false">
|
||||
<div class="font-heading fs-12 all-caps bold m-b-15">Can't Complete Your Purchase Order ?</div>
|
||||
@@ -140,17 +140,17 @@
|
||||
<h6 class="font-heading all-caps bold">Total:</h6>
|
||||
</div>
|
||||
<div class="col-auto b-t b-grey p-t-10 p-r-0">
|
||||
<h6><span v-if="!submitted" class="bold m-r-5" :class="[{'text-danger' : (Math.round((poTotal + Number.EPSILON) * 1000) / 1000).toFixed(3) !== (Math.round((data.amount - data.payment_history[0].refunded_amount + Number.EPSILON) * 1000) / 1000).toFixed(3)}, {'text-success' : (Math.round((this.poTotal + Number.EPSILON) * 1000) / 1000).toFixed(3) === (Math.round((this.data.amount - data.payment_history[0].refunded_amount + Number.EPSILON) * 1000) / 1000).toFixed(3)}]">{{(Math.round(( poTotal + Number.EPSILON) * 1000) / 1000).toFixed(3)}}/</span><span class="text-primary bold m-l-5">{{(Math.round((data.amount - data.payment_history[0].refunded_amount + Number.EPSILON) * 1000) / 1000).toFixed(3)}} {{data.fixed_currency.short_code}}</span></h6>
|
||||
<h6><span v-if="!submitted" class="bold m-r-5" :class="[{'text-danger' : (Math.round((poTotal + Number.EPSILON) * 1000) / 1000).toFixed(3) !== (Math.round((data.paid_amount + Number.EPSILON) * 1000) / 1000).toFixed(3)}, {'text-success' : (Math.round((this.poTotal + Number.EPSILON) * 1000) / 1000).toFixed(3) === (Math.round((this.data.paid_amount + Number.EPSILON) * 1000) / 1000).toFixed(3)}]">{{(Math.round(( poTotal + Number.EPSILON) * 1000) / 1000).toFixed(3)}}/</span><span class="text-primary bold m-l-5">{{(Math.round((data.paid_amount + Number.EPSILON) * 1000) / 1000).toFixed(3)}} {{data.fixed_currency.short_code}}</span></h6>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row" v-if="poTotal > 0 && !submitted">
|
||||
<div class="col">
|
||||
<div class="row m-b-10">
|
||||
<div class="col">
|
||||
<button id="save-purchase-order" name="save-purchase-order" class="btn btn-xs all-caps b-rad-none btn-primary btn-block" @click="submitForm()">{{(Math.round((poTotal + Number.EPSILON) * 1000) / 1000).toFixed(3) !== (Math.round((data.amount - data.payment_history[0].refunded_amount + Number.EPSILON) * 1000) / 1000).toFixed(3) ? 'Save Purchase Order' : 'Save & Confirm'}}</button>
|
||||
<button id="save-purchase-order" name="save-purchase-order" class="btn btn-xs all-caps b-rad-none btn-primary btn-block" @click="submitForm()">{{(Math.round((poTotal + Number.EPSILON) * 1000) / 1000).toFixed(3) !== (Math.round((data.paid_amount + Number.EPSILON) * 1000) / 1000).toFixed(3) ? 'Save Purchase Order' : 'Save & Confirm'}}</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row" v-if="(Math.round((poTotal + Number.EPSILON) * 1000) / 1000).toFixed(3) !== data.amount - data.payment_history[0].refunded_amount">
|
||||
<div class="row" v-if="(Math.round((poTotal + Number.EPSILON) * 1000) / 1000).toFixed(3) !== data.paid_amount">
|
||||
<div class="col">
|
||||
<div class="fs-10">** you purchase order will be saved but wont be approved until your <span class="text-danger bold all-caps">purchase order's total</span> matches your <span class="text-success bold all-caps">transfer order's total</span>.</div>
|
||||
</div>
|
||||
@@ -285,7 +285,7 @@
|
||||
this.submit(route('api.transaction.po.import', this.data.id), 'post', this.section, true, true);
|
||||
},
|
||||
successHandler(){
|
||||
if((Math.round((this.poTotal + Number.EPSILON) * 1000) / 1000).toFixed(3) === (Math.round((this.data.amount - data.payment_history[0].refunded_amount + Number.EPSILON) * 1000) / 1000).toFixed(3)){
|
||||
if((Math.round((this.poTotal + Number.EPSILON) * 1000) / 1000).toFixed(3) === (Math.round((this.data.paid_amount + Number.EPSILON) * 1000) / 1000).toFixed(3)){
|
||||
this.submitted = true;
|
||||
}
|
||||
this.updateList()
|
||||
|
||||
@@ -105,7 +105,7 @@
|
||||
<small class="all-caps muted fs-10">Fully Refund</small>
|
||||
</div>
|
||||
<div class="col text-right">
|
||||
<a :href="route('orders.refunds')" target="_blank">
|
||||
<a :href="route('orders.refunds') + '?type=pre-full'" target="_blank">
|
||||
<button class="btn btn-success btn-xs">Export Refunded Transactions</button>
|
||||
</a>
|
||||
</div>
|
||||
@@ -123,6 +123,11 @@
|
||||
<div class="col">
|
||||
<small class="all-caps muted fs-10">Partial Refund</small>
|
||||
</div>
|
||||
<div class="col text-right">
|
||||
<a :href="route('orders.refunds') + '?type=pre-partial'" target="_blank">
|
||||
<button class="btn btn-success btn-xs">Export Refunded Transactions</button>
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col">
|
||||
@@ -142,7 +147,7 @@
|
||||
<small class="all-caps muted fs-10">Fully Refund</small>
|
||||
</div>
|
||||
<div class="col text-right">
|
||||
<a :href="route('orders.refunds')" target="_blank">
|
||||
<a :href="route('orders.refunds') + '?type=post-full'" target="_blank">
|
||||
<button class="btn btn-success btn-xs">Export Refunded Transactions</button>
|
||||
</a>
|
||||
</div>
|
||||
@@ -160,6 +165,11 @@
|
||||
<div class="col">
|
||||
<small class="all-caps muted fs-10">Partial Refund</small>
|
||||
</div>
|
||||
<div class="col text-right">
|
||||
<a :href="route('orders.refunds') + '?type=post-partial'" target="_blank">
|
||||
<button class="btn btn-success btn-xs">Export Refunded Transactions</button>
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col">
|
||||
|
||||
+32
-7
@@ -433,13 +433,27 @@ Route::get('/pending_orders', function(){
|
||||
echo '</table>';
|
||||
})->name('orders.pending');
|
||||
|
||||
Route::get('/approve_refunds', function(){
|
||||
Route::get('/approve_refunds', function(Request $request){
|
||||
$type = $request->query('type');
|
||||
$payments = Transaction::where('type', TransactionType::PAYMENT)->where('owner_type', Booking::class)->whereIn('status', [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED, ApprovalStatus::REFUNDED])
|
||||
->whereHas('transactions', function ($query) {
|
||||
return $query->where('type', TransactionType::REFUND)->where('status', ApprovalStatus::APPROVED);
|
||||
})
|
||||
->orderBy('updated_at', 'DESC')
|
||||
->get();
|
||||
->whereHas('transactions', function ($query) use ($type) {
|
||||
$query->where('type', TransactionType::REFUND)->where('status', ApprovalStatus::APPROVED);
|
||||
if (str_contains($type, 'partial')) {
|
||||
$query->whereColumn('original_amount', '!=','transactions.original_amount');
|
||||
} else {
|
||||
$query->whereColumn('original_amount', 'transactions.original_amount');
|
||||
}
|
||||
});
|
||||
|
||||
if (str_contains($type, 'post')) {
|
||||
$payments->whereHas('transactions', function($query) {
|
||||
$query->where('type', TransactionType::SUPPLIER_REFUND);
|
||||
});
|
||||
} else {
|
||||
$payments->whereDoesntHave('transactions', function($query) {
|
||||
$query->where('type', TransactionType::SUPPLIER_REFUND);
|
||||
});
|
||||
}
|
||||
|
||||
echo '<table>';
|
||||
echo '<tr>';
|
||||
@@ -452,12 +466,13 @@ Route::get('/approve_refunds', function(){
|
||||
echo '<td></td>';
|
||||
echo '<td colspan="2">Refunded Original Amount</td>';
|
||||
echo '<td></td>';
|
||||
echo '<td>Remark</td>';
|
||||
echo '<td>Service</td>';
|
||||
echo '<td>Last Updated At</td>';
|
||||
echo '<td>Bank Type</td>';
|
||||
echo '<td>Bank Holder Name</td>';
|
||||
echo '</tr>';
|
||||
foreach ($payments as $index => $payment){
|
||||
foreach ($payments->orderBy('updated_at', 'DESC')->get() as $index => $payment){
|
||||
$booking = $payment->owner;
|
||||
$original_refunds = floatval((App()->make(CalculatesBookingRefundAmount::class))->calculateRefundAmount($payment, $booking->fix_currency_id));
|
||||
$refunds = $original_refunds / $payment->currency_rate;
|
||||
@@ -471,6 +486,15 @@ Route::get('/approve_refunds', function(){
|
||||
$bankType = str_word_count($booking->bank->holder_name) > 4 ? 'Company' : 'Personal';
|
||||
}
|
||||
|
||||
$refundTransaction = $payment->transactions()->refunds()->whereIn('status', [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED])->first();
|
||||
$remark = $refundTransaction->original_amount === $payment->original_amount ? 'Fully Refund' : 'Partial Refund';
|
||||
|
||||
if (str_contains($type, 'post')) {
|
||||
$remark = 'Post ' . $remark;
|
||||
} else {
|
||||
$remark = 'Pre ' . $remark;
|
||||
}
|
||||
|
||||
echo '<tr>';
|
||||
echo '<td>'.($index + 1).'.</td>';
|
||||
echo '<td>'.$payment->updated_at->format('d-M-y').'</td>';
|
||||
@@ -483,6 +507,7 @@ Route::get('/approve_refunds', function(){
|
||||
echo '<td>'.$payment->original_currency->short_code.'</td>';
|
||||
echo '<td>'.number_format($original_refunds, 5, '.', '').'</td>';
|
||||
echo '<td></td>';
|
||||
echo '<td>'.$remark.'</td>';
|
||||
echo '<td>'.$booking->service->name.'</td>';
|
||||
echo '<td>'.$payment->updated_at->diffForHumans().'</td>';
|
||||
echo '<td>'.$bankType.'</td>';
|
||||
|
||||
Reference in New Issue
Block a user