OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 132 | 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.core.finance.payment.element;
15
 
80 ilm 16
import org.openconcerto.erp.config.ComptaPropsConfiguration;
18 ilm 17
import org.openconcerto.erp.core.common.element.ComptaSQLConfElement;
18
import org.openconcerto.erp.core.finance.accounting.element.EcritureSQLElement;
19
import org.openconcerto.erp.core.finance.payment.component.EncaisserMontantSQLComponent;
20
import org.openconcerto.sql.Configuration;
21
import org.openconcerto.sql.element.SQLComponent;
22
import org.openconcerto.sql.element.TreesOfSQLRows;
80 ilm 23
import org.openconcerto.sql.model.FieldPath;
18 ilm 24
import org.openconcerto.sql.model.SQLRow;
80 ilm 25
import org.openconcerto.sql.model.SQLRowAccessor;
18 ilm 26
import org.openconcerto.sql.model.SQLRowListRSH;
27
import org.openconcerto.sql.model.SQLRowValues;
28
import org.openconcerto.sql.model.SQLSelect;
29
import org.openconcerto.sql.model.SQLTable;
30
import org.openconcerto.sql.model.Where;
83 ilm 31
import org.openconcerto.sql.model.graph.Path;
32
import org.openconcerto.sql.model.graph.PathBuilder;
80 ilm 33
import org.openconcerto.sql.view.list.BaseSQLTableModelColumn;
142 ilm 34
import org.openconcerto.sql.view.list.SQLTableModelSource;
83 ilm 35
import org.openconcerto.utils.CollectionUtils;
18 ilm 36
 
37
import java.sql.SQLException;
38
import java.util.ArrayList;
83 ilm 39
import java.util.Arrays;
40
import java.util.Collection;
18 ilm 41
import java.util.Collections;
132 ilm 42
import java.util.HashSet;
18 ilm 43
import java.util.List;
44
import java.util.Set;
45
 
46
public class EncaisserMontantSQLElement extends ComptaSQLConfElement {
47
 
48
    public EncaisserMontantSQLElement() {
49
        super("ENCAISSER_MONTANT", "un encaissement de montant", "encaissements de montant");
50
    }
51
 
52
    @Override
53
    protected List<String> getListFields() {
54
        final List<String> l = new ArrayList<String>();
83 ilm 55
            l.add("DATE");
56
            l.add("NOM");
57
            l.add("ID_CLIENT");
58
            // l.add("ID_MOUVEMENT");
59
            l.add("ID_MODE_REGLEMENT");
60
            l.add("MONTANT");
18 ilm 61
        return l;
62
    }
63
 
64
    @Override
65
    protected List<String> getComboFields() {
66
        final List<String> l = new ArrayList<String>();
67
        l.add("DATE");
68
        l.add("MONTANT");
69
        return l;
70
    }
71
 
72
    @Override
73
    public Set<String> getReadOnlyFields() {
74
 
75
        return Collections.singleton("ID_CLIENT");
76
    }
77
 
80 ilm 78
 
18 ilm 79
    /*
80
     * (non-Javadoc)
81
     *
82
     * @see org.openconcerto.devis.SQLElement#getComponent()
83
     */
84
    @Override
85
    public SQLComponent createComponent() {
86
        return new EncaisserMontantSQLComponent(this);
87
    }
88
 
89
    @Override
90
    protected void archive(TreesOfSQLRows trees, boolean cutLinks) throws SQLException {
91
 
92
        // On rétablit les échéances
93
        for (SQLRow row : trees.getRows()) {
94
            for (SQLRow rowEncaisse : row.getReferentRows()) {
95
 
96
                SQLRow rowEch = rowEncaisse.getForeignRow("ID_ECHEANCE_CLIENT");
97
                // SI une echeance est associée (paiement non comptant)
98
                if (rowEch.getID() > 1) {
99
                    SQLRowValues rowVals = rowEch.createEmptyUpdateRow();
100
                    rowVals.put("REGLE", Boolean.FALSE);
101
                    if (rowEch.getBoolean("REGLE")) {
102
                        rowVals.put("MONTANT", rowEncaisse.getLong("MONTANT_REGLE"));
103
                    } else {
104
                        rowVals.put("MONTANT", rowEch.getLong("MONTANT") + rowEncaisse.getLong("MONTANT_REGLE"));
105
                    }
106
                    rowVals.update();
107
                }
108
                Configuration.getInstance().getDirectory().getElement(rowEncaisse.getTable()).archive(rowEncaisse);
109
            }
110
 
111
            // On supprime les mouvements
112
            SQLSelect sel = new SQLSelect(getTable().getBase());
113
 
114
            SQLTable tableMvt = getTable().getTable("MOUVEMENT");
115
            EcritureSQLElement eltEcr = (EcritureSQLElement) Configuration.getInstance().getDirectory().getElement(tableMvt.getTable("ECRITURE"));
116
            sel.addSelectStar(tableMvt);
117
            Where w = new Where(tableMvt.getField("SOURCE"), "=", getTable().getName());
118
            w = w.and(new Where(tableMvt.getField("IDSOURCE"), "=", row.getID()));
119
            sel.setWhere(w);
120
            List<SQLRow> list = (List<SQLRow>) getTable().getBase().getDataSource().execute(sel.asString(), SQLRowListRSH.createFromSelect(sel, tableMvt));
121
            for (SQLRow sqlRow : list) {
122
                eltEcr.archiveMouvementProfondeur(sqlRow.getID(), true);
123
            }
124
        }
125
 
126
        super.archive(trees, cutLinks);
127
    }
128
}