BrightSide Workbench Full Report + Source Code
FinancialsMenu.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2011 Lluis TurrĂ³ Cutiller <http://www.turro.org/>
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU Affero General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU Affero General Public License for more details.
14  *
15  * You should have received a copy of the GNU Affero General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 package org.turro.financials.menu;
19 
20 import java.util.Date;
21 import java.util.HashMap;
22 import javax.activation.MimetypesFileTypeMap;
23 import org.amic.util.date.CheckDate;
24 import org.turro.annotation.ExternalMenu;
25 import org.turro.command.Command;
26 import org.turro.command.Context;
27 import org.turro.elephant.context.ElephantContext;
28 import org.turro.financials.account.DiaryReport;
29 import org.turro.financials.account.PrintBook;
30 import org.turro.financials.assets.FixedAssetWrapper;
31 import org.turro.financials.book.ExpensesBook;
32 import org.turro.financials.book.IncomeBook;
33 import org.turro.financials.document.QuickDocument;
34 import org.turro.financials.entity.Document;
35 import org.turro.financials.entity.Register;
36 import org.turro.financials.model.document.AnnualTransactionsSet;
37 import org.turro.financials.product.ProductImport;
38 import org.turro.financials.report.ReportBody;
39 import org.turro.financials.usual.UsualUpdate;
40 import org.turro.i18n.I_;
41 import org.turro.jpa.export.ExportQuery;
42 import org.turro.menu.ElephantMenu;
43 import org.turro.menu.ElephantMenuBar;
44 import org.turro.reflection.Reflections;
45 import org.turro.security.Permission;
46 import org.turro.zkoss.dialog.InputDialog;
47 import org.turro.zkoss.dialog.InputField;
48 import org.turro.zul.frame.Framework;
49 import org.zkoss.zk.ui.Executions;
50 import org.zkoss.zk.ui.event.Event;
51 import org.zkoss.zk.ui.event.EventListener;
52 import org.zkoss.zul.Filedownload;
53 
59 public class FinancialsMenu extends ElephantMenu {
60 
61  private void exportAnnualTransactions(ElephantMenuBar bar) {
62  InputDialog.getInput(bar.getPage(), I_.get("Annual statement transactions"), "Year",
63  Integer.valueOf(0), null, 0, new Command() {
64  @Override
65  public Object execute(Context context) {
66  Integer year = (Integer) context.get("value");
67  if(year != null) {
69  @Override
70  public String getLabel(String key) {
71  return I_.get(key);
72  }
73  };
74  ats.fillSet(year);
75  String name = ElephantContext.getSiteName() + "_AnnualTrans.xls";
76  ExportQuery eq = new ExportQuery(ats.getColumns(), ats.getRows());
77  Filedownload.save(eq.getExcel(name), new MimetypesFileTypeMap().getContentType(name), name);
78  }
79  return null;
80  }
81  });
82  }
83 
84  private void exportAccountBalance(ElephantMenuBar bar) {
86  bar.getPage(), I_.get("Export account balance"), new InputField[] {
87  new InputField("Year", Integer.valueOf(new CheckDate().getYear()), null, 0),
88  new InputField("Month", Integer.valueOf(new CheckDate().getMonth()), null, 0),
89  new InputField("Carry on initial balance", Boolean.valueOf(false), null, 0),
90  new InputField("Breakdown", Boolean.valueOf(false), null, 0)
91  }, new Command() {
92  @Override
93  public Object execute(Context context) {
94  InputField[] fields = (InputField[]) context.get("fields");
95  if(fields.length > 0) {
97  (Integer) InputField.getByLabel("Year", fields).getValue(),
98  (Integer) InputField.getByLabel("Month", fields).getValue(),
99  (Boolean) InputField.getByLabel("Carry on initial balance", fields).getValue(),
100  (Boolean) InputField.getByLabel("Breakdown", fields).getValue()
101  );
102  }
103  return null;
104  }
105  });
106  }
107 
108  private void expensesBook(ElephantMenuBar bar) {
109  InputDialog.getInput(bar.getPage(), I_.get("Expenses book"), "Year",
110  Integer.valueOf(0), null, 0, new Command() {
111  @Override
112  public Object execute(Context context) {
113  Integer year = (Integer) context.get("value");
114  if(year != null) {
115  ExpensesBook.from(year).download();
116  }
117  return null;
118  }
119  });
120  }
121 
122  private void incomeBook(ElephantMenuBar bar) {
123  InputDialog.getInput(bar.getPage(), I_.get("Income book"), "Year",
124  Integer.valueOf(0), null, 0, new Command() {
125  @Override
126  public Object execute(Context context) {
127  Integer year = (Integer) context.get("value");
128  if(year != null) {
129  IncomeBook.from(year).download();
130  }
131  return null;
132  }
133  });
134  }
135 
136  @Override
137  public void addToMenu(ElephantMenuBar bar) {
138  bar.addMenu("Financials", Permission.from("finan-contract", "finan-document", "finan-product", "finan-account"))
139  .addSubmenu()
140  .addMenu("Management", Permission.from("finan-contract:list", "finan-document:list", "finan-product:list"))
141  .addSubmenu()
142  .addMenuitem("Contracts", "contract", "/financials/contract/contracts.zul", true, Permission.from("finan-contract:list"))
143  .addMenuitem("Documents", "document", "/financials/document/documents.zul", true, Permission.from("finan-document:list"))
144  .addMenuitem("Batch of", "batchof", "/financials/batchof/batchofs.zul", true, Permission.from("finan-document:list"))
145  .addMenuitem("Payrolls", "/financials/batchof/payrolls.zul", false, Permission.from("finan-document:list"))
146  .addMenuitem("Products", "product", "/financials/product/products.zul", true, Permission.from("finan-product:list"))
147  .addToolbarSeparator(true)
149  .addMenuitem("New contract", "contract_new", (EventListener) (Event event) -> {
150  showContract(0L);
151  }, true, Permission.from("finan-contract:new"))
152  .addMenuitem("New document", "document_new", (EventListener) (Event event) -> {
153  showDocument(0L);
154  }, true, Permission.from("finan-document:new"))
155  .addMenuitem("New quick document", (EventListener) (Event event) -> {
156  Date now = new Date();
157  QuickDocument w = new QuickDocument(now, 0.0, "");
158  w.setPage(bar.getPage());
159  w.afterCompose();
160  Framework.getCurrent().showModal(I_.get("New document"), w, null);
161  }, Permission.from("finan-document:new"))
162  .addMenuitem("New batch of", "batchof_new", (EventListener) (Event event) -> {
163  showBatchOf(0L);
164  }, true, Permission.from("finan-document:new"))
165  .addMenuitem("New product", "product_new", (EventListener) (Event event) -> {
166  showProduct(0L);
167  }, true, Permission.from("finan-product:new"))
168  .addMenuitem("Import CSV", (EventListener) (Event event) -> {
170  }, true, Permission.from("finan-product:new"))
171  .addToolbarSeparator(true)
173  .addMenuitem("Handshakes", "handshake", "/financials/handshake/queue.zul", true, Permission.from("finan-contract:list"))
174  .addToolbarSeparator(true)
176  .addMenu("Portfolio", Permission.from("finan-contract:list", "finan-document:list"))
177  .addSubmenu()
178  .addMenuitem("Portfolio", "portfolio", "/financials/document/portfolio.zul", true)
179  .addMenuitem("Documents statement", "/financials/contract/documentsStatement.zul")
180  .addMenuitem("Portfolio status", "/financials/document/portfolioStatus.zul")
182  .addMenuitem("Portfolio disagreements", "/financials/document/portfolioDisagreements.zul")
183  .addMenuitem("Portfolio errors", "/financials/document/portfolioErrors.zul")
185  .addMenuitem("Portfolio by entity", "/financials/entities/portfolio.zul")
187  .addMenu("POS", Permission.from("class:org.turro.pos.financials.ExportData"))
188  .addSubmenu()
189  .addMenuitem("Export", (EventListener) (Event event) -> {
190  Reflections.of("org.turro.pos.financials.ExportProducts").invoke("execute");
191  }, false, Permission.from("finan-product:list"))
193  .addMenu("Accounting", Permission.from("finan-account:statement", "finan-account:balance", "finan-register:new"))
194  .addSubmenu()
195  .addMenuitem("Account statement", "statement", "/financials/account/statement.zul", true, Permission.from("finan-account:statement"))
196  .addMenuitem("Account balance", "/financials/account/balance.zul", Permission.from("finan-account:balance"))
197  //.addMenuitem("Accounts report", "/financials/account/report.zul", Permission.from("finan-account:balance"))
198  .addMenu("Reports", Permission.from("finan-account:balance"))
199  .addSubmenu()
200  .addCollecction(ReportBody.reports(), (esm, rb) -> {
201  esm.addMenuitem(rb.getName(), (EventListener) (Event event) -> {
202  HashMap<String, Object> map = new HashMap<String, Object>();
203  map.put("body", rb);
204  showZulFile(rb.getName(), "/financials/reports/report.zul", map);
205  });
206  })
208  .addObject(new DiaryReport(), (esm, dr) -> {
209  dr.setLabel(I_.get("Diary book"));
210  esm.appendChild(dr);
211  dr.afterCompose();
212  })
213  .addObject(new PrintBook(), (esm, pb) -> {
214  pb.setLabel(I_.get("Print book"));
215  esm.appendChild(pb);
216  pb.afterCompose();
217  })
218  .addMenuitem("Export diary", (EventListener) (Event event) -> {
220  }, false)
221  .addMenuitem("Export account balance", (EventListener) (Event event) -> {
222  exportAccountBalance(bar);
223  }, false, Permission.from("finan-account:balance"))
224  .addMenuitem("Annual statement transactions", (EventListener) (Event event) -> {
225  exportAnnualTransactions(bar);
226  }, false, Permission.from("finan-account:balance"))
227  .addMenuitem("Report sheets", (EventListener) (Event event) -> {
228  new FinancialsSheets().exportSheet(bar.getPage());
229  }, false, Permission.from("finan-account:balance"))
230  .addMenuitem("Operating", "linechart", "/financials/business/operating.zul", Permission.from("finan-account:balance"))
231  .addMenuSeparator()
232  .addMenuitem("Views", "/financials/view/views.zul", Permission.from("finan-model:list"))
233  .addMenuitem("Books", "/financials/book/books.zul", Permission.from("finan-model:list"))
234  .addMenuitem("Major accounts", "/financials/account/majors.zul", Permission.from("finan-model:list"))
235  .addMenuitem("Accounts", "/financials/account/accounts.zul", Permission.from("finan-model:list"))
236  .addMenuSeparator()
237  .addMenuitem("Fixed assets", "asset", "/financials/asset/fixedAssets.zul", Permission.from("finan-fixed-asset:list"))
238  .addMenuitem("New fixed asset", "asset_new", (EventListener) (Event event) -> {
239  showFixedAsset(0L);
240  }, false, Permission.from("finan-fixed-asset:list"))
241  .addMenuitem("Depreciations", (EventListener) (Event event) -> {
242  FixedAssetWrapper.doDepreciations(bar.getPage());
243  }, false, Permission.from("finan-fixed-asset:list"))
244  .addMenuSeparator()
245  .addMenuitem("New register", "register_new", (EventListener) (Event event) -> {
246  showRegister(0L);
247  }, false, Permission.from("finan-register:new"))
249  .addMenu("Treasury", Permission.from("finan-account:balance"))
250  .addSubmenu()
251  .addMenuitem("Model 111, 115, 123", "/financials/treasury/model111.zul")
252  .addMenuitem("Model 303 Quarter", "/financials/treasury/model303.zul")
253  .addMenuitem("Model 303 Month", "/financials/treasury/model303m.zul")
254  .addMenuitem("Settlement", "/financials/treasury/settlement.zul")
255  .addMenuitem("Expenses book", (EventListener) (Event event) -> {
256  expensesBook(bar);
257  }, false, Permission.from("finan-account:balance"))
258  .addMenuitem("Income book", (EventListener) (Event event) -> {
259  incomeBook(bar);
260  }, false, Permission.from("finan-account:balance"))
262  .addMenu("Warnings", Permission.from("finan-contract:list", "finan-document:list"))
263  .addSubmenu()
264  .addMenuitem("Disagreements in contacts", "/financials/contract/contactDisagreements.zul", Permission.from("finan-contract:list"))
265  .addMenuitem("Update Usuals", (EventListener) (Event event) -> {
266  new UsualUpdate().update();
267  }, false, Permission.from("finan-document:list"))
268  .addMenuitem("Non balanced registers", "/financials/register/nonBalanced.zul", Permission.from("finan-register:list"))
270  .addToolbarSeparator(true)
271  .addMenu("Models", Permission.from("finan-model:list"))
272  .addSubmenu()
273  .addMenuitem("Viewer", "/financials/ctcdef/viewer.zul")
275  .addMenuitem("Companies", "/financials/business/companies.zul")
277  .addMenuitem("Contract models", "/financials/ctcdef/contracts.zul")
278  .addMenuitem("Document models", "/financials/docdef/documents.zul")
279  .addMenuitem("Line types", "/financials/linetype/lineTypes.zul")
281  .addMenuitem("Notes", "/financials/ctcdef/notes.zul");
282  }
283 
284  public static void showDocumentDefinition(Long id) {
285  showEntity(id, "docdefId", "Document model", "/financials/docdef/document.zul");
286  }
287 
288  public static void showContractDefinition(Long id) {
289  showEntity(id, "ctcdefId", "Contract model", "/financials/ctcdef/contract.zul");
290  }
291 
292  public static void showContract(Long id) {
293  showEntity(id, "contractId", "Contract", "/financials/contract/contract.zul");
294  }
295 
296  public static void showDocument(Long id) {
297  showEntity(id, "documentId", "Document", "/financials/document/document.zul");
298  }
299 
300  public static void showBatchOf(Long id) {
301  showEntity(id, "batchOfId", "Batch of", "/financials/batchof/batchof.zul");
302  }
303 
304  public static void showDocument(Document doc) {
305  HashMap<String, Object> map = new HashMap<String, Object>();
306  map.put("documentGenerated", doc);
307  showEntity(doc.getId(), "documentId", "Document", "/financials/document/document.zul", map);
308  }
309 
310  public static void showRegister(Long id) {
311  showEntity(id, "registerId", "Register", "/financials/register/register.zul");
312  }
313 
314  public static void showRegister(Register reg) {
315  HashMap<String, Object> map = new HashMap<String, Object>();
316  map.put("registerGenerated", reg);
317  showEntity(reg.getId(), "registerId", "Register", "/financials/register/register.zul", map);
318  }
319 
320  public static void showProduct(Long id) {
321  showEntity(id, "productId", "Product", "/financials/product/product.zul");
322  }
323 
324  public static void showStatement(String account) {
325  Executions.getCurrent().getDesktop().setAttribute("statementId", account);
326  showEntity(0L, "none", "Account statement", "/financials/account/statement.zul");
327  }
328 
329  public static void showFixedAsset(Long id) {
330  showEntity(id, "fixedAssetId", "Fixed asset", "/financials/asset/fixedAsset.zul");
331  }
332 
333  public static void showCompanies() {
334  showZulFile("Companies", "/financials/business/companies.zul");
335  }
336 }
static void exportAccountBalance(int year, int month, boolean carry, boolean breakdown)
static ExpensesBook from(int year)
static IncomeBook from(int year)
static void showStatement(String account)
static List< ReportBody > reports()
static String get(String msg)
Definition: I_.java:41
InputStream getExcel(String sheetName)
ElephantMenu addMenu(String label)
static void showEntity(Object id, String attribute, String label, String include)
ElephantSubmenu getParentSubmenu()
ElephantSubmenu addSubmenu()
static void showZulFile(String label, String include)
ElephantMenu addMenu(String label)
ElephantSubmenu addMenuitem(String label, String include)
ElephantSubmenu addToolbarSeparator(boolean bar)
static Permission from(String... roles)
Definition: Permission.java:79
static void getInput(Page page, String title, String label, Object value, String format, int scale, final Command onOk)
static InputField getByLabel(String label, InputField[] fields)
static Framework getCurrent()
Definition: Framework.java:203
void showModal(String label, String src, Map arg, Command command)
Definition: Framework.java:111