<?php
 
session_start();
include("DMMYSQLG.php");
include("DSA1000.php");
include("DMMYSQLG.php");
include('DF30000.inc');
?>
<?php
 
//busquedas
	if(isset($_POST['botbuscar']) || isset($_POST['ra_imp'])){
		$m=substr($_SESSION['m_a'],0,2);
		$a=substr($_SESSION['m_a'],2,4);
		$fecproc=$arbusproc["axo_pro"].'-'.$arbusproc["mes_pro"].'-01';
		$busqcal="select * from dncageno where cve_nomi = '".$_POST['setipnom']."' and axo_mes='$fecproc'";
		$busq="select * from dndatnom where tip_nom ='".$_POST['setipnom']."'";
	}
	else{
		$busq=" ";
	}
	$sqbusq=mysqli_query($con ,$busq);
	$sqbusqcal=mysqli_query($con ,$busqcal);
	while(@$arbusqw=mysqli_fetch_array($sqbusqcal)) if($arbusqw['act_nom']=="NO") break;
	
	$fec1 = $arbusqw['fec_ini'];
	include('DF20000.php');
	$fecha_inicial = $f_f;
	$fec1 = $arbusqw['fec_fin'];
	include('DF20000.php');
	$fecha_final = $f_f;
	if(!isset($_POST['ra_imp'])) $_REQUEST['ra_imp']='emp';
?>
<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 = 'DN5300A_AG.php';
include("DYAYUDA.php");
?>
<div align="center">
<form name="form1" id="form1" method="post" action="">
  <table  align="center">
    <tr>
      <th colspan="2">REPORTE PER./DED. ACUMULADA </th>
    </tr>
    <tr>
      <th colspan="2">Per./Ded. , Nomina </th>
      </tr>
	<tr>
	  <td class="inputcodigo">
	    <div align="right">
	      <select name="seperded" id="seperded" onChange="javascript: document.getElementById('form1').submit()" tabindex="1" >
            <option value="P" <?php
 
			if($_POST['seperded']=="P") echo 'selected';?>>PERCEPCION</option>
            <option value="Q" <?php
 
			if($_POST['seperded']=="Q") echo 'selected';?>>DEDUCCION</option>
          </select>
	      </div></td><td class="inputcodigo"><div align="right">
	        <select name="secatpd" id="secatpd" tabindex="2"  
		  <?php
 
		  if(isset($_POST['bomodificar'])){
		  	if($_POST['bot2']=="")
		  		echo 'disabled="disabled"';
			  }
		  ?>>
	          <?php
 
					if(isset($_POST['seperded']))
						$dncap="select * from dncatper where operac = '".$_REQUEST['seperded']."' order by no_pd";
					else
						$dncap="select * from dncatper where operac = 'P' order by no_pd";
					$mdncap=mysqli_query($con ,$dncap);
					while($adncap=mysqli_fetch_array($mdncap)){
					if(isset($_POST['bomodificar']) && $modusu['no_pd']=="$adncap['no_pd']") 
						echo '<option value = "'.$adncap['no_pd'].'" selected>'.$adncap["no_pd"].'|'.$adncap["des_perc"].'</option>';
					elseif($_POST['secatpd']=="$adncap['no_pd']")
						echo '<option value = "'.$adncap['no_pd'].'" selected>'.$adncap["no_pd"].'|'.$adncap["des_perc"].'</option>';
					else
						echo '<option value = "'.$adncap['no_pd'].'">'.$adncap["no_pd"].'|'.$adncap["des_perc"].'</option>';
					}
					
			?>
            </select>
	        </div></td>
	</tr>
	    <tr class="inputcodigo">
	      <td colspan="2"><div align="center">
	        <select name="setipnom" id="setipnom">
	          <!--  <option value="ALL">TODAS</option> -->
              <?php
  
		  $stipnom="select * from dntipnom";
		  $sqtipnom=mysqli_query($con ,$stipnom);
		  while($artipnom=mysqli_fetch_array($sqtipnom)){
		  	if("$_POST['setipnom']"=="$artipnom['cve_nomi']") echo '<option value="'.$artipnom['cve_nomi'].'" selected>'.$artipnom['des_nomi'].'</option>';
		  	else echo '<option value="'.$artipnom['cve_nomi'].'">'.$artipnom['des_nomi'].'</option>';
		  }
		  ?>
            </select>
	        &nbsp;</div></td>
      </tr>
	    <tr class="inputcodigo">
	      <td colspan="2"><div align="center">
            <input name="botbuscar" type="submit" id="botbuscar" value="Aplica " />
            </div></td>
		<tr>
		  <th colspan="2">Reporte</th>
	  </tr>
		<tr>
          <th> 
            <input name="ra_imp" type="radio" value="emp" onClick="javascript: document.getElementById('form1').submit()" 
	  <?php
 
			if($_REQUEST['ra_imp']=="emp")
				echo 'checked';
		?> >
            Por Empleado </th>
	      <th> 
            <input name="ra_imp" type="radio" value="dep" onClick="javascript: document.getElementById('form1').submit()" 
	  <?php
 
			if($_REQUEST['ra_imp']=="dep")
				echo 'checked';
		?> >
	        Por Departamento </th>
      </tr>
      </tr>
	    <th colspan="2"><div align="center">Mes-A&ntilde;o de  Nomina</div></th>
      </tr>
	    <tr>
	      <td colspan="2" class="typeagre"><div align="center">
		  <?php
 
		  	echo $m.'-'.$a;
		  ?>
		  </div></td>
      </tr>
      <tr>
        <td colspan="2" class="inputcodigo">
		    <div align="center">
		      <p>
			  <input name="tenonom" type="hidden" id="tenonom"  readonly value="<?php
 echo $arbusqw['no_nomi'];?>">
			  <input name="tefecini" type="hidden" class="thcons" id="tefecini" size="30"  readonly
			  <?php
 
			  if(isset($_POST['tefecini']) || isset($_POST['ra_imp'])) echo 'value="'.$fecha_inicial.'"'; 
			 ?>
			  >
			  <input name="tefecfin" type="hidden" class="thcons" id="tefecfin" size="30" readonly
				<?php
 
			  if(isset($_POST['tefecfin']) || isset($_POST['ra_imp'])) echo 'value="'.$fecha_final.'"'; 
			  ?>
				>
		      </p>
    </div></td></table>
</form>
<form name="form2" method="post" action="">
</form>
</div>
<div align="center">
  <form name="frm1" id="frm1" method="post" action="" >
   <input type="hidden" name="setipnom" id="setipnom" value="<?php
 echo $_POST['setipnom'];?>">
   <input name="tenonom2" type="hidden" id="tenonom2"   value="<?php
 echo $arbusqw['no_nomi'];?>">
    <input type="hidden" name="seperded" id="seperded" value="<?php
 echo $_POST['seperded'];?>">
   <input  type="hidden" name="secatpd" id="secatpd"   value="<?php
 echo  $_POST['secatpd'];?>">
    <input  type="hidden" name="ra_imp" id="ra_imp"   value="<?php
 echo  $_POST['ra_imp'];?>">
    <input name="tefecfin" type="hidden" class="thcons" id="tefecfin" size="30"
	<?php
 
			  if(isset($_POST['tefecfin']) || isset($_POST['ra_imp'])) echo 'value="'.$fecha_final.'"'; 
	 ?>	>
	 <input name="tefecini" type="hidden" class="thcons" id="tefecini" size="30"
	<?php
 
			  if(isset($_POST['tefecini']) || isset($_POST['ra_imp'])) echo 'value="'.$fecha_inicial.'"'; 
	 ?>>
   <table border='1'>
      <tr>
        <th colspan="4">
		  <div align="left">
            <input name="boimp" type="button" id="boimp" onClick="openpage('DN53000_IM.php','_self')" value="Imprimir"/>
		  </div>		</th>
      </tr>
      <tr>
        <th colspan="4">Concepto -Per./ Ded. Acumulada </th>
      </tr>
      <tr>
			<td class="tabagre"><div align="center">NO. NOMINA</div></td>
			<td class="tabagre"><div align="center">NOMBRE</div></td>
			<!--<td class="tabagre"><div align="center">R.F.C.</div></td>
			<td class="tabagre"><div align="center">I.M.S.S.</div></td>
			<td class="tabagre"><div align="center">SUELDO DIA</div></td>
			<td class="tabagre"><div align="center">DEPARTAMENTO</div></td>
			<td class="tabagre"><div align="center">PUESTO</div></td>-->
			<td class="tabagre"><div align="center">CAN. MOV.</div></td>
			<td class="tabagre"><div align="center">IMP. MOV.</div></td>
	  </tr>
	  <tr>      </tr>
<?php

if(isset($_POST['botbuscar']) || isset($_POST['ra_imp'])){
	include("DN53000_CL.php");
	include('DF10000.php');
	$busproc=mysqli_query($con ,"select * from dnpargen");
	$arbusproc=mysqli_fetch_array($busproc);
	$nomusu = new clase('dnnommen',$a,$m,$_POST['setipnom'],-1,$_POST['seperded'],$_POST['secatpd'],$_SESSION['num_usu']);
	$norec=0;
	if($_REQUEST['ra_imp']=='emp')
		$result=$nomusu->listaElemEmp();
	else
		$result=$nomusu->listaElem();
	$cchck=$nomusu->conReg();
	for($dfi=0; $dfi<$cchck; $dfi++) 
	{
		//Busquedas de trabajador
		$chboxes=mysqli_fetch_array($result);
		$nomusu->modEmp("$chboxes['no_nom']");
		$noEmp = $nomusu->getEmp();
		$sqbusqx=mysqli_query($con ,"select * from dntrab_a where no_trab = '$noEmp'");
		$arbusq=mysqli_fetch_array($sqbusqx);
		$sqbusqxdat=mysqli_query($con ,"select * from dndatnom where no_nom = '$noEmp'");
		$sqbusqxx=mysqli_query($con ,"select * from dntrab_b where no_nom = '$noEmp'");
		$detnom=$nomusu->listaBusq();
		$arbusqxdat=mysqli_fetch_array($sqbusqxdat);
		$arbusqx=mysqli_fetch_array($sqbusqxx);
		$buspue=mysqli_fetch_array(mysqli_query($con ,"select * from dncatpue where no_puesto = '".$arbusqxdat['puesto']."'"));
		$busdep=mysqli_fetch_array(mysqli_query($con ,"select * from dncatdep where no_depto = '".$arbusqxdat['depto']."'"));
		//if($dfi==0) $depto= $chboxes['depto'];
		if($_REQUEST['ra_imp']=='dep'){
			if($depto!=$chboxes['depto']){
				$ct_dncatdep=mysqli_fetch_array(mysqli_query($con ,"select * from dncatdep where no_depto = '".$chboxes['depto']."'"));
		if($dfi>0) impTot($totdep);
		$totdep=NULL;
		echo '<tr><td colspan="4" class="inputcodigo"><div align="center">'.$ct_dncatdep['no_depto'].'-'.$ct_dncatdep['des_depto'].'</div></td></tr>';
				$depto= $chboxes['depto'];
			}
		}
		$perded=NULL;
		while($adetnom=mysqli_fetch_array($detnom)){//Inicia separa detalles de trabajador per/ded
			llenaDet($adetnom,$togen);
			llenaDet($adetnom,$perded);
			if($_REQUEST['ra_imp']=='dep'){
				llenaDet($adetnom,$totdep);
			}
		}//Termina separa detalles de trabajador per/ded
		//Inicia impresion de detalles de trabajador
		echo '<tr>';
		echo '<td><div align="center">'.$arbusq["no_nom"].'&nbsp;</div></td>';
		if($arbusqxdat['status']=='A') echo '<td><div align="center">'.$arbusq["nom"].' '.$arbusq["ape_pat"].' '.$arbusq["ape_mat"].'&nbsp;</div></td>';
		else echo '<td><div align="center">'.$arbusq["nom"].' '.$arbusq["ape_pat"].' '.$arbusq["ape_mat"].'(Inactivo) &nbsp;</div></td>';
		echo '<td ><div align="center">'.number_format($perded[2],2,'.',',').'&nbsp;</div></td>';
		echo '<td ><div align="center">'.number_format($perded[3],2,'.',',').'&nbsp;</div></td>';
		echo'</tr>';
		//Termina impresion de detalles de trabajador
		/*echo '<tr><td colspan="7" class="inputcodigo"><div align="center">&nbsp;</div></td></tr>';*/
	} 
	/*Se aņade pagina para imprimir resumen de detalles con valores totales y neto*/
	if($_REQUEST['ra_imp']=='dep'){
		if($dfi>0) impTot($totdep);
		$totdep=NULL;
	}
	echo '<tr><th  colspan="4" ><div align="center">'.'Resumen'.'&nbsp;</div></th></tr>';
	impTot($togen);
}

mysqli_close($con);

function llenaDet($adetnom,&$perded){
	$dncapxx=mysqli_fetch_array(mysqli_query($con ,"select * from dncatper where no_pd = '".$adetnom['no_pd']."'  and operac='".$adetnom['operac']."' and cve_mae = '".$adetnom['cve_mae']."' order by operac desc"));
	$perded[0]=$adetnom["no_pd"];
	$perded[1]=$dncapxx["des_perc"];
	$perded[2]+=$adetnom["can_mov"];
	$perded[3]+=$adetnom["imp_mov"];
}

function impTot($togen){
	echo '<tr>';
	echo '<td colspan="2"><div align="center"> TOTAL : &nbsp;</div></td>';
	//echo '</tr>';
	echo '<td colspan="1" class="inputcodigo"><div align="center">'.number_format($togen[2],2,'.',',').'&nbsp;</div></td>';
	echo '<td colspan="1" class="inputcodigo"><div align="center">'.number_format($togen[3],2,'.',',').'&nbsp;</div></td></tr>';
}
?>
    </table>
  </form>
</div>
</body>
</html>
