while ($orders = tep_db_fetch_array($orders_query)) { $order = new order($orders['orders_id']); switch ($pdf_check) { case 'invoice': require DIR_WS_MODULES . 'batch_print/templates/Invoice_s3.php'; break; case 'packingslip': require DIR_WS_MODULES . 'batch_print/templates/Packing-Slip.php'; break; default: break; } // end switch } // end while $pdf_code = $pdf->output(); $fname = BATCH_PDF_DIR . BATCH_PDF_FILE; if ($fp = fopen($fname, 'w')) { fwrite($fp, $pdf_code); fclose($fp); } // end if tep_redirect(tep_href_link(DIR_WS_MODULES . 'batch_print/temp_pdf/batch_orders.pdf', '', 'NONSSL', false)); } // end if pdf if (tep_not_null($action)) { switch ($action) { case 'update_order': $oID = tep_db_prepare_input($_GET['oID']); $status = tep_db_prepare_input($_POST['status']); $comments = tep_db_prepare_input($_POST['comments']);
function pdfoutput__make_pdf_calendar($displayfrom = 0, $wholeyear = false, $admin = false, $forward = 0, $file = false) { global $settings, $lang; if ($displayfrom == 0) { $displayfrom = time(); } // prepare pdf include_once '../tagsets/class.ezpdf.php'; $pdf = new Cezpdf('a4'); $pdf->selectFont('../tagsets/fonts/Times-Roman.afm'); $fontsize = $settings['calendar_pdf_table_fontsize'] ? $settings['calendar_pdf_table_fontsize'] : 8; $titlefontsize = $settings['calendar_pdf_title_fontsize'] ? $settings['calendar_pdf_title_fontsize'] : 12; //start building calendar $displayfrom_lower = $displayfrom; $displayfrom_upper = date__skip_months($forward, $displayfrom_lower); if ($wholeyear) { $displayfrom_upper = mktime(0, 0, 0, 1, 1, date('Y', $displayfrom) + 1); } $results = calendar__get_events($admin, $displayfrom_lower, $displayfrom_upper, false, true); $month_names = explode(",", $lang['month_names']); //loop through each month for ($itime = $displayfrom_lower; $itime <= $displayfrom_upper; $itime = date__skip_months(1, $itime)) { $year = date("Y", $itime); $month = date("m", $itime); $weeks = days_in_month($month, $year); $table_title = $month_names[$month - 1] . ' ' . $year; $table_headings = array(); $calendar__weekdays = explode(",", $lang['format_datetime_weekday_abbr']); for ($i3 = 1; $i3 <= 7; ++$i3) { if (!isset($lang['format_datetime_firstdayofweek_0:Su_1:Mo']) || !$lang['format_datetime_firstdayofweek_0:Su_1:Mo']) { $wdindex = $i3 - 2; if ($wdindex < 0) { $wdindex = 6; } } else { $wdindex = $i3 - 1; } $table_headings[$i3] = $calendar__weekdays[$wdindex]; } $table_data = array(); for ($i2 = 1; $i2 <= count($weeks); ++$i2) { $las1 = array(); $las2 = array(); for ($i3 = 1; $i3 <= 7; ++$i3) { if (!isset($weeks[$i2][$i3])) { $las1[$i3] = ""; $las2[$i3] = ""; } else { $las1[$i3] = $weeks[$i2][$i3]; $las2[$i3] = ""; //the date is the key of the $results array for easy searching $today = $year * 10000 + $month * 100 + $weeks[$i2][$i3]; if (isset($results[$today])) { foreach ($results[$today] as $item) { $las2[$i3] .= $item['display_time']; $las2[$i3] .= "\n" . "<i>" . $item['location'] . "</i>\n"; if ($admin || $settings['public_calendar_hide_exp_name'] != 'y') { $las2[$i3] .= '<b>' . $item['title'] . '</b>'; } else { $las2[$i3] .= '<b>' . $lang['calendar_experiment_session'] . '</b>'; } $las2[$i3] .= "\n"; if ($admin) { $las2[$i3] .= experiment__list_experimenters($item['experimenters'], false, true) . "\n"; } if ($item['type'] == "experiment_session") { if ($admin) { $las2[$i3] .= $item['participants_registered'] . " (" . $item['participants_needed'] . "," . $item['participants_reserve'] . ")"; } else { $las2[$i3] .= $statusdata[$item['status']]['message']; } } $las2[$i3] .= "\n\n"; } } } } $table_data[] = $las1; $table_data[] = $las2; } $y = $pdf->ezTable($table_data, $table_headings, $table_title, array('gridlines' => 31, 'showHeadings' => 1, 'shaded' => 2, 'shadeCol' => array(1, 1, 1), 'shadeCol2' => array(0.9, 0.9, 1), 'fontSize' => $fontsize, 'titleFontSize' => $titlefontsize, 'rowGap' => 1, 'colGap' => 3, 'innerLineThickness' => 0.5, 'outerLineThickness' => 1, 'maxWidth' => 500, 'width' => 500, 'protectRows' => 2)); $pdf->ezSetDy(-20); } if ($file) { $pdffilecode = $pdf->output(); return $pdffilecode; //$fname ="/apache/orsee/admin/pdfdir/test.pdf"; //$fp = fopen($fname,'w'); //fwrite($fp,$pdffilecode); //fclose($fp); //echo '<A HREF="pdfdir/test.pdf" target="_blank">pdf file</A><BR><BR>'; //$pdfcode = str_replace("\n","\n<br>",htmlspecialchars($pdfcode)); //echo trim($pdfcode); } else { $pdf->ezStream(array('Content-Disposition' => 'calendar.pdf', 'Accept-Ranges' => 0, 'compress' => 1)); } }
function kontobuchungen_pdf($geldkonto_id, $kostenkonto, $jahr, $monat) { if ($monat == '') { $result = mysql_query("SELECT DATUM, BETRAG, VERWENDUNGSZWECK FROM GELD_KONTO_BUCHUNGEN WHERE GELDKONTO_ID='{$geldkonto_id}' && KONTENRAHMEN_KONTO = '{$kostenkonto}' && ( DATE_FORMAT( DATUM, '%Y' ) = '{$jahr}') && AKTUELL='1' ORDER BY GELD_KONTO_BUCHUNGEN_ID DESC"); } else { $result = mysql_query("SELECT DATUM, BETRAG, VERWENDUNGSZWECK FROM GELD_KONTO_BUCHUNGEN WHERE GELDKONTO_ID='{$geldkonto_id}' && KONTENRAHMEN_KONTO = '{$kostenkonto}' && ( DATE_FORMAT( DATUM, '%Y-%m' ) = '{$jahr}-{$monat}') && AKTUELL='1' ORDER BY GELD_KONTO_BUCHUNGEN_ID DESC"); } $numrows = mysql_numrows($result); if ($numrows > 0) { $k = new kontenrahmen(); $k->konto_informationen($kostenkonto); /* PDF */ //include_once ('pdfclass/class.ezpdf.php'); $pdf = new Cezpdf('a4', 'portrait'); $pdf->ezSetCmMargins(4.5, 2.5, 2.5, 2.5); $berlus_schrift = './fonts/Times-Roman.afm'; $text_schrift = './fonts/Arial.afm'; $pdf->addJpegFromFile('includes/logos/hv_logo198_80.jpg', 450, 780, 100, 42); $pdf->setLineStyle(0.5); $pdf->selectFont($berlus_schrift); $pdf->addText(42, 743, 6, "BERLUS HAUSVERWALTUNG - Fontanestr. 1 - 14193 Berlin"); $pdf->line(42, 750, 550, 750); $seite = $pdf->ezGetCurrentPageNumber(); $alle_seiten = $pdf->ezPageCount; $pdf->addText(70, 780, 12, "Kostenkonto {$kostenkonto}"); while ($row = mysql_fetch_assoc($result)) { $datum = date_mysql2german($row[DATUM]); $betrag = nummer_punkt2komma($row[BETRAG]); $vzweck = $this->umlaute_anpassen(ltrim(rtrim($row[VERWENDUNGSZWECK]))); $this->summe_kontobuchungen_jahr($geldkonto_id, $kostenkonto, $jahr); echo "<tr></td><td>{$datum}</td><td>{$erfass_nr}</td><td>{$betrag}</td><td>{$b_id}</td><td>{$vzweck}</td></tr><br>"; $pdf->ezText("{$datum}", 10, array('left' => '0')); if (strlen($vzweck) > '60') { $pdf->ezText("{$vzweck}", 10, array('left' => '60')); // $pdf->ezSetDy(-12); //abstand } else { $pdf->ezText("{$vzweck}", 10, array('left' => '60')); } $pdf->ezText("{$betrag}", 10, array('left' => '430')); $pdf->ezSetDy(-12); // abstand } $content = $pdf->output(); $dateiname_org = 'Kontenbericht'; $dateiname = $this->save_file($dateiname_org, 'Monatsbericht_Konten', $geldkonto_id, $content, $monat, $jahr); // weiterleiten($dateiname); $download_link = "<h3><a href=\"{$dateiname}\">Monatsbericht {$geldkonto_id} für {$monat}/{$jahr} HIER</a></h3>"; echo $download_link; } else { // echo "Geldkonto $geldkonto_id - Kostenkonto $kostenkonto leer<br>"; } }
function BuildPDFReport($userid) { $GLOBALS["SartON"] = time(); $q = new mysql(); $sql = "SELECT * FROM quarantine_report_users WHERE userid='{$userid}' and `type`=1 and `enabled`=1"; $ligne = mysql_fetch_array($q->QUERY_SQL($sql, "artica_backup")); if ($ligne["enabled"] == 0) { return; } $params = unserialize(base64_decode($ligne["parameters"])); $days = $params["days"]; $subject = $params["subject"]; $subject = str_replace("{", "", $subject); $subject = str_replace("}", "", $subject); $session = md5($user->password); if ($days < 1) { $days = 2; } $user = new user($userid); while (list($num, $ligne) = each($user->HASH_ALL_MAILS)) { $recipient_sql[] = "mailto='{$ligne}'"; } $date = date('Y-m-d'); $recipients = implode(" OR ", $recipient_sql); $sql = "SELECT mailfrom,zDate,MessageID,DATE_FORMAT(zdate,'%W %D %H:%i') as tdate,subject FROM quarantine\n\tWHERE (zDate>DATE_ADD('{$date}', INTERVAL -{$days} DAY)) AND ({$recipients}) ORDER BY zDate DESC;"; if ($GLOBALS["VERBOSE"]) { echo "{$sql}\n"; } $datepdf = date('Y-m-d'); $results = $q->QUERY_SQL($sql, "artica_backup"); $num_rows = mysql_num_rows($results); if (!$q->ok) { send_email_events("Build SMTP quarantine report failed for {$uid}", "{$sql}\n{$q->mysql_error}", "postfix"); return null; } if ($num_rows == 0) { return; } $pdf = new Cezpdf('a4', 'portrait'); $pdf->ezSetMargins(50, 70, 50, 50); $all = $pdf->openObject(); $pdf->saveState(); //$pdf->setStrokeColor(0,0,0,1); $pdf->line(20, 40, 578, 40); $pdf->line(20, 822, 578, 822); $pdf->addText(50, 34, 6, $date); $pdf->restoreState(); $pdf->closeObject(); $pdf->addObject($all, 'all'); $mainFont = dirname(__FILE__) . "/ressources/fonts/Helvetica.afm"; $codeFont = dirname(__FILE__) . "/ressources/fonts/Courier.afm"; $pdf->selectFont($mainFont); $pdf->ezText("{$user->DisplayName}\n", 30, array('justification' => 'centre')); $pdf->ezText("{$subject}\n", 20, array('justification' => 'centre')); $pdf->ezText("{$date} ({$num_rows} message(s))", 18, array('justification' => 'centre')); $pdf->ezStartPageNumbers(100, 30, 12, "left", "Page {PAGENUM}/{TOTALPAGENUM}"); $pdf->ezNewPage(); $options = array('showLines' => 2, 'showHeadings' => 0, 'shaded' => 2, 'shadeCol' => array(1, 1, 1), 'shadeCol2' => array(0.8, 0.8, 0.8), 'fontSize' => 11, 'textCol' => array(0, 0, 0), 'textCol2' => array(1, 1, 1), 'titleFontSize' => 16, 'titleGap' => 8, 'rowGap' => 5, 'colGap' => 10, 'lineCol' => array(1, 1, 1), 'xPos' => 'left', 'xOrientation' => 'right', 'width' => 500, 'maxWidth' => 500); while ($ligne = @mysql_fetch_array($results, MYSQL_ASSOC)) { $mail_subject = $ligne["subject"]; $from = trim($ligne["mailfrom"]); $zDate = $ligne["tdate"]; $MessageID = $ligne["MessageID"]; if ($from == null) { $from = "unknown"; } $domain = "unknown"; if (preg_match("#(.+?)@(.+)#", $from, $re)) { $domain = $re[2]; } $mail_subject = str_replace("{", "", $mail_subject); $mail_subject = str_replace("}", "", $mail_subject); $uri = "<c:alink:{{$params["URI"]}/user.quarantine.query.php?uid={$user->uid}&session={$session}&mail={$MessageID}>{$mail_subject}</c:alink>"; $data[] = array($zDate, $from, $uri); } $pdf->ezTable($data, $cols, $subject, $options); $pdfcode = $pdf->output(); $fname = "/tmp/" . date('Ymdhi') . "-{$user->mail}-quarantines.pdf"; if ($GLOBALS["VERBOSE"]) { echo "{$pdf->messages}\nbuilding {$fname}\n"; } @unlink($fname); if ($GLOBALS["VERBOSE"]) { echo "Building {$fname}\n"; } $fp = fopen($fname, 'w'); fwrite($fp, $pdfcode); fclose($fp); if (preg_match("#(.+?)@(.+)#", $user->mail, $re)) { $domain = $re[2]; } $PostmasterAdress = "no-reply-quarantine@{$domain}"; $ini = new Bs_IniHandler("/etc/artica-postfix/smtpnotif.conf"); if ($ini->_params["SMTP"]["smtp_sender"] != null) { $PostmasterAdress = $ini->_params["SMTP"]["smtp_sender"]; } if (file_exists('/etc/artica-postfix/settings/Daemons/PostfixPostmaster')) { $PostmasterAdress = trim(@file_get_contents('/etc/artica-postfix/settings/Daemons/PostfixPostmaster')); } $unix = new unix(); $sendmail = $unix->find_program("sendmail"); $mail = new PHPMailer(true); $mail->IsSendmail(); $mail->AddAddress($user->mail, $user->DisplayName); $mail->AddReplyTo($PostmasterAdress, $PostmasterAdress); $mail->From = $PostmasterAdress; $mail->Subject = $subject; $mail->Body = "{$subject}\nSee attached file...\n"; $mail->AddAttachment($fname, basename($fname)); $content = $mail->Send(true); $tmpfile = "/tmp/" . md5(date('Y-m-d H:is') . "-{$user->uid}-msmtp"); file_put_contents($tmpfile, $content); $cmd = "{$sendmail} -bm -t -f {$PostmasterAdress} <{$tmpfile}"; system($cmd); @unlink($tmpfile); @unlink($fname); $SartOff = time(); $time_duration = distanceOfTimeInWords($GLOBALS["SartON"], $SartOff); send_email_events("SMTP quarantine report for {$user->mail} (success) {$num_rows} message(s)", "duration:{$time_duration}\nnothing to say more...", "postfix"); }
function creaPDF($ids, $tmpName, $path, $PATHQR, $tmp = "") { require dirname(dirname(dirname(__FILE__))) . '/f4/configuracion/utils.php'; require dirname(dirname(dirname(__FILE__))) . '/f4/configuracion/importeco.php'; require dirname(dirname(dirname(__FILE__))) . "/gui/QRCode/qr_imgV2.php"; $data = ""; $facturaController = new FacturaController($path); $selloController = new SelloController($path); $empresaController = new EmpresaController($path); $sucursalController = new SucursalController($path); $FWK_PDFFONTS = 'pdf/fonts/'; $FWK_PDFDEFAULTFONT = 'pdf/fonts/Helvetica.afm'; $FWK_PDFCOURIERFONT = 'pdf/fonts/Courier.afm'; // Obtener factura y sus anexos $TIPOSCOMPROBANTEMXP = array(1 => "Factura", 3 => "Nota de Cr.", 2 => "NOTA DE DEBITO"); $idconsulta = ""; $idconsulta = explode(",", trim($ids)); foreach ($idconsulta as $valor) { if (is_null($valor) || $valor == "") { array_pop($idconsulta); } } $contadorTotalPaginas = count($idconsulta); $contadorPagina = 1; // Crea el documento pdf $pdf = new Cezpdf('LETTER', 'portrait'); foreach ($idconsulta as $idfactura) { $data['idfactura'] = $idfactura; $factura = $facturaController->execute('facturaParaPdf', $data); $row_factura = $factura['respuesta']; $info_xtra = json_decode($row_factura["info_xtra"]); $data['idfacefactura'] = $factura['respuesta']['idface_factura']; $data['idempresa'] = $factura['respuesta']['idempresa']; $data['idsello'] = $factura['respuesta']['idsello']; $version = $factura['respuesta']['version']; $addenda = $facturaController->execute('datosAddenda', $data); $row_addenda = $addenda['respuesta']; $empresa = $empresaController->execute('allId', $data); $row_empresa = $empresa['respuesta']; $sello = $selloController->execute('obtenerPorIdsello', $data); $row_sello = $sello['respuesta']; $data['sucursal'] = $sello['respuesta']['sucursal']; $sucursal = $sucursalController->execute('nombreSucIdempresa', $data); $row_sucursal = $sucursal['respuesta']; $xmlArray = xml2array(base64_decode($row_factura['factura'])); $attr = "_attr"; if ($version === "3.2") { $NSP = "cfdi:"; } else { $NSP = ""; } $comprobante = $NSP . "Comprobante"; $emisor = $NSP . "Emisor"; $emisorDomFiscal = $NSP . "DomicilioFiscal"; $emisorExpedidoEn = $NSP . "ExpedidoEn"; $receptor = $NSP . "Receptor"; $domicilio = $NSP . "Domicilio"; $concepto = $NSP . "Conceptos"; $conceptoTag = $NSP . "Concepto"; $impuestos = $NSP . "Impuestos"; $traslado = $NSP . "Traslados"; $trasladoTag = $NSP . "Traslado"; $retencion = $NSP . "Retenciones"; $retencionTag = $NSP . "Retencion"; //INICIALIZACIONES $comprobanteNode = null; $emisorNode = null; $emisordomicilioNode = null; $expedidoNode = null; $receptorNode = null; $receptordomicilioNode = null; $conceptoNode = null; $impuestosNode = null; $trasladoNode = null; $retencionNode = null; // -------------------------------------------------chs -------------------------------------------------------------- $comprobanteNode = $xmlArray[$comprobante . $attr]; $emisorNode = $xmlArray[$comprobante][$emisor . $attr]; $emisordomicilioNode = $xmlArray[$comprobante][$emisor][$emisorDomFiscal . $attr]; $expedidoNode = isset($xmlArray[$comprobante][$emisor][$emisorExpedidoEn . $attr]) ? $xmlArray[$comprobante][$emisor][$emisorExpedidoEn . $attr] : ""; $receptorNode = $xmlArray[$comprobante][$receptor . $attr]; $receptordomicilioNode = $xmlArray[$comprobante][$receptor][$domicilio . $attr]; $conceptos = $xmlArray[$comprobante][$concepto]; $impuestosNode = $xmlArray[$comprobante][$impuestos . $attr]; $traslados = $xmlArray[$comprobante][$impuestos][$traslado]; $retenciones = isset($xmlArray[$comprobante][$impuestos][$retencion][$retencionTag . $attr]) ? $xmlArray[$comprobante][$impuestos][$retencion][$retencionTag . $attr] : ""; $regimenFiscal = $xmlArray[$comprobante][$emisor]["cfdi:RegimenFiscal_attr"]["Regimen"]; // --------------------------------------------------------------------------------------------------------------- //descuentos $desc1 = 0.0; $desc2 = 0.0; //================================================================================================================== $pdf->ezSetMargins(100, 30, 30, 30); $pdf->selectFont($FWK_PDFDEFAULTFONT); $pdf->setLineStyle(0.7, '', '', '', 0); $pdf->openHere('Fit'); if ($row_factura['tipocfd'] == 3) { $pdf->setStrokeColor(255, 0, 0); } if ($row_factura['tipocfd'] == 2) { $pdf->setStrokeColor(0, 255, 0); } // Inicia numeracin de paginas. $pagina = 1; $pdf->ezStartPageNumbers(500, 15, 10, '', '{PAGENUM} de {TOTALPAGENUM}', 1); $primeraPagina = $pdf->currentPage; // i. Agrega el logo de la empresa $pathToLogo = $path == "../" ? "../f4/extensiones/" : ""; $logofile = "logos/f.jpg"; //TENDRA QUE VENIR DE UN PARAMETRO EN LA BD. /*if(isset($row_empresa['rfc']) && !empty($row_empresa['rfc'])) $logofile="logos/".$row_empresa['rfc'].".jpg";*/ if (isset($sucursal["respuesta"]["sucursal"]) && !empty($sucursal["respuesta"]["sucursal"])) { $logofile = "logos/" . strtolower($sucursal["respuesta"]["sucursal"]) . ".jpg"; } error_log($logofile); if ($comprobanteNode['serie'] == "X") { $logofile = "logos/wingu-xpress.jpg"; } $pdf->addJpegFromFile($pathToLogo . $logofile, 30, 705, 140); // i. Agrega la leyenda "cancelada" if ($row_factura['estatus'] == 0) { $pdf->setColor(0.9, 0.9, 0.9); $pdf->addText(180, 200, 65, "<b>CANCELADA</b>", -45); $pdf->setColor(0, 0, 0); } // ------------------------------------------ENCABEZADO ------------------------------------------ //ENCABEZADO DE LA FACTURA $tipoDocto = $row_factura['tipodocumento']; $tipoDocto1 = $row_factura['tipodocumento'] == "FACTURA" ? "FACTURA" : ""; $tipoDocto2 = $row_factura['tipodocumento'] == "NOTA CARGO" ? "FACTURA" : ""; $tipoDocto3 = $row_factura['tipodocumento'] == "NOTA CREDITO" ? "NOTA DE CREDITO" : ""; $emisor = utf8_decode($emisorNode['nombre'] . "\n" . $emisorNode['rfc']) . "\n"; $noInterior = isset($emisordomicilioNode['noInterior']) ? $emisordomicilioNode['noInterior'] : ""; $noExterior = isset($emisordomicilioNode['noExterior']) ? $emisordomicilioNode['noExterior'] : ""; $emisor .= utf8_decode($emisordomicilioNode['calle'] . " {$noExterior}"); $emisor .= utf8_decode($emisordomicilioNode['colonia']); if (isset($emisordomicilioNode['localidad'])) { $emisor .= "\n" . utf8_decode($emisordomicilioNode['localidad']); } if ($emisordomicilioNode['municipio'] != "" && isset($emisordomicilioNode['municipio'])) { $emisor .= "\n" . utf8_decode($emisordomicilioNode['municipio']); } if ($emisordomicilioNode['estado'] != "" && isset($emisordomicilioNode['estado'])) { $emisor .= ", " . utf8_decode($emisordomicilioNode['estado']); } if ($emisordomicilioNode['codigoPostal'] != "" && isset($emisordomicilioNode['codigoPostal'])) { $emisor .= "\nCP " . utf8_decode($emisordomicilioNode['codigoPostal']); } $emisor .= " " . utf8_decode($emisordomicilioNode['pais']); $telefono = isset($row_empresa['telefono']) ? $row_empresa['telefono'] : ""; $emisor .= "\nTel: " . $telefono . "\n"; $mail = isset($row_empresa['mail']) ? $row_empresa['mail'] : ""; $emisor .= "\n" . $mail; $emisor1 = utf8_decode($emisorNode['nombre']); $sucursal = ""; if ($expedidoNode != "") { if (utf8_decode($row_sucursal['sucursal']) == "Q") { $tipoSucursal = utf8_decode('Querétaro'); } else { if (utf8_decode($row_sucursal['sucursal']) == "F") { $tipoSucursal = utf8_decode('5/6'); } else { if (utf8_decode($row_sucursal['sucursal']) == "S") { $tipoSucursal = utf8_decode('Santa Fe'); } } } $sucursal = "Sucursal " . $tipoSucursal . "\n"; if (utf8_decode($row_sucursal['sucursal']) != "S") { $noInteriorExpedido = isset($expedidoNode['noInterior']) ? $expedidoNode['noInterior'] : ""; $sucursal .= utf8_decode($expedidoNode['calle'] . " " . $expedidoNode['noExterior'] . " ") . "\n"; $sucursal .= utf8_decode($expedidoNode['colonia']) . "\n"; $sucursal .= utf8_decode($expedidoNode['municipio']) . ", " . utf8_decode($expedidoNode['estado']) . "\n"; $sucursal .= "CP " . utf8_decode($expedidoNode['codigoPostal']) . " " . utf8_decode($expedidoNode['pais']); } } ////////// i. Nombre del emisor $colNames = array(); $tableData = array(array("dato" => $emisor1)); $colOptions = array("dato" => array('justification' => 'left', 'width' => 200)); $options = array('showLines' => 0, 'showHeadings' => 0, 'shaded' => 0, 'shadeCol' => array(1, 1, 1), 'fontSize' => 9, 'textCol' => array(0, 0, 0), 'rowGap' => 0, 'colGap' => 0, 'xPos' => 200, 'xOrientation' => 'right', 'width' => 200, 'cols' => $colOptions, 'innerLineThickness' => 0.3, 'outerLineThickness' => 0.3); // Dibuja la tabla nombre del emisor $pdf->ezSetY(765); $pdf->ezTable($tableData, $colNames, "", $options); ////////// i. Datos del emisor y de la sucursal $tableData = array(array("emisor" => $emisor, "espacio" => "", "sucursal" => $sucursal)); $colOptions = array("emisor" => array('justification' => 'left', 'width' => 150), "espacio" => array('justification' => 'left', 'width' => 3), "sucursal" => array('justification' => 'left', 'width' => 100)); $options = array('showLines' => 0, 'showHeadings' => 0, 'shaded' => 0, 'shadeCol' => array(1, 1, 1), 'fontSize' => 7, 'textCol' => array(0, 0, 0), 'rowGap' => 0, 'colGap' => 0, 'xPos' => 190, 'xOrientation' => 'right', 'width' => 335, 'cols' => $colOptions, 'innerLineThickness' => 0.3, 'outerLineThickness' => 0.3); // Dibuja la tabla $pdf->ezTable($tableData, "", "", $options); ////////// i. Datos del documento $foliodocto = rellena("0", 6, $comprobanteNode['folio']); $seriedocto = $comprobanteNode['serie']; if (!empty($seriedocto)) { $foliodocto = $seriedocto . "-" . rellena("0", 6, $comprobanteNode['folio']); } $fechastr = $comprobanteNode['fecha']; $fechatok = explode("T", $fechastr); $toksf = explode("-", $fechatok[0]); $fechastr = $toksf[2] . "-" . $toksf[1] . "-" . $toksf[0] . " " . $fechatok[1]; $fechastrcfdi = $row_factura['FechaTimbrado']; $ncert = $comprobanteNode['noCertificado']; $aprob = $row_factura['noCertificadoSAT']; //chs $tableData = array(array("dato" => "<b>" . $tipoDocto1 . $tipoDocto2 . $tipoDocto3 . "</b>"), array("dato" => "<b>" . $foliodocto . "</b>"), array("dato" => "FECHA DE EMISION"), array("dato" => $fechastr), array("dato" => "LUGAR DE EXPEDICION"), array("dato" => utf8_decode($info_xtra->LugarExpedicion)), array("dato" => "FECHA DE CERTIFICACION"), array("dato" => $fechastrcfdi), array("dato" => "No. de Serie del Certificado del Emisor"), array("dato" => $ncert), array("dato" => "No. de Serie del Certificado del SAT"), array("dato" => $aprob), array("dato" => "Folio Fiscal"), array("dato" => $row_factura['uuid'])); $colOptions = array("dato" => array('justification' => 'left', 'width' => 120)); /*JASR*/ $options = array('showLines' => 1, 'showHeadings' => 0, 'shaded' => 2, 'shadeCol' => array(1, 1, 1), 'shadeCol2' => array(0.9, 0.9, 0.9), 'fontSize' => 7, 'textCol' => array(1, 1, 1), 'rowGap' => 2, 'colGap' => 5, 'xPos' => 455, 'xOrientation' => 'right', 'width' => 120, 'cols' => $colOptions, 'innerLineThickness' => 0.3, 'outerLineThickness' => 0.3); // Dibuja la tabla datos del documento $pdf->ezSetDy(70); $pdf->ezTable($tableData, "", "", $options); ////////// i. Datos del cliente $noInterior = isset($receptordomicilioNode['noInterior']) ? utf8_decode($receptordomicilioNode['noInterior']) : ""; $municipio = isset($receptordomicilioNode['municipio']) ? $receptordomicilioNode['municipio'] : ""; $localidadCliente = isset($receptordomicilioNode['localidad']) ? utf8_decode($receptordomicilioNode['localidad']) : ""; $tableData1 = array(array("cliente" => "<b>Cliente</b>"), array("cliente" => utf8_decode($receptorNode['nombre'])), array("cliente" => "RFC: " . utf8_decode($receptorNode['rfc'])), array("cliente" => utf8_decode($receptordomicilioNode['calle']) . " " . utf8_decode($receptordomicilioNode['noExterior']) . " {$noInterior} "), array("cliente" => utf8_decode($receptordomicilioNode['colonia']) . " " . $localidadCliente), array("cliente" => utf8_decode($municipio) . ", " . utf8_decode($receptordomicilioNode['estado']) . " " . utf8_decode($receptordomicilioNode['codigoPostal']) . " \n" . utf8_decode($receptordomicilioNode['pais'])), array("cliente" => utf8_decode("Atención: " . $info_xtra->Receptor->contacto . " Cliente: " . $info_xtra->Receptor->noCliente)), array("cliente" => utf8_decode("Tel: " . $info_xtra->Receptor->telefono))); $formaDePago = isset($comprobanteNode['formaDePago']) ? $comprobanteNode['formaDePago'] : "PAGO EN UNA SOLA EXHIBICION"; $metodoPago = isset($comprobanteNode['metodoDePago']) ? $comprobanteNode['metodoDePago'] : "No Identificado"; $numeroCuentaPago = isset($comprobanteNode['NumCtaPago']) ? $comprobanteNode['NumCtaPago'] : "No Identificado"; $tableData2 = array(array("expedido" => "Expedido en: " . utf8_decode($info_xtra->LugarExpedicion)), array("expedido" => "Forma de Pago: " . utf8_decode($formaDePago)), array("expedido" => "Metodo de Pago: " . utf8_decode($metodoPago)), array("expedido" => "No. de Cuenta: " . utf8_decode($numeroCuentaPago)), array("expedido" => "Condiciones de Pago: " . utf8_decode($comprobanteNode['condicionesDePago'])), array("expedido" => "Regimen Fiscal: " . utf8_decode(preg_replace("/Ii/", "II", ucwords(strtolower($regimenFiscal))))), array("expedido" => "Tipo de Cambio: " . $comprobanteNode['TipoCambio'] . " Moneda: " . $comprobanteNode['Moneda']), array("expedido" => "Elaboro: " . utf8_decode($info_xtra->Vendedor)), array("expedido" => utf8_decode("Póliza: " . $info_xtra->NumeroPoliza . " SAP No: " . $info_xtra->NumeroPedido))); $tableData = array(); $aux = count($tableData1) >= count($tableData2) ? $tableData1 : $tableData2; $cont = 0; foreach ($aux as $arr) { array_push($tableData, array("cliente" => $tableData1[$cont]["cliente"], "expedido" => $tableData2[$cont]["expedido"])); $cont++; } $colNames = array("cliente" => "", "expedido" => ""); $colOptions = array("cliente" => array('justification' => 'left', 'width' => 205), "expedido" => array('justification' => 'left', 'width' => 205)); $options = array('showLines' => 1, 'showHeadings' => 0, 'shaded' => 1, 'shadeCol' => array(0.9, 0.9, 0.9), 'fontSize' => 7, 'textCol' => array(0, 0, 0), 'rowGap' => 2, 'colGap' => 5, 'xPos' => 35, 'xOrientation' => 'right', 'width' => 410, 'cols' => $colOptions, 'innerLineThickness' => 0.3, 'outerLineThickness' => 0.3); $pdf->ezSetDy(125); $pdf->ezTable($tableData, $colNames, "", $options); //encabezado //error_log(print_r($info_xtra,true)); $tableData = array(array("dato" => utf8_decode($info_xtra->Consumo->NotaEncabezado))); $colOptions = array("dato" => array('justification' => 'left', 'width' => 540)); $options = array('showLines' => 1, 'showHeadings' => 0, 'shaded' => 0, 'shadeCol' => array(0.9, 0.9, 0.9), 'fontSize' => 7, 'textCol' => array(0, 0, 0), 'rowGap' => 5, 'colGap' => 5, 'xPos' => 35, 'xOrientation' => 'right', 'width' => 120, 'cols' => $colOptions, 'innerLineThickness' => 0.3, 'outerLineThickness' => 0.3); $pdf->ezSetDy(-10); $pdf->ezTable($tableData, "", "", $options); $actualY = $pdf->y; $pdf->setColor(0, 0, 0); $pdf->filledRectangle(30, $actualY - 30, 540, 18); $pdf->ezSetY($actualY - 15); $pdf->setColor(1, 1, 1); $pdf->ezText("<b>Codigo</b>", 7, array('left' => 25, 'justification' => 'left')); $pdf->ezSetY($actualY - 15); $pdf->ezText("<b>Descripcion</b>", 7, array('left' => 180, 'justification' => 'left')); $pdf->ezSetY($actualY - 15); $pdf->ezText("<b>Cant</b>", 7, array('left' => 361, 'justification' => 'left')); $pdf->ezSetY($actualY - 15); $pdf->ezText("<b>Unidad</b>", 7, array('left' => 398, 'justification' => 'left')); $pdf->ezSetY($actualY - 15); $pdf->ezText("<b>Unitario</b>", 7, array('left' => 445, 'justification' => 'left')); $pdf->ezSetY($actualY - 15); $pdf->ezText("<b>Importe</b>", 7, array('left' => 497, 'justification' => 'left')); ////////// i. Partidas $tableData = array(); $renglones = 0; $rowData = array("codigo" => "", "cantidad" => "", "unidad" => "", "descripcion" => "", "unitario" => "", "importe" => ""); $partidaCnt = 0; $cantidadArrayConceptos = count($conceptos); foreach ($conceptos as $key => $conceptoNode) { if (stristr($key, $attr) && $cantidadArrayConceptos == 2) { $partidaCnt++; $renglones += 2; $currentObj = array(); $descripcion = $conceptoNode['descripcion']; $totalPalabras = strlen($descripcion); $totalCaracteres = 4800; if ($totalPalabras >= $totalCaracteres) { $pagDesc = ceil($totalPalabras / $totalCaracteres); $aux = 1; $array = array(); for ($i = 1; $i <= $pagDesc; $i++) { if ($i == $pagDesc) { $array[] = $totalPalabras; } else { $val = $aux += $totalCaracteres; $array[] = $val; } } $desc = array(); $o = 0; foreach ($array as $valor) { $desc[] = substr($descripcion, $o, $valor); $o += $valor - $o; } $cont = 1; foreach ($desc as $descripcionexp) { $currentObj["codigo"] = $info_xtra->Consumo->partidas[$partidaCnt - 1]->codigo; $currentObj["cantidad"] = number_format(abs(doubleval($conceptoNode['cantidad'])), 2); //$currentObj["unidad"]= (isset($conceptoNode['unidad'])) ? $conceptoNode['unidad'] : "No Aplica"; $currentObj["unidad"] = $conceptoNode['unidad']; //)) ? $conceptoNode['unidad'] : "No Aplica"; $currentObj["descripcion"] = str_replace("__", "\n", utf8_decode($descripcionexp) . "\n" . utf8_decode($info_xtra->Consumo->partidas[$partidaCnt - 1]->nota)); if ($info_xtra->TipoImpresion == "KI2") { $contPartidas = count($info_xtra->Consumo->partidas); for ($i = 1; $i < $contPartidas; $i++) { $currentObj["descripcion"] .= $info_xtra->Consumo->partidas[$i]->codigo . " " . $info_xtra->Consumo->partidas[$i]->cantidad . " " . $info_xtra->Consumo->partidas[$i]->unidad . " " . $info_xtra->Consumo->partidas[$i]->descripcion . " \$" . $info_xtra->Consumo->partidas[$i]->valorUnitario . " \n"; } } $currentObj["unitario"] = number_format($conceptoNode['valorUnitario'], 2); $currentObj["importe"] = number_format(doubleval($conceptoNode['importe']), 2); $for = $cont++; log_action("for:::" . $for); if ($for > 1) { $currentObj["codigo"] = ""; $currentObj["cantidad"] = ""; $currentObj["unidad"] = ""; $currentObj["unitario"] = ""; $currentObj["importe"] = ""; } array_push($tableData, $currentObj); } } else { $currentObj["codigo"] = $info_xtra->Consumo->partidas[$partidaCnt - 1]->codigo; $currentObj["cantidad"] = number_format(abs(doubleval($conceptoNode['cantidad'])), 2); //$currentObj["unidad"]= (isset($conceptoNode['unidad'])) ? $conceptoNode['unidad'] : "No Aplica"; $currentObj["unidad"] = $conceptoNode['unidad']; //)) ? $conceptoNode['unidad'] : "No Aplica"; $currentObj["descripcion"] = str_replace("__", "\n", utf8_decode($descripcion) . "\n" . utf8_decode($info_xtra->Consumo->partidas[$partidaCnt - 1]->nota)); if ($info_xtra->TipoImpresion == "KI2") { $contPartidas = count($info_xtra->Consumo->partidas); for ($i = 1; $i < $contPartidas; $i++) { $currentObj["descripcion"] .= utf8_decode($info_xtra->Consumo->partidas[$i]->codigo . " " . $info_xtra->Consumo->partidas[$i]->cantidad . " " . $info_xtra->Consumo->partidas[$i]->unidad . " " . $info_xtra->Consumo->partidas[$i]->descripcion . " " . $info_xtra->Consumo->partidas[$i]->valorUnitario) . " \n"; } } $currentObj["unitario"] = number_format($conceptoNode['valorUnitario'], 2); $currentObj["importe"] = number_format(doubleval($conceptoNode['importe']), 2); array_push($tableData, $currentObj); } } else { foreach ($conceptoNode as $key1 => $conceptoNode1) { log_action(print_r($key1, TRUE)); if (stristr($key1, $attr)) { $partidaCnt++; $renglones += 2; $currentObj = array(); $currentObj["codigo"] = $info_xtra->Consumo->partidas[$partidaCnt - 1]->codigo; $currentObj["cantidad"] = number_format(abs(doubleval($conceptoNode1['cantidad'])), 2); //$currentObj["unidad"]= (isset($conceptoNode['unidad'])) ? $conceptoNode['unidad'] : "No Aplica"; $currentObj["unidad"] = $conceptoNode1['unidad']; //)) ? $conceptoNode['unidad'] : "No Aplica"; $currentObj["descripcion"] = str_replace("__", "\n", utf8_decode($conceptoNode1['descripcion'] . "\n" . $info_xtra->Consumo->partidas[$partidaCnt - 1]->nota)); if ($info_xtra->TipoImpresion == "KI2") { $contPartidas = count($info_xtra->Consumo->partidas); for ($i = 1; $i < $contPartidas; $i++) { $currentObj["descripcion"] .= $info_xtra->Consumo->partidas[$i]->codigo . " " . $info_xtra->Consumo->partidas[$i]->cantidad . " " . $info_xtra->Consumo->partidas[$i]->unidad . " " . $info_xtra->Consumo->partidas[$i]->descripcion . " \$" . $info_xtra->Consumo->partidas[$i]->valorUnitario . " \n"; } } $currentObj["unitario"] = number_format($conceptoNode1['valorUnitario'], 2); $currentObj["importe"] = number_format(doubleval($conceptoNode1['importe']), 2); array_push($tableData, $currentObj); } } //fin foreach 2 chs 20130705 } } $currentObj = array(); $currentObj["codigo"] = ""; $currentObj["cantidad"] = ""; $currentObj["unidad"] = ""; $currentObj["descripcion"] = str_replace("__", "\n", utf8_decode($row_factura["fnotas"])); $currentObj["unitario"] = ""; $currentObj["importe"] = ""; array_push($tableData, $currentObj); if (isset($row_addenda['cl_fld1'])) { $currentObj = array(); $currentObj["cantidad"] = ""; $currentObj["descripcion"] = $row_addenda['cl_fld1']; if (!empty($row_addenda['cl_fld2'])) { $currentObj["descripcion"] .= "\n" . $row_addenda['cl_fld2']; } if (!empty($row_addenda['cl_fld3'])) { $currentObj["descripcion"] .= "\n" . $row_addenda['cl_fld3']; } if (!empty($row_addenda['cl_fld4'])) { $currentObj["descripcion"] .= "\n" . $row_addenda['cl_fld4']; } if (!empty($row_addenda['cl_fld5'])) { $currentObj["descripcion"] .= "\n" . $row_addenda['cl_fld5']; } if (!empty($row_addenda['cl_fld6'])) { $currentObj["descripcion"] .= "\n" . $row_addenda['cl_fld6']; } if (!empty($row_addenda['cl_fld7'])) { $currentObj["descripcion"] .= "\n" . $row_addenda['cl_fld7']; } if (!empty($row_addenda['cl_fld8'])) { $currentObj["descripcion"] .= "\n" . $row_addenda['cl_fld8']; } if (!empty($row_addenda['cl_fld9'])) { $currentObj["descripcion"] .= "\n" . $row_addenda['cl_fld9']; } if (!empty($row_addenda['cl_fld10'])) { $currentObj["descripcion"] .= "\n" . $row_addenda['cl_fld10']; } if (!empty($row_addenda['cl_fld11'])) { $currentObj["descripcion"] .= "\n" . $row_addenda['cl_fld11']; } if (!empty($row_addenda['cl_fld12'])) { $currentObj["descripcion"] .= "\n" . $row_addenda['cl_fld12']; } $currentObj["unitario"] = ""; $currentObj["importe"] = ""; array_push($tableData, $currentObj); } $currentObj = array(); $currentObj["codigo"] = ""; $currentObj["cantidad"] = ""; $currentObj["unidad"] = ""; $currentObj["descripcion"] = ""; $currentObj["unitario"] = ""; $currentObj["importe"] = ""; if ($info_xtra->TipoImpresion == "KI2") { for ($renglones; $renglones < 10 - count($info_xtra->Consumo->partidas) * 0.95; $renglones++) { array_push($tableData, $currentObj); } } else { if ($renglones < 10) { for ($renglones; $renglones < 10; $renglones++) { array_push($tableData, $currentObj); } } } $colNames = array("codigo" => "", "descripcion" => "", "cantidad" => "", "unidad" => "", "unitario" => "", "importe" => ""); $colOptions = array("codigo" => array('justification' => 'center', 'width' => 70), "descripcion" => array('justification' => 'left', 'width' => 280), "cantidad" => array('justification' => 'center', 'width' => 40), "unidad" => array('justification' => 'left', 'width' => 40), "unitario" => array('justification' => 'right', 'width' => 55), "importe" => array('justification' => 'right', 'width' => 55)); $options = array('showLines' => 1, 'showHeadings' => 1, 'shaded' => 1, 'shadeCol' => array(0.9, 0.9, 0.9), 'fontSize' => 7, 'textCol' => array(0, 0, 0), 'rowGap' => 4, 'colGap' => 5, 'xPos' => 35, 'xOrientation' => 'right', 'width' => 410, 'cols' => $colOptions, 'innerLineThickness' => 0.3, 'outerLineThickness' => 0.3); // Dibuja la tabla partidas $pdf->ezSetDy(11); $pdf->ezTable($tableData, $colNames, "", $options); ////////// i. Cantidad con letra $cadena = covertirNumLetras(number_format($comprobanteNode['total'], 2, ".", '')); if ($comprobanteNode['Moneda'] == "USD") { $cadena = str_replace("M.N.", "USD", $cadena); $cadena = str_replace("PESOS", "DOLARES", $cadena); $cadena = str_replace("PESO", "DOLAR", $cadena); } $tableData = array(array("dato" => "<b>Nota:</b>\n" . utf8_decode($info_xtra->Consumo->notaAlPie)), array("dato" => "<b>Total con letra</b>\n" . trim($cadena))); $colNames = array("dato" => "<b>Cant</b>"); $colOptions = array("dato" => array('justification' => 'left', 'width' => 390)); $options = array('showLines' => 1, 'showHeadings' => 0, 'shaded' => 1, 'shadeCol' => array(0.9, 0.9, 0.9), 'fontSize' => 7, 'textCol' => array(0, 0, 0), 'rowGap' => 2.5, 'colGap' => 5, 'xPos' => 35, 'xOrientation' => 'right', 'width' => 120, 'cols' => $colOptions, 'innerLineThickness' => 0.3, 'outerLineThickness' => 0.3); // Dibuja la tabla cantidad con letra $pdf->ezSetDy(0); $pdf->ezTable($tableData, "", "", $options); ////////// i. Totales $f_importe = "\$" . number_format($comprobanteNode['subTotal'], 2); //$f_iva_T=$conceptoNode['totalImpuestosTrasladados']; $f_total = "\$" . number_format($comprobanteNode['total'], 2); $tableData = array(); $rowData = array("leyenda" => "", "cantidad" => ""); $subtotal = array("dato" => "Subtotal", "valor" => $f_importe); array_push($tableData, $subtotal); foreach ($traslados as $key => $trasladoNode) { if ($key === $trasladoTag . $attr) { $tasaImpuesto = array(); $tasaImpuesto_t = number_format($trasladoNode['tasa'], 0); $tasaImpuesto["dato"] = $trasladoNode['impuesto'] . " " . $tasaImpuesto_t . "%"; $tasaImpuesto["valor"] = "\$" . number_format($trasladoNode['importe'], 2); //array_push($tableData,$tasaImpuesto); } } if (!empty($retenciones)) { foreach ($retenciones as $key => $retencionNode) { if ($key === $retencionTag . $attr) { $tasaImpuesto = array(); $tasaImpuesto_t = number_format($retencionNode['tasa'], 2); $tasaImpuesto["dato"] = "Ret. " . $retencionNode['impuesto']; $tasaImpuesto["valor"] = "\$" . number_format($retencionNode['importe'], 2); //array_push($tableData,$tasaImpuesto); } } } //fin if empty $iva = array("dato" => "<b>IVA</b>", "valor" => "<b>\$ " . number_format($info_xtra->TotalImpuestosTrasladados, 2) . "</b>"); array_push($tableData, $iva); $total = array("dato" => "<b>Total</b>", "valor" => "<b>" . $f_total . "</b>"); array_push($tableData, $total); $colNames = array("dato" => "<b>Cant</b>", "valor" => "Importe"); $colOptions = array("dato" => array('justification' => 'right', 'width' => 55), "valor" => array('justification' => 'right', 'width' => 95)); $options = array('showLines' => 1, 'showHeadings' => 0, 'shaded' => 2, 'shadeCol' => array(1, 1, 1), 'shadeCol2' => array(91, 21, 0), 'fontSize' => 7, 'textCol' => array(0, 0, 0), 'rowGap' => 3, 'colGap' => 5, 'xPos' => 425, 'xOrientation' => 'right', 'width' => 120, 'cols' => $colOptions, 'innerLineThickness' => 0.3, 'outerLineThickness' => 0.3); // Dibuja la tabla totales $pdf->ezSetDy(42.5); $pdf->ezTable($tableData, $colNames, "", $options); $rfce = $row_empresa['rfc']; $rfcr = $receptorNode['rfc']; $total = $comprobanteNode['total']; $uuidsat = $row_factura['uuid']; $cadenaQRCode = sprintf("?re=%s&rr=%s&tt=%s&id=%s", $rfce, $rfcr, $total, $uuidsat); /*QR Code: Para usar qr_imgV2(): qr_imgV2(d,e,s,v,t); d= datos Cadena o datos a ser codificados. e= ECC level Puede ser L,M,Q,H (default M) s= module size Para imagen JPEG:8; para PNG:4 v= version 1-40 8 recomendado. t= image type "J":imagen jpeg, "P" o culaquier otra cosa: imagen PNG */ $img_filename = qr_imgV2($cadenaQRCode, "M", 8, 8, "J", $PATHQR); //v:7-13 8 parece adecuado. //$pdf->addJpegFromFile($img_filename,495,$pdf->y,90); //100 //$pdf->addJpegFromFile($img_filename,32,170,130); //100 $pdf->addJpegFromFile($img_filename, 32, $pdf->y - 140, 130); //100 unlink($img_filename); ////////// i. Sello if ($version === "3.2") { $tableData = array(array("dato" => "<b>Sello Digital del Emisor</b>\n" . $row_factura['sello']), array("dato" => "<b>Sello Digital del SAT</b>\n" . $row_factura['selloSAT'])); } else { $tableData = array(array("dato" => "<b>Sello Digital</b>\n" . $row_factura['sello'])); } $colNames = array("dato" => "<b>Cant</b>"); $colOptions = array("dato" => array('justification' => 'left', 'width' => 400)); $options = array('showLines' => 1, 'showHeadings' => 0, 'shaded' => 0, 'shadeCol' => array(0.8, 0.8, 0.8), 'fontSize' => 7, 'textCol' => array(0, 0, 0), 'rowGap' => 5, 'colGap' => 5, 'xPos' => 175, 'xOrientation' => 'right', 'width' => 120, 'cols' => $colOptions, 'innerLineThickness' => 0.3, 'outerLineThickness' => 0.3); // Dibuja la tabla sello $pdf->ezSetDy(-10); $pdf->ezTable($tableData, $colNames, "", $options); /*$pdf->setColor(91,21,0); $pdf->filledRectangle(30,167,134,151); $pdf->setColor(1,1,1); $pdf->filledRectangle(31,167.5,132.3,149.5);*/ ////////// i. Cadena original $columnaCadena = ""; if ($version === "3.2") { $columnaCadena = sprintf("||1.0|%s|%s|%s|%s||", $row_factura['uuid'], $row_factura['FechaTimbrado'], $row_factura['selloCFD'], $row_factura['noCertificadoSAT']); } else { $columnaCadena = sprintf("%s", $row_factura['cadena']); } $tableData = array(array("dato" => "<b>Cadena original del complemento de certificacion digital del SAT</b>\n" . $columnaCadena), array("dato" => "<b>Folio Fiscal</b>\n" . $row_factura['uuid'])); $colNames = array("dato" => "<b>Cant</b>"); $colOptions = array("dato" => array('justification' => 'left', 'width' => 400)); $options = array('showLines' => 1, 'showHeadings' => 0, 'shaded' => 0, 'shadeCol' => array(0.8, 0.8, 0.8), 'fontSize' => 7, 'textCol' => array(0, 0, 0), 'rowGap' => 5, 'colGap' => 5, 'xPos' => 175, 'xOrientation' => 'right', 'width' => 120, 'cols' => $colOptions, 'innerLineThickness' => 0.3, 'outerLineThickness' => 0.3); // Dibuja la tabla cadena original $pdf->ezSetDy(-5); $pdf->ezTable($tableData, $colNames, "", $options); // Leyendas $pdf->ezSetDy(-12); $leyendas = "ESTE DOCUMENTO ES UNA REPRESENTACION IMPRESA DE UN CFDI.\n"; $pdf->setColor(0.5, 0.5, 0.5); $pdf->ezText($leyendas, 5, array('left' => 50, 'justification' => 'center')); $pdf->setColor(0, 0, 0); $pdf->ezStream(array("filename" => $row_factura['folio'] . "_" . str_replace(" ", "-", $receptorNode['nombre']))); //Necesario para que funcione ezStartPageNumbers //REGRESA PARA PONER ENCABEZADO EN PAGINAS 2 -> if ($contadorPagina != $contadorTotalPaginas) { $pdf->ezNewPage(); $pdf->ezSetDy(-12); } $contadorPagina++; } //fin del foreach para la creacion del objeto pdf //ESCRIBE REPORTE AL ARCHIVO. //================================================================================ $pdfcode = $pdf->output(); error_log($tmpName); if ($tmpName === 2 || !$tmpName) { $tmpName = !$tmpName ? $tmpName : true; } else { exit($pdfcode); } //save the file if ($tmpName) { $nombrePDF = tempnam($tmp . "tmp/", 'face5') . ".pdf"; $nombreToks = explode("/", $nombrePDF); if (count($nombreToks) < 2) { $nombreToks = explode("\\", $nombrePDF); } $lastTok = count($nombreToks) - 1; $nombrePDF = $nombreToks[$lastTok]; $archivoPDF = $tmp . "tmp/" . $nombrePDF; $archivos = array($nombrePDF, $archivoPDF); error_log(print_R($archivos, true)); } else { $nombrePDF = $tipoDocto . "_" . $row_factura['serie'] . $row_factura['folio'] . ".pdf"; //$archivoPDF ="tmp/".$nombrePDF;//chs 20130705 $archivoPDF = $tmp . "tmp/" . $nombrePDF; $archivos = array($nombrePDF, $archivoPDF); error_log(2); ob_flush(); ob_clean(); } global $SITE_ROOT; error_log($archivoPDF); @file_put_contents($SITE_ROOT . "gui/" . $archivoPDF, $pdfcode); /*$fp = fopen($archivoPDF,'w+'); fwrite($fp,$pdfcode); fclose($fp);*/ return $archivos; }
function buildpdf() { @mkdir("/usr/share/artica-postfix/PDFs", 666, true); if ($GLOBALS["RCPT_TO"] == null) { echo "No recipient set...\n"; return; } if ($GLOBALS["OU"] == null) { echo "No organization set...\n"; return; } getSommaire(); sql_domain(); $date = date("Y-m-d"); $pdf = new Cezpdf('a4', 'portrait'); echo __FUNCTION__ . " Creating instance done...\n"; $pdf->ezSetMargins(50, 70, 50, 50); $all = $pdf->openObject(); $pdf->saveState(); //$pdf->setStrokeColor(0,0,0,1); $pdf->line(20, 40, 578, 40); $pdf->line(20, 822, 578, 822); $pdf->addText(50, 34, 6, $date); $pdf->restoreState(); $pdf->closeObject(); $pdf->addObject($all, 'all'); $mainFont = dirname(__FILE__) . "/ressources/fonts/Helvetica.afm"; $codeFont = dirname(__FILE__) . "/ressources/fonts/Courier.afm"; $pdf->selectFont($mainFont); $pdf->ezText("{$GLOBALS["OU"]}\n", 30, array('justification' => 'centre')); $pdf->ezText("Messaging report\n", 20, array('justification' => 'centre')); $pdf->ezText("{$date}", 18, array('justification' => 'centre')); $pdf->ezText(count($GLOBALS["OU-USERS"]) . " users", 18, array('justification' => 'centre')); $pdf->ezStartPageNumbers(100, 30, 12, "left", "Page {PAGENUM}/{TOTALPAGENUM}"); $pdf->ezNewPage(); $pdf->ezText("The report:", 28, array('justification' => 'left')); $pdf->ezText(""); $pdf->ezText("The current report is based on " . count($GLOBALS["mydomains"]) . " domains", 12, array('justification' => 'left')); $pdf->ezText("Including " . @implode(", ", $GLOBALS["mydomains"]) . " for the last {$GLOBALS["LAST_DAYS"]} days", 12, array('justification' => 'left')); $sql = "SELECT COUNT(bounce_error) as tcount,bounce_error FROM smtp_logs WHERE {$GLOBALS["SQL_DOMAINS"]} AND time_stamp>DATE_ADD(NOW(), INTERVAL -{$GLOBALS["LAST_DAYS"]} DAY) GROUP BY bounce_error"; $q = new mysql(); $results = $q->QUERY_SQL($sql, "artica_events"); while ($ligne = @mysql_fetch_array($results, MYSQL_ASSOC)) { $data[] = array($ligne["tcount"], $ligne["bounce_error"]); } $pdf->ezText(""); $title = "Global email status during the period"; // 005447 = 0,0.32,0.278 // CCCCCC = 0.8,0.8,0.8 $options = array('showLines' => 2, 'showHeadings' => 0, 'shaded' => 2, 'shadeCol' => array(1, 1, 1), 'shadeCol2' => array(0.8, 0.8, 0.8), 'fontSize' => 11, 'textCol' => array(0, 0, 0), 'textCol2' => array(1, 1, 1), 'titleFontSize' => 16, 'titleGap' => 8, 'rowGap' => 5, 'colGap' => 10, 'lineCol' => array(1, 1, 1), 'xPos' => 'left', 'xOrientation' => 'right', 'width' => 500, 'maxWidth' => 500); $pdf->ezTable($data, $cols, $title, $options); $file = FlowMessages(); $pdf->ezNewPage(); echo __FUNCTION__ . " image {$file}\n"; $pdf->ezImage("/usr/share/artica-postfix/PDFs/graph1.png", 5, 500, "none", 'left', 1); $pdf->ezText(""); $pdf->ezImage("/usr/share/artica-postfix/PDFs/graph2.png", 5, 500, "none", 'left', 1); $pdf->ezNewPage(); //---------------------------------------------------------------------------------------------------------- $sql = "SELECT COUNT( ID ) AS tcount,delivery_user\nFROM smtp_logs\nWHERE {$GLOBALS["SQL_DOMAINS"]}\nAND time_stamp > DATE_ADD( NOW( ) , INTERVAL -{$GLOBALS["LAST_DAYS"]}\nDAY )\nGROUP BY delivery_user ORDER BY tcount DESC LIMIT 0,10 "; $q = new mysql(); $results = $q->QUERY_SQL($sql, "artica_events"); echo $sql; unset($data); $data[] = array("nb", "recipients"); while ($ligne = @mysql_fetch_array($results, MYSQL_ASSOC)) { if ($ligne["delivery_user"] == null) { continue; } $data[] = array($ligne["tcount"], $ligne["delivery_user"]); } $title = "Most active users (recipients) during the period"; $options = array('showLines' => 2, 'showHeadings' => 0, 'shaded' => 2, 'shadeCol' => array(1, 1, 1), 'shadeCol2' => array(0.8, 0.8, 0.8), 'fontSize' => 11, 'textCol' => array(0, 0, 0), 'textCol2' => array(1, 1, 1), 'titleFontSize' => 16, 'titleGap' => 8, 'rowGap' => 5, 'colGap' => 10, 'lineCol' => array(1, 1, 1), 'xPos' => 'left', 'xOrientation' => 'right', 'width' => 500, 'maxWidth' => 500); $pdf->ezTable($data, $cols, $title, $options); //---------------------------------------------------------------------------------------------------------- $pdf->ezText("\n"); //---------------------------------------------------------------------------------------------------------- $sql = "SELECT COUNT( ID ) AS tcount,sender_user\nFROM smtp_logs\nWHERE {$GLOBALS["SQL_OUT_DOMAINS"]}\nAND time_stamp > DATE_ADD( NOW( ) , INTERVAL -{$GLOBALS["LAST_DAYS"]}\nDAY )\nGROUP BY sender_user ORDER BY tcount DESC LIMIT 0,10 "; $q = new mysql(); $results = $q->QUERY_SQL($sql, "artica_events"); echo $sql; unset($data); $data[] = array("nb", "senders"); while ($ligne = @mysql_fetch_array($results, MYSQL_ASSOC)) { if ($ligne["sender_user"] == null) { continue; } $data[] = array($ligne["tcount"], $ligne["sender_user"]); } $title = "Most active users (senders) during the period"; $options = array('showLines' => 2, 'showHeadings' => 0, 'shaded' => 2, 'shadeCol' => array(1, 1, 1), 'shadeCol2' => array(0.8, 0.8, 0.8), 'fontSize' => 11, 'textCol' => array(0, 0, 0), 'textCol2' => array(1, 1, 1), 'titleFontSize' => 16, 'titleGap' => 8, 'rowGap' => 5, 'colGap' => 10, 'lineCol' => array(1, 1, 1), 'xPos' => 'left', 'xOrientation' => 'right', 'width' => 500, 'maxWidth' => 500); $pdf->ezTable($data, $cols, $title, $options); //---------------------------------------------------------------------------------------------------------- $pdf->ezNewPage(); //---------------------------------------------------------------------------------------------------------- $sql = "SELECT COUNT( ID ) AS tcount,sender_user\nFROM smtp_logs\nWHERE {$GLOBALS["SQL_DOMAINS"]}\nAND time_stamp > DATE_ADD( NOW( ) , INTERVAL -{$GLOBALS["LAST_DAYS"]}\nDAY )\nGROUP BY sender_user ORDER BY tcount DESC LIMIT 0,32 "; $q = new mysql(); $results = $q->QUERY_SQL($sql, "artica_events"); echo $sql; unset($data); $data[] = array("nb", "Internet senders"); while ($ligne = @mysql_fetch_array($results, MYSQL_ASSOC)) { if ($ligne["sender_user"] == null) { continue; } $data[] = array($ligne["tcount"], $ligne["sender_user"]); } $title = "Most active sender internet users during the period"; $options = array('showLines' => 2, 'showHeadings' => 0, 'shaded' => 2, 'shadeCol' => array(1, 1, 1), 'shadeCol2' => array(0.8, 0.8, 0.8), 'fontSize' => 10, 'textCol' => array(0, 0, 0), 'textCol2' => array(1, 1, 1), 'titleFontSize' => 16, 'titleGap' => 8, 'rowGap' => 5, 'colGap' => 10, 'lineCol' => array(1, 1, 1), 'xPos' => 'left', 'xOrientation' => 'right', 'width' => 500, 'maxWidth' => 500); $pdf->ezTable($data, $cols, $title, $options); //---------------------------------------------------------------------------------------------------------- $pdf->ezNewPage(); //---------------------------------------------------------------------------------------------------------- $sql = "SELECT COUNT( ID ) AS tcount,delivery_user\nFROM smtp_logs\nWHERE {$GLOBALS["SQL_OUT_DOMAINS"]}\nAND time_stamp > DATE_ADD( NOW( ) , INTERVAL -{$GLOBALS["LAST_DAYS"]}\nDAY )\nGROUP BY delivery_user ORDER BY tcount DESC LIMIT 0,32 "; $q = new mysql(); $results = $q->QUERY_SQL($sql, "artica_events"); echo $sql; unset($data); $data[] = array("nb", "Internet recipients"); while ($ligne = @mysql_fetch_array($results, MYSQL_ASSOC)) { if ($ligne["delivery_user"] == null) { continue; } $data[] = array($ligne["tcount"], $ligne["delivery_user"]); } $title = "Most active internet recipients during the period"; $options = array('showLines' => 2, 'showHeadings' => 0, 'shaded' => 2, 'shadeCol' => array(1, 1, 1), 'shadeCol2' => array(0.8, 0.8, 0.8), 'fontSize' => 10, 'textCol' => array(0, 0, 0), 'textCol2' => array(1, 1, 1), 'titleFontSize' => 16, 'titleGap' => 8, 'rowGap' => 5, 'colGap' => 10, 'lineCol' => array(1, 1, 1), 'xPos' => 'left', 'xOrientation' => 'right', 'width' => 500, 'maxWidth' => 500); $pdf->ezTable($data, $cols, $title, $options); //---------------------------------------------------------------------------------------------------------- $pdf->ezNewPage(); //----------------------------------------------------------------------------------------------------------; $pdf->ezText("Per users report", 28, array('justification' => 'center')); $pdf->ezText(""); $pdf->ezText(count($GLOBALS["OU-USERS"]) . " users detailed report", 18, array('justification' => 'center')); //---------------------------------------------------------------------------------------------------------- $pdf->ezNewPage(); //----------------------------------------------------------------------------------------------------------; while (list($uid) = each($GLOBALS["OU-USERS"])) { $u = new user($uid); $displayname = $u->DisplayName; echo "Generate report for {$u->uid}\n"; $pdf->ezText("{$displayname}", 22, array('justification' => 'left')); $pdf->ezText(""); $pdf->ezText("The current report is based on " . count($u->HASH_ALL_MAILS) . " email addresses", 10, array('justification' => 'left')); $pdf->ezText("Including " . @implode(", ", $u->HASH_ALL_MAILS) . " mails", 10, array('justification' => 'left')); $pdf->ezText("\n"); FlowMessages_users($uid, $u->HASH_ALL_MAILS); if (is_file("/usr/share/artica-postfix/PDFs/{$uid}-inbound.png")) { $pdf->ezImage("/usr/share/artica-postfix/PDFs/{$uid}-inbound.png", 5, 500, "none", 'left', 1); $pdf->ezText(""); } if (is_file("/usr/share/artica-postfix/PDFs/{$uid}-outbound.png")) { $pdf->ezImage("/usr/share/artica-postfix/PDFs/{$uid}-outbound.png", 5, 500, "none", 'left', 1); $pdf->ezText(""); } if (is_array($GLOBALS[$uid]["RECEIVE"])) { $title = "Most Internet senders for {$displayname} during the period"; $options = array('showLines' => 2, 'showHeadings' => 0, 'shaded' => 2, 'shadeCol' => array(1, 1, 1), 'shadeCol2' => array(0.8, 0.8, 0.8), 'fontSize' => 11, 'textCol' => array(0, 0, 0), 'textCol2' => array(1, 1, 1), 'titleFontSize' => 16, 'titleGap' => 8, 'rowGap' => 5, 'colGap' => 10, 'lineCol' => array(1, 1, 1), 'xPos' => 'left', 'xOrientation' => 'right', 'width' => 500, 'maxWidth' => 500); $pdf->ezTable($GLOBALS[$uid]["RECEIVE"], $cols, $title, $options); } if (is_array($GLOBALS[$uid]["SENT"])) { $title = "Most Internet recipients for {$displayname} during the period"; $options = array('showLines' => 2, 'showHeadings' => 0, 'shaded' => 2, 'shadeCol' => array(1, 1, 1), 'shadeCol2' => array(0.8, 0.8, 0.8), 'fontSize' => 11, 'textCol' => array(0, 0, 0), 'textCol2' => array(1, 1, 1), 'titleFontSize' => 16, 'titleGap' => 8, 'rowGap' => 5, 'colGap' => 10, 'lineCol' => array(1, 1, 1), 'xPos' => 'left', 'xOrientation' => 'right', 'width' => 500, 'maxWidth' => 500); $pdf->ezTable($GLOBALS[$uid]["SENT"], $cols, $title, $options); } $pdf->ezNewPage(); } $pdfcode = $pdf->output(); $fname = "/usr/share/artica-postfix/PDFs/report-director-{$GLOBALS["OU"]}.pdf"; if ($GLOBALS["VERBOSE"]) { echo "{$pdf->messages}\nbuilding {$fname}\n"; } @unlink($fname); if ($GLOBALS["VERBOSE"]) { echo "Building {$fname}\n"; } $fp = fopen($fname, 'w'); fwrite($fp, $pdfcode); fclose($fp); $users = new usersMenus(); send_email_events("[ARTICA]: ({$users->hostname}) {$GLOBALS["OU"]}:: weekly report sended to {$GLOBALS["RCPT_TO"]}", "", "mailbox", date('Y-m-d H:i:s'), array($fname), $GLOBALS["RCPT_TO"]); if ($GLOBALS["VERBOSE"]) { echo "Sending mail\n"; } SendMailNotif("you will find in attached file the weekly report of your {$users->hostname} mail server", "[ARTICA]: ({$users->hostname}) {$GLOBALS["OU"]}:: weekly messaging report", null, $GLOBALS["RCPT_TO"], $GLOBALS["VERBOSE"], array($fname)); }