Skip to content

Commit daa9616

Browse files
committed
terminado finanzas y clientes datos
1 parent dee3bbd commit daa9616

10 files changed

+349
-99
lines changed
4.23 KB
Binary file not shown.

Factura 1 pepa2 en 30-12-2024.xlsx

4.27 KB
Binary file not shown.
4.24 KB
Binary file not shown.

src/electricity_bills_system/ClientSearch.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ public void actionPerformed(ActionEvent ae) {
345345
} else if(ae.getSource() == imprimir){
346346
try{
347347
Workbook workbook = new XSSFWorkbook();
348-
Sheet sheet = workbook.createSheet("Clientes; "+NAMEa.size()+"de ");
348+
Sheet sheet = workbook.createSheet("Clientes; "+NAMEa.size());
349349
int rowIndex = 0;
350350

351351
Row clientesHeadarRow = sheet.createRow(rowIndex++);

src/electricity_bills_system/ClientUpdate.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -381,12 +381,10 @@ public void actionPerformed(ActionEvent ae){
381381
String rs2=rs.getString("PHONE");
382382
String rs3=rs.getString("EMAIL");
383383
if(rs2.equals(phone)){
384-
condicion=1;
385-
tf=1;
384+
386385
}
387386
if(rs3.equals(mail)){
388-
condicion=1;
389-
ml=1;
387+
390388
}
391389
}
392390
rs.close();
@@ -447,7 +445,7 @@ public void actionPerformed(ActionEvent ae){
447445
if (opcion == JOptionPane.YES_OPTION) {
448446
try {
449447
Connect c= new Connect();
450-
String query ="UPDATE CLIENT SET NAME='"+name+"',ADDRESS='"+address+"',CITY='"+city+"', POSTAL='"+postal+"', EMAIL='"+mail+"', PHONE='"+phone+"'";
448+
String query ="UPDATE CLIENT SET NAME='"+name+"',ADDRESS='"+address+"',CITY='"+city+"', POSTAL='"+postal+"', EMAIL='"+mail+"', PHONE='"+phone+"' where id='"+ID+"'";
451449
c.s.executeUpdate(query);
452450
JOptionPane.showMessageDialog(null,"Cliente Modificado Correctamente");
453451
setVisible(false);

src/electricity_bills_system/Finance.java

Lines changed: 74 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
import java.awt.*;
44
import java.awt.event.*;
5+
import java.sql.*;
6+
import java.text.SimpleDateFormat;
7+
import java.util.Date;
58
import javax.swing.*;
69
import javax.swing.border.TitledBorder;
710
import org.jfree.chart.ChartFactory;
@@ -20,12 +23,47 @@ public class Finance extends JFrame implements ActionListener {
2023
JFrame financeFrame;
2124
RoundedButton updateButton;
2225
String NIF,ID_USER;
26+
String beneficios,horas,factura_pendiente,factura_pagada,gastos;
27+
SimpleDateFormat dateFormat;
2328

2429
Finance(String NIF, String ID_USER) {
30+
dateFormat = new SimpleDateFormat("MM-yyyy");
31+
Date fechaActual = new Date();
32+
String fecha = dateFormat.format(fechaActual);
33+
34+
try{
35+
Connect c= new Connect();
36+
String query="SELECT COALESCE(SUM(HOUR),0) AS HORAS,COALESCE(ROUND(SUM(TOTAL_BILL),2),0) AS BENEFICIOS FROM bill_standard WHERE NIF='"+NIF+"' AND DATE LIKE '%-"+fecha+"'";
37+
ResultSet rs1 = c.s.executeQuery(query);
38+
while(rs1.next()){
39+
beneficios = rs1.getString("BENEFICIOS");
40+
horas = rs1.getString("HORAS");
41+
horas=horas.substring(0, horas.indexOf("."));
42+
}
43+
String query4="SELECT COALESCE(COUNT(STATUS),0) AS PENDIENTE FROM bill_standard WHERE NIF='"+NIF+"' AND DATE LIKE '%-"+fecha+"' AND (STATUS LIKE 'sin enviar' OR STATUS LIKE 'pendiente%')";
44+
ResultSet rs4 = c.s.executeQuery(query4);
45+
while(rs4.next()){
46+
factura_pendiente= rs4.getString("PENDIENTE");
47+
}
48+
49+
String query2="SELECT COALESCE(COUNT(STATUS),0) AS PAGADA FROM bill_standard WHERE NIF='"+NIF+"' AND DATE LIKE '%-"+fecha+"' AND STATUS LIKE 'pagado'";
50+
ResultSet rs2 = c.s.executeQuery(query2);
51+
while(rs2.next()){
52+
factura_pagada= rs2.getString("PAGADA");
53+
}
54+
String query3="SELECT COALESCE(SUM(TOTAL_PRICE),0) AS GASTOS FROM material_bill WHERE NIF='"+NIF+"' AND DATE LIKE '%-"+fecha+"'";
55+
ResultSet rs3 = c.s.executeQuery(query3);
56+
while(rs3.next()){
57+
gastos= rs3.getString("GASTOS");
58+
}
59+
60+
}catch (Exception e){
61+
e.printStackTrace();
62+
}
63+
2564
this.NIF=NIF;
2665
this.ID_USER=ID_USER;
2766
financeFrame = new JFrame("Finanzas - Resumen del Mes");
28-
financeFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
2967

3068
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
3169
int screenWidth = screenSize.width;
@@ -41,11 +79,11 @@ public class Finance extends JFrame implements ActionListener {
4179
JPanel mainPanel = new JPanel();
4280
mainPanel.setLayout(new BorderLayout());
4381
financeFrame.add(mainPanel);
44-
JPanel dataPanel = new JPanel(new GridLayout(6, 4, 10, 4));
82+
JPanel dataPanel = new JPanel(new GridLayout(7, 4, 10, 4));
4583

4684

4785

48-
TitledBorder titledBorder = BorderFactory.createTitledBorder("Datos del Mes");
86+
TitledBorder titledBorder = BorderFactory.createTitledBorder("Finanzas del Mes");
4987
titledBorder.setTitleJustification(TitledBorder.CENTER);
5088
titledBorder.setTitleFont(new Font("Roboto", Font.BOLD, 20));
5189
titledBorder.setBorder(BorderFactory.createEmptyBorder());
@@ -57,32 +95,41 @@ public class Finance extends JFrame implements ActionListener {
5795
dataPanel.add(benefitsLabel);
5896

5997
dataPanel.add(new JLabel("Beneficios Totales:", SwingConstants.RIGHT));
60-
benefitsLabel = new JLabel("1,200 €", SwingConstants.LEFT);
98+
benefitsLabel = new JLabel(beneficios+" €", SwingConstants.LEFT);
6199
dataPanel.add(benefitsLabel);
62100

63101
dataPanel.add(new JLabel("Gastos Totales:", SwingConstants.RIGHT));
64-
expensesLabel = new JLabel("800 €", SwingConstants.LEFT);
102+
expensesLabel = new JLabel(gastos+" €", SwingConstants.LEFT);
65103
dataPanel.add(expensesLabel);
104+
105+
dataPanel.add(new JLabel("Horas realizadas:", SwingConstants.RIGHT));
106+
pendingInvoicesLabel = new JLabel(horas+" h", SwingConstants.LEFT);
107+
dataPanel.add(pendingInvoicesLabel);
66108

67109
dataPanel.add(new JLabel("Facturas Procesadas:", SwingConstants.RIGHT));
68-
processedInvoicesLabel = new JLabel("15", SwingConstants.LEFT);
110+
processedInvoicesLabel = new JLabel(factura_pagada, SwingConstants.LEFT);
69111
dataPanel.add(processedInvoicesLabel);
70112

71113
dataPanel.add(new JLabel("Facturas Pendientes:", SwingConstants.RIGHT));
72-
pendingInvoicesLabel = new JLabel("3", SwingConstants.LEFT);
114+
pendingInvoicesLabel = new JLabel(factura_pendiente, SwingConstants.LEFT);
73115
dataPanel.add(pendingInvoicesLabel);
74116

117+
75118
dataPanel.add(new JLabel("", SwingConstants.RIGHT));
76119
benefitsLabel = new JLabel("", SwingConstants.LEFT);
77120
dataPanel.add(benefitsLabel);
78-
79-
121+
122+
double beneficios_int=Double.parseDouble(beneficios);
123+
double gastos_int=Double.parseDouble(gastos);
124+
int horas_int=Integer.parseInt(horas);
125+
int facturas_pendientes_int=Integer.parseInt(factura_pendiente);
126+
int facturas_pagadas_int=Integer.parseInt(factura_pagada);
127+
80128
mainPanel.add(dataPanel, BorderLayout.NORTH);
81129

82130
DefaultPieDataset pieDataset = new DefaultPieDataset();
83-
pieDataset.setValue("Beneficios", 120);
84-
pieDataset.setValue("Gastos", 800);
85-
pieDataset.setValue("Facturas Pendientes", 1000);
131+
pieDataset.setValue("Facturas Finalizadas", facturas_pagadas_int);
132+
pieDataset.setValue("Facturas Pendientes", facturas_pendientes_int);
86133

87134
JFreeChart pieChart = ChartFactory.createPieChart(
88135
"Distribución Financiera del Mes",
@@ -99,11 +146,10 @@ public class Finance extends JFrame implements ActionListener {
99146
piePlot.setBackgroundPaint(new Color(0, 0, 0, 0));
100147
piePlot.setOutlinePaint(null);
101148

102-
piePlot.setSectionPaint("Beneficios", new Color(255, 87, 34,98));
103-
piePlot.setSectionPaint("Gastos", new Color(156, 39, 176,98));
104-
piePlot.setSectionPaint("Facturas Pendientes", new Color(3, 169, 244,98));
149+
piePlot.setSectionPaint("Facturas Finalizadas", new Color(255, 87, 34,98));
150+
piePlot.setSectionPaint("Facturas Pendientes", new Color(156, 39, 176,98));
105151

106-
piePlot.setLabelFont(fuente2);
152+
piePlot.setLabelFont(fuente3);
107153
piePlot.setLabelPaint(new Color(200, 200, 200));
108154
piePlot.setLabelBackgroundPaint(new Color(70, 73, 75,0));
109155
piePlot.setShadowPaint(new Color(70, 73, 75));
@@ -122,8 +168,8 @@ public void paintComponent(Graphics g) {
122168

123169

124170
DefaultCategoryDataset barDataset = new DefaultCategoryDataset();
125-
barDataset.addValue(1200, "Beneficios", "Beneficios Gastos");
126-
barDataset.addValue(800, "Gastos", "Beneficios Gastos");
171+
barDataset.addValue(beneficios_int, "Beneficios", "Beneficios Gastos");
172+
barDataset.addValue(gastos_int, "Gastos", "Beneficios Gastos");
127173

128174
JFreeChart barChart = ChartFactory.createBarChart(
129175
"Comparación: Beneficios vs Gastos",
@@ -142,6 +188,10 @@ public void paintComponent(Graphics g) {
142188
barPlot.setRangeGridlinePaint(new Color(0, 0, 0, 0));
143189
barPlot.setOutlinePaint(null);
144190

191+
barPlot.getDomainAxis().setTickLabelPaint(Color.WHITE);
192+
barPlot.getRangeAxis().setTickLabelPaint(Color.WHITE);
193+
barChart.getTitle().setPaint(Color.WHITE);
194+
145195
BarRenderer renderer = (BarRenderer) barPlot.getRenderer();
146196
renderer.setSeriesPaint(0, new Color(156, 39, 176,95));
147197
renderer.setSeriesPaint(1, new Color(3, 169, 244,95));
@@ -171,12 +221,12 @@ public void paintComponent(Graphics g) {
171221

172222

173223
public void actionPerformed(ActionEvent ae) {
174-
// Simular actualización de datos
175-
benefitsLabel.setText("1,500 €");
176-
expensesLabel.setText("900 €");
177-
processedInvoicesLabel.setText("20");
178-
pendingInvoicesLabel.setText("2");
179-
JOptionPane.showMessageDialog(financeFrame, "Datos actualizados con éxito", "Actualizar", JOptionPane.INFORMATION_MESSAGE);
224+
225+
if(ae.getSource() == updateButton){
226+
financeFrame.setVisible(false);
227+
new Finance(NIF,ID_USER);
228+
}
229+
180230
}
181231

182232
public static void main(String[] args) {

0 commit comments

Comments
 (0)