<style>
	.fila_0{background-color:#F0F0F9;}
	.fila_0:hover{background-color: #FFFFFF;font-weight: bold;}
	.fila_1{background-color:#D9D7D8;}
	.fila_1:hover{background-color: #FFFFFF;font-weight: bold;}
	.sfila_0{background-color:#E9E9F5;}
	.sfila_1{background-color:#CFCDCE;}
</style>
<?php 
ini_set('date.timezone','America/Lima');
require_once("../include/EntidadMod.php");
$obj_con=new EntidadMod();
if(isset($_POST)){
	$dia = $_POST["dia"];
	$mes = $_POST["mes"];
	$ano = $_POST["ano"];
	$bus = $_POST["bus"];
	$den = $_POST["den"];
	$acc = $_POST["acc"];
	$ins = $_POST["ins"]; 
	$par = $_POST["par"];
	$res = $_POST["res"]; 
	$cla = $_POST["cla"]; 
	$valor=$obj_con->filtrarEntidad($dia,$mes,$ano,$bus,$den,$acc,$ins,$par,$res,$cla);
	if($valor!=0){
		for($i=0;$i<count($valor);$i++){
			//$cdfx= $valor[$i]->getCodsiaf();
			//$orgx= ucwords(strtolower($valor[$i]->getOrganizacion()));
			$ide=$valor[$i]->getIdentidad();
			$cod=$valor[$i]->getCod_entidad();
			$nom=ucwords(strtolower(utf8_encode($valor[$i]->getNom_entidad())));
			$cnm=$cod." - ".$nom;
			$per=$valor[$i]->getPermisos();
			$int=$valor[$i]->getInstaladores();
			$pac=$valor[$i]->getParches();
			$reu=$valor[$i]->getResumenes();
			$clv=$valor[$i]->getClaves();
			$fml=$valor[$i]->getFecha_mel();
			$fcl=$valor[$i]->getFecha_cla();
			$fmc=$valor[$i]->getFecha_myc();
			$est=$valor[$i]->getEstado();
			$dep=ucwords(strtolower($valor[$i]->getDepart()));
			$pro=ucwords(strtolower($valor[$i]->getProvin()));
			$dis=ucwords(strtolower($valor[$i]->getDistri()));
			$igv=$valor[$i]->getIgv();
?>
<div class="ch fila_<?=$i%2?>">
	<div>
		<span class="lh nb dot1" style="width:26%;"><?=$cnm?></span>
		<span class="lh nb" style="width:7%">
			<script>
				$(".cbace_<?=$i?>").on('change',function() {
					if($(this).is(':checked') ) { actiAcceso('<?=$id?>','1');} 
					else { actiAcceso('<?=$id?>','0');}
				});
			</script>
			<input name="checacceso<?=$i?>" class="cbace_<?=$i?>" type="checkbox" id="checacceso<?=$i?>" style="cursor: pointer" <?php if($per=='1'){echo('checked="checked"');} ?>>
			<label for="checacceso<?=$i?>" style="cursor: pointer">Acceso</label>
		</span>
		<span class="lh nb" style="width:7%">
			<script>
				$(".cbins_<?=$i?>").on('change',function() {
					if($(this).is(':checked') ) {actiInstal('<?=$id?>','1');} 
					else { actiInstal('<?=$id?>','0');}
				});
			</script>
			<input name="checinstal<?=$i?>" type="checkbox" id="checinstal<?=$i?>" class="cbins_<?=$i?>" style="cursor: pointer" <?php if($int=='1'){echo('checked="checked"');} ?>>
			<label for="checinstal<?=$i?>" style="cursor: pointer">Instaladores</label>
		</span>
		<span class="lh nb" style="width:7%">
			<script>
				$(".cbpar_<?=$i?>").on('change',function() {
					if($(this).is(':checked') ) {actiParche('<?=$id?>','1');} 
					else {actiParche('<?=$id?>','0');}
				});
			</script>
			<input name="checparch<?=$i?>" type="checkbox" id="checparch<?=$i?>" style="cursor: pointer" class="cbpar_<?=$i?>" <?php if($pac=='1'){echo('checked="checked"');} ?>>
			<label for="checparch<?=$i?>" style="cursor: pointer">Parches</label>
		</span>
		<span class="lh nb" style="width:7%;">
			<script>
				$(".cbres_<?=$i?>").on('change',function() {
					if($(this).is(':checked') ) {actiResume('<?=$id?>','1');} 
					else { actiResume('<?=$id?>','0'); }
				});
			</script>
			<input name="checresum<?=$i?>" type="checkbox" id="checresum<?=$i?>" style="cursor: pointer" class="cbres_<?=$i?>" <?php if($reu=='1'){echo('checked="checked"');} ?>>
			<label for="checresum<?=$i?>" style="cursor: pointer">Resumenes</label>
		</span>
		<span class="lh nb" style="width:7%">
			<script>
				$(".cbcla_<?=$i?>").on('change',function() {
					if($(this).is(':checked') ) {actiClaves('<?=$id?>','1');} 
					else {actiClaves('<?=$id?>','0');}
				});
			</script>
			<input name="checclaves<?=$i?>" type="checkbox" id="checclaves<?=$i?>" style="cursor: pointer" class="cbcla_<?=$i?>" <?php if($clv=='1'){echo('checked="checked"');} ?>>
			<label for="checclaves<?=$i?>" style="cursor: pointer">Claves</label>
		</span>
		<span class="lh nb" style="width:8%;font-size: 10px;">
			<?php
				
				$aa=date("Y"); 
				$ma=date("m"); 		
				$da=date("d");
				$fa=$aa."-".$ma."-".$da; //Fecha actual
			
				/* Restantes de Melissa */
				$d1=new DateTime($fa); //Actual
				$d2=new DateTime($fml);//Melissa
				$d3=new DateTime($fcl);//Clarissa
				$d4=new DateTime($fmc);//Clarissa
			    //Melissa
				$ntm=$d1->diff($d2);
				$itnm = $ntm->format('%r%a');
				//Clarissa
				$ntc=$d1->diff($d3);
				$itnc = $ntc->format('%r%a');
				//MYC
				$ntmc=$d1->diff($d4);
				$itnmc = $ntmc->format('%r%a');
				
			
				if($fml=='' && $fcl=='' && $fmc==''){
					echo '<span style="color: #168750">Nuevo</span>';
				}else if($fml!='' && $fcl=='' && $fmc==''){
					if($itnm<0){
						echo '<span style="color: #C8351F">Vencido</span>';
					}else{
						echo "<span>Melissa: ".$fml."</span>";
					}
				}else if($fml=='' && $fcl!='' && $fmc==''){
					if($itnc<0){
						echo '<span style="color: #C8351F">Vencido</span>';
					}else{
						echo "<span>Clarissa: ".$fcl."</span>";
					}
				}else if($fml=='' && $fcl=='' && $fmc!=''){
					if($itnmc<0){
						echo '<span style="color: #C8351F">Vencido</span>';
					}else{
						echo "<span>MyC: ".$fmc."</span>";
					}	
				}else if($fml!='' && $fcl!='' && $fmc==''){
					if($itnm<0 && $itnc>=0){
						echo "<span>Clarissa: ".$fcl."</span>";
					}else if($itnm>=0 && $itnc<0){
						echo "<span>Melissa: ".$fml."</span>";
					}else if($itnm>=0 && $itnc>=0){
						echo "<span>M: ".$fml." &nbsp;C: ".$fcl."</span>";
					}else{
						echo '<span style="color: #C8351F">Vencido</span>';
					}
				}else if($fml=='' && $fcl!='' && $fmc!=''){
					if($itnc<0 && $itnmc>=0){
						echo "<span>MyC: ".$fmc."</span>";
					}else if($itnc>=0 && $itnmc<0){
						echo "<span>Clarissa: ".$fcl."</span>";
					}else if($itnc<0 && $itnmc<0){
						echo '<span style="color: #C8351F">Vencido</span>';
					}
				}else if($fml!='' && $fcl=='' && $fmc!=''){
					if($itnm<0 && $itnmc>=0){
						echo "<span>MyC: ".$fmc."</span>";
					}else if($itnm>=0 && $itnmc<0){
						echo "<span>Melissa: ".$fml."</span>";
					}else if($itnm<0 && $itnmc<0){
						echo '<span style="color: #C8351F">Vencido</span>';
					}
				}else if($fml!='' && $fcl!='' && $fmc!=''){
					if($itnm>=0 && $itnc<0 && $itnmc<0 ){
						echo "<span>Melissa: ".$fml."</span>";
					}else if($itnm<0 && $itnc>=0 && $itnmc<0){
						echo "<span>Clarissa: ".$fcl."</span>";
					}else if($itnm<0 && $itnc<0 && $itnmc>=0){
						echo "<span>MyC: ".$fmc."</span>";
					}else if($itnm>=0 && $itnc>=0 && $itnmc<0){
						echo "<span>M: ".$fml." &nbsp;C: ".$fcl."</span>";
					}else if($itnm<0 && $itnc<0 && $itnmc<0){
						echo '<span style="color: #C8351F">Vencido</span>';
					}
				}
			?>
		</span>
		<span class="lh nb" style="width:7%">
			<script>
				$(".cbcla_<?=$i?>").on('change',function() {
					if($(this).is(':checked') ) {actiEstado('<?=$id?>','1');} 
					else {actiEstado('<?=$id?>','0');}
				});
			</script>
			<input name="checclaves<?=$i?>" type="checkbox" id="checclaves<?=$i?>" style="cursor: pointer" class="cbcla_<?=$i?>" <?php if($est=='1'){echo('checked="checked"');} ?>>
			<label for="checclaves<?=$i?>" style="cursor: pointer">Denegado</label>
		</span>
		<span class="lh nb dot1" style="width:3%;font-size: 11px;">
			<?php
				if($dep==''){
					echo '<span style="color:#C8351F">No ubicado</span>';
				}else{
					echo '<span style="color:#A27338">'.$dep.'</span>';
				}
			?>
		</span>
		<span class="lh nb dot1" style="width:5%;font-size: 10px;">
			<?php
				if($pro==''){
					echo '<span style="color:#C8351F">No ubicado</span>';
				}else{
					echo '<span style="color:#175F55">'.$pro.'</span>';
				}
			?>
		</span>
		<span class="lh nb dot1" style="width:5%;font-size: 10px;">
			<?php
				if($dis==''){
					echo '<span style="color:#C8351F">No ubicado</span>';
				}else{
					echo '<span style="color:#366998">'.$dis.'</span>';
				}
			?>
		</span>
		<span class="lh nb dot1" style="width:5%;">
			<?php 
				if($igv==='0'){
					echo 'AYP';
				}else{
					echo 'SYS';
				}
			?>
		</span>
		<span class="lh nb" style="width:5%">
			<span class="icon-add-to-list" style="cursor:pointer;" onclick=" registrarAdquisicionx('<?=$cod?>','<?=$nom?>');"></span>
			<span class="icon-eye" style="cursor:pointer;margin-left: 10px" onclick="historial_adquisiciones('<?=$cod?>','<?=$cnm?>');"></span>
			<span class="icon-cross" style="cursor:pointer;margin-left: 10px" onclick="conf_elimin_enti('<?=$cod?>','<?=$cnm?>');"></span>
		</span>
	</div>
</div>
<?php  } ?>
<?php } else {?>
<div class="ch fila_1">
	<div>
		<span class="lh nb dot1" style="width:100%;font-size: 13px;">
			Entidades no disponibles - - Ingrese nuevo criterio de busqueda
		</span>
	</div>
</div>
<?php }}else{ echo 'Accion no permitida';}

?>