From: Vásáry Dániel Date: Wed, 15 Nov 2023 10:59:35 +0000 (+0100) Subject: Invoice import modification X-Git-Url: http://git.useribm.hu/?a=commitdiff_plain;h=bcfe1ec4e0cb32fb118288c7ba6edcae9060b6f3;p=sly-crm.git Invoice import modification --- diff --git a/lis-app/src/test/java/hu/user/lis/RepositoryIT.java b/lis-app/src/test/java/hu/user/lis/RepositoryIT.java index b00e823..6475371 100644 --- a/lis-app/src/test/java/hu/user/lis/RepositoryIT.java +++ b/lis-app/src/test/java/hu/user/lis/RepositoryIT.java @@ -6,9 +6,7 @@ package hu.user.lis; import hu.user.lis.db.*; -import hu.user.lis.db.repository.ProjectRepository; -import hu.user.lis.db.repository.ServiceRecordRepository; -import hu.user.lis.db.repository.TreasuryRepository; +import hu.user.lis.db.repository.*; import hu.user.lis.service.data.ProjectService; import hu.user.lis.service.data.TreasuryService; import lombok.extern.log4j.Log4j2; @@ -22,9 +20,11 @@ import org.springframework.test.context.TestPropertySource; import org.springframework.test.context.junit4.SpringRunner; import javax.persistence.EntityNotFoundException; +import java.util.Arrays; import java.util.List; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; @Log4j2 @@ -47,6 +47,12 @@ public class RepositoryIT { @Autowired private TreasuryRepository treasuryRepository; + @Autowired + private InvoiceImportRepository invoiceImportRepository; + + @Autowired + private InvoiceRepository invoiceRepository; + @Test public void testRepositoryCapabilities() { List allItems = serviceRecordRepository.findAll(); @@ -102,4 +108,24 @@ public class RepositoryIT { projectRepository.deleteAll(); } + + @Test + public void createImportInvoice() { + List invoices = invoiceRepository.findAll(); + + Invoice invoice = invoices.get(0); + + InvoiceImport invoiceImport = InvoiceImport.builder() + .invoice(invoice) + .suggestedProjects(Arrays.asList("X1", "X2")) + .build(); + + invoiceImportRepository.saveAndFlush(invoiceImport); + + assertNotNull(invoiceImport.getImported()); + assertEquals("X1", invoiceImport.getSuggestedProjects().get(0)); + assertEquals("X2", invoiceImport.getSuggestedProjects().get(1)); + invoiceImportRepository.delete(invoiceImport); + + } } diff --git a/lis-db/migrations/environments/prod.properties b/lis-db/migrations/environments/prod.properties index c5d02a9..77fc048 100644 --- a/lis-db/migrations/environments/prod.properties +++ b/lis-db/migrations/environments/prod.properties @@ -4,9 +4,9 @@ time_zone=GMT+0:00 script_char_set=UTF-8 ## JDBC connection properties. driver=com.ibm.db2.jcc.DB2Driver -url=jdbc:db2://dvdev.in.useribm.hu:50000/lis +url=jdbc:db2://db2.in.useribm.hu:50000/slycrm username=db2admin -password=password +password=Passw@rd01 # # A NOTE ON STORED PROCEDURES AND DELIMITERS # diff --git a/lis-db/migrations/environments/test.properties b/lis-db/migrations/environments/test.properties new file mode 100644 index 0000000..c5d02a9 --- /dev/null +++ b/lis-db/migrations/environments/test.properties @@ -0,0 +1,57 @@ +## Base time zone to ensure times are consistent across machines +time_zone=GMT+0:00 +## The character set that scripts are encoded with +script_char_set=UTF-8 +## JDBC connection properties. +driver=com.ibm.db2.jcc.DB2Driver +url=jdbc:db2://dvdev.in.useribm.hu:50000/lis +username=db2admin +password=password +# +# A NOTE ON STORED PROCEDURES AND DELIMITERS +# +# Stored procedures and functions commonly have nested delimiters +# that conflict with the schema migration parsing. If you tend +# to use procs, functions, triggers or anything that could create +# this situation, then you may want to experiment with +# send_full_script=true (preferred), or if you can't use +# send_full_script, then you may have to resort to a full +# line delimiter such as "GO" or "/" or "!RUN!". +# +# Also play with the autocommit settings, as some drivers +# or databases don't support creating procs, functions or +# even tables in a transaction, and others require it. +# +# This ignores the line delimiters and +# simply sends the entire script at once. +# Use with JDBC drivers that can accept large +# blocks of delimited text at once. +send_full_script=false +# This controls how statements are delimited. +# By default statements are delimited by an +# end of line semicolon. Some databases may +# (e.g. MS SQL Server) may require a full line +# delimiter such as GO. +# These are ignored if send_full_script is true. +delimiter=; +full_line_delimiter=false +# If set to true, each statement is isolated +# in its own transaction. Otherwise the entire +# script is executed in one transaction. +# Few databases should need this set to true, +# but some do. +auto_commit=false +# If set to false, warnings from the database will interrupt migrations. +ignore_warnings=true +# Custom driver path to allow you to centralize your driver files +# Default requires the drivers to be in the drivers directory of your +# initialized migration directory (created with "migrate init") +# driver_path= +# Name of the table that tracks changes to the database +changelog=CHANGELOG +# Migrations support variable substitutions in the form of ${variable} +# in the migration scripts. All of the above properties will be ignored though, +# with the exception of changelog. +# Example: The following would be referenced in a migration file as ${ip_address} +# ip_address=192.168.0.1 + diff --git a/lis-db/migrations/scripts/012_add_created_by_import_to_partner.sql b/lis-db/migrations/scripts/012_add_created_by_import_to_partner.sql new file mode 100644 index 0000000..8603565 --- /dev/null +++ b/lis-db/migrations/scripts/012_add_created_by_import_to_partner.sql @@ -0,0 +1,9 @@ +-- // add created_by_import to partner +-- Migration SQL that makes the change goes here. + +ALTER TABLE partner ADD COLUMN created_by_import SMALLINT NOT NULL DEFAULT 0; + +-- //@UNDO +-- SQL to undo the change goes here. + +ALTER TABLE partner DROP COLUMN created_by_import; diff --git a/lis-db/migrations/scripts/013_create_incvoice_import.sql b/lis-db/migrations/scripts/013_create_incvoice_import.sql new file mode 100644 index 0000000..80f3438 --- /dev/null +++ b/lis-db/migrations/scripts/013_create_incvoice_import.sql @@ -0,0 +1,16 @@ +-- // create invoice import +-- Migration SQL that makes the change goes here. + +CREATE TABLE invoice_import ( + id BIGINT NOT NULL GENERATED BY DEFAULT AS IDENTITY, + invoice_id BIGINT, + imported TIMESTAMP NOT NULL, + suggested_projects VARCHAR(200), + CONSTRAINT pk_invoice_import PRIMARY KEY (id) +); +ALTER TABLE invoice_import ADD CONSTRAINT FK_INVOICE_IMPORT_ON_INVOICE FOREIGN KEY (invoice_id) REFERENCES invoice (id); + +-- //@UNDO +-- SQL to undo the change goes here. + +DROP TABLE invoice_import; diff --git a/lis-db/pom.xml b/lis-db/pom.xml index ea1d6f8..c94753f 100644 --- a/lis-db/pom.xml +++ b/lis-db/pom.xml @@ -44,10 +44,10 @@ com.fasterxml.jackson.core jackson-annotations - - org.hibernate - hibernate-core - 5.6.15.Final - + + + + + \ No newline at end of file diff --git a/lis-db/src/main/java/hu/user/lis/db/InvoiceImport.java b/lis-db/src/main/java/hu/user/lis/db/InvoiceImport.java new file mode 100644 index 0000000..07ef118 --- /dev/null +++ b/lis-db/src/main/java/hu/user/lis/db/InvoiceImport.java @@ -0,0 +1,37 @@ +package hu.user.lis.db; + +import com.fasterxml.jackson.annotation.JsonIncludeProperties; +import hu.user.lis.db.converter.StringListConverter; +import lombok.*; +import org.hibernate.annotations.CreationTimestamp; + +import javax.persistence.*; +import java.io.Serializable; +import java.util.Date; +import java.util.List; + +@Getter +@Setter +@Entity +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class InvoiceImport implements Serializable { + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + @ManyToOne + @JoinColumn(name = "invoice_id") + @JsonIncludeProperties({"id"}) + private Invoice invoice; + + @GeneratedValue(strategy = GenerationType.AUTO) + @Column(updatable = false) + @CreationTimestamp + private Date imported; + + @Convert(converter = StringListConverter.class) + private List suggestedProjects; + +} diff --git a/lis-db/src/main/java/hu/user/lis/db/Partner.java b/lis-db/src/main/java/hu/user/lis/db/Partner.java index 7bce08c..88e330e 100644 --- a/lis-db/src/main/java/hu/user/lis/db/Partner.java +++ b/lis-db/src/main/java/hu/user/lis/db/Partner.java @@ -15,9 +15,15 @@ public class Partner implements Serializable { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) Long id; + String name; + @Column(unique = true) String vatNr; + String address; + boolean active; + + boolean createdByImport; } diff --git a/lis-db/src/main/java/hu/user/lis/db/converter/StringListConverter.java b/lis-db/src/main/java/hu/user/lis/db/converter/StringListConverter.java new file mode 100644 index 0000000..8c12157 --- /dev/null +++ b/lis-db/src/main/java/hu/user/lis/db/converter/StringListConverter.java @@ -0,0 +1,23 @@ +package hu.user.lis.db.converter; + +import javax.persistence.AttributeConverter; +import javax.persistence.Converter; +import java.util.Arrays; +import java.util.List; + +import static java.util.Collections.emptyList; + +@Converter +public class StringListConverter implements AttributeConverter, String> { + private static final String SPLIT_CHAR = ","; + + @Override + public String convertToDatabaseColumn(List stringList) { + return stringList != null ? String.join(SPLIT_CHAR, stringList) : ""; + } + + @Override + public List convertToEntityAttribute(String string) { + return string != null ? Arrays.asList(string.split(SPLIT_CHAR)) : emptyList(); + } +} \ No newline at end of file diff --git a/lis-db/src/main/java/hu/user/lis/db/repository/InvoiceImportRepository.java b/lis-db/src/main/java/hu/user/lis/db/repository/InvoiceImportRepository.java new file mode 100644 index 0000000..7b4c222 --- /dev/null +++ b/lis-db/src/main/java/hu/user/lis/db/repository/InvoiceImportRepository.java @@ -0,0 +1,8 @@ +package hu.user.lis.db.repository; + +import hu.user.lis.db.InvoiceImport; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface InvoiceImportRepository extends JpaRepository { + +} diff --git a/lis-workflow/src/main/java/hu/user/lis/workflow/invoice/DownloadInvoiceData.java b/lis-workflow/src/main/java/hu/user/lis/workflow/invoice/DownloadInvoiceData.java index e453367..4fc1ae5 100644 --- a/lis-workflow/src/main/java/hu/user/lis/workflow/invoice/DownloadInvoiceData.java +++ b/lis-workflow/src/main/java/hu/user/lis/workflow/invoice/DownloadInvoiceData.java @@ -1,7 +1,10 @@ package hu.user.lis.workflow.invoice; import hu.user.lis.db.IncomingInvoice; +import hu.user.lis.db.InvoiceImport; import hu.user.lis.db.Partner; +import hu.user.lis.db.repository.InvoiceImportRepository; +import hu.user.lis.db.repository.InvoiceRepository; import hu.user.lis.db.repository.PartnerRepository; import hu.user.lis.workflow.invoice.service.IncomingInvoiceFetcherService; import lombok.extern.log4j.Log4j2; @@ -17,6 +20,10 @@ import java.util.Optional; @Log4j2 @Component public class DownloadInvoiceData implements JavaDelegate { + @Autowired + private InvoiceImportRepository invoiceImportRepository; + @Autowired + private InvoiceRepository invoiceRepository; @Autowired private PartnerRepository partnerRepository; @@ -42,9 +49,18 @@ public class DownloadInvoiceData implements JavaDelegate { List projectSuggestions = new ArrayList<>(); IncomingInvoice invoice = incomingInvoiceFetcherService.getInvoiceDataOnline(invoiceXml, projectSuggestions); Optional partnerEntity = partnerRepository.findByVatNr(invoice.getPartner().getVatNr()); - partnerEntity.ifPresent(invoice::setPartner); - delegateExecution.setVariableLocal("invoiceEntity", invoice); - delegateExecution.setVariableLocal("projectSuggestions", projectSuggestions); - log.info("Invoice {} processed", invoiceXml); + if (partnerEntity.isPresent()) { + invoice.setPartner(partnerEntity.get()); + } else { + invoice.getPartner().setCreatedByImport(true); + partnerRepository.save(invoice.getPartner()); + } + invoiceRepository.save(invoice); + InvoiceImport invoiceImport = InvoiceImport.builder() + .invoice(invoice) + .suggestedProjects(projectSuggestions) + .build(); + invoiceImportRepository.save(invoiceImport); + log.info("Invoice {} {} processed", invoice.getHumanId(), invoice.getPartner().getName()); } } diff --git a/lis-workflow/src/main/java/hu/user/lis/workflow/invoice/ListNewInvoices.java b/lis-workflow/src/main/java/hu/user/lis/workflow/invoice/ListNewInvoices.java index 84b8ce6..286bd71 100644 --- a/lis-workflow/src/main/java/hu/user/lis/workflow/invoice/ListNewInvoices.java +++ b/lis-workflow/src/main/java/hu/user/lis/workflow/invoice/ListNewInvoices.java @@ -30,6 +30,8 @@ public class ListNewInvoices implements JavaDelegate { @Override public void execute(DelegateExecution delegateExecution) throws Exception { log.info("Executing"); + + //TODO TaxOfficeRequestBuilder params() List invoices = incomingInvoiceFetcherService.getNewInvoicesOnline(); delegateExecution.setVariableLocal("invoices", invoices); } diff --git a/lis-workflow/src/main/resources/assign-incoming-invoices.bpmn b/lis-workflow/src/main/resources/assign-incoming-invoices.bpmn new file mode 100644 index 0000000..e25b7f5 --- /dev/null +++ b/lis-workflow/src/main/resources/assign-incoming-invoices.bpmn @@ -0,0 +1,76 @@ + + + + + Flow_1ubjpz9 + + + Flow_0uvj71q + + + + Flow_0efz1ox + Flow_1ubjpz9 + Flow_0c887e2 + + + Flow_0c887e2 + Flow_00r2v71 + + + Flow_00r2v71 + Flow_0uvj71q + Flow_0efz1ox + + + + + ${not approved} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/lis-workflow/src/main/resources/import-incoming-invoices.bpmn b/lis-workflow/src/main/resources/import-incoming-invoices.bpmn index c33b482..ad2f47e 100644 --- a/lis-workflow/src/main/resources/import-incoming-invoices.bpmn +++ b/lis-workflow/src/main/resources/import-incoming-invoices.bpmn @@ -10,7 +10,7 @@ Flow_1gzempz Flow_0y5cjps - + Flow_0y5cjps Flow_0vgb0nw @@ -18,42 +18,21 @@ Flow_1ubjpz9 - Flow_0uvj71q + Flow_0e62ocl - - - - Flow_14m4iht - Flow_0efz1ox - Flow_0c887e2 - - - - Flow_0c887e2 - Flow_00r2v71 - Flow_1ubjpz9 - Flow_14m4iht + Flow_0e62ocl - - - Flow_00r2v71 - Flow_0uvj71q - Flow_0efz1ox - - - - ${not approved} - + Flow_0vgb0nw - - + + @@ -64,65 +43,36 @@ - + - - + + - - - - - + - - - + + - - - - - - - + - - - - - - - - - - + + - - - - - - - - - - - - - + + + - - + +