<?php
session_start();
include("DMMYSQLG.php");
include("DSA1000.php");
include("DF80000.php");
include('JQUERY.inc');
$granSalVen=0;
$granSer=0;
$granPro=0;
$granDesVen=0;
$granTotVen=0;


//$update=mysqli_query($con ,"SELECT fol_ven,tip FROM fpropina where fol_ven>'14400' and tip!='0' order by nparte1");
$update = mysqli_query($con ,"SELECT a.fol_ven, a.tip FROM fpropina a join dgpemema b on b.fol_ven=a.fol_ven where a.tip<>'0' and a.tip<>b.tip  order by nparte1");
while ($up = mysqli_fetch_array($update)) {
    $insert = mysqli_query($con ,"update dgpemema set tip='" . $up['tip'] . "' where fol_ven='" . $up['fol_ven'] . "'");
}
$updbte = mysqli_query($con ,"SELECT cvmesero, fol_ven FROM fcomhues WHERE modify='1'");
while ($dt_date = mysqli_fetch_array($updbte)) {
    $insbrt = mysqli_query($con ,"update dgpemema set cod_ven='" . $dt_date['cvmesero'] . "' where fol_ven='" . $dt_date['fol_ven'] . "'");
}
?>
<html>
    <head>
        <link rel="stylesheet" href="css/estilo1.css" type="text/css"/>
        <script type="text/javascript" language="JavaScript1.2" src="DSSCRIPT.js"></script>
        <script language="javascript">
            function abrir2popup(val1, val2)
            {

                a = window.open("rep_ventas_TK.php?bot=<?php echo $_POST['fecini']; ?>&but=<?php echo $_POST['fecfin']; ?>&ven=<?php echo $_POST['secodven']; ?>&pven=<?php echo $vars; ?>", "", //$_POST['setipvent']
                        "scrollbars=yes, resizable=no, width=300,height=700, top=85, left=140");
            }
        </script>
        <style type="text/css">
            <!--
            .estiloFecha {
                font-size: 12px;
                font-weight: bold;
            }

            .granTotL{
                font-family:Arial, Helvetica, sans-serif;
                font-size:14px;
                font-weight:bold;
                text-align:left;
                background-color:#0080FF;
                 ;
            }
            .granTotR{
                font-family:Arial, Helvetica, sans-serif;
                font-size:14px;
                font-weight:bold;
                text-align:right;
                background-color:#0080FF;
                 ;	
            }
            .granTotParL{
                font-family:Arial, Helvetica, sans-serif;
                font-size:12px;
                font-weight:bold;
                text-align:left;
                background-color:#9DCEFF;
                color:#000000;
            }
            .granTotParR{
                font-family:Arial, Helvetica, sans-serif;
                font-size:12px;
                font-weight:bold;
                text-align:right;
                background-color:#9DCEFF;
                color:#000000;	
            }
            .granTotCan{
                font-family:Arial, Helvetica, sans-serif;
                font-size:12px;
                font-weight:bold;
                text-align:left;
                background-color:#FF0000;
                color:#000000;	
            }
            .granTotAb{
                font-family:Arial, Helvetica, sans-serif;
                font-size:12px;
                font-weight:bold;
                text-align:left;
                background-color:#00CC33;
                color:#000000;	
            }


            .Estilo4 {
                color: #FFFFFF;
                font-weight: bold;
            }
            .Estilo5 {font-size: 12px; font-weight: bold; color: #FFFFFF; }
            .Estilo6 {font-family :urw gothic l; background-color: #dbe0e9; border: 1px;}
            -->
        </style>
    </head>
    <body>
       
<?php
$sq_tipven = mysqli_query($con ,"select * from dgtipven"); //Datos para combo setipven 
$sq_pvta = mysqli_query($con ,"select * from ptventa"); //Datos para combo punto de venta 
?>
    <div align="center">
        <form name="frm1" id="frm1" method="post" action="">
            <table  align="center">
                <tr>
                    <th colspan="2">LISTADO DE VENTAS DIARIAS</th>
                </tr>
                <tr>
                    <td><span class="Estilo4">Punto de Venta:</span></td>
                    <td>
                        <div align="left" class="Estilo4">
                            <select name="setipvent" id="setipvent">
                                <option value="T">------ TODOS ------</option>
<?php
while ($dt_tippag = mysqli_fetch_array($sq_pvta)) {
    if ($dt_tippag['nparte1'] == $vars) //$_POST['setipvent']
        echo '<option value="' . $dt_tippag['nparte1'] . '" selected>' . $dt_tippag['np_desc1'] . '</option>';
    else
        echo '<option value="' . $dt_tippag['nparte1'] . '">' . $dt_tippag['np_desc1'] . '</option>';
}
?>
                            </select>
                        </div></td>
                </tr>
                <tr style="display:none">
                    <td><span class="Estilo4">Tipo Venta:</span></td>
                    <td>
                        <div align="left" class="Estilo4">
                            <select name="setipven" id="setipven">
                                <option value="T">---- TODAS ----</option>
                                <?php
                                while ($dt_tipven = mysqli_fetch_array($sq_tipven)) {
                                    if ($dt_tipven['tip_ven'] == $_POST['setipven'])
                                        echo '<option value="' . $dt_tipven['tip_ven'] . '" selected>' . $dt_tipven['des_tipven'] . '</option>';
                                    else
                                        echo '<option value="' . $dt_tipven['tip_ven'] . '">' . $dt_tipven['des_tipven'] . '</option>';
                                }
                                ?>
                            </select>
                        </div></td>
                </tr>
                <tr>
                    <td colspan="2" nowrap>
                        <div align="center" class="Estilo5">

                            Del 
                            <input name="fecini" type="text" class="Estilo6 datefrom" id="fecini" size="15" 
                                <?php
                                if (isset($_POST['fecini']))
                                    echo 'value="' . $_POST['fecini'] . '"';
                                else
                                    echo 'value="' . date('d/m/Y') . '"';
                                ?>>		      
                         al 
                            

                            <input name="fecfin" type="text" class="Estilo6 dateto" id="fecfin" size="15" 
<?php
if (isset($_POST['fecfin']))
    echo 'value="' . $_POST['fecfin'] . '"';
else
    echo 'value="' . date('d/m/Y') . '"';
?>>
                        
                        </div></td>
                </tr>
                <tr>
                    <td><span class="Estilo4">Cajero:</span></td>
                    <td><span class="Estilo4">
                            <select name="secodven" id="secodven">
                                <option value="T">---- TODOS ----</option>
<?php
$sql = mysqli_query($con ,"SELECT * FROM dgcatven order by CONCAT(nom_ven,' ',ap_pat_ven,' ',ap_mat_ven) asc");
while ($reg = mysqli_fetch_array($sql)) {
    if ($reg['cod_ven'] == $_POST['secodven']) {
        echo '<option value="' . $reg['cod_ven'] . '" selected>' . $reg['nom_ven'] . ' ' . $reg['ap_pat_ven'] . ' ' . $reg['ap_mat_ven'] . '</option>';
    } else {
        echo '<option value="' . $reg['cod_ven'] . '">' . $reg['nom_ven'] . ' ' . $reg['ap_pat_ven'] . ' ' . $reg['ap_mat_ven'] . '</option>';
    }
}
?>
                            </select>
                            &nbsp;</span></td>
                </tr>
                <tr>
                    <td colspan="2"><div align="center">
                            <input name="boproc" type="submit" id="boproc" value="Procesar" onClick="openpage('rep_ventas_PR.php', '_self')" />
                        </div></td>
                </tr>
            </table>

            <table border="0" cellpadding="0" width="84%">
                <tr>
                    <th colspan="12">
                <div align="left">
                    <input type="button" name="bot4" value="PDF" onClick="openpage('rep_ventas_IM.php', '_self')">
                    <input type="button" name="bot4" value="Ticket" onClick="abrir2popup('javascript:document.frm1.fecini.value', 'javascript:document.frm1.fecfin.value');">
                </div>			</th>
                </tr>
                <tr>
                    <th colspan="12" align="justify"><?php
if (isset($_POST["setipvent"])&&$_POST["setipvent"] == "T") {
    echo "TIP. VTA.: ";
    echo "TODAS";
} else {
    @$bus = mysqli_query($con ,"SELECT * FROM ptventa WHERE nparte1= '" . $vars . "'"); //$_POST['setipvent']
    $re = mysqli_fetch_array($bus);
    echo "TIP. VTA.: ";
    echo $re['np_desc1'];
}
?></th>
                </tr>
                <tr>
                    <th colspan="12"><?php
if (isset($_POST["secodven"])&&$_POST["secodven"] == "T") {
    echo "CAJERO: ";
    echo "TODOS";
} else {
    @$bus1 = mysqli_query($con ,"SELECT * FROM dgcatven WHERE cod_ven = '" . $_POST['secodven'] . "'");
    $re1 = mysqli_fetch_array($bus1);
    echo "CAJERO: ";
    echo $re1['nom_ven'];
    echo ' ';
    echo $re1['ap_pat_ven'];
    echo ' ';
    echo $re1['ap_mat_ven'];
}
?></th>
                </tr>
                <tr class="typeagre">
                    <td width="7%"><div align="center">Folio Vta.</div></td>
                    <td width="6%"><div align="center">P. Vta. / Mesa</div></td>
                    <td width="6%"><div align="center">Fecha</div></td>		  
                    <td width="6%"><div align="center">Hora</div></td>
                    <td width="6%"><div align="center"># Tickets</div></td>
                    <td width="15%"><div align="center">Mesero</div></td>
                    <td width="13%"><div align="center">FP</div></td>
                    <td width="9%">Subtotal</td>
                    <td width="8%">Descuento</td>
                    <td width="6%"> Nrta Entr X Cta</td>	
                    <td width="9%"> Nrta Entr X Cta (S)</td>
                    <td width="9%">Total</td>
                </tr>

                        <?php
                        require_once("PV00000_CL.php");

                        if (isset($_POST["fecini"])) {
                           $vard=(isset($data))?$data:NULL;
                            $dgPEmema = new dgpeMema($vard);
                             

                            $sq_dgpeMEma = $dgPEmema->report_getDiarias();

                            while ($reg = mysqli_fetch_array($sq_dgpeMEma)) {

///------>suma de productos
                                @$s = mysqli_query($con ,"SELECT SUM($memaDet.pre_bas*$memaDet.can_ref) as sumat, sum($memaDet.imp_des) as desCuento FROM $memaDet, $table, $mema WHERE $memaDet.cons_ven='" . $reg['folVen'] . "' and $table.pedido='" . $reg['folVen'] . "' and $memaDet.cons_ven=$mema.fol_ven and $mema.cancelado!=1 and $mema.cancela=0 and $table.cancelado=0 and $memaDet.cancela=0");
								
                                echo mysqli_error($con);
                                while ($r = mysqli_fetch_array($s)) {
                                    $suma = $r["sumat"];
                                    $desCuento = $r['desCuento']; 
                                }

                                /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>suma de productos solo cortesia
                                  @$cr=mysqli_query($con ,"select $taDet.importe as sumat from $table left join $taDet on ($taDet.n_rec=$table.n_rec) where $table.pedido='".$reg['folVen']."' and $taDet.tip_pag=3");
                                  echo mysqli_error($con);
                                  $ccr = mysqli_fetch_array($cr);
                                  if ($ccr['sumat']!=0){
                                  $sumacr=$ccr["sumat"]+$reg['propina'];
                                  }else{
                                  $sumacr=$ccr["sumat"];
                                  }
                                  +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */

//IMPRESION DE CUENTAS NO PAGADAS
                                if (($reg["impPag"] == 0.00) && ($reg["cancela"] == 0)) {
                                    //el error es por que en versiones anteriores de php un string pude formarse por varias lineas
                                    //pero esto generaba muchos conflicots al momento de interpretarlo
                                    //ahora se puede formar por varias lineas per unidas por un .
                                    //algunas varibles vamso atener ue usar concatenacion tambien con .
                                    echo "<tr class=\"granTotAb\"> "//cerramos la "linea".
                                    . " <td class=\"granTotAb\">" . $reg['conVen'] . "</div></td>"//cone l punto indicamos que inicia una nueva y al final la cerramos
                                    . "<td class=\"granTotAb\">" . $reg['dptvta'] . " | " . $reg['dmesa'] . "</div></td> "
                                    . "    <td class=\"granTotAb\">" . $reg['fecVen'] . "</div></td>"
                                    . " <td class=\"granTotAb\" colspan=\"2\">" . $reg['hora'] . "</div></td>"
                                    . " <td class=\"granTotAb\" colspan=\"2\">" . $reg['nomVen'] . "</div></td>"
                                    . "  <td class=\"granTotAb\" colspan=\"8\">CUENTA ABIERTA</div></td></tr>";
                                    //hacemos eso para todas las lineas
                                    //hasta sacar ese error
                                    //
                                    $numVen++;
                                } else if (($reg["impPag"] == 0.00) && ($reg["cancela"] == 1)) { //CUENTAS CANCELADAS
                                    //lo mismo con esto okOK
                                    //puede dar shift.alt -f
                                    //eso alinea todo el codigo
                                    echo "<tr class=\"granTotCan\"> "
             . " <td class=\"granTotCan\">".$reg['conVen']."</div></td>"
			 ." <td class=\"granTotCan\">".$reg['dptvta']." | ".$reg['dmesa']."</div></td> " 
		     . "  <td class=\"granTotCan\">".$reg['fecVen']."</div></td>"
		       ." <td class=\"granTotCan\" colspan=\"2\"></div></td>"
			."	 <td class=\"granTotCan\" colspan=\"2\">".$reg['nomVen']."</div></td>"
				."  <td class=\"granTotCan\" colspan=\"2\">CANCELADO</div></td>"
				  ." <td class=\"granTotCan\" colspan=\"4\">".$reg['comentario']."</div></td></tr>";
                                    $numVen++;
                                } else {
                                    $tickets = mysqli_fetch_array(mysqli_query($con ,"select count(*) as num_imp from $impresion where fol_ven='" . $reg['folVen'] . "'"));

                                    echo "<tr class=\"granTotParR\"> "
             ."  <td class=\"granTotParR\">".$reg['conVen']."</div></td>"
			   ." <td class=\"granTotParL\">".$reg['dptvta']." | ".$reg['dmesa']."</div></td>" 
		      ."   <td class=\"granTotParL\">".$reg['fecVen']."</div></td>"
			     ." <td class=\"granTotParL\">".$reg['hora']."</div></td>"
		          ." <td class=\"granTotParL\">".$tickets['num_imp']."</div></td>"
				   ." <td class=\"granTotParL\">".$reg['nomVen']."</div></td>";

                                    $folio = mysqli_query($con ,"select $table.num_cli as cliente,$taDet.tip_pag as tppag,dgtippag.ini_pag as pagoo from $taDet inner join dgtippag on dgtippag.tip_pag=$taDet.tip_pag inner join $table on $table.n_rec=$taDet.n_rec
	   where $table.pedido='" . $reg['folVen'] . "'");
                                    $saldo = 0;
                                    $cont = 0;
                                    $_SESSION['clientec'] = 0;
                                    echo '<td class="granTotParL">&nbsp;';
                                    while ($rg = mysqli_fetch_array($folio)) {
                                        if ($rg['tppag'] == 1) {
                                            $_SESSION['clientec'] = $rg['cliente'];
                                            $cont++;
                                        }
                                        echo $rg['pagoo'];
                                        echo ' | ';
                                    }
                                    if ($cont >= 1) {
                                        $sql_cli = mysqli_query($con ,"select * from valeryus19 where n_reg='".$_SESSION['clientec']."'");
                                        $reg_hb = mysqli_fetch_array($sql_cli);
                                        if ($reg_hb['fnumcto'] != '')
                                            $hbit = $reg_hb['fnumcto'];
                                        else
                                            $hbit = $reg_hb['fmuncto'];

                                        echo 'F.' . $reg_hb['n_reg'] . 'H.' . $hbit;
                                    }

                                    echo " 
             <td class=\"granTotParR\">" . number_format($suma, 2, '.', ',') . "</div></td>
			  <td class=\"granTotParR\">$ " . number_format($desCuento, 2, '.', ',') . "</div></td> 
		       <td class=\"granTotParR\">" . number_format($reg['propina'], 2, '.', ',') . "</div></td>
			    <td class=\"granTotParR\">" . number_format($reg['servicio'], 2, '.', ',') . "</div></td>
				 <td class=\"granTotParR\">" . number_format($sumtot = ($suma + $reg['propina'] + $reg['servicio'] - $desCuento), 2, '.', ',') . "</div></td></tr>";

                                    $granDesVen +=$desCuento;  //descuento
                                    //$granCorVen +=$sumacr;  //cortesia
                                    $granSer +=$reg['servicio'];  //servicio
                                    $granTotVen +=$suma;  //subtotal
                                    //$granPagVen +=$reg["iva_ven"];  //iva
                                    if ($reg['impPag'] != 0) {
                                        $granSalVen +=$sumtot;  //total
                                    }
                                    $granPro +=($reg['propina']);  //propina		
                                    $numVen++;
                                }
                            }

                            echo "<tr> 
			<td class=\"granTotL\" colspan=\"7\">TOTALES</td>
			<td class=\"granTotR\">" . number_format($granTotVen, 2, '.', ',') . "</td>  		
			<td class=\"granTotR\">" . number_format($granDesVen, 2, '.', ',') . "</td> 
			<td class=\"granTotR\">" . number_format($granPro, 2, '.', ',') . "</td> 		
			<td class=\"granTotR\">" . number_format($granSer, 2, '.', ',') . "</td> 				
			<td class=\"granTotR\">" . number_format($granSalVen, 2, '.', ',') . "</td>												
		</tr>";
                        }
//603-->600
//598-->500
//429-->400 473
                        ?>	
            </table>
        </form>
    </div>
</body>
</html>