OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 156 | 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
        }
174 ilm 49
        if (getSource().getTable().contains("ID_CATEGORIE_COMPTABLE") && getDestination().getTable().contains("ID_CATEGORIE_COMPTABLE")) {
50
            map(getSource().getField("ID_CATEGORIE_COMPTABLE"), getDestination().getField("ID_CATEGORIE_COMPTABLE"));
51
        }
93 ilm 52
        if (tableBon.contains("ID_TAXE_PORT")) {
53
            map(tableBon.getField("ID_TAXE_PORT"), tableFacture.getField("ID_TAXE_PORT"));
54
        }
55
        if (tableBon.contains("PORT_HT")) {
56
            map(tableBon.getField("PORT_HT"), tableFacture.getField("PORT_HT"));
57
        }
156 ilm 58
        if (getSource().contains("FRAIS_DOCUMENT_HT") && getDestination().contains("FRAIS_DOCUMENT_HT")) {
59
            map(getSource().getField("FRAIS_DOCUMENT_HT"), getDestination().getField("FRAIS_DOCUMENT_HT"));
60
        }
61
        if (getSource().contains("ID_TAXE_FRAIS_DOCUMENT") && getDestination().contains("ID_TAXE_FRAIS_DOCUMENT")) {
62
            map(getSource().getField("ID_TAXE_FRAIS_DOCUMENT"), getDestination().getField("ID_TAXE_FRAIS_DOCUMENT"));
63
        }
93 ilm 64
        if (tableBon.contains("REMISE_HT")) {
65
            map(tableBon.getField("REMISE_HT"), tableFacture.getField("REMISE_HT"));
66
        }
132 ilm 67
        if (getSource().getTable().contains("ID_TARIF") && getDestination().getTable().contains("ID_TARIF")) {
68
            map(getSource().getField("ID_TARIF"), getDestination().getField("ID_TARIF"));
69
        }
142 ilm 70
        if (getSource().getTable().contains("ACOMPTE_COMMANDE")) {
71
            map(getSource().getField("ACOMPTE_COMMANDE"), getDestination().getField("ACOMPTE_COMMANDE"));
72
        }
18 ilm 73
    }
73 ilm 74
 
75
    @Override
76
    protected void merge(SQLRowAccessor srcRow, SQLRowValues rowVals) {
77
        super.merge(srcRow, rowVals);
78
 
79
        // Merge elements
80
        final SQLTable tableElementSource = getSource().getTable("BON_DE_LIVRAISON_ELEMENT");
81
        final SQLTable tableElementDestination = getSource().getTable("SAISIE_VENTE_FACTURE_ELEMENT");
82
        final Collection<? extends SQLRowAccessor> myListItem = srcRow.asRow().getReferentRows(tableElementSource);
83 ilm 83
        transfertNumberReference(srcRow, rowVals, tableElementDestination, "ID_SAISIE_VENTE_FACTURE");
174 ilm 84
        transfertReference(srcRow, rowVals, tableElementDestination, "ID_SAISIE_VENTE_FACTURE", "NOM", "NOM");
85
        transfertReference(srcRow, rowVals, tableElementDestination, "ID_SAISIE_VENTE_FACTURE", "INFOS", "INFOS");
156 ilm 86
        if (getDestination().contains("ID_TAXE_FRAIS_DOCUMENT")) {
87
            final SQLRowAccessor rowClient = srcRow.getForeign("ID_CLIENT");
88
            SQLRowAccessor rowFrais = rowClient.getForeign("ID_FRAIS_DOCUMENT");
89
            if (rowFrais != null && !rowFrais.isUndefined()) {
90
                rowVals.put("FRAIS_DOCUMENT_HT", rowFrais.getLong("MONTANT_HT"));
91
                rowVals.put("ID_TAXE_FRAIS_DOCUMENT", rowFrais.getForeignID("ID_TAXE"));
92
            }
93
        }
73 ilm 94
        if (myListItem.size() != 0) {
95
            final SQLInjector injector = SQLInjector.getInjector(tableElementSource, tableElementDestination);
96
            for (SQLRowAccessor rowElt : myListItem) {
97
                final SQLRowValues createRowValuesFrom = injector.createRowValuesFrom(rowElt.asRow());
98
                if (createRowValuesFrom.getTable().getFieldsName().contains("POURCENT_ACOMPTE")) {
99
                    if (createRowValuesFrom.getObject("POURCENT_ACOMPTE") == null) {
100
                        createRowValuesFrom.put("POURCENT_ACOMPTE", new BigDecimal(100.0));
101
                    }
102
                }
103
                createRowValuesFrom.put("ID_SAISIE_VENTE_FACTURE", rowVals);
104
            }
105
        }
106
    }
107
 
18 ilm 108
}