OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

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