-
Notifications
You must be signed in to change notification settings - Fork 51
/
Copy pathfactura.php
96 lines (81 loc) · 2.4 KB
/
factura.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
<?php
declare(strict_types=1);
use Greenter\Model\Response\BillResult;
use Greenter\Model\Sale\FormaPagos\FormaPagoContado;
use Greenter\Model\Sale\Invoice;
use Greenter\Model\Sale\SaleDetail;
use Greenter\Model\Sale\Legend;
use Greenter\Ws\Services\SunatEndpoints;
require __DIR__ . '/../vendor/autoload.php';
$util = Util::getInstance();
$invoice = new Invoice();
$invoice
->setUblVersion('2.1')
->setFecVencimiento(new DateTime())
->setTipoOperacion('0101')
->setTipoDoc('01')
->setSerie('F001')
->setCorrelativo('123')
->setFechaEmision(new DateTime())
->setFormaPago(new FormaPagoContado())
->setTipoMoneda('PEN')
->setCompany($util->shared->getCompany())
->setClient($util->shared->getClient())
->setMtoOperGravadas(200)
->setMtoOperExoneradas(100)
->setMtoIGV(36)
->setTotalImpuestos(36)
->setValorVenta(300)
->setSubTotal(336)
->setMtoImpVenta(336)
;
// Detalle gravado
$item1 = new SaleDetail();
$item1->setCodProducto('P001')
->setUnidad('NIU')
->setDescripcion('PROD 1')
->setCantidad(2)
->setMtoValorUnitario(100)
->setMtoValorVenta(200)
->setMtoBaseIgv(200)
->setPorcentajeIgv(18)
->setIgv(36)
->setTipAfeIgv('10') // Catalog: 07
->setTotalImpuestos(36)
->setMtoPrecioUnitario(118)
;
// Detalle Exonerado
$item2 = new SaleDetail();
$item2->setCodProducto('P002')
->setUnidad('KG')
->setDescripcion('PROD 2')
->setCantidad(2)
->setMtoValorUnitario(50)
->setMtoValorVenta(100)
->setMtoBaseIgv(100)
->setPorcentajeIgv(0)
->setIgv(0)
->setTipAfeIgv('20') // Catalog: 07
->setTotalImpuestos(0)
->setMtoPrecioUnitario(50)
;
$invoice->setDetails([$item1, $item2])
->setLegends([
(new Legend())
->setCode('1000')
->setValue('SON TRESCIENTOS TREINTA Y SEIS CON OO/100 SOLES')
]);
// Envio a SUNAT.
$see = $util->getSee(SunatEndpoints::FE_BETA);
/** Si solo desea enviar un XML ya generado utilice esta función**/
//$res = $see->sendXml(get_class($invoice), $invoice->getName(), file_get_contents($ruta_XML));
$res = $see->send($invoice);
$util->writeXml($invoice, $see->getFactory()->getLastXml());
if (!$res->isSuccess()) {
echo $util->getErrorResponse($res->getError());
exit();
}
/**@var $res BillResult*/
$cdr = $res->getCdrResponse();
$util->writeCdr($invoice, $res->getCdrZip());
$util->showResponse($invoice, $cdr);