Issues (232)

Model/NCFRango.php (1 issue)

1
<?php
2
/**
3
 * Copyright (C) 2019-2020 Joe Zegarra.
4
 *
5
 * This library is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU Lesser General Public
7
 * License as published by the Free Software Foundation; either
8
 * version 3 of the License, or (at your option) any later version.
9
 *
10
 * This library 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 GNU
13
 * Lesser General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU Lesser General Public
16
 * License along with this library; if not, write to the Free Software
17
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
18
 * MA 02110-1301  USA
19
 */
20
21
namespace FacturaScripts\Plugins\fsRepublicaDominicana\Model;
22
23
use FacturaScripts\Core\Model\Base;
24
use FacturaScripts\Core\Base\DataBase;
25
26
/**
27
 * Description of NCFRango
28
 *
29
 * @author Joe Zegarra
30
 */
31
class NCFRango extends Base\ModelClass
32
{
33
    use Base\ModelTrait;
34
    
35
    /**
36
     * The key of all the records
37
     * @var int
38
     */
39
    public $id;
40
    
41
    /**
42
     * Authorization number gived by DGII
43
     * @var int
44
     */
45
    public $autorizacion;
46
    
47
    /**
48
     * Old record for printing area
49
     * @var string
50
     * @deprecated since version 2017.50 added only for migration purposes
51
     */
52
    public $areaimpresion;
53
    
54
    /**
55
     * Old record for warehouse location
56
     * @var string
57
     * @deprecated since version 2017.50 added only for migration purposes
58
     */
59
    public $codalmacen;
60
    
61
    /**
62
     * Old record for cash or credit payment rule
63
     * @var bool
64
     * @deprecated since version 2017.50
65
     */
66
    public $contado;
67
    
68
    /**
69
     * The next number to assign for a NCF number
70
     * @var int
71
     */
72
    public $correlativo;
73
    
74
    /**
75
     * Old record for business unit where had been generated the NCF
76
     * @var string
77
     * @deprecated since version 2017.50
78
     */
79
    public $division;
80
    
81
    /**
82
     * Status of the record true or false, true if active
83
     * @var bool
84
     */
85
    public $estado;
86
    
87
    /**
88
     * Record creation date
89
     * @var date
90
     */
91
    public $fechacreacion;
92
    
93
    /**
94
     * Record modification date
95
     * @var date
96
     */
97
    public $fechamodificacion;
98
    
99
    /**
100
     * NCF Authorization expiration date
101
     * @var date
102
     */
103
    public $fechavencimiento;
104
    
105
    /**
106
     * Compnay id for who the records is created
107
     * @var int
108
     */
109
    public $idempresa;
110
    
111
    /**
112
     * Old record for point of NCF generation
113
     * @var string
114
     * @deprecated since version 2017.50
115
     */
116
    public $puntoemision;
117
    
118
    /**
119
     * Start number for the DGII NCF sequence
120
     * @var int
121
     */
122
    public $secuenciainicio;
123
    /**
124
     * Last number for the DGII NCF sequence
125
     * @var int
126
     */
127
    public $secuenciafin;
128
    
129
    /**
130
     * The letter assigned to the NCF sequence
131
     * @var string
132
     */
133
    public $serie;
134
    
135
    /**
136
     * The request number generated in the DGII Virtual Office for the NCF sequence
137
     * @var int
138
     */
139
    public $solicitud;
140
    
141
    /**
142
     * The NCF type for this sequence
143
     * @var string
144
     */
145
    public $tipocomprobante;
146
    
147
    /**
148
     * The user nickname that created the record
149
     * @var string
150
     */
151
    public $usuariocreacion;
152
    
153
    /**
154
     * The user nickname that modified the record
155
     * @var string
156
     */
157
    public $usuariomodificacion;
158
    
159
    public static function primaryColumn(): string
160
    {
161
        return 'id';
162
    }
163
    
164
    public static function tableName(): string
165
    {
166
        return 'rd_ncfrango';
167
    }
168
    
169
    protected function saveUpdate(array $values = array()): bool
170
    {
171
        if ($this->id and isset($this->usuariomodificacion_view)) {
172
            $this->fechamodificacion = \date('d-m-Y');
0 ignored issues
show
Documentation Bug introduced by
It seems like date('d-m-Y') of type string is incompatible with the declared type FacturaScripts\Plugins\f...caDominicana\Model\date of property $fechamodificacion.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
173
            $this->usuariomodificacion = $this->usuariomodificacion_view;
174
        }
175
        return parent::saveUpdate($values);
176
    }
177
    
178
    public function getByTipoComprobante($idempresa, $tipocomprobante)
179
    {
180
        $dataBase = new DataBase();
181
        $sql = 'SELECT * FROM '
182
                . $this->tableName()
183
                . ' WHERE idempresa = '
184
                . $idempresa
185
                . ' AND tipocomprobante = '
186
                . $dataBase->var2str($tipocomprobante)
187
                . ' AND estado = ' . $dataBase->var2str(true)
188
                . ' AND correlativo <= secuenciafin '
189
                . ';';
190
        $data = $dataBase->select($sql);
191
        if (empty($data) === true || in_array($data[0], [null, ''], true)) {
192
            return false;
193
        }
194
        return new NCFRango($data[0]);
195
    }
196
    
197
    public function generateNCF()
198
    {
199
        return $this->serie
200
        . $this->tipocomprobante
201
        . \str_pad($this->correlativo, 8, '0', STR_PAD_LEFT);
202
    }
203
}
204