Aug 6 09:16:23 ip-172-31-29-215 fwupdmgr[3080017]: Successfully downloaded new metadata: 0 local devices supported Aug 6 09:16:23 ip-172-31-29-215 systemd[1]: fwupd-refresh.service: Succeeded. Aug 6 09:16:23 ip-172-31-29-215 systemd[1]: Finished Refresh fwupd metadata and update motd. Aug 6 09:17:01 ip-172-31-29-215 CRON[3080059]: (root) CMD ( cd / && run-parts --report /etc/cron.hourly) Aug 6 09:20:01 ip-172-31-29-215 CRON[3080064]: (smmsp) CMD (test -x /etc/init.d/sendmail && test -x /usr/share/sendmail/sendmail && test -x /usr/lib/sm.bin/sendmail && /usr/share/sendmail/sendmail cron-msp) Aug 6 09:24:29 ip-172-31-29-215 amazon-ssm-agent.amazon-ssm-agent[1875640]: 2025-08-06 09:24:29.4635 WARN EC2RoleProvider Failed to connect to Systems Manager with instance profile role credentials. Err: retrieved credentials failed to report to ssm. Error: EC2RoleRequestError: no EC2 instance role found Aug 6 09:24:29 ip-172-31-29-215 amazon-ssm-agent.amazon-ssm-agent[1875640]: 2025-08-06 09:24:29.5096 ERROR EC2RoleProvider Failed to connect to Systems Manager with SSM role credentials. error calling RequestManagedInstanceRoleToken: AccessDeniedException: Systems Manager's instance management role is not configured for account: 227937466084 Aug 6 09:24:29 ip-172-31-29-215 amazon-ssm-agent.amazon-ssm-agent[1875640]: #011status code: 400, request id: 0c3f57cf-f45d-4bcf-a79a-ab2d318b1091 Aug 6 09:35:35 ip-172-31-29-215 systemd[1]: Created slice User Slice of UID 1000. Aug 6 09:35:35 ip-172-31-29-215 systemd[1]: Starting User Runtime Directory /run/user/1000... Aug 6 09:35:35 ip-172-31-29-215 systemd[1]: Finished User Runtime Directory /run/user/1000. Aug 6 09:35:35 ip-172-31-29-215 systemd[1]: Starting User Manager for UID 1000... Aug 6 09:35:35 ip-172-31-29-215 systemd[3080112]: Reached target Paths. Aug 6 09:35:35 ip-172-31-29-215 systemd[3080112]: Reached target Timers. Aug 6 09:35:35 ip-172-31-29-215 systemd[3080112]: Starting D-Bus User Message Bus Socket. Aug 6 09:35:35 ip-172-31-29-215 systemd[3080112]: Listening on GnuPG network certificate management daemon. Aug 6 09:35:35 ip-172-31-29-215 systemd[3080112]: Listening on GnuPG cryptographic agent and passphrase cache (access for web browsers). Aug 6 09:35:35 ip-172-31-29-215 systemd[3080112]: Listening on GnuPG cryptographic agent and passphrase cache (restricted). Aug 6 09:35:35 ip-172-31-29-215 systemd[3080112]: Listening on GnuPG cryptographic agent (ssh-agent emulation). Aug 6 09:35:35 ip-172-31-29-215 systemd[3080112]: Listening on GnuPG cryptographic agent and passphrase cache. Aug 6 09:35:35 ip-172-31-29-215 systemd[3080112]: Listening on debconf communication socket. Aug 6 09:35:35 ip-172-31-29-215 systemd[3080112]: Listening on Sound System. Aug 6 09:35:35 ip-172-31-29-215 systemd[3080112]: Listening on REST API socket for snapd user session agent. Aug 6 09:35:35 ip-172-31-29-215 systemd[3080112]: Listening on D-Bus User Message Bus Socket. Aug 6 09:35:35 ip-172-31-29-215 systemd[3080112]: Reached target Sockets. Aug 6 09:35:35 ip-172-31-29-215 systemd[3080112]: Reached target Basic System. Aug 6 09:35:35 ip-172-31-29-215 systemd[1]: Started User Manager for UID 1000. Aug 6 09:35:35 ip-172-31-29-215 systemd[3080112]: Starting Sound Service... Aug 6 09:35:35 ip-172-31-29-215 systemd[1]: Started Session 44374 of user ubuntu. Aug 6 09:35:35 ip-172-31-29-215 dbus-daemon[475]: [system] Activating via systemd: service name='org.bluez' unit='dbus-org.bluez.service' requested by ':1.30108' (uid=1000 pid=3080119 comm="/usr/bin/pulseaudio --daemonize=no --log-target=jo" label="unconfined") Aug 6 09:35:35 ip-172-31-29-215 systemd[1]: Condition check resulted in Bluetooth service being skipped. Aug 6 09:35:35 ip-172-31-29-215 rtkit-daemon[877]: Supervising 0 threads of 0 processes of 1 users. Aug 6 09:35:35 ip-172-31-29-215 rtkit-daemon[877]: message repeated 4 times: [ Supervising 0 threads of 0 processes of 1 users.] Aug 6 09:35:35 ip-172-31-29-215 systemd[3080112]: Started D-Bus User Message Bus. Aug 6 09:35:35 ip-172-31-29-215 dbus-daemon[30 "310", "message" => "ERROR - [wsPreBillZohoBooks] Parametros incompletos para el Servicio Web, falta el ID de la Orden de Cobro"); $Resultado = json_encode($j_array); echo $Resultado; return; } if($app_name_ZC == "") { $j_array = array('code' => "320", "message" => "ERROR - [wsPreBillZohoBooks] Parametros incompletos para el Servicio Web, falta el Nombre de la Aplicación"); $Resultado = json_encode($j_array); echo $Resultado; return; } // if($authtoken_ZC == "") // { // $j_array = array('code' => "330", "message" => "ERROR - [wsPreBillZohoBooks] Parametros incompletos para el Servicio Web, falta el Código de Autorización"); // $Resultado = json_encode($j_array); // echo $Resultado; // return; // } if($bDatPac == "") { $j_array = array('code' => "310", "message" => "ERROR - [wsPreBillZohoBooks] Faltan los parametros de conexión OAuth"); $Resultado = json_encode($j_array); echo $Resultado; return; } $bDatPac = base64_decode($bDatPac); $aDatPac = json_decode($bDatPac, true); $RefreshToken = $aDatPac["C_OAuth_refresh_token"]; $ClientId = $aDatPac["C_OAuth_client_id"]; $ClientSecret = $aDatPac["C_OAuth_client_secret"]; $RedirectUri = $aDatPac["C_OAuth_redirect_uri"]; $GrantType = $aDatPac["C_OAuth_grant_type"]; $AuthUrl = "https://accounts.zoho.com/oauth/v2/token"; #Obtenemos el access token de Zoho Creator #---------------------------------------------------------------- #== Llamado para generar el token para donatello #---------------------------------------------------------------- $curl = curl_init(); curl_setopt_array($curl, array( CURLOPT_URL => 'https://donatello.aptuslegal.app/oauth/token/f/'.$appOwner, 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', CURLOPT_HTTPHEADER => array( 'Authorization: Token e68d5a079f937ea29ad2ec5a5b105b75491a0e0c' ), )); $response = curl_exec($curl); curl_close($curl); // Decodificamos la respuesta JSON $data = json_decode($response, true); // Accedemos al valor de 'access_token de donatello' $access_token = $data['access_token']; #== Conexión a Zoho Creator para obtener el registro de la Orden de Cobro //$request_url = 'https://creator.zoho.com/api/json/'.$app_name_ZC.'/view/Prebills_Query?scope=creatorapi&raw=true&authtoken='.$authtoken_ZC.'&criteria=(ID='.$bRecId.')'; $request_url = 'https://creator.zoho.com/api/v2/'.$appOwner.'/'.$app_name_ZC.'/report/Prebills_Query?criteria=(ID='.$bRecId.')'; $context = [ 'recordId' => $bRecId, 'reportLinkName' => "Prebills_Query" ]; $bdDatBill = getZohoCreatorDataGeneric($request_url, $access_token, 5, 1, $context); if ($bdDatBill === null) { // Manejar el error adecuadamente $j_array = array('code' => "650", "message" => "ERROR - [wsPrebillZB_Seplaw_Esp001] No se puede obtener el registro de la Orden de Cobro desde Zoho Creator. Verifique que el ID de la Orden de Cobro sea correcto o que la aplicación esté activa."); $Resultado = json_encode($j_array); echo $Resultado; return; } //print_r($bdDatBill); #== Datos de la Orden de Cobro $prebill_number = str_pad($bdDatBill[0]->Prebill_Number, 6, "0", STR_PAD_LEFT); $prebill_client = $bdDatBill[0]->Client->display_value; $prebill_matter = $bdDatBill[0]->Matter->display_value; $prebill_date = $bdDatBill[0]->Prebill_Date; $prebill_IncDate = $bdDatBill[0]->Included_to; $prebill_currency = substr($bdDatBill[0]->Currency,0,3); $prebill_Fees = $bdDatBill[0]->Fees; $prebill_Disbur = $bdDatBill[0]->Disbursements; $prebill_SubTot = $bdDatBill[0]->Subtotal_Import; $prebill_ImpIva = $bdDatBill[0]->VAT_Import; $prebill_Import = $bdDatBill[0]->Total_Import; $prebill_PorIva = $bdDatBill[0]->VAT; $prebill_Factur = $bdDatBill[0]->Billable_Hours; $prebill_NoFact = $bdDatBill[0]->NON_Billable_Hours; $prebill_Trabaj = $bdDatBill[0]->Worked_Hours; $prebill_Notes = strip_tags($bdDatBill[0]->Notes); $prebill_TerCon = strip_tags($bdDatBill[0]->Terms_Conditions); $strTotal = number_format($bdDatBill[0]->Total_Import,2,".",""); #== Resumenes para el reporte $prebill_SummPro = json_decode("[".$bdDatBill[0]->Project_Summary."]"); $prebill_SummTks = json_decode("[".$bdDatBill[0]->Timekeeper_Summary."]"); $prebill_SummCha = json_decode("[".$bdDatBill[0]->Charges_Summary."]"); $sNumToLet = strtolower(convert_number_to_words($prebill_Import)); $Resto = substr($strTotal,strlen($strTotal)-2,2); //Obtiene decimales. if($prebill_currency == 'USD'){ $sNumToLet = "(".trim($sNumToLet)." DOLLARS ".$Resto."/100 USD)"; } elseif($prebill_currency == 'EUR'){ $sNumToLet = "(".trim($sNumToLet)." EUROS ".$Resto."/100 EUR)"; } else{ $sNumToLet = "(".trim($sNumToLet)." PESOS ".$Resto."/100 M.N.)"; } $prebill_domicilio = ""; $prebill_colonia = ""; $prebill_ciudad = ""; $prebill_estado = ""; $prebill_pais = ""; $prebill_codigo = ""; $prebill_attention = ""; foreach ( $bdDatBill[0] as $nombre => $hexa ) { if($nombre == "Client.Domicilio_fiscal") { $prebill_domicilio = $hexa; } if($nombre == "Client.Colonia_fiscal") { $prebill_colonia = $hexa; } if($nombre == "Client.Ciudad_fiscal") { $prebill_ciudad = $hexa; } if($nombre == "Client.Estado_fiscal") { $prebill_estado = $hexa; } if($nombre == "Client.Pais_fiscal") { $prebill_pais = $hexa; } if($nombre == "Client.Codigo_fiscal") { $prebill_codigo = $hexa; } if($nombre == "Client.Atencion_de_facturacion") { $prebill_attention = $hexa; } } $sFecha = ""; $sMes = substr($prebill_date,3,3); switch($sMes){ case "Jan": $sFecha = $sFecha . "January "; break; case "Ene": $sFecha = $sFecha . "January "; break; case "Feb": $sFecha = $sFecha . "February "; break; case "Mar": $sFecha = $sFecha . "March "; break; case "Apr": $sFecha = $sFecha . "April "; break; case "Abr": $sFecha = $sFecha . "April "; break; case "May": $sFecha = $sFecha . "May "; break; case "Jun": $sFecha = $sFecha . "June "; break; case "Jul": $sFecha = $sFecha . "July "; break; case "Aug": $sFecha = $sFecha . "August "; break; case "Ago": $sFecha = $sFecha . "August "; break; case "Sep": $sFecha = $sFecha . "September "; break; case "Oct": $sFecha = $sFecha . "October "; break; case "Nov": $sFecha = $sFecha . "November "; break; case "Dec": $sFecha = $sFecha . "December "; break; case "Dic": $sFecha = $sFecha . "December "; break; } $sFecha = $sFecha . substr($prebill_date,0,2).", "; $sFecha = $sFecha . substr($prebill_date,7,4); #== Conexión a Zoho Creator para obtener los registros de tiempos asociados a la Orden de Cobro //$request_url = 'https://creator.zoho.com/api/json/'.$app_name_ZC.'/view/For_Sincronize_Times?scope=creatorapi&raw=true&authtoken='.$authtoken_ZC.'&criteria=(Prebills='.$bRecId.')'; $request_url = 'https://creator.zoho.com/api/v2/'.$appOwner.'/'.$app_name_ZC.'/report/For_Sincronize_Times?criteria=(Prebills='.$bRecId.')'; $context = [ 'recordId' => $bRecId, 'reportLinkName' => "For_Sincronize_Times" ]; //$bdDatTime = $array->TimeEntry; $bdDatTime = getZohoCreatorDataGeneric($request_url, $access_token, 5, 1, $context); if ($bdDatTime === null) { // Manejar el error adecuadamente $j_array = array('code' => "651", "message" => "ERROR - [wsPrebillZB_Seplaw_Ing01] No se puede obtener el registro de For_Sincronize_Times desde Zoho Creator. Verifique que el ID de la Orden de Cobro sea correcto o que la aplicación esté activa."); $Resultado = json_encode($j_array); echo $Resultado; return; } #== Conexión a Zoho Creator para obtener los registros de tiempos asociados a la Orden de Cobro ordenados por fecha //$request_url = 'https://creator.zoho.com/api/json/'.$app_name_ZC.'/view/Times_Order_for_Date?scope=creatorapi&raw=true&authtoken='.$authtoken_ZC.'&criteria=(Prebills='.$bRecId.')'; $request_url = 'https://creator.zoho.com/api/v2/'.$appOwner.'/'.$app_name_ZC.'/report/Times_Order_for_Date?criteria=(Prebills='.$bRecId.')'; $context = [ 'recordId' => $bRecId, 'reportLinkName' => "Times_Order_for_Date" ]; //$bdTimeOrdered = $array->TimeEntry; $bdTimeOrdered = getZohoCreatorDataGeneric($request_url, $access_token, 5, 1, $context); if ($bdTimeOrdered === null) { // Manejar el error adecuadamente $j_array = array('code' => "652", "message" => "ERROR - [wsPrebillZB_Seplaw_Esp001] No se puede obtener el registro de Times_Order_for_Date desde Zoho Creator. Verifique que el ID de la Orden de Cobro sea correcto o que la aplicación esté activa."); $Resultado = json_encode($j_array); echo $Resultado; return; } // SRL $prebill_prestserv = "Del "; $prebill_prestserv = ""; $TotRegsTie = count($bdTimeOrdered); if($TotRegsTie > 0){ for ($i = 0; $i < $TotRegsTie; $i++){ if($i == 0) { $prebill_prestserv = $prebill_prestserv . substr($bdTimeOrdered[$i]->WorkDate,0,2); } if($i == $TotRegsTie-1) { $sMes = substr($bdTimeOrdered[$i]->WorkDate,3,3); switch($sMes){ case "Jan": $prebill_prestserv = $prebill_prestserv . " to " . substr($bdTimeOrdered[$i]->WorkDate,0,2) . " " . "january, " . substr($bdTimeOrdered[$i]->WorkDate,7,4); break; case "Ene": $prebill_prestserv = $prebill_prestserv . " to " . substr($bdTimeOrdered[$i]->WorkDate,0,2) . " " . "january, " . substr($bdTimeOrdered[$i]->WorkDate,7,4); break; case "Feb": $prebill_prestserv = $prebill_prestserv . " to " . substr($bdTimeOrdered[$i]->WorkDate,0,2) . " " . "february, " . substr($bdTimeOrdered[$i]->WorkDate,7,4); break; case "Mar": $prebill_prestserv = $prebill_prestserv . " to " . substr($bdTimeOrdered[$i]->WorkDate,0,2) . " " . "march, " . substr($bdTimeOrdered[$i]->WorkDate,7,4); break; case "Apr": $prebill_prestserv = $prebill_prestserv . " to " . substr($bdTimeOrdered[$i]->WorkDate,0,2) . " " . "april, " . substr($bdTimeOrdered[$i]->WorkDate,7,4); break; case "Abr": $prebill_prestserv = $prebill_prestserv . " to " . substr($bdTimeOrdered[$i]->WorkDate,0,2) . " " . "april, " . substr($bdTimeOrdered[$i]->WorkDate,7,4); break; case "May": $prebill_prestserv = $prebill_prestserv . " to " . substr($bdTimeOrdered[$i]->WorkDate,0,2) . " " . "may, " . substr($bdTimeOrdered[$i]->WorkDate,7,4); break; case "Jun": $prebill_prestserv = $prebill_prestserv . " to " . substr($bdTimeOrdered[$i]->WorkDate,0,2) . " " . "june, " . substr($bdTimeOrdered[$i]->WorkDate,7,4); break; case "Jul": $prebill_prestserv = $prebill_prestserv . " to " . substr($bdTimeOrdered[$i]->WorkDate,0,2) . " " . "july, " . substr($bdTimeOrdered[$i]->WorkDate,7,4); break; case "Aug": $prebill_prestserv = $prebill_prestserv . " to " . substr($bdTimeOrdered[$i]->WorkDate,0,2) . " " . "august, " . substr($bdTimeOrdered[$i]->WorkDate,7,4); break; case "Ago": $prebill_prestserv = $prebill_prestserv . " to " . substr($bdTimeOrdered[$i]->WorkDate,0,2) . " " . "august, " . substr($bdTimeOrdered[$i]->WorkDate,7,4); break; case "Sep": $prebill_prestserv = $prebill_prestserv . " to " . substr($bdTimeOrdered[$i]->WorkDate,0,2) . " " . "september, " . substr($bdTimeOrdered[$i]->WorkDate,7,4); break; case "Oct": $prebill_prestserv = $prebill_prestserv . " to " . substr($bdTimeOrdered[$i]->WorkDate,0,2) . " " . "october, " . substr($bdTimeOrdered[$i]->WorkDate,7,4); break; case "Nov": $prebill_prestserv = $prebill_prestserv . " to " . substr($bdTimeOrdered[$i]->WorkDate,0,2) . " " . "november, " . substr($bdTimeOrdered[$i]->WorkDate,7,4); break; case "Dec": $prebill_prestserv = $prebill_prestserv . " to " . substr($bdTimeOrdered[$i]->WorkDate,0,2) . " " . "december, " . substr($bdTimeOrdered[$i]->WorkDate,7,4); break; case "Dic": $prebill_prestserv = $prebill_prestserv . " to " . substr($bdTimeOrdered[$i]->WorkDate,0,2) . " " . "december, " . substr($bdTimeOrdered[$i]->WorkDate,7,4); break; } } } } #== Conexión a Zoho Creator para obtener los registros de gastos asociados a la Orden de Cobro //$request_url = 'https://creator.zoho.com/api/json/'.$app_name_ZC.'/view/Disbursements_Query?scope=creatorapi&raw=true&authtoken='.$authtoken_ZC.'&criteria=(Prebills='.$bRecId.')'; $request_url = 'https://creator.zoho.com/api/v2/'.$appOwner.'/'.$app_name_ZC.'/report/Disbursements_Query?criteria=(Prebills='.$bRecId.')'; $context = [ 'recordId' => $bRecId, 'reportLinkName' => "Disbursements_Query" ]; //$bdDatDisb = $array->Disbursements; $bdDatDisb = getZohoCreatorDataGeneric($request_url, $access_token, 5, 1, $context); if ($bdDatDisb === null) { // Manejar el error adecuadamente $j_array = array('code' => "652", "message" => "ERROR - [wsPrebillZB_Seplaw_Esp001] No se puede obtener el registro de Disbursements_Query desde Zoho Creator. Verifique que el ID de la Orden de Cobro sea correcto o que la aplicación esté activa."); $Resultado = json_encode($j_array); echo $Resultado; return; } // 0) Define el orden de categorías $categoryOrder = [ 'SOC' => 1, // Socio 'ASOSR' => 2, // Asociados Senior 'ASOJR' => 3, // Asociados Jr 'PAR' => 4, // Pasantes 'ADMIN' => 5, // Administrativos ]; // 1) Ordena bdDatTime por categoría → identidad → fecha usort($bdDatTime, function($a, $b) use ($categoryOrder) { // peso de categoría $catA = $a->{'Timekeeper.Category'} ?? ''; $catB = $b->{'Timekeeper.Category'} ?? ''; $wA = $categoryOrder[$catA] ?? PHP_INT_MAX; $wB = $categoryOrder[$catB] ?? PHP_INT_MAX; if ($wA !== $wB) { return $wA <=> $wB; } // misma categoría → por Identity $idA = $a->{'Timekeeper.Identity'} ?? ''; $idB = $b->{'Timekeeper.Identity'} ?? ''; if ($idA !== $idB) { return strcmp($idA, $idB); } // misma identidad → por fecha ascendente (formato 'd-M-Y') $dA = DateTime::createFromFormat('d-M-Y', $a->WorkDate); $dB = DateTime::createFromFormat('d-M-Y', $b->WorkDate); if ($dA && $dB) { return $dA <=> $dB; } return strcmp($a->WorkDate, $b->WorkDate); }); // 2) Extrae el primer category de cada Identity (para el resumen) $identityToCategory = []; foreach ($bdDatTime as $entry) { $id = $entry->{'Timekeeper.Identity'} ?? ''; $cat = $entry->{'Timekeeper.Category'} ?? ''; if ($id !== '' && !isset($identityToCategory[$id])) { $identityToCategory[$id] = $cat; } } // 3) Ordena prebill_SummTks por ese mismo category → Clave (Identity) usort($prebill_SummTks, function($a, $b) use ($categoryOrder, $identityToCategory) { $idA = $a->Clave ?? ''; $idB = $b->Clave ?? ''; // peso de categoría según el mapa $wA = $categoryOrder[$identityToCategory[$idA] ?? ''] ?? PHP_INT_MAX; $wB = $categoryOrder[$identityToCategory[$idB] ?? ''] ?? PHP_INT_MAX; if ($wA !== $wB) { return $wA <=> $wB; } // misma categoría → por identidad return strcmp($idA, $idB); }); /* #== Conexión a Zoho Creator para obtener los registros de honorarios fijos asociados a la Orden de Cobro //$request_url = 'https://creator.zoho.com/api/json/'.$app_name_ZC.'/view/Fixed_Fees_Query?scope=creatorapi&raw=true&authtoken='.$authtoken_ZC.'&criteria=(Prebills='.$bRecId.')'; $request_url = 'https://creator.zoho.com/api/v2/'.$appOwner.'/'.$app_name_ZC.'/report/Fixed_Fees_Query?criteria=(Prebills='.$bRecId.')'; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $request_url); // curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); curl_setopt($ch, CURLOPT_HTTPHEADER, array('Authorization: Zoho-oauthtoken ' . $coa_access_token)); $r = curl_exec($ch); $array = json_decode($r); //$bdDatHonF = $array->Fixed_Fees; $bdDatHonF = $array->data; */ $SendaArchsGraf = "archs_graf/"; $SendaArchsCFDI = "archs_cfdi/"; $NomArchPDF = "OC_SEPLAW_".$prebill_number.".PDF"; $GLOBALS['footOne'] = "Av. Santa Fe 505, P. 3-303, Col. Cruz Manca, Cuajimalpa, Ciudad de México, C.P. 05349"; $GLOBALS['footTwo'] = "www.seplaw.com.mx"; $SendaArchsCFDI = "archs_cfdi/"; $SendaArchsGraf = "archs_graf/"; #============================================================================================================ #== 1. CREAMOS LA CLASE Y OBTENEMOS LOS DATOS BASICOS DEL REPORTE #============================================================================================================ class PDF extends FPDF { function SetDash($black=null, $white=null) { if($black!==null) $s=sprintf('[%.3F %.3F] 0 d',$black*$this->k,$white*$this->k); else $s='[] 0 d'; $this->_out($s); } function Header() { } function Footer() { if( $this->PageNo() == 1) { $this->SetTextColor(81,81,81); $this->SetFont('arial','',8.5); $this->SetXY(1.0,26.7); $this->MultiCell(19.0, 0.25, utf8_decode($GLOBALS['footOne']), 0, 'C', 0); $this->SetTextColor(81,81,81); $this->SetFont('arial','',8.5); $this->SetXY(1.0,$this->GetY()); $this->Cell(19, 0.25, utf8_decode($GLOBALS['footTwo']), 0, 1,'C', 0); } else { $this->SetTextColor(0,0,0); $this->SetFont('arial','',10); $this->SetXY(19.4,26.9); $this->Cell(1.5, 0.25, $this->PageNo().'/{nb}', 0, 1,'R', 0); } } } #============================================================================================================ #== 2. CONSTRUYENDO EL DOCUMENTOS CON LA LIBRERÍA FPDF #============================================================================================================ $pdf=new PDF('P','cm','Letter'); $pdf->AliasNbPages(); $pdf->AddPage(); $pdf->AddFont('IDAutomationHC39M','','IDAutomationHC39M.php'); $pdf->AddFont('verdana','','verdana.php'); $pdf->SetAutoPageBreak(true); $pdf->SetMargins(0, 0, 0); $pdf->SetLineWidth(0.02); $pdf->SetFillColor(0,0,0); #============================================================================================================ #== 2.1 ENCABEZADO DE LA FACTURA #============================================================================================================ $X = 0; $Y = 0; $pdf->image("archs_graf/Logo_Prebills_Main.png",$X+5.08, $Y+1 , 11.32, 4.55); $pdf->image("archs_graf/Firma_Seplaw.png",$X+7.15, $Y+16.0 , 7.25, 1.43); $pdf->SetTextColor(0,0,0); $pdf->SetFont('arial','',8); $pdf->SetXY($X+2,$Y+5.30); $pdf->Cell(3.5, 0.25, utf8_decode("FEES AND EXPENSES STATEMENT"), 0, 1,'L', 0); $pdf->SetTextColor(0,0,0); $pdf->SetFont('verdana','',10); $pdf->SetXY($X+15,$Y+6.0); $pdf->Cell(4.0, 0.25, utf8_decode($sFecha), 0, 1,'R', 0); $pdf->SetTextColor(0,0,0); $pdf->SetFont('verdana','',10); $pdf->SetXY($X+2,$Y+7.00); $pdf->Cell(2.5, 0.25, utf8_decode("Client:"), 0, 1,'L', 0); $pdf->SetTextColor(0,0,0); $pdf->SetFont('arial','B',11); $pdf->SetXY($X+4.0,$Y+7.00); $pdf->Cell(4.0, 0.25, utf8_decode($prebill_client), 0, 1,'L', 0); /* $pdf->SetTextColor(0,0,0); $pdf->SetFont('verdana','',10); $pdf->SetXY($X+4.00,$Y+7.5); //$pdf->MultiCell(14, 0.45, utf8_decode($prebill_domicilio), 0, 'J', 0); $pdf->Cell(14.0, 0.25, utf8_decode($prebill_domicilio), 0, 1,'L', 0); $pdf->SetXY($X+4.00,$Y+7.9); $pdf->Cell(14.0, 0.25, utf8_decode($prebill_colonia)." ".utf8_decode($prebill_ciudad), 0, 1,'L', 0); $pdf->SetXY($X+4.00,$Y+8.3); $pdf->Cell(14.0, 0.25, utf8_decode($prebill_codigo)." ".utf8_decode($prebill_estado), 0, 1,'L', 0); $pdf->SetXY($X+4.00,$Y+8.7); $pdf->Cell(14.0, 0.25, utf8_decode($prebill_pais), 0, 1,'L', 0); */ /* $pdf->SetTextColor(0,0,0); $pdf->SetFont('verdana','',10); $pdf->SetXY($X+4.00,$Y+7.5); $pdf->Cell(2.5, 0.25, utf8_decode("Boulevard Presidente Adolfo Ruiz Cortines No. 3433"), 0, 1,'L', 0); $pdf->SetTextColor(0,0,0); $pdf->SetFont('verdana','',10); $pdf->SetXY($X+4.00,$Y+8.0); $pdf->Cell(2.5, 0.25, utf8_decode("Col. San Jerónimo Lídice, alcaldía La Magdalena Contreras"), 0, 1,'L', 0); $pdf->SetTextColor(0,0,0); $pdf->SetFont('verdana','',10); $pdf->SetXY($X+4.00,$Y+8.5); $pdf->Cell(2.5, 0.25, utf8_decode("10200, Ciudad de México"), 0, 1,'L', 0); */ $pdf->SetTextColor(0,0,0); $pdf->SetFont('verdana','',10); $pdf->SetXY($X+2,$Y+8.00); $pdf->Cell(2.5, 0.25, utf8_decode("Att'n:"), 0, 1,'L', 0); $pdf->SetTextColor(0,0,0); $pdf->SetFont('arial','B',11); $pdf->SetXY($X+4.0,$Y+8.00); $pdf->Cell(4.0, 0.25, utf8_decode($$prebill_attention), 0, 1,'L', 0); $pdf->SetTextColor(0,0,0); $pdf->SetFont('verdana','',10); $pdf->SetXY($X+2,$Y+09.00); $pdf->Cell(2.5, 0.25, utf8_decode("Re.:"), 0, 1,'L', 0); $pdf->SetTextColor(0,0,0); $pdf->SetFont('arial','',11); $pdf->SetXY($X+4.0,$Y+09.00); $pdf->Cell(4.0, 0.25, "(".utf8_decode($prebill_matter).")", 0, 1,'L', 0); $pdf->SetTextColor(0,0,0); $pdf->SetFont('verdana','',10); $pdf->SetXY($X+2,$Y+11.00); $pdf->Cell(2.5, 0.25, utf8_decode("I. Fees for professional services described in enclosed exhibit"), 0, 1,'L', 0); $pdf->SetTextColor(0,0,0); $pdf->SetFont('verdana','',10); $pdf->SetXY($X+14,$Y+11.00); $pdf->Cell(1.0, 0.25, utf8_decode($prebill_currency), 0, 1,'L', 0); $pdf->SetTextColor(0,0,0); $pdf->SetFont('verdana','',10); $pdf->SetXY($X+15.0,$Y+11.00); $pdf->Cell(1.0, 0.25, utf8_decode("$"), 0, 1,'L', 0); $pdf->SetTextColor(0,0,0); $pdf->SetFont('verdana','',10); $pdf->SetXY($X+16.0,$Y+11.00); $pdf->Cell(3.0, 0.25, number_format($prebill_Fees,2), 0, 1,'R', 0); $pdf->SetTextColor(0,0,0); $pdf->SetFont('verdana','',10); $pdf->SetXY($X+2,$Y+11.50); $pdf->Cell(2.5, 0.25, utf8_decode("II. Expenses incurred in connection with professional services"), 0, 1,'L', 0); $pdf->SetTextColor(0,0,0); $pdf->SetFont('verdana','',10); $pdf->SetXY($X+14,$Y+11.50); $pdf->Cell(1.0, 0.25, utf8_decode($prebill_currency), 0, 1,'L', 0); $pdf->SetTextColor(0,0,0); $pdf->SetFont('verdana','',10); $pdf->SetXY($X+15.0,$Y+11.50); $pdf->Cell(1.0, 0.25, utf8_decode("$"), 0, 1,'L', 0); $pdf->SetTextColor(0,0,0); $pdf->SetFont('verdana','',10); $pdf->SetXY($X+16.0,$Y+11.50); $pdf->Cell(3.0, 0.25, number_format($prebill_Disbur,2), 0, 1,'R', 0); $pdf->SetDrawColor(0,0,0); $pdf->SetLineWidth(0.05); $pdf->line(16.0, 12.0, 19.0, 12.0); $pdf->SetTextColor(0,0,0); $pdf->SetFont('arial','',11); $pdf->SetXY($X+10,$Y+12.250); $pdf->Cell(3.0, 0.25, utf8_decode("Total Fees and Expenses Sum:"), 0, 1,'R', 0); $pdf->SetTextColor(0,0,0); $pdf->SetFont('arial','',11); $pdf->SetXY($X+14,$Y+12.250); $pdf->Cell(1.0, 0.25, utf8_decode($prebill_currency), 0, 1,'L', 0); $pdf->SetTextColor(0,0,0); $pdf->SetFont('arial','',11); $pdf->SetXY($X+15,$Y+12.250); $pdf->Cell(1.0, 0.25, utf8_decode("$"), 0, 1,'L', 0); $pdf->SetTextColor(0,0,0); $pdf->SetFont('arial','',11); $pdf->SetXY($X+16.0,$Y+12.250); $pdf->Cell(3.0, 0.25, number_format($prebill_SubTot,2), 0, 1,'R', 0); $pdf->SetTextColor(0,0,0); $pdf->SetFont('verdana','',10); $pdf->SetXY($X+10,$Y+13.0); $pdf->Cell(3.0, 0.25, utf8_decode("V.A.T. (".number_format($prebill_PorIva,0)." %)"), 0, 1,'R', 0); $pdf->SetTextColor(0,0,0); $pdf->SetFont('verdana','',10); $pdf->SetXY($X+14,$Y+13.0); $pdf->Cell(1.0, 0.25, utf8_decode($prebill_currency), 0, 1,'L', 0); $pdf->SetTextColor(0,0,0); $pdf->SetFont('verdana','',10); $pdf->SetXY($X+15,$Y+13.0); $pdf->Cell(1.0, 0.25, utf8_decode("$"), 0, 1,'L', 0); $pdf->SetTextColor(0,0,0); $pdf->SetFont('verdana','',10); $pdf->SetXY($X+16.0,$Y+13.0); $pdf->Cell(3.0, 0.25, number_format($prebill_ImpIva,2), 0, 1,'R', 0); $pdf->SetDrawColor(0,0,0); $pdf->SetLineWidth(0.05); $pdf->line(16.0, 13.5, 19.0, 13.5); $pdf->SetTextColor(0,0,0); $pdf->SetFont('arial','B',11); $pdf->SetXY($X+10,$Y+13.75); $pdf->Cell(3.0, 0.25, utf8_decode("Total:"), 0, 1,'R', 0); $pdf->SetTextColor(0,0,0); $pdf->SetFont('arial','B',11); $pdf->SetXY($X+14,$Y+13.75); $pdf->Cell(1.0, 0.25, utf8_decode($prebill_currency), 0, 1,'L', 0); $pdf->SetTextColor(0,0,0); $pdf->SetFont('arial','B',11); $pdf->SetXY($X+15,$Y+13.75); $pdf->Cell(1.0, 0.25, utf8_decode("$"), 0, 1,'L', 0); $pdf->SetTextColor(0,0,0); $pdf->SetFont('arial','B',11); $pdf->SetXY($X+16.0,$Y+13.75); $pdf->Cell(3.0, 0.25, number_format($prebill_Import,2), 0, 1,'R', 0); $pdf->SetTextColor(0,0,0); $pdf->SetFont('arial','B',11); $pdf->SetXY($X+2.0,$Y+15.0); //$pdf->MultiCell(17, 0.45, utf8_decode(convertirNumeroLetra($strTotal,$prebill_currency) ), 0, 'C', 0); $pdf->MultiCell(17, 0.45, utf8_decode(strtolower($sNumToLet)), 0, 'C', 0); $pdf->SetDrawColor(0,0,0); $pdf->SetLineWidth(0.03); $pdf->line(7.0, 17.5, 15.0, 17.5); $pdf->SetTextColor(0,0,0); $pdf->SetFont('verdana','',10); $pdf->SetXY($X+8,$Y+17.7); $pdf->Cell(1.0, 0.25, utf8_decode("SEPÚLVEDA Y DÍAZ NORIEGA, S.C."), 0, 1,'L', 0); $pdf->SetTextColor(0,0,0); $pdf->SetFont('arial','B',9); $pdf->SetXY($X+2,$Y+18.5); $pdf->Cell(1.0, 0.25, utf8_decode("Below is the information to make payment by wire transfer to our Mexican Bank account in US Dollars,"), 0, 1,'L', 0); $pdf->SetTextColor(0,0,0); $pdf->SetFont('arial','B',9); $pdf->SetXY($X+2,$Y+19.0); $pdf->Cell(1.0, 0.25, utf8_decode("through its correspondent US Bank:"), 0, 1,'L', 0); $pdf->SetDrawColor(0,0,0); $pdf->SetLineWidth(0.03); $pdf->line(2.0, 19.5, 19.0, 19.5); $pdf->SetTextColor(0,0,0); $pdf->SetFont('verdana','',10); $pdf->SetXY($X+2,$Y+20.50); $pdf->Cell(1.0, 0.25, utf8_decode("Correspondent US Bank:"), 0, 1,'L', 0); $pdf->SetTextColor(0,0,0); $pdf->SetFont('arial','B',11); $pdf->SetXY($X+7.5,$Y+20.50); $pdf->Cell(5.0, 0.25, utf8_decode("JP MORGAN CHASE BANK"), 0, 1,'L', 0); $pdf->SetTextColor(0,0,0); $pdf->SetFont('verdana','',10); $pdf->SetXY($X+2,$Y+21.00); $pdf->Cell(1.0, 0.25, utf8_decode("Mexican Bank:"), 0, 1,'L', 0); $pdf->SetTextColor(0,0,0); $pdf->SetFont('arial','B',11); $pdf->SetXY($X+7.5,$Y+21.00); $pdf->Cell(5.0, 0.25, utf8_decode("Banco Santander, (México) S.A."), 0, 1,'L', 0); $pdf->SetTextColor(0,0,0); $pdf->SetFont('verdana','',10); $pdf->SetXY($X+2,$Y+21.50); $pdf->Cell(1.0, 0.25, utf8_decode("Account holder/beneficiary:"), 0, 1,'L', 0); $pdf->SetTextColor(0,0,0); $pdf->SetFont('arial','B',11); $pdf->SetXY($X+7.5,$Y+21.50); $pdf->Cell(5.0, 0.25, utf8_decode("Sepúlveda y Díaz Noriega, S.C."), 0, 1,'L', 0); $pdf->SetTextColor(0,0,0); $pdf->SetFont('verdana','',10); $pdf->SetXY($X+2,$Y+22.00); $pdf->Cell(1.0, 0.25, utf8_decode("Swift Code:"), 0, 1,'L', 0); $pdf->SetTextColor(0,0,0); $pdf->SetFont('arial','B',11); $pdf->SetXY($X+7.5,$Y+22.00); $pdf->Cell(5.0, 0.25, utf8_decode("BMSXMXMMXXX"), 0, 1,'L', 0); $pdf->SetTextColor(0,0,0); $pdf->SetFont('verdana','',10); $pdf->SetXY($X+2,$Y+22.50); $pdf->Cell(1.0, 0.25, utf8_decode("Account No.:"), 0, 1,'L', 0); $pdf->SetTextColor(0,0,0); $pdf->SetFont('arial','B',11); $pdf->SetXY($X+7.5,$Y+22.50); $pdf->Cell(5.0, 0.25, utf8_decode("82-50065878-9"), 0, 1,'L', 0); $pdf->SetTextColor(0,0,0); $pdf->SetFont('verdana','',10); $pdf->SetXY($X+2,$Y+23.00); $pdf->Cell(1.0, 0.25, utf8_decode("Clabe number:"), 0, 1,'L', 0); $pdf->SetTextColor(0,0,0); $pdf->SetFont('arial','B',11); $pdf->SetXY($X+7.5,$Y+23.00); $pdf->Cell(5.0, 0.25, utf8_decode("014180825006587896"), 0, 1,'L', 0); $pdf->AddPage(); TitulosPag($pdf); $X = 0; $Y = 0; //SRL 2021/02/03 Modificar fuentes para poner negritas activar el asunto $pdf->SetTextColor(0,0,0); $pdf->SetFont('arial','B',10); $pdf->SetXY($X+2,$Y+6.00); $pdf->Cell(2.5, 0.25, utf8_decode("Services provided to:"), 0, 1,'L', 0); $pdf->SetTextColor(0,0,0); $pdf->SetFont('arial','B',11); $pdf->SetXY($X+6.0,$Y+6.00); $pdf->Cell(4.0, 0.25, utf8_decode($prebill_client), 0, 1,'L', 0); $pdf->SetTextColor(0,0,0); $pdf->SetFont('arial','B',11); $pdf->SetXY($X+6.0,$Y+6.50); $pdf->Cell(4.0, 0.25, "(".utf8_decode($prebill_matter).")", 0, 1,'L', 0); $pdf->SetTextColor(0,0,0); $pdf->SetFont('arial','B',10); $pdf->SetXY($X+2,$Y+7.25); $pdf->Cell(2.5, 0.25, utf8_decode("During: ".strtolower($prebill_prestserv)), 0, 1,'L', 0); $pdf->SetTextColor(0,0,0); $pdf->SetFont('arial','B',10); $pdf->SetXY($X+2,$Y+8.00); $pdf->Cell(2.5, 0.25, utf8_decode("Description of Services:"), 0, 1,'L', 0); //TitulosTie($pdf,8.0); $X = 0; $Y = 8.0; #============================================================================================================ #== 2.2 REGISTROS DE TIEMPOS #============================================================================================================ $Puntero = $pdf->GetY(); $TotRegsTie = count($bdDatTime); $TkAnt = ""; if($TotRegsTie > 0){ $Y = $pdf->GetY()+0.20; $Y = $Y+0.5; $Puntero = $Y; for ($i = 0; $i < $TotRegsTie; $i++){ if ($Puntero > 24.5) { $pdf->AddPage(); TitulosPag($pdf); //TitulosTie($pdf,5.0); $Y = 6.0; } $time_timekeeper = ""; foreach ( $bdDatTime[$i] as $nombre => $hexa ) { if($nombre == "Timekeeper.Identity") { $time_timekeeper = $hexa; } } if($TkAnt != $time_timekeeper) { if($TkAnt != "") { $pdf->SetDrawColor(0,0,0); $pdf->SetLineWidth(0.02); $pdf->SetDash(0.5,0.25); $pdf->line(2.0, $Y-0.1, 19.5, $Y-0.1); $Y = $Y+0.30; $pdf->SetDash(); } $TkAnt = $time_timekeeper; $pdf->SetTextColor(0,0,0); $pdf->SetFont('arial','B',12); $pdf->SetXY(2.0,$Y); $pdf->Cell(1.3, 0.25, utf8_decode($TkAnt), 0, 1,'L', 0); $Y = $Y+0.50; } //srl mm/dd/yy $sMesWork = substr($bdDatTime[$i]->WorkDate,3,3); switch($sMesWork){ case "Jan": $sDateWork = "01/".substr($bdDatTime[$i]->WorkDate,0,2)."/".substr($bdDatTime[$i]->WorkDate,9,2); break; case "Ene": $sDateWork = "01/".substr($bdDatTime[$i]->WorkDate,0,2)."/".substr($bdDatTime[$i]->WorkDate,9,2); break; case "Feb": $sDateWork = "02/".substr($bdDatTime[$i]->WorkDate,0,2)."/".substr($bdDatTime[$i]->WorkDate,9,2); break; case "Mar": $sDateWork = "03/".substr($bdDatTime[$i]->WorkDate,0,2)."/".substr($bdDatTime[$i]->WorkDate,9,2); break; case "Apr": $sDateWork = "04/".substr($bdDatTime[$i]->WorkDate,0,2)."/".substr($bdDatTime[$i]->WorkDate,9,2); break; case "Abr": $sDateWork = "04/".substr($bdDatTime[$i]->WorkDate,0,2)."/".substr($bdDatTime[$i]->WorkDate,9,2); break; case "May": $sDateWork = "05/".substr($bdDatTime[$i]->WorkDate,0,2)."/".substr($bdDatTime[$i]->WorkDate,9,2); break; case "Jun": $sDateWork = "06/".substr($bdDatTime[$i]->WorkDate,0,2)."/".substr($bdDatTime[$i]->WorkDate,9,2); break; case "Jul": $sDateWork = "07/".substr($bdDatTime[$i]->WorkDate,0,2)."/".substr($bdDatTime[$i]->WorkDate,9,2); break; case "Aug": $sDateWork = "08/".substr($bdDatTime[$i]->WorkDate,0,2)."/".substr($bdDatTime[$i]->WorkDate,9,2); break; case "Ago": $sDateWork = "08/".substr($bdDatTime[$i]->WorkDate,0,2)."/".substr($bdDatTime[$i]->WorkDate,9,2); break; case "Sep": $sDateWork = "09/".substr($bdDatTime[$i]->WorkDate,0,2)."/".substr($bdDatTime[$i]->WorkDate,9,2); break; case "Oct": $sDateWork = "10/".substr($bdDatTime[$i]->WorkDate,0,2)."/".substr($bdDatTime[$i]->WorkDate,9,2); break; case "Nov": $sDateWork = "11/".substr($bdDatTime[$i]->WorkDate,0,2)."/".substr($bdDatTime[$i]->WorkDate,9,2); break; case "Dec": $sDateWork = "12/".substr($bdDatTime[$i]->WorkDate,0,2)."/".substr($bdDatTime[$i]->WorkDate,9,2); break; case "Dic": $sDateWork = "12/".substr($bdDatTime[$i]->WorkDate,0,2)."/".substr($bdDatTime[$i]->WorkDate,9,2); break; } //SRL Poner en minusculas los meses // $sDateWork = strtolower(substr($bdDatTime[$i]->WorkDate,0,2)."/".substr($bdDatTime[$i]->WorkDate,3,3)."/".substr($bdDatTime[$i]->WorkDate,7,4)); $pdf->SetTextColor(0,0,0); $pdf->SetFont('arial','B',10); $pdf->SetXY(2.0,$Y); $pdf->Cell(3.5, 0.25, utf8_decode($sDateWork), 0, 1,'L', 0); $pdf->SetTextColor(0,0,0); $pdf->SetFont('arial','B',10); $pdf->SetXY(4.9,$Y); $pdf->Cell(1.3, 0.25, utf8_decode($time_timekeeper), 0, 1,'C', 0); $pdf->SetTextColor(0,0,0); $pdf->SetFont('arial','B',10); $pdf->SetXY(5.9,$Y); $pdf->Cell(2.0, 0.25, number_format($bdDatTime[$i]->dHours,2), 0, 1,'C', 0); $Y = $Y+0.40; $pdf->SetTextColor(0,0,0); $pdf->SetFont('verdana','',9); $pdf->SetXY(2.0,$Y); $pdf->MultiCell(17, 0.30, utf8_decode(trim($bdDatTime[$i]->Description)), 0, 'J', 0); $YY = $pdf->GetY()+0.50; $Puntero = $pdf->GetY(); $Y = $YY; } /* $pdf->SetDrawColor(0,0,0); $pdf->SetLineWidth(0.02); $pdf->line(2.0, $Y-0.1, 19.0, $Y-0.1); $pdf->SetFont('arial','B',10); $pdf->SetTextColor(0,0,0); $pdf->SetXY(2.0,$Y); $pdf->Cell(3.5, 0.25, "Total Trabajos", 0, 1,'L', 0); $pdf->SetXY(17.0,$Y); $pdf->Cell(2.0, 0.25, number_format($prebill_Factur,2), 0, 1,'C', 0); $Puntero = $pdf->GetY(); */ } if ($Puntero > 24.5) { $pdf->AddPage(); TitulosPag($pdf); $Y = 5.0; } $Y = $Y + 1.0; #============================================================================================================ #== 2.2 RESUMEN DE HONORARIOS #============================================================================================================ $pdf->SetFont('arial','B',12); $pdf->SetTextColor(0,0,0); $pdf->SetXY(2.0,$Y); $pdf->Cell(18, 0.25, "FEES SUMMARY", 0, 1,'C', 0); $X = $X; $Y = $Y+0.75; $Puntero = $Y; if ($Puntero>24.5) { $pdf->AddPage(); TitulosPag($pdf); $Y = 5.0; } $TotRegsTie = count($prebill_SummTks); if($TotRegsTie > 0){ $Regs = 0; $Y = $pdf->GetY()+0.20; $Y = $Y+0.5; $pdf->SetFont('arial','B',10); $pdf->SetTextColor(0,0,0); $pdf->SetXY(2.0,$Y); $pdf->Cell(6.35, 0.60, utf8_decode("SEPLAW Attorney"), 0, 1,'L', 0); $pdf->SetXY(10.5,$Y); $pdf->SetTextColor(0,0,0); $pdf->Cell(3.5, 0.60, utf8_decode("Hourly rate"), 0, 1,'L', 0); $pdf->SetFont('arial','B',10); $pdf->SetTextColor(0,0,0); $pdf->SetXY(13.80,$Y); $pdf->Cell(2.00, 0.60, utf8_decode("Hours worked"), 0, 1,'R', 0); $pdf->SetFont('arial','B',10); $pdf->SetTextColor(0,0,0); $pdf->SetXY(17.0,$Y); $pdf->Cell(2.50, 0.60, utf8_decode("Total Fees"), 0, 1,'R', 0); $Y = $Y+0.7; $pdf->SetDrawColor(0,0,0); $pdf->SetLineWidth(0.02); $pdf->line(2.0, $Y-0.2, 19.50, $Y-0.2); for ($i = 0; $i < $TotRegsTie; $i++){ $pdf->SetFont('arial','B',10); $pdf->SetTextColor(0,0,0); if($prebill_SummTks[$i]->TotImp > 0) { $pdf->SetXY(2.00,$Y); $pdf->Cell(6.25, 0.30, utf8_decode($prebill_SummTks[$i]->Name), 0, 1,'L', 0); $pdf->SetFont('arial','B',9); $pdf->SetXY(8.2,$Y); $pdf->Cell(3.5, 0.30, utf8_decode("[".$prebill_SummTks[$i]->Clave."]"), 0, 1,'L', 0); $pdf->SetFont('arial','B',9); $pdf->SetXY(10.00, $Y); $pdf->Cell(3.5, 0.30, utf8_decode($prebill_currency." $"), 0, 1,'L', 0); $pdf->SetFont('arial','B',10); $pdf->SetXY(10.70,$Y); $pdf->Cell(2.00, 0.30, number_format($prebill_SummTks[$i]->Rate,2), 0, 1,'R', 0); $pdf->SetFont('arial','B',10); $pdf->SetXY(13.8,$Y); $pdf->Cell(2.00, 0.30, number_format($prebill_SummTks[$i]->TotHrs,2), 0, 1,'R', 0); $pdf->SetFont('arial','B',9); $pdf->SetXY(16.20,$Y); $pdf->Cell(3.5, 0.30, utf8_decode($prebill_currency." $"), 0, 1,'L', 0); $pdf->SetFont('arial','B',10); $pdf->SetXY(17.0,$Y); $pdf->Cell(2.50, 0.30, number_format($prebill_SummTks[$i]->TotImp,2), 0, 1,'R', 0); //$pdf->SetDrawColor(140,133,169); //$pdf->line(1.0, $Y-0.1, 20.45, $Y-0.1); $YY = $pdf->GetY()+0.18; $Puntero = $pdf->GetY(); $Y = $YY; $Regs++; if ($Puntero>25.5) { $pdf->AddPage(); TitulosPag($pdf); $Y = 5.0; } } } $Y = $pdf->GetY()+0.50; $pdf->SetTextColor(0,0,0); $pdf->SetFont('arial','B',12); $pdf->SetXY(2.0,$Y); $pdf->Cell(10.0, 0.60, "Total Fees Sum: " . utf8_decode($prebill_currency) . " $ " . number_format($prebill_Fees,2), 0, 1,'L', 0); } if ($Puntero > 24.5) { $pdf->AddPage(); TitulosPag($pdf); $Y = 5.0; } $Y = $Y + 2.0; #============================================================================================================ #== 2.2 DETALLE DE GASTOS #============================================================================================================ if($TotRegsGas > 0) { $pdf->SetFont('arial','B',12); $pdf->SetTextColor(0,0,0); $pdf->SetXY(2.0,$Y); $pdf->Cell(18, 0.25, "EXPENSES", 0, 1,'C', 0); $X = $X; $Y = $Y+0.5; $Puntero = $Y; if ($Puntero>24.5) { $pdf->AddPage(); TitulosPag($pdf); $Y = 6.0; } } $TotRegsGas = count($bdDatDisb); if($TotRegsGas > 0){ $Regs = 0; $Y = $pdf->GetY()+0.20; $Y = $Y+0.5; $pdf->SetFont('arial','B',10); $pdf->SetTextColor(0,0,0); $pdf->SetXY(2.0,$Y); $pdf->Cell(2.00, 0.60, utf8_decode("Date"), 0, 1,'L', 0); $pdf->SetXY(5.0,$Y); $pdf->SetTextColor(0,0,0); $pdf->Cell(10.0, 0.60, utf8_decode("Description"), 0, 1,'L', 0); $pdf->SetTextColor(0,0,0); $pdf->SetXY(16.00,$Y); $pdf->Cell(3.00, 0.60, utf8_decode("Amount (".$prebill_currency.")"), 0, 1,'R', 0); $Y = $Y+0.7; $pdf->SetDrawColor(0,0,0); $pdf->SetLineWidth(0.02); $pdf->line(2.0, $Y-0.2, 19.50, $Y-0.2); for ($i = 0; $i < $TotRegsGas; $i++){ $sDateWork = strtolower(substr($bdDatDisb[$i]->WorkDate,0,2)."/".substr($bdDatDisb[$i]->WorkDate,3,3)."/".substr($bdDatDisb[$i]->WorkDate,9,2)); $pdf->SetFont('verdana','',10); $pdf->SetTextColor(0,0,0); $pdf->SetFont('verdana','',10); $pdf->SetXY(2.10,$Y); $pdf->Cell(2.0, 0.30, utf8_decode($sDateWork), 0, 1,'L', 0); $pdf->SetFont('verdana','',9); $pdf->SetXY(16.20,$Y); $pdf->Cell(1.5, 0.30, utf8_decode($prebill_currency), 0, 1,'L', 0); $pdf->SetFont('verdana','',10); $pdf->SetXY(17.0,$Y); $pdf->Cell(2.45, 0.30, number_format($bdDatDisb[$i]->Import,2), 0, 1,'R', 0); $pdf->SetFont('verdana','',10); $pdf->SetXY(5.0,$Y); $pdf->MultiCell(10.0, 0.30, utf8_decode(trim($bdDatDisb[$i]->Description)), 0, 'J', 0); $YY = $pdf->GetY()+0.20; $Puntero = $pdf->GetY(); $Y = $YY; $Regs++; if ($Puntero>24.5) { $pdf->AddPage(); TitulosPag($pdf); $Y = 6.0; } } $pdf->SetDrawColor(0,0,0); $pdf->SetLineWidth(0.02); $pdf->line(2.0, $Y, 19.50, $Y); $Y = $Y + 0.20; $pdf->SetFont('arial','B',10); $pdf->SetXY(16.20,$Y); $pdf->Cell(1.5, 0.30, utf8_decode($prebill_currency), 0, 1,'L', 0); $pdf->SetXY(17.0,$Y); $pdf->Cell(2.45, 0.30, number_format($prebill_Disbur,2), 0, 1,'R', 0); $Y = $Y + 1.0; } if ($Puntero>24.5) { $pdf->AddPage(); TitulosPag($pdf); $Y = 6.0; } /* //SRL 2021/02/12 No se despliega la sesion de resumen de gastos a solicitud del cliente #============================================================================================================ #== 2.2 RESUMEN DE GASTOS #============================================================================================================ $pdf->SetFont('arial','B',12); $pdf->SetTextColor(0,0,0); $pdf->SetXY(2.0,$Y); $pdf->Cell(18, 0.25, "EXPENSE SUMMARY", 0, 1,'C', 0); $X = $X; //SRL De 0.5 a 1.0 $Y = $Y+1.0; $Puntero = $Y; //SRL 2021/02/04 Agregar linea $pdf->SetDrawColor(0,0,0); $pdf->SetLineWidth(0.02); $pdf->line(2.0, $Y-0.2, 19.50, $Y-0.2); if ($Puntero>24.5) { $pdf->AddPage(); TitulosPag($pdf); $Y = 5.0; } $TotRegsTie = count($prebill_SummCha); if($TotRegsTie > 0){ $Regs = 0; $Y = $pdf->GetY()+0.20; $Y = $Y+0.5; for ($i = 0; $i < $TotRegsTie; $i++){ $pdf->SetFont('verdana','',10); $pdf->SetTextColor(0,0,0); $pdf->SetFont('verdana','',9); $pdf->SetXY(16.20,$Y); $pdf->Cell(1.5, 0.30, utf8_decode($prebill_currency), 0, 1,'L', 0); $pdf->SetFont('verdana','',10); $pdf->SetXY(17.00,$Y); $pdf->Cell(2.45, 0.30, number_format($prebill_SummCha[$i]->TotDis,2), 0, 1,'R', 0); $pdf->SetFont('verdana','',10); $pdf->SetXY(2.10,$Y); $pdf->MultiCell(14.0, 0.30, utf8_decode($prebill_SummCha[$i]->Name), 0, 'L', 0); $YY = $pdf->GetY()+0.18; $Puntero = $pdf->GetY(); $Y = $YY; $Regs++; if ($Puntero>25.5) { $pdf->AddPage(); TitulosPag($pdf); } } //SRL Agregar linea $Y = $Y+0.5; $pdf->SetDrawColor(0,0,0); $pdf->SetLineWidth(0.02); $pdf->line(2.0, $Y-0.2, 19.50, $Y-0.2); $Y = $pdf->GetY()+0.50; $pdf->SetTextColor(0,0,0); $pdf->SetFont('arial','B',12); $pdf->SetXY(2.0,$Y); $pdf->Cell(10.0, 0.60, "Total Expense Sum: " . utf8_decode($prebill_currency) . " $ " . number_format($prebill_Disbur,2), 0, 1,'L', 0); $Y = $Y + 1.0; } $Y = $Y + 1.0; $Puntero = $pdf->GetY(); // SRL De 23.5 a 24.5 if ($Puntero>24.5) { $pdf->AddPage(); TitulosPag($pdf); $Y = 5.0; } */ #============================================================================================================ #== 2.2 TOTALES GENERALES #============================================================================================================ /* $pdf->SetFont('arial','B',12); $pdf->SetTextColor(0,0,0); $pdf->SetXY(2.0,$Y); $pdf->Cell(18, 0.25, "Grand Total:", 0, 1,'L', 0); */ $Y = $Y + 1.0; $Puntero = $pdf->GetY(); if ($Puntero>24.5) { $pdf->AddPage(); TitulosPag($pdf); $Y = 6.0; } $pdf->SetFont('arial','B',12); $pdf->SetTextColor(0,0,0); $pdf->SetXY(2.0,$Y); $pdf->Cell(18, 0.25, "Grand Total: ", 0, 1,'L', 0); $Y = $Y + 1.0; $pdf->SetTextColor(0,0,0); $pdf->SetFont('verdana','',10); $pdf->SetXY(2.0,$Y); $pdf->Cell(5.5, 0.25, utf8_decode("I. Fees for professional services described in enclosed exhibit"), 0, 1,'L', 0); $pdf->SetTextColor(0,0,0); $pdf->SetFont('verdana','',10); $pdf->SetXY(14,$Y); $pdf->Cell(1.0, 0.25, utf8_decode($prebill_currency), 0, 1,'L', 0); $pdf->SetTextColor(0,0,0); $pdf->SetFont('verdana','',10); $pdf->SetXY(15.0,$Y); $pdf->Cell(1.0, 0.25, utf8_decode("$"), 0, 1,'L', 0); $pdf->SetTextColor(0,0,0); $pdf->SetFont('verdana','',10); $pdf->SetXY(16.0,$Y); $pdf->Cell(3.0, 0.25, number_format($prebill_Fees,2), 0, 1,'R', 0); $Y = $Y + 0.50; $Puntero = $pdf->GetY(); if ($Puntero>24.5) { $pdf->AddPage(); TitulosPag($pdf); $Y = 6.0; } $pdf->SetTextColor(0,0,0); $pdf->SetFont('verdana','',10); $pdf->SetXY(2,$Y); $pdf->Cell(2.5, 0.25, utf8_decode("II. Expenses incurred in connection with professional services"), 0, 1,'L', 0); $pdf->SetTextColor(0,0,0); $pdf->SetFont('verdana','',10); $pdf->SetXY(14,$Y); $pdf->Cell(1.0, 0.25, utf8_decode($prebill_currency), 0, 1,'L', 0); $pdf->SetTextColor(0,0,0); $pdf->SetFont('verdana','',10); $pdf->SetXY(15.0,$Y); $pdf->Cell(1.0, 0.25, utf8_decode("$"), 0, 1,'L', 0); $pdf->SetTextColor(0,0,0); $pdf->SetFont('verdana','',10); $pdf->SetXY(16.0,$Y); $pdf->Cell(3.0, 0.25, number_format($prebill_Disbur,2), 0, 1,'R', 0); $Y = $Y + 0.50; $Puntero = $pdf->GetY(); if ($Puntero>24.5) { $pdf->AddPage(); TitulosPag($pdf); $Y = 6.0; } $pdf->SetDrawColor(0,0,0); $pdf->SetLineWidth(0.05); $pdf->line(16.0, $Y, 19.0, $Y); $Y = $Y + 0.25; $Puntero = $pdf->GetY(); if ($Puntero>24.5) { $pdf->AddPage(); TitulosPag($pdf); $Y = 6.0; } $pdf->SetTextColor(0,0,0); $pdf->SetFont('arial','',11); $pdf->SetXY(10,$Y); $pdf->Cell(3.0, 0.25, utf8_decode("Total Fees and Expenses Sum:"), 0, 1,'R', 0); $pdf->SetTextColor(0,0,0); $pdf->SetFont('arial','',11); $pdf->SetXY(14,$Y); $pdf->Cell(1.0, 0.25, utf8_decode($prebill_currency), 0, 1,'L', 0); $pdf->SetTextColor(0,0,0); $pdf->SetFont('arial','',11); $pdf->SetXY(15,$Y); $pdf->Cell(1.0, 0.25, utf8_decode("$"), 0, 1,'L', 0); $pdf->SetTextColor(0,0,0); $pdf->SetFont('arial','',11); $pdf->SetXY(16.0,$Y); $pdf->Cell(3.0, 0.25, number_format($prebill_SubTot,2), 0, 1,'R', 0); $Y = $Y + 0.50; $Puntero = $pdf->GetY(); if ($Puntero>24.5) { $pdf->AddPage(); TitulosPag($pdf); $Y = 6.0; } $pdf->SetTextColor(0,0,0); $pdf->SetFont('verdana','',10); $pdf->SetXY(10,$Y); $pdf->Cell(3.0, 0.25, utf8_decode("V.A.T. (".number_format($prebill_PorIva,0)." %)"), 0, 1,'R', 0); $pdf->SetTextColor(0,0,0); $pdf->SetFont('verdana','',10); $pdf->SetXY(14,$Y); $pdf->Cell(1.0, 0.25, utf8_decode($prebill_currency), 0, 1,'L', 0); $pdf->SetTextColor(0,0,0); $pdf->SetFont('verdana','',10); $pdf->SetXY(15,$Y); $pdf->Cell(1.0, 0.25, utf8_decode("$"), 0, 1,'L', 0); $pdf->SetTextColor(0,0,0); $pdf->SetFont('verdana','',10); $pdf->SetXY(16.0,$Y); $pdf->Cell(3.0, 0.25, number_format($prebill_ImpIva,2), 0, 1,'R', 0); $Y = $Y + 0.50; $Puntero = $pdf->GetY(); if ($Puntero>24.5) { $pdf->AddPage(); TitulosPag($pdf); $Y = 6.0; } $pdf->SetDrawColor(0,0,0); $pdf->SetLineWidth(0.05); $pdf->line(16.0, $Y, 19.0, $Y); $Y = $Y + 0.25; $Puntero = $pdf->GetY(); if ($Puntero>24.5) { $pdf->AddPage(); TitulosPag($pdf); $Y = 6.0; } $pdf->SetTextColor(0,0,0); $pdf->SetFont('arial','B',11); $pdf->SetXY(10,$Y); $pdf->Cell(3.0, 0.25, utf8_decode("Total:"), 0, 1,'R', 0); $pdf->SetTextColor(0,0,0); $pdf->SetFont('arial','B',11); $pdf->SetXY(14,$Y); $pdf->Cell(1.0, 0.25, utf8_decode($prebill_currency), 0, 1,'L', 0); $pdf->SetTextColor(0,0,0); $pdf->SetFont('arial','B',11); $pdf->SetXY(15,$Y); $pdf->Cell(1.0, 0.25, utf8_decode("$"), 0, 1,'L', 0); $pdf->SetTextColor(0,0,0); $pdf->SetFont('arial','B',11); $pdf->SetXY(16.0,$Y); $pdf->Cell(3.0, 0.25, number_format($prebill_Import,2), 0, 1,'R', 0); $Y = $Y + 1.00; $Puntero = $pdf->GetY(); if ($Puntero>24.5) { $pdf->AddPage(); TitulosPag($pdf); $Y = 6.0; } $pdf->SetTextColor(0,0,0); $pdf->SetFont('arial','B',11); $pdf->SetXY(2.0,$Y); //$pdf->MultiCell(17, 0.45, utf8_decode(convertirNumeroLetra($strTotal,$prebill_currency) ), 0, 'C', 0); $pdf->MultiCell(17, 0.45, utf8_decode(strtolower($sNumToLet)), 0, 'C', 0); $Y = $pdf->GetY()+0.50; $pdf->SetFont('verdana','',10); $pdf->SetTextColor(0,0,0); $pdf->SetXY(2.0,$Y); $pdf->Cell(19, 0.25, "-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.", 0, 1,'C', 0); #============================================================================================================ #== 2.6 SE GRABA EL DOCUMENTO .PDF EN EL DISCO DURO #============================================================================================================ $pdf->Output($SendaArchsCFDI.$NomArchPDF, 'F'); #============================================================================================================ #== 2.7 DESCOMENTAR SI ESTÁ UTILIZANDO EL SISTEMA OPERATIVO LINUX. #============================================================================================================ chmod ($SendaArchsCFDI.$NomArchPDF,0777); #============================================================================================================ #== 2.8 SE MUESTRA EL DOCUMENTO .PDF EN EL NAVEGADOR. #============================================================================================================ // $pdf->Output($SendaArchsCFDI.$NomArchPDF, 'I'); #============================================================================================================ # 2.9 Envio del Archivos a Zoho Creator #============================================================================================================ if($organi_id_ZB == "" && $authtoken_ZB == "" && $invoiceID == "") { $file_name_with_full_path = '/var/www/html/aptusCFDIRF/archs_cfdi/'.$NomArchPDF; //$request_url = 'https://creator.zoho.com/api/xml/fileupload/scope=creatorapi'; $request_url = 'https://creator.zoho.com/api/v2/'.$appOwner.'/'.$app_name_ZC.'/report/Prebills_Report/' . $bRecId . '/File_PDF_OC/upload'; if (function_exists('curl_file_create')) { // php 5.6+ $cFile = curl_file_create($file_name_with_full_path); } else { $cFile = '@' . realpath($file_name_with_full_path); } $post = array( // 'authtoken' => $authtoken_ZC, // 'applinkname' => $app_name_ZC, // 'formname' => 'Prebills', // 'fieldname' => 'File_PDF_OC', // 'recordId' => $bRecId, // 'filename' => $NomArchPDF, 'file'=> $cFile); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $request_url); // curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $post); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); curl_setopt($ch, CURLOPT_HTTPHEADER, array('Authorization: Zoho-oauthtoken ' . $coa_access_token)); $r = curl_exec($ch); curl_close ($ch); } #============================================================================================================ # 2.10 Envio del Archivos a Zoho Books #============================================================================================================ if($organi_id_ZB <> "" && $authtoken_ZB <> "" && $invoiceID <> "") { # Obtenemos el access token de Zoho Books $bRefreshToken = $aDatPac["B_OAuth_refresh_token"]; $bClientId = $aDatPac["B_OAuth_client_id"]; $bClientSecret = $aDatPac["B_OAuth_client_secret"]; $bRedirectUri = $aDatPac["B_OAuth_redirect_uri"]; $bGrantType = $aDatPac["B_OAuth_grant_type"]; $bAuthUrl = "https://accounts.zoho.com/oauth/v2/token"; // $bParams = array( // "refresh_token" => $bRefreshToken, // "client_id" => $bClientId, // "client_secret" => $bClientSecret, // "redirect_uri" => $bRedirectUri, // "grant_type" => $bGrantType // ); // $curl = curl_init(); // curl_setopt($curl, CURLOPT_URL, $bAuthUrl); // curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'POST'); // curl_setopt($curl, CURLOPT_POSTFIELDS, $bParams); // curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); // curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true); // $response = curl_exec($curl); // $array = json_decode($response); // $boa_access_token = $array->access_token; $boa_access_token = oauth('Seplaw', 'ZBooks', $bRefreshToken, $bClientId, $bClientSecret, $bRedirectUri, $bGrantType, $bAuthUrl); // $boa_access_token = oauth($appOwner, 'ZBooks', $bRefreshToken, $bClientId, $bClientSecret, $bRedirectUri, $bGrantType, $bAuthUrl); $file_name_with_full_path = '/var/www/html/aptusCFDIRF/archs_cfdi/'.$NomArchPDF; $request_url = 'https://www.zohoapis.com/books/v3/invoices/'.$invoiceID.'/attachment'; if (function_exists('curl_file_create')) { // php 5.6+ $cFile = curl_file_create($file_name_with_full_path); } else { $cFile = '@' . realpath($file_name_with_full_path); } $post = array( // 'authtoken' => $authtoken_ZB, 'organization_id' => $organi_id_ZB, // 'can_send_in_mail' => 'true', 'attachment'=> $cFile); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $request_url); // curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $post); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); curl_setopt($ch, CURLOPT_HTTPHEADER, array('Authorization: Zoho-oauthtoken ' . $boa_access_token)); $r = curl_exec($ch); # Usamos la funcion curl_errno() para atrapar cualquier error relacionado con la llamada. if (curl_errno($ch)) { $error_msg = curl_error($ch); } curl_close ($ch); if (isset($error_msg)) { $j_array = array('code' => '666', 'message' => "Error en la llamada curl " . $error_msg); $Resultado = json_encode($j_array); echo $Resultado; return; } else { $ra = json_decode($r); $resultPDF = $ra->code.' - '.$ra->message; $code = (int)$ra->code; if ($code != 0) { $j_array = array('code' => $ra->code, 'message' => "No se pudo adjuntar el archivo a Books, contacte al administrador " . $ra->message); $Resultado = json_encode($j_array); echo $Resultado; return; } } } $j_array = array('code' => "200", 'message' => "Proceso de creacion de Orden de Cobro fue exitoso"); $Resultado = json_encode($j_array); echo $Resultado; return; #============================================================================================================ #== FUNCIONES GENERALES #============================================================================================================ function TitulosPag($pdf){ $pdf->image("archs_graf/Logo_Prebills_Second.png",9.0, 1 , 11.32, 4.55); $pdf->SetTextColor(0,0,0); $pdf->SetFont('arial','',8); $pdf->SetXY(2,5.30); $pdf->Cell(3.5, 0.25, utf8_decode("DESCRIPTION OF SERVICES"), 0, 1,'L', 0); $pdf->SetDrawColor(0,0,0); $pdf->SetLineWidth(0.03); $pdf->line(2.0, 5.6, 19.0, 5.6); } function TitulosTie($pdf, $Y){ $pdf->SetTextColor(0,0,0); $pdf->SetFont('arial','B',9); $pdf->SetXY(17.5,$Y+1.00); $pdf->Cell(3.5, 0.25, utf8_decode("Horas"), 0, 1,'L', 0); $pdf->SetTextColor(0,0,0); $pdf->SetFont('arial','B',9); $pdf->SetXY(2.0,$Y+1.50); $pdf->Cell(3.5, 0.25, utf8_decode("Fecha"), 0, 1,'L', 0); $pdf->SetTextColor(0,0,0); $pdf->SetFont('arial','B',9); $pdf->SetXY(3.5,$Y+1.50); $pdf->Cell(3.5, 0.25, utf8_decode("Profesional"), 0, 1,'L', 0); $pdf->SetTextColor(0,0,0); $pdf->SetFont('arial','B',9); $pdf->SetXY(10.0,$Y+1.50); $pdf->Cell(3.5, 0.25, utf8_decode("Descripción"), 0, 1,'L', 0); $pdf->SetTextColor(0,0,0); $pdf->SetFont('arial','B',9); $pdf->SetXY(17.0,$Y+1.50); $pdf->Cell(3.5, 0.25, utf8_decode("Trabajadas"), 0, 1,'L', 0); $pdf->SetDrawColor(0,0,0); $pdf->SetLineWidth(0.02); $pdf->line(2.0, $Y+1.80, 19.0, $Y+1.80); } function TitulosGas($pdf, $Y ){ $Y = $Y + 0.24; $pdf->SetFont('arial','',10); $pdf->SetXY(1.0,$Y); $pdf->SetFillColor(60,61,58); $pdf->Cell(12.5, 0.60, "", 0, 1,'L', 1); $pdf->SetTextColor(255,255,255); $pdf->SetXY(1.25,$Y); $pdf->Cell(12.5, 0.60, utf8_decode($lblAboFec), 0, 1,'L', 1); $pdf->SetFont('arial','',10); $pdf->SetXY(13.5,$Y); $pdf->SetFillColor(60,61,58); $pdf->SetTextColor(255,255,255); $pdf->Cell(2.00, 0.60, $lblCantid, 0, 1,'R', 1); $pdf->SetFont('arial','',10); $pdf->SetXY(15.5,$Y); $pdf->SetFillColor(60,61,58); $pdf->SetTextColor(255,255,255); $pdf->Cell(2.50, 0.60, $lblTarifa, 0, 1,'R', 1); $pdf->SetFont('arial','',10); $pdf->SetXY(18.0,$Y); $pdf->SetFillColor(60,61,58); $pdf->SetTextColor(255,255,255); $pdf->Cell(2.45, 0.60, $lblImport, 0, 1,'R', 1); } /** * Obtiene datos de Zoho Creator (o cualquier endpoint) con reintentos y manejo de errores típico. * * @param string $request_url URL completa a consultar. * @param string $access_token Token OAuth válido. * @param int $maxRetries Número máximo de intentos. * @param int $initialDelay Retardo inicial en segundos para backoff exponencial. * @param array $context Datos opcionales para mensajes de error (['recordId'=>..., 'reportLinkName'=>...]). * * @return mixed Devuelve $data->data en éxito o un json_encode([...]) con 'code' y 'message' en error. */ function getZohoCreatorDataGeneric($request_url, $access_token, $maxRetries = 3, $initialDelay = 1, array $context = []) { $headers = [ "Authorization: Zoho-oauthtoken $access_token", "Accept: application/json" ]; $retryCount = 0; $waitSeconds = $initialDelay; while ($retryCount < $maxRetries) { $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, $headers); $response = curl_exec($ch); $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); $curlError = curl_error($ch); curl_close($ch); // Error de cURL (timeout, DNS, etc.) if ($response === false) { error_log("CURL Error: $curlError"); $retryCount++; sleep($waitSeconds); $waitSeconds *= 2; continue; } $data = json_decode($response); // JSON inválido if (json_last_error() !== JSON_ERROR_NONE) { error_log("JSON decode error: " . json_last_error_msg()); $retryCount++; sleep($waitSeconds); $waitSeconds *= 2; continue; } // ÉXITO: HTTP 200 y existe data if (($httpCode === 200 || $httpCode === 3000) && isset($data->data)) { return $data->data; } // Capturamos código y mensaje que manda Zoho (o el API en general) $errorCode = $data->code ?? 'N/A'; $errorMsg = $data->message ?? 'Respuesta inválida'; // Token expirado / inválido if ($httpCode === 401 || $errorCode === 1030 || $errorCode === 'INVALID_OAUTHTOKEN') { return json_encode([ 'code' => '401', 'message' => 'ERROR - Token de acceso expirado o inválido' ]); } // Registro no encontrado if ($errorCode === 3190) { $recId = $context['recordId'] ?? 'N/A'; $report = $context['reportLinkName'] ?? 'N/A'; return json_encode([ 'code' => '404', 'message' => "ERROR - No se encontró el registro con ID $recId en el reporte $report" ]); } // Rate limit / Too many requests if ($httpCode === 429 || $errorCode === 2955) { sleep($waitSeconds); $waitSeconds *= 2; $retryCount++; continue; } // Respuesta sin data, pero no es error de token: reintentar if (!isset($data->data)) { $retryCount++; sleep($waitSeconds); $waitSeconds *= 2; continue; } // Error desconocido: cortar return json_encode([ 'code' => '500', 'message' => "ERROR - Fallo inesperado. HTTP $httpCode - Código $errorCode - $errorMsg" ]); } // Agotamos reintentos return json_encode([ 'code' => '408', 'message' => "ERROR - Tiempo de espera agotado tras $maxRetries intentos" ]); } function normClave($s){ return mb_strtoupper(trim((string)$s), 'UTF-8'); }