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