Update rules for setting Impuesto values

This commit is contained in:
David Bomba 2025-08-15 13:02:59 +10:00
parent 117709e551
commit e8336c85d7
2 changed files with 20 additions and 24 deletions

View File

@ -31,7 +31,7 @@ class EntityLevel implements EntityLevelInterface
// 'city', // 'city',
// 'state', // 'state',
// 'postal_code', // 'postal_code',
'vat_number', // 'vat_number',
'country_id', 'country_id',
]; ];
@ -164,36 +164,32 @@ class EntityLevel implements EntityLevelInterface
continue; continue;
} }
if($field == 'vat_number' && $client->classification == 'individual') { // if($field == 'vat_number' && $client->classification == 'individual') {
continue; // continue;
} // }
$errors[] = ['field' => $field, 'label' => ctrans("texts.{$field}")]; $errors[] = ['field' => $field, 'label' => ctrans("texts.{$field}")];
} }
/** Spanish Client Validation requirements */
if ($client->country_id == 724) { if ($client->country_id == 724) {
if (in_array($client->classification, ['','individual']) && strlen($client->id_number ?? '') == 0) { if (in_array($client->classification, ['','individual']) && strlen($client->id_number ?? '') == 0 && strlen($client->vat_number ?? '') == 0) {
$errors[] = ['field' => 'id_number', 'label' => ctrans("texts.id_number")]; $errors[] = ['field' => 'id_number', 'label' => ctrans("texts.id_number")];
} elseif (strlen($client->vat_number ?? '')) { } elseif (!in_array($client->classification, ['','individual']) && strlen($client->vat_number ?? '')) {
$errors[] = ['field' => 'vat_number', 'label' => ctrans("texts.vat_number")]; $errors[] = ['field' => 'vat_number', 'label' => ctrans("texts.vat_number")];
} }
} }
else{
//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. // else{
// if ($client->present()->email() == 'No Email Set') { // //If not an individual, you MUST have a VAT number if you are in the EU
// $errors[] = ['field' => 'email', 'label' => ctrans("texts.email")]; // if (!in_array($client->classification,['','individual']) && !$this->validString($client->vat_number)) {
// $errors[] = ['field' => 'vat_number', 'label' => ctrans("texts.vat_number")];
// } // }
} // }
return $errors; return $errors;

View File

@ -138,17 +138,18 @@ class RegistroAlta
$destinatarios = []; $destinatarios = [];
$destinatario = new PersonaFisicaJuridica(); $destinatario = new PersonaFisicaJuridica();
//Spanish NIF/VAT
if($this->invoice->client->country_id == 724 && strlen($this->invoice->client->vat_number ?? '') > 5) { 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) { elseif($this->invoice->client->country_id == 724) { // Spanish Passport
$destinatario = new IDOtro(); $destinatario = new IDOtro();
$destinatario->setNombreRazon($this->invoice->client->present()->name()); $destinatario->setNombreRazon($this->invoice->client->present()->name());
$destinatario->setCodigoPais('ES') $destinatario->setCodigoPais('ES')
->setIdType('06') ->setIdType('03')
->setId($this->invoice->client->id_number); ->setId($this->invoice->client->id_number);
} }
@ -197,7 +198,7 @@ class RegistroAlta
}; };
if(count($taxes) == 0) { if(count($taxes) == 0) {
nlog("tax count = 0");
$client_country_code = $this->invoice->client->country->iso_3166_2; $client_country_code = $this->invoice->client->country->iso_3166_2;
$impuesto = 'S2'; $impuesto = 'S2';
@ -216,9 +217,9 @@ class RegistroAlta
$clave_regimen = '05'; $clave_regimen = '05';
$calificacion = 'N2'; $calificacion = 'N2';
} }
else{ else{ //Non-EU
$impuesto = '08'; $impuesto = '05';
$clave_regimen = '01'; $clave_regimen = '05';
$calificacion = 'N2'; $calificacion = 'N2';
} }
@ -227,7 +228,6 @@ class RegistroAlta
'ClaveRegimen' => $clave_regimen, //tax regime classification code 'ClaveRegimen' => $clave_regimen, //tax regime classification code
'CalificacionOperacion' => $calificacion, //operation classification code 'CalificacionOperacion' => $calificacion, //operation classification code
'BaseImponible' => $this->calc->getNetSubtotal(), // taxable base amount - fixed: key matches DetalleDesglose::toXml() 'BaseImponible' => $this->calc->getNetSubtotal(), // taxable base amount - fixed: key matches DetalleDesglose::toXml()
]; ];
$detalle_desglose = new DetalleDesglose(); $detalle_desglose = new DetalleDesglose();