<?php
date_default_timezone_set("America/Lima");
if($_SESSION["perfil"] == "Especial"){

  echo '<script>

    window.location = "inicio";

  </script>';

  return;


}


?>
<div class="content-wrapper">
  <section class="content-header">
    <h2>Historia Caja</h2>
    <ol class="breadcrumb">
      <li><a href=""><i class="fa fa-dashboard"></i>Inicio</a></li>
      <li class="active">Detalle de cobranza</li>
    </ol>
  </section>

  <section class="content">
    <div class="row">
      
      <?php
      if(!isset($_SESSION['idCaja'])){
        echo '<h2 style="padding: 50px;">No tiene caja abierta o la caja del día presente ya fue cerrada.</h2>';
        ?>
        <script>
          $(document).ready(function(){
            $('#modalApertura').modal('toggle')
          });
        </script>
        
        <?php
      } else {
        $data = ControladorCaja::ctrConsultarCaja($_SESSION['idCaja'], 'Apertura');
        $subtotal = $data['subTotal'] + $data['caja']['AperturaCaja'];
        //var_dump($data['caja']);
       ?>
      
      <div class="form-group form-space col-md-12">
                  <div class="panel panel-success">
                    <div class="panel-heading">
                      
                      <h2 class="panel-title">Cierre de Caja</h2>
                     
                    </div>
                    <div class="panel-body" style="padding:0px">

                      <form action="" method="post">
                        <div class="form-row">
          
                        <div class="col-xs-12 col-md-6 col-lg-4">
                          <h3 class="text-center">Ingresos del día en:</h2>
                          <hr style="width: 80%; margin:0; margin-bottom: 20px;">

                          <div class="form-horizontal">
                            <div class="form-group">
                              <label for="totalComercial" class="col-sm-5 control-label">Total Comercial</label>
                              <div class="col-sm-5">
                                <input type="text" class="form-control" id="totalComercial" name="totalComercial" value="<?= isset($data['totalComercial'])? number_format($data['totalComercial'], 2, ".", ","): '0.00' ?>" readonly>
                              </div>
                              
                            </div>

                            <div class="form-group">
                              <label for="totalDomiciliario" class="col-sm-5 control-label">Total Domiciliario</label>
                              <div class="col-sm-5">
                                <input type="text" class="form-control" id="totalDomiciliario" name="totalDomiciliario" value="<?= isset($data['totalDomiciliar'])? number_format($data['totalDomiciliar'], 2, ".", ","): '0.00' ?>" readonly>
                              </div>
                              
                            </div>

                            <hr style="width: 50%; margin:0; margin-left: 30%; margin-bottom: 20px;">
                            <div class="form-group">
                              <label for="subTotalIngreso" class="col-sm-5 control-label">Subtotal:</label>
                              <div class="col-sm-5">
                                <input type="text" class="form-control" id="subTotalIngreso" name="subTotalIngreso" value="<?= isset($data['subTotal'])?number_format($data['subTotal'], 2, ".", ","): '0.00' ?>" readonly>
                              </div>
                              
                            </div>
                            
                          </div>
                          
                        </div>
                        <div class="col-xs-12 col-md-6 col-lg-4">
                          <h3 class="text-center">Resumen del ingreso del día:</h2>
                          <hr style="width: 80%; margin:0; margin-bottom: 20px;">
                          <div class="form-horizontal">
                            <div class="form-group">
                              <label for="ingresoBruto" class="col-sm-5 control-label">Ingreso Bruto</label>
                              <div class="col-sm-5">
                                <input type="text" class="form-control" id="ingresoBruto" name="ingresoBruto" value="<?= isset($data['subTotal'])?number_format($subtotal, 2, ".", ","): '0.00' ?>" disabled>
                              </div>
                              
                            </div>

                            <div class="form-group">
                              <label for="totalEntregar" class="col-sm-5 control-label">Total entregar:</label>
                              <div class="col-sm-5">
                                <input type="text" class="form-control" id="totalEntregar" name="totalEntregar">
                              </div>
                              
                            </div>

                            <div class="form-group">
                              <label for="saldoSiguiente" class="col-sm-5 control-label">Saldo Siguiente:</label>
                              <div class="col-sm-5">
                                <input type="text" class="form-control" id="saldoSiguiente" name="saldoSiguiente" value="0.00" readonly>
                              </div>
                              
                            </div>
                            
                          </div>
                        </div>
                        <div class="col-xs-12 col-md-6 col-lg-4">
                          <h3 class="text-center">Datos principales Cierre:</h2>
                          <hr style="width: 80%; margin:0; margin-bottom: 20px;">
                          <div class="form-horizontal">
                            <div class="form-group">
                              <label for="codigoCaja" class="col-sm-5 control-label">Codigo Caja:</label>
                              <div class="col-sm-6">
                                <input type="text" class="form-control" id="codigoCaja" name="codigoCaja" value="<?= isset($data['caja'])?$data['caja']['id']:'' ?>" readonly>
                              </div>
                              
                            </div>

                            <div class="form-group">
                              <label for="fechaCaja" class="col-sm-5 control-label">Fecha apertura:</label>
                              <div class="col-sm-6">
                                <input type="date" class="form-control" id="fechaCaja" name="fechaCaja" value="<?= isset($data['caja'])?$data['caja']['fechaRegistro']:0000-00-00 ?>" readonly>
                              </div>
                              
                            </div>

                            <div class="form-group">
                              <label for="fechaCierre" class="col-sm-5 control-label">Fecha cierre:</label>
                              <div class="col-sm-6">
                                <input type="date" class="form-control" id="fechaCierre" name="fechaCierre" value="<?= date('Y-m-d') ?>" readonly>
                              </div>
                              
                            </div>

                            <div class="form-group">
                              <label for="importeInicial" class="col-sm-5 control-label">Importe Inicial:</label>
                              <div class="col-sm-6">
                                <input type="text" class="form-control" id="importeInicial" name="importeInicial" value="<?= isset($data['caja'])?number_format($data['caja']['AperturaCaja'], 2, ".", ","): '0.00' ?>" readonly>
                              </div>
                              
                            </div>

                            <div class="form-group">
                              <label for="estadoCierre" class="col-sm-5 control-label">Estado de Cierre:</label>
                              <div class="col-sm-6">
                                <input type="text" class="form-control" id="estadoCierre" name="estadoCierre" value="<?= isset($data['caja'])?$data['caja']['estadoCierre']:'' ?>" readonly>
                              </div>
                              
                            </div>
                            
                          </div>
                        </div>

                        <div class="col-sm-12 text-center" style="padding: 20px 0;">
                          <button type="button" class="btn btn-primary btn-carcular-venta">Calcular Caja</button>
                          <button type="submit" class="btn btn-primary" name="btnCerrarCaja">Cerrar Caja</button>
                        </div>
                          <?php 
                            $cerrarCaja = new ControladorCaja();
                            $cerrarCaja->ctrCerrarCaja();
                          ?>
                        </div> 
                      </form>                       
                    </div>
                  </div>
    </div>

    <?php } ?>
 
  </section>

</div>








