OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 73 | Rev 93 | Go to most recent revision | 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
        }
19 ilm 36
    }
73 ilm 37
 
38
    @Override
39
    protected void merge(SQLRowAccessor srcRow, SQLRowValues rowVals) {
40
        super.merge(srcRow, rowVals);
41
 
42
        // Merge elements
43
        final SQLTable tableElementSource = getSource().getTable("SAISIE_VENTE_FACTURE_ELEMENT");
44
        final SQLTable tableElementDestination = getSource().getTable("BON_DE_LIVRAISON_ELEMENT");
45
        final Collection<? extends SQLRowAccessor> myListItem = srcRow.asRow().getReferentRows(tableElementSource);
83 ilm 46
        transfertReference(srcRow, rowVals, "NOM", "NOM");
47
        transfertReference(srcRow, rowVals, "INFOS", "INFOS");
48
        transfertNumberReference(srcRow, rowVals, tableElementDestination, "ID_BON_DE_LIVRAISON");
73 ilm 49
 
50
        if (myListItem.size() != 0) {
51
            final SQLInjector injector = SQLInjector.getInjector(tableElementSource, tableElementDestination);
52
            for (SQLRowAccessor rowElt : myListItem) {
53
                final SQLRowValues createRowValuesFrom = injector.createRowValuesFrom(rowElt.asRow());
54
                if (createRowValuesFrom.getTable().getFieldsName().contains("POURCENT_ACOMPTE")) {
55
                    if (createRowValuesFrom.getObject("POURCENT_ACOMPTE") == null) {
56
                        createRowValuesFrom.put("POURCENT_ACOMPTE", new BigDecimal(100.0));
57
                    }
58
                }
59
                createRowValuesFrom.put("ID_BON_DE_LIVRAISON", rowVals);
60
            }
61
        }
62
    }
19 ilm 63
}