private function new_search() { /// desactivamos la plantilla HTML $this->template = FALSE; $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]->cantidad = 1; /// añadimos el stock de cada almacén $this->results[$i]->origen = 0; if (isset($_REQUEST['origen'])) { $this->results[$i]->origen = $stock->total_from_articulo($this->results[$i]->referencia, $_REQUEST['origen']); } $this->results[$i]->destino = 0; if (isset($_REQUEST['destino'])) { $this->results[$i]->destino = $stock->total_from_articulo($this->results[$i]->referencia, $_REQUEST['destino']); } } 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]->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); } } } } } header('Content-Type: application/json'); echo json_encode($this->results); }
/** * Suma la cantidad especificada al stock del artículo en el almacén especificado. * @param type $almacen * @param type $cantidad * @param type $recalcula_coste * @return boolean */ public function sum_stock($almacen, $cantidad = 1, $recalcula_coste = FALSE) { if ($this->nostock) { return TRUE; } else { $result = FALSE; $stock = new stock(); $encontrado = FALSE; $stocks = $stock->all_from_articulo($this->referencia); foreach ($stocks as $k => $value) { if ($value->codalmacen == $almacen) { $stocks[$k]->sum_cantidad($cantidad); $result = $stocks[$k]->save(); $encontrado = TRUE; break; } } if (!$encontrado) { $stock->referencia = $this->referencia; $stock->codalmacen = $almacen; $stock->set_cantidad($cantidad); $result = $stock->save(); } if ($result) { $nuevo_stock = $stock->total_from_articulo($this->referencia); if ($this->stockfis != $nuevo_stock) { $this->stockfis = $nuevo_stock; if ($recalcula_coste) { $this->costemedio = $this->get_costemedio(); } if ($this->exists) { $this->clean_cache(); $result = $this->db->exec("UPDATE " . $this->table_name . " SET stockfis = " . $this->var2str($this->stockfis) . ",\n costemedio = " . $this->var2str($this->costemedio) . " WHERE referencia = " . $this->var2str($this->referencia) . ";"); } else { if (!$this->save()) { $this->new_error_msg("¡Error al actualizar el stock del artículo!"); } } } } else { $this->new_error_msg("¡Error al guardar el stock!"); } return $result; } }
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(); $this->results = $this->search_from_proveedor(); /// completamos los datos de la búsqueda foreach ($this->results as $i => $value) { $this->results[$i]->query = $this->query; $this->results[$i]->coste = $value->preciocoste(); $this->results[$i]->dtopor = 0; $this->results[$i]->cantidad = 1; $this->results[$i]->coddivisa = $this->empresa->coddivisa; /// si tenemos un codproveedor, ahí que buscar el coste para este proveedor if (isset($_REQUEST['codproveedor'])) { $ap = $this->articulo_prov->get_by($value->referencia, $_REQUEST['codproveedor']); if ($ap) { $this->results[$i]->coste = $ap->precio; $this->results[$i]->dtopor = $ap->dto; } } /// 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']); } /// convertimos la divisa if (isset($_REQUEST['coddivisa'])) { if ($_REQUEST['coddivisa'] != $this->empresa->coddivisa) { $this->results[$i]->coddivisa = $_REQUEST['coddivisa']; $this->results[$i]->coste = $this->divisa_convert($value->coste, $this->empresa->coddivisa, $_REQUEST['coddivisa']); $this->results[$i]->pvp = $this->divisa_convert($value->pvp, $this->empresa->coddivisa, $_REQUEST['coddivisa']); } } } /// 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); } } header('Content-Type: application/json'); echo json_encode($this->results); }