-
Notifications
You must be signed in to change notification settings - Fork 0
/
Presupuesto.java
87 lines (77 loc) · 3.02 KB
/
Presupuesto.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import java.util.ArrayList;
import java.util.HashMap;
public class Presupuesto {
private HashMap<Producto, Integer> productos;
private float precioTotal;
private float subtotal;
// private String Cliente;
public Presupuesto(HashMap<Producto, Integer> productos, String nombreCliente) {
this.productos = productos;
//this.nombreCliente = nombreCliente;
this.precioTotal = calcularPrecioTotal(BaseDeDatos.getMargenGanancia());
this.subtotal = calcularSubtotal();
}
public HashMap<Producto, Integer> getProductos() {
return productos;
}
public void setProductos(HashMap<Producto, Integer> productos) {
this.productos = productos;
this.precioTotal = calcularPrecioTotal(BaseDeDatos.getMargenGanancia());
this.subtotal = calcularSubtotal();
}
public float getPrecioTotal() {
return precioTotal;
}
public float getSubtotal() {
return subtotal;
}
/* public String getNombreCliente() {
return nombreCliente;
}
*/
/* public void setNombreCliente(String nombreCliente) {
this.nombreCliente = nombreCliente;
}
*/
public float calcularPrecioTotal(float margenGanancia) {
float precioTotal = 0.0f;
for (Producto producto : productos.keySet()) {
int cantidad = productos.get(producto);
float precioProducto = producto.calcularPrecioVenta(margenGanancia); // Llamada al método calcularPrecioVenta() con el margen de ganancia recibido
precioTotal += precioProducto * cantidad;
}
return precioTotal;
}
public float calcularSubtotal() {
float subtotal = 0.0f;
for (Producto producto : productos.keySet()) {
int cantidad = productos.get(producto);
float precioProducto = producto.calcularPrecioVenta();
subtotal += precioProducto * cantidad;
}
return subtotal;
}
public ArrayList<String> obtenerNombreProductos() {
ArrayList<String> nombresProductos = new ArrayList<>();
for (Producto producto : productos.keySet()) {
nombresProductos.add(producto.getNombre());
}
return nombresProductos;
}
public HashMap<Material, Float> calcularMaterialNecesario() {
HashMap<Material, Float> materialNecesario = new HashMap<>();
for (Producto producto : productos.keySet()) {
int cantidad = productos.get(producto);
HashMap<Material, Float> porcentajeMaterial = producto.getMaterialNecesario();
for (Material material : porcentajeMaterial.keySet()) {
float cantidadMaterial = porcentajeMaterial.get(material) * cantidad;
if (materialNecesario.containsKey(material)) {
float cantidadAnterior = materialNecesario.get(material);
cantidadMaterial += cantidadAnterior;
}
materialNecesario.put(material, cantidadMaterial);
}
}
return materialNecesario;
}
}