diff --git a/app/Classes/Exceptions/CriteriaNotFulfilledException.php b/app/Classes/Exceptions/CriteriaNotFulfilledException.php
new file mode 100644
index 00000000..da105690
--- /dev/null
+++ b/app/Classes/Exceptions/CriteriaNotFulfilledException.php
@@ -0,0 +1,14 @@
+addresses()->where('id', $id)->first() ?? new Address();
+
+ $model->reference = $object->getReference();
+ $model->street_one = $object->getStreetOne();
+ $model->street_two = $object->getStreetTwo();
+ $model->country_id = $object->getCountryId();
+ $model->state_id = $object->getStateId();
+ $model->district_id = $object->getDistrictId();
+ $model->postcode = $object->getPostCode();
+ $model->status = $object->getStatus();
+ $model->type = $object->getType();
+
+ return $this->handler($addressable->addresses(), $model);
+ }
+}
diff --git a/app/Classes/Modules/Companies/ControllersLogic/FetchCompanyEInvoiceInfoLogic.php b/app/Classes/Modules/Companies/ControllersLogic/FetchCompanyEInvoiceInfoLogic.php
new file mode 100644
index 00000000..30f7642c
--- /dev/null
+++ b/app/Classes/Modules/Companies/ControllersLogic/FetchCompanyEInvoiceInfoLogic.php
@@ -0,0 +1,69 @@
+ 'Retrieved Company E-Invoice Info',
+ 'message' => 'You have successfully retrieved a Company E-Invoice Info'
+ ];
+ }
+
+ /** @var CanFetchCompany */
+ private $canFetchCompany;
+
+ /** @var FetchesCompany */
+ private $fetchesCompany;
+
+ /**
+ * FetchCompanyEInvoiceInfoLogic 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();
+
+ $company = $this->fetchesCompany->execute(['id' => $request->route('id')]);
+ $eInvoiceInfo = $company->companyModules()->first()->addresses()->where('type', '=', AddressType::E_INVOICE)->latest()->first();
+
+ if($eInvoiceInfo){
+ $eInvoiceInfo->tin = $company->tin;
+ $eInvoiceInfo->msic_code = $company->msic_code;
+ $eInvoiceInfo->e_invoice = $company->e_invoice;
+ }
+ else{
+ return $this->response([]);
+ }
+
+ return $this->resourceResponse(new EInvoiceInfoResource($eInvoiceInfo));
+ }
+}
diff --git a/app/Classes/Modules/Companies/ControllersLogic/UpdateCompanyDetailsLogic.php b/app/Classes/Modules/Companies/ControllersLogic/UpdateCompanyDetailsLogic.php
new file mode 100644
index 00000000..fe1c2c23
--- /dev/null
+++ b/app/Classes/Modules/Companies/ControllersLogic/UpdateCompanyDetailsLogic.php
@@ -0,0 +1,133 @@
+ '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;
+
+ /**
+ * 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 UpdatesCompanyModuleName $updatesCompanyModuleName
+ */
+ public function __construct(
+ CanUpdateCompany $canUpdateCompany,
+ UpdatesCompany $updatesCompany,
+ FetchesCompany $fetchesCompany,
+ UpdatesCompanyDebtor $updatesCompanyDebtor,
+ CanCreateAddress $canCreateAddress,
+ FetchesDistrict $fetchesDistrict,
+ UpsertsAddress $upsertsAddress,
+ UpdatesCompanyEInvoiceInfo $updatesCompanyEInvoiceInfo,
+ UpdatesCompanyModuleName $updatesCompanyModuleName
+ )
+ {
+ $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;
+ }
+
+ /**
+ * @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);
+ }
+
+ return $this->resourceResponse(new CompanyResource($company));
+ }
+}
+
diff --git a/app/Classes/Modules/Companies/ControllersLogic/UpdateCompanyEInvoiceInfoLogic.php b/app/Classes/Modules/Companies/ControllersLogic/UpdateCompanyEInvoiceInfoLogic.php
new file mode 100644
index 00000000..319fa1a2
--- /dev/null
+++ b/app/Classes/Modules/Companies/ControllersLogic/UpdateCompanyEInvoiceInfoLogic.php
@@ -0,0 +1,109 @@
+ 'EInvoice Info Update',
+ 'message' => 'You have successfully updated company E-Invoice information'
+ ];
+ }
+
+ /** @var CanCreateAddress */
+ private $canCreateAddress;
+
+ /** @var FetchesDistrict */
+ private $fetchesDistrict;
+
+ /** @var FetchesCompanyModule */
+ private $fetchesCompanyModule;
+
+ /** @var CreatesAddress */
+ private $createsAddress;
+
+ /** @var RuleEvaluator */
+ private $ruleEvaluator;
+
+ /** @var UpdatesCompanyEInvoiceInfo */
+ private $updatesCompanyEInvoiceInfo;
+
+ /** @var CanPassEInvoicePromptedRule */
+ private $canPassEInvoicePromptedRule;
+
+ /**
+ * UpdateCompanyEInvoiceInfoLogic constructor.
+ * @param CanCreateAddress $canCreateAddress
+ * @param FetchesDistrict $fetchesDistrict
+ * @param FetchesCompanyModule $fetchesCompanyModule
+ * @param CreatesAddress $createsAddress
+ * @param RuleEvaluator $ruleEvaluator;
+ * @param UpdatesCompanyEInvoiceInfo $updatesCompanyEInvoiceInfo;
+ * @param CanPassEInvoicePromptedRule $canPassEInvoicePromptedRule
+ */
+ public function __construct(CanCreateAddress $canCreateAddress, FetchesDistrict $fetchesDistrict, FetchesCompanyModule $fetchesCompanyModule, CreatesAddress $createsAddress, RuleEvaluator $ruleEvaluator, UpdatesCompanyEInvoiceInfo $updatesCompanyEInvoiceInfo, CanPassEInvoicePromptedRule $canPassEInvoicePromptedRule)
+ {
+ $this->canCreateAddress = $canCreateAddress;
+ $this->fetchesDistrict = $fetchesDistrict;
+ $this->fetchesCompanyModule = $fetchesCompanyModule;
+ $this->createsAddress = $createsAddress;
+ $this->ruleEvaluator = $ruleEvaluator;
+ $this->updatesCompanyEInvoiceInfo = $updatesCompanyEInvoiceInfo;
+ $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, AddressType::E_INVOICE, ApprovalStatus::APPROVED, 'E-Invoice');
+
+ //Update Address
+ $this->canCreateAddress->passes($object);
+ $companyModule = $this->fetchesCompanyModule->execute(['id' => $dto->companyModuleId]);
+ $this->createsAddress->execute($companyModule, $object);
+
+ //Update tin, msic code
+ $this->updatesCompanyEInvoiceInfo->execute($companyModule->company, $dto->tin, $dto->msicCode);
+
+ return $this->response([]);
+ }
+}
diff --git a/app/Classes/Modules/Companies/ControllersLogic/UpdateCompanyEInvoiceRequestLogic.php b/app/Classes/Modules/Companies/ControllersLogic/UpdateCompanyEInvoiceRequestLogic.php
new file mode 100644
index 00000000..a065802d
--- /dev/null
+++ b/app/Classes/Modules/Companies/ControllersLogic/UpdateCompanyEInvoiceRequestLogic.php
@@ -0,0 +1,59 @@
+ 'Updated EInvoice Request',
+ 'message' => 'You have successfully updated company E-Invoice request'
+ ];
+ }
+
+ /** @var FetchesCompanyModule */
+ private $fetchesCompanyModule;
+
+ /** @var UpdatesCompanyEInvoiceRequest */
+ private $updatesCompanyEInvoiceRequest;
+
+
+ /**
+ * UpdateCompanyEInvoiceRequestLogic constructor.
+ * @param FetchesCompanyModule $fetchesCompanyModule
+ * @param UpdatesCompanyEInvoiceRequest $updatesCompanyEInvoiceRequest
+ */
+ public function __construct(FetchesCompanyModule $fetchesCompanyModule, UpdatesCompanyEInvoiceRequest $updatesCompanyEInvoiceRequest)
+ {
+ $this->fetchesCompanyModule = $fetchesCompanyModule;
+ $this->updatesCompanyEInvoiceRequest = $updatesCompanyEInvoiceRequest;
+ }
+
+ /**
+ * @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
+ {
+ $dto = new EInvoiceRequestDTO($request->all());
+ $companyModule = $this->fetchesCompanyModule->execute(['id' => $dto->companyModuleId]);
+ $this->updatesCompanyEInvoiceRequest->execute($companyModule->company, $dto->eInvoiceRequest);
+
+ return $this->response([]);
+ }
+}
diff --git a/app/Classes/Modules/Companies/DataTransferObjects/EInvoiceInfoDTO.php b/app/Classes/Modules/Companies/DataTransferObjects/EInvoiceInfoDTO.php
new file mode 100644
index 00000000..a9cf02f1
--- /dev/null
+++ b/app/Classes/Modules/Companies/DataTransferObjects/EInvoiceInfoDTO.php
@@ -0,0 +1,43 @@
+tin = (string) ($data['tin'] ?? '');
+ $this->msicCode = (int) ($data['msic_code'] ?? 0);
+ $this->districtId = (int) ($data['district_id'] ?? 0);
+ $this->stateId = (int) ($data['state_id'] ?? 0);
+ $this->companyModuleId = (int) ($data['company_module_id'] ?? 0);
+ $this->streetOne = (string) ($data['street_one'] ?? '');
+ $this->streetTwo = (string) ($data['street_two'] ?? '');
+ $this->postCode = (int) ($data['post_code'] ?? 0);
+ }
+
+ public function toArray(): array
+ {
+ return [
+ 'tin' => $this->tin,
+ 'msic_code' => $this->msicCode,
+ 'district_id' => $this->districtId,
+ 'state_id' => $this->stateId,
+ 'company_module_id' => $this->companyModuleId,
+ 'street_one' => $this->streetOne,
+ 'street_two' => $this->streetTwo,
+ 'post_code' => $this->postCode,
+ ];
+ }
+}
diff --git a/app/Classes/Modules/Companies/DataTransferObjects/EInvoiceRequestDTO.php b/app/Classes/Modules/Companies/DataTransferObjects/EInvoiceRequestDTO.php
new file mode 100644
index 00000000..1c46f2df
--- /dev/null
+++ b/app/Classes/Modules/Companies/DataTransferObjects/EInvoiceRequestDTO.php
@@ -0,0 +1,25 @@
+eInvoiceRequest = $data['e_invoice_request'];
+ $this->companyModuleId = $data['company_module_id'];
+ }
+
+ public function toArray(): array
+ {
+ return [
+ 'e_invoice_request' => $this->eInvoiceRequest,
+ 'company_module_id' => $this->companyModuleId,
+ ];
+ }
+}
diff --git a/app/Classes/Modules/Companies/DataTransferObjects/UpdateCompanyDetailsDTO.php b/app/Classes/Modules/Companies/DataTransferObjects/UpdateCompanyDetailsDTO.php
new file mode 100644
index 00000000..e9a76434
--- /dev/null
+++ b/app/Classes/Modules/Companies/DataTransferObjects/UpdateCompanyDetailsDTO.php
@@ -0,0 +1,64 @@
+id = (int) ($data['id'] ?? 0);
+ $this->name = (string) ($data['name'] ?? '');
+ $this->debtor = (string) ($data['debtor'] ?? '');
+ $this->reference = (string) ($data['reference'] ?? '');
+ $this->type = (int) ($data['type'] ?? 0);
+
+ $this->tin = (string) ($data['tin'] ?? 0);
+ $this->msicCode = (int) ($data['msic_code'] ?? 0);
+ $this->addressId = (int) ($data['address_id'] ?? 0);
+ $this->districtId = (int) ($data['district_id'] ?? 0);
+ $this->stateId = (int) ($data['state_id'] ?? 0);
+ $this->companyId = (int) ($data['company_id'] ?? 0);
+ $this->streetOne = (string) ($data['street_one'] ?? '');
+ $this->streetTwo = (string) ($data['street_two'] ?? '');
+ $this->postCode = (int) ($data['post_code'] ?? 0);
+ }
+
+ public function toArray(): array
+ {
+ return [
+ 'id' => $this->id,
+ 'name' => $this->name,
+ 'debtor' => $this->debtor,
+ 'reference' => $this->reference,
+ 'type' => $this->type,
+
+ 'tin' => $this->tin,
+ 'msic_code' => $this->msicCode,
+ 'address_id' => $this->addressId,
+ 'district_id' => $this->districtId,
+ 'state_id' => $this->stateId,
+ 'company_id' => $this->companyId,
+ 'street_one' => $this->streetOne,
+ 'street_two' => $this->streetTwo,
+ 'post_code' => $this->postCode,
+ ];
+ }
+}
diff --git a/app/Classes/Modules/Companies/Services/UpdatesCompanyEInvoiceInfo.php b/app/Classes/Modules/Companies/Services/UpdatesCompanyEInvoiceInfo.php
new file mode 100644
index 00000000..0a2c5cc5
--- /dev/null
+++ b/app/Classes/Modules/Companies/Services/UpdatesCompanyEInvoiceInfo.php
@@ -0,0 +1,25 @@
+tin = $tin;
+ $model->msic_code = $msicCode;
+
+ return $this->handler($model);
+ }
+}
diff --git a/app/Classes/Modules/Companies/Services/UpdatesCompanyEInvoiceRequest.php b/app/Classes/Modules/Companies/Services/UpdatesCompanyEInvoiceRequest.php
new file mode 100644
index 00000000..bdef7fc8
--- /dev/null
+++ b/app/Classes/Modules/Companies/Services/UpdatesCompanyEInvoiceRequest.php
@@ -0,0 +1,29 @@
+e_invoice_requested_at)) {
+ if($eInvoice){
+ $model->e_invoice_requested_at = now();
+ }
+ }
+ $model->e_invoice = $eInvoice;
+
+ return $this->handler($model);
+ }
+}
diff --git a/app/Classes/Modules/Rules/ControllersLogic/CheckEInvoiceRuleLogic.php b/app/Classes/Modules/Rules/ControllersLogic/CheckEInvoiceRuleLogic.php
new file mode 100644
index 00000000..9c690686
--- /dev/null
+++ b/app/Classes/Modules/Rules/ControllersLogic/CheckEInvoiceRuleLogic.php
@@ -0,0 +1,70 @@
+ 'Rule Check E-Invoice',
+ 'message' => 'You have successfully passed all rules evaluated'
+ ];
+ }
+
+ /** @var RuleEvaluator */
+ private $ruleEvaluator;
+
+ /** @var CanPassEInvoicePromptedRule */
+ private $canPassEInvoicePromptedRule;
+
+ /** @var CanPassTINRule */
+ private $canPassTINRule;
+
+ /**
+ * CheckEInvoiceRuleLogic constructor.
+ */
+ public function __construct(RuleEvaluator $ruleEvaluator, CanPassEInvoicePromptedRule $canPassEInvoicePromptedRule, CanPassTINRule $canPassTINRule)
+ {
+ $this->ruleEvaluator = $ruleEvaluator;
+ $this->canPassEInvoicePromptedRule = $canPassEInvoicePromptedRule;
+ $this->canPassTINRule = $canPassTINRule;
+ }
+
+ /**
+ * @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 CheckEInvoiceRuleDTO($request->all());
+
+ $result = $this->ruleEvaluator->evaluate([
+ $this->canPassEInvoicePromptedRule,
+ $this->canPassTINRule,
+ ], $dto);
+
+ if ($result->failed()) {
+ throw new CriteriaNotFulfilledException("- " . implode("
- ", $result->messages()));
+ }
+
+ return $this->resourceResponse(new RuleResource((object)$result));
+ }
+}
diff --git a/app/Classes/Modules/Rules/DataTransferObjects/CheckEInvoiceRuleDTO.php b/app/Classes/Modules/Rules/DataTransferObjects/CheckEInvoiceRuleDTO.php
new file mode 100644
index 00000000..c982aeb0
--- /dev/null
+++ b/app/Classes/Modules/Rules/DataTransferObjects/CheckEInvoiceRuleDTO.php
@@ -0,0 +1,22 @@
+companyModuleId = $data['company_module_id'];
+ }
+
+ public function toArray(): array
+ {
+ return [
+ 'company_module_id' => $this->companyModuleId,
+ ];
+ }
+}
diff --git a/app/Classes/Modules/Rules/Services/RuleEvaluator.php b/app/Classes/Modules/Rules/Services/RuleEvaluator.php
new file mode 100644
index 00000000..ac248a25
--- /dev/null
+++ b/app/Classes/Modules/Rules/Services/RuleEvaluator.php
@@ -0,0 +1,44 @@
+passes($object)) {
+ $success = false;
+ $messages[] = get_class($rule) . ' failed without exception';
+ }
+ } catch (AccessForbiddenException | RequestValidationException | CriteriaNotFulfilledException $e) {
+ $success = false;
+ $messages[] = $e->getMessage();
+ } catch (\Exception $e) {
+ $success = false;
+ $messages[] = 'Unexpected error in ' . get_class($rule) . ': ' . $e->getMessage();
+ }
+ }
+
+ return new RuleEvaluationResult($success, $messages);
+ }
+
+}
diff --git a/app/Classes/Modules/Rules/Standards/Rules/CanPassEInvoicePromptedRule.php b/app/Classes/Modules/Rules/Standards/Rules/CanPassEInvoicePromptedRule.php
new file mode 100644
index 00000000..61d1dfcb
--- /dev/null
+++ b/app/Classes/Modules/Rules/Standards/Rules/CanPassEInvoicePromptedRule.php
@@ -0,0 +1,57 @@
+fetchesCompanyModule = $fetchesCompanyModule;
+ }
+
+ /**
+ * @return bool
+ */
+ protected function authorized($object): bool
+ {
+ return true;
+
+ }
+
+ /**
+ * @return bool
+ */
+ protected function validators($object): bool
+ {
+ return true;
+
+ }
+
+
+ /**
+ * @return bool
+ */
+ protected function criteria($object): bool
+ {
+ //Check if account requires E-Invoice
+ $companyModule = $this->fetchesCompanyModule->execute(['id' => $object->companyModuleId]);
+ if($companyModule->company->e_invoice === null){
+ throw new CriteriaNotFulfilledException("Please refresh page to answer question related to E-Invoice.");
+ }
+ return true;
+ }
+
+}
diff --git a/app/Classes/Modules/Rules/Standards/Rules/CanPassTINRule.php b/app/Classes/Modules/Rules/Standards/Rules/CanPassTINRule.php
new file mode 100644
index 00000000..5ec859cb
--- /dev/null
+++ b/app/Classes/Modules/Rules/Standards/Rules/CanPassTINRule.php
@@ -0,0 +1,55 @@
+fetchesCompanyModule = $fetchesCompanyModule;
+ }
+
+ /**
+ * @return bool
+ */
+ protected function authorized($object): bool
+ {
+ return true;
+ }
+
+ /**
+ * @return bool
+ */
+ protected function validators($object): bool
+ {
+ return true;
+ }
+
+
+ /**
+ * @return bool
+ */
+ protected function criteria($object): bool
+ {
+ //Check if TIN already provided if account requires E-Invoice
+ $companyModule = $this->fetchesCompanyModule->execute(['id' => $object->companyModuleId]);
+ if($companyModule->company->e_invoice === 1 && !$companyModule->company->tin){
+ throw new CriteriaNotFulfilledException("Please provide all requested E-Invoice Info.");
+ }
+ return true;
+ }
+
+}
diff --git a/app/Classes/ValueObjects/Constants/AddressType.php b/app/Classes/ValueObjects/Constants/AddressType.php
index 614b9774..b9952a3e 100644
--- a/app/Classes/ValueObjects/Constants/AddressType.php
+++ b/app/Classes/ValueObjects/Constants/AddressType.php
@@ -10,4 +10,6 @@ final class AddressType {
public const PICK_UP = 3;
+ public const E_INVOICE = 4;
+
}
diff --git a/app/Classes/ValueObjects/Response/RuleEvaluationResult.php b/app/Classes/ValueObjects/Response/RuleEvaluationResult.php
new file mode 100644
index 00000000..264eaf26
--- /dev/null
+++ b/app/Classes/ValueObjects/Response/RuleEvaluationResult.php
@@ -0,0 +1,30 @@
+success = $success;
+ $this->messages = $messages;
+ }
+
+ public function failed(): bool
+ {
+ return ! $this->success;
+ }
+
+ public function passed(): bool
+ {
+ return $this->success;
+ }
+
+ public function messages(): array
+ {
+ return $this->messages;
+ }
+}
diff --git a/app/Http/Controllers/Companies/FetchCompanyEInvoiceInfoController.php b/app/Http/Controllers/Companies/FetchCompanyEInvoiceInfoController.php
new file mode 100644
index 00000000..d506e24e
--- /dev/null
+++ b/app/Http/Controllers/Companies/FetchCompanyEInvoiceInfoController.php
@@ -0,0 +1,20 @@
+execute($request);
+ }
+}
diff --git a/app/Http/Controllers/Companies/UpdateCompanyDetailsController.php b/app/Http/Controllers/Companies/UpdateCompanyDetailsController.php
new file mode 100644
index 00000000..e8cbfd1c
--- /dev/null
+++ b/app/Http/Controllers/Companies/UpdateCompanyDetailsController.php
@@ -0,0 +1,21 @@
+execute($request);
+ }
+}
diff --git a/app/Http/Controllers/Companies/UpdateCompanyEInvoiceInfoController.php b/app/Http/Controllers/Companies/UpdateCompanyEInvoiceInfoController.php
new file mode 100644
index 00000000..9157e9de
--- /dev/null
+++ b/app/Http/Controllers/Companies/UpdateCompanyEInvoiceInfoController.php
@@ -0,0 +1,29 @@
+execute($request);
+ }
+
+ /**
+ * @param Request $request
+ * @param UpdateCompanyEInvoiceRequestLogic $logic
+ * @return JsonResponse
+ */
+ public function updateRequest(Request $request, UpdateCompanyEInvoiceRequestLogic $logic): JsonResponse {
+ return $logic->execute($request);
+ }
+}
diff --git a/app/Http/Controllers/Rules/CheckRuleController.php b/app/Http/Controllers/Rules/CheckRuleController.php
new file mode 100644
index 00000000..af95e185
--- /dev/null
+++ b/app/Http/Controllers/Rules/CheckRuleController.php
@@ -0,0 +1,19 @@
+execute($request);
+ }
+}
diff --git a/app/Http/Resources/CompanyModuleResource.php b/app/Http/Resources/CompanyModuleResource.php
index 5ffc40f8..1e54674e 100644
--- a/app/Http/Resources/CompanyModuleResource.php
+++ b/app/Http/Resources/CompanyModuleResource.php
@@ -51,6 +51,11 @@ class CompanyModuleResource extends JsonResource
'connections' => $this->connections,
'contact' => new ContactResource ($this->when($this->has('contacts'), $this->contacts->first())),
'debtor' => $this->company->debtor,
+ 'e_invoice' => $this->company->e_invoice,
+ 'tin' => $this->company->tin,
+ 'msic_code' => $this->company->msic_code,
+ 'address_einvoice' => $this->company->e_invoice ? new AddressResource($this->when($this->has('addresses'), $this->addresses->where('type', AddressType::E_INVOICE)->sortByDesc('created_at')->first())) : null,
+
];
}
diff --git a/app/Http/Resources/EInvoiceInfoResource.php b/app/Http/Resources/EInvoiceInfoResource.php
new file mode 100644
index 00000000..565e86a7
--- /dev/null
+++ b/app/Http/Resources/EInvoiceInfoResource.php
@@ -0,0 +1,31 @@
+ $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,
+ 'msic_code' => (int) $this->msic_code,
+ 'tin' => (string) $this->tin,
+ 'e_invoice' => (int) $this->e_invoice,
+ ];
+ }
+}
diff --git a/app/Http/Resources/RuleResource.php b/app/Http/Resources/RuleResource.php
new file mode 100644
index 00000000..1fb42181
--- /dev/null
+++ b/app/Http/Resources/RuleResource.php
@@ -0,0 +1,22 @@
+ $this->success,
+ 'messages' => $this->messages,
+ ];
+ }
+}
diff --git a/database/migrations/2025_06_15_192423_add_tin_to_companies_table.php b/database/migrations/2025_06_15_192423_add_tin_to_companies_table.php
new file mode 100644
index 00000000..ed5f2c58
--- /dev/null
+++ b/database/migrations/2025_06_15_192423_add_tin_to_companies_table.php
@@ -0,0 +1,38 @@
+string('tin')->nullable()->after('debtor');
+ $table->string('msic_code')->nullable()->after('debtor')->comment("5-digit code representing business activity");
+ $table->timestamp('e_invoice_requested_at')->nullable()->after('debtor');
+ $table->boolean('e_invoice')->nullable()->default(null)->after('debtor');
+ });
+ }
+
+ /**
+ * Reverse the migrations.
+ *
+ * @return void
+ */
+ public function down()
+ {
+ Schema::table('companies', function (Blueprint $table) {
+ $table->dropColumn('tin');
+ $table->dropColumn('msic_code');
+ $table->dropColumn('e_invoice_requested_at');
+ $table->dropColumn('e_invoice');
+ });
+ }
+}
diff --git a/resources/assets/vue/components/companies/elements/CustomerProfileComponent.vue b/resources/assets/vue/components/companies/elements/CustomerProfileComponent.vue
index b71287c5..bef39049 100644
--- a/resources/assets/vue/components/companies/elements/CustomerProfileComponent.vue
+++ b/resources/assets/vue/components/companies/elements/CustomerProfileComponent.vue
@@ -16,7 +16,8 @@
TIN
+{{ eInvoiceData.tin }}
+MSIC Code
+{{ eInvoiceData.msic_code }}
+Billing Address
+ + +TIN
+{{parameters.tin}}
+MSIC Code
+{{parameters.msic_code}}
+Billing Address
+{{parameters.street_one}} {{parameters.street_two}}, {{districts[parseFloat(parameters.district_id) - 1].text}} {{parameters.post_code}} {{states[parseFloat(parameters.state_id) - 1].text}}, Malaysia
+