new: copy remaining company module classes from exhange2.0.

This commit is contained in:
weichien00
2021-07-08 03:31:33 +08:00
parent 8da79a2017
commit 10a7bd3421
32 changed files with 1391 additions and 0 deletions
@@ -0,0 +1,91 @@
<?php
namespace App\Classes\Modules\Companies\ControllersLogic;
use App\Classes\Modules\Companies\Services\UpdatesCompanyStatus;
use App\Classes\Modules\Documents\Services\RejectsDocument;
use App\Classes\Modules\Documents\Standards\Rules\CanApproveDocument;
use App\Classes\ValueObjects\Constants\ApprovalStatus;
use App\Http\Resources\DocumentResource;
use App\Classes\General\Abstracts\AbstractControllerLogic;
use App\Classes\Modules\Documents\Services\FetchesDocument;
use App\Classes\Modules\Documents\Services\ApprovesDocument;
use App\Models\Document;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
class ApproveIdentificationDocumentLogic extends AbstractControllerLogic
{
/**
* @return array
*/
protected function notification():array {
return [
'title' => '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));
}
}
@@ -0,0 +1,59 @@
<?php
namespace App\Classes\Modules\Companies\ControllersLogic;
use App\Classes\General\Abstracts\AbstractControllerLogic;
use App\Classes\Modules\Companies\Processors\AssignSegmentProcessor;
use App\Classes\Modules\Companies\Services\FetchesCompany;
use App\Http\Resources\CompanyResource;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
class AssignCompanyToSegmentLogic extends AbstractControllerLogic
{
/**
* @return array
*/
protected function notification():array {
return [
'title' => '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));
}
}
@@ -0,0 +1,53 @@
<?php
namespace App\Classes\Modules\Companies\ControllersLogic;
use App\Classes\General\Abstracts\AbstractControllerLogic;
use App\Classes\Modules\Companies\Processors\CreateCompanyProcessor;
use App\Classes\ValueObjects\Constants\ApprovalStatus;
use App\Classes\ValueObjects\Constants\BusinessType;
use App\Classes\ValueObjects\Constants\CompanyType;
use App\Http\Resources\CompanyResource;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
class CreateCompanyLogic extends AbstractControllerLogic
{
/**
* CreateCompanyLogic constructor.
* @param CreateCompanyProcessor $createCompanyProcessor
*/
public function __construct(CreateCompanyProcessor $createCompanyProcessor)
{
$this->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));
}
}
@@ -0,0 +1,84 @@
<?php
namespace App\Classes\Modules\Companies\ControllersLogic;
use App\Classes\General\Abstracts\AbstractControllerLogic;
use App\Classes\Modules\Companies\Services\FetchesCompany;
use App\Classes\Modules\Companies\Services\UpdatesCompanyStatus;
use App\Classes\Modules\Documents\DataTransferObjects\DocumentObject;
use App\Classes\Modules\Documents\Services\CreatesDocument;
use App\Classes\Modules\Documents\Services\CreatesFiles;
use App\Classes\ValueObjects\Constants\ApprovalStatus;
use App\Classes\ValueObjects\Constants\CompanyType;
use App\Classes\ValueObjects\Constants\DocumentType;
use App\Models\Company;
use App\Models\Document;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
class CreateIdentificationDocumentLogic extends AbstractControllerLogic
{
/**
* @return array
*/
protected function notification():array {
return [
'title' => '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([]);
}
}
@@ -0,0 +1,69 @@
<?php
namespace App\Classes\Modules\Companies\ControllersLogic;
use App\Classes\General\Abstracts\AbstractControllerLogic;
use App\Classes\Modules\Companies\Services\DeletesCompany;
use App\Classes\Modules\Companies\Services\FetchesCompany;
use App\Classes\Modules\Companies\Standards\Rules\CanDeleteCompany;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
class DeleteCompanyLogic extends AbstractControllerLogic
{
/**
* @return array
*/
protected function notification():array {
return [
'title' => '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([]);
}
}
@@ -0,0 +1,79 @@
<?php
namespace App\Classes\Modules\Companies\ControllersLogic;
use App\Classes\Exceptions\MalformedRequestException;
use App\Classes\Exceptions\RequestValidationException;
use App\Classes\General\Abstracts\AbstractControllerLogic;
use App\Classes\Modules\Bookings\Services\FetchesBookingQuotation;
use App\Classes\Modules\Bookings\Services\GeneratesBookingQuotation;
use App\Classes\Modules\Currencies\DataTransferObjects\CurrencyConversionObject;
use App\Classes\Modules\Currencies\Services\FetchesCurrency;
use App\Models\Company;
use App\Models\Currency;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
class FetchCompanyBookingQuotationLogic extends AbstractControllerLogic
{
/**
* @return array
*/
protected function notification():array {
return [
'title' => '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)]);
}
}
@@ -0,0 +1,61 @@
<?php
namespace App\Classes\Modules\Companies\ControllersLogic;
use App\Classes\General\Abstracts\AbstractControllerLogic;
use App\Classes\Modules\Companies\Services\FetchesCompany;
use App\Classes\Modules\Companies\Standards\Rules\CanFetchCompany;
use App\Http\Resources\CompanyResource;
use ErrorException;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
class FetchCompanyLogic extends AbstractControllerLogic
{
/**
* @return array
*/
protected function notification():array {
return [
'title' => '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));
}
}
@@ -0,0 +1,65 @@
<?php
namespace App\Classes\Modules\Companies\ControllersLogic;
use App\Classes\General\Abstracts\AbstractControllerLogic;
use App\Classes\Modules\Companies\Services\ListsCompanies;
use App\Classes\Modules\Companies\Standards\Rules\CanListCompanies;
use App\Http\Resources\CompanyResource;
use ErrorException;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
class ListCompaniesLogic extends AbstractControllerLogic
{
/**
* @return array
*/
protected function notification():array {
return [
'title' => '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));
}
}
@@ -0,0 +1,65 @@
<?php
namespace App\Classes\Modules\Companies\ControllersLogic;
use App\Classes\General\Abstracts\AbstractControllerLogic;
use App\Classes\Modules\Companies\Services\FetchesCompany;
use App\Classes\Modules\Companies\Services\RemovesCompanyFromSegment;
use App\Classes\Modules\Segments\Services\FetchesSegment;
use App\Http\Resources\CompanyResource;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
class RemoveCompanyFromSegmentLogic extends AbstractControllerLogic
{
/**
* @return array
*/
protected function notification():array {
return [
'title' => '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));
}
}
@@ -0,0 +1,78 @@
<?php
namespace App\Classes\Modules\Companies\ControllersLogic;
use App\Classes\General\Abstracts\AbstractControllerLogic;
use App\Classes\Modules\Companies\Services\UpdatesCompany;
use App\Classes\Modules\Companies\Services\FetchesCompany;
use App\Classes\Modules\Companies\Standards\Rules\CanUpdateCompany;
use App\Classes\Modules\Companies\DataTransferObjects\CompanyObject;
use App\Http\Resources\CompanyResource;
use ErrorException;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
class UpdateCompanyLogic extends AbstractControllerLogic
{
/**
* @return array
*/
protected function notification():array {
return [
'title' => '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());
}
}
}
@@ -0,0 +1,106 @@
<?php
namespace App\Classes\Modules\Companies\ControllersLogic;
use App\Classes\Exceptions\ResourceNotFoundException;
use App\Classes\General\Abstracts\AbstractControllerLogic;
use App\Classes\Modules\Segments\DataTransferObjects\ConstantObject;
use App\Classes\Modules\Segments\Services\CreatesConstant;
use App\Classes\Modules\Segments\Services\FetchesConstant;
use App\Classes\Modules\Segments\Services\FetchesSegment;
use App\Classes\Modules\Segments\Services\UpdatesConstant;
use App\Classes\Modules\Segments\Standards\Rules\CanCreateConstant;
use App\Classes\Modules\Segments\Standards\Rules\CanUpdateConstant;
use App\Classes\ValueObjects\Constants\SegmentConstants;
use App\Http\Resources\ConstantResource;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
class UpdateSupplierCurrenciesLogic extends AbstractControllerLogic
{
/**
* @return array
*/
protected function notification():array {
return [
'title' => '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([]);
}
}
@@ -0,0 +1,29 @@
<?php
namespace App\Classes\Modules\Companies\Services;
use App\Http\Resources\CurrencyResource;
use App\Models\Currency;
use Illuminate\Support\Collection;
class FetchesCompanyServices
{
public function getServices(Collection $services){
return $services->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())
];
});
}
}
@@ -0,0 +1,33 @@
<?php
namespace App\Classes\Modules\Companies\Services;
use App\Classes\General\Eloquent\AbstractListRecord;
use Illuminate\Database\Eloquent\Builder;
use App\Models\Company;
class ListsCompanies extends AbstractListRecord
{
/** @var Company */
private $repository;
/**
* ListsCompanies constructor.
* @param Company $repository
*/
public function __construct(Company $repository)
{
$this->repository = $repository;
}
/**
* @return Builder
*/
function getRepository(): Builder
{
return $this->repository->newQuery();
}
}
@@ -0,0 +1,43 @@
<?php
namespace App\Classes\Modules\Companies\Standards\Rules;
use App\Classes\General\Abstracts\AbstractRule;
use App\Classes\Modules\Companies\DataTransferObjects\CompanyObject;
class CanListCompanies extends AbstractRule
{
/**
* @return bool
*/
protected function authorized(): bool
{
// TODO Set Authorization rules
return true;
}
/**
* @param CompanyObject $object
* @return bool
*/
protected function validators($object): bool
{
return true;
}
/**
* @param CompanyObject $object
* @return bool
*/
protected function criteria($object): bool
{
return true;
}
}
@@ -0,0 +1,20 @@
<?php
namespace App\Http\Controllers\Companies;
use App\Classes\Modules\Companies\ControllersLogic\ApproveIdentificationDocumentLogic;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
class ApproveIdentificationDocumentController
{
/**
* @param Request $request
* @param ApproveIdentificationDocumentLogic $logic
* @return JsonResponse
*/
public function approve(Request $request, ApproveIdentificationDocumentLogic $logic): JsonResponse {
return $logic->execute($request);
}
}
@@ -0,0 +1,20 @@
<?php
namespace App\Http\Controllers\Companies;
use App\Classes\Modules\Companies\ControllersLogic\AssignCompanyToSegmentLogic;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
class AssignCompanyToSegmentController
{
/**
* @param Request $request
* @param AssignCompanyToSegmentLogic $logic
* @return JsonResponse
*/
public function assign(Request $request, AssignCompanyToSegmentLogic $logic): JsonResponse {
return $logic->execute($request);
}
}
@@ -0,0 +1,20 @@
<?php
namespace App\Http\Controllers\Companies;
use App\Classes\Modules\Companies\ControllersLogic\CreateCompanyLogic;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
class CreateCompanyController
{
/**
* @param Request $request
* @param CreateCompanyLogic $logic
* @return JsonResponse
*/
public function create(Request $request, CreateCompanyLogic $logic): JsonResponse {
return $logic->execute($request);
}
}
@@ -0,0 +1,20 @@
<?php
namespace App\Http\Controllers\Companies;
use App\Classes\Modules\Companies\ControllersLogic\CreateIdentificationDocumentLogic;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
class CreateIdentificationDocumentController
{
/**
* @param Request $request
* @param CreateIdentificationDocumentLogic $logic
* @return JsonResponse
*/
public function create(Request $request, CreateIdentificationDocumentLogic $logic): JsonResponse {
return $logic->execute($request);
}
}
@@ -0,0 +1,20 @@
<?php
namespace App\Http\Controllers\Companies;
use App\Classes\Modules\Companies\ControllersLogic\DeleteCompanyLogic;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
class DeleteCompanyController
{
/**
* @param Request $request
* @param DeleteCompanyLogic $logic
* @return JsonResponse
*/
public function destroy(Request $request, DeleteCompanyLogic $logic): JsonResponse {
return $logic->execute($request);
}
}
@@ -0,0 +1,20 @@
<?php
namespace App\Http\Controllers\Companies;
use App\Classes\Modules\Companies\ControllersLogic\FetchCompanyBookingQuotationLogic;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
class FetchCompanyBookingQuotationController
{
/**
* @param Request $request
* @param FetchCompanyBookingQuotationLogic $logic
* @return JsonResponse
*/
public function fetch(Request $request, FetchCompanyBookingQuotationLogic $logic): JsonResponse {
return $logic->execute($request);
}
}
@@ -0,0 +1,20 @@
<?php
namespace App\Http\Controllers\Companies;
use App\Classes\Modules\Companies\ControllersLogic\FetchCompanyLogic;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
class FetchCompanyController
{
/**
* @param Request $request
* @param FetchCompanyLogic $logic
* @return JsonResponse
*/
public function fetch(Request $request, FetchCompanyLogic $logic): JsonResponse {
return $logic->execute($request);
}
}
@@ -0,0 +1,20 @@
<?php
namespace App\Http\Controllers\Companies;
use App\Classes\Modules\Companies\ControllersLogic\ListCompaniesLogic;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
class ListCompaniesController
{
/**
* @param Request $request
* @param ListCompaniesLogic $logic
* @return JsonResponse
*/
public function list(Request $request, ListCompaniesLogic $logic): JsonResponse {
return $logic->execute($request);
}
}
@@ -0,0 +1,20 @@
<?php
namespace App\Http\Controllers\Companies;
use App\Classes\Modules\Companies\ControllersLogic\RemoveCompanyFromSegmentLogic;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
class RemoveCompanyFromSegmentController
{
/**
* @param Request $request
* @param RemoveCompanyFromSegmentLogic $logic
* @return JsonResponse
*/
public function detach(Request $request, RemoveCompanyFromSegmentLogic $logic): JsonResponse {
return $logic->execute($request);
}
}
@@ -0,0 +1,20 @@
<?php
namespace App\Http\Controllers\Companies;
use App\Classes\Modules\Companies\ControllersLogic\UpdateCompanyLogic;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
class UpdateCompanyController
{
/**
* @param Request $request
* @param UpdateCompanyLogic $logic
* @return JsonResponse
*/
public function update(Request $request, UpdateCompanyLogic $logic): JsonResponse {
return $logic->execute($request);
}
}
@@ -0,0 +1,20 @@
<?php
namespace App\Http\Controllers\Companies;
use App\Classes\Modules\Companies\ControllersLogic\UpdateSupplierCurrenciesLogic;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
class UpdateSupplierCurrenciesController
{
/**
* @param Request $request
* @param UpdateSupplierCurrenciesLogic $logic
* @return JsonResponse
*/
public function update(Request $request, UpdateSupplierCurrenciesLogic $logic): JsonResponse {
return $logic->execute($request);
}
}
+28
View File
@@ -0,0 +1,28 @@
<?php
namespace App\Http\Resources;
use Illuminate\Http\Resources\Json\JsonResource;
class AddressResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @param \Illuminate\Http\Request $request
* @return array
*/
public function toArray($request)
{
return [
'id' => $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
];
}
}
+31
View File
@@ -0,0 +1,31 @@
<?php
namespace App\Http\Resources;
use Illuminate\Http\Resources\Json\JsonResource;
class BankResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @param \Illuminate\Http\Request $request
* @return array
*/
public function toArray($request)
{
return [
'id' => $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,
];
}
}
+61
View File
@@ -0,0 +1,61 @@
<?php
namespace App\Http\Resources;
use App\Classes\Modules\Bookings\Services\CalculatesBookingFloatingAmount;
use App\Classes\Modules\Bookings\Services\CalculatesBookingOutstanding;
use App\Classes\Modules\Bookings\Services\CalculatesBookingPaidAmount;
use App\Classes\ValueObjects\Constants\ApprovalStatus;
use App\Classes\ValueObjects\Constants\TransactionType;
use App\Classes\ValueObjects\Constants\DocumentType;
use Carbon\Carbon;
use Illuminate\Http\Resources\Json\JsonResource;
class BookingResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @param \Illuminate\Http\Request $request
* @return array
* @throws \Illuminate\Contracts\Container\BindingResolutionException
*/
public function toArray($request)
{
return [
'id' => $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())
])
];
}
}
+52
View File
@@ -0,0 +1,52 @@
<?php
namespace App\Http\Resources;
use App\Classes\Modules\Companies\Services\FetchesCompanyServices;
use App\Classes\ValueObjects\Constants\BankAccountType;
use App\Classes\ValueObjects\Constants\BusinessType;
use App\Classes\ValueObjects\Constants\DocumentType;
use App\Classes\ValueObjects\Constants\SegmentConstants;
use App\Models\Currency;
use App\Models\SegmentConstant;
use Illuminate\Http\Resources\Json\JsonResource;
class CompanyResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @param \Illuminate\Http\Request $request
* @return array
*/
public function toArray($request)
{
return [
'id' => $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()) : [];
// })
];
}
}
+26
View File
@@ -0,0 +1,26 @@
<?php
namespace App\Http\Resources;
use Illuminate\Http\Resources\Json\JsonResource;
class ContactResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @param \Illuminate\Http\Request $request
* @return array
*/
public function toArray($request)
{
return [
'id' => $this->id,
//'country_code' => $this->country->phone_code,
'reference' => $this->reference,
'phone' => $this->phone,
'email' => $this->email,
'wechat_id' => $this->wechat_id,
];
}
}
+31
View File
@@ -0,0 +1,31 @@
<?php
namespace App\Http\Resources;
use App\Models\Company;
use App\Models\Document;
use Carbon\Carbon;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Http\Resources\Json\JsonResource;
class DocumentResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @param \Illuminate\Http\Request $request
* @return array
*/
public function toArray($request)
{
return [
'id' => $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')
];
}
}
+27
View File
@@ -0,0 +1,27 @@
<?php
namespace App\Http\Resources;
use App\Classes\ValueObjects\Constants\SegmentConstants;
use Illuminate\Http\Resources\Json\JsonResource;
class SegmentResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @param \Illuminate\Http\Request $request
* @return array
*/
public function toArray($request)
{
return [
'id' => $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))
];
}
}