186 lines
4.4 KiB
Java
186 lines
4.4 KiB
Java
package Logica;
|
|
import java.io.Serializable;
|
|
import java.time.LocalDate;
|
|
import java.util.Vector;
|
|
|
|
public class Gestion implements Serializable{
|
|
private Vector<Transaccion> gestiones;
|
|
private float suma;
|
|
private float total;
|
|
private boolean isPositivo;
|
|
private String nombre;
|
|
private boolean isModified;
|
|
|
|
/**
|
|
* Constructor principal de gestion
|
|
*
|
|
* @param nombre nombre de la gestion
|
|
* @param isPositivo si es verdadero la gestion sera de beneficios, si es falsa sera de gastos
|
|
*/
|
|
public Gestion(String nombre, boolean isPositivo) {
|
|
this.gestiones = new Vector<Transaccion>();
|
|
this.suma = 0;
|
|
this.total = 0;
|
|
this.nombre = nombre;
|
|
this.isPositivo = isPositivo;
|
|
this.isModified = false;
|
|
}
|
|
|
|
/**
|
|
* Devuelve el nombre de la gestion
|
|
*
|
|
* @return nombre de la gestion
|
|
*/
|
|
public String getNombre() {
|
|
return this.nombre;
|
|
}
|
|
|
|
/**
|
|
* Establece un nuevo nombre a la gestion
|
|
*
|
|
* @param nombre nuevo nombre
|
|
*/
|
|
public void setNombre(String nombre) {
|
|
this.nombre = nombre;
|
|
this.isModified = true;
|
|
}
|
|
|
|
/**
|
|
* Aniade una transaccion a la gestion
|
|
*
|
|
* @param transaccion transaccion que sera aniadida a la gestion
|
|
*/
|
|
public void aniadirGasto(Transaccion transaccion) {
|
|
this.gestiones.add(transaccion);
|
|
this.suma += transaccion.getDinero();
|
|
if(this.isPositivo) {
|
|
this.total += transaccion.getDinero();
|
|
}else {
|
|
this.total -= transaccion.getDinero();
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Devuelve la suma (sin tener e cuenta si es gasto o ingreso) de la gestion
|
|
*
|
|
* @return suma de las transacciones de la gestion
|
|
*/
|
|
public float getSuma() {
|
|
return this.suma;
|
|
}
|
|
|
|
/**
|
|
* Devuelve la suma de todos sus datos, esta vez teniendo en cuenta si debe sumar o restar
|
|
*
|
|
* @return suma correcta de los datos
|
|
*/
|
|
public float getTotal() {
|
|
return this.total;
|
|
}
|
|
|
|
/**
|
|
* Devuelve todas las transacciones que tiene
|
|
*
|
|
* @return Transacciones que contiene
|
|
*/
|
|
public Vector<Transaccion> getElementos(){
|
|
return this.gestiones;
|
|
}
|
|
|
|
/**
|
|
* Elimina una transaccion
|
|
*
|
|
* @param transaccion transaccion a eliminar
|
|
*/
|
|
public void eliminarTransaccion(String transaccion) {
|
|
for(Transaccion elemento:this.gestiones) {
|
|
if(elemento.toString().equals(transaccion)) {
|
|
this.gestiones.remove(elemento);
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Permite editar una transaccion por nombre para cambiarselo
|
|
*
|
|
* @param nombreViejo nombre de la transaccion a cambiar
|
|
* @param nombreNuevo nuevo nombre
|
|
*/
|
|
public void editarTransaccion(String nombreViejo, String nombreNuevo) {
|
|
for(Transaccion elemento:this.gestiones) {
|
|
if(elemento.getNombre().equals(nombreViejo)) {
|
|
elemento.setName(nombreNuevo);
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Edita la fecha de una transaccion dada su fecha
|
|
*
|
|
* @param nombreViejo nombre de la trasnaccion a editar
|
|
* @param fecha nueva fecha
|
|
*/
|
|
public void editarTransaccionFecha(String nombreViejo, LocalDate fecha) {
|
|
for(Transaccion elemento:this.gestiones) {
|
|
if(elemento.getNombre().equals(nombreViejo)) {
|
|
elemento.setFecha(fecha);
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Edita la transaccion con el nombre indicado alterando el dinero que cuesta
|
|
*
|
|
* @param nombreViejo nombre de la transaccion a editar
|
|
* @param dinero nueva cantidad de dinero;
|
|
*/
|
|
public void editarTransaccionDiero(String nombreViejo, float dinero) {
|
|
for(Transaccion elemento:this.gestiones) {
|
|
if(elemento.getNombre().equals(nombreViejo)) {
|
|
elemento.setPrecio(dinero);
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Devuelve verdadero si es un ingerso y falso si es un gasto
|
|
*
|
|
* @return verdadero si es ingersos y falso si sin gastos
|
|
*/
|
|
public boolean esIngreso() {
|
|
return this.isPositivo;
|
|
}
|
|
|
|
/**
|
|
* Permite alterar la visibilidad de un elemento
|
|
*
|
|
* @param elemento indice del elemento a alterar
|
|
*/
|
|
public void alterarVisibilidad(int elemento) {
|
|
if(this.gestiones.get(elemento).alterarVisivilidad()) {
|
|
this.suma += this.gestiones.get(elemento).getDinero();
|
|
if(this.isPositivo) {
|
|
this.total += this.gestiones.get(elemento).getDinero();
|
|
}else {
|
|
this.total -= this.gestiones.get(elemento).getDinero();
|
|
}
|
|
}else {
|
|
this.suma -= this.gestiones.get(elemento).getDinero();
|
|
if(this.isPositivo) {
|
|
this.total -= this.gestiones.get(elemento).getDinero();
|
|
}else {
|
|
this.total += this.gestiones.get(elemento).getDinero();
|
|
}
|
|
}
|
|
}
|
|
|
|
public String toString() {
|
|
return this.nombre + " " + this.suma + " Gastos:" + this.isPositivo + " Modificado:"+ this.isModified;
|
|
}
|
|
|
|
}
|