OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 149 | 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
 
142 ilm 16
import org.openconcerto.erp.config.ComptaPropsConfiguration;
18 ilm 17
import org.openconcerto.sql.model.DBRoot;
18
import org.openconcerto.sql.model.SQLInjector;
73 ilm 19
import org.openconcerto.sql.model.SQLRowAccessor;
20
import org.openconcerto.sql.model.SQLRowValues;
18 ilm 21
import org.openconcerto.sql.model.SQLTable;
22
 
93 ilm 23
import java.math.BigDecimal;
24
import java.util.Collection;
25
 
142 ilm 26
import com.ibm.icu.util.Calendar;
27
 
18 ilm 28
public class DevisFactureSQLInjector extends SQLInjector {
29
    public DevisFactureSQLInjector(final DBRoot root) {
73 ilm 30
        super(root, "DEVIS", "SAISIE_VENTE_FACTURE", true);
18 ilm 31
        final SQLTable tableDevis = getSource();
32
        final SQLTable tableFacture = getDestination();
149 ilm 33
        if (tableDevis.contains("T_ACOMPTE")) {
34
            map(tableDevis.getField("T_ACOMPTE"), tableFacture.getField("T_ACOMPTE"));
35
        }
18 ilm 36
        map(tableDevis.getField("PORT_HT"), tableFacture.getField("PORT_HT"));
156 ilm 37
        if (getSource().contains("FRAIS_DOCUMENT_HT") && getDestination().contains("FRAIS_DOCUMENT_HT")) {
38
            map(getSource().getField("FRAIS_DOCUMENT_HT"), getDestination().getField("FRAIS_DOCUMENT_HT"));
39
        }
40
        if (getSource().contains("ID_TAXE_FRAIS_DOCUMENT") && getDestination().contains("ID_TAXE_FRAIS_DOCUMENT")) {
41
            map(getSource().getField("ID_TAXE_FRAIS_DOCUMENT"), getDestination().getField("ID_TAXE_FRAIS_DOCUMENT"));
42
        }
18 ilm 43
        map(tableDevis.getField("REMISE_HT"), tableFacture.getField("REMISE_HT"));
44
        map(tableDevis.getField("ID_CLIENT"), tableFacture.getField("ID_CLIENT"));
45
        map(tableDevis.getField("ID_COMMERCIAL"), tableFacture.getField("ID_COMMERCIAL"));
73 ilm 46
        map(tableDevis.getField("ID_DEVIS"), tableFacture.getField("ID_DEVIS"));
83 ilm 47
        if (tableDevis.getTable().contains("ID_POLE_PRODUIT")) {
48
            map(tableDevis.getField("ID_POLE_PRODUIT"), tableFacture.getField("ID_POLE_PRODUIT"));
49
        }
93 ilm 50
        if (tableDevis.getTable().contains("ID_VERIFICATEUR") && tableFacture.getTable().contains("ID_VERIFICATEUR")) {
51
            map(tableDevis.getField("ID_VERIFICATEUR"), tableFacture.getField("ID_VERIFICATEUR"));
52
        }
83 ilm 53
        if (tableDevis.getTable().contains("ID_CONTACT")) {
54
            map(tableDevis.getField("ID_CONTACT"), tableFacture.getField("ID_CONTACT"));
55
        }
93 ilm 56
        if (getSource().getTable().contains("ID_CLIENT_DEPARTEMENT")) {
57
            map(tableDevis.getField("ID_CLIENT_DEPARTEMENT"), tableFacture.getField("ID_CLIENT_DEPARTEMENT"));
58
        }
59
        if (getSource().getTable().contains("ID_ADRESSE") && getDestination().contains("ID_ADRESSE")) {
60
            map(tableDevis.getField("ID_ADRESSE"), tableFacture.getField("ID_ADRESSE"));
61
        }
62
        if (getSource().getTable().contains("ID_ADRESSE_LIVRAISON") && getDestination().contains("ID_ADRESSE_LIVRAISON")) {
63
            map(tableDevis.getField("ID_ADRESSE_LIVRAISON"), tableFacture.getField("ID_ADRESSE_LIVRAISON"));
64
        }
65
 
66
        if (getSource().getTable().contains("MONTANT_REMISE") && tableFacture.contains("MONTANT_REMISE")) {
67
            map(tableDevis.getField("MONTANT_REMISE"), tableFacture.getField("MONTANT_REMISE"));
68
            map(tableDevis.getField("POURCENT_REMISE"), tableFacture.getField("POURCENT_REMISE"));
69
        }
18 ilm 70
    }
73 ilm 71
 
72
    @Override
73
    protected void merge(SQLRowAccessor srcRow, SQLRowValues rowVals) {
74
        super.merge(srcRow, rowVals);
75
 
142 ilm 76
 
73 ilm 77
        // Merge elements
78
        final SQLTable tableElementSource = getSource().getTable("DEVIS_ELEMENT");
79
        final SQLTable tableElementDestination = getSource().getTable("SAISIE_VENTE_FACTURE_ELEMENT");
80
        final Collection<? extends SQLRowAccessor> myListItem = srcRow.asRow().getReferentRows(tableElementSource);
83 ilm 81
        transfertReference(srcRow, rowVals, "OBJET", "NOM");
82
        transfertReference(srcRow, rowVals, "INFOS", "INFOS");
83
        transfertNumberReference(srcRow, rowVals, tableElementDestination, "ID_SAISIE_VENTE_FACTURE");
73 ilm 84
 
156 ilm 85
        if (getDestination().contains("ID_TAXE_FRAIS_DOCUMENT")) {
86
            final SQLRowAccessor rowClient = srcRow.getForeign("ID_CLIENT");
87
            SQLRowAccessor rowFrais = rowClient.getForeign("ID_FRAIS_DOCUMENT");
88
            if (rowFrais != null && !rowFrais.isUndefined()) {
89
                rowVals.put("FRAIS_DOCUMENT_HT", rowFrais.getLong("MONTANT_HT"));
90
                rowVals.put("ID_TAXE_FRAIS_DOCUMENT", rowFrais.getForeignID("ID_TAXE"));
91
            }
92
        }
73 ilm 93
        if (myListItem.size() != 0) {
94
            final SQLInjector injector = SQLInjector.getInjector(tableElementSource, tableElementDestination);
95
            for (SQLRowAccessor rowElt : myListItem) {
96
                final SQLRowValues createRowValuesFrom = injector.createRowValuesFrom(rowElt.asRow());
97
                if (createRowValuesFrom.getTable().getFieldsName().contains("POURCENT_ACOMPTE")) {
98
                    if (createRowValuesFrom.getObject("POURCENT_ACOMPTE") == null) {
99
                        createRowValuesFrom.put("POURCENT_ACOMPTE", new BigDecimal(100.0));
100
                    }
101
                }
102
                createRowValuesFrom.put("ID_SAISIE_VENTE_FACTURE", rowVals);
103
            }
104
        }
105
    }
18 ilm 106
}