<?php
 
session_start();
include("DMMYSQLG.php");
include("DSA1000.php");
include("DMMYSQLG.php");
include("DF30000.inc");
require_once("DF80000.php");
require_once("DFMOVCAP.inc");
require_once("DFJQUERY.inc");

?>
<?php

/*if($_SESSION['tipven']=="" || $_SESSION['vendedor']==""){
	echo '<h2>VUELVA A IDENTIFICARSE!!</h2>';
	exit();
}*/

if(!isset($_POST['tip_imp'])){
	$_REQUEST['tip_imp']='H';
}
$dt_parame=mysqli_fetch_array(mysqli_query($con ,"SELECT * FROM dgparame"));
?>
<html>
<link rel="stylesheet" href="css/estilo1.css" type="text/css"/>
<script type="text/javascript" language="JavaScript1.2" src="DSSCRIPT.js"></script>
<script language="javascript">
$(document).ready(function(){
	$('#bot_tip_pag').click(function(){
		loadOnLayer({				
			action:'DYTIPPAG.php',
			idLayer:'divTipPag',			
			width:'auto',
			height:'200px'
		},{
			idRetObj:'tip_pag_pro'		
		});
		
	});
});
</script>
<style type="text/css">
<!--
.style12 {font-family: Arial, Helvetica, sans-serif; font-size: 12px; color: #FFFFFF; font-weight: bold; }
.encPag{
	background-color:#DDEEFF;
	color:#000000;
	font-family:Arial, Helvetica, sans-serif;
	font-size:12px;
}
.detFac{
	background- ;
	color:#000000;
	font-family:Arial, Helvetica, sans-serif;
	font-style:italic;
	font-size:11px;
}

.style16 {text-align:center; background-color: #b8cbe1; color: #000000;}
.style19 {font-family: Arial, Helvetica, sans-serif; font-size: 14px; font-weight: bold; }
#divTipPag {
	position:absolute;
	width:64px;
	height:63px;
	z-index:1;
	left: 74px;
	top: 53px;
}
.botonTipPag{
	background-color:#FFFFCC;
	border-bottom-color:#000000;
	border-bottom-style:solid;
	color:#000000;
	font-family:Arial, Helvetica, sans-serif;
	font-size:12px;
	font-weight:bold;
}
--> 
</style>
<div id="divTipPag"></div>
<body>
<form name="frm1" method="post" action="">
  
  <table border="0" align="center">
    <tr>
      <th colspan="4" nowrap>CORTE DE CAJA </th>
    </tr>
    <tr style="display:none">
      <td colspan="4" nowrap><div align="center" class="style19">
        <input name="r1" type="radio" onClick="openpage('DG32000_PR.php','_self')" value="1"
		<?php
 
		if($_REQUEST['r1']==1){
			echo ' checked';
		}
		?>
		>
        Verificacion&nbsp;&nbsp;&nbsp;
        <input name="r1" type="radio" onClick="openpage('DG32000_PR.php','_self')" value="2"
		<?php
 
		if($_REQUEST['r1']==2){
			echo ' checked';
		}
		?>
		>
        Actualiza&nbsp;&nbsp;&nbsp;
          <input name="r1" type="radio" onClick="openpage('DG32000_PR.php','_self')" value="3" checked
		  <?php
 
		if($_REQUEST['r1']==3){
			echo ' checked';
		}
		?>
		  >
		  <script language="javascript1.2" type="text/javascript">
		  		
		  </script>
      Reimprime</div></td>
    </tr>
    <? $_REQUEST['r1']=3;
	 if(true){?>
	<tr style="display:none">
      <td nowrap><span class="style19">Movimiento:</span></td>
      <td nowrap> 
        <span class="style19">
        <select name="select" tabindex="2">
           <option selected="selected">TODOS</option>
          <?php
 
		    $tipMov=array(1=>"COBRO DE PEDIDOS","COBRO DE FACTURAS","ANTICIPOS","DEVOLUCION DE VENTAS","OTROS");
			for($i=1;$i<=count($tipMov);$i++){
				if($_REQUEST['select']==$i)
					echo '<option value="'.$i.'" selected>'.$tipMov[$i].'</option>';
				else
					echo '<option value="'.$i.'" >'.$tipMov[$i].'</option>';
			}
			?>
        </select>
        </span> </td>
      <td nowrap><span class="style19">
        <input name="bot_tip_pag" type="button" id="bot_tip_pag" value="Tipos De  Pago:" class="botonTipPag">
      </span></td>
      <td nowrap><label>
        <input name="tip_pag_pro" type="text" id="tip_pag_pro" size="10" value="<? echo $_REQUEST['tip_pag_pro'];?>">
      </label></td>
    </tr>
    <? ;}//
//	if($_REQUEST['r1']=='3' || $_REQUEST['r1']=='1'){//SI es Reimpresion pone menu cajero
	?>
	<tr style="display:block">
	  <td nowrap><div align="center" class="style19">
	    <div align="left">Cajero:</div>
	  </div></td>
      <td colspan="3" nowrap><div align="left"><span class="style19">
        <select name="vendedor" id="vendedor">
          <option value="T" selected="selected">--TODOS--</option>
          <?php

		 $tipVen=$_SESSION['tipven'];
		@$resultado=mysqli_query($con ,"select * from dgcatven  order by nom_ven");
/*		if(!isset($_POST['vendedor'])){
			$selVen=$_SESSION['vendedor'];
			/*$dt_catven=mysqli_fetch_array($resultado);
			$selVen=$dt_catven['cod_ven'];
			if(mysqli_num_rows($resultado)>0)
				mysqli_data_seek($resultado,0);* /
		}
		else{
			$selVen=$_POST['vendedor'];
		}	*/	
		while($registro=mysqli_fetch_array($resultado)){
			//if(strstr($registro['aceso'],$tipVen)){
/*				if($selVen==$registro['cod_ven'])
					echo '<option value="' . $registro['cod_ven'] . '" selected>' . $registro['cod_ven'].' '.$registro['nom_ven'] . ' ' . $registro['ap_pat_ven'] . ' ' . $registro['ap_mat_ven'] . '</option>';
				else*/
					echo '<option value="' . $registro['cod_ven'] . '">' . $registro['cod_ven'].' '. $registro['nom_ven'] . ' ' . $registro['ap_pat_ven'] . ' ' . $registro['ap_mat_ven'] . '</option>';
			//}
		}			
		?>
        </select>
      </span></div></td>
    </tr>
	<? //}//Termina Si es Reimpresion Imprime Menu Cajeros?>
	<tr>
      <td colspan="4" nowrap>
    
	    <div align="center" class="style19">
       <?php

	   if($_REQUEST['r1']=='2' && $_SESSION['mod_sis']!='LAB'){
			echo 'Cierra  Dia: <input type="checkbox" value="1" name="cie_dia" id="cie_dia">&nbsp;&nbsp;&nbsp;';
	   }
	   ?>
	   <? if($_REQUEST['r1']=='3'){?>
	   Del
          <input name="fecini" type="text" class="style16" id="fecini" onBlur="valFecha(this)"
			  <?php
 
			  if(isset($_POST['t1']) && $_POST['fecini']!=""){
			  	echo 'value="'.$_POST['fecini'].'"'; 
			  }elseif($_POST['fecini']==''){
			  	echo 'value="'.$_POST['t1'].'"'; 			  
			  }else{
			  	echo 'value="'.chfecha($_SESSION['fecven'],'Y-m-d','d/m/Y').'"'; 
			  }
			  ?>
			  >
			  
          <input name="boti" id="boti" value=" ... " type="image" src="logos/cal4.jpg"/>
          <script type="text/javascript">Calendar.setup(
    					{
      						inputField  : "fecini",        // ID of the input field
      						ifFormat    : "%d/%m/%Y",    // the date format
      						button      : "boti"      // ID of the button
    					}
  					);
				</script>			  
	   al 
          <input name="t1" type="text" class="style16" id="t1" onBlur="valFecha(this)"
			  <?php
 
			  if(isset($_POST['t1'])){
			  	echo 'value="'.$_POST['t1'].'"'; 
			  }else{
			  	echo 'value="'.chfecha($_SESSION['fecven'],'Y-m-d','d/m/Y').'"'; 
			  }
			  ?>
			  >

	   <? ;}else{?>
	   Fecha de corte:
          <input name="t1" type="text" class="style16" id="t1" onBlur="valFecha(this)"
			  <?php
 
			  if(isset($_POST['t1'])){
			  	echo 'value="'.$_POST['t1'].'"'; 
			  }else{
			  	echo 'value="'.chfecha($_SESSION['fecven'],'Y-m-d','d/m/Y').'"'; 
			  }
			  ?>
			  >
       <? ;}?>
          <input name="reset2" id="bot1" value=" ... " type="image" src="logos/cal4.jpg"/>
          <script type="text/javascript">
				  	Calendar.setup(
    					{
      						inputField  : "t1",        // ID of the input field
      						ifFormat    : "%d/%m/%Y",    // the date format
      						button      : "bot1"      // ID of the button
    					}
  					);
				</script>
        </div></td>
    </tr>
    <tr>
      <td colspan="4" nowrap>
        <div align="center" class="style19">
          <input type="submit" name="Submit" value="Procesar" onClick="openpage('DG32000_PR.php?ct=1','_self')">
        </div>      </td>
    </tr>
  </table>
	<? ($_SESSION['mod_sis']!="LAB")?($colspan='8'):($colspan='7');//Colspan Dinamico?>
  <table border="0" align="center">
  <tr>
    <th colspan="<? echo $colspan;?>" nowrap>CORTE DE CAJA </th>
  </tr>
  <tr>
    <th colspan="<? echo $colspan;?>" nowrap><input name="imprimir" type="submit" id="imprimir" onClick="<? 
		  if($_REQUEST['tip_imp']=='H')
			echo "openpage('DG32000_PRIM.php','_self')";
		  else
		  	echo "openpage('DG32000_RE.php','_self')";
		  ?>" value="Imprimir" <? if($_REQUEST['r1']==2) echo 'disabled="disabled"';?>>
      
	  <? //if($_REQUEST['r1']=='3' || $_REQUEST['r1']=='1'){//Si es Reimpresion imprime Menu Cortes?>
	  Corte:
      <select name="select2" tabindex="2">
<!--        <option>TODOS</option>-->
		<? if($_REQUEST['r1']=='1'){?>
        <option value="SC">SIN CORTE</option>		
        <?php

		}
		$fec = $_REQUEST['t1'];
		$tipVen=$_SESSION['tipven'];
		include("DF20000.php");
		@$r=mysqli_query($con ,"select * from dgger_cajerosj where corte <> '0'  AND tip_caj='$tipVen'  ");
		while($ew=mysqli_fetch_array($r)){
			if($_REQUEST['select2'] == $ew['corte']){
				echo '<option selected>'.$ew['corte']. '</option>';
			}else{
				echo '<option>'.$ew['corte']. '</option>';
			}
			
		}			
		?>
      </select>
	  <? //}//Termina si es Reimpresion imprime Menu cortes ?>
      Impresion:
      <label>
      <select name="tip_imp" id="tip_imp" onChange="openpage('DG32000_PR.php','_self')">
        <option value="H" <?php
 if (!(strcmp("H", "$_REQUEST['tip_imp']"))) {echo "selected=\"selected\"";} ?>>HOJA</option>
        <option value="T" <?php
 if (!(strcmp("T", "$_REQUEST['tip_imp']"))) {echo "selected=\"selected\"";} ?>>TICKET</option>
      </select>
      </label></th>
  </tr>
  <tr>
    <td height="16" nowrap style="#0066CC"><div align="center" class="style12">Folio Recibo </div></td>
    <? if($_SESSION['mod_sis']!="LAB"){//Si no es laboratorio?>
	<td nowrap style="#0066CC"><div align="center" class="style12">Movimiento</div></td>
    <? }//Termina si no es laboratorio?>
	<td nowrap style="#0066CC"><div align="center" class="style12">Cliente / Persona</div></td>
    <td nowrap style="#0066CC"><div align="center" class="style12">Concepto</div></td>
    <td nowrap style="#0066CC"><div align="center" class="style12">Folio</div></td>
    <td nowrap style="#0066CC"><div align="center" class="style12">Total</div></td>
    <td nowrap style="#0066CC"><div align="center" class="style12">No. Fac. </div></td>
    <td nowrap style="#0066CC"><div align="center" class="style12">Cve. Cajero </div></td>
  </tr>
  <?php
 
  if(isset($_POST['Submit']))
  	include("DG32000_PA.php");//busca 
	echo mysqli_error($con);
  $tipMov=array(1=>'COBRO DE PEDIDOS','COBRO DE FACTURAS','ANTICIPOS','DEVOLUCION DE VENTAS','OTROS');
  while($reg = mysqli_fetch_array($sql)){
 	if($dt_parame['cod_pubgral']==$dt_pemema['cod_cli']){
		$subTotPubGen +=$dt_pemema['sub_ven'];
		$ivaTotPubGen +=$dt_pemema['iva_ven'];
		$totPubGen    +=$dt_pemema['tot_ven'];
	}
	if (trim($_REQUEST['tip_pag_pro']) == "")//si todos los pagos
		$sq_ger_cajerosd = mysqli_query($con ,"select * from dgger_cajerosd where n_rec = '".$reg['n_rec']."'");
	else//en caso contrario
		$sq_ger_cajerosd = mysqli_query($con ,"select * from dgger_cajerosd where n_rec = '".$reg['n_rec']."' and tip_pag IN($_REQUEST['tip_pag_pro'])");
	if(mysqli_num_rows($sq_ger_cajerosd)>0){
		echo '<tr>';
		echo '<td class="encPag"><div align="right">'.$reg['n_rec'].'</div></td>';
		if($_SESSION['mod_sis']!="LAB")
			echo '<td class="encPag"><div align="left">'.$tipMov[$reg['tip_mov']].'</div></td>';
		echo '<td class="encPag"><div align="left">'.$reg['nomCliAlt'].'</div></td>';	
		echo '<td class="encPag"><div align="left">'.$reg['cveEmp'].'-'.$reg['nomEmp'].'</div></td>';
		if ($reg['fol_unp']!=0){		
		echo '<td  class="encPag"><div align="right">';
		$sq_fm=mysqli_query($con ,"select con_ven from dgger_cajerosj left join dgpemema on (dgpemema.fol_ven=dgger_cajerosj.pedido) where dgger_cajerosj.fol_unp='".$reg['fol_unp']."' and dgger_cajerosj.fol_unp!=0 order by dgpemema.con_ven");	
		while ($rfol=mysqli_fetch_array($sq_fm)){
		echo $rfol['con_ven'];
		echo ' - ';
		}
		echo '</div></td>';
		}else{
		echo '<td  class="encPag"><div align="right">'.$reg['con_ven'].'</div></td>';
		}
		if ($reg['fol_unp']!=0){
		$sql_sumc=mysqli_fetch_array(mysqli_query($con ,"select sum(dgpemema.tot_ven) as totvta from dgger_cajerosj left join dgpemema on (dgpemema.fol_ven=dgger_cajerosj.pedido) where dgger_cajerosj.fol_unp='".$reg['fol_unp']."' and dgger_cajerosj.fol_unp!=0 group by dgger_cajerosj.fol_unp"));
		echo '<td class="encPag"><div align="right">'.'$' . number_format($sql_sumc['totvta'], 2, '.', ',').'</div></td>';
		}else{
		$sql_sumc=mysqli_fetch_array(mysqli_query($con ,"select dgpemema.tot_ven as totvta from dgger_cajerosj left join dgpemema on (dgpemema.fol_ven=dgger_cajerosj.pedido) where dgpemema.con_ven='".$reg['con_ven']."' "));
		echo '<td class="encPag"><div align="right">'.'$' . number_format($sql_sumc['totvta'], 2, '.', ',').'</div></td>';
		
//		echo '<td class="encPag"><div align="right">'.'$' . number_format($reg['impParCaj'], 2, '.', ',').'</div></td>';
		}
		if($reg['numFac']=='0' || $reg['numFac']==''){$reg['tipFac']="";$reg['numFac']="";}
			echo '<td class="encPag"><div align="left">'.$reg['tipFac'].$reg['numFac'].'</div></td>';
		echo '<td class="encPag"><div align="left">'.$reg['vendedor'].'</div></td>';
		echo '</tr>';
		//------>Si Es Pago de Factura Imprimirlas---------->
		if($reg['tip_mov']=='2'){
			echo "<tr><td  colspan=\"$colspan\">";
			echo "<table border=\"0\" align=\"center\">";
			$sq_ger_cajeroso=mysqli_query($con ,"SELECT * FROM dgger_cajeroso WHERE rec_caj='".$reg['n_rec']."'");
			$kt=0;
			while($dt_ger_cajeroso=mysqli_fetch_array($sq_ger_cajeroso)){
				if($kt%4==0 && $kt!=0){
					$kt=0;
					echo "</tr>";
				}elseif($kt==0){
					echo "<tr>";
				}
				echo "<td class=\"detFac\">$dt_ger_cajeroso['num_doc']</td>";
				echo "<td class=\"detFac\">".number_format($dt_ger_cajeroso['import'],2,'.',',')."</td>";
				echo "<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>";
				$kt++;								
			}
			for($nks=$kt;$nks<4;$nks++){
				echo "<td>&nbsp;</td>";
				if(($nks+1)==4) echo "</tr>";
			}
			
			echo "</table>";
			echo "</td></tr>";
		}
		//-------------------------------------------------->
		while ($rrr = mysqli_fetch_array($sq_ger_cajerosd)){
			echo '<tr>';
			$bus = mysqli_query($con ,"select * from dgtippag where tip_pag = '".$rrr['tip_pag']."'");
			$sa = mysqli_fetch_array($bus);
			echo '<td class="sin_bo" >&nbsp;</td>';
			if ($sa['tip_mv_pag'] == "N"){
				echo '<td class="sin_bo" colspan="3">'.$sa['desc_pag'].'</td>';
			}else{
				echo '<td class="sin_bo" colspan="3">'.$sa['desc_pag']. '&nbsp;&nbsp;&nbsp;Ref: ' . $rrr['ref'] . '&nbsp;&nbsp;&nbsp;Aut: ' . $rrr['aut'] . '</td>';
			}
			echo '<td class="sin_bo"><div align="center">'.'$' . number_format($rrr['importe'], 2, '.', ',').'</div></td>';
			echo '<td class="sin_bo">&nbsp;</td>';
			echo '</tr>';
			 
			 $pag_ban = $rrr['tip_pag'];
			 if ($sa['pag_bancos'] =='0'){//Depocito en banco
				 $DepBan += abs($rrr['importe']);
				 
			}elseif ($sa['pag_bancos'] =='1'){//Directo en banco
				$DirBan += abs($rrr['importe']);  
			}      
				 
			$tt = $rrr['tip_pag'];
			if ($reg['tip_afe'] == 'I'){//si ingreso		
				${'I'.$rrr['tip_pag']} += abs($rrr['importe']);
				
			}elseif ($reg['tip_afe'] == 'E'){//si egreso	
				${'E'.$rrr['tip_pag']} += abs($rrr['importe']);
				
			}
		}
	}
}


  ?>
</table>

<table  align="center">
      <tr>
        <th colspan="5">Resumen de Caja </th>
      </tr>
      <tr>
        <td class="inputcodigo"><div align="center">Movimientos</div></td>
        <td class="inputcodigo" colspan="2"><div align="center">Total</div></td>
      </tr>
      <?php
 
$fec = $_REQUEST['t1'];
include("DF20000.php");
  $tipos = array ("INGRESOS", "EGRESOS"); 
  $cdr = count($tipos);
  $tt = count($entrada);
  for ($u=0; $u<$cdr;$u++){
  		if($u == 0)
			$tp = "I";
		else
			$tp = "E";
		echo '<tr><td colspan="5" class="inputcodigo">'.$tipos[$u].'</td></tr>';
		$busc = mysqli_query($con ,"select * from dgtippag");
	  	while($say = mysqli_fetch_array($busc)){
			if(isset(${$tp.$say['tip_pag']}) && ${$tp.$say['tip_pag']}!=0){
				echo '<tr>';
				echo '<td class="sin_bo">'.$say['desc_pag'].'</td>';
				echo '<td class="sin_bo" colspan="2">'.'$' . number_format(${$tp.$say['tip_pag']}, 2, '.', ',').'</td>';
				echo '</tr>';
			}
			if($u == 0)
				$sum += abs(${$tp.$say['tip_pag']});
			else
				$sum1 += abs(${$tp.$say['tip_pag']});
		}
		echo '<tr>';
		echo '<td class="trcoti">Total de '.$tipos[$u].':</td>';	
		if($u == 0)
			echo '<td class="trcoti" colspan="2">'.'$' . number_format($sum, 2, '.', ',').'</td>';
		else
			echo '<td class="trcoti" colspan="2">'.'$' . number_format($sum1, 2, '.', ',').'</td>';
		echo '</tr>';
		$t = $sum - $sum1;
	}
echo '<tr>';
		echo '<td class="trtotal">Total</td>';
		echo '<td class="trtotal" colspan="2">'.'$' . number_format($t, 2, '.', ',').'</td>';
echo '</tr>';

echo '<tr><td colspan="5" class="estilotabla"><div align="center">TOTAL PUBLICO EN GENERAL</div></td></tr>';
echo '<tr>';
		echo '<td class="trtotal">Sub.Tot: '.number_format($subTotPubGen,2,'.',',').'</td>';
		echo '<td class="trtotal">IVA Tot:'.number_format($ivaTotPubGen,2,'.',',').'</td>';
		echo '<td class="trtotal">Tot:'.number_format($totPubGen,2,'.',',').'</td>';
echo '</tr>';
?>
  </table>
<p>&nbsp;</p>
<p><br>
</p>
</form>
</body>
</html>