nfo] [fetchCompletions] Request 4717da0e-c730-4e61-89d8-0898c25d6229 at finished with 200 status after 441.8874440006912ms 2025-05-29 16:33:54.508 [info] [streamChoices] solution 0 returned. finish reason: [stop] 2025-05-29 16:34:06.199 [info] [fetchCompletions] Request acb275f2-fc20-4bd1-9450-284f042f95f5 at finished with 200 status after 699.1584509983659ms 2025-05-29 16:34:06.253 [info] [fetchCompletions] Request 6df530c7-6a9c-47e2-91cc-30c7df97c809 at finished with 200 status after 461.80793699994683ms 2025-05-29 16:34:06.256 [info] [streamChoices] solution 0 returned. finish reason: [stop] 2025-05-29 16:34:11.824 [info] [fetchCompletions] Request e89a8f1a-3561-445b-af0d-efdddeddfd2c at finished with 200 status after 396.0873329974711ms 2025-05-29 16:34:11.827 [info] [streamChoices] solution 0 returned. finish reason: [stop] 2025-05-29 16:48:49.409 [info] [fetcher] Using Helix fetcher, Electron fetcher is not available. 2025-05-29 16:48:49.409 [info] [code-referencing] Public code references are enabled. 2025-05-29 16:48:49.416 [info] [fetcher] Using Helix fetcher, Electron fetcher is not available. 2025-05-29 16:48:49.827 [info] [fetchCompletions] Request e7ce409b-e7a9-483a-936b-a8906482ad74 at finished with 200 status after 401.7778959982097ms 2025-05-29 16:48:49.831 [info] [streamChoices] solution 0 returned. finish reason: [stop] 2025-05-29 16:48:51.489 [info] [fetchCompletions] Request 2694e8e2-843e-4e28-8ba6-9ff634f066c7 at finished with 200 status after 383.0955920033157ms 2025-05-29 16:48:51.491 [info] [streamChoices] solution 0 returned. finish reason: [stop] 2025-05-29 16:48:52.226 [info] [fetchCompletions] Request 3f7ffe38-db97-4a51-b1e5-3d458ac9053e at finished with 200 status after 192.3767200000584ms 2025-05-29 16:48:52.228 [info] [streamChoices] solution 0 returned. finish reason: [stop] 2025-05-29 16:49:07.573 [info] [fetchCompletions] Request 96505bd5-e1b7-4cef-84a9-dfe957659756 at finished with 200 status after 275.17082199826837ms 2025-05-29 16:49:07.774 [info] [fetchCompletions] Request cc52ac31-59fb-4bdc-91cd-680e2c6ffd6d at finished with 200 status after 207.99795600026846ms 2025-05-29 16:49:07.777 [info] [streamChoices] solution 0 returned. finish reason: [stop] 2025-05-29 16:49:08.186 [info] [fetchCompletions] Request caa3258f-67dd-4d95-a8bf-eb2d9a046886 at finished with 200 status after 238.47089099884033ms 2025-05-29 16:49:08.188 [info] [streamChoices] solution 0 returned. finish reason: [stop] 2025-05-29 16:49:08.648 [info] [fetchCompletions] Request 1e140dbb-9e78-431c-85fe-b14268de7fc6 at finished with 200 status after 223.3755670003593ms 2025-05-29 16:49:08.649 [info] [streamChoices] solution 0 returned. finish reason: [stop] 2025-05-29 16:49:12.017 [info] [fetchCompletions] Request bf352c53-b66e-46b1-995c-3ac0324c78d1 at finished with 200 status after 187.62168999761343ms 2025-05-29 16:49:12.019 [info] [streamChoices] solution 0 returned. finish reason: [stop] 2025-05-29 16:49:22.614 [info] [fetchCompletions] Request 24661d91-8aaf-4d30-8aa2-6ee6cbb07e79 at function formatMoney(string $amount): string { $clean = preg_replace('/[^0-9.]/', '', $amount); return '$ ' . number_format((float)$clean, 2, '.', ','); } # ------------------------------------------------------------------------------------------------------------------------------------------------------------------ # MODAL PARA MOSTRAR ERRORES # ------------------------------------------------------------------------------------------------------------------------------------------------------------------ --> function showMessage(string $title, string $message): void { // Generar el HTML del modal echo << HTML; } # ------------------------------------------------------------------------------------------------------------------------------------------------------------------ # OBTENGO EL TOKEN DE BOOKS # ------------------------------------------------------------------------------------------------------------------------------------------------------------------ function GetToken(){ $sOrganiZB = ""; if (isset($_REQUEST['pOrganiZB'])) { $sOrganiZB = $_REQUEST['pOrganiZB']; } else { echo 'Por favor introduzca el ID de la Organización de Zoho Books.'; return; } #---------------------------------------------------------------- # Creamos la conexión a la base de datos #---------------------------------------------------------------- $conn = mysqli_connect("127.0.0.1", "aptuslegal", "#Aptus2021#", "vendorbills"); if (!$conn) { echo "Error: No se pudo conectar a MySQL." . PHP_EOL; echo "errno de depuración: " . mysqli_connect_errno() . PHP_EOL; exit; } #---------------------------------------------------------------- # Traemos los valores de conexión utilizando el organizationId #---------------------------------------------------------------- $sql = 'SELECT * FROM conndetails WHERE organization_id = "' . $sOrganiZB.'"'; if($result = $conn->query($sql)) { $row = $result->fetch_assoc(); } else exit('No se ejecuto la consulta'); #---------------------------------------------------------------- # RFC de la Organización #---------------------------------------------------------------- $regFeCa = $row['rfc']; #---------------------------------------------------------------- # Variables para Zoho Books #---------------------------------------------------------------- $appOwner = $row['appOwner']; $boa_RefreshToken = $row['zbooks_rtoken']; $boa_ClientId = $row['zbooksclient_id']; $boa_ClientSecret = $row['zbooksclient_secret']; $boa_RedirectUri = $row['RedirectUri']; $boa_AuthUrl = 'https://accounts.zoho.com/oauth/v2/token'; $boa_GrantType = "refresh_token"; #---------------------------------------------------------------- # Cerramos la conexión #---------------------------------------------------------------- mysqli_close($conn); #---------------------------------------------------------------- # Obtengo el Token de Books #---------------------------------------------------------------- return oauth($appOwner, 'ZBooks', $boa_RefreshToken, $boa_ClientId, $boa_ClientSecret, $boa_RedirectUri, $boa_GrantType, $boa_AuthUrl); } # ------------------------------------------------------------------------------------------------------------------------------------------------------------------ # USUARIO ACTIVO # ------------------------------------------------------------------------------------------------------------------------------------------------------------------ function getUser($zbToken){ if (isset($_REQUEST['pOrganiZB'])) { $sOrganiZB = $_REQUEST['pOrganiZB']; } else { echo "Es necesario introducir el ID de la organización en Zoho Books"; } $request_url = "https://www.zohoapis.com/books/v3/users/me?organization_id=".$sOrganiZB; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $request_url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); curl_setopt($ch, CURLOPT_HTTPHEADER, array('Authorization: Zoho-oauthtoken ' . $zbToken)); $r = curl_exec($ch); $array = json_decode($r); $user = $array->user; curl_close ($ch); //var_dump($array->user); echo ''; echo "

Usuario activo: " . $user->name."

"; echo "

Rol activo: " . $user->user_role."

"; echo "

eMail: ".$user->email."

"; echo "

Estatus: " . $user->status."

"; } # ------------------------------------------------------------------------------------------------------------------------------------------------------------------ # BALANZA DE COMPROBACIÓN # ------------------------------------------------------------------------------------------------------------------------------------------------------------------ function getBalCom($zbToken){ $sOrganiZB = ""; if (isset($_REQUEST['pOrganiZB'])) { $sOrganiZB = $_REQUEST['pOrganiZB']; } $sAnioCat = $_POST['anio']; $sMesCat = $_POST['mes']; $sTipoEnv = $_POST['tipo']; $file_name = basename($_FILES["fileToUpload"]["name"]); $file_name = str_replace(' ', '_', $file_name); $temp_file = $_FILES["fileToUpload"]["tmp_name"]; $target_dir = "archs_csv/"; $target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]); $target_file = str_replace(' ', '_', $target_file); $uploadOk = 1; $imageFileType = strtolower(pathinfo($target_file,PATHINFO_EXTENSION)); if(empty($_POST['anio'])) { echo 'Por favor introduzca el Año para el proceso.'; } else if(empty($_POST['mes'])) { echo 'Por favor introduzca el Mes para el proceso.'; } else if(empty($_POST['tipo'])) { echo 'Por favor introduzca el Tipo para el proceso.'; } else if(empty($file_name)) { showMessage($title = 'Información faltante', $message = 'Por favor seleccione el archivo a procesar.'); return; } else if($sOrganiZB == "") { showMessage($title = 'Información erronea', $message = 'Por favor introduzca el ID de la Organización de Zoho Books.'); return; } else { // Check if file already exists if (file_exists($target_file)) { # showMessage($title = 'Información', $message = 'Se eliminó un archivo pre-existente con el mismo nombre.'); } // Allow certain file formats if($imageFileType != "csv" ) { showMessage($title = 'Información erronea', $message = 'El archivos debe contener el libro mayor y ser tipo CSV.'); return; } // Check if $uploadOk is set to 0 by an error if ($uploadOk == 0) { ?>message . '
'; if (curl_errno($ch)) { $error_msg = curl_error($ch); } curl_close ($ch); if (isset($error_msg)) { $j_array = array('code' => $JsonResponse->code, 'message' => "Error al procesar la balanza: " . $JsonResponse->message); $Resultado = json_encode($j_array); echo $Resultado; return; } else { /********************************************************************/ // LINKS DE DESCARGA /********************************************************************/ $linkXML = ''.$JsonResponse->data->xmlFileName.''; $linkCSV = ''.$JsonResponse->data->csvFileName.''; $linkZIP = ''.$JsonResponse->data->zipFileName.''; /********************************************************************/ // MODAL /********************************************************************/ ?> true, CURLOPT_FOLLOWLOCATION => true, // GET es el método por defecto, no es necesario CURLOPT_POST = false ]); $r = curl_exec($ch); if (curl_errno($ch)) { $error_msg = curl_error($ch); curl_close($ch); echo json_encode(['code'=>'666','message'=>"Error en la llamada curl: $error_msg"]); return; } curl_close($ch); // 4. Parsear JSON de respuesta $resp = json_decode($r, true); if (!$resp || !isset($resp['code'])) { echo 'Respuesta inválida del servicio.'; return; } if ($resp['code'] !== '200') { // Mostrar el mensaje de error que regresa el servicio echo 'Error al generar Auxiliar: ' . ($resp['message'] ?? 'Desconocido'); return; } // 5. Construir enlaces de descarga con los nombres reales $XML_Path = 'https://aptuslegal.app/aptusContaElec/archs_xml/'; $ZIP_Path = 'https://aptuslegal.app/aptusContaElec/archs_zip/'; $xmlFileName = $resp['xml_file']; // viene, por ejemplo, "RFC202504AC.xml" $zipFileName = $resp['zip_file']; // viene, p.ej., "RFC202504AC.zip" $fileXmlUrl = sprintf( '%s', $XML_Path, $xmlFileName, $xmlFileName, 'Auxiliar de Cuentas XML' ); $fileZipUrl = sprintf( '%s', $ZIP_Path, $zipFileName, $zipFileName, 'Auxiliar de Cuentas ZIP' ); // 6. Renderizar tu modal con los enlaces ?> '666', 'message' => "Error en la llamada curl " . $error_msg); $Resultado = json_encode($j_array); echo $Resultado; return; } else { /********************************************************************/ // LINKS DE DESCARGA /********************************************************************/ $XML_Path = 'https://aptuslegal.app/aptusContaElec/archs_xml/'; $ZIP_Path = 'https://aptuslegal.app/aptusContaElec/archs_zip/'; $XML_fileName = $XML_Path.'AML9605085V8'.$sAnioCat.$sMesCat.'XF.xml'; // basename() extrae sólo "AML9605085V8202505XF.xml" $xmlBasename = basename($XML_fileName); // El link sigue apuntando a la URL, pero el download sólo lleva el nombre $fileXmlUrl = 'Auxiliar de folios XML
'; // Igual para el ZIP: $ZIP_fileName = $ZIP_Path.'AML9605085V8'.$sAnioCat.$sMesCat.'XF.zip'; $zipBasename = basename($ZIP_fileName); $fileZipUrl = 'Auxiliar de folios ZIP
'; /********************************************************************/ ?> message; if (curl_errno($ch)) { $error_msg = curl_error($ch); } curl_close ($ch); if (isset($error_msg)) { $j_array = array('code' => '500', 'message' => "Error en la llamada curl: " . $error_msg); $Resultado = json_encode($j_array); //echo $Resultado; return; } else { /********************************************************************/ // LINKS DE DESCARGA /********************************************************************/ $linkXML = ''.$JsonResponse->data->xmlFileName.''; $linkZIP = ''.$JsonResponse->data->zipFileName.''; /********************************************************************/ // MODAL /********************************************************************/ ?> ', $errors); return; } $queryParams = http_build_query([ 'Anio' => $anio, 'Mes' => $mes, 'pOrganiZB' => $organiZB, 'pOrganiAnalytics' => '722699151', 'RFC' => 'AML9605085V8', 'workspace' => '2296733000000004013', 'view' => '2296733000030848002', 'appOwner' => 'arochiylindner.aptus', 'txbNumeroOrden' => $txbNumeroOrden, 'TipoSolicitud' => $TipoSolicitud ]); $url = "https://aptuslegal.app/aptusContaElec/wsPolizasAnalytics.php?$queryParams"; echo implode('
', $url); $curl = curl_init(); curl_setopt_array($curl, array( CURLOPT_URL => $url, CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => '', CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 0, CURLOPT_FOLLOWLOCATION => true, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => 'GET', )); $response = curl_exec($curl); curl_close($curl); // Decodificar la respuesta del servicio $data = json_decode($response, true); if (!$data || $data['code'] !== "200") { echo "Ocurrió un error al generar las pólizas: " . ($data['message'] ?? 'Respuesta inválida del servicio.'); return; } $xmlFileName = $data['xml_file_name']; $zipFileName = $data['zip_file_name']; $csvFileName = $data['csv_file_name'] ?? null; $XML_file = "https://aptuslegal.app/aptusContaElec/archs_xml/$xmlFileName"; $ZIP_file = "https://aptuslegal.app/aptusContaElec/archs_zip/$zipFileName"; $CSV_file = "https://aptuslegal.app/aptusContaElec/archs_csv/$csvFileName"; // Output con HTML ?>