protected function private_core() { $almacen = new almacen(); $this->pais = new pais(); /// ¿El usuario tiene permiso para eliminar en esta página? $this->allow_delete = $this->user->allow_delete_on(__CLASS__); if (isset($_POST['scodalmacen'])) { $al0 = $almacen->get($_POST['scodalmacen']); if (!$al0) { $al0 = new almacen(); $al0->codalmacen = $_POST['scodalmacen']; } $al0->nombre = $_POST['snombre']; $al0->codpais = $_POST['scodpais']; $al0->provincia = $_POST['sprovincia']; $al0->poblacion = $_POST['spoblacion']; $al0->direccion = $_POST['sdireccion']; $al0->codpostal = $_POST['scodpostal']; $al0->telefono = $_POST['stelefono']; $al0->fax = $_POST['sfax']; $al0->contacto = $_POST['scontacto']; if ($al0->save()) { $this->new_message("Almacén " . $al0->codalmacen . " guardado correctamente."); } else { $this->new_error_msg("¡Imposible guardar el almacén!"); } } else { if (isset($_GET['delete'])) { $al0 = $almacen->get($_GET['delete']); if ($al0) { if (!$this->user->admin) { $this->new_error_msg("Solo un administrador puede eliminar un almacén."); } else { if ($al0->delete()) { $this->new_message("Almacén " . $al0->codalmacen . " eliminado correctamente"); } else { $this->new_error_msg("¡Imposible eliminar el almacén!"); } } } else { $this->new_error_msg("¡Almacén no encontrado!"); } } else { /// ¿Guardamos las opciones avanzadas? $guardar = FALSE; foreach ($GLOBALS['config2'] as $i => $value) { if (isset($_POST[$i])) { $GLOBALS['config2'][$i] = $_POST[$i]; $guardar = TRUE; } } if ($guardar) { $file = fopen('tmp/' . FS_TMP_NAME . 'config2.ini', 'w'); if ($file) { foreach ($GLOBALS['config2'] as $i => $value) { if (is_numeric($value)) { fwrite($file, $i . " = " . $value . ";\n"); } else { fwrite($file, $i . " = '" . $value . "';\n"); } } fclose($file); } $this->new_message('Datos guardados correctamente.'); } } } $this->almacenes = $almacen->all(); /// si hay más de un almacén activamos el soporte multi-almacén en los listados $fsvar = new fs_var(); if (count($this->almacenes) > 1) { $fsvar->simple_save('multi_almacen', TRUE); } else { $fsvar->simple_delete('multi_almacen'); } }
public function stats_almacenes($tabla = 'facturasprov') { $stats = array(); $al0 = new almacen(); $sql = "select codalmacen,sum(totaleuros) as total from " . $tabla . " group by codalmacen order by total desc;"; $data = $this->db->select($sql); if ($data) { foreach ($data as $d) { $alma = $al0->get($d['codalmacen']); if ($alma) { $stats[] = array('txt' => $alma->nombre, 'total' => round(abs($this->euro_convert(floatval($d['total']))), FS_NF0)); } else { $stats[] = array('txt' => $d['codalmacen'], 'total' => round(abs($this->euro_convert(floatval($d['total']))), FS_NF0)); } } } return $stats; }
/** * esta función se ejecuta si el usuario ha hecho login, * a efectos prácticos, este es el constructor */ protected function process() { /// ¿El usuario tiene permiso para eliminar en esta página? $this->allow_delete = $this->user->allow_delete_on(__CLASS__); //Cargo el modelo de la caja y la selecciono $this->caja_model = new cajas_general(); //Cargo el modelo de los movimientos $this->cajamov_model = new cajas_general_mov(); //Conseguimos el agente $this->agente = $this->user->get_agente(); if ($_GET['id'] != '') { $this->cajaid = $_GET['id']; $caja = $this->caja_model->get($this->cajaid); if ($caja) { //Compruebo si la caja esta o no Abierta $this->cajaopen = $caja->abierta(); //Consultamos almacenes existentes $almacenes = new almacen(); $this->almacen = $almacenes->get($caja->codalmacen); /* ********** // MODAL APUNTE * ********** */ if (isset($_REQUEST['idapunte'])) { $this->apunte = $this->cajamov_model->get($_REQUEST['idapunte']); // VISUALIZAR MODAL APUNTE if (isset($_POST['ajax'])) { $this->template = 'ajax_apunte'; } /* ********** // MODAL EDITAR APUNTE * ********** */ if (isset($_POST['importe'])) { if ($this->apunte->concepto == 'Apertura de Caja') { $this->resultados = $this->cajamov_model->get_all($this->cajaid); $this->new_error_msg('OJO! Apunte inicial: NO EDITABLE...'); return; } $this->apunte->concepto = $_POST['concepto']; $this->apunte->apunte = floatval($_POST['importe']); $this->apunte->caja_id = $this->cajaid; $this->apunte->codagente = $this->agente->codagente; if ($this->apunte->save()) { $this->new_message('Apunte EDITADO correctamente.'); $this->new_log_msg('Apunte Nº ' . $_REQUEST['idapunte'] . ' de la CAJA Nº ' . $this->cajaid . ' EDITADO correctamente.'); } else { $this->new_error_msg('Imposible EDITAR apunte Nº ' . $_REQUEST['idapunte']); } } } else { if (isset($_GET['delete'])) { /* ********** // ELIMINAMOS APUNTE * ********** */ $apunte = $this->cajamov_model->get($_GET['delete']); if ($apunte) { if ($apunte->concepto == 'Apertura de Caja') { $this->resultados = $this->cajamov_model->get_all($this->cajaid); $this->new_error_msg('OJO! Apunte incicial: NO se puede eliminar'); return; } if ($apunte->delete()) { $this->new_message('Apunte ' . $_GET['delete'] . ' eliminado correctamente.'); $this->new_log_msg('Apunte Nº ' . $_GET['delete'] . ' de la CAJA Nº ' . $this->cajaid . ' eliminado correctamente.'); } else { $this->new_error_msg('Error al eliminar el apunte ' . $_GET['delete']); } } else { $this->new_error_msg('Apunte ' . $_GET['delete'] . ' no encontrado.'); } } else { if (isset($_POST['ingreso']) and $_POST['ingreso'] > 0) { /* ********** // CREAMOS APUNTE INGRESO POSITIVO * ********** */ $this->cajamov_model->concepto = $_POST['nota']; $this->cajamov_model->apunte = floatval($_POST['ingreso']); $this->cajamov_model->caja_id = $this->cajaid; $this->cajamov_model->codagente = $this->agente->codagente; if ($this->cajamov_model->save()) { $this->new_message('Ingreso apuntado correctamente.'); } else { $this->new_error_msg('Imposible guardar el ingreso.'); } } else { if (isset($_POST['pago']) and $_POST['pago'] > 0) { /* ********** // CREAMOS APUNTE PAGO CONVERTIMOS A NEGATIVO * ********** */ $this->cajamov_model->concepto = $_POST['nota']; $apunte = floatval($_POST['pago']); $this->cajamov_model->apunte = $apunte *= -1; $this->cajamov_model->caja_id = $this->cajaid; $this->cajamov_model->codagente = $this->agente->codagente; if ($this->cajamov_model->save()) { $this->new_message('Pago apuntado correctamente.'); } else { $this->new_error_msg('Imposible guardar el pago.'); } } } } } $this->tipo = FALSE; if (isset($_REQUEST['tipo'])) { if ($_REQUEST['tipo'] == 'ingresos') { $this->tipo = 'ingresos'; $this->resultados = $this->cajamov_model->ingresos($this->cajaid); } else { if ($_REQUEST['tipo'] == 'pagos') { $this->tipo = 'pagos'; $this->resultados = $this->cajamov_model->pagos($this->cajaid); } } } else { $this->resultados = $this->cajamov_model->get_all($this->cajaid); } } else { $this->new_error_msg('Caja no existe, ha sido eliminada anteriormente !', 'cajamov'); } } else { $this->new_error_msg('Caja NO seleccionada correctamente!', 'cajamov'); } }
public function nombre() { $al0 = new \almacen(); $almacen = $al0->get($this->codalmacen); if ($almacen) { $this->nombre = $almacen->nombre; } return $this->nombre; }
public function nombre_almacen() { $almacen = new almacen(); return $almacen->get($this->codalmacen); }