OpenConcerto

Dépôt officiel du code source de l'ERP OpenConcerto
sonarqube

svn://code.openconcerto.org/openconcerto

Rev

Rev 156 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
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
 
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
        }
93 ilm 35
        if (getSource().getTable().contains("ID_CONTACT")) {
36
            map(getSource().getField("ID_CONTACT"), getDestination().getField("ID_CONTACT"));
37
        }
38
        if (getSource().getTable().contains("ID_CLIENT_DEPARTEMENT")) {
39
            map(getSource().getField("ID_CLIENT_DEPARTEMENT"), getDestination().getField("ID_CLIENT_DEPARTEMENT"));
40
        }
132 ilm 41
        if (getSource().getTable().contains("ID_TARIF") && getDestination().getTable().contains("ID_TARIF")) {
42
            map(getSource().getField("ID_TARIF"), getDestination().getField("ID_TARIF"));
43
        }
142 ilm 44
        if (tableBl.contains("ACOMPTE_COMMANDE")) {
45
            map(getSource().getField("ACOMPTE_COMMANDE"), getDestination().getField("ACOMPTE_COMMANDE"));
46
        }
93 ilm 47
        if (tableBl.contains("CREATE_VIRTUAL_STOCK")) {
48
            mapDefaultValues(tableBl.getField("CREATE_VIRTUAL_STOCK"), Boolean.FALSE);
49
        }
50
 
51
        if (tableBl.contains("ID_TAXE_PORT")) {
52
            map(tableCmd.getField("ID_TAXE_PORT"), tableBl.getField("ID_TAXE_PORT"));
53
        }
54
        if (tableBl.contains("PORT_HT")) {
55
            map(tableCmd.getField("PORT_HT"), tableBl.getField("PORT_HT"));
56
        }
156 ilm 57
        if (getSource().contains("FRAIS_DOCUMENT_HT") && getDestination().contains("FRAIS_DOCUMENT_HT")) {
58
            map(getSource().getField("FRAIS_DOCUMENT_HT"), getDestination().getField("FRAIS_DOCUMENT_HT"));
59
        }
60
        if (getSource().contains("ID_TAXE_FRAIS_DOCUMENT") && getDestination().contains("ID_TAXE_FRAIS_DOCUMENT")) {
61
            map(getSource().getField("ID_TAXE_FRAIS_DOCUMENT"), getDestination().getField("ID_TAXE_FRAIS_DOCUMENT"));
62
        }
93 ilm 63
        if (tableBl.contains("REMISE_HT")) {
64
            map(tableCmd.getField("REMISE_HT"), tableBl.getField("REMISE_HT"));
65
        }
142 ilm 66
        if (getSource().getTable().contains("ID_ADRESSE") && getDestination().contains("ID_ADRESSE")) {
67
            map(getSource().getField("ID_ADRESSE"), getDestination().getField("ID_ADRESSE"));
68
        }
69
        if (getSource().getTable().contains("ID_ADRESSE_LIVRAISON")) {
70
            map(getSource().getField("ID_ADRESSE_LIVRAISON"), getDestination().getField("ID_ADRESSE_LIVRAISON"));
71
        }
174 ilm 72
        if (getSource().getTable().contains("ID_CATEGORIE_COMPTABLE") && getDestination().getTable().contains("ID_CATEGORIE_COMPTABLE")) {
73
            map(getSource().getField("ID_CATEGORIE_COMPTABLE"), getDestination().getField("ID_CATEGORIE_COMPTABLE"));
74
        }
18 ilm 75
    }
73 ilm 76
 
77
    @Override
78
    protected void merge(SQLRowAccessor srcRow, SQLRowValues rowVals) {
79
        super.merge(srcRow, rowVals);
80
 
81
        // Merge elements
82
        final SQLTable tableElementSource = getSource().getTable("COMMANDE_CLIENT_ELEMENT");
83
        final SQLTable tableElementDestination = getSource().getTable("BON_DE_LIVRAISON_ELEMENT");
84
        final Collection<? extends SQLRowAccessor> myListItem = srcRow.asRow().getReferentRows(tableElementSource);
85
 
83 ilm 86
        transfertNumberReference(srcRow, rowVals, tableElementDestination, "ID_BON_DE_LIVRAISON");
174 ilm 87
        transfertReference(srcRow, rowVals, tableElementDestination, "ID_BON_DE_LIVRAISON", "NOM", "NOM");
88
        transfertReference(srcRow, rowVals, tableElementDestination, "ID_BON_DE_LIVRAISON", "INFOS", "INFOS");
83 ilm 89
 
73 ilm 90
        if (myListItem.size() != 0) {
91
            final SQLInjector injector = SQLInjector.getInjector(tableElementSource, tableElementDestination);
92
            for (SQLRowAccessor rowElt : myListItem) {
93
                final SQLRowValues createRowValuesFrom = injector.createRowValuesFrom(rowElt.asRow());
94
                if (createRowValuesFrom.getTable().getFieldsName().contains("POURCENT_ACOMPTE")) {
95
                    if (createRowValuesFrom.getObject("POURCENT_ACOMPTE") == null) {
96
                        createRowValuesFrom.put("POURCENT_ACOMPTE", new BigDecimal(100.0));
97
                    }
98
                }
99
                createRowValuesFrom.put("ID_BON_DE_LIVRAISON", rowVals);
100
            }
101
        }
102
    }
18 ilm 103
}