From 053729fe7d495ce26711d99db877131497cd2029 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20Pant=C5=AF=C4=8Dek?= Date: Sat, 29 Jul 2023 11:02:54 +0200 Subject: [PATCH] Finish splitter. --- fio_splitter.sh | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/fio_splitter.sh b/fio_splitter.sh index df56ad7..e283758 100644 --- a/fio_splitter.sh +++ b/fio_splitter.sh @@ -7,7 +7,6 @@ # ISC License # # Copyright 2023 Brmlab, z.s. -# Jan Hrach # Dominik Pantůček # # Permission to use, copy, modify, and/or distribute this software @@ -139,6 +138,15 @@ end_of_month() { echo "$DAY.$MONTH.$YEAR" } +# +# Given as 1/100 of currency +format_100() { + AMT="$1" + INT=`echo $AMT|sed 's/..$//'` + FRA=`echo $AMT|sed 's/^.*\(..\)$/\1/'` + echo $INT,$FRA +} + # # Splits given file into twelve months split_year() { @@ -162,6 +170,11 @@ split_year() { idFrom=`get_header_field $CSVNAME idFrom` idTo=`get_header_field $CSVNAME idTo` + # Special handling of balances - in 1/100 of currency + currentBalanceTmp=${openingBalance#*;} + currentBalanceStr=`echo $currentBalanceTmp | sed 's/,//'` + currentBalance=`expr $currentBalanceStr + 0` + # Emit months for month in `seq 1 12` ; do MONTH=$month @@ -169,13 +182,19 @@ split_year() { MONTH=0$MONTH fi MCSVNAME="$BANK_DIR_PARTS/$ACCNO-$YEAR-$MONTH.csv" + log $MCSVNAME $currentBalance { echo "$accountId" echo "$bankId" echo "$currency" echo "$iban" - echo "$openingBalance" - echo "$closingBalance" + OPENINGBALANCE=`format_100 $currentBalance` + echo "openingBalance;$OPENINGBALANCE" + for tr in `grep "^[0-9]*;...$MONTH.$YEAR;" "$CSVNAME" | cut -f3 -d';'|sed 's/,//'` ; do + currentBalance=`expr $currentBalance + $tr` + done + CLOSINGBALANCE=`format_100 $currentBalance` + echo "closingBalance;$CLOSINGBALANCE" # echo "$dateStart" echo "dateStart;01.$MONTH.$YEAR" #echo "$dateEnd"