EDocument handling completed on import invoice
authorVásáry Dániel <vasary@elgekko.net>
Thu, 21 Dec 2023 10:22:35 +0000 (11:22 +0100)
committerVásáry Dániel <vasary@elgekko.net>
Thu, 21 Dec 2023 10:22:35 +0000 (11:22 +0100)
20 files changed:
lis-service/src/main/java/hu/user/lis/service/data/EntityDocumentService.java
lis-service/src/main/java/hu/user/lis/service/nav/mapper/PartnerMapper.java
lis-ui/src/main/java/hu/user/lis/ui/data/InvoiceDataModel.java
lis-ui/src/main/java/hu/user/lis/ui/editor/ImportInvoiceApproveEditorModel.java
lis-ui/src/main/java/hu/user/lis/ui/editor/ImportInvoiceAssignEditorModel.java
lis-ui/src/main/java/hu/user/lis/ui/editor/InvoiceEditorModel.java
lis-ui/src/main/java/hu/user/lis/ui/editor/ProjectEditorModel.java
lis-ui/src/main/java/hu/user/lis/ui/editor/ServiceRecordEditorModel.java
lis-ui/src/main/java/hu/user/lis/ui/editor/TreasuryEditorModel.java
lis-ui/src/main/java/hu/user/lis/ui/editor/common/EntityAttachmentEditorModel.java
lis-ui/src/main/java/hu/user/lis/ui/event/SaveEntityEvent.java
lis-ui/src/main/java/hu/user/lis/ui/view/ApproveInvoicesViewModel.java
lis-ui/src/main/java/hu/user/lis/ui/view/AssignInvoicesViewModel.java
lis-ui/src/main/java/hu/user/lis/ui/view/AssociatesViewModel.java
lis-ui/src/main/java/hu/user/lis/ui/view/ImportInvoicesSuspendedViewModel.java
lis-ui/src/main/java/hu/user/lis/ui/view/InvoicesViewModel.java
lis-ui/src/main/java/hu/user/lis/ui/view/PartnersViewModel.java
lis-ui/src/main/java/hu/user/lis/ui/view/ServiceRecordsViewModel.java
lis-ui/src/main/resources/web/editor/import-invoice-approve-editor.zul
lis-ui/src/main/resources/web/editor/import-invoice-assign-editor.zul

index 4e344a4c2498f055451c4960d991e6a8c841479f..74b6e3329f03c40e82b003840e88af041ccbdb50 100644 (file)
@@ -7,6 +7,7 @@ import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
 import java.util.List;
+import java.util.Objects;
 import java.util.stream.Collectors;
 
 @Service
@@ -17,10 +18,12 @@ public class EntityDocumentService {
 
     @Transactional
     public void executeActions(Long referenceId, List<EntityDocumentAction> actions) {
-        List<Long> idsToAttach = actions.stream().filter(EntityDocumentAction::isAttach).map(EntityDocumentAction::getDocumentId).collect(Collectors.toList());
-        eDocumentRepository.attach(referenceId, idsToAttach);
-        List<Long> idsToRemove = actions.stream().filter(EntityDocumentAction::isDetach).map(EntityDocumentAction::getDocumentId).collect(Collectors.toList());
-        eDocumentRepository.deleteAllById(idsToRemove);
+        if (Objects.nonNull(actions) && !actions.isEmpty()) {
+            List<Long> idsToAttach = actions.stream().filter(EntityDocumentAction::isAttach).map(EntityDocumentAction::getDocumentId).collect(Collectors.toList());
+            eDocumentRepository.attach(referenceId, idsToAttach);
+            List<Long> idsToRemove = actions.stream().filter(EntityDocumentAction::isDetach).map(EntityDocumentAction::getDocumentId).collect(Collectors.toList());
+            eDocumentRepository.deleteAllById(idsToRemove);
+        }
     }
 
 }
index a7e62333ad9c83f91dc8ce7e03065bebe4e6030e..e0fba9501d3ab30991718caf3e619ca0ec691930 100644 (file)
@@ -12,11 +12,12 @@ import org.mapstruct.MappingTarget;
 @Mapper(componentModel = "spring")
 public interface PartnerMapper {
     String ADDRESS_FORMAT = "%s %s, %s %s %s";
-    String VATNR_FORMAT = "%s-%s-%s";
+    String VAT_NR_FORMAT = "%s-%s-%s";
 
     @Mapping(target = "id", ignore = true)
     @Mapping(target = "address", ignore = true)
     @Mapping(target = "name", source = "supplierName")
+    @Mapping(target = "shortName", source = "supplierName")
     @Mapping(target = "vatNr", source = "supplierTaxNumber.vatCode")
     @Mapping(target = "active", constant = "true")
     Partner toEntity(SupplierInfoType source);
@@ -29,7 +30,7 @@ public interface PartnerMapper {
         builder.address(address);
 
         TaxNumberType supplierTaxNumber = source.getSupplierTaxNumber();
-        String vatNr = String.format(VATNR_FORMAT, supplierTaxNumber.getTaxpayerId(), supplierTaxNumber.getVatCode(),
+        String vatNr = String.format(VAT_NR_FORMAT, supplierTaxNumber.getTaxpayerId(), supplierTaxNumber.getVatCode(),
                 supplierTaxNumber.getCountyCode());
         builder.vatNr(vatNr);
     }
index bddfd37cc2ce945b5f7a6702e68c92a6abb8c82e..a9e3d9d9b0bbd2eb9196b17acee15d0bd4515cf8 100644 (file)
@@ -6,11 +6,17 @@ import hu.user.lis.db.InvoiceStatus;
 import hu.user.lis.db.OutgoingInvoice;
 import hu.user.lis.db.repository.InvoiceRepository;
 import hu.user.lis.service.data.EntityDataService;
+import hu.user.lis.service.data.EntityDocumentAction;
+import hu.user.lis.service.data.EntityDocumentService;
 import hu.user.lis.service.data.InvoiceService;
 import lombok.extern.log4j.Log4j2;
 import org.apache.commons.lang3.RandomStringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
+import org.springframework.transaction.annotation.Transactional;
+
+import javax.persistence.EntityNotFoundException;
+import java.util.List;
 
 @Component
 @Log4j2
@@ -22,11 +28,18 @@ public class InvoiceDataModel {
     @Autowired
     InvoiceRepository invoiceRepository;
 
+    @Autowired
+    EntityDocumentService entityDocumentService;
+
     @Autowired
     EntityDataService<IncomingInvoice> incomingInvoiceDataService;
     @Autowired
     EntityDataService<OutgoingInvoice> outgoingInvoiceDataService;
 
+    public Invoice findById(Long id) {
+        return invoiceRepository.findById(id).orElseThrow(EntityNotFoundException::new);
+    }
+
     public IncomingInvoice clone(IncomingInvoice entity) {
         return incomingInvoiceDataService.clone(entity);
     }
@@ -45,8 +58,10 @@ public class InvoiceDataModel {
         return OutgoingInvoice.builder().technicalId(technicalId).status(InvoiceStatus.ACTIVE).build();
     }
 
-    public void save(Invoice modifiedEntity) {
+    @Transactional
+    public void save(Invoice modifiedEntity, List<EntityDocumentAction> actions) {
         invoiceRepository.save(modifiedEntity);
+        entityDocumentService.executeActions(modifiedEntity.getId(), actions);
     }
 
     public void delete(Invoice selectedIncomingInvoice) {
index 8e1c4b7c36843e45169f41c199d8b2cf0ccf95d4..64c591d32f6e5e9a7935b358e1d2e7f293c59f3d 100644 (file)
@@ -66,7 +66,7 @@ public class ImportInvoiceApproveEditorModel extends InvoiceEditorModel {
     }
 
     public void handleEntitySaveEvent(SaveEntityEvent<Partner> event) {
-        if (!event.isCanceled()) {
+        if (event.isSave()) {
             getFormDocument().setPartner(event.getData());
         }
     }
@@ -79,7 +79,8 @@ public class ImportInvoiceApproveEditorModel extends InvoiceEditorModel {
         } else {
             Events.postEvent(new Event("onClose", target, ImmutableMap.of(
                     "modifiedEntity", getFormDocument(),
-                    "status", status
+                    "status", status,
+                    "actions", getEntityDocumentDataModel().getActions()
             )));
         }
     }
index 3c85196be43345edcaa23039d11d13a8aea47558..b0b3aed22b658ee1073342e961c7b7fb8b1acbbb 100644 (file)
@@ -78,7 +78,7 @@ public class ImportInvoiceAssignEditorModel extends InvoiceEditorModel {
     }
 
     public void handleEntitySaveEvent(SaveEntityEvent<Partner> event) {
-        if (!event.isCanceled()) {
+        if (event.isSave()) {
             getFormDocument().setPartner(event.getData());
         }
     }
@@ -102,7 +102,8 @@ public class ImportInvoiceAssignEditorModel extends InvoiceEditorModel {
         } else {
             Events.postEvent(new Event("onClose", target, ImmutableMap.of(
                     "modifiedEntity", getFormDocument(),
-                    "status", status
+                    "status", status,
+                    "actions", getEntityDocumentDataModel().getActions()
             )));
         }
     }
index 8bc013230d039f3eac5c4c6e2672047df1a95852..e9f97224d5c8452e81320917c5d0b2ea8f16f368 100644 (file)
@@ -63,6 +63,11 @@ public class InvoiceEditorModel extends EntityAttachmentEditorModel<Invoice> {
         return invoiceFormValidator.validate(entity);
     }
 
+    @Override
+    protected Class<?> getDocumentType() {
+        return Invoice.class;
+    }
+
     @Override
     public void onEvent(Event evt) {
         if (isEventForCurrentDocument(evt)) {
index 4d642c00d3479ee1de33938c9ff6519700129682..a47a166445a7ed1863886fbcf4836905a6b3fb30 100644 (file)
@@ -189,7 +189,7 @@ public class ProjectEditorModel extends EntityEditorModel<Project> {
 
 
     private void incomingAdded(SaveEntityEvent<IncomingInvoice> event) {
-        if (!event.isCanceled()) {
+        if (event.isSave()) {
             IncomingInvoice modifiedEntity = event.getData();
             getFormDocument().getIncomingInvoices().add(modifiedEntity);
             selectedIncomingInvoice = modifiedEntity;
@@ -201,7 +201,7 @@ public class ProjectEditorModel extends EntityEditorModel<Project> {
     }
 
     private void incomingModified(SaveEntityEvent<IncomingInvoice> event) {
-        if (!event.isCanceled()) {
+        if (event.isSave()) {
             List<IncomingInvoice> incomingInvoices = getFormDocument().getIncomingInvoices();
             incomingInvoices.remove(selectedIncomingInvoice);
             IncomingInvoice modifiedEntity = event.getData();
@@ -244,7 +244,7 @@ public class ProjectEditorModel extends EntityEditorModel<Project> {
     }
 
     private void outgoingAdded(SaveEntityEvent<OutgoingInvoice> event) {
-        if (!event.isCanceled()) {
+        if (event.isSave()) {
             OutgoingInvoice modifiedEntity = event.getData();
             getFormDocument().getOutgoingInvoices().add(modifiedEntity);
             selectedOutgoingInvoice = modifiedEntity;
@@ -256,7 +256,7 @@ public class ProjectEditorModel extends EntityEditorModel<Project> {
     }
 
     private void outgoingModified(SaveEntityEvent<OutgoingInvoice> event) {
-        if (!event.isCanceled()) {
+        if (event.isSave()) {
             OutgoingInvoice modifiedEntity = event.getData();
             List<OutgoingInvoice> outgoingInvoices = getFormDocument().getOutgoingInvoices();
             outgoingInvoices.remove(selectedOutgoingInvoice);
@@ -294,7 +294,7 @@ public class ProjectEditorModel extends EntityEditorModel<Project> {
     }
 
     private void treasuryAdded(SaveEntityEvent<Treasury> event) {
-        if (!event.isCanceled()) {
+        if (event.isSave()) {
             Treasury modifiedEntity = event.getData();
             getFormDocument().getTreasuries().add(modifiedEntity);
             selectedTreasury = modifiedEntity;
@@ -305,7 +305,7 @@ public class ProjectEditorModel extends EntityEditorModel<Project> {
     }
 
     private void treasuryModified(SaveEntityEvent<Treasury> event) {
-        if (!event.isCanceled()) {
+        if (event.isSave()) {
             Treasury modifiedEntity = event.getData();
             List<Treasury> treasuries = getFormDocument().getTreasuries();
             treasuries.remove(selectedTreasury);
index 81c8860ab2da87088f6713b130a6de13f3cf6912..abed574fbdc782cf6e8871ca8222647632f3692c 100644 (file)
@@ -107,6 +107,11 @@ public class ServiceRecordEditorModel extends EntityAttachmentEditorModel<Servic
         }
     }
 
+    @Override
+    protected Class<?> getDocumentType() {
+        return ServiceRecord.class;
+    }
+
     private List<Long> getProjectIds(List<ProjectAssociate> projectAssociates) {
         if (Objects.nonNull(projectAssociates)) {
             return projectAssociates.stream().map(ProjectAssociate::getProjectId).collect(Collectors.toList());
index b8dd97d860f1b1b379d3c1a031f3595d59e6b906..741a6cc303a47099cb379b6b4eec7c6869b7725b 100644 (file)
@@ -30,4 +30,9 @@ public class TreasuryEditorModel extends EntityAttachmentEditorModel<Treasury> {
         return treasuryFormValidator.validate(entity);
     }
 
+    @Override
+    protected Class<?> getDocumentType() {
+        return Treasury.class;
+    }
+
 }
index bc659b5ef27bebbd933875ca4524f5050e539abd..2f92f77613b67e7db345c028ff23020f4247f771 100644 (file)
@@ -14,7 +14,6 @@ import org.zkoss.bind.annotation.BindingParam;
 import org.zkoss.bind.annotation.Command;
 import org.zkoss.bind.annotation.ContextParam;
 import org.zkoss.bind.annotation.ContextType;
-import org.zkoss.lang.Strings;
 import org.zkoss.zk.ui.Executions;
 import org.zkoss.zk.ui.event.Events;
 import org.zkoss.zk.ui.event.UploadEvent;
@@ -23,13 +22,11 @@ import org.zkoss.zul.Messagebox;
 import org.zkoss.zul.Window;
 
 import java.io.Serializable;
-import java.lang.reflect.ParameterizedType;
-import java.lang.reflect.Type;
 import java.util.List;
 
 @Getter
 @Log4j2
-public class EntityAttachmentEditorModel<T extends Serializable> extends EntityEditorModel<T> {
+public abstract class EntityAttachmentEditorModel<T extends Serializable> extends EntityEditorModel<T> {
 
     @WireVariable
     private EntityDocumentDataModel entityDocumentDataModel;
@@ -41,7 +38,7 @@ public class EntityAttachmentEditorModel<T extends Serializable> extends EntityE
         List<EntityDocumentAction> actions = (List<EntityDocumentAction>) Executions.getCurrent().getArg().get("actions");
         log.info(actions);
 
-        entityDocumentDataModel.refresh((IdEntity) getFormDocument(), getDocumentType(), actions);
+        entityDocumentDataModel.refresh((IdEntity) getFormDocument(), getDocumentType().getSimpleName(), actions);
     }
 
     @Override
@@ -57,7 +54,7 @@ public class EntityAttachmentEditorModel<T extends Serializable> extends EntityE
             return;
         }
         EDocument document = EDocument.builder()
-                .documentType(getDocumentType())
+                .documentType(getDocumentType().getSimpleName())
                 .file(evt.getMedia().getByteData())
                 .size(evt.getMedia().getByteData().length)
                 .name(evt.getMedia().getName())
@@ -79,14 +76,7 @@ public class EntityAttachmentEditorModel<T extends Serializable> extends EntityE
         }
     }
 
-    private String getDocumentType() {
-        String documentType = Strings.EMPTY;
-        Type[] actualTypeArguments = ((ParameterizedType) getClass().getGenericSuperclass()).getActualTypeArguments();
-        if (actualTypeArguments.length > 0) {
-            documentType = ((Class<?>) actualTypeArguments[0]).getSimpleName();
-        }
-        return documentType;
-    }
+    protected abstract Class<?> getDocumentType();
 
     @Command
     public void onRemoveFile() {
index bfe8f8a7abe51069e14a49da69ca0f4580cd1b62..395dc9d191d3e297cca043643170ac6842fb8b19 100644 (file)
@@ -14,8 +14,8 @@ public class SaveEntityEvent<T> extends Event {
         return (T) super.getData();
     }
 
-    public boolean isCanceled() {
-        return this instanceof CancelEntityEditEvent;
+    public boolean isSave() {
+        return !(this instanceof CancelEntityEditEvent);
     }
 
     public SaveEntityWithAttachmentEvent<T> withAttachment() {
index d70eb806f6867777abb508b0b2b6e13342dae284..a99d8937867194033290341da1b994f9bb5aa40e 100644 (file)
@@ -3,10 +3,11 @@ package hu.user.lis.ui.view;
 import com.google.common.collect.ImmutableMap;
 import hu.user.lis.db.Invoice;
 import hu.user.lis.db.InvoiceStatus;
-import hu.user.lis.db.repository.InvoiceRepository;
 import hu.user.lis.db.repository.PartnerRepository;
+import hu.user.lis.service.data.EntityDocumentAction;
 import hu.user.lis.ui.Constants;
 import hu.user.lis.ui.data.ApproveInvoicesDataModel;
+import hu.user.lis.ui.data.InvoiceDataModel;
 import hu.user.lis.ui.data.common.CachedSpringDataModel;
 import hu.user.lis.ui.editor.common.Editors;
 import hu.user.lis.ui.event.EventBus;
@@ -30,6 +31,7 @@ import org.zkoss.zk.ui.select.annotation.WireVariable;
 import org.zkoss.zkplus.spring.DelegatingVariableResolver;
 import org.zkoss.zul.Window;
 
+import java.util.List;
 import java.util.Map;
 import java.util.Objects;
 
@@ -44,7 +46,7 @@ public class ApproveInvoicesViewModel extends EntityViewModel<JSONObject> implem
     ProcessEventRouter processEventRouter;
 
     @WireVariable
-    InvoiceRepository invoiceRepository;
+    InvoiceDataModel invoiceDataModel;
 
     @WireVariable
     PartnerRepository partnerRepository;
@@ -88,24 +90,23 @@ public class ApproveInvoicesViewModel extends EntityViewModel<JSONObject> implem
         editorWindow.addEventListener("onClose", e -> {
             if (Objects.nonNull(e.getData())) {
                 Map<String, Object> results = (Map<String, Object>) e.getData();
-                Invoice modifiedEntity = (Invoice) results.get("modifiedEntity");
                 InvoiceImportStatus status = (InvoiceImportStatus) results.get("status");
+                if (InvoiceImportStatus.NONE.equals(status)) {
+                    return;
+                }
+                Invoice modifiedEntity = (Invoice) results.get("modifiedEntity");
+                List<EntityDocumentAction> actions = (List<EntityDocumentAction>) results.get("actions");
+                if (InvoiceImportStatus.SKIP.equals(status)) {
+                    modifiedEntity.setStatus(InvoiceStatus.SUSPENDED);
+                }
                 if (InvoiceImportStatus.APPROVE.equals(status)) {
                     modifiedEntity.setStatus(InvoiceStatus.ACTIVE);
-                    invoiceRepository.save(modifiedEntity);
-                    approveInvoicesDataModel.completeTask(getSelectedEntity(), ImmutableMap.of(
-                            "invoiceEntity", modifiedEntity,
-                            "status", status
-                    ));
-                } else {
-                    if (InvoiceImportStatus.SKIP.equals(status)) {
-                        modifiedEntity.setStatus(InvoiceStatus.SUSPENDED);
-                        invoiceRepository.save(modifiedEntity);
-                    }
-                    approveInvoicesDataModel.completeTask(getSelectedEntity(), ImmutableMap.of(
-                            "status", status
-                    ));
                 }
+                invoiceDataModel.save(modifiedEntity, actions);
+                approveInvoicesDataModel.completeTask(getSelectedEntity(), ImmutableMap.of(
+                        "invoiceEntity", modifiedEntity,
+                        "status", status
+                ));
             }
         });
         editorWindow.doModal();
index 73aab0bd51bc899c521d791be139887a5c653fa4..72cf5e4d94fb3dc1b98111f92d151835ed07c58b 100644 (file)
@@ -3,9 +3,10 @@ package hu.user.lis.ui.view;
 import com.google.common.collect.ImmutableMap;
 import hu.user.lis.db.Invoice;
 import hu.user.lis.db.InvoiceStatus;
-import hu.user.lis.db.repository.InvoiceRepository;
+import hu.user.lis.service.data.EntityDocumentAction;
 import hu.user.lis.ui.Constants;
 import hu.user.lis.ui.data.AssignInvoicesDataModel;
+import hu.user.lis.ui.data.InvoiceDataModel;
 import hu.user.lis.ui.data.common.CachedSpringDataModel;
 import hu.user.lis.ui.editor.common.Editors;
 import hu.user.lis.ui.event.EventBus;
@@ -26,9 +27,9 @@ import org.zkoss.zk.ui.event.EventListener;
 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 javax.persistence.EntityNotFoundException;
 import java.util.List;
 import java.util.Map;
 import java.util.Objects;
@@ -47,7 +48,7 @@ public class AssignInvoicesViewModel extends EntityViewModel<JSONObject> impleme
     WorkflowManagerService workflowManagerService;
 
     @WireVariable
-    InvoiceRepository invoiceRepository;
+    InvoiceDataModel invoiceDataModel;
 
     @WireVariable
     EventBus eventBus;
@@ -83,36 +84,39 @@ public class AssignInvoicesViewModel extends EntityViewModel<JSONObject> impleme
         List<String> projectSuggestions = (List<String>) getSelectedEntity().get("projectSuggestions");
         Long invoiceId = (Long) getSelectedEntity().get("invoiceId");
 
-        Invoice entity = invoiceRepository.findById(invoiceId).orElseThrow(EntityNotFoundException::new);
-        Map<String, Object> args = ImmutableMap.of("formDocument", entity, "projectSuggestions", projectSuggestions);
+        Invoice entity;
+
+        try {
+            entity = invoiceDataModel.findById(invoiceId);
+        } catch (Exception e) {
+            Messagebox.show(e.getMessage());
+            return;
+        }
 
+        Map<String, Object> args = ImmutableMap.of("formDocument", entity, "projectSuggestions", projectSuggestions);
         Window editorWindow = (Window) Executions.createComponents(Editors.IMPORT_INVOICE_ASSIGN, null, args);
         editorWindow.addEventListener("onClose", e -> {
             if (Objects.nonNull(e.getData())) {
                 Map<String, Object> results = (Map<String, Object>) e.getData();
-                Invoice modifiedEntity = (Invoice) results.get("modifiedEntity");
                 InvoiceImportStatus status = (InvoiceImportStatus) results.get("status");
-                if (InvoiceImportStatus.ASSIGN.equals(status)) {
-                    invoiceRepository.save(modifiedEntity);
-                    assignInvoicesDataModel.completeTask(getSelectedEntity(), ImmutableMap.of(
-                            "invoiceEntity", modifiedEntity,
-                            "status", status
-                    ));
-                } else {
-                    if (InvoiceImportStatus.SKIP.equals(status)) {
-                        modifiedEntity.setStatus(InvoiceStatus.SUSPENDED);
-                        invoiceRepository.save(modifiedEntity);
-                    }
-                    assignInvoicesDataModel.completeTask(getSelectedEntity(), ImmutableMap.of(
-                            "status", status
-                    ));
+                if (InvoiceImportStatus.NONE.equals(status)) {
+                    return;
+                }
+                Invoice modifiedEntity = (Invoice) results.get("modifiedEntity");
+                List<EntityDocumentAction> actions = (List<EntityDocumentAction>) results.get("actions");
+                if (InvoiceImportStatus.SKIP.equals(status)) {
+                    modifiedEntity.setStatus(InvoiceStatus.SUSPENDED);
                 }
+                invoiceDataModel.save(modifiedEntity, actions);
+                assignInvoicesDataModel.completeTask(getSelectedEntity(), ImmutableMap.of(
+                        "invoiceEntity", modifiedEntity,
+                        "status", status
+                ));
                 onRefresh();
             }
         });
         editorWindow.doModal();
         editorWindow.setFocus(true);
-
     }
 
     @Override
index 5714f419a6cd7b32ccaade44f4f812450347f2da..afb5edec9d37cd1db5e018d5fc2bac0e805b8f7c 100644 (file)
@@ -71,7 +71,7 @@ public class AssociatesViewModel extends FilterActiveViewModel<Associate> {
     }
 
     private void saveAssociate(SaveEntityEvent<Associate> event) {
-        if (!event.isCanceled()) {
+        if (event.isSave()) {
             Associate modifiedEntity = event.getData();
             associatesDataModel.save(modifiedEntity);
             refresh();
index 633309bd110057d6dfe5ec4a7fc77eb0d0b31aed..e7c5132342a0165721c8c628599ba67ee081d00d 100644 (file)
@@ -145,27 +145,19 @@ public class ImportInvoicesSuspendedViewModel extends EntityViewModel<Invoice> i
     public void onEditIncoming() {
         IncomingInvoice selectedIncomingInvoice = (IncomingInvoice) getSelectedEntity();
         IncomingInvoice entity = invoiceDataModel.clone(selectedIncomingInvoice);
-        Editors.doEdit(Editors.INCOMING_INVOICE, entity, selectedIncomingInvoice, this::saveIncomingInvoice);
-    }
-
-    private void saveIncomingInvoice(SaveEntityEvent<IncomingInvoice> event) {
-        if (!event.isCanceled()) {
-            Invoice modifiedEntity = event.getData();
-            invoiceDataModel.save(modifiedEntity);
-            refresh();
-        }
+        Editors.doEdit(Editors.INCOMING_INVOICE, entity, selectedIncomingInvoice, this::saveInvoice);
     }
 
     public void onEditOutgoing() {
         OutgoingInvoice selectedOutgoingInvoice = (OutgoingInvoice) getSelectedEntity();
         OutgoingInvoice entity = invoiceDataModel.clone((OutgoingInvoice) getSelectedEntity());
-        Editors.doEdit(Editors.OUTGOING_INVOICE, entity, selectedOutgoingInvoice, this::saveOutgoingInvoice);
+        Editors.doEdit(Editors.OUTGOING_INVOICE, entity, selectedOutgoingInvoice, this::saveInvoice);
     }
 
-    private void saveOutgoingInvoice(SaveEntityEvent<OutgoingInvoice> event) {
-        if (!event.isCanceled()) {
+    private void saveInvoice(SaveEntityEvent<Invoice> event) {
+        if (event.isSave()) {
             Invoice modifiedEntity = event.getData();
-            invoiceDataModel.save(modifiedEntity);
+            invoiceDataModel.save(modifiedEntity, event.withAttachment().getActions());
             refresh();
         }
     }
index 7b3480d626ab148d3db5491b98a0d120e796c9b6..292ec3c6cc5bdcf9a2c25279255d88a805e23a34 100644 (file)
@@ -15,6 +15,7 @@ import hu.user.lis.ui.event.SaveEntityEvent;
 import hu.user.lis.ui.view.common.EntityViewModel;
 import lombok.Getter;
 import lombok.extern.log4j.Log4j2;
+import org.springframework.transaction.annotation.Transactional;
 import org.zkoss.bind.BindUtils;
 import org.zkoss.bind.PropertyChangeEvent;
 import org.zkoss.bind.annotation.*;
@@ -45,10 +46,6 @@ public class InvoicesViewModel extends EntityViewModel<Invoice> implements Event
     @WireVariable
     private InvoiceDataModel invoiceDataModel;
 
-//    @Getter
-//    @WireVariable
-//    private DateTypeConverter dateTypeConverter;
-
     @Init
     @Override
     public void init() {
@@ -141,27 +138,20 @@ public class InvoicesViewModel extends EntityViewModel<Invoice> implements Event
     public void onEditIncoming() {
         IncomingInvoice selectedIncomingInvoice = (IncomingInvoice) getSelectedEntity();
         IncomingInvoice entity = invoiceDataModel.clone(selectedIncomingInvoice);
-        Editors.doEdit(Editors.INCOMING_INVOICE, entity, selectedIncomingInvoice, this::saveIncomingInvoice);
-    }
-
-    private void saveIncomingInvoice(SaveEntityEvent<IncomingInvoice> event) {
-        if (!event.isCanceled()) {
-            Invoice modifiedEntity = event.getData();
-            invoiceDataModel.save(modifiedEntity);
-            refresh();
-        }
+        Editors.doEdit(Editors.INCOMING_INVOICE, entity, selectedIncomingInvoice, this::saveInvoice);
     }
 
     public void onEditOutgoing() {
         OutgoingInvoice selectedOutgoingInvoice = (OutgoingInvoice) getSelectedEntity();
         OutgoingInvoice entity = invoiceDataModel.clone((OutgoingInvoice) getSelectedEntity());
-        Editors.doEdit(Editors.OUTGOING_INVOICE, entity, selectedOutgoingInvoice, this::saveOutgoingInvoice);
+        Editors.doEdit(Editors.OUTGOING_INVOICE, entity, selectedOutgoingInvoice, this::saveInvoice);
     }
 
-    private void saveOutgoingInvoice(SaveEntityEvent<OutgoingInvoice> event) {
-        if (!event.isCanceled()) {
+    @Transactional
+    public void saveInvoice(SaveEntityEvent<Invoice> event) {
+        if (event.isSave()) {
             Invoice modifiedEntity = event.getData();
-            invoiceDataModel.save(modifiedEntity);
+            invoiceDataModel.save(modifiedEntity, event.withAttachment().getActions());
             refresh();
         }
     }
@@ -172,10 +162,10 @@ public class InvoicesViewModel extends EntityViewModel<Invoice> implements Event
     }
 
     private void attachProject(SaveEntityEvent<Project> event) {
-        if (!event.isCanceled()) {
+        if (event.isSave()) {
             Project modifiedEntity = event.getData();
             getSelectedEntity().setProject(modifiedEntity);
-            invoiceDataModel.save(getSelectedEntity());
+            invoiceDataModel.save(getSelectedEntity(), null);
             refresh();
         }
     }
index 0b273bcbfa48b5a5a9682d83df57bec4b76f492f..2218c30d939320adcf07222e043de0bf59118e58 100644 (file)
@@ -70,7 +70,7 @@ public class PartnersViewModel extends FilterActiveViewModel<Partner> {
     }
 
     private void savePartner(SaveEntityEvent<Partner> event) {
-        if (!event.isCanceled()) {
+        if (event.isSave()) {
             Partner modifiedEntity = event.getData();
             partnersDataModel.save(modifiedEntity);
             refresh();
index 74960aa606ef474371966fe540c7a4c85df9e9f6..c3a0f21add4069d1afd3a103cfb970cbcb702872 100644 (file)
@@ -116,7 +116,7 @@ public class ServiceRecordsViewModel extends EntityViewModel<ServiceRecord> impl
     }
 
     public void saveServiceRecord(SaveEntityEvent<ServiceRecord> event) {
-        if (!event.isCanceled()) {
+        if (event.isSave()) {
             ServiceRecord modifiedEntity = event.getData();
             List<EntityDocumentAction> actions = event.withAttachment().getActions();
             modifiedEntity.setSigned(!actions.isEmpty());
index aa8d7cede6b2939e2b1a8cad52cfacdc210d7325..3e314d315d1a6da8eb702ed5cddeb02c99fff0e6 100644 (file)
@@ -1,3 +1,4 @@
+<?import hu.user.lis.workflow.invoice.data.InvoiceImportStatus?>
 <?link rel="stylesheet" type="text/css" href="~./static/css/skeleton.css" ?>
 <?link rel="stylesheet" type="text/css" href="~./static/css/webclient.css" ?>
 <?component name="entity-selector" inline="true" class="hu.user.lis.ui.editor.widget.EntitySelector"?>
                             </vlayout>
                         </tabpanel>
                         <tabpanel>
-                            <borderlayout>
-                                <north flex="true">
-                                    <toolbar>
-                                        <toolbarbutton label="Feltöltés" iconSclass="z-icon-plus" upload="true"
-                                                       onUpload="@command('onUploadFile')"/>
-                                        <toolbarbutton label="Törlés" iconSclass="z-icon-remove"
-                                                       onClick="@command('onRemoveFile')"
-                                                       disabled="@load(empty vm.formDocument.file)"/>
-                                    </toolbar>
-                                </north>
-                                <center border="none" flex="true">
-                                    <iframe hflex="true" vflex="true"
-                                            content="@load(vm.formDocument.file) @converter('hu.user.lis.ui.converter.ByteArrayToAMediaConverter')"/>
-                                </center>
-                            </borderlayout>
+                            <include src="~./form/attachment-form.zul" hflex="true" vflex="true"/>
                         </tabpanel>
                     </tabpanels>
                 </tabbox>
index e117ba73a60f90460fba075754d538b72f403b38..cb8b99cb5d15352b5afdee74e52177b30fcdadd6 100644 (file)
                             </vlayout>
                         </tabpanel>
                         <tabpanel>
-                            <borderlayout>
-                                <north flex="true">
-                                    <toolbar>
-                                        <toolbarbutton label="Feltöltés" iconSclass="z-icon-plus" upload="true"
-                                                       onUpload="@command('onUploadFile')"/>
-                                        <toolbarbutton label="Törlés" iconSclass="z-icon-remove"
-                                                       onClick="@command('onRemoveFile')"
-                                                       disabled="@load(empty vm.formDocument.file)"/>
-                                    </toolbar>
-                                </north>
-                                <center border="none" flex="true">
-                                    <iframe hflex="true" vflex="true"
-                                            content="@load(vm.formDocument.file) @converter('hu.user.lis.ui.converter.ByteArrayToAMediaConverter')"/>
-                                </center>
-                            </borderlayout>
+                            <include src="~./form/attachment-form.zul" hflex="true" vflex="true"/>
                         </tabpanel>
                     </tabpanels>
                 </tabbox>