OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 142 | 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.core.finance.accounting.report;
15
 
16
import org.openconcerto.erp.config.ComptaPropsConfiguration;
17
import org.openconcerto.erp.config.Gestion;
18
import org.openconcerto.erp.core.finance.accounting.element.ComptePCESQLElement;
19
import org.openconcerto.erp.core.finance.accounting.model.SommeCompte;
20
import org.openconcerto.sql.Configuration;
21
import org.openconcerto.sql.model.SQLBase;
22
import org.openconcerto.sql.model.SQLRow;
23
import org.openconcerto.sql.model.SQLRowValues;
24
import org.openconcerto.sql.model.SQLTable;
25
import org.openconcerto.utils.GestionDevise;
26
 
27
import java.util.Date;
28
import java.util.HashMap;
29
import java.util.Map;
30
 
31
import javax.swing.JProgressBar;
32
import javax.swing.SwingUtilities;
33
 
34
public class Map3310 extends Thread {
35
 
156 ilm 36
    private Map<String, String> m;
18 ilm 37
    private JProgressBar bar;
156 ilm 38
    private Date dateDebut;
39
    private Date dateFin;
40
    private static final SQLBase base = ((ComptaPropsConfiguration) Configuration.getInstance()).getSQLBaseSociete();
18 ilm 41
    private static final SQLTable tablePrefCompte = base.getTable("PREFS_COMPTE");
42
    private static final SQLTable tableCompte = Configuration.getInstance().getRoot().findTable("COMPTE_PCE");
43
    private SQLRowValues rowPrefCompteVals = new SQLRowValues(tablePrefCompte);
44
    SommeCompte sommeCompte;
45
 
46
    // TODO if value = 0.0 ne pas mettre -0.0
47
 
48
    public void run() {
49
 
50
        SQLRow rowPrefCompte = tablePrefCompte.getRow(2);
51
        this.rowPrefCompteVals.loadAbsolutelyAll(rowPrefCompte);
52
        // TVA Coll
53
        int idCompteTVACol = this.rowPrefCompteVals.getInt("ID_COMPTE_PCE_TVA_VENTE");
54
        if (idCompteTVACol <= 1) {
55
            String compte;
56
            try {
57
                compte = ComptePCESQLElement.getComptePceDefault("TVACollectee");
58
                idCompteTVACol = ComptePCESQLElement.getId(compte);
59
            } catch (Exception e) {
60
                e.printStackTrace();
61
            }
62
        }
63
        SQLRow rowCompteTVACol = tableCompte.getRow(idCompteTVACol);
64
 
65
        // TVA Ded
66
        int idCompteTVADed = this.rowPrefCompteVals.getInt("ID_COMPTE_PCE_TVA_ACHAT");
67
        if (idCompteTVADed <= 1) {
68
            try {
69
                String compte = ComptePCESQLElement.getComptePceDefault("TVADeductible");
70
                idCompteTVADed = ComptePCESQLElement.getId(compte);
71
            } catch (Exception e) {
72
                e.printStackTrace();
73
            }
74
        }
75
        SQLRow rowCompteTVADed = tableCompte.getRow(idCompteTVADed);
76
 
77
        // TVA intracomm
78
        int idCompteTVAIntra = this.rowPrefCompteVals.getInt("ID_COMPTE_PCE_TVA_INTRA");
79
        if (idCompteTVAIntra <= 1) {
80
            try {
81
                String compte = ComptePCESQLElement.getComptePceDefault("TVAIntraComm");
82
                idCompteTVAIntra = ComptePCESQLElement.getId(compte);
83
            } catch (Exception e) {
84
                e.printStackTrace();
85
            }
86
        }
87
        SQLRow rowCompteTVAIntra = tableCompte.getRow(idCompteTVAIntra);
88
 
89
        // Achats intracomm
90
        int idCompteAchatsIntra = this.rowPrefCompteVals.getInt("ID_COMPTE_PCE_ACHAT_INTRA");
91
        if (idCompteAchatsIntra <= 1) {
92
            try {
93
                String compte = ComptePCESQLElement.getComptePceDefault("AchatsIntra");
94
                idCompteAchatsIntra = ComptePCESQLElement.getId(compte);
95
            } catch (Exception e) {
96
                e.printStackTrace();
97
            }
98
        }
99
        SQLRow rowCompteAchatIntra = tableCompte.getRow(idCompteAchatsIntra);
100
 
101
        // TVA immo
102
        int idCompteTVAImmo = this.rowPrefCompteVals.getInt("ID_COMPTE_PCE_TVA_IMMO");
103
        if (idCompteTVAImmo <= 1) {
104
            try {
105
                String compte = ComptePCESQLElement.getComptePceDefault("TVAImmo");
106
                idCompteTVAImmo = ComptePCESQLElement.getId(compte);
107
            } catch (Exception e) {
108
                e.printStackTrace();
109
            }
110
        }
111
        SQLRow rowCompteTVAImmo = tableCompte.getRow(idCompteTVAImmo);
112
 
113
        PdfGenerator_3310 p = new PdfGenerator_3310();
156 ilm 114
        this.m = new HashMap<String, String>();
18 ilm 115
 
116
        long v010 = -this.sommeCompte.soldeCompte(70, 70, true, this.dateDebut, this.dateFin);
21 ilm 117
        this.m.put("A01", GestionDevise.round(v010));
18 ilm 118
 
119
        this.m.put("A02", "");
41 ilm 120
        long tvaIntra = -this.sommeCompte.sommeCompteFils(rowCompteTVAIntra.getString("NUMERO"), this.dateDebut, this.dateFin);
18 ilm 121
        long achatsIntra = this.sommeCompte.sommeCompteFils(rowCompteAchatIntra.getString("NUMERO"), this.dateDebut, this.dateFin);
21 ilm 122
        this.m.put("A03", GestionDevise.round(achatsIntra));
18 ilm 123
        this.m.put("A04", "");
124
        this.m.put("A05", "");
125
        this.m.put("A06", "");
126
        this.m.put("A07", "");
127
 
41 ilm 128
        long tvaCol = -this.sommeCompte.sommeCompteFils(rowCompteTVACol.getString("NUMERO"), this.dateDebut, this.dateFin) + tvaIntra;
21 ilm 129
        this.m.put("B08", GestionDevise.round(tvaCol));
130
        this.m.put("B08HT", GestionDevise.round(Math.round(tvaCol / 0.196)));
18 ilm 131
        this.m.put("B09", "");
132
        this.m.put("B09HT", "");
133
        this.m.put("B09B", "");
134
        this.m.put("B09BHT", "");
135
 
136
        this.m.put("B10", "");
137
        this.m.put("B10HT", "");
138
        this.m.put("B11", "");
139
        this.m.put("B11HT", "");
140
        this.m.put("B12", "");
141
        this.m.put("B12HT", "");
142
        this.m.put("B13", "");
143
        this.m.put("B13HT", "");
144
        this.m.put("B14", "");
145
        this.m.put("B14HT", "");
146
 
147
        this.m.put("B15", "");
21 ilm 148
        this.m.put("B16", GestionDevise.round(tvaCol));
149
        this.m.put("B17", GestionDevise.round(tvaIntra));
18 ilm 150
        this.m.put("B18", "");
73 ilm 151
        final String numeroCptTVAImmo = rowCompteTVAImmo.getString("NUMERO");
152
        long tvaImmo = this.sommeCompte.sommeCompteFils(numeroCptTVAImmo, this.dateDebut, this.dateFin);
21 ilm 153
        this.m.put("B19", GestionDevise.round(tvaImmo));
18 ilm 154
 
73 ilm 155
        final String numeroCptTVADed = rowCompteTVADed.getString("NUMERO");
156
        long tvaAutre = this.sommeCompte.sommeCompteFils(numeroCptTVADed, this.dateDebut, this.dateFin);
157
 
158
        // Déduction de la tva sur immo si elle fait partie des sous comptes
159
        if (numeroCptTVAImmo.startsWith(numeroCptTVADed)) {
160
            tvaAutre -= tvaImmo;
161
        }
162
 
21 ilm 163
        this.m.put("B20", GestionDevise.round(tvaAutre));
18 ilm 164
        this.m.put("B21", "");
165
        this.m.put("B22", "");
166
        this.m.put("B23", "");
21 ilm 167
        long tvaDed = tvaAutre + tvaImmo;
168
        this.m.put("B24", GestionDevise.round(tvaDed));
18 ilm 169
 
170
        this.m.put("C25", "");
171
        this.m.put("C26", "");
172
        this.m.put("C27", "");
21 ilm 173
        this.m.put("C28", GestionDevise.round(tvaCol - tvaDed));
18 ilm 174
        this.m.put("C29", "");
175
        this.m.put("C30", "");
176
        this.m.put("C31", "");
21 ilm 177
        this.m.put("C32", GestionDevise.round(tvaCol - tvaDed));
18 ilm 178
 
179
        p.generateFrom(this.m);
180
 
181
        SwingUtilities.invokeLater(new Runnable() {
182
            public void run() {
183
                Map3310.this.bar.setValue(95);
184
            }
185
        });
186
 
187
        SwingUtilities.invokeLater(new Runnable() {
188
            public void run() {
156 ilm 189
                Gestion.openPDF(p.getGeneratedFile());
18 ilm 190
                Map3310.this.bar.setValue(100);
191
            }
192
        });
193
 
194
    }
195
 
196
    public Map3310(JProgressBar bar, Date dateDeb, Date dateFin) {
197
        this.bar = bar;
198
        if (dateDeb == null && dateFin == null) {
199
            SQLRow rowSociete = ((ComptaPropsConfiguration) Configuration.getInstance()).getRowSociete();
200
            SQLRow rowExercice = Configuration.getInstance().getBase().getTable("EXERCICE_COMMON").getRow(rowSociete.getInt("ID_EXERCICE_COMMON"));
201
            dateFin = (Date) rowExercice.getObject("DATE_FIN");
202
            dateDeb = (Date) rowExercice.getObject("DATE_DEB");
203
        }
204
        this.dateDebut = dateDeb;
205
        this.dateFin = dateFin;
206
        this.sommeCompte = new SommeCompte();
207
    }
208
 
209
    public Map3310(JProgressBar bar) {
210
        this(bar, null, null);
211
    }
212
 
213
    public void generateMap2033A() {
214
        this.start();
215
    }
216
}