Working of feature flow of verifactu
This commit is contained in:
parent
ee775e58a0
commit
f7055b516e
|
|
@ -36,6 +36,8 @@ class Verifactu extends AbstractService
|
|||
|
||||
private AeatClient $aeat_client;
|
||||
|
||||
private string $soapXml;
|
||||
|
||||
public function __construct(public Invoice $invoice)
|
||||
{
|
||||
$this->aeat_client = new AeatClient();
|
||||
|
|
@ -52,15 +54,16 @@ class Verifactu extends AbstractService
|
|||
$v_logs = $this->invoice->verifactu_logs;
|
||||
|
||||
//determine the current status of the invoice.
|
||||
$document = new RegistroAlta($this->invoice);
|
||||
$document = (new RegistroAlta($this->invoice))->run()->getInvoice();
|
||||
|
||||
$huella = '';
|
||||
|
||||
nlog($v_logs->count());
|
||||
//1. new => RegistraAlta
|
||||
if($v_logs->count() >= 1){
|
||||
$v_log = $v_logs->first();
|
||||
$huella = $v_log->hash;
|
||||
$document = InvoiceModification::createFromInvoice($document->getInvoice(), $v_log->deserialize());
|
||||
$document = InvoiceModification::createFromInvoice($document, $v_log->deserialize());
|
||||
}
|
||||
|
||||
//3. cancelled => RegistroAnulacion
|
||||
|
|
@ -68,12 +71,24 @@ class Verifactu extends AbstractService
|
|||
$new_huella = $this->calculateHash($document, $huella); // careful with this! we'll need to reference this later
|
||||
$document->setHuella($new_huella);
|
||||
|
||||
$soapXml = $document->toSoapEnvelope();
|
||||
$this->setEnvelope($document->toSoapEnvelope());
|
||||
|
||||
|
||||
return $this;
|
||||
|
||||
}
|
||||
|
||||
public function getEnvelope(): string
|
||||
{
|
||||
return $this->soapXml;
|
||||
}
|
||||
|
||||
private function setEnvelope(string $soapXml): self
|
||||
{
|
||||
$this->soapXml = $soapXml;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* calculateHash
|
||||
*
|
||||
|
|
@ -83,8 +98,9 @@ class Verifactu extends AbstractService
|
|||
*/
|
||||
public function calculateHash($document, string $huella): string
|
||||
{
|
||||
nlog($document->toXmlString());
|
||||
$idEmisorFactura = $document->getIdEmisorFactura();
|
||||
$numSerieFactura = $document->getNumSerieFactura();
|
||||
$numSerieFactura = $document->getIdFactura();
|
||||
$fechaExpedicionFactura = $document->getFechaExpedicionFactura();
|
||||
$tipoFactura = $document->getTipoFactura();
|
||||
$cuotaTotal = $document->getCuotaTotal();
|
||||
|
|
|
|||
|
|
@ -284,6 +284,11 @@ class Invoice extends BaseXmlModel implements XmlModelInterface
|
|||
return $this;
|
||||
}
|
||||
|
||||
public function getIdEmisorFactura(): string
|
||||
{
|
||||
return $this->tercero->getNif();
|
||||
}
|
||||
|
||||
public function getDestinatarios(): ?array
|
||||
{
|
||||
return $this->destinatarios;
|
||||
|
|
|
|||
|
|
@ -201,7 +201,6 @@ class RegistroAlta
|
|||
|
||||
$this->v_invoice->setSistemaInformatico($sistema);
|
||||
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ use App\DataMapper\InvoiceItem;
|
|||
use App\DataMapper\ClientSettings;
|
||||
use App\DataMapper\CompanySettings;
|
||||
use App\Factory\CompanyUserFactory;
|
||||
use App\Services\EDocument\Standards\Verifactu;
|
||||
|
||||
class VerifactuFeatureTest extends TestCase
|
||||
{
|
||||
|
|
@ -161,10 +162,24 @@ class VerifactuFeatureTest extends TestCase
|
|||
|
||||
public function test_construction_and_validation()
|
||||
{
|
||||
// - current previous hash - 10C643EDC7DC727FAC6BAEBAAC7BEA67B5C1369A5A5ED74E5AD3149FC30A3C8C
|
||||
// - current previous invoice number - TEST0033343443
|
||||
|
||||
$invoice = $this->buildData();
|
||||
|
||||
$invoice->number = 'TEST0033343444';
|
||||
$invoice->save();
|
||||
|
||||
$this->assertNotNull($invoice);
|
||||
|
||||
$verifactu = new Verifactu($invoice);
|
||||
$verifactu->run();
|
||||
|
||||
$envelope = $verifactu->getEnvelope();
|
||||
|
||||
$this->assertNotEmpty($envelope);
|
||||
|
||||
nlog($envelope);
|
||||
}
|
||||
|
||||
public function testInvoiceCancellation()
|
||||
|
|
|
|||
Loading…
Reference in New Issue