package hu.user.lis;
-import com.google.common.collect.Sets;
import hu.user.lis.db.Associate;
import hu.user.lis.db.Project;
import hu.user.lis.db.Treasury;
import org.springframework.test.context.junit4.SpringRunner;
import java.util.Arrays;
+import java.util.Collections;
import java.util.List;
import static org.assertj.core.api.Assertions.assertThat;
.build();
Project project = Project.builder()
.id(1L)
- .treasuries(Sets.newHashSet(treasury))
+ .treasuries(Collections.singletonList(treasury))
.build();
Project clone = SerializationUtils.clone(project);
Treasury cloneTreasury = (Treasury) clone.getTreasuries().toArray()[0];
.build();
Project project = Project.builder()
.id(1L)
- .treasuries(Sets.newHashSet(treasury1, treasury2))
+ .treasuries(Arrays.asList(treasury1, treasury2))
.build();
Project clone = SerializationUtils.clone(project);
Treasury treasury3 = Treasury.builder()
.id(2L)
.humanId("Test2")
.build();
- clone.setTreasuries(Sets.newHashSet(treasury4, treasury3));
+ clone.setTreasuries(Arrays.asList(treasury4, treasury3));
assertTrue(entityDataService.areEquals(project, clone));
}
}
--- /dev/null
+-- // add signed to service_record
+-- Migration SQL that makes the change goes here.
+
+ALTER TABLE service_record ADD COLUMN signed SMALLINT NOT NULL DEFAULT 0;
+
+-- //@UNDO
+-- SQL to undo the change goes here.
+
+ALTER TABLE service_record DROP COLUMN signed;
+CALL SYSPROC.ADMIN_CMD('REORG TABLE service_record');
--- /dev/null
+-- // add order to treasury
+-- Migration SQL that makes the change goes here.
+
+ALTER TABLE treasury ADD COLUMN pos SMALLINT NOT NULL DEFAULT 0;
+
+-- //@UNDO
+-- SQL to undo the change goes here.
+
+ALTER TABLE treasury DROP COLUMN pos;
+CALL SYSPROC.ADMIN_CMD('REORG TABLE treasury');
--- /dev/null
+-- // add order to invoice
+-- Migration SQL that makes the change goes here.
+
+ALTER TABLE invoice ADD COLUMN pos SMALLINT NOT NULL DEFAULT 0;
+
+-- //@UNDO
+-- SQL to undo the change goes here.
+
+ALTER TABLE invoice DROP COLUMN pos;
+CALL SYSPROC.ADMIN_CMD('REORG TABLE invoice');
--- /dev/null
+-- // add order to invoice
+-- Migration SQL that makes the change goes here.
+
+ALTER TABLE invoice ADD COLUMN technical_id VARCHAR(8);
+
+-- //@UNDO
+-- SQL to undo the change goes here.
+
+ALTER TABLE invoice DROP COLUMN technical_id;
+CALL SYSPROC.ADMIN_CMD('REORG TABLE invoice');
--- /dev/null
+-- // add order to treasury
+-- Migration SQL that makes the change goes here.
+
+ALTER TABLE treasury ADD COLUMN technical_id VARCHAR(8);
+
+-- //@UNDO
+-- SQL to undo the change goes here.
+
+ALTER TABLE treasury DROP COLUMN technical_id;
+CALL SYSPROC.ADMIN_CMD('REORG TABLE treasury');
--- /dev/null
+-- // remove file
+-- Migration SQL that makes the change goes here.
+
+ALTER TABLE treasury DROP COLUMN file;
+CALL SYSPROC.ADMIN_CMD('REORG TABLE treasury');
+
+ALTER TABLE invoice DROP COLUMN file;
+CALL SYSPROC.ADMIN_CMD('REORG TABLE invoice');
+
+ALTER TABLE service_record DROP COLUMN file;
+CALL SYSPROC.ADMIN_CMD('REORG TABLE service_record');
+
+-- //@UNDO
+-- SQL to undo the change goes here.
+
+ALTER TABLE treasury ADD COLUMN file BLOB;
+CALL SYSPROC.ADMIN_CMD('REORG TABLE treasury');
+
+ALTER TABLE invoice ADD COLUMN file BLOB;
+CALL SYSPROC.ADMIN_CMD('REORG TABLE invoice');
+
+ALTER TABLE service_record ADD COLUMN file BLOB;
+CALL SYSPROC.ADMIN_CMD('REORG TABLE service_record');
package hu.user.lis.db;
-import lombok.*;
+import lombok.AllArgsConstructor;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+import lombok.Setter;
+import lombok.experimental.SuperBuilder;
import javax.persistence.Entity;
-import javax.persistence.GeneratedValue;
-import javax.persistence.GenerationType;
-import javax.persistence.Id;
-import java.io.Serializable;
@Getter
@Setter
@Entity
-@Builder
+@SuperBuilder
@NoArgsConstructor
@AllArgsConstructor
-public class Associate implements Serializable {
- @Id
- @GeneratedValue(strategy = GenerationType.IDENTITY)
- Long id;
- String name;
- String login;
- String password;
- double monthlyCost;
- boolean active;
- boolean remotelyAuthenticated;
+public class Associate extends IdEntity {
+
+ private String name;
+
+ private String login;
+
+ private String password;
+
+ private double monthlyCost;
+
+ private boolean active;
+
+ private boolean remotelyAuthenticated;
}
Currency(int val) {
this.val = val;
}
-
-
}
package hu.user.lis.db;
-import lombok.*;
+import lombok.AllArgsConstructor;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+import lombok.Setter;
+import lombok.experimental.SuperBuilder;
import org.hibernate.annotations.CreationTimestamp;
-import javax.persistence.*;
-import java.io.Serializable;
+import javax.persistence.Column;
+import javax.persistence.Entity;
import java.util.Date;
@Getter
@Setter
@Entity
-@Builder
+@SuperBuilder
@NoArgsConstructor
@AllArgsConstructor
-public class EDocument implements Serializable {
- @Id
- @GeneratedValue(strategy = GenerationType.IDENTITY)
- private Long id;
+public class EDocument extends IdEntity {
@Column(nullable = false)
private Long referenceId;
--- /dev/null
+package hu.user.lis.db;
+
+import lombok.AllArgsConstructor;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+import lombok.Setter;
+import lombok.experimental.SuperBuilder;
+
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+import javax.persistence.MappedSuperclass;
+import java.io.Serializable;
+
+@Getter
+@Setter
+@SuperBuilder
+@MappedSuperclass
+@NoArgsConstructor
+@AllArgsConstructor
+public class IdEntity implements Serializable {
+
+ @Id
+ @GeneratedValue(strategy = GenerationType.IDENTITY)
+ private Long id;
+
+}
package hu.user.lis.db;
+import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;
import javax.persistence.DiscriminatorValue;
@Entity
@SuperBuilder
+@NoArgsConstructor
@DiscriminatorValue("1")
public class IncomingInvoice extends Invoice {
- public IncomingInvoice() {
- incoming = true;
- }
}
import lombok.experimental.SuperBuilder;
import javax.persistence.*;
-import java.io.Serializable;
import java.util.Date;
@Getter
@NoArgsConstructor
@DiscriminatorColumn(name = "incoming", discriminatorType = DiscriminatorType.INTEGER)
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
-public class Invoice implements Serializable {
- @Id
- @GeneratedValue(strategy = GenerationType.IDENTITY)
- Long id;
+public class Invoice extends IdEntity {
- String humanId;
+ @OneToOne
+ @JoinColumn(name = "partner_id")
+ @JsonIncludeProperties({"id"})
+ private Partner partner;
- String title;
+ @ManyToOne
+ @JoinColumn(name = "project_id")
+ @JsonIncludeProperties({"id"})
+ private Project project;
- Currency currency;
+ private String humanId;
- double netAmount;
+ private String title;
- double grossAmount;
+ private Currency currency;
- double vatAmount;
+ private double netAmount;
- Date completionDate;
+ private double grossAmount;
- Date createDate;
+ private double vatAmount;
- Date paymentDeadline;
+ private Date completionDate;
- @Column(nullable = false, insertable = false, updatable = false)
- boolean incoming;
+ private Date createDate;
- InvoiceStatus status;
+ private Date paymentDeadline;
- boolean paid;
+ private InvoiceStatus status;
- boolean planned;
+ @Column(nullable = false, insertable = false, updatable = false)
+ private boolean incoming;
- byte[] file;
+ private boolean planned;
- @OneToOne
- @JoinColumn(name = "partner_id")
- @JsonIncludeProperties({"id"})
- Partner partner;
+ private boolean paid;
+
+ private String technicalId;
- @ManyToOne
- @JoinColumn(name = "project_id")
- @JsonIncludeProperties({"id"})
- Project project;
}
import com.fasterxml.jackson.annotation.JsonIncludeProperties;
import hu.user.lis.db.converter.StringListConverter;
-import lombok.*;
+import lombok.AllArgsConstructor;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+import lombok.Setter;
+import lombok.experimental.SuperBuilder;
import org.hibernate.annotations.CreationTimestamp;
import javax.persistence.*;
-import java.io.Serializable;
import java.util.Date;
import java.util.List;
@Getter
@Setter
@Entity
-@Builder
+@SuperBuilder
@NoArgsConstructor
@AllArgsConstructor
-public class InvoiceImport implements Serializable {
- @Id
- @GeneratedValue(strategy = GenerationType.IDENTITY)
- private Long id;
+public class InvoiceImport extends IdEntity {
@ManyToOne
@JoinColumn(name = "invoice_id")
@Getter
public enum InvoiceStatus {
+
INACTIVE(0), ACTIVE(1), SUSPENDED(2);
- final int val;
+
+ private final int val;
InvoiceStatus(int val) {
this.val = val;
}
-
}
package hu.user.lis.db;
-import lombok.*;
+import lombok.AllArgsConstructor;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+import lombok.Setter;
+import lombok.experimental.SuperBuilder;
-import javax.persistence.*;
-import java.io.Serializable;
+import javax.persistence.Column;
+import javax.persistence.Entity;
@Getter
@Setter
@Entity
-@Builder
+@SuperBuilder
@NoArgsConstructor
@AllArgsConstructor
-public class Partner implements Serializable {
- @Id
- @GeneratedValue(strategy = GenerationType.IDENTITY)
- Long id;
+public class Partner extends IdEntity {
- String name;
+ private String name;
@Column(nullable = false)
- String shortName;
+ private String shortName;
@Column(unique = true)
- String vatNr;
+ private String vatNr;
- String address;
+ private String address;
- String orderDescription;
+ private String orderDescription;
- boolean active;
+ private boolean active;
- boolean createdByImport;
+ private boolean createdByImport;
}
package hu.user.lis.db;
import com.fasterxml.jackson.annotation.JsonIncludeProperties;
-import lombok.*;
+import lombok.AllArgsConstructor;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+import lombok.Setter;
+import lombok.experimental.SuperBuilder;
-import javax.persistence.*;
-import java.io.Serializable;
+import javax.persistence.Entity;
+import javax.persistence.JoinColumn;
+import javax.persistence.ManyToOne;
import java.util.Date;
@Getter
@Setter
@Entity
-@Builder
+@SuperBuilder
@NoArgsConstructor
@AllArgsConstructor
-public class Payment implements Serializable {
+public class Payment extends IdEntity {
+
@ManyToOne
@JoinColumn(name = "invoice_id")
@JsonIncludeProperties({"id"})
- Invoice invoice;
- @Id
- @GeneratedValue(strategy = GenerationType.IDENTITY)
- Long id;
- double netAmount;
- double grossAmount;
- double vatAmount;
- Date paymentDate;
+ private Invoice invoice;
+
+ private double netAmount;
+
+ private double grossAmount;
+
+ private double vatAmount;
+
+ private Date paymentDate;
}
package hu.user.lis.db;
-import lombok.*;
+import lombok.AllArgsConstructor;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+import lombok.Setter;
+import lombok.experimental.SuperBuilder;
import javax.persistence.Entity;
-import javax.persistence.GeneratedValue;
-import javax.persistence.GenerationType;
-import javax.persistence.Id;
-import java.io.Serializable;
@Getter
@Setter
@Entity
-@Builder
+@SuperBuilder
@NoArgsConstructor
@AllArgsConstructor
-public class Profile implements Serializable {
- @Id
- @GeneratedValue(strategy = GenerationType.IDENTITY)
- Long id;
- String login;
- String type;
- String setting;
+public class Profile extends IdEntity {
+
+ private String login;
+
+ private String type;
+
+ private String setting;
}
package hu.user.lis.db;
import com.fasterxml.jackson.annotation.JsonIncludeProperties;
-import lombok.*;
+import lombok.AllArgsConstructor;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+import lombok.Setter;
+import lombok.experimental.SuperBuilder;
import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;
import org.hibernate.annotations.Where;
import javax.persistence.*;
-import java.io.Serializable;
-import java.util.Set;
+import java.util.List;
@Getter
@Setter
@Entity
-@Builder
+@SuperBuilder
@NoArgsConstructor
@AllArgsConstructor
-public class Project implements Serializable {
- @Id
- @GeneratedValue(strategy = GenerationType.IDENTITY)
- Long id;
+public class Project extends IdEntity {
@ManyToOne
@JoinColumn(name = "project_status_id")
- ProjectStatus projectStatus;
+ private ProjectStatus projectStatus;
@ManyToOne
@Fetch(FetchMode.JOIN)
@JsonIncludeProperties({"id"})
- Partner partner;
+ private Partner partner;
@OneToMany(targetEntity = IncomingInvoice.class, cascade = CascadeType.ALL, fetch = FetchType.EAGER)
@JoinColumn(name = "project_id", referencedColumnName = "id")
@Where(clause = "incoming=1")
@Fetch(FetchMode.JOIN)
+ @OrderColumn(name = "pos")
@JsonIncludeProperties({"id"})
- Set<IncomingInvoice> incomingInvoices;
+ private List<IncomingInvoice> incomingInvoices;
@OneToMany(targetEntity = OutgoingInvoice.class, cascade = CascadeType.ALL, fetch = FetchType.EAGER)
@JoinColumn(name = "project_id", referencedColumnName = "id")
@Where(clause = "incoming=0")
@Fetch(FetchMode.JOIN)
+ @OrderColumn(name = "pos")
@JsonIncludeProperties({"id"})
- Set<OutgoingInvoice> outgoingInvoices;
+ private List<OutgoingInvoice> outgoingInvoices;
@OneToMany(targetEntity = Treasury.class, cascade = CascadeType.ALL, fetch = FetchType.EAGER, orphanRemoval = true)
@JoinColumn(name = "project_id", referencedColumnName = "id")
@Fetch(FetchMode.JOIN)
+ @OrderColumn(name = "pos")
@JsonIncludeProperties({"id"})
- Set<Treasury> treasuries;
+ private List<Treasury> treasuries;
- String name;
+ private String name;
- String humanId;
+ private String humanId;
- String contactName;
+ private String contactName;
- boolean active;
+ private boolean active;
}
package hu.user.lis.db;
-import lombok.*;
+import lombok.AllArgsConstructor;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+import lombok.Setter;
+import lombok.experimental.SuperBuilder;
import javax.persistence.Entity;
-import javax.persistence.GeneratedValue;
-import javax.persistence.GenerationType;
-import javax.persistence.Id;
-import java.io.Serializable;
@Getter
@Setter
@Entity
-@Builder
+@SuperBuilder
@NoArgsConstructor
@AllArgsConstructor
-public class ProjectAssociate implements Serializable {
- @Id
- @GeneratedValue(strategy = GenerationType.IDENTITY)
- Long id;
- Long projectId;
- Long associateId;
+public class ProjectAssociate extends IdEntity {
+
+ private Long projectId;
+
+ private Long associateId;
+
}
package hu.user.lis.db;
-import lombok.*;
+import lombok.AllArgsConstructor;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+import lombok.Setter;
+import lombok.experimental.SuperBuilder;
import javax.persistence.Entity;
-import javax.persistence.GeneratedValue;
-import javax.persistence.GenerationType;
-import javax.persistence.Id;
-import java.io.Serializable;
@Getter
@Setter
@Entity
-@Builder
+@SuperBuilder
@NoArgsConstructor
@AllArgsConstructor
-public class ProjectStatus implements Serializable {
- @Id
- @GeneratedValue(strategy = GenerationType.IDENTITY)
- Long id;
- String name;
- boolean active;
- int order;
+public class ProjectStatus extends IdEntity {
+
+ private String name;
+
+ private boolean active;
+
+ private int order;
}
package hu.user.lis.db;
import com.fasterxml.jackson.annotation.JsonIncludeProperties;
-import lombok.*;
-
-import javax.persistence.*;
-import java.io.Serializable;
+import lombok.AllArgsConstructor;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+import lombok.Setter;
+import lombok.experimental.SuperBuilder;
+
+import javax.persistence.Entity;
+import javax.persistence.JoinColumn;
+import javax.persistence.ManyToOne;
import java.util.Date;
@Getter
@Setter
@Entity
-@Builder
+@SuperBuilder
@NoArgsConstructor
@AllArgsConstructor
-public class ServiceRecord implements Serializable {
- @Id
- @GeneratedValue(strategy = GenerationType.IDENTITY)
- private Long id;
+public class ServiceRecord extends IdEntity {
@ManyToOne
@JoinColumn(name = "project_id")
private int workHours;
private double cost;
-
- private byte[] file;
+
+ private boolean signed;
+
}
+++ /dev/null
-package hu.user.lis.db;
-
-import lombok.AllArgsConstructor;
-import lombok.Builder;
-import lombok.Getter;
-import lombok.Setter;
-
-@Getter
-@Setter
-@Builder
-@AllArgsConstructor
-public class Supplier {
- String id;
- String name;
- String zipCode;
-}
package hu.user.lis.db;
-import lombok.*;
+import com.fasterxml.jackson.annotation.JsonIncludeProperties;
+import lombok.AllArgsConstructor;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+import lombok.Setter;
+import lombok.experimental.SuperBuilder;
import javax.persistence.Entity;
-import javax.persistence.GeneratedValue;
-import javax.persistence.GenerationType;
-import javax.persistence.Id;
-import java.io.Serializable;
+import javax.persistence.JoinColumn;
+import javax.persistence.ManyToOne;
import java.util.Date;
@Getter
@Setter
@Entity
-@Builder
+@SuperBuilder
@NoArgsConstructor
@AllArgsConstructor
-public class Treasury implements Serializable {
+public class Treasury extends IdEntity {
- @Id
- @GeneratedValue(strategy = GenerationType.IDENTITY)
- Long id;
+ @ManyToOne
+ @JoinColumn(name = "project_id")
+ @JsonIncludeProperties({"id"})
+ private Project project;
- String humanId;
+ private String humanId;
- double buyAmount;
+ private double buyAmount;
- Currency buyCurrency;
+ private Currency buyCurrency;
- double sellAmount;
+ private double sellAmount;
- Currency sellCurrency;
+ private Currency sellCurrency;
- Date transactionDate;
+ private Date transactionDate;
- Date valueDate;
+ private Date valueDate;
- byte[] file;
-
-// @ManyToOne(fetch = FetchType.LAZY)
-// @JoinColumn(name = "project_id")
-// @JsonIncludeProperties({"id"})
-// Project project;
+ private String technicalId;
}
import hu.user.lis.db.EDocument;
import org.springframework.data.jpa.repository.JpaRepository;
+import org.springframework.data.jpa.repository.Modifying;
+import org.springframework.data.jpa.repository.Query;
import java.util.List;
public interface EDocumentRepository extends JpaRepository<EDocument, Long> {
List<EDocument> findByReferenceIdAndDocumentType(Long referenceId, String documentType);
+ @Modifying
+ @Query("UPDATE EDocument e SET e.referenceId = :referenceId WHERE e.id IN (:ids)")
+ void attach(Long referenceId, List<Long> ids);
}
import java.util.List;
import java.util.Objects;
-import java.util.Set;
@Log4j2
@RestController
@Override
protected void afterSave(List<Project> entities) {
entities.forEach(p -> {
- Set<IncomingInvoice> incomingInvoices = p.getIncomingInvoices();
+ List<IncomingInvoice> incomingInvoices = p.getIncomingInvoices();
if (Objects.nonNull(incomingInvoices)) {
incomingInvoices.forEach(i -> {
// i.setProject(p);
});
}
- Set<OutgoingInvoice> outgoingInvoices = p.getOutgoingInvoices();
+ List<OutgoingInvoice> outgoingInvoices = p.getOutgoingInvoices();
if (Objects.nonNull(outgoingInvoices)) {
outgoingInvoices.forEach(i -> {
// i.setProject(p);
});
}
- Set<Treasury> treasuries = p.getTreasuries();
+ List<Treasury> treasuries = p.getTreasuries();
treasuries.forEach(t -> {
// t.setProject(p);
treasuryRepository.save(t);
+++ /dev/null
-package hu.user.lis.service.data;
-
-import hu.user.lis.db.EDocument;
-
-public interface EDocumentService extends DataService<EDocument> {
- EDocument createNew();
-
- void add(EDocument entity);
-}
+++ /dev/null
-package hu.user.lis.service.data;
-
-import hu.user.lis.db.EDocument;
-import lombok.extern.log4j.Log4j2;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Service;
-
-import java.util.ArrayList;
-import java.util.List;
-
-@Service
-@Log4j2
-public class EDocumentServiceImpl extends DataServiceImpl<EDocument> implements EDocumentService {
- @Autowired
- DataGeneratorService dataGeneratorService;
- private List<EDocument> entities;
-
- @Override
- public List<EDocument> getAll() {
- if (entities == null) {
- entities = new ArrayList<>();
- }
- return entities;
- }
-
- @Override
- public EDocument createNew() {
- return EDocument.builder().build();
- }
-
- @Override
- public void add(EDocument entity) {
- entities.add(entity);
- }
-
-}
--- /dev/null
+package hu.user.lis.service.data;
+
+import lombok.*;
+
+@Getter
+@Setter
+@Builder
+@NoArgsConstructor
+@AllArgsConstructor
+public class EntityDocumentAction {
+
+ private boolean attach;
+
+ private Long documentId;
+
+ public boolean isDetach() {
+ return !attach;
+ }
+}
--- /dev/null
+package hu.user.lis.service.data;
+
+import hu.user.lis.db.repository.EDocumentRepository;
+import lombok.extern.log4j.Log4j2;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+import java.util.List;
+import java.util.stream.Collectors;
+
+@Service
+@Log4j2
+public class EntityDocumentService {
+ @Autowired
+ private EDocumentRepository eDocumentRepository;
+
+ @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);
+ }
+
+}
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
-import java.util.HashSet;
import java.util.List;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
ProjectStatus projectStatus = projectStatusService.getAll().get(0);
return Project.builder()
.projectStatus(projectStatus)
- .incomingInvoices(new HashSet<>())
- .outgoingInvoices(new HashSet<>())
- .treasuries(new HashSet<>())
+// .incomingInvoices(new HashSet<>())
+// .outgoingInvoices(new HashSet<>())
+ .treasuries(new ArrayList<>())
.active(true)
.build();
}
.partner(partner)
// .incomingInvoices(invoiceService.getRandom(true))
// .outgoingInvoices(invoiceService.getRandom(false))
- .treasuries(new HashSet<>())
+ .treasuries(new ArrayList<>())
.build();
result.add(entity);
}
.partner(partner)
// .incomingInvoices(invoiceService.getByHumanIds(new String[]{"VSz-2023/00070-"})) // VSz-2023/00070-
// .outgoingInvoices(invoiceService.getByHumanIds(new String[]{"USER-2023-7"})) // USER-2023-7
- .treasuries(new HashSet<>())
+// .treasuries(new HashSet<>())
.build();
result.add(entity);
.partner(partner)
// .incomingInvoices(invoiceService.getByHumanIds(new String[]{"582-SPI1003006-3021", "582-SPI003118", "582-SPI003680", "582-SPI003681", "582-SPI004090", "9090010764", "VSz-2021/00091"})) // 582-SPI1003006-3021, 582-SPI003118, 582-SPI003680, 582-SPI003681, 582-SPI004090, 9090010764, VSz-2021/00091
// .outgoingInvoices(invoiceService.getByHumanIds(new String[]{"2021/0001", "2021/0069"})) // 2021/0001, 2021/0069
- .treasuries(treasuryService.getByHumanIds(new String[]{"014", "015"}))
+// .treasuries(treasuryService.getByHumanIds(new String[]{"014", "015"}))
.build();
result.add(entity);
.partner(partner)
// .incomingInvoices(invoiceService.getByHumanIds(new String[]{"EURSZLA0177/2022", "19044", "9171058452", "9171058628", "2022-SOV/000495", "2022-SOV/000496", "E-SYMPR-2022-105"})) // EURSZLA0177/2022, 19044, 9171058452, 9171058628, V-SZ3-2022/00001, 2022-SOV/000495, 2022-SOV/000496, E-SYMPR-2022-105
// .outgoingInvoices(invoiceService.getByHumanIds(new String[]{"E-USER-2023-12", "E-USER-2023-13"})) // E-USER-2023-12, E-USER-2023-13
- .treasuries(treasuryService.getByHumanIds(new String[]{"001", "002", "003", "004", "005", "006", "007", "008", "009", "010", "011"}))
+// .treasuries(treasuryService.getByHumanIds(new String[]{"001", "002", "003", "004", "005", "006", "007", "008", "009", "010", "011"}))
.build();
result.add(entity);
.partner(partner)
// .incomingInvoices(invoiceService.getByHumanIds(new String[]{"17356/23"})) // 17356/23
// .outgoingInvoices(invoiceService.getByHumanIds(new String[]{"E-USER-2023-53"})) // E-USER-2023-53
- .treasuries(new HashSet<>())
+// .treasuries(new HashSet<>())
.build();
result.add(entity);
.partner(partner)
// .incomingInvoices(invoiceService.getByHumanIds(new String[]{"2023-SOV/000123"})) // 2023-SOV/000123
// .outgoingInvoices(invoiceService.getByHumanIds(new String[]{"E-USER-2023-95"})) // E-USER-2023-95
- .treasuries(treasuryService.getByHumanIds(new String[]{"012", "013"}))
+// .treasuries(treasuryService.getByHumanIds(new String[]{"012", "013"}))
.build();
result.add(entity);
+++ /dev/null
-package hu.user.lis.service.data;
-
-import hu.user.lis.db.Supplier;
-
-public interface SupplierService extends DataService<Supplier> {
-}
+++ /dev/null
-package hu.user.lis.service.data;
-
-import hu.user.lis.db.Supplier;
-import org.apache.commons.lang3.RandomStringUtils;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Service;
-
-import java.util.ArrayList;
-import java.util.List;
-
-@Service
-public class SupplierServiceImpl extends DataServiceImpl<Supplier> implements SupplierService {
- @Autowired
- DataGeneratorService dataGeneratorService;
- private List<Supplier> suppliers;
-
- @Override
- public List<Supplier> getAll() {
- if (suppliers == null) {
- suppliers = generate();
- }
- return suppliers;
- }
-
- private List<Supplier> generate() {
- List<Supplier> result = new ArrayList<>();
- for (int i = 0; i < 100; i++) {
- String name = dataGeneratorService.faker().name().fullName();
- String zipCode = RandomStringUtils.random(4, "0123456789");
- Supplier supplier = Supplier.builder().name(name).zipCode(zipCode).build();
- result.add(supplier);
- }
- return result;
- }
-}
@Mapping(target = "id", ignore = true)
@Mapping(target = "title", ignore = true)
@Mapping(target = "planned", ignore = true)
- @Mapping(target = "file", ignore = true)
@Mapping(target = "partner", ignore = true)
@Mapping(target = "project", ignore = true)
IncomingInvoice toEntity(InvoiceData source);
+++ /dev/null
-package hu.user.lis.ui.converter;
-
-import hu.user.lis.db.Supplier;
-import org.zkoss.bind.BindContext;
-import org.zkoss.bind.Converter;
-import org.zkoss.zul.Bandbox;
-
-public class SupplierToNameConverter implements Converter<String, Supplier, Bandbox> {
-
- @Override
- public String coerceToUi(Supplier supplier, Bandbox bandbox, BindContext bindContext) {
- return supplier == null ? null : supplier.getName();
- }
-
- @Override
- public Supplier coerceToBean(String s, Bandbox bandbox, BindContext bindContext) {
- return null;
- }
-}
\ No newline at end of file
package hu.user.lis.ui.data;
import hu.user.lis.db.EDocument;
+import hu.user.lis.db.IdEntity;
import hu.user.lis.db.repository.EDocumentRepository;
+import hu.user.lis.service.data.EntityDocumentAction;
+import lombok.Getter;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.zkoss.bind.BindUtils;
import org.zkoss.bind.annotation.Command;
import org.zkoss.zul.ListModelList;
+import org.zkoss.zul.Messagebox;
import java.util.*;
+import java.util.stream.Collectors;
@Log4j2
@Component
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class EntityDocumentDataModel extends ListModelList<EDocument> {
- private final List<EDocument> added = new ArrayList<>();
- private final List<EDocument> removed = new ArrayList<>();
+
+ @Getter
+ private final List<EntityDocumentAction> actions = new ArrayList<>();
+
@Autowired
private EDocumentRepository eDocumentRepository;
-
public EDocument getSelectedDocument() {
EDocument result = null;
Set<EDocument> documents = getSelection();
return result;
}
-
public void setSelectedDocument(EDocument document) {
clearSelection();
if (Objects.nonNull(document)) {
BindUtils.postNotifyChange(this, "selectedDocument");
}
- public void refresh(Long referenceId, String documentType) {
+ public void refresh(IdEntity formDocument, String documentType, List<EntityDocumentAction> actions) {
clear();
- List<EDocument> documents = eDocumentRepository.findByReferenceIdAndDocumentType(referenceId, documentType);
- addAll(documents);
- if (!documents.isEmpty()) {
- setSelectedDocument(documents.stream().findFirst().get());
+ if (Objects.nonNull(formDocument.getId())) {
+ if (Objects.nonNull(actions)) {
+ List<Long> ids = actions.stream().filter(EntityDocumentAction::isAttach).map(EntityDocumentAction::getDocumentId).collect(Collectors.toList());
+ if (!ids.isEmpty()) {
+ List<EDocument> allById = eDocumentRepository.findAllById(ids);
+ addAll(allById);
+ }
+ }
+
+ List<EDocument> documents = eDocumentRepository.findByReferenceIdAndDocumentType(formDocument.getId(), documentType);
+ addAll(documents);
+
+ if (!getInnerList().isEmpty()) {
+ setSelectedDocument(getInnerList().get(0));
+ }
}
}
public void addNew(EDocument document) {
- added.add(document);
+ long count = getInnerList().stream().filter(d -> d.getName().equals(document.getName()) && d.getSize() == document.getSize()).count();
+ if (count > 0) {
+ Messagebox.show("A fájl már csatolva van.");
+ return;
+ }
+ eDocumentRepository.save(document);
add(document);
setSelectedDocument(document);
+ actions.add(EntityDocumentAction.builder().attach(true).documentId(document.getId()).build());
}
public void remove() {
- EDocument selectedDocument = getSelectedDocument();
- removed.add(selectedDocument);
- setSelectedDocument(null);
- remove(selectedDocument);
+ EDocument document = getSelectedDocument();
+ if (Objects.nonNull(document)) {
+ actions.add(EntityDocumentAction.builder().documentId(document.getId()).build());
+ setSelectedDocument(null);
+ remove(document);
+ }
}
- public void save(Long entityId) {
- eDocumentRepository.deleteAll(removed);
- added.forEach(d -> d.setReferenceId(entityId));
- eDocumentRepository.saveAll(added);
+ public boolean hasFiles() {
+ return !getInnerList().isEmpty();
}
public boolean isChanged() {
- return !added.isEmpty() || !removed.isEmpty();
+ return !actions.isEmpty();
}
@Command
public void recalculate(Project project, ServiceRecordsDataModel serviceRecordsDataModel) {
clear();
Map<Currency, Double> balances = new HashMap<>();
- Set<OutgoingInvoice> outgoingInvoices = project.getOutgoingInvoices();
+ List<OutgoingInvoice> outgoingInvoices = project.getOutgoingInvoices();
if (Objects.nonNull(outgoingInvoices)) {
for (Invoice invoice : outgoingInvoices) {
addBalance(balances, invoice.getCurrency(), invoice.getNetAmount());
}
}
- Set<IncomingInvoice> incomingInvoices = project.getIncomingInvoices();
+ List<IncomingInvoice> incomingInvoices = project.getIncomingInvoices();
if (Objects.nonNull(incomingInvoices)) {
for (Invoice invoice : incomingInvoices) {
substractBalance(balances, invoice.getCurrency(), invoice.getNetAmount());
}
}
- Set<Treasury> treasuries = project.getTreasuries();
+ List<Treasury> treasuries = project.getTreasuries();
if (Objects.nonNull(treasuries)) {
for (Treasury treasury : treasuries) {
substractBalance(balances, treasury.getSellCurrency(), treasury.getSellAmount());
.sorted(Comparator.comparing(IncomeMargin::getCurrency))
.collect(Collectors.toCollection(() -> this));
- BindUtils.postNotifyChange(null, null, this, "*");
+ BindUtils.postNotifyChange(this, "*");
}
import hu.user.lis.service.data.EntityDataService;
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;
}
public IncomingInvoice createNewIncomingInvoice() {
- return IncomingInvoice.builder().incoming(true).status(InvoiceStatus.ACTIVE).build();
+ String technicalId = RandomStringUtils.random(8, "0123456789abcdef");
+ return IncomingInvoice.builder().incoming(true).technicalId(technicalId).status(InvoiceStatus.ACTIVE).build();
}
public OutgoingInvoice createNewOutgoingInvoice() {
- return OutgoingInvoice.builder().status(InvoiceStatus.ACTIVE).build();
+ String technicalId = RandomStringUtils.random(8, "0123456789abcdef");
+ return OutgoingInvoice.builder().technicalId(technicalId).status(InvoiceStatus.ACTIVE).build();
}
public void save(Invoice modifiedEntity) {
import hu.user.lis.db.Project;
import hu.user.lis.db.ProjectStatus;
+import hu.user.lis.db.repository.InvoiceRepository;
import hu.user.lis.db.repository.ProjectRepository;
import hu.user.lis.service.data.EntityDataService;
import hu.user.lis.ui.data.common.CachedSpringDataModel;
import javax.persistence.EntityNotFoundException;
import java.text.DecimalFormat;
import java.time.Year;
-import java.util.HashSet;
+import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
@Autowired
ProjectRepository projectRepository;
+ @Autowired
+ InvoiceRepository invoiceRepository;
+
@Autowired
ProjectStatusDataModel projectStatusDataModel;
ProjectStatus projectStatus = projectStatusDataModel.getDefault();
return Project.builder()
.projectStatus(projectStatus)
- .incomingInvoices(new HashSet<>())
- .outgoingInvoices(new HashSet<>())
- .treasuries(new HashSet<>())
+ .incomingInvoices(new ArrayList<>())
+ .outgoingInvoices(new ArrayList<>())
+ .treasuries(new ArrayList<>())
.active(true)
.build();
}
+++ /dev/null
-package hu.user.lis.ui.data;
-
-import hu.user.lis.db.Supplier;
-import hu.user.lis.service.data.SupplierService;
-import hu.user.lis.ui.data.common.CachedDataModel;
-import lombok.extern.log4j.Log4j2;
-import org.apache.commons.lang3.StringUtils;
-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.bind.BindUtils;
-import org.zkoss.zul.FieldComparator;
-
-import java.util.Comparator;
-import java.util.List;
-import java.util.stream.Collectors;
-
-@Component
-@Log4j2
-@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
-public class SuppliersDataModel extends CachedDataModel<Supplier> {
- @Autowired
- SupplierService supplierService;
- private String partialName;
- private String partialZipCode;
- private boolean listAll;
-
- private boolean canExecuteSearch() {
- boolean result = StringUtils.isNotBlank(partialName) || StringUtils.isNotBlank(partialZipCode) || listAll;
- log.info("Can execute searchByProject: {}", result);
- return result;
- }
-
- private boolean filter(Supplier supplier) {
- if (listAll) {
- return true;
- }
-
- boolean result = true;
- if (StringUtils.isNotBlank(partialName)) {
- if (!supplier.getName().toLowerCase().startsWith(partialName.toLowerCase())) {
- result = false;
- }
- }
- if (StringUtils.isNotBlank(partialZipCode)) {
- if (!supplier.getZipCode().toLowerCase().startsWith(partialZipCode.toLowerCase())) {
- result = false;
- }
- }
- return result;
- }
-
- @Override
- public List<Supplier> getResultSet(int page, int pageSize, FieldComparator sortComparator) {
- List<Supplier> result = null;
- if (canExecuteSearch()) {
- result = supplierService.getAll().stream()
- .sorted(Comparator.comparing(Supplier::getName))
- .filter(s -> filter(s))
- .collect(Collectors.toList());
- }
- return result;
- }
-
- @Override
- public int getResultSetCount() {
- int result = 0;
- if (canExecuteSearch()) {
- result = (int) supplierService.getAll().stream()
- .filter(s -> filter(s))
- .count();
- }
- return result;
- }
-
- public void search(String partialName, String partialZipCode) {
- log.info("Searching supplier using filters: name LIKE {}, ZIP code LIKE {}", partialName, partialZipCode);
- listAll = false;
- this.partialName = partialName;
- this.partialZipCode = partialZipCode;
- super.reset();
- BindUtils.postNotifyChange(null, null, this, "*");
- }
-
- public void listAll() {
- log.info("List all suppliers");
- listAll = true;
- super.reset();
- BindUtils.postNotifyChange(null, null, this, "*");
- }
-}
+++ /dev/null
-package hu.user.lis.ui.data;
-
-import hu.user.lis.db.Supplier;
-import hu.user.lis.service.data.SupplierService;
-import hu.user.lis.ui.data.common.CachedDataModel;
-import lombok.extern.log4j.Log4j2;
-import org.apache.commons.lang3.StringUtils;
-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.bind.BindUtils;
-import org.zkoss.zul.FieldComparator;
-
-import java.util.Comparator;
-import java.util.List;
-import java.util.stream.Collectors;
-
-@Component
-@Log4j2
-@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
-public class SuppliersSimpleDataModel extends CachedDataModel<Supplier> {
- static private final int SEARCH_LIMIT = 10;
- @Autowired
- SupplierService supplierService;
- private String partialName;
-
- private boolean filter(Supplier supplier) {
- if (StringUtils.isBlank(partialName)) {
- return true;
- } else {
- if (supplier.getName().toLowerCase().startsWith(partialName.toLowerCase())) {
- return true;
- }
- }
- return false;
- }
-
- @Override
- public List<Supplier> getResultSet(int page, int pageSize, FieldComparator sortComparator) {
- List<Supplier> result = supplierService.getAll().stream()
- .sorted(Comparator.comparing(Supplier::getName))
- .filter(s -> filter(s))
- .limit(SEARCH_LIMIT)
- .collect(Collectors.toList());
- return result;
- }
-
- @Override
- public int getResultSetCount() {
- int result = (int) supplierService.getAll().stream()
- .filter(s -> filter(s))
- .limit(SEARCH_LIMIT)
- .count();
- return result;
- }
-
- public void search(String partialName) {
- log.info("Searching supplier using filter {}", partialName);
- this.partialName = partialName;
- super.reset();
- BindUtils.postNotifyChange(null, null, this, "*");
- }
-}
import hu.user.lis.db.Currency;
import hu.user.lis.db.Invoice;
import hu.user.lis.db.Partner;
-import hu.user.lis.ui.editor.common.EntityEditorModel;
+import hu.user.lis.ui.editor.common.EntityAttachmentEditorModel;
import hu.user.lis.ui.editor.validator.FormValidator;
import hu.user.lis.ui.editor.validator.InvoiceFormValidator;
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.annotation.*;
import org.zkoss.zk.ui.Component;
import org.zkoss.zk.ui.event.Event;
-import org.zkoss.zk.ui.event.UploadEvent;
import org.zkoss.zk.ui.select.annotation.WireVariable;
-import org.zkoss.zul.Messagebox;
@Log4j2
@Getter
@Setter
-public class InvoiceEditorModel extends EntityEditorModel<Invoice> {
+public class InvoiceEditorModel extends EntityAttachmentEditorModel<Invoice> {
private boolean vatCalculated;
return invoiceFormValidator.validate(entity);
}
- @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;
- }
- getFormDocument().setFile(evt.getMedia().getByteData());
- BindUtils.postNotifyChange(getFormDocument(), "file");
- validate();
- }
-
- @Command
- public void onRemoveFile() {
- getFormDocument().setFile(null);
- BindUtils.postNotifyChange(getFormDocument(), "file");
- validate();
- }
-
@Override
public void onEvent(Event evt) {
if (isEventForCurrentDocument(evt)) {
import com.google.common.collect.ImmutableMap;
import hu.user.lis.db.*;
+import hu.user.lis.service.data.EntityDocumentAction;
+import hu.user.lis.service.data.EntityDocumentService;
import hu.user.lis.ui.Constants;
import hu.user.lis.ui.converter.ProjectStatusConverter;
import hu.user.lis.ui.data.*;
import org.zkoss.zul.Panel;
import org.zkoss.zul.Window;
-import java.util.*;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
@Log4j2
public class ProjectEditorModel extends EntityEditorModel<Project> {
+ private final Map<String, List<EntityDocumentAction>> invoiceDocumentActions = new HashMap<>();
+ private final Map<String, List<EntityDocumentAction>> treasuryDocumentActions = new HashMap<>();
+
@Getter
@Setter
@WireVariable
AssociatesDataModel associatesDataModel;
-
@WireVariable
ProjectsDataModel projectsDataModel;
-
@WireVariable
private InvoiceDataModel invoiceDataModel;
-
@WireVariable
private TreasuryDataModel treasuryDataModel;
-
@Getter
@Setter
@WireVariable
private ServiceRecordsDataModel serviceRecordsDataModel;
-
@Getter
@Setter
@WireVariable
private ProjectStatusDataModel projectStatusDataModel;
-
@Getter
@Setter
@WireVariable
private IncomeMarginsDataModel incomeMarginsDataModel;
-
@WireVariable
private ProjectAssociatesDataModel projectAssociatesDataModel;
-
@Getter
@Setter
@WireVariable
private ProjectStatusConverter projectStatusConverter;
-
private Map<Long, Boolean> origAssociates;
-
@Getter
@Setter
private Map<Long, Boolean> formAssociates;
-
@Getter
@Setter
private IncomingInvoice selectedIncomingInvoice;
-
@Getter
@Setter
private OutgoingInvoice selectedOutgoingInvoice;
-
@Getter
@Setter
private Treasury selectedTreasury;
-
@Getter
private String partialAssociateName;
-
@WireVariable
private ProjectFormValidator projectFormValidator;
+ @WireVariable
+ private EntityDocumentService entityDocumentService;
+
@Override
public FormValidator<Project> getFormValidator() {
return projectFormValidator;
BindUtils.postNotifyChange(this, "formDocument");
}
- @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();
- }
-
public void saveProject(Component notif) {
boolean notify = Objects.isNull(getFormDocument().getId());
- projectsDataModel.save(getFormDocument());
+ Project project = projectsDataModel.save(getFormDocument());
+ project.getIncomingInvoices().forEach(this::updateInvoiceFileChanges);
+ project.getOutgoingInvoices().forEach(this::updateInvoiceFileChanges);
+ project.getTreasuries().forEach(this::updateTreasuryFileChanges);
if (notify) {
String msg = String.format("Sikeres projekt létrehozás %s azonosítóval.", getFormDocument().getHumanId());
Notification.show(msg, "info", notif, "after_start", 3000, true);
}
}
+ private void updateInvoiceFileChanges(Invoice invoice) {
+ List<EntityDocumentAction> actions = invoiceDocumentActions.get(invoice.getTechnicalId());
+ if (!actions.isEmpty()) {
+ entityDocumentService.executeActions(invoice.getId(), actions);
+ }
+ }
+
+ private void updateTreasuryFileChanges(Treasury treasury) {
+ List<EntityDocumentAction> actions = treasuryDocumentActions.get(treasury.getTechnicalId());
+ if (!actions.isEmpty()) {
+ entityDocumentService.executeActions(treasury.getId(), actions);
+ }
+ }
+
@Command
@Transactional
public void onEndEdit(@BindingParam("target") Window target, @BindingParam("save") boolean save, @BindingParam("notif") Component notif) {
@Command
public void onEditIncoming() {
IncomingInvoice entity = invoiceDataModel.clone(selectedIncomingInvoice);
- Editors.doEdit(Editors.INCOMING_INVOICE, entity, selectedIncomingInvoice, this::incomingModified);
+ Map<String, Object> extraArg = ImmutableMap.of("actions", invoiceDocumentActions.get(selectedIncomingInvoice.getTechnicalId()));
+ Editors.doEdit(Editors.INCOMING_INVOICE, entity, selectedIncomingInvoice, extraArg, this::incomingModified);
}
+
private void incomingAdded(SaveEntityEvent<IncomingInvoice> event) {
if (!event.isCanceled()) {
IncomingInvoice modifiedEntity = event.getData();
getFormDocument().getIncomingInvoices().add(modifiedEntity);
selectedIncomingInvoice = modifiedEntity;
+ invoiceDocumentActions.put(modifiedEntity.getTechnicalId(), event.withAttachment().getActions());
validate();
BindUtils.postNotifyChange(this, "selectedIncomingInvoice");
BindUtils.postNotifyChange(getFormDocument(), "incomingInvoices");
private void incomingModified(SaveEntityEvent<IncomingInvoice> event) {
if (!event.isCanceled()) {
- Set<IncomingInvoice> incomingInvoices = getFormDocument().getIncomingInvoices();
+ List<IncomingInvoice> incomingInvoices = getFormDocument().getIncomingInvoices();
incomingInvoices.remove(selectedIncomingInvoice);
IncomingInvoice modifiedEntity = event.getData();
incomingInvoices.add(modifiedEntity);
selectedIncomingInvoice = modifiedEntity;
+ invoiceDocumentActions.put(modifiedEntity.getTechnicalId(), event.withAttachment().getActions());
validate();
BindUtils.postNotifyChange(this, "selectedIncomingInvoice");
BindUtils.postNotifyChange(getFormDocument(), "incomingInvoices");
@Command
public void onRemoveIncoming() {
if (Objects.nonNull(selectedIncomingInvoice)) {
+ invoiceDocumentActions.remove(selectedIncomingInvoice.getTechnicalId());
getFormDocument().getIncomingInvoices().remove(selectedIncomingInvoice);
selectedIncomingInvoice = null;
validate();
@Command
public void onEditOutgoing() {
OutgoingInvoice entity = invoiceDataModel.clone(selectedOutgoingInvoice);
- Editors.doEdit(Editors.OUTGOING_INVOICE, entity, this::outgoingModified);
+ if (invoiceDocumentActions.containsKey(selectedOutgoingInvoice.getTechnicalId())) {
+ Map<String, Object> extraArg = ImmutableMap.of("actions", invoiceDocumentActions.get(selectedOutgoingInvoice.getTechnicalId()));
+ Editors.doEdit(Editors.OUTGOING_INVOICE, entity, selectedOutgoingInvoice, extraArg, this::outgoingModified);
+ } else {
+ Editors.doEdit(Editors.OUTGOING_INVOICE, entity, selectedOutgoingInvoice, this::outgoingModified);
+ }
}
private void outgoingAdded(SaveEntityEvent<OutgoingInvoice> event) {
OutgoingInvoice modifiedEntity = event.getData();
getFormDocument().getOutgoingInvoices().add(modifiedEntity);
selectedOutgoingInvoice = modifiedEntity;
+ invoiceDocumentActions.put(modifiedEntity.getTechnicalId(), event.withAttachment().getActions());
validate();
BindUtils.postNotifyChange(this, "selectedOutgoingInvoice");
BindUtils.postNotifyChange(getFormDocument(), "outgoingInvoices");
private void outgoingModified(SaveEntityEvent<OutgoingInvoice> event) {
if (!event.isCanceled()) {
OutgoingInvoice modifiedEntity = event.getData();
- Set<OutgoingInvoice> outgoingInvoices = getFormDocument().getOutgoingInvoices();
+ List<OutgoingInvoice> outgoingInvoices = getFormDocument().getOutgoingInvoices();
outgoingInvoices.remove(selectedOutgoingInvoice);
outgoingInvoices.add(modifiedEntity);
selectedOutgoingInvoice = modifiedEntity;
+ invoiceDocumentActions.put(modifiedEntity.getTechnicalId(), event.withAttachment().getActions());
validate();
BindUtils.postNotifyChange(this, "selectedOutgoingInvoice");
BindUtils.postNotifyChange(getFormDocument(), "outgoingInvoices");
@Command
public void onRemoveOutgoing() {
if (Objects.nonNull(selectedOutgoingInvoice)) {
+ invoiceDocumentActions.remove(selectedOutgoingInvoice.getTechnicalId());
getFormDocument().getOutgoingInvoices().remove(selectedOutgoingInvoice);
selectedOutgoingInvoice = null;
validate();
BindUtils.postNotifyChange(this, "selectedOutgoingInvoice");
- BindUtils.postNotifyChange(getFormDocument(), "outgoingInvoice");
+ BindUtils.postNotifyChange(getFormDocument(), "outgoingInvoices");
}
}
private void treasuryModified(SaveEntityEvent<Treasury> event) {
if (!event.isCanceled()) {
Treasury modifiedEntity = event.getData();
- Set<Treasury> treasuries = getFormDocument().getTreasuries();
+ List<Treasury> treasuries = getFormDocument().getTreasuries();
treasuries.remove(selectedTreasury);
treasuries.add(modifiedEntity);
selectedTreasury = modifiedEntity;
+ treasuryDocumentActions.put(modifiedEntity.getTechnicalId(), event.withAttachment().getActions());
validate();
BindUtils.postNotifyChange(this, "selectedTreasury");
BindUtils.postNotifyChange(getFormDocument(), "treasuries");
@Command
public void onRemoveTreasury() {
if (Objects.nonNull(selectedTreasury)) {
+ treasuryDocumentActions.remove(selectedTreasury.getTechnicalId());
getFormDocument().getTreasuries().remove(selectedTreasury);
selectedTreasury = null;
validate();
.anyMatch(e -> !e.getValue().equals(origAssociates.get(e.getKey())));
}
+ @Override
protected boolean areDifferent(Project entity) {
- return super.areDifferent(entity) || isAssociatesChanged();
+ return super.areDifferent(entity) || isAssociatesChanged() || !invoiceDocumentActions.isEmpty() || !treasuryDocumentActions.isEmpty();
}
@Command
import hu.user.lis.db.Project;
import hu.user.lis.db.ProjectAssociate;
import hu.user.lis.db.ServiceRecord;
+import hu.user.lis.service.data.EntityDocumentAction;
import hu.user.lis.ui.auth.CurrentProfile;
import hu.user.lis.ui.data.ProjectAssociatesDataModel;
import hu.user.lis.ui.editor.common.EntityAttachmentEditorModel;
@Override
public void init() {
super.init();
- getEntityDocumentDataModel().refresh(getFormDocument().getId(), ServiceRecord.class.getSimpleName());
}
@AfterCompose
if (isSaveEnabled()) {
Optional<ProjectAssociate> opProjectAssociate = projectAssociatesDataModel.searchByAssociateAndProject(getFormDocument().getAssociate().getId(),
getFormDocument().getProject().getId());
+
+
+ List<EntityDocumentAction> actions = getEntityDocumentDataModel().getActions();
if (opProjectAssociate.isPresent()) {
- Events.postEvent(new SaveEntityWithAttachmentEvent<>(getFormDocument(), getEntityDocumentDataModel(), target));
+ Events.postEvent(new SaveEntityWithAttachmentEvent<>(getFormDocument(), actions, target));
} else {
Messagebox.show("A munkatárs a kiválasztott projekt résztvevője lesz.", "Megerősítés",
Messagebox.OK | Messagebox.CANCEL, Messagebox.QUESTION, e -> {
if (!e.getName().equals("onCancel")) {
projectAssociatesDataModel.addProjectAssociate(getFormDocument().getProject(), getFormDocument().getAssociate());
- Events.postEvent(new SaveEntityWithAttachmentEvent<>(getFormDocument(), getEntityDocumentDataModel(), target));
+ Events.postEvent(new SaveEntityWithAttachmentEvent<>(getFormDocument(), actions, target));
}
});
}
package hu.user.lis.ui.editor;
import hu.user.lis.db.Treasury;
-import hu.user.lis.ui.editor.common.EntityEditorModel;
+import hu.user.lis.ui.editor.common.EntityAttachmentEditorModel;
import hu.user.lis.ui.editor.validator.FormValidator;
import hu.user.lis.ui.editor.validator.TreasuryFormValidator;
import lombok.extern.log4j.Log4j2;
-import org.zkoss.bind.BindContext;
-import org.zkoss.bind.BindUtils;
-import org.zkoss.bind.annotation.Command;
-import org.zkoss.bind.annotation.ContextParam;
-import org.zkoss.bind.annotation.ContextType;
import org.zkoss.bind.annotation.Init;
-import org.zkoss.zk.ui.event.UploadEvent;
import org.zkoss.zk.ui.select.annotation.WireVariable;
-import org.zkoss.zul.Messagebox;
@Log4j2
-public class TreasuryEditorModel extends EntityEditorModel<Treasury> {
+public class TreasuryEditorModel extends EntityAttachmentEditorModel<Treasury> {
@WireVariable
private TreasuryFormValidator treasuryFormValidator;
return treasuryFormValidator.validate(entity);
}
- @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;
- }
- getFormDocument().setFile(evt.getMedia().getByteData());
- BindUtils.postNotifyChange(getFormDocument(), "file");
- validate();
- }
-
- @Command
- public void onRemoveFile() {
- getFormDocument().setFile(null);
- BindUtils.postNotifyChange(getFormDocument(), "file");
- validate();
- }
}
import org.zkoss.zk.ui.Executions;
import org.zkoss.zul.Window;
+import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
public static final String TREASURY = "~./editor/treasury-editor.zul";
public static final String ASSOCIATE = "~./editor/associate-editor.zul";
public static final String PARTNER = "~./editor/partner-editor.zul";
- public static final String PROJECT_ATTACH = "~./editor/project-attach.zul";
+ public static final String PROJECT_ATTACH = "~./editor/project-executeActions.zul";
public static final String IMPORT_INVOICE_ASSIGN = "~./editor/import-invoice-assign-editor.zul";
public static final String IMPORT_INVOICE_APPROVE = "~./editor/import-invoice-approve-editor.zul";
public static final String PROJECT = "~./editor/project-editor.zul";
doShowEdit(page, arg, editCompleted);
}
+ public static <E> void doEdit(String page, E entity, E original, Map<String, Object> extraArg, EditCompletedListener<E> editCompleted) {
+ if (Objects.isNull(entity)) {
+ //header double click
+ return;
+ }
+ Map<String, Object> arg = new HashMap<>(extraArg);
+
+ arg.put("formDocument", entity);
+ if (Objects.nonNull(original)) {
+ arg.put("origDocument", original);
+ }
+ doShowEdit(page, arg, editCompleted);
+ }
+
public static <E> void doShowEdit(String page, Map<String, Object> arg, EditCompletedListener<E> editCompleted) {
Window editorWindow = (Window) Executions.createComponents(page, null, arg);
editorWindow.addEventListener("onClose", e -> {
package hu.user.lis.ui.editor.common;
import hu.user.lis.db.EDocument;
+import hu.user.lis.db.IdEntity;
+import hu.user.lis.service.data.EntityDocumentAction;
import hu.user.lis.ui.data.EntityDocumentDataModel;
+import hu.user.lis.ui.event.CancelEntityEditEvent;
+import hu.user.lis.ui.event.SaveEntityWithAttachmentEvent;
import lombok.Getter;
import lombok.extern.log4j.Log4j2;
import org.zkoss.bind.BindContext;
import org.zkoss.bind.BindUtils;
+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;
import org.zkoss.zk.ui.select.annotation.WireVariable;
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> {
- @Getter
@WireVariable
private EntityDocumentDataModel entityDocumentDataModel;
+ @Override
+ public void init() {
+ super.init();
+
+ List<EntityDocumentAction> actions = (List<EntityDocumentAction>) Executions.getCurrent().getArg().get("actions");
+ log.info(actions);
+
+ entityDocumentDataModel.refresh((IdEntity) getFormDocument(), getDocumentType(), actions);
+ }
+
+ @Override
protected boolean canSave(T entity) {
return true;
}
Messagebox.show("Csak PDF állomány feltöltése támogatott.", "Error", Messagebox.OK, Messagebox.ERROR);
return;
}
- String documentType = Strings.EMPTY;
- Type[] actualTypeArguments = ((ParameterizedType) getClass().getGenericSuperclass()).getActualTypeArguments();
- if (actualTypeArguments.length > 0) {
- documentType = ((Class<?>) actualTypeArguments[0]).getSimpleName();
- }
EDocument document = EDocument.builder()
- .documentType(documentType)
+ .documentType(getDocumentType())
.file(evt.getMedia().getByteData())
.size(evt.getMedia().getByteData().length)
.name(evt.getMedia().getName())
validate();
}
+ @Command
+ @Override
+ public void onCloseWindow(@BindingParam("target") Window target, @BindingParam("save") boolean save) {
+ if (save) {
+ if (saveEnabled) {
+ Events.postEvent(new SaveEntityWithAttachmentEvent<>(formDocument, entityDocumentDataModel.getActions(), target));
+ }
+ } else {
+ Events.postEvent(new CancelEntityEditEvent<>(target));
+ }
+ }
+
+ private String getDocumentType() {
+ String documentType = Strings.EMPTY;
+ Type[] actualTypeArguments = ((ParameterizedType) getClass().getGenericSuperclass()).getActualTypeArguments();
+ if (actualTypeArguments.length > 0) {
+ documentType = ((Class<?>) actualTypeArguments[0]).getSimpleName();
+ }
+ return documentType;
+ }
+
@Command
public void onRemoveFile() {
entityDocumentDataModel.remove();
eventBus.registerForBinding(this);
origDocument = (T) Executions.getCurrent().getArg().get("origDocument");
formDocument = (T) Executions.getCurrent().getArg().get("formDocument");
- validate(formDocument);
+ if (Objects.nonNull(formDocument)) {
+ //special pages like ProjectEditorModel validates later
+ validate(formDocument);
+ }
}
@Override
protected FieldValidation[] getValidators(Invoice entity) {
FieldValidation[] validators = new FieldValidation[]{
validator(entity.getProject(), this::validateNotNull, "A 'Projekt' kitöltése kötelező."),
- validator(entity.getFile(), this::validateNotNull, "A 'Számlakép' feltöltése kötelező.")
+ //validator(entity.getFile(), this::validateNotNull, "A 'Számlakép' feltöltése kötelező.")
};
return ArrayUtils.addAll(super.getValidators(entity), validators);
}
protected FieldValidation[] getValidators(Invoice entity) {
FieldValidation[] validators = new FieldValidation[]{
validator(entity.getProject(), this::validateNotNull, "A 'Projekt' kitöltése kötelező."),
- validator(entity.getFile(), this::validateNotNull, "A 'Számlakép' feltöltése kötelező.")
+ //validator(entity.getFile(), this::validateNotNull, "A 'Számlakép' feltöltése kötelező.")
};
return ArrayUtils.addAll(super.getValidators(entity), validators);
}
package hu.user.lis.ui.event;
-import hu.user.lis.ui.data.EntityDocumentDataModel;
+import hu.user.lis.service.data.EntityDocumentAction;
import lombok.Getter;
import org.zkoss.zul.Window;
+import java.util.List;
+
@Getter
public class SaveEntityWithAttachmentEvent<T> extends SaveEntityEvent<T> {
- private final EntityDocumentDataModel entityDocumentDataModel;
+ private final List<EntityDocumentAction> actions;
- public SaveEntityWithAttachmentEvent(T data, EntityDocumentDataModel entityDocumentDataModel, Window target) {
+ public SaveEntityWithAttachmentEvent(T data, List<EntityDocumentAction> actions, Window target) {
super(data, target);
- this.entityDocumentDataModel = entityDocumentDataModel;
+ this.actions = actions;
}
}
private String searchPhrase;
private String page;
private final Map<String, SpecialRoute> specialRoutes = ImmutableMap.of(
- Constants.NAV_PROJECTS, this::showProjectEditor,
+ Constants.NAV_PROJECT, this::showProjectEditor,
Constants.NAV_INVOICE_PAYMENT, this::showInvoicePayment
);
private String importInvoiceMenuClassName;
String[] pathTokens = path.split("/");
if (pathTokens.length > 2) {
Long id = Long.parseLong(pathTokens[2]);
- specialRoutes.get(path).route(id);
+ specialRoutes.get("/" + pathTokens[1]).route(id);
} else {
setPage("~." + path + ".zul");
}
import hu.user.lis.db.Associate;
import hu.user.lis.db.Project;
import hu.user.lis.db.ServiceRecord;
+import hu.user.lis.service.data.EntityDocumentAction;
+import hu.user.lis.service.data.EntityDocumentService;
import hu.user.lis.ui.Constants;
-import hu.user.lis.ui.data.EntityDocumentDataModel;
import hu.user.lis.ui.data.ServiceRecordsDataModel;
import hu.user.lis.ui.data.common.CachedSpringDataModel;
import hu.user.lis.ui.editor.common.Editors;
import org.zkoss.zk.ui.select.annotation.WireVariable;
import org.zkoss.zkplus.spring.DelegatingVariableResolver;
+import java.util.List;
import java.util.Map;
import java.util.Objects;
@WireVariable
EntitySelectorRouter entitySelectorRouter;
+ @WireVariable
+ private EntityDocumentService entityDocumentService;
+
+ @WireVariable
+ private EventBus eventBus;
+
@Getter
private Project filterProject;
@Getter
private Associate filterAssociate;
- @WireVariable
- private EventBus eventBus;
@Override
protected CachedSpringDataModel<ServiceRecord> getDataModel() {
public void saveServiceRecord(SaveEntityEvent<ServiceRecord> event) {
if (!event.isCanceled()) {
ServiceRecord modifiedEntity = event.getData();
+ List<EntityDocumentAction> actions = event.withAttachment().getActions();
+ modifiedEntity.setSigned(!actions.isEmpty());
serviceRecordsDataModel.save(modifiedEntity);
- EntityDocumentDataModel entityDocumentDataModel = event.withAttachment().getEntityDocumentDataModel();
- entityDocumentDataModel.save(modifiedEntity.getId());
+ entityDocumentService.executeActions(modifiedEntity.getId(), actions);
refresh();
serviceRecordsDataModel.addToSelection(modifiedEntity);
}
onOpen="@command('onOpenFormPanel', parentPanel=centerPanel)">
<caption label="Résztvevők" style="cursor: pointer"
onClick="@command('onClickFormPanel', parentPanel=centerPanel, panel=self.parent)"/>
- <!-- <north flex="true">-->
- <!-- <toolbar>-->
- <!-- <textbox instant="true" value="@bind(vm.partialAssociateName)"/>-->
- <!-- <toolbarbutton iconSclass="z-icon-remove"-->
- <!-- onClick="@command('onResetAssociateFilter')"/>-->
- <!-- </toolbar>-->
- <!-- </north>-->
<panelchildren>
<listbox model="@load(vm.associatesDataModel)"
multiple="false">
</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')" disabled="@bind(vm.readonlyForm)"/>
- <toolbarbutton label="Törlés" iconSclass="z-icon-remove"
- onClick="@command('onRemoveFile')"
- disabled="@load(empty vm.formDocument.file or vm.readonlyForm)"/>
- </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>
<label value="@load(each.workHours)"/>
</listcell>
<listcell>
- <a iconSclass="z-icon-check" visible="@load(not empty each.file)"/>
- <a iconSclass="z-icon-ban" visible="@load(empty each.file)"/>
+ <a iconSclass="z-icon-check" visible="@load(each.signed)"/>
+ <a iconSclass="z-icon-ban" visible="@load(not each.signed)"/>
</listcell>
</listitem>
</template>