mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/exchange-2.0.git
synced 2026-08-19 04:23:55 +00:00
106 lines
4.0 KiB
PHP
106 lines
4.0 KiB
PHP
<?php
|
|
|
|
namespace App\Classes\Modules\Wallets\ControllersLogic;
|
|
|
|
use App\Classes\General\Abstracts\AbstractControllerLogic;
|
|
|
|
use App\Classes\Modules\Wallets\Standards\Rules\CanCreateWalletTransaction;
|
|
use App\Classes\Modules\Wallets\DataTransferObjects\WalletTransactionObject;
|
|
use App\Classes\Modules\Wallets\Services\CreatesWalletTransaction;
|
|
use App\Classes\Modules\Wallets\Services\GeneratesWalletTransactionBillNo;
|
|
use App\Http\Resources\WalletTransactionResource;
|
|
/*
|
|
use App\Classes\Modules\Accounts\Standards\Rules\CanCreateUser;
|
|
use App\Classes\Modules\Accounts\Services\CreatesUser;
|
|
use App\Classes\Modules\Accounts\DataTransferObjects\UserObject;
|
|
use App\Http\Resources\UserResource;
|
|
|
|
use App\Classes\Modules\Companies\Standards\Rules\CanCreateCompany;
|
|
use App\Classes\Modules\Companies\Services\CreatesCompany;
|
|
use App\Classes\Modules\Companies\DataTransferObjects\CompanyObject;
|
|
|
|
use App\Classes\Modules\Contacts\Standards\Rules\CanCreateContact;
|
|
use App\Classes\Modules\Contacts\Services\CreatesContact;
|
|
use App\Classes\Modules\Contacts\DataTransferObjects\ContactObject;
|
|
|
|
use App\Classes\Modules\CompanyEmployees\Standards\Rules\CanCreateCompanyEmployee;
|
|
use App\Classes\Modules\CompanyEmployees\Services\CreatesCompanyEmployee;
|
|
use App\Classes\Modules\CompanyEmployees\DataTransferObjects\CompanyEmployeeObject;
|
|
|
|
use App\Classes\Modules\SegmentCompanies\Standards\Rules\CanCreateSegmentCompany;
|
|
use App\Classes\Modules\SegmentCompanies\Services\CreatesSegmentCompany;
|
|
use App\Classes\Modules\SegmentCompanies\DataTransferObjects\SegmentCompanyObject;
|
|
*/
|
|
use ErrorException;
|
|
use Illuminate\Http\JsonResponse;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
class CreateWalletTransactionLogic extends AbstractControllerLogic
|
|
{
|
|
|
|
|
|
/**
|
|
* @return array
|
|
*/
|
|
protected function notification():array {
|
|
return [
|
|
'title' => 'Created Wallet Transaction',
|
|
'message' => 'You have successfully created a wallet transaction'
|
|
];
|
|
}
|
|
|
|
/** @var CreatesWalletTransaction */
|
|
private $createsWalletTransaction;
|
|
|
|
/** @var GeneratesWalletTransactionBillNo */
|
|
private $generatesWalletTransactionBillNo;
|
|
|
|
/** @var CanCreateWalletTransaction */
|
|
private $canCreateWalletTransaction;
|
|
|
|
/**
|
|
* CreateWalletLogic constructor.
|
|
* @param CreatesWallet $createsWallet
|
|
* @param GeneratesWalletCode $generatesWalletCode
|
|
* @param CanCreateCompanyWallet $canCreateCompanyWallet
|
|
*/
|
|
public function __construct(CreatesWalletTransaction $createsWalletTransaction, GeneratesWalletTransactionBillNo $generatesWalletTransactionBillNo, CanCreateWalletTransaction $canCreateWalletTransaction)
|
|
{
|
|
$this->createsWalletTransaction = $createsWalletTransaction;
|
|
$this->generatesWalletTransactionBillNo = $generatesWalletTransactionBillNo;
|
|
$this->canCreateWalletTransaction = $canCreateWalletTransaction;
|
|
}
|
|
|
|
/**
|
|
* @param Request $request
|
|
* @return JsonResponse
|
|
* @throws ErrorException
|
|
*/
|
|
public function logic(Request $request) : JsonResponse
|
|
{
|
|
try {
|
|
|
|
DB::beginTransaction();
|
|
|
|
|
|
$object = new WalletTransactionObject(
|
|
$request->route('id'), $this->generatesWalletTransactionBillNo->execute(),$request->input('trans_type'),
|
|
number_format( (float) $request->input('amount'), 5, '.', ''), $request->input('currency_id') , number_format( (float) $request->input('original_amount'), 5, '.', ''),
|
|
$request->input('original_currency_id'),number_format( (float) $request->input('currency_rate'), 5, '.', '')
|
|
);
|
|
|
|
$this->canCreateWalletTransaction->passes($object);
|
|
|
|
$wallet_transaction = $this->createsWalletTransaction->execute($object);
|
|
|
|
DB::commit();
|
|
|
|
return $this->resourceResponse(new WalletTransactionResource($wallet_transaction));
|
|
|
|
} catch (\Exception $exception) {
|
|
throw new ErrorException($exception->getMessage(), $exception->getCode());
|
|
}
|
|
|
|
}
|
|
} |