Ejemplo n.º 1
0
  private static void updateSaisieVC(String databaseName) {

    System.err.println("Update " + databaseName);
    String select =
        "SELECT MONTANT_TTC, TAUX, ID FROM \""
            + databaseName
            + "\".SAISIE_VENTE_COMPTOIR, \""
            + databaseName
            + "\".TAXE";
    System.err.println("Request " + select);
    List listBaseNX =
        (List)
            Configuration.getInstance()
                .getBase()
                .getDataSource()
                .execute(select, new ArrayListHandler());

    for (int i = 0; i < listBaseNX.size(); i++) {
      Object[] tmp = (Object[]) listBaseNX.get(i);
      PrixTTC p = new PrixTTC(Long.parseLong(tmp[0].toString()));
      long ht = p.calculLongHT(((Float) tmp[1]).doubleValue() / 100.0);

      // Update Value
      String updateVC =
          "UPDATE \""
              + databaseName
              + "\".SAISIE_VENTE_COMPTOIR SET MONTANT_HT = "
              + ht
              + " WHERE ID="
              + tmp[2];
      Configuration.getInstance().getBase().execute(updateVC);
    }
  }
Ejemplo n.º 2
0
  private static void updateMultiBase() {
    // Calcul automatique du ht des saisies de vente avec facture

    System.err.println("Start");
    // on recupere les differentes bases
    ComptaPropsConfiguration instance = ComptaPropsConfiguration.create();
    Configuration.setInstance(instance);
    SQLBase base = Configuration.getInstance().getBase();
    SQLTable tableBase = base.getTable("SOCIETE_COMMON");

    SQLSelect sel = new SQLSelect(base, false);
    sel.addSelect(tableBase.getField("DATABASE_NAME"));

    List listBasesNX =
        (List)
            Configuration.getInstance()
                .getBase()
                .getDataSource()
                .execute(sel.asString(), new ArrayListHandler());

    // for (int i = 0; i < listBasesNX.size(); i++) {
    // Object[] tmp = (Object[]) listBasesNX.get(i);
    //
    // setOrdreComptePCE(tmp[0].toString());
    // }

    reOrderCompteID("Default");
    System.err.println("End");
  }
Ejemplo n.º 3
0
  public static void reOrderCompteID(String databaseName) {
    String select =
        "SELECT ID, ORDRE FROM \"" + databaseName + "\".COMPTE_PCE WHERE ID > 1 ORDER BY NUMERO";

    List listBaseNX =
        (List)
            Configuration.getInstance()
                .getBase()
                .getDataSource()
                .execute(select, new ArrayListHandler());
    for (int i = 0; i < listBaseNX.size(); i++) {
      Object[] tmp = (Object[]) listBaseNX.get(i);
      int id = Integer.valueOf(tmp[0].toString()).intValue();
      String update =
          "UPDATE \"" + databaseName + "\".COMPTE_PCE SET ID=" + (id + 1000) + " WHERE ID=" + id;
      Configuration.getInstance().getBase().execute(update);
    }

    select =
        "SELECT ID, ORDRE FROM \"" + databaseName + "\".COMPTE_PCE WHERE ID > 1 ORDER BY NUMERO";

    listBaseNX =
        (List)
            Configuration.getInstance()
                .getBase()
                .getDataSource()
                .execute(select, new ArrayListHandler());
    for (int i = 0; i < listBaseNX.size(); i++) {
      Object[] tmp = (Object[]) listBaseNX.get(i);
      int id = Integer.valueOf(tmp[0].toString()).intValue();
      String update =
          "UPDATE \"" + databaseName + "\".COMPTE_PCE SET ID=" + (i + 2) + " WHERE ID=" + id;
      Configuration.getInstance().getBase().execute(update);
    }
  }
Ejemplo n.º 4
0
  /**
   * Obtenir la date d'échéance
   *
   * @param aJ
   * @param nJ
   * @param currentDate
   * @return la date d'échéance
   */
  public static final Date calculDate(int aJ, int nJ, Date currentDate) {

    if (aJ == 0 && nJ == 0) {
      return currentDate;
    }
    Calendar cal = Calendar.getInstance();

    ComptaPropsConfiguration conf = (ComptaPropsConfiguration) Configuration.getInstance();

    // on fixe le temps sur ToDay + Ajour
    cal.setTime(currentDate);
    cal.set(Calendar.DATE, cal.get(Calendar.DATE) + aJ);
    if (nJ > 0) {
      int maxDay = cal.getActualMaximum(Calendar.DATE);

      // on fixe le jour nJour de paiement
      if (nJ > maxDay) {
        nJ = maxDay;
      }

      if (nJ < cal.get(Calendar.DAY_OF_MONTH)) {
        cal.add(Calendar.MONTH, 1);
      }

      maxDay = cal.getActualMaximum(Calendar.DATE);

      // on fixe le jour nJour de paiement
      if (nJ > maxDay) {
        nJ = maxDay;
      }

      cal.set(Calendar.DAY_OF_MONTH, nJ);
    }
    return cal.getTime();
  }
Ejemplo n.º 5
0
  public static void setOrdreComptePCE(String databaseName) {
    String select = "SELECT ID, ORDRE FROM \"" + databaseName + "\".COMPTE_PCE ORDER BY NUMERO";
    List listBaseNX =
        (List)
            Configuration.getInstance()
                .getBase()
                .getDataSource()
                .execute(select, new ArrayListHandler());
    for (int i = 0; i < listBaseNX.size(); i++) {
      Object[] tmp = (Object[]) listBaseNX.get(i);

      String update =
          "UPDATE \"" + databaseName + "\".COMPTE_PCE SET ORDRE=" + (i + 1) + " WHERE ID=" + tmp[0];
      Configuration.getInstance().getBase().execute(update);
    }
  }
  public JFrame createFrame() {
    SQLElement element = Configuration.getInstance().getDirectory().getElement("SAISIE_ACHAT");
    ListeGestCommEltPanel panel = new ListeGestCommEltPanel(element);
    panel.setAddVisible(true);
    IListFrame frame = new IListFrame(panel);
    IListTotalPanel total =
        new IListTotalPanel(
            frame.getPanel().getListe(),
            Arrays.asList(
                element.getTable().getField("MONTANT_HT"),
                element.getTable().getField("MONTANT_TTC")));
    GridBagConstraints c = new DefaultGridBagConstraints();
    c.gridy = 3;
    c.weightx = 0;
    c.fill = GridBagConstraints.NONE;
    c.anchor = GridBagConstraints.EAST;
    frame.getPanel().add(total, c);

    // Date panel
    Map<IListe, SQLField> map = new HashMap<IListe, SQLField>();
    map.put(frame.getPanel().getListe(), element.getTable().getField("DATE"));

    IListFilterDatePanel datePanel =
        new IListFilterDatePanel(map, IListFilterDatePanel.getDefaultMap());
    c.gridy = 4;
    c.anchor = GridBagConstraints.CENTER;
    c.weighty = 0;
    datePanel.setFilterOnDefault();
    frame.getPanel().add(datePanel, c);
    return frame;
  }
Ejemplo n.º 7
0
  /**
   * Création d'une société à partir de la base GestionDefault
   *
   * @param baseDefault nom de la base par défaut
   * @param newBase nom de la nouvelle base
   */
  public static void dupliqueDB(String baseDefault, String newBase, StatusListener l) {
    final DBSystemRoot sysRoot = Configuration.getInstance().getSystemRoot();

    // FIXME ADD TRIGGER TO UPDATE SOLDE COMPTE_PCE
    // ComptaPropsConfiguration instance = ComptaPropsConfiguration.create();
    // Configuration.setInstance(instance);

    try {
      log(l, "Création du schéma");
      if (!sysRoot.getRootsToMap().contains(baseDefault)) {
        sysRoot.getRootsToMap().add(baseDefault);
        sysRoot.refetch(Collections.singleton(baseDefault));
      }
      final DBRoot baseSQLDefault = sysRoot.getRoot(baseDefault);
      log(l, "Traitement des " + baseSQLDefault.getChildrenNames().size() + " tables");

      final SQLCreateRoot createRoot =
          baseSQLDefault.getDefinitionSQL(sysRoot.getServer().getSQLSystem());
      final SQLDataSource ds = sysRoot.getDataSource();
      // be safe don't add DROP SCHEMA
      ds.execute(createRoot.asString(newBase, false, true));
      sysRoot.getRootsToMap().add(newBase);
      // TODO find a more functional way
      final boolean origVal = Boolean.getBoolean(SQLSchema.NOAUTO_CREATE_METADATA);
      if (!origVal) System.setProperty(SQLSchema.NOAUTO_CREATE_METADATA, "true");
      sysRoot.refetch(Collections.singleton(newBase));
      if (!origVal) System.setProperty(SQLSchema.NOAUTO_CREATE_METADATA, "false");
      final DBRoot baseSQLNew = sysRoot.getRoot(newBase);

      final Set<SQLTable> newTables = baseSQLNew.getTables();
      int i = 0;
      final SQLSyntax syntax = sysRoot.getServer().getSQLSystem().getSyntax();
      // MAYBE SQLCreateRoot can avoid creating foreign constraints, then we insert data,
      // finally SQLCreateRoot adds just the constraints
      ds.execute(syntax.disableFKChecks(baseSQLNew));
      for (final SQLTable table : newTables) {
        String tableName = table.getName();

        log(l, "Copie de la table " + tableName + " " + (i + 1) + "/" + newTables.size());
        // Dump Table
        dumpTable(baseSQLDefault, table);
        log(l, "Table " + tableName + " " + (i + 1) + "/" + newTables.size() + " OK");
        i++;
      }
      ds.execute(syntax.enableFKChecks(baseSQLNew));

      if (syntax.getSystem() == SQLSystem.POSTGRESQL) {
        log(l, "Maj des séquences des tables");
        new FixSerial(sysRoot).changeAll(baseSQLNew);
      }

      log(l, "Duplication terminée");

    } catch (Throwable e) {
      e.printStackTrace();
      ExceptionHandler.handle("Erreur pendant la création de la base!", e);
      log(l, "Erreur pendant la duplication");
    }
  }
Ejemplo n.º 8
0
  public Map3310(JProgressBar bar, Date dateDeb, Date dateFin) {

    this.bar = bar;

    if (dateDeb == null && dateFin == null) {
      SQLRow rowSociete = ((ComptaPropsConfiguration) Configuration.getInstance()).getRowSociete();
      SQLRow rowExercice =
          Configuration.getInstance()
              .getBase()
              .getTable("EXERCICE_COMMON")
              .getRow(rowSociete.getInt("ID_EXERCICE_COMMON"));
      dateFin = (Date) rowExercice.getObject("DATE_FIN");
      dateDeb = (Date) rowExercice.getObject("DATE_DEB");
    }

    this.dateDebut = dateDeb;
    this.dateFin = dateFin;
    this.sommeCompte = new SommeCompte();
  }
Ejemplo n.º 9
0
  public BalanceAgeePanel() {
    super(new GridBagLayout());

    JLabel label = new JLabel("Balance âgée client pour la période du ");

    SQLRow rowExercice =
        ((ComptaPropsConfiguration) Configuration.getInstance())
            .getRowSociete()
            .getForeignRow("ID_EXERCICE_COMMON");
    Calendar dDebut = rowExercice.getDate("DATE_DEB");
    final JDate dateDeb = new JDate();
    dateDeb.setDate(dDebut.getTime());
    final JDate dateFin = new JDate(true);

    DefaultGridBagConstraints c = new DefaultGridBagConstraints();
    c.gridx = GridBagConstraints.RELATIVE;
    this.add(label, c);
    this.add(dateDeb, c);
    this.add(new JLabel("au"), c);
    this.add(dateFin, c);

    c.gridy++;
    c.gridx = 0;
    c.gridwidth = GridBagConstraints.REMAINDER;
    final JCheckBox boxExcludeEcr = new JCheckBox("Exclure les écritures de clotures");
    boxExcludeEcr.setSelected(true);
    this.add(boxExcludeEcr, c);

    c.gridy++;
    c.gridwidth = GridBagConstraints.REMAINDER;
    c.anchor = GridBagConstraints.EAST;
    c.fill = GridBagConstraints.NONE;
    JButton gen = new JButton("Créer");

    this.add(gen, c);

    gen.addActionListener(
        new ActionListener() {

          @Override
          public void actionPerformed(ActionEvent e) {
            BalanceAgeeListeSheetXML l =
                new BalanceAgeeListeSheetXML(
                    dateDeb.getDate(), dateFin.getDate(), boxExcludeEcr.isSelected());

            try {
              l.createDocument();
              l.openDocument(false);
            } catch (Exception originalExn) {
              ExceptionHandler.handle("Impossible de créer la balance âgée", originalExn);
            }
          }
        });
  }
Ejemplo n.º 10
0
  // Lettre la ligne passée en parametre
  private void actionLettrage(int[] rowIndex) {
    String codeLettre = this.codeLettrage.getText().trim();

    List<SQLRow> rowsSelected = new ArrayList<SQLRow>(rowIndex.length);

    long solde = 0;
    for (int i = 0; i < rowIndex.length; i++) {
      int id = this.ecriturePanel.getListe().idFromIndex(rowIndex[i]);
      SQLRow row = this.tableEcr.getRow(id);
      rowsSelected.add(row);

      solde += ((Long) row.getObject("DEBIT")).longValue();
      solde -= ((Long) row.getObject("CREDIT")).longValue();
    }

    if (solde == 0) {

      for (SQLRow row2 : rowsSelected) {

        SQLRowValues rowVals = new SQLRowValues(this.tableEcr);

        // Lettrage
        // On lettre ou relettre la ligne avec le code saisi
        if (codeLettre.length() > 0) {

          // Si la ligne est en brouillard on valide le mouvement associé
          if (this.boxValidEcriture.isSelected() && (!row2.getBoolean("VALIDE"))) {
            EcritureSQLElement.validationEcritures(row2.getInt("ID_MOUVEMENT"));
          }

          rowVals.put("LETTRAGE", codeLettre);
          rowVals.put("DATE_LETTRAGE", this.dateLettrage.getDate());
          try {
            rowVals.update(row2.getID());
          } catch (SQLException e1) {

            e1.printStackTrace();
          }
        }
      }
      // Mise à jour du code de lettrage
      SQLElement elt = Configuration.getInstance().getDirectory().getElement("NUMEROTATION_AUTO");
      SQLRowValues rowVals = elt.getTable().getRow(2).createEmptyUpdateRow();
      rowVals.put("CODE_LETTRAGE", codeLettre);
      try {
        rowVals.update();
      } catch (SQLException e) {
        e.printStackTrace();
      }
      this.codeLettrage.setText(NumerotationAutoSQLElement.getNextCodeLettrage());

      this.model.updateTotauxCompte();
    }
  }
  public JFrame createFrame() {
    final JFrame frame = new JFrame("Commandes clients");
    // Actions

    frame.getContentPane().add(createAllOrderPanel());
    final SQLElement eltCmd =
        Configuration.getInstance().getDirectory().getElement("COMMANDE_CLIENT");
    FrameUtil.setBounds(frame);
    final File file = IListFrame.getConfigFile(eltCmd, frame.getClass());
    if (file != null) new WindowStateManager(frame, file).loadState();
    return frame;
  }
Ejemplo n.º 12
0
  @Override
  protected SQLRowValues createDefaults() {
    System.err.println("Create defaults");

    setSiteEnabled(false, Type_Diff.DONNEUR_ORDRE);
    setSiteEnabled(false, Type_Diff.SITE);

    // Numero incremental auto
    final SQLRowValues rowVals = new SQLRowValues(getTable());
    rowVals.put("NUMERO", NumerotationAutoSQLElement.getNextNumero(DevisSQLElement.class));

    // User
    // final SQLSelect sel = new SQLSelect(Configuration.getInstance().getBase());
    final SQLElement eltComm = Configuration.getInstance().getDirectory().getElement("COMMERCIAL");
    final int idUser = UserManager.getInstance().getCurrentUser().getId();
    //
    // sel.addSelect(eltComm.getTable().getKey());
    // sel.setWhere(new Where(eltComm.getTable().getField("ID_USER_COMMON"), "=", idUser));
    // final List<SQLRow> rowsComm = (List<SQLRow>)
    // Configuration.getInstance().getBase().getDataSource().execute(sel.asString(), new
    // SQLRowListRSH(eltComm.getTable()));

    SQLRow rowsComm =
        SQLBackgroundTableCache.getInstance()
            .getCacheForTable(eltComm.getTable())
            .getFirstRowContains(idUser, eltComm.getTable().getField("ID_USER_COMMON"));

    if (rowsComm != null) {
      rowVals.put("ID_COMMERCIAL", rowsComm.getID());
    }
    if (getTable().getUndefinedID() == SQLRow.NONEXISTANT_ID) {
      rowVals.put("ID_ETAT_DEVIS", EtatDevisSQLElement.EN_ATTENTE);
    } else {
      SQLRowValues foreign = UndefinedRowValuesCache.getInstance().getDefaultRowValues(getTable());
      if (foreign != null && !foreign.isUndefined()) {
        rowVals.put("ID_ETAT_DEVIS", foreign.getObject("ID_ETAT_DEVIS"));
      } else {
        rowVals.put("ID_ETAT_DEVIS", EtatDevisSQLElement.EN_ATTENTE);
      }
    }
    rowVals.put("T_HT", Long.valueOf(0));
    rowVals.put("T_TVA", Long.valueOf(0));
    rowVals.put("T_SERVICE", Long.valueOf(0));
    rowVals.put("T_TTC", Long.valueOf(0));

    if (getTable().getFieldsName().contains("DATE_VALIDITE")) {
      Calendar cal = Calendar.getInstance();
      cal.add(Calendar.MONTH, 1);
      rowVals.put("DATE_VALIDITE", cal.getTime());
    }
    return rowVals;
  }
Ejemplo n.º 13
0
  /**
   * Création d'un devis à partir d'un devis existant
   *
   * @param idDevis
   */
  public void loadDevisExistant(final int idDevis) {

    final SQLElement devis = Configuration.getInstance().getDirectory().getElement("DEVIS");
    final SQLElement devisElt =
        Configuration.getInstance().getDirectory().getElement("DEVIS_ELEMENT");

    // On duplique le devis
    if (idDevis > 1) {
      final SQLRow row = devis.getTable().getRow(idDevis);
      final SQLRowValues rowVals = new SQLRowValues(devis.getTable());
      rowVals.put("ID_CLIENT", row.getInt("ID_CLIENT"));
      rowVals.put("NUMERO", NumerotationAutoSQLElement.getNextNumero(DevisSQLElement.class));

      this.select(rowVals);
    }

    // On duplique les elements de devis
    final List<SQLRow> myListItem =
        devis.getTable().getRow(idDevis).getReferentRows(devisElt.getTable());

    if (myListItem.size() != 0) {
      this.table.getModel().clearRows();

      for (final SQLRow rowElt : myListItem) {

        final SQLRowValues rowVals = rowElt.createUpdateRow();
        rowVals.clearPrimaryKeys();
        this.table.getModel().addRow(rowVals);
        final int rowIndex = this.table.getModel().getRowCount() - 1;
        this.table.getModel().fireTableModelModified(rowIndex);
      }
    } else {
      this.table.getModel().clearRows();
    }
    this.table.getModel().fireTableDataChanged();
    this.table.repaint();
  }
Ejemplo n.º 14
0
 public NumerotationPreferencePanel() {
   this.setLayout(new GridBagLayout());
   final GridBagConstraints c = new DefaultGridBagConstraints();
   c.weighty = 1;
   c.weightx = 1;
   c.anchor = GridBagConstraints.NORTHWEST;
   this.sc =
       Configuration.getInstance()
           .getDirectory()
           .getElement("NUMEROTATION_AUTO")
           .createComponent();
   sc.setOpaque(false);
   this.sc.uiInit();
   this.sc.select(2);
   this.add(this.sc, c);
 }
Ejemplo n.º 15
0
  @SuppressWarnings("unchecked")
  public static final Map<String, Map<Integer, String>> getMapAllStyle() {
    Map<String, Map<Integer, String>> m = new HashMap<String, Map<Integer, String>>();
    SQLBase base = ((ComptaPropsConfiguration) Configuration.getInstance()).getSQLBaseSociete();
    SQLSelect sel = new SQLSelect(base);
    sel.addSelect(base.getField("STYLE.NOM"));
    String req = sel.asString();
    List<Map<String, Object>> l = base.getDataSource().execute(req);

    for (Map<String, Object> map : l) {

      Object o = map.get("NOM");
      String s = (o == null) ? null : o.toString();
      m.put(s, null);
    }
    m.put("BlankStyle", null);
    return m;
  }
  private int[] getMouvement(int idPiece) {

    int[] idS = null;

    SQLBase b = ((ComptaPropsConfiguration) Configuration.getInstance()).getSQLBaseSociete();
    SQLTable tableMvt = b.getTable("MOUVEMENT");

    SQLSelect sel = new SQLSelect(b);
    sel.addSelect(tableMvt.getField("NUMERO"));
    sel.setWhere(tableMvt.getField("ID_PIECE"), "=", idPiece);

    List l = (List) b.getDataSource().execute(sel.asString(), new ArrayListHandler());

    if (l.size() > 0) {
      idS = new int[l.size()];
    }

    for (int i = 0; i < l.size(); i++) {
      Object[] tmp = (Object[]) l.get(i);
      idS[i] = Integer.parseInt(tmp[0].toString());
    }

    return idS;
  }
Ejemplo n.º 17
0
  public ExportPanel() {
    super(new GridBagLayout());
    final GridBagConstraints c = new DefaultGridBagConstraints();

    c.gridwidth = 4;
    this.add(new JLabelBold("Export des écritures comptables"), c);

    // Fichier de destination
    final JPanel panelFichier = new JPanel(new GridBagLayout());
    final GridBagConstraints cFic = new DefaultGridBagConstraints();
    cFic.insets.left = 0;
    cFic.insets.bottom = 0;
    cFic.gridx++;
    cFic.weightx = 1;
    panelFichier.add(this.textDestination, cFic);

    final JButton buttonChoose = new JButton("...");
    cFic.gridx++;
    cFic.weightx = 0;
    cFic.fill = GridBagConstraints.NONE;
    panelFichier.add(buttonChoose, cFic);

    this.buttonGen.setEnabled(false);
    this.textDestination.setEditable(false);

    this.fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    buttonChoose.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(final ActionEvent e) {
            final int answer = ExportPanel.this.fileChooser.showSaveDialog(ExportPanel.this);
            if (answer == JFileChooser.APPROVE_OPTION) {
              ExportPanel.this.textDestination.setText(
                  ExportPanel.this.fileChooser.getSelectedFile().getAbsolutePath());
            }
            ExportPanel.this.buttonGen.setEnabled(answer == JFileChooser.APPROVE_OPTION);
          }
        });
    c.gridy++;
    c.gridx = 0;
    c.gridwidth = 1;
    this.add(new JLabel("Dossier de destination", SwingUtilities.RIGHT), c);
    c.gridx++;
    c.weightx = 1;
    c.gridwidth = 4;
    this.add(panelFichier, c);

    c.gridx = 0;
    c.gridwidth = 1;
    c.gridy++;
    c.weightx = 0;
    c.anchor = GridBagConstraints.EAST;
    this.add(new JLabel("Période du", SwingUtilities.RIGHT), c);

    c.gridx++;
    c.anchor = GridBagConstraints.WEST;
    c.fill = GridBagConstraints.NONE;
    this.du = new JDate(true);
    this.add(this.du, c);

    c.gridx++;
    this.add(new JLabel("au"), c);

    c.gridx++;
    this.au = new JDate(true);
    this.add(this.au, c);

    this.boxExport.setSelected(true);
    c.gridy++;
    c.gridx = 0;
    c.gridwidth = 3;
    this.add(this.boxExport, c);

    final SQLElement elt =
        Configuration.getInstance().getDirectory().getElement(JournalSQLElement.class);
    final ComboSQLRequest comboRequest = elt.getComboRequest(true);
    comboRequest.setUndefLabel("Tous");
    this.boxJournal.init(elt, comboRequest);
    c.gridy++;
    c.gridx = 0;
    c.weightx = 0;
    c.gridwidth = 1;
    c.fill = GridBagConstraints.HORIZONTAL;
    this.add(new JLabel("Ecritures du journal", SwingUtilities.RIGHT), c);
    c.gridx++;
    c.weightx = 1;
    c.gridwidth = 4;
    c.fill = GridBagConstraints.NONE;
    this.boxJournal.setValue(JournalSQLElement.VENTES);
    this.add(this.boxJournal, c);

    c.gridy++;
    c.gridx = 0;
    c.weightx = 0;
    c.gridwidth = 1;
    c.fill = GridBagConstraints.HORIZONTAL;
    this.add(new JLabel("Type d'export", SwingUtilities.RIGHT), c);
    c.gridx++;
    c.weightx = 1;
    c.gridwidth = 4;
    final JComboBox comboType = new JComboBox(ExportType.values());
    comboType.setRenderer(
        new DefaultListCellRenderer() {
          @Override
          public Component getListCellRendererComponent(
              JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
            return super.getListCellRendererComponent(
                list, ((ExportType) value).getLabel(), index, isSelected, cellHasFocus);
          }
        });
    c.fill = GridBagConstraints.NONE;
    comboType.setSelectedIndex(0);
    this.add(comboType, c);

    final JPanel p = new JPanel(new GridBagLayout());
    GridBagConstraints c2 = new DefaultGridBagConstraints();
    c2.gridx = 0;
    c2.weightx = 1;
    c2.gridwidth = GridBagConstraints.REMAINDER;
    c2.fill = GridBagConstraints.HORIZONTAL;
    p.add(new TitledSeparator("Option export relation expert", true), c2);

    c2.gridy++;
    c2.gridx = 0;
    c2.weightx = 0;
    c2.gridwidth = 3;
    c2.fill = GridBagConstraints.HORIZONTAL;
    p.add(
        new JLabel(
            "Formater les numéros de compte suivant le nombre de caractères suivants",
            SwingUtilities.RIGHT),
        c2);
    c2.gridx += 3;
    c2.weightx = 1;
    c2.gridwidth = 1;

    p.add(this.spinNbChar, c2);

    c2.gridy++;
    c2.gridx = 0;
    c2.weightx = 0;
    c2.gridwidth = 3;
    c2.fill = GridBagConstraints.HORIZONTAL;
    p.add(
        new JLabel("Limiter le nombre de caractéres des numéros compte à", SwingUtilities.RIGHT),
        c2);
    c2.gridx += 3;
    c2.weightx = 1;
    c2.gridwidth = 1;
    p.add(this.spinNbCharLimit, c2);

    c.gridy++;
    c.gridx = 0;
    c.weightx = 1;
    c.weighty = 1;
    c.gridwidth = GridBagConstraints.REMAINDER;
    c.fill = GridBagConstraints.HORIZONTAL;
    this.add(p, c);

    c.gridy++;
    c.weightx = 1;
    c.gridx = 0;
    c.gridwidth = 1;
    final JPanel panelButton = new JPanel();
    panelButton.add(this.buttonGen);
    c.gridwidth = GridBagConstraints.REMAINDER;
    c.fill = GridBagConstraints.NONE;
    c.anchor = GridBagConstraints.SOUTHEAST;
    c.weightx = 0;
    c.weighty = 1;
    this.add(panelButton, c);
    this.buttonGen.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            export((ExportType) comboType.getSelectedItem());
          }
        });
    p.setVisible(false);
    comboType.addActionListener(
        new ActionListener() {

          @Override
          public void actionPerformed(ActionEvent e) {
            p.setVisible((ExportType) comboType.getSelectedItem() == ExportType.RelationExpert);
          }
        });
  }
 @Override
 public JFrame createFrame() {
   return new EditFrame(Configuration.getInstance().getDirectory().getElement("COMMANDE_CLIENT"));
 }
Ejemplo n.º 19
0
 public ListPanelEcheancesClients() {
   this(Configuration.getInstance().getDirectory().getElement("ECHEANCE_CLIENT"));
 }
Ejemplo n.º 20
0
public class PointageModel extends AbstractTableModel {

  private String[] titresCol;
  private String[] titresRow;

  private long debitPointe,
      creditPointe,
      debitNonPointe,
      creditNonPointe,
      creditSelection,
      debitSelection;

  private static final SQLBase base =
      ((ComptaPropsConfiguration) Configuration.getInstance()).getSQLBaseSociete();
  private static final SQLTable tableEcr = base.getTable("ECRITURE");
  int idCpt;

  public PointageModel(int idCpt) {

    this.creditNonPointe = 0;
    this.creditPointe = 0;
    this.creditSelection = 0;

    this.debitNonPointe = 0;
    this.debitPointe = 0;
    this.debitSelection = 0;

    this.idCpt = idCpt;
    this.titresCol = new String[6];
    this.titresCol[0] = "Totaux";
    this.titresCol[1] = "Pointé";
    this.titresCol[2] = "Non Pointé";
    this.titresCol[3] = "Total";

    this.titresCol[4] = "Sélection";
    this.titresCol[5] = "Pointéé + sélection";

    this.titresRow = new String[3];
    this.titresRow[0] = "Débit";
    this.titresRow[1] = "Crédit";
    this.titresRow[2] = "Solde";

    updateTotauxCompte();
  }

  public void setIdCompte(int id) {
    this.idCpt = id;
    updateTotauxCompte();
    updateSelection(null);
  }

  public void updateSelection(int[] rowIndex) {
    System.err.println("Update Selection");
    this.creditSelection = 0;
    this.debitSelection = 0;

    if (rowIndex != null) {
      for (int i = 0; i < rowIndex.length; i++) {

        SQLRow row = tableEcr.getRow(rowIndex[i]);

        if (row != null) {

          // if (row.getString("POINTEE").trim().length() == 0) {
          this.debitSelection += ((Long) row.getObject("DEBIT")).longValue();
          this.creditSelection += ((Long) row.getObject("CREDIT")).longValue();
          // }
          /*
           * else {
           *
           * this.debitSelection -= row.getFloat("DEBIT"); this.creditSelection -=
           * row.getFloat("CREDIT"); }
           */
        }
      }
    }
    this.fireTableDataChanged();
  }

  public void updateTotauxCompte() {

    new SwingWorker<String, Object>() {

      @Override
      protected String doInBackground() throws Exception {

        SQLSelect sel = new SQLSelect(base);
        sel.addSelect(tableEcr.getField("CREDIT"), "SUM");
        sel.addSelect(tableEcr.getField("DEBIT"), "SUM");

        Where w = new Where(tableEcr.getField("ID_COMPTE_PCE"), "=", PointageModel.this.idCpt);
        sel.setWhere(w.and(new Where(tableEcr.getField("POINTEE"), "!=", "")));

        String reqPointee = sel.toString();

        Object obPointee = base.getDataSource().execute(reqPointee, new ArrayListHandler());

        List myListPointee = (List) obPointee;

        PointageModel.this.creditPointe = 0;
        PointageModel.this.debitPointe = 0;
        if (myListPointee.size() != 0) {

          for (int i = 0; i < myListPointee.size(); i++) {
            Object[] objTmp = (Object[]) myListPointee.get(i);

            if (objTmp[0] != null) {
              PointageModel.this.creditPointe += ((Number) objTmp[0]).longValue();
            }
            if (objTmp[1] != null) {
              PointageModel.this.debitPointe += ((Number) objTmp[1]).longValue();
            }
          }
        }

        sel.setWhere(w.and(new Where(tableEcr.getField("POINTEE"), "=", "")));
        String reqNotPointee = sel.toString();

        Object obNotPointee = base.getDataSource().execute(reqNotPointee, new ArrayListHandler());

        List myListNotPointee = (List) obNotPointee;

        PointageModel.this.creditNonPointe = 0;
        PointageModel.this.debitNonPointe = 0;
        if (myListNotPointee.size() != 0) {

          for (int i = 0; i < myListNotPointee.size(); i++) {
            Object[] objTmp = (Object[]) myListNotPointee.get(i);

            if (objTmp[0] != null) {
              PointageModel.this.creditNonPointe += ((Number) objTmp[0]).longValue();
            }

            if (objTmp[1] != null) {
              PointageModel.this.debitNonPointe += ((Number) objTmp[1]).longValue();
            }
          }
        }

        return null;
      }

      @Override
      protected void done() {

        PointageModel.this.fireTableDataChanged();
      }
    }.execute();
  }

  public String getColumnName(int column) {

    return this.titresCol[column];
  }

  public int getColumnCount() {

    return this.titresCol.length;
  }

  public int getRowCount() {

    return this.titresRow.length;
  }

  @Override
  public Class<?> getColumnClass(int columnIndex) {
    if (columnIndex == 0) {
      return String.class;
    } else {
      return Long.class;
    }
  }

  public Object getValueAt(int rowIndex, int columnIndex) {

    if (columnIndex == 0) {
      return this.titresRow[rowIndex];
    }

    if (columnIndex == 1) {
      if (rowIndex == 0) {
        return new Long(this.debitPointe);
      }
      if (rowIndex == 1) {
        return new Long(this.creditPointe);
      }
      if (rowIndex == 2) {
        return new Long(this.debitPointe - this.creditPointe);
      }
    }

    if (columnIndex == 2) {
      if (rowIndex == 0) {
        return new Long(this.debitNonPointe);
      }
      if (rowIndex == 1) {
        return new Long(this.creditNonPointe);
      }
      if (rowIndex == 2) {
        return new Long(this.debitNonPointe - this.creditNonPointe);
      }
    }

    if (columnIndex == 3) {
      if (rowIndex == 0) {
        return new Long(this.debitNonPointe + this.debitPointe);
      }
      if (rowIndex == 1) {
        return new Long(this.creditNonPointe + this.creditPointe);
      }
      if (rowIndex == 2) {
        return new Long(
            (this.debitNonPointe - this.creditNonPointe) + (this.debitPointe - this.creditPointe));
      }
    }

    if (columnIndex == 4) {
      if (rowIndex == 0) {
        return new Long(this.debitSelection);
      }
      if (rowIndex == 1) {
        return new Long(this.creditSelection);
      }
      if (rowIndex == 2) {
        return new Long(this.debitSelection - this.creditSelection);
      }
    }

    if (columnIndex == 5) {
      if (rowIndex == 0) {
        return new Long(this.debitSelection + this.debitPointe);
      }
      if (rowIndex == 1) {
        return new Long(this.creditSelection + this.creditPointe);
      }
      if (rowIndex == 2) {
        return new Long(
            this.debitSelection - this.creditSelection + this.debitPointe - this.creditPointe);
      }
    }

    return null;
  }
}
Ejemplo n.º 21
0
  public static ComptaTipsFrame getFrame(boolean checked) {

    if (f != null) {
      return f;
    } else {
      f = new ComptaTipsFrame(checked);

      Tip t1 = new Tip();
      t1.addText("Les fonctions de gestion courante se trouvent dans le menu 'Saisie'.");
      t1.addText("  ");
      t1.addText("Vous y trouverez les interfaces de création :");
      t1.addText("- des devis et factures");
      t1.addText("- des achats, livraisons et mouvements stocks");
      t1.addText("- des commandes et bons de réception");
      t1.addText("  ");
      t1.addImage(ComptaTipsFrame.class.getResource("tips_gnx.png"));

      f.addTip(t1);

      Tip t2 = new Tip();
      t2.addText("Le logiciel intègre un module de cartographie.");
      t2.addText("  ");
      t2.addImage(ComptaTipsFrame.class.getResource("tips_map.png"));
      f.addTip(t2);

      Tip t3 = new Tip();
      t3.addText(
          Configuration.getInstance().getAppName() + " fonctionne sous Windows 7, Vista et XP");
      t3.addText("et aussi sous Linux et MacOS...");
      t3.addText("  ");
      t3.addImage(ComptaTipsFrame.class.getResource("tips_os.png"));
      f.addTip(t3);

      Tip t4 = new Tip();
      t4.addText("Les sélecteurs intègrent l'auto-complétion.");
      t4.addText(" ");
      t4.addText("Vous commencez à écrire, le logiciel suggère les possibilités!");
      t4.addText(" ");
      t4.addImage(ComptaTipsFrame.class.getResource("tips_auto.png"));
      f.addTip(t4);

      Tip t5 = new Tip();
      t5.addText("Un clic droit sur une ligne...");
      t5.addText("et les fonctionnalités contextuelles apparaissent.");
      t5.addImage(ComptaTipsFrame.class.getResource("tips_click.png"));
      f.addTip(t5);

      Tip t6 = new Tip();
      t6.addText("Le logiciel peut mémoriser des valeurs (textes).");
      t6.addText(" ");
      t6.addText(
          "Un clic droit sur les sélecteurs vous permet d'ajouter et de supprimer des éléments.");
      t6.addText(" ");
      t6.addImage(ComptaTipsFrame.class.getResource("tips_combo.png"));
      f.addTip(t6);

      Tip t7 = new Tip();
      t7.addText("Les listes possèdent une recherche intégrée.");

      t7.addText("Les résutats sont visibles en temps réel.");
      t7.addText(" ");

      t7.addImage(ComptaTipsFrame.class.getResource("tips_search.png"));
      t7.addText(" ");
      t7.addText("Dans cet exemple, nous avons immédiatement les éléments relatifs");
      t7.addText("à M. Blanc en 2010 !");
      f.addTip(t7);

      Tip t8 = new Tip();
      t8.addText("Tous les documents créés par le logiciel sont standards.");
      t8.addText("");
      t8.addText("Nous utilisons pour cela : ");
      t8.addText("- format PDF  ");
      t8.addText("- format OpenDocument utilisable avec OpenOffice");
      t8.addText(" ");
      t8.addImage(ComptaTipsFrame.class.getResource("tips_oo.png"));
      f.addTip(t8);

      Tip t9 = new Tip();
      t9.addText("Vous pouvez envoyer directement les documents par email.");
      t9.addText(" ");
      t9.addText("Le logiciel est compatible avec :");
      t9.addText("- Outlook, Outlook Express et Mail");
      t9.addText("- Thunderbird ");
      t9.addText(" ");
      t9.addImage(ComptaTipsFrame.class.getResource("tips_firefox.png"));
      f.addTip(t9);

      Tip t10 = new Tip();
      t10.addText("Le logiciel est basé sur la technologie SQL.");
      t10.addText(" ");
      t10.addText("Le logiciel fonctionne avec les bases de données :");
      t10.addText("- postgreSQL");
      t10.addText("- MySQL ");
      t10.addText("- H2 ");
      t10.addText(" ");
      t10.addImage(ComptaTipsFrame.class.getResource("tips_db.png"));
      f.addTip(t10);

      Tip t11 = new Tip();
      t11.addText("Le logiciel bloque les saisies incorrectes.");
      t11.addText(" ");
      t11.addText("Si le bouton ajouter reste grisé, un clic affiche la cause.");
      t11.addText(" ");
      t11.addImage(ComptaTipsFrame.class.getResource("tips_add.png"));
      f.addTip(t11);
      f.setCurrentTip(0);
      f.setAlwaysOnTop(true);
      f.setLocationRelativeTo(null);
      f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
      return f;
    }
  }
Ejemplo n.º 22
0
public class Map3310 extends Thread {

  private Map<String, Object> m;
  private static final DateFormat format = new SimpleDateFormat("ddMMyyyy");
  private JProgressBar bar;
  private Date dateDebut, dateFin;

  private static final SQLBase base =
      ((ComptaPropsConfiguration) Configuration.getInstance()).getSQLBaseSociete();
  private static final SQLTable tablePrefCompte = base.getTable("PREFS_COMPTE");
  private static final SQLTable tableCompte =
      Configuration.getInstance().getRoot().findTable("COMPTE_PCE");
  private SQLRowValues rowPrefCompteVals = new SQLRowValues(tablePrefCompte);
  SommeCompte sommeCompte;

  private static String getVille(final String name) {

    Ville ville = Ville.getVilleFromVilleEtCode(name);
    if (ville == null) {
      SwingUtilities.invokeLater(
          new Runnable() {
            public void run() {
              JOptionPane.showMessageDialog(
                  null,
                  "La ville "
                      + "\""
                      + name
                      + "\""
                      + " est introuvable! Veuillez corriger l'erreur!");
            }
          });
      return null;
    }
    return ville.getName();
  }

  private static String getVilleCP(String name) {
    Ville ville = Ville.getVilleFromVilleEtCode(name);
    if (ville == null) {

      return null;
    }
    return ville.getCodepostal();
  }

  // TODO if value = 0.0 ne pas mettre -0.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);
          }
        });
  }

  public Map3310(JProgressBar bar, Date dateDeb, Date dateFin) {

    this.bar = bar;

    if (dateDeb == null && dateFin == null) {
      SQLRow rowSociete = ((ComptaPropsConfiguration) Configuration.getInstance()).getRowSociete();
      SQLRow rowExercice =
          Configuration.getInstance()
              .getBase()
              .getTable("EXERCICE_COMMON")
              .getRow(rowSociete.getInt("ID_EXERCICE_COMMON"));
      dateFin = (Date) rowExercice.getObject("DATE_FIN");
      dateDeb = (Date) rowExercice.getObject("DATE_DEB");
    }

    this.dateDebut = dateDeb;
    this.dateFin = dateFin;
    this.sommeCompte = new SommeCompte();
  }

  public Map3310(JProgressBar bar) {

    this(bar, null, null);
  }

  public void generateMap2033A() {
    this.start();
  }
}
Ejemplo n.º 23
0
  public static void fixUserCommon(int base) {

    if (Configuration.getInstance() == null) {
      Configuration.setInstance(ComptaPropsConfiguration.create());
    }
    Configuration instance = Configuration.getInstance();
    SQLTable tableSociete = Configuration.getInstance().getBase().getTable("SOCIETE_COMMON");

    String baseName = tableSociete.getRow(base).getString("DATABASE_NAME");

    instance.getBase().getDBSystemRoot().getRootsToMap().clear();
    try {
      Set<String> s = new HashSet<String>();
      s.add(baseName);
      instance.getBase().fetchTables(s);
    } catch (SQLException e) {
      throw new IllegalStateException("could not access societe base", e);
    }

    System.err.println("baseName" + baseName);
    instance.getSystemRoot().prependToRootPath("Common");
    instance.getSystemRoot().prependToRootPath(baseName);

    SQLSchema baseSQL = instance.getBase().getSchema(baseName);

    DatabaseMetaData dbMetaDataSociete;
    try {
      dbMetaDataSociete = baseSQL.getBase().getDataSource().getConnection().getMetaData();

      String[] type = new String[1];
      type[0] = "TABLE";
      ResultSet rs = dbMetaDataSociete.getTables("", baseSQL.getName(), "%", null);

      System.err.println("Start " + rs.getFetchSize());
      int i = 0;
      while (rs.next()) {

        if (rs.getString("TABLE_TYPE") != null
            && rs.getString("TABLE_TYPE").equalsIgnoreCase("TABLE")) {
          // System.err.println("FIND TABLE");
          // baseSQL.getTableNames();
          final SQLTable table = baseSQL.getTable(rs.getString("TABLE_NAME"));
          Set<SQLField> s = table.getFields();
          for (SQLField field : s) {
            if (field.getName().equalsIgnoreCase("ID_USER_COMMON_CREATE")
                || field.getName().equalsIgnoreCase("ID_USER_COMMON_MODIFY")) {
              Object o = field.getDefaultValue();
              if (o == null || (o instanceof Integer && ((Integer) o) == 0)) {

                System.err.println("Bad default on " + field);
                baseSQL
                    .getBase()
                    .execute(
                        "ALTER TABLE \""
                            + field.getTable().getSchema().getName()
                            + "\".\""
                            + field.getTable().getName()
                            + "\" ALTER COLUMN \""
                            + field.getName()
                            + "\" SET DEFAULT 1;");

                baseSQL
                    .getBase()
                    .execute(
                        "UPDATE \""
                            + field.getTable().getSchema().getName()
                            + "\".\""
                            + field.getTable().getName()
                            + "\" SET \""
                            + field.getName()
                            + "\"=1 WHERE \""
                            + field.getName()
                            + "\"=0 OR \""
                            + field.getName()
                            + "\" IS NULL;");
              }
            }
          }
        }
        // System.err.println(i++ + " " + rs.getString("TABLE_TYPE"));
      }
      rs.close();
    } catch (SQLException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
  }
Ejemplo n.º 24
0
public class LettragePanel extends JPanel {

  private ListPanelEcritures ecriturePanel;
  private JTextField codeLettrage;
  private ISQLCompteSelector selCompte;
  private JCheckBox boxValidEcriture, boxAddSousCompte;
  private JPanel warningPanel, warningSolde;

  private final SQLBase base =
      ((ComptaPropsConfiguration) Configuration.getInstance()).getSQLBaseSociete();
  private final SQLTable tableEcr = this.base.getTable("ECRITURE");
  private final SQLTable tableComptePCE = this.base.getTable("COMPTE_PCE");

  private static final int allEcriture = 0;
  private static final int ecritureLettree = 1;
  private static final int ecritureNonLettree = 2;

  private int modeSelect;
  private LettrageModel model;
  private JButton buttonLettrer;
  private JDate dateDeb, dateFin, dateLettrage;

  public LettragePanel() {
    this.setLayout(new GridBagLayout());
    GridBagConstraints c = new DefaultGridBagConstraints();

    this.modeSelect = allEcriture;

    // Selection du compte à lettrer
    JLabel labelPointageCompte = new JLabel("Lettrage du compte");
    labelPointageCompte.setHorizontalAlignment(SwingConstants.RIGHT);

    this.add(labelPointageCompte, c);
    this.selCompte = new ISQLCompteSelector();
    this.selCompte.init();
    this.selCompte.setValue(ComptePCESQLElement.getId("5"));

    c.gridx++;
    c.weightx = 1;
    c.gridwidth = GridBagConstraints.REMAINDER;
    this.add(this.selCompte, c);

    c.gridwidth = 1;

    // Gestion du lettrage
    c.insets = new Insets(2, 2, 1, 2);
    TitledSeparator sepGestionLettrage = new TitledSeparator("Gestion du lettrage");
    c.fill = GridBagConstraints.HORIZONTAL;
    c.gridy++;
    c.gridx = 0;
    c.gridwidth = GridBagConstraints.REMAINDER;
    this.add(sepGestionLettrage, c);

    // Code de lettrage
    JLabel labelCode = new JLabel("Code lettrage");
    labelCode.setHorizontalAlignment(SwingConstants.RIGHT);
    c.gridx = 0;
    c.gridy++;
    c.gridwidth = 1;
    c.weightx = 0;
    this.add(labelCode, c);

    this.codeLettrage = new JTextField(10);
    DocumentFilterList.add(
        (AbstractDocument) this.codeLettrage.getDocument(),
        new UpperCaseFormatFilter(),
        FilterType.SIMPLE_FILTER);
    c.gridx++;
    c.weightx = 1;
    this.add(this.codeLettrage, c);
    this.codeLettrage.setText(NumerotationAutoSQLElement.getNextCodeLettrage());

    // Warning si aucun code rentré
    createPanelWarning();
    c.gridwidth = GridBagConstraints.REMAINDER;
    c.weightx = 0;
    c.gridx++;
    this.add(this.warningPanel, c);

    // Date de lettrage
    JLabel labelDate = new JLabel("Date");
    labelDate.setHorizontalAlignment(SwingConstants.RIGHT);
    c.gridx = 0;
    c.gridy++;
    c.weightx = 0;
    c.gridwidth = 1;
    this.add(labelDate, c);
    this.dateLettrage = new JDate(true);
    c.gridx++;
    this.add(this.dateLettrage, c);

    // Warning si solde non nul
    c.gridx++;
    createPanelWarningSolde();
    c.gridwidth = GridBagConstraints.REMAINDER;
    c.weightx = 0;
    this.add(this.warningSolde, c);

    c.gridwidth = 1;

    TitledSeparator sepPeriode = new TitledSeparator("Filtre ");
    c.gridy++;
    c.gridx = 0;
    c.anchor = GridBagConstraints.WEST;
    c.gridwidth = GridBagConstraints.REMAINDER;
    c.fill = GridBagConstraints.HORIZONTAL;
    this.add(sepPeriode, c);

    JPanel panelSelectEcritures = createPanelSelectionEcritures();
    c.gridy++;
    c.gridx = 0;
    c.gridwidth = 1;
    c.weightx = 0;

    JLabel labelEcr = new JLabel("Ecritures");
    labelEcr.setHorizontalAlignment(SwingConstants.RIGHT);
    this.add(labelEcr, c);
    c.gridx++;
    c.weightx = 1;
    c.gridwidth = GridBagConstraints.REMAINDER;
    c.fill = GridBagConstraints.NONE;
    this.add(panelSelectEcritures, c);

    JPanel panelPeriode = new JPanel();
    // Date de début
    this.dateDeb = new JDate();
    c.gridy++;
    c.gridx = 0;
    c.gridwidth = 1;
    c.weightx = 0;
    JLabel labelPerio = new JLabel("Période du ");
    labelPerio.setHorizontalAlignment(SwingConstants.RIGHT);
    c.fill = GridBagConstraints.HORIZONTAL;
    this.add(labelPerio, c);

    panelPeriode.add(this.dateDeb);
    this.dateDeb.addValueListener(
        new PropertyChangeListener() {
          public void propertyChange(PropertyChangeEvent evt) {
            changeListRequest();
          }
        });

    // Date de fin
    this.dateFin = new JDate(true);
    panelPeriode.add(new JLabel("au"));
    this.dateFin.addValueListener(
        new PropertyChangeListener() {
          public void propertyChange(PropertyChangeEvent evt) {
            changeListRequest();
          }
        });

    panelPeriode.add(this.dateFin);
    c.gridx++;
    c.gridwidth = GridBagConstraints.REMAINDER;
    c.weightx = 1;
    c.fill = GridBagConstraints.NONE;
    this.add(panelPeriode, c);

    c.gridx = 0;
    c.gridy++;
    this.boxAddSousCompte = new JCheckBox("Ajouter les sous comptes");
    this.boxAddSousCompte.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            // TODO Auto-generated method stub
            changeListRequest();
          }
        });

    this.add(this.boxAddSousCompte, c);

    TitledSeparator sepEcriture = new TitledSeparator("Ecritures ");
    c.gridy++;
    c.gridx = 0;
    c.weightx = 1;
    c.gridwidth = GridBagConstraints.REMAINDER;
    c.fill = GridBagConstraints.HORIZONTAL;
    this.add(sepEcriture, c);

    // Liste des ecritures
    final EcritureSQLElement ecritureElem =
        Configuration.getInstance().getDirectory().getElement(EcritureSQLElement.class);
    this.ecriturePanel =
        new ListPanelEcritures(ecritureElem, new IListe(ecritureElem.createLettrageTableSource()));
    c.gridx = 0;
    c.gridy++;
    c.weighty = 1;
    c.weightx = 1;
    c.fill = GridBagConstraints.BOTH;
    c.gridwidth = GridBagConstraints.REMAINDER;
    this.ecriturePanel
        .getListe()
        .setPreferredSize(
            new Dimension(this.ecriturePanel.getListe().getPreferredSize().width, 200));
    this.add(this.ecriturePanel, c);

    // JTable Totaux
    c.gridy++;
    c.gridx = 0;
    c.weighty = 0;
    c.weightx = 1;
    c.fill = GridBagConstraints.BOTH;
    c.gridwidth = 3;
    c.gridheight = 3;
    this.model = new LettrageModel(this.selCompte.getSelectedId());
    JTable table = new JTable(this.model);

    // AlternateTableCellRenderer.setAllColumns(table);
    for (int i = 0; i < table.getColumnCount(); i++) {
      // if (table.getColumnClass(i) == Long.class || table.getColumnClass(i) ==
      // BigInteger.class) {
      table.getColumnModel().getColumn(i).setCellRenderer(new DeviseNiceTableCellRenderer());
      // }
    }
    JScrollPane sPane = new JScrollPane(table);

    // TODO Gerer la taille des colonnes
    Dimension d =
        new Dimension(
            table.getPreferredSize().width,
            table.getPreferredSize().height + table.getTableHeader().getPreferredSize().height + 4);
    sPane.setPreferredSize(d);
    this.add(sPane, c);

    // Legende
    c.gridx = 4;
    c.gridwidth = 1;
    c.anchor = GridBagConstraints.EAST;
    c.fill = GridBagConstraints.NONE;
    c.weightx = 0;
    this.add(createPanelLegende(), c);

    c.gridheight = 1;
    final JButton buttonDelettrer = new JButton("Délettrer");
    this.buttonLettrer = new JButton("Lettrer");
    // Validation des ecritures pointées
    this.boxValidEcriture = new JCheckBox("Valider les écritures lettrées");
    c.gridx++;
    c.gridwidth = GridBagConstraints.REMAINDER;
    this.add(this.boxValidEcriture, c);

    JPanel panelButton = new JPanel();

    // Boutton lettrer

    panelButton.add(this.buttonLettrer, c);

    // Boutton Delettrer

    panelButton.add(buttonDelettrer, c);

    c.gridy++;
    c.gridx = 5;
    c.gridwidth = GridBagConstraints.REMAINDER;
    c.gridheight = 1;
    c.weightx = 1;
    c.fill = GridBagConstraints.NONE;
    c.anchor = GridBagConstraints.EAST;
    this.add(panelButton, c);

    c.gridy++;
    c.anchor = GridBagConstraints.SOUTHEAST;
    JButton buttonClose = new JButton("Fermer");
    buttonClose.addActionListener(
        new ActionListener() {

          @Override
          public void actionPerformed(ActionEvent e) {
            ((Window) SwingUtilities.getRoot((Component) e.getSource())).dispose();
          }
        });
    this.add(buttonClose, c);
    this.buttonLettrer.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {

            int[] rowIndex =
                LettragePanel.this.ecriturePanel.getListe().getJTable().getSelectedRows();

            // System.err.println("Action lettrage sur " + i);
            actionLettrage(rowIndex);
          }
        });

    buttonDelettrer.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {

            int[] rowIndex =
                LettragePanel.this.ecriturePanel.getListe().getJTable().getSelectedRows();
            actionDelettrage(rowIndex);
          }
        });

    // Changement de compte
    this.selCompte.addValueListener(
        new PropertyChangeListener() {
          public void propertyChange(PropertyChangeEvent evt) {

            changeListRequest();
          };
        });

    // Action Souris sur la IListe

    addActionMenuDroit();
    this.ecriturePanel
        .getListe()
        .getJTable()
        .addMouseListener(
            new MouseAdapter() {

              public void mouseReleased(MouseEvent e) {
                System.err.println("Mouse released");
                int[] selectedRows =
                    LettragePanel.this.ecriturePanel.getListe().getJTable().getSelectedRows();
                int[] idRows = new int[selectedRows.length];
                for (int i = 0; i < idRows.length; i++) {
                  idRows[i] =
                      LettragePanel.this.ecriturePanel.getListe().idFromIndex(selectedRows[i]);
                }

                LettragePanel.this.model.updateSelection(idRows);
                LettragePanel.this.warningSolde.setVisible(
                    LettragePanel.this.model.getSoldeSelection() != 0);
                buttonDelettrer.setEnabled(LettragePanel.this.model.getSoldeSelection() == 0);
                LettragePanel.this.buttonLettrer.setEnabled(
                    LettragePanel.this.model.getSoldeSelection() == 0);
              }
            });

    // action sur la IListe
    this.ecriturePanel
        .getListe()
        .getJTable()
        .addKeyListener(
            new KeyAdapter() {
              public void keyReleased(KeyEvent e) {

                System.err.println("Key released");
                int[] selectedRows =
                    LettragePanel.this.ecriturePanel.getListe().getJTable().getSelectedRows();
                int[] idRows = new int[selectedRows.length];
                for (int i = 0; i < idRows.length; i++) {
                  idRows[i] =
                      LettragePanel.this.ecriturePanel.getListe().idFromIndex(selectedRows[i]);
                }

                LettragePanel.this.model.updateSelection(idRows);
                LettragePanel.this.warningPanel.setVisible(
                    (LettragePanel.this.codeLettrage.getText().trim().length() == 0));
                LettragePanel.this.warningSolde.setVisible(
                    LettragePanel.this.model.getSoldeSelection() != 0);
              }
            });

    // Gestion du code
    this.codeLettrage
        .getDocument()
        .addDocumentListener(
            new SimpleDocumentListener() {

              @Override
              public void update(DocumentEvent e) {
                // TODO Auto-generated method stub
                LettragePanel.this.warningPanel.setVisible(
                    (LettragePanel.this.codeLettrage.getText().trim().length() == 0));
                LettragePanel.this.buttonLettrer.setEnabled(
                    (LettragePanel.this.codeLettrage.getText().trim().length() != 0));
              }
            });

    changeListRequest();
    this.warningPanel.setVisible((this.codeLettrage.getText().trim().length() == 0));
    this.buttonLettrer.setEnabled((this.codeLettrage.getText().trim().length() != 0));
  }

  /* Menu clic Droit */
  private void addActionMenuDroit() {
    // JPopupMenu menu = new JPopupMenu();

    this.ecriturePanel
        .getListe()
        .addRowAction(
            new AbstractAction("Voir la source") {
              public void actionPerformed(ActionEvent e) {

                SQLRow rowEcr = LettragePanel.this.ecriturePanel.getListe().fetchSelectedRow();
                MouvementSQLElement.showSource(rowEcr.getInt("ID_MOUVEMENT"));
              }
            },
            "financing.accouning.entries.source.show");

    // if (this.codeLettrage.getText().trim().length() != 0) {
    final AbstractAction abstractAction =
        new AbstractAction() {
          public void actionPerformed(ActionEvent e) {

            int[] rowIndex =
                LettragePanel.this.ecriturePanel.getListe().getJTable().getSelectedRows();
            actionLettrage(rowIndex);
          }
        };
    this.ecriturePanel.getListe().addRowAction(abstractAction, "financing.accouning.entries.match");
    // }
    this.codeLettrage
        .getDocument()
        .addDocumentListener(
            new SimpleDocumentListener() {
              @Override
              public void update(DocumentEvent e) {
                abstractAction.setEnabled(
                    LettragePanel.this.codeLettrage.getText().trim().length() > 0);
              }
            });

    this.ecriturePanel
        .getListe()
        .addRowAction(
            new AbstractAction("Délettrer") {
              public void actionPerformed(ActionEvent e) {

                int[] rowIndex =
                    LettragePanel.this.ecriturePanel.getListe().getJTable().getSelectedRows();
                actionDelettrage(rowIndex);
              }
            },
            "financing.accouning.entries.unmatch");

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

  /* Panel Warning no numero releve */
  private void createPanelWarning() {

    this.warningPanel = new JPanel();
    this.warningPanel.setLayout(new GridBagLayout());
    // this.warningPanel.setBorder(BorderFactory.createTitledBorder("Warning"));

    GridBagConstraints c = new GridBagConstraints();
    c.anchor = GridBagConstraints.WEST;
    c.fill = GridBagConstraints.NONE;
    c.gridheight = 1;
    c.gridwidth = 1;
    c.gridx = 0;
    c.gridy = 0;
    c.weightx = 0;
    c.weighty = 0;

    final JLabel warningNoCodeImg = new JLabelWarning();
    warningNoCodeImg.setHorizontalAlignment(SwingConstants.RIGHT);
    this.warningPanel.add(warningNoCodeImg, c);
    final JLabel warningNoCodeText =
        new JLabel("Impossible de lettrer tant que le code de lettrage n'est pas saisi!");
    c.gridx++;
    this.warningPanel.add(warningNoCodeText, c);
  }

  /* Panel Warning solde invalide */
  private void createPanelWarningSolde() {

    this.warningSolde = new JPanel();
    this.warningSolde.setLayout(new GridBagLayout());
    // this.warningPanel.setBorder(BorderFactory.createTitledBorder("Warning"));

    GridBagConstraints c = new GridBagConstraints();
    c.anchor = GridBagConstraints.WEST;
    c.fill = GridBagConstraints.NONE;
    c.gridheight = 1;
    c.gridwidth = 1;
    c.gridx = 0;
    c.gridy = 0;
    c.weightx = 0;
    c.weighty = 0;

    final JLabel warningNoCodeImg = new JLabelWarning();
    warningNoCodeImg.setHorizontalAlignment(SwingConstants.RIGHT);
    this.warningSolde.add(warningNoCodeImg, c);
    final JLabel warningNoCodeText =
        new JLabel("Impossible de lettrer tant que le solde sélectionné n'est pas nul!");
    c.gridx++;
    this.warningSolde.add(warningNoCodeText, c);
  }

  // Lettre la ligne passée en parametre
  private void actionLettrage(int[] rowIndex) {
    String codeLettre = this.codeLettrage.getText().trim();

    List<SQLRow> rowsSelected = new ArrayList<SQLRow>(rowIndex.length);

    long solde = 0;
    for (int i = 0; i < rowIndex.length; i++) {
      int id = this.ecriturePanel.getListe().idFromIndex(rowIndex[i]);
      SQLRow row = this.tableEcr.getRow(id);
      rowsSelected.add(row);

      solde += ((Long) row.getObject("DEBIT")).longValue();
      solde -= ((Long) row.getObject("CREDIT")).longValue();
    }

    if (solde == 0) {

      for (SQLRow row2 : rowsSelected) {

        SQLRowValues rowVals = new SQLRowValues(this.tableEcr);

        // Lettrage
        // On lettre ou relettre la ligne avec le code saisi
        if (codeLettre.length() > 0) {

          // Si la ligne est en brouillard on valide le mouvement associé
          if (this.boxValidEcriture.isSelected() && (!row2.getBoolean("VALIDE"))) {
            EcritureSQLElement.validationEcritures(row2.getInt("ID_MOUVEMENT"));
          }

          rowVals.put("LETTRAGE", codeLettre);
          rowVals.put("DATE_LETTRAGE", this.dateLettrage.getDate());
          try {
            rowVals.update(row2.getID());
          } catch (SQLException e1) {

            e1.printStackTrace();
          }
        }
      }
      // Mise à jour du code de lettrage
      SQLElement elt = Configuration.getInstance().getDirectory().getElement("NUMEROTATION_AUTO");
      SQLRowValues rowVals = elt.getTable().getRow(2).createEmptyUpdateRow();
      rowVals.put("CODE_LETTRAGE", codeLettre);
      try {
        rowVals.update();
      } catch (SQLException e) {
        e.printStackTrace();
      }
      this.codeLettrage.setText(NumerotationAutoSQLElement.getNextCodeLettrage());

      this.model.updateTotauxCompte();
    }
  }

  protected MaskFormatter createFormatter() {
    MaskFormatter formatter = null;
    try {
      formatter = new MaskFormatter("UUU");
    } catch (ParseException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
    return formatter;
  }

  // Pointe la ligne passée en parametre
  private void actionDelettrage(int[] rowIndex) {

    List<SQLRow> rowsSelected = new ArrayList<SQLRow>(rowIndex.length);

    long solde = 0;
    for (int i = 0; i < rowIndex.length; i++) {
      int id = this.ecriturePanel.getListe().idFromIndex(rowIndex[i]);
      SQLRow row = this.tableEcr.getRow(id);
      rowsSelected.add(row);

      solde += ((Long) row.getObject("DEBIT")).longValue();
      solde -= ((Long) row.getObject("CREDIT")).longValue();
    }

    if (solde == 0) {
      for (SQLRow row : rowsSelected) {

        SQLRowValues rowVals = new SQLRowValues(this.tableEcr);

        // Dépointage
        if (row.getString("LETTRAGE").trim().length() != 0) {

          rowVals.put("LETTRAGE", "");
          rowVals.put("DATE_LETTRAGE", null);
          try {
            rowVals.update(row.getID());
          } catch (SQLException e1) {
            e1.printStackTrace();
          }
        }
      }
    }
    this.model.updateTotauxCompte();
  }

  /*
   * MaJ de la requete pour remplir la IListe en fonction du compte sélectionner et du mode de
   * sélection
   */
  private void changeListRequest() {
    Object idCpt = this.selCompte.getSelectedId();

    SQLRow row = this.tableComptePCE.getRow(Integer.valueOf(idCpt.toString()));

    // filtre de selection
    Where w = new Where(this.tableEcr.getField("ID_COMPTE_PCE"), "=", this.tableComptePCE.getKey());

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

    if (row != null) {
      String num = row.getString("NUMERO");
      Where w2;
      if (this.boxAddSousCompte.isSelected()) {
        w2 = new Where(this.tableComptePCE.getField("NUMERO"), "LIKE", num + "%");
      } else {
        w2 = new Where(this.tableComptePCE.getField("NUMERO"), "=", num);
      }
      w = w.and(w2);
    } else {
      w = w.and(new Where(this.tableComptePCE.getKey(), "=", idCpt));
    }

    // final Calendar cal = Calendar.getInstance();
    // cal.setTimeInMillis(this.rangeSlide.getValue(0));
    //
    // Date dInf = cal.getTime();
    // cal.setTimeInMillis(this.rangeSlide.getValue(1));
    // Date dSup = cal.getTime();

    // w = w.and(new Where(this.tableEcr.getField("DATE"), dInf, dSup));

    Date d1 = this.dateDeb.getValue();
    Date d2 = this.dateFin.getValue();

    if (d1 == null && d2 != null) {
      w = w.and(new Where(this.tableEcr.getField("DATE"), "<=", d2));
    } else {
      if (d1 != null && d2 == null) {
        w = w.and(new Where(this.tableEcr.getField("DATE"), ">=", d1));
      } else {
        if (d1 != null && d2 != null) {
          w = w.and(new Where(this.tableEcr.getField("DATE"), d1, d2));
        }
      }
    }

    if (this.modeSelect == ecritureLettree) {
      w = w.and(new Where(this.tableEcr.getField("LETTRAGE"), "!=", ""));
    } else {
      if (this.modeSelect == ecritureNonLettree) {

        Where wLettre = new Where(this.tableEcr.getField("LETTRAGE"), "=", "");
        String s = null;
        wLettre = wLettre.or(new Where(this.tableEcr.getField("LETTRAGE"), "=", s));
        w = w.and(wLettre);
      }
    }

    this.ecriturePanel.getListe().getRequest().setWhere(w);
    this.ecriturePanel.getListe().setSQLEditable(false);

    this.model.setIdCompte(Integer.parseInt(idCpt.toString()));
  }

  /*
   * Panel de sélection du mode d'affichage des ecritures
   */
  private JPanel createPanelSelectionEcritures() {

    JPanel panelSelectEcritures = new JPanel();

    GridBagConstraints cPanel = new GridBagConstraints();
    cPanel.anchor = GridBagConstraints.NORTHWEST;
    cPanel.fill = GridBagConstraints.HORIZONTAL;
    cPanel.gridheight = 1;
    cPanel.gridwidth = 1;
    cPanel.gridx = 0;
    cPanel.gridy = 0;
    cPanel.weightx = 0;
    cPanel.weighty = 0;

    panelSelectEcritures.setLayout(new GridBagLayout());

    final JRadioButton buttonBoth = new JRadioButton("Toutes");
    panelSelectEcritures.add(buttonBoth, cPanel);
    cPanel.gridx++;
    final JRadioButton buttonNonLettre = new JRadioButton("Non lettrées");
    panelSelectEcritures.add(buttonNonLettre, cPanel);
    cPanel.gridx++;
    final JRadioButton buttonLettre = new JRadioButton("Lettrées");
    panelSelectEcritures.add(buttonLettre, cPanel);

    ButtonGroup group = new ButtonGroup();
    group.add(buttonBoth);
    group.add(buttonNonLettre);
    group.add(buttonLettre);
    buttonBoth.setSelected(true);

    buttonLettre.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            if (buttonLettre.isSelected()) {
              LettragePanel.this.modeSelect = ecritureLettree;
              changeListRequest();
            }
          }
        });

    buttonNonLettre.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            if (buttonNonLettre.isSelected()) {
              LettragePanel.this.modeSelect = ecritureNonLettree;
              changeListRequest();
            }
          }
        });

    buttonBoth.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            if (buttonBoth.isSelected()) {
              LettragePanel.this.modeSelect = allEcriture;
              changeListRequest();
            }
          }
        });

    return panelSelectEcritures;
  }

  /*
   * Creation du panel de la legende
   */
  private JPanel createPanelLegende() {
    JPanel panelLegende = new JPanel();

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

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

    panelLegende.setLayout(new GridBagLayout());
    panelLegende.setBorder(BorderFactory.createTitledBorder("Légendes"));

    JPanel ecritureValidPanel = new JPanel();
    ecritureValidPanel.setLayout(new GridBagLayout());
    ecritureValidPanel.setBackground(Color.WHITE);
    ecritureValidPanel.add(new JLabel("Ecritures validées"), cPanel);
    panelLegende.add(ecritureValidPanel, c);

    JPanel ecritureNonValidPanel = new JPanel();
    ecritureNonValidPanel.setLayout(new GridBagLayout());
    ecritureNonValidPanel.setBackground(PointageRenderer.getCouleurEcritureNonValide());
    ecritureNonValidPanel.add(new JLabel("Ecritures non validées"), cPanel);
    panelLegende.add(ecritureNonValidPanel, c);

    JPanel ecritureNonValidTodayPanel = new JPanel();
    ecritureNonValidTodayPanel.setLayout(new GridBagLayout());
    ecritureNonValidTodayPanel.setBackground(PointageRenderer.getCouleurEcritureToDay());
    ecritureNonValidTodayPanel.add(new JLabel("Ecritures non validées du jour"), cPanel);
    panelLegende.add(ecritureNonValidTodayPanel, c);

    JPanel ecriturePointePanel = new JPanel();
    ecriturePointePanel.setLayout(new GridBagLayout());
    ecriturePointePanel.setBackground(PointageRenderer.getCouleurEcriturePointee());
    ecriturePointePanel.add(new JLabel("Ecritures lettrées"), cPanel);
    panelLegende.add(ecriturePointePanel, c);

    return panelLegende;
  }
}
  public SuppressionEcrituresPanel(final int idMvt) {
    this.setLayout(new GridBagLayout());
    final GridBagConstraints c = new DefaultGridBagConstraints();
    c.weightx = 1;
    SQLBase base = ((ComptaPropsConfiguration) Configuration.getInstance()).getSQLBaseSociete();
    SQLTable tableMouvement = base.getTable("MOUVEMENT");
    SQLRow rowMvt = tableMouvement.getRow(idMvt);
    JLabel label = new JLabel("Vous allez supprimer la piéce n°" + rowMvt.getInt("ID_PIECE"));
    JLabelWarning warning = new JLabelWarning();
    JPanel panelLabel = new JPanel();
    panelLabel.add(warning);
    panelLabel.add(label);

    c.gridwidth = GridBagConstraints.REMAINDER;
    this.add(panelLabel, c);

    // TODO afficher les numeros de mouvement implique
    int[] idS = getMouvement(rowMvt.getInt("ID_PIECE"));
    if (idS == null) {
      ExceptionHandler.handle(
          "Aucun mouvement associé à la piéce n°"
              + ((rowMvt != null) ? rowMvt.getInt("ID_PIECE") : "mouvement nul"));
    } else {
      StringBuffer s = new StringBuffer();
      s.append("Elle est composée par les mouvements : (");
      JLabel labelMouv = new JLabel();
      // c.gridwidth = 1;
      c.gridy++;
      c.gridx = 0;
      this.add(labelMouv, c);
      s.append(idS[0]);
      for (int i = 1; i < idS.length; i++) {

        s.append(", ");
        s.append(idS[i]);
      }
      s.append(')');
      labelMouv.setText(s.toString());
    }

    JButton buttonOK = new JButton("OK");
    JButton buttonCancel = new JButton("Annuler");

    c.gridwidth = 1;
    c.gridy++;
    c.gridx = 0;
    this.add(buttonOK, c);
    c.gridx++;
    this.add(buttonCancel, c);

    buttonOK.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            EcritureSQLElement elt =
                (EcritureSQLElement)
                    Configuration.getInstance().getDirectory().getElement("ECRITURE");
            elt.archiveMouvement(idMvt);
            ((JFrame) SwingUtilities.getRoot(SuppressionEcrituresPanel.this)).dispose();
          }
        });
    buttonCancel.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            ((JFrame) SwingUtilities.getRoot(SuppressionEcrituresPanel.this)).dispose();
          }
        });
  }
Ejemplo n.º 26
0
 @Override
 public SQLElement getSQLElement() {
   return Configuration.getInstance().getDirectory().getElement("COMMANDE_CLIENT_ELEMENT");
 }
Ejemplo n.º 27
0
  /**
   * Affiche si il y a des différences entre les tables de base et baseDefault
   *
   * @param base
   * @param baseDefault
   */
  public static void compareDB(int base, int baseDefault) {

    try {
      if (Configuration.getInstance() == null) {
        Configuration.setInstance(ComptaPropsConfiguration.create());
      }
      Configuration instance = Configuration.getInstance();
      SQLTable tableSociete = Configuration.getInstance().getBase().getTable("SOCIETE_COMMON");

      String baseName = tableSociete.getRow(base).getString("DATABASE_NAME");
      String baseDefaultName = tableSociete.getRow(baseDefault).getString("DATABASE_NAME");

      instance.getBase().getDBSystemRoot().getRootsToMap().clear();
      try {
        Set<String> s = new HashSet<String>();
        s.add(baseName);
        s.add(baseDefaultName);
        instance.getBase().fetchTables(s);
      } catch (SQLException e) {
        throw new IllegalStateException("could not access societe base", e);
      }
      // instance.getBase().getDBRoot(baseName);
      // instance.getBase().getDBRoot(baseDefaultName);
      System.err.println("baseName" + baseName);
      System.err.println("baseDefault" + baseDefaultName);
      instance.getSystemRoot().prependToRootPath("Common");
      instance.getSystemRoot().prependToRootPath(baseName);
      instance.getSystemRoot().prependToRootPath(baseDefaultName);

      SQLSchema baseSQL = instance.getBase().getSchema(baseName);
      SQLSchema baseSQLDefault = instance.getBase().getSchema(baseDefaultName);

      DatabaseMetaData dbMetaDataSociete =
          baseSQL.getBase().getDataSource().getConnection().getMetaData();
      DatabaseMetaData dbMetaDataSocieteDefault =
          baseSQLDefault.getBase().getDataSource().getConnection().getMetaData();

      Map<String, Map<String, SQLField>> mapTableSociete =
          new HashMap<String, Map<String, SQLField>>();
      Map<String, Map<String, SQLField>> mapTableSocieteDefault =
          new HashMap<String, Map<String, SQLField>>();

      ResultSet rs = dbMetaDataSociete.getTables("", baseSQL.getName(), "%", null);

      System.err.println("Start");

      while (rs.next()) {
        // System.err.println(rs.getString("TABLE_NAME") + ", TYPE ::" +
        // rs.getString("TABLE_TYPE"));

        if (rs.getString("TABLE_TYPE") != null
            && rs.getString("TABLE_TYPE").equalsIgnoreCase("TABLE")) {
          Map<String, SQLField> m = new HashMap<String, SQLField>();
          baseSQL.getTableNames();
          Set<SQLField> s = baseSQL.getTable(rs.getString("TABLE_NAME")).getFields();
          for (SQLField field : s) {
            m.put(field.getName(), field);
          }
          mapTableSociete.put(rs.getString("TABLE_NAME"), m);
        }
      }
      rs.close();

      rs = dbMetaDataSocieteDefault.getTables("", baseSQLDefault.getName(), "%", null);

      while (rs.next()) {
        // System.err.println(rs.getString("TABLE_NAME") + ", TYPE ::" +
        // rs.getString("TABLE_TYPE"));
        if (rs.getString("TABLE_TYPE") != null
            && rs.getString("TABLE_TYPE").equalsIgnoreCase("TABLE")) {
          Map<String, SQLField> m = new HashMap<String, SQLField>();
          Set<SQLField> s = baseSQLDefault.getTable(rs.getString("TABLE_NAME")).getFields();
          for (SQLField field : s) {
            m.put(field.getName(), field);
          }
          mapTableSocieteDefault.put(rs.getString("TABLE_NAME"), m);
        }
      }
      rs.close();

      System.err.println("Test 1 " + mapTableSociete.keySet().size());
      // On verifie que toutes les tables de la societe sont contenues dans la base default
      for (String tableName : mapTableSociete.keySet()) {

        if (!mapTableSocieteDefault.containsKey(tableName)) {
          System.err.println(
              "!! **** La table " + tableName + " n'est pas dans la base " + baseDefault);

        } else {
          Map<String, SQLField> mSoc = mapTableSociete.get(tableName);
          Map<String, SQLField> mDef = mapTableSocieteDefault.get(tableName);
          if (mSoc.keySet().containsAll(mDef.keySet())) {
            if (mSoc.keySet().size() == mDef.keySet().size()) {
              System.err.println("Table " + tableName + " --- OK");
              compareTypeField(mSoc, mDef);
            } else {
              if (mSoc.keySet().size() > mDef.keySet().size()) {
                for (String fieldName : mDef.keySet()) {
                  mSoc.remove(fieldName);
                }
                System.err.println("!! **** Difference Table " + tableName);
                System.err.println(
                    tableSociete.getRow(baseDefault).getString("DATABASE_NAME")
                        + " Set Column "
                        + mSoc);
                System.err.println(
                    getAlterTable(
                        mSoc,
                        tableSociete.getRow(baseDefault).getString("DATABASE_NAME"),
                        tableName));
              } else {

              }
            }
          } else {
            // System.err.println("!! **** Difference Table " + tableName);
            // System.err.println(tableSociete.getRow(base).getString("DATABASE_NAME") +
            // " Set Column " + mapTableSociete.get(tableName));
            // System.err.println(tableSociete.getRow(baseDefault).getString("DATABASE_NAME")
            // + " Set Column " + mapTableSocieteDefault.get(tableName));
            for (String fieldName : mSoc.keySet()) {
              mDef.remove(fieldName);
            }
            System.err.println("!! **** Difference Table " + tableName);
            System.err.println(
                tableSociete.getRow(base).getString("DATABASE_NAME") + " Set Column " + mDef);
            System.err.println(
                getAlterTable(
                    mDef, tableSociete.getRow(base).getString("DATABASE_NAME"), tableName));
          }
        }
      }

      System.err.println("Test 2 " + mapTableSocieteDefault.keySet().size());
      // On verifie que toutes les tables de la base default sont contenues dans la base
      // societe
      for (Iterator i = mapTableSocieteDefault.keySet().iterator(); i.hasNext(); ) {
        Object tableName = i.next();
        if (!mapTableSociete.containsKey(tableName)) {
          System.err.println(
              "!! **** La table " + tableName + " n'est pas dans la base " + baseDefault);
        }
      }

      SQLSchema schem = instance.getBase().getSchema("Common");

    } catch (SQLException e) {
      e.printStackTrace();
    }
  }
  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;
  }
 @Override
 public JFrame createFrame() {
   return new EditFrame(Configuration.getInstance().getDirectory().getElement("VARIABLE_SALARIE"));
 }
Ejemplo n.º 30
0
  public LettragePanel() {
    this.setLayout(new GridBagLayout());
    GridBagConstraints c = new DefaultGridBagConstraints();

    this.modeSelect = allEcriture;

    // Selection du compte à lettrer
    JLabel labelPointageCompte = new JLabel("Lettrage du compte");
    labelPointageCompte.setHorizontalAlignment(SwingConstants.RIGHT);

    this.add(labelPointageCompte, c);
    this.selCompte = new ISQLCompteSelector();
    this.selCompte.init();
    this.selCompte.setValue(ComptePCESQLElement.getId("5"));

    c.gridx++;
    c.weightx = 1;
    c.gridwidth = GridBagConstraints.REMAINDER;
    this.add(this.selCompte, c);

    c.gridwidth = 1;

    // Gestion du lettrage
    c.insets = new Insets(2, 2, 1, 2);
    TitledSeparator sepGestionLettrage = new TitledSeparator("Gestion du lettrage");
    c.fill = GridBagConstraints.HORIZONTAL;
    c.gridy++;
    c.gridx = 0;
    c.gridwidth = GridBagConstraints.REMAINDER;
    this.add(sepGestionLettrage, c);

    // Code de lettrage
    JLabel labelCode = new JLabel("Code lettrage");
    labelCode.setHorizontalAlignment(SwingConstants.RIGHT);
    c.gridx = 0;
    c.gridy++;
    c.gridwidth = 1;
    c.weightx = 0;
    this.add(labelCode, c);

    this.codeLettrage = new JTextField(10);
    DocumentFilterList.add(
        (AbstractDocument) this.codeLettrage.getDocument(),
        new UpperCaseFormatFilter(),
        FilterType.SIMPLE_FILTER);
    c.gridx++;
    c.weightx = 1;
    this.add(this.codeLettrage, c);
    this.codeLettrage.setText(NumerotationAutoSQLElement.getNextCodeLettrage());

    // Warning si aucun code rentré
    createPanelWarning();
    c.gridwidth = GridBagConstraints.REMAINDER;
    c.weightx = 0;
    c.gridx++;
    this.add(this.warningPanel, c);

    // Date de lettrage
    JLabel labelDate = new JLabel("Date");
    labelDate.setHorizontalAlignment(SwingConstants.RIGHT);
    c.gridx = 0;
    c.gridy++;
    c.weightx = 0;
    c.gridwidth = 1;
    this.add(labelDate, c);
    this.dateLettrage = new JDate(true);
    c.gridx++;
    this.add(this.dateLettrage, c);

    // Warning si solde non nul
    c.gridx++;
    createPanelWarningSolde();
    c.gridwidth = GridBagConstraints.REMAINDER;
    c.weightx = 0;
    this.add(this.warningSolde, c);

    c.gridwidth = 1;

    TitledSeparator sepPeriode = new TitledSeparator("Filtre ");
    c.gridy++;
    c.gridx = 0;
    c.anchor = GridBagConstraints.WEST;
    c.gridwidth = GridBagConstraints.REMAINDER;
    c.fill = GridBagConstraints.HORIZONTAL;
    this.add(sepPeriode, c);

    JPanel panelSelectEcritures = createPanelSelectionEcritures();
    c.gridy++;
    c.gridx = 0;
    c.gridwidth = 1;
    c.weightx = 0;

    JLabel labelEcr = new JLabel("Ecritures");
    labelEcr.setHorizontalAlignment(SwingConstants.RIGHT);
    this.add(labelEcr, c);
    c.gridx++;
    c.weightx = 1;
    c.gridwidth = GridBagConstraints.REMAINDER;
    c.fill = GridBagConstraints.NONE;
    this.add(panelSelectEcritures, c);

    JPanel panelPeriode = new JPanel();
    // Date de début
    this.dateDeb = new JDate();
    c.gridy++;
    c.gridx = 0;
    c.gridwidth = 1;
    c.weightx = 0;
    JLabel labelPerio = new JLabel("Période du ");
    labelPerio.setHorizontalAlignment(SwingConstants.RIGHT);
    c.fill = GridBagConstraints.HORIZONTAL;
    this.add(labelPerio, c);

    panelPeriode.add(this.dateDeb);
    this.dateDeb.addValueListener(
        new PropertyChangeListener() {
          public void propertyChange(PropertyChangeEvent evt) {
            changeListRequest();
          }
        });

    // Date de fin
    this.dateFin = new JDate(true);
    panelPeriode.add(new JLabel("au"));
    this.dateFin.addValueListener(
        new PropertyChangeListener() {
          public void propertyChange(PropertyChangeEvent evt) {
            changeListRequest();
          }
        });

    panelPeriode.add(this.dateFin);
    c.gridx++;
    c.gridwidth = GridBagConstraints.REMAINDER;
    c.weightx = 1;
    c.fill = GridBagConstraints.NONE;
    this.add(panelPeriode, c);

    c.gridx = 0;
    c.gridy++;
    this.boxAddSousCompte = new JCheckBox("Ajouter les sous comptes");
    this.boxAddSousCompte.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            // TODO Auto-generated method stub
            changeListRequest();
          }
        });

    this.add(this.boxAddSousCompte, c);

    TitledSeparator sepEcriture = new TitledSeparator("Ecritures ");
    c.gridy++;
    c.gridx = 0;
    c.weightx = 1;
    c.gridwidth = GridBagConstraints.REMAINDER;
    c.fill = GridBagConstraints.HORIZONTAL;
    this.add(sepEcriture, c);

    // Liste des ecritures
    final EcritureSQLElement ecritureElem =
        Configuration.getInstance().getDirectory().getElement(EcritureSQLElement.class);
    this.ecriturePanel =
        new ListPanelEcritures(ecritureElem, new IListe(ecritureElem.createLettrageTableSource()));
    c.gridx = 0;
    c.gridy++;
    c.weighty = 1;
    c.weightx = 1;
    c.fill = GridBagConstraints.BOTH;
    c.gridwidth = GridBagConstraints.REMAINDER;
    this.ecriturePanel
        .getListe()
        .setPreferredSize(
            new Dimension(this.ecriturePanel.getListe().getPreferredSize().width, 200));
    this.add(this.ecriturePanel, c);

    // JTable Totaux
    c.gridy++;
    c.gridx = 0;
    c.weighty = 0;
    c.weightx = 1;
    c.fill = GridBagConstraints.BOTH;
    c.gridwidth = 3;
    c.gridheight = 3;
    this.model = new LettrageModel(this.selCompte.getSelectedId());
    JTable table = new JTable(this.model);

    // AlternateTableCellRenderer.setAllColumns(table);
    for (int i = 0; i < table.getColumnCount(); i++) {
      // if (table.getColumnClass(i) == Long.class || table.getColumnClass(i) ==
      // BigInteger.class) {
      table.getColumnModel().getColumn(i).setCellRenderer(new DeviseNiceTableCellRenderer());
      // }
    }
    JScrollPane sPane = new JScrollPane(table);

    // TODO Gerer la taille des colonnes
    Dimension d =
        new Dimension(
            table.getPreferredSize().width,
            table.getPreferredSize().height + table.getTableHeader().getPreferredSize().height + 4);
    sPane.setPreferredSize(d);
    this.add(sPane, c);

    // Legende
    c.gridx = 4;
    c.gridwidth = 1;
    c.anchor = GridBagConstraints.EAST;
    c.fill = GridBagConstraints.NONE;
    c.weightx = 0;
    this.add(createPanelLegende(), c);

    c.gridheight = 1;
    final JButton buttonDelettrer = new JButton("Délettrer");
    this.buttonLettrer = new JButton("Lettrer");
    // Validation des ecritures pointées
    this.boxValidEcriture = new JCheckBox("Valider les écritures lettrées");
    c.gridx++;
    c.gridwidth = GridBagConstraints.REMAINDER;
    this.add(this.boxValidEcriture, c);

    JPanel panelButton = new JPanel();

    // Boutton lettrer

    panelButton.add(this.buttonLettrer, c);

    // Boutton Delettrer

    panelButton.add(buttonDelettrer, c);

    c.gridy++;
    c.gridx = 5;
    c.gridwidth = GridBagConstraints.REMAINDER;
    c.gridheight = 1;
    c.weightx = 1;
    c.fill = GridBagConstraints.NONE;
    c.anchor = GridBagConstraints.EAST;
    this.add(panelButton, c);

    c.gridy++;
    c.anchor = GridBagConstraints.SOUTHEAST;
    JButton buttonClose = new JButton("Fermer");
    buttonClose.addActionListener(
        new ActionListener() {

          @Override
          public void actionPerformed(ActionEvent e) {
            ((Window) SwingUtilities.getRoot((Component) e.getSource())).dispose();
          }
        });
    this.add(buttonClose, c);
    this.buttonLettrer.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {

            int[] rowIndex =
                LettragePanel.this.ecriturePanel.getListe().getJTable().getSelectedRows();

            // System.err.println("Action lettrage sur " + i);
            actionLettrage(rowIndex);
          }
        });

    buttonDelettrer.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {

            int[] rowIndex =
                LettragePanel.this.ecriturePanel.getListe().getJTable().getSelectedRows();
            actionDelettrage(rowIndex);
          }
        });

    // Changement de compte
    this.selCompte.addValueListener(
        new PropertyChangeListener() {
          public void propertyChange(PropertyChangeEvent evt) {

            changeListRequest();
          };
        });

    // Action Souris sur la IListe

    addActionMenuDroit();
    this.ecriturePanel
        .getListe()
        .getJTable()
        .addMouseListener(
            new MouseAdapter() {

              public void mouseReleased(MouseEvent e) {
                System.err.println("Mouse released");
                int[] selectedRows =
                    LettragePanel.this.ecriturePanel.getListe().getJTable().getSelectedRows();
                int[] idRows = new int[selectedRows.length];
                for (int i = 0; i < idRows.length; i++) {
                  idRows[i] =
                      LettragePanel.this.ecriturePanel.getListe().idFromIndex(selectedRows[i]);
                }

                LettragePanel.this.model.updateSelection(idRows);
                LettragePanel.this.warningSolde.setVisible(
                    LettragePanel.this.model.getSoldeSelection() != 0);
                buttonDelettrer.setEnabled(LettragePanel.this.model.getSoldeSelection() == 0);
                LettragePanel.this.buttonLettrer.setEnabled(
                    LettragePanel.this.model.getSoldeSelection() == 0);
              }
            });

    // action sur la IListe
    this.ecriturePanel
        .getListe()
        .getJTable()
        .addKeyListener(
            new KeyAdapter() {
              public void keyReleased(KeyEvent e) {

                System.err.println("Key released");
                int[] selectedRows =
                    LettragePanel.this.ecriturePanel.getListe().getJTable().getSelectedRows();
                int[] idRows = new int[selectedRows.length];
                for (int i = 0; i < idRows.length; i++) {
                  idRows[i] =
                      LettragePanel.this.ecriturePanel.getListe().idFromIndex(selectedRows[i]);
                }

                LettragePanel.this.model.updateSelection(idRows);
                LettragePanel.this.warningPanel.setVisible(
                    (LettragePanel.this.codeLettrage.getText().trim().length() == 0));
                LettragePanel.this.warningSolde.setVisible(
                    LettragePanel.this.model.getSoldeSelection() != 0);
              }
            });

    // Gestion du code
    this.codeLettrage
        .getDocument()
        .addDocumentListener(
            new SimpleDocumentListener() {

              @Override
              public void update(DocumentEvent e) {
                // TODO Auto-generated method stub
                LettragePanel.this.warningPanel.setVisible(
                    (LettragePanel.this.codeLettrage.getText().trim().length() == 0));
                LettragePanel.this.buttonLettrer.setEnabled(
                    (LettragePanel.this.codeLettrage.getText().trim().length() != 0));
              }
            });

    changeListRequest();
    this.warningPanel.setVisible((this.codeLettrage.getText().trim().length() == 0));
    this.buttonLettrer.setEnabled((this.codeLettrage.getText().trim().length() != 0));
  }