mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/exchange-2.0.git
synced 2026-08-22 14:04:01 +00:00
107 lines
3.4 KiB
PHP
107 lines
3.4 KiB
PHP
<?php
|
|
|
|
namespace App\Classes\Modules\Bookings\ControllersLogic;
|
|
|
|
use App\Classes\General\Abstracts\AbstractControllerLogic;
|
|
|
|
use App\Classes\Modules\Transactions\Services\ListsTransactions;
|
|
use App\Classes\Modules\Transactions\Services\CreatesTransaction;
|
|
use App\Classes\Modules\Transactions\Services\GeneratesTransactionBillNumber;
|
|
|
|
use App\Classes\Modules\Transactions\DataTransferObjects\TransactionObject;
|
|
|
|
use App\Classes\ValueObjects\Constants\ApprovalStatus;
|
|
use App\Classes\ValueObjects\Constants\TransactionType;
|
|
|
|
use Illuminate\Http\JsonResponse;
|
|
use Illuminate\Http\Request;
|
|
|
|
class CreateInvoiceTransactionLogic extends AbstractControllerLogic
|
|
{
|
|
/**
|
|
* CreateInvoiceTransactionLogic constructor.
|
|
* @param ListsTransactions $listsTransactions
|
|
* @param CreatesTransaction $createsTransaction
|
|
* @param GeneratesTransactionBillNumber $generatesTransactionBillNumber
|
|
*/
|
|
public function __construct(ListsTransactions $listsTransactions, CreatesTransaction $createsTransaction, GeneratesTransactionBillNumber $generatesTransactionBillNumber)
|
|
{
|
|
$this->listsTransactions = $listsTransactions;
|
|
$this->generatesTransactionBillNumber = $generatesTransactionBillNumber;
|
|
$this->createsTransaction = $createsTransaction;
|
|
}
|
|
|
|
/**
|
|
* @return array
|
|
*/
|
|
protected function notification():array {
|
|
return [
|
|
'title' => 'Created InvoiceTransaction',
|
|
'message' => 'You have successfully created a invoice transaction'
|
|
];
|
|
}
|
|
|
|
/** @var ListsTransactions */
|
|
private $listsTransactions;
|
|
|
|
/** @var CreatesTransaction */
|
|
private $createsTransaction;
|
|
|
|
/** @var GeneratesTransactionBillNumber */
|
|
private $generatesTransactionBillNumber;
|
|
|
|
/**
|
|
* @param Request $request
|
|
* @return JsonResponse
|
|
* @throws \App\Classes\Exceptions\MalformedRequestException
|
|
*/
|
|
public function logic(Request $request) : JsonResponse
|
|
{
|
|
$booking_id = $request->input('booking_id');
|
|
|
|
$transaction = $this->listsTransactions->execute([
|
|
'booking_id' => $booking_id
|
|
]);
|
|
|
|
$allow = true;
|
|
$total_currency_rate = 0;
|
|
|
|
foreach ($transaction as $key => $row) {
|
|
$total_currency_rate += $row->currency_rate;
|
|
|
|
if ($row->status != ApprovalStatus::APPROVED ) {
|
|
$allow = false;
|
|
}
|
|
}
|
|
|
|
$total_average_currency_rate = $total_currency_rate / count($transaction);
|
|
|
|
if ($allow) {
|
|
$transaction = $transaction[0];
|
|
|
|
$billNumber = $this->generatesTransactionBillNumber->execute('INV-');
|
|
$object = new TransactionObject(
|
|
$billNumber,
|
|
TransactionType::INVOICE,
|
|
$transaction->issuer,
|
|
$transaction->receiver,
|
|
$transaction->recipient_bank_account_id,
|
|
$transaction->payment_method,
|
|
$transaction->amount,
|
|
$transaction->original_amount,
|
|
$transaction->currency_id,
|
|
$transaction->original_currency_id,
|
|
$total_average_currency_rate,
|
|
$transaction->tax,
|
|
$transaction->service_charge,
|
|
null,
|
|
ApprovalStatus::APPROVED
|
|
);
|
|
|
|
$transaction = $this->createsTransaction->execute($transaction->booking, $object);
|
|
}
|
|
|
|
return $this->response([]);
|
|
}
|
|
|
|
} |