OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 73 | 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.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_JOURNAL", JournalSQLElement.BANQUES);
64
        this.mEcritures.put("ID_MOUVEMENT", new Integer(this.idMvt));
65
 
66
        setDateReglement(this.idCheque, this.date);
67
 
68
        // compte Clients
69
        int idCompteClient = -1;
70
        if (clientRow != null) {
71
            idCompteClient = clientRow.getInt("ID_COMPTE_PCE");
72
        }
73
        if (idCompteClient <= 1) {
74
            idCompteClient = rowPrefsCompte.getInt("ID_COMPTE_PCE_CLIENT");
75
            if (idCompteClient <= 1) {
73 ilm 76
                idCompteClient = ComptePCESQLElement.getIdComptePceDefault("Clients");
18 ilm 77
            }
78
        }
79
 
73 ilm 80
        int idPce = base.getTable("TYPE_REGLEMENT").getRow(2).getInt("ID_COMPTE_PCE_CLIENT");
81
        if (idPce <= 1) {
82
            idPce = ComptePCESQLElement.getIdComptePceDefault("VenteCheque");
83
        }
18 ilm 84
 
73 ilm 85
        this.mEcritures.put("ID_COMPTE_PCE", new Integer(idCompteClient));
86
        this.mEcritures.put("DEBIT", new Long(0));
87
        this.mEcritures.put("CREDIT", new Long(this.montant));
88
        ajoutEcriture();
89
        System.err.println("First ECriture for mvt " + this.idMvt);
90
 
91
        // compte de reglement cheque, ...
92
        this.mEcritures.put("ID_COMPTE_PCE", new Integer(idPce));
93
        this.mEcritures.put("DEBIT", new Long(this.montant));
94
        this.mEcritures.put("CREDIT", new Long(0));
95
        ajoutEcriture();
96
        System.err.println("Ecritures générées pour le mouvement " + this.idMvt);
97
 
18 ilm 98
    }
99
 
73 ilm 100
    private void setDateReglement(int idCheque, Date d) throws SQLException {
18 ilm 101
        if (idCheque > 1) {
102
            SQLRow chequeRow = Configuration.getInstance().getBase().getTable("CHEQUE_A_ENCAISSER").getRow(idCheque);
103
            final int sourceId = MouvementSQLElement.getSourceId(chequeRow.getInt("ID_MOUVEMENT"));
104
            SQLRow rowMvt = Configuration.getInstance().getBase().getTable("MOUVEMENT").getRow(sourceId);
105
 
106
            if (rowMvt.getString("SOURCE").equalsIgnoreCase("SAISIE_VENTE_FACTURE")) {
107
                SQLElement eltFacture = Configuration.getInstance().getDirectory().getElement("SAISIE_VENTE_FACTURE");
108
                SQLRow saisieRow = eltFacture.getTable().getRow(rowMvt.getInt("IDSOURCE"));
109
                // On fixe la date du paiement
110
                SQLRowValues rowValsUpdateVF = saisieRow.createEmptyUpdateRow();
111
                rowValsUpdateVF.put("DATE_REGLEMENT", new Timestamp(d.getTime()));
73 ilm 112
                rowValsUpdateVF.update();
18 ilm 113
            }
114
 
115
        }
116
 
117
    }
118
 
119
}