diff --git a/api/contrib/check/check.php b/api/contrib/check/check.php index 23af08e..43eb045 100644 --- a/api/contrib/check/check.php +++ b/api/contrib/check/check.php @@ -60,7 +60,7 @@ function libxml_display_errors() } $tipoDoc = params_get('tipoDocumento'); - $tipos = array("FE", "ND", "NC", "TE", "CCE", "CPCE", "RCE","FEC"); + $tipos = array("FE", "ND", "NC", "TE", "CCE", "CPCE", "RCE","FEC, FEE"); grace_debug($tipoDoc); if (in_array($tipoDoc, $tipos)) @@ -69,7 +69,7 @@ function libxml_display_errors() { case 'FE': //Factura Electronica { - // Enable user error handling + // Enable user error handling libxml_use_internal_errors(true); $xml = new DOMDocument(); @@ -103,6 +103,9 @@ function libxml_display_errors() case 'FEC': // Factura Electronica de Compra $tipoDocumento = "08"; break; + case 'FEE': // Factura Electronica de Exportación + $tipoDocumento = "09"; + break; default: break; } diff --git a/api/contrib/clave/clave.php b/api/contrib/clave/clave.php index da27779..9370761 100644 --- a/api/contrib/clave/clave.php +++ b/api/contrib/clave/clave.php @@ -147,7 +147,7 @@ function getClave($tipoDocumento = "", $tipoCedula = "", $cedula = "", $situacio } $tipoDoc = params_get('tipoDocumento'); - $tipos = array("FE", "ND", "NC", "TE", "CCE", "CPCE", "RCE","FEC"); + $tipos = array("FE", "ND", "NC", "TE", "CCE", "CPCE", "RCE","FEC", "FEE"); grace_debug($tipoDoc); if (in_array($tipoDoc, $tipos)) { @@ -177,6 +177,9 @@ function getClave($tipoDocumento = "", $tipoCedula = "", $cedula = "", $situacio case 'FEC': // Factura Electronica de Compra $tipoDocumento = "08"; break; + case 'FEE': // Factura Electronica de Exportación + $tipoDocumento = "09"; + break; default: break; } diff --git a/api/contrib/genXML/genXML.php b/api/contrib/genXML/genXML.php index 688ae2a..a4e7188 100644 --- a/api/contrib/genXML/genXML.php +++ b/api/contrib/genXML/genXML.php @@ -19,12 +19,12 @@ /* * ************************************************** */ /* Constantes de validacion */ /* * ************************************************** */ -const TIPODOCREFVALUES = array('01','02','03','04','05','06','07','08','99'); +const TIPODOCREFVALUES = array('01', '02', '03', '04', '05', '06', '07', '08', '09', '99'); const CODIDOREFVALUES = array('01','02','04','05','99'); const CODIGOACTIVIDADSIZE = 6; const EMISORNOMBREMAXSIZE = 100; const RECEPTORNOMBREMAXSIZE = 100; -const RECEPTOROTRASSENASMAXSIZE = 250; +const RECEPTOROTRASSENASEXTRANJEROMAXSIZE = 250; /* * ************************************************** */ @@ -108,7 +108,7 @@ function genXMLFe() $detalles = json_decode(params_get("detalles")); $otrosCargos = json_decode(params_get("otrosCargos")); $mediosPago = json_decode(params_get("medios_pago")); - + grace_debug(params_get("detalles")); if ( isset($otrosCargos) && $otrosCargos != "") @@ -128,8 +128,8 @@ function genXMLFe() if (strlen($receptorNombre) > RECEPTORNOMBREMAXSIZE) error_log("receptorNombreMaxSize: ".RECEPTORNOMBREMAXSIZE." is greater than receptorNombre: ".$receptorNombre); - if (strlen($receptorOtrasSenas) > RECEPTOROTRASSENASMAXSIZE) - error_log("receptorOtrasSenasMaxSize: ".RECEPTOROTRASSENASMAXSIZE." is greater than receptorOtrasSenas: ".$receptorOtrasSenas); + if (strlen($receptorOtrasSenas) > RECEPTOROTRASSENASEXTRANJEROMAXSIZE) + error_log("RECEPTOROTRASSENASEXTRANJEROMAXSIZE: ".RECEPTOROTRASSENASEXTRANJEROMAXSIZE." is greater than receptorOtrasSenas: ".$receptorOtrasSenas); if ( isset($otrosCargos) && $otrosCargos != "") if (count($otrosCargos) > 15){ @@ -144,7 +144,6 @@ function genXMLFe() //Delimita el array a solo 4 elementos $mediosPago = array_slice($mediosPago, 0, 4); } - $xmlString = ' '; - $xmlString .= ' ' . $receptorNombre . ''; @@ -233,7 +231,7 @@ function genXMLFe() { $xmlString .= ' ' - . $receptorIdentifExtranjero. + . $receptorIdentifExtranjero. ''; } @@ -259,7 +257,7 @@ function genXMLFe() if ($receptorOtrasSenasExtranjero != '' && strlen($receptorOtrasSenasExtranjero) <= 300){ $xmlString .= ' ' - .$receptorOtrasSenasExtranjero. + .$receptorOtrasSenasExtranjero. ''; } /*}*/ @@ -299,13 +297,13 @@ function genXMLFe() ' . $medioPago . ''; else //mediosPago 4 nodos nada más - if ( isset($mediosPago) && $mediosPago != ""){ + if ( isset($mediosPago) && $mediosPago != ""){ foreach ($mediosPago as $o) { $xmlString .= '' . $o->codigo . ''; } } - + $xmlString .= ' '; @@ -372,7 +370,7 @@ function genXMLFe() ' . $d->detalle . ' ' . $d->precioUnitario . ' ' . $d->montoTotal . ''; - + if (isset($d->descuento) && $d->descuento != "" && $d->descuento != 0){ //Delimita el array a solo 5 elementos if (count($d->descuento) > 5){ @@ -417,13 +415,13 @@ function genXMLFe() ' . $i->codigo . ''; if ( isset($i->codigoTarifa) && $i->codigoTarifa != "" ) $xmlString .= '' . $i->codigoTarifa . ''; - + if ( isset($i->tarifa) && $i->tarifa != "") $xmlString .= '' . $i->tarifa . ''; - + if ( isset($i->factorIVA) && $i->factorIVA != "") $xmlString .= '' . $i->factorIVA . ''; - + $xmlString .= '' . $i->monto . ''; if (isset($i->exoneracion) && $i->exoneracion != "") @@ -465,14 +463,14 @@ function genXMLFe() '.$o->numeroIdentidadTercero.''; if ( isset($o->nombreTercero) && $o->nombreTercero != "") $xmlString .= ' - '.$o->nombreTercero.''; + '.$o->nombreTercero.''; $xmlString .= ' '.$o->detalle.''; if ( isset($o->porcentaje) && $o->porcentaje != "") $xmlString .= ' '.$o->porcentaje.''; $xmlString .= ' - '.$o->montoCargo.''; + '.$o->montoCargo.''; $xmlString .= ' '; } @@ -499,15 +497,15 @@ function genXMLFe() if ($totalServExonerados != '') $xmlString .= ' ' . $totalServExonerados . ''; - + if ($totalMercGravadas != '') $xmlString .= ' ' . $totalMercGravadas . ''; - + if ($totalMercExentas != '') $xmlString .= ' ' . $totalMercExentas . ''; - + if ($totalMercExonerada != '') $xmlString .= ' ' . $totalMercExonerada . ''; @@ -549,12 +547,12 @@ function genXMLFe() $xmlString .= ' ' . $totalComprobante . ' '; - + if ($infoRefeTipoDoc != '' && $infoRefeFechaEmision != ''){ $xmlString .= ' '; - + if(in_array($infoRefeTipoDoc, TIPODOCREFVALUES, true)) $xmlString .=' ' . $infoRefeTipoDoc . ''; @@ -579,7 +577,6 @@ function genXMLFe() return "El parámetro infoRefeCodigo no cumple con la estructura establecida."; } } - if ( isset($infoRefeRazon) && $infoRefeRazon != "") $xmlString .= ' @@ -693,7 +690,7 @@ function genXMLNC() if ( isset($otrosCargos) && $otrosCargos != "") grace_debug(params_get("otrosCargos")); - + if ( isset($mediosPago) && $mediosPago != "") grace_debug(params_get("medios_pago")); @@ -708,8 +705,8 @@ function genXMLNC() if (strlen($receptorNombre) > RECEPTORNOMBREMAXSIZE) error_log("receptorNombreMaxSize: ".RECEPTORNOMBREMAXSIZE." is greater than receptorNombre: ".$receptorNombre); - if (strlen($receptorOtrasSenas) > RECEPTOROTRASSENASMAXSIZE) - error_log("receptorOtrasSenasMaxSize: ".RECEPTOROTRASSENASMAXSIZE." is greater than receptorOtrasSenas: ".$receptorOtrasSenas); + if (strlen($receptorOtrasSenas) > RECEPTOROTRASSENASEXTRANJEROMAXSIZE) + error_log("RECEPTOROTRASSENASEXTRANJEROMAXSIZE: ".RECEPTOROTRASSENASEXTRANJEROMAXSIZE." is greater than receptorOtrasSenas: ".$receptorOtrasSenas); if ( isset($otrosCargos) && $otrosCargos != "") if (count($otrosCargos) > 15){ @@ -815,7 +812,7 @@ function genXMLNC() { $xmlString .= ' ' - . $receptorIdentifExtranjero. + . $receptorIdentifExtranjero. ''; } @@ -841,7 +838,7 @@ function genXMLNC() if ($receptorOtrasSenasExtranjero != '' && strlen($receptorOtrasSenasExtranjero) <= 300){ $xmlString .= ' ' - .$receptorOtrasSenasExtranjero. + .$receptorOtrasSenasExtranjero. ''; } @@ -871,7 +868,7 @@ function genXMLNC() $xmlString .= ' ' . $condVenta . ''; - + if ( isset($plazoCredito) && $plazoCredito != "" ) $xmlString .= ' ' . $plazoCredito . ''; @@ -887,7 +884,7 @@ function genXMLNC() $xmlString .= '' . $o->codigo . ''; } } - + $xmlString .= ' '; @@ -983,7 +980,7 @@ function genXMLNC() '; } } - + $xmlString .= '' . $d->subtotal . ''; if (isset($d->baseImponible) && $d->baseImponible != "") { @@ -998,18 +995,18 @@ function genXMLNC() if ( isset($i->codigoTarifa) && $i->codigoTarifa != "" ) $xmlString .= '' . $i->codigoTarifa . ''; - + if ( isset($i->tarifa) && $i->tarifa != "") $xmlString .= '' . $i->tarifa . ''; - + if ( isset($i->factorIVA) && $i->factorIVA != "") $xmlString .= '' . $i->factorIVA . ''; - $xmlString .= '' . $i->monto . ''; + $xmlString .= '' . $i->monto . ''; if ( isset($i->montoExportacion) && $i->montoExportacion != "") $xmlString .= '' . $i->montoExportacion . ''; - + if (isset($i->exoneracion) && $i->exoneracion != "") { $xmlString .= ' @@ -1020,7 +1017,6 @@ function genXMLNC() ' . $i->exoneracion->fechaEmision . ' ' . $i->exoneracion->porcentajeExoneracion . ' ' . $i->exoneracion->montoExoneracion . ' - '; } @@ -1051,7 +1047,7 @@ function genXMLNC() '.$o->numeroIdentidadTercero.''; if ( isset($o->nombreTercero) && $o->nombreTercero != "") $xmlString .= ' - '.$o->nombreTercero.''; + '.$o->nombreTercero.''; //if ( isset($o->detalle) && $o->detalle != "") $xmlString .= ' '.$o->detalle.''; @@ -1065,7 +1061,7 @@ function genXMLNC() '; } } - + $xmlString .= ' '; @@ -1087,15 +1083,15 @@ function genXMLNC() if ($totalServExonerados != '') $xmlString .= ' ' . $totalServExonerados . ''; - + if ($totalMercGravadas != '') $xmlString .= ' ' . $totalMercGravadas . ''; - + if ($totalMercExentas != '') $xmlString .= ' ' . $totalMercExentas . ''; - + if ($totalMercExonerada != '') $xmlString .= ' ' . $totalMercExonerada . ''; @@ -1168,7 +1164,7 @@ function genXMLNC() if ( isset($infoRefeRazon) && $infoRefeRazon != "") $xmlString .= ' ' . $infoRefeRazon . ''; - + $xmlString .= ' '; @@ -1291,8 +1287,8 @@ function genXMLND() if (strlen($receptorNombre) > RECEPTORNOMBREMAXSIZE) error_log("receptorNombreMaxSize: ".RECEPTORNOMBREMAXSIZE." is greater than receptorNombre: ".$receptorNombre); - if (strlen($receptorOtrasSenas) > RECEPTOROTRASSENASMAXSIZE) - error_log("receptorOtrasSenasMaxSize: ".RECEPTOROTRASSENASMAXSIZE." is greater than receptorOtrasSenas: ".$receptorOtrasSenas); + if (strlen($receptorOtrasSenas) > RECEPTOROTRASSENASEXTRANJEROMAXSIZE) + error_log("RECEPTOROTRASSENASEXTRANJEROMAXSIZE: ".RECEPTOROTRASSENASEXTRANJEROMAXSIZE." is greater than receptorOtrasSenas: ".$receptorOtrasSenas); if ( isset($otrosCargos) && $otrosCargos != "") if (count($otrosCargos) > 15){ @@ -1396,7 +1392,7 @@ function genXMLND() { $xmlString .= ' ' - . $receptorIdentifExtranjero. + . $receptorIdentifExtranjero. ''; } @@ -1417,11 +1413,11 @@ function genXMLND() ' . $receptorOtrasSenas . ' '; } - + if ($receptorOtrasSenasExtranjero != '' && strlen($receptorOtrasSenasExtranjero) <= 300){ $xmlString .= ' ' - .$receptorOtrasSenasExtranjero. + .$receptorOtrasSenasExtranjero. ''; } @@ -1451,7 +1447,7 @@ function genXMLND() $xmlString .= ' ' . $condVenta . ''; - + if ( isset($plazoCredito) && $plazoCredito != "" ) $xmlString .= ' ' . $plazoCredito . ''; @@ -1467,7 +1463,7 @@ function genXMLND() $xmlString .= '' . $o->codigo . ''; } } - + $xmlString .= ' '; @@ -1486,7 +1482,6 @@ function genXMLND() ' . $l . ''; if ( isset($d->partidaArancelaria) && $d->partidaArancelaria != "" ) $xmlString .= '' . $d->partidaArancelaria . ''; - if (isset($d->codigo) && $d->codigo != "") $xmlString .= ' @@ -1577,21 +1572,21 @@ function genXMLND() { $xmlString .= ' ' . $i->codigo . ''; - + if ( isset($i->codigoTarifa) && $i->codigoTarifa != "" ) $xmlString .= '' . $i->codigoTarifa . ''; - + if ( isset($i->tarifa) && $i->tarifa != "") $xmlString .= '' . $i->tarifa . ''; - + if ( isset($i->factorIVA) && $i->factorIVA != "") $xmlString .= '' . $i->factorIVA . ''; - $xmlString .= '' . $i->monto . ''; + $xmlString .= '' . $i->monto . ''; if ( isset($i->montoExportacion) && $i->montoExportacion != "") $xmlString .= '' . $i->montoExportacion . ''; - + if (isset($i->exoneracion) && $i->exoneracion != "") { $xmlString .= ' @@ -1631,7 +1626,7 @@ function genXMLND() '.$o->numeroIdentidadTercero.''; if ( isset($o->nombreTercero) && $o->nombreTercero != "") $xmlString .= ' - '.$o->nombreTercero.''; + '.$o->nombreTercero.''; $xmlString .= ' '.$o->detalle.''; if ( isset($o->porcentaje) && $o->porcentaje != "") @@ -1665,15 +1660,15 @@ function genXMLND() if ($totalServExonerados != '') $xmlString .= ' ' . $totalServExonerados . ''; - + if ($totalMercGravadas != '') $xmlString .= ' ' . $totalMercGravadas . ''; - + if ($totalMercExentas != '') $xmlString .= ' ' . $totalMercExentas . ''; - + if ($totalMercExonerada != '') $xmlString .= ' ' . $totalMercExonerada . ''; @@ -1718,7 +1713,7 @@ function genXMLND() $xmlString .= ' '; - + if(in_array($infoRefeTipoDoc, TIPODOCREFVALUES, true)) $xmlString .=' ' . $infoRefeTipoDoc . ''; @@ -1747,7 +1742,7 @@ function genXMLND() if ( isset($infoRefeRazon) && $infoRefeRazon != "") $xmlString .= ' ' . $infoRefeRazon . ''; - + $xmlString .= ' '; @@ -1872,8 +1867,8 @@ function genXMLTE() if (strlen($receptorNombre) > RECEPTORNOMBREMAXSIZE) error_log("receptorNombreMaxSize: ".RECEPTORNOMBREMAXSIZE." is greater than receptorNombre: ".$receptorNombre); - if (strlen($receptorOtrasSenas) > RECEPTOROTRASSENASMAXSIZE) - error_log("receptorOtrasSenasMaxSize: ".RECEPTOROTRASSENASMAXSIZE." is greater than receptorOtrasSenas: ".$receptorOtrasSenas); + if (strlen($receptorOtrasSenas) > RECEPTOROTRASSENASEXTRANJEROMAXSIZE) + error_log("RECEPTOROTRASSENASEXTRANJEROMAXSIZE: ".RECEPTOROTRASSENASEXTRANJEROMAXSIZE." is greater than receptorOtrasSenas: ".$receptorOtrasSenas); if ( isset($otrosCargos) && $otrosCargos != "") if (count($otrosCargos) > 15){ @@ -1987,7 +1982,7 @@ function genXMLTE() if ($receptorOtrasSenasExtranjero != '' && strlen($receptorOtrasSenasExtranjero) <= 300){ $xmlString .= ' ' - .$receptorOtrasSenasExtranjero. + .$receptorOtrasSenasExtranjero. ''; } @@ -2017,7 +2012,7 @@ function genXMLTE() $xmlString .= ' ' . $condVenta . ''; - + if ( isset($plazoCredito) && $plazoCredito != "" ) $xmlString .= ' ' . $plazoCredito . ''; @@ -2033,7 +2028,7 @@ function genXMLTE() $xmlString .= '' . $o->codigo . ''; } } - + $xmlString .=''; // cant - unidad medida - detalle - precio unitario - monto total - subtotal - monto total linea - Monto desc -Naturaleza Desc - Impuesto : Codigo / Tarifa / Monto @@ -2099,7 +2094,7 @@ function genXMLTE() ' . $d->unidadMedidaComercial . ''; $xmlString .= ' ' . $d->detalle . ' - ' . $d->precioUnitario . ' + ' . $d->precioUnitario . ' ' . $d->montoTotal . ''; if (isset($d->descuento) && $d->descuento != "" && $d->descuento != 0){ @@ -2149,14 +2144,14 @@ function genXMLTE() if ( isset($i->tarifa) && $i->tarifa != "") $xmlString .= ' ' . $i->tarifa . ''; - + if ( isset($i->factorIVA) && $i->factorIVA != "") $xmlString .= ' ' . $i->factorIVA . ''; - + $xmlString .= ' ' . $i->monto . ''; - + if (isset($i->exoneracion) && $i->exoneracion != "") { $xmlString .= ' @@ -2198,7 +2193,7 @@ function genXMLTE() '.$o->numeroIdentidadTercero.''; if ( isset($o->nombreTercero) && $o->nombreTercero != "") $xmlString .= ' - '.$o->nombreTercero.''; + '.$o->nombreTercero.''; //if ( isset($o->detalle) && $o->detalle != "") $xmlString .= ' '.$o->detalle.''; @@ -2234,15 +2229,15 @@ function genXMLTE() if ($totalServExonerados != '') $xmlString .= ' ' . $totalServExonerados . ''; - + if ($totalMercGravadas != '') $xmlString .= ' ' . $totalMercGravadas . ''; - + if ($totalMercExentas != '') $xmlString .= ' ' . $totalMercExentas . ''; - + if ($totalMercExonerada != '') $xmlString .= ' ' . $totalMercExonerada . ''; @@ -2284,7 +2279,7 @@ function genXMLTE() $xmlString .= ' ' . $totalComprobante . ' '; - + if ($infoRefeTipoDoc != '' && $infoRefeFechaEmision != ''){ $xmlString .= ' @@ -2475,7 +2470,7 @@ function genXMLFec() $detalles = json_decode(params_get("detalles")); $otrosCargos = json_decode(params_get("otrosCargos")); $mediosPago = json_decode(params_get("medios_pago")); - + grace_debug(params_get("detalles")); if ( isset($otrosCargos) && $otrosCargos != "") @@ -2495,8 +2490,8 @@ function genXMLFec() if (strlen($receptorNombre) > RECEPTORNOMBREMAXSIZE) error_log("receptorNombreMaxSize: ".RECEPTORNOMBREMAXSIZE." is greater than receptorNombre: ".$receptorNombre); - if (strlen($receptorOtrasSenas) > RECEPTOROTRASSENASMAXSIZE) - error_log("receptorOtrasSenasMaxSize: ".RECEPTOROTRASSENASMAXSIZE." is greater than receptorOtrasSenas: ".$receptorOtrasSenas); + if (strlen($receptorOtrasSenas) > RECEPTOROTRASSENASEXTRANJEROMAXSIZE) + error_log("RECEPTOROTRASSENASEXTRANJEROMAXSIZE: ".RECEPTOROTRASSENASEXTRANJEROMAXSIZE." is greater than receptorOtrasSenas: ".$receptorOtrasSenas); if ( isset($otrosCargos) && $otrosCargos != "") if (count($otrosCargos) > 15){ @@ -2511,7 +2506,6 @@ function genXMLFec() //Delimita el array a solo 4 elementos $mediosPago = array_slice($mediosPago, 0, 4); } - $xmlString = ' '; } @@ -2626,7 +2620,7 @@ function genXMLFec() if ($receptorOtrasSenasExtranjero != '' && strlen($receptorOtrasSenasExtranjero) <= 300){ $xmlString .= ' ' - .$receptorOtrasSenasExtranjero. + .$receptorOtrasSenasExtranjero. ''; } /*}*/ @@ -2666,13 +2660,13 @@ function genXMLFec() ' . $medioPago . ''; else //mediosPago 4 nodos nada más - if ( isset($mediosPago) && $mediosPago != ""){ + if ( isset($mediosPago) && $mediosPago != ""){ foreach ($mediosPago as $o) { $xmlString .= '' . $o->codigo . ''; } } - + $xmlString .= ' '; @@ -2739,7 +2733,7 @@ function genXMLFec() ' . $d->detalle . ' ' . $d->precioUnitario . ' ' . $d->montoTotal . ''; - + if (isset($d->descuento) && $d->descuento != "" && $d->descuento != 0){ //Delimita el array a solo 5 elementos if (count($d->descuento) > 5){ @@ -2784,13 +2778,13 @@ function genXMLFec() ' . $i->codigo . ''; if ( isset($i->codigoTarifa) && $i->codigoTarifa != "" ) $xmlString .= '' . $i->codigoTarifa . ''; - + if ( isset($i->tarifa) && $i->tarifa != "") $xmlString .= '' . $i->tarifa . ''; - + if ( isset($i->factorIVA) && $i->factorIVA != "") $xmlString .= '' . $i->factorIVA . ''; - + $xmlString .= '' . $i->monto . ''; if (isset($i->exoneracion) && $i->exoneracion != "") @@ -2832,14 +2826,14 @@ function genXMLFec() '.$o->numeroIdentidadTercero.''; if ( isset($o->nombreTercero) && $o->nombreTercero != "") $xmlString .= ' - '.$o->nombreTercero.''; + '.$o->nombreTercero.''; $xmlString .= ' '.$o->detalle.''; if ( isset($o->porcentaje) && $o->porcentaje != "") $xmlString .= ' '.$o->porcentaje.''; $xmlString .= ' - '.$o->montoCargo.''; + '.$o->montoCargo.''; $xmlString .= ' '; } @@ -2866,15 +2860,15 @@ function genXMLFec() if ($totalServExonerados != '') $xmlString .= ' ' . $totalServExonerados . ''; - + if ($totalMercGravadas != '') $xmlString .= ' ' . $totalMercGravadas . ''; - + if ($totalMercExentas != '') $xmlString .= ' ' . $totalMercExentas . ''; - + if ($totalMercExonerada != '') $xmlString .= ' ' . $totalMercExonerada . ''; @@ -2912,12 +2906,12 @@ function genXMLFec() $xmlString .= ' ' . $totalComprobante . ' '; - + if ($infoRefeTipoDoc != '' && $infoRefeFechaEmision != ''){ $xmlString .= ' '; - + if(in_array($infoRefeTipoDoc, TIPODOCREFVALUES, true)) $xmlString .=' ' . $infoRefeTipoDoc . ''; @@ -2942,7 +2936,6 @@ function genXMLFec() return "El parámetro infoRefeCodigo no cumple con la estructura establecida."; } } - if ( isset($infoRefeRazon) && $infoRefeRazon != "") $xmlString .= ' @@ -2975,6 +2968,563 @@ function genXMLFec() return $arrayResp; } +function genXMLFee() +{ + $clave = params_get("clave"); + $codigoActividad = params_get("codigo_actividad"); // https://cloud-cube.s3.amazonaws.com/sp5z9nxkd1ra/public/assets/json/actividades_por_codigo.json + $consecutivo = params_get("consecutivo"); + $fechaEmision = params_get("fecha_emision"); + $emisorNombre = params_get("emisor_nombre"); + $emisorTipoIdentif = params_get("emisor_tipo_identif"); + $emisorNumIdentif = params_get("emisor_num_identif"); + $emisorNombreComercial = params_get("emisor_nombre_comercial"); + $emisorProv = params_get("emisor_provincia"); + $emisorCanton = params_get("emisor_canton"); + $emisorDistrito = params_get("emisor_distrito"); + $emisorBarrio = params_get("emisor_barrio"); + $emisorOtrasSenas = params_get("emisor_otras_senas"); + $emisorCodPaisTel = params_get("emisor_cod_pais_tel"); + $emisorTel = params_get("emisor_tel"); + $emisorCodPaisFax = params_get("emisor_cod_pais_fax"); + $emisorFax = params_get("emisor_fax"); + $emisorEmail = params_get("emisor_email"); + $receptorNombre = params_get("receptor_nombre"); + $receptorTipoIdentif = params_get("receptor_tipo_identif"); + $receptorNumIdentif = params_get("receptor_num_identif"); + $receptorIdentifExtranjero = params_get("receptor_identif_extranjero"); + $receptorNombreComercial = params_get("receptor_nombre_comercial"); + $receptorOtrasSenasExtranjero = params_get("receptor_otras_senas_extranjero"); + $receptorCodPaisTel = params_get("receptor_cod_pais_tel"); + $receptorTel = params_get("receptor_tel"); + $receptorCodPaisFax = params_get("receptor_cod_pais_fax"); + $receptorFax = params_get("receptor_fax"); + $receptorEmail = params_get("receptor_email"); + $condVenta = params_get("condicion_venta"); + $plazoCredito = params_get("plazo_credito"); + $medioPago = json_decode(params_get("medio_pago")); + $detalles = json_decode(params_get("detalles")); + $otrosCargos = json_decode(params_get("otrosCargos")); + $codMoneda = params_get("cod_moneda"); + $tipoCambio = params_get("tipo_cambio"); + $totalServGravados = params_get("total_serv_gravados"); + $totalServExentos = params_get("total_serv_exentos"); + $totalMercGravadas = params_get("total_merc_gravada"); + $totalMercExentas = params_get("total_merc_exenta"); + $totalGravados = params_get("total_gravados"); + $totalExento = params_get("total_exento"); + $totalVentas = params_get("total_ventas"); + $totalDescuentos = params_get("total_descuentos"); + $totalVentasNeta = params_get("total_ventas_neta"); + $totalImp = params_get("total_impuestos"); + $totalOtrosCargos = params_get("totalOtrosCargos"); + $totalComprobante = params_get("total_comprobante"); + $infoRefeTipoDoc = params_get("infoRefeTipoDoc"); + $infoRefeNumero = params_get("infoRefeNumero"); + $infoRefeFechaEmision = params_get("infoRefeFechaEmision"); + $infoRefeCodigo = params_get("infoRefeCodigo"); + $infoRefeRazon = params_get("infoRefeRazon"); + $otros = json_decode(params_get("otros")); + + grace_debug(params_get("detalles")); + + if ( isset($otrosCargos) && $otrosCargos != "") + grace_debug(params_get("otrosCargos")); + + if ( isset($medioPago) && $medioPago != "") + grace_debug(params_get("medio_pago")); + + // Validate string sizes + $codigoActividad = str_pad($codigoActividad, 6, "0", STR_PAD_LEFT); + if (strlen($codigoActividad) != CODIGOACTIVIDADSIZE) + error_log("codigoActividadSize is: ".CODIGOACTIVIDADSIZE." and codigoActividad is ".$codigoActividad); + + if (strlen($emisorNombre) > EMISORNOMBREMAXSIZE) + error_log("emisorNombreSize: ".EMISORNOMBREMAXSIZE." is greater than emisorNombre: ".$emisorNombre); + + if (strlen($receptorNombre) > RECEPTORNOMBREMAXSIZE) + error_log("receptorNombreMaxSize: ".RECEPTORNOMBREMAXSIZE." is greater than receptorNombre: ".$receptorNombre); + + if (strlen($receptorOtrasSenasExtranjero) > RECEPTOROTRASSENASEXTRANJEROMAXSIZE) + error_log("RECEPTOROTRASSENASEXTRANJEROMAXSIZE: ".RECEPTOROTRASSENASEXTRANJEROMAXSIZE." is greater than receptorOtrasSenas: ".$receptorOtrasSenasExtranjero); + + if ( isset($otrosCargos) && !empty($otrosCargos)) + if (count($otrosCargos->otrosCargos) > 15){ + error_log("otrosCargos: ".count($otrosCargos->otrosCargos)." is greater than 15"); + //Delimita el array a solo 4 elementos + $otrosCargos->otrosCargos = array_slice($otrosCargos->otrosCargos, 0, 15); + } + + if ( isset($medioPago) && !empty($medioPago)) + if (count($medioPago->medioPago) > 4){ + error_log("medioPago: ".count($medioPago->medioPago)." is greater than 4"); + //Delimita el array a solo 4 elementos + $medioPago->medioPago = array_slice($medioPago->medioPago, 0, 4); + } + + $xmlString = ' + + ' . $clave . ' + ' . $codigoActividad . ' + ' . $consecutivo . ' + ' . $fechaEmision . ' + + ' . $emisorNombre . ' + + ' . $emisorTipoIdentif . ' + ' . $emisorNumIdentif . ' + '; + if ( isset($emisorNombreComercial) && $emisorNombreComercial != "") + $xmlString .= ' + ' . $emisorNombreComercial . ''; + + if ($emisorProv != '' && $emisorCanton != '' && $emisorDistrito != '' && $emisorOtrasSenas != '') + { + $xmlString .= ' + + ' . $emisorProv . ' + ' . $emisorCanton . ' + ' . $emisorDistrito . ''; + if ($emisorBarrio != '') + $xmlString .= '' . $emisorBarrio . ''; + $xmlString .= ' + ' . $emisorOtrasSenas . ' + '; + } + + if ($emisorCodPaisTel != '' && $emisorTel != '') + { + $xmlString .= ' + + ' . $emisorCodPaisTel . ' + ' . $emisorTel . ' + '; + } + + if ($emisorCodPaisFax != '' && $emisorFax != '') + { + $xmlString .= ' + + ' . $emisorCodPaisFax . ' + ' . $emisorFax . ' + '; + } + + $xmlString .= '' . $emisorEmail . ' + '; + + if (isset($receptorNombre) && $receptorNombre != "") { + $xmlString .= ' + ' . $receptorNombre . ''; + } + + if (isset($receptorTipoIdentif) && $receptorTipoIdentif != "" && isset($receptorNumIdentif) && $receptorNumIdentif != "") { + $xmlString .= ' + + ' . $receptorTipoIdentif . ' + ' . $receptorNumIdentif . ' + '; + } + + if ($receptorIdentifExtranjero != '' && $receptorIdentifExtranjero != '') + { + $xmlString .= ' + ' + . $receptorIdentifExtranjero. + ''; + } + + if ( isset($receptorNombreComercial) && $receptorNombreComercial != "") { + $xmlString .= ' + ' . $receptorNombreComercial . ''; + } + + if (isset($receptorProvincia) && $receptorProvincia != '' && $receptorCanton != '' && $receptorDistrito != '' && $receptorOtrasSenas != '') + { + $xmlString .= ' + + ' . $receptorProvincia . ' + ' . $receptorCanton . ' + ' . $receptorDistrito . ''; + if ($receptorBarrio != '') + $xmlString .= '' . $receptorBarrio . ''; + $xmlString .= ' + ' . $receptorOtrasSenas . ' + '; + } + + if ($receptorOtrasSenasExtranjero != '' && strlen($receptorOtrasSenasExtranjero) <= 300){ + $xmlString .= ' + ' + .$receptorOtrasSenasExtranjero. + ''; + } + + + if ($receptorCodPaisTel != '' && $receptorTel != '') + { + $xmlString .= ' + + ' . $receptorCodPaisTel . ' + ' . $receptorTel . ' + '; + } + + if ($receptorCodPaisFax != '' && $receptorFax != '') + { + $xmlString .= ' + + ' . $receptorCodPaisFax . ' + ' . $receptorFax . ' + '; + } + + if ($receptorEmail != '') { + $xmlString .= '' . $receptorEmail . ''; + $xmlString .= ''; + } + + + $xmlString .= ' + ' . $condVenta . ''; + + if ( isset($plazoCredito) && $plazoCredito != "" ) + $xmlString .= ' + ' . $plazoCredito . ''; + + // JSON DE EJEMPLO + // { + // "medioPago": [ + // "01", + // "02", + // "03" + // ] + // } + + if (isset($medioPago) && !empty($medioPago)) { + // Iteramos sobre los elementos de otroContenido + foreach ($medioPago->medioPago as $c) { + $xmlString .= '' . $c . ''; + } + } + + // XML Resultante + // 01 + // 02 + // 03 + + $xmlString .= ' + '; + + + $l = 1; + foreach ($detalles as $d) + { + $xmlString .= ' + + ' . $l . ''; + + if (isset($d->partidaArancelaria) && $d->partidaArancelaria != "") + $xmlString .= ' + ' . $d->partidaArancelaria . ''; + + if (isset($d->codigo) && $d->codigo != "") + $xmlString .= ' + ' . $d->codigo . ''; + + if (isset($d->codigoComercial) && !empty($d->codigoComercial)) { + // Convertir el objeto $d->codigoComercial en un array + $codigoComercialArray = (array)$d->codigoComercial; + + // Delimitar el array a solo 5 elementos + if (count($codigoComercialArray) > 5) { + error_log("codigoComercial: " . count($codigoComercialArray) . " is greater than 5"); + } + $codigoComercialArray = array_slice($codigoComercialArray, 0, 5); + + // Iterar sobre los elementos del array + foreach ($codigoComercialArray as $codigos) { + $c = (array)$codigos; + // Verificar si el elemento es un array asociativo + if (is_array($c) && isset($c['tipo']) && $c['tipo'] != "" && isset($c['codigo']) && $c['codigo'] != "") { + $xmlString .= ' + + ' . $c['tipo'] . ' + ' . $c['codigo'] . ' + '; + } + } + } + + + $xmlString .= ' + ' . $d->cantidad . ' + ' . $d->unidadMedida . ''; + if (isset($d->unidadMedidaComercial) && $d->unidadMedidaComercial != "") + $xmlString .= ' + ' . $d->unidadMedidaComercial . ''; + $xmlString .= ' + ' . $d->detalle . ' + ' . $d->precioUnitario . ' + ' . $d->montoTotal . ''; + + if (isset($d->descuento) && !empty($d->descuento)) { + // Convertir el objeto $d->descuento en un array + $descuentoArray = (array)$d->descuento; + + // Delimitar el array a solo 5 elementos + if (count($descuentoArray) > 5) { + error_log("descuento: " . count($descuentoArray) . " is greater than 5"); + } + $descuentoArray = array_slice($descuentoArray, 0, 5); + + // Iterar sobre los elementos del array + foreach ($descuentoArray as $descuentos) { + $c = (array)$descuentos; + // Verificar si el elemento es un array asociativo + if (is_array($c) && isset($c['montoDescuento']) && $c['montoDescuento'] != "" && isset($c['naturalezaDescuento']) && $c['naturalezaDescuento'] != "") { + $xmlString .= ' + + ' . $c['montoDescuento'] . ' + ' . $c['naturalezaDescuento'] . ' + '; + } + } + } + + $xmlString .= '' . $d->subTotal . ''; + + if (isset($d->impuesto) && $d->impuesto != "") + { + foreach ($d->impuesto as $i) + { + $xmlString .= ' + + ' . $i->codigo . ''; + if ( isset($i->codigoTarifa) && $i->codigoTarifa != "" ) + $xmlString .= '' . $i->codigoTarifa . ''; + + if ( isset($i->tarifa) && $i->tarifa != "") + $xmlString .= '' . $i->tarifa . ''; + + if ( isset($i->factorIVA) && $i->factorIVA != "") + $xmlString .= '' . $i->factorIVA . ''; + + $xmlString .= '' . $i->monto . ''; + + $xmlString .= '' . $i->montoExportacion . ''; + + $xmlString .= ''; + } + } + + if (isset($d->impuestoNeto) && $d->impuestoNeto != "") + { + $xmlString .= '' . $d->impuestoNeto . ''; + } + $xmlString .= '' . $d->montoTotalLinea . ''; + $xmlString .= ''; + $l++; + } + + $xmlString .= ''; + + // JSON DE EJEMPLO + // { + // "otrosCargos": [ + // { + // "detalle": "123", + // "montoCargo": "123", + // "porcentaje": "123", + // "tipoDocumento": "01" + // } + // ] + // } + + if (isset($otrosCargos) && !empty($otrosCargos)) { + // Iteramos sobre los elementos de otroContenido + foreach ($otrosCargos->otrosCargos as $o) { + $xmlString .= ' + + '.$o->tipoDocumento.''; + $xmlString .= ' + '.$o->detalle.''; + if ( isset($o->porcentaje) && $o->porcentaje != "") + $xmlString .= ' + '.$o->porcentaje.''; + $xmlString .= ' + '.$o->montoCargo.''; + $xmlString .= ' + '; + } + } + + // XML Resultante + // + // 01 + // 123 + // 123 + // 123 + // + + $xmlString .= ' + '; + + if ($codMoneda != '' && $tipoCambio != '' && $tipoCambio != 0) + $xmlString .= ' + + ' . $codMoneda . ' + ' . $tipoCambio . ' + '; + + if ($totalServGravados != '') + $xmlString .= ' + ' . $totalServGravados . ''; + + if ($totalServExentos != '') + $xmlString .= ' + ' . $totalServExentos . ''; + + if ($totalMercGravadas != '') + $xmlString .= ' + ' . $totalMercGravadas . ''; + + if ($totalMercExentas != '') + $xmlString .= ' + ' . $totalMercExentas . ''; + + if ($totalGravados != '') + $xmlString .= ' + ' . $totalGravados . ''; + + if ($totalExento != '') + $xmlString .= ' + ' . $totalExento . ''; + + $xmlString .= ' + ' . $totalVentas . ''; + + if ($totalDescuentos != '') + $xmlString .= ' + ' . $totalDescuentos . ''; + + $xmlString .= ' + ' . $totalVentasNeta . ''; + + if ($totalImp != '') + $xmlString .= ' + ' . $totalImp . ''; + + if ( isset($totalOtrosCargos) && $totalOtrosCargos != "") + $xmlString .= ' + ' . $totalOtrosCargos . ''; + + $xmlString .= ' + ' . $totalComprobante . ' + '; + + if ($infoRefeTipoDoc != '' && $infoRefeFechaEmision != ''){ + + $xmlString .= ' + '; + + if(in_array($infoRefeTipoDoc, TIPODOCREFVALUES, true)) + $xmlString .=' + ' . $infoRefeTipoDoc . ''; + else{ + grace_error("El parámetro infoRefeTipoDoc no cumple con la estructura establecida. infoRefeTipoDoc = ". $infoRefeTipoDoc); + return "El parámetro infoRefeTipoDoc no cumple con la estructura establecida."; + } + + if ( isset($infoRefeNumero) && $infoRefeNumero != "") + $xmlString .= ' + ' . $infoRefeNumero . ''; + + $xmlString .= ' + ' . $infoRefeFechaEmision . ''; + + if ( isset($infoRefeCodigo) && $infoRefeCodigo != ""){ + if(in_array($infoRefeCodigo, CODIDOREFVALUES, true)){ + $xmlString .= ' + ' . $infoRefeCodigo . ''; + }else{ + grace_error("El parámetro infoRefeCodigo no cumple con la estructura establecida. infoRefeCodigo = ". $infoRefeCodigo); + return "El parámetro infoRefeCodigo no cumple con la estructura establecida."; + } + } + + + if (isset($infoRefeRazon) && $infoRefeRazon != "") + $xmlString .= ' + ' . $infoRefeRazon . ''; + + $xmlString .= ' + '; + + } + + // // JSON de ejemplo + // { + // "otroContenido": [ + // { + // "codigo": "CONT1", + // "contenidoEstructurado": { + // "Elemento1": "Contenido 1", + // "Elemento2": "Contenido 2" + // } + // } + // ], + // "otroTexto": { + // "codigo": "COD1", + // "texto": "Texto opcional 1" + // } + // } + + if (isset($otros) && !empty($otros)) { + $xmlString .= ''; + + // Comprobamos si existe la propiedad "otroTexto" + if (isset($otros->otroTexto)) { + $xmlString .= '' . $otros->otroTexto->texto . ''; + } + + // Comprobamos si existe la propiedad "otroContenido" + if (isset($otros->otroContenido)) { + // Iteramos sobre los elementos de otroContenido + foreach ($otros->otroContenido as $item) { + $xmlString .= ''; + // Iteramos sobre el contenido estructurado de cada elemento + foreach ($item->contenidoEstructurado as $element => $content) { + $xmlString .= '<' . $element . '>' . $content . ''; + } + $xmlString .= ''; + } + } + + $xmlString .= ''; + } + + // XML Resultante + // + // Texto opcional 1 + // + // Contenido 1 + // Contenido 2 + // + // + + $xmlString .= ' + '; + $arrayResp = array( + "clave" => $clave, + "xml" => base64_encode($xmlString) + ); + + return $arrayResp; +} + /* * ************************************************** */ /* Funcion de prueba */ diff --git a/api/contrib/genXML/module.php b/api/contrib/genXML/module.php index 00499f7..4df34fc 100644 --- a/api/contrib/genXML/module.php +++ b/api/contrib/genXML/module.php @@ -421,6 +421,69 @@ function genXML_init() ), 'file' => 'genXML.php' ), + array( + 'r' => 'gen_xml_fee', + 'action' => 'genXMLFee', + 'access' => 'users_openAccess', + 'access_params' => 'accessName', + 'params' => array( + array("key" => "clave", "def" => "", "req" => true), + array("key" => "codigo_actividad", "def" => "", "req" => true), + array("key" => "consecutivo", "def" => "", "req" => true), + array("key" => "fecha_emision", "def" => "", "req" => true), + array("key" => "emisor_nombre", "def" => "", "req" => true), + array("key" => "emisor_tipo_identif", "def" => "", "req" => true), + array("key" => "emisor_num_identif", "def" => "", "req" => true), + array("key" => "emisor_nombre_comercial", "def" => "", "req" => false), + array("key" => "emisor_provincia", "def" => "", "req" => true), + array("key" => "emisor_canton", "def" => "", "req" => true), + array("key" => "emisor_distrito", "def" => "", "req" => true), + array("key" => "emisor_barrio", "def" => "", "req" => false), + array("key" => "emisor_otras_senas", "def" => "", "req" => true), + array("key" => "emisor_cod_pais_tel", "def" => "", "req" => false), + array("key" => "emisor_tel", "def" => "", "req" => false), + array("key" => "emisor_cod_pais_fax", "def" => "", "req" => false), + array("key" => "emisor_fax", "def" => "", "req" => false), + array("key" => "emisor_email", "def" => "", "req" => true), + array("key" => "receptor_nombre", "def" => "", "req" => false), + array("key" => "receptor_tipo_identif", "def" => "", "req" => false), + array("key" => "receptor_num_identif", "def" => "", "req" => false), + array("key" => "receptor_identif_extranjero", "def" => "", "req" => false), + array("key" => "receptor_nombre_comercial", "def" => "", "req" => false), + array("key" => "receptor_otras_senas_extranjero", "def" => "", "req" => false), + array("key" => "receptor_cod_pais_tel", "def" => "", "req" => false), + array("key" => "receptor_tel", "def" => "", "req" => false), + array("key" => "receptor_cod_pais_fax", "def" => "", "req" => false), + array("key" => "receptor_fax", "def" => "", "req" => false), + array("key" => "receptor_email", "def" => "", "req" => false), + array("key" => "condicion_venta", "def" => "", "req" => true), + array("key" => "plazo_credito", "def" => "", "req" => false), + array("key" => "medio_pago", "def" => "", "req" => false), + array("key" => "detalles", "def" => "", "req" => true), + array("key" => "otrosCargos", "def" => "", "req" => false), + array("key" => "cod_moneda", "def" => "", "req" => false), + array("key" => "tipo_cambio", "def" => "", "req" => false), + array("key" => "total_serv_gravados", "def" => "", "req" => false), + array("key" => "total_serv_exentos", "def" => "", "req" => false), + array("key" => "total_merc_gravada", "def" => "", "req" => false), + array("key" => "total_merc_exenta", "def" => "", "req" => false), + array("key" => "total_gravados", "def" => "", "req" => false), + array("key" => "total_exento", "def" => "", "req" => false), + array("key" => "total_ventas", "def" => "", "req" => true), + array("key" => "total_descuentos", "def" => "", "req" => false), + array("key" => "total_ventas_neta", "def" => "", "req" => true), + array("key" => "total_impuestos", "def" => "", "req" => false), + array("key" => "totalOtrosCargos", "def" => "", "req" => false), + array("key" => "total_comprobante", "def" => "", "req" => true), + array("key" => "infoRefeTipoDoc", "def" => "", "req" => false), + array("key" => "infoRefeNumero", "def" => "", "req" => false), + array("key" => "infoRefeFechaEmision", "def" => "", "req" => false), + array("key" => "infoRefeCodigo", "def" => "", "req" => false), + array("key" => "infoRefeRazon", "def" => "", "req" => false), + array("key" => "otros", "def" => "", "req" => false) + ), + 'file' => 'genXML.php' + ), array( 'r' => 'test', 'action' => 'test', diff --git a/api/contrib/genXML/xmlGenerator.php b/api/contrib/genXML/xmlGenerator.php index 0c91c6c..2e14cff 100644 --- a/api/contrib/genXML/xmlGenerator.php +++ b/api/contrib/genXML/xmlGenerator.php @@ -185,6 +185,11 @@ function genXML() $headerDoc=' '; $footerDoc=''; } + elseif ($tipoDocumento == 'FEE') + { + $headerDoc=' '; + $footerDoc=''; + } $finalXML= $headerDoc . $xmltext . $footerDoc; return $finalXML; diff --git a/api/core/modules.php b/api/core/modules.php index bf185fe..c00b49b 100644 --- a/api/core/modules.php +++ b/api/core/modules.php @@ -37,7 +37,6 @@ function modules_getPath($which) function modules_loader($which, $file = 'module.php', $boot = true) { $path = modules_getPath($which); - grace_debug("Loading in path: " . $path . "/" . $file); # Load the module and the config if one exists diff --git a/www/api.php b/www/api.php index a6d9a25..55ca6a0 100644 --- a/www/api.php +++ b/www/api.php @@ -83,7 +83,7 @@ grace_debug("Adding to post: $key => $val"); } - params_set('w', $_POST); + params_set('w', $_POST); } $r = boot_itUp();