'EInvoice Info Update', 'message' => 'You have successfully updated company E-Invoice information' ]; } /** @var CanCreateAddress */ private $canCreateAddress; /** @var FetchesDistrict */ private $fetchesDistrict; /** @var FetchesCompany */ private $fetchesCompany; /** @var CreatesAddress */ private $createsAddress; /** @var RuleEvaluator */ private $ruleEvaluator; /** @var UpdatesCompanyEInvoiceInfo */ private $updatesCompanyEInvoiceInfo; /** @var UpdatesAddressMetadata */ private $updatesAddressMetadata; /** @var CanPassEInvoicePromptedRule */ private $canPassEInvoicePromptedRule; /** * UpdateCompanyEInvoiceInfoLogic constructor. * @param CanCreateAddress $canCreateAddress * @param FetchesDistrict $fetchesDistrict * @param FetchesCompany $fetchesCompany * @param CreatesAddress $createsAddress * @param RuleEvaluator $ruleEvaluator; * @param UpdatesCompanyEInvoiceInfo $updatesCompanyEInvoiceInfo; * @param UpdatesAddressMetadata $updatesAddressMetadata * @param CanPassEInvoicePromptedRule $canPassEInvoicePromptedRule */ public function __construct(CanCreateAddress $canCreateAddress, FetchesDistrict $fetchesDistrict, FetchesCompany $fetchesCompany, CreatesAddress $createsAddress, RuleEvaluator $ruleEvaluator, UpdatesCompanyEInvoiceInfo $updatesCompanyEInvoiceInfo, UpdatesAddressMetadata $updatesAddressMetadata, CanPassEInvoicePromptedRule $canPassEInvoicePromptedRule) { $this->canCreateAddress = $canCreateAddress; $this->fetchesDistrict = $fetchesDistrict; $this->fetchesCompany = $fetchesCompany; $this->createsAddress = $createsAddress; $this->ruleEvaluator = $ruleEvaluator; $this->updatesCompanyEInvoiceInfo = $updatesCompanyEInvoiceInfo; $this->updatesAddressMetadata = $updatesAddressMetadata; $this->canPassEInvoicePromptedRule = $canPassEInvoicePromptedRule; } /** * @param Request $request * @return JsonResponse * @throws \App\Classes\Exceptions\AccessForbiddenException * @throws \App\Classes\Exceptions\MalformedRequestException * @throws \App\Classes\Exceptions\RequestValidationException * @throws \App\Classes\Exceptions\CriteriaNotFulfilledException */ public function logic(Request $request) : JsonResponse { $dto = new EInvoiceInfoDTO($request->all()); $result = $this->ruleEvaluator->evaluate([ $this->canPassEInvoicePromptedRule, ], $dto); if ($result->failed()) { throw new CriteriaNotFulfilledException("- " . implode("
- ", $result->messages())); } $district = $this->fetchesDistrict->execute(['id' => $dto->districtId]); $object = new AddressObject($dto->streetOne, $dto->streetTwo, $district->country_id, $dto->stateId, $district->id, $dto->postCode); //Update Address $this->canCreateAddress->passes($object); $company = $this->fetchesCompany->execute(['id' => $dto->companyId]); $address = $this->createsAddress->execute($company, $object); $query = $this->updatesAddressMetadata->execute($address, false, true); //Update tin, msic code $this->updatesCompanyEInvoiceInfo->execute($company, $dto->tin, $dto->msicCode); return $this->response([]); } }