<div class="content-wrapper">

  <section class="content-header">

    <h1>

      Administrar Caja

    </h1>

    <ol class="breadcrumb">

      <li><a href="inicio"><i class="fa fa-dashboard"></i> Inicio</a></li>

      <li class="active">Administrar estados de servicios</li>

    </ol>

  </section>

<section class="content">

<div class="box">

<div class="box-header with-border">



<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#modalApertura">Apertura Caja</button>


    <button class="btn btn-success reporteCajaPDF" >

        Descargar reporte en .pdf <i class="fa fa-file-pdf-o"></i>
        <input type="hidden" id="idCaja" value="<?= base64_encode($_SESSION['id']) ?>">

    </button>
    <button type="button" class="btn btn-primary" id="actualizar-tabla">Actualizar Tabla</button>
    <div class="row" style="margin-top: 10px;">
      <div class="col-12 col-md-6 col-lg-6">
        <form class="" action="" method="post">
          <div class="row">
            <div class="col-md-4">
              <input type="date" class="form-control" name="fecha1" id="fecha1" value="<?= (isset($_POST['fecha1'])) ? $_POST['fecha1'] : '' ?>">
            </div>
            <div class="col-md-4">
              <input type="date" class="form-control" name="fecha2" id="fecha2" value="<?= (isset($_POST['fecha2'])) ? $_POST['fecha2'] : '' ?>">
            </div>

            <div class="col-md-4">
              <input type="submit" class="btn btn-primary" name="consultar-caja" value="Consultar">
            </div>

          </div>
        </form>
      </div>
    </div>
<!--
    <div class="form-row">

        <div class="form-group col-md-3">
            <div class="input-group">




            </div>
        </div>

    </div>
-->
</div>

      <div class="box-body">

       <table class="table table-bordered table-striped dt-responsive tablas serviConti">

        <thead>

         <tr>

           <th style="width:10px">#</th>
           <th style="width:80px">Fecha registro</th>
           <th style="width:80px">Fecha cierre</th>
           <th>Nombres</th>
           <th>Apertura Caja</th>
           <th>Total Comercial</th>
           <th>Total Domiciliario</th>
           <th>Total ingreso</th>
           <th>Ingreso bruto</th>
           <th>Total entregado</th>
           <th>Saldo siguiente</th>
           <th>Estado</th>

         </tr>

        </thead>

        <tbody id="serviCont">

        <?php

        $consultaCaja = ControladorCaja::ctrMostrarCajas();
        if(isset($_POST['consultar-caja'])){

            $consultaCaja = ControladorCaja::ctrMostrarCajas(null, null, $_POST['fecha1'], $_POST['fecha2']);
        }

       foreach ($consultaCaja as $key => $value){
         //select c.id, fechaRegistro, usu.nombre, AperturaCaja, totalComercial, totalDomiciliario, totalIngreso, totalEntregado, saldoSigiente, estadoCierre from caja as c inner join usuarios as usu ON c.idUsuario=usu.id
          echo ' <tr>
                  <td>'.($key+1).'</td>
                  <td>'.$value["fechaRegistro"].'</td>
                  <td>'.$value["fechaCierre"].'</td>';

                 $itemPersona="nombre";
                 $valorPersona=$value["AperturaCaja"];


                echo '<td>'.$value["nombre"].'</td>';

                echo '<td>'.number_format($value["AperturaCaja"],2,'.',',').'</td>';

                echo '<td>'.number_format($value["totalComercial"],2,'.',',').'</td>';

                echo '<td>'.number_format($value["totalDomiciliario"],2,'.',',').'</td>';

                echo '<td>'.number_format($value["totalIngreso"],2,'.',',').'</td>';

                echo '<td>'.number_format(($value["totalIngreso"]+$value["AperturaCaja"]),2,'.',',').'</td>';

                 echo '<td>'.number_format($value["totalEntregado"],2,'.',',').'</td>';


                 echo '<td>'.number_format($value["saldoSigiente"],2,'.',',').'</td>';

                echo '<td>'.$value["estadoCierre"].'</td>';




                       echo '<td>

                      <div>
                      <button class="btn btn-info btnImprimirCaja" idCaja="'.base64_encode($value["id"]).'">
                        <i class="fa fa-print"></i></button>

                        <!--<button class="btn btn-warning btnEditarPersona" idCaja="'.base64_encode($value["id"]).'"><i class="fa fa-eye"></i></button>-->
                        <form action="detalle-caja" method="post" style="display: inline;">
                        <input type="hidden" value="'.base64_encode($value["id"]).'" name="idCaja">
                        <button class="btn btn-warning btnDetalleCaja"  idCaja="'.base64_encode($value["id"]).'"><i class="fa fa-eye"></i></button> </form>';


                      echo '</div>

                    </td>



                </tr>';
        }


        ?>

        </tbody>

       </table>

      </div>

    </div>

  </section>

</div>



<div id="modalEditarContrato" class="modal fade" role="dialog">

<div class="modal-dialog modal-lg">
    <div class="modal-content">

      <form role="form" method="post">

        <!--=====================================
        CABEZA DEL MODAL
        ======================================-->

        <div class="modal-header" style="background:#3c8dbc; color:white">

          <button type="button" class="close" data-dismiss="modal">&times;</button>

          <h4 class="modal-title">Cronograma de Pagos</h4>

        </div>

        <!--=====================================
        CUERPO DEL MODAL
        ======================================-->

        <div class="modal-body">

          <div class="box-body">

            <table class="table table-bordered table-striped dt-responsive tablas tablaContratos" width="100%">


        <thead>

         <tr>

           <th style="width:10px">#</th>
           <th>Fechas de pagos</th>
           <th>Monto</th>
           <th>Estado</th>

         </tr>

        </thead>

        <tbody id="tablebody1">


        </tbody>

       </table>


          </div>

        </div>



        <!--=====================================
        PIE DEL MODAL
        ======================================-->

        <div class="modal-footer">

          <button type="button" class="btn btn-danger pull-right" data-dismiss="modal">Close</button>


        </div>

      </form>

      </div>

  </div>

</div>
