示例#1
0
  @Override
  public void select(final SQLRowAccessor r) {
    if (r != null) {
      this.numeroUniqueDevis.setIdSelected(r.getID());
    }

    if (r == null || r.getIDNumber() == null) super.select(r);
    else {
      System.err.println(r);
      final SQLRowValues rVals = r.asRowValues();
      final SQLRowValues vals = new SQLRowValues(r.getTable());
      vals.load(rVals, createSet("ID_CLIENT"));
      vals.setID(rVals.getID());
      System.err.println("Select CLIENT");

      super.select(vals);
      rVals.remove("ID_CLIENT");
      super.select(rVals);
    }

    // super.select(r);
    if (r != null) {
      this.table.insertFrom("ID_DEVIS", r.getID());
      // this.radioEtat.setVisible(r.getID() > getTable().getUndefinedID());
      if (getTable().contains("SITE_DIFF"))
        setSiteEnabled(r.getBoolean("SITE_DIFF"), Type_Diff.SITE);

      if (getTable().contains("DONNEUR_DIFF"))
        setSiteEnabled(r.getBoolean("DONNEUR_DIFF"), Type_Diff.DONNEUR_ORDRE);
    }
  }
 public static double getTimeSpent(SQLRowAccessor row) {
   double time = 0;
   final Collection<? extends SQLRowAccessor> rTimes =
       row.getReferentRows(row.getTable().getTable("AFFAIRE_TEMPS"));
   for (SQLRowAccessor r : rTimes) {
     time += r.getFloat("TEMPS");
   }
   return time;
 }
 private BigDecimal getAvancement(SQLRowAccessor r) {
   Collection<? extends SQLRowAccessor> rows =
       r.getReferentRows(r.getTable().getTable("TR_COMMANDE_CLIENT"));
   long totalFact = 0;
   long total = r.getLong("T_HT");
   for (SQLRowAccessor row : rows) {
     if (!row.isForeignEmpty("ID_SAISIE_VENTE_FACTURE")) {
       SQLRowAccessor rowFact = row.getForeign("ID_SAISIE_VENTE_FACTURE");
       Long l = rowFact.getLong("T_HT");
       totalFact += l;
     }
   }
   if (total > 0) {
     return new BigDecimal(totalFact)
         .divide(new BigDecimal(total), DecimalUtils.HIGH_PRECISION)
         .movePointRight(2)
         .setScale(2, RoundingMode.HALF_UP);
   } else {
     return BigDecimal.ONE.movePointRight(2);
   }
 }
  @Override
  public JComponent getRenderer(final SQLRowAccessor row, int maxWidth) {
    final JPanel p = new JPanel();
    p.setLayout(new VFlowLayout(VFlowLayout.TOP, 2, 2, true));
    p.setBorder(BorderFactory.createLineBorder(new Color(206, 226, 255)));
    final String number = row.getForeign("ID_COMMANDE_CLIENT").getString("NUMERO");
    final String customer =
        row.getForeign("ID_COMMANDE_CLIENT").getForeign("ID_CLIENT").getString("NOM");

    // Amount
    final long amount =
        row.getBigDecimal("T_PV_HT")
            .setScale(2, BigDecimal.ROUND_HALF_UP)
            .movePointRight(2)
            .longValue();
    String total = GestionDevise.currencyToString(amount, true) + " € HT";
    final long totalAmount = row.getForeign("ID_COMMANDE_CLIENT").getLong("T_HT");
    if (totalAmount != amount) {
      total += ", commande de " + GestionDevise.currencyToString(totalAmount, true) + " € HT";
    }
    // Hours
    int h = getHours(row);

    p.add(new JLabelBold(number + " " + customer));
    p.add(new JLabel(total));
    if (h > 0) {
      p.add(new JLabel(h + " heures prévues"));
    }
    if (row.getTable().getDBRoot().contains("AFFAIRE_TEMPS")) {
      // Time spend
      double time = getTimeSpent(row);

      final JLabel lTime = new JLabel(time + " heures passées");
      if (time > h) {
        lTime.setFont(lTime.getFont().deriveFont(Font.BOLD));
        lTime.setForeground(new Color(255, 135, 30));
      }
      if (time > 0) {
        p.add(lTime);
      }
    }

    p.setBackground(new Color(239, 243, 248));
    p.addMouseListener(
        new MouseAdapter() {
          @Override
          public void mouseClicked(MouseEvent e) {
            if (e.getClickCount() > 1) {
              final SQLRowAccessor foreign = row.getForeign("ID_COMMANDE_CLIENT");
              EditFrame frame =
                  new EditFrame(
                      ComptaPropsConfiguration.getInstanceCompta()
                          .getDirectory()
                          .getElement(foreign.getTable()),
                      EditPanel.MODIFICATION);
              frame.selectionId(foreign.getID());
              FrameUtil.showPacked(frame);
            }
          }
        });

    return p;
  }