Example #1
0
 protected function private_core()
 {
     $this->mostrar = 'clientes';
     if (isset($_REQUEST['mostrar'])) {
         $this->mostrar = $_REQUEST['mostrar'];
     }
     $this->offset = 0;
     if (isset($_REQUEST['offset'])) {
         $this->offset = intval($_REQUEST['offset']);
     }
     $this->grupo = FALSE;
     $this->tarifa = FALSE;
     if (isset($_REQUEST['cod'])) {
         $grupo = new grupo_clientes();
         $this->grupo = $grupo->get($_REQUEST['cod']);
     }
     if ($this->grupo) {
         $tar0 = new tarifa();
         $this->tarifa = $tar0->get($this->grupo->codtarifa);
         $this->total_clientes = 0;
         $this->total_facturas = 0;
         if ($this->mostrar == 'clientes') {
             $this->resultados = $this->clientes_from_grupo($this->grupo->codgrupo, $this->offset);
         } else {
             $this->resultados = $this->facturas_from_grupo($this->grupo->codgrupo, $this->offset);
         }
     } else {
         $this->new_error_msg('Grupo no encontrado.');
     }
 }
 private function new_search()
 {
     /// desactivamos la plantilla HTML
     $this->template = FALSE;
     $articulo = new articulo();
     $codfamilia = '';
     if (isset($_REQUEST['codfamilia'])) {
         $codfamilia = $_REQUEST['codfamilia'];
     }
     $codfabricante = '';
     if (isset($_REQUEST['codfabricante'])) {
         $codfabricante = $_REQUEST['codfabricante'];
     }
     $con_stock = isset($_REQUEST['con_stock']);
     $this->results = $articulo->search($this->query, 0, $codfamilia, $con_stock, $codfabricante);
     /// añadimos la busqueda, el descuento y la cantidad
     foreach ($this->results as $i => $value) {
         $this->results[$i]->query = $this->query;
         $this->results[$i]->dtopor = 0;
         $this->results[$i]->cantidad = 1;
     }
     /// ejecutamos las funciones de las extensiones
     foreach ($this->extensions as $ext) {
         if ($ext->type == 'function' and $ext->params == 'new_search') {
             $name = $ext->text;
             $name($this->db, $this->results);
         }
     }
     /// buscamos el grupo de clientes y la tarifa
     if (isset($_REQUEST['codcliente'])) {
         $cliente = $this->cliente->get($_REQUEST['codcliente']);
         if ($cliente->codgrupo) {
             $grupo0 = new grupo_clientes();
             $tarifa0 = new tarifa();
             $grupo = $grupo0->get($cliente->codgrupo);
             if ($grupo) {
                 $tarifa = $tarifa0->get($grupo->codtarifa);
                 if ($tarifa) {
                     $tarifa->set_precios($this->results);
                 }
             }
         }
     }
     header('Content-Type: application/json');
     echo json_encode($this->results);
 }
 private function new_search()
 {
     /// desactivamos la plantilla HTML
     $this->template = FALSE;
     $fsvar = new fs_var();
     $multi_almacen = $fsvar->simple_get('multi_almacen');
     $stock = new stock();
     $articulo = new articulo();
     $codfamilia = '';
     if (isset($_REQUEST['codfamilia'])) {
         $codfamilia = $_REQUEST['codfamilia'];
     }
     $codfabricante = '';
     if (isset($_REQUEST['codfabricante'])) {
         $codfabricante = $_REQUEST['codfabricante'];
     }
     $con_stock = isset($_REQUEST['con_stock']);
     $this->results = $articulo->search($this->query, 0, $codfamilia, $con_stock, $codfabricante);
     /// añadimos la busqueda, el descuento, la cantidad, etc...
     foreach ($this->results as $i => $value) {
         $this->results[$i]->query = $this->query;
         $this->results[$i]->dtopor = 0;
         $this->results[$i]->cantidad = 1;
         $this->results[$i]->coddivisa = $this->empresa->coddivisa;
         /// añadimos el stock del almacén y el general
         $this->results[$i]->stockalm = $this->results[$i]->stockfis;
         if ($multi_almacen and isset($_REQUEST['codalmacen'])) {
             $this->results[$i]->stockalm = $stock->total_from_articulo($this->results[$i]->referencia, $_REQUEST['codalmacen']);
         }
     }
     /// ejecutamos las funciones de las extensiones
     foreach ($this->extensions as $ext) {
         if ($ext->type == 'function' and $ext->params == 'new_search') {
             $name = $ext->text;
             $name($this->db, $this->results);
         }
     }
     /// buscamos el grupo de clientes y la tarifa
     if (isset($_REQUEST['codcliente'])) {
         $cliente = $this->cliente->get($_REQUEST['codcliente']);
         if ($cliente) {
             if ($cliente->codgrupo) {
                 $grupo0 = new grupo_clientes();
                 $tarifa0 = new tarifa();
                 $grupo = $grupo0->get($cliente->codgrupo);
                 if ($grupo) {
                     $tarifa = $tarifa0->get($grupo->codtarifa);
                     if ($tarifa) {
                         $tarifa->set_precios($this->results);
                     }
                 }
             }
         }
     }
     /// convertimos la divisa
     if (isset($_REQUEST['coddivisa'])) {
         if ($_REQUEST['coddivisa'] != $this->empresa->coddivisa) {
             foreach ($this->results as $i => $value) {
                 $this->results[$i]->coddivisa = $_REQUEST['coddivisa'];
                 $this->results[$i]->pvp = $this->divisa_convert($value->pvp, $this->empresa->coddivisa, $_REQUEST['coddivisa']);
             }
         }
     }
     header('Content-Type: application/json');
     echo json_encode($this->results);
 }
 protected function private_core()
 {
     /// ¿El usuario tiene permiso para eliminar en esta página?
     $this->allow_delete = $this->user->allow_delete_on(__CLASS__);
     $this->cliente = new cliente();
     $this->grupo = new grupo_clientes();
     $this->pais = new pais();
     $this->serie = new serie();
     $this->tarifa = new tarifa();
     $this->tarifas = $this->tarifa->all();
     $this->ncf_tipo = new ncf_tipo();
     $this->ncf_entidad_tipo = new ncf_entidad_tipo();
     /// cargamos la configuración
     $fsvar = new fs_var();
     $this->nuevocli_setup = $fsvar->array_get(array('nuevocli_cifnif_req' => 0, 'nuevocli_direccion' => 1, 'nuevocli_direccion_req' => 0, 'nuevocli_codpostal' => 1, 'nuevocli_codpostal_req' => 0, 'nuevocli_pais' => 0, 'nuevocli_pais_req' => 0, 'nuevocli_provincia' => 1, 'nuevocli_provincia_req' => 0, 'nuevocli_ciudad' => 1, 'nuevocli_ciudad_req' => 0, 'nuevocli_telefono1' => 0, 'nuevocli_telefono1_req' => 0, 'nuevocli_telefono2' => 0, 'nuevocli_telefono2_req' => 0, 'nuevocli_codgrupo' => ''), FALSE);
     if (isset($_GET['delete_grupo'])) {
         $grupo = $this->grupo->get($_GET['delete_grupo']);
         if ($grupo) {
             if ($grupo->delete()) {
                 $this->new_message('Grupo eliminado correctamente.');
             } else {
                 $this->new_error_msg('Imposible eliminar el grupo.');
             }
         } else {
             $this->new_error_msg('Grupo no encontrado.');
         }
     } else {
         if (isset($_POST['codgrupo'])) {
             $grupo = $this->grupo->get($_POST['codgrupo']);
             if (!$grupo) {
                 $grupo = new grupo_clientes();
                 $grupo->codgrupo = $_POST['codgrupo'];
             }
             $grupo->nombre = $_POST['nombre'];
             $grupo->codtarifa = NULL;
             if ($_POST['codtarifa'] != '---') {
                 $grupo->codtarifa = $_POST['codtarifa'];
             }
             if ($grupo->save()) {
                 $this->new_message('Grupo guardado correctamente.');
             } else {
                 $this->new_error_msg('Imposible guardar el grupo.');
             }
         } else {
             if (isset($_GET['delete'])) {
                 $cliente = $this->cliente->get($_GET['delete']);
                 if ($cliente) {
                     if (FS_DEMO) {
                         $this->new_error_msg('En el modo demo no se pueden eliminar clientes. Otros usuarios podrían necesitarlos.');
                     } else {
                         if ($cliente->delete()) {
                             $this->new_message('Cliente eliminado correctamente.');
                         } else {
                             $this->new_error_msg('Ha sido imposible eliminar el cliente.');
                         }
                     }
                 } else {
                     $this->new_error_msg('Cliente no encontrado.');
                 }
             } else {
                 if (isset($_POST['cifnif'])) {
                     $cliente = new cliente();
                     $cliente->codcliente = $cliente->get_new_codigo();
                     $cliente->nombre = $_POST['nombre'];
                     $cliente->razonsocial = $_POST['nombre'];
                     $cliente->tipoidfiscal = $_POST['tipoidfiscal'];
                     $cliente->cifnif = $_POST['cifnif'];
                     $cliente->personafisica = isset($_POST['personafisica']);
                     if (isset($_POST['scodgrupo'])) {
                         if ($_POST['scodgrupo'] != '') {
                             $cliente->codgrupo = $_POST['scodgrupo'];
                         }
                     }
                     if (isset($_POST['telefono1'])) {
                         $cliente->telefono1 = $_POST['telefono1'];
                     }
                     if (isset($_POST['telefono2'])) {
                         $cliente->telefono2 = $_POST['telefono2'];
                     }
                     if ($cliente->save()) {
                         if (\filter_input(INPUT_POST, 'tipo_comprobante') != '') {
                             $ncf_entidad_tipo = new ncf_entidad_tipo();
                             $ncf_entidad_tipo->idempresa = $this->empresa->id;
                             $ncf_entidad_tipo->entidad = $cliente->codcliente;
                             $ncf_entidad_tipo->tipo_entidad = 'CLI';
                             $ncf_entidad_tipo->tipo_comprobante = \filter_input(INPUT_POST, 'tipo_comprobante');
                             $ncf_entidad_tipo->estado = TRUE;
                             $ncf_entidad_tipo->usuario_creacion = $this->user->nick;
                             $ncf_entidad_tipo->fecha_creacion = Date('d-m-Y H:i:s');
                             $ncf_entidad_tipo->save();
                         }
                         $dircliente = new direccion_cliente();
                         $dircliente->codcliente = $cliente->codcliente;
                         $dircliente->codpais = $this->empresa->codpais;
                         $dircliente->provincia = $this->empresa->provincia;
                         $dircliente->ciudad = $this->empresa->ciudad;
                         $dircliente->descripcion = 'Principal';
                         if (isset($_POST['pais'])) {
                             $dircliente->codpais = $_POST['pais'];
                         }
                         if (isset($_POST['provincia'])) {
                             $dircliente->provincia = $_POST['provincia'];
                         }
                         if (isset($_POST['ciudad'])) {
                             $dircliente->ciudad = $_POST['ciudad'];
                         }
                         if (isset($_POST['codpostal'])) {
                             $dircliente->codpostal = $_POST['codpostal'];
                         }
                         if (isset($_POST['direccion'])) {
                             $dircliente->direccion = $_POST['direccion'];
                         }
                         if ($dircliente->save()) {
                             if ($this->empresa->contintegrada) {
                                 /// forzamos la creación de la subcuenta
                                 $cliente->get_subcuenta($this->empresa->codejercicio);
                             }
                             /// redireccionamos a la página del cliente
                             header('location: ' . $cliente->url());
                         } else {
                             $this->new_error_msg("¡Imposible guardar la dirección del cliente!");
                         }
                     } else {
                         $this->new_error_msg("¡Imposible guardar los datos del cliente!");
                     }
                 }
             }
         }
     }
     $this->offset = 0;
     if (isset($_GET['offset'])) {
         $this->offset = intval($_GET['offset']);
     }
     $this->ciudad = '';
     if (isset($_REQUEST['ciudad'])) {
         $this->ciudad = $this->empresa->no_html($_REQUEST['ciudad']);
     }
     $this->provincia = '';
     if (isset($_REQUEST['provincia'])) {
         $this->provincia = $this->empresa->no_html($_REQUEST['provincia']);
     }
     $this->codpais = '';
     if (isset($_REQUEST['codpais'])) {
         $this->codpais = $_REQUEST['codpais'];
     }
     $this->codgrupo = '';
     if (isset($_REQUEST['bcodgrupo'])) {
         $this->codgrupo = $_REQUEST['bcodgrupo'];
     }
     $this->orden = 'nombre ASC';
     if (isset($_REQUEST['orden'])) {
         $this->orden = $_REQUEST['orden'];
     }
     $this->nocifnif = isset($_REQUEST['nocifnif']);
     $this->debaja = isset($_REQUEST['debaja']);
     $this->buscar();
     $this->grupos = $this->grupo->all();
 }
 protected function private_core()
 {
     /// ¿El usuario tiene permiso para eliminar en esta página?
     $this->allow_delete = $this->user->allow_delete_on(__CLASS__);
     $this->cliente = new cliente();
     $this->grupo = new grupo_clientes();
     $this->pais = new pais();
     $this->serie = new serie();
     $this->tarifa = new tarifa();
     /// cargamos la configuración
     $fsvar = new fs_var();
     $this->nuevocli_setup = $fsvar->array_get(array('nuevocli_cifnif_req' => 0, 'nuevocli_direccion' => 1, 'nuevocli_direccion_req' => 0, 'nuevocli_codpostal' => 1, 'nuevocli_codpostal_req' => 0, 'nuevocli_pais' => 0, 'nuevocli_pais_req' => 0, 'nuevocli_provincia' => 1, 'nuevocli_provincia_req' => 0, 'nuevocli_ciudad' => 1, 'nuevocli_ciudad_req' => 0, 'nuevocli_telefono1' => 0, 'nuevocli_telefono1_req' => 0, 'nuevocli_telefono2' => 0, 'nuevocli_telefono2_req' => 0), FALSE);
     if (isset($_GET['delete_grupo'])) {
         $grupo = $this->grupo->get($_GET['delete_grupo']);
         if ($grupo) {
             if ($grupo->delete()) {
                 $this->new_message('Grupo eliminado correctamente.');
             } else {
                 $this->new_error_msg('Imposible eliminar el grupo.');
             }
         } else {
             $this->new_error_msg('Grupo no encontrado.');
         }
     } else {
         if (isset($_POST['codgrupo'])) {
             $grupo = $this->grupo->get($_POST['codgrupo']);
             if (!$grupo) {
                 $grupo = new grupo_clientes();
                 $grupo->codgrupo = $_POST['codgrupo'];
             }
             $grupo->nombre = $_POST['nombre'];
             $grupo->codtarifa = NULL;
             if ($_POST['codtarifa'] != '---') {
                 $grupo->codtarifa = $_POST['codtarifa'];
             }
             if ($grupo->save()) {
                 $this->new_message('Grupo guardado correctamente.');
             } else {
                 $this->new_error_msg('Imposible guardar el grupo.');
             }
         } else {
             if (isset($_GET['delete'])) {
                 $cliente = $this->cliente->get($_GET['delete']);
                 if ($cliente) {
                     if (FS_DEMO) {
                         $this->new_error_msg('En el modo demo no se pueden eliminar clientes. Otros usuarios podrían necesitarlos.');
                     } else {
                         if ($cliente->delete()) {
                             $this->new_message('Cliente eliminado correctamente.');
                         } else {
                             $this->new_error_msg('Ha sido imposible eliminar el cliente.');
                         }
                     }
                 } else {
                     $this->new_error_msg('Cliente no encontrado.');
                 }
             } else {
                 if (isset($_POST['cifnif'])) {
                     $this->save_codpais($_POST['pais']);
                     $cliente = FALSE;
                     if ($_POST['cifnif'] != '') {
                         $cliente = $this->cliente->get_by_cifnif($_POST['cifnif']);
                         if ($cliente) {
                             $this->new_advice('Ya existe un cliente con el ' . FS_CIFNIF . ' ' . $_POST['cifnif']);
                             $this->query = $_POST['cifnif'];
                         }
                     }
                     if (!$cliente) {
                         $cliente = new cliente();
                         $cliente->codcliente = $cliente->get_new_codigo();
                         $cliente->nombre = $_POST['nombre'];
                         $cliente->razonsocial = $_POST['nombre'];
                         $cliente->cifnif = $_POST['cifnif'];
                         $cliente->codserie = $this->empresa->codserie;
                         $cliente->codgrupo = $_POST['scodgrupo'];
                         if (isset($_POST['telefono1'])) {
                             $cliente->telefono1 = $_POST['telefono1'];
                         }
                         if (isset($_POST['telefono2'])) {
                             $cliente->telefono2 = $_POST['telefono2'];
                         }
                         if ($cliente->save()) {
                             $dircliente = new direccion_cliente();
                             $dircliente->codcliente = $cliente->codcliente;
                             $dircliente->codpais = $this->empresa->codpais;
                             $dircliente->provincia = $this->empresa->provincia;
                             $dircliente->ciudad = $this->empresa->ciudad;
                             $dircliente->descripcion = 'Principal';
                             if (isset($_POST['pais'])) {
                                 $dircliente->codpais = $_POST['pais'];
                             }
                             if (isset($_POST['provincia'])) {
                                 $dircliente->provincia = $_POST['provincia'];
                             }
                             if (isset($_POST['ciudad'])) {
                                 $dircliente->ciudad = $_POST['ciudad'];
                             }
                             if (isset($_POST['codpostal'])) {
                                 $dircliente->codpostal = $_POST['codpostal'];
                             }
                             if (isset($_POST['direccion'])) {
                                 $dircliente->direccion = $_POST['direccion'];
                             }
                             if ($dircliente->save()) {
                                 header('location: ' . $cliente->url());
                             } else {
                                 $this->new_error_msg("¡Imposible guardar la dirección del cliente!");
                             }
                         } else {
                             $this->new_error_msg("¡Imposible guardar los datos del cliente!");
                         }
                     }
                 }
             }
         }
     }
     $this->offset = 0;
     if (isset($_GET['offset'])) {
         $this->offset = intval($_GET['offset']);
     }
     if ($this->query != '') {
         $this->resultados = $this->cliente->search($this->query, $this->offset);
     } else {
         $this->resultados = $this->cliente->all($this->offset);
     }
     $this->grupos = $this->grupo->all();
 }
 private function new_search()
 {
     /// desactivamos la plantilla HTML
     $this->template = FALSE;
     $articulo = new articulo();
     $codfamilia = '';
     if (isset($_REQUEST['codfamilia'])) {
         $codfamilia = $_REQUEST['codfamilia'];
     }
     $con_stock = isset($_REQUEST['con_stock']);
     $this->results = $articulo->search($this->query, 0, $codfamilia, $con_stock);
     /// añadimos la busqueda
     foreach ($this->results as $i => $value) {
         $this->results[$i]->query = $this->query;
         $this->results[$i]->dtopor = 0;
     }
     /// buscamos el grupo de clientes y la tarifa
     if (isset($_REQUEST['codcliente'])) {
         $cliente = $this->cliente->get($_REQUEST['codcliente']);
         if ($cliente->codgrupo) {
             $grupo0 = new grupo_clientes();
             $grupo = $grupo0->get($cliente->codgrupo);
             if ($grupo) {
                 $tarifa0 = new tarifa();
                 $tarifa = $tarifa0->get($grupo->codtarifa);
                 if ($tarifa) {
                     foreach ($this->results as $i => $value) {
                         $this->results[$i]->dtopor = 0 - $tarifa->incporcentual;
                     }
                 }
             }
         }
     }
     header('Content-Type: application/json');
     echo json_encode($this->results);
 }
Example #7
0
 /**
  * Devuelve un array con los nombres de los grupos que tienen asignada
  * la tarifa $codtarifa
  * @param type $codtarifa
  * @return array
  */
 public function get_grupos_tar($codtarifa)
 {
     $lista = array();
     $grupo = new grupo_clientes();
     foreach ($grupo->all_with_tarifa($codtarifa) as $gru) {
         $lista[] = $gru;
     }
     return $lista;
 }
Example #8
0
 protected function private_core()
 {
     $this->cliente = new cliente();
     $this->grupo = new grupo_clientes();
     $this->pais = new pais();
     $this->serie = new serie();
     $this->tarifa = new tarifa();
     /// ¿El usuario tiene permiso para eliminar en esta página?
     $this->allow_delete = $this->user->allow_delete_on(__CLASS__);
     if (isset($_REQUEST['buscar_provincia'])) {
         $this->buscar_provincia();
     } else {
         if (isset($_REQUEST['buscar_ciudad'])) {
             $this->buscar_ciudad();
         } else {
             if (isset($_GET['delete_grupo'])) {
                 $grupo = $this->grupo->get($_GET['delete_grupo']);
                 if ($grupo) {
                     if ($grupo->delete()) {
                         $this->new_message('Grupo eliminado correctamente.');
                     } else {
                         $this->new_error_msg('Imposible eliminar el grupo.');
                     }
                 } else {
                     $this->new_error_msg('Grupo no encontrado.');
                 }
             } else {
                 if (isset($_POST['codgrupo'])) {
                     $grupo = $this->grupo->get($_POST['codgrupo']);
                     if (!$grupo) {
                         $grupo = new grupo_clientes();
                         $grupo->codgrupo = $_POST['codgrupo'];
                     }
                     $grupo->nombre = $_POST['nombre'];
                     if ($_POST['codtarifa'] == '---') {
                         $grupo->codtarifa = NULL;
                     } else {
                         $grupo->codtarifa = $_POST['codtarifa'];
                     }
                     if ($grupo->save()) {
                         $this->new_message('Grupo guardado correctamente.');
                     } else {
                         $this->new_error_msg('Imposible guardar el grupo.');
                     }
                 } else {
                     if (isset($_GET['delete'])) {
                         $cliente = $this->cliente->get($_GET['delete']);
                         if ($cliente) {
                             if (FS_DEMO) {
                                 $this->new_error_msg('En el modo demo no se pueden eliminar clientes. Otros usuarios podrían necesitarlos.');
                             } else {
                                 if ($cliente->delete()) {
                                     $this->new_message('Cliente eliminado correctamente.');
                                 } else {
                                     $this->new_error_msg('Ha sido imposible eliminar el cliente.');
                                 }
                             }
                         } else {
                             $this->new_error_msg('Cliente no encontrado.');
                         }
                     } else {
                         if (isset($_POST['cifnif'])) {
                             $this->save_codpais($_POST['pais']);
                             $cliente = new cliente();
                             $cliente->codcliente = $cliente->get_new_codigo();
                             if (isset($_POST['cli_codgrupo'])) {
                                 $cliente->codgrupo = $_POST['cli_codgrupo'];
                             }
                             if ($_POST['razonsocial'] != '') {
                                 $cliente->nombre = $cliente->razonsocial = $_POST['razonsocial'];
                             } else {
                                 $cliente->nombre = $cliente->razonsocial = $_POST['nombre'] . ' ' . $_POST['nombre2'] . ' ' . $_POST['apellido'] . ' ' . $_POST['apellido2'];
                             }
                             $cliente->cifnif = $_POST['cifnif'];
                             $cliente->codserie = $this->empresa->codserie;
                             if ($cliente->save()) {
                                 $cliente_prop = new cliente_propiedad();
                                 $cliente_prop->array_save($cliente->codcliente, array('nombre' => $_POST['nombre'], 'nombre2' => $_POST['nombre2'], 'apellido' => $_POST['apellido'], 'apellido2' => $_POST['apellido2']));
                                 $dircliente = new direccion_cliente();
                                 $dircliente->codcliente = $cliente->codcliente;
                                 $dircliente->codpais = $_POST['pais'];
                                 $dircliente->provincia = $_POST['provincia'];
                                 $dircliente->ciudad = $_POST['ciudad'];
                                 $dircliente->codpostal = $_POST['codpostal'];
                                 $dircliente->direccion = $_POST['direccion'];
                                 $dircliente->descripcion = 'Principal';
                                 if ($dircliente->save()) {
                                     header('location: ' . $cliente->url());
                                 } else {
                                     $this->new_error_msg("¡Imposible guardar la dirección del cliente!");
                                 }
                             } else {
                                 $this->new_error_msg("¡Imposible guardar los datos del cliente!");
                             }
                         }
                     }
                 }
             }
         }
     }
     $this->offset = 0;
     if (isset($_GET['offset'])) {
         $this->offset = intval($_GET['offset']);
     }
     if ($this->query != '') {
         $this->resultados = $this->cliente->search($this->query, $this->offset);
     } else {
         $this->resultados = $this->cliente->all($this->offset);
     }
     $this->grupos = $this->grupo->all();
 }
Example #9
0
 private function new_search()
 {
     /// cambiamos la plantilla HTML
     $this->template = 'ajax/tpv_recambios';
     $codfamilia = '';
     if (isset($_POST['codfamilia'])) {
         $codfamilia = $_POST['codfamilia'];
     }
     $con_stock = isset($_POST['con_stock']);
     $this->results = $this->articulo->search($this->query, 0, $codfamilia, $con_stock);
     /// añadimos el descuento y la cantidad
     foreach ($this->results as $i => $value) {
         $this->results[$i]->dtopor = 0;
         $this->results[$i]->cantidad = 1;
     }
     /// ejecutamos las funciones de las extensiones
     foreach ($this->extensions as $ext) {
         if ($ext->type == 'function' and $ext->params == 'new_search') {
             $name = $ext->text;
             $name($this->db, $this->results);
         }
     }
     $cliente = $this->cliente->get($_POST['codcliente']);
     if ($cliente) {
         if ($cliente->regimeniva == 'Exento') {
             foreach ($this->results as $i => $value) {
                 $this->results[$i]->iva = 0;
             }
         }
         if ($cliente->codgrupo) {
             $grupo0 = new grupo_clientes();
             $tarifa0 = new tarifa();
             $grupo = $grupo0->get($cliente->codgrupo);
             if ($grupo) {
                 $tarifa = $tarifa0->get($grupo->codtarifa);
                 if ($tarifa) {
                     $tarifa->set_precios($this->results);
                 }
             }
         }
     }
 }
 protected function process()
 {
     $this->show_fs_toolbar = FALSE;
     $this->cliente = new cliente();
     $this->clientes_grupo = FALSE;
     $this->grupo = new grupo_clientes();
     $this->pais = new pais();
     $this->serie = new serie();
     $this->tarifa = new tarifa();
     if (isset($_GET['delete_grupo'])) {
         $grupo = $this->grupo->get($_GET['delete_grupo']);
         if ($grupo) {
             if ($grupo->delete()) {
                 $this->new_message('Grupo eliminado correctamente.');
             } else {
                 $this->new_error_msg('Imposible eliminar el grupo.');
             }
         } else {
             $this->new_error_msg('Grupo no encontrado.');
         }
     } else {
         if (isset($_POST['codgrupo'])) {
             $grupo = $this->grupo->get($_POST['codgrupo']);
             if (!$grupo) {
                 $grupo = new grupo_clientes();
                 $grupo->codgrupo = $_POST['codgrupo'];
             }
             $grupo->nombre = $_POST['nombre'];
             if ($_POST['codtarifa'] == '---') {
                 $grupo->codtarifa = NULL;
             } else {
                 $grupo->codtarifa = $_POST['codtarifa'];
             }
             if ($grupo->save()) {
                 $this->new_message('Grupo guardado correctamente.');
             } else {
                 $this->new_error_msg('Imposible guardar el grupo.');
             }
         } else {
             if (isset($_GET['delete'])) {
                 $cliente = $this->cliente->get($_GET['delete']);
                 if ($cliente) {
                     if (FS_DEMO) {
                         $this->new_error_msg('En el modo demo no se pueden eliminar clientes. Otros usuarios podrían necesitarlos.');
                     } else {
                         if ($cliente->delete()) {
                             $this->new_message('Cliente eliminado correctamente.');
                         } else {
                             $this->new_error_msg('Ha sido imposible eliminar el cliente.');
                         }
                     }
                 } else {
                     $this->new_error_msg('Cliente no encontrado.');
                 }
             } else {
                 if (isset($_POST['cifnif'])) {
                     $this->save_codpais($_POST['pais']);
                     $this->save_codserie($_POST['codserie']);
                     $cliente = new cliente();
                     $cliente->codcliente = $cliente->get_new_codigo();
                     $cliente->nombre = $_POST['nombre'];
                     $cliente->nombrecomercial = $_POST['nombre'];
                     $cliente->cifnif = $_POST['cifnif'];
                     $cliente->codserie = $_POST['codserie'];
                     if ($cliente->save()) {
                         $dircliente = new direccion_cliente();
                         $dircliente->codcliente = $cliente->codcliente;
                         $dircliente->codpais = $_POST['pais'];
                         $dircliente->provincia = $_POST['provincia'];
                         $dircliente->ciudad = $_POST['ciudad'];
                         $dircliente->codpostal = $_POST['codpostal'];
                         $dircliente->direccion = $_POST['direccion'];
                         $dircliente->descripcion = 'Principal';
                         if ($dircliente->save()) {
                             header('location: ' . $cliente->url());
                         } else {
                             $this->new_error_msg("¡Imposible guardar la dirección del cliente!");
                         }
                     } else {
                         $this->new_error_msg("¡Imposible guardar los datos del cliente!");
                     }
                 }
             }
         }
     }
     $this->offset = 0;
     if (isset($_GET['offset'])) {
         $this->offset = intval($_GET['offset']);
     }
     if ($this->query != '') {
         $this->resultados = $this->cliente->search($this->query, $this->offset);
     } else {
         $this->resultados = $this->cliente->all($this->offset);
     }
     $this->grupos = $this->grupo->all();
     if (isset($_GET['grupo'])) {
         $this->clientes_grupo = $this->clientes_from_grupo($_GET['grupo']);
     }
 }