BrightSide Workbench Full Report + Source Code
DocumentByEntityVM.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2021 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 
19 package org.turro.entities.portfolio;
20 
21 import java.util.ArrayList;
22 import java.util.Collections;
23 import java.util.List;
24 import org.turro.entities.IElephantEntity;
25 import org.turro.financials.model.document.contract.DocumentPortfolio;
26 import org.turro.i18n.I_;
27 import org.zkoss.bind.annotation.BindingParam;
28 import org.zkoss.bind.annotation.Command;
29 import org.zkoss.bind.annotation.NotifyChange;
30 
35 public class DocumentByEntityVM {
36 
37  private final DocumentByEntityList documents;
38  private IElephantEntity entity, category;
39  private EntityPortfolioList entityModel;
40 
41  public DocumentByEntityVM() {
42  documents = new DocumentByEntityList();
43  }
44 
46  return entity;
47  }
48 
49  @NotifyChange({"model", "entity", "finalInvoice", "finalSettlement", "finalPortfolio", "finalBalance", "finalCount"})
50  @Command("entity")
51  public void setEntity(@BindingParam("entity") IElephantEntity entity) {
52  this.entity = entity;
53  this.category = entity;
54  }
55 
56  @NotifyChange({"model", "finalInvoice", "finalSettlement", "finalPortfolio", "finalBalance", "finalCount"})
57  @Command("category")
58  public void setCategory(@BindingParam("category") IElephantEntity category) {
59  this.category = category;
60  }
61 
62  @NotifyChange("model")
63  @Command("update")
64  public void update() {}
65 
66  public List<DocumentPortfolio> getModel() {
67  if(entity != null) {
68  documents.clear();
69  entityModel = new EntityPortfolioList(documents, category.getAllChildren().getEntityPaths());
70  return new ArrayList(entityModel);
71  } else {
72  return Collections.EMPTY_LIST;
73  }
74  }
75 
76  public String getLabel(String label) {
77  return I_.get(label);
78  }
79 
80  public double getFinalBalance() {
81  return entityModel == null ? 0.0 : entityModel.getFinalBalance();
82  }
83 
84  public double getFinalInvoice() {
85  return entityModel == null ? 0.0 : entityModel.getFinalInvoice();
86  }
87 
88  public double getFinalPortfolio() {
89  return entityModel == null ? 0.0 : entityModel.getFinalPortfolio();
90  }
91 
92  public double getFinalSettlement() {
93  return entityModel == null ? 0.0 : entityModel.getFinalSettlement();
94  }
95 
96  public int getFinalCount() {
97  return entityModel == null ? 0 : entityModel.getFinalCount();
98  }
99 
100 }
List< String > getEntityPaths()
Definition: EntitySet.java:31
void setCategory(@BindingParam("category") IElephantEntity category)
void setEntity(@BindingParam("entity") IElephantEntity entity)
static String get(String msg)
Definition: I_.java:41