r3200 - in trunk/lima-swing/src/main/java/org/chorem/lima/ui: . vatchart vatreports
Author: vsalaun Date: 2011-07-05 18:19:45 +0200 (Tue, 05 Jul 2011) New Revision: 3200 Url: http://chorem.org/repositories/revision/lima/3200 Log: #347 rename Vat to VatReport add VatChart Added: trunk/lima-swing/src/main/java/org/chorem/lima/ui/vatchart/ trunk/lima-swing/src/main/java/org/chorem/lima/ui/vatchart/VatChartTreeTable.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/vatchart/VatChartTreeTableModel.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/vatchart/VatChartView.jaxx trunk/lima-swing/src/main/java/org/chorem/lima/ui/vatchart/VatChartViewHandler.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/vatreports/VatReportTable.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/vatreports/VatReportTableModel.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/vatreports/VatReportView.jaxx trunk/lima-swing/src/main/java/org/chorem/lima/ui/vatreports/VatReportViewHandler.java Removed: 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-swing/src/main/java/org/chorem/lima/ui/MainView.jaxx trunk/lima-swing/src/main/java/org/chorem/lima/ui/MainViewHandler.java Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/MainView.jaxx =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/MainView.jaxx 2011-07-05 10:34:37 UTC (rev 3199) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/MainView.jaxx 2011-07-05 16:19:45 UTC (rev 3200) @@ -168,6 +168,8 @@ actionIcon='charts-financialperiod'/> <JMenuItem text="lima.charts.financialstatement" onActionPerformed='getHandler().showFinancialStatementView(this)' actionIcon='charts-financialstatements'/> + <JMenuItem text="lima.charts.vat" onActionPerformed='getHandler().showVatChartView(this)' + actionIcon='charts-financialstatements'/> </JMenu> <JMenu text="lima.entries" mnemonic="{'E'}"> @@ -191,7 +193,7 @@ actionIcon='reports-ledger'/> <JMenuItem text="lima.reports.financialstatement" onActionPerformed='getHandler().showFinancialStatementReportsView(this)' actionIcon='reports-financialstatement'/> - <JMenuItem text="lima.reports.vat" onActionPerformed='getHandler().showVatView(this)' + <JMenuItem text="lima.reports.vat" onActionPerformed='getHandler().showVatReportView(this)' actionIcon='reports-financialstatement'/> </JMenu> Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/MainViewHandler.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/MainViewHandler.java 2011-07-05 10:34:37 UTC (rev 3199) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/MainViewHandler.java 2011-07-05 16:19:45 UTC (rev 3200) @@ -54,7 +54,8 @@ import org.chorem.lima.ui.importexport.ImportExport; import org.chorem.lima.ui.ledger.LedgerView; import org.chorem.lima.ui.lettering.LetteringView; -import org.chorem.lima.ui.vatreports.VatView; +import org.chorem.lima.ui.vatchart.VatChartView; +import org.chorem.lima.ui.vatreports.VatReportView; import org.chorem.lima.util.ErrorHelper; /** @@ -337,9 +338,19 @@ FinancialStatementChartView financialStatementView = new FinancialStatementChartView(mainView); mainView.showTab(_("lima.charts.financialstatement"), financialStatementView); - } + } /** + * Show vat chart to generate vat document + * @param rootContext + */ + public void showVatChartView(JAXXContext rootContext){ + MainView mainView = getUI(rootContext); + VatChartView vatChartView = new VatChartView(mainView); + mainView.showTab(_("lima.charts.financialstatement"), vatChartView); + } + + /** * Show account table report to view an account on a period * @param rootContext */ @@ -407,10 +418,10 @@ mainView.showTab(_("lima.reports.financialstatement"), financialStatementReportView); } - public void showVatView(JAXXContext rootContext) { + public void showVatReportView(JAXXContext rootContext) { MainView mainView = getUI(rootContext); - VatView vatView = new VatView(mainView); - mainView.showTab(_("lima.reports.vat"), vatView); + VatReportView vatReportView = new VatReportView(mainView); + mainView.showTab(_("lima.reports.vat"), vatReportView); } Added: trunk/lima-swing/src/main/java/org/chorem/lima/ui/vatchart/VatChartTreeTable.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/vatchart/VatChartTreeTable.java (rev 0) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/vatchart/VatChartTreeTable.java 2011-07-05 16:19:45 UTC (rev 3200) @@ -0,0 +1,77 @@ +package org.chorem.lima.ui.vatchart; + +import java.awt.event.KeyEvent; +import java.awt.event.KeyListener; +import java.awt.event.MouseEvent; +import java.awt.event.MouseListener; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.jdesktop.swingx.JXTreeTable; + +public class VatChartTreeTable extends JXTreeTable + implements KeyListener, MouseListener { + + /** serialVersionUID. */ + private static final long serialVersionUID = 3960840343197845825L; + + /** log. */ + private static final Log log = LogFactory + .getLog(VatChartTreeTable.class); + + protected VatChartViewHandler handler; + + public VatChartTreeTable(VatChartViewHandler handler) { + this.handler = handler; + + addKeyListener(this); + addMouseListener(this); + + } + + @Override + public void mouseClicked(MouseEvent e) { + } + + @Override + public void mousePressed(MouseEvent e) { + if (this.rowAtPoint(e.getPoint()) == -1) { + this.clearSelection(); + } + } + + @Override + public void mouseReleased(MouseEvent e) { + } + + @Override + public void mouseEntered(MouseEvent e) { + } + + @Override + public void mouseExited(MouseEvent e) { + } + + @Override + public void keyTyped(KeyEvent e) { + } + + /** + * for each action combination key are think + * for extend keyboard and laptop keyboard + */ + @Override + public void keyPressed(KeyEvent e) { + // clear row selection with the key: escape + if (e.getKeyCode() == KeyEvent.VK_ESCAPE) { + if (!this.isEditing()) { + this.clearSelection(); + } + } + } + + @Override + public void keyReleased(KeyEvent e) { + } + +} Added: trunk/lima-swing/src/main/java/org/chorem/lima/ui/vatchart/VatChartTreeTableModel.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/vatchart/VatChartTreeTableModel.java (rev 0) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/vatchart/VatChartTreeTableModel.java 2011-07-05 16:19:45 UTC (rev 3200) @@ -0,0 +1,232 @@ +package org.chorem.lima.ui.vatchart; + +import static org.nuiton.i18n.I18n._; +import java.util.List; +import javax.swing.tree.TreePath; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.chorem.lima.business.FinancialStatementServiceMonitorable; +import org.chorem.lima.business.LimaException; +import org.chorem.lima.entity.FinancialStatement; +import org.chorem.lima.entity.FinancialStatementImpl; +import org.chorem.lima.service.LimaServiceFactory; +import org.jdesktop.swingx.treetable.AbstractTreeTableModel; + +public class VatChartTreeTableModel extends AbstractTreeTableModel { + + /** log. */ + private static final Log log = LogFactory.getLog(VatChartViewHandler.class); + + /** Services. */ + protected final FinancialStatementServiceMonitorable financialStatementService; + + /** + * Model constructor. Init account service used here. + */ + public VatChartTreeTableModel() { + + financialStatementService = + LimaServiceFactory.getInstance().getService( + FinancialStatementServiceMonitorable.class); + } + + + @Override + public int getColumnCount() { + return 5; + } + + @Override + public String getColumnName(int column) { + String res = null; + switch (column) { + case 0: + res = _("lima.table.label"); + break; + case 1: + res = _("lima.table.debitcredit"); + break; + case 2: + res = _("lima.table.debit"); + break; + case 3: + res = _("lima.table.credit"); + break; + case 4: + res = _("lima.table.provisiondeprecationamount"); + break; + } + return res; + } + + @Override + public int getChildCount(Object node) { + int result = 0; + if (node == getRoot()) { + try { + result = financialStatementService. + getChildrenFinancialStatement(null).size(); + } catch (LimaException eee) { + log.debug("Can't count child", eee); + } + } + else { + FinancialStatement parentFinancialStatementHeader = + (FinancialStatement) node; + try { + result = financialStatementService.getChildrenFinancialStatement( + parentFinancialStatementHeader).size(); + } catch (LimaException eee) { + log.debug("Can't count child", eee); + } + } + return result; + } + + @Override + public Object getChild(Object parent, int index) { + Object result = null; + if (parent == getRoot()) { + try { + List<FinancialStatement> financialStatements = + financialStatementService.getChildrenFinancialStatement(null); + result = financialStatements.get(index); + } catch (LimaException eee) { + log.debug("Can't get child", eee); + } + } + else { + FinancialStatement parentFinancialStatement = + (FinancialStatement) parent; + try { + List<FinancialStatement> financialStatements = financialStatementService. + getChildrenFinancialStatement(parentFinancialStatement); + result = financialStatements.get(index); + } catch (LimaException eee) { + log.debug("Can't get child", eee); + } + } + return result; + } + + @Override + public int getIndexOfChild(Object parent, Object child) { + int result = 0; + + if (parent == getRoot()) { + try { + List<FinancialStatement> financialStatements = + financialStatementService.getChildrenFinancialStatement(null); + result = financialStatements.indexOf(child); + } catch (LimaException eee) { + log.debug("Can't get index child", eee); + } + } + else { + FinancialStatement parentFinancialStatement = + (FinancialStatement) parent; + try { + List<FinancialStatement> financialStatements = financialStatementService. + getChildrenFinancialStatement(parentFinancialStatement); + result = financialStatements.indexOf(child); + } catch (LimaException eee) { + log.debug("Can't get index child", eee); + } + } + return result; + } + + @Override + public Object getValueAt(Object node, int column) { + Object result = "n/a"; + FinancialStatement financialStatement = (FinancialStatement) node; + switch (column) { + case 0: + result = financialStatement.getLabel(); + break; + case 1: + result = financialStatement.getAccounts(); + break; + case 2: + result = financialStatement.getDebitAccounts(); + break; + case 3: + result = financialStatement.getCreditAccounts(); + break; + case 4: + result = financialStatement.getProvisionDeprecationAccounts(); + break; + } + return result; + } + + @Override + public boolean isCellEditable(Object node, int column) { + return false; + } + + @Override + public boolean isLeaf(Object node) { + return getChildCount(node) == 0; + } + + + /** + * Refresh FinancialStatementChart. + * + */ + public void refreshTree() throws LimaException { + + modelSupport.fireNewRoot(); + } + + + /** + * Add FinancialStatement(path can be null). + * + * @param path + * @param account + * @throws LimaException + */ + public void addFinancialStatement(TreePath path, FinancialStatement financialStatement) throws LimaException { + // Calling account service + FinancialStatement parentFinancialStatementHeader = + (FinancialStatement) path.getLastPathComponent(); + if (parentFinancialStatementHeader == getRoot()) { + parentFinancialStatementHeader = null; + } + financialStatementService.createFinancialStatement( + parentFinancialStatementHeader, financialStatement); + modelSupport.fireTreeStructureChanged(path); + } + + + /** + * Update financialStatement + * + * @param path + * @param account + * @throws LimaException + */ + public void updateFinancialStatement(TreePath path, FinancialStatement financialStatement) throws LimaException { + + financialStatementService.updateFinancialStatement(financialStatement); + modelSupport.fireTreeStructureChanged(path); + } + + + /** + * Remove financialStatement + * + * @param path + * @param object + * @throws LimaException + */ + public void removeFinancialStatementObject(TreePath path, FinancialStatement financialStatement) throws LimaException { + // Calling account service + int index = getIndexOfChild( + path.getParentPath().getLastPathComponent(), financialStatement); + financialStatementService.removeFinancialStatement(financialStatement); + modelSupport.fireChildRemoved(path.getParentPath(), index, financialStatement); + } +} Added: trunk/lima-swing/src/main/java/org/chorem/lima/ui/vatchart/VatChartView.jaxx =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/vatchart/VatChartView.jaxx (rev 0) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/vatchart/VatChartView.jaxx 2011-07-05 16:19:45 UTC (rev 3200) @@ -0,0 +1,26 @@ +<Table> + + <VatChartViewHandler id="handler" javaBean="new VatChartViewHandler(this)" /> + <Boolean id="selectedRow" javaBean="false" /> + + <script> + <![CDATA[ + //getHandler().init(); + ]]> + </script> + + <row> + <cell fill="both" weightx="1" weighty="1" rows='6'> + <JScrollPane> + <VatChartTreeTable id="treeTable" + constructorParams="getHandler()" + selectionMode="{ListSelectionModel.SINGLE_SELECTION}" + treeTableModel="{new org.chorem.lima.ui.vatchart.VatChartTreeTableModel()}" + highlighters="{org.jdesktop.swingx.decorator.HighlighterFactory.createSimpleStriping(new java.awt.Color(222,222,222))}" /> + <javax.swing.ListSelectionModel + javaBean="getTreeTable().getSelectionModel()" + onValueChanged="setSelectedRow(treeTable.getSelectedRow() != -1)"/> + </JScrollPane> + </cell> + </row> +</Table> \ No newline at end of file Added: trunk/lima-swing/src/main/java/org/chorem/lima/ui/vatchart/VatChartViewHandler.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/vatchart/VatChartViewHandler.java (rev 0) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/vatchart/VatChartViewHandler.java 2011-07-05 16:19:45 UTC (rev 3200) @@ -0,0 +1,70 @@ +package org.chorem.lima.ui.vatchart; + +import static org.nuiton.i18n.I18n._; + +import javax.swing.JOptionPane; +import javax.swing.tree.TreePath; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.chorem.lima.business.FinancialStatementServiceMonitorable; +import org.chorem.lima.business.ImportServiceMonitorable; +import org.chorem.lima.business.LimaBusinessException; +import org.chorem.lima.business.LimaException; +import org.chorem.lima.business.ServiceListener; +import org.chorem.lima.entity.FinancialStatement; +import org.chorem.lima.entity.FinancialStatementImpl; +import org.chorem.lima.enums.FinancialStatementsChartEnum; +import org.chorem.lima.enums.ImportExportEnum; +import org.chorem.lima.service.LimaServiceFactory; +import org.chorem.lima.ui.financialstatementchart.FinancialStatementHeaderForm; +import org.chorem.lima.ui.financialstatementchart.FinancialStatementMovementForm; +import org.chorem.lima.ui.importexport.ImportExport; +import org.chorem.lima.util.DialogHelper; +import org.chorem.lima.util.ErrorHelper; +import org.jdesktop.swingx.JXTreeTable; + +public class VatChartViewHandler implements ServiceListener { + + /** log. */ + private static final Log log = LogFactory.getLog(VatChartViewHandler.class); + + protected FinancialStatementServiceMonitorable financialStatementService; + + protected VatChartView view; + + protected VatChartViewHandler(VatChartView view) { + this.view = view; + + financialStatementService = + LimaServiceFactory.getInstance().getService( + FinancialStatementServiceMonitorable.class); + LimaServiceFactory.getInstance().getService( + ImportServiceMonitorable.class).addListener(this); + } + + public void refresh(){ + JXTreeTable treeTable = view.getTreeTable(); + VatChartTreeTableModel treeTableModel = + (VatChartTreeTableModel) treeTable.getTreeTableModel(); + try { + treeTableModel.refreshTree(); + } catch (LimaException eee) { + if(log.isDebugEnabled()){ + log.debug("Can't refresh model", eee); + } + } + //refresh view + view.repaint(); + } + + @Override + public void notifyMethod(String serviceName, String methodeName) { + /*if (methodeName.contains("FinancialStatements") + || methodeName.contains("importAll") + || methodeName.contains("importAs")){ + refresh(); + }*/ + } + + +} Added: trunk/lima-swing/src/main/java/org/chorem/lima/ui/vatreports/VatReportTable.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/vatreports/VatReportTable.java (rev 0) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/vatreports/VatReportTable.java 2011-07-05 16:19:45 UTC (rev 3200) @@ -0,0 +1,69 @@ +package org.chorem.lima.ui.vatreports; + +import java.awt.Color; +import java.awt.Component; +import java.math.BigDecimal; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.chorem.lima.entity.FinancialPeriod; +import org.chorem.lima.ui.celleditor.BigDecimalTableCellEditor; +import org.chorem.lima.ui.celleditor.BigDecimalTableCellRenderer; +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 VatReportTable extends JXTable { + + /** serialVersionUID. */ + private static final long serialVersionUID = 4042515416850867834L; + + /** log. */ + private static final Log log = LogFactory.getLog(VatReportTable.class); + + protected VatReportViewHandler handler; + + protected VatReportTableModel model; + + private Highlighter colorTransaction; + + public VatReportTable(VatReportViewHandler handler) { + + this.handler = handler; + + model = this.handler.getView().getVatReportTableModel(); + + //Get new BigDecimal editor + setDefaultEditor(BigDecimal.class, new BigDecimalTableCellEditor()); + //Get new BigDecimal renderer + setDefaultRenderer(BigDecimal.class, new BigDecimalTableCellRenderer()); + + //highlight financial financial transactions + //FIXME 2011.06.09 doesn'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) { + Object object = model.getElementAt(adapter.row); + if (object instanceof FinancialPeriod) { + return true; + } else { + return false; + } + } + }; + colorTransaction = + new ColorHighlighter(predicate, new Color(222,222,222), null); + addHighlighter(colorTransaction); + } + +} Added: trunk/lima-swing/src/main/java/org/chorem/lima/ui/vatreports/VatReportTableModel.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/vatreports/VatReportTableModel.java (rev 0) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/vatreports/VatReportTableModel.java 2011-07-05 16:19:45 UTC (rev 3200) @@ -0,0 +1,315 @@ +package org.chorem.lima.ui.vatreports; + +import static org.nuiton.i18n.I18n._; + +import java.text.SimpleDateFormat; +import java.math.BigDecimal; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +import javax.swing.table.AbstractTableModel; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.chorem.lima.beans.BalanceTrial; +import org.chorem.lima.beans.ReportsDatas; +import org.chorem.lima.business.LimaException; +import org.chorem.lima.business.ReportServiceMonitorable; +import org.chorem.lima.business.ServiceListener; +import org.chorem.lima.business.utils.EntryComparator; +import org.chorem.lima.entity.Account; +import org.chorem.lima.entity.Entry; +import org.chorem.lima.entity.FinancialPeriod; +import org.chorem.lima.entity.FiscalPeriod; +import org.chorem.lima.service.LimaServiceFactory; +import org.chorem.lima.util.ErrorHelper; +import org.nuiton.topia.TopiaException; + +public class VatReportTableModel extends AbstractTableModel implements ServiceListener { + + /** serialVersionUID. */ + private static final long serialVersionUID = -6301817853711018389L; + + /** log. */ + private static final Log log = LogFactory + .getLog(VatReportTableModel.class); + + /** Services. */ + protected ReportServiceMonitorable reportService; + + /** selected financial period */ + protected FiscalPeriod selectedFiscalPeriod; + + /** data cache */ + protected List<Object> cacheDataList; + + + public VatReportTableModel() { + reportService = + LimaServiceFactory.getInstance().getService( + ReportServiceMonitorable.class); + } + + protected List<Object> getDataList() throws TopiaException { + List<Object> finalresults = new ArrayList<Object>(); + + if (selectedFiscalPeriod != null) { + try { + List<Object> results = reportService.generateVat(selectedFiscalPeriod); + + for (int index=0; index<results.size(); index++) { + if (results.get(index) instanceof BalanceTrial) { + if (((BalanceTrial)results.get(index)).getReportsDatas() != null){ + for (ReportsDatas reportsDatas : ((BalanceTrial)results.get(index)).getReportsDatas()) { + //reports datas + finalresults.add(reportsDatas); + List<Entry> entries = (List<Entry>) reportsDatas.getListEntry(); + if (entries != null){ + Collections.sort(entries, new EntryComparator()); + for (Entry entry : entries) { + //entry + finalresults.add(entry); + } + } + } + } + } else { + //financial period + finalresults.add(results.get(index)); + } + } + } + catch (LimaException eee) { + if (log.isErrorEnabled()) { + log.debug("Can't update model", eee); + } + ErrorHelper.showErrorDialog("Can't get VAT list", eee); + } + } + return finalresults; + } + + public void refresh(){ + try { + cacheDataList = getDataList(); + } catch (TopiaException eee) { + if (log.isErrorEnabled()) { + log.debug("Can't update model", eee); + } + ErrorHelper.showErrorDialog("Can't get VAT list", eee); + } + fireTableDataChanged(); + } + + @Override + public Class<?> getColumnClass(int column) { + + Class<?> result = null; + + switch (column) { + case 0: + result = String.class; + break; + case 1: + result = Account.class; + break; + case 2: + result = String.class; + break; + case 3: + result = String.class; + break; + case 4: + result = BigDecimal.class; + break; + case 5: + result = BigDecimal.class; + break; + case 6: + result = BigDecimal.class; + break; + } + + return result; + } + + @Override + public String getColumnName(int column) { + String result = "n/a"; + + switch (column) { + case 0: + result = _("lima.table.date"); //date + break; + case 1: + result = "compte"; //tva collectee + break; + case 2: + result = "piece comptable"; //tva due + break; + case 3: + result = "description"; //credit de tva + break; + case 4: + result = "debit"; //remboursemments + break; + case 5: + result = "credit"; //credit restant + break; + case 6: + result = "solde"; //tva a payer + break; + } + + return result; + } + + @Override + public int getRowCount() { + int result = 0; + + if (cacheDataList != null) { + result = cacheDataList.size(); + } + + return result; + } + + @Override + public int getColumnCount() { + return 7; + } + + public Object getElementAt(int row){ + Object currentRow = cacheDataList.get(row); + return currentRow; + } + + @Override + public Object getValueAt(int row, int column) { + Object result = null; + // just prevent too much result + if (cacheDataList != null) { + result = cacheDataList.get(row); + SimpleDateFormat simpleDateFormat = new SimpleDateFormat("dd MMM yyyy"); + if (result instanceof FinancialPeriod) { + FinancialPeriod fp = (FinancialPeriod) result; + + switch (column) { + case 0: + result = simpleDateFormat.format(fp.getBeginDate()) + + " - " + simpleDateFormat.format(fp.getEndDate()); + break; + case 1: + result = null; + break; + case 2: + result = null; // voucher + break; + case 3: + result = null; // description + break; + case 4: + result = null; // position + break; + case 5: + result = null; + break; + case 6: + result = null; + break; + } + } + else if (result instanceof ReportsDatas) { + ReportsDatas currentRow = (ReportsDatas)result; + BigDecimal amountDebit = currentRow.getAmountDebit(); + BigDecimal amountCredit = currentRow.getAmountCredit(); + + switch (column) { + case 0: + result = null; // date + break; + case 1: + if (currentRow.getAccount() != null){ + result = currentRow.getAccount().getAccountNumber() + + " - " + currentRow.getAccount().getLabel(); + } + else { + result = null; + } + break; + case 2: + result = null; // voucher + break; + case 3: + result = null; // description + break; + case 4: + result = amountDebit; // position + break; + case 5: + result = amountCredit; + break; + case 6: + result = amountDebit.subtract(amountCredit); + break; + } + } + else if (result instanceof Entry) { + Entry currentRow = (Entry)result; + BigDecimal amountDebit = BigDecimal.ZERO, + amountCredit = BigDecimal.ZERO; + if (currentRow.getDebit()){ + amountDebit = currentRow.getAmount(); + } + else { + amountCredit = currentRow.getAmount(); + } + + switch (column) { + case 0: // date + result = simpleDateFormat. + format(currentRow.getFinancialTransaction().getTransactionDate()); + break; + case 1 : // account + result = null; + break; + case 2: // description + result = currentRow.getVoucher(); + break; + case 3: + result = currentRow.getDescription(); + break; + case 4: + result = amountDebit; + break; + case 5: + result = amountCredit; + break; + case 6: + result = amountDebit.subtract(amountCredit); + break; + } + } + } + + return result; + } + + public FiscalPeriod getFiscalPeriod() { + return selectedFiscalPeriod; + } + + public void setFiscalPeriod(FiscalPeriod fiscalPeriod){ + selectedFiscalPeriod = fiscalPeriod; + refresh(); + } + + @Override + public void notifyMethod(String serviceName, String methodeName) { + // TODO Auto-generated method stub + + } + +} Added: trunk/lima-swing/src/main/java/org/chorem/lima/ui/vatreports/VatReportView.jaxx =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/vatreports/VatReportView.jaxx (rev 0) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/vatreports/VatReportView.jaxx 2011-07-05 16:19:45 UTC (rev 3200) @@ -0,0 +1,58 @@ +<Table> + <VatReportViewHandler id="handler" javaBean="new VatReportViewHandler(this)" /> + <Boolean id="selectedRow" javaBean="false" /> + + <script> + <![CDATA[ + import org.chorem.lima.entity.FiscalPeriod; + import org.chorem.lima.entity.FinancialPeriod; + import org.chorem.lima.ui.combobox.FiscalPeriodComboBoxModel; + import org.chorem.lima.ui.financialtransaction.FinancialPeriodComboBox; + import org.chorem.lima.ui.combobox.FinancialPeriodComboBoxRenderer; + import org.chorem.lima.ui.combobox.FiscalPeriodComboBoxRenderer; + import org.chorem.lima.ui.vatreports.VatTableModel; + import org.chorem.lima.ui.vatreports.VatTable; + + void $afterCompleteSetup() { + getHandler().refresh(); + } + + ]]> + </script> + + <row weightx="1" weighty="0" anchor="center"> + <cell anchor="east"> + <JLabel id="fiscalPeriodLabel" text="lima.charts.fiscalyear"/> + </cell> + <cell anchor="west"> + <org.chorem.lima.ui.combobox.FiscalPeriodComboBoxModel id="modelFiscalPeriod"/> + <JComboBox id="fiscalPeriodComboBox" + model="{getModelFiscalPeriod()}" + renderer="{new FiscalPeriodComboBoxRenderer()}" + onActionPerformed="getVatReportTableModel().setFiscalPeriod((FiscalPeriod)fiscalPeriodComboBox.getSelectedItem())" + editable="false"/> + </cell> + <cell> + <EnumEditor id='DocumentEditor' + constructorParams='org.chorem.lima.business.utils.FormatsEnum.class'/> + </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"> + <JScrollPane> + <org.chorem.lima.ui.vatreports.VatReportTableModel + id="vatReportTableModel"/> + <org.chorem.lima.ui.vatreports.VatReportTable + id="vatReportTable" sortable="false" rowHeight="22" + constructorParams="getHandler()" model="{getVatReportTableModel()}" + selectionMode="{ListSelectionModel.SINGLE_SELECTION}" /> + <javax.swing.ListSelectionModel javaBean="getVatReportTable().getSelectionModel()" + onValueChanged="setSelectedRow(vatReportTable.getSelectedRow() != -1)"/> + </JScrollPane> + </cell> + </row> +</Table> \ No newline at end of file Added: trunk/lima-swing/src/main/java/org/chorem/lima/ui/vatreports/VatReportViewHandler.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/vatreports/VatReportViewHandler.java (rev 0) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/vatreports/VatReportViewHandler.java 2011-07-05 16:19:45 UTC (rev 3200) @@ -0,0 +1,83 @@ +package org.chorem.lima.ui.vatreports; + +import java.awt.Desktop; +import java.io.IOException; +import java.net.URI; +import java.net.URISyntaxException; +import java.text.SimpleDateFormat; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.chorem.lima.LimaConfig; +import org.chorem.lima.business.DocumentServiceMonitorable; +import org.chorem.lima.business.HttpServerServiceMonitorable; +import org.chorem.lima.business.utils.DocumentsEnum; +import org.chorem.lima.service.LimaServiceFactory; + +public class VatReportViewHandler { + /** log. */ + private static final Log log = + LogFactory.getLog(VatReportViewHandler.class); + + protected VatReportView view; + + protected VatReportTable table; + + protected VatReportTableModel tableModel; + + protected DocumentServiceMonitorable documentService; + + private static SimpleDateFormat dateFormat = + new SimpleDateFormat("yyyy-MM-dd"); + + protected int port; + + protected VatReportViewHandler(VatReportView view) { + this.view = view; + + port = LimaServiceFactory.getInstance().getService( + HttpServerServiceMonitorable.class).getHttpPort(); + + documentService = + LimaServiceFactory.getInstance().getService( + DocumentServiceMonitorable.class); + } + + /** + * @return VatView + */ + public VatReportView getView() { + return view; + } + + /** + * Edit VAT document + */ + public void editVat() { + if (tableModel.getFiscalPeriod() != null){ + String address = LimaConfig.getInstance().getHostAdress(); + + try { + String url = "http://"+address+":"+port+"/?beginDate=" + + dateFormat.format(tableModel.getFiscalPeriod().getBeginDate()) + + "&endDate="+dateFormat.format(tableModel.getFiscalPeriod().getEndDate()) + + "&format=.pdf&model=" + + DocumentsEnum.VAT.getFileName(); + Desktop.getDesktop().browse(new URI(url)); + } catch (IOException e) { + log.error("Can't open browser", e); + } catch (URISyntaxException e) { + log.error("Can't create news URI", e); + } + } + } + + /** + * Refresh VatTableModel + */ + public void refresh(){ + tableModel = view.getVatReportTableModel(); + tableModel.refresh(); + } + +} Deleted: 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-07-05 10:34:37 UTC (rev 3199) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/vatreports/VatTable.java 2011-07-05 16:19:45 UTC (rev 3200) @@ -1,69 +0,0 @@ -package org.chorem.lima.ui.vatreports; - -import java.awt.Color; -import java.awt.Component; -import java.math.BigDecimal; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.chorem.lima.entity.FinancialPeriod; -import org.chorem.lima.ui.celleditor.BigDecimalTableCellEditor; -import org.chorem.lima.ui.celleditor.BigDecimalTableCellRenderer; -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 { - - /** serialVersionUID. */ - private static final long serialVersionUID = 4042515416850867834L; - - /** log. */ - 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; - - model = this.handler.getView().getVatTableModel(); - - //Get new BigDecimal editor - setDefaultEditor(BigDecimal.class, new BigDecimalTableCellEditor()); - //Get new BigDecimal renderer - setDefaultRenderer(BigDecimal.class, new BigDecimalTableCellRenderer()); - - //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) { - Object object = model.getElementAt(adapter.row); - if (object instanceof FinancialPeriod) { - return true; - } else { - return false; - } - } - }; - colorTransaction = - new ColorHighlighter(predicate, new Color(222,222,222), null); - addHighlighter(colorTransaction); - } - -} Deleted: 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-07-05 10:34:37 UTC (rev 3199) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/vatreports/VatTableModel.java 2011-07-05 16:19:45 UTC (rev 3200) @@ -1,315 +0,0 @@ -package org.chorem.lima.ui.vatreports; - -import static org.nuiton.i18n.I18n._; - -import java.text.SimpleDateFormat; -import java.math.BigDecimal; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; - -import javax.swing.table.AbstractTableModel; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.chorem.lima.beans.BalanceTrial; -import org.chorem.lima.beans.ReportsDatas; -import org.chorem.lima.business.LimaException; -import org.chorem.lima.business.ReportServiceMonitorable; -import org.chorem.lima.business.ServiceListener; -import org.chorem.lima.business.utils.EntryComparator; -import org.chorem.lima.entity.Account; -import org.chorem.lima.entity.Entry; -import org.chorem.lima.entity.FinancialPeriod; -import org.chorem.lima.entity.FiscalPeriod; -import org.chorem.lima.service.LimaServiceFactory; -import org.chorem.lima.util.ErrorHelper; -import org.nuiton.topia.TopiaException; - -public class VatTableModel extends AbstractTableModel implements ServiceListener { - - /** serialVersionUID. */ - private static final long serialVersionUID = -6301817853711018389L; - - /** log. */ - 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; - - - public VatTableModel() { - reportService = - LimaServiceFactory.getInstance().getService( - ReportServiceMonitorable.class); - } - - protected List<Object> getDataList() throws TopiaException { - List<Object> finalresults = new ArrayList<Object>(); - - if (selectedFiscalPeriod != null) { - try { - List<Object> results = reportService.generateVat(selectedFiscalPeriod); - - for (int index=0; index<results.size(); index++) { - if (results.get(index) instanceof BalanceTrial) { - if (((BalanceTrial)results.get(index)).getReportsDatas() != null){ - for (ReportsDatas reportsDatas : ((BalanceTrial)results.get(index)).getReportsDatas()) { - //reports datas - finalresults.add(reportsDatas); - List<Entry> entries = (List<Entry>) reportsDatas.getListEntry(); - if (entries != null){ - Collections.sort(entries, new EntryComparator()); - for (Entry entry : entries) { - //entry - finalresults.add(entry); - } - } - } - } - } else { - //financial period - finalresults.add(results.get(index)); - } - } - } - catch (LimaException eee) { - if (log.isErrorEnabled()) { - log.debug("Can't update model", eee); - } - ErrorHelper.showErrorDialog("Can't get VAT list", eee); - } - } - return finalresults; - } - - public void refresh(){ - try { - cacheDataList = getDataList(); - } catch (TopiaException eee) { - if (log.isErrorEnabled()) { - log.debug("Can't update model", eee); - } - ErrorHelper.showErrorDialog("Can't get VAT list", eee); - } - fireTableDataChanged(); - } - - @Override - public Class<?> getColumnClass(int column) { - - Class<?> result = null; - - switch (column) { - case 0: - result = String.class; - break; - case 1: - result = Account.class; - break; - case 2: - result = String.class; - break; - case 3: - result = String.class; - break; - case 4: - result = BigDecimal.class; - break; - case 5: - result = BigDecimal.class; - break; - case 6: - result = BigDecimal.class; - break; - } - - return result; - } - - @Override - public String getColumnName(int column) { - String result = "n/a"; - - switch (column) { - case 0: - result = _("lima.table.date"); //date - break; - case 1: - result = "compte"; //tva collectee - break; - case 2: - result = "piece comptable"; //tva due - break; - case 3: - result = "description"; //credit de tva - break; - case 4: - result = "debit"; //remboursemments - break; - case 5: - result = "credit"; //credit restant - break; - case 6: - result = "solde"; //tva a payer - break; - } - - return result; - } - - @Override - public int getRowCount() { - int result = 0; - - if (cacheDataList != null) { - result = cacheDataList.size(); - } - - return result; - } - - @Override - public int getColumnCount() { - return 7; - } - - public Object getElementAt(int row){ - Object currentRow = cacheDataList.get(row); - return currentRow; - } - - @Override - public Object getValueAt(int row, int column) { - Object result = null; - // just prevent too much result - if (cacheDataList != null) { - result = cacheDataList.get(row); - SimpleDateFormat simpleDateFormat = new SimpleDateFormat("dd MMM yyyy"); - if (result instanceof FinancialPeriod) { - FinancialPeriod fp = (FinancialPeriod) result; - - switch (column) { - case 0: - result = simpleDateFormat.format(fp.getBeginDate()) - + " - " + simpleDateFormat.format(fp.getEndDate()); - break; - case 1: - result = null; - break; - case 2: - result = null; // voucher - break; - case 3: - result = null; // description - break; - case 4: - result = null; // position - break; - case 5: - result = null; - break; - case 6: - result = null; - break; - } - } - else if (result instanceof ReportsDatas) { - ReportsDatas currentRow = (ReportsDatas)result; - BigDecimal amountDebit = currentRow.getAmountDebit(); - BigDecimal amountCredit = currentRow.getAmountCredit(); - - switch (column) { - case 0: - result = null; // date - break; - case 1: - if (currentRow.getAccount() != null){ - result = currentRow.getAccount().getAccountNumber() - + " - " + currentRow.getAccount().getLabel(); - } - else { - result = null; - } - break; - case 2: - result = null; // voucher - break; - case 3: - result = null; // description - break; - case 4: - result = amountDebit; // position - break; - case 5: - result = amountCredit; - break; - case 6: - result = amountDebit.subtract(amountCredit); - break; - } - } - else if (result instanceof Entry) { - Entry currentRow = (Entry)result; - BigDecimal amountDebit = BigDecimal.ZERO, - amountCredit = BigDecimal.ZERO; - if (currentRow.getDebit()){ - amountDebit = currentRow.getAmount(); - } - else { - amountCredit = currentRow.getAmount(); - } - - switch (column) { - case 0: // date - result = simpleDateFormat. - format(currentRow.getFinancialTransaction().getTransactionDate()); - break; - case 1 : // account - result = null; - break; - case 2: // description - result = currentRow.getVoucher(); - break; - case 3: - result = currentRow.getDescription(); - break; - case 4: - result = amountDebit; - break; - case 5: - result = amountCredit; - break; - case 6: - result = amountDebit.subtract(amountCredit); - break; - } - } - } - - return result; - } - - public FiscalPeriod getFiscalPeriod() { - return selectedFiscalPeriod; - } - - public void setFiscalPeriod(FiscalPeriod fiscalPeriod){ - selectedFiscalPeriod = fiscalPeriod; - refresh(); - } - - @Override - public void notifyMethod(String serviceName, String methodeName) { - // TODO Auto-generated method stub - - } - -} Deleted: 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-07-05 10:34:37 UTC (rev 3199) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/vatreports/VatView.jaxx 2011-07-05 16:19:45 UTC (rev 3200) @@ -1,58 +0,0 @@ -<Table> - <VatViewHandler id="handler" javaBean="new VatViewHandler(this)" /> - <Boolean id="selectedRow" javaBean="false" /> - - <script> - <![CDATA[ - import org.chorem.lima.entity.FiscalPeriod; - import org.chorem.lima.entity.FinancialPeriod; - import org.chorem.lima.ui.combobox.FiscalPeriodComboBoxModel; - import org.chorem.lima.ui.financialtransaction.FinancialPeriodComboBox; - import org.chorem.lima.ui.combobox.FinancialPeriodComboBoxRenderer; - import org.chorem.lima.ui.combobox.FiscalPeriodComboBoxRenderer; - import org.chorem.lima.ui.vatreports.VatTableModel; - import org.chorem.lima.ui.vatreports.VatTable; - - void $afterCompleteSetup() { - getHandler().refresh(); - } - - ]]> - </script> - - <row weightx="1" weighty="0" anchor="center"> - <cell anchor="east"> - <JLabel id="fiscalPeriodLabel" text="lima.charts.fiscalyear"/> - </cell> - <cell anchor="west"> - <org.chorem.lima.ui.combobox.FiscalPeriodComboBoxModel id="modelFiscalPeriod"/> - <JComboBox id="fiscalPeriodComboBox" - model="{getModelFiscalPeriod()}" - renderer="{new FiscalPeriodComboBoxRenderer()}" - onActionPerformed="getVatTableModel().setFiscalPeriod((FiscalPeriod)fiscalPeriodComboBox.getSelectedItem())" - editable="false"/> - </cell> - <cell> - <EnumEditor id='DocumentEditor' - constructorParams='org.chorem.lima.business.utils.FormatsEnum.class'/> - </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"> - <JScrollPane> - <org.chorem.lima.ui.vatreports.VatTableModel - id="vatTableModel"/> - <org.chorem.lima.ui.vatreports.VatTable - id="vatTable" sortable="false" rowHeight="22" - constructorParams="getHandler()" model="{getVatTableModel()}" - selectionMode="{ListSelectionModel.SINGLE_SELECTION}" /> - <javax.swing.ListSelectionModel javaBean="getVatTable().getSelectionModel()" - onValueChanged="setSelectedRow(vatTable.getSelectedRow() != -1)"/> - </JScrollPane> - </cell> - </row> -</Table> \ No newline at end of file Deleted: 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-07-05 10:34:37 UTC (rev 3199) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/vatreports/VatViewHandler.java 2011-07-05 16:19:45 UTC (rev 3200) @@ -1,88 +0,0 @@ -package org.chorem.lima.ui.vatreports; - -import java.awt.Desktop; -import java.io.IOException; -import java.net.URI; -import java.net.URISyntaxException; -import java.text.SimpleDateFormat; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.chorem.lima.LimaConfig; -import org.chorem.lima.business.DocumentServiceMonitorable; -import org.chorem.lima.business.HttpServerServiceMonitorable; -import org.chorem.lima.business.utils.DocumentsEnum; -import org.chorem.lima.business.utils.FormatsEnum; -import org.chorem.lima.service.LimaServiceFactory; -import org.chorem.lima.ui.vatreports.VatTable; -import org.chorem.lima.ui.vatreports.VatTableModel; -import org.chorem.lima.ui.vatreports.VatView; - -public class VatViewHandler { - /** log. */ - private static final Log log = - LogFactory.getLog(VatViewHandler.class); - - protected VatView view; - - protected VatTable table; - - protected VatTableModel tableModel; - - protected DocumentServiceMonitorable documentService; - - private static SimpleDateFormat dateFormat = - new SimpleDateFormat("yyyy-MM-dd"); - - protected int port; - - protected VatViewHandler(VatView view) { - this.view = view; - - port = LimaServiceFactory.getInstance().getService( - HttpServerServiceMonitorable.class).getHttpPort(); - - documentService = - LimaServiceFactory.getInstance().getService( - DocumentServiceMonitorable.class); - } - - /** - * @return VatView - */ - public VatView getView() { - return view; - } - - /** - * Edit VAT document - */ - public void editVat() { - if (tableModel.getFiscalPeriod() != null){ - FormatsEnum selectedEnum = (FormatsEnum) view.getDocumentEditor().getSelectedItem(); - String address = LimaConfig.getInstance().getHostAdress(); - - try { - String url = "http://"+address+":"+port+"/?beginDate=" - + dateFormat.format(tableModel.getFiscalPeriod().getBeginDate()) - + "&endDate="+dateFormat.format(tableModel.getFiscalPeriod().getEndDate()) - + "&format="+selectedEnum.getExtension()+"&model=" - + DocumentsEnum.VAT.getFileName(); - Desktop.getDesktop().browse(new URI(url)); - } catch (IOException e) { - log.error("Can't open browser", e); - } catch (URISyntaxException e) { - log.error("Can't create news URI", e); - } - } - } - - /** - * Refresh VatTableModel - */ - public void refresh(){ - tableModel = view.getVatTableModel(); - tableModel.refresh(); - } - -}
participants (1)
-
vsalaun@users.chorem.org