18 |
ilm |
1 |
/*
|
|
|
2 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
|
|
|
3 |
*
|
182 |
ilm |
4 |
* Copyright 2011-2019 OpenConcerto, by ILM Informatique. All rights reserved.
|
18 |
ilm |
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 |
|
|
|
16 |
import org.openconcerto.sql.model.DBRoot;
|
|
|
17 |
import org.openconcerto.sql.model.SQLInjector;
|
73 |
ilm |
18 |
import org.openconcerto.sql.model.SQLRowAccessor;
|
|
|
19 |
import org.openconcerto.sql.model.SQLRowValues;
|
18 |
ilm |
20 |
import org.openconcerto.sql.model.SQLTable;
|
|
|
21 |
|
93 |
ilm |
22 |
import java.math.BigDecimal;
|
|
|
23 |
import java.util.Collection;
|
|
|
24 |
|
18 |
ilm |
25 |
public class CommandeBlSQLInjector extends SQLInjector {
|
|
|
26 |
public CommandeBlSQLInjector(final DBRoot root) {
|
73 |
ilm |
27 |
super(root, "COMMANDE_CLIENT", "BON_DE_LIVRAISON", true);
|
18 |
ilm |
28 |
final SQLTable tableCmd = getSource();
|
|
|
29 |
final SQLTable tableBl = getDestination();
|
|
|
30 |
map(tableCmd.getField("ID_CLIENT"), tableBl.getField("ID_CLIENT"));
|
|
|
31 |
map(tableCmd.getField("ID"), tableBl.getField("ID_COMMANDE_CLIENT"));
|
83 |
ilm |
32 |
if (tableCmd.getTable().contains("ID_POLE_PRODUIT") && tableBl.contains("ID_POLE_PRODUIT")) {
|
|
|
33 |
map(tableCmd.getField("ID_POLE_PRODUIT"), tableBl.getField("ID_POLE_PRODUIT"));
|
|
|
34 |
}
|
185 |
ilm |
35 |
if (tableCmd.contains("T_ACOMPTE") && tableBl.contains("T_ACOMPTE")) {
|
|
|
36 |
map(tableCmd.getField("T_ACOMPTE"), tableBl.getField("T_ACOMPTE"));
|
|
|
37 |
}
|
93 |
ilm |
38 |
if (getSource().getTable().contains("ID_CONTACT")) {
|
|
|
39 |
map(getSource().getField("ID_CONTACT"), getDestination().getField("ID_CONTACT"));
|
|
|
40 |
}
|
|
|
41 |
if (getSource().getTable().contains("ID_CLIENT_DEPARTEMENT")) {
|
|
|
42 |
map(getSource().getField("ID_CLIENT_DEPARTEMENT"), getDestination().getField("ID_CLIENT_DEPARTEMENT"));
|
|
|
43 |
}
|
132 |
ilm |
44 |
if (getSource().getTable().contains("ID_TARIF") && getDestination().getTable().contains("ID_TARIF")) {
|
|
|
45 |
map(getSource().getField("ID_TARIF"), getDestination().getField("ID_TARIF"));
|
|
|
46 |
}
|
142 |
ilm |
47 |
if (tableBl.contains("ACOMPTE_COMMANDE")) {
|
|
|
48 |
map(getSource().getField("ACOMPTE_COMMANDE"), getDestination().getField("ACOMPTE_COMMANDE"));
|
|
|
49 |
}
|
93 |
ilm |
50 |
if (tableBl.contains("CREATE_VIRTUAL_STOCK")) {
|
|
|
51 |
mapDefaultValues(tableBl.getField("CREATE_VIRTUAL_STOCK"), Boolean.FALSE);
|
|
|
52 |
}
|
|
|
53 |
|
|
|
54 |
if (tableBl.contains("ID_TAXE_PORT")) {
|
|
|
55 |
map(tableCmd.getField("ID_TAXE_PORT"), tableBl.getField("ID_TAXE_PORT"));
|
|
|
56 |
}
|
|
|
57 |
if (tableBl.contains("PORT_HT")) {
|
|
|
58 |
map(tableCmd.getField("PORT_HT"), tableBl.getField("PORT_HT"));
|
|
|
59 |
}
|
156 |
ilm |
60 |
if (getSource().contains("FRAIS_DOCUMENT_HT") && getDestination().contains("FRAIS_DOCUMENT_HT")) {
|
|
|
61 |
map(getSource().getField("FRAIS_DOCUMENT_HT"), getDestination().getField("FRAIS_DOCUMENT_HT"));
|
|
|
62 |
}
|
|
|
63 |
if (getSource().contains("ID_TAXE_FRAIS_DOCUMENT") && getDestination().contains("ID_TAXE_FRAIS_DOCUMENT")) {
|
|
|
64 |
map(getSource().getField("ID_TAXE_FRAIS_DOCUMENT"), getDestination().getField("ID_TAXE_FRAIS_DOCUMENT"));
|
|
|
65 |
}
|
93 |
ilm |
66 |
if (tableBl.contains("REMISE_HT")) {
|
|
|
67 |
map(tableCmd.getField("REMISE_HT"), tableBl.getField("REMISE_HT"));
|
|
|
68 |
}
|
142 |
ilm |
69 |
if (getSource().getTable().contains("ID_ADRESSE") && getDestination().contains("ID_ADRESSE")) {
|
|
|
70 |
map(getSource().getField("ID_ADRESSE"), getDestination().getField("ID_ADRESSE"));
|
|
|
71 |
}
|
|
|
72 |
if (getSource().getTable().contains("ID_ADRESSE_LIVRAISON")) {
|
|
|
73 |
map(getSource().getField("ID_ADRESSE_LIVRAISON"), getDestination().getField("ID_ADRESSE_LIVRAISON"));
|
|
|
74 |
}
|
174 |
ilm |
75 |
if (getSource().getTable().contains("ID_CATEGORIE_COMPTABLE") && getDestination().getTable().contains("ID_CATEGORIE_COMPTABLE")) {
|
|
|
76 |
map(getSource().getField("ID_CATEGORIE_COMPTABLE"), getDestination().getField("ID_CATEGORIE_COMPTABLE"));
|
|
|
77 |
}
|
182 |
ilm |
78 |
if (getSource().contains("ID_COMMERCIAL") && getDestination().contains("ID_COMMERCIAL")) {
|
|
|
79 |
map(getSource().getField("ID_COMMERCIAL"), getDestination().getField("ID_COMMERCIAL"));
|
|
|
80 |
}
|
18 |
ilm |
81 |
}
|
73 |
ilm |
82 |
|
|
|
83 |
@Override
|
|
|
84 |
protected void merge(SQLRowAccessor srcRow, SQLRowValues rowVals) {
|
|
|
85 |
super.merge(srcRow, rowVals);
|
|
|
86 |
|
|
|
87 |
// Merge elements
|
|
|
88 |
final SQLTable tableElementSource = getSource().getTable("COMMANDE_CLIENT_ELEMENT");
|
|
|
89 |
final SQLTable tableElementDestination = getSource().getTable("BON_DE_LIVRAISON_ELEMENT");
|
|
|
90 |
final Collection<? extends SQLRowAccessor> myListItem = srcRow.asRow().getReferentRows(tableElementSource);
|
|
|
91 |
|
83 |
ilm |
92 |
transfertNumberReference(srcRow, rowVals, tableElementDestination, "ID_BON_DE_LIVRAISON");
|
174 |
ilm |
93 |
transfertReference(srcRow, rowVals, tableElementDestination, "ID_BON_DE_LIVRAISON", "NOM", "NOM");
|
|
|
94 |
transfertReference(srcRow, rowVals, tableElementDestination, "ID_BON_DE_LIVRAISON", "INFOS", "INFOS");
|
83 |
ilm |
95 |
|
73 |
ilm |
96 |
if (myListItem.size() != 0) {
|
|
|
97 |
final SQLInjector injector = SQLInjector.getInjector(tableElementSource, tableElementDestination);
|
|
|
98 |
for (SQLRowAccessor rowElt : myListItem) {
|
|
|
99 |
final SQLRowValues createRowValuesFrom = injector.createRowValuesFrom(rowElt.asRow());
|
|
|
100 |
if (createRowValuesFrom.getTable().getFieldsName().contains("POURCENT_ACOMPTE")) {
|
|
|
101 |
if (createRowValuesFrom.getObject("POURCENT_ACOMPTE") == null) {
|
|
|
102 |
createRowValuesFrom.put("POURCENT_ACOMPTE", new BigDecimal(100.0));
|
|
|
103 |
}
|
|
|
104 |
}
|
|
|
105 |
createRowValuesFrom.put("ID_BON_DE_LIVRAISON", rowVals);
|
|
|
106 |
}
|
|
|
107 |
}
|
|
|
108 |
}
|
18 |
ilm |
109 |
}
|