1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* Copyright (C) 2019 joenilson. |
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\model; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Description of residentes_facturacion_programada |
25
|
|
|
* |
26
|
|
|
* @author joenilson |
27
|
|
|
*/ |
28
|
|
|
class residentes_facturacion_programada extends \fs_model |
29
|
|
|
{ |
30
|
|
|
public $id; |
31
|
|
|
public $descripcion; |
32
|
|
|
public $forma_pago; |
33
|
|
|
public $formato_factura; |
34
|
|
|
public $fecha_envio; |
35
|
|
|
public $hora_envio; |
36
|
|
|
public $residentes_facturar; |
37
|
|
|
public $facturas_generadas; |
38
|
|
|
public $usuario_creacion; |
39
|
|
|
public $usuario_modificacion; |
40
|
|
|
public $estado; |
41
|
|
|
public $fecha_creacion; |
42
|
|
|
public $fecha_modificacion; |
43
|
|
|
public $ahora; |
44
|
|
|
public $horaActual; |
45
|
|
|
|
46
|
|
|
public function __construct($t = false) |
47
|
|
|
{ |
48
|
|
|
parent::__construct('residentes_fact_prog', 'plugins/residentes'); |
49
|
|
|
if ($t) { |
50
|
|
|
$this->id = $t['id']; |
51
|
|
|
$this->descripcion = $t['descripcion']; |
52
|
|
|
$this->forma_pago = $t['forma_pago']; |
53
|
|
|
$this->formato_factura = $t['formato_factura']; |
54
|
|
|
$this->fecha_envio = $t['fecha_envio']; |
55
|
|
|
$this->hora_envio = $t['hora_envio']; |
56
|
|
|
$this->residentes_facturar = $t['residentes_facturar']; |
57
|
|
|
$this->facturas_generadas = $t['facturas_generadas']; |
58
|
|
|
$this->usuario_creacion = $t['usuario_creacion']; |
59
|
|
|
$this->usuario_modificacion = $t['usuario_modificacion']; |
60
|
|
|
$this->estado = $t['estado']; |
61
|
|
|
$this->fecha_creacion = $t['fecha_creacion']; |
62
|
|
|
$this->fecha_modificacion = $t['fecha_modificacion']; |
63
|
|
|
} else { |
64
|
|
|
$this->id = null; |
65
|
|
|
$this->descripcion = ''; |
66
|
|
|
$this->forma_pago = ''; |
67
|
|
|
$this->formato_factura = 'plantillas_pdf'; |
68
|
|
|
$this->fecha_envio = null; |
69
|
|
|
$this->hora_envio = null; |
70
|
|
|
$this->residentes_facturar = 0; |
71
|
|
|
$this->facturas_generadas = 0; |
72
|
|
|
$this->usuario_creacion = null; |
73
|
|
|
$this->usuario_modificacion = null; |
74
|
|
|
$this->estado = 'ENCOLA'; |
75
|
|
|
$this->fecha_creacion = null; |
76
|
|
|
$this->fecha_modificacion = null; |
77
|
|
|
} |
78
|
|
|
$this->ahora = new \DateTime('NOW'); |
79
|
|
|
$this->horaActual = \strtotime($this->ahora->format('H')); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
public function install() |
83
|
|
|
{ |
84
|
|
|
return ""; |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
public function exists() |
88
|
|
|
{ |
89
|
|
|
if (is_null($this->id)) { |
90
|
|
|
return false; |
91
|
|
|
} |
92
|
|
|
return true; |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
public function save() |
96
|
|
|
{ |
97
|
|
|
if ($this->exists()) { |
98
|
|
|
$sql = "UPDATE ".$this->table_name." SET ". |
99
|
|
|
"descripcion = ".$this->var2str($this->descripcion).", ". |
100
|
|
|
"forma_pago = ".$this->var2str($this->forma_pago).", ". |
101
|
|
|
"formato_factura = ".$this->var2str($this->formato_factura).", ". |
102
|
|
|
"fecha_envio = ".$this->var2str($this->fecha_envio).", ". |
103
|
|
|
"hora_envio = ".$this->var2str($this->hora_envio).", ". |
104
|
|
|
"residentes_facturar = ".$this->intval($this->residentes_facturar).", ". |
105
|
|
|
"facturas_generadas = ".$this->intval($this->facturas_generadas).", ". |
106
|
|
|
"estado = ".$this->var2str($this->estado).", ". |
107
|
|
|
"usuario_modificacion = ".$this->var2str($this->usuario_modificacion).", ". |
108
|
|
|
"fecha_modificacion = ".$this->var2str($this->fecha_modificacion)." ". |
109
|
|
|
"WHERE id = ".$this->intval($this->id).";"; |
110
|
|
|
$data = $this->db->exec($sql); |
111
|
|
|
return $data; |
112
|
|
|
} else { |
113
|
|
|
$sql = "INSERT INTO ".$this->table_name. |
114
|
|
|
" (descripcion, forma_pago, formato_factura, fecha_envio, hora_envio, residentes_facturar, ". |
115
|
|
|
"facturas_generadas, usuario_creacion, fecha_creacion, estado) VALUES (". |
116
|
|
|
$this->var2str($this->descripcion).", ". |
117
|
|
|
$this->var2str($this->forma_pago).", ". |
118
|
|
|
$this->var2str($this->formato_factura).", ". |
119
|
|
|
$this->var2str($this->fecha_envio).", ". |
120
|
|
|
$this->var2str($this->hora_envio).", ". |
121
|
|
|
$this->intval($this->residentes_facturar).", ". |
122
|
|
|
$this->intval($this->facturas_generadas).", ". |
123
|
|
|
$this->var2str($this->usuario_creacion).", ". |
124
|
|
|
$this->var2str($this->fecha_creacion).", ". |
125
|
|
|
$this->var2str($this->estado).");"; |
126
|
|
|
if ($this->db->exec($sql)) { |
127
|
|
|
return $this->db->lastval(); |
128
|
|
|
} else { |
129
|
|
|
return false; |
130
|
|
|
} |
131
|
|
|
} |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
/** |
135
|
|
|
* @param integer $id |
136
|
|
|
* @return residentes_facturacion_programada|false |
137
|
|
|
*/ |
138
|
|
|
public function get($id) |
139
|
|
|
{ |
140
|
|
|
$sql = "select * from ".$this->table_name." WHERE id = ".$this->intval($id); |
141
|
|
|
|
142
|
|
|
$data = $this->db->select($sql); |
143
|
|
|
if ($data) { |
144
|
|
|
return new residentes_facturacion_programada($data[0]); |
145
|
|
|
} |
146
|
|
|
return false; |
147
|
|
|
} |
148
|
|
|
|
149
|
|
|
/** |
150
|
|
|
* @param string $date |
151
|
|
|
* @return array|false |
152
|
|
|
*/ |
153
|
|
|
public function get_by_date($date) |
154
|
|
|
{ |
155
|
|
|
$sql = "select * from ".$this->table_name." WHERE fecha_envio = ".$this->var2str($date). |
156
|
|
|
" ORDER BY fecha_envio, hora_envio"; |
157
|
|
|
$data = $this->db->select($sql); |
158
|
|
|
$lista = array(); |
159
|
|
|
if ($data) { |
160
|
|
|
foreach ($data as $d) { |
161
|
|
|
$lista[] = new residentes_facturacion_programada($d); |
162
|
|
|
} |
163
|
|
|
return $lista; |
164
|
|
|
} |
165
|
|
|
return false; |
166
|
|
|
} |
167
|
|
|
|
168
|
|
|
/** |
169
|
|
|
* @param integer $id |
170
|
|
|
* @param string $status |
171
|
|
|
* @return array|false |
172
|
|
|
*/ |
173
|
|
|
public function get_by_id_and_status($id, $status = 'CONCLUIDO') |
174
|
|
|
{ |
175
|
|
|
$sql = "select * from ".$this->table_name." WHERE ESTADO = ".$this->var2str($status). |
176
|
|
|
" ORDER BY fecha_envio, hora_envio"; |
177
|
|
|
$data = $this->db->select($sql); |
178
|
|
|
$lista = array(); |
179
|
|
|
if ($data) { |
180
|
|
|
foreach ($data as $d) { |
181
|
|
|
$lista[] = new residentes_facturacion_programada($d); |
182
|
|
|
} |
183
|
|
|
return $lista; |
184
|
|
|
} |
185
|
|
|
return false; |
186
|
|
|
} |
187
|
|
|
|
188
|
|
|
/** |
189
|
|
|
* @param string $date |
190
|
|
|
* @param string $status |
191
|
|
|
* @return array|false |
192
|
|
|
*/ |
193
|
|
|
public function get_by_date_status($date, $status) |
194
|
|
|
{ |
195
|
|
|
$sql = "select * from ".$this->table_name." WHERE fecha_envio = ".$this->var2str($date) |
196
|
|
|
." AND "."estado = ".$this->var2str($status)." ORDER BY fecha_envio, hora_envio"; |
197
|
|
|
$data = $this->db->select($sql); |
198
|
|
|
$lista = array(); |
199
|
|
|
if ($data) { |
200
|
|
|
foreach ($data as $d) { |
201
|
|
|
$lista[] = new residentes_facturacion_programada($d); |
202
|
|
|
} |
203
|
|
|
return $lista; |
204
|
|
|
} |
205
|
|
|
return false; |
206
|
|
|
} |
207
|
|
|
|
208
|
|
|
/** |
209
|
|
|
* @param string $date |
210
|
|
|
* @param string $hour |
211
|
|
|
* @param string $status |
212
|
|
|
* @return residentes_facturacion_programada|false |
213
|
|
|
*/ |
214
|
|
|
public function get_by_date_hour_status($date, $hour, $status) |
215
|
|
|
{ |
216
|
|
|
$sql = "select * from ".$this->table_name." WHERE fecha_envio = ".$this->var2str($date) |
217
|
|
|
." AND ". |
218
|
|
|
" hora_envio = ".$this->var2str($hour). |
219
|
|
|
" AND ". |
220
|
|
|
"estado = ".$this->var2str($status)." ORDER BY fecha_envio, hora_envio"; |
221
|
|
|
$data = $this->db->select($sql); |
222
|
|
|
if ($data) { |
223
|
|
|
return new residentes_facturacion_programada($data[0]); |
224
|
|
|
} |
225
|
|
|
return false; |
226
|
|
|
} |
227
|
|
|
|
228
|
|
|
public function all() |
229
|
|
|
{ |
230
|
|
|
$sql = "select * from ".$this->table_name." ORDER BY fecha_envio, hora_envio"; |
231
|
|
|
$data = $this->db->select($sql); |
232
|
|
|
$lista = array(); |
233
|
|
|
if ($data) { |
234
|
|
|
foreach ($data as $d) { |
235
|
|
|
$lista[] = new residentes_facturacion_programada($d); |
236
|
|
|
} |
237
|
|
|
return $lista; |
238
|
|
|
} |
239
|
|
|
return false; |
240
|
|
|
} |
241
|
|
|
|
242
|
|
|
public function delete() |
243
|
|
|
{ |
244
|
|
|
$sql = "DELETE from ".$this->table_name." WHERE id = ".$this->intval($this->id); |
245
|
|
|
$data = $this->db->exec($sql); |
246
|
|
|
if ($data) { |
247
|
|
|
return true; |
248
|
|
|
} |
249
|
|
|
return false; |
250
|
|
|
} |
251
|
|
|
|
252
|
|
|
public function eliminar_facturas() |
253
|
|
|
{ |
254
|
|
|
$rfpe = new residentes_facturacion_programada_edificaciones(); |
255
|
|
|
$listaResidentes = $rfpe->getByIdProgramacion($this->id); |
256
|
|
|
foreach ($listaResidentes as $residente) { |
257
|
|
|
$fact = new factura_cliente(); |
258
|
|
|
$f = $fact->get($residente->idfactura); |
259
|
|
|
if ($f) { |
260
|
|
|
$f->delete(); |
261
|
|
|
} |
262
|
|
|
$residente->procesado = false; |
263
|
|
|
$residente->idfactura = ''; |
264
|
|
|
$residente->save(); |
265
|
|
|
} |
266
|
|
|
} |
267
|
|
|
} |
268
|
|
|
|