19 package org.turro.financials.business;
21 import java.util.Collection;
23 import org.turro.elephant.util.DecimalFormats;
24 import org.turro.elephant.util.Images;
25 import org.turro.elephant.util.Messages;
26 import org.turro.financials.entity.Register;
27 import org.turro.financials.menu.FinancialsMenu;
28 import org.turro.financials.model.register.AccountItem;
29 import org.turro.financials.model.register.ClosingRegisters;
30 import org.turro.i18n.I_;
31 import org.turro.math.Zero;
32 import org.turro.zkoss.dialog.SelectionDialog;
33 import org.turro.zkoss.grid.PagingGrid;
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.zul.Button;
39 import org.zkoss.zul.Checkbox;
40 import org.zkoss.zul.Column;
41 import org.zkoss.zul.Columns;
42 import org.zkoss.zul.Hlayout;
43 import org.zkoss.zul.Image;
44 import org.zkoss.zul.Label;
45 import org.zkoss.zul.Row;
46 import org.zkoss.zul.Rows;
61 getRows(
true).getChildren().clear();
65 private void addRows() {
67 I_.
get(
"Start exercise"),
68 I_.
get(
"End exercise"),
69 I_.
get(
"Operating closure"));
74 boolean removalShown =
false;
76 for(
final Integer exercise : exercises) {
78 rows.appendChild(row);
79 row.appendChild(
new Label(exercise +
""));
82 Double amount129 =
null;
84 Hlayout hbox =
new Hlayout();
85 hbox.setSpacing(
"5px");
87 hbox.appendChild(
new Label(
I_.
get(
"Closed")));
88 final Set<AccountItem> items = cr.
getNotClosed(exercise);
89 if(!items.isEmpty()) {
91 img.setTooltiptext(
I_.
get(
"Unbalanced"));
92 img.addEventListener(Events.ON_CLICK,
new EventListener<Event>() {
94 public void onEvent(Event event) throws Exception {
95 AccountItemListbox ail = new AccountItemListbox();
96 ail.setCollection(items);
97 SelectionDialog.showComponent(getPage(), I_.get(
"Unbalanced"),
98 ail,
"80%",
"400px", null);
101 hbox.appendChild(img);
104 hbox.appendChild(
new Label(I_.get(
"Opened")));
105 amount129 = cr.
get129(exercise);
106 if(amount129 !=
null && !Zero.near(amount129, 2)) {
107 Image img =
new Image(Images.getImage(
"warn"));
108 img.setTooltiptext(
"129 = " + DecimalFormats.format(amount129));
109 hbox.appendChild(img);
112 row.appendChild(hbox);
114 hbox =
new Hlayout();
115 Button regen =
new Button(I_.get(
"Generate registers"));
116 regen.addEventListener(Events.ON_CLICK,
new EventListener<Event>() {
118 public void onEvent(Event event) throws Exception {
119 Messages.confirmProcess().add(I_.get(
"Generate registers")).show(() -> {
120 cr.deleteClosingRegisters(exercise);
121 cr.createClosingRegisters(exercise);
126 hbox.appendChild(regen);
128 Button show =
new Button(I_.get(
"Show"));
129 show.addEventListener(Events.ON_CLICK,
new EventListener<Event>() {
131 public void onEvent(Event event) throws Exception {
132 for(Register r : cr.getClosureRegisters(exercise)) {
133 FinancialsMenu.showRegister(r);
137 hbox.appendChild(show);
138 Button
delete =
new Button(I_.get(
"Delete"));
139 delete.addEventListener(Events.ON_CLICK,
new EventListener<Event>() {
141 public void onEvent(Event event) throws Exception {
142 Messages.confirmDeletion().show(() -> {
143 cr.deleteClosingRegisters(exercise);
148 hbox.appendChild(
delete);
150 row.appendChild(hbox);
152 hbox =
new Hlayout();
153 Button renum =
new Button(I_.get(
"Renumerate registers"));
154 final Checkbox booksTo =
new Checkbox(I_.get(
"Remun book registers"));
155 renum.addEventListener(Events.ON_CLICK,
new EventListener<Event>() {
157 public void onEvent(Event event) throws Exception {
158 Messages.confirmProcess().add(I_.get(
"Renumerate registers")).show(() -> {
159 CompanyWrapper.renumRegisters(exercise, booksTo.isChecked());
163 hbox.appendChild(renum);
164 hbox.appendChild(booksTo);
165 row.appendChild(hbox);
167 hbox =
new Hlayout();
170 Button removal =
new Button(I_.get(
"Remove exercise"));
171 removal.addEventListener(Events.ON_CLICK,
new EventListener<Event>() {
173 public void onEvent(Event event) throws Exception {
174 Messages.confirmDeletion().add(I_.get(
"Remove exercise"))
175 .line().add(I_.get(
"Ensure the exercise is close."))
176 .line().add(I_.get(
"This process will remove movements and documents."))
178 CompanyWrapper.removeExercise(exercise);
183 hbox.appendChild(removal);
185 row.appendChild(hbox);
188 setRowCount(exercises.size());
191 private void addColumns() {
192 Columns cols =
new Columns();
195 Column col =
new Column(I_.get(
"Exercise"));
196 col.setWidth(
"100px");
197 cols.appendChild(col);
199 col =
new Column(I_.get(
"Status"));
200 col.setWidth(
"150px");
201 cols.appendChild(col);
203 col =
new Column(I_.get(
"Closing"));
205 cols.appendChild(col);
207 col =
new Column(I_.get(
"Renum"));
209 cols.appendChild(col);
211 col =
new Column(I_.get(
"Management"));
213 cols.appendChild(col);
static String getImage(String image)
Set< AccountItem > getNotClosed(int exercise)
boolean existsClosingRegisters(int exercise)
Double get129(int exercise)
Collection< Integer > getExercises()
static String get(String msg)
Rows getRows(boolean create)