Issues (2050)

controller/documentos_residentes.php (5 issues)

1
<?php
2
/*
3
 * Copyright (C) 2018 Joe Nilson <joenilson at gmail.com>
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 published by
7
 * the Free Software Foundation, either version 3 of the License, or
8
 * (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
 *
15
 * You should have received a copy of the GNU Lesser General Public License
16
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
17
 */
18
require_once 'plugins/residentes/extras/residentesFacturaDetallada.php';
19
require_once 'plugins/residentes/extras/residentesEstadoCuenta.php';
20
require_once 'plugins/residentes/extras/residentesEnviarMail.php';
21
22
require_once 'plugins/residentes/extras/residentes_controller.php';
23
24
/**
25
 * Class Controller to manage all the documents to be printed, showed or emailed
26
 * in the Residentes plugin for FS_2017
27
 * @author Joe Nilson <joenilson at gmail.com>
28
 */
29
class documentos_residentes extends residentes_controller
30
{
31
    public $archivo;
32
    public $cliente_residente;
33
    public $documento;
34
    public $pagado;
35
    public $pendiente;
36
    public $tipo_accion;
37
    public $idprogramacion;
38
    public $idfactura;
39
    public $envio_masivo;
40
    public $factura;
41
    public $facturas;
42
    public $contador_facturas;
43
    public function __construct()
44
    {
45
        parent::__construct(__CLASS__, 'Documentos Residentes', 'admin', false, false, false);
46
    }
47
48
    protected function private_core()
49
    {
50
        parent::private_core();
51
        $this->init();
52
        $cod = $this->filter_request('codcliente');
53
        if ($cod) {
54
            $this->obtenerInformacionResidente($cod);
0 ignored issues
show
It seems like $cod can also be of type true; however, parameter $cod of documentos_residentes::o...rInformacionResidente() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

54
            $this->obtenerInformacionResidente(/** @scrutinizer ignore-type */ $cod);
Loading history...
55
        }
56
        $info_accion = $this->filter_request('info_accion');
57
        $tipo_documento = $this->filter_request('tipo_documento');
58
        $this->idprogramacion = $this->filter_request('idprogramacion');
59
        $this->envio_masivo = !(($this->filter_request('envio_masivo') === 'false'));
60
        $this->tipo_accion = $tipo_documento;
61
        $this->verificarCantidadFacturas();
62
        $this->archivo = $tipo_documento.'_'.\date('dmYhis') . '.pdf';
63
        if ($this->cliente_residente && $info_accion) {
64
            switch ($info_accion) {
65
                case 'imprimir':
66
                    $this->template = false;
67
                    $this->imprimir_documento($tipo_documento);
68
                    break;
69
                case 'enviar':
70
                    $this->enviar_documento($tipo_documento);
71
                    break;
72
                default:
73
                    break;
74
            }
75
        }
76
    }
77
78
    /**
79
     * @param string $cod
80
     */
81
    public function obtenerInformacionResidente($cod)
82
    {
83
        $cliente = new cliente();
84
        $this->cliente_residente = $cliente->get($cod);
85
        $residenteInformacion = new residentes_informacion();
86
        $informacion = $residenteInformacion->get($cod);
87
        $residenteEdificacion = new residentes_edificaciones();
88
        $residente = $residenteEdificacion->get_by_field('codcliente', $cod);
89
        $this->cliente_residente->inmueble = $residente[0];
90
        $this->cliente_residente->informacion = $informacion;
91
    }
92
93
    public function crear_documento($tipo_documento)
94
    {
95
        switch ($tipo_documento) {
96
            case 'informacion_cobros':
97
                $this->crearEstadoCuenta();
98
                break;
99
            case 'factura_residente_detallada':
100
                $this->crearFacturaDetallada();
101
                break;
102
            default:
103
                $this->documento = false;
104
                break;
105
        }
106
    }
107
108
    private function verificarCantidadFacturas()
109
    {
110
111
        $facturas = $this->filter_request('idfactura');
112
        if ($facturas !== null) {
0 ignored issues
show
The condition $facturas !== null is always true.
Loading history...
113
            $this->getFacturaProgramadaPendiente($facturas);
114
        }
115
    }
116
117
    /**
118
     * @param array|string $facturas
119
     */
120
    private function getFacturaProgramadaPendiente($facturas)
121
    {
122
        $lista_facturas = explode(',', $facturas);
0 ignored issues
show
It seems like $facturas can also be of type array; however, parameter $string of explode() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

122
        $lista_facturas = explode(',', /** @scrutinizer ignore-type */ $facturas);
Loading history...
123
        $this->idfactura = (is_array($lista_facturas)) ? $lista_facturas[0] : $facturas;
0 ignored issues
show
The condition is_array($lista_facturas) is always true.
Loading history...
124
        if (is_array($lista_facturas)) {
0 ignored issues
show
The condition is_array($lista_facturas) is always true.
Loading history...
125
            unset($lista_facturas[0]);
126
            $this->contador_facturas = count($lista_facturas);
127
            $this->facturas = implode(',', $lista_facturas);
128
        } else {
129
            $this->contador_facturas = 0;
130
            $this->facturas = '';
131
        }
132
        $facturasCliente = new factura_cliente();
133
        $f = $facturasCliente->get($this->idfactura);
134
        $this->factura = $f;
135
        $this->obtenerInformacionResidente($f->codcliente);
136
    }
137
138
    public function crearEstadoCuenta()
139
    {
140
        $info_accion = $this->filter_request('info_accion');
141
        $estadoCuentaGenerador = new ResidentesEstadoCuenta(
142
            $this->empresa,
143
            $this->cliente_residente,
144
            $this->user,
145
            $this->archivo,
146
            $info_accion
147
        );
148
        $pendientes = $this->pagosFactura();
149
        $pagado = $this->pagosFactura(true);
150
        $estadoCuentaGenerador->crearEstadoCuenta($pendientes, $pagado);
151
    }
152
153
    public function crearFacturaDetallada()
154
    {
155
        $infoAccion = $this->filter_request('info_accion');
156
        $this->documento = new residentesFacturaDetallada('L', 'mm', 'A5', $infoAccion, $this->archivo, $this->user);
157
        $this->documento->crearFactura($this->empresa, $this->factura, $this->cliente_residente);
158
    }
159
160
    /**
161
     * @throws phpmailerException
162
     */
163
    public function enviar_documento($tipo_documento)
164
    {
165
        $this->crear_documento($tipo_documento);
166
    }
167
168
    public function imprimir_documento($tipo_documento)
169
    {
170
        $this->template = false;
171
        $this->crear_documento($tipo_documento);
172
    }
173
174
    public function init()
175
    {
176
        $this->envio_masivo = false;
177
        $this->existe_tesoreria();
178
        $this->cliente_residente = false;
179
        if (!file_exists('tmp/' . FS_TMP_NAME . 'enviar') &&
180
            !mkdir($concurrentDirectory = 'tmp/' . FS_TMP_NAME . 'enviar') &&
181
            !is_dir($concurrentDirectory)) {
182
            throw new \RuntimeException(sprintf('Directory "%s" was not created', $concurrentDirectory));
183
        }
184
    }
185
186
    public function is_html($txt)
187
    {
188
        return $txt !== strip_tags($txt);
189
    }
190
}
191