 <?php $r="../";
$id=$_GET['id'];
require_once($r."inc/funciones.php");
validNotSession($r);
$mysqli = connectDB($r);
$spe=$_SESSION['perfil'];if($spe!=$psu && $spe!=$pad){ exit(header("Location:".$r."dashboard.php?error=NO TIENES PERMISO PARA ESTA SECCION"));}
$row1 = $mysqli->query("SELECT * FROM z_dproveedor WHERE idproveedor='$id'");
$arraycodigopedidos = array();
?>
<!DOCTYPE html>
<html lang="en">
  <?php include $r."inc/head.php"; ?>
  <style>
      .container-fluid{padding-right:5px;padding-left:5px;}
  </style>
<body class="fixed-nav sticky-footer sidenav-toggled bg-dark" id="page-top">
  <?php include $r."inc/nav.php"; ?>
  <div class="content-wrapper">
    <div class="container-fluid">
      <div class="card mb-3">
        <div class="h3 card-header">
          <i class="fa fa-table"></i> INERSIONES POR PAGAR DE <? $proveedor=sprove($id); echo $proveedor['nombre']; ?></div>
        <div class="card-body">
          <div class="table-responsive">
            <table class="table table-bordered" width="100%" cellspacing="0">
              
              <thead>
                <tr>
                  <th>Codigo de pedido</th>
                  <th>Abono</th>
                  <th>Valor factura</th>
                  <th>Total a Pagar</th>
                  <th id="select" width="150px"></th>
                </tr>
              </thead>
              <tbody>
                  <form id="formulario" action="acciones.php" method="POST">
                      <input type="hidden" name="pagos" value="si">
                      <input type="hidden" name="idproveedor" value="<? echo $proveedor['id']; ?>">
                <?
                  while($row2 = $row1->fetch_assoc()) {
                    $item=$row2['id'];
                    $codigo=$row2['codigofactura'];
                    array_push($arraycodigopedidos,$item);  
                    $total=$row2['valor'];
                    $abono=$row2['abono'];
                    $proveedor=$row2['idrpoveedor']; ?><tr>
                        <td><?echo $codigo;?></td>
                        <td><a id="verpedido" class="text-primary" data-toggle="modal" data-target="#a<?php echo $item ?>"><? echo $abono;?></a></td>
                        <td class="text-danger h6 text-right">$ <? echo number_format($total); ?> COP</td>
                        <td class="text-danger h6 text-right">$ <? echo number_format($total-$abono);$t=$total-$abono ?> COP<? $total2=$total2+$t; $total=0; ?></td>
                        <td></td>
                    </tr>
                    
                 
                <?}?>
              </tbody>
                <tfoot>
                    <tr>
                  <th></th>
                  <th></th>
                    <td class="text-right h6"><b>SUMA TOTAL</b></td>
                    <td class="text-danger h6 text-right"><b>$ <? echo number_format($total2); ?> COP</b></td>
                  <th></th>
                    </tr>
                </tfoot>
            </table>
          </div>
        </div>
        <span id="abo"></span>
        
              <div class="text-center">
                  <a href="javascript:history.back(1)" class="btn btn-primary">ATRAS</a>
        <button type="submit" class="btn btn-success">COBRAR</button>
        </div>
                </form>
      </div>
    </div>
  </div>
<?  foreach($arraycodigopedidos as $key => $item){?>
   <!-- Modal -->
<div class="modal fade" id="a<?php echo $item ?>" tabindex="-1" role="dialog" aria-labelledby="verpedidoLabel" aria-hidden="true">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title" id="verpedidoLabel">Detalle del Pedido<span id="code"> <?php echo $item ?></span></h5>
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div id="verpedido">
          
          <?  $pedidos = $mysqli->query("SELECT * FROM z_aproveedores WHERE idcodigo=$item");
    $rmodal.='<table style="width:100%" class="table">
          <thead>
            <tr>
              <th>USUARIO</th>
              <th>ABONO</th>
              <th>FECHA</th>
            </tr>
          </thead>
          <tbody>';
    while ($ped = $pedidos->fetch_assoc()){
        $rmodal.='<tr><td>'.$ped['iduser'].'</a><br/></td>';
        $rmodal.='<td>'.$ped['abono'].'</a><br/></td>';
        $rmodal.='<td>'.$ped['fecha'].'<br/></td></tr>';
    }
        $rmodal.='<tr><td><br/></td>';
        $rmodal.='<td>Direccion<br/></td>';
        $rmodal.='<td class="text-danger"><b>'.$proveedor['direccion'].'</b><br/></td></tr>';
    $rmodal.='</tbody>
        </table>';  echo $rmodal;$rmodal=""; ?>
      </div>
    </div>
  </div>
</div><? } ?>
  <?php include $r."inc/foot.php"; ?>
  <script type="text/javascript">
function sumar(){
        var abono = $("#abono").val();
        if(abono==''){}
        var total=0;
        var total2=0;
        $("input:checkbox:checked").each(function() {
             var valor=$(this).val();
             total+=parseInt(valor);
             total2= total-parseInt(abono);
        });
        $('#TOTAL').html(total).slideDown(400);
        $('#TOTAL2').html(total2).slideDown(400);
        $('#abo').html('<input form="formulario" type="hidden" name="abonos" value="'+total2+'"/>').slideDown(400);
}
</script>
</body>
</html>    
    
 