11import re
2- from datetime import datetime
2+ from datetime import datetime , timedelta
33
44import beangulp
55import camelot
@@ -46,6 +46,11 @@ def createEntry(
4646 if conversionOriginal and conversionRate :
4747 kv = {"original" : conversionOriginal , "rate" : conversionRate }
4848 text = text .replace ("Amount: " + conversionOriginal , "" )
49+ # handle decimal seperated original amounts
50+ [originalCcy , originalAmt ] = conversionOriginal .split (" " )
51+ text = text .replace (
52+ "Amount: " + f"{ originalCcy } { float (originalAmt ):,} " , ""
53+ )
4954 else :
5055 kv = None
5156
@@ -63,17 +68,34 @@ def createEntry(
6368 ],
6469 )
6570
71+ def createBalance (
72+ self ,
73+ filepath : str ,
74+ date : str ,
75+ amt : amount .Amount ,
76+ ) -> data .Balance :
77+ meta = data .new_metadata (filepath , 0 , None )
78+ return data .Balance (
79+ meta ,
80+ datetime .strptime (date , "%d.%m.%Y" ).date () + timedelta (days = 1 ),
81+ self ._account ,
82+ amt ,
83+ None ,
84+ None ,
85+ )
86+
6687 def extract (self , filepath : str , existing : data .Entries ) -> data .Entries :
6788 entries = []
6889
6990 conversionPattern = re .compile (r"(?P<original>.+) at the rate of (?P<rate>.+)" )
91+ balancePattern = re .compile (r"Balance as of (?P<date>\d\d\.\d\d\.\d\d\d\d)" )
7092
7193 tables = camelot .read_pdf (
7294 filepath ,
7395 flavor = "stream" ,
7496 pages = "all" ,
75- table_regions = ["40,470 ,580,32" ],
76- columns = ["110,300 ,370,440,500" ],
97+ table_regions = ["40,600 ,580,32" ],
98+ columns = ["110,305 ,370,440,500" ],
7799 strip_text = "\n " ,
78100 layout_kwargs = {"word_margin" : 0.50 },
79101 split_text = True ,
@@ -89,7 +111,7 @@ def extract(self, filepath: str, existing: data.Entries) -> data.Entries:
89111 conversionOriginal = None
90112 conversionRate = None
91113 for _ , row in df .iterrows ():
92- date , text , _ , debit , credit , _ = tuple (row )
114+ date , text , _ , debit , credit , bal = tuple (row )
93115
94116 # skip stuff before
95117 if beforeStart and "Date" != date :
@@ -98,8 +120,16 @@ def extract(self, filepath: str, existing: data.Entries) -> data.Entries:
98120 beforeStart = False
99121 continue
100122
101- # skip stuff after
102- if "Balance as of" in text :
123+ # create balance and skip stuff after
124+ balanceMatch = balancePattern .match (text )
125+ if balanceMatch :
126+ entries .append (
127+ self .createBalance (
128+ filepath ,
129+ balanceMatch .group ("date" ),
130+ amount .Amount (D (bal .replace ("'" , "" )), self .currency ),
131+ )
132+ )
103133 break
104134
105135 trxDate = date
0 commit comments