OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

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

Rev 180 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 24... Line 24...
24
import org.openconcerto.erp.core.finance.payment.element.TypeReglementSQLElement;
24
import org.openconcerto.erp.core.finance.payment.element.TypeReglementSQLElement;
25
import org.openconcerto.erp.core.finance.tax.model.TaxeCache;
25
import org.openconcerto.erp.core.finance.tax.model.TaxeCache;
26
import org.openconcerto.erp.generationEcritures.provider.AccountingRecordsProvider;
26
import org.openconcerto.erp.generationEcritures.provider.AccountingRecordsProvider;
27
import org.openconcerto.erp.generationEcritures.provider.AccountingRecordsProviderManager;
27
import org.openconcerto.erp.generationEcritures.provider.AccountingRecordsProviderManager;
28
import org.openconcerto.erp.model.PrixTTC;
28
import org.openconcerto.erp.model.PrixTTC;
-
 
29
import org.openconcerto.erp.preferences.DefaultNXProps;
29
import org.openconcerto.erp.preferences.GestionCommercialeGlobalPreferencePanel;
30
import org.openconcerto.erp.preferences.GestionCommercialeGlobalPreferencePanel;
30
import org.openconcerto.sql.Configuration;
31
import org.openconcerto.sql.Configuration;
31
import org.openconcerto.sql.element.SQLElement;
32
import org.openconcerto.sql.element.SQLElement;
32
import org.openconcerto.sql.model.SQLRow;
33
import org.openconcerto.sql.model.SQLRow;
33
import org.openconcerto.sql.model.SQLRowAccessor;
34
import org.openconcerto.sql.model.SQLRowAccessor;
Line 159... Line 160...
159
            }
160
            }
160
 
161
 
161
            // Cheque
162
            // Cheque
162
            if (typeRegRow.getID() == TypeReglementSQLElement.CHEQUE) {
163
            if (typeRegRow.getID() == TypeReglementSQLElement.CHEQUE) {
163
 
164
 
-
 
165
                final SQLRowAccessor nonEmptyForeign = modeReglement.getNonEmptyForeign("ID_BANQUE");
-
 
166
                if (nonEmptyForeign != null && nonEmptyForeign.getTable().contains("TYPE_CAISSE") && nonEmptyForeign.getBoolean("TYPE_CAISSE")) {
-
 
167
                    rowClient = null;
-
 
168
                    cptTiers = nonEmptyForeign.getForeign("ID_COMPTE_PCE");
-
 
169
                }
-
 
170
 
164
                Date dateTmp = this.date;
171
                Date dateTmp = this.date;
165
                if (modeReglement.getObject("DATE") != null) {
172
                if (modeReglement.getObject("DATE") != null) {
166
                    dateTmp = modeReglement.getDate("DATE").getTime();
173
                    dateTmp = modeReglement.getDate("DATE").getTime();
167
                }
174
                }
168
                // On fixe la date du règlement de la facture à reception du cheque
175
                // On fixe la date du règlement de la facture à reception du cheque
Line 194... Line 201...
194
 
201
 
195
                if (typeRegRow.getID() == TypeReglementSQLElement.CB && this.rowPrefsCompte.getTable().contains("ID_JOURNAL_CB_ATTENTE")
202
                if (typeRegRow.getID() == TypeReglementSQLElement.CB && this.rowPrefsCompte.getTable().contains("ID_JOURNAL_CB_ATTENTE")
196
                        && !this.rowPrefsCompte.isForeignEmpty("ID_JOURNAL_CB_ATTENTE")) {
203
                        && !this.rowPrefsCompte.isForeignEmpty("ID_JOURNAL_CB_ATTENTE")) {
197
                    this.putValue("ID_JOURNAL", this.rowPrefsCompte.getForeignID("ID_JOURNAL_CB_ATTENTE"));
204
                    this.putValue("ID_JOURNAL", this.rowPrefsCompte.getForeignID("ID_JOURNAL_CB_ATTENTE"));
198
                }
205
                }
-
 
206
                if (typeRegRow.contains("ID_COMPTE_PCE_CAISSE") && (rowClient == null || rowClient.isUndefined()) && !typeRegRow.isForeignEmpty("ID_COMPTE_PCE_CAISSE")) {
-
 
207
                    this.putValue("ID_JOURNAL", JournalSQLElement.CAISSES);
-
 
208
                }
199
 
209
 
200
                int idCompteClient = cptTiers != null && !cptTiers.isUndefined() ? cptTiers.getID() : rowClient.getInt("ID_COMPTE_PCE");
210
                int idCompteClient = cptTiers != null && !cptTiers.isUndefined() ? cptTiers.getID() : rowClient.getInt("ID_COMPTE_PCE");
201
                if (avance) {
211
                if (avance) {
202
                    idCompteClient = rowPrefsCompte.getInt("ID_COMPTE_PCE_AVANCE_CLIENT");
212
                    idCompteClient = rowPrefsCompte.getInt("ID_COMPTE_PCE_AVANCE_CLIENT");
203
                    if (idCompteClient <= 1) {
213
                    if (idCompteClient <= 1) {
Line 212... Line 222...
212
                        if (idCompteClient <= 1) {
222
                        if (idCompteClient <= 1) {
213
                            idCompteClient = ComptePCESQLElement.getIdComptePceDefault("Clients");
223
                            idCompteClient = ComptePCESQLElement.getIdComptePceDefault("Clients");
214
                        }
224
                        }
215
                    }
225
                    }
216
                }
226
                }
-
 
227
                boolean genEcrDisabled = DefaultNXProps.getInstance().getBooleanValue(GenerationMvtSaisieVenteFacture.NOT_GEN_ECRITURE, false);
-
 
228
                if (typeRegRow.contains("ID_COMPTE_PCE_CAISSE") && (rowClient == null || rowClient.isUndefined()) && !typeRegRow.isForeignEmpty("ID_COMPTE_PCE_CAISSE")) {
-
 
229
                    if (!modeReglement.isForeignEmpty("ID_BANQUE")) {
-
 
230
                        rowClient = null;
-
 
231
                        final SQLRow foreign = modeReglement.getForeign("ID_BANQUE");
-
 
232
                        if (foreign.getBoolean("TYPE_CAISSE")) {
-
 
233
                            idCompteClient = foreign.getForeignID("ID_COMPTE_PCE");
-
 
234
                        }
-
 
235
                    }
-
 
236
                }
217
                this.putValue("ID_COMPTE_PCE", idCompteClient);
237
                this.putValue("ID_COMPTE_PCE", idCompteClient);
218
                this.putValue("DEBIT", Long.valueOf(0));
238
                this.putValue("DEBIT", Long.valueOf(0));
219
                this.putValue("CREDIT", Long.valueOf(ttc.getLongValue()));
239
                this.putValue("CREDIT", Long.valueOf(ttc.getLongValue()));
220
 
240
 
-
 
241
                if (!genEcrDisabled) {
221
                this.ecrClient = ajoutEcriture();
242
                    this.ecrClient = ajoutEcriture();
-
 
243
                }
222
 
244
 
223
                // compte de reglement, caisse, cheque, ...
245
                // compte de reglement, caisse, cheque, ...
224
                if (typeRegRow.getID() == TypeReglementSQLElement.ESPECE) {
246
                if (typeRegRow.getID() == TypeReglementSQLElement.ESPECE) {
225
                    int idCompteRegl = typeRegRow.getInt("ID_COMPTE_PCE_CLIENT");
247
                    int idCompteRegl = typeRegRow.getInt("ID_COMPTE_PCE_CLIENT");
226
                    if (idCompteRegl <= 1) {
248
                    if (idCompteRegl <= 1) {
Line 233... Line 255...
233
                        fillCompteBanqueFromRow(modeReglement, "VenteCB", false);
255
                        fillCompteBanqueFromRow(modeReglement, "VenteCB", false);
234
                    } catch (Exception e) {
256
                    } catch (Exception e) {
235
                        throw new SQLException(e);
257
                        throw new SQLException(e);
236
                    }
258
                    }
237
                }
259
                }
-
 
260
 
-
 
261
                if (typeRegRow.contains("ID_COMPTE_PCE_CAISSE") && (rowClient == null || rowClient.isUndefined()) && !typeRegRow.isForeignEmpty("ID_COMPTE_PCE_CAISSE")) {
-
 
262
                    this.putValue("ID_COMPTE_PCE", typeRegRow.getForeignID("ID_COMPTE_PCE_CAISSE"));
-
 
263
                }
-
 
264
 
238
                if (typeRegRow.getID() == TypeReglementSQLElement.CB && this.rowPrefsCompte.getTable().contains("ID_COMPTE_PCE_CB_ATTENTE")
265
                if (typeRegRow.getID() == TypeReglementSQLElement.CB && this.rowPrefsCompte.getTable().contains("ID_COMPTE_PCE_CB_ATTENTE")
239
                        && !this.rowPrefsCompte.isForeignEmpty("ID_COMPTE_PCE_CB_ATTENTE")) {
266
                        && !this.rowPrefsCompte.isForeignEmpty("ID_COMPTE_PCE_CB_ATTENTE")) {
240
 
267
 
241
                    this.putValue("ID_COMPTE_PCE", this.rowPrefsCompte.getForeignID("ID_COMPTE_PCE_CB_ATTENTE"));
268
                    this.putValue("ID_COMPTE_PCE", this.rowPrefsCompte.getForeignID("ID_COMPTE_PCE_CB_ATTENTE"));
242
                }
269
                }
243
 
270
 
244
                this.putValue("DEBIT", Long.valueOf(ttc.getLongValue()));
271
                this.putValue("DEBIT", Long.valueOf(ttc.getLongValue()));
245
                this.putValue("CREDIT", Long.valueOf(0));
272
                this.putValue("CREDIT", Long.valueOf(0));
-
 
273
                if (!genEcrDisabled) {
246
                ajoutEcriture();
274
                    ajoutEcriture();
247
 
-
 
-
 
275
                }
248
                // FIXME remove getConf
276
                // FIXME remove getConf
249
                SQLRow rowSoc = ComptaPropsConfiguration.getInstanceCompta().getRowSociete();
277
                SQLRow rowSoc = ComptaPropsConfiguration.getInstanceCompta().getRowSociete();
250
                if (rowSoc.getTable().contains("TVA_ENCAISSEMENT") && rowSoc.getBoolean("TVA_ENCAISSEMENT")) {
278
                if (rowSoc.getTable().contains("TVA_ENCAISSEMENT") && rowSoc.getBoolean("TVA_ENCAISSEMENT")) {
251
                    SQLRow rowTaxe = TaxeCache.getCache().getFirstTaxe();
279
                    SQLRow rowTaxe = TaxeCache.getCache().getFirstTaxe();
252
                    if (rowTaxe.contains("ID_COMPTE_PCE_COLLECTE_ENCAISSEMENT")) {
280
                    if (rowTaxe.contains("ID_COMPTE_PCE_COLLECTE_ENCAISSEMENT")) {
Line 257... Line 285...
257
 
285
 
258
                            long tva = ttc.calculLongTVA(taux / 100.0);
286
                            long tva = ttc.calculLongTVA(taux / 100.0);
259
                            this.putValue("ID_COMPTE_PCE", rowCompteTvaCol.getID());
287
                            this.putValue("ID_COMPTE_PCE", rowCompteTvaCol.getID());
260
                            this.putValue("DEBIT", Long.valueOf(tva));
288
                            this.putValue("DEBIT", Long.valueOf(tva));
261
                            this.putValue("CREDIT", Long.valueOf(0));
289
                            this.putValue("CREDIT", Long.valueOf(0));
-
 
290
                            if (!genEcrDisabled) {
262
                            ajoutEcriture();
291
                                ajoutEcriture();
-
 
292
                            }
263
 
293
 
264
                            this.putValue("ID_COMPTE_PCE", rowCompteTvaEnc.getID());
294
                            this.putValue("ID_COMPTE_PCE", rowCompteTvaEnc.getID());
265
                            this.putValue("DEBIT", Long.valueOf(0));
295
                            this.putValue("DEBIT", Long.valueOf(0));
266
                            this.putValue("CREDIT", Long.valueOf(tva));
296
                            this.putValue("CREDIT", Long.valueOf(tva));
-
 
297
                            if (!genEcrDisabled) {
267
                            ajoutEcriture();
298
                                ajoutEcriture();
-
 
299
                            }
268
 
300
 
269
                        }
301
                        }
270
                    }
302
                    }
271
                }
303
                }
272
 
304
 
Line 292... Line 324...
292
                SQLRowValues valEcheance = new SQLRowValues(tableEch);
324
                SQLRowValues valEcheance = new SQLRowValues(tableEch);
293
 
325
 
294
                this.idMvt = getNewMouvement("ECHEANCE_CLIENT", 1, mvtSource.getID(), mvtSource.getInt("ID_PIECE"));
326
                this.idMvt = getNewMouvement("ECHEANCE_CLIENT", 1, mvtSource.getID(), mvtSource.getInt("ID_PIECE"));
295
                valEcheance.put("ID_MOUVEMENT", Integer.valueOf(this.idMvt));
327
                valEcheance.put("ID_MOUVEMENT", Integer.valueOf(this.idMvt));
296
                valEcheance.put("DATE", dateEch);
328
                valEcheance.put("DATE", dateEch);
-
 
329
                valEcheance.put("RG", modeReglement.getBoolean("RG"));
297
                valEcheance.put("MONTANT", Long.valueOf(ttc.getLongValue()));
330
                valEcheance.put("MONTANT", Long.valueOf(ttc.getLongValue()));
298
                valEcheance.put("ID_CLIENT", rowClient == null ? null : rowClient.getID());
331
                valEcheance.put("ID_CLIENT", rowClient == null ? null : rowClient.getID());
299
                valEcheance.put("TIERS", tiers);
332
                valEcheance.put("TIERS", tiers);
300
                valEcheance.put("ID_COMPTE_PCE_TIERS", cptTiers == null || !cptTiers.isUndefined() ? null : cptTiers.getID());
333
                valEcheance.put("ID_COMPTE_PCE_TIERS", cptTiers == null || cptTiers.isUndefined() ? mvtSource.getTable().getTable("COMPTE_PCE").getUndefinedIDNumber() : cptTiers.getID());
301
                if (source.getTable().equals(tableSaisieVenteFacture)) {
334
                if (source.getTable().equals(tableSaisieVenteFacture)) {
302
                    valEcheance.put("ID_SAISIE_VENTE_FACTURE", source.getID());
335
                    valEcheance.put("ID_SAISIE_VENTE_FACTURE", source.getID());
303
                }
336
                }
304
                if (source.getTable().getName().equals(valEcheance.getTable().getName())) {
337
                if (source.getTable().getName().equals(valEcheance.getTable().getName())) {
305
                    valEcheance.put("ID_SAISIE_VENTE_FACTURE", source.getObject("ID_SAISIE_VENTE_FACTURE"));
338
                    valEcheance.put("ID_SAISIE_VENTE_FACTURE", source.getObject("ID_SAISIE_VENTE_FACTURE"));
Line 368... Line 401...
368
        }
401
        }
369
 
402
 
370
    }
403
    }
371
 
404
 
372
    public void doLettrageAuto(final SQLRowAccessor source, Date dateLettrage) {
405
    public void doLettrageAuto(final SQLRowAccessor source, Date dateLettrage) {
-
 
406
 
-
 
407
        if (this.ecrClient != null) {
-
 
408
 
373
        // A. On lettre les critures client (facture ET reglement)
409
            // A. On lettre les critures client (facture ET reglement)
374
        // A1. Recherche criture client de facturation
410
            // A1. Recherche criture client de facturation
375
 
411
 
376
        final SQLRowValues g1 = new SQLRowValues(ecritureTable);
412
            final SQLRowValues g1 = new SQLRowValues(ecritureTable);
377
        g1.put("DEBIT", null);
413
            g1.put("DEBIT", null);
Line 419... Line 455...
419
            rowVals1.update();
455
                rowVals1.update();
420
        } catch (SQLException e) {
456
            } catch (SQLException e) {
421
            e.printStackTrace();
457
                e.printStackTrace();
422
        }
458
            }
423
    }
459
        }
-
 
460
    }
424
 
461
 
425
    private void paiementCheque(Date dateEch, SQLRow source, PrixTTC ttc, SQLRow rowClient, SQLRow modeRegl, SQLRow mvtSource, boolean avance, String tiers, SQLRowAccessor cptTiers)
462
    private void paiementCheque(Date dateEch, SQLRow source, PrixTTC ttc, SQLRow rowClient, SQLRow modeRegl, SQLRow mvtSource, boolean avance, String tiers, SQLRowAccessor cptTiers)
426
            throws SQLException {
463
            throws SQLException {
427
 
464
 
428
        SQLRowValues valCheque = new SQLRowValues(base.getTable("CHEQUE_A_ENCAISSER"));
465
        SQLRowValues valCheque = new SQLRowValues(base.getTable("CHEQUE_A_ENCAISSER"));
Line 475... Line 512...
475
 
512
 
476
            int idJournal = JournalSQLElement.BANQUES;
513
            int idJournal = JournalSQLElement.BANQUES;
477
            if (rowPrefsCompte.getObject("ID_JOURNAL_VALEUR_ENCAISSEMENT") != null && !rowPrefsCompte.isForeignEmpty("ID_JOURNAL_VALEUR_ENCAISSEMENT")) {
514
            if (rowPrefsCompte.getObject("ID_JOURNAL_VALEUR_ENCAISSEMENT") != null && !rowPrefsCompte.isForeignEmpty("ID_JOURNAL_VALEUR_ENCAISSEMENT")) {
478
                idJournal = rowPrefsCompte.getForeignID("ID_JOURNAL_VALEUR_ENCAISSEMENT");
515
                idJournal = rowPrefsCompte.getForeignID("ID_JOURNAL_VALEUR_ENCAISSEMENT");
479
            }
516
            }
-
 
517
            // compte de reglement, caisse, cheque, ...
-
 
518
            int idCompteRegl = rowPrefsCompte.getInt("ID_COMPTE_PCE_VALEUR_ENCAISSEMENT");
-
 
519
            if (idCompteRegl <= 1) {
-
 
520
                idCompteRegl = ComptePCESQLElement.getIdComptePceDefault("ValeurEncaissement");
-
 
521
            }
-
 
522
            if (modeRegl != null) {
-
 
523
                final SQLRowAccessor nonEmptyForeign = modeRegl.getNonEmptyForeign("ID_BANQUE");
-
 
524
                if (nonEmptyForeign != null && nonEmptyForeign.getTable().contains("TYPE_CAISSE") && nonEmptyForeign.getBoolean("TYPE_CAISSE")) {
-
 
525
                    final SQLRow rowTypeREgl = tableMouvement.getTable("TYPE_REGLEMENT").getRow(TypeReglementSQLElement.CHEQUE);
-
 
526
                    if (rowTypeREgl.contains("ID_COMPTE_PCE_CAISSE") && (rowClient == null || rowClient.isUndefined()) && !rowTypeREgl.isForeignEmpty("ID_COMPTE_PCE_CAISSE")) {
-
 
527
                        idCompteRegl = rowTypeREgl.getForeignID("ID_COMPTE_PCE_CAISSE");
-
 
528
                        idJournal = JournalSQLElement.CAISSES;
-
 
529
                    }
-
 
530
                }
-
 
531
            }
480
 
532
 
481
            this.putValue("ID_JOURNAL", idJournal);
533
            this.putValue("ID_JOURNAL", idJournal);
482
            this.putValue("ID_COMPTE_PCE", idCompteClient);
534
            this.putValue("ID_COMPTE_PCE", idCompteClient);
483
            this.putValue("DEBIT", Long.valueOf(0));
535
            this.putValue("DEBIT", Long.valueOf(0));
484
            this.putValue("CREDIT", Long.valueOf(ttc.getLongValue()));
536
            this.putValue("CREDIT", Long.valueOf(ttc.getLongValue()));
485
 
537
 
-
 
538
            boolean genEcrDisabled = DefaultNXProps.getInstance().getBooleanValue(GenerationMvtSaisieVenteFacture.NOT_GEN_ECRITURE, false);
-
 
539
            if (!genEcrDisabled) {
486
            this.ecrClient = ajoutEcriture();
540
                this.ecrClient = ajoutEcriture();
487
 
541
 
488
            // compte de reglement, caisse, cheque, ...
-
 
489
            int idCompteRegl = rowPrefsCompte.getInt("ID_COMPTE_PCE_VALEUR_ENCAISSEMENT");
-
 
490
            if (idCompteRegl <= 1) {
-
 
491
                idCompteRegl = ComptePCESQLElement.getIdComptePceDefault("ValeurEncaissement");
-
 
492
            }
-
 
493
            this.putValue("ID_COMPTE_PCE", Integer.valueOf(idCompteRegl));
542
                this.putValue("ID_COMPTE_PCE", Integer.valueOf(idCompteRegl));
494
            this.putValue("DEBIT", Long.valueOf(ttc.getLongValue()));
543
                this.putValue("DEBIT", Long.valueOf(ttc.getLongValue()));
495
            this.putValue("CREDIT", Long.valueOf(0));
544
                this.putValue("CREDIT", Long.valueOf(0));
496
 
545
 
497
            ajoutEcriture();
546
                ajoutEcriture();
498
        }
547
            }
-
 
548
        }
499
 
549
 
500
    }
550
    }
501
 
551
 
502
}
552
}