import lombok.Setter;
import lombok.extern.log4j.Log4j2;
import org.zkoss.bind.BindUtils;
-import org.zkoss.bind.annotation.BindingParam;
-import org.zkoss.bind.annotation.Command;
-import org.zkoss.bind.annotation.Init;
-import org.zkoss.bind.annotation.NotifyChange;
+import org.zkoss.bind.annotation.*;
+import org.zkoss.zk.ui.Component;
import org.zkoss.zk.ui.event.Event;
import org.zkoss.zk.ui.event.EventListener;
import org.zkoss.zk.ui.select.annotation.WireVariable;
+import org.zkoss.zk.ui.util.Clients;
import org.zkoss.zk.ui.util.Notification;
import org.zkoss.zul.ListModelList;
EntitySelectorRouter entitySelectorRouter;
@Getter
- @Setter
Invoice formDocument;
- @Getter
- @Setter
- private Payment selectedPayment;
-
@WireVariable
private EventBus eventBus;
public void init() {
super.init();
eventBus.register(this);
- setReadonlyForm(true);
-// addColumns(ImmutableMap.of(
-// "partner.name", ASCENDING,
-// "partner.vatNr", NATURAL,
-// "project.name", NATURAL,
-// "paymentDeadline", NATURAL,
-// "grossAmount", NATURAL,
-// "currency", NATURAL,
-// "incoming", NATURAL
-// ));
+ //setReadonlyForm(false);
+ }
+
+ @AfterCompose
+ public void onAfterCompose(@ContextParam(ContextType.VIEW) Component view) {
+ BindUtils.postNotifyChange(this, "formDocument");
}
@Override
}
private void showEditor(Invoice invoice) {
- paymentsDataModel.search(invoice);
formDocument = invoice;
- getEntitySelectorRouter().configureSelector(Partner.class, getFormDocument(), "partner");
- paymentsDataModel.search(invoice);
+ getEntitySelectorRouter().configureSelector(Partner.class, formDocument, "partner");
+ paymentsDataModel.search(formDocument);
BindUtils.postNotifyChange(this, "formDocument");
}
@Command
public void onCreatePayment() {
- if (Objects.nonNull(getFormDocument())) {
- paymentsDataModel.create(getFormDocument());
- paymentsDataModel.search(getFormDocument());
+ if (Objects.nonNull(formDocument)) {
+ paymentsDataModel.create(formDocument);
+ paymentsDataModel.search(formDocument);
}
}
@Command
@NotifyChange({"newPaymentDisabled", "formDocument"})
- public void onDeletePayment() {
+ public void onDeletePayment(@BindingParam("item") Payment selectedPayment) {
if (Objects.nonNull(selectedPayment)) {
paymentsDataModel.delete(selectedPayment);
- paymentsDataModel.search(getFormDocument());
+ paymentsDataModel.search(formDocument);
updateInvoiceStatus();
}
}
}
private void updateInvoiceStatus() {
- if (Objects.nonNull(getFormDocument())) {
- double paymentsSum = paymentsDataModel.getInnerList().stream().map(Payment::getNetAmount).reduce(0d, Double::sum);
- newPaymentDisabled = getFormDocument().getNetAmount() <= paymentsSum;
- getFormDocument().setPaid(newPaymentDisabled);
- invoiceRepository.save(getFormDocument());
+ if (Objects.nonNull(formDocument)) {
+ double paymentsSum = paymentsDataModel.getInnerList().stream().map(Payment::getGrossAmount).reduce(0d, Double::sum);
+ newPaymentDisabled = formDocument.getGrossAmount() == paymentsSum;
+ if (newPaymentDisabled != formDocument.isPaid()) {
+ formDocument.setPaid(newPaymentDisabled);
+ invoiceRepository.save(formDocument);
+ if (newPaymentDisabled) {
+ Clients.showNotification("A számla kiegyenlítés megtörtént.", "info", null, null, 3000);
+ }
+ }
+
+ if (formDocument.getGrossAmount() < paymentsSum) {
+ Clients.showNotification("A kiegyenlítések összege meghaladja a számla végösszegét.", "warning", null, null, 3000);
+ }
}
}
public void onEvent(Event event) throws Exception {
if (SET_INVOICE_PAYMENT_DATA.equals(event.getName())) {
Optional<Invoice> opInvoice = invoiceRepository.findById(((InvoicePaymentData) event).getId());
- opInvoice.ifPresent(invoice -> {
- this.showEditor(invoice);
+ if (opInvoice.isPresent()) {
+ Invoice invoice = opInvoice.get();
invoiceNumber = invoice.getHumanId();
+ BindUtils.postNotifyChange(this, "invoiceNumber");
filterPartner = null;
setPartnerRequired(false);
BindUtils.postNotifyChange(this, "partnerRequired");
- BindUtils.postNotifyChange(this, "invoiceNumber");
- });
+ this.showEditor(invoice);
+ }
}
}
+ @Command
+ public void onRefresh() {
+ if (Objects.nonNull(formDocument)) {
+ paymentsDataModel.search(formDocument);
+ }
+ }
+
+ @Destroy
+ public void onDestroy() {
+
+ eventBus.unregister(this);
+ }
+
}
<borderlayout>
<north hflex="true">
<toolbar>
+ <toolbarbutton label="Frissít" iconSclass="z-icon-refresh"
+ onClick="@command('onRefresh')"/>
<toolbarbutton label="Hozzáadás" iconSclass="z-icon-plus"
onClick="@command('onCreatePayment')"
disabled="@bind(vm.newPaymentDisabled)"/>
- <toolbarbutton label="Törlés" iconSclass="z-icon-remove"
- onClick="@command('onDeletePayment')"
- disabled="@load(empty vm.selectedPayment)"/>
</toolbar>
</north>
<center border="none" hflex="true" vflex="true">
<listbox vflex="true" model="@load(vm.paymentsDataModel)"
- autopaging="true" pagingPosition="top" multiple="false"
- selectedItem="@bind(vm.selectedPayment)">
+ autopaging="true" pagingPosition="top" multiple="false">
<listhead sizable="true">
- <listheader label="Dátum" align="left"/>
- <listheader label="Nettó összeg" align="right"/>
- <listheader label="Bruttó összeg" align="right"/>
- <listheader label="ÁFA összeg" align="right"/>
+ <listheader label="Dátum" align="left" hflex="true"/>
+ <!-- <listheader label="Nettó összeg" align="right"/>-->
+ <listheader label="Bruttó összeg" align="right" hflex="true"/>
+ <!-- <listheader label="ÁFA összeg" align="right" hflex="true"/>-->
+ <listheader label="Törlés" align="right" hflex="min"/>
</listhead>
<template name="model">
<listitem>
format="yyyy. MM. dd." inplace="true" width="100%"
onChange="@command('onPaymentChanged', entity=each)"/>
</listcell>
- <listcell>
- <doublebox value="@bind(each.netAmount)"
- format="#,###.##" locale="hu" inplace="true" width="100%"
- onChange="@command('onPaymentChanged', entity=each)"/>
- </listcell>
+ <!-- <listcell>-->
+ <!-- <doublebox value="@bind(each.netAmount)"-->
+ <!-- format="#,###.##" locale="hu" inplace="true" width="100%"-->
+ <!-- onChange="@command('onPaymentChanged', entity=each)"/>-->
+ <!-- </listcell>-->
<listcell>
<doublebox value="@bind(each.grossAmount)"
- format="#,###.##" locale="hu" inplace="true" width="100%"
+ format="#,###.##" locale="hu" inplace="true" instant="true"
+ width="100%"
onChange="@command('onPaymentChanged', entity=each)"/>
</listcell>
<listcell>
- <doublebox value="@bind(each.vatAmount)"
- format="#,###.##" locale="hu" inplace="true" width="100%"
- onChange="@command('onPaymentChanged', entity=each)"/>
+ <button iconSclass="z-icon-remove"
+ onClick="@command('onDeletePayment', item=each)"/>
</listcell>
</listitem>
</template>