OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 142 | Go to most recent revision | 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
        }
18 ilm 48
    }
83 ilm 49
 
73 ilm 50
    @Override
51
    protected void merge(SQLRowAccessor srcRow, SQLRowValues rowVals) {
52
        super.merge(srcRow, rowVals);
53
 
54
        // Merge elements
55
        final SQLTable tableElementSource = getSource().getTable("DEVIS_ELEMENT");
56
        final SQLTable tableElementDestination = getSource().getTable("BON_DE_LIVRAISON_ELEMENT");
57
        final Collection<? extends SQLRowAccessor> myListItem = srcRow.asRow().getReferentRows(tableElementSource);
83 ilm 58
        transfertReference(srcRow, rowVals, "NOM", "NOM");
59
        transfertReference(srcRow, rowVals, "INFOS", "INFOS");
60
        transfertNumberReference(srcRow, rowVals, tableElementDestination, "ID_BON_DE_LIVRAISON");
73 ilm 61
 
62
        if (myListItem.size() != 0) {
63
            final SQLInjector injector = SQLInjector.getInjector(tableElementSource, tableElementDestination);
64
            for (SQLRowAccessor rowElt : myListItem) {
65
                final SQLRowValues createRowValuesFrom = injector.createRowValuesFrom(rowElt.asRow());
66
                if (createRowValuesFrom.getTable().getFieldsName().contains("POURCENT_ACOMPTE")) {
67
                    if (createRowValuesFrom.getObject("POURCENT_ACOMPTE") == null) {
68
                        createRowValuesFrom.put("POURCENT_ACOMPTE", new BigDecimal(100.0));
69
                    }
70
                }
71
                createRowValuesFrom.put("ID_BON_DE_LIVRAISON", rowVals);
72
            }
73
        }
74
    }
18 ilm 75
}