18 package org.turro.financials.treasury.m303;
20 import java.text.NumberFormat;
21 import org.turro.elephant.util.DecimalFormats;
22 import org.turro.elephant.util.Images;
23 import org.turro.financials.model.business.CompanyWrapper;
24 import org.turro.i18n.I_;
25 import org.turro.math.Zero;
26 import org.turro.util.CompareUtil;
27 import org.turro.zkoss.dialog.SelectionDialog;
28 import org.turro.zkoss.grid.GroupExtended;
29 import org.turro.zkoss.label.AlertLabel;
30 import org.turro.zkoss.label.LabelTypes;
31 import org.turro.zkoss.layout.AuxheaderAdapter;
32 import org.turro.zkoss.layout.GridLayout;
33 import org.zkoss.zk.ui.HtmlBasedComponent;
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.zul.*;
46 private NumberFormat currencyFormatter;
53 getChildren().clear();
54 Auxhead head =
new Auxhead();
60 setColumns(
"min,right-300px,min,right-300px,min,right-300px,min,right-300px");
75 private void compose() {
80 Row[] rows =
new Row[] {
new Row(),
new Row(),
new Row(),
new Row(),
new Row(),
new Row(),
new Row(),
81 new Row(),
new Row(),
new Row(),
new Row(),
new Row(),
new Row(),
new Row() };
82 for(
int quarter = 0; quarter < 4; quarter++) {
83 composeVats(me.getQuarter(quarter), rows);
86 if(r.getChildren().size() > 1) {
91 GroupExtended ge =
new GroupExtended(I_.get(
"Total"));
94 for(
int quarter = 0; quarter < 4; quarter++) {
95 row.appendChild(
new Space());
96 row.appendChild(getTotalCell(quarter));
101 private void composeVats(EntryQuarter eq, Row[] rows) {
103 for(VatEntry ve : eq.getVatMap().values()) {
104 rows[index].appendChild(
new Label(DecimalFormats.format(ve.getVat())));
105 rows[index].appendChild(getAmountsCell(ve));
108 if(!eq.getVatMap().values().isEmpty()) {
109 rows[index].appendChild(
new Space());
110 rows[index].appendChild(getTaxableCell(eq));
114 private HtmlBasedComponent getAmountsCell(
final VatEntry ve) {
115 boolean notDeclared = Zero.near(modelSet.getDeclaredQuarter(ve.getQuarter().getQuarter() - 1).getAmountDeclared(), 2);
117 gl.addCaption(I_.get(
"Tax"));
118 gl.addComponent(
new Label(currencyFormatter.format(ve.getAmountVat())));
120 gl.addCaption(I_.get(
"Declared"));
121 gl.addComponent(
new AlertLabel(currencyFormatter.format(ve.getDeclaredVat())) {
123 protected int getType() {
124 if(!Zero.near(ve.getDeclaredVat(), 2)) {
125 if(CompareUtil.compare(ve.getAmountVat(), ve.getDeclaredVat()) == 0) {
126 return AlertLabel.ALERT_RIGHT;
128 return AlertLabel.ALERT_WRONG;
135 gl.addCaption(I_.get(
"Pending"));
136 gl.addComponent(
new Label(currencyFormatter.format(ve.getPendingVat())));
138 gl.addCaption(I_.get(
"Taxable"));
139 gl.addComponent(
new Label(currencyFormatter.format(ve.getAmountOp())));
142 gl.addComponent(LabelTypes.getCaptionLabel(I_.get(
"To declare")));
145 gl.addCaption(I_.get(
"Tax"));
146 gl.addComponent(LabelTypes.getCaptionLabel(currencyFormatter.format(ve.getToDeclareAmountVat())));
148 gl.addCaption(I_.get(
"Taxable"));
149 gl.addComponent(LabelTypes.getCaptionLabel(currencyFormatter.format(ve.getToDeclareAmountOp())));
154 private HtmlBasedComponent getBreakdownCell(
final EntryQuarter eq) {
155 Toolbarbutton breakdown =
new Toolbarbutton(I_.get(
"Breakdown"), Images.getImage(
"breakdown-open"));
156 breakdown.addEventListener(Events.ON_CLICK,
new EventListener() {
158 public void onEvent(Event event)
throws Exception {
159 SelectionDialog.showComponent(getPage(), I_.get(
"Breakdown"),
160 new Model349List(eq),
"750px",
"70%",
null);
166 private HtmlBasedComponent getTaxableCell(
final EntryQuarter eq) {
167 boolean notDeclared = Zero.near(modelSet.getDeclaredQuarter(eq.getQuarter() - 1).getAmountDeclared(), 2);
168 GridLayout gl =
new GridLayout(
"100%,right-160px");
169 gl.addCaption(I_.get(
"Total"));
170 gl.addComponent(
new Label(currencyFormatter.format(eq.getTotalOp())));
173 gl.addComponent(LabelTypes.getCaptionLabel(I_.get(
"To declare")));
176 gl.addCaption(I_.get(
"Tax"));
177 gl.addComponent(LabelTypes.getCaptionLabel(currencyFormatter.format(eq.getToDeclareTotalVat())));
179 gl.addCaption(I_.get(
"Taxable"));
180 gl.addComponent(LabelTypes.getCaptionLabel(currencyFormatter.format(eq.getToDeclareTotalOp())));
183 gl.addComponent(getBreakdownCell(eq));
184 gl.addComponent(LabelTypes.getTinyLabel(currencyFormatter.format(eq.getAmountOp())));
188 private HtmlBasedComponent getTotalCell(
final int quarter) {
189 final double inputVat = modelSet.getTotalInputVat(quarter),
190 outputVat = modelSet.getTotalOutputVat(quarter);
191 GridLayout gl =
new GridLayout(
"100%,right-160px");
192 gl.addCaption(I_.get(
"Input VAT"));
193 gl.addComponent(
new Label(currencyFormatter.format(inputVat)));
195 gl.addCaption(I_.get(
"Output VAT"));
196 gl.addComponent(
new Label(currencyFormatter.format(outputVat)));
197 final double declared = modelSet.getDeclaredQuarter(quarter).getAmountDeclared();
199 gl.addCaption(I_.get(
"Declared"));
200 gl.addComponent(
new AlertLabel(currencyFormatter.format(Math.abs(declared))) {
202 protected int getType() {
203 if(Zero.near((outputVat - inputVat) - declared, 2)) {
204 return AlertLabel.ALERT_RIGHT;
206 return AlertLabel.ALERT_WRONG;
210 if(Zero.near(declared, 2)) {
212 Button b =
new Button(I_.get(
"Register"));
213 b.addEventListener(Events.ON_CLICK,
new EventListener() {
215 public void onEvent(Event event)
throws Exception {
216 modelSet.generateRegister(quarter);
220 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)