Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix directasim pdf #4454

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
PDFBox Version: 1.8.17
Portfolio Performance Version: 0.73.0
System: linux | x86_64 | 23 | Arch Linux
-----------------------------------------
Signor
NySCUtY IyWjXm
WTmNCh QIjIafB f BBszIwhEpy 7
51961 kQjxQ btJ OukDTd'
Goszrd
PErSD O2036
Nota Informativa per l'ordine c6954896449059
Vi Confermiamo il Vs. ordine sopra riportato del 23.09.2023 Data scadenza 23.10.2023
per l'acquisto di: 9 CROCS INC ISIN US2270461096
sottostante cod. mult. 1
eseguito per: 9
tramite l'intermediario ViewTrade
Tipo di Operazione: Acquisto Mercato di esecuzione: Borsa - NASDAQ
Quantita' USD Euro Prezzo Valuta
24.09.2023 19:02:34 Richiesta Immissione 9 780,3000 732,88* 86,70
25.09.2023 14:30:10 Inoltro
25.09.2023 14:30:15 In negoziazione
25.09.2023 15:30:14 Eseguito (09:30:14) 9 769,7700 722,99* 85,53 27.09.2023
Controvalore: 769,7700 722,99* 85,53
Commissioni: 9,0000 8,45*
Totale a Vs. Debito : 778,7700 731,44
Gli effetti fiscali saranno disponibili a data valuta nel menu Info - 2b.Capital Gain
=C/$= 1,06470
* - cambio provvisorio
Torino, 25.09.2023
DIRECTA SIM
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package name.abuchen.portfolio.datatransfer.pdf.directasim;

import static name.abuchen.portfolio.datatransfer.ExtractorMatchers.check;
import static name.abuchen.portfolio.datatransfer.ExtractorMatchers.hasAmount;
import static name.abuchen.portfolio.datatransfer.ExtractorMatchers.hasCurrencyCode;
import static name.abuchen.portfolio.datatransfer.ExtractorMatchers.hasDate;
import static name.abuchen.portfolio.datatransfer.ExtractorMatchers.hasFees;
import static name.abuchen.portfolio.datatransfer.ExtractorMatchers.hasForexGrossValue;
import static name.abuchen.portfolio.datatransfer.ExtractorMatchers.hasGrossValue;
import static name.abuchen.portfolio.datatransfer.ExtractorMatchers.hasIsin;
import static name.abuchen.portfolio.datatransfer.ExtractorMatchers.hasName;
Expand All @@ -25,14 +27,21 @@

import java.util.ArrayList;
import java.util.List;
import java.util.Locale;

import org.junit.Test;

import name.abuchen.portfolio.datatransfer.Extractor.InputFile;
import name.abuchen.portfolio.datatransfer.Extractor.Item;
import name.abuchen.portfolio.datatransfer.ImportAction.Status;
import name.abuchen.portfolio.datatransfer.actions.AssertImportActions;
import name.abuchen.portfolio.datatransfer.actions.CheckCurrenciesAction;
import name.abuchen.portfolio.datatransfer.pdf.DirectaSimPDFExtractor;
import name.abuchen.portfolio.datatransfer.pdf.PDFInputFile;
import name.abuchen.portfolio.model.Client;
import name.abuchen.portfolio.model.Portfolio;
import name.abuchen.portfolio.model.PortfolioTransaction;
import name.abuchen.portfolio.model.Security;
import name.abuchen.portfolio.money.CurrencyUnit;

@SuppressWarnings("nls")
Expand All @@ -45,7 +54,27 @@ public void testSecurityBuy01()

List<Exception> errors = new ArrayList<>();

List<Item> results = extractor.extract(PDFInputFile.loadTestCase(getClass(), "Buy01.txt"), errors);
System.out.println("running test as = " + Locale.getDefault().toString());

var testCases = PDFInputFile.loadTestCase(getClass(), "Buy01.txt");

var text = ((PDFInputFile) testCases.get(0)).getText();
var lines = text.split("\\n");

for (var line : lines)
{
System.out.println("line = " + line);
System.out.print(" ");

for (int ii = 0; ii < line.length(); ii++)
{
System.out.print(line.codePointAt(ii));
}

System.out.println();
}

List<Item> results = extractor.extract(testCases, errors);

assertThat(errors, empty());
assertThat(countSecurities(results), is(1L));
Expand All @@ -62,7 +91,7 @@ public void testSecurityBuy01()

// check buy sell transaction
assertThat(results, hasItem(purchase( //
hasDate("2024-01-05T14:02:36"), hasShares(29), //
hasDate("2024-01-05T14:02:36"), hasShares(29.00), //
hasSource("Buy01.txt"), //
hasNote("Ordine T1673620593440"), //
hasAmount("EUR", 3079.29), hasGrossValue("EUR", 3074.29), //
Expand Down Expand Up @@ -93,7 +122,7 @@ public void testSecurityBuy02()

// check buy sell transaction
assertThat(results, hasItem(purchase( //
hasDate("2024-01-09T11:57:34"), hasShares(2900), //
hasDate("2024-01-09T11:57:34"), hasShares(2900.00), //
hasSource("Buy02.txt"), //
hasNote("Ordine X4171246514720"), //
hasAmount("EUR", 1511.58), hasGrossValue("EUR", 1502.08), //
Expand Down Expand Up @@ -124,11 +153,80 @@ public void testSecurityBuy03()

// check buy sell transaction
assertThat(results, hasItem(purchase( //
hasDate("2024-04-12T09:04:21"), hasShares(7), //
hasDate("2024-04-12T09:04:21"), hasShares(7.00), //
hasSource("Buy03.txt"), //
hasNote("Ordine P9417565891845"), //
hasAmount("EUR", 829.15), hasGrossValue("EUR", 829.15), //
hasTaxes("EUR", 0.00), hasFees("EUR", 0.00))));

}

@Test
public void testSecurityBuy04()
{
DirectaSimPDFExtractor extractor = new DirectaSimPDFExtractor(new Client());

List<Exception> errors = new ArrayList<>();

List<Item> results = extractor.extract(PDFInputFile.loadTestCase(getClass(), "Buy04.txt"), errors);

assertThat(errors, empty());
assertThat(countSecurities(results), is(1L));
assertThat(countBuySell(results), is(1L));
assertThat(countAccountTransactions(results), is(0L));
assertThat(results.size(), is(2));
new AssertImportActions().check(results, CurrencyUnit.EUR);

// check security
assertThat(results, hasItem(security( //
hasIsin("US2270461096"), hasWkn(null), hasTicker(null), //
hasName("CROCS INC"), //
hasCurrencyCode("USD"))));

// check buy sell transaction
assertThat(results, hasItem(purchase( //
hasDate("2023-09-25T15:30:14"), hasShares(9.00), //
hasSource("Buy04.txt"), //
hasNote("Ordine c6954896449059"), //
hasAmount("EUR", 731.44), hasGrossValue("EUR", 722.99), //
hasForexGrossValue("USD", 769.77), //
hasTaxes("EUR", 0.00), hasFees("EUR", 8.45))));

}

@Test
public void testSecurityBuy04WithSecurityInEUR()
{
Security security = new Security("CROCS INC", CurrencyUnit.EUR);
security.setIsin("US2270461096");

Client client = new Client();
client.addSecurity(security);

DirectaSimPDFExtractor extractor = new DirectaSimPDFExtractor(client);

List<Exception> errors = new ArrayList<>();

List<Item> results = extractor.extract(PDFInputFile.loadTestCase(getClass(), "Buy04.txt"), errors);

assertThat(errors, empty());
assertThat(countSecurities(results), is(0L));
assertThat(countBuySell(results), is(1L));
assertThat(countAccountTransactions(results), is(0L));
assertThat(results.size(), is(1));
new AssertImportActions().check(results, CurrencyUnit.EUR);

// check buy sell transaction
assertThat(results, hasItem(purchase( //
hasDate("2023-09-25T15:30:14"), hasShares(9.00), //
hasSource("Buy04.txt"), //
hasNote("Ordine c6954896449059"), //
hasAmount("EUR", 731.44), hasGrossValue("EUR", 722.99), //
hasTaxes("EUR", 0.00), hasFees("EUR", 8.45), //
check(tx -> {
CheckCurrenciesAction c = new CheckCurrenciesAction();
Status s = c.process((PortfolioTransaction) tx, new Portfolio());
assertThat(s, is(Status.OK_STATUS));
}))));
}
}
Loading
Loading