$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);
});
/* SRL
#== 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);
//SRL Febrero 2, 2021
//Cambio de etiquetas a ingles
$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+10.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+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. 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','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("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(convert_number_to_words($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);
// SRL Febrero 2, 2021 Cambio fuente para poner negritas y cortar el renglon
$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 la fuente para poner negritas.
$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("Services provided to:"), 0, 1,'L', 0);
/* SRL
$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+6.0,$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+6.0,$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);
$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.50);
$pdf->Cell(2.5, 0.25, utf8_decode("Description of Services:"), 0, 1,'L', 0);
TitulosTie($pdf,8.0);
$X = 0;
$Y = 10.0;
#============================================================================================================
#== 2.2 REGISTROS DE TIEMPOS
#============================================================================================================
$Puntero = $pdf->GetY();
$TotRegsTie = count($bdDatTime);
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 = 7.0;
}
$time_timekeeper = "";
foreach ( $bdDatTime[$i] as $nombre => $hexa ) {
if($nombre == "Timekeeper.Identity")
{
$time_timekeeper = $hexa;
}
}
//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;
}
//$sDateWork = strtolower(substr($bdDatTime[$i]->WorkDate,0,2)."/".substr($bdDatTime[$i]->WorkDate,3,3)."/".substr($bdDatTime[$i]->WorkDate,9,2));
$pdf->SetTextColor(0,0,0);
$pdf->SetFont('verdana','',9);
$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('verdana','',9);
$pdf->SetXY(3.9,$Y);
$pdf->Cell(1.3, 0.25, utf8_decode($time_timekeeper), 0, 1,'C', 0);
$pdf->SetTextColor(0,0,0);
$pdf->SetFont('verdana','',9);
$pdf->SetXY(17.0,$Y);
$pdf->Cell(2.0, 0.25, number_format($bdDatTime[$i]->dHours,2), 0, 1,'C', 0);
$pdf->SetTextColor(0,0,0);
$pdf->SetFont('verdana','',9);
$pdf->SetXY(5.5,$Y);
$pdf->MultiCell(11.5, 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 Fees", 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.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("Professional"), 0, 1,'L', 0);
$pdf->SetXY(10.5,$Y);
$pdf->SetTextColor(0,0,0);
$pdf->Cell(3.5, 0.60, utf8_decode("Rate per 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("Work Hours"), 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 el 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, "EXPENSES 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','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("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(convert_number_to_words($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 == "" && $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 <> "" && $invoiceID <> "")
{
//echo $organi_id_ZB."test".$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";
//echo $bRefreshToken."
".$bClientId."
".$bClientSecret."
".$bRedirectUri."
".$bGrantType;
// $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;
echo $file_name_with_full_path;
$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("Work"), 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("Date"), 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("Professional"), 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("Description"), 0, 1,'L', 0);
$pdf->SetTextColor(0,0,0);
$pdf->SetFont('arial','B',9);
$pdf->SetXY(17.5,$Y+1.50);
$pdf->Cell(3.5, 0.25, utf8_decode("Hours"), 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 (($data->code === 200 || $data->code === 3000) && isset($data->code)) {
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');
}