OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 174 | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 174 Rev 177
1
/*
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 * 
3
 * 
4
 * Copyright 2011 OpenConcerto, by ILM Informatique. All rights reserved.
4
 * Copyright 2011 OpenConcerto, by ILM Informatique. All rights reserved.
5
 * 
5
 * 
6
 * The contents of this file are subject to the terms of the GNU General Public License Version 3
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
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
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.
9
 * language governing permissions and limitations under the License.
10
 * 
10
 * 
11
 * When distributing the software, include this License Header Notice in each file.
11
 * When distributing the software, include this License Header Notice in each file.
12
 */
12
 */
13
 
13
 
14
 /*
14
 /*
15
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
15
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
16
 * 
16
 * 
17
 * Copyright 2011 OpenConcerto, by ILM Informatique. All rights reserved.
17
 * Copyright 2011 OpenConcerto, by ILM Informatique. All rights reserved.
18
 * 
18
 * 
19
 * The contents of this file are subject to the terms of the GNU General Public License Version 3
19
 * The contents of this file are subject to the terms of the GNU General Public License Version 3
20
 * only ("GPL"). You may not use this file except in compliance with the License. You can obtain a
20
 * only ("GPL"). You may not use this file except in compliance with the License. You can obtain a
21
 * copy of the License at http://www.gnu.org/licenses/gpl-3.0.html See the License for the specific
21
 * copy of the License at http://www.gnu.org/licenses/gpl-3.0.html See the License for the specific
22
 * language governing permissions and limitations under the License.
22
 * language governing permissions and limitations under the License.
23
 * 
23
 * 
24
 * When distributing the software, include this License Header Notice in each file.
24
 * When distributing the software, include this License Header Notice in each file.
25
 */
25
 */
26
 
26
 
27
package org.openconcerto.erp.generationEcritures;
27
package org.openconcerto.erp.generationEcritures;
28
 
28
 
29
import org.openconcerto.erp.core.common.element.BanqueSQLElement;
29
import org.openconcerto.erp.core.common.element.BanqueSQLElement;
30
import org.openconcerto.erp.core.finance.accounting.element.ComptePCESQLElement;
30
import org.openconcerto.erp.core.finance.accounting.element.ComptePCESQLElement;
31
import org.openconcerto.sql.model.SQLRow;
31
import org.openconcerto.sql.model.SQLRow;
32
import org.openconcerto.sql.model.SQLRowAccessor;
32
import org.openconcerto.sql.model.SQLRowAccessor;
33
import org.openconcerto.sql.model.SQLRowValues;
33
import org.openconcerto.sql.model.SQLRowValues;
34
import org.openconcerto.sql.model.SQLRowValuesCluster.StoreMode;
34
import org.openconcerto.sql.model.SQLRowValuesCluster.StoreMode;
35
import org.openconcerto.sql.model.SQLRowValuesListFetcher;
35
import org.openconcerto.sql.model.SQLRowValuesListFetcher;
36
import org.openconcerto.sql.model.SQLTable;
36
import org.openconcerto.sql.model.SQLTable;
37
import org.openconcerto.sql.model.Where;
37
import org.openconcerto.sql.model.Where;
38
import org.openconcerto.utils.StringUtils;
38
import org.openconcerto.utils.StringUtils;
39
 
39
 
40
import java.util.ArrayList;
40
import java.util.ArrayList;
41
import java.util.List;
41
import java.util.List;
42
 
42
 
43
public class GenerationMvtDepotChequeClient extends GenerationEcritures {
43
public class GenerationMvtDepotChequeClient extends GenerationEcritures {
44
 
44
 
45
    private long montant;
45
    private long montant;
46
 
46
 
47
    private static final SQLTable tablePrefCompte = base.getTable("PREFS_COMPTE");
47
    private static final SQLTable tablePrefCompte = base.getTable("PREFS_COMPTE");
48
    private static final SQLRow rowPrefsCompte = tablePrefCompte.getRow(2);
48
    private static final SQLRow rowPrefsCompte = tablePrefCompte.getRow(2);
49
    private final SQLRow depot;
49
    private final SQLRow depot;
50
    private SQLRowAccessor banque;
50
    private SQLRowAccessor banque;
51
 
51
 
52
    public GenerationMvtDepotChequeClient(SQLRow depot) {
52
    public GenerationMvtDepotChequeClient(SQLRow depot) {
53
        this.montant = depot.getLong("MONTANT");
53
        this.montant = depot.getLong("MONTANT");
54
        this.date = depot.getDate("DATE").getTime();
54
        this.date = depot.getDate("DATE").getTime();
55
        this.banque = depot.getForeign("ID_" + BanqueSQLElement.TABLENAME);
55
        this.banque = depot.getForeign("ID_" + BanqueSQLElement.TABLENAME);
56
        this.depot = depot;
56
        this.depot = depot;
57
        // SQLRow chequeRow = base.getTable("CHEQUE_A_ENCAISSER").getRow(this.idCheque);
57
        // SQLRow chequeRow = base.getTable("CHEQUE_A_ENCAISSER").getRow(this.idCheque);
58
        // String num = "";
58
        // String num = "";
59
        // if (chequeRow != null && !chequeRow.isUndefined() &&
59
        // if (chequeRow != null && !chequeRow.isUndefined() &&
60
        // chequeRow.getString("NUMERO").trim().length() > 0) {
60
        // chequeRow.getString("NUMERO").trim().length() > 0) {
61
        // num = " N° " + chequeRow.getString("NUMERO");
61
        // num = " N° " + chequeRow.getString("NUMERO");
62
        // }
62
        // }
63
        //
63
        //
64
        // if (s != null && s.trim().length() > 0) {
64
        // if (s != null && s.trim().length() > 0) {
65
        // this.nom = s + (num.trim().length() > 0 ? " - Cheque" + num : "");
65
        // this.nom = s + (num.trim().length() > 0 ? " - Cheque" + num : "");
66
        // } else {
66
        // } else {
67
        // this.nom = "Reglement cheque client" + num;
67
        // this.nom = "Reglement cheque client" + num;
68
        // }
68
        // }
69
    }
69
    }
70
 
70
 
71
    public void genere() throws Exception {
71
    public void genere() throws Exception {
72
        System.err.println("génération des ecritures de règlement d'un cheque client du mouvement " + this.idMvt);
72
        System.err.println("génération des ecritures de règlement d'un cheque client du mouvement " + this.idMvt);
73
        this.nom = this.depot.getString("NOM");
73
        this.nom = this.depot.getString("NOM");
74
        if (this.depot.getObject("ID_MOUVEMENT") == null || this.depot.isForeignEmpty("ID_MOUVEMENT")) {
74
        if (this.depot.getObject("ID_MOUVEMENT") == null || this.depot.isForeignEmpty("ID_MOUVEMENT")) {
75
            this.idMvt = getNewMouvement(depot.getTable().getName(), depot.getID(), 1, this.nom);
75
            this.idMvt = getNewMouvement(depot.getTable().getName(), depot.getID(), 1, this.nom);
76
        } else {
76
        } else {
77
            this.idMvt = this.depot.getForeignID("ID_MOUVEMENT");
77
            this.idMvt = this.depot.getForeignID("ID_MOUVEMENT");
78
            SQLRowValues rowValspiece = this.depot.getForeign("ID_MOUVEMENT").getForeign("ID_PIECE").createEmptyUpdateRow();
78
            SQLRowValues rowValspiece = this.depot.getForeign("ID_MOUVEMENT").getForeign("ID_PIECE").createEmptyUpdateRow();
79
            rowValspiece.put("NOM", this.nom);
79
            rowValspiece.put("NOM", this.nom);
80
            rowValspiece.update();
80
            rowValspiece.update();
81
        }
81
        }
82
 
82
 
83
        // initialisation des valeurs de la map
83
        // initialisation des valeurs de la map
84
        this.putValue("ID_MOUVEMENT", new Integer(this.idMvt));
84
        this.putValue("ID_MOUVEMENT", new Integer(this.idMvt));
85
        this.putValue("DATE", new java.sql.Date(this.date.getTime()));
85
        this.putValue("DATE", new java.sql.Date(this.date.getTime()));
86
        this.putValue("NOM", this.nom);
86
        this.putValue("NOM", this.nom);
87
        if (this.banque == null || this.banque.isUndefined() || this.banque.isForeignEmpty("ID_JOURNAL")) {
87
        if (this.banque == null || this.banque.isUndefined() || this.banque.isForeignEmpty("ID_JOURNAL")) {
88
            fillJournalBanqueFromRow(depot);
88
            fillJournalBanqueFromRow(depot);
89
        } else {
89
        } else {
90
            int idJrnl = this.banque.getForeignID("ID_JOURNAL");
90
            int idJrnl = this.banque.getForeignID("ID_JOURNAL");
91
            this.putValue("ID_JOURNAL", idJrnl);
91
            this.putValue("ID_JOURNAL", idJrnl);
92
        }
92
        }
93
 
93
 
94
        List<Integer> pieceIDs = new ArrayList<Integer>();
94
        List<Integer> pieceIDs = new ArrayList<Integer>();
95
        SQLRowValues rowValsDepotElt = new SQLRowValues(depot.getTable().getTable("DEPOT_CHEQUE_ELEMENT"));
95
        SQLRowValues rowValsDepotElt = new SQLRowValues(depot.getTable().getTable("DEPOT_CHEQUE_ELEMENT"));
96
        rowValsDepotElt.putNulls("MONTANT", "TIERS", "PIECE");
96
        rowValsDepotElt.putNulls("MONTANT", "TIERS", "PIECE");
97
        rowValsDepotElt.putRowValues("ID_CLIENT").putNulls("NOM", "ID_COMPTE_PCE");
97
        rowValsDepotElt.putRowValues("ID_CLIENT").putNulls("NOM", "ID_COMPTE_PCE");
98
        final SQLRowValues rowValuesChq = rowValsDepotElt.putRowValues("ID_CHEQUE_A_ENCAISSER");
98
        final SQLRowValues rowValuesChq = rowValsDepotElt.putRowValues("ID_CHEQUE_A_ENCAISSER");
99
        rowValuesChq.putNulls("SANS_VALEUR_ENCAISSEMENT").putRowValues("ID_MOUVEMENT").putNulls("ID_PIECE");
99
        rowValuesChq.putNulls("SANS_VALEUR_ENCAISSEMENT").putRowValues("ID_MOUVEMENT").putRowValues("ID_PIECE").putNulls("NOM");
100
        rowValuesChq.putNulls("ID_COMPTE_PCE_TIERS").putNulls("NUMERO");
100
        rowValuesChq.putNulls("ID_COMPTE_PCE_TIERS").putNulls("NUMERO");
101
        List<SQLRowValues> cheques = SQLRowValuesListFetcher.create(rowValsDepotElt).fetch(new Where(rowValsDepotElt.getTable().getField("ID_DEPOT_CHEQUE"), "=", depot.getID()));
101
        List<SQLRowValues> cheques = SQLRowValuesListFetcher.create(rowValsDepotElt).fetch(new Where(rowValsDepotElt.getTable().getField("ID_DEPOT_CHEQUE"), "=", depot.getID()));
102
        for (SQLRowValues sqlRowAccessor : cheques) {
102
        for (SQLRowValues sqlRowAccessor : cheques) {
103
            final SQLRowAccessor clientRow = sqlRowAccessor.getForeign("ID_CLIENT");
103
            final SQLRowAccessor clientRow = sqlRowAccessor.getForeign("ID_CLIENT");
104
            // this.nom = this.nom + " " + StringUtils.limitLength(clientRow.getString("NOM"), 20);
104
            // this.nom = this.nom + " " + StringUtils.limitLength(clientRow.getString("NOM"), 20);
105
            this.putValue("NOM", this.nom + " " + sqlRowAccessor.getString("PIECE") + " " + StringUtils.limitLength(clientRow.getString("NOM"), 20));
105
            this.putValue("NOM", this.nom + " " + sqlRowAccessor.getString("PIECE") + " " + StringUtils.limitLength(clientRow.getString("NOM"), 20));
106
            SQLRowAccessor chequeRow = sqlRowAccessor.getForeign("ID_CHEQUE_A_ENCAISSER");
106
            SQLRowAccessor chequeRow = sqlRowAccessor.getForeign("ID_CHEQUE_A_ENCAISSER");
107
            pieceIDs.add(chequeRow.getForeign("ID_MOUVEMENT").getForeignID("ID_PIECE"));
107
            pieceIDs.add(chequeRow.getForeign("ID_MOUVEMENT").getForeignID("ID_PIECE"));
108
            // compte Clients
108
            // compte Clients
109
            SQLRowAccessor rowCptTiers = chequeRow.getForeign("ID_COMPTE_PCE_TIERS");
109
            SQLRowAccessor rowCptTiers = chequeRow.getForeign("ID_COMPTE_PCE_TIERS");
110
            int idCompteClient = rowCptTiers != null && !rowCptTiers.isUndefined() ? rowCptTiers.getID() : -1;
110
            int idCompteClient = rowCptTiers != null && !rowCptTiers.isUndefined() ? rowCptTiers.getID() : -1;
111
 
111
 
112
            if (chequeRow.getBoolean("SANS_VALEUR_ENCAISSEMENT")) {
112
            if (chequeRow.getBoolean("SANS_VALEUR_ENCAISSEMENT")) {
113
                if (idCompteClient == -1) {
113
                if (idCompteClient == -1) {
114
                    if (clientRow != null) {
114
                    if (clientRow != null) {
115
                        idCompteClient = clientRow.getInt("ID_COMPTE_PCE");
115
                        idCompteClient = clientRow.getInt("ID_COMPTE_PCE");
116
                    }
116
                    }
117
                    if (idCompteClient <= 1) {
117
                    if (idCompteClient <= 1) {
118
                        idCompteClient = rowPrefsCompte.getInt("ID_COMPTE_PCE_CLIENT");
118
                        idCompteClient = rowPrefsCompte.getInt("ID_COMPTE_PCE_CLIENT");
119
                        if (idCompteClient <= 1) {
119
                        if (idCompteClient <= 1) {
120
                            idCompteClient = ComptePCESQLElement.getIdComptePceDefault("Clients");
120
                            idCompteClient = ComptePCESQLElement.getIdComptePceDefault("Clients");
121
                        }
121
                        }
122
                    }
122
                    }
123
                }
123
                }
124
            } else {
124
            } else {
125
                idCompteClient = rowPrefsCompte.getInt("ID_COMPTE_PCE_VALEUR_ENCAISSEMENT");
125
                idCompteClient = rowPrefsCompte.getInt("ID_COMPTE_PCE_VALEUR_ENCAISSEMENT");
126
                if (idCompteClient <= 1) {
126
                if (idCompteClient <= 1) {
127
                    idCompteClient = ComptePCESQLElement.getIdComptePceDefault("ValeurEncaissement");
127
                    idCompteClient = ComptePCESQLElement.getIdComptePceDefault("ValeurEncaissement");
128
                }
128
                }
129
            }
129
            }
130
 
130
 
131
            this.putValue("ID_COMPTE_PCE", new Integer(idCompteClient));
131
            this.putValue("ID_COMPTE_PCE", new Integer(idCompteClient));
132
            this.putValue("DEBIT", new Long(0));
132
            this.putValue("DEBIT", new Long(0));
133
            this.putValue("CREDIT", new Long(sqlRowAccessor.getLong("MONTANT")));
133
            this.putValue("CREDIT", new Long(sqlRowAccessor.getLong("MONTANT")));
134
            SQLRow insertedRow = ajoutEcriture();
134
            SQLRow insertedRow = ajoutEcriture();
135
 
135
 
136
            sqlRowAccessor.createEmptyUpdateRow().put("ID_ECRITURE", insertedRow.getID()).getGraph().store(StoreMode.COMMIT, false);
136
            sqlRowAccessor.createEmptyUpdateRow().put("ID_ECRITURE", insertedRow.getID()).getGraph().store(StoreMode.COMMIT, false);
137
            sqlRowAccessor.getForeign("ID_CHEQUE_A_ENCAISSER").createEmptyUpdateRow().put("ENCAISSE", Boolean.TRUE).getGraph().store(StoreMode.COMMIT, false);
137
            sqlRowAccessor.getForeign("ID_CHEQUE_A_ENCAISSER").createEmptyUpdateRow().put("ENCAISSE", Boolean.TRUE).getGraph().store(StoreMode.COMMIT, false);
138
        }
138
        }
139
        // compte de reglement cheque, ...
139
        // compte de reglement cheque, ...
140
        fillCompteBanqueFromRow(depot, "VenteCheque", false);
140
        fillCompteBanqueFromRow(depot, "VenteCheque", false);
141
        this.putValue("NOM", this.nom);
141
        this.putValue("NOM", this.nom);
142
        this.putValue("DEBIT", new Long(this.montant));
142
        this.putValue("DEBIT", new Long(this.montant));
143
        this.putValue("CREDIT", new Long(0));
143
        this.putValue("CREDIT", new Long(0));
144
        SQLRow insertedRow = ajoutEcriture();
144
        SQLRow insertedRow = ajoutEcriture();
145
 
145
 
146
        depot.createEmptyUpdateRow().put("ID_MOUVEMENT", idMvt).put("ID_ECRITURE", insertedRow.getID()).getGraph().store(StoreMode.COMMIT, false);
146
        depot.createEmptyUpdateRow().put("ID_MOUVEMENT", idMvt).put("ID_ECRITURE", insertedRow.getID()).getGraph().store(StoreMode.COMMIT, false);
147
 
147
 
148
        pieceIDs.add(mouvementTable.getRow(idMvt).getForeignID("ID_PIECE"));
148
        pieceIDs.add(mouvementTable.getRow(idMvt).getForeignID("ID_PIECE"));
149
        lettrageAuto(pieceIDs, this.date);
149
        lettrageAuto(pieceIDs, this.date);
150
 
150
 
151
        System.err.println("Ecritures générées pour le mouvement " + this.idMvt);
151
        System.err.println("Ecritures générées pour le mouvement " + this.idMvt);
152
 
152
 
153
    }
153
    }
154
 
154
 
155
    // private void setDateReglement(int idCheque, Date d) throws SQLException {
155
    // private void setDateReglement(int idCheque, Date d) throws SQLException {
156
    // if (idCheque > 1) {
156
    // if (idCheque > 1) {
157
    // SQLRow chequeRow =
157
    // SQLRow chequeRow =
158
    // Configuration.getInstance().getBase().getTable("CHEQUE_A_ENCAISSER").getRow(idCheque);
158
    // Configuration.getInstance().getBase().getTable("CHEQUE_A_ENCAISSER").getRow(idCheque);
159
    // final int sourceId = MouvementSQLElement.getSourceId(chequeRow.getInt("ID_MOUVEMENT"));
159
    // final int sourceId = MouvementSQLElement.getSourceId(chequeRow.getInt("ID_MOUVEMENT"));
160
    // SQLRow rowMvt = Configuration.getInstance().getBase().getTable("MOUVEMENT").getRow(sourceId);
160
    // SQLRow rowMvt = Configuration.getInstance().getBase().getTable("MOUVEMENT").getRow(sourceId);
161
    //
161
    //
162
    // if (rowMvt.getString("SOURCE").equalsIgnoreCase("SAISIE_VENTE_FACTURE")) {
162
    // if (rowMvt.getString("SOURCE").equalsIgnoreCase("SAISIE_VENTE_FACTURE")) {
163
    // SQLElement eltFacture =
163
    // SQLElement eltFacture =
164
    // Configuration.getInstance().getDirectory().getElement("SAISIE_VENTE_FACTURE");
164
    // Configuration.getInstance().getDirectory().getElement("SAISIE_VENTE_FACTURE");
165
    // SQLRow saisieRow = eltFacture.getTable().getRow(rowMvt.getInt("IDSOURCE"));
165
    // SQLRow saisieRow = eltFacture.getTable().getRow(rowMvt.getInt("IDSOURCE"));
166
    // // On fixe la date du paiement
166
    // // On fixe la date du paiement
167
    // SQLRowValues rowValsUpdateVF = saisieRow.createEmptyUpdateRow();
167
    // SQLRowValues rowValsUpdateVF = saisieRow.createEmptyUpdateRow();
168
    // rowValsUpdateVF.put("DATE_REGLEMENT", new Timestamp(d.getTime()));
168
    // rowValsUpdateVF.put("DATE_REGLEMENT", new Timestamp(d.getTime()));
169
    // rowValsUpdateVF.update();
169
    // rowValsUpdateVF.update();
170
    // }
170
    // }
171
    // }
171
    // }
172
    // }
172
    // }
173
 
173
 
174
}
174
}