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