18 package org.turro.financials.portfolio;
21 import org.turro.collections.AggregateCountItem;
22 import org.turro.collections.AggregateCountMap;
23 import org.turro.elephant.util.DateFormats;
24 import org.turro.elephant.util.DecimalFormats;
25 import org.turro.elephant.util.Messages;
26 import org.turro.financials.db.FinancialsPU;
27 import org.turro.financials.document.action.DocumentActionMenu;
28 import org.turro.financials.menu.FinancialsMenu;
29 import org.turro.i18n.I_;
30 import org.turro.zkoss.filter.FilterGrid;
31 import org.turro.zkoss.grid.PagingGrid;
32 import org.turro.zkoss.label.LabelTypes;
33 import org.zkoss.zk.ui.Component;
34 import org.zkoss.zk.ui.event.Event;
35 import org.zkoss.zk.ui.event.EventListener;
36 import org.zkoss.zk.ui.event.Events;
37 import org.zkoss.zk.ui.ext.AfterCompose;
38 import org.zkoss.zk.ui.util.Clients;
39 import org.zkoss.zul.*;
52 this.filterGrid = filterGrid;
69 for(Component row :
getRows().getChildren()) {
89 AggregateCountMap acm =
new AggregateCountMap();
90 for(Component row :
getRows().getChildren()) {
105 StringBuilder sb =
new StringBuilder();
106 for(Map.Entry<String, AggregateCountItem> entry : acm.entrySet()) {
107 sb.append(entry.getKey())
109 .append(String.format(
"%.2f (%d)",entry.getValue().getAmount(), entry.getValue().getCount()))
112 Clients.showNotification(sb.toString());
118 getParent().appendChild(dam);
122 private void addRows() {
123 if(filterGrid !=
null && !filterGrid.
hasValues())
return;
125 Rows rows =
new Rows();
128 if(filterGrid !=
null) {
132 for(
final PortfolioItem item : filter) {
133 filter.checkGroup(
this, item.getDocument());
134 final Row row =
new Row();
136 rows.appendChild(row);
137 if(item.getDocument().isDraft()) {
138 row.setSclass(
"draft");
140 row.appendChild(
new Label(item.getDocument().getId() +
""));
141 row.appendChild(
new Label(DateFormats.format(item.getDocument().getReceiptDate(),
true)));
142 row.appendChild(
new Label(DateFormats.format(item.getDocument().getDocumentDate(),
true)));
143 row.appendChild(
new Label(item.getDocument().getDocumentNumber()));
144 Vbox vbox =
new Vbox();
146 item.getDocument().getDocumentDefinition().getName() +
147 (item.getDocument().getForcedView() ==
null ?
"" :
" (" + item.getDocument().getForcedView().getName() +
")"));
148 b.setImage(
"/_zul/images/document.png");
149 b.addEventListener(Events.ON_CLICK,
new EventListener() {
151 public void onEvent(Event event)
throws Exception {
152 FinancialsMenu.showDocument(item.getDocument().getId());
156 b.setAttribute(
"document", item.getDocument());
159 vbox.appendChild(LabelTypes.getSoftLabel(item.getDocument().getConcept()));
160 vbox.appendChild(LabelTypes.getSoftLabel(item.getDocument().getNotes()));
161 row.appendChild(vbox);
162 row.appendChild(
new Label(DecimalFormats.format(item.getDocument().getTotalAmount(),
163 DecimalFormats.getStringFormat(item.getDocument().getCurrency().getDefaultFractionDigits()))));
164 if(filterGrid !=
null) {
166 for(
final WorkflowItem dw : item.getForward()) {
167 Hlayout hbox =
new Hlayout();
168 vbox.appendChild(hbox);
169 final Checkbox cb =
new Checkbox(dw.getWorkflow().getDescendant().getName(),
"/_zul/images/forward.png");
170 cb.setChecked(dw.isSelected());
171 cb.addEventListener(Events.ON_CHECK,
new EventListener() {
173 public void onEvent(Event event)
throws Exception {
174 dw.setSelected(cb.isChecked());
177 hbox.appendChild(cb);
178 Toolbarbutton del =
new Toolbarbutton(
null,
"/_zul/images/edit-delete.png");
179 del.addEventListener(Events.ON_CLICK,
new EventListener() {
181 public void onEvent(Event event)
throws Exception {
182 Messages.question().add(I_.get(
"Mark as") +
": " + I_.get(
"No descendants")).show(() -> {
183 item.getDocument().setNoDescendants(
true);
184 new FinancialsPU().saveObject(item.getDocument());
189 hbox.appendChild(del);
191 for(
final WorkflowItem dw : item.getBackward()) {
192 Hlayout hbox =
new Hlayout();
193 vbox.appendChild(hbox);
194 final Checkbox cb =
new Checkbox(dw.getWorkflow().getAncestor().getName(),
"/_zul/images/back.png");
195 cb.setChecked(dw.isSelected());
196 cb.addEventListener(Events.ON_CHECK,
new EventListener() {
198 public void onEvent(Event event)
throws Exception {
199 dw.setSelected(cb.isChecked());
202 hbox.appendChild(cb);
203 Toolbarbutton del =
new Toolbarbutton(
null,
"/_zul/images/edit-delete.png");
204 del.addEventListener(Events.ON_CLICK,
new EventListener() {
206 public void onEvent(Event event)
throws Exception {
207 Messages.question().add(I_.get(
"Mark as") +
": " + I_.get(
"No ancestors")).show(() -> {
208 item.getDocument().setNoAncestors(
true);
209 new FinancialsPU().saveObject(item.getDocument());
214 hbox.appendChild(del);
216 row.appendChild(vbox);
224 private void addColumns() {
228 Column col =
new Column(
"#",
null,
"40px");
229 cols.appendChild(col);
231 col =
new Column(I_.get(
"Receipt/Issue"),
null,
"120px");
232 cols.appendChild(col);
234 col =
new Column(I_.get(
"Date"),
null,
"90px");
235 cols.appendChild(col);
237 col =
new Column(I_.get(
"Number"),
null,
"180px");
238 cols.appendChild(col);
240 col =
new Column(I_.get(
"Document"));
241 cols.appendChild(col);
243 col =
new Column(I_.get(
"Amount"),
null,
"120px");
244 col.setAlign(
"right");
245 cols.appendChild(col);
247 if(filterGrid !=
null) {
248 col =
new Column(
"",
null,
"220px");
249 cols.appendChild(col);
void setFilterGrid(FilterGrid filterGrid)
Collection< WorkflowItem > getBackward()
Collection< WorkflowItem > getForward()
void load(RelationMode mode, List< IFilterValue > values)
List< IFilterValue > getValues()
Columns getColumns(boolean create)
Rows getRows(boolean create)
void setRowCount(int rows)