mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/exchange-2.0.git
synced 2026-08-19 04:23:55 +00:00
resolve supplier refund amount to follow white form rate
This commit is contained in:
@@ -1,24 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\General\Eloquent\Filters;
|
||||
|
||||
use App\Classes\ValueObjects\Constants\TransactionType;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
|
||||
class BelongsToSupplierId implements Filter
|
||||
{
|
||||
|
||||
/**
|
||||
* @param Builder $builder
|
||||
* @param $value
|
||||
* @return mixed
|
||||
*/
|
||||
public static function apply(Builder $builder, $value)
|
||||
{
|
||||
return $builder->whereHas('owner', function ($q) use ($value) {
|
||||
$q->whereHas('transactions', function ($q2) use ($value) {
|
||||
$q2->where('type', TransactionType::BILL)->where('issuer', $value);
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\General\Eloquent\Filters;
|
||||
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
|
||||
class CurrencyRateIsNotEqual implements Filter
|
||||
{
|
||||
|
||||
/**
|
||||
* @param Builder $builder
|
||||
* @param $value
|
||||
* @return Builder|mixed
|
||||
*/
|
||||
public static function apply(Builder $builder, $value)
|
||||
{
|
||||
return $builder->where('currency_rate', '!=', $value);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\General\Eloquent\Filters;
|
||||
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
|
||||
class ReceiverIn implements Filter
|
||||
{
|
||||
|
||||
/**
|
||||
* @param Builder $builder
|
||||
* @param $value
|
||||
* @return Builder|mixed
|
||||
*/
|
||||
public static function apply(Builder $builder, $value)
|
||||
{
|
||||
return $builder->whereIn('receiver', $value);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -88,7 +88,8 @@ class CreateBookingRefundLogic extends AbstractControllerLogic
|
||||
|
||||
$refundAmount = bcdiv($request->input('amount'), $transaction->currency_rate, 7);
|
||||
// refund service charges if is fully refund
|
||||
$refundTotal = ($refund + $request->input('amount')) == $transaction->original_amount ? $refundAmount + $transaction->service_charge + $transaction->tax : $refundAmount;
|
||||
$isFullyRefund = ($refund + $request->input('amount')) == $transaction->original_amount;
|
||||
$refundTotal = $isFullyRefund ? $refundAmount + $transaction->service_charge + $transaction->tax : $refundAmount;
|
||||
|
||||
$object = new TransactionObject($billNumber, TransactionType::REFUND, 1, $booking->company->id,
|
||||
1, PaymentMethodType::CASH,
|
||||
@@ -98,13 +99,17 @@ class CreateBookingRefundLogic extends AbstractControllerLogic
|
||||
|
||||
$refund_transaction = $this->createsTransaction->execute($transaction, $object);
|
||||
|
||||
$bookingInWhiteForm = $transaction->transactions()->bills()->first();
|
||||
|
||||
// create supplier refund
|
||||
if ($transaction->transactions()->bills()->first()) {
|
||||
if ($bookingInWhiteForm) {
|
||||
$billNumber = $this->generatesTransactionBillNumber->execute('SRFD-');
|
||||
$object = new TransactionObject($billNumber, TransactionType::SUPPLIER_REFUND, 1, $booking->company->id,
|
||||
$supplierRefundTotal = bcdiv($request->input('amount'), $bookingInWhiteForm->currency_rate, 7);
|
||||
|
||||
$object = new TransactionObject($billNumber, TransactionType::SUPPLIER_REFUND, 1, $bookingInWhiteForm->issuer,
|
||||
1, PaymentMethodType::CASH,
|
||||
$refundTotal, $request->input('amount'), 1,
|
||||
$transaction->original_currency_id, $transaction->currency_rate,
|
||||
$supplierRefundTotal, $request->input('amount'), 1,
|
||||
$transaction->original_currency_id, $bookingInWhiteForm->currency_rate,
|
||||
0, 0, null, ApprovalStatus::PENDING_VERIFICATION, [], $transaction->bill_no);
|
||||
|
||||
$transaction = $this->createsTransaction->execute($transaction, $object);
|
||||
|
||||
@@ -102,6 +102,10 @@ class CreateSupplierBillGroupLogic extends AbstractControllerLogic
|
||||
if ($refund->type !== TransactionType::SUPPLIER_REFUND) {
|
||||
throw new MalformedRequestException('Only transaction type supplier refund can be used for bill refund.');
|
||||
}
|
||||
|
||||
if ($refund->currency_rate == 1) {
|
||||
throw new MalformedRequestException('Supplier refund with currecy rate 1 cannot be used for bill refund.');
|
||||
}
|
||||
}
|
||||
|
||||
$amount = 0;
|
||||
|
||||
@@ -125,6 +125,18 @@ class UpdateGroupLogic extends AbstractControllerLogic
|
||||
|
||||
$billTransaction = $this->updatesTransaction->execute($transaction, $object);
|
||||
|
||||
$supplierRefundTransactions = $transaction->owner->transactions()->supplierRefunds()->whereIn('status', [ApprovalStatus::PENDING_VERIFICATION, ApprovalStatus::APPROVED])->get();
|
||||
|
||||
foreach ($supplierRefundTransactions as $supplierRefundTransaction) {
|
||||
$claimBefore = $supplierRefundTransaction->transactions()->where('type', TransactionType::BILL_REFUND)->where('status', ApprovalStatus::APPROVED)->exists();
|
||||
|
||||
if (!$claimBefore) {
|
||||
$supplierRefundTransaction->currency_rate = $rate;
|
||||
$supplierRefundTransaction->amount = $supplierRefundTransaction->original_amount / $rate;
|
||||
$supplierRefundTransaction->save();
|
||||
}
|
||||
}
|
||||
|
||||
$transferTransaction = $transaction->transactions()->where('type', TransactionType::TRANSFER_FEE)->first();
|
||||
|
||||
$transferFee = $this->calculatesTransactionTransferFee->execute($billTransaction->original_amount, $constant);
|
||||
|
||||
@@ -114,10 +114,12 @@ class ExpiredRefundedBookingCommand extends Command
|
||||
// check if the booking is fully refund
|
||||
$amountDifference = bcsub($transaction->amount, $bookingPaymentAmount, 7);
|
||||
|
||||
$isFullyRefund = false;
|
||||
if (abs($amountDifference) < 0.01) {
|
||||
// rejecting booking payment transaction
|
||||
// $bookingPayment->status = ApprovalStatus::REJECTED;
|
||||
// $bookingPayment->save();
|
||||
$isFullyRefund = true;
|
||||
// update fully refunded booking payment transaction
|
||||
$bookingPayment->status = ApprovalStatus::REFUNDED;
|
||||
$bookingPayment->save();
|
||||
|
||||
//expired booking
|
||||
// $this->updatesBookingStatus->execute($booking, ApprovalStatus::EXPIRED);
|
||||
@@ -136,16 +138,12 @@ class ExpiredRefundedBookingCommand extends Command
|
||||
Log::info("Credit note transaction id: {$transaction->id}, already created same amount of refund transaction for same booking payment transaction");
|
||||
}
|
||||
|
||||
if ($bookingInWhiteForm) {
|
||||
Log::info("Credit note transaction id: {$transaction->id}, booking is in white form");
|
||||
}
|
||||
|
||||
if (!$refund) {
|
||||
$billNumber = $this->generatesTransactionBillNumber->execute('RFD-');
|
||||
|
||||
$object = new TransactionObject($billNumber, TransactionType::REFUND, 1, $booking->company->id,
|
||||
1, PaymentMethodType::CASH,
|
||||
$transaction->amount, $transaction->amount * $bookingPayment->currency_rate, 1,
|
||||
$transaction->amount, $isFullyRefund ? $bookingPayment->original_amount : $transaction->amount * $bookingPayment->currency_rate, 1,
|
||||
$bookingPayment->original_currency_id, $bookingPayment->currency_rate,
|
||||
0, 0, null, ApprovalStatus::APPROVED, [], $bookingPayment->bill_no);
|
||||
|
||||
@@ -153,15 +151,24 @@ class ExpiredRefundedBookingCommand extends Command
|
||||
}
|
||||
|
||||
if ($bookingInWhiteForm) {
|
||||
$refund = $bookingPayment->transactions()->supplierRefunds()->where('amount', $transaction->amount)->whereIn('status', [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED])->first();
|
||||
$original_amount = $isFullyRefund ? $bookingPayment->original_amount : bcmul($transaction->amount, $bookingPayment->currency_rate, 7);
|
||||
$supplier_refund_amount = bcdiv($original_amount, $bookingInWhiteForm->currency_rate, 7);
|
||||
|
||||
Log::info("Credit note transaction id: {$transaction->id}, booking is in white form, white form currency rate is {$bookingInWhiteForm->currency_rate}");
|
||||
|
||||
// if ($isFullyRefund && $bookingInWhiteForm->currency_rate == 1) {
|
||||
// dd ($bookingInWhiteForm->owner_id);
|
||||
// }
|
||||
|
||||
$refund = $bookingPayment->transactions()->supplierRefunds()->where('original_amount', $original_amount)->first();
|
||||
|
||||
if (!$refund) {
|
||||
$billNumber = $this->generatesTransactionBillNumber->execute('SRFD-');
|
||||
|
||||
$object = new TransactionObject($billNumber, TransactionType::SUPPLIER_REFUND, 1, $booking->company->id,
|
||||
$object = new TransactionObject($billNumber, TransactionType::SUPPLIER_REFUND, 1, $bookingInWhiteForm->issuer,
|
||||
1, PaymentMethodType::CASH,
|
||||
$transaction->amount, $transaction->amount * $bookingPayment->currency_rate, 1,
|
||||
$bookingPayment->original_currency_id, $bookingPayment->currency_rate,
|
||||
$supplier_refund_amount, $original_amount, 1,
|
||||
$bookingPayment->original_currency_id, $bookingInWhiteForm->currency_rate,
|
||||
0, 0, null, ApprovalStatus::APPROVED, [], $bookingPayment->bill_no);
|
||||
|
||||
$transaction = $this->createsTransaction->execute($bookingPayment, $object);
|
||||
|
||||
+1
-1
@@ -108,7 +108,7 @@
|
||||
<div class="m-b-20">
|
||||
<small class="all-caps muted fs-15">Supplier Refund</small>
|
||||
</div>
|
||||
<list-component :key="supplierRefundListKey" section="supplierRefundListSection" :options="{'per_page': 20, 'type': 15, 'status': 2, 'belongs_to_supplier_id': this.supplier.id}" :endpoint="route('api.transaction.list')">
|
||||
<list-component :key="supplierRefundListKey" section="supplierRefundListSection" :options="{'per_page': 20, 'type': 15, 'currency_rate_is_not_equal': 1, 'status': 2, 'receiver_in': [this.supplier.id]}" :endpoint="route('api.transaction.list')">
|
||||
<template slot="list" slot-scope="{data}">
|
||||
<supplier-refund-component section="supplierRefundListSection" :data="data" :is1688Supplier="is1688Supplier" :payments="payments" :supplierRefunds="supplierRefunds" :refundTotal="refundTotal" :paymentTotal="paymentTotal" :inputPaymentTotal="inputPaymentTotal" v-on:input="refundOrder($event)"></supplier-refund-component>
|
||||
</template>
|
||||
|
||||
Reference in New Issue
Block a user