OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

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

Rev Author Line No. Line
94 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;
18
import org.openconcerto.sql.model.SQLRowAccessor;
19
import org.openconcerto.sql.model.SQLRowValues;
20
import org.openconcerto.sql.model.SQLTable;
21
 
22
import java.math.BigDecimal;
23
import java.util.Collection;
24
 
25
public class BonReceptionFactureFournisseurSQLInjector extends SQLInjector {
26
    public BonReceptionFactureFournisseurSQLInjector(final DBRoot root) {
27
        super(root, "BON_RECEPTION", "FACTURE_FOURNISSEUR", true);
28
        map(getSource().getField("ID_FOURNISSEUR"), getDestination().getField("ID_FOURNISSEUR"));
29
        map(getSource().getField("NOM"), getDestination().getField("NOM"));
30
        map(getSource().getField("INFOS"), getDestination().getField("INFOS"));
149 ilm 31
        if (getSource().contains("REMISE_HT")) {
32
            map(getSource().getField("TOTAL_POIDS"), getDestination().getField("T_POIDS"));
33
            map(getSource().getField("REMISE_HT"), getDestination().getField("REMISE_HT"));
34
            map(getSource().getField("PORT_HT"), getDestination().getField("PORT_HT"));
35
            map(getSource().getField("ID_TAXE_PORT"), getDestination().getField("ID_TAXE_PORT"));
36
        }
174 ilm 37
        if (getSource().contains("ID_AFFAIRE") && getDestination().contains("ID_AFFAIRE")) {
38
            map(getSource().getField("ID_AFFAIRE"), getDestination().getField("ID_AFFAIRE"));
39
        }
40
        if (getSource().contains("ID_POLE_PRODUIT") && getDestination().contains("ID_POLE_PRODUIT")) {
41
            map(getSource().getField("ID_POLE_PRODUIT"), getDestination().getField("ID_POLE_PRODUIT"));
42
        }
94 ilm 43
    }
44
 
45
    @Override
46
    protected void merge(SQLRowAccessor srcRow, SQLRowValues rowVals) {
47
        super.merge(srcRow, rowVals);
48
 
49
        // Merge elements
50
        final SQLTable tableElementSource = getSource().getTable("BON_RECEPTION_ELEMENT");
51
        final SQLTable tableElementDestination = getSource().getTable("FACTURE_FOURNISSEUR_ELEMENT");
52
        final Collection<? extends SQLRowAccessor> myListItem = srcRow.asRow().getReferentRows(tableElementSource);
53
        transfertNumberReference(srcRow, rowVals, tableElementDestination, "ID_FACTURE_FOURNISSEUR");
174 ilm 54
        transfertReference(srcRow, rowVals, tableElementDestination, "ID_FACTURE_FOURNISSEUR", "NOM", "NOM");
55
        transfertReference(srcRow, rowVals, tableElementDestination, "ID_FACTURE_FOURNISSEUR", "INFOS", "INFOS");
94 ilm 56
        if (myListItem.size() != 0) {
57
            final SQLInjector injector = SQLInjector.getInjector(tableElementSource, tableElementDestination);
58
            for (SQLRowAccessor rowElt : myListItem) {
59
                final SQLRowValues createRowValuesFrom = injector.createRowValuesFrom(rowElt.asRow());
60
                if (createRowValuesFrom.getTable().getFieldsName().contains("POURCENT_ACOMPTE")) {
61
                    if (createRowValuesFrom.getObject("POURCENT_ACOMPTE") == null) {
62
                        createRowValuesFrom.put("POURCENT_ACOMPTE", new BigDecimal(100.0));
63
                    }
64
                }
65
                createRowValuesFrom.put("ID_FACTURE_FOURNISSEUR", rowVals);
66
            }
67
        }
68
    }
69
 
70
}