<?php
 
session_start();
include("DMMYSQLG.php");
include("DSA1000.php");
include("DMMYSQLG.php");
include('DF30000.inc');
include('DF80000.php');
?>
<?php

$sq_nomina=mysqli_query($con ,"SELECT * FROM dnnomina ");
?>
<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 = 'DND00A_PR.php';
include("DYAYUDA.php");
?>
<div align="center">
<form name="frm1" id="frm1" method="post" action="DND000_PR.php">
<br><br>
<br><br>
  <table  align="center">
    <tr>
      <th>REGENERA ACUMULADOS </th>
    </tr>
    <tr>
      <th> Seleccione A&ntilde;o       </th>
      </tr>
	
      <tr>
        <td class="inputcodigo"><div align="center">
          <select name="se_axo" id="se_axo">
            <?php
 
		while($dt_nomina=mysqli_fetch_array($sq_nomina)){
				echo ' <option value="'.$dt_nomina['axo_pro'].'" >'.$dt_nomina['axo_pro'].'</option>';
		}
		?>
          </select>
        </div></td>
      </tr>
      <tr>
        <td class="inputcodigo">
	      <div align="center">
		    <input name="bo_rege" type="submit" id="bo_rege" value="Regenerar">
			<?php
 
	  	if(isset($_POST['bo_rege'])){
			mysqli_query($con ,"delete from dnnommen where axo_pro = '".$_POST['se_axo']."'");
			mysqli_query($con ,"delete from dnnomanu where axo_pro='".$_POST['se_axo']."'");
			echo '<tr>';
			echo '<td class="typeagre">';
			$sq_nomina=mysqli_query($con ,"select * from dnnomina where axo_pro = '".$_POST['se_axo']."'");
			while($dt_nomina=mysqli_fetch_array($sq_nomina)){
				// Acumula al Mensual	
				$sq_nommen=mysqli_query($con ,"select * from dnnommen where axo_pro='".$dt_nomina['axo_pro']."' and mes_pro='".$dt_nomina['mes_pro']."' and no_nomina='".$dt_nomina['no_nomina']."' and operac='".$dt_nomina['operac']."' and no_pd='".$dt_nomina['no_pd']."'");
				@$dt_nommen=mysqli_fetch_array($sq_nommen);
				$nre=mysqli_num_rows($sq_nommen);
				if($nre==1){
					$sql = "update dnnommen set can_mov = can_mov + $dt_nomina['can_mov'], imp_mov = imp_mov + $dt_nomina['imp_mov'],imp_gra_isp = imp_gra_isp + $dt_nomina['imp_gra_isp'], imp_exe_isp = imp_exe_isp + $dt_nomina['imp_exe_isp'], imp_gra_ims = imp_gra_ims + $dt_nomina['imp_gra_ims'], imp_exe_ims = imp_exe_ims + '".$dt_nomina['imp_exe_ims']."', fec_acc ='" .date('Y-m-d'). "',hor_acc='".date('H:i:s')."',usuario='".$_SESSION['num_usu']."' where no_reg = '".$dt_nommen['no_reg']."'";
					$sq = mysqli_query($con ,$sql);
				}else{
					$sql = "insert into dnnommen (no_nomina, operac, no_pd, can_mov, imp_mov, cve_mae, imp_gra_isp, imp_exe_isp, imp_gra_ims, imp_exe_ims, axo_pro, mes_pro, fec_acc, hor_acc, usuario) values('".$dt_nomina['no_nomina']."', '".$dt_nomina['operac']."', '".$dt_nomina['no_pd']."', '".$dt_nomina['can_mov']."', '".$dt_nomina['imp_mov']."', '".$dt_nomina['cve_mae']."', '".$dt_nomina['imp_gra_isp']."', '".$dt_nomina['imp_exe_isp']."', '".$dt_nomina['imp_gra_ims']."', '".$dt_nomina['imp_exe_ims']."','".$dt_nomina['axo_pro']."','".$dt_nomina['mes_pro']."','" .date('Y-m-d'). "','".date('H:i:s')."','".$_SESSION['num_usu']."')";
					$sq = mysqli_query($con ,$sql);
				}
				// Acumula al Anual	
				$sq_nomanu=mysqli_query($con ,"select * from dnnomanu where axo_pro='".$dt_nomina['axo_pro']."' and no_nomina='".$dt_nomina['no_nomina']."' and operac='".$dt_nomina['operac']."' and no_pd='".$dt_nomina['no_pd']."'");
				@$dt_nomanu=mysqli_fetch_array($sq_nomanu);
				$nre=mysqli_num_rows($sq_nomanu);
				if($nre==1){
//					echo 'Per : '.$dt_nomina['no_nomi'].$dt_nomanu['operac'].$dt_nomanu['no_pd'].' Can :'.$dt_nomanu['can_mov'].' '.$dt_nomina['can_mov'].' canmov :'.$can_mov.'<br>';
					$sql = "update dnnomanu set can_mov = can_mov + $dt_nomina['can_mov'], imp_mov = imp_mov + '".$dt_nomina['imp_mov']."',imp_gra_isp = imp_gra_isp + '".$dt_nomina['imp_gra_isp']."', imp_exe_isp = imp_exe_isp + '".$dt_nomina['imp_exe_isp']."', imp_gra_ims = imp_gra_ims + '".$dt_nomina['imp_gra_ims']."', imp_exe_ims = imp_exe_ims + '".$dt_nomina['imp_exe_ims']."', fec_acc ='" .date('Y-m-d'). "',hor_acc='".date('H:i:s')."',usuario='".$_SESSION['num_usu']."' where no_reg = '".$dt_nomanu['no_reg']."'";
					$sq = mysqli_query($con ,$sql);
				}else{
					$sql = "insert into dnnomanu (no_nomina, operac, no_pd, can_mov, imp_mov, cve_mae, imp_gra_isp, imp_exe_isp, imp_gra_ims, imp_exe_ims, axo_pro, fec_acc, hor_acc, usuario) values('".$dt_nomina['no_nomina']."', '".$dt_nomina['operac']."', '".$dt_nomina['no_pd']."', '".$dt_nomina['can_mov']."', '".$dt_nomina['imp_mov']."', '".$dt_nomina['cve_mae']."', '".$dt_nomina['imp_gra_isp']."', '".$dt_nomina['imp_exe_isp']."', '".$dt_nomina['imp_gra_ims']."', '".$dt_nomina['imp_exe_ims']."','".$dt_nomina['axo_pro']."','" .date('Y-m-d'). "','".date('H:i:s')."','".$_SESSION['num_usu']."')";
					$sq = mysqli_query($con ,$sql);
				}
			}
			echo '**** REGENERACION DE ACUMULADOS EXITOSA *******';
			echo '</td>';
			echo '</tr>';
		}
	  ?>
      </div></td></tr>
    </table>
</form>
</div>
</body>
</html>
