OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 83 | Rev 144 | 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.generationEcritures;
15
 
16
import org.openconcerto.erp.core.finance.accounting.element.ComptePCESQLElement;
17
import org.openconcerto.erp.core.finance.accounting.element.JournalSQLElement;
18
import org.openconcerto.erp.core.finance.accounting.element.MouvementSQLElement;
19
import org.openconcerto.sql.Configuration;
20
import org.openconcerto.sql.element.SQLElement;
21
import org.openconcerto.sql.model.SQLRow;
22
import org.openconcerto.sql.model.SQLRowValues;
23
import org.openconcerto.sql.model.SQLTable;
24
 
25
import java.sql.SQLException;
26
import java.sql.Timestamp;
27
import java.util.Date;
28
 
29
public class GenerationMvtReglementChequeClient extends GenerationEcritures {
30
 
31
    private long montant;
32
 
33
    private static final SQLTable tablePrefCompte = base.getTable("PREFS_COMPTE");
34
    private static final SQLRow rowPrefsCompte = tablePrefCompte.getRow(2);
35
    private int idCheque;
36
 
73 ilm 37
    public GenerationMvtReglementChequeClient(int idMvt, long montant, Date d, int idCheque, String s) {
38
        this.montant = montant;
39
        this.date = d;
40
        this.idMvt = idMvt;
41
        this.idCheque = idCheque;
80 ilm 42
        SQLRow chequeRow = base.getTable("CHEQUE_A_ENCAISSER").getRow(this.idCheque);
43
        String num = "";
44
        if (chequeRow != null && !chequeRow.isUndefined() && chequeRow.getString("NUMERO").trim().length() > 0) {
45
            num = " N° " + chequeRow.getString("NUMERO");
46
        }
47
 
73 ilm 48
        if (s != null && s.trim().length() > 0) {
80 ilm 49
            this.nom = s + (num.trim().length() > 0 ? " - Cheque" + num : "");
73 ilm 50
        } else {
80 ilm 51
            this.nom = "Reglement cheque client" + num;
73 ilm 52
        }
53
    }
18 ilm 54
 
73 ilm 55
    public void genere() throws Exception {
18 ilm 56
        System.err.println("génération des ecritures de règlement d'un cheque client du mouvement " + this.idMvt);
57
        SQLRow chequeRow = base.getTable("CHEQUE_A_ENCAISSER").getRow(this.idCheque);
58
        SQLRow clientRow = base.getTable("CLIENT").getRow(chequeRow.getInt("ID_CLIENT"));
59
 
73 ilm 60
        // initialisation des valeurs de la map
18 ilm 61
        this.mEcritures.put("DATE", new java.sql.Date(this.date.getTime()));
62
        this.mEcritures.put("NOM", this.nom);
63
        this.mEcritures.put("ID_MOUVEMENT", new Integer(this.idMvt));
64
 
83 ilm 65
        fillJournalBanqueFromRow(chequeRow);
66
 
18 ilm 67
        setDateReglement(this.idCheque, this.date);
68
 
69
        // compte Clients
70
        int idCompteClient = -1;
142 ilm 71
        if (chequeRow.getBoolean("SANS_VALEUR_ENCAISSEMENT")) {
72
            if (clientRow != null) {
73
                idCompteClient = clientRow.getInt("ID_COMPTE_PCE");
74
            }
18 ilm 75
            if (idCompteClient <= 1) {
142 ilm 76
                idCompteClient = rowPrefsCompte.getInt("ID_COMPTE_PCE_CLIENT");
77
                if (idCompteClient <= 1) {
78
                    idCompteClient = ComptePCESQLElement.getIdComptePceDefault("Clients");
79
                }
18 ilm 80
            }
142 ilm 81
        } else {
82
            idCompteClient = rowPrefsCompte.getInt("ID_COMPTE_PCE_VALEUR_ENCAISSEMENT");
83
            if (idCompteClient <= 1) {
84
                idCompteClient = ComptePCESQLElement.getIdComptePceDefault("ValeurEncaissement");
85
            }
18 ilm 86
        }
87
 
73 ilm 88
        this.mEcritures.put("ID_COMPTE_PCE", new Integer(idCompteClient));
89
        this.mEcritures.put("DEBIT", new Long(0));
90
        this.mEcritures.put("CREDIT", new Long(this.montant));
91
        ajoutEcriture();
92
        System.err.println("First ECriture for mvt " + this.idMvt);
93
 
94
        // compte de reglement cheque, ...
83 ilm 95
        fillCompteBanqueFromRow(chequeRow, "VenteCheque", false);
73 ilm 96
        this.mEcritures.put("DEBIT", new Long(this.montant));
97
        this.mEcritures.put("CREDIT", new Long(0));
98
        ajoutEcriture();
99
        System.err.println("Ecritures générées pour le mouvement " + this.idMvt);
100
 
18 ilm 101
    }
102
 
73 ilm 103
    private void setDateReglement(int idCheque, Date d) throws SQLException {
18 ilm 104
        if (idCheque > 1) {
105
            SQLRow chequeRow = Configuration.getInstance().getBase().getTable("CHEQUE_A_ENCAISSER").getRow(idCheque);
106
            final int sourceId = MouvementSQLElement.getSourceId(chequeRow.getInt("ID_MOUVEMENT"));
107
            SQLRow rowMvt = Configuration.getInstance().getBase().getTable("MOUVEMENT").getRow(sourceId);
108
 
109
            if (rowMvt.getString("SOURCE").equalsIgnoreCase("SAISIE_VENTE_FACTURE")) {
110
                SQLElement eltFacture = Configuration.getInstance().getDirectory().getElement("SAISIE_VENTE_FACTURE");
111
                SQLRow saisieRow = eltFacture.getTable().getRow(rowMvt.getInt("IDSOURCE"));
112
                // On fixe la date du paiement
113
                SQLRowValues rowValsUpdateVF = saisieRow.createEmptyUpdateRow();
114
                rowValsUpdateVF.put("DATE_REGLEMENT", new Timestamp(d.getTime()));
73 ilm 115
                rowValsUpdateVF.update();
18 ilm 116
            }
117
 
118
        }
119
 
120
    }
121
 
122
}