<?php
session_start();
include("class_folder/sigesp_cxp_c_cmp_retencion.php");
$objcxp = new sigesp_cxp_c_cmp_retencion("../");
$objcxp->io_conexiones->decodificar_post();
$datos = $objcxp->io_conexiones->asignar_post();

$ls_logusr=$_SESSION["la_logusr"];
require_once("../shared/class_folder/class_funciones.php");
$io_funciones=new class_funciones();
require_once("class_folder/class_funciones_cxp.php");
$io_fun_cxp=new class_funciones_cxp();
$io_fun_cxp->uf_load_seguridad("CXP","sigesp_cxp_p_cmp_retencion.php",$ls_permisos,$la_seguridad,$la_permisos);
$objcxp->Seguridad = $la_seguridad;

switch($datos['PROCESO']){
	
	case 'PROCESAR':
		$resul = $objcxp->ProcCmpRet($datos);
		if($resul===false){break;}
		
		if(sizeof($objcxp->CmpGen)<1){
			$objcxp->io_conexiones->mensajes_ajax("No se generaron Comprobantes de Retencion verifique sus datos!!"); 
			break;
		}
		
		foreach($objcxp->CmpGen as $CmpGen){$TxtCmpGen .= $CmpGen.',';}
		$objcxp->io_conexiones->mensajes_ajax("Se procesaron satisfactoriamente: <br><b>Cantidad de Comprobantes:</b> ".sizeof($objcxp->CmpGen)."<br><b>N° Comprobantes:</b> ".$TxtCmpGen);
		break;
	
			
				
	case 'BUSCAR':			
				$resultado = $objcxp->BuscarRecepciones($datos);
				?>
				<link href="../../shared/css/catalogos.css" rel="stylesheet" type="text/css">
				<?php 
				$ancho[1] = 30;
				$ancho[2] = 200;
				$ancho[3] = 150;
				$ancho[4] = 150;
				$ancho[5] = 300;
				//$ancho[6] = 150;
				$ancho[7] = 150;
				$ancho[8] = 200;
				$ancho_total = array_sum($ancho);
				
				?>
				<link href="../shared/css/cabecera.css" rel="stylesheet" type="text/css">
				<link href="../shared/css/general.css" rel="stylesheet" type="text/css">
				<link href="../shared/css/tablas.css" rel="stylesheet" type="text/css">
				<link href="../shared/css/ventanas.css" rel="stylesheet" type="text/css">
				<link href="../shared/js/css_intra/datepickercontrol.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[1]; ?>"><div align="center"><input type="checkbox" name="chktodo" id="chktodo" onclick="marcar_todas(this)"></div></td>
					 <td width="<?php echo $ancho[7]; ?>"><div align="center">RETENCIÓN</div></td>
					<td width="<?php echo $ancho[2]; ?>"><div align="center">PROVEEDOR</div></td>
					 <td width="<?php echo $ancho[3]; ?>"><div align="center">SOLICITUD</div></td> 
					 <td width="<?php echo $ancho[4]; ?>"><div align="center">RECEP. DOC.</div></td> 
					 <td width="<?php echo $ancho[5]; ?>"><div align="center">CONCEPTO</div></td>      
					 <td width="<?php echo $ancho[8]; ?>"><div align="center">PROV. ALTERNO</div></td>     
				  </tr>
				  <?php foreach($resultado as $fila) { ?>
				<?php
							$seguridad = true;	
							if($seguridad){	
									  
							$IdRet = trim($fila['numsol']).'|'.trim($fila['numrecdoc']).'|'.trim($fila['codtipdoc']).'|'.trim($fila['ced_bene']).'|'.trim($fila['cod_pro']).'|'.trim($fila['procede_doc']).'|'.trim($fila['numdoccom']).'|'.trim($fila['tipsolpag']).'|'.trim($fila['codded']).'|'.trim($fila['codcar']).'|'.trim($fila['tipproben']).'|'.trim($fila['codproalt']).'|'.trim($fila['porded']).'|'.trim($fila['porcar']);
							
							$CodSujRet = ($fila['tipproben']=="P")?$fila['cod_pro']:$fila['ced_bene'];
							
							$monret = $fila['monret'];
							if($fila['iva']){
								$monret = $fila['subtotret'];	
							}
							
							/****************************************************************************************************/
							/*********** SI ES UNA LIQUIDACIÓN DE ANTICIPO EL TOTAL DE LA FACTURA ES EL TOTAL SPG ***************/
							/****************************************************************************************************/
							if($fila['tipsolpag']=='LIQA'){
								$montotfact = $objcxp->MonTotLiqAnt($fila);
								if($montotfact===false){return false;}
								$fila['montotdoc'] = $montotfact-$fila['mondeddoc'];
							}
							/****************************************************************************************************/
							
							$DatosProv = '<b>cod/ced: </b>'.$CodSujRet.'<br><b>Rif: </b>'.$fila['rifpro'].'<br><b>Nombre: </b>'.$fila['nompro'];
							$DatosSolic = '<b>Num: </b>'.$fila['numsol'].'<br><b>Estatus: </b>'.$fila['desc_estprosol'].'<br><b>Fecha Sol.: </b>'.$objcxp->io_conexiones->formatea_fecha_normal($fila['fecemisol']);
							$DatosRecep = '<b>Num: </b>'.$fila['numrecdoc'].
										  '<br><b>Estatus: </b>'.$fila['estatus_rd']	.
										  '<br><b>Fec. Emi.: </b>'.$objcxp->io_conexiones->formatea_fecha_normal($fila['fecemidoc']).
										  '<br><b>Fec. Reg.: </b>'.$objcxp->io_conexiones->formatea_fecha_normal($fila['fecregdoc']).
										  '<br><b>Fec. Aprob.: </b>'.$objcxp->io_conexiones->formatea_fecha_normal($fila['fecaprord']);
							$DatosMontos = '<b>Sub Tot: </b>'.number_format($fila['montotdoc']+$fila['mondeddoc']-$fila['moncardoc'] ,2,',','.').
							               '<br><b>Obj. Ret.: </b>'.number_format($fila['monobjret'],2,',','.').
										   '<br><b>Ret.: </b>'.number_format($monret,2,',','.');
							$DatosCargos = '<b>Base Imp.: </b>'.number_format($fila['subtotbasimp'],2,',','.').
							               '<br><b>Mon. Car.: </b>'.number_format($fila['moncar'],2,',','.').
										   '<br><b>Porc(%): </b>'.number_format($fila['porcar'],2,',','.');
							if($fila['subtotbasimp'] and $fila['monret']){$DatosMontos = $DatosMontos.'<br>'.$DatosCargos;}
							$DatosRet = '<b>Cod: </b>'.$fila['codded'].'<br><b>Denom.: </b>'.$fila['dended'].'<br>'.$DatosMontos;
							$DatosProvAlt = '<b>Cod: </b>'.$fila['codproalt'].'<br><b>Rif: </b>'.$fila['nomproalt'].'<br><b>Nombre: </b>'.$fila['rifproalt'];
						   ?>    
								  <tr id="consulta">
									<td width="<?php echo $ancho[1]; ?>"><div align="left"><input type="checkbox" name="chkdoc" id="chkdoc" value="<?php echo $IdRet; ?>" ></div></td>
									<td width="<?php echo $ancho[7]; ?>" valign="top"><div align="left" style="font-size:10px"><?php echo $DatosRet;?></div></td>
									<td width="<?php echo $ancho[2]; ?>" valign="top"><div align="left" style="font-size:10px"><?php echo $DatosProv;?></div></td>
									<td width="<?php echo $ancho[3]; ?>" valign="top"><div align="left" style="font-size:10px"><?php echo $DatosSolic;?></div></td>
									<td width="<?php echo $ancho[4]; ?>" valign="top"><div align="left" style="font-size:10px"><?php echo $DatosRecep;?></div></td>
									<td width="<?php echo $ancho[5]; ?>" valign="top"><div align="left" style="font-size:10px"><?php echo $fila['dencondoc'];?></div></td>
									<td width="<?php echo $ancho[8]; ?>" valign="top"><div align="left" style="font-size:10px"><?php echo $DatosProvAlt;?></div></td>
				  </tr>
								  <tr>
									<td height="1" bgcolor="#BBBBBB" colspan="8">
									</td>
								  </tr>
						  <?php } ?>
				  <?php }  ?>
				</table>
 				<?php 
       break;
}					
