r3532 - trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialtransaction
Author: mallon Date: 2012-07-17 15:35:19 +0200 (Tue, 17 Jul 2012) New Revision: 3532 Url: http://chorem.org/repositories/revision/lima/3532 Log: fixes #648 Ajout du calcul de la tva (Celle ?\195?\160 19,6%), lors de l ajout d'une seconde entree du compte 410 ou 418; suppression des colonnes lettre et journal, devenues obsoletes. Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialtransaction/FinancialTransactionTable.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialtransaction/FinancialTransactionTableModel.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialtransaction/FinancialTransactionView.jaxx trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialtransaction/FinancialTransactionViewHandler.java Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialtransaction/FinancialTransactionTable.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialtransaction/FinancialTransactionTable.java 2012-07-16 17:09:57 UTC (rev 3531) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialtransaction/FinancialTransactionTable.java 2012-07-17 13:35:19 UTC (rev 3532) @@ -30,14 +30,12 @@ import org.apache.commons.logging.LogFactory; import org.chorem.lima.entity.Account; import org.chorem.lima.entity.Entry; -import org.chorem.lima.entity.EntryBook; import org.chorem.lima.entity.FinancialTransaction; import org.chorem.lima.ui.celleditor.AccountTableCellEditor; import org.chorem.lima.ui.celleditor.BigDecimalTableCellEditor; import org.chorem.lima.ui.celleditor.BigDecimalTableCellRenderer; import org.chorem.lima.ui.celleditor.DateTableCellEditor; import org.chorem.lima.ui.celleditor.EmptyCellRenderer; -import org.chorem.lima.ui.celleditor.EntryBookTableCellEditor; import org.jdesktop.swingx.JXDatePicker; import org.jdesktop.swingx.JXTable; import org.jdesktop.swingx.decorator.ColorHighlighter; @@ -95,9 +93,6 @@ //Get new date editor setDefaultEditor(Date.class, new DateTableCellEditor()); - //Get new entry book editor - setDefaultEditor(EntryBook.class, new EntryBookTableCellEditor()); - //Get new account editor setDefaultEditor(Account.class, new AccountTableCellEditor()); @@ -113,9 +108,6 @@ //get new Account renderer for empty cells setDefaultRenderer(Account.class, new EmptyCellRenderer()); - //get new EntryBook renderer for empty cells - setDefaultRenderer(EntryBook.class, new EmptyCellRenderer()); - //highlight financial financial transactions HighlightPredicate predicate = new HighlightPredicate() { @Override @@ -242,11 +234,6 @@ x_tab = 0; } - if (log.isInfoEnabled()) { - log.info("Valeur de x_tab : " + x_tab + "\n" + - "Valeur de y_tab : " + y_tab); - } - //skip all cell while not editable or if end of table add entry or transaction or end of table while (!isCellEditable(y_tab, x_tab) && end) { //if end of row @@ -258,7 +245,8 @@ FinancialTransaction financialTransaction = (FinancialTransaction) object; if (CollectionUtils.isEmpty(financialTransaction.getEntry())) { handler.addEntry(); - setColumnSelectionInterval(1, 1); + //setColumnSelectionInterval(1, 1); + setColumnSelectionInterval(0, 0); } } //if entry @@ -294,7 +282,8 @@ } } else { handler.addEntry(); - setColumnSelectionInterval(1, 1); + //setColumnSelectionInterval(1, 1); + setColumnSelectionInterval(0, 0); y_tab++; // positionne la sélection sur la nouvelle ligne créée setRowSelectionInterval(y_tab, y_tab); @@ -314,18 +303,12 @@ } } - - //focusEdition(); + } } private class MyMouseAdapter extends MouseAdapter { - /*@Override - public void mouseClicked(MouseEvent e){ - focusEdition(); - }*/ - @Override public void mousePressed(MouseEvent e) { if (rowAtPoint(e.getPoint()) == -1) { @@ -334,92 +317,9 @@ } } - //TEST - /*boolean selectAllForActionEvent; - boolean selectAllForMouseEvent; - boolean selectAllForKeyEvent; - @Override public boolean editCellAt(int row, int column, EventObject e) { boolean result = super.editCellAt(row, column, e); - - if (selectAllForMouseEvent || selectAllForActionEvent || selectAllForKeyEvent){ - selectAll(e); - } - - return result; - } - - private void selectAll(EventObject e) { - final Component editor = getEditorComponent(); - - if (editor == null || ! (editor instanceof JTextComponent)){ - return; - } - - if (e == null) { - ((JTextComponent)editor).selectAll(); - return; - } - - // Typing in the cell was used to activate the editor - if (e instanceof KeyEvent && selectAllForKeyEvent) { - ((JTextComponent)editor).selectAll(); - return; - } - - // F2 was used to activate the editor - if (e instanceof ActionEvent && selectAllForActionEvent){ - ((JTextComponent)editor).selectAll(); - return; - } - - // A mouse click was used to activate the editor. - // Generally this is a double click and the second mouse click is - // passed to the editor which would remove the text selection unless - // we use the invokeLater() - if (e instanceof MouseEvent && selectAllForMouseEvent) { - SwingUtilities.invokeLater(new Runnable() { - public void run() { - ((JTextComponent)editor).selectAll(); - } - }); - } - }*/ - - /*public void setSelectAllForEdit(boolean selectAllForEdit){ - setSelectAllForMouseEvent( selectAllForEdit ); - setSelectAllForActionEvent( selectAllForEdit ); - setSelectAllForKeyEvent( selectAllForEdit ); - }*/ - - /* - * Set the Select All property when editing is invoked by the mouse - */ - /*public void setSelectAllForMouseEvent(boolean isSelectAllForMouseEvent){ - selectAllForMouseEvent = isSelectAllForMouseEvent; - }*/ - - /* - * Set the Select All property when editing is invoked by the "F2" key - */ - /*public void setSelectAllForActionEvent(boolean isSelectAllForActionEvent) { - selectAllForActionEvent = isSelectAllForActionEvent; - }*/ - - /* - * Set the Select All property when editing is invoked by - * typing directly into the cell - */ - /*public void setSelectAllForKeyEvent(boolean isSelectAllForKeyEvent){ - selectAllForKeyEvent = isSelectAllForKeyEvent; - }*/ - - //FIN TEST - - @Override - public boolean editCellAt(int row, int column, EventObject e) { - boolean result = super.editCellAt(row, column, e); int lengthCellValue; if (getEditorComponent() != null) if (getEditorComponent() instanceof JXDatePicker) { Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialtransaction/FinancialTransactionTableModel.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialtransaction/FinancialTransactionTableModel.java 2012-07-16 17:09:57 UTC (rev 3531) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialtransaction/FinancialTransactionTableModel.java 2012-07-17 13:35:19 UTC (rev 3532) @@ -28,7 +28,6 @@ import org.chorem.lima.business.api.FinancialTransactionService; import org.chorem.lima.entity.Account; import org.chorem.lima.entity.Entry; -import org.chorem.lima.entity.EntryBook; import org.chorem.lima.entity.FinancialTransaction; import org.chorem.lima.service.LimaServiceFactory; @@ -67,7 +66,7 @@ @Override public int getColumnCount() { - return 9; + return 7; } @Override @@ -80,29 +79,23 @@ result = Date.class; break; case 1: - result = EntryBook.class; + result = String.class; break; case 2: - result = String.class; + result = Account.class; break; case 3: - result = Account.class; + result = String.class; break; case 4: - result = String.class; + result = BigDecimal.class; break; case 5: - result = String.class; + result = BigDecimal.class; break; case 6: result = BigDecimal.class; break; - case 7: - result = BigDecimal.class; - break; - case 8: - result = BigDecimal.class; - break; } return result; } @@ -116,27 +109,21 @@ result = _("lima.ui.financialtransaction.date"); break; case 1: - result = _("lima.ui.financialtransaction.entrybook"); - break; - case 2: result = _("lima.ui.financialtransaction.voucher"); break; - case 3: + case 2: result = _("lima.ui.financialtransaction.account"); break; - case 4: + case 3: result = _("lima.ui.financialtransaction.description"); break; - case 5: - result = _("lima.ui.financialtransaction.letter"); - break; - case 6: + case 4: result = _("lima.ui.financialtransaction.debit"); break; - case 7: + case 5: result = _("lima.ui.financialtransaction.credit"); break; - case 8: + case 6: result = _("lima.ui.financialtransaction.balance"); break; } @@ -168,31 +155,21 @@ result = currentRow.getTransactionDate(); break; case 1: - if (currentRow.getEntryBook() != null) { - result = currentRow.getEntryBook().getCode(); - } else { - result = null; - } - break; - case 2: result = null; //voucher break; - case 3: + case 2: result = null; // account break; - case 4: + case 3: result = null; // description break; - case 5: - result = null; // letter - break; - case 6: + case 4: result = amountDebit; break; - case 7: + case 5: result = amountCredit; break; - case 8: + case 6: result = amountDebit.subtract(amountCredit); break; } @@ -202,32 +179,26 @@ case 0: result = null; // date break; - case 1: // entry book - result = null; - break; - case 2: + case 1: result = currentEntry.getVoucher(); break; - case 3: // account + case 2: // account if (currentEntry.getAccount() != null) { result = currentEntry.getAccount().getAccountNumber(); } else { result = null; } break; - case 4: + case 3: result = currentEntry.getDescription(); break; - case 5: - result = currentEntry.getLettering(); - break; - case 6: + case 4: result = currentEntry.getDebit() ? currentEntry.getAmount() : BigDecimal.ZERO; break; - case 7: + case 5: result = currentEntry.getDebit() ? BigDecimal.ZERO : currentEntry.getAmount(); break; - case 8: + case 6: result = null; break; } @@ -244,11 +215,11 @@ boolean editableCell = false; Object currentRow = transactionAndEntries.get(rowIndex); // cells editable for the financialtransaction row, no cells exclude the date - if (currentRow instanceof FinancialTransaction && (columnIndex == 0 || columnIndex == 1)) { + if (currentRow instanceof FinancialTransaction && (columnIndex == 0)) { editableCell = true; } // cells editable for the entry row, all cells exclude the date - if (currentRow instanceof Entry && !(columnIndex == 0 || columnIndex == 1 || columnIndex == 8)) { + if (currentRow instanceof Entry && !(columnIndex == 0 || columnIndex == 6)) { editableCell = true; } return editableCell; @@ -305,18 +276,6 @@ //update currentFinancialTransaction.setTransactionDate((Date) value); break; - case 1: - // FIXME echatellier 20120515 je ne comprend pas pourquoi - // il n'est pas possible de changer le journal si la transaction - // a des entrées - // update : autorisation si le journal est null au moins - if (currentFinancialTransaction.getEntry() != null - && currentFinancialTransaction.getEntryBook() != null) { - // not authorized to change the value - return; - } - currentFinancialTransaction.setEntryBook((EntryBook) value); - break; } // update transaction @@ -327,7 +286,7 @@ currentFinancialTransaction = currentEntry.getFinancialTransaction(); boolean updateTransaction = false; switch (column) { - case 2: + case 1: String voucher = ((String) value).trim(); int firstEntryRow = getFirstEntry(row); @@ -346,7 +305,7 @@ currentEntry.setVoucher(voucher); } break; - case 3: + case 2: Account account = (Account) value; currentEntry.setAccount(account); // let's copy the account description @@ -365,7 +324,7 @@ currentEntry.setDescription(description1); } break; - case 4: + case 3: String description = ((String) value).trim(); firstEntryRow = getFirstEntry(row); if (row == firstEntryRow) { @@ -383,14 +342,11 @@ currentEntry.setDescription(description); } break; - case 5: - currentEntry.setLettering((String) value); - break; - case 6: + case 4: currentEntry.setAmount((BigDecimal) value); currentEntry.setDebit(true); break; - case 7: + case 5: currentEntry.setAmount((BigDecimal) value); currentEntry.setDebit(false); break; Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialtransaction/FinancialTransactionView.jaxx =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialtransaction/FinancialTransactionView.jaxx 2012-07-16 17:09:57 UTC (rev 3531) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialtransaction/FinancialTransactionView.jaxx 2012-07-17 13:35:19 UTC (rev 3532) @@ -22,7 +22,7 @@ <http://www.gnu.org/licenses/gpl-3.0.html>. #L% --> -<Table name="test"> +<Table> <import> javax.swing.ListSelectionModel Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialtransaction/FinancialTransactionViewHandler.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialtransaction/FinancialTransactionViewHandler.java 2012-07-16 17:09:57 UTC (rev 3531) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialtransaction/FinancialTransactionViewHandler.java 2012-07-17 13:35:19 UTC (rev 3532) @@ -46,6 +46,7 @@ import javax.swing.*; import java.awt.event.ItemEvent; +import java.math.BigDecimal; import java.util.ArrayList; import java.util.Calendar; import java.util.Collection; @@ -351,16 +352,40 @@ String defaultVoucher = null; String defaultDescription = null; + String defaultAccount = null; + //Actual (2012) tva percentage : 19,6% + BigDecimal tvaPercentAdd = new BigDecimal(0.196); + BigDecimal tvaTax = null; if (firstentryBookrow != -1) { - // there is no first entry, grab the voucher and - defaultVoucher = (String) tableModel.getValueAt(firstentryBookrow, 2); - defaultDescription = (String) tableModel.getValueAt(firstentryBookrow, 4); + defaultVoucher = (String) tableModel.getValueAt(firstentryBookrow, 1); + defaultDescription = (String) tableModel.getValueAt(firstentryBookrow, 3); + + //Calculation of tva tax only if first entry is a sale + defaultAccount = (String) tableModel.getValueAt(firstentryBookrow, 2); + if (defaultAccount.equals("410") || defaultAccount.equals("418")){ + if (log.isInfoEnabled()) { + log.info("Calcul de la TVA"); + } + tvaTax = ((BigDecimal)tableModel.getValueAt(firstentryBookrow, 4)).multiply(tvaPercentAdd); + } + } // creates the new entry Entry entry = new EntryImpl(); entry.setVoucher(defaultVoucher); entry.setDescription(defaultDescription); + + //Set tva tax on the debit of the new entry + if (tvaTax != null){ + entry.setAmount(tvaTax); + entry.setDebit(true); + } + + if (log.isInfoEnabled()) { + log.info("tva : " + tvaTax); + } + // check if current row is a transaction or an entry FinancialTransaction currentTransaction = null; Object currentRow = tableModel.getElementAt(indexSelectedRow);
participants (1)
-
mallon@users.chorem.org