Reset DB table identities, add invoice payment, add project id regexp
authorVásáry Dániel <vasary@elgekko.net>
Tue, 24 Oct 2023 14:31:37 +0000 (16:31 +0200)
committerVásáry Dániel <vasary@elgekko.net>
Tue, 24 Oct 2023 14:31:37 +0000 (16:31 +0200)
17 files changed:
.idea/misc.xml
lis-db/migrations/README
lis-db/migrations/scripts/010_reset_partner_index.sql
lis-db/migrations/scripts/011_reset_project_index.sql
lis-db/migrations/scripts/015_reset_project_status_index.sql [new file with mode: 0644]
lis-db/src/main/java/hu/user/lis/db/repository/InvoiceRepository.java
lis-db/src/main/java/hu/user/lis/db/repository/PaymentRepository.java
lis-ui/src/main/java/hu/user/lis/ui/Constants.java
lis-ui/src/main/java/hu/user/lis/ui/converter/PartnerConverter.java [new file with mode: 0644]
lis-ui/src/main/java/hu/user/lis/ui/converter/ProjectStatusConverter.java
lis-ui/src/main/java/hu/user/lis/ui/data/InvoicesDataModel.java
lis-ui/src/main/java/hu/user/lis/ui/data/PaymentsDataModel.java [new file with mode: 0644]
lis-ui/src/main/java/hu/user/lis/ui/view/InvoicePaymentViewModel.java [new file with mode: 0644]
lis-ui/src/main/java/hu/user/lis/ui/view/InvoicesViewModel.java
lis-ui/src/main/resources/web/index.zul
lis-ui/src/main/resources/web/invoice-payment.zul
runConfigurations/server-dev.run.xml

index 509fbe32e408920e84d5f707413625f13a480fff..88fda26e7f4798fce90f7640510aee531eb9e176 100644 (file)
@@ -17,7 +17,7 @@
       </list>
     </option>
   </component>
-  <component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" project-jdk-name="semeru-1.8" project-jdk-type="JavaSDK" />
+  <component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" project-jdk-name="1.8" project-jdk-type="JavaSDK" />
   <component name="ProjectType">
     <option name="id" value="jpab" />
   </component>
index 70fd38d7e4930d99004027a831be8ac005eb6a2f..2851db15231f5d9db6b4bcd90ea7dd2387882063 100644 (file)
@@ -48,8 +48,10 @@ Enjoy.
 
 
 DOCKER
-docker pull ibmcom/db2
-docker run -itd --name ibmdb2 --privileged=true -p 50000:50000 -e LICENSE=accept -e DB2INSTANCE=db2admin -e DB2INST1_PASSWORD=password -e DBNAME=lis -e PERSISTENT_HOME=false -v /docker/ibmdb2:/database ibmcom/db2
+# docker pull ibmcom/db2
+mkdir -R /data/db2
+chmod -R 777 /data/db2
+docker run -itd --name ibmdb2 --privileged=true -p 50000:50000 -e LICENSE=accept -e DB2INSTANCE=db2admin -e DB2INST1_PASSWORD=password -e DBNAME=lis -e PERSISTENT_HOME=false -v /data/db2:/database ibmcom/db2
 docker logs -f lis
 docker exec -it lis bash
 docker stop lis
index 99f2ed603aace5d7b2255456e48555189792ea72..16fbb70044f011bada21048705ffbcd9868fa090 100644 (file)
@@ -1,7 +1,7 @@
 -- // reset partner index
 -- Migration SQL that makes the change goes here.
 
-ALTER TABLE PARTNER ALTER COLUMN id RESTART WITH 4;
+ALTER TABLE partner ALTER COLUMN id RESTART WITH 4;
 
 -- //@UNDO
 -- SQL to undo the change goes here.
index ff882d8ca77cacd0ad14b78ccf45e385fd68132e..93499022dfecf93d5fd45e91e04d3f6a6d7d502e 100644 (file)
@@ -1,7 +1,7 @@
 -- // reset project index
 -- Migration SQL that makes the change goes here.
 
-ALTER TABLE PROJECT ALTER COLUMN id RESTART WITH 2;
+ALTER TABLE project ALTER COLUMN id RESTART WITH 2;
 
 -- //@UNDO
 -- SQL to undo the change goes here.
diff --git a/lis-db/migrations/scripts/015_reset_project_status_index.sql b/lis-db/migrations/scripts/015_reset_project_status_index.sql
new file mode 100644 (file)
index 0000000..fad2834
--- /dev/null
@@ -0,0 +1,9 @@
+-- // reset project index
+-- Migration SQL that makes the change goes here.
+
+ALTER TABLE project_status ALTER COLUMN id RESTART WITH 2;
+
+-- //@UNDO
+-- SQL to undo the change goes here.
+
+
index da74be71e3bf1ae1f05d12fcda3e65bf271999ec..0c6ef8b1a5626c9a8e1e6603b1b05ca3ed2c7207 100644 (file)
@@ -1,8 +1,16 @@
 package hu.user.lis.db.repository;
 
 import hu.user.lis.db.Invoice;
+import hu.user.lis.db.Partner;
 import org.springframework.data.jpa.repository.JpaRepository;
 
+import java.util.List;
+import java.util.Optional;
+
 public interface InvoiceRepository extends JpaRepository<Invoice, Long>, InvoiceRepositorySearch {
 
+    List<Invoice> findByHumanId(String humanId);
+
+    Optional<Invoice> findByHumanIdAndPartner(String humanId, Partner partner);
+
 }
index 8860d62b72fbc9f7ad5e7ad9845ac638ac1da181..0dd136e91e26c208b29a5ac6fd26b4aa99db715e 100644 (file)
@@ -8,6 +8,7 @@ import java.util.List;
 
 public interface PaymentRepository extends JpaRepository<Payment, Long> {
 
-    List<Payment> findAllByInvoice(Invoice invoice);
+    List<Payment> findAllByInvoiceOrderByPaymentDateDesc(Invoice invoice);
 
+    long countByInvoice(Invoice invoice);
 }
index 83b15cd6de160b274c8a46ca785ab14fa71974e0..cbf9e29edde908657e5c756b034c2708b8c93e02 100644 (file)
@@ -1,5 +1,9 @@
 package hu.user.lis.ui;
 
+import lombok.AccessLevel;
+import lombok.NoArgsConstructor;
+
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
 public class Constants {
     public static final String BINDING_QUEUE = "$ZKBIND_DEFQUE$";
     public static final String PROJECT_EDITOR_QUEUE = "PROJECT_EDITOR_QUEUE";
@@ -26,8 +30,6 @@ public class Constants {
     public static final String NAV_LOGIN = "/login";
     public static final String NAV_LOGOUT = "/logout";
     public static final String NAV_ROOT = "/";
-
     public static final String NAV_API = "/api";
-
     public static final String WIDGET_ENTITY_SELECTOR = "~./widget/entity-selector.zul";
 }
diff --git a/lis-ui/src/main/java/hu/user/lis/ui/converter/PartnerConverter.java b/lis-ui/src/main/java/hu/user/lis/ui/converter/PartnerConverter.java
new file mode 100644 (file)
index 0000000..95c1725
--- /dev/null
@@ -0,0 +1,36 @@
+package hu.user.lis.ui.converter;
+
+import hu.user.lis.db.Partner;
+import org.springframework.stereotype.Component;
+import org.zkoss.bind.BindContext;
+import org.zkoss.bind.Converter;
+import org.zkoss.zul.ListModel;
+import org.zkoss.zul.Selectbox;
+import org.zkoss.zul.ext.Selectable;
+
+import java.util.Objects;
+
+@Component
+public class PartnerConverter implements Converter<Object, Partner, Selectbox> {
+    @Override
+    public Object coerceToUi(Partner entity, Selectbox bandbox, BindContext bindContext) {
+        if (Objects.isNull(entity)) {
+            return IGNORED_VALUE;
+        }
+        ListModel<?> model = bandbox.getModel();
+        ((Selectable<Object>) model).clearSelection();
+        for (int i = 0; i < model.getSize(); i++) {
+            Partner status = (Partner) model.getElementAt(i);
+            if (status.getId().equals(entity.getId())) {
+                return i;
+            }
+        }
+        return IGNORED_VALUE;
+    }
+
+    @Override
+    public Partner coerceToBean(Object order, Selectbox bandbox, BindContext bindContext) {
+        ListModel<Partner> model = bandbox.getModel();
+        return model.getElementAt((int) order);
+    }
+}
\ No newline at end of file
index 75b10f8bb59bc0f22c489e321f6ace82dd5750da..05d1bfa34d03cd1daf193addf51399164ff975eb 100644 (file)
@@ -1,8 +1,6 @@
 package hu.user.lis.ui.converter;
 
 import hu.user.lis.db.ProjectStatus;
-import hu.user.lis.db.repository.ProjectStatusRepository;
-import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 import org.zkoss.bind.BindContext;
 import org.zkoss.bind.Converter;
@@ -14,8 +12,8 @@ import java.util.Objects;
 
 @Component
 public class ProjectStatusConverter implements Converter<Object, ProjectStatus, Selectbox> {
-    @Autowired
-    ProjectStatusRepository projectStatusRepository;
+//    @Autowired
+//    ProjectStatusRepository projectStatusRepository;
 
     @Override
     public Object coerceToUi(ProjectStatus projectStatus, Selectbox box, BindContext bindContext) {
@@ -35,6 +33,8 @@ public class ProjectStatusConverter implements Converter<Object, ProjectStatus,
 
     @Override
     public ProjectStatus coerceToBean(Object order, Selectbox bandbox, BindContext bindContext) {
-        return projectStatusRepository.findByOrder((Integer) order + 1);
+        ListModel<ProjectStatus> model = bandbox.getModel();
+        return model.getElementAt((int) order);
+//        return projectStatusRepository.findByOrder((Integer) order + 1);
     }
 }
\ No newline at end of file
index 3468cdf545080c418bfc84b6128414afea78c37d..4c1a9e0f09dc4950bd31a9d340d1687a95f8c579 100644 (file)
@@ -16,8 +16,8 @@ import java.util.List;
 import java.util.Objects;
 import java.util.Optional;
 
-@Component
 @Log4j2
+@Component
 @Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
 public class InvoicesDataModel extends CachedSpringDataModel<Invoice> {
     @Autowired
diff --git a/lis-ui/src/main/java/hu/user/lis/ui/data/PaymentsDataModel.java b/lis-ui/src/main/java/hu/user/lis/ui/data/PaymentsDataModel.java
new file mode 100644 (file)
index 0000000..9f2bb28
--- /dev/null
@@ -0,0 +1,52 @@
+package hu.user.lis.ui.data;
+
+import hu.user.lis.db.Invoice;
+import hu.user.lis.db.Payment;
+import hu.user.lis.db.repository.PaymentRepository;
+import hu.user.lis.service.data.EntityDataService;
+import hu.user.lis.ui.data.common.CachedSpringDataModel;
+import lombok.extern.log4j.Log4j2;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.config.ConfigurableBeanFactory;
+import org.springframework.context.annotation.Scope;
+import org.springframework.stereotype.Component;
+import org.zkoss.zul.FieldComparator;
+
+import java.util.List;
+
+@Log4j2
+@Component
+@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
+public class PaymentsDataModel extends CachedSpringDataModel<Payment> {
+
+    @Autowired
+    private PaymentRepository paymentRepository;
+
+    @Autowired
+    private EntityDataService<Payment> paymenssDataService;
+
+    private Invoice invoice;
+
+    public void save(Payment modifiedEntity) {
+        paymentRepository.save(modifiedEntity);
+    }
+
+    public void delete(Payment selectedPayment) {
+        paymentRepository.delete(selectedPayment);
+    }
+
+    @Override
+    public List<Payment> getResultSet(int page, int pageSize, FieldComparator sortComparator) {
+        return paymentRepository.findAllByInvoiceOrderByPaymentDateDesc(invoice);
+    }
+
+    @Override
+    public int getResultSetCount() {
+        return (int) paymentRepository.countByInvoice(invoice);
+    }
+
+    public void search(Invoice invoice) {
+        this.invoice = invoice;
+        super.reset();
+    }
+}
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
new file mode 100644 (file)
index 0000000..001fe74
--- /dev/null
@@ -0,0 +1,121 @@
+package hu.user.lis.ui.view;
+
+import hu.user.lis.db.Invoice;
+import hu.user.lis.db.Partner;
+import hu.user.lis.db.Payment;
+import hu.user.lis.db.repository.InvoiceRepository;
+import hu.user.lis.ui.Constants;
+import hu.user.lis.ui.converter.PartnerConverter;
+import hu.user.lis.ui.data.PaymentsDataModel;
+import hu.user.lis.ui.data.common.CachedSpringDataModel;
+import hu.user.lis.ui.editor.selector.EntitySelectorRouter;
+import hu.user.lis.ui.event.EventBus;
+import hu.user.lis.ui.view.common.EntityViewModel;
+import lombok.Getter;
+import lombok.Setter;
+import lombok.extern.log4j.Log4j2;
+import org.zkoss.bind.annotation.Command;
+import org.zkoss.bind.annotation.Init;
+import org.zkoss.bind.annotation.NotifyChange;
+import org.zkoss.zk.ui.select.annotation.WireVariable;
+import org.zkoss.zul.ListModelList;
+
+import java.util.List;
+import java.util.Objects;
+import java.util.Optional;
+
+@Log4j2
+public class InvoicePaymentViewModel extends EntityViewModel<Payment> {
+
+    @Getter
+    private final ListModelList<Partner> partners = new ListModelList<>();
+
+    @Getter
+    @WireVariable
+    EntitySelectorRouter entitySelectorRouter;
+
+    @WireVariable
+    private EventBus eventBus;
+
+    @Getter
+    @Setter
+    private Partner filterPartner;
+
+    @Getter
+    @Setter
+    private Invoice selectedInvoice;
+
+    @Getter
+    @Setter
+    private String invoiceNumber;
+
+    @WireVariable
+    private InvoiceRepository invoiceRepository;
+
+    @Getter
+    @WireVariable
+    private PaymentsDataModel paymentsDataModel;
+
+    @Getter
+    @WireVariable
+    private PartnerConverter partnerConverter;
+
+    @Getter
+    @Setter
+    private boolean partnerRequired;
+
+    @Init
+    @Override
+    public void init() {
+        super.init();
+//        addColumns(ImmutableMap.of(
+//                "partner.name", ASCENDING,
+//                "partner.vatNr", NATURAL,
+//                "project.name", NATURAL,
+//                "paymentDeadline", NATURAL,
+//                "grossAmount", NATURAL,
+//                "currency", NATURAL,
+//                "incoming", NATURAL
+//        ));
+    }
+
+    @Override
+    protected CachedSpringDataModel<Payment> getDataModel() {
+        return paymentsDataModel;
+    }
+
+    @Override
+    protected String getNavigation() {
+        return Constants.NAV_INVOICE_PAYMENT;
+    }
+
+    @Command
+    @NotifyChange("partnerRequired")
+    public void search() {
+        paymentsDataModel.clearSelection();
+        paymentsDataModel.clear();
+        if (Objects.isNull(filterPartner)) {
+            List<Invoice> invoices = invoiceRepository.findByHumanId(invoiceNumber);
+            if (invoices.isEmpty()) {
+                setPartnerRequired(false);
+                //show message
+            } else {
+                if (invoices.size() == 1) {
+                    setPartnerRequired(false);
+                    showEditor(invoices.get(0));
+                } else {
+                    setPartnerRequired(true);
+                    partners.clear();
+                    invoices.forEach(invoice -> partners.add(invoice.getPartner()));
+                }
+            }
+        } else {
+            Optional<Invoice> opInvoice = invoiceRepository.findByHumanIdAndPartner(invoiceNumber, filterPartner);
+            opInvoice.ifPresent(this::showEditor);
+        }
+    }
+
+    private void showEditor(Invoice invoice) {
+        paymentsDataModel.search(invoice);
+    }
+}
index 61e74d246789501bca66470125ad4dd7e15d03fb..a3da68a3cccc6f455d3d2ebaca47e6836f89c765 100644 (file)
@@ -30,16 +30,11 @@ import static hu.user.lis.ui.data.common.CachedDataModel.NATURAL;
 public class InvoicesViewModel extends EntityViewModel<Invoice> implements EventListener<Event> {
     @Getter
     private final InvoiceFilter invoiceFilter = InvoiceFilter.builder().incoming(true).build();
-
-    @Getter
-    @WireVariable
-    EntitySelectorRouter entitySelectorRouter;
-
     @WireVariable
     private EventBus eventBus;
-
-    //    private boolean filterShowIncoming;
-//    private boolean filterShowOutgoing;
+    @Getter
+    @WireVariable
+    private EntitySelectorRouter entitySelectorRouter;
     @Getter
     @WireVariable
     private InvoicesDataModel invoicesDataModel;
index 97d900cb6784eb3a34e31ed9b9f34b062a0f0657..4138e6dbd46ae7cbeae04eac647789b0ad4c7f7c 100644 (file)
@@ -88,7 +88,7 @@
                                     <menuitem iconSclass="z-icon-money" label="Összes számla"
                                               onClick="@command(vm.selectPage('~./invoices.zul'))"/>
                                     <menuitem iconSclass="z-icon-credit-card" label="Számla kiegyenlítés"
-                                              onClick="@command(vm.selectPage('~./invoice-settle.zul'))"/>
+                                              onClick="@command(vm.selectPage('~./invoice-payment.zul'))"/>
                                     <menuitem iconSclass="z-icon-exchange" label="Követelés követés"
                                               onClick="@command('onInvoiceDues')"/>
                                     <menuseparator/>
index 36e170c2fea1cc571bb80b12123ded4a76030862..df60d22ee5d6e6ea85b541056cbe4f84cdf18fbe 100644 (file)
@@ -1,47 +1,41 @@
 <zk>
-    <window vflex="true" viewModel="@id('vm') @init('hu.user.lis.ui.view.InvoicesViewModel')">
+    <window vflex="true" viewModel="@id('vm') @init('hu.user.lis.ui.view.InvoicePaymentViewModel')">
         <caption label="Számla kiegyenlítés"/>
         <borderlayout>
             <north flex="true">
                 <toolbar>
-                    <toolbarbutton label="Hozzáadás" iconSclass="z-icon-plus" onClick="@command('onAdd')"/>
-                    <toolbarbutton label="Szerkesztés" iconSclass="z-icon-edit" onClick="@command('onEdit')"
-                                   disabled="@load(empty vm.selectedEntity)"/>
-                    <toolbarbutton label="Törlés" iconSclass="z-icon-remove" onClick="@command('onDelete')"
-                                   disabled="@load(empty vm.selectedEntity)"/>
+                    <label value="Számla sorszáma"/>
                     <separator orient="vertical"/>
-                    <toolbarbutton mode="toggle" iconSclass="z-icon-check" label="Aktív"
-                                   checked="@bind(vm.filterShowActive)"/>
-                    <toolbarbutton mode="toggle" iconSclass="z-icon-ban" label="Inaktív"
-                                   checked="@bind(vm.filterShowInActive)"/>
-                    <toolbarbutton mode="toggle" iconSclass="z-icon-adjust" label="Mind"
-                                   checked="@bind(vm.filterShowBoth)"/>
+                    <textbox value="@bind(vm.invoiceNumber)" onChange="@command('search')"/>
+
+                    <space bar="true"/>
+
+                    <label value="Partner" visible="@bind(vm.partnerRequired)"/>
+                    <separator orient="vertical" visible="@bind(vm.partnerRequired)"/>
+                    <selectbox model="@bind(vm.partners)"
+                               selectedIndex="@bind(vm.filterPartner) @converter(vm.partnerConverter)"
+                               onSelect="@command('search')"
+                               visible="@bind(vm.partnerRequired)">
+                        <template name="model">
+                            ${each.name}
+                        </template>
+                    </selectbox>
                 </toolbar>
             </north>
             <center border="none" flex="true">
-                <listbox id="partnersList" vflex="true" model="@load(vm.partnersDataModel)"
-                         autopaging="true" mold="paging" pagingPosition="top" multiple="false"
-                         onSelect="@command('onListSelection')" onDoubleClick="@command('onEdit')">
+                <listbox vflex="true" model="@load(vm.paymentsDataModel)" multiple="false">
                     <listhead sizable="true">
-                        <listheader label="Név" sort="auto(name)" align="left"
-                                    sortDirection="@load(vm.cols['name'].sortDirection)"/>
-                        <listheader label="Adószám" sort="auto(vatNr)" align="left"
-                                    sortDirection="@load(vm.cols['vatNr'].sortDirection)"/>
-                        <listheader label="Cím" sort="auto(address)" align="left"
-                                    sortDirection="@load(vm.cols['address'].sortDirection)"/>
-                        <listheader label="Aktív" sort="auto(active)" align="left"
-                                    sortDirection="@load(vm.cols['active'].sortDirection)"/>
-
+                        <listheader label="Dátum" align="left"/>
+                        <listheader label="Nettó összeg" align="right"/>
+                        <listheader label="Bruttó összeg" align="right"/>
+                        <listheader label="ÁFA összeg" align="right"/>
                     </listhead>
                     <template name="model">
                         <listitem>
-                            <listcell label="@load(each.name)"/>
-                            <listcell label="@load(each.vatNr)"/>
-                            <listcell label="@load(each.address)"/>
-                            <listcell>
-                                <a iconSclass="z-icon-check" visible="@load(each.active)"/>
-                                <a iconSclass="z-icon-ban" visible="@load(!each.active)"/>
-                            </listcell>
+                            <listcell label="@load(each.paymentDate)"/>
+                            <listcell label="@load(each.netAmount)"/>
+                            <listcell label="@load(each.grossAmount)"/>
+                            <listcell label="@load(each.vatAmount)"/>
                         </listitem>
                     </template>
                 </listbox>
index 86bdc22507984be1217794be079eb72e317d2fbf..8b4535f1ca8f0cdfba34c49fc888b65ffe885909 100644 (file)
@@ -1,6 +1,6 @@
 <component name="ProjectRunConfigurationManager">
   <configuration default="false" name="server-dev" type="Application" factoryName="Application">
-    <option name="ALTERNATIVE_JRE_PATH" value="semeru-1.8" />
+    <option name="ALTERNATIVE_JRE_PATH" value="1.8" />
     <option name="ALTERNATIVE_JRE_PATH_ENABLED" value="true" />
     <envs>
       <env name="spring.profiles.active" value="dev" />