OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 174 | 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
 *
185 ilm 4
 * Copyright 2011-2019 OpenConcerto, by ILM Informatique. All rights reserved.
18 ilm 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;
185 ilm 21
import org.openconcerto.sql.model.SQLRow;
73 ilm 22
import org.openconcerto.sql.model.SQLRowAccessor;
23
import org.openconcerto.sql.model.SQLRowValues;
18 ilm 24
import org.openconcerto.sql.model.SQLTable;
25
 
26
public class FactureAvoirSQLInjector extends SQLInjector {
27
    public FactureAvoirSQLInjector(final DBRoot root) {
73 ilm 28
        super(root, "SAISIE_VENTE_FACTURE", "AVOIR_CLIENT", true);
18 ilm 29
        final SQLTable tableFacture = getSource();
30
        final SQLTable tableAvoir = getDestination();
31
        map(tableFacture.getField("ID_CLIENT"), tableAvoir.getField("ID_CLIENT"));
32
        map(tableFacture.getField("ID_ADRESSE"), tableAvoir.getField("ID_ADRESSE"));
33
        map(tableFacture.getField("ID_COMMERCIAL"), tableAvoir.getField("ID_COMMERCIAL"));
34
        map(tableFacture.getField("REMISE_HT"), tableAvoir.getField("REMISE_HT"));
35
        map(tableFacture.getField("PORT_HT"), tableAvoir.getField("PORT_HT"));
93 ilm 36
        if (getSource().getTable().contains("ID_CONTACT")) {
37
            map(getSource().getField("ID_CONTACT"), getDestination().getField("ID_CONTACT"));
38
        }
73 ilm 39
 
93 ilm 40
        if (getSource().contains("ID_ADRESSE") && getDestination().contains("ID_ADRESSE")) {
41
            map(getSource().getField("ID_ADRESSE"), getDestination().getField("ID_ADRESSE"));
42
        }
43
 
44
        if (getSource().contains("ID_ADRESSE_LIVRAISON") && getDestination().contains("ID_ADRESSE_LIVRAISON")) {
45
            map(getSource().getField("ID_ADRESSE_LIVRAISON"), getDestination().getField("ID_ADRESSE_LIVRAISON"));
46
        }
174 ilm 47
        if (getSource().getTable().contains("ID_CATEGORIE_COMPTABLE") && getDestination().getTable().contains("ID_CATEGORIE_COMPTABLE")) {
48
            map(getSource().getField("ID_CATEGORIE_COMPTABLE"), getDestination().getField("ID_CATEGORIE_COMPTABLE"));
49
        }
93 ilm 50
        if (getSource().getTable().contains("DATE_LIVRAISON") && getDestination().contains("DATE_LIVRAISON")) {
51
            map(getSource().getField("DATE_LIVRAISON"), getDestination().getField("DATE_LIVRAISON"));
52
        }
53
 
54
        if (getSource().getTable().contains("ID_CLIENT_DEPARTEMENT")) {
55
            map(getSource().getField("ID_CLIENT_DEPARTEMENT"), getDestination().getField("ID_CLIENT_DEPARTEMENT"));
56
        }
132 ilm 57
        if (getSource().getTable().contains("ID_TARIF") && getDestination().getTable().contains("ID_TARIF")) {
58
            map(getSource().getField("ID_TARIF"), getDestination().getField("ID_TARIF"));
59
        }
18 ilm 60
    }
73 ilm 61
 
62
    @Override
63
    protected void merge(SQLRowAccessor srcRow, SQLRowValues rowVals) {
64
        super.merge(srcRow, rowVals);
65
 
66
        // Merge elements
67
        final SQLTable tableElementSource = getSource().getTable("SAISIE_VENTE_FACTURE_ELEMENT");
68
        final SQLTable tableElementDestination = getSource().getTable("AVOIR_CLIENT_ELEMENT");
69
        final Collection<? extends SQLRowAccessor> myListItem = srcRow.asRow().getReferentRows(tableElementSource);
83 ilm 70
        transfertNumberReference(srcRow, rowVals, tableElementDestination, "ID_AVOIR_CLIENT");
174 ilm 71
        transfertReference(srcRow, rowVals, tableElementDestination, "ID_AVOIR_CLIENT", "NOM", "NOM");
73 ilm 72
 
73
        if (myListItem.size() != 0) {
74
            final SQLInjector injector = SQLInjector.getInjector(tableElementSource, tableElementDestination);
75
            for (SQLRowAccessor rowElt : myListItem) {
185 ilm 76
                final SQLRow asRow = rowElt.asRow();
77
                final SQLRowValues createRowValuesFrom = injector.createRowValuesFrom(asRow);
78
 
79
                if (asRow.getObject("MONTANT_FACTURABLE") != null) {
80
                    createRowValuesFrom.put("PV_HT", asRow.getObject("MONTANT_FACTURABLE"));
81
                    createRowValuesFrom.put("PRIX_METRIQUE_VT_1", asRow.getObject("MONTANT_FACTURABLE"));
82
                } else if (asRow.getObject("POURCENT_FACTURABLE") != null && asRow.getObject("PRIX_METRIQUE_VT_1") != null) {
83
                    final BigDecimal pv = asRow.getBigDecimal("PRIX_METRIQUE_VT_1").multiply(asRow.getBigDecimal("POURCENT_FACTURABLE")).movePointLeft(2);
84
                    createRowValuesFrom.put("PV_HT", pv);
85
                    createRowValuesFrom.put("PRIX_METRIQUE_VT_1", pv);
86
                }
87
 
73 ilm 88
                if (createRowValuesFrom.getTable().getFieldsName().contains("POURCENT_ACOMPTE")) {
89
                    if (createRowValuesFrom.getObject("POURCENT_ACOMPTE") == null) {
90
                        createRowValuesFrom.put("POURCENT_ACOMPTE", new BigDecimal(100.0));
91
                    }
92
                }
93
                createRowValuesFrom.put("ID_AVOIR_CLIENT", rowVals);
94
            }
95
        }
96
    }
18 ilm 97
}