Borrador, 1 -> Timbrado, 2 -> Cancelado public $status_guardado = 0; // 0 -> Sin guardar, 1 -> Guardado public $numero_monedas = 0; public $cfdi_relacionado = array( "uuid" => "", "fk_pago_rel" => "" ); public $datos_complemento = array( "fk_facture" => 0, "fecha_pago" => "", "fecha" => "", "hora" => "", "forma_pago" => -1, "moneda" => "", "monto" => "", "tipo_cambio" => "", "numero_operacion" => "", "rfc_cta_ordenante" => "", "nom_banco_ordenante" => "", "cta_ordenante" => "", "rfc_cta_beneficiario" => "", "cta_beneficiario" => "", "tipo_cadena_pago" => "", "certificado_pago" => "", "cadena_original_comprobante_pago" => "", "sello_pago" => "", "tipo_relacion" => "", "uuid" => "", "xml" => "", "cadena" => "", "version" => "", "selloCFD" => "", "certificado" => "", "sello" => "", "certEmisor" => "", "cancelado" => "", "fecha_emision" => "", "hora_emision" => "", "entity" => "", "rel_facture" => "" ); public $doc_relacionado = array( "rowid" => 0, "uuid" => "", "moneda" => "", "metodo_pago" => "", "tipo_cambio" => "", "parcialidad" => "", "importe_anterior" => "", "importe_pagado" => "", "importe_insoluto" => "", "equivalencia" => "", "impuestos" => array() ); public $lista_cfdi_relacionados = array(); public $lista_doc_relacionados = array(); public $omitir_pagos = array(); public $folios = array( "timbrados" => 0, "adquiridos" => 0, "disponibles" => 0 ); public $num_solicitudes_cancelacion = 0; public $solicitud_cancelacion = array( ); public $lista_archivo_vinculados = array(); public $lista_facturas_correo = array(); public $info_estatus = array( "registro" => 0, "estado_cfdi" => "", "estatus_cancelacion" => "", "fecha_consulta_estatus" => "" ); public $datos_emisor = array(); public $conf_ws = array( "estatus" => "", "modo_timbrado" => "", "pass_timbrado" => "" ); public $ret_locales = array(); public $formas_pago = array(); public $ajustes_opc = array(); public $carga_masiva = array(); public $lista_val_doc_rel = array(); public function __construct($db){ global $conf; $this->db = $db; $this->doli_version = DOL_VERSION; ##Determinar el # de Monedas que se utilizan $select_monedas = "SELECT * FROM ".MAIN_DB_PREFIX."multicurrency WHERE entity = ".$conf->entity; $res_select_monedas = $this->db->query($select_monedas); $this->numero_monedas = $this->db->num_rows($res_select_monedas); ##Se inicia la consulta de Timbres $this->getTimbres(); } public function create(){ global $conf, $user; $sql = "INSERT INTO ".MAIN_DB_PREFIX."cfdimx_recepcion_pagos"; $sql .= "("; $sql .= "fk_facture,"; $sql .= "fk_paiement,"; $sql .= "fechaPago,"; $sql .= "formaDePago,"; $sql .= "monedaP,"; $sql .= "TipoCambioP,"; $sql .= "monto,"; $sql .= "numOperacion,"; $sql .= "rfcEmisorCtaOrd,"; $sql .= "nomBancoOrdExt,"; $sql .= "ctaOrdenante,"; $sql .= "rfcEmisorCtaBen,"; $sql .= "ctaBeneficiario,"; $sql .= "tipoCadPago,"; $sql .= "certPago,"; $sql .= "cadPago,"; $sql .= "selloPago,"; $sql .= "entity,"; $sql .= "rel_facture,"; $sql .= "tipo_rel"; $sql .= ")"; $sql .= "VALUES"; $sql .= "("; $sql .= "'".$this->datos_complemento["fk_facture"]."',"; $sql .= "'".$this->id_doli."',"; $sql .= "'".$this->datos_complemento["fecha_pago"]."',"; $sql .= ($this->datos_complemento["forma_pago"] != '' ? "'".$this->datos_complemento["forma_pago"]."'" : 'NULL').","; $sql .= ($this->datos_complemento["moneda"] != '' ? "'".$this->datos_complemento["moneda"]."'" : 'NULL').","; $sql .= ($this->datos_complemento["tipo_cambio"] != '' ? "'".$this->datos_complemento["tipo_cambio"]."'" : 'NULL').","; $sql .= ($this->datos_complemento["monto"] != '' ? "'".$this->datos_complemento["monto"]."'" : 'NULL').","; $sql .= ($this->datos_complemento["numero_operacion"] != '' ? "'".$this->datos_complemento["numero_operacion"]."'" : 'NULL').","; $sql .= ($this->datos_complemento["rfc_cta_ordenante"] != '' ? "'".$this->datos_complemento["rfc_cta_ordenante"]."'" : 'NULL').","; $sql .= ($this->datos_complemento["nom_banco_ordenante"] != '' ? "'".$this->datos_complemento["nom_banco_ordenante"]."'" : 'NULL').","; $sql .= ($this->datos_complemento["cta_ordenante"] != '' ? "'".$this->datos_complemento["cta_ordenante"]."'" : 'NULL').","; $sql .= ($this->datos_complemento["rfc_cta_beneficiario"] != '' ? "'".$this->datos_complemento["rfc_cta_beneficiario"]."'" : 'NULL').","; $sql .= ($this->datos_complemento["cta_beneficiario"] != '' ? "'".$this->datos_complemento["cta_beneficiario"]."'" : 'NULL').","; $sql .= ($this->datos_complemento["tipo_cadena_pago"] != '' ? "'".$this->datos_complemento["tipo_cadena_pago"]."'" : 'NULL').","; $sql .= ($this->datos_complemento["certificado_pago"] != '' ? "'".$this->datos_complemento["certificado_pago"]."'" : 'NULL').","; $sql .= ($this->datos_complemento["cadena_original_comprobante_pago"] != '' ? "'".$this->datos_complemento["cadena_original_comprobante_pago"]."'" : 'NULL').","; $sql .= ($this->datos_complemento["sello_pago"] != '' ? "'".$this->datos_complemento["sello_pago"]."'" : 'NULL').","; $sql .= "'".$conf->entity."',"; $sql .= "1,"; $sql .= ($this->datos_complemento["tipo_relacion"] != '' ? "'".$this->datos_complemento["tipo_relacion"]."'" : 'NULL'); $sql .= ")"; $res = $this->db->query($sql); if($res){ $this->id_complemento = $this->db->last_insert_id(MAIN_DB_PREFIX."cfdimx_recepcion_pagos"); $this->status_guardado = 1; if(!is_null($this->lista_doc_relacionados) && count($this->lista_doc_relacionados) > 0){ foreach($this->lista_doc_relacionados as $key => $value){ $sql_doc_rel = "INSERT INTO ".MAIN_DB_PREFIX."cfdimx_recepcion_pagos_docto_relacionado"; $sql_doc_rel .= "("; $sql_doc_rel .= "fk_recepago,"; $sql_doc_rel .= "idDocumento,"; $sql_doc_rel .= "serie,"; $sql_doc_rel .= "folio,"; $sql_doc_rel .= "monedaDR,"; $sql_doc_rel .= "tipoCambioDR,"; $sql_doc_rel .= "metodoDePagoDR,"; $sql_doc_rel .= "numParcialidad,"; $sql_doc_rel .= "impSaldoAnt,"; $sql_doc_rel .= "impPagado,"; $sql_doc_rel .= "impSaldoInsoluto,"; $sql_doc_rel .= "entity,"; $sql_doc_rel .= "equivalencia"; $sql_doc_rel .= ")"; $sql_doc_rel .= "VALUES"; $sql_doc_rel .= "("; $sql_doc_rel .= "'".$this->id_complemento."',"; $sql_doc_rel .= ($value["uuid"] != '' ? "'".$value["uuid"]."'" : 'NULL').","; $sql_doc_rel .= ($value["serie"] != '' ? "'".$value["serie"]."'" : 'NULL').","; $sql_doc_rel .= ($value["folio"] != '' ? "'".$value["folio"]."'" : 'NULL').","; $sql_doc_rel .= ($value["moneda"] != '' ? "'".$value["moneda"]."'" : 'NULL').","; $sql_doc_rel .= ($value["tipo_cambio"] != '' ? "'".$value["tipo_cambio"]."'" : 'NULL').","; $sql_doc_rel .= ($value["forma_pago"] != '' ? "'".$value["forma_pago"]."'" : 'NULL').","; $sql_doc_rel .= ($value["parcialidad"] != '' ? "'".$value["parcialidad"]."'" : 'NULL').","; $sql_doc_rel .= ($value["saldo_anterior"] != '' ? "'".$value["saldo_anterior"]."'" : 'NULL').","; $sql_doc_rel .= ($value["importe_pagado"] != '' ? "'".$value["importe_pagado"]."'" : 'NULL').","; $sql_doc_rel .= ($value["saldo_insoluto"] != '' ? "'".$value["saldo_insoluto"]."'" : 'NULL').","; $sql_doc_rel .= $conf->entity.","; $sql_doc_rel .= ($value["equivalencia"] != '' ? "'".$value["equivalencia"]."'" : 'NULL').""; $sql_doc_rel .= ")"; $res_doc_rel = $this->db->query($sql_doc_rel); $sql_rel_factura = "INSERT INTO ".MAIN_DB_PREFIX."cfdimx_recepcion_pagos_relacion_facturas"; $sql_rel_factura .= "(fk_facture,fk_relacion_pagos)"; $sql_rel_factura .= " VALUES"; $sql_rel_factura .= "("; $sql_rel_factura .= "'".$value["id_factura"]."',"; $sql_rel_factura .= "'".$this->id_complemento."'"; $sql_rel_factura .= ")"; $res_rel_factura = $this->db->query($sql_rel_factura); // print $sql_doc_rel.'
'; // print $sql_rel_factura.'
'; if(!is_null($value["impuestos_aplicados"]) && count($value["impuestos_aplicados"]) > 0){ // print 'tiene impuestos
';cancelado foreach ($value["impuestos_aplicados"] as $key2 => $value2) { // print '
';
								// 	print_r($value2);
								// print '
'; $sql_impuesto = "INSERT INTO ".MAIN_DB_PREFIX."cfdimx_pagos_impuestos"; $sql_impuesto .= " (entity, fk_pago, uuid_doc_rel, base, impuesto, tipo_factor, tasa_o_cuota, importe, tipo, fk_user)"; $sql_impuesto .= " VALUES"; $sql_impuesto .= " ("; $sql_impuesto .= " '".$conf->entity."',"; $sql_impuesto .= " '".$this->id_doli."',"; $sql_impuesto .= " '".$value["uuid"]."',"; $sql_impuesto .= " '".$value2["base"]."',"; $sql_impuesto .= " '".$value2["impuesto"]."',"; $sql_impuesto .= " '".$value2["tipoFactor"]."',"; $sql_impuesto .= " '".$value2["tasaOCuota"]."',"; $sql_impuesto .= " '".$value2["importe"]."',"; $sql_impuesto .= " '".$value2["tipo"]."',"; $sql_impuesto .= " '".$user->id."'"; $sql_impuesto .= " )"; // print $sql_impuesto.'
'; $res_impuesto = $this->db->query($sql_impuesto); } } // print '

'; } } } } public function fetch($id_complemento = 0, $id_pago = null, $uuid = null){ global $conf; $condiciones = array(); $sql = "SELECT * FROM ".MAIN_DB_PREFIX."cfdimx_recepcion_pagos"; if($id_complemento > 0){ $condiciones[] = "rowid = ".$id_complemento; } if(!is_null($id_pago) && $id_pago > 0){ $condiciones[] = "fk_paiement = ".$id_pago; } if(!is_null($uuid) && $uuid != ""){ $condiciones[] = "uuid = '".$uuid."'"; } if(!is_null($condiciones) && count($condiciones) > 0){ $sql .= " WHERE "; $sql .= implode(" AND ", $condiciones); }else{ $sql .= " LIMIT 1"; } $res = $this->db->query($sql); $num = $this->db->num_rows($res); if($num > 0){ $obj_pago = $this->db->fetch_object($res); $this->datos_complemento["fk_facture"] = $obj_pago->fk_facture; $this->datos_complemento["fecha_pago"] = $obj_pago->fechaPago; $separa_fecha = explode(" ", $obj_pago->fechaPago); $this->datos_complemento["fecha"] = $separa_fecha[0]; $this->datos_complemento["hora"] = $separa_fecha[1]; $this->datos_complemento["forma_pago"] = $obj_pago->formaDePago; $this->datos_complemento["moneda"] = $obj_pago->monedaP; $this->datos_complemento["monto"] = $obj_pago->monto; $this->datos_complemento["tipo_cambio"] = $obj_pago->TipoCambioP; $this->datos_complemento["numero_operacion"] = $obj_pago->numOperacion; $this->datos_complemento["rfc_cta_ordenante"] = $obj_pago->rfcEmisorCtaOrd; $this->datos_complemento["nom_banco_ordenante"] = $obj_pago->nomBancoOrdExt; $this->datos_complemento["cta_ordenante"] = $obj_pago->ctaOrdenante; $this->datos_complemento["rfc_cta_beneficiario"] = $obj_pago->rfcEmisorCtaBen; $this->datos_complemento["cta_beneficiario"] = $obj_pago->ctaBeneficiario; $this->datos_complemento["tipo_cadena_pago"] = $obj_pago->tipoCadPago; $this->datos_complemento["certificado_pago"] = $obj_pago->certPago; $this->datos_complemento["cadena_original_comprobante_pago"] = $obj_pago->cadPago; $this->datos_complemento["sello_pago"] = $obj_pago->selloPago; #datos fiscales $this->datos_complemento["uuid"] = $obj_pago->uuid; $this->datos_complemento["xml"] = $obj_pago->xml; $this->datos_complemento["cadena"] = $obj_pago->cadena; $this->datos_complemento["version"] = $obj_pago->version; $this->datos_complemento["selloCFD"] = $obj_pago->selloCFD; $this->datos_complemento["certificado"] = $obj_pago->certificado; $this->datos_complemento["sello"] = $obj_pago->sello; $this->datos_complemento["certEmisor"] = $obj_pago->certEmisor; $this->datos_complemento["cancelado"] = $obj_pago->cancelado; $this->datos_complemento["fecha_emision"] = $obj_pago->fecha_emision; $this->datos_complemento["hora_emision"] = $obj_pago->hora_emision; $this->datos_complemento["entity"] = $obj_pago->entity; $this->datos_complemento["rel_facture"] = $obj_pago->rel_facture; $this->datos_complemento["tipo_relacion"] = $obj_pago->tipo_rel; ##Inicia Obtener CFDI Relacionados $sql_cfdi_rel = "SELECT * FROM ".MAIN_DB_PREFIX."cfdimx_cfdi_relacionados_pagos"; $sql_cfdi_rel .= " WHERE fk_pago = ".$obj_pago->fk_paiement; // print $sql_cfdi_rel; $res_cfdi_rel = $this->db->query($sql_cfdi_rel); $num_cfdi_rel = $this->db->num_rows($res_cfdi_rel); // $lista_ids_pagos[] = $id; if($num_cfdi_rel > 0){ while($obj = $this->db->fetch_object($res_cfdi_rel)){ if(!is_null($obj->fk_pago_rel) && $obj->fk_pago_rel != ""){ $this->lista_cfdi_relacionados[] = $obj; $this->omitir_pagos[] = $obj->fk_pago_rel; } } } ##Termina Obtener CFDI Relacionados ##Inicia Obtener Documentos Relacionados e Impuestos Relacionados $sql_doc_rel = "SELECT * FROM ".MAIN_DB_PREFIX."cfdimx_recepcion_pagos_docto_relacionado"; $sql_doc_rel .= " WHERE"; $sql_doc_rel .= " fk_recepago = ".$obj_pago->rowid; // print $sql_doc_rel.'
'; $res_doc_rel = $this->db->query($sql_doc_rel); $num_doc_rel = $this->db->num_rows($res_doc_rel); if($num_doc_rel > 0){ while($obj_doc_rel = $this->db->fetch_object($res_doc_rel)){ $obj_doc_rel->fk_facture = $this->getFacturaID($obj_doc_rel->idDocumento); $sql_impuestos_guardados = "SELECT * FROM ".MAIN_DB_PREFIX."cfdimx_pagos_impuestos"; $sql_impuestos_guardados .= " WHERE"; $sql_impuestos_guardados .= " entity = ".$conf->entity; $sql_impuestos_guardados .= " AND fk_pago = ".$obj_pago->fk_paiement; $sql_impuestos_guardados .= " AND uuid_doc_rel = '".$obj_doc_rel->idDocumento."'"; $sql_impuestos_guardados .= " ORDER BY tipo, impuesto ASC"; // print $sql_impuestos_guardados; $res_impuestos_guardados = $this->db->query($sql_impuestos_guardados); $num_impuestos_guardados = $this->db->num_rows($res_impuestos_guardados); if($num_impuestos_guardados > 0){ // $impuestos_aplicados = null; while($obj_tmp_impuestos = $this->db->fetch_object($res_impuestos_guardados)){ $obj_doc_rel->impuestos[] = $obj_tmp_impuestos; // $impuestos_aplicados[] = array( // "base" => $obj_tmp_impuestos->base, // "impuesto" => $obj_tmp_impuestos->impuesto, // "tipoFactor" => $obj_tmp_impuestos->tipo_factor, // "tasaOCuota" => $obj_tmp_impuestos->tasa_o_cuota, // "importe" => $obj_tmp_impuestos->importe, // "tipo" => $obj_tmp_impuestos->tipo // ); // array_push($impuestos_aplicados, $info_impuesto); } // $obj_doc_rel->impuestos = $impuestos_aplicados; } // print '
';
						// 	print_r($obj_doc_rel);
						// print '
'; $this->lista_doc_relacionados[] = $obj_doc_rel; } } ##Termina Obtener Documentos Relacionados e Impuestos Relacionados ##Inicia Obtencion de Archivos Vinculados $this->getArchivosVinculados($obj_pago->fk_paiement); ##Termina Obtencion de Archivos Vinculados ##Inicia Obtencion de Solicitudes de Cancelacion $sql_solicitud_cancelacion = ""; $sql_solicitud_cancelacion .= "SELECT * FROM ".MAIN_DB_PREFIX."cfdimx_solicitud_cancelacion_pago"; $sql_solicitud_cancelacion .= " WHERE"; $sql_solicitud_cancelacion .= " fk_pago = ".$obj_pago->fk_paiement; $sql_solicitud_cancelacion .= " ORDER BY rowid ASC"; $res_solicitud_cancelacion = $this->db->query($sql_solicitud_cancelacion); $num_solicitud_cancelacion = $this->db->num_rows($res_solicitud_cancelacion); if($num_solicitud_cancelacion > 0){ $this->num_solicitudes_cancelacion = $num_solicitud_cancelacion; while($obj = $this->db->fetch_object($res_solicitud_cancelacion)){ // $this->solicitud_cancelacion = $obj; $this->solicitud_cancelacion["rowid"] = $obj->rowid; $this->solicitud_cancelacion["fk_pago"] = $obj->fk_pago; $this->solicitud_cancelacion["httpStatusCode"] = $obj->httpStatusCode; $this->solicitud_cancelacion["acuse"] = $obj->acuse; $this->solicitud_cancelacion["status"] = $obj->status; $this->solicitud_cancelacion["uuid"] = $obj->uuid; $this->solicitud_cancelacion["uuidStatusCode"] = $obj->uuidStatusCode; $this->solicitud_cancelacion["message"] = $obj->message; $this->solicitud_cancelacion["messageDetail"] = $obj->messageDetail; $this->solicitud_cancelacion["fecha"] = $obj->fecha; $this->solicitud_cancelacion["hora"] = $obj->hora; $this->solicitud_cancelacion["fechahora"] = $obj->fecha." ".$obj->hora; $this->solicitud_cancelacion["archivo"] = $obj->archivo; } } ##Termina Obtencion de Solicitudes de Cancelacion ##Inicia Obtencion de Facturas para envio de correo $this->getFacturasCorreo($obj_pago->fk_paiement); ##Termina Obtencion de Facturas para envio de correo ##Inicia Consulta de Peticiones de Estatus if(!is_null($this->datos_complemento["uuid"]) && $this->datos_complemento["uuid"] != ""){ $this->getEstatusComplemento($this->datos_complemento["uuid"]); } ##Termina Consulta de Peticiones de Estatus } // print $sql; } public function update(){ $sql = "UPDATE ".MAIN_DB_PREFIX."cfdimx_recepcion_pagos"; $sql .= " SET"; // $sql .= "'".$this->datos_complemento["fk_facture"]."',"; // $sql .= "'".$this->id_doli."',"; $sql .= " fechaPago = '".$this->datos_complemento["fecha_pago"]."',"; $sql .= " formaDePago = ".($this->datos_complemento["forma_pago"] != '' ? "'".$this->datos_complemento["forma_pago"]."'" : 'NULL').","; $sql .= " monedaP = ".($this->datos_complemento["moneda"] != '' ? "'".$this->datos_complemento["moneda"]."'" : 'NULL').","; $sql .= " TipoCambioP = ".($this->datos_complemento["tipo_cambio"] != '' ? "'".$this->datos_complemento["tipo_cambio"]."'" : 'NULL').","; $sql .= " monto = ".($this->datos_complemento["monto"] != '' ? "'".$this->datos_complemento["monto"]."'" : 'NULL').","; $sql .= " numOperacion = ".($this->datos_complemento["numero_operacion"] != '' ? "'".$this->datos_complemento["numero_operacion"]."'" : 'NULL').","; $sql .= " rfcEmisorCtaOrd = ".($this->datos_complemento["rfc_cta_ordenante"] != '' ? "'".$this->datos_complemento["rfc_cta_ordenante"]."'" : 'NULL').","; $sql .= " nomBancoOrdExt = ".($this->datos_complemento["nom_banco_ordenante"] != '' ? "'".$this->datos_complemento["nom_banco_ordenante"]."'" : 'NULL').","; $sql .= " ctaOrdenante = ".($this->datos_complemento["cta_ordenante"] != '' ? "'".$this->datos_complemento["cta_ordenante"]."'" : 'NULL').","; $sql .= " rfcEmisorCtaBen = ".($this->datos_complemento["rfc_cta_beneficiario"] != '' ? "'".$this->datos_complemento["rfc_cta_beneficiario"]."'" : 'NULL').","; $sql .= " ctaBeneficiario = ".($this->datos_complemento["cta_beneficiario"] != '' ? "'".$this->datos_complemento["cta_beneficiario"]."'" : 'NULL').","; $sql .= " tipoCadPago = ".($this->datos_complemento["tipo_cadena_pago"] != '' ? "'".$this->datos_complemento["tipo_cadena_pago"]."'" : 'NULL').","; $sql .= " certPago = ".($this->datos_complemento["certificado_pago"] != '' ? "'".$this->datos_complemento["certificado_pago"]."'" : 'NULL').","; $sql .= " cadPago = ".($this->datos_complemento["cadena_original_comprobante_pago"] != '' ? "'".$this->datos_complemento["cadena_original_comprobante_pago"]."'" : 'NULL').","; $sql .= " selloPago = ".($this->datos_complemento["sello_pago"] != '' ? "'".$this->datos_complemento["sello_pago"]."'" : 'NULL').""; $sql .= " WHERE"; $sql .= " rowid = ".$this->id_complemento; $res = $this->db->query($sql); if($res){ return 1; }else{ return 0; } } public function updateDocumentoRel(){ global $conf, $user; $sql_doc_rel = "UPDATE ".MAIN_DB_PREFIX."cfdimx_recepcion_pagos_docto_relacionado"; $sql_doc_rel .= " SET"; $sql_doc_rel .= " idDocumento = ".($this->doc_relacionado["uuid"] != '' ? "'".$this->doc_relacionado["uuid"]."'" : 'NULL').","; // $sql_doc_rel .= " serie = ".($this->doc_relacionado["serie"] != '' ? "'".$this->doc_relacionado["serie"]."'" : 'NULL').","; // $sql_doc_rel .= " folio = ".($this->doc_relacionado["folio"] != '' ? "'".$this->doc_relacionado["folio"]."'" : 'NULL').","; $sql_doc_rel .= " monedaDR = ".($this->doc_relacionado["moneda"] != '' ? "'".$this->doc_relacionado["moneda"]."'" : 'NULL').","; $sql_doc_rel .= " tipoCambioDR = ".($this->doc_relacionado["tipo_cambio"] != '' ? "'".$this->doc_relacionado["tipo_cambio"]."'" : 'NULL').","; $sql_doc_rel .= " numParcialidad = ".($this->doc_relacionado["parcialidad"] != '' ? "'".$this->doc_relacionado["parcialidad"]."'" : 'NULL').","; $sql_doc_rel .= " impSaldoAnt = ".($this->doc_relacionado["importe_anterior"] != '' ? "'".$this->doc_relacionado["importe_anterior"]."'" : 'NULL').","; $sql_doc_rel .= " impPagado = ".($this->doc_relacionado["importe_pagado"] != '' ? "'".$this->doc_relacionado["importe_pagado"]."'" : 'NULL').","; $sql_doc_rel .= " impSaldoInsoluto = ".($this->doc_relacionado["importe_insoluto"] != '' ? "'".$this->doc_relacionado["importe_insoluto"]."'" : 'NULL').","; if(strcmp($conf->global->CFDIMX_VERSION_SAT, "4.0") == 0){ $sql_doc_rel .= " equivalencia = ".($this->doc_relacionado["equivalencia"] != '' ? "'".$this->doc_relacionado["equivalencia"]."'" : 'NULL').""; }else{ $sql_doc_rel .= " metodoDePagoDR = ".($this->doc_relacionado["metodo_pago"] != '' ? "'".$this->doc_relacionado["metodo_pago"]."'" : 'NULL').""; } $sql_doc_rel .= " WHERE"; $sql_doc_rel .= " rowid = ".$this->doc_relacionado["rowid"]; $res = $this->db->query($sql_doc_rel); if($res){ if(strcmp($conf->global->CFDIMX_VERSION_SAT, "4.0") == 0){ if(!is_null($this->doc_relacionado["impuestos"]) && is_array($this->doc_relacionado["impuestos"]) && count($this->doc_relacionado["impuestos"]) > 0){ foreach ($this->doc_relacionado["impuestos"] as $key => $value) { $sql_impuesto = "UPDATE ".MAIN_DB_PREFIX."cfdimx_pagos_impuestos"; $sql_impuesto .= " SET"; $sql_impuesto .= " uuid_doc_rel = '".$this->doc_relacionado["uuid"]."',"; $sql_impuesto .= " base = '".$value["base"]."',"; $sql_impuesto .= " impuesto = '".$value["impuesto"]."',"; $sql_impuesto .= " tipo_factor = '".$value["tipo_factor"]."',"; $sql_impuesto .= " tasa_o_cuota = '".$value["tasa_o_cuota"]."',"; $sql_impuesto .= " importe = '".$value["importe"]."',"; $sql_impuesto .= " tipo = '".$value["tipo"]."',"; $sql_impuesto .= " fk_user = '".$user->id."'"; $sql_impuesto .= " WHERE"; $sql_impuesto .= " rowid = ".$value["rowid"]; $res_update = $this->db->query($sql_impuesto); } } } return 1; }else{ return 0; } } public function getArchivosVinculados($id){ global $conf; $object = new Paiement($this->db); $object->fetch($id); $out_files=""; $filedir = DOL_DATA_ROOT.'/facture/'.$object->ref.'/'; $n = $conf->facture->dir_output."/".$object->ref."/"; $file_list=dol_dir_list($filedir,'files',0,'','\.meta$','date',SORT_DESC); // print $filedir.'
'; // print $n.'
'; // Loop on each file found if (is_array($file_list)){ foreach($file_list as $file){ $this->lista_archivo_vinculados[] = $file; // print '
';
					// 	print_r($file);
					// print '
'; // $aux_ext = explode(".", $file['name']); // $ext = $aux_ext[1]; // if (in_array($ext, array("pdf"))){ // $out_lupa = ''; // }else { // $out_lupa = ""; // } // $out_files.= ''; // //Ruta antigua para eliminar // // // $out_files.=' // // '.$file['name'].' // '.$out_lupa.' // // '.filesize($file['fullname']).' Bytes // '.dol_print_date($file['date'], "%H:%M %d/%m/%Y").''; // $out_files.= ''; } } } public function createCFDIRelacionado(){ $error = 0; $sql = "INSERT INTO ".MAIN_DB_PREFIX."cfdimx_cfdi_relacionados_pagos"; $sql .= " (fk_pago, uuid, fk_pago_rel)"; $sql .= " VALUES"; $sql .= " ("; $sql .= "'".$this->id_doli."',"; $sql .= "'".$this->cfdi_relacionado["uuid"]."',"; $sql .= "'".$this->cfdi_relacionado["fk_pago_rel"]."'"; $sql .= " )"; // print $sql; if($this->cfdi_relacionado["fk_pago_rel"] != -1){ $res = $this->db->query($sql); if(!$res){ $error++; $this->mensaje_error .= "Error: No se agrego correctamente el UUID (".$this->cfdi_relacionado["uuid"].")
"; dol_print_error($this->db); }else{ $this->mensaje_error .= "Se agrego correctamente el UUID (".$this->cfdi_relacionado["uuid"].")
"; } } $update = "UPDATE ".MAIN_DB_PREFIX."cfdimx_recepcion_pagos"; $update .= " SET"; $update .= " tipo_rel = ".($this->datos_complemento["tipo_relacion"] != '' ? "'".$this->datos_complemento["tipo_relacion"]."'" : 'NULL'); $update .= " WHERE"; $update .= " rowid = ".$this->id_complemento; $res_update = $this->db->query($update); if(!$res_update){ $this->mensaje_error .= "Error: No se actualizo correctamente el Tipo de Relación
"; dol_print_error($this->db); $error++; }else{ $this->mensaje_error .= "Se actualizo correctamente el Tipo de Relación
"; } // print $update; return $error; } public function deleteCFDIRelacionado($id){ $error = 0; $sql = "DELETE FROM ".MAIN_DB_PREFIX."cfdimx_cfdi_relacionados_pagos"; $sql .= " WHERE"; $sql .= " rowid = ".$id; // print $sql; $res = $this->db->query($sql); if($res){ } $error = 1; return $error; } public function setInformacionPago($id, $ref){ global $conf; $object = new Paiement($this->db); $object->fetch($id, $ref); $amount_header = $object->amount; $amount_multi_header = $object->multicurrency_amount; ##Inicia Consulta para ver si existe moneda $facturas_asociadas = $object->getBillsArray(); $sql_control_moneda = "SELECT * FROM ".MAIN_DB_PREFIX."paiement_facture"; $sql_control_moneda .= " WHERE"; $sql_control_moneda .= " fk_facture = ".$facturas_asociadas[0]; $sql_control_moneda .= " AND fk_paiement = ".$id; $sql_control_moneda .= " LIMIT 1"; // print $sql_control_moneda; $res_control_moneda = $this->db->query($sql_control_moneda); $num_control_moneda = $this->db->num_rows($res_control_moneda); if($num_control_moneda > 0){ $obj_control_moneda = $this->db->fetch_object($res_control_moneda); if(!is_null($obj_control_moneda->multicurrency_code) && $obj_control_moneda->multicurrency_code != ""){ // $monedaa = $obj_control_moneda->multicurrency_code; $this->datos_complemento["moneda"] = $obj_control_moneda->multicurrency_code; } } ##Termina Consulta para ver si existe moneda $this->datos_complemento["hora"] = dol_print_date($object->date, "hour"); $this->datos_complemento["fecha"] = dol_print_date($object->date, "dayrfc"); $this->datos_complemento["fecha_pago"] = dol_print_date($object->date, "standard"); // print dol_print_date($this->datos_complemento["fecha_pago"], "hour"); ##Inicia Forma de Pago $sql_forma_pago = "SELECT accountancy_code FROM ".MAIN_DB_PREFIX."c_paiement WHERE code='".$object->type_code."'"; $res_forma_pago = $this->db->query($sql_forma_pago); $num_forma_pago = $this->db->num_rows($res_forma_pago); if($num_forma_pago > 0){ $obj_forma_pago = $this->db->fetch_object($res_forma_pago); $this->datos_complemento["forma_pago"] = $obj_forma_pago->accountancy_code; } ##Termina Forma de Pago ##Inicia Monedas $select_monedas = "SELECT * FROM ".MAIN_DB_PREFIX."multicurrency WHERE entity = ".$conf->entity; $res_select_monedas = $this->db->query($select_monedas); $num_select_monedas = $this->db->num_rows($res_select_monedas); if($num_select_monedas == 0){ $this->datos_complemento["moneda"] = $conf->currency; } if(strcmp($conf->global->CFDIMX_VERSION_SAT, "4.0") == 0){ if($this->datos_complemento["tipo_cambio"] == ""){ if($this->datos_complemento["moneda"] == "MXN"){ $this->datos_complemento["tipo_cambio"] = 1; } } } $this->datos_complemento["monto"] = str_replace(",","",number_format($amount_header,2)); ##Termina Monedas ##Inicia Documentos Relacionados $this->setDocumentosRelacionados($id, $this->datos_complemento["moneda"]); ##Termina Documentos Relacionados // print '
';
			// 	print_r($this->datos_complemento);
			// print '
'; /* foreach($this->lista_doc_relacionados as $key => $value){ $tmp = ($value["serie"] != '' ? "'".$value["serie"]."'" : 'NULL'); print '<>'.$tmp.'<>'; print '
';
					print_r($value);
				print '
'; } print '
';
				print_r($this->lista_doc_relacionados);
			print '
'; die; */ $this->create(); ## } public function setDocumentosRelacionados($id, $moneda_pago){ global $conf; $sql = "SELECT"; $sql .= " f.rowid as facid, f.ref, f.type, f.total_ttc, f.paye, f.fk_statut, pf.amount, pf.multicurrency_amount,"; $sql .= " s.nom as name, s.rowid as socid"; $sql .= " FROM ".MAIN_DB_PREFIX."paiement_facture as pf, ".MAIN_DB_PREFIX."facture as f, ".MAIN_DB_PREFIX."societe as s"; $sql .= " WHERE"; $sql .= " pf.fk_facture = f.rowid"; $sql .= " AND f.fk_soc = s.rowid"; $sql .= " AND f.entity = ".$conf->entity; $sql .= " AND pf.fk_paiement = ".$id; // print $sql.'
'; $resql = $this->db->query($sql); if($resql){ $num = $this->db->num_rows($sql); $i = 0; while ($i < $num) { $obj = $this->db->fetch_object($resql); // print '
';
					// 	print_r($obj);
					// print '
'; $this->lista_doc_relacionados[$i]["id_factura"] = $obj->facid; $this->lista_doc_relacionados[$i]["tipo_cambio"] = ""; $facture_static = new Facture($this->db); $facture_static->fetch($this->lista_doc_relacionados[$i]["id_factura"]); $this->lista_doc_relacionados[$i]["moneda"] = $facture_static->multicurrency_code; if ($this->lista_doc_relacionados[$i]["moneda"] != 'MXN'){ $invoicetotal = $facture_static->multicurrency_total_ttc; $paiement = $facture_static->getSommePaiement(1); $creditnotes = $facture_static->getSumCreditNotesUsed(1); $deposits = $facture_static->getSumDepositsUsed(1); $alreadypayed = price2num($paiement + $creditnotes + $deposits,'MT'); }else{ $invoicetotal = $facture_static->total_ttc; $paiement = $facture_static->getSommePaiement(); $creditnotes = $facture_static->getSumCreditNotesUsed(); $deposits = $facture_static->getSumDepositsUsed(); $alreadypayed = price2num($paiement + $creditnotes + $deposits,'MT'); } $remaintopay = price2num($invoicetotal - $paiement - $creditnotes - $deposits,'MT'); // equivalencia entre la moneda del pago y el de la factura $this->lista_doc_relacionados[$i]["ayuda_equivalencia"] = ""; $this->lista_doc_relacionados[$i]["equivalencia"] = 0; $this->lista_doc_relacionados[$i]["forma_pago"] = $facture_static->array_options["options_formpagcfdi"]; $tercero_static = new Societe($this->db); $tercero_static->id = $obj->socid; $tercero_static->name = $obj->name; $separa_ref = explode("-", $facture_static->ref); if(count($separa_ref) > 1){ // Mascara Estandar Ejemplo FA1001-0001 if(count($separa_ref) == 2){ $this->lista_doc_relacionados[$i]["serie"] = $separa_ref[0]; $this->lista_doc_relacionados[$i]["folio"] = $separa_ref[1]; } // Mascar Personalizada con mas de 2 series, Ejemplo CFDIMX-FACTURA-20240102-0001 if(count($separa_ref) > 2){ $this->lista_doc_relacionados[$i]["serie"] = ""; for ($m = 0; $m < count($separa_ref); $m++) { if($m == (count($separa_ref) - 1)){ $this->lista_doc_relacionados[$i]["folio"] = $separa_ref[$m]; }else{ if($m == 0){ $this->lista_doc_relacionados[$i]["serie"] .= $separa_ref[$m]; }else{ $this->lista_doc_relacionados[$i]["serie"] .= "-".$separa_ref[$m]; } } } } }else{ // Mascara Personalizada sin seperador de serie y folio, Ejemlo FACCFDIMX00001 $this->lista_doc_relacionados[$i]["folio"] = $separa_ref[0]; } $sql_cfdimx = "SELECT cfdi.uuid, cfdi.divisa FROM ".MAIN_DB_PREFIX."cfdimx AS cfdi"; $sql_cfdimx .= " WHERE"; $sql_cfdimx .= " cfdi.fk_facture = ".$facture_static->id; //print $sql."
"; $res_cfdimx = $this->db->query($sql_cfdimx); $num_cfdimx = $this->db->num_rows($res_cfdimx); if ($num_cfdimx > 0) { $res_obj = $this->db->fetch_object($res_cfdimx); $this->lista_doc_relacionados[$i]["divisa"] = $res_obj->divisa; $this->lista_doc_relacionados[$i]["uuid"] = $res_obj->uuid; } if($this->lista_doc_relacionados[$i]["moneda"] == "MXN"){ $this->lista_doc_relacionados[$i]["importe_pagado"] = str_replace(array(",","-"), "", number_format($obj->amount, 2)); }else{ $this->lista_doc_relacionados[$i]["importe_pagado"] = str_replace(array(",","-"), "", number_format($obj->multicurrency_amount, 2)); } if(strcmp($conf->global->CFDIMX_VERSION_SAT, "4.0") == 0){ $this->lista_doc_relacionados[$i]["forma_pago"] = ""; $this->lista_doc_relacionados[$i]["parcialidad"] = 1; $this->lista_doc_relacionados[$i]["saldo_anterior"] = str_replace(array(",","-"), "",number_format($invoicetotal, 2)); if($moneda_pago == $this->lista_doc_relacionados[$i]["moneda"]){ $this->lista_doc_relacionados[$i]["equivalencia"] = 1; }else{ if($moneda_pago == ""){ $this->lista_doc_relacionados[$i]["ayuda_equivalencia"] = '1 ¿? = ¿XXX '.$this->lista_doc_relacionados[$i]["moneda"].'?'; }else{ $this->lista_doc_relacionados[$i]["ayuda_equivalencia"] = '1 '.$moneda_pago.' = ¿XXX '.$this->lista_doc_relacionados[$i]["moneda"].'?'; } } ##Iinicio para verificar si tiene una parcialidad previa $sql_parcialidad = "SELECT * FROM ".MAIN_DB_PREFIX."cfdimx_recepcion_pagos_docto_relacionado"; $sql_parcialidad .= " WHERE"; $sql_parcialidad .= " idDocumento = '".$this->lista_doc_relacionados[$i]["uuid"]."'"; $sql_parcialidad .= " ORDER BY rowid"; $sql_parcialidad .= " DESC LIMIT 1"; $res_parcialidad = $this->db->query($sql_parcialidad); $num_parcialidad = $this->db->num_rows($res_parcialidad); if($num_parcialidad > 0){ $obj_documento = $this->db->fetch_object($res_parcialidad); $this->lista_doc_relacionados[$i]["parcialidad"] = $obj_documento->numParcialidad + 1; $this->lista_doc_relacionados[$i]["saldo_anterior"] = str_replace(array(",","-"), "",number_format($obj_documento->impSaldoInsoluto, 2)); } ##Termina para verificar si tiene una parcialidad previa $this->lista_doc_relacionados[$i]["saldo_insoluto"] = $this->lista_doc_relacionados[$i]["importe_pagado"] - $this->lista_doc_relacionados[$i]["saldo_anterior"]; $this->lista_doc_relacionados[$i]["saldo_insoluto"] = str_replace(array(",","-"), "", number_format($this->lista_doc_relacionados[$i]["saldo_insoluto"], 2)); }else{ $this->lista_doc_relacionados[$i]["saldo_anterior"] = str_replace(array(",","-"), "",number_format($invoicetotal, 2)); $this->lista_doc_relacionados[$i]["saldo_insoluto"] = $this->lista_doc_relacionados[$i]["importe_pagado"] - $this->lista_doc_relacionados[$i]["saldo_anterior"]; } $this->lista_doc_relacionados[$i]["impuestos_aplicados"] = $this->getImpuestosDoctoRel($obj->facid, $this->lista_doc_relacionados[$i]["uuid"]); // print '
';
					// 	print_r($this->lista_doc_relacionados[$i]);
					// print '
'; $i++; } } } public function getFacturaID($uuid){ $sql = "SELECT fk_facture FROM ".MAIN_DB_PREFIX."cfdimx"; $sql .= " WHERE"; $sql .= " uuid = '".$uuid."'"; $res = $this->db->query($sql); $num = $this->db->num_rows($res); if($num > 0){ $obj = $this->db->fetch_object($res); return $obj->fk_facture; }else{ return 0; } } public function obtener_catalogo($selected='', $htmlname='', $tipo_catalogo, $tipo_informacion = 0, $tipo_sql = '', $show_empty=0, $exclude='', $disabled=0, $include='', $enableonly='', $force_entity=0, $maxlength=0, $showstatus=0, $morefilter='', $show_every=0, $enableonlytext='', $morecss='', $noactive=0, $entrepot=0){ global $conf,$user,$langs; $db = $this->db; // If no preselected user defined, we take current user if ((is_numeric($selected) && ($selected < -2 || empty($selected))) && empty($conf->global->SOCIETE_DISABLE_DEFAULT_SALESREPRESENTATIVE)) $selected=$user->id; $excludeUsers=null; $includeUsers=null; // Permettre l’exclusion d’utilisateurs if (is_array($exclude)) $excludeUsers = implode("','",$exclude); // Permettre l’inclusion d’utilisateurs if (is_array($include)) $includeUsers = implode("','",$include); else if ($include == 'hierarchy') { // Build list includeUsers to have only hierarchy $userid=$user->id; $include=array(); if (empty($user->users) || ! is_array($user->users)) $user->get_full_tree(); foreach($user->users as $key => $val) { if (preg_match('/'.$userid.'/',$val['fullpath'])) $include[]=$val['id']; } $includeUsers = implode("','",$include); } $out = ''; $valor_placeholder = ""; if($conf->global->CFDIMX_PAGOS_LIST_MONEDAS == 0 && in_array($tipo_catalogo, array(3, 4))){ $tipo_catalogo = 10; } switch ($tipo_catalogo) { case 1: $sql = "SELECT * FROM ".MAIN_DB_PREFIX."c_cfdimx_uso_cfdi WHERE active = 1"; $valor_placeholder = "Uso CFDI"; break; case 2: $sql = "SELECT * FROM ".MAIN_DB_PREFIX."c_cfdimx_formapago WHERE active = 1"; $valor_placeholder = "Forma de Pago"; break; case 3: $sql = "SELECT * FROM ".MAIN_DB_PREFIX."multicurrency WHERE entity = ".$conf->entity; $valor_placeholder = "Moneda del Pago"; break; case 4: $sql = "SELECT * FROM ".MAIN_DB_PREFIX."c_currencies WHERE code_iso='".$conf->currency."'"; $valor_placeholder = "Moneda del Pago"; break; case 5: $sql = "SELECT * FROM ".MAIN_DB_PREFIX."c_cfdimx_formapago WHERE active = 1"; $valor_placeholder = "Forma de Pago"; break; case 6: $sql = "SELECT * FROM ".MAIN_DB_PREFIX."c_cfdimx_exportacion WHERE active = 1"; $valor_placeholder = "Exportación"; break; case 7: $sql = "SELECT * FROM ".MAIN_DB_PREFIX."paiement"; if($tipo_sql != ""){ $sql .= " WHERE rowid = ".$tipo_sql; } $valor_placeholder = "Monto del Pago"; break; case 8: $sql = "SELECT * FROM ".MAIN_DB_PREFIX."c_cfdimx_tipo_rel"; $valor_placeholder = "Tipo de Relación"; break; case 9: $sql = "SELECT * FROM ".MAIN_DB_PREFIX."c_cfdimx_tipo_rel LIMIT 1"; $valor_placeholder = "Tipo de Impuesto"; break; case 10: $sql = "SELECT * FROM ".MAIN_DB_PREFIX."c_currencies WHERE code_iso IN('USD', 'MXN', 'EUR')"; $valor_placeholder = "Moneda del Pago"; break; default: $sql = ""; break; } // if($tipo_informacion == 1) // $sql .= " AND code='".$selected."'"; $resql = ""; $resql = $db->query($sql); // print $sql; if ($resql) { $num = $db->num_rows($resql); $i = 0; $etiqueta = ""; if ($num) { // Enhance with select2 $nodatarole=''; if ($conf->use_javascript_ajax) { include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php'; $comboenhancement = ajax_combobox($htmlname); $out.=$comboenhancement; $nodatarole=($comboenhancement?' data-role="none"':''); } $out.= ''; } $out.= ''; if($tipo_informacion == 1) $out = $etiqueta_list; }else{ dol_print_error($db); } return $out; } ##Funcion Exclusiva de la Ficha donde se llena el Pago public function obtener_moneda($selected='', $htmlname='', $tipo_catalogo, $tipo_informacion = 0, $tipo_sql = '', $show_empty=0, $exclude='', $disabled=0, $include='', $enableonly='', $force_entity=0, $maxlength=0, $showstatus=0, $morefilter='', $show_every=0, $enableonlytext='', $morecss='', $noactive=0, $entrepot=0){ global $conf,$user,$langs; $db = $this->db; // If no preselected user defined, we take current user if ((is_numeric($selected) && ($selected < -2 || empty($selected))) && empty($conf->global->SOCIETE_DISABLE_DEFAULT_SALESREPRESENTATIVE)) $selected=$user->id; $excludeUsers=null; $includeUsers=null; // Permettre l’exclusion d’utilisateurs if (is_array($exclude)) $excludeUsers = implode("','",$exclude); // Permettre l’inclusion d’utilisateurs if (is_array($include)) $includeUsers = implode("','",$include); else if ($include == 'hierarchy') { // Build list includeUsers to have only hierarchy $userid=$user->id; $include=array(); if (empty($user->users) || ! is_array($user->users)) $user->get_full_tree(); foreach($user->users as $key => $val) { if (preg_match('/'.$userid.'/',$val['fullpath'])) $include[]=$val['id']; } $includeUsers = implode("','",$include); } $out=''; $valor_placeholder = ""; $sql_val = "SELECT * FROM ".MAIN_DB_PREFIX."multicurrency WHERE entity = ".$conf->entity; $res_val = $db->query($sql_val); $num_val = $db->num_rows($res_val); if($num_val > 0){ $tipo_catalogo = 2; } if($conf->global->CFDIMX_PAGOS_LIST_MONEDAS == 0 && in_array($tipo_catalogo, array(1, 2))){ $tipo_catalogo = 3; } switch ($tipo_catalogo) { case 1: $sql = "SELECT * FROM ".MAIN_DB_PREFIX."c_currencies"; $valor_placeholder = "Moneda del Pago"; break; case 2: $sql = "SELECT * FROM ".MAIN_DB_PREFIX."multicurrency WHERE entity = ".$conf->entity; $valor_placeholder = "Moneda del Pago"; break; case 3: $sql = "SELECT * FROM ".MAIN_DB_PREFIX."c_currencies WHERE code_iso IN('USD', 'MXN', 'EUR')"; $valor_placeholder = "Moneda del Pago"; break; default: $sql = ""; break; } // if($tipo_informacion == 1) // $sql .= " AND code='".$selected."'"; $resql = ""; $resql = $db->query($sql); // print $sql; if ($resql) { $num = $db->num_rows($resql); $i = 0; $etiqueta = ""; if ($num) { // Enhance with select2 $nodatarole=''; if ($conf->use_javascript_ajax) { include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php'; $comboenhancement = ajax_combobox($htmlname); $out.=$comboenhancement; $nodatarole=($comboenhancement?' data-role="none"':''); } $out.= ''; } $out.= ''; if($tipo_informacion == 1) $out = $etiqueta_list; }else{ dol_print_error($db); } return $out; } ##Funcion Exclusiva para CFDI Relacionados Pagos public function obtener_rel_pagos($selected='', $htmlname='', $tipo_catalogo, $tipo_informacion = 0, $tipo_sql = '', $show_empty=0, $exclude='', $disabled=0, $include='', $enableonly='', $force_entity=0, $maxlength=0, $showstatus=0, $morefilter='', $show_every=0, $enableonlytext='', $morecss='', $noactive=0, $entrepot=0){ global $conf,$user,$langs; $db = $this->db; // If no preselected user defined, we take current user if ((is_numeric($selected) && ($selected < -2 || empty($selected))) && empty($conf->global->SOCIETE_DISABLE_DEFAULT_SALESREPRESENTATIVE)) $selected=$user->id; $excludeUsers=null; $includeUsers=null; // Permettre l’exclusion d’utilisateurs if (is_array($exclude)) $excludeUsers = implode("','",$exclude); // Permettre l’inclusion d’utilisateurs if (is_array($include)) $includeUsers = implode("','",$include); else if ($include == 'hierarchy') { // Build list includeUsers to have only hierarchy $userid=$user->id; $include=array(); if (empty($user->users) || ! is_array($user->users)) $user->get_full_tree(); foreach($user->users as $key => $val) { if (preg_match('/'.$userid.'/',$val['fullpath'])) $include[]=$val['id']; } $includeUsers = implode("','",$include); } $out=''; $valor_placeholder = ""; switch ($tipo_catalogo) { case 1: $sql = "SELECT * FROM ".MAIN_DB_PREFIX."c_cfdimx_tipo_rel"; $valor_placeholder = "Tipo de Relación"; break; case 2: $sql = "SELECT * FROM ".MAIN_DB_PREFIX."cfdimx_recepcion_pagos"; $sql .= " WHERE fk_facture = 0"; if($tipo_sql != ""){ $sql .= " AND fk_paiement NOT IN(".$tipo_sql.")"; } $sql .= " AND uuid IS NOT NULL"; $valor_placeholder = "Complemento de Pagos"; break; default: $sql = ""; break; } // if($tipo_informacion == 1) // $sql .= " AND code='".$selected."'"; $resql = ""; $resql = $db->query($sql); // print $sql; if ($resql) { $num = $db->num_rows($resql); $i = 0; $etiqueta = ""; if ($num) { // Enhance with select2 $nodatarole=''; if ($conf->use_javascript_ajax) { include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php'; $comboenhancement = ajax_combobox($htmlname); $out.=$comboenhancement; $nodatarole=($comboenhancement?' data-role="none"':''); } // if($tipo_catalogo == 2){ // $out.= ''; if ($show_empty) $out.= ''."\n"; if ($show_every) $out.= ''."\n"; $out.= ''; $i=0; while ($rw = $db->fetch_object($resql)) { switch ($tipo_catalogo) { case 1: $valor = $rw->code; $etiqueta = $rw->code." - ".$rw->label; if ($selected == $valor) { $out.= '"; break; case 2: $pago_tmp = new Paiement($db); $pago_tmp->fetch($rw->fk_paiement); // $valor = $rw->uuid."<>".$rw->fk_paiement; $valor = $rw->fk_paiement; $etiqueta = "Ref: ".$pago_tmp->ref." Monto: ".$rw->monto." UUID: ".$rw->uuid; if ($selected == $valor) { $out.= '"; break; } } }else{ $nodatarole=''; if ($conf->use_javascript_ajax) { include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php'; $comboenhancement = ajax_combobox($htmlname); $out.=$comboenhancement; $nodatarole=($comboenhancement?' data-role="none"':''); } $out.= ''; if($tipo_informacion == 1) $out = $etiqueta_list; }else{ dol_print_error($db); } return $out; } public function mostrarDescuentos(){ global $conf; $sql = "SELECT * FROM ".MAIN_DB_PREFIX."cfdimx_descuentos"; $sql = " WHERE entity_id=".$conf->entity; $res_sql = $this->db->query($sql); $num_res_sql = $this->db->num_rows($res_sql); $mostrar_descuento=1; if($num_res_sql > 0){ $obj_descuento = $this->db->fetch_object($res_sql); if($obj_descuento->mostrar == 1){ $mostrar_descuento = 1; }else{ $mostrar_descuento = 2; } } return $mostrar_descuento; } //Funcion para obtener las retenciones del Producto function obtenerRetencionesProducto($id, $id_detalle, $impuesto, $vowels){ $retenBase = null; $retenImporte = null; $retenTasa = null; $retenTipoFactor = null; $retencImpuesto = null; $sql_ret = " SELECT base,impuesto,tipo_factor,tasa,importe FROM ".MAIN_DB_PREFIX."cfdimx_retencionesdet WHERE factura_id=".$id." AND fk_facturedet=".$id_detalle." AND impuesto='".$impuesto."'"; $res_sql_ret = $this->db->query($sql_ret); $num_sql_ret = $this->db->num_rows($res_sql_ret); if($num_sql_ret > 0){ $obj_ret = $this->db->fetch_object($res_sql_ret); $retenBase = str_replace($vowels, "",number_format($obj_ret->base,2)); $retenImporte = str_replace($vowels, "",number_format($obj_ret->importe,2)); $retenTasa = $obj_ret->tasa; $retenTipoFactor = $obj_ret->tipo_factor; $retencImpuesto = $obj_ret->impuesto; } $retenciones = array( "retenBase" => $retenBase, "retenImporte" => $retenImporte, "retenTasa" => $retenTasa, "retenTipoFactor" => $retenTipoFactor, "retencImpuesto" => $retencImpuesto ); return $retenciones; } public function getImpuestosDoctoRel($id_factura, $uuid_factura){ global $conf; $factura = new Facture($this->db); $factura->fetch($id_factura); if($factura->type == 2){ $vowels = array(",", "-"); }else{ $vowels = array(","); } $producto = new Product($this->db); //print '
'; print_r($factura->lines); print '
'; $descheader = 0; $cfdi_decimal = isset($conf->global->MAIN_INFO_CFDI_NUM_CFDI_DECIMAL) ? $conf->global->MAIN_INFO_CFDI_NUM_CFDI_DECIMAL : 2; $mostrar_descuentos = $this->mostrarDescuentos(); $version_cfdi_sat = $conf->global->CFDIMX_VERSION_SAT; $conceptos = array(); for($i=0; $i < sizeof($factura->lines); $i++) { $impuesto = '002'; if ($factura->lines[$i]->fk_product != "") { $producto->fetch($factura->lines[$i]->fk_product); $tipoFactor = $producto->array_options["options_exentoiva"]; $objimp = $producto->array_options["options_objimp"]; if(@$factura->lines[$i]->array_options["options_exentoiva"] != ""){ $tipoFactor = $factura->lines[$i]->array_options["options_exentoiva"]; } if(@$factura->lines[$i]->array_options["options_objimp"] != "" && $factura->lines[$i]->array_options["options_objimp"] != 0){ $objimp = $factura->lines[$i]->array_options["options_objimp"]; } }else{ $tipoFactor = $factura->lines[$i]->array_options["options_exentoiva"]; $objimp = $factura->lines[$i]->array_options["options_objimp"]; } $label_tipoFactor = ($tipoFactor == 1 ? 'Exento' : 'Tasa'); if(@$conf->global->MAIN_MODULE_MULTICURRENCY == 1 && $factura->multicurrency_code != "MXN") { $factura_subtotal_detalle = $factura->lines[$i]->multicurrency_total_ht; $importeImpuesto = $factura->lines[$i]->multicurrency_total_tva; if($factura->lines[$i]->remise_percent != 0 && $mostrar_descuentos == 1){ $descuento = $factura->lines[$i]->remise_percent/100; $descuento2 = ($factura->lines[$i]->multicurrency_subprice*$factura->lines[$i]->qty)*$descuento; $descuento2 = str_replace(array("-",","), "",number_format($descuento2,2)); $descprodl = str_replace(array("-",","), "",number_format($descuento2,2)); $descheader = $descheader+$descuento2; $total_vuni = number_format($factura->lines[$i]->multicurrency_subprice,$cfdi_decimal); $total_ttc = number_format($factura->lines[$i]->multicurrency_subprice*$factura->lines[$i]->qty,$cfdi_decimal); }else{ if($factura->lines[$i]->remise_percent!=0 && $mostrar_descuentos==2){ $descuento = $factura->lines[$i]->multicurrency_total_ht/$factura->lines[$i]->qty; $total_vuni = number_format($descuento,$cfdi_decimal); $total_ttc = number_format($factura->lines[$i]->multicurrency_total_ht,$cfdi_decimal); }else{ $total_vuni = number_format($factura->lines[$i]->multicurrency_subprice,$cfdi_decimal); $total_ttc = number_format($factura->lines[$i]->multicurrency_total_ht,$cfdi_decimal); } } }else{ $factura_subtotal_detalle = $factura->lines[$i]->total_ht; $importeImpuesto = $factura->lines[$i]->total_tva; if($factura->lines[$i]->remise_percent != 0 && $mostrar_descuentos == 1){ $descuento = $factura->lines[$i]->remise_percent/100; $descuento2 = ($factura->lines[$i]->subprice*$factura->lines[$i]->qty)*$descuento; $descuento2 = str_replace(array("-",","), "",number_format($descuento2,2)); $descprodl = str_replace(array("-",","), "",number_format($descuento2,2)); $descheader = $descheader+$descuento2; $total_vuni = number_format($factura->lines[$i]->subprice,$cfdi_decimal); $total_ttc = number_format($factura->lines[$i]->subprice*$factura->lines[$i]->qty,$cfdi_decimal); }else{ if($factura->lines[$i]->remise_percent!=0 && $mostrar_descuentos==2){ $descuento = $factura->lines[$i]->total_ht/$factura->lines[$i]->qty; $total_vuni = number_format($descuento,$cfdi_decimal); $total_ttc = number_format($factura->lines[$i]->total_ht,$cfdi_decimal); }else{ $total_vuni = number_format($factura->lines[$i]->subprice,$cfdi_decimal); $total_ttc = number_format($factura->lines[$i]->total_ht,$cfdi_decimal); } } } ///Inicia Ajuste Nota Credito if($total_vuni == 0) $total_vuni = number_format($factura->lines[$i]->subprice, $cfdi_decimal); if($total_ttc == 0) $total_ttc = number_format($factura->lines[$i]->total_ht, $cfdi_decimal); if($factura->lines[$i]->total_tva == 0) $factura->lines[$i]->total_tva = $factura->lines[$i]->total_tva; if($factura->lines[$i]->total_ht == 0) $factura->lines[$i]->total_ht = $factura->lines[$i]->total_ht; ///Termina Ajuste Nota Credito $retencion_iva = $this->obtenerRetencionesProducto($factura->id, $factura->lines[$i]->id, '002', $vowels); $retencion_isr = $this->obtenerRetencionesProducto($factura->id, $factura->lines[$i]->id, '001', $vowels); if(strcmp($version_cfdi_sat, "4.0") == 0){ $conceptos[] = array( // "descripcion" => $descripcion, // "descripcion" => $descripcion_xml, // 'cantidad' =>str_replace($vowels, "",number_format($cantidad,2)), // 'valorUnitario'=>str_replace($vowels, "", $total_vuni), // 'importe'=>str_replace($vowels, "", $total_ttc), // 'importeImpuesto'=>str_replace($vowels, "",round(($factura->lines[$i]->total_tva),6)), 'importeImpuesto'=>str_replace($vowels, "",round(($importeImpuesto),6)), 'impuesto'=>$impuesto, 'tasa'=>number_format(($factura->lines[$i]->tva_tx/100),6), // "unidad" => $unidad, // 'noIdentificacion' => $noIdentificacion, // 'tipoFactor'=>"Tasa", 'tipoFactor' => $label_tipoFactor, // 'claveProdServ' => $claveprodserv, // 'base'=>str_replace($vowels, "", number_format($factura->lines[$i]->total_ht,2)), 'base'=>str_replace($vowels, "", number_format($factura_subtotal_detalle,2)), 'retenBase'=>$retencion_iva["retenBase"], 'retenImporte'=>$retencion_iva["retenImporte"], 'retenTasa'=>number_format($retencion_iva["retenTasa"],6), 'retenTipoFactor'=>$retencion_iva["retenTipoFactor"], 'retencImpuesto'=>$retencion_iva["retencImpuesto"], 'retenBaseISR'=>$retencion_isr["retenBase"], 'retenImporteISR'=>$retencion_isr["retenImporte"], 'retenTasaISR'=>number_format($retencion_isr["retenTasa"],6), 'retenTipoFactorISR'=>$retencion_isr["retenTipoFactor"], 'retencImpuestoISR'=>$retencion_isr["retencImpuesto"], // 'descuento'=>$descprodl, // 'cuentaPredial'=>$cuentapredial, 'objetoImp'=>$objimp ); } } #Inicia verifiación de desglose de Impuestos $impuestos = array(); if($conceptos != null){ foreach($conceptos AS $valores){ // print '
'; print_r($valores); print '
'; ##Retencion IVA $retencion_iva = array( "base" => $valores["retenBase"], "impuesto" => $valores["retencImpuesto"], "tipoFactor" => $valores["retenTipoFactor"], "tasaOCuota" => $valores["retenTasa"], "importe" => $valores["retenImporte"], "tipo" => 1 ); if($valores["retencImpuesto"] != null && $valores["objetoImp"] == "02"){ array_push($impuestos, $retencion_iva); } ##Retencion ISR $retencion_isr = array( "base" => $valores["retenBaseISR"], "impuesto" => $valores["retencImpuestoISR"], "tipoFactor" => $valores["retenTipoFactorISR"], "tasaOCuota" => $valores["retenTasaISR"], "importe" => $valores["retenImporteISR"], "tipo" => 1 ); if($valores["retencImpuestoISR"] != null && $valores["objetoImp"] == "02"){ array_push($impuestos, $retencion_isr); } ##Traslado $traslado = array( "base" => $valores["base"], "impuesto" => $valores["impuesto"], "tipoFactor" => $valores["tipoFactor"], "tasaOCuota" => $valores["tasa"], "importe" => $valores["importeImpuesto"], "tipo" => 2 ); if($valores["importeImpuesto"] != null && $valores["objetoImp"] == "02"){ array_push($impuestos, $traslado); } } } #Termina verifiación de desglose de Impuestos #Inicia Agrupacion de Impuestos if($impuestos != null){ $nuevos_impuestos_tras_ret = array(); foreach($impuestos AS $impuesto){ $impuesto_tras_ret = array( "base" => $impuesto["base"], "impuesto" => $impuesto["impuesto"], "tipoFactor" => $impuesto["tipoFactor"], "tasaOCuota" => $impuesto["tasaOCuota"], "importe" => $impuesto["importe"], "tipo" => $impuesto["tipo"] ); if(count($nuevos_impuestos_tras_ret) == 0){ array_push($nuevos_impuestos_tras_ret, $impuesto_tras_ret); }else{ $validaciones = $this->existeTasaOCuota($nuevos_impuestos_tras_ret, $impuesto_tras_ret); if($validaciones["encontrado"] == 0){ array_push($nuevos_impuestos_tras_ret, $impuesto_tras_ret); }else{ if($validaciones["posicion"] >= 0){ $nuevos_impuestos_tras_ret[$validaciones["posicion"]]["base"] += $impuesto["base"]; $nuevos_impuestos_tras_ret[$validaciones["posicion"]]["importe"] += $impuesto["importe"]; } } } } if(!is_null($nuevos_impuestos_tras_ret) && count($nuevos_impuestos_tras_ret) > 0){ unset($impuestos); $impuestos = array(); foreach ($nuevos_impuestos_tras_ret AS $nuevo_tras_ret) { $info_impuesto = array( "base" => $nuevo_tras_ret["base"], "impuesto" => $nuevo_tras_ret["impuesto"], "tipoFactor" => $nuevo_tras_ret["tipoFactor"], "tasaOCuota" => $nuevo_tras_ret["tasaOCuota"], "importe" => number_format($nuevo_tras_ret["base"] * $nuevo_tras_ret["tasaOCuota"], 2, ".", ""), "tipo" => $nuevo_tras_ret["tipo"] ); array_push($impuestos, $info_impuesto); } } } #Termina Agrupacion de Impuestos return $impuestos; } public function existeTasaOCuota($lista_impuetos, $impuesto){ $encontrado = 0; $posicion = 0; foreach ($lista_impuetos as $lista_impuesto) { if( strcmp($lista_impuesto["impuesto"], $impuesto["impuesto"]) == 0 && strcmp($lista_impuesto["tipoFactor"], $impuesto["tipoFactor"]) == 0 && strcmp($lista_impuesto["tasaOCuota"], $impuesto["tasaOCuota"]) == 0 && $lista_impuesto["tipo"] == $impuesto["tipo"] ){ $encontrado = 1; break; } $posicion++; } $validaciones = array( "encontrado" => $encontrado, "posicion" => $posicion, ); return $validaciones; } public function getDatosXML($ref_pago, $uuid){ global $conf; $ruta_xml = $conf->facture->dir_output."/".$ref_pago."/Pago_".$uuid.".xml"; $xml = simplexml_load_string(file_get_contents($ruta_xml)); $ns = $xml->getNamespaces(true); $xml->registerXPathNamespace('c', $ns['cfdi']); $xml->registerXPathNamespace('t', $ns['tfd']); $emisor_rfc = ""; $receptor_rfc = ""; foreach ($xml->xpath('//cfdi:Comprobante//cfdi:Emisor') as $Emisor){ $emisor_rfc = (String)$Emisor["Rfc"]; } foreach ($xml->xpath('//cfdi:Comprobante//cfdi:Receptor') as $Receptor){ $receptor_rfc = (String)$Receptor["Rfc"]; } $informacion_xml = array(); if($emisor_rfc != "" && $receptor_rfc != ""){ $informacion_xml = array( "emisor_rfc" => $emisor_rfc, "receptor_rfc" => $receptor_rfc ); } return $informacion_xml; } public function validarDocumentosRel($id_pago){ global $conf; $validacion = 0; $sql = "SELECT"; $sql .= " f.rowid as facid, f.ref, f.type, f.total_ttc, f.paye, f.fk_statut, pf.amount, pf.multicurrency_amount,"; $sql .= " s.nom as name, s.rowid as socid,"; $sql .= " (SELECT count(*) FROM ".MAIN_DB_PREFIX."cfdimx AS cfdi WHERE cfdi.fk_facture = f.rowid) AS reg_cfdimx"; $sql .= " FROM ".MAIN_DB_PREFIX."paiement_facture as pf, ".MAIN_DB_PREFIX."facture as f, ".MAIN_DB_PREFIX."societe as s"; $sql .= " WHERE"; $sql .= " pf.fk_facture = f.rowid"; $sql .= " AND f.fk_soc = s.rowid"; $sql .= " AND f.entity = ".$conf->entity; $sql .= " AND pf.fk_paiement = ".$id_pago; // print $sql.'
'; $res = $this->db->query($sql); $num = $this->db->num_rows($sql); if($num > 0){ $i = 0; while($obj = $this->db->fetch_object($res)){ $icono = ''; if($obj->reg_cfdimx == 0){ $validacion++; $icono = ''; } $this->lista_val_doc_rel[] = array( "facid" => $obj->facid, "reg_cfdimx" => $obj->reg_cfdimx, "icono" => $icono ); $i++; } } return $validacion; } public function validarComplemento(){ global $conf; $validacion = 0; $this->id_complemento = 0; $this->status_cdfi = 0; // 0 -> Borrador, 1 -> Timbrado $this->status_guardado = 0; // 0 -> Sin guardar, 1 -> Guardado $sql = "SELECT * FROM ".MAIN_DB_PREFIX."cfdimx_recepcion_pagos"; $sql .= " WHERE"; $sql .= " fk_facture = 0"; $sql .= " AND fk_paiement = ".$this->id_doli; $sql .= " AND entity = ".$conf->entity; // print $sql.'
'; $res = $this->db->query($sql); $num = $this->db->num_rows($res); if($num > 0){ $obj = $this->db->fetch_object($res); $this->id_complemento = $obj->rowid; $this->status_guardado = 1; if(!is_null($obj->uuid) && $obj->uuid != ""){ $this->status_cdfi = 1; } if($obj->cancelado == 1){ $this->status_cdfi = 2; } $validacion = 1; } return $validacion; } public function getTimbres(){ global $conf; $url_ws = $conf->global->MAIN_MODULE_CFDIMX_WS; $peticion = new nusoap_client($url_ws, 'wsdl'); $datos_peticion = array( "rfc" => $conf->global->MAIN_INFO_SIREN ); $res_peticion = $peticion->call('validaCliente', $datos_peticion); // $status_clt = $res_peticion["return"]["status_cliente_id"]; // $status_clt_desc = $res_peticion["return"]["status_cliente_desc"]; $this->folios["timbrados"] = $res_peticion["return"]["folios_timbrados"]; // $this->folios["adquiridos"] = $res_peticion["return"]["folios_adquiridos"]; $this->folios["disponibles"] = $res_peticion["return"]["folios_disponibles"]; $sql = "SELECT * FROM ".MAIN_DB_PREFIX."cfdimx_config"; $sql .= " WHERE"; $sql .= " emisor_rfc = '".$conf->global->MAIN_INFO_SIREN."'"; $sql .= " AND entity_id = ".$conf->entity; $res = $this->db->query($sql); $num = $this->db->num_rows($res); if ($num > 0){ $obj = $this->db->fetch_object($res); $this->conf_ws["estatus"] = $obj->status_conf; $this->conf_ws["modo_timbrado"] = $obj->modo_timbrado; $this->conf_ws["pass_timbrado"] = $obj->password_timbrado_txt; } // conf_ws // estatus // modo_timbrado // pass_timbrado } public function getFacturasCorreo($id_pago){ // lista_facturas_correo $this->lista_facturas_correo[-1] = "Seleccione la factura de la cual desea enviar sus documentos"; $sql = "SELECT pf.*, f.ref FROM ".MAIN_DB_PREFIX."paiement_facture pf"; $sql .= " INNER JOIN ".MAIN_DB_PREFIX."facture f ON pf.fk_facture=f.rowid"; $sql .= " WHERE"; $sql .= " pf.fk_paiement = ".$id_pago; $res = $this->db->query($sql); $num = $this->db->num_rows($res); if ($num > 0) { while ($obj = $this->db->fetch_object($res)) { $this->lista_facturas_correo[$obj->fk_facture] = $obj->ref; } } } public function getEstatusComplemento($uuid){ global $conf; $sql = ""; $sql = "SELECT * FROM ".MAIN_DB_PREFIX."cfdimx_estatus"; $sql .= " WHERE uuid = '".$uuid."'"; $sql .= " AND entity = ".$conf->entity; $res = $this->db->query($sql); $this->info_estatus["registro"] = $this->db->num_rows($res); if($this->info_estatus["registro"] > 0){ $obj = $this->db->fetch_object($res); $this->info_estatus["estado_cfdi"] = $obj->estado; $this->info_estatus["estatus_cancelacion"] = $obj->escancelable; $this->info_estatus["fecha_consulta_estatus"] = $obj->fecha." ".$obj->hora; } } public function log($ref){ global $conf; if(file_exists($conf->facture->dir_output."/".$ref)){ }else{ mkdir($conf->facture->dir_output."/".$ref,0700); } $fecha = date("Y-m-d")."_".date("H-i-s"); $archivo_acuse = "log_timbrado.txt"; $nombre_file_acuse = $conf->facture->dir_output."/".$ref."/".$archivo_acuse; $file_acuse = fopen ($nombre_file_acuse, "w"); ##Inicia Header fwrite($file_acuse, "Header"); fwrite($file_acuse, "\n"); foreach ($_SESSION['header'] as $key => $value) { $texto = $key.':: --> ::'.$value.'::'; fwrite($file_acuse, utf8_encode($texto)); fwrite($file_acuse, "\n"); unset($texto); } fwrite($file_acuse, "\n"); fwrite($file_acuse, "\n"); ##Termina Header ##Inicia Conceptos fwrite($file_acuse, "Conceptos"); fwrite($file_acuse, "\n"); foreach ($_SESSION['conceptos'] as $key => $value) { foreach ($value as $key2 => $value2) { $texto = $key2.':: --> ::'.$value2.'::'; fwrite($file_acuse, utf8_encode($texto)); fwrite($file_acuse, "\n"); unset($texto); } fwrite($file_acuse, "\n"); } fwrite($file_acuse, "\n"); fwrite($file_acuse, "\n"); ##Termina Conceptos ##Inicia Emisor fwrite($file_acuse, "Emisor"); fwrite($file_acuse, "\n"); foreach ($_SESSION['emisor'] as $key => $value) { $texto = $key.':: --> ::'.$value.'::'; fwrite($file_acuse, utf8_encode($texto)); fwrite($file_acuse, "\n"); unset($texto); } fwrite($file_acuse, "\n"); fwrite($file_acuse, "\n"); ##Termina Emisor ##Inicia Receptor fwrite($file_acuse, "Receptor"); fwrite($file_acuse, "\n"); foreach ($_SESSION['receptor'] as $key => $value) { $texto = $key.':: --> ::'.$value.'::'; fwrite($file_acuse, utf8_encode($texto)); fwrite($file_acuse, "\n"); unset($texto); } fwrite($file_acuse, "\n"); fwrite($file_acuse, "\n"); ##Termina Receptor ##Inicia Adicionales fwrite($file_acuse, "Adicionales"); fwrite($file_acuse, "\n"); foreach ($_SESSION['adicionales'] as $key1 => $value1) { if(is_array($value1)){ foreach ($value1 as $key2 => $value2) { if(is_array($value2)){ foreach ($value2 as $key3 => $value3) { if(is_array($value3)){ foreach ($value3 as $key4 => $value4) { if(is_array($value4)){ foreach ($value4 as $key5 => $value5) { if(is_array($value5)){ foreach ($value5 as $key6 => $value6) { if(is_array($value6)){ foreach ($value6 as $key7 => $value7) { if(is_array($value7)){ foreach ($value7 as $key8 => $value8) { $texto = $key8.':: --> ::'.$value8.'::'; fwrite($file_acuse, utf8_encode($texto)); fwrite($file_acuse, "\n"); unset($texto); } }else{ $texto = $key7.':: --> ::'.$value7.'::'; fwrite($file_acuse, utf8_encode($texto)); fwrite($file_acuse, "\n"); unset($texto); } } }else{ $texto = $key6.':: --> ::'.$value6.'::'; fwrite($file_acuse, utf8_encode($texto)); fwrite($file_acuse, "\n"); unset($texto); } } fwrite($file_acuse, "\n"); }else{ $texto = $key5.':: --> ::'.$value5.'::'; fwrite($file_acuse, utf8_encode($texto)); fwrite($file_acuse, "\n"); unset($texto); } } fwrite($file_acuse, "\n"); }else{ $texto = $key4.':: --> ::'.$value4.'::'; fwrite($file_acuse, utf8_encode($texto)); fwrite($file_acuse, "\n"); unset($texto); } } fwrite($file_acuse, "\n"); }else{ $texto = $key3.':: --> ::'.$value3.'::'; fwrite($file_acuse, utf8_encode($texto)); fwrite($file_acuse, "\n"); unset($texto); } } fwrite($file_acuse, "\n"); }else{ $texto = $key2.':: --> ::'.$value2.'::'; fwrite($file_acuse, utf8_encode($texto)); fwrite($file_acuse, "\n"); unset($texto); } } fwrite($file_acuse, "\n"); }else{ $texto1 = $key1.':: --> ::'.$value1.'::'; fwrite($file_acuse, utf8_encode($texto1)); fwrite($file_acuse, "\n"); } fwrite($file_acuse, "\n"); } fwrite($file_acuse, "\n"); fwrite($file_acuse, "\n"); ##Termina Adicionales fwrite($file_acuse, "rfc_emisor --> ::".$_SESSION['rfc_emisor']."::"); fwrite($file_acuse, "\n"); fwrite($file_acuse, "passwd_timbrado --> ::".$_SESSION['passwd_timbrado']."::"); fwrite($file_acuse, "\n"); fwrite($file_acuse, "\n"); ##Inicia Respuesta fwrite($file_acuse, "Respuesta"); fwrite($file_acuse, "\n"); foreach ($_SESSION['resultado'] as $key => $value) { foreach ($value as $key2 => $value2) { $texto = $key2.':: --> ::'.$value2.'::'; fwrite($file_acuse, utf8_encode($texto)); fwrite($file_acuse, "\n"); unset($texto); } } fwrite($file_acuse, "\n"); fwrite($file_acuse, "\n"); ##Termina Respuesta // // // fclose($file_acuse); } } ?>