OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

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