Line 12... |
Line 12... |
12 |
*/
|
12 |
*/
|
13 |
|
13 |
|
14 |
package org.openconcerto.erp.core.supplychain.order.action;
|
14 |
package org.openconcerto.erp.core.supplychain.order.action;
|
15 |
|
15 |
|
16 |
import org.openconcerto.erp.action.CreateFrameAbstractAction;
|
16 |
import org.openconcerto.erp.action.CreateFrameAbstractAction;
|
- |
|
17 |
import org.openconcerto.erp.core.common.ui.IListFilterDatePanel;
|
17 |
import org.openconcerto.sql.Configuration;
|
18 |
import org.openconcerto.sql.Configuration;
|
18 |
import org.openconcerto.sql.element.SQLElement;
|
19 |
import org.openconcerto.sql.element.SQLElement;
|
19 |
import org.openconcerto.sql.model.FieldPath;
|
20 |
import org.openconcerto.sql.model.FieldPath;
|
- |
|
21 |
import org.openconcerto.sql.model.SQLField;
|
20 |
import org.openconcerto.sql.model.SQLRowAccessor;
|
22 |
import org.openconcerto.sql.model.SQLRowAccessor;
|
21 |
import org.openconcerto.sql.model.graph.Path;
|
23 |
import org.openconcerto.sql.model.graph.Path;
|
22 |
import org.openconcerto.sql.model.graph.PathBuilder;
|
24 |
import org.openconcerto.sql.model.graph.PathBuilder;
|
23 |
import org.openconcerto.sql.view.IListFrame;
|
25 |
import org.openconcerto.sql.view.IListFrame;
|
24 |
import org.openconcerto.sql.view.ListeAddPanel;
|
26 |
import org.openconcerto.sql.view.ListeAddPanel;
|
25 |
import org.openconcerto.sql.view.list.BaseSQLTableModelColumn;
|
27 |
import org.openconcerto.sql.view.list.BaseSQLTableModelColumn;
|
26 |
import org.openconcerto.sql.view.list.IListe;
|
28 |
import org.openconcerto.sql.view.list.IListe;
|
27 |
import org.openconcerto.sql.view.list.SQLTableModelSourceOnline;
|
29 |
import org.openconcerto.sql.view.list.SQLTableModelSourceOnline;
|
- |
|
30 |
import org.openconcerto.ui.DefaultGridBagConstraints;
|
28 |
import org.openconcerto.ui.table.PercentTableCellRenderer;
|
31 |
import org.openconcerto.ui.table.PercentTableCellRenderer;
|
29 |
import org.openconcerto.utils.CollectionUtils;
|
32 |
import org.openconcerto.utils.CollectionUtils;
|
30 |
import org.openconcerto.utils.DecimalUtils;
|
33 |
import org.openconcerto.utils.DecimalUtils;
|
31 |
|
34 |
|
- |
|
35 |
import java.awt.GridBagConstraints;
|
32 |
import java.math.BigDecimal;
|
36 |
import java.math.BigDecimal;
|
33 |
import java.math.RoundingMode;
|
37 |
import java.math.RoundingMode;
|
34 |
import java.util.Collection;
|
38 |
import java.util.Collection;
|
- |
|
39 |
import java.util.HashMap;
|
- |
|
40 |
import java.util.Map;
|
35 |
import java.util.Set;
|
41 |
import java.util.Set;
|
36 |
|
42 |
|
37 |
import javax.swing.Action;
|
43 |
import javax.swing.Action;
|
38 |
import javax.swing.JFrame;
|
44 |
import javax.swing.JFrame;
|
39 |
|
45 |
|
Line 45... |
Line 51... |
45 |
|
51 |
|
46 |
public JFrame createFrame() {
|
52 |
public JFrame createFrame() {
|
47 |
|
53 |
|
48 |
final SQLElement elementCmd = Configuration.getInstance().getDirectory().getElement("COMMANDE");
|
54 |
final SQLElement elementCmd = Configuration.getInstance().getDirectory().getElement("COMMANDE");
|
49 |
final SQLTableModelSourceOnline tableSource = elementCmd.getTableSource(true);
|
55 |
final SQLTableModelSourceOnline tableSource = elementCmd.getTableSource(true);
|
50 |
BaseSQLTableModelColumn colAvancement = new BaseSQLTableModelColumn("Avancement réception", BigDecimal.class) {
|
56 |
BaseSQLTableModelColumn colAvancementR = new BaseSQLTableModelColumn("Avancement réception", BigDecimal.class) {
|
51 |
|
57 |
|
52 |
@Override
|
58 |
@Override
|
53 |
protected Object show_(SQLRowAccessor r) {
|
59 |
protected Object show_(SQLRowAccessor r) {
|
54 |
|
60 |
|
55 |
return getAvancement(r);
|
61 |
return getAvancementLFromBR(r);
|
56 |
}
|
62 |
}
|
57 |
|
63 |
|
58 |
@Override
|
64 |
@Override
|
59 |
public Set<FieldPath> getPaths() {
|
65 |
public Set<FieldPath> getPaths() {
|
- |
|
66 |
final Path p = new PathBuilder(elementCmd.getTable()).addTable("COMMANDE_ELEMENT").build();
|
- |
|
67 |
return CollectionUtils.createSet(new FieldPath(p, "RECU_FORCED"), new FieldPath(p, "RECU"), new FieldPath(p, "QTE_RECUE"), new FieldPath(p, "PA_HT"), new FieldPath(p, "ID_ARTICLE"),
|
- |
|
68 |
new FieldPath(p, "QTE"), new FieldPath(p, "QTE_UNITAIRE"));
|
- |
|
69 |
}
|
- |
|
70 |
};
|
- |
|
71 |
tableSource.getColumns().add(colAvancementR);
|
- |
|
72 |
colAvancementR.setRenderer(new PercentTableCellRenderer());
|
- |
|
73 |
|
- |
|
74 |
BaseSQLTableModelColumn colAvancement = new BaseSQLTableModelColumn("Avancement facturation", BigDecimal.class) {
|
- |
|
75 |
|
- |
|
76 |
@Override
|
- |
|
77 |
protected Object show_(SQLRowAccessor r) {
|
- |
|
78 |
|
- |
|
79 |
return getAvancementFact(r);
|
- |
|
80 |
}
|
- |
|
81 |
|
- |
|
82 |
@Override
|
- |
|
83 |
public Set<FieldPath> getPaths() {
|
- |
|
84 |
final Path p = new PathBuilder(elementCmd.getTable()).addTable("TR_COMMANDE").addTable("SAISIE_ACHAT").build();
|
- |
|
85 |
final Path p2 = new PathBuilder(elementCmd.getTable()).addTable("TR_COMMANDE").addTable("FACTURE_FOURNISSEUR").build();
|
- |
|
86 |
|
60 |
final Path p = new PathBuilder(elementCmd.getTable()).addTable("TR_COMMANDE").addTable("BON_RECEPTION").build();
|
87 |
final Path pBr = new PathBuilder(elementCmd.getTable()).addTable("TR_COMMANDE").addTable("BON_RECEPTION").build();
|
- |
|
88 |
final Path trBr = pBr.add(elementCmd.getTable().getTable("TR_BON_RECEPTION"));
|
- |
|
89 |
final Path pFact2 = trBr.addTable("FACTURE_FOURNISSEUR");
|
61 |
return CollectionUtils.createSet(new FieldPath(p, "TOTAL_HT"));
|
90 |
final Path pAchat2 = trBr.addTable("SAISIE_ACHAT");
|
- |
|
91 |
return CollectionUtils.createSet(new FieldPath(p, "MONTANT_HT"), new FieldPath(p2, "T_HT"), new FieldPath(pAchat2, "MONTANT_HT"), new FieldPath(pFact2, "T_HT"));
|
62 |
}
|
92 |
}
|
63 |
};
|
93 |
};
|
64 |
tableSource.getColumns().add(colAvancement);
|
94 |
tableSource.getColumns().add(colAvancement);
|
65 |
colAvancement.setRenderer(new PercentTableCellRenderer());
|
95 |
colAvancement.setRenderer(new PercentTableCellRenderer());
|
66 |
|
96 |
|
67 |
final IListFrame frame = new IListFrame(new ListeAddPanel(elementCmd, new IListe(tableSource)));
|
97 |
final ListeAddPanel panel = new ListeAddPanel(elementCmd, new IListe(tableSource));
|
- |
|
98 |
// Date panel
|
- |
|
99 |
Map<IListe, SQLField> map = new HashMap<IListe, SQLField>();
|
- |
|
100 |
map.put(panel.getListe(), elementCmd.getTable().getField("DATE"));
|
- |
|
101 |
|
- |
|
102 |
IListFilterDatePanel datePanel = new IListFilterDatePanel(map, IListFilterDatePanel.getDefaultMap());
|
- |
|
103 |
GridBagConstraints c = new DefaultGridBagConstraints();
|
- |
|
104 |
c.weightx = 0;
|
- |
|
105 |
c.fill = GridBagConstraints.NONE;
|
- |
|
106 |
c.gridy = 4;
|
- |
|
107 |
c.anchor = GridBagConstraints.CENTER;
|
- |
|
108 |
c.weighty = 0;
|
- |
|
109 |
datePanel.setFilterOnDefault();
|
- |
|
110 |
panel.add(datePanel, c);
|
- |
|
111 |
final IListFrame frame = new IListFrame(panel);
|
68 |
|
112 |
|
69 |
return frame;
|
113 |
return frame;
|
70 |
}
|
114 |
}
|
71 |
|
115 |
|
- |
|
116 |
private BigDecimal getAvancementLFromBR(SQLRowAccessor r) {
|
- |
|
117 |
Collection<? extends SQLRowAccessor> rows = r.getReferentRows(r.getTable().getTable("COMMANDE_ELEMENT"));
|
- |
|
118 |
BigDecimal totalQte = BigDecimal.ZERO;
|
- |
|
119 |
BigDecimal totalQteL = BigDecimal.ZERO;
|
- |
|
120 |
for (SQLRowAccessor row : rows) {
|
- |
|
121 |
BigDecimal qte = row.getBigDecimal("QTE_UNITAIRE").multiply(new BigDecimal(row.getInt("QTE")));
|
- |
|
122 |
// On ne prend en compte que les articles ou les lignes différentes de 0
|
- |
|
123 |
if (!row.isForeignEmpty("ID_ARTICLE") || row.getBigDecimal("PA_HT").signum() != 0) {
|
- |
|
124 |
totalQte = totalQte.add(qte);
|
- |
|
125 |
if (row.getBoolean("RECU_FORCED") || row.getBoolean("RECU")) {
|
- |
|
126 |
totalQteL = totalQteL.add(qte);
|
- |
|
127 |
} else if (row.getBigDecimal("QTE_RECUE") != null) {
|
- |
|
128 |
final BigDecimal qteLivree = row.getBigDecimal("QTE_RECUE");
|
- |
|
129 |
if (qteLivree != null) {
|
- |
|
130 |
totalQteL = totalQteL.add(qteLivree);
|
- |
|
131 |
}
|
- |
|
132 |
}
|
- |
|
133 |
}
|
- |
|
134 |
}
|
- |
|
135 |
if (totalQte.signum() != 0) {
|
- |
|
136 |
return totalQteL.divide(totalQte, DecimalUtils.HIGH_PRECISION).movePointRight(2).setScale(2, RoundingMode.HALF_UP);
|
- |
|
137 |
} else {
|
- |
|
138 |
return BigDecimal.ONE.movePointRight(2);
|
- |
|
139 |
}
|
- |
|
140 |
}
|
- |
|
141 |
|
- |
|
142 |
BigDecimal bigDecimal100 = new BigDecimal(100.0);
|
- |
|
143 |
|
- |
|
144 |
private BigDecimal getAvancementFact(SQLRowAccessor r) {
|
- |
|
145 |
Collection<? extends SQLRowAccessor> rows = r.getReferentRows(r.getTable().getTable("TR_COMMANDE"));
|
- |
|
146 |
long totalFact = 0;
|
- |
|
147 |
long total = r.getLong("T_HT");
|
- |
|
148 |
for (SQLRowAccessor row : rows) {
|
- |
|
149 |
if (!row.isForeignEmpty("ID_FACTURE_FOURNISSEUR")) {
|
- |
|
150 |
SQLRowAccessor rowFact = row.getForeign("ID_FACTURE_FOURNISSEUR");
|
- |
|
151 |
Long l = rowFact.getLong("T_HT");
|
- |
|
152 |
totalFact += l;
|
- |
|
153 |
}
|
- |
|
154 |
if (!row.isForeignEmpty("ID_SAISIE_ACHAT")) {
|
- |
|
155 |
SQLRowAccessor rowFact = row.getForeign("ID_SAISIE_ACHAT");
|
- |
|
156 |
Long l = rowFact.getLong("MONTANT_HT");
|
- |
|
157 |
totalFact += l;
|
- |
|
158 |
}
|
- |
|
159 |
|
- |
|
160 |
if (!row.isForeignEmpty("ID_BON_RECEPTION")) {
|
- |
|
161 |
Collection<? extends SQLRowAccessor> rowsBr = row.getForeign("ID_BON_RECEPTION").getReferentRows(r.getTable().getTable("TR_BON_RECEPTION"));
|
- |
|
162 |
for (SQLRowAccessor rowTrBr : rowsBr) {
|
- |
|
163 |
if (!rowTrBr.isForeignEmpty("ID_FACTURE_FOURNISSEUR")) {
|
- |
|
164 |
SQLRowAccessor rowFact = rowTrBr.getForeign("ID_FACTURE_FOURNISSEUR");
|
- |
|
165 |
Long l = rowFact.getLong("T_HT");
|
- |
|
166 |
totalFact += l;
|
- |
|
167 |
}
|
- |
|
168 |
if (!rowTrBr.isForeignEmpty("ID_SAISIE_ACHAT")) {
|
- |
|
169 |
SQLRowAccessor rowFact = rowTrBr.getForeign("ID_SAISIE_ACHAT");
|
- |
|
170 |
Long l = rowFact.getLong("MONTANT_HT");
|
- |
|
171 |
totalFact += l;
|
- |
|
172 |
}
|
- |
|
173 |
|
- |
|
174 |
}
|
- |
|
175 |
}
|
- |
|
176 |
}
|
- |
|
177 |
|
- |
|
178 |
if (total > 0) {
|
- |
|
179 |
return this.bigDecimal100.min(new BigDecimal(totalFact).divide(new BigDecimal(total), DecimalUtils.HIGH_PRECISION).movePointRight(2).setScale(2, RoundingMode.HALF_UP));
|
- |
|
180 |
} else {
|
- |
|
181 |
return BigDecimal.ONE.movePointRight(2);
|
- |
|
182 |
}
|
- |
|
183 |
}
|
- |
|
184 |
|
72 |
private BigDecimal getAvancement(SQLRowAccessor r) {
|
185 |
private BigDecimal getAvancement(SQLRowAccessor r) {
|
73 |
Collection<? extends SQLRowAccessor> rows = r.getReferentRows(r.getTable().getTable("TR_COMMANDE"));
|
186 |
Collection<? extends SQLRowAccessor> rows = r.getReferentRows(r.getTable().getTable("TR_COMMANDE"));
|
74 |
long totalFact = 0;
|
187 |
long totalFact = 0;
|
75 |
long total = r.getLong("T_HT");
|
188 |
long total = r.getLong("T_HT");
|
76 |
for (SQLRowAccessor row : rows) {
|
189 |
for (SQLRowAccessor row : rows) {
|