factura_ncf::checkLogo()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
cc 3
eloc 5
c 1
b 1
f 0
nc 3
nop 0
dl 0
loc 7
rs 10
1
<?php
2
/**
3
 * This file is part of FacturaScripts
4
 * Copyright (C) 2014  Valentín González    [email protected]
5
 * Copyright (C) 2014-2015  Carlos Garcia Gomez  [email protected]
6
 *
7
 * This program is free software: you can redistribute it and/or modify
8
 * it under the terms of the GNU Lesser General Public License as
9
 * published by the Free Software Foundation, either version 3 of the
10
 * License, or (at your option) any later version.
11
 *
12
 * This program is distributed in the hope that it will be useful,
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
 * GNU Lesser General Public License for more details.
16
 *
17
 * You should have received a copy of the GNU Lesser General Public License
18
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
19
 */
20
require_once 'plugins/republica_dominicana/extras/fpdf181/fs_fpdf.php';
21
require_once 'plugins/republica_dominicana/extras/rd_controller.php';
22
require_once 'extras/phpmailer/class.phpmailer.php';
23
require_once 'extras/phpmailer/class.smtp.php';
24
define('FPDF_FONTPATH', 'plugins/republica_dominicana/extras/fpdf181/font/');
25
define('EEURO', chr(128));
26
class factura_ncf extends rd_controller
27
{
28
    public $cliente;
29
    public $factura;
30
    public $documento;
31
    public $ncf_ventas;
32
    public $distrib_transporte;
33
    public $idtransporte;
34
    public $archivo;
35
    public $agente;
36
    public $logo;
37
    public $negativo;
38
39
    public function __construct()
40
    {
41
        parent::__construct(__CLASS__, 'Factura NCF', 'ventas', false, false);
42
    }
43
44
    protected function private_core()
45
    {
46
        parent::private_core();
47
        $this->template = false;
48
        $this->agente = new agente();
0 ignored issues
show
Bug introduced by
The type agente was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
49
50
        $this->share_extensions();
51
        $this->checkLogo();
52
        $val_id = \filter_input(INPUT_GET, 'id');
53
        $solicitud = \filter_input(INPUT_GET, 'solicitud');
54
        $valores_id = explode(',', $val_id);
55
56
        if (class_exists('distribucion_ordenescarga_facturas')) {
57
            $this->distrib_transporte = new distribucion_ordenescarga_facturas();
0 ignored issues
show
Bug introduced by
The type distribucion_ordenescarga_facturas was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
58
        }
59
60
        if (!empty($valores_id[0]) and $solicitud == 'imprimir') {
61
            $this->procesar_facturas($valores_id);
62
        } elseif (!empty($valores_id[0]) and $solicitud == 'email') {
63
            $this->enviar_email($valores_id[0]);
64
        }
65
    }
66
67
    public function checkLogo()
68
    {
69
        $this->logo = false;
70
        if (file_exists(FS_MYDOCS . 'images/logo.png')) {
0 ignored issues
show
Bug introduced by
The constant FS_MYDOCS was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
71
            $this->logo = 'images/logo.png';
72
        } elseif (file_exists(FS_MYDOCS . 'images/logo.jpg')) {
73
            $this->logo = 'images/logo.jpg';
74
        }
75
    }
76
77
    // Corregir el Bug de fpdf con el Simbolo del Euro ---> €
78
    public function ckeckEuro($cadena)
79
    {
80
        $mostrar = '';
81
        if (!empty($cadena)) {
82
            $mostrar = $this->show_precio($cadena, $this->factura->coddivisa);
83
            $pos = strpos($mostrar, '€');
84
            if ($pos !== false) {
85
                if (FS_POS_DIVISA == 'right') {
0 ignored issues
show
Bug introduced by
The constant FS_POS_DIVISA was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
86
                    return number_format($cadena, FS_NF0, FS_NF1, FS_NF2) . ' ' . EEURO;
87
                } else {
88
                    return EEURO . ' ' . number_format($cadena, FS_NF0, FS_NF1, FS_NF2);
89
                }
90
            }
91
        }
92
        return $mostrar;
93
    }
94
95
    public function checkPorcentaje($cadena)
96
    {
97
        $mostrar = '';
98
        if (!empty($cadena)) {
99
            $mostrar = $cadena.'%';
100
        }
101
        return $mostrar;
102
    }
103
104
    public function checkFechaVencimiento($ncf_datos, $tipo_comprobante)
105
    {
106
        if (isset($ncf_datos)) {
107
            $fecha_vencimiento_comprobante = \date("d-m-Y", \strtotime($ncf_datos));
108
        } else {
109
            $fecha_vencimiento_comprobante = \date("d-m-Y", \strtotime($tipo_comprobante));
110
        }
111
112
        return $fecha_vencimiento_comprobante;
113
    }
114
115
    public function procesar_facturas($valores_id, $archivo = false)
116
    {
117
        if (!empty($valores_id)) {
118
            if (ob_get_status()) {
119
                ob_end_clean();
120
            }
121
            $pdf_doc = new PDF_MC_Table('P', 'mm', 'letter');
0 ignored issues
show
Bug introduced by
The type PDF_MC_Table was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
122
            $pdf_doc->SetTitle('Facturas de Venta');
123
            $pdf_doc->SetSubject('Facturas de Venta para clientes');
124
            $pdf_doc->SetAuthor($this->empresa->nombre);
125
            $pdf_doc->SetCreator('FacturaScripts V_' . $this->version());
126
            $pdf_doc->SetFont('Arial', '', 8);
127
            $this->archivo = $archivo;
128
            $contador = 0;
129
            foreach ($valores_id as $id) {
130
                $factura = new factura_cliente();
131
                $this->factura = $factura->get($id);
132
                if ($this->factura) {
133
                    $ncf_datos = new ncf_ventas();
134
                    $valores = $ncf_datos->get_ncf(
135
                        $this->empresa->id,
136
                        $this->factura->idfactura,
137
                        $this->factura->codcliente
138
                    );
139
                    $ncf_tipo = new ncf_tipo();
140
                    $ncf_rango = new ncf_rango();
141
                    $tipo_comprobante = $ncf_tipo->get($valores->tipo_comprobante);
142
                    $tipo_comprobante_data = $ncf_rango->get_by_tipo(
143
                        $this->empresa->id,
144
                        $tipo_comprobante->tipo_comprobante
145
                    );
146
                    $this->factura->ncf = $valores->ncf;
147
                    $this->factura->ncf_afecta = $valores->ncf_modifica;
148
                    $this->factura->estado = $valores->estado;
149
                    $this->factura->tipo_comprobante = ($tipo_comprobante) ? $tipo_comprobante->descripcion : '';
150
                    $this->factura->fecha_vencimiento_comprobante = '';
151
                    if (in_array($tipo_comprobante->tipo_comprobante, array('02', '04'), true)===false) {
152
                        $this->factura->fecha_vencimiento_comprobante = $this->checkFechaVencimiento(
153
                            $valores->fecha_vencimiento,
154
                            $tipo_comprobante_data->fecha_vencimiento
155
                        );
156
                    }
157
                    if ($this->distrib_transporte) {
158
                        $transporte = $this->distrib_transporte->get(
159
                            $this->empresa->id,
160
                            $this->factura->idfactura,
161
                            $this->factura->codalmacen
162
                        );
163
                        $this->idtransporte =
164
                            (isset($transporte[0]->idtransporte))?
165
                            str_pad($transporte[0]->idtransporte, 10, "0", STR_PAD_LEFT):
166
                            false;
167
                    }
168
                    $cliente = new cliente();
0 ignored issues
show
Bug introduced by
The type cliente was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
169
                    $this->cliente = $cliente->get($this->factura->codcliente);
170
                    $this->generar_pdf($pdf_doc);
171
                    $contador++;
172
                }
173
            }
174
            if ($this->archivo) {
175
                if (!file_exists('tmp/' . FS_TMP_NAME . 'enviar')) {
0 ignored issues
show
Bug introduced by
The constant FS_TMP_NAME was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
176
                    mkdir('tmp/' . FS_TMP_NAME . 'enviar');
177
                }
178
                $pdf_doc->Output('tmp/' . FS_TMP_NAME . 'enviar/' . $archivo, 'F');
179
            } else {
180
                $pdf_doc->Output();
181
            }
182
            if (!$this->factura) {
183
                $this->new_error_msg("¡Factura de cliente no encontrada!");
184
            }
185
        }
186
    }
187
188
    private function enviar_email($doc, $tipo = 'ncf')
189
    {
190
        $factura = new factura_cliente();
191
        $factura_enviar = $factura->get($doc);
192
        $cliente = new cliente();
193
        $this->cliente = $cliente->get($factura_enviar->codcliente);
194
        if ($this->empresa->can_send_mail()) {
195
            if ($_POST['email'] != $this->cliente->email and isset($_POST['guardar'])) {
196
                $this->cliente->email = $_POST['email'];
197
                $this->cliente->save();
198
            }
199
200
            $filename = 'factura_' . $factura_enviar->numero2 . '.pdf';
201
            if ($tipo == 'ncf') {
202
                $this->procesar_facturas(array($factura_enviar->idfactura), $filename);
203
            }
204
205
206
            if (file_exists('tmp/' . FS_TMP_NAME . 'enviar/' . $filename)) {
0 ignored issues
show
Bug introduced by
The constant FS_TMP_NAME was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
207
                $mail = $this->empresa->new_mail();
208
                $mail->FromName = $this->user->get_agente_fullname();
209
                $mail->addReplyTo($_POST['de'], $mail->FromName);
210
211
                $mail->addAddress($_POST['email'], $this->cliente->razonsocial);
212
                if ($_POST['email_copia']) {
213
                    if (isset($_POST['cco'])) {
214
                        $mail->addBCC($_POST['email_copia'], $this->cliente->razonsocial);
215
                    } else {
216
                        $mail->addCC($_POST['email_copia'], $this->cliente->razonsocial);
217
                    }
218
                }
219
                $mail->Subject = $this->empresa->nombre . ': Su factura ' . $this->factura->codigo;
220
221
                $mail->AltBody = $_POST['mensaje'];
222
                $mail->msgHTML(nl2br($_POST['mensaje']));
223
                $mail->isHTML(true);
224
225
                $mail->addAttachment('tmp/' . FS_TMP_NAME . 'enviar/' . $filename);
226
                if (is_uploaded_file($_FILES['adjunto']['tmp_name'])) {
227
                    $mail->addAttachment($_FILES['adjunto']['tmp_name'], $_FILES['adjunto']['name']);
228
                }
229
230
                if ($mail->smtpConnect($this->empresa->smtp_options())) {
231
                    if ($mail->send()) {
232
                        $this->template = 'ventas_imprimir';
233
                        $this->new_message('Mensaje enviado correctamente.');
234
                        $this->documento = $this->factura;
235
236
                        /// nos guardamos la fecha de envío
237
                        $factura_enviar->femail = $this->today();
238
                        $factura_enviar->save();
239
240
                        $this->empresa->save_mail($mail);
241
                    } else {
242
                        $this->new_error_msg("Error al enviar el email: " . $mail->ErrorInfo);
243
                    }
244
                } else {
245
                    $this->new_error_msg("Error al enviar el email: " . $mail->ErrorInfo);
246
                }
247
248
                unlink('tmp/' . FS_TMP_NAME . 'enviar/' . $filename);
249
            } else {
250
                $this->new_error_msg('Imposible generar el PDF.');
251
            }
252
        }
253
    }
254
255
    public function pdf_informacion_empresa($pdf_doc)
256
    {
257
        $vendedor = $this->agente->get($this->factura->codagente);
258
        $pdf_doc->fde_nombre = $this->empresa->nombre;
259
        $pdf_doc->fde_FS_CIFNIF = FS_CIFNIF;
260
        $pdf_doc->fde_cifnif = $this->empresa->cifnif;
261
        $pdf_doc->fde_direccion = $this->empresa->direccion;
262
        $pdf_doc->fde_codpostal = $this->empresa->codpostal;
263
        $pdf_doc->fde_ciudad = $this->empresa->ciudad;
264
        $pdf_doc->fde_provincia = $this->empresa->provincia;
265
        $pdf_doc->fde_telefono = 'Teléfono: ' . $this->empresa->telefono;
266
        $pdf_doc->fde_fax = 'Fax: ' . $this->empresa->fax;
267
        $pdf_doc->fde_email = $this->empresa->email;
268
        $pdf_doc->fde_web = $this->empresa->web;
269
        $pdf_doc->fde_vendedor = '';
270
        if (in_array('distribucion', $GLOBALS['plugins'])) {
271
            $pdf_doc->fde_vendedor = $vendedor->nombreap;
272
            $pdf_doc->fdf_ruta = $this->factura->codruta;
273
            $pdf_doc->fde_ruta = $this->factura->codruta;
274
            $pdf_doc->fdf_transporte = $this->idtransporte;
275
        }
276
        $pdf_doc->fde_piefactura = $this->empresa->pie_factura;
277
    }
278
279
    public function configuracion_pdf($pdf_doc)
280
    {
281
        $pdf_doc->fdf_verlogotipo = ($this->rd_setup['rd_imprimir_logo'] == 'TRUE' and $this->logo) ? '1' : '0';
282
        $pdf_doc->fdf_Xlogotipo = ($this->rd_setup['rd_imprimir_logo'] == 'TRUE' and $this->logo) ? '10' : '0';
283
        $pdf_doc->fdf_Ylogotipo = ($this->rd_setup['rd_imprimir_logo'] == 'TRUE' and $this->logo) ? '5' : '0';
284
        $pdf_doc->fdf_vermarcaagua = ($this->rd_setup['rd_imprimir_marca_agua'] == 'TRUE' and $this->logo) ? '1' : '0';
285
        $pdf_doc->fdf_Xmarcaagua = ($this->rd_setup['rd_imprimir_marca_agua'] == 'TRUE' and $this->logo) ? '25' : '0';
286
        $pdf_doc->fdf_Ymarcaagua = ($this->rd_setup['rd_imprimir_marca_agua'] == 'TRUE' and $this->logo) ? '110' : '0';
287
        $pdf_doc->fdf_verSelloPagado = (isset($this->rd_setup['rd_imprimir_sello_pagado']) && $this->rd_setup['rd_imprimir_sello_pagado'] == 'TRUE') ? '1' : '0';
288
        $pdf_doc->fdf_Xsellopagado = (isset($this->rd_setup['rd_imprimir_sello_pagado']) && $this->rd_setup['rd_imprimir_sello_pagado'] == 'TRUE') ? '65' : '0';
289
        $pdf_doc->fdf_Ysellopagado = (isset($this->rd_setup['rd_imprimir_sello_pagado']) && $this->rd_setup['rd_imprimir_sello_pagado'] == 'TRUE') ? '180' : '0';
290
291
        $pdf_doc->fdf_imprimir_bn = ($this->rd_setup['rd_imprimir_bn'] == 'TRUE') ? '1' : '0';
292
        $pdf_doc->fdf_cliente_box = ($this->rd_setup['rd_imprimir_cliente_box'] == 'TRUE') ? '1' : '0';
293
        $pdf_doc->fdf_detalle_box = ($this->rd_setup['rd_imprimir_detalle_box'] == 'TRUE') ? '1' : '0';
294
        $pdf_doc->fdf_detalle_lineas = ($this->rd_setup['rd_imprimir_detalle_lineas'] == 'TRUE') ? '1' : '0';
295
        $pdf_doc->fdf_detalle_colores = ($this->rd_setup['rd_imprimir_detalle_colores'] == 'TRUE') ? '1' : '0';
296
        $pdf_doc->fdf_cabecera_fcolor = ($this->rd_setup['rd_imprimir_bn'] == 'FALSE') ? $this->rd_setup['rd_imprimir_cabecera_fcolor'] : false;
297
        $pdf_doc->fdf_cabecera_tcolor = ($this->rd_setup['rd_imprimir_bn'] == 'FALSE') ? $this->rd_setup['rd_imprimir_cabecera_tcolor'] : false;
298
        $pdf_doc->fdf_detalle_color = ($this->rd_setup['rd_imprimir_detalle_colores'] == 'TRUE') ? $this->rd_setup['rd_imprimir_detalle_color'] : '#000000';
299
    }
300
301
    public function pdf_tipo_documento($pdf_doc)
302
    {
303
        // Tipo de Documento
304
        $pdf_doc->fdf_documento = $this->factura;
305
        $pdf_doc->fdf_tipodocumento = $this->factura->tipo_comprobante;
306
        $pdf_doc->fdf_codigo = $this->factura->ncf;
307
        $pdf_doc->fdf_codigorect = $this->factura->ncf_afecta;
308
        $pdf_doc->fdf_tipodocumento_vencimiento = $this->factura->fecha_vencimiento_comprobante;
309
        $pdf_doc->fdf_estado = ($this->factura->estado) ? "" : "DOCUMENTO ANULADO";
310
    }
311
312
    public function pdf_datos_cliente($pdf_doc)
313
    {
314
        // Fecha, Codigo Cliente y observaciones de la factura
315
        $pdf_doc->fdf_fecha = $this->factura->fecha;
316
        $pdf_doc->fdf_vencimiento = $this->factura->vencimiento;
317
        $pdf_doc->fdf_codcliente = $this->factura->codcliente;
318
        $pdf_doc->fdf_observaciones = utf8_decode($this->fix_html($this->factura->observaciones));
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->fix_html($this->factura->observaciones) targeting factura_ncf::fix_html() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
Bug introduced by
$this->fix_html($this->factura->observaciones) of type void is incompatible with the type string expected by parameter $string of utf8_decode(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

318
        $pdf_doc->fdf_observaciones = utf8_decode(/** @scrutinizer ignore-type */ $this->fix_html($this->factura->observaciones));
Loading history...
319
320
321
        // Datos del Cliente
322
        $pdf_doc->fdf_nombrecliente = $this->fix_html($this->factura->nombrecliente);
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $pdf_doc->fdf_nombrecliente is correct as $this->fix_html($this->factura->nombrecliente) targeting factura_ncf::fix_html() seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
323
        $pdf_doc->fdf_FS_CIFNIF = FS_CIFNIF;
324
        $pdf_doc->fdf_cifnif = $this->factura->cifnif;
325
        $pdf_doc->fdf_direccion = $this->fix_html($this->factura->direccion);
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $pdf_doc->fdf_direccion is correct as $this->fix_html($this->factura->direccion) targeting factura_ncf::fix_html() seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
326
        $pdf_doc->fdf_codpostal = $this->factura->codpostal;
327
        $pdf_doc->fdf_ciudad = $this->factura->ciudad;
328
        $pdf_doc->fdf_provincia = $this->factura->provincia;
329
        $pdf_doc->fdc_telefono1 = $this->cliente->telefono1;
330
        $pdf_doc->fdc_telefono2 = $this->cliente->telefono2;
331
        $pdf_doc->fdc_fax = $this->cliente->fax;
332
        $pdf_doc->fdc_email = $this->cliente->email;
333
        $pdf_doc->fdc_factura_codigo = $this->factura->codigo;
334
        $pdf_doc->fdf_epago = $pdf_doc->fdf_divisa = $pdf_doc->fdf_pais = '';
335
    }
336
337
    public function pdf_divisa_pago_pais($pdf_doc)
338
    {
339
        // Forma de Pago de la Factura
340
        $pago = new forma_pago();
0 ignored issues
show
Bug introduced by
The type forma_pago was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
341
        $epago = $pago->get($this->factura->codpago);
342
        if ($epago) {
343
            $pdf_doc->fdf_epago = $epago->descripcion;
344
        }
345
346
        // Divisa de la Factura
347
        $divisa = new divisa();
0 ignored issues
show
Bug introduced by
The type divisa was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
348
        $edivisa = $divisa->get($this->factura->coddivisa);
349
        if ($edivisa) {
350
            $pdf_doc->fdf_divisa = $edivisa->descripcion;
351
        }
352
353
        // Pais de la Factura
354
        $pais = new pais();
0 ignored issues
show
Bug introduced by
The type pais was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
355
        $epais = $pais->get($this->factura->codpais);
356
        if ($epais) {
357
            $pdf_doc->fdf_pais = $epais->nombre;
358
        }
359
    }
360
361
    public function pdf_cabecera_titulo_columnas($pdf_doc)
362
    {
363
        list($r, $g, $b) = $pdf_doc->htmlColor2Hex($pdf_doc->fdf_detalle_color);
364
        // Cabecera Titulos Columnas
365
        $pdf_doc->Setdatoscab(array('ARTICULO', 'DESCRIPCION', 'CANT', 'P. UNIT', 'IMPORTE', 'DSCTO', FS_IVA, 'NETO'));
366
        $pdf_doc->SetWidths(array(20, 68, 12, 15, 20, 20, 16, 25));
367
        $pdf_doc->SetAligns(array('L', 'L', 'R', 'R', 'R', 'R', 'R', 'R'));
368
        $colores = ($this->rd_setup['rd_imprimir_bn'] == 'FALSE') ? $r . '|' . $g . '|' . $b : '0|0|0';
369
        $pdf_doc->SetColors(array($colores, $colores, $colores, $colores, $colores, $colores, $colores, $colores));
370
    }
371
372
    public function pdf_lineas_iva($pdf_doc)
373
    {
374
        $lineas_iva = $this->factura->get_lineas_iva();
375
        if (count($lineas_iva) > 3) {
376
            $pdf_doc->fdf_lineasiva = $lineas_iva;
377
        } else {
378
            $filaiva = array(); $i = 0;
379
            foreach ($lineas_iva as $li) {
380
                $i++;
381
                $filaiva[$i][0] = '';
382
                $filaiva[$i][1] = $this->ckeckEuro(($li->neto * $this->negativo));
383
                $filaiva[$i][2] = $this->checkPorcentaje(($li->iva * $this->negativo));
384
                $filaiva[$i][3] = $this->ckeckEuro(($li->totaliva * $this->negativo));
385
                $filaiva[$i][4] = $this->checkPorcentaje($li->recargo);
386
                $filaiva[$i][5] = $this->ckeckEuro(($li->totalrecargo * $this->negativo));
387
                $filaiva[$i][6] = '';
388
                $filaiva[$i][7] = '';
389
                $filaiva[$i][8] = $this->ckeckEuro(($li->totallinea * $this->negativo));
390
            }
391
            if (!empty($filaiva)) {
392
                $filaiva[1][6] = $this->factura->irpf . ' %';
393
                $filaiva[1][7] = $this->ckeckEuro(0 - ($this->factura->totalirpf * $this->negativo));
394
            }
395
            $pdf_doc->fdf_lineasiva = $filaiva;
396
        }
397
    }
398
399
    public function pdf_lineas_factura($pdf_doc)
400
    {
401
         // Lineas de la Factura
402
        $lineas = $this->factura->get_lineas();
403
        $cantidad_lineas = count($lineas);
404
        $lineas_restantes = count($lineas);
405
        $neto = 0;
406
        $descuento = 0;
407
        for ($i = 0; $i < $cantidad_lineas; $i++) {
408
            $pdf_doc->piepagina = false;
409
            $neto += ($lineas[$i]->pvptotal * $this->negativo);
410
            $linea_impuesto = (($lineas[$i]->pvptotal * $this->negativo) * ($lineas[$i]->iva / 100));
411
            $linea_neto = ($lineas[$i]->pvptotal * $this->negativo) * (1 + ($lineas[$i]->iva / 100));
412
            $descuento_linea = ($lineas[$i]->dtopor) ? (($lineas[$i]->pvpunitario * $this->negativo) * ($lineas[$i]->cantidad * $this->negativo)) * ($lineas[$i]->dtopor / 100) : 0;
413
            $descuento += $descuento_linea;
414
            $pdf_doc->neto = $this->ckeckEuro($neto);
415
            $articulo = new articulo();
416
            $art = $articulo->get($lineas[$i]->referencia);
417
            if ($art) {
418
                $observa = "\n" . utf8_decode($this->fix_html($art->observaciones));
0 ignored issues
show
Bug introduced by
$this->fix_html($art->observaciones) of type void is incompatible with the type string expected by parameter $string of utf8_decode(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

418
                $observa = "\n" . utf8_decode(/** @scrutinizer ignore-type */ $this->fix_html($art->observaciones));
Loading history...
Bug introduced by
Are you sure the usage of $this->fix_html($art->observaciones) targeting factura_ncf::fix_html() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
419
            } else {
420
                $observa = "\n";
421
            }
422
423
            $lafila = array(
424
                '0' => utf8_decode($lineas[$i]->referencia),
425
                '1' => utf8_decode(strtoupper($lineas[$i]->descripcion)) . $observa,
426
                '2' => utf8_decode(($lineas[$i]->cantidad * $this->negativo)),
427
                '3' => $this->show_numero($lineas[$i]->pvpunitario, FS_NF0),
428
                '4' => $this->show_numero(($lineas[$i]->pvpsindto * $this->negativo), FS_NF0),
429
                '5' => ($lineas[$i]->dtopor) ? $this->show_numero($descuento_linea, FS_NF0) : '',
430
                '6' => utf8_decode($this->show_numero($linea_impuesto, FS_NF0)),
431
                '7' => utf8_decode($this->show_numero($linea_neto, FS_NF0)), // Importe con Descuentos aplicados
432
            );
433
434
            $pdf_doc->Row($lafila, '1', $lineas_restantes);
435
            $lineas_restantes--;
436
        }
437
        $pdf_doc->fdf_documento_descuentos = ($descuento) ? $this->ckeckEuro(($descuento)) : '';
438
    }
439
440
    public function generar_pdf($pdf_doc)
441
    {
442
        if (!empty($pdf_doc)) {
443
            ///// INICIO - Factura Detallada
444
            /// Creamos el PDF y escribimos sus metadatos
445
446
            $pdf_doc->StartPageGroup();
447
            $pdf_doc->AliasNbPages();
448
            $pdf_doc->SetAutoPageBreak(true, 40);
449
            $pdf_doc->lineaactual = 0;
450
            $pdf_doc->fdf_observaciones = "";
451
452
            // Definimos el color de relleno (gris, rojo, verde, azul o con un codigo html)
453
            if ($this->rd_setup['rd_imprimir_bn'] == 'FALSE') {
454
                $pdf_doc->SetColorRelleno($this->rd_setup['rd_imprimir_cabecera_fcolor']);
455
            } else {
456
                $pdf_doc->SetColorRelleno('blanco');
457
            }
458
459
            $this->pdf_informacion_empresa($pdf_doc);
460
            $this->configuracion_pdf($pdf_doc);
461
            $this->pdf_tipo_documento($pdf_doc);
462
            $this->pdf_datos_cliente($pdf_doc);
463
            $this->pdf_divisa_pago_pais($pdf_doc);
464
            $this->pdf_cabecera_titulo_columnas($pdf_doc);
465
466
            /// Agregamos la pagina inicial de la factura
467
            $pdf_doc->AddPage();
468
            $this->negativo = (!empty($this->factura->idfacturarect)) ? -1 : 1;
469
            $this->pdf_lineas_iva($pdf_doc);
470
            // Total factura numerico
471
            $pdf_doc->fdf_documento_neto = $this->ckeckEuro(($this->factura->neto * $this->negativo));
472
            $pdf_doc->fdf_documento_totaliva = $this->ckeckEuro(($this->factura->totaliva * $this->negativo));
473
            $pdf_doc->fdf_numtotal = $this->ckeckEuro(($this->factura->total * $this->negativo));
474
475
            // Total factura numeros a texto
476
            $pdf_doc->fdf_textotal = ($this->factura->total * $this->negativo);
477
478
            $pdf_doc->fdf_pagada = $this->factura->pagada;
479
            $pdf_doc->fdf_fecha_pagada = '';
480
            if ($this->factura->pagada) {
481
                $dato_pago = $this->factura->get_asiento_pago();
482
                $pdf_doc->fdf_fecha_pagada = ($dato_pago)?$dato_pago->fecha:$this->factura->fecha;
483
            }
484
485
            $this->pdf_lineas_factura($pdf_doc);
486
487
            $pdf_doc->piepagina = true;
488
        }
489
    }
490
491
    private function share_extensions()
492
    {
493
        $extensiones = array(
494
            array(
495
                'name' => 'factura_ncf',
496
                'page_from' => __CLASS__,
497
                'page_to' => 'ventas_factura',
498
                'type' => 'pdf',
499
                'text' => 'Factura con NCF',
500
                'params' => '&solicitud=imprimir'
501
            ),
502
            array(
503
                'name' => 'email_factura_ncf',
504
                'page_from' => __CLASS__,
505
                'page_to' => 'ventas_factura',
506
                'type' => 'email',
507
                'text' => 'Factura con NCF',
508
                'params' => '&solicitud=email'
509
            )
510
        );
511
        foreach ($extensiones as $ext) {
512
            $fsext = new fs_extension($ext);
0 ignored issues
show
Bug introduced by
The type fs_extension was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
513
            $fsext->save();
514
        }
515
    }
516
517
    /**
518
     * Undocumented function
519
     *
520
     * @param string $txt 
521
     * 
522
     * @return void
523
     */
524
    private function fix_html($txt)
525
    {
526
        $newt1 = str_replace('&lt;', '<', $txt);
527
        $newt2 = str_replace('&gt;', '>', $newt1);
528
        $newt3 = str_replace('&quot;', '"', $newt2);
529
        $newt = str_replace('&#39;', "'", $newt3);
530
        return $newt;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $newt returns the type string which is incompatible with the documented return type void.
Loading history...
531
    }
532
}
533