Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 94 |
|
0.00% |
0 / 4 |
CRAP | n/a |
0 / 0 |
|
| acuentasMovs | |
0.00% |
0 / 50 |
|
0.00% |
0 / 1 |
210 | |||
| obtenSQLACuentasVale | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
6 | |||
| obtenSQLACuentas | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| actualizaSaldosACuentas | |
0.00% |
0 / 39 |
|
0.00% |
0 / 1 |
182 | |||
| 1 | <?php |
| 2 | |
| 3 | function acuentasMovs($andWhere='',$orderby='',&$sumasGridServer=array(),&$pk_field="") |
| 4 | { |
| 5 | |
| 6 | global $gIAsql, $gIAParametros; |
| 7 | |
| 8 | $arrACuentas = array(); |
| 9 | |
| 10 | $keys2Replace = array("{wherecheque_pago}","{wherepagare_pago}","{wherecheque_pago_log}","{wherepagare_pago_log}" |
| 11 | ,"{wherevale}","{wherevale_pago}","{wherevale_pago_log}"); //VALE_PAGO_MULTIPLE |
| 12 | |
| 13 | $keys2rLimit = array("{limitcheque_pago}","{limitpagare_pago}","{limitcheque_pago_log}","{limitpagare_pago_log}" |
| 14 | ,"{limitvale}","{limitvale_pago}","{limitvale_pago_log}"); //VALE_PAGO_MULTIPLE |
| 15 | |
| 16 | $keys2rOrder = array("{ordercheque_pago}","{orderpagare_pago}","{ordercheque_pago_log}","{orderpagare_pago_log}" |
| 17 | ,"{ordervale}","{ordervale_pago}","{ordervale_pago_log}"); //VALE_PAGO_MULTIPLE |
| 18 | |
| 19 | $arrLimit = array(); |
| 20 | $arrOrder = array(); |
| 21 | |
| 22 | $pk_field = "doc_pago_id"; |
| 23 | //$bleh = ''; |
| 24 | foreach($andWhere as $k=>&$v) |
| 25 | { |
| 26 | $v = str_replace("AND )", ")", $v); |
| 27 | |
| 28 | if($k == '{wherevale}') |
| 29 | { |
| 30 | //$bleh.="\r\n Ya entrĂ³: $k"; |
| 31 | |
| 32 | $par = substr($v, -1) == ")"; |
| 33 | $v = $par ? substr($v, 0, -1) : $v; |
| 34 | |
| 35 | //$v .= (empty($v) ? "":" AND ") . " cp.alta_db < '2019-06-13' " . ($par ? ")" : ""); |
| 36 | $v .= (empty($v) ? "":" AND ") . "" . ($par ? ")" : ""); |
| 37 | } |
| 38 | |
| 39 | $v = !empty($v) ? " WHERE $v" : ''; |
| 40 | |
| 41 | $v = str_replace("AND )", " )", $v); |
| 42 | } |
| 43 | |
| 44 | $bug_horrible = $andWhere['{wherevale_pago_log}']; |
| 45 | |
| 46 | $sqllimit = $sumasGridServer['sqllimit']; |
| 47 | $limit = $sumasGridServer['finallimit']; |
| 48 | $orderby = $sumasGridServer['finalorderby']; |
| 49 | $groupby = $sumasGridServer['finalgroupby']; |
| 50 | |
| 51 | //VCA sumasGridServer |
| 52 | |
| 53 | foreach($keys2rLimit as $k=>$l) { |
| 54 | $arrLimit[$l] = $limit; |
| 55 | } |
| 56 | |
| 57 | $obt = $orderby; |
| 58 | |
| 59 | $obt = str_replace("numero AS UNSIGNED", "cp.numero AS UNSIGNED", $obt); |
| 60 | $obt = str_replace("fecha DESC", "cp.fecha DESC", $obt); |
| 61 | |
| 62 | foreach($keys2rOrder as $k=>$l) { |
| 63 | |
| 64 | $ob = $obt; |
| 65 | |
| 66 | if($l == '{ordervale}') |
| 67 | { |
| 68 | $ob = str_replace("cp.numero AS UNSIGNED", "cp.vale_number AS UNSIGNED", $ob); |
| 69 | } |
| 70 | |
| 71 | $arrOrder[$l] = $ob; |
| 72 | } |
| 73 | |
| 74 | $sql = obtenSQLACuentas(); |
| 75 | |
| 76 | $andWhere['{wherevale_pago_log}'] = is_array($andWhere['{wherevale_pago_log}']) ? $bug_horrible : $andWhere['{wherevale_pago_log}']; |
| 77 | $sql = str_replace($keys2Replace,$andWhere,$sql); |
| 78 | $sql = str_replace($keys2rOrder,$arrOrder,$sql); |
| 79 | $sql = str_replace($keys2rLimit,$arrLimit,$sql); |
| 80 | $sql = str_replace(array("\r\n","\t"),array(' ',' '),$sql); |
| 81 | $sql .= $orderby . $limit; |
| 82 | |
| 83 | $COUNTsql = "SELECT /** acuentasMovs **/ COUNT(*) FROM ( ". $sql . " ) AS COUNT_TMP "; |
| 84 | |
| 85 | $sumasGridServer['total_records'] = ia_singleread($COUNTsql); |
| 86 | |
| 87 | $sumasGridServer['tablaOriginal'] = "a_cuentas_schema"; |
| 88 | $sumasGridServer['demasiadasLineasGrid'] = "NO"; |
| 89 | |
| 90 | $tempTable4Sum = "aa_tmp".ia_guid(); |
| 91 | $arrsqlData = array('tempTable4Sum'=>$tempTable4Sum, 'sql' => $sql, 'func'=>"acuentasMovs", 'sumasGridServer'=>$sumasGridServer); |
| 92 | |
| 93 | /** |
| 94 | $myFile = "acuentas.txt"; |
| 95 | $fh = fopen($myFile, 'w') or die("can't open file"); |
| 96 | |
| 97 | $bleh = "<pre>arrsqlData".print_r($arrsqlData, true)."</pre>"; |
| 98 | $bleh .= "<pre>sumasGridServer".print_r($sumasGridServer, true)."</pre>"; |
| 99 | $bleh .= "<pre>andWhere".print_r($andWhere, true)."</pre>"; |
| 100 | fwrite($fh, $bleh); |
| 101 | fclose($fh); |
| 102 | **/ |
| 103 | |
| 104 | |
| 105 | if($sumasGridServer['total_records'] > $gIAParametros['numero_maximo_renglones_grid'] && $sumasGridServer['orGridTrigger'] == "NO" && $sumasGridServer['iaGridInicial'] == "NO") |
| 106 | { |
| 107 | $sumasGridServer['demasiadasLineasGrid'] = 'SI'; |
| 108 | $arrsqlData['sumasGridServer']['demasiadasLineasGrid'] = 'SI'; |
| 109 | $arrsqlData = json_encode($arrsqlData); |
| 110 | |
| 111 | /** |
| 112 | $myFile = "true_asyncGridServer.txt"; |
| 113 | $fh = fopen($myFile, 'w') or die("can't open file"); |
| 114 | |
| 115 | $bleh = "<pre>arrsqlData".print_r(json_decode($arrsqlData), true)."</pre>"; |
| 116 | fwrite($fh, $bleh); |
| 117 | fclose($fh); |
| 118 | * **/ |
| 119 | |
| 120 | async_guardaConsulta($arrsqlData); |
| 121 | } |
| 122 | else |
| 123 | { |
| 124 | $arrsqlData = json_encode($arrsqlData); |
| 125 | guardaConsulta(json_decode($arrsqlData)); |
| 126 | //$sumasGridServer['total_records'] = ia_singleread("SELECT COUNT(*) FROM $tempTable4Sum"); |
| 127 | $arrACuentas = ia_sqlArrayIndx("SELECT * FROM $tempTable4Sum $sqllimit"); |
| 128 | |
| 129 | } |
| 130 | |
| 131 | $sumasGridServer['iactbl'] = $sumasGridServer['iasumFuncTable'] = $tempTable4Sum; |
| 132 | |
| 133 | |
| 134 | //VCA sumasGridServer |
| 135 | return $arrACuentas; |
| 136 | |
| 137 | } |
| 138 | |
| 139 | function obtenSQLACuentasVale() { |
| 140 | $sql = trim(" |
| 141 | (SELECT /**-- VALE_PAGO_MULTIPLE de TABLA vale_pago @TODO**/ |
| 142 | cp.vale_id AS doc_pago_id, |
| 143 | cp.vale_id AS doc_id, |
| 144 | cp.fecha, |
| 145 | if((cp.cancelado = 1),'No','Si') AS activo, |
| 146 | cp.origen, |
| 147 | cp.vale_number AS doc_numero, |
| 148 | cp.cliente_id, |
| 149 | IF(cp.cliente_id IS NULL, cp.cliente, cli.nombre) AS doc_cliente, |
| 150 | cp.quantity AS doc_quantity, |
| 151 | 0.00 AS quantity, |
| 152 | cp.tipo_cambio, |
| 153 | cp.quantity_recibido AS quantity_ctat, |
| 154 | cp.quantity_total, |
| 155 | cp.recibido_moneda_id AS moneda_id, |
| 156 | (cp.quantity - cp.total_payments) AS doc_saldo, |
| 157 | cp.alta_por, |
| 158 | cp.cuentaT_id, |
| 159 | cp.metodo_pago_id, |
| 160 | cp.deposit_total, |
| 161 | cp.banco_cuenta_mov_link_id, |
| 162 | cp.deposit_fecha, |
| 163 | cp.banco_cuenta_id, |
| 164 | '' AS fecha_borrado, |
| 165 | cp.comentario, |
| 166 | cp.ide_amount, |
| 167 | cp.ide_percent, |
| 168 | cp.factura, |
| 169 | cp.tipo_cash_nota, |
| 170 | cp.cash_nota_num, |
| 171 | cp.cliente, |
| 172 | '1' AS numero, |
| 173 | cp.alta_db, |
| 174 | cp.dinero_en_cuentaT_id AS cuentaT_deliveredto_id, |
| 175 | cp.paid, |
| 176 | cp.moneda_id AS doc_moneda, |
| 177 | cp.cobra_iva, |
| 178 | cp.iva_incluido, |
| 179 | cp.numero_referencia, |
| 180 | cp.cash_num_cobro_iva, |
| 181 | cp.empresa_id, |
| 182 | cp.cliente_rfc, |
| 183 | cp.ultimo_cambio, |
| 184 | cp.ultimo_cambio_por, |
| 185 | cp.referencia, |
| 186 | cp.factura_numero, |
| 187 | cp.ivacobradox100, |
| 188 | cp.ivacobradototal, |
| 189 | cp.tarjeta_amount, |
| 190 | cp.tarjeta_percent, |
| 191 | cp.comision_percent, |
| 192 | cp.comision_amount, |
| 193 | 'NO' AS puede_borrar, |
| 194 | '' AS vs_pago_key, |
| 195 | '' AS vs_doc_key, |
| 196 | '' AS vs_doc, |
| 197 | cp.cuenta_t_mov_id, |
| 198 | cp.tienda_id, |
| 199 | cp.total_payments, |
| 200 | NULL AS origen_cuentat_id |
| 201 | from vale as cp LEFT JOIN cliente cli ON cp.cliente_id = cli.cliente_id |
| 202 | {wherevale} {ordervale} {limitvale} )"); |
| 203 | |
| 204 | if(VALE_PAGO_MULTIPLE) { |
| 205 | $sql .= trim(" |
| 206 | UNION ALL |
| 207 | (SELECT |
| 208 | cp.vale_pago_id AS doc_pago_id, |
| 209 | cp.vale_id AS doc_id, |
| 210 | cp.fecha, |
| 211 | cp.activo, |
| 212 | 'valepago' as origen, |
| 213 | ch.vale_number AS doc_numero, |
| 214 | ch.cliente_id, |
| 215 | IF(ch.cliente_id IS NULL, ch.cliente, cli.nombre) AS doc_cliente, |
| 216 | ch.quantity AS doc_quantity, |
| 217 | cp.quantity, |
| 218 | cp.tipo_cambio, |
| 219 | '' as quantity_ctat, |
| 220 | cp.quantity_total, |
| 221 | cp.moneda_id, |
| 222 | cp.saldo AS doc_saldo, |
| 223 | cp.alta_por, |
| 224 | cp.cuentaT_id, |
| 225 | cp.metodo_pago_id, |
| 226 | '' as deposit_total, |
| 227 | cp.banco_cuenta_mov_link_id, |
| 228 | '' as deposit_fecha, |
| 229 | cp.banco_cuenta_id, |
| 230 | '' AS fecha_borrado, |
| 231 | cp.comentario, |
| 232 | cp.ide_amount, |
| 233 | cp.ide_percent, |
| 234 | '' as factura, |
| 235 | '' as tipo_cash_nota, |
| 236 | '' as cash_nota_num, |
| 237 | '' as cliente, |
| 238 | cp.numero, |
| 239 | cp.alta_db, |
| 240 | ch.dinero_en_cuentaT_id, |
| 241 | ch.paid, |
| 242 | ch.moneda_id AS doc_moneda, |
| 243 | '' as cobra_iva, |
| 244 | '' as iva_incluido, |
| 245 | '' as numero_referencia, |
| 246 | '' as cash_num_cobro_iva, |
| 247 | '' as empresa_id, |
| 248 | '' as cliente_rfc, |
| 249 | cp.ultimo_cambio, |
| 250 | cp.ultimo_cambio_por, |
| 251 | cp.referencia, |
| 252 | '' as factura_numero, |
| 253 | '' as ivacobradox100, |
| 254 | '' as ivacobradototal, |
| 255 | cp.tarjeta_amount, |
| 256 | cp.tarjeta_percent, |
| 257 | '' as comision_amount, |
| 258 | '' as comision_percent, |
| 259 | '' as puede_borrar, |
| 260 | '' as vs_pago_key, |
| 261 | '' as vs_doc_key, |
| 262 | '' as vs_doc, |
| 263 | '' as cuenta_t_mov_id, |
| 264 | ch.tienda_id, |
| 265 | ch.total_payments, |
| 266 | NULL AS origen_cuentat_id |
| 267 | FROM vale_pago AS cp |
| 268 | LEFT JOIN vale ch ON ch.vale_id=cp.vale_id |
| 269 | LEFT JOIN cliente cli ON ch.cliente_id=cli.cliente_id |
| 270 | {wherevale_pago} {ordervale_pago} {limitvale_pago} )"); |
| 271 | |
| 272 | |
| 273 | $sql .= trim(" |
| 274 | UNION ALL |
| 275 | (SELECT |
| 276 | cp.vale_pago_log_id AS doc_pago_id, |
| 277 | cp.vale_id AS doc_id, |
| 278 | cp.fecha, |
| 279 | 'No' as activo, |
| 280 | 'valepago' as origen, |
| 281 | ch.vale_number AS doc_numero, |
| 282 | ch.cliente_id, |
| 283 | IF(ch.cliente_id IS NULL, ch.cliente, cli.nombre) AS doc_cliente, |
| 284 | ch.quantity AS doc_quantity, |
| 285 | cp.quantity, |
| 286 | cp.tipo_cambio, |
| 287 | '' as quantity_ctat, |
| 288 | cp.quantity_total, |
| 289 | cp.moneda_id, |
| 290 | cp.saldo AS doc_saldo, |
| 291 | cp.alta_por, |
| 292 | cp.cuentaT_id, |
| 293 | cp.metodo_pago_id, |
| 294 | '' as deposit_total, |
| 295 | cp.banco_cuenta_mov_link_id, |
| 296 | '' as deposit_fecha, |
| 297 | cp.banco_cuenta_id, |
| 298 | '' AS fecha_borrado, |
| 299 | cp.comentario, |
| 300 | cp.ide_amount, |
| 301 | cp.ide_percent, |
| 302 | '' as factura, |
| 303 | '' as tipo_cash_nota, |
| 304 | '' as cash_nota_num, |
| 305 | '' as cliente, |
| 306 | cp.numero, |
| 307 | cp.alta_db, |
| 308 | ch.dinero_en_cuentaT_id, |
| 309 | ch.paid, |
| 310 | ch.moneda_id AS doc_moneda, |
| 311 | '' as cobra_iva, |
| 312 | '' as iva_incluido, |
| 313 | '' as numero_referencia, |
| 314 | '' as cash_num_cobro_iva, |
| 315 | '' as empresa_id, |
| 316 | '' as cliente_rfc, |
| 317 | cp.ultimo_cambio, |
| 318 | cp.ultimo_cambio_por, |
| 319 | cp.referencia, |
| 320 | '' as factura_numero, |
| 321 | '' as ivacobradox100, |
| 322 | '' as ivacobradototal, |
| 323 | cp.tarjeta_amount, |
| 324 | cp.tarjeta_percent, |
| 325 | '' as comision_amount, |
| 326 | '' as comision_percent, |
| 327 | '' as puede_borrar, |
| 328 | '' as vs_pago_key, |
| 329 | '' as vs_doc_key, |
| 330 | '' as vs_doc, |
| 331 | '' as cuenta_t_mov_id, |
| 332 | ch.tienda_id, |
| 333 | ch.total_payments, |
| 334 | NULL AS origen_cuentat_id |
| 335 | FROM vale_pago_log AS cp |
| 336 | LEFT JOIN vale ch ON ch.vale_id=cp.vale_id |
| 337 | LEFT JOIN cliente cli ON ch.cliente_id=cli.cliente_id |
| 338 | {wherevale_pago_log} {ordervale_pago_log} {limitvale_pago_log} )"); |
| 339 | |
| 340 | } |
| 341 | |
| 342 | return $sql; |
| 343 | } |
| 344 | |
| 345 | function obtenSQLACuentas() |
| 346 | { |
| 347 | $valeSelect = obtenSQLACuentasVale(); |
| 348 | return " |
| 349 | (SELECT |
| 350 | cp.cheque_pago_id AS doc_pago_id, |
| 351 | cp.cheque_id AS doc_id, |
| 352 | cp.fecha, |
| 353 | cp.activo, |
| 354 | cp.origen, |
| 355 | ch.numero AS doc_numero, |
| 356 | ch.cliente_id, |
| 357 | cli.nombre AS doc_cliente, |
| 358 | ch.quantity AS doc_quantity, |
| 359 | cp.quantity, |
| 360 | cp.tipo_cambio, |
| 361 | cp.quantity_ctat, |
| 362 | cp.quantity_total, |
| 363 | cp.moneda_id, |
| 364 | cp.saldo AS doc_saldo, |
| 365 | cp.alta_por, |
| 366 | cp.cuentaT_id, |
| 367 | cp.metodo_pago_id, |
| 368 | cp.deposit_total, |
| 369 | cp.banco_cuenta_mov_link_id, |
| 370 | cp.deposit_fecha, |
| 371 | cp.banco_cuenta_id, |
| 372 | '' AS fecha_borrado, |
| 373 | cp.comentario, |
| 374 | cp.ide_amount, |
| 375 | cp.ide_percent, |
| 376 | cp.factura, |
| 377 | cp.tipo_cash_nota, |
| 378 | cp.cash_nota_num, |
| 379 | cp.cliente, |
| 380 | cp.numero, |
| 381 | cp.alta_db, |
| 382 | ch.cuentaT_deliveredto_id, |
| 383 | ch.paid, |
| 384 | ch.moneda_id AS doc_moneda, |
| 385 | cp.cobra_iva, |
| 386 | cp.iva_incluido, |
| 387 | cp.numero_referencia, |
| 388 | cp.cash_num_cobro_iva, |
| 389 | cp.empresa_id, |
| 390 | cp.cliente_rfc, |
| 391 | cp.ultimo_cambio, |
| 392 | cp.ultimo_cambio_por, |
| 393 | cp.referencia, |
| 394 | cp.factura_numero, |
| 395 | cp.ivacobradox100, |
| 396 | cp.ivacobradototal, |
| 397 | cp.tarjeta_amount, |
| 398 | cp.tarjeta_percent, |
| 399 | cp.comision_amount, |
| 400 | cp.comision_percent, |
| 401 | cp.puede_borrar, |
| 402 | cp.vs_pago_key, |
| 403 | cp.vs_doc_key, |
| 404 | cp.vs_doc, |
| 405 | cp.cuenta_t_mov_id, |
| 406 | ch.tienda_id, |
| 407 | ch.total_payments, |
| 408 | ch.origen_cuentat_id |
| 409 | FROM cheque_pago AS cp |
| 410 | LEFT JOIN cheque ch ON ch.cheque_id=cp.cheque_id |
| 411 | LEFT JOIN cliente cli ON ch.cliente_id=cli.cliente_id |
| 412 | {wherecheque_pago} {ordercheque_pago} {limitcheque_pago} ) |
| 413 | UNION ALL |
| 414 | (SELECT |
| 415 | cp.pagare_pago_id AS doc_pago_id, |
| 416 | cp.pagare_id AS doc_id, |
| 417 | cp.fecha, |
| 418 | cp.activo, |
| 419 | cp.origen, |
| 420 | ch.numero AS doc_numero, |
| 421 | ch.cliente_id, |
| 422 | cli.nombre AS doc_cliente, |
| 423 | ch.quantity AS doc_quantity, |
| 424 | cp.quantity, |
| 425 | cp.tipo_cambio, |
| 426 | cp.quantity_ctat, |
| 427 | cp.quantity_total, |
| 428 | cp.moneda_id, |
| 429 | cp.saldo AS doc_saldo, |
| 430 | cp.alta_por, |
| 431 | cp.cuentaT_id, |
| 432 | cp.metodo_pago_id, |
| 433 | cp.deposit_total, |
| 434 | cp.banco_cuenta_mov_link_id, |
| 435 | cp.deposit_fecha, |
| 436 | cp.banco_cuenta_id, |
| 437 | '' AS fecha_borrado, |
| 438 | cp.comentario, |
| 439 | cp.ide_amount, |
| 440 | cp.ide_percent, |
| 441 | cp.factura, |
| 442 | cp.tipo_cash_nota, |
| 443 | cp.cash_nota_num, |
| 444 | cp.cliente, |
| 445 | cp.numero, |
| 446 | cp.alta_db, |
| 447 | ch.cuentaT_deliveredto_id, |
| 448 | ch.paid, |
| 449 | ch.moneda_id AS doc_moneda, |
| 450 | cp.cobra_iva, |
| 451 | cp.iva_incluido, |
| 452 | cp.numero_referencia, |
| 453 | cp.cash_num_cobro_iva, |
| 454 | cp.empresa_id, |
| 455 | cp.cliente_rfc, |
| 456 | cp.ultimo_cambio, |
| 457 | cp.ultimo_cambio_por, |
| 458 | cp.referencia, |
| 459 | cp.factura_numero, |
| 460 | cp.ivacobradox100, |
| 461 | cp.ivacobradototal, |
| 462 | cp.tarjeta_amount, |
| 463 | cp.tarjeta_percent, |
| 464 | cp.comision_amount, |
| 465 | cp.comision_percent, |
| 466 | cp.puede_borrar, |
| 467 | cp.vs_pago_key, |
| 468 | cp.vs_doc_key, |
| 469 | cp.vs_doc, |
| 470 | cp.cuenta_t_mov_id, |
| 471 | ch.tienda_id, |
| 472 | ch.total_payments, |
| 473 | ch.origen_cuentat_id |
| 474 | FROM pagare_pago AS cp |
| 475 | LEFT JOIN pagare ch ON ch.pagare_id=cp.pagare_id |
| 476 | LEFT JOIN cliente cli ON ch.cliente_id=cli.cliente_id |
| 477 | {wherepagare_pago} {orderpagare_pago} {limitpagare_pago} ) |
| 478 | UNION ALL |
| 479 | (SELECT |
| 480 | cp.cheque_pago_log_id AS doc_pago_id, |
| 481 | cp.cheque_id AS doc_id, |
| 482 | cp.fecha, |
| 483 | 'No' as activo, |
| 484 | 'CHEQUE' as origen, |
| 485 | ch.numero AS doc_numero, |
| 486 | ch.cliente_id, |
| 487 | cli.nombre AS doc_cliente, |
| 488 | ch.quantity AS doc_quantity, |
| 489 | cp.quantity, |
| 490 | cp.tipo_cambio, |
| 491 | '' as quantity_ctat, |
| 492 | cp.quantity_total, |
| 493 | cp.moneda_id, |
| 494 | cp.saldo AS doc_saldo, |
| 495 | cp.alta_por, |
| 496 | cp.cuentaT_id, |
| 497 | cp.metodo_pago_id, |
| 498 | '' as deposit_total, |
| 499 | cp.banco_cuenta_mov_link_id, |
| 500 | '' as deposit_fecha, |
| 501 | cp.banco_cuenta_id, |
| 502 | cp.fecha_borrado, |
| 503 | cp.comentario, |
| 504 | cp.ide_amount, |
| 505 | cp.ide_percent, |
| 506 | '' as factura, |
| 507 | '' as tipo_cash_nota, |
| 508 | '' as cash_nota_num, |
| 509 | '' as cliente, |
| 510 | cp.numero, |
| 511 | cp.alta_db, |
| 512 | ch.cuentaT_deliveredto_id, |
| 513 | ch.paid, |
| 514 | ch.moneda_id AS doc_moneda, |
| 515 | '' as cobra_iva, |
| 516 | '' as iva_incluido, |
| 517 | '' as numero_referencia, |
| 518 | '' as cash_num_cobro_iva, |
| 519 | '' as empresa_id, |
| 520 | '' as cliente_rfc, |
| 521 | cp.ultimo_cambio, |
| 522 | cp.ultimo_cambio_por, |
| 523 | cp.referencia, |
| 524 | '' as factura_numero, |
| 525 | '' as ivacobradox100, |
| 526 | '' as ivacobradototal, |
| 527 | cp.tarjeta_amount, |
| 528 | cp.tarjeta_percent, |
| 529 | '' as comision_amount, |
| 530 | '' as comision_percent, |
| 531 | '' as puede_borrar, |
| 532 | '' as vs_pago_key, |
| 533 | '' as vs_doc_key, |
| 534 | '' as vs_doc, |
| 535 | '' as cuenta_t_mov_id, |
| 536 | ch.tienda_id, |
| 537 | ch.total_payments, |
| 538 | ch.origen_cuentat_id |
| 539 | FROM cheque_pago_log AS cp |
| 540 | LEFT JOIN cheque ch ON ch.cheque_id=cp.cheque_id |
| 541 | LEFT JOIN cliente cli ON ch.cliente_id=cli.cliente_id |
| 542 | {wherecheque_pago_log} {ordercheque_pago_log} {limitcheque_pago_log} ) |
| 543 | UNION ALL |
| 544 | (SELECT |
| 545 | cp.pagare_pago_log_id AS doc_pago_id, |
| 546 | cp.pagare_id AS doc_id, |
| 547 | cp.fecha, |
| 548 | 'No' as activo, |
| 549 | 'pagare' as origen, |
| 550 | ch.numero AS doc_numero, |
| 551 | ch.cliente_id, |
| 552 | cli.nombre AS doc_cliente, |
| 553 | ch.quantity AS doc_quantity, |
| 554 | cp.quantity, |
| 555 | cp.tipo_cambio, |
| 556 | '' as quantity_ctat, |
| 557 | cp.quantity_total, |
| 558 | cp.moneda_id, |
| 559 | cp.saldo AS doc_saldo, |
| 560 | cp.alta_por, |
| 561 | cp.cuentaT_id, |
| 562 | cp.metodo_pago_id, |
| 563 | '' as deposit_total, |
| 564 | cp.banco_cuenta_mov_link_id, |
| 565 | '' as deposit_fecha, |
| 566 | cp.banco_cuenta_id, |
| 567 | cp.fecha_borrado, |
| 568 | cp.comentario, |
| 569 | cp.ide_amount, |
| 570 | cp.ide_percent, |
| 571 | '' as factura, |
| 572 | '' as tipo_cash_nota, |
| 573 | '' as cash_nota_num, |
| 574 | '' as cliente, |
| 575 | cp.numero, |
| 576 | cp.alta_db, |
| 577 | ch.cuentaT_deliveredto_id, |
| 578 | ch.paid, |
| 579 | ch.moneda_id AS doc_moneda, |
| 580 | '' as cobra_iva, |
| 581 | '' as iva_incluido, |
| 582 | '' as numero_referencia, |
| 583 | '' as cash_num_cobro_iva, |
| 584 | '' as empresa_id, |
| 585 | '' as cliente_rfc, |
| 586 | cp.ultimo_cambio, |
| 587 | cp.ultimo_cambio_por, |
| 588 | cp.referencia, |
| 589 | '' as factura_numero, |
| 590 | '' as ivacobradox100, |
| 591 | '' as ivacobradototal, |
| 592 | cp.tarjeta_amount, |
| 593 | cp.tarjeta_percent, |
| 594 | '' as comision_amount, |
| 595 | '' as comision_percent, |
| 596 | '' as puede_borrar, |
| 597 | '' as vs_pago_key, |
| 598 | '' as vs_doc_key, |
| 599 | '' as vs_doc, |
| 600 | '' as cuenta_t_mov_id, |
| 601 | ch.tienda_id, |
| 602 | ch.total_payments, |
| 603 | ch.origen_cuentat_id |
| 604 | FROM pagare_pago_log AS cp |
| 605 | LEFT JOIN pagare ch ON ch.pagare_id=cp.pagare_id |
| 606 | LEFT JOIN cliente cli ON ch.cliente_id=cli.cliente_id |
| 607 | {wherepagare_pago_log} {orderpagare_pago_log} {limitpagare_pago_log} ) |
| 608 | UNION ALL |
| 609 | $valeSelect"; |
| 610 | } |
| 611 | |
| 612 | function actualizaSaldosACuentas(&$sql,$iacase=null,$table=null,$id=null,$cpid=null, $esValeUso = false){ |
| 613 | global $gIAParametros; |
| 614 | |
| 615 | if($iacase!=null) |
| 616 | { |
| 617 | $docID = $iacase->id; |
| 618 | $docApp = $iacase->table; |
| 619 | $docAppPago = $iacase->table."_pago"; |
| 620 | $docPK = $iacase->table."_id"; |
| 621 | $docPagoPK = $iacase->table."_pago_id"; |
| 622 | $moneda_id = $iacase->enDB['moneda_id']; |
| 623 | $saldo = $iacase->values['quantity']; |
| 624 | } |
| 625 | else |
| 626 | { |
| 627 | $docID = $id; |
| 628 | $docApp = $table; |
| 629 | $docAppPago = $table."_pago"; |
| 630 | $docPK = $table."_id"; |
| 631 | $docPagoPK = $table."_pago_id"; |
| 632 | |
| 633 | if ($esValeUso) { |
| 634 | $docAppPago = $table."_uso"; |
| 635 | $docPagoPK = $table."_uso_id"; |
| 636 | } |
| 637 | $query = "SELECT * FROM $docApp WHERE $docPK='$docID'"; |
| 638 | //echo $query; |
| 639 | $doc_arr = ia_singleton($query); |
| 640 | |
| 641 | $moneda_id = $doc_arr['moneda_id']; |
| 642 | $saldo = $doc_arr['quantity']; |
| 643 | } |
| 644 | |
| 645 | if($moneda_id == 1) |
| 646 | $docTolerancia = $gIAParametros['tolerancia_pago_documentos_pesos']; |
| 647 | else |
| 648 | $docTolerancia = $gIAParametros['tolerancia_pago_documentos_usd']; |
| 649 | |
| 650 | if ($table == 'vale' and $docAppPago == 'vale_pago') { |
| 651 | $saldo = 0; |
| 652 | $query = "SELECT * FROM $docAppPago WHERE $docPK='$docID' ORDER BY numero ASC"; |
| 653 | } else { |
| 654 | $query = "SELECT * FROM $docAppPago WHERE $docPK='$docID' AND $docPagoPK NOT IN ('$cpid') ORDER BY numero ASC"; |
| 655 | } |
| 656 | |
| 657 | if ($esValeUso) { |
| 658 | $query = "SELECT * FROM $docAppPago WHERE $docPK='$docID' ORDER BY numero ASC"; |
| 659 | } |
| 660 | // dd_($query); |
| 661 | |
| 662 | $actas_arr = ia_sqlArray($query, $docPagoPK); |
| 663 | if(!empty($actas_arr) && is_array($actas_arr)) |
| 664 | { |
| 665 | foreach($actas_arr as $k=>$v) |
| 666 | { |
| 667 | |
| 668 | if ($table == 'vale' and $docAppPago == 'vale_pago') { |
| 669 | $saldo+=$v['quantity']; |
| 670 | } else { |
| 671 | $saldo-=$v['quantity']; |
| 672 | } |
| 673 | $saldo = $saldo < $docTolerancia ? $saldo = 0.00 : $saldo; |
| 674 | $cuentat = ''; |
| 675 | $query = "UPDATE $docAppPago SET saldo = '$saldo' $cuentat WHERE $docPagoPK='$k'"; |
| 676 | $sql[] = $query; |
| 677 | } |
| 678 | } |
| 679 | |
| 680 | //echo "<pre>".print_r($sql, true)."</pre>"; |
| 681 | return $sql; |
| 682 | } |