                <!-- Content Header (Page header) -->
                <section class="content-header">
                    <h1>
                      Editar factura
                    </h1>
                    <ol class="breadcrumb">
                        <li><a href="<?=base_index();?>"><i class="fa fa-dashboard"></i> Inicio</a></li>
                        <li><a href="<?=base_index();?>nuevafactura">factura</a></li>
                        <li class="active">Editar factura</li>
                    </ol>
                </section>

                <!-- Main content -->
                <section class="content">
<div class="row">
    <div class="col-lg-12">
        <div class="box box-solid box-primary">
                                   <div class="box-header">
                                    <h3 class="box-title">Editar Nuevafactura</h3>
                                    <div class="box-tools pull-right">
                                        <button class="btn btn-info btn-sm" data-widget="collapse"><i class="fa fa-minus"></i></button>
                                        <button class="btn btn-info btn-sm" data-widget="remove"><i class="fa fa-times"></i></button>
                                    </div>
                                </div>

                  <div class="box-body">
                     <form id="update" method="post" class="form-horizontal" action="<?=base_admin();?>modul/nuevafactura/nuevafactura_action.php?act=up">
                      <?php switch ($data_edit->estado) {
                        case 'D':
                          echo '<div class="pad margin no-print">
                            <div class="callout callout-danger" style="margin-bottom: 0!important;">
                              <h4><i class="fa fa-info"></i> Nota:</h4>
                              Factura no pagada.
                            </div>
                          </div>';
                          break;
                        case 'P':
                          echo '<div class="pad margin no-print">
                            <div class="callout callout-success" style="margin-bottom: 0!important;">
                              <h4><i class="fa fa-info"></i> Nota:</h4>
                              Factura Pagada.
                            </div>
                          </div>';
                          break;
                        case 'A':
                          echo '<div class="pad margin no-print">
                            <div class="callout callout-warning" style="margin-bottom: 0!important;">
                              <h4><i class="fa fa-warning"></i> Nota:</h4>
                              Factura Anulada.
                            </div>
                          </div>';
                          break;
                        
                        default:
                          # code...
                          break;
                      } ?>
                      

    <!-- Main content -->
    <section class="invoice">
      <!-- title row -->
      <div class="row">
        <div class="col-xs-12">
          <h2 class="page-header">
            <strong class="pull-right" style="color:red;">Factura #<?=$data_edit->numfact?></strong><br>
            <small class="pull-right">Fecha: <?=$data_edit->fecha?></small><br>
            <?php if ($data_edit->estado == "A"){ ?>
             <div class="form-group col-lg-3 pull-right">
                        <div class="input-group">
                          <div class="input-group-addon">
                            <i class="fa fa-check"></i>
                          </div>
                          <select name="estado" data-placeholder="Seleccione estado..." class="form-control chzn-select" tabindex="2" disabled>
                           <?php switch ($data_edit->estado) {
                              case 'D':
                                echo '<option value="$data_edit->estado">Sin Pagar</option>';
                                break;
                              case 'P':
                                echo '<option value="$data_edit->estado">Pagada</option>';
                                break;
                              case 'A':
                                echo '<option value="$data_edit->estado">Anulada</option>';
                                break;
                              
                              default:
                                # code...
                                break;
                            } ?>
                           <option value="D">Sin Pagar</option>
                           <option value="P">Pagada</option>
                           <option value="A">Anulada</option>
                          </select>                           
                        </div>
                      </div><!-- /.form-group --> 
            <?php }else{ ?>
            <div class="form-group col-lg-3 pull-right">
                        <div class="input-group">
                          <div class="input-group-addon">
                            <i class="fa fa-check"></i>
                          </div>
                          <select name="estado" data-placeholder="Seleccione estado..." class="form-control chzn-select" tabindex="2" >
                           <?php switch ($data_edit->estado) {
                              case 'D':
                                echo '<option value="$data_edit->estado">Sin Pagar</option>';
                                break;
                              case 'P':
                                echo '<option value="$data_edit->estado">Pagada</option>';
                                break;
                              case 'A':
                                echo '<option value="$data_edit->estado">Anulada</option>';
                                break;
                              
                              default:
                                # code...
                                break;
                            } ?>
                           <option value="D">Sin Pagar</option>
                           <option value="P">Pagada</option>
                           <option value="A">Anulada</option>
                          </select>                           
                        </div>
                      </div><!-- /.form-group -->
                    <?php } ?>
            <!--<img src="../../../../upload/empresa/logo.png" alt="logo" style="margin-top:-10px;">-->
            <div><strong>GLITTER MAKE UP</strong></div><br>
          </h2>
        </div>
        <!-- /.col -->
      </div>
      <!-- info row -->
      <div class="row invoice-info">
        <div class="col-sm-6 invoice-col">
          <address>
            <?php foreach ($db->fetch_all('empresa') as $emp) { ?>
            <strong><?=$emp->nombre?></strong><br>
            NIT:<?=$emp->nit?><br>
            <?=$emp->direccion?><br>
            <?=$emp->departamento?>-<?=$emp->ciudad?><br>
            Tel: <?=$emp->tel?><br>
            <?php } ?> 
          </address>
        </div>
        <!-- /.col -->
        <div class="col-sm-3 invoice-col col-sm-offset-3">
          Facturado A
          <address>  
          <?php foreach ($db->fetch_custom('SELECT
clientes.idclientes,
clientes.ciudad_idciudad,
clientes.identificacion,
clientes.nombres,
clientes.apellidos,
clientes.direccion,
clientes.tel,
clientes.cel,
clientes.email,
clientes.fechana,
ciudad.ciudad
FROM
clientes
INNER JOIN ciudad ON clientes.ciudad_idciudad = ciudad.idciudad
            WHERE idclientes="'.$data_edit->clientes_idclientes.'"') as $cli) { 
            ?>
            <strong><?=$cli->nombres?> <?=$cli->apellidos?></strong><br>
            <?=$cli->direccion?><br>
            <?=$cli->ciudad?><br>
            Tel: <?=$cli->tel?><br>
            Email: <?=$cli->email?>
          <?php } ?>          
                                   
          </address>
        </div>
        <!-- /.col
        <div class="col-sm-4 invoice-col">
          <b>Invoice #007612</b><br>
          <br>
          <b>Order ID:</b> 4F3S8J<br>
          <b>Payment Due:</b> 2/22/2014<br>
          <b>Account:</b> 968-34567
        </div>-->
        <!-- /.col -->
      </div>
      <!-- /.row -->

      <!-- Table row -->
      <div class="row">
        <div class="col-xs-12 table-responsive">
          <table id="dtb_manual" class="table table-bordered table-striped">
                                   <thead>
                                     <tr>
                           <th style="width:25px" align="center">No</th>
                          <th>Nombre</th>
                          <th>Cantidad</th>
                          <th>Valor Unit.</th>
                          <th>Descuento</th>
                          <th>Valor</th>
                         
                        </tr>
                                      </thead>
                                        <tbody>
                                         <?php 
      $dtb=$db->fetch_custom("SELECT
factura_detalle.precio_venta,
factura_detalle.cantidad,
factura_detalle.des,
productos.nombre
FROM
factura_detalle ,
productos
WHERE
factura_detalle.numfact = '".$data_edit->numfact."' AND
factura_detalle.id_producto = productos.idproductos");
      $i=1;
      foreach ($dtb as $isi) {
        ?><tr id="line_<?=$isi->idfactura;?>">
        <td align="center"><?=$i;?></td><td><?=$isi->nombre;?></td>
<td><?=$isi->cantidad;?></td>
<td><?=$isi->des+$isi->precio_venta;?></td>
<td><?=$isi->des;?></td>
<td><?=$isi->precio_venta;?></td>
        </tr>
        <?php
        $i++;
      }
      ?>
                                        </tbody>
                                    </table>
        </div>
        <!-- /.col -->
      </div>
      <!-- /.row -->

      <div class="row">
        <!-- accepted payments column -->
        <div class="col-xs-6">
          <!--<p class="lead">Observaciones:</p>
          <img src="../../dist/img/credit/visa.png" alt="Visa">
          <img src="../../dist/img/credit/mastercard.png" alt="Mastercard">
          <img src="../../dist/img/credit/american-express.png" alt="American Express">
          <img src="../../dist/img/credit/paypal2.png" alt="Paypal">-->

          <p class="text-muted well well-sm no-shadow" style="margin-top: 10px;">
            <strong>Observaciones:</strong><br>
            <?=$data_edit->condiciones?>
          </p>
        </div>
        <!-- /.col -->
        <div class="col-xs-6">

          <div class="table-responsive">
            <table class="table">
              <tr>
                <th style="width:50%">Subtotal:</th>
                <td>$<?=$data_edit->total_venta?></td>
              </tr>

              <tr>
                <th>Impuesto</th>
                <td>$0</td>
              </tr>
              <tr>
                <th>Total:</th>
                <td>$<?=$data_edit->total_venta?></td>
              </tr>
            </table>
          </div>
        </div>
        <!-- /.col -->
      </div>
      <!-- /.row -->

      <!-- this row will not appear when printing -->
      <div class="row no-print">
        <div class="col-xs-12">
          <button type="button" class="btn btn-info" onclick="imprimir_factura('<?=$data_edit->idfactura?>')">
            <span class="fa fa-print"></span> Imprimir
          </button>
          <a href="<?=base_index();?>nuevafactura" class="btn btn-success pull-right"><i class="fa fa-step-backward"></i> Volver</a>
          <input type="submit" class="btn btn-primary pull-right" value="Actualizar">
          </button>          
        </div>
      </div>
    </section>
                      <div class="form-group col-lg-4 hidden">
                        <label for="Número" class="control-label">Número</label>
                        <div class="input-group">
                          <div class="input-group-addon">
                            <i class="fa fa-hashtag"></i>
                          </div>
                          <input type="text" name="numfact" value="<?=$data_edit->numfact;?>" class="form-control" readonly> 
                        </div>
                      </div><!-- /.form-group -->
<div class="form-group col-lg-4 hidden">
                        <label for="Fecha" class="control-label">Fecha</label>
                        <div class="input-group">
                          <div class="input-group-addon">
                            <i class="fa fa-calendar"></i>
                          </div>
                          <input type="text" name="fecha" value="<?=$data_edit->fecha;?>" class="form-control" readonly> 
                        </div>
                      </div><!-- /.form-group -->
<div class="form-group col-lg-4 hidden">
                        <label for="Clientes" class="control-label">Clientes</label>
                        <div class="input-group">
                          <div class="input-group-addon">
                            <i class="fa fa-user"></i>
                          </div>
                          <select name="clientes_idclientes" data-placeholder="Seleccione Clientes..." class="form-control chzn-select" tabindex="2" readonly>
               <option value=""></option>
               <?php foreach ($db->fetch_all("clientes") as $isi) {

                  if ($data_edit->clientes_idclientes==$isi->idclientes) {
                    echo "<option value='$isi->idclientes' selected>$isi->razon_social</option>";
                  } /*else {
                  echo "<option value='$isi->idclientes'>$isi->razon_social</option>";
                    }*/
               } ?>
              </select>
                        </div>
                      </div><!-- /.form-group -->
<div class="form-group col-lg-4 hidden">
                        <label for="Condiciones" class="control-label">Condiciones</label>
                        <div class="input-group">
                          <div class="input-group-addon">
                            <i class="fa fa-file"></i>
                          </div>
                          <input type="text" name="condiciones" value="<?=$data_edit->condiciones;?>" class="form-control" readonly> 
                        </div>
                      </div><!-- /.form-group -->
<div class="form-group col-lg-4 hidden">
                        <label for="Total" class="control-label">Total</label>
                        <div class="input-group">
                          <div class="input-group-addon">
                            <i class="fa fa-dollar"></i>
                          </div>                          <input type="text" name="total_venta" value="<?=$data_edit->total_venta;?>" class="form-control" readonly> 
                        </div>
                      </div><!-- /.form-group -->


                      <input type="hidden" name="id" value="<?=$data_edit->idfactura;?>">
                      <!--<div class="form-group col-lg-6">
                        <label for="tags" class="control-label ">&nbsp;</label>
                        <div class="input-group">
                          <input type="submit" class="btn btn-primary btn-flat" value="Actualizar">
                          <button type="button" class="btn btn-info btn-flat" onclick="imprimir_factura('<?=$data_edit->idfactura?>')">
                            <span class="fa fa-print"></span> Imprimir
                          </button>
                          <a href="<?=base_index();?>nuevafactura" class="btn btn-success btn-flat"><i class="fa fa-step-backward"></i> Volver</a>
                        </div>
                      </div>--><!-- /.form-group -->
                    </form>
                    <h1>Pagos Parciales</h1>
                    <h2 class="pull-right" style="color:red;">Saldo $<?php foreach ($db->fetch_custom("SELECT
SUM(ingreso.valor) totals
/*ingreso.fecha,
ingreso.valor,
formadepago.formadepago,
ingreso.descripcion*/
FROM
ingreso
INNER JOIN formadepago ON ingreso.formadepago_idformadepago = formadepago.idformadepago
INNER JOIN tipo_pago ON ingreso.tipo_pago_idtipo_pago = tipo_pago.idtipo_pago
WHERE
ingreso.factura_idfactura = '".$data_edit->idfactura."' AND
tipo_pago.tipo_pago = 'Pago Parcial'") as $tot) {
                      $saldo = $data_edit->total_venta - $tot->totals;
                      echo number_format($saldo);
                    } ?></h2>
                    <div class="row">

        <div class="col-xs-12 table-responsive">
          <table id="dtb_manual" class="table table-bordered table-striped">
                                   <thead>
                                     <tr>
                           <th style="width:25px" align="center">No</th>
                          <th>Fecha</th>
                          <th>Forma de Pago</th>
                          <th>Valor</th>
                          <th>Descripción</th>
                         
                        </tr>
                                      </thead>
                                        <tbody>
                                         <?php 
      $dtb=$db->fetch_custom("SELECT
ingreso.fecha,
ingreso.valor,
formadepago.formadepago,
ingreso.descripcion
FROM
ingreso
INNER JOIN formadepago ON ingreso.formadepago_idformadepago = formadepago.idformadepago
INNER JOIN tipo_pago ON ingreso.tipo_pago_idtipo_pago = tipo_pago.idtipo_pago
WHERE
ingreso.factura_idfactura = '".$data_edit->idfactura."' AND
tipo_pago.tipo_pago = 'Pago Parcial'");
      $i=1;
      foreach ($dtb as $isi) {
        ?><tr id="line_<?=$isi->idfactura;?>">
        <td align="center"><?=$i;?></td><td><?=$isi->fecha;?></td>
<td><?=$isi->formadepago;?></td>
<td><?=$isi->valor;?></td>
<td><?=$isi->descripcion;?></td>
        </tr>
        <?php
        $i++;
      }
      ?>
                                        </tbody>
                                    </table>
        </div>
        <!-- /.col -->
      </div>
      <!-- /.row -->
                  </div>

                  </div>
              </div>

</div>
                  
                </section><!-- /.content -->
        
<script type="text/javascript" src="<?=base_admin();?>inc/js/VentanaCentrada.js"></script>
  <script type="text/javascript" src="<?=base_admin();?>inc/js/editar_factura.js"></script> 