diff --git a/app/Classes/Modules/Accounts/ControllersLogic/AddNewMemberLogic.php b/app/Classes/Modules/Accounts/ControllersLogic/AddNewMemberLogic.php
new file mode 100644
index 00000000..19dc5b59
--- /dev/null
+++ b/app/Classes/Modules/Accounts/ControllersLogic/AddNewMemberLogic.php
@@ -0,0 +1,78 @@
+ 'Updated Email',
+ 'message' => 'Successfully updated email'
+ ];
+ }
+
+ /**
+ * @var AssignEmployeeProcessor
+ */
+ private $assignEmployeeProcessor;
+
+ /**
+ * @var GenerateEmailVerificationAttemptProcessor
+ */
+ private $generateEmailVerificationAttemptProcessor;
+
+ /**
+ * AddNewMemberLogic constructor.
+ * @param AssignEmployeeProcessor $assignEmployeeProcessor
+ * @param GenerateEmailVerificationAttemptProcessor $generateEmailVerificationAttemptProcessor
+ */
+ public function __construct(AssignEmployeeProcessor $assignEmployeeProcessor, GenerateEmailVerificationAttemptProcessor $generateEmailVerificationAttemptProcessor)
+ {
+ $this->assignEmployeeProcessor = $assignEmployeeProcessor;
+ $this->generateEmailVerificationAttemptProcessor = $generateEmailVerificationAttemptProcessor;
+ }
+
+ /**
+ * @param Request $request
+ * @return JsonResponse
+ * @throws ResourceConflictException
+ * @throws \App\Classes\Exceptions\AccessForbiddenException
+ * @throws \App\Classes\Exceptions\MalformedRequestException
+ * @throws \App\Classes\Exceptions\RequestValidationException
+ */
+ public function logic(Request $request): JsonResponse
+ {
+ try {
+ $user = Auth::user()->replicate();
+ $user->email = $request->input('email');
+ $user->status = ApprovalStatus::PENDING_VERIFICATION;
+ $user->save();
+ } catch (QueryException $exception){
+ throw new ResourceConflictException('Unable to change your email address as it already exists');
+ }
+
+ if($company = Auth::user()->companyModule()->first()){
+ $Object = new EmploymentObject($company, $user);
+ $this->assignEmployeeProcessor->execute($Object);
+ }
+
+ $this->generateEmailVerificationAttemptProcessor->execute($user);
+
+ return $this->resourceResponse(new UserResource($user));
+ }
+}
diff --git a/app/Classes/Modules/Segments/ControllersLogic/DeleteSegmentLogic.php b/app/Classes/Modules/Segments/ControllersLogic/DeleteSegmentLogic.php
index 5d2f6c3b..98844819 100644
--- a/app/Classes/Modules/Segments/ControllersLogic/DeleteSegmentLogic.php
+++ b/app/Classes/Modules/Segments/ControllersLogic/DeleteSegmentLogic.php
@@ -45,7 +45,6 @@ class DeleteSegmentLogic extends AbstractControllerLogic
$this->fetchesSegment = $fetchesSegment;
}
-
/**
* @param Request $request
* @return JsonResponse
diff --git a/app/Classes/Modules/Segments/ControllersLogic/FetchConstantLogic.php b/app/Classes/Modules/Segments/ControllersLogic/FetchConstantLogic.php
new file mode 100644
index 00000000..6c5c5b0f
--- /dev/null
+++ b/app/Classes/Modules/Segments/ControllersLogic/FetchConstantLogic.php
@@ -0,0 +1,52 @@
+ 'Fetch Segment Constant',
+ 'message' => 'You have successfully retrieved the Segment Constant'
+ ];
+ }
+
+
+ /** @var FetchesConstant */
+ private $fetchesConstant;
+
+ /**
+ * FetchConstantLogic constructor.
+ * @param FetchesConstant $fetchesConstant
+ */
+ public function __construct(FetchesConstant $fetchesConstant)
+ {
+ $this->fetchesConstant = $fetchesConstant;
+ }
+
+
+ /**
+ * @param Request $request
+ * @return JsonResponse
+ */
+ public function logic(Request $request) : JsonResponse
+ {
+
+ $constant = $this->fetchesConstant->execute(['segment_id' => $request->route('id'), 'reference' => $request->route('reference')]);
+
+ return $this->resourceResponse(new ConstantResource($constant));
+
+ }
+
+}
\ No newline at end of file
diff --git a/app/Classes/Modules/Segments/ControllersLogic/FetchSegmentLogic.php b/app/Classes/Modules/Segments/ControllersLogic/FetchSegmentLogic.php
new file mode 100644
index 00000000..d5c35fdc
--- /dev/null
+++ b/app/Classes/Modules/Segments/ControllersLogic/FetchSegmentLogic.php
@@ -0,0 +1,59 @@
+ 'Retrieved Segment',
+ 'message' => 'You have successfully retrieved a segment'
+ ];
+ }
+
+ /** @var CanFetchSegment */
+ private $canFetchSegment;
+
+ /** @var FetchesSegment */
+ private $fetchesSegment;
+
+ /**
+ * FetchSegmentLogic constructor.
+ * @param CanFetchSegment $canFetchSegment
+ * @param FetchesSegment $fetchesSegment
+ */
+ public function __construct(CanFetchSegment $canFetchSegment, FetchesSegment $fetchesSegment)
+ {
+ $this->canFetchSegment = $canFetchSegment;
+ $this->fetchesSegment = $fetchesSegment;
+ }
+
+ /**
+ * @param Request $request
+ * @return JsonResponse
+ * @throws \App\Classes\Exceptions\AccessForbiddenException
+ * @throws \App\Classes\Exceptions\RequestValidationException
+ */
+ public function logic(Request $request) : JsonResponse
+ {
+ $this->canFetchSegment->passes();
+
+ $query = $this->fetchesSegment->execute(['id' => $request->route('id')]);
+
+ return $this->resourceResponse(new SegmentResource($query));
+
+ }
+
+}
\ No newline at end of file
diff --git a/app/Classes/Modules/Segments/ControllersLogic/ListSegmentLogic.php b/app/Classes/Modules/Segments/ControllersLogic/ListSegmentLogic.php
new file mode 100644
index 00000000..d8299424
--- /dev/null
+++ b/app/Classes/Modules/Segments/ControllersLogic/ListSegmentLogic.php
@@ -0,0 +1,52 @@
+ 'Retrieved Segment',
+ 'message' => 'You have successfully retrieved a list of Segment'
+ ];
+ }
+
+
+ /** @var ListsSegments */
+ private $listsSegments;
+
+ /**
+ * ListSegmentLogic constructor.
+ * @param ListsSegments $listsSegments
+ */
+ public function __construct(ListsSegments $listsSegments)
+ {
+ $this->listsSegments = $listsSegments;
+ }
+
+ /**
+ * @param Request $request
+ * @return JsonResponse
+ * @throws \App\Classes\Exceptions\MalformedRequestException
+ */
+ public function logic(Request $request) : JsonResponse
+ {
+
+ $query = $this->listsSegments->execute($this->listsSegments->deserializeFilters($request->input('filters')));
+
+ return $this->collectionResponse(SegmentResource::collection($query));
+
+ }
+
+}
\ No newline at end of file
diff --git a/app/Classes/Modules/Segments/ControllersLogic/UpdateConstantLogic.php b/app/Classes/Modules/Segments/ControllersLogic/UpdateConstantLogic.php
new file mode 100644
index 00000000..dac04ec7
--- /dev/null
+++ b/app/Classes/Modules/Segments/ControllersLogic/UpdateConstantLogic.php
@@ -0,0 +1,104 @@
+ 'Updated Segment Constant',
+ 'message' => 'You have successfully updated the Segment Constant'
+ ];
+ }
+
+ /** @var CanUpdateConstant */
+ private $canUpdateConstant;
+
+ /** @var UpdatesConstant */
+ private $updatesConstant;
+
+ /** @var FetchesSegment */
+ private $fetchesSegment;
+
+ /** @var FetchesConstant */
+ private $fetchesConstant;
+
+ /** @var CanCreateConstant */
+ private $canCreateConstant;
+
+ /** @var CreatesConstant */
+ private $createsConstant;
+
+
+ /**
+ * UpdateConstantLogic constructor.
+ * @param CanUpdateConstant $canUpdateConstant
+ * @param UpdatesConstant $updatesConstant
+ * @param FetchesSegment $fetchesSegment
+ * @param FetchesConstant $fetchesConstant
+ * @param CanCreateConstant $canCreateConstant
+ * @param CreatesConstant $createsConstant
+ */
+ public function __construct(CanUpdateConstant $canUpdateConstant, UpdatesConstant $updatesConstant, FetchesSegment $fetchesSegment, FetchesConstant $fetchesConstant, CanCreateConstant $canCreateConstant, CreatesConstant $createsConstant)
+ {
+ $this->canUpdateConstant = $canUpdateConstant;
+ $this->updatesConstant = $updatesConstant;
+ $this->fetchesSegment = $fetchesSegment;
+ $this->fetchesConstant = $fetchesConstant;
+ $this->canCreateConstant = $canCreateConstant;
+ $this->createsConstant = $createsConstant;
+ }
+ /**
+ * @param Request $request
+ * @return JsonResponse
+ * @throws \App\Classes\Exceptions\AccessForbiddenException
+ * @throws \App\Classes\Exceptions\MalformedRequestException
+ * @throws \App\Classes\Exceptions\RequestValidationException
+ */
+ public function logic(Request $request) : JsonResponse
+ {
+
+ $object = new ConstantObject($request->input('name'), $request->input('reference'), $request->input('detail'));
+
+ $segment = $this->fetchesSegment->execute(['id' => $request->route('id')]);
+
+ try {
+
+ $constant = $this->fetchesConstant->execute(['segment_id' => $segment->id, 'reference' => $object->getReference()]);
+ $this->canUpdateConstant->passes($object);
+
+ /** @var SegmentConstant $constant */
+ $constant = $this->updatesConstant->execute($constant, $object);
+
+ } catch (ResourceNotFoundException $exception){
+
+ $this->canCreateConstant->passes($object);
+
+ /** @var SegmentConstant $constant */
+ $constant = $this->createsConstant->execute($segment, $object);
+
+ }
+
+
+ return $this->resourceResponse(new ConstantResource($constant));
+ }
+
+}
\ No newline at end of file
diff --git a/app/Classes/Modules/Segments/ControllersLogic/UpdateSegmentLogic.php b/app/Classes/Modules/Segments/ControllersLogic/UpdateSegmentLogic.php
new file mode 100644
index 00000000..43eaa54e
--- /dev/null
+++ b/app/Classes/Modules/Segments/ControllersLogic/UpdateSegmentLogic.php
@@ -0,0 +1,87 @@
+ 'Updated Segment',
+ 'message' => 'You have successfully updated the Segment'
+ ];
+ }
+
+ /** @var CanUpdateSegment */
+ private $canUpdateSegment;
+
+ /** @var UpdatesSegment */
+ private $updatesSegment;
+
+ /** @var FetchesSegment */
+ private $fetchesSegment;
+
+
+ /**
+ * UpdateSegmentLogic 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/Services/ConvertsConstantDetailsToResource.php b/app/Classes/Modules/Segments/Services/ConvertsConstantDetailsToResource.php
new file mode 100644
index 00000000..4489da1f
--- /dev/null
+++ b/app/Classes/Modules/Segments/Services/ConvertsConstantDetailsToResource.php
@@ -0,0 +1,38 @@
+fetchesCurrency = $fetchesCurrency;
+ }
+
+
+ public function execute(SegmentConstant $constant){
+
+ if($constant->reference === SegmentConstants::SUPPLIER_CURRENCIES) {
+ return property_exists($constant->detail, 'id') ? new CurrencyResource($this->fetchesCurrency->execute(['id' => $constant->detail->id])) : '';
+ }
+
+ return $constant->detail;
+
+ }
+
+}
\ No newline at end of file
diff --git a/app/Classes/Modules/Segments/Services/CreatesSegment.php b/app/Classes/Modules/Segments/Services/CreatesSegment.php
index 4dff35a7..aea2d87f 100644
--- a/app/Classes/Modules/Segments/Services/CreatesSegment.php
+++ b/app/Classes/Modules/Segments/Services/CreatesSegment.php
@@ -8,7 +8,6 @@ use App\Models\Segment;
class CreatesSegment extends AbstractUpdateRecord
{
-
/**
* @param SegmentObject $object
* @return \Illuminate\Database\Eloquent\Model
diff --git a/app/Classes/Modules/Segments/Services/FetchesConstant.php b/app/Classes/Modules/Segments/Services/FetchesConstant.php
new file mode 100644
index 00000000..bfa1b2cb
--- /dev/null
+++ b/app/Classes/Modules/Segments/Services/FetchesConstant.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/ListsConstants.php b/app/Classes/Modules/Segments/Services/ListsConstants.php
new file mode 100644
index 00000000..733a6db7
--- /dev/null
+++ b/app/Classes/Modules/Segments/Services/ListsConstants.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/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/UpdatesConstant.php b/app/Classes/Modules/Segments/Services/UpdatesConstant.php
new file mode 100644
index 00000000..13fb22c1
--- /dev/null
+++ b/app/Classes/Modules/Segments/Services/UpdatesConstant.php
@@ -0,0 +1,26 @@
+name = $object->getName();
+ $model->reference = $object->getReference();
+ $model->detail = json_encode($object->getDetail());
+
+ return $this->handler($model);
+ }
+}
\ 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..17f13efb
--- /dev/null
+++ b/app/Classes/Modules/Segments/Services/UpdatesSegment.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/Standards/Rules/CanCreateConstant.php b/app/Classes/Modules/Segments/Standards/Rules/CanCreateConstant.php
new file mode 100644
index 00000000..55f9c61a
--- /dev/null
+++ b/app/Classes/Modules/Segments/Standards/Rules/CanCreateConstant.php
@@ -0,0 +1,54 @@
+constantValidation = $constantValidation;
+ }
+
+
+ /**
+ * @return bool
+ */
+ protected function authorized(): bool
+ {
+ // TODO Set Authorization rules
+ return true;
+
+
+ }
+
+ /**
+ * @param ConstantObject $object
+ * @return bool
+ * @throws \App\Classes\Exceptions\RequestValidationException
+ */
+ protected function validators($object): bool
+ {
+ return $this->constantValidation->validate($object, 'POST');
+ }
+
+ /**
+ * @param ConstantObject $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/CanFetchSegment.php b/app/Classes/Modules/Segments/Standards/Rules/CanFetchSegment.php
new file mode 100644
index 00000000..e6756305
--- /dev/null
+++ b/app/Classes/Modules/Segments/Standards/Rules/CanFetchSegment.php
@@ -0,0 +1,43 @@
+ConstantValidation = $ConstantValidation;
+ }
+
+
+ /**
+ * @return bool
+ */
+ protected function authorized(): bool
+ {
+ // TODO Set Authorization rules
+ return true;
+ }
+
+ /**
+ * @param ConstantObject $object
+ * @return bool
+ * @throws \App\Classes\Exceptions\RequestValidationException
+ */
+ protected function validators($object): bool
+ {
+ return $this->ConstantValidation->validate($object, 'PUT');
+ }
+
+ /**
+ * @param ConstantObject $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..58a8c0ca
--- /dev/null
+++ b/app/Classes/Modules/Segments/Standards/Rules/CanUpdateSegment.php
@@ -0,0 +1,59 @@
+segmentValidation = $segmentValidation;
+ }
+
+ /**
+ * @return bool
+ */
+ protected function authorized(): bool
+ {
+ // TODO Set Authorization rules
+
+ if (!\Auth::user()->can('edit 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/Validators/ConstantValidation.php b/app/Classes/Modules/Segments/Standards/Validators/ConstantValidation.php
new file mode 100644
index 00000000..d5ac8819
--- /dev/null
+++ b/app/Classes/Modules/Segments/Standards/Validators/ConstantValidation.php
@@ -0,0 +1,44 @@
+ $object->getName(),
+ 'reference' => $object->getReference(),
+ 'detail' => $object->getDetail()
+ ];
+
+ return $data;
+ }
+
+ /**
+ * @return array
+ */
+ protected function rules(): array {
+ return [
+ 'name' => 'required',
+ 'reference' => 'required',
+ 'detail' => 'required'
+ ];
+ }
+
+ /**
+ * @return array
+ */
+ protected function messages(): array {
+ return [];
+ }
+
+}
\ No newline at end of file
diff --git a/app/Classes/Modules/ServiceTypes/ControllersLogic/CreateServiceTypeLogic.php b/app/Classes/Modules/ServiceTypes/ControllersLogic/CreateServiceTypeLogic.php
new file mode 100644
index 00000000..07672f85
--- /dev/null
+++ b/app/Classes/Modules/ServiceTypes/ControllersLogic/CreateServiceTypeLogic.php
@@ -0,0 +1,105 @@
+ 'Created Service Type',
+ 'message' => 'You have successfully created a new Service Type'
+ ];
+ }
+
+ /** @var CanCreateServiceType */
+ private $canCreateServiceType;
+
+ /** @var CreatesServiceType */
+ private $createsServiceType;
+
+ /** @var CreatesServiceTypeConstantDetails */
+ private $createsServiceTypeConstantDetails;
+
+ /** @var UpdatesServiceCurrencyRates */
+ private $updatesServiceCurrencyRates;
+
+ /** @var FetchesSegment */
+ private $fetchesSegment;
+
+ /** @var CreatesConstant */
+ private $createsConstant;
+
+
+ /**
+ * CreateServiceTypeLogic constructor.
+ * @param CanCreateServiceType $canCreateServiceType
+ * @param CreatesServiceType $createsServiceType
+ * @param CreatesServiceTypeConstantDetails $createsServiceTypeConstantDetails
+ * @param UpdatesServiceCurrencyRates $updatesServiceCurrencyRates
+ * @param FetchesSegment $fetchesSegment
+ * @param CreatesConstant $createsConstant
+ */
+ public function __construct(CanCreateServiceType $canCreateServiceType, CreatesServiceType $createsServiceType, CreatesServiceTypeConstantDetails $createsServiceTypeConstantDetails, UpdatesServiceCurrencyRates $updatesServiceCurrencyRates, FetchesSegment $fetchesSegment, CreatesConstant $createsConstant)
+ {
+ $this->canCreateServiceType = $canCreateServiceType;
+ $this->createsServiceType = $createsServiceType;
+ $this->createsServiceTypeConstantDetails = $createsServiceTypeConstantDetails;
+ $this->updatesServiceCurrencyRates = $updatesServiceCurrencyRates;
+ $this->fetchesSegment = $fetchesSegment;
+ $this->createsConstant = $createsConstant;
+ }
+
+ /**
+ * @param Request $request
+ * @return JsonResponse
+ * @throws \App\Classes\Exceptions\AccessForbiddenException
+ * @throws \App\Classes\Exceptions\MalformedRequestException
+ * @throws \App\Classes\Exceptions\RequestValidationException
+ */
+ public function logic(Request $request) : JsonResponse
+ {
+
+ $object = new ServiceTypeObject($request->input('name'));
+
+ $this->canCreateServiceType->passes($object);
+
+ /** @var ServiceType $service */
+ $service = $this->createsServiceType->execute($object);
+
+ $object = new ServiceDetailObject($service->id, (int) $request->input('configurations.bank_id'),
+ $request->input('configurations.service_charge'), $request->input('configurations.minimum_charge'), $request->input('configurations.tax'),
+ $request->input('configurations.po_limit'), $request->input('configurations.currencies'), false, $request->input('configurations.billable'));
+
+ $this->updatesServiceCurrencyRates->execute($service, $object->getCurrencies());
+
+ $constantObject = new ConstantObject('Service Type', SegmentConstants::SERVICE_TYPE, $this->createsServiceTypeConstantDetails->execute($object));
+
+ $this->createsConstant->execute($this->fetchesSegment->execute(['type' => SegmentConstants::STANDARD_SEGMENT]), $constantObject);
+
+
+ return $this->resourceResponse(new ServiceTypeResource($service));
+
+ }
+
+}
\ No newline at end of file
diff --git a/app/Classes/Modules/ServiceTypes/ControllersLogic/DeleteServiceTypeLogic.php b/app/Classes/Modules/ServiceTypes/ControllersLogic/DeleteServiceTypeLogic.php
new file mode 100644
index 00000000..c45c49d9
--- /dev/null
+++ b/app/Classes/Modules/ServiceTypes/ControllersLogic/DeleteServiceTypeLogic.php
@@ -0,0 +1,68 @@
+ 'Deleted Service Type',
+ 'message' => 'You have successfully deleted a Service Type'
+ ];
+ }
+
+
+ /** @var CanDeleteServiceType */
+ private $canDeleteServiceType;
+
+ /** @var DeletesServiceType */
+ private $deletesServiceType;
+
+ /** @var FetchesServiceType */
+ private $fetchesServiceType;
+
+ /**
+ * DeleteServiceTypeLogic constructor.
+ * @param CanDeleteServiceType $canDeleteServiceType
+ * @param DeletesServiceType $deletesServiceType
+ * @param FetchesServiceType $fetchesServiceType
+ */
+ public function __construct(CanDeleteServiceType $canDeleteServiceType, DeletesServiceType $deletesServiceType, FetchesServiceType $fetchesServiceType)
+ {
+ $this->canDeleteServiceType = $canDeleteServiceType;
+ $this->deletesServiceType = $deletesServiceType;
+ $this->fetchesServiceType = $fetchesServiceType;
+ }
+
+
+ /**
+ * @param Request $request
+ * @return JsonResponse
+ * @throws \App\Classes\Exceptions\AccessForbiddenException
+ * @throws \App\Classes\Exceptions\RequestValidationException
+ */
+ public function logic(Request $request) : JsonResponse
+ {
+
+ $this->canDeleteServiceType->passes();
+
+ $query = $this->fetchesServiceType->execute(['id' => $request->route('id')]);
+
+ $this->deletesServiceType->execute($query);
+
+ return $this->response([]);
+
+ }
+
+}
\ No newline at end of file
diff --git a/app/Classes/Modules/ServiceTypes/ControllersLogic/FetchServiceTypeLogic.php b/app/Classes/Modules/ServiceTypes/ControllersLogic/FetchServiceTypeLogic.php
new file mode 100644
index 00000000..f7835d34
--- /dev/null
+++ b/app/Classes/Modules/ServiceTypes/ControllersLogic/FetchServiceTypeLogic.php
@@ -0,0 +1,62 @@
+ 'Retrieved Service Type',
+ 'message' => 'You have successfully retrieved a Service Type'
+ ];
+ }
+
+ /** @var CanFetchServiceType */
+ private $canFetchServiceType;
+
+ /** @var FetchesServiceType */
+ private $fetchesServiceType;
+
+ /**
+ * FetchServiceTypeLogic constructor.
+ * @param CanFetchServiceType $canFetchServiceType
+ * @param FetchesServiceType $fetchesServiceType
+ */
+ public function __construct(CanFetchServiceType $canFetchServiceType, FetchesServiceType $fetchesServiceType)
+ {
+ $this->canFetchServiceType = $canFetchServiceType;
+ $this->fetchesServiceType = $fetchesServiceType;
+ }
+
+
+ /**
+ * @param Request $request
+ * @return JsonResponse
+ * @throws \App\Classes\Exceptions\AccessForbiddenException
+ * @throws \App\Classes\Exceptions\RequestValidationException
+ */
+ public function logic(Request $request) : JsonResponse
+ {
+ $this->canFetchServiceType->passes();
+
+ $query = $this->fetchesServiceType->execute(['id' => $request->route('id')]);
+
+ return $this->resourceResponse(new ServiceTypeResource($query));
+
+ }
+
+}
\ No newline at end of file
diff --git a/app/Classes/Modules/ServiceTypes/ControllersLogic/ListServiceTypesLogic.php b/app/Classes/Modules/ServiceTypes/ControllersLogic/ListServiceTypesLogic.php
new file mode 100644
index 00000000..10b390ae
--- /dev/null
+++ b/app/Classes/Modules/ServiceTypes/ControllersLogic/ListServiceTypesLogic.php
@@ -0,0 +1,62 @@
+ 'Retrieved Service Types',
+ 'message' => 'You have successfully retrieved a list of Service Types'
+ ];
+ }
+
+ /** @var CanListServiceTypes */
+ private $canListServiceTypes;
+
+ /** @var ListsServiceTypes */
+ private $listsServiceTypes;
+
+ /**
+ * ListServiceTypesControllerLogic constructor.
+ * @param CanListServiceTypes $canListServiceTypes
+ * @param ListsServiceTypes $listsServiceTypes
+ */
+ public function __construct(CanListServiceTypes $canListServiceTypes, ListsServiceTypes $listsServiceTypes)
+ {
+ $this->canListServiceTypes = $canListServiceTypes;
+ $this->listsServiceTypes = $listsServiceTypes;
+ }
+
+
+ /**
+ * @param Request $request
+ * @return JsonResponse
+ * @throws \App\Classes\Exceptions\AccessForbiddenException
+ * @throws \App\Classes\Exceptions\MalformedRequestException
+ * @throws \App\Classes\Exceptions\RequestValidationException
+ */
+ public function logic(Request $request) : JsonResponse
+ {
+ $this->canListServiceTypes->passes();
+
+ $query = $this->listsServiceTypes->execute($this->listsServiceTypes->deserializeFilters($request->input('filters')));
+
+ return $this->collectionResponse(ServiceTypeResource::collection($query));
+
+ }
+
+}
\ No newline at end of file
diff --git a/app/Classes/Modules/ServiceTypes/ControllersLogic/UpdateCustomServiceConstantLogic.php b/app/Classes/Modules/ServiceTypes/ControllersLogic/UpdateCustomServiceConstantLogic.php
new file mode 100644
index 00000000..e08ef598
--- /dev/null
+++ b/app/Classes/Modules/ServiceTypes/ControllersLogic/UpdateCustomServiceConstantLogic.php
@@ -0,0 +1,110 @@
+ 'Update Segment Service',
+ 'message' => 'You have successfully update a segments service configuration'
+ ];
+ }
+
+ /** @var FetchesServiceType */
+ private $fetchesServiceType;
+
+ /** @var CreatesServiceTypeConstantDetails */
+ private $createsServiceTypeConstantDetails;
+
+ /** @var FetchesSegment */
+ private $fetchesSegment;
+
+ /** @var FetchesConstant */
+ private $fetchesConstant;
+
+ /** @var UpdatesConstant */
+ private $updatesConstant;
+
+ /** @var CreatesConstant */
+ private $createsConstant;
+
+ /**
+ * UpdateCustomServiceConstantLogic constructor.
+ * @param FetchesServiceType $fetchesServiceType
+ * @param CreatesServiceTypeConstantDetails $createsServiceTypeConstantDetails
+ * @param FetchesSegment $fetchesSegment
+ * @param FetchesConstant $fetchesConstant
+ * @param UpdatesConstant $updatesConstant
+ * @param CreatesConstant $createsConstant
+ */
+ public function __construct(FetchesServiceType $fetchesServiceType, CreatesServiceTypeConstantDetails $createsServiceTypeConstantDetails, FetchesSegment $fetchesSegment, FetchesConstant $fetchesConstant, UpdatesConstant $updatesConstant, CreatesConstant $createsConstant)
+ {
+ $this->fetchesServiceType = $fetchesServiceType;
+ $this->createsServiceTypeConstantDetails = $createsServiceTypeConstantDetails;
+ $this->fetchesSegment = $fetchesSegment;
+ $this->fetchesConstant = $fetchesConstant;
+ $this->updatesConstant = $updatesConstant;
+ $this->createsConstant = $createsConstant;
+ }
+
+ /**
+ * @param Request $request
+ * @return JsonResponse
+ * @throws \App\Classes\Exceptions\MalformedRequestException
+ */
+ public function logic(Request $request) : JsonResponse
+ {
+
+ $service = $this->fetchesServiceType->execute(['id' => $request->input('id')]);
+
+ $customFields = $request->input('custom_fields');
+
+ $object = new ServiceDetailObject($service->id, $customFields['bank_id'], $customFields['service_charge'],
+ $customFields['minimum_charge'], $customFields['tax'], $customFields['po_limit'], $request->input('configurations.currencies'),
+ $request->input('configurations.active'), true);
+
+ $constantObject = new ConstantObject('Custom Service Type', SegmentConstants::CUSTOM_SERVICE_TYPE, $this->createsServiceTypeConstantDetails->execute($object, true));
+
+ /** @var Segment $segment */
+ $segment = $this->fetchesSegment->execute(['id' => $request->route('id')]);
+
+ try {
+
+ $constant = $this->fetchesConstant->execute(['segment_id' => $segment->id, 'custom_service_type' => $object->getId()]);
+
+ $this->updatesConstant->execute($constant, $constantObject);
+
+ } catch (ResourceNotFoundException $exception){
+
+ $constant = $this->createsConstant->execute($segment, $constantObject);
+ }
+
+
+ return $this->resourceResponse(new CustomServiceTypeResource($constant));
+
+ }
+
+}
\ No newline at end of file
diff --git a/app/Classes/Modules/ServiceTypes/ControllersLogic/UpdateServiceTypeLogic.php b/app/Classes/Modules/ServiceTypes/ControllersLogic/UpdateServiceTypeLogic.php
new file mode 100644
index 00000000..51b88051
--- /dev/null
+++ b/app/Classes/Modules/ServiceTypes/ControllersLogic/UpdateServiceTypeLogic.php
@@ -0,0 +1,112 @@
+ 'Updated Service Type',
+ 'message' => 'You have successfully updated the Service Type'
+ ];
+ }
+
+ /** @var CanUpdateServiceType */
+ private $canUpdateServiceType;
+
+ /** @var UpdatesServiceType */
+ private $updatesServiceType;
+
+ /** @var FetchesServiceType */
+ private $fetchesServiceType;
+
+ /** @var CreatesServiceTypeConstantDetails */
+ private $createsServiceTypeConstantDetails;
+
+ /** @var UpdatesServiceCurrencyRates */
+ private $updatesServiceCurrencyRates;
+
+ /** @var UpdatesConstant */
+ private $updatesConstant;
+
+ /** @var FetchesConstant */
+ private $fetchesConstant;
+
+
+ /**
+ * UpdateServiceTypeLogic constructor.
+ * @param CanUpdateServiceType $canUpdateServiceType
+ * @param UpdatesServiceType $updatesServiceType
+ * @param FetchesServiceType $fetchesServiceType
+ * @param CreatesServiceTypeConstantDetails $createsServiceTypeConstantDetails
+ * @param UpdatesServiceCurrencyRates $updatesServiceCurrencyRates
+ * @param UpdatesConstant $updatesConstant
+ * @param FetchesConstant $fetchesConstant
+ */
+ public function __construct(CanUpdateServiceType $canUpdateServiceType, UpdatesServiceType $updatesServiceType, FetchesServiceType $fetchesServiceType, CreatesServiceTypeConstantDetails $createsServiceTypeConstantDetails, UpdatesServiceCurrencyRates $updatesServiceCurrencyRates, UpdatesConstant $updatesConstant, FetchesConstant $fetchesConstant)
+ {
+ $this->canUpdateServiceType = $canUpdateServiceType;
+ $this->updatesServiceType = $updatesServiceType;
+ $this->fetchesServiceType = $fetchesServiceType;
+ $this->createsServiceTypeConstantDetails = $createsServiceTypeConstantDetails;
+ $this->updatesServiceCurrencyRates = $updatesServiceCurrencyRates;
+ $this->updatesConstant = $updatesConstant;
+ $this->fetchesConstant = $fetchesConstant;
+ }
+
+ /**
+ * @param Request $request
+ * @return JsonResponse
+ * @throws \App\Classes\Exceptions\AccessForbiddenException
+ * @throws \App\Classes\Exceptions\MalformedRequestException
+ * @throws \App\Classes\Exceptions\RequestValidationException
+ */
+ public function logic(Request $request) : JsonResponse
+ {
+ $object = new ServiceTypeObject($request->input('name'));
+
+ $this->canUpdateServiceType->passes($object);
+
+ $service = $this->fetchesServiceType->execute(['id' => $request->route('id')]);
+
+ /** @var ServiceType $service */
+ $service = $this->updatesServiceType->execute($service, $object);
+
+ $object = new ServiceDetailObject($service->id, (int) $request->input('configurations.bank_id'),
+ $request->input('configurations.service_charge'), $request->input('configurations.minimum_charge'), $request->input('configurations.tax'),
+ $request->input('configurations.po_limit'), $request->input('configurations.currencies'), $request->input('configurations.active'), $request->input('configurations.billable'));
+
+ $this->updatesServiceCurrencyRates->execute($service, $object->getCurrencies());
+
+ $constantObject = new ConstantObject('Service Type', SegmentConstants::SERVICE_TYPE, $this->createsServiceTypeConstantDetails->execute($object));
+
+ $this->updatesConstant->execute($this->fetchesConstant->execute(['service_type' => $service->id]), $constantObject);
+
+ return $this->resourceResponse(new ServiceTypeResource($service));
+
+ }
+
+}
\ No newline at end of file
diff --git a/app/Classes/Modules/ServiceTypes/ControllersLogic/UpdateServiceTypeStatusLogic.php b/app/Classes/Modules/ServiceTypes/ControllersLogic/UpdateServiceTypeStatusLogic.php
new file mode 100644
index 00000000..f1d75665
--- /dev/null
+++ b/app/Classes/Modules/ServiceTypes/ControllersLogic/UpdateServiceTypeStatusLogic.php
@@ -0,0 +1,59 @@
+ 'Update Service Type',
+ 'message' => 'You have successfully updated a Service Type status'
+ ];
+ }
+
+ /** @var FetchesServiceType */
+ private $fetchesServiceType;
+
+ /** @var UpdatesServiceTypeStatus */
+ private $updatesServiceTypeStatus;
+
+ /**
+ * UpdateServiceTypeStatusLogic constructor.
+ * @param FetchesServiceType $fetchesServiceType
+ * @param UpdatesServiceTypeStatus $updatesServiceTypeStatus
+ */
+ public function __construct(FetchesServiceType $fetchesServiceType, UpdatesServiceTypeStatus $updatesServiceTypeStatus)
+ {
+ $this->fetchesServiceType = $fetchesServiceType;
+ $this->updatesServiceTypeStatus = $updatesServiceTypeStatus;
+ }
+
+ /**
+ * @param Request $request
+ * @return JsonResponse
+ */
+ public function logic(Request $request) : JsonResponse
+ {
+
+
+ $query = $this->fetchesServiceType->execute(['id' => $request->route('id')]);
+
+ $this->updatesServiceTypeStatus->execute($query, $request->route('status') === 'active' ? ApprovalStatus::APPROVED : ApprovalStatus::SUSPENDED);
+
+ return $this->response([]);
+
+ }
+
+}
\ No newline at end of file
diff --git a/app/Classes/Modules/ServiceTypes/DataTransferObjects/CustomConfigurationsObject.php b/app/Classes/Modules/ServiceTypes/DataTransferObjects/CustomConfigurationsObject.php
new file mode 100644
index 00000000..b14caa8c
--- /dev/null
+++ b/app/Classes/Modules/ServiceTypes/DataTransferObjects/CustomConfigurationsObject.php
@@ -0,0 +1,75 @@
+configurations = $configurations;
+ $this->customOptions = $customOptions;
+ }
+
+ /**
+ * @return SegmentConstant
+ */
+ public function getConfigurations(): SegmentConstant
+ {
+ return $this->configurations;
+ }
+
+ /**
+ * @return SegmentConstant
+ */
+ public function getCustomOptions(): SegmentConstant
+ {
+ return $this->customOptions;
+ }
+
+
+ /**
+ * @param string $name
+ * @return mixed
+ */
+ public function getConfigurationValue(string $name) {
+ return property_exists($this->getCustomOptions()->detail, $name) ?
+ $this->getCustomOptions()->detail->$name: $this->configurations->detail->$name;
+ }
+
+
+ /**
+ * @return mixed
+ */
+ public function calculateServiceCharge(){
+ return ($this->getConfigurationValue('service_charge')->value * 0.01) > $this->getConfigurationValue('minimum_charge')->value ?
+ $this->getConfigurationValue('service_charge')->value : $this->getConfigurationValue('minimum_charge')->value;
+ }
+
+ /**
+ * @return float
+ */
+ public function calculateTax(){
+ return $this->getConfigurationValue('tax')->value * 0.01;
+ }
+
+}
\ No newline at end of file
diff --git a/app/Classes/Modules/ServiceTypes/DataTransferObjects/ServiceCurrenciesObject.php b/app/Classes/Modules/ServiceTypes/DataTransferObjects/ServiceCurrenciesObject.php
new file mode 100644
index 00000000..fa32e5dd
--- /dev/null
+++ b/app/Classes/Modules/ServiceTypes/DataTransferObjects/ServiceCurrenciesObject.php
@@ -0,0 +1,90 @@
+id = $id;
+ $this->isActive = $isActive;
+ $this->maxLimit = $maxLimit;
+ $this->minLimit = $minLimit;
+ $this->rates = $rates;
+ }
+
+
+ /**
+ * @return int
+ */
+ public function getId(): int
+ {
+ return $this->id;
+ }
+
+ /**
+ * @return bool
+ */
+ public function isActive(): bool
+ {
+ return $this->isActive;
+ }
+
+ /**
+ * @return array
+ */
+ public function getMaxLimit(): array
+ {
+ return $this->maxLimit;
+ }
+
+ /**
+ * @return array
+ */
+ public function getMinLimit(): array
+ {
+ return $this->minLimit;
+ }
+
+
+ /**
+ * @return array
+ */
+ public function getRates(): array
+ {
+ return array_map(function($rate){
+ return new RateObject($rate['selling'], $rate['payment_method']);
+ }, $this->rates);
+ }
+
+
+
+
+}
\ No newline at end of file
diff --git a/app/Classes/Modules/ServiceTypes/DataTransferObjects/ServiceDetailObject.php b/app/Classes/Modules/ServiceTypes/DataTransferObjects/ServiceDetailObject.php
new file mode 100644
index 00000000..233d1fb3
--- /dev/null
+++ b/app/Classes/Modules/ServiceTypes/DataTransferObjects/ServiceDetailObject.php
@@ -0,0 +1,138 @@
+id = $id;
+ $this->bankId = $bankId;
+ $this->serviceCharge = $serviceCharge;
+ $this->minimumCharge = $minimumCharge;
+ $this->tax = $tax;
+ $this->poLimit = $poLimit;
+ $this->currencies = $currencies;
+ $this->isActive = $isActive;
+ $this->isBillable = $isBillable;
+ }
+
+ /**
+ * @return int
+ */
+ public function getId(): int
+ {
+ return $this->id;
+ }
+
+ /**
+ * @return int|null
+ */
+ public function getBankId(): ?int
+ {
+ return $this->bankId;
+ }
+
+ /**
+ * @return array|null
+ */
+ public function getServiceCharge(): ?array
+ {
+ return $this->serviceCharge;
+ }
+
+ /**
+ * @return array|null
+ */
+ public function getMinimumCharge(): ?array
+ {
+ return $this->minimumCharge;
+ }
+
+ /**
+ * @return array|null
+ */
+ public function getTax(): ?array
+ {
+ return $this->tax;
+ }
+
+ /**
+ * @return array|null
+ */
+ public function getPoLimit(): ?array
+ {
+ return $this->poLimit;
+ }
+
+ /**
+ * @return bool
+ */
+ public function isActive(): bool
+ {
+ return $this->isActive;
+ }
+
+ /**
+ * @return bool
+ */
+ public function isBillable(): bool
+ {
+ return $this->isBillable;
+ }
+
+
+ /**
+ * @return array|null
+ */
+ public function getCurrencies(): ?array
+ {
+ return array_map(function($currency){
+ return new ServiceCurrenciesObject($currency['id'], $currency['active'], $currency['maximum_limit'], $currency['minimum_limit'], $currency['rates']);
+ }, $this->currencies);
+ }
+
+
+}
\ No newline at end of file
diff --git a/app/Classes/Modules/ServiceTypes/DataTransferObjects/ServiceTypeObject.php b/app/Classes/Modules/ServiceTypes/DataTransferObjects/ServiceTypeObject.php
new file mode 100644
index 00000000..f65b7262
--- /dev/null
+++ b/app/Classes/Modules/ServiceTypes/DataTransferObjects/ServiceTypeObject.php
@@ -0,0 +1,33 @@
+name = $name;
+ }
+
+ /**
+ * @return string
+ */
+ public function getName(): string
+ {
+ return $this->name;
+ }
+
+
+
+}
\ No newline at end of file
diff --git a/app/Classes/Modules/ServiceTypes/Services/CreatesServiceType.php b/app/Classes/Modules/ServiceTypes/Services/CreatesServiceType.php
new file mode 100644
index 00000000..e9c05e94
--- /dev/null
+++ b/app/Classes/Modules/ServiceTypes/Services/CreatesServiceType.php
@@ -0,0 +1,19 @@
+name = $object->getName();
+
+ return $this->handler($model);
+
+ }
+}
\ No newline at end of file
diff --git a/app/Classes/Modules/ServiceTypes/Services/CreatesServiceTypeConstantDetails.php b/app/Classes/Modules/ServiceTypes/Services/CreatesServiceTypeConstantDetails.php
new file mode 100644
index 00000000..aacf66f1
--- /dev/null
+++ b/app/Classes/Modules/ServiceTypes/Services/CreatesServiceTypeConstantDetails.php
@@ -0,0 +1,141 @@
+mapCurrencies($object->$methodName(), $isCustomSegment);
+
+ continue;
+ }
+
+ $this->addToConstantDetails($methodName, $this->cleanValue($object->$methodName()));
+
+ }
+
+ return $this->ConstantDetails;
+
+ }
+
+ /**
+ * @param array $currencies
+ * @param bool $isCustomSegment
+ */
+ private function mapCurrencies(array $currencies, bool $isCustomSegment){
+
+ $isEmpty = true;
+ foreach ($currencies as $currency){
+
+ if(!$currency->isActive()) { continue; }
+
+ $currencyObject = [];
+
+
+ foreach (Helper::getClassMethodsArray(ServiceCurrenciesObject::class) as $methodName){
+
+ if($methodName === 'isActive') continue;
+ if($methodName === 'getRates') {
+ $currencyObject['rates'] = $this->mapRates($currency->$methodName(), $isCustomSegment);
+ continue;
+ }
+
+ $value = $this->cleanValue($currency->$methodName());
+
+ if($this->isAddable($value)) {
+ $isEmpty = false;
+ $currencyObject[Helper::getPropertyName($methodName)] = $value;
+ }
+
+ }
+
+ $this->addToCurrencyDetails($currencyObject);
+
+ }
+
+ if($isEmpty) $this->ConstantDetails['currencies'] = [];
+
+ }
+
+ private function mapRates(array $rates, bool $isCustomSegment){
+
+ if(!$isCustomSegment) return [];
+
+ $ratesObject = [];
+
+ /** @var RateObject $rate */
+ foreach ($rates as $rate){
+
+ $selling = $this->cleanValue($rate->getSelling());
+
+ if(!$selling['value']) continue;
+
+ $ratesObject[] = [
+ 'payment_type' => $rate->getPaymentMethodType(),
+ 'payment_method' => PaymentMethodType::PAYMENT_METHODS_ID[$rate->getPaymentMethodType()],
+ 'selling' => $rate->getSelling()
+ ];
+
+ }
+ return $ratesObject;
+
+ }
+
+
+ /**
+ * @param string $methodName
+ * @param $value
+ */
+ private function addToConstantDetails(string $methodName, $value){
+ $this->isAddable($value) ? $this->ConstantDetails[Helper::getPropertyName($methodName)] = $value : null;
+ }
+
+ /**
+ * @param $value
+ * @return bool
+ */
+ private function isAddable($value){
+
+ return $value !== '' && $value !== null;
+ }
+
+ private function cleanValue($value){
+
+ if(is_array($value)) {
+ if(array_key_exists('value', $value)) $value['value'] = floatval(str_replace(',', '', $value['value']));
+ }
+
+ return $value;
+ }
+
+ /**
+ * @param array $value
+ */
+ private function addToCurrencyDetails(array $value){
+ $this->ConstantDetails['currencies'][] = $value;
+ }
+
+}
\ No newline at end of file
diff --git a/app/Classes/Modules/ServiceTypes/Services/DeletesServiceType.php b/app/Classes/Modules/ServiceTypes/Services/DeletesServiceType.php
new file mode 100644
index 00000000..3cc4d69d
--- /dev/null
+++ b/app/Classes/Modules/ServiceTypes/Services/DeletesServiceType.php
@@ -0,0 +1,15 @@
+handler($model);
+ }
+}
\ No newline at end of file
diff --git a/app/Classes/Modules/ServiceTypes/Services/FetchesServiceBankConfigurations.php b/app/Classes/Modules/ServiceTypes/Services/FetchesServiceBankConfigurations.php
new file mode 100644
index 00000000..28843e4d
--- /dev/null
+++ b/app/Classes/Modules/ServiceTypes/Services/FetchesServiceBankConfigurations.php
@@ -0,0 +1,27 @@
+fetchesBank = $fetchesBank;
+ }
+
+ public function execute(SegmentConstant $constants)
+ {
+ return $this->fetchesBank->execute(['id' => $constants->detail->bank_id]);
+ }
+}
diff --git a/app/Classes/Modules/ServiceTypes/Services/FetchesServiceConfigurations.php b/app/Classes/Modules/ServiceTypes/Services/FetchesServiceConfigurations.php
new file mode 100644
index 00000000..d641d641
--- /dev/null
+++ b/app/Classes/Modules/ServiceTypes/Services/FetchesServiceConfigurations.php
@@ -0,0 +1,65 @@
+fetchesConstant = $fetchesConstant;
+ $this->fetchesServiceCurrenciesConfigurations = $fetchesServiceCurrenciesConfigurations;
+ $this->fetchesServiceBankConfigurations = $fetchesServiceBankConfigurations;
+ }
+
+
+ public function execute(SegmentConstant $constant, string $type){
+
+ return array_merge([
+ 'active' => (int) $constant->detail->is_active ?? false,
+ 'billable' => (int) $constant->detail->is_billable ?? false,
+ 'bank_id' => property_exists($constant->detail, 'bank_id') ? $constant->detail->bank_id : '',
+ 'bank_info' => property_exists($constant->detail, 'bank_id') ? $this->fetchesServiceBankConfigurations->execute($constant) : '',
+ 'currencies' => $this->fetchesServiceCurrenciesConfigurations->execute($constant)
+ ], $this->addConfigurations($constant)->toArray());
+
+ }
+
+ private function addConfigurations(SegmentConstant $constant) {
+
+ $configurations = collect(['service_charge', 'minimum_charge', 'tax', 'po_limit']);
+
+ return $configurations->flatMap(function($configuration) use($constant) {
+ if(!property_exists($constant->detail, $configuration)) return [];
+
+ return [$configuration => [
+ 'type' => $constant->detail->$configuration->type,
+ 'value' => $configuration !== 'po_limit' ? $this->covertToDecimal($constant->detail->$configuration->value) : $constant->detail->$configuration->value
+ ]];
+
+ });
+
+ }
+
+ private function covertToDecimal($value){
+ return number_format((float)$value, 2, '.', '');
+ }
+
+}
\ No newline at end of file
diff --git a/app/Classes/Modules/ServiceTypes/Services/FetchesServiceCurrenciesConfigurations.php b/app/Classes/Modules/ServiceTypes/Services/FetchesServiceCurrenciesConfigurations.php
new file mode 100644
index 00000000..7d00225a
--- /dev/null
+++ b/app/Classes/Modules/ServiceTypes/Services/FetchesServiceCurrenciesConfigurations.php
@@ -0,0 +1,69 @@
+fetchesCurrency = $fetchesCurrency;
+ }
+
+ public function execute(SegmentConstant $constants){
+
+ $currencies = array_map(function($configuration) use($constants){
+
+ $currency = $this->fetchesCurrency->execute(['id' => $configuration->id]);
+
+ if(! $currency->exists()) return [];
+
+ return json_decode(json_encode([
+ 'currency_object' => new CurrencyResource($currency),
+ 'id' => $configuration->id,
+ 'active' => true,
+ 'maximum_limit' => [
+ 'type' => $configuration->max_limit->type,
+ 'value' => number_format((float)$configuration->max_limit->value, 2, '.', ',')
+ ],
+ 'minimum_limit' => [
+ 'type' => $configuration->min_limit->type,
+ 'value' => number_format((float)$configuration->min_limit->value, 2, '.', ',')
+ ],
+ 'rates' => $constants->reference === SegmentConstants::SERVICE_TYPE ? $this->standardRates($currency->rates->where('service_id', $constants->detail->id)) : $configuration->rates
+ ]));
+
+ }, $constants->detail->currencies);
+
+ return array_filter($currencies);
+
+ }
+
+ private function standardRates(Collection $rates){
+ return $rates->map(function($rate){
+ return [
+ 'payment_method' => PaymentMethodType::PAYMENT_METHODS_ID[$rate->payment_method_type],
+ 'selling' => [
+ 'type' => 'rate',
+ 'value' => $rate->selling
+ ]
+ ];
+ });
+ }
+
+}
\ No newline at end of file
diff --git a/app/Classes/Modules/ServiceTypes/Services/FetchesServiceType.php b/app/Classes/Modules/ServiceTypes/Services/FetchesServiceType.php
new file mode 100644
index 00000000..7b5899fa
--- /dev/null
+++ b/app/Classes/Modules/ServiceTypes/Services/FetchesServiceType.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/ServiceTypes/Services/ListsServiceTypes.php b/app/Classes/Modules/ServiceTypes/Services/ListsServiceTypes.php
new file mode 100644
index 00000000..344d6c4d
--- /dev/null
+++ b/app/Classes/Modules/ServiceTypes/Services/ListsServiceTypes.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/ServiceTypes/Services/UpdatesServiceCurrencyRates.php b/app/Classes/Modules/ServiceTypes/Services/UpdatesServiceCurrencyRates.php
new file mode 100644
index 00000000..019d30b4
--- /dev/null
+++ b/app/Classes/Modules/ServiceTypes/Services/UpdatesServiceCurrencyRates.php
@@ -0,0 +1,55 @@
+createsRateLog = $createsRateLog;
+ }
+
+
+ /**
+ * @param ServiceType $service
+ * @param array $currencies
+ * @throws \App\Classes\Exceptions\MalformedRequestException
+ */
+ public function execute(ServiceType $service, array $currencies){
+
+ /** @var ServiceCurrenciesObject $currency */
+ foreach ($currencies as $currency) {
+
+ /** @var RateObject $rate */
+ foreach ($currency->getRates() as $rate){
+ if($rate->getSelling()['value'] > 0){
+ /** @var CurrencyRate $query */
+ $query = $service->rates()->updateOrCreate([
+ 'currency_id' => $currency->getId(),
+ 'payment_method_type' => $rate->getPaymentMethodType()
+ ], ['selling' => $rate->getSelling()['value']]);
+
+ $this->createsRateLog->execute($query);
+ }
+
+ }
+
+ }
+ }
+
+}
\ No newline at end of file
diff --git a/app/Classes/Modules/ServiceTypes/Services/UpdatesServiceType.php b/app/Classes/Modules/ServiceTypes/Services/UpdatesServiceType.php
new file mode 100644
index 00000000..06bd1e4f
--- /dev/null
+++ b/app/Classes/Modules/ServiceTypes/Services/UpdatesServiceType.php
@@ -0,0 +1,19 @@
+name = $object->getName();
+
+ return $this->handler($model);
+
+ }
+}
\ No newline at end of file
diff --git a/app/Classes/Modules/ServiceTypes/Services/UpdatesServiceTypeStatus.php b/app/Classes/Modules/ServiceTypes/Services/UpdatesServiceTypeStatus.php
new file mode 100644
index 00000000..065b218e
--- /dev/null
+++ b/app/Classes/Modules/ServiceTypes/Services/UpdatesServiceTypeStatus.php
@@ -0,0 +1,19 @@
+status = $status;
+
+ return $this->handler($model);
+
+ }
+}
\ No newline at end of file
diff --git a/app/Classes/Modules/ServiceTypes/Standards/Rules/CanCreateServiceType.php b/app/Classes/Modules/ServiceTypes/Standards/Rules/CanCreateServiceType.php
new file mode 100644
index 00000000..0fb57c32
--- /dev/null
+++ b/app/Classes/Modules/ServiceTypes/Standards/Rules/CanCreateServiceType.php
@@ -0,0 +1,57 @@
+serviceTypeValidation = $serviceTypeValidation;
+ }
+
+
+ /**
+ * @return bool
+ */
+ protected function authorized(): bool
+ {
+ // TODO Set Authorization rules
+ return true;
+
+ }
+
+ /**
+ * @param ServiceTypeObject $object
+ * @return bool
+ * @throws \App\Classes\Exceptions\RequestValidationException
+ */
+ protected function validators($object): bool
+ {
+ return $this->serviceTypeValidation->validate($object);
+
+ }
+
+
+ /**
+ * @param ServiceTypeObject $object
+ * @return bool
+ */
+ protected function criteria($object): bool
+ {
+ return true;
+ }
+
+}
\ No newline at end of file
diff --git a/app/Classes/Modules/ServiceTypes/Standards/Rules/CanDeleteServiceType.php b/app/Classes/Modules/ServiceTypes/Standards/Rules/CanDeleteServiceType.php
new file mode 100644
index 00000000..1a832257
--- /dev/null
+++ b/app/Classes/Modules/ServiceTypes/Standards/Rules/CanDeleteServiceType.php
@@ -0,0 +1,43 @@
+serviceTypeValidation = $serviceTypeValidation;
+ }
+
+
+ /**
+ * @return bool
+ */
+ protected function authorized(): bool
+ {
+ // TODO Set Authorization rules
+ return true;
+
+ }
+
+ /**
+ * @param ServiceTypeObject $object
+ * @return bool
+ * @throws \App\Classes\Exceptions\RequestValidationException
+ */
+ protected function validators($object): bool
+ {
+ return $this->serviceTypeValidation->validate($object);
+
+ }
+
+
+ /**
+ * @param ServiceTypeObject $object
+ * @return bool
+ */
+ protected function criteria($object): bool
+ {
+ return true;
+ }
+
+}
\ No newline at end of file
diff --git a/app/Classes/Modules/ServiceTypes/Standards/Validators/ServiceTypeValidation.php b/app/Classes/Modules/ServiceTypes/Standards/Validators/ServiceTypeValidation.php
new file mode 100644
index 00000000..86946a39
--- /dev/null
+++ b/app/Classes/Modules/ServiceTypes/Standards/Validators/ServiceTypeValidation.php
@@ -0,0 +1,39 @@
+ $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/Http/Controllers/Announcements/ListAnnouncementsController.php b/app/Http/Controllers/Announcements/ListAnnouncementsController.php
index a69dff50..2dcee4d7 100644
--- a/app/Http/Controllers/Announcements/ListAnnouncementsController.php
+++ b/app/Http/Controllers/Announcements/ListAnnouncementsController.php
@@ -17,4 +17,4 @@ class ListAnnouncementsController
{
return $logic->execute($request);
}
-}
\ No newline at end of file
+}
diff --git a/app/Http/Controllers/Announcements/UpdateAnnouncementController.php b/app/Http/Controllers/Announcements/UpdateAnnouncementController.php
index 72431980..8d406632 100644
--- a/app/Http/Controllers/Announcements/UpdateAnnouncementController.php
+++ b/app/Http/Controllers/Announcements/UpdateAnnouncementController.php
@@ -18,4 +18,3 @@ class UpdateAnnouncementController
return $logic->execute($request);
}
}
-
diff --git a/app/Http/Controllers/Companies/AddNewMemberController.php b/app/Http/Controllers/Companies/AddNewMemberController.php
new file mode 100644
index 00000000..6307ac37
--- /dev/null
+++ b/app/Http/Controllers/Companies/AddNewMemberController.php
@@ -0,0 +1,22 @@
+execute($request);
+ }
+}
diff --git a/app/Http/Controllers/Segments/CreateSegmentController.php b/app/Http/Controllers/Segments/CreateSegmentController.php
index 4e748536..2950bdc3 100644
--- a/app/Http/Controllers/Segments/CreateSegmentController.php
+++ b/app/Http/Controllers/Segments/CreateSegmentController.php
@@ -16,5 +16,4 @@ class CreateSegmentController
public function create(Request $request, CreateSegmentLogic $logic): JsonResponse {
return $logic->execute($request);
}
-
}
\ No newline at end of file
diff --git a/app/Http/Controllers/Segments/FetchConstantController.php b/app/Http/Controllers/Segments/FetchConstantController.php
new file mode 100644
index 00000000..e3658802
--- /dev/null
+++ b/app/Http/Controllers/Segments/FetchConstantController.php
@@ -0,0 +1,20 @@
+execute($request);
+ }
+
+}
\ No newline at end of file
diff --git a/app/Http/Controllers/Segments/FetchSegmentController.php b/app/Http/Controllers/Segments/FetchSegmentController.php
new file mode 100644
index 00000000..91961689
--- /dev/null
+++ b/app/Http/Controllers/Segments/FetchSegmentController.php
@@ -0,0 +1,20 @@
+execute($request);
+ }
+
+}
\ No newline at end of file
diff --git a/app/Http/Controllers/Segments/ListSegmentsController.php b/app/Http/Controllers/Segments/ListSegmentsController.php
new file mode 100644
index 00000000..3dc14ebd
--- /dev/null
+++ b/app/Http/Controllers/Segments/ListSegmentsController.php
@@ -0,0 +1,20 @@
+execute($request);
+ }
+
+}
\ No newline at end of file
diff --git a/app/Http/Controllers/Segments/UpdateConstantController.php b/app/Http/Controllers/Segments/UpdateConstantController.php
new file mode 100644
index 00000000..47def571
--- /dev/null
+++ b/app/Http/Controllers/Segments/UpdateConstantController.php
@@ -0,0 +1,20 @@
+execute($request);
+ }
+
+}
\ No newline at end of file
diff --git a/app/Http/Controllers/Segments/UpdateCustomServiceConstantController.php b/app/Http/Controllers/Segments/UpdateCustomServiceConstantController.php
new file mode 100644
index 00000000..29bb6655
--- /dev/null
+++ b/app/Http/Controllers/Segments/UpdateCustomServiceConstantController.php
@@ -0,0 +1,20 @@
+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/Resources/ConstantResource.php b/app/Http/Resources/ConstantResource.php
new file mode 100644
index 00000000..c6bcf344
--- /dev/null
+++ b/app/Http/Resources/ConstantResource.php
@@ -0,0 +1,27 @@
+ $this->id,
+ 'name' => $this->name,
+ 'reference' => $this->reference,
+ 'detail' => (App()->make(ConvertsConstantDetailsToResource::class))->execute($this->resource)
+ ];
+ }
+}
diff --git a/app/Http/Resources/CustomServiceTypeResource.php b/app/Http/Resources/CustomServiceTypeResource.php
new file mode 100644
index 00000000..8ec26e47
--- /dev/null
+++ b/app/Http/Resources/CustomServiceTypeResource.php
@@ -0,0 +1,27 @@
+ $this->detail->id,
+ 'name' => ServiceType::where('id', $this->detail->id)->first()->name,
+ 'detail' => $this->detail,
+ 'configurations' => (App()->make(FetchesServiceConfigurations::class))->execute($this->resource, SegmentConstants::CUSTOM_SERVICE_TYPE)
+ ];
+ }
+}
diff --git a/resources/assets/vue/components/settings/elements/CurrenciesListComponent.vue b/resources/assets/vue/components/settings/elements/CurrenciesListComponent.vue
new file mode 100644
index 00000000..3554a8f2
--- /dev/null
+++ b/resources/assets/vue/components/settings/elements/CurrenciesListComponent.vue
@@ -0,0 +1,218 @@
+
+ A reset password link will send to your email account{{this.data?"Update":"Create"}} Announcement
+ Are you Sure?
+ Change Email Address
+ Edit Full Name
+ Payment Attempt Limit
+ Reset Password
+ Create Custom Segment
+ Create Service
+ Create Service
+ Are you Sure?
+ Are you Sure?
+ Add Admin Account
+