Issues (2050)

extras/residentesFacturaDetallada.php (2 issues)

Labels
Severity
1
<?php
2
/*
3
 * Copyright (C) 2021 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
require_once 'base/fs_controller.php';
19
require_once 'plugins/residentes/extras/residentes_controller.php';
20
require_once 'plugins/residentes/extras/residentesEnviarMail.php';
21
require_once 'plugins/residentes/extras/fpdf183/ResidentesFpdf.php';
22
23
class residentesFacturaDetallada
24
{
25
    public $archivo ;
26
    public $document;
27
    public $emailHelper;
28
    public $output;
29
    public $user;
30
    public $log;
31
    private $residentesController;
32
    public function __construct($orientation = 'L', $um = 'mm', $size = 'A5', $output = 'enviar', $archivo = 'doc.pdf', $user = 'cron')
33
    {
34
        $this->archivo = ($archivo) ?: \date('dmYHis') . ".pdf";
35
        $this->output = $output;
36
        $this->user = $user;
37
        $this->log = new fs_core_log();
0 ignored issues
show
The type fs_core_log 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...
38
        $this->emailHelper = new ResidentesEnviarMail();
39
        $this->document = new ResidentesFpdf($orientation, $um, $size);
0 ignored issues
show
The type ResidentesFpdf 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...
40
        $this->residentesController = new residentes_controller();
41
    }
42
43
    /**
44
     * @param object $companyInformation
45
     * @param object $invoice
46
     * @param object $customer
47
     */
48
    public function crearFactura(&$companyInformation, &$invoice, &$customer)
49
    {
50
        $datosFactura = $this->invoiceData($companyInformation, $invoice);
51
        $datosEmpresa = (array) $companyInformation;
52
        $customerInfo = (array) $customer;
53
        $customerInfo['direccion'] = trim($customer->inmueble->codigo_externo()) . " numero " . $customer->inmueble->numero;
54
        $this->document->createDocument($datosEmpresa, $datosFactura[0], $datosFactura[1], $customerInfo);
55
        $this->residentesController->cliente_residente = $customer;
56
        $pendiente = $this->residentesController->pagosFactura(false);
57
        $this->document->addEstadoCuentaPendiente($pendiente);
58
        if ($this->output === 'enviar') {
59
            $this->document->Output(
60
                'F',
61
                'tmp/' . FS_TMP_NAME . 'enviar/' . $this->archivo,
62
                true
63
            );
64
            if(isset($_POST['email']) && $_POST['email'] !== '') {
65
                $customer->email = $_POST['email'];
66
            }
67
            $this->emailHelper->invoiceEmail($companyInformation, $invoice, $customer, $this->user, $this->archivo);
68
        } else {
69
            $this->document->Output(
70
                'I',
71
                'factura_' .$datosFactura[0]['numero2']. '_' . \date('dmYhis') . '.pdf'
72
            );
73
        }
74
    }
75
76
    private function invoiceData($empresa, $invoice)
77
    {
78
        $datosFacturaDetalle = [];
79
        $datosFacturaCabecera = (array) $invoice;
80
        if (class_exists('ncf_ventas')) {
81
            $ncf = new ncf_ventas();
82
            $ncfTipo = $ncf->get($empresa->id, $invoice->numero2);
83
            $datosFacturaCabecera['tiponcf'] = $ncfTipo[0]->tipo_descripcion;
84
            $datosFacturaCabecera['vencimientoncf'] = $ncfTipo[0]->fecha_vencimiento;
85
            $datosFacturaCabecera['condicion'] = $invoice->pagada ? 'Pagada' : 'Pendiente de pago';
86
        }
87
        $lineas = $invoice->get_lineas();
88
        $totalAntesDescuento = 0;
89
        $totalDescuento = 0;
90
        foreach ($lineas as $linea) {
91
            $totalAntesDescuento += $linea->pvpsindto;
92
            $totalDescuento += ($linea->pvpsindto - $linea->pvptotal);
93
            $datosFacturaDetalle[] = (array) $linea;
94
        }
95
        $datosFacturaCabecera['total_antes_descuento'] = $totalAntesDescuento;
96
        $datosFacturaCabecera['total_descuento'] = $totalDescuento;
97
        return [$datosFacturaCabecera, $datosFacturaDetalle];
98
    }
99
}