FiscalReport607::getSQLFrom()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 6
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 8
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
use FacturaScripts\Core\Tools;
22
23
24
class FiscalReport607 extends JoinModel
25
{
26
    const MAIN_TABLE = 'facturascli';
27
    const SECONDARY_TABLE = 'facturascli AS f2';
28
    const SECONDARY_TABLE_ALIAS = 'f2';
29
    const ESTADOSDOC_TABLE = 'estados_documentos';
30
31
    /**
32
     *
33
     * @return array
34
     */
35
    protected function getFields(): array
36
    {
37
        $dateFormat = (FS_DB_TYPE === 'postgresql') ? "to_char" : "date_format";
0 ignored issues
show
Bug introduced by
The constant FacturaScripts\Plugins\f...a\Model\Join\FS_DB_TYPE was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
38
        $dateFormatString = (FS_DB_TYPE === 'postgresql') ? "YYYYMMDD" : "%Y%m%d";
39
40
        $data = [
41
            'itemrow' => static::MAIN_TABLE.'.idfactura',
42
            'idempresa' => static::MAIN_TABLE.'.idempresa',
43
            'codalmacen' => static::MAIN_TABLE.'.codalmacen',
44
            'cifnif' => 'CASE WHEN length('.static::MAIN_TABLE.'.cifnif)=9 THEN '
45
                        . static::MAIN_TABLE.'.cifnif WHEN length('.static::MAIN_TABLE.'.cifnif)=11 THEN '
46
                        . static::MAIN_TABLE.'.cifnif ELSE NULL END',
47
            'tipoid' => 'CASE WHEN length('.static::MAIN_TABLE.'.cifnif)=9 THEN 1 WHEN length('
48
                        . static::MAIN_TABLE.'.cifnif)=11 THEN 2 ELSE 3 END',
49
            'ncf' => static::MAIN_TABLE.'.numeroncf',
50
            'ncfmodifica' => static::SECONDARY_TABLE_ALIAS.'.numeroncf',
51
            'tipoingreso' => 'CASE WHEN '.static::MAIN_TABLE.'.ncftipomovimiento is null THEN \'1\' ELSE '
52
                            . static::MAIN_TABLE.'.ncftipomovimiento END',
53
            'fecha' => $dateFormat.'('.static::MAIN_TABLE.'.fecha,\''.$dateFormatString.'\')',
54
//            'fecharetencion' => '\'\'',
55
            'base' => 'CASE WHEN '.static::ESTADOSDOC_TABLE.'.nombre = \'Anulada\' THEN 0 WHEN '
56
                        . static::ESTADOSDOC_TABLE.'.nombre = \'Emitida\' AND '.static::MAIN_TABLE.'.neto < 0 THEN '
57
                        . static::MAIN_TABLE.'.neto*-1 ELSE '.static::MAIN_TABLE.'.neto END',
58
            'itbis' => 'CASE WHEN '.static::ESTADOSDOC_TABLE.'.nombre = \'Anulada\' THEN 0 WHEN '
59
                        . static::ESTADOSDOC_TABLE.'.nombre = \'Emitida\' AND '.static::MAIN_TABLE.'.totaliva < 0 THEN '
60
                        . static::MAIN_TABLE.'.totaliva*-1 ELSE '.static::MAIN_TABLE.'.totaliva END',
61
//            'itbisretenido' => '0',
62
//            'itbispercibido' => '0',
63
//            'rentaretenido' => '0',
64
//            'rentapercibido' => '0',
65
//            'isc' => '0',
66
//            'otrosimpuestos' => '0',
67
//            'propinalegal' => '0',
68
            'totalefectivo' => 'CASE WHEN '.static::MAIN_TABLE.'.ncftipopago IS NULL OR '
69
                                . static::MAIN_TABLE.'.ncftipopago = \'\' OR '
70
                                . static::MAIN_TABLE.'.ncftipopago = \'17\' THEN '
71
                                . static::MAIN_TABLE.'.total else 0 END',
72
            'totalcheque' => 'CASE WHEN '.static::MAIN_TABLE.'.ncftipopago = \'18\' THEN '
73
                            . static::MAIN_TABLE.'.total else 0 END',
74
            'totaltarjeta' => 'CASE WHEN '.static::MAIN_TABLE.'.ncftipopago = \'19\' THEN '
75
                            . static::MAIN_TABLE.'.total else 0 END',
76
            'totalcredito' => 'CASE WHEN '.static::MAIN_TABLE.'.ncftipopago = \'20\' THEN '
77
                            . static::MAIN_TABLE.'.total else 0 END',
78
            'totalbonos' => 'CASE WHEN '.static::MAIN_TABLE.'.ncftipopago = \'21\' THEN '
79
                            . static::MAIN_TABLE.'.total else 0 END',
80
            'totalpermuta' => 'CASE WHEN '.static::MAIN_TABLE.'.ncftipopago = \'22\' THEN '
81
                            . static::MAIN_TABLE.'.total else 0 END',
82
            'totalotrasformas' => 'CASE WHEN '.static::MAIN_TABLE.'.ncftipopago = \'23\' THEN '
83
                                . static::MAIN_TABLE.'.total else 0 END',
84
            'estado' => 'CASE WHEN '.static::ESTADOSDOC_TABLE
85
                        . '.nombre = \'Emitida\' THEN \'Activo\' ELSE \'Anulado\' END',
86
        ];
87
        return $data;
88
    }
89
90
    /**
91
     *
92
     * @return string
93
     */
94
    protected function getSQLFrom(): string
95
    {
96
        return static::MAIN_TABLE
97
            . ' LEFT JOIN '. static::SECONDARY_TABLE . ' ON ('
98
            . static::MAIN_TABLE . '.idfacturarect = ' . static::SECONDARY_TABLE_ALIAS . '.idfactura)'
99
            . ' LEFT JOIN ' . static::ESTADOSDOC_TABLE . ' ON ('
100
            . static::MAIN_TABLE . '.idestado = ' . static::ESTADOSDOC_TABLE . '.idestado AND '
101
            . static::ESTADOSDOC_TABLE.'.nombre != \'Anulada\')';
102
    }
103
104
    /**
105
     *
106
     * @return array
107
     */
108
    protected function getTables(): array
109
    {
110
        return [
111
            static::MAIN_TABLE,
112
            static::ESTADOSDOC_TABLE
113
        ];
114
    }
115
}
116