protected function process()
 {
     $this->factura = new factura_proveedor();
     /// desactivamos la barra de botones
     $this->show_fs_toolbar = FALSE;
     $this->offset = 0;
     if (isset($_GET['offset'])) {
         $this->offset = intval($_GET['offset']);
     }
     if (isset($_POST['buscar_lineas'])) {
         $this->buscar_lineas();
     } else {
         if (isset($_GET['codagente'])) {
             $this->template = 'extension/compras_facturas_agente';
             $agente = new agente();
             $this->agente = $agente->get($_GET['codagente']);
             $this->resultados = $this->factura->all_from_agente($_GET['codagente'], $this->offset);
         } else {
             if (isset($_GET['codproveedor'])) {
                 $this->template = 'extension/compras_facturas_proveedor';
                 $proveedor = new proveedor();
                 $this->proveedor = $proveedor->get($_GET['codproveedor']);
                 $this->resultados = $this->factura->all_from_proveedor($_GET['codproveedor'], $this->offset);
             } else {
                 if (isset($_GET['ref'])) {
                     $this->template = 'extension/compras_facturas_articulo';
                     $articulo = new articulo();
                     $this->articulo = $articulo->get($_GET['ref']);
                     $linea = new linea_factura_proveedor();
                     $this->resultados = $linea->all_from_articulo($_GET['ref'], $this->offset);
                 } else {
                     $this->share_extension();
                     if (isset($_GET['delete'])) {
                         $fact = $this->factura->get($_GET['delete']);
                         if ($fact) {
                             if ($fact->delete()) {
                                 $this->new_message("Factura eliminada correctamente.");
                             } else {
                                 $this->new_error_msg("¡Imposible eliminar la factura!");
                             }
                         } else {
                             $this->new_error_msg("Factura no encontrada.");
                         }
                     }
                     if ($this->query != '') {
                         $this->resultados = $this->factura->search($this->query, $this->offset);
                     } else {
                         if (isset($_GET['sinpagar'])) {
                             $this->resultados = $this->factura->all_sin_pagar($this->offset);
                         } else {
                             $this->resultados = $this->factura->all($this->offset);
                         }
                     }
                 }
             }
         }
     }
 }
 protected function private_core()
 {
     $this->agente = new agente();
     $this->factura = new factura_proveedor();
     $this->serie = new serie();
     $this->mostrar = 'todo';
     if (isset($_GET['mostrar'])) {
         $this->mostrar = $_GET['mostrar'];
         setcookie('compras_fac_mostrar', $this->mostrar, time() + FS_COOKIES_EXPIRE);
     } else {
         if (isset($_COOKIE['compras_fac_mostrar'])) {
             $this->mostrar = $_COOKIE['compras_fac_mostrar'];
         }
     }
     $this->offset = 0;
     if (isset($_GET['offset'])) {
         $this->offset = intval($_GET['offset']);
     }
     $this->order = 'fecha DESC';
     if (isset($_GET['order'])) {
         if ($_GET['order'] == 'fecha_desc') {
             $this->order = 'fecha DESC';
         } else {
             if ($_GET['order'] == 'fecha_asc') {
                 $this->order = 'fecha ASC';
             } else {
                 if ($_GET['order'] == 'codigo_desc') {
                     $this->order = 'codigo DESC';
                 } else {
                     if ($_GET['order'] == 'codigo_asc') {
                         $this->order = 'codigo ASC';
                     } else {
                         if ($_GET['order'] == 'total_desc') {
                             $this->order = 'total DESC';
                         }
                     }
                 }
             }
         }
         setcookie('compras_fac_order', $this->order, time() + FS_COOKIES_EXPIRE);
     } else {
         if (isset($_COOKIE['compras_fac_order'])) {
             $this->order = $_COOKIE['compras_fac_order'];
         }
     }
     if (isset($_POST['buscar_lineas'])) {
         $this->buscar_lineas();
     } else {
         if (isset($_REQUEST['buscar_proveedor'])) {
             $this->buscar_proveedor();
         } else {
             if (isset($_GET['ref'])) {
                 $this->template = 'extension/compras_facturas_articulo';
                 $articulo = new articulo();
                 $this->articulo = $articulo->get($_GET['ref']);
                 $linea = new linea_factura_proveedor();
                 $this->resultados = $linea->all_from_articulo($_GET['ref'], $this->offset);
             } else {
                 $this->share_extension();
                 $this->proveedor = FALSE;
                 $this->codagente = '';
                 $this->codserie = '';
                 $this->desde = '';
                 $this->estado = '';
                 $this->hasta = '';
                 $this->num_resultados = '';
                 $this->total_resultados = array();
                 $this->total_resultados_txt = '';
                 if (isset($_GET['delete'])) {
                     $this->delete_factura();
                 } else {
                     if (!isset($_GET['mostrar']) and (isset($_REQUEST['codagente']) or isset($_REQUEST['codproveedor']) or isset($_REQUEST['codserie']))) {
                         /**
                          * si obtenermos un codagente, un codproveedor o un codserie pasamos direcatemente
                          * a la pestaña de búsqueda, a menos que tengamos un mostrar, que
                          * entonces nos indica donde tenemos que estar.
                          */
                         $this->mostrar = 'buscar';
                     }
                     if (isset($_REQUEST['codproveedor'])) {
                         if ($_REQUEST['codproveedor'] != '') {
                             $pro0 = new proveedor();
                             $this->proveedor = $pro0->get($_REQUEST['codproveedor']);
                         }
                     }
                     if (isset($_REQUEST['codagente'])) {
                         $this->codagente = $_REQUEST['codagente'];
                     }
                     if (isset($_REQUEST['codserie'])) {
                         $this->codserie = $_REQUEST['codserie'];
                     }
                     if (isset($_REQUEST['desde'])) {
                         $this->desde = $_REQUEST['desde'];
                         $this->hasta = $_REQUEST['hasta'];
                         $this->estado = $_REQUEST['estado'];
                     }
                 }
                 /// añadimos segundo nivel de ordenación
                 $order2 = '';
                 if ($this->order == 'fecha DESC') {
                     $order2 = ', hora DESC, numero DESC';
                 } else {
                     if ($this->order == 'fecha ASC') {
                         $order2 = ', hora ASC, numero ASC';
                     }
                 }
                 if ($this->mostrar == 'sinpagar') {
                     $this->resultados = $this->factura->all_sin_pagar($this->offset, FS_ITEM_LIMIT, $this->order . $order2);
                     if ($this->offset == 0) {
                         /// calculamos el total, pero desglosando por divisa
                         $this->total_resultados = array();
                         $this->total_resultados_txt = 'Suma total de esta página:';
                         foreach ($this->resultados as $fac) {
                             if (!isset($this->total_resultados[$fac->coddivisa])) {
                                 $this->total_resultados[$fac->coddivisa] = array('coddivisa' => $fac->coddivisa, 'total' => 0);
                             }
                             $this->total_resultados[$fac->coddivisa]['total'] += $fac->total;
                         }
                     }
                 } else {
                     if ($this->mostrar == 'buscar') {
                         $this->buscar($order2);
                     } else {
                         $this->resultados = $this->factura->all($this->offset, FS_ITEM_LIMIT, $this->order . $order2);
                     }
                 }
             }
         }
     }
 }
 protected function private_core()
 {
     $this->agente = new agente();
     $this->factura = new factura_proveedor();
     $this->serie = new serie();
     $albaran = new albaran_proveedor();
     $this->autorizar_factura = 1;
     if (isset($_GET['nueva'])) {
         if ($_GET['nueva'] == 1) {
             $this->new_message("Factura guardada correctamente.");
         }
         if ($_GET['nueva'] == 2) {
             $this->new_error_msg("La Factura no se guardó. La Fecha corresponde a un ejercicio Cerrado o Inexistente.");
         }
     }
     $this->mostrar = 'todo';
     if (isset($_GET['mostrar'])) {
         $this->mostrar = $_GET['mostrar'];
         setcookie('compras_fac_mostrar', $this->mostrar, time() + FS_COOKIES_EXPIRE);
     } else {
         if (isset($_COOKIE['compras_fac_mostrar'])) {
             $this->mostrar = $_COOKIE['compras_fac_mostrar'];
         }
     }
     $this->offset = 0;
     if (isset($_GET['offset'])) {
         $this->offset = intval($_GET['offset']);
     }
     $this->order = 'fecha DESC';
     if (isset($_GET['order'])) {
         if ($_GET['order'] == 'fecha_desc') {
             $this->order = 'fecha DESC';
         } else {
             if ($_GET['order'] == 'fecha_asc') {
                 $this->order = 'fecha ASC';
             } else {
                 if ($_GET['order'] == 'codigo_desc') {
                     $this->order = 'numproveedor DESC';
                 } else {
                     if ($_GET['order'] == 'codigo_asc') {
                         $this->order = 'numproveedor ASC';
                     }
                 }
             }
         }
         setcookie('compras_fac_order', $this->order, time() + FS_COOKIES_EXPIRE);
     } else {
         if (isset($_COOKIE['compras_fac_order'])) {
             $this->order = $_COOKIE['compras_fac_order'];
         }
     }
     if (isset($_POST['buscar_lineas'])) {
         $this->buscar_lineas();
     } else {
         if (isset($_REQUEST['buscar_proveedor'])) {
             $this->buscar_proveedor();
         } else {
             if (isset($_GET['ref'])) {
                 $this->template = 'extension/compras_facturas_articulo';
                 $articulo = new articulo();
                 $this->articulo = $articulo->get($_GET['ref']);
                 $linea = new linea_factura_proveedor();
                 $this->resultados = $linea->all_from_articulo($_GET['ref'], $this->offset);
             } else {
                 $this->share_extension();
                 $this->proveedor = FALSE;
                 $this->codagente = '';
                 $this->codserie = '';
                 $this->desde = '';
                 $this->hasta = '';
                 $this->num_resultados = '';
                 $this->total_resultados = '';
                 $this->total_resultados_txt = '';
                 if (isset($_POST['delete'])) {
                     $this->delete_albaran();
                 }
                 if (isset($_GET['delete'])) {
                     $this->delete_factura();
                 } else {
                     if (!isset($_GET['mostrar']) and (isset($_REQUEST['codagente']) or isset($_REQUEST['codproveedor']))) {
                         /**
                          * si obtenermos un codagente o un codproveedor pasamos direcatemente
                          * a la pestaña de búsqueda, a menos que tengamos un mostrar, que
                          * entonces nos indica donde tenemos que estar.
                          */
                         $this->mostrar = 'buscar';
                     }
                     if (isset($_REQUEST['codproveedor'])) {
                         if ($_REQUEST['codproveedor'] != '') {
                             $pro0 = new proveedor();
                             $this->proveedor = $pro0->get($_REQUEST['codproveedor']);
                         }
                     }
                     if (isset($_REQUEST['codagente'])) {
                         $this->codagente = $_REQUEST['codagente'];
                     }
                     if (isset($_REQUEST['codserie'])) {
                         $this->codserie = $_REQUEST['codserie'];
                         $this->desde = $_REQUEST['desde'];
                         $this->hasta = $_REQUEST['hasta'];
                     }
                 }
                 /// añadimos segundo nivel de ordenación
                 $order2 = '';
                 if ($this->order == 'fecha DESC') {
                     $order2 = ', numproveedor DESC';
                 } else {
                     if ($this->order == 'fecha ASC') {
                         $order2 = ', numproveedor ASC';
                     }
                 }
                 if ($this->mostrar == 'sinpagar') {
                     $this->resultados = $this->factura->all_sin_pagar($this->offset, FS_ITEM_LIMIT, $this->order . $order2);
                     if ($this->offset == 0) {
                         $this->total_resultados = 0;
                         $this->total_resultados_txt = 'Suma total de esta página:';
                         foreach ($this->resultados as $alb) {
                             $this->total_resultados += $alb->total;
                         }
                     }
                 } else {
                     if ($this->mostrar == 'buscar') {
                         $this->buscar($order2);
                     } else {
                         $this->resultados = $this->factura->all($this->offset, FS_ITEM_LIMIT, $this->order . $order2);
                     }
                 }
             }
         }
     }
     if ($this->mostrar == 'remitos') {
         $this->resultados = $albaran->all_ptefactura($this->offset, $this->order . $order2);
         if ($this->offset == 0) {
             $this->total_resultados = 0;
             $this->total_resultados_txt = 'Suma total de esta página:';
             foreach ($this->resultados as $alb) {
                 $this->total_resultados += $alb->total;
             }
         }
     }
 }