Пример #1
0
 private ListPanelEcheancesClients(final SQLElement elem) {
   super(elem, new IListe(elem.getTableSource(true)));
   setListe();
 }
  JPanel createAllOrderPanel() {
    final SQLElement eltCmd =
        Configuration.getInstance().getDirectory().getElement("COMMANDE_CLIENT");
    final SQLTableModelSourceOnline tableSource = eltCmd.getTableSource(true);
    final List<RowAction> allowedActions = new ArrayList<RowAction>();
    // Transfert vers facture
    PredicateRowAction bonAction =
        new PredicateRowAction(
            new AbstractAction() {
              public void actionPerformed(ActionEvent e) {
                transfertBonLivraisonClient(IListe.get(e).copySelectedRows());
              }
            },
            false,
            "sales.order.create.deliverynote");

    // Transfert vers facture
    RowAction factureAction =
        new RowAction(
            new AbstractAction() {
              public void actionPerformed(ActionEvent e) {
                transfertFactureClient(IListe.get(e).copySelectedRows());
              }
            },
            false,
            "sales.order.create.invoice") {

          @Override
          public boolean enabledFor(List<SQLRowAccessor> selection) {
            if (selection.isEmpty()) {
              return false;
            } else if (selection.size() > 1) {
              return true;
            } else {
              BigDecimal d = getAvancement(selection.get(0));
              return d.signum() == 0;
            }
          }
        };

    // Transfert vers facture intermédiaire
    RowAction acompteAction =
        new RowAction(
            new AbstractAction("Créer une facture intermédiaire") {
              public void actionPerformed(ActionEvent e) {
                transfertAcompteClient(IListe.get(e).copySelectedRows());
              }
            },
            false,
            "sales.order.create.account") {
          BigDecimal cent = BigDecimal.ONE.movePointRight(2);

          @Override
          public boolean enabledFor(List<SQLRowAccessor> selection) {
            if (selection.isEmpty() || selection.size() > 1) {
              return false;
            } else {
              BigDecimal d = getAvancement(selection.get(0));
              return NumberUtils.compare(d, cent) != 0;
            }
          }
        };

    // Transfert vers facture solde
    RowAction soldeAction =
        new RowAction(
            new AbstractAction("Facturer le solde") {
              public void actionPerformed(ActionEvent e) {
                transfertSoldeClient(IListe.get(e).copySelectedRows());
              }
            },
            false,
            "sales.order.create.account.solde") {
          BigDecimal cent = BigDecimal.ONE.movePointRight(2);

          @Override
          public boolean enabledFor(List<SQLRowAccessor> selection) {
            if (selection.isEmpty() || selection.size() > 1) {
              return false;
            } else {
              BigDecimal d = getAvancement(selection.get(0));
              return NumberUtils.compare(d, cent) != 0
                  && NumberUtils.compare(d, BigDecimal.ZERO) != 0;
            }
          }
        };

    // Transfert vers commande
    PredicateRowAction cmdAction =
        new PredicateRowAction(
            new AbstractAction() {
              public void actionPerformed(ActionEvent e) {
                final int selectedId = IListe.get(e).getSelectedId();
                ComptaPropsConfiguration.getInstanceCompta()
                    .getNonInteractiveSQLExecutor()
                    .execute(
                        new Runnable() {

                          @Override
                          public void run() {
                            final CommandeClientSQLElement elt =
                                (CommandeClientSQLElement)
                                    Configuration.getInstance()
                                        .getDirectory()
                                        .getElement("COMMANDE_CLIENT");
                            elt.transfertCommande(selectedId);
                          }
                        });
              }
            },
            false,
            "sales.order.create.supplier.order");

    cmdAction.setPredicate(IListeEvent.getSingleSelectionPredicate());

    bonAction.setPredicate(IListeEvent.getSingleSelectionPredicate());
    allowedActions.add(bonAction);
    allowedActions.add(factureAction);
    allowedActions.add(acompteAction);
    allowedActions.add(soldeAction);
    allowedActions.add(cmdAction);

    this.colAvancement =
        new BaseSQLTableModelColumn("Avancement facturation", BigDecimal.class) {

          @Override
          protected Object show_(SQLRowAccessor r) {

            return getAvancement(r);
          }

          @Override
          public Set<FieldPath> getPaths() {
            final Path p =
                new PathBuilder(eltCmd.getTable())
                    .addTable("TR_COMMANDE_CLIENT")
                    .addTable("SAISIE_VENTE_FACTURE")
                    .build();
            return CollectionUtils.createSet(new FieldPath(p, "T_HT"));
          }
        };
    tableSource.getColumns().add(this.colAvancement);
    this.colAvancement.setRenderer(new PercentTableCellRenderer());
    final ListeAddPanel panel = getPanel(eltCmd, tableSource, allowedActions);
    return panel;
  }