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 15... Line 15...
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.EncaisserMontantSQLElement;
20
import org.openconcerto.erp.core.finance.payment.element.TypeReglementSQLElement;
-
 
21
import org.openconcerto.erp.core.finance.payment.ui.EncaisseMontantTable;
20
import org.openconcerto.erp.core.finance.payment.ui.EncaisseMontantTable;
22
import org.openconcerto.erp.preferences.ModeReglementDefautPrefPanel;
21
import org.openconcerto.erp.preferences.ModeReglementDefautPrefPanel;
23
import org.openconcerto.sql.Configuration;
22
import org.openconcerto.sql.Configuration;
24
import org.openconcerto.sql.element.BaseSQLComponent;
23
import org.openconcerto.sql.element.BaseSQLComponent;
25
import org.openconcerto.sql.element.ElementSQLObject;
24
import org.openconcerto.sql.element.ElementSQLObject;
Line 64... Line 63...
64
    private JTextField nom = new JTextField();
63
    private JTextField nom = new JTextField();
65
    private DeviseField montant = new DeviseField(10);
64
    private DeviseField montant = new DeviseField(10);
66
    private JLabel labelWarning = new JLabelWarning("Le montant est trop élevé!");
65
    private JLabel labelWarning = new JLabelWarning("Le montant est trop élevé!");
67
 
66
 
68
    private JDate date;
67
    private JDate date;
-
 
68
    private ElementSQLObject eltModeRegl;
-
 
69
 
-
 
70
    final TableModelListener tableListener = new TableModelListener() {
-
 
71
 
-
 
72
        @Override
-
 
73
        public void tableChanged(TableModelEvent e) {
-
 
74
            final RowValuesTableModel model = table.getRowValuesTable().getRowValuesTableModel();
-
 
75
            if (e.getColumn() == TableModelEvent.ALL_COLUMNS || e.getColumn() == model.getColumnIndexForElement(table.getMontantElement())) {
-
 
76
 
-
 
77
                final int rowCount = model.getRowCount();
-
 
78
                long total = 0;
-
 
79
                for (int i = 0; i < rowCount; i++) {
-
 
80
                    Number nHT = (Number) model.getValueAt(i, model.getColumnIndexForElement(table.getMontantElement()));
-
 
81
                    if (nHT != null) {
-
 
82
                        total += nHT.longValue();
-
 
83
                    }
-
 
84
                }
-
 
85
 
-
 
86
                montant.getDocument().removeDocumentListener(listenerMontant);
-
 
87
                montant.setText(GestionDevise.currencyToString(total));
-
 
88
                montant.getDocument().addDocumentListener(listenerMontant);
-
 
89
                // Selection du mode de reglement
-
 
90
                if (getMode() == SQLComponent.Mode.INSERTION) {
-
 
91
                    if (rowCount >= 1) {
-
 
92
 
-
 
93
                        MouvementSQLElement element = getElement().getDirectory().getElement(MouvementSQLElement.class);
-
 
94
                        SQLRowValues row1 = model.getRowValuesAt(0);
-
 
95
                        if (row1.getObject("ID_MOUVEMENT_ECHEANCE") != null && !row1.isForeignEmpty("ID_MOUVEMENT_ECHEANCE")) {
-
 
96
                            final int idScr = element.getSourceId(row1.getForeignID("ID_MOUVEMENT_ECHEANCE"));
-
 
97
                            SQLTable tableMvt = element.getTable();
-
 
98
                            if (idScr > 1) {
-
 
99
                                SQLRow rowMvt = tableMvt.getRow(idScr);
-
 
100
                                String source = rowMvt.getString("SOURCE");
-
 
101
                                int idSource = rowMvt.getInt("IDSOURCE");
-
 
102
                                SQLElement eltSource = element.getDirectory().getElement(source);
-
 
103
                                if (eltSource != null) {
-
 
104
                                    SQLRow rowSource = eltSource.getTable().getRow(idSource);
-
 
105
 
-
 
106
                                    if (rowSource != null) {
-
 
107
                                        SQLRow rowModeRegl = rowSource.getForeignRow("ID_MODE_REGLEMENT");
-
 
108
                                        if (rowModeRegl != null) {
-
 
109
                                            System.err.println("Set mode de règlement");
-
 
110
                                            int idTypeRegl = rowModeRegl.getInt("ID_TYPE_REGLEMENT");
-
 
111
                                            SQLTable tableModeRegl = Configuration.getInstance().getDirectory().getElement("MODE_REGLEMENT").getTable();
-
 
112
                                            SQLRowValues rowVals = new SQLRowValues(tableModeRegl);
-
 
113
                                            rowVals.put("ID_TYPE_REGLEMENT", idTypeRegl);
-
 
114
                                            rowVals.put("COMPTANT", Boolean.TRUE);
-
 
115
                                            rowVals.put("AJOURS", 0);
-
 
116
                                            rowVals.put("LENJOUR", 0);
-
 
117
                                            rowVals.put("ID_" + BanqueSQLElement.TABLENAME, rowModeRegl.getInt("ID_" + BanqueSQLElement.TABLENAME));
-
 
118
                                            eltModeRegl.setValue(rowVals);
-
 
119
                                        }
-
 
120
                                    }
-
 
121
                                }
-
 
122
                            }
-
 
123
                        }
-
 
124
                    }
-
 
125
                }
-
 
126
 
-
 
127
            }
-
 
128
            if (e.getColumn() == TableModelEvent.ALL_COLUMNS || e.getColumn() == model.getColumnIndexForElement(table.getMontantElement())
-
 
129
                    || e.getColumn() == model.getColumnIndexForElement(table.getMontantAReglerElement())) {
-
 
130
                updateWarning();
-
 
131
            }
-
 
132
        }
-
 
133
    };
-
 
134
 
-
 
135
    final SimpleDocumentListener listenerMontant = new SimpleDocumentListener() {
-
 
136
 
-
 
137
        @Override
-
 
138
        public void update(DocumentEvent e) {
-
 
139
            table.getRowValuesTable().getRowValuesTableModel().removeTableModelListener(tableListener);
-
 
140
            updateMontant(montant.getText());
-
 
141
            table.getRowValuesTable().getRowValuesTableModel().addTableModelListener(tableListener);
-
 
142
            updateWarning();
-
 
143
 
-
 
144
        }
-
 
145
    };
69
 
146
 
70
    public EncaisserMontantSQLComponent(SQLElement elt) {
147
    public EncaisserMontantSQLComponent(SQLElement elt) {
71
        super(elt);
148
        super(elt);
72
    }
149
    }
73
 
150
 
Line 82... Line 159...
82
        this.add(new JLabelBold("Echéances"), c);
159
        this.add(new JLabelBold("Echéances"), c);
83
        c.gridy++;
160
        c.gridy++;
84
        c.weighty = 1;
161
        c.weighty = 1;
85
        c.fill = GridBagConstraints.BOTH;
162
        c.fill = GridBagConstraints.BOTH;
86
        this.add(this.table, c);
163
        this.add(this.table, c);
87
        this.table.getRowValuesTable().setEnabled(false);
-
 
88
        c.fill = GridBagConstraints.HORIZONTAL;
164
        c.fill = GridBagConstraints.HORIZONTAL;
89
        c.gridwidth = 1;
165
        c.gridwidth = 1;
90
        c.gridy++;
166
        c.gridy++;
91
        c.weighty = 0;
167
        c.weighty = 0;
92
 
168
 
Line 142... Line 218...
142
        c.weightx = 0;
218
        c.weightx = 0;
143
        this.add(new JLabel("Montant encaissé", SwingConstants.RIGHT), c);
219
        this.add(new JLabel("Montant encaissé", SwingConstants.RIGHT), c);
144
 
220
 
145
        c.gridx++;
221
        c.gridx++;
146
        c.gridwidth = 3;
222
        c.gridwidth = 3;
-
 
223
        c.weightx = 1;
147
        c.fill = GridBagConstraints.NONE;
224
        c.fill = GridBagConstraints.NONE;
148
        this.add(this.montant, c);
225
        this.add(this.montant, c);
149
 
226
 
150
        // Warning
227
        // Warning
151
        c.gridx++;
228
        c.gridx++;
-
 
229
        c.weightx = 0;
152
        c.gridwidth = GridBagConstraints.REMAINDER;
230
        c.gridwidth = GridBagConstraints.REMAINDER;
153
        this.labelWarning.setHorizontalAlignment(SwingConstants.RIGHT);
231
        this.labelWarning.setHorizontalAlignment(SwingConstants.RIGHT);
154
        this.add(this.labelWarning, c);
232
        this.add(this.labelWarning, c);
155
 
233
 
156
        /***********************************************************************************
234
        /***********************************************************************************
Line 168... Line 246...
168
 
246
 
169
        c.gridx = 0;
247
        c.gridx = 0;
170
        c.gridy++;
248
        c.gridy++;
171
        c.gridwidth = GridBagConstraints.REMAINDER;
249
        c.gridwidth = GridBagConstraints.REMAINDER;
172
        this.addView("ID_MODE_REGLEMENT", BaseSQLComponent.REQ + ";" + BaseSQLComponent.DEC + ";" + BaseSQLComponent.SEP);
250
        this.addView("ID_MODE_REGLEMENT", BaseSQLComponent.REQ + ";" + BaseSQLComponent.DEC + ";" + BaseSQLComponent.SEP);
173
        final ElementSQLObject eltModeRegl = (ElementSQLObject) this.getView("ID_MODE_REGLEMENT");
251
        this.eltModeRegl = (ElementSQLObject) this.getView("ID_MODE_REGLEMENT");
174
        this.add(eltModeRegl, c);
252
        this.add(this.eltModeRegl, c);
-
 
253
        ModeDeReglementSQLComponent modeReglComp;
175
 
254
 
-
 
255
        modeReglComp = (ModeDeReglementSQLComponent) this.eltModeRegl.getSQLChild();
-
 
256
        modeReglComp.addDateCompListener(this.date);
176
        this.addRequiredSQLObject(this.date, "DATE");
257
        this.addRequiredSQLObject(this.date, "DATE");
177
        this.addRequiredSQLObject(this.montant, "MONTANT");
258
        this.addRequiredSQLObject(this.montant, "MONTANT");
178
 
259
 
179
        this.addSQLObject(this.nom, "NOM");
260
        this.addSQLObject(this.nom, "NOM");
180
 
261
 
181
        this.addSQLObject(new ElementComboBox(), "ID_COMPTE_PCE_TIERS");
262
        this.addSQLObject(new ElementComboBox(), "ID_COMPTE_PCE_TIERS");
182
        this.addSQLObject(new JTextField(), "TIERS");
263
        this.addSQLObject(new JTextField(), "TIERS");
183
        DefaultGridBagConstraints.lockMinimumSize(this.montant);
264
        DefaultGridBagConstraints.lockMinimumSize(this.montant);
184
 
265
 
185
        final TableModelListener tableListener = new TableModelListener() {
-
 
186
 
-
 
187
            @Override
-
 
188
            public void tableChanged(TableModelEvent e) {
-
 
189
                final RowValuesTableModel model = table.getRowValuesTable().getRowValuesTableModel();
-
 
190
                if (e.getColumn() == TableModelEvent.ALL_COLUMNS || e.getColumn() == model.getColumnIndexForElement(table.getMontantElement())) {
-
 
191
 
-
 
192
                    final int rowCount = model.getRowCount();
-
 
193
                    long total = 0;
-
 
194
                    for (int i = 0; i < rowCount; i++) {
-
 
195
                        Number nHT = (Number) model.getValueAt(i, model.getColumnIndexForElement(table.getMontantElement()));
-
 
196
                        if (nHT != null) {
-
 
197
                            total += nHT.longValue();
-
 
198
                        }
-
 
199
                    }
-
 
200
 
-
 
201
                    montant.setText(GestionDevise.currencyToString(total));
-
 
202
 
-
 
203
                    // Selection du mode de reglement
-
 
204
                    if (getMode() == SQLComponent.Mode.INSERTION) {
-
 
205
                        if (rowCount >= 1 && model.getRowValuesAt(0).getObject("ID_MOUVEMENT_ECHEANCE") != null && !model.getRowValuesAt(0).isForeignEmpty("ID_MOUVEMENT_ECHEANCE")) {
-
 
206
                            final int idScr = MouvementSQLElement.getSourceId(model.getRowValuesAt(0).getInt("ID_MOUVEMENT_ECHEANCE"));
-
 
207
                            SQLTable tableMvt = Configuration.getInstance().getDirectory().getElement("MOUVEMENT").getTable();
-
 
208
                            if (idScr > 1) {
-
 
209
                                SQLRow rowMvt = tableMvt.getRow(idScr);
-
 
210
                                String source = rowMvt.getString("SOURCE");
-
 
211
                                int idSource = rowMvt.getInt("IDSOURCE");
-
 
212
                                SQLElement eltSource = Configuration.getInstance().getDirectory().getElement(source);
-
 
213
                                if (eltSource != null) {
-
 
214
                                    SQLRow rowSource = eltSource.getTable().getRow(idSource);
-
 
215
 
-
 
216
                                    if (rowSource != null) {
-
 
217
                                        SQLRow rowModeRegl = rowSource.getForeignRow("ID_MODE_REGLEMENT");
-
 
218
                                        if (rowModeRegl != null) {
-
 
219
                                            System.err.println("Set mode de règlement");
-
 
220
                                            int idTypeRegl = rowModeRegl.getInt("ID_TYPE_REGLEMENT");
-
 
221
                                            SQLTable tableModeRegl = Configuration.getInstance().getDirectory().getElement("MODE_REGLEMENT").getTable();
-
 
222
                                            SQLRowValues rowVals = new SQLRowValues(tableModeRegl);
-
 
223
                                            if (idTypeRegl == TypeReglementSQLElement.INDEFINI) {
-
 
224
                                                idTypeRegl = TypeReglementSQLElement.CHEQUE;
-
 
225
                                            }
-
 
226
                                            rowVals.put("ID_TYPE_REGLEMENT", idTypeRegl);
-
 
227
                                            rowVals.put("COMPTANT", Boolean.TRUE);
-
 
228
                                            rowVals.put("AJOURS", 0);
-
 
229
                                            rowVals.put("LENJOUR", 0);
-
 
230
                                            rowVals.put("ID_" + BanqueSQLElement.TABLENAME, rowModeRegl.getInt("ID_" + BanqueSQLElement.TABLENAME));
-
 
231
                                            eltModeRegl.setValue(rowVals);
-
 
232
                                        }
-
 
233
                                    }
-
 
234
                                }
-
 
235
                            }
-
 
236
                        }
-
 
237
                    }
-
 
238
 
-
 
239
                }
-
 
240
                if (e.getColumn() == TableModelEvent.ALL_COLUMNS || e.getColumn() == model.getColumnIndexForElement(table.getMontantAReglerElement())) {
-
 
241
                    updateWarning();
-
 
242
                }
-
 
243
            }
-
 
244
        };
-
 
245
 
-
 
246
        this.montant.getDocument().addDocumentListener(new SimpleDocumentListener() {
266
        this.montant.getDocument().addDocumentListener(listenerMontant);
247
 
-
 
248
            @Override
-
 
249
            public void update(DocumentEvent e) {
-
 
250
                table.getRowValuesTable().getRowValuesTableModel().removeTableModelListener(tableListener);
-
 
251
                updateMontant(montant.getText());
-
 
252
                table.getRowValuesTable().getRowValuesTableModel().addTableModelListener(tableListener);
-
 
253
                updateWarning();
-
 
254
 
-
 
255
            }
-
 
256
        });
-
 
257
        this.table.getRowValuesTable().getRowValuesTableModel().addTableModelListener(tableListener);
267
        this.table.getRowValuesTable().getRowValuesTableModel().addTableModelListener(tableListener);
258
 
268
 
259
    }
269
    }
260
 
270
 
261
    private void updateMontant(String s) {
271
    private void updateMontant(String s) {