protected function private_core()
 {
     //
     //	  $this->ppage_r = $this->page->get('compras_albaranes');
     if (isset($_REQUEST['autorizar_factura'])) {
         $this->autorizar_factura = $_REQUEST['autorizar_factura'];
     }
     if ($this->autorizar_factura == 1) {
         $this->ppage = $this->page->get('compras_facturas');
     } else {
         $this->ppage = $this->page->get('compras_albaranes');
     }
     $this->agente = FALSE;
     $this->empresa = new empresa();
     $albaran = new albaran_proveedor();
     $this->albaran = FALSE;
     $this->divisa = new divisa();
     $this->ejercicio = new ejercicio();
     $this->fabricante = new fabricante();
     $this->familia = new familia();
     $this->forma_pago = new forma_pago();
     $this->impuesto = new impuesto();
     $this->proveedor = new proveedor();
     $this->proveedor_s = FALSE;
     $this->serie = new serie();
     $factura = new factura_proveedor();
     $this->verif_factura = $factura->all_sin_anular();
     $this->subcuentas = new subcuenta();
     $this->view_subcuen = $this->subcuentas->subcoenta_compras($this->empresa->codejercicio);
     $this->view_subcuen_dev = $this->subcuentas->subcoenta_compras_credito($this->empresa->codejercicio);
     $this->list_subcuen = $this->subcuentas->subcoenta_compras($this->empresa->codejercicio);
     /// ¿El usuario tiene permiso para eliminar en esta página?
     $this->allow_delete = $this->user->allow_delete_on(__CLASS__);
     /// comprobamos si el usuario tiene acceso a nueva_compra
     $this->nuevo_albaran_url = FALSE;
     if ($this->user->have_access_to('nueva_compra', FALSE)) {
         $nuevoalbp = $this->page->get('nueva_compra');
         if ($nuevoalbp) {
             $this->nuevo_albaran_url = $nuevoalbp->url();
         }
     }
     if (isset($_POST['idalbaran'])) {
         if ($_POST['facturar'] == 'TRUE') {
             $this->albaran = $albaran->get($_POST['idalbaran']);
             $this->modificar();
             $this->generar_factura();
             header('Location: ' . $this->url_retorno());
         } else {
             $this->albaran = $albaran->get($_POST['idalbaran']);
             $this->modificar();
         }
     } else {
         if (isset($_GET['id'])) {
             $this->albaran = $albaran->get($_GET['id']);
         }
     }
     if ($this->albaran) {
         $this->page->title = $this->albaran->codigo;
         /// cargamos el agente
         if (!is_null($this->albaran->codagente)) {
             $agente = new agente();
             $this->agente = $agente->get($this->albaran->codagente);
         }
         /// cargamos el proveedor
         $this->proveedor_s = $this->proveedor->get($this->albaran->codproveedor);
         $this->cai = $this->proveedor_s->cai;
         $this->caivence = $this->proveedor_s->caivence;
         /// comprobamos el albarán
         $this->albaran->full_test();
         if (isset($_POST['facturar']) and isset($_GET['petid']) and $this->albaran->ptefactura) {
             if ($this->duplicated_petition($_GET['petid'])) {
                 $this->new_error_msg('Petición duplicada. Evita hacer doble clic sobre los botones.');
             } else {
                 $this->generar_factura();
             }
             if ($this->autorizar_factura == 1) {
                 header('Location: ' . $this->url_retorno());
             } else {
                 header('Location: ' . $this->url_albaran());
             }
         } else {
             if (isset($_GET['forze_fecha'])) {
                 $this->forzar_fecha();
             }
         }
     } else {
         $this->new_error_msg("¡" . FS_ALBARAN . " de proveedor no encontrado!");
     }
 }
 protected function private_core()
 {
     $this->ppage = $this->page->get('compras_albaranes');
     $this->empresa = new empresa();
     $this->articulo_prov = new articulo_proveedor();
     $this->fabricante = new fabricante();
     $this->familia = new familia();
     $this->impuesto = new impuesto();
     $this->proveedor = new proveedor();
     $this->proveedor_s = FALSE;
     $this->results = array();
     $factura = new factura_proveedor();
     $this->verif_factura = $factura->all_sin_anular();
     $remito = new albaran_proveedor();
     $this->verif_remito = $remito->all_ptefactura();
     $this->subcuentas = new subcuenta();
     $this->artsubcuentas = new articulo();
     $this->view_subcuen = $this->subcuentas->subcoenta_compras($this->empresa->codejercicio);
     $this->view_subcuen_dev = $this->subcuentas->subcoenta_compras($this->empresa->codejercicio);
     if (isset($_REQUEST['tipo'])) {
         if (isset($_REQUEST['autorizar_factura'])) {
             $this->autorizar_factura = $_REQUEST['autorizar_factura'];
         }
         $this->tipo = $_REQUEST['tipo'];
     } else {
         foreach ($this->tipos_a_guardar() as $t) {
             $this->tipo = $t['tipo'];
             break;
         }
     }
     if (isset($_REQUEST['buscar_proveedor'])) {
         $this->buscar_proveedor();
     } else {
         if (isset($_REQUEST['datosproveedor'])) {
             $this->datos_proveedor();
         } else {
             if (isset($_REQUEST['new_articulo'])) {
                 $this->new_articulo();
             } else {
                 if ($this->query != '') {
                     $this->new_search();
                 } else {
                     if (isset($_POST['referencia4precios'])) {
                         $this->get_precios_articulo();
                     } else {
                         if (isset($_POST['proveedor'])) {
                             if (isset($_POST['numfactproveedor'])) {
                                 $this->numproveedor = $_POST['numfactproveedor'];
                             }
                             $this->proveedor_s = $this->proveedor->get($_POST['proveedor']);
                             $this->cai = $this->proveedor_s->cai;
                             $this->caivence = $this->proveedor_s->caivence;
                             if (isset($_POST['nuevo_proveedor'])) {
                                 if ($_POST['nuevo_proveedor'] != '') {
                                     $this->proveedor_s = FALSE;
                                     if ($_POST['nuevo_dni'] != '') {
                                         $this->proveedor_s = $this->proveedor->get_by_cifnif($_POST['nuevo_dni']);
                                         if ($this->proveedor_s) {
                                             $this->new_advice('Ya existe un proveedor con ese ' . FS_CIFNIF . '. Se ha seleccionado.');
                                         }
                                     }
                                     if (!$this->proveedor_s) {
                                         $this->proveedor_s = new proveedor();
                                         $this->proveedor_s->codproveedor = $this->proveedor_s->get_new_codigo();
                                         $this->proveedor_s->nombre = $this->proveedor_s->razonsocial = $_POST['nuevo_proveedor'];
                                         $this->proveedor_s->cifnif = $_POST['nuevo_dni'];
                                         $this->proveedor_s->acreedor = isset($_POST['acreedor']);
                                         $this->proveedor_s->save();
                                     }
                                 }
                             }
                             if (isset($_POST['codagente'])) {
                                 $agente = new agente();
                                 $this->agente = $agente->get($_POST['codagente']);
                             } else {
                                 $this->agente = $this->user->get_agente();
                             }
                             $this->almacen = new almacen();
                             $this->serie = new serie();
                             $this->forma_pago = new forma_pago();
                             $this->divisa = new divisa();
                             if (isset($_POST['tipo'])) {
                                 if ($_POST['tipo'] == 'pedido') {
                                     if (class_exists('pedido_proveedor')) {
                                         $this->nuevo_pedido_proveedor();
                                     } else {
                                         $this->new_error_msg('Clase pedido_proveedor no encontrada.');
                                     }
                                 } else {
                                     if ($_POST['pagina'] == 'albaran') {
                                         $this->nuevo_albaran_proveedor();
                                         //			   header('Location: '.$this->url_list1());
                                     } else {
                                         if ($_POST['tipo'] == 'B') {
                                             $this->nueva_factura_proveedor();
                                             //			header('Location: '.$this->url_list());
                                         } else {
                                             if ($_POST['tipo'] == 'F') {
                                                 $this->nueva_factura_proveedor();
                                                 //			header('Location: '.$this->url_list());
                                             } else {
                                                 if ($_POST['tipo'] == 'T') {
                                                     $this->nueva_factura_proveedor();
                                                     //			header('Location: '.$this->url_list());
                                                 } else {
                                                     if ($_POST['tipo'] == 'Q') {
                                                         $this->nueva_factura_proveedor();
                                                         //			header('Location: '.$this->url_list());
                                                     } else {
                                                         if ($_POST['tipo'] == 'C') {
                                                             $this->nueva_factura_proveedor();
                                                             //			  header('Location: '.$this->url_list());
                                                         } else {
                                                             if ($_POST['tipo'] == 'D') {
                                                                 $this->nueva_factura_proveedor();
                                                                 //			  header('Location: '.$this->url_list());
                                                             }
                                                         }
                                                     }
                                                 }
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
 }