mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/exchange-2.0.git
synced 2026-08-19 04:23:55 +00:00
Receipt
This commit is contained in:
@@ -0,0 +1,151 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Classes\Modules\Receipts\ControllersLogic;
|
||||||
|
|
||||||
|
use App\Classes\General\Abstracts\AbstractControllerLogic;
|
||||||
|
|
||||||
|
use App\Classes\Modules\Receipts\Standards\Rules\CanCreateReceipt;
|
||||||
|
use App\Classes\Modules\Receipts\Standards\Rules\CanCreateReceiptDetail;
|
||||||
|
use App\Classes\Modules\Receipts\DataTransferObjects\ReceiptObject;
|
||||||
|
use App\Classes\Modules\Receipts\DataTransferObjects\ReceiptDetailObject;
|
||||||
|
use App\Classes\Modules\Receipts\Services\CreatesReceipt;
|
||||||
|
use App\Classes\Modules\Receipts\Services\CreatesReceiptDetail;
|
||||||
|
use App\Classes\Modules\Receipts\Services\GeneratesReceiptBillNo;
|
||||||
|
use App\Http\Resources\ReceiptResource;
|
||||||
|
use App\Http\Resources\ReceiptDetailResource;
|
||||||
|
|
||||||
|
use App\Classes\Modules\Currencies\Services\FetchesCurrency;
|
||||||
|
use App\Classes\Modules\Currencies\Services\RateCalculatesCurrency;
|
||||||
|
|
||||||
|
use App\Classes\Modules\Companies\Services\FetchesCompany;
|
||||||
|
|
||||||
|
use App\Classes\Modules\Transactions\Services\FetchesTransaction;
|
||||||
|
|
||||||
|
use ErrorException;
|
||||||
|
use Illuminate\Http\JsonResponse;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
|
||||||
|
class CreateReceiptLogic extends AbstractControllerLogic
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
protected function notification():array {
|
||||||
|
return [
|
||||||
|
'title' => 'Created Receipt',
|
||||||
|
'message' => 'You have successfully created a receipt'
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/** @var GeneratesReceiptBillNo */
|
||||||
|
private $generatesReceiptBillNo;
|
||||||
|
|
||||||
|
/** @var CanCreateReceipt */
|
||||||
|
private $canCreateReceipt;
|
||||||
|
|
||||||
|
private $fetchesCurrency;
|
||||||
|
|
||||||
|
private $rateCalculatesCurrency;
|
||||||
|
|
||||||
|
private $fetchesCompany;
|
||||||
|
|
||||||
|
private $createsReceipt;
|
||||||
|
|
||||||
|
private $canCreateReceiptDetail;
|
||||||
|
|
||||||
|
private $createsReceiptDetail;
|
||||||
|
|
||||||
|
private $fetchesTransaction;
|
||||||
|
/**
|
||||||
|
* CreateWalletLogic constructor.
|
||||||
|
* @param CreatesWallet $createsWallet
|
||||||
|
* @param GeneratesWalletCode $generatesWalletCode
|
||||||
|
* @param CanCreateCompanyWallet $canCreateCompanyWallet
|
||||||
|
*/
|
||||||
|
public function __construct(
|
||||||
|
GeneratesReceiptBillNo $generatesReceiptBillNo, CanCreateReceipt $canCreateReceipt,
|
||||||
|
FetchesCurrency $fetchesCurrency,RateCalculatesCurrency $rateCalculatesCurrency, FetchesCompany $fetchesCompany,
|
||||||
|
CreatesReceipt $createsReceipt,
|
||||||
|
CanCreateReceiptDetail $canCreateReceiptDetail, CreatesReceiptDetail $createsReceiptDetail,
|
||||||
|
FetchesTransaction $fetchesTransaction
|
||||||
|
){
|
||||||
|
$this->generatesReceiptBillNo = $generatesReceiptBillNo;
|
||||||
|
$this->canCreateReceipt = $canCreateReceipt;
|
||||||
|
$this->fetchesCurrency = $fetchesCurrency;
|
||||||
|
$this->rateCalculatesCurrency = $rateCalculatesCurrency;
|
||||||
|
$this->fetchesCompany = $fetchesCompany;
|
||||||
|
$this->createsReceipt =$createsReceipt;
|
||||||
|
$this->canCreateReceiptDetail =$canCreateReceiptDetail;
|
||||||
|
$this->createsReceiptDetail = $createsReceiptDetail;
|
||||||
|
$this->fetchesTransaction = $fetchesTransaction;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param Request $request
|
||||||
|
* @return JsonResponse
|
||||||
|
* @throws ErrorException
|
||||||
|
*/
|
||||||
|
public function logic(Request $request) : JsonResponse
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
|
||||||
|
DB::beginTransaction();
|
||||||
|
$json_array = json_decode($request->getContent(), true);
|
||||||
|
$company = $this->fetchesCompany->execute(['id' => $json_array['company_id']]);
|
||||||
|
|
||||||
|
$conversion_currency = $this->fetchesCurrency->execute(['id' => $json_array['currency_id']]);
|
||||||
|
$convertable_currency = $this->fetchesCurrency->execute(['id' => 1]);//MYR
|
||||||
|
$convert_amount = $this->rateCalculatesCurrency->execute($conversion_currency, $convertable_currency, $json_array['amount']);
|
||||||
|
$convert_rate = $this->rateCalculatesCurrency->execute_rate($conversion_currency, $convertable_currency);
|
||||||
|
|
||||||
|
$object = new ReceiptObject(
|
||||||
|
$this->generatesReceiptBillNo->execute(),$json_array['trans_type1'],$json_array['trans_type2'],
|
||||||
|
number_format( (float) $convert_amount, 5, '.', ''), 1 , number_format( (float) $json_array['amount'], 5, '.', ''),
|
||||||
|
$json_array['currency_id'],number_format( (float) $convert_rate, 5, '.', ''),
|
||||||
|
$json_array['dt_transaction'],1,$request->route('id'),
|
||||||
|
$company->id
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
$this->canCreateReceipt->passes($object);
|
||||||
|
|
||||||
|
$receipt = $this->createsReceipt->execute($object);
|
||||||
|
|
||||||
|
$receipt_array = new ReceiptResource($receipt);
|
||||||
|
$receipt_detail_array = array();
|
||||||
|
|
||||||
|
foreach ($json_array['receipt_detail'] as $key => $value) {
|
||||||
|
|
||||||
|
$transaction_inv = $this->fetchesTransaction->execute(['id' => $value['transaction_id']]);
|
||||||
|
|
||||||
|
$object_detail = new ReceiptDetailObject(
|
||||||
|
$json_array['trans_type1'],$json_array['trans_type2'],
|
||||||
|
$transaction_inv->id,$receipt->id,
|
||||||
|
number_format( (float) $convert_amount, 5, '.', ''), number_format( (float) $json_array['amount'], 5, '.', '')
|
||||||
|
);
|
||||||
|
$this->canCreateReceiptDetail->passes($object_detail);
|
||||||
|
$transaction_detail = $this->createsReceiptDetail->execute($object_detail);
|
||||||
|
//array_push($stack, "apple", "raspberry");
|
||||||
|
$receipt_detail_resource= new ReceiptDetailResource($transaction_detail);
|
||||||
|
$receipt_detail_array[]= $receipt_detail_resource->toArray($request);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
//$transaction_array['transaction_detail']= $transaction_detail_array;
|
||||||
|
//print_r($transaction_detail_array);
|
||||||
|
//dd($transaction_detail_array);
|
||||||
|
DB::commit();
|
||||||
|
|
||||||
|
return $this->resourceResponse($receipt_array);
|
||||||
|
//return $this->resourceResponse($json_array);
|
||||||
|
|
||||||
|
} catch (\Exception $exception) {
|
||||||
|
throw new ErrorException($exception->getMessage(), $exception->getCode());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,81 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Classes\Modules\Receipts\DataTransferObjects;
|
||||||
|
|
||||||
|
use App\Classes\Interfaces\DataTransferObject;
|
||||||
|
|
||||||
|
class ReceiptDetailObject implements DataTransferObject
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
private $trans_type1;
|
||||||
|
|
||||||
|
private $trans_type2;
|
||||||
|
|
||||||
|
private $transaction_id;
|
||||||
|
|
||||||
|
private $receipt_id;
|
||||||
|
|
||||||
|
private $price;
|
||||||
|
|
||||||
|
private $amount;
|
||||||
|
|
||||||
|
|
||||||
|
public function __construct(
|
||||||
|
string $trans_type1,string $trans_type2,
|
||||||
|
int $transaction_id, int $receipt_id,
|
||||||
|
float $price,float $amount
|
||||||
|
){
|
||||||
|
$this->trans_type1= $trans_type1;
|
||||||
|
$this->trans_type2 = $trans_type2;
|
||||||
|
$this->transaction_id = $transaction_id;
|
||||||
|
$this->receipt_id = $receipt_id;
|
||||||
|
$this->price = $price;
|
||||||
|
$this->amount = $amount;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getTransType1(): string
|
||||||
|
{
|
||||||
|
return $this->trans_type1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getTransType2(): string
|
||||||
|
{
|
||||||
|
return $this->trans_type2;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
public function getTransactionId(): int
|
||||||
|
{
|
||||||
|
return $this->transaction_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
public function getReceiptId(): int
|
||||||
|
{
|
||||||
|
return $this->receipt_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getPrice(): float
|
||||||
|
{
|
||||||
|
return $this->price;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getAmount(): float
|
||||||
|
{
|
||||||
|
return $this->amount;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,150 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Classes\Modules\Receipts\DataTransferObjects;
|
||||||
|
|
||||||
|
use App\Classes\Interfaces\DataTransferObject;
|
||||||
|
|
||||||
|
class ReceiptObject implements DataTransferObject
|
||||||
|
{
|
||||||
|
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
* return [
|
||||||
|
'id' => $this->id,
|
||||||
|
'trans_type1' => $this->trans_type1,
|
||||||
|
'trans_type2' => $this->trans_type2,
|
||||||
|
'bill_no' => (int) $this->bill_no,
|
||||||
|
'amount' => (double) $this->amount,
|
||||||
|
'currency_id' => (int) $this->currency_id,
|
||||||
|
'original_amount' => (double) $this->original_amount,
|
||||||
|
'original_currency_id' => (int) $this->original_currency_id,
|
||||||
|
'currency_rate' => (double) $this->currency_rate,
|
||||||
|
'dt_transaction' => $this->dt_transaction,
|
||||||
|
'status' => (int) $this->status,
|
||||||
|
'booking_id' => (int) $this->booking_id,
|
||||||
|
'company_id' => (int) $this->company_id
|
||||||
|
];
|
||||||
|
*/
|
||||||
|
private $trans_type1;
|
||||||
|
|
||||||
|
private $trans_type2;
|
||||||
|
|
||||||
|
private $bill_no;
|
||||||
|
|
||||||
|
private $amount;
|
||||||
|
|
||||||
|
private $currency_id;
|
||||||
|
|
||||||
|
private $original_amount;
|
||||||
|
|
||||||
|
private $original_currency_id;
|
||||||
|
|
||||||
|
private $currency_rate;
|
||||||
|
|
||||||
|
private $dt_transaction;
|
||||||
|
|
||||||
|
private $status;
|
||||||
|
|
||||||
|
private $booking_id;
|
||||||
|
|
||||||
|
private $company_id;
|
||||||
|
|
||||||
|
public function __construct(
|
||||||
|
int $bill_no,string $trans_type1,string $trans_type2,
|
||||||
|
float $amount, int $currency_id, int $original_amount,
|
||||||
|
int $original_currency_id, float $currency_rate,
|
||||||
|
string $dt_transaction,int $status,int $booking_id,
|
||||||
|
int $company_id
|
||||||
|
){
|
||||||
|
$this->bill_no = $bill_no;
|
||||||
|
$this->trans_type1= $trans_type1;
|
||||||
|
$this->trans_type2 = $trans_type2;
|
||||||
|
$this->amount= $amount;
|
||||||
|
$this->currency_id = $currency_id;
|
||||||
|
$this->original_amount = $original_amount;
|
||||||
|
$this->original_currency_id = $original_currency_id;
|
||||||
|
$this->currency_rate = $currency_rate;
|
||||||
|
$this->dt_transaction = $dt_transaction;
|
||||||
|
$this->status = $status;
|
||||||
|
$this->booking_id = $booking_id;
|
||||||
|
$this->company_id = $company_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
public function getBillNo(): int
|
||||||
|
{
|
||||||
|
return $this->bill_no;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getTransType1(): string
|
||||||
|
{
|
||||||
|
return $this->trans_type1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getTransType2(): string
|
||||||
|
{
|
||||||
|
return $this->trans_type2;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function getAmount(): float
|
||||||
|
{
|
||||||
|
return $this->amount;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
public function getCurrency(): int
|
||||||
|
{
|
||||||
|
return $this->currency_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function getOriginalAmount(): float
|
||||||
|
{
|
||||||
|
return $this->original_amount;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getOriginalCurrency(): int
|
||||||
|
{
|
||||||
|
return $this->original_currency_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getCurrencyRate(): float
|
||||||
|
{
|
||||||
|
return $this->currency_rate;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getDtTransaction(): string
|
||||||
|
{
|
||||||
|
return $this->dt_transaction;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getStatus(): int
|
||||||
|
{
|
||||||
|
return $this->original_currency_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getBookingId(): int
|
||||||
|
{
|
||||||
|
return $this->booking_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getCompanyId(): int
|
||||||
|
{
|
||||||
|
return $this->company_id;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Classes\Modules\Receipts\Services;
|
||||||
|
|
||||||
|
|
||||||
|
use App\Models\Receipt;
|
||||||
|
|
||||||
|
class ChecksIfReceiptBillNoExists
|
||||||
|
{
|
||||||
|
|
||||||
|
private $repository;
|
||||||
|
|
||||||
|
public function __construct(Receipt $repository)
|
||||||
|
{
|
||||||
|
$this->repository = $repository;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function execute(int $bill_no): bool {
|
||||||
|
return $this->repository->where('bill_no', $bill_no)->exists();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Classes\Modules\Receipts\Services;
|
||||||
|
|
||||||
|
use App\Classes\General\Eloquent\AbstractUpdateRecord;
|
||||||
|
use App\Classes\Modules\Receipts\DataTransferObjects\ReceiptObject;
|
||||||
|
use App\Models\Receipt;
|
||||||
|
|
||||||
|
class CreatesReceipt extends AbstractUpdateRecord
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @param WalletObject $object
|
||||||
|
* @return \Illuminate\Database\Eloquent\Model
|
||||||
|
* @throws \App\Classes\Exceptions\MalformedRequestException
|
||||||
|
*/
|
||||||
|
public function execute(ReceiptObject $object) {
|
||||||
|
$model = new Receipt();
|
||||||
|
$model->bill_no = $object->getBillNo();
|
||||||
|
$model->trans_type1 = $object->getTransType1();
|
||||||
|
$model->trans_type2 = $object->getTransType2();
|
||||||
|
$model->amount = $object->getAmount();
|
||||||
|
$model->currency_id = $object->getCurrency();
|
||||||
|
$model->original_amount = $object->getOriginalAmount();
|
||||||
|
$model->original_currency_id = $object->getOriginalCurrency();
|
||||||
|
$model->currency_rate = $object->getCurrencyRate();
|
||||||
|
$model->dt_transaction = $object->getDtTransaction();
|
||||||
|
$model->status = $object->getStatus();
|
||||||
|
$model->booking_id = $object->getBookingId();
|
||||||
|
$model->company_id = $object->getCompanyId();
|
||||||
|
|
||||||
|
|
||||||
|
return $this->handler($model);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Classes\Modules\Receipts\Services;
|
||||||
|
|
||||||
|
use App\Classes\General\Eloquent\AbstractUpdateRecord;
|
||||||
|
use App\Classes\Modules\Receipts\DataTransferObjects\ReceiptDetailObject;
|
||||||
|
use App\Models\ReceiptDetail;
|
||||||
|
|
||||||
|
class CreatesReceiptDetail extends AbstractUpdateRecord
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @param WalletObject $object
|
||||||
|
* @return \Illuminate\Database\Eloquent\Model
|
||||||
|
* @throws \App\Classes\Exceptions\MalformedRequestException
|
||||||
|
*/
|
||||||
|
public function execute(ReceiptDetailObject $object) {
|
||||||
|
$model = new ReceiptDetail();
|
||||||
|
$model->trans_type1 = $object->getTransType1();
|
||||||
|
$model->trans_type2 = $object->getTransType2();
|
||||||
|
$model->transaction_id = $object->getTransactionId();
|
||||||
|
$model->receipt_id = $object->getReceiptId();
|
||||||
|
$model->price = $object->getPrice();
|
||||||
|
$model->amount = $object->getAmount();
|
||||||
|
|
||||||
|
|
||||||
|
return $this->handler($model);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Classes\Modules\Receipts\Services;
|
||||||
|
|
||||||
|
|
||||||
|
class GeneratesReceiptBillNo
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
private $receiptBillNoExists;
|
||||||
|
|
||||||
|
|
||||||
|
public function __construct(ChecksIfReceiptBillNoExists $receiptBillNoExists)
|
||||||
|
{
|
||||||
|
$this->receiptBillNoExists = $receiptBillNoExists;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public function execute(): int {
|
||||||
|
|
||||||
|
$code = mt_rand(100000001, 999999999);
|
||||||
|
return !$this->receiptBillNoExists->execute($code) ? $code : self::execute();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,50 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Classes\Modules\Receipts\Standards\Rules;
|
||||||
|
|
||||||
|
|
||||||
|
use App\Classes\General\Abstracts\AbstractRule;
|
||||||
|
use App\Classes\Modules\Receipts\Standards\Validators\ReceiptValidation;
|
||||||
|
|
||||||
|
class CanCreateReceipt extends AbstractRule
|
||||||
|
{
|
||||||
|
|
||||||
|
/** @var WalletTransactionValidation */
|
||||||
|
private $receiptValidation;
|
||||||
|
|
||||||
|
|
||||||
|
public function __construct(ReceiptValidation $receiptValidation)
|
||||||
|
{
|
||||||
|
$this->receiptValidation = $receiptValidation;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
protected function authorized(): bool
|
||||||
|
{
|
||||||
|
// TODO Set Authorization rules
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param CompanyWalletValidation $object
|
||||||
|
* @return bool
|
||||||
|
* @throws \App\Classes\Exceptions\RequestValidationException
|
||||||
|
*/
|
||||||
|
protected function validators($object): bool
|
||||||
|
{
|
||||||
|
return $this->receiptValidation->validate($object);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param SegmentCompanyValidation $object
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
protected function criteria($object): bool
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,50 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Classes\Modules\Receipts\Standards\Rules;
|
||||||
|
|
||||||
|
|
||||||
|
use App\Classes\General\Abstracts\AbstractRule;
|
||||||
|
use App\Classes\Modules\Receipts\Standards\Validators\ReceiptDetailValidation;
|
||||||
|
|
||||||
|
class CanCreateReceiptDetail extends AbstractRule
|
||||||
|
{
|
||||||
|
|
||||||
|
/** @var WalletTransactionValidation */
|
||||||
|
private $receiptDetailValidation;
|
||||||
|
|
||||||
|
|
||||||
|
public function __construct(ReceiptDetailValidation $receiptDetailValidation)
|
||||||
|
{
|
||||||
|
$this->receiptDetailValidation = $receiptDetailValidation;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
protected function authorized(): bool
|
||||||
|
{
|
||||||
|
// TODO Set Authorization rules
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param CompanyWalletValidation $object
|
||||||
|
* @return bool
|
||||||
|
* @throws \App\Classes\Exceptions\RequestValidationException
|
||||||
|
*/
|
||||||
|
protected function validators($object): bool
|
||||||
|
{
|
||||||
|
return $this->receiptDetailValidation->validate($object);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param SegmentCompanyValidation $object
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
protected function criteria($object): bool
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,59 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Classes\Modules\Receipts\Standards\Validators;
|
||||||
|
|
||||||
|
use App\Classes\General\Abstracts\AbstractValidation;
|
||||||
|
use App\Classes\Modules\Receipts\DataTransferObjects\ReceiptDetailObject;
|
||||||
|
|
||||||
|
class ReceiptDetailValidation extends AbstractValidation
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
* $this->bill_no = $bill_no;
|
||||||
|
$this->trans_type1= $trans_type1;
|
||||||
|
$this->trans_type2 = $trans_type2;
|
||||||
|
$this->amount= $amount;
|
||||||
|
$this->currency_id = $currency_id;
|
||||||
|
$this->original_amount = $original_amount;
|
||||||
|
$this->original_currency_id = $original_currency_id;
|
||||||
|
$this->currency_rate = $currency_rate;
|
||||||
|
$this->dt_transaction = $dt_transaction;
|
||||||
|
$this->status = $status;
|
||||||
|
$this->booking_id = $booking_id;
|
||||||
|
$this->company_id = $company_id;
|
||||||
|
*/
|
||||||
|
protected function data($object): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'trans_type1' => $object->getTransType1(),
|
||||||
|
'trans_type2' => $object->getTransType2(),
|
||||||
|
'transaction_id' => $object->getTransactionId(),
|
||||||
|
'receipt_id' => $object->getReceiptId(),
|
||||||
|
'price'=>$object->getPrice(),
|
||||||
|
'amount' => $object->getAmount()
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
protected function rules(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'trans_type1' => 'required',
|
||||||
|
'trans_type2' => 'required',
|
||||||
|
'transaction_id' => 'required',
|
||||||
|
'receipt_id' => 'required',
|
||||||
|
'price'=>'required',
|
||||||
|
'amount' => 'required'
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
protected function messages(): array
|
||||||
|
{
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,55 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Classes\Modules\Receipts\Standards\Validators;
|
||||||
|
|
||||||
|
use App\Classes\General\Abstracts\AbstractValidation;
|
||||||
|
use App\Classes\Modules\Receipts\DataTransferObjects\ReceiptObject;
|
||||||
|
|
||||||
|
class ReceiptValidation extends AbstractValidation
|
||||||
|
{
|
||||||
|
|
||||||
|
protected function data($object): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'bill_no' => $object->getBillNo(),
|
||||||
|
'trans_type1' => $object->getBillNo(),
|
||||||
|
'trans_type2' => $object->getTransType2(),
|
||||||
|
'amount' => $object->getAmount(),
|
||||||
|
'currency_id' => $object->getCurrency(),
|
||||||
|
'original_amount' => $object->getOriginalAmount(),
|
||||||
|
'original_currency_id'=>$object->getOriginalCurrency(),
|
||||||
|
'dt_transaction'=>$object->getDtTransaction(),
|
||||||
|
'status'=>$object->getStatus(),
|
||||||
|
'booking_id'=>$object->getBookingId(),
|
||||||
|
'company_id'=>$object->getCompanyId()
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
protected function rules(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'bill_no' => 'required',
|
||||||
|
'trans_type1' => 'required',
|
||||||
|
'trans_type2' => 'required',
|
||||||
|
'amount' => 'required',
|
||||||
|
'currency_id' => 'required',
|
||||||
|
'original_amount' => 'required',
|
||||||
|
'original_currency_id'=>'required',
|
||||||
|
'dt_transaction'=>'required',
|
||||||
|
'status'=>'required',
|
||||||
|
'booking_id'=>'required',
|
||||||
|
'company_id'=>'required'
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
protected function messages(): array
|
||||||
|
{
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Classes\Modules\Transactions\Services;
|
||||||
|
|
||||||
|
|
||||||
|
use App\Classes\General\Eloquent\AbstractFetchRecord;
|
||||||
|
use Illuminate\Database\Eloquent\Builder;
|
||||||
|
use App\Models\Transaction;
|
||||||
|
|
||||||
|
class FetchesTransaction extends AbstractFetchRecord
|
||||||
|
{
|
||||||
|
|
||||||
|
/** @var Transaction */
|
||||||
|
private $repository;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* FetchesTransaction constructor.
|
||||||
|
* @param Transaction $repository
|
||||||
|
*/
|
||||||
|
public function __construct(Transaction $repository)
|
||||||
|
{
|
||||||
|
$this->repository = $repository;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return Builder
|
||||||
|
*/
|
||||||
|
public function getRepository(): Builder
|
||||||
|
{
|
||||||
|
return $this->repository->newQuery();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers\Receipts;
|
||||||
|
|
||||||
|
use App\Classes\Modules\Receipts\ControllersLogic\CreateReceiptLogic;
|
||||||
|
use Illuminate\Http\JsonResponse;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
|
||||||
|
class CreateReceiptController
|
||||||
|
{
|
||||||
|
|
||||||
|
public function create(Request $request, CreateReceiptLogic $logic): JsonResponse {
|
||||||
|
return $logic->execute($request);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Resources;
|
||||||
|
|
||||||
|
use Illuminate\Http\Resources\Json\JsonResource;
|
||||||
|
|
||||||
|
class ReceiptDetailResource extends JsonResource
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Transform the resource into an array.
|
||||||
|
*
|
||||||
|
* @param \Illuminate\Http\Request $request
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function toArray($request)
|
||||||
|
{
|
||||||
|
|
||||||
|
return [
|
||||||
|
'id' => $this->id,
|
||||||
|
'trans_type1' => $this->trans_type1,
|
||||||
|
'trans_type2' => $this->trans_type2,
|
||||||
|
'transaction_id' => (int) $this->transaction_id,
|
||||||
|
'receipt_id' => (int)$this->receipt_id,
|
||||||
|
'price' => (double) $this->price,
|
||||||
|
'amount' => (double) $this->amount
|
||||||
|
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Resources;
|
||||||
|
|
||||||
|
use Illuminate\Http\Resources\Json\JsonResource;
|
||||||
|
|
||||||
|
class ReceiptResource extends JsonResource
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Transform the resource into an array.
|
||||||
|
*
|
||||||
|
* @param \Illuminate\Http\Request $request
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function toArray($request)
|
||||||
|
{
|
||||||
|
|
||||||
|
return [
|
||||||
|
'id' => $this->id,
|
||||||
|
'trans_type1' => $this->trans_type1,
|
||||||
|
'trans_type2' => $this->trans_type2,
|
||||||
|
'bill_no' => (int) $this->bill_no,
|
||||||
|
'amount' => (double) $this->amount,
|
||||||
|
'currency_id' => (int) $this->currency_id,
|
||||||
|
'original_amount' => (double) $this->original_amount,
|
||||||
|
'original_currency_id' => (int) $this->original_currency_id,
|
||||||
|
'currency_rate' => (double) $this->currency_rate,
|
||||||
|
'dt_transaction' => $this->dt_transaction,
|
||||||
|
'status' => (int) $this->status,
|
||||||
|
'booking_id' => (int) $this->booking_id,
|
||||||
|
'company_id' => (int) $this->company_id
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Relations\HasOne;
|
||||||
|
|
||||||
|
|
||||||
|
class Receipt extends AbstractModel
|
||||||
|
{
|
||||||
|
protected $table = 'receipt';
|
||||||
|
|
||||||
|
public function company(): HasOne
|
||||||
|
{
|
||||||
|
return $this->hasOne(Companies::class, 'company_id', 'id');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function currency(): HasOne
|
||||||
|
{
|
||||||
|
return $this->hasOne(Currency::class, 'currency_id', 'id');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function original_currency(): HasOne
|
||||||
|
{
|
||||||
|
return $this->hasOne(Currency::class, 'original_currency_id', 'id');
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Relations\HasOne;
|
||||||
|
|
||||||
|
|
||||||
|
class ReceiptDetail extends AbstractModel
|
||||||
|
{
|
||||||
|
protected $table = 'receipt_detail';
|
||||||
|
|
||||||
|
public function transaction(): HasOne
|
||||||
|
{
|
||||||
|
return $this->hasOne(Transaction::class, 'transaction_id', 'id');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function receipt(): HasOne
|
||||||
|
{
|
||||||
|
return $this->hasOne(Receipt::class, 'receipt_id', 'id');
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,62 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
class CreateReceiptTable extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function up()
|
||||||
|
{
|
||||||
|
Schema::create('receipt', function (Blueprint $table) {
|
||||||
|
$table->id();
|
||||||
|
$table->string('trans_type1');
|
||||||
|
$table->string('trans_type2');
|
||||||
|
$table->bigInteger('bill_no')->unsigned();
|
||||||
|
$table->decimal('amount', 14, 5)->default(0.00);
|
||||||
|
$table->decimal('original_amount', 14, 5)->default(0.00);
|
||||||
|
$table->bigInteger('currency_id')->unsigned();
|
||||||
|
$table->bigInteger('original_currency_id')->unsigned();
|
||||||
|
$table->decimal('currency_rate', 14, 5)->default(0.00);
|
||||||
|
$table->date('dt_transaction');
|
||||||
|
$table->integer('status');
|
||||||
|
$table->bigInteger('booking_id')->unsigned();
|
||||||
|
$table->bigInteger('company_id')->unsigned();
|
||||||
|
$table->timestamps();
|
||||||
|
$table->foreign('company_id')->references('id')->on('companies')->onDelete('cascade');
|
||||||
|
$table->foreign('currency_id')->references('id')->on('currencies')->onDelete('cascade');
|
||||||
|
$table->foreign('original_currency_id')->references('id')->on('currencies')->onDelete('cascade');
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
Schema::create('receipt_detail', function (Blueprint $table) {
|
||||||
|
$table->id();
|
||||||
|
$table->string('trans_type1');
|
||||||
|
$table->string('trans_type2');
|
||||||
|
$table->bigInteger('receipt_id')->unsigned();
|
||||||
|
$table->bigInteger('transaction_id')->unsigned();
|
||||||
|
$table->decimal('price', 14, 5)->default(0.00);
|
||||||
|
$table->decimal('amount', 14, 5)->default(0.00);
|
||||||
|
$table->timestamps();
|
||||||
|
$table->foreign('receipt_id')->references('id')->on('receipt')->onDelete('cascade');
|
||||||
|
$table->foreign('transaction_id')->references('id')->on('transaction')->onDelete('cascade');
|
||||||
|
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function down()
|
||||||
|
{
|
||||||
|
Schema::dropIfExists('receipt');
|
||||||
|
Schema::dropIfExists('receipt_detail');
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -19,6 +19,8 @@ Route::group(['middleware' => 'api', 'prefix' => 'v1', 'as' => 'api.'], function
|
|||||||
require __DIR__ . '/account.php';
|
require __DIR__ . '/account.php';
|
||||||
|
|
||||||
require __DIR__ . '/transaction.php';
|
require __DIR__ . '/transaction.php';
|
||||||
|
|
||||||
|
require __DIR__ . '/receipt.php';
|
||||||
|
|
||||||
Route::group(['middleware' => 'valid.token'], function () {
|
Route::group(['middleware' => 'valid.token'], function () {
|
||||||
require __DIR__ . '/crud.php';
|
require __DIR__ . '/crud.php';
|
||||||
|
|||||||
@@ -0,0 +1,10 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Support\Facades\Route;
|
||||||
|
|
||||||
|
Route::group(['prefix' => 'receipt', 'namespace' => 'Receipts', 'as' => 'receipt.'], function () {
|
||||||
|
|
||||||
|
Route::post('/create/{id}', 'CreateReceiptController@create')->name('create');
|
||||||
|
//Route::post('/create-transaction/{id}', 'CreateWalletTransactionController@create')->name('create_transaction');
|
||||||
|
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user