OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 19 | Rev 80 | 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;
42
        if (s != null && s.trim().length() > 0) {
43
            this.nom = s;
44
        } else {
45
            this.nom = "Reglement cheque client";
46
        }
47
    }
18 ilm 48
 
73 ilm 49
    public void genere() throws Exception {
18 ilm 50
        System.err.println("génération des ecritures de règlement d'un cheque client du mouvement " + this.idMvt);
51
        SQLRow chequeRow = base.getTable("CHEQUE_A_ENCAISSER").getRow(this.idCheque);
52
        SQLRow clientRow = base.getTable("CLIENT").getRow(chequeRow.getInt("ID_CLIENT"));
53
 
73 ilm 54
        // initialisation des valeurs de la map
18 ilm 55
        this.mEcritures.put("DATE", new java.sql.Date(this.date.getTime()));
56
        this.mEcritures.put("NOM", this.nom);
57
        this.mEcritures.put("ID_JOURNAL", JournalSQLElement.BANQUES);
58
        this.mEcritures.put("ID_MOUVEMENT", new Integer(this.idMvt));
59
 
60
        setDateReglement(this.idCheque, this.date);
61
 
62
        // compte Clients
63
        int idCompteClient = -1;
64
        if (clientRow != null) {
65
            idCompteClient = clientRow.getInt("ID_COMPTE_PCE");
66
        }
67
        if (idCompteClient <= 1) {
68
            idCompteClient = rowPrefsCompte.getInt("ID_COMPTE_PCE_CLIENT");
69
            if (idCompteClient <= 1) {
73 ilm 70
                idCompteClient = ComptePCESQLElement.getIdComptePceDefault("Clients");
18 ilm 71
            }
72
        }
73
 
73 ilm 74
        int idPce = base.getTable("TYPE_REGLEMENT").getRow(2).getInt("ID_COMPTE_PCE_CLIENT");
75
        if (idPce <= 1) {
76
            idPce = ComptePCESQLElement.getIdComptePceDefault("VenteCheque");
77
        }
18 ilm 78
 
73 ilm 79
        this.mEcritures.put("ID_COMPTE_PCE", new Integer(idCompteClient));
80
        this.mEcritures.put("DEBIT", new Long(0));
81
        this.mEcritures.put("CREDIT", new Long(this.montant));
82
        ajoutEcriture();
83
        System.err.println("First ECriture for mvt " + this.idMvt);
84
 
85
        // compte de reglement cheque, ...
86
        this.mEcritures.put("ID_COMPTE_PCE", new Integer(idPce));
87
        this.mEcritures.put("DEBIT", new Long(this.montant));
88
        this.mEcritures.put("CREDIT", new Long(0));
89
        ajoutEcriture();
90
        System.err.println("Ecritures générées pour le mouvement " + this.idMvt);
91
 
18 ilm 92
    }
93
 
73 ilm 94
    private void setDateReglement(int idCheque, Date d) throws SQLException {
18 ilm 95
        if (idCheque > 1) {
96
            SQLRow chequeRow = Configuration.getInstance().getBase().getTable("CHEQUE_A_ENCAISSER").getRow(idCheque);
97
            final int sourceId = MouvementSQLElement.getSourceId(chequeRow.getInt("ID_MOUVEMENT"));
98
            SQLRow rowMvt = Configuration.getInstance().getBase().getTable("MOUVEMENT").getRow(sourceId);
99
 
100
            if (rowMvt.getString("SOURCE").equalsIgnoreCase("SAISIE_VENTE_FACTURE")) {
101
                SQLElement eltFacture = Configuration.getInstance().getDirectory().getElement("SAISIE_VENTE_FACTURE");
102
                SQLRow saisieRow = eltFacture.getTable().getRow(rowMvt.getInt("IDSOURCE"));
103
                // On fixe la date du paiement
104
                SQLRowValues rowValsUpdateVF = saisieRow.createEmptyUpdateRow();
105
                rowValsUpdateVF.put("DATE_REGLEMENT", new Timestamp(d.getTime()));
73 ilm 106
                rowValsUpdateVF.update();
18 ilm 107
            }
108
 
109
        }
110
 
111
    }
112
 
113
}