'Update Company Details', 'message' => 'You have successfully updated the Company Details' ]; } /** @var CanUpdateCompany */ private $canUpdateCompany; /** @var UpdatesCompany */ private $updatesCompany; /** @var FetchesCompany */ private $fetchesCompany; /** @var UpdatesCompanyDebtor */ private $updatesCompanyDebtor; /** @var CanCreateAddress */ private $canCreateAddress; /** @var FetchesDistrict */ private $fetchesDistrict; /** @var UpsertsAddress */ private $upsertsAddress; /** @var UpdatesCompanyEInvoiceInfo */ private $updatesCompanyEInvoiceInfo; /** @var UpdatesCompanyModuleName */ private $updatesCompanyModuleName; /** @var FetchesDocument */ private $fetchesDocument; /** @var UpdatesDocumentReference */ private $updatesDocumentReference; /** @var CreatesDocument */ private $createsDocument; /** @var CreatesFiles */ private $createsFile; /** * UpdateCompanyDetailsLogic constructor. * @param CanUpdateCompany $canUpdateCompany * @param UpdatesCompany $updatesCompany * @param FetchesCompany $fetchesCompany * @param UpdatesCompanyDebtor $updatesCompanyDebtor * @param CanCreateAddress $canCreateAddress * @param FetchesDistrict $fetchesDistrict * @param UpsertsAddress $upsertsAddress * @param UpdatesCompanyEInvoiceInfo $updatesCompanyEInvoiceInfo; * @param FetchesDocument $fetchesDocument * @param UpdatesDocumentReference $updatesDocumentReference * @param CreatesDocument $createsDocument * @param CreatesFiles $createsFile */ public function __construct( CanUpdateCompany $canUpdateCompany, UpdatesCompany $updatesCompany, FetchesCompany $fetchesCompany, UpdatesCompanyDebtor $updatesCompanyDebtor, CanCreateAddress $canCreateAddress, FetchesDistrict $fetchesDistrict, UpsertsAddress $upsertsAddress, UpdatesCompanyEInvoiceInfo $updatesCompanyEInvoiceInfo, UpdatesCompanyModuleName $updatesCompanyModuleName, FetchesDocument $fetchesDocument, UpdatesDocumentReference $updatesDocumentReference, CreatesDocument $createsDocument, CreatesFiles $createsFile ) { $this->canUpdateCompany = $canUpdateCompany; $this->updatesCompany = $updatesCompany; $this->fetchesCompany = $fetchesCompany; $this->updatesCompanyDebtor = $updatesCompanyDebtor; $this->canCreateAddress = $canCreateAddress; $this->fetchesDistrict = $fetchesDistrict; $this->upsertsAddress = $upsertsAddress; $this->updatesCompanyEInvoiceInfo = $updatesCompanyEInvoiceInfo; $this->updatesCompanyModuleName = $updatesCompanyModuleName; $this->fetchesDocument = $fetchesDocument; $this->updatesDocumentReference = $updatesDocumentReference; $this->createsDocument = $createsDocument; $this->createsFile = $createsFile; } /** * @param Request $request * @return JsonResponse * @throws ErrorException */ public function logic(Request $request) : JsonResponse { $dto = new UpdateCompanyDetailsDTO($request->all()); $object = new CompanyObject($dto->name, $dto->reference, $dto->type); $this->canUpdateCompany->passes($object); $company = $this->fetchesCompany->execute(['id' => $request->route('id')]); $this->updatesCompanyModuleName->execute($company->companyModules()->first(), $object->getName()); //Update Name and Debtor, Type $company = $this->updatesCompany->execute($company, $object); if ($request->input('debtor') || $company->first()->debtor !== null) { $this->updatesCompanyDebtor->execute($company, $request->input('debtor')); } //Update EInvoice Related Info if($company->e_invoice){ $district = $this->fetchesDistrict->execute(['id' => $dto->districtId]); $addObj = new AddressObject($dto->streetOne, $dto->streetTwo, $district->country_id, $dto->stateId, $district->id, $dto->postCode, AddressType::E_INVOICE, ApprovalStatus::APPROVED, 'E-Invoice'); $this->canCreateAddress->passes($addObj); $this->upsertsAddress->execute($company->companyModules()->first(), $addObj, $dto->addressId); $this->updatesCompanyEInvoiceInfo->execute($company, $dto->tin, $dto->msicCode); } //Update Identification Card / SSM Registration if($dto->identificationId){ $document = $this->fetchesDocument->execute(['id' => $dto->identificationId]); $this->updatesDocumentReference->execute($document, $dto->identificationReference); } else{ if($dto->identificationReference){ $pathToFile = base_path('resources/assets/images/ssm_ic_placeholder.png'); $mimeType = mime_content_type($pathToFile); $fileContents = file_get_contents($pathToFile); $base64 = base64_encode($fileContents); $base64File = "data:$mimeType;base64,$base64"; $files = [$base64File]; /** @var Document $document */ $company = $this->fetchesCompany->execute(['id' => $dto->id]); $object = new DocumentObject($company->type === CompanyType::COMPANY_BUSINESS ? DocumentType::SSM_REGISTRATION : DocumentType::IDENTITY_CARD, $files, $dto->identificationReference, ApprovalStatus::PENDING_VERIFICATION, 'identifications'); $document = $this->createsDocument->execute($company, $object); $this->createsFile->execute($document, $object); } } return $this->resourceResponse(new CompanyResource($company)); } }