170 |
ilm |
1 |
package org.openconcerto.modules.project.panel;
|
|
|
2 |
|
|
|
3 |
import java.awt.GridBagConstraints;
|
|
|
4 |
import java.awt.GridBagLayout;
|
|
|
5 |
import java.awt.Insets;
|
|
|
6 |
import java.math.BigDecimal;
|
|
|
7 |
import java.math.RoundingMode;
|
|
|
8 |
import java.text.DecimalFormat;
|
|
|
9 |
import java.util.Collection;
|
|
|
10 |
|
|
|
11 |
import javax.swing.JLabel;
|
|
|
12 |
import javax.swing.JPanel;
|
|
|
13 |
import javax.swing.SwingConstants;
|
|
|
14 |
import javax.swing.SwingUtilities;
|
|
|
15 |
|
|
|
16 |
import org.openconcerto.erp.modules.ModuleFactory;
|
|
|
17 |
import org.openconcerto.sql.model.SQLRowAccessor;
|
|
|
18 |
import org.openconcerto.sql.model.SQLRowValues;
|
|
|
19 |
import org.openconcerto.sql.view.list.IListe;
|
|
|
20 |
import org.openconcerto.sql.view.list.ITableModel;
|
|
|
21 |
import org.openconcerto.ui.DefaultGridBagConstraints;
|
|
|
22 |
import org.openconcerto.utils.GestionDevise;
|
|
|
23 |
|
|
|
24 |
public class HistoriqueAffaireBilanPanel extends JPanel {
|
|
|
25 |
|
|
|
26 |
private DecimalFormat decimalFormat = new DecimalFormat("0.00");
|
|
|
27 |
|
|
|
28 |
private double pourcentCommande = 0;
|
|
|
29 |
private final JLabel labelPourcentCommande = new JLabel("", SwingConstants.RIGHT);
|
|
|
30 |
|
|
|
31 |
private long montantCommandeClient = 0;
|
|
|
32 |
private final JLabel labelCommandeClient = new JLabel("", SwingConstants.RIGHT);
|
|
|
33 |
|
|
|
34 |
private long montantBudget = 0;
|
|
|
35 |
private final JLabel labelBudget = new JLabel("", SwingConstants.RIGHT);
|
|
|
36 |
|
|
|
37 |
private long montantCommande = 0;
|
|
|
38 |
private final JLabel labelCommande = new JLabel("", SwingConstants.RIGHT);
|
|
|
39 |
|
|
|
40 |
private long montantCommandeP = 0;
|
|
|
41 |
private final JLabel labelCommandeP = new JLabel("", SwingConstants.RIGHT);
|
|
|
42 |
|
|
|
43 |
private long montantFacturer = 0;
|
|
|
44 |
private final JLabel labelFacturer = new JLabel("", SwingConstants.RIGHT);
|
|
|
45 |
|
|
|
46 |
private long montantRegler = 0;
|
|
|
47 |
private final JLabel labelMontantRegler = new JLabel("", SwingConstants.RIGHT);
|
|
|
48 |
|
|
|
49 |
private long montantRemise = 0;
|
|
|
50 |
|
|
|
51 |
private long montantRestantFacturer = 0;
|
|
|
52 |
private final JLabel labelRestantFacturer = new JLabel("", SwingConstants.RIGHT);
|
|
|
53 |
|
|
|
54 |
private final JLabel labelAvoir = new JLabel("");
|
|
|
55 |
private String motifAvoir = "";
|
|
|
56 |
|
|
|
57 |
private long montantAchat = 0;
|
|
|
58 |
private final JLabel labelAchat = new JLabel("", SwingConstants.RIGHT);
|
|
|
59 |
|
|
|
60 |
private final JLabel labelPercentBilan = new JLabel("", SwingConstants.RIGHT);
|
|
|
61 |
|
|
|
62 |
private final JLabel labelPercentMargeHT = new JLabel("", SwingConstants.RIGHT);
|
|
|
63 |
|
|
|
64 |
private final JLabel labelPercentMBBilan = new JLabel("", SwingConstants.RIGHT);
|
|
|
65 |
|
|
|
66 |
private final JLabel labelPercentMBAchat = new JLabel("", SwingConstants.RIGHT);
|
|
|
67 |
|
|
|
68 |
private static ModuleFactory factory;
|
|
|
69 |
|
|
|
70 |
public HistoriqueAffaireBilanPanel() {
|
|
|
71 |
super();
|
|
|
72 |
|
|
|
73 |
setLayout(new GridBagLayout());
|
|
|
74 |
GridBagConstraints c = new DefaultGridBagConstraints();
|
|
|
75 |
c.insets = new Insets(2, 2, 2, 75);
|
|
|
76 |
c.gridx = GridBagConstraints.RELATIVE;
|
|
|
77 |
|
|
|
78 |
c.gridwidth = GridBagConstraints.REMAINDER;
|
|
|
79 |
add(this.labelAvoir, c);
|
|
|
80 |
|
|
|
81 |
c.gridy++;
|
|
|
82 |
c.gridwidth = 1;
|
|
|
83 |
add(this.labelCommandeClient, c);
|
|
|
84 |
// add(this.labelCommandeP, c);
|
|
|
85 |
add(this.labelPercentMargeHT, c);
|
|
|
86 |
add(this.labelFacturer, c);
|
|
|
87 |
|
|
|
88 |
c.gridy++;
|
|
|
89 |
// add(this.labelPourcentCommande, c);
|
|
|
90 |
add(this.labelBudget, c);
|
|
|
91 |
add(this.labelCommande, c);
|
|
|
92 |
add(this.labelPercentMBBilan, c);
|
|
|
93 |
// add(this.labelMontantRegler, c);
|
|
|
94 |
|
|
|
95 |
c.gridy++;
|
|
|
96 |
// add(this.labelPercentBilan, c);
|
|
|
97 |
// add(this.labelPourcentCommande, c);
|
|
|
98 |
// add(this.labelAchat, c);
|
|
|
99 |
// add(this.labelPercentMBAchat, c);
|
|
|
100 |
// add(this.labelRestantFacturer, c);
|
|
|
101 |
|
|
|
102 |
// add(this.labelDemande);
|
|
|
103 |
//
|
|
|
104 |
// add(this.labelDemandeM);
|
|
|
105 |
//
|
|
|
106 |
// add(this.labelDemandeT);
|
|
|
107 |
//
|
|
|
108 |
// add(this.labelCommande);
|
|
|
109 |
//
|
|
|
110 |
// add(this.labelCommandeMonteur);
|
|
|
111 |
//
|
|
|
112 |
// add(this.labelCommandeTransporteur);
|
|
|
113 |
}
|
|
|
114 |
|
|
|
115 |
public synchronized void updateBilanPreBilan(final IListe listeCmdF) {
|
|
|
116 |
// if (rowAffaire == null || rowAffaire.isUndefined()) {
|
|
|
117 |
// this.montantCommande = 0;
|
|
|
118 |
// this.montantCommandeP = 0;
|
|
|
119 |
// return;
|
|
|
120 |
// }
|
|
|
121 |
long montant = 0;
|
|
|
122 |
|
|
|
123 |
if (listeCmdF != null) {
|
|
|
124 |
// Commande F
|
|
|
125 |
for (int i = 0; i < listeCmdF.getRowCount(); i++) {
|
|
|
126 |
final SQLRowValues rowAt = ITableModel.getLine(listeCmdF.getModel(), i).getRow();
|
|
|
127 |
|
|
|
128 |
montant += rowAt.getLong("T_HT");
|
|
|
129 |
}
|
|
|
130 |
}
|
|
|
131 |
|
|
|
132 |
this.montantCommande = montant;
|
|
|
133 |
|
|
|
134 |
updateLabels();
|
|
|
135 |
}
|
|
|
136 |
|
|
|
137 |
public synchronized void updateFacturer(final IListe liste, final IListe listeAvoir) {
|
|
|
138 |
// List<SQLRowAccessor> rows =
|
|
|
139 |
// liste.getSource().getLine(viewIndex)SelectedRows()Model().get;
|
|
|
140 |
if (liste == null || listeAvoir == null) {
|
|
|
141 |
return;
|
|
|
142 |
}
|
|
|
143 |
|
|
|
144 |
String motif = "";
|
|
|
145 |
long montant = 0;
|
|
|
146 |
BigDecimal montantRegler = BigDecimal.ZERO;
|
|
|
147 |
long montantRemise = 0;
|
|
|
148 |
for (int i = 0; i < liste.getRowCount(); i++) {
|
|
|
149 |
final SQLRowValues rowAt = ITableModel.getLine(liste.getModel(), i).getRow();
|
|
|
150 |
long ht = rowAt.getLong("T_HT");
|
|
|
151 |
long ttc = rowAt.getLong("T_TTC");
|
|
|
152 |
montant += ht;
|
|
|
153 |
|
|
|
154 |
// BigDecimal regler = new
|
|
|
155 |
// BigDecimal(calc.getReglement(rowAt.getForeign("ID_MOUVEMENT").getInt("ID_PIECE"),
|
|
|
156 |
// null));
|
|
|
157 |
// if (ht != ttc) {
|
|
|
158 |
// if (rowAt.getDate("DATE").getTime().compareTo(date2014) <= 0) {
|
|
|
159 |
// regler = regler.divide(new BigDecimal(1.196D), MathContext.DECIMAL128);
|
|
|
160 |
// } else {
|
|
|
161 |
// regler = regler.divide(new BigDecimal(1.2D), MathContext.DECIMAL128);
|
|
|
162 |
// }
|
|
|
163 |
// // regler = regler.divide(new BigDecimal(1.2D), MathContext.DECIMAL128);
|
|
|
164 |
// }
|
|
|
165 |
// montantRegler = montantRegler.add(regler);
|
|
|
166 |
|
|
|
167 |
}
|
|
|
168 |
|
|
|
169 |
// EncoursCalculator calc = new EncoursCalculator();
|
|
|
170 |
for (int i = 0; i < listeAvoir.getRowCount(); i++) {
|
|
|
171 |
final SQLRowValues rowAt = ITableModel.getLine(listeAvoir.getModel(), i).getRow();
|
|
|
172 |
if (rowAt.getBoolean("A_DEDUIRE")) {
|
|
|
173 |
montant -= rowAt.getLong("MONTANT_HT");
|
|
|
174 |
// montantRegler -= rowAt.getLong("MONTANT_TTC");
|
|
|
175 |
}
|
|
|
176 |
// else {
|
|
|
177 |
// long long1 = calc.getMontantAvoir(rowAt);
|
|
|
178 |
// montant -= long1;
|
|
|
179 |
// montantRemise += long1;
|
|
|
180 |
// motif += rowAt.getString("MOTIF") + "(-" + GestionDevise.currencyToString(long1,
|
|
|
181 |
// true) + " €)";
|
|
|
182 |
// }
|
|
|
183 |
}
|
|
|
184 |
this.motifAvoir = motif;
|
|
|
185 |
this.montantFacturer = montant;
|
|
|
186 |
this.montantRemise = montantRemise;
|
|
|
187 |
this.montantRegler = montantRegler.setScale(0, RoundingMode.HALF_UP).longValue();
|
|
|
188 |
updateLabels();
|
|
|
189 |
}
|
|
|
190 |
|
|
|
191 |
public synchronized void updateAchat(final IListe listeAchat, final IListe listeAchatAvoir) {
|
|
|
192 |
if (listeAchat == null) {
|
|
|
193 |
return;
|
|
|
194 |
}
|
|
|
195 |
final ITableModel model = listeAchat.getModel();
|
|
|
196 |
final ITableModel modelAvoir = listeAchatAvoir.getModel();
|
|
|
197 |
final Runnable r = new Runnable() {
|
|
|
198 |
@Override
|
|
|
199 |
public void run() {
|
|
|
200 |
// TODO Raccord de méthode auto-généré
|
|
|
201 |
long m = 0;
|
|
|
202 |
for (int i = 0; i < model.getRowCount(); i++) {
|
|
|
203 |
final SQLRowValues rowAt = model.getRow(i).getRow();
|
|
|
204 |
m += rowAt.getLong("MONTANT_HT");
|
|
|
205 |
}
|
|
|
206 |
|
|
|
207 |
for (int i = 0; i < modelAvoir.getRowCount(); i++) {
|
|
|
208 |
final SQLRowValues rowAt = modelAvoir.getRow(i).getRow();
|
|
|
209 |
m -= rowAt.getLong("MONTANT_HT");
|
|
|
210 |
}
|
|
|
211 |
montantAchat = m;
|
|
|
212 |
|
|
|
213 |
SwingUtilities.invokeLater(new Runnable() {
|
|
|
214 |
@Override
|
|
|
215 |
public void run() {
|
|
|
216 |
updateLabels();
|
|
|
217 |
}
|
|
|
218 |
});
|
|
|
219 |
}
|
|
|
220 |
};
|
|
|
221 |
model.invokeLater(r);
|
|
|
222 |
modelAvoir.invokeLater(r);
|
|
|
223 |
|
|
|
224 |
}
|
|
|
225 |
|
|
|
226 |
public synchronized void updateCommandeClient(SQLRowAccessor rowAff) {
|
|
|
227 |
if (rowAff != null) {
|
|
|
228 |
Collection<? extends SQLRowAccessor> rowCmd = rowAff.getReferentRows(rowAff.getTable().getTable("COMMANDE_CLIENT"));
|
|
|
229 |
long cmd = 0;
|
|
|
230 |
long b = 0;
|
|
|
231 |
for (SQLRowAccessor r : rowCmd) {
|
|
|
232 |
cmd += r.getLong("T_HT");
|
|
|
233 |
Collection<? extends SQLRowAccessor> ref = r.getReferentRows(rowAff.getTable().getTable("CHIFFRAGE_COMMANDE_CLIENT"));
|
|
|
234 |
for (SQLRowAccessor sqlRowAccessor : ref) {
|
|
|
235 |
b += sqlRowAccessor.getBigDecimal("T_PA_HT").setScale(0, RoundingMode.HALF_UP).longValue();
|
|
|
236 |
}
|
|
|
237 |
}
|
|
|
238 |
|
|
|
239 |
this.montantBudget = b;
|
|
|
240 |
this.montantCommandeClient = cmd;
|
|
|
241 |
updateLabels();
|
|
|
242 |
}
|
|
|
243 |
}
|
|
|
244 |
|
|
|
245 |
public synchronized void updateDevis(SQLRowAccessor rowAff) {
|
|
|
246 |
if (rowAff != null) {
|
|
|
247 |
Collection<? extends SQLRowAccessor> rowCmd = rowAff.getReferentRows(rowAff.getTable().getTable("DEVIS"));
|
|
|
248 |
long cmd = 0;
|
|
|
249 |
for (SQLRowAccessor r : rowCmd) {
|
|
|
250 |
cmd += r.getLong("T_HA");
|
|
|
251 |
}
|
|
|
252 |
// this.montantBudget = cmd;
|
|
|
253 |
updateLabels();
|
|
|
254 |
}
|
|
|
255 |
}
|
|
|
256 |
|
|
|
257 |
private void updateLabels() {
|
|
|
258 |
long mbP = this.montantCommandeClient - this.montantCommandeP;
|
|
|
259 |
final long mbB = this.montantCommandeClient - this.montantCommande;
|
|
|
260 |
long mbA = this.montantFacturer - this.montantAchat;
|
|
|
261 |
|
|
|
262 |
final double percentMBPreBilan = Math.round((this.montantCommandeClient == 0 ? 0 : (double) mbP / (double) this.montantCommandeClient) * 10000.0D) / 100.0D;
|
|
|
263 |
final double percentMBBilan = Math.round((this.montantCommandeClient == 0 ? 0 : (double) mbB / (double) this.montantCommandeClient) * 10000.0D) / 100.0D;
|
|
|
264 |
final double percentMBAchat = Math.round((this.montantFacturer == 0 || this.montantAchat == 0 ? 0 : (double) mbA / (double) this.montantFacturer) * 10000.0D) / 100.0D;
|
|
|
265 |
|
|
|
266 |
SwingUtilities.invokeLater(new Runnable() {
|
|
|
267 |
public void run() {
|
|
|
268 |
HistoriqueAffaireBilanPanel.this.labelAvoir.setText(motifAvoir);
|
|
|
269 |
HistoriqueAffaireBilanPanel.this.labelPourcentCommande.setText(decimalFormat.format(pourcentCommande) + "% des commandes livrées");
|
|
|
270 |
|
|
|
271 |
// HistoriqueAffaireBilanPanel.this.labelPercentMBPreBilan.setText(decimalFormat.format(percentMBPreBilan)
|
|
|
272 |
// + "% MB Prébilan");
|
|
|
273 |
HistoriqueAffaireBilanPanel.this.labelPercentMBBilan.setText(decimalFormat.format(percentMBBilan) + "% MB sur commande");
|
|
|
274 |
HistoriqueAffaireBilanPanel.this.labelPercentMBAchat.setText(decimalFormat.format(percentMBAchat) + "% MB Achats");
|
|
|
275 |
HistoriqueAffaireBilanPanel.this.labelCommandeClient.setText("Montant du marché : " + GestionDevise.currencyToString(montantCommandeClient) + "€");
|
|
|
276 |
HistoriqueAffaireBilanPanel.this.labelFacturer.setText("Montant facturé : " + GestionDevise.currencyToString(montantFacturer) + "€");
|
|
|
277 |
HistoriqueAffaireBilanPanel.this.labelAchat.setText("Total Achats : " + GestionDevise.currencyToString(montantAchat) + "€");
|
|
|
278 |
HistoriqueAffaireBilanPanel.this.labelCommandeP.setText("Total PréBilan : " + GestionDevise.currencyToString(montantCommandeP) + "€");
|
|
|
279 |
HistoriqueAffaireBilanPanel.this.labelCommande.setText("Total Commandes F. : " + GestionDevise.currencyToString(montantCommande) + "€");
|
|
|
280 |
HistoriqueAffaireBilanPanel.this.labelBudget.setText("Budget chiffré à : " + GestionDevise.currencyToString(montantBudget) + "€");
|
|
|
281 |
HistoriqueAffaireBilanPanel.this.labelMontantRegler.setText("Règlements effectués : " + GestionDevise.currencyToString(montantRegler) + "€");
|
|
|
282 |
HistoriqueAffaireBilanPanel.this.labelRestantFacturer.setText("Reste à facturer : " + GestionDevise.currencyToString(montantCommandeClient - montantFacturer - montantRemise) + "€");
|
|
|
283 |
HistoriqueAffaireBilanPanel.this.labelPercentMargeHT.setText("Marge HT : " + GestionDevise.currencyToString(mbB) + "€");
|
|
|
284 |
}
|
|
|
285 |
});
|
|
|
286 |
|
|
|
287 |
}
|
|
|
288 |
}
|