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; |
|
|
|
|
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
|
|
|
|
28
|
|
|
const RECIBOSPROV_TABLE = 'recibospagosprov'; |
29
|
|
|
const SECONDARY_TABLE_ALIAS = 'f2'; |
30
|
|
|
const ESTADOSDOC_TABLE = 'estados_documentos'; |
31
|
|
|
const PRODS_TABLE = 'productos'; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* |
35
|
|
|
* @return array |
36
|
|
|
*/ |
37
|
|
|
protected function getFields(): array |
38
|
|
|
{ |
39
|
|
|
$dateFormat = (FS_DB_TYPE === 'postgresql') ? "to_char" : "date_format"; |
|
|
|
|
40
|
|
|
$dateFormatString = (FS_DB_TYPE === 'postgresql') ? "YYYYMMDD" : "%Y%m%d"; |
41
|
|
|
|
42
|
|
|
$data = [ |
43
|
|
|
'itemrow' => static::MAIN_TABLE.'.idfactura', |
44
|
|
|
'idempresa' => static::MAIN_TABLE.'.idempresa', |
45
|
|
|
'codalmacen' => static::MAIN_TABLE.'.codalmacen', |
46
|
|
|
'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', |
47
|
|
|
'tipoid' => 'CASE WHEN length('.static::MAIN_TABLE.'.cifnif)=9 THEN 1 WHEN length('.static::MAIN_TABLE.'.cifnif)=11 THEN 2 ELSE 3 END', |
48
|
|
|
'tipocompra' => static::MAIN_TABLE.'.ncftipomovimiento', |
49
|
|
|
'ncf' => static::MAIN_TABLE.'.numeroncf', |
50
|
|
|
'ncfmodifica' => static::SECONDARY_TABLE_ALIAS.'.numeroncf', |
51
|
|
|
'fecha' => $dateFormat.'('.static::MAIN_TABLE.'.fecha,\''.$dateFormatString.'\')', |
52
|
|
|
'fechapago' => $dateFormat.'('.static::RECIBOSPROV_TABLE.'.fechapago,\''.$dateFormatString.'\')', |
53
|
|
|
'totalservicios' => 'SUM(CASE WHEN '.static::PRODS_TABLE.'.esservicio = true THEN '.static::LINES_TABLE.'.pvptotal ELSE 0 END)', |
54
|
|
|
'totalbienes' => 'SUM(CASE WHEN ('.static::PRODS_TABLE.'.esservicio = false OR '.static::PRODS_TABLE.'.esservicio IS NULL) THEN '.static::LINES_TABLE.'.pvptotal ELSE 0 END)', |
55
|
|
|
'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', |
56
|
|
|
'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', |
57
|
|
|
// 'itbisretenido' => '0', |
58
|
|
|
// 'itbissujeto' => '0', |
59
|
|
|
'itbisalcosto' => 'CASE WHEN SUM(CASE WHEN '.static::PRODS_TABLE.'.esservicio = true THEN '.static::LINES_TABLE.'.pvptotal ELSE 0 END) = 0 THEN 0 ELSE 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 END', |
60
|
|
|
// 'itbisporadelantar' => '0', |
61
|
|
|
// 'itbispercibido' => '0', |
62
|
|
|
//'tiporetencionrenta' => '\'\'', |
63
|
|
|
// 'rentaretenido' => '0', |
64
|
|
|
// 'rentapercibido' => '0', |
65
|
|
|
// 'isc' => '0', |
66
|
|
|
// 'otrosimpuestos' => '0', |
67
|
|
|
// 'propinalegal' => '0', |
68
|
|
|
'tipopago' => 'CASE WHEN '.static::MAIN_TABLE.'.ncftipomovimiento is null THEN \'02\' ELSE '.static::MAIN_TABLE.'.ncftipomovimiento END', |
69
|
|
|
'estado' => 'CASE WHEN '.static::ESTADOSDOC_TABLE.'.nombre = \'Anulada\' THEN \'Anulado\' ELSE \'Activo\' END', |
70
|
|
|
]; |
71
|
|
|
return $data; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
protected function getGroupFields(): string |
75
|
|
|
{ |
76
|
|
|
//return parent::getGroupFields(); // TODO: Change the autogenerated stub |
77
|
|
|
return static::MAIN_TABLE.'.idfactura, ' . |
78
|
|
|
static::MAIN_TABLE.'.idempresa, ' . |
79
|
|
|
static::MAIN_TABLE.'.codalmacen, ' . |
80
|
|
|
static::MAIN_TABLE.'.cifnif, ' . |
81
|
|
|
static::MAIN_TABLE.'.ncftipomovimiento, ' . |
82
|
|
|
static::MAIN_TABLE.'.numeroncf, ' . |
83
|
|
|
static::SECONDARY_TABLE_ALIAS.'.numeroncf, ' . |
84
|
|
|
static::MAIN_TABLE.'.fecha, ' . |
85
|
|
|
static::RECIBOSPROV_TABLE.'.fechapago, ' . |
86
|
|
|
static::ESTADOSDOC_TABLE.'.nombre, ' . |
87
|
|
|
static::MAIN_TABLE.'.neto, ' . |
88
|
|
|
static::MAIN_TABLE.'.totaliva' . |
89
|
|
|
' '; |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* |
94
|
|
|
* @return string |
95
|
|
|
*/ |
96
|
|
|
protected function getSQLFrom(): string |
97
|
|
|
{ |
98
|
|
|
return static::MAIN_TABLE |
99
|
|
|
. ' LEFT JOIN '. static::SECONDARY_TABLE . ' ON (' |
100
|
|
|
. static::MAIN_TABLE . '.idfacturarect = ' . static::SECONDARY_TABLE_ALIAS . '.idfactura)' |
101
|
|
|
. ' LEFT JOIN '. static::RECIBOSPROV_TABLE . ' ON (' |
102
|
|
|
. static::MAIN_TABLE . '.idfactura = ' . static::RECIBOSPROV_TABLE . '.idfactura)' |
103
|
|
|
. ' LEFT JOIN '. static::LINES_TABLE . ' ON (' |
104
|
|
|
. static::MAIN_TABLE . '.idfactura = ' . static::LINES_TABLE . '.idfactura)' |
105
|
|
|
. ' LEFT JOIN '. static::PRODS_TABLE . ' ON (' |
106
|
|
|
. static::LINES_TABLE . '.referencia = ' . static::PRODS_TABLE . '.referencia)' |
107
|
|
|
. ' LEFT JOIN ' . static::ESTADOSDOC_TABLE . ' ON (' |
108
|
|
|
. static::MAIN_TABLE . '.idestado = ' . static::ESTADOSDOC_TABLE . '.idestado)'; |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* |
113
|
|
|
* @return array |
114
|
|
|
*/ |
115
|
|
|
protected function getTables(): array |
116
|
|
|
{ |
117
|
|
|
return [ |
118
|
|
|
static::MAIN_TABLE, |
119
|
|
|
static::RECIBOSPROV_TABLE, |
120
|
|
|
static::LINES_TABLE, |
121
|
|
|
static::ESTADOSDOC_TABLE, |
122
|
|
|
static::PRODS_TABLE |
123
|
|
|
]; |
124
|
|
|
} |
125
|
|
|
} |
126
|
|
|
|
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:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths