Skip to content

Commit ca0109d

Browse files
authored
Merge pull request #215 from thegreenter/gre-api-mejoras
GRE mejoras
2 parents 77a3974 + 5339ece commit ca0109d

4 files changed

Lines changed: 45 additions & 5 deletions

File tree

packages/data/src/Data/Generator/Despatch2022Store.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
use Greenter\Model\Despatch\Transportist;
2424
use Greenter\Model\Despatch\Vehicle;
2525
use Greenter\Model\DocumentInterface;
26+
use Greenter\Model\Sale\DetailAttribute;
2627

2728
class Despatch2022Store implements DocumentGeneratorInterface
2829
{
@@ -129,7 +130,20 @@ public function create(): ?DocumentInterface
129130
->setCodigo('PROD1')
130131
->setCodProdSunat('P001');
131132

132-
$despatch->setDetails([$detail]);
133+
$detail2 = new DespatchDetail();
134+
$detail2->setCantidad(0.123456789111) // xml formateará a 10 decimales
135+
->setUnidad('KGM')
136+
->setDescripcion('PROD 2')
137+
->setCodigo('PROD2')
138+
->setCodProdSunat('P002')
139+
->setAtributos([
140+
(new DetailAttribute())
141+
->setCode('01')
142+
->setName('CONCEPTO')
143+
->setValue('TEST')
144+
]);
145+
146+
$despatch->setDetails([$detail, $detail2]);
133147

134148
return $despatch;
135149
}

packages/lite/src/Greenter/Api.php

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ class Api
2121
{
2222
private ?ApiFactory $factory = null;
2323
private ?SignedXml $signer = null;
24+
private ?string $lastXml = null;
2425

2526
private array $credentials = [];
2627
private array $defaaultEndpoints = [
@@ -101,6 +102,16 @@ public function setCertificate(string $certificate): Api
101102
return $this;
102103
}
103104

105+
/**
106+
* Get Last XML Signed.
107+
*
108+
* @return string
109+
*/
110+
public function getLastXml(): ?string
111+
{
112+
return $this->lastXml;
113+
}
114+
104115
/**
105116
* Envia comprobante.
106117
*
@@ -113,11 +124,25 @@ public function send(DocumentInterface $document): ?BaseResult
113124
{
114125
$buildResolver = new XmlBuilderResolver($this->options);
115126
$builder = $buildResolver->find(get_class($document));
116-
$sender = $this->createSender();
117127

118128
$xml = $builder->build($document);
119-
$xmlSigned = $this->signer->signXml($xml);
120-
return $sender->send($document->getName(), $xmlSigned);
129+
$this->lastXml = $this->signer->signXml($xml);
130+
return $this->sendXml($document->getName(), $this->lastXml);
131+
}
132+
133+
/**
134+
* Enviar xml firmado.
135+
*
136+
* @param string $name
137+
* @param string $content
138+
* @return BaseResult|null
139+
* @throws ApiException
140+
*/
141+
public function sendXml(string $name, string $content): ?BaseResult
142+
{
143+
$sender = $this->createSender();
144+
145+
return $sender->send($name, $content);
121146
}
122147

123148
/**

packages/lite/tests/Greenter/ApiTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ public function testSend(): void
3131

3232
$this->assertTrue($result->isSuccess());
3333
$this->assertNotEmpty($result->getTicket());
34+
$this->assertNotEmpty($api->getLastXml());
3435

3536
$res = $api->getStatus($result->getTicket());
3637
$this->assertTrue($res->isSuccess());

packages/xml/src/Xml/Templates/despatch2022.xml.twig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@
219219
{% for det in doc.details %}
220220
<cac:DespatchLine>
221221
<cbc:ID>{{ loop.index }}</cbc:ID>
222-
<cbc:DeliveredQuantity unitCode="{{ det.unidad }}">{{ det.cantidad }}</cbc:DeliveredQuantity>
222+
<cbc:DeliveredQuantity unitCode="{{ det.unidad }}">{{ det.cantidad|n_format_limit(10) }}</cbc:DeliveredQuantity>
223223
<cac:OrderLineReference>
224224
<cbc:LineID>{{ loop.index }}</cbc:LineID>
225225
</cac:OrderLineReference>

0 commit comments

Comments
 (0)