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 |
|
|
|
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 |
|
73 |
ilm |
22 |
import java.math.BigDecimal;
|
|
|
23 |
import java.util.Collection;
|
|
|
24 |
|
18 |
ilm |
25 |
public class CommandeFactureClientSQLInjector extends SQLInjector {
|
|
|
26 |
public CommandeFactureClientSQLInjector(final DBRoot root) {
|
73 |
ilm |
27 |
super(root, "COMMANDE_CLIENT", "SAISIE_VENTE_FACTURE", true);
|
18 |
ilm |
28 |
final SQLTable tableCommande = getSource();
|
|
|
29 |
final SQLTable tableFacture = getDestination();
|
|
|
30 |
map(tableCommande.getField("ID_CLIENT"), tableFacture.getField("ID_CLIENT"));
|
93 |
ilm |
31 |
if (tableCommande.contains("ID_TAXE_PORT")) {
|
|
|
32 |
map(tableCommande.getField("ID_TAXE_PORT"), tableFacture.getField("ID_TAXE_PORT"));
|
|
|
33 |
}
|
|
|
34 |
if (tableCommande.contains("PORT_HT")) {
|
|
|
35 |
map(tableCommande.getField("PORT_HT"), tableFacture.getField("PORT_HT"));
|
|
|
36 |
}
|
|
|
37 |
if (tableCommande.contains("REMISE_HT")) {
|
|
|
38 |
map(tableCommande.getField("REMISE_HT"), tableFacture.getField("REMISE_HT"));
|
|
|
39 |
}
|
83 |
ilm |
40 |
if (tableCommande.getTable().contains("ID_POLE_PRODUIT")) {
|
|
|
41 |
map(tableCommande.getField("ID_POLE_PRODUIT"), tableFacture.getField("ID_POLE_PRODUIT"));
|
|
|
42 |
}
|
93 |
ilm |
43 |
|
|
|
44 |
if (getSource().getTable().contains("ID_CONTACT")) {
|
|
|
45 |
map(getSource().getField("ID_CONTACT"), getDestination().getField("ID_CONTACT"));
|
|
|
46 |
}
|
|
|
47 |
if (getSource().getTable().contains("ID_CLIENT_DEPARTEMENT")) {
|
|
|
48 |
map(getSource().getField("ID_CLIENT_DEPARTEMENT"), getDestination().getField("ID_CLIENT_DEPARTEMENT"));
|
|
|
49 |
}
|
|
|
50 |
if (getSource().getTable().contains("ID_ADRESSE") && getDestination().contains("ID_ADRESSE")) {
|
|
|
51 |
map(getSource().getField("ID_ADRESSE"), getDestination().getField("ID_ADRESSE"));
|
|
|
52 |
}
|
|
|
53 |
if (getSource().getTable().contains("ID_ADRESSE_LIVRAISON")) {
|
|
|
54 |
map(getSource().getField("ID_ADRESSE_LIVRAISON"), getDestination().getField("ID_ADRESSE_LIVRAISON"));
|
|
|
55 |
}
|
|
|
56 |
|
|
|
57 |
if (getSource().getTable().contains("MONTANT_REMISE") && getDestination().contains("MONTANT_REMISE")) {
|
|
|
58 |
map(getSource().getField("MONTANT_REMISE"), getDestination().getField("MONTANT_REMISE"));
|
|
|
59 |
map(getSource().getField("POURCENT_REMISE"), getDestination().getField("POURCENT_REMISE"));
|
|
|
60 |
}
|
|
|
61 |
|
|
|
62 |
if (tableFacture.contains("CREATE_VIRTUAL_STOCK")) {
|
|
|
63 |
mapDefaultValues(tableFacture.getField("CREATE_VIRTUAL_STOCK"), Boolean.FALSE);
|
|
|
64 |
}
|
|
|
65 |
|
18 |
ilm |
66 |
}
|
73 |
ilm |
67 |
|
|
|
68 |
@Override
|
|
|
69 |
protected void merge(SQLRowAccessor srcRow, SQLRowValues rowVals) {
|
|
|
70 |
super.merge(srcRow, rowVals);
|
|
|
71 |
|
|
|
72 |
// Merge elements
|
|
|
73 |
final SQLTable tableElementSource = getSource().getTable("COMMANDE_CLIENT_ELEMENT");
|
|
|
74 |
final SQLTable tableElementDestination = getSource().getTable("SAISIE_VENTE_FACTURE_ELEMENT");
|
|
|
75 |
final Collection<? extends SQLRowAccessor> myListItem = srcRow.asRow().getReferentRows(tableElementSource);
|
83 |
ilm |
76 |
transfertReference(srcRow, rowVals, "NOM", "NOM");
|
|
|
77 |
transfertReference(srcRow, rowVals, "INFOS", "INFOS");
|
|
|
78 |
transfertNumberReference(srcRow, rowVals, tableElementDestination, "ID_SAISIE_VENTE_FACTURE");
|
73 |
ilm |
79 |
if (myListItem.size() != 0) {
|
|
|
80 |
final SQLInjector injector = SQLInjector.getInjector(tableElementSource, tableElementDestination);
|
|
|
81 |
for (SQLRowAccessor rowElt : myListItem) {
|
|
|
82 |
System.err.println("CommandeFactureClientSQLInjector.merge():" + rowElt);
|
|
|
83 |
final SQLRowValues createRowValuesFrom = injector.createRowValuesFrom(rowElt.asRow());
|
|
|
84 |
if (createRowValuesFrom.getTable().getFieldsName().contains("POURCENT_ACOMPTE")) {
|
|
|
85 |
if (createRowValuesFrom.getObject("POURCENT_ACOMPTE") == null) {
|
|
|
86 |
createRowValuesFrom.put("POURCENT_ACOMPTE", new BigDecimal(100.0));
|
|
|
87 |
}
|
|
|
88 |
}
|
|
|
89 |
createRowValuesFrom.put("ID_SAISIE_VENTE_FACTURE", rowVals);
|
|
|
90 |
}
|
|
|
91 |
}
|
|
|
92 |
}
|
|
|
93 |
|
18 |
ilm |
94 |
}
|