Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 394 |
|
0.00% |
0 / 2 |
CRAP | n/a |
0 / 0 |
|
| SolicitaLinkBancario | |
0.00% |
0 / 234 |
|
0.00% |
0 / 1 |
7832 | |||
| RompeLinkBancario | |
0.00% |
0 / 160 |
|
0.00% |
0 / 1 |
2652 | |||
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * SolicitaLinkBancario() |
| 5 | * |
| 6 | * @param $arrMovData = array con los datos del movimiento: A Cuenta o Cuenta T. |
| 7 | * $arrMovData['link'] = ID del movimiento. OBLIGATORIO. |
| 8 | * $arrMovData['link_to'] = Desde donde se hace el link, nombre de la tabla. OBLIGATORIO. |
| 9 | * $arrMovData['tienda_id'] = tienda del movimiento. OBLIGATORIO. |
| 10 | * $arrMovData['withdrawal'] = withdrawal. Del movimiento bancario. |
| 11 | * $arrMovData['deposit'] = deposit. Del movimiento bancario. |
| 12 | * $arrMovData['cash'] = cash. Del movimiento bancario. |
| 13 | * $arrMovData['monto_acta'] = monto del a cuenta. Especial para link parcial. Si no pones éste o es cero, se asume que quieres Link Total. |
| 14 | * $arrMovData['fecha'] = fecha del movimiento bancario. En formato mysql: AAAA-MM-DD. OBLIGATORIO. |
| 15 | * $arrMovData['banco_mov_tipo_id'] = tipo de movimiento bancario, por ej. Transferencia, Efectivo, pago con tarjeta de credito, etc. |
| 16 | * $arrMovData['banco_cuenta_id'] = La cuenta bancaria. OBLIGATORIO. |
| 17 | * $arrMovData['idex100'] = Porcentaje de Comisión, si aplica. |
| 18 | * $arrMovData['idetotal'] = (idemonto)Monto de Comisión, si aplica. //No existe la columna. Tal vez en el futuro lo hagamos 11-Feb-2013. Ya existe la columna 01-05-2014. |
| 19 | * $arrMovData['factura'] = Concepto del a cuenta: FACTURA, MST, FACTURA PENDIENTE, DEVOLUCION |
| 20 | * $arrMovData['ivacobradox100'] = % de IVA cobrado. |
| 21 | * $arrMovData['ivacobradototal'] = Monto de IVA cobrado. |
| 22 | * $arrMovData['empresa_id'] = Empresa a la que pertenece la cuenta (puede no ser así) |
| 23 | * $arrMovData['factura_numero'] = Número de la factura |
| 24 | * $arrMovData['cash_nota_num'] = Número de CASH, NOTA, OTRO. |
| 25 | * $arrMovData['cliente'] = Cliente que hizo el pago. |
| 26 | * $arrMovData['tienda_id'] = Tienda a la que pertenece el pago. |
| 27 | * $arrMovData['tipo_cash_nota'] = Tipo de Venta: CASH, NOTA, OTRO. |
| 28 | * $arrMovData['cobra_iva'] = Bandera para saber si no se cobró IVA por especificación de quien registró la venta. |
| 29 | * $arrMovData['cash_num_cobro_iva'] = Número de CASH en que se cobró el IVA. |
| 30 | * $arrMovData['banco_cuenta_mov_id'] = ID del movimiento bancario al que se quiere hacer LINK. Esto es sólo para Link de TC. |
| 31 | * $arrMovData['origen_moneda_id'] = Moneda de la cuenta origen. Link entre cuentas con distinta moneda. |
| 32 | * $arrMovData['destino_moneda_id'] = Moneda de la cuenta destino. Link entre cuentas con distinta moneda. |
| 33 | * $arrMovData['monto_origen'] = Monto de la cuenta origen. Link entre cuentas con distinta moneda. |
| 34 | * $arrMovData['monto_destino'] = Monto de la cuenta destino. Link entre cuentas con distinta moneda. |
| 35 | * $arrMovData['tipo_cambio'] = Tipo de cambio. Link entre cuentas con distinta moneda. |
| 36 | * $arrMovData['ajusta_ctat'] = Para saber si afecta cuentat (inversiones). |
| 37 | * ##23-JUL-2018 También para Links, cuando hay multiples depósitos de la misma cantidad y fecha. |
| 38 | * @param $usuario = nick del usuario; |
| 39 | * @return array $arrInfoLink['vale_acta'] = true o false, dependiendo si el link fue exitoso o no. |
| 40 | * $arrInfoLink['mensaje'] = descripción del error. En link exitoso, va en blanco. En error una explicación del por qué no se hizo. |
| 41 | * $arrInfoLink['link_id'] = equivalente al anterior $banco_cuenta_mov_link_id = UUID del link del movimiento bancario, si el link fue exitoso. False si no se hizo el link. |
| 42 | */ |
| 43 | |
| 44 | function SolicitaLinkBancario($arrMovData, $usuario, $doLink='SI', $ghost_mov = []) |
| 45 | { |
| 46 | |
| 47 | global $gIAsql; |
| 48 | global $gIAParametros; |
| 49 | |
| 50 | $fn = " /** SolicitaLinkBancario **/ "; |
| 51 | |
| 52 | $gIAsql['trace']=true; |
| 53 | $sql=array(); |
| 54 | $sqlstr=''; |
| 55 | |
| 56 | //Declaramos el array que vamos a regresar |
| 57 | $arrInfoLink = array ( "vale_acta" => "", |
| 58 | "mensaje" => "", |
| 59 | "link_id" => "", |
| 60 | "ref_num" => "", |
| 61 | "deposit_fecha" => ""); |
| 62 | |
| 63 | if(empty($usuario) || is_numeric($usuario)) |
| 64 | $usuario = $_SESSION['usuario']; |
| 65 | |
| 66 | //Verificamos que nos hayan mandado los parametros bien. |
| 67 | if(!array_key_exists('link', $arrMovData) || !array_key_exists('link_to', $arrMovData) || !array_key_exists('tienda_id', $arrMovData) || !array_key_exists('banco_cuenta_id', $arrMovData) || !array_key_exists('fecha', $arrMovData)) |
| 68 | { |
| 69 | $arrInfoLink['vale_acta'] = false; |
| 70 | $arrInfoLink['mensaje'] = "DATOS INCOMPLETOS PARA HACER EL LINK."; |
| 71 | $arrInfoLink['link_id'] = false; |
| 72 | return $arrInfoLink; |
| 73 | } |
| 74 | |
| 75 | if(empty($arrMovData['idex100'])) |
| 76 | $arrMovData['idex100'] = 0.00; |
| 77 | |
| 78 | //01-05-2014: Completamos las llaves que pueden no venir. |
| 79 | if(!array_key_exists('idetotal', $arrMovData)) |
| 80 | $arrMovData['idetotal'] = 0.00; |
| 81 | if(!array_key_exists('factura', $arrMovData)) |
| 82 | $arrMovData['factura'] = ''; |
| 83 | if(!array_key_exists('cash_nota_num', $arrMovData)) |
| 84 | $arrMovData['cash_nota_num'] = ''; |
| 85 | if(!array_key_exists('ivacobradox100', $arrMovData)) |
| 86 | $arrMovData['ivacobradox100'] = 0.00; |
| 87 | if(!array_key_exists('ivacobradototal', $arrMovData)) |
| 88 | $arrMovData['ivacobradototal'] = 0.00; |
| 89 | if(!array_key_exists('empresa_id', $arrMovData)) |
| 90 | $arrMovData['empresa_id'] = ''; |
| 91 | if(!array_key_exists('factura_numero', $arrMovData)) |
| 92 | $arrMovData['factura_numero'] = ''; |
| 93 | if(!array_key_exists('cliente', $arrMovData)) |
| 94 | $arrMovData['cliente'] = ''; |
| 95 | if(!array_key_exists('tienda_id', $arrMovData)) |
| 96 | $arrMovData['tienda_id'] = ''; |
| 97 | if(!array_key_exists('tipo_cash_nota', $arrMovData)) |
| 98 | $arrMovData['tipo_cash_nota'] = ''; |
| 99 | if(!array_key_exists('cobra_iva', $arrMovData)) |
| 100 | $arrMovData['cobra_iva'] = ''; |
| 101 | if(!array_key_exists('cash_num_cobro_iva', $arrMovData)) |
| 102 | $arrMovData['cash_num_cobro_iva'] = ''; |
| 103 | if(!array_key_exists('iva_incluido', $arrMovData)) |
| 104 | $arrMovData['iva_incluido'] = ''; |
| 105 | if(!array_key_exists('banco_mov_tipo_id', $arrMovData)) |
| 106 | $arrMovData['banco_mov_tipo_id'] = 2; |
| 107 | |
| 108 | $arrMovData['ajusta_ctat'] = empty($arrMovData['ajusta_ctat']) ? 'SI' : $arrMovData['ajusta_ctat']; |
| 109 | |
| 110 | //Link de TC o específico |
| 111 | $bcmIDDestino = array_key_exists('banco_cuenta_mov_id', $arrMovData) ? $arrMovData['banco_cuenta_mov_id'] : ''; |
| 112 | |
| 113 | //Agregamos la variable global para saber si hacemos el link estricto o relajado. |
| 114 | global $gIAstrictlinking; |
| 115 | |
| 116 | $link_datetime = date('Y-m-d H:i:s'); |
| 117 | |
| 118 | //$oknumop = 1; |
| 119 | if(!array_key_exists('deposit', $arrMovData)) |
| 120 | $arrMovData['deposit']=0; |
| 121 | if(!array_key_exists('cash', $arrMovData)) |
| 122 | $arrMovData['cash']=0; |
| 123 | if(!array_key_exists('withdrawal', $arrMovData)) |
| 124 | $arrMovData['withdrawal']=0; |
| 125 | |
| 126 | $bcmov_quantity = $arrMovData['deposit'] + $arrMovData['cash'] - $arrMovData['withdrawal']; //Por el link parcial, debemos separar el monto del mov bancario del monto de link. |
| 127 | $bcmov_quantity = round($bcmov_quantity,2); |
| 128 | //$link_quantity = $arrMovData['deposit'] + $arrMovData['cash'] - $arrMovData['withdrawal']; //Monto del link (lo que se aplicará a usado). |
| 129 | |
| 130 | |
| 131 | $bc_id = $arrMovData['banco_cuenta_id']; |
| 132 | |
| 133 | /** |
| 134 | //Verificamos puedeCuentaBancaria el permiso que debe tener para hacer link es Link (L/O) o Editar (R/W) |
| 135 | $puedeBorrar = puedeCuentaBancaria('',$bc_id, 'L/O'); |
| 136 | |
| 137 | if($puedeBorrar['quePuede'] != 'Link' || $puedeBorrar['quePuede'] != 'Editar') |
| 138 | { |
| 139 | |
| 140 | $arrInfoLink['vale_acta'] = false; |
| 141 | $arrInfoLink['mensaje'] = "NO TIENE PERMISO EN LA CUENTA BANCARIA."; |
| 142 | $arrInfoLink['link_id'] = false; |
| 143 | return $arrInfoLink; |
| 144 | } |
| 145 | * **/ |
| 146 | |
| 147 | //Modificación 30-08-2012 |
| 148 | //Fecha de movimientos más recientes ya capturados en el Estado de Cuenta. |
| 149 | $sqlstr="SELECT $fn max(fecha) as fecha FROM banco_cuenta_mov WHERE banco_cuenta_id='$arrMovData[banco_cuenta_id]'"; |
| 150 | $fecha_mov_mr = ia_singleread($sqlstr); |
| 151 | if($fecha_mov_mr == '') |
| 152 | $fecha_mov_mr = date('Y-m-d'); |
| 153 | |
| 154 | //Revisamos si se quiere un link parcial, y si así es, entonces $link_quantity será igual a$arrMovData['monto_acta']. |
| 155 | //Deshabilitamos link parcial 18/06/2013. |
| 156 | //Regresamo el link parcial 02/09/2016 |
| 157 | |
| 158 | if(!empty($arrMovData['monto_acta'])) |
| 159 | $link_quantity = $arrMovData['monto_acta']; |
| 160 | else |
| 161 | $link_quantity = $bcmov_quantity; |
| 162 | |
| 163 | $link_quantity = round($link_quantity,2); |
| 164 | |
| 165 | //Nombre del movimiento: Pago a cuenta de Cheque, Pagaré, Deuda o Vale (a secas). |
| 166 | $nombreMov = 'PAGO A CUENTA DE '; |
| 167 | |
| 168 | //Transferencias con tipo de cambio. |
| 169 | $origen_moneda_id = array_key_exists('origen_moneda_id', $arrMovData) ? $arrMovData['origen_moneda_id'] : false; |
| 170 | $destino_moneda_id = array_key_exists('destino_moneda_id', $arrMovData) ? $arrMovData['destino_moneda_id'] : false; |
| 171 | $monto_origen = array_key_exists('monto_origen', $arrMovData) ? $arrMovData['monto_origen'] : false; |
| 172 | $monto_destino = array_key_exists('monto_destino', $arrMovData) ? $arrMovData['monto_destino'] : false; |
| 173 | $tipo_cambio = array_key_exists('tipo_cambio', $arrMovData) ? $arrMovData['tipo_cambio'] : false; |
| 174 | |
| 175 | switch($tp=tablapadre($arrMovData['link_to'])) |
| 176 | { |
| 177 | case 'vale': |
| 178 | $nombreMov = 'VALE'; |
| 179 | break; |
| 180 | |
| 181 | case 'cuentat_mov': |
| 182 | if(empty($bcmIDDestino)) |
| 183 | $nombreMov = 'LINK DE CUENTA T'; |
| 184 | else |
| 185 | $nombreMov = 'LINK DE TARJETAS DE CRÉDITO'; |
| 186 | break; |
| 187 | |
| 188 | case 'banco_cuenta_mov': |
| 189 | $nombreMov = 'TRANSFERENCIA ENTRE CUENTAS'; |
| 190 | $link_quantity = $monto_destino; |
| 191 | break; |
| 192 | |
| 193 | default: |
| 194 | $nombreMov.=strtoupper($tp); |
| 195 | break; |
| 196 | } |
| 197 | |
| 198 | $tp = strtolower($tp); |
| 199 | |
| 200 | //Primero buscamos el movimiento y vemos si existe y está disponible o tiene link total o parcial. |
| 201 | $sepuedelink = false; |
| 202 | $arrcI = $arr_bcmenDB = $bcmenDB = array(); |
| 203 | |
| 204 | |
| 205 | //Revisamos que la fecha del depósito no sea anterior al límite establecido en los parámetros. |
| 206 | //Ni que tampoco sea posterior al parámetro dias_limite_adelante_link_bancario |
| 207 | $dateHoy = date('Y-m-d'); |
| 208 | $dateMov = $arrMovData['fecha']; |
| 209 | |
| 210 | //if(empty($bcmIDDestino) && diferenciadeTiempo($dateHoy, $dateMov, 'dias') > $gIAParametros['dias_limite_atras_link_bancario'] && !usuarioTipoRony($_SESSION['usuario_id']) ) //Si es Rony que se salte esa restricción/*&& $_SESSION['usuario_id'] != 1*/ |
| 211 | |
| 212 | if(!usuarioTipoRony() && //Si es Rony que se salte esa restricción |
| 213 | diferenciadeTiempo($dateHoy, $dateMov, 'dias') > $gIAParametros['dias_limite_atras_link_bancario'] && |
| 214 | diferenciadeTiempo($dateHoy, $dateMov, 'dias') > $gIAParametros['dias_limite_adelante_link_bancario']) |
| 215 | { |
| 216 | $arrInfoLink['vale_acta'] = false; |
| 217 | $arrInfoLink['mensaje'] = "<strong>LINK BANCARIO NO ACEPTADO.</strong><br/><br/><strong class=\"msgerr\">EXCEDE EL LÍMITE DE DÍAS</strong><br/><br/><strong>$nombreMov</strong> <strong class=\"msgerr\">NO SE ACEPTA.</strong>"; |
| 218 | $arrInfoLink['link_id'] = false; |
| 219 | // $arrInfoLink['dateMov'] = $dateMov; |
| 220 | // $arrInfoLink['gIAParametros'] = $gIAParametros; |
| 221 | // $arrInfoLink['dif_atras'] = diferenciadeTiempo($dateHoy, $dateMov, 'dias') > $gIAParametros['dias_limite_atras_link_bancario']; |
| 222 | // $arrInfoLink['dif_adelante'] = diferenciadeTiempo($dateHoy, $dateMov, 'dias') > $gIAParametros['dias_limite_adelante_link_bancario']; |
| 223 | |
| 224 | |
| 225 | //echo "<pre>".print_r($arrInfoLink, true)."</pre>"; |
| 226 | return $arrInfoLink; |
| 227 | } |
| 228 | //Buscamos el movimiento sólo con la fecha y la cantidad |
| 229 | |
| 230 | $primerdiamesfechaDeposito = date('Y-m-d', strtotime($arrMovData['fecha'])) . " 00:00:00"; |
| 231 | $ultimodiamesfechaDeposito = date('Y-m-d', strtotime($arrMovData['fecha'])) . " 23:59:59"; |
| 232 | |
| 233 | if(empty($bcmIDDestino)) |
| 234 | $sqlstr="SELECT $fn * FROM banco_cuenta_mov WHERE banco_cuenta_id = '$bc_id' AND ((cash + deposit - withdrawal) = $bcmov_quantity) AND fecha between '$primerdiamesfechaDeposito' AND '$ultimodiamesfechaDeposito' ORDER BY fecha DESC, usado DESC LOCK IN SHARE MODE"; |
| 235 | //$sqlstr="SELECT $fn * FROM banco_cuenta_mov WHERE banco_cuenta_id = '$bc_id' AND ((cash + deposit - |
| 236 | // withdrawal) = $bcmov_quantity) AND fecha LIKE '$arrMovData[fecha]%' ORDER BY usado DESC LOCK IN SHARE MODE"; |
| 237 | else |
| 238 | $sqlstr="SELECT $fn * FROM banco_cuenta_mov WHERE banco_cuenta_mov_id = '$bcmIDDestino' LOCK IN SHARE MODE"; |
| 239 | |
| 240 | $arr_bcmenDB = ia_sqlArrayIndx($sqlstr); |
| 241 | // echo "<pre>_ghost_mov" . print_r($ghost_mov, true) . "</pre>"; |
| 242 | // echo "<pre>arr_bcmenDB" . print_r($arr_bcmenDB, true) . "</pre>"; |
| 243 | if((empty($arr_bcmenDB) || !is_array($arr_bcmenDB)) && empty($ghost_mov)) |
| 244 | { |
| 245 | $arrInfoLink['vale_acta'] = false; |
| 246 | $arrInfoLink['mensaje'] = "<strong>LINK BANCARIO NO ENCONTRADO.</strong>.<br/><br/><strong class=\"msgerr\">EL $nombreMov NO SE ACEPTA.</strong>"; |
| 247 | $arrInfoLink['link_id'] = false; |
| 248 | return $arrInfoLink; |
| 249 | } |
| 250 | if(!empty($ghost_mov) && empty($arr_bcmenDB)){ |
| 251 | $arr_bcmenDB[] = $ghost_mov; |
| 252 | } |
| 253 | |
| 254 | // echo "hola"; |
| 255 | |
| 256 | /** Se encontró uno o varios movimientos con la fecha y cantidad especificados. |
| 257 | * Vamos a buscar alguno disponible, y si no, entonces decimos cuál es el status del o los no disponibles. **/ |
| 258 | // Declaramos una variable para llevar registro de los movimientos que concuerdan y no se pueden tomar. |
| 259 | $txt_bcm = ''; |
| 260 | $huboSBC = false; |
| 261 | $cI = 0; |
| 262 | |
| 263 | // echo "<pre>arrMovData:" . print_r($arrMovData, true) . "</pre>"; |
| 264 | |
| 265 | if(is_array($arr_bcmenDB)) |
| 266 | foreach($arr_bcmenDB as $k=>$bcm) |
| 267 | { |
| 268 | // echo "<pre>".print_r($bcm, true)."</pre>"; |
| 269 | |
| 270 | /** Revisamos su estado **/ |
| 271 | switch ($bcm['link_vale']) |
| 272 | { |
| 273 | case 'LP': |
| 274 | /** Primero revisamos si lo que le queda disponible al mov bancario alcanza para el link. |
| 275 | * Si sí le alcanza, entonces salimos del foreach. No necesitamos revisar más. |
| 276 | * Si no le alcanza, leemos sus a cuentas y las mandamos en la respuesta. **/ |
| 277 | |
| 278 | $solicitado=$link_quantity; |
| 279 | $usado=round($bcm['usado'],2); |
| 280 | $disponible=round(abs($bcmov_quantity-$usado),2); |
| 281 | if($link_quantity<=$disponible) |
| 282 | { |
| 283 | $sepuedelink = true; |
| 284 | $bcmenDB = $bcm; |
| 285 | $bcmIDDestino = $bcm['banco_cuenta_mov_id']; //Ya sabemos el ID del movimiento bancario y nos ahorramos un select al final. |
| 286 | break 2; //Ya encontramos un movimiento disponible. No necesitamos revisar más. |
| 287 | } |
| 288 | |
| 289 | $solicitado=echonf($solicitado,true); |
| 290 | $disponible=echonf($disponible,true); |
| 291 | $txt_actas = ''; |
| 292 | $txt_actas = generaaCuentasdeBancoMov($bcm['banco_cuenta_mov_id'],'str','SI'); |
| 293 | $txt_actas = empty($txt_actas) ? $txt_actas : "<ol>$txt_actas</ol>"; |
| 294 | $txt_bcm .= "<li><strong class=\"msgerr\">MOV. BANCARIO CON LINKS PARCIALES. NO ALCANZA EL DISPONIBLE.</strong><br /> |
| 295 | SOLICITADO: $solicitado<br />DISPONIBLE: $disponible<br /> |
| 296 | <br/><strong>DETALLE:</strong>$txt_actas</li>"; |
| 297 | // $sepuedelink = false; |
| 298 | |
| 299 | break; |
| 300 | |
| 301 | //FIDUCIARIO |
| 302 | //INVERSIONES 2020 |
| 303 | case 'FID': |
| 304 | if($arrMovData['link_to'] == 'fiduciario_reembolso') {//Revisamos que venga de fiduciario. |
| 305 | $sepuedelink = true; |
| 306 | $arrcI[] = $bcmenDB = $bcm; |
| 307 | $bcmIDDestino = $bcm['banco_cuenta_mov_id']; //Ya sabemos el ID del movimiento bancario y nos ahorramos un select al final. |
| 308 | if ($tp == 'vale') |
| 309 | break 2; |
| 310 | $cI++; |
| 311 | } |
| 312 | //$txt_bcm .= "<li><strong>MOVIMIENTO DE FIDUCIARIO.</strong></li>"; |
| 313 | //break 2; //Ya encontramos un movimiento disponible. No necesitamos revisar más. |
| 314 | break; |
| 315 | |
| 316 | case 'Q': |
| 317 | $sepuedelink = true; |
| 318 | $arrcI[] = $bcmenDB = $bcm; |
| 319 | $bcmIDDestino = $bcm['banco_cuenta_mov_id']; //Ya sabemos el ID del movimiento bancario y nos ahorramos un select al final. |
| 320 | // if($tp=='vale') |
| 321 | // break 2; |
| 322 | $cI++; |
| 323 | //break 2; //Ya encontramos un movimiento disponible. No necesitamos revisar más. |
| 324 | break; |
| 325 | |
| 326 | case 'INV': |
| 327 | if($arrMovData['link_to'] == 'inversion_reembolso'){//Revisamos que venga de inversiones. |
| 328 | $sepuedelink = true; |
| 329 | $arrcI[] = $bcmenDB = $bcm; |
| 330 | $bcmIDDestino = $bcm['banco_cuenta_mov_id']; //Ya sabemos el ID del movimiento bancario y nos ahorramos un select al final. |
| 331 | if($tp=='vale') |
| 332 | break 2; |
| 333 | $cI++; |
| 334 | } |
| 335 | //$txt_bcm .= "<li><strong>MOVIMIENTO DE INVERSION.</strong></li>"; |
| 336 | //break 2; //Ya encontramos un movimiento disponible. No necesitamos revisar más. |
| 337 | break; |
| 338 | |
| 339 | case 'SBC': |
| 340 | $txt_bcm .= "<li><strong>CHEQUE SALVO BUEN COBRO.</strong></li>"; |
| 341 | $huboSBC = true; |
| 342 | $sepuedelink = false; |
| 343 | break; |
| 344 | |
| 345 | case 'ND':case 'NAVIERA': |
| 346 | //VCA 15-12-2020 SolicitaLinkBancario permite hacer link desde Transfers propias aún cuando el depósito esté en ND. |
| 347 | //Sólo permite desde fiduciario_reembolso y propias |
| 348 | if((empty($bcmIDDestino) && |
| 349 | $arrMovData['link_to'] != 'fiduciario_reembolso' && //Desde fiduciario |
| 350 | $arrMovData['link_to'] != 'inversion_reembolso' && //Desde Inversión |
| 351 | $arrMovData['link_to'] != 'banco_cuenta_mov') //Desde Tranfers Propias |
| 352 | && |
| 353 | ($arrMovData['link_to'] != 'cuentat_mov' || $arrMovData['ajusta_ctat'] != 'NO' || $arrMovData['factura'] != 'DEVOLUCION') |
| 354 | ) |
| 355 | { |
| 356 | $txt_bcm .= "<li><strong>MOV. BANCARIO NO DISPONIBLE.</strong></li>"; |
| 357 | $sepuedelink = false; |
| 358 | } |
| 359 | else |
| 360 | { |
| 361 | $sepuedelink = true; |
| 362 | $arrcI[] = $bcmenDB = $bcm; |
| 363 | $bcmIDDestino = $bcm['banco_cuenta_mov_id']; //Ya sabemos el ID del movimiento bancario y nos ahorramos un select al final. |
| 364 | $cI++; |
| 365 | //break 2; //Ya encontramos un movimiento disponible. No necesitamos revisar más. |
| 366 | // break; |
| 367 | } |
| 368 | break; |
| 369 | |
| 370 | case 'LT':case 'BL':case 'RJ': |
| 371 | |
| 372 | //VCA 15-12-2020 SolicitaLinkBancario permite hacer link desde Transfers propias aún cuando el depósito esté en ND. |
| 373 | //Sólo permite desde fiduciario_reembolso y propias |
| 374 | if($bcm['banco_mov_tipo_id'] != 26 /**ya tiene link sin afectar cuentatt**/ && $arrMovData['ajusta_ctat'] == 'NO' && $arrMovData['factura'] == 'DEVOLUCION') { |
| 375 | $sepuedelink = true; |
| 376 | $arrcI[] = $bcmenDB = $bcm; |
| 377 | $bcmIDDestino = $bcm['banco_cuenta_mov_id']; //Ya sabemos el ID del movimiento bancario y nos ahorramos un select al final. |
| 378 | $cI++; |
| 379 | //break 2; //Ya encontramos un movimiento disponible. No necesitamos revisar más. |
| 380 | // break; |
| 381 | } |
| 382 | else { |
| 383 | //$bcmov_detalle_tmp = ''; |
| 384 | $txt_actas = ''; |
| 385 | $txt_actas = generaaCuentasdeBancoMov($bcm['banco_cuenta_mov_id'], 'str', 'SI'); |
| 386 | $txt_actas = empty($txt_actas) ? $txt_actas : "<ol>$txt_actas</ol>"; |
| 387 | $txt_actas = html_entity_decode($txt_actas); |
| 388 | $txt_bcm .= "<li><strong>MOV. BANCARIO CON LINK TOTAL.</strong><br/><strong>DETALLE:</strong>$txt_actas</li>";; |
| 389 | // $sepuedelink = false; |
| 390 | } |
| 391 | break; |
| 392 | } |
| 393 | } |
| 394 | //die(); |
| 395 | // echo "hola!!"; |
| 396 | if(!$sepuedelink) |
| 397 | { |
| 398 | $arrInfoLink['vale_acta'] = false; |
| 399 | $arrInfoLink['mensaje'] = $txt_bcm ."<hr/><strong class=\"msgerr\">EL $nombreMov NO SE ACEPTA.</strong>"; |
| 400 | $arrInfoLink['link_id'] = false; |
| 401 | return $arrInfoLink; |
| 402 | } |
| 403 | |
| 404 | // echo "hola!"; |
| 405 | |
| 406 | //echo "<pre>arrcI".print_r($arrcI, true)."</pre>"; |
| 407 | /** Encontró más de un movimiento disponible con la misma cantidad y la misma. Los mandamos en un array para que elija el que quiere.**/ |
| 408 | /** VCA Agregamos una excepcion por si el vale y encontró más de un movimiento, que le ofrezca el listado que encontró */ |
| 409 | if($cI > 1 ) // && $tp!='vale' // && $tp!='banco_cuenta_mov' |
| 410 | { |
| 411 | usort($arrcI, function( $a, $b ) { |
| 412 | return strtotime($a['alta_db']) - strtotime($b['alta_db']); |
| 413 | }); |
| 414 | |
| 415 | foreach($arrcI as $k=>&$v){ |
| 416 | $v['fecha'] = date('d-m-Y H:i:s', strtotime($v['fecha'])); |
| 417 | } |
| 418 | |
| 419 | $arrInfoLink['vale_acta'] = false; |
| 420 | $arrInfoLink['mensaje'] = $txt_bcm ."<hr/><strong class=\"lbl\">MULTIPLES DEPÓSITOS CON LA MISMA CANTIDAD.</strong>"; |
| 421 | $arrInfoLink['link_id'] = false; |
| 422 | $arrInfoLink['arrcI'] = $arrcI; |
| 423 | $arrInfoLink['cI'] = $cI; |
| 424 | return $arrInfoLink; |
| 425 | } |
| 426 | |
| 427 | //VCA 02-06-2021 Agrego faltante_permitido_completar_link. Si le falta menos del faltante_permitido_completar_link para completar el link, entonces lo completa. |
| 428 | $faltante_permitido = $gIAParametros['faltante_permitido_completar_link']; |
| 429 | |
| 430 | $link_quantity = abs($arrMovData['ajusta_ctat'] == 'NO' && $arrMovData['factura'] == 'DEVOLUCION' ? 0.00 : $link_quantity); |
| 431 | $link_quantity_txt = empty($link_quantity) ? "deposit - usado" : "usado + $link_quantity"; |
| 432 | $updateFields=" link_vale = IF(usado+$link_quantity+$faltante_permitido>=deposit OR $link_quantity = 0,'LT','LP') |
| 433 | , usado = $link_quantity_txt |
| 434 | , idex100 = '$arrMovData[idex100]' |
| 435 | , idetotal = '$arrMovData[idetotal]' |
| 436 | , factura = '$arrMovData[factura]' |
| 437 | , factura_numero = '$arrMovData[factura_numero]' |
| 438 | , ivacobradox100 = '$arrMovData[ivacobradox100]' |
| 439 | , ivacobradototal = '$arrMovData[ivacobradototal]' |
| 440 | , empresa_id = '$arrMovData[empresa_id]' |
| 441 | , cliente = '$arrMovData[cliente]' |
| 442 | , tienda_id = '$arrMovData[tienda_id]' |
| 443 | , cobra_iva = '$arrMovData[cobra_iva]' |
| 444 | , tipo_cash_nota = '$arrMovData[tipo_cash_nota]' |
| 445 | , cash_nota_num = '$arrMovData[cash_nota_num]' |
| 446 | , cash_num_cobro_iva = '$arrMovData[cash_num_cobro_iva]' |
| 447 | , iva_incluido = '$arrMovData[iva_incluido]' |
| 448 | , puede_editar = 'No' |
| 449 | , ultimo_cambio = '$link_datetime' |
| 450 | , ultimo_cambio_por = '$usuario' |
| 451 | , link_el = '$link_datetime' |
| 452 | , link_por = '$usuario' |
| 453 | , banco_mov_tipo_id = '$arrMovData[banco_mov_tipo_id]' |
| 454 | WHERE banco_cuenta_id = '$bc_id' "; |
| 455 | |
| 456 | $sqlstr = "UPDATE $fn banco_cuenta_mov SET $updateFields AND banco_cuenta_mov_id = '$bcmIDDestino' "; |
| 457 | |
| 458 | $sql[]=$sqlstr; |
| 459 | |
| 460 | $bcml_id = ia_guid(); |
| 461 | $bcm_id = $bcmIDDestino; |
| 462 | $link_to = $arrMovData['link_to']; |
| 463 | $link = $arrMovData['link']; |
| 464 | $tienda_id = $arrMovData['tienda_id']; |
| 465 | |
| 466 | $sqlstr = "INSERT $fn INTO banco_cuenta_mov_link |
| 467 | (banco_cuenta_mov_link_id, banco_cuenta_mov_id, link_to, link, tienda_id, link_por, link_el) |
| 468 | VALUES ('$bcml_id', '$bcm_id', '$link_to', '$link', '$tienda_id', '$usuario', '$link_datetime')"; |
| 469 | |
| 470 | // echo "hola2"; |
| 471 | // exit; |
| 472 | |
| 473 | $sql[]=$sqlstr; |
| 474 | if($doLink=='SI') |
| 475 | if(ia_transaction($sql)) |
| 476 | { |
| 477 | $arrInfoLink['vale_acta'] = false; |
| 478 | $arrInfoLink['mensaje'] = "OCURRIÓ UN ERROR AL HACER EL LINK."; |
| 479 | $arrInfoLink['link_id'] = false; |
| 480 | $arrInfoLink['sql'] = $sql; |
| 481 | return $arrInfoLink; |
| 482 | } |
| 483 | |
| 484 | $arrInfoLink['disponible'] = $arrMovData['ajusta_ctat'] == 'NO' && $arrMovData['factura'] == 'DEVOLUCION'? 0.00 : (abs($bcmenDB['cash'] + $bcmenDB['deposit'] - $bcmenDB['withdrawal']) - ($bcmenDB['usado'] + $link_quantity)); |
| 485 | $arrInfoLink['vale_acta'] = true; |
| 486 | $arrInfoLink['mensaje'] = "LINK EXITOSO."; |
| 487 | $arrInfoLink['link_id'] = $bcml_id; |
| 488 | $arrInfoLink['bcm_id'] = $bcm_id; |
| 489 | $arrInfoLink['ref_num'] = numRefLink(); |
| 490 | $arrInfoLink['deposit_fecha'] = $bcmenDB['fecha']; |
| 491 | $arrInfoLink['referencia'] = $bcmenDB['numero']; |
| 492 | $arrInfoLink['bcmenDB'] = $bcmenDB=ia_singleton("SELECT $fn * FROM banco_cuenta_mov WHERE banco_cuenta_mov_id = '$bcm_id'"); |
| 493 | $arrInfoLink['sql'] = $sql; |
| 494 | |
| 495 | return $arrInfoLink; |
| 496 | } |
| 497 | |
| 498 | /** |
| 499 | * RompeLinkBancario() |
| 500 | * |
| 501 | * @param $bcml_id = banco_cuenta_mov_link_id. |
| 502 | * @return $rlb_arr = un array con atributos para el log si la rotura del link fue exitosa y $doRLB==true. Si $doRLB==false, entonces el $sql_arr. |
| 503 | * false si ocurrio algun error. |
| 504 | */ |
| 505 | |
| 506 | function RompeLinkBancario($bcml_id, $usuario='', $dedonde = "<li>LINK ROTO DESDE ESTADO DE CUENTA POR ", $comParaBancoMov="", $doRLB=true) |
| 507 | { |
| 508 | //Revisar esta operacion |
| 509 | |
| 510 | if($bcml_id == '' || strlen($bcml_id) < 32) |
| 511 | return false; |
| 512 | |
| 513 | global $gIAsql; |
| 514 | $gIAsql['trace']=true; |
| 515 | |
| 516 | if(empty($usuario)) |
| 517 | $usuario = $_SESSION['usuario']; |
| 518 | |
| 519 | $commentSQL = " /** RompeLinkBancario **/"; |
| 520 | |
| 521 | $rlb_arr = array(); |
| 522 | |
| 523 | $bcml_arr = ia_singleton("SELECT $commentSQL * FROM banco_cuenta_mov_link WHERE banco_cuenta_mov_link_id = ". strit($bcml_id)); |
| 524 | |
| 525 | |
| 526 | if(!array_key_exists('banco_cuenta_mov_id',$bcml_arr)) //Ya no existe el link bancario. Nada que hacer aquí. |
| 527 | return false; |
| 528 | |
| 529 | $bcm_id = $bcml_arr['banco_cuenta_mov_id']; |
| 530 | $bcm_arr = ia_singleton("SELECT $commentSQL * FROM banco_cuenta_mov WHERE banco_cuenta_mov_id = '$bcm_id'"); |
| 531 | $bc_cash = array_key_exists('cash',$bcm_arr) ? $bcm_arr['cash'] : 0.00; |
| 532 | $bc_withdrawal = array_key_exists('withdrawal',$bcm_arr) ? $bcm_arr['withdrawal'] : 0.00; |
| 533 | $bc_deposit = array_key_exists('deposit',$bcm_arr) ? $bcm_arr['deposit'] : 0.00; |
| 534 | |
| 535 | $acta_id = $bcml_arr['link']; |
| 536 | $acta_tbl = $bcml_arr['link_to']; |
| 537 | $acta_id_nombre = $acta_tbl . '_id'; |
| 538 | $actapadre_tbl = tablapadre($acta_tbl); |
| 539 | $actapadre_id_nombre = $actapadre_tbl . '_id'; |
| 540 | |
| 541 | $acta_arr = ia_singleton("SELECT $commentSQL * FROM $acta_tbl WHERE $acta_id_nombre = '$acta_id'"); |
| 542 | if(empty($acta_arr) && $acta_tbl=='cuentat_mov') |
| 543 | $acta_arr = ia_singleton("SELECT * FROM cuentat_a_banco WHERE cuentat_a_banco_mov_id = '$acta_id'"); |
| 544 | |
| 545 | |
| 546 | //echo "<pre>".print_r($acta_arr,true)."</pre>"; |
| 547 | //echo "<pre>".print_r($ctaT_arr,true)."</pre>"; |
| 548 | |
| 549 | $Quantity = 0; |
| 550 | $QuantityCtaT = 0; |
| 551 | $usado = 0; |
| 552 | |
| 553 | if(array_key_exists('quantity',$acta_arr)) |
| 554 | $Quantity = $acta_arr['quantity']; //Este monto es el que vamos a quitarle al total_payments del padre y a restar de usado en banco_cuenta_mov |
| 555 | else if(array_key_exists('monto',$acta_arr)) |
| 556 | $Quantity = $acta_arr['monto']; |
| 557 | else if(array_key_exists('monto_global_reembolso',$acta_arr)) // Inversiones 2020 |
| 558 | $Quantity = $acta_arr['monto_global_reembolso']; |
| 559 | |
| 560 | $QuantityCtaT = array_key_exists('quantity_ctat',$acta_arr) ? $acta_arr['quantity_ctat'] : 0.00; |
| 561 | $usado = array_key_exists('quantity_total',$acta_arr) ? $acta_arr['quantity_total'] : $Quantity; |
| 562 | |
| 563 | switch($acta_tbl) |
| 564 | { |
| 565 | case 'cuentat_mov': |
| 566 | if($acta_arr['tipo'] == 'Egreso') |
| 567 | $Quantity = limpiaCantidad($acta_arr['egreso']); |
| 568 | else |
| 569 | $Quantity = limpiaCantidad($acta_arr['monto']); |
| 570 | break; |
| 571 | |
| 572 | case 'banco_cuenta_mov': |
| 573 | $Quantity = limpiaCantidad($acta_arr['withdrawal']); |
| 574 | break; |
| 575 | |
| 576 | case 'fiduciario_reembolso': |
| 577 | $Quantity = limpiaCantidad($acta_arr['monto_global_reembolso']); |
| 578 | break; |
| 579 | |
| 580 | case 'inversion_reembolso': |
| 581 | $usado = $Quantity = limpiaCantidad($acta_arr['monto_reembolsado'] + $acta_arr['monto_interes'] - $acta_arr['monto_isr']); |
| 582 | break; |
| 583 | |
| 584 | case 'vale': |
| 585 | $QuantityCtaT = limpiaCantidad($acta_arr['quantity_recibido']); |
| 586 | break; |
| 587 | |
| 588 | } |
| 589 | |
| 590 | $actapadre_id = array_key_exists($actapadre_id_nombre,$acta_arr) ? $acta_arr[$actapadre_id_nombre] : ''; |
| 591 | |
| 592 | $rlb_arr['banco_cuenta_id'] = $bc_id = array_key_exists('banco_cuenta_id',$bcm_arr) ? $bcm_arr['banco_cuenta_id'] : '0'; |
| 593 | $rlb_arr['acta_tbl'] = $acta_tbl; |
| 594 | $rlb_arr['Quantity'] = $QuantityCtaT ? $QuantityCtaT : $Quantity; |
| 595 | $rlb_arr['bcm_id'] = $bcm_id; |
| 596 | $rlb_arr['acta'] = ''; |
| 597 | $rlb_arr['actapadre'] = $actapadre_tbl; |
| 598 | $rlb_arr['actapadre_id'] = $actapadre_id; |
| 599 | $rlb_arr['cuentat_id'] = ''; |
| 600 | $rlb_arr['cuentat_mov'] = ''; |
| 601 | $rlb_arr['link_roto_id'] = ''; |
| 602 | $rlb_arr['link_ori_id'] = ''; |
| 603 | $rlb_arr['banco_cuenta_mov_id'] = $bcml_arr['banco_cuenta_mov_id']; |
| 604 | |
| 605 | $bc_tc = array_key_exists('tipo_cambio',$acta_arr) ? $acta_arr['tipo_cambio'] : '0.00'; |
| 606 | |
| 607 | |
| 608 | |
| 609 | $now = $ultimo_cambio = date('Y-m-d H:i:s'); |
| 610 | |
| 611 | |
| 612 | //Diferenciamos Ingreso y Egreso 9-1-13 |
| 613 | $cTcampoMonto = 'monto'; |
| 614 | $cTtipomov = 'Ingreso'; |
| 615 | $cTcampoMontoCP = 'egreso'; |
| 616 | $cTtipomovCP = 'Egreso'; |
| 617 | |
| 618 | if(!array_key_exists('es',$bcm_arr)) |
| 619 | $bcm_arr['es'] = 'Ingreso'; |
| 620 | |
| 621 | if($bcm_arr['es'] == 'Retiro') |
| 622 | { |
| 623 | $cTcampoMonto = 'egreso'; |
| 624 | $cTtipomov = 'Egreso'; |
| 625 | $cTcampoMontoCP = 'monto'; |
| 626 | $cTtipomovCP = 'Ingreso'; |
| 627 | } |
| 628 | else |
| 629 | { |
| 630 | $cTcampoMonto = 'monto'; |
| 631 | $cTtipomov = 'Ingreso'; |
| 632 | $cTcampoMontoCP = 'egreso'; |
| 633 | $cTtipomovCP = 'Egreso'; |
| 634 | } |
| 635 | /////////////////////////////////////// |
| 636 | |
| 637 | $sql = array(); |
| 638 | |
| 639 | $quantity_total = 0; |
| 640 | |
| 641 | $updateFields=", idex100 = 0.00 |
| 642 | , idetotal = 0.00 |
| 643 | , factura = '' |
| 644 | , factura_numero = '' |
| 645 | , ivacobradox100 = 0.00 |
| 646 | , ivacobradototal = 0.00 |
| 647 | , empresa_id = NULL |
| 648 | , cliente = '' |
| 649 | , tienda_id = NULL |
| 650 | , cobra_iva = NULL |
| 651 | , tipo_cash_nota = NULL |
| 652 | , cash_nota_num = NULL |
| 653 | , cash_num_cobro_iva = NULL |
| 654 | , iva_incluido = NULL "; |
| 655 | |
| 656 | if(esBancoChina($bc_id)) |
| 657 | { |
| 658 | $updateFields = ", cash = 0.00, withdrawal = 0.00, deposit = 0.00 "; |
| 659 | $comParaBancoMov .= ($bc_cash > 0 ? "<li>TENIA CASH $ ".echonf($bc_cash, true)." " : ""); |
| 660 | $comParaBancoMov .= ($bc_withdrawal > 0 ? "<li>TENIA WITHDRAWAL $ ".echonf($bc_withdrawal, true)." " : ""); |
| 661 | $comParaBancoMov .= ($bc_deposit > 0 ? "<li>TENIA DEPOSIT $ ".echonf($bc_deposit, true)." " : ""); |
| 662 | $comParaBancoMov .= ($bc_tc > 0 ? "<li>TIPO DE CAMBIO $ ".echonf($bc_tc, true)." " : ""); |
| 663 | } |
| 664 | |
| 665 | if($acta_tbl == 'banco_cuenta_mov') |
| 666 | { |
| 667 | $quantity_total = $Quantity; |
| 668 | $bcm_sql = "UPDATE $commentSQL banco_cuenta_mov SET |
| 669 | link_vale = 'ND' |
| 670 | , usado = '0.00' |
| 671 | , remarks = '<li>TRANSFERENCIA ENTRE CUENTAS BANCARIAS CANCELADA POR <strong>$usuario</strong>' |
| 672 | $updateFields |
| 673 | WHERE banco_cuenta_mov_id = '$acta_id'"; |
| 674 | $sql[] = $bcm_sql; |
| 675 | } |
| 676 | else |
| 677 | { |
| 678 | $sql[] = "UPDATE $commentSQL $acta_tbl SET banco_cuenta_mov_link_id = 'roto' WHERE $acta_id_nombre = '$acta_id' LIMIT 1"; |
| 679 | |
| 680 | //Sólo si no existe el Documento padre borramos el a cuenta. |
| 681 | //Quiere decir que era un link mocho, y no hay necesidad de dejarlo vivo. |
| 682 | if(empty($actapadre_id) && $acta_tbl != 'cuentat_mov') |
| 683 | { |
| 684 | $quantity_total = $Quantity; |
| 685 | |
| 686 | $sql[] = "DELETE $commentSQL FROM $acta_tbl WHERE $acta_id_nombre = '$acta_id' LIMIT 1"; |
| 687 | $rlb_arr['acta'] = $acta_tbl; |
| 688 | } |
| 689 | else |
| 690 | { |
| 691 | //El Documento padre existe, entonces debemos hacer un Ingreso a la cuentaT. |
| 692 | //Primero averiguo a qué cuentaT debo Ingresar el dinero. |
| 693 | |
| 694 | //25-1-14 Creo que debo averiguar el movimiento original en cuenta t. |
| 695 | if($actapadre_tbl=='cheque' || $actapadre_tbl=='pagare' || $actapadre_tbl=='vale') |
| 696 | { |
| 697 | $ctaTMovIDOriginal = obtenCuentaTMovIDOriginal($acta_id); |
| 698 | $sqlctat = "SELECT /* BUSCA MOV CTA T EN CHEQUE, PAGARE, VALE */ * FROM cuentat_mov WHERE origen_mov_id = '$ctaTMovIDOriginal' AND tipo = '$cTtipomovCP' AND $cTcampoMontoCP = '$QuantityCtaT'"; |
| 699 | } |
| 700 | else |
| 701 | { |
| 702 | $sqlctat = "SELECT /* BUSCA MOV CTA T LINK AL BANCO, ETC. */ * FROM cuentat_mov WHERE (origen_mov_id = '$acta_id' OR cuentat_mov_id = '$acta_id') AND tipo = '$cTtipomovCP' AND $cTcampoMontoCP = '$Quantity'"; |
| 703 | } |
| 704 | $cuentaT_arr = ia_singleton($sqlctat); |
| 705 | |
| 706 | |
| 707 | /*$myFile = "valever.txt"; |
| 708 | $fh = fopen($myFile, 'w') or die("can't open file"); |
| 709 | fwrite($fh, $sqlctat . print_r($cuentaT_arr, true));*/ |
| 710 | |
| 711 | |
| 712 | if(array_key_exists('cuentaT_id', $cuentaT_arr)) //Verificamos que exista el movimiento original. Es muy importante. |
| 713 | { |
| 714 | $contra_mov_id = $cuentaT_arr['cuentaT_mov_id']; |
| 715 | $rlb_arr['link_ori_id'] = $contra_mov_id;//$cuentaT_arr['contra_mov_id']; |
| 716 | $actualizaCtaTMovOriginal = true; |
| 717 | |
| 718 | if($cuentaT_arr['app_origen']=='A Cuenta Cheque' || $cuentaT_arr['app_origen']=='A Cuenta Pagare' || $cuentaT_arr['app_origen']=='Cheque' || $cuentaT_arr['app_origen']=='Pagare' || $cuentaT_arr['app_origen']=='Vale') |
| 719 | { |
| 720 | $cuentaT_arr['origen_mov_id']=$acta_id; |
| 721 | $contra_mov_id = ''; |
| 722 | $actualizaCtaTMovOriginal = false; |
| 723 | } |
| 724 | else |
| 725 | $cuentaT_arr['origen_mov_id']=$cuentaT_arr['cuentaT_mov_id']; |
| 726 | |
| 727 | //$cuentaT_arr['cuentaT_mov_id'] = ia_guid(); |
| 728 | $cuentaT_mov_id = ia_guid(); |
| 729 | |
| 730 | $cuentaT_arr['fecha'] = $ultimo_cambio; |
| 731 | $cuentaT_arr['alta_db'] = $ultimo_cambio; |
| 732 | $cuentaT_arr['alta_por'] = $usuario; |
| 733 | $cuentaT_arr['ultimo_cambio'] = $ultimo_cambio; |
| 734 | $cuentaT_arr['ultimo_cambio_por'] = $usuario; |
| 735 | |
| 736 | $cuentaT_arr['cuentaT_tipo_mov_id'] = 2; |
| 737 | |
| 738 | if($dedonde == "<li>LINK ROTO DESDE ESTADO DE CUENTA POR ") |
| 739 | { |
| 740 | $cuentaT_arr['remarks'] = "$dedonde <strong>$usuario</strong><hr>".addslashes($cuentaT_arr['remarks']); |
| 741 | } |
| 742 | else if(!empty($dedonde)) |
| 743 | { |
| 744 | $ctaBancariaNombre = ia_htmlentities(ia_singleread("SELECT $commentSQL nombre FROM banco_cuenta WHERE banco_cuenta_id = '$cuentaT_arr[banco_cuenta_id]'")); |
| 745 | $ctaBancariaNombre = "CUENTA <a title='$ctaBancariaNombre' href='../cobranza/edocta.php?ACC=CB&ECO=SI&banco_cuenta_id=$cuentaT_arr[banco_cuenta_id]' target='_blank'><strong>$ctaBancariaNombre</strong></a>"; |
| 746 | |
| 747 | $dedonde = stripslashes($dedonde); |
| 748 | $dedonde = str_replace('SE ROMPE LINK BANCARIO DEL', "SE ROMPE LINK BANCARIO $ctaBancariaNombre DEL",$dedonde); |
| 749 | $dedonde = addslashes($dedonde); |
| 750 | |
| 751 | $cuentaT_arr['remarks'] = "$dedonde <strong>$usuario</strong>."; |
| 752 | } |
| 753 | |
| 754 | $quantity_total = $cuentaT_arr['quantity_total']; |
| 755 | |
| 756 | $ctaT_sql = array(); |
| 757 | |
| 758 | //Insertamos el contramovimiento, o sea, la cancelación. |
| 759 | $sql[] = "INSERT $commentSQL INTO cuentat_mov (cuentaT_mov_id, cuentaT_id, fecha, cuentaT_tipo_mov_id, $cTcampoMonto, moneda_id, tipo_cambio, banco_cuenta_id, referencia, remarks, banco_cuenta_mov_link_id, cuentaT_deliveredto_id, esta_en, cuentaT_transferto_id, quantity_total, ultimo_cambio, ultimo_cambio_por, alta_db, alta_por, tipo, origen_mov_id, app_origen, fecha_deposito, deposit_total, contra_mov_id, activo) VALUES |
| 760 | ( '$cuentaT_mov_id', |
| 761 | '$cuentaT_arr[cuentaT_id]', |
| 762 | '$cuentaT_arr[fecha]', |
| 763 | '$cuentaT_arr[cuentaT_tipo_mov_id]', |
| 764 | '$cuentaT_arr[$cTcampoMontoCP]', |
| 765 | '$cuentaT_arr[moneda_id]', |
| 766 | '$cuentaT_arr[tipo_cambio]', |
| 767 | '$cuentaT_arr[banco_cuenta_id]', |
| 768 | '$cuentaT_arr[referencia]', |
| 769 | '$cuentaT_arr[remarks]', |
| 770 | '$cuentaT_arr[cuentaT_mov_id]', NULL, 'user', NULL, |
| 771 | '$cuentaT_arr[quantity_total]', |
| 772 | '$cuentaT_arr[ultimo_cambio]', |
| 773 | '$cuentaT_arr[ultimo_cambio_por]', |
| 774 | '$cuentaT_arr[alta_db]', |
| 775 | '$cuentaT_arr[alta_por]', |
| 776 | '$cTtipomov', |
| 777 | '$cuentaT_arr[origen_mov_id]', |
| 778 | '$cuentaT_arr[app_origen]', |
| 779 | '$cuentaT_arr[fecha_deposito]', |
| 780 | '$cuentaT_arr[deposit_total]', |
| 781 | '$contra_mov_id','No')"; |
| 782 | |
| 783 | //Actualizamos el movimiento original. |
| 784 | if($actualizaCtaTMovOriginal) |
| 785 | $sql[] = "UPDATE $commentSQL cuentat_mov SET ultimo_cambio='$now', contra_mov_id='$cuentaT_mov_id', activo='No' WHERE cuentaT_mov_id='$cuentaT_arr[cuentaT_mov_id]'"; |
| 786 | |
| 787 | $rlb_arr['cuentat_id'] = $cuentaT_arr['cuentaT_id']; |
| 788 | $rlb_arr['cuentat_mov'] = $cuentaT_arr['cuentaT_mov_id']; |
| 789 | $rlb_arr['link_roto_id'] = $cuentaT_mov_id; |
| 790 | $cuentaT_arr['cuentaT_mov_id'] = $cuentaT_mov_id; |
| 791 | $rlb_arr['arr_cuentat_mov'] = $cuentaT_arr; |
| 792 | |
| 793 | /** |
| 794 | fwrite($fh, "rlb: \r\n".print_r($rlb_arr, true)."\r\nSQL:". print_r($sql, true)."</pre>"); |
| 795 | fclose($fh); |
| 796 | **/ |
| 797 | } |
| 798 | } |
| 799 | } |
| 800 | $link_vale = $acta_tbl == 'banco_cuenta_mov' ? " link_vale = IF(usado-$usado=0,'Q','LP'), usado = 0 " : " link_vale = IF(usado-$usado=0,'Q','LP'), usado = usado-$usado "; |
| 801 | $remarks = ", remarks = ".strit($comParaBancoMov); |
| 802 | //$Quantity = 500; |
| 803 | $sql[] = "UPDATE $commentSQL banco_cuenta_mov SET |
| 804 | $link_vale |
| 805 | , ultimo_cambio = '$ultimo_cambio' |
| 806 | , ultimo_cambio_por = '$usuario' |
| 807 | , link_el = NULL |
| 808 | , link_por = '$usuario' |
| 809 | $updateFields |
| 810 | $remarks |
| 811 | WHERE banco_cuenta_mov_id = '$bcm_id'"; |
| 812 | |
| 813 | $sql[] = "DELETE $commentSQL FROM banco_cuenta_mov_link WHERE banco_cuenta_mov_link_id = ". strit($bcml_id) ." LIMIT 1"; //Borro el banco_cuenta_mov_link. |
| 814 | |
| 815 | $rlb_arr['sql'] = $sql; |
| 816 | |
| 817 | /** |
| 818 | |
| 819 | $myFile = "valever.txt"; |
| 820 | $fh = fopen($myFile, 'w') or die("can't open file"); |
| 821 | fwrite($fh, $sqlctat . print_r($sql, true)); |
| 822 | * |
| 823 | * **/ |
| 824 | |
| 825 | |
| 826 | if($doRLB) |
| 827 | { |
| 828 | if(ia_transaction($sql)) |
| 829 | { |
| 830 | ia_errores_a_dime(); |
| 831 | if($gIAsql['trace']) |
| 832 | ia_errores_a_dime("sql_trace=".print_r($gIAsql['sql_trace'],true)); |
| 833 | return false; |
| 834 | } |
| 835 | } |
| 836 | |
| 837 | return $rlb_arr; |
| 838 | } |