Validation checks

This commit is contained in:
David Bomba 2025-08-15 12:26:40 +10:00
parent 70dea557f5
commit 117709e551
3 changed files with 54 additions and 26 deletions

View File

@ -62,6 +62,7 @@ class EntityLevel implements EntityLevelInterface
{ {
$this->init($client->locale()); $this->init($client->locale());
$this->errors['client'] = $this->testClientState($client); $this->errors['client'] = $this->testClientState($client);
$this->errors['passes'] = count($this->errors['client']) == 0; $this->errors['passes'] = count($this->errors['client']) == 0;
@ -89,6 +90,7 @@ class EntityLevel implements EntityLevelInterface
$this->errors['client'] = $this->testClientState($invoice->client); $this->errors['client'] = $this->testClientState($invoice->client);
$this->errors['company'] = $this->testCompanyState($invoice->client); // uses client level settings which is what we want $this->errors['company'] = $this->testCompanyState($invoice->client); // uses client level settings which is what we want
if (count($this->errors['client']) > 0) { if (count($this->errors['client']) > 0) {
$this->errors['passes'] = false; $this->errors['passes'] = false;
@ -96,6 +98,13 @@ class EntityLevel implements EntityLevelInterface
} }
// $this->errors['invoice'][] = 'test error';
$this->errors['passes'] = count($this->errors['invoice']) === 0 && count($this->errors['company']) === 0; //no need to check client as we are using client level settings
return $this->errors;
// $p = new Peppol($invoice); // $p = new Peppol($invoice);
@ -137,9 +146,6 @@ class EntityLevel implements EntityLevelInterface
// $this->checkNexus($invoice->client); // $this->checkNexus($invoice->client);
$this->errors['passes'] = count($this->errors['invoice']) == 0 && count($this->errors['client']) == 0 && count($this->errors['company']) == 0;
return $this->errors;
} }
@ -166,14 +172,27 @@ class EntityLevel implements EntityLevelInterface
} }
//If not an individual, you MUST have a VAT number if you are in the EU
if ($client->classification != 'individual' && !$this->validString($client->vat_number)) { if ($client->country_id == 724) {
if (in_array($client->classification, ['','individual']) && strlen($client->id_number ?? '') == 0) {
$errors[] = ['field' => 'id_number', 'label' => ctrans("texts.id_number")];
} elseif (strlen($client->vat_number ?? '')) {
$errors[] = ['field' => 'vat_number', 'label' => ctrans("texts.vat_number")]; $errors[] = ['field' => 'vat_number', 'label' => ctrans("texts.vat_number")];
} }
//Primary contact email is present. }
if ($client->present()->email() == 'No Email Set') { else{
$errors[] = ['field' => 'email', 'label' => ctrans("texts.email")]; //If not an individual, you MUST have a VAT number if you are in the EU
if (!in_array($client->classification,['','individual']) && !$this->validString($client->vat_number)) {
$errors[] = ['field' => 'vat_number', 'label' => ctrans("texts.vat_number")];
}
// //Primary contact email is present.
// if ($client->present()->email() == 'No Email Set') {
// $errors[] = ['field' => 'email', 'label' => ctrans("texts.email")];
// }
} }
return $errors; return $errors;

View File

@ -138,11 +138,20 @@ class RegistroAlta
$destinatarios = []; $destinatarios = [];
$destinatario = new PersonaFisicaJuridica(); $destinatario = new PersonaFisicaJuridica();
if($this->invoice->client->country_id == 724) { if($this->invoice->client->country_id == 724 && strlen($this->invoice->client->vat_number ?? '') > 5) {
$destinatario $destinatario
->setNif($this->invoice->client->vat_number) ->setNif($this->invoice->client->vat_number)
->setNombreRazon($this->invoice->client->present()->name()); ->setNombreRazon($this->invoice->client->present()->name());
} }
elseif($this->invoice->client->country_id == 724) {
$destinatario = new IDOtro();
$destinatario->setNombreRazon($this->invoice->client->present()->name());
$destinatario->setCodigoPais('ES')
->setIdType('06')
->setId($this->invoice->client->id_number);
}
else { else {
$locationData = $this->invoice->service()->location(); $locationData = $this->invoice->service()->location();

30
composer.lock generated
View File

@ -17906,16 +17906,16 @@
}, },
{ {
"name": "fidry/cpu-core-counter", "name": "fidry/cpu-core-counter",
"version": "1.2.0", "version": "1.3.0",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/theofidry/cpu-core-counter.git", "url": "https://github.com/theofidry/cpu-core-counter.git",
"reference": "8520451a140d3f46ac33042715115e290cf5785f" "reference": "db9508f7b1474469d9d3c53b86f817e344732678"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/theofidry/cpu-core-counter/zipball/8520451a140d3f46ac33042715115e290cf5785f", "url": "https://api.github.com/repos/theofidry/cpu-core-counter/zipball/db9508f7b1474469d9d3c53b86f817e344732678",
"reference": "8520451a140d3f46ac33042715115e290cf5785f", "reference": "db9508f7b1474469d9d3c53b86f817e344732678",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -17925,10 +17925,10 @@
"fidry/makefile": "^0.2.0", "fidry/makefile": "^0.2.0",
"fidry/php-cs-fixer-config": "^1.1.2", "fidry/php-cs-fixer-config": "^1.1.2",
"phpstan/extension-installer": "^1.2.0", "phpstan/extension-installer": "^1.2.0",
"phpstan/phpstan": "^1.9.2", "phpstan/phpstan": "^2.0",
"phpstan/phpstan-deprecation-rules": "^1.0.0", "phpstan/phpstan-deprecation-rules": "^2.0.0",
"phpstan/phpstan-phpunit": "^1.2.2", "phpstan/phpstan-phpunit": "^2.0",
"phpstan/phpstan-strict-rules": "^1.4.4", "phpstan/phpstan-strict-rules": "^2.0",
"phpunit/phpunit": "^8.5.31 || ^9.5.26", "phpunit/phpunit": "^8.5.31 || ^9.5.26",
"webmozarts/strict-phpunit": "^7.5" "webmozarts/strict-phpunit": "^7.5"
}, },
@ -17955,7 +17955,7 @@
], ],
"support": { "support": {
"issues": "https://github.com/theofidry/cpu-core-counter/issues", "issues": "https://github.com/theofidry/cpu-core-counter/issues",
"source": "https://github.com/theofidry/cpu-core-counter/tree/1.2.0" "source": "https://github.com/theofidry/cpu-core-counter/tree/1.3.0"
}, },
"funding": [ "funding": [
{ {
@ -17963,7 +17963,7 @@
"type": "github" "type": "github"
} }
], ],
"time": "2024-08-06T10:04:20+00:00" "time": "2025-08-14T07:29:31+00:00"
}, },
{ {
"name": "filp/whoops", "name": "filp/whoops",
@ -18383,16 +18383,16 @@
}, },
{ {
"name": "laravel/boost", "name": "laravel/boost",
"version": "v1.0.9", "version": "v1.0.17",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/laravel/boost.git", "url": "https://github.com/laravel/boost.git",
"reference": "ad025a2f2325ccdc5f52e926dab4e0c1d2c6def9" "reference": "3d1121561f793d027b76cb02b4ef9e654f8870fb"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/laravel/boost/zipball/ad025a2f2325ccdc5f52e926dab4e0c1d2c6def9", "url": "https://api.github.com/repos/laravel/boost/zipball/3d1121561f793d027b76cb02b4ef9e654f8870fb",
"reference": "ad025a2f2325ccdc5f52e926dab4e0c1d2c6def9", "reference": "3d1121561f793d027b76cb02b4ef9e654f8870fb",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -18444,7 +18444,7 @@
"issues": "https://github.com/laravel/boost/issues", "issues": "https://github.com/laravel/boost/issues",
"source": "https://github.com/laravel/boost" "source": "https://github.com/laravel/boost"
}, },
"time": "2025-08-13T19:51:44+00:00" "time": "2025-08-14T17:31:57+00:00"
}, },
{ {
"name": "laravel/mcp", "name": "laravel/mcp",