ken_ZC = $_REQUEST['pAuthToken']; } if (isset($_REQUEST['pOrgaID'])) { $organi_id_ZB = $_REQUEST['pOrgaID']; } if (isset($_REQUEST['pAuthTokenZB'])) { $authtoken_ZB = $_REQUEST['pAuthTokenZB']; } if (isset($_REQUEST['pInvoiceID'])) { $invoiceID = $_REQUEST['pInvoiceID']; } if (isset($_REQUEST['pLang'])) { $language = $_REQUEST['pLang']; } if (isset($_REQUEST['pCiaName'])) { $ciaName = $_REQUEST['pCiaName']; } if (isset($_REQUEST['pCiaAddr1'])) { $ciaAddr1 = $_REQUEST['pCiaAddr1']; } if (isset($_REQUEST['pCiaAddr2'])) { $ciaAddr2 = $_REQUEST['pCiaAddr2']; } if (isset($_REQUEST['pCiaAddr3'])) { $ciaAddr3 = $_REQUEST['pCiaAddr3']; } if (isset($_REQUEST['pDatPac'])) { $bDatPac = $_REQUEST['pDatPac']; } if (isset($_REQUEST['pAppOwner'])) { $appOwner = $_REQUEST['pAppOwner']; // Parametros para el propietario de la aplicación } if($bRecId == "") { $j_array = array('code' => "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."]"); $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 = substr($prebill_date,0,2)." de "; $sMes = substr($prebill_date,3,3); switch($sMes){ case "Jan": $sFecha = $sFecha . "Enero de "; break; case "Ene": $sFecha = $sFecha . "Enero de "; break; case "Feb": $sFecha = $sFecha . "Febrero de "; break; case "Mar": $sFecha = $sFecha . "Marzo de "; break; case "Apr": $sFecha = $sFecha . "Abril de "; break; case "Abr": $sFecha = $sFecha . "Abril de "; break; case "May": $sFecha = $sFecha . "Mayo de "; break; case "Jun": $sFecha = $sFecha . "Junio de "; break; case "Jul": $sFecha = $sFecha . "Julio de "; break; case "Aug": $sFecha = $sFecha . "Agosto de "; break; case "Ago": $sFecha = $sFecha . "Agosto de "; break; case "Sep": $sFecha = $sFecha . "Septiembre de "; break; case "Oct": $sFecha = $sFecha . "Octubre de "; break; case "Nov": $sFecha = $sFecha . "Noviembre de "; break; case "Dec": $sFecha = $sFecha . "Diciembre de "; break; case "Dic": $sFecha = $sFecha . "Diciembre de "; break; } $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; } $prebill_prestserv = "Del "; $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 . " al " . substr($bdTimeOrdered[$i]->WorkDate,0,2) . " de " . "Enero de " . substr($bdTimeOrdered[$i]->WorkDate,7,4); break; case "Ene": $prebill_prestserv = $prebill_prestserv . " al " . substr($bdTimeOrdered[$i]->WorkDate,0,2) . " de " . "Enero de " . substr($bdTimeOrdered[$i]->WorkDate,7,4); break; case "Feb": $prebill_prestserv = $prebill_prestserv . " al " . substr($bdTimeOrdered[$i]->WorkDate,0,2) . " de " . "Febrero de " . substr($bdTimeOrdered[$i]->WorkDate,7,4); break; case "Mar": $prebill_prestserv = $prebill_prestserv . " al " . substr($bdTimeOrdered[$i]->WorkDate,0,2) . " de " . "Marzo de " . substr($bdTimeOrdered[$i]->WorkDate,7,4); break; case "Apr": $prebill_prestserv = $prebill_prestserv . " al " . substr($bdTimeOrdered[$i]->WorkDate,0,2) . " de " . "Abril de " . substr($bdTimeOrdered[$i]->WorkDate,7,4); break; case "Abr": $prebill_prestserv = $prebill_prestserv . " al " . substr($bdTimeOrdered[$i]->WorkDate,0,2) . " de " . "Abril de " . substr($bdTimeOrdered[$i]->WorkDate,7,4); break; case "May": $prebill_prestserv = $prebill_prestserv . " al " . substr($bdTimeOrdered[$i]->WorkDate,0,2) . " de " . "Mayo de " . substr($bdTimeOrdered[$i]->WorkDate,7,4); break; case "Jun": $prebill_prestserv = $prebill_prestserv . " al " . substr($bdTimeOrdered[$i]->WorkDate,0,2) . " de " . "Junio de " . substr($bdTimeOrdered[$i]->WorkDate,7,4); break; case "Jul": $prebill_prestserv = $prebill_prestserv . " al " . substr($bdTimeOrdered[$i]->WorkDate,0,2) . " de " . "Julio de " . substr($bdTimeOrdered[$i]->WorkDate,7,4); break; case "Aug": $prebill_prestserv = $prebill_prestserv . " al " . substr($bdTimeOrdered[$i]->WorkDate,0,2) . " de " . "Agosto de " . substr($bdTimeOrdered[$i]->WorkDate,7,4); break; case "Ago": $prebill_prestserv = $prebill_prestserv . " al " . substr($bdTimeOrdered[$i]->WorkDate,0,2) . " de " . "Agosto de " . substr($bdTimeOrdered[$i]->WorkDate,7,4); break; case "Sep": $prebill_prestserv = $prebill_prestserv . " al " . substr($bdTimeOrdered[$i]->WorkDate,0,2) . " de " . "Septiembre de " . substr($bdTimeOrdered[$i]->WorkDate,7,4); break; case "Oct": $prebill_prestserv = $prebill_prestserv . " al " . substr($bdTimeOrdered[$i]->WorkDate,0,2) . " de " . "Octubre de " . substr($bdTimeOrdered[$i]->WorkDate,7,4); break; case "Nov": $prebill_prestserv = $prebill_prestserv . " al " . substr($bdTimeOrdered[$i]->WorkDate,0,2) . " de " . "Noviembre de " . substr($bdTimeOrdered[$i]->WorkDate,7,4); break; case "Dec": $prebill_prestserv = $prebill_prestserv . " al " . substr($bdTimeOrdered[$i]->WorkDate,0,2) . " de " . "Diciembre de " . substr($bdTimeOrdered[$i]->WorkDate,7,4); break; case "Dic": $prebill_prestserv = $prebill_prestserv . " al " . substr($bdTimeOrdered[$i]->WorkDate,0,2) . " de " . "Diciembre de " . 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; } //Ordena los registros de tiempo por Timekeeper // === Normalizar claves === foreach ($prebill_SummTks as $o) { $o->_claveNorm = normClave($o->Clave ?? ''); } foreach ($bdDatTime as $o) { // El campo viene como "Timekeeper.Identity" $o->_claveNorm = normClave($o->{"Timekeeper.Identity"} ?? ''); } // === Armar un orden maestro por clave === $claves = array_unique(array_merge( array_map(fn($o) => $o->_claveNorm, $prebill_SummTks), array_map(fn($o) => $o->_claveNorm, $bdDatTime) )); sort($claves, SORT_NATURAL | SORT_FLAG_CASE); $rank = array_flip($claves); // 'ABC' => 0, 'DEF' => 1, ... // 3) Ordenar con el mismo ranking usort($prebill_SummTks, function($a,$b) use($rank){ return $rank[$a->_claveNorm] <=> $rank[$b->_claveNorm]; }); usort($bdDatTime, function($a,$b) use($rank){ $byClave = $rank[$a->_claveNorm] <=> $rank[$b->_claveNorm]; if ($byClave !== 0) return $byClave; return strcmp($a->WorkDate, $b->WorkDate); // opcional }); /* #== 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".$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/"; $NomArchPDF = "OC_SEPLAW.PDF";; #============================================================================================================ #== 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("CUENTA DE HONORARIOS Y/O GASTOS"), 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("Ciudad de México, a ".$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("Cliente:"), 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+10.00); $pdf->Cell(2.5, 0.25, utf8_decode("At'n:"), 0, 1,'L', 0); $pdf->SetTextColor(0,0,0); $pdf->SetFont('arial','B',11); $pdf->SetXY($X+4.0,$Y+10.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+11.00); $pdf->Cell(2.5, 0.25, utf8_decode("I. Honorarios por servicios profesionales según descripción anexa"), 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. Gastos incurridos en relación con los servicios profesionales"), 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','B',11); $pdf->SetXY($X+10,$Y+12.250); $pdf->Cell(3.0, 0.25, utf8_decode("Subtotal:"), 0, 1,'R', 0); $pdf->SetTextColor(0,0,0); $pdf->SetFont('arial','B',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','B',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','B',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("I.V.A. (".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(strtolower(convertirNumeroLetra($strTotal,$prebill_currency) )), 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); // SRL 2021/02/04 Modificar la fuente para ponerla en negritas $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("A continuación, encontrará la información correspondiente para el depósito en nuestra cuenta bancaria:"), 0, 1,'L', 0); $pdf->SetDrawColor(0,0,0); $pdf->SetLineWidth(0.03); $pdf->line(2.0, 19.5, 19.0, 19.5); if ($prebill_currency == "USD") { $pdf->SetTextColor(0,0,0); $pdf->SetFont('verdana','',10); $pdf->SetXY($X+2,$Y+20.50); $pdf->Cell(1.0, 0.25, utf8_decode("Banco Corresponsal:"), 0, 1,'L', 0); $pdf->SetTextColor(0,0,0); $pdf->SetFont('arial','B',11); $pdf->SetXY($X+6.0,$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("Banco en México:"), 0, 1,'L', 0); $pdf->SetTextColor(0,0,0); $pdf->SetFont('arial','B',11); $pdf->SetXY($X+6.0,$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("Beneficiario:"), 0, 1,'L', 0); $pdf->SetTextColor(0,0,0); $pdf->SetFont('arial','B',11); $pdf->SetXY($X+6.0,$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:"), 0, 1,'L', 0); $pdf->SetTextColor(0,0,0); $pdf->SetFont('arial','B',11); $pdf->SetXY($X+6.0,$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("No. de Cuenta:"), 0, 1,'L', 0); $pdf->SetTextColor(0,0,0); $pdf->SetFont('arial','B',11); $pdf->SetXY($X+6.0,$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 Interbancaria:"), 0, 1,'L', 0); $pdf->SetTextColor(0,0,0); $pdf->SetFont('arial','B',11); $pdf->SetXY($X+6.0,$Y+23.00); $pdf->Cell(5.0, 0.25, utf8_decode("014180825006587896"), 0, 1,'L', 0); } if ($prebill_currency == "MXN") { $pdf->SetTextColor(0,0,0); $pdf->SetFont('verdana','',10); $pdf->SetXY($X+2,$Y+20.50); $pdf->Cell(1.0, 0.25, utf8_decode("Banco :"), 0, 1,'L', 0); $pdf->SetTextColor(0,0,0); $pdf->SetFont('arial','B',11); $pdf->SetXY($X+6.0,$Y+20.50); $pdf->Cell(5.0, 0.25, utf8_decode("Banco Santander, S.A."), 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("Beneficiario:"), 0, 1,'L', 0); $pdf->SetTextColor(0,0,0); $pdf->SetFont('arial','B',11); $pdf->SetXY($X+6.0,$Y+21.00); $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+21.50); $pdf->Cell(1.0, 0.25, utf8_decode("Sucursal:"), 0, 1,'L', 0); $pdf->SetTextColor(0,0,0); $pdf->SetFont('arial','B',11); $pdf->SetXY($X+6.0,$Y+21.50); $pdf->Cell(5.0, 0.25, utf8_decode("0398(Diamante Santa Fe)"), 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("No. de Cuenta:"), 0, 1,'L', 0); $pdf->SetTextColor(0,0,0); $pdf->SetFont('arial','B',11); $pdf->SetXY($X+6.0,$Y+22.00); $pdf->Cell(5.0, 0.25, utf8_decode("65-50452846-8"), 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("Clabe:"), 0, 1,'L', 0); $pdf->SetTextColor(0,0,0); $pdf->SetFont('arial','B',11); $pdf->SetXY($X+6.0,$Y+22.50); $pdf->Cell(5.0, 0.25, utf8_decode("014180655045284689"), 0, 1,'L', 0); } $pdf->AddPage(); TitulosPag($pdf); $X = 0; $Y = 0; $pdf->SetTextColor(0,0,0); $pdf->SetFont('arial','B',10); $pdf->SetXY($X+2,$Y+6.50); $pdf->Cell(2.5, 0.25, utf8_decode("Prestados a:"), 0, 1,'L', 0); $pdf->SetTextColor(0,0,0); $pdf->SetFont('arial','B',11); $pdf->SetXY($X+4.5,$Y+6.50); $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+4.5,$Y+7.00); $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.75); //SRL $pdf->Cell(2.5, 0.25, utf8_decode("Periodo de la Prestación de Servicios: ".strtolower($prebill_prestserv)), 0, 1,'L', 0); $pdf->SetTextColor(0,0,0); $pdf->SetFont('arial','B',10); $pdf->SetXY($X+2,$Y+8.50); $pdf->Cell(2.5, 0.25, utf8_decode("Descripción de los Servicios:"), 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 $sMesWork = substr($bdDatTime[$i]->WorkDate,3,3); switch($sMesWork){ case "Jan": $sDateWork = substr($bdDatTime[$i]->WorkDate,0,2)."/01/".substr($bdDatTime[$i]->WorkDate,9,2); break; case "Ene": $sDateWork = substr($bdDatTime[$i]->WorkDate,0,2)."/01/".substr($bdDatTime[$i]->WorkDate,9,2); break; case "Feb": $sDateWork = substr($bdDatTime[$i]->WorkDate,0,2)."/02/".substr($bdDatTime[$i]->WorkDate,9,2); break; case "Mar": $sDateWork = substr($bdDatTime[$i]->WorkDate,0,2)."/03/".substr($bdDatTime[$i]->WorkDate,9,2); break; case "Apr": $sDateWork = substr($bdDatTime[$i]->WorkDate,0,2)."/04/".substr($bdDatTime[$i]->WorkDate,9,2); break; case "Abr": $sDateWork = substr($bdDatTime[$i]->WorkDate,0,2)."/04/".substr($bdDatTime[$i]->WorkDate,9,2); break; case "May": $sDateWork = substr($bdDatTime[$i]->WorkDate,0,2)."/05/".substr($bdDatTime[$i]->WorkDate,9,2); break; case "Jun": $sDateWork = substr($bdDatTime[$i]->WorkDate,0,2)."/06/".substr($bdDatTime[$i]->WorkDate,9,2); break; case "Jul": $sDateWork = substr($bdDatTime[$i]->WorkDate,0,2)."/07/".substr($bdDatTime[$i]->WorkDate,9,2); break; case "Aug": $sDateWork = substr($bdDatTime[$i]->WorkDate,0,2)."/08/".substr($bdDatTime[$i]->WorkDate,9,2); break; case "Ago": $sDateWork = substr($bdDatTime[$i]->WorkDate,0,2)."/08/".substr($bdDatTime[$i]->WorkDate,9,2); break; case "Sep": $sDateWork = substr($bdDatTime[$i]->WorkDate,0,2)."/09/".substr($bdDatTime[$i]->WorkDate,9,2); break; case "Oct": $sDateWork = substr($bdDatTime[$i]->WorkDate,0,2)."/10/".substr($bdDatTime[$i]->WorkDate,9,2); break; case "Nov": $sDateWork = substr($bdDatTime[$i]->WorkDate,0,2)."/11/".substr($bdDatTime[$i]->WorkDate,9,2); break; case "Dec": $sDateWork = substr($bdDatTime[$i]->WorkDate,0,2)."/12/".substr($bdDatTime[$i]->WorkDate,9,2); break; case "Dic": $sDateWork = substr($bdDatTime[$i]->WorkDate,0,2)."/12/".substr($bdDatTime[$i]->WorkDate,9,2); break; } // $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, "RESUMEN DE HONORARIOS", 0, 1,'C', 0); $X = $X; $Y = $Y+0.5; $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("Abogado SEPLAW"), 0, 1,'L', 0); $pdf->SetXY(10.5,$Y); $pdf->SetTextColor(0,0,0); $pdf->Cell(3.5, 0.60, utf8_decode("Costo por Hr."), 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("Hrs Trabajadas"), 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 de Honorarios"), 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); //SRL 2021/02/04 Modificar fuente para ponerla en negritas 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, "Suma Total de Honorarios: " . 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, "GASTOS", 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("Fecha"), 0, 1,'L', 0); $pdf->SetXY(5.0,$Y); $pdf->SetTextColor(0,0,0); $pdf->Cell(10.0, 0.60, utf8_decode("Descripción"), 0, 1,'L', 0); $pdf->SetTextColor(0,0,0); $pdf->SetXY(16.00,$Y); $pdf->Cell(3.00, 0.60, utf8_decode("Monto (".$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 a solicitud del cliente la seccion de resumen de gastos. #============================================================================================================ #== 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, "RESUMEN DE GASTOS", 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, "Suma Total de Gastos: " . 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, "GRAN 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, "GRAN 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. Honorarios por servicios profesionales según descripción anexa"), 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. Gastos incurridos en relación con los servicios profesionales"), 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','B',11); $pdf->SetXY(10,$Y); $pdf->Cell(3.0, 0.25, utf8_decode("Subtotal:"), 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_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("I.V.A. (".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(strtolower(convertirNumeroLetra($strTotal,$prebill_currency) )), 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("RELACIÓN DE SERVICIOS"), 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); } function AmountInWords(float $amount) { $amount_after_decimal = round($amount - ($num = floor($amount)), 2) * 100; // Check if there is any number after decimal $amt_hundred = null; $count_length = strlen($num); $x = 0; $string = array(); $change_words = array(0 => '', 1 => 'One', 2 => 'Two', 3 => 'Three', 4 => 'Four', 5 => 'Five', 6 => 'Six', 7 => 'Seven', 8 => 'Eight', 9 => 'Nine', 10 => 'Ten', 11 => 'Eleven', 12 => 'Twelve', 13 => 'Thirteen', 14 => 'Fourteen', 15 => 'Fifteen', 16 => 'Sixteen', 17 => 'Seventeen', 18 => 'Eighteen', 19 => 'Nineteen', 20 => 'Twenty', 30 => 'Thirty', 40 => 'Forty', 50 => 'Fifty', 60 => 'Sixty', 70 => 'Seventy', 80 => 'Eighty', 90 => 'Ninety'); $here_digits = array('', 'Hundred','Thousand','Lakh', 'Crore'); while( $x < $count_length ) { $get_divider = ($x == 2) ? 10 : 100; $amount = floor($num % $get_divider); $num = floor($num / $get_divider); $x += $get_divider == 10 ? 1 : 2; if ($amount) { $add_plural = (($counter = count($string)) && $amount > 9) ? 's' : null; $amt_hundred = ($counter == 1 && $string[0]) ? ' and ' : null; $string [] = ($amount < 21) ? $change_words[$amount].' '. $here_digits[$counter]. $add_plural.' '.$amt_hundred:$change_words[floor($amount / 10) * 10].' '.$change_words[$amount % 10]. ' '.$here_digits[$counter].$add_plural.' '.$amt_hundred; } else $string[] = null; } $implode_to_Rupees = implode('', array_reverse($string)); $get_paise = ($amount_after_decimal > 0) ? "And " . ($change_words[$amount_after_decimal / 10] . " " . $change_words[$amount_after_decimal % 10]) . ' Paise' : ''; return ($implode_to_Rupees ? $implode_to_Rupees . 'Rupees ' : '') . $get_paise; } /** * 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'); }