OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

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