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
 
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 DevisCommandeSQLInjector extends SQLInjector {
26
    public DevisCommandeSQLInjector(final DBRoot root) {
73 ilm 27
        super(root, "DEVIS", "COMMANDE_CLIENT", true);
18 ilm 28
        final SQLTable tableDevis = getSource();
29
        final SQLTable tableCommande = getDestination();
30
        map(tableDevis.getField("ID_CLIENT"), tableCommande.getField("ID_CLIENT"));
132 ilm 31
        if (tableDevis.contains("REMISE_HT") && tableCommande.contains("REMISE_HT")) {
32
            map(tableDevis.getField("REMISE_HT"), tableCommande.getField("REMISE_HT"));
33
        }
34
        if (tableDevis.contains("PORT_HT") && tableCommande.contains("PORT_HT")) {
35
            map(tableDevis.getField("PORT_HT"), tableCommande.getField("PORT_HT"));
36
        }
156 ilm 37
 
38
        if (getSource().contains("FRAIS_DOCUMENT_HT") && getDestination().contains("FRAIS_DOCUMENT_HT")) {
39
            map(getSource().getField("FRAIS_DOCUMENT_HT"), getDestination().getField("FRAIS_DOCUMENT_HT"));
40
        }
41
        if (getSource().contains("ID_TAXE_FRAIS_DOCUMENT") && getDestination().contains("ID_TAXE_FRAIS_DOCUMENT")) {
42
            map(getSource().getField("ID_TAXE_FRAIS_DOCUMENT"), getDestination().getField("ID_TAXE_FRAIS_DOCUMENT"));
43
        }
19 ilm 44
        mapDefaultValues(tableCommande.getField("SOURCE"), tableDevis.getName());
18 ilm 45
        map(tableDevis.getField("ID_DEVIS"), tableCommande.getField("IDSOURCE"));
46
        map(tableDevis.getField("ID_DEVIS"), tableCommande.getField("ID_DEVIS"));
47
        map(tableDevis.getField("ID_COMMERCIAL"), tableCommande.getField("ID_COMMERCIAL"));
83 ilm 48
        if (tableDevis.getTable().contains("ID_POLE_PRODUIT")) {
49
            map(tableDevis.getField("ID_POLE_PRODUIT"), tableCommande.getField("ID_POLE_PRODUIT"));
50
        }
132 ilm 51
        if (tableDevis.getTable().contains("ID_TARIF") && tableCommande.getTable().contains("ID_TARIF")) {
52
            map(tableDevis.getField("ID_TARIF"), tableCommande.getField("ID_TARIF"));
53
        }
93 ilm 54
        if (getSource().getTable().contains("ID_CONTACT")) {
55
            map(tableDevis.getField("ID_CONTACT"), tableCommande.getField("ID_CONTACT"));
56
        }
57
        if (getSource().getTable().contains("ID_CLIENT_DEPARTEMENT")) {
58
            map(getSource().getField("ID_CLIENT_DEPARTEMENT"), getDestination().getField("ID_CLIENT_DEPARTEMENT"));
59
        }
60
        if (getSource().getTable().contains("ID_ADRESSE") && getDestination().contains("ID_ADRESSE")) {
61
            map(tableDevis.getField("ID_ADRESSE"), getDestination().getField("ID_ADRESSE"));
62
        }
63
        if (getSource().getTable().contains("ID_ADRESSE_LIVRAISON")) {
64
            map(tableDevis.getField("ID_ADRESSE_LIVRAISON"), getDestination().getField("ID_ADRESSE_LIVRAISON"));
65
        }
66
 
67
        if (getSource().getTable().contains("MONTANT_REMISE") && getDestination().contains("MONTANT_REMISE")) {
68
            map(tableDevis.getField("MONTANT_REMISE"), getDestination().getField("MONTANT_REMISE"));
69
            map(tableDevis.getField("POURCENT_REMISE"), getDestination().getField("POURCENT_REMISE"));
70
        }
174 ilm 71
        if (getSource().getTable().contains("ID_CATEGORIE_COMPTABLE") && getDestination().getTable().contains("ID_CATEGORIE_COMPTABLE")) {
72
            map(getSource().getField("ID_CATEGORIE_COMPTABLE"), getDestination().getField("ID_CATEGORIE_COMPTABLE"));
73
        }
18 ilm 74
    }
83 ilm 75
 
73 ilm 76
    @Override
77
    protected void merge(SQLRowAccessor srcRow, SQLRowValues rowVals) {
78
        super.merge(srcRow, rowVals);
79
 
80
        // Merge elements
81
        final SQLTable tableElementSource = getSource().getTable("DEVIS_ELEMENT");
82
        final SQLTable tableElementDestination = getSource().getTable("COMMANDE_CLIENT_ELEMENT");
83
        final Collection<? extends SQLRowAccessor> myListItem = srcRow.asRow().getReferentRows(tableElementSource);
83 ilm 84
        transfertNumberReference(srcRow, rowVals, tableElementDestination, "ID_COMMANDE_CLIENT");
174 ilm 85
        transfertReference(srcRow, rowVals, tableElementDestination, "ID_COMMANDE_CLIENT", "OBJET", "NOM");
86
        transfertReference(srcRow, rowVals, tableElementDestination, "ID_COMMANDE_CLIENT", "INFOS", "INFOS");
73 ilm 87
 
88
        if (myListItem.size() != 0) {
89
            final SQLInjector injector = SQLInjector.getInjector(tableElementSource, tableElementDestination);
90
            for (SQLRowAccessor rowElt : myListItem) {
91
                final SQLRowValues createRowValuesFrom = injector.createRowValuesFrom(rowElt.asRow());
92
                if (createRowValuesFrom.getTable().getFieldsName().contains("POURCENT_ACOMPTE")) {
93
                    if (createRowValuesFrom.getObject("POURCENT_ACOMPTE") == null) {
94
                        createRowValuesFrom.put("POURCENT_ACOMPTE", new BigDecimal(100.0));
95
                    }
96
                }
97
                createRowValuesFrom.put("ID_COMMANDE_CLIENT", rowVals);
98
            }
99
        }
100
    }
18 ilm 101
}