OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 128 | Rev 152 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 128 Rev 146
Line 57... Line 57...
57
import org.openconcerto.sql.model.SQLTableEvent.Mode;
57
import org.openconcerto.sql.model.SQLTableEvent.Mode;
58
import org.openconcerto.sql.model.SQLTableModifiedListener;
58
import org.openconcerto.sql.model.SQLTableModifiedListener;
59
import org.openconcerto.sql.model.Where;
59
import org.openconcerto.sql.model.Where;
60
import org.openconcerto.sql.model.graph.Link.Direction;
60
import org.openconcerto.sql.model.graph.Link.Direction;
61
import org.openconcerto.sql.model.graph.Path;
61
import org.openconcerto.sql.model.graph.Path;
-
 
62
import org.openconcerto.sql.utils.AlterTable;
62
import org.openconcerto.sql.utils.SQLCreateTable;
63
import org.openconcerto.sql.utils.SQLCreateTable;
63
import org.openconcerto.sql.view.EditFrame;
64
import org.openconcerto.sql.view.EditFrame;
64
import org.openconcerto.sql.view.IListFrame;
65
import org.openconcerto.sql.view.IListFrame;
65
import org.openconcerto.sql.view.ListeAddPanel;
66
import org.openconcerto.sql.view.ListeAddPanel;
66
import org.openconcerto.sql.view.column.ColumnFooterRenderer;
67
import org.openconcerto.sql.view.column.ColumnFooterRenderer;
Line 78... Line 79...
78
import org.openconcerto.utils.i18n.TranslationManager;
79
import org.openconcerto.utils.i18n.TranslationManager;
79
 
80
 
80
public final class Module extends AbstractModule {
81
public final class Module extends AbstractModule {
81
 
82
 
82
    public static final String PROJECT_TABLENAME = "AFFAIRE";
83
    public static final String PROJECT_TABLENAME = "AFFAIRE";
83
    private List<String> listTableAffaire = Arrays.asList("SAISIE_VENTE_FACTURE", "AVOIR_CLIENT", "BON_DE_LIVRAISON", "COMMANDE_CLIENT", "DEVIS", "COMMANDE", "SAISIE_ACHAT", "AVOIR_FOURNISSEUR");
84
    private List<String> listTableAffaire = Arrays.asList("DEMANDE_PRIX", "DEMANDE_ACHAT_ELEMENT", "SAISIE_VENTE_FACTURE", "AVOIR_CLIENT", "BON_DE_LIVRAISON", "COMMANDE_CLIENT", "DEVIS", "COMMANDE",
-
 
85
            "SAISIE_ACHAT", "AVOIR_FOURNISSEUR");
84
 
86
 
85
    public Module(ModuleFactory f) throws IOException {
87
    public Module(ModuleFactory f) throws IOException {
86
        super(f);
88
        super(f);
87
 
89
 
88
    }
90
    }
Line 291... Line 293...
291
        NumerotationAutoSQLElement.addClass(ProjectSQLElement.class, PROJECT_TABLENAME);
293
        NumerotationAutoSQLElement.addClass(ProjectSQLElement.class, PROJECT_TABLENAME);
292
 
294
 
293
        for (String tableName : this.listTableAffaire) {
295
        for (String tableName : this.listTableAffaire) {
294
            if (!tableName.equalsIgnoreCase("DEVIS")) {
296
            if (!tableName.equalsIgnoreCase("DEVIS")) {
295
                final SQLElement elt = dir.getElement(tableName);
297
                final SQLElement elt = dir.getElement(tableName);
-
 
298
                if (elt == null) {
-
 
299
                    JOptionPane.showMessageDialog(null, "Table " + tableName + " manquante");
-
 
300
                    continue;
-
 
301
                }
296
                RowAction action = new RowAction(new AbstractAction("Historique affaire") {
302
                RowAction action = new RowAction(new AbstractAction("Historique affaire") {
297
                    @Override
303
                    @Override
298
                    public void actionPerformed(ActionEvent e) {
304
                    public void actionPerformed(ActionEvent e) {
299
                        ProjectHistory histo = new ProjectHistory();
305
                        ProjectHistory histo = new ProjectHistory();
300
                        histo.getHistoriquePanel().selectIDinJList(IListe.get(e).getSelectedRow().getForeignID("ID_AFFAIRE"));
306
                        histo.getHistoriquePanel().selectIDinJList(IListe.get(e).getSelectedRow().getForeignID("ID_AFFAIRE"));
Line 421... Line 427...
421
                } catch (SQLException exn) {
427
                } catch (SQLException exn) {
422
                    // TODO Bloc catch auto-généré
428
                    // TODO Bloc catch auto-généré
423
                    exn.printStackTrace();
429
                    exn.printStackTrace();
424
                }
430
                }
425
            }
431
            }
-
 
432
 
426
        } else {
433
        } else if (row.getInt("ID_ETAT_DEVIS") != EtatDevisSQLElement.ACCEPTE) {
427
            SQLRowValues rowVals = rowAffaire.asRowValues();
434
            SQLRowValues rowVals = rowAffaire.asRowValues();
428
            rowVals.putEmptyLink("ID_DEVIS");
435
            rowVals.putEmptyLink("ID_DEVIS");
429
            try {
436
            try {
430
                rowVals.update();
437
                rowVals.update();
431
            } catch (SQLException exn) {
438
            } catch (SQLException exn) {
432
                // TODO Bloc catch auto-généré
-
 
433
                exn.printStackTrace();
439
                exn.printStackTrace();
434
            }
440
            }
435
        }
441
        }
436
    }
442
    }
437
 
443
 
Line 506... Line 512...
506
        };
512
        };
507
    }
513
    }
508
 
514
 
509
    @Override
515
    @Override
510
    protected void setupComponents(final ComponentsContext ctxt) {
516
    protected void setupComponents(final ComponentsContext ctxt) {
-
 
517
        DBRoot root = ComptaPropsConfiguration.getInstanceCompta().getRootSociete();
-
 
518
        List<String> table2check = Arrays.asList("DEMANDE_PRIX", "DEMANDE_ACHAT_ELEMENT");
-
 
519
        for (String table : table2check) {
-
 
520
            if (root.contains(table)) {
-
 
521
                SQLTable tableCR = root.getTable(table);
-
 
522
                if (!tableCR.contains("ID_AFFAIRE")) {
-
 
523
                    try {
-
 
524
                        AlterTable alt = new AlterTable(tableCR);
-
 
525
                        alt.addForeignColumn("ID_AFFAIRE", root.getTable("AFFAIRE"));
-
 
526
                        root.getDBSystemRoot().getDataSource().execute(alt.asString());
-
 
527
                        String s = "INSERT INTO " + root.getTable("FWK_MODULE_METADATA").getSQLName().quote()
-
 
528
                                + "(\"MODULE_NAME\",\"TABLE\",\"FIELD\",\"KEY\",\"MODULE_VERSION\") VALUES('org.openconcerto.modules.project','" + table + "','ID_AFFAIRE',true,10000)";
-
 
529
                        root.getDBSystemRoot().getDataSource().execute(s);
-
 
530
                        root.getSchema().updateVersion();
-
 
531
                        root.refetchTable(tableCR.getName());
-
 
532
                    } catch (SQLException e) {
-
 
533
                        e.printStackTrace();
-
 
534
                    }
-
 
535
                }
-
 
536
            }
511
 
537
        }
512
        for (String table : this.listTableAffaire) {
538
        for (String table : this.listTableAffaire) {
513
            if (!table.equalsIgnoreCase("DEVIS"))
539
            if (!table.equalsIgnoreCase("DEVIS"))
514
                ctxt.putAdditionalField(table, "ID_AFFAIRE");
540
                ctxt.putAdditionalField(table, "ID_AFFAIRE");
515
        }
541
        }
-
 
542
 
516
    }
543
    }
517
 
544
 
518
    @Override
545
    @Override
519
    protected void setupMenu(final MenuContext ctxt) {
546
    protected void setupMenu(final MenuContext ctxt) {
520
        ctxt.addMenuItem(new CreateFrameAbstractAction("Liste des affaires") {
547
        ctxt.addMenuItem(new CreateFrameAbstractAction("Liste des affaires") {
Line 538... Line 565...
538
            public JFrame createFrame() {
565
            public JFrame createFrame() {
539
                return new EditFrame(ctxt.getElement(PROJECT_TABLENAME));
566
                return new EditFrame(ctxt.getElement(PROJECT_TABLENAME));
540
            }
567
            }
541
        }, MainFrame.CREATE_MENU);
568
        }, MainFrame.CREATE_MENU);
542
 
569
 
-
 
570
        // ctxt.addMenuItem(new AbstractAction("Export Affaire") {
-
 
571
        // @Override
-
 
572
        // public void actionPerformed(ActionEvent e) {
-
 
573
        // ProjectImportExport importExport = new
-
 
574
        // ProjectImportExport(ctxt.getElement("AFFAIRE").getTable().getDBRoot());
-
 
575
        // importExport.export();
-
 
576
        // }
-
 
577
        // }, MainFrame.HELP_MENU);
-
 
578
        //
-
 
579
        // ctxt.addMenuItem(new AbstractAction("Import Affaire") {
-
 
580
        // @Override
-
 
581
        // public void actionPerformed(ActionEvent e) {
-
 
582
        // ProjectImportExport importExport = new
-
 
583
        // ProjectImportExport(ctxt.getElement("AFFAIRE").getTable().getDBRoot());
-
 
584
        // importExport.importProjects();
-
 
585
        // }
-
 
586
        // }, MainFrame.HELP_MENU);
-
 
587
        //
-
 
588
        // ctxt.addMenuItem(new AbstractAction("Fix ID_AFFAIRE") {
-
 
589
        // @Override
-
 
590
        // public void actionPerformed(ActionEvent e) {
-
 
591
        // {
-
 
592
        // SQLTable tableCmd = ctxt.getElement("COMMANDE_CLIENT").getTable();
-
 
593
        // SQLSelect selBadCmd = new SQLSelect();
-
 
594
        // selBadCmd.addSelect(tableCmd.getKey());
-
 
595
        // selBadCmd.addSelect(tableCmd.getField("ID_AFFAIRE"));
-
 
596
        // SQLSelectJoin joinTR = selBadCmd.addBackwardJoin("RIGHT", "tr",
-
 
597
        // tableCmd.getTable().getTable("TR_DEVIS").getField("ID_COMMANDE_CLIENT"), null);
-
 
598
        // SQLSelectJoin joinDevis = selBadCmd.addJoin("LEFT",
-
 
599
        // joinTR.getJoinedTable().getField("ID_DEVIS"));
-
 
600
        // SQLSelectJoin joinAff = selBadCmd.addBackwardJoin("LEFT", "aff",
-
 
601
        // tableCmd.getTable().getTable("AFFAIRE").getField("ID_DEVIS"), null);
-
 
602
        // selBadCmd.addSelect(joinAff.getJoinedTable().getKey());
-
 
603
        //
-
 
604
        // selBadCmd.setWhere(Where.isNull(tableCmd.getField("ID_AFFAIRE")));
-
 
605
        // System.err.println(selBadCmd.asString());
-
 
606
        //
-
 
607
        // List<Object[]> result = (List<Object[]>)
-
 
608
        // tableCmd.getDBSystemRoot().getDataSource().executeA(selBadCmd.asString());
-
 
609
        // try {
-
 
610
        // for (Object[] objects : result) {
-
 
611
        // if (objects[2] != null && objects[2].toString().trim().length() > 0)
-
 
612
        // tableCmd.getRow(((Number)
-
 
613
        // objects[0]).intValue()).createEmptyUpdateRow().put("ID_AFFAIRE", ((Number)
-
 
614
        // objects[2]).intValue()).commit();
-
 
615
        // }
-
 
616
        // } catch (SQLException e1) {
-
 
617
        // // TODO Auto-generated catch block
-
 
618
        // e1.printStackTrace();
-
 
619
        // }
-
 
620
        //
-
 
621
        // // List<SQLRow> list = SQLRowListRSH.execute(selBadVF);
-
 
622
        // }
-
 
623
        // {
-
 
624
        // SQLTable tableVF = ctxt.getElement("SAISIE_VENTE_FACTURE").getTable();
-
 
625
        // SQLSelect selBadVF = new SQLSelect();
-
 
626
        // selBadVF.addSelect(tableVF.getKey());
-
 
627
        // selBadVF.addSelect(tableVF.getField("ID_AFFAIRE"));
-
 
628
        // SQLSelectJoin joinTR = selBadVF.addBackwardJoin("RIGHT", "tr",
-
 
629
        // tableVF.getTable().getTable("TR_COMMANDE_CLIENT").getField("ID_SAISIE_VENTE_FACTURE"),
-
 
630
        // null);
-
 
631
        // SQLSelectJoin joinCmd = selBadVF.addJoin("LEFT",
-
 
632
        // joinTR.getJoinedTable().getField("ID_COMMANDE_CLIENT"));
-
 
633
        // selBadVF.addSelect(joinCmd.getJoinedTable().getField("ID_AFFAIRE"));
-
 
634
        //
-
 
635
        // selBadVF.setWhere(Where.isNull(tableVF.getField("ID_AFFAIRE")));
-
 
636
        // System.err.println(selBadVF.asString());
-
 
637
        // List<Object[]> result = (List<Object[]>)
-
 
638
        // tableVF.getDBSystemRoot().getDataSource().executeA(selBadVF.asString());
-
 
639
        // try {
-
 
640
        // for (Object[] objects : result) {
-
 
641
        // if (objects[2] != null && objects[2].toString().trim().length() > 0)
-
 
642
        // tableVF.getRow(((Number) objects[0]).intValue()).createEmptyUpdateRow().put("ID_AFFAIRE",
-
 
643
        // ((Number) objects[2]).intValue()).commit();
-
 
644
        // }
-
 
645
        // } catch (SQLException e1) {
-
 
646
        // // TODO Auto-generated catch block
-
 
647
        // e1.printStackTrace();
-
 
648
        // }
-
 
649
        // }
-
 
650
        // }
-
 
651
        // }, MainFrame.CREATE_MENU);
-
 
652
        //
-
 
653
        // ctxt.addMenuItem(new AbstractAction("Recalcul Total achat facture prorata") {
-
 
654
        // @Override
-
 
655
        // public void actionPerformed(ActionEvent e) {
-
 
656
        //
-
 
657
        // {
-
 
658
        // final SQLTable table = ctxt.getElement("SAISIE_VENTE_FACTURE").getTable();
-
 
659
        // SQLRowValues rowValsFact = new SQLRowValues(table);
-
 
660
        // rowValsFact.putNulls("SOLDE", "PARTIAL", "T_HA", "T_HT");
-
 
661
        //
-
 
662
        // final SQLTable tableCmd = ctxt.getElement("COMMANDE_CLIENT").getTable();
-
 
663
        // SQLRowValues rowValsCmd = new SQLRowValues(tableCmd);
-
 
664
        // rowValsCmd.putNulls("T_HT");
-
 
665
        //
-
 
666
        // final SQLTable tableCmdElt = ctxt.getElement("COMMANDE_CLIENT_ELEMENT").getTable();
-
 
667
        // SQLRowValues rowValsCmdElt = new SQLRowValues(tableCmdElt);
-
 
668
        // rowValsCmdElt.put("ID_COMMANDE_CLIENT", rowValsCmd);
-
 
669
        // rowValsCmdElt.putNulls("T_PA_HT", "NIVEAU");
-
 
670
        //
-
 
671
        // final SQLTable tableTR = table.getTable("TR_COMMANDE_CLIENT");
-
 
672
        // SQLRowValues rowValsTR = new SQLRowValues(tableTR);
-
 
673
        // rowValsTR.put("ID_SAISIE_VENTE_FACTURE", rowValsFact);
-
 
674
        // rowValsTR.put("ID_COMMANDE_CLIENT", rowValsCmd);
-
 
675
        //
-
 
676
        // SQLRowValuesListFetcher fetcher = SQLRowValuesListFetcher.create(rowValsFact);
-
 
677
        // fetcher.appendSelTransf(new ITransformer<SQLSelect, SQLSelect>() {
-
 
678
        // @Override
-
 
679
        // public SQLSelect transformChecked(SQLSelect input) {
-
 
680
        // Where w = new Where(table.getField("SOLDE"), "=", Boolean.TRUE);
-
 
681
        // w = w.or(new Where(table.getField("PARTIAL"), "=", Boolean.TRUE));
-
 
682
        // input.setWhere(w);
-
 
683
        // return input;
-
 
684
        // }
-
 
685
        // });
-
 
686
        //
-
 
687
        // List<SQLRowValues> rowVals = fetcher.fetch();
-
 
688
        //
-
 
689
        // for (SQLRowValues sqlRowValues : rowVals) {
-
 
690
        // // Recuperation de la commande
-
 
691
        // final Collection<SQLRowValues> referentRows = sqlRowValues.getReferentRows(tableTR);
-
 
692
        // if (!referentRows.isEmpty()) {
-
 
693
        // SQLRowAccessor rowTR = referentRows.iterator().next();
-
 
694
        // SQLRowAccessor rowCmd = rowTR.getForeign("ID_COMMANDE_CLIENT");
-
 
695
        // final long htCmd = rowCmd.getLong("T_HT");
-
 
696
        // if (htCmd != 0) {
-
 
697
        //
-
 
698
        // BigDecimal totalHA = BigDecimal.ZERO;
-
 
699
        // Collection<? extends SQLRowAccessor> elt = rowCmd.getReferentRows(tableCmdElt);
-
 
700
        // for (SQLRowAccessor sqlRowAccessor : elt) {
-
 
701
        // if (sqlRowAccessor.getInt("NIVEAU") == 1) {
-
 
702
        // totalHA = totalHA.add(sqlRowAccessor.getBigDecimal("T_PA_HT"));
-
 
703
        // }
-
 
704
        // }
-
 
705
        // BigDecimal prorata = new BigDecimal((double) sqlRowValues.getLong("T_HT") / (double)
-
 
706
        // htCmd);
-
 
707
        // try {
-
 
708
        // sqlRowValues.createEmptyUpdateRow().put("T_HA",
-
 
709
        // totalHA.multiply(prorata).movePointRight(2).setScale(0,
-
 
710
        // RoundingMode.HALF_UP).longValue()).update();
-
 
711
        // } catch (SQLException e1) {
-
 
712
        // e1.printStackTrace();
-
 
713
        // }
-
 
714
        // }
-
 
715
        // }
-
 
716
        // }
-
 
717
        // }
-
 
718
        // }
-
 
719
        // }, MainFrame.CREATE_MENU);
-
 
720
 
543
    }
721
    }
544
 
722
 
545
    @Override
723
    @Override
546
    protected void start() {
724
    protected void start() {
-
 
725
 
-
 
726
 
-
 
727
 
547
        final JComponent quoteComponent = createQuotePanel();
728
        final JComponent quoteComponent = createQuotePanel();
548
        final JComponent orderComponent = createOrderPanel();
729
        final JComponent orderComponent = createOrderPanel();
549
        MainFrame.getInstance().getTabbedPane().addTab("Commandes en cours", orderComponent);
730
        MainFrame.getInstance().getTabbedPane().addTab("Commandes en cours", orderComponent);
550
        MainFrame.getInstance().getTabbedPane().addTab("Devis en attente", quoteComponent);
731
        MainFrame.getInstance().getTabbedPane().addTab("Devis en attente", quoteComponent);
551
        MainFrame.getInstance().getTabbedPane().addTab("Affaires", new ListeAddPanel(Configuration.getInstance().getDirectory().getElement(PROJECT_TABLENAME)));
732
        MainFrame.getInstance().getTabbedPane().addTab("Affaires", new ListeAddPanel(Configuration.getInstance().getDirectory().getElement(PROJECT_TABLENAME)));