18 |
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.injector;
|
|
|
15 |
|
73 |
ilm |
16 |
import java.math.BigDecimal;
|
|
|
17 |
import java.util.Collection;
|
|
|
18 |
|
18 |
ilm |
19 |
import org.openconcerto.sql.model.DBRoot;
|
|
|
20 |
import org.openconcerto.sql.model.SQLInjector;
|
73 |
ilm |
21 |
import org.openconcerto.sql.model.SQLRowAccessor;
|
|
|
22 |
import org.openconcerto.sql.model.SQLRowValues;
|
18 |
ilm |
23 |
import org.openconcerto.sql.model.SQLTable;
|
|
|
24 |
|
|
|
25 |
public class CommandeBrSQLInjector extends SQLInjector {
|
|
|
26 |
public CommandeBrSQLInjector(final DBRoot root) {
|
73 |
ilm |
27 |
super(root, "COMMANDE", "BON_RECEPTION", true);
|
18 |
ilm |
28 |
final SQLTable tableCmd = getSource();
|
|
|
29 |
final SQLTable tableBr = getDestination();
|
|
|
30 |
map(tableCmd.getField("ID_FOURNISSEUR"), tableBr.getField("ID_FOURNISSEUR"));
|
|
|
31 |
map(tableCmd.getField("NOM"), tableBr.getField("NOM"));
|
149 |
ilm |
32 |
if (tableCmd.contains("REMISE_HT")) {
|
|
|
33 |
map(tableCmd.getField("T_POIDS"), tableBr.getField("TOTAL_POIDS"));
|
|
|
34 |
map(tableCmd.getField("REMISE_HT"), tableBr.getField("REMISE_HT"));
|
|
|
35 |
map(tableCmd.getField("PORT_HT"), tableBr.getField("PORT_HT"));
|
|
|
36 |
map(tableCmd.getField("ID_TAXE_PORT"), tableBr.getField("ID_TAXE_PORT"));
|
|
|
37 |
}
|
18 |
ilm |
38 |
map(tableCmd.getField("INFOS"), tableBr.getField("INFOS"));
|
|
|
39 |
map(tableCmd.getField("ID"), tableBr.getField("ID_COMMANDE"));
|
93 |
ilm |
40 |
if (tableBr.contains("CREATE_VIRTUAL_STOCK")) {
|
|
|
41 |
mapDefaultValues(tableBr.getField("CREATE_VIRTUAL_STOCK"), Boolean.FALSE);
|
|
|
42 |
}
|
174 |
ilm |
43 |
if (getSource().contains("ID_AFFAIRE") && getDestination().contains("ID_AFFAIRE")) {
|
|
|
44 |
map(getSource().getField("ID_AFFAIRE"), getDestination().getField("ID_AFFAIRE"));
|
|
|
45 |
}
|
18 |
ilm |
46 |
}
|
73 |
ilm |
47 |
|
|
|
48 |
@Override
|
|
|
49 |
protected void merge(SQLRowAccessor srcRow, SQLRowValues rowVals) {
|
|
|
50 |
super.merge(srcRow, rowVals);
|
|
|
51 |
|
|
|
52 |
// Merge elements
|
|
|
53 |
final SQLTable tableElementSource = getSource().getTable("COMMANDE_ELEMENT");
|
|
|
54 |
final SQLTable tableElementDestination = getSource().getTable("BON_RECEPTION_ELEMENT");
|
|
|
55 |
final Collection<? extends SQLRowAccessor> myListItem = srcRow.asRow().getReferentRows(tableElementSource);
|
174 |
ilm |
56 |
transfertNumberReference(srcRow, rowVals, tableElementDestination, "ID_BON_RECEPTION");
|
73 |
ilm |
57 |
|
|
|
58 |
if (myListItem.size() != 0) {
|
|
|
59 |
final SQLInjector injector = SQLInjector.getInjector(tableElementSource, tableElementDestination);
|
|
|
60 |
for (SQLRowAccessor rowElt : myListItem) {
|
|
|
61 |
final SQLRowValues createRowValuesFrom = injector.createRowValuesFrom(rowElt.asRow());
|
149 |
ilm |
62 |
createRowValuesFrom.put("QTE_ORIGINE", createRowValuesFrom.getObject("QTE"));
|
73 |
ilm |
63 |
if (createRowValuesFrom.getTable().getFieldsName().contains("POURCENT_ACOMPTE")) {
|
|
|
64 |
if (createRowValuesFrom.getObject("POURCENT_ACOMPTE") == null) {
|
|
|
65 |
createRowValuesFrom.put("POURCENT_ACOMPTE", new BigDecimal(100.0));
|
|
|
66 |
}
|
|
|
67 |
}
|
|
|
68 |
createRowValuesFrom.put("ID_BON_RECEPTION", rowVals);
|
|
|
69 |
}
|
|
|
70 |
}
|
|
|
71 |
}
|
18 |
ilm |
72 |
}
|