invoiceninja/app/Services/EDocument/Standards/Verifactu/Models/PersonaFisicaJuridica.php

207 lines
5.7 KiB
PHP

<?php
namespace App\Services\EDocument\Standards\Verifactu\Models;
use App\Services\EDocument\Standards\Verifactu\Models\BaseXmlModel;
class PersonaFisicaJuridica extends BaseXmlModel
{
protected ?string $nif = null;
protected ?string $nombreRazon = null;
protected ?string $apellidos = null;
protected ?string $nombre = null;
protected ?string $razonSocial = null;
protected ?string $tipoIdentificacion = null;
protected ?string $idOtro = null;
protected ?string $pais = null;
public function getNif(): ?string
{
return $this->nif;
}
public function setNif(?string $nif): self
{
$this->nif = $nif;
return $this;
}
public function getNombreRazon(): ?string
{
return $this->nombreRazon;
}
public function setNombreRazon(?string $nombreRazon): self
{
$this->nombreRazon = $nombreRazon;
return $this;
}
public function getApellidos(): ?string
{
return $this->apellidos;
}
public function setApellidos(?string $apellidos): self
{
$this->apellidos = $apellidos;
return $this;
}
public function getNombre(): ?string
{
return $this->nombre;
}
public function setNombre(?string $nombre): self
{
$this->nombre = $nombre;
return $this;
}
public function getRazonSocial(): ?string
{
return $this->razonSocial;
}
public function setRazonSocial(?string $razonSocial): self
{
$this->razonSocial = $razonSocial;
return $this;
}
public function getTipoIdentificacion(): ?string
{
return $this->tipoIdentificacion;
}
public function setTipoIdentificacion(?string $tipoIdentificacion): self
{
$this->tipoIdentificacion = $tipoIdentificacion;
return $this;
}
public function getIdOtro(): ?string
{
return $this->idOtro;
}
public function setIdOtro(?string $idOtro): self
{
$this->idOtro = $idOtro;
return $this;
}
public function getPais(): ?string
{
return $this->pais;
}
public function setPais(?string $pais): self
{
$this->pais = $pais;
return $this;
}
public function toXml(\DOMDocument $doc): \DOMElement
{
$root = $this->createElement($doc, 'PersonaFisicaJuridica');
if ($this->nif !== null) {
$root->appendChild($this->createElement($doc, 'NIF', $this->nif));
}
if ($this->nombreRazon !== null) {
$root->appendChild($this->createElement($doc, 'NombreRazon', $this->nombreRazon));
}
if ($this->apellidos !== null) {
$root->appendChild($this->createElement($doc, 'Apellidos', $this->apellidos));
}
if ($this->nombre !== null) {
$root->appendChild($this->createElement($doc, 'Nombre', $this->nombre));
}
if ($this->razonSocial !== null) {
$root->appendChild($this->createElement($doc, 'RazonSocial', $this->razonSocial));
}
if ($this->tipoIdentificacion !== null) {
$root->appendChild($this->createElement($doc, 'TipoIdentificacion', $this->tipoIdentificacion));
}
if ($this->idOtro !== null) {
$root->appendChild($this->createElement($doc, 'IDOtro', $this->idOtro));
}
if ($this->pais !== null) {
$root->appendChild($this->createElement($doc, 'Pais', $this->pais));
}
return $root;
}
/**
* Create a PersonaFisicaJuridica instance from XML string or DOMElement
*/
public static function fromXml($xml): BaseXmlModel
{
if (is_string($xml)) {
$doc = new \DOMDocument();
$doc->loadXML($xml);
$element = $doc->documentElement;
} else {
$element = $xml;
}
return self::fromDOMElement($element);
}
public static function fromDOMElement(\DOMElement $element): self
{
$persona = new self();
$nifElement = $element->getElementsByTagNameNS(self::XML_NAMESPACE, 'NIF')->item(0);
if ($nifElement) {
$persona->setNif($nifElement->nodeValue);
}
$nombreRazonElement = $element->getElementsByTagNameNS(self::XML_NAMESPACE, 'NombreRazon')->item(0);
if ($nombreRazonElement) {
$persona->setNombreRazon($nombreRazonElement->nodeValue);
}
$apellidosElement = $element->getElementsByTagNameNS(self::XML_NAMESPACE, 'Apellidos')->item(0);
if ($apellidosElement) {
$persona->setApellidos($apellidosElement->nodeValue);
}
$nombreElement = $element->getElementsByTagNameNS(self::XML_NAMESPACE, 'Nombre')->item(0);
if ($nombreElement) {
$persona->setNombre($nombreElement->nodeValue);
}
$razonSocialElement = $element->getElementsByTagNameNS(self::XML_NAMESPACE, 'RazonSocial')->item(0);
if ($razonSocialElement) {
$persona->setRazonSocial($razonSocialElement->nodeValue);
}
$tipoIdentificacionElement = $element->getElementsByTagNameNS(self::XML_NAMESPACE, 'TipoIdentificacion')->item(0);
if ($tipoIdentificacionElement) {
$persona->setTipoIdentificacion($tipoIdentificacionElement->nodeValue);
}
$idOtroElement = $element->getElementsByTagNameNS(self::XML_NAMESPACE, 'IDOtro')->item(0);
if ($idOtroElement) {
$persona->setIdOtro($idOtroElement->nodeValue);
}
$paisElement = $element->getElementsByTagNameNS(self::XML_NAMESPACE, 'Pais')->item(0);
if ($paisElement) {
$persona->setPais($paisElement->nodeValue);
}
return $persona;
}
}