From: elgekko Date: Wed, 3 May 2023 22:18:24 +0000 (+0200) Subject: Treasury list and editor added X-Git-Url: http://git.useribm.hu/?a=commitdiff_plain;h=0b7b414c27298a478b2ba54161d00416dbbe672f;p=sly-crm.git Treasury list and editor added --- diff --git a/TODO.txt b/TODO.txt index 5ddebc5..a2ac5ec 100644 --- a/TODO.txt +++ b/TODO.txt @@ -19,9 +19,9 @@ * A projektszám formátuma más kell, hogy legyen (Csabi). * Számlához kellene a számla sorszám: a szerkesztőben és/vagy a listában? * A be és kimenő számlák táblázatban szerepeljen a teljesítés dátuma a fizetési határidő oszlop előtt. -- Projekt résztvevők így nagy helyet foglalnak el. +* Projekt résztvevők így nagy helyet foglalnak el. Inkább legyen egy nyomógomb a projekt szerkesztő tetején egy dialógus ablakban lehet szerkeszteni a résztvevőket. - A felugró ablak helyett inkáb plusz tab lett az adatok mellett, maradhat? Layout para + A felugró ablak helyett inkáb plusz tab lett az adatok mellett, maradhat? * Munkatárs táblázatban a szerkesztés gomb nem aktív. - Projekt szerkesztőben treasury műveletek lista: Eladás (aloszlop összeg és deviza), Vétel (aloszlop összeg és deviza),Üzletkötés dátuma, Értéknap diff --git a/lis-db/src/main/java/hu/user/lis/db/Treasury.java b/lis-db/src/main/java/hu/user/lis/db/Treasury.java index b4d8a3c..9572229 100644 --- a/lis-db/src/main/java/hu/user/lis/db/Treasury.java +++ b/lis-db/src/main/java/hu/user/lis/db/Treasury.java @@ -17,4 +17,5 @@ public class Treasury { Currency sellCurrency; Date transactionDate; Date valueDate; + byte[] file; } diff --git a/lis-services/src/main/java/hu/user/lis/services/data/ProjectServiceImpl.java b/lis-services/src/main/java/hu/user/lis/services/data/ProjectServiceImpl.java index a83b16f..1212e6a 100644 --- a/lis-services/src/main/java/hu/user/lis/services/data/ProjectServiceImpl.java +++ b/lis-services/src/main/java/hu/user/lis/services/data/ProjectServiceImpl.java @@ -1,6 +1,5 @@ package hu.user.lis.services.data; -import com.fasterxml.jackson.databind.ObjectMapper; import hu.user.lis.db.Partner; import hu.user.lis.db.Project; import lombok.extern.log4j.Log4j2; @@ -18,14 +17,14 @@ import java.util.concurrent.TimeUnit; @Service @Log4j2 public class ProjectServiceImpl extends DataServiceImpl implements ProjectService { - @Autowired - ObjectMapper mapper; @Autowired DataGeneratorService dataGeneratorService; @Autowired PartnerService partnerService; @Autowired InvoiceService invoiceService; + @Autowired + TreasuryService treasuryService; private List entities; @Override @@ -45,6 +44,7 @@ public class ProjectServiceImpl extends DataServiceImpl implements Proj .humanId(humanId) .incomingInvoices(new ArrayList<>()) .outgoingInvoices(new ArrayList<>()) + .treasuries(new ArrayList<>()) .active(true) .build(); } @@ -56,8 +56,8 @@ public class ProjectServiceImpl extends DataServiceImpl implements Proj @Override public void replace(Project targetEntity, Project replacementEntity) { - Project partnerInList = entities.stream().filter(p -> p.getId().equals(targetEntity.getId())).findFirst().get(); - entities.remove(partnerInList); + Project target = entities.stream().filter(p -> p.getId().equals(targetEntity.getId())).findFirst().get(); + entities.remove(target); entities.add(replacementEntity); } @@ -80,6 +80,7 @@ public class ProjectServiceImpl extends DataServiceImpl implements Proj .partner(partner) .incomingInvoices(invoiceService.getRandom(true)) .outgoingInvoices(invoiceService.getRandom(false)) + .treasuries(treasuryService.getRandom()) .build(); result.add(entity); } diff --git a/lis-services/src/main/java/hu/user/lis/services/data/TreasuryServiceImpl.java b/lis-services/src/main/java/hu/user/lis/services/data/TreasuryServiceImpl.java index 8cd9bef..57402bb 100644 --- a/lis-services/src/main/java/hu/user/lis/services/data/TreasuryServiceImpl.java +++ b/lis-services/src/main/java/hu/user/lis/services/data/TreasuryServiceImpl.java @@ -83,9 +83,9 @@ public class TreasuryServiceImpl extends DataServiceImpl implements Tr int count = RandomUtils.nextInt(2, 5); List result = new ArrayList<>(); for (int i = 0; i < count; i++) { - int index = RandomUtils.nextInt(0, entities.size()); - result.add(entities.get(index)); - entities.remove(index); + int index = RandomUtils.nextInt(0, getAll().size()); + result.add(getAll().get(index)); + getAll().remove(index); } return result; } diff --git a/lis-ui/src/main/java/hu/user/lis/ui/data/AssociatesDataModel.java b/lis-ui/src/main/java/hu/user/lis/ui/data/AssociatesDataModel.java index ce702f7..7c73dff 100644 --- a/lis-ui/src/main/java/hu/user/lis/ui/data/AssociatesDataModel.java +++ b/lis-ui/src/main/java/hu/user/lis/ui/data/AssociatesDataModel.java @@ -84,6 +84,8 @@ public class AssociatesDataModel extends CachedDataModel { public void search(String partialName) { log.info("Searching associate using filters: name LIKE {}", partialName); listAll = false; + this.filterShowActive = true; + this.filterShowInActive = true; this.partialName = partialName; super.reset(); BindUtils.postNotifyChange(null, null, this, "*"); diff --git a/lis-ui/src/main/java/hu/user/lis/ui/editor/ProjectEditorModel.java b/lis-ui/src/main/java/hu/user/lis/ui/editor/ProjectEditorModel.java index 3ad7b22..3c24dee 100644 --- a/lis-ui/src/main/java/hu/user/lis/ui/editor/ProjectEditorModel.java +++ b/lis-ui/src/main/java/hu/user/lis/ui/editor/ProjectEditorModel.java @@ -67,20 +67,27 @@ public class ProjectEditorModel extends AbstractValidator implements EventListen private Invoice selectedOutgoingInvoice; private Treasury selectedTreasury; - private String partialAssociateName; - - public ProjectEditorModel() { - - } - @Init public void init() { eventBus.register(this); log.info("Initialized"); } + @NotifyChange("associatesDataModel") + public void setPartialAssociateName(String partialAssociateName) { + this.partialAssociateName = partialAssociateName; + log.info("Filter assosiates: {}", partialAssociateName); + associatesDataModel.search(partialAssociateName); + } + + @Command + @NotifyChange({"associatesDataModel", "partialAssociateName"}) + public void onResetAssociateFilter() { + this.partialAssociateName = null; + associatesDataModel.listAll(); + } @Command public void onEndEdit(@BindingParam("target") Window target, @BindingParam("select") boolean select) { @@ -273,16 +280,16 @@ public class ProjectEditorModel extends AbstractValidator implements EventListen @Command public void onAddTreasury() { - String page = "~./outgoing-invoice-editor.zul"; - Invoice editEntity = invoiceServiceImpl.createNew(); + String page = "~./treasury-editor.zul"; + Treasury editEntity = treasuryServiceImpl.createNew(); Window editorWindow = (Window) Executions.createComponents(page, null, Collections.singletonMap("formDocument", editEntity)); editorWindow.addEventListener("onClose", e -> { if (e.getData() != null) { - formDocument.getOutgoingInvoices().add(editEntity); - selectedOutgoingInvoice = editEntity; - BindUtils.postNotifyChange(this, "selectedOutgoingInvoice"); - BindUtils.postNotifyChange(this.formDocument, "outgoingInvoices"); + formDocument.getTreasuries().add(editEntity); + selectedTreasury = editEntity; + BindUtils.postNotifyChange(this, "selectedTreasury"); + BindUtils.postNotifyChange(this.formDocument, "treasuries"); validate(projectServiceImpl.copy(formDocument)); } }); @@ -291,22 +298,20 @@ public class ProjectEditorModel extends AbstractValidator implements EventListen @Command public void onEditTreasury() throws JsonProcessingException { - String page = "~./outgoing-invoice-editor.zul"; - Invoice editEntity = invoiceServiceImpl.copy(selectedOutgoingInvoice); - Map arg = new HashMap<>(); - arg.put("origDocument", selectedOutgoingInvoice); - arg.put("formDocument", editEntity); + String page = "~./treasury-editor.zul"; + Treasury editEntity = treasuryServiceImpl.copy(selectedTreasury); + Map arg = ImmutableMap.of("origDocument", selectedTreasury, "formDocument", editEntity); Window editorWindow = (Window) Executions.createComponents(page, null, arg); editorWindow.addEventListener("onClose", e -> { if (e.getData() != null) { - Invoice modifiedEntity = (Invoice) e.getData(); - List outgoingInvoices = formDocument.getOutgoingInvoices(); - int index = outgoingInvoices.indexOf(selectedOutgoingInvoice); - outgoingInvoices.remove(selectedOutgoingInvoice); - outgoingInvoices.add(index, modifiedEntity); - selectedOutgoingInvoice = modifiedEntity; - BindUtils.postNotifyChange(this, "selectedOutgoingInvoice"); - BindUtils.postNotifyChange(this.formDocument, "outgoingInvoices"); + Treasury modifiedEntity = (Treasury) e.getData(); + List treasuries = formDocument.getTreasuries(); + int index = treasuries.indexOf(selectedTreasury); + treasuries.remove(selectedTreasury); + treasuries.add(index, modifiedEntity); + selectedTreasury = modifiedEntity; + BindUtils.postNotifyChange(this, "selectedTreasury"); + BindUtils.postNotifyChange(this.formDocument, "treasuries"); validate(projectServiceImpl.copy(formDocument)); } }); @@ -318,10 +323,10 @@ public class ProjectEditorModel extends AbstractValidator implements EventListen if (selectedOutgoingInvoice == null) { return; } - formDocument.getOutgoingInvoices().remove(selectedOutgoingInvoice); - selectedOutgoingInvoice = null; - BindUtils.postNotifyChange(this, "selectedOutgoingInvoice"); - BindUtils.postNotifyChange(this.formDocument, "outgoingInvoices"); + formDocument.getTreasuries().remove(selectedTreasury); + selectedTreasury = null; + BindUtils.postNotifyChange(this, "selectedTreasury"); + BindUtils.postNotifyChange(this.formDocument, "treasuries"); validate(projectServiceImpl.copy(formDocument)); } @@ -348,14 +353,14 @@ public class ProjectEditorModel extends AbstractValidator implements EventListen } @Command - public void onOpenInvoicePanel(@BindingParam("parentPanel") Center parentPanel) { - log.info("Invoice panel open/close"); + public void onOpenFormPanel(@BindingParam("parentPanel") Center parentPanel) { + log.info("Panel open/close"); parentPanel.invalidate(); } @Command - public void onClickInvoicePanel(@BindingParam("parentPanel") Center parentPanel, @BindingParam("panel") Panel panel) { - log.info("Invoice panel click"); + public void onClickFormPanel(@BindingParam("parentPanel") Center parentPanel, @BindingParam("panel") Panel panel) { + log.info("Panel click"); panel.setOpen(!panel.isOpen()); parentPanel.invalidate(); } diff --git a/lis-ui/src/main/java/hu/user/lis/ui/editor/TreasuryEditorModel.java b/lis-ui/src/main/java/hu/user/lis/ui/editor/TreasuryEditorModel.java new file mode 100644 index 0000000..b4f818b --- /dev/null +++ b/lis-ui/src/main/java/hu/user/lis/ui/editor/TreasuryEditorModel.java @@ -0,0 +1,115 @@ +package hu.user.lis.ui.editor; + +import hu.user.lis.db.Treasury; +import hu.user.lis.services.data.TreasuryService; +import lombok.Getter; +import lombok.Setter; +import lombok.extern.log4j.Log4j2; +import org.zkoss.bind.BindContext; +import org.zkoss.bind.BindUtils; +import org.zkoss.bind.ValidationContext; +import org.zkoss.bind.annotation.*; +import org.zkoss.bind.validator.AbstractValidator; +import org.zkoss.zk.ui.Component; +import org.zkoss.zk.ui.Executions; +import org.zkoss.zk.ui.event.Event; +import org.zkoss.zk.ui.event.Events; +import org.zkoss.zk.ui.event.UploadEvent; +import org.zkoss.zk.ui.select.annotation.VariableResolver; +import org.zkoss.zk.ui.select.annotation.WireVariable; +import org.zkoss.zkplus.spring.DelegatingVariableResolver; +import org.zkoss.zul.Messagebox; +import org.zkoss.zul.Window; + +import java.util.Objects; + +@Log4j2 +@Getter +@Setter +@VariableResolver(DelegatingVariableResolver.class) +public class TreasuryEditorModel extends AbstractValidator { + private Treasury origDocument; + private Treasury formDocument; + @WireVariable + private TreasuryService treasuryServiceImpl; + private boolean formInvalid = true; + + @Init + public void init() { + log.info("Initialized"); + origDocument = (Treasury) Executions.getCurrent().getArg().get("origDocument"); + formDocument = (Treasury) Executions.getCurrent().getArg().get("formDocument"); + } + + @Command + public void onCloseWindow(@BindingParam("target") Window target, @BindingParam("select") boolean select) { + if (select && formInvalid) { + return; + } + Event closeEvent = new Event("onClose", target, select ? formDocument : null); + Events.postEvent(closeEvent); + } + + @Override + @NotifyChange("formInvalid") + public void validate(ValidationContext ctx) { + Component target = ctx.getBindContext().getComponent(); + String property = ctx.getProperty().getProperty(); + Object value = ctx.getProperty().getValue(); + log.info("Validating caused by {} {} {}", target.getId(), property, value); + try { + Treasury newData = treasuryServiceImpl.copy(formDocument, property, value); + validate(newData); + } catch (Exception e) { + log.catching(e); + } + + } + + private void validate(Treasury newData) { + updateFormInvalid(false); + if (!Objects.isNull(origDocument) && treasuryServiceImpl.toString(origDocument).equals(treasuryServiceImpl.toString(newData))) { + log.info("Document not changed"); + updateFormInvalid(true); + return; + } + + boolean invalid = false; + if (newData.getBuyAmount() <= 0 || + newData.getSellAmount() <= 0 || + Objects.isNull(newData.getValueDate()) || + Objects.isNull(newData.getTransactionDate()) + ) { + invalid = true; + } + + if (invalid) { + log.info("Document is not valid"); + updateFormInvalid(true); + } + } + + private void updateFormInvalid(boolean invalid) { + setFormInvalid(invalid); + BindUtils.postNotifyChange(this, "formInvalid"); + } + + @Command + public void onUploadFile(@ContextParam(ContextType.BIND_CONTEXT) BindContext ctx) { + UploadEvent evt = (UploadEvent) ctx.getTriggerEvent(); + if (!evt.getMedia().getName().toLowerCase().endsWith(".pdf")) { + Messagebox.show("Csak PDF állomány feltöltése támogatott.", "Error", Messagebox.OK, Messagebox.ERROR); + return; + } + formDocument.setFile(evt.getMedia().getByteData()); + BindUtils.postNotifyChange(this.formDocument, "file"); + validate(treasuryServiceImpl.copy(formDocument)); + } + + @Command + public void onRemoveFile() { + formDocument.setFile(null); + BindUtils.postNotifyChange(this.formDocument, "file"); + validate(treasuryServiceImpl.copy(formDocument)); + } +} diff --git a/lis-ui/src/main/resources/web/incoming-invoice-editor.zul b/lis-ui/src/main/resources/web/incoming-invoice-editor.zul index c1f115f..285a3f9 100644 --- a/lis-ui/src/main/resources/web/incoming-invoice-editor.zul +++ b/lis-ui/src/main/resources/web/incoming-invoice-editor.zul @@ -30,7 +30,7 @@ diff --git a/lis-ui/src/main/resources/web/outgoing-invoice-editor.zul b/lis-ui/src/main/resources/web/outgoing-invoice-editor.zul index 1c49907..416fd6f 100644 --- a/lis-ui/src/main/resources/web/outgoing-invoice-editor.zul +++ b/lis-ui/src/main/resources/web/outgoing-invoice-editor.zul @@ -30,7 +30,7 @@ diff --git a/lis-ui/src/main/resources/web/project-editor.zul b/lis-ui/src/main/resources/web/project-editor.zul index 28c573c..22bbb9a 100644 --- a/lis-ui/src/main/resources/web/project-editor.zul +++ b/lis-ui/src/main/resources/web/project-editor.zul @@ -9,7 +9,7 @@
- + @@ -37,40 +37,45 @@ - - - - - - + + + + + + + + +
+ + - - - - - - - - + + + + + + + +
+
+ onOpen="@command('onOpenFormPanel', parentPanel=centerPanel)"> + onClick="@command('onClickFormPanel', parentPanel=centerPanel, panel=self.parent)"/> @@ -116,9 +121,9 @@ + onOpen="@command('onOpenFormPanel', parentPanel=centerPanel)"> + onClick="@command('onClickFormPanel', parentPanel=centerPanel, panel=self.parent)"/> @@ -165,9 +170,9 @@ + onOpen="@command('onOpenFormPanel', parentPanel=centerPanel)"> + onClick="@command('onClickFormPanel', parentPanel=centerPanel, panel=self.parent)"/> diff --git a/lis-ui/src/main/resources/web/treasury-editor.zul b/lis-ui/src/main/resources/web/treasury-editor.zul new file mode 100644 index 0000000..1e13b5c --- /dev/null +++ b/lis-ui/src/main/resources/web/treasury-editor.zul @@ -0,0 +1,104 @@ + + + + + + import hu.user.lis.db.Currency; + ListModelList currencies = new ListModelList(Currency.values()); + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+