OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 73 | Rev 93 | 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
 
73 ilm 16
import java.math.BigDecimal;
17
import java.util.Collection;
18
 
83 ilm 19
import org.openconcerto.erp.preferences.GenerationDocGlobalPreferencePanel;
20
import org.openconcerto.erp.preferences.GestionCommercialeGlobalPreferencePanel;
21
import org.openconcerto.sql.Configuration;
18 ilm 22
import org.openconcerto.sql.model.DBRoot;
23
import org.openconcerto.sql.model.SQLInjector;
73 ilm 24
import org.openconcerto.sql.model.SQLRowAccessor;
25
import org.openconcerto.sql.model.SQLRowValues;
18 ilm 26
import org.openconcerto.sql.model.SQLTable;
83 ilm 27
import org.openconcerto.sql.model.UndefinedRowValuesCache;
28
import org.openconcerto.sql.preferences.SQLPreferences;
18 ilm 29
 
30
public class DevisFactureSQLInjector extends SQLInjector {
31
    public DevisFactureSQLInjector(final DBRoot root) {
73 ilm 32
        super(root, "DEVIS", "SAISIE_VENTE_FACTURE", true);
18 ilm 33
        final SQLTable tableDevis = getSource();
34
        final SQLTable tableFacture = getDestination();
35
        map(tableDevis.getField("PORT_HT"), tableFacture.getField("PORT_HT"));
36
        map(tableDevis.getField("REMISE_HT"), tableFacture.getField("REMISE_HT"));
37
        map(tableDevis.getField("ID_CLIENT"), tableFacture.getField("ID_CLIENT"));
38
        map(tableDevis.getField("ID_COMMERCIAL"), tableFacture.getField("ID_COMMERCIAL"));
73 ilm 39
        map(tableDevis.getField("ID_DEVIS"), tableFacture.getField("ID_DEVIS"));
83 ilm 40
        if (tableDevis.getTable().contains("ID_POLE_PRODUIT")) {
41
            map(tableDevis.getField("ID_POLE_PRODUIT"), tableFacture.getField("ID_POLE_PRODUIT"));
42
        }
43
        if (tableDevis.getTable().contains("ID_CONTACT")) {
44
            map(tableDevis.getField("ID_CONTACT"), tableFacture.getField("ID_CONTACT"));
45
        }
18 ilm 46
    }
73 ilm 47
 
48
    @Override
49
    protected void merge(SQLRowAccessor srcRow, SQLRowValues rowVals) {
50
        super.merge(srcRow, rowVals);
51
 
52
        // Merge elements
53
        final SQLTable tableElementSource = getSource().getTable("DEVIS_ELEMENT");
54
        final SQLTable tableElementDestination = getSource().getTable("SAISIE_VENTE_FACTURE_ELEMENT");
55
        final Collection<? extends SQLRowAccessor> myListItem = srcRow.asRow().getReferentRows(tableElementSource);
83 ilm 56
        transfertReference(srcRow, rowVals, "OBJET", "NOM");
57
        transfertReference(srcRow, rowVals, "INFOS", "INFOS");
58
        transfertNumberReference(srcRow, rowVals, tableElementDestination, "ID_SAISIE_VENTE_FACTURE");
73 ilm 59
 
60
        if (myListItem.size() != 0) {
61
            final SQLInjector injector = SQLInjector.getInjector(tableElementSource, tableElementDestination);
62
            for (SQLRowAccessor rowElt : myListItem) {
63
                final SQLRowValues createRowValuesFrom = injector.createRowValuesFrom(rowElt.asRow());
64
                if (createRowValuesFrom.getTable().getFieldsName().contains("POURCENT_ACOMPTE")) {
65
                    if (createRowValuesFrom.getObject("POURCENT_ACOMPTE") == null) {
66
                        createRowValuesFrom.put("POURCENT_ACOMPTE", new BigDecimal(100.0));
67
                    }
68
                }
69
                createRowValuesFrom.put("ID_SAISIE_VENTE_FACTURE", rowVals);
70
            }
71
        }
72
    }
18 ilm 73
}