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



<script type="text/javascript">
   function comprobar_url()
   {
      if(window.location.hash.substring(1) == 'export')
      {
         $("#b_importar").removeClass('active');
         $("#g_importar").hide();
         $("#b_exportar").addClass('active');
         $("#g_exportar").show();
         $("#b_ventasp").removeClass('active');
         $("#g_ventasp").hide();        
      }
      else if(window.location.hash.substring(1) == 'import')
      {
         $("#b_exportar").removeClass('active');
         $("#g_exportar").hide();
         $("#b_ventasp").removeClass('active');
         $("#g_ventasp").hide();  
         $("#b_importar").addClass('active');
         $("#g_importar").show();
      
      }
      else if(window.location.hash.substring(1) == 'ventasp')
      {
         $("#b_ventasp").addClass('active');
         $("#g_ventasp").show(); 
         $("#b_importar").removeClass('active');
         $("#g_importar").hide();
         $("#b_exportar").removeClass('active');
         $("#g_exportar").hide();
 
     
     }

    }
   $(document).ready(function() {
      comprobar_url();
      window.onpopstate = function(){ 
         comprobar_url();
      }
   });
</script>
<script type="text/javascript">
   $(document).ready(function () {
      $("#ac_referencia").autocomplete({
         serviceUrl: '<?php echo $fsc->url();?>',
         paramName: 'buscar_referencia',
         onSelect: function (suggestion) {
            if(suggestion)
            {
               if( $("#ac_referencia").val() != suggestion.data)
               {
                  $("#ac_referencia").val(suggestion.data);
               }
            }
         }
      });

   });
</script>

<div class="container-fluid" style="margin-top: 10px;">
   <div class="row" style="margin-bottom: 10px;">
      <div class="col-xs-2">
         <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="col-xs-10 text-right">
         <h3 style="margin-top: 0px;">LIQUIDACION DE FACTURAS</h3>
      </div>
   </div>
   <div class="row">
      <div class="col-lg-2 col-md-2 col-sm-2">
         <div class="list-group">
            <a id="b_exportar" href="#export" class="list-group-item active">
               <span class="glyphicon glyphicon-export"></span> &nbsp; Cancelacion / Deuda
            </a>
            <a id="b_ventasp" href="#ventasp" class="list-group-item">
               <span class="glyphicon glyphicon-export"></span> &nbsp; Ventas x Vendedor
            </a>
             <a id="b_importar" href="#import" class="list-group-item">
               <span class="glyphicon glyphicon-export"></span> &nbsp; Liq. de facturas
            </a>

         </div>
      </div>
      <div class="col-lg-10 col-md-10 col-sm-12">
         <div id="g_exportar">
            <form action="<?php echo $fsc->url();?>" method="post" class="form">
                <div class="panel panel-info">
                    <div class="panel-heading">
                        <h3 class="panel-title">FACTURAS SIN CANCELAR</h3>
                    </div>
                  <div class="row"> 
                    <div class="">
                        <div class="form-group col-sm-2">
                            Fecha Ini=>
                            <input type="text" name="fechaini2" class="form-control datepicker" value="<?php echo $fsc->today();?>" autocomplete="off"/>
                        </div>
                        
                        <div class="form-group col-sm-2 ">
                            <div class="form-group">   
                              Fecha fin=>
                              <input type="text" name="fechafin2" class="form-control datepicker" value="<?php echo $fsc->today();?>" autocomplete="off"/>
                            </div>  
                        </div> 
                        <!-- almacen a procesar jl-->
                        <div class="col-sm-3">
                           Vendedor=>
                            <div class="form-group">
                                <select name="codagente" class="form-control">
                                    <option value="<?php echo $fsc->agente->codagente;?>"><?php echo $fsc->agente->get_fullname();?></option>
                                    <?php $loop_var1=$fsc->agente->all(); $counter1=-1; if($loop_var1) foreach( $loop_var1 as $key1 => $value1 ){ $counter1++; ?>

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

                                </select>
                            </div>
                           </div>                      
                        <div class="form-group col-sm-1">
                            <div class="panel-footer">
                                <button class="btn btn-sm btn-primary" type="submit" onclick="this.disabled=true;this.form.submit();">
                                <span class="glyphicon glyphicon-import"></span> &nbsp; Generar
                                </button>
                            </div>
                        </div>    
                    </div>
                   </div>                    
                      <div>
                        <table class="table table-hover">
                           <thead>
                              <tr>
                                 
                                 <th class="text-left">Código</th>
                                 <th class="text-left">Cliente</th>
                                 <th class="hidden-sm"></th>
                                 <th class="text-center">Presupusto</th>
                                 <th class="text-center">Pedido</th>
                                 <th class="text-center">Pre-factura</th>
                                 <th class="text-center">Factura</th>
                                 <th class="text-right">Total</th>
                                 <th class="text-right">Abono(s)</th>
                                 <th class="text-right">Saldo</th>
                              </tr>
                           </thead>
                           <?php $loop_var1=$fsc->resultado; $counter1=-1; if($loop_var1) foreach( $loop_var1 as $key1 => $value1 ){ $counter1++; ?>

                           <tr>
                               <td class="text-left"><?php echo $value1['codigo'];?> </td>
                               <td class="text-left"><?php echo $value1['nombre'];?> </td>
                               <td class="hidden-sm"></td>
                               <td class="text-center"><?php echo $value1['presup'];?> </td>
                               <td class="text-center"><?php echo $value1['pedido'];?> </td>
                               <td class="text-center"><?php echo $value1['albaran'];?> </td>
                               <td class="text-center"><?php echo $value1['factura'];?> </td>
                               <td class="text-right"><?php echo $value1['total'];?> </td>
                               <td class="text-right"><?php echo $value1['abono'];?> </td>
                               <td class="text-right"><?php echo $fsc->show_precio($value1['saldo'],$value1['coddivisa1']);?> </td>
                           </tr>
                           <?php } ?>

                        </table>
                    </div> 
                </div>
            </form>      
        </div>    
        
         <div id="g_ventasp" style="display: none;">
             <form action="<?php echo $fsc->url();?>#ventasp" method="post" class="form">
               
                <div class="panel panel-info">
                    <div class="panel-heading">
                        <h3 class="panel-title">Ventas  por vendedor</h3>
                    </div>
                  <div class="row"> 
                    <div class="">
                        <div class="form-group col-sm-2">
                            Fecha Ini:
                            <input type="text" name="fechaini3" class="form-control datepicker" value="<?php echo $fsc->today();?>" autocomplete="off"/>
                        </div>
                        
                        <div class="form-group col-sm-2 ">
                            <div class="form-group">   
                              Fecha fin:
                              <input type="text" name="fechafin3" class="form-control datepicker" value="<?php echo $fsc->today();?>" autocomplete="off"/>
                            </div>  
                        </div> 

                        
                        <!-- almacen a procesar jl-->
                        <div class="form-group col-sm-2">
                           Vendedor:
                            <div class="form-group">
                                <select name="codagentev" class="form-control">
                                     <option value="">Todos los vendedores</option>
                                     <option value="">-----</option>                                    
                                    <option value="<?php echo $fsc->agente->codagente;?>"><?php echo $fsc->agente->get_fullname();?></option>
                                    <?php $loop_var1=$fsc->agente->all(); $counter1=-1; if($loop_var1) foreach( $loop_var1 as $key1 => $value1 ){ $counter1++; ?>

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

                                </select>
                            </div>
                           </div>   
                           <div class="form-group col-sm-2">
                               Fabricante:
                               <div class='form-group<?php if( $fsc->b_codfabricante ){ ?> has-success<?php } ?>'>
                                   <select class="form-control" name="b_codfabricante" >  <!--onchange="this.form.submit()">-->
                                     <option value="">Todos los fabricantes</option>
                                     <option value="">-----</option>
                                     <?php $loop_var1=$fsc->fabricante->all(); $counter1=-1; if($loop_var1) foreach( $loop_var1 as $key1 => $value1 ){ $counter1++; ?>

                                        <?php if( $value1->codfabricante==$fsc->b_codfabricante ){ ?>

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

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

                                     <?php } ?>

                                  </select>
                               </div>
                            </div>
                            <div class="form-group col-sm-2">
                               Referencia:
                               <input class="form-control" type="text" name="referencia" value="<?php echo $fsc->referencia;?>" id="ac_referencia" maxlength="18" placeholder="Todos" autocomplete="off"/>
                               <p class="help-block">
                                  
                               </p>
                            </div>  
        
            <div class="col-sm-2">
            <div class="radio">
               <label>
                  <?php if( $fsc->estado=='' ){ ?>

                  <input  type="radio" name="estado" value="" checked="" />
                  <?php }else{ ?>

                  <input  type="radio" name="estado" value="" />
                  <?php } ?>

                  Por vendedor
               </label>
            </div>
            <div class="radio">
               <label>
                  <?php if( $fsc->estado=='xclientes' ){ ?>

                  <input class="text-left" type="radio" name="estado" value="xclientes" checked="" />
                  <?php }else{ ?>

                  <input class="text-left" type="radio" name="estado" value="xclientes" />
                  <?php } ?>

                  Por clientes
               </label>
            </div>
             </div>
                                
                        
                        <div class="form-group col-sm-2">
                            <div class="panel-footer">
                                <button class="btn btn-sm btn-primary" type="submit" onclick="this.disabled=true;this.form.submit();">
                                <span class="glyphicon glyphicon-import"></span> &nbsp; Generar
                                </button>
                            </div>
                        </div>    
                    </div>
                   </div>                    
                      <div>
                        <table class="table table-hover">
                           <thead>
                              <tr>
                                 <th class="text-left">Vendedor</th>
                                 <th class="text-left"><?php echo $fsc->agentenom;?></th>
                                 <th class="hidden-sm">Fabricante:</th>
                                 <th class="text-left"><?php echo $fsc->nfabricante;?></th>
                                 <th class="text-left">Desde:</th>
                                 <th class="text-left"><?php echo $fsc->fecini;?></th>
                                 <th class="text-left:">Hasta</th>
                                 <th class="text-left"><?php echo $fsc->fecfin;?></th>
                              </tr>
                           </thead>
                        </table>   
                        <!-- cuando la consulta es resumen --> 
                        <?php if( $fsc->estado=='' ){ ?>

                        <table class="table table-hover">
                           <thead>
                              <tr>
                                  <th class="text-left">Referencia</th>
                                 <th class="text-left">Descripción</th>
                                 <th class="hidden-sm"></th>
                                 <th class="text-center">Cantidad</th>
                                 <th class="text-center">PVP</th>
                              </tr>
                           </thead>
                           <?php $loop_var1=$fsc->resultadoven; $counter1=-1; if($loop_var1) foreach( $loop_var1 as $key1 => $value1 ){ $counter1++; ?>

                           <tr>
                               <td class="text-left"><?php echo $value1['referen'];?> </td>
                               <td class="text-left"><?php echo $value1['nombre'];?> </td>
                               <td class="hidden-sm"></td>
                               <td class="text-center"><?php echo $value1['cantid'];?> </td>
                               <td class="text-right"><?php echo $fsc->show_numero($value1['pvptota']);?> </td>
                               
                           </tr>
                           <?php } ?>

                           
                        </table>
                        <?php }else{ ?>

                        <!-- cuando la consulta es por clientes -->        
                        <table class="table table-hover">
                           <thead>
                              <tr>
                                  <th class="text-left">Cliente</th>
                                 <th class="text-left">Referencia</th>
                                 <th class="hidden-sm"></th>
                                 <th class="text-center">Cantidad</th>
                                 <th class="text-center">PVP</th>
                              </tr>
                           </thead>
                           <?php $loop_var1=$fsc->resultadoven; $counter1=-1; if($loop_var1) foreach( $loop_var1 as $key1 => $value1 ){ $counter1++; ?>

                           <tr>
                               <td class="text-left"><?php echo $value1['nombcli'];?> </td>
                               <td class="text-left"><?php echo $value1['referen'];?> </td>
                               <td class="hidden-sm"></td>
                               <td class="text-center"><?php echo $value1['cantid'];?> </td>
                               <td class="text-right"><?php echo $fsc->show_numero($value1['pvptota']);?> </td>
                               
                           </tr>
                           <?php } ?>

                        </table>
                        <?php } ?>

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

        <div id="g_importar" style="display: none;">
            <form action="<?php echo $fsc->url();?>#import" method="post" enctype='multipart/form-data' class="form">
               <input name='import' type='hidden' value='TRUE'/>
               <div class="panel panel-info">
                  <div class="panel-heading">
                     <h3 class="panel-title">Generación de Informacion para EXCEL</h3>
                  </div>
                  <div class="row"> 
                    <div class="">
                        <div class="form-group col-sm-2">
                            Fecha Ini:
                            <input type="text" name="fechaini1" class="form-control datepicker" value="<?php echo $fsc->today();?>" autocomplete="off"/>
                        </div>
                        
                        <div class="form-group col-sm-2 ">
                            <div class="form-group">   
                              Fecha fin:
                              <input type="text" name="fechafin1" class="form-control datepicker" value="<?php echo $fsc->today();?>" autocomplete="off"/>
                            </div>  
                        </div> 
                        <!-- almacen a procesar jl-->
                        <div class="col-sm-3">
                           Vendedor:
                            <div class="form-group">
                                <select name="codagente" class="form-control">
                                    <option value="<?php echo $fsc->agente->codagente;?>"><?php echo $fsc->agente->get_fullname();?></option>
                                    <?php $loop_var1=$fsc->agente->all(); $counter1=-1; if($loop_var1) foreach( $loop_var1 as $key1 => $value1 ){ $counter1++; ?>

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

                                </select>
                            </div>
                           </div>                      
                        <div class="form-group col-sm-1">
                            <div class="panel-footer">
                                <button class="btn btn-sm btn-primary" type="submit" onclick="this.disabled=true;this.form.submit();">
                                <span class="glyphicon glyphicon-import"></span> &nbsp; Exportar XLS
                                </button>
                            </div>
                        </div>    
                    </div>
                   </div>
                </div>   
            </form>
      </div>

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

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

