OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

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

Rev Author Line No. Line
19 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
 
19 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;
19 ilm 23
import org.openconcerto.sql.model.SQLTable;
24
 
25
public class FactureBonSQLInjector extends SQLInjector {
26
    public FactureBonSQLInjector(final DBRoot root) {
73 ilm 27
        super(root, "SAISIE_VENTE_FACTURE", "BON_DE_LIVRAISON", true);
19 ilm 28
        final SQLTable tableFacture = getSource();
29
        final SQLTable tableBon = getDestination();
30
        map(tableFacture.getField("ID_CLIENT"), tableBon.getField("ID_CLIENT"));
31
        mapDefaultValues(tableBon.getField("SOURCE"), tableFacture.getName());
32
        map(tableFacture.getKey(), tableBon.getField("IDSOURCE"));
83 ilm 33
        if (tableFacture.contains("ID_POLE_PRODUIT") && tableBon.contains("ID_POLE_PRODUIT")) {
34
            map(tableFacture.getField("ID_POLE_PRODUIT"), tableBon.getField("ID_POLE_PRODUIT"));
35
        }
93 ilm 36
        if (getSource().getTable().contains("ID_CONTACT") && getDestination().getTable().contains("ID_CONTACT")) {
37
            map(getSource().getField("ID_CONTACT"), getDestination().getField("ID_CONTACT"));
38
        }
39
        if (getSource().getTable().contains("ID_CLIENT_DEPARTEMENT")) {
40
            map(getSource().getField("ID_CLIENT_DEPARTEMENT"), getDestination().getField("ID_CLIENT_DEPARTEMENT"));
41
        }
19 ilm 42
    }
73 ilm 43
 
44
    @Override
45
    protected void merge(SQLRowAccessor srcRow, SQLRowValues rowVals) {
46
        super.merge(srcRow, rowVals);
47
 
48
        // Merge elements
49
        final SQLTable tableElementSource = getSource().getTable("SAISIE_VENTE_FACTURE_ELEMENT");
50
        final SQLTable tableElementDestination = getSource().getTable("BON_DE_LIVRAISON_ELEMENT");
51
        final Collection<? extends SQLRowAccessor> myListItem = srcRow.asRow().getReferentRows(tableElementSource);
83 ilm 52
        transfertNumberReference(srcRow, rowVals, tableElementDestination, "ID_BON_DE_LIVRAISON");
174 ilm 53
        transfertReference(srcRow, rowVals, tableElementDestination, "ID_BON_DE_LIVRAISON", "NOM", "NOM");
54
        transfertReference(srcRow, rowVals, tableElementDestination, "ID_BON_DE_LIVRAISON", "INFOS", "INFOS");
73 ilm 55
 
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_BON_DE_LIVRAISON", rowVals);
66
            }
67
        }
68
    }
19 ilm 69
}