<?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">

                                  <div class="row">
                                    <div class="col-md-6">
                                     <?php 
                                             if ($_SESSION["roles"]==1 || $_SESSION["roles"]==2) {
                                             ?>   
                                             <form action="informes.php" method="GET">
                                              <div class="row" style="margin-top: -10px;">
                                                <div class="col-md-6">
                                                  <input type="text" name="orden" class="form-control">
                                                </div>
                                                <div class="col-md-4">
                                                     <button class="btn btn-primary" type="submit"><i class="fas fa-search"></i> Buscar Orden</button>
                                                </div>
                                              </div>
                                
                             
                              </form>
                            </div>
                            <div class="col-md-6" style="margin-top: -10px;">
                          <form action="informes.php" method="GET">
                                              <div class="row" >
                                                <div class="col-md-6">
                                                  <select class="form-control m-b chosen-select" name="cliente" id="cliente" onchange="buscar_nit(this.value)">

                                        <option value="">Seleccione</option>
                                                           <?php
                                                                               include("conexion.php");
                                         $queryc="SELECT * FROM `clientes` where `tipo_tercero`='2'  or `tipo_tercero`='3'  order by nombre asc";
                                        $resultadoc=$conexion->query($queryc);
                                        while ($rowc=$resultadoc->fetch_assoc()) {
                                         
                                       echo "<option  value='".$rowc['id']."'>".$rowc['nombre'] ."</option>";
                                    
                                        };
                                        ?>
                                    </select>
                                   
                                                </div>
                                                <div class="col-md-4">
                                                     <button class="btn btn-primary" type="submit"><i class="fas fa-users-cog"></i> Buscar Cliente</button>
                                                </div>
                                              </div>
                                
                             
                              </form>
                                </div>
                            </div>
                                   <?php 
                                            }
                                             ?>   
                                </div>
<form action="informes_todo.php" method="GET" name="buscaryear" id="buscaryear">
                                <div class="row">
                                  <div class="col-md-4">
                                <h5>Orden Año:  <input autocomplete="off" type="text" size="4" style="border: none; background-color: white; display: inline; font-size: 18px" name="ayo" ondragenter="javascript:document.getElementById('buscaryear').submit()" value="<?php if (isset($_GET['ayo'])) {
                                  echo $_GET['ayo'];
                                }  else echo date(Y)?>" ></h5>

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

                            </div>
                            <div class="ibox-content">
                                
                                <div class="table-responsive">
                                    <table class="table table-striped table-hover dataTables-example" width="100%">
                                        <thead style="color: #ffffff">
                                        <tr>

                                            <th style="background-color: #000000" >ORDEN</th>
                                            <th style="background-color: #000000" >CANTIDAD MT/GR</th>
                                            <th style="background-color: #000000" >TOTAL (USD)</th>
                                            <th style="background-color: #000000" >TOTAL CENT DE MAS (USD)</th>
                                            <th style="background-color: #000000" >TOTAL COMISIONES CLIENTE (USD)</th>
                                            <th style="background-color: #000000" >TOTAL BON.FABRICA (USD)</th>
                                            <th style="background-color: #000000" >TOTAL GANACIA POR ORDEN (USD)</th>

                                            </tr>
                                        </thead>
                                        <tbody style="font-weight: bold;">
                                             <?php 
                         

$total_venta=0;
$total_cap=0;
$total_cent=0;
$total_com_total=0;
$total_bon_fab=0;
$total_ganac_total=0;


$item=$rowc['id_item'];


  $quantity=0;
  $quantity2=0;
$supplier=0;
$um=0;
$width=0;
$weight=0;
$meter=0;
$precio_compra=0;
$price_usd=0;
$fob=0;
$cap_hq=0;
$porc_ocup=0;
$com_colim=0;
$total_com=0;
$bon_fab=0;
$echa_prod=0;
$remark=0;
$fecha=0;


$porc_ocup=0;

$total_venta=0;

$total_cap=0;
$total_comp=0;

$total_cent=0;

$total_com_total=0;
$total_bon_fab=0;
$total_ganac_total=0;



$orden=0;
if (isset($_GET['ayo'])) {
  $ayo=$_GET['ayo'];


}
else
{
    $ayo=date(Y);
}


 $query3="SELECT orden FROM pedidos where fecha_pedido like '%$ayo%' or fecha_final like '%$ayo%' order by id_pedido asc";
//echo $query3;
    $resultadoc3=$conexion->query($query3);
           while ($rowc3=$resultadoc3->fetch_assoc()) {

 $orden=$rowc3['orden'];


     $query="SELECT quantity, precio_compra, price_usd, porc_ocup, seis_ocho, cent, `com_colim`, `bon_fab`, orden, orden_pedido FROM `pedidos_items` inner join pedidos on orden_pedido= pedidos.id_pedido inner join referencias on id_ref=descripcion inner join clientes on id=supplier WHERE orden='$orden' ";
     //echo $query;
    $resultadoc=$conexion->query($query);
           while ($rowc=$resultadoc->fetch_assoc()) {



$item=$rowc['id_item'];


  $quantity=$rowc['quantity'];
  $quantity2=$quantity2+$rowc['quantity'];
$supplier=$rowc['nombre'];
$um=$rowc['um'];
$width=$rowc['width'];
$weight=$rowc['weight'];
$meter=$rowc['meter'];
$precio_compra=$rowc['precio_compra'];
$price_usd=$rowc['price_usd'];
$fob=$rowc['fob'];
$cap_hq=$rowc['cap_hq'];
$porc_ocup=$rowc['porc_ocup'];
$com_colim=$rowc['com_colim'];
$total_com=$rowc['total_com'];
$bon_fab=$rowc['bon_fab'];
$echa_prod=$rowc['echa_prod'];
$remark=$rowc['remark'];
$fecha=$rowc['fecha_final'];


$query2="SELECT quantity, precio_compra, price_usd, porc_ocup, seis_ocho, cent, `com_colim`, `bon_fab`, orden, orden_pedido FROM `importado_items` inner join importado on orden_pedido= importado.id_pedido inner join referencias on id_ref=descripcion inner join clientes on id=supplier WHERE orden='$orden' ";
    $resultadoc2=$conexion->query($query2);
$rowc2=$resultadoc2->fetch_assoc();
if ($rowc2['quantity']!="") {

  $id_item=$rowc2['id_item'];
  $quantity=$rowc2['quantity'];
  $quantity2=$quantity2+$rowc2['quantity'];
$supplier=$rowc2['nombre'];
$um=$rowc2['um'];
$width=$rowc2['width'];
$weight=$rowc2['weight'];
$meter=$rowc2['meter'];
$precio_compra=$rowc2['precio_compra'];
$price_usd=$rowc2['price_usd'];
$fob=$rowc2['fob'];
$cap_hq=$rowc2['cap_hq'];
$porc_ocup=$rowc2['porc_ocup'];
$com_colim=$rowc2['com_colim'];
$total_com=$rowc2['total_com'];
$bon_fab=$rowc2['bon_fab'];
$echa_prod=$rowc2['echa_prod'];
$remark=$rowc2['remark'];
$fecha=$rowc['fecha_final'];


$consulta_color="SELECT sum(q_real) q_real FROM `importado_items_color` inner join importado_items  on  id_item=id_pedidos_items inner join importado on orden_pedido= importado.id_pedido where orden='$orden'";
//echo $consulta_color;
$resultado_color=$conexion-> query ($consulta_color);
$row_color=$resultado_color->fetch_assoc();
$total_qty_real=$row_color['q_real'];

if (($row_color['q_real']>0 && $row_color['q_real']!="") && ($row_color['q_real']>$quantity || $row_color['q_real']<$quantity )) {

$quantity=$row_color['q_real'];
$quantity2=$row_color['q_real'];

}


}


$porc_ocup=($quantity/$cap_hq)*100;

$total_venta=$total_venta+($quantity*$price_usd);
$total_comp=$total_comp+($quantity*$precio_compra);

$total_cap=$total_cap+$porc_ocup;

$total_cent=$total_cent+(($price_usd-$precio_compra)*$quantity);
$total_cent2=$total_cent2+(($price_usd-$precio_compra)*$quantity);



$total_com_total=$total_com_total+(((($quantity*$price_usd)*$com_colim))/100);
$total_bon_fab=$total_bon_fab+(((($quantity*$price_usd)-(($price_usd-$precio_compra)*$quantity))*$bon_fab)/100);
$total_ganac_total=$total_ganac_total+((($price_usd-$precio_compra)*$quantity)+(((($quantity*$price_usd)*$com_colim)/100))+((((($quantity*$price_usd)-(($price_usd-$precio_compra)*$quantity))*$bon_fab)/100)));


}



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


                                          <td><a href="informes.php?orden=<?php echo strtoupper($orden); ?>"><?php echo strtoupper($orden); ?></a></td>
                                          
                                          <td align="right"><?php echo number_format($quantity2,0,".",","); ?></td>
                                         <!-- <td align="right"><?php echo number_format($precio_compra,2,".",","); ?></td>
                                          <td align="right"><?php echo number_format($price_usd,2,".",","); ?></td>-->
                                          <td align="right"><?php echo number_format(($total_venta),2,".",","); ?></td>
                                         
                                          <td align="right"><?php echo number_format((($total_venta-$total_comp)),2,".",","); ?></td>
                                          
                                          <td align="right"><?php echo number_format(((($total_venta)*$com_colim)/100),2,".",","); ?></td>
                                   
                                          <td align="right"><?php echo number_format(((($total_venta-$total_cent)*$bon_fab)/100),2,".",","); ?></td>
                                          <!--<td><?php echo ""; ?>BON JAVIER </td>
                                          <td><?php echo ""; ?>TOTAL </td>-->
                                          <td align="right"><?php echo number_format(((($total_venta-$total_comp))+(($total_venta)*$com_colim/100)+(((($total_venta-$total_cent)*$bon_fab)/100))),2,".",","); ?></td>
                                     
                                            
                                            
                                        </tr>

                                   <?php 

$total_cent_2=$total_cent_2+$total_cent;
$total_venta_2=$total_venta_2+$total_venta;
$total_venta=0;
$total_comp=0;
$total_cent=0;
$price_usd=0;
$precio_compra=0;
$quantity2=0;

   }
                     ?>
                                        </tbody>
                                        <tfoot>
                                         
                                        <th></th>
                                          <th></th>
                                          <!--<th></th>
                                          <th></th>-->
                                         
                                          <TD align="right"><B><?php echo number_format($total_venta_2,2,".",","); ?></B></TD>
                                        
                                          <TD align="right"><B><?php echo number_format($total_cent_2,2,".",","); ?></B></TD>
                                          
                                          <TD align="right"><B><?php echo number_format($total_com_total,2,".",","); ?></B></TD>
                                
                                          <TD align="right"><B><?php echo number_format($total_bon_fab,2,".",","); ?></B></TD>
                                          <!--<TD><?php echo ""; ?>BON JAVIER </TD>
                                          <TD><?php echo ""; ?>TOTAL </TD>-->
                                          <TD align="right"><B><?php echo number_format($total_ganac_total,2,".",","); ?></B></TD>
                                      

                                        </tfoot>
                                    </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 class="form-horizontal" action="<?php 
                                  if (isset($_GET['id'])) {
                                                    echo "act_pedido.php";
                                             }
                                             else
                                             {
                                                echo "reg_pedido.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="pedidos.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%"> Orden de Pedido</h4>
                                                <!-- <small class="font-bold">Lorem Ipsum is simply dummy text of the printing and typesetting industry.</small> -->
                                            </div>
                                            <div class="modal-body">
                                                <!--
                                             SELECT `id_cotizacion`, `fecha`, `nit_cliente`, `dirigido_a`, `cargo`, `tipo_carroceria`, `chasis`, `largo_int`, `ancho_int`, `alto_int`, `concesionario`, `largo_ext`, `ancho_ext`, `alto_ext`, `plataforma`, `perfileria`, `forro`, `marco`, `incluye`, `tiempo`, `garantia`, `pago`, `referencia`, `nombre_referencia`, `cantidad`, `precio_unit`, `total`, `observaciones`, `asesor_interno`, `asesor_concesionario`, `estado`, `num_orden_p` FROM `cotizaciones`
                                                -->
                                                    <?php
$id_pedido=0;
                                                if (isset($_GET['id'])) {
                                                    $id_pedido=$_GET['id'];
                                                   
                                             }  

                                             



                                                  $query="SELECT `id_pedido`, `orden`, `fecha_pedido`, `fecha_final`, `cliente`, `observaciones`, `forma_pago`, `embalaje` FROM `pedidos` WHERE id_pedido='$id_pedido'";
    $resultadoc=$conexion->query($query);
     $rowx=$resultadoc->fetch_assoc();

?>                                          

                                                                                             <div class="form-group">
                                                            <div class="row">
                                                              <div class="col-md-4">
                                                            <label>Orden #</label>
                                                            <input type="text" class="form-control" name="orden" value='<?php echo $rowx["orden"]; ?>'>
                                                            
                                                             </div>
                                                                <div class="col-md-8">
                                                            <label>Nombre de Cliente</label>
                                                            <input type="hidden" name="id_pedido" id="id_pedido" value='<?php echo $id_pedido; ?>'>
                                                            <select class="form-control m-b chosen-select" name="cliente" id="cliente" onchange="buscar_nit(this.value)">

                                        <option value="">Seleccione</option>
                                                           <?php
                                         $queryc="SELECT * FROM `clientes` where `tipo_tercero`='2'  or `tipo_tercero`='3'  order by nombre asc";
                                        $resultadoc=$conexion->query($queryc);
                                        while ($rowc=$resultadoc->fetch_assoc()) {
                                            if ($rowc['id']==$rowx['cliente']) {
                                              echo "<option selected value='".$rowc['id']."'>".$rowc['nombre'] ."</option>";
                                            }
                                            else
                                            {
                                       echo "<option  value='".$rowc['id']."'>".$rowc['nombre'] ."</option>";
                                      }
                                        };
                                        ?>
                                    </select>
                                   
                                  </div>
                                 
                                   </div>
                                 </div>

                                 <div class="form-group">
                                                            <div class="row">
                                                           
                                                               <div class="col-md-4">
                                                                <label>Fecha de Pedido</label>
                                                                <input type="date" name="fecha_pedido" placeholder="" required class="form-control col-md-4" value="<?php if($rowx["fecha_pedido"]!="") {echo $rowx["fecha_pedido"];} else { echo date("Y-m-d"); }?>" >
                                                              </div>

                                                               <div class="col-md-4">
                                                            <label>Fecha Producción</label>
                                                            <input type="date" name="fecha_final" id="fecha_final" placeholder="" required class="form-control col-md-4" value="<?php if($rowx["fecha_final"]!="") {echo $rowx["fecha_final"];} else { echo date("Y-m-d"); }?>" >
                                                              </div>

                                                              <div class="col-md-4">
                                                                <label>Embalaje</label>
                                                                <select class="form-control" name="embalaje">
                                                                   <option value="">Seleccione</option>
                                                 <?php 
                                                 if($rowx["embalaje"]!="") 
                                                  {
                                                    ?>
<option selected value="<?php echo $rowx["embalaje"]; ?>"><?php echo $rowx["embalaje"]; ?></option>
                                                    <?php
                                                  }
                                                ?>


                                                                   <option value="BALE PACKING">BALE PACKING</option>
                                                                   <option value="LOOSE PACKING">LOOSE PACKING</option>


                                                                </select>
                                                              </div>
                                                             
                                 
                                                        
                                                    
                                                    </div>
                                                  </div>
                                         
                                                    <div class="form-group">
                                                            <div class="row">
                                                          
                                                              <div class="col-md-12">
                                                            <label>Forma de Pago</label>
                                                            <select class="form-control" name="forma_pago">
                                                                   <option value="">Seleccione</option>
                                                 <?php 
                                                 if($rowx["forma_pago"]!="") 
                                                  {
                                                    ?>
                                          <option selected value="<?php echo $rowx["forma_pago"]; ?>"><?php echo $rowx["forma_pago"]; ?></option>
                                                    <?php
                                                  }
                                                ?>


                                                                   <option value="100% WITHIN 30 DAYS AFTER SHIPMENT">100% WITHIN 30 DAYS AFTER SHIPMENT</option>
                                                                   <option value="100% BEFORE SHIPMENT">100% BEFORE SHIPMENT</option>
                                                                   <option value="ADVANCE PAYMENT 20%  BALANCE 80% WITHIN 30 DAYS AFTER SHIPMENT">ADVANCE PAYMENT 20%  BALANCE 80% WITHIN 30 DAYS AFTER SHIPMENT</option>


                                                                </select>
                                                            




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


                                                      
                                                      <!-- compras -->
       



                                                
                                                 <div class="form-group">
                                                        <div class="row">
                                                          <div class="col-md-12">
                                                         <label>Observaciones</label>
                                                         <textarea onkeyup="MaysPrimera(this);" name="observaciones" class="form-control"><?php echo $rowx['observaciones'] ?></textarea>
                                                  
                                                    </div>
                                                  </div>
                                                </div>
                                                      <div class="form-group">
                                                        <div class="row">
                                                         <div class="col-md-12">
                                                         <label><h4>Detalle de Productos/Referencias</h4></label>
                                                        </div>
                                                    </div>
                                                </div>
                                                <?php 
                                                $temporal=rand(5, 17958);
                                                ?>
                                      <div class="form-group">
                                                          <div class="row">
                                                         <div style="display: block" class="col-md-6">

                                                            
                                                            <input type="hidden" name="num_orden" id="num_orden" value='<?php  if (isset($_GET['id'])) {
                                                    echo $_GET['id'];
                                             } else {echo $temporal; }?>'>
                                             <label>Tela o Referencia</label>
                                                          <select  class="form-control m-b chosen-select" name="referencia" id="referencia" placeholder="Item" onchange="buscar_ref(this.value)">

                                        <option value="">Seleccione</option>
                                                           <?php
                                         $queryc="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` FROM `referencias` order by nombre_ref asc";
                                        $resultadoc=$conexion->query($queryc);
                                        while ($rowc=$resultadoc->fetch_assoc()) {
                                            
                                       echo "<option  value='".$rowc['id_ref']."'>".$rowc['nombre_ref'] ."</option>";
                                      
                                        };
                                        ?>
                                    </select>
                                                        </div>
                                                        <div class="col-md-6">
                                                            <label>Remark</label>
                                                            <select class="form-control" name="remark" id="remark">
                                                                   <option value="">Seleccione</option>
                                                                   <option value="GLUE SELVEDGE NOT CUT">GLUE SELVEDGE & NOT CUT</option>
                                                                   <option value="GLUE AND CUT SELVEDGE">GLUE AND CUT SELVEDGE</option>
                                                                   <option value="ONE SIDE BRUSH">ONE SIDE BRUSH</option>
                                                                   <option value="TWO SIDE BRUSH">TWO SIDE BRUSH</option>
                                                                   <option value="VAT OYED">VAT OYED</option>
                                                                   <option value="AIR FLOW OYED">AIR FLOW OYED</option>
                                                                   <option value="REACTIVE OYED">REACTIVE OYED</option>
                                                                </select>
                                                              </div>

                                                             <div class="col-md-12">
                                                            <label>Nombre del Proveedor</label>
                                                            <select class="form-control m-b chosen-select" name="supplier" id="supplier" onchange="buscar_nit(this.value)">

                                        <option value="">Seleccione</option>
                                                           <?php
                                         $queryc="SELECT * FROM `clientes` where `tipo_tercero`='1'  or `tipo_tercero`='3'  order by nombre asc";
                                        $resultadoc=$conexion->query($queryc);
                                        while ($rowc=$resultadoc->fetch_assoc()) {
                                           
                                       echo "<option  value='".$rowc['id']."'>".$rowc['nombre'] ."</option>";
                                     
                                        };
                                        ?>
                                    </select>
                                   
                                  </div>
                                                      </div>
                                                    </div>
                                       <div class="form-group">
                                                          <div class="row">
                                                        <div class="col-md-3">
                                                          <label>U.M.</label>
                                                          <input  type="text" autocomplete="off" placeholder="" onkeyup="calc_rend()"  class="form-control" name="um_ref" id="um_ref" value="">
                                                        </div>
                                                         <div class="col-md-3">
                                                          <label>Ancho</label>

                                                          <input  type="text"  autocomplete="off" placeholder="" onkeyup="calc_rend()"  class="form-control" name="ancho_ref" id="ancho_ref">
                                                        </div>
                                                        <div class="col-md-3">
                                                          <label>Peso</label>

                                                          <input  type="text"  autocomplete="off" placeholder="" onkeyup="calc_rend()"  class="form-control" name="peso_ref" id="peso_ref">
                                                        </div>
                                                         <div class="col-md-3">
                                                          <label>Rendimiento</label>
                                                          <input  type="text"  autocomplete="off" placeholder="" onkeyup="calc_rend()"  class="form-control" name="rendi_ref" id="rendi_ref">
                                                        </div>
                                                         <div class="col-md-3">
                                                          <label>Capacidad</label>
                                                          <input  type="text"  autocomplete="off" placeholder="" onkeyup="calc_rend()"  class="form-control" name="cap_ref" id="cap_ref">
                                                        </div>
                                                        <div class="col-md-3">
                                                          <label>Ocupacion %</label>
                                                          <input  type="text"  autocomplete="off" placeholder="" onkeyup="calc_rend()"  class="form-control" name="porc_ocup" id="porc_ocup">
                                                        </div>

                                                        <div class="col-md-3">
                                                          <label>Cantidad</label>
                                                          <input  type="text"  autocomplete="off" placeholder="" onkeyup="calc_porc()"  class="form-control" name="quantity" id="quantity">
                                                        </div>

                                                         <div class="col-md-3">
                                                          <label>$ Venta</label>
                                                          <input  type="text"  autocomplete="off" placeholder="" onkeyup="calc_rend()"  class="form-control" name="prec_venta" id="prec_venta">
                                                        </div>

                                                         <div class="col-md-3">
                                                          <label>$ Compra</label>
                                                          <input  type="text"  autocomplete="off" placeholder="" onkeyup="calc_rend()"  class="form-control" name="prec_comp" id="prec_comp">
                                                        </div>


                                                         <div class="col-md-3" style="display: none;">
                                                          <label>$ FOB</label>
                                                          <input  type="text"  autocomplete="off" placeholder="" onkeyup="calc_rend()"  class="form-control" name="fob" id="fob">
                                                        </div>

                                                         <div class="col-md-3">
                                                          <label>Com. Colimptex</label>
                                                          <input  type="text"  autocomplete="off" placeholder="" onkeyup="calc_rend()"  class="form-control" name="com_colim" id="com_colim">
                                                        </div>

                                                        <div class="col-md-3">
                                                          <label>Bon. Fabrica</label>
                                                          <input  type="text"  autocomplete="off" placeholder="" onkeyup="calc_rend()"  class="form-control" name="bon_fab" id="bon_fab">
                                                        </div>
                                                       

                                                    </div>
                                                </div>
                                                <div class="form-group">
                                                          <div class="row">
                                                         <div class="col-md-12">
                                                   <button type="button" class="btn btn-white" onclick="regdetalles_pedidos()">Agregar</button>
                                                        </div>
                                                       <div class="col-md-12">
                                                       <div id="resultado">
                                                           <?php
$servicios="";
                                                           if (isset($_GET['id'])) {
                                                              
$costo_t=0;
$servicios="";
$i=0;
$pedido=$_GET['id'];
$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>";

                                                           ?>



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

                                            </div>
                                            <div class="modal-footer">
                                               <a href="pedidos.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>