OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

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

Rev 174 Rev 177
Line 18... Line 18...
18
import org.openconcerto.erp.core.common.element.NumerotationAutoSQLElement;
18
import org.openconcerto.erp.core.common.element.NumerotationAutoSQLElement;
19
import org.openconcerto.erp.core.finance.accounting.element.ComptePCESQLElement;
19
import org.openconcerto.erp.core.finance.accounting.element.ComptePCESQLElement;
20
import org.openconcerto.erp.core.finance.accounting.element.JournalSQLElement;
20
import org.openconcerto.erp.core.finance.accounting.element.JournalSQLElement;
21
import org.openconcerto.erp.core.finance.accounting.element.MouvementSQLElement;
21
import org.openconcerto.erp.core.finance.accounting.element.MouvementSQLElement;
22
import org.openconcerto.erp.core.finance.payment.element.ModeDeReglementSQLElement;
22
import org.openconcerto.erp.core.finance.payment.element.ModeDeReglementSQLElement;
-
 
23
import org.openconcerto.erp.core.finance.payment.element.SEPAMandateSQLElement;
23
import org.openconcerto.erp.core.finance.payment.element.TypeReglementSQLElement;
24
import org.openconcerto.erp.core.finance.payment.element.TypeReglementSQLElement;
24
import org.openconcerto.erp.model.PrixTTC;
25
import org.openconcerto.erp.model.PrixTTC;
25
import org.openconcerto.erp.preferences.GestionCommercialeGlobalPreferencePanel;
26
import org.openconcerto.erp.preferences.GestionCommercialeGlobalPreferencePanel;
26
import org.openconcerto.sql.Configuration;
27
import org.openconcerto.sql.Configuration;
27
import org.openconcerto.sql.element.SQLElement;
28
import org.openconcerto.sql.element.SQLElement;
Line 51... Line 52...
51
    private static final SQLTable tablePrefCompte = base.getTable("PREFS_COMPTE");
52
    private static final SQLTable tablePrefCompte = base.getTable("PREFS_COMPTE");
52
    private static final SQLRow rowPrefsCompte = tablePrefCompte.getRow(2);
53
    private static final SQLRow rowPrefsCompte = tablePrefCompte.getRow(2);
53
 
54
 
54
    public SQLRow ecrClient = null;
55
    public SQLRow ecrClient = null;
55
 
56
 
56
    public GenerationReglementVenteNG(String label, SQLRow rowClient, PrixTTC ttc, Date d, SQLRow modeReglement, SQLRow source, SQLRow mvtSource) throws Exception {
57
    public GenerationReglementVenteNG(String label, SQLRow rowClient, PrixTTC ttc, Date d, SQLRow modeReglement, SQLRow source, SQLRow mvtSource) throws SQLException {
57
        this(label, rowClient, ttc, d, modeReglement, source, mvtSource, true);
58
        this(label, rowClient, ttc, d, modeReglement, source, mvtSource, true);
58
    }
59
    }
59
 
60
 
60
    public GenerationReglementVenteNG(String label, SQLRow rowClient, PrixTTC ttc, Date d, SQLRow modeReglement, SQLRow source, SQLRow mvtSource, boolean createEncaisse) throws Exception {
61
    public GenerationReglementVenteNG(String label, SQLRow rowClient, PrixTTC ttc, Date d, SQLRow modeReglement, SQLRow source, SQLRow mvtSource, boolean createEncaisse) throws SQLException {
61
        this(label, rowClient, ttc, d, modeReglement, source, mvtSource, createEncaisse, false);
62
        this(label, rowClient, ttc, d, modeReglement, source, mvtSource, createEncaisse, false);
62
    }
63
    }
63
 
64
 
64
    public GenerationReglementVenteNG(String label, SQLRow rowClient, PrixTTC ttc, Date d, SQLRow modeReglement, SQLRow source, SQLRow mvtSource, boolean createEncaisse, boolean avance)
65
    public GenerationReglementVenteNG(String label, SQLRow rowClient, PrixTTC ttc, Date d, SQLRow modeReglement, SQLRow source, SQLRow mvtSource, boolean createEncaisse, boolean avance)
65
            throws Exception {
66
            throws SQLException {
66
        this(label, rowClient, ttc, d, modeReglement, source, mvtSource, createEncaisse, avance, rowClient.getString("NOM"), null);
67
        this(label, rowClient, ttc, d, modeReglement, source, mvtSource, createEncaisse, avance, rowClient.getString("NOM"), null);
67
    }
68
    }
68
 
69
 
69
    public GenerationReglementVenteNG(String label, SQLRow rowClient, PrixTTC ttc, Date d, SQLRow modeReglement, SQLRow source, SQLRow mvtSource, boolean createEncaisse, boolean avance, String tiers,
70
    public GenerationReglementVenteNG(String label, SQLRow rowClient, PrixTTC ttc, Date d, SQLRow modeReglement, SQLRow source, SQLRow mvtSource, boolean createEncaisse, boolean avance, String tiers,
70
            SQLRowAccessor cptTiers) throws Exception {
71
            SQLRowAccessor cptTiers) throws SQLException {
71
 
72
 
72
        SQLRow typeRegRow = modeReglement.getForeignRow("ID_TYPE_REGLEMENT");
73
        SQLRow typeRegRow = modeReglement.getForeignRow("ID_TYPE_REGLEMENT");
73
        setRowAnalytiqueSource(source);
74
        setRowAnalytiqueSource(source);
74
        // iniatilisation des valeurs de la map
75
        // iniatilisation des valeurs de la map
75
        this.date = d;
76
        this.date = d;
Line 153... Line 154...
153
 
154
 
154
                Date dateTmp = this.date;
155
                Date dateTmp = this.date;
155
                if (modeReglement.getObject("DATE") != null) {
156
                if (modeReglement.getObject("DATE") != null) {
156
                    dateTmp = modeReglement.getDate("DATE").getTime();
157
                    dateTmp = modeReglement.getDate("DATE").getTime();
157
                }
158
                }
158
                // On fixe la date du règlement de la facture
159
                // On fixe la date du règlement de la facture à reception du cheque
159
                setDateReglement(source, dateTmp);
160
                setDateReglement(source, this.date);
160
 
161
 
161
                Calendar c = modeReglement.getDate("DATE_DEPOT");
162
                Calendar c = modeReglement.getDate("DATE_DEPOT");
162
                if (c != null) {
163
                if (c != null) {
163
                    paiementCheque(c.getTime(), source, ttc, rowClient, modeReglement, mvtSource.getTable().getRow(idMvt), avance, tiers, cptTiers);
164
                    paiementCheque(c.getTime(), source, ttc, rowClient, modeReglement, mvtSource.getTable().getRow(idMvt), avance, tiers, cptTiers);
164
                } else {
165
                } else {
Line 180... Line 181...
180
                }
181
                }
181
                if (typeRegRow.getID() == TypeReglementSQLElement.ESPECE) {
182
                if (typeRegRow.getID() == TypeReglementSQLElement.ESPECE) {
182
                    this.putValue("ID_JOURNAL", JournalSQLElement.CAISSES);
183
                    this.putValue("ID_JOURNAL", JournalSQLElement.CAISSES);
183
                }
184
                }
184
 
185
 
-
 
186
                if (typeRegRow.getID() == TypeReglementSQLElement.CB && this.rowPrefsCompte.getTable().contains("ID_JOURNAL_CB_ATTENTE")
-
 
187
                        && !this.rowPrefsCompte.isForeignEmpty("ID_JOURNAL_CB_ATTENTE")) {
-
 
188
                    this.putValue("ID_JOURNAL", this.rowPrefsCompte.getForeignID("ID_JOURNAL_CB_ATTENTE"));
-
 
189
                }
-
 
190
 
185
                int idCompteClient = cptTiers != null && !cptTiers.isUndefined() ? cptTiers.getID() : rowClient.getInt("ID_COMPTE_PCE");
191
                int idCompteClient = cptTiers != null && !cptTiers.isUndefined() ? cptTiers.getID() : rowClient.getInt("ID_COMPTE_PCE");
186
                if (avance) {
192
                if (avance) {
187
                    idCompteClient = rowPrefsCompte.getInt("ID_COMPTE_PCE_AVANCE_CLIENT");
193
                    idCompteClient = rowPrefsCompte.getInt("ID_COMPTE_PCE_AVANCE_CLIENT");
188
                    if (idCompteClient <= 1) {
194
                    if (idCompteClient <= 1) {
189
                        idCompteClient = ComptePCESQLElement.getIdComptePceDefault("AvanceClients");
195
                        idCompteClient = ComptePCESQLElement.getIdComptePceDefault("AvanceClients");
Line 212... Line 218...
212
                        idCompteRegl = ComptePCESQLElement.getIdComptePceDefault("VenteEspece");
218
                        idCompteRegl = ComptePCESQLElement.getIdComptePceDefault("VenteEspece");
213
                    }
219
                    }
214
 
220
 
215
                    this.putValue("ID_COMPTE_PCE", Integer.valueOf(idCompteRegl));
221
                    this.putValue("ID_COMPTE_PCE", Integer.valueOf(idCompteRegl));
216
                } else {
222
                } else {
-
 
223
                    try {
217
                    fillCompteBanqueFromRow(modeReglement, "VenteCB", false);
224
                        fillCompteBanqueFromRow(modeReglement, "VenteCB", false);
-
 
225
                    } catch (Exception e) {
-
 
226
                        throw new SQLException(e);
-
 
227
                    }
-
 
228
                }
-
 
229
                if (typeRegRow.getID() == TypeReglementSQLElement.CB && this.rowPrefsCompte.getTable().contains("ID_COMPTE_PCE_CB_ATTENTE")
-
 
230
                        && !this.rowPrefsCompte.isForeignEmpty("ID_COMPTE_PCE_CB_ATTENTE")) {
-
 
231
 
-
 
232
                    this.putValue("ID_COMPTE_PCE", this.rowPrefsCompte.getForeignID("ID_COMPTE_PCE_CB_ATTENTE"));
218
                }
233
                }
-
 
234
 
219
                this.putValue("DEBIT", Long.valueOf(ttc.getLongValue()));
235
                this.putValue("DEBIT", Long.valueOf(ttc.getLongValue()));
220
                this.putValue("CREDIT", Long.valueOf(0));
236
                this.putValue("CREDIT", Long.valueOf(0));
221
                ajoutEcriture();
237
                ajoutEcriture();
222
 
238
 
223
                List<Integer> pieceIDs = new ArrayList<Integer>();
239
                List<Integer> pieceIDs = new ArrayList<Integer>();
Line 249... Line 265...
249
                valEcheance.put("TIERS", tiers);
265
                valEcheance.put("TIERS", tiers);
250
                valEcheance.put("ID_COMPTE_PCE_TIERS", cptTiers == null || !cptTiers.isUndefined() ? null : cptTiers.getID());
266
                valEcheance.put("ID_COMPTE_PCE_TIERS", cptTiers == null || !cptTiers.isUndefined() ? null : cptTiers.getID());
251
                if (source.getTable().equals(tableSaisieVenteFacture)) {
267
                if (source.getTable().equals(tableSaisieVenteFacture)) {
252
                    valEcheance.put("ID_SAISIE_VENTE_FACTURE", source.getID());
268
                    valEcheance.put("ID_SAISIE_VENTE_FACTURE", source.getID());
253
                }
269
                }
-
 
270
                if (source.getTable().getName().equals(valEcheance.getTable().getName())) {
-
 
271
                    valEcheance.put("ID_SAISIE_VENTE_FACTURE", source.getObject("ID_SAISIE_VENTE_FACTURE"));
-
 
272
                }
-
 
273
                if (modeReglement.getForeign("ID_TYPE_REGLEMENT").getBoolean("SEPA")) {
-
 
274
                    final String foreignBanqueFieldName = "ID_" + BanqueSQLElement.TABLENAME;
-
 
275
                    if (valEcheance.getTable().contains(foreignBanqueFieldName))
-
 
276
                        valEcheance.put(foreignBanqueFieldName, modeReglement.getInt(foreignBanqueFieldName));
-
 
277
 
-
 
278
                    valEcheance.put("ETS", modeReglement.getObject("ETS"));
-
 
279
 
-
 
280
                    if (!modeReglement.isForeignEmpty("ID_SEPA_MANDATE")) {
-
 
281
                        valEcheance.put("ID_SEPA_MANDATE", modeReglement.getForeignID("ID_SEPA_MANDATE"));
-
 
282
                    } else if (rowClient != null && !rowClient.isForeignEmpty("ID_SEPA_MANDATE_DEFAULT")) {
-
 
283
                        valEcheance.put("ID_SEPA_MANDATE", rowClient.getForeignID("ID_SEPA_MANDATE_DEFAULT"));
-
 
284
                    } else {
-
 
285
                        SEPAMandateSQLElement mandateElem = ComptaPropsConfiguration.getInstanceCompta().getDirectory().getElement(SEPAMandateSQLElement.class);
-
 
286
                        final String mandateID = mandateElem.generateMandateIdentification("Facturation", '0', true, true);
-
 
287
                        // TODO gestion si pas de client (ex : don ou cotisation association)
-
 
288
                        if (rowClient != null) {
-
 
289
                            final SQLRowValues newVals = mandateElem.createRecurrent(rowClient.getID(), mandateID, source.getDate("DATE").getTime());
-
 
290
                            SQLRow rowMandate = newVals.commit();
-
 
291
                            valEcheance.put("ID_SEPA_MANDATE", rowMandate.getID());
-
 
292
                            rowClient.createEmptyUpdateRow().put("ID_SEPA_MANDATE_DEFAULT", rowMandate.getID()).commit();
-
 
293
                        }
-
 
294
                    }
-
 
295
                }
254
 
296
 
255
                // ajout de l'ecriture
297
                // ajout de l'ecriture
256
                SQLRow row = valEcheance.insert();
298
                SQLRow row = valEcheance.insert();
257
                SQLRowValues rowVals = new SQLRowValues(tableMouvement);
299
                SQLRowValues rowVals = new SQLRowValues(tableMouvement);
258
                rowVals.put("IDSOURCE", row.getID());
300
                rowVals.put("IDSOURCE", row.getID());
Line 340... Line 382...
340
        } catch (SQLException e) {
382
        } catch (SQLException e) {
341
            e.printStackTrace();
383
            e.printStackTrace();
342
        }
384
        }
343
    }
385
    }
344
 
386
 
345
    private void paiementCheque(Date dateEch, SQLRow source, PrixTTC ttc, SQLRow rowClient, SQLRow modeRegl, SQLRow mvtSource, boolean avance, String tiers, SQLRowAccessor cptTiers) throws Exception {
387
    private void paiementCheque(Date dateEch, SQLRow source, PrixTTC ttc, SQLRow rowClient, SQLRow modeRegl, SQLRow mvtSource, boolean avance, String tiers, SQLRowAccessor cptTiers)
-
 
388
            throws SQLException {
346
 
389
 
347
        SQLRowValues valCheque = new SQLRowValues(base.getTable("CHEQUE_A_ENCAISSER"));
390
        SQLRowValues valCheque = new SQLRowValues(base.getTable("CHEQUE_A_ENCAISSER"));
348
        SQLPreferences prefs = SQLPreferences.getMemCached(valCheque.getTable().getDBRoot());
391
        SQLPreferences prefs = SQLPreferences.getMemCached(valCheque.getTable().getDBRoot());
349
        boolean createEcr = prefs.getBoolean(GestionCommercialeGlobalPreferencePanel.CREATE_ECR_CHQ, true);
392
        boolean createEcr = prefs.getBoolean(GestionCommercialeGlobalPreferencePanel.CREATE_ECR_CHQ, true);
350
 
393