<?php
  $page_title = 'CONFIGURACION';
  require_once('../../includes/load.php');
?>
<?php
// Checkin What level user has permission to view this page
 page_require_level(1);
?>
<?php
  if(isset($_POST['vehiculo'])){
   if(empty($errors)){
      $placa   = remove_junk($db->escape($_POST['placa']));
      $SoatCostoA   = remove_junk($db->escape($_POST['SoatCostoA']));
      $SoatCostoM   = $SoatCostoA/12;

      $GpsCostoA   = remove_junk($db->escape($_POST['GpsCostoA']));
      $GpsCostoM   = $GpsCostoA/12;

      $RevtecCostoA   = remove_junk($db->escape($_POST['RevtecCostoA']));
      $RevtecCostoM   = $RevtecCostoA/12;

      $DepreCostoM   = remove_junk($db->escape($_POST['DepreCostoM']));

      $NeumaConcepto   = remove_junk($db->escape($_POST['NeumaConcepto']));
      $NeumaMonto   = remove_junk($db->escape($_POST['NeumaMonto']));
      $NeumaCostokm   = $NeumaMonto/60000;


      $OperaSueldo   = remove_junk($db->escape($_POST['OperaSueldo']));
      $OperaAsigF   = remove_junk($db->escape($_POST['OperaAsigF']));
      $OperaCts   = (($OperaSueldo + $OperaAsigF + ($OperaSueldo*0.09))/2)/6;
      $OperaGrati   = ($OperaSueldo + $OperaAsigF + ($OperaSueldo*0.09))/6;
      $OperaEssalud   = $OperaSueldo*0.09;
      $OperaHE   = remove_junk($db->escape($_POST['NeumaMonto']));
      $OperaTotal   = $OperaSueldo + ((($OperaSueldo + $OperaAsigF + ($OperaSueldo*0.09))/2)/6) +
    (($OperaSueldo + $OperaAsigF + ($OperaSueldo*0.09))/6) + $OperaAsigF + ($OperaSueldo*0.09) + $OperaHE;

      $ImpCostoM   = remove_junk($db->escape($_POST['ImpCostoM']));

      $created_at=date("Y-m-d H:i:s");

   


      $querySoat ="INSERT INTO tb_configuracion_soat(placa1, costo_anual1, costo_mensual1, created_at) VALUES ('{$placa }','{$SoatCostoA }','{$SoatCostoM }','{$created_at}')";

      $queryGPS="INSERT INTO tb_configuracion_gps(placa3, costo_anual3, costo_mensual3, created_at) VALUES ('{$placa }','{$GpsCostoA }','{$GpsCostoM }','{$created_at}')";

      $queryRevision ="INSERT INTO tb_configuracion_revisiontecnica(placa5, costo_anual5, costo_mensual5, created_at) VALUES ('{$placa }','{$RevtecCostoA }','{$RevtecCostoM }','{$created_at}')";

      $queryDepresacion ="INSERT INTO tb_configuracion_depreciacion(placa2, costo_mensual2, created_at) VALUES ('{$placa }','{$DepreCostoM }','{$created_at}')";

      $queryNeumatico ="INSERT INTO tb_configuracion_costoneumatico(placa6, concepto, monto, costokm, created_at) VALUES ('{$placa }','{$NeumaConcepto }','{$NeumaMonto }','{$NeumaCostokm }','{$created_at}')";

      $querySueldo ="INSERT INTO tb_configuracion_sueldooperaciones(placa7, sueldo, asignacion_fam, cts, gratificacion, essalud, horas_extras, total, created_at) VALUES ('{$placa }','{$OperaSueldo }','{$OperaAsigF }','{$OperaCts }','{$OperaGrati }','{$OperaEssalud }','{$OperaHE }','{$OperaTotal }','{$created_at}')";

      $queryImpVehicular ="INSERT INTO tb_configuracion_impvehicular(placa4, costo_mensual4, created_at) VALUES ('{$placa }','{$ImpCostoM }','{$created_at}')";

      $query1=$db->query($querySoat);
      $query2=$db->query($queryGPS);
      $query3=$db->query($queryRevision);
      $query4=$db->query($queryDepresacion);
      $query5=$db->query($queryNeumatico);
      $query6=$db->query($querySueldo);
      $query7=$db->query($queryImpVehicular);

 

      if($query1 && $query2 && $query3 && $query4 && $query5 && $query6 && $query7){
        //sucess
        $session->msg('s'," La Configuración de VEHICULO ha sido Actualizada");
        redirect('vehiculos.php', false);
      } else {
        //failed
        $session->msg('d',' No se pudo Actualizar Configuración de VEHICULO');
        redirect('vehiculos.php', false);
      }
   }else {
   $session->msg("d", $errors);
    redirect('vehiculos.php',false);
 }
}
?>
<?php include_once('../../layouts/header.php'); ?>
<div class="col-md-12">
   <?php echo display_msg($msg); ?>
</div>
 <form method="post" action="vehiculos.php">
    <div class="row mb-3">
        <div class="col-12">
            <p class="text-center h2">CONFIGURACIÓN VEHICULO</p>
        </div>
    </div>

    <div class="row d-flex justify-content-center pt-3">
        <div class="col-12 col-md-4">
          <div class="input-group">
            <select class="custom-select is-requerido" id="placa" name="placa" required>
                  <option value="" disabled selected>Seleccione</option>
                  <?php   
                    $consulta = $db->query("SELECT * FROM vehiculo ORDER BY id DESC");
                      while ($row = $db->fetch_assoc($consulta)) {   
                        $Placa = $row['PLACA'];    
                        echo "<option value='$Placa'>$Placa</option>";
                      }
                  ?>
            </select>
            <div class="input-group-append">
              <button class="btn btn-outline-secondary" type="button" id="buscar" name="buscar">Buscar</button>
            </div>
          </div>
        </div>
    </div>
    <div class="col-12 px-4 pt-3">
        <div class="container-fluid">
          <div class="row mb-3">
                <div class="col-6">
                  <div class="card">
                    <div class="card-header">
                      <h5 class="card-title mb-3">SOAT</h5>
                    </div>
                    <div class="card-body">
                      <div class="row mb-3">
                        <div class="col-12 col-lg-12">
                          <div class="form-group row">
                            <label for="SoatCostoA" class="col-sm-6 col-form-label text-primary ">COSTO ANUAL</label>
                            <div class="col-sm-6">
                              <input type="number" class="form-control" id="SoatCostoA" name="SoatCostoA" placeholder="number" step="any">
                            </div>
                          </div>
                        </div>
                      </div>
                      <div class="row mb-3">
                        <div class="col-12 col-lg-12">
                          <div class="form-group row">
                            <label for="SoatCostoM" class="col-sm-6 col-form-label text-primary ">COSTO MENSUAL</label>
                            <div class="col-sm-6">
                              <input type="number" class="form-control" id="SoatCostoM" name="SoatCostoM" placeholder="number" step="any" disabled>
                            </div>
                          </div>
                        </div>
                      </div>
          
                    </div>
          
                  </div>
          
          
                </div>
                <div class="col-6">
                  <div class="card">
                    <div class="card-header">
                      <h5 class="card-title mb-3">GPS</h5>
                    </div>
                    <div class="card-body">
                      <div class="row mb-3">
                        <div class="col-12 col-lg-12">
                          <div class="form-group row">
                            <label for="GpsCostoA" class="col-sm-6 col-form-label text-primary ">COSTO ANUAL </label>
                            <div class="col-sm-6">
                              <input type="number" class="form-control" id="GpsCostoA" name="GpsCostoA" placeholder="number" step="any">
                            </div>
                          </div>
                        </div>
                      </div>
                      <div class="row mb-3">
                        <div class="col-12 col-lg-12">
                          <div class="form-group row">
                            <label for="GpsCostoM" class="col-sm-6 col-form-label text-primary ">COSTO MENSUAL</label>
                            <div class="col-sm-6">
                              <input type="number" class="form-control" id="GpsCostoM" name="GpsCostoM" placeholder="number" step="any" disabled>
                            </div>
                          </div>
                        </div>
                      </div>
          
                    </div>
                  </div>
                </div>
            </div>
        </div>
    </div>

    <div class="col-12 px-4 pt-3">
      <div class="container-fluid">
        <div class="row mb-3">
          <div class="col-6">
            <div class="card">
              <div class="card-header">
                <h5 class="card-title mb-3">REVISION TECNICA</h5>
              </div>
              <div class="card-body">
                <div class="row mb-3">
                  <div class="col-12 col-lg-12">
                    <div class="form-group row">
                      <label for="RevtecCostoA" class="col-sm-6 col-form-label text-primary ">COSTO ANUAL</label>
                      <div class="col-sm-6">
                        <input type="number" class="form-control" id="RevtecCostoA" name="RevtecCostoA" placeholder="number" step="any">
                      </div>
                    </div>
                  </div>
                </div>
                <div class="row mb-3">
                  <div class="col-12 col-lg-12">
                    <div class="form-group row">
                      <label for="RevtecCostoM" class="col-sm-6 col-form-label text-primary ">COSTO
                        MENSUAL</label>
                      <div class="col-sm-6">
                        <input type="number" class="form-control" id="RevtecCostoM" name="RevtecCostoM" placeholder="number" step="any" disabled>
                      </div>
                    </div>
                  </div>
                </div>

              </div>

            </div>


          </div>
          <div class="col-6">
            <div class="card">
              <div class="card-header">
                <h5 class="card-title mb-3">DEPRECIACIÓN</h5>
              </div>
              <div class="card-body">

                <div class="row mb-3">
                  <div class="col-12 col-lg-12">
                    <div class="form-group row">
                      <label for="DepreCostoM" class="col-sm-6 col-form-label text-primary ">COSTO
                        MENSUAL</label>
                      <div class="col-sm-6">
                        <input type="number" class="form-control" id="DepreCostoM" name="DepreCostoM" placeholder="number" step="any">
                      </div>
                    </div>
                  </div>
                </div>
                <br>
                <br>
              </div>
            </div>
          </div>
          </div>
      </div>
    </div>
    <div class="col-12 px-4 pt-3">
        <div class="container-fluid">
          <div class="row mb-3">
                <div class="col-6">
                  <div class="card">
                    <div class="card-header">
                      <h5 class="card-title mb-3">COSTO DE NEUMATICOS</h5>
                    </div>
                    <div class="card-body">
                      <div class="row mb-3">
                        <div class="col-12 col-lg-12">
                          <div class="form-group row">
                            <label for="NeumaConcepto"
                              class="col-sm-6 col-form-label text-primary ">CONCEPTO</label>
                            <div class="col-sm-6">
                              <input type="text" class="form-control" id="NeumaConcepto" name="NeumaConcepto" placeholder="number" step="any">
                            </div>
                          </div>
                        </div>
                      </div>
                      <div class="row mb-3">
                        <div class="col-12 col-lg-12">
                          <div class="form-group row">
                            <label for="NeumaMonto" class="col-sm-6 col-form-label text-primary ">MONTO</label>
                            <div class="col-sm-6">
                              <input type="number" class="form-control" id="NeumaMonto" name="NeumaMonto" placeholder="number" step="any">
                            </div>
                          </div>
                        </div>
                      </div>
                      <div class="row mb-3">
                        <div class="col-12 col-lg-12">
                          <div class="form-group row">
                            <label for="NeumaCostokm"
                              class="col-sm-6 col-form-label text-primary ">COSTO/KM</label>
                            <div class="col-sm-6">
                              <input type="number" class="form-control" id="NeumaCostokm" name="NeumaCostokm" placeholder="number" step="any" disabled >
                            </div>
                          </div>
                        </div>
                      </div>
                        <br>
                        <br>
                        <br>
                        <br> 
                        <br>
                        <br>
                        <br>
                        <br>
                    </div>  
                  </div>
                </div>
                <div class="col-6">
                  <div class="card">
                    <div class="card-header">
                      <h5 class="card-title mb-3">SUELDO OPERACIONES</h5>
                    </div>
                    <div class="card-body">
                      <div class="row mb-3">
                        <div class="col-12 col-lg-12">
                          <div class="form-group row">
                            <label for="OperaSueldo"
                              class="col-sm-6 col-form-label text-primary ">SUELDO</label>
                            <div class="col-sm-6">
                              <input type="number" class="form-control" id="OperaSueldo" name="OperaSueldo" placeholder="number" step="any">
                            </div>
                          </div>
                        </div>
                      </div>
                      <div class="row mb-3">
                        <div class="col-12 col-lg-12">
                          <div class="form-group row">
                            <label for="OperaAsigF" class="col-sm-6 col-form-label text-primary ">ASIGNACION
                              FAMILIAR</label>
                            <div class="col-sm-6">
                              <input type="number" class="form-control" id="OperaAsigF" name="OperaAsigF" placeholder="number" step="any">
                            </div>
                          </div>
                        </div>
                      </div>
                      <div class="row mb-3">
                        <div class="col-12 col-lg-12">
                          <div class="form-group row">
                            <label for="OperaCts" class="col-sm-6 col-form-label text-primary ">CTS</label>
                            <div class="col-sm-6">
                              <input type="number" class="form-control" id="OperaCts" name="OperaCts" placeholder="number" step="any" readonly> 
                            </div>
                          </div>
                        </div>
                      </div>
                      <div class="row mb-3">
                        <div class="col-12 col-lg-12">
                          <div class="form-group row">
                            <label for="OperaGrati"
                              class="col-sm-6 col-form-label text-primary ">GRATIFICACION</label>
                            <div class="col-sm-6">
                              <input type="number" class="form-control" id="OperaGrati" name="OperaGrati" placeholder="number" step="any" readonly>
                            </div>
                          </div>
                        </div>
                      </div>
                      <div class="row mb-3">
                        <div class="col-12 col-lg-12">
                          <div class="form-group row">
                            <label for="OperaEssalud"
                              class="col-sm-6 col-form-label text-primary ">ESSALUD</label>
                            <div class="col-sm-6">
                              <input type="number" class="form-control" id="OperaEssalud" name="OperaEssalud" placeholder="number" step="any" readonly>
                            </div>
                          </div>
                        </div>
                      </div>
                      <div class="row mb-3">
                        <div class="col-12 col-lg-12">
                          <div class="form-group row">
                            <label for="OperaHE" class="col-sm-6 col-form-label text-primary ">HORAS
                              EXTRAS</label>
                            <div class="col-sm-6">
                              <input type="number" class="form-control" id="OperaHE" name="OperaHE" placeholder="number" step="any">
                            </div>
                          </div>
                        </div>
                      </div>
                      <div class="row mb-3">
                        <div class="col-12 col-lg-12">
                          <div class="form-group row">
                            <label for="OperaTotal" class="col-sm-6 col-form-label text-primary ">TOTAL</label>
                            <div class="col-sm-6">
                              <input type="number" class="form-control" id="OperaTotal" name="OperaTotal" placeholder="number" step="any" readonly>
                            </div>
                          </div>
                        </div>
                      </div>

                    </div>
                  </div>
                </div>
            </div>
        </div>
    </div>

    <div class="col-12 px-4 pt-3">
      <div class="container-fluid">
        <div class="row mb-3">
          <div class="col-6">
            <div class="card">
              <div class="card-header">
                <h5 class="card-title mb-3">IMPUESTO VEHICULAR</h5>
              </div>
              <div class="card-body">
                <div class="row mb-3">
                  <div class="col-12 col-lg-12">
                    <div class="form-group row">
                      <label for="ImpCostoM" class="col-sm-6 col-form-label text-primary ">COSTO
                        MENSUAL</label>
                      <div class="col-sm-6">
                        <input type="number" class="form-control" id="ImpCostoM" name="ImpCostoM" placeholder="number" step="any">
                      </div>
                    </div>
                  </div>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
                      
      <div class="row  pt-4">
        <div class="col-12">
          <button type="submit" class="btn btn-block btn-success" id="vehiculo" name="vehiculo">Actualizar Registros</button>
        </div>
      </div>
</form>

<?php include_once('../../layouts/footer.php'); ?>
<script type="text/javascript" src="js/configuracion_vehiculo.js"></script>