OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 156 | Rev 182 | 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
        }
174 ilm 75
        if (getSource().getTable().contains("ID_CATEGORIE_COMPTABLE") && getDestination().getTable().contains("ID_CATEGORIE_COMPTABLE")) {
76
            map(getSource().getField("ID_CATEGORIE_COMPTABLE"), getDestination().getField("ID_CATEGORIE_COMPTABLE"));
77
        }
18 ilm 78
    }
73 ilm 79
 
80
    @Override
81
    protected void merge(SQLRowAccessor srcRow, SQLRowValues rowVals) {
82
        super.merge(srcRow, rowVals);
83
 
84
        // Merge elements
85
        final SQLTable tableElementSource = getSource().getTable("COMMANDE_CLIENT_ELEMENT");
86
        final SQLTable tableElementDestination = getSource().getTable("SAISIE_VENTE_FACTURE_ELEMENT");
87
        final Collection<? extends SQLRowAccessor> myListItem = srcRow.asRow().getReferentRows(tableElementSource);
83 ilm 88
        transfertNumberReference(srcRow, rowVals, tableElementDestination, "ID_SAISIE_VENTE_FACTURE");
174 ilm 89
        transfertReference(srcRow, rowVals, tableElementDestination, "ID_SAISIE_VENTE_FACTURE", "NOM", "NOM");
90
        transfertReference(srcRow, rowVals, tableElementDestination, "ID_SAISIE_VENTE_FACTURE", "INFOS", "INFOS");
156 ilm 91
        if (getDestination().contains("ID_TAXE_FRAIS_DOCUMENT")) {
92
            final SQLRowAccessor rowClient = srcRow.getForeign("ID_CLIENT");
93
            SQLRowAccessor rowFrais = rowClient.getForeign("ID_FRAIS_DOCUMENT");
94
            if (rowFrais != null && !rowFrais.isUndefined()) {
95
                rowVals.put("FRAIS_DOCUMENT_HT", rowFrais.getLong("MONTANT_HT"));
96
                rowVals.put("ID_TAXE_FRAIS_DOCUMENT", rowFrais.getForeignID("ID_TAXE"));
97
            }
98
        }
73 ilm 99
        if (myListItem.size() != 0) {
100
            final SQLInjector injector = SQLInjector.getInjector(tableElementSource, tableElementDestination);
101
            for (SQLRowAccessor rowElt : myListItem) {
102
                System.err.println("CommandeFactureClientSQLInjector.merge():" + rowElt);
103
                final SQLRowValues createRowValuesFrom = injector.createRowValuesFrom(rowElt.asRow());
104
                if (createRowValuesFrom.getTable().getFieldsName().contains("POURCENT_ACOMPTE")) {
105
                    if (createRowValuesFrom.getObject("POURCENT_ACOMPTE") == null) {
106
                        createRowValuesFrom.put("POURCENT_ACOMPTE", new BigDecimal(100.0));
107
                    }
108
                }
109
                createRowValuesFrom.put("ID_SAISIE_VENTE_FACTURE", rowVals);
110
            }
111
        }
112
    }
113
 
18 ilm 114
}