<?php
include("session.php");
?>
<!DOCTYPE html>
<html>


  <?php

   include("head.php"); ?>
<body>
    <div id="wrapper">
       <?php
        include ("menu.php");
       ?>

        <div id="page-wrapper" class="gray-bg dashbard-1">
        <div class="row border-bottom">
        <nav class="navbar navbar-static-top" role="navigation" style="margin-bottom: 0">
        <div class="navbar-header">
            <a class="navbar-minimalize minimalize-styl-2 btn btn-primary " href="#"><i class="fa fa-bars"></i> </a>
            
        </div>
            <ul class="nav navbar-top-links navbar-right">

                <li>
                    <a href="index.php">
                    
                        <i class="fa fa-sign-out"></i> Salir
                    </a>
                </li>
                
            </ul>

        </nav>
        </div>
               
        <div class="row">
            <div class="col-lg-12">
                 <div class="ibox float-e-margins">
                    
                            <div class="ibox-title">
                                <div class="pull-right">
                                     <?php 
                                             if ($_SESSION["roles"]==1 || $_SESSION["roles"]==2) {
                                             ?>   
                                <button class="btn btn-primary" data-toggle="modal" data-target="#myModal">Nuevo Item</button>
                                   <?php 
                                            }
                                             ?>   
                                </div>
                                <h5>Registro de Items</h5>
                                
                            </div>
                            <div class="ibox-content">
                                
                                <div class="table-responsive">
                                    <table class="table table-striped table-hover dataTables-example">
                                        <thead style="color: #1f51a3">
                                        <tr>

                                            <th>Nombre</th>
                                            <th>Ancho</th>
                                            <th>Peso</th>
                                            <th>Rendimiento</th>
                                            <th>U.M</th>
                                            <th>Composición</th>
                                            <th>Ligamento</th>
                                            <th>Contrucción</th>
                                            <th>Teñido</th>
                                            <th>Remark</th>
                                            <th>Cap. 40HQ</th>
                                            <th>Posición Arancelaria</th>
                                            <th>Precio Compra</th>
                                            <th>Precio Venta</th>
                                            <th>Factor</th>
                                            <th>Financiero</th>
                                            <th>Pais Origen</th>


                                             <?php 
                                             if ($_SESSION["roles"]==1 || $_SESSION["roles"]==2) {
                                             ?>                  
                                            <th>Editar</th>

                                            <?php if ($_SESSION["roles"]==1) {
                                              ?>
                                            <th>Eliminar</th>

                                            <?php
                                          }
                                          }
                                          ?>
                                            </tr>
                                        </thead>
                                        <tbody style="font-weight: bold;">
                                             <?php 
                                             include("conexion.php");
                                             


     $query="SELECT `id_ref`, `nombre_ref`, `ancho_ref`, `peso_ref`, `rendi_ref`, `um_ref`, `comp_ref`, `const_ref`, `cap_ref`, `prec_venta`, `prec_comp`, `posi_aranc`, `tejido_ref`, `ligamento_ref`, `acabdado_ref`, `pais_origen`, `cod_ref`, `factor`, `financiero`,tenido_ref FROM `referencias`";
    $resultadoc=$conexion->query($query);
           while ($rowc=$resultadoc->fetch_assoc()) {


                                                ?>
                                        <tr style="font-size: 10px">

                                            <td><?php echo $rowc['nombre_ref']; ?></td>
                                            <td><?php echo $rowc['ancho_ref'];?></td>
                                            <td><?php echo $rowc['peso_ref'];?></td>
                                            <td><?php echo number_format($rowc['rendi_ref'],2,",",".");?></td>
                                            <td><?php echo $rowc['um_ref'];?></td>

                                            <td><?php echo $rowc['comp_ref'];?></td>
                                            <td><?php echo $rowc['ligamento_ref'];?></td>
                                            <td><?php echo $rowc['const_ref'];?></td>
                                            <td><?php echo $rowc['tenido_ref'];?></td>
                                            <td><?php echo $rowc['acabdado_ref'];?></td>

                                            <td><?php echo $rowc['cap_ref'];?></td>
                                            <td><?php echo $rowc['posi_aranc'];?></td>
                                            <td><?php echo $rowc['prec_comp'];?></td>
                                            <td><?php echo $rowc['prec_venta'];?></td>
                                            <td><?php echo $rowc['factor'];?></td>
                                            <td><?php echo $rowc['financiero'];?></td>

                                            <td><?php echo $rowc['pais_origen'];?>
                                                       </td>
                                             <?php 
                                             if ($_SESSION["roles"]==1 || $_SESSION["roles"]==2) {
                                             ?>                  
                                           <td><a href="referencias.php?id=<?php echo $rowc['id_ref'] ?>"><i class="fa fa-pencil"></i></a></td>

                                            <?php if ($_SESSION["roles"]==1) {
                                              ?>
                                            <td><a href="elim_referencias.php?id=<?php echo $rowc['id_ref'] ?>"><i class="fa fa-trash"></i></a></td>

                                            <?php
                                          }
                                          }
                                          ?>
                                            
                                            
                                        </tr>

                                         <?php 
}
                     ?>
                                        </tbody>
                                    </table>
                                </div>

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

        
              
        <?php include("footer.php"); ?>
</div>
      
        
 <!-- MODAL -->  
   
  <div class="modal inmodal" id="myModal" tabindex="-1" role="dialog" aria-hidden="true">
                                
                                <form enctype="multipart/form-data" class="form-horizontal" action="<?php 
                                  if (isset($_GET['id'])) {
                                                    echo "act_referencias.php";
                                             }
                                             else
                                             {
                                                echo "reg_referencias.php";
                                             }
                                              ?>" method="POST" name="formulario" >
                                    <div class="modal-dialog">
                                    <div class="modal-content animated bounceInRight">
                                            <div class="modal-header" style="text-align: left">
                                                <a href="referencias.php"><button type="button" class="close"><span aria-hidden="true">×</span><span class="sr-only">Close</span></button></a>
                                                
                                                 <h4 class="modal-title"><img alt="Logo" src="img/logo.png" height="10%" width="10%">Item</h4>
                                                <!-- <small class="font-bold">Lorem Ipsum is simply dummy text of the printing and typesetting industry.</small> -->
                                            </div>
                                            <div class="modal-body">
                                               
                                               <?php
$id_ref=0;
                                                if (isset($_GET['id'])) {
                                                    $id_ref=$_GET['id'];
                                                   
                                             }  

                                             



                                                  $query="SELECT `id_ref`, `nombre_ref`, `ancho_ref`, `peso_ref`, `rendi_ref`, `um_ref`, `comp_ref`, `const_ref`, `cap_ref`, `prec_venta`, `prec_comp`, `posi_aranc`, `tejido_ref`, `ligamento_ref`, `acabdado_ref`, `pais_origen`, `cod_ref`, factor, financiero,tenido_ref FROM `referencias` where  id_ref='$id_ref'";
    $resultadoc=$conexion->query($query);
     $rowx=$resultadoc->fetch_assoc();


?>                                        

                            <div class="form-group">

                         <div class="row">
                            
                              <div class="col-sm-9">
                              <label>Nombre de la Referencia</label>
                            <input  type="text" placeholder="" class="form-control" name="nombre_ref" value="<?php echo $rowx['nombre_ref'] ;?>">
                            <input type="hidden" placeholder="Ingresa login" class="form-control" name="id_ref" value="<?php echo $rowx['id_ref'] ;?>" >
                            </div>
                             <div class="col-sm-3">
                                <label>Pais de Origen</label>
                                <input  type="text" placeholder="" class="form-control" name="pais_origen" value="<?php if ($rowx['pais_origen']=="") { echo "China"; } else {echo $rowx['pais_origen'] ;}?>">
                          </div>

                          </div>


                            <div class="row">
                              <div class="col-sm-3">
                                <label>Ancho</label>
                                <input  type="text" placeholder="" onkeyup="calc_rend();" class="form-control" id="ancho_ref"  name="ancho_ref" value="<?php echo $rowx['ancho_ref'] ;?>">
                          </div>
                          <div class="col-sm-3">
                                <label>Peso</label>
                                <input  type="text" onkeyup="calc_rend();" placeholder="" class="form-control" id="peso_ref" name="peso_ref" value="<?php echo $rowx['peso_ref'] ;?>">
                          </div>
                          <div class="col-sm-3">
                                <label>Redimiento</label>
                                <input  type="text" placeholder="" class="form-control" id="rendi_ref" name="rendi_ref" value="<?php echo $rowx['rendi_ref'] ;?>">
                          </div>
                          <div class="col-sm-3">
                                <label>U.M.</label>
                                <input  type="text" placeholder="" onkeyup="calc_rend();" class="form-control" name="um_ref" id="um_ref" value="<?php echo $rowx['um_ref'] ;?>">
                          </div>
                          </div>

                           <div class="row">
                              <div class="col-sm-3">
                                <label>Composición</label>
                                <input  type="text" placeholder="" class="form-control" name="comp_ref" value="<?php echo $rowx['comp_ref'] ;?>">
                          </div>
                            <div class="col-sm-3">
                                <label>Ligamento</label>
                                <input  type="text" placeholder="" class="form-control" name="ligamento_ref" value="<?php echo $rowx['ligamento_ref'] ;?>">
                          </div>
                          <div class="col-sm-3">
                                <label>Construcción</label>
                                <input  type="text" placeholder="" class="form-control" name="const_ref" value="<?php echo $rowx['const_ref'] ;?>">
                          </div>
                           <div class="col-sm-3">
                                <label>Teñido</label>
                                <input  type="text" placeholder="" class="form-control" name="tenido_ref" value="<?php echo $rowx['tenido_ref'] ;?>">
                          </div>
                         
                          </div>

                           <div class="row">
                            <div class="col-sm-4">
                                <label>Cap. Max. 40HQ</label>
                                <input  type="number" placeholder="" class="form-control" name="cap_ref" value="<?php echo $rowx['cap_ref'] ;?>">
                          </div>
                          <div class="col-sm-4">
                                <label>Remark</label>
                                <select class="form-control" name="acabdado_ref" id="acabdado_ref">
                                                                   <option value="">Seleccione</option>
                                                                                      <?php
                                         $queryc="SELECT `id_remarks`, `nombre_remarks` FROM `remarks`  order by nombre_remarks asc";
                                        $resultadoc=$conexion->query($queryc);
                                        while ($rowc=$resultadoc->fetch_assoc()) {
                                            if ($rowc['nombre_remarks']==$rowx["acabdado_ref"]) {
                                              echo "<option selected value='".$rowc['nombre_remarks']."'>".$rowc['nombre_remarks'] ."</option>";
                                            }
                                            else
                                            {
                                       echo "<option  value='".$rowc['nombre_remarks']."'>".$rowc['nombre_remarks'] ."</option>";
                                      }
                                        };

                                                                   ?>

                                                                 
                                                                </select>
                             
                          </div>
                          <div class="col-sm-4">
                                <label>Posicion Arancelaria</label>
                                <input  type="text" placeholder="" class="form-control" name="posi_aranc" value="<?php echo $rowx['posi_aranc'] ;?>">
                          </div>
                          
                          </div>
                           </div>


<div class="form-group">

                          <div class="row">
                              
                          <div class="col-sm-2">
                          </div>
                          <div class="col-sm-4">
                                <label>Precio Compra $</label>
                                <input  type="text" placeholder="" class="form-control" id="prec_comp" name="prec_comp" value="<?php echo $rowx['prec_comp'] ;?>">
                          </div>
                          <div class="col-sm-4">
                                <label>Precio Venta $</label>
                                <input  type="text" placeholder="" class="form-control" id="prec_venta" name="prec_venta" value="<?php echo $rowx['prec_venta'] ;?>">
                          </div>
                          <div class="col-sm-2">
                          </div>
                         
                        
                          </div>



                            </div>

                            <div class="form-group">

                          <div class="row">
                              
                          <div class="col-sm-2">
                          </div>
                          <div class="col-sm-4">
                                <label>Factor</label>
                                <input  type="text" placeholder="" class="form-control" id="factor" name="factor" value="<?php echo $rowx['factor'] ;?>">
                          </div>
                          <div class="col-sm-4">
                                <label>Financiero</label>
                                <input  type="text" placeholder="" class="form-control" id="financiero" name="financiero" value="<?php echo $rowx['financiero'] ;?>">
                          </div>
                          <div class="col-sm-2">
                          </div>
                         
                        
                          </div>



                            </div>
                                                       
                           
                                             

                                               
                                                

                                            </div>
                                            <div class="modal-footer">
                                                <a href="referencias.php"><button type="button" class="btn btn-white">Cerrar</button></a>
                                                <button type="submit" class="btn btn-primary">Guardar cambios</button>
                                            
                                            </div>
                                        </div>
                                    </div>
                                </form>
                            </div>
 <!-- MODAL -->
    </div>
    <?php include("script.php"); ?>

       <script type="text/javascript">
           <?php
                    if (isset($_GET['id'])) {
                    ?>
                    $('#myModal').modal('show');
                      <?php                       }  
           ?>


          
       </script>
</body>
</html>