OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 142 | Rev 174 | 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
 
16
import org.openconcerto.sql.model.DBRoot;
17
import org.openconcerto.sql.model.SQLInjector;
73 ilm 18
import org.openconcerto.sql.model.SQLRowAccessor;
19
import org.openconcerto.sql.model.SQLRowValues;
18 ilm 20
import org.openconcerto.sql.model.SQLTable;
21
 
93 ilm 22
import java.math.BigDecimal;
23
import java.util.Collection;
24
 
18 ilm 25
public class BonFactureSQLInjector extends SQLInjector {
26
 
27
    public BonFactureSQLInjector(final DBRoot root) {
73 ilm 28
        super(root.getTable("BON_DE_LIVRAISON"), root.getTable("SAISIE_VENTE_FACTURE"), true);
18 ilm 29
        final SQLTable tableBon = getSource();
30
        final SQLTable tableFacture = getDestination();
31
        // map(tableDevis.getField("PORT_HT"), tableCommande.getField("PORT_HT"));
32
        // map(tableDevis.getField("REMISE_HT"), tableCommande.getField("REMISE_HT"));
33
        map(tableBon.getField("ID_CLIENT"), tableFacture.getField("ID_CLIENT"));
83 ilm 34
        if (tableBon.getTable().contains("ID_POLE_PRODUIT")) {
35
            map(tableBon.getField("ID_POLE_PRODUIT"), tableFacture.getField("ID_POLE_PRODUIT"));
36
        }
93 ilm 37
        if (getSource().getTable().contains("ID_CONTACT")) {
38
            map(getSource().getField("ID_CONTACT"), getDestination().getField("ID_CONTACT"));
39
        }
40
        if (getSource().getTable().contains("ID_CLIENT_DEPARTEMENT")) {
41
            map(getSource().getField("ID_CLIENT_DEPARTEMENT"), getDestination().getField("ID_CLIENT_DEPARTEMENT"));
42
        }
142 ilm 43
        if (getSource().getTable().contains("ID_ADRESSE") && getDestination().contains("ID_ADRESSE")) {
44
            map(getSource().getField("ID_ADRESSE"), getDestination().getField("ID_ADRESSE"));
45
        }
46
        if (getSource().getTable().contains("ID_ADRESSE_LIVRAISON")) {
47
            map(getSource().getField("ID_ADRESSE_LIVRAISON"), getDestination().getField("ID_ADRESSE_LIVRAISON"));
48
        }
93 ilm 49
        if (tableBon.contains("ID_TAXE_PORT")) {
50
            map(tableBon.getField("ID_TAXE_PORT"), tableFacture.getField("ID_TAXE_PORT"));
51
        }
52
        if (tableBon.contains("PORT_HT")) {
53
            map(tableBon.getField("PORT_HT"), tableFacture.getField("PORT_HT"));
54
        }
156 ilm 55
        if (getSource().contains("FRAIS_DOCUMENT_HT") && getDestination().contains("FRAIS_DOCUMENT_HT")) {
56
            map(getSource().getField("FRAIS_DOCUMENT_HT"), getDestination().getField("FRAIS_DOCUMENT_HT"));
57
        }
58
        if (getSource().contains("ID_TAXE_FRAIS_DOCUMENT") && getDestination().contains("ID_TAXE_FRAIS_DOCUMENT")) {
59
            map(getSource().getField("ID_TAXE_FRAIS_DOCUMENT"), getDestination().getField("ID_TAXE_FRAIS_DOCUMENT"));
60
        }
93 ilm 61
        if (tableBon.contains("REMISE_HT")) {
62
            map(tableBon.getField("REMISE_HT"), tableFacture.getField("REMISE_HT"));
63
        }
132 ilm 64
        if (getSource().getTable().contains("ID_TARIF") && getDestination().getTable().contains("ID_TARIF")) {
65
            map(getSource().getField("ID_TARIF"), getDestination().getField("ID_TARIF"));
66
        }
142 ilm 67
        if (getSource().getTable().contains("ACOMPTE_COMMANDE")) {
68
            map(getSource().getField("ACOMPTE_COMMANDE"), getDestination().getField("ACOMPTE_COMMANDE"));
69
        }
18 ilm 70
    }
73 ilm 71
 
72
    @Override
73
    protected void merge(SQLRowAccessor srcRow, SQLRowValues rowVals) {
74
        super.merge(srcRow, rowVals);
75
 
76
        // Merge elements
77
        final SQLTable tableElementSource = getSource().getTable("BON_DE_LIVRAISON_ELEMENT");
78
        final SQLTable tableElementDestination = getSource().getTable("SAISIE_VENTE_FACTURE_ELEMENT");
79
        final Collection<? extends SQLRowAccessor> myListItem = srcRow.asRow().getReferentRows(tableElementSource);
83 ilm 80
        transfertReference(srcRow, rowVals, "NOM", "NOM");
81
        transfertReference(srcRow, rowVals, "INFOS", "INFOS");
82
        transfertNumberReference(srcRow, rowVals, tableElementDestination, "ID_SAISIE_VENTE_FACTURE");
156 ilm 83
        if (getDestination().contains("ID_TAXE_FRAIS_DOCUMENT")) {
84
            final SQLRowAccessor rowClient = srcRow.getForeign("ID_CLIENT");
85
            SQLRowAccessor rowFrais = rowClient.getForeign("ID_FRAIS_DOCUMENT");
86
            if (rowFrais != null && !rowFrais.isUndefined()) {
87
                rowVals.put("FRAIS_DOCUMENT_HT", rowFrais.getLong("MONTANT_HT"));
88
                rowVals.put("ID_TAXE_FRAIS_DOCUMENT", rowFrais.getForeignID("ID_TAXE"));
89
            }
90
        }
73 ilm 91
        if (myListItem.size() != 0) {
92
            final SQLInjector injector = SQLInjector.getInjector(tableElementSource, tableElementDestination);
93
            for (SQLRowAccessor rowElt : myListItem) {
94
                final SQLRowValues createRowValuesFrom = injector.createRowValuesFrom(rowElt.asRow());
95
                if (createRowValuesFrom.getTable().getFieldsName().contains("POURCENT_ACOMPTE")) {
96
                    if (createRowValuesFrom.getObject("POURCENT_ACOMPTE") == null) {
97
                        createRowValuesFrom.put("POURCENT_ACOMPTE", new BigDecimal(100.0));
98
                    }
99
                }
100
                createRowValuesFrom.put("ID_SAISIE_VENTE_FACTURE", rowVals);
101
            }
102
        }
103
    }
104
 
18 ilm 105
}