<?php

if(!isset($_COOKIE["sesion"])){
  echo '<meta http-equiv="refresh" content="0;url=./" />';
  die();
}

?>

<!DOCTYPE html>
<html lang="en">
<?php include("style.php"); ?>

<style>
  .fileimport
  {
    opacity: 0;
    position: absolute;
    left: 0;
    right: 0;
    top: -12px;
    bottom: 6px;
  }
  .swal2-content2 {
   font-size: medium !important;color: crimson !important;
}
.swal2-show {
    width: 60% !important;
}
.cupon-btn
{
  border-bottom-left-radius: 0px;
  border-top-left-radius: 0px;
}
#nombre_cupon
{
  display: block;
    margin-bottom: 0px;
    align-self: center;
    margin-left: 8px;
}
/* Define the styles for when the elements should be visible */
.show {
    display: block !important; /* Asegura que se muestre cuando se agrega la clase .show */
}
        span
        {
          border-top-right-radius: 0 !important;
          border-bottom-right-radius: 0 !important;
        }
</style>
<title>Cotizador - MYPSA CASEWORK</title>
<body class="hold-transition sidebar-mini layout-fixed" onload="obtenerAreasMuebles()">
  <div class="wrapper">
    <?php include("menu.php") ?>
    <div class="content-wrapper"><br>.
      <section class="content" style="text-align: center;">
        <div class="form-group row">
          <div class="col-2">
            <button class="btn btn-primary btn-block btn-flat btn-sm" id="btnNuevaCotizacion" style="margin-top: 32.5px !important;">
              <i class="fa fa-plus"></i>
              Agregar proyecto
            </button>
          </div>
          <div class="offset-md-2 col-2">
            <label>Estatus</label>
            <select id="selectStatus" class="form-control form-control-sm">
              <option value="Diseño">Diseño</option>
              <option value="Procesando">Procesando</option>
              <option value="Cotizado">Cotizado</option>
            </select>
          </div>
          <div class="col-1">
            <label>Desde</label>
            <input type="text" id="txtFechaIni" class="form-control form-control-sm flat-input">
          </div>
          <div class="col-1">
            <label>Hasta</label>
            <input type="text" id="txtFechaFin" class="form-control form-control-sm flat-input">
          </div>

          <div class="col-4" style="margin-top:31px !important">
          <input type="text" class="form-control form-control-sm flat-input ftfamily" id="inputBusqueda" placeholder="&#xF002; Filtrar cotizaciones" autofocus autocomplete="off" value="">

          </div>
        </div>

        <div class="form-group row">
          <div class="col-12">
            <table id="tablaCotizaciones" class="table table-bordered table-sm" style="width:100%;font-size:14px;background: white;">
              <thead>
                <tr>

                  <th>Folio</th>

                  <th>F. Alta</th>

                  <th>F. Cot</th>

                  <th>Proyecto</th>

                  <th>Total</th>

                  <th>Estado</th>

                  <th></th>

                </tr>

              </thead>

              <tbody></tbody>

              <tfoot>

                <tr>

                  <th></th>

                  <th></th>

                  <th></th>

                  <th></th>

                  <th></th>

                  <th></th>

                  <th></th>

                </tr>

              </tfoot>

            </table>

          </div>

        </div>

      </section>

    </div>

  </div>



  <!--MODAL PARA REGISTRAR/MODIFICAR COTIZACIÓN-->

  <div class="modal" id="modalCotizacion" role="dialog" aria-labelledby="myModalLabels">
    <div class="modal-dialog modal-xl" role="document">
      <div class="modal-content">
        <div class="modal-body" style="text-align:center; height: 525px;">
          <div class="form-group row">
            <div class="col-6">
              <br>
              <div class="input-group">
                <label>PROYECTO:</label>&nbsp;&nbsp;&nbsp;&nbsp;
                <input type="text" class="form-control flat-input form-control-sm" id="inputDescCotizacion" autocomplete="false">
              </div>
              <div class='col-10 mt-4 p-0' id="cupon">
                <div class="input-group">
                  <label>Cupon:</label>&nbsp;&nbsp;&nbsp;&nbsp;
                  <input type="password" class="form-control" id="pass_cupon" aria-describedby="basic-addon3 basic-addon4" autocomplete="off">
                  <input type="hidden" class="form-control" id="id_cupon" aria-describedby="basic-addon3 basic-addon4" autocomplete="off"><input class="btn btn-secondary cupon-btn" type="button" id="verify-cupon" value="Aplicar"><label id="nombre_cupon"></label><span id="verify" style=""></span>
                </div>
              </div>
            </div>
            <div class="offset-3 col-3">
              <div class='row'>
                <div class='col-6'>
                  <label style='text-align: right;'>Folio:</label>
                </div>
                <div class='col-6'>
                  <label style="font-weight: normal;" id="labelFolio">Nuevo</label>
                </div>
              </div>
              <div class='row'>
                <div class='col-6'>
                  <label style='text-align: right;'>Fecha:</label>
                </div>
                <div class='col-6'>
                  <label style="font-weight: normal;" id="labelFecha"></label>
                </div>
              </div>
              <div class='row'>
                <div class='col-6'>
                  <label style='text-align: right;'>Exportar:</label>
                </div>
                <div class='col-6'>
                  <div class='btn-group'>
                    <button class='btn btn-default btn-flat btn-sm' onclick="exportExcel()">Excel</button>
                    <button class='btn btn-default btn-flat btn-sm' id="btnVerPDF">PDF</button>
                  </div>
                </div>
              </div>
            </div>
          </div>
          <div class="form-group row">
            <div class='col-2'>
              <button type="button" class="btn btn-primary btn-flat btn-sm btn-block" id="btnModalAgregarObjeto">
                <i class="fa fa-plus"></i>
                Agregar productos
              </button>
            </div>
            <div class="col-4" id="importar_csv">
              <div class="form-group" style="text-align: left;margin-bottom: auto;">
                <label for="btnImportarProductos" class="btn btn-warning btn-flat btn-sm" id="lblImportarProductos" style="position: relative;"><i class="fa fa-upload" aria-hidden="true" style="margin-right:6px"></i>Importar productos
                <input type="file" class="form-control fileimport" id="btnImportarProductos">
              </label>
                
                <label id="file_nombre" for="" style="font: message-box;"></label>
              </div>
            </div>
            <div class="offset-3 col-3">
              <input type="text" id="inputBusquedaDetalle" placeholder="&#xF002; Filtrar cotización" class="form-control form-control-sm flat-input ftfamily">
            </div>
          </div>
          <div class="form-group row">
            <div class="col-12" style="height: 19rem; overflow: auto;">
              <table id="tablaDetalle" class="table table-bordered table-sm" style="width:100%; font-size: 13px;">
                <thead>
                  <tr>
                    <th>#</th>
                    <th>Area</th>
                    <th>Mueble</th>
                    <th>Referencia</th>
                    <th>Cantidad</th>
                    <th>Unidad</th>
                    <th>Costo Uni</th>
                    <th>Importe</th>
                    <th></th>
                  </tr>
                </thead>
                <tbody id="bodyDetalle"></tbody>
                <tfoot>
                  <tr>
                    <th></th>
                    <th></th>
                    <th></th>
                    <th></th>
                    <th></th>
                    <th></th>
                    <th></th>
                    <th></th>
                    <th></th>
                  </tr>
                </tfoot>
              </table>
            </div>
          </div>
        </div>
        <div class="modal-footer">
          <div class="pull-left">
            <label style="font-weight:normal;font-size:14px;">*Precios sujetos a cambios sin previo aviso</label>
          </div>
          <button type="button" class="btn btn-default btn-flat btn-sm" id="btnModalParametros">Modificar parámetros</button>
          <button type="button" class="btn btn-info btn-flat btn-sm" id="btnProcesarCotizacion">Procesar cotización</button>
          <button type="button"class="btn btn-danger btn-flat btn-sm" id="btnCancelaCotizacion">Cerrar</button>
          <input type="button" id="btnGuardaCotizacion" class="btn btn-success btn-sm btn-flat" value="Guardar">
        </div>
      </div>
    </div>
  </div>



  <!--MODAL AGREGAR OBJETO COMPUESTO-->

  <div class="modal" id="modalAgregarObjeto" role="dialog" aria-labelledby="myModalLabels">
    <div class="modal-dialog modal-xl" role="document">
      <div class="modal-content">
        <div class="modal-body" style="height:450px;">
          <form id="FormObjeto">
            <div class="row">
              <div class="col-6">
                <h5 style="text-align: center; font-weight:bold">Información del mueble</h5>
                <div class="form-group row">
                  <div class='col-4'>
                    <label>Categoría:</label>
                  </div>
                  <div class='col-8' style='text-align: center;'>
                    <select class="form-control select2" id="selectArea" required></select>
                  </div>
                </div>
                <div class="form-group row">
                  <div class='col-4'>
                    <label>Mueble:</label>
                  </div>
                  <div class='col-8' style='text-align: center;'>
                    <select class="form-control select2" id="selectObjeto" name="ObjCompID" required></select>
                  </div>
                </div>
                <div class="form-group row">
                  <div class='col-4'>
                    <label>Cantidad:</label>
                  </div>
                  <div class='col-8' style='text-align: center;'>
                    <input type="number" value="1" step="any" min="1" id="inputCantidad" name="Cantidad" class="form-control" oninput="NotNegatives(this)" required>
                  </div>
                </div>
                <div class="form-group row">
                  <div class='col-4'>
                    <label>Referencia:</label>
                  </div>
                  <div class='col-8' style='text-align: center;'>
                    <input type="text" id="inputReferencia" maxlength="30" name="Referencia" class="form-control" autocomplete="false" required>
                  </div>
                </div>
                <div class="form-group row">
                  <div class="offset-md-6 col-2">
                    <button type="button" class="btn btn-default btn-flat btn-sm" id="btnCerrarAgregarObjeto">Cerrar</button>
                  </div>
                  <div class="col-4">
                    <button type="submit" class="btn btn-info btn-sm btn-flat btn-block" id="btnGuardarObjeto">
                      Agregar
                    </button>
                  </div>
                </div>
              </div>
              <div class="col-6" style="height: 385px ;overflow: auto;">
                <h5 style="text-align:center; font-weight: bold;">Parámetros</h5>
                <div class="row">
                  <div class="col-12" style="text-align:center;width: 100%;">
                    <table id="tablaParametrosMueble" class="table table-bordered table-sm" style="width:100%; font-size: 13px;">
                      <thead>
                        <tr>
                          <th>Parámetro</th>
                          <th>Valor</th>
                          <th>Unidad</th>
                        </tr>
                      </thead>
                      <tbody id="bodyParametrosMueble"></tbody>
                    </table>
                  </div>
                </div>
              </div>
            </div>
          </form>
        </div>
      </div>
    </div>
  </div>

  <!--MODAL MODIFICAR PARAMETROS-->
  <div class="modal" id="modalParametros" role="dialog" aria-labelledby="myModalLabels">
    <div class="modal-dialog modal-lg modal-dialog-centered" role="document">
      <div class="modal-content" style="text-align:center;">
        <form id="FormUpdPar">
          <div class="modal-body" style="height: auto;">
            <div class="form-group row">
              <div class="offset-md-2 col-4">
                <label>Selecciona parámetro</label>
                <select class="form-control select2" id="selectParametrosCotizacion" onchange="changeParametros()"></select>
              </div>
              <div class="col-4" id="divModificarTodos">
                <label>Modificar todos</label>
                <select class="form-control select2" id="selectTodos"></select>
              </div>
            </div>
            <div class="form-group row" style="height: 335px; overflow: auto;">
              <div class="col-12">
                <table id="tablaDPar" class="table table-bordered table-sm" style="width:100%; font-size: 13px;">
                  <thead>
                    <tr>
                      <th>Mueble</th>
                      <th>Referencia</th>
                      <th>Cantidad</th>
                      <th>Unidad</th>
                      <th>Concepto</th>
                    </tr>
                  </thead>
                  <tbody id="BodyBPar"></tbody>
                </table>
              </div>
            </div>
          </div>
          <div class="modal-footer">
            <button type="submit" class="btn btn-primary btn-flat btn-sm" id="btnUpdPar">
              Aceptar
            </button>
          </div>
        </form>
      </div>
    </div>
  </div>

  <!--MODAL PARAMETRO IMPORTADO-->
  <div class="modal" id="modalParametros2" role="dialog" aria-labelledby="myModalLabels">
    <div class="modal-dialog modal-lg modal-dialog-centered" role="document">
      <div class="modal-content" style="text-align:center;">
        <form id="FormUpdPar2">
          <div class="modal-body" style="height: 450px;">
            <div class="form-group row">
              <div class="offset-md-2 col-4">
                <label>Selecciona parámetro</label>
                <select class="form-control select2" id="selectParametrosCotizacion2" disabled></select>
              </div>
              <div class="col-4" id="divModificarTodos2">
                <label>Modificar todos</label>
                <select class="form-control select2" id="selectTodos2"></select>
              </div>
            </div>
            <div class="form-group row" style="height: auto; overflow: auto;">
              <div class="col-12">
                <table id="tablaDPar2" class="table table-bordered table-sm" style="width:100%; font-size: 13px;">
                  <thead>
                    <tr>
                      <th>Mueble</th>
                      <th>Referencia</th>
                      <th>Cantidad</th>
                      <th>Unidad</th>
                      <th>Concepto</th>
                    </tr>
                  </thead>
                  <tbody id="BodyBPar2"></tbody>
                </table>
              </div>
            </div>
          </div>
          <div class="modal-footer">
            
          </div>
        </form>
        <button class="btn btn-primary btn-flat btn-sm" id="btnUpdPar2">
              Siguiente
            </button>
      </div>
    </div>
  </div>

  <!--MODAL VER OBJETO-->

  <div class="modal" id="modalVerObjeto" role="dialog" aria-labelledby="myModalLabels">

    <div class="modal-dialog modal-lg modal-dialog-centered" role="document">

      <div class="modal-content" style="text-align:center">

        <div class="modal-body">

         <h3 style="text-align:center" id="lblCotizacion"></h3><br>

         <div class="row">

          <div class="col-6">

            <h5 style="font-weight: bold;">Información del mueble</h5>

            <div class="form-group row">

              <div class="col-6">

                <label>Categoría</label><br>

                <label style="font-weight: normal;" id="lblCategoria"></label>

              </div>

              <div class="col-6">

                <label>Mueble</label><br>

                <label style="font-weight:normal" id="lblMueble"></label>

              </div>

            </div>

            <div class="form-group row">

              <div class="col-6">

                <label>Cantidad</label><br>

                <label style="font-weight: normal;" id="lblCantidad"></label>

              </div>

              <div class="col-6">

                <label>Referencia</label><br>

                <label style="font-weight: normal;" id="lblReferencia"></label>

              </div>

            </div>

          </div>

          <div class="col-6">

            <div class="form-group row">

              <div class="col-12">

                <table id="tablaParametrosDetalle" class="table table-bordered table-sm" style="width:100%; font-size: 13px">

                  <thead>

                    <tr>

                      <th>Parámetro</th>

                      <th>Valor</th>

                    </tr>

                  </thead>

                  <tbody id="bodyParametrosDetalle"></tbody>

                </table>

              </div>

            </div>

          </div>

        </div>

      </div>

      <div class="modal-footer">

        <button type="button" class="btn btn-default btn-flat btn-sm" data-dismiss="modal">Cerrar</button>

      </div>

    </div>

  </div>

</div>



<!--MODAL DUPLICAR COTIZACIÓN-->

<div class="modal" id="modalDuplicaCotizacion" role="dialog" aria-labelledby="myModalLabels">

  <div class="modal-dialog modal-dialog-centered" role="document">

    <div class="modal-content">

      <div class="modal-body">

        <div class="row">

          <div class="col-12" style="text-align: center;">

            <label>Indique el nombre de la nueva cotización duplicada</label>

            <input type="text" class="form-control flat-input" id="inputCotDuplicada">

          </div>

        </div>

      </div>

      <div class="modal-footer">

        <button type="button" data-toggle="tooltip" title="" class="btn btn-default btn-flat btn-sm" data-dismiss="modal">Cancelar</button>

        <button type="button" id="btnGuardarCotDuplicada" class="btn btn-success btn-flat btn-sm">Guardar</button>

      </div>

    </div>

  </div>

</div>

<?php include("scripts.php"); ?>
<script src="https://cdnjs.cloudflare.com/ajax/libs/xlsx/0.16.9/xlsx.full.min.js"></script>
<script type="text/javascript" src="scripts/cotizaciones.js" defer></script>

</body>
<script>

$(document).ready(function() {
            $("#btnNuevaCotizacion").click(function(){
                $("#pass_cupon").val('');  // Limpiar el campo de contraseña
                $("#importar_csv").css('display', 'block');
                $("#cupon").css('display', 'block');
                $("#importar_csv").addClass('show');  // Agregar la clase .show para mostrar el div
                $("#cupon").addClass('show');  // Agregar la clase .show para mostrar el div
                console.log('Button clicked');
            });
            
            $(document).on('click', '#verco', function() {
        var selectedValue = $('#selectStatus').val(); // Obtiene el valor seleccionado
        console.log('Selected value:', selectedValue);

        if (selectedValue === "Diseño") {
            $("#importar_csv").css('display', 'block');
            $("#cupon").css('display', 'block');
            $("#importar_csv").addClass('show');  // Agregar la clase .show para mostrar el div
            $("#cupon").addClass('show');  // Agregar la clase .show para mostrar el div
            console.log('Button clicked22');
        } else {
            $("#importar_csv").css('display', 'none');
            $("#cupon").css('display', 'none');
            $("#importar_csv").removeClass('show');  // Quitar la clase .show para ocultar el div
            $("#cupon").removeClass('show');  // Quitar la clase .show para ocultar el div
            console.log('Button clicked 2');
        }
    });
});
</script>
</html>

