<!DOCTYPE html>
<html>
<head>
  <title></title>
  
</head>
<body>
<?php
  require_once("models/config.php");
  if(isUserLoggedIn()) { 
    
  }else{
    header("Location: index.php"); die(); 
  }

$mysqli = new mysqli("localhost", "bdicentralserver_sc", "Myl-PGfSbzcf", "bdicentralserver_sc");
              //no muestra todo
              //$result_pro = $mysqli->query("SELECT p.id, p.SKU,p.MFRPartNumber,p.ProductDescription1, p.disponibilidad, fi.marca AS marca FROM pricefile_mx p INNER JOIN manufacturer_mx fi ON fi.id = p.id_marca WHERE p.id_subcategoria = ".$_GET["id"]." and p.precio > 0 AND (DATEDIFF( now(),updated)) <= 120 AND p.id_marca IN (SELECT manufacturer_id_xref FROM manufacturer_xref_user_mx WHERE user_id = ".$loggedInUser->user_id.")");
              ////////////////////////////////////////////////
              $result_pro = $mysqli->query("SELECT p.precio, p.id, p.SKU,p.MFRPartNumber,p.ProductDescription1, p.disponibilidad, fi.marca AS marca FROM pricefile_mx p INNER JOIN manufacturer_mx fi ON fi.id = p.id_marca WHERE p.id_subcategoria = ".$_GET["id"]." and  (DATEDIFF( now(),updated)) <= 120 AND p.id_marca IN (SELECT manufacturer_id_xref FROM manufacturer_xref_user_mx WHERE user_id = ".$loggedInUser->user_id.")");

?> 
        
            <?php 
            
            echo "<h3>Productos</h3><hr><div style=\"height:500px; overflow:scroll; display:block;\"><table class=\"table table-sm\"><thead><tr><th>No.</th><th>Sku</th><th>Modelo</th><th>Descripción</th><th>Stock</th><th>Marca</th></tr></thead><tbody>";
            $i = 1;
            while ($row = $result_pro->fetch_assoc()) {
                $stock = ($row["disponibilidad"]>0)?$row["disponibilidad"]:0;
                $disabled = ($stock<=0)?"disabled=\"disabled\"":"";
                $typePrecio = (($row["precio"]<=0)?"style=\"background-color:#FF0000\"":"");
                echo "<tr ".$typePrecio.">";
                echo "<td>".$i."</td>";               
                echo "<td>".$row["SKU"]."</td>";
                echo "<td>".$row["MFRPartNumber"]."</td>";
                echo "<td>".utf8_encode($row["ProductDescription1"])."</td>";
                echo "<td>".$stock."</td>";
                echo "<td>".$row["marca"]."</td>";
                echo "</tr>";
                $i++;
            }
            echo "</tbody></table></div>";
         ?>
<script
  src="https://code.jquery.com/jquery-3.4.1.min.js"
  integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo="
  crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/feather-icons/4.9.0/feather.min.js"></script>
<script src="https://cdn.datatables.net/1.10.20/js/jquery.dataTables.min.js"></script>
<script type="text/javascript">
  $( document ).ready(function() {
     $("#agregar-todos").click(function( event ) {
            if($(this).prop("checked") == true){
              var id_subcategoria = $(this).data("id_subcategoria");
              var user_id = $(this).data("user_id");
                $.post( "api.php", { action: "insert_bulk", id_subcategoria: id_subcategoria, user_id :user_id } );
            }      
     });

   });
</script>        
</body>
</html>