OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

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