예제 #1
0
  /*
   * Crée un panel destiné à l'onglet de jrnl
   */
  private JPanel initJournalPanel(final Journal jrnl) {

    final JPanel panelTmp = new JPanel();
    long totalDebitJournal = 0;
    long totalCreditJournal = 0;

    panelTmp.setLayout(new GridBagLayout());

    final GridBagConstraints c = new GridBagConstraints();
    c.insets = new Insets(2, 2, 1, 2);
    c.fill = GridBagConstraints.HORIZONTAL;
    c.anchor = GridBagConstraints.NORTHWEST;
    c.gridx = 0;
    c.gridy = 0;
    c.gridwidth = 1;
    c.gridheight = 1;
    c.weightx = 1;
    c.weighty = 0;

    // Récupération des ecritures du journal avec le total par mois
    // SQLTable ecritureTable = base.getTable("ECRITURE");
    // SQLSelect sel = new SQLSelect(base);
    //
    // sel.addSelect(ecritureTable.getField("DATE"), "YEAR");
    // sel.addSelect(ecritureTable.getField("DATE"), "MONTH");
    // sel.addSelect(ecritureTable.getField("DEBIT"), "SUM");
    // sel.addSelect(ecritureTable.getField("CREDIT"), "SUM");
    //
    // Where w = new Where(ecritureTable.getField("ID_JOURNAL"), "=", jrnl.getId());
    //
    // sel.setWhere(w);
    //
    // sel.setDistinct(true);
    //
    // String req = sel.asString() + " GROUP BY YEAR(ECRITURE.DATE), MONTH(ECRITURE.DATE) ORDER
    // BY ECRITURE.DATE";

    String req =
        "SELECT DISTINCT EXTRACT(YEAR FROM \""
            + baseName
            + "\".\"ECRITURE\".\"DATE\"), "
            + "EXTRACT(MONTH FROM \""
            + baseName
            + "\".\"ECRITURE\".\"DATE\"),"
            + " SUM(\""
            + baseName
            + "\".\"ECRITURE\".\"DEBIT\"), "
            + "SUM(\""
            + baseName
            + "\".\"ECRITURE\".\"CREDIT\")"
            + " FROM \""
            + baseName
            + "\".\"ECRITURE\" "
            + "WHERE (\""
            + baseName
            + "\".\"ECRITURE\".\"ID\" != 1) "
            + "AND ((\""
            + baseName
            + "\".\"ECRITURE\".\"ARCHIVE\" = 0) "
            + "AND (\""
            + baseName
            + "\".\"ECRITURE\".\"ID_JOURNAL\" = "
            + jrnl.getId()
            + ")) "
            + "GROUP BY EXTRACT(YEAR FROM \""
            + baseName
            + "\".\"ECRITURE\".\"DATE\"), "
            + "EXTRACT(MONTH FROM \""
            + baseName
            + "\".\"ECRITURE\".\"DATE\") "
            + "ORDER BY EXTRACT(YEAR FROM \""
            + baseName
            + "\".\"ECRITURE\".\"DATE\"), "
            + "EXTRACT(MONTH FROM \""
            + baseName
            + "\".\"ECRITURE\".\"DATE\")";
    System.out.println(req);

    Object ob = base.getDataSource().execute(req, new ArrayListHandler());

    List myList = (List) ob;

    // System.err.println("TEST DATE " + t);

    if (myList.size() != 0) {

      for (int i = 0; i < myList.size(); i++) {

        Object[] objTmp = (Object[]) myList.get(i);

        Calendar cal = Calendar.getInstance();
        cal.set(Calendar.DATE, 1);
        int month = (new Double(objTmp[1].toString()).intValue() - 1);
        System.err.println(jrnl.getNom() + " SET MONTH " + month);
        cal.set(Calendar.MONTH, month);
        System.err.println(month + " = " + cal.getTime());

        cal.set(Calendar.YEAR, new Double(objTmp[0].toString()).intValue());

        long debitMois = ((Number) objTmp[2]).longValue();
        long creditMois = ((Number) objTmp[3]).longValue();

        c.gridwidth = GridBagConstraints.REMAINDER;
        final JPanel creerJournalMoisPanel =
            creerJournalMoisPanel(cal.getTime(), debitMois, creditMois, jrnl);
        creerJournalMoisPanel.setOpaque(false);
        panelTmp.add(creerJournalMoisPanel, c);

        c.gridy++;

        totalDebitJournal += debitMois;
        totalCreditJournal += creditMois;
      }
    }
    c.gridx = 0;
    c.weighty = 1;
    c.gridwidth = 1;
    final JLabel label = new JLabel("Journal " + jrnl.getNom());
    label.setOpaque(false);
    panelTmp.add(label, c);
    c.gridx = GridBagConstraints.RELATIVE;
    panelTmp.add(
        new JLabel(" Total débit : " + GestionDevise.currencyToString(totalDebitJournal)), c);
    panelTmp.add(
        new JLabel(" Total crédit : " + GestionDevise.currencyToString(totalCreditJournal)), c);

    return panelTmp;
  }
예제 #2
0
  /*
   * Panel du mois d'un journal
   */
  private JPanel creerJournalMoisPanel(
      final Date date, long debit, long credit, final Journal jrnl) {

    final JPanel panelMoisCompte = new JPanel();
    panelMoisCompte.setLayout(new GridBagLayout());
    final GridBagConstraints c = new GridBagConstraints();
    c.insets = new Insets(2, 2, 1, 2);
    c.fill = GridBagConstraints.HORIZONTAL;
    c.anchor = GridBagConstraints.NORTHWEST;
    c.gridx = 0;
    c.gridy = 0;
    c.gridwidth = 1;
    c.gridheight = 1;
    c.weightx = 1;
    c.weighty = 0;

    panelMoisCompte.setBorder(BorderFactory.createTitledBorder(dateFormat.format(date)));

    // Date du mois
    panelMoisCompte.add(new JLabel(dateFormat.format(date)), c);

    // Totaux du mois
    c.gridx++;
    panelMoisCompte.add(new JLabel(" débit : " + GestionDevise.currencyToString(debit)), c);
    c.gridx++;
    panelMoisCompte.add(new JLabel(" crédit : " + GestionDevise.currencyToString(credit)), c);

    // Bouton détails
    JButton boutonShow = new JButton("+/-");
    boutonShow.setOpaque(false);
    boutonShow.setHorizontalAlignment(SwingConstants.LEFT);

    c.weightx = 0;
    c.gridx++;
    panelMoisCompte.add(boutonShow, c);

    boutonShow.addActionListener(
        new ActionListener() {
          private boolean isShow = false;
          private ListPanelEcritures listEcriture;

          public void actionPerformed(ActionEvent e) {

            System.err.println(this.isShow);

            // Afficher la JTable du compte
            if (!this.isShow) {
              final SQLElement element =
                  Configuration.getInstance().getDirectory().getElement("ECRITURE");
              final SQLTable ecrTable = element.getTable();

              Calendar cal = Calendar.getInstance();

              cal.setTime(date);
              cal.set(Calendar.DATE, 1);
              Date inf = cal.getTime();

              cal.set(Calendar.DATE, cal.getActualMaximum(Calendar.DATE));
              Date sup = cal.getTime();

              System.out.println("Inf : " + inf + " Sup : " + sup);
              Where w = new Where(ecrTable.getField("ID_JOURNAL"), "=", jrnl.getId());
              Where w2 = new Where(ecrTable.getField("DATE"), inf, sup);

              if (!UserManager.getInstance()
                  .getCurrentUser()
                  .getRights()
                  .haveRight(ComptaUserRight.ACCES_NOT_RESCTRICTED_TO_411)) {
                // TODO Show Restricted acces in UI
                w = w.and(new Where(ecrTable.getField("COMPTE_NUMERO"), "LIKE", "411%"));
              }

              this.listEcriture = new ListPanelEcritures(element, w.and(w2));
              this.listEcriture.setModificationVisible(false);
              this.listEcriture.setAjoutVisible(false);
              this.listEcriture.setSuppressionVisible(false);
              this.listEcriture.getListe().setSQLEditable(false);

              Dimension d;
              // Taille limitée à 200 maximum
              if (this.listEcriture.getListe().getPreferredSize().height > 200) {
                d = new Dimension(this.listEcriture.getListe().getPreferredSize().width, 200);
              } else {
                d =
                    new Dimension(
                        this.listEcriture.getListe().getPreferredSize().width,
                        this.listEcriture.getListe().getPreferredSize().height + 30);
              }
              this.listEcriture.getListe().setPreferredSize(d);

              // c.gridy = 2;
              c.gridx = 0;
              c.gridy = 1;

              c.gridwidth = 4;
              c.weightx = 1;
              c.weighty = 1;
              c.fill = GridBagConstraints.BOTH;

              this.listEcriture.getListe().setSQLEditable(false);

              panelMoisCompte.add(this.listEcriture, c);
              this.listEcriture
                  .getListe()
                  .getJTable()
                  .addMouseListener(
                      new MouseAdapter() {
                        public void mousePressed(MouseEvent e) {
                          if (e.getButton() == MouseEvent.BUTTON3) {
                            JPopupMenu menu = new JPopupMenu();
                            menu.add(
                                new AbstractAction("Voir la source") {
                                  public void actionPerformed(ActionEvent e) {

                                    SQLRow row =
                                        base.getTable("ECRITURE")
                                            .getRow(listEcriture.getListe().getSelectedId());

                                    MouvementSQLElement.showSource(row.getInt("ID_MOUVEMENT"));
                                  }
                                });

                            menu.show(e.getComponent(), e.getPoint().x, e.getPoint().y);
                          }
                        }
                      });

            } else {

              panelMoisCompte.remove(this.listEcriture);
              System.out.println("Hide ListEcriture");

              panelMoisCompte.repaint();
              panelMoisCompte.revalidate();
            }

            this.isShow = !this.isShow;
            SwingUtilities.getRoot(panelMoisCompte).repaint();
          }
        });

    return panelMoisCompte;
  }
  @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;
  }