Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 179 |
|
0.00% |
0 / 5 |
CRAP | n/a |
0 / 0 |
|
| actualizaInversionesAtrasadas | |
0.00% |
0 / 25 |
|
0.00% |
0 / 1 |
6 | |||
| bcm_retiro_es_inversion | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
6 | |||
| genera_remarks_retiro_inversion | |
0.00% |
0 / 80 |
|
0.00% |
0 / 1 |
756 | |||
| genera_remarks_apertura_inversion | |
0.00% |
0 / 16 |
|
0.00% |
0 / 1 |
42 | |||
| genera_remarks_reembolso_inversion | |
0.00% |
0 / 54 |
|
0.00% |
0 / 1 |
210 | |||
| 1 | <?php |
| 2 | |
| 3 | function actualizaInversionesAtrasadas() |
| 4 | { |
| 5 | global $gIAParametros; |
| 6 | |
| 7 | $tipo_inversion_empresa_privada = array('empresa', 'privada'); |
| 8 | |
| 9 | foreach($tipo_inversion_empresa_privada as $tipo_inv) { |
| 10 | |
| 11 | //Por expirar: mañana expiran. |
| 12 | $sql1 = "SELECT COUNT(DISTINCT(inversion_id)) FROM inversion |
| 13 | WHERE (DATEDIFF(solicitud_reembolso_fecha,NOW()) - $gIAParametros[dias_para_solicitar_reembolso_inversion] = 0) AND indefinida <> 'Si' AND capturado = 'Si' AND terminado = 'No' AND (inversion_reembolso_id IS NULL OR inversion_reembolso_id = '') AND tipo_inversion_empresa_privada = '$tipo_inv'"; |
| 14 | |
| 15 | //Expirados. |
| 16 | $sql3 = "SELECT COUNT(DISTINCT(inversion_id)) as ExpUrgente FROM inversion |
| 17 | WHERE (DATEDIFF(solicitud_reembolso_fecha,NOW()) - $gIAParametros[dias_para_solicitar_reembolso_inversion] < 0) AND indefinida <> 'Si' AND capturado = 'Si' AND terminado = 'No' AND (inversion_reembolso_id IS NULL OR inversion_reembolso_id = '') AND tipo_inversion_empresa_privada = '$tipo_inv'"; |
| 18 | |
| 19 | $sql4 = "SELECT COUNT(bloqueado) FROM inversion WHERE bloqueado IN ('MODIFICADO','AMBOSMOD','CONTMOD') AND tipo_inversion_empresa_privada = '$tipo_inv'"; |
| 20 | $sql4 = "SELECT COUNT(bloqueado) FROM inversion WHERE bloqueado IN ('MODIFICADO','AMBOSMOD','CONTMOD') AND terminado = 'No' AND (inversion_reembolso_id = '' OR inversion_reembolso_id IS NULL) AND tipo_inversion_empresa_privada = '$tipo_inv'"; |
| 21 | $sql5 = "SELECT COUNT(error) FROM inversion WHERE error IN ('Si','Pa') AND tipo_inversion_empresa_privada = '$tipo_inv'"; |
| 22 | $sql6 = "SELECT COUNT(capturado) FROM inversion WHERE capturado IN ('No') AND tipo_inversion_empresa_privada = '$tipo_inv'"; |
| 23 | |
| 24 | $InvExp = ia_singleread($sql1); |
| 25 | |
| 26 | $InvExpUrg = ia_singleread($sql3); |
| 27 | $InvBloq = ia_singleread($sql4); |
| 28 | $InvErr = ia_singleread($sql5); |
| 29 | $InvCap = ia_singleread($sql6); |
| 30 | |
| 31 | $sql = array(); |
| 32 | |
| 33 | $sql[] = "INSERT INTO campos_exists (campo_id, valor, tabla_exists, tabla_origen) VALUES(1, $InvExp, 'expirados_sin_solicitud', 'inversion$tipo_inv') ON DUPLICATE KEY UPDATE valor=$InvExp"; |
| 34 | |
| 35 | $sql[] = "INSERT INTO campos_exists (campo_id, valor, tabla_exists, tabla_origen) VALUES(1, $InvExpUrg, 'expirados_urgentes', 'inversion$tipo_inv') ON DUPLICATE KEY UPDATE valor=$InvExpUrg"; |
| 36 | $sql[] = "INSERT INTO campos_exists (campo_id, valor, tabla_exists, tabla_origen) VALUES(1, $InvBloq, 'bloqueado', 'inversion$tipo_inv') ON DUPLICATE KEY UPDATE valor=$InvBloq"; |
| 37 | $sql[] = "INSERT INTO campos_exists (campo_id, valor, tabla_exists, tabla_origen) VALUES(1, $InvErr, 'error', 'inversion$tipo_inv') ON DUPLICATE KEY UPDATE valor=$InvErr"; |
| 38 | $sql[] = "INSERT INTO campos_exists (campo_id, valor, tabla_exists, tabla_origen) VALUES(1, $InvCap, 'capturado', 'inversion$tipo_inv') ON DUPLICATE KEY UPDATE valor=$InvCap"; |
| 39 | |
| 40 | // JJDPL 13-04-2021 |
| 41 | $sql_ = "SELECT COUNT(bloqueado) FROM inversion WHERE bloqueado IN ('MODIFICADO','AMBOSMOD','CONTMOD') AND terminado = 'Si' AND (inversion_reembolso_id != '' OR inversion_reembolso_id IS NOT NULL) AND tipo_inversion_empresa_privada = '$tipo_inv'"; |
| 42 | $InvModReem = ia_singleread($sql_); |
| 43 | $sql[] = "INSERT INTO campos_exists (campo_id, valor, tabla_exists, tabla_origen) VALUES(1, $InvModReem, 'modificados_con_reembolso', 'inversion$tipo_inv') ON DUPLICATE KEY UPDATE valor=$InvModReem"; |
| 44 | |
| 45 | /** |
| 46 | * $myFile = "actualizainversionsAtrasados.txt"; |
| 47 | * $fh = fopen($myFile, 'w') or die("can't open file"); |
| 48 | * $bleh = "<pre>".print_r($sql, true)."</pre>"; |
| 49 | * fwrite($fh, $bleh); |
| 50 | * fclose($fh); |
| 51 | **/ |
| 52 | echo "<pre>".print_r($sql, true)."</pre>"; |
| 53 | |
| 54 | ia_transaction($sql); |
| 55 | } |
| 56 | } |
| 57 | |
| 58 | /** |
| 59 | * @param string $bcm_id banco_cuenta_mov_id |
| 60 | * @return bool |
| 61 | */ |
| 62 | function bcm_retiro_es_inversion($bcm_id = ''){ |
| 63 | $es = false; |
| 64 | |
| 65 | if(empty($bcm_id)) |
| 66 | return $es; |
| 67 | |
| 68 | $es = ia_singleread("SELECT COUNT(*) FROM inversion WHERE banco_cuenta_mov_id = " . strit($bcm_id)); |
| 69 | |
| 70 | return $es; |
| 71 | } |
| 72 | |
| 73 | /** Genera una descripción y detalle de los links que tiene una inversión. |
| 74 | * Actualiza los remarks del retiro en el banco, la apertura de inversión y de los reembolsos de inversión. |
| 75 | * Regresa un array con |
| 76 | * @param string $inv_id |
| 77 | * @param string $bcm_id |
| 78 | * @param bool $do_SQL |
| 79 | * @param bool $debug |
| 80 | * @return array |
| 81 | */ |
| 82 | function genera_remarks_retiro_inversion($inv_id = '', $bcm_id = '', $do_SQL = false, $debug = false, $inv_en_DB = array(), $remarks_por_usuario = "") |
| 83 | { |
| 84 | //@todo cambiar debug por guardar en un archivo (copiar codigo de los repetidos) |
| 85 | $sql = array(); |
| 86 | $arr_ret = array(); |
| 87 | |
| 88 | if(empty($bcm_id) && empty($inv_id)) |
| 89 | return $sql; |
| 90 | |
| 91 | $txt_bcm_id = !empty($bcm_id) ? " OR banco_cuenta_mov_id = " . strit($bcm_id) : ""; |
| 92 | //Traigo la inversión de la BD. La leo con su id con el id del retiro. Están ligados uno a uno. |
| 93 | $inv_en_DB = empty($inv_en_DB) ? ia_singleton("SELECT * FROM inversion WHERE inversion_id = " . strit($inv_id) . $txt_bcm_id) : $inv_en_DB; |
| 94 | |
| 95 | $vx_remarks = $inv_en_DB['remarks'] ?? ''; |
| 96 | //$vx_remarks = ""; //Bug. no dejamos poner remarks por el momento. |
| 97 | |
| 98 | $vx_remarks = strpos($vx_remarks, "<hr>") !== false ? substr($vx_remarks, 0, strpos($vx_remarks, "<hr>")) : ""; |
| 99 | |
| 100 | $bcm_id = empty($bcm_id) ? $inv_en_DB['banco_cuenta_mov_id'] : $bcm_id; |
| 101 | // $bcm_retiro_en_DB = ia_singleton("SELECT * FROM banco_cuenta_mov WHERE banco_cuenta_mov_id = " . strit($bcm_id)); |
| 102 | |
| 103 | $inv_id = $inv_en_DB['inversion_id']; |
| 104 | // $bcm_id = $inv_en_DB['banco_cuenta_mov_id']; |
| 105 | |
| 106 | $remarks_aper_inv = ""; |
| 107 | $remarks_inv_links = ""; |
| 108 | $saldo = $inv_en_DB['monto_retiro']; //El capital que retitaron |
| 109 | |
| 110 | //Podemos referirnos a retiro, tanto como al retiro en el banco como al movimiento inversión. |
| 111 | //Este retiro puede tener 0 o más links de reembolso. |
| 112 | |
| 113 | //En esta llave ponemos los remarks que lleva la apertura de inversión. |
| 114 | //Que es: la descripción de la inversión más los links que tenga. |
| 115 | $arr_ret['remarks_aper_inv'][$inv_id] = ""; |
| 116 | |
| 117 | $ol = "</ol><ul>"; |
| 118 | $remarks_aper_inv = "APERTURA DE INVERSION" . (strpos($inv_en_DB['referencia_bancaria'],"MANUAL") !== false ? " MANUAL" : ""); |
| 119 | |
| 120 | if($inv_en_DB['indefinida'] == 'Si') |
| 121 | { |
| 122 | $duracion = $ti_remarks = " INDEFINIDA"; |
| 123 | } |
| 124 | else |
| 125 | { |
| 126 | $duracion = $inv_en_DB['duracion_dias']; |
| 127 | $fecha_retiro = $inv_en_DB['fecha_retiro']; |
| 128 | $fecha_expiracion = $inv_en_DB['solicitud_reembolso_fecha']; |
| 129 | $fecha_expiracion = get_date_spanish(strtotime($fecha_expiracion), false, 'mini_date'); |
| 130 | $duracion = " A $duracion DIAS"; |
| 131 | $ti_remarks = "$duracion. (VENCE EL $fecha_expiracion)"; |
| 132 | } |
| 133 | |
| 134 | $remarks_aper_inv .= $ti_remarks; |
| 135 | |
| 136 | //Banco destino y tasa de interés pactada. Lo agregaremos al título que nos regresa preparaRemarksBCM(); |
| 137 | $remarks_extra = "<span class=\"bold txt12px\">$ti_remarks CON </span><span class=\"txt_bold_blue txt14px\">" . $inv_en_DB['banco_destino'] . "</span>, <span class=\"bold txt12px\">" . ($inv_en_DB['tipo_inversion'] ?? "") ."</span> <span class=\"txt_bold_blue txt14px\">" . echonf($inv_en_DB['tasa_interes_anual'] ?? 0.00, true) ." % </span>"; |
| 138 | |
| 139 | $vx_remarks = !empty($vx_remarks) ? "<strong>$vx_remarks</strong><hr>" : ""; |
| 140 | //Leo los links |
| 141 | $arr_links = ia_sqlArrayIndx("SELECT * FROM inversion_reembolso WHERE activo = 'Si' AND inversion_id = " .strit($inv_id) . " ORDER BY alta_db ASC"); |
| 142 | //echo "<pre>".print_r($arr_links, true)."</pre>"; |
| 143 | |
| 144 | if(!empty($arr_links) && is_array($arr_links)){ |
| 145 | foreach($arr_links as $k=>$inv_link_en_DB) { |
| 146 | //echo "<pre>$k:".print_r($v, true)."</pre>"; |
| 147 | |
| 148 | $saldo -= ($inv_link_en_DB['monto_reembolsado'] + $inv_link_en_DB['monto_interes'] - $inv_link_en_DB['monto_isr']); |
| 149 | |
| 150 | if($saldo < 0) { |
| 151 | $saldo = 0; |
| 152 | } |
| 153 | |
| 154 | $parcial = ""; |
| 155 | if($saldo == 0) |
| 156 | $parcial = " TERMINADA"; |
| 157 | else |
| 158 | $parcial = " PARCIAL"; |
| 159 | |
| 160 | $remarks_por_link = '<table class="noborders" style="width: 270px; padding: 0;"><tr><td class="noborders row_altura_10px" colspan="2">'; |
| 161 | |
| 162 | $txt_inversion = "$" . echonf($inv_link_en_DB['monto_reembolsado'], true); |
| 163 | $txt_intereses = "$" . echonf($inv_link_en_DB['monto_interes'], true); |
| 164 | $txt_isr = "$" . echonf($inv_link_en_DB['monto_isr'], true); |
| 165 | $txt_intereses_real = "$" . echonf($inv_link_en_DB['monto_interes'] - $inv_link_en_DB['monto_isr'], true); |
| 166 | |
| 167 | $parcial .= ( $inv_link_en_DB['monto_reembolsado'] != $inv_en_DB['monto_reembolsado'] ? PHP_EOL . "(". echonf($inv_en_DB['monto_reembolsado'], true) .")" : ""); //VCA Bajar para abajo. |
| 168 | |
| 169 | |
| 170 | //Este link nos lleva a inversion_reembolso.php, donde se pueden cancelar los Links de Inversión |
| 171 | $remarks_por_link .= "<a title=\"Ir al Link de Inversión\" href=\"../backoffice/inversion_reembolso.php?inversion_reembolso_id=$inv_link_en_DB[inversion_reembolso_id]\" target=\"_blank\"><span class=\"bold txt16px\">LINK DE INVERSIÓN$parcial </span></a></td></tr><tr>"; |
| 172 | |
| 173 | $a_dep_reem = "<a title=\"Ir al Depósito en el banco\" href=\"../cobranza/edocta.php?banco_cuenta_id=$inv_link_en_DB[banco_cuenta_id]&banco_cuenta_mov_id=$inv_link_en_DB[banco_cuenta_mov_id]\" target=\"_blank\"><span class=\"txt_bold_blue txt15px\">"; |
| 174 | $remarks_por_link .= "<td class=\"txt_left_aligned noborders row_altura_10px\">". $a_dep_reem ."DEPÓSITO:</span></a></td><td class=\"txt_right_aligned noborders row_altura_10px\">$a_dep_reem$". echonf($inv_link_en_DB['monto_global_reembolso'], true) ."</span></a></td></tr><tr>"; |
| 175 | |
| 176 | $a_todo_a_banco = "<a title=\"Ir a Todo al Banco\" href=\"../backoffice/todo_a_banco_list.php?cuentat_a_banco_id=$inv_link_en_DB[inversion_reembolso_id]\" target=\"_blank\"><span class=\"txt_bold_red txt15px\">"; |
| 177 | $remarks_por_link .= "<td class=\"txt_left_aligned noborders row_altura_10px\">". $a_todo_a_banco ."INVERSIÓN:</span></a></td><td class=\"txt_right_aligned noborders row_altura_10px\"><span class=\"txt_bold_red txt15px\">$a_todo_a_banco$txt_inversion</span></a></td></tr><tr>"; |
| 178 | |
| 179 | $a_aper_inver = "<a title=\"Ir a la apertura de inversión\" href=\"../backoffice/inversion_list.php?inversion_id=$inv_en_DB[inversion_id]\" target=\"_blank\"><span class=\"txt_bold_orange txt15px\">"; |
| 180 | $remarks_por_link .= "<td class=\"txt_left_aligned noborders row_altura_10px\">". $a_aper_inver ."INTERÉS:</a></td><td class=\"txt_right_aligned noborders row_altura_10px\">$a_aper_inver$txt_intereses</span></a></td></tr><tr>"; |
| 181 | |
| 182 | $a_isr = "<a title=\"Ir a la apertura de inversión\" href=\"../backoffice/inversion_list.php?inversion_id=$inv_en_DB[inversion_id]\" target=\"_blank\"><span class=\"txt_bold_orange txt15px\">"; |
| 183 | $remarks_por_link .= "<td class=\"txt_left_aligned noborders row_altura_10px\">". $a_isr . "ISR:</span></a></td><td class=\"txt_right_aligned noborders row_altura_10px\">$a_isr$txt_isr</span></a></td></tr><tr>"; |
| 184 | |
| 185 | $a_interes_real = "<a title=\"Ir al retiro del banco\" href=\"../backoffice/withdrawals_de_banco_list.php?bc_mov_id=$inv_en_DB[banco_cuenta_mov_id]\" target=\"_blank\"><span class=\"txt_bold_purple txt15px\">"; |
| 186 | $remarks_por_link .= "<td class=\"txt_left_aligned noborders row_altura_10px\">". $a_interes_real . "INT. REAL:</a></td><td class=\"txt_right_aligned noborders row_altura_10px\">$a_interes_real$txt_intereses_real</span></a></td></tr></table>"; |
| 187 | |
| 188 | $remarks_inv_links .= $remarks_por_link . PHP_EOL; |
| 189 | $arr_ret['remarks_inv_links'][$inv_link_en_DB['inversion_reembolso_id']] = $remarks_por_link; |
| 190 | |
| 191 | $inv_link_ND = ['remarks' => $remarks_por_link]; |
| 192 | $sql_inv_link_remarks = haz_update_con_log($inv_link_ND, $inv_link_en_DB, "inversion_reembolso", "inversion_reembolso_id", $inv_link_en_DB['inversion_reembolso_id']); |
| 193 | |
| 194 | if(is_array($sql_inv_link_remarks) && !empty($sql_inv_link_remarks)) |
| 195 | foreach($sql_inv_link_remarks as $ilr) |
| 196 | $sql[] = $ilr; |
| 197 | } |
| 198 | |
| 199 | $remarks_ok = array(); |
| 200 | |
| 201 | // preparaRemarksBCM($bcm_id, $remarks_aper_inv . PHP_EOL . $remarks_inv_links, "", "", $remarks_ok, true, false); |
| 202 | |
| 203 | //Buscamos si quedó terminada y cambiamos {VENCE} por VENCIÓ o dejamos VENCE |
| 204 | // if (strpos($remarks_ok['titulo'], "TERMINADA") !== false) |
| 205 | // $remarks_extra = str_replace("{VENCE}", "VENCIÓ", $remarks_extra); |
| 206 | // else |
| 207 | // $remarks_extra = str_replace("{VENCE}", "VENCE", $remarks_extra); |
| 208 | //echo "<pre>remarks_ok".print_r($remarks_ok, true)."</pre>"; |
| 209 | |
| 210 | // $remarks_aper_inv = $remarks_ok['titulo'] . $remarks_extra . PHP_EOL . $remarks_inv_links; |
| 211 | |
| 212 | |
| 213 | |
| 214 | /*echo "<br>=====================================================<br>"; |
| 215 | echo $remarks_aper_inv;*/ |
| 216 | //echo $arr_return['remarks']; |
| 217 | |
| 218 | |
| 219 | } |
| 220 | // else{ |
| 221 | //if(empty($arr_links)) |
| 222 | $remarks_aper_inv = genera_remarks_apertura_inversion($inv_en_DB); |
| 223 | // } |
| 224 | |
| 225 | $remarks_aper_inv .= PHP_EOL . $remarks_inv_links; |
| 226 | |
| 227 | $remarks_aper_inv = "$vx_remarks<div style='width: 300px;'>" . $remarks_aper_inv . "</div>"; |
| 228 | |
| 229 | $arr_ret['remarks_aper_inv'][$inv_id] = $remarks_aper_inv; |
| 230 | $arr_ret['remarks_retiro_inv'][$bcm_id] = $remarks_aper_inv; |
| 231 | |
| 232 | $bcm_inv_ret_ND = ['remarks' => $remarks_aper_inv]; |
| 233 | $bcm_inv_ret_enDB = array(); |
| 234 | $sql_bcm_inv_ret_remarks = haz_update_con_log($bcm_inv_ret_ND, $bcm_inv_ret_enDB, "banco_cuenta_mov", "banco_cuenta_mov_id", $bcm_id); |
| 235 | |
| 236 | if(is_array($sql_bcm_inv_ret_remarks) && !empty($sql_bcm_inv_ret_remarks)) |
| 237 | foreach($sql_bcm_inv_ret_remarks as $r) |
| 238 | $sql[] = $r; |
| 239 | |
| 240 | $aper_inv_ret_ND = ['remarks' => $remarks_aper_inv]; |
| 241 | $aper_inv_ret_enDB = array(); |
| 242 | $sql_aper_inv_ret_remarks = haz_update_con_log($aper_inv_ret_ND, $aper_inv_ret_enDB, "inversion", "inversion_id", $inv_id); |
| 243 | |
| 244 | if(is_array($sql_aper_inv_ret_remarks) && !empty($sql_aper_inv_ret_remarks)) |
| 245 | foreach($sql_aper_inv_ret_remarks as $q) |
| 246 | $sql[] = $q; |
| 247 | |
| 248 | |
| 249 | $arr_ret['sql'] = $sql; |
| 250 | // $arr_ret['remarks_aper_inv'] = $remarks_aper_inv; |
| 251 | |
| 252 | if($do_SQL) |
| 253 | if(ia_transaction($sql)) |
| 254 | ia_errores_a_dime(); |
| 255 | |
| 256 | |
| 257 | return $arr_ret; |
| 258 | |
| 259 | } |
| 260 | /** Genera una descripción y detalle de los links que tiene una inversión. |
| 261 | * Actualiza los remarks del retiro en el banco, la apertura de inversión y de los reembolsos de inversión. |
| 262 | * Regresa un array con |
| 263 | * @param array $inv_en_DB |
| 264 | |
| 265 | * @return string |
| 266 | */ |
| 267 | function genera_remarks_apertura_inversion($inv_en_DB = array()){ |
| 268 | |
| 269 | $remarks_aper_inv = ""; |
| 270 | |
| 271 | if(empty($inv_en_DB)) |
| 272 | return $remarks_aper_inv; |
| 273 | |
| 274 | $inv_en_DB['indefinida'] = $inv_en_DB['indefinida'] ?? 'Si'; |
| 275 | $inv_en_DB['tasa_interes_anual'] = $inv_en_DB['tasa_interes_anual'] ?? 0; |
| 276 | $inv_en_DB['tipo_inversion'] = $inv_en_DB['tipo_inversion'] ?? ''; |
| 277 | $inv_en_DB['solicitud_reembolso_fecha'] = $inv_en_DB['solicitud_reembolso_fecha'] ?? ''; |
| 278 | $inv_en_DB['duracion_dias'] = $inv_en_DB['duracion_dias'] ?? 0; |
| 279 | |
| 280 | |
| 281 | $remarks_aper_inv = "<strong class='txt18pxfr txt_bold_red txt_centered' style='min-width: 335px;'>APERTURA DE INVERSION CON ALTA</strong>"; |
| 282 | |
| 283 | if($inv_en_DB['indefinida'] == 'Si') |
| 284 | { |
| 285 | $ti_remarks = " INDEFINIDA"; |
| 286 | } |
| 287 | else |
| 288 | { |
| 289 | $duracion = $inv_en_DB['duracion_dias'] ?? 0; |
| 290 | $fecha_expiracion = $inv_en_DB['solicitud_reembolso_fecha'] ?? ''; |
| 291 | $fecha_expiracion = empty($fecha_expiracion) ? '' : get_date_spanish(strtotime($fecha_expiracion), false, 'mini_date'); |
| 292 | $duracion = empty($duracion) ? '' : " A $duracion DIAS"; |
| 293 | $ti_remarks = empty($duracion) ? '' : "$duracion. (VENCE EL $fecha_expiracion)"; |
| 294 | } |
| 295 | $remarks_aper_inv .= PHP_EOL; |
| 296 | |
| 297 | //Banco destino y tasa de interés pactada. Lo agregaremos al título que nos regresa preparaRemarksBCM(); |
| 298 | $remarks_extra = "<a href='../backoffice/inversion_list.php?inversion_id=" . $inv_en_DB['inversion_id'] ."' target='_blank'><span class=\"bold txt12px\">$ti_remarks CON </span><span class=\"txt_bold_blue txt14px\">" . $inv_en_DB['banco_destino'] . "</span>, <span class=\"bold txt12px\">" . $inv_en_DB['tipo_inversion'] ."</span> <span class=\"txt_bold_blue txt14px\">" . echonf($inv_en_DB['tasa_interes_anual'], true) ." % </span></a>"; |
| 299 | |
| 300 | return $remarks_aper_inv . $remarks_extra; |
| 301 | |
| 302 | } |
| 303 | |
| 304 | /** |
| 305 | * Genera los remarks de las inversiones pagadas con un depósito. Genera la consulta SQL y puede o no ejecutarla. |
| 306 | * |
| 307 | * @param string $bcm_id banco_cuenta_mov_id del del depósito que pagó la inversión. |
| 308 | * @param bool $do_SQL |
| 309 | * @param bool $debug |
| 310 | * @return array $arr_return = array('remarks'=>'','sql'=>'','inv_link_remarks'=>array()); |
| 311 | */ |
| 312 | function genera_remarks_reembolso_inversion($bcm_id = '', $do_SQL = false, $debug = false) |
| 313 | { |
| 314 | //@todo cambiar debug por guardar en un archivo (copiar codigo de los repetidos) |
| 315 | $sql = array(); |
| 316 | $arr_ret = array(); |
| 317 | |
| 318 | if(empty($bcm_id)) |
| 319 | return $sql; |
| 320 | |
| 321 | $preQuery= "SELECT COUNT(*) FROM inversion_reembolso WHERE activo='Si' AND banco_cuenta_mov_id = " . strit($bcm_id); |
| 322 | $cntReembolso = ia_singleread($preQuery); |
| 323 | // -- $inv_en_DB = ia_singleton("SELECT * FROM inversion WHERE inversion_id = " . strit($inv_id) . " OR banco_cuenta_mov_id = " . strit($bcm_id)); |
| 324 | if($cntReembolso == 0){ |
| 325 | return $arr_ret; |
| 326 | } |
| 327 | |
| 328 | $bcm_reembolso_en_DB = ia_singleton("SELECT * FROM banco_cuenta_mov WHERE banco_cuenta_mov_id = " . strit($bcm_id)); |
| 329 | |
| 330 | $bcm_id = $bcm_reembolso_en_DB['banco_cuenta_mov_id']; |
| 331 | |
| 332 | $remarks_reembolso_inv = ""; |
| 333 | $remarks_inv_links = ""; |
| 334 | |
| 335 | //Podemos referirnos a retiro, tanto como al retiro en el banco como al movimiento inversión. |
| 336 | //Este retiro puede tener 0 o más links de reembolso. |
| 337 | |
| 338 | //En esta llave ponemos los remarks que lleva la apertura de inversión. |
| 339 | //Que es: la descripción de la inversión más los links que tenga. |
| 340 | $arr_ret['remarks_reembolso_inv'][$bcm_id] = ""; |
| 341 | |
| 342 | //Leo los links de este depósito $bcm_id |
| 343 | $arr_links = ia_sqlArrayIndx("SELECT * FROM inversion_reembolso WHERE activo = 'Si' AND banco_cuenta_mov_id = " .strit($bcm_id) . " ORDER BY alta_db ASC"); |
| 344 | |
| 345 | $remarks_inv_links = ""; |
| 346 | if(!empty($arr_links) && is_array($arr_links)) |
| 347 | foreach($arr_links as $k=>$inv_link_en_DB) { |
| 348 | //echo "<pre>$k:".print_r($v, true)."</pre>"; |
| 349 | |
| 350 | $remarks_por_link = ""; |
| 351 | //Leemos la inversión de este link de reembolso $inv_link_en_DB |
| 352 | $inv_en_DB = ia_singleton("SELECT * FROM inversion WHERE inversion_id = " . strit($inv_link_en_DB["inversion_id"])); |
| 353 | //El saldo es el monto de la apertura de inversión (el capital que invertimos) |
| 354 | $saldo = $inv_en_DB['monto_retiro']; |
| 355 | |
| 356 | //Restamos del saldo, el monto del capital retornado, el interés y sumamos el ISR. Por ejemplo, invertimos 1000. Nos regresaron 1000 (capital) + 200 (interés) - 100 (ISR). Nos regresaron 1100, e invertimos 1000. El saldo será -100. Quiere decir que al menos nos regresaron el capital y 100 pesos más. La inversión quedó pagada. |
| 357 | $saldo -= ($inv_link_en_DB['monto_reembolsado'] + $inv_link_en_DB['monto_interes'] - $inv_link_en_DB['monto_isr']); |
| 358 | |
| 359 | if($saldo < 0) { |
| 360 | $saldo = 0; |
| 361 | } |
| 362 | |
| 363 | $parcial = ""; |
| 364 | if($saldo == 0) |
| 365 | $parcial = " TERMINADA"; |
| 366 | else |
| 367 | $parcial = " PARCIAL"; |
| 368 | |
| 369 | $remarks_por_link = '<table class="noborders" style="width: 270px; padding: 0;"><tr><td class="noborders row_altura_10px" colspan="2">'; |
| 370 | |
| 371 | $txt_inversion = "$" . echonf($inv_link_en_DB['monto_reembolsado'], true); |
| 372 | $txt_intereses = "$" . echonf($inv_link_en_DB['monto_interes'], true); |
| 373 | $txt_isr = "$" . echonf($inv_link_en_DB['monto_isr'], true); |
| 374 | $txt_intereses_real = "$" . echonf($inv_link_en_DB['monto_interes'] - $inv_link_en_DB['monto_isr'], true); |
| 375 | |
| 376 | $parcial .= ( $inv_link_en_DB['monto_reembolsado'] != $inv_en_DB['monto_reembolsado'] ? PHP_EOL . "(". echonf($inv_en_DB['monto_reembolsado'], true) .")" : ""); //VCA Bajar para abajo. |
| 377 | |
| 378 | |
| 379 | //Este link nos lleva a inversion_reembolso.php, donde se pueden cancelar los Links de Inversión |
| 380 | $remarks_por_link .= "<a title=\"Ir al Link de Inversión\" href=\"../backoffice/inversion_reembolso.php?inversion_reembolso_id=$inv_link_en_DB[inversion_reembolso_id]\" target=\"_blank\"><span class=\"bold txt16px\">LINK DE INVERSIÓN$parcial </span></a></td></tr><tr>"; |
| 381 | |
| 382 | $a_dep_reem = "<a title=\"Ir al Depósito en el banco\" href=\"../cobranza/edocta.php?banco_cuenta_id=$inv_link_en_DB[banco_cuenta_id]&banco_cuenta_mov_id=$inv_link_en_DB[banco_cuenta_mov_id]\" target=\"_blank\"><span class=\"txt_bold_blue txt15px\">"; |
| 383 | $remarks_por_link .= "<td class=\"txt_left_aligned noborders row_altura_10px\">". $a_dep_reem ."DEPÓSITO:</span></a></td><td class=\"txt_right_aligned noborders row_altura_10px\">$a_dep_reem$". echonf($inv_link_en_DB['monto_global_reembolso'], true) ."</span></a></td></tr><tr>"; |
| 384 | |
| 385 | $a_todo_a_banco = "<a title=\"Ir a Todo al Banco\" href=\"../backoffice/todo_a_banco_list.php?cuentat_a_banco_id=$inv_link_en_DB[inversion_reembolso_id]\" target=\"_blank\"><span class=\"txt_bold_red txt15px\">"; |
| 386 | $remarks_por_link .= "<td class=\"txt_left_aligned noborders row_altura_10px\">". $a_todo_a_banco ."INVERSIÓN:</span></a></td><td class=\"txt_right_aligned noborders row_altura_10px\"><span class=\"txt_bold_red txt15px\">$a_todo_a_banco$txt_inversion</span></a></td></tr><tr>"; |
| 387 | |
| 388 | $a_aper_inver = "<a title=\"Ir a la apertura de inversión\" href=\"../backoffice/inversion_list.php?inversion_id=$inv_en_DB[inversion_id]\" target=\"_blank\"><span class=\"txt_bold_orange txt15px\">"; |
| 389 | $remarks_por_link .= "<td class=\"txt_left_aligned noborders row_altura_10px\">". $a_aper_inver ."INTERÉS:</a></td><td class=\"txt_right_aligned noborders row_altura_10px\">$a_aper_inver$txt_intereses</span></a></td></tr><tr>"; |
| 390 | |
| 391 | $a_isr = "<a title=\"Ir a la apertura de inversión\" href=\"../backoffice/inversion_list.php?inversion_id=$inv_en_DB[inversion_id]\" target=\"_blank\"><span class=\"txt_bold_orange txt15px\">"; |
| 392 | $remarks_por_link .= "<td class=\"txt_left_aligned noborders row_altura_10px\">". $a_isr . "ISR:</span></a></td><td class=\"txt_right_aligned noborders row_altura_10px\">$a_isr$txt_isr</span></a></td></tr><tr>"; |
| 393 | |
| 394 | $a_interes_real = "<a title=\"Ir al retiro del banco\" href=\"../backoffice/withdrawals_de_banco_list.php?bc_mov_id=$inv_en_DB[banco_cuenta_mov_id]\" target=\"_blank\"><span class=\"txt_bold_purple txt15px\">"; |
| 395 | $remarks_por_link .= "<td class=\"txt_left_aligned noborders row_altura_10px\">". $a_interes_real . "INT. REAL:</a></td><td class=\"txt_right_aligned noborders row_altura_10px\">$a_interes_real$txt_intereses_real</span></a></td></tr></table>"; |
| 396 | |
| 397 | $remarks_inv_links .= $remarks_por_link . PHP_EOL; |
| 398 | $arr_ret['remarks_inv_links'][$inv_link_en_DB['inversion_reembolso_id']] = $remarks_por_link; |
| 399 | |
| 400 | /*$inv_link_ND = ['remarks' => $remarks_por_link]; |
| 401 | $sql_inv_link_remarks = haz_update_con_log($inv_link_ND, $inv_link_en_DB, "inversion_reembolso", "inversion_reembolso_id", $inv_link_en_DB['inversion_reembolso_id']); |
| 402 | |
| 403 | if(is_array($sql_inv_link_remarks) && !empty($sql_inv_link_remarks)) |
| 404 | foreach($sql_inv_link_remarks as $ilr) |
| 405 | $sql[] = $ilr;*/ |
| 406 | } |
| 407 | |
| 408 | $arr_ret['remarks_reembolso_inv'][$bcm_id] = $remarks_inv_links; |
| 409 | |
| 410 | /*echo "<br>=====================================================<br>"; |
| 411 | echo $remarks_inv_links;*/ |
| 412 | |
| 413 | |
| 414 | $bcm_inv_ret_ND = ['remarks' => $remarks_inv_links]; |
| 415 | $bcm_inv_ret_enDB = array(); |
| 416 | $sql_bcm_inv_ret_remarks = haz_update_con_log($bcm_inv_ret_ND, $bcm_inv_ret_enDB, "banco_cuenta_mov", "banco_cuenta_mov_id", $bcm_id); |
| 417 | |
| 418 | |
| 419 | if(is_array($sql_bcm_inv_ret_remarks) && !empty($sql_bcm_inv_ret_remarks)) |
| 420 | foreach($sql_bcm_inv_ret_remarks as $q) |
| 421 | $sql[] = $q; |
| 422 | |
| 423 | $arr_ret['sql'] = $sql; |
| 424 | |
| 425 | if($do_SQL) |
| 426 | if(ia_transaction($sql)) |
| 427 | ia_errores_a_dime(); |
| 428 | |
| 429 | |
| 430 | return $arr_ret; |
| 431 | |
| 432 | } |