Skip to content

Commit

Permalink
Se agrega parseador para retencion de comprobante
Browse files Browse the repository at this point in the history
  • Loading branch information
leip1493 committed Oct 11, 2019
1 parent 91ea4a8 commit 832b2f5
Show file tree
Hide file tree
Showing 9 changed files with 276 additions and 276 deletions.
57 changes: 57 additions & 0 deletions ComprobanteRetencionParser.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php require_once 'XmlParser.php' ?>
<?php

class ComprobanteRetencionParser extends XmlParser{
public function __construct(DOMDocument $dom)
{
parent::__construct($dom);
}

public function getInfoCompRetencion(){
$infoComprobanteContent = [
'fechaEmision', 'contribuyenteEspecial',
'obligadoContabilidad', 'tipoIdentificacionSujetoRetenido',
'razonSocialSujetoRetenido', 'identificacionSujetoRetenido',
'periodoFiscal'
];
$infoComprobante = $this->getNode($this->dom, 'infoCompRetencion', 0);
$infoComprobanteData = [];
foreach ($infoComprobanteContent as $content) {
$infoComprobanteData[$content] = $this->getNodeData($infoComprobante, $content, 0);
}
return $infoComprobanteData;
}

public function getImpuestos(){
$impuestos = $this->getNode($this->dom, 'impuestos', 0);
$impuesto = $this->getNodes($this->dom, 'impuesto');
$impuestoHeaders = [
'codigo', 'codigoRetencion', 'baseImponible', 'porcentajeRetener',
'valorRetenido', 'codDocSustento', 'numDocSustento', 'fechaEmisionDocSustento'
];
$impuestosContent = [];
foreach ($impuesto as $index => $imp) {
$rowImpuesto = [];
foreach ($impuestoHeaders as $header) {
$rowImpuesto[$header] = $this->getNodeData($imp, $header, 0);
}
$impuestosContent[$index] = $rowImpuesto;
}
return $impuestosContent;
}

public function getInfoAdicional(){
$infoAdicional = $this->getNode($this->dom, 'infoAdicional', 0);
$campoAdicional = $this->getNodes($this->dom, 'campoAdicional');
$detallesContent = [];
foreach ($campoAdicional as $index => $campo) {
$detallesContent[$index] = [
'name' => $campo->getAttribute('nombre'),
'value' => $campo->nodeValue

];
}
return $detallesContent;
}

}
164 changes: 0 additions & 164 deletions factura.xml

This file was deleted.

132 changes: 20 additions & 112 deletions index.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
<?php require_once 'XmlParser.php' ?>
<?php require_once 'FacturaParser.php' ?>
<?php require_once 'NotaCreditoParser.php' ?>
<?php require_once 'ComprobanteRetencionParser.php' ?>
<?php

try {
$clave_acc = "0509201901179242984600120020052050754120054076917"; // FACTURA
// $clave_acc = "0809201901099133185900120230150009498921357246816"; // FACTURA
$clave_acc = "2608201901019038904900120010020000019611234567816"; // FACTURA
// $clave_acc = "2608201901019038904900120010020000019611234567816"; // FACTURA
// $clave_acc = "2608201904179037150600120020210000994710009947118"; // NOTA DE CREDITO
// $clave_acc = "2608201904099236486600120020020000004490000044918"; // NOTA DE CREDITO
$clave_acc = "2608201904099236486600120020020000004490000044918"; // NOTA DE CREDITO
// $clave_acc = "2608201907179009835400120010050030421340000000111"; // COMPROBANTE DE RETENCION
// $clave_acc = "2608201907179009835400120010050030410160000000111"; // COMPROBANTE DE RETENCION


// $input = readline("Ingrese clave de acceso a consultar: ");
Expand Down Expand Up @@ -44,7 +47,6 @@

// echo $client->__getLastRequest();
$autorizacionComprobante = $response->RespuestaAutorizacionComprobante;
print_r($response);

if(!$autorizacionComprobante->numeroComprobantes){
throw new Exception("No hay comprobantes para estos datos");
Expand Down Expand Up @@ -91,124 +93,30 @@
print_r($notaCreditoParser->getInfoAdicional());
echo "<hr>";
}

elseif ($infoTributaria["codDoc"] == XmlParser::COMPROBANTE_RETENCION) { // Comprobante de retencion

$comprobanteRetencon = new ComprobanteRetencionParser($dom);

echo "Info Comprobante retencion<br>";
print_r($comprobanteRetencon->getInfoCompRetencion());
echo "<hr>";

echo "Impuestos <br>";
print_r($comprobanteRetencon->getImpuestos());
echo "<hr>";

echo "Info adicional <br>";
print_r($comprobanteRetencon->getInfoAdicional());
echo "<hr>";

die("EL ARCHIVO ES UN COMPROBANTE DE RETENCION");
}
else{
print_r($response);
die("FIN");
die("Tipo de documento no reconocido: " . $infoTributaria['codDoc']);
}

print_r($response);

echo "Tiempo de ejecucion de consulta: " . (time() - $timeStart) . " segundos";

} catch (Exception $e) {
die($e->getMessage());
}
//////////////////////////
// METODOS NOTA CREDITO //
//////////////////////////
// ///PUBLIC
// function getInfoNotaCredito($dom){
// $infoFacturaContent = [
// 'fechaEmision', 'dirEstablecimiento',
// 'tipoIdentificacionComprador', 'razonSocialComprador',
// 'identificacionComprador', 'contribuyenteEspecial',
// 'obligadoContabilidad', 'codDocModificado',
// 'numDocModificado', 'fechaEmisionDocSustento',
// 'totalSinImpuestos', 'valorModificacion',
// 'moneda', 'motivo',
// 'totalConImpuestos'
// ];
// $infoFactura = getNode($dom, 'infoNotaCredito', 0);
// $infoFacturaData = [];
// foreach ($infoFacturaContent as $content) {
// $infoFacturaData[$content] = getNodeData($infoFactura, $content, 0);
// }
// $infoFacturaData['totalConImpuestos'] = getInfoNotaCreditoImpuestos($dom);
// // $infoFacturaData['pagos'] = getInfoFacturaPagos();
// return $infoFacturaData;
// }
// function getDetalles($dom){
// $detalles = getNode($dom, 'detalles', 0);
// $detalle = getNodes($dom, 'detalle');
// $detalleHeaders = [
// 'codigoInterno', 'descripcion', 'cantidad', 'precioUnitario', 'descuento', 'precioTotalSinImpuesto', 'impuestos',
// ];
// $detallesContent = [];
// foreach ($detalle as $index => $d) {
// $rowDetalle = [];
// foreach ($detalleHeaders as $header) {
// $rowDetalle[$header] = getNodeData($d, $header, 0);
// }
// $rowDetalle['impuestos'] = getDetallesImpuestos($dom, $index);
// $detallesContent[$index] = $rowDetalle;
// }
// return $detallesContent;
// }
// function getInfoAdicional($dom){
// $infoAdicional = getNode($dom, 'infoAdicional', 0);
// $campoAdicional = getNodes($dom, 'campoAdicional');
// $detallesContent = [];
// foreach ($campoAdicional as $index => $campo) {
// $detallesContent[$index] = [
// 'name' => $campo->getAttribute('nombre'),
// 'value' => $campo->nodeValue

// ];
// }
// return $detallesContent;
// }
// // PRIVATE
// function getInfoNotaCreditoImpuestos($dom){
// $totalConImpuestos = getNode($dom, 'totalConImpuestos', 0);
// $totalImpuestos = getNodes($dom, 'totalImpuesto');
// $totalImpuestoHeaders = [
// 'codigo', 'codigoPorcentaje', 'baseImponible', 'valor'
// ];
// $totalImpuestoContent = [];
// foreach ($totalImpuestos as $index => $totalImpuesto) {
// $rowImpuesto = [];
// foreach ($totalImpuestoHeaders as $header) {
// $rowImpuesto[$header] = getNodeData($totalImpuesto, $header, 0);
// }
// $totalImpuestoContent[$index] = $rowImpuesto;
// }

// return $totalImpuestoContent;
// }
// function getDetallesImpuestos($dom, $position){
// $impuestos = getNode($dom, 'impuestos', $position);
// $impuesto = getNodes($dom, 'impuesto');
// $impuestoHeaders = [
// 'codigo', 'codigoPorcentaje', 'tarifa', 'baseImponible', 'valor'
// ];
// $impuestoContent = [];
// foreach ($impuesto as $index => $i) {
// $rowImpuesto = [];
// foreach ($impuestoHeaders as $header) {
// $rowImpuesto[$header] = getNodeData($i, $header, 0);
// }
// $impuestoContent[$index] = $rowImpuesto;
// }
// return $impuestoContent;
// }

/////////////////
// DOM GETTERs //
/////////////////
function getNodes($parent, $child){
return $parent->getElementsByTagName($child);
}

function getNode($parent, $child, $position){
return getNodes($parent,$child)->item($position);
}

function getNodeData($parent, $child, $position){
$node = getNode($parent,$child, $position);
return $node ? $node->nodeValue: "";
}
Loading

0 comments on commit 832b2f5

Please sign in to comment.