OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

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