private function generar_pdf_factura($tipo = 'simple', $archivo = FALSE) { if (!$archivo) { /// desactivamos la plantilla HTML $this->template = FALSE; } /// Creamos el PDF y escribimos sus metadatos $pdf_doc = new fs_pdf(); $pdf_doc->pdf->addInfo('Title', ucfirst(FS_FACTURA) . ' ' . $this->factura->codigo); $pdf_doc->pdf->addInfo('Subject', ucfirst(FS_FACTURA) . ' ' . $this->factura->codigo); $pdf_doc->pdf->addInfo('Author', $this->empresa->nombre); $lineas = $this->factura->get_lineas(); $lineas_iva = $this->factura->get_lineas_iva(); if ($lineas) { $lineasfact = count($lineas); $linea_actual = 0; $pagina = 1; // Imprimimos las páginas necesarias while ($linea_actual < $lineasfact) { $lppag = 35; /// líneas por página /// salto de página if ($linea_actual > 0) { $pdf_doc->pdf->ezNewPage(); } /* * Creamos la cabecera de la página, en este caso para el modelo carta */ if ($tipo == 'carta') { $direccion = $this->factura->nombrecliente . "\n" . $this->factura->direccion; if ($this->factura->codpostal and $this->factura->ciudad) { $direccion .= "\n CP: " . $this->factura->codpostal . ' ' . $this->factura->ciudad; } else { if ($this->factura->ciudad) { $direccion .= "\n" . $this->factura->ciudad; } } if ($this->factura->provincia) { $direccion .= "\n(" . $this->factura->provincia . ")"; } $pdf_doc->pdf->ezText("\n\n", 10); $pdf_doc->new_table(); $pdf_doc->add_table_row(array('campos' => "<b>" . ucfirst(FS_FACTURA) . ":</b>\n<b>Fecha:</b>\n<b>" . FS_CIFNIF . ":</b>", 'factura' => $this->factura->codigo . "\n" . $this->factura->fecha . "\n" . $this->factura->cifnif, 'cliente' => $this->fix_html($direccion))); $pdf_doc->save_table(array('cols' => array('campos' => array('justification' => 'right', 'width' => 100), 'factura' => array('justification' => 'left'), 'cliente' => array('justification' => 'right')), 'showLines' => 0, 'width' => 520)); $pdf_doc->pdf->ezText("\n\n\n", 14); } else { /// ¿Añadimos el logo? if (file_exists('tmp/' . FS_TMP_NAME . 'logo.png')) { if (function_exists('imagecreatefromstring')) { $pdf_doc->pdf->ezImage('tmp/' . FS_TMP_NAME . 'logo.png', 0, 200, 'none'); $lppag -= 2; /// si metemos el logo, caben menos líneas } else { die('ERROR: no se encuentra la función imagecreatefromstring(). ' . 'Y por tanto no se puede usar el logotipo en los documentos.'); } } else { $pdf_doc->pdf->ezText("<b>" . $this->empresa->nombre . "</b>", 16, array('justification' => 'center')); $pdf_doc->pdf->ezText(FS_CIFNIF . ": " . $this->empresa->cifnif, 8, array('justification' => 'center')); $direccion = $this->empresa->direccion; if ($this->empresa->codpostal) { $direccion .= ' - ' . $this->empresa->codpostal; } if ($this->empresa->ciudad) { $direccion .= ' - ' . $this->empresa->ciudad; } if ($this->empresa->provincia) { $direccion .= ' (' . $this->empresa->provincia . ')'; } if ($this->empresa->telefono) { $direccion .= ' - Teléfono: ' . $this->empresa->telefono; } $pdf_doc->pdf->ezText($this->fix_html($direccion), 9, array('justification' => 'center')); } /* * Esta es la tabla con los datos del cliente: * Factura: Fecha: * Cliente: CIF/NIF: * Dirección: Teléfonos: */ $pdf_doc->new_table(); $pdf_doc->add_table_row(array('campo1' => "<b>" . ucfirst(FS_FACTURA) . ":</b>", 'dato1' => $this->factura->codigo, 'campo2' => "<b>Fecha:</b>", 'dato2' => $this->factura->fecha)); $pdf_doc->add_table_row(array('campo1' => "<b>Cliente:</b>", 'dato1' => $this->fix_html($this->factura->nombrecliente), 'campo2' => "<b>" . FS_CIFNIF . ":</b>", 'dato2' => $this->factura->cifnif)); $pdf_doc->add_table_row(array('campo1' => "<b>Dirección:</b>", 'dato1' => $this->factura->direccion . ' CP: ' . $this->factura->codpostal . ' - ' . $this->factura->ciudad . ' (' . $this->factura->provincia . ')', 'campo2' => "<b>Teléfonos:</b>", 'dato2' => $this->cliente->telefono1 . ' ' . $this->cliente->telefono2)); $pdf_doc->save_table(array('cols' => array('campo1' => array('justification' => 'right'), 'dato1' => array('justification' => 'left'), 'campo2' => array('justification' => 'right'), 'dato2' => array('justification' => 'left')), 'showLines' => 0, 'width' => 520, 'shaded' => 0)); $pdf_doc->pdf->ezText("\n", 10); /// en el tipo 'firma' caben menos líneas if ($tipo == 'firma') { $lppag -= 3; } } /* * Creamos la tabla con las lineas de la factura: * * Descripción Cantidad PVP DTO Importe */ $columnas = array('alb' => '<b>' . ucfirst(FS_ALBARAN) . '</b>', 'descripcion' => '<b>Descripción</b>', 'cantidad' => '<b>Cantidad</b>', 'pvp' => '<b>PVP</b>', 'dto' => '<b>DTO</b>', 'importe' => '<b>Importe</b>'); if (!$this->impresion['print_alb']) { unset($columnas['alb']); } if (!$this->impresion['print_dto']) { unset($columnas['dto']); } $pdf_doc->new_table(); $pdf_doc->add_table_header($columnas); for ($i = $linea_actual; $linea_actual < $lppag + $i and $linea_actual < $lineasfact;) { $descripcion = $this->fix_html($lineas[$linea_actual]->descripcion); if ($this->impresion['print_ref'] and !is_null($lineas[$linea_actual]->referencia)) { $descripcion = '<b>' . $lineas[$linea_actual]->referencia . '</b> ' . $descripcion; } $fila = array('alb' => $lineas[$linea_actual]->albaran_numero(), 'descripcion' => $descripcion, 'cantidad' => $lineas[$linea_actual]->cantidad, 'pvp' => $this->show_precio($lineas[$linea_actual]->pvpunitario, $this->factura->coddivisa), 'dto' => $this->show_numero($lineas[$linea_actual]->dtopor, 0) . " %", 'importe' => $this->show_precio($lineas[$linea_actual]->pvptotal, $this->factura->coddivisa)); $pdf_doc->add_table_row($fila); $linea_actual++; } $pdf_doc->save_table(array('fontSize' => 8, 'cols' => array('cantidad' => array('justification' => 'right'), 'pvp' => array('justification' => 'right'), 'dto' => array('justification' => 'right'), 'importe' => array('justification' => 'right')), 'width' => 520, 'shaded' => 0)); if ($linea_actual == count($lineas)) { /* * Añadimos la parte de la firma y las observaciones, * para el tipo 'firma' */ if ($tipo == 'firma') { $pdf_doc->pdf->ezText("\n", 9); $pdf_doc->new_table(); $pdf_doc->add_table_header(array('campo1' => "<b>Observaciones</b>", 'campo2' => "<b>Firma</b>")); $pdf_doc->add_table_row(array('campo1' => $this->fix_html($this->factura->observaciones), 'campo2' => "")); $pdf_doc->save_table(array('cols' => array('campo1' => array('justification' => 'left'), 'campo2' => array('justification' => 'right', 'width' => 100)), 'showLines' => 4, 'width' => 530, 'shaded' => 0)); } else { if ($this->factura->observaciones != '') { $pdf_doc->pdf->ezText("\n" . $this->fix_html($this->factura->observaciones), 9); } } if (!$this->factura->pagada) { $fp0 = new forma_pago(); $forma_pago = $fp0->get($this->factura->codpago); if ($forma_pago) { if (is_null($forma_pago->codcuenta)) { $pdf_doc->pdf->ezText("\n<b>Forma de pago</b>: " . $forma_pago->descripcion . "\n<b>Vencimiento</b>: " . $this->factura->vencimiento, 9); } else { $texto_pago = "\n<b>Forma de pago</b>: " . $forma_pago->descripcion; if ($forma_pago->domiciliado) { $cbc0 = new cuenta_banco_cliente(); $encontrada = FALSE; foreach ($cbc0->all_from_cliente($this->factura->codcliente) as $cbc) { if ($cbc->iban) { $texto_pago .= "\n<b>Domiciliado en</b>: " . $cbc->iban; } else { $texto_pago .= "\n<b>Domiciliado en</b>: " . $cbc->swift; } $encontrada = TRUE; break; } if (!$encontrada) { $texto_pago .= "\n<b>El cliente no tiene cuenta bancaria asignada.</b>"; } } else { $cb0 = new cuenta_banco(); $cuenta_banco = $cb0->get($forma_pago->codcuenta); if ($cuenta_banco) { if ($cuenta_banco->iban) { $texto_pago .= "\n<b>IBAN</b>: " . $cuenta_banco->iban; } else { $texto_pago .= "\n<b>SWIFT o BIC</b>: " . $cuenta_banco->swift; } } } $texto_pago .= "\n<b>Vencimiento</b>: " . $this->factura->vencimiento; $pdf_doc->pdf->ezText($texto_pago, 9); } } } } $pdf_doc->set_y(80); /* * Rellenamos la última tabla de la página: * * Página Neto IVA Total */ $pdf_doc->new_table(); $titulo = array('pagina' => '<b>Página</b>', 'neto' => '<b>Neto</b>'); $fila = array('pagina' => $pagina . '/' . ceil(count($lineas) / $lppag), 'neto' => $this->show_precio($this->factura->neto, $this->factura->coddivisa)); $opciones = array('cols' => array('neto' => array('justification' => 'right')), 'showLines' => 4, 'width' => 520); foreach ($lineas_iva as $li) { $imp = $this->impuesto->get($li->codimpuesto); if ($imp) { $titulo['iva' . $li->iva] = '<b>' . $imp->descripcion . '</b>'; } else { $titulo['iva' . $li->iva] = '<b>' . FS_IVA . ' ' . $li->iva . '%</b>'; } $fila['iva' . $li->iva] = $this->show_precio($li->totaliva, $this->factura->coddivisa); if ($li->totalrecargo != 0) { $fila['iva' . $li->iva] .= ' (RE: ' . $this->show_precio($li->totalrecargo, $this->factura->coddivisa) . ')'; } $opciones['cols']['iva' . $li->iva] = array('justification' => 'right'); } if ($this->factura->totalirpf != 0) { $titulo['irpf'] = '<b>' . FS_IRPF . ' ' . $this->factura->irpf . '%</b>'; $fila['irpf'] = $this->show_precio(0 - $this->factura->totalirpf); $opciones['cols']['irpf'] = array('justification' => 'right'); } $titulo['liquido'] = '<b>Total</b>'; $fila['liquido'] = $this->show_precio($this->factura->total, $this->factura->coddivisa); $opciones['cols']['liquido'] = array('justification' => 'right'); $pdf_doc->add_table_header($titulo); $pdf_doc->add_table_row($fila); $pdf_doc->save_table($opciones); /// pié de página para la factura $pdf_doc->pdf->addText(10, 10, 8, $pdf_doc->center_text($this->fix_html($this->empresa->pie_factura), 153), 0, 1.5); $pagina++; } } if ($archivo) { if (!file_exists('tmp/' . FS_TMP_NAME . 'enviar')) { mkdir('tmp/' . FS_TMP_NAME . 'enviar'); } $pdf_doc->save('tmp/' . FS_TMP_NAME . 'enviar/' . $archivo); } else { $pdf_doc->show(); } }
private function generar_pdf_servicio($archivo = FALSE) { if (!$archivo) { /// desactivamos la plantilla HTML $this->template = FALSE; } $pdf_doc = new fs_pdf(); $pdf_doc->pdf->addInfo('Title', ucfirst(FS_SERVICIO) . ' ' . $this->servicio->codigo); $pdf_doc->pdf->addInfo('Subject', ucfirst(FS_SERVICIO) . ' de cliente ' . $this->servicio->codigo); $pdf_doc->pdf->addInfo('Author', $this->empresa->nombre); /// ¿Añadimos el logo? if (file_exists('tmp/' . FS_TMP_NAME . 'logo.png')) { if (function_exists('imagecreatefromstring')) { $pdf_doc->pdf->ezImage('tmp/' . FS_TMP_NAME . 'logo.png', 0, 200, 'none'); //$lppag -= 2; /// si metemos el logo, caben menos líneas } else { die('ERROR: no se encuentra la función imagecreatefromstring(). ' . 'Y por tanto no se puede usar el logotipo en los documentos.'); } } else { $pdf_doc->pdf->ezText("<b>" . $this->empresa->nombre . "</b>", 16, array('justification' => 'center')); $pdf_doc->pdf->ezText(FS_CIFNIF . ": " . $this->empresa->cifnif, 8, array('justification' => 'center')); $direccion = $this->empresa->direccion; if ($this->empresa->codpostal) { $direccion .= ' - ' . $this->empresa->codpostal; } if ($this->empresa->ciudad) { $direccion .= ' - ' . $this->empresa->ciudad; } if ($this->empresa->provincia) { $direccion .= ' (' . $this->empresa->provincia . ')'; } if ($this->empresa->telefono) { $direccion .= ' - Teléfono: ' . $this->empresa->telefono; } $pdf_doc->pdf->ezText($this->fix_html($direccion), 9, array('justification' => 'center')); } /* * Esta es la tabla con los datos del cliente: * Servicio: Fecha: * Cliente: CIF/NIF: * Dirección: Teléfonos: */ $pdf_doc->new_table(); $pdf_doc->add_table_row(array('campo1' => "<b>" . $this->st['st_servicio'] . ":</b>", 'dato1' => $this->servicio->codigo, 'campo2' => "<b>Fecha:</b>", 'dato2' => $this->servicio->fecha)); $pdf_doc->add_table_row(array('campo1' => "<b>Cliente:</b>", 'dato1' => $this->fix_html($this->servicio->nombrecliente), 'campo2' => "<b>" . FS_CIFNIF . ":</b>", 'dato2' => $this->servicio->cifnif)); $pdf_doc->add_table_row(array('campo1' => "<b>Dirección:</b>", 'dato1' => $this->fix_html($this->servicio->direccion . ' CP: ' . $this->servicio->codpostal . ' - ' . $this->servicio->ciudad . ' (' . $this->servicio->provincia . ')'), 'campo2' => "<b>Teléfonos:</b>", 'dato2' => $this->cliente->telefono1 . ' ' . $this->cliente->telefono2)); $pdf_doc->save_table(array('cols' => array('campo1' => array('justification' => 'right'), 'dato1' => array('justification' => 'left'), 'campo2' => array('justification' => 'right'), 'dato2' => array('justification' => 'left')), 'showLines' => 0, 'width' => 520, 'shaded' => 0)); $pdf_doc->pdf->ezText("\n", 10); /*Esta es la tabla de los datos del servicio y trabajos a realizar*/ $pdf_doc->pdf->ezText("\n<b>" . $this->st['st_servicio'] . "</b>", 14); $pdf_doc->new_table(); $pdf_doc->add_table_row(array('campo1' => "<b>" . $this->st['st_material'] . ":</b>", 'dato1' => $this->fix_html($this->servicio->material), 'campo2' => "<b>" . $this->st['st_material_estado'] . ":</b>", 'dato2' => $this->servicio->material_estado)); $pdf_doc->add_table_row(array('campo1' => "<b>" . $this->st['st_accesorios'] . ":</b>", 'dato1' => $this->fix_html($this->servicio->accesorios), 'campo2' => "", 'dato2' => "")); $pdf_doc->add_table_row(array('campo1' => "<b>" . $this->st['st_descripcion'] . ":</b>", 'dato1' => $this->fix_html($this->servicio->descripcion), 'campo2' => "<b>" . $this->st['st_solucion'] . ": </b>", 'dato2' => $this->servicio->solucion)); $pdf_doc->add_table_row(array('campo1' => "<b>Fecha prevista de inicio:</b>", 'dato1' => $this->fix_html($this->servicio->fechainicio), 'campo2' => "<b>Fecha prevista de finalización:</b>", 'dato2' => $this->fix_html($this->servicio->fechafin))); $pdf_doc->save_table(array('cols' => array('campo1' => array('justification' => 'left'), 'dato1' => array('justification' => 'left'), 'campo2' => array('justification' => 'left'), 'dato2' => array('justification' => 'left')), 'showLines' => 0, 'width' => 520, 'shaded' => 0)); $pdf_doc->pdf->ezText("\n", 10); $lineas = $this->servicio->get_lineas(); $lineas_iva = $this->get_lineas_iva($lineas); if ($lineas) { $linea_actual = 0; $pagina = 1; /// imprimimos las páginas necesarias while ($linea_actual < count($lineas)) { $lppag = 35; /// salto de página if ($linea_actual > 0) { $pdf_doc->pdf->ezNewPage(); } /* * Creamos la tabla con las lineas del servicio: * * Descripción PVP DTO Cantidad Importe */ $pdf_doc->new_table(); $pdf_doc->pdf->ezText("\n<b>Detalle</b>\n", 14); if ($this->impresion['print_dto']) { $pdf_doc->add_table_header(array('descripcion' => '<b>Descripción</b>', 'cantidad' => '<b>Cantidad</b>', 'pvp' => '<b>PVP</b>', 'dto' => '<b>DTO</b>', 'importe' => '<b>Importe</b>')); } else { $pdf_doc->add_table_header(array('descripcion' => '<b>Descripción</b>', 'cantidad' => '<b>Cantidad</b>', 'pvp' => '<b>PVP</b>', 'importe' => '<b>Importe</b>')); } for ($i = $linea_actual; $linea_actual < $lppag + $i and $linea_actual < count($lineas);) { $descripcion = $this->fix_html($lineas[$linea_actual]->descripcion); if ($this->impresion['print_ref'] and !is_null($lineas[$linea_actual]->referencia)) { $descripcion = '<b>' . $lineas[$linea_actual]->referencia . '</b> ' . $descripcion; } $fila = array('descripcion' => $descripcion, 'cantidad' => $lineas[$linea_actual]->cantidad, 'pvp' => $this->show_precio($lineas[$linea_actual]->pvpunitario, $this->servicio->coddivisa), 'dto' => $this->show_numero($lineas[$linea_actual]->dtopor, 0) . " %", 'importe' => $this->show_precio($lineas[$linea_actual]->pvptotal, $this->servicio->coddivisa)); $pdf_doc->add_table_row($fila); $linea_actual++; } $pdf_doc->save_table(array('fontSize' => 8, 'cols' => array('cantidad' => array('justification' => 'right'), 'pvp' => array('justification' => 'right'), 'dto' => array('justification' => 'right'), 'importe' => array('justification' => 'right')), 'width' => 520, 'shaded' => 0)); if ($linea_actual == count($lineas)) { if ($this->servicio->observaciones != '') { $pdf_doc->pdf->ezText("\n" . $this->servicio->observaciones, 9); } $pdf_doc->pdf->ezText("\n" . $this->servicios_setup['servicios_condiciones'], 9); } $pdf_doc->set_y(80); /* * Rellenamos la última tabla de la página: * * Página Neto IVA Total */ $pdf_doc->new_table(); $titulo = array('pagina' => '<b>Página</b>', 'neto' => '<b>Neto</b>'); $fila = array('pagina' => $pagina . '/' . ceil(count($lineas) / $lppag), 'neto' => $this->show_precio($this->servicio->neto, $this->servicio->coddivisa)); $opciones = array('cols' => array('neto' => array('justification' => 'right')), 'showLines' => 4, 'width' => 520); foreach ($lineas_iva as $li) { $imp = $this->impuesto->get($li['codimpuesto']); if ($imp) { $titulo['iva' . $li['iva']] = '<b>' . $imp->descripcion . '</b>'; } else { $titulo['iva' . $li['iva']] = '<b>' . FS_IVA . ' ' . $li['iva'] . '%</b>'; } $fila['iva' . $li['iva']] = $this->show_precio($li['totaliva'], $this->servicio->coddivisa); if ($li['totalrecargo'] != 0) { $fila['iva' . $li['iva']] .= ' (RE: ' . $this->show_precio($li['totalrecargo'], $this->servicio->coddivisa) . ')'; } $opciones['cols']['iva' . $li['iva']] = array('justification' => 'right'); } if ($this->servicio->totalirpf != 0) { $titulo['irpf'] = '<b>' . FS_IRPF . ' ' . $this->servicio->irpf . '%</b>'; $fila['irpf'] = $this->show_precio(0 - $this->servicio->totalirpf); $opciones['cols']['irpf'] = array('justification' => 'right'); } $titulo['liquido'] = '<b>Total</b>'; $fila['liquido'] = $this->show_precio($this->servicio->total, $this->servicio->coddivisa); $opciones['cols']['liquido'] = array('justification' => 'right'); $pdf_doc->add_table_header($titulo); $pdf_doc->add_table_row($fila); $pdf_doc->save_table($opciones); $pdf_doc->pdf->addText(10, 10, 8, $pdf_doc->center_text($this->fix_html($this->empresa->pie_factura), 153), 0, 1.5); $pagina++; } } if ($archivo) { if (!file_exists('tmp/' . FS_TMP_NAME . 'enviar')) { mkdir('tmp/' . FS_TMP_NAME . 'enviar'); } $pdf_doc->save('tmp/' . FS_TMP_NAME . 'enviar/' . $archivo); } else { $pdf_doc->show(FS_SERVICIO . '_' . $this->servicio->codigo . '.pdf'); } }
private function pdf_facturas_prov() { /// desactivamos el motor de plantillas $this->template = FALSE; $pdf_doc = new fs_pdf('a4', 'landscape', 'Courier'); $pdf_doc->pdf->addInfo('Title', 'Facturas emitidas del ' . $_POST['dfecha'] . ' al ' . $_POST['hfecha']); $pdf_doc->pdf->addInfo('Subject', 'Facturas emitidas del ' . $_POST['dfecha'] . ' al ' . $_POST['hfecha']); $pdf_doc->pdf->addInfo('Author', $this->empresa->nombre); $serie = FALSE; if ($_POST['codserie'] != '---') { $serie = $_POST['codserie']; } $facturas = $this->factura_pro->all_desde($_POST['dfecha'], $_POST['hfecha'], $serie); if ($facturas) { $total_lineas = count($facturas); $linea_actual = 0; $lppag = 31; $total = $totalrecargo = $totalirpf = 0; $impuestos = array(); $pagina = 1; while ($linea_actual < $total_lineas) { if ($linea_actual > 0) { $pdf_doc->pdf->ezNewPage(); $pagina++; } /// encabezado $pdf_doc->pdf->ezText($this->empresa->nombre . " - Facturas de compras del " . $_POST['dfecha'] . " al " . $_POST['hfecha'] . ":\n\n", 14); /// tabla principal $pdf_doc->new_table(); $pdf_doc->add_table_header(array('serie' => '<b>S</b>', 'factura' => '<b>Fact.</b>', 'asiento' => '<b>Asi.</b>', 'fecha' => '<b>Fecha</b>', 'subcuenta' => '<b>Subcuenta</b>', 'descripcion' => '<b>Descripción</b>', 'cifnif' => '<b>' . FS_CIFNIF . '</b>', 'base' => '<b>Base Im.</b>', 'iva' => '<b>% IVA</b>', 'totaliva' => '<b>IVA</b>', 'totalrecargo' => '<b>RE</b>', 'totalirpf' => '<b>IRPF</b>', 'total' => '<b>Total</b>')); for ($i = 0; $i < $lppag and $linea_actual < $total_lineas; $i++) { $linea = array('serie' => $facturas[$linea_actual]->codserie, 'factura' => $facturas[$linea_actual]->numero, 'asiento' => '-', 'fecha' => $facturas[$linea_actual]->fecha, 'subcuenta' => '-', 'descripcion' => $facturas[$linea_actual]->nombre, 'cifnif' => $facturas[$linea_actual]->cifnif, 'base' => 0, 'iva' => 0, 'totaliva' => 0, 'totalrecargo' => 0, 'totalirpf' => '-', 'total' => 0); $asiento = $facturas[$linea_actual]->get_asiento(); if ($asiento) { $linea['asiento'] = $asiento->numero; $partidas = $asiento->get_partidas(); if ($partidas) { $linea['subcuenta'] = $partidas[0]->codsubcuenta; } } if ($facturas[$linea_actual]->totalirpf != 0) { $linea['totalirpf'] = $this->show_numero($facturas[$linea_actual]->totalirpf); $linea['total'] = $this->show_numero($facturas[$linea_actual]->total); /// añade la línea al PDF $pdf_doc->add_table_row($linea); $linea['totalirpf'] = '-'; } $linivas = $facturas[$linea_actual]->get_lineas_iva(); if ($linivas) { $nueva_linea = FALSE; foreach ($linivas as $liva) { /// acumulamos la base if (!isset($impuestos[$liva->iva]['base'])) { $impuestos[$liva->iva]['base'] = $liva->neto; } else { $impuestos[$liva->iva]['base'] += $liva->neto; } /// acumulamos el iva if (!isset($impuestos[$liva->iva]['iva'])) { $impuestos[$liva->iva]['iva'] = $liva->totaliva; } else { $impuestos[$liva->iva]['iva'] += $liva->totaliva; } /// completamos y añadimos la línea al PDF $linea['base'] = $this->show_numero($liva->neto); $linea['iva'] = $this->show_numero($liva->iva); $linea['totaliva'] = $this->show_numero($liva->totaliva); $linea['totalrecargo'] = $this->show_numero($liva->totalrecargo); $linea['total'] = $this->show_numero($liva->totallinea); $pdf_doc->add_table_row($linea); if ($nueva_linea) { $i++; } else { $nueva_linea = TRUE; } } } $totalrecargo += $facturas[$linea_actual]->totalrecargo; $totalirpf += $facturas[$linea_actual]->totalirpf; $total += $facturas[$linea_actual]->total; $linea_actual++; } $pdf_doc->save_table(array('fontSize' => 8, 'cols' => array('base' => array('justification' => 'right'), 'iva' => array('justification' => 'right'), 'totaliva' => array('justification' => 'right'), 'totalrecargo' => array('justification' => 'right'), 'totalirpf' => array('justification' => 'right'), 'total' => array('justification' => 'right')), 'shaded' => 0, 'width' => 780)); $pdf_doc->pdf->ezText("\n", 10); /// Rellenamos la última tabla $pdf_doc->new_table(); $titulo = array('pagina' => '<b>Suma y sigue</b>'); $fila = array('pagina' => $pagina . '/' . ceil($total_lineas / $lppag)); $opciones = array('cols' => array('base' => array('justification' => 'right')), 'showLines' => 0, 'width' => 780); foreach ($impuestos as $i => $value) { $titulo['base' . $i] = '<b>Base ' . $i . '%</b>'; $fila['base' . $i] = $this->show_precio($value['base']); $opciones['cols']['base' . $i] = array('justification' => 'right'); if ($i != 0) { $titulo['iva' . $i] = '<b>IVA ' . $i . '%</b>'; $fila['iva' . $i] = $this->show_precio($value['iva']); $opciones['cols']['iva' . $i] = array('justification' => 'right'); } } $titulo['totalrecargo'] = '<b>RE</b>'; $titulo['totalirpf'] = '<b>IRPF</b>'; $titulo['total'] = '<b>Total</b>'; $fila['totalrecargo'] = $this->show_precio($totalrecargo); $fila['totalirpf'] = $this->show_precio($totalirpf); $fila['total'] = $this->show_precio($total); $opciones['cols']['totalrecargo'] = array('justification' => 'right'); $opciones['cols']['totalirpf'] = array('justification' => 'right'); $opciones['cols']['total'] = array('justification' => 'right'); $pdf_doc->add_table_header($titulo); $pdf_doc->add_table_row($fila); $pdf_doc->save_table($opciones); } } else { $pdf_doc->pdf->ezText($this->empresa->nombre . " - Facturas de compras del " . $_POST['dfecha'] . ' al ' . $_POST['hfecha'] . ":\n\n", 14); $pdf_doc->pdf->ezText("Ninguna.\n\n", 14); } $pdf_doc->show(); }
private function generar_pdf_factura($archivo = FALSE) { if (!$archivo) { /// desactivamos la plantilla HTML $this->template = FALSE; } /// Creamos el PDF y escribimos sus metadatos $pdf_doc = new fs_pdf(); $pdf_doc->pdf->addInfo('Title', 'Factura ' . $this->factura->codigo); $pdf_doc->pdf->addInfo('Subject', 'Ingreso proveedor' . $this->factura->codigo); $pdf_doc->pdf->addInfo('Author', $this->empresa->nombre); $lineas = $this->factura->get_lineas(); $lineas_iva = $this->factura->get_lineas_iva(); if ($lineas) { $lineasfact = count($lineas); $linea_actual = 0; $pagina = 1; // Imprimimos las páginas necesarias while ($linea_actual < $lineasfact) { $lppag = 35; /// líneas por página /// salto de página if ($linea_actual > 0) { $pdf_doc->pdf->ezNewPage(); } /// ¿Añadimos el logo? if (file_exists('tmp/' . FS_TMP_NAME . 'logo.png')) { if (function_exists('imagecreatefromstring')) { $pdf_doc->pdf->ezImage('tmp/' . FS_TMP_NAME . 'logo.png', 0, 200, 'none'); $lppag -= 2; /// si metemos el logo, caben menos líneas } else { die('ERROR: no se encuentra la función imagecreatefromstring(). ' . 'Y por tanto no se puede usar el logotipo en los documentos.'); } } else { $pdf_doc->pdf->ezText("<b>" . $this->empresa->nombre . "</b>", 16, array('justification' => 'center')); $pdf_doc->pdf->ezText(FS_CIFNIF . ": " . $this->empresa->cifnif, 8, array('justification' => 'center')); $direccion = $this->empresa->direccion; if ($this->empresa->codpostal) { $direccion .= ' - ' . $this->empresa->codpostal; } if ($this->empresa->ciudad) { $direccion .= ' - ' . $this->empresa->ciudad; } if ($this->empresa->provincia) { $direccion .= ' (' . $this->empresa->provincia . ')'; } if ($this->empresa->telefono) { $direccion .= ' - Teléfono: ' . $this->empresa->telefono; } $pdf_doc->pdf->ezText($this->fix_html($direccion), 9, array('justification' => 'center')); } /* * Esta es la tabla con los datos del proveedor: * Factura: Fecha: * Proveedor: CIF/NIF: * Dirección: Teléfonos: */ $pdf_doc->new_table(); $pdf_doc->add_table_row(array('campo1' => "<b>Factura:</b>", 'dato1' => $this->factura->codigo, 'campo2' => "<b>Fecha:</b>", 'dato2' => $this->factura->fecha)); $pdf_doc->add_table_row(array('campo1' => "<b>Proveedor:</b>", 'dato1' => $this->fix_html($this->factura->nombre), 'campo2' => "<b>" . FS_CIFNIF . ":</b>", 'dato2' => $this->factura->cifnif)); $pdf_doc->save_table(array('cols' => array('campo1' => array('justification' => 'right'), 'dato1' => array('justification' => 'left'), 'campo2' => array('justification' => 'right'), 'dato2' => array('justification' => 'left')), 'showLines' => 0, 'width' => 520, 'shaded' => 0)); $pdf_doc->pdf->ezText("\n", 10); /* * Creamos la tabla con las lineas de la factura: * * Cantidad Ref. Prov. + Descripción PVP DTO Importe */ $pdf_doc->new_table(); $pdf_doc->add_table_header(array('cantidad' => '<b>Cant.</b>', 'descripcion' => '<b>Ref. Prov. + Descripción</b>', 'pvp' => '<b>PVP</b>', 'dto' => '<b>Dto.</b>', 'importe' => '<b>Importe</b>')); for ($i = $linea_actual; $linea_actual < $lppag + $i and $linea_actual < $lineasfact;) { $descripcion = $this->fix_html($lineas[$linea_actual]->descripcion); if (!is_null($lineas[$linea_actual]->referencia)) { $descripcion = '<b>' . $this->get_referencia_proveedor($lineas[$linea_actual]->referencia, $this->factura->codproveedor) . '</b> ' . $this->fix_html($lineas[$linea_actual]->descripcion); } $fila = array('cantidad' => $lineas[$linea_actual]->cantidad, 'descripcion' => $descripcion, 'pvp' => $this->show_precio($lineas[$linea_actual]->pvpunitario, $this->factura->coddivisa), 'dto' => $this->show_numero($lineas[$linea_actual]->dtopor, 0) . " %", 'importe' => $this->show_precio($lineas[$linea_actual]->pvptotal, $this->factura->coddivisa)); $pdf_doc->add_table_row($fila); $linea_actual++; } $pdf_doc->save_table(array('fontSize' => 8, 'cols' => array('cantidad' => array('justification' => 'right'), 'pvp' => array('justification' => 'right'), 'dto' => array('justification' => 'right'), 'importe' => array('justification' => 'right')), 'width' => 520, 'shaded' => 0)); if ($linea_actual == count($lineas)) { if ($this->factura->observaciones != '') { $pdf_doc->pdf->ezText("\n" . $this->factura->observaciones, 9); } } $pdf_doc->set_y(80); /* * Rellenamos la última tabla de la página: * * Página Neto IVA Total */ $pdf_doc->new_table(); $titulo = array('pagina' => '<b>Página</b>', 'neto' => '<b>Neto</b>'); $fila = array('pagina' => $pagina . '/' . ceil(count($lineas) / $lppag), 'neto' => $this->show_precio($this->factura->neto, $this->factura->coddivisa)); $opciones = array('cols' => array('neto' => array('justification' => 'right')), 'showLines' => 4, 'width' => 520); foreach ($lineas_iva as $li) { $imp = $this->impuesto->get($li->codimpuesto); if ($imp) { $titulo['iva' . $li->iva] = '<b>' . $imp->descripcion . '</b>'; } else { $titulo['iva' . $li->iva] = '<b>' . FS_IVA . ' ' . $li->iva . '%</b>'; } $fila['iva' . $li->iva] = $this->show_precio($li->totaliva, $this->factura->coddivisa); if ($li->totalrecargo != 0) { $fila['iva' . $li->iva] .= ' (RE: ' . $this->show_precio($li->totalrecargo, $this->factura->coddivisa) . ')'; } $opciones['cols']['iva' . $li->iva] = array('justification' => 'right'); } if ($this->factura->totalirpf != 0) { $titulo['irpf'] = '<b>' . FS_IRPF . ' ' . $this->factura->irpf . '%</b>'; $fila['irpf'] = $this->show_precio(0 - $this->factura->totalirpf); $opciones['cols']['irpf'] = array('justification' => 'right'); } $titulo['liquido'] = '<b>Total</b>'; $fila['liquido'] = $this->show_precio($this->factura->total, $this->factura->coddivisa); $opciones['cols']['liquido'] = array('justification' => 'right'); $pdf_doc->add_table_header($titulo); $pdf_doc->add_table_row($fila); $pdf_doc->save_table($opciones); $pagina++; } } if ($archivo) { if (!file_exists('tmp/' . FS_TMP_NAME . 'enviar')) { mkdir('tmp/' . FS_TMP_NAME . 'enviar'); } $pdf_doc->save('tmp/' . FS_TMP_NAME . 'enviar/' . $archivo); } else { $pdf_doc->show(); } }
private function generar_pdf_factura($tipo = 'simple', $archivo = FALSE) { $divi = new divisa(); if (!$archivo) { /// desactivamos la plantilla HTML $this->template = FALSE; } /// Creamos el PDF y escribimos sus metadatos $pdf_doc = new fs_pdf(); $pdf_doc->pdf->addInfo('Title', ucfirst(FS_FACTURA) . ' ' . $this->factura->codigo); $pdf_doc->pdf->addInfo('Subject', ucfirst(FS_FACTURA) . ' ' . $this->factura->codigo); $pdf_doc->pdf->addInfo('Author', $this->empresa->nombre); $lineas = $this->factura->get_lineas(); $lineas_iva = $this->factura->get_lineas_iva(); if ($lineas) { $lineasfact = count($lineas); $linea_actual = 0; $pagina = 1; /////////////////////////////////////////////////////////////////////////////////// //////////////////// PARA FACTURA PREIMPRESA //////////////////////////////////////////////////////////////////////////////////// if ($tipo == 'firma') { $numFactura = $this->factura->numero2; $fecha = $this->factura->fecha; $nomCliente = $this->factura->nombrecliente; $dirCliente = $this->direccioncli->direccion; $cpCliente = $this->factura->codpostal; $locCliente = $this->direccioncli->ciudad; $provincia = $this->direccioncli->provincia; $telCliente1 = $this->cliente->telefono1; $telCliente2 = $this->cliente->telefono2; $catIVA = $this->cliente->regimeniva; $numCuit = '88-88888888-888 '; $ingBrutos = '1234-567890-1234-5678-90'; $this->simbdivisa = $divi->get($this->factura->coddivisa); $uMoneda = $this->simbdivisa->simbolo; //Unidad de Moneda $cheqNum = '8888-8888-8888-8888 '; $cheqBanco = 'Banco Internacional y Nacional'; $cheqImporte = '7789.99'; $anticipo = '3854.88'; $anticipoDetalle = 'Detalle por si hay algo anotar del anticipo'; $efectivo = '38888.88'; $efectivoDetalle = 'Detalle por si hay algo anotar del efectivo'; $tarjDebito = '48888.88'; $debitoDetalle = 'Visa Nº 8888-8888-8888-8888-8888'; $tarjCredito = '48888.88'; $creditoDetalle = 'Master Card Nº 9888-8888-8888-8888-8888'; $linea_arranque = -10; $linea_fin = 0; $cant_pag = intval($lineasfact / 10); if ($lineasfact / 10 - intval($lineasfact / 10) > 0) { $cant_pag = $cant_pag + 1; } for ($j = 0; $j < $cant_pag; $j++) { if ($lineasfact - $linea_fin < 10) { $linea_menor = ($lineasfact / 10 - intval($lineasfact / 10)) * 10; $linea_fin = $linea_fin + $linea_menor; } else { $linea_fin = $linea_fin + 10; } $linea_arranque = $linea_arranque + 10; if ($j != 0) { $pdf_doc->pdf->ezNewPage(); } $pdf_doc->pdf->addTextWrap(430, 773, 400, 16, $numFactura, 'left'); ////// Nº FACTURA $pdf_doc->pdf->addTextWrap(390, 698, 200, 14, $fecha); $pdf_doc->pdf->addTextWrap(111, 648, 470, 14, $nomCliente); $pdf_doc->pdf->addTextWrap(111, 633, 470, 10, $dirCliente . ' CP: ' . $cpCliente); $pdf_doc->pdf->addTextWrap(111, 619, 280, 10, $locCliente . ' - ' . $provincia); $pdf_doc->pdf->addTextWrap(444, 619, 200, 9, $telCliente1 . " / " . $telCliente2); $pdf_doc->pdf->addTextWrap(132, 589, 200, 9, $catIVA); // $pdf_doc->pdf->addTextWrap CUIT // $pdf_doc->pdf->addTextWrap ING BRUTOS ////////////////////////////////////////////////////////////////////////////////////// ////////////// CONTENIDO DESCRIPCIÓN ////////////////////////////////////////////////////////////////////////////////////// //Variable X p encolumnar importe $varImporte = '465'; $Sub_Total = 0; for ($i = $linea_arranque; $i < $linea_fin; $i++) { // $pdf_doc->pdf->addTextWrap(55,518-(22*($i-$linea_arranque)), 25, 12,number_format($lineas[$i]->cantidad, 0, ',', ' '),'right'); $pdf_doc->pdf->addTextWrap(85, 518 - 22 * ($i - $linea_arranque), 300, 12, $this->fix_html($lineas[$i]->descripcion), 'left'); // $pdf_doc->pdf->addTextWrap(390,518-(22*($i-$linea_arranque)), 410, 12,$uMoneda.' '.number_format($lineas[$i]->pvpunitario, 2, ',', 'right')); // $pdf_doc->pdf->addTextWrap(370,518-(22*($i-$linea_arranque)), 90, 12,$uMoneda.' '.number_format($lineas[$i]->pvpunitario, 2, ',', ' '),'right'); // $pdf_doc->pdf->addTextWrap(390,518-(22*($i-$linea_arranque)), 410, 12,$uMoneda.' '.number_format($lineas[$i]->pvpunitario, 2, ',', 'right')); $pdf_doc->pdf->addTextWrap($varImporte, 518 - 22 * ($i - $linea_arranque), 90, 12, number_format($lineas[$i]->pvptotal, 2, ',', ' '), 'right'); $Sub_Total = $Sub_Total + $lineas[$i]->pvptotal; } $pdf_doc->pdf->addTextWrap($varImporte - 10, 270, 90, 12, number_format($Sub_Total, 2, ',', ' '), 'right'); //////////////////////////////////////////////////////////////////////////// //////////// Pie // /* $pdf_doc->new_table(); $pdf_doc->add_table_row( array( 'campo1' => "Cheque", 'dato1' => $cheqNum, 'campo2' => "Importe", 'dato2' => $cheqImporte ) ); $pdf_doc->add_table_row( array( 'campo1' => "Anticipo", 'dato1' => $anticipoDetalle, 'campo2' => "Efectivo", 'dato2' => $efectivo ) ); */ $pdf_doc->save_table(array('cols' => array('campo1' => array('justification' => 'right'), 'dato1' => array('justification' => 'left'), 'campo2' => array('justification' => 'right'), 'dato2' => array('justification' => 'left')), 'showLines' => 0, 'width' => 520, 'shaded' => 0)); $pdf_doc->pdf->ezText("\n", 10); $valores = $cheqImporte + $anticipo + $efectivo + $tarjDebito + $tarjCredito; /* $pdf_doc->pdf->addTextWrap(111,195, 150, 12,$cheqNum); $pdf_doc->pdf->addTextWrap(283,195, 200, 12,$cheqBanco); $pdf_doc->pdf->addTextWrap($varImporte,190, 90, 12,$cheqImporte,'right'); $pdf_doc->pdf->addTextWrap(111,166, 370, 12,$anticipoDetalle); $pdf_doc->pdf->addTextWrap($varImporte,161, 90, 12,$anticipo,'right'); $pdf_doc->pdf->addTextWrap($varImporte,132, 90, 12,$efectivo,'right'); $pdf_doc->pdf->addTextWrap(111,137, 370, 12,$efectivoDetalle); $pdf_doc->pdf->addTextWrap($varImporte,104, 90, 12,$tarjDebito,'right'); $pdf_doc->pdf->addTextWrap(140,109, 350, 12,$debitoDetalle); $pdf_doc->pdf->addTextWrap($varImporte,76, 90, 12,$tarjCredito,'right'); $pdf_doc->pdf->addTextWrap(140,81,350, 12,$creditoDetalle); $pdf_doc->pdf->addTextWrap($varImporte,48, 35, 12,$valores,'right'); */ $linea_actual++; } } else { // Imprimimos las páginas necesarias while ($linea_actual < $lineasfact) { $lppag = 35; /// líneas por página /// salto de página if ($linea_actual > 0) { $pdf_doc->pdf->ezNewPage(); } /* * Creamos la cabecera de la página, en este caso para el modelo carta */ if ($tipo == 'carta') { $direccion = $this->factura->nombrecliente . "\n" . $this->factura->direccion; if ($this->factura->codpostal and $this->factura->ciudad) { $direccion .= "\n CP: " . $this->factura->codpostal . ' ' . $this->factura->ciudad; } else { if ($this->factura->ciudad) { $direccion .= "\n" . $this->factura->ciudad; } } if ($this->factura->provincia) { $direccion .= "\n(" . $this->factura->provincia . ")"; } $pdf_doc->pdf->ezText("\n\n", 10); $pdf_doc->new_table(); $pdf_doc->add_table_row(array('campos' => "<b>" . ucfirst(FS_FACTURA) . ":</b>\n<b>Fecha:</b>\n<b>" . FS_CIFNIF . ":</b>", 'factura' => $this->factura->codigo . "\n" . $this->factura->fecha . "\n" . $this->factura->cifnif, 'cliente' => $this->fix_html($direccion))); $pdf_doc->save_table(array('cols' => array('campos' => array('justification' => 'right', 'width' => 100), 'factura' => array('justification' => 'left'), 'cliente' => array('justification' => 'right')), 'showLines' => 0, 'width' => 520)); $pdf_doc->pdf->ezText("\n\n\n", 14); } else { /// ¿Añadimos el logo? if (file_exists('tmp/' . FS_TMP_NAME . 'logo.png')) { if (function_exists('imagecreatefromstring')) { $pdf_doc->pdf->ezImage('tmp/' . FS_TMP_NAME . 'logo.png', 0, 200, 'none'); $lppag -= 2; /// si metemos el logo, caben menos líneas } else { die('ERROR: no se encuentra la función imagecreatefromstring(). ' . 'Y por tanto no se puede usar el logotipo en los documentos.'); } } else { $pdf_doc->pdf->ezText("<b>" . $this->empresa->nombre . "</b>", 16, array('justification' => 'center')); $pdf_doc->pdf->ezText(FS_CIFNIF . ": " . $this->empresa->cifnif, 8, array('justification' => 'center')); $direccion = $this->empresa->direccion; if ($this->empresa->codpostal) { $direccion .= ' - ' . $this->empresa->codpostal; } if ($this->empresa->ciudad) { $direccion .= ' - ' . $this->empresa->ciudad; } if ($this->empresa->provincia) { $direccion .= ' (' . $this->empresa->provincia . ')'; } if ($this->empresa->telefono) { $direccion .= ' - Teléfono: ' . $this->empresa->telefono; } $pdf_doc->pdf->ezText($this->fix_html($direccion), 9, array('justification' => 'center')); } //////////////////// //// CLIENTES ///// /* * Esta es la tabla con los datos del cliente: * Factura: Fecha: * Cliente: CIF/NIF: * Dirección: Teléfonos: */ $pdf_doc->new_table(); $pdf_doc->add_table_row(array('campo1' => "<b>" . ucfirst(FS_FACTURA) . ":</b>", 'dato1' => $this->factura->codigo, 'campo2' => "<b>Fecha:</b>", 'dato2' => $this->factura->fecha)); $pdf_doc->add_table_row(array('campo1' => "<b>Cliente:</b>", 'dato1' => $this->fix_html($this->factura->nombrecliente), 'campo2' => "<b>" . FS_CIFNIF . ":</b>", 'dato2' => $this->factura->cifnif)); $pdf_doc->add_table_row(array('campo1' => "<b>Dirección:</b>", 'dato1' => $this->factura->direccion . ' CP: ' . $this->factura->codpostal . ' - ' . $this->factura->ciudad . ' (' . $this->factura->provincia . ')', 'campo2' => "<b>Teléfonos:</b>", 'dato2' => $this->cliente->telefono1 . ' ' . $this->cliente->telefono2)); $pdf_doc->save_table(array('cols' => array('campo1' => array('justification' => 'right'), 'dato1' => array('justification' => 'left'), 'campo2' => array('justification' => 'right'), 'dato2' => array('justification' => 'left')), 'showLines' => 0, 'width' => 520, 'shaded' => 0)); $pdf_doc->pdf->ezText("\n", 10); /// en el tipo 'firma' caben menos líneas if ($tipo == 'firma') { $lppag -= 3; } } /* * Creamos la tabla con las lineas de la factura: * * Descripción Cantidad PVP DTO Importe */ $columnas = array('alb' => '<b>' . ucfirst(FS_ALBARAN) . '</b>', 'descripcion' => '<b>Descripción</b>', 'cantidad' => '<b>Cantidad</b>', 'pvp' => '<b>PVP</b>', 'dto' => '<b>DTO</b>', 'importe' => '<b>Importe</b>'); if (!$this->impresion['print_alb']) { unset($columnas['alb']); } if (!$this->impresion['print_dto']) { unset($columnas['dto']); } $pdf_doc->new_table(); $pdf_doc->add_table_header($columnas); for ($i = $linea_actual; $linea_actual < $lppag + $i and $linea_actual < $lineasfact;) { $descripcion = $this->fix_html($lineas[$linea_actual]->descripcion); if ($this->impresion['print_ref'] and !is_null($lineas[$linea_actual]->referencia)) { $descripcion = '<b>' . $lineas[$linea_actual]->referencia . '</b> ' . $descripcion; } ////////////////// //////// CONTENIDO ////////////////// $fila = array('alb' => $lineas[$linea_actual]->albaran_numero(), 'descripcion' => $descripcion, 'cantidad' => $lineas[$linea_actual]->cantidad, 'pvp' => $this->show_precio($lineas[$linea_actual]->pvpunitario, $this->factura->coddivisa), 'dto' => $this->show_numero($lineas[$linea_actual]->dtopor, 0) . " %", 'importe' => $this->show_precio($lineas[$linea_actual]->pvptotal, $this->factura->coddivisa)); $pdf_doc->add_table_row($fila); $linea_actual++; } $pdf_doc->save_table(array('fontSize' => 8, 'cols' => array('cantidad' => array('justification' => 'right'), 'pvp' => array('justification' => 'right'), 'dto' => array('justification' => 'right'), 'importe' => array('justification' => 'right')), 'width' => 520, 'shaded' => 0)); if ($linea_actual == count($lineas)) { /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /* * Añadimos la parte de la firma y las observaciones, * para el tipo 'firma' */ if ($tipo == 'firma') { $pdf_doc->pdf->ezText("\n", 9); $pdf_doc->new_table(); $pdf_doc->add_table_header(array('campo1' => "<b>Observaciones</b>", 'campo2' => "<b>Firma</b>")); $pdf_doc->add_table_row(array('campo1' => $this->fix_html($this->factura->observaciones), 'campo2' => "")); $pdf_doc->save_table(array('cols' => array('campo1' => array('justification' => 'left'), 'campo2' => array('justification' => 'right', 'width' => 100)), 'showLines' => 4, 'width' => 530, 'shaded' => 0)); } else { if ($this->factura->observaciones != '') { $pdf_doc->pdf->ezText("\n" . $this->fix_html($this->factura->observaciones), 9); } } if (!$this->factura->pagada) { $fp0 = new forma_pago(); $forma_pago = $fp0->get($this->factura->codpago); if ($forma_pago) { if (is_null($forma_pago->codcuenta)) { $pdf_doc->pdf->ezText("\n<b>Forma de pago</b>: " . $forma_pago->descripcion . "\n<b>Vencimiento</b>: " . $this->factura->vencimiento, 9); } else { $texto_pago = "\n<b>Forma de pago</b>: " . $forma_pago->descripcion; if ($forma_pago->domiciliado) { $cbc0 = new cuenta_banco_cliente(); $encontrada = FALSE; foreach ($cbc0->all_from_cliente($this->factura->codcliente) as $cbc) { if ($cbc->iban) { $texto_pago .= "\n<b>Domiciliado en</b>: " . $cbc->iban; } else { $texto_pago .= "\n<b>Domiciliado en</b>: " . $cbc->swift; } $encontrada = TRUE; break; } if (!$encontrada) { $texto_pago .= "\n<b>El cliente no tiene cuenta bancaria asignada.</b>"; } } else { $cb0 = new cuenta_banco(); $cuenta_banco = $cb0->get($forma_pago->codcuenta); if ($cuenta_banco) { if ($cuenta_banco->iban) { $texto_pago .= "\n<b>IBAN</b>: " . $cuenta_banco->iban; } else { $texto_pago .= "\n<b>SWIFT o BIC</b>: " . $cuenta_banco->swift; } } } $texto_pago .= "\n<b>Vencimiento</b>: " . $this->factura->vencimiento; $pdf_doc->pdf->ezText($texto_pago, 9); } } } } $pdf_doc->set_y(80); /* * Rellenamos la última tabla de la página: * * Página Neto IVA Total */ $pdf_doc->new_table(); $titulo = array('pagina' => '<b>Página</b>', 'neto' => '<b>Neto</b>'); $fila = array('pagina' => $pagina . '/' . ceil(count($lineas) / $lppag), 'neto' => $this->show_precio($this->factura->neto, $this->factura->coddivisa)); $opciones = array('cols' => array('neto' => array('justification' => 'right')), 'showLines' => 4, 'width' => 520); foreach ($lineas_iva as $li) { $imp = $this->impuesto->get($li->codimpuesto); if ($imp) { $titulo['iva' . $li->iva] = '<b>' . $imp->descripcion . '</b>'; } else { $titulo['iva' . $li->iva] = '<b>' . FS_IVA . ' ' . $li->iva . '%</b>'; } $fila['iva' . $li->iva] = $this->show_precio($li->totaliva, $this->factura->coddivisa); if ($li->totalrecargo != 0) { $fila['iva' . $li->iva] .= ' (RE: ' . $this->show_precio($li->totalrecargo, $this->factura->coddivisa) . ')'; } $opciones['cols']['iva' . $li->iva] = array('justification' => 'right'); } if ($this->factura->totalirpf != 0) { $titulo['irpf'] = '<b>' . FS_IRPF . ' ' . $this->factura->irpf . '%</b>'; $fila['irpf'] = $this->show_precio(0 - $this->factura->totalirpf); $opciones['cols']['irpf'] = array('justification' => 'right'); } $titulo['liquido'] = '<b>Total</b>'; $fila['liquido'] = $this->show_precio($this->factura->total, $this->factura->coddivisa); $opciones['cols']['liquido'] = array('justification' => 'right'); $pdf_doc->add_table_header($titulo); $pdf_doc->add_table_row($fila); $pdf_doc->save_table($opciones); /// pié de página para la factura $pdf_doc->pdf->addText(10, 10, 8, $pdf_doc->center_text($this->fix_html($this->empresa->pie_factura), 153), 0, 1.5); $pagina++; /////////////////////////////////////////////////// } ////////// FIN DE IF DE FIRMA } } else { $pdf_doc->pdf->ezText('¡' . ucfirst(FS_FACTURA) . ' sin líneas!', 20); } if ($archivo) { if (!file_exists('tmp/' . FS_TMP_NAME . 'enviar')) { mkdir('tmp/' . FS_TMP_NAME . 'enviar'); } $pdf_doc->save('tmp/' . FS_TMP_NAME . 'enviar/' . $archivo); } else { $pdf_doc->show(FS_FACTURA . '_' . $this->factura->codigo . '.pdf'); } }
private function generar_pdf_pedido($archivo = FALSE) { if (!$archivo) { /// desactivamos la plantilla HTML $this->template = FALSE; } $pdf_doc = new fs_pdf(); $pdf_doc->pdf->addInfo('Title', ucfirst(FS_PEDIDO) . ' ' . $this->pedido->codigo); $pdf_doc->pdf->addInfo('Subject', ucfirst(FS_PEDIDO) . ' de cliente ' . $this->pedido->codigo); $pdf_doc->pdf->addInfo('Author', $this->empresa->nombre); $lineas = $this->pedido->get_lineas(); if ($lineas) { $linea_actual = 0; $lppag = 42; $pagina = 1; /// imprimimos las páginas necesarias while ($linea_actual < count($lineas)) { /// salto de página if ($linea_actual > 0) { $pdf_doc->pdf->ezNewPage(); } /// ¿Añadimos el logo? if (file_exists('tmp/' . FS_TMP_NAME . 'logo.png')) { $pdf_doc->pdf->ezImage('tmp/' . FS_TMP_NAME . 'logo.png', 0, 200, 'none'); $lppag -= 2; /// si metemos el logo, caben menos líneas } else { $pdf_doc->pdf->ezText("<b>" . $this->empresa->nombre . "</b>", 16, array('justification' => 'center')); $pdf_doc->pdf->ezText(FS_CIFNIF . ": " . $this->empresa->cifnif, 8, array('justification' => 'center')); $direccion = $this->empresa->direccion; if ($this->empresa->codpostal) { $direccion .= ' - ' . $this->empresa->codpostal; } if ($this->empresa->ciudad) { $direccion .= ' - ' . $this->empresa->ciudad; } if ($this->empresa->provincia) { $direccion .= ' (' . $this->empresa->provincia . ')'; } if ($this->empresa->telefono) { $direccion .= ' - Teléfono: ' . $this->empresa->telefono; } $pdf_doc->pdf->ezText($direccion, 9, array('justification' => 'center')); } /* * Esta es la tabla con los datos del cliente: * Pedido: Fecha: * Cliente: CIF/NIF: * Dirección: Teléfonos: */ $pdf_doc->new_table(); $pdf_doc->add_table_row(array('campo1' => "<b>" . ucfirst(FS_PEDIDO) . ":</b>", 'dato1' => $this->pedido->codigo, 'campo2' => "<b>Fecha:</b>", 'dato2' => $this->pedido->fecha)); $pdf_doc->add_table_row(array('campo1' => "<b>Cliente:</b>", 'dato1' => $this->pedido->nombrecliente, 'campo2' => "<b>" . FS_CIFNIF . ":</b>", 'dato2' => $this->pedido->cifnif)); $pdf_doc->add_table_row(array('campo1' => "<b>Dirección:</b>", 'dato1' => $this->pedido->direccion . ' CP: ' . $this->pedido->codpostal . ' - ' . $this->pedido->ciudad . ' (' . $this->pedido->provincia . ')', 'campo2' => "<b>Teléfonos:</b>", 'dato2' => $this->cliente->telefono1 . ' ' . $this->cliente->telefono2)); $pdf_doc->save_table(array('cols' => array('campo1' => array('justification' => 'right'), 'dato1' => array('justification' => 'left'), 'campo2' => array('justification' => 'right'), 'dato2' => array('justification' => 'left')), 'showLines' => 0, 'width' => 540, 'shaded' => 0)); $pdf_doc->pdf->ezText("\n", 10); /* * Creamos la tabla con las lineas del pedido: * * Descripción PVP DTO Cantidad Importe */ $pdf_doc->new_table(); $pdf_doc->add_table_header(array('descripcion' => '<b>Descripción</b>', 'cantidad' => '<b>Cantidad</b>', 'pvp' => '<b>PVP</b>', 'dto' => '<b>DTO</b>', 'importe' => '<b>Importe</b>')); $saltos = 0; $subtotal = 0; $impuestos = array(); for ($i = $linea_actual; $linea_actual < $lppag + $i and $linea_actual < count($lineas);) { if (!isset($impuestos[$lineas[$linea_actual]->iva])) { $impuestos[$lineas[$linea_actual]->iva] = $lineas[$linea_actual]->pvptotal * $lineas[$linea_actual]->iva / 100; } else { $impuestos[$lineas[$linea_actual]->iva] += $lineas[$linea_actual]->pvptotal * $lineas[$linea_actual]->iva / 100; } $fila = array('descripcion' => substr($lineas[$linea_actual]->descripcion, 0, 60), 'cantidad' => $lineas[$linea_actual]->cantidad, 'pvp' => $this->show_precio($lineas[$linea_actual]->pvpunitario, $this->pedido->coddivisa), 'dto' => $this->show_numero($lineas[$linea_actual]->dtopor, 0) . " %", 'importe' => $this->show_precio($lineas[$linea_actual]->pvptotal, $this->pedido->coddivisa)); if ($lineas[$linea_actual]->referencia != '0') { $fila['descripcion'] = substr($lineas[$linea_actual]->referencia . ' - ' . $lineas[$linea_actual]->descripcion, 0, 50); } $pdf_doc->add_table_row($fila); $saltos++; $linea_actual++; } $pdf_doc->save_table(array('fontSize' => 8, 'cols' => array('cantidad' => array('justification' => 'right'), 'pvp' => array('justification' => 'right'), 'dto' => array('justification' => 'right'), 'importe' => array('justification' => 'right')), 'width' => 540, 'shaded' => 0)); /* * Rellenamos el hueco que falta hasta donde debe aparecer la última tabla */ if ($this->pedido->observaciones == '') { $salto = ''; } else { $salto = "\n<b>Observaciones</b>: " . $this->pedido->observaciones; $saltos += count(explode("\n", $this->pedido->observaciones)) - 1; } if ($saltos < $lppag) { for (; $saltos < $lppag; $saltos++) { $salto .= "\n"; } $pdf_doc->pdf->ezText($salto, 11); } else { if ($linea_actual >= $lineasfact) { $pdf_doc->pdf->ezText($salto, 11); } else { $pdf_doc->pdf->ezText("\n", 11); } } /* * Rellenamos la última tabla de la página: * * Página Neto IVA Total */ $pdf_doc->new_table(); $titulo = array('pagina' => '<b>Página</b>', 'neto' => '<b>Neto</b>'); $fila = array('pagina' => $pagina . '/' . ceil(count($lineas) / $lppag), 'neto' => $this->show_precio($this->pedido->neto, $this->pedido->coddivisa)); $opciones = array('cols' => array('neto' => array('justification' => 'right')), 'showLines' => 4, 'width' => 540); foreach ($impuestos as $i => $value) { $titulo['iva' . $i] = '<b>IVA ' . $i . '%</b>'; $fila['iva' . $i] = $this->show_precio($value, $this->pedido->coddivisa); $opciones['cols']['iva' . $i] = array('justification' => 'right'); } if ($this->pedido->totalirpf != 0) { $titulo['irpf'] = '<b>IRPF</b>'; $fila['irpf'] = $this->show_precio(0 - $this->pedido->totalirpf); $opciones['cols']['irpf'] = array('justification' => 'right'); } $titulo['liquido'] = '<b>Total</b>'; $fila['liquido'] = $this->show_precio($this->pedido->total, $this->pedido->coddivisa); $opciones['cols']['liquido'] = array('justification' => 'right'); $pdf_doc->add_table_header($titulo); $pdf_doc->add_table_row($fila); $pdf_doc->save_table($opciones); $pdf_doc->pdf->ezText("\n", 10); $pdf_doc->pdf->addText(10, 10, 8, $pdf_doc->center_text($this->empresa->pie_factura, 153), 0, 1.5); $pagina++; } } if ($archivo) { if (!file_exists('tmp/' . FS_TMP_NAME . 'enviar')) { mkdir('tmp/' . FS_TMP_NAME . 'enviar'); } $pdf_doc->save('tmp/' . FS_TMP_NAME . 'enviar/' . $archivo); } else { $pdf_doc->show(); } }
private function generar_pdf_factura($tipo = 'simple', $archivo = FALSE) { if (!$archivo) { /// desactivamos la plantilla HTML $this->template = FALSE; } /// Creamos el PDF y escribimos sus metadatos $pdf_doc = new fs_pdf(); $pdf_doc->pdf->addInfo('Title', 'Factura ' . $this->factura->codigo); $pdf_doc->pdf->addInfo('Subject', 'Factura de cliente ' . $this->factura->codigo); $pdf_doc->pdf->addInfo('Author', $this->empresa->nombre); $lineas = $this->factura->get_lineas(); $lineas_iva = $this->factura->get_lineas_iva(); if ($lineas) { $lineasfact = count($lineas); $linea_actual = 0; $lppag = 42; /// líneas por página $pagina = 1; // Imprimimos las páginas necesarias while ($linea_actual < $lineasfact) { /// salto de página if ($linea_actual > 0) { $pdf_doc->pdf->ezNewPage(); } /* * Creamos la cabecera de la página, en este caso para el modelo carta */ if ($tipo == 'carta') { $lppag = 40; /// en el modelo carta caben menos líneas $direccion = $this->factura->nombrecliente . "\n" . $this->factura->direccion; if ($this->factura->codpostal and $this->factura->ciudad) { $direccion .= "\n CP: " . $this->factura->codpostal . ' ' . $this->factura->ciudad; } else { if ($this->factura->ciudad) { $direccion .= "\n" . $this->factura->ciudad; } } if ($this->factura->provincia) { $direccion .= "\n(" . $this->factura->provincia . ")"; } $pdf_doc->pdf->ezText("\n\n", 10); $pdf_doc->new_table(); $pdf_doc->add_table_row(array('campos' => "<b>Factura de cliente:</b>\n<b>Fecha:</b>\n<b>" . FS_CIFNIF . ":</b>", 'factura' => $this->factura->codigo . "\n" . $this->factura->fecha . "\n" . $this->factura->cifnif, 'cliente' => $direccion)); $pdf_doc->save_table(array('cols' => array('campos' => array('justification' => 'right', 'width' => 100), 'factura' => array('justification' => 'left'), 'cliente' => array('justification' => 'right')), 'showLines' => 0, 'width' => 540)); $pdf_doc->pdf->ezText("\n\n\n", 14); } else { /// ¿Añadimos el logo? if (file_exists('tmp/' . FS_TMP_NAME . 'logo.png')) { $pdf_doc->pdf->ezImage('tmp/' . FS_TMP_NAME . 'logo.png', 0, 200, 'none'); $lppag -= 2; /// si metemos el logo, caben menos líneas } else { $pdf_doc->pdf->ezText("<b>" . $this->empresa->nombre . "</b>", 16, array('justification' => 'center')); $pdf_doc->pdf->ezText(FS_CIFNIF . ": " . $this->empresa->cifnif, 8, array('justification' => 'center')); $direccion = $this->empresa->direccion; if ($this->empresa->codpostal) { $direccion .= ' - ' . $this->empresa->codpostal; } if ($this->empresa->ciudad) { $direccion .= ' - ' . $this->empresa->ciudad; } if ($this->empresa->provincia) { $direccion .= ' (' . $this->empresa->provincia . ')'; } if ($this->empresa->telefono) { $direccion .= ' - Teléfono: ' . $this->empresa->telefono; } $pdf_doc->pdf->ezText($direccion, 9, array('justification' => 'center')); } /* * Esta es la tabla con los datos del cliente: * Factura: Fecha: * Cliente: CIF/NIF: * Dirección: Teléfonos: */ $pdf_doc->new_table(); $pdf_doc->add_table_row(array('campo1' => "<b>Factura:</b>", 'dato1' => $this->factura->codigo, 'campo2' => "<b>Fecha:</b>", 'dato2' => $this->factura->fecha)); $pdf_doc->add_table_row(array('campo1' => "<b>Cliente:</b>", 'dato1' => $this->factura->nombrecliente, 'campo2' => "<b>" . FS_CIFNIF . ":</b>", 'dato2' => $this->factura->cifnif)); $pdf_doc->add_table_row(array('campo1' => "<b>Dirección:</b>", 'dato1' => $this->factura->direccion . ' CP: ' . $this->factura->codpostal . ' - ' . $this->factura->ciudad . ' (' . $this->factura->provincia . ')', 'campo2' => "<b>Teléfonos:</b>", 'dato2' => $this->cliente->telefono1 . ' ' . $this->cliente->telefono2)); $pdf_doc->save_table(array('cols' => array('campo1' => array('justification' => 'right'), 'dato1' => array('justification' => 'left'), 'campo2' => array('justification' => 'right'), 'dato2' => array('justification' => 'left')), 'showLines' => 0, 'width' => 540, 'shaded' => 0)); $pdf_doc->pdf->ezText("\n", 10); /// en el tipo 'firma' caben menos líneas if ($tipo == 'firma') { $lppag -= 10; } } /* * Creamos la tabla con las lineas de la factura: * * Descripción Cantidad PVP DTO Importe */ $pdf_doc->new_table(); $pdf_doc->add_table_header(array('descripcion' => '<b>Descripción</b>', 'cantidad' => '<b>Cantidad</b>', 'pvp' => '<b>PVP</b>', 'dto' => '<b>DTO</b>', 'importe' => '<b>Importe</b>')); $saltos = 0; for ($i = $linea_actual; $linea_actual < $lppag + $i and $linea_actual < $lineasfact;) { $fila = array('descripcion' => $lineas[$linea_actual]->descripcion, 'cantidad' => $lineas[$linea_actual]->cantidad, 'pvp' => $this->show_precio($lineas[$linea_actual]->pvpunitario, $this->factura->coddivisa), 'dto' => $this->show_numero($lineas[$linea_actual]->dtopor, 0) . " %", 'importe' => $this->show_precio($lineas[$linea_actual]->pvptotal, $this->factura->coddivisa)); $pdf_doc->add_table_row($fila); $saltos++; $linea_actual++; } $pdf_doc->save_table(array('fontSize' => 8, 'cols' => array('cantidad' => array('justification' => 'right'), 'pvp' => array('justification' => 'right'), 'dto' => array('justification' => 'right'), 'importe' => array('justification' => 'right')), 'width' => 540, 'shaded' => 0)); /* * Rellenamos el hueco que falta hasta donde debe aparecer la última tabla */ if ($this->factura->observaciones == '' or $tipo == 'firma') { $salto = ''; } else { $salto = "\n<b>Observaciones</b>: " . $this->factura->observaciones; $saltos += count(explode("\n", $this->factura->observaciones)) - 1; } if ($saltos < $lppag) { for (; $saltos < $lppag; $saltos++) { $salto .= "\n"; } $pdf_doc->pdf->ezText($salto, 11); } else { if ($linea_actual >= $lineasfact) { $pdf_doc->pdf->ezText($salto, 11); } else { $pdf_doc->pdf->ezText("\n", 11); } } /* * Rellenamos la última tabla de la página: * * Página Neto IVA Total */ $pdf_doc->new_table(); $titulo = array('pagina' => '<b>Página</b>', 'neto' => '<b>Neto</b>'); $fila = array('pagina' => $pagina . '/' . ceil(count($lineas) / $lppag), 'neto' => $this->show_precio($this->factura->neto, $this->factura->coddivisa)); $opciones = array('cols' => array('neto' => array('justification' => 'right')), 'showLines' => 4, 'width' => 540); foreach ($lineas_iva as $li) { $imp = $this->impuesto->get($li->codimpuesto); if ($imp) { $titulo['iva' . $li->iva] = '<b>' . $imp->descripcion . '</b>'; } else { $titulo['iva' . $li->iva] = '<b>IVA ' . $li->iva . '%</b>'; } $fila['iva' . $li->iva] = $this->show_precio($li->totaliva, $this->factura->coddivisa); $opciones['cols']['iva' . $li->iva] = array('justification' => 'right'); } if ($this->factura->totalirpf != 0) { $titulo['irpf'] = '<b>IRPF</b>'; $fila['irpf'] = $this->show_precio(0 - $this->factura->totalirpf); $opciones['cols']['irpf'] = array('justification' => 'right'); } $titulo['liquido'] = '<b>Total</b>'; $fila['liquido'] = $this->show_precio($this->factura->total, $this->factura->coddivisa); $opciones['cols']['liquido'] = array('justification' => 'right'); $pdf_doc->add_table_header($titulo); $pdf_doc->add_table_row($fila); $pdf_doc->save_table($opciones); /* * Añadimos la parte de la firma y las observaciones, * para el tipo 'firma' */ if ($tipo == 'firma') { $pdf_doc->new_table(); $pdf_doc->add_table_row(array('campo1' => "<b>Observaciones</b>", 'campo2' => "<b>Firma</b>")); $pdf_doc->add_table_row(array('campo1' => $this->factura->observaciones, 'campo2' => "")); $pdf_doc->save_table(array('cols' => array('campo1' => array('justification' => 'left'), 'campo2' => array('justification' => 'right')), 'showLines' => 0, 'width' => 540, 'shaded' => 0)); } /// pié de página para la factura if ($tipo == 'simple' or $tipo == 'firma') { $pdf_doc->pdf->addText(10, 10, 8, $pdf_doc->center_text($this->empresa->pie_factura, 153), 0, 1.5); } $pagina++; } } if ($archivo) { if (!file_exists('tmp/' . FS_TMP_NAME . 'enviar')) { mkdir('tmp/' . FS_TMP_NAME . 'enviar'); } $pdf_doc->save('tmp/' . FS_TMP_NAME . 'enviar/' . $archivo); } else { $pdf_doc->show(); } }
public function libro_mayor_ver(&$subc, $mes, $codejercicio, $echos = FALSE) { if ($subc) { /* if( !file_exists('tmp/'.FS_TMP_NAME.'libro_mayor') ) mkdir('tmp/'.FS_TMP_NAME.'libro_mayor'); if( !file_exists('tmp/'.FS_TMP_NAME.'libro_mayor/'.$subc->idsubcuenta.'-'.$mes.'-'.$subc->codejercicio.'.pdf') ) { */ if ($echos) { echo '.'; } $pdf_doc = new fs_pdf(); $pdf_doc->pdf->addInfo('Title', 'Libro mayor de ' . $subc->codsubcuenta); $pdf_doc->pdf->addInfo('Subject', 'Libro mayor de ' . $subc->codsubcuenta); $pdf_doc->pdf->addInfo('Author', $this->empresa->nombre); $pdf_doc->pdf->ezStartPageNumbers(590, 10, 10, 'left', '{PAGENUM} de {TOTALPAGENUM}'); $partidas = $subc->get_partidas_libros_ver($mes, $codejercicio, $offset = 0); if ($partidas) { $lineasfact = count($partidas); $linea_actual = 0; $lppag = $lineasfact; // Imprimimos las páginas necesarias while ($linea_actual < $lineasfact) { /// salto de página if ($linea_actual > 0) { $pdf_doc->pdf->ezNewPage(); } ///// Primer encabezado $pdf_doc->pdf->ezText("<b>" . $this->empresa->nombre . "</b>", 14, array('justification' => 'left')); $pdf_doc->pdf->ezText("<b>Libro Mayor</b>", 12, array('justification' => 'center')); $pdf_doc->pdf->ezText("\n", 10); $pdf_doc->pdf->ezText("Fecha/Hora impresión: " . Date('d-m-Y - H:i:s'), 10, array('justification' => 'left')); $pdf_doc->pdf->ezText("\n", 10); $pdf_doc->new_table(); $pdf_doc->add_table_row(array('subcuenta' => "<b>Subcuenta: </b>" . $subc->codsubcuenta, 'descripcion' => $subc->descripcion, 'alias' => "<b>Alias: </b>" . $subc->alias, 'periodo' => "<b>Periodo: </b>" . $subc->get_nom_mes($mes) . ' ' . $subc->codejercicio)); $pdf_doc->save_table(array('cols' => array('campos' => array('justification' => 'right', 'width' => 70), 'factura' => array('justification' => 'left')), 'showLines' => 0, 'width' => 540)); $pdf_doc->pdf->ezText("\n", 10); /// Creamos la tabla con las lineas $pdf_doc->new_table(); $pdf_doc->add_table_row(array('asiento' => "", 'fecha' => "", 'concepto' => "Saldo Anterior", 'debe' => "", 'haber' => "", 'saldo' => $subc->get_partidas_saldo_anterior_ver($mes, $codejercicio))); $pdf_doc->add_table_header(array('asiento' => '<b>Asiento</b>', 'fecha' => '<b>Fecha</b>', 'concepto' => '<b>Concepto</b>', 'debe' => '<b>Debe</b>', 'haber' => '<b>Haber</b>', 'saldo' => '<b>Saldo</b>')); for ($i = $linea_actual; $linea_actual < $lppag + $i and $linea_actual < $lineasfact;) { $pdf_doc->add_table_row(array('asiento' => $partidas[$linea_actual]->numero, 'fecha' => $partidas[$linea_actual]->fecha, 'concepto' => substr($partidas[$linea_actual]->concepto, 0, 60), 'debe' => $this->show_numero($partidas[$linea_actual]->debe), 'haber' => $this->show_numero($partidas[$linea_actual]->haber), 'saldo' => $this->show_numero($partidas[$linea_actual]->saldo))); $a = $linea_actual; $linea_actual++; } /// añadimos las sumas de la línea actual $pdf_doc->add_table_row(array('asiento' => '', 'fecha' => '', 'concepto' => '', 'debe' => '<b>' . $this->show_numero($partidas[$linea_actual - 1]->sum_debe) . '</b>', 'haber' => '<b>' . $this->show_numero($partidas[$linea_actual - 1]->sum_haber) . '</b>', 'saldo' => '')); $pdf_doc->save_table(array('fontSize' => 8, 'cols' => array('debe' => array('justification' => 'right'), 'haber' => array('justification' => 'right'), 'saldo' => array('justification' => 'right')), 'width' => 540, 'shaded' => 0)); } } $pdf_doc->pdf->ezText("\n", 18); $pdf_doc->pdf->ezText("<b>Total Debe : </b>" . $this->show_numero($partidas[$linea_actual - 1]->sum_debe), 12, array('justification' => 'left')); $pdf_doc->pdf->ezText("\n", 12); $pdf_doc->pdf->ezText("<b>Total Haber : </b>" . $this->show_numero($partidas[$linea_actual - 1]->sum_haber), 12, array('justification' => 'left')); $pdf_doc->pdf->ezText("\n", 12); $pdf_doc->pdf->ezText("<b>Saldo : </b>" . $this->show_numero($partidas[$linea_actual - 1]->saldo), 12, array('justification' => 'left')); $pdf_doc->show(); // $pdf_doc->save('tmp/'.FS_TMP_NAME.'libro_mayor/'.$subc->idsubcuenta.'-'.$mes.'-'.$subc->codejercicio.'.pdf'); // } } }