function processXmlString($xmlString, $rideContent, $rideExtension, $rucReceptor, $basename) { $returnArray = array("status" => true, "html" => ""); $html = ""; $processed = true; $message = ""; // Crear arrays para cabecera/lineas $arrayCabecera = array(); $arrayLineas = array(); try { // Cargar estructura XML // Se deben verificar tres casos: // 1. Cuando la factura llega con las cabeceras de soap (root: RespuestaAutorizacionComprobante) // 2. Cuando la factura llega con el root element "autorizacion" // 3. Cuando la factura no llega aprobada descartarla de acuerdo al parámetro $xml = simplexml_load_string($xmlString, NULL, NULL, "http://schemas.xmlsoap.org/soap/envelope"); $root = $xml->xpath("//RespuestaAutorizacionComprobante"); if (!empty($root)) { $root = $xml->xpath("//RespuestaAutorizacionComprobante")[0]; $xml->registerXPathNamespace('soap', 'http://schemas.xmlsoap.org/soap/envelope/'); $xml->registerXPathNamespace('ns2', 'http://ec.gob.sri.ws.autorizacion'); $numeroAutorizacion = (string) $root->autorizaciones->autorizacion->numeroAutorizacion; $tmpValue = (string) $root->autorizaciones->autorizacion->comprobante; if (empty($tmpValue)) { $tmpValue = (string) $root->autorizaciones->comprobante; } } else { $root = $xml->xpath("//autorizacion"); if (!empty($root)) { $root = $root[0]; $numeroAutorizacion = (string) $root->numeroAutorizacion; $tmpValue = (string) $root->comprobante; } else { $root = $xml->xpath("//Autorizacion"); if (!empty($root)) { $root = $root[0]; $numeroAutorizacion = (string) $root->numeroAutorizacion; $tmpValue = (string) $root->comprobante; } else { if (FlowSettingsCore::get(FLOW_RECEPCIONDOCUMENTOS, "RDE_MC_SOLO_APROBADOS") == "0") { $root = $xml; $numeroAutorizacion = ""; $tmpValue = $root->asXml(); } else { $processed = false; $message = "Adjunto XML (" . $basename . "): Documento no se encuentra aprobado"; } } } } if ($processed) { $tmpString = (string) $tmpValue; $tmpString = str_replace("<", "<", $tmpString); $tmpString = str_replace(">", ">", $tmpString); $tmpString = str_replace("<![CDATA[", "", $tmpString); $tmpString = str_replace("]]>", "", $tmpString); $tmpString = preg_replace("/\r|\n/", "", $tmpString); $innerXml = simplexml_load_string($tmpString); $facturaValida = Documento::where('ruc', (string) $innerXml->infoTributaria->ruc)->where('estab', (string) $innerXml->infoTributaria->estab)->where('ptoEmi', (string) $innerXml->infoTributaria->ptoEmi)->where('secuencial', (string) $innerXml->infoTributaria->secuencial)->get(); if (count($facturaValida) == 0) { procesarDocumentoElectronico($innerXml, $numeroAutorizacion, $rucReceptor, $tmpString, $rideContent, $rideExtension, $xmlString); } else { $message = "Factura procesada previamente"; $processed = false; } } } catch (Exception $e) { $processed = false; $message = $e->getFile() . ":" . $e->getLine() . " / " . $e->getMessage(); } $html .= $message; $returnArray["status"] = $processed; $returnArray["html"] = $html; return $returnArray; }
/** * Initialize data */ public function getInitialData() { if (isset($this->task->task_request)) { $this->documento = Documento::where('ef_id', $this->task->task_request)->first(); } }