<?php

include("session.php");

include("conexion.php");

$query  = "SELECT `orden_pedido`, id_item FROM `importado_items`";

$resultadoc = $conexion->query($query);

while($row1=$resultadoc->fetch_assoc()){

  $pedido=$row1['orden_pedido'];

  $id=$row1['id_item'];

  $queryi="SELECT `id_pedido` FROM `importado` where id_pedido='$pedido'";

  $resultadoi=$conexion->query($queryi);

  $rowi=$resultadoi->fetch_assoc();

  if ($pedido!=$rowi['id_pedido']) {

    $querye="DELETE FROM `importado_items` WHERE `id_item`='$id'";

    $resultadoce=$conexion->query($querye);

  }

}

?>



<!DOCTYPE html>

<html>

<?php include("head.php");?>

<style type="text/css">

.th_pgrw{

  background-color:#000000;color:#ffffff ;border-left:1px solid; border-top:1px solid; padding-top:50px;border-bottom:1px solid;

}

.th_pgrw2{

  background-color:#c9c5c5;color:#000000;border-left:1px solid; border-bottom:1px solid;

}

.verde{

  background: rgba(63,133,36,1);

  background: -webkit-linear-gradient(rgba(63,133,36,1) 1%, rgba(64,135,37,1) 3%, rgba(96,177,68,1) 53%, rgba(97,179,69,1) 55%, rgba(63,133,36,1) 100%);

  background: -o-linear-gradient(rgba(63,133,36,1) 1%, rgba(64,135,37,1) 3%, rgba(96,177,68,1) 53%, rgba(97,179,69,1) 55%, rgba(63,133,36,1) 100%);

  background: linear-gradient(rgba(63,133,36,1) 1%, rgba(64,135,37,1) 3%, rgba(96,177,68,1) 53%, rgba(97,179,69,1) 55%, rgba(63,133,36,1) 100%);

  filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#3f8524', endColorstr='#3f8524', GradientType=0 );

}

.rojo{

  background: rgba(201,0,0,1);

  background: -moz-linear-gradient(top, rgba(201,0,0,1) 1%, rgba(203,5,5,1) 3%, rgba(250,138,138,1) 53%, rgba(252,143,143,1) 55%, rgba(201,18,18,1) 100%);

  background: -webkit-gradient(left top, left bottom, color-stop(1%, rgba(201,0,0,1)), color-stop(3%, rgba(203,5,5,1)), color-stop(53%, rgba(250,138,138,1)), color-stop(55%, rgba(252,143,143,1)), color-stop(100%, rgba(201,18,18,1)));

  background: -webkit-linear-gradient(top, rgba(201,0,0,1) 1%, rgba(203,5,5,1) 3%, rgba(250,138,138,1) 53%, rgba(252,143,143,1) 55%, rgba(201,18,18,1) 100%);

  background: -o-linear-gradient(top, rgba(201,0,0,1) 1%, rgba(203,5,5,1) 3%, rgba(250,138,138,1) 53%, rgba(252,143,143,1) 55%, rgba(201,18,18,1) 100%);

  background: -ms-linear-gradient(top, rgba(201,0,0,1) 1%, rgba(203,5,5,1) 3%, rgba(250,138,138,1) 53%, rgba(252,143,143,1) 55%, rgba(201,18,18,1) 100%);

  background: linear-gradient(to bottom, rgba(201,0,0,1) 1%, rgba(203,5,5,1) 3%, rgba(250,138,138,1) 53%, rgba(252,143,143,1) 55%, rgba(201,18,18,1) 100%);

  filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#c90000', endColorstr='#c91212', GradientType=0 );

}

</style>

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

                <!--button -->

              </div>

              <form action="checklist.php" method="GET" name="buscaryear" id="buscaryear">

                <div class="row">

                  <div class="col-md-4">

                    <h5>Check List 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>

              <form method="GET" action="checklist.php">

               <input type="hidden" name="filtro">

               <button type="submit" class="btn rojo pull-right" style="color: white">Pendientes</button>

             </form>

             <a href="checklist.php">

               <input type="hidden" name="filtro">

               <button type="submit" class="btn verde pull-right" style="color: white">Todos</button>

             </a>

           </div>

           <div class="ibox-content">

             <div class="table-responsive">

               <table class="table table-hover">

                 <thead style="color: #1f51a3">

                   <tr valign="bottom" align="center" style="text-align: center;">

                     <th class="th_pgrw" rowspan="2" valign="bottom" align="center" >Check List</th>

                     <th class="th_pgrw" rowspan="2" valign="bottom" align="center">Orden #</th>

                     <th class="th_pgrw" rowspan="2" valign="bottom" align="center" >Cliente</th>

                     <th class="th_pgrw" colspan="7" align="center">

                       <div style="width: 100%; text-align: center;" >FASE 1 (PEDIDO)</div>

                     </th>

                     <th class="th_pgrw" colspan="6" align="center"><div style="width: 100%; text-align: center;" >FASE 2 (PRODUCCION)</div></th>

                     <th class="th_pgrw" colspan="10" align="center"><div style="width: 100%; text-align: center;" >FASE 3 (LOGISTICA)</div></th>

                     <th class="th_pgrw" colspan="10" align="center"><div style="width: 100%; text-align: center;" > </th>

                   </tr>

                   <tr>

                    <th class="th_pgrw2" style="" >Nueva orden</th>

                    <th class="th_pgrw">Proforma</th>

                    <th class="th_pgrw">Pago anticipo (cliente)</th>

                    <th class="th_pgrw">Pagar anticipo (fabrica)</th>

                    <th class="th_pgrw">Generar orden de producción</th>

                    <th class="th_pgrw">Enviar Lab dips/stike off</th>

                    <th class="th_pgrw">Aprobación Lab dips/stike off</th>

                    <th style="background-color:#c9c5c5;color:#000000;border-bottom: 1px solid; border-left:1px solid;" >Inicio de producción</th>

                    <th class="th_pgrw">Reserva de embarque</th>

                    <th class="th_pgrw">Final de producción</th>

                    <th class="th_pgrw">Inspección mercancía</th>

                    <th class="th_pgrw">Enviar informe de inspección</th>

                    <th class="th_pgrw">Enviar shipping sample</th>

                    <th style="background-color:#c9c5c5;color:#000000;border-bottom: 1px solid; border-left:1px solid;">Cargue (ETL)</th>

                    <th class="th_pgrw">Zarpe (ETD)</th>

                    <th class="th_pgrw">Notificar fecha de llegada (ETA)</th>

                    <th class="th_pgrw">Revisión de los documentos</th>

                    <th class="th_pgrw">Envío de los documentos</th>

                    <th class="th_pgrw">Pago balance (cliente)</th>

                    <th class="th_pgrw">Pago balance (fabrica)</th>

                    <th class="th_pgrw">Liberar y enviar documentos (cliente)</th>

                    <th class="th_pgrw">Realizar factura de comisión</th>

                    <th style="background-color:#c9c5c5;color:#000000;border-bottom: 1px solid; border-right:1px solid;"> Pago de comisión</th>

                    <th style="background-color:#000000;color:#ffffff ;border-left:1px solid; border-right:1px solid; border-top:1px solid; border-bottom:1px solid;" colspan="10" align="center"><div style="width: 100%; text-align: center;" > Detalles de la orden</th>

                  </tr>

                </thead>

                <tbody style="font-weight: bold;">

                  <?php

                  if(isset($_GET['ayo'])) {

                    $ayo=$_GET['ayo'];

                  } else {

                    $ayo=date("Y");

                  }

                  if($_SESSION["roles"]==2 || $_SESSION["roles"]==3) {

                    $id_cliente=$_SESSION["clienteid"];

                    $query="SELECT `id_pedido`,

                    `orden`,

                    `fecha_pedido`,

                    `fecha_final`,

                    `cliente`,

                    `forma_pago`,

                    `embalaje`,

                    nombre,

                    ciudad,

                    telefono

                    FROM `pedidos`

                    inner join  clientes on id  = cliente

                    where (fecha_pedido like '%$ayo%' or fecha_final like '%$ayo%')

                    and cliente='$id_cliente' order by id_pedido asc";

                  }else{

                    $query="SELECT `id_pedido`, `orden`, `fecha_pedido`, `fecha_final`, `cliente`, `forma_pago`, `embalaje`, nombre, ciudad, telefono FROM `pedidos` inner join  clientes on id=cliente where fecha_pedido like '%$ayo%' or fecha_final like '%$ayo%' order by id_pedido asc";

                  }



                  $resultadoc=$conexion->query($query);

                  while ($rowc=$resultadoc->fetch_assoc()) {

                    $valorfiltro=0;

                    if (isset($_GET['filtro'])) {

                      include "validador.php";

                      $valorfiltro=1;

                    }

                    if ($resul_validador>=$valorfiltro) {?>

                    <tr style="font-size: 12px">

                      <td style="border-left:1px solid;">

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

                        <a href="#" data-toggle="modal" data-target="#myModal_<?php echo $rowc['id_pedido'] ?>">

                          <i class="fa fa-tasks"></i>

                        </a>

                        <?php  }  ?>

                        <a href="seguimientos_pedidos.php?id=<?php echo $rowc['id_pedido'] ?>&id_check=1" data-toggle="modal">

                          <i class="fa fa-comments"></i>

                        </a>

                        <div class="modal inmodal" id="myModalSeg_<?php echo $rowc['id_pedido'] ?>" >

                          <div class="modal-dialog">

                            <div class="modal-content animated bounceInRight">

                              <div class="modal-header">

                                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>

                                <h4 class='modal-title'><img alt='Logo' src='img/logo.png' height='10%' width='10%'> Comentarios</h4>

                              </div>

                              <div class="modal-body">

                                <div class="box-body">

                                  <form  action="registro_activi_p.php" method="post">

                                    <?php

                                    $fecha=date('Y-m-d');

                                    $id=$rowc['id_pedido'];

                                    $ida=0;

                                    ?>

                                    <input type="hidden" name="id" value="<?php echo $id?>">

                                    <input type="hidden" name="ida" value="<?php echo $ida?>">

                                    <div class="form-group">

                                      <div class="row">

                                      </div>

                                    </div>

                                    <div class="form-group">

                                      <div class="row">

                                        <div class="col-md-12">

                                          <label>Detalles</label>

                                          <textarea class="form-control" name="detalles" rows="5" required></textarea>

                                        </div>

                                      </div>

                                    </div>

                                    <div class="form-group">

                                      <div class="row">

                                        <div class="col-md-4">

                                          <label>Fecha</label>

                                          <input type="date" name="fecha" class="form-control" required min="2018-<?php echo date("m") ?>-01" max="<?php echo $fecha ?>" value="<?php echo $fecha; ?>">

                                        </div>

                                        <div class="col-md-8">

                                          <label>Responsable</label>

                                          <input readonly type="text" name="usuario" class="form-control" value="<?php echo strtoupper($_SESSION["nombre"]); ?>">

                                        </div>

                                      </div>

                                    </div>

                                  </div><!-- /.box-body -->

                                  <div class="modal-footer">

                                    <button class="btn btn-primary pull-right" type="submit" >Guardar Comentario</button>

                                  </div><!-- /.box-footer -->

                                </form>

                              </div><!-- /.box -->

                            </div><!-- /.modal-content -->

                          </div><!-- /.modal-dialog -->

                        </div><!-- /.modal -->

                        <!-- MODAL Seguimiento-->

                        <?php

                        $num_ordenf= $rowc['id_pedido'];

                        $queryf ="SELECT `id_check`,

                        `num_orden`,

                        `f_orden`,

                        `f_proforma`,

                        `f_anticipo`,

                        `f_verif_ant`,

                        `f_pago_ant`,

                        `f_produccion`,

                        f_embarque,

                        `f_producion_cant`,

                        `f_producion_color`,

                        `f_producion_empaque`,

                        `f_laps`,

                        `f_aprob_lap`,

                        `f_aprob_lap_tipo`,

                        `f_ini_prod`,

                        `f_fin_prod`,

                        `f_revision`,

                        `f_revision_tipo`,

                        `f_envio_informe`,

                        `f_shipping_sample`,

                        `f_aprob_sample`,

                        `f_aprob_sample_tipo`,

                        `f_cargue_zarpe`,

                        `f_cargue`,

                        `f_zarpe`,

                        `f_llegada`,

                        `f_revision_doc`,

                        `f_revision_doc_bl`,

                        `f_revision_doc_emp`,

                        `f_revision_doc_fact`,

                        `f_envio_doc`,

                        `f_balance`,

                        `f_balance_pago`,

                        `f_balance_fab` ,

                        `f_balance_fab_pago`,

                        `f_liberar`,

                        `f_liberar_tipo`,

                        `f_factura`,

                        `f_pago`

                        FROM `checklist`

                        where num_orden='$num_ordenf'";

                        $resultadof=$conexion->query($queryf);

                        $rowf=$resultadof->fetch_assoc();

                        ?>

                        <!-- Modal-->

                        <div class="modal inmodal" id="myModal_<?php echo $rowc['id_pedido'] ?>" tabindex="-1" role="dialog" aria-hidden="true">

                          <div class="modal-dialog">

                            <div class="modal-content animated bounceInRight">

                              <div class="modal-header" style="text-align: left">

                                <h4 class="modal-title"><img alt="Logo" src="img/logo.png" height="10%" width="10%"> Registro de Detalles</h4>

                              </div>

                              <div class="modal-body">

                                <form action="<?php if ($rowf['id_check']=='') { echo "reg_checklist.php"; } else { echo "act_checklist.php"; } ?>" method="POST" >

                                  <div class="row">

                                    <div class="col-lg-12">

                                      <div class="tabs-container">

                                        <ul class="nav nav-tabs">

                                          <li class="active"><a data-toggle="tab" href="#tab-1_<?php echo $rowc['id_pedido'] ?>"> Fase 1</a></li>

                                          <li class=""><a data-toggle="tab" href="#tab-2_<?php echo $rowc['id_pedido'] ?>"> Fase 2</a></li>

                                          <li class=""><a data-toggle="tab" href="#tab-3_<?php echo $rowc['id_pedido'] ?>"> Fase 3</a></li>

                                        </ul>

                                        <div class="tab-content">

                                          <div id="tab-1_<?php echo $rowc['id_pedido'] ?>" class="tab-pane active">

                                            <div class="panel-body">

                                              <div class="form-group">

                                                <div class="row">

                                                  <div class="col-md-6">

                                                    <label>1. Nueva orden</label>

                                                    <input type="hidden" name="id_check" value="<?php echo $rowf['id_check'] ?>">

                                                    <input type="hidden" name="num_orden" id="num_orden" value="<?php echo $rowc['id_pedido'] ?>">

                                                    <input type="date" class="form-control" name="f_orden" id="f_orden"  value="<?php if ($rowf['f_orden']==""){ echo $rowc['fecha_pedido']; } else { echo $rowf['f_orden']; } ?>" >

                                                  </div>

                                                  <div class="col-md-6">

                                                    <label>2. Proforma</label>

                                                    <input type="date" value="<?php echo $rowf['f_proforma'] ?>"  class="form-control" name="f_proforma" id="f_proforma">

                                                  </div>

                                                  <div class="col-md-6">

                                                    <label>3. Pago anticipo (cliente)</label>

                                                    <input type="date" value="<?php echo $rowf['f_anticipo'] ?>"  class="form-control" name="f_anticipo" id="f_anticipo">

                                                  </div>

                                                  <div class="col-md-6">

                                                    <label>4. Pago anticipo (fabrica)</label>

                                                    <input type="date" class="form-control" value="<?php echo $rowf['f_pago_ant'] ?>"   name="f_pago_ant" id="f_pago_ant">

                                                  </div>

                                                  <div class="col-md-12">

                                                    <label>5. Generar orden de producción</label>

                                                    <div class="row">

                                                      <div class="col-md-6">

                                                        <input type="date" class="form-control" value="<?php echo $rowf['f_produccion'] ?>"  name="f_produccion" id="f_produccion">

                                                      </div>

                                                      <div class="col-md-6">

                                                        <input type="checkbox" <?php if ($rowf['f_producion_cant']=="f_producion_cant"){ echo "checked"; } ?> name="f_producion_cant" id="f_producion_cant" value="f_producion_cant"> Verificación de Cantidades <br>

                                                        <input type="checkbox" <?php if ($rowf['f_producion_color']=="f_producion_color"){ echo "checked"; } ?> name="f_producion_color" id="f_producion_color" value="f_producion_color"> Colorido  <br>

                                                        <input type="checkbox" <?php if ($rowf['f_producion_empaque']=="f_producion_empaque"){ echo "checked"; } ?> name="f_producion_empaque" id="f_producion_empaque" value="f_producion_empaque"> Instrucciones de empaque

                                                      </div>

                                                    </div>

                                                  </div>

                                                  <div class="col-md-6">

                                                    <label>6. Enviar lab dips/strike off</label>

                                                    <input type="date" value="<?php echo $rowf['f_laps'] ?>"  class="form-control" name="f_laps" id="f_laps">

                                                  </div>

                                                  <div class="col-md-6">

                                                    <label>7. Aprob. lab dips/strike off</label>

                                                    <input type="date" class="form-control" value="<?php echo $rowf['f_aprob_lap'] ?>"  name="f_aprob_lap" id="f_aprob_lap">

                                                    <input type="radio" <?php if ($rowf['f_aprob_lap_tipo']=="f_aprob_lap_tipo_aprobado"){ echo "checked"; } ?>  name="f_aprob_lap_tipo" id="f_aprob_lap_tipo" value="f_aprob_lap_tipo_aprobado"> Aprobado

                                                    <input type="radio" <?php if ($rowf['f_aprob_lap_tipo']=="f_aprob_lap_tipo_no_aprobado"){ echo "checked"; } ?>   name="f_aprob_lap_tipo" id="f_aprob_lap_tipo" value="f_aprob_lap_tipo_no_aprobado"> No aprobado

                                                  </div>

                                                  <div class="col-md-6" style="display: none;">

                                                    <label>XXXX. Verificación del anticipo</label>

                                                    <input type="date" class="form-control" value="<?php echo $rowf['f_verif_ant'] ?>"   name="f_verif_ant" id="f_verif_ant">

                                                  </div>

                                                </div>

                                              </div>

                                            </div>

                                          </div>

                                          <div id="tab-2_<?php echo $rowc['id_pedido'] ?>" class="tab-pane">

                                            <div class="panel-body">

                                              <div class="form-group">

                                                <div class="row">

                                                  <div class="col-md-6">

                                                    <label>8. Inicio de producción</label>

                                                    <input type="date" value="<?php echo $rowf['f_ini_prod'] ?>" class="form-control" name="f_ini_prod" id="f_ini_prod">

                                                  </div>

                                                  <div class="col-md-6">

                                                    <label>9. Reservacion de embarque</label>

                                                    <input type="date" value="<?php echo $rowf['f_embarque'] ?>"  class="form-control" name="f_embarque" id="f_embarque">

                                                  </div>

                                                  <div class="col-md-6">

                                                    <label>10. Final de producción</label>

                                                    <input type="date" value="<?php echo $rowf['f_fin_prod'] ?>" class="form-control" name="f_fin_prod" id="f_fin_prod">

                                                  </div>

                                                  <div class="col-md-6">

                                                    <label>11. Inspección mercancía</label>

                                                    <input type="date" value="<?php echo $rowf['f_revision'] ?>" class="form-control" name="f_revision" id="f_revision">

                                                    <input type="radio" <?php if ($rowf['f_revision_tipo']=="f_revision_tipo_revisada"){ echo "checked"; } ?> name="f_revision_tipo" id="f_revision_tipo" value="f_revision_tipo_revisada"> Revisada

                                                    <input type="radio" <?php if ($rowf['f_revision_tipo']=="f_revision_tipo_no_revisada"){ echo "checked"; } ?> name="f_revision_tipo" id="f_revision_tipo" value="f_revision_tipo_no_revisada"> No revisada

                                                  </div>

                                                  <div class="col-md-6">

                                                    <label>12. Enviar informe de inspección</label>

                                                    <input type="date" value="<?php echo $rowf['f_envio_informe'] ?>" class="form-control" name="f_envio_informe" id="f_envio_informe">

                                                  </div>

                                                  <div class="col-md-6">

                                                    <label>13. Enviar shipping sample</label>

                                                    <input type="date" value="<?php echo $rowf['f_shipping_sample'] ?>" class="form-control" name="f_shipping_sample" id="f_shipping_sample">

                                                  </div>

                                                  <div class="col-md-6" style="display: none">

                                                    <label>xx. Aprobación de shipping sample</label>

                                                    <input type="date" value="<?php echo $rowf['f_aprob_sample'] ?>" class="form-control" name="f_aprob_sample" id="f_aprob_sample">

                                                    <input type="radio" <?php if ($rowf['f_aprob_sample_tipo']=="f_aprob_sample_tipo_aprobado"){ echo "checked"; } ?> name="f_aprob_sample_tipo" id="f_aprob_sample_tipo" value="f_aprob_sample_tipo_aprobado"> Aprobado

                                                    <input type="radio" <?php if ($rowf['f_aprob_sample_tipo']=="f_aprob_sample_tipo_no_aprobado"){ echo "checked"; } ?> name="f_aprob_sample_tipo" id="f_aprob_sample_tipo" value="f_aprob_sample_tipo_no_aprobado"> No aprobado

                                                  </div>

                                                </div>

                                              </div>

                                            </div>

                                          </div>

                                          <div id="tab-3_<?php echo $rowc['id_pedido'] ?>" class="tab-pane">

                                            <div class="panel-body">

                                              <div class="form-group">

                                                <div class="row">

                                                  <div class="col-md-6" style="display: none">

                                                    <label>xx. Fecha de cargue y zarpe</label>

                                                    <input type="date" value="<?php echo $rowf['f_cargue_zarpe'] ?>" class="form-control" name="f_cargue_zarpe" id="f_cargue_zarpe">

                                                  </div>

                                                  <div class="col-md-6">

                                                    <label>14. Cargue (ETL)</label>

                                                    <input type="date" value="<?php echo $rowf['f_cargue'] ?>" class="form-control" name="f_cargue" id="f_cargue">

                                                  </div>

                                                  <div class="col-md-6">

                                                    <label>15. Zarpe (EDT)</label>

                                                    <input type="date" value="<?php echo $rowf['f_zarpe'] ?>" class="form-control" name="f_zarpe" id="f_zarpe">

                                                  </div>

                                                  <div class="col-md-6">

                                                    <label>16. Notificar fecha de llegada (ETA)</label>

                                                    <input type="date" value="<?php echo $rowf['f_llegada'] ?>" class="form-control" name="f_llegada" id="f_llegada">

                                                  </div>

                                                  <div class="col-md-12">

                                                    <label>17. Revisión de los documentos</label>

                                                    <div class="row">

                                                      <div class="col-md-6">

                                                        <input type="date" value="<?php echo $rowf['f_revision_doc'] ?>" class="form-control" name="f_revision_doc" id="f_revision_doc">

                                                      </div>

                                                      <div class="col-md-6">

                                                        <input type="checkbox" <?php if ($rowf['f_revision_doc_bl']=="f_revision_doc_bl"){ echo "checked"; } ?>  name="f_revision_doc_bl" id="f_revision_doc_bl" value="f_revision_doc_bl"> BL <br>

                                                        <input type="checkbox" <?php if ($rowf['f_revision_doc_emp']=="f_revision_doc_emp"){ echo "checked"; } ?>  name="f_revision_doc_emp" id="f_revision_doc_emp" value="f_revision_doc_emp"> Lista de Empaques  <br>

                                                        <input type="checkbox" <?php if ($rowf['f_revision_doc_fact']=="f_revision_doc_fact"){ echo "checked"; } ?>  name="f_revision_doc_fact" id="f_revision_doc_fact" value="f_revision_doc_fact"> Factura Comercial

                                                      </div>

                                                    </div>

                                                  </div>

                                                  <div class="col-md-6">

                                                    <label>18. Envío de los documentos</label>

                                                    <input type="date" value="<?php echo $rowf['f_envio_doc'] ?>" class="form-control" name="f_envio_doc" id="f_envio_doc">

                                                  </div>

                                                  <div class="col-md-6">

                                                    <label>19. Pago balance (cliente)</label>

                                                    <input type="date" class="form-control" name="f_balance" value="<?php echo $rowf['f_balance'] ?>" id="f_balance">

                                                    <input type="radio" <?php if ($rowf['f_balance_pago']=="f_balance_pago_pagado"){ echo "checked"; } ?> name="f_balance_pago" id="f_balance_pago" value="f_balance_pago_pagado"> Pagado

                                                    <input type="radio" <?php if ($rowf['f_balance_pago']=="f_balance_pago_nopagado"){ echo "checked"; } ?> name="f_balance_pago" id="f_balance_pago" value="f_balance_pago_nopagado"> No pagado

                                                  </div>

                                                  <div class="col-md-6">

                                                    <label>20. Pago balance (fabrica)</label>

                                                    <input type="date" class="form-control" name="f_balance_fab" value="<?php echo $rowf['f_balance_fab'] ?>" id="f_balance">

                                                    <input type="radio" <?php if ($rowf['f_balance_fab_pago']=="f_balance_fab_pago_pagado"){ echo "checked"; } ?> name="f_balance_fab_pago" id="f_balance_fab_pago" value="f_balance_fab_pago_pagado"> Pagado

                                                    <input type="radio" <?php if ($rowf['f_balance_fab_pago']=="f_balance_fab_pago_nopagado"){ echo "checked"; } ?> name="f_balance_fab_pago" id="f_balance_fab_pago" value="f_balance_fab_pago_nopagado"> No pagado

                                                  </div>

                                                  <div class="col-md-6">

                                                    <label>21. Liberar y enviar documentos (cliente)</label>

                                                    <input type="date" class="form-control"  value="<?php echo $rowf['f_liberar'] ?>" name="f_liberar" id="f_liberar">

                                                    <input type="radio" <?php if ($rowf['f_liberar_tipo']=="f_liberar_tipo_liberados"){ echo "checked"; } ?>  name="f_liberar_tipo" id="f_liberar_tipo" value="f_liberar_tipo_liberados"> Liberados

                                                    <input type="radio" <?php if ($rowf['f_liberar_tipo']=="f_liberar_tipo_noliberados"){ echo "checked"; } ?>   name="f_liberar_tipo" id="f_liberar_tipo" value="f_liberar_tipo_noliberados"> No liberados

                                                  </div>

                                                  <div class="col-md-6">

                                                    <label>22. Realizar factura de comisión</label>

                                                    <input type="date" value="<?php echo $rowf['f_factura'] ?>" class="form-control" name="f_factura" id="f_factura">

                                                  </div>

                                                  <div class="col-md-6">

                                                    <label>23. Pago de comisión</label>

                                                    <input type="date" class="form-control" value="<?php echo $rowf['f_pago'] ?>" name="f_pago" id="f_pago">

                                                  </div>

                                                  <div class="col-md-6">

                                                    <label>23. Pago de comisión</label>

                                                    <input type="date" class="form-control" value="<?php echo $rowf['f_pago'] ?>" name="f_pago" id="f_pago">

                                                  </div>

                                                </div>

                                              </div>

                                            </div>

                                          </div>

                                        </div>

                                      </div>

                                    </div>

                                  </div>

                                  <div class="modal-footer">

                                    <a href="checklist.php"> <button type="button" class="btn btn-white">Cerrar</button></a>

                                    <button type="submit" class="btn btn-primary">Guardar cambios</button>

                                  </div>

                                </form>

                              </div><!-- div body-->

                            </div>

                          </div>

                        </div>

                        <!-- Modal-->

                      </td>

                      <?php

                      $id_pedido= $rowc['id_pedido'];

                      $query_f="SELECT  `id_check`,

                      `num_orden`,

                      `f_orden`,

                      `f_proforma`,

                      `f_anticipo`,

                      `f_verif_ant`,

                      `f_pago_ant`,

                      `f_produccion`,

                      f_embarque,

                      `f_producion_cant`,

                      `f_producion_color`,

                      `f_producion_empaque`,

                      `f_laps`,

                      `f_aprob_lap`,

                      `f_aprob_lap_tipo`,

                      `f_ini_prod`,

                      `f_fin_prod`,

                      `f_revision`,

                      `f_revision_tipo`,

                      `f_envio_informe`,

                      `f_shipping_sample`,

                      `f_aprob_sample`,

                      `f_aprob_sample_tipo`,

                      `f_cargue_zarpe`,

                      `f_cargue`,

                      `f_zarpe`,

                      `f_llegada`,

                      `f_revision_doc`,

                      `f_revision_doc_bl`,

                      `f_revision_doc_emp`,

                      `f_revision_doc_fact`,

                      `f_envio_doc`,

                      `f_balance`,

                      `f_balance_fab`,

                      `f_liberar`,

                      `f_liberar_tipo`,

                      `f_factura`,

                      `f_pago`

                      FROM `checklist`

                      WHERE `num_orden`='$id_pedido'";

                      $resultado_f=$conexion->query($query_f);

                      $row_f=$resultado_f->fetch_assoc();?>

                      <td>

                        <?php echo $rowc['orden']; ?>

                      </td>

                      <td >

                        <?php echo strtoupper($rowc['nombre']);?>

                      </td>

                      <td style="border-left:1px solid;">

                        <?php echo $rowc['fecha_pedido']; ?>

                      </td>

                      <!--Proforma-->

                      <?php  if ($rowc['fecha_pedido']=="") {

                        echo "<td></td>";

                      }else{

                        $startDateString = $rowc['fecha_pedido'];

                        if($row_f['f_proforma']==""){

                          $endDateString = date("Y-m-d");

                        }else{

                          $endDateString = $row_f['f_proforma'];

                        }

                        $format = 'Y-m-d';

                        $startDateTime = DateTime::createFromFormat($format, $startDateString);

                        $endDateTime = DateTime::createFromFormat($format, $endDateString);

                        $dateInterval = new DateInterval('P1D');

                        $days = new DatePeriod($startDateTime, $dateInterval, $endDateTime);

                        $total_dias=0;

                        foreach ($days as $day) {

                          $weekDay = $day->format('N');

                          $dia = $day->format('Y-m-d');

                          if ($weekDay !== 'XXXX' && $weekDay !== 'XX' ) {

                            $total_dias=$total_dias+1;

                          }

                        }

                        if($row_f['f_proforma']=="" && $total_dias>=1 ){

                          echo "<td class=rojo ></td>";

                        }else{

                          if ($total_dias<=0 && $row_f['f_proforma']=="") {

                            echo "<td ></td>";

                          }else{

                            echo "<td class=verde ></td>";

                          }

                        }

                      }

                      ?>

                      <!-- fecha Pago 1er Anticipo -->

                      <?php

                      if ($row_f['f_proforma']=="") {

                        echo "<td></td>";

                      }else{

                        $startDateString = $row_f['f_proforma'];

                        if ($row_f['f_anticipo']=="") {

                          $endDateString = date("Y-m-d");

                        }else{

                          $endDateString = $row_f['f_anticipo'];

                        }

                        $format = 'Y-m-d';

                        $startDateTime = DateTime::createFromFormat($format, $startDateString);

                        $endDateTime = DateTime::createFromFormat($format, $endDateString);

                        $dateInterval = new DateInterval('P1D');

                        $days = new DatePeriod($startDateTime, $dateInterval, $endDateTime);

                        $total_dias=0;

                        foreach ($days as $day) {

                          $weekDay = $day->format('N');

                          $dia = $day->format('Y-m-d');

                          if ($weekDay !== 'XXXX' && $weekDay !== 'XX' ) {

                            $total_dias=$total_dias+1;

                          }

                        }

                        if($row_f['f_anticipo']=="" && $total_dias>=1 ) {

                          echo "<td class=rojo ></td>";

                        }else{

                          if ($total_dias<=0 && $row_f['f_anticipo']=="") {

                            echo "<td ></td>";

                          }else{

                            echo "<td class=verde ></td>";

                          }

                        }

                      }

                      ?>




                      <!-- Verificaión de Pago 1er Anticipo-->

                      <?php

                      if ($row_f['f_anticipo']=="") {

                  //echo "<td></td>";

                      }else{

                        $startDateString = $row_f['f_anticipo'];

                        if($row_f['f_verif_ant']=="") {

                          $endDateString = date("Y-m-d");

                        }else{

                          $endDateString = $row_f['f_verif_ant'];

                        }

                        $format = 'Y-m-d';

                        $startDateTime = DateTime::createFromFormat($format, $startDateString);

                        $endDateTime = DateTime::createFromFormat($format, $endDateString);

                        $dateInterval = new DateInterval('P1D');

                        $days = new DatePeriod($startDateTime, $dateInterval, $endDateTime);

                        $total_dias=0;

                        foreach ($days as $day) {

                          $weekDay = $day->format('N');

                          $dia = $day->format('Y-m-d');

                          if ($weekDay !== 'XXXX' && $weekDay !== 'XX' ){

                            $total_dias=$total_dias+1;

                          }

                        }

                        if ($row_f['f_verif_ant']=="" && $total_dias>=1 ) {

                    //echo "<td class=rojo ></td>";

                        }else{

                          if ($total_dias<=0 && $row_f['f_verif_ant']=="") {

                      // echo "<td ></td>";

                          }else{

                      //   echo "<td class=verde ></td>";

                          }

                        }

                      }?>











                      <!-- Verificaión de Pago 1er Anticipo-->

                      <?php

                      if ($row_f['f_anticipo']=="") {

                  //echo "<td></td>";

                      }else{

                        $startDateString = $row_f['f_anticipo'];

                        if($row_f['f_pago_ant']=="") {

                          $endDateString = date("Y-m-d");

                        }else{

                          $endDateString = $row_f['f_pago_ant'];

                        }

                        $format = 'Y-m-d';

                        $startDateTime = DateTime::createFromFormat($format, $startDateString);

                        $endDateTime = DateTime::createFromFormat($format, $endDateString);

                        $dateInterval = new DateInterval('P1D');

                        $days = new DatePeriod($startDateTime, $dateInterval, $endDateTime);

                        $total_dias=0;

                        foreach ($days as $day) {

                          $weekDay = $day->format('N');

                          $dia = $day->format('Y-m-d');

                          if ($weekDay !== 'XXXX' && $weekDay !== 'XX' ){

                            $total_dias=$total_dias+1;

                          }

                        }

                        if ($row_f['f_pago_ant']=="" && $total_dias>=1 ) {

                    //echo "<td class=rojo ></td>";

                        }else{

                          if ($total_dias<=0 && $row_f['f_pago_ant']=="") {

                      // echo "<td ></td>";

                          }else{

                      //   echo "<td class=verde ></td>";

                          }

                        }

                      }?>







                      <!-- Verificaión de Pago Anticipo fabrica

                      <?php

                      if ($row_f['f_verif_ant']=="") {

                        echo "<td></td>";

                      }else{

                        $startDateString = $row_f['f_verif_ant'];

                        if ($row_f['f_pago_ant']=="") {

                          $endDateString = date("Y-m-d");

                        }else {

                          $endDateString = $row_f['f_pago_ant'];

                        }

                        $format = 'Y-m-d';

                        $startDateTime = DateTime::createFromFormat($format, $startDateString);

                        $endDateTime = DateTime::createFromFormat($format, $endDateString);

                        $dateInterval = new DateInterval('P1D');

                        $days = new DatePeriod($startDateTime, $dateInterval, $endDateTime);

                        $total_dias=0;

                        foreach ($days as $day) {

                          $weekDay = $day->format('N');

                          $dia = $day->format('Y-m-d');

                          if ($weekDay !== 'XXXX' && $weekDay !== 'XX' ) {

                            $total_dias=$total_dias+1;

                          }

                        }



                        if ($row_f['f_pago_ant']=="" && $total_dias>=0 ){

                          echo "<td class=rojo ></td>";

                        }else{

                          if ($total_dias<=0 && $row_f['f_pago_ant']==""){

                            echo "<td ></td>";

                          }else{

                            echo "<td class=verde ></td>";

                          }

                        }

                      }?>

                    -->





                      <!-- Generar orden de producción-->

                      <?php

                      if ($row_f['f_pago_ant']==""){

                        echo "<td></td>";

                      }else{

                        $startDateString = $row_f['f_pago_ant'];

                        if ($row_f['f_produccion']=="") {

                          $endDateString = date("Y-m-d");

                        }else{

                          $endDateString = $row_f['f_produccion'];

                        }

                        $format = 'Y-m-d';

                        $startDateTime = DateTime::createFromFormat($format, $startDateString);

                        $endDateTime = DateTime::createFromFormat($format, $endDateString);

                        $dateInterval = new DateInterval('P1D');

                        $days = new DatePeriod($startDateTime, $dateInterval, $endDateTime);

                        $total_dias=0;

                        foreach ($days as $day) {

                          $weekDay = $day->format('N');

                          $dia = $day->format('Y-m-d');

                          if ($weekDay !== 'XXXX' && $weekDay !== 'XX' ) {

                            $total_dias=$total_dias+1;

                          }

                        }

                        if ($row_f['f_produccion']=="" && $total_dias>=1 ) {

                          echo "<td class=rojo ></td>";

                        }else{

                          if ($total_dias<=0 && $row_f['f_produccion']=="") {

                            echo "<td ></td>";

                          }else{

                            echo "<td class=verde ></td>";

                          }

                        }

                      }?>

                      <!--Fecha de envío Lab dips/stike off-->

                      <?php

                      if ($row_f['f_produccion']=="") {

                        echo "<td></td>";

                      }else{

                        $startDateString = $row_f['f_produccion'];

                        if ($row_f['f_laps']=="") {

                          $endDateString = date("Y-m-d");

                        }else{

                          $endDateString = $row_f['f_laps'];

                        }

                        $format = 'Y-m-d';

                        $startDateTime = DateTime::createFromFormat($format, $startDateString);

                        $endDateTime = DateTime::createFromFormat($format, $endDateString);

                        $dateInterval = new DateInterval('P1D');

                        $days = new DatePeriod($startDateTime, $dateInterval, $endDateTime);

                        $total_dias=0;

                        foreach ($days as $day) {

                          $weekDay = $day->format('N');

                          $dia = $day->format('Y-m-d');

                          if ($weekDay !== 'XXXX' && $weekDay !== 'XX' ){

                            $total_dias=$total_dias+1;

                          }

                        }

                        if ($row_f['f_laps']=="" && $total_dias>=1 ) {

                          echo "<td class=rojo ></td>";

                        }else{

                          if ($total_dias<=0 && $row_f['f_laps']=="") {

                            echo "<td ></td>";

                          }else{

                            echo "<td class=verde ></td>";

                          }

                        }

                      }?>

                      <!--Fecha de aprobación Lab dips/stike off-->

                      <?php

                      if ($row_f['f_laps']==""){

                        echo "<td></td>";

                      }else{

                        $startDateString = $row_f['f_laps'];

                        if ($row_f['f_aprob_lap']=="") {

                          $endDateString = date("Y-m-d");

                        }else{

                          $endDateString = $row_f['f_aprob_lap'];

                        }

                        $format = 'Y-m-d';

                        $startDateTime = DateTime::createFromFormat($format, $startDateString);

                        $endDateTime = DateTime::createFromFormat($format, $endDateString);

                        $dateInterval = new DateInterval('P1D');

                        $days = new DatePeriod($startDateTime, $dateInterval, $endDateTime);

                        $total_dias=0;

                        foreach ($days as $day) {

                          $weekDay = $day->format('N');

                          $dia = $day->format('Y-m-d');

                          if ($weekDay !== 'XXXX' && $weekDay !== 'XX' ) {

                            $total_dias=$total_dias+1;

                          }

                        }

                        if ($row_f['f_aprob_lap']=="" && $total_dias>=1 ) {

                          echo "<td class=rojo ></td>";

                        }else{

                          if ($total_dias<=0 && $row_f['f_aprob_lap']=="") {

                            echo "<td ></td>";

                          }else{

                            echo "<td class=verde ></td>";

                          }

                        }

                      }?>

                      <!-- Fecha de inicio de Producción-->

                      <?php

                      if ($row_f['f_ini_prod']=="" && $row_f['f_aprob_lap']=="") {

                        echo "<td style='border-left:1px solid;'></td>";

                      }else{

                        if ($row_f['f_ini_prod']=="") {

                          echo "<td style='border-left:1px solid;' class=rojo ></td>";

                        }else{

                          echo "<td style='border-left:1px solid;' class=verde ></td>";

                        }

                      }

                      ?>

                      <!-- Generar embarque-->

                      <?php

                      if ($row_f['f_ini_prod']=="") {

                        echo "<td></td>";

                      }else{

                        $startDateString = $row_f['f_ini_prod'];

                        if ($row_f['f_embarque']=="") {

                          $endDateString = date("Y-m-d");

                        }else{

                          $endDateString = $row_f['f_embarque'];

                        }

                        $format = 'Y-m-d';

                        $startDateTime = DateTime::createFromFormat($format, $startDateString);

                        $endDateTime = DateTime::createFromFormat($format, $endDateString);

                        $dateInterval = new DateInterval('P1D');

                        $days = new DatePeriod($startDateTime, $dateInterval, $endDateTime);

                        $total_dias=0;

                        foreach ($days as $day) {

                          $weekDay = $day->format('N');

                          $dia = $day->format('Y-m-d');

                          if ($weekDay !== 'XXXX' && $weekDay !== 'XX' ) {

                            $total_dias=$total_dias+1;

                          }

                        }

                        if ($row_f['f_embarque']=="" && $total_dias>=0 ){

                          echo "<td class=rojo ></td>";

                        }else{

                          if ($total_dias<=0 && $row_f['f_embarque']=="") {

                            echo "<td ></td>";

                          }else{

                            echo "<td class=verde ></td>";

                          }

                        }

                      }?>

                      <!-- Fecha de fin de Producción-->

                      <?php

                      if ($row_f['f_fin_prod']=="" && $row_f['f_ini_prod']=="") {

                        echo "<td></td>";

                      }else{

                        if ($row_f['f_fin_prod']=="") {

                          echo "<td class=rojo ></td>";

                        }else{

                          echo "<td class=verde ></td>";

                        }

                      }

                      ?>

                      <!--Revisión mercancia-->

                      <?php

                      if ($row_f['f_fin_prod']=="") {

                        echo "<td ></td>";

                      }else{

                        $startDateString = $row_f['f_fin_prod'];

                        if ($row_f['f_revision']=="") {

                          $endDateString = date("Y-m-d");

                        }  else { $endDateString = $row_f['f_revision']; }

                        $format = 'Y-m-d';

                        $startDateTime = DateTime::createFromFormat($format, $startDateString);

                        $endDateTime = DateTime::createFromFormat($format, $endDateString);

                        $dateInterval = new DateInterval('P1D');

                        $days = new DatePeriod($startDateTime, $dateInterval, $endDateTime);

                        $total_dias=0;

                        foreach ($days as $day) {

                          $weekDay = $day->format('N');

                          $dia = $day->format('Y-m-d');

                          if ($weekDay !== 'XXXX' && $weekDay !== 'XX' ) {

                            $total_dias=$total_dias+1;

                          }

                        }

                        if ($row_f['f_revision']=="" && $total_dias>=1 ) {

                          echo "<td class=rojo ></td>";

                        }else{

                          if ($total_dias<=0 && $row_f['f_revision']==""){

                            echo "<td ></td>";

                          }else{

                            echo "<td class=verde ></td>";

                          }

                        }

                      }?>

                      <!--Envío informe-->

                      <?php

                      if ($row_f['f_revision']=="") {

                        echo "<td></td>";

                      }else{

                        $startDateString = $row_f['f_revision'];

                        if ($row_f['f_envio_informe']=="") {

                          $endDateString = date("Y-m-d");

                        } else {

                          $endDateString = $row_f['f_envio_informe'];

                        }

                        $format = 'Y-m-d';

                        $startDateTime = DateTime::createFromFormat($format, $startDateString);

                        $endDateTime = DateTime::createFromFormat($format, $endDateString);

                        $dateInterval = new DateInterval('P1D');

                        $days = new DatePeriod($startDateTime, $dateInterval, $endDateTime);

                        $total_dias=0;

                        foreach ($days as $day) {

                          $weekDay = $day->format('N');

                          $dia = $day->format('Y-m-d');

                          if ($weekDay !== 'XXXX' && $weekDay !== 'XX' ) {

                            $total_dias=$total_dias+1;

                          }

                        }

                        if ($row_f['f_envio_informe']=="" && $total_dias>=1 ) {

                          echo "<td class=rojo ></td>";

                        }else{

                          if ($total_dias<=0 && $row_f['f_envio_informe']=="") {

                            echo "<td ></td>";

                          }else{

                            echo "<td class=verde ></td>";

                          }

                        }

                      }?>

                      <!--Envío de shipping sample-->

                      <?php

                      if ($row_f['f_envio_informe']=="") {

                        echo "<td></td>";

                      }else{

                        $startDateString = $row_f['f_envio_informe'];

                        if($row_f['f_shipping_sample']=="") {

                          $endDateString = date("Y-m-d");

                        }else {

                          $endDateString = $row_f['f_shipping_sample'];

                        }

                        $format = 'Y-m-d';

                        $startDateTime = DateTime::createFromFormat($format, $startDateString);

                        $endDateTime = DateTime::createFromFormat($format, $endDateString);

                        $dateInterval = new DateInterval('P1D');

                        $days = new DatePeriod($startDateTime, $dateInterval, $endDateTime);

                        $total_dias=0;

                        foreach ($days as $day) {

                          $weekDay = $day->format('N');

                          $dia = $day->format('Y-m-d');

                          if ($weekDay !== 'XXXX' && $weekDay !== 'XX' ) {

                            $total_dias=$total_dias+1;

                          }

                        }

                        if ($row_f['f_shipping_sample']=="" && $total_dias>=1 ) {

                          echo "<td class=rojo ></td>";

                        }else{

                          if ($total_dias<=0 && $row_f['f_shipping_sample']=="") {

                            echo "<td ></td>";

                          }else{

                            echo "<td class=verde ></td>";

                          }

                        }

                      }?>

                      <!-- fecha de cargue-->

                      <?php

                      if ($row_f['f_cargue']=="" && $row_f['f_shipping_sample']=="") {

                        echo "<td style='border-left:1px solid;'></td>";

                      } else {

                        if ($row_f['f_cargue']=="") {

                          echo "<td style='border-left:1px solid;' class=rojo ></td>";

                        }else{

                          echo "<td style='border-left:1px solid;' class=verde ></td>";

                        }

                      }

                      ?>

                      <!-- fecha de zarpe-->

                      <?php

                      if ($row_f['f_zarpe']=="" && $row_f['f_cargue']=="") {

                        echo "<td></td>";

                      } else {

                        if ($row_f['f_zarpe']=="") {

                          echo "<td class=rojo ></td>";

                        }else{

                          echo "<td class=verde ></td>";

                        }

                      }

                      ?>

                      <!--fecha de llegada-->

                      <?php

                      if ($row_f['f_zarpe']=="") {

                        echo "<td></td>";

                      }else{

                        $startDateString = $row_f['f_zarpe'];

                        if ($row_f['f_llegada']=="") {

                          $endDateString = date("Y-m-d");

                        }else {

                          $endDateString = $row_f['f_llegada'];

                        }

                        $format = 'Y-m-d';

                        $startDateTime = DateTime::createFromFormat($format, $startDateString);

                        $endDateTime = DateTime::createFromFormat($format, $endDateString);

                        $dateInterval = new DateInterval('P1D');

                        $days = new DatePeriod($startDateTime, $dateInterval, $endDateTime);

                        $total_dias=0;

                        foreach ($days as $day) {

                          $weekDay = $day->format('N');

                          $dia = $day->format('Y-m-d');

                          if ($weekDay !== 'XXXX' && $weekDay !== 'XX' ) {

                            $total_dias=$total_dias+1;

                          }

                        }

                        if ($row_f['f_llegada']=="" && $total_dias>=1 ) {

                          echo "<td class=rojo ></td>";

                        }else{

                          if ($total_dias<=0 && $row_f['f_llegada']=="") {

                            echo "<td ></td>";

                          }else{

                            echo "<td class=verde ></td>";

                          }

                        }

                      }?>

                      <!--Revision de doc  -->

                      <?php

                      if ($row_f['f_zarpe']=="") {

                        echo "<td></td>";

                      }else{

                        $startDateString = $row_f['f_zarpe'];

                        if ($row_f['f_revision_doc']=="") {

                          $endDateString = date("Y-m-d");

                        }else {

                          $endDateString = $row_f['f_revision_doc'];

                        }

                        $format = 'Y-m-d';

                        $startDateTime = DateTime::createFromFormat($format, $startDateString);

                        $endDateTime = DateTime::createFromFormat($format, $endDateString);

                        $dateInterval = new DateInterval('P1D');

                        $days = new DatePeriod($startDateTime, $dateInterval, $endDateTime);

                        $total_dias=0;

                        foreach ($days as $day) {

                          $weekDay = $day->format('N');

                          $dia = $day->format('Y-m-d');

                          if ($weekDay !== 'XXXX' && $weekDay !== 'XX' ) {

                            $total_dias=$total_dias+1;

                          }

                        }

                        if ($row_f['f_revision_doc']=="" && $total_dias>=1 ) {

                          echo "<td class=rojo ></td>";

                        }else{

                          if ($total_dias<=0 && $row_f['f_revision_doc']=="") {

                            echo "<td ></td>";

                          }else{

                            echo "<td class=verde ></td>";

                          }

                        }

                      }?>

                      <!-- Fecha envio doc-->

                      <?php

                      if ($row_f['f_zarpe']=="") {

                        echo "<td></td>";

                      } else {

                        $startDateString = $row_f['f_zarpe'];

                        if ($row_f['f_envio_doc']=="") {

                          $endDateString = date("Y-m-d");

                        } else {

                          $endDateString = $row_f['f_envio_doc'];

                        }

                        $format = 'Y-m-d';

                        $startDateTime = DateTime::createFromFormat($format, $startDateString);

                        $endDateTime = DateTime::createFromFormat($format, $endDateString);

                        $dateInterval = new DateInterval('P1D');

                        $days = new DatePeriod($startDateTime, $dateInterval, $endDateTime);

                        $total_dias=0;

                        foreach ($days as $day) {

                          $weekDay = $day->format('N');

                          $dia = $day->format('Y-m-d');

                          if ($weekDay !== 'XXXX' && $weekDay !== 'XX' ) {

                            $total_dias=$total_dias+1;

                          }

                        }

                        if ($row_f['f_envio_doc']=="" && $total_dias>=1 ) {

                          echo "<td class=rojo ></td>";

                        }else{

                          if ($total_dias<=0 && $row_f['f_envio_doc']=="") {

                            echo "<td ></td>";

                          }else{

                            echo "<td class=verde ></td>";

                          }

                        }

                      }?>

                      <!-- Fecha pago balance-->

                      <?php

                      if ($row_f['f_zarpe']=="") {

                        echo "<td></td>";

                      }else {

                        $startDateString = $row_f['f_zarpe'];

                        if ($row_f['f_balance']=="") {

                          $endDateString = date("Y-m-d");

                        } else {

                          $endDateString = $row_f['f_balance'];

                        }

                        $format = 'Y-m-d';

                        $startDateTime = DateTime::createFromFormat($format, $startDateString);

                        $endDateTime = DateTime::createFromFormat($format, $endDateString);

                        $dateInterval = new DateInterval('P1D');

                        $days = new DatePeriod($startDateTime, $dateInterval, $endDateTime);

                        $total_dias=0;

                        foreach ($days as $day) {

                          $weekDay = $day->format('N');

                          $dia = $day->format('Y-m-d');

                          if ($weekDay !== 'XXXX' && $weekDay !== 'XX' ) {

                            $total_dias=$total_dias+1;

                          }

                        }

                        if ($row_f['f_balance']=="" && $total_dias>=1 ) {

                          echo "<td class=rojo ></td>";

                        }else{

                          if ($total_dias<=20 && $row_f['f_balance']=="") {

                           echo "<td ></td>";

                         }else{

                           echo "<td class=verde ></td>";

                         }

                       }

                     }?>

                     <!-- Fecha pago balance-->

                     <?php

                     if ($row_f['f_balance']=="") {

                      echo "<td></td>";

                    } else {

                      $startDateString = $row_f['f_balance'];

                      if ($row_f['f_balance_fab']=="") {

                        $endDateString = date("Y-m-d");

                      } else {

                        $endDateString = $row_f['f_balance_fab'];

                      }



                      $format = 'Y-m-d';

                      $startDateTime = DateTime::createFromFormat($format, $startDateString);

                      $endDateTime = DateTime::createFromFormat($format, $endDateString);

                      $dateInterval = new DateInterval('P1D');

                      $days = new DatePeriod($startDateTime, $dateInterval, $endDateTime);

                      $total_dias=0;

                      foreach ($days as $day) {

                        $weekDay = $day->format('N');

                        $dia = $day->format('Y-m-d');

                        if ($weekDay !== 'XXXX' && $weekDay !== 'XX' ) {

                          $total_dias=$total_dias+1;

                        }

                      }

                      if ($row_f['f_balance_fab']=="" && $total_dias>=1 ) {

                        echo "<td class=rojo ></td>";

                      } else  {

                        if ($total_dias<=20 && $row_f['f_balance_fab']=="") {

                         echo "<td ></td>";

                       } else {

                         echo "<td class=verde ></td>";

                       }

                     }

                   }?>

                   <!-- Fecha liberar-->

                   <?php

                   if ($row_f['f_balance']=="") {

                    echo "<td></td>";

                  } else {

                    $startDateString = $row_f['f_balance'];

                    if ($row_f['f_liberar']=="") {

                      $endDateString = date("Y-m-d");

                    } else {

                      $endDateString = $row_f['f_liberar'];

                    }

                    $format = 'Y-m-d';

                    $startDateTime = DateTime::createFromFormat($format, $startDateString);

                    $endDateTime = DateTime::createFromFormat($format, $endDateString);

                    $dateInterval = new DateInterval('P1D');

                    $days = new DatePeriod($startDateTime, $dateInterval, $endDateTime);

                    $total_dias=0;

                    foreach ($days as $day) {

                      $weekDay = $day->format('N');

                      $dia = $day->format('Y-m-d');

                      if ($weekDay !== 'XXXX' && $weekDay !== 'XX' ) {

                        $total_dias=$total_dias+1;

                      }

                    }

                    if ($row_f['f_liberar']=="" && $total_dias>=1 ) {

                      echo "<td class=rojo ></td>";

                    } else {

                      if ($total_dias<=0 && $row_f['f_liberar']=="") {

                       echo "<td ></td>";

                     } else {

                       echo "<td class=verde ></td>";

                     }

                   }

                 } ?>

                 <!-- Fecha factura-->

                 <?php

                 if ($row_f['f_balance']=="") {

                  echo "<td></td>";

                } else {

                  $startDateString = $row_f['f_balance'];

                  if ($row_f['f_factura']=="") {

                    $endDateString = date("Y-m-d");

                  } else {

                    $endDateString = $row_f['f_factura'];

                  }

                  $format = 'Y-m-d';

                  $startDateTime = DateTime::createFromFormat($format, $startDateString);

                  $endDateTime = DateTime::createFromFormat($format, $endDateString);

                  $dateInterval = new DateInterval('P1D');

                  $days = new DatePeriod($startDateTime, $dateInterval, $endDateTime);

                  $total_dias=0;

                  foreach ($days as $day) {

                    $weekDay = $day->format('N');

                    $dia = $day->format('Y-m-d');

                    if ($weekDay !== 'XXXX' && $weekDay !== 'XX' ) {

                      $total_dias=$total_dias+1;

                    }

                  }

                  if ($row_f['f_factura']=="" && $total_dias>=1 ) {

                    echo "<td class=rojo ></td>";

                  } else  {

                    if ($total_dias<=0 && $row_f['f_factura']=="") {

                      echo "<td ></td>";

                    } else {

                      echo "<td class=verde ></td>";

                    }

                  }

                }?>

                <!-- fecha de pago comision-->

                <?php

                if ($row_f['f_factura']=="" && $row_f['f_pago']=="") {

                  echo "<td></td>";

                } else {

                  if ($row_f['f_pago']=="") {

                    echo "<td class=rojo ></td>";

                  }else{

                    echo "<td class=verde ></td>";

                  }

                }?>

                <td style='border-left:1px solid;'></td>

                <td >

                  <a href="#"

                  data-toggle="modal"

                  data-target="#myModal_pgrw_<?php echo $rowc['id_pedido'] ;$pedido=$pedido2=$rowc['id_pedido'];?>">

                  <i class="fa fa-search"></i>

                  <!--AQUI MODAL-->

                </a>

                <div class="modal inmodal" id="myModal_pgrw_<?php echo $rowc['id_pedido'] ?>" tabindex="-1" role="dialog" aria-hidden="true">

                  <div class="modal-dialog">

                    <div class="modal-content animated bounceInRight">

                      <div class="modal-header" style="text-align: left">

                        <h4 class="modal-title"><img alt="Logo" src="img/logo.png" height="10%" width="10%">Detalles Orden de Producción</h4>

                      </div>

                      <div class="modal-body">







                        <!--/*INICIO PGRW*/-->

                        <div id="resultado_detalles_<?php echo $pedido ?>" style="margin-top: 20px">

                          <table width='100%' border='1' style='border-collapse: collapse;' class='table table-bordered table-condensed table-hover'>

                            <?php

                            $referencias  = [];

                            $query_referencias="SELECT cap_ref,um_ref,peso_ref,ancho_ref,nombre_ref FROM `referencias`";

                            $resultadoc_referencias=$conexion->query($query_referencias);

                            while ($rowc_items=$resultadoc_referencias->fetch_assoc()) {

                              $referencias[$rowc_items["nombre_ref"]]  =    $rowc_items["cap_ref"];

                            }



                                                            // echo '<pre>';

                                                            //   print_r($referencias);

                                                            // echo '</pre>';





                            $query_items="SELECT id_item, nombre, descripcion, supplier, um FROM `pedidos_items` inner join clientes on id=supplier where orden_pedido ='$pedido' order by nombre asc";

                            $supliern="";

                            $i=0;

                            $resultadoc_items=$conexion->query($query_items);

                            while ($rowc_items=$resultadoc_items->fetch_assoc()) {

                              $Total=0;

                              $Total2=0;

                              $pedido=$rowc_items['id_item'];

                              $consulta_color="SELECT `id_pedidos_color`, `id_pedidos_items`, `color`, pedidos_items_color.`quantity` quantity, nombre_ref, descripcion FROM `pedidos_items_color` inner join pedidos_items on id_item=id_pedidos_items inner join referencias on descripcion=id_ref where id_pedidos_items ='$pedido' order by color asc";

                              $resultado_color=$conexion-> query ($consulta_color);

                              $supliern2=$rowc_items['nombre'];

                              $consult_total="SELECT sum(pedidos_items_color.quantity) quantity FROM `pedidos_items_color` inner join pedidos_items on id_item=id_pedidos_items inner join clientes on id=supplier where nombre='$supliern2' and orden_pedido ='$pedido2' ";

                              $resultado_total=$conexion-> query ($consult_total);

                              $row_total=$resultado_total->fetch_assoc();

                              $Total=$row_total['quantity'];

                              if($supliern2!=$supliern){

                                echo "

                                <tr>

                                <td colspan='8' >Detalles de la orden </td>

                                </tr>

                                <tr>

                                <td align=center width=10%  style='background: rgba(145, 140, 142, 0.15); font-weight: bold;' colspan=2>Referencia</td>

                                <td align=center width=10%  style='background: rgba(145, 140, 142, 0.15); font-weight: bold;' colspan=2>Color.</td>

                                <td align=center width=15%  style='background: rgba(145, 140, 142, 0.15); font-weight: bold;'>Qty</td>

                                <td align=center width=15%  style='background: rgba(145, 140, 142, 0.15); font-weight: bold;'>CBM</td>

                                <td align=center width=15%  style='background: rgba(145, 140, 142, 0.15); font-weight: bold;'>%</td>

                                </tr>

                                ";

                                $i=0;

                                ?>

                                <!-- Modal-->

















                                <!-- Modal purchase-->

                                <div class="modal inmodal" id="myModal_purchase_<?php echo $pedido ?>" tabindex="-1" role="dialog" aria-hidden="true" >

                                 <div class="modal-dialog modal-xs" style="width: 550px">

                                   <div class="modal-content animated bounceInRight">

                                    <div class="modal-header" style="text-align: left">

                                      <h4 class="modal-title"><img alt="Logo" src="img/logo.png" height="10%" width="10%"> Generar Purchase Order</h4>

                                    </div>



                                    <form action="imprimir_detalle.php" method="get" target="_blank">

                                      <div class="modal-body">

                                        <input type="hidden" name="id_supplier" value="<?php echo $rowc_items['supplier'] ?>">

                                        <input type="hidden" name="id" value="<?php echo $pedido2 ?>">

                                        <div class="form-group">

                                          <div class="row">

                                            <div class="col-md-12">

                                              <label>Date</label><br>

                                              <input type="date" class="form-control" name="date">

                                            </div>

                                          </div>

                                        </div>

                                      </div><!-- div body-->



                                      <div class="modal-footer">

                                       <button data-toggle="modal" data-target="#myModal_purchase_<?php echo $pedido ?>" type="button" class="btn btn-white">Cerrar</button>

                                       <button type="submit" class="btn btn-primary" data-toggle="modal" data-target="#myModal_purchase_<?php echo $pedido ?>">Generar</button>

                                     </div>

                                   </form>

                                 </div>

                               </div>

                             </div>

                             <!-- Modal purchase-->

                             <?php



                           }



                           $refn="";

                           $supliern2="";

                           $contador=1;


                           while ($row_color=$resultado_color->fetch_assoc()){



                            $refn2=$row_color['nombre_ref'];

                            if ($refn2!=$refn)

                            {


                              $supliern=$rowc_items['nombre'];

                              $i=$i+1;



                              echo "<tr>

                            

                              <td align=center height=25px align=center colspan=2> ".$row_color['nombre_ref']."</td>                                      

                              <td align=center height=25px colspan=2 >".$row_color['color']."</td>

                              <td align=center height=25px>".number_format($row_color['quantity'],0,".",","). " " .$rowc_items['um']."</td>

                              <td align=center height=25px>".number_format(($row_color['quantity'] * 68 )/$referencias[$row_color['nombre_ref']],2,".",",")."</td>

                              <td align=center height=25px>".number_format(($row_color['quantity'] * 100 )/$referencias[$row_color['nombre_ref']],2,".",",")."</td>

                              <tr>";

                              $contador++;


                            }


                            else

                            {

                              echo "<tr>

                              <td align=center height=25px style='border:none' colspan=2 ></td>

                              

                              <td align=center height=25px colspan=2 >".$row_color['color']."</td>

                              <td align=center height=25px>".number_format($row_color['quantity'],0,".",","). " " .$rowc_items['um']."</td>

                              <td align=center height=25px>".number_format(($row_color['quantity'] * 68 )/$referencias[$row_color['nombre_ref']],2,".",",")."</td>

                              <td align=center height=25px>".number_format(($row_color['quantity'] * 100 )/$referencias[$row_color['nombre_ref']],2,".",",")."</td>

                              </tr>";
                              $contador++;


                          }//fin while



                          $refn=$row_color['nombre_ref'];

                          $Total2= $Total2 + $row_color['quantity'];

                          $Total3= $Total3 + ($row_color['quantity'] * 68 )/$referencias[$row_color['nombre_ref']];

                          $Total4= $Total4 + ($row_color['quantity'] * 100 )/$referencias[$row_color['nombre_ref']];

                        }

                        if ($supliern2!=$supliern)

                        {

if ($rowc_items['um']=='KILOS') {
 $rowc_items['um']='';
}

                          echo "<tr style='background: rgba(145, 140, 142, 0.15); font-weight: bold;'>

                          <td align=center height=25px style='border:none' align=center colspan=2></td>

                          

                          <td align=center height=25px colspan=2 >TOTAL</td>

                          <td align=center height=25px>".number_format($Total2,0,".",",")." " .$rowc_items['um']."</td>

                          <td align=center height=25px>".number_format($Total3,2,".",",")." " .$rowc_items['um']."</td>

                          <td align=center height=25px>".number_format($Total4,2,".",",")." %</td>

                          <tr>";



                        }

$Total3='';
$Total4='';

                        $supliern=$rowc_items['nombre'];


                      }

                      ?>

                    </table>

                  </div>

                  <!--/*FIN PGRW*/-->

































                </div>

                <div class="modal-footer">

                 <button data-toggle="modal" data-target="#myModal_pgrw_<?php echo $rowc['id_pedido'] ?>" type="button" class="btn btn-white">Cerrar</button>

               </div>

             </div>

           </div>

         </div>

       </td>

       <?php echo "<td style='border-right: 1px solid;'></td>"; ?>

     </tr>

     <?php

   }

 }?>

</tr>

<tr>

  <td colspan="29" style='border-top:1px solid;'></td>

</tr>

</tbody>

</table>

</div>

</div>

</div>

</div>

</div>

<?php include("footer.php"); ?>

</div>

</div>

<?php include("script.php"); ?>

<script type="text/javascript">

<?php

if (isset($_GET['id'])) {

  ?>

  $('#myModal').modal('show');

  <?php }?>

  </script>

</body>

</html>

