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 177
Line 24... Line 24...
24
import org.openconcerto.erp.generationDoc.AbstractSheetXml;
24
import org.openconcerto.erp.generationDoc.AbstractSheetXml;
25
import org.openconcerto.erp.model.MouseSheetXmlListeListener;
25
import org.openconcerto.erp.model.MouseSheetXmlListeListener;
26
import org.openconcerto.sql.Configuration;
26
import org.openconcerto.sql.Configuration;
27
import org.openconcerto.sql.element.SQLElement;
27
import org.openconcerto.sql.element.SQLElement;
28
import org.openconcerto.sql.element.SQLElementDirectory;
28
import org.openconcerto.sql.element.SQLElementDirectory;
-
 
29
import org.openconcerto.sql.model.AliasedTable;
29
import org.openconcerto.sql.model.SQLDataSource;
30
import org.openconcerto.sql.model.SQLDataSource;
30
import org.openconcerto.sql.model.SQLField;
31
import org.openconcerto.sql.model.SQLField;
31
import org.openconcerto.sql.model.SQLFieldsSet;
32
import org.openconcerto.sql.model.SQLFieldsSet;
32
import org.openconcerto.sql.model.SQLRow;
33
import org.openconcerto.sql.model.SQLRow;
33
import org.openconcerto.sql.model.SQLRowAccessor;
34
import org.openconcerto.sql.model.SQLRowAccessor;
Line 63... Line 64...
63
import java.awt.event.ActionEvent;
64
import java.awt.event.ActionEvent;
64
import java.awt.event.ActionListener;
65
import java.awt.event.ActionListener;
65
import java.io.File;
66
import java.io.File;
66
import java.io.FilenameFilter;
67
import java.io.FilenameFilter;
67
import java.io.IOException;
68
import java.io.IOException;
-
 
69
import java.math.BigDecimal;
68
import java.math.BigInteger;
70
import java.math.BigInteger;
69
import java.sql.SQLException;
71
import java.sql.SQLException;
70
import java.util.ArrayList;
72
import java.util.ArrayList;
71
import java.util.Collections;
73
import java.util.Collections;
72
import java.util.HashMap;
74
import java.util.HashMap;
Line 122... Line 124...
122
            }
124
            }
123
            int selectIndex = ListeHistoriquePanel.this.jListePanel.getSelectedIndex();
125
            int selectIndex = ListeHistoriquePanel.this.jListePanel.getSelectedIndex();
124
 
126
 
125
            SQLRowAccessor row = ListeHistoriquePanel.this.jListePanel.getModel().getRowAt(selectIndex);
127
            SQLRowAccessor row = ListeHistoriquePanel.this.jListePanel.getModel().getRowAt(selectIndex);
126
 
128
 
127
            if ((row == null || row.isUndefined()) && undefinedLabel == null) {
129
            if ((row == null || row.isUndefined()) && ListeHistoriquePanel.this.undefinedLabel == null) {
128
                return;
130
                return;
129
            }
131
            }
130
 
132
 
131
            int id = SQLRow.NONEXISTANT_ID;
133
            int id = SQLRow.NONEXISTANT_ID;
132
            if (row != null) {
134
            if (row != null) {
Line 158... Line 160...
158
                        SQLField field = ListeHistoriquePanel.this.listFieldMap.get(table);
160
                        SQLField field = ListeHistoriquePanel.this.listFieldMap.get(table);
159
                        Where w2 = new Where(field, "=", table.getForeignTable(field.getName()).getKey());
161
                        Where w2 = new Where(field, "=", table.getForeignTable(field.getName()).getKey());
160
                        w2 = w2.and(new Where(table.getForeignTable(field.getName()).getField("ID_" + ListeHistoriquePanel.this.jListePanel.getModel().getTable().getName()), "=", id));
162
                        w2 = w2.and(new Where(table.getForeignTable(field.getName()).getField("ID_" + ListeHistoriquePanel.this.jListePanel.getModel().getTable().getName()), "=", id));
161
                        liste.getListe().getRequest().setWhere(w2.and(w));
163
                        liste.getListe().getRequest().setWhere(w2.and(w));
162
                    } else {
164
                    } else {
163
                        if (liste.getElement().getTable().equals(jListePanel.getModel().getTable())) {
165
                        if (liste.getElement().getTable().equals(ListeHistoriquePanel.this.jListePanel.getModel().getTable())) {
-
 
166
                            final Where whereMatch = new Where(table.getField("ID_" + ListeHistoriquePanel.this.jListePanel.getModel().getTable().getName()), "=", id);
-
 
167
                            if ((table.getName().equals("COMMANDE_ELEMENT") || table.getName().equals("BON_RECEPTION_ELEMENT"))
-
 
168
                                    && ListeHistoriquePanel.this.jListePanel.getModel().getTable().getName().equals("AFFAIRE")) {
-
 
169
 
-
 
170
                                // FIXME alias forcé à la main, voir pour remplacer avec un
-
 
171
                                // selectTransformer
-
 
172
                                final String tablePere = table.getName().replaceAll("_ELEMENT", "");
-
 
173
                                AliasedTable tableAlias = new AliasedTable(table.getTable(tablePere), "tAlias__ID_" + tablePere + "__" + tablePere);
-
 
174
                                final int idAffaire = id;
-
 
175
                                Where wPere = new Where(tableAlias.getField("ID_AFFAIRE"), "=", idAffaire);
164
                            liste.getListe().getRequest().setWhere(new Where(table.getKey(), "=", id).and(w));
176
                                liste.getListe().getRequest().setWhere(whereMatch.or(wPere).and(w));
-
 
177
                                // whereMatch = whereMatch.or(new Where(new
-
 
178
                                // AliasedTable(table.getForeignTable("ID_"+tablePere),
-
 
179
                                // alias).getField("ID_AFFAIRE"), "=", id));
-
 
180
 
-
 
181
                            } else {
-
 
182
                                liste.getListe().getRequest().setWhere(whereMatch.and(w));
-
 
183
                            }
-
 
184
                        } else {
-
 
185
                            if ((table.getName().equals("MOUVEMENT_STOCK")) && ListeHistoriquePanel.this.jListePanel.getModel().getTable().getName().equals("AFFAIRE")) {
-
 
186
 
-
 
187
                                final String tableStock = "STOCK";
-
 
188
                                AliasedTable tableAlias = new AliasedTable(table.getTable(tableStock), "tAlias__ID_" + tableStock + "__" + tableStock);
-
 
189
                                final int idAffaire = table.getTable("AFFAIRE").getRow(id).getForeignID("ID_DEPOT_STOCK");
-
 
190
                                Where w2 = new Where(table.getField("REEL"), "=", Boolean.TRUE);
-
 
191
                                w2 = w2.and(new Where(table.getField("SOURCE"), "=", ""));
-
 
192
                                Where wPere = new Where(tableAlias.getField("ID_DEPOT_STOCK"), "=", idAffaire).and(w2);
-
 
193
                                liste.getListe().getRequest().setWhere(wPere);
-
 
194
 
-
 
195
                            } else {
-
 
196
                                final Where whereMatch = new Where(table.getField("ID_" + ListeHistoriquePanel.this.jListePanel.getModel().getTable().getName()), "=", id);
-
 
197
                                if ((table.getName().equals("FACTURE_FOURNISSEUR_ELEMENT") || table.getName().equals("COMMANDE_ELEMENT") || table.getName().equals("BON_RECEPTION_ELEMENT"))
-
 
198
                                        && ListeHistoriquePanel.this.jListePanel.getModel().getTable().getName().equals("AFFAIRE")) {
-
 
199
 
-
 
200
                                    // FIXME alias forcé à la main, voir pour remplacer avec un
-
 
201
                                    // selectTransformer
-
 
202
                                    final String tablePere = table.getName().replaceAll("_ELEMENT", "");
-
 
203
                                    AliasedTable tableAlias = new AliasedTable(table.getTable(tablePere), "tAlias__ID_" + tablePere + "__" + tablePere);
-
 
204
                                    final int idAffaire = id;
-
 
205
                                    Where wPere = new Where(tableAlias.getField("ID_AFFAIRE"), "=", idAffaire);
-
 
206
                                    liste.getListe().getRequest().setWhere(whereMatch.or(wPere).and(w).and(new Where(table.getField("PA_HT"), "!=", BigDecimal.ZERO)));
-
 
207
 
165
                        } else {
208
                                } else {
166
                            liste.getListe().getRequest().setWhere(new Where(table.getField("ID_" + ListeHistoriquePanel.this.jListePanel.getModel().getTable().getName()), "=", id).and(w));
209
                                    liste.getListe().getRequest().setWhere(whereMatch.and(w));
-
 
210
                                }
-
 
211
                            }
167
                        }
212
                        }
168
                    }
213
                    }
169
                } else {
214
                } else {
170
                    liste.getListe().getRequest().setWhere(w);
215
                    liste.getListe().getRequest().setWhere(w);
171
                }
216
                }
Line 340... Line 385...
340
                                    super.handleAction(source, evt);
385
                                    super.handleAction(source, evt);
341
                                }
386
                                }
342
                            }
387
                            }
343
                        };
388
                        };
344
 
389
 
345
                    } else {
390
                    } else
-
 
391
 
-
 
392
                    {
346
 
393
 
347
                        liste = new ListeAddPanel(elt, new IListe(createTableSource), "historique-" + title) {
394
                        liste = new ListeAddPanel(elt, new IListe(createTableSource), "historique-" + title) {
348
                            @Override
395
                            @Override
349
                            protected void handleAction(JButton source, ActionEvent evt) {
396
                            protected void handleAction(JButton source, ActionEvent evt) {
350
                                if (source == this.buttonAjouter) {
397
                                if (source == this.buttonAjouter) {
Line 497... Line 544...
497
        });
544
        });
498
 
545
 
499
        this.addAncestorListener(new AncestorListener() {
546
        this.addAncestorListener(new AncestorListener() {
500
            @Override
547
            @Override
501
            public void ancestorAdded(AncestorEvent event) {
548
            public void ancestorAdded(AncestorEvent event) {
502
                jListePanel.addListSelectionListener(listListener);
549
                ListeHistoriquePanel.this.jListePanel.addListSelectionListener(ListeHistoriquePanel.this.listListener);
503
            }
550
            }
504
 
551
 
505
            @Override
552
            @Override
506
            public void ancestorMoved(AncestorEvent event) {
553
            public void ancestorMoved(AncestorEvent event) {
507
 
554
 
508
            }
555
            }
509
 
556
 
510
            @Override
557
            @Override
511
            public void ancestorRemoved(AncestorEvent event) {
558
            public void ancestorRemoved(AncestorEvent event) {
512
                jListePanel.removeListSelectionListener(listListener);
559
                ListeHistoriquePanel.this.jListePanel.removeListSelectionListener(ListeHistoriquePanel.this.listListener);
513
            }
560
            }
514
        });
561
        });
515
 
562
 
516
    }
563
    }
517
 
564
 
Line 545... Line 592...
545
        }
592
        }
546
    }
593
    }
547
 
594
 
548
    public void addListSelectionListener(ListSelectionListener l) {
595
    public void addListSelectionListener(ListSelectionListener l) {
549
        this.jListePanel.addListSelectionListener(l);
596
        this.jListePanel.addListSelectionListener(l);
550
        System.out.println("ListeHistoriquePanel.addListSelectionListener()" + jListePanel);
597
        System.out.println("ListeHistoriquePanel.addListSelectionListener()" + this.jListePanel);
551
    }
598
    }
552
 
599
 
553
    public void removeListSelectionListener(ListSelectionListener l) {
600
    public void removeListSelectionListener(ListSelectionListener l) {
554
        this.jListePanel.removeListSelectionListener(l);
601
        this.jListePanel.removeListSelectionListener(l);
555
    }
602
    }
Line 581... Line 628...
581
 
628
 
582
    public List<Integer> getListId(String tableName) {
629
    public List<Integer> getListId(String tableName) {
583
        IListe liste = getIListeFromTableName(tableName);
630
        IListe liste = getIListeFromTableName(tableName);
584
        List<Integer> listeIds = null;
631
        List<Integer> listeIds = null;
585
        if (liste != null) {
632
        if (liste != null) {
-
 
633
            ITableModel m = liste.getModel();
586
            int size = liste.getRowCount();
634
            int size = m.getRowCount();
587
            listeIds = new ArrayList<Integer>(size);
635
            listeIds = new ArrayList<>(size);
588
            for (int i = 0; i < size; i++) {
636
            for (int i = 0; i < size; i++) {
-
 
637
                try {
589
                listeIds.add(liste.idFromIndex(i));
638
                    listeIds.add(m.idFromIndex(i));
-
 
639
                } catch (Exception e) {
-
 
640
                    e.printStackTrace();
590
            }
641
                }
-
 
642
            }
-
 
643
 
591
        } else {
644
        } else {
592
            listeIds = Collections.emptyList();
645
            listeIds = Collections.emptyList();
593
        }
646
        }
594
        return listeIds;
647
        return listeIds;
595
    }
648
    }
596
 
649
 
597
    public void removeAllTableListener() {
650
    public void removeAllTableListener() {
598
        this.jListePanel.removeAllTableListener();
651
        this.jListePanel.removeAllTableListener();
599
        for (Integer i : this.mapListener.keySet()) {
652
        for (Integer i : this.mapListener.keySet()) {
600
            IListPanel panel = vectListePanel.get(i);
653
            IListPanel panel = this.vectListePanel.get(i);
601
            List<TableModelListener> l = this.mapListener.get(i);
654
            List<TableModelListener> l = this.mapListener.get(i);
602
            for (TableModelListener tableModelListener : l) {
655
            for (TableModelListener tableModelListener : l) {
603
                final IListe liste = panel.getListe();
656
                final IListe liste = panel.getListe();
604
                if (liste != null) {
657
                if (liste != null) {
605
                    final TableModel tableModel = liste.getTableModel();
658
                    final TableModel tableModel = liste.getTableModel();