Merge branch 'master' into 'login_register'

# Conflicts:
#   routes/api.php
This commit is contained in:
omair saleh
2020-12-08 07:26:12 +00:00
72 changed files with 2586 additions and 27 deletions
+1 -1
View File
@@ -45,4 +45,4 @@ PUSHER_APP_CLUSTER=mt1
MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"
JWT_SECRET=
JWT_SECRET=
@@ -0,0 +1,116 @@
<?php
namespace App\Classes\Modules\Bookings\ControllersLogic;
use App\Classes\General\Abstracts\AbstractControllerLogic;
use App\Classes\Modules\Companies\Services\FetchesCompany;
use App\Classes\Modules\CompanyBanks\Services\FetchesCompanyBank;
use App\Classes\Modules\Currencies\Services\FetchesCurrency;
use App\Classes\Modules\Bookings\Standards\Rules\CanCreateBooking;
use App\Classes\Modules\Bookings\Services\CreatesBooking;
use App\Classes\Modules\Bookings\Services\GeneratesBookingMarking;
use App\Classes\Modules\Bookings\DataTransferObjects\BookingObject;
use App\Http\Resources\BookingResource;
use ErrorException;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
class CreateBookingLogic extends AbstractControllerLogic
{
/**
* @return array
*/
protected function notification():array {
return [
'title' => 'Created Booking',
'message' => 'You have successfully created a new Booking'
];
}
/** @var CanCreateBooking */
private $canCreateBooking;
/** @var CreatesBooking */
private $createsBooking;
/** @var GeneratesBookingMarking */
private $generatesBookingMarking;
/** @var FetchesCompany */
private $fetchesCompany;
/** @var FetchesCompanyBank */
private $fetchesCompanyBank;
/** @var FetchesCurrency */
private $fetchesCurrency;
/**
* CreateSegmentLogic constructor.
* @param CanCreateBooking $canCreateBooking
* @param CreatesBooking $createsBooking
* @param FetchesCompany $fetchesCompany
* @param FetchesCompanyBank $fetchesCompanyBank
* @param FetchesCurrency $fetchesCurrency
*/
public function __construct(
CanCreateBooking $canCreateBooking,
CreatesBooking $createsBooking,
GeneratesBookingMarking $generatesBookingMarking,
FetchesCompany $fetchesCompany,
FetchesCompanyBank $fetchesCompanyBank,
FetchesCurrency $fetchesCurrency
)
{
$this->canCreateBooking = $canCreateBooking;
$this->createsBooking = $createsBooking;
$this->generatesBookingMarking = $generatesBookingMarking;
$this->fetchesCompany = $fetchesCompany;
$this->fetchesCompanyBank = $fetchesCompanyBank;
$this->fetchesCurrency = $fetchesCurrency;
}
/**
* @param Request $request
* @return JsonResponse
* @throws ErrorException
*/
public function logic(Request $request) : JsonResponse
{
try {
DB::beginTransaction();
$booking_object = new BookingObject(
$request->input('company_id'),
$request->input('transferable_bank_id'),
$this->generatesBookingMarking->execute(),
$request->input('reference'),
number_format( (float) $request->input('fix_amount'), 5, '.', ''),
$request->input('fix_currency_id'),
$request->input('convertible_currency_id'),
$request->input('conversion_currency_id')
);
$this->canCreateBooking->passes($booking_object);
$company = $this->fetchesCompany->execute(['id' => $request->input('company_id')]);
$transferable_bank = $this->fetchesCompanyBank->execute(['id' => $request->input('transferable_bank_id')]);
$fix_currency = $this->fetchesCurrency->execute(['id' => $request->input('fix_currency_id')]);
$convertible_currency = $this->fetchesCurrency->execute(['id' => $request->input('convertible_currency_id')]);
$conversion_currency = $this->fetchesCurrency->execute(['id' => $request->input('conversion_currency_id')]);
$booking = $this->createsBooking->execute($booking_object);
DB::commit();
return $this->resourceResponse(new BookingResource($booking));
} catch (\Exception $exception) {
throw new ErrorException($exception->getMessage(), $exception->getCode());
}
}
}
@@ -0,0 +1,82 @@
<?php
namespace App\Classes\Modules\Bookings\ControllersLogic;
use App\Http\Resources\BookingResource;
use App\Classes\General\Abstracts\AbstractControllerLogic;
use App\Classes\Modules\Bookings\Services\FetchesBooking;
use App\Classes\Modules\Bookings\Standards\Rules\CanDeleteBooking;
use App\Classes\Modules\Bookings\Services\DeletesBooking;
use App\Classes\Modules\Bookings\DataTransferObjects\SegmentObject;
use ErrorException;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
class DeleteBookingLogic extends AbstractControllerLogic
{
/**
* @return array
*/
protected function notification():array {
return [
'title' => 'Delete Booking',
'message' => 'You have successfully deleted the Booking'
];
}
/** @var CanDeleteBooking */
private $canDeleteBooking;
/** @var DeletesBooking */
private $deletesBooking;
/** @var FetchesBooking */
private $fetchesBooking;
/**
* UpdateStandardSegmentConstantLogic constructor.
* @param CanUpdateSegment $canDeleteBooking
* @param UpdatesSegment $deletesSegment
* @param FetchesBooking $fetchesBooking
*/
public function __construct(
CanDeleteBooking $canDeleteBooking,
DeletesBooking $deletesBooking,
FetchesBooking $fetchesBooking
)
{
$this->canDeleteBooking = $canDeleteBooking;
$this->deletesBooking = $deletesBooking;
$this->fetchesBooking = $fetchesBooking;
}
/**
* @param Request $request
* @return JsonResponse
* @throws ErrorException
*/
public function logic(Request $request) : JsonResponse
{
try {
DB::beginTransaction();
$booking = $this->fetchesBooking->execute(['id' => $request->route('id')]);
$this->canDeleteBooking->passes();
$this->deletesBooking->execute($booking);
DB::commit();
return $this->resourceResponse(new BookingResource($booking));
} catch (\Exception $exception){
throw new ErrorException($exception->getMessage(), $exception->getCode());
}
}
}
@@ -0,0 +1,93 @@
<?php
namespace App\Classes\Modules\Bookings\ControllersLogic;
use App\Http\Resources\BookingResource;
use App\Classes\General\Abstracts\AbstractControllerLogic;
use App\Classes\Modules\Bookings\Services\FetchesBooking;
use App\Classes\Modules\Bookings\Standards\Rules\CanUpdateBooking;
use App\Classes\Modules\Bookings\Services\UpdatesBooking;
use App\Classes\Modules\Bookings\DataTransferObjects\BookingObject;
use ErrorException;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
class UpdateBookingLogic extends AbstractControllerLogic
{
/**
* @return array
*/
protected function notification():array {
return [
'title' => 'Updated Booking',
'message' => 'You have successfully updated the Booking'
];
}
/** @var CanUpdateBooking */
private $canUpdateBooking;
/** @var UpdatesBookingRate */
private $updatesBookingRate;
/** @var FetchesBooking */
private $fetchesBooking;
/**
* UpdateStandardSegmentConstantLogic constructor.
* @param CanUpdateBooking $canUpdateBooking
* @param UpdatesBooking $updatesBooking
* @param FetchesBooking $fetchesBooking
*/
public function __construct(
CanUpdateBooking $canUpdateBooking,
UpdatesBooking $updatesBooking,
FetchesBooking $fetchesBooking
)
{
$this->canUpdateBooking = $canUpdateBooking;
$this->updatesBooking = $updatesBooking;
$this->fetchesBooking = $fetchesBooking;
}
/**
* @param Request $request
* @return JsonResponse
* @throws ErrorException
*/
public function logic(Request $request) : JsonResponse
{
try {
DB::beginTransaction();
$booking = $this->fetchesBooking->execute(['id' => $request->route('id')]);
$booking_object = new BookingObject(
$booking->company_id,
$request->input('transferable_bank_id', $booking->transferable_bank_id),
$booking->marking,
$request->input('reference', $booking->reference),
$request->input('fix_amount', $booking->fix_amount),
$request->input('fix_currency_id', $booking->fix_currency_id),
$request->input('convertible_currency_id', $booking->convertible_currency_id),
$request->input('conversion_currency_id', $booking->conversion_currency_id)
);
$this->canUpdateBooking->passes($booking_object);
$booking = $this->updatesBooking->execute($booking, $booking_object);
DB::commit();
return $this->resourceResponse(new BookingResource($booking));
} catch (\Exception $exception){
throw new ErrorException($exception->getMessage(), $exception->getCode());
}
}
}
@@ -0,0 +1,112 @@
<?php
namespace App\Classes\Modules\Bookings\DataTransferObjects;
use App\Classes\Interfaces\DataTransferObject;
class BookingObject implements DataTransferObject
{
private $company_id;
private $transferable_bank_id;
private $marking;
private $reference;
private $fix_amount;
private $fix_currency_id;
private $convertible_currency_id;
private $conversion_currency_id;
/**
* BookingObject constructor.
* @param int|null $company_id
* @param int|null $transferable_bank_id
* @param string|null $marking
* @param string|null $reference
* @param float|null $fix_amount
* @param int|null $fix_currency_id
* @param int|null $convertible_currency_id
* @param int|null $conversion_currency_id
*/
public function __construct(
?int $company_id,
?int $transferable_bank_id,
?string $marking,
?string $reference,
?float $fix_amount,
?int $fix_currency_id,
?int $convertible_currency_id,
?int $conversion_currency_id
)
{
$this->company_id = $company_id;
$this->transferable_bank_id = $transferable_bank_id;
$this->marking = $marking;
$this->reference = $reference;
$this->fix_amount = $fix_amount;
$this->fix_currency_id = $fix_currency_id;
$this->convertible_currency_id = $convertible_currency_id;
$this->conversion_currency_id = $conversion_currency_id;
}
/**
* @return int
*/
public function getCompanyId(): ?int
{
return $this->company_id;
}
/**
* @return int
*/
public function getTransferableBankId(): ?int
{
return $this->transferable_bank_id;
}
/**
* @return string
*/
public function getMarking(): ?string
{
return $this->marking;
}
/**
* @return string
*/
public function getReference(): ?string
{
return $this->reference;
}
/**
* @return float
*/
public function getFixAmount(): ?float
{
return $this->fix_amount;
}
/**
* @return int
*/
public function getFixCurrencyId(): ?int
{
return $this->fix_currency_id;
}
/**
* @return int
*/
public function getConvertibleCurrencyId(): ?int
{
return $this->convertible_currency_id;
}
/**
* @return int
*/
public function getConversionCurrencyId(): ?int
{
return $this->conversion_currency_id;
}
}
@@ -0,0 +1,27 @@
<?php
namespace App\Classes\Modules\Bookings\Services;
use App\Models\Booking;
class ChecksIfBookingMarkingExists
{
/** @var Booking */
private $repository;
/**
* ChecksIfBookingMarkingExists constructor.
* @param Booking $repository
*/
public function __construct(Booking $repository)
{
$this->repository = $repository;
}
public function execute(int $marking): bool {
return $this->repository->where('marking', $marking)->exists();
}
}
@@ -0,0 +1,28 @@
<?php
namespace App\Classes\Modules\Bookings\Services;
use App\Classes\General\Eloquent\AbstractUpdateRecord;
use App\Classes\Modules\Bookings\DataTransferObjects\BookingObject;
use App\Models\Booking;
class CreatesBooking extends AbstractUpdateRecord
{
/**
* @param BookingObject $object
* @return \Illuminate\Database\Eloquent\Model
* @throws \App\Classes\Exceptions\MalformedRequestException
*/
public function execute(BookingObject $object) {
$model = new Booking();
$model->company_id = $object->getCompanyId();
$model->transferable_bank_id = $object->getTransferableBankId();
$model->marking = $object->getMarking();
$model->reference = $object->getReference();
$model->fix_amount = $object->getFixAmount();
$model->fix_currency_id = $object->getFixCurrencyId();
$model->convertible_currency_id = $object->getConvertibleCurrencyId();
$model->conversion_currency_id = $object->getConversionCurrencyId();
return $this->handler($model);
}
}
@@ -0,0 +1,14 @@
<?php
namespace App\Classes\Modules\Bookings\Services;
use App\Classes\General\Eloquent\AbstractDeleteRecord;
use App\Models\Booking;
class DeletesBooking extends AbstractDeleteRecord
{
public function execute(Booking $model) {
return $this->handler($model);
}
}
@@ -0,0 +1,33 @@
<?php
namespace App\Classes\Modules\Bookings\Services;
use App\Classes\General\Eloquent\AbstractFetchRecord;
use Illuminate\Database\Eloquent\Builder;
use App\Models\Booking;
class FetchesBooking extends AbstractFetchRecord
{
/** @var Booking */
private $repository;
/**
* FetchesUser constructor.
* @param Booking $repository
*/
public function __construct(Booking $repository)
{
$this->repository = $repository;
}
/**
* @return Builder
*/
public function getRepository(): Builder
{
return $this->repository->newQuery();
}
}
@@ -0,0 +1,31 @@
<?php
namespace App\Classes\Modules\Bookings\Services;
class GeneratesBookingMarking
{
/** @var ChecksIfBookingMarkingExists */
private $bookingMarkingExists;
/**
* GeneratesWalletCode constructor.
* @param ChecksIfBookingMarkingExists $bookingMarkingExists
*/
public function __construct(ChecksIfBookingMarkingExists $bookingMarkingExists)
{
$this->bookingMarkingExists = $bookingMarkingExists;
}
/**
* @return int
*/
public function execute(): int {
$marking = mt_rand(100000001, 999999999);
return !$this->bookingMarkingExists->execute($marking) ? $marking : self::execute();
}
}
@@ -0,0 +1,27 @@
<?php
namespace App\Classes\Modules\Bookings\Services;
use App\Classes\General\Eloquent\AbstractUpdateRecord;
use App\Classes\Modules\Bookings\DataTransferObjects\BookingObject;
use App\Models\Booking;
class UpdatesBooking extends AbstractUpdateRecord
{
/**
* @param BookingObject $object
* @return \Illuminate\Database\Eloquent\Model
* @throws \App\Classes\Exceptions\MalformedRequestException
*/
public function execute(Booking $model, BookingObject $object)
{
$model->transferable_bank_id = $object->getTransferableBankId();
$model->reference = $object->getReference();
$model->fix_amount = $object->getFixAmount();
$model->fix_currency_id = $object->getFixCurrencyId();
$model->convertible_currency_id = $object->getConvertibleCurrencyId();
$model->conversion_currency_id = $object->getConversionCurrencyId();
return $this->handler($model);
}
}
@@ -0,0 +1,55 @@
<?php
namespace App\Classes\Modules\Bookings\Standards\Rules;
use App\Classes\General\Abstracts\AbstractRule;
use App\Classes\Modules\Bookings\DataTransferObjects\SegmentObject;
use App\Classes\Modules\Bookings\Standards\Validators\BookingValidation;
class CanCreateBooking extends AbstractRule
{
/** @var BookingValidation */
private $bookingValidation;
/**
* CanCreateBooking constructor.
* @param BookingValidation $BookingValidation
*/
public function __construct(BookingValidation $bookingValidation)
{
$this->bookingValidation = $bookingValidation;
}
/**
* @return bool
*/
protected function authorized(): bool
{
// TODO Set Authorization rules
if (!\Auth::user()->can('add booking')) {
return false;
}
return true;
}
/**
* @param SegmentObject $object
* @return bool
* @throws \App\Classes\Exceptions\RequestValidationException
*/
protected function validators($object): bool
{
return $this->bookingValidation->validate($object);
}
/**
* @param SegmentObject $object
* @return bool
*/
protected function criteria($object): bool
{
return true;
}
}
@@ -0,0 +1,45 @@
<?php
namespace App\Classes\Modules\Bookings\Standards\Rules;
use App\Classes\General\Abstracts\AbstractRule;
use App\Classes\Modules\Bookings\DataTransferObjects\BookingObject;
class CanDeleteBooking extends AbstractRule
{
/**
* @return bool
*/
protected function authorized(): bool
{
// TODO Set Authorization rules
if (!\Auth::user()->can('delete booking')) {
return false;
}
return true;
}
/**
* @param BookingObject $object
* @return bool
*/
protected function validators($object): bool
{
return true;
}
/**
* @param BookingObject $object
* @return bool
*/
protected function criteria($object): bool
{
return true;
}
}
@@ -0,0 +1,58 @@
<?php
namespace App\Classes\Modules\Bookings\Standards\Rules;
use App\Classes\General\Abstracts\AbstractRule;
use App\Classes\Modules\Bookings\DataTransferObjects\BookingObject;
use App\Classes\Modules\Bookings\Standards\Validators\BookingValidation;
class CanUpdateBooking extends AbstractRule
{
/** @var BookingValidation */
private $bookingValidation;
/**
* CanCreateAddress constructor.
* @param BookingValidation $BookingValidation
*/
public function __construct(BookingValidation $bookingValidation)
{
$this->bookingValidation = $bookingValidation;
}
/**
* @return bool
*/
protected function authorized(): bool
{
// TODO Set Authorization rules
if (!\Auth::user()->can('edit booking')) {
return false;
}
return true;
}
/**
* @param BookingValidation $object
* @return bool
* @throws \App\Classes\Exceptions\RequestValidationException
*/
protected function validators($object): bool
{
return $this->bookingValidation->validate($object);
}
/**
* @param BookingValidation $object
* @return bool
*/
protected function criteria($object): bool
{
return true;
}
}
@@ -0,0 +1,52 @@
<?php
namespace App\Classes\Modules\Bookings\Standards\Validators;
use App\Classes\General\Abstracts\AbstractValidation;
use App\Classes\Modules\Bookings\DataTransferObjects\BookingObject;
class BookingValidation extends AbstractValidation
{
/**
* @param BookingObject $object
* @return array
*/
protected function data($object): array
{
return [
'company_id' => $object->getCompanyId(),
'transferable_bank_id' => $object->getTransferableBankId(),
'marking' => $object->getMarking(),
'reference' => $object->getReference(),
'fix_amount' => $object->getFixAmount(),
'fix_currency_id' => $object->getFixCurrencyId(),
'convertible_currency_id' => $object->getConvertibleCurrencyId(),
'conversion_currency_id' => $object->getConversionCurrencyId(),
];
}
/**
* @return array
*/
protected function rules(): array
{
return [
'company_id' => 'required',
'transferable_bank_id' => 'required',
'marking' => 'required',
'reference' => 'required',
'fix_amount' => 'required',
'fix_currency_id' => 'required',
'convertible_currency_id' => 'required',
'conversion_currency_id' => 'required'
];
}
/**
* @return array
*/
protected function messages(): array
{
return [];
}
}
@@ -0,0 +1,33 @@
<?php
namespace App\Classes\Modules\Companies\Services;
use App\Classes\General\Eloquent\AbstractFetchRecord;
use Illuminate\Database\Eloquent\Builder;
use App\Models\Company;
class FetchesCompany extends AbstractFetchRecord
{
/** @var Company */
private $repository;
/**
* FetchesUser constructor.
* @param Company $repository
*/
public function __construct(Company $repository)
{
$this->repository = $repository;
}
/**
* @return Builder
*/
public function getRepository(): Builder
{
return $this->repository->newQuery();
}
}
@@ -12,4 +12,9 @@ class RateCalculatesCurrency extends AbstractUpdateRecord
{
return $convert_amount = ($conversion_currency->selling / $convertable_currency->selling) * $amount;
}
public function execute_rate(Currency $conversion_currency, Currency $convertable_currency)
{
return $convert_rate = ($conversion_currency->selling / $convertable_currency->selling);
}
}
@@ -0,0 +1,147 @@
<?php
namespace App\Classes\Modules\Transactions\ControllersLogic;
use App\Classes\General\Abstracts\AbstractControllerLogic;
use App\Classes\Modules\Transactions\Standards\Rules\CanCreateTransaction;
use App\Classes\Modules\Transactions\Standards\Rules\CanCreateTransactionDetail;
use App\Classes\Modules\Transactions\DataTransferObjects\TransactionObject;
use App\Classes\Modules\Transactions\DataTransferObjects\TransactionDetailObject;
use App\Classes\Modules\Transactions\Services\CreatesTransaction;
use App\Classes\Modules\Transactions\Services\CreatesTransactionDetail;
use App\Classes\Modules\Transactions\Services\GeneratesTransactionBillNo;
use App\Http\Resources\TransactionResource;
use App\Http\Resources\TransactionDetailResource;
use App\Classes\Modules\Currencies\Services\FetchesCurrency;
use App\Classes\Modules\Currencies\Services\RateCalculatesCurrency;
use App\Classes\Modules\Companies\Services\FetchesCompany;
use ErrorException;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
class CreateTransactionLogic extends AbstractControllerLogic
{
/**
* @return array
*/
protected function notification():array {
return [
'title' => 'Created Transaction',
'message' => 'You have successfully created a transaction'
];
}
/** @var GeneratesTransactionBillNo */
private $generatesTransactionBillNo;
/** @var CanCreateTransaction */
private $canCreateTransaction;
private $fetchesCurrency;
private $rateCalculatesCurrency;
private $fetchesCompany;
private $createsTransaction;
private $canCreateTransactionDetail;
private $createsTransactionDetail;
/**
* CreateWalletLogic constructor.
* @param CreatesWallet $createsWallet
* @param GeneratesWalletCode $generatesWalletCode
* @param CanCreateCompanyWallet $canCreateCompanyWallet
*/
public function __construct(
GeneratesTransactionBillNo $generatesTransactionBillNo, CanCreateTransaction $canCreateTransaction,
FetchesCurrency $fetchesCurrency,RateCalculatesCurrency $rateCalculatesCurrency, FetchesCompany $fetchesCompany,
CreatesTransaction $createsTransaction,
CanCreateTransactionDetail $canCreateTransactionDetail, CreatesTransactionDetail $createsTransactionDetail
){
$this->generatesTransactionBillNo = $generatesTransactionBillNo;
$this->canCreateTransaction = $canCreateTransaction;
$this->fetchesCurrency = $fetchesCurrency;
$this->rateCalculatesCurrency = $rateCalculatesCurrency;
$this->fetchesCompany = $fetchesCompany;
$this->createsTransaction =$createsTransaction;
$this->canCreateTransactionDetail =$canCreateTransactionDetail;
$this->createsTransactionDetail = $createsTransactionDetail;
}
/**
* @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);
/*
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
*/
$object = new TransactionObject(
$this->generatesTransactionBillNo->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->canCreateTransaction->passes($object);
$transaction = $this->createsTransaction->execute($object);
$transaction_array = new TransactionResource($transaction);
$transaction_detail_array = array();
foreach ($json_array['transaction_detail'] as $key => $value) {
$object_detail = new TransactionDetailObject(
$json_array['trans_type1'],$json_array['trans_type2'],
$transaction->id,$value['product_code'],$value['product_name'],
(int)$value['qty'],number_format( (float) $convert_amount, 5, '.', ''), number_format( (float) $json_array['amount'], 5, '.', '')
);
$this->canCreateTransactionDetail->passes($object_detail);
$transaction_detail = $this->createsTransactionDetail->execute($object_detail);
//array_push($stack, "apple", "raspberry");
$transaction_detail_resource= new TransactionDetailResource($transaction_detail);
$transaction_detail_array[]= $transaction_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($transaction_array);
//return $this->resourceResponse($json_array);
} catch (\Exception $exception) {
throw new ErrorException($exception->getMessage(), $exception->getCode());
}
}
}
@@ -0,0 +1,113 @@
<?php
namespace App\Classes\Modules\Transactions\DataTransferObjects;
use App\Classes\Interfaces\DataTransferObject;
class TransactionDetailObject implements DataTransferObject
{
/*
*
* $table->string('trans_type1');
$table->string('trans_type2');
$table->bigInteger('transaction_id')->unsigned();
$table->string('product_code');
$table->string('product_name');
$table->integer('qty')->default(0);
$table->decimal('price', 14, 5)->default(0.00);
$table->decimal('amount', 14, 5)->default(0.00);
*/
private $trans_type1;
private $trans_type2;
private $transaction_id;
private $product_code;
private $product_name;
private $qty;
private $price;
private $amount;
public function __construct(
string $trans_type1,string $trans_type2,
int $transaction_id, string $product_code, $product_name,
int $qty, float $price,float $amount
){
$this->trans_type1= $trans_type1;
$this->trans_type2 = $trans_type2;
$this->transaction_id = $transaction_id;
$this->product_code = $product_code;
$this->product_name = $product_name;
$this->qty = $qty;
$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 string
*/
public function getProductCode(): string
{
return $this->product_code;
}
/**
* @return string
*/
public function getProductName(): string
{
return $this->product_name;
}
/**
* @return int
*/
public function getQty(): int
{
return $this->qty;
}
public function getPrice(): float
{
return $this->price;
}
public function getAmount(): float
{
return $this->amount;
}
}
@@ -0,0 +1,150 @@
<?php
namespace App\Classes\Modules\Transactions\DataTransferObjects;
use App\Classes\Interfaces\DataTransferObject;
class TransactionObject 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\Transactions\Services;
use App\Models\Transaction;
class ChecksIfTransactionBillNoExists
{
private $repository;
public function __construct(Transaction $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\Transactions\Services;
use App\Classes\General\Eloquent\AbstractUpdateRecord;
use App\Classes\Modules\Transactions\DataTransferObjects\TransactionObject;
use App\Models\Transaction;
class CreatesTransaction extends AbstractUpdateRecord
{
/**
* @param WalletObject $object
* @return \Illuminate\Database\Eloquent\Model
* @throws \App\Classes\Exceptions\MalformedRequestException
*/
public function execute(TransactionObject $object) {
$model = new Transaction();
$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,31 @@
<?php
namespace App\Classes\Modules\Transactions\Services;
use App\Classes\General\Eloquent\AbstractUpdateRecord;
use App\Classes\Modules\Transactions\DataTransferObjects\TransactionDetailObject;
use App\Models\TransactionDetail;
class CreatesTransactionDetail extends AbstractUpdateRecord
{
/**
* @param WalletObject $object
* @return \Illuminate\Database\Eloquent\Model
* @throws \App\Classes\Exceptions\MalformedRequestException
*/
public function execute(TransactionDetailObject $object) {
$model = new TransactionDetail();
$model->trans_type1 = $object->getTransType1();
$model->trans_type2 = $object->getTransType2();
$model->transaction_id = $object->getTransactionId();
$model->product_code = $object->getProductCode();
$model->product_name = $object->getProductName();
$model->qty = $object->getQty();
$model->price = $object->getPrice();
$model->amount = $object->getAmount();
return $this->handler($model);
}
}
@@ -0,0 +1,27 @@
<?php
namespace App\Classes\Modules\Transactions\Services;
class GeneratesTransactionBillNo
{
private $transationBillNoExists;
public function __construct(ChecksIfTransactionBillNoExists $transationBillNoExists)
{
$this->transationBillNoExists = $transationBillNoExists;
}
public function execute(): int {
$code = mt_rand(100000001, 999999999);
return !$this->transationBillNoExists->execute($code) ? $code : self::execute();
}
}
@@ -0,0 +1,50 @@
<?php
namespace App\Classes\Modules\Transactions\Standards\Rules;
use App\Classes\General\Abstracts\AbstractRule;
use App\Classes\Modules\Transactions\Standards\Validators\TransactionValidation;
class CanCreateTransaction extends AbstractRule
{
/** @var WalletTransactionValidation */
private $transactionValidation;
public function __construct(TransactionValidation $transactionValidation)
{
$this->transactionValidation = $transactionValidation;
}
/**
* @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->transactionValidation->validate($object);
}
/**
* @param SegmentCompanyValidation $object
* @return bool
*/
protected function criteria($object): bool
{
return true;
}
}
@@ -0,0 +1,50 @@
<?php
namespace App\Classes\Modules\Transactions\Standards\Rules;
use App\Classes\General\Abstracts\AbstractRule;
use App\Classes\Modules\Transactions\Standards\Validators\TransactionDetailValidation;
class CanCreateTransactionDetail extends AbstractRule
{
/** @var WalletTransactionValidation */
private $transactionDetailValidation;
public function __construct(TransactionDetailValidation $transactionDetailValidation)
{
$this->transactionDetailValidation = $transactionDetailValidation;
}
/**
* @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->transactionDetailValidation->validate($object);
}
/**
* @param SegmentCompanyValidation $object
* @return bool
*/
protected function criteria($object): bool
{
return true;
}
}
@@ -0,0 +1,63 @@
<?php
namespace App\Classes\Modules\Transactions\Standards\Validators;
use App\Classes\General\Abstracts\AbstractValidation;
use App\Classes\Modules\Transactions\DataTransferObjects\TransactionDetailObject;
class TransactionDetailValidation 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(),
'product_code' => $object->getProductCode(),
'product_name'=>$object->getProductName(),
'qty'=>$object->getQty(),
'price'=>$object->getPrice(),
'amount' => $object->getAmount()
];
}
/**
* @return array
*/
protected function rules(): array
{
return [
'trans_type1' => 'required',
'trans_type2' => 'required',
'transaction_id' => 'required',
'product_code' => 'required',
'product_name'=>'required',
'qty'=>'required',
'price'=>'required',
'amount' => 'required'
];
}
/**
* @return array
*/
protected function messages(): array
{
return [];
}
}
@@ -0,0 +1,69 @@
<?php
namespace App\Classes\Modules\Transactions\Standards\Validators;
use App\Classes\General\Abstracts\AbstractValidation;
use App\Classes\Modules\Transactions\DataTransferObjects\TransactionObject;
class TransactionValidation 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 [
'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 [];
}
}
@@ -84,7 +84,7 @@ class CreateWalletLogic extends AbstractControllerLogic
DB::beginTransaction();
$object = new WalletObject($request->input('currency'), $request->input('company_id'), $this->generatesWalletCode->execute());
$object = new WalletObject($request->input('currency_id'), $request->input('company_id'), $this->generatesWalletCode->execute());
$this->canCreateCompanyWallet->passes($object);
@@ -0,0 +1,129 @@
<?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\Wallets\Services\FetchesWallet;
use App\Classes\Modules\Currencies\Services\FetchesCurrency;
use App\Classes\Modules\Currencies\Services\RateCalculatesCurrency;
/*
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;
private $fetchesCurrency;
private $rateCalculatesCurrency;
private $fetchesWallet;
/**
* CreateWalletLogic constructor.
* @param CreatesWallet $createsWallet
* @param GeneratesWalletCode $generatesWalletCode
* @param CanCreateCompanyWallet $canCreateCompanyWallet
*/
public function __construct(
CreatesWalletTransaction $createsWalletTransaction, GeneratesWalletTransactionBillNo $generatesWalletTransactionBillNo, CanCreateWalletTransaction $canCreateWalletTransaction,
FetchesCurrency $fetchesCurrency,RateCalculatesCurrency $rateCalculatesCurrency, FetchesWallet $fetchesWallet
)
{
$this->createsWalletTransaction = $createsWalletTransaction;
$this->generatesWalletTransactionBillNo = $generatesWalletTransactionBillNo;
$this->canCreateWalletTransaction = $canCreateWalletTransaction;
$this->fetchesCurrency = $fetchesCurrency;
$this->rateCalculatesCurrency = $rateCalculatesCurrency;
$this->fetchesWallet = $fetchesWallet;
}
/**
* @param Request $request
* @return JsonResponse
* @throws ErrorException
*/
public function logic(Request $request) : JsonResponse
{
try {
DB::beginTransaction();
$wallet = $this->fetchesWallet->execute(['id' => $request->route('id')]);
$conversion_currency = $this->fetchesCurrency->execute(['id' => $request->input('currency_id')]);
$convertable_currency = $this->fetchesCurrency->execute(['id' => $wallet->currency_id]);//MYR
$convert_amount = $this->rateCalculatesCurrency->execute($conversion_currency, $convertable_currency, $request->input('amount'));
$convert_rate = $this->rateCalculatesCurrency->execute_rate($conversion_currency, $convertable_currency);
$object = new WalletTransactionObject(
$wallet->id, $this->generatesWalletTransactionBillNo->execute(),$request->input('trans_type'),
number_format( (float) $convert_amount, 5, '.', ''), $wallet->currency_id , number_format( (float) $request->input('amount'), 5, '.', ''),
$request->input('currency_id'),number_format( (float) $convert_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());
}
}
}
@@ -11,7 +11,7 @@ class WalletObject implements DataTransferObject
private $company_id;
/** @var int */
private $currency;
private $currency_id;
/** @var int */
private $code;
@@ -25,7 +25,7 @@ class WalletObject implements DataTransferObject
public function __construct(int $company_id, int $currency, int $code)
{
$this->company_id = $company_id;
$this->currency = $currency;
$this->currency_id = $currency;
$this->code = $code;
}
@@ -42,7 +42,7 @@ class WalletObject implements DataTransferObject
*/
public function getCurrency(): int
{
return $this->currency;
return $this->currency_id;
}
/**
@@ -0,0 +1,94 @@
<?php
namespace App\Classes\Modules\Wallets\DataTransferObjects;
use App\Classes\Interfaces\DataTransferObject;
class WalletTransactionObject implements DataTransferObject
{
private $wallet_id;
private $bill_no;
private $trans_type;
private $amount;
private $currency_id;
private $original_amount;
private $original_currency_id;
private $currency_rate;
public function __construct(
int $wallet_id, int $bill_no,int $trans_type,
float $amount, int $currency_id, int $original_amount,
int $original_currency_id, float $currency_rate
){
$this->wallet_id = $wallet_id;
$this->bill_no = $bill_no;
$this->trans_type = $trans_type;
$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;
}
/**
* @return int
*/
public function getWalletId(): int
{
return $this->wallet_id;
}
/**
* @return int
*/
public function getBillNo(): int
{
return $this->bill_no;
}
/**
* @return int
*/
public function getTransType(): int
{
return $this->trans_type;
}
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;
}
}
@@ -0,0 +1,22 @@
<?php
namespace App\Classes\Modules\Wallets\Services;
use App\Models\WalletTransaction;
class ChecksIfWalletTransactionBillNoExists
{
private $repository;
public function __construct(WalletTransaction $repository)
{
$this->repository = $repository;
}
public function execute(int $bill_no): bool {
return $this->repository->where('bill_no', $bill_no)->exists();
}
}
@@ -17,7 +17,7 @@ class CreatesWallet extends AbstractUpdateRecord
$model = new Wallet();
$model->company_id = $object->getCompanyId();
$model->code = $object->getCode();
$model->currency = $object->getCurrency();
$model->currency_id = $object->getCurrency();
return $this->handler($model);
@@ -0,0 +1,30 @@
<?php
namespace App\Classes\Modules\Wallets\Services;
use App\Classes\General\Eloquent\AbstractUpdateRecord;
use App\Classes\Modules\Wallets\DataTransferObjects\WalletTransactionObject;
use App\Models\WalletTransaction;
class CreatesWalletTransaction extends AbstractUpdateRecord
{
/**
* @param WalletObject $object
* @return \Illuminate\Database\Eloquent\Model
* @throws \App\Classes\Exceptions\MalformedRequestException
*/
public function execute(WalletTransactionObject $object) {
$model = new WalletTransaction();
$model->wallet_id = $object->getWalletId();
$model->bill_no = $object->getBillNo();
$model->trans_type = $object->getTransType();
$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();
return $this->handler($model);
}
}
@@ -0,0 +1,33 @@
<?php
namespace App\Classes\Modules\Wallets\Services;
use App\Classes\General\Eloquent\AbstractFetchRecord;
use Illuminate\Database\Eloquent\Builder;
use App\Models\Wallet;
class FetchesWallet extends AbstractFetchRecord
{
/** @var Currency */
private $repository;
/**
* FetchesUser constructor.
* @param Currency $repository
*/
public function __construct(Wallet $repository)
{
$this->repository = $repository;
}
/**
* @return Builder
*/
public function getRepository(): Builder
{
return $this->repository->newQuery();
}
}
@@ -0,0 +1,27 @@
<?php
namespace App\Classes\Modules\Wallets\Services;
class GeneratesWalletTransactionBillNo
{
private $walletTransationBillNoExists;
public function __construct(ChecksIfWalletTransactionBillNoExists $walletTransationBillNoExists)
{
$this->walletTransationBillNoExists = $walletTransationBillNoExists;
}
public function execute(): int {
$code = mt_rand(100000001, 999999999);
return !$this->walletTransationBillNoExists->execute($code) ? $code : self::execute();
}
}
@@ -0,0 +1,50 @@
<?php
namespace App\Classes\Modules\Wallets\Standards\Rules;
use App\Classes\General\Abstracts\AbstractRule;
use App\Classes\Modules\Wallets\Standards\Validators\WalletTransactionValidation;
class CanCreateWalletTransaction extends AbstractRule
{
/** @var WalletTransactionValidation */
private $walletTransactionValidation;
public function __construct(WalletTransactionValidation $walletTransactionValidation)
{
$this->walletTransactionValidation = $walletTransactionValidation;
}
/**
* @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->walletTransactionValidation->validate($object);
}
/**
* @param SegmentCompanyValidation $object
* @return bool
*/
protected function criteria($object): bool
{
return true;
}
}
@@ -16,7 +16,7 @@ class CompanyWalletValidation extends AbstractValidation
{
return [
'company_id' => $object->getCompanyId(),
'currency' => $object->getCurrency(),
'currency_id' => $object->getCurrency(),
];
}
@@ -27,7 +27,7 @@ class CompanyWalletValidation extends AbstractValidation
{
return [
'company_id' => 'required',
'currency' => 'required',
'currency_id' => 'required',
];
}
@@ -0,0 +1,42 @@
<?php
namespace App\Classes\Modules\Wallets\Standards\Validators;
use App\Classes\General\Abstracts\AbstractValidation;
use App\Classes\Modules\Wallets\DataTransferObjects\WalletObject;
use App\Classes\Modules\Wallets\DataTransferObjects\WalletTransactionObject;
class WalletTransactionValidation extends AbstractValidation
{
protected function data($object): array
{
return [
'wallet_id' => $object->getWalletId(),
'currency_id' => $object->getCurrency(),
'amount' => $object->getAmount(),
'trans_type'=>$object->getTransType()
];
}
/**
* @return array
*/
protected function rules(): array
{
return [
'wallet_id' => 'required',
'currency_id' => 'required',
'amount' => 'required',
'trans_type'=>'required'
];
}
/**
* @return array
*/
protected function messages(): array
{
return [];
}
}
@@ -0,0 +1,19 @@
<?php
namespace App\Http\Controllers\Bookings;
use App\Classes\Modules\Bookings\ControllersLogic\CreateBookingLogic;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
class CreateBookingController
{
/**
* @param Request $request
* @param CreateBookingLogic $logic
* @return JsonResponse
*/
public function create(Request $request, CreateBookingLogic $logic): JsonResponse {
return $logic->execute($request);
}
}
@@ -0,0 +1,19 @@
<?php
namespace App\Http\Controllers\Bookings;
use App\Classes\Modules\Bookings\ControllersLogic\DeleteBookingLogic;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
class DeleteBookingController
{
/**
* @param Request $request
* @param DeleteBookingLogic $logic
* @return JsonResponse
*/
public function delete(Request $request, DeleteBookingLogic $logic): JsonResponse {
return $logic->execute($request);
}
}
@@ -0,0 +1,20 @@
<?php
namespace App\Http\Controllers\Bookings;
use App\Classes\Modules\Bookings\ControllersLogic\UpdateBookingLogic;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
class UpdateBookingController
{
/**
* @param Request $request
* @param UpdateBookingLogic $logic
* @return JsonResponse
*/
public function update(Request $request, UpdateBookingLogic $logic): JsonResponse {
return $logic->execute($request);
}
}
@@ -0,0 +1,15 @@
<?php
namespace App\Http\Controllers\Transactions;
use App\Classes\Modules\Transactions\ControllersLogic\CreateTransactionLogic;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
class CreateTransactionController
{
public function create(Request $request, CreateTransactionLogic $logic): JsonResponse {
return $logic->execute($request);
}
}
@@ -0,0 +1,15 @@
<?php
namespace App\Http\Controllers\Wallets;
use App\Classes\Modules\Wallets\ControllersLogic\CreateWalletTransactionLogic;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
class CreateWalletTransactionController
{
public function create(Request $request, CreateWalletTransactionLogic $logic): JsonResponse {
return $logic->execute($request);
}
}
+30
View File
@@ -0,0 +1,30 @@
<?php
namespace App\Http\Resources;
use Illuminate\Http\Resources\Json\JsonResource;
class BookingResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @param \Illuminate\Http\Request $request
* @return array
*/
public function toArray($request)
{
return [
'id' => $this->id,
'company_id' => $this->company_id,
'transferable_bank_id' => $this->transferable_bank_id,
'marking' => $this->marking,
'reference' => $this->reference,
'fix_amount' => $this->fix_amount,
'fix_currency_id' => $this->fix_currency_id,
'convertible_currency_id' => $this->convertible_currency_id,
'conversion_currency_id' => $this->conversion_currency_id,
'status' => $this->status
];
}
}
@@ -0,0 +1,31 @@
<?php
namespace App\Http\Resources;
use Illuminate\Http\Resources\Json\JsonResource;
class TransactionDetailResource 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,
'product_code' => $this->product_code,
'product_name' => $this->product_name,
'qty' => (int) $this->qty,
'price' => (double) $this->price,
'amount' => (double) $this->amount
];
}
}
@@ -0,0 +1,34 @@
<?php
namespace App\Http\Resources;
use Illuminate\Http\Resources\Json\JsonResource;
class TransactionResource 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
];
}
}
+1 -1
View File
@@ -17,7 +17,7 @@ class WalletResource extends JsonResource
return [
'id' => $this->id,
'code' => $this->code,
'currency' => $this->currency,
'currency_id' => $this->currency_id,
'amount' => (double) $this->amount,
'company_id' => (int) $this->company_id
];
@@ -0,0 +1,29 @@
<?php
namespace App\Http\Resources;
use Illuminate\Http\Resources\Json\JsonResource;
class WalletTransactionResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @param \Illuminate\Http\Request $request
* @return array
*/
public function toArray($request)
{
return [
'id' => $this->id,
'wallet_id' => (int) $this->wallet_id,
'bill_no' => (int) $this->bill_no,
'trans_type'=>(int) $this->trans_type,
'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
];
}
}
+27
View File
@@ -0,0 +1,27 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\SoftDeletes;
/**
* Class Booking
* @package App\Models
* @version August 4, 2020, 4:36 am
*
* @property \App\Models\Company company_id
* @property \App\Models\CompanyBank transferable_bank_id
* @property string marking
* @property string reference
* @property float fix_amount
* @property \App\Models\Currency convertible_currency_id
* @property \App\Models\Currency conversion_currency_id
*/
class Booking extends AbstractModel
{
use SoftDeletes;
protected $table = 'bookings';
protected $dates = ['deleted_at'];
}
+27
View File
@@ -0,0 +1,27 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Relations\HasOne;
class Transaction extends AbstractModel
{
protected $table = 'transaction';
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');
}
}
+17
View File
@@ -0,0 +1,17 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Relations\HasOne;
class TransactionDetail extends AbstractModel
{
protected $table = 'transaction_detail';
public function transaction(): HasOne
{
return $this->hasOne(Transaction::class, 'transaction_id', 'id');
}
}
+27
View File
@@ -0,0 +1,27 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Relations\HasOne;
class WalletTransaction extends AbstractModel
{
protected $table = 'wallet_transaction';
public function wallet(): HasOne
{
return $this->hasOne(Wallet::class, 'wallet_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');
}
}
@@ -20,7 +20,7 @@ class CreateCurrenciesTable extends Migration
$table->string('name')->nullable();
$table->string('short_code')->nullable();
$table->string('symbol')->nullable();
$table->float('selling', 20, 5)->nullable();
$table->decimal('selling', 20, 5)->nullable();
$table->timestamps();
$table->softDeletes();
});
@@ -17,7 +17,7 @@ class CreateCurrencyLogsTable extends Migration
$table->id();
$table->bigInteger('currency_id')->unsigned()->nullable();
$table->foreign('currency_id')->references('id')->on('currencies')->onDelete('cascade');
$table->float('selling', 20, 5)->nullable();
$table->decimal('selling', 20, 5)->nullable();
$table->bigInteger('created_by')->unsigned()->nullable();
$table->foreign('created_by')->references('id')->on('users')->onDelete('cascade');
$table->timestamps();
@@ -19,7 +19,7 @@ class CreateCompaniesWalletTable extends Migration
$table->bigInteger('company_id')->unsigned();
$table->string('code');
$table->bigInteger('currency_id')->unsigned();
$table->decimal('amount', 14, 5)->default(0.00);
$table->decimal('amount', 20, 5)->default(0.00);
$table->timestamps();
$table->foreign('company_id')->references('id')->on('companies')->onDelete('cascade');
@@ -0,0 +1,45 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateWalletTransactionTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('wallet_transaction', function (Blueprint $table) {
$table->id();
$table->bigInteger('wallet_id')->unsigned();
$table->bigInteger('bill_no')->unsigned();
$table->integer('trans_type');
$table->decimal('amount', 14, 5)->default(0.00);
$table->bigInteger('currency_id')->unsigned();
$table->decimal('original_amount', 14, 5)->default(0.00);
$table->bigInteger('original_currency_id')->unsigned();
$table->decimal('currency_rate', 14, 5)->default(0.00);
$table->timestamps();
$table->foreign('wallet_id')->references('id')->on('wallets')->onDelete('cascade');
$table->foreign('currency_id')->references('id')->on('currencies')->onDelete('cascade');
$table->foreign('original_currency_id')->references('id')->on('currencies')->onDelete('cascade');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('wallet_transaction');
}
}
@@ -0,0 +1,63 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateTransactionTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('transaction', 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('transaction_detail', function (Blueprint $table) {
$table->id();
$table->string('trans_type1');
$table->string('trans_type2');
$table->bigInteger('transaction_id')->unsigned();
$table->string('product_code');
$table->string('product_name');
$table->integer('qty')->default(0);
$table->decimal('price', 14, 5)->default(0.00);
$table->decimal('amount', 14, 5)->default(0.00);
$table->timestamps();
$table->foreign('transaction_id')->references('id')->on('transaction')->onDelete('cascade');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('transaction');
Schema::dropIfExists('transaction_detail');
}
}
@@ -0,0 +1,46 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateBookingsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('bookings', function (Blueprint $table) {
$table->id();
$table->bigInteger('company_id')->unsigned()->nullable();
$table->foreign('company_id')->references('id')->on('companies')->onDelete('cascade');
$table->bigInteger('transferable_bank_id')->unsigned()->nullable();
$table->foreign('transferable_bank_id')->references('id')->on('company_banks')->onDelete('cascade');
$table->string('marking');
$table->string('reference');
$table->float('fix_amount', 20, 5)->nullable();
$table->bigInteger('fix_currency_id')->unsigned()->nullable();
$table->foreign('fix_currency_id')->references('id')->on('currencies')->onDelete('cascade');
$table->bigInteger('convertible_currency_id')->unsigned()->nullable();
$table->foreign('convertible_currency_id')->references('id')->on('currencies')->onDelete('cascade');
$table->bigInteger('conversion_currency_id')->unsigned()->nullable();
$table->foreign('conversion_currency_id')->references('id')->on('currencies')->onDelete('cascade');
$table->integer('status')->default(1);
$table->timestamps();
$table->softDeletes();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('bookings');
}
}
@@ -54,6 +54,11 @@ class AdminUserPermissionsTableSeeder extends Seeder
Permission::create(['name' => 'edit currency', 'guard_name' => 'web']);
Permission::create(['name' => 'delete currency', 'guard_name' => 'web']);
Permission::create(['name' => 'view booking', 'guard_name' => 'web']);
Permission::create(['name' => 'add booking', 'guard_name' => 'web']);
Permission::create(['name' => 'edit booking', 'guard_name' => 'web']);
Permission::create(['name' => 'delete booking', 'guard_name' => 'web']);
///////////////////////////////////////////////////////////////////////
$shadow_admin_role = Role::create([
@@ -0,0 +1,30 @@
<?php
use Illuminate\Database\Seeder;
use Illuminate\Support\Str;
class CompanyBanksTableSeeder extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
DB::table('company_banks')->insert([
[
'id' => 1,
'country_id' => 1,
'bank_name' => '12345678',
'holder_name' => '12345678',
'account_no' => '12345678',
'type' => 1,
'default' => 1,
'status' => 1,
'created_at' => date('Y-m-d H:i:s'),
'updated_at' => date('Y-m-d H:i:s')
]
]);
}
}
+1
View File
@@ -23,6 +23,7 @@ class DatabaseSeeder extends Seeder
$this->call(SegmentConstantsTableSeeder::class);
$this->call(CompaniesTableSeeder::class);
$this->call(CompanyBanksTableSeeder::class);
// Admin
$this->call(AdminUserTableSeeder::class);
+7
View File
@@ -0,0 +1,7 @@
include.path=${php.global.include.path}
php.version=PHP_70
source.encoding=UTF-8
src.dir=.
tags.asp=false
tags.short=false
web.root=.
+9
View File
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://www.netbeans.org/ns/project/1">
<type>org.netbeans.modules.php.project</type>
<configuration>
<data xmlns="http://www.netbeans.org/ns/php-project/1">
<name>laravel</name>
</data>
</configuration>
</project>
+11 -6
View File
@@ -17,18 +17,23 @@ use Illuminate\Support\Facades\Route;
Route::group(['middleware' => 'api', 'prefix' => 'v1', 'as' => 'api.'], function () {
require __DIR__ . '/account.php';
require __DIR__ . '/wallet.php';
require __DIR__ . '/transaction.php';
require __DIR__ . '/document.php';
Route::group(['middleware' => 'valid.token'], function () {
require __DIR__ . '/crud.php';
require __DIR__ . '/segment.php';
require __DIR__ . '/wallet.php';
require __DIR__ . '/company.php';
require __DIR__ . '/company_bank.php';
Route::group(['middleware' => 'valid.token'], function () {
require __DIR__ . '/crud.php';
require __DIR__ . '/segment.php';
require __DIR__ . '/company_bank.php';
require __DIR__ . '/currency.php';
});
});
+13
View File
@@ -0,0 +1,13 @@
<?php
use Illuminate\Support\Facades\Route;
Route::group(['namespace' => 'Bookings'], function () {
Route::group(['middleware' => 'valid.token'], function () {
Route::group(['prefix' => 'booking'], function () {
Route::post('/create', 'CreateBookingController@create')->name('create');
Route::put('/update/{id}', 'UpdateBookingController@update')->name('update');
Route::delete('/delete/{id}', 'DeleteBookingController@delete')->name('delete');
});
});
});
+2 -1
View File
@@ -13,4 +13,5 @@ Route::group(['prefix' => 'address', 'as' => 'address.', 'namespace' => 'Address
Route::delete('/delete/{id}', 'DeleteAddressController@destroy')->name('delete');
});
});
+3 -7
View File
@@ -2,11 +2,7 @@
use Illuminate\Support\Facades\Route;
Route::group(['namespace' => 'Documents'], function () {
Route::group(['middleware' => 'valid.token'], function () {
Route::group(['prefix' => 'document'], function () {
Route::get('/list', 'ListDocumentsController@list')->name('document.list');
Route::put('/approve/{id}', 'ApproveDocumentController@approve')->name('document.approve');
});
});
Route::group(['prefix' => 'document', 'as' => 'document.', 'namespace' => 'Documents'], function () {
Route::get('/list', 'ListDocumentsController@list')->name('list');
Route::put('/approve/{id}', 'ApproveDocumentController@approve')->name('approve');
});
+22
View File
@@ -0,0 +1,22 @@
<?php
use Illuminate\Support\Facades\Route;
Route::group(['namespace' => 'StandardSegmentConstants'], function () {
Route::group(['middleware' => 'valid.token'], function () {
Route::group(['prefix' => 'standard-segment-constant'], function () {
Route::get('/list', 'ListStandardSegmentConstantsController@list')->name('standard_segment.update');
Route::put('/update/{id}', 'UpdateStandardSegmentConstantController@update')->name('standard_segment_constant.update');
});
});
});
Route::group(['namespace' => 'SegmentConstants'], function () {
Route::group(['middleware' => 'valid.token'], function () {
Route::group(['prefix' => 'segment-constant'], function () {
Route::post('/create', 'CreateSegmentConstantController@create')->name('segment_constant.create');
Route::put('/update/{id}', 'UpdateSegmentConstantController@update')->name('segment_constant.update');
});
});
});
+10
View File
@@ -0,0 +1,10 @@
<?php
use Illuminate\Support\Facades\Route;
Route::group(['prefix' => 'transactions', 'namespace' => 'Transactions', 'as' => 'transaction.'], function () {
Route::post('/create/{id}', 'CreateTransactionController@create')->name('create');
//Route::post('/create-transaction/{id}', 'CreateWalletTransactionController@create')->name('create_transaction');
});
+2 -1
View File
@@ -2,8 +2,9 @@
use Illuminate\Support\Facades\Route;
Route::group(['prefix' => 'wallet', 'namespace' => 'Wallet', 'as' => 'wallet.'], function () {
Route::group(['prefix' => 'wallets', 'namespace' => 'Wallets', 'as' => 'wallet.'], function () {
Route::post('/create', 'CreateWalletController@create')->name('create');
Route::post('/create-transaction/{id}', 'CreateWalletTransactionController@create')->name('create_transaction');
});