<?php if(!class_exists('raintpl')){exit;}?><?php $tpl = new RainTPL;$tpl_dir_temp = self::$tpl_dir;$tpl->assign( $this->var );$tpl->draw( dirname("header") . ( substr("header",-1,1) != "/" ? "/" : "" ) . basename("header") );?>


<!--
This file is part of editar_facturas
Copyright (C) 2015-2017  Carlos Garcia Gomez  neorazorx@gmail.com

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.
-->

<?php if( $fsc->factura ){ ?>

<script type="text/javascript" src="<?php echo $fsc->get_js_location('provincias.js');?>"></script>
<script type="text/javascript" src="<?php echo $fsc->get_js_location('nueva_venta.js');?>"></script>
<script type="text/javascript">
   numlineas = <?php echo count($fsc->factura->get_lineas()); ?>;
   fs_nf0 = <?php  echo FS_NF0;?>;
   fs_nf0_art = <?php  echo FS_NF0_ART;?>;
   all_impuestos = <?php echo json_encode($fsc->impuesto->all()); ?>;
   all_series = <?php echo json_encode($fsc->serie->all()); ?>;
   cliente = <?php echo json_encode($fsc->cliente_s); ?>;
   nueva_venta_url = '<?php echo $fsc->nuevo_albaran_url;?>';
   
   function cambiar_cliente() {
      $("#div_cambiar_cliente").removeClass('hidden');
      document.f_edit_factura.ac_cliente.readOnly = false;
      document.f_edit_factura.ac_cliente.value = '';
      document.f_edit_factura.ac_cliente.focus();
   }
   $(document).ready(function() {
      $("#numlineas").val(numlineas);
      usar_serie();
      usar_almacen();
      usar_divisa();
      recalcular();
      $("#ac_cliente").autocomplete({
         serviceUrl: nueva_venta_url,
         paramName: 'buscar_cliente',
         onSelect: function (suggestion) {
            if(suggestion)
            {
               if(document.f_edit_factura.cliente.value != suggestion.data && suggestion.data != '')
               {
                  document.f_edit_factura.cliente.value = suggestion.data;
                  usar_cliente(suggestion.data);
               }
            }
         }
      });
   });
</script>

<form id="f_edit_factura" class="form" name="f_edit_factura" action="<?php echo $fsc->url();?>" method="post">
   <input type="hidden" name="id" value="<?php echo $fsc->factura->idfactura;?>"/>
   <input type="hidden" name="cliente" value="<?php echo $fsc->factura->codcliente;?>"/>
   <input type="hidden" name="almacen" id="codalmacen" value="<?php echo $fsc->factura->codalmacen;?>"/>
   <input type="hidden" id="numlineas" name="numlineas" value="0"/>
   <div class="container-fluid">
      <div class="row">
         <div class="col-xs-8">
            <div class="btn-group">
               <a class="btn btn-sm btn-default" href="<?php echo $fsc->factura->url();?>" title="volver a la factura">
                  <span class="glyphicon glyphicon-arrow-left"></span>
                  <span class="hidden-sm hidden-xs">&nbsp; Volver</span>
               </a>
               <a class="btn btn-sm btn-default" href="<?php echo $fsc->url();?>" title="recargar la página">
                  <span class="glyphicon glyphicon-refresh"></span>
               </a>
            </div>
            <div class="btn-group">
            <?php $loop_var1=$fsc->extensions; $counter1=-1; if($loop_var1) foreach( $loop_var1 as $key1 => $value1 ){ $counter1++; ?>

               <?php if( $value1->type=='button' ){ ?>

               <a href="index.php?page=<?php echo $value1->from;?><?php echo $value1->params;?>&id=<?php echo $fsc->factura->idfactura;?>" class="btn btn-sm btn-default">
                  <?php echo $value1->text;?>

               </a>
               <?php } ?>

            <?php } ?>

            </div>
         </div>
         <div class="col-xs-4 text-right">
            <div class="btn-group">
               <a href="<?php echo $fsc->factura->url();?>" class="btn btn-sm btn-default">
                  <span class="glyphicon glyphicon-remove"></span>
                  <span class="hidden-sm hidden-xs">&nbsp;Cancelar</span>
               </a>
               <button class="btn btn-sm btn-primary" type="button" onclick="this.disabled=true;this.form.submit();">
                  <span class="glyphicon glyphicon-floppy-disk"></span>
                  <span class="hidden-xs">&nbsp;Guardar</span>
               </button>
            </div>
         </div>
      </div>
      <div class="row">
         <div class="col-sm-12">
            <div class="page-header">
               <h2>
                  <span class="glyphicon glyphicon-edit"></span>
                  factura de venta <small><?php echo $fsc->factura->codigo;?></small>
               </h2>
               <p class="help-block">
                  Ten en cuenta que hay en muchos paises y muchas situaciones donde
                  no se pueden modificar las facturas. Utiliza la <?php  echo FS_FACTURA_RECTIFICATIVA;?>

                  en esos casos.
               </p>
               <?php if( $fsc->factura->idfacturarect ){ ?>

               <span class="label label-danger">
                  <span class="glyphicon glyphicon-flag" aria-hidden="true"></span>
                  &nbsp; <?php  echo FS_FACTURA_RECTIFICATIVA;?> de <?php echo $fsc->factura->codigorect;?>

               </span> &nbsp;
               <?php } ?>

               <div class="checkbox-inline">
                  <label>
                     <?php if( $fsc->factura->anulada ){ ?>

                     <input type="checkbox" name="anulada" value="TRUE" checked=""/>
                     <?php }else{ ?>

                     <input type="checkbox" name="anulada" value="TRUE"/>
                     <?php } ?>

                     Anulada
                  </label>
               </div>
               <div class="checkbox-inline">
                  <label>
                     <?php if( $fsc->factura->femail ){ ?>

                     <input type="checkbox" name="enviada" value="<?php echo $fsc->factura->femail;?>" checked=""/>
                     <?php }else{ ?>

                     <input type="checkbox" name="enviada" value="<?php echo $fsc->today();?>"/>
                     <?php } ?>

                     Enviada
                  </label>
               </div>
               <?php if( $fsc->tesoreria ){ ?>

                  &nbsp;
                  <?php if( $fsc->factura->pagada ){ ?>

                  <input type="hidden" name="pagada" value="TRUE"/>
                  <span class="label label-warning">
                     <span class="glyphicon glyphicon-check" aria-hidden="true"></span> Pagada
                  </span>
                  <?php }else{ ?>

                  <span class="label label-warning">
                     Sin pagar
                  </span>
                  <?php } ?>

                  &nbsp; Usa la pestaña recbios para indicar si los recibos de esta factura están pagados o no.
               <?php }else{ ?>

               <div class="checkbox-inline">
                  <label>
                     <?php if( $fsc->factura->pagada ){ ?>

                     <input type="checkbox" name="pagada" value="TRUE" checked=""/>
                     <?php }else{ ?>

                     <input type="checkbox" name="pagada" value="TRUE"/>
                     <?php } ?>

                     Pagada
                  </label>
               </div>
               <?php } ?>

            </div>
            <?php if( $fsc->factura->get_rectificativas() ){ ?>

            <div class="alert alert-warning">
               ¡Cuidado! Hay una <b><?php  echo FS_FACTURA_RECTIFICATIVA;?></b> asociada.
            </div>
            <?php } ?>

         </div>
      </div>
      <div class="row">
         <div class="col-sm-2">
            <div class="form-group">
               Cliente actual:
               <div class="input-group">
                  <input class="form-control" type="text" name="ac_cliente" id="ac_cliente" value="<?php echo $fsc->factura->nombrecliente;?>" placeholder="Buscar" readonly="" autocomplete="off"/>
                  <span class="input-group-btn" title="Cambiar cliente">
                     <button class="btn btn-default" type="button" onclick="cambiar_cliente()">
                        <span class="glyphicon glyphicon-edit"></span>
                     </button>
                  </span>
               </div>
            </div>
            <div id="div_cambiar_cliente" class="hidden">
               <div class="form-group">
                  <p class="help-block">
                     Para cambiar el nombre o el <?php  echo FS_CIFNIF;?>, pero no el cliente, usa estos campos:
                  </p>
                  <div class="input-group">
                     <span class="input-group-addon">Nombre</span>
                     <input class="form-control" type="text" name="nombrecliente" value="<?php echo $fsc->factura->nombrecliente;?>" autocomplete="off"/>
                  </div>
               </div>
               <div class="form-group">
                  <div class="input-group">
                     <span class="input-group-addon"><?php  echo FS_CIFNIF;?></span>
                     <input class="form-control" type="text" name="cifnif" value="<?php echo $fsc->factura->cifnif;?>" autocomplete="off"/>
                  </div>
               </div>
            </div>
         </div>
         <div class="col-sm-2">
            <div class="form-group">
               Número:
               <input class="form-control" type="text" name="numero" value="<?php echo $fsc->factura->numero;?>" autocomplete="off"/>
            </div>
         </div>
         <div class="col-sm-2">
            <div class="form-group">
               <span class='text-capitalize'><?php  echo FS_NUMERO2;?>:</span>
               <input class="form-control" type="text" name="numero2" value="<?php echo $fsc->factura->numero2;?>" autocomplete="off"/>
            </div>
         </div>
         <div class="col-sm-2">
            <div class="form-group">
               <a href="<?php echo $fsc->serie->url();?>">Serie</a>:
               <select class="form-control" name="serie" id="codserie" onchange="usar_serie();recalcular();">
               <?php $loop_var1=$fsc->serie->all(); $counter1=-1; if($loop_var1) foreach( $loop_var1 as $key1 => $value1 ){ $counter1++; ?>

                  <?php if( $value1->codserie==$fsc->factura->codserie ){ ?>

                  <option value="<?php echo $value1->codserie;?>" selected=""><?php echo $value1->descripcion;?></option>
                  <?php }else{ ?>

                  <option value="<?php echo $value1->codserie;?>"><?php echo $value1->descripcion;?></option>
                  <?php } ?>

               <?php } ?>

               </select>
               <p class="help-block">Al cambiar de serie se generará un nuevo código para la factura.</p>
            </div>
         </div>
         <div class="col-sm-2">
            <div class="form-group">
               Fecha:
               <input class="form-control datepicker" type="text" name="fecha" value="<?php echo $fsc->factura->fecha;?>" autocomplete="off"/>
            </div>
         </div>
         <div class="col-sm-2">
            <div class="form-group">
               Hora:
               <input class="form-control" type="text" name="hora" value="<?php echo $fsc->factura->hora;?>" autocomplete="off"/>
            </div>
         </div>
      </div>
   </div>
   
   <div role="tabpanel">
      <ul class="nav nav-tabs" role="tablist">
         <li role="presentation" class="active">
            <a href="#lineas" aria-controls="lineas" role="tab" data-toggle="tab">
               <span class="glyphicon glyphicon-list"></span>
               <span class="hidden-xs">&nbsp;Líneas</span>
            </a>
         </li>
         <li role="presentation">
            <a href="#direccion" aria-controls="direccion" role="tab" data-toggle="tab">
               <span class="glyphicon glyphicon-road"></span>
               <span class="hidden-xs">&nbsp;Dirección</span>
            </a>
         </li>
         <?php $loop_var1=$fsc->extensions; $counter1=-1; if($loop_var1) foreach( $loop_var1 as $key1 => $value1 ){ $counter1++; ?>

            <?php if( $value1->type=='tab' ){ ?>

            <li role="presentation">
               <a href="#ext_<?php echo $value1->name;?>" aria-controls="ext_<?php echo $value1->name;?>" role="tab" data-toggle="tab"><?php echo $value1->text;?></a>
            </li>
            <?php } ?>

         <?php } ?>

      </ul>
      <div class="tab-content">
         <div role="tabpanel" class="tab-pane active" id="lineas">
            <div class="table-responsive">
               <table class="table table-condensed">
                  <thead>
                     <tr>
                        <th class="text-left" width="180">Referencia</th>
                        <th class="text-left">Descripción</th>
                        <th class="text-right" width="90">Cantidad</th>
                        <th width="60"></th>
                        <th class="text-right" width="110">Precio</th>
                        <th class="text-right" width="90">Dto. %</th>
                        <th class="text-right" width="130">Neto</th>
                        <th class="text-right" width="115"><?php  echo FS_IVA;?></th>
                        <th class="text-right recargo" width="115">RE %</th>
                        <th class="text-right irpf" width="115"><?php  echo FS_IRPF;?> %</th>
                        <th class="text-right" width="140">Total</th>
                     </tr>
                  </thead>
                  <tbody id="lineas_albaran">
                     <?php $loop_var1=$fsc->factura->get_lineas(); $counter1=-1; if($loop_var1) foreach( $loop_var1 as $key1 => $value1 ){ $counter1++; ?>

                     <tr id="linea_<?php echo $counter1;?>">
                        <td>
                           <input type="hidden" name="idlinea_<?php echo $counter1;?>" value="<?php echo $value1->idlinea;?>"/>
                           <input type="hidden" name="referencia_<?php echo $counter1;?>" value="<?php echo $value1->referencia;?>"/>
                           <input type="hidden" name="codcombinacion_<?php echo $counter1;?>" value="<?php echo $value1->codcombinacion;?>"/>
                           <div class="form-control">
                              <small><a href="<?php echo $value1->articulo_url();?>" target="_blank"><?php echo $value1->referencia;?></a></small>
                           </div>
                        </td>
                        <td><textarea class="form-control" name="desc_<?php echo $counter1;?>" rows="1"><?php echo $value1->descripcion;?></textarea></td>
                        <td>
                           <input type="number" step="any" id="cantidad_<?php echo $counter1;?>" class="form-control text-right" name="cantidad_<?php echo $counter1;?>"
                                  value="<?php echo $value1->cantidad;?>" onchange="recalcular()" onkeyup="recalcular()" autocomplete="off" value="1"/>
                        </td>
                        <td>
                           <button class="btn btn-sm btn-danger" type="button" onclick="$('#linea_<?php echo $counter1;?>').remove();recalcular();">
                              <span class="glyphicon glyphicon-trash"></span>
                           </button>
                        </td>
                        <td>
                           <input type="text" class="form-control text-right" id="pvp_<?php echo $counter1;?>" name="pvp_<?php echo $counter1;?>" value="<?php echo $value1->pvpunitario;?>"
                                  onkeyup="recalcular()" onclick="this.select()" autocomplete="off"/>
                        </td>
                        <td>
                           <input type="text" id="dto_<?php echo $counter1;?>" name="dto_<?php echo $counter1;?>" value="<?php echo $value1->dtopor;?>" class="form-control text-right"
                                  onkeyup="recalcular()" onclick="this.select()" autocomplete="off"/>
                        </td>
                        <td>
                           <input type="text" class="form-control text-right" id="neto_<?php echo $counter1;?>" name="neto_<?php echo $counter1;?>"
                                  onchange="ajustar_neto('<?php echo $counter1;?>')" onclick="this.select()" autocomplete="off"/>
                        </td>
                        <td>
                           <select class="form-control" id="iva_<?php echo $counter1;?>" name="iva_<?php echo $counter1;?>" onchange="ajustar_iva('<?php echo $counter1;?>')">
                           <?php $loop_var2=$fsc->impuesto->all(); $counter2=-1; if($loop_var2) foreach( $loop_var2 as $key2 => $value2 ){ $counter2++; ?>

                              <?php if( $value1->codimpuesto==$value2->codimpuesto OR $value1->iva==$value2->iva ){ ?>

                              <option value="<?php echo $value2->iva;?>" selected=""><?php echo $value2->descripcion;?></option>
                              <?php }else{ ?>

                              <option value="<?php echo $value2->iva;?>"><?php echo $value2->descripcion;?></option>
                              <?php } ?>

                           <?php } ?>

                           </select>
                        </td>
                        <td class="recargo">
                           <input type="text" class="form-control text-right" id="recargo_<?php echo $counter1;?>" name="recargo_<?php echo $counter1;?>" value="<?php echo $value1->recargo;?>"
                                  onchange="recalcular()" onclick="this.select()" autocomplete="off"/>
                        </td>
                        <td class="irpf">
                           <input type="text" class="form-control text-right" id="irpf_<?php echo $counter1;?>" name="irpf_<?php echo $counter1;?>" value="<?php echo $value1->irpf;?>"
                                  onchange="recalcular()" onclick="this.select()" autocomplete="off"/>
                        </td>
                        <td class="warning" title="Cálculo aproximado del total de la linea">
                           <input type="text" class="form-control text-right" id="total_<?php echo $counter1;?>" name="total_<?php echo $counter1;?>"
                                  onchange="ajustar_total('<?php echo $counter1;?>')" onclick="this.select()" autocomplete="off"/>
                        </td>
                     </tr>
                     <?php } ?>

                  </tbody>
                  <tbody>
                     <tr class="info">
                        <td><input id="i_new_line" class="form-control" type="text" placeholder="Buscar para añadir..." autocomplete="off"/></td>
                        <td colspan="3">
                           <a href="#" class="btn btn-sm btn-default" title="Añadir sin buscar" onclick="return add_linea_libre()">
                              <span class="glyphicon glyphicon-edit" aria-hidden="true"></span>
                           </a>
                        </td>
                        <td colspan="2">
                           <div class="form-control text-right">Totales</div>
                        </td>
                        <td><div id="aneto" class="form-control text-right" style="font-weight: bold;"><?php echo $fsc->show_numero(0);?></div></td>
                        <td><div id="aiva" class="form-control text-right" style="font-weight: bold;"><?php echo $fsc->show_numero(0);?></div></td>
                        <td class="recargo"><div id="are" class="form-control text-right" style="font-weight: bold;"><?php echo $fsc->show_numero(0);?></div></td>
                        <td class="irpf"><div id="airpf" class="form-control text-right" style="font-weight: bold;"><?php echo $fsc->show_numero(0);?></div></td>
                        <td>
                           <input type="text" name="atotal" id="atotal" class="form-control text-right" style="font-weight: bold;"
                                  value="0" onchange="recalcular()" autocomplete="off"/>
                        </td>
                     </tr>
                     <?php if( $fsc->user->admin AND FS_DB_HISTORY ){ ?>

                     <tr>
                        <td colspan="6"></td>
                        <td class="text-right"><?php echo $fsc->show_precio($fsc->factura->neto, $fsc->factura->coddivisa);?></td>
                        <td class="text-right"><?php echo $fsc->show_precio($fsc->factura->totaliva, $fsc->factura->coddivisa);?></td>
                        <td class="recargo text-right"><?php echo $fsc->show_precio($fsc->factura->totalrecargo, $fsc->factura->coddivisa);?></td>
                        <td class="irpf text-right"><?php echo $fsc->show_precio($fsc->factura->totalirpf, $fsc->factura->coddivisa);?></td>
                        <td class="text-right"><?php echo $fsc->show_precio($fsc->factura->total, $fsc->factura->coddivisa);?></td>
                     </tr>
                     <?php } ?>

                  </tbody>
               </table>
            </div>
            <div class="container-fluid">
               <div class="row">
                  <div class="col-sm-12 text-right">
                     <a href="#" class="label label-default" onclick="cliente.recargo=true;recalcular();" title="Mostrar Recargo de Equivalencia">
                        <span class="glyphicon glyphicon-eye-open" aria-hidden="true"></span>&nbsp; RE
                     </a>
                     &nbsp;
                     <a href="#" class="label label-default" onclick="irpf=21;recalcular();" title="Mostrar <?php  echo FS_IRPF;?>">
                        <span class="glyphicon glyphicon-eye-open" aria-hidden="true"></span>&nbsp; <?php  echo FS_IRPF;?>

                     </a>
                  </div>
               </div>
               <div class="row">
                  <div class="col-sm-2">
                     <div class="form-group">
                        <a href="<?php echo $fsc->forma_pago->url();?>">Forma de pago</a>:
                        <select name="forma_pago" class="form-control">
                           <?php $loop_var1=$fsc->forma_pago->all(); $counter1=-1; if($loop_var1) foreach( $loop_var1 as $key1 => $value1 ){ $counter1++; ?>

                           <option value="<?php echo $value1->codpago;?>"<?php if( $fsc->factura->codpago==$value1->codpago ){ ?> selected=""<?php } ?>><?php echo $value1->descripcion;?></option>
                           <?php } ?>

                        </select>
                     </div>
                  </div>
                  <div class="col-sm-2">
                     <div class="form-group<?php if( $fsc->factura->vencida() ){ ?> has-warning<?php } ?>">
                        Vencimiento:
                        <?php if( $fsc->factura->pagada OR $fsc->tesoreria ){ ?>

                        <input type="text" name="vencimiento" value="<?php echo $fsc->factura->vencimiento;?>" class="form-control datepicker" readonly=""/>
                        <?php }else{ ?>

                        <input type="text" name="vencimiento" value="<?php echo $fsc->factura->vencimiento;?>" class="form-control datepicker" autocomplete="off"/>
                        <?php } ?>

                     </div>
                  </div>
                   
<!------ JOLY 28/09/2017 AUMENTO DE CAMPO ALMACEN PARA MODIFICARSE -->                   
                  <div class="col-sm-2">
                     <div class="form-group">
                        Almac�n :
                        <select name="codalmacen" class="form-control">
             
                           <?php $loop_var1=$fsc->almacen->all(); $counter1=-1; if($loop_var1) foreach( $loop_var1 as $key1 => $value1 ){ $counter1++; ?>

                              <?php if( $value1->codalmacen==$fsc->factura->codalmacen ){ ?>


                              <option value="<?php echo $value1->codalmacen;?>" selected=""><?php echo $value1->nombre;?></option>
                              <?php }else{ ?>


                              <option value="<?php echo $value1->codalmacen;?>"><?php echo $value1->nombre;?></option>
                              <?php } ?>

                           <?php } ?>

                        </select>
                     </div>
                  </div>
           
      
            
<!------ JOLY 28/09/2017 FIN AUMENTO DE CAMPO ALMACEN PARA MODIFICARSE -->                   
                   
                  <div class="col-sm-2">
                     <div class="form-group">
                        <a href="<?php echo $fsc->divisa->url();?>">Divisa</a>:
                        <select name="divisa" id="coddivisa" class="form-control" onchange="usar_divisa()">
                        <?php $loop_var1=$fsc->divisa->all(); $counter1=-1; if($loop_var1) foreach( $loop_var1 as $key1 => $value1 ){ $counter1++; ?>

                           <?php if( $value1->coddivisa==$fsc->factura->coddivisa ){ ?>

                           <option value="<?php echo $value1->coddivisa;?>" selected=""><?php echo $value1->descripcion;?></option>
                           <?php }else{ ?>

                           <option value="<?php echo $value1->coddivisa;?>"><?php echo $value1->descripcion;?></option>
                           <?php } ?>

                        <?php } ?>

                        </select>
                     </div>
                     <div class="form-group">
                        Tasa de conversión (1€ = X)
                        <input type="text" name="tasaconv" class="form-control" placeholder="<?php echo $fsc->factura->tasaconv;?>" autocomplete="off"/>
                     </div>
                  </div>
                  
                  <div class="col-sm-2">
                     <div class="form-group">
                        Empleado :
                        <select name="codagente" class="form-control">
                           <option value="">Ninguno</option>
                           <option value="">------</option>
                           <?php $loop_var1=$fsc->agente->all(); $counter1=-1; if($loop_var1) foreach( $loop_var1 as $key1 => $value1 ){ $counter1++; ?>

                              <?php if( $value1->codagente==$fsc->factura->codagente ){ ?>

                              <option value="<?php echo $value1->codagente;?>" selected=""><?php echo $value1->get_fullname();?></option>
                              <?php }else{ ?>

                              <option value="<?php echo $value1->codagente;?>"><?php echo $value1->get_fullname();?></option>
                              <?php } ?>

                           <?php } ?>

                        </select>
                     </div>
                     <div class="form-group">
                        Comisión:
                        <input type="number" step="any" name="porcomision" value="<?php echo $fsc->factura->porcomision;?>" class="form-control" autocomplete="off"/>
                     </div>
                  </div>
               </div>
               <div class="row">
                  <div class="col-sm-12">
                     <div class="form-group">
                        Observaciones:
                        <textarea class="form-control" name="observaciones" rows="6"><?php echo $fsc->factura->observaciones;?></textarea>
                     </div>
                  </div>
               </div>
            </div>
         </div>
         <div role="tabpanel" class="tab-pane" id="direccion">
            <div class="container-fluid" style="margin-top: 10px;">
               <div class="row">
                  <div class="col-sm-3">
                     <div class="form-group">
                        <a href="<?php echo $fsc->pais->url();?>">País</a>:
                        <select class="form-control" name="codpais">
                           <?php $loop_var1=$fsc->pais->all(); $counter1=-1; if($loop_var1) foreach( $loop_var1 as $key1 => $value1 ){ $counter1++; ?>

                           <option value="<?php echo $value1->codpais;?>"<?php if( $value1->codpais==$fsc->factura->codpais ){ ?> selected=""<?php } ?>><?php echo $value1->nombre;?></option>
                           <?php } ?>

                        </select>
                     </div>
                  </div>
                  <div class="col-sm-3">
                     <div class="form-group">
                        <span class="text-capitalize"><?php  echo FS_PROVINCIA;?></span>:
                        <input id="ac_provincia" class="form-control" type="text" name="provincia" autocomplete="off" value="<?php echo $fsc->factura->provincia;?>"/>
                     </div>
                  </div>
                  <div class="col-sm-3">
                     <div class="form-group">
                        Ciudad:
                        <input class="form-control" type="text" name="ciudad" autocomplete="off" value="<?php echo $fsc->factura->ciudad;?>"/>
                     </div>
                  </div>
                  <div class="col-sm-3">
                     <div class="form-group">
                        Código Postal:
                        <input class="form-control" type="text" name="codpostal" autocomplete="off" value="<?php echo $fsc->factura->codpostal;?>"/>
                     </div>
                  </div>
                  <div class="col-sm-6">
                     <div class="form-group">
                        Dirección:
                        <input class="form-control" type="text" name="direccion" value="<?php echo $fsc->factura->direccion;?>" autocomplete="off"/>
                     </div>
                  </div>
               </div>
            </div>
         </div>
         <?php $loop_var1=$fsc->extensions; $counter1=-1; if($loop_var1) foreach( $loop_var1 as $key1 => $value1 ){ $counter1++; ?>

            <?php if( $value1->type=='tab' ){ ?>

            <div role="tabpanel" class="tab-pane" id="ext_<?php echo $value1->name;?>">
               <iframe src="index.php?page=<?php echo $value1->from;?><?php echo $value1->params;?>&id=<?php echo $fsc->factura->idfactura;?>" width="100%" height="2000" frameborder="0"></iframe>
            </div>
            <?php } ?>

         <?php } ?>

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

<?php echo $fsc->iframe_xid();?>


<div class="modal" id="modal_articulos">
   <div class="modal-dialog" style="width: 99%; max-width: 1000px;">
      <div class="modal-content">
         <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
            <h4 class="modal-title">Buscar artículos</h4>
            <p class="help-block">
               <span class="glyphicon glyphicon-info-sign"></span>
               Coloca el puntero sobre un precio para ver la fecha en la que fue actualizado.
            </p>
         </div>
         <div class="modal-body">
            <form id="f_buscar_articulos" name="f_buscar_articulos" action="<?php echo $fsc->url();?>" method="post" class="form">
               <input type="hidden" name="codcliente" value="<?php echo $fsc->factura->codcliente;?>"/>
               <input type="hidden" name="codalmacen"/>
               <input type="hidden" name="coddivisa"/>
               <div class="container-fluid">
                  <div class="row">
                     <div class="col-sm-4">
                        <div class="input-group">
                           <input class="form-control" type="text" name="query" autocomplete="off"/>
                           <span class="input-group-btn">
                              <button class="btn btn-primary" type="submit">
                                 <span class="glyphicon glyphicon-search"></span>
                              </button>
                           </span>
                        </div>
                        <label class="checkbox-inline">
                           <input type="checkbox" name="con_stock" value="TRUE" onchange="buscar_articulos()"/>
                           sólo con stock
                        </label>
                     </div>
                     <div class="col-sm-4">
                        <select class="form-control" name="codfamilia" onchange="buscar_articulos()">
                           <option value="">Cualquier familia</option>
                           <option value="">------</option>
                           <?php $loop_var1=$fsc->familia->all(); $counter1=-1; if($loop_var1) foreach( $loop_var1 as $key1 => $value1 ){ $counter1++; ?>

                           <option value="<?php echo $value1->codfamilia;?>"><?php echo $value1->nivel;?><?php echo $value1->descripcion;?></option>
                           <?php } ?>

                        </select>
                     </div>
                     <div class="col-sm-4">
                        <select class="form-control" name="codfabricante" onchange="buscar_articulos()">
                           <option value="">Cualquier fabricante</option>
                           <option value="">------</option>
                           <?php $loop_var1=$fsc->fabricante->all(); $counter1=-1; if($loop_var1) foreach( $loop_var1 as $key1 => $value1 ){ $counter1++; ?>

                           <option value="<?php echo $value1->codfabricante;?>"><?php echo $value1->nombre;?></option>
                           <?php } ?>

                        </select>
                     </div>
                  </div>
               </div>
            </form>
         </div>
         <ul class="nav nav-tabs" id="nav_articulos" style="display: none;">
            <li id="li_mis_articulos">
               <a href="#" id="b_mis_articulos">Mi catálogo</a>
            </li>
            <li id="li_nuevo_articulo">
               <a href="#" id="b_nuevo_articulo">
                  <span class="glyphicon glyphicon-plus"></span>&nbsp; Nuevo
               </a>
            </li>
         </ul>
         <div id="search_results"></div>
         <div id="nuevo_articulo" class="modal-body" style="display: none;">
            <form name="f_nuevo_articulo" action="<?php echo $fsc->url();?>" method="post" class="form">
               <div class="container-fluid">
                  <div class="row">
                     <div class="col-sm-4">
                        <div class="form-group">
                           Referencia:
                           <div class="input-group">
                              <input class="form-control" type="text" name="referencia" maxlength="18" autocomplete="off"/>
                              <span class="input-group-btn" title="Borrar">
                                 <button class="btn btn-default" type="button" onclick="document.f_nuevo_articulo.referencia.value='';document.f_nuevo_articulo.descripcion.focus();">
                                    <span class="glyphicon glyphicon-edit"></span>
                                 </button>
                              </span>
                           </div>
                           <p class="help-block">Dejar en blanco para asignar una referencia automática.</p>
                        </div>   
                     </div>
                     <div class="col-sm-8">
                        <div class="form-group">
                           Descripción:
                           <textarea name="descripcion" rows="1" class="form-control"></textarea>
                        </div>
                     </div>
                  </div>
                  <div class="row">
                     <div class="col-sm-4">
                        <div class="form-group">
                           Código de barras:
                           <div class="input-group">
                              <span class="input-group-addon">
                                 <span class="glyphicon glyphicon-barcode"></span>
                              </span>
                              <input class="form-control" type="text" name="codbarras" maxlength="18" autocomplete="off"/>
                           </div>
                        </div>
                     </div>
                     <div class="col-sm-4">
                        <div class="form-group">
                           <a href="<?php echo $fsc->familia->url();?>">Familia</a>:
                           <select name="codfamilia" class="form-control">
                              <option value="">Ninguna</option>
                              <option value="">------</option>
                              <?php $loop_var1=$fsc->familia->all(); $counter1=-1; if($loop_var1) foreach( $loop_var1 as $key1 => $value1 ){ $counter1++; ?>

                              <option value="<?php echo $value1->codfamilia;?>"><?php echo $value1->nivel;?><?php echo $value1->descripcion;?></option>
                              <?php } ?>

                           </select>
                        </div>
                     </div>
                     <div class="col-sm-4">
                        <div class="form-group">
                           <a href="<?php echo $fsc->fabricante->url();?>">Fabricante</a>:
                           <select name="codfabricante" class="form-control">
                              <option value="">Ninguno</option>
                              <option value="">------</option>
                              <?php $loop_var1=$fsc->fabricante->all(); $counter1=-1; if($loop_var1) foreach( $loop_var1 as $key1 => $value1 ){ $counter1++; ?>

                              <option value="<?php echo $value1->codfabricante;?>"><?php echo $value1->nombre;?></option>
                              <?php } ?>

                           </select>
                        </div>
                     </div>
                  </div>
                  <div class="row">
                     <div class="col-sm-4">
                        <div class="form-group">
                           <a href="<?php echo $fsc->impuesto->url();?>"><?php  echo FS_IVA;?></a>:
                           <select name="codimpuesto" class="form-control">
                              <?php $loop_var1=$fsc->impuesto->all(); $counter1=-1; if($loop_var1) foreach( $loop_var1 as $key1 => $value1 ){ $counter1++; ?>

                              <option value="<?php echo $value1->codimpuesto;?>"<?php if( $value1->is_default() ){ ?> selected=""<?php } ?>><?php echo $value1->descripcion;?></option>
                              <?php } ?>

                           </select>
                        </div>
                     </div>
                     <div class="col-sm-4">
                        <div class="form-group">
                           Precio de venta:
                           <input type="text" name="pvp" value="0" class="form-control" autocomplete="off"/>
                        </div>
                     </div>
                     <div class="col-sm-4 text-right">
                        <br/>
                        <button class="btn btn-sm btn-primary" type="submit" onclick="new_articulo();return false;">
                           <span class="glyphicon glyphicon-floppy-disk"></span>&nbsp; Guardar y seleccionar
                        </button>
                     </div>
                  </div>
                  <div class="row">
                     <div class="col-sm-12">
                        <label class="checkbox-inline">
                           <input type="checkbox" name="secompra" value="TRUE" checked=""/> Se compra
                        </label> &nbsp;
                        <label class="checkbox-inline">
                           <input type="checkbox" name="sevende" value="TRUE" checked=""/> Se vende
                        </label> &nbsp;
                        <label class="checkbox-inline">
                           <input type="checkbox" name="nostock" value="TRUE"/> No controlar stock
                        </label> &nbsp;
                        <label class="checkbox-inline">
                           <input type="checkbox" name="publico" value="TRUE"/>
                           <span class="glyphicon glyphicon-globe"></span> Público
                        </label>
                     </div>
                  </div>
               </div>
            </form>
         </div>
      </div>
   </div>
</div>
<?php } ?>


<?php $tpl = new RainTPL;$tpl_dir_temp = self::$tpl_dir;$tpl->assign( $this->var );$tpl->draw( dirname("footer") . ( substr("footer",-1,1) != "/" ? "/" : "" ) . basename("footer") );?>