-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCliente.java
More file actions
188 lines (170 loc) · 7.68 KB
/
Copy pathCliente.java
File metadata and controls
188 lines (170 loc) · 7.68 KB
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package ModelClass;
import Connection.Consult;
import Models.*;
import java.util.List;
import java.util.stream.Collectors;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;
/**
*
* @author AlexJPZ
*/
public class Cliente extends Consult {
//private Consult consult = new Consult();
private DefaultTableModel modelo, modelo2;
private List<Clientes> cliente, clienteFilter;
private int IdCliente;
private String Id;
private String sql;
private Object[] obect;
public Cliente (){
}
public boolean insertCliente(String ID, String Nombre, String Apellido,
String Direccion, String Telefono) {
boolean valor = false;
cliente = clientes();
clienteFilter = cliente.stream()
.filter(c -> c.getID().equals(ID))
.collect(Collectors.toList());
if (0 == clienteFilter.size()) {
sql = "INSERT INTO clientes(ID,Nombre,Apellido,Direccion,Telefono)"
+ "VALUES(?,?,?,?,?)";
obect = new Object[]{ID, Nombre, Apellido, Direccion, Telefono};
insert(sql, obect);
cliente = clientes();
cliente.forEach(item -> {
IdCliente = item.getIdCliente();
Id = item.getID();
});
sql = "INSERT INTO reportes_clientes(IdCliente,SaldoActual,FechaActual,"
+ "UltimoPago,FechaPago,ID)"
+ "VALUES(?,?,?,?,?,?)";
obect = new Object[]{IdCliente, "$0.00", "Sin fecha", "$0.00", "Sin fecha", Id};
insert(sql, obect);
valor = true;
}
return valor;
}
public List<Clientes> getClientes() {
return clientes();
}
public void searchCliente(JTable table, String campo, int num_registro, int reg_por_pagina) {
String[] registros = new String[6];
String[] titulos = {"Id", "ID", "Nombre", "Apellido", "Direccion", "Telefono"};
modelo = new DefaultTableModel(null, titulos);
cliente = clientes();
if (campo.equals("")) {
clienteFilter = cliente.stream()
.skip(num_registro).limit(reg_por_pagina)
.collect(Collectors.toList());
} else {
clienteFilter = cliente.stream()
.filter(C -> C.getID().startsWith(campo) || C.getNombre().startsWith(campo)
|| C.getApellido().startsWith(campo))
.skip(num_registro).limit(reg_por_pagina)
.collect(Collectors.toList());
}
clienteFilter.forEach(item -> {
registros[0] = String.valueOf(item.getIdCliente());
registros[1] = item.getID();
registros[2] = item.getNombre();
registros[3] = item.getApellido();
registros[4] = item.getDireccion();
registros[5] = item.getTelefono();
modelo.addRow(registros);
});
table.setModel(modelo);
table.setRowHeight(30);
table.getColumnModel().getColumn(0).setMaxWidth(0);
table.getColumnModel().getColumn(0).setMinWidth(0);
table.getColumnModel().getColumn(0).setPreferredWidth(0);
}
public DefaultTableModel getModelo() {
return modelo;
}
public DefaultTableModel reportesCliente(JTable table, int idCliente) {
String[] registros = new String[7];
String[] titulos = {"Id", "Nombre", "Apellido", "Saldo Actual", "Fecha Actual", "Ultimo Pago", "Fecha Pago"};
modelo2 = new DefaultTableModel(null, titulos);
List<Reportes_clientes> resportes = reportesClientes(idCliente,1);
resportes.forEach(item -> {
registros[0] = String.valueOf(item.getIdRegistro());
registros[1] = item.getNombre();
registros[2] = item.getApellido();
registros[3] = item.getSaldoActual();
registros[4] = item.getFechaActual();
registros[5] = item.getUltimoPago();
registros[6] = item.getFechaPago();
modelo2.addRow(registros);
});
table.setModel(modelo2);
table.setRowHeight(30);
table.getColumnModel().getColumn(0).setMaxWidth(0);
table.getColumnModel().getColumn(0).setMinWidth(0);
table.getColumnModel().getColumn(0).setPreferredWidth(0);
return modelo2;
}
public boolean updateCliente(String id, String nombre, String apellido,
String direccion, String telefono, int idCliente) {
boolean valor = false;
cliente = clientes();
clienteFilter = cliente.stream()
.filter(c -> c.getID().equals(id))
.collect(Collectors.toList());
int count = clienteFilter.size();
clienteFilter = cliente.stream()
.filter(c -> c.getIdCliente() == idCliente)
.collect(Collectors.toList());
if (0 == count || id.equals(clienteFilter.get(0).getID())) {
sql = "UPDATE clientes SET ID = ?,Nombre = ?,Apellido = ?,"
+ "Direccion = ?,Telefono = ? WHERE IdCliente =" + idCliente;
Object[] cliente = new Object[]{id, nombre, apellido, direccion, telefono};
update(sql, cliente);
List<Reportes_clientes> resportes = reportesClientes(idCliente,1);
int idRegistro = resportes.get(0).getIdRegistro();
int IdCliente = resportes.get(0).getIdCliente();
String SaldoActual = resportes.get(0).getSaldoActual();
String FechaActual = resportes.get(0).getFechaActual();
String UltimoPago = resportes.get(0).getUltimoPago();
String FechaPago = resportes.get(0).getFechaPago();
String ID = id;
sql = "UPDATE reportes_clientes SET IdCliente = ?,SaldoActual = ?,FechaActual = ?"
+ ",UltimoPago = ?,FechaPago = ? ,ID = ? WHERE IdRegistro =" + idRegistro;
Object[] reporte = new Object[]{IdCliente, SaldoActual, FechaActual, UltimoPago, FechaPago, ID};
update(sql, reporte);
valor = true;
}
return valor;
}
public void deleteCliente(int idCliente, int idRegistro) {
sql = "DELETE FROM reportes_clientes WHERE IdRegistro LIKE ?";
delete(sql, idRegistro);
sql = "DELETE FROM clientes WHERE IdCliente LIKE ?";
delete(sql, idCliente);
}
public void updateRepostes(String saldoActual, String fecha, String pago, int idCliente) {
List<Reportes_clientes> resportes = reportesClientes(idCliente,1);
int idRegistro = resportes.get(0).getIdRegistro();
// int IdCliente = resportes.get(0).getIdCliente();
String ID = resportes.get(0).getID();
double pago1 =formato.reconstruir(resportes.get(0).getUltimoPago().replace("$",""));
double pago2 = formato.reconstruir(pago);
pago1 += pago2;
// sql = "INSERT INTO reportes_clientes(IdCliente,SaldoActual,FechaActual,"
// + "UltimoPago,FechaPago,ID)"
// + "VALUES(?,?,?,?,?,?)";
// Object[] reporte = new Object[]{idCliente, "$" + saldoActual, fecha, "$" + pago, fecha, ID};
// insert(sql, reporte);
sql = "UPDATE reportes_clientes SET IdCliente = ?,SaldoActual = ?,FechaActual = ?"
+ ",UltimoPago = ?,FechaPago = ? ,ID = ? WHERE IdRegistro =" + idRegistro;
Object[] reporte = new Object[]{idCliente, "$" + saldoActual, fecha, "$" + formato.decimal(pago1), fecha, ID};
update(sql, reporte);
}
}