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 DevisBlSQLInjector extends SQLInjector {
26
    public DevisBlSQLInjector(final DBRoot root) {
73 ilm 27
        super(root, "DEVIS", "BON_DE_LIVRAISON", true);
18 ilm 28
        final SQLTable tableDevis = getSource();
29
        final SQLTable tableBon = getDestination();
30
        map(tableDevis.getField("ID_CLIENT"), tableBon.getField("ID_CLIENT"));
93 ilm 31
        if (getSource().getTable().contains("ID_CONTACT")) {
32
            map(tableDevis.getField("ID_CONTACT"), tableBon.getField("ID_CONTACT"));
33
        }
18 ilm 34
        mapDefaultValues(tableBon.getField("SOURCE"), tableBon.getName());
35
        map(tableDevis.getField("ID_DEVIS"), tableBon.getField("IDSOURCE"));
156 ilm 36
        if (tableDevis.getTable().contains("ID_POLE_PRODUIT") && tableBon.getTable().contains("ID_POLE_PRODUIT")) {
83 ilm 37
            map(tableDevis.getField("ID_POLE_PRODUIT"), tableBon.getField("ID_POLE_PRODUIT"));
38
        }
93 ilm 39
        if (getSource().getTable().contains("ID_CLIENT_DEPARTEMENT")) {
40
            map(getSource().getField("ID_CLIENT_DEPARTEMENT"), getDestination().getField("ID_CLIENT_DEPARTEMENT"));
41
        }
142 ilm 42
        if (getSource().getTable().contains("ID_ADRESSE") && getDestination().contains("ID_ADRESSE")) {
43
            map(getSource().getField("ID_ADRESSE"), getDestination().getField("ID_ADRESSE"));
44
        }
45
        if (getSource().getTable().contains("ID_ADRESSE_LIVRAISON")) {
46
            map(getSource().getField("ID_ADRESSE_LIVRAISON"), getDestination().getField("ID_ADRESSE_LIVRAISON"));
47
        }
174 ilm 48
        if (getSource().getTable().contains("ID_CATEGORIE_COMPTABLE") && getDestination().getTable().contains("ID_CATEGORIE_COMPTABLE")) {
49
            map(getSource().getField("ID_CATEGORIE_COMPTABLE"), getDestination().getField("ID_CATEGORIE_COMPTABLE"));
50
        }
18 ilm 51
    }
83 ilm 52
 
73 ilm 53
    @Override
54
    protected void merge(SQLRowAccessor srcRow, SQLRowValues rowVals) {
55
        super.merge(srcRow, rowVals);
56
 
57
        // Merge elements
58
        final SQLTable tableElementSource = getSource().getTable("DEVIS_ELEMENT");
59
        final SQLTable tableElementDestination = getSource().getTable("BON_DE_LIVRAISON_ELEMENT");
60
        final Collection<? extends SQLRowAccessor> myListItem = srcRow.asRow().getReferentRows(tableElementSource);
83 ilm 61
        transfertNumberReference(srcRow, rowVals, tableElementDestination, "ID_BON_DE_LIVRAISON");
174 ilm 62
        transfertReference(srcRow, rowVals, tableElementDestination, "ID_BON_DE_LIVRAISON", "NOM", "NOM");
63
        transfertReference(srcRow, rowVals, tableElementDestination, "ID_BON_DE_LIVRAISON", "INFOS", "INFOS");
73 ilm 64
 
65
        if (myListItem.size() != 0) {
66
            final SQLInjector injector = SQLInjector.getInjector(tableElementSource, tableElementDestination);
67
            for (SQLRowAccessor rowElt : myListItem) {
68
                final SQLRowValues createRowValuesFrom = injector.createRowValuesFrom(rowElt.asRow());
69
                if (createRowValuesFrom.getTable().getFieldsName().contains("POURCENT_ACOMPTE")) {
70
                    if (createRowValuesFrom.getObject("POURCENT_ACOMPTE") == null) {
71
                        createRowValuesFrom.put("POURCENT_ACOMPTE", new BigDecimal(100.0));
72
                    }
73
                }
74
                createRowValuesFrom.put("ID_BON_DE_LIVRAISON", rowVals);
75
            }
76
        }
77
    }
18 ilm 78
}