<?php
 
session_start();
include("DMMYSQLG.php");
//include("DSA1000.php");
include("DMMYSQLG.php");
include("DF30000.inc");
//   --->  llena matriz de percepciones y deducciones
$mat_pd = array("P04", "P12", "P19", "P20", "Q03", "Q04", "Q06", "Q13", "Q14", "Q15");

//   --->  Saca el axo, mes cve_nomi y no_nomi que depende de la variable de session  $_SESSION['tip_nomina']
$sq_pargen=mysqli_query($con ,"select * from dnpargen");
$dt_pargen=mysqli_fetch_array($sq_pargen);

$sq_tipnom=mysqli_query($con ,"select * from dntipnom where cve_nomi = '".$_SESSION['tip_nomina']."'");
$dt_tipnom=mysqli_fetch_array($sq_tipnom);
$mesproc=$dt_pargen["mes_pro"];
$fecproc=$dt_pargen["axo_pro"].'-'.$mesproc.'-01';

$ssq_cageno="select * from dncageno where cve_nomi = '".$_SESSION['tip_nomina']."' and axo_mes ='$fecproc' order by no_nomi";
$sq_cageno=mysqli_query($con ,$ssq_cageno);
while($dt_cageno=mysqli_fetch_array($sq_cageno)) if($dt_cageno['act_nom']=="NO") break;
	$axm = $dt_cageno['axo_mes']; 
	$axo = substr($axm,0,4);
	$mes = substr($axm,5,2);
	$cve_nomi = $dt_cageno['cve_nomi'];// tipo de nomina
	$no_nomi = $dt_cageno['no_nomi'];// numero de nomina
	/* echo 'Axo:'.$axo.'<br>';
	echo 'mes:'.$mes.'<br>';
	echo 'cve_nomi:'.$cve_nomi.'<br>';
	echo 'no_nomi:'.$no_nomi.'<br>';
	exit(); */
if(isset($_REQUEST['Submit6']) and  $_REQUEST['t2']<>""){
	//agregar
	$tm="A";
	$tipo=$_REQUEST['co1'];
	$no_nomina=$_REQUEST['bot'];
	$operac=$_REQUEST['t1'];
	$no_pd=$_REQUEST['t2'];
	$can_nom=$_REQUEST['t3'];
	$can_tot=$_REQUEST['t4'];
	if(($can_nom=="" or $can_nom==0 or $can_tot=="" or $can_tot==0 )and $_REQUEST['co1']=="A"){

		?>
		<script language="javascript1.2">
			alert ("Se necesita una cantidad");
		</script>
		<?php

	}else{
		$ent = "ent";
		include ("DN31500_CL.php");
	}

}
if(isset($_REQUEST['boton3'])){
	
	$tm="E";
	$arrLlaves = array_keys($_POST);
	$TotalRecibidos = count($arrLlaves);
	for ($i=0;$i<$TotalRecibidos;$i++){
		$let = substr($arrLlaves[$i],0,4);
		if($let == "cver"){
			if($_POST[$arrLlaves[$i]] <> ""){
				$n_reg=$_POST[$arrLlaves[$i]];
				include ("DN31500_CL.php");
			}
		}
	}
}
if(isset($_REQUEST['boton4'])){

	//Modificar
	$tm="M";
	$tipo=$_REQUEST['co1'];
	$no_nomina=$_REQUEST['bot'];
	$n_reg = $_REQUEST['key_inc'];
	$operac=$_REQUEST['t1'];
	$no_pd=$_REQUEST['t2'];
	$can_nom=$_REQUEST['t3'];
	$can_tot=$_REQUEST['t4'];
	if(($can_nom=="" or $can_nom==0 or $can_tot=="" or $can_tot==0 )and $_REQUEST['co1']=="A"){
		?>
		<script language="javascript1.2">
			alert ("Se necesita una cantidad");
		</script>
		<?php

	}else{
		$ent = "ent";
		include ("DN31500_CL.php");
	}
}

if(isset($_REQUEST['boton2']) or ($_REQUEST['ttr']==1 and $tm <> "M")){
	$arrLlaves = array_keys($_POST);
	$TotalRecibidos = count($arrLlaves);
	for ($i=0;$i<$TotalRecibidos;$i++){
		$let = substr($arrLlaves[$i],0,4);
		if($let == "cver"){
			if($_POST[$arrLlaves[$i]] <> ""){
				$n_reg=$_POST[$arrLlaves[$i]];
			}
		}
	}
	$ssss = mysqli_query($con ,"select * from dnincfij where n_reg = '$n_reg'");
	$ffr = mysqli_fetch_array($ssss);
}

?>

<html>
<link rel="stylesheet" href="css/estilo1.css" type="text/css"/>
<script type="text/javascript" language="JavaScript1.2" src="DSSCRIPT.js"></script>
<body>
<?php
 
$ayuda = 'DN31500A_AG.php';
include("DYAYUDA.php");
?>
<div align="center">
  <form name="frm1" id="frm1" method="post" action="">
  <input name="co1" type="hidden" value="<?php
 echo $_POST['co1'] ?>">
<input name="bot" type="hidden" <?php
 echo 'value = "'.$_POST['bot'].'"'?>>
<input name="key_inc" type="hidden" 
<?php
 
	if ($n_reg<>""){
		echo 'value = "'.$n_reg.'"';
	}else{
		echo 'value = "'.$_POST['key_inc'].'"';
	}
?>>
<br>
    <table   align="center">
      <tr>
        <th colspan="9"><div align="left">
          <input type="submit" name="Submit6" value="Agregar" onClick="openpage('DN31500_PR2.php','_self')"  
		  <?php
 
		  if(isset($_REQUEST['boton2']) or ($_REQUEST['ttr']==1 and $tm <> "M")){
		  	echo ' disabled';
		  }
		  ?>
		  />
          <input name="boton3" type="submit" id="boton3" onClick="openpage('DN31500_PR2.php','_self')" value="Eliminar"
		  <?php
 
		  if(isset($_REQUEST['boton2']) or ($_REQUEST['ttr']==1 and $tm <> "M")){
		  	echo ' disabled';
		  }
		  ?>
		  />
          <input name="boton2" type="submit" id="boton2" onClick="openpage('DN31500_PR2.php','_self')" onMouseMove="val_checks()" value="Modificar"<?php
 
		  if(isset($_REQUEST['boton2']) or ($_REQUEST['ttr']==1 and $tm <> "M")){
		  	echo ' disabled';
		  }
		  ?>
		  />
          <input type="button" name="Submit2" value="Regresar" onClick="openpage('DN31500_PR1.php','_self')"
		  <?php
 
		  if(isset($_REQUEST['boton2'])){
		  	echo ' disabled';
		  }
		  ?>
		  />
          <span class="inputcodigo">
          <?php
 
		if(isset($_REQUEST['boton2']) or ($_REQUEST['ttr']==1 and $tm <> "M")){
			?>
          <input name="ttr" type="hidden" value="1">
          <input name="boton4" type="submit" id="boton4" onClick="openpage('DN31500_PR2.php','_self')" value="Modificar"/>
          <?php

		}
		?>
          </span></div></th>
      </tr>
      <tr>
        <th colspan="8">INCIDENCIAS FIJAS (<?php
 echo $_POST['co1'] ?>) EMPLEADO :   
		<?php
 
		$no_nomina = $_REQUEST['bot'];
		$bus = mysqli_query($con ,"select * from dntrab_a where no_trab = $no_nomina");
		$row1 = mysqli_fetch_array($bus);
		echo $no_nomina.' '.$row1['ape_pat'].' '.$row1['ape_mat'].' '.$row1['nom'];
		?>		</th>
      </tr>
      
      <tr>
        <td class="inputcodigo"><span class="thcon">
          <input type="checkbox" name="checkbox" value="checkbox" onClick="todos(this)">
        </span></td>
        <td class="inputcodigo">Tipo:  
          <select name="t1" id="t1" onChange="javascript: document.getElementById('frm1').submit()">
		<option></option>
		<?php
 
		if($_REQUEST['t1']=="P" or ($ffr['operac']  == "P" and (isset($_REQUEST['boton2']) or ($_REQUEST['ttr']==1 and $tm <> "M")))){
			echo '<option value="P" selected>(P) PERCEPCIONES</option>';
		}else{
			echo '<option value="P">(P) PERCEPCIONES</option>';
		}
		if($_REQUEST['t1']=="Q" or ($ffr['operac']  == "Q" and (isset($_REQUEST['boton2']) or ($_REQUEST['ttr']==1 and $tm <> "M" and !isset($_REQUEST['t1']))))){
			echo '<option value="Q" selected>(Q) DEDUCCIONES</option>';
		}else{
			echo '<option value="Q">(Q) DEDUCCIONES</option>';
		}
		?>
        </select>        </td>
        <td colspan="3" class="inputcodigo">No.:
          <select name="t2" id="t2" onChange="javascript: document.getElementById('frm1').submit()">
		  <option></option>
          <?php
 
		  if(isset($_REQUEST['boton2'])){
		  	$r = mysqli_query($con ,"SELECT * FROM dncatper where operac = '".$ffr['operac']."'");
		  }elseif($_REQUEST['ttr']==1 and $tm <> "M"){
		  	$r = mysqli_query($con ,"SELECT * FROM dncatper where operac = '".$_REQUEST['t1']."' order by no_pd");
		  }else{
		  	$r = mysqli_query($con ,"SELECT * FROM dncatper where operac = '".$_REQUEST['t1']."' order by no_pd");
		  }
	  	
		while($reg = mysqli_fetch_array($r)){
			if((isset($_REQUEST['boton2']) or ($_REQUEST['ttr']==1 and $tm <> "M")) and $reg['no_pd'] == $ffr['no_pd'] or $_REQUEST['t2'] == $reg['no_pd']){
				echo '<option value="'.$reg['no_pd'].'" selected>'.$reg['no_pd'].' - ' .$reg['des_perc'].'</option>';
			}else{
				echo '<option value="'.$reg['no_pd'].'">'.$reg['no_pd'].' - ' .$reg['des_perc'].'</option>';
			}
			
		}
	  ?>
        </select></td>
        <td colspan="7" class="inputcodigo">Cantidad: 
          <input name="t3" type="text" id="t3"
		<?php
 
		if(isset($_REQUEST['boton2']) or ($_REQUEST['ttr']==1 and $tm <> "M")){
			echo ' value="'.$ffr['can_nom'].'"';
		}elseif($ent <> "ent"){
		  	echo ' value="'.$_REQUEST['t3'].'"';
		}
		?>
		>    
		<?php
 
		if($_POST['co1']=="A"){
		?>
		Can/Tot:
          <input name="t4" type="text" id="t4"
		<?php
 
		if(isset($_REQUEST['boton2']) or ($_REQUEST['ttr']==1 and $tm <> "M")){
			echo ' value="'.$ffr['can_tot'].'"';
		}elseif($ent <> "ent"){
		  	echo ' value="'.$_REQUEST['t4'].'"';
		}
		?>
		>
		<?php
 }?>
		</td>
      </tr>
      <tr>
        <th><div align="center">Sel</div></th>
        <th><div align="center">Per/Ded</div></th>
        <th><div align="center">N&deg; </div></th>
        <th><div align="center">Descripcion</div></th>
		<th><div align="center">Tipo</div></th>
        <th><div align="center">Cantidad</div></th>
		<th><div align="center">Cantidad/Total</div></th>
		<th><div align="center">Cantidad/Acumulada</div></th>
      </tr>
      <?php

	$no_nomina = $_REQUEST['bot'];
	@$sql = mysqli_query($con ,"SELECT * FROM dnincfij where no_nomina = '$no_nomina' order by operac,no_pd");
	echo '<input name="txt_t1" type="hidden" value="'.$_POST['t1'].'">';
	while($reg = mysqli_fetch_array($sql))
	{
		$jj += 1;
	  	echo "<tr>";
		if(isset($_REQUEST['boton2']) or ($_REQUEST['ttr']==1 and $tm <> "M")){
			$se = 'checked';
		}
		echo '<td><div align="center"><input name="cver'.$jj.'" type="checkbox" value="'. $reg['n_reg'].'"></div></td>';
		if($reg['operac']=="P"){
			echo '<td><div align="center">PERCEPCION</div></td>';
		}else{
			echo '<td><div align="center">DEDUCCION</div></td>';
		}
		echo '<td><div align="center">' . $reg['no_pd'] . '&nbsp</div></td>';
		
		@$sss = mysqli_query($con ,"SELECT * FROM dncatper WHERE operac = '".$reg['operac']."' and no_pd = '".$reg['no_pd']."'");
		$rrr = mysqli_fetch_array($sss);
		
		echo '<td><div align="center">' . $rrr['des_perc'] . '&nbsp</div></td>';
		echo '<td><div align="center">' . $reg['tipo']. '&nbsp</div></td>';
		echo '<td><div align="center">' . number_format($reg['can_nom'],2,".",",") . '&nbsp</div></td>';
		echo '<td><div align="center">' . number_format($reg['can_tot'],2,".",",") . '&nbsp</div></td>';
		echo '<td><div align="center">' . number_format($reg['can_acu'],2,".",",") . '&nbsp</div></td>';
	}
	mysqli_close($con);
	?>
    </table>
  </form>
</div>
</body>
</html>