OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

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