OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 156 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 156 Rev 177
1
/*
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 * 
3
 * 
4
 * Copyright 2011 OpenConcerto, by ILM Informatique. All rights reserved.
4
 * Copyright 2011 OpenConcerto, by ILM Informatique. All rights reserved.
5
 * 
5
 * 
6
 * The contents of this file are subject to the terms of the GNU General Public License Version 3
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
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
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.
9
 * language governing permissions and limitations under the License.
10
 * 
10
 * 
11
 * When distributing the software, include this License Header Notice in each file.
11
 * When distributing the software, include this License Header Notice in each file.
12
 */
12
 */
13
 
13
 
14
 package org.openconcerto.erp.generationEcritures;
14
 package org.openconcerto.erp.generationEcritures;
15
 
15
 
16
import org.openconcerto.erp.core.finance.accounting.element.ComptePCESQLElement;
16
import org.openconcerto.erp.core.finance.accounting.element.ComptePCESQLElement;
17
import org.openconcerto.erp.core.finance.accounting.element.JournalSQLElement;
17
import org.openconcerto.erp.core.finance.accounting.element.JournalSQLElement;
18
import org.openconcerto.erp.core.finance.tax.model.TaxeCache;
18
import org.openconcerto.erp.core.finance.tax.model.TaxeCache;
19
import org.openconcerto.erp.model.PrixHT;
19
import org.openconcerto.erp.model.PrixHT;
20
import org.openconcerto.erp.model.PrixTTC;
20
import org.openconcerto.erp.model.PrixTTC;
21
import org.openconcerto.sql.model.SQLRow;
21
import org.openconcerto.sql.model.SQLRow;
22
import org.openconcerto.sql.model.SQLRowAccessor;
22
import org.openconcerto.sql.model.SQLRowAccessor;
23
import org.openconcerto.sql.model.SQLRowValues;
23
import org.openconcerto.sql.model.SQLRowValues;
24
import org.openconcerto.sql.model.SQLTable;
24
import org.openconcerto.sql.model.SQLTable;
25
 
25
 
26
import java.util.Date;
26
import java.util.Date;
27
 
27
 
28
public class GenerationMvtAvoirFournisseur extends GenerationEcritures {
28
public class GenerationMvtAvoirFournisseur extends GenerationEcritures {
29
 
29
 
30
    private static final String source = "AVOIR_FOURNISSEUR";
30
    private static final String source = "AVOIR_FOURNISSEUR";
31
    // TODO dans quel journal les ecritures des avoirs? OD?
31
    // TODO dans quel journal les ecritures des avoirs? OD?
32
    private static final Integer journal = Integer.valueOf(JournalSQLElement.ACHATS);
32
    private static final Integer journal = Integer.valueOf(JournalSQLElement.ACHATS);
33
    private int idAvoirFourn;
33
    private int idAvoirFourn;
34
    private static final SQLTable tablePrefCompte = base.getTable("PREFS_COMPTE");
34
    private static final SQLTable tablePrefCompte = base.getTable("PREFS_COMPTE");
35
    private static final SQLRow rowPrefsCompte = tablePrefCompte.getRow(2);
35
    private static final SQLRow rowPrefsCompte = tablePrefCompte.getRow(2);
36
 
36
 
37
    public GenerationMvtAvoirFournisseur(SQLRow row) {
37
    public GenerationMvtAvoirFournisseur(SQLRow row) {
38
        this(row, 1);
38
        this(row, 1);
39
    }
39
    }
40
 
40
 
41
    public GenerationMvtAvoirFournisseur(SQLRow row, int idMvt) {
41
    public GenerationMvtAvoirFournisseur(SQLRow row, int idMvt) {
42
        this.idMvt = idMvt;
42
        this.idMvt = idMvt;
43
        this.idAvoirFourn = row.getID();
43
        this.idAvoirFourn = row.getID();
44
        setRowAnalytiqueSource(row);
44
        setRowAnalytiqueSource(row);
45
    }
45
    }
46
 
46
 
47
    public int genereMouvement() throws Exception {
47
    public int genereMouvement() throws Exception {
48
 
48
 
49
        SQLTable avoirFournTable = base.getTable("AVOIR_FOURNISSEUR");
49
        SQLTable avoirFournTable = base.getTable("AVOIR_FOURNISSEUR");
50
        SQLTable fournTable = base.getTable("FOURNISSEUR");
50
        SQLTable fournTable = base.getTable("FOURNISSEUR");
51
 
51
 
52
        SQLRow avoirRow = avoirFournTable.getRow(this.idAvoirFourn);
52
        SQLRow avoirRow = avoirFournTable.getRow(this.idAvoirFourn);
53
        SQLRow rowFourn = fournTable.getRow(avoirRow.getInt("ID_FOURNISSEUR"));
53
        SQLRow rowFourn = fournTable.getRow(avoirRow.getInt("ID_FOURNISSEUR"));
54
 
54
 
55
        // Calcul des montants
55
        // Calcul des montants
56
        PrixTTC prixTTC = new PrixTTC(((Long) avoirRow.getObject("MONTANT_TTC")).longValue());
56
        PrixTTC prixTTC = new PrixTTC(((Long) avoirRow.getObject("MONTANT_TTC")).longValue());
57
        PrixHT prixHT = new PrixHT(((Long) avoirRow.getObject("MONTANT_HT")).longValue());
57
        PrixHT prixHT = new PrixHT(((Long) avoirRow.getObject("MONTANT_HT")).longValue());
58
        PrixHT prixTVA = new PrixHT(((Long) avoirRow.getObject("MONTANT_TVA")).longValue());
58
        PrixHT prixTVA = new PrixHT(((Long) avoirRow.getObject("MONTANT_TVA")).longValue());
59
 
59
 
60
        // iniatilisation des valeurs de la map
60
        // iniatilisation des valeurs de la map
61
        this.date = (Date) avoirRow.getObject("DATE");
61
        this.date = (Date) avoirRow.getObject("DATE");
62
        this.nom = avoirRow.getObject("NOM").toString();
62
        this.nom = avoirRow.getObject("NOM").toString();
63
        this.putValue("DATE", new java.sql.Date(this.date.getTime()));
63
        this.putValue("DATE", new java.sql.Date(this.date.getTime()));
64
        this.putValue("NOM", "Avoir fournisseur : " + avoirRow.getString("NUMERO") + " " + rowFourn.getString("NOM"));
64
        this.putValue("NOM", "Avoir fournisseur : " + avoirRow.getString("NUMERO") + " " + rowFourn.getString("NOM"));
65
        this.putValue("ID_JOURNAL", GenerationMvtAvoirFournisseur.journal);
65
        this.putValue("ID_JOURNAL", GenerationMvtAvoirFournisseur.journal);
66
        this.putValue("ID_MOUVEMENT", Integer.valueOf(1));
66
        this.putValue("ID_MOUVEMENT", Integer.valueOf(1));
-
 
67
        if (rowFourn.getTable().getTable("ECRITURE").contains("CODE_CLIENT")) {
-
 
68
            this.putValue("CODE_CLIENT", rowFourn.getString("CODE"));
67
 
69
        }
68
        // on cree un nouveau mouvement
70
        // on cree un nouveau mouvement
69
        if (this.idMvt == 1) {
71
        if (this.idMvt == 1) {
70
            getNewMouvement(GenerationMvtAvoirFournisseur.source, this.idAvoirFourn, 1, "Avoir Fournisseur : " + avoirRow.getString("NUMERO"));
72
            getNewMouvement(GenerationMvtAvoirFournisseur.source, this.idAvoirFourn, 1, "Avoir Fournisseur : " + avoirRow.getString("NUMERO"));
71
        } else {
73
        } else {
72
            this.putValue("ID_MOUVEMENT", Integer.valueOf(this.idMvt));
74
            this.putValue("ID_MOUVEMENT", Integer.valueOf(this.idMvt));
73
        }
75
        }
74
 
76
 
75
        // generation des ecritures + maj des totaux du compte associe
77
        // generation des ecritures + maj des totaux du compte associe
76
 
78
 
77
        // compte Achat
79
        // compte Achat
78
        int idCompteAchat = avoirRow.getInt("ID_COMPTE_PCE");
80
        int idCompteAchat = avoirRow.getInt("ID_COMPTE_PCE");
79
 
81
 
80
        if (idCompteAchat <= 1) {
82
        if (idCompteAchat <= 1) {
81
            idCompteAchat = rowPrefsCompte.getInt("ID_COMPTE_PCE_ACHAT");
83
            idCompteAchat = rowPrefsCompte.getInt("ID_COMPTE_PCE_ACHAT");
82
            if (idCompteAchat <= 1) {
84
            if (idCompteAchat <= 1) {
83
                try {
85
                try {
84
                    idCompteAchat = ComptePCESQLElement.getIdComptePceDefault("Achats");
86
                    idCompteAchat = ComptePCESQLElement.getIdComptePceDefault("Achats");
85
                } catch (Exception e) {
87
                } catch (Exception e) {
86
                    e.printStackTrace();
88
                    e.printStackTrace();
87
                }
89
                }
88
            }
90
            }
89
        }
91
        }
-
 
92
 
90
        this.putValue("ID_COMPTE_PCE", Integer.valueOf(idCompteAchat));
93
        this.putValue("ID_COMPTE_PCE", Integer.valueOf(idCompteAchat));
91
        this.putValue("DEBIT", Long.valueOf(0));
94
        this.putValue("DEBIT", Long.valueOf(0));
92
        this.putValue("CREDIT", Long.valueOf(prixHT.getLongValue()));
95
        this.putValue("CREDIT", Long.valueOf(prixHT.getLongValue()));
93
        SQLRow rowEcr = ajoutEcriture();
96
        SQLRow rowEcr = ajoutEcriture();
94
        // addAssocAnalytiqueFromProvider(rowEcr, avoirRow);
97
        // addAssocAnalytiqueFromProvider(rowEcr, avoirRow);
95
 
98
 
96
        SQLRowAccessor taxe = TaxeCache.getCache().getRowFromId(avoirRow.getForeignID("ID_TAXE"));
99
        SQLRowAccessor taxe = TaxeCache.getCache().getRowFromId(avoirRow.getForeignID("ID_TAXE"));
97
        if (prixTVA.getLongValue() > 0) {
100
        if (prixTVA.getLongValue() > 0) {
98
            // compte TVA
101
            // compte TVA
99
            int idCompteTVA = rowPrefsCompte.getInt("ID_COMPTE_PCE_TVA_ACHAT");
102
            int idCompteTVA = rowPrefsCompte.getInt("ID_COMPTE_PCE_TVA_ACHAT");
100
            if (avoirRow.getBoolean("IMMO")) {
103
            if (avoirRow.getBoolean("IMMO")) {
101
                idCompteTVA = rowPrefsCompte.getInt("ID_COMPTE_PCE_TVA_IMMO");
104
                idCompteTVA = rowPrefsCompte.getInt("ID_COMPTE_PCE_TVA_IMMO");
102
                if (idCompteTVA <= 1) {
105
                if (idCompteTVA <= 1) {
103
                    idCompteTVA = ComptePCESQLElement.getIdComptePceDefault("TVAImmo");
106
                    idCompteTVA = ComptePCESQLElement.getIdComptePceDefault("TVAImmo");
104
                }
107
                }
105
            } else {
108
            } else {
106
                if (rowFourn.getBoolean("UE")) {
109
                if (rowFourn.getBoolean("UE")) {
107
                    idCompteTVA = taxe.getForeignID("ID_COMPTE_PCE_DED_INTRA");
110
                    idCompteTVA = taxe.getForeignID("ID_COMPTE_PCE_DED_INTRA");
108
                    if (idCompteTVA <= 1) {
111
                    if (idCompteTVA <= 1) {
109
                        idCompteTVA = rowPrefsCompte.getInt("ID_COMPTE_PCE_TVA_INTRA");
112
                        idCompteTVA = rowPrefsCompte.getInt("ID_COMPTE_PCE_TVA_INTRA");
110
                        if (idCompteTVA <= 1) {
113
                        if (idCompteTVA <= 1) {
111
                            idCompteTVA = ComptePCESQLElement.getIdComptePceDefault("TVAIntraComm");
114
                            idCompteTVA = ComptePCESQLElement.getIdComptePceDefault("TVAIntraComm");
112
                        }
115
                        }
113
                    }
116
                    }
114
                } else {
117
                } else {
115
                    idCompteTVA = rowPrefsCompte.getInt("ID_COMPTE_PCE_TVA_ACHAT");
118
                    idCompteTVA = rowPrefsCompte.getInt("ID_COMPTE_PCE_TVA_ACHAT");
116
                    if (idCompteTVA <= 1) {
119
                    if (idCompteTVA <= 1) {
117
                        idCompteTVA = ComptePCESQLElement.getIdComptePceDefault("TVADeductible");
120
                        idCompteTVA = ComptePCESQLElement.getIdComptePceDefault("TVADeductible");
118
                    }
121
                    }
119
                }
122
                }
120
            }
123
            }
121
 
124
 
122
            this.putValue("ID_COMPTE_PCE", Integer.valueOf(idCompteTVA));
125
            this.putValue("ID_COMPTE_PCE", Integer.valueOf(idCompteTVA));
123
            this.putValue("DEBIT", Long.valueOf(0));
126
            this.putValue("DEBIT", Long.valueOf(0));
124
            this.putValue("CREDIT", Long.valueOf(prixTVA.getLongValue()));
127
            this.putValue("CREDIT", Long.valueOf(prixTVA.getLongValue()));
125
            ajoutEcriture();
128
            ajoutEcriture();
126
 
129
 
127
            if (rowFourn.getBoolean("UE")) {
130
            if (rowFourn.getBoolean("UE")) {
128
                int idCompteTVAIntra = taxe.getForeignID("ID_COMPTE_PCE_COLLECTE_INTRA");
131
                int idCompteTVAIntra = taxe.getForeignID("ID_COMPTE_PCE_COLLECTE_INTRA");
129
                if (idCompteTVAIntra <= 1) {
132
                if (idCompteTVAIntra <= 1) {
130
                    idCompteTVAIntra = rowPrefsCompte.getInt("ID_COMPTE_PCE_TVA_INTRA");
133
                    idCompteTVAIntra = rowPrefsCompte.getInt("ID_COMPTE_PCE_TVA_INTRA");
131
                    if (idCompteTVAIntra <= 1) {
134
                    if (idCompteTVAIntra <= 1) {
132
                        idCompteTVAIntra = ComptePCESQLElement.getIdComptePceDefault("TVAIntraComm");
135
                        idCompteTVAIntra = ComptePCESQLElement.getIdComptePceDefault("TVAIntraComm");
133
                    }
136
                    }
134
                }
137
                }
135
                this.putValue("ID_COMPTE_PCE", Integer.valueOf(idCompteTVAIntra));
138
                this.putValue("ID_COMPTE_PCE", Integer.valueOf(idCompteTVAIntra));
136
                this.putValue("DEBIT", Long.valueOf(prixTVA.getLongValue()));
139
                this.putValue("DEBIT", Long.valueOf(prixTVA.getLongValue()));
137
                this.putValue("CREDIT", Long.valueOf(0));
140
                this.putValue("CREDIT", Long.valueOf(0));
138
                ajoutEcriture();
141
                ajoutEcriture();
139
            }
142
            }
140
        }
143
        }
141
        // compte Fournisseur
144
        // compte Fournisseur
142
        int idCompteFourn = rowFourn.getInt("ID_COMPTE_PCE");
145
        int idCompteFourn = rowFourn.getInt("ID_COMPTE_PCE");
143
        if (idCompteFourn <= 1) {
146
        if (idCompteFourn <= 1) {
144
            idCompteFourn = rowPrefsCompte.getInt("ID_COMPTE_PCE_FOURNISSEUR");
147
            idCompteFourn = rowPrefsCompte.getInt("ID_COMPTE_PCE_FOURNISSEUR");
145
            if (idCompteFourn <= 1) {
148
            if (idCompteFourn <= 1) {
146
                idCompteFourn = ComptePCESQLElement.getIdComptePceDefault("Fournisseurs");
149
                idCompteFourn = ComptePCESQLElement.getIdComptePceDefault("Fournisseurs");
147
            }
150
            }
148
        }
151
        }
149
        this.putValue("ID_COMPTE_PCE", Integer.valueOf(idCompteFourn));
152
        this.putValue("ID_COMPTE_PCE", Integer.valueOf(idCompteFourn));
150
        this.putValue("DEBIT", Long.valueOf(prixTTC.getLongValue()));
153
        this.putValue("DEBIT", Long.valueOf(prixTTC.getLongValue()));
151
        this.putValue("CREDIT", Long.valueOf(0));
154
        this.putValue("CREDIT", Long.valueOf(0));
152
        ajoutEcriture();
155
        ajoutEcriture();
153
 
156
 
154
        // Mise à jour de mouvement associé à la facture d'avoir
157
        // Mise à jour de mouvement associé à la facture d'avoir
155
        SQLRowValues valAvoir = new SQLRowValues(avoirFournTable);
158
        SQLRowValues valAvoir = new SQLRowValues(avoirFournTable);
156
        valAvoir.put("ID_MOUVEMENT", Integer.valueOf(this.idMvt));
159
        valAvoir.put("ID_MOUVEMENT", Integer.valueOf(this.idMvt));
157
 
160
 
158
        if (valAvoir.getInvalid() == null) {
161
        if (valAvoir.getInvalid() == null) {
159
 
162
 
160
            valAvoir.update(this.idAvoirFourn);
163
            valAvoir.update(this.idAvoirFourn);
161
            displayMvtNumber();
164
            displayMvtNumber();
162
        }
165
        }
163
 
166
 
164
        // if (avoirRow.getInt("ID_MODE_REGLEMENT") > 1) {
167
        // if (avoirRow.getInt("ID_MODE_REGLEMENT") > 1) {
165
        // new GenerationMvtReglementAvoir(this.idAvoirFourn, this.idMvt);
168
        // new GenerationMvtReglementAvoir(this.idAvoirFourn, this.idMvt);
166
        // } else {
169
        // } else {
167
        // valAvoir.put("SOLDE", Boolean.FALSE);
170
        // valAvoir.put("SOLDE", Boolean.FALSE);
168
        // try {
171
        // try {
169
        // valAvoir.update(this.idAvoirClient);
172
        // valAvoir.update(this.idAvoirClient);
170
        // } catch (SQLException e) {
173
        // } catch (SQLException e) {
171
        // e.printStackTrace();
174
        // e.printStackTrace();
172
        // }
175
        // }
173
        // }
176
        // }
174
 
177
 
175
        return this.idMvt;
178
        return this.idMvt;
176
    }
179
    }
177
}
180
}