Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 1566
0.00% covered (danger)
0.00%
0 / 6
CRAP
n/a
0 / 0
obtenCatalogo
0.00% covered (danger)
0.00%
0 / 1491
0.00% covered (danger)
0.00%
0 / 1
546860
catalogosUnique
0.00% covered (danger)
0.00%
0 / 4
0.00% covered (danger)
0.00%
0 / 1
12
catalogosDefault
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
generaCatalogos
0.00% covered (danger)
0.00%
0 / 23
0.00% covered (danger)
0.00%
0 / 1
342
obtenCatalogos
0.00% covered (danger)
0.00%
0 / 5
0.00% covered (danger)
0.00%
0 / 1
12
obtenClientesConPermiso
0.00% covered (danger)
0.00%
0 / 42
0.00% covered (danger)
0.00%
0 / 1
210
1<?php
2
3/** @noinspection PhpMissingReturnTypeInspection */
4/** @noinspection SqlResolve */
5/** @noinspection SqlSignature */
6
7function obtenCatalogo($nombreCatalogo ='', $genera=false, $extraId='', $printFiles = false, $categoria_id = -1)
8{
9    global $gIAsql;
10    $gIAsql['trace']=true;
11
12    if(empty($nombreCatalogo))
13        return false;
14    $nombre = $nombreCatalogo;
15    $method = __METHOD__;
16    $jsonData='';
17    global $gWebDir;
18    $path = "C:\\wamp\\www\\$gWebDir\\backoffice\\json\\";
19    $ext = "html";
20    $fileName = $path.$nombreCatalogo.$extraId.".".$ext;
21    //$fieldName = ''; $fieldDesc = '';
22    //$vsTable = ''; $vsFieldID = '';
23    $sqlComment = __METHOD__ . ' ' . $nombreCatalogo;
24    switch($nombreCatalogo)
25    {
26        case 'doctos_cliente':
27            if(!$genera && file_exists($fileName))
28                $jsonData = file_get_contents($fileName);
29            if(strlen($jsonData) === 0)
30            {
31                /** @noinspection SqlConstantExpression */
32                $sql = "SELECT /*$sqlComment*/ 
33IF(cli.nombre IS NULL,'CLIENTE NO EXISTE', cli.nombre) AS cliente,
34IF(cli.nombre IS NULL,'CLIENTE NO EXISTE', cli.nombre) AS real_data,
35IF(cli.nombre IS NULL,'CLIENTE NO EXISTE', cli.nombre) AS label,
36IF(cli.nombre IS NULL,'CLIENTE NO EXISTE', cli.nombre) AS value
37FROM cheque AS doc
38LEFT OUTER JOIN cliente cli ON doc.cliente_id=cli.cliente_id
39GROUP BY cli.cliente_id
40UNION ALL
41SELECT
42IF(cli.nombre IS NULL,'CLIENTE NO EXISTE', cli.nombre) AS cliente,
43IF(cli.nombre IS NULL,'CLIENTE NO EXISTE', cli.nombre) AS real_data,
44IF(cli.nombre IS NULL,'CLIENTE NO EXISTE', cli.nombre) AS label,
45IF(cli.nombre IS NULL,'CLIENTE NO EXISTE', cli.nombre) AS value
46FROM pagare AS doc
47LEFT OUTER JOIN cliente cli ON doc.cliente_id=cli.cliente_id
48GROUP BY cli.cliente_id
49UNION ALL
50SELECT
51IF(doc.cliente_id IS NULL, doc.cliente, IF(cli.nombre IS NULL,'CLIENTE NO EXISTE', cli.nombre)) AS cliente,
52IF(doc.cliente_id IS NULL, doc.cliente, IF(cli.nombre IS NULL,'CLIENTE NO EXISTE', cli.nombre)) AS real_data,
53IF(doc.cliente_id IS NULL, doc.cliente, IF(cli.nombre IS NULL,'CLIENTE NO EXISTE', cli.nombre)) AS label,
54IF(doc.cliente_id IS NULL, doc.cliente, IF(cli.nombre IS NULL,'CLIENTE NO EXISTE', cli.nombre)) AS value
55FROM vale AS doc
56LEFT OUTER JOIN cliente cli ON doc.cliente_id=cli.cliente_id
57GROUP BY cli.cliente_id
58UNION ALL
59SELECT
60IF(cli.nombre IS NULL,'CLIENTE NO EXISTE', cli.nombre) AS cliente,
61IF(cli.nombre IS NULL,'CLIENTE NO EXISTE', cli.nombre) AS real_data,
62IF(cli.nombre IS NULL,'CLIENTE NO EXISTE', cli.nombre) AS label,
63IF(cli.nombre IS NULL,'CLIENTE NO EXISTE', cli.nombre) AS value
64FROM cheque_log AS doc
65LEFT OUTER JOIN cliente cli ON doc.cliente_id=cli.cliente_id
66GROUP BY cli.cliente_id
67UNION ALL
68SELECT
69IF(cli.nombre IS NULL,'CLIENTE NO EXISTE', cli.nombre) AS cliente,
70IF(cli.nombre IS NULL,'CLIENTE NO EXISTE', cli.nombre) AS real_data,
71IF(cli.nombre IS NULL,'CLIENTE NO EXISTE', cli.nombre) AS label,
72IF(cli.nombre IS NULL,'CLIENTE NO EXISTE', cli.nombre) AS value
73FROM pagare_log AS doc
74LEFT OUTER JOIN cliente cli ON doc.cliente_id=cli.cliente_id
75GROUP BY cli.cliente_id
76UNION ALL
77SELECT
78IF(doc.cliente_id IS NULL, doc.cliente, IF(cli.nombre IS NULL,'CLIENTE NO EXISTE', cli.nombre)) AS cliente,
79IF(doc.cliente_id IS NULL, doc.cliente, IF(cli.nombre IS NULL,'CLIENTE NO EXISTE', cli.nombre)) AS real_data,
80IF(doc.cliente_id IS NULL, doc.cliente, IF(cli.nombre IS NULL,'CLIENTE NO EXISTE', cli.nombre)) AS label,
81IF(doc.cliente_id IS NULL, doc.cliente, IF(cli.nombre IS NULL,'CLIENTE NO EXISTE', cli.nombre)) AS value
82FROM vale_log AS doc
83LEFT OUTER JOIN cliente cli ON doc.cliente_id=cli.cliente_id
84GROUP BY cli.cliente_id
85ORDER BY cliente";
86
87                $array = ia_sqlArray($sql,'cliente');
88                //$array = ia_sqlArrayIndx($sql);
89                jsonFile($fileName, $array);
90                $jsonData = json_encode($array);
91            }
92            break;
93
94        case 'doctos_cliente_id':
95
96            $nombre = 'cliente'; $fieldName = 'cliente_id'; $fieldDesc = 'nombre';
97            $vsTable = 'doctos'; $vsFieldID = 'cliente_id';
98            $jsonData = obtenClientesConPermiso(
99                $fileName, $genera=true,$nombre, $fieldName, $fieldDesc,
100                $vsTable, $vsFieldID, '', 'docto', '');
101            break;
102
103            if(!$genera && file_exists($fileName))
104                $jsonData = file_get_contents($fileName);
105            if(strlen($jsonData) === 0)
106            {
107                $nombre = 'cliente'; $fieldName = 'cliente_id'; $fieldDesc = 'nombre'; $vsTable = 'doctos'; $vsFieldID = 'cliente_id';
108                /** @noinspection SqlSignature */
109                $sql = "SELECT /*$sqlComment*/  $fieldName$fieldDesc$fieldName as real_data, $fieldDesc as label, $fieldName as value FROM $nombre WHERE EXISTS (SELECT 1 FROM $vsTable WHERE $nombre.$fieldName=$vsTable.$vsFieldID) ORDER BY 2";
110                
111                $array = ia_sqlArrayIndx($sql);
112                jsonFile($fileName, $array);
113                $jsonData = json_encode($array);
114            }
115            break;
116
117        case 'doctos_tienda':
118
119            if(!$genera && file_exists($fileName))
120                $jsonData = file_get_contents($fileName);
121            if(strlen($jsonData) === 0)
122            {
123                $nombre = 'tienda'; $fieldName = 'tienda_id'; $fieldDesc = 'clave'; $vsTable = 'doctos'; $vsFieldID = 'tienda_id';
124                /** @noinspection SqlSignature */
125                $sql = "SELECT /*$sqlComment*/  $fieldName$fieldDesc$fieldName as real_data, $fieldDesc as label, $fieldName as value FROM $nombre WHERE EXISTS (SELECT 1 FROM $vsTable WHERE $nombre.$fieldName=$vsTable.$vsFieldID) AND $nombre.vale='Active' ORDER BY 2";
126                
127                $array = ia_sqlArrayIndx($sql);
128                jsonFile($fileName, $array);
129                $jsonData = json_encode($array);
130            }
131            break;
132
133        case 'doctos_moneda':
134
135            if(!$genera && file_exists($fileName))
136                $jsonData = file_get_contents($fileName);
137            if(strlen($jsonData) === 0)
138            {
139                $nombre = 'moneda'; $fieldName = 'moneda_id'; $fieldDesc = 'moneda'; $vsTable = 'doctos'; $vsFieldID = 'moneda_id';
140                /** @noinspection SqlSignature */
141                $sql = "SELECT /*$sqlComment*/  $fieldName$fieldDesc$fieldName as real_data, $fieldDesc as label, $fieldName as value 
142                FROM $nombre WHERE EXISTS (SELECT 1 FROM $vsTable WHERE $nombre.$fieldName=$vsTable.$vsFieldID) ORDER BY 2";
143                
144                $array = ia_sqlArrayIndx($sql);
145                jsonFile($fileName, $array);
146                $jsonData = json_encode($array);
147            }
148            break;
149
150
151        case 'doctos_cuentat_deliveredto_id':
152
153            if(!$genera && file_exists($fileName))
154                $jsonData = file_get_contents($fileName);
155            if(strlen($jsonData) === 0)
156            {
157                $nombre = 'cuentat'; $fieldName = 'cuentaT_id'; $fieldDesc = 'usuario'; $vsTable = 'doctos'; $vsFieldID = 'cuentaT_deliveredto_id';
158                /** @noinspection SqlSignature */
159                $sql = "SELECT /*$sqlComment*/  $fieldName$fieldDesc$fieldName as real_data, $fieldDesc as label, $fieldName as value FROM $nombre WHERE EXISTS (SELECT 1 FROM $vsTable WHERE $nombre.$fieldName=$vsTable.$vsFieldID) AND $nombre.vale='Active'ORDER BY 2";
160                
161                $array = ia_sqlArrayIndx($sql);
162                jsonFile($fileName, $array);
163                $jsonData = json_encode($array);
164            }
165            break;
166
167
168        case 'doctos_origen_cuentat_id':
169            if(!$genera && file_exists($fileName))
170                $jsonData = file_get_contents($fileName);
171            if(strlen($jsonData) === 0)
172            {
173                $nombre = 'cuentat'; $fieldName = 'cuentaT_id'; $fieldDesc = 'usuario'; $vsTable = 'doctos'; $vsFieldID = 'origen_cuentat_id';
174                /** @noinspection SqlSignature */
175                $sql = "SELECT /*$sqlComment*/  $fieldName$fieldDesc$fieldName as real_data, $fieldDesc as label, $fieldName as value FROM $nombre WHERE EXISTS (SELECT 1 FROM $vsTable WHERE $nombre.$fieldName=$vsTable.$vsFieldID) AND $nombre.vale='Active' ORDER BY 2";
176                
177                //echo "<li>$sql";
178                //die();
179                $array = ia_sqlArrayIndx($sql);
180                jsonFile($fileName, $array);
181                $jsonData = json_encode($array);
182            }
183            break;
184
185        case 'doctos_alta_por':
186            if(!$genera && file_exists($fileName))
187                $jsonData = file_get_contents($fileName);
188            if(strlen($jsonData) === 0)
189            {
190                $sql = "SELECT /*$sqlComment*/  alta_por, alta_por as real_data, alta_por as label, alta_por as value FROM cheque
191GROUP BY alta_por
192UNION
193SELECT alta_por, alta_por as real_data, alta_por as label, alta_por as value FROM pagare
194GROUP BY alta_por
195UNION
196SELECT alta_por, alta_por as real_data, alta_por as label, alta_por as value FROM vale
197UNION
198SELECT alta_por, alta_por as real_data, alta_por as label, alta_por as value FROM cheque_log
199GROUP BY alta_por
200UNION
201SELECT alta_por, alta_por as real_data, alta_por as label, alta_por as value FROM pagare_log
202GROUP BY alta_por
203UNION
204SELECT alta_por, alta_por as real_data, alta_por as label, alta_por as value FROM vale_log
205UNION
206SELECT alta_por, alta_por as real_data, alta_por as label, alta_por as value FROM cheque_pago_log
207WHERE banco_cuenta_id > 0
208GROUP BY alta_por
209UNION
210SELECT alta_por, alta_por as real_data, alta_por as label, alta_por as value FROM pagare_pago_log
211WHERE banco_cuenta_id > 0
212GROUP BY alta_por
213UNION
214SELECT alta_por, alta_por as real_data, alta_por as label, alta_por as value FROM cuentat_a_banco
215WHERE activo = 'No' AND factura_directa = 'NO'
216GROUP BY alta_por
217ORDER BY alta_por";
218                $array = ia_sqlArray($sql,'alta_por');
219                //$array = ia_sqlArrayIndx($sql);
220                jsonFile($fileName, $array);
221                $jsonData = json_encode($array);
222            }
223            break;
224
225        case 'doctos_origen':
226            if(!$genera && file_exists($fileName))
227                $jsonData = file_get_contents($fileName);
228            if(strlen($jsonData) === 0)
229            {
230                $array = array(
231                    array('label'=>'CHEQUE',     'value'=> 'CHEQUE'),
232                    array('label'=>'NOTA',       'value'=> 'NOTA'),
233                    array('label'=>'GASTO',       'value'=> 'GASTO'),
234                    array('label'=>'PAGARE',     'value'=> 'PAGARE'),
235                    array('label'=>'VALE',       'value'=> 'VALE'),
236                    array('label'=>'COMPRA',       'value'=> 'COMPRA'),
237                    array('label'=>'CUENTA T',   'value'=> 'CUENTA T'),
238
239                    array('label'=>'COMPRA CASH','value'=> 'COMPRA CASH'),
240
241
242                    array('label'=>'NOTA CASH','value'=> 'NOTA CASH'),
243                    array('label'=>'GASTO CASH','value'=> 'GASTO CASH'),
244                    array('label'=>'CHEQUE CASH','value'=> 'CHEQUE CASH'),
245                    array('label'=>'CHEQUE LINK','value'=> 'CHEQUE LINK'),
246                    array('label'=>'CHEQUE VALE','value'=> 'CHEQUE VALE'),
247
248                    array('label'=>'PAGARE CASH','value'=> 'PAGARE CASH'),
249                    array('label'=>'PAGARE LINK','value'=> 'PAGARE LINK'),
250                    array('label'=>'PAGARE VALE','value'=> 'PAGARE VALE')
251                );
252                jsonFile($fileName, $array);
253                $jsonData = json_encode($array);
254            }
255            break;
256
257
258        case 'doctos_ultimo_movimiento':
259            if(!$genera && file_exists($fileName))
260                $jsonData = file_get_contents($fileName);
261            if(strlen($jsonData) === 0){
262                $array = array(
263                    array('label'=>'ALTA',             'value'=> 'ALTA'),
264                    array('label'=>'BORRADO',          'value'=> 'BORRADO'),
265                    array('label'=>'A CUENTA BORRADO', 'value'=> 'A CUENTA BORRADO'),
266                    array('label'=>'CLIENTE',          'value'=> 'CLIENTE'),
267                    array('label'=>'CUENTAT ORIGEN',   'value'=> 'CUENTAT ORIGEN'),
268                    array('label'=>'CURRENCY',         'value'=> 'CURRENCY'),
269                    array('label'=>'DELIVERED DIRECTO','value'=> 'DELIVERED DIRECTO'),
270                    array('label'=>'ERROR PAID',       'value'=> 'ERROR PAID'),
271                    array('label'=>'LINK BORRADO',     'value'=> 'LINK BORRADO'),
272                    array('label'=>'LINK PARCIAL BORRADO',     'value'=> 'LINK PARCIAL BORRADO'),
273                    array('label'=>'TIPO CAMBIO',         'value'=> 'TIPO CAMBIO'),
274                    array('label'=>'QUANTITY',         'value'=> 'QUANTITY'),
275                );
276                jsonFile($fileName, $array);
277                $jsonData = json_encode($array);
278            }
279            break;
280
281        case 'links_cuentat_id_activo':
282            if(!$genera && file_exists($fileName))
283                $jsonData = file_get_contents($fileName);
284            if(strlen($jsonData) === 0)
285            {
286                $nombre = 'cuentat'; $fieldName = 'cuentaT_id'; $fieldDesc = 'usuario'; $vsTable = 'links_al_banco_live'; $vsFieldID = 'cuentaT_id'; $xtraWhere = " AND links_al_banco_live.activo='Si' ";
287                /** @noinspection SqlSignature */
288                $sql = "SELECT /*$sqlComment*/  $fieldName$fieldDesc$fieldName as real_data, $fieldDesc as label, $fieldName as value FROM $nombre WHERE EXISTS (SELECT 1 FROM $vsTable WHERE $nombre.$fieldName=$vsTable.$vsFieldID $xtraWhere) AND $nombre.vale='Active' ORDER BY 2";
289
290
291                
292                /*$array = ia_sqlArrayIndx($sql);
293                jsonFile($fileName, $array);
294                $jsonData = json_encode($array);*/
295                $array = ia_sqlArrayIndx($sql);
296                if(empty($array) && file_exists($fileName))
297                    $jsonData = file_get_contents($fileName);
298                else {
299                    jsonFile($fileName, $array);
300                    $jsonData = json_encode($array);
301                }
302            }
303            break;
304
305
306        case 'links_tienda_id_activo':
307            if(!$genera && file_exists($fileName))
308                $jsonData = file_get_contents($fileName);
309            if(strlen($jsonData) === 0)
310            {
311                $nombre = 'tienda'; $fieldName = 'tienda_id'; $fieldDesc = 'clave'; $vsTable = 'links_al_banco_live'; $vsFieldID = 'tienda_id'; $xtraWhere = " AND links_al_banco_live.activo='Si' ";
312                /** @noinspection SqlSignature */
313                $sql = "SELECT /*$sqlComment*/  $fieldName$fieldDesc$fieldName as real_data, $fieldDesc as label, $fieldName as value FROM $nombre WHERE EXISTS (SELECT 1 FROM $vsTable WHERE $nombre.$fieldName=$vsTable.$vsFieldID $xtraWhere) AND $nombre.vale='Active' ORDER BY 2";
314
315                $array = ia_sqlArrayIndx($sql);
316                jsonFile($fileName, $array);
317                $jsonData = json_encode($array);
318            }
319            break;
320
321        case 'links_banco_cuenta_id_activo':
322            if(!$genera && file_exists($fileName))
323                $jsonData = file_get_contents($fileName);
324            if(strlen($jsonData) === 0)
325            {
326                $nombre = 'banco_cuenta'; $fieldName = 'banco_cuenta_id'; $fieldDesc = 'nombre'; $vsTable = 'links_al_banco_live'; $vsFieldID = 'banco_cuenta_id'; $xtraWhere = " AND links_al_banco_live.activo='Si' ";
327                /** @noinspection SqlSignature */
328                $sql = "SELECT /*$sqlComment*/  $fieldName$fieldDesc$fieldName as real_data, $fieldDesc as label, $fieldName as value FROM $nombre WHERE EXISTS (SELECT 1 FROM $vsTable WHERE $nombre.$fieldName=$vsTable.$vsFieldID $xtraWhere) AND $nombre.vale='Active' ORDER BY 2";
329
330                $array = ia_sqlArrayIndx($sql);
331                if(empty($array) && file_exists($fileName))
332                    $jsonData = file_get_contents($fileName);
333                else {
334                    jsonFile($fileName, $array);
335                    $jsonData = json_encode($array);
336                }
337            }
338            break;
339
340        case 'links_cuentat_tipo_mov_id_activo':
341            if(!$genera && file_exists($fileName))
342                $jsonData = file_get_contents($fileName);
343            if(strlen($jsonData) === 0)
344            {
345                $nombre = 'banco_mov_tipo'; $fieldName = 'banco_mov_tipo_id'; $fieldDesc = 'tipo'; $vsTable = 'links_al_banco_live'; $vsFieldID = 'cuentaT_tipo_mov_id'; $xtraWhere = " AND links_al_banco_live.activo='Si' ";
346                /** @noinspection SqlSignature */
347                $sql = "SELECT /*$sqlComment*/  $fieldName$fieldDesc$fieldName as real_data, $fieldDesc as label, $fieldName as value FROM $nombre WHERE EXISTS (SELECT 1 FROM $vsTable WHERE $nombre.$fieldName=$vsTable.$vsFieldID $xtraWhere) ORDER BY 2";
348
349                /*$array = ia_sqlArrayIndx($sql);
350                jsonFile($fileName, $array);
351                $jsonData = json_encode($array);*/
352                $array = ia_sqlArrayIndx($sql);
353                if(empty($array) && file_exists($fileName))
354                    $jsonData = file_get_contents($fileName);
355                else {
356                    jsonFile($fileName, $array);
357                    $jsonData = json_encode($array);
358                }
359            }
360            break;
361
362        case 'links_tipo_cash_nota_movimiento':
363            if(!$genera && file_exists($fileName))
364                $jsonData = file_get_contents($fileName);
365            if(strlen($jsonData) === 0)
366            {
367                $array = arrayTipoCashNota(true);
368                jsonFile($fileName, $array);
369                $jsonData = json_encode($array);
370            }
371            break;
372
373        case 'links_tipo_factura':
374            if(!$genera && file_exists($fileName))
375                $jsonData = file_get_contents($fileName);
376            if(strlen($jsonData) === 0)
377            {
378                $array = arrayTipoFactura(true);
379                jsonFile($fileName, $array);
380                $jsonData = json_encode($array);
381            }
382            break;
383
384        case 'links_empresa_id_activo':
385            if(!$genera && file_exists($fileName))
386                $jsonData = file_get_contents($fileName);
387            if(strlen($jsonData) === 0)
388            {
389                $nombre = 'empresa'; $fieldName = 'empresa_id'; $fieldDesc = 'empresa'; $vsTable = 'links_al_banco_live'; $vsFieldID = 'empresa_id'; $xtraWhere = " AND links_al_banco_live.activo='Si' ";
390                /** @noinspection SqlSignature */
391                $sql = "SELECT /*$sqlComment*/  $fieldName$fieldDesc$fieldName as real_data, $fieldDesc as label, $fieldName as value FROM $nombre WHERE EXISTS (SELECT 1 FROM $vsTable WHERE $nombre.$fieldName=$vsTable.$vsFieldID $xtraWhere) AND $nombre.vale='Active' ORDER BY 2";
392
393                $array = ia_sqlArrayIndx($sql);
394                jsonFile($fileName, $array);
395                $jsonData = json_encode($array);
396            }
397            break;
398
399        case 'links_cuentat_id_activo_ba':
400            if(!$genera && file_exists($fileName))
401                $jsonData = file_get_contents($fileName);
402            if(strlen($jsonData) === 0)
403            {
404                $nombre = 'cuentat'; $fieldName = 'cuentaT_id'; $fieldDesc = 'usuario'; $vsTable = 'links_al_banco_live'; $vsFieldID = 'cuentaT_id'; $xtraWhere = " AND links_al_banco_live.activo='Si' ";
405                /** @noinspection SqlSignature */
406                $sql = "SELECT /*$sqlComment*/  $fieldName$fieldDesc$fieldName as real_data, $fieldDesc as label, $fieldName as value FROM $nombre WHERE EXISTS (SELECT 1 FROM $vsTable WHERE $nombre.$fieldName=$vsTable.$vsFieldID $xtraWhere) AND $nombre.vale='Active' ORDER BY 2";
407
408                //echo $sql;
409                //SELECT ".SQL_CACHE." t.cuentat_id,t.usuario from cuentat t WHERE (t.cuentat_id IN (SELECT cuentaT_id FROM cuentat_a_banco) AND t.cuentat_id IN (". cuentasTPuede('','ver_saldo_y_movimientos') ."))
410
411                
412//                $array = ia_sqlArrayIndx($sql);
413//                jsonFile($fileName, $array);
414//                $jsonData = json_encode($array);
415                $array = ia_sqlArrayIndx($sql);
416                if(empty($array) && file_exists($fileName))
417                    $jsonData = file_get_contents($fileName);
418                else {
419                    jsonFile($fileName, $array);
420                    $jsonData = json_encode($array);
421                }
422            }
423            break;
424
425        case 'links_alta_por':
426            if(!$genera && file_exists($fileName))
427                $jsonData = file_get_contents($fileName);
428            if(strlen($jsonData) === 0)
429            {
430                $sql = "SELECT /*$sqlComment*/  alta_por, alta_por as real_data, alta_por as label, alta_por as value FROM cuentat_a_banco a where (a.activo = 'SI' AND banco_cuenta_id > 0)
431GROUP BY alta_por
432UNION
433SELECT alta_por, alta_por as real_data, alta_por as label, alta_por as value FROM cheque_pago b where (b.banco_cuenta_id > 0 and b.banco_cuenta_mov_link_id <> '')
434GROUP BY alta_por
435UNION
436SELECT alta_por, alta_por as real_data, alta_por as label, alta_por as value FROM pagare_pago c where (c.banco_cuenta_id > 0 and c.banco_cuenta_mov_link_id <> '' )
437UNION
438SELECT alta_por, alta_por as real_data, alta_por as label, alta_por as value FROM vale d where (d.banco_cuenta_id > 0 and d.banco_cuenta_mov_link_id <> '')
439GROUP BY alta_por
440UNION
441SELECT alta_por, alta_por as real_data, alta_por as label, alta_por as value FROM cuentat_a_banco_tc e where (e.activo = 'SI')
442GROUP BY alta_por
443UNION
444SELECT alta_por, alta_por as real_data, alta_por as label, alta_por as value FROM banco_cuenta_trans f where (f.activo = 'SI')
445UNION
446SELECT alta_por, alta_por as real_data, alta_por as label, alta_por as value FROM cheque_pago_log
447WHERE banco_cuenta_id > 0
448GROUP BY alta_por
449UNION
450SELECT alta_por, alta_por as real_data, alta_por as label, alta_por as value FROM pagare_pago_log
451WHERE banco_cuenta_id > 0
452GROUP BY alta_por
453ORDER BY alta_por";
454                $array = ia_sqlArray($sql,'alta_por');
455                //$array = ia_sqlArrayIndx($sql);
456                jsonFile($fileName, $array);
457                $jsonData = json_encode($array);
458            }
459            break;
460
461        case 'links_origen':
462            if(!$genera && file_exists($fileName))
463                $jsonData = file_get_contents($fileName);
464            if(strlen($jsonData) === 0)
465            {
466                $array = array(
467                    array('label'=>'CUENTAT',   'value'=> 'CUENTAT'),
468                    array('label'=>'CHEQUE',    'value'=> 'CHEQUE'),
469                    array('label'=>'PAGARE',    'value'=> 'PAGARE'),
470                    array('label'=>'VALE',      'value'=> 'VALE'),
471                    array('label'=>'VALEPAGO',  'value'=> 'VALEPAGO'),
472                    array('label'=>'TC',        'value'=> 'TARJ CRED'),
473                    array('label'=>'PROP',      'value'=> 'PROPIAS'),
474                    array('label'=>'INVERSION', 'value'=> 'INVERSION'),
475                    array('label'=>'FIDUCIARIO','value'=> 'FIDUCIARIO'),
476                );
477                jsonFile($fileName, $array);
478                $jsonData = json_encode($array);
479            }
480            break;
481
482
483        case 'acuentas_cliente':
484            if(!$genera && file_exists($fileName))
485                $jsonData = file_get_contents($fileName);
486            if(strlen($jsonData) === 0)
487            {
488                /** @noinspection SqlConstantExpression */
489                /** @noinspection SqlConstantExpression */
490                $sql = "SELECT /*$sqlComment*/ 
491IF(cli.nombre IS NULL,'CLIENTE NO EXISTE', cli.nombre) AS cliente,
492IF(cli.nombre IS NULL,'CLIENTE NO EXISTE', cli.nombre) AS real_data,
493IF(cli.nombre IS NULL,'CLIENTE NO EXISTE', cli.nombre) AS label,
494IF(cli.nombre IS NULL,'CLIENTE NO EXISTE', cli.nombre) AS value
495FROM cheque AS doc
496LEFT OUTER JOIN cliente cli ON doc.cliente_id=cli.cliente_id
497GROUP BY cli.cliente_id
498UNION ALL
499SELECT
500IF(cli.nombre IS NULL,'CLIENTE NO EXISTE', cli.nombre) AS cliente,
501IF(cli.nombre IS NULL,'CLIENTE NO EXISTE', cli.nombre) AS real_data,
502IF(cli.nombre IS NULL,'CLIENTE NO EXISTE', cli.nombre) AS label,
503IF(cli.nombre IS NULL,'CLIENTE NO EXISTE', cli.nombre) AS value
504FROM pagare AS doc
505LEFT OUTER JOIN cliente cli ON doc.cliente_id=cli.cliente_id
506GROUP BY cli.cliente_id
507UNION ALL
508SELECT
509IF(doc.cliente_id IS NULL, doc.cliente, IF(cli.nombre IS NULL,'CLIENTE NO EXISTE', cli.nombre)) AS cliente,
510IF(doc.cliente_id IS NULL, doc.cliente, IF(cli.nombre IS NULL,'CLIENTE NO EXISTE', cli.nombre)) AS real_data,
511IF(doc.cliente_id IS NULL, doc.cliente, IF(cli.nombre IS NULL,'CLIENTE NO EXISTE', cli.nombre)) AS label,
512IF(doc.cliente_id IS NULL, doc.cliente, IF(cli.nombre IS NULL,'CLIENTE NO EXISTE', cli.nombre)) AS value
513FROM vale AS doc
514LEFT OUTER JOIN cliente cli ON doc.cliente_id=cli.cliente_id
515GROUP BY cli.cliente_id
516ORDER BY cliente";
517
518                $array = ia_sqlArray($sql,'cliente');
519                //$array = ia_sqlArrayIndx($sql);
520                jsonFile($fileName, $array);
521                $jsonData = json_encode($array);
522            }
523            break;
524
525        case 'acuentas_alta_por':
526            if(!$genera && file_exists($fileName))
527                $jsonData = file_get_contents($fileName);
528            if(strlen($jsonData) === 0)
529            {
530                $sql = "SELECT /*$sqlComment*/  alta_por as alta_por, alta_por as real_data, alta_por as label, alta_por as value FROM cheque_pago
531GROUP BY alta_por
532UNION
533SELECT alta_por as alta_por, alta_por as real_data, alta_por as label, alta_por as value FROM pagare_pago
534GROUP BY alta_por
535UNION
536SELECT alta_por as alta_por, alta_por as real_data, alta_por as label, alta_por as value FROM vale
537GROUP BY alta_por
538ORDER BY alta_por";
539                $array = ia_sqlArray($sql,'alta_por');
540                //$array = ia_sqlArrayIndx($sql);
541                jsonFile($fileName, $array);
542                $jsonData = json_encode($array);
543            }
544            break;
545
546        case 'acuentas_cliente_id':
547
548            if(!$genera && file_exists($fileName))
549                $jsonData = file_get_contents($fileName);
550            if(strlen($jsonData) === 0)
551            {
552                /** @noinspection SqlConstantExpression */
553                $sql = "SELECT /*$sqlComment*/ 
554IF(cli.nombre IS NULL,'CLIENTE NO EXISTE', cli.nombre) AS cliente,
555IF(cli.nombre IS NULL,'CLIENTE NO EXISTE', cli.cliente_id) AS real_data,
556IF(cli.nombre IS NULL,'CLIENTE NO EXISTE', cli.nombre) AS label,
557IF(cli.nombre IS NULL,'CLIENTE NO EXISTE', cli.cliente_id) AS value
558FROM cheque AS doc
559LEFT OUTER JOIN cliente cli ON doc.cliente_id=cli.cliente_id
560GROUP BY cli.cliente_id
561UNION ALL
562SELECT
563IF(cli.nombre IS NULL,'CLIENTE NO EXISTE', cli.nombre) AS cliente,
564IF(cli.nombre IS NULL,'CLIENTE NO EXISTE', cli.cliente_id) AS real_data,
565IF(cli.nombre IS NULL,'CLIENTE NO EXISTE', cli.nombre) AS label,
566IF(cli.nombre IS NULL,'CLIENTE NO EXISTE', cli.cliente_id) AS value
567FROM pagare AS doc
568LEFT OUTER JOIN cliente cli ON doc.cliente_id=cli.cliente_id
569GROUP BY cli.cliente_id
570UNION ALL
571SELECT
572IF(doc.cliente_id IS NULL, doc.cliente, IF(cli.nombre IS NULL,'CLIENTE NO EXISTE', cli.nombre)) AS cliente,
573IF(doc.cliente_id IS NULL, doc.cliente, IF(cli.nombre IS NULL,'CLIENTE NO EXISTE', cli.cliente_id)) AS real_data,
574IF(doc.cliente_id IS NULL, doc.cliente, IF(cli.nombre IS NULL,'CLIENTE NO EXISTE', cli.nombre)) AS label,
575IF(doc.cliente_id IS NULL, doc.cliente, IF(cli.nombre IS NULL,'CLIENTE NO EXISTE', cli.cliente_id)) AS value
576FROM vale AS doc
577LEFT OUTER JOIN cliente cli ON doc.cliente_id=cli.cliente_id
578GROUP BY cli.cliente_id
579ORDER BY cliente";
580                $array = ia_sqlArray($sql,'real_data');
581                jsonFile($fileName, $array);
582                $jsonData = json_encode($array);
583            }
584            break;
585
586        case 'acuentas_origen':
587            if(!$genera && file_exists($fileName))
588                $jsonData = file_get_contents($fileName);
589            if(strlen($jsonData) === 0)
590            {
591                $array = array(
592                    array('label'=>'CHEQUE',     'value'=> 'CHEQUE'),
593                    array('label'=>'PAGARE',     'value'=> 'PAGARE'),
594                    array('label'=>'VALE',       'value'=> 'VALE')
595                );
596                jsonFile($fileName, $array);
597                $jsonData = json_encode($array);
598            }
599            break;
600
601        case 'acuentas_cuentat_id':
602
603            if(!$genera && file_exists($fileName))
604                $jsonData = file_get_contents($fileName);
605            if(strlen($jsonData) === 0)
606            {
607                $sql = "SELECT /*$sqlComment*/ 
608doc.cuentaT_id AS real_data,
609cli.usuario AS label,
610doc.cuentaT_id AS value
611FROM cheque_pago AS doc
612LEFT OUTER JOIN cuentat cli ON doc.cuentaT_id=cli.cuentaT_id
613GROUP BY cli.cuentaT_id
614UNION ALL
615SELECT
616doc.cuentaT_id AS real_data,
617cli.usuario AS label,
618doc.cuentaT_id AS value
619FROM pagare_pago AS doc
620LEFT OUTER JOIN cuentat cli ON doc.cuentaT_id=cli.cuentaT_id
621GROUP BY cli.cuentaT_id
622UNION ALL
623SELECT
624doc.dinero_en_cuentaT_id AS real_data,
625cli.usuario AS label,
626doc.dinero_en_cuentaT_id AS value
627FROM vale AS doc
628LEFT OUTER JOIN cuentat cli ON doc.dinero_en_cuentaT_id=cli.cuentaT_id
629GROUP BY cli.cuentaT_id
630ORDER BY label";
631                $array = ia_sqlArray($sql,'real_data');
632                jsonFile($fileName, $array);
633                $jsonData = json_encode($array);
634            }
635            break;
636
637        case 'acuentas_metodo_pago_id':
638            if(!$genera && file_exists($fileName))
639                $jsonData = file_get_contents($fileName);
640            if(strlen($jsonData) === 0)
641            {
642                $nombre = 'banco_mov_tipo'; $fieldName = 'banco_mov_tipo_id'; $fieldDesc = 'tipo';
643                $sql = "SELECT /*$sqlComment*/  $fieldName$fieldDesc$fieldName as real_data, $fieldDesc as label, $fieldName as value FROM $nombre WHERE $fieldName IN('1','2','14') ORDER BY 2";
644
645                $array = ia_sqlArrayIndx($sql);
646                jsonFile($fileName, $array);
647                $jsonData = json_encode($array);
648            }
649            break;
650
651        case 'acuentas_banco_cuenta_id':
652
653            if(!$genera && file_exists($fileName))
654                $jsonData = file_get_contents($fileName);
655            if(strlen($jsonData) === 0)
656            {
657                $sql = "SELECT /*$sqlComment*/ 
658doc.banco_cuenta_id AS real_data,
659cli.nombre AS label,
660doc.banco_cuenta_id AS value
661FROM cheque_pago AS doc
662LEFT OUTER JOIN banco_cuenta cli ON doc.banco_cuenta_id=cli.banco_cuenta_id
663WHERE cli.vale='Active'
664GROUP BY cli.banco_cuenta_id
665UNION ALL
666SELECT
667doc.banco_cuenta_id AS real_data,
668cli.nombre AS label,
669doc.banco_cuenta_id AS value
670FROM pagare_pago AS doc
671LEFT OUTER JOIN banco_cuenta cli ON doc.banco_cuenta_id=cli.banco_cuenta_id
672WHERE cli.vale='Active'
673GROUP BY cli.banco_cuenta_id
674UNION ALL
675SELECT
676doc.banco_cuenta_id AS real_data,
677cli.nombre AS label,
678doc.banco_cuenta_id AS value
679FROM vale AS doc
680LEFT OUTER JOIN banco_cuenta cli ON doc.banco_cuenta_id=cli.banco_cuenta_id
681WHERE cli.vale='Active'
682GROUP BY cli.banco_cuenta_id
683ORDER BY label";
684                $array = ia_sqlArray($sql,'real_data');
685                jsonFile($fileName, $array);
686                $jsonData = json_encode($array);
687            }
688            break;
689
690        case 'cuentat_gasto_cuentat_id_activo':
691            if(!$genera && file_exists($fileName))
692                $jsonData = file_get_contents($fileName);
693            if(strlen($jsonData) === 0)
694            {
695                $nombre = 'cuentat'; $fieldName = 'cuentaT_id'; $fieldDesc = 'usuario'; $vsTable = 'cuentat_gasto'; $vsFieldID = 'cuentaT_id'; $xtraWhere = " AND cuentat_gasto.activo='Si' ";
696                /** @noinspection SqlSignature */
697                $sql = "SELECT /*$sqlComment*/  $fieldName$fieldDesc$fieldName as real_data, $fieldDesc as label, $fieldName as value FROM $nombre WHERE EXISTS (SELECT 1 FROM $vsTable WHERE $nombre.$fieldName=$vsTable.$vsFieldID $xtraWhere) AND $nombre.vale='Active' ORDER BY 2";
698
699                $array = ia_sqlArrayIndx($sql);
700                jsonFile($fileName, $array);
701                $jsonData = json_encode($array);
702            }
703            break;
704
705        case 'cuentat_gasto_plantilla':case 'plantilla_cuentat_gasto_id':
706        if(!$genera && file_exists($fileName))
707            $jsonData = file_get_contents($fileName);
708        if(strlen($jsonData) === 0)
709        {
710            $nombre = 'plantilla_cuentat_gasto'; $fieldName = 'plantilla_cuentat_gasto_id'; $fieldDesc = 'nombre'; $vsTable = 'cuentat_gasto'; $vsFieldID = 'plantilla_cuentat_gasto_id'; $xtraWhere = " AND cuentat_gasto.activo='Si' ";
711            $sql = "SELECT /*$sqlComment*/  $fieldName$fieldDesc$fieldName as real_data, $fieldDesc as label, $fieldName as value, bkgcolor, color, orden FROM $nombre WHERE EXISTS (SELECT 1 FROM $vsTable WHERE $nombre.$fieldName=$vsTable.$vsFieldID $xtraWhere) ORDER BY orden";
712
713            $array = ia_sqlArrayIndx($sql);
714            jsonFile($fileName, $array);
715            $jsonData = json_encode($array);
716        }
717        break;
718
719        case 'cuentat_gasto_alta_por':
720            if(!$genera && file_exists($fileName))
721                $jsonData = file_get_contents($fileName);
722            if(strlen($jsonData) === 0)
723            {
724                $nombre = 'cuentat_gasto'; $fieldName = 'alta_por'; $fieldDesc = 'alta_por';
725                $sql = "SELECT /*$sqlComment*/  $fieldName$fieldDesc$fieldName as real_data, $fieldDesc as label, $fieldName as value FROM $nombre ORDER BY 2";
726                $array = ia_sqlArray($sql,'alta_por');
727                //$array = ia_sqlArrayIndx($sql);
728                jsonFile($fileName, $array);
729                $jsonData = json_encode($array);
730            }
731            break;
732
733        //Fiduciario
734        case 'fiduciario_reembolso_alta_por':
735            if(!$genera && file_exists($fileName))
736                $jsonData = file_get_contents($fileName);
737            if(strlen($jsonData) === 0)
738            {
739                $nombre = 'fiduciario_reembolso'; $fieldName = 'alta_por'; $fieldDesc = 'alta_por';
740                $sql = "SELECT /*$sqlComment*/  $fieldName$fieldDesc$fieldName as real_data, $fieldDesc as label, $fieldName as value FROM $nombre ORDER BY 2";
741                $array = ia_sqlArray($sql,'alta_por');
742                //$array = ia_sqlArrayIndx($sql);
743                jsonFile($fileName, $array);
744                $jsonData = json_encode($array);
745            }
746            break;
747
748        case 'fiduciario_reembolso_banco_cuenta_id_activo':
749            if(!$genera && file_exists($fileName))
750                $jsonData = file_get_contents($fileName);
751            if(strlen($jsonData) === 0)
752            {
753                $nombre = 'banco_cuenta'; $fieldName = 'banco_cuenta_id'; $fieldDesc = 'nombre'; $vsTable = 'fiduciario_reembolso'; $vsFieldID = 'banco_cuenta_id'; $xtraWhere = " AND fiduciario_reembolso.activo='Si' ";
754                $sql = "SELECT /*$sqlComment*/  $fieldName$fieldDesc$fieldName as real_data, $fieldDesc as label, $fieldName as value FROM $nombre WHERE EXISTS (SELECT 1 FROM $vsTable WHERE $nombre.$fieldName=$vsTable.$vsFieldID $xtraWhere) AND $nombre.vale='Active' ORDER BY 2";
755
756                $array = ia_sqlArrayIndx($sql);
757                jsonFile($fileName, $array);
758                $jsonData = json_encode($array);
759            }
760            break;
761
762        case 'fiduciario_banco_cuenta_id_activo':
763            if(!$genera && file_exists($fileName))
764                $jsonData = file_get_contents($fileName);
765            if(strlen($jsonData) === 0)
766            {
767                $nombre = 'banco_cuenta'; $fieldName = 'banco_cuenta_id'; $fieldDesc = 'nombre'; $vsTable = 'fiduciario'; $vsFieldID = 'banco_cuenta_id'; $xtraWhere = "";
768                $sql = "SELECT /*$sqlComment*/  $fieldName$fieldDesc$fieldName as real_data, $fieldDesc as label, $fieldName as value FROM $nombre WHERE EXISTS (SELECT 1 FROM $vsTable WHERE $nombre.$fieldName=$vsTable.$vsFieldID $xtraWhere) AND $nombre.vale='Active' ORDER BY 2";
769
770                $array = ia_sqlArrayIndx($sql);
771                jsonFile($fileName, $array);
772                $jsonData = json_encode($array);
773            }
774            break;
775
776        case 'fiduciario_cliente_id':
777            $nombre = 'cliente'; $fieldName = 'cliente_id'; $fieldDesc = 'nombre';
778            $vsTable = 'fiduciario_contenedor'; $vsFieldID = 'cliente_id';
779            $jsonData = obtenClientesConPermiso(
780                $fileName, $genera=true,$nombre, $fieldName, $fieldDesc,
781                $vsTable, $vsFieldID, '', 'docto', '');
782            break;
783
784            if(!$genera && file_exists($fileName))
785                $jsonData = file_get_contents($fileName);
786            if(strlen($jsonData) === 0)
787            {
788                $nombre = 'cliente'; $fieldName = 'cliente_id'; $fieldDesc = 'nombre'; $vsTable = 'fiduciario_contenedor'; $vsFieldID = 'cliente_id';
789                $sql = "SELECT /*$sqlComment*/  $fieldName$fieldDesc$fieldName as real_data, $fieldDesc as label, $fieldName as value FROM $nombre WHERE EXISTS (SELECT 1 FROM $vsTable WHERE $nombre.$fieldName=$vsTable.$vsFieldID) ORDER BY 2";
790                
791                $array = ia_sqlArrayIndx($sql);
792                jsonFile($fileName, $array);
793                $jsonData = json_encode($array);
794            }
795            break;
796
797        //Cheques
798
799        case 'cheque_cliente_id':
800            $nombre = 'cliente'; $fieldName = 'cliente_id'; $fieldDesc = 'nombre';
801            $vsTable = 'cheque'; $vsFieldID = 'cliente_id'; $vsAnd = " "; $vsPaid = " AND $vsTable.paid='0'";
802            $vsAnd .= $categoria_id > 1 ? " AND $vsTable.categoria_id=".strit($categoria_id) : " ";
803            $jsonData = obtenClientesConPermiso(
804                $fileName, $genera=true,$nombre, $fieldName, $fieldDesc,
805                $vsTable, $vsFieldID, $vsAnd, 'cheque', $vsPaid);
806            break;
807
808            if(!$genera && file_exists($fileName))
809                $jsonData = file_get_contents($fileName);
810            if(strlen($jsonData) === 0)
811            {
812                $nombre = 'cliente'; $fieldName = 'cliente_id'; $fieldDesc = 'nombre'; $vsTable = 'cheque'; $vsFieldID = 'cliente_id';
813                $sql = "SELECT /*$sqlComment*/  $fieldName$fieldDesc$fieldName as real_data, $fieldDesc as label, $fieldName as value 
814                        FROM $nombre WHERE EXISTS (SELECT 1 FROM $vsTable WHERE $nombre.$fieldName=$vsTable.$vsFieldID AND $vsTable.paid='0') ORDER BY 2";
815                
816                $array = ia_sqlArrayIndx($sql);
817                jsonFile($fileName, $array);
818                $jsonData = json_encode($array);
819            }
820            break;
821
822        case 'cheque_dd_cliente_id':
823            $nombre = 'cliente'; $fieldName = 'cliente_id'; $fieldDesc = 'nombre';
824            $vsTable = 'cheque'; $vsFieldID = 'cliente_id'; $vsAnd = " AND $vsTable.tipo IN ('NOTA', 'GASTO') "; $vsPaid = " AND $vsTable.paid='0'";
825            $vsAnd .= $categoria_id > 1 ? " AND $vsTable.categoria_id=".strit($categoria_id) : " ";
826            $jsonData = obtenClientesConPermiso(
827                $fileName, $genera=true,$nombre, $fieldName, $fieldDesc,
828                $vsTable, $vsFieldID, $vsAnd, 'cheque', $vsPaid);
829            break;
830
831            if(!$genera && file_exists($fileName))
832                $jsonData = file_get_contents($fileName);
833            if(strlen($jsonData) === 0)
834            {
835                $nombre = 'cliente'; $fieldName = 'cliente_id'; $fieldDesc = 'nombre'; $vsTable = 'cheque'; $vsFieldID = 'cliente_id';
836                $sql = "SELECT /*$sqlComment*/  $fieldName$fieldDesc$fieldName as real_data, $fieldDesc as label, $fieldName as value FROM $nombre WHERE EXISTS (SELECT 1 FROM $vsTable WHERE $nombre.$fieldName=$vsTable.$vsFieldID AND $vsTable.tipo IN ('NOTA', 'GASTO') AND $vsTable.paid='0') ORDER BY 2";
837
838                $array = ia_sqlArrayIndx($sql);
839                jsonFile($fileName, $array);
840                $jsonData = json_encode($array);
841            }
842            break;
843
844        case 'cheque_tienda':
845            //@TODO permiso por usuario?
846            if(!$genera && file_exists($fileName))
847                $jsonData = file_get_contents($fileName);
848            if(strlen($jsonData) === 0)
849            {
850                $nombre = 'tienda'; $fieldName = 'tienda_id'; $fieldDesc = 'clave'; $vsTable = 'cheque'; $vsFieldID = 'tienda_id';
851                $sql = "SELECT /*$sqlComment*/  $fieldName$fieldDesc$fieldName as real_data, $fieldDesc as label, $fieldName as value 
852                FROM $nombre WHERE EXISTS (SELECT 1 FROM $vsTable WHERE $nombre.$fieldName=$vsTable.$vsFieldID) AND $nombre.vale='Active' ORDER BY 2";
853                
854                $array = ia_sqlArrayIndx($sql);
855                jsonFile($fileName, $array);
856                $jsonData = json_encode($array);
857            }
858            break;
859
860        case 'cheque_cuentat_deliveredto_id':
861
862            if(!$genera && file_exists($fileName))
863                $jsonData = file_get_contents($fileName);
864            if(strlen($jsonData) === 0)
865            {
866                $nombre = 'cuentat'; $fieldName = 'cuentaT_id'; $fieldDesc = 'usuario'; $vsTable = 'cheque'; $vsFieldID = 'cuentaT_deliveredto_id';
867                $sql = "SELECT /*$sqlComment*/  $fieldName$fieldDesc$fieldName as real_data, $fieldDesc as label, $fieldName as value FROM $nombre WHERE EXISTS (SELECT 1 FROM $vsTable WHERE $nombre.$fieldName=$vsTable.$vsFieldID) AND $nombre.vale='Active' ORDER BY 2";
868                
869                $array = ia_sqlArrayIndx($sql);
870                jsonFile($fileName, $array);
871                $jsonData = json_encode($array);
872            }
873            break;
874
875
876        case 'cheque_origen_cuentat_id':
877            if(!$genera && file_exists($fileName))
878                $jsonData = file_get_contents($fileName);
879            if(strlen($jsonData) === 0)
880            {
881                $nombre = 'cuentat'; $fieldName = 'cuentaT_id'; $fieldDesc = 'usuario'; $vsTable = 'cheque'; $vsFieldID = 'origen_cuentat_id';
882                $sql = "SELECT /*$sqlComment*/  $fieldName$fieldDesc$fieldName as real_data, $fieldDesc as label, $fieldName as value FROM $nombre WHERE EXISTS (SELECT 1 FROM $vsTable WHERE $nombre.$fieldName=$vsTable.$vsFieldID) AND $nombre.vale='Active' ORDER BY 2";
883                
884                $array = ia_sqlArrayIndx($sql);
885                jsonFile($fileName, $array);
886                $jsonData = json_encode($array);
887            }
888            break;
889
890        case 'cheque_alta_por':
891            if(!$genera && file_exists($fileName))
892                $jsonData = file_get_contents($fileName);
893            if(strlen($jsonData) === 0)
894            {
895                $sql = "SELECT /*$sqlComment*/  alta_por, alta_por as real_data, alta_por as label, alta_por as value FROM cheque GROUP BY alta_por ORDER BY alta_por";
896                $array = ia_sqlArray($sql,'alta_por');
897                //$array = ia_sqlArrayIndx($sql);
898                jsonFile($fileName, $array);
899                $jsonData = json_encode($array);
900            }
901            break;
902
903        case 'cheque_dd_tipo':
904            if(!$genera && file_exists($fileName))
905                $jsonData = file_get_contents($fileName);
906            if(strlen($jsonData) === 0)
907            {
908                $array = array(
909                    array('label'=>'SIN TIPO', 'value'=> '', 'real_data'=> ''),
910                    array('label'=>'NOTA', 'value'=> 'NOTA', 'real_data'=> 'NOTA', ),
911                    array('label'=>'GASTO', 'value'=> 'GASTO', 'real_data'=> 'GASTO', ),
912                );
913                jsonFile($fileName, $array);
914                $jsonData = json_encode($array);
915            }
916            break;
917
918        case 'doctos_cheque_dd_tipo':
919            if(!$genera && file_exists($fileName))
920                $jsonData = file_get_contents($fileName);
921            if(strlen($jsonData) === 0)
922            {
923                $array = array(
924                    array('label'=>'SIN TIPO', 'value'=> '', 'real_data'=> ''),
925                    array('label'=>'NOTA', 'value'=> 'NOTA', 'real_data'=> 'NOTA', ),
926                    array('label'=>'GASTO', 'value'=> 'GASTO', 'real_data'=> 'GASTO', ),
927                    array('label'=>'COMPRA', 'value'=> 'COMPRA', 'real_data'=> 'COMPRA', ),
928                );
929                jsonFile($fileName, $array);
930                $jsonData = json_encode($array);
931            }
932            break;
933
934        //compras
935
936        case 'compra_cliente_id':
937            $nombre = 'cliente'; $fieldName = 'cliente_id'; $fieldDesc = 'nombre';
938            $vsTable = 'compra'; $vsFieldID = 'cliente_id'; $vsAnd = " "; $vsPaid = " AND $vsTable.paid='0'";
939            $vsAnd .= $categoria_id > 1 ? " AND $vsTable.categoria_id=".strit($categoria_id) : " ";
940            $jsonData = obtenClientesConPermiso(
941                $fileName, $genera=true,$nombre, $fieldName, $fieldDesc,
942                $vsTable, $vsFieldID, $vsAnd, 'docto', $vsPaid);
943            break;
944
945            if(!$genera && file_exists($fileName))
946                $jsonData = file_get_contents($fileName);
947            if(strlen($jsonData) === 0)
948            {
949                $nombre = 'cliente'; $fieldName = 'cliente_id'; $fieldDesc = 'nombre'; $vsTable = 'compra'; $vsFieldID = 'cliente_id';
950                $sql = "SELECT /*$sqlComment*/  $fieldName$fieldDesc$fieldName as real_data, $fieldDesc as label, $fieldName as value FROM $nombre WHERE EXISTS (SELECT 1 FROM $vsTable WHERE $nombre.$fieldName=$vsTable.$vsFieldID AND $vsTable.paid='0') ORDER BY 2";
951                
952                $array = ia_sqlArrayIndx($sql);
953                jsonFile($fileName, $array);
954                $jsonData = json_encode($array);
955            }
956            break;
957
958        case 'compra_tienda':
959
960            if(!$genera && file_exists($fileName))
961                $jsonData = file_get_contents($fileName);
962            if(strlen($jsonData) === 0)
963            {
964                $nombre = 'tienda'; $fieldName = 'tienda_id'; $fieldDesc = 'clave'; $vsTable = 'compra'; $vsFieldID = 'tienda_id';
965                $sql = "SELECT /*$sqlComment*/  $fieldName$fieldDesc$fieldName as real_data, $fieldDesc as label, $fieldName as value FROM $nombre WHERE EXISTS (SELECT 1 FROM $vsTable WHERE $nombre.$fieldName=$vsTable.$vsFieldID) AND $nombre.vale='Active' ORDER BY 2";
966                
967                $array = ia_sqlArrayIndx($sql);
968                jsonFile($fileName, $array);
969                $jsonData = json_encode($array);
970            }
971            break;
972
973        case 'compra_cuentat_deliveredto_id':
974
975            if(!$genera && file_exists($fileName))
976                $jsonData = file_get_contents($fileName);
977            if(strlen($jsonData) === 0)
978            {
979                $nombre = 'cuentat'; $fieldName = 'cuentaT_id'; $fieldDesc = 'usuario'; $vsTable = 'compra'; $vsFieldID = 'cuentaT_deliveredto_id';
980                $sql = "SELECT /*$sqlComment*/  $fieldName$fieldDesc$fieldName as real_data, $fieldDesc as label, $fieldName as value FROM $nombre WHERE EXISTS (SELECT 1 FROM $vsTable WHERE $nombre.$fieldName=$vsTable.$vsFieldID) AND $nombre.vale='Active' ORDER BY 2";
981                
982                $array = ia_sqlArrayIndx($sql);
983                jsonFile($fileName, $array);
984                $jsonData = json_encode($array);
985            }
986            break;
987
988
989        case 'compra_origen_cuentat_id':
990            if(!$genera && file_exists($fileName))
991                $jsonData = file_get_contents($fileName);
992            if(strlen($jsonData) === 0)
993            {
994                $nombre = 'cuentat'; $fieldName = 'cuentaT_id'; $fieldDesc = 'usuario'; $vsTable = 'compra'; $vsFieldID = 'origen_cuentat_id';
995                $sql = "SELECT /*$sqlComment*/  $fieldName$fieldDesc$fieldName as real_data, $fieldDesc as label, $fieldName as value FROM $nombre WHERE EXISTS (SELECT 1 FROM $vsTable WHERE $nombre.$fieldName=$vsTable.$vsFieldID) AND $nombre.vale='Active' ORDER BY 2";
996                
997                $array = ia_sqlArrayIndx($sql);
998                jsonFile($fileName, $array);
999                $jsonData = json_encode($array);
1000            }
1001            break;
1002
1003        case 'compra_alta_por':
1004            if(!$genera && file_exists($fileName))
1005                $jsonData = file_get_contents($fileName);
1006            if(strlen($jsonData) === 0)
1007            {
1008                $sql = "SELECT /*$sqlComment*/  alta_por, alta_por as real_data, alta_por as label, alta_por as value FROM compra GROUP BY alta_por ORDER BY alta_por";
1009                $array = ia_sqlArray($sql,'alta_por');
1010                //$array = ia_sqlArrayIndx($sql);
1011                jsonFile($fileName, $array);
1012                $jsonData = json_encode($array);
1013            }
1014            break;
1015
1016        case 'compra_dd_tipo':
1017            if(!$genera && file_exists($fileName))
1018                $jsonData = file_get_contents($fileName);
1019            if(strlen($jsonData) === 0)
1020            {
1021                $array = array(
1022                    array('label'=>'SIN TIPO', 'value'=> '', 'real_data'=> ''),
1023                    array('label'=>'GASTO', 'value'=> 'GASTO', 'real_data'=> 'GASTO', ),
1024                    array('label'=>'COMPRA', 'value'=> 'COMPRA', 'real_data'=> 'COMPRA', ),
1025                );
1026                jsonFile($fileName, $array);
1027                $jsonData = json_encode($array);
1028            }
1029            break;
1030
1031        //Pagares
1032
1033        case 'pagare_cliente_id':
1034            $nombre = 'cliente'; $fieldName = 'cliente_id'; $fieldDesc = 'nombre';
1035            $vsTable = 'pagare'; $vsFieldID = 'cliente_id'; $vsAnd = " "; $vsPaid = " AND $vsTable.paid='0'";
1036            $vsAnd .= $categoria_id > 1 ? " AND $vsTable.categoria_id=".strit($categoria_id) : " ";
1037            $jsonData = obtenClientesConPermiso(
1038                $fileName, $genera=true,$nombre, $fieldName, $fieldDesc,
1039                $vsTable, $vsFieldID, $vsAnd, 'pagare', $vsPaid);
1040            break;
1041
1042            if(!$genera && file_exists($fileName))
1043                $jsonData = file_get_contents($fileName);
1044            if(strlen($jsonData) === 0)
1045            {
1046                $nombre = 'cliente'; $fieldName = 'cliente_id'; $fieldDesc = 'nombre'; $vsTable = 'pagare'; $vsFieldID = 'cliente_id';
1047                $sql = "SELECT /*$sqlComment*/  $fieldName$fieldDesc$fieldName as real_data, $fieldDesc as label, $fieldName as value FROM $nombre WHERE EXISTS (SELECT 1 FROM $vsTable WHERE $nombre.$fieldName=$vsTable.$vsFieldID AND $vsTable.paid='0') ORDER BY 2";
1048                
1049                $array = ia_sqlArrayIndx($sql);
1050                jsonFile($fileName, $array);
1051                $jsonData = json_encode($array);
1052            }
1053            break;
1054
1055        case 'pagare_tienda':
1056
1057            if(!$genera && file_exists($fileName))
1058                $jsonData = file_get_contents($fileName);
1059            if(strlen($jsonData) === 0)
1060            {
1061                $nombre = 'tienda'; $fieldName = 'tienda_id'; $fieldDesc = 'clave'; $vsTable = 'pagare'; $vsFieldID = 'tienda_id';
1062                $sql = "SELECT /*$sqlComment*/  $fieldName$fieldDesc$fieldName as real_data, $fieldDesc as label, $fieldName as value FROM $nombre WHERE EXISTS (SELECT 1 FROM $vsTable WHERE $nombre.$fieldName=$vsTable.$vsFieldID) AND $nombre.vale='Active' ORDER BY 2";
1063                
1064                $array = ia_sqlArrayIndx($sql);
1065                jsonFile($fileName, $array);
1066                $jsonData = json_encode($array);
1067            }
1068            break;
1069
1070        case 'pagare_cuentat_deliveredto_id':
1071
1072            if(!$genera && file_exists($fileName))
1073                $jsonData = file_get_contents($fileName);
1074            if(strlen($jsonData) === 0)
1075            {
1076                $nombre = 'cuentat'; $fieldName = 'cuentaT_id'; $fieldDesc = 'usuario'; $vsTable = 'pagare'; $vsFieldID = 'cuentaT_deliveredto_id';
1077                $sql = "SELECT /*$sqlComment*/  $fieldName$fieldDesc$fieldName as real_data, $fieldDesc as label, $fieldName as value FROM $nombre WHERE EXISTS (SELECT 1 FROM $vsTable WHERE $nombre.$fieldName=$vsTable.$vsFieldID) AND $nombre.vale='Active' ORDER BY 2";
1078                
1079                $array = ia_sqlArrayIndx($sql);
1080                jsonFile($fileName, $array);
1081                $jsonData = json_encode($array);
1082            }
1083            break;
1084
1085
1086        case 'pagare_origen_cuentat_id':
1087            if(!$genera && file_exists($fileName))
1088                $jsonData = file_get_contents($fileName);
1089            if(strlen($jsonData) === 0)
1090            {
1091                $nombre = 'cuentat'; $fieldName = 'cuentaT_id'; $fieldDesc = 'usuario'; $vsTable = 'pagare'; $vsFieldID = 'origen_cuentat_id';
1092                $sql = "SELECT /*$sqlComment*/  $fieldName$fieldDesc$fieldName as real_data, $fieldDesc as label, $fieldName as value FROM $nombre WHERE EXISTS (SELECT 1 FROM $vsTable WHERE $nombre.$fieldName=$vsTable.$vsFieldID) AND $nombre.vale='Active' ORDER BY 2";
1093                
1094                $array = ia_sqlArrayIndx($sql);
1095                jsonFile($fileName, $array);
1096                $jsonData = json_encode($array);
1097            }
1098            break;
1099
1100        case 'pagare_alta_por':
1101            if(!$genera && file_exists($fileName))
1102                $jsonData = file_get_contents($fileName);
1103            if(strlen($jsonData) === 0)
1104            {
1105                $sql = "SELECT /*$sqlComment*/  alta_por, alta_por as real_data, alta_por as label, alta_por as value FROM pagare GROUP BY alta_por ORDER BY alta_por";
1106                $array = ia_sqlArray($sql,'alta_por');
1107                //$array = ia_sqlArrayIndx($sql);
1108                jsonFile($fileName, $array);
1109                $jsonData = json_encode($array);
1110            }
1111            break;
1112
1113        //Vales
1114        case 'vale_cliente_activo_toolbar':
1115
1116            if(!$genera && file_exists($fileName))
1117                $jsonData = file_get_contents($fileName);
1118            if(strlen($jsonData) === 0)
1119            {
1120                $sql = "SELECT /*$sqlComment*/ 
1121IF(doc.cliente_id IS NULL, doc.cliente, IF(cli.nombre IS NULL,'CLIENTE NO EXISTE', cli.nombre)) AS cliente,
1122IF(doc.cliente_id IS NULL, doc.cliente, IF(cli.nombre IS NULL,'CLIENTE NO EXISTE', cli.nombre)) AS real_data,
1123IF(doc.cliente_id IS NULL, doc.cliente, IF(cli.nombre IS NULL,'CLIENTE NO EXISTE', cli.nombre)) AS label,
1124IF(doc.cliente_id IS NULL, doc.cliente, IF(cli.nombre IS NULL,'CLIENTE NO EXISTE', cli.nombre)) AS value
1125FROM vale AS doc
1126LEFT JOIN cliente cli ON doc.cliente_id=cli.cliente_id
1127WHERE doc.aplicado = 0
1128GROUP BY cliente
1129ORDER BY cliente";
1130                
1131                $array = ia_sqlArrayIndx($sql);
1132                jsonFile($fileName, $array);
1133                $jsonData = json_encode($array);
1134            }
1135            break;
1136
1137            case 'vale_cliente_activo':
1138
1139            if(!$genera && file_exists($fileName))
1140                $jsonData = file_get_contents($fileName);
1141            if(strlen($jsonData) === 0)
1142            {
1143                $sql = "SELECT /*$sqlComment*/ 
1144IF(doc.cliente_id IS NULL, doc.cliente, IF(cli.nombre IS NULL,'CLIENTE NO EXISTE', cli.nombre)) AS cliente,
1145IF(doc.cliente_id IS NULL, doc.cliente, IF(cli.nombre IS NULL,'CLIENTE NO EXISTE', doc.cliente_id)) AS real_data,
1146IF(doc.cliente_id IS NULL, doc.cliente, IF(cli.nombre IS NULL,'CLIENTE NO EXISTE', cli.nombre)) AS label,
1147IF(doc.cliente_id IS NULL, doc.cliente, IF(cli.nombre IS NULL,'CLIENTE NO EXISTE', doc.cliente_id)) AS value
1148FROM vale AS doc
1149LEFT JOIN cliente cli ON doc.cliente_id=cli.cliente_id
1150WHERE doc.aplicado = 0
1151GROUP BY cliente
1152ORDER BY cliente";
1153                
1154                $array = ia_sqlArrayIndx($sql);
1155                jsonFile($fileName, $array);
1156                $jsonData = json_encode($array);
1157            }
1158            break;
1159
1160        case 'vale_cliente':
1161            if(!$genera && file_exists($fileName))
1162                $jsonData = file_get_contents($fileName);
1163            if(strlen($jsonData) === 0)
1164            {
1165                $sql = "SELECT /*$sqlComment*/ 
1166IF(doc.cliente_id IS NULL, doc.cliente, IF(cli.nombre IS NULL,'CLIENTE NO EXISTE', cli.nombre)) AS cliente,
1167IF(doc.cliente_id IS NULL, doc.cliente, IF(cli.nombre IS NULL,'CLIENTE NO EXISTE', doc.cliente_id)) AS real_data,
1168IF(doc.cliente_id IS NULL, doc.cliente, IF(cli.nombre IS NULL,'CLIENTE NO EXISTE', cli.nombre)) AS label,
1169IF(doc.cliente_id IS NULL, doc.cliente, IF(cli.nombre IS NULL,'CLIENTE NO EXISTE', doc.cliente_id)) AS value
1170FROM vale AS doc
1171LEFT JOIN cliente cli ON doc.cliente_id=cli.cliente_id
1172GROUP BY cliente
1173ORDER BY cliente";
1174
1175                $array = ia_sqlArray($sql,'cliente');
1176                //$array = ia_sqlArrayIndx($sql);
1177                jsonFile($fileName, $array);
1178                $jsonData = json_encode($array);
1179            }
1180            break;
1181
1182        case 'vale_alta_por':
1183            if(!$genera && file_exists($fileName))
1184                $jsonData = file_get_contents($fileName);
1185            if(strlen($jsonData) === 0)
1186            {
1187                $sql = "SELECT /*$sqlComment*/  alta_por, alta_por as real_data, alta_por as label, alta_por as value FROM vale GROUP BY alta_por ORDER BY alta_por";
1188                $array = ia_sqlArray($sql,'alta_por');
1189                //$array = ia_sqlArrayIndx($sql);
1190                jsonFile($fileName, $array);
1191                $jsonData = json_encode($array);
1192            }
1193            break;
1194
1195        case 'vale_dinero_en_cuentaT_id':
1196
1197            if(!$genera && file_exists($fileName))
1198                $jsonData = file_get_contents($fileName);
1199            if(strlen($jsonData) === 0)
1200            {
1201                $nombre = 'cuentat'; $fieldName = 'cuentaT_id'; $fieldDesc = 'usuario'; $vsTable = 'vale'; $vsFieldID = 'dinero_en_cuentaT_id';
1202                $sql = "SELECT /*$sqlComment*/  $fieldName$fieldDesc$fieldName as real_data, $fieldDesc as label, $fieldName as value FROM $nombre WHERE EXISTS (SELECT 1 FROM $vsTable WHERE $nombre.$fieldName=$vsTable.$vsFieldID) AND $nombre.vale='Active' ORDER BY 2";
1203                
1204                $array = ia_sqlArrayIndx($sql);
1205                jsonFile($fileName, $array);
1206                $jsonData = json_encode($array);
1207            }
1208            break;
1209
1210        case 'vale_cuentaT_id':
1211
1212            if(!$genera && file_exists($fileName))
1213                $jsonData = file_get_contents($fileName);
1214            if(strlen($jsonData) === 0)
1215            {
1216                $nombre = 'cuentat'; $fieldName = 'cuentaT_id'; $fieldDesc = 'usuario'; $vsTable = 'vale'; $vsFieldID = 'cuentaT_id';
1217                $sql = "SELECT /*$sqlComment*/  $fieldName$fieldDesc$fieldName as real_data, $fieldDesc as label, $fieldName as value FROM $nombre WHERE EXISTS (SELECT 1 FROM $vsTable WHERE $nombre.$fieldName=$vsTable.$vsFieldID) AND $nombre.vale='Active' ORDER BY 2";
1218                
1219                $array = ia_sqlArrayIndx($sql);
1220                jsonFile($fileName, $array);
1221                $jsonData = json_encode($array);
1222            }
1223            break;
1224
1225        //cuentat_mov
1226        case 'cuentat_mov_alta_por':
1227            if(!$genera && file_exists($fileName))
1228                $jsonData = file_get_contents($fileName);
1229            if(strlen($jsonData) === 0)
1230            {
1231                $sql = "SELECT /*$sqlComment*/  alta_por, alta_por as real_data, alta_por as label, alta_por as value FROM cuentat_mov GROUP BY alta_por ORDER BY alta_por";
1232                $array = ia_sqlArray($sql,'alta_por');
1233                //$array = ia_sqlArrayIndx($sql);
1234                jsonFile($fileName, $array);
1235                $jsonData = json_encode($array);
1236            }
1237            break;
1238
1239        case 'cuentat_mov_cuentaT_id':
1240
1241            if(!$genera && file_exists($fileName))
1242                $jsonData = file_get_contents($fileName);
1243            if(strlen($jsonData) === 0)
1244            {
1245                $nombre = 'cuentat'; $fieldName = 'cuentaT_id'; $fieldDesc = 'usuario'; $vsTable = 'cuentat_mov'; $vsFieldID = 'cuentaT_id';
1246                $sql = "SELECT /*$sqlComment*/  $fieldName$fieldDesc$fieldName as real_data, $fieldDesc as label, $fieldName as value FROM $nombre WHERE EXISTS (SELECT 1 FROM $vsTable WHERE $nombre.$fieldName=$vsTable.$vsFieldID) AND $nombre.vale='Active' ORDER BY 2";
1247                
1248                $array = ia_sqlArrayIndx($sql);
1249                jsonFile($fileName, $array);
1250                $jsonData = json_encode($array);
1251            }
1252            break;
1253
1254
1255        case 'cuentat_mov_tienda_id':
1256
1257            if(!$genera && file_exists($fileName))
1258                $jsonData = file_get_contents($fileName);
1259            if(strlen($jsonData) === 0)
1260            {
1261                $nombre = 'tienda'; $fieldName = 'tienda_id'; $fieldDesc = 'clave'; $vsTable = 'cuentat_mov'; $vsFieldID = 'tienda_id';
1262                $sql = "SELECT /*$sqlComment*/  $fieldName$fieldDesc$fieldName as real_data, $fieldDesc as label, $fieldName as value FROM $nombre WHERE EXISTS (SELECT 1 FROM $vsTable WHERE $nombre.$fieldName=$vsTable.$vsFieldID) AND $nombre.vale='Active' ORDER BY 2";
1263                
1264                $array = ia_sqlArrayIndx($sql);
1265                jsonFile($fileName, $array);
1266                $jsonData = json_encode($array);
1267            }
1268            break;
1269
1270        //banco_a_banco
1271        case 'banco_a_banco_alta_por':
1272            if(!$genera && file_exists($fileName))
1273                $jsonData = file_get_contents($fileName);
1274            if(strlen($jsonData) === 0)
1275            {
1276                $sql = "SELECT /*$sqlComment*/  alta_por, alta_por as real_data, alta_por as label, alta_por as value FROM banco_cuenta_trans GROUP BY alta_por ORDER BY alta_por";
1277                $array = ia_sqlArray($sql,'alta_por');
1278                //$array = ia_sqlArrayIndx($sql);
1279                jsonFile($fileName, $array);
1280                $jsonData = json_encode($array);
1281            }
1282            break;
1283        //banco_a_banco_banco_cuenta_id_origen
1284        case 'banco_a_banco_bid_origen':
1285            if(!$genera && file_exists($fileName))
1286                $jsonData = file_get_contents($fileName);
1287            if(strlen($jsonData) === 0)
1288            {
1289                $nombre = 'banco_cuenta'; $fieldName = 'banco_cuenta_id'; $fieldDesc = 'nombre'; $vsTable = 'banco_cuenta_trans'; $vsFieldID = 'origen_banco_cuenta_id'; $xtraWhere = " AND banco_cuenta_trans.activo='Si' ";
1290                $sql = "SELECT /*$sqlComment*/  $fieldName$fieldDesc$fieldName as real_data, $fieldDesc as label, $fieldName as value FROM $nombre WHERE EXISTS (SELECT 1 FROM $vsTable WHERE $nombre.$fieldName=$vsTable.$vsFieldID $xtraWhere) AND $nombre.vale='Active' ORDER BY 2";
1291
1292                $array = ia_sqlArrayIndx($sql);
1293                jsonFile($fileName, $array);
1294                $jsonData = json_encode($array);
1295            }
1296            break;
1297        //banco_a_banco_banco_cuenta_id_destino
1298        case 'banco_a_banco_bid_destino':
1299            if(!$genera && file_exists($fileName))
1300                $jsonData = file_get_contents($fileName);
1301            if(strlen($jsonData) === 0)
1302            {
1303                $nombre = 'banco_cuenta'; $fieldName = 'banco_cuenta_id'; $fieldDesc = 'nombre'; $vsTable = 'banco_cuenta_trans'; $vsFieldID = 'destino_banco_cuenta_id'; $xtraWhere = " AND banco_cuenta_trans.activo='Si' ";
1304                $sql = "SELECT /*$sqlComment*/  $fieldName$fieldDesc$fieldName as real_data, $fieldDesc as label, $fieldName as value FROM $nombre WHERE EXISTS (SELECT 1 FROM $vsTable WHERE $nombre.$fieldName=$vsTable.$vsFieldID $xtraWhere) AND $nombre.vale='Active' ORDER BY 2";
1305
1306                $array = ia_sqlArrayIndx($sql);
1307                jsonFile($fileName, $array);
1308                $jsonData = json_encode($array);
1309            }
1310            break;
1311
1312        //cuentat_transfer
1313        case 'cuentat_transfer_envia_cuentaT_id':
1314            if(!$genera && file_exists($fileName))
1315                $jsonData = file_get_contents($fileName);
1316            if(strlen($jsonData) === 0)
1317            {
1318                $nombre = 'cuentat'; $fieldName = 'cuentaT_id'; $fieldDesc = 'usuario'; $vsTable = 'cuentat_transfer'; $vsFieldID = 'cuentaT_de_id';
1319                $sql = "SELECT /*$sqlComment*/  $fieldName$fieldDesc$fieldName as real_data, $fieldDesc as label, $fieldName as value FROM $nombre WHERE EXISTS (SELECT 1 FROM $vsTable WHERE $nombre.$fieldName=$vsTable.$vsFieldID) AND $nombre.vale='Active' ORDER BY 2";
1320                
1321                $array = ia_sqlArrayIndx($sql);
1322                jsonFile($fileName, $array);
1323                $jsonData = json_encode($array);
1324            }
1325            break;
1326
1327        case 'cuentat_transfer_envia_usuario_id':
1328            if(!$genera && file_exists($fileName))
1329                $jsonData = file_get_contents($fileName);
1330            if(strlen($jsonData) === 0)
1331            {
1332                $nombre = 'iac_usr'; $fieldName = 'iac_usr_id'; $fieldDesc = 'nick'; $vsTable = 'cuentat_transfer'; $vsFieldID = 'usuario_envia';
1333                $sql = "SELECT /*$sqlComment*/  $fieldName$fieldDesc$fieldName as real_data, $fieldDesc as label, $fieldName as value FROM $nombre WHERE EXISTS (SELECT 1 FROM $vsTable WHERE $nombre.$fieldName=$vsTable.$vsFieldID) AND $nombre.vale='Active' ORDER BY 2";
1334                
1335                $array = ia_sqlArrayIndx($sql);
1336                jsonFile($fileName, $array);
1337                $jsonData = json_encode($array);
1338            }
1339            break;
1340
1341        case 'cuentat_transfer_recibe_cuentaT_id':
1342            if(!$genera && file_exists($fileName))
1343                $jsonData = file_get_contents($fileName);
1344            if(strlen($jsonData) === 0)
1345            {
1346                $nombre = 'cuentat'; $fieldName = 'cuentaT_id'; $fieldDesc = 'usuario'; $vsTable = 'cuentat_transfer'; $vsFieldID = 'cuentaT_a_id';
1347                $sql = "SELECT /*$sqlComment*/  $fieldName$fieldDesc$fieldName as real_data, $fieldDesc as label, $fieldName as value FROM $nombre WHERE EXISTS (SELECT 1 FROM $vsTable WHERE $nombre.$fieldName=$vsTable.$vsFieldID) AND $nombre.vale='Active' ORDER BY 2";
1348                
1349                $array = ia_sqlArrayIndx($sql);
1350                jsonFile($fileName, $array);
1351                $jsonData = json_encode($array);
1352            }
1353            break;
1354
1355        case 'cuentat_transfer_recibe_usuario_id':
1356            if(!$genera && file_exists($fileName))
1357                $jsonData = file_get_contents($fileName);
1358            if(strlen($jsonData) === 0)
1359            {
1360                $nombre = 'iac_usr'; $fieldName = 'iac_usr_id'; $fieldDesc = 'nick'; $vsTable = 'cuentat_transfer'; $vsFieldID = 'usuario_recibe';
1361                $sql = "SELECT /*$sqlComment*/  $fieldName$fieldDesc$fieldName as real_data, $fieldDesc as label, $fieldName as value FROM $nombre WHERE EXISTS (SELECT 1 FROM $vsTable WHERE $nombre.$fieldName=$vsTable.$vsFieldID) AND $nombre.vale='Active' ORDER BY 2";
1362                
1363                $array = ia_sqlArrayIndx($sql);
1364                jsonFile($fileName, $array);
1365                $jsonData = json_encode($array);
1366            }
1367            break;
1368
1369        //cuentat_ingreso_xtienda
1370
1371        case 'cuentat_ingreso_cuentat_id_xtienda_activo':
1372            if(!$genera && file_exists($fileName))
1373                $jsonData = file_get_contents($fileName);
1374            if(strlen($jsonData) === 0)
1375            {
1376                $nombre = 'cuentat'; $fieldName = 'cuentaT_id'; $fieldDesc = 'usuario'; $vsTable = 'cuentat_ingreso'; $vsFieldID = 'cuentaT_id'; $xtraWhere = " AND cuentat_ingreso.activo='Si' AND cuentat_ingreso.tienda_id IS NOT NULL";
1377                $sql = "SELECT /*$sqlComment*/  /** $nombre **/ $fieldName$fieldDesc$fieldName as real_data, $fieldDesc as label, $fieldName as value FROM $nombre WHERE EXISTS (SELECT 1 FROM $vsTable WHERE $nombre.$fieldName=$vsTable.$vsFieldID $xtraWhere) AND $nombre.vale='Active' ORDER BY 2";
1378
1379                //echo "<li>".$sql;
1380
1381                $array = ia_sqlArrayIndx($sql);
1382                jsonFile($fileName, $array);
1383                $jsonData = json_encode($array);
1384            }
1385            break;
1386
1387        case 'cuentat_ingreso_alta_por_xtienda':
1388            if(!$genera && file_exists($fileName))
1389                $jsonData = file_get_contents($fileName);
1390            if(strlen($jsonData) === 0)
1391            {
1392                 $fieldName = 'alta_por'; $fieldDesc = 'alta_por';
1393                $sql = "SELECT /*$sqlComment*/  /** $fileName **/ $fieldName$fieldDesc$fieldName as real_data, $fieldDesc as label, $fieldName as value 
1394                        FROM cuentat_ingreso WHERE  tienda_id IS NOT NULL ORDER BY 2";
1395                $array = ia_sqlArray($sql,'alta_por');
1396                //$array = ia_sqlArrayIndx($sql);
1397
1398                //echo "<li>".$sql;
1399
1400                jsonFile($fileName, $array);
1401                $jsonData = json_encode($array);
1402            }
1403            break;
1404
1405        case 'cuentat_ingreso_tienda_id_xtienda_activo':
1406            if(!$genera && file_exists($fileName))
1407                $jsonData = file_get_contents($fileName);
1408            if(strlen($jsonData) === 0)
1409            {
1410                $nombre = 'tienda'; $fieldName = 'tienda_id'; $fieldDesc = 'clave'; $vsTable = 'cuentat_ingreso'; $vsFieldID = 'tienda_id'; $xtraWhere = " AND cuentat_ingreso.activo='Si' AND cuentat_ingreso.tienda_id IS NOT NULL";
1411                $sql = "SELECT /*$sqlComment*/  /** $fileName **/ $fieldName$fieldDesc$fieldName as real_data, $fieldDesc as label, $fieldName as value FROM $nombre WHERE EXISTS (SELECT 1 FROM $vsTable WHERE $nombre.$fieldName=$vsTable.$vsFieldID $xtraWhere) AND $nombre.vale='Active' ORDER BY 2";
1412
1413                //echo "<li>".$sql;
1414
1415                $array = ia_sqlArrayIndx($sql);
1416                jsonFile($fileName, $array);
1417                $jsonData = json_encode($array);
1418            }
1419            break;
1420
1421        //cuentat_ingreso_xtienda
1422
1423        case 'cuentat_ingreso_cuentat_id_activo':
1424            if(!$genera && file_exists($fileName))
1425                $jsonData = file_get_contents($fileName);
1426            if(strlen($jsonData) === 0)
1427            {
1428                $nombre = 'cuentat'; $fieldName = 'cuentaT_id'; $fieldDesc = 'usuario'; $vsTable = 'cuentat_ingreso'; $vsFieldID = 'cuentaT_id'; $xtraWhere = " AND cuentat_ingreso.activo='Si' AND (cuentat_ingreso.tienda_id IS NULL OR LENGTH(cuentat_ingreso.tienda_id) = 0)";
1429                $sql = "SELECT /*$sqlComment*/  /** $fileName **/ $fieldName$fieldDesc$fieldName as real_data, $fieldDesc as label, $fieldName as value FROM $nombre WHERE EXISTS (SELECT 1 FROM $vsTable WHERE $nombre.$fieldName=$vsTable.$vsFieldID $xtraWhere) AND $nombre.vale='Active' ORDER BY 2";
1430
1431                //echo "<li>".$sql;
1432
1433                $array = ia_sqlArrayIndx($sql);
1434                jsonFile($fileName, $array);
1435                $jsonData = json_encode($array);
1436            }
1437            break;
1438
1439        case 'cuentat_ingreso_alta_por':
1440            if(!$genera && file_exists($fileName))
1441                $jsonData = file_get_contents($fileName);
1442            if(strlen($jsonData) === 0)
1443            {
1444                $fieldName = 'alta_por'; $fieldDesc = 'alta_por';
1445                $sql = "SELECT /*$sqlComment*/  /** $fileName **/ $fieldName$fieldDesc$fieldName as real_data, $fieldDesc as label, $fieldName as value 
1446                    FROM cuentat_ingreso 
1447                    WHERE (tienda_id IS NULL OR LENGTH(tienda_id) = 0) ORDER BY 2";
1448                $array = ia_sqlArray($sql,'alta_por');
1449                //$array = ia_sqlArrayIndx($sql);
1450                //echo "<li>".$sql;
1451                jsonFile($fileName, $array);
1452                $jsonData = json_encode($array);
1453            }
1454            break;
1455
1456        case 'cuentat_ingreso_tienda_id_activo':
1457            if(!$genera && file_exists($fileName))
1458                $jsonData = file_get_contents($fileName);
1459            if(strlen($jsonData) === 0)
1460            {
1461                $nombre = 'tienda'; $fieldName = 'tienda_id'; $fieldDesc = 'clave'; $vsTable = 'cuentat_ingreso'; $vsFieldID = 'tienda_id'; $xtraWhere = " AND cuentat_ingreso.activo='Si' AND (cuentat_ingreso.tienda_id IS NULL OR LENGTH(cuentat_ingreso.tienda_id) = 0)";
1462                $sql = "SELECT /*$sqlComment*/  /** $fileName **/ $fieldName$fieldDesc$fieldName as real_data, $fieldDesc as label, $fieldName as value FROM $nombre WHERE EXISTS (SELECT 1 FROM $vsTable WHERE $nombre.$fieldName=$vsTable.$vsFieldID $xtraWhere) AND $nombre.vale='Active' ORDER BY 2";
1463
1464                //echo "<li>".$sql;
1465
1466                $array = ia_sqlArrayIndx($sql);
1467                jsonFile($fileName, $array);
1468                $jsonData = json_encode($array);
1469            }
1470            break;
1471
1472        //cuentat_a_banco_tc
1473        case 'cuentat_a_banco_tc_alta_por':
1474            if(!$genera && file_exists($fileName))
1475                $jsonData = file_get_contents($fileName);
1476            if(strlen($jsonData) === 0)
1477            {
1478                $sql = "SELECT /*$sqlComment*/  alta_por, alta_por as real_data, alta_por as label, alta_por as value FROM cuentat_a_banco_tc GROUP BY alta_por ORDER BY alta_por";
1479                $array = ia_sqlArray($sql,'alta_por');
1480                //$array = ia_sqlArrayIndx($sql);
1481                jsonFile($fileName, $array);
1482                $jsonData = json_encode($array);
1483            }
1484            break;
1485
1486        case 'cuentat_a_banco_tc_cuentaT_id_activo':
1487
1488            if(!$genera && file_exists($fileName))
1489                $jsonData = file_get_contents($fileName);
1490            if(strlen($jsonData) === 0)
1491            {
1492                $nombre = 'cuentat'; $fieldName = 'cuentaT_id'; $fieldDesc = 'usuario'; $vsTable = 'cuentat_a_banco_tc'; $vsFieldID = 'cuentaT_id';
1493                $sql = "SELECT /*$sqlComment*/  $fieldName$fieldDesc$fieldName as real_data, $fieldDesc as label, $fieldName as value FROM $nombre WHERE EXISTS (SELECT 1 FROM $vsTable WHERE $nombre.$fieldName=$vsTable.$vsFieldID) AND $nombre.vale='Active' ORDER BY 2";
1494                
1495                $array = ia_sqlArrayIndx($sql);
1496                jsonFile($fileName, $array);
1497                $jsonData = json_encode($array);
1498            }
1499            break;
1500
1501        case 'cuentat_a_banco_tc_banco_cuenta_id_activo':
1502
1503            if(!$genera && file_exists($fileName))
1504                $jsonData = file_get_contents($fileName);
1505            if(strlen($jsonData) === 0)
1506            {
1507                $nombre = 'banco_cuenta'; $fieldName = 'banco_cuenta_id'; $fieldDesc = 'nombre'; $vsTable = 'cuentat_a_banco_tc'; $vsFieldID = 'banco_cuenta_id';
1508                $sql = "SELECT /*$sqlComment*/  $fieldName$fieldDesc$fieldName as real_data, $fieldDesc as label, $fieldName as value FROM $nombre WHERE EXISTS (SELECT 1 FROM $vsTable WHERE $nombre.$fieldName=$vsTable.$vsFieldID) AND $nombre.vale='Active' ORDER BY 2";
1509                
1510                $array = ia_sqlArrayIndx($sql);
1511                jsonFile($fileName, $array);
1512                $jsonData = json_encode($array);
1513            }
1514            break;
1515
1516        case 'inversion_banco_cuenta_id_empresa_activo':
1517            if(!$genera && file_exists($fileName))
1518                $jsonData = file_get_contents($fileName);
1519            if(strlen($jsonData) === 0)
1520            {
1521                $nombre = 'banco_cuenta'; $fieldName = 'banco_cuenta_id'; $fieldDesc = 'nombre'; $vsTable = 'inversion'; $vsFieldID = 'banco_cuenta_id'; $xtraWhere = "";
1522                $sql = "SELECT /*$sqlComment*/  $fieldName$fieldDesc$fieldName as real_data, $fieldDesc as label, $fieldName as value FROM $nombre WHERE EXISTS (SELECT 1 FROM $vsTable WHERE $nombre.$fieldName=$vsTable.$vsFieldID $xtraWhere) AND $nombre.vale='Active' AND  tipo_inversion_empresa_privada='empresa' ORDER BY 2";
1523
1524                //echo $sql;
1525
1526                $array = ia_sqlArrayIndx($sql);
1527                jsonFile($fileName, $array);
1528                $jsonData = json_encode($array);
1529            }
1530            break;
1531
1532
1533        case 'inversion_reembolso_banco_cuenta_id_empresa_activo':
1534            if(!$genera && file_exists($fileName))
1535                $jsonData = file_get_contents($fileName);
1536            if(strlen($jsonData) === 0)
1537            {
1538                $nombre = 'banco_cuenta'; $fieldName = 'banco_cuenta_id'; $fieldDesc = 'nombre'; $vsTable = 'inversion_reembolso'; $vsFieldID = 'banco_cuenta_id'; $xtraWhere = "";
1539                $sql = "SELECT /*$sqlComment*/  $fieldName$fieldDesc$fieldName as real_data, $fieldDesc as label, $fieldName as value FROM $nombre WHERE EXISTS (SELECT 1 FROM $vsTable WHERE $nombre.$fieldName=$vsTable.$vsFieldID $xtraWhere) AND $nombre.vale='Active' AND  tipo_inversion_empresa_privada='empresa' ORDER BY 2";
1540
1541//                echo $sql;
1542
1543                $array = ia_sqlArrayIndx($sql);
1544                jsonFile($fileName, $array);
1545                $jsonData = json_encode($array);
1546            }
1547            break;
1548
1549        case 'inversion_banco_cuenta_id_privada_activo':
1550            if(!$genera && file_exists($fileName))
1551                $jsonData = file_get_contents($fileName);
1552            if(strlen($jsonData) === 0)
1553            {
1554                $nombre = 'banco_cuenta'; $fieldName = 'banco_cuenta_id'; $fieldDesc = 'nombre'; $vsTable = 'inversion'; $vsFieldID = 'banco_cuenta_id'; $xtraWhere = "";
1555                $sql = "SELECT /*$sqlComment*/  $fieldName$fieldDesc$fieldName as real_data, $fieldDesc as label, $fieldName as value FROM $nombre WHERE EXISTS (SELECT 1 FROM $vsTable WHERE $nombre.$fieldName=$vsTable.$vsFieldID $xtraWhere) AND $nombre.vale='Active' AND  tipo_inversion_empresa_privada='privada' ORDER BY 2";
1556
1557                //echo $sql;
1558
1559                $array = ia_sqlArrayIndx($sql);
1560                jsonFile($fileName, $array);
1561                $jsonData = json_encode($array);
1562            }
1563            break;
1564
1565        case 'inversion_reembolso_banco_cuenta_id_privada_activo':
1566            if(!$genera && file_exists($fileName))
1567                $jsonData = file_get_contents($fileName);
1568            if(strlen($jsonData) === 0)
1569            {
1570                $nombre = 'banco_cuenta'; $fieldName = 'banco_cuenta_id'; $fieldDesc = 'nombre'; $vsTable = 'inversion_reembolso'; $vsFieldID = 'banco_cuenta_id'; $xtraWhere = "";
1571                $sql = "SELECT /*$sqlComment*/  $fieldName$fieldDesc$fieldName as real_data, $fieldDesc as label, $fieldName as value FROM $nombre WHERE EXISTS (SELECT 1 FROM $vsTable WHERE $nombre.$fieldName=$vsTable.$vsFieldID $xtraWhere) AND $nombre.vale='Active' AND  tipo_inversion_empresa_privada='privada' ORDER BY 2";
1572
1573                //echo $sql;
1574
1575                $array = ia_sqlArrayIndx($sql);
1576                jsonFile($fileName, $array);
1577                $jsonData = json_encode($array);
1578            }
1579            break;
1580
1581        case 'inversion_reembolso_alta_por':
1582            if(!$genera && file_exists($fileName))
1583                $jsonData = file_get_contents($fileName);
1584            if(strlen($jsonData) === 0)
1585            {
1586                $nombre = 'inversion_reembolso'; $fieldName = 'alta_por'; $fieldDesc = 'alta_por';
1587                $sql = "SELECT /*$sqlComment*/  $fieldName$fieldDesc$fieldName as real_data, $fieldDesc as label, $fieldName as value FROM $nombre ORDER BY 2";
1588                $array = ia_sqlArray($sql,'alta_por');
1589                //$array = ia_sqlArrayIndx($sql);
1590                jsonFile($fileName, $array);
1591                $jsonData = json_encode($array);
1592            }
1593            break;
1594
1595
1596
1597        //Generales compartidos
1598        case 'banco_cuenta':
1599
1600            if(!$genera && file_exists($fileName))
1601                $jsonData = file_get_contents($fileName);
1602            if(strlen($jsonData) === 0)
1603            {
1604                $nombre = 'banco_cuenta'; $fieldName = 'banco_cuenta_id'; $fieldDesc = 'nombre';
1605                $sql = "SELECT /*$sqlComment*/  $fieldName$fieldDesc$fieldName as real_data, $fieldDesc as label, $fieldName as value FROM $nombre WHERE $nombre.vale='Active' ORDER BY 2";
1606
1607                
1608                $array = ia_sqlArrayIndx($sql);
1609                jsonFile($fileName, $array);
1610                $jsonData = json_encode($array);
1611            }
1612            break;
1613
1614        case 'banco':
1615
1616            if(!$genera && file_exists($fileName))
1617                $jsonData = file_get_contents($fileName);
1618            if(strlen($jsonData) === 0)
1619            {
1620                $nombre = 'banco'; $fieldName = 'banco_id'; $fieldDesc = 'banco';
1621                $sql = "SELECT /*$sqlComment*/  $fieldName$fieldDesc$fieldName as real_data, $fieldDesc as label, $fieldName as value FROM $nombre ORDER BY 2";
1622
1623                
1624                $array = ia_sqlArrayIndx($sql);
1625                jsonFile($fileName, $array);
1626                $jsonData = json_encode($array);
1627            }
1628            break;
1629        case 'banco_con_cuenta':
1630
1631            if(!$genera && file_exists($fileName))
1632                $jsonData = file_get_contents($fileName);
1633            if(strlen($jsonData) === 0)
1634            {
1635                $nombre = 'banco'; $fieldName = 'banco_id'; $fieldDesc = 'banco';
1636                $sql = "SELECT /*$sqlComment*/  $fieldName$fieldDesc$fieldName as real_data, $fieldDesc as label, $fieldName as value FROM $nombre WHERE banco_id IN (SELECT banco_id FROM banco_cuenta WHERE vale = 'Active') ORDER BY 2";
1637
1638
1639                $array = ia_sqlArrayIndx($sql);
1640                jsonFile($fileName, $array);
1641                $jsonData = json_encode($array);
1642            }
1643            break;
1644
1645        case 'categoria':
1646
1647            if(!$genera && file_exists($fileName))
1648                $jsonData = file_get_contents($fileName);
1649            if(strlen($jsonData) === 0)
1650            {
1651                $nombre = 'categoria'; $fieldName = 'categoria_id'; $fieldDesc = 'categoria';
1652                $sql = "SELECT /*$sqlComment*/  $fieldName$fieldDesc$fieldName as real_data, $fieldDesc as label, $fieldName as value FROM $nombre ORDER BY 2";
1653                
1654                $array = ia_sqlArrayIndx($sql);
1655                jsonFile($fileName, $array);
1656                $jsonData = json_encode($array);
1657
1658                $sql = "SELECT /*$sqlComment*/  $fieldName$fieldDesc$fieldName as real_data, $fieldDesc as label, $fieldName as value FROM $nombre WHERE para_quien = 'TODOS' ORDER BY 2";
1659                $array = ia_sqlArrayIndx($sql);
1660                jsonFile(str_replace('categoria', 'categoriaNoRony', $fileName), $array);
1661
1662            }
1663            break;
1664
1665        case 'reporte_grid':
1666            if(!$genera && file_exists($fileName))
1667                $jsonData = file_get_contents($fileName);
1668            if(strlen($jsonData) === 0)
1669            {
1670                //$nombre = 'reportes_grid';
1671                $sql = "SELECT /*$sqlComment*/  reporte_grid_id, nombre, descripcion, usuario, origen, '1' as permiso FROM reportes_grid WHERE 1 ORDER BY alta_db DESC";
1672                
1673                $array = ia_sqlArrayIndx($sql);
1674                jsonFile($fileName, $array);
1675                $jsonData = json_encode($array);
1676            }
1677            break;
1678
1679        case 'importador':
1680            if(!$genera && file_exists($fileName))
1681                $jsonData = file_get_contents($fileName);
1682            if(strlen($jsonData) === 0) {
1683                $nombre = 'importador'; $fieldName = 'importador_id'; $fieldDesc = 'nombre';
1684                $sql = "SELECT /*$sqlComment*/  $fieldName$fieldDesc$fieldName as real_data, $fieldDesc as label, $fieldName as value FROM $nombre WHERE $nombre.activo='Si' ORDER BY 2";
1685                $array = ia_sqlArrayIndx($sql);
1686                jsonFile($fileName, $array);
1687                $jsonData = json_encode($array);
1688            }
1689            break;
1690
1691        case 'tienda':
1692
1693            if(!$genera && file_exists($fileName))
1694                $jsonData = file_get_contents($fileName);
1695            if(strlen($jsonData) === 0)
1696            {
1697                $nombre = 'tienda'; $fieldName = 'tienda_id'; $fieldDesc = 'clave';
1698                $sql = "SELECT /*$sqlComment*/  $fieldName$fieldDesc$fieldName as real_data, $fieldDesc as label, $fieldName as value FROM $nombre WHERE $nombre.vale='Active' ORDER BY 2";
1699
1700                
1701                $array = ia_sqlArrayIndx($sql);
1702                jsonFile($fileName, $array);
1703                $jsonData = json_encode($array);
1704            }
1705            break;
1706
1707        case 'empresa':
1708
1709            if(!$genera && file_exists($fileName))
1710                $jsonData = file_get_contents($fileName);
1711            if(strlen($jsonData) === 0)
1712            {
1713                $nombre = 'empresa'; $fieldName = 'empresa_id'; $fieldDesc = 'empresa';
1714                $sql = "SELECT /*$sqlComment*/  $fieldName$fieldDesc$fieldName as real_data, $fieldDesc as label, $fieldName as value FROM $nombre WHERE vale='Active' ORDER BY 2";
1715
1716                
1717                $array = ia_sqlArrayIndx($sql);
1718                jsonFile($fileName, $array);
1719                $jsonData = json_encode($array);
1720            }
1721            break;
1722
1723        case 'nombre_empresa':
1724
1725            if(!$genera && file_exists($fileName))
1726                $jsonData = file_get_contents($fileName);
1727            if(strlen($jsonData) === 0)
1728            {
1729                $nombre = 'empresa'; $fieldName = 'empresa'; $fieldDesc = 'empresa';
1730                $sql = "SELECT /*$sqlComment*/  $fieldName$fieldDesc$fieldName as real_data, $fieldDesc as label, $fieldName as value FROM $nombre WHERE vale='Active' ORDER BY 2";
1731
1732
1733                $array = ia_sqlArrayIndx($sql);
1734                jsonFile($fileName, $array);
1735                $jsonData = json_encode($array);
1736            }
1737            break;
1738
1739        case 'banco_mov_tipo':case 'banco_mov_tipo_id':
1740
1741        if(!$genera && file_exists($fileName))
1742            $jsonData = file_get_contents($fileName);
1743        if(strlen($jsonData) === 0)
1744        {
1745            $nombre = 'banco_mov_tipo'; $fieldName = 'banco_mov_tipo_id'; $fieldDesc = 'tipo';
1746            $sql = "SELECT /*$sqlComment*/  $fieldName$fieldDesc$fieldName as real_data, $fieldDesc as label, $fieldName as value FROM $nombre WHERE vale='Active' ORDER BY 2";
1747
1748            
1749            $array = ia_sqlArrayIndx($sql);
1750            jsonFile($fileName, $array);
1751            $jsonData = json_encode($array);
1752        }
1753        break;
1754
1755
1756        case 'moneda':case 'moneda_id':
1757
1758        if(!$genera && file_exists($fileName))
1759            $jsonData = file_get_contents($fileName);
1760        if(strlen($jsonData) === 0)
1761        {
1762            $nombre = 'moneda'; $fieldName = 'moneda_id'; $fieldDesc = 'moneda';
1763            $sql = "SELECT /*$sqlComment*/  $fieldName$fieldDesc$fieldName as real_data, $fieldDesc as label, $fieldName as value FROM $nombre ORDER BY 2";
1764
1765            
1766            $array = ia_sqlArrayIndx($sql);
1767            jsonFile($fileName, $array);
1768            $jsonData = json_encode($array);
1769        }
1770        break;
1771
1772        case 'tc':
1773
1774            if(!$genera && file_exists($fileName))
1775                $jsonData = file_get_contents($fileName);
1776            if(strlen($jsonData) === 0)
1777            {
1778                //$nombre = ''; $fieldName = ''; $fieldDesc = '';
1779                $sql = "SELECT /*$sqlComment*/  * FROM tc_log ORDER BY alta_db DESC LIMIT 1";
1780
1781                
1782                $array = ia_singleton($sql);
1783                jsonFile($fileName, $array);
1784                $jsonData = json_encode($array);
1785            }
1786            break;
1787
1788        case 'cuentaT_id':case 'cuentat':
1789        if(!$genera && file_exists($fileName))
1790            $jsonData = file_get_contents($fileName);
1791        if(strlen($jsonData) === 0)
1792        {
1793            $nombre = 'cuentat'; $fieldName = 'cuentaT_id'; $fieldDesc = 'usuario';
1794            $sql = "SELECT /*$sqlComment*/  $fieldName$fieldDesc$fieldName as real_data, $fieldDesc as label, $fieldName as value FROM $nombre WHERE $nombre.vale='Active' ORDER BY 2";
1795
1796            
1797
1798            //echo "<li>".$sql;
1799            $array = ia_sqlArrayIndx($sql);
1800            jsonFile($fileName, $array);
1801            $jsonData = json_encode($array);
1802        }
1803        break;
1804
1805        case 'usocfdi':
1806
1807            if(!$genera && file_exists($fileName))
1808                $jsonData = file_get_contents($fileName);
1809            if(strlen($jsonData) === 0)
1810            {
1811                $sql = "SELECT /*$sqlComment*/  valor as real_data, valor as label, valor as value FROM campos_exists WHERE tabla_exists='UsoCFDI' ORDER BY campo_id";
1812
1813                
1814                $array = ia_sqlArrayIndx($sql);
1815                jsonFile($fileName, $array);
1816                $jsonData = json_encode($array);
1817            }
1818            break;
1819
1820        case 'metodopago':
1821
1822            if(!$genera && file_exists($fileName))
1823                $jsonData = file_get_contents($fileName);
1824            if(strlen($jsonData) === 0)
1825            {
1826                $sql = "SELECT /*$sqlComment*/  valor as real_data, valor as label, valor as value FROM campos_exists WHERE tabla_exists='MetodoPago' ORDER BY campo_id";
1827
1828                
1829                $array = ia_sqlArrayIndx($sql);
1830                jsonFile($fileName, $array);
1831                $jsonData = json_encode($array);
1832            }
1833            break;
1834
1835        case 'formapago':
1836
1837            if(!$genera && file_exists($fileName))
1838                $jsonData = file_get_contents($fileName);
1839            if(strlen($jsonData) === 0)
1840            {
1841                $sql = "SELECT /*$sqlComment*/  valor as real_data, valor as label, valor as value FROM campos_exists WHERE tabla_exists='FormaPago' ORDER BY campo_id";
1842
1843                
1844                $array = ia_sqlArrayIndx($sql);
1845                jsonFile($fileName, $array);
1846                $jsonData = json_encode($array);
1847            }
1848            break;
1849
1850        case 'depositar_en':
1851
1852            if(!$genera && file_exists($fileName))
1853                $jsonData = file_get_contents($fileName);
1854            if(strlen($jsonData) === 0)
1855            {
1856                //$nombre = ''; $fieldName = ''; $fieldDesc = '';
1857                $sql = "SELECT /*$sqlComment*/  * FROM kv_record_log WHERE collection_id = '".kvTablaID("depositar_en")."' ORDER BY alta_db DESC LIMIT 1";
1858
1859                
1860                $array = ia_singleton($sql);
1861                jsonFile($fileName, $array);
1862                $jsonData = json_encode($array);
1863            }
1864            break;
1865
1866        case 'clientes_internos':
1867
1868            if(!$genera && file_exists($fileName))
1869                $jsonData = file_get_contents($fileName);
1870            if(strlen($jsonData) === 0)
1871            {
1872                $nombre = 'cliente'; $fieldName = 'cliente_id'; $fieldDesc = 'nombre'; //$vsTable = 'cliente'; $vsFieldID = 'cliente_id';
1873                $sql = "SELECT /*$sqlComment*/  $fieldName$fieldDesc$fieldName as real_data, $fieldDesc as label, $fieldName as value FROM $nombre WHERE interno='Si' ORDER BY 2";
1874                
1875                $array = ia_sqlArrayIndx($sql);
1876                jsonFile($fileName, $array);
1877                $jsonData = json_encode($array);
1878            }
1879            break;
1880
1881        case 'es_withdrawal_deposit':
1882            if(!$genera && file_exists($fileName))
1883                $jsonData = file_get_contents($fileName);
1884            if(strlen($jsonData) === 0)
1885            {
1886                $array = array(
1887                    array('label'=>'Withdrawal', 'value'=> 'Retiro', 'real_data'=> 'Retiro'),
1888                    array('label'=>'Deposit', 'value'=> 'Deposito', 'real_data'=> 'Deposito'),
1889                    array('label'=>'Deposit MST', 'value'=> 'Deposito', 'real_data'=> 'Deposito'),
1890                    array('label'=>'Deposit FACTURA', 'value'=> 'Deposito', 'real_data'=> 'Deposito')
1891                );
1892                jsonFile($fileName, $array);
1893                $jsonData = json_encode($array);
1894            }
1895            break;
1896
1897        case 'app_origen':
1898            if(!$genera && file_exists($fileName))
1899                $jsonData = file_get_contents($fileName);
1900            if(strlen($jsonData) === 0)
1901            {
1902                $array = arrayAppOrigen(true);
1903                jsonFile($fileName, $array);
1904                $jsonData = json_encode($array);
1905            }
1906            break;
1907
1908        case 'kv_accion_log_id':
1909
1910            if(!$genera && file_exists($fileName))
1911                $jsonData = file_get_contents($fileName);
1912            if(strlen($jsonData) === 0)
1913            {
1914                $nombre = 'kv_accion_log'; $fieldName = 'kv_accion_log_id'; $fieldDesc = 'accion';
1915                $sql = "SELECT /*$sqlComment*/  $fieldName$fieldDesc$fieldName as real_data, $fieldDesc as label, $fieldName as value FROM $nombre WHERE 1 ORDER BY 2";
1916                
1917                $array = ia_sqlArrayIndx($sql);
1918                jsonFile($fileName, $array);
1919                $jsonData = json_encode($array);
1920            }
1921            break;
1922
1923        case 'collection_id':
1924
1925            if(!$genera && file_exists($fileName))
1926                $jsonData = file_get_contents($fileName);
1927            if(strlen($jsonData) === 0)
1928            {
1929                $nombre = 'tablas'; $fieldName = 'tabla_id'; $fieldDesc = 'tabla';
1930                $sql = "SELECT /*$sqlComment*/  $fieldName$fieldDesc$fieldName as real_data, $fieldDesc as label, $fieldName as value FROM $nombre WHERE 1 ORDER BY 2";
1931                
1932                $array = ia_sqlArrayIndx($sql);
1933                jsonFile($fileName, $array);
1934                $jsonData = json_encode($array);
1935            }
1936            break;
1937
1938
1939        case 'links_borrados_ultimo_movimiento':
1940            if(!$genera && file_exists($fileName))
1941                $jsonData = file_get_contents($fileName);
1942            if(strlen($jsonData) === 0)
1943            {
1944                $array = array(
1945                    array('label'=>'LINK BORRADO',     'value'=> 'LINK BORRADO'),
1946                );
1947                jsonFile($fileName, $array);
1948                $jsonData = json_encode($array);
1949            }
1950            break;
1951
1952        case 'link_vale':
1953            if(!$genera && file_exists($fileName))
1954                $jsonData = file_get_contents($fileName);
1955            if(strlen($jsonData) === 0)
1956            {
1957                $array = arrayLinkVale(true);
1958
1959
1960                jsonFile($fileName, $array);
1961                $jsonData = json_encode($array);
1962            }
1963            break;
1964
1965        case 'cliente_tienda_id':
1966
1967            if(!$genera && file_exists($fileName))
1968                $jsonData = file_get_contents($fileName);
1969            if(strlen($jsonData) === 0)
1970            {
1971                $nombre = 'tienda'; $fieldName = 'tienda_id'; $fieldDesc = 'clave'; $vsTable = 'cliente'; $vsFieldID = 'tienda_id';
1972                $sql = "SELECT /*$sqlComment*/  $fieldName$fieldDesc$fieldName as real_data, $fieldDesc as label, $fieldName as value FROM $nombre WHERE EXISTS (SELECT 1 FROM $vsTable WHERE $nombre.$fieldName=$vsTable.$vsFieldID) AND $nombre.vale='Active' ORDER BY 2";
1973                
1974                $array = ia_sqlArrayIndx($sql);
1975                jsonFile($fileName, $array);
1976                $jsonData = json_encode($array);
1977            }
1978            break;
1979
1980        case 'cliente_activo':
1981
1982            if(!$genera && file_exists($fileName))
1983                $jsonData = file_get_contents($fileName);
1984            if(strlen($jsonData) === 0)
1985            {
1986                $nombre = 'cliente'; $fieldName = 'cliente_id'; $fieldDesc = 'nombre';
1987                $sql = "SELECT /*$sqlComment*/  $fieldName$fieldDesc$fieldName as real_data, $fieldDesc as label, $fieldName as value FROM $nombre WHERE vale='Active' ORDER BY 2";
1988
1989                
1990                $array = ia_sqlArrayIndx($sql);
1991                jsonFile($fileName, $array);
1992                $jsonData = json_encode($array);
1993            }
1994            break;
1995
1996        case 'cliente':
1997
1998            $nombre = 'cliente'; $fieldName = 'cliente_id'; $fieldDesc = 'nombre';
1999            $vsTable = ''; $vsFieldID = ''; $vsAnd = ""; $vsPaid = "";
2000            $jsonData = obtenClientesConPermiso(
2001                $fileName, $genera=true,$nombre, $fieldName, $fieldDesc,
2002                $vsTable, $vsFieldID, $vsAnd, '', $vsPaid);
2003            break;
2004
2005
2006            if(!$genera && file_exists($fileName))
2007                $jsonData = file_get_contents($fileName);
2008            if(strlen($jsonData) === 0)
2009            {
2010                $nombre = 'cliente'; $fieldName = 'cliente_id'; $fieldDesc = 'nombre';
2011                $sql = "SELECT /*$sqlComment*/  $fieldName$fieldDesc$fieldName as real_data, $fieldDesc as label, $fieldName as value FROM $nombre ORDER BY 2";
2012
2013                
2014                $array = ia_sqlArrayIndx($sql);
2015                jsonFile($fileName, $array);
2016                $jsonData = json_encode($array);
2017            }
2018            break;
2019
2020
2021        case 'clientes_saldos':
2022
2023            if(!$genera && file_exists($fileName))
2024                $jsonData = file_get_contents($fileName);
2025            if(strlen($jsonData) === 0)
2026            {
2027                $nombre = 'clientes_saldos_live'; $fieldName = 'cliente_id'; $fieldDesc = 'nombre';
2028                $sql = "SELECT /*$sqlComment*/  $fieldName$fieldDesc$fieldName as real_data, $fieldDesc as label, $fieldName as value FROM $nombre WHERE saldo_total_ventas_pesos > 0.00 OR saldo_total_ventas_usd > 0.00 OR saldo_compras_pesos > 0.00 OR saldo_compras_usd > 0.00 ORDER BY 2";
2029
2030                
2031                $array = ia_sqlArrayIndx($sql);
2032                jsonFile($fileName, $array);
2033                $jsonData = json_encode($array);
2034            }
2035            break;
2036
2037        case 'clientes_saldos_nombre':
2038
2039            if(!$genera && file_exists($fileName))
2040                $jsonData = file_get_contents($fileName);
2041            if(strlen($jsonData) === 0)
2042            {
2043                $nombre = 'clientes_saldos_live'; $fieldName = 'nombre'; $fieldDesc = 'nombre';
2044                $sql = "SELECT /*$sqlComment*/  $fieldName$fieldDesc$fieldName as real_data, $fieldDesc as label, $fieldName as value FROM $nombre WHERE saldo_total_ventas_pesos > 0.00 OR saldo_total_ventas_usd > 0.00 OR saldo_compras_pesos > 0.00 OR saldo_compras_usd > 0.00 ORDER BY 2";
2045
2046                
2047                $array = ia_sqlArrayIndx($sql);
2048                jsonFile($fileName, $array);
2049                $jsonData = json_encode($array);
2050            }
2051            break;
2052        // inician catalogos de bodega
2053        case 'bodega':
2054
2055            if(!$genera && file_exists($fileName))
2056                $jsonData = file_get_contents($fileName);
2057            if(strlen($jsonData) === 0)
2058            {
2059                $nombre = 'bodega'; $fieldName = 'bodega_id'; $fieldDesc = 'bodega';
2060                $sql = "SELECT /*$sqlComment*/  $fieldName$fieldDesc$fieldName as real_data, $fieldDesc as label, $fieldName as value, color FROM $nombre WHERE activo = 'Si' ORDER BY bodega";
2061
2062                $sql = "SELECT /*$sqlComment*/ bodega_id, bodega, bodega_id as real_value, bodega_id as real_data, bodega as label, bodega as value, grupo, color FROM bodega WHERE activo = 'Si' ORDER BY bodega";
2063    
2064                $array = ia_sqlArrayIndx($sql);
2065                jsonFile($fileName, $array, JSON_PRETTY_PRINT);
2066                $jsonData = json_encode($array);
2067            }
2068            break;
2069
2070        case 'bodega_cliente':
2071            $nombre = 'cliente'; $fieldName = 'cliente_id'; $fieldDesc = 'nombre';
2072            $vsTable = 'nota_bodega'; $vsFieldID = 'cliente'; $vsAnd = ""; $vsPaid = "";
2073
2074            $jsonData = obtenClientesConPermiso(
2075                $fileName, $genera,$nombre, $fieldName, $fieldDesc,
2076                $vsTable, $vsFieldID, $vsAnd, $nombreCatalogo, $vsPaid);
2077            break;
2078
2079        case 'bodega_todas':
2080
2081            if(!$genera && file_exists($fileName))
2082                $jsonData = file_get_contents($fileName);
2083            if(strlen($jsonData) === 0)
2084            {
2085                $sql = "SELECT /*$sqlComment*/ bodega_id, bodega, bodega_id as real_value, bodega_id as real_data, bodega as label, bodega as value, grupo, color FROM bodega ORDER BY bodega";
2086
2087                $array = ia_sqlArrayIndx($sql);
2088                jsonFile($fileName, $array, JSON_PRETTY_PRINT);
2089                $jsonData = json_encode($array);
2090            }
2091            break;
2092        case 'bodega_labels':
2093
2094            if(!$genera && file_exists($fileName))
2095                $jsonData = file_get_contents($fileName);
2096            if(strlen($jsonData) === 0)
2097            {
2098                $sql = "SELECT /*$sqlComment*/ bodega_id, bodega, bodega_id as real_value, bodega as real_data, bodega as label, bodega as value, grupo, color FROM bodega WHERE activo = 'Si' ORDER BY bodega";
2099
2100                $array = ia_sqlArrayIndx($sql);
2101                jsonFile($fileName, $array, JSON_PRETTY_PRINT);
2102                $jsonData = json_encode($array);
2103            }
2104            break;
2105
2106        case 'bodega_labels_todas':
2107
2108            if(!$genera && file_exists($fileName))
2109                $jsonData = file_get_contents($fileName);
2110            if(strlen($jsonData) === 0)
2111            {
2112                $sql = "SELECT /*$sqlComment*/ bodega_id, bodega, bodega_id as real_value, bodega as real_data, bodega as label, bodega as value, grupo, color FROM bodega ORDER BY bodega";
2113
2114                $array = ia_sqlArrayIndx($sql);
2115                jsonFile($fileName, $array, JSON_PRETTY_PRINT);
2116                $jsonData = json_encode($array);
2117            }
2118            break;
2119
2120        case 'bodegas_y_grupos':
2121            if(!$genera && file_exists($fileName))
2122                $jsonData = file_get_contents($fileName);
2123            if(strlen($jsonData) === 0)
2124            {
2125                $nombre = 'bodega'; $fieldName = 'bodega_id'; $fieldDesc = 'bodega';
2126                $sql =
2127                    "SELECT /*$sqlComment*/ 
2128                        bodega_id, bodega, bodega_id as real_value, bodega_id as real_data, bodega as label, bodega as value 
2129                    FROM bodega 
2130                    WHERE activo = 'Si' 
2131                    UNION ALL
2132                    SELECT DISTINCT 
2133                        grupo, grupo, grupo as real_value, grupo as real_data, grupo as label, grupo as value
2134                    FROM bodega 
2135                    WHERE activo = 'Si' AND grupo <> ''
2136                    ORDER BY 2";
2137
2138                $array = ia_sqlArrayIndx($sql);
2139                jsonFile($fileName, $array, JSON_PRETTY_PRINT);
2140                $jsonData = json_encode($array);
2141            }
2142            break;
2143
2144        case 'grupo':
2145
2146            if(!$genera && file_exists($fileName))
2147                $jsonData = file_get_contents($fileName);
2148            if(strlen($jsonData) === 0)
2149            {
2150                $nombre = 'grupo'; $fieldName = 'grupo'; $fieldDesc = 'grupo';
2151                $sql = "SELECT DISTINCT /*$sqlComment*/  $fieldName$fieldDesc$fieldName as real_data, $fieldDesc as label, $fieldName as value FROM bodega WHERE activo = 'Si' ORDER BY bodega";
2152
2153                $array = array_values( ia_sqlArray($sql, 'grupo') );
2154                jsonFile($fileName,  $array, JSON_PRETTY_PRINT);
2155                $jsonData = json_encode($array);
2156            }
2157            break;
2158
2159        case 'color':
2160            if(!$genera && file_exists($fileName))
2161                $jsonData = file_get_contents($fileName);
2162            if(empty($jsonData) || $jsonData === 'false')
2163            {
2164                $sql = "SELECT /*$sqlComment*/ color_id, color, color_valor, color_id as real_value, color_id as real_data, color as label, color as value FROM color WHERE activo = 'Si' ORDER BY orden, color";
2165                $array = ia_sqlArrayIndx($sql);
2166                jsonFile($fileName, $array, JSON_PRETTY_PRINT);
2167                $jsonData = json_encode($array);
2168            }
2169            break;
2170        case 'color_alfabetico':
2171            if(!$genera && file_exists($fileName))
2172                $jsonData = file_get_contents($fileName);
2173            if(empty($jsonData) || $jsonData === 'false')
2174            {
2175                $sql = "SELECT /*$sqlComment*/ color_id, color, color_valor, color_id as real_value, color_id as real_data, color as label, color as value FROM color WHERE activo = 'Si' ORDER BY color";
2176                $array = ia_sqlArrayIndx($sql);
2177                jsonFile($fileName, $array, JSON_PRETTY_PRINT);
2178                $jsonData = json_encode($array);
2179            }
2180            break;
2181        case 'color_alfabetico_desc':
2182            if(!$genera && file_exists($fileName))
2183                $jsonData = file_get_contents($fileName);
2184            if(empty($jsonData) || $jsonData === 'false')
2185            {
2186                $sql = "SELECT /*$sqlComment*/ color_id, color, color_valor, color_id as real_value, color_id as real_data, color as label, color as value FROM color WHERE activo = 'Si' ORDER BY color desc";
2187                $array = ia_sqlArrayIndx($sql);
2188                jsonFile($fileName, $array, JSON_PRETTY_PRINT);
2189                $jsonData = json_encode($array);
2190            }
2191            break;
2192        case 'color_busca_por_nombre':
2193
2194            if(!$genera && file_exists($fileName))
2195                $jsonData = file_get_contents($fileName);
2196            if(empty($jsonData) || $jsonData === 'false')
2197            {
2198                $nombre = 'color'; $fieldName = 'color'; $fieldDesc = 'color';
2199                $sql = "SELECT /*$sqlComment*/  $fieldName$fieldDesc$fieldName as real_data, $fieldDesc as label, $fieldName as value, color_valor FROM $nombre WHERE activo = 'Si' ORDER BY orden, color";
2200                $array = ia_sqlArrayIndx($sql);
2201                jsonFile($fileName, $array, JSON_PRETTY_PRINT);
2202                $jsonData = json_encode($array);
2203            }
2204            break;
2205
2206        case 'origen_bodega_bodega_grupo_keyValue_all':
2207            //
2208            if(!$genera && file_exists($fileName))
2209                $jsonData = file_get_contents($fileName);
2210            if(empty($jsonData) || $jsonData === 'false') {
2211                $p = ia_sqlKeyValue("select /*$sqlComment*/ origen_bodega_id, clave from origen_bodega WHERE es IN ('BODEGA', 'GRUPO BODEGA') ORDER BY 2");
2212                if(empty($p))
2213                    $p = [];
2214                $jsonData = json_encode($p, JSON_OPTIONS_FOR_MYSQL);
2215                jsonFile($fileName, $p);
2216            }
2217            break;
2218
2219        case 'bodega_keyValue':
2220            if(!$genera && file_exists($fileName))
2221                $jsonData = file_get_contents($fileName);
2222            if(empty($jsonData) || $jsonData === 'false') {
2223                $p = ia_sqlKeyValue("SELECT /*$sqlComment*/ bodega_id, bodega FROM bodega WHERE activo = 'Si' ORDER BY 2");
2224                if(empty($p))
2225                    $p = [];
2226                $jsonData = json_encode($p, JSON_OPTIONS_FOR_MYSQL);
2227                jsonFile($fileName, $p);
2228            }
2229            break;
2230        case 'bodega2grupo':
2231            if(!$genera && file_exists($fileName))
2232                $jsonData = file_get_contents($fileName);
2233            if(empty($jsonData) || $jsonData === 'false') {
2234                $p = ia_sqlKeyValue("SELECT /*$sqlComment*/ bodega_id, grupo FROM bodega WHERE activo = 'Si' ORDER BY 2");
2235                if(empty($p))
2236                    $p = [];
2237                $jsonData = json_encode($p, JSON_OPTIONS_FOR_MYSQL);
2238                jsonFile($fileName, $p);
2239            }
2240            break;
2241        case 'bodega_keyValue_all':
2242            if(!$genera && file_exists($fileName))
2243                $jsonData = file_get_contents($fileName);
2244            if(empty($jsonData) || $jsonData === 'false') {
2245                $p = ia_sqlKeyValue("SELECT /*$sqlComment*/ bodega_id, bodega FROM bodega ORDER BY 2");
2246                if(empty($p))
2247                    $p = [];
2248                $jsonData = json_encode($p, JSON_OPTIONS_FOR_MYSQL);
2249                jsonFile($fileName, $p);
2250            }
2251            break;
2252        case 'color_keyValue':
2253            if(!$genera && file_exists($fileName))
2254                $jsonData = file_get_contents($fileName);
2255            if(empty($jsonData) || $jsonData === 'false') {
2256                $p = ia_sqlKeyValue("SELECT /*$sqlComment*/ color_id, color FROM color WHERE activo = 'Si' ORDER BY 2");
2257                if(empty($p))
2258                    $p = [];
2259                $jsonData = json_encode($p, JSON_OPTIONS_FOR_MYSQL);
2260                jsonFile($fileName, $p);
2261            }
2262            break;
2263        case 'color_keyValue_all':
2264            if(!$genera && file_exists($fileName))
2265                $jsonData = file_get_contents($fileName);
2266            if(empty($jsonData) || $jsonData === 'false') {
2267                $p = ia_sqlKeyValue("SELECT /*$sqlComment*/ color_id, color FROM color ORDER BY 2");
2268                if(empty($p))
2269                    $p = [];
2270                $jsonData = json_encode($p, JSON_OPTIONS_FOR_MYSQL);
2271                jsonFile($fileName, $p);
2272            }
2273            break;
2274        case 'producto_general_keyValue':
2275            if(!$genera && file_exists($fileName))
2276                $jsonData = file_get_contents($fileName);
2277            if(empty($jsonData) || $jsonData === 'false') {
2278                $p = ia_sqlKeyValue("SELECT /*$sqlComment*/ producto_general_id, producto FROM producto_general WHERE activo = 'Si' ORDER BY 2");
2279                if(empty($p))
2280                    $p = [];
2281                $jsonData = json_encode($p, JSON_OPTIONS_FOR_MYSQL);
2282                jsonFile($fileName, $p);
2283            }
2284            break;
2285        case 'producto_general_keyValue_all':
2286            if(!$genera && file_exists($fileName))
2287                $jsonData = file_get_contents($fileName);
2288            if(empty($jsonData) || $jsonData === 'false') {
2289                $p = ia_sqlKeyValue("SELECT /*$sqlComment*/ producto_general_id, producto FROM producto_general ORDER BY 2");
2290                if(empty($p))
2291                    $p = [];
2292                $jsonData = json_encode($p, JSON_OPTIONS_FOR_MYSQL);
2293                jsonFile($fileName, $p);
2294            }
2295            break;
2296        case 'usuario_keyValue':
2297            if(!$genera && file_exists($fileName))
2298                $jsonData = file_get_contents($fileName);
2299            if(empty($jsonData) || $jsonData === 'false') {
2300                $p = ia_sqlKeyValue("SELECT /*$sqlComment*/ iac_usr_id, nick FROM iac_usr WHERE vale='Active' ORDER BY 2");
2301                if(empty($p))
2302                    $p = [];
2303                $jsonData = json_encode($p, JSON_OPTIONS_FOR_MYSQL);
2304                jsonFile($fileName, $p);
2305            }
2306            break;
2307        case 'producto_general_info':
2308            if(!$genera && file_exists($fileName))
2309                $jsonData = file_get_contents($fileName);
2310            if(empty($jsonData) || $jsonData === 'false') {
2311                $sql =
2312                    "SELECT pg.producto_general_id, pg.producto, IF(u.unidad IS NULL, '', u.unidad) as unidad,
2313                        pg.min_por_rollo, pg.max_por_rollo, pg.average_calculado, pg.weight_per_m,
2314                        pg.activo, pg.huerfano, pg.estado, pg.solo_carta_porte
2315                    FROM producto_general pg
2316                    LEFT OUTER JOIN unidades u on pg.unidades_id = u.unidades_id";
2317                $array = ia_sqlArray($sql, 'producto_general_id');
2318                jsonFile($fileName, $array, JSON_PRETTY_PRINT);
2319                $jsonData = json_encode($array);
2320            }
2321            break;
2322        case 'producto_general':
2323
2324            if(!$genera && file_exists($fileName))
2325                $jsonData = file_get_contents($fileName);
2326            if(empty($jsonData) || $jsonData === 'false')
2327            {
2328                $nombre = 'producto_general'; $fieldName = 'producto_general_id'; $fieldDesc = 'producto';
2329                $sql = "SELECT /*$sqlComment*/  $fieldName$fieldDesc$fieldName as real_data, $fieldDesc as label, $fieldName as value FROM $nombre WHERE activo = 'Si' ORDER BY producto";
2330
2331                $sql = "SELECT /*$sqlComment*/ 
2332                            producto_general_id, producto_general_id as real_data, producto, producto as producto_general, producto_general_id as real_value, 
2333                            producto as label, producto as value, u.unidad, min_por_rollo,max_por_rollo,weight_per_m, average_calculado
2334                        FROM producto_general JOIN unidades u USING (unidades_id) 
2335                        WHERE activo = 'Si' AND solo_carta_porte = 'No' 
2336                        ORDER BY producto";
2337
2338
2339
2340                $array = ia_sqlArrayIndx($sql);
2341                jsonFile($fileName, $array, JSON_PRETTY_PRINT);
2342                $jsonData = json_encode($array);
2343            }
2344            break;
2345        case 'producto_general_por_nombre':
2346
2347            if(!$genera && file_exists($fileName))
2348                $jsonData = file_get_contents($fileName);
2349            if(empty($jsonData) || $jsonData === 'false')
2350            {
2351                $nombre = 'producto_general'; $fieldName = 'producto'; $fieldDesc = 'producto';
2352                $sql = "SELECT /*$sqlComment*/  $fieldName$fieldDesc$fieldName as real_data, $fieldDesc as label, $fieldName as value, min_por_rollo,max_por_rollo,weight_per_m FROM $nombre WHERE activo = 'Si'  AND solo_carta_porte = 'No' ORDER BY producto";
2353
2354                $array = ia_sqlArrayIndx($sql);
2355                jsonFile($fileName, $array, JSON_PRETTY_PRINT);
2356                $jsonData = json_encode($array);
2357            }
2358            break;
2359
2360        case 'producto_general_cp':
2361
2362            if(!$genera && file_exists($fileName))
2363                $jsonData = file_get_contents($fileName);
2364            if(empty($jsonData) || $jsonData === 'false')
2365            {
2366                $sql = "SELECT /*$sqlComment*/ producto_general_id, producto_general_id as real_data, producto, producto as producto_general, 
2367                 producto_general_id as real_value, producto as label, producto as value, u.unidad, min_por_rollo,max_por_rollo,weight_per_m
2368                        FROM producto_general JOIN unidades u USING (unidades_id) WHERE activo = 'Si' ORDER BY producto";
2369
2370                $array = ia_sqlArrayIndx($sql);
2371                jsonFile($fileName, $array, JSON_PRETTY_PRINT);
2372                $jsonData = json_encode($array);
2373            }
2374            break;
2375
2376        case 'producto_color':
2377
2378            if(!$genera && file_exists($fileName))
2379                $jsonData = file_get_contents($fileName);
2380            if(strlen($jsonData) === 0)
2381            {
2382                $nombre = 'producto_color'; $fieldName = 'producto_color_id'; $fieldDesc = 'producto';
2383                $sql = "SELECT /*$sqlComment*/  $fieldName$fieldDesc$fieldName as real_data, $fieldDesc as label, $fieldName as value FROM $nombre WHERE activo = 'Si' ORDER BY producto";
2384        
2385                $array = ia_sqlArrayIndx($sql);
2386                jsonFile($fileName, $array, JSON_PRETTY_PRINT);
2387                $jsonData = json_encode($array);
2388            }
2389            break;
2390        case 'producto_color_nombre':
2391
2392            if(!$genera && file_exists($fileName))
2393                $jsonData = file_get_contents($fileName);
2394            if(strlen($jsonData) === 0 || $jsonData === 'false') {
2395                $nombre = 'producto_color'; $fieldName = 'producto'; $fieldDesc = 'producto';
2396                $sql = "SELECT /*$sqlComment*/  $fieldName$fieldDesc$fieldName as real_data, $fieldDesc as label, $fieldName as value FROM $nombre WHERE activo = 'Si' ORDER BY producto";
2397
2398                $array = ia_sqlArrayIndx($sql);
2399                jsonFile($fileName, $array, JSON_PRETTY_PRINT);
2400                $jsonData = json_encode($array);
2401            }
2402            break;
2403        case 'producto_bodega':
2404            if(!$genera && file_exists($fileName))
2405                $jsonData = file_get_contents($fileName);
2406            if(strlen($jsonData) === 0)
2407            {
2408                $sql = "SELECT /*$sqlComment*/  pb.producto_bodega_id, 
2409                            pb.bodega_id, b.bodega, b.label, b.color as bodega_color, b.activo as bodega_activo,
2410                            pb.producto_general_id, pg.producto, pb.activo as producto_general_activo,
2411                            pb.color_id,  c.color, c.color_valor, c.color as color_activo
2412                    FROM producto_bodega pb JOIN bodega b on pb.bodega_id = b.bodega_id
2413                    JOIN producto_general pg ON pb.producto_general_id=pg.producto_general_id
2414                    JOIN color c ON c.color_id = pb.color_id
2415                    ";
2416                $array = ia_sqlArray($sql, 'producto_bodega_id');
2417                jsonFile($fileName, $array);
2418                $jsonData = json_encode($array);
2419            }
2420            break;
2421
2422        case 'pedido_china':
2423            if(!$genera && file_exists($fileName))
2424                $jsonData = file_get_contents($fileName);
2425            if(strlen($jsonData) === 0) {
2426                $sql = "
2427                    SELECT /*$sqlComment*/
2428                        CONCAT(pg.producto,  c.color) as id,
2429                        MIN(IF(p.eta IS NULL, 'S/F', p.eta)) as eta,
2430                        MIN(IF(p.bodega_eta IS NULL, 'S/F', p.bodega_eta)) as bodega_eta,
2431                        SUM(pi.quantity) as quantity, SUM(pi.rollos) as rollos,
2432                        GROUP_CONCAT(DISTINCT
2433                         CONCAT_WS(' ', FORMAT(pi.rollos, 0), 'rollos:',
2434                                   IF(p.estado IN ('Entregado', 'Cancelado'), p.estado,
2435                                      IF(p.bodega_eta IS NOT NULL,
2436                                         CONCAT('ETA ', DATE_FORMAT(p.bodega_eta, '%e/%b/%y')),
2437                                         IF(p.eta IS NOT NULL, CONCAT('ETA ', DATE_FORMAT(p.eta, '%e/%b/%y')), 'Producción')
2438                                          )
2439                                       )
2440                             )
2441                       ORDER BY p.estado DESC, p.bodega_eta, p.eta   ) as estado
2442                    FROM pedido p JOIN pedido_items pi on p.pedido_id = pi.pedido_id
2443                    JOIN producto_general pg on pi.producto_general_id = pg.producto_general_id
2444                    JOIN color c on pi.color_id = c.color_id
2445                    WHERE p.activo = 'Si' AND p.mostrar_en_ventas = 'Si'
2446                    GROUP BY 1";
2447                $array = ia_sqlArray($sql, 'id');
2448                jsonFile($fileName, $array);
2449                $jsonData = json_encode($array);
2450            }
2451            break;
2452        case 'pedido_china_nombre':
2453            if(!$genera && file_exists($fileName))
2454                $jsonData = file_get_contents($fileName);
2455            if(strlen($jsonData) === 0) {
2456                $sql = "
2457                    SELECT /*$sqlComment*/ 
2458                        CONCAT(pg.producto, '\t', c.color) as id,
2459                       MIN(IF(p.eta IS NULL, 'S/F', p.eta)) as eta,
2460                       MIN(IF(p.bodega_eta IS NULL, 'S/F', p.bodega_eta)) as bodega_eta,
2461                       SUM(pi.quantity) as quantity, SUM(pi.rollos) as rollos,
2462                        GROUP_CONCAT(DISTINCT
2463                         CONCAT_WS(' ', FORMAT(pi.rollos, 0), 'rollos:',
2464                                   IF(p.estado IN ('Entregado', 'Cancelado'), p.estado,
2465                                      IF(p.bodega_eta IS NOT NULL,
2466                                         CONCAT('ETA ', DATE_FORMAT(p.bodega_eta, '%e/%b/%y')),
2467                                         IF(p.eta IS NOT NULL, CONCAT('ETA ', DATE_FORMAT(p.eta, '%e/%b/%y')), 'Producción')
2468                                          )
2469                                       )
2470                             )
2471                      ORDER BY p.estado DESC, p.bodega_eta, p.eta SEPARATOR '<dt>' ) as estado
2472                    FROM pedido p JOIN pedido_items pi on p.pedido_id = pi.pedido_id
2473                                  JOIN producto_general pg on pi.producto_general_id = pg.producto_general_id
2474                                  JOIN color c on pi.color_id = c.color_id
2475                    WHERE p.activo = 'Si' AND p.mostrar_en_ventas = 'Si'
2476                    GROUP BY 1";
2477                $array = ia_sqlArray($sql, 'id');
2478                jsonFile($fileName, $array);
2479                $jsonData = json_encode($array);
2480            }
2481            break;
2482
2483        case 'unidades':
2484            if(!$genera && file_exists($fileName))
2485                $jsonData = file_get_contents($fileName);
2486            if(strlen($jsonData) === 0)
2487            {
2488                $nombre = 'unidades'; $fieldName = 'unidades_id'; $fieldDesc = 'unidad';
2489                $sql = "SELECT /*$sqlComment*/  $fieldName$fieldDesc$fieldName as real_data, $fieldDesc as label, $fieldName as value FROM $nombre WHERE vale = 'Active' ORDER BY unidad";
2490
2491                $array = ia_sqlArrayIndx($sql);
2492                jsonFile($fileName, $array, JSON_PRETTY_PRINT);
2493                $jsonData = json_encode($array);
2494            }
2495            break;
2496
2497
2498        case 'origen_bodega_bodega':
2499            if(!$genera && file_exists($fileName))
2500                $jsonData = file_get_contents($fileName);
2501            if(strlen($jsonData) === 0) {
2502                foreach(ia_sqlVector("SELECT /*$sqlComment*/  /*$method*/ bodega_id FROM bodega") as $bodega_id) {
2503                    $sql = "SELECT /*$sqlComment*/  /*$method*/
2504                            origen_bodega_id, clave, origen_bodega_id as real_data,
2505                            clave as label, origen_bodega_id as value, 
2506                            clave as origen,
2507                            origen_bodega_id as origen_id, es, empresa_id
2508                        FROM origen_bodega WHERE activo = 'Si' AND es <> 'CLIENTE'
2509                        AND EXISTS 
2510                            (SELECT 1 FROM origen_bodega_bodega bb 
2511                            WHERE bb.bodega_id='$bodega_id' AND bb.origen_bodega_id=origen_bodega.origen_bodega_id )
2512                        ORDER BY clave";
2513                    $array = ia_sqlArrayIndx($sql);
2514                    jsonFile($path.$nombre.$bodega_id.".".$ext, $array, JSON_PRETTY_PRINT);
2515                    if($extraId === $bodega_id)
2516                        $jsonData = json_encode($array);
2517                }
2518            }
2519            break;
2520        case 'origen_bodega':
2521            if(!$genera && file_exists($fileName))
2522                $jsonData = file_get_contents($fileName);
2523            if(strlen($jsonData) === 0)
2524            {
2525
2526                $sql = "SELECT /*$sqlComment*/  /*$method*/
2527                            origen_bodega_id, clave, origen_bodega_id as real_data,
2528                            origen_bodega_id as real_value,
2529                            clave as label, clave as value, 
2530                            clave as origen,
2531                            origen_bodega_id as origen_id, es, empresa_id
2532                        FROM origen_bodega WHERE activo = 'Si' AND es <> 'CLIENTE' 
2533                        AND vale_bodega_entrada = 'Si' AND vale_bodega_salida = 'Si'
2534                        ORDER BY clave";
2535
2536                $array = ia_sqlArrayIndx($sql);
2537                jsonFile($fileName, $array, JSON_PRETTY_PRINT);
2538                $jsonData = json_encode($array);
2539            }
2540            break;
2541
2542        case 'origen_bodega_grupo':
2543            if(!$genera && file_exists($fileName))
2544                $jsonData = file_get_contents($fileName);
2545            if(strlen($jsonData) === 0 || $jsonData === 'false')
2546            {
2547
2548                $sql = "SELECT /*$sqlComment*/  /*$method*/
2549                            origen_bodega_id, clave, origen_bodega_id as real_data,
2550                            clave as label, origen_bodega_id as value, 
2551                            clave as origen,
2552                            origen_bodega_id as origen_id, es, empresa_id
2553                        FROM origen_bodega 
2554                        WHERE activo = 'Si' AND es = 'BODEGA' AND vale_bodega_entrada = 'Si' AND vale_bodega_salida = 'Si'            
2555                        UNION ALL
2556                        SELECT DISTINCT
2557                            grupo, grupo, grupo as real_data,
2558                            grupo as label, grupo as value, 
2559                            grupo as origen,
2560                            grupo as origen_id, 'GRUPO', 0
2561                        FROM bodega
2562                        WHERE activo = 'Si' AND grupo <> ''
2563                        ORDER BY 2";
2564
2565                $array = ia_sqlArrayIndx($sql);
2566                jsonFile($fileName, $array, JSON_PRETTY_PRINT);
2567                $jsonData = json_encode($array);
2568            }
2569            break;
2570
2571        case 'origen_bodega_grupo_2':
2572            if(!$genera && file_exists($fileName))
2573                $jsonData = file_get_contents($fileName);
2574            if(strlen($jsonData) === 0 || $jsonData === 'false')
2575            {
2576
2577                $sql = "SELECT /*$sqlComment*/  /*$method*/
2578                            origen_bodega_id,
2579                            clave,
2580                            CONCAT(clave, ' <span style=\'font-size:10px;\'>(', IF(es = 'BODEGA', 'B', IF(es='TIENDA', 'T', 'GB') ), ')</span>') as label,
2581                            origen_bodega_id as real_data,
2582                            clave as value,
2583                            origen_bodega_id real_value,
2584                            clave as origen,
2585                            origen_bodega_id as origen_id, es, empresa_id, bodega_id
2586                        FROM origen_bodega 
2587                        WHERE activo = 'Si' AND es IN('BODEGA', 'GRUPO BODEGA') /*AND vale_bodega_entrada = 'Si' AND vale_bodega_salida = 'Si'*/ ORDER BY es DESC, clave";
2588
2589                $array = ia_sqlArrayIndx($sql);
2590                jsonFile($fileName, $array, JSON_PRETTY_PRINT);
2591                $jsonData = json_encode($array);
2592            }
2593            break;
2594
2595        case 'origen_bodega_carta_porte':
2596            if(!$genera && file_exists($fileName))
2597                $jsonData = file_get_contents($fileName);
2598            if(strlen($jsonData) === 0)
2599            {
2600                $sql = "SELECT /*$sqlComment*/  /*$method*/
2601                            ob.origen_bodega_id, ob.clave, ob.origen_bodega_id as real_data,
2602                            IF(ob.es = 'Cliente' OR ob.es = 'IMPORTACION', ob.clave, CONCAT(ob.clave, IF(e.empresa IS NOT NULL, CONCAT(' (', e.empresa, ')'), '') ) ) as label,
2603                            ob.origen_bodega_id as value,
2604                            ob.clave as origen,
2605                            ob.origen_bodega_id as origen_id, ob.es, ob.empresa_id, e.empresa
2606                        FROM origen_bodega ob
2607                        LEFT JOIN empresa e on ob.empresa_id = e.empresa_id
2608                        WHERE ob.activo = 'Si' AND ob.es <> 'CLIENTE' ORDER BY ob.clave";
2609
2610
2611
2612                $array = ia_sqlArrayIndx($sql);
2613                jsonFile($fileName, $array, JSON_PRETTY_PRINT);
2614                $jsonData = json_encode($array);
2615            }
2616            break;
2617        case 'cp_autotransporte':
2618            if(!$genera && file_exists($fileName))
2619                $jsonData = file_get_contents($fileName);
2620            if(strlen($jsonData) === 0)
2621            {
2622
2623                $sql = "SELECT /*$sqlComment*/  /*$method*/
2624                            autotransporte_id, PlacaVM, autotransporte_id as real_data,
2625                            PlacaVM as label, autotransporte_id as value, 
2626                           empresa_id, AnioModeloVM as anio_modelo, descripcion
2627                        FROM cp_autotransporte ORDER BY PlacaVM";
2628
2629                $sql = "SELECT /*$sqlComment*/ autotransporte_id, autotransporte_id as real_data, PlacaVM, autotransporte_id as real_value, PlacaVM as label, PlacaVM as value, empresa_id, AnioModeloVM as anio_modelo, descripcion FROM cp_autotransporte  ORDER BY PlacaVM";
2630
2631                $array = ia_sqlArrayIndx($sql);
2632                jsonFile($fileName, $array, JSON_PRETTY_PRINT);
2633                $jsonData = json_encode($array);
2634            }
2635            break;
2636
2637        case 'cp_autotransporte_scp':
2638            if(!$genera && file_exists($fileName))
2639                $jsonData = file_get_contents($fileName);
2640            if(strlen($jsonData) === 0)
2641            {
2642
2643                $sql = "SELECT /*$sqlComment*/ autotransporte_id, autotransporte_id as real_data, PlacaVM, autotransporte_id as real_value, CONCAT(PlacaVM, ' (', e.empresa, ')') as label, PlacaVM as value, cp.empresa_id, AnioModeloVM as anio_modelo, descripcion, e.empresa FROM cp_autotransporte cp LEFT JOIN empresa e ON cp.empresa_id = e.empresa_id ORDER BY PlacaVM";
2644
2645                $array = ia_sqlArrayIndx($sql);
2646                jsonFile($fileName, $array, JSON_PRETTY_PRINT);
2647                $jsonData = json_encode($array);
2648            }
2649            break;
2650
2651        case 'cp_figuratransporte':
2652            if(!$genera && file_exists($fileName))
2653                $jsonData = file_get_contents($fileName);
2654            if(strlen($jsonData) === 0)
2655            {
2656                $sql = "SELECT /*$sqlComment*/  /*$method*/
2657                            figuratransporte_id, NombreFigura, figuratransporte_id as real_data,
2658                            NombreFigura as label, figuratransporte_id as value, 
2659                           empresa_id, RFCFigura
2660                        FROM cp_figuratransporte ORDER BY NombreFigura";
2661
2662                $sql = "SELECT /*$sqlComment*/ figuratransporte_id, figuratransporte_id as real_data, NombreFigura, figuratransporte_id as real_value, NombreFigura as label, NombreFigura as value, empresa_id, RFCFigura FROM cp_figuratransporte ORDER BY NombreFigura";
2663
2664                $array = ia_sqlArrayIndx($sql);
2665                jsonFile($fileName, $array, JSON_PRETTY_PRINT);
2666                $jsonData = json_encode($array);
2667            }
2668            break;
2669
2670        case 'cp_figuratransporte_scp':
2671            if(!$genera && file_exists($fileName))
2672                $jsonData = file_get_contents($fileName);
2673            if(strlen($jsonData) === 0)
2674            {
2675                $sql = "SELECT /*$sqlComment*/  /*$method*/ figuratransporte_id, figuratransporte_id as real_data, NombreFigura, figuratransporte_id as real_value, CONCAT(NombreFigura, ' (', e.empresa, ')') as label, NombreFigura as value, cp.empresa_id, RFCFigura, e.empresa FROM cp_figuratransporte cp LEFT JOIN empresa e ON cp.empresa_id = e.empresa_id ORDER BY NombreFigura";
2676
2677                $array = ia_sqlArrayIndx($sql);
2678                jsonFile($fileName, $array, JSON_PRETTY_PRINT);
2679                $jsonData = json_encode($array);
2680            }
2681            break;
2682
2683        case 'cp_figuratransporte_br_nombre':
2684            if(!$genera && file_exists($fileName))
2685                $jsonData = file_get_contents($fileName);
2686            if(strlen($jsonData) === 0)
2687            {
2688                $sql = "SELECT /*$sqlComment*/  /*$method*/ NombreFigura, NombreFigura as real_data, NombreFigura as real_value, NombreFigura as label, NombreFigura as value FROM cp_figuratransporte cp GROUP BY NombreFigura ORDER BY NombreFigura";
2689
2690                $array = ia_sqlArrayIndx($sql);
2691                jsonFile($fileName, $array, JSON_PRETTY_PRINT);
2692                $jsonData = json_encode($array);
2693            }
2694            break;
2695
2696
2697        case 'bodega_ayudantes':
2698            if(!$genera && file_exists($fileName))
2699                $jsonData = file_get_contents($fileName);
2700            if(strlen($jsonData) === 0)
2701            {
2702                $sql = "SELECT /*$sqlComment*/ ayudante_id, ayudante_id as id, nombre, nombre as lbl, ayudante_id as real_data, ayudante_id as real_value, nombre as label FROM ayudantes WHERE es_encargado = 'No' ORDER BY orden, mostrar, nombre";
2703//                echo "<li>$sql";
2704//                $array = ia_sqlArray($sql,'nick');
2705                $array = ia_sqlArrayIndx($sql);
2706                jsonFile($fileName, $array, JSON_PRETTY_PRINT);
2707                $jsonData = json_encode($array);
2708            }
2709            break;
2710
2711        case 'bodega_ayudantes_donde':
2712            if(!$genera && file_exists($fileName))
2713                $jsonData = file_get_contents($fileName);
2714            if(strlen($jsonData) === 0) {
2715                $array =   ia_sqlKeyValue(
2716                "SELECT /*$sqlComment*/ a.ayudante_id, GROUP_CONCAT(DISTINCT ob.clave ORDER BY ob.clave SEPARATOR ', ')
2717                    FROM ayudantes a 
2718                        JOIN origen_bodega_ayudantes oba on a.ayudante_id = oba.ayudante_id
2719                        JOIN origen_bodega ob on oba.origen_bodega_id = ob.origen_bodega_id
2720                    WHERE oba.activo = 'Si'
2721                    GROUP BY 1"
2722                );
2723                jsonFile($fileName, $array, JSON_PRETTY_PRINT);
2724                $jsonData = json_encode($array);
2725            }
2726            break;
2727
2728        case 'bodega_encargados':
2729            if(!$genera && file_exists($fileName))
2730                $jsonData = file_get_contents($fileName);
2731            if(strlen($jsonData) === 0)
2732            {
2733                $sql = "SELECT /*$sqlComment*/ ayudante_id, ayudante_id as id, nombre, nombre as lbl, ayudante_id as real_data, ayudante_id as real_value, nombre as label FROM ayudantes WHERE es_encargado = 'Si' ORDER BY orden, mostrar, nombre";
2734//                echo "<li>$sql";
2735//                $array = ia_sqlArray($sql,'nick');
2736                $array = ia_sqlArrayIndx($sql);
2737                jsonFile($fileName, $array, JSON_PRETTY_PRINT);
2738                $jsonData = json_encode($array);
2739            }
2740            break;
2741
2742        // fin catalogos de bodega
2743
2744        case 'iac_usr_nick':
2745            if(!$genera && file_exists($fileName))
2746                $jsonData = file_get_contents($fileName);
2747            if(strlen($jsonData) === 0)
2748            {
2749                $sql = "SELECT /*$sqlComment*/  nick, nick as real_data, nick as label, nick as value FROM iac_usr WHERE vale='Active' ORDER BY nick";
2750//                echo "<li>$sql";
2751                $array = ia_sqlArray($sql,'nick');
2752                //$array = ia_sqlArrayIndx($sql);
2753                jsonFile($fileName, $array);
2754                $jsonData = json_encode($array);
2755            }
2756            break;
2757
2758        case 'iac_usr_nombre':
2759            if(!$genera && file_exists($fileName))
2760                $jsonData = file_get_contents($fileName);
2761            if(strlen($jsonData) === 0)
2762            {
2763                $sql = "SELECT /*$sqlComment*/  nombre, nombre as real_data, nombre as label, nombre as value FROM iac_usr WHERE vale='Active' ORDER BY nombre";
2764//                echo "<li>$sql";
2765                $array = ia_sqlArray($sql,'nombre');
2766                //$array = ia_sqlArrayIndx($sql);
2767                jsonFile($fileName, $array);
2768                $jsonData = json_encode($array);
2769            }
2770            break;
2771
2772        case 'iac_usr_plantillatienda_id':
2773            if(!$genera && file_exists($fileName))
2774                $jsonData = file_get_contents($fileName);
2775            if(strlen($jsonData) === 0)
2776            {
2777                $sql =
2778                    "SELECT /*$sqlComment*/  i.plantillatienda_id, i.plantillatienda_id as real_data, 
2779                        p.plantilla as label, p.plantilla as value 
2780                        FROM iac_usr i LEFT JOIN plantillatienda p ON i.plantillatienda_id = p.plantillatienda_id 
2781                        ORDER BY p.plantilla"; // GROUP BY i.plantillatienda_id
2782//                echo "<li>$sql";
2783                $array = ia_sqlArray($sql,'plantillatienda_id');
2784                //$array = ia_sqlArrayIndx($sql);
2785                jsonFile($fileName, $array);
2786                $jsonData = json_encode($array);
2787            }
2788            break;
2789        case 'iac_usr_plantilla_id':
2790            if(!$genera && file_exists($fileName))
2791                $jsonData = file_get_contents($fileName);
2792            if(strlen($jsonData) === 0)
2793            {
2794                $sql = "SELECT /*$sqlComment*/  i.plantilla_id, i.plantilla_id as real_data, p.plantilla as label, p.plantilla as value 
2795                        FROM iac_usr i LEFT JOIN plantilla p ON i.plantilla_id = p.plantilla_id  ORDER BY p.plantilla_id"; // GROUP BY i.plantilla_id
2796//                echo "<li>$sql";
2797                $array = ia_sqlArray($sql,'plantilla_id');
2798                //$array = ia_sqlArrayIndx($sql);
2799                jsonFile($fileName, $array);
2800                $jsonData = json_encode($array);
2801            }
2802            break;
2803        case 'iac_usr_cuentat_preferida_id':
2804            if(!$genera && file_exists($fileName))
2805                $jsonData = file_get_contents($fileName);
2806            if(strlen($jsonData) === 0)
2807            {
2808                $sql = "SELECT /*$sqlComment*/  i.cuentat_preferida_id, i.cuentat_preferida_id as real_data, p.usuario as label, p.usuario as value FROM iac_usr i LEFT JOIN cuentat p ON i.cuentat_preferida_id = p.cuentaT_id WHERE i.cuentat_preferida_id is NOT NULL GROUP BY i.cuentat_preferida_id ORDER BY i.cuentat_preferida_id";
2809//                echo "<li>$sql";
2810                $array = ia_sqlArray($sql,'cuentat_preferida_id');
2811                //$array = ia_sqlArrayIndx($sql);
2812                jsonFile($fileName, $array);
2813                $jsonData = json_encode($array);
2814            }
2815            break;
2816
2817        case 'movimiento_divisa_warning_status':
2818            if(!$genera && file_exists($fileName))
2819                $jsonData = file_get_contents($fileName);
2820            if(strlen($jsonData) === 0)
2821            {
2822                $array = arrayTipoWarning(true);
2823                jsonFile($fileName, $array);
2824                $jsonData = json_encode($array);
2825            }
2826            break;
2827
2828        case 'movimiento_divisa_warning_tipo':
2829            if(!$genera && file_exists($fileName))
2830                $jsonData = file_get_contents($fileName);
2831            if(strlen($jsonData) === 0)
2832            {
2833                $array = array_movimiento_divisa_warning_tipo(true);
2834                jsonFile($fileName, $array);
2835                $jsonData = json_encode($array);
2836            }
2837            break;
2838
2839        case 'movimiento_divisa_alta_por':
2840            if(!$genera && file_exists($fileName))
2841                $jsonData = file_get_contents($fileName);
2842            if(strlen($jsonData) === 0)
2843            {
2844                $sql = "SELECT /*$sqlComment*/  alta_por, alta_por as real_data, alta_por as label, alta_por as value FROM movimiento_divisa GROUP BY alta_por ORDER BY alta_por";
2845                $array = ia_sqlArray($sql,'alta_por');
2846                //$array = ia_sqlArrayIndx($sql);
2847                jsonFile($fileName, $array);
2848                $jsonData = json_encode($array);
2849            }
2850            break;
2851
2852        case 'cpTipoFigura':
2853            if(!$genera && file_exists($fileName))
2854                $jsonData = file_get_contents($fileName);
2855            if(strlen($jsonData) === 0)
2856            {
2857                $array = arrayTipoFigura(true);
2858
2859
2860                jsonFile($fileName, $array);
2861                $jsonData = json_encode($array);
2862            }
2863            break;
2864
2865        case 'nota_bodega_ultimo_cambio_por':
2866            if(!$genera && file_exists($fileName))
2867                $jsonData = file_get_contents($fileName);
2868            if(strlen($jsonData) === 0)
2869            {
2870                $sql = "SELECT  /*$sqlComment*/ DISTINCT ultimo_cambio_por, ultimo_cambio_por as real_data,
2871                           ultimo_cambio_por as label, ultimo_cambio_por as value 
2872                            FROM nota_bodega ORDER BY ultimo_cambio_por";
2873                $array = ia_sqlArray($sql,'ultimo_cambio_por');
2874                jsonFile($fileName, $array);
2875                $jsonData = json_encode($array);
2876            }
2877            break;
2878        case 'nota_bodega_alta_por':
2879            if(!$genera && file_exists($fileName))
2880                $jsonData = file_get_contents($fileName);
2881            if(strlen($jsonData) === 0)
2882            {
2883                $sql = "SELECT /*$sqlComment*/  alta_por, alta_por as real_data, alta_por as label, alta_por as value FROM nota_bodega WHERE alta_por IN (SELECT nick FROM iac_usr WHERE vale = 'active') GROUP BY alta_por ORDER BY alta_por";
2884                $array = ia_sqlArray($sql,'alta_por');
2885                //$array = ia_sqlArrayIndx($sql);
2886                jsonFile($fileName, $array);
2887                $jsonData = json_encode($array);
2888            }
2889            break;
2890
2891        case 'tipo_generacion_cfdi':
2892            if(!$genera && file_exists($fileName))
2893                $jsonData = file_get_contents($fileName);
2894            if(strlen($jsonData) === 0)
2895            {
2896                $array = array(
2897                    array('label'=>'INMEDIATAMENTE', 'value'=> 'inmediato', 'real_data'=> 'inmediato'),
2898                    array('label'=>'DIA SIGUIENTE', 'value'=> 'dia_siguiente', 'real_data'=> 'dia_siguiente'),
2899                    array('label'=>'NO TIMBRAR', 'value'=> 'sin_timbrar', 'real_data'=> 'sin_timbrar'),
2900                );
2901                jsonFile($fileName, $array);
2902                $jsonData = json_encode($array);
2903            }
2904            break;
2905        case 'busca_bodega_all':
2906            if(!$genera && file_exists($fileName))
2907                $jsonData = file_get_contents($fileName);
2908            if(strlen($jsonData) === 0) {
2909                $sql =
2910                "SELECT /*$method*/ bodega FROM bodega WHERE activo='Si'
2911                UNION DISTINCT
2912                SELECT /*$method*/ DISTINCT grupo FROM bodega WHERE grupo<>'' AND activo='Si'
2913                UNION DISTINCT
2914                SELECT /*$method*/ DISTINCT clave FROM origen_bodega WHERE es IN ('tienda','correccion','importacion') AND activo='Si'
2915                UNION DISTINCT
2916                SELECT producto FROM producto_general WHERE activo='Si'
2917                UNION DISTINCT
2918                SELECT color FROM color WHERE activo='Si'
2919                UNION DISTINCT
2920                select nombre from ayudantes where mostrar='Si'
2921                UNION DISTINCT      
2922                select nombre from cliente where cliente AND vale='Active' AND interno = 'No'      
2923                UNION DISTINCT
2924                select nick from iac_usr WHERE vale='Active'
2925                UNION DISTINCT
2926                select PlacaVM from cp_autotransporte WHERE activo='Si'
2927                UNION DISTINCT
2928                select NombreFigura from cp_figuratransporte WHERE activo='Si'
2929                ORDER BY 1";
2930                $dl = [];
2931                foreach(ia_sqlVector($sql) as $d)
2932                    $dl[] = "<option value='" . ia_htmlentities($d) . "'>";
2933                $jsonData = implode('', $dl);
2934                file_put_contents(__DIR__ . '/../../backoffice/json/busca_bodega_all.html', $jsonData, LOCK_EX );
2935            }
2936            break;
2937        case 'bodega_producto_color':
2938            if(!$genera && file_exists($fileName))
2939                $jsonData = file_get_contents($fileName);
2940            if(strlen($jsonData) === 0) {
2941                $sql =
2942                    "SELECT /*$method*/ bodega FROM bodega WHERE activo='Si'
2943                UNION DISTINCT
2944                SELECT producto FROM producto_general WHERE activo='Si'
2945                UNION DISTINCT
2946                SELECT color FROM color WHERE activo='Si'
2947                ORDER BY 1";
2948                $dl = [];
2949                foreach(ia_sqlVector($sql) as $d)
2950                    $dl[] = "<option value='" . ia_htmlentities($d) . "'>";
2951                $jsonData = implode('', $dl);
2952                file_put_contents(__DIR__ . '/../../backoffice/json/bodega_producto_color.html', $jsonData, LOCK_EX );
2953            }
2954            break;
2955        case 'bodegas_tiendas_por_usuario':
2956
2957            $usuario_id_get = $extraId;
2958            // $wheres = ["t.vale = 'Active'"];
2959            $wheres = [];
2960            if (!empty($usuario_id_get)) {
2961                $wheres[] = "iac_usr_id = $usuario_id_get";
2962            }
2963            $where = '';
2964            if (!empty($wheres)) {
2965                $where = "WHERE ".implode(" AND ", $wheres);
2966            }
2967            $query = "SELECT
2968                        pt.tienda_id, pt.tienda_id real_data, ob.clave as tienda, pt.tienda_id real_value, ob.clave, ob.clave label, ob.clave value, pt.iac_usr_id
2969                    FROM permiso_bodega_consulta_salida_tienda pt
2970                    JOIN origen_bodega ob using(origen_bodega_id)
2971                    $where";
2972
2973            $tiendas = ia_sqlArrayIndx($query);
2974            $usuario_tiendas = objetivisa_($tiendas, 'iac_usr_id');
2975
2976            $jsonData = ['tiendas' => [], 'bodegas' => []];
2977
2978            $files = [];
2979            $tiendas_usuario = [];
2980            foreach ($usuario_tiendas as $usuario_id => $tiendas) {
2981                $tiendas_usuario = $tiendas;
2982                $fileName = $path.'tienda_'.$usuario_id.".".$ext;
2983                jsonFile($fileName, $tiendas, JSON_PRETTY_PRINT);
2984                $files[] = $fileName;
2985            }
2986            if (!empty($usuario_id_get)) {
2987                $jsonData['tiendas'] = json_encode($tiendas_usuario);
2988            }
2989
2990
2991            $wheres = ["iac_usr_id <> 1", "vale = 'Active'"];
2992            if (!empty($usuario_id_get)) {
2993                $wheres[] = "iac_usr_id = $usuario_id_get";
2994            }
2995            $where = implode(" AND ", $wheres);
2996            $users_actives = ia_sqlArrayIndx("SELECT iac_usr_id, nick FROM iac_usr WHERE $where");
2997            $bodegas_usuario = [];
2998            foreach ($users_actives as $i => $user) {
2999                $permisosBodega = new PermisosBodega($user['iac_usr_id'] ?? $_SESSION['usuario_id']);
3000                $bodegas_con_permiso = $permisosBodega->bodegasPuedeConsultarMovimientos();
3001                if (empty($bodegas_con_permiso))
3002                    continue;
3003                $bodegas_usuario = [];
3004                foreach ($bodegas_con_permiso as $bodega_id => $bodega) {
3005                    $bodegas_usuario[] = [
3006                        'bodega_id' => $bodega_id,
3007                        'bodega' => $bodega['bodega'],
3008                        'color' => $bodega['color'],
3009                        'grupo' => $bodega['grupo'],
3010                        'real_data' => $bodega_id,
3011                        'real_value' => $bodega_id,
3012                        'label' => $bodega['bodega'],
3013                        'value' => $bodega['bodega'],
3014                    ];
3015                }
3016                $fileName = $path.'bodega_'.$user['iac_usr_id'].".".$ext;
3017                jsonFile($fileName, $bodegas_usuario, JSON_PRETTY_PRINT);
3018                $files[] = $fileName;
3019            }
3020            if (!empty($usuario_id_get)) {
3021                $jsonData['bodegas'] = json_encode($bodegas_usuario);
3022                return $jsonData;
3023            }
3024
3025            if ($printFiles)
3026                return $files;
3027            break;
3028
3029        case 'bodega_grupo_verificador_id':
3030
3031            if(!$genera && file_exists($fileName))
3032                $jsonData = file_get_contents($fileName);
3033            if(strlen($jsonData) === 0)
3034            {
3035                $nombre = 'bodega_grupo_verificador'; $fieldName = 'bodega_grupo_verificador_id'; $fieldDesc = 'grupo_verficiador';
3036                $sql = "SELECT /*$sqlComment*/  $fieldName$fieldDesc$fieldName as real_data, $fieldDesc as label, $fieldName as value FROM $nombre ORDER BY 2";
3037
3038                //echo $sql;
3039
3040
3041                $array = ia_sqlArrayIndx($sql);
3042                jsonFile($fileName, $array);
3043                $jsonData = json_encode($array);
3044            }
3045            break;
3046
3047        case 'bodega_tipo_cash_nota':
3048            if(!$genera && file_exists($fileName))
3049                $jsonData = file_get_contents($fileName);
3050            if(strlen($jsonData) === 0)
3051            {
3052                $array = array_bodega_tipo_cash_nota(true);
3053                jsonFile($fileName, $array);
3054                $jsonData = json_encode($array);
3055            }
3056            break;
3057
3058    }
3059    return $jsonData;
3060}
3061
3062function catalogosUnique() {
3063    $catalotos = catalogosDefault();
3064    $unicos = array_keys($catalotos);
3065    foreach($catalotos as $c)
3066        if(is_array($c))
3067            $unicos = array_merge($unicos, $c);
3068    return array_unique($unicos);
3069}
3070
3071function catalogosDefault()
3072{
3073    return array(
3074        'doctos'=> array('doctos_cliente','doctos_cliente_id','doctos_tienda','doctos_moneda','doctos_cuentat_deliveredto_id','doctos_origen_cuentat_id','doctos_alta_por','doctos_origen','doctos_ultimo_movimiento','clientes_saldos','doctos_cheque_dd_tipo'),
3075        'tienda'=> array('tienda','doctos_tienda','links_tienda_id_activo','cheque_tienda','pagare_tienda','links_cuentat_id_activo','origen_bodega','origen_bodega_bodega', 'origen_bodega_carta_porte'),
3076        'empresa'=> array('empresa','banco_cuenta','acuentas_banco_cuenta_id','busca_bodega_all','nombre_empresa'),
3077        'moneda'=> array('moneda','moneda_id'),
3078        'categoria'=> array('categoria'),
3079        'cliente'=> array('cliente_inactivo','cliente_activo','cliente','clientes_saldos','clientes_saldos_nombre','cliente_tienda_id','cheque_cliente_id','compra_cliente_id','pagare_cliente_id','acuentas_cliente_id','cheque_dd_cliente_id','busca_bodega_all'),
3080        'banco'=> array('banco'),
3081        'banco_mov_tipo'=> array('banco_mov_tipo'),
3082        'banco_a_banco' => array('banco_a_banco_alta_por','banco_a_banco_bid_origen','banco_a_banco_bid_destino'),
3083        'banco_cuenta'=> array('banco_cuenta','acuentas_banco_cuenta_id'),
3084        'reporte_grid'=> array('reporte_grid'),
3085        'links'=> array('links_cuentat_id_activo','links_tienda_id_activo','links_banco_cuenta_id_activo','links_tipo_cash_nota_movimiento',
3086            'links_cuentat_tipo_mov_id_activo','links_tipo_factura','links_empresa_id_activo','links_cuentat_id_activo_ba','links_alta_por','links_origen','links_borrados_ultimo_movimiento'),
3087        'acuentas'=> array('acuentas_cliente','acuentas_alta_por','acuentas_cliente_id','acuentas_origen','acuentas_cuentat_id','acuentas_metodo_pago_id','acuentas_banco_cuenta_id'),
3088        'vale' => array('vale_cliente_activo_toolbar','vale_cliente_activo','vale_alta_por','vale_cuentaT_id','vale_cliente','vale_dinero_en_cuentaT_id','clientes_saldos','clientes_saldos_nombre'),
3089        'cheque' => array('cheque_cliente_id','cheque_tienda','cheque_cuentat_deliveredto_id','cheque_origen_cuentat_id','cheque_alta_por','clientes_internos','clientes_saldos','clientes_saldos_nombre','cheque_dd_tipo','cheque_dd_cliente_id'),
3090        'compra' => array('compra_cliente_id','compra_tienda','compra_cuentat_deliveredto_id','compra_origen_cuentat_id','compra_alta_por','clientes_internos','clientes_saldos','clientes_saldos_nombre','compra_dd_tipo'),
3091        'pagare' => array('pagare_cliente_id','pagare_tienda','pagare_cuentat_deliveredto_id','pagare_origen_cuentat_id','pagare_alta_por','clientes_saldos','clientes_saldos_nombre'),
3092        'cuentat_gasto' => array('cuentat_gasto_cuentat_id_activo','cuentat_gasto_plantilla','cuentat_gasto_alta_por'),
3093        'cuentat_ingreso' => array('cuentat_ingreso_cuentat_id_activo','cuentat_ingreso_alta_por','cuentat_ingreso_tienda_id_activo','cuentat_ingreso_cuentat_id_xtienda_activo','cuentat_ingreso_alta_por_xtienda','cuentat_ingreso_tienda_id_xtienda_activo'),
3094        'cuentat_mov' => array('cuentat_mov_cuentaT_id','cuentat_mov_alta_por','app_origen','cuentat_mov_tienda_id'),
3095        'cuentat_transfer' => array('cuentat_transfer_envia_cuentaT_id','cuentat_transfer_recibe_cuentaT_id','cuentat_transfer_envia_usuario_id','cuentat_transfer_recibe_usuario_id'),
3096        'tc' => array('tc'),
3097        'link_vale' => array('link_vale'),
3098        'cuentat' => array('cuentaT_id'),
3099        'cfdi33' => array('usocfdi','metodopago','formapago'),
3100        'depositar_en' => array('depositar_en'),
3101        'es_withdrawal_deposit' => array('es_withdrawal_deposit'),
3102        'fiduciario_reembolso' => array('fiduciario_reembolso_banco_cuenta_id_activo','fiduciario_reembolso_alta_por'),
3103        'fiduciario' => array('fiduciario_banco_cuenta_id_activo'),
3104        'inversion' => array('inversion_banco_cuenta_id_empresa_activo','inversion_banco_cuenta_id_privada_activo'),
3105        'inversion_reembolso' => array('inversion_reembolso_banco_cuenta_id_empresa_activo','inversion_reembolso_alta_por','inversion_reembolso_banco_cuenta_id_privada_activo'),
3106        'cuentat_a_banco_tc' => array('cuentat_a_banco_tc_cuentaT_id_activo','cuentat_a_banco_tc_banco_cuenta_id_activo','cuentat_a_banco_tc_alta_por'),
3107        'kv_record_log' => array('kv_accion_log_id','collection_id'),
3108        'movimiento_divisa' => array('movimiento_divisa_warning_status','movimiento_divisa_warning_tipo','movimiento_divisa_alta_por'),
3109        'bodega' => ['bodega', 'bodega_keyValue', 'bodega_keyValue_all',"bodegas_y_grupos", 'origen_bodega', 'origen_bodega_grupo','origen_bodega_bodega', 'grupo', 'origen_bodega_carta_porte','bodega_producto_color', 'bodega_labels', 'bodega_todas', 'bodega_labels_todas','busca_bodega_all'],
3110        'bodegas_y_grupos' => ['bodegas_y_grupos','bodega_keyValue'],
3111        'grupo' => ['grupo'],
3112
3113        'color' => ['color', 'color_keyValue', 'color_keyValue_all', 'color_alfabetico', 'color_alfabetico_desc', 'color_busca_por_nombre', 'bodega_producto_color','busca_bodega_all'],
3114        'color_alfabetico' => ['color', 'color_keyValue','color_alfabetico', 'color_alfabetico_desc', 'color_busca_por_nombre'],
3115        'color_alfabetico_desc' => ['color', 'color_keyValue','color_alfabetico', 'color_alfabetico_desc', 'color_busca_por_nombre'],
3116        'color_busca_por_nombre' => ['color_busca_por_nombre', 'color_keyValue', 'color', 'color_alfabetico', 'color_alfabetico_desc'],
3117
3118
3119        'producto_general' => array('producto_general','producto_general_keyValue','producto_general_keyValue_all','producto_general_info','producto_general_por_nombre','bodega_producto_color', 'producto_general_cp','busca_bodega_all'),
3120        'producto_general_por_nombre' => array('producto_general','producto_general_keyValue','producto_general_info','producto_general_por_nombre', 'producto_general_cp','busca_bodega_all'),
3121
3122
3123        'producto_bodega' => array('producto_bodega'),
3124        'producto_color' => array('producto_color', 'producto_color_nombre'),
3125        'producto_color_nombre' => array('producto_color', 'producto_color_nombre'),
3126        'pedido_china' => ['pedido_china', 'pedido_china_nombre'],
3127        'unidades' => array('unidades'),
3128        'origen_bodega' => array('origen_bodega', 'origen_bodega_bodega_grupo_keyValue_all',  'origen_bodega_grupo' ,'origen_bodega_bodega', 'origen_bodega_carta_porte', 'origen_bodega_grupo_2', 'busca_bodega_all'),
3129        'origen_bodega_grupo' => array( "origen_bodega_grupo", 'origen_bodega_bodega_grupo_keyValue_all', 'origen_bodega_grupo_2'  ),
3130        'origen_bodega_grupo_2' => array( "origen_bodega_grupo_2", 'origen_bodega_bodega_grupo_keyValue_all',  ),
3131        'origen_bodega_bodega' => array('origen_bodega_bodega', 'origen_bodega_carta_porte', 'origen_bodega_bodega_grupo_keyValue_all',),
3132        'iac_usr' => array('iac_usr_nick','iac_usr_nombre','iac_usr_cuentat_preferida_id','iac_usr_plantillatienda_id','iac_usr_plantilla_id','busca_bodega_all'),
3133        'carta_porte' => array('cpTipoFigura', 'cp_figuratransporte', 'cp_autotransporte'),
3134        'cp_figuratransporte' => array('cp_figuratransporte', 'cp_figuratransporte_scp', 'cp_figuratransporte_scp','busca_bodega_all'),
3135        'cp_autotransporte' => array('cp_autotransporte','cp_autotransporte_scp','busca_bodega_all'),
3136        'origen_bodega_carta_porte' => array('origen_bodega_carta_porte'),
3137        'nota_alta' => array('nota_bodega_alta_por', 'nota_bodega_ultimo_cambio_por'),
3138        'nota_update' => array('nota_bodega_ultimo_cambio_por'),
3139        'tipo_generacion_cfdi' => array('tipo_generacion_cfdi'),
3140        'bodega_producto_color' => array('bodega_producto_color','busca_bodega_all'),
3141        'producto_general_cp' => ['producto_general_cp'],
3142
3143        'usuario_keyValue' => ['usuario_keyValue'],
3144
3145        'bodegas_tiendas_por_usuario' => ['bodegas_tiendas_por_usuario'],
3146        'bodega_grupo_verificador' => ['bodega_grupo_verificador_id'],
3147        'bodega_tipo_cash_nota' => ['bodega_tipo_cash_nota'],
3148        'bodega_labels' => ['bodega_labels', 'bodega_labels_todas'],
3149        'bodega_ayudantes' => ['bodega_ayudantes','bodega_encargados','bodega_ayudantes_donde','busca_bodega_all'],
3150        'bodega_encargados' => ['bodega_ayudantes','bodega_encargados','bodega_ayudantes_donde','busca_bodega_all'],
3151        'busca_bodega_all' => ['busca_bodega_all'],
3152    );
3153}
3154
3155function generaCatalogos($nombre='QWERTY')
3156{
3157    global $arr_catalogos;
3158    global $gWebDir;
3159
3160    //echo "<pre>".print_r($nombre,true)."</pre>";
3161
3162    $pathCat = "C:\\wamp\\www\\$gWebDir\\backoffice\\json\\";
3163    //echo "<li>".$pathCat;
3164    valida_carpetas($pathCat, $gWebDir);
3165
3166    if(empty($nombre) || $nombre==='QWERTY' || is_array($nombre) ||
3167        (is_array($nombre) && (array_key_exists(0, $nombre) && $nombre[0]==='QWERTY'))
3168    )
3169        $nombre = $arr_catalogos;
3170
3171    //echo "<pre>".print_r($nombre,true)."</pre>";
3172
3173    if(!is_array($nombre))
3174        $nombre = array($nombre=>$arr_catalogos[$nombre]);
3175    else if($nombre != $arr_catalogos)
3176    {
3177        $tmp=array();
3178        foreach($nombre as $v)
3179            $tmp[$v] = $arr_catalogos[$v];
3180        $nombre=$tmp;
3181    }
3182    $done=[];
3183    if(is_array($nombre) && !empty($nombre))
3184        foreach($nombre as $v)
3185            if(is_array($v) && !empty($v))
3186                foreach($v as $w)
3187                    if( !array_key_exists($w, $done)) {
3188                        $done[$w] = true;
3189                        obtenCatalogo($w, true);
3190                    }
3191    global $gDebugging;
3192    if($gDebugging) {
3193        $guarde = array_keys($done);
3194        asort($guarde);
3195        //ia_errores_a_dime("catalogos guardados: " . implode(", ", $guarde));
3196    }
3197}
3198
3199function obtenCatalogos(array $catalogos = [])
3200{
3201    $ret = [];
3202    foreach ($catalogos as $catalogo) {
3203        if(!array_key_exists($catalogo, $ret))
3204            $ret[$catalogo] = obtenCatalogo($catalogo, true);
3205    }
3206    return $ret;
3207}
3208
3209function obtenClientesConPermiso(
3210    $fileName, $genera,
3211    $nombre, $fieldName, $fieldDesc, $vsTable, $vsFieldID, $vsAnd,
3212    $para, $vsPaid
3213) {
3214    $sqlComment = __FUNCTION__;
3215    $jsonData = '';
3216    if(usuarioTipoRony()) {
3217        if(!$genera && file_exists($fileName))
3218            $jsonData = file_get_contents($fileName);
3219        if(empty($jsonData) || $jsonData === 'false') {
3220            $where_exists = " WHERE EXISTS (SELECT 1 FROM $vsTable WHERE $nombre.$fieldName=$vsTable.$vsFieldID $vsAnd $vsPaid)";
3221            if(empty($vsPaid))
3222                $where_exists = "";
3223            $sql = "SELECT /*$sqlComment*/  $fieldName$fieldDesc$fieldName as real_data, $fieldDesc as label, $fieldName as value FROM $nombre $where_exists ORDER BY 2";
3224//            echo "<li>$sql";
3225            $array = ia_sqlArrayIndx($sql);
3226            jsonFile($fileName, $array);
3227            $jsonData = json_encode($array);
3228         }
3229        return $jsonData;
3230
3231    }
3232
3233    $usuario_id = strit($_SESSION['usuario_id']);
3234    switch($para) {
3235        case 'cheque':
3236            $tiendas = ia_sqlVector(
3237                "SELECT pc.tienda_id
3238                FROM iac_usr u
3239                    JOIN plantillatienda pt on u.plantillatienda_id = pt.plantillatienda_id
3240                    JOIN plantilla_cobranza pc on pt.plantillatienda_id = pc.plantillatienda_id
3241                WHERE u.iac_usr_id = $usuario_id AND pc.permiso_cheque<>'Nada'"
3242            );
3243            break;
3244        case 'pagare':
3245            $tiendas = ia_sqlVector(
3246                "SELECT pc.tienda_id
3247                FROM iac_usr u
3248                    JOIN plantillatienda pt on u.plantillatienda_id = pt.plantillatienda_id
3249                    JOIN plantilla_cobranza pc on pt.plantillatienda_id = pc.plantillatienda_id
3250                WHERE u.iac_usr_id = $usuario_id AND pc.permiso_pagare<>'Nada'"
3251            );
3252            break;
3253        case 'vale':
3254            $tiendas = ia_sqlVector(
3255                "SELECT pc.tienda_id
3256                FROM iac_usr u
3257                    JOIN plantillatienda pt on u.plantillatienda_id = pt.plantillatienda_id
3258                    JOIN plantilla_cobranza pc on pt.plantillatienda_id = pc.plantillatienda_id
3259                WHERE u.iac_usr_id = $usuario_id AND pc.permiso_cobranza<>'Nada'"
3260            );
3261            break;
3262        case 'docto':
3263            $tiendas = ia_sqlVector(
3264                "SELECT pc.tienda_id
3265                FROM iac_usr u
3266                    JOIN plantillatienda pt on u.plantillatienda_id = pt.plantillatienda_id
3267                    JOIN plantilla_cobranza pc on pt.plantillatienda_id = pc.plantillatienda_id
3268                WHERE u.iac_usr_id = $usuario_id AND (pc.permiso_cheque<>'Nada' OR pc.permiso_pagare<>'Nada' OR pc.permiso_cobranza<>'Nada')"
3269            );
3270            break;
3271        default:
3272            $tiendas = [];
3273            $tiendas = ia_sqlVector(
3274                "SELECT pc.tienda_id
3275                FROM iac_usr u
3276                    JOIN plantillatienda pt on u.plantillatienda_id = pt.plantillatienda_id
3277                    JOIN plantilla_cobranza pc on pt.plantillatienda_id = pc.plantillatienda_id
3278                WHERE u.iac_usr_id = $usuario_id AND (pc.permiso_cheque<>'Nada' OR pc.permiso_pagare<>'Nada' OR pc.permiso_cobranza<>'Nada')"
3279            );
3280    }
3281    $in = "('\t'";
3282    foreach($tiendas as $tienda_id)
3283        $in .= "," . strit($tienda_id);
3284    $in .= ")";
3285
3286    $where_exists = " WHERE EXISTS (SELECT 1 FROM $vsTable WHERE $nombre.$fieldName=$vsTable.$vsFieldID $vsAnd $vsPaid)";
3287    if(empty($vsPaid))
3288        $where_exists = "";
3289
3290    $sql = "SELECT /*$sqlComment*/ DISTINCT $fieldName$fieldDesc$fieldName as real_data, $fieldDesc as label, $fieldName as value 
3291            FROM $nombre 
3292               JOIN JSON_TABLE( $nombre.origen_bodega, '$[*]' 
3293                   COLUMNS(tienda_id INT PATH '$.tienda_id')
3294            ) as oriTda ON oriTda.tienda_id IN $in OR $nombre.tienda_id IN $in
3295            $where_exists 
3296            ORDER BY 2";
3297    //echo "<li>".$sql;
3298    return json_encode(ia_sqlArrayIndx($sql));
3299}