OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 156 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 156 Rev 185
Line 1... Line 1...
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-2019 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.
Line 17... Line 17...
17
import org.openconcerto.erp.core.common.ui.TotalCalculator;
17
import org.openconcerto.erp.core.common.ui.TotalCalculator;
18
import org.openconcerto.erp.core.finance.accounting.element.ComptePCESQLElement;
18
import org.openconcerto.erp.core.finance.accounting.element.ComptePCESQLElement;
19
import org.openconcerto.erp.core.finance.accounting.element.JournalSQLElement;
19
import org.openconcerto.erp.core.finance.accounting.element.JournalSQLElement;
20
import org.openconcerto.erp.generationEcritures.provider.AccountingRecordsProvider;
20
import org.openconcerto.erp.generationEcritures.provider.AccountingRecordsProvider;
21
import org.openconcerto.erp.generationEcritures.provider.AccountingRecordsProviderManager;
21
import org.openconcerto.erp.generationEcritures.provider.AccountingRecordsProviderManager;
-
 
22
import org.openconcerto.erp.preferences.DefaultNXProps;
22
import org.openconcerto.sql.Configuration;
23
import org.openconcerto.sql.Configuration;
23
import org.openconcerto.sql.model.SQLRow;
24
import org.openconcerto.sql.model.SQLRow;
24
import org.openconcerto.sql.model.SQLRowAccessor;
25
import org.openconcerto.sql.model.SQLRowAccessor;
25
import org.openconcerto.sql.model.SQLRowValues;
26
import org.openconcerto.sql.model.SQLRowValues;
26
import org.openconcerto.sql.model.SQLTable;
27
import org.openconcerto.sql.model.SQLTable;
Line 50... Line 51...
50
        setRowAnalytiqueSource(row);
51
        setRowAnalytiqueSource(row);
51
        this.idAvoirClient = row.getID();
52
        this.idAvoirClient = row.getID();
52
    }
53
    }
53
 
54
 
54
    public int genereMouvement() throws Exception {
55
    public int genereMouvement() throws Exception {
-
 
56
        boolean genEcrDisabled = DefaultNXProps.getInstance().getBooleanValue(GenerationMvtSaisieVenteFacture.NOT_GEN_ECRITURE, false);
55
 
57
 
56
        SQLTable avoirClientTable = base.getTable("AVOIR_CLIENT");
58
        SQLTable avoirClientTable = base.getTable("AVOIR_CLIENT");
57
 
59
 
58
        SQLRow avoirRow = avoirClientTable.getRow(this.idAvoirClient);
60
        SQLRow avoirRow = avoirClientTable.getRow(this.idAvoirClient);
59
 
61
 
Line 118... Line 120...
118
                        if (compl.get(rowCompl) != null) {
120
                        if (compl.get(rowCompl) != null) {
119
                            long taxeC = compl.get(rowCompl).multiply(rowCompl.getBigDecimal("POURCENT").movePointLeft(2)).setScale(2, RoundingMode.HALF_UP).movePointRight(2).longValue();
121
                            long taxeC = compl.get(rowCompl).multiply(rowCompl.getBigDecimal("POURCENT").movePointLeft(2)).setScale(2, RoundingMode.HALF_UP).movePointRight(2).longValue();
120
                            this.putValue("ID_COMPTE_PCE", rowCompl.getForeignID("ID_COMPTE_PCE"));
122
                            this.putValue("ID_COMPTE_PCE", rowCompl.getForeignID("ID_COMPTE_PCE"));
121
                            this.putValue("CREDIT", Long.valueOf(0));
123
                            this.putValue("CREDIT", Long.valueOf(0));
122
                            this.putValue("DEBIT", Long.valueOf(taxeC));
124
                            this.putValue("DEBIT", Long.valueOf(taxeC));
-
 
125
                            if (!genEcrDisabled) {
123
                            ajoutEcriture();
126
                                ajoutEcriture();
-
 
127
                            }
124
                            taxe += taxeC;
128
                            taxe += taxeC;
125
                            // this.putValue("ID_COMPTE_PCE",
129
                            // this.putValue("ID_COMPTE_PCE",
126
                            // rowCompl.getForeignID("ID_COMPTE_PCE_PRODUITS"));
130
                            // rowCompl.getForeignID("ID_COMPTE_PCE_PRODUITS"));
127
                            // this.putValue("CREDIT", Long.valueOf(taxeC));
131
                            // this.putValue("CREDIT", Long.valueOf(taxeC));
128
                            // this.putValue("DEBIT", Long.valueOf(0));
132
                            // this.putValue("DEBIT", Long.valueOf(0));
Line 132... Line 136...
132
                }
136
                }
133
 
137
 
134
                this.putValue("ID_COMPTE_PCE", row.getID());
138
                this.putValue("ID_COMPTE_PCE", row.getID());
135
                this.putValue("DEBIT", Long.valueOf(b - taxe));
139
                this.putValue("DEBIT", Long.valueOf(b - taxe));
136
                this.putValue("CREDIT", Long.valueOf(0));
140
                this.putValue("CREDIT", Long.valueOf(0));
-
 
141
                if (!genEcrDisabled) {
137
                SQLRow rowEcr = ajoutEcriture();
142
                    SQLRow rowEcr = ajoutEcriture();
138
                // addAssocAnalytiqueFromProvider(rowEcr, avoirRow);
143
                    // addAssocAnalytiqueFromProvider(rowEcr, avoirRow);
139
            }
144
                }
140
        }
145
            }
-
 
146
        }
141
 
147
 
142
        // compte TVA
148
        // compte TVA
143
        Map<SQLRowAccessor, BigDecimal> tvaMap = calc.getMapHtTVA();
149
        Map<SQLRowAccessor, BigDecimal> tvaMap = calc.getMapHtTVA();
144
        for (SQLRowAccessor rowAc : tvaMap.keySet()) {
150
        for (SQLRowAccessor rowAc : tvaMap.keySet()) {
145
            long longValue = tvaMap.get(rowAc).setScale(2, RoundingMode.HALF_UP).movePointRight(2).longValue();
151
            long longValue = tvaMap.get(rowAc).setScale(2, RoundingMode.HALF_UP).movePointRight(2).longValue();
146
            if (longValue != 0) {
152
            if (longValue != 0) {
147
                this.putValue("ID_COMPTE_PCE", rowAc.getID());
153
                this.putValue("ID_COMPTE_PCE", rowAc.getID());
148
                this.putValue("DEBIT", Long.valueOf(longValue));
154
                this.putValue("DEBIT", Long.valueOf(longValue));
149
                this.putValue("CREDIT", Long.valueOf(0));
155
                this.putValue("CREDIT", Long.valueOf(0));
-
 
156
                if (!genEcrDisabled) {
150
                ajoutEcriture();
157
                    ajoutEcriture();
151
            }
158
                }
152
        }
159
            }
-
 
160
        }
153
 
161
 
154
        // compte Clients
162
        // compte Clients
155
        int idCompteClient = avoirRow.getForeignRow("ID_CLIENT").getInt("ID_COMPTE_PCE");
163
        int idCompteClient = avoirRow.getForeignRow("ID_CLIENT").getInt("ID_COMPTE_PCE");
156
        if (idCompteClient <= 1) {
164
        if (idCompteClient <= 1) {
157
            idCompteClient = rowPrefsCompte.getInt("ID_COMPTE_PCE_CLIENT");
165
            idCompteClient = rowPrefsCompte.getInt("ID_COMPTE_PCE_CLIENT");
Line 162... Line 170...
162
 
170
 
163
        this.putValue("ID_COMPTE_PCE", Integer.valueOf(idCompteClient));
171
        this.putValue("ID_COMPTE_PCE", Integer.valueOf(idCompteClient));
164
        this.putValue("DEBIT", Long.valueOf(0));
172
        this.putValue("DEBIT", Long.valueOf(0));
165
        long ttc = calc.getTotalTTC().movePointRight(2).longValue();
173
        long ttc = calc.getTotalTTC().movePointRight(2).longValue();
166
        this.putValue("CREDIT", Long.valueOf(ttc));
174
        this.putValue("CREDIT", Long.valueOf(ttc));
-
 
175
        if (!genEcrDisabled) {
167
        ajoutEcriture();
176
            ajoutEcriture();
168
 
177
        }
169
        // Mise à jour de mouvement associé à la facture d'avoir
178
        // Mise à jour de mouvement associé à la facture d'avoir
170
        SQLRowValues valAvoir = new SQLRowValues(avoirClientTable);
179
        SQLRowValues valAvoir = new SQLRowValues(avoirClientTable);
171
        valAvoir.put("ID_MOUVEMENT", Integer.valueOf(this.idMvt));
180
        valAvoir.put("ID_MOUVEMENT", Integer.valueOf(this.idMvt));
172
 
181
 
173
        if (valAvoir.getInvalid() == null) {
182
        if (valAvoir.getInvalid() == null) {
Line 177... Line 186...
177
 
186
 
178
        if (affacturage) {
187
        if (affacturage) {
179
            this.putValue("ID_COMPTE_PCE", Integer.valueOf(idCompteClient));
188
            this.putValue("ID_COMPTE_PCE", Integer.valueOf(idCompteClient));
180
            this.putValue("DEBIT", Long.valueOf(ttc));
189
            this.putValue("DEBIT", Long.valueOf(ttc));
181
            this.putValue("CREDIT", Long.valueOf(0));
190
            this.putValue("CREDIT", Long.valueOf(0));
-
 
191
            if (!genEcrDisabled) {
182
            ajoutEcriture();
192
                ajoutEcriture();
183
 
193
            }
184
            // compte Factor
194
            // compte Factor
185
            int idComptefactor = rowPrefsCompte.getInt("ID_COMPTE_PCE_FACTOR");
195
            int idComptefactor = rowPrefsCompte.getInt("ID_COMPTE_PCE_FACTOR");
186
            if (idComptefactor <= 1) {
196
            if (idComptefactor <= 1) {
187
                idComptefactor = rowPrefsCompte.getInt("ID_COMPTE_PCE_FACTOR");
197
                idComptefactor = rowPrefsCompte.getInt("ID_COMPTE_PCE_FACTOR");
188
                if (idComptefactor <= 1) {
198
                if (idComptefactor <= 1) {
Line 195... Line 205...
195
            }
205
            }
196
 
206
 
197
            this.putValue("ID_COMPTE_PCE", idComptefactor);
207
            this.putValue("ID_COMPTE_PCE", idComptefactor);
198
            this.putValue("DEBIT", Long.valueOf(0));
208
            this.putValue("DEBIT", Long.valueOf(0));
199
            this.putValue("CREDIT", Long.valueOf(ttc));
209
            this.putValue("CREDIT", Long.valueOf(ttc));
-
 
210
            if (!genEcrDisabled) {
200
            ajoutEcriture();
211
                ajoutEcriture();
201
        }
212
            }
-
 
213
        }
202
 
214
 
203
        if (avoirRow.getInt("ID_MODE_REGLEMENT") > 1) {
215
        if (avoirRow.getInt("ID_MODE_REGLEMENT") > 1) {
204
            new GenerationMvtReglementAvoir(avoirRow, this.idMvt);
216
            new GenerationMvtReglementAvoir(avoirRow, this.idMvt);
205
        } else {
217
        } else {
206
            valAvoir.put("SOLDE", Boolean.FALSE);
218
            valAvoir.put("SOLDE", Boolean.FALSE);