OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 18 | Rev 83 | 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 DevisFactureSQLInjector extends SQLInjector {
26
    public DevisFactureSQLInjector(final DBRoot root) {
73 ilm 27
        super(root, "DEVIS", "SAISIE_VENTE_FACTURE", true);
18 ilm 28
        final SQLTable tableDevis = getSource();
29
        final SQLTable tableFacture = getDestination();
30
        map(tableDevis.getField("PORT_HT"), tableFacture.getField("PORT_HT"));
31
        map(tableDevis.getField("REMISE_HT"), tableFacture.getField("REMISE_HT"));
32
        map(tableDevis.getField("ID_CLIENT"), tableFacture.getField("ID_CLIENT"));
33
        map(tableDevis.getField("OBJET"), tableFacture.getField("NOM"));
34
        map(tableDevis.getField("ID_COMMERCIAL"), tableFacture.getField("ID_COMMERCIAL"));
73 ilm 35
        map(tableDevis.getField("ID_DEVIS"), tableFacture.getField("ID_DEVIS"));
18 ilm 36
        map(tableDevis.getField("INFOS"), tableFacture.getField("INFOS"));
37
    }
73 ilm 38
 
39
    @Override
40
    protected void merge(SQLRowAccessor srcRow, SQLRowValues rowVals) {
41
        super.merge(srcRow, rowVals);
42
 
43
        // Merge elements
44
        final SQLTable tableElementSource = getSource().getTable("DEVIS_ELEMENT");
45
        final SQLTable tableElementDestination = getSource().getTable("SAISIE_VENTE_FACTURE_ELEMENT");
46
        final Collection<? extends SQLRowAccessor> myListItem = srcRow.asRow().getReferentRows(tableElementSource);
47
 
48
        if (myListItem.size() != 0) {
49
            final SQLInjector injector = SQLInjector.getInjector(tableElementSource, tableElementDestination);
50
            for (SQLRowAccessor rowElt : myListItem) {
51
                final SQLRowValues createRowValuesFrom = injector.createRowValuesFrom(rowElt.asRow());
52
                if (createRowValuesFrom.getTable().getFieldsName().contains("POURCENT_ACOMPTE")) {
53
                    if (createRowValuesFrom.getObject("POURCENT_ACOMPTE") == null) {
54
                        createRowValuesFrom.put("POURCENT_ACOMPTE", new BigDecimal(100.0));
55
                    }
56
                }
57
                createRowValuesFrom.put("ID_SAISIE_VENTE_FACTURE", rowVals);
58
            }
59
        }
60
    }
18 ilm 61
}