Passed
Push — master ( d131f6...dda4d9 )
by Joe Nilson
03:14
created

FiscalReports::getTables()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 8
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 11
rs 10
1
<?php
2
/*
3
 * Copyright (C) 2022 Joe Nilson <[email protected]>
4
 *
5
 * This program is free software: you can redistribute it and/or modify
6
 * it under the terms of the GNU Lesser General Public License as
7
 * published by the Free Software Foundation, either version 3 of the
8
 * License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU Lesser General Public License for more details.
14
 * You should have received a copy of the GNU Lesser General Public License
15
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
16
 */
17
18
namespace FacturaScripts\Plugins\fsRepublicaDominicana\Model\Join;
19
20
use FacturaScripts\Core\Model\Base\JoinModel;
0 ignored issues
show
Bug introduced by
The type FacturaScripts\Core\Model\Base\JoinModel 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...
21
22
class FiscalReports extends JoinModel
23
{
24
    const MAIN_TABLE = 'facturascli';
25
    const SECONDARY_TABLE = 'facturascli f2';
26
    const SECONDARY_TABLE_ALIAS = 'f2';
27
    const LINES_TABLE = 'lineasfacturascli';
28
    const ALMACENES_TABLE = 'almacenes';
29
    const NCFTIPO_TABLE = 'rd_ncftipo';
30
    const NCFTIPOMOV_TABLE = 'rd_ncftipomovimiento';
31
    const NCFTIPOANUL_TABLE = 'rd_ncftipoanulacion';
32
    const NCFTIPOPAGO_TABLE = 'rd_ncftipopagos';
33
34
    /**
35
     *
36
     * @return array
37
     */
38
    protected function getFields(): array
39
    {
40
        $data = [
41
            'idfactura' => static::MAIN_TABLE.'.idfactura',
42
            'idempresa' => static::MAIN_TABLE.'.idempresa',
43
            'fecha' => static::MAIN_TABLE.'.fecha',
44
            'codalmacen' => static::MAIN_TABLE.'.codalmacen',
45
            'almacen' => static::ALMACENES_TABLE.'.nombre',
46
            'cliente' => static::MAIN_TABLE.'.nombrecliente',
47
            'cifnif' => static::MAIN_TABLE.'.cifnif',
48
            'ncf' => static::MAIN_TABLE.'.numero2',
49
            'baseimponible' => 'sum(case when '.static::LINES_TABLE.'.iva != 0 then '.static::LINES_TABLE.'.pvptotal else 0 end)',
50
            'baseexenta' => 'sum(case when '.static::LINES_TABLE.'.iva = 0 then '.static::LINES_TABLE.'.pvptotal else 0 end)',
51
            'itbis' => static::MAIN_TABLE.'.totaliva',
52
            'total' => static::MAIN_TABLE.'.total',
53
            'pagada' => static::MAIN_TABLE.'.pagada',
54
            'estado' => static::MAIN_TABLE.'.idestado',
55
//            'ncfmodifica' => static::SECONDARY_TABLE_ALIAS.'.numero2',
56
            'tipocomprobante' => static::NCFTIPO_TABLE.'.descripcion',
57
            'tipopago' => static::NCFTIPOPAGO_TABLE.'.descripcion',
58
            'tipomovimiento' => static::NCFTIPOMOV_TABLE.'.descripcion',
59
            'tipoanulacion' => static::NCFTIPOANUL_TABLE.'.descripcion',
60
        ];
61
        return $data;
62
    }
63
64
    /**
65
     *
66
     * @return string
67
     */
68
    protected function getGroupFields(): string
69
    {
70
        return static::MAIN_TABLE.'.idfactura, '.
71
            static::MAIN_TABLE.'.idempresa, '.
72
            static::MAIN_TABLE.'.fecha, '.
73
            static::MAIN_TABLE.'.codalmacen, '.
74
            static::ALMACENES_TABLE.'.nombre, '.
75
            static::MAIN_TABLE.'.nombrecliente, '.
76
            static::MAIN_TABLE.'.cifnif, '.
77
            static::MAIN_TABLE.'.numero2, '.
78
            static::MAIN_TABLE.'.total, '.
79
            static::MAIN_TABLE.'.totaliva, '.
80
            static::MAIN_TABLE.'.pagada, '.
81
            static::MAIN_TABLE.'.idestado, '.
82
//            static::SECONDARY_TABLE_ALIAS.'.numero2, '.
83
            static::NCFTIPO_TABLE.'.descripcion, '.
84
            static::NCFTIPOPAGO_TABLE.'.descripcion, '.
85
            static::NCFTIPOMOV_TABLE.'.descripcion, '.
86
            static::NCFTIPOANUL_TABLE.'.descripcion';
87
    }
88
89
    /**
90
     *
91
     * @return string
92
     */
93
    protected function getSQLFrom(): string
94
    {
95
        return static::MAIN_TABLE
96
            . ' LEFT JOIN ' . static::LINES_TABLE . ' ON ('
97
            . static::MAIN_TABLE . '.idfactura = ' . static::LINES_TABLE . '.idfactura)'
98
//            . ' LEFT JOIN '. static::SECONDARY_TABLE . ' ON ('
99
//            . static::MAIN_TABLE . '.idfacturarect = ' . static::SECONDARY_TABLE_ALIAS . '.idfactura)'
100
            . ' LEFT JOIN '. static::ALMACENES_TABLE . ' ON ('
101
            . static::MAIN_TABLE . '.codalmacen = ' . static::ALMACENES_TABLE . '.codalmacen)'
102
            . ' LEFT JOIN '. static::NCFTIPO_TABLE . ' ON ('
103
            . static::MAIN_TABLE . '.tipocomprobante = ' . static::NCFTIPO_TABLE . '.tipocomprobante)'
104
            . ' LEFT JOIN ' . static::NCFTIPOPAGO_TABLE . ' ON ('
105
            . static::MAIN_TABLE . '.ncftipopago = ' . static::NCFTIPOPAGO_TABLE . '.codigo)'
106
            . ' LEFT JOIN ' . static::NCFTIPOMOV_TABLE . ' ON ('
107
            . static::MAIN_TABLE . '.ncftipomovimiento = ' . static::NCFTIPOMOV_TABLE . '.codigo)'
108
            . ' LEFT JOIN ' . static::NCFTIPOANUL_TABLE . ' ON ('
109
            . static::MAIN_TABLE . '.ncftipoanulacion = ' . static::NCFTIPOANUL_TABLE . '.codigo)';
110
    }
111
112
    /**
113
     *
114
     * @return array
115
     */
116
    protected function getTables(): array
117
    {
118
        return [
119
            static::MAIN_TABLE,
120
            static::ALMACENES_TABLE,
121
//            static::SECONDARY_TABLE,
122
            static::LINES_TABLE,
123
            static::NCFTIPO_TABLE,
124
            static::NCFTIPOANUL_TABLE,
125
            static::NCFTIPOMOV_TABLE,
126
            static::NCFTIPOPAGO_TABLE
127
        ];
128
    }
129
}
130