Reorgnizando la diferenciacion entre lo que suma y resta al total del
mes
This commit is contained in:
		
							parent
							
								
									0d7df06ad6
								
							
						
					
					
						commit
						21203e9524
					
				
										
											Binary file not shown.
										
									
								
							
										
											Binary file not shown.
										
									
								
							| @ -9,20 +9,15 @@ public class Gestion{ | ||||
| 	private static float total; | ||||
| 	private Month mes; | ||||
| 	private Year anio; | ||||
| 	//private boolean isPositivo; | ||||
| 	private boolean isPositivo; | ||||
| 	private String nombre; | ||||
| 	 | ||||
| 	public Gestion() { | ||||
| 		this.gestiones=new Vector<Transaccion>(); | ||||
| 		this.suma = 0; | ||||
| 		Gestion.total = 0; | ||||
| 	} | ||||
| 	 | ||||
| 	public Gestion(String nombre) { | ||||
| 	public Gestion(String nombre, boolean isPositivo) { | ||||
| 		this.gestiones = new Vector<Transaccion>(); | ||||
| 		this.suma = 0; | ||||
| 		Gestion.total = 0; | ||||
| 		this.nombre = nombre; | ||||
| 		this.isPositivo = isPositivo; | ||||
| 	} | ||||
| 	 | ||||
| 	public String getNombre() { | ||||
| @ -32,7 +27,7 @@ public class Gestion{ | ||||
| 	public void aniadirGasto(Transaccion transaccion) { | ||||
| 		this.gestiones.add(transaccion); | ||||
| 		this.suma += transaccion.getDinero(); | ||||
| 		if(transaccion.isPositivo()) { | ||||
| 		if(this.isPositivo) { | ||||
| 			Gestion.total += transaccion.getDinero(); | ||||
| 		}else { | ||||
| 			Gestion.total -= transaccion.getDinero(); | ||||
| @ -54,14 +49,14 @@ public class Gestion{ | ||||
| 	public void alterarVisibilidad(int elemento) { | ||||
| 		if(this.gestiones.get(elemento).alterarVisivilidad()) { | ||||
| 			this.suma += this.gestiones.get(elemento).getDinero(); | ||||
| 			if(this.gestiones.get(elemento).isPositivo()) { | ||||
| 			if(this.isPositivo) { | ||||
| 				Gestion.total += this.gestiones.get(elemento).getDinero(); | ||||
| 			}else { | ||||
| 				Gestion.total -= this.gestiones.get(elemento).getDinero(); | ||||
| 			} | ||||
| 		}else { | ||||
| 			this.suma -= this.gestiones.get(elemento).getDinero(); | ||||
| 			if(this.gestiones.get(elemento).isPositivo()) { | ||||
| 			if(this.isPositivo) { | ||||
| 				Gestion.total -= this.gestiones.get(elemento).getDinero(); | ||||
| 			}else { | ||||
| 				Gestion.total += this.gestiones.get(elemento).getDinero(); | ||||
|  | ||||
| @ -11,41 +11,41 @@ private ArrayList<Mes> meses; | ||||
| 		this.meses = new ArrayList<Mes>(); | ||||
| 	} | ||||
| 	 | ||||
| 	public Gestion aniadirGestion(String nombre, int anio, Month mes) { | ||||
| 	public Gestion aniadirGestion(String nombre, int anio, Month mes, boolean isPositivo) { | ||||
| 		Gestion ret; | ||||
| 		try { | ||||
| 			for(Mes mesSelect:this.meses) { | ||||
| 				if(mesSelect.getMes().equals(mes) && mesSelect.getAnio() == anio){ | ||||
| 					ret = new Gestion(nombre); | ||||
| 					ret = new Gestion(nombre, isPositivo); | ||||
| 					mesSelect.getGestiones().add(ret); | ||||
| 					return ret; | ||||
| 				} | ||||
| 			} | ||||
| 		}catch (NullPointerException e) { | ||||
| 			ArrayList<Gestion> gestiones=new ArrayList<Gestion>(); | ||||
| 			ret = new Gestion(nombre); | ||||
| 			ret = new Gestion(nombre, isPositivo); | ||||
| 			gestiones.add(ret); | ||||
| 			this.meses.add(new Mes(gestiones,anio,mes)); | ||||
| 			return ret; | ||||
| 		} | ||||
| 		ArrayList<Gestion> gestiones=new ArrayList<Gestion>(); | ||||
| 		ret = new Gestion(nombre); | ||||
| 		ret = new Gestion(nombre, isPositivo); | ||||
| 		gestiones.add(ret); | ||||
| 		this.meses.add(new Mes(gestiones,anio,mes)); | ||||
| 		return ret; | ||||
| 	} | ||||
| 	 | ||||
| 	public void aniadirTransaccion(Transaccion transaccion, String nombre) { | ||||
| 	public void aniadirTransaccion(Transaccion transaccion, String nombre, boolean isPositivo) { | ||||
| 		for(Mes mes:this.meses) { | ||||
| 			if(transaccion.getDia().getMonth().equals(mes.getMes()) && | ||||
| 					transaccion.getDia().getYear() == mes.getAnio()){ | ||||
| 				mes.aniadirTransaccion(transaccion, nombre); | ||||
| 				mes.aniadirTransaccion(transaccion, nombre, isPositivo); | ||||
| 				return; | ||||
| 			} | ||||
| 		} | ||||
| 		this.meses.add(new Mes(new ArrayList<Gestion>(),transaccion.getDia().getYear(), | ||||
| 				transaccion.getDia().getMonth())); | ||||
| 		this.meses.get(this.meses.size()-1).aniadirTransaccion(transaccion, nombre); | ||||
| 		this.meses.get(this.meses.size()-1).aniadirTransaccion(transaccion, nombre, isPositivo); | ||||
| 	} | ||||
| 	 | ||||
| 	public void elegirMes(int anio, Month mes) { | ||||
| @ -75,14 +75,14 @@ class Mes{ | ||||
| 		this.mes=mes; | ||||
| 	} | ||||
| 	 | ||||
| 	void aniadirTransaccion(Transaccion transaccion, String nombre) { | ||||
| 	void aniadirTransaccion(Transaccion transaccion, String nombre, boolean isPositivo) { | ||||
| 		for(Gestion gestion:this.gestiones) { | ||||
| 			if(gestion.getNombre().equals(nombre)) { | ||||
| 				gestion.aniadirGasto(transaccion); | ||||
| 				return; | ||||
| 			} | ||||
| 		} | ||||
| 		gestiones.add(new Gestion(nombre)); | ||||
| 		gestiones.add(new Gestion(nombre, isPositivo)); | ||||
| 		gestiones.get(this.gestiones.size()-1).aniadirGasto(transaccion); | ||||
| 		return; | ||||
| 	} | ||||
|  | ||||
| @ -7,21 +7,18 @@ public class Transaccion { | ||||
| 	private float dinero; | ||||
| 	private boolean visible; | ||||
| 	private LocalDate dia; | ||||
| 	private boolean positivo; | ||||
| 	 | ||||
| 	public Transaccion(String nombre, float dinero){ | ||||
| 		this.nombre = nombre; | ||||
| 		this.dinero = dinero; | ||||
| 		this.visible = true; | ||||
| 		this.dia = LocalDate.now(); | ||||
| 		this.positivo = true; | ||||
| 	} | ||||
| 	 | ||||
| 	public Transaccion(String nombre, float dinero, LocalDate dia, boolean positivo){ | ||||
| 	public Transaccion(String nombre, float dinero, LocalDate dia){ | ||||
| 		this.nombre = nombre; | ||||
| 		this.dinero = dinero; | ||||
| 		this.visible = true; | ||||
| 		this.positivo = positivo; | ||||
| 		this.dia = dia; | ||||
| 	} | ||||
| 	 | ||||
| @ -42,10 +39,6 @@ public class Transaccion { | ||||
| 		return this.dinero; | ||||
| 	} | ||||
| 	 | ||||
| 	public boolean isPositivo() { | ||||
| 		return this.positivo; | ||||
| 	} | ||||
| 	 | ||||
| 	public LocalDate getDia() { | ||||
| 		return this.dia; | ||||
| 	} | ||||
|  | ||||
| @ -60,11 +60,11 @@ public class Menu extends JFrame{ | ||||
| 	} | ||||
| 	 | ||||
| 	private void iniciarMes(int anio, Month mes) { | ||||
| 		meses.aniadirGestion("Ingresos", anio, mes); | ||||
| 		meses.aniadirGestion("Gastos", anio, mes); | ||||
| 		meses.aniadirGestion("Ingresos", anio, mes, true); | ||||
| 		meses.aniadirGestion("Gastos", anio, mes, false); | ||||
| 		this.pestanias=new ArrayList<VistaAniadirVisualizar>(); | ||||
| 		this.pestanias.add(new VistaAniadirVisualizar(this,meses.getGestionesActuales().get(0),true)); | ||||
| 		this.pestanias.add(new VistaAniadirVisualizar(this,meses.getGestionesActuales().get(1),false)); | ||||
| 		this.pestanias.add(new VistaAniadirVisualizar(this,meses.getGestionesActuales().get(0))); | ||||
| 		this.pestanias.add(new VistaAniadirVisualizar(this,meses.getGestionesActuales().get(1))); | ||||
| 		this.controladores=new ArrayList<ControladorAniadirVisualizar>(); | ||||
| 		this.controladores.add(new ControladorAniadirVisualizar(this.pestanias.get(0))); | ||||
| 		this.controladores.add(new ControladorAniadirVisualizar(this.pestanias.get(1))); | ||||
| @ -86,7 +86,7 @@ public class Menu extends JFrame{ | ||||
| 		this.pestanias=new ArrayList<VistaAniadirVisualizar>(); | ||||
| 		this.controladores=new ArrayList<ControladorAniadirVisualizar>(); | ||||
| 		for(Gestion gestion:this.meses.getGestionesActuales()) { | ||||
| 			VistaAniadirVisualizar vista = new VistaAniadirVisualizar(this, gestion, true); | ||||
| 			VistaAniadirVisualizar vista = new VistaAniadirVisualizar(this, gestion); | ||||
| 			this.pestania.add(vista); | ||||
| 			this.controladores.add(new ControladorAniadirVisualizar(vista)); | ||||
| 		} | ||||
| @ -100,8 +100,8 @@ public class Menu extends JFrame{ | ||||
| 	} | ||||
| 	 | ||||
| 	void aniadirGestion(String nombre, boolean sumaOResta) { | ||||
| 		Gestion gestion=this.meses.aniadirGestion(nombre, VistaPanelLateral.getDate().getYear(), VistaPanelLateral.getDate().getMonth()); | ||||
| 		VistaAniadirVisualizar vista = new VistaAniadirVisualizar(this, gestion, sumaOResta); | ||||
| 		Gestion gestion=this.meses.aniadirGestion(nombre, VistaPanelLateral.getDate().getYear(), VistaPanelLateral.getDate().getMonth(), sumaOResta); | ||||
| 		VistaAniadirVisualizar vista = new VistaAniadirVisualizar(this, gestion); | ||||
| 		this.pestanias.add(vista); | ||||
| 		this.controladores.add(new ControladorAniadirVisualizar(vista)); | ||||
| 		this.pestania.addTab(vista.getName(),vista); | ||||
|  | ||||
| @ -20,10 +20,8 @@ public class VistaAniadirVisualizar extends JPanel{ | ||||
| 	JPanel cuadro; | ||||
| 	JScrollPane panel; | ||||
| 	Menu menu; | ||||
| 	boolean positivo; | ||||
| 	static VistaPanelLateral panelLateral; | ||||
| 	public VistaAniadirVisualizar(Menu menu, Gestion gestion,boolean positivo) { | ||||
| 		this.positivo = positivo; | ||||
| 	public VistaAniadirVisualizar(Menu menu, Gestion gestion) { | ||||
| 		this.gestiones = gestion; | ||||
| 		this.transacciones = new LinkedList<JCheckBox>(); | ||||
| 		this.menu = menu; | ||||
| @ -49,7 +47,7 @@ public class VistaAniadirVisualizar extends JPanel{ | ||||
| 	} | ||||
| 	 | ||||
| 	public void aniadirElemento(String nombre, float dinero, ControladorAniadirVisualizar controlador) { | ||||
| 		Transaccion transaccion = new Transaccion(nombre, dinero,panelLateral.getDate(),this.positivo); | ||||
| 		Transaccion transaccion = new Transaccion(nombre, dinero,panelLateral.getDate()); | ||||
| 		this.gestiones.aniadirGasto(transaccion); | ||||
| 		JCheckBox check = new JCheckBox(transaccion.toString()); | ||||
| 		check.setSelected(true); | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user