144 |
ilm |
1 |
/*
|
|
|
2 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
|
|
|
3 |
*
|
|
|
4 |
* Copyright 2011 OpenConcerto, by ILM Informatique. All rights reserved.
|
|
|
5 |
*
|
|
|
6 |
* The contents of this file are subject to the terms of the GNU General Public License Version 3
|
|
|
7 |
* only ("GPL"). You may not use this file except in compliance with the License. You can obtain a
|
|
|
8 |
* copy of the License at http://www.gnu.org/licenses/gpl-3.0.html See the License for the specific
|
|
|
9 |
* language governing permissions and limitations under the License.
|
|
|
10 |
*
|
|
|
11 |
* When distributing the software, include this License Header Notice in each file.
|
|
|
12 |
*/
|
|
|
13 |
|
|
|
14 |
package org.openconcerto.erp.core.sales.order.element;
|
|
|
15 |
|
|
|
16 |
import org.openconcerto.erp.core.common.element.ComptaSQLConfElement;
|
149 |
ilm |
17 |
import org.openconcerto.erp.core.common.ui.DeviseTableCellRenderer;
|
144 |
ilm |
18 |
import org.openconcerto.erp.core.sales.invoice.report.VenteFactureXmlSheet;
|
|
|
19 |
import org.openconcerto.erp.core.sales.order.ui.TypeFactureCommandeCellRenderer;
|
|
|
20 |
import org.openconcerto.erp.core.sales.order.ui.TypeFactureCommandeClient;
|
|
|
21 |
import org.openconcerto.erp.core.sales.order.ui.TypeFactureCommandeClientComboBox;
|
|
|
22 |
import org.openconcerto.erp.core.sales.order.ui.TypeFactureCommandeRowItemView;
|
|
|
23 |
import org.openconcerto.sql.element.BaseSQLComponent;
|
|
|
24 |
import org.openconcerto.sql.element.SQLComponent;
|
|
|
25 |
import org.openconcerto.sql.element.UISQLComponent;
|
149 |
ilm |
26 |
import org.openconcerto.sql.model.FieldPath;
|
144 |
ilm |
27 |
import org.openconcerto.sql.model.SQLRow;
|
|
|
28 |
import org.openconcerto.sql.model.SQLRowAccessor;
|
|
|
29 |
import org.openconcerto.sql.model.SQLRowValues;
|
149 |
ilm |
30 |
import org.openconcerto.sql.model.graph.Path;
|
144 |
ilm |
31 |
import org.openconcerto.sql.view.EditFrame;
|
|
|
32 |
import org.openconcerto.sql.view.EditPanelListener;
|
149 |
ilm |
33 |
import org.openconcerto.sql.view.list.BaseSQLTableModelColumn;
|
144 |
ilm |
34 |
import org.openconcerto.sql.view.list.IListe;
|
|
|
35 |
import org.openconcerto.sql.view.list.RowAction;
|
|
|
36 |
import org.openconcerto.sql.view.list.SQLTableModelSource;
|
149 |
ilm |
37 |
import org.openconcerto.utils.CollectionUtils;
|
|
|
38 |
import org.openconcerto.utils.DecimalUtils;
|
144 |
ilm |
39 |
import org.openconcerto.utils.ExceptionHandler;
|
|
|
40 |
|
|
|
41 |
import java.awt.event.ActionEvent;
|
149 |
ilm |
42 |
import java.math.BigDecimal;
|
144 |
ilm |
43 |
import java.sql.SQLException;
|
|
|
44 |
import java.util.ArrayList;
|
|
|
45 |
import java.util.Arrays;
|
|
|
46 |
import java.util.HashSet;
|
|
|
47 |
import java.util.List;
|
|
|
48 |
import java.util.Set;
|
|
|
49 |
|
|
|
50 |
import javax.swing.AbstractAction;
|
|
|
51 |
|
|
|
52 |
public class FacturationCommandeClientSQLElement extends ComptaSQLConfElement {
|
|
|
53 |
|
|
|
54 |
public static final String TABLENAME = "FACTURATION_COMMANDE_CLIENT";
|
|
|
55 |
|
|
|
56 |
public FacturationCommandeClientSQLElement() {
|
|
|
57 |
super(TABLENAME, "une terme de facturation de commande client", "termes de facturation commandes clients");
|
|
|
58 |
{
|
|
|
59 |
RowAction action = new RowAction(new AbstractAction("Facturer") {
|
|
|
60 |
|
|
|
61 |
@Override
|
|
|
62 |
public void actionPerformed(ActionEvent e) {
|
|
|
63 |
final SQLRow sel = IListe.get(e).getSelectedRow().asRow();
|
|
|
64 |
sel.fetchValues();
|
|
|
65 |
CommandeClientSQLElement eltCmd = (CommandeClientSQLElement) getForeignElement("ID_COMMANDE_CLIENT");
|
|
|
66 |
int typeFacture = sel.getInt("TYPE_FACTURE");
|
|
|
67 |
final SQLRow asRow = sel.getForeign("ID_COMMANDE_CLIENT").asRow();
|
|
|
68 |
asRow.fetchValues();
|
|
|
69 |
List<SQLRowValues> l = Arrays.asList(asRow.asRowValues());
|
|
|
70 |
final EditFrame f;
|
|
|
71 |
if (typeFacture == TypeFactureCommandeClient.SITUATION.getId()) {
|
|
|
72 |
f = eltCmd.transfertAcompteClient(l);
|
|
|
73 |
SQLRowValues rowValues = new SQLRowValues(getForeignElement("ID_SAISIE_VENTE_FACTURE").getTable());
|
|
|
74 |
rowValues.put("POURCENT_FACTURABLE", sel.getObject("POURCENT"));
|
|
|
75 |
rowValues.put("MONTANT_FACTURABLE", null);
|
|
|
76 |
((BaseSQLComponent) f.getSQLComponent()).getView("MONTANT_FACTURABLE,POURCENT_FACTURABLE").show(rowValues);
|
|
|
77 |
;
|
|
|
78 |
|
|
|
79 |
} else if (typeFacture == TypeFactureCommandeClient.SOLDE.getId()) {
|
|
|
80 |
f = eltCmd.transfertSoldeClient(l);
|
|
|
81 |
|
|
|
82 |
} else {
|
|
|
83 |
f = eltCmd.transfertFactureClient(l);
|
|
|
84 |
}
|
|
|
85 |
|
|
|
86 |
SQLRowValues rowValues = new SQLRowValues(eltCmd.getTable().getTable("MODE_REGLEMENT").getTable());
|
|
|
87 |
rowValues.put("ID_TYPE_REGLEMENT", sel.getForeignID("ID_TYPE_REGLEMENT"));
|
|
|
88 |
rowValues.put("FIN_MOIS", Boolean.FALSE);
|
|
|
89 |
if (sel.getBoolean("COMPTANT")) {
|
|
|
90 |
rowValues.put("AJOURS", 0);
|
|
|
91 |
rowValues.put("LENJOUR", 0);
|
|
|
92 |
rowValues.put("DATE_FACTURE", Boolean.TRUE);
|
|
|
93 |
rowValues.put("COMPTANT", Boolean.TRUE);
|
|
|
94 |
} else {
|
|
|
95 |
rowValues.put("AJOURS", sel.getObject("AJOURS"));
|
|
|
96 |
int lenjour = sel.getInt("LENJOUR");
|
|
|
97 |
if (sel.getBoolean("FIN_MOIS")) {
|
|
|
98 |
lenjour = 31;
|
|
|
99 |
}
|
|
|
100 |
rowValues.put("LENJOUR", lenjour);
|
|
|
101 |
rowValues.put("COMPTANT", Boolean.FALSE);
|
|
|
102 |
rowValues.put("FIN_MOIS", lenjour == 31);
|
|
|
103 |
rowValues.put("DATE_FACTURE", lenjour == 0);
|
|
|
104 |
}
|
|
|
105 |
|
|
|
106 |
((BaseSQLComponent) f.getSQLComponent()).getView("ID_MODE_REGLEMENT").show(rowValues);
|
|
|
107 |
;
|
|
|
108 |
|
|
|
109 |
f.addEditPanelListener(new EditPanelListener() {
|
|
|
110 |
|
|
|
111 |
@Override
|
|
|
112 |
public void modified() {
|
|
|
113 |
|
|
|
114 |
}
|
|
|
115 |
|
|
|
116 |
@Override
|
|
|
117 |
public void inserted(int id) {
|
|
|
118 |
try {
|
|
|
119 |
sel.createEmptyUpdateRow().put("ID_SAISIE_VENTE_FACTURE", id).commit();
|
|
|
120 |
} catch (SQLException e) {
|
|
|
121 |
ExceptionHandler.handle("Erreur lors de l'affectation de la facture", e);
|
|
|
122 |
}
|
|
|
123 |
}
|
|
|
124 |
|
|
|
125 |
@Override
|
|
|
126 |
public void deleted() {
|
|
|
127 |
}
|
|
|
128 |
|
|
|
129 |
@Override
|
|
|
130 |
public void cancelled() {
|
|
|
131 |
|
|
|
132 |
}
|
|
|
133 |
});
|
|
|
134 |
}
|
|
|
135 |
}, true) {
|
|
|
136 |
@Override
|
|
|
137 |
public boolean enabledFor(List<SQLRowValues> selection) {
|
|
|
138 |
|
|
|
139 |
if (selection != null && selection.size() == 1) {
|
|
|
140 |
SQLRowAccessor sel = selection.get(0);
|
|
|
141 |
return sel.isForeignEmpty("ID_SAISIE_VENTE_FACTURE");
|
|
|
142 |
}
|
|
|
143 |
return false;
|
|
|
144 |
}
|
|
|
145 |
};
|
|
|
146 |
|
|
|
147 |
getRowActions().add(action);
|
|
|
148 |
}
|
|
|
149 |
|
|
|
150 |
{
|
|
|
151 |
RowAction action = new RowAction(new AbstractAction("Voir la facture") {
|
|
|
152 |
|
|
|
153 |
@Override
|
|
|
154 |
public void actionPerformed(ActionEvent e) {
|
|
|
155 |
final SQLRowAccessor sel = IListe.get(e).getSelectedRow();
|
|
|
156 |
SQLRowAccessor fact = sel.getForeign("ID_SAISIE_VENTE_FACTURE");
|
|
|
157 |
VenteFactureXmlSheet sheet = new VenteFactureXmlSheet(fact.asRow());
|
|
|
158 |
try {
|
|
|
159 |
sheet.showPreviewDocument();
|
|
|
160 |
} catch (Exception e1) {
|
|
|
161 |
// TODO Auto-generated catch block
|
|
|
162 |
e1.printStackTrace();
|
|
|
163 |
}
|
|
|
164 |
}
|
|
|
165 |
}, true) {
|
|
|
166 |
@Override
|
|
|
167 |
public boolean enabledFor(List<SQLRowValues> selection) {
|
|
|
168 |
|
|
|
169 |
if (selection != null && selection.size() == 1) {
|
|
|
170 |
SQLRowAccessor sel = selection.get(0);
|
|
|
171 |
return !sel.isForeignEmpty("ID_SAISIE_VENTE_FACTURE");
|
|
|
172 |
}
|
|
|
173 |
return false;
|
|
|
174 |
}
|
|
|
175 |
};
|
|
|
176 |
|
|
|
177 |
getRowActions().add(action);
|
|
|
178 |
}
|
|
|
179 |
}
|
|
|
180 |
|
|
|
181 |
/*
|
|
|
182 |
* (non-Javadoc)
|
|
|
183 |
*
|
|
|
184 |
* @see org.openconcerto.devis.BaseSQLElement#getComboFields()
|
|
|
185 |
*/
|
|
|
186 |
protected List<String> getComboFields() {
|
|
|
187 |
final List<String> l = new ArrayList<>(1);
|
|
|
188 |
l.add("NOM");
|
|
|
189 |
return l;
|
|
|
190 |
}
|
|
|
191 |
|
|
|
192 |
@Override
|
|
|
193 |
public Set<String> getReadOnlyFields() {
|
|
|
194 |
Set<String> s = new HashSet<>(1);
|
|
|
195 |
s.add("CHOICE");
|
|
|
196 |
return s;
|
|
|
197 |
}
|
|
|
198 |
|
|
|
199 |
@Override
|
|
|
200 |
protected String getParentFFName() {
|
|
|
201 |
return "ID_COMMANDE_CLIENT";
|
|
|
202 |
}
|
|
|
203 |
|
|
|
204 |
/*
|
|
|
205 |
* (non-Javadoc)
|
|
|
206 |
*
|
|
|
207 |
* @see org.openconcerto.devis.BaseSQLElement#getListFields()
|
|
|
208 |
*/
|
|
|
209 |
protected List<String> getListFields() {
|
|
|
210 |
final List<String> l = new ArrayList<>(7);
|
|
|
211 |
l.add("NOM");
|
|
|
212 |
l.add("TYPE_FACTURE");
|
|
|
213 |
l.add("ID_TYPE_REGLEMENT");
|
|
|
214 |
l.add("POURCENT");
|
|
|
215 |
l.add("DATE_PREVISIONNELLE");
|
|
|
216 |
l.add("ID_COMMANDE_CLIENT");
|
|
|
217 |
l.add("ID_SAISIE_VENTE_FACTURE");
|
|
|
218 |
return l;
|
|
|
219 |
}
|
|
|
220 |
|
|
|
221 |
@Override
|
|
|
222 |
protected void _initTableSource(SQLTableModelSource res) {
|
|
|
223 |
res.init();
|
149 |
ilm |
224 |
res.getColumn(getTable().getField("POURCENT")).setRenderer(new DeviseTableCellRenderer());
|
144 |
ilm |
225 |
res.getColumn(getTable().getField("TYPE_FACTURE")).setRenderer(new TypeFactureCommandeCellRenderer());
|
149 |
ilm |
226 |
final BaseSQLTableModelColumn pourcentFact = new BaseSQLTableModelColumn("Montant facturé", BigDecimal.class) {
|
|
|
227 |
|
|
|
228 |
@Override
|
|
|
229 |
protected Object show_(SQLRowAccessor r) {
|
|
|
230 |
long ht = r.getForeign("ID_COMMANDE_CLIENT").getLong("T_TTC");
|
|
|
231 |
BigDecimal percent = r.getBigDecimal("POURCENT");
|
|
|
232 |
return percent.movePointLeft(2).multiply(new BigDecimal(ht).movePointLeft(2), DecimalUtils.HIGH_PRECISION);
|
|
|
233 |
}
|
|
|
234 |
|
|
|
235 |
@Override
|
|
|
236 |
public Set<FieldPath> getPaths() {
|
|
|
237 |
Path p = new Path(getTable());
|
|
|
238 |
Path p2 = p.add(p.getFirst().getField("ID_COMMANDE_CLIENT"));
|
|
|
239 |
return CollectionUtils.createSet(new FieldPath(p, "POURCENT"), new FieldPath(p2, "T_TTC"));
|
|
|
240 |
}
|
|
|
241 |
};
|
|
|
242 |
pourcentFact.setRenderer(new DeviseTableCellRenderer());
|
|
|
243 |
res.getColumns().add(pourcentFact);
|
144 |
ilm |
244 |
super._initTableSource(res);
|
|
|
245 |
}
|
|
|
246 |
|
|
|
247 |
/*
|
|
|
248 |
* (non-Javadoc)
|
|
|
249 |
*
|
|
|
250 |
* @see org.openconcerto.devis.SQLElement#getComponent()
|
|
|
251 |
*/
|
|
|
252 |
public SQLComponent createComponent() {
|
|
|
253 |
return new UISQLComponent(this) {
|
|
|
254 |
public void addViews() {
|
|
|
255 |
this.addView("NOM");
|
|
|
256 |
this.addView("POURCENT");
|
|
|
257 |
this.addView("ID_TYPE_REGLEMENT");
|
|
|
258 |
this.addView("AJOURS");
|
|
|
259 |
this.addView("COMPTANT");
|
|
|
260 |
this.addView("CHOICE");
|
|
|
261 |
|
|
|
262 |
TypeFactureCommandeClientComboBox box = new TypeFactureCommandeClientComboBox();
|
|
|
263 |
|
|
|
264 |
this.addView(new TypeFactureCommandeRowItemView(box), "TYPE_FACTURE", REQ);
|
|
|
265 |
this.addView("ID_MODELE");
|
|
|
266 |
}
|
|
|
267 |
|
|
|
268 |
@Override
|
|
|
269 |
protected SQLRowValues createDefaults() {
|
|
|
270 |
SQLRowValues rowVals = new SQLRowValues(getTable());
|
|
|
271 |
rowVals.put("CHOICE", Boolean.TRUE);
|
|
|
272 |
return rowVals;
|
|
|
273 |
}
|
|
|
274 |
};
|
|
|
275 |
}
|
|
|
276 |
|
|
|
277 |
@Override
|
|
|
278 |
protected String createCode() {
|
|
|
279 |
return createCodeFromPackage() + ".facturation";
|
|
|
280 |
}
|
|
|
281 |
|
|
|
282 |
}
|