Author: vsalaun Date: 2011-06-09 16:05:37 +0200 (Thu, 09 Jun 2011) New Revision: 3165 Url: http://chorem.org/repositories/revision/lima/3165 Log: #347 Updating VatReports (table, model, view, accounting.zargo) Modified: trunk/lima-callao/src/main/xmi/accounting.zargo trunk/lima-swing/src/main/java/org/chorem/lima/ui/vatreports/VatTable.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/vatreports/VatTableModel.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/vatreports/VatView.jaxx trunk/lima-swing/src/main/java/org/chorem/lima/ui/vatreports/VatViewHandler.java Modified: trunk/lima-callao/src/main/xmi/accounting.zargo =================================================================== (Binary files differ) Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/vatreports/VatTable.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/vatreports/VatTable.java 2011-06-09 14:01:42 UTC (rev 3164) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/vatreports/VatTable.java 2011-06-09 14:05:37 UTC (rev 3165) @@ -1,23 +1,20 @@ package org.chorem.lima.ui.vatreports; -import java.awt.event.KeyEvent; -import java.awt.event.KeyListener; -import java.awt.event.MouseEvent; -import java.awt.event.MouseListener; +import java.awt.Color; +import java.awt.Component; import java.math.BigDecimal; -import java.util.Date; +import java.text.SimpleDateFormat; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.chorem.lima.entity.Account; -import org.chorem.lima.entity.EntryBook; -import org.chorem.lima.ui.celleditor.AccountTableCellEditor; +import org.chorem.lima.beans.VatReports; 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.JXTable; +import org.jdesktop.swingx.decorator.ColorHighlighter; +import org.jdesktop.swingx.decorator.ComponentAdapter; +import org.jdesktop.swingx.decorator.HighlightPredicate; +import org.jdesktop.swingx.decorator.Highlighter; public class VatTable extends JXTable { @@ -28,27 +25,47 @@ private static final Log log = LogFactory.getLog(VatTable.class); protected VatViewHandler handler; + + protected VatTableModel model; + + private Highlighter colorTransaction; public VatTable(VatViewHandler handler) { this.handler = handler; - //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()); - //Get new amount editor + model = this.handler.getView().getVatTableModel(); + + //Get new BigDecimal editor setDefaultEditor(BigDecimal.class, new BigDecimalTableCellEditor()); //Get new BigDecimal renderer setDefaultRenderer(BigDecimal.class, new BigDecimalTableCellRenderer()); - //get new String renderer for empty cells - setDefaultRenderer(String.class, new EmptyCellRenderer()); - //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 + //FIXME 2011.06.09 doen't work !!! + addMonthColor(); } + + /* + * Color the background row in grey if the month number is even (pair in french) + */ + protected void addMonthColor() { + HighlightPredicate predicate = new HighlightPredicate() { + @Override + public boolean isHighlighted(Component renderer, + ComponentAdapter adapter) { + VatReports vatReport = model.getElementAt(adapter.row); + SimpleDateFormat simpleDateFormat = new SimpleDateFormat("MM"); + int month = Integer.parseInt(simpleDateFormat.format( + vatReport.getPeriod().getBeginDate())); + // true if month is even + return ((month % 2)==0); + + } + }; + colorTransaction = + new ColorHighlighter(predicate, new Color(222,222,222), null); + addHighlighter(colorTransaction); + } } Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/vatreports/VatTableModel.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/vatreports/VatTableModel.java 2011-06-09 14:01:42 UTC (rev 3164) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/vatreports/VatTableModel.java 2011-06-09 14:05:37 UTC (rev 3165) @@ -2,8 +2,8 @@ import static org.nuiton.i18n.I18n._; +import java.text.SimpleDateFormat; import java.math.BigDecimal; -import java.util.ArrayList; import java.util.Date; import java.util.List; @@ -11,12 +11,13 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.chorem.lima.beans.VatReports; +import org.chorem.lima.business.LimaException; +import org.chorem.lima.business.ReportServiceMonitorable; import org.chorem.lima.business.ServiceListener; -import org.chorem.lima.entity.Account; -import org.chorem.lima.entity.EntryBook; -import org.chorem.lima.entity.FinancialPeriod; import org.chorem.lima.entity.FiscalPeriod; -import org.chorem.lima.entity.Letter; +import org.chorem.lima.service.LimaServiceFactory; +import org.chorem.lima.util.ErrorHelper; public class VatTableModel extends AbstractTableModel implements ServiceListener { @@ -27,19 +28,38 @@ private static final Log log = LogFactory .getLog(VatTableModel.class); + /** Services. */ + protected ReportServiceMonitorable reportService; + /** selected financial period */ protected FiscalPeriod selectedFiscalPeriod; /** data cache */ - protected List<Object> cacheDataList; + protected List<VatReports> cacheDataList; + protected VatReports vatReportsCache; public VatTableModel() { - // + reportService = + LimaServiceFactory.getInstance().getService( + ReportServiceMonitorable.class); } - protected List<Object> getDataList() { - List<Object> results = new ArrayList<Object>(); + protected List<VatReports> getDataList() { + List<VatReports> results = null; + + if (selectedFiscalPeriod != null) { + try { + results = reportService.generateVat(selectedFiscalPeriod); + } + catch (LimaException eee) { + if (log.isErrorEnabled()) { + log.debug("Can't update model", eee); + } + ErrorHelper.showErrorDialog("Can't get VAT list", eee); + } + } + return results; } @@ -114,11 +134,55 @@ public int getColumnCount() { return 8; } + + public VatReports getElementAt(int row){ + VatReports currentRow = (VatReports) cacheDataList.get(row); + return currentRow; + } @Override - public Object getValueAt(int rowIndex, int columnIndex) { - // TODO Auto-generated method stub - return null; + public Object getValueAt(int row, int column) { + Object result = null; + VatReports currentRow = (VatReports) cacheDataList.get(row); + //get entries for the period for the current row + + SimpleDateFormat simpleDateFormat = new SimpleDateFormat("dd MMM yyyy"); + + try { + switch (column) { + case 0: + //result = currentRow.getDate(); //date + result = simpleDateFormat.format(currentRow.getPeriod().getBeginDate()) + + " - " + simpleDateFormat.format(currentRow.getPeriod().getEndDate()); + break; + case 1: + result = currentRow.getAmountCollected(); //tva collectee + break; + case 2: + result = currentRow.getAmountDeductible(); //tva deductible + break; + case 3: + result = currentRow.getAmountDue(); //tva due + break; + case 4: + result = currentRow.getAmountCredit(); //credit de tva + break; + case 5: + result = currentRow.getAmountRepayments(); //remboursemments + break; + case 6: + result = currentRow.getAmountRemainingCredit(); //credit restant + break; + case 7: + result = currentRow.getAmountPayable(); //tva a payer + break; + } + } + catch (Exception eee) { + log.debug("Can't get entries", eee); + } + + return result; } public void setFiscalPeriod(FiscalPeriod fiscalPeriod){ Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/vatreports/VatView.jaxx =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/vatreports/VatView.jaxx 2011-06-09 14:01:42 UTC (rev 3164) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/vatreports/VatView.jaxx 2011-06-09 14:05:37 UTC (rev 3165) @@ -32,6 +32,10 @@ onActionPerformed="getVatTableModel().setFiscalPeriod((FiscalPeriod)fiscalPeriodComboBox.getSelectedItem())" editable="false"/> </cell> + <cell> + <JButton id="editVatButton" text="lima.reports.vat" + onActionPerformed="getHandler().editVat()"/> + </cell> </row> <row> <cell fill="both" weightx="1" weighty="1" rows="3" columns="11"> Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/vatreports/VatViewHandler.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/vatreports/VatViewHandler.java 2011-06-09 14:01:42 UTC (rev 3164) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/vatreports/VatViewHandler.java 2011-06-09 14:05:37 UTC (rev 3165) @@ -21,6 +21,23 @@ this.view = view; } + /** + * @return VatView + */ + public VatView getView() { + return view; + } + + /** + * Edit VAT document + */ + public void editVat() { + + } + + /** + * Refresh VatTableModel + */ public void refresh(){ tableModel = view.getVatTableModel(); tableModel.refresh();