Skip to content
This repository has been archived by the owner on Aug 9, 2024. It is now read-only.

Commit

Permalink
Escribir Reporte 2
Browse files Browse the repository at this point in the history
  • Loading branch information
Laifsyn committed Jun 18, 2024
1 parent 9b6e84d commit ef0434a
Show file tree
Hide file tree
Showing 3 changed files with 109 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import java.text.NumberFormat;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoUnit;
import java.util.Arrays;

import com.utp.clsHerramientas.pry6_trabajo_final.Datos;
Expand Down Expand Up @@ -34,6 +35,9 @@ public String monto_as_string() {
format.setMinimumFractionDigits(2);
return format.format(monto);
}
public long antiguedad(){
return ChronoUnit.DAYS.between(LocalDate.now(), fecha);
}

public static void main(String[] args) {
Factura[] facturas = cargar_facturas();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,122 @@
import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Locale;

public final class Reporte1 {
public final class Reporte {
public static final DateTimeFormatter FORMATTER = DateTimeFormatter
.ofPattern("EEEE dd 'de' MMMM 'de' yyyy HH:mm:ss a, zzzz",
new Locale.Builder().setLanguage("es").setRegion("PA").build());
final Cliente cliente;
final Factura[] facturas;
public final JButton ok = new JButton("OK");
static public final int[] dias = { 10000, 120, 90, 60, 30, 0 };

public Reporte1(Cliente cliente, Factura[] facturas) {
public Reporte(Cliente cliente, Factura[] facturas) {
this.cliente = cliente;
this.facturas = Querier.selectFacturas(cliente, facturas);
}

public JPanel as_panel() {
public JPanel as_reporte_1() {

JPanel final_panel = new JPanel(new GridBagLayout());
Table tabla = new Table(facturas, cliente);

var gbc = new GridBagConstraints();
gbc.gridx = 0;
gbc.gridy = 0;

final_panel.add(this.encabezado(), gbc);
gbc.gridy = 1;
final_panel.add(this.empty_panel(), gbc);
gbc.gridy = 2;
final_panel.add(tabla.as_panel(), gbc);
gbc.gridy = 3;
final_panel.add(this.empty_panel(), gbc);
gbc.gridy = 4;
final_panel.add(ok, gbc);

return final_panel;
}

public JPanel as_reporte_2() {

JPanel final_panel = new JPanel(new GridBagLayout());

var gbc = new GridBagConstraints();
gbc.gridx = 0;
gbc.gridy = 0;

final_panel.add(this.encabezado(), gbc);
gbc.gridy = 1;
// RESUMEN FINAL DE CUENTAS POR COBRAR/CLIENTES
final_panel.add(this.empty_panel(), gbc);
gbc.gridy = 2;
final_panel.add(into_label("RESUMEN FINAL DE CUENTAS POR COBRAR/CLIENTES"), gbc);
gbc.gridy = 3;
final_panel.add(this.empty_panel());
gbc.gridy = 4;

JPanel resumen = new JPanel(new GridBagLayout());
JLabel[] labels = { into_label("MES CORRIENTE: "),
into_label("30 DIAS: "),
into_label("60 DIAS: "),
into_label("90 DIAS: "),
into_label("+120 DIAS: ") };
var resumen_gbc = new GridBagConstraints();
for (int i = 1; i < labels.length + 1; i++) {
resumen_gbc.gridx = 0;
resumen_gbc.gridy = i - 1;
resumen.add(labels[i - 1], resumen_gbc);
resumen_gbc.gridx = 1;
// some offset due to dias[] layout
BigDecimal summary = summary(labels.length - i + 1);
JLabel monto;
if (summary.equals(BigDecimal.ZERO)) {
monto = into_label("0.00");
} else {
monto = into_label(summary.toString());
}
if (i == 1) {
monto.setForeground(UI.DarkCyan);

}
resumen_gbc.anchor = GridBagConstraints.EAST;
resumen.add(monto, resumen_gbc);
}
final_panel.add(resumen, gbc);
gbc.gridy = 5;
final_panel.add(this.empty_panel(), gbc);
gbc.gridy = 6;

// Table tabla = new Table(facturas, cliente);
// final_panel.add(tabla.as_panel(), gbc);
// gbc.gridy = 7;
final_panel.add(ok, gbc);
return final_panel;
}

public BigDecimal summary(int idx_dia) {
BigDecimal resumen = BigDecimal.ZERO;
for (int i = 0; i < facturas.length; i++) {
long antiguedad = -facturas[i].antiguedad();
if (antiguedad >= dias[idx_dia] && antiguedad < dias[idx_dia - 1]) {
resumen = resumen.add(facturas[i].monto());
}
// System.out.printf("%d)Antiguedad: %d, monto: %s (%s)\n", idx_dia, antiguedad, facturas[i].monto(),
// (antiguedad >= dias[idx_dia] && antiguedad < dias[idx_dia - 1]));
}
resumen.setScale(2, RoundingMode.HALF_EVEN);
return resumen;
}

public JPanel encabezado() {

JPanel panel = new JPanel(new GridBagLayout());
var gbc = new GridBagConstraints();
gbc.gridx = 0;
Expand Down Expand Up @@ -73,21 +171,7 @@ public JPanel as_panel() {
gbc.gridx = 2;
panel.add(into_label(" Nombre: " + cliente.nombre_completo()), gbc);

Table tabla = new Table(facturas, cliente);
gbc.gridwidth = 2;
gbc.gridy = 10;
gbc.gridx = 0;
gbc.gridwidth = 4;
gbc.fill = GridBagConstraints.BOTH;
panel.add(this.empty_panel(), gbc);
gbc.gridy = 11;
panel.add(tabla.as_panel(), gbc);
JPanel final_panel = new JPanel();
final_panel.setLayout(new BoxLayout(final_panel, BoxLayout.Y_AXIS));
final_panel.add(panel);
final_panel.add(this.empty_panel());
final_panel.add(ok);
return final_panel;
return panel;
}

public void add_ok_action(Runnable action) {
Expand Down Expand Up @@ -117,11 +201,11 @@ JPanel empty_panel() {
public static void main(String[] args) {
Cliente[] cliente = Cliente.cargar_clientes();
Factura[] facturas = Factura.cargar_facturas();
Reporte1 reporte = new Reporte1(cliente[3], facturas);
Reporte reporte = new Reporte(cliente[4], facturas);
reporte.add_ok_action(() -> {
System.out.println("OK! Exiting....");
System.exit(0);
});
UI.show(reporte.as_panel());
UI.show(reporte.as_reporte_2());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ public static void show(JPanel panel) {
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.add(panel);
frame.pack();
frame.setVisible(true);
frame.pack();

}
}

0 comments on commit ef0434a

Please sign in to comment.