From 83faa69c9dc77a21d0ac539afab7ff45dcd55490 Mon Sep 17 00:00:00 2001 From: =?utf8?q?V=C3=A1s=C3=A1ry=20D=C3=A1niel?= Date: Tue, 28 Nov 2023 11:25:21 +0100 Subject: [PATCH] Invoice payment modified according to requests (payment list bugfix needed) --- TODO.txt | 5 ++ .../lis/ui/view/InvoicePaymentViewModel.java | 84 +++++++++++-------- .../main/resources/web/invoice-payment.zul | 35 ++++---- 3 files changed, 70 insertions(+), 54 deletions(-) diff --git a/TODO.txt b/TODO.txt index 2f0a3f0..bd33dbc 100644 --- a/TODO.txt +++ b/TODO.txt @@ -4,6 +4,11 @@ - távlati: banki integráció - távlati: táblák exportja + +* tervezett számla is kiegyenlíthető? +* mi a a számla import és tervezett számla kezelésének metódusa? + + Számla import ------------- Javításra váró számlák lista kezelése: az elvetett vagy meg nem érkezett számlákat egy külön listába kell tenni. diff --git a/lis-ui/src/main/java/hu/user/lis/ui/view/InvoicePaymentViewModel.java b/lis-ui/src/main/java/hu/user/lis/ui/view/InvoicePaymentViewModel.java index be29ec0..df2a1a9 100644 --- a/lis-ui/src/main/java/hu/user/lis/ui/view/InvoicePaymentViewModel.java +++ b/lis-ui/src/main/java/hu/user/lis/ui/view/InvoicePaymentViewModel.java @@ -16,13 +16,12 @@ import lombok.Getter; 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; @@ -43,13 +42,8 @@ public class InvoicePaymentViewModel extends EntityViewModel implements EntitySelectorRouter entitySelectorRouter; @Getter - @Setter Invoice formDocument; - @Getter - @Setter - private Payment selectedPayment; - @WireVariable private EventBus eventBus; @@ -86,16 +80,12 @@ public class InvoicePaymentViewModel extends EntityViewModel implements 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 @@ -146,27 +136,26 @@ public class InvoicePaymentViewModel extends EntityViewModel implements } 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(); } } @@ -179,11 +168,20 @@ public class InvoicePaymentViewModel extends EntityViewModel implements } 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); + } } } @@ -192,16 +190,30 @@ public class InvoicePaymentViewModel extends EntityViewModel implements public void onEvent(Event event) throws Exception { if (SET_INVOICE_PAYMENT_DATA.equals(event.getName())) { Optional 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); + } + } diff --git a/lis-ui/src/main/resources/web/invoice-payment.zul b/lis-ui/src/main/resources/web/invoice-payment.zul index 6e93ea3..51dafd0 100644 --- a/lis-ui/src/main/resources/web/invoice-payment.zul +++ b/lis-ui/src/main/resources/web/invoice-payment.zul @@ -35,23 +35,22 @@ + -
+ autopaging="true" pagingPosition="top" multiple="false"> - - - - + + + + + -- 2.54.0