<?php
session_start();
require_once('../conexion.php');
require_once('../include/sesiones.php'); 
include ('totales_caja.php'); 
?>
<table class="table table-striped table-bordered">
    <thead>
        <tr>
            <th width="1%">N°</th>
            <th width="8%">FECHA</th>
            <th width="">USUARIO</th>
            <th width="1%">BASE</th>
            <th width="1%">EFECTIVO</th>
            <th width="1%">CREDITO</th>
            <th width="1%">TARJETA</th>
            <th width="1%">TRANSF</th>
            <th width="1%">CRUZADAS</th>
            <th width="1%">COMBINADO</th>
            <th width="1%">TOTAL_V</th>
            <!--<th width="6%">E_CRUCES</th> -->
            <th width="1%">ABONOS</th>
            <th width="1%">EGRESOS</th>
            <th width="1%">CIERRE</th>
            <th width="1%"></th>
        </tr>
    </thead>
            
    <?php 
    $action = (isset($_REQUEST['action'])&& $_REQUEST['action'] !=NULL)?$_REQUEST['action']:'';
    if($action == 'ajax')
    {
        include '../include/pagination.php'; 
        $page=(isset($_REQUEST['page']) && !empty($_REQUEST['page']))?$_REQUEST['page']:1;
        $per_page=10;
        $adjacents=4; 
        $offset=($page - 1) * $per_page;
        $count_query=mysqli_query($con,"SELECT count(*) AS numrows FROM movimiento_caja where empresa='$empresa' and sucursal='$sucursal' and mca_estado='0' order by apertura desc ");
        $row= mysqli_fetch_array($count_query);
        $numrows = $row['numrows'];
        $total_pages = ceil($numrows/$per_page);
        $reload = './P_pos.php';
        $sql="SELECT *, DATE_FORMAT(`mca_inicio`,'%d-%m-%Y') as mca_inicio FROM movimiento_caja where empresa='$empresa' and sucursal='$sucursal' and mca_estado='0' order by apertura desc  LIMIT $offset,$per_page";
        $query = mysqli_query($con, $sql);
        if ($numrows>0)
           {
             while ($reg=mysqli_fetch_array($query))
                {
    ?>
        <tr>
            <td><?php echo $reg['apertura']; ?></td>
            <td><?php echo $reg['mca_inicio']; ?></td>
            <td><?php
                $mca_usuario=$reg['mca_usuario']; 
                $datos1 = mysqli_query($con,"SELECT * FROM usuario WHERE usu_id='$mca_usuario'") ;
                $fila1 = mysqli_fetch_array( $datos1 );
                echo $fila1['usu_nombre']; ?></strong></td>
            <td><p style="color:#07650F" align="right"><?php echo number_format($reg['mca_base']); ?></p></td>
            <td><p style="color:#07650F" align="right"><?php echo number_format($reg['mca_ventas'],0); ?></p></td>
            <td><p style="color:#FF7514" align="right"><?php echo number_format($reg['mca_credito'],0);?></p></td>
            <td><p style="color:#FF7514" align="right"><?php echo number_format($reg['mca_tarjeta'],0); ?></p></td>
            <td><p style="color:#FF7514" align="right"><?php echo number_format($reg['mca_transferencia'],0); ?></p></td>
            <td><p style="color:#FF7514" align="right"><?php echo number_format($reg['mca_nota'],0); ?></p></td>
            <td><p style="color:#000" align="right"><?php echo number_format($reg['mca_combinado'],0); ?></p></td>
            <td><p style="color:#000" align="right"><?php echo number_format($reg['mca_ventas']+$reg['mca_credito']+$reg['mca_tarjeta']+$reg['mca_transferencia']+$reg['mca_nota']+$reg['mca_combinado'],0); ?></p></td>
            <!--<td><p style="color:#07650F" align="right"><?php echo number_format($reg['mca_efectivo_nota'],0); ?></p></td>-->
            <td><p style="color:#07650F" align="right"><?php echo number_format($reg['mca_abonos'],0); ?><p style="color:#07650F";></td>
            <td><p style="color:#FF0000" align="right"><?php echo number_format($reg['mca_otros_movimientos'],0); ?></p></td>
            <td><p style="color:#000" align="right"><?php echo number_format($reg['mca_valor_cierre'],0); ?></p></td>
          <!--  <td><p style="" align="right"><?php echo number_format($reg['mca_diferencia'],0); ?></p></td>-->
            <td>
                <a href="tirillas/cierre.php?mca_id=<?php echo $reg['mca_id']; ?>" target="_blank" class="btn btn-xs btn-success"> <i class="btn-icon-only icon-print"></i></a>
            </td>
        </tr>
<?php } } }?>
        <tr>
            <td colspan=15>
              <span class="pull-right">
                <?php echo paginate($reload, $page, $total_pages, $adjacents); ?>
              </span>
            </td>
        </tr>
</table>


<script>
    $(".contado").click(function(){
        $.get("./php_caja/form_contado.php",function(data){
            $("#form-con").html(data);
        });
        $('#contadoModal').modal('show');
    });
</script>
<div class="modal fade" id="contadoModal" tabindex="-1" role="dialog" aria-labelledby="editModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title">Ventas En Efectivo</h4>
            </div>
            <div class="modal-body">
                <div id="form-con"></div>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal-dialog -->
</div><!-- /.modal -->

<script>
    $(".credito").click(function(){
        $.get("./php_caja/form_credito.php",function(data){
            $("#form-cre").html(data);
        });
        $('#creditoModal').modal('show');
    });
</script>
<div class="modal fade" id="creditoModal" tabindex="-1" role="dialog" aria-labelledby="editModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title">Ventas a Credito</h4>
            </div>
            <div class="modal-body">
                <div id="form-cre"></div>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal-dialog -->
</div><!-- /.modal -->

<script>
    $(".tarjeta").click(function(){
        $.get("./php_caja/form_tarjeta.php",function(data){
            $("#form-tar").html(data);
        });
        $('#tarjetaModal').modal('show');
    });
</script>
<div class="modal fade" id="tarjetaModal" tabindex="-1" role="dialog" aria-labelledby="editModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title">Ventas Con tarjeta</h4>
            </div>
            <div class="modal-body">
                <div id="form-tar"></div>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal-dialog -->
</div><!-- /.modal -->


<script>
    $(".transferencia").click(function(){
        $.get("./php_caja/form_transferencia.php",function(data){
            $("#form-trans").html(data);
        });
        $('#transferenciaModal').modal('show');
    });
</script>
<div class="modal fade" id="transferenciaModal" tabindex="-1" role="dialog" aria-labelledby="editModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title">Ventas Con Transferencia</h4>
            </div>
            <div class="modal-body">
                <div id="form-trans"></div>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal-dialog -->
</div><!-- /.modal -->


<script>
    $(".cruces").click(function(){
        $.get("./php_caja/form_cruces.php",function(data){
            $("#form-cru").html(data);
        });
        $('#crucesModal').modal('show');
    });
</script>
<div class="modal fade" id="crucesModal" tabindex="-1" role="dialog" aria-labelledby="editModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title">Ventas con Cruces de Nota Credito</h4>
            </div>
            <div class="modal-body">
                <div id="form-cru"></div>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal-dialog -->
</div><!-- /.modal -->

<script>
    $(".combinado").click(function(){
        $.get("./php_caja/form_combinado.php",function(data){
            $("#form-com").html(data);
        });
        $('#combinadoModal').modal('show');
    });
</script>
<div class="modal fade bs-example-modal-lg" id="combinadoModal" tabindex="-1" role="dialog" aria-labelledby="editModalLabel" aria-hidden="true">
    <div class="modal-dialog modal-lg">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title">Ventas Combinadas</h4>
            </div>
            <div class="modal-body">
                <div id="form-com"></div>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal-dialog -->
</div><!-- /.modal -->

 
<script>
    $(".egresos").click(function(){
        $.get("./php_caja/form_egresos.php",function(data){
            $("#form-egre").html(data);
        });
        $('#egresosModal').modal('show');
    });
</script>
<div class="modal fade" id="egresosModal" tabindex="-1" role="dialog" aria-labelledby="editModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title">Egresos</h4>
            </div>
            <div class="modal-body">
                <div id="form-egre"></div>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal-dialog -->
</div><!-- /.modal -->


<script>
    $(".abonos").click(function(){
        $.get("./php_caja/form_abonos.php",function(data){
            $("#form-abo").html(data);
        });
        $('#abonosModal').modal('show');
    });
</script>
<div class="modal fade" id="abonosModal" tabindex="-1" role="dialog" aria-labelledby="editModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title">Abonos</h4>
            </div>
            <div class="modal-body">
                <div id="form-abo"></div>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal-dialog -->
</div><!-- /.modal -->


<script>
    $(".cierre").click(function(){
        id = $(this).data("id");
        $.get("./php_caja/form_cierre.php","id="+id,function(data){
        $("#form-cierre").html(data);
        });
        $('#cierreModal').modal('show');
    });
</script>
<div class="modal fade" id="cierreModal" tabindex="-1" role="dialog" aria-labelledby="editModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title">Modificar Cierre de Caja</h4>
            </div>
            <div class="modal-body">
                <div id="form-cierre"></div>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal-dialog -->
</div><!-- /.modal -->