WIP transaction precise

This commit is contained in:
Benjamin Loison 2024-10-03 21:22:30 +02:00
parent 31b81fa33e
commit 046835064d
Signed by: Benjamin_Loison
SSH Key Fingerprint: SHA256:BtnEgYTlHdOg1u+RmYcDE0mnfz1rhv5dSbQ2gyxW8B8
2 changed files with 23 additions and 38 deletions

View File

@ -14,55 +14,38 @@ PRINT_TRANSACTIONS = False
MAIN_BANK_ACCOUNT = 'compte_de_cheques' MAIN_BANK_ACCOUNT = 'compte_de_cheques'
# As far as I know there was no debit yet. debits = []
otherBankAccountsCredits = {} credits_ = []
# Precise bank account
allTransactions = []
for folder in os.listdir():#[-2:]: def appendTransactions()
for folder in os.listdir():
if folder != MAIN_BANK_ACCOUNT: if folder != MAIN_BANK_ACCOUNT:
print(folder) print(folder)
for file in os.listdir(folder):#[-1:]: for file in os.listdir(folder):
print(file) print(file)
filePath = f'{folder}/{file}' filePath = f'{folder}/{file}'
initialAmount, totalMonthlyDebit, totalMonthlyCredit, transactions, fileDatetime = readPdfBankStatement(filePath) _initialAmount, _totalMonthlyDebit, _totalMonthlyCredit, transactions, fileDatetime = readPdfBankStatement(filePath)
#print(totalMonthlyCredit) for transaction in transactions:
#import json transaction['bank account'] = folder
#print(json.dumps(transactions, indent = 4)) allTransactions += [transaction]
otherBankAccountsCredits[fileDatetime] = otherBankAccountsCredits.get(fileDatetime, 0) + totalMonthlyCredit
#exit(1) #exit(1)
os.chdir(f'{MAIN_BANK_ACCOUNT}/') os.chdir(f'{MAIN_BANK_ACCOUNT}/')
totalMonthlyDebits = []
totalMonthlyCredits = []
totalMonthlyDifferences = []
totals = []
firstDatetime = None
lastDatetime = None
for folder in sorted(os.listdir()): for folder in sorted(os.listdir()):
for file in sorted(os.listdir(folder)): for file in sorted(os.listdir(folder)):
filePath = f'{folder}/{file}' filePath = f'{folder}/{file}'
print(filePath) print(filePath)
initialAmount, totalMonthlyDebit, totalMonthlyCredit, transactions, fileDatetime = readPdfBankStatement(filePath) initialAmount, totalMonthlyDebit, totalMonthlyCredit, transactions, fileDatetime = readPdfBankStatement(filePath)
print('Initial amount', initialAmount) for transaction in transactions:
print() transaction['bank account'] = MAIN_BANK_ACCOUNT
totals += [initialAmount] allTransactions += [transaction]
print(f'Total monthly debit: {totalMonthlyDebit}')
print(f'Total monthly credit: {totalMonthlyCredit}')
totalMonthlyDebits += [totalMonthlyDebit]
otherBankAccountsCredit = otherBankAccountsCredits.get(fileDatetime, 0)
print(f'{otherBankAccountsCredit=}')
totalMonthlyCredit += otherBankAccountsCredit
totalMonthlyCredits += [totalMonthlyCredit]
totalMonthlyDifference = totalMonthlyCredit - totalMonthlyDebit
totalMonthlyDifferences += [totalMonthlyDifference]
if PRINT_TRANSACTIONS: if PRINT_TRANSACTIONS:
for transaction in transactions: for transaction in transactions:
# , transaction['currentAmount'] printTransaction(transaction)
print(transaction['date'], transaction['valeur'], transaction['amount'])
print(transaction['comment'])
print()
if firstDatetime is None:
firstDatetime = fileDatetime
#break #break
#break #break
lastDatetime = getDatetimeFromFileName(file) lastDatetime = getDatetimeFromFileName(file)

View File

@ -29,12 +29,10 @@ def toFloat(group):
return float(group.replace(',', '.').replace(' ', '')) return float(group.replace(',', '.').replace(' ', ''))
def getDateFollowing(date, initialDate): def getDateFollowing(date, initialDate):
#print(f'start {date}')
date = datetime.strptime(date, '%d.%m').replace(year = initialDate.year) date = datetime.strptime(date, '%d.%m').replace(year = initialDate.year)
# To support new year. # To support new year.
if date < initialDate: if date < initialDate:
date = date.replace(year = date.year + 1) date = date.replace(year = date.year + 1)
#print(f'end {date}')
return date return date
def readPdfBankStatement(filePath): def readPdfBankStatement(filePath):
@ -57,8 +55,6 @@ def readPdfBankStatement(filePath):
if soldeCrediteurAuRegexMatch is not None or (line.startswith('Date Nature des opérations Valeur Débit Crédit') and not firstPage): if soldeCrediteurAuRegexMatch is not None or (line.startswith('Date Nature des opérations Valeur Débit Crédit') and not firstPage):
if soldeCrediteurAuRegexMatch is not None: if soldeCrediteurAuRegexMatch is not None:
initialDate = datetime.strptime(soldeCrediteurAuRegexMatch.group(1), '%d.%m.%Y') initialDate = datetime.strptime(soldeCrediteurAuRegexMatch.group(1), '%d.%m.%Y')
print(f'{initialDate=}')
#exit(1)
initialAmount = toFloat(soldeCrediteurAuRegexMatch.group(2)) initialAmount = toFloat(soldeCrediteurAuRegexMatch.group(2))
#currentAmount = initialAmount #currentAmount = initialAmount
started = True started = True
@ -106,3 +102,9 @@ def readPdfBankStatement(filePath):
'comment': '\n'.join(comment) 'comment': '\n'.join(comment)
}] }]
return initialAmount, totalMonthlyDebit, totalMonthlyCredit, transactions, fileDatetime return initialAmount, totalMonthlyDebit, totalMonthlyCredit, transactions, fileDatetime
def printTransaction(transaction):
# , transaction['currentAmount']
print(transaction['date'], transaction['valeur'], transaction['amount'])
print(transaction['comment'])
print()