Add CVR handling to guest and auth routes with virkdata integration
- Introduced `/guest/cvr/search` endpoint in `guestRoute` for company search using CVR. - Added `/auth/register/cvr` endpoint in `authRoute` to handle CVR-based registration with validation. - Enhanced `virkdata` with `searchCompanies` and improved response handling for search requests. - Updated E-conomic integration to check for existing CVR registrations and create new customers where needed.
This commit is contained in:
@@ -3,9 +3,12 @@
|
||||
namespace routes;
|
||||
|
||||
use classes\authentication;
|
||||
use classes\economic;
|
||||
use classes\recaptcha;
|
||||
use classes\virkdata;
|
||||
use objects\logs_o;
|
||||
use objects\tokens_o;
|
||||
use objects\users_o;
|
||||
use traits\route_t;
|
||||
|
||||
class authRoute
|
||||
@@ -123,5 +126,112 @@ class authRoute
|
||||
'recaptcha' => $recaptcha
|
||||
]);
|
||||
});
|
||||
|
||||
$this->post('/auth/register/cvr', function () {
|
||||
// Get the post data
|
||||
global $response;
|
||||
$this->requireRecaptcha();
|
||||
/**
|
||||
* {
|
||||
* "cvr": "44794780",
|
||||
* "companyPhone": 21754690,
|
||||
* "invoiceEmail": "mikkel@truckwash.dk",
|
||||
* "contactEmail": "mikkel@truckwash.dk",
|
||||
* "contactPhone": 21754690,
|
||||
* "searchResult": {
|
||||
* "vat": 41004355,
|
||||
* "status": "Normal",
|
||||
* "name": "Truckwash ApS",
|
||||
* "address": "Letland Alle 2",
|
||||
* "zipcode": 2630,
|
||||
* "city": "Taastrup",
|
||||
* "protected": true,
|
||||
* "phone": "21754690",
|
||||
* "website": null,
|
||||
* "email": "mikkel@truckwash.dk",
|
||||
* "fax": null,
|
||||
* "startdate": "2019-12-11",
|
||||
* "enddate": null,
|
||||
* "employees": 14,
|
||||
* "industrycode": 953190,
|
||||
* "industrydesc": "Reparation og vedligeholdelse af motorkøretøjer i.a.n.",
|
||||
* "companytype": "APS",
|
||||
* "companydesc": "Anpartsselskab",
|
||||
* "owners": [
|
||||
* "DELOITTE STATSAUTORISERET REVISIONSPARTNERSELSKAB",
|
||||
* "MBL Revision I/S",
|
||||
* "WASH GROUP A/S"
|
||||
* ]
|
||||
* }
|
||||
* }
|
||||
*/
|
||||
/**
|
||||
* Parameters:
|
||||
*/
|
||||
self::requireParameters(['cvr', 'companyPhone', 'invoiceEmail', 'contactEmail', 'contactPhone']);
|
||||
$cvr = self::getParameter('cvr');
|
||||
$companyPhone = (int)self::getParameter('companyPhone');
|
||||
$invoiceEmail = self::getParameter('invoiceEmail');
|
||||
$contactEmail = self::getParameter('contactEmail');
|
||||
$contactPhone = (int)self::getParameter('contactPhone');
|
||||
/**
|
||||
* Validate
|
||||
*/
|
||||
self::requireType($cvr, $this->type_string());
|
||||
self::requireMinLength('cvr', 8);
|
||||
self::requireMaxLength('cvr', 20);
|
||||
self::requireType($companyPhone, $this->type_int());
|
||||
self::requireMinValue($companyPhone, 10000000);
|
||||
self::requireMaxValue($companyPhone, 9999999999);
|
||||
self::requireType($invoiceEmail, $this->type_string());
|
||||
self::requireMinLength('invoiceEmail', 5);
|
||||
self::requireMaxLength('invoiceEmail', 255);
|
||||
self::requireType($contactEmail, $this->type_string());
|
||||
self::requireMinLength('contactEmail', 5);
|
||||
self::requireMaxLength('contactEmail', 255);
|
||||
self::requireType($contactPhone, $this->type_int());
|
||||
self::requireMinValue($contactPhone, 10000000);
|
||||
self::requireMaxValue($contactPhone, 9999999999);
|
||||
/**
|
||||
* Check if the cvr already exists
|
||||
*/
|
||||
$economic_response = ((new economic())->customers->customers->search([
|
||||
'corporateIdentificationNumber' => (string)$cvr,
|
||||
], [
|
||||
'skipPages' => 0,
|
||||
'pageSize' => 1, // Since the limit is 1000, we need to set the page size to 1000.
|
||||
])->collection);
|
||||
if (count($economic_response) === 0) {
|
||||
/**
|
||||
* Create the customer in E-conomic
|
||||
*/
|
||||
// Get the customer name
|
||||
$name = (new virkdata())->getCompanyInformation($cvr, '', [])->name;
|
||||
/**
|
||||
* $economic = new economic();
|
||||
* $economic->createCustomer(
|
||||
* $customer_number,
|
||||
* $name,
|
||||
* $cvr,
|
||||
* $invoiceEmail,
|
||||
* $companyPhone,
|
||||
* );
|
||||
*/
|
||||
$economic = new economic();
|
||||
$result = $economic->createCustomer(
|
||||
(int)$companyPhone,
|
||||
$name,
|
||||
(string)$cvr,
|
||||
$invoiceEmail,
|
||||
(string)$companyPhone,
|
||||
);
|
||||
/**
|
||||
* Return the result
|
||||
*/
|
||||
$response->success($result, 201);
|
||||
} else {
|
||||
$response->error('CVR already registered', 400);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user