OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 132 | 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 FactureAvoirSQLInjector extends SQLInjector {
26
    public FactureAvoirSQLInjector(final DBRoot root) {
73 ilm 27
        super(root, "SAISIE_VENTE_FACTURE", "AVOIR_CLIENT", true);
18 ilm 28
        final SQLTable tableFacture = getSource();
29
        final SQLTable tableAvoir = getDestination();
30
        map(tableFacture.getField("ID_CLIENT"), tableAvoir.getField("ID_CLIENT"));
31
        map(tableFacture.getField("ID_ADRESSE"), tableAvoir.getField("ID_ADRESSE"));
32
        map(tableFacture.getField("ID_COMMERCIAL"), tableAvoir.getField("ID_COMMERCIAL"));
33
        map(tableFacture.getField("REMISE_HT"), tableAvoir.getField("REMISE_HT"));
34
        map(tableFacture.getField("PORT_HT"), tableAvoir.getField("PORT_HT"));
93 ilm 35
        if (getSource().getTable().contains("ID_CONTACT")) {
36
            map(getSource().getField("ID_CONTACT"), getDestination().getField("ID_CONTACT"));
37
        }
73 ilm 38
 
93 ilm 39
        if (getSource().contains("ID_ADRESSE") && getDestination().contains("ID_ADRESSE")) {
40
            map(getSource().getField("ID_ADRESSE"), getDestination().getField("ID_ADRESSE"));
41
        }
42
 
43
        if (getSource().contains("ID_ADRESSE_LIVRAISON") && getDestination().contains("ID_ADRESSE_LIVRAISON")) {
44
            map(getSource().getField("ID_ADRESSE_LIVRAISON"), getDestination().getField("ID_ADRESSE_LIVRAISON"));
45
        }
174 ilm 46
        if (getSource().getTable().contains("ID_CATEGORIE_COMPTABLE") && getDestination().getTable().contains("ID_CATEGORIE_COMPTABLE")) {
47
            map(getSource().getField("ID_CATEGORIE_COMPTABLE"), getDestination().getField("ID_CATEGORIE_COMPTABLE"));
48
        }
93 ilm 49
        if (getSource().getTable().contains("DATE_LIVRAISON") && getDestination().contains("DATE_LIVRAISON")) {
50
            map(getSource().getField("DATE_LIVRAISON"), getDestination().getField("DATE_LIVRAISON"));
51
        }
52
 
53
        if (getSource().getTable().contains("ID_CLIENT_DEPARTEMENT")) {
54
            map(getSource().getField("ID_CLIENT_DEPARTEMENT"), getDestination().getField("ID_CLIENT_DEPARTEMENT"));
55
        }
132 ilm 56
        if (getSource().getTable().contains("ID_TARIF") && getDestination().getTable().contains("ID_TARIF")) {
57
            map(getSource().getField("ID_TARIF"), getDestination().getField("ID_TARIF"));
58
        }
18 ilm 59
    }
73 ilm 60
 
61
    @Override
62
    protected void merge(SQLRowAccessor srcRow, SQLRowValues rowVals) {
63
        super.merge(srcRow, rowVals);
64
 
65
        // Merge elements
66
        final SQLTable tableElementSource = getSource().getTable("SAISIE_VENTE_FACTURE_ELEMENT");
67
        final SQLTable tableElementDestination = getSource().getTable("AVOIR_CLIENT_ELEMENT");
68
        final Collection<? extends SQLRowAccessor> myListItem = srcRow.asRow().getReferentRows(tableElementSource);
83 ilm 69
        transfertNumberReference(srcRow, rowVals, tableElementDestination, "ID_AVOIR_CLIENT");
174 ilm 70
        transfertReference(srcRow, rowVals, tableElementDestination, "ID_AVOIR_CLIENT", "NOM", "NOM");
73 ilm 71
 
72
        if (myListItem.size() != 0) {
73
            final SQLInjector injector = SQLInjector.getInjector(tableElementSource, tableElementDestination);
74
            for (SQLRowAccessor rowElt : myListItem) {
75
                final SQLRowValues createRowValuesFrom = injector.createRowValuesFrom(rowElt.asRow());
76
                if (createRowValuesFrom.getTable().getFieldsName().contains("POURCENT_ACOMPTE")) {
77
                    if (createRowValuesFrom.getObject("POURCENT_ACOMPTE") == null) {
78
                        createRowValuesFrom.put("POURCENT_ACOMPTE", new BigDecimal(100.0));
79
                    }
80
                }
81
                createRowValuesFrom.put("ID_AVOIR_CLIENT", rowVals);
82
            }
83
        }
84
    }
18 ilm 85
}