Passed
Push — master ( 1e4dff...7f4dae )
by Joe Nilson
03:57 queued 15s
created

FiscalReport606::getFields()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 32
Code Lines 29

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 29
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 32
rs 9.456
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 FiscalReport606 extends JoinModel
23
{
24
    const MAIN_TABLE = 'facturasprov';
25
    const LINES_TABLE = 'lineasfacturasprov';
26
    const SECONDARY_TABLE = 'facturasprov AS f2';
27
    const SECONDARY_TABLE_ALIAS = 'f2';
28
    const ESTADOSDOC_TABLE = 'estados_documentos';
29
    const PRODS_TABLE = 'productos';
30
31
    /**
32
     *
33
     * @return array
34
     */
35
    protected function getFields(): array
36
    {
37
        $data = [
38
            'itemrow' => 'rank() over (PARTITION BY '.static::MAIN_TABLE.'.idempresa order by '.static::MAIN_TABLE.'.numproveedor)',
39
            'idempresa' => static::MAIN_TABLE.'.idempresa',
40
            'codalmacen' => static::MAIN_TABLE.'.codalmacen',
41
            'cifnif' => 'CASE WHEN length('.static::MAIN_TABLE.'.cifnif)=9 THEN '.static::MAIN_TABLE.'.cifnif WHEN length('.static::MAIN_TABLE.'.cifnif)=11 THEN '.static::MAIN_TABLE.'.cifnif ELSE NULL END',
42
            'tipoid' => 'CASE WHEN length('.static::MAIN_TABLE.'.cifnif)=9 THEN 1 WHEN length('.static::MAIN_TABLE.'.cifnif)=11 THEN 2 ELSE 3 END',
43
            'tipocompra' => static::MAIN_TABLE.'.ncftipomovimiento',
44
            'ncf' => static::MAIN_TABLE.'.numproveedor',
45
            'ncfmodifica' => static::SECONDARY_TABLE_ALIAS.'.numproveedor',
46
            'fecha' => 'to_char('.static::MAIN_TABLE.'.fecha,\'YYYYMMDD\')',
47
            'fechapago' => '\'\'',
48
            'totalservicios' => 'SUM(CASE WHEN '.static::PRODS_TABLE.'.esservicio = true THEN '.static::LINES_TABLE.'.pvptotal ELSE 0 END)',
49
            'totalbienes' => 'SUM(CASE WHEN '.static::PRODS_TABLE.'.esservicio = false THEN '.static::LINES_TABLE.'.pvptotal ELSE 0 END)',
50
            'base' => 'CASE WHEN '.static::ESTADOSDOC_TABLE.'.nombre = \'Anulada\' THEN 0 WHEN '.static::ESTADOSDOC_TABLE.'.nombre = \'Emitida\' AND '.static::MAIN_TABLE.'.neto < 0 THEN '.static::MAIN_TABLE.'.neto*-1 ELSE '.static::MAIN_TABLE.'.neto END',
51
            'itbis' => 'CASE WHEN '.static::ESTADOSDOC_TABLE.'.nombre = \'Anulada\' THEN 0 WHEN '.static::ESTADOSDOC_TABLE.'.nombre = \'Emitida\' AND '.static::MAIN_TABLE.'.totaliva < 0 THEN '.static::MAIN_TABLE.'.totaliva*-1 ELSE '.static::MAIN_TABLE.'.totaliva END',
52
            'itbisretenido' => '0',
53
            'itbissujeto' => '0',
54
            'itbisalcosto' => '0',
55
            'itbisporadelantar' => '0',
56
            'itbispercibido' => '0',
57
            'tiporetencionrenta' => '\'\'',
58
            'rentaretenido' => '0',
59
            'rentapercibido' => '0',
60
            'isc' => '0',
61
            'otrosimpuestos' => '0',
62
            'propinalegal' => '0',
63
            'tipopago' => 'CASE WHEN '.static::MAIN_TABLE.'.ncftipomovimiento is null THEN \'02\' ELSE '.static::MAIN_TABLE.'.ncftipomovimiento END',
64
            'estado' => 'CASE WHEN '.static::ESTADOSDOC_TABLE.'.nombre = \'Emitida\' THEN \'Activo\' ELSE \'Anulado\' END',
65
        ];
66
        return $data;
67
    }
68
69
    protected function getGroupFields(): string
70
    {
71
        //return parent::getGroupFields(); // TODO: Change the autogenerated stub
72
        return  static::MAIN_TABLE.'.idempresa, ' .
73
                static::MAIN_TABLE.'.codalmacen, ' .
74
                static::MAIN_TABLE.'.cifnif, ' .
75
                static::MAIN_TABLE.'.ncftipomovimiento, ' .
76
                static::MAIN_TABLE.'.numproveedor, ' .
77
                static::SECONDARY_TABLE_ALIAS.'.numproveedor, ' .
78
                static::MAIN_TABLE.'.fecha, ' .
79
                static::ESTADOSDOC_TABLE.'.nombre, ' .
80
                static::MAIN_TABLE.'.neto, ' .
81
                static::MAIN_TABLE.'.totaliva' .
82
            ' ';
83
    }
84
85
    /**
86
     *
87
     * @return string
88
     */
89
    protected function getSQLFrom(): string
90
    {
91
        return static::MAIN_TABLE
92
            . ' LEFT JOIN '. static::SECONDARY_TABLE . ' ON ('
93
            . static::MAIN_TABLE . '.idfacturarect = ' . static::SECONDARY_TABLE_ALIAS . '.idfactura)'
94
            . ' LEFT JOIN '. static::LINES_TABLE . ' ON ('
95
            . static::MAIN_TABLE . '.idfactura = ' . static::LINES_TABLE . '.idfactura)'
96
            . ' LEFT JOIN '. static::PRODS_TABLE . ' ON ('
97
            . static::LINES_TABLE . '.referencia = ' . static::PRODS_TABLE . '.referencia)'
98
            . ' LEFT JOIN ' . static::ESTADOSDOC_TABLE . ' ON ('
99
            . static::MAIN_TABLE . '.idestado = ' . static::ESTADOSDOC_TABLE . '.idestado)';
100
    }
101
102
    /**
103
     *
104
     * @return array
105
     */
106
    protected function getTables(): array
107
    {
108
        return [
109
            static::MAIN_TABLE,
110
            static::LINES_TABLE,
111
            static::ESTADOSDOC_TABLE,
112
            static::PRODS_TABLE
113
        ];
114
    }
115
}
116