======= $cfdi = $xml->saveXML(); $xml->formatOutput = true; $xml->save($file_name_with_full_path); unset($xml); #=== Se dan permisos de escritura al archivo .xml. ========================= if($tipoEnvio == "N") { chmod($SendaXML.$regFeCa.$anioCat.$mesCata."BN.xml", 0777); } else { chmod($SendaXML.$regFeCa.$anioCat.$mesCata."BC.xml", 0777); } #=== Se procede a crear el archivo ZIP del Catalogo de Cuentas ========================= $zip = new ZipArchive(); $zipFilesPath = 'archs_zip/'; if($tipoEnvio == "N") { $nombreArchivoZip = $zipFilesPath.$regFeCa.$anioCat.$mesCata."BN.zip"; $nameArchZip = $regFeCa.$anioCat.$mesCata."BN.zip"; } else { $nombreArchivoZip = $zipFilesPath.$regFeCa.$anioCat.$mesCata."BC.zip"; $nameArchZip = $regFeCa.$anioCat.$mesCata."BC.zip"; } #=== Si existe el archivo ZIP se elimina para crear el nuevo ======================= if(!file_exists($nombreArchivoZip)){ unlink($nombreArchivoZip); } if (!$zip->open($nombreArchivoZip, ZipArchive::CREATE | ZipArchive::OVERWRITE)) { exit("Error abriendo ZIP en $nombreArchivoZip"); } $nombre = basename($file_name_with_full_path); $zip->addFile($file_name_with_full_path, $nombre); $resultado = $zip->close(); if (!$resultado) { // echo "Error creando archivo"; exit("Error creando archivo ZIP"); } #=== FIN DEL PROCESO ======================= $resultData = array( 'xmlFilesPath' => $xmlFilesPath, 'xmlFileName' => $regFeCa.$anioCat.$mesCata."BN.xml", 'csvFilesPath' => $csvFilesPath, 'csvFileName' => $regFeCa.$anioCat.$mesCata."BN.csv", 'zipFilesPath' => $zipFilesPath, 'zipFileName' => $regFeCa.$anioCat.$mesCata."BN.zip", 'totalCargos' => round($totalCargos,2), 'totalAbonos' => round($totalAbonos,2), 'totalCuentas' => $Account1count, 'cantidadDeudoras' => 333); if($tipoEnvio == "N") { $j_array = array('code' => "200", 'message' => 'Proceso de creacion de Archivo (NORMAL) de Balanza de Comprobacion fue exitoso', 'data' => $resultData); } else { $j_array = array('code' => "200", 'message' => "Proceso de creacion de Archivo (COMPLEMENTARIO) de Balanza de Comprobacion fue exitoso", 'data' => $resultData); } $Resultado = json_encode($j_array); echo $Resultado; return $Resultado; ### FUNCIONES DEL MÓDULO ######################################################### # Funcion para convertir CSV a formato JSON function csvToJson($fname) { if (!($fp = fopen($fname, 'r'))) { die("No se pudo abrir el arcivo CSV..."); } $key = fgetcsv($fp,"1024",","); $json = array(); while ($row = fgetcsv($fp,"1024",",")) { $json[] = array_combine($key, $row); } fclose($fp); return json_encode($json); } # Función que integra los nodos al archivo .XML function cargaAttNodo(&$nodo, $attr){ global $xmldoc; foreach ($attr as $key => $val){ $val = preg_replace('/\s\s+/', ' ', $val); $val = trim($val); if (strlen($val)>0){ $val = utf8_encode(str_replace("|","/",$val)); $nodo->setAttribute($key,$val); } } }