import coop assets
This commit is contained in:
parent
b0bfb127b6
commit
53d46da49a
@ -1,5 +1,12 @@
|
|||||||
package net.hostsharing.hsadminng.hs.office.coopassets;
|
package net.hostsharing.hsadminng.hs.office.coopassets;
|
||||||
|
|
||||||
public enum HsOfficeCoopAssetsTransactionType {
|
public enum HsOfficeCoopAssetsTransactionType {
|
||||||
ADJUSTMENT, DEPOSIT, DISBURSAL, TRANSFER, ADOPTION, CLEARING, LOSS
|
ADJUSTMENT, // correction of wrong bookings
|
||||||
|
DEPOSIT, // payment received from member after signing shares, >0
|
||||||
|
DISBURSAL, // payment send to member after cancellation of shares, <0
|
||||||
|
TRANSFER, // transferring shares to another member, <0
|
||||||
|
ADOPTION, // receiving shares from another member, >0
|
||||||
|
CLEARING, // settlement with members dept, <0
|
||||||
|
LOSS, // assignment of balance sheet loss in case of cancellation of shares, <0
|
||||||
|
LIMITATION // limitation period was reached after impossible disbursal, <0
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
package net.hostsharing.hsadminng.hs.office.coopshares;
|
package net.hostsharing.hsadminng.hs.office.coopshares;
|
||||||
|
|
||||||
public enum HsOfficeCoopSharesTransactionType {
|
public enum HsOfficeCoopSharesTransactionType {
|
||||||
ADJUSTMENT, SUBSCRIPTION, CANCELLATION;
|
ADJUSTMENT, // correction of wrong bookings
|
||||||
|
SUBSCRIPTION, // shares signed, e.g. with the declaration of accession, >0
|
||||||
|
CANCELLATION; // shares terminated, e.g. when a membership is resigned, <0
|
||||||
}
|
}
|
||||||
|
@ -8,6 +8,7 @@ import net.hostsharing.hsadminng.context.ContextBasedTest;
|
|||||||
import net.hostsharing.hsadminng.hs.office.bankaccount.HsOfficeBankAccountEntity;
|
import net.hostsharing.hsadminng.hs.office.bankaccount.HsOfficeBankAccountEntity;
|
||||||
import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactEntity;
|
import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactEntity;
|
||||||
import net.hostsharing.hsadminng.hs.office.coopassets.HsOfficeCoopAssetsTransactionEntity;
|
import net.hostsharing.hsadminng.hs.office.coopassets.HsOfficeCoopAssetsTransactionEntity;
|
||||||
|
import net.hostsharing.hsadminng.hs.office.coopassets.HsOfficeCoopAssetsTransactionType;
|
||||||
import net.hostsharing.hsadminng.hs.office.coopshares.HsOfficeCoopSharesTransactionEntity;
|
import net.hostsharing.hsadminng.hs.office.coopshares.HsOfficeCoopSharesTransactionEntity;
|
||||||
import net.hostsharing.hsadminng.hs.office.coopshares.HsOfficeCoopSharesTransactionType;
|
import net.hostsharing.hsadminng.hs.office.coopshares.HsOfficeCoopSharesTransactionType;
|
||||||
import net.hostsharing.hsadminng.hs.office.debitor.HsOfficeDebitorEntity;
|
import net.hostsharing.hsadminng.hs.office.debitor.HsOfficeDebitorEntity;
|
||||||
@ -38,12 +39,11 @@ import jakarta.validation.constraints.NotNull;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import java.io.Reader;
|
import java.io.Reader;
|
||||||
|
import java.math.BigDecimal;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
import java.util.HashMap;
|
import java.util.*;
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import static java.util.Arrays.stream;
|
import static java.util.Arrays.stream;
|
||||||
import static net.hostsharing.hsadminng.mapper.PostgresDateRange.toPostgresDateRange;
|
import static net.hostsharing.hsadminng.mapper.PostgresDateRange.toPostgresDateRange;
|
||||||
@ -65,15 +65,15 @@ import static org.assertj.core.api.Assertions.assertThat;
|
|||||||
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
|
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
|
||||||
public class ImportOfficeTables extends ContextBasedTest {
|
public class ImportOfficeTables extends ContextBasedTest {
|
||||||
|
|
||||||
private static Map<Integer, HsOfficeContactEntity> contacts = new HashMap<>();
|
private static NavigableMap<Integer, HsOfficeContactEntity> contacts = new TreeMap<>();
|
||||||
private static Map<Integer, HsOfficePersonEntity> persons = new HashMap<>();
|
private static NavigableMap<Integer, HsOfficePersonEntity> persons = new TreeMap<>();
|
||||||
private static Map<Integer, HsOfficePartnerEntity> partners = new HashMap<>();
|
private static NavigableMap<Integer, HsOfficePartnerEntity> partners = new TreeMap<>();
|
||||||
private static Map<Integer, HsOfficeDebitorEntity> debitors = new HashMap<>();
|
private static NavigableMap<Integer, HsOfficeDebitorEntity> debitors = new TreeMap<>();
|
||||||
private static Map<Integer, HsOfficeMembershipEntity> memberships = new HashMap<>();
|
private static NavigableMap<Integer, HsOfficeMembershipEntity> memberships = new TreeMap<>();
|
||||||
private static Map<Integer, HsOfficeSepaMandateEntity> sepaMandates = new HashMap<>();
|
private static NavigableMap<Integer, HsOfficeSepaMandateEntity> sepaMandates = new TreeMap<>();
|
||||||
private static Map<Integer, HsOfficeBankAccountEntity> bankAccounts = new HashMap<>();
|
private static NavigableMap<Integer, HsOfficeBankAccountEntity> bankAccounts = new TreeMap<>();
|
||||||
private static Map<Integer, HsOfficeCoopSharesTransactionEntity> coopShares = new HashMap<>();
|
private static NavigableMap<Integer, HsOfficeCoopSharesTransactionEntity> coopShares = new TreeMap<>();
|
||||||
private static Map<Integer, HsOfficeCoopAssetsTransactionEntity> assetTransactions = new HashMap<>();
|
private static NavigableMap<Integer, HsOfficeCoopAssetsTransactionEntity> coopAssets = new TreeMap<>();
|
||||||
|
|
||||||
@PersistenceContext
|
@PersistenceContext
|
||||||
EntityManager em;
|
EntityManager em;
|
||||||
@ -142,9 +142,9 @@ public class ImportOfficeTables extends ContextBasedTest {
|
|||||||
""");
|
""");
|
||||||
assertThat(contacts.toString()).isEqualToIgnoringWhitespace("""
|
assertThat(contacts.toString()).isEqualToIgnoringWhitespace("""
|
||||||
{
|
{
|
||||||
|
71=contact(label='Herr Michael Mellies ', emailAddresses='mih@example.org'),
|
||||||
101=contact(label='Frau Dr. Jenny Meyer , JM e.K.', emailAddresses='jm@example.org'),
|
101=contact(label='Frau Dr. Jenny Meyer , JM e.K.', emailAddresses='jm@example.org'),
|
||||||
102=contact(label='Herr Andrew Meyer , JM e.K.', emailAddresses='am@example.org'),
|
102=contact(label='Herr Andrew Meyer , JM e.K.', emailAddresses='am@example.org'),
|
||||||
71=contact(label='Herr Michael Mellies ', emailAddresses='mih@example.org'),
|
|
||||||
121=contact(label='Paule Schmidt , Test PS', emailAddresses='ps@example.com')
|
121=contact(label='Paule Schmidt , Test PS', emailAddresses='ps@example.com')
|
||||||
}
|
}
|
||||||
""");
|
""");
|
||||||
@ -209,10 +209,37 @@ public class ImportOfficeTables extends ContextBasedTest {
|
|||||||
|
|
||||||
assertThat(coopShares.toString()).isEqualToIgnoringWhitespace("""
|
assertThat(coopShares.toString()).isEqualToIgnoringWhitespace("""
|
||||||
{
|
{
|
||||||
33810=CoopShareTransaction(10010, 2016-12-31, CANCELLATION, 22, membership ended),
|
|
||||||
33443=CoopShareTransaction(10007, 2000-12-06, SUBSCRIPTION, 20, initial share subscription),
|
33443=CoopShareTransaction(10007, 2000-12-06, SUBSCRIPTION, 20, initial share subscription),
|
||||||
|
33451=CoopShareTransaction(10010, 2000-12-06, SUBSCRIPTION, 2, initial share subscription),
|
||||||
33701=CoopShareTransaction(10007, 2005-01-10, SUBSCRIPTION, 40, increase),
|
33701=CoopShareTransaction(10007, 2005-01-10, SUBSCRIPTION, 40, increase),
|
||||||
33451=CoopShareTransaction(10010, 2000-12-06, SUBSCRIPTION, 2, initial share subscription)
|
33810=CoopShareTransaction(10010, 2016-12-31, CANCELLATION, 22, membership ended)
|
||||||
|
}
|
||||||
|
""");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Order(5)
|
||||||
|
void importCoopAssets() {
|
||||||
|
|
||||||
|
try (Reader reader = resourceReader("migration/asset-transactions.csv")) {
|
||||||
|
final var lines = readAllLines(reader);
|
||||||
|
importCoopAssets(justHeader(lines), withoutHeader(lines));
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
assertThat(coopAssets.toString()).isEqualToIgnoringWhitespace("""
|
||||||
|
{
|
||||||
|
30000=CoopAssetsTransaction(10007, 2000-12-06, DEPOSIT, 1280.00, for subscription A),
|
||||||
|
31001=CoopAssetsTransaction(10010, 2000-12-06, DEPOSIT, 18.00, for subscription B),
|
||||||
|
31002=CoopAssetsTransaction(10010, 2000-12-06, -18.00, for subscription B),
|
||||||
|
31003=CoopAssetsTransaction(10010, 2000-12-06, DEPOSIT, 128.00, for subscription B),
|
||||||
|
32000=CoopAssetsTransaction(10007, 2005-01-10, DEPOSIT, 2560.00, for subscription C),
|
||||||
|
33001=CoopAssetsTransaction(10007, 2005-01-10, -512.00, for transfer to 10),
|
||||||
|
33002=CoopAssetsTransaction(10010, 2005-01-10, ADOPTION, 512.00, for transfer from 7),
|
||||||
|
34001=CoopAssetsTransaction(10010, 2016-12-31, CLEARING, -8.00, for cancellation D),
|
||||||
|
34002=CoopAssetsTransaction(10010, 2016-12-31, DISBURSAL, -100.00, for cancellation D),
|
||||||
|
34003=CoopAssetsTransaction(10010, 2016-12-31, LOSS, -20.00, for cancellation D)
|
||||||
}
|
}
|
||||||
""");
|
""");
|
||||||
}
|
}
|
||||||
@ -355,6 +382,38 @@ public class ImportOfficeTables extends ContextBasedTest {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void importCoopAssets(final String[] header, final List<String[]> records) {
|
||||||
|
|
||||||
|
final var columns = new Columns(header);
|
||||||
|
|
||||||
|
records.stream()
|
||||||
|
.map(this::trimAll)
|
||||||
|
.map(row -> new Record(columns, row))
|
||||||
|
.forEach(rec -> {
|
||||||
|
final var member = memberships.get(rec.getInteger("bp_id"));
|
||||||
|
|
||||||
|
final var assetTypeMapping = new HashMap<String, HsOfficeCoopAssetsTransactionType>() {{
|
||||||
|
put("HANDOVER", HsOfficeCoopAssetsTransactionType.TRANSFER);
|
||||||
|
put("ADOPTION", HsOfficeCoopAssetsTransactionType.ADOPTION);
|
||||||
|
put("LOSS", HsOfficeCoopAssetsTransactionType.LOSS);
|
||||||
|
put("CLEARING", HsOfficeCoopAssetsTransactionType.CLEARING);
|
||||||
|
put("PRESCRIPTION", HsOfficeCoopAssetsTransactionType.LIMITATION);
|
||||||
|
put("PAYBACK", HsOfficeCoopAssetsTransactionType.DISBURSAL);
|
||||||
|
put("PAYMENT", HsOfficeCoopAssetsTransactionType.DEPOSIT);
|
||||||
|
}};
|
||||||
|
|
||||||
|
final var assetTransaction = HsOfficeCoopAssetsTransactionEntity.builder()
|
||||||
|
.membership(member)
|
||||||
|
.valueDate(rec.getLocalDate("date"))
|
||||||
|
.transactionType(assetTypeMapping.get(rec.getString("action")))
|
||||||
|
.assetValue(rec.getBigDecimal("amount"))
|
||||||
|
.reference(rec.getString("comment"))
|
||||||
|
.build();
|
||||||
|
|
||||||
|
coopAssets.put(rec.getInteger("member_asset_id"), assetTransaction);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
private void importSepaMandates(final String[] header, final List<String[]> records) {
|
private void importSepaMandates(final String[] header, final List<String[]> records) {
|
||||||
|
|
||||||
final var columns = new Columns(header);
|
final var columns = new Columns(header);
|
||||||
@ -549,18 +608,20 @@ class Record {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Integer getInteger(final String columnName) {
|
Integer getInteger(final String columnName) {
|
||||||
return toInt(getString(columnName));
|
final String value = getString(columnName);
|
||||||
}
|
|
||||||
|
|
||||||
LocalDate getLocalDate(final String columnName) {
|
|
||||||
return toLocalDate(getString(columnName));
|
|
||||||
}
|
|
||||||
|
|
||||||
private static Integer toInt(final String value) {
|
|
||||||
return isNotBlank(value) ? Integer.parseInt(value.trim()) : 0;
|
return isNotBlank(value) ? Integer.parseInt(value.trim()) : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
private LocalDate toLocalDate(final String dateString) {
|
BigDecimal getBigDecimal(final String columnName) {
|
||||||
|
final String value = getString(columnName);
|
||||||
|
if (isNotBlank(value)) {
|
||||||
|
return new BigDecimal(value);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
LocalDate getLocalDate(final String columnName) {
|
||||||
|
final String dateString = getString(columnName);
|
||||||
if (isNotBlank(dateString)) {
|
if (isNotBlank(dateString)) {
|
||||||
return LocalDate.parse(dateString);
|
return LocalDate.parse(dateString);
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,11 @@
|
|||||||
member_asset_id; bp_id; date; action; amount
|
member_asset_id; bp_id; date; action; amount; comment
|
||||||
33443; 7; 2000-12-06; PAYMENT; 1280
|
30000; 7; 2000-12-06; PAYMENT; 1280.00; for subscription A
|
||||||
33451; 10; 2000-12-06; PAYMENT; 128
|
31001; 10; 2000-12-06; PAYMENT; 18.00; for subscription B
|
||||||
33701; 7; 2005-01-10; PAYMENT; 2560
|
31002; 10; 2000-12-06; ADJUSTMENT; -18.00; for subscription B
|
||||||
33810; 10; 2016-12-31; PAYBACK; 128
|
31003; 10; 2000-12-06; PAYMENT; 128.00; for subscription B
|
||||||
|
32000; 7; 2005-01-10; PAYMENT; 2560.00; for subscription C
|
||||||
|
33001; 7; 2005-01-10; TRANSFER; -512.00; for transfer to 10
|
||||||
|
33002; 10; 2005-01-10; ADOPTION; 512.00; for transfer from 7
|
||||||
|
34001; 10; 2016-12-31; CLEARING; -8.00; for cancellation D
|
||||||
|
34002; 10; 2016-12-31; PAYBACK; -100.00; for cancellation D
|
||||||
|
34003; 10; 2016-12-31; LOSS; -20.00; for cancellation D
|
||||||
|
|
Loading…
Reference in New Issue
Block a user