From: elgekko Date: Tue, 19 Sep 2023 08:04:54 +0000 (+0200) Subject: Invoice import modified with existing partner lookup X-Git-Url: http://git.useribm.hu/?a=commitdiff_plain;h=d1c0411a67f463b5fd91d636b379e009e3c880dc;p=sly-crm.git Invoice import modified with existing partner lookup --- diff --git a/lis-app/src/main/resources/logback-spring.xml b/lis-app/src/main/resources/logback-spring.xml index cf0a9f0..99f82ff 100644 --- a/lis-app/src/main/resources/logback-spring.xml +++ b/lis-app/src/main/resources/logback-spring.xml @@ -34,13 +34,13 @@ - + - + diff --git a/lis-db/migrations/scripts/003_add_remotely_authenticated_to_associate.sql b/lis-db/migrations/scripts/003_add_remotely_authenticated_to_associate.sql index bd50d37..cb8b83f 100644 --- a/lis-db/migrations/scripts/003_add_remotely_authenticated_to_associate.sql +++ b/lis-db/migrations/scripts/003_add_remotely_authenticated_to_associate.sql @@ -1,12 +1,10 @@ -- // add_remotely_authenticated_to_associate -- Migration SQL that makes the change goes here. -ALTER TABLE associate - ADD COLUMN remotely_authenticated SMALLINT NOT NULL DEFAULT 0; +ALTER TABLE ASSOCIATE ADD COLUMN remotely_authenticated SMALLINT NOT NULL DEFAULT 0; -- //@UNDO -- SQL to undo the change goes here. -ALTER TABLE associate - DROP COLUMN remotely_authenticated; +ALTER TABLE ASSOCIATE DROP COLUMN remotely_authenticated; diff --git a/lis-db/migrations/scripts/004_create_test_data.sql b/lis-db/migrations/scripts/004_create_test_data.sql index 0da1d67..ba552bc 100644 --- a/lis-db/migrations/scripts/004_create_test_data.sql +++ b/lis-db/migrations/scripts/004_create_test_data.sql @@ -7,19 +7,19 @@ VALUES ('Test User', 'user', 'password', 1, 1); INSERT INTO PARTNER - (ID, NAME, VAT_NR, ACTIVE) + (id, name, vat_nr, active) VALUES (1, 'NYÍRŐ', '00000000-00-0', 1), (2, 'KOLOS', '00000000-00-0', 1); INSERT INTO PROJECT_STATUS - (ID, NAME, ACTIVE, "ORDER") + (id, name, active, "ORDER") VALUES (1, 'START', 1, 1); INSERT INTO PROJECT - (ID, PROJECT_STATUS_ID, NAME, HUMAN_ID, CONTACT_NAME, PARTNER_ID, ACTIVE) + (id, project_status_id, name, human_id, contact_name, partner_id, active) VALUES (1, 1, 'Halászat', '2023-0001', 'Kovács', 1, 1); diff --git a/lis-db/migrations/scripts/005_create_profile.sql b/lis-db/migrations/scripts/005_create_profile.sql index cfc8ed2..d89efa8 100644 --- a/lis-db/migrations/scripts/005_create_profile.sql +++ b/lis-db/migrations/scripts/005_create_profile.sql @@ -1,16 +1,16 @@ -- // create profile -- Migration SQL that makes the change goes here. -CREATE TABLE profile ( +CREATE TABLE PROFILE ( id BIGINT NOT NULL GENERATED BY DEFAULT AS IDENTITY, login VARCHAR(255), type VARCHAR(255), setting CLOB, CONSTRAINT pk_profile PRIMARY KEY (id) ); -CREATE UNIQUE INDEX UDX_PROFILE_LOGIN_TYPE ON PROFILE(LOGIN, TYPE); +CREATE UNIQUE INDEX UDX_PROFILE_LOGIN_TYPE ON PROFILE(login, type); -- //@UNDO -- SQL to undo the change goes here. -DROP TABLE profile; +DROP TABLE PROFILE; diff --git a/lis-db/migrations/scripts/008_add_unique_index_to_partner_vatnr.sql b/lis-db/migrations/scripts/008_add_unique_index_to_partner_vatnr.sql new file mode 100644 index 0000000..161472c --- /dev/null +++ b/lis-db/migrations/scripts/008_add_unique_index_to_partner_vatnr.sql @@ -0,0 +1,9 @@ +-- // add unique index to partner vatnr +-- Migration SQL that makes the change goes here. + +CREATE UNIQUE INDEX UX_PARTNER_VAT_NR ON PARTNER(vat_nr); + +-- //@UNDO +-- SQL to undo the change goes here. + +DROP INDEX UX_PARTNER_VAT_NR; diff --git a/lis-db/migrations/scripts/009_add_partner_for_invoice_import_test.sql b/lis-db/migrations/scripts/009_add_partner_for_invoice_import_test.sql new file mode 100644 index 0000000..b9e0435 --- /dev/null +++ b/lis-db/migrations/scripts/009_add_partner_for_invoice_import_test.sql @@ -0,0 +1,10 @@ +-- // add partner for invoice import test +-- Migration SQL that makes the change goes here. + +INSERT INTO PARTNER(name, vat_nr, address, active) +VALUES('Értékesítő Kft', '99999999-2-41', '1234 Budapest, Hármas utca 1', 1); + +-- //@UNDO +-- SQL to undo the change goes here. + +DELETE FROM PARTNER WHERE name = 'Értékesítő Kft'; 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 4e3e5dc..7bce08c 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 @@ -2,10 +2,7 @@ package hu.user.lis.db; import lombok.*; -import javax.persistence.Entity; -import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; -import javax.persistence.Id; +import javax.persistence.*; import java.io.Serializable; @Getter @@ -19,6 +16,7 @@ public class Partner implements Serializable { @GeneratedValue(strategy = GenerationType.IDENTITY) Long id; String name; + @Column(unique = true) String vatNr; String address; boolean active; diff --git a/lis-db/src/main/java/hu/user/lis/db/repository/PartnerRepository.java b/lis-db/src/main/java/hu/user/lis/db/repository/PartnerRepository.java index 9104831..daabdb6 100644 --- a/lis-db/src/main/java/hu/user/lis/db/repository/PartnerRepository.java +++ b/lis-db/src/main/java/hu/user/lis/db/repository/PartnerRepository.java @@ -3,5 +3,10 @@ package hu.user.lis.db.repository; import hu.user.lis.db.Partner; import org.springframework.data.jpa.repository.JpaRepository; +import java.util.Optional; + public interface PartnerRepository extends JpaRepository, PartnerRepositorySearch { + + Optional findByVatNr(String vatNr); + } diff --git a/lis-db/src/main/java/hu/user/lis/db/repository/PartnerRepositorySearch.java b/lis-db/src/main/java/hu/user/lis/db/repository/PartnerRepositorySearch.java index 9e07be7..b7dc072 100644 --- a/lis-db/src/main/java/hu/user/lis/db/repository/PartnerRepositorySearch.java +++ b/lis-db/src/main/java/hu/user/lis/db/repository/PartnerRepositorySearch.java @@ -8,5 +8,5 @@ import java.util.List; public interface PartnerRepositorySearch { List search(String partialSearch, boolean filterShowActive, boolean filterShowInActive, Pageable pageable); - long count(String ppartialSearch, boolean filterShowActive, boolean filterShowInActive); + long count(String partialSearch, boolean filterShowActive, boolean filterShowInActive); } diff --git a/lis-ui/src/main/java/hu/user/lis/ui/event/EventBus.java b/lis-ui/src/main/java/hu/user/lis/ui/event/EventBus.java index f8cbc29..27fac65 100644 --- a/lis-ui/src/main/java/hu/user/lis/ui/event/EventBus.java +++ b/lis-ui/src/main/java/hu/user/lis/ui/event/EventBus.java @@ -29,25 +29,27 @@ public class EventBus { return EventQueues.lookup(Constants.BINDING_QUEUE, EventQueues.DESKTOP, true); } - public void register(EventListener listener) { + public void register(EventListener listener) { getQueue().subscribe(listener); } - public void registerForBinding(EventListener listener) { + public void registerForBinding(EventListener listener) { getBindingQueue().subscribe(listener); } - public void registerForProcessEvent(EventListener listener) { + public void registerForProcessEvent(EventListener listener) { getProcessEventQueue().subscribe(listener); } - public void unregister(EventListener listener) { + public void unregister(EventListener listener) { try { getQueue().unsubscribe(listener); getBindingQueue().unsubscribe(listener); - getProcessEventQueue().unsubscribe(listener); - } catch (Exception e) { -// log.warn("Not necessary to unregister"); + EventQueue processEventQueue = getProcessEventQueue(); + if (Objects.nonNull(processEventQueue)) { + processEventQueue.unsubscribe(listener); + } + } catch (Exception ignored) { } } 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 88bedc0..3a52917 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,8 @@ package hu.user.lis.workflow.invoice; import hu.user.lis.db.IncomingInvoice; -import hu.user.lis.db.repository.InvoiceRepository; +import hu.user.lis.db.Partner; +import hu.user.lis.db.repository.PartnerRepository; import hu.user.lis.workflow.invoice.service.IncomingInvoiceFetcherService; import lombok.extern.log4j.Log4j2; import org.camunda.bpm.engine.delegate.DelegateExecution; @@ -10,22 +11,25 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import java.nio.file.Paths; +import java.util.Optional; @Log4j2 @Component public class DownloadInvoiceData implements JavaDelegate { + @Autowired - InvoiceRepository invoiceRepository; + PartnerRepository partnerRepository; @Autowired IncomingInvoiceFetcherService incomingInvoiceFetcherService; - @Override public void execute(DelegateExecution delegateExecution) throws Exception { String invoiceId = (String) delegateExecution.getVariable("invoice"); log.info("Processing invoice {}", invoiceId); IncomingInvoice invoice = incomingInvoiceFetcherService.getInvoiceFromPath(Paths.get(invoiceId)); + Optional partnerEntity = partnerRepository.findByVatNr(invoice.getPartner().getVatNr()); + partnerEntity.ifPresent(invoice::setPartner); delegateExecution.setVariableLocal("invoiceEntity", invoice); log.info("Invoice {} processed", invoiceId); }