Пример #1
0
 protected function private_core()
 {
     $this->share_extensions();
     /// ¿El usuario tiene permiso para eliminar en esta página?
     $this->allow_delete = $this->user->allow_delete_on(__CLASS__);
     $this->articulo = new articulo();
     $this->cliente = new cliente();
     $this->cliente_s = FALSE;
     $this->familia = new familia();
     $this->impuesto = new impuesto();
     $this->results = array();
     if (isset($_REQUEST['buscar_cliente'])) {
         $this->buscar_cliente();
     } else {
         if (isset($_REQUEST['datoscliente'])) {
             $this->datos_cliente();
         } else {
             if ($this->query != '') {
                 $this->new_search();
             } else {
                 if (isset($_REQUEST['referencia4precios'])) {
                     $this->get_precios_articulo();
                 } else {
                     $this->agente = $this->user->get_agente();
                     $this->almacen = new almacen();
                     $this->divisa = new divisa();
                     $this->ejercicio = new ejercicio();
                     $this->forma_pago = new forma_pago();
                     $this->serie = new serie();
                     $this->imprimir_descripciones = isset($_COOKIE['imprimir_desc']);
                     $this->imprimir_observaciones = isset($_COOKIE['imprimir_obs']);
                     if ($this->agente) {
                         $this->caja = FALSE;
                         $this->terminal = FALSE;
                         $caja = new caja();
                         $terminal0 = new terminal_caja();
                         foreach ($caja->all_by_agente($this->agente->codagente) as $cj) {
                             if ($cj->abierta()) {
                                 $this->caja = $cj;
                                 $this->terminal = $terminal0->get($cj->fs_id);
                                 break;
                             }
                         }
                         if (!$this->caja) {
                             if (isset($_POST['terminal'])) {
                                 $this->terminal = $terminal0->get($_POST['terminal']);
                                 if (!$this->terminal) {
                                     $this->new_error_msg('Terminal no encontrado.');
                                 } else {
                                     if ($this->terminal->disponible()) {
                                         $this->caja = new caja();
                                         $this->caja->fs_id = $this->terminal->id;
                                         $this->caja->codagente = $this->agente->codagente;
                                         $this->caja->dinero_inicial = floatval($_POST['d_inicial']);
                                         $this->caja->dinero_fin = floatval($_POST['d_inicial']);
                                         if ($this->caja->save()) {
                                             $this->new_message("Caja iniciada con " . $this->show_precio($this->caja->dinero_inicial));
                                         } else {
                                             $this->new_error_msg("¡Imposible guardar los datos de caja!");
                                         }
                                     } else {
                                         $this->new_error_msg('El terminal ya no está disponible.');
                                     }
                                 }
                             } else {
                                 if (isset($_GET['terminal'])) {
                                     $this->terminal = $terminal0->get($_GET['terminal']);
                                     if ($this->terminal) {
                                         $this->terminal->abrir_cajon();
                                         $this->terminal->save();
                                     } else {
                                         $this->new_error_msg('Terminal no encontrado.');
                                     }
                                 }
                             }
                         }
                         if ($this->caja) {
                             if (isset($_POST['cliente'])) {
                                 $this->cliente_s = $this->cliente->get($_POST['cliente']);
                             } else {
                                 if ($this->terminal) {
                                     $this->cliente_s = $this->cliente->get($this->terminal->codcliente);
                                 }
                             }
                             if (!$this->cliente_s) {
                                 foreach ($this->cliente->all() as $cli) {
                                     $this->cliente_s = $cli;
                                     break;
                                 }
                             }
                             if (isset($_GET['abrir_caja'])) {
                                 $this->abrir_caja();
                             } else {
                                 if (isset($_GET['cerrar_caja'])) {
                                     $this->cerrar_caja();
                                 } else {
                                     if (isset($_POST['cliente'])) {
                                         if (intval($_POST['numlineas']) > 0) {
                                             $this->nueva_factura_cliente();
                                         }
                                     } else {
                                         if (isset($_GET['reticket'])) {
                                             $this->reimprimir_ticket();
                                         }
                                     }
                                 }
                             }
                         } else {
                             $this->results = $terminal0->disponibles();
                         }
                     } else {
                         $this->new_error_msg('No tienes un <a href="' . $this->user->url() . '">agente asociado</a>
            a tu usuario, y por tanto no puedes hacer tickets.');
                     }
                 }
             }
         }
     }
 }