Finish splitter.

This commit is contained in:
Dominik Pantůček 2023-07-29 11:02:54 +02:00
parent 7e12fb3c25
commit 053729fe7d

View file

@ -7,7 +7,6 @@
# ISC License
#
# Copyright 2023 Brmlab, z.s.
# Jan Hrach
# Dominik Pantůček <dominik.pantucek@trustica.cz>
#
# 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"