ventas_facturas::private_core()   F
last analyzed

Complexity

Conditions 30
Paths > 20000

Size

Total Lines 140
Code Lines 93

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 30
eloc 93
c 1
b 0
f 0
nc 74088
nop 0
dl 0
loc 140
rs 0

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
/*
3
 * This file is part of facturacion_base
4
 * Copyright (C) 2013-2017  Carlos Garcia Gomez  [email protected]
5
 *
6
 * This program is free software: you can redistribute it and/or modify
7
 * it under the terms of the GNU Lesser General Public License as
8
 * published by the Free Software Foundation, either version 3 of the
9
 * License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU Lesser General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU Lesser General Public License
17
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18
 */
19
20
require_once 'plugins/republica_dominicana/extras/rd_controller.php';
21
22
class ventas_facturas extends rd_controller
23
{
24
25
    public $agente;
26
    public $almacenes;
27
    public $articulo;
28
    public $buscar_lineas;
29
    public $cliente;
30
    public $codagente;
31
    public $codalmacen;
32
    public $codgrupo;
33
    public $codpago;
34
    public $codserie;
35
    public $desde;
36
    public $estado;
37
    public $factura;
38
    public $forma_pago;
39
    public $grupo;
40
    public $hasta;
41
    public $huecos;
42
    public $lineas;
43
    public $mostrar;
44
    public $num_resultados;
45
    public $offset;
46
    public $order;
47
    public $resultados;
48
    public $serie;
49
    public $total_resultados;
50
    public $total_resultados_comision;
51
    public $total_resultados_txt;
52
53
    public function __construct()
54
    {
55
        parent::__construct(__CLASS__, 'Facturas', 'ventas');
56
    }
57
58
    protected function private_core()
59
    {
60
        parent::private_core();
61
62
        $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...
63
        $this->almacenes = new almacen();
0 ignored issues
show
Bug introduced by
The type almacen 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...
64
        $this->factura = new factura_cliente();
65
        $this->forma_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...
66
        $this->grupo = new grupo_clientes();
0 ignored issues
show
Bug introduced by
The type grupo_clientes 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...
67
        $this->huecos = array();
68
        $this->serie = new serie();
0 ignored issues
show
Bug introduced by
The type serie 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...
69
70
        $this->mostrar = 'todo';
71
        if (isset($_GET['mostrar'])) {
72
            $this->mostrar = $_GET['mostrar'];
73
            setcookie('ventas_fac_mostrar', $this->mostrar, time() + FS_COOKIES_EXPIRE);
0 ignored issues
show
Bug introduced by
The constant FS_COOKIES_EXPIRE was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
74
        } else if (isset($_COOKIE['ventas_fac_mostrar'])) {
75
            $this->mostrar = $_COOKIE['ventas_fac_mostrar'];
76
        }
77
78
        $this->offset = 0;
79
        if (isset($_REQUEST['offset'])) {
80
            $this->offset = intval($_REQUEST['offset']);
81
        }
82
83
        $this->order = 'fecha DESC';
84
        if (isset($_GET['order'])) {
85
            $orden_l = $this->orden();
86
            if (isset($orden_l[$_GET['order']])) {
87
                $this->order = $orden_l[$_GET['order']]['orden'];
88
            }
89
90
            setcookie('ventas_fac_order', $this->order, time() + FS_COOKIES_EXPIRE);
91
        } else if (isset($_COOKIE['ventas_fac_order'])) {
92
            $this->order = $_COOKIE['ventas_fac_order'];
93
        }
94
95
        if (isset($_POST['buscar_lineas'])) {
96
            $this->buscar_lineas();
97
        } else if (isset($_REQUEST['buscar_cliente'])) {
98
            $this->fbase_buscar_cliente($_REQUEST['buscar_cliente']);
99
        } else if (isset($_GET['ref'])) {
100
            $this->template = 'extension/ventas_facturas_articulo';
101
102
            $articulo = new articulo();
103
            $this->articulo = $articulo->get($_GET['ref']);
104
105
            $linea = new linea_factura_cliente();
0 ignored issues
show
Bug introduced by
The type linea_factura_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...
106
            $this->resultados = $linea->all_from_articulo($_GET['ref'], $this->offset);
107
        } else {
108
            $this->share_extension();
109
            $this->huecos = $this->factura->huecos();
110
            $this->cliente = FALSE;
111
            $this->codagente = '';
112
            $this->codalmacen = '';
113
            $this->codgrupo = '';
114
            $this->codpago = '';
115
            $this->codserie = '';
116
            $this->desde = '';
117
            $this->estado = '';
118
            $this->hasta = '';
119
            $this->num_resultados = '';
120
            $this->total_resultados = array();
121
            $this->total_resultados_comision = 0;
122
            $this->total_resultados_txt = '';
123
124
            if (isset($_GET['delete'])) {
125
                $this->delete_factura();
126
            } else {
127
                if (!isset($_GET['mostrar']) && ( $this->query != '' || isset($_REQUEST['codagente']) || isset($_REQUEST['codcliente']) || isset($_REQUEST['codserie']))) {
128
                    /**
129
                     * si obtenermos un codagente, un codcliente o un codserie pasamos direcatemente
130
                     * a la pestaña de búsqueda, a menos que tengamos un mostrar, que
131
                     * entonces nos indica donde tenemos que estar.
132
                     */
133
                    $this->mostrar = 'buscar';
134
                }
135
136
                if (isset($_REQUEST['codcliente']) && $_REQUEST['codcliente'] != '') {
137
                    $cli0 = 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...
138
                    $this->cliente = $cli0->get($_REQUEST['codcliente']);
139
                }
140
141
                if (isset($_REQUEST['codagente'])) {
142
                    $this->codagente = $_REQUEST['codagente'];
143
                }
144
145
                if (isset($_REQUEST['codalmacen'])) {
146
                    $this->codalmacen = $_REQUEST['codalmacen'];
147
                }
148
149
                if (isset($_REQUEST['codgrupo'])) {
150
                    $this->codgrupo = $_REQUEST['codgrupo'];
151
                }
152
153
                if (isset($_REQUEST['codpago'])) {
154
                    $this->codpago = $_REQUEST['codpago'];
155
                }
156
157
                if (isset($_REQUEST['codserie'])) {
158
                    $this->codserie = $_REQUEST['codserie'];
159
                }
160
161
                if (isset($_REQUEST['desde'])) {
162
                    $this->desde = $_REQUEST['desde'];
163
                    $this->hasta = $_REQUEST['hasta'];
164
                    $this->estado = $_REQUEST['estado'];
165
                }
166
            }
167
168
            /// añadimos segundo nivel de ordenación
169
            $order2 = '';
170
            if (substr($this->order, -4) == 'DESC') {
171
                $order2 = ', hora DESC, numero DESC';
172
            } else {
173
                $order2 = ', hora ASC, numero ASC';
174
            }
175
176
            if ($this->mostrar == 'sinpagar') {
177
                $this->resultados = $this->factura->all_sin_pagar($this->offset, FS_ITEM_LIMIT, $this->order . $order2);
0 ignored issues
show
Bug introduced by
The constant FS_ITEM_LIMIT was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
178
179
                if ($this->offset == 0) {
180
                    /// calculamos el total, pero desglosando por divisa
181
                    $this->total_resultados = array();
182
                    $this->total_resultados_txt = 'Suma total de esta página:';
183
                    foreach ($this->resultados as $fac) {
184
                        if (!isset($this->total_resultados[$fac->coddivisa])) {
185
                            $this->total_resultados[$fac->coddivisa] = array(
186
                                'coddivisa' => $fac->coddivisa,
187
                                'total' => 0
188
                            );
189
                        }
190
191
                        $this->total_resultados[$fac->coddivisa]['total'] += $fac->total;
192
                    }
193
                }
194
            } else if ($this->mostrar == 'buscar') {
195
                $this->buscar($order2);
196
            } else {
197
                $this->resultados = $this->factura->all($this->offset, FS_ITEM_LIMIT, $this->order . $order2);
198
            }
199
        }
200
    }
201
202
    public function url($busqueda = FALSE)
203
    {
204
        if ($busqueda) {
205
            $codcliente = '';
206
            if ($this->cliente) {
207
                $codcliente = $this->cliente->codcliente;
208
            }
209
210
            $url = parent::url() . "&mostrar=" . $this->mostrar
211
                    . "&query=" . $this->query
212
                    . "&codagente=" . $this->codagente
213
                    . "&codalmacen=" . $this->codalmacen
214
                    . "&codcliente=" . $codcliente
215
                    . "&codgrupo=" . $this->codgrupo
216
                    . "&codpago=" . $this->codpago
217
                    . "&codserie=" . $this->codserie
218
                    . "&desde=" . $this->desde
219
                    . "&estado=" . $this->estado
220
                    . "&hasta=" . $this->hasta;
221
222
            return $url;
223
        }
224
225
        return parent::url();
226
    }
227
228
    public function paginas()
229
    {
230
        if ($this->mostrar == 'sinpagar') {
231
            $total = $this->total_sinpagar();
232
        } else if ($this->mostrar == 'buscar') {
233
            $total = $this->num_resultados;
234
        } else {
235
            $total = $this->total_registros();
236
        }
237
238
        return $this->fbase_paginas($this->url(TRUE), $total, $this->offset);
239
    }
240
241
    public function buscar_lineas()
242
    {
243
        /// cambiamos la plantilla HTML
244
        $this->template = 'ajax/ventas_lineas_facturas';
245
246
        $this->buscar_lineas = $_POST['buscar_lineas'];
247
        $linea = new linea_factura_cliente();
248
249
        if (isset($_POST['codcliente'])) {
250
            $this->lineas = $linea->search_from_cliente2($_POST['codcliente'], $this->buscar_lineas, $_POST['buscar_lineas_o']);
251
        } else {
252
            $this->lineas = $linea->search($this->buscar_lineas);
253
        }
254
    }
255
256
    private function share_extension()
257
    {
258
        /// añadimos las extensiones para clientes, agentes y artículos
259
        $extensiones = array(
260
            array(
261
                'name' => 'facturas_cliente',
262
                'page_from' => __CLASS__,
263
                'page_to' => 'ventas_cliente',
264
                'type' => 'button',
265
                'text' => '<span class="glyphicon glyphicon-list" aria-hidden="true"></span> &nbsp; Facturas',
266
                'params' => ''
267
            ),
268
            array(
269
                'name' => 'facturas_agente',
270
                'page_from' => __CLASS__,
271
                'page_to' => 'admin_agente',
272
                'type' => 'button',
273
                'text' => '<span class="glyphicon glyphicon-list" aria-hidden="true"></span> &nbsp; Facturas de cliente',
274
                'params' => ''
275
            ),
276
            array(
277
                'name' => 'facturas_articulo',
278
                'page_from' => __CLASS__,
279
                'page_to' => 'ventas_articulo',
280
                'type' => 'tab_button',
281
                'text' => '<span class="glyphicon glyphicon-list" aria-hidden="true"></span> &nbsp; Facturas de cliente',
282
                'params' => ''
283
            ),
284
        );
285
        foreach ($extensiones as $ext) {
286
            $fsext0 = 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...
287
            if (!$fsext0->save()) {
288
                $this->new_error_msg('Imposible guardar los datos de la extensión ' . $ext['name'] . '.');
289
            }
290
        }
291
    }
292
293
    public function total_sinpagar()
294
    {
295
        return $this->fbase_sql_total('facturascli', 'idfactura', 'WHERE pagada = false');
296
    }
297
298
    private function total_registros()
299
    {
300
        return $this->fbase_sql_total('facturascli', 'idfactura');
301
    }
302
303
    private function buscar($order2)
304
    {
305
        $this->resultados = array();
306
        $this->num_resultados = 0;
307
        $sql = " FROM facturascli ";
308
        $where = 'WHERE ';
309
310
        if ($this->query) {
311
            $query = $this->agente->no_html(mb_strtolower($this->query, 'UTF8'));
312
            $sql .= $where;
313
            if (is_numeric($query)) {
314
                $sql .= "(codigo LIKE '%" . $query . "%' OR numero2 LIKE '%" . $query . "%' "
315
                        . "OR observaciones LIKE '%" . $query . "%' OR cifnif LIKE '" . $query . "%')";
316
            } else {
317
                $sql .= "(lower(codigo) LIKE '%" . $query . "%' OR lower(numero2) LIKE '%" . $query . "%' "
318
                        . "OR lower(cifnif) LIKE '" . $query . "%' "
319
                        . "OR lower(observaciones) LIKE '%" . str_replace(' ', '%', $query) . "%')";
320
            }
321
            $where = ' AND ';
322
        }
323
324
        if ($this->cliente) {
325
            $sql .= $where . "codcliente = " . $this->agente->var2str($this->cliente->codcliente);
326
            $where = ' AND ';
327
        }
328
329
        if ($this->codagente != '') {
330
            $sql .= $where . "codagente = " . $this->agente->var2str($this->codagente);
331
            $where = ' AND ';
332
        }
333
334
        if ($this->codalmacen != '') {
335
            $sql .= $where . "codalmacen = " . $this->agente->var2str($this->codalmacen);
336
            $where = ' AND ';
337
        }
338
339
        if ($this->codgrupo != '') {
340
            $sql .= $where . "codcliente IN (SELECT codcliente FROM clientes WHERE codgrupo = " . $this->agente->var2str($this->codgrupo) . ")";
341
            $where = ' AND ';
342
        }
343
344
        if ($this->codpago != '') {
345
            $sql .= $where . "codpago = " . $this->agente->var2str($this->codpago);
346
            $where = ' AND ';
347
        }
348
349
        if ($this->codserie != '') {
350
            $sql .= $where . "codserie = " . $this->agente->var2str($this->codserie);
351
            $where = ' AND ';
352
        }
353
354
        if ($this->desde) {
355
            $sql .= $where . "fecha >= " . $this->agente->var2str($this->desde);
356
            $where = ' AND ';
357
        }
358
359
        if ($this->hasta) {
360
            $sql .= $where . "fecha <= " . $this->agente->var2str($this->hasta);
361
            $where = ' AND ';
362
        }
363
364
        if ($this->estado == 'pagadas') {
365
            $sql .= $where . "pagada";
366
            $where = ' AND ';
0 ignored issues
show
Unused Code introduced by
The assignment to $where is dead and can be removed.
Loading history...
367
        } else if ($this->estado == 'impagadas') {
368
            $sql .= $where . "pagada = false";
369
            $where = ' AND ';
370
        } else if ($this->estado == 'anuladas') {
371
            $sql .= $where . "anulada = true";
372
            $where = ' AND ';
373
        } else if ($this->estado == 'sinasiento') {
374
            $sql .= $where . "idasiento IS NULL";
375
            $where = ' AND ';
376
        }
377
378
        $data = $this->db->select("SELECT COUNT(idfactura) as total" . $sql);
379
        if ($data) {
380
            $this->num_resultados = intval($data[0]['total']);
381
382
            $data2 = $this->db->select_limit("SELECT *" . $sql . " ORDER BY " . $this->order . $order2, FS_ITEM_LIMIT, $this->offset);
0 ignored issues
show
Bug introduced by
The constant FS_ITEM_LIMIT was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
383
            if ($data2) {
384
                foreach ($data2 as $d) {
385
                    $this->resultados[] = new factura_cliente($d);
386
                }
387
            }
388
389
            $data2 = $this->db->select("SELECT coddivisa,SUM(total) as total" . $sql . " GROUP BY coddivisa");
390
            if ($data2) {
391
                $this->total_resultados_txt = 'Suma total de los resultados:';
392
393
                foreach ($data2 as $d) {
394
                    $this->total_resultados[] = array(
395
                        'coddivisa' => $d['coddivisa'],
396
                        'total' => floatval($d['total'])
397
                    );
398
                }
399
            }
400
401
            if ($this->codagente !== '') {
402
                /// calculamos la comisión del empleado
403
                $data2 = $this->db->select("SELECT SUM(neto*porcomision/100) as total" . $sql);
404
                if ($data2) {
405
                    $this->total_resultados_comision = floatval($data2[0]['total']);
406
                }
407
            }
408
        }
409
    }
410
411
    private function delete_factura()
412
    {
413
        $fact = $this->factura->get($_GET['delete']);
414
        if ($fact) {
415
            /// obtenemos las líneas de la factura antes de eliminar
416
            $lineas = $fact->get_lineas();
417
418
            if ($fact->delete()) {
419
                $this->delete_ncf($fact);
420
                $this->new_message('Factura '.$fact->idfactura.' '.$fact->codigo.' - '.$fact->numero2.' del cliente '.$fact->nombrecliente.' por un valor de: '.$fact->total.' '.$fact->coddivisa.' del '.$fact->fecha.' eliminada por '.$this->user->nick, TRUE, 'log');
421
                if (!$fact->anulada) {
422
                    /// Restauramos el stock
423
                    $art0 = new articulo();
424
                    foreach ($lineas as $linea) {
425
                        /// si la línea pertenece a un albarán no descontamos stock
426
                        if (is_null($linea->idalbaran)) {
427
                            $articulo = $art0->get($linea->referencia);
428
                            if ($articulo) {
429
                                $articulo->sum_stock($fact->codalmacen, $linea->cantidad, FALSE, $linea->codcombinacion);
430
                            }
431
                        }
432
                    }
433
                }
434
435
                /// ¿Esta factura es rectificativa de otra?
436
                if ($fact->idfacturarect) {
437
                    $original = $this->factura->get($fact->idfacturarect);
438
                    if ($original) {
439
                        $original->anulada = FALSE;
440
                        $original->save();
441
                    }
442
                }
443
444
                $this->clean_last_changes();
445
            } else {
446
                $this->new_error_msg("¡Imposible eliminar la factura!");
447
            }
448
        } else {
449
            $this->new_error_msg("Factura no encontrada.");
450
        }
451
    }
452
453
    /**
454
     * Cuando se le da a eliminar factura en realidad se anula
455
     * generando un albaran con las cantidades en negativo para retornar el stock
456
     */
457
    private function delete_factura_old()
0 ignored issues
show
Unused Code introduced by
The method delete_factura_old() is not used, and could be removed.

This check looks for private methods that have been defined, but are not used inside the class.

Loading history...
458
    {
459
        $delete = \filter_input(INPUT_GET, 'delete');
0 ignored issues
show
Unused Code introduced by
The assignment to $delete is dead and can be removed.
Loading history...
460
        $motivo = \filter_input(INPUT_POST, 'motivo');
461
        $fecha = \filter_input(INPUT_POST, 'fecha');
462
        $motivo_anulacion = $this->ncf_tipo_anulacion->get($motivo);
463
        $fact = $this->factura->get($_GET['delete']);
464
        if ($fact) {
465
            /// obtenemos las líneas de la factura antes de eliminar
466
            $lineas = $fact->get_lineas();
467
468
            $albaranes = new albaran_cliente();
0 ignored issues
show
Bug introduced by
The type albaran_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...
469
            /// ¿Sumamos stock?
470
            $art0 = new articulo();
471
            $idalbaran = false;
472
            foreach ($lineas as $linea) {
473
                /// si la línea pertenece a un albarán no descontamos stock
474
                if (is_null($linea->idalbaran)) {
475
                    $articulo = $art0->get($linea->referencia);
476
                    if ($articulo) {
477
                        $articulo->sum_stock($fact->codalmacen, $linea->cantidad, false, $linea->codcombinacion);
478
                    }
479
                } else {
480
                    $idalbaran = $linea->idalbaran;
481
                }
482
            }
483
            if ($idalbaran) {
484
                $albaran0 = $albaranes->get($idalbaran);
485
                $new_albaran = clone $albaran0;
486
                $new_albaran->idalbaran = null;
487
                $new_albaran->idfactura = null;
488
                $new_albaran->observaciones = ucfirst(FS_ALBARAN) . " " . $albaran0->codigo . " anulado por eliminación de la factura asociada " . $fact->codigo;
0 ignored issues
show
Bug introduced by
The constant FS_ALBARAN was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
489
                $new_albaran->fecha = $fecha;
490
                $new_albaran->neto = $new_albaran->neto * -1;
491
                $new_albaran->total = $new_albaran->total * -1;
492
                $new_albaran->totaliva = $new_albaran->totaliva * -1;
493
                $new_albaran->hora = \date('H:i:s');
494
495
                if ($new_albaran->save()) {
496
                    $linea0 = new linea_albaran_cliente();
0 ignored issues
show
Bug introduced by
The type linea_albaran_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...
497
                    $new_albaran_lineas = $linea0->all_from_albaran($idalbaran);
498
                    foreach ($new_albaran_lineas as $linea) {
499
                        $linea->idalbaran = $new_albaran->idalbaran;
500
                        $linea->idfactura = null;
501
                        $linea->idlinea = null;
502
                        $linea->cantidad = $linea->cantidad * -1;
503
                        $linea->pvptotal = $linea->pvptotal * -1;
504
                        $linea->pvpsindto = $linea->pvpsindto * -1;
505
                        $linea->save();
506
                    }
507
                }
508
            }
509
510
            $ncf0 = $this->ncf_ventas->get_ncf($this->empresa->id, $fact->idfactura, $fact->codcliente);
511
            $ncf0->motivo = $motivo_anulacion->codigo . " " . $motivo_anulacion->descripcion;
512
            $ncf0->estado = false;
513
            $ncf0->usuario_modificacion = $this->user->nick;
514
            $ncf0->fecha_modificacion = Date('d-m-Y H:i:s');
515
            if ($ncf0->anular()) {
516
                $asiento_factura = new asiento_factura();
0 ignored issues
show
Bug introduced by
The type asiento_factura 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...
517
                $asiento_factura->soloasiento = true;
518
                $fact_rectifica = $fact->idfacturarect;
519
                $factrectifica = (!empty($fact->idfacturarect)) ? $fact_rectifica : 'NULL';
520
                $fact->idfacturarect = ($ncf0->tipo_comprobante == '04') ? null : $fact->idfactura;
521
                $albaran_origen = ($idalbaran)?'Del '.FS_ALBARAN . ": ".$new_albaran->idalbaran:'';
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $new_albaran does not seem to be defined for all execution paths leading up to this point.
Loading history...
522
                if ($asiento_factura->generar_asiento_venta($fact)) {
523
                    $this->db->exec("UPDATE facturascli set observaciones = '" . ucfirst(FS_FACTURA) . " eliminada por: " . $motivo_anulacion->descripcion . ", " . $albaran_origen . "', anulada = true, pagada = true, neto = 0, total = 0, totalirpf = 0, totaleuros = 0, totaliva = 0, idfacturarect = " . $factrectifica . " where idfactura = " . $fact->idfactura . ";");
0 ignored issues
show
Bug introduced by
The constant FS_FACTURA was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
524
                    $this->db->exec("DELETE FROM lineasivafactcli where idfactura = " . $fact->idfactura);
525
                    $fact_lineas = new linea_factura_cliente();
526
                    $lineas_fact = $fact_lineas->all_from_factura($fact->idfactura);
527
                    foreach ($lineas_fact as $linea) {
528
                        $linea->delete();
529
                    }
530
                    $fact->get_lineas_iva();
531
                    $this->new_message("<a href='" . $asiento_factura->asiento->url() . "'>Asiento</a> reversado correctamente.");
532
                    $this->clean_last_changes();
533
                }
534
                $this->new_message("<a href='" . $fact->url() . "'>Factura</a> cambiada a estado anulada por error correctamente.");
535
            } else {
536
                $this->new_error_msg("¡Imposible eliminar la factura!");
537
            }
538
        } else {
539
            $this->new_error_msg("Factura no encontrada.");
540
        }
541
    }
542
543
    public function orden()
544
    {
545
        return array(
546
            'fecha_desc' => array(
547
                'icono' => '<span class="glyphicon glyphicon-sort-by-attributes-alt" aria-hidden="true"></span>',
548
                'texto' => 'Fecha',
549
                'orden' => 'fecha DESC'
550
            ),
551
            'fecha_asc' => array(
552
                'icono' => '<span class="glyphicon glyphicon-sort-by-attributes" aria-hidden="true"></span>',
553
                'texto' => 'Fecha',
554
                'orden' => 'fecha ASC'
555
            ),
556
            'vencimiento_desc' => array(
557
                'icono' => '<span class="glyphicon glyphicon-sort-by-attributes-alt" aria-hidden="true"></span>',
558
                'texto' => 'Vencimiento',
559
                'orden' => 'vencimiento DESC'
560
            ),
561
            'vencimiento_asc' => array(
562
                'icono' => '<span class="glyphicon glyphicon-sort-by-attributes" aria-hidden="true"></span>',
563
                'texto' => 'Vencimiento',
564
                'orden' => 'vencimiento ASC'
565
            ),
566
            'codigo_desc' => array(
567
                'icono' => '<span class="glyphicon glyphicon-sort-by-attributes-alt" aria-hidden="true"></span>',
568
                'texto' => 'Código',
569
                'orden' => 'codigo DESC'
570
            ),
571
            'codigo_asc' => array(
572
                'icono' => '<span class="glyphicon glyphicon-sort-by-attributes" aria-hidden="true"></span>',
573
                'texto' => 'Código',
574
                'orden' => 'codigo ASC'
575
            ),
576
            'total_desc' => array(
577
                'icono' => '<span class="glyphicon glyphicon-sort-by-attributes-alt" aria-hidden="true"></span>',
578
                'texto' => 'Total',
579
                'orden' => 'total DESC'
580
            )
581
        );
582
    }
583
}
584