<?php define('FPDF_FONTPATH', 'fpdf/font/'); require 'mc_table.php'; $pdf = new PDF_MC_Table('P', 'cm', "Legal"); $pdf->Open(); $pdf->AddPage(); $pdf->AliasNbPages(); $pdf->SetMargins(1, 1, 1); $pdf->SetFont('times', 'B', 12); $pdf->Cell(0, 0.9, 'Laporan Barang', 0, 0, 'C'); $pdf->Ln(); $tgl = date('Y-m-d'); $pdf->SetFont('times', 'B', 8); $pdf->SetFont('times', 'B', 10); $pdf->SetWidths(array(1, 8, 1.8, 2.1)); $pdf->SetHeight(0.1); $pdf->Row(array("NO", "NAMA", "SATUAN", "STOK")); $pdf->SetFont('times', '', 10); $pdf->Row(array("1", "Buku Tulis Matematika Kualitas ABCD Kiki 80 gram 1 Lusin ", "Lusin", "100")); $pdf->Output(); ?>
public function generar_pdf($archivo = FALSE) { ///// INICIO - Factura Detallada /// Creamos el PDF y escribimos sus metadatos ob_end_clean(); $pdf_doc = new PDF_MC_Table('P', 'mm', 'A4'); define('EEURO', chr(128)); $lineas = $this->factura->get_lineas(); if ($this->impresion['print_dto']) { $this->impresion['print_dto'] = FALSE; /// leemos las líneas para ver si de verdad mostramos los descuentos foreach ($lineas as $lin) { if ($lin->dtopor != 0) { $this->impresion['print_dto'] = TRUE; break; } } } $pdf_doc->SetTitle('Factura: ' . $this->factura->codigo . " " . $this->factura->numero2); $pdf_doc->SetSubject('Factura del cliente: ' . $this->factura->nombrecliente); $pdf_doc->SetAuthor($this->empresa->nombre); $pdf_doc->SetCreator('FacturaSctipts V_' . $this->version()); $pdf_doc->Open(); $pdf_doc->AliasNbPages(); $pdf_doc->SetAutoPageBreak(true, 40); // Definimos el color de relleno (gris, rojo, verde, azul) $pdf_doc->SetColorRelleno('azul'); /// Definimos todos los datos de la cabecera de la factura /// Datos de la empresa $pdf_doc->fde_nombre = $this->empresa->nombre; $pdf_doc->fde_FS_CIFNIF = FS_CIFNIF; $pdf_doc->fde_cifnif = $this->empresa->cifnif; $pdf_doc->fde_direccion = $this->empresa->direccion; $pdf_doc->fde_codpostal = $this->empresa->codpostal; $pdf_doc->fde_ciudad = $this->empresa->ciudad; $pdf_doc->fde_provincia = $this->empresa->provincia; $pdf_doc->fde_telefono = 'Teléfono: ' . $this->empresa->telefono; $pdf_doc->fde_fax = 'Fax: ' . $this->empresa->fax; $pdf_doc->fde_email = $this->empresa->email; $pdf_doc->fde_web = $this->empresa->web; $pdf_doc->fde_piefactura = $this->empresa->pie_factura; /// Insertamos el Logo y Marca de Agua if (file_exists('tmp/' . FS_TMP_NAME . 'logo.png') or file_exists('tmp/' . FS_TMP_NAME . 'logo.jpg')) { $pdf_doc->fdf_verlogotipo = '1'; // 1/0 --> Mostrar Logotipo $pdf_doc->fdf_Xlogotipo = '15'; // Valor X para Logotipo $pdf_doc->fdf_Ylogotipo = '35'; // Valor Y para Logotipo $pdf_doc->fdf_vermarcaagua = '1'; // 1/0 --> Mostrar Marca de Agua $pdf_doc->fdf_Xmarcaagua = '25'; // Valor X para Marca de Agua $pdf_doc->fdf_Ymarcaagua = '110'; // Valor Y para Marca de Agua } else { $pdf_doc->fdf_verlogotipo = '0'; $pdf_doc->fdf_Xlogotipo = '0'; $pdf_doc->fdf_Ylogotipo = '0'; $pdf_doc->fdf_vermarcaagua = '0'; $pdf_doc->fdf_Xmarcaagua = '0'; $pdf_doc->fdf_Ymarcaagua = '0'; } // Tipo de Documento $pdf_doc->fdf_tipodocumento = 'FACTURA'; // (FACTURA, FACTURA PROFORMA, ¿ALBARAN, PRESUPUESTO?...) $pdf_doc->fdf_codigo = $this->factura->codigo . " " . $this->factura->numero2; // Fecha, Codigo Cliente y observaciones de la factura $pdf_doc->fdf_fecha = $this->factura->fecha; $pdf_doc->fdf_codcliente = $this->factura->codcliente; $pdf_doc->fdf_observaciones = iconv("UTF-8", "CP1252", $this->fix_html($this->factura->observaciones)); // Datos del Cliente $pdf_doc->fdf_nombrecliente = $this->fix_html($this->factura->nombrecliente); $pdf_doc->fdf_FS_CIFNIF = FS_CIFNIF; $pdf_doc->fdf_cifnif = $this->factura->cifnif; $pdf_doc->fdf_direccion = $this->fix_html($this->factura->direccion); $pdf_doc->fdf_codpostal = $this->factura->codpostal; $pdf_doc->fdf_ciudad = $this->factura->ciudad; $pdf_doc->fdf_provincia = $this->factura->provincia; $pdf_doc->fdc_telefono1 = $this->cliente->telefono1; $pdf_doc->fdc_telefono2 = $this->cliente->telefono2; $pdf_doc->fdc_fax = $this->cliente->fax; $pdf_doc->fdc_email = $this->cliente->email; $pdf_doc->fdf_epago = $pdf_doc->fdf_divisa = $pdf_doc->fdf_pais = ''; // Forma de Pago de la Factura $pago = new forma_pago(); $epago = $pago->get($this->factura->codpago); if ($epago) { $pdf_doc->fdf_epago = $epago->descripcion; } // Divisa de la Factura $divisa = new divisa(); $edivisa = $divisa->get($this->factura->coddivisa); if ($edivisa) { $pdf_doc->fdf_divisa = $edivisa->descripcion; } // Pais de la Factura $pais = new pais(); $epais = $pais->get($this->factura->codpais); if ($epais) { $pdf_doc->fdf_pais = $epais->nombre; } // Cabecera Titulos Columnas if ($this->impresion['print_dto']) { $pdf_doc->Setdatoscab(array('ALB', 'DESCRIPCION', 'CANT', 'PRECIO', 'DTO', FS_IVA, 'IMPORTE')); $pdf_doc->SetWidths(array(16, 102, 10, 20, 10, 10, 22)); $pdf_doc->SetAligns(array('C', 'L', 'R', 'R', 'R', 'R', 'R')); $pdf_doc->SetColors(array('6|47|109', '6|47|109', '6|47|109', '6|47|109', '6|47|109', '6|47|109', '6|47|109')); } else { $pdf_doc->Setdatoscab(array('ALB', 'DESCRIPCION', 'CANT', 'PRECIO', FS_IVA, 'IMPORTE')); $pdf_doc->SetWidths(array(16, 107, 10, 20, 15, 22)); $pdf_doc->SetAligns(array('C', 'L', 'R', 'R', 'R', 'R')); $pdf_doc->SetColors(array('6|47|109', '6|47|109', '6|47|109', '6|47|109', '6|47|109', '6|47|109')); } /// Definimos todos los datos del PIE de la factura /// Lineas de IVA $lineas_iva = $this->factura->get_lineas_iva(); if (count($lineas_iva) > 3) { $pdf_doc->fdf_lineasiva = $lineas_iva; } else { $filaiva = array(); $i = 0; foreach ($lineas_iva as $li) { $i++; $filaiva[$i][0] = $li->iva ? FS_IVA . $li->iva : ''; $filaiva[$i][1] = $li->neto ? $this->ckeckEuro($li->neto) : ''; $filaiva[$i][2] = $li->iva ? $li->iva . "%" : ''; $filaiva[$i][3] = $li->totaliva ? $this->ckeckEuro($li->totaliva) : ''; $filaiva[$i][4] = $li->recargo ? $li->recargo . "%" : ''; $filaiva[$i][5] = $li->totalrecargo ? $this->ckeckEuro($li->totalrecargo) : ''; $filaiva[$i][6] = ''; //// POR CREARRRRRR $filaiva[$i][7] = ''; //// POR CREARRRRRR $filaiva[$i][8] = $li->totallinea ? $this->ckeckEuro($li->totallinea) : ''; } if ($filaiva) { $filaiva[1][6] = $this->factura->irpf . ' %'; $filaiva[1][7] = $this->ckeckEuro(0 - $this->factura->totalirpf); } $pdf_doc->fdf_lineasiva = $filaiva; } // Total factura numerico $pdf_doc->fdf_numtotal = $this->ckeckEuro($this->factura->total); // Total factura numeros a texto $pdf_doc->fdf_textotal = $this->factura->total; /// Agregamos la pagina inicial de la factura $pdf_doc->AddPage(); // Lineas de la Factura //$lineas = $this->factura->get_lineas(); if ($lineas) { $neto = 0; for ($i = 0; $i < count($lineas); $i++) { $neto += $lineas[$i]->pvptotal; $pdf_doc->neto = $this->ckeckEuro($neto); $articulo = new articulo(); $art = $articulo->get($lineas[$i]->referencia); if ($art) { $observa = "\n" . utf8_decode($this->fix_html($art->observaciones)); } else { // $observa = null; // No mostrar mensaje de error $observa = "\n"; } if ($this->impresion['print_dto']) { $lafila = array('0' => utf8_decode($lineas[$i]->albaran_numero()), '1' => utf8_decode(strtoupper($lineas[$i]->descripcion)) . $observa, '2' => utf8_decode($lineas[$i]->cantidad), '3' => $this->ckeckEuro($lineas[$i]->pvpunitario), '4' => utf8_decode($this->show_numero($lineas[$i]->dtopor, 0) . " %"), '5' => utf8_decode($this->show_numero($lineas[$i]->iva, 0) . " %"), '6' => $this->ckeckEuro($lineas[$i]->total_iva())); } else { $lafila = array('0' => utf8_decode($lineas[$i]->albaran_numero()), '1' => utf8_decode(strtoupper($lineas[$i]->descripcion)) . $observa, '2' => utf8_decode($lineas[$i]->cantidad), '3' => $this->ckeckEuro($lineas[$i]->pvpunitario), '4' => utf8_decode($this->show_numero($lineas[$i]->iva, 0) . " %"), '5' => $this->ckeckEuro($lineas[$i]->total_iva())); } $pdf_doc->Row($lafila, '1'); // Row(array, Descripcion del Articulo -- ultimo valor a imprimir) } $pdf_doc->piepagina = true; } // Damos salida al archivo PDF if ($archivo) { if (!file_exists('tmp/' . FS_TMP_NAME . 'enviar')) { mkdir('tmp/' . FS_TMP_NAME . 'enviar'); } $pdf_doc->Output('tmp/' . FS_TMP_NAME . 'enviar/' . $archivo, 'F'); } else { $pdf_doc->Output(); } }
function search_pdf($VAR, $construct, $type) { # include fpdf class: include_once PATH_CORE . 'fpdf.inc.php'; # set the field list for this method: $arr = $construct->method["{$type}"]; # loop through the field list to create the sql queries $field_list = ''; $heading_list = ''; $width_list = ''; $i = 0; while (list($key, $value) = each($arr)) { if ($i == 0) { $field_var = $construct->table . '_' . $value; $field_list .= $value; $heading_list .= strtoupper($value); // <- translate $width_list .= $construct->field[$value]['pdf_width']; } else { $field_var = $construct->table . '_' . $value; $field_list .= "," . $value; $heading_list .= "," . strtoupper($value); // <- translate $width_list .= "," . $construct->field[$value]['pdf_width']; } $i++; } # start the new PDF class... $pdf = new PDF_MC_Table(); $pdf->Open(); $pdf->AddPage(); # Determine the number of columns and width for each one... $SetWidths = explode(",", $width_list); $pdf->SetWidths($SetWidths); # Define the table heading $TableHeading = explode(",", $heading_list); # Define the Properties for the table heading cells: # set the font: $pdf->HeadFontFamily = "Arial"; $pdf->HeadFontStyle = "BI"; $pdf->HeadFontSize = 8; # set the font color: $pdf->HeadTextColor1 = 255; $pdf->HeadTextColor2 = 255; $pdf->HeadTextColor3 = 255; # set the bg color: $pdf->HeadFillColor1 = 90; $pdf->HeadFillColor2 = 90; $pdf->HeadFillColor3 = 90; # set the hieght $pdf->HeadHeight = 6; # Print the Heading: $pdf->HeadRow($TableHeading); # Define the row settings for the rest of the cells... # define the font settings $pdf->SetFontFamily = "Arial"; $pdf->SetFontStyle = ""; $pdf->SetFontSize = "7"; # set the hieght $pdf->RowHeight = 4; /************** BEGIN STANDARD EXPORT SEARCH CODE *********************/ # set the field list for this method: $arr = $construct->method["{$type}"]; # loop through the field list to create the sql queries $arr = $construct->method[$type]; $field_list = ''; $i = 0; while (list($key, $value) = each($arr)) { if ($i == 0) { $field_var = $construct->table . '_' . $value; $field_list .= AGILE_DB_PREFIX . $construct->table . '.' . $value; // determine if this record is linked to another table/field if ($construct->field[$value]["asso_table"] != "") { $this->linked[] = array('field' => $value, 'link_table' => $construct->field[$value]["asso_table"], 'link_field' => $construct->field[$value]["asso_field"]); } } else { $field_var = $construct->table . '_' . $value; $field_list .= "," . AGILE_DB_PREFIX . $construct->table . "." . $value; // determine if this record is linked to another table/field if ($construct->field[$value]["asso_table"] != "") { $this->linked[] = array('field' => $value, 'link_table' => $construct->field[$value]["asso_table"], 'link_field' => $construct->field[$value]["asso_field"]); } } $i++; } # get the search details: if (isset($VAR['search_id'])) { include_once PATH_CORE . 'search.inc.php'; $search = new CORE_search(); $search->get($VAR['search_id']); } else { echo '<BR> The search terms submitted were invalid!'; } # get the sort order details: if (isset($VAR['order_by']) && $VAR['order_by'] != "") { $order_by = ' ORDER BY ' . AGILE_DB_PREFIX . $construct->table . '.' . $VAR['order_by']; $smarty_order = $VAR['order_by']; } else { $order_by = ' ORDER BY ' . AGILE_DB_PREFIX . $construct->table . '.' . $construct->order_by; $smarty_order = $search->order_by; } # format saved search string $sql = explode(" WHERE ", $search->sql); # generate the full query $q = preg_replace("/%%fieldList%%/i", $field_list, $search->sql); $q = preg_replace("/%%tableList%%/i", AGILE_DB_PREFIX . $construct->table, $q); $q = preg_replace("/%%whereList%%/i", "", $q); $q .= " " . AGILE_DB_PREFIX . $construct->table . ".site_id = '" . DEFAULT_SITE . "'"; $q .= $order_by; $db =& DB(); $result = $db->Execute($q); # error reporting if ($result === false) { global $C_debug; $C_debug->error('core:export.inc.php', 'search_xml', $db->ErrorMsg() . '<br><br>' . $q); echo "An SQL error has occured!"; return; } # put the results into an array $i = 0; $class_name = TRUE; $results = ''; while (!$result->EOF) { $results[$i] = $result->fields; $result->MoveNext(); $i++; } # get any linked fields if ($i > 0) { $this->result = $results; $db_join = new CORE_database(); $this->result = $db_join->join_fields($results, $this->linked); } else { $this->result = $results; } /************** END STANDARD EXPORT SEARCH CODE *********************/ # LOOP THROUGH THE RESULTS & DISPLAY AS PDF $results = $result->RecordCount(); $BackAlt = TRUE; while (!$result->EOF) { # get the data for each cell: reset($arr); $CurrRow = ''; $i = 0; while (list($key, $value) = each($arr)) { if ($i == 0) { $CurrRow .= $result->fields["{$key}"]; } else { $CurrRow .= "::" . $result->fields["{$key}"]; } $i++; } $ThisRow = explode("::", $CurrRow); # set the colors & fonts if ($BackAlt) { # alternating row 1: $pdf->SetTextColorVar1 = "50"; $pdf->SetTextColorVar2 = "50"; $pdf->SetTextColorVar3 = "50"; $pdf->SetFillColorVar1 = 255; $pdf->SetFillColorVar2 = 255; $pdf->SetFillColorVar3 = 255; $BackAlt = FALSE; } else { # alternating row 2: $pdf->SetTextColorVar1 = "0"; $pdf->SetTextColorVar2 = "0"; $pdf->SetTextColorVar3 = "0"; $pdf->SetFillColorVar1 = 240; $pdf->SetFillColorVar2 = 240; $pdf->SetFillColorVar3 = 240; $BackAlt = TRUE; } # check for needed page break $nb = 0; for ($ii = 0; $ii < count($dataarr); $ii++) { $nb = max($nb, $pdf->NbLines($pdf->widths[$ii], $dataarr[$ii])); } $h = 5 * $nb; # Issue a page break first if needed if ($pdf->CheckPageBreak($h)) { # print the Table Heading again $pdf->HeadRow($TableHeading); } $pdf->Row($ThisRow); # Next record $result->MoveNext(); } # Dispay the output $pdf->Output(); exit; }
/** * Init function */ function __construct($json) { require 'mc_table.php'; parent::__construct($json); // Get Config $conf = isset($_SESSION['pluginsConfig']) && isset($_SESSION['pluginsConfig']['export']) && isset($_SESSION['pluginsConfig']['export']['PDF']) ? $_SESSION['pluginsConfig']['export'] : array('PDF' => array()); $defaultFont = isset($conf['PDF']['defaultFont']) ? $conf['PDF']['defaultFont'] : 'FreeSans'; $defaultFontSize = isset($conf['PDF']['defaultFontSize']) ? $conf['PDF']['defaultFontSize'] : 9; $headerFont = isset($conf['PDF']['headerFont']) ? $conf['PDF']['headerFont'] : $defaultFont; $headerFontSize = isset($conf['PDF']['headerFontSize']) ? $conf['PDF']['headerFontSize'] : $defaultFontSize; $headerFontStyle = isset($conf['PDF']['headerFontStyle']) ? $conf['PDF']['headerFontStyle'] : ''; $layerFont = isset($conf['PDF']['layerFont']) ? $conf['PDF']['layerFont'] : $defaultFont; $layerFontSize = isset($conf['PDF']['layerFontSize']) ? $conf['PDF']['layerFontSize'] : $defaultFontSize; $layerFontStyle = isset($conf['PDF']['layerFontStyle']) ? $conf['PDF']['layerFontStyle'] : ''; // Write to table $pdf = new PDF_MC_Table(); // only for tcpdf version >= 3 // - font not well defined --> errors // - header and footer printed = lines on top and bottom $pdf->setPrintHeader(false); $pdf->setPrintFooter(false); $pdf->Open(); $groups = (array) $this->jsonList[0]; foreach ($groups as $grp) { $ret = $this->prepareData4PDF($grp); $colsPerc = $ret[0]; $data = $ret[1]; $header = $data['header']; $records = $data['records']; $pdfW = 180; // orientation detection $orientation = 'P'; $colsum = $ret[2]; $maxSize = max($headerFontSize, $defaultFontSize); $widthTmp = $colsum * $maxSize / 4; if ($widthTmp > 1.5 * $pdfW) { $pdfW = 270; $orientation = 'L'; } $pdf->AddPage($orientation); $cols = array(); foreach ($colsPerc as $cp) { $cols[] = $cp * $pdfW; } // add group name: $pdf->SetFont($layerFont, $layerFontStyle, $layerFontSize); $x = $pdf->GetX(); $y = $pdf->GetY(); $pdf->Cell(0, 0, $grp->description); $pdf->SetXY($x, $y + 9); // Calculate column widths $pdf->SetWidths($cols); // Add header $pdf->SetFont($headerFont, $headerFontStyle, $headerFontSize); $pdf->Row($header); // Add records $pdf->SetFont($defaultFont, '', $defaultFontSize); foreach ($records as $row) { $pdf->Row($row); } } $pdfFilePath = $this->tempFilePath . '.pdf'; $this->tempFileLocation .= '.pdf'; $pdf->Output($pdfFilePath, 'F'); }