OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 149 | 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
 *
185 ilm 4
 * Copyright 2011-2019 OpenConcerto, by ILM Informatique. All rights reserved.
18 ilm 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.sql.model.SQLRow;
19
import org.openconcerto.sql.model.SQLRowValues;
20
import org.openconcerto.sql.model.SQLTable;
21
import org.openconcerto.utils.GestionDevise;
22
 
23
import java.sql.SQLException;
24
import java.util.Date;
25
 
185 ilm 26
public final class GenerationMvtAcompte extends GenerationEcritures {
18 ilm 27
 
28
    private int idSalarie;
29
    private long montant;
30
    private int idAcompte;
31
 
32
    private static final SQLTable tableSalarie = base.getTable("SALARIE");
33
    private static final SQLTable tableAcompte = base.getTable("ACOMPTE");
34
    // Journal OD
35
    private static final Integer journalOD = Integer.valueOf(JournalSQLElement.OD);
36
    private static final SQLTable tablePrefCompte = base.getTable("PREFS_COMPTE");
37
    private static final SQLRow rowPrefsCompte = tablePrefCompte.getRow(2);
38
 
93 ilm 39
    public GenerationMvtAcompte(SQLRow rowAcompte) throws SQLException {
40
        this.idAcompte = rowAcompte.getID();
41
        setRowAnalytiqueSource(rowAcompte);
18 ilm 42
        this.idSalarie = rowAcompte.getInt("ID_SALARIE");
43
        this.montant = GestionDevise.parseLongCurrency(String.valueOf(rowAcompte.getFloat("MONTANT")));
44
        SQLRow rowSal = tableSalarie.getRow(this.idSalarie);
45
        this.idMvt = getNewMouvement("ACOMPTE", this.idAcompte, 1, "Acompte " + rowSal.getString("NOM"));
185 ilm 46
        genereComptaAcompte();
18 ilm 47
    }
48
 
185 ilm 49
    private void genereComptaAcompte() throws SQLException {
18 ilm 50
 
51
        System.out.println("Génération des ecritures du mouvement " + this.idMvt);
52
 
53
        SQLRow rowSal = tableSalarie.getRow(this.idSalarie);
54
        // iniatilisation des valeurs de la map
55
        this.date = new Date();
56
        // TODO recuperer le mois et l'année
57
        this.nom = "Acompte " + rowSal.getString("NOM");
149 ilm 58
        this.putValue("DATE", new java.sql.Date(this.date.getTime()));
59
        this.putValue("NOM", this.nom);
60
        this.putValue("ID_JOURNAL", journalOD);
61
        this.putValue("ID_MOUVEMENT", Integer.valueOf(this.idMvt));
18 ilm 62
 
63
        // Acompte
64
        int idCompteAcompte = rowPrefsCompte.getInt("ID_COMPTE_PCE_ACOMPTE");
65
        if (idCompteAcompte <= 1) {
73 ilm 66
            idCompteAcompte = ComptePCESQLElement.getIdComptePceDefault("PayeAcompte");
18 ilm 67
        }
68
 
149 ilm 69
        this.putValue("ID_COMPTE_PCE", Integer.valueOf(idCompteAcompte));
70
        this.putValue("NOM", this.nom);
71
        this.putValue("DEBIT", Long.valueOf(this.montant));
72
        this.putValue("CREDIT", Long.valueOf(0));
18 ilm 73
 
73 ilm 74
        ajoutEcriture();
18 ilm 75
 
73 ilm 76
        // Trésorie
77
        int idCompteTresor = rowPrefsCompte.getInt("ID_COMPTE_PCE_ACOMPTE_REGL");
78
        if (idCompteTresor <= 1) {
79
            try {
80
                idCompteTresor = ComptePCESQLElement.getIdComptePceDefault("PayeReglementAcompte");
81
            } catch (Exception e) {
82
 
83
                e.printStackTrace();
18 ilm 84
            }
85
        }
149 ilm 86
        this.putValue("ID_COMPTE_PCE", Integer.valueOf(idCompteTresor));
87
        this.putValue("NOM", this.nom);
88
        this.putValue("DEBIT", Long.valueOf(0));
89
        this.putValue("CREDIT", Long.valueOf(this.montant));
18 ilm 90
 
73 ilm 91
        ajoutEcriture();
92
 
18 ilm 93
        // Replace mvt
94
        SQLRowValues rowVals = new SQLRowValues(tableAcompte);
95
        rowVals.put("ID_MOUVEMENT", Integer.valueOf(this.idMvt));
73 ilm 96
 
97
        rowVals.update(this.idAcompte);
98
 
18 ilm 99
    }
100
 
101
}