diff --git a/app/Classes/General/Eloquent/Filters/SegmentId.php b/app/Classes/General/Eloquent/Filters/SegmentId.php new file mode 100644 index 00000000..dade3d25 --- /dev/null +++ b/app/Classes/General/Eloquent/Filters/SegmentId.php @@ -0,0 +1,20 @@ +where('segment_id', $value); + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/Accounts/ControllerLogic/CreateUserLogic.php b/app/Classes/Modules/Accounts/ControllerLogic/CreateUserLogic.php index 4d3a5ce9..bc898205 100644 --- a/app/Classes/Modules/Accounts/ControllerLogic/CreateUserLogic.php +++ b/app/Classes/Modules/Accounts/ControllerLogic/CreateUserLogic.php @@ -12,17 +12,18 @@ 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\Http\Resources\CompanyResource; use App\Classes\Modules\Contacts\Standards\Rules\CanCreateContact; use App\Classes\Modules\Contacts\Services\CreatesContact; use App\Classes\Modules\Contacts\DataTransferObjects\ContactObject; -use App\Http\Resources\ContactResource; use App\Classes\Modules\CompanyEmployees\Standards\Rules\CanCreateCompanyEmployee; use App\Classes\Modules\CompanyEmployees\Services\CreatesCompanyEmployee; use App\Classes\Modules\CompanyEmployees\DataTransferObjects\CompanyEmployeeObject; -use App\Http\Resources\CompanyEmployeeResource; + +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; @@ -65,6 +66,12 @@ class CreateUserLogic extends AbstractControllerLogic /** @var CreatesCompanyEmployee */ private $createsCompanyEmployee; + /** @var CanCreateSegmentCompany */ + private $canCreateSegmentCompany; + + /** @var CreatesSegmentCompany */ + private $createsSegmentCompany; + /** * CreateUserControllerLogic constructor. * @param CanCreateUser $canCreateUser @@ -75,6 +82,8 @@ class CreateUserLogic extends AbstractControllerLogic * @param CreatesContact $createsContact * @param CanCreateCompanyEmployee $canCreateCompanyEmployee * @param CreatesCompanyEmployee $createsCompanyEmployee + * @param CanCreateSegmentCompany $canCreateSegmentCompany + * @param CreatesSegmentCompany $createsSegmentCompany */ public function __construct( CanCreateUser $canCreateUser, @@ -84,7 +93,9 @@ class CreateUserLogic extends AbstractControllerLogic CanCreateContact $canCreateContact, CreatesContact $createsContact, CanCreateCompanyEmployee $canCreateCompanyEmployee, - CreatesCompanyEmployee $createsCompanyEmployee + CreatesCompanyEmployee $createsCompanyEmployee, + CanCreateSegmentCompany $canCreateSegmentCompany, + CreatesSegmentCompany $createsSegmentCompany ) { $this->canCreateUser = $canCreateUser; @@ -95,6 +106,8 @@ class CreateUserLogic extends AbstractControllerLogic $this->createsContact = $createsContact; $this->canCreateCompanyEmployee = $canCreateCompanyEmployee; $this->createsCompanyEmployee = $createsCompanyEmployee; + $this->canCreateSegmentCompany = $canCreateSegmentCompany; + $this->createsSegmentCompany = $createsSegmentCompany; } /** @@ -140,7 +153,6 @@ class CreateUserLogic extends AbstractControllerLogic $this->canCreateContact->passes($contact_object); $contact_query = $this->createsContact->execute($contact_object); - $company_employee_object = new CompanyEmployeeObject( $company_query->id, $user_query->id @@ -149,11 +161,21 @@ class CreateUserLogic extends AbstractControllerLogic $this->canCreateCompanyEmployee->passes($company_employee_object); $company_employee_query = $this->createsCompanyEmployee->execute($user_query, $company_employee_object); + + $segment_company_object = new SegmentCompanyObject( + 1, + $company_query->id + ); + + $this->canCreateSegmentCompany->passes($segment_company_object); + $segment_company_query = $this->createsSegmentCompany->execute($company_query, $segment_company_object); + DB::commit(); return $this->resourceResponse(new UserResource($user_query)); } catch (\Exception $exception) { + dd($exception); throw new ErrorException($exception->getMessage(), $exception->getCode()); } diff --git a/app/Classes/Modules/Documents/ControllerLogic/ApproveDocumentLogic.php b/app/Classes/Modules/Documents/ControllerLogic/ApproveDocumentLogic.php new file mode 100644 index 00000000..c41ab371 --- /dev/null +++ b/app/Classes/Modules/Documents/ControllerLogic/ApproveDocumentLogic.php @@ -0,0 +1,97 @@ + 'Approve Document', + 'message' => 'You have successfully approved the Document' + ]; + } + + /** @var CanUpdateDocument */ + private $canUpdateDocument; + + /** @var ApprovesDocument */ + private $approvesDocument; + + /** @var FetchesDocument */ + private $fetchesDocument; + + /** + * UpdateStandardSegmentConstantLogic constructor. + * @param CanUpdateDocument $canUpdateDocument + * @param ApprovesDocument $approvesDocument + * @param FetchesDocument $fetchesDocument + */ + public function __construct( + canUpdateDocument $canUpdateDocument, + ApprovesDocument $approvesDocument, + FetchesDocument $fetchesDocument + ) + { + $this->canUpdateDocument = $canUpdateDocument; + $this->approvesDocument = $approvesDocument; + $this->fetchesDocument = $fetchesDocument; + } + + /** + * @param Request $request + * @return JsonResponse + * @throws ErrorException + */ + public function logic(Request $request) : JsonResponse + { + try { + DB::beginTransaction(); + + $document_query = $this->fetchesDocument->execute(['id' => $request->route('id')]); + + $document_object = new DocumentObject( + $document_query->owner_id, + $document_query->owner_type, + $document_query->document_type, + $document_query->reference, + ObjectStatus::ACTIVE, + \Auth::user()->id, + $document_query->issued_date, + $document_query->expired_date, + $document_query->approved_date + ); + $this->canUpdateDocument->passes($document_object); + $document_query = $this->approvesDocument->execute($document_query, $document_object); + + DB::commit(); + + return $this->resourceResponse(new DocumentResource($document_query)); + + } catch (\Exception $exception){ + dd($exception); + throw new ErrorException($exception->getMessage(), $exception->getCode()); + } + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/Documents/ControllerLogic/ListDocumentLogic.php b/app/Classes/Modules/Documents/ControllerLogic/ListDocumentLogic.php new file mode 100644 index 00000000..25049850 --- /dev/null +++ b/app/Classes/Modules/Documents/ControllerLogic/ListDocumentLogic.php @@ -0,0 +1,82 @@ + 'Retrieved Document', + 'message' => 'You have successfully retrieved a list of Document' + ]; + } + + /** @var CanListDocuments */ + private $canListDocuments; + + /** @var ListsDocuments */ + private $listsDocuments; + + /** + * ListStandardSegmentLogic constructor. + * @param CanListDocuments $canListDocuments + * @param ListsDocuments $listsDocuments + */ + public function __construct(CanListDocuments $canListDocuments, ListsDocuments $listsDocuments) + { + $this->canListDocuments = $canListDocuments; + $this->listsDocuments = $listsDocuments; + } + + + /** + * @param Request $request + * @return JsonResponse + * @throws ErrorException + */ + public function logic(Request $request) : JsonResponse + { + try { + + $document_type = $request->input('document_type'); + $reference = $request->input('reference'); + $status = $request->input('status'); + + $data = []; + + if ($document_type) { + $data['document_type'] = $document_type; + } + if ($reference) { + $data['reference'] = $reference; + } + if ($status) { + $data['status'] = $status; + } + + $this->canListDocuments->passes(); + + $query = $this->listsDocuments->execute($data); + + return $this->collectionResponse(DocumentResource::collection($query)); + + } catch (\Exception $exception){ + throw new ErrorException($exception->getMessage(), $exception->getCode()); + } + + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/Documents/Services/ApprovesDocument.php b/app/Classes/Modules/Documents/Services/ApprovesDocument.php new file mode 100644 index 00000000..206d9efd --- /dev/null +++ b/app/Classes/Modules/Documents/Services/ApprovesDocument.php @@ -0,0 +1,23 @@ +status = $object->getStatus(); + $model->approved_by = $object->getApprovedBy(); + return $this->handler($model); + } +} \ No newline at end of file diff --git a/app/Classes/Modules/Documents/Services/FetchesDocument.php b/app/Classes/Modules/Documents/Services/FetchesDocument.php new file mode 100644 index 00000000..1aa12c87 --- /dev/null +++ b/app/Classes/Modules/Documents/Services/FetchesDocument.php @@ -0,0 +1,33 @@ +repository = $repository; + } + + + /** + * @return Builder + */ + public function getRepository(): Builder + { + return $this->repository->newQuery(); + } +} \ No newline at end of file diff --git a/app/Classes/Modules/Documents/Services/ListsDocuments.php b/app/Classes/Modules/Documents/Services/ListsDocuments.php new file mode 100644 index 00000000..9f372279 --- /dev/null +++ b/app/Classes/Modules/Documents/Services/ListsDocuments.php @@ -0,0 +1,33 @@ +repository = $repository; + } + + + /** + * @return Builder + */ + function getRepository(): Builder + { + return $this->repository->newQuery(); + } +} \ No newline at end of file diff --git a/app/Classes/Modules/Documents/Standards/Rules/CanListDocuments.php b/app/Classes/Modules/Documents/Standards/Rules/CanListDocuments.php new file mode 100644 index 00000000..d94068b7 --- /dev/null +++ b/app/Classes/Modules/Documents/Standards/Rules/CanListDocuments.php @@ -0,0 +1,45 @@ +can('view document')) { + return false; + } + + return true; + + } + + /** + * @param DocumentObject $object + * @return bool + */ + protected function validators($object): bool + { + return true; + + } + + + /** + * @param DocumentObject $object + * @return bool + */ + protected function criteria($object): bool + { + return true; + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/Documents/Standards/Rules/CanUpdateDocument.php b/app/Classes/Modules/Documents/Standards/Rules/CanUpdateDocument.php new file mode 100644 index 00000000..f07fb166 --- /dev/null +++ b/app/Classes/Modules/Documents/Standards/Rules/CanUpdateDocument.php @@ -0,0 +1,53 @@ +documentValidation = $documentValidation; + } + + /** + * @return bool + */ + protected function authorized(): bool + { + // TODO Set Authorization rules + return true; + } + + /** + * @param DocumentObject $object + * @return bool + * @throws \App\Classes\Exceptions\RequestValidationException + */ + protected function validators($object): bool + { + return $this->documentValidation->validate($object); + } + + /** + * @param DocumentObject $object + * @return bool + */ + protected function criteria($object): bool + { + return true; + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/SegmentCompanies/DataTransferObjects/SegmentCompanyObject.php b/app/Classes/Modules/SegmentCompanies/DataTransferObjects/SegmentCompanyObject.php new file mode 100644 index 00000000..023d4f57 --- /dev/null +++ b/app/Classes/Modules/SegmentCompanies/DataTransferObjects/SegmentCompanyObject.php @@ -0,0 +1,44 @@ +segment_id = $segment_id; + $this->company_id = $company_id; + } + + /** + * @return int|null + */ + public function getSegmentId(): ?int + { + return $this->segment_id; + } + + /** + * @return int|null + */ + public function getCompanyId(): ?int + { + return $this->company_id; + } +} \ No newline at end of file diff --git a/app/Classes/Modules/SegmentCompanies/Services/CreatesSegmentCompany.php b/app/Classes/Modules/SegmentCompanies/Services/CreatesSegmentCompany.php new file mode 100644 index 00000000..ae791fca --- /dev/null +++ b/app/Classes/Modules/SegmentCompanies/Services/CreatesSegmentCompany.php @@ -0,0 +1,21 @@ +segment()->sync($object->getSegmentId()); + return $model; + } +} \ No newline at end of file diff --git a/app/Classes/Modules/SegmentCompanies/Standards/Rules/CanCreateSegmentCompany.php b/app/Classes/Modules/SegmentCompanies/Standards/Rules/CanCreateSegmentCompany.php new file mode 100644 index 00000000..2670467e --- /dev/null +++ b/app/Classes/Modules/SegmentCompanies/Standards/Rules/CanCreateSegmentCompany.php @@ -0,0 +1,53 @@ +segmentCompanyValidation = $segmentCompanyValidation; + } + + /** + * @return bool + */ + protected function authorized(): bool + { + // TODO Set Authorization rules + return true; + } + + /** + * @param SegmentCompanyValidation $object + * @return bool + * @throws \App\Classes\Exceptions\RequestValidationException + */ + protected function validators($object): bool + { + return $this->segmentCompanyValidation->validate($object); + } + + /** + * @param SegmentCompanyValidation $object + * @return bool + */ + protected function criteria($object): bool + { + return true; + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/SegmentCompanies/Standards/Validators/SegmentCompanyValidation.php b/app/Classes/Modules/SegmentCompanies/Standards/Validators/SegmentCompanyValidation.php new file mode 100644 index 00000000..2185c519 --- /dev/null +++ b/app/Classes/Modules/SegmentCompanies/Standards/Validators/SegmentCompanyValidation.php @@ -0,0 +1,40 @@ + $object->getSegmentId(), + 'company_id' => $object->getCompanyId(), + ]; + } + + /** + * @return array + */ + protected function rules(): array + { + return [ + 'segment_id' => 'required', + 'company_id' => 'required', + ]; + } + + /** + * @return array + */ + protected function messages(): array + { + return []; + } +} \ No newline at end of file diff --git a/app/Classes/Modules/SegmentConstants/ControllerLogic/CreateSegmentConstantLogic.php b/app/Classes/Modules/SegmentConstants/ControllerLogic/CreateSegmentConstantLogic.php new file mode 100644 index 00000000..7f27e3f3 --- /dev/null +++ b/app/Classes/Modules/SegmentConstants/ControllerLogic/CreateSegmentConstantLogic.php @@ -0,0 +1,187 @@ + 'Created Segment Constant', + 'message' => 'You have successfully created a new Segment Constant' + ]; + } + + /** @var CanCreateSegmentConstant */ + private $canCreateSegmentConstant; + + /** @var CreatesSegmentConstantTax */ + private $createsSegmentConstantTax; + + /** @var CreatesSegmentConstantBillingFee */ + private $createsSegmentConstantBillingFee; + + /** @var CreatesSegmentConstantServiceCharge */ + private $createsSegmentConstantServiceCharge; + + /** @var CreatesSegmentConstantBookingAmountMax */ + private $createsSegmentConstantBookingAmountMax; + + /** @var CreatesSegmentConstantPaymentAttemptExpiryTime */ + private $createsSegmentConstantPaymentAttemptExpiryTime; + + /** @var FetchesSegmentConstant */ + private $fetchesSegmentConstant; + + /** @var FetchesSegment */ + private $fetchesSegment; + + /** + * CreateSegmentConstantLogic constructor. + * @param CanCreateSegmentConstant $canCreateSegmentConstant + * @param CreatesSegmentConstantTax $createsSegmentConstantTax + * @param CreatesSegmentConstantBillingFee $createsSegmentConstantBillingFee + * @param CreatesSegmentConstantServiceCharge $createsSegmentConstantServiceCharge + * @param CreatesSegmentConstantBookingAmountMax $createsSegmentConstantBookingAmountMax + * @param CreatesSegmentConstantPaymentAttemptExpiryTime $createsSegmentConstantPaymentAttemptExpiryTime + * @param FetchesSegmentConstant $fetchesSegmentConstant + * @param FetchesSegment $fetchesSegment + */ + public function __construct( + CanCreateSegmentConstant $canCreateSegmentConstant, + CreatesSegmentConstantTax $createsSegmentConstantTax, + CreatesSegmentConstantBillingFee $createsSegmentConstantBillingFee, + CreatesSegmentConstantServiceCharge $createsSegmentConstantServiceCharge, + CreatesSegmentConstantBookingAmountMax $createsSegmentConstantBookingAmountMax, + CreatesSegmentConstantPaymentAttemptExpiryTime $createsSegmentConstantPaymentAttemptExpiryTime, + FetchesSegmentConstant $fetchesSegmentConstant, + FetchesSegment $fetchesSegment + ) + { + $this->canCreateSegmentConstant = $canCreateSegmentConstant; + $this->createsSegmentConstantTax = $createsSegmentConstantTax; + $this->createsSegmentConstantBillingFee = $createsSegmentConstantBillingFee; + $this->createsSegmentConstantServiceCharge = $createsSegmentConstantServiceCharge; + $this->createsSegmentConstantBookingAmountMax = $createsSegmentConstantBookingAmountMax; + $this->createsSegmentConstantPaymentAttemptExpiryTime = $createsSegmentConstantPaymentAttemptExpiryTime; + $this->fetchesSegmentConstant = $fetchesSegmentConstant; + $this->fetchesSegment = $fetchesSegment; + } + + /** + * @param Request $request + * @return JsonResponse + * @throws ErrorException + */ + public function logic(Request $request) : JsonResponse + { + try { + DB::beginTransaction(); + + $segment_query = $this->fetchesSegment->execute([ + 'id' => $request->input('segment_id'), + ]); + + $segment_constant_query = $this->fetchesSegmentConstant->execute([ + 'id' => $request->input('standard_segment_constant_id'), + ]); + + if ($segment_constant_query->reference == 'TAX') { + $segment_constant_object = new SegmentConstantTaxObject( + $request->input('segment_id'), + $segment_constant_query->name, + $segment_constant_query->reference, + $segment_constant_query->detail->type, + $request->input('value') + ); + + $this->canCreateSegmentConstant->passes($segment_constant_object); + $segment_constant_query = $this->createsSegmentConstantTax->execute($segment_query, $segment_constant_object); + } + elseif ($segment_constant_query->reference == 'BILLING_FEE') { + $segment_constant_object = new SegmentConstantBillingFeeObject( + $request->input('segment_id'), + $segment_constant_query->name, + $segment_constant_query->reference, + $segment_constant_query->detail->type, + $request->input('value') + ); + $this->canCreateSegmentConstant->passes($segment_constant_object); + $segment_constant_query = $this->createsSegmentConstantBillingFee->execute($segment_query, $segment_constant_object); + } + elseif ($segment_constant_query->reference == 'SERVICE_CHARGE') { + $segment_constant_object = new SegmentConstantServiceChargeObject( + $request->input('segment_id'), + $segment_constant_query->name, + $segment_constant_query->reference, + $segment_constant_query->detail->type, + $request->input('value') + ); + $this->canCreateSegmentConstant->passes($segment_constant_object); + $segment_constant_query = $this->createsSegmentConstantServiceCharge->execute($segment_query, $segment_constant_object); + } + elseif ($segment_constant_query->reference == 'BOOKING_AMOUNT_MAX') { + $segment_constant_object = new SegmentConstantBookingAmountMaxObject( + $request->input('segment_id'), + $segment_constant_query->name, + $segment_constant_query->reference, + $segment_constant_query->detail->type, + $request->input('value'), + $segment_constant_query->detail->currency_id + ); + $this->canCreateSegmentConstant->passes($segment_constant_object); + $segment_constant_query = $this->createsSegmentConstantBookingAmountMax->execute($segment_query, $segment_constant_object); + } + elseif ($segment_constant_query->reference == 'PAYMENT_ATTEMP_EXPIRY_TIME') { + $segment_constant_object = new SegmentConstantPaymentAttemptExpiryTimeObject( + $request->input('segment_id'), + $segment_constant_query->name, + $segment_constant_query->reference, + $segment_constant_query->detail->type, + $request->input('value') + ); + $this->canCreateSegmentConstant->passes($segment_constant_object); + $segment_constant_query = $this->createsSegmentConstantPaymentAttemptExpiryTime->execute($segment_query, $segment_constant_object); + } + + DB::commit(); + + return $this->resourceResponse(new SegmentConstantResource($segment_constant_query)); + + } catch (\Exception $exception) { + throw new ErrorException($exception->getMessage(), $exception->getCode()); + } + + } +} \ No newline at end of file diff --git a/app/Classes/Modules/SegmentConstants/ControllerLogic/ListStandardSegmentConstantLogic.php b/app/Classes/Modules/SegmentConstants/ControllerLogic/ListStandardSegmentConstantLogic.php new file mode 100644 index 00000000..3ce065c1 --- /dev/null +++ b/app/Classes/Modules/SegmentConstants/ControllerLogic/ListStandardSegmentConstantLogic.php @@ -0,0 +1,69 @@ + 'Retrieved Standard Segment Constant', + 'message' => 'You have successfully retrieved a list of Standard Segment Constant' + ]; + } + + /** @var CanListStandardSegmentConstants */ + private $canListStandardSegmentConstants; + + /** @var ListsSegmentConstants */ + private $listsSegmentConstants; + + /** + * ListStandardSegmentConstantLogic constructor. + * @param CanListStandardSegmentConstants $canListStandardSegmentConstants + * @param ListsSegmentConstants $listsSegmentConstants + */ + public function __construct(CanListStandardSegmentConstants $canListStandardSegmentConstants, ListsSegmentConstants $listsSegmentConstants) + { + $this->canListStandardSegmentConstants = $canListStandardSegmentConstants; + $this->listsSegmentConstants = $listsSegmentConstants; + } + + + /** + * @param Request $request + * @return JsonResponse + * @throws ErrorException + */ + public function logic(Request $request) : JsonResponse + { + try { + $this->canListStandardSegmentConstants->passes(); + + $query = $this->listsSegmentConstants->execute( + [ + 'segment_id' => 1 + ] + ); + + return $this->collectionResponse(SegmentResource::collection($query)); + + } catch (\Exception $exception){ + throw new ErrorException($exception->getMessage(), $exception->getCode()); + } + + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/SegmentConstants/ControllerLogic/UpdateSegmentConstantLogic.php b/app/Classes/Modules/SegmentConstants/ControllerLogic/UpdateSegmentConstantLogic.php new file mode 100644 index 00000000..c4ecf270 --- /dev/null +++ b/app/Classes/Modules/SegmentConstants/ControllerLogic/UpdateSegmentConstantLogic.php @@ -0,0 +1,175 @@ + 'Updated Segment Constant', + 'message' => 'You have successfully updated the Segment Constant' + ]; + } + + /** @var CanUpdateStandardSegmentConstant */ + private $canUpdateStandardSegmentConstant; + + /** @var UpdatesSegmentConstantTax */ + private $updatesSegmentConstantTax; + + /** @var UpdatesSegmentConstantBillingFee */ + private $updatesSegmentConstantBillingFee; + + /** @var UpdatesSegmentConstantServiceCharge */ + private $updatesSegmentConstantServiceCharge; + + /** @var UpdatesSegmentConstantBookingAmountMax */ + private $updatesSegmentConstantBookingAmountMax; + + /** @var UpdatesSegmentConstantPaymentAttemptExpiryTime */ + private $updatesSegmentConstantPaymentAttemptExpiryTime; + + /** @var FetchesSegmentConstant */ + private $fetchesSegmentConstant; + + /** + * UpdateStandardSegmentConstantLogic constructor. + * @param CanUpdateStandardSegmentConstant $canUpdateStandardSegmentConstant + * @param UpdatesSegmentConstantTax $updatesSegmentConstantTax + * @param UpdatesSegmentConstantBillingFee $updatesSegmentConstantBillingFee + * @param UpdatesSegmentConstantServiceCharge $updatesSegmentConstantServiceCharge + * @param UpdatesSegmentConstantBookingAmountMax $updatesSegmentConstantBookingAmountMax + * @param UpdatesSegmentConstantPaymentAttemptExpiryTime $updatesSegmentConstantPaymentAttemptExpiryTime + * @param FetchesSegmentConstant $fetchesSegmentConstant + */ + public function __construct( + CanUpdateStandardSegmentConstant $canUpdateStandardSegmentConstant, + UpdatesSegmentConstantTax $updatesSegmentConstantTax, + UpdatesSegmentConstantBillingFee $updatesSegmentConstantBillingFee, + UpdatesSegmentConstantServiceCharge $updatesSegmentConstantServiceCharge, + UpdatesSegmentConstantBookingAmountMax $updatesSegmentConstantBookingAmountMax, + UpdatesSegmentConstantPaymentAttemptExpiryTime $updatesSegmentConstantPaymentAttemptExpiryTime, + FetchesSegmentConstant $fetchesSegmentConstant + ) + { + $this->canUpdateStandardSegmentConstant = $canUpdateStandardSegmentConstant; + $this->updatesSegmentConstantTax = $updatesSegmentConstantTax; + $this->updatesSegmentConstantBillingFee = $updatesSegmentConstantBillingFee; + $this->updatesSegmentConstantServiceCharge = $updatesSegmentConstantServiceCharge; + $this->updatesSegmentConstantBookingAmountMax = $updatesSegmentConstantBookingAmountMax; + $this->updatesSegmentConstantPaymentAttemptExpiryTime = $updatesSegmentConstantPaymentAttemptExpiryTime; + $this->fetchesSegmentConstant = $fetchesSegmentConstant; + } + + /** + * @param Request $request + * @return JsonResponse + * @throws ErrorException + */ + public function logic(Request $request) : JsonResponse + { + try { + DB::beginTransaction(); + + $segment_constant_query = $this->fetchesSegmentConstant->execute(['id' => $request->route('id')]); + + if ($segment_constant_query->reference == 'TAX') { + $segment_constant_object = new SegmentConstantTaxObject( + $segment_constant_query->segment_id, + $segment_constant_query->name, + $segment_constant_query->reference, + $segment_constant_query->detail->type, + $request->input('value') + ); + + $this->canUpdateStandardSegmentConstant->passes($segment_constant_object); + $segment_constant_query = $this->updatesSegmentConstantTax->execute($segment_constant_query, $segment_constant_object); + } + elseif ($segment_constant_query->reference == 'BILLING_FEE') { + $segment_constant_object = new SegmentConstantBillingFeeObject( + $segment_constant_query->segment_id, + $segment_constant_query->name, + $segment_constant_query->reference, + $segment_constant_query->detail->type, + $request->input('value') + ); + $this->canUpdateStandardSegmentConstant->passes($segment_constant_object); + $segment_constant_query = $this->updatesSegmentConstantBillingFee->execute($segment_constant_query, $segment_constant_object); + } + elseif ($segment_constant_query->reference == 'SERVICE_CHARGE') { + $segment_constant_object = new SegmentConstantServiceChargeObject( + $segment_constant_query->segment_id, + $segment_constant_query->name, + $segment_constant_query->reference, + $segment_constant_query->detail->type, + $request->input('value') + ); + $this->canUpdateStandardSegmentConstant->passes($segment_constant_object); + $segment_constant_query = $this->updatesSegmentConstantServiceCharge->execute($segment_constant_query, $segment_constant_object); + } + elseif ($segment_constant_query->reference == 'BOOKING_AMOUNT_MAX') { + $segment_constant_object = new SegmentConstantBookingAmountMaxObject( + $segment_constant_query->segment_id, + $segment_constant_query->name, + $segment_constant_query->reference, + $segment_constant_query->detail->type, + $request->input('value'), + $segment_constant_query->detail->currency_id + ); + $this->canUpdateStandardSegmentConstant->passes($segment_constant_object); + $segment_constant_query = $this->updatesSegmentConstantBookingAmountMax->execute($segment_constant_query, $segment_constant_object); + } + elseif ($segment_constant_query->reference == 'PAYMENT_ATTEMP_EXPIRY_TIME') { + $segment_constant_object = new SegmentConstantPaymentAttemptExpiryTimeObject( + $segment_constant_query->segment_id, + $segment_constant_query->name, + $segment_constant_query->reference, + $segment_constant_query->detail->type, + $request->input('value') + ); + $this->canUpdateStandardSegmentConstant->passes($segment_constant_object); + $segment_constant_query = $this->updatesSegmentConstantPaymentAttemptExpiryTime->execute($segment_constant_query, $segment_constant_object); + } + + DB::commit(); + + return $this->resourceResponse(new SegmentConstantResource($segment_constant_query)); + + } catch (\Exception $exception){ + throw new ErrorException($exception->getMessage(), $exception->getCode()); + } + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/SegmentConstants/ControllerLogic/UpdateStandardSegmentConstantLogic.php b/app/Classes/Modules/SegmentConstants/ControllerLogic/UpdateStandardSegmentConstantLogic.php new file mode 100644 index 00000000..bdb42ff5 --- /dev/null +++ b/app/Classes/Modules/SegmentConstants/ControllerLogic/UpdateStandardSegmentConstantLogic.php @@ -0,0 +1,175 @@ + 'Updated Standard Segment Constant', + 'message' => 'You have successfully updated the Standard Segment Constant' + ]; + } + + /** @var CanUpdateStandardSegmentConstant */ + private $canUpdateStandardSegmentConstant; + + /** @var UpdatesSegmentConstantTax */ + private $updatesSegmentConstantTax; + + /** @var UpdatesSegmentConstantBillingFee */ + private $updatesSegmentConstantBillingFee; + + /** @var UpdatesSegmentConstantServiceCharge */ + private $updatesSegmentConstantServiceCharge; + + /** @var UpdatesSegmentConstantBookingAmountMax */ + private $updatesSegmentConstantBookingAmountMax; + + /** @var UpdatesSegmentConstantPaymentAttemptExpiryTime */ + private $updatesSegmentConstantPaymentAttemptExpiryTime; + + /** @var FetchesSegmentConstant */ + private $fetchesSegmentConstant; + + /** + * UpdateStandardSegmentConstantLogic constructor. + * @param CanUpdateStandardSegmentConstant $canUpdateStandardSegmentConstant + * @param UpdatesSegmentConstantTax $updatesSegmentConstantTax + * @param UpdatesSegmentConstantBillingFee $updatesSegmentConstantBillingFee + * @param UpdatesSegmentConstantServiceCharge $updatesSegmentConstantServiceCharge + * @param UpdatesSegmentConstantBookingAmountMax $updatesSegmentConstantBookingAmountMax + * @param UpdatesSegmentConstantPaymentAttemptExpiryTime $updatesSegmentConstantPaymentAttemptExpiryTime + * @param FetchesSegmentConstant $fetchesSegmentConstant + */ + public function __construct( + CanUpdateStandardSegmentConstant $canUpdateStandardSegmentConstant, + UpdatesSegmentConstantTax $updatesSegmentConstantTax, + UpdatesSegmentConstantBillingFee $updatesSegmentConstantBillingFee, + UpdatesSegmentConstantServiceCharge $updatesSegmentConstantServiceCharge, + UpdatesSegmentConstantBookingAmountMax $updatesSegmentConstantBookingAmountMax, + UpdatesSegmentConstantPaymentAttemptExpiryTime $updatesSegmentConstantPaymentAttemptExpiryTime, + FetchesSegmentConstant $fetchesSegmentConstant + ) + { + $this->canUpdateStandardSegmentConstant = $canUpdateStandardSegmentConstant; + $this->updatesSegmentConstantTax = $updatesSegmentConstantTax; + $this->updatesSegmentConstantBillingFee = $updatesSegmentConstantBillingFee; + $this->updatesSegmentConstantServiceCharge = $updatesSegmentConstantServiceCharge; + $this->updatesSegmentConstantBookingAmountMax = $updatesSegmentConstantBookingAmountMax; + $this->updatesSegmentConstantPaymentAttemptExpiryTime = $updatesSegmentConstantPaymentAttemptExpiryTime; + $this->fetchesSegmentConstant = $fetchesSegmentConstant; + } + + /** + * @param Request $request + * @return JsonResponse + * @throws ErrorException + */ + public function logic(Request $request) : JsonResponse + { + try { + DB::beginTransaction(); + + $segment_constant_query = $this->fetchesSegmentConstant->execute(['id' => $request->route('id')]); + + if ($segment_constant_query->reference == 'TAX') { + $segment_constant_object = new SegmentConstantTaxObject( + $segment_constant_query->segment_id, + $segment_constant_query->name, + $segment_constant_query->reference, + $segment_constant_query->detail->type, + $request->input('value') + ); + + $this->canUpdateStandardSegmentConstant->passes($segment_constant_object); + $segment_constant_query = $this->updatesSegmentConstantTax->execute($segment_constant_query, $segment_constant_object); + } + elseif ($segment_constant_query->reference == 'BILLING_FEE') { + $segment_constant_object = new SegmentConstantBillingFeeObject( + $segment_constant_query->segment_id, + $segment_constant_query->name, + $segment_constant_query->reference, + $segment_constant_query->detail->type, + $request->input('value') + ); + $this->canUpdateStandardSegmentConstant->passes($segment_constant_object); + $segment_constant_query = $this->updatesSegmentConstantBillingFee->execute($segment_constant_query, $segment_constant_object); + } + elseif ($segment_constant_query->reference == 'SERVICE_CHARGE') { + $segment_constant_object = new SegmentConstantServiceChargeObject( + $segment_constant_query->segment_id, + $segment_constant_query->name, + $segment_constant_query->reference, + $segment_constant_query->detail->type, + $request->input('value') + ); + $this->canUpdateStandardSegmentConstant->passes($segment_constant_object); + $segment_constant_query = $this->updatesSegmentConstantServiceCharge->execute($segment_constant_query, $segment_constant_object); + } + elseif ($segment_constant_query->reference == 'BOOKING_AMOUNT_MAX') { + $segment_constant_object = new SegmentConstantBookingAmountMaxObject( + $segment_constant_query->segment_id, + $segment_constant_query->name, + $segment_constant_query->reference, + $segment_constant_query->detail->type, + $request->input('value'), + $segment_constant_query->detail->currency_id + ); + $this->canUpdateStandardSegmentConstant->passes($segment_constant_object); + $segment_constant_query = $this->updatesSegmentConstantBookingAmountMax->execute($segment_constant_query, $segment_constant_object); + } + elseif ($segment_constant_query->reference == 'PAYMENT_ATTEMP_EXPIRY_TIME') { + $segment_constant_object = new SegmentConstantPaymentAttemptExpiryTimeObject( + $segment_constant_query->segment_id, + $segment_constant_query->name, + $segment_constant_query->reference, + $segment_constant_query->detail->type, + $request->input('value') + ); + $this->canUpdateStandardSegmentConstant->passes($segment_constant_object); + $segment_constant_query = $this->updatesSegmentConstantPaymentAttemptExpiryTime->execute($segment_constant_query, $segment_constant_object); + } + + DB::commit(); + + return $this->resourceResponse(new SegmentConstantResource($segment_constant_query)); + + } catch (\Exception $exception){ + throw new ErrorException($exception->getMessage(), $exception->getCode()); + } + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/SegmentConstants/DataTransferObjects/SegmentConstantBillingFeeObject.php b/app/Classes/Modules/SegmentConstants/DataTransferObjects/SegmentConstantBillingFeeObject.php new file mode 100644 index 00000000..2cac6d93 --- /dev/null +++ b/app/Classes/Modules/SegmentConstants/DataTransferObjects/SegmentConstantBillingFeeObject.php @@ -0,0 +1,86 @@ +segment_id = $segment_id; + $this->name = $name; + $this->reference = $reference; + $this->type = $type; + $this->value = $value; + } + + /** + * @return int + */ + public function getSegmentId(): ?int + { + return $this->segment_id; + } + + /** + * @return string + */ + public function getName(): ?string + { + return $this->name; + } + + /** + * @return string + */ + public function getReference(): ?string + { + return $this->reference; + } + + /** + * @return string + */ + public function getType(): ?string + { + return $this->type; + } + + /** + * @return int + */ + public function getValue(): ?int + { + return $this->value; + } +} \ No newline at end of file diff --git a/app/Classes/Modules/SegmentConstants/DataTransferObjects/SegmentConstantBookingAmountMaxObject.php b/app/Classes/Modules/SegmentConstants/DataTransferObjects/SegmentConstantBookingAmountMaxObject.php new file mode 100644 index 00000000..709cdb18 --- /dev/null +++ b/app/Classes/Modules/SegmentConstants/DataTransferObjects/SegmentConstantBookingAmountMaxObject.php @@ -0,0 +1,100 @@ +segment_id = $segment_id; + $this->name = $name; + $this->reference = $reference; + $this->type = $type; + $this->value = $value; + $this->currency_id = $currency_id; + } + + /** + * @return int + */ + public function getSegmentId(): ?int + { + return $this->segment_id; + } + + /** + * @return string + */ + public function getName(): ?string + { + return $this->name; + } + + /** + * @return string + */ + public function getReference(): ?string + { + return $this->reference; + } + + /** + * @return string + */ + public function getType(): ?string + { + return $this->type; + } + + /** + * @return int + */ + public function getValue(): ?int + { + return $this->value; + } + + /** + * @return int + */ + public function getCurrencyId(): ?int + { + return $this->currency_id; + } +} \ No newline at end of file diff --git a/app/Classes/Modules/SegmentConstants/DataTransferObjects/SegmentConstantPaymentAttemptExpiryTimeObject.php b/app/Classes/Modules/SegmentConstants/DataTransferObjects/SegmentConstantPaymentAttemptExpiryTimeObject.php new file mode 100644 index 00000000..7b97584f --- /dev/null +++ b/app/Classes/Modules/SegmentConstants/DataTransferObjects/SegmentConstantPaymentAttemptExpiryTimeObject.php @@ -0,0 +1,86 @@ +segment_id = $segment_id; + $this->name = $name; + $this->reference = $reference; + $this->type = $type; + $this->value = $value; + } + + /** + * @return int + */ + public function getSegmentId(): ?int + { + return $this->segment_id; + } + + /** + * @return string + */ + public function getName(): ?string + { + return $this->name; + } + + /** + * @return string + */ + public function getReference(): ?string + { + return $this->reference; + } + + /** + * @return string + */ + public function getType(): ?string + { + return $this->type; + } + + /** + * @return int + */ + public function getValue(): ?int + { + return $this->value; + } +} \ No newline at end of file diff --git a/app/Classes/Modules/SegmentConstants/DataTransferObjects/SegmentConstantServiceChargeObject.php b/app/Classes/Modules/SegmentConstants/DataTransferObjects/SegmentConstantServiceChargeObject.php new file mode 100644 index 00000000..4f3adfa1 --- /dev/null +++ b/app/Classes/Modules/SegmentConstants/DataTransferObjects/SegmentConstantServiceChargeObject.php @@ -0,0 +1,86 @@ +segment_id = $segment_id; + $this->name = $name; + $this->reference = $reference; + $this->type = $type; + $this->value = $value; + } + + /** + * @return int + */ + public function getSegmentId(): ?int + { + return $this->segment_id; + } + + /** + * @return string + */ + public function getName(): ?string + { + return $this->name; + } + + /** + * @return string + */ + public function getReference(): ?string + { + return $this->reference; + } + + /** + * @return string + */ + public function getType(): ?string + { + return $this->type; + } + + /** + * @return int + */ + public function getValue(): ?int + { + return $this->value; + } +} \ No newline at end of file diff --git a/app/Classes/Modules/SegmentConstants/DataTransferObjects/SegmentConstantTaxObject.php b/app/Classes/Modules/SegmentConstants/DataTransferObjects/SegmentConstantTaxObject.php new file mode 100644 index 00000000..b7125cd1 --- /dev/null +++ b/app/Classes/Modules/SegmentConstants/DataTransferObjects/SegmentConstantTaxObject.php @@ -0,0 +1,86 @@ +segment_id = $segment_id; + $this->name = $name; + $this->reference = $reference; + $this->type = $type; + $this->value = $value; + } + + /** + * @return int + */ + public function getSegmentId(): ?int + { + return $this->segment_id; + } + + /** + * @return string + */ + public function getName(): ?string + { + return $this->name; + } + + /** + * @return string + */ + public function getReference(): ?string + { + return $this->reference; + } + + /** + * @return string + */ + public function getType(): ?string + { + return $this->type; + } + + /** + * @return int + */ + public function getValue(): ?int + { + return $this->value; + } +} \ No newline at end of file diff --git a/app/Classes/Modules/SegmentConstants/Services/CreatesSegmentConstantBillingFee.php b/app/Classes/Modules/SegmentConstants/Services/CreatesSegmentConstantBillingFee.php new file mode 100644 index 00000000..55133247 --- /dev/null +++ b/app/Classes/Modules/SegmentConstants/Services/CreatesSegmentConstantBillingFee.php @@ -0,0 +1,30 @@ +segment_id = $segment->id; + $model->name = $object->getName(); + $model->reference = $object->getReference(); + $model->detail = json_encode([ + 'type' => $object->getType(), + 'value' => $object->getValue() + ]); + + return $this->handler($model); + } +} \ No newline at end of file diff --git a/app/Classes/Modules/SegmentConstants/Services/CreatesSegmentConstantBookingAmountMax.php b/app/Classes/Modules/SegmentConstants/Services/CreatesSegmentConstantBookingAmountMax.php new file mode 100644 index 00000000..61971f50 --- /dev/null +++ b/app/Classes/Modules/SegmentConstants/Services/CreatesSegmentConstantBookingAmountMax.php @@ -0,0 +1,31 @@ +segment_id = $segment->id; + $model->name = $object->getName(); + $model->reference = $object->getReference(); + $model->detail = json_encode([ + 'type' => $object->getType(), + 'value' => $object->getValue(), + 'currency_id' => $object->getCurrencyId() + ]); + + return $this->handler($model); + } +} \ No newline at end of file diff --git a/app/Classes/Modules/SegmentConstants/Services/CreatesSegmentConstantPaymentAttemptExpiryTime.php b/app/Classes/Modules/SegmentConstants/Services/CreatesSegmentConstantPaymentAttemptExpiryTime.php new file mode 100644 index 00000000..ae6077b8 --- /dev/null +++ b/app/Classes/Modules/SegmentConstants/Services/CreatesSegmentConstantPaymentAttemptExpiryTime.php @@ -0,0 +1,30 @@ +segment_id = $object->getSegmentId(); + $model->name = $object->getName(); + $model->reference = $object->getReference(); + $model->detail = json_encode([ + 'type' => $object->getType(), + 'value' => $object->getValue(), + ]); + + return $this->handler($model); + } +} \ No newline at end of file diff --git a/app/Classes/Modules/SegmentConstants/Services/CreatesSegmentConstantServiceCharge.php b/app/Classes/Modules/SegmentConstants/Services/CreatesSegmentConstantServiceCharge.php new file mode 100644 index 00000000..695b7df9 --- /dev/null +++ b/app/Classes/Modules/SegmentConstants/Services/CreatesSegmentConstantServiceCharge.php @@ -0,0 +1,30 @@ +segment_id = $object->getSegmentId(); + $model->name = $object->getName(); + $model->reference = $object->getReference(); + $model->detail = json_encode([ + 'type' => $object->getType(), + 'value' => $object->getValue() + ]); + + return $this->handler($model); + } +} \ No newline at end of file diff --git a/app/Classes/Modules/SegmentConstants/Services/CreatesSegmentConstantTax.php b/app/Classes/Modules/SegmentConstants/Services/CreatesSegmentConstantTax.php new file mode 100644 index 00000000..64b2e7a5 --- /dev/null +++ b/app/Classes/Modules/SegmentConstants/Services/CreatesSegmentConstantTax.php @@ -0,0 +1,30 @@ +segment_id = $object->getSegmentId(); + $model->name = $object->getName(); + $model->reference = $object->getReference(); + $model->detail = json_encode([ + 'type' => $object->getType(), + 'value' => $object->getValue() + ]); + + return $this->handler($model); + } +} \ No newline at end of file diff --git a/app/Classes/Modules/SegmentConstants/Services/FetchesSegmentConstant.php b/app/Classes/Modules/SegmentConstants/Services/FetchesSegmentConstant.php new file mode 100644 index 00000000..003e20ba --- /dev/null +++ b/app/Classes/Modules/SegmentConstants/Services/FetchesSegmentConstant.php @@ -0,0 +1,33 @@ +repository = $repository; + } + + + /** + * @return Builder + */ + public function getRepository(): Builder + { + return $this->repository->newQuery(); + } +} \ No newline at end of file diff --git a/app/Classes/Modules/SegmentConstants/Services/ListsSegmentConstants.php b/app/Classes/Modules/SegmentConstants/Services/ListsSegmentConstants.php new file mode 100644 index 00000000..5f959f98 --- /dev/null +++ b/app/Classes/Modules/SegmentConstants/Services/ListsSegmentConstants.php @@ -0,0 +1,33 @@ +repository = $repository; + } + + + /** + * @return Builder + */ + function getRepository(): Builder + { + return $this->repository->newQuery(); + } +} \ No newline at end of file diff --git a/app/Classes/Modules/SegmentConstants/Services/UpdatesSegmentConstantBillingFee.php b/app/Classes/Modules/SegmentConstants/Services/UpdatesSegmentConstantBillingFee.php new file mode 100644 index 00000000..573d287b --- /dev/null +++ b/app/Classes/Modules/SegmentConstants/Services/UpdatesSegmentConstantBillingFee.php @@ -0,0 +1,28 @@ +name = $object->getName(); + $model->reference = $object->getReference(); + $model->detail = json_encode([ + 'type' => $object->getType(), + 'value' => $object->getValue() + ]); + + return $this->handler($model); + } +} \ No newline at end of file diff --git a/app/Classes/Modules/SegmentConstants/Services/UpdatesSegmentConstantBookingAmountMax.php b/app/Classes/Modules/SegmentConstants/Services/UpdatesSegmentConstantBookingAmountMax.php new file mode 100644 index 00000000..8885a701 --- /dev/null +++ b/app/Classes/Modules/SegmentConstants/Services/UpdatesSegmentConstantBookingAmountMax.php @@ -0,0 +1,29 @@ +name = $object->getName(); + $model->reference = $object->getReference(); + $model->detail = json_encode([ + 'type' => $object->getType(), + 'value' => $object->getValue(), + 'currency_id' => $object->getCurrencyId(), + ]); + + return $this->handler($model); + } +} \ No newline at end of file diff --git a/app/Classes/Modules/SegmentConstants/Services/UpdatesSegmentConstantPaymentAttemptExpiryTime.php b/app/Classes/Modules/SegmentConstants/Services/UpdatesSegmentConstantPaymentAttemptExpiryTime.php new file mode 100644 index 00000000..5acdd9e9 --- /dev/null +++ b/app/Classes/Modules/SegmentConstants/Services/UpdatesSegmentConstantPaymentAttemptExpiryTime.php @@ -0,0 +1,28 @@ +name = $object->getName(); + $model->reference = $object->getReference(); + $model->detail = json_encode([ + 'type' => $object->getType(), + 'value' => $object->getValue() + ]); + + return $this->handler($model); + } +} \ No newline at end of file diff --git a/app/Classes/Modules/SegmentConstants/Services/UpdatesSegmentConstantServiceCharge.php b/app/Classes/Modules/SegmentConstants/Services/UpdatesSegmentConstantServiceCharge.php new file mode 100644 index 00000000..afa201f5 --- /dev/null +++ b/app/Classes/Modules/SegmentConstants/Services/UpdatesSegmentConstantServiceCharge.php @@ -0,0 +1,28 @@ +name = $object->getName(); + $model->reference = $object->getReference(); + $model->detail = json_encode([ + 'type' => $object->getType(), + 'value' => $object->getValue() + ]); + + return $this->handler($model); + } +} \ No newline at end of file diff --git a/app/Classes/Modules/SegmentConstants/Services/UpdatesSegmentConstantTax.php b/app/Classes/Modules/SegmentConstants/Services/UpdatesSegmentConstantTax.php new file mode 100644 index 00000000..2b02e9f9 --- /dev/null +++ b/app/Classes/Modules/SegmentConstants/Services/UpdatesSegmentConstantTax.php @@ -0,0 +1,28 @@ +name = $object->getName(); + $model->reference = $object->getReference(); + $model->detail = json_encode([ + 'type' => $object->getType(), + 'value' => $object->getValue() + ]); + + return $this->handler($model); + } +} \ No newline at end of file diff --git a/app/Classes/Modules/SegmentConstants/Standards/Rules/CanCreateSegmentConstant.php b/app/Classes/Modules/SegmentConstants/Standards/Rules/CanCreateSegmentConstant.php new file mode 100644 index 00000000..f8004575 --- /dev/null +++ b/app/Classes/Modules/SegmentConstants/Standards/Rules/CanCreateSegmentConstant.php @@ -0,0 +1,55 @@ +segmentConstantValidation = $segmentConstantValidation; + } + + /** + * @return bool + */ + protected function authorized(): bool + { + // TODO Set Authorization rules + if (!\Auth::user()->can('add segment_constant')) { + return false; + } + + return true; + } + + /** + * @param SegmentObject $object + * @return bool + * @throws \App\Classes\Exceptions\RequestValidationException + */ + protected function validators($object): bool + { + return $this->segmentConstantValidation->validate($object, 'POST'); + } + + /** + * @param SegmentObject $object + * @return bool + */ + protected function criteria($object): bool + { + return true; + } +} \ No newline at end of file diff --git a/app/Classes/Modules/SegmentConstants/Standards/Rules/CanListStandardSegmentConstants.php b/app/Classes/Modules/SegmentConstants/Standards/Rules/CanListStandardSegmentConstants.php new file mode 100644 index 00000000..094cdd48 --- /dev/null +++ b/app/Classes/Modules/SegmentConstants/Standards/Rules/CanListStandardSegmentConstants.php @@ -0,0 +1,45 @@ +can('view standard_segment_constant')) { + return false; + } + + return true; + + } + + /** + * @param SegmentObject $object + * @return bool + */ + protected function validators($object): bool + { + return true; + + } + + + /** + * @param SegmentObject $object + * @return bool + */ + protected function criteria($object): bool + { + return true; + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/SegmentConstants/Standards/Rules/CanUpdateStandardSegmentConstant.php b/app/Classes/Modules/SegmentConstants/Standards/Rules/CanUpdateStandardSegmentConstant.php new file mode 100644 index 00000000..daee97ba --- /dev/null +++ b/app/Classes/Modules/SegmentConstants/Standards/Rules/CanUpdateStandardSegmentConstant.php @@ -0,0 +1,58 @@ +segmentConstantValidation = $segmentConstantValidation; + } + + /** + * @return bool + */ + protected function authorized(): bool + { + // TODO Set Authorization rules + + if (!\Auth::user()->can('view standard_segment_constant')) { + return false; + } + + return true; + } + + /** + * @param SegmentConstantValidation $object + * @return bool + * @throws \App\Classes\Exceptions\RequestValidationException + */ + protected function validators($object): bool + { + return $this->segmentConstantValidation->validate($object, 'PUT'); + } + + /** + * @param SegmentConstantValidation $object + * @return bool + */ + protected function criteria($object): bool + { + return true; + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/SegmentConstants/Standards/Validators/SegmentConstantValidation.php b/app/Classes/Modules/SegmentConstants/Standards/Validators/SegmentConstantValidation.php new file mode 100644 index 00000000..9a09a074 --- /dev/null +++ b/app/Classes/Modules/SegmentConstants/Standards/Validators/SegmentConstantValidation.php @@ -0,0 +1,126 @@ +reference = $object->getReference(); + if ($this->reference == 'TAX') { + return [ + 'segment_id'=> $object->getSegmentId(), + 'name' => $object->getName(), + 'reference' => $object->getReference(), + 'type' => $object->getType(), + 'value' => $object->getValue() + ]; + } + elseif ($this->reference == 'BILLING_FEE') { + return [ + 'segment_id' => $object->getSegmentId(), + 'name' => $object->getName(), + 'reference' => $object->getReference(), + 'type' => $object->getType(), + 'value' => $object->getValue() + ]; + } + elseif ($this->reference == 'SERVICE_CHARGE') { + return [ + 'segment_id' => $object->getSegmentId(), + 'name' => $object->getName(), + 'reference' => $object->getReference(), + 'type' => $object->getType(), + 'value' => $object->getValue() + ]; + } + elseif ($this->reference == 'BOOKING_AMOUNT_MAX') { + return [ + 'segment_id' => $object->getSegmentId(), + 'name' => $object->getName(), + 'reference' => $object->getReference(), + 'type' => $object->getType(), + 'value' => $object->getValue(), + 'currency_id' => $object->getCurrencyId() + ]; + } + elseif ($this->reference == 'PAYMENT_ATTEMP_EXPIRY_TIME') { + return [ + 'segment_id' => $object->getSegmentId(), + 'name' => $object->getName(), + 'reference' => $object->getReference(), + 'type' => $object->getType(), + 'value' => $object->getValue() + ]; + } + } + + /** + * @return array + */ + protected function rules(?string $type = 'POST'): array { + + if ($this->reference == 'TAX') { + return [ + 'segment_id' => $type == 'POST' ? 'required' : '', + 'name' => 'required', + 'reference' => 'required', + 'type' => 'required', + 'value' => 'required' + ]; + } + elseif ($this->reference == 'BILLING_FEE') { + return [ + 'segment_id' => $type == 'POST' ? 'required' : '', + 'name' => 'required', + 'reference' => 'required', + 'type' => 'required', + 'value' => 'required' + ]; + } + elseif ($this->reference == 'SERVICE_CHARGE') { + return [ + 'segment_id' => $type == 'POST' ? 'required' : '', + 'name' => 'required', + 'reference' => 'required', + 'type' => 'required', + 'value' => 'required' + ]; + } + elseif ($this->reference == 'BOOKING_AMOUNT_MAX') { + return [ + 'segment_id' => $type == 'POST' ? 'required' : '', + 'name' => 'required', + 'reference' => 'required', + 'type' => 'required', + 'value' => 'required', + 'currency_id' => 'required' + ]; + } + elseif ($this->reference == 'PAYMENT_ATTEMP_EXPIRY_TIME') { + return [ + 'segment_id' => $type == 'POST' ? 'required' : '', + 'name' => 'required', + 'reference' => 'required', + 'type' => 'required', + 'value' => 'required', + ]; + } + } + + /** + * @return array + */ + protected function messages(): array { + return []; + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/Segments/ControllerLogic/CreateSegmentLogic.php b/app/Classes/Modules/Segments/ControllerLogic/CreateSegmentLogic.php new file mode 100644 index 00000000..557117c6 --- /dev/null +++ b/app/Classes/Modules/Segments/ControllerLogic/CreateSegmentLogic.php @@ -0,0 +1,75 @@ + 'Created Segment', + 'message' => 'You have successfully created a new Segment' + ]; + } + + /** @var CanCreateSegment */ + private $canCreateSegment; + + /** @var CreatesSegment */ + private $createsSegment; + + /** + * CreateSegmentLogic constructor. + * @param CanCreateSegment $canCreateSegment + * @param CreatesSegment $createsSegment + */ + public function __construct( + CanCreateSegment $canCreateSegment, + CreatesSegment $createsSegment + ) + { + $this->canCreateSegment = $canCreateSegment; + $this->createsSegment = $createsSegment; + } + + /** + * @param Request $request + * @return JsonResponse + * @throws ErrorException + */ + public function logic(Request $request) : JsonResponse + { + try { + DB::beginTransaction(); + + $segment_object = new SegmentObject( + $request->input('name') + ); + + $this->canCreateSegment->passes($segment_object); + $segment_query = $this->createsSegment->execute($segment_object); + + DB::commit(); + + return $this->resourceResponse(new SegmentResource($segment_query)); + + } catch (\Exception $exception) { + throw new ErrorException($exception->getMessage(), $exception->getCode()); + } + + } +} \ No newline at end of file diff --git a/app/Classes/Modules/Segments/ControllerLogic/DeleteSegmentLogic.php b/app/Classes/Modules/Segments/ControllerLogic/DeleteSegmentLogic.php new file mode 100644 index 00000000..24284c29 --- /dev/null +++ b/app/Classes/Modules/Segments/ControllerLogic/DeleteSegmentLogic.php @@ -0,0 +1,83 @@ + 'Delete Segment', + 'message' => 'You have successfully deleted the Segment' + ]; + } + + /** @var CanDeleteSegment */ + private $canDeleteSegment; + + /** @var DeletesSegment */ + private $deletesSegment; + + /** @var FetchesSegment */ + private $fetchesSegment; + + /** + * UpdateStandardSegmentConstantLogic constructor. + * @param CanUpdateSegment $canDeleteSegment + * @param UpdatesSegment $deletesSegment + * @param FetchesSegment $fetchesSegment + */ + public function __construct( + CanDeleteSegment $canDeleteSegment, + DeletesSegment $deletesSegment, + FetchesSegment $fetchesSegment + ) + { + $this->canDeleteSegment = $canDeleteSegment; + $this->deletesSegment = $deletesSegment; + $this->fetchesSegment = $fetchesSegment; + } + + /** + * @param Request $request + * @return JsonResponse + * @throws ErrorException + */ + public function logic(Request $request) : JsonResponse + { + try { + DB::beginTransaction(); + + $segment_query = $this->fetchesSegment->execute(['id' => $request->route('id')]); + $this->canDeleteSegment->passes(); + $this->deletesSegment->execute($segment_query); + + DB::commit(); + + return $this->resourceResponse(new SegmentResource($segment_query)); + + } catch (\Exception $exception){ + dd($exception); + throw new ErrorException($exception->getMessage(), $exception->getCode()); + } + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/Segments/ControllerLogic/ListStandardSegmentLogic.php b/app/Classes/Modules/Segments/ControllerLogic/ListStandardSegmentLogic.php new file mode 100644 index 00000000..6458962b --- /dev/null +++ b/app/Classes/Modules/Segments/ControllerLogic/ListStandardSegmentLogic.php @@ -0,0 +1,65 @@ + 'Retrieved Segment', + 'message' => 'You have successfully retrieved a list of Segment' + ]; + } + + /** @var CanListStandardSegments */ + private $canListStandardSegments; + + /** @var ListsSegments */ + private $listsSegments; + + /** + * ListStandardSegmentLogic constructor. + * @param CanListStandardSegments $canListStandardSegments + * @param ListsSegments $listsSegments + */ + public function __construct(CanListStandardSegments $canListStandardSegments, ListsSegments $listsSegments) + { + $this->canListStandardSegments = $canListStandardSegments; + $this->listsSegments = $listsSegments; + } + + + /** + * @param Request $request + * @return JsonResponse + * @throws ErrorException + */ + public function logic(Request $request) : JsonResponse + { + try { + $this->canListStandardSegments->passes(); + + $query = $this->listsSegments->execute(['id' => 1]); + + return $this->collectionResponse(SegmentResource::collection($query)); + + } catch (\Exception $exception){ + throw new ErrorException($exception->getMessage(), $exception->getCode()); + } + + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/Segments/ControllerLogic/UpdateSegmentLogic.php b/app/Classes/Modules/Segments/ControllerLogic/UpdateSegmentLogic.php new file mode 100644 index 00000000..8ce9038d --- /dev/null +++ b/app/Classes/Modules/Segments/ControllerLogic/UpdateSegmentLogic.php @@ -0,0 +1,86 @@ + 'Updated Segment', + 'message' => 'You have successfully updated the Segment' + ]; + } + + /** @var CanUpdateSegment */ + private $canUpdateSegment; + + /** @var UpdatesSegment */ + private $updatesSegment; + + /** @var FetchesSegment */ + private $fetchesSegment; + + /** + * UpdateStandardSegmentConstantLogic constructor. + * @param CanUpdateSegment $canUpdateSegment + * @param UpdatesSegment $updatesSegment + * @param FetchesSegment $fetchesSegment + */ + public function __construct( + CanUpdateSegment $canUpdateSegment, + UpdatesSegment $updatesSegment, + FetchesSegment $fetchesSegment + ) + { + $this->canUpdateSegment = $canUpdateSegment; + $this->updatesSegment = $updatesSegment; + $this->fetchesSegment = $fetchesSegment; + } + + /** + * @param Request $request + * @return JsonResponse + * @throws ErrorException + */ + public function logic(Request $request) : JsonResponse + { + try { + DB::beginTransaction(); + + $segment_query = $this->fetchesSegment->execute(['id' => $request->route('id')]); + + $segment_object = new SegmentObject( + $request->input('name', $segment_query->name) + ); + $this->canUpdateSegment->passes($segment_object); + $segment_query = $this->updatesSegment->execute($segment_query, $segment_object); + + DB::commit(); + + return $this->resourceResponse(new SegmentResource($segment_query)); + + } catch (\Exception $exception){ + throw new ErrorException($exception->getMessage(), $exception->getCode()); + } + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/Segments/DataTransferObjects/SegmentObject.php b/app/Classes/Modules/Segments/DataTransferObjects/SegmentObject.php new file mode 100644 index 00000000..dc4de3ed --- /dev/null +++ b/app/Classes/Modules/Segments/DataTransferObjects/SegmentObject.php @@ -0,0 +1,30 @@ +name = $name; + } + + /** + * @return string + */ + public function getName(): ?string + { + return $this->name; + } +} \ No newline at end of file diff --git a/app/Classes/Modules/Segments/Services/CreatesSegment.php b/app/Classes/Modules/Segments/Services/CreatesSegment.php new file mode 100644 index 00000000..f3dc2a1c --- /dev/null +++ b/app/Classes/Modules/Segments/Services/CreatesSegment.php @@ -0,0 +1,23 @@ +name = $object->getName(); + + return $this->handler($model); + + } +} \ No newline at end of file diff --git a/app/Classes/Modules/Segments/Services/DeletesSegment.php b/app/Classes/Modules/Segments/Services/DeletesSegment.php new file mode 100644 index 00000000..88d44d60 --- /dev/null +++ b/app/Classes/Modules/Segments/Services/DeletesSegment.php @@ -0,0 +1,14 @@ +handler($model); + } +} \ No newline at end of file diff --git a/app/Classes/Modules/Segments/Services/FetchesSegment.php b/app/Classes/Modules/Segments/Services/FetchesSegment.php new file mode 100644 index 00000000..25e5dbbe --- /dev/null +++ b/app/Classes/Modules/Segments/Services/FetchesSegment.php @@ -0,0 +1,33 @@ +repository = $repository; + } + + + /** + * @return Builder + */ + public function getRepository(): Builder + { + return $this->repository->newQuery(); + } +} \ No newline at end of file diff --git a/app/Classes/Modules/Segments/Services/ListsSegments.php b/app/Classes/Modules/Segments/Services/ListsSegments.php new file mode 100644 index 00000000..af44820d --- /dev/null +++ b/app/Classes/Modules/Segments/Services/ListsSegments.php @@ -0,0 +1,33 @@ +repository = $repository; + } + + + /** + * @return Builder + */ + function getRepository(): Builder + { + return $this->repository->newQuery(); + } +} \ No newline at end of file diff --git a/app/Classes/Modules/Segments/Services/UpdatesSegment.php b/app/Classes/Modules/Segments/Services/UpdatesSegment.php new file mode 100644 index 00000000..fed1fb2d --- /dev/null +++ b/app/Classes/Modules/Segments/Services/UpdatesSegment.php @@ -0,0 +1,22 @@ +name = $object->getName(); + return $this->handler($model); + } +} \ No newline at end of file diff --git a/app/Classes/Modules/Segments/Standards/Rules/CanCreateSegment.php b/app/Classes/Modules/Segments/Standards/Rules/CanCreateSegment.php new file mode 100644 index 00000000..50f7e81d --- /dev/null +++ b/app/Classes/Modules/Segments/Standards/Rules/CanCreateSegment.php @@ -0,0 +1,55 @@ +segmentValidation = $segmentValidation; + } + + /** + * @return bool + */ + protected function authorized(): bool + { + // TODO Set Authorization rules + if (!\Auth::user()->can('add segment')) { + return false; + } + + return true; + } + + /** + * @param SegmentObject $object + * @return bool + * @throws \App\Classes\Exceptions\RequestValidationException + */ + protected function validators($object): bool + { + return $this->segmentValidation->validate($object); + } + + /** + * @param SegmentObject $object + * @return bool + */ + protected function criteria($object): bool + { + return true; + } +} \ No newline at end of file diff --git a/app/Classes/Modules/Segments/Standards/Rules/CanDeleteSegments.php b/app/Classes/Modules/Segments/Standards/Rules/CanDeleteSegments.php new file mode 100644 index 00000000..197b0a5f --- /dev/null +++ b/app/Classes/Modules/Segments/Standards/Rules/CanDeleteSegments.php @@ -0,0 +1,45 @@ +can('delete segment')) { + return false; + } + + return true; + + } + + /** + * @param SegmentObject $object + * @return bool + */ + protected function validators($object): bool + { + return true; + + } + + + /** + * @param SegmentObject $object + * @return bool + */ + protected function criteria($object): bool + { + return true; + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/Segments/Standards/Rules/CanListStandardSegments.php b/app/Classes/Modules/Segments/Standards/Rules/CanListStandardSegments.php new file mode 100644 index 00000000..7f71182e --- /dev/null +++ b/app/Classes/Modules/Segments/Standards/Rules/CanListStandardSegments.php @@ -0,0 +1,45 @@ +can('view standard_segment')) { + return false; + } + + return true; + + } + + /** + * @param SegmentObject $object + * @return bool + */ + protected function validators($object): bool + { + return true; + + } + + + /** + * @param SegmentObject $object + * @return bool + */ + protected function criteria($object): bool + { + return true; + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/Segments/Standards/Rules/CanUpdateSegment.php b/app/Classes/Modules/Segments/Standards/Rules/CanUpdateSegment.php new file mode 100644 index 00000000..ed01004a --- /dev/null +++ b/app/Classes/Modules/Segments/Standards/Rules/CanUpdateSegment.php @@ -0,0 +1,58 @@ +segmentValidation = $segmentValidation; + } + + /** + * @return bool + */ + protected function authorized(): bool + { + // TODO Set Authorization rules + + if (!\Auth::user()->can('edit segment')) { + return false; + } + + return true; + } + + /** + * @param SegmentValidation $object + * @return bool + * @throws \App\Classes\Exceptions\RequestValidationException + */ + protected function validators($object): bool + { + return $this->segmentValidation->validate($object); + } + + /** + * @param SegmentValidation $object + * @return bool + */ + protected function criteria($object): bool + { + return true; + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/Segments/Standards/Validators/SegmentValidation.php b/app/Classes/Modules/Segments/Standards/Validators/SegmentValidation.php new file mode 100644 index 00000000..364a4c88 --- /dev/null +++ b/app/Classes/Modules/Segments/Standards/Validators/SegmentValidation.php @@ -0,0 +1,38 @@ + $object->getName(), + ]; + } + + /** + * @return array + */ + protected function rules(): array + { + return [ + 'name' => 'required', + ]; + } + + /** + * @return array + */ + protected function messages(): array + { + return []; + } +} \ No newline at end of file diff --git a/app/Classes/ValueObjects/Constants/ObjectStatus.php b/app/Classes/ValueObjects/Constants/ObjectStatus.php index 55191cd5..18dcaa58 100644 --- a/app/Classes/ValueObjects/Constants/ObjectStatus.php +++ b/app/Classes/ValueObjects/Constants/ObjectStatus.php @@ -3,5 +3,6 @@ namespace App\Classes\ValueObjects\Constants; final class ObjectStatus { + public const ACTIVE = 1; public const PENDING = 9; } diff --git a/app/Http/Controllers/Documents/ApproveDocumentController.php b/app/Http/Controllers/Documents/ApproveDocumentController.php new file mode 100644 index 00000000..964a3811 --- /dev/null +++ b/app/Http/Controllers/Documents/ApproveDocumentController.php @@ -0,0 +1,20 @@ +execute($request); + } + +} \ No newline at end of file diff --git a/app/Http/Controllers/Documents/ListDocumentsController.php b/app/Http/Controllers/Documents/ListDocumentsController.php new file mode 100644 index 00000000..a440737d --- /dev/null +++ b/app/Http/Controllers/Documents/ListDocumentsController.php @@ -0,0 +1,20 @@ +execute($request); + } + +} \ No newline at end of file diff --git a/app/Http/Controllers/SegmentConstants/CreateSegmentConstantController.php b/app/Http/Controllers/SegmentConstants/CreateSegmentConstantController.php new file mode 100644 index 00000000..7520e1d1 --- /dev/null +++ b/app/Http/Controllers/SegmentConstants/CreateSegmentConstantController.php @@ -0,0 +1,19 @@ +execute($request); + } +} \ No newline at end of file diff --git a/app/Http/Controllers/SegmentConstants/UpdateSegmentConstantController.php b/app/Http/Controllers/SegmentConstants/UpdateSegmentConstantController.php new file mode 100644 index 00000000..c34914dc --- /dev/null +++ b/app/Http/Controllers/SegmentConstants/UpdateSegmentConstantController.php @@ -0,0 +1,20 @@ +execute($request); + } + +} \ No newline at end of file diff --git a/app/Http/Controllers/Segments/CreateSegmentController.php b/app/Http/Controllers/Segments/CreateSegmentController.php new file mode 100644 index 00000000..2950bdc3 --- /dev/null +++ b/app/Http/Controllers/Segments/CreateSegmentController.php @@ -0,0 +1,19 @@ +execute($request); + } +} \ No newline at end of file diff --git a/app/Http/Controllers/Segments/DeleteSegmentController.php b/app/Http/Controllers/Segments/DeleteSegmentController.php new file mode 100644 index 00000000..adf0043b --- /dev/null +++ b/app/Http/Controllers/Segments/DeleteSegmentController.php @@ -0,0 +1,19 @@ +execute($request); + } +} \ No newline at end of file diff --git a/app/Http/Controllers/Segments/UpdateSegmentController.php b/app/Http/Controllers/Segments/UpdateSegmentController.php new file mode 100644 index 00000000..51dfe25e --- /dev/null +++ b/app/Http/Controllers/Segments/UpdateSegmentController.php @@ -0,0 +1,20 @@ +execute($request); + } + +} \ No newline at end of file diff --git a/app/Http/Controllers/StandardSegmentConstants/ListStandardSegmentConstantsController.php b/app/Http/Controllers/StandardSegmentConstants/ListStandardSegmentConstantsController.php new file mode 100644 index 00000000..b921540e --- /dev/null +++ b/app/Http/Controllers/StandardSegmentConstants/ListStandardSegmentConstantsController.php @@ -0,0 +1,20 @@ +execute($request); + } + +} \ No newline at end of file diff --git a/app/Http/Controllers/StandardSegmentConstants/UpdateStandardSegmentConstantController.php b/app/Http/Controllers/StandardSegmentConstants/UpdateStandardSegmentConstantController.php new file mode 100644 index 00000000..8c883031 --- /dev/null +++ b/app/Http/Controllers/StandardSegmentConstants/UpdateStandardSegmentConstantController.php @@ -0,0 +1,20 @@ +execute($request); + } + +} \ No newline at end of file diff --git a/app/Http/Controllers/StandardSegments/ListStandardSegmentsController.php b/app/Http/Controllers/StandardSegments/ListStandardSegmentsController.php new file mode 100644 index 00000000..0218ac37 --- /dev/null +++ b/app/Http/Controllers/StandardSegments/ListStandardSegmentsController.php @@ -0,0 +1,20 @@ +execute($request); + } + +} \ No newline at end of file diff --git a/app/Http/Resources/DocumentResource.php b/app/Http/Resources/DocumentResource.php new file mode 100644 index 00000000..51aef2e7 --- /dev/null +++ b/app/Http/Resources/DocumentResource.php @@ -0,0 +1,26 @@ + $this->id, + 'document_type' => $this->document_type, + 'reference' => $this->reference, + 'status' => (int) $this->status, + 'approved_by' => (int) $this->approved_by, + 'files' => $this->files()->get() + ]; + } +} diff --git a/app/Http/Resources/SegmentConstantResource.php b/app/Http/Resources/SegmentConstantResource.php new file mode 100644 index 00000000..aa939d8e --- /dev/null +++ b/app/Http/Resources/SegmentConstantResource.php @@ -0,0 +1,23 @@ + $this->id, + 'name' => $this->name, + 'detail' => $this->detail + ]; + } +} diff --git a/app/Http/Resources/SegmentResource.php b/app/Http/Resources/SegmentResource.php new file mode 100644 index 00000000..f07e9661 --- /dev/null +++ b/app/Http/Resources/SegmentResource.php @@ -0,0 +1,22 @@ + $this->id, + 'name' => $this->name, + ]; + } +} diff --git a/app/Models/Company.php b/app/Models/Company.php index 7d2f785e..f791ddeb 100644 --- a/app/Models/Company.php +++ b/app/Models/Company.php @@ -1,6 +1,7 @@ belongsToMany(Segment::class, 'segment_company', 'company_id', 'segment_id'); + } } diff --git a/app/Models/Document.php b/app/Models/Document.php index 6c48c2c8..05899fdf 100644 --- a/app/Models/Document.php +++ b/app/Models/Document.php @@ -5,6 +5,8 @@ namespace App\Models; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\SoftDeletes; +use Illuminate\Database\Eloquent\Relations\hasMany; + /** * Class Document * @package App\Models @@ -22,5 +24,18 @@ use Illuminate\Database\Eloquent\SoftDeletes; */ class Document extends AbstractModel { - // + use SoftDeletes; + + protected $table = 'documents'; + + protected $dates = ['deleted_at']; + + /** + * @return hasMany + */ + public function files(): hasMany + { + return $this->hasMany(File::class, 'document_id'); + } + } diff --git a/app/Models/File.php b/app/Models/File.php index e22d3a4d..8c175039 100644 --- a/app/Models/File.php +++ b/app/Models/File.php @@ -21,4 +21,9 @@ class File extends AbstractModel protected $table = 'files'; protected $dates = ['deleted_at']; + + public function getFileAttribute($value) + { + return $value ? json_decode($value) : []; + } } diff --git a/app/Models/Permission.php b/app/Models/Permission.php new file mode 100644 index 00000000..9245cdd8 --- /dev/null +++ b/app/Models/Permission.php @@ -0,0 +1,9 @@ +hasMany(PasswordReset::class, 'user_id', 'id'); } - // public function employers(): belongsToMany { - // return $this->belongsToMany(CompanyModule::class, (new CompanyEmployee())->getTable(), 'user_id', 'module_id'); - // } - - // public function tweets(): hasMany { - // return $this->hasMany(Order::class, 'user_id', 'id'); - // } - - /** * @return belongsToMany */ diff --git a/database/migrations/2020_11_03_122319_create_documents_table.php b/database/migrations/2020_11_03_122319_create_documents_table.php index e81aefb7..dbe9c684 100644 --- a/database/migrations/2020_11_03_122319_create_documents_table.php +++ b/database/migrations/2020_11_03_122319_create_documents_table.php @@ -20,8 +20,8 @@ class CreateDocumentsTable extends Migration $table->string('document_type')->nullable(); $table->string('reference')->nullable(); $table->integer('status')->nullable(); - $table->bigInteger('approved_by')->unsigned(); - $table->foreign('approved_by')->references('id')->on('users')->onDelete('cascade')->nullable(); + $table->bigInteger('approved_by')->unsigned()->nullable(); + $table->foreign('approved_by')->references('id')->on('users')->onDelete('cascade'); $table->timestamp('issued_date')->nullable(); $table->timestamp('expired_date')->nullable(); $table->timestamp('approved_date')->nullable(); diff --git a/database/migrations/2020_11_11_065757_create_segments_table.php b/database/migrations/2020_11_11_065757_create_segments_table.php new file mode 100644 index 00000000..4bfa3f05 --- /dev/null +++ b/database/migrations/2020_11_11_065757_create_segments_table.php @@ -0,0 +1,33 @@ +id(); + $table->string('name')->nullable(); + $table->timestamps(); + $table->softDeletes(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('segments'); + } +} diff --git a/database/migrations/2020_11_11_065838_create_segment_constants_table.php b/database/migrations/2020_11_11_065838_create_segment_constants_table.php new file mode 100644 index 00000000..a64fef62 --- /dev/null +++ b/database/migrations/2020_11_11_065838_create_segment_constants_table.php @@ -0,0 +1,38 @@ +id(); + $table->bigInteger('segment_id')->unsigned()->nullable(); + $table->foreign('segment_id')->references('id')->on('segments')->onDelete('cascade'); + $table->string('name')->nullable(); + $table->string('reference')->nullable(); + $table->text('detail')->nullable(); + $table->timestamps(); + $table->integer('type')->nullable(); + $table->softDeletes(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('segment_constants'); + } +} diff --git a/database/migrations/2020_11_11_065851_create_segment_companies_table.php b/database/migrations/2020_11_11_065851_create_segment_companies_table.php new file mode 100644 index 00000000..f2a55572 --- /dev/null +++ b/database/migrations/2020_11_11_065851_create_segment_companies_table.php @@ -0,0 +1,34 @@ +bigInteger('segment_id')->unsigned(); + $table->foreign('segment_id')->references('id')->on('segments')->onDelete('cascade'); + $table->bigInteger('company_id')->unsigned(); + $table->foreign('company_id')->references('id')->on('companies')->onDelete('cascade'); + $table->primary(['segment_id', 'company_id']); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('segment_company'); + } +} diff --git a/database/seeds/AdminUserPermissionsTableSeeder.php b/database/seeds/AdminUserPermissionsTableSeeder.php new file mode 100644 index 00000000..21acdf8e --- /dev/null +++ b/database/seeds/AdminUserPermissionsTableSeeder.php @@ -0,0 +1,76 @@ +forget('spatie.permission.cache'); + + // admin permissions + Permission::create(['name' => 'view document', 'guard_name' => 'web']); + Permission::create(['name' => 'add document', 'guard_name' => 'web']); + Permission::create(['name' => 'edit document', 'guard_name' => 'web']); + Permission::create(['name' => 'delete document', 'guard_name' => 'web']); + + + Permission::create(['name' => 'view standard_segment', 'guard_name' => 'web']); + Permission::create(['name' => 'add standard_segment', 'guard_name' => 'web']); + Permission::create(['name' => 'edit standard_segment', 'guard_name' => 'web']); + Permission::create(['name' => 'delete standard_segment', 'guard_name' => 'web']); + + Permission::create(['name' => 'view standard_segment_constant', 'guard_name' => 'web']); + Permission::create(['name' => 'add standard_segment_constant', 'guard_name' => 'web']); + Permission::create(['name' => 'edit standard_segment_constant', 'guard_name' => 'web']); + Permission::create(['name' => 'delete standard_segment_constant', 'guard_name' => 'web']); + + Permission::create(['name' => 'view segment', 'guard_name' => 'web']); + Permission::create(['name' => 'add segment', 'guard_name' => 'web']); + Permission::create(['name' => 'edit segment', 'guard_name' => 'web']); + Permission::create(['name' => 'delete segment', 'guard_name' => 'web']); + + Permission::create(['name' => 'view segment_constant', 'guard_name' => 'web']); + Permission::create(['name' => 'add segment_constant', 'guard_name' => 'web']); + Permission::create(['name' => 'edit segment_constant', 'guard_name' => 'web']); + Permission::create(['name' => 'delete segment_constant', 'guard_name' => 'web']); + + /////////////////////////////////////////////////////////////////////// + + $shadow_admin_role = Role::create([ + 'name' => 'Shadow Admin', + 'guard_name' => 'web', + 'type' => 1, + ]); + + $shadow_admin_role->givePermissionTo(Permission::all()); + + $admin = User::find(1); + $admin->assignRole($shadow_admin_role); + + /////////////////////////////////////////////////////////////////////// + + $ultimate_admin_role = Role::create([ + 'name' => 'Ultimate Admin', + 'guard_name' => 'web', + 'type' => 1, + ]); + + $ultimate_admin_role->givePermissionTo(Permission::all()); + + $admin = User::find(2); + $admin->assignRole($ultimate_admin_role); + + /////////////////////////////////////////////////////////////////////// + } +} diff --git a/database/seeds/AdminUserTableSeeder.php b/database/seeds/AdminUserTableSeeder.php new file mode 100644 index 00000000..0eb00cba --- /dev/null +++ b/database/seeds/AdminUserTableSeeder.php @@ -0,0 +1,42 @@ +insert([ + [ + 'id' => 1, + 'name' => 'The One', + 'email' => 'admin@exchange.com', + 'password' => bcrypt('pass123'), + 'type' => 1, + 'status' => 1, + 'remember_token' => (string) Str::uuid(), + 'active_at' => date('Y-m-d H:i:s'), + 'created_at' => date('Y-m-d H:i:s'), + 'updated_at' => date('Y-m-d H:i:s'), + ], + [ + 'id' => 2, + 'name' => 'The Admin', + 'email' => 'admin2@exchange.com', + 'password' => bcrypt('pass123'), + 'type' => 1, + 'status' => 1, + 'remember_token' => (string) Str::uuid(), + 'active_at' => date('Y-m-d H:i:s'), + 'created_at' => date('Y-m-d H:i:s'), + 'updated_at' => date('Y-m-d H:i:s'), + ] + ]); + } +} diff --git a/database/seeds/DatabaseSeeder.php b/database/seeds/DatabaseSeeder.php index b02b426f..cdfc22d4 100644 --- a/database/seeds/DatabaseSeeder.php +++ b/database/seeds/DatabaseSeeder.php @@ -19,6 +19,13 @@ class DatabaseSeeder extends Seeder $this->call(StatesTableSeeder::class); $this->call(DistrictsTableSeeder::class); + $this->call(SegmentsTableSeeder::class); + $this->call(SegmentConstantsTableSeeder::class); + + // Admin + $this->call(AdminUserTableSeeder::class); + $this->call(AdminUserPermissionsTableSeeder::class); + DB::commit(); } } diff --git a/database/seeds/SegmentConstantsTableSeeder.php b/database/seeds/SegmentConstantsTableSeeder.php new file mode 100644 index 00000000..283bb4d5 --- /dev/null +++ b/database/seeds/SegmentConstantsTableSeeder.php @@ -0,0 +1,79 @@ +insert([ + [ + 'id' => 1, + 'segment_id' => 1, + 'name' => 'Tax', + 'reference' => 'TAX', + 'detail' => json_encode([ + 'type' => 'percentage', + 'value' => '10' + ]), + 'created_at' => date('Y-m-d H:i:s'), + 'updated_at' => date('Y-m-d H:i:s'), + ], + [ + 'id' => 2, + 'segment_id' => 1, + 'name' => 'Billing Fee', + 'reference' => 'BILLING_FEE', + 'detail' => json_encode([ + 'type' => 'fix_rate', + 'value' => '10' + ]), + 'created_at' => date('Y-m-d H:i:s'), + 'updated_at' => date('Y-m-d H:i:s'), + ], + [ + 'id' => 3, + 'segment_id' => 1, + 'name' => 'Service Charge', + 'reference' => 'SERVICE_CHARGE', + 'detail' => json_encode([ + 'type' => 'fix_rate', + 'value' => '10' + ]), + 'created_at' => date('Y-m-d H:i:s'), + 'updated_at' => date('Y-m-d H:i:s'), + ], + [ + 'id' => 4, + 'segment_id' => 1, + 'name' => 'Booking Amount Max', + 'reference' => 'BOOKING_AMOUNT_MAX', + 'detail' => json_encode([ + 'type' => 'fix_rate', + 'value' => '10', + 'currency_id' => 1 + ]), + 'created_at' => date('Y-m-d H:i:s'), + 'updated_at' => date('Y-m-d H:i:s'), + ], + [ + 'id' => 5, + 'segment_id' => 1, + 'name' => 'Payment Attempt Expiry Time', + 'reference' => 'PAYMENT_ATTEMP_EXPIRY_TIME', + 'detail' => json_encode([ + 'type' => 'day', + 'value' => '10', + ]), + 'created_at' => date('Y-m-d H:i:s'), + 'updated_at' => date('Y-m-d H:i:s'), + ], + ]); + } +} diff --git a/database/seeds/SegmentsTableSeeder.php b/database/seeds/SegmentsTableSeeder.php new file mode 100644 index 00000000..bda12c31 --- /dev/null +++ b/database/seeds/SegmentsTableSeeder.php @@ -0,0 +1,24 @@ +insert([ + [ + 'id' => 1, + 'name' => 'Standard Segment', + 'created_at' => date('Y-m-d H:i:s'), + 'updated_at' => date('Y-m-d H:i:s'), + ] + ]); + } +} diff --git a/resources/assets/vue/components/accounts/forms/LoginFormComponent.vue b/resources/assets/vue/components/accounts/forms/LoginFormComponent.vue index 98aa3746..1528f831 100644 --- a/resources/assets/vue/components/accounts/forms/LoginFormComponent.vue +++ b/resources/assets/vue/components/accounts/forms/LoginFormComponent.vue @@ -79,12 +79,15 @@ methods:{ successHandler(response){ localStorage.setItem('user-token', response.payload.access_token); + + console.log(response.payload.access_token); + this.$store.dispatch('userAuthentication', {access_token: response.payload.access_token}); this.error = ''; - this.$store.dispatch('toggleSection', {name: 'loginSuccess', status: true}) - setTimeout(function(){ - window.location.href = response.payload.redirect_url; - }, 2000); + // this.$store.dispatch('toggleSection', {name: 'loginSuccess', status: true}) + // setTimeout(function(){ + // window.location.href = response.payload.redirect_url; + // }, 2000); }, errorHandler(error){ this.$store.dispatch('userAuthentication', {access_token: ''}); diff --git a/routes/api.php b/routes/api.php index 343abddc..7199a37a 100644 --- a/routes/api.php +++ b/routes/api.php @@ -18,6 +18,12 @@ Route::group(['middleware' => 'api', 'prefix' => 'v1', 'as' => 'api.'], function require __DIR__ . '/account.php'; + require __DIR__ . '/document.php'; + + require __DIR__ . '/segment.php'; + require __DIR__ . '/segment_constant.php'; + + Route::group(['middleware' => 'valid.token'], function () { require __DIR__ . '/crud.php'; }); diff --git a/routes/document.php b/routes/document.php new file mode 100644 index 00000000..d6d16a4e --- /dev/null +++ b/routes/document.php @@ -0,0 +1,12 @@ + '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'); + }); + }); +}); \ No newline at end of file diff --git a/routes/segment.php b/routes/segment.php new file mode 100644 index 00000000..4ca1f3fb --- /dev/null +++ b/routes/segment.php @@ -0,0 +1,21 @@ + 'StandardSegments'], function () { + Route::group(['middleware' => 'valid.token'], function () { + Route::group(['prefix' => 'standard-segment'], function () { + Route::get('/list', 'ListStandardSegmentsController@list')->name('standard_segment.update'); + }); + }); +}); + +Route::group(['namespace' => 'Segments'], function () { + Route::group(['middleware' => 'valid.token'], function () { + Route::group(['prefix' => 'segment'], function () { + Route::post('/create', 'CreateSegmentController@create')->name('segment.create'); + Route::put('/update/{id}', 'UpdateSegmentController@update')->name('segment.update'); + Route::delete('/delete/{id}', 'DeleteSegmentController@delete')->name('segment.delete'); + }); + }); +}); \ No newline at end of file diff --git a/routes/segment_constant.php b/routes/segment_constant.php new file mode 100644 index 00000000..7f61aaa4 --- /dev/null +++ b/routes/segment_constant.php @@ -0,0 +1,23 @@ + '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::get('/list', 'ListStandardSegmentConstantsController@list')->name('standard_segment.update'); + Route::post('/create', 'CreateSegmentConstantController@create')->name('segment_constant.create'); + Route::put('/update/{id}', 'UpdateSegmentConstantController@update')->name('segment_constant.update'); + }); + }); +}); \ No newline at end of file