Skip to content

Commit

Permalink
Merge pull request #215 from thegreenter/gre-api-mejoras
Browse files Browse the repository at this point in the history
GRE mejoras
  • Loading branch information
giansalex authored Jan 12, 2023
2 parents 77a3974 + 5339ece commit ca0109d
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 5 deletions.
16 changes: 15 additions & 1 deletion packages/data/src/Data/Generator/Despatch2022Store.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
use Greenter\Model\Despatch\Transportist;
use Greenter\Model\Despatch\Vehicle;
use Greenter\Model\DocumentInterface;
use Greenter\Model\Sale\DetailAttribute;

class Despatch2022Store implements DocumentGeneratorInterface
{
Expand Down Expand Up @@ -129,7 +130,20 @@ public function create(): ?DocumentInterface
->setCodigo('PROD1')
->setCodProdSunat('P001');

$despatch->setDetails([$detail]);
$detail2 = new DespatchDetail();
$detail2->setCantidad(0.123456789111) // xml formateará a 10 decimales
->setUnidad('KGM')
->setDescripcion('PROD 2')
->setCodigo('PROD2')
->setCodProdSunat('P002')
->setAtributos([
(new DetailAttribute())
->setCode('01')
->setName('CONCEPTO')
->setValue('TEST')
]);

$despatch->setDetails([$detail, $detail2]);

return $despatch;
}
Expand Down
31 changes: 28 additions & 3 deletions packages/lite/src/Greenter/Api.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class Api
{
private ?ApiFactory $factory = null;
private ?SignedXml $signer = null;
private ?string $lastXml = null;

private array $credentials = [];
private array $defaaultEndpoints = [
Expand Down Expand Up @@ -101,6 +102,16 @@ public function setCertificate(string $certificate): Api
return $this;
}

/**
* Get Last XML Signed.
*
* @return string
*/
public function getLastXml(): ?string
{
return $this->lastXml;
}

/**
* Envia comprobante.
*
Expand All @@ -113,11 +124,25 @@ public function send(DocumentInterface $document): ?BaseResult
{
$buildResolver = new XmlBuilderResolver($this->options);
$builder = $buildResolver->find(get_class($document));
$sender = $this->createSender();

$xml = $builder->build($document);
$xmlSigned = $this->signer->signXml($xml);
return $sender->send($document->getName(), $xmlSigned);
$this->lastXml = $this->signer->signXml($xml);
return $this->sendXml($document->getName(), $this->lastXml);
}

/**
* Enviar xml firmado.
*
* @param string $name
* @param string $content
* @return BaseResult|null
* @throws ApiException
*/
public function sendXml(string $name, string $content): ?BaseResult
{
$sender = $this->createSender();

return $sender->send($name, $content);
}

/**
Expand Down
1 change: 1 addition & 0 deletions packages/lite/tests/Greenter/ApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public function testSend(): void

$this->assertTrue($result->isSuccess());
$this->assertNotEmpty($result->getTicket());
$this->assertNotEmpty($api->getLastXml());

$res = $api->getStatus($result->getTicket());
$this->assertTrue($res->isSuccess());
Expand Down
2 changes: 1 addition & 1 deletion packages/xml/src/Xml/Templates/despatch2022.xml.twig
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@
{% for det in doc.details %}
<cac:DespatchLine>
<cbc:ID>{{ loop.index }}</cbc:ID>
<cbc:DeliveredQuantity unitCode="{{ det.unidad }}">{{ det.cantidad }}</cbc:DeliveredQuantity>
<cbc:DeliveredQuantity unitCode="{{ det.unidad }}">{{ det.cantidad|n_format_limit(10) }}</cbc:DeliveredQuantity>
<cac:OrderLineReference>
<cbc:LineID>{{ loop.index }}</cbc:LineID>
</cac:OrderLineReference>
Expand Down

0 comments on commit ca0109d

Please sign in to comment.