Exemple #1
0
  public void run() {

    SQLRow rowPrefCompte = tablePrefCompte.getRow(2);
    this.rowPrefCompteVals.loadAbsolutelyAll(rowPrefCompte);
    // TVA Coll
    int idCompteTVACol = this.rowPrefCompteVals.getInt("ID_COMPTE_PCE_TVA_VENTE");
    if (idCompteTVACol <= 1) {
      String compte;
      try {
        compte = ComptePCESQLElement.getComptePceDefault("TVACollectee");
        idCompteTVACol = ComptePCESQLElement.getId(compte);
      } catch (Exception e) {
        e.printStackTrace();
      }
    }
    SQLRow rowCompteTVACol = tableCompte.getRow(idCompteTVACol);

    // TVA Ded
    int idCompteTVADed = this.rowPrefCompteVals.getInt("ID_COMPTE_PCE_TVA_ACHAT");
    if (idCompteTVADed <= 1) {
      try {
        String compte = ComptePCESQLElement.getComptePceDefault("TVADeductible");
        idCompteTVADed = ComptePCESQLElement.getId(compte);
      } catch (Exception e) {
        e.printStackTrace();
      }
    }
    SQLRow rowCompteTVADed = tableCompte.getRow(idCompteTVADed);

    // TVA intracomm
    int idCompteTVAIntra = this.rowPrefCompteVals.getInt("ID_COMPTE_PCE_TVA_INTRA");
    if (idCompteTVAIntra <= 1) {
      try {
        String compte = ComptePCESQLElement.getComptePceDefault("TVAIntraComm");
        idCompteTVAIntra = ComptePCESQLElement.getId(compte);
      } catch (Exception e) {
        e.printStackTrace();
      }
    }
    SQLRow rowCompteTVAIntra = tableCompte.getRow(idCompteTVAIntra);

    // Achats intracomm
    int idCompteAchatsIntra = this.rowPrefCompteVals.getInt("ID_COMPTE_PCE_ACHAT_INTRA");
    if (idCompteAchatsIntra <= 1) {
      try {
        String compte = ComptePCESQLElement.getComptePceDefault("AchatsIntra");
        idCompteAchatsIntra = ComptePCESQLElement.getId(compte);
      } catch (Exception e) {
        e.printStackTrace();
      }
    }
    SQLRow rowCompteAchatIntra = tableCompte.getRow(idCompteAchatsIntra);

    // TVA immo
    int idCompteTVAImmo = this.rowPrefCompteVals.getInt("ID_COMPTE_PCE_TVA_IMMO");
    if (idCompteTVAImmo <= 1) {
      try {
        String compte = ComptePCESQLElement.getComptePceDefault("TVAImmo");
        idCompteTVAImmo = ComptePCESQLElement.getId(compte);
      } catch (Exception e) {
        e.printStackTrace();
      }
    }
    SQLRow rowCompteTVAImmo = tableCompte.getRow(idCompteTVAImmo);

    PdfGenerator_3310 p = new PdfGenerator_3310();
    this.m = new HashMap<String, Object>();

    long v010 = -this.sommeCompte.soldeCompte(70, 70, true, this.dateDebut, this.dateFin);
    this.m.put("A01", GestionDevise.round(v010));

    // long vA02 = this.sommeCompte.soldeCompte(70, 70, true, this.dateDebut, this.dateFin);
    this.m.put("A02", "");
    long tvaIntra =
        -this.sommeCompte.sommeCompteFils(
            rowCompteTVAIntra.getString("NUMERO"), new Date(100, 0, 1), this.dateFin);
    long achatsIntra =
        this.sommeCompte.sommeCompteFils(
            rowCompteAchatIntra.getString("NUMERO"), this.dateDebut, this.dateFin);
    this.m.put("A03", GestionDevise.round(achatsIntra));
    this.m.put("A04", "");
    this.m.put("A05", "");
    this.m.put("A06", "");
    this.m.put("A07", "");

    long tvaCol =
        -this.sommeCompte.sommeCompteFils(
                rowCompteTVACol.getString("NUMERO"), new Date(100, 0, 1), this.dateFin)
            + tvaIntra;
    this.m.put("B08", GestionDevise.round(tvaCol));
    this.m.put("B08HT", GestionDevise.round(Math.round(tvaCol / 0.196)));
    this.m.put("B09", "");
    this.m.put("B09HT", "");
    this.m.put("B09B", "");
    this.m.put("B09BHT", "");

    this.m.put("B10", "");
    this.m.put("B10HT", "");
    this.m.put("B11", "");
    this.m.put("B11HT", "");
    this.m.put("B12", "");
    this.m.put("B12HT", "");
    this.m.put("B13", "");
    this.m.put("B13HT", "");
    this.m.put("B14", "");
    this.m.put("B14HT", "");

    this.m.put("B15", "");
    this.m.put("B16", GestionDevise.round(tvaCol));
    this.m.put("B17", GestionDevise.round(tvaIntra));
    this.m.put("B18", "");
    long tvaImmo =
        this.sommeCompte.sommeCompteFils(
            rowCompteTVAImmo.getString("NUMERO"), new Date(100, 0, 1), this.dateFin);
    this.m.put("B19", GestionDevise.round(tvaImmo));

    long tvaAutre =
        this.sommeCompte.sommeCompteFils(
            rowCompteTVADed.getString("NUMERO"), new Date(100, 0, 1), this.dateFin);
    this.m.put("B20", GestionDevise.round(tvaAutre));
    this.m.put("B21", "");
    this.m.put("B22", "");
    this.m.put("B23", "");
    long tvaDed = tvaAutre + tvaImmo;
    this.m.put("B24", GestionDevise.round(tvaDed));

    this.m.put("C25", "");
    this.m.put("C26", "");
    this.m.put("C27", "");
    this.m.put("C28", GestionDevise.round(tvaCol - tvaDed));
    this.m.put("C29", "");
    this.m.put("C30", "");
    this.m.put("C31", "");
    this.m.put("C32", GestionDevise.round(tvaCol - tvaDed));

    p.generateFrom(this.m);

    SwingUtilities.invokeLater(
        new Runnable() {
          public void run() {
            Map3310.this.bar.setValue(95);
          }
        });

    SwingUtilities.invokeLater(
        new Runnable() {
          public void run() {

            String file =
                TemplateNXProps.getInstance().getStringProperty("Location3310PDF")
                    + File.separator
                    + String.valueOf(Calendar.getInstance().get(Calendar.YEAR))
                    + File.separator
                    + "result_3310_2.pdf";
            System.err.println(file);
            File f = new File(file);
            Gestion.openPDF(f);
            Map3310.this.bar.setValue(100);
          }
        });
  }
Exemple #2
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;
  }
Exemple #3
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;
  }