19 package org.turro.financials.treasury.m303m;
21 import java.text.NumberFormat;
22 import org.turro.elephant.util.DecimalFormats;
23 import org.turro.elephant.util.Images;
24 import org.turro.financials.model.business.CompanyWrapper;
25 import org.turro.i18n.I_;
26 import org.turro.math.Zero;
27 import org.turro.util.CompareUtil;
28 import org.turro.zkoss.dialog.SelectionDialog;
29 import org.turro.zkoss.grid.GroupExtended;
30 import org.turro.zkoss.label.AlertLabel;
31 import org.turro.zkoss.label.LabelTypes;
32 import org.turro.zkoss.layout.AuxheaderAdapter;
33 import org.turro.zkoss.layout.GridLayout;
34 import org.zkoss.zk.ui.HtmlBasedComponent;
35 import org.zkoss.zk.ui.event.Event;
36 import org.zkoss.zk.ui.event.EventListener;
37 import org.zkoss.zk.ui.event.Events;
38 import org.zkoss.zul.Auxhead;
39 import org.zkoss.zul.Button;
40 import org.zkoss.zul.Label;
41 import org.zkoss.zul.Row;
42 import org.zkoss.zul.Space;
43 import org.zkoss.zul.Toolbarbutton;
52 private NumberFormat currencyFormatter;
59 getChildren().clear();
60 Auxhead head =
new Auxhead();
74 setColumns(
"min,right-300px,min,right-300px,min,right-300px,min,right-300px," +
75 "min,right-300px,min,right-300px,min,right-300px,min,right-300px," +
76 "min,right-300px,min,right-300px,min,right-300px,min,right-300px,");
107 private void compose() {
112 Row[] rows =
new Row[] {
new Row(),
new Row(),
new Row(),
new Row(),
new Row(),
new Row(),
new Row(),
113 new Row(),
new Row(),
new Row(),
new Row(),
new Row(),
new Row(),
new Row() };
114 for(
int month = 0; month < 12; month++) {
115 composeVats(me.getMonth(month), rows);
118 if(r.getChildren().size() > 1) {
123 GroupExtended ge =
new GroupExtended(I_.get(
"Total"));
126 for(
int month = 0; month < 12; month++) {
127 row.appendChild(
new Space());
128 row.appendChild(getTotalCell(month));
133 private void composeVats(EntryMonth em, Row[] rows) {
135 for(VatEntry ve : em.getVatMap().values()) {
136 rows[index].appendChild(
new Label(DecimalFormats.format(ve.getVat())));
137 rows[index].appendChild(getAmountsCell(ve));
140 if(!em.getVatMap().values().isEmpty()) {
141 rows[index].appendChild(
new Space());
142 rows[index].appendChild(getTaxableCell(em));
146 private HtmlBasedComponent getAmountsCell(
final VatEntry ve) {
147 boolean notDeclared = Zero.near(modelSet.getDeclaredMonth(ve.getMonth().getMonth() - 1).getAmountDeclared(), 2);
149 gl.addCaption(I_.get(
"Tax"));
150 gl.addComponent(
new Label(currencyFormatter.format(ve.getAmountVat())));
152 gl.addCaption(I_.get(
"Declared"));
153 gl.addComponent(
new AlertLabel(currencyFormatter.format(ve.getDeclaredVat())) {
155 protected int getType() {
156 if(!Zero.near(ve.getDeclaredVat(), 2)) {
157 if(CompareUtil.compare(ve.getAmountVat(), ve.getDeclaredVat()) == 0) {
158 return AlertLabel.ALERT_RIGHT;
160 return AlertLabel.ALERT_WRONG;
167 gl.addCaption(I_.get(
"Pending"));
168 gl.addComponent(
new Label(currencyFormatter.format(ve.getPendingVat())));
170 gl.addCaption(I_.get(
"Taxable"));
171 gl.addComponent(
new Label(currencyFormatter.format(ve.getAmountOp())));
174 gl.addComponent(LabelTypes.getCaptionLabel(I_.get(
"To declare")));
177 gl.addCaption(I_.get(
"Tax"));
178 gl.addComponent(LabelTypes.getCaptionLabel(currencyFormatter.format(ve.getToDeclareAmountVat())));
180 gl.addCaption(I_.get(
"Taxable"));
181 gl.addComponent(LabelTypes.getCaptionLabel(currencyFormatter.format(ve.getToDeclareAmountOp())));
186 private HtmlBasedComponent getBreakdownCell(
final EntryMonth em) {
187 Toolbarbutton breakdown =
new Toolbarbutton(I_.get(
"Breakdown"), Images.getImage(
"breakdown-open"));
188 breakdown.addEventListener(Events.ON_CLICK,
new EventListener() {
190 public void onEvent(Event event)
throws Exception {
191 SelectionDialog.showComponent(getPage(), I_.get(
"Breakdown"),
192 new Model349List(em),
"750px",
"70%",
null);
198 private HtmlBasedComponent getTaxableCell(
final EntryMonth em) {
199 boolean notDeclared = Zero.near(modelSet.getDeclaredMonth(em.getMonth()- 1).getAmountDeclared(), 2);
200 GridLayout gl =
new GridLayout(
"100%,right-160px");
201 gl.addCaption(I_.get(
"Total"));
202 gl.addComponent(
new Label(currencyFormatter.format(em.getTotalOp())));
205 gl.addComponent(LabelTypes.getCaptionLabel(I_.get(
"To declare")));
208 gl.addCaption(I_.get(
"Tax"));
209 gl.addComponent(LabelTypes.getCaptionLabel(currencyFormatter.format(em.getToDeclareTotalVat())));
211 gl.addCaption(I_.get(
"Taxable"));
212 gl.addComponent(LabelTypes.getCaptionLabel(currencyFormatter.format(em.getToDeclareTotalOp())));
215 gl.addComponent(getBreakdownCell(em));
216 gl.addComponent(LabelTypes.getTinyLabel(currencyFormatter.format(em.getAmountOp())));
220 private HtmlBasedComponent getTotalCell(
final int month) {
221 final double inputVat = modelSet.getTotalInputVat(month),
222 outputVat = modelSet.getTotalOutputVat(month);
223 GridLayout gl =
new GridLayout(
"100%,right-160px");
224 gl.addCaption(I_.get(
"Input VAT"));
225 gl.addComponent(
new Label(currencyFormatter.format(inputVat)));
227 gl.addCaption(I_.get(
"Output VAT"));
228 gl.addComponent(
new Label(currencyFormatter.format(outputVat)));
229 final double declared = modelSet.getDeclaredMonth(month).getAmountDeclared();
231 gl.addCaption(I_.get(
"Declared"));
232 gl.addComponent(
new AlertLabel(currencyFormatter.format(Math.abs(declared))) {
234 protected int getType() {
235 if(Zero.near((outputVat - inputVat) - declared, 2)) {
236 return AlertLabel.ALERT_RIGHT;
238 return AlertLabel.ALERT_WRONG;
242 if(Zero.near(declared, 2)) {
244 Button b =
new Button(I_.get(
"Register"));
245 b.addEventListener(Events.ON_CLICK,
new EventListener() {
247 public void onEvent(Event event)
throws Exception {
248 modelSet.generateRegister(month);
252 gl.addComponent(
new Label(currencyFormatter.format(Math.abs(outputVat - inputVat))));
static NumberFormat getCurrencyFormatter()
void setExercise(int exercise)
static String byKey(String key)
static String get(String msg)
void setColCaptions(String captions)
void setColumns(int columns)
Rows getRows(boolean create)