mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/exchange-2.0.git
synced 2026-08-19 04:23:55 +00:00
delete refund
This commit is contained in:
@@ -0,0 +1,113 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Classes\Modules\Transactions\ControllersLogic;
|
||||||
|
|
||||||
|
|
||||||
|
use App\Classes\General\Abstracts\AbstractControllerLogic;
|
||||||
|
use App\Classes\Modules\Transactions\Services\FetchesTransaction;
|
||||||
|
use App\Classes\Modules\Transactions\Services\DeletesTransaction;
|
||||||
|
use App\Classes\Modules\Transactions\Services\UpdatesTransactionStatus;
|
||||||
|
use App\Classes\ValueObjects\Constants\ApprovalStatus;
|
||||||
|
use Illuminate\Http\JsonResponse;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use App\Classes\ValueObjects\Constants\TransactionType;
|
||||||
|
use App\Models\Transaction;
|
||||||
|
use App\Classes\Modules\Bookings\ControllersLogic\UpdateBookingAmountLogic;
|
||||||
|
use App\Classes\Modules\Bookings\Services\CalculatesBookingRefundAmount;
|
||||||
|
use Illuminate\Support\Facades\Log;
|
||||||
|
use App\Classes\Modules\Bookings\Services\CalculatesBookingPaidAmount;
|
||||||
|
|
||||||
|
class DeleteRefundTransactionLogic extends AbstractControllerLogic
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
protected function notification(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'title' => 'Deleted Refund Transaction',
|
||||||
|
'message' => 'You have successfully deleted a transaction'
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @var FetchesTransaction */
|
||||||
|
private $fetchesTransaction;
|
||||||
|
|
||||||
|
/** @var DeletesTransaction */
|
||||||
|
private $deletesTransaction;
|
||||||
|
|
||||||
|
/** @var UpdatesTransactionStatus */
|
||||||
|
private $updatesTransactionStatus;
|
||||||
|
|
||||||
|
/** @var CalculatesBookingRefundAmount */
|
||||||
|
private $calculatesBookingRefundAmount;
|
||||||
|
|
||||||
|
/** @var CalculatesBookingPaidAmount */
|
||||||
|
private $calculatesBookingPaidAmount;
|
||||||
|
|
||||||
|
/** @var UpdateBookingAmountLogic */
|
||||||
|
private $updateBookingAmountLogic;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* CreatePaymentVerificationDocumentLogic constructor.
|
||||||
|
* @param FetchesTransaction $fetchesTransaction
|
||||||
|
* @param DeletesTransaction $deletesTransaction
|
||||||
|
* @param CalculatesBookingRefundAmount $calculatesBookingRefundAmount
|
||||||
|
* @param UpdateBookingAmountLogic $updateBookingAmountLogic
|
||||||
|
* @param calculatesBookingPaidAmount $calculatesBookingPaidAmount
|
||||||
|
*/
|
||||||
|
public function __construct(FetchesTransaction $fetchesTransaction, DeletesTransaction $deletesTransaction, UpdatesTransactionStatus $updatesTransactionStatus, CalculatesBookingRefundAmount $calculatesBookingRefundAmount, UpdateBookingAmountLogic $updateBookingAmountLogic, CalculatesBookingPaidAmount $calculatesBookingPaidAmount)
|
||||||
|
{
|
||||||
|
$this->fetchesTransaction = $fetchesTransaction;
|
||||||
|
$this->deletesTransaction = $deletesTransaction;
|
||||||
|
$this->updatesTransactionStatus = $updatesTransactionStatus;
|
||||||
|
$this->calculatesBookingRefundAmount = $calculatesBookingRefundAmount;
|
||||||
|
$this->updateBookingAmountLogic = $updateBookingAmountLogic;
|
||||||
|
$this->calculatesBookingPaidAmount = $calculatesBookingPaidAmount;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param Request $request
|
||||||
|
* @return JsonResponse
|
||||||
|
* @throws \App\Classes\Exceptions\MalformedRequestException
|
||||||
|
*/
|
||||||
|
public function logic(Request $request): JsonResponse
|
||||||
|
{
|
||||||
|
// delete refund transaction
|
||||||
|
$transaction = $this->fetchesTransaction->execute(['id' => $request->route('id')]);
|
||||||
|
$this->deletesTransaction->execute($transaction);
|
||||||
|
|
||||||
|
// Update payment_transaction status
|
||||||
|
$payment_transaction = $transaction->owner;
|
||||||
|
$this->updatesTransactionStatus->execute($payment_transaction, ApprovalStatus::APPROVED);
|
||||||
|
|
||||||
|
// delete wallet top up transaction
|
||||||
|
$booking = $transaction->owner->owner;
|
||||||
|
Transaction::where('type', TransactionType::CREDIT_NOTE)
|
||||||
|
->where('amount', $transaction->amount)
|
||||||
|
->where('payment_reference', 'like', '%' . $booking->marking . '%')
|
||||||
|
->delete();
|
||||||
|
|
||||||
|
// update back the latest booking amount
|
||||||
|
$request['fix_amount'] = $this->calculatesBookingPaidAmount->execute($booking);
|
||||||
|
$request->route()->setParameter('id', $booking->id);
|
||||||
|
$this->updateBookingAmountLogic->execute($request);
|
||||||
|
|
||||||
|
// if have SUPPLIER_REFUND transaction
|
||||||
|
$bookingInWhiteForm = $payment_transaction->transactions()->bills()->first();
|
||||||
|
if ($bookingInWhiteForm) {
|
||||||
|
|
||||||
|
$whiteFormTransaction = Transaction::where('type', TransactionType::SUPPLIER_REFUND)
|
||||||
|
->where('payment_reference', $transaction->payment_reference)
|
||||||
|
->first();
|
||||||
|
|
||||||
|
|
||||||
|
Log::info($whiteFormTransaction->id);
|
||||||
|
|
||||||
|
$whiteFormTransaction->delete();
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->response([]);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers\Transactions;
|
||||||
|
|
||||||
|
use App\Classes\Modules\Transactions\ControllersLogic\DeleteRefundTransactionLogic;
|
||||||
|
use Illuminate\Http\JsonResponse;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
|
||||||
|
class DeleteRefundTransactionController
|
||||||
|
{
|
||||||
|
public function delete(Request $request, DeleteRefundTransactionLogic $logic): JsonResponse {
|
||||||
|
return $logic->execute($request);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -392,6 +392,24 @@
|
|||||||
</modal-component>
|
</modal-component>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="row m-b-15 text-right parentContainer" v-if="$store.getters.isSuperAdmin && refund.status === 2">
|
||||||
|
<div class="col">
|
||||||
|
<button class="btn btn-xs btn-outline-danger b-rad-none m-r-5 requestModal" data-type="deleteRefund">
|
||||||
|
<i class="fa fa-times fa-fw"></i>
|
||||||
|
</button>
|
||||||
|
<modal-component class="animate__animated animate__fast animate__fadeIn" type="deleteRefund">
|
||||||
|
<general-confirmation-form-component
|
||||||
|
contentText="Are you sure you want to delete this refund?"
|
||||||
|
modalType="delete"
|
||||||
|
class="text-center"
|
||||||
|
:apiRoute="route('api.transaction.refund.delete', refund.id)"
|
||||||
|
apiMethod="delete"
|
||||||
|
:section="section"
|
||||||
|
>
|
||||||
|
</general-confirmation-form-component>
|
||||||
|
</modal-component>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -14,6 +14,8 @@ Route::group(['prefix' => 'transactions', 'namespace' => 'Transactions', 'as' =>
|
|||||||
Route::put('/{id}/bill/{status}', 'UpdatePaymentTransactionStatusController@update')->where('status', 'pending|complete')->name('bill.status');
|
Route::put('/{id}/bill/{status}', 'UpdatePaymentTransactionStatusController@update')->where('status', 'pending|complete')->name('bill.status');
|
||||||
Route::put('/{id}/refund/status/update/{status}', 'UpdateRefundTransactionStatusController@update')->name('refund.status.update');
|
Route::put('/{id}/refund/status/update/{status}', 'UpdateRefundTransactionStatusController@update')->name('refund.status.update');
|
||||||
|
|
||||||
|
Route::delete('/refund/{id}/delete', 'DeleteRefundTransactionController@delete')->name('refund.delete');
|
||||||
|
|
||||||
route::delete('{id}/bill/delete', 'DeletePaymentProofDocumentController@delete')->name('bill.delete');
|
route::delete('{id}/bill/delete', 'DeletePaymentProofDocumentController@delete')->name('bill.delete');
|
||||||
|
|
||||||
Route::post('booking/{id}/details/update', 'CreatePurchaseOrderTransactionController@create')->name('po.create');
|
Route::post('booking/{id}/details/update', 'CreatePurchaseOrderTransactionController@create')->name('po.create');
|
||||||
|
|||||||
Reference in New Issue
Block a user