import org.springframework.transaction.annotation.Transactional;
import java.util.List;
+import java.util.Objects;
import java.util.stream.Collectors;
@Service
@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);
+ }
}
}
@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);
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);
}
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
@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);
}
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) {
}
public void handleEntitySaveEvent(SaveEntityEvent<Partner> event) {
- if (!event.isCanceled()) {
+ if (event.isSave()) {
getFormDocument().setPartner(event.getData());
}
}
} else {
Events.postEvent(new Event("onClose", target, ImmutableMap.of(
"modifiedEntity", getFormDocument(),
- "status", status
+ "status", status,
+ "actions", getEntityDocumentDataModel().getActions()
)));
}
}
}
public void handleEntitySaveEvent(SaveEntityEvent<Partner> event) {
- if (!event.isCanceled()) {
+ if (event.isSave()) {
getFormDocument().setPartner(event.getData());
}
}
} else {
Events.postEvent(new Event("onClose", target, ImmutableMap.of(
"modifiedEntity", getFormDocument(),
- "status", status
+ "status", status,
+ "actions", getEntityDocumentDataModel().getActions()
)));
}
}
return invoiceFormValidator.validate(entity);
}
+ @Override
+ protected Class<?> getDocumentType() {
+ return Invoice.class;
+ }
+
@Override
public void onEvent(Event evt) {
if (isEventForCurrentDocument(evt)) {
private void incomingAdded(SaveEntityEvent<IncomingInvoice> event) {
- if (!event.isCanceled()) {
+ if (event.isSave()) {
IncomingInvoice modifiedEntity = event.getData();
getFormDocument().getIncomingInvoices().add(modifiedEntity);
selectedIncomingInvoice = modifiedEntity;
}
private void incomingModified(SaveEntityEvent<IncomingInvoice> event) {
- if (!event.isCanceled()) {
+ if (event.isSave()) {
List<IncomingInvoice> incomingInvoices = getFormDocument().getIncomingInvoices();
incomingInvoices.remove(selectedIncomingInvoice);
IncomingInvoice modifiedEntity = event.getData();
}
private void outgoingAdded(SaveEntityEvent<OutgoingInvoice> event) {
- if (!event.isCanceled()) {
+ if (event.isSave()) {
OutgoingInvoice modifiedEntity = event.getData();
getFormDocument().getOutgoingInvoices().add(modifiedEntity);
selectedOutgoingInvoice = modifiedEntity;
}
private void outgoingModified(SaveEntityEvent<OutgoingInvoice> event) {
- if (!event.isCanceled()) {
+ if (event.isSave()) {
OutgoingInvoice modifiedEntity = event.getData();
List<OutgoingInvoice> outgoingInvoices = getFormDocument().getOutgoingInvoices();
outgoingInvoices.remove(selectedOutgoingInvoice);
}
private void treasuryAdded(SaveEntityEvent<Treasury> event) {
- if (!event.isCanceled()) {
+ if (event.isSave()) {
Treasury modifiedEntity = event.getData();
getFormDocument().getTreasuries().add(modifiedEntity);
selectedTreasury = modifiedEntity;
}
private void treasuryModified(SaveEntityEvent<Treasury> event) {
- if (!event.isCanceled()) {
+ if (event.isSave()) {
Treasury modifiedEntity = event.getData();
List<Treasury> treasuries = getFormDocument().getTreasuries();
treasuries.remove(selectedTreasury);
}
}
+ @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());
return treasuryFormValidator.validate(entity);
}
+ @Override
+ protected Class<?> getDocumentType() {
+ return Treasury.class;
+ }
+
}
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;
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;
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
return;
}
EDocument document = EDocument.builder()
- .documentType(getDocumentType())
+ .documentType(getDocumentType().getSimpleName())
.file(evt.getMedia().getByteData())
.size(evt.getMedia().getByteData().length)
.name(evt.getMedia().getName())
}
}
- 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() {
return (T) super.getData();
}
- public boolean isCanceled() {
- return this instanceof CancelEntityEditEvent;
+ public boolean isSave() {
+ return !(this instanceof CancelEntityEditEvent);
}
public SaveEntityWithAttachmentEvent<T> withAttachment() {
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;
import org.zkoss.zkplus.spring.DelegatingVariableResolver;
import org.zkoss.zul.Window;
+import java.util.List;
import java.util.Map;
import java.util.Objects;
ProcessEventRouter processEventRouter;
@WireVariable
- InvoiceRepository invoiceRepository;
+ InvoiceDataModel invoiceDataModel;
@WireVariable
PartnerRepository partnerRepository;
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();
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;
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;
WorkflowManagerService workflowManagerService;
@WireVariable
- InvoiceRepository invoiceRepository;
+ InvoiceDataModel invoiceDataModel;
@WireVariable
EventBus eventBus;
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
}
private void saveAssociate(SaveEntityEvent<Associate> event) {
- if (!event.isCanceled()) {
+ if (event.isSave()) {
Associate modifiedEntity = event.getData();
associatesDataModel.save(modifiedEntity);
refresh();
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();
}
}
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.*;
@WireVariable
private InvoiceDataModel invoiceDataModel;
-// @Getter
-// @WireVariable
-// private DateTypeConverter dateTypeConverter;
-
@Init
@Override
public void init() {
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();
}
}
}
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();
}
}
}
private void savePartner(SaveEntityEvent<Partner> event) {
- if (!event.isCanceled()) {
+ if (event.isSave()) {
Partner modifiedEntity = event.getData();
partnersDataModel.save(modifiedEntity);
refresh();
}
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());
+<?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>
</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>