OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 156 | Rev 182 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
18 ilm 1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2011 OpenConcerto, by ILM Informatique. All rights reserved.
5
 *
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
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.
10
 *
11
 * When distributing the software, include this License Header Notice in each file.
12
 */
13
 
14
 package org.openconcerto.erp.core.sales.invoice.ui;
15
 
16
import org.openconcerto.erp.config.ComptaPropsConfiguration;
17
import org.openconcerto.erp.core.common.ui.IListFilterDatePanel;
18
import org.openconcerto.erp.core.common.ui.IListTotalPanel;
21 ilm 19
import org.openconcerto.erp.core.common.ui.ListeViewPanel;
18 ilm 20
import org.openconcerto.erp.core.finance.accounting.ui.ListeGestCommEltPanel;
151 ilm 21
import org.openconcerto.erp.core.finance.payment.element.SDDMessageSQLElement;
22
import org.openconcerto.erp.core.finance.payment.element.SDDMessageSQLElement.GenerationResult;
23
import org.openconcerto.erp.core.finance.payment.element.SDDMessageSQLElement.IgnoreReason;
24
import org.openconcerto.erp.core.sales.invoice.element.SaisieVenteFactureSQLElement;
156 ilm 25
import org.openconcerto.erp.core.sales.pos.POSConfiguration;
21 ilm 26
import org.openconcerto.erp.core.sales.pos.ui.TextAreaTicketPanel;
151 ilm 27
import org.openconcerto.erp.utils.TM;
18 ilm 28
import org.openconcerto.sql.element.SQLElement;
177 ilm 29
import org.openconcerto.sql.element.SQLElementDirectory;
151 ilm 30
import org.openconcerto.sql.model.FieldPath;
18 ilm 31
import org.openconcerto.sql.model.SQLField;
80 ilm 32
import org.openconcerto.sql.model.SQLRowAccessor;
18 ilm 33
import org.openconcerto.sql.model.SQLRowValues;
34
import org.openconcerto.sql.model.Where;
151 ilm 35
import org.openconcerto.sql.model.graph.Path;
156 ilm 36
import org.openconcerto.sql.request.UpdateBuilder;
18 ilm 37
import org.openconcerto.sql.view.list.IListe;
151 ilm 38
import org.openconcerto.sql.view.list.IListeAction.IListeEvent;
21 ilm 39
import org.openconcerto.sql.view.list.ITableModel;
151 ilm 40
import org.openconcerto.sql.view.list.RowAction;
41
import org.openconcerto.sql.view.list.RowAction.PredicateRowAction;
18 ilm 42
import org.openconcerto.sql.view.list.SQLTableModelColumn;
43
import org.openconcerto.sql.view.list.SQLTableModelColumnPath;
44
import org.openconcerto.sql.view.list.SQLTableModelSourceOnline;
45
import org.openconcerto.ui.DefaultGridBagConstraints;
19 ilm 46
import org.openconcerto.ui.JLabelBold;
21 ilm 47
import org.openconcerto.ui.PanelFrame;
83 ilm 48
import org.openconcerto.utils.ExceptionHandler;
18 ilm 49
import org.openconcerto.utils.TableSorter;
50
import org.openconcerto.utils.cc.IClosure;
151 ilm 51
import org.openconcerto.utils.i18n.Grammar_fr;
18 ilm 52
 
53
import java.awt.GridBagConstraints;
54
import java.awt.GridBagLayout;
55
import java.awt.Insets;
56
import java.awt.event.ActionEvent;
57
import java.math.BigInteger;
58
import java.sql.SQLException;
59
import java.util.ArrayList;
151 ilm 60
import java.util.Collections;
18 ilm 61
import java.util.Date;
151 ilm 62
import java.util.HashMap;
18 ilm 63
import java.util.List;
151 ilm 64
import java.util.Map;
18 ilm 65
 
151 ilm 66
import javax.swing.AbstractAction;
18 ilm 67
import javax.swing.JButton;
151 ilm 68
import javax.swing.JOptionPane;
18 ilm 69
import javax.swing.JPanel;
70
import javax.swing.JTabbedPane;
71
import javax.swing.JTable;
151 ilm 72
import javax.swing.SwingWorker;
18 ilm 73
import javax.swing.table.TableColumn;
74
 
151 ilm 75
public class ListeDesVentesPanel extends JPanel {
18 ilm 76
 
77
    private ListeGestCommEltPanel listeFact;
151 ilm 78
    // private JButton buttonEnvoye, buttonRegle, buttonDupliquer;
93 ilm 79
    private JLabelBold textField = new JLabelBold("0");
80
    private JLabelBold textField2 = new JLabelBold("0");
18 ilm 81
 
177 ilm 82
    public ListeDesVentesPanel(final ComptaPropsConfiguration conf) {
18 ilm 83
        this.setLayout(new GridBagLayout());
84
        GridBagConstraints c = new GridBagConstraints();
85
        c.insets = new Insets(2, 2, 1, 2);
86
        c.fill = GridBagConstraints.BOTH;
87
        c.anchor = GridBagConstraints.NORTHWEST;
88
        c.gridx = 0;
89
        c.gridy = 0;
90
        c.gridwidth = 1;
91
        c.gridheight = 1;
92
        c.weightx = 1;
93
        c.weighty = 1;
94
 
95
        JTabbedPane tabbedPane = new JTabbedPane();
96
 
177 ilm 97
        final SQLElementDirectory dir = conf.getDirectory();
98
        final SQLElement elementVF = dir.getElement("SAISIE_VENTE_FACTURE");
18 ilm 99
        // tab Vente facture
80 ilm 100
        final SQLElement eltFacture = elementVF;
18 ilm 101
        final SQLTableModelSourceOnline src = eltFacture.getTableSource(true);
102
        // Filter
80 ilm 103
        Where wPrev = new Where(eltFacture.getTable().getField("PREVISIONNELLE"), "=", Boolean.FALSE);
104
        if (src.getReq().getWhere() != null) {
105
            wPrev = wPrev.and(src.getReq().getWhere());
106
        }
18 ilm 107
        src.getReq().setWhere(wPrev);
108
 
109
        final ListeFactureRenderer rend = new ListeFactureRenderer();
110
        for (SQLTableModelColumn column : src.getColumns()) {
111
            if (column.getClass().isAssignableFrom(SQLTableModelColumnPath.class)) {
112
                ((SQLTableModelColumnPath) column).setEditable(false);
113
            }
83 ilm 114
            // FIXME Voir pour appliquer le renderer correctement
115
            if (!column.getName().startsWith("Avancement")) {
116
                column.setRenderer(rend);
117
            }
18 ilm 118
        }
119
 
120
        final SQLTableModelColumn dateEnvoiCol = src.getColumn(eltFacture.getTable().getField("DATE_ENVOI"));
121
            ((SQLTableModelColumnPath) dateEnvoiCol).setEditable(true);
122
        final SQLTableModelColumn dateReglCol = src.getColumn(eltFacture.getTable().getField("DATE_REGLEMENT"));
61 ilm 123
        if (dateReglCol != null)
124
            ((SQLTableModelColumnPath) dateReglCol).setEditable(true);
18 ilm 125
 
19 ilm 126
            // Edition des dates d'envois
127
            dateEnvoiCol.setColumnInstaller(new IClosure<TableColumn>() {
128
                @Override
129
                public void executeChecked(TableColumn columnDateEnvoi) {
151 ilm 130
                    final org.openconcerto.ui.table.TimestampTableCellEditor cellEditor = new org.openconcerto.ui.table.TimestampTableCellEditor();
131
                    cellEditor.setAllowNull(true);
132
                    columnDateEnvoi.setCellEditor(cellEditor);
19 ilm 133
                    columnDateEnvoi.setCellRenderer(new DateEnvoiRenderer());
134
                }
135
            });
18 ilm 136
 
137
        // Edition des dates de reglement
61 ilm 138
        if (dateReglCol != null) {
139
            dateReglCol.setColumnInstaller(new IClosure<TableColumn>() {
151 ilm 140
 
61 ilm 141
                @Override
142
                public void executeChecked(TableColumn columnDateReglement) {
151 ilm 143
                    final org.openconcerto.ui.table.TimestampTableCellEditor cellEditor = new org.openconcerto.ui.table.TimestampTableCellEditor();
144
                    cellEditor.setAllowNull(true);
145
                    columnDateReglement.setCellEditor(cellEditor);
61 ilm 146
                    columnDateReglement.setCellRenderer(new DateEnvoiRenderer());
147
                }
148
            });
149
        }
18 ilm 150
 
151 ilm 151
        src.getColumns().add(new SQLTableModelColumnPath(new FieldPath(new Path(eltFacture.getTable()).addForeignField(SaisieVenteFactureSQLElement.MESSAGE_FIELD_NAME), "MessageIdentification")));
152
 
18 ilm 153
        this.listeFact = new ListeGestCommEltPanel(eltFacture, new IListe(src), true);
151 ilm 154
 
18 ilm 155
        this.listeFact.setOpaque(false);
151 ilm 156
        this.listeFact.getListe().setModificationAllowed(true);
18 ilm 157
        final JTable tableFact = this.listeFact.getListe().getJTable();
158
        final SQLTableModelColumn numeroCol = src.getColumn(eltFacture.getTable().getField("NUMERO"));
159
        ((TableSorter) tableFact.getModel()).setSortingStatus(src.getColumns().indexOf(numeroCol), TableSorter.ASCENDING);
160
 
161
        JPanel panelFacture = new JPanel(new GridBagLayout());
162
        GridBagConstraints cFacture = new DefaultGridBagConstraints();
163
 
164
        cFacture.gridy++;
165
        cFacture.gridx = 0;
166
        cFacture.weighty = 1;
167
        cFacture.weightx = 1;
168
        cFacture.gridwidth = GridBagConstraints.REMAINDER;
169
        cFacture.fill = GridBagConstraints.BOTH;
170
        panelFacture.add(this.listeFact, cFacture);
171
 
172
        List<SQLField> l = new ArrayList<SQLField>();
142 ilm 173
        if (this.listeFact.getListe().getSource().getColumn(eltFacture.getTable().getField("T_HA")) != null) {
174
            l.add(eltFacture.getTable().getField("T_HA"));
175
        }
18 ilm 176
        l.add(eltFacture.getTable().getField("T_HT"));
177
        l.add(eltFacture.getTable().getField("T_TTC"));
61 ilm 178
        final IListTotalPanel total = new IListTotalPanel(this.listeFact.getListe(), l);
18 ilm 179
        cFacture.weighty = 0;
180
        cFacture.fill = GridBagConstraints.NONE;
181
        cFacture.gridy++;
182
        cFacture.anchor = GridBagConstraints.EAST;
183
        total.setOpaque(false);
184
        panelFacture.add(total, cFacture);
185
 
19 ilm 186
 
18 ilm 187
        IListFilterDatePanel filterDate = new IListFilterDatePanel(this.listeFact.getListe(), eltFacture.getTable().getField("DATE"), IListFilterDatePanel.getDefaultMap());
188
        cFacture.weighty = 0;
189
        cFacture.fill = GridBagConstraints.HORIZONTAL;
190
        cFacture.gridy++;
191
        filterDate.setOpaque(false);
192
        panelFacture.add(filterDate, cFacture);
193
        tabbedPane.add("Ventes avec facture", panelFacture);
194
 
151 ilm 195
        PredicateRowAction actionRegle = new PredicateRowAction(new AbstractAction("Facture réglée") {
18 ilm 196
 
151 ilm 197
            @Override
198
            public void actionPerformed(ActionEvent e) {
199
                final List<SQLRowValues> selectedRows = IListe.get(e).getSelectedRows();
200
                for (SQLRowAccessor sqlRowAccessor : selectedRows) {
201
                    final SQLRowValues rowVals = sqlRowAccessor.asRow().createEmptyUpdateRow();
202
                    rowVals.put("DATE_REGLEMENT", new Date());
203
                    try {
204
                        rowVals.update();
205
                    } catch (SQLException e1) {
206
                        ExceptionHandler.handle("Modification impossible", e1);
207
                    }
208
                }
209
            }
210
        }, true);
211
        actionRegle.setPredicate(IListeEvent.getNonEmptySelectionPredicate());
212
        this.listeFact.getListe().addIListeAction(actionRegle);
80 ilm 213
 
151 ilm 214
        PredicateRowAction actionEnvoye = new PredicateRowAction(new AbstractAction("Facture envoyée") {
215
 
216
            @Override
217
            public void actionPerformed(ActionEvent e) {
218
                final List<SQLRowValues> selectedRows = IListe.get(e).getSelectedRows();
219
                for (SQLRowAccessor sqlRowAccessor : selectedRows) {
220
                    final SQLRowValues rowVals = sqlRowAccessor.asRow().createEmptyUpdateRow();
221
                    rowVals.put("DATE_ENVOI", new Date());
222
                    try {
223
                        rowVals.update();
224
                    } catch (SQLException e1) {
225
                        ExceptionHandler.handle("Modification impossible", e1);
226
                    }
80 ilm 227
                }
18 ilm 228
            }
151 ilm 229
        }, true);
230
        actionEnvoye.setPredicate(IListeEvent.getNonEmptySelectionPredicate());
231
        this.listeFact.getListe().addIListeAction(actionEnvoye);
18 ilm 232
 
21 ilm 233
 
234
            {
235
                // Tab Vente caisse
177 ilm 236
                ListeViewPanel panelTicket = new ListeViewPanel(dir.getElement("TICKET_CAISSE")) {
21 ilm 237
                    @Override
238
                    protected void handleAction(JButton source, ActionEvent evt) {
239
                        if (source == this.buttonModifier) {
156 ilm 240
                            POSConfiguration posConf = POSConfiguration.getInstance();
241
                            try {
242
                                if (posConf == null)
243
                                    posConf = POSConfiguration.setInstance();
244
                            } catch (Exception e) {
245
                                ExceptionHandler.handle(source, "Impossible d'initialiser la configuration de la caisse", e);
246
                                return;
247
                            }
248
                            new PanelFrame(new TextAreaTicketPanel(posConf, this.getListe().fetchSelectedRow()), "Ticket").setVisible(true);
21 ilm 249
                        } else {
250
                            super.handleAction(source, evt);
251
                        }
252
                    }
253
                };
254
 
255
                JPanel panel = new JPanel(new GridBagLayout());
256
                GridBagConstraints cc = new DefaultGridBagConstraints();
257
                cc.weightx = 1;
258
                cc.weighty = 1;
259
                cc.fill = GridBagConstraints.BOTH;
260
                panel.add(panelTicket, cc);
261
 
262
                final List<SQLField> l2 = new ArrayList<SQLField>();
263
                l2.add(panelTicket.getElement().getTable().getField("TOTAL_HT"));
264
                l2.add(panelTicket.getElement().getTable().getField("TOTAL_TTC"));
61 ilm 265
                final IListTotalPanel total2 = new IListTotalPanel(panelTicket.getListe(), l2);
21 ilm 266
                cc.weighty = 0;
267
                cc.fill = GridBagConstraints.NONE;
268
                cc.gridy++;
269
                cc.anchor = GridBagConstraints.EAST;
270
                total2.setOpaque(false);
271
                panel.add(total2, cc);
272
 
273
                IListFilterDatePanel filterDate2 = new IListFilterDatePanel(panelTicket.getListe(), panelTicket.getElement().getTable().getField("DATE"), IListFilterDatePanel.getDefaultMap());
274
                cc.weighty = 0;
275
                cc.fill = GridBagConstraints.HORIZONTAL;
276
                cc.gridy++;
277
                filterDate2.setOpaque(false);
278
                panel.add(filterDate2, cc);
279
 
280
                tabbedPane.add("Ventes caisse", panel);
281
 
282
            }
19 ilm 283
            // Tab Vente comptoir
21 ilm 284
            {
177 ilm 285
                final ListeGestCommEltPanel listeVC = new ListeGestCommEltPanel(dir.getElement("SAISIE_VENTE_COMPTOIR"), true);
151 ilm 286
                listeVC.getListe().setModificationAllowed(false);
21 ilm 287
                listeVC.setOpaque(false);
18 ilm 288
 
21 ilm 289
                final JTable table = listeVC.getListe().getJTable();
290
                for (int i = 0; i < table.getColumnCount(); i++) {
291
                    if (table.getColumnClass(i) == Long.class || table.getColumnClass(i) == BigInteger.class) {
292
                        table.getColumnModel().getColumn(i).setCellRenderer(rend);
293
                    }
19 ilm 294
                }
18 ilm 295
 
21 ilm 296
                JPanel panelComptoir = new JPanel(new GridBagLayout());
297
                GridBagConstraints cc = new DefaultGridBagConstraints();
298
                cc.weightx = 1;
299
                cc.weighty = 1;
300
                cc.fill = GridBagConstraints.BOTH;
301
                panelComptoir.add(listeVC, cc);
18 ilm 302
 
21 ilm 303
                final List<SQLField> l2 = new ArrayList<SQLField>();
304
                l2.add(listeVC.getElement().getTable().getField("MONTANT_HT"));
305
                l2.add(listeVC.getElement().getTable().getField("MONTANT_TTC"));
61 ilm 306
                final IListTotalPanel total2 = new IListTotalPanel(listeVC.getListe(), l2);
21 ilm 307
                cc.weighty = 0;
308
                cc.fill = GridBagConstraints.NONE;
309
                cc.gridy++;
310
                cc.anchor = GridBagConstraints.EAST;
311
                total2.setOpaque(false);
312
                panelComptoir.add(total2, cc);
18 ilm 313
 
21 ilm 314
                IListFilterDatePanel filterDate2 = new IListFilterDatePanel(listeVC.getListe(), listeVC.getElement().getTable().getField("DATE"), IListFilterDatePanel.getDefaultMap());
315
                cc.weighty = 0;
316
                cc.fill = GridBagConstraints.HORIZONTAL;
317
                cc.gridy++;
318
                filterDate2.setOpaque(false);
319
                panelComptoir.add(filterDate2, cc);
18 ilm 320
 
21 ilm 321
                tabbedPane.add("Ventes comptoir", panelComptoir);
322
            }
18 ilm 323
        this.add(tabbedPane, c);
324
    }
325
 
326
}