import bank-accounts + sepa-mandates

This commit is contained in:
Michael Hoennig 2022-10-29 18:18:19 +02:00
parent fa5fb30117
commit d44d2e3e82
2 changed files with 59 additions and 4 deletions

View File

@ -5,6 +5,7 @@ import com.opencsv.CSVReader;
import com.opencsv.CSVReaderBuilder;
import net.hostsharing.hsadminng.context.Context;
import net.hostsharing.hsadminng.context.ContextBasedTest;
import net.hostsharing.hsadminng.hs.office.bankaccount.HsOfficeBankAccountEntity;
import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactEntity;
import net.hostsharing.hsadminng.hs.office.debitor.HsOfficeDebitorEntity;
import net.hostsharing.hsadminng.hs.office.membership.HsOfficeMembershipEntity;
@ -13,8 +14,12 @@ import net.hostsharing.hsadminng.hs.office.partner.HsOfficePartnerDetailsEntity;
import net.hostsharing.hsadminng.hs.office.partner.HsOfficePartnerEntity;
import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonEntity;
import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonType;
import net.hostsharing.hsadminng.hs.office.sepamandate.HsOfficeSepaMandateEntity;
import net.hostsharing.test.JpaAttempt;
import org.junit.jupiter.api.*;
import org.junit.jupiter.api.MethodOrderer;
import org.junit.jupiter.api.Order;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestMethodOrder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;
import org.springframework.boot.test.mock.mockito.MockBean;
@ -48,6 +53,8 @@ public class ImportBusinessPartners extends ContextBasedTest {
private static Map<Integer, HsOfficePartnerEntity> partners = new HashMap<>();
private static Map<Integer, HsOfficeDebitorEntity> debitors = new HashMap<>();
private static Map<Integer, HsOfficeMembershipEntity> memberships = new HashMap<>();
private static Map<Integer, HsOfficeSepaMandateEntity> sepaMandates = new HashMap<>();
private static Map<Integer, HsOfficeBankAccountEntity> bankAccounts = new HashMap<>();
@PersistenceContext
EntityManager em;
@ -82,10 +89,22 @@ public class ImportBusinessPartners extends ContextBasedTest {
}
}
@Test
@Order(3)
void importSepaMandates() {
try (Reader reader = resourceReader("migration/sepa-mandates.csv")) {
final var records = readAllLines(reader);
importSepaMandates(records);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
@Test
@Order(10)
void persistEntities() {
jpaAttempt.transacted( () -> {
jpaAttempt.transacted(() -> {
context("superuser-alex@hostsharing.net"); // TODO: use real user
contacts.forEach((id, contact) -> em.persist(contact));
@ -93,6 +112,8 @@ public class ImportBusinessPartners extends ContextBasedTest {
partners.forEach((id, partner) -> em.persist(partner));
debitors.forEach((id, debitor) -> em.persist(debitor));
memberships.forEach((id, membership) -> em.persist(membership));
bankAccounts.forEach((id, account) -> em.persist(account));
sepaMandates.forEach((id, mandate) -> em.persist(mandate));
}).assertSuccessful();
}
@ -158,12 +179,39 @@ public class ImportBusinessPartners extends ContextBasedTest {
});
}
private void importSepaMandates(final List<String[]> records) {
records.stream()
.map(this::trimAll)
.forEach(record -> {
final var debitor = debitors.get(toInt(record[1]));
final var sepaMandate = HsOfficeSepaMandateEntity.builder()
.debitor(debitor)
.bankAccount(HsOfficeBankAccountEntity.builder()
.holder(record[2])
// .bankName(record[3]) // TODO
.iban(record[4])
.bic(record[5])
.build())
.reference(record[6])
.agreement(LocalDate.parse(record[7]))
.validity(toPostgresDateRange(
toLocalDate(record[8]),
toLocalDate(record[9])))
.build();
sepaMandates.put(toInt(record[0]), sepaMandate);
bankAccounts.put(toInt(record[0]), sepaMandate.getBankAccount());
});
}
private void importContacts(final List<String[]> records) {
records.stream()
.map(this::trimAll)
.forEach(record -> {
if ( isNotBlank(record[17]) && record[17].contains("billing") ) {
if (isNotBlank(record[17]) && record[17].contains("billing")) {
final var partner = partners.get(toInt(record[1]));
@ -266,6 +314,13 @@ public class ImportBusinessPartners extends ContextBasedTest {
return toLabel(salut, title, firstname, lastname, null);
}
private LocalDate toLocalDate(final String dateString) {
if (isNotBlank(dateString)) {
return LocalDate.parse(dateString);
}
return null;
}
private static Integer toInt(final String value) {
return isNotBlank(value) ? Integer.parseInt(value.trim()) : 0;
}

View File

@ -1,3 +1,3 @@
sepa_mandat_id; bp_id; bank_customer; bank_name; bank_iban; bank_bic; mandat_ref; mandat_signed; mandat_since; mandat_until; mandat_used
234234; 7; Michael Mellies; ING Bank AG; DE37500105177419788228; INGDDEFFXXX; MH12345; 2004-06-12; 2004-06-15; ; 2022-10-20
235662; 10; JM e.K.; ING Bank AG; DE49500105174516484892; INGDDEFFXXX; JM33344; 2005-06-282; 2005-07-01; ; 2016-01-18
235662; 10; JM e.K.; ING Bank AG; DE49500105174516484892; INGDDEFFXXX; JM33344; 2005-06-28; 2005-07-01; ; 2016-01-18

1 sepa_mandat_id bp_id bank_customer bank_name bank_iban bank_bic mandat_ref mandat_signed mandat_since mandat_until mandat_used
2 234234 7 Michael Mellies ING Bank AG DE37500105177419788228 INGDDEFFXXX MH12345 2004-06-12 2004-06-15 2022-10-20
3 235662 10 JM e.K. ING Bank AG DE49500105174516484892 INGDDEFFXXX JM33344 2005-06-282 2005-06-28 2005-07-01 2016-01-18