<?php
 
session_start();
include("DMMYSQLG.php");
include("DSA1000.php");
include("DMMYSQLG.php");
include("DF30000.inc");
include('DF80000.php');
?>
<?php
 
$tipmov='P';
$fecini=chfecha($_POST['fecini'],'d/m/Y','Y-m-d');
$fecfin=chfecha($_POST['fecfin'],'d/m/Y','Y-m-d');

if(isset($_POST['bo_bus'])){//Inicia Si buscar
	if($_POST['teser']=="")
		$st_bus="select * from dvcobdoc where tip_mto='$tipmov' and tot_cob<>0 and fec_cob between '$fecini' and '$fecfin' order by fec_cob ";
	else
		$st_bus="select * from dvcobdoc where tip_mto='$tipmov' and num_doc like '$_POST['teser']%'and tot_cob<>0 and fec_cob between '$fecini' and '$fecfin' order by fec_cob ";
	$sq_redocl=mysqli_query($con ,$st_bus);
}//Termina Si buscar
?>
<html>
<link rel="stylesheet" href="css/estilo1.css" type="text/css"/>
<script type="text/javascript" language="JavaScript1.2" src="DSSCRIPT.js"></script>
<body>
<form name="form1" method="post" action="DW34000_PR.php">
  <div align="center">
  <table >
    <tr>
      <th colspan="2" >PAGO X DIA </th>
      </tr>
    <tr>
      <td class="tabagre">Fecha inicial: </td>
      <td class="inputcodigo"> <input name="fecini" type="text" class="emplea" id="fecini" size="15" 
					value="<?php
 if(!isset($_POST['fecini'])){
									echo date("d/m/Y");
								}
								else{
									echo $_POST['fecini'];
								}
					?>"> 
				<input name="bot1" id="bot1" 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      : "bot1"      // ID of the button
    					}
  					);
				</script>&nbsp;</td>
    </tr>
	<tr>
      <td class="tabagre">Fecha finall: </td>
      <td class="inputcodigo"> <input name="fecfin" type="text" class="emplea" id="fecfin" size="15" 		value="<?php
 if(!isset($_POST['fecfin'])){
									echo date("d/m/Y");
								}
								else{
									echo $_POST['fecfin'];
								}
					?>"> 
				<input name="bot2" id="bot2" value=" ... " type="image" src="logos/cal4.jpg"/>
                <script type="text/javascript">
				  	Calendar.setup(
    					{
      						inputField  : "fecfin",        // ID of the input field
      						ifFormat    : "%d/%m/%Y",    // the date format
      						button      : "bot2"      // ID of the button
    					}
  					);
				</script>&nbsp;</td>
    </tr>
    <tr>
      <td class="tabagre">Serie Facturas:</td>
      <td class="inputcodigo"> <input name="teser" type="text" id="teser" value="<?php
 echo $_POST['teser'];?>"></td>
    </tr>
    <tr>
      <td colspan="2"> 
        <div align="center">
          <input name="bo_bus" type="submit" id="bo_bus" value="Buscar">
          </div>
      </td>
      </tr>
  </table>
  </div>
</form>
<form name="frm1" method="post" action="">
<input name="teser" type="hidden" id="teser" value="<?php
 echo $_POST['teser'];?>">
<input name="fecini" type="hidden" id="fecini" value="<?php
 echo $_POST['fecini'];?>">
<input name="fecfin" type="hidden" id="fecfin" value="<?php
 echo $_POST['fecfin'];?>">
<input name="busqueda" type="hidden" id="busqueda" value="<?php
 echo $st_bus;?>">
<div align="center">
  <table >
    <tr>
      <th colspan="6" >
        <div align="left">
          <input name="bo_imp" type="button" id="bo_imp" value="Imprimir"  onClick="openpage('DW34000_IM.php','_self')">
          <input name="toExcel" type="button" id="toExcel" value="Exportar Excel" onClick="openpage('DW34000_IME.php','_self')">
        </div>     </th>
    </tr>
    <tr>
      <td nowrap class="tdagre1">Folio Caja </td>
      <td nowrap class="tdagre1">Numero Docto. </td>
      <td nowrap class="tdagre1">Nombre Cliente </td>
      <td nowrap class="tdagre1">Subtotal</td>
      <td nowrap class="tdagre1">IVA</td>
      <td nowrap class="tdagre1">Total  </td>
      </tr>
	<?php
 
		if(isset($_POST['bo_bus'])){
		$z=-1;
		$totales=NULL;
		$totgeneral=NULL;
		while(@$dt_redocl=mysqli_fetch_array($sq_redocl)){
		if ($dt_redocl['tip_cam'] > 0 && $dt_redocl['tip_mon']!='N') $tipcambio=$dt_redocl['tip_cam'];
		else $tipcambio=1;
			$dt_bascps=mysqli_fetch_array(mysqli_query($con ,"select * from dxbascps where codigo='".$dt_redocl['codigo']."'"));
			if($z==-1){
				echo '<tr><td colspan="6" class="typeagre"><div align="center"> Movimientos Del '.chfecha($dt_redocl['fec_cob'],'Y-m-d','d de M del Y').'&nbsp;</div></td></tr>';
				$z=$dt_redocl['fec_cob'];
			}elseif($z!=$dt_redocl['fec_cob']){
				imptotales("Total x dia: ",$totales);
				echo '<tr><td colspan="6" class="typeagre"><div align="center"> Movimientos Del '.chfecha($dt_redocl['fec_cob'],'Y-m-d','d de M del Y').'&nbsp;</div></td></tr>';
				$z=$dt_redocl['fec_cob'];
				$totales=NULL;
			}
			llenaTotales($totales,$dt_redocl);
			llenaTotales($totgeneral,$dt_redocl);
			echo '<tr>';
			echo '<td nowrap colspan="1">'.$dt_redocl['fol_cob'].'&nbsp;</td>';
			echo '<td nowrap colspan="1">'.$dt_redocl['num_doc'].'&nbsp;</td>';
			echo '<td nowrap colspan="1">'.$dt_bascps['ap_paterno'].' '.$dt_bascps['ap_materno'].' '.$dt_bascps['nombre'].'&nbsp;</td>';
			echo '<td nowrap colspan="1">'.number_format($dt_redocl['imp_cob']*$tipcambio,2,'.',',').'&nbsp;</td>';
			echo '<td nowrap colspan="1">'.number_format($dt_redocl['iva_cob']*$tipcambio,2,'.',',').'&nbsp;</td>';
			echo '<td nowrap colspan="1">'.number_format($dt_redocl['tot_cob']*$tipcambio,2,'.',',').'&nbsp;</td>';
			echo '</tr>';
		}
		imptotales("Total x dia: ",$totales);
		imptotales("Total General: ",$totgeneral);
		//imptotales("Saldo General Documentos: ",$totgeneral);
	}
	
	function llenaTotales(&$totales, $dat){
		if ($dat['tip_cam'] > 0 && $dat['tip_mon']!='N') $tipcambio=$dat['tip_cam'];
		else $tipcambio=1;
		$totales[0]+=$dat["imp_cob"]*$tipcambio;
		$totales[1]+=$dat["iva_cob"]*$tipcambio;
		$totales[2]+=$dat["tot_cob"]*$tipcambio;
	}
	
	function imptotales($leyenda,$totales){
		echo '<tr>';
		echo '<td colspan="3"><div align="right">'.$leyenda.'&nbsp;</div></td>';
		echo '<td colspan="1">'.number_format($totales[0],2,'.',',').'&nbsp;</td>';
		echo '<td colspan="1">'.number_format($totales[1],2,'.',',').'&nbsp;</td>';
		echo '<td colspan="1">'.number_format($totales[2],2,'.',',').'&nbsp;</td>';
		echo '</tr>';
	}
	?>
  </table>
  </div>
</form>
</body>
</html>