@Override public int insert(final SQLRow order) { final int idDevis; // on verifie qu'un devis du meme numero n'a pas été inséré entre temps if (this.numeroUniqueDevis.checkValidation()) { idDevis = super.insert(order); this.table.updateField("ID_DEVIS", idDevis); // Création des articles this.table.createArticle(idDevis, getElement()); // generation du document try { final DevisXmlSheet sheet = new DevisXmlSheet(getTable().getRow(idDevis)); sheet.createDocumentAsynchronous(); sheet.showPrintAndExportAsynchronous( DevisSQLComponent.this.panelOO.isVisualisationSelected(), DevisSQLComponent.this.panelOO.isImpressionSelected(), true); } catch (Exception e) { ExceptionHandler.handle("Impossible de créer le devis", e); } // incrémentation du numéro auto if (NumerotationAutoSQLElement.getNextNumero(DevisSQLElement.class) .equalsIgnoreCase(this.numeroUniqueDevis.getText().trim())) { final SQLRowValues rowVals = new SQLRowValues(this.tableNum); int val = this.tableNum .getRow(2) .getInt(NumerotationAutoSQLElement.getLabelNumberFor(DevisSQLElement.class)); val++; rowVals.put( NumerotationAutoSQLElement.getLabelNumberFor(DevisSQLElement.class), new Integer(val)); try { rowVals.update(2); } catch (final SQLException e) { e.printStackTrace(); } } } else { idDevis = getSelectedID(); ExceptionHandler.handle("Impossible d'ajouter, numéro de devis existant."); final Object root = SwingUtilities.getRoot(this); if (root instanceof EditFrame) { final EditFrame frame = (EditFrame) root; frame.getPanel().setAlwaysVisible(true); } } return idDevis; }
// 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(); } }
@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; }
/** * 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(); }
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)); }