'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 UpdatesAddressMetadata */ private $updatesAddressMetadata; /** * UpdateCompanyDetailsLogic constructor. * @param CanUpdateCompany $canUpdateCompany * @param UpdatesCompany $updatesCompany * @param FetchesCompany $fetchesCompany * @param UpdatesCompanyDebtor $updatesCompanyDebtor * @param CanCreateAddress $canCreateAddress * @param FetchesDistrict $fetchesDistrict * @param FetchesCompany $fetchesCompany * @param UpsertsAddress $upsertsAddress * @param UpdatesCompanyEInvoiceInfo $updatesCompanyEInvoiceInfo; * @param UpdatesAddressMetadata $updatesAddressMetadata */ public function __construct( CanUpdateCompany $canUpdateCompany, UpdatesCompany $updatesCompany, FetchesCompany $fetchesCompany, UpdatesCompanyDebtor $updatesCompanyDebtor, CanCreateAddress $canCreateAddress, FetchesDistrict $fetchesDistrict, UpsertsAddress $upsertsAddress, UpdatesCompanyEInvoiceInfo $updatesCompanyEInvoiceInfo, UpdatesAddressMetadata $updatesAddressMetadata ) { $this->canUpdateCompany = $canUpdateCompany; $this->updatesCompany = $updatesCompany; $this->fetchesCompany = $fetchesCompany; $this->updatesCompanyDebtor = $updatesCompanyDebtor; $this->canCreateAddress = $canCreateAddress; $this->fetchesDistrict = $fetchesDistrict; $this->fetchesCompany = $fetchesCompany; $this->upsertsAddress = $upsertsAddress; $this->updatesCompanyEInvoiceInfo = $updatesCompanyEInvoiceInfo; $this->updatesAddressMetadata = $updatesAddressMetadata; } /** * @param Request $request * @return JsonResponse * @throws ErrorException */ public function logic(Request $request) : JsonResponse { $dto = new UpdateCompanyDetailsDTO($request->all()); $company = $this->fetchesCompany->execute(['id' => $request->route('id')]); $object = new CompanyObject($dto->name, $dto->reference, $company->business_type, $dto->type); $this->canUpdateCompany->passes($object); //Update Name and Debtor $company = $this->updatesCompany->execute($company, $object); if ($dto->debtor|| $company->first()->debtor !== null) { $this->updatesCompanyDebtor->execute($company, $dto->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); $this->canCreateAddress->passes($addObj); $address = $this->upsertsAddress->execute($company, $addObj, $dto->addressId); $query = $this->updatesAddressMetadata->execute($address, false, true); $this->updatesCompanyEInvoiceInfo->execute($company, $dto->tin, $dto->msicCode); } return $this->resourceResponse(new CompanyResource($company)); } }