<?php
session_start();
$ruta='../';
require_once("clases/covensol_cxc_c_cuentasxcobrar.php");
$objcxc = new covensol_cxc_cuentasxcobrar();
$objcxc->io_conexiones->decodificar_post();
$opciones = $objcxc->io_conexiones->asignar_post();
$objcxc->ope =  $opciones['operacion'];
			
		
if($opciones['accion']=='ANULAR'){	
	$objcxc->Ids = explode(',',$opciones['ids']);
	if(sizeof($objcxc->Ids)>0 and $opciones['ids']!=""){	
		
		$objcxc->io_sql->begin_transaction();
		$objcxc->fecanula = $opciones['fecanula'];
		$objcxc->conanula = $opciones['conanula'];
		$objcxc->io_sql->DisableTrans = 1;
		switch($objcxc->ope){
			case 'A':
				$resp = $objcxc->ProcAnulaFactura($opciones);
				$msj = "La anulación se realizó con éxito.";
				$msjError = "<b>ERROR:</b> Las facturas no Pudieron ser Anuladas. <br>Transacción Abortada!";
				break;
				
			case 'R':
				$resp = $objcxc->ProcRevAnulaFactura($opciones);
				$msj = "El reverso de anulación se realizó con éxito.";
				$msjError = "<b>ERROR:</b> El reverso de anulación no se pudo realizar. <br>Transacción Abortada!";
				break;		
		}
		$objcxc->io_sql->DisableTrans = 0;		
		//$resp=false;
		if($resp===false){
			$objcxc->io_sql->rollback();
			$objcxc->io_conexiones->mensajes_ajax($msjError);
			if($resp===false){exit();}			
		}	
		else{							
			$objcxc->io_sql->commit();
			$objcxc->io_conexiones->mensajes_ajax($msj);
		}
	}
	else{
		$objcxc->io_conexiones->mensajes_ajax("No se seleccionó ninguna factura.");
	}
	
}

switch($opciones['operacion']){
	case 'A':
		$opciones['criterio']='por_listado_anulacion';
		break;
		
	case 'R':
		$opciones['criterio']='por_listado_reverso_anulacion';
		break;		
}			
		
$filas = $objcxc->consulta_facturas($opciones);

$ancho[8] = 20;
$ancho[0] = 80;
$ancho[1] = 80;
$ancho[2] = 250;
$ancho[3] = 80;
$ancho[4] = 80;
$ancho[5] = 80;
$ancho[6] = 190;
$ancho[7] = 20;
					
$ancho_total = array_sum($ancho);

if($filas['cantidad']){

?>
        <link href="../shared/css/catalogos.css" rel="stylesheet" type="text/css">
        <link href="../shared/css/tablas.css" rel="stylesheet" type="text/css">
        
        <table width="<?php echo $ancho_total; ?>" border="0" cellpadding="0" cellspacing="0"   class='fondo-tabla'>
          <tr class="titulo-celda">
            <td width="<?php echo $ancho[8] ?>" align="center"></td>
            <td width="<?php echo $ancho[0] ?>" align="center">Número</td>
            <td width="<?php echo $ancho[1] ?>" align="center">Control</td>
            <td width="<?php echo $ancho[2] ?>" align="center">Cliente</td>
            <td width="<?php echo $ancho[3] ?>" align="center">Estatus</td>
            <td width="<?php echo $ancho[4] ?>" align="center">Fecha</td>
            <td width="<?php echo $ancho[5] ?>" align="center">Monto</td>                
            <td width="<?php echo $ancho[6] ?>" align="center">Vendedor</td>
            <td width="<?php echo $ancho[7] ?>" align="center"></td>                
            
          </tr>
          <?php do {  ?>
          
          <?php
           $mostrar=1;
           
           if($mostrar==1){	
                
                //$aceptar = 'onClick="aceptar('.$filas['fila']['id_fact'].",'".$objcxc->formato_numero_fact($filas['fila']['numfact'])."','".$filas['fila']['numcont']."','".$filas['fila']['codfact']."')".'"';                                       
                $aceptar = "";	
                                            
                switch($filas['fila']['id_estfact']){                
                        case '1':
                                 $color_fila='style="background-color:#FFFFFF"';
                            break;
                        
                        case '4':
                                $color_fila='style="background-color:#FFFFBB"';
                            break;
                            
                        case '3':
                                 $color_fila='style="background-color:#E1ECEC"';
                            break;                
                }
                                                                                                        
                
            ?>
                      <tr id="consulta" <?php echo $color_fila; ?> > 
                      <td width="<?php echo $ancho[8] ?>" align="right"><input type="checkbox" name="chkselec" id="chkselec" value="<?php echo $filas['fila']['id_fact'];?>" ></td>
                      <td width="<?php echo $ancho[0] ?>" align="right"><a href="#" <?php echo $aceptar; ?>><div style="color:#189FBC;padding-right:10px;"><?php echo $filas['fila']['numfact']; ?></div></a></td>
                      <td width="<?php echo $ancho[1] ?>" align="right"><a href="#" style="color:#990000;padding-right:5px;" <?php echo $aceptar; ?>><?php echo $filas['fila']['numcont']; ?></a></td>
                        <td width="<?php echo $ancho[2] ?>" align="left"><a href="#" <?php echo $aceptar; ?>><?php echo $filas['fila']['nombre_cliente']; ?></a></td>
                        <td width="<?php echo $ancho[3] ?>" align="left"><a href="#" <?php echo $aceptar; ?>><?php echo $filas['fila']['descestfact']; ?></a></td>							
                        <td width="<?php echo $ancho[4] ?>" align="center"><a href="#" <?php echo $aceptar; ?>><?php echo $objcxc->io_conexiones->formatea_fecha_normal($filas['fila']['fecfact']); ?></a></td>
                        <td width="<?php echo $ancho[5] ?>" align="right"><a href="#" <?php echo $aceptar; ?>><?php echo number_format($filas['fila']['total'],2,',','.'); ?></a></td>
                        <td width="<?php echo $ancho[6] ?>" align="left"><a href="#" <?php echo $aceptar; ?>><div style="padding-left:10px;"><?php echo $filas['fila']['nomvend']; ?></div></a></td>
                        <td width="<?php echo $ancho[7] ?>" align="left"><a href="#"  onclick="imprimir_fact(<?php echo $filas['fila']['id_fact']; ?>);"><img src="../shared/imagebank/tools20/imprimir.gif" alt="Reporte de resumen de gestion de documento" width="20" height="20" border="0" /></a></td>                                        
                       
          </tr>
                      <tr>
                        <td height="1" bgcolor="#BBBBBB" colspan="5">
                            <input name="hnombre_cliente<?php echo $filas['fila']['id_fact'];?>" type="hidden" id="hnombre_cliente<?php echo $filas['fila']['id_fact'];?>"  value="<?php echo $filas['fila']['nombre_cliente']; ?>"/>
                            <input name="htotal<?php echo $filas['fila']['id_fact'];?>" type="hidden" id="htotal<?php echo $filas['fila']['id_fact'];?>"  value="<?php echo number_format($filas['fila']['total'],2,',','.'); ?>"/>
                            <input name="hidestfact<?php echo $filas['fila']['id_fact'];?>" type="hidden" id="hidestfact<?php echo $filas['fila']['id_fact'];?>"  value="<?php echo $filas['fila']['id_estfact']; ?>"/>
                            <input name="hestfact<?php echo $filas['fila']['id_fact'];?>" type="hidden" id="hestfact<?php echo $filas['fila']['id_fact'];?>"  value="<?php echo $filas['fila']['descestfact']; ?>"/>
                        </td>
                      </tr>
            <?php } ?>
          <?php } while($filas['fila'] = $obj_sql->fetch_row($filas['rs']));?>
        </table>	
<?php 
  
  }// CIERRE DEL IF PRINCIPAL
  else{
  
  		$mensaje = 'No hay facturas encontradas para este criterio de busqueda.<br>';
		$objcxc->io_conexiones->mensajes_ajax($mensaje);
  
  }
  
  
  ?>          