<?php
  include("conexion.php");


$id=$_POST['id'];


 $query="SELECT `orden_pedido` FROM `pedidos_items` WHERE `id_item`='$id'";
    $resultadoc=$conexion->query($query);
    $row1=$resultadoc->fetch_assoc();
$pedido=$row1['orden_pedido'];






 $query="DELETE FROM `pedidos_items` WHERE `id_item`='$id'";
    $resultadoc=$conexion->query($query);



$costo_t=0;
$servicios="";
$i=0;

$consulta="SELECT `id_item`, `orden_pedido`, `descripcion`, `supplier`, `um`, `width`, `weight`, `meter`, `quantity`, `precio_compra`, `price_usd`, `fob`, `cap_hq`, `porc_ocup`, `seis_ocho`, `cent`, `cent_usd`, `com_colim`, `total_com`, `bon_fab`, `total_bon_fab`, `total_ganac`, `fecha_prod`, `remark`, nombre_ref FROM `pedidos_items` inner join  referencias on id_ref=descripcion  where orden_pedido ='$pedido'";
$resultado2=$conexion-> query ($consulta);


     while ($row1=$resultado2->fetch_assoc()){
      $i=$i+1;
      
      $provee1= $row1['supplier'];

      $costo= ($row1['quantity']  * $row1['price_usd']);

    
      $servicios.="<tr>

<td align=center height=25px>".$i."</td>
<td align=center height=25px >".$row1['nombre_ref']."</td>
<td align=center height=25px>".$row1['quantity']."</td>
<td align=right height=25px>".number_format($row1['price_usd'], 2, ',', '.')."</td>
<td align=right height=25px>".number_format($costo, 2, ',', '.')."</td>
<td align=center height=25px><a onclick=elminar_det_pedido(".$row1['id_item'].") ><i class='fa fa-trash'></i></a></td>
</tr>";
$costo_t=$costo_t+$costo;


     }
     echo "<table width='100%' border='1' style='border-collapse: collapse;' class='table table-bordered table-condensed table-hover'>
<tr>
<td align=center width=5% height=30px style='background: rgba(145, 140, 142, 0.15); font-weight: bold;'>#</td>
<td align=center width=45% height=30px style='background: rgba(145, 140, 142, 0.15); font-weight: bold;'>REFERENCIA</td>
<td align=center width=10% height=30px style='background: rgba(145, 140, 142, 0.15); font-weight: bold;'>CANT.</td>
<td align=center width=15% height=30px style='background: rgba(145, 140, 142, 0.15); font-weight: bold;'>V/UNITARIO</td>
<td align=center width=15% height=30px style='background: rgba(145, 140, 142, 0.15); font-weight: bold;'>FOB/TOTAL</td>
<td align=center width=15% height=30px style='background: rgba(145, 140, 142, 0.15); font-weight: bold;'><i class='fa fa-trash'></i></td>
</tr>
 ".$servicios."
<tr>
<td colspan=4 rowspan=3 align=left valign=top ></td>
<td align=center height=30px style='background: rgba(226, 226, 226, 0.15); font-weight: bold;'>TOTAL</td>
<td colspan=2 align=right>". number_format($costo_t, 2, ',', '.')."</td>
</tr>

</table>";

 // header("Location: cotizaciones.php")

?>