Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 374 |
|
0.00% |
0 / 6 |
CRAP | |
0.00% |
0 / 1 |
| BancoCuentaMov | |
0.00% |
0 / 374 |
|
0.00% |
0 / 6 |
10506 | |
0.00% |
0 / 1 |
| leeBancoCuentaMov | |
0.00% |
0 / 55 |
|
0.00% |
0 / 1 |
72 | |||
| guardaBancoCuentaMov | |
0.00% |
0 / 37 |
|
0.00% |
0 / 1 |
56 | |||
| insertaBancoCuentaMov | |
0.00% |
0 / 63 |
|
0.00% |
0 / 1 |
182 | |||
| arreglaCamposparaleeBancoCuentaMov | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
42 | |||
| arreglaCamposparaguardaBancoCuentaMov | |
0.00% |
0 / 9 |
|
0.00% |
0 / 1 |
72 | |||
| calculaCamposAutomaticos | |
0.00% |
0 / 205 |
|
0.00% |
0 / 1 |
3660 | |||
| 1 | <?php |
| 2 | //marzo2020 |
| 3 | /** |
| 4 | * BancoCuentaMov |
| 5 | * |
| 6 | * @package Vitex Cobranza |
| 7 | * @author Victor Cazares |
| 8 | * @copyright 2014 |
| 9 | * @version $Id$ |
| 10 | * @access public |
| 11 | */ |
| 12 | class BancoCuentaMov |
| 13 | { |
| 14 | |
| 15 | /*****************************/ |
| 16 | //Datos del Movimiento Bancario |
| 17 | /*****************************/ |
| 18 | |
| 19 | var $banco_cuenta_mov_id; |
| 20 | var $banco_cuenta_id; |
| 21 | var $fecha; |
| 22 | var $es; |
| 23 | var $cash; |
| 24 | var $deposit; |
| 25 | var $withdrawal; |
| 26 | var $banco_mov_tipo_id; |
| 27 | var $numero; |
| 28 | var $banco_id; |
| 29 | |
| 30 | var $verificado; |
| 31 | var $verificado_el; |
| 32 | var $verificado_por; |
| 33 | var $mov_verificado_id; |
| 34 | |
| 35 | var $idex100; |
| 36 | var $factura; |
| 37 | var $ivacobradox100; |
| 38 | var $ivacobradototal; |
| 39 | var $remarks; |
| 40 | var $alta_db; |
| 41 | var $alta_por; |
| 42 | var $ultimo_cambio; |
| 43 | var $ultimo_cambio_por; |
| 44 | |
| 45 | var $Original = true; |
| 46 | var $tblOriginal = 'banco_cuenta_mov'; |
| 47 | var $tblVerif = 'mov_verificado'; |
| 48 | |
| 49 | var $id = ''; |
| 50 | var $vid = ''; |
| 51 | var $tbl = ''; |
| 52 | |
| 53 | var $usado; |
| 54 | var $puede_editar; |
| 55 | var $link_vale; |
| 56 | |
| 57 | var $OldQuantity = 0.00; |
| 58 | |
| 59 | var $alta_tipo; |
| 60 | |
| 61 | var $tipo_cash_nota; |
| 62 | var $cash_nota_num; |
| 63 | var $tienda; |
| 64 | var $empresa; |
| 65 | var $cliente; |
| 66 | var $factura_numero; |
| 67 | |
| 68 | var $withdrawal_autorizado = 'No'; |
| 69 | var $withdrawal_autorizado_el; |
| 70 | var $withdrawal_autorizado_por; |
| 71 | |
| 72 | var $extraInsertSQL = array(); |
| 73 | |
| 74 | var $categoria_gasto_id; |
| 75 | var $fecha1; |
| 76 | var $bc_empresa_id; |
| 77 | var $numero_original; |
| 78 | var $go; |
| 79 | var $moneda_id; |
| 80 | |
| 81 | |
| 82 | |
| 83 | |
| 84 | function leeBancoCuentaMov($UUID) |
| 85 | { |
| 86 | |
| 87 | if($UUID == '' || $UUID == NULL) |
| 88 | return FALSE; |
| 89 | |
| 90 | if($this->Original) |
| 91 | $bcmsql = "SELECT * FROM $this->tblOriginal WHERE banco_cuenta_mov_id = ".strit($UUID); |
| 92 | else |
| 93 | $bcmsql = "SELECT * FROM $this->tblVerif WHERE mov_verificado_id = ".strit($UUID); |
| 94 | |
| 95 | $bcmarray = ia_singleton($bcmsql); |
| 96 | |
| 97 | if (!$bcmarray) |
| 98 | return FALSE; |
| 99 | $this->banco_cuenta_mov_id = $bcmarray['banco_cuenta_mov_id']; |
| 100 | $this->banco_cuenta_id = $bcmarray['banco_cuenta_id']; |
| 101 | $this->fecha = $bcmarray['fecha']; |
| 102 | $this->es = $bcmarray['es']; |
| 103 | $this->cash = $bcmarray['cash']; |
| 104 | $this->deposit = $bcmarray['deposit']; |
| 105 | $this->withdrawal = $bcmarray['withdrawal']; |
| 106 | $this->banco_mov_tipo_id = $bcmarray['banco_mov_tipo_id']; |
| 107 | $this->numero = mb_convert_encoding($bcmarray['numero'], 'ISO-8859-1', 'UTF-8'); |
| 108 | $this->banco_id = $bcmarray['banco_id']; |
| 109 | $this->verificado = $bcmarray['verificado']; |
| 110 | $this->verificado_el = $bcmarray['verificado_el']; |
| 111 | $this->verificado_por = $bcmarray['verificado_por']; |
| 112 | $this->mov_verificado_id = $bcmarray['mov_verificado_id']; |
| 113 | $this->idex100 = $bcmarray['idex100']; |
| 114 | $this->factura = mb_convert_encoding($bcmarray['factura'], 'ISO-8859-1', 'UTF-8'); |
| 115 | |
| 116 | $this->ivacobradox100 = $bcmarray['ivacobradox100']; |
| 117 | |
| 118 | |
| 119 | $this->remarks = mb_convert_encoding($bcmarray['remarks'], 'ISO-8859-1', 'UTF-8'); |
| 120 | $this->alta_db = $bcmarray['alta_db']; |
| 121 | $this->alta_por = $bcmarray['alta_por']; |
| 122 | $this->ultimo_cambio = $bcmarray['ultimo_cambio']; |
| 123 | $this->ultimo_cambio_por = $bcmarray['ultimo_cambio_por']; |
| 124 | |
| 125 | $this->usado = $bcmarray['usado']; |
| 126 | $this->puede_editar = $bcmarray['puede_editar']; |
| 127 | $this->link_vale = $bcmarray['link_vale']; |
| 128 | |
| 129 | $this->alta_tipo = $bcmarray['alta_tipo']; |
| 130 | |
| 131 | $this->OldQuantity = $this->cash + $this->deposit - $this->withdrawal; |
| 132 | $this->ivacobradototal = $this->OldQuantity * $this->ivacobradox100 / 100; |
| 133 | |
| 134 | if($this->Original) |
| 135 | { $this->id = 'banco_cuenta_mov_id'; $this->tbl = 'banco_cuenta_mov'; $this->vid = 'mov_verificado_id';} |
| 136 | else |
| 137 | { $this->id = 'mov_verificado_id'; $this->tbl = 'mov_verificado'; $this->vid = 'banco_cuenta_mov_id';} |
| 138 | |
| 139 | $this->tipo_cash_nota = $bcmarray['tipo_cash_nota']; |
| 140 | $this->cash_nota_num = $bcmarray['cash_nota_num']; |
| 141 | $this->tienda = !empty($bcmarray['tienda_id']) ? ia_singleread("SELECT tienda FROM tienda WHERE tienda_id=".strit($bcmarray['tienda_id'])) : ''; |
| 142 | $this->empresa = !empty($bcmarray['empresa_id']) ? ia_singleread("SELECT empresa FROM empresa WHERE empresa_id=".strit($bcmarray['empresa_id'])) : '';; |
| 143 | $this->cliente = $bcmarray['cliente']; |
| 144 | $this->factura_numero = $bcmarray['factura_numero']; |
| 145 | |
| 146 | $this->withdrawal_autorizado = $bcmarray['withdrawal_autorizado']; |
| 147 | $this->withdrawal_autorizado_el = $bcmarray['withdrawal_autorizado_el']; |
| 148 | $this->withdrawal_autorizado_por = $bcmarray['withdrawal_autorizado_por']; |
| 149 | |
| 150 | $this->categoria_gasto_id = $bcmarray['categoria_gasto_id']; |
| 151 | $this->fecha1 = $bcmarray['fecha1']; |
| 152 | $this->bc_empresa_id = $bcmarray['bc_empresa_id']; |
| 153 | |
| 154 | $this->numero_original = $bcmarray['numero_original']; |
| 155 | $this->moneda_id = $bcmarray['moneda_id']; |
| 156 | |
| 157 | $this->arreglaCamposparaleeBancoCuentaMov(); |
| 158 | |
| 159 | |
| 160 | return TRUE; |
| 161 | } |
| 162 | |
| 163 | function guardaBancoCuentaMov($UUID, $EliminoVerif = false, $do=true) |
| 164 | { |
| 165 | //global $gIAsql; |
| 166 | |
| 167 | //$gIAsql['trace']=true; |
| 168 | |
| 169 | global $gIAsql; |
| 170 | if($UUID != $this->banco_cuenta_mov_id && $UUID != $this->mov_verificado_id) |
| 171 | { |
| 172 | return FALSE; |
| 173 | } |
| 174 | |
| 175 | $this->ultimo_cambio = date('Y-m-d H:i:s'); |
| 176 | $this->arreglaCamposparaguardaBancoCuentaMov(); |
| 177 | $mFecha = date('Y-m-d', strtotime($this->fecha)); |
| 178 | |
| 179 | $cmnt = 'Modificacion Mov Bancario'; |
| 180 | $sql = array(); |
| 181 | |
| 182 | $sql[] = "UPDATE $this->tblOriginal /** $cmnt **/ SET |
| 183 | fecha = '$this->fecha', |
| 184 | es = '$this->es', |
| 185 | banco_mov_tipo_id = '$this->banco_mov_tipo_id', |
| 186 | cash = '$this->cash', |
| 187 | deposit = '$this->deposit', |
| 188 | withdrawal = '$this->withdrawal', |
| 189 | numero = '$this->numero', |
| 190 | numero_original = '$this->numero_original', |
| 191 | usado = '$this->usado', |
| 192 | puede_editar = '$this->puede_editar', |
| 193 | link_vale = '$this->link_vale', |
| 194 | idex100 = '$this->idex100', |
| 195 | factura = '$this->factura', |
| 196 | ivacobradox100 = '$this->ivacobradox100', |
| 197 | remarks = '$this->remarks', |
| 198 | ultimo_cambio = '$this->ultimo_cambio', |
| 199 | ultimo_cambio_por = '$this->ultimo_cambio_por', |
| 200 | fecha1 = '$this->fecha', |
| 201 | moneda_id = '$this->moneda_id' |
| 202 | WHERE banco_cuenta_mov_id = '$this->banco_cuenta_mov_id'"; |
| 203 | |
| 204 | if(!empty($this->extraInsertSQL)) |
| 205 | $sql = array_merge($sql, $this->extraInsertSQL); |
| 206 | |
| 207 | $this->extraInsertSQL = array(); |
| 208 | |
| 209 | if($do) |
| 210 | if(ia_transaction($sql)) |
| 211 | { |
| 212 | ia_errores_a_dime(); |
| 213 | if($gIAsql['trace']) |
| 214 | ia_errores_a_dime("sql_trace=".print_r($gIAsql['sql_trace'],true)); |
| 215 | return false; |
| 216 | } |
| 217 | else |
| 218 | return true; |
| 219 | |
| 220 | return $sql; |
| 221 | } |
| 222 | |
| 223 | function insertaBancoCuentaMov($do=true, $imp=false, $agrega_asignacion = false) |
| 224 | { |
| 225 | global $gIAsql; |
| 226 | |
| 227 | $this->arreglaCamposparaguardaBancoCuentaMov(); |
| 228 | |
| 229 | if(empty($this->banco_cuenta_mov_id)) |
| 230 | $this->banco_cuenta_mov_id = ia_guid(); |
| 231 | |
| 232 | $oknumop = 1; //En principio sólo hay insertar un movimiento |
| 233 | $ok = 0; |
| 234 | $sql = array(); |
| 235 | |
| 236 | if(empty($this->alta_tipo)) |
| 237 | $this->alta_tipo = 'manual'; |
| 238 | |
| 239 | $complete_insert_a_s = ", asignacion, supervision, asig_semaforo_rony, asig_semaforo_usuarios, html_asignaciones"; |
| 240 | $complete_values_a_s = ", 'ZZZZZZZZZZZZ', 'ZZZZZZZZZZZZ', '', '', ''"; |
| 241 | $querys_asignacion = []; |
| 242 | $data_asignacion = []; |
| 243 | if ($agrega_asignacion) { |
| 244 | $complete_insert_a_s = ", asignacion, supervision, asig_semaforo_rony, asig_semaforo_usuarios, html_asignaciones"; |
| 245 | $asignacion = new AsignacionEstatus('banco_cuenta_mov'); |
| 246 | $asignacion->asignaGastoSupervision($this->banco_cuenta_mov_id, $querys_asignacion, $data_asignacion, 'banco_cuenta_mov_supervision'); |
| 247 | $semaforo = calculaSemaforo(null, $data_asignacion['asignacion'], 'banco_cuenta_mov'); |
| 248 | $data_asignacion['asig_semaforo_rony'] = $semaforo['rony']; |
| 249 | $data_asignacion['asig_semaforo_usuarios'] = isset($semaforo['otros']) ? json_encode($semaforo['otros']) : ''; |
| 250 | $fecha_revision = date('Y-m-d H:i:s'); |
| 251 | $data_asignacion['html_asignaciones'] = strit(asignacion_2_html("banco_cuenta_mov_asignacion", $data_asignacion['asignacion'], $this->banco_cuenta_mov_id, true, $fecha_revision)); |
| 252 | $complete_values_a_s = ", '$data_asignacion[asignacion]', '$data_asignacion[supervision]', '$data_asignacion[asig_semaforo_rony]', '$data_asignacion[asig_semaforo_usuarios]', $data_asignacion[html_asignaciones]"; |
| 253 | } |
| 254 | |
| 255 | $tmp1 = "INSERT INTO $this->tblOriginal ( |
| 256 | banco_cuenta_mov_id, |
| 257 | banco_cuenta_id, |
| 258 | fecha, |
| 259 | es, |
| 260 | cash, |
| 261 | deposit, |
| 262 | withdrawal, |
| 263 | banco_mov_tipo_id, |
| 264 | numero, |
| 265 | banco_id, |
| 266 | link_vale, |
| 267 | idex100, |
| 268 | factura, |
| 269 | remarks, |
| 270 | alta_por, |
| 271 | alta_tipo, |
| 272 | categoria_gasto_id, |
| 273 | fecha1, |
| 274 | bc_empresa_id, |
| 275 | numero_original, |
| 276 | moneda_id, |
| 277 | withdrawal_autorizado, |
| 278 | alta_db $complete_insert_a_s) "; |
| 279 | $tmp2 = " VALUES "; |
| 280 | $tmp3 = "('$this->banco_cuenta_mov_id', |
| 281 | '$this->banco_cuenta_id', |
| 282 | '$this->fecha', |
| 283 | '$this->es', |
| 284 | '$this->cash', |
| 285 | '$this->deposit', |
| 286 | '$this->withdrawal', |
| 287 | '$this->banco_mov_tipo_id', |
| 288 | '$this->numero', |
| 289 | '$this->banco_id', |
| 290 | '$this->link_vale', |
| 291 | '$this->idex100', |
| 292 | '$this->factura', |
| 293 | '$this->remarks', |
| 294 | '$this->alta_por', |
| 295 | '$this->alta_tipo', |
| 296 | '$this->categoria_gasto_id', |
| 297 | '$this->fecha', |
| 298 | '$this->bc_empresa_id', |
| 299 | '$this->numero_original', |
| 300 | '$this->moneda_id', |
| 301 | '$this->withdrawal_autorizado', |
| 302 | '$this->alta_db' $complete_values_a_s)"; |
| 303 | |
| 304 | if($imp) |
| 305 | $sql[] = $tmp3; |
| 306 | else |
| 307 | $sql[] = $tmp1.$tmp2.$tmp3; |
| 308 | |
| 309 | if(!$imp) |
| 310 | $sql[] = "UPDATE banco_cuenta SET ultima_conciliacion=NOW() WHERE banco_cuenta_id=".strit($this->banco_cuenta_id); |
| 311 | |
| 312 | $sql['asignacion'] = []; |
| 313 | if(!empty($this->extraInsertSQL)) |
| 314 | $sql['asignacion'] = $this->extraInsertSQL; |
| 315 | |
| 316 | |
| 317 | if ($agrega_asignacion == true) { |
| 318 | if ($do) { |
| 319 | $sql = array_merge($sql, $querys_asignacion); |
| 320 | } else { |
| 321 | $sql['asignacion'] = array_merge($sql['asignacion'], $querys_asignacion); |
| 322 | } |
| 323 | } |
| 324 | else |
| 325 | $sql = array_merge($sql, $querys_asignacion, $sql['asignacion']); |
| 326 | |
| 327 | if($do) { |
| 328 | unset($sql['asignacion']); |
| 329 | // echo "$this->banco_cuenta_mov_id: <pre>".print_r($sql, true)."</pre>"; |
| 330 | // die(); |
| 331 | if (ia_transaction($sql)) { |
| 332 | ia_errores_a_dime(); |
| 333 | if ($gIAsql['trace']) |
| 334 | ia_errores_a_dime("sql_trace=" . print_r($gIAsql['sql_trace'], true)); |
| 335 | |
| 336 | return false; |
| 337 | } else |
| 338 | return true; |
| 339 | }else |
| 340 | return $sql; |
| 341 | } |
| 342 | |
| 343 | function arreglaCamposparaleeBancoCuentaMov() |
| 344 | { |
| 345 | if(!empty($this->fecha)) $this->fecha = date('d-m-Y H:i:s', strtotime($this->fecha)); else $this->fecha = ''; |
| 346 | if(!empty($this->verificado_el)) $this->verificado_el = date('d-m-Y H:i:s', strtotime($this->verificado_el)); else $this->verificado_el = ''; |
| 347 | if(!empty($this->alta_db)) $this->alta_db = date('d-m-Y H:i:s', strtotime($this->alta_db)); else $this->alta_db = ''; |
| 348 | if(!empty($this->ultimo_cambio)) $this->ultimo_cambio = date('d-m-Y H:i:s', strtotime($this->ultimo_cambio)); else $this->ultimo_cambio = ''; |
| 349 | |
| 350 | if(!empty($this->withdrawal_autorizado_el)) $this->withdrawal_autorizado_el = date('d-m-Y H:i:s', strtotime($this->withdrawal_autorizado_el)); else $this->withdrawal_autorizado_el = ''; |
| 351 | |
| 352 | } |
| 353 | |
| 354 | function arreglaCamposparaguardaBancoCuentaMov() |
| 355 | { |
| 356 | if(!empty($this->fecha)) $this->fecha = date('Y-m-d H:i:s', strtotime($this->fecha)); else $this->fecha = NULL; |
| 357 | if(!empty($this->fecha1)) $this->fecha1 = date('Y-m-d', strtotime($this->fecha1)); else $this->fecha1 = NULL; |
| 358 | if(!empty($this->verificado_el)) $this->verificado_el = date('Y-m-d H:i:s', strtotime($this->verificado_el)); else $this->verificado_el = NULL; |
| 359 | if(!empty($this->ultimo_cambio)) $this->ultimo_cambio = date('Y-m-d H:i:s', strtotime($this->ultimo_cambio)); else $this->ultimo_cambio = NULL; |
| 360 | |
| 361 | if(!empty($this->withdrawal_autorizado_el)) $this->withdrawal_autorizado_el = date('Y-m-d H:i:s', strtotime($this->withdrawal_autorizado_el)); else $this->withdrawal_autorizado_el = NULL; |
| 362 | |
| 363 | if(empty($this->moneda_id)) |
| 364 | $this->moneda_id = ia_singleread("SELECT moneda_id FROM banco_cuenta WHERE banco_cuenta_id = ".strit($this->banco_cuenta_id)); |
| 365 | |
| 366 | //VCA: 07-Nov-2023 se siguen colando unos movimientos de monex a las autorizaciones de Rony. Intento forzarlo |
| 367 | if($this->banco_cuenta_id > 47) {//Son de monex. Los autorizamos automáticamente |
| 368 | $this->withdrawal_autorizado = 'Si'; |
| 369 | } |
| 370 | |
| 371 | } |
| 372 | |
| 373 | function calculaCamposAutomaticos() |
| 374 | { |
| 375 | |
| 376 | global $gIAsql; |
| 377 | if(empty($this->banco_cuenta_id)) |
| 378 | return false; |
| 379 | |
| 380 | $this->banco_cuenta_mov_id = ia_guid(); |
| 381 | |
| 382 | global $arr_DicDatosBanco; |
| 383 | global $gIAParametros; |
| 384 | |
| 385 | if(empty($arr_DicDatosBanco)) |
| 386 | $arr_DicDatosBanco = preparaDiccionarioDatosBanco(); |
| 387 | |
| 388 | // die("<pre>".print_r($arr_DicDatosBanco, true)."</pre>"); |
| 389 | |
| 390 | $this->es = $this->withdrawal > 0 ? 'Retiro':'Deposito'; |
| 391 | |
| 392 | $usuario = "sistema"; //$_SESSION['usuario']; |
| 393 | $usuario_id = $_SESSION['usuario_id']; |
| 394 | $now = date('Y-m-d H:i:s'); |
| 395 | $ya_insertado = false; |
| 396 | $debo_insertar = false; |
| 397 | |
| 398 | if($this->es == 'Retiro') |
| 399 | { |
| 400 | $esListo = false; |
| 401 | |
| 402 | if(!$esListo) |
| 403 | foreach($arr_DicDatosBanco[$this->es] as $vddB) |
| 404 | foreach($vddB['palabra_clave'] as $kw) |
| 405 | if(str_contains($this->numero, $kw) || ($this->alta_tipo == "manual" && str_contains($this->remarks, $kw)))//VCA Captura manual del estado de cuenta. |
| 406 | { |
| 407 | $this->banco_mov_tipo_id = $vddB['banco_mov_tipo_id']; |
| 408 | $tmpDesc = $vddB['agregar_palabra_clave'] == 'Si' ? $kw:''; |
| 409 | $tmpDesc = empty($vddB['descripcion_a_poner']) ? $tmpDesc:$vddB['descripcion_a_poner']." ".$tmpDesc; |
| 410 | $this->remarks = $tmpDesc; |
| 411 | $this->link_vale = $vddB['link_vale']; |
| 412 | $this->withdrawal_autorizado = $vddB['withdrawal_autorizado']; |
| 413 | |
| 414 | $this->categoria_gasto_id = $vddB['categoria_gasto_id']; |
| 415 | |
| 416 | if($this->withdrawal_autorizado == 'Si') |
| 417 | { |
| 418 | $this->withdrawal_autorizado_el = $now; |
| 419 | $this->withdrawal_autorizado_por = 'sistema'; |
| 420 | } |
| 421 | |
| 422 | if($vddB['accion_extra'] == 'FIDUCIARIO') |
| 423 | { |
| 424 | $arr_Fiduciario = array(); |
| 425 | $arr_Fiduciario['fiduciario_id'] = ia_guid(); |
| 426 | $arr_Fiduciario['banco_cuenta_id'] = $this->banco_cuenta_id; |
| 427 | $arr_Fiduciario['empresa_id'] = ia_singleread("SELECT empresa_id FROM banco_cuenta WHERE banco_cuenta_id = ". strit($this->banco_cuenta_id)); |
| 428 | $arr_Fiduciario['banco_cuenta_mov_id'] = $this->banco_cuenta_mov_id = ia_guid(); |
| 429 | $arr_Fiduciario['fecha_retiro'] = date('Y-m-d H:i:s', strtotime($this->fecha));//$this->fecha; |
| 430 | $arr_Fiduciario['referencia_bancaria'] = $this->numero; |
| 431 | $arr_Fiduciario['monto_retiro'] = $this->withdrawal; |
| 432 | $arr_Fiduciario['saldo'] = $this->withdrawal; |
| 433 | $arr_Fiduciario['alta_db'] = $now; |
| 434 | $arr_Fiduciario['alta_por'] = 'sistema'; |
| 435 | |
| 436 | $this->extraInsertSQL[] = ia_insert('fiduciario', $arr_Fiduciario); |
| 437 | |
| 438 | |
| 439 | /** |
| 440 | $myFile = "fiduciario.txt"; |
| 441 | $fh = fopen($myFile, 'a') or die("can't open file"); |
| 442 | $bleh = $this->extraInsertSQL."\r\n"; |
| 443 | fwrite($fh, $bleh); |
| 444 | fclose($fh); |
| 445 | //Debug de VCA. |
| 446 | **/ |
| 447 | } |
| 448 | |
| 449 | if($vddB['accion_extra'] == 'INVERSION') |
| 450 | { |
| 451 | $arr_Fiduciario = array(); |
| 452 | $arr_Fiduciario['inversion_id'] = ia_guid(); |
| 453 | $arr_Fiduciario['banco_cuenta_id'] = $this->banco_cuenta_id; |
| 454 | |
| 455 | $arr_Fiduciario['banco_cuenta_mov_id'] = $this->banco_cuenta_mov_id = ia_guid(); |
| 456 | $arr_Fiduciario['fecha_retiro'] = date('Y-m-d H:i:s', strtotime($this->fecha));//$this->fecha; |
| 457 | $arr_Fiduciario['referencia_bancaria'] = $this->numero_original ?? ""; |
| 458 | $arr_Fiduciario['monto_retiro'] = $this->withdrawal; |
| 459 | $arr_Fiduciario['saldo'] = $this->withdrawal; |
| 460 | //$arr_Fiduciario['usado'] = $this->withdrawal; //Para revisar que no existen en la tabla de inversiones. |
| 461 | // $arr_Fiduciario['banco_destino'] = str_contains($this->numero_original ?? "", 'MONEX') ? 'MONEX' : 'BBVA'; |
| 462 | |
| 463 | $arr_Fiduciario['alta_db'] = $now; |
| 464 | $arr_Fiduciario['alta_por'] = 'sistema'; |
| 465 | $arr_Fiduciario['bloqueado'] = 'MODIFICADO'; |
| 466 | $arr_Fiduciario['indefinida'] = 'Si'; |
| 467 | $arr_Fiduciario['capturado'] = 'Si'; |
| 468 | |
| 469 | |
| 470 | |
| 471 | |
| 472 | $banco_cuenta = ia_singleton("SELECT * FROM banco_cuenta WHERE banco_cuenta_id = ". strit($this->banco_cuenta_id)); |
| 473 | |
| 474 | |
| 475 | |
| 476 | $arr_Fiduciario['empresa_id'] = $banco_cuenta['empresa_id']; |
| 477 | $arr_Fiduciario['tipo_inversion_empresa_privada'] = $banco_cuenta['tipo_inversion_empresa_privada']; |
| 478 | $arr_Fiduciario['moneda_id'] = $banco_cuenta['moneda_id']; |
| 479 | |
| 480 | $arr_Fiduciario['banco_destino'] = ia_singleread("SELECT banco FROM banco WHERE banco_id = " . strit($banco_cuenta['banco_id'])); |
| 481 | |
| 482 | $sql_ = array( |
| 483 | 'remarks' => str_replace("'", "\"",genera_remarks_apertura_inversion($arr_Fiduciario)), |
| 484 | 'link_vale' => 'INV' |
| 485 | ); |
| 486 | $this->extraInsertSQL[] = ia_update('banco_cuenta_mov', $sql_, array('banco_cuenta_mov_id' => $this->banco_cuenta_mov_id)); |
| 487 | |
| 488 | $arr_Fiduciario['remarks'] = $sql_['remarks']; |
| 489 | $this->extraInsertSQL[] = ia_insert('inversion', $arr_Fiduciario); |
| 490 | |
| 491 | $arr_aper_inv = genera_remarks_retiro_inversion($arr_Fiduciario['inversion_id'], $arr_Fiduciario['banco_cuenta_mov_id'], false, false, $arr_Fiduciario); |
| 492 | // foreach($arr_aper_inv['sql'] as $v) |
| 493 | // $sql[] = $v; |
| 494 | $this->extraInsertSQL = array_merge($arr_aper_inv['sql'], $this->extraInsertSQL); |
| 495 | |
| 496 | //@todo Agregar a la bitacora el alta. Problema: Hay que cambiar extraInsertSQL a array(). |
| 497 | |
| 498 | $myFile = "fiduciario.txt"; |
| 499 | $fh = fopen($myFile, 'w') or die("can't open file"); |
| 500 | $bleh = print_r($this->extraInsertSQL, true) ."\r\n"; |
| 501 | fwrite($fh, $bleh); |
| 502 | fclose($fh); |
| 503 | //Debug de VCA. |
| 504 | |
| 505 | } |
| 506 | |
| 507 | if($this->banco_cuenta_id > 47) {//Son de monex. Los autorizamos automáticamente |
| 508 | $this->withdrawal_autorizado = 'Si'; |
| 509 | $debo_insertar = true; |
| 510 | } |
| 511 | |
| 512 | $esListo = true; |
| 513 | break 2; |
| 514 | } |
| 515 | |
| 516 | if(!$esListo) |
| 517 | $this->banco_mov_tipo_id = '17'; //GASTO DE EMPRESA, TAL VEZ FALTAN MÁS FILTROS. |
| 518 | |
| 519 | if($this->banco_cuenta_id > 47) {//Son de monex. Los autorizamos automáticamente |
| 520 | $this->withdrawal_autorizado = 'Si'; |
| 521 | $debo_insertar = true; |
| 522 | } |
| 523 | } |
| 524 | else |
| 525 | { |
| 526 | $esListo = false; |
| 527 | $this->numero_original = empty($this->numero_original) ? "" : $this->numero_original; |
| 528 | |
| 529 | //die("<pre>Antes de revisar: ".print_r($this, true)."</pre>"); |
| 530 | if($this->banco_cuenta_id > 47 && (str_contains($this->numero_original, "DE REVISION") || str_contains($this->numero_original, "GENERICO PRIVADO"))) { //Son de monex. |
| 531 | $this->go = 'NO'; |
| 532 | // die("<pre>Antes de revisar: ".print_r($this, true)."</pre>"); |
| 533 | return false; |
| 534 | } |
| 535 | foreach($arr_DicDatosBanco[$this->es] as $vddB) { |
| 536 | // echo "<pre>vddB" . print_r($vddB, true) . "</pre>"; |
| 537 | foreach ($vddB['palabra_clave'] as $kw) { |
| 538 | //echo "$kw ===== $this->numero_original\r\n"; |
| 539 | if (str_contains($this->numero_original ?? "", $kw) || ($this->alta_tipo == "manual" && str_contains($this->remarks ?? "", $kw))) { |
| 540 | //VCA Captura manual del estado de cuenta. |
| 541 | $this->banco_mov_tipo_id = $vddB['banco_mov_tipo_id']; |
| 542 | $tmpDesc = $vddB['agregar_palabra_clave'] == 'Si' ? $kw : ''; |
| 543 | $tmpDesc = empty($vddB['descripcion_a_poner']) ? $tmpDesc : $vddB['descripcion_a_poner'] . " " . $tmpDesc; |
| 544 | $this->remarks = $tmpDesc; |
| 545 | $this->link_vale = $vddB['link_vale']; |
| 546 | |
| 547 | |
| 548 | if ($vddB['accion_extra'] == 'INVERSION' && $this->banco_cuenta_id > 47) { |
| 549 | $debo_insertar = true; |
| 550 | //VCA 26 Octubre 2023 |
| 551 | //Busco una inversión |
| 552 | $monto_reembolso = $this->deposit; |
| 553 | |
| 554 | $tasa_maxima_inversion = $gIAParametros['tasa_maxima_inversion'] ?? 10.00; |
| 555 | $diferencia_maxima = $monto_reembolso * $tasa_maxima_inversion / 100 / 12; |
| 556 | |
| 557 | $sql_inv = ""; |
| 558 | if (strlen($this->banco_cuenta_id)) |
| 559 | $sql_inv = " i.banco_cuenta_id = " . strit($this->banco_cuenta_id); |
| 560 | |
| 561 | if (strlen($this->fecha)) |
| 562 | $sql_inv .= " AND i.fecha_retiro <= " . strit($this->fecha); |
| 563 | |
| 564 | if (strlen($monto_reembolso)) |
| 565 | $sql_inv .= " AND i.monto_retiro <= " . strit($monto_reembolso) . " AND i.saldo <= " . strit($monto_reembolso) . " AND ($monto_reembolso - i.saldo) < $diferencia_maxima "; |
| 566 | |
| 567 | $sql_inv = "SELECT i.inversion_id, i.banco_cuenta_id, i.empresa_id, DATE_FORMAT(i.fecha_retiro,'%d-%m-%Y') as fecha_retiro, i.monto_retiro, i.monto_isr, i.duracion_dias, i.indefinida, b.nombre, i.saldo |
| 568 | FROM inversion i |
| 569 | LEFT JOIN banco_cuenta b ON i.banco_cuenta_id = b.banco_cuenta_id |
| 570 | WHERE i.capturado = 'Si' AND i.terminado = 'No' AND i.tipo_ganancia_perdida = 'No' |
| 571 | AND ($sql_inv) |
| 572 | ORDER BY i.saldo, i.fecha_retiro LIMIT 1"; |
| 573 | |
| 574 | // echo "<li>$sql_inv"; |
| 575 | //// |
| 576 | // die(); |
| 577 | |
| 578 | $inv_enDB = ia_singleton($sql_inv); |
| 579 | //No hubo inversión disponible, Ciao!!! |
| 580 | if (empty($inv_enDB) || $inv_enDB['monto_retiro'] > $monto_reembolso) { |
| 581 | $esListo = true; |
| 582 | break 2; |
| 583 | } |
| 584 | |
| 585 | // echo "<pre>arr_link_inv" . print_r($inv_enDB, true) . "</pre>"; |
| 586 | $nvoLinkInvID = ia_guid(); |
| 587 | $invlink['inversion_reembolso_id'] = $nvoLinkInvID; |
| 588 | |
| 589 | $invlink['banco_cuenta_id'] = $inv_enDB['banco_cuenta_id']; |
| 590 | $invlink['monto_reembolsado'] = $inv_enDB['monto_retiro']; |
| 591 | $invlink['monto_global_reembolso'] = $monto_reembolso; |
| 592 | $invlink['monto_isr'] = 0.00; //Se puede sacar con un Regexp, pero qué hueva. |
| 593 | $invlink['monto_interes'] = $monto_reembolso - $inv_enDB['monto_retiro']; |
| 594 | $invlink['monto_interes_real'] = $invlink['monto_interes']; |
| 595 | $invlink['fecha_deposito'] = $this->fecha; |
| 596 | $invlink['fecha'] = $now; |
| 597 | |
| 598 | $invlink['alta_db'] = $now; |
| 599 | $invlink['alta_por'] = $usuario; |
| 600 | |
| 601 | $ghost_mov = get_object_vars($this); |
| 602 | // echo "<pre>ghost_mov" . print_r($ghost_mov, true) . "</pre>"; |
| 603 | $arrInfoLink = SolicitaLinkBancario(array |
| 604 | ('link' => $invlink['inversion_reembolso_id'] |
| 605 | , 'link_to' => 'inversion_reembolso' |
| 606 | , 'tienda_id' => '' |
| 607 | , 'withdrawal' => 0 |
| 608 | , 'deposit' => $invlink['monto_global_reembolso'] |
| 609 | , 'cash' => 0 |
| 610 | , 'monto_acta' => $invlink['monto_global_reembolso'] //$jsonFC->monto_global_reembolso Cambia porquo ocupaba todo el depósito y no solo la inversón pagada. |
| 611 | , 'fecha' => $invlink['fecha_deposito'] |
| 612 | , 'banco_mov_tipo_id' => 22 // Id de Inversion A |
| 613 | , 'banco_cuenta_id' => $invlink['banco_cuenta_id'] |
| 614 | , 'idex100' => 0 |
| 615 | , 'idetotal' => 0 |
| 616 | , 'factura' => 'DEVOLUCION' |
| 617 | , 'ivacobradox100' => 0 |
| 618 | , 'ivacobradototal' => 0 |
| 619 | , 'empresa_id' => $inv_enDB['empresa_id'] |
| 620 | , 'factura_numero' => 0 |
| 621 | , 'cash_nota_num' => '' |
| 622 | , 'cliente' => '' |
| 623 | , 'tipo_cash_nota' => '' |
| 624 | , 'cobra_iva' => '' |
| 625 | , 'cash_num_cobro_iva' => '') |
| 626 | , $usuario, 'NO', $ghost_mov); |
| 627 | |
| 628 | // echo "<pre>arrInfoLink" . print_r($arrInfoLink, true) . "</pre>"; |
| 629 | if ($arrInfoLink['vale_acta'] === FALSE || empty($arrInfoLink['link_id']) || empty($arrInfoLink['sql'])) { |
| 630 | ia_errores_a_dime($arrInfoLink); |
| 631 | $esListo = true; |
| 632 | break 2; |
| 633 | } |
| 634 | $sql = []; |
| 635 | foreach ($arrInfoLink['sql'] as $v) |
| 636 | $sql[] = $v; |
| 637 | |
| 638 | $bcm_id = $arrInfoLink['bcm_id']; |
| 639 | foreach ($sql as &$s) |
| 640 | $s = str_replace("#@#@BCMID#@#@", $bcm_id, $s); |
| 641 | |
| 642 | //Agregamos el renglón del Inversion Reembolsado. |
| 643 | $invlink['banco_cuenta_mov_id'] = $arrInfoLink['bcm_id']; |
| 644 | $invlink['banco_cuenta_mov_link_id'] = $arrInfoLink['link_id']; |
| 645 | $invlink['numero_referencia'] = $arrInfoLink['ref_num']; |
| 646 | $invlink['inversion_id'] = $inv_enDB['inversion_id']; |
| 647 | |
| 648 | $invlink['empresa_id'] = $inv_enDB['empresa_id']; |
| 649 | |
| 650 | $sql[] = ia_insert('inversion_reembolso', $invlink); |
| 651 | |
| 652 | $inv_ND['bloqueado'] = 'MODIFICADO'; |
| 653 | $inv_ND['fecha_terminado'] = $now; |
| 654 | $inv_ND['terminado'] = 'Si'; |
| 655 | |
| 656 | $inv_ND['inversion_reembolso_id'] = $nvoLinkInvID; |
| 657 | |
| 658 | |
| 659 | $inv_ND['monto_reembolsado'] = $inv_enDB['monto_retiro']; |
| 660 | $inv_ND['fecha_reembolsado'] = $invlink['fecha_deposito']; |
| 661 | |
| 662 | //VCA Error al recalcular el saldo. Si cancelan un link el saldo queda mayor y nunca se paga. |
| 663 | //$iFN['saldo'] = (($ienDB['saldo'] - $invlink['monto_reembolsado']) + $invlink['monto_interes']) - $invlink['monto_isr']; |
| 664 | |
| 665 | //VCA 13-10-2021 inversión con pérdida. |
| 666 | |
| 667 | $inv_ND['saldo'] = $inv_enDB['saldo'] - $invlink['monto_reembolsado']; |
| 668 | $inv_ND['monto_interes'] = $invlink['monto_interes']; |
| 669 | |
| 670 | // echo "<pre>".$ienDB['monto_isr']." + ".$invlink['monto_isr']."</pre>"; exit; |
| 671 | |
| 672 | $inv_ND['monto_isr'] = $invlink['monto_isr']; |
| 673 | |
| 674 | $inv_ND['monto_interes_real'] = $inv_ND['monto_interes'] - $inv_ND['monto_isr']; |
| 675 | |
| 676 | |
| 677 | $inv_sql = haz_update_con_log($inv_ND, $inv_enDB, 'inversion', 'inversion_id', $inv_enDB['inversion_id']); |
| 678 | foreach ($inv_sql as $v) |
| 679 | $sql[] = $v; |
| 680 | |
| 681 | // echo "<pre>sql" . print_r($sql, true) . "</pre>"; |
| 682 | |
| 683 | if (!$this->insertaBancoCuentaMov(true, false, false)) { |
| 684 | ia_errores_a_dime(); |
| 685 | $esListo = true; |
| 686 | break 2; |
| 687 | } |
| 688 | if (ia_transaction($sql)) { |
| 689 | ia_errores_a_dime(); |
| 690 | $esListo = true; |
| 691 | break 2; |
| 692 | } |
| 693 | $ya_insertado = true; |
| 694 | $this->go = 'NO'; //Con esto el importador ignora este registro. |
| 695 | //Aquí calcula los remarks de APERTURA de inversión, del movimiento original de retiro en el banco y del depósito de reembolso |
| 696 | $sql_ = array(); |
| 697 | $arr_aper_inv = genera_remarks_retiro_inversion($inv_enDB['inversion_id'], "", false, false); |
| 698 | // foreach($arr_aper_inv['sql'] as $v) |
| 699 | // $sql[] = $v; |
| 700 | $sql_ = array_merge($arr_aper_inv['sql'], $sql_); |
| 701 | |
| 702 | $arr_bcm_inv_link = genera_remarks_reembolso_inversion($invlink['banco_cuenta_mov_id'], false, false); |
| 703 | //// foreach($arr_bcm_inv_link['sql'] as $v) |
| 704 | //// $sql[] = $v; |
| 705 | $sql_ = array_merge($arr_bcm_inv_link['sql'], $sql_); |
| 706 | // |
| 707 | $sql_[] = insert_update_links_al_banco_live(inversion_reembolso_id: $nvoLinkInvID); |
| 708 | if (ia_transaction($sql_)) { |
| 709 | ia_errores_a_dime(); |
| 710 | $esListo = true; |
| 711 | break 2; |
| 712 | } |
| 713 | $myFile = "inversion_reembolso_link_automatico.txt"; |
| 714 | $fh = fopen($myFile, 'a') or die("can't open file"); |
| 715 | $bleh = "sql" . print_r($sql, true) . "\r\n"; |
| 716 | $bleh .= "sql_" . print_r($sql_, true) . "\r\n"; |
| 717 | $bleh .= "arr_aper_inv" . print_r($arr_aper_inv, true) . "\r\n"; |
| 718 | $bleh .= "invlink" . print_r($invlink, true) . "\r\n"; |
| 719 | $bleh .= "inv_sql" . print_r($inv_sql, true) . "\r\n"; |
| 720 | fwrite($fh, $bleh); |
| 721 | fclose($fh); |
| 722 | //Debug de VCA. |
| 723 | |
| 724 | } |
| 725 | |
| 726 | $esListo = true; |
| 727 | break 2; |
| 728 | } |
| 729 | |
| 730 | |
| 731 | } |
| 732 | } |
| 733 | if(!$esListo) |
| 734 | $this->banco_mov_tipo_id = '2'; //DEPOSITO CON COMISIÓN, TAL VEZ FALTAN MÁS FILTROS. |
| 735 | |
| 736 | |
| 737 | } |
| 738 | |
| 739 | //Para saber si el link_vale |
| 740 | if(empty($this->link_vale)) |
| 741 | { |
| 742 | switch($this->banco_mov_tipo_id) |
| 743 | { |
| 744 | case '6': case '11': case '10': |
| 745 | $this->link_vale = 'SYS'; |
| 746 | break; |
| 747 | |
| 748 | case '2': |
| 749 | $this->link_vale = 'Q'; |
| 750 | break; |
| 751 | |
| 752 | default: |
| 753 | $this->link_vale = 'ND'; |
| 754 | break; |
| 755 | } |
| 756 | } |
| 757 | |
| 758 | if($debo_insertar && !$ya_insertado){ |
| 759 | |
| 760 | // echo "<pre>vddB" . print_r($this, true) . "</pre>"; |
| 761 | if (!$this->insertaBancoCuentaMov(true, false, false)) { |
| 762 | ia_errores_a_dime(); |
| 763 | } |
| 764 | if($this->banco_mov_tipo_id == 22 || $this->banco_mov_tipo_id == 23){ |
| 765 | |
| 766 | } |
| 767 | $this->go = 'NO'; //Con esto el importador ignora este registro. |
| 768 | } |
| 769 | ia_errores_a_dime(); |
| 770 | return true; |
| 771 | } |
| 772 | } |