Invoice payment modified according to requests (payment list bugfix needed)
authorVásáry Dániel <vasary@elgekko.net>
Tue, 28 Nov 2023 10:25:21 +0000 (11:25 +0100)
committerVásáry Dániel <vasary@elgekko.net>
Tue, 28 Nov 2023 10:25:21 +0000 (11:25 +0100)
TODO.txt
lis-ui/src/main/java/hu/user/lis/ui/view/InvoicePaymentViewModel.java
lis-ui/src/main/resources/web/invoice-payment.zul

index 2f0a3f05950d08a8bc226310cc3e8c2cb78b3079..bd33dbca8a5ac8da21c3fde1bf9a45b7c9f157bc 100644 (file)
--- 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.
index be29ec0dcd2e5256e56952fc69d593ecaae668d4..df2a1a98ca32218a3c399cef1f48d76cb549b0cd 100644 (file)
@@ -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<Payment> 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<Payment> 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<Payment> 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<Payment> 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<Payment> implements
     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);
+    }
+
 
 }
index 6e93ea30536ba7b1e103d5d7f904e39ba03f681b..51dafd004090633d901d4e8b6c7a06a4d15d12bc 100644 (file)
                         <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>