public static int getHours(SQLRowAccessor row) {
   int h = 0;
   final String code = row.getForeign("ID_UNITE_VENTE").getString("CODE");
   if (code.equals("h")) {
     h += row.getLong("QTE_UNITAIRE") * row.getLong("QTE");
   } else if (code.equals("j")) {
     h += row.getLong("QTE_UNITAIRE") * row.getLong("QTE") * 8;
   }
   return h;
 }
 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;
  }