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 174
Line 14... Line 14...
14
 package org.openconcerto.erp.core.finance.payment.component;
14
 package org.openconcerto.erp.core.finance.payment.component;
15
 
15
 
16
import org.openconcerto.erp.core.common.element.BanqueSQLElement;
16
import org.openconcerto.erp.core.common.element.BanqueSQLElement;
17
import org.openconcerto.erp.core.common.ui.DeviseField;
17
import org.openconcerto.erp.core.common.ui.DeviseField;
18
import org.openconcerto.erp.core.finance.accounting.element.MouvementSQLElement;
18
import org.openconcerto.erp.core.finance.accounting.element.MouvementSQLElement;
-
 
19
import org.openconcerto.erp.core.finance.payment.element.EncaisserMontantSQLElement;
19
import org.openconcerto.erp.core.finance.payment.element.TypeReglementSQLElement;
20
import org.openconcerto.erp.core.finance.payment.element.TypeReglementSQLElement;
20
import org.openconcerto.erp.core.finance.payment.ui.EncaisseMontantTable;
21
import org.openconcerto.erp.core.finance.payment.ui.EncaisseMontantTable;
21
import org.openconcerto.erp.core.sales.invoice.component.SaisieVenteFactureSQLComponent;
-
 
22
import org.openconcerto.erp.generationEcritures.GenerationReglementVenteNG;
-
 
23
import org.openconcerto.erp.model.PrixTTC;
-
 
24
import org.openconcerto.erp.preferences.ModeReglementDefautPrefPanel;
22
import org.openconcerto.erp.preferences.ModeReglementDefautPrefPanel;
25
import org.openconcerto.sql.Configuration;
23
import org.openconcerto.sql.Configuration;
26
import org.openconcerto.sql.element.BaseSQLComponent;
24
import org.openconcerto.sql.element.BaseSQLComponent;
27
import org.openconcerto.sql.element.ElementSQLObject;
25
import org.openconcerto.sql.element.ElementSQLObject;
28
import org.openconcerto.sql.element.SQLComponent;
26
import org.openconcerto.sql.element.SQLComponent;
Line 31... Line 29...
31
import org.openconcerto.sql.model.SQLRow;
29
import org.openconcerto.sql.model.SQLRow;
32
import org.openconcerto.sql.model.SQLRowAccessor;
30
import org.openconcerto.sql.model.SQLRowAccessor;
33
import org.openconcerto.sql.model.SQLRowValues;
31
import org.openconcerto.sql.model.SQLRowValues;
34
import org.openconcerto.sql.model.SQLTable;
32
import org.openconcerto.sql.model.SQLTable;
35
import org.openconcerto.sql.sqlobject.ElementComboBox;
33
import org.openconcerto.sql.sqlobject.ElementComboBox;
36
import org.openconcerto.sql.view.EditFrame;
-
 
37
import org.openconcerto.sql.view.list.RowValuesTableModel;
34
import org.openconcerto.sql.view.list.RowValuesTableModel;
38
import org.openconcerto.ui.DefaultGridBagConstraints;
35
import org.openconcerto.ui.DefaultGridBagConstraints;
39
import org.openconcerto.ui.JDate;
36
import org.openconcerto.ui.JDate;
40
import org.openconcerto.ui.JLabelBold;
37
import org.openconcerto.ui.JLabelBold;
41
import org.openconcerto.ui.warning.JLabelWarning;
38
import org.openconcerto.ui.warning.JLabelWarning;
42
import org.openconcerto.utils.ExceptionHandler;
39
import org.openconcerto.utils.ExceptionHandler;
43
import org.openconcerto.utils.GestionDevise;
40
import org.openconcerto.utils.GestionDevise;
44
import org.openconcerto.utils.StringUtils;
-
 
45
import org.openconcerto.utils.text.SimpleDocumentListener;
41
import org.openconcerto.utils.text.SimpleDocumentListener;
46
 
42
 
47
import java.awt.GridBagConstraints;
43
import java.awt.GridBagConstraints;
48
import java.awt.GridBagLayout;
44
import java.awt.GridBagLayout;
49
import java.awt.Insets;
45
import java.awt.Insets;
Line 53... Line 49...
53
import java.util.Comparator;
49
import java.util.Comparator;
54
import java.util.List;
50
import java.util.List;
55
 
51
 
56
import javax.swing.JCheckBox;
52
import javax.swing.JCheckBox;
57
import javax.swing.JLabel;
53
import javax.swing.JLabel;
58
import javax.swing.JOptionPane;
-
 
59
import javax.swing.JTextField;
54
import javax.swing.JTextField;
60
import javax.swing.SwingConstants;
55
import javax.swing.SwingConstants;
61
import javax.swing.event.DocumentEvent;
56
import javax.swing.event.DocumentEvent;
62
import javax.swing.event.TableModelEvent;
57
import javax.swing.event.TableModelEvent;
63
import javax.swing.event.TableModelListener;
58
import javax.swing.event.TableModelListener;
Line 181... Line 176...
181
        this.addRequiredSQLObject(this.date, "DATE");
176
        this.addRequiredSQLObject(this.date, "DATE");
182
        this.addRequiredSQLObject(this.montant, "MONTANT");
177
        this.addRequiredSQLObject(this.montant, "MONTANT");
183
 
178
 
184
        this.addSQLObject(this.nom, "NOM");
179
        this.addSQLObject(this.nom, "NOM");
185
        
180
 
186
 
-
 
187
        this.addSQLObject(new ElementComboBox(), "ID_COMPTE_PCE_TIERS");
181
        this.addSQLObject(new ElementComboBox(), "ID_COMPTE_PCE_TIERS");
188
        this.addSQLObject(new JTextField(), "TIERS");
182
        this.addSQLObject(new JTextField(), "TIERS");
189
        DefaultGridBagConstraints.lockMinimumSize(this.montant);
183
        DefaultGridBagConstraints.lockMinimumSize(this.montant);
190
 
184
 
191
        final TableModelListener tableListener = new TableModelListener() {
185
        final TableModelListener tableListener = new TableModelListener() {
Line 303... Line 297...
303
 
297
 
304
    @Override
298
    @Override
305
    public int insert(SQLRow order) {
299
    public int insert(SQLRow order) {
306
 
300
 
307
        int id = super.insert(order);
301
        int id = super.insert(order);
308
        try {
-
 
309
            this.table.updateField("ID_ENCAISSER_MONTANT", id);
302
        this.table.updateField("ID_ENCAISSER_MONTANT", id);
310
 
303
 
311
            System.out.println("Génération des ecritures du reglement");
304
        System.out.println("Génération des ecritures du reglement");
312
            SQLRow row = getTable().getRow(id);
305
        SQLRow row = getTable().getRow(id);
313
            String s = row.getString("NOM");
-
 
314
            SQLRow rowModeRegl = row.getForeignRow("ID_MODE_REGLEMENT");
-
 
315
            SQLRow rowTypeRegl = rowModeRegl.getForeignRow("ID_TYPE_REGLEMENT");
-
 
316
 
-
 
317
            // Compte Client
-
 
318
            SQLRow clientRow = row.getForeignRow("ID_CLIENT");
-
 
319
 
-
 
320
            String label = "Règlement vente " + ((s == null) ? "" : s) + " (" + rowTypeRegl.getString("NOM") + ") " + StringUtils.limitLength(clientRow.getString("NOM"), 20);
-
 
321
            long montant = row.getLong("MONTANT");
-
 
322
            PrixTTC ttc = new PrixTTC(montant);
-
 
323
 
-
 
324
            List<SQLRow> l = row.getReferentRows(Configuration.getInstance().getDirectory().getElement("ENCAISSER_MONTANT_ELEMENT").getTable());
-
 
325
            if (l.isEmpty()) {
-
 
326
                JOptionPane.showMessageDialog(null, "Un problème a été rencontré lors de l'encaissement! \n Les écritures comptables non pu être générer!");
-
 
327
                System.err.println("Liste des échéances vides pour l'encaissement ID " + id);
-
 
328
                Thread.dumpStack();
-
 
329
            }
-
 
330
            new GenerationReglementVenteNG(label, clientRow, ttc, row.getDate("DATE").getTime(), rowModeRegl, row, l.get(0).getForeignRow("ID_MOUVEMENT_ECHEANCE"), false, false,
-
 
331
                    row.getString("TIERS"), row.getForeign("ID_COMPTE_PCE_TIERS"));
-
 
332
 
-
 
333
            // Mise a jour du montant de l'echeance
-
 
334
            boolean supplement = false;
-
 
335
 
-
 
336
            if (!row.getBoolean("ACOMPTE")) {
-
 
337
                // On marque les echeances comme reglees
-
 
338
                for (SQLRow sqlRow : l) {
-
 
339
 
-
 
340
                    final SQLRow rowEch = sqlRow.getForeignRow("ID_ECHEANCE_CLIENT");
-
 
341
                    SQLRowValues rowValsEch = rowEch.createEmptyUpdateRow();
-
 
342
                    if (sqlRow.getLong("MONTANT_REGLE") >= sqlRow.getLong("MONTANT_A_REGLER")) {
-
 
343
                        rowValsEch.put("REGLE", Boolean.TRUE);
-
 
344
                        if (sqlRow.getLong("MONTANT_REGLE") > sqlRow.getLong("MONTANT_A_REGLER")) {
-
 
345
                            supplement = true;
-
 
346
                        }
-
 
347
                    }
-
 
348
                    rowValsEch.put("MONTANT", Long.valueOf(rowEch.getLong("MONTANT") - sqlRow.getLong("MONTANT_REGLE")));
-
 
349
 
306
 
350
                    rowValsEch.update();
-
 
351
                    // this.comboEcheance.rowDeleted(tableEch, rowEch.getID());
-
 
352
                    // getTable().fireTableModified(rowEch.getID());
-
 
353
                }
-
 
354
            }
307
        try {
355
            // si le montant réglé est supérieur, on crée une facture de complément
308
            ((EncaisserMontantSQLElement) getElement()).regleFacture(row);
356
            if (supplement) {
-
 
357
                SQLElement elt = Configuration.getInstance().getDirectory().getElement("SAISIE_VENTE_FACTURE");
-
 
358
                EditFrame f = new EditFrame(elt, EditFrame.CREATION);
-
 
359
                SaisieVenteFactureSQLComponent comp = (SaisieVenteFactureSQLComponent) f.getSQLComponent();
-
 
360
                comp.setComplement(true);
-
 
361
                f.setVisible(true);
-
 
362
            }
-
 
363
        } catch (Exception e) {
309
        } catch (Exception e) {
364
            ExceptionHandler.handle("Erreur lors de la génération des ecritures du reglement", e);
310
            ExceptionHandler.handle("Erreur de génération des écritures", e);
365
        }
311
        }
-
 
312
 
366
        return id;
313
        return id;
367
    }
314
    }
368
 
315
 
369
    @Override
316
    @Override
370
    protected SQLRowValues createDefaults() {
317
    protected SQLRowValues createDefaults() {