diff --git a/app/Classes/Modules/Companies/ControllersLogic/ApproveIdentificationDocumentLogic.php b/app/Classes/Modules/Companies/ControllersLogic/ApproveIdentificationDocumentLogic.php new file mode 100644 index 00000000..d5e052a9 --- /dev/null +++ b/app/Classes/Modules/Companies/ControllersLogic/ApproveIdentificationDocumentLogic.php @@ -0,0 +1,91 @@ + 'Approve Document', + 'message' => 'You have successfully approved the Document' + ]; + } + + /** @var CanApproveDocument*/ + private $canApproveDocument; + + /** @var ApprovesDocument */ + private $approvesDocument; + + /** @var RejectsDocument */ + private $rejectsDocument; + + /** @var FetchesDocument */ + private $fetchesDocument; + + /** @var UpdatesCompanyStatus */ + private $updatesCompanyStatus; + + /** + * ApproveIdentificationDocumentLogic constructor. + * @param CanApproveDocument $canApproveDocument + * @param ApprovesDocument $approvesDocument + * @param RejectsDocument $rejectsDocument + * @param FetchesDocument $fetchesDocument + * @param UpdatesCompanyStatus $updatesCompanyStatus + */ + public function __construct(CanApproveDocument $canApproveDocument, ApprovesDocument $approvesDocument, RejectsDocument $rejectsDocument, FetchesDocument $fetchesDocument, UpdatesCompanyStatus $updatesCompanyStatus) + { + $this->canApproveDocument = $canApproveDocument; + $this->approvesDocument = $approvesDocument; + $this->rejectsDocument = $rejectsDocument; + $this->fetchesDocument = $fetchesDocument; + $this->updatesCompanyStatus = $updatesCompanyStatus; + } + + /** + * @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 + { + + $status = $request->route('status'); + + /** @var Document $document */ + $document = $this->fetchesDocument->execute(['id' => $request->route('document_id')]); + + $this->canApproveDocument->passes(); + + $document = $status === 'approve' ? $this->approvesDocument->execute($document) : $this->rejectsDocument->execute($document); + + $this->updatesCompanyStatus->execute($document->owner, $status === 'approve' ? ApprovalStatus::APPROVED : ApprovalStatus::REJECTED); + + return $this->resourceResponse(new DocumentResource($document)); + + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/Companies/ControllersLogic/AssignCompanyToSegmentLogic.php b/app/Classes/Modules/Companies/ControllersLogic/AssignCompanyToSegmentLogic.php new file mode 100644 index 00000000..17a6c900 --- /dev/null +++ b/app/Classes/Modules/Companies/ControllersLogic/AssignCompanyToSegmentLogic.php @@ -0,0 +1,59 @@ + 'Assign Company To Segment', + 'message' => 'You have successfully assigned Company to segment' + ]; + } + + /** @var FetchesCompany */ + private $fetchesCompany; + + /** @var AssignSegmentProcessor */ + private $assignCompanyToSegmentProcessor; + + /** + * AssignCompanyToSegmentLogic constructor. + * @param FetchesCompany $fetchesCompany + * @param AssignSegmentProcessor $assignCompanyToSegmentProcessor + */ + public function __construct(FetchesCompany $fetchesCompany, AssignSegmentProcessor $assignCompanyToSegmentProcessor) + { + $this->fetchesCompany = $fetchesCompany; + $this->assignCompanyToSegmentProcessor = $assignCompanyToSegmentProcessor; + } + + /** + * @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 + { + + $company = $this->fetchesCompany->execute(['id' => $request->route('id')]); + + $this->assignCompanyToSegmentProcessor->execute($company, $request->input('segment_id')); + + return $this->resourceResponse(new CompanyResource($company)); + } +} \ No newline at end of file diff --git a/app/Classes/Modules/Companies/ControllersLogic/CreateCompanyLogic.php b/app/Classes/Modules/Companies/ControllersLogic/CreateCompanyLogic.php new file mode 100644 index 00000000..019fe833 --- /dev/null +++ b/app/Classes/Modules/Companies/ControllersLogic/CreateCompanyLogic.php @@ -0,0 +1,53 @@ +createCompanyProcessor = $createCompanyProcessor; + } + + /** + * @return array + */ + protected function notification():array { + return [ + 'title' => 'Created Company', + 'message' => 'You have successfully created a new Company' + ]; + } + + /** @var CreateCompanyProcessor */ + private $createCompanyProcessor; + + + /** + * @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 + { + $company = $this->createCompanyProcessor->execute($request, BusinessType::CURRENCY_VENDOR, CompanyType::COMPANY_BUSINESS, ApprovalStatus::APPROVED); + return $this->resourceResponse(new CompanyResource($company)); + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/Companies/ControllersLogic/CreateIdentificationDocumentLogic.php b/app/Classes/Modules/Companies/ControllersLogic/CreateIdentificationDocumentLogic.php new file mode 100644 index 00000000..bbf91ea7 --- /dev/null +++ b/app/Classes/Modules/Companies/ControllersLogic/CreateIdentificationDocumentLogic.php @@ -0,0 +1,84 @@ + 'Created Identification Document', + 'message' => 'You have successfully created a new identification document' + ]; + } + + /** @var FetchesCompany */ + private $fetchesCompany; + + /** @var CreatesDocument */ + private $createsDocument; + + /** @var CreatesFiles */ + private $createsFile; + + /** @var UpdatesCompanyStatus */ + private $updatesCompanyStatus; + + + /** + * CreateIdentificationDocumentLogic constructor. + * @param FetchesCompany $fetchesCompany + * @param CreatesDocument $createsDocument + * @param CreatesFiles $createsFile + * @param UpdatesCompanyStatus $updatesCompanyStatus + */ + public function __construct(FetchesCompany $fetchesCompany, CreatesDocument $createsDocument, CreatesFiles $createsFile, UpdatesCompanyStatus $updatesCompanyStatus) + { + $this->fetchesCompany = $fetchesCompany; + $this->createsDocument = $createsDocument; + $this->createsFile = $createsFile; + $this->updatesCompanyStatus = $updatesCompanyStatus; + } + + /** + * @param Request $request + * @return JsonResponse + * @throws \App\Classes\Exceptions\MalformedRequestException + */ + public function logic(Request $request) : JsonResponse + { + + /** @var Company $company */ + $company = $this->fetchesCompany->execute(['id' => $request->route('id')]); + $object = new DocumentObject($company->type === CompanyType::COMPANY_BUSINESS ? + DocumentType::SSM_REGISTRATION : DocumentType::IDENTITY_CARD, $request->input('files'), + $request->input('identification_no'), ApprovalStatus::PENDING_VERIFICATION, 'identifications'); + + /** @var Document $document */ + $document = $this->createsDocument->execute($company, $object); + $this->createsFile->execute($document, $object); + + $this->updatesCompanyStatus->execute($company, ApprovalStatus::PENDING_VERIFICATION); + + return $this->response([]); + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/Companies/ControllersLogic/DeleteCompanyLogic.php b/app/Classes/Modules/Companies/ControllersLogic/DeleteCompanyLogic.php new file mode 100644 index 00000000..ac5dabb0 --- /dev/null +++ b/app/Classes/Modules/Companies/ControllersLogic/DeleteCompanyLogic.php @@ -0,0 +1,69 @@ + 'Deleted Company', + 'message' => 'You have successfully deleted a Company' + ]; + } + + + /** @var CanDeleteCompany */ + private $canDeleteCompany; + + /** @var DeletesCompany */ + private $deletesCompany; + + /** @var FetchesCompany */ + private $fetchesCompany; + + /** + * DeleteCompanyLogic constructor. + * @param CanDeleteCompany $canDeleteCompany + * @param DeletesCompany $deletesCompany + * @param FetchesCompany $fetchesCompany + */ + public function __construct(CanDeleteCompany $canDeleteCompany, DeletesCompany $deletesCompany, FetchesCompany $fetchesCompany) + { + $this->canDeleteCompany = $canDeleteCompany; + $this->deletesCompany = $deletesCompany; + $this->fetchesCompany = $fetchesCompany; + } + + + /** + * @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->canDeleteCompany->passes(); + + $query = $this->fetchesCompany->execute(['id' => $request->route('id')]); + + $this->deletesCompany->execute($query); + + return $this->response([]); + + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/Companies/ControllersLogic/FetchCompanyBookingQuotationLogic.php b/app/Classes/Modules/Companies/ControllersLogic/FetchCompanyBookingQuotationLogic.php new file mode 100644 index 00000000..37225631 --- /dev/null +++ b/app/Classes/Modules/Companies/ControllersLogic/FetchCompanyBookingQuotationLogic.php @@ -0,0 +1,79 @@ + 'Fetch Currency Conversion', + 'message' => 'You have successfully retrieved a currency conversion' + ]; + } + + + /** @var FetchesBookingQuotation */ + private $fetchBookingQuotation; + + /** @var GeneratesBookingQuotation */ + private $generatesBookingQuotation; + + /** @var FetchesCurrency */ + private $fetchesCurrency; + + /** + * FetchCompanyBookingQuotationLogic constructor. + * @param FetchesBookingQuotation $fetchBookingQuotation + * @param GeneratesBookingQuotation $generatesBookingQuotation + * @param FetchesCurrency $fetchesCurrency + */ + public function __construct(FetchesBookingQuotation $fetchBookingQuotation, GeneratesBookingQuotation $generatesBookingQuotation, FetchesCurrency $fetchesCurrency) + { + $this->fetchBookingQuotation = $fetchBookingQuotation; + $this->generatesBookingQuotation = $generatesBookingQuotation; + $this->fetchesCurrency = $fetchesCurrency; + } + + /** + * @param Request $request + * @return JsonResponse + * @throws MalformedRequestException + * @throws RequestValidationException + */ + public function logic(Request $request) : JsonResponse + { + /** @var Company $company */ + $company = Company::find($request->route('id')); + + $conversionObject = new CurrencyConversionObject(floatval(str_replace(',', '', $request->input('amount'))), $request->input('currency_id'), $request->input('service_id'), $request->input('type')); + + $calculationObject = $this->fetchBookingQuotation->execute($company, $conversionObject); + + /** @var Currency $currency */ + $currency = $this->fetchesCurrency->execute(['id' => $conversionObject->getCurrencyId()]); + if($calculationObject->getConvertibleTotal() < $calculationObject->getConfigurations()->getMinLimit()) throw new RequestValidationException('Your transfer is below the minimum amount allowed of '.$calculationObject->getConfigurations()->getMinLimit().' '.$currency->short_code); + + //TODO add po limit validation + return $this->response(['data' => $this->generatesBookingQuotation->execute($calculationObject)]); + + } + + +} \ No newline at end of file diff --git a/app/Classes/Modules/Companies/ControllersLogic/FetchCompanyLogic.php b/app/Classes/Modules/Companies/ControllersLogic/FetchCompanyLogic.php new file mode 100644 index 00000000..5406d682 --- /dev/null +++ b/app/Classes/Modules/Companies/ControllersLogic/FetchCompanyLogic.php @@ -0,0 +1,61 @@ + 'Retrieved Company', + 'message' => 'You have successfully retrieved a Company' + ]; + } + + /** @var CanFetchCompany */ + private $canFetchCompany; + + /** @var FetchesCompany */ + private $fetchesCompany; + + /** + * FetchCompanyControllersLogic constructor. + * @param CanFetchCompany $canFetchCompany + * @param FetchesCompany $fetchesCompany + */ + public function __construct(CanFetchCompany $canFetchCompany, FetchesCompany $fetchesCompany) + { + $this->canFetchCompany = $canFetchCompany; + $this->fetchesCompany = $fetchesCompany; + } + + + /** + * @param Request $request + * @return JsonResponse + * @throws \App\Classes\Exceptions\AccessForbiddenException + * @throws \App\Classes\Exceptions\RequestValidationException + */ + public function logic(Request $request) : JsonResponse + { + $this->canFetchCompany->passes(); + + $query = $this->fetchesCompany->execute(['id' => $request->route('id'), 'with_bookings' => true]); + + return $this->resourceResponse(new CompanyResource($query)); + + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/Companies/ControllersLogic/ListCompaniesLogic.php b/app/Classes/Modules/Companies/ControllersLogic/ListCompaniesLogic.php new file mode 100644 index 00000000..e060ddc7 --- /dev/null +++ b/app/Classes/Modules/Companies/ControllersLogic/ListCompaniesLogic.php @@ -0,0 +1,65 @@ + 'Retrieved Companies', + 'message' => 'You have successfully retrieved a list of Companies' + ]; + } + + /** @var CanListCompanies */ + private $canListCompanies; + + /** @var ListsCompanies */ + private $listsCompanies; + + /** + * ListCompaniesControllersLogic constructor. + * @param CanListCompanies $canListCompanies + * @param ListsCompanies $listsCompanies + */ + public function __construct(CanListCompanies $canListCompanies, ListsCompanies $listsCompanies) + { + $this->canListCompanies = $canListCompanies; + $this->listsCompanies = $listsCompanies; + } + + + /** + * @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->canListCompanies->passes(); + + logger("llogic"); + + logger($request->input('filters')); + + $query = $this->listsCompanies->execute($this->listsCompanies->deserializeFilters($request->input('filters'))); + return $this->collectionResponse(CompanyResource::collection($query)); + + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/Companies/ControllersLogic/RemoveCompanyFromSegmentLogic.php b/app/Classes/Modules/Companies/ControllersLogic/RemoveCompanyFromSegmentLogic.php new file mode 100644 index 00000000..10623311 --- /dev/null +++ b/app/Classes/Modules/Companies/ControllersLogic/RemoveCompanyFromSegmentLogic.php @@ -0,0 +1,65 @@ + 'Detach Company From Segment', + 'message' => 'You have successfully detached Company from segment' + ]; + } + + /** @var FetchesCompany */ + private $fetchesCompany; + + /** @var FetchesSegment */ + private $fetchesSegment; + + /** @var RemovesCompanyFromSegment */ + private $removesCompanyFromSegment; + + /** + * RemoveCompanyFromSegmentLogic constructor. + * @param FetchesCompany $fetchesCompany + * @param FetchesSegment $fetchesSegment + * @param RemovesCompanyFromSegment $removesCompanyFromSegment + */ + public function __construct(FetchesCompany $fetchesCompany, FetchesSegment $fetchesSegment, RemovesCompanyFromSegment $removesCompanyFromSegment) + { + $this->fetchesCompany = $fetchesCompany; + $this->fetchesSegment = $fetchesSegment; + $this->removesCompanyFromSegment = $removesCompanyFromSegment; + } + + /** + * @param Request $request + * @return JsonResponse + * @throws \App\Classes\Exceptions\MalformedRequestException + */ + public function logic(Request $request) : JsonResponse + { + + $company = $this->fetchesCompany->execute(['id' => $request->route('id')]); + + $segment = $this->fetchesSegment->execute(['id' => $request->route('segment_id')]); + + $this->removesCompanyFromSegment->execute($company, $segment); + + return $this->resourceResponse(new CompanyResource($company)); + } +} \ No newline at end of file diff --git a/app/Classes/Modules/Companies/ControllersLogic/UpdateCompanyLogic.php b/app/Classes/Modules/Companies/ControllersLogic/UpdateCompanyLogic.php new file mode 100644 index 00000000..c435dab4 --- /dev/null +++ b/app/Classes/Modules/Companies/ControllersLogic/UpdateCompanyLogic.php @@ -0,0 +1,78 @@ + 'Updated Company', + 'message' => 'You have successfully updated the Company' + ]; + } + + /** @var CanUpdateCompany */ + private $canUpdateCompany; + + /** @var UpdatesCompany */ + private $updatesCompany; + + /** @var FetchesCompany */ + private $fetchesCompany; + + /** + * UpdateCompanyControllersLogic constructor. + * @param CanUpdateCompany $canUpdateCompany + * @param UpdatesCompany $updatesCompany + * @param FetchesCompany $fetchesCompany + */ + public function __construct(CanUpdateCompany $canUpdateCompany, UpdatesCompany $updatesCompany, FetchesCompany $fetchesCompany) + { + $this->canUpdateCompany = $canUpdateCompany; + $this->updatesCompany = $updatesCompany; + $this->fetchesCompany = $fetchesCompany; + } + + + /** + * @param Request $request + * @return JsonResponse + * @throws ErrorException + */ + public function logic(Request $request) : JsonResponse + { + try { + + $object = new CompanyObject($request->input('reference_no'), $request->input('name'), $request->input('type')); + + $this->canUpdateCompany->passes($object); + + $query = $this->fetchesCompany->execute(['id' => $request->route('id')]); + + $query = $this->updatesCompany->execute($query, $object); + + return $this->resourceResponse(new CompanyResource($query)); + + + } catch (\Exception $exception){ + throw new ErrorException($exception->getMessage(), $exception->getCode()); + } + + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/Companies/ControllersLogic/UpdateSupplierCurrenciesLogic.php b/app/Classes/Modules/Companies/ControllersLogic/UpdateSupplierCurrenciesLogic.php new file mode 100644 index 00000000..a42cc78f --- /dev/null +++ b/app/Classes/Modules/Companies/ControllersLogic/UpdateSupplierCurrenciesLogic.php @@ -0,0 +1,106 @@ + 'Updated Supplier', + 'message' => 'You have successfully updated the Supplier' + ]; + } + + /** @var CanCreateConstant */ + private $canCreateConstant; + + /** @var CanUpdateConstant */ + private $canUpdateConstant; + + /** @var FetchesSegment */ + private $fetchesSegment; + + /** @var FetchesConstant */ + private $fetchesConstant; + + /** @var UpdatesConstant */ + private $updatesConstant; + + /** @var CreatesConstant */ + private $createsConstant; + + + /** + * UpdateSupplierCurrenciesLogic constructor. + * @param CanCreateConstant $canCreateConstant + * @param CanUpdateConstant $canUpdateConstant + * @param FetchesSegment $fetchesSegment + * @param FetchesConstant $fetchesConstant + * @param UpdatesConstant $updatesConstant + * @param CreatesConstant $createsConstant + */ + public function __construct(CanCreateConstant $canCreateConstant, CanUpdateConstant $canUpdateConstant, FetchesSegment $fetchesSegment, FetchesConstant $fetchesConstant, UpdatesConstant $updatesConstant, CreatesConstant $createsConstant) + { + $this->canCreateConstant = $canCreateConstant; + $this->canUpdateConstant = $canUpdateConstant; + $this->fetchesSegment = $fetchesSegment; + $this->fetchesConstant = $fetchesConstant; + $this->updatesConstant = $updatesConstant; + $this->createsConstant = $createsConstant; + } + + /** + * @param Request $request + * @return JsonResponse + * @throws ResourceNotFoundException + * @throws \App\Classes\Exceptions\AccessForbiddenException + * @throws \App\Classes\Exceptions\MalformedRequestException + * @throws \App\Classes\Exceptions\RequestValidationException + */ + public function logic(Request $request) : JsonResponse + { + + $supplierId = $request->route('id'); + + $object = new ConstantObject('Supplier\'s Currencies',SegmentConstants::SUPPLIER_CURRENCIES, + [ + 'id' => $supplierId, 'currencies' => $request->input('currencies') + ] + ); + + try { + + $constant = $this->fetchesConstant->execute(['supplier_currencies' => $supplierId]); + $this->canUpdateConstant->passes($object); + $this->updatesConstant->execute($constant, $object); + + } catch (ResourceNotFoundException $exception){ + $this->canCreateConstant->passes($object); + $segment = $this->fetchesSegment->execute(['type' => SegmentConstants::STANDARD_SEGMENT]); + $this->createsConstant->execute($segment, $object); + } + + return $this->response([]); + + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/Companies/Services/FetchesCompanyServices.php b/app/Classes/Modules/Companies/Services/FetchesCompanyServices.php new file mode 100644 index 00000000..d78fca75 --- /dev/null +++ b/app/Classes/Modules/Companies/Services/FetchesCompanyServices.php @@ -0,0 +1,29 @@ +map(function($service){ + $currencies = collect($service->getConfigurations()->detail->currencies)->pluck('id'); + if(!empty($service->getCustomOptions())){ + $currencies = $currencies->merge(collect($service->getCustomOptions())->flatMap(function($configurations){ + return collect($configurations->getConfigurationValue('currencies'))->pluck('id'); + })); + } + + return [ + 'id' => $service->getService()->id, + 'name' => $service->getService()->name, + 'currencies' => CurrencyResource::collection(Currency::whereIn('id', $currencies->filter()->unique()->toArray())->get()) + ]; + }); + } +} \ No newline at end of file diff --git a/app/Classes/Modules/Companies/Services/ListsCompanies.php b/app/Classes/Modules/Companies/Services/ListsCompanies.php new file mode 100644 index 00000000..179704e7 --- /dev/null +++ b/app/Classes/Modules/Companies/Services/ListsCompanies.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/Companies/Standards/Rules/CanListCompanies.php b/app/Classes/Modules/Companies/Standards/Rules/CanListCompanies.php new file mode 100644 index 00000000..35cd974c --- /dev/null +++ b/app/Classes/Modules/Companies/Standards/Rules/CanListCompanies.php @@ -0,0 +1,43 @@ +execute($request); + } + +} \ No newline at end of file diff --git a/app/Http/Controllers/Companies/AssignCompanyToSegmentController.php b/app/Http/Controllers/Companies/AssignCompanyToSegmentController.php new file mode 100644 index 00000000..a5981771 --- /dev/null +++ b/app/Http/Controllers/Companies/AssignCompanyToSegmentController.php @@ -0,0 +1,20 @@ +execute($request); + } + +} \ No newline at end of file diff --git a/app/Http/Controllers/Companies/CreateCompanyController.php b/app/Http/Controllers/Companies/CreateCompanyController.php new file mode 100644 index 00000000..2ed56acc --- /dev/null +++ b/app/Http/Controllers/Companies/CreateCompanyController.php @@ -0,0 +1,20 @@ +execute($request); + } + +} \ No newline at end of file diff --git a/app/Http/Controllers/Companies/CreateIdentificationDocumentController.php b/app/Http/Controllers/Companies/CreateIdentificationDocumentController.php new file mode 100644 index 00000000..dd8ca321 --- /dev/null +++ b/app/Http/Controllers/Companies/CreateIdentificationDocumentController.php @@ -0,0 +1,20 @@ +execute($request); + } + +} \ No newline at end of file diff --git a/app/Http/Controllers/Companies/DeleteCompanyController.php b/app/Http/Controllers/Companies/DeleteCompanyController.php new file mode 100644 index 00000000..f59a8eaa --- /dev/null +++ b/app/Http/Controllers/Companies/DeleteCompanyController.php @@ -0,0 +1,20 @@ +execute($request); + } + +} \ No newline at end of file diff --git a/app/Http/Controllers/Companies/FetchCompanyBookingQuotationController.php b/app/Http/Controllers/Companies/FetchCompanyBookingQuotationController.php new file mode 100644 index 00000000..e2fd37b4 --- /dev/null +++ b/app/Http/Controllers/Companies/FetchCompanyBookingQuotationController.php @@ -0,0 +1,20 @@ +execute($request); + } + +} \ No newline at end of file diff --git a/app/Http/Controllers/Companies/FetchCompanyController.php b/app/Http/Controllers/Companies/FetchCompanyController.php new file mode 100644 index 00000000..cc4a9a02 --- /dev/null +++ b/app/Http/Controllers/Companies/FetchCompanyController.php @@ -0,0 +1,20 @@ +execute($request); + } + +} \ No newline at end of file diff --git a/app/Http/Controllers/Companies/ListCompaniesController.php b/app/Http/Controllers/Companies/ListCompaniesController.php new file mode 100644 index 00000000..25b8ae76 --- /dev/null +++ b/app/Http/Controllers/Companies/ListCompaniesController.php @@ -0,0 +1,20 @@ +execute($request); + } + +} \ No newline at end of file diff --git a/app/Http/Controllers/Companies/RemoveCompanyFromSegmentController.php b/app/Http/Controllers/Companies/RemoveCompanyFromSegmentController.php new file mode 100644 index 00000000..604f8ee6 --- /dev/null +++ b/app/Http/Controllers/Companies/RemoveCompanyFromSegmentController.php @@ -0,0 +1,20 @@ +execute($request); + } + +} \ No newline at end of file diff --git a/app/Http/Controllers/Companies/UpdateCompanyController.php b/app/Http/Controllers/Companies/UpdateCompanyController.php new file mode 100644 index 00000000..3ff239fb --- /dev/null +++ b/app/Http/Controllers/Companies/UpdateCompanyController.php @@ -0,0 +1,20 @@ +execute($request); + } + +} \ No newline at end of file diff --git a/app/Http/Controllers/Companies/UpdateSupplierCurrenciesController.php b/app/Http/Controllers/Companies/UpdateSupplierCurrenciesController.php new file mode 100644 index 00000000..f58f3997 --- /dev/null +++ b/app/Http/Controllers/Companies/UpdateSupplierCurrenciesController.php @@ -0,0 +1,20 @@ +execute($request); + } + +} \ No newline at end of file diff --git a/app/Http/Resources/AddressResource.php b/app/Http/Resources/AddressResource.php new file mode 100644 index 00000000..4e545092 --- /dev/null +++ b/app/Http/Resources/AddressResource.php @@ -0,0 +1,28 @@ + $this->id, + 'street_one' => $this->street_one, + 'street_two' => $this->street_two, + 'district' => $this->district, + 'state' => $this->state, + 'post_code' => $this->postcode, + 'country' => $this->country, + 'billing' => (int) $this->billing + ]; + } +} diff --git a/app/Http/Resources/BankResource.php b/app/Http/Resources/BankResource.php new file mode 100644 index 00000000..35fec923 --- /dev/null +++ b/app/Http/Resources/BankResource.php @@ -0,0 +1,31 @@ + $this->id, + 'company_business_type' => $this->company->business_type, + 'type' => $this->type, + 'reference' => $this->reference, + 'bank_name' => $this->bank_name, + 'bank_branch' => $this->bank_branch, + 'holder_name' => $this->holder_name, + 'account_no' => $this->account_no, + 'country_id' => $this->country_id, + 'default' => $this->default, + 'status' => $this->status, + ]; + } +} diff --git a/app/Http/Resources/BookingResource.php b/app/Http/Resources/BookingResource.php new file mode 100644 index 00000000..b91bf7f8 --- /dev/null +++ b/app/Http/Resources/BookingResource.php @@ -0,0 +1,61 @@ + $this->id, + 'company' => new CompanyResource($this->company), + 'bank' => new BankResource($this->bank), + 'service' => new ServiceTypeResource($this->service), + 'marking' => $this->marking, + 'amount' => $this->fix_amount, + 'floating_amount' => floatval((App()->make(CalculatesBookingFloatingAmount::class))->execute($this->resource, $this->fix_currency_id)), + 'paid_amount' => floatval((App()->make(CalculatesBookingPaidAmount::class))->execute($this->resource, $this->fix_currency_id)), + 'outstanding_amount' => floatval((App()->make(CalculatesBookingOutstanding::class))->execute($this->resource)), + 'fixed_currency' => new CurrencyResource($this->fixedCurrency), + 'convertible_currency' => new CurrencyResource($this->convertibleCurrency), + 'conversion_currency' => new CurrencyResource($this->conversionCurrency), + 'documents' => [ + 'purchase_order' => new DocumentResource($this->documents()->where('document_type', DocumentType::PURCHASE_ORDER)->first()), + 'delivery_order' => new DocumentResource($this->documents()->where('document_type', DocumentType::DELIVER_ORDER)->first()), + 'invoice' => new DocumentResource($this->documents()->where('document_type', DocumentType::INVOICE)->first()), + 'supplier_delivery_order' => new DocumentResource($this->documents()->where('document_type', DocumentType::SUPPLIER_DELIVER_ORDER)->first()), + ], + 'status' => $this->status, + 'created_at' => Carbon::parse($this->created_at)->format('d-m-Y'), + $this->mergeWhen($this->relationLoaded('transactions'), [ + 'purchase_order' => new TransactionResource($this->transactions()->where('type', TransactionType::PURCHASE_ORDER)->first()), + 'payment_attempts' => TransactionResource::collection($this->transactions()->payments()->where('status', ApprovalStatus::PENDING_SUBMISSION)->whereDate('expires_on', '>=', Carbon::now())->get()), + 'expired_payment_attempts' => TransactionResource::collection($this->transactions()->payments()->where('status', ApprovalStatus::PENDING_SUBMISSION)->whereDate('expires_on', '<', Carbon::now())->get()), + 'payment_history' => TransactionResource::collection($this->transactions()->where(function($query){ + $query->where(function($query){ + $query->payments()->whereIn('status', [ApprovalStatus::APPROVED, ApprovalStatus::PENDING_VERIFICATION, ApprovalStatus::REJECTED]); + })->orWhere(function($query){ + $query->where('type', TransactionType::BILL)->whereIn('status', [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED]); + }); + })->latest()->get()) + ]) + ]; + } +} diff --git a/app/Http/Resources/CompanyResource.php b/app/Http/Resources/CompanyResource.php new file mode 100644 index 00000000..726e1c36 --- /dev/null +++ b/app/Http/Resources/CompanyResource.php @@ -0,0 +1,52 @@ + $this->id, + 'name' => $this->name, + 'reference' => $this->reference, + 'type' => (int) $this->type, + 'business_type' => (int) $this->business_type, + 'status' => (int) $this->status, + 'contact' => new ContactResource ($this->when($this->has('contacts'), $this->contacts->first())), + 'address' => new AddressResource($this->when($this->has('addresses'), $this->addresses->where('billing', true)->first())), + // 'employee' => new UserResource($this->employees->first()), + // 'identification' => new DocumentResource($this->documents->whereIn('document_type', DocumentType::IDENTIFICATION_DOCUMENTS)->first()), + // 'bookings' => BookingResource::collection($this->whenLoaded('bookings', $this->bookings()->orderBy('id', 'DESC')->get(), [])), + // 'personal_banks' => BankResource::collection($this->banks->where('type', BankAccountType::PERSONAL)), + // 'recipient_banks' => [ + // 'accounts' => BankResource::collection($this->banks->where('type', BankAccountType::EXTERNAL)), + // 'default' => new BankResource($this->banks->where('type', BankAccountType::EXTERNAL)->where('default', true)->first()) + // ], + // 'segments' => SegmentResource::collection($this->segments), + // 'services' => (new FetchesCompanyServices())->getServices($this->servicesConfigurations()), + // 'currencies' => $this->when($this->business_type === BusinessType::CURRENCY_VENDOR, function(){ + // $segment = SegmentConstant::where('reference', SegmentConstants::SUPPLIER_CURRENCIES)->where('detail->id', $this->id)->first(); + // return $segment ? CurrencyResource::collection(Currency::whereIn('id', $segment->detail->currencies)->get()) : []; + // }) + + + ]; + + } +} diff --git a/app/Http/Resources/ContactResource.php b/app/Http/Resources/ContactResource.php new file mode 100644 index 00000000..74a3e4c3 --- /dev/null +++ b/app/Http/Resources/ContactResource.php @@ -0,0 +1,26 @@ + $this->id, + //'country_code' => $this->country->phone_code, + 'reference' => $this->reference, + 'phone' => $this->phone, + 'email' => $this->email, + 'wechat_id' => $this->wechat_id, + ]; + } +} diff --git a/app/Http/Resources/DocumentResource.php b/app/Http/Resources/DocumentResource.php new file mode 100644 index 00000000..2595ed55 --- /dev/null +++ b/app/Http/Resources/DocumentResource.php @@ -0,0 +1,31 @@ + $this->id, + 'reference' => $this->reference, + 'status' => (int) $this->status, + 'document_type' => $this->document_type, + 'owner' => new CompanyResource($this->whenLoaded('owner')), + 'files' => FileResource::collection($this->files), + 'created_at' => Carbon::parse($this->created_at)->format('d-m-Y h:i:s A') + ]; + } +} diff --git a/app/Http/Resources/SegmentResource.php b/app/Http/Resources/SegmentResource.php new file mode 100644 index 00000000..58118e08 --- /dev/null +++ b/app/Http/Resources/SegmentResource.php @@ -0,0 +1,27 @@ + $this->id, + 'name' => $this->name, + 'time_limit' => $this->when($this->whereHas('constants', function($query){ + $query->where('reference', SegmentConstants::PAYMENT_ATTEMPT_DURATION_LIMIT); + }), $this->constants->where('reference', SegmentConstants::PAYMENT_ATTEMPT_DURATION_LIMIT)->first()), + 'services' => CustomServiceTypeResource::collection($this->constants->where('reference', SegmentConstants::CUSTOM_SERVICE_TYPE)) + ]; + } +}