OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

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