Redesign of monthly cash flow.
This commit is contained in:
		
							
								
								
									
										499
									
								
								BAK/create_monthly_cash_flow.sh.00
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										499
									
								
								BAK/create_monthly_cash_flow.sh.00
									
									
									
									
									
										Executable file
									
								
							| @@ -0,0 +1,499 @@ | |||||||
|  | #!/usr/bin/env bash | ||||||
|  |  | ||||||
|  | # ============= | ||||||
|  | # --- Some Definitions | ||||||
|  | # ============= | ||||||
|  |  | ||||||
|  | logfile=$(mktemp) | ||||||
|  |  | ||||||
|  | office_dir="/home/chris/O.OPEN/Büro" | ||||||
|  | base_dir_bank_statement="/home/chris/O.OPEN/Bank-Konten/Commerzbank/Geschaefts-Konto/Kontoauszüge" | ||||||
|  | #src_base_dir_cash_flow="${office_dir}/Einnahmen/" | ||||||
|  |  | ||||||
|  | bill_receipts="Rechnungen Einnahmen" | ||||||
|  | bill_cost="Rechnungen Ausgaben" | ||||||
|  | bill_storno="Storno Rechnungen" | ||||||
|  |  | ||||||
|  | backup_time="$(date +%Y-%m-%d-%H%M)" | ||||||
|  |  | ||||||
|  | default_year="$(date +%Y)" | ||||||
|  | default_month="$(date +%m)" | ||||||
|  |  | ||||||
|  |  | ||||||
|  | # --- | ||||||
|  | # --- DON'T MAKE CHANGES AFTER THIS LINE | ||||||
|  | # --- | ||||||
|  |  | ||||||
|  |  | ||||||
|  | # ============= | ||||||
|  | # --- Some functions | ||||||
|  | # ============= | ||||||
|  |  | ||||||
|  | # - Revursive function | ||||||
|  | # - | ||||||
|  | copy_file () { | ||||||
|  |  | ||||||
|  |    echo "" | ||||||
|  |    echononl "Create directory '"$1"'.." | ||||||
|  |    if [[ ! -d "${dir_cash_cost}/$2/$1" ]]; then | ||||||
|  |       mkdir "${dir_cash_cost}/$2/$1" > $logfile 2>&1 | ||||||
|  |       if [[ $? -eq 0 ]]; then | ||||||
|  |          echo_ok | ||||||
|  |       else | ||||||
|  |          echo_failed | ||||||
|  |          error $(cat $logfile) | ||||||
|  |       fi | ||||||
|  |    else | ||||||
|  |       echo_skipped | ||||||
|  |    fi | ||||||
|  |     | ||||||
|  |    while IFS='' read -r -d '' _file || [[ -n $_file ]] ; do | ||||||
|  |  | ||||||
|  |       [[ -h "$_file" ]] && continue | ||||||
|  |  | ||||||
|  |       if [[ -d "$_file" ]] ; then | ||||||
|  |          copy_file "$(basename "${_file}")" "$2/$1" | ||||||
|  |          continue | ||||||
|  |       fi | ||||||
|  |  | ||||||
|  |       echononl "Copy '$(basename "$_file")' to '$(basename "$1")'.." | ||||||
|  |       if [[ "$_file" =~ \.zip$ ]] ; then | ||||||
|  |          echo_skipped | ||||||
|  |       else | ||||||
|  |          cp -a "$_file" "${dir_cash_cost}/$2/$1/$(basename "$_file")" > $logfile 2>&1 | ||||||
|  |          if [[ $? -eq 0 ]]; then | ||||||
|  |             echo_ok | ||||||
|  |          else | ||||||
|  |             echo_failed | ||||||
|  |             error $(cat $logfile) | ||||||
|  |          fi | ||||||
|  |       fi | ||||||
|  |    done < <(find "${src_dir_cash_cost}/$2/$1" -mindepth 1 -maxdepth 1 -print0) | ||||||
|  | } | ||||||
|  |  | ||||||
|  | clean_up() { | ||||||
|  |  | ||||||
|  |    rm -f $logfile | ||||||
|  |    exit $1 | ||||||
|  | } | ||||||
|  |  | ||||||
|  |  | ||||||
|  | echononl(){ | ||||||
|  |    echo X\\c > /tmp/shprompt$$ | ||||||
|  |    if [ `wc -c /tmp/shprompt$$ | awk '{print $1}'` -eq 1 ]; then | ||||||
|  |       echo "$*\\c" 1>&2 | ||||||
|  |    else | ||||||
|  |        echo -e -n "$*" 1>&2 | ||||||
|  |    fi | ||||||
|  |    rm /tmp/shprompt$$ | ||||||
|  | } | ||||||
|  |  | ||||||
|  | fatal(){ | ||||||
|  |    echo "" | ||||||
|  |    echo -e "\t[ \033[31m\033[1mfataler Fehler\033[m ]: $*" | ||||||
|  |    echo "" | ||||||
|  |    echo -e "\t\033[31m\033[1mInstalllation wird abgebrochen\033[m\033[m" | ||||||
|  |    echo "" | ||||||
|  |    clean_up 1 | ||||||
|  | } | ||||||
|  |  | ||||||
|  | error(){ | ||||||
|  |    echo "" | ||||||
|  |    echo -e "\t[ \033[31m\033[1mFehler\033[m ]: $*" | ||||||
|  |    echo "" | ||||||
|  | } | ||||||
|  |  | ||||||
|  | warn (){ | ||||||
|  |    echo "" | ||||||
|  |    echo -e "\t[ \033[33m\033[1mWarning\033[m ]: $*" | ||||||
|  |    echo "" | ||||||
|  | } | ||||||
|  |  | ||||||
|  | info (){ | ||||||
|  |    echo "" | ||||||
|  |    echo -e "\t[ \033[32m\033[1mInfo\033[m ]: $*" | ||||||
|  |    echo "" | ||||||
|  | } | ||||||
|  |  | ||||||
|  | echo_ok() { | ||||||
|  |    echo -e "\033[75G[ \033[32mok\033[m ]" | ||||||
|  | } | ||||||
|  | echo_failed(){ | ||||||
|  |    echo -e "\033[75G[ \033[1;31mfailed\033[m ]" | ||||||
|  | } | ||||||
|  | echo_skipped() { | ||||||
|  |    echo -e "\033[75G[ \033[33m\033[1mskipped\033[m ]" | ||||||
|  | } | ||||||
|  |  | ||||||
|  | trap clean_up SIGHUP SIGINT SIGTERM | ||||||
|  |  | ||||||
|  | ## --- | ||||||
|  | ## --- END: functions | ||||||
|  |  | ||||||
|  | clear | ||||||
|  | echo | ||||||
|  | #echo -e "\033[21G\033[32mSkript zur Erstellung der Dateien für die  monatlich Bilanz \033[m" | ||||||
|  | echo -e "\t\033[32mSkript zur Erstellung der Dateien für die monatlich Bilanz \033[m" | ||||||
|  | echo | ||||||
|  | echo | ||||||
|  | echo | ||||||
|  |  | ||||||
|  | echo "" | ||||||
|  | echo -e "\033[32m--\033[m" | ||||||
|  | echo "" | ||||||
|  | echo "Für welches Jahr (JJJJ) soll die Bilanz erstellt werden?" | ||||||
|  | echo "" | ||||||
|  | year="" | ||||||
|  | if [[ -n "$default_year" ]] ; then | ||||||
|  |    echononl "Jahr [${default_year}]: " | ||||||
|  |    read year | ||||||
|  |    if [[ "X$year" = "X" ]]; then | ||||||
|  |       year="$default_year" | ||||||
|  |    fi | ||||||
|  | else | ||||||
|  |    echononl "Jahr [JJJJ]: " | ||||||
|  |    read year | ||||||
|  |    while [ "X$year" = "X" ] ; do | ||||||
|  |       echo -e "\n\t\033[33m\033[1mDie Angabe von 'Jahr' ist erforderlich!\033[m\n" | ||||||
|  |       echononl "Jahr [JJJJ]: " | ||||||
|  |       read year | ||||||
|  |    done | ||||||
|  | fi | ||||||
|  | year_short="$(echo ${year:${#year} - 2})" | ||||||
|  |  | ||||||
|  | echo "" | ||||||
|  | echo -e "\033[32m--\033[m" | ||||||
|  | echo "" | ||||||
|  | echo "Für welche Monat (MM) soll die Bilanz erstellt werden?" | ||||||
|  | echo "" | ||||||
|  | month="" | ||||||
|  | if [[ -n "$default_month" ]] ; then | ||||||
|  |    echononl "Monat [${default_month}]: " | ||||||
|  |    read month | ||||||
|  |    if [[ "X$month" = "X" ]]; then | ||||||
|  |       month="$default_month" | ||||||
|  |    fi | ||||||
|  | else | ||||||
|  |    echononl "Monat [MM]: " | ||||||
|  |    read month | ||||||
|  |    while [ "X$month" = "X" ] ; do | ||||||
|  |       echo -e "\n\t\033[33m\033[1mDie Angabe von 'Monat' ist erforderlich!\033[m\n" | ||||||
|  |       echononl "Monat [MM]: " | ||||||
|  |       read month | ||||||
|  |    done | ||||||
|  | fi | ||||||
|  |  | ||||||
|  |  | ||||||
|  |  | ||||||
|  | src_dir_cash_receipts="${office_dir}/Einnahmen/${year}" | ||||||
|  | src_dir_cash_storno="${office_dir}/Einnahmen/${year}/Stornorechnungen" | ||||||
|  | src_dir_cash_cost="${office_dir}/Ausgaben/${year}/$month" | ||||||
|  | src_dir_bank_statement="$base_dir_bank_statement/${year}" | ||||||
|  |  | ||||||
|  | base_dir_cash_flow="${office_dir}/Abschluss_${year}" | ||||||
|  | dir_cash_flow="${base_dir_cash_flow}/${year}-${month}" | ||||||
|  | dir_cash_receipts="${dir_cash_flow}/$bill_receipts" | ||||||
|  | dir_cash_cost="${dir_cash_flow}/$bill_cost" | ||||||
|  | dir_cash_storno="${dir_cash_flow}/$bill_storno" | ||||||
|  |     | ||||||
|  |  | ||||||
|  | echo | ||||||
|  | #echo -e "\033[21G\033[32mSkript zur Erstellung der Dateien für die  monatlich Bilanz \033[m" | ||||||
|  | echo -e "\t\033[32mErstelle die Dateien für die monatlich Bilanz \033[1m${month}/${year}\033[m" | ||||||
|  | echo | ||||||
|  |  | ||||||
|  | info "Continue creating the monthly bilnce type uppercase 'YES'" | ||||||
|  | echo -e -n "\033[1mContinue:\033[m " | ||||||
|  | read OK | ||||||
|  |  | ||||||
|  | if [[ "$OK" != "YES" ]] ; then | ||||||
|  |    fatal "Abort by user request - Answer as not 'YES'" | ||||||
|  | fi | ||||||
|  |  | ||||||
|  |  | ||||||
|  | if [[ -d "$dir_cash_flow" ]]; then | ||||||
|  |    echo "" | ||||||
|  |    echononl "Backup existing cash flow directory\n   '$dir_cash_flow'.." | ||||||
|  |    mv "$dir_cash_flow" "${dir_cash_flow}.BAK-$backup_time" > $logfile 2>&1 | ||||||
|  |    if [[ $? -eq 0 ]]; then | ||||||
|  |       echo_ok | ||||||
|  |    else | ||||||
|  |       echo_failed | ||||||
|  |       error $(cat $logfile) | ||||||
|  |    fi | ||||||
|  | fi | ||||||
|  |  | ||||||
|  | # --- | ||||||
|  | # - Create needed directories | ||||||
|  | # --- | ||||||
|  |  | ||||||
|  | echo "" | ||||||
|  | echo "" | ||||||
|  | echo -e "\033[37m\033[1mCreate needed directories..\033[m" | ||||||
|  | echo "" | ||||||
|  |  | ||||||
|  |  | ||||||
|  | echononl "Create directory '$(basename "$base_dir_cash_flow")'.." | ||||||
|  | if [[ ! -d "$base_dir_cash_flow" ]]; then | ||||||
|  |    mkdir "$base_dir_cash_flow" > $logfile 2>&1 | ||||||
|  |    if [[ $? -eq 0 ]]; then | ||||||
|  |       echo_ok | ||||||
|  |    else | ||||||
|  |       echo_failed | ||||||
|  |       error $(cat $logfile) | ||||||
|  |    fi | ||||||
|  | else | ||||||
|  |    echo_skipped | ||||||
|  | fi | ||||||
|  |  | ||||||
|  | echononl "Create directory '$(basename "$dir_cash_flow")'.." | ||||||
|  | if [[ ! -d "$dir_cash_flow" ]]; then | ||||||
|  |    mkdir "$dir_cash_flow" > $logfile 2>&1 | ||||||
|  |    if [[ $? -eq 0 ]]; then | ||||||
|  |       echo_ok | ||||||
|  |    else | ||||||
|  |       echo_failed | ||||||
|  |       error $(cat $logfile) | ||||||
|  |    fi | ||||||
|  | else | ||||||
|  |    echo_skipped | ||||||
|  | fi | ||||||
|  |  | ||||||
|  | echononl "Create directory '$(basename "$dir_cash_receipts")'.." | ||||||
|  | if [[ ! -d "$dir_cash_receipts" ]]; then | ||||||
|  |    mkdir "$dir_cash_receipts" > $logfile 2>&1 | ||||||
|  |    if [[ $? -eq 0 ]]; then | ||||||
|  |       echo_ok | ||||||
|  |    else | ||||||
|  |       echo_failed | ||||||
|  |       error $(cat $logfile) | ||||||
|  |    fi | ||||||
|  | else | ||||||
|  |    echo_skipped | ||||||
|  | fi | ||||||
|  |  | ||||||
|  | echononl "Create directory '$(basename "$dir_cash_cost")'.." | ||||||
|  | if [[ ! -d "$dir_cash_cost" ]]; then | ||||||
|  |    mkdir "$dir_cash_cost" > $logfile 2>&1 | ||||||
|  |    if [[ $? -eq 0 ]]; then | ||||||
|  |       echo_ok | ||||||
|  |    else | ||||||
|  |       echo_failed | ||||||
|  |       error $(cat $logfile) | ||||||
|  |    fi | ||||||
|  | else | ||||||
|  |    echo_skipped | ||||||
|  | fi | ||||||
|  |  | ||||||
|  | echononl "Create directory '$(basename "$dir_cash_storno")'.." | ||||||
|  | if [[ ! -d "$dir_cash_storno" ]]; then | ||||||
|  |    mkdir "$dir_cash_storno" > $logfile 2>&1 | ||||||
|  |    if [[ $? -eq 0 ]]; then | ||||||
|  |       echo_ok | ||||||
|  |    else | ||||||
|  |       echo_failed | ||||||
|  |       error $(cat $logfile) | ||||||
|  |    fi | ||||||
|  | else | ||||||
|  |    echo_skipped | ||||||
|  | fi | ||||||
|  |  | ||||||
|  |  | ||||||
|  |  | ||||||
|  |  | ||||||
|  | # --- | ||||||
|  | # - Bank statement | ||||||
|  | # --- | ||||||
|  |  | ||||||
|  | echo "" | ||||||
|  | echo "" | ||||||
|  | echo -e "\033[37m\033[1mGet bank statement file for ${month}/${year} ..\033[m" | ||||||
|  | echo "" | ||||||
|  |  | ||||||
|  | found_bank_statement=false | ||||||
|  | echononl "Copy '${src_dir_bank_statement}/Auszug01-${month}-${year_short}.pdf' \n   to directory '$dir_cash_flow'.." | ||||||
|  | if [[ -f "${src_dir_bank_statement}/Auszug01-${month}-${year_short}.pdf" ]]; then | ||||||
|  |    found_bank_statement=true | ||||||
|  |    cp -a "${src_dir_bank_statement}/Auszug01-${month}-${year_short}.pdf" "$dir_cash_flow/" > $logfile 2>&1 | ||||||
|  |    if [[ $? -eq 0 ]]; then | ||||||
|  |       echo_ok | ||||||
|  |    else | ||||||
|  |       echo_failed | ||||||
|  |       error $(cat $logfile) | ||||||
|  |    fi | ||||||
|  | else | ||||||
|  |    echo_skipped | ||||||
|  | fi | ||||||
|  |  | ||||||
|  | found_bank_transaction=false | ||||||
|  | echononl "Copy '${src_dir_bank_statement}/Umsatz-${year}-${month}.pdf' \n   to directory '$dir_cash_flow'.." | ||||||
|  | if [[ -f "${src_dir_bank_statement}/Umsatz-${year}-${month}.pdf" ]]; then | ||||||
|  |    found_bank_transaction=true | ||||||
|  |    cp -a "${src_dir_bank_statement}/Umsatz-${year}-${month}.pdf" "$dir_cash_flow/" > $logfile 2>&1 | ||||||
|  |    if [[ $? -eq 0 ]]; then | ||||||
|  |       echo_ok | ||||||
|  |    else | ||||||
|  |       echo_failed | ||||||
|  |       error $(cat $logfile) | ||||||
|  |    fi | ||||||
|  | else | ||||||
|  |    echo_skipped | ||||||
|  | fi | ||||||
|  |  | ||||||
|  |  | ||||||
|  | # --- | ||||||
|  | # - Cash flow storno | ||||||
|  | # --- | ||||||
|  |  | ||||||
|  | echo "" | ||||||
|  | echo "" | ||||||
|  | echo -e "\033[37m\033[1mCreate cash flow storno (Stornorechnungen)..\033[m" | ||||||
|  | echo "" | ||||||
|  |  | ||||||
|  | found_cash_storno=false | ||||||
|  | while IFS='' read -r -d '' _storno_rg_pdf ; do | ||||||
|  |    found_cash_storno=true | ||||||
|  |    echononl "Kopiere Stornorechnung '$(basename "$_storno_rg_pdf")'.." | ||||||
|  |    cp -a "$_storno_rg_pdf" "$dir_cash_storno" > $logfile 2>&1 | ||||||
|  |    if [[ $? -eq 0 ]]; then | ||||||
|  |       echo_ok | ||||||
|  |    else | ||||||
|  |       echo_failed | ||||||
|  |       error $(cat $logfile) | ||||||
|  |    fi | ||||||
|  | done < <(find "$src_dir_cash_storno" -maxdepth 1 -type f -name "storno-${year}-${month}*.pdf" -print0) | ||||||
|  |  | ||||||
|  |  | ||||||
|  | # --- | ||||||
|  | # - Cash flow receipts | ||||||
|  | # --- | ||||||
|  |  | ||||||
|  | echo "" | ||||||
|  | echo "" | ||||||
|  | echo -e "\033[37m\033[1mCreate cash flow receipts (Einnahmen)..\033[m" | ||||||
|  | echo "" | ||||||
|  |  | ||||||
|  | found_cash_receipts=false | ||||||
|  | while IFS='' read -r -d '' _rg_pdf ; do | ||||||
|  |    found_cash_receipts=true | ||||||
|  |    echononl "Kopiere Rechnung '$(basename "$_rg_pdf")'.." | ||||||
|  |    cp -a "$_rg_pdf" "$dir_cash_receipts" > $logfile 2>&1 | ||||||
|  |    if [[ $? -eq 0 ]]; then | ||||||
|  |       echo_ok | ||||||
|  |    else | ||||||
|  |       echo_failed | ||||||
|  |       error $(cat $logfile) | ||||||
|  |    fi | ||||||
|  | done < <(find "$src_dir_cash_receipts" -maxdepth 1 -type f -name "rg-${year}-${month}*.pdf" -print0) | ||||||
|  |  | ||||||
|  | echo | ||||||
|  | found_contract_file=false | ||||||
|  | _month=$(expr $month + 1) | ||||||
|  | _year=$year | ||||||
|  | if [[ ${#_month} -eq 1 ]]; then | ||||||
|  |    _month="0${_month}" | ||||||
|  | elif [[ $_month -eq 13 ]]; then | ||||||
|  |    _month=01 | ||||||
|  |    _year=$(expr $_year + 1) | ||||||
|  | fi | ||||||
|  |  | ||||||
|  | while IFS='' read -r -d '' file || [[ -n $file ]] ; do | ||||||
|  |    found_contract_file=true | ||||||
|  |    echononl "Copy '$(basename $file)' to directory\n '$dir_cash_flow'.." | ||||||
|  |    cp -a "$file" "$dir_cash_flow/" > $logfile 2>&1 | ||||||
|  |    if [[ $? -eq 0 ]]; then | ||||||
|  |       echo_ok | ||||||
|  |    else | ||||||
|  |       echo_failed | ||||||
|  |       error $(cat $logfile) | ||||||
|  |    fi | ||||||
|  | done < <(find "$base_dir_cash_flow" -mindepth 1 -maxdepth 1 -type f -name "ServiceVertraege_${year}_Stand-${_year}-${_month}-*.xlsx" -print0) | ||||||
|  |  | ||||||
|  | echo -e "\n\tServiceVertraege_${year}_Stand-${_year}-${_month}-*.xlsx\n" | ||||||
|  |  | ||||||
|  |  | ||||||
|  |  | ||||||
|  | # --- | ||||||
|  | # - Cash flow cost | ||||||
|  | # --- | ||||||
|  |  | ||||||
|  | echo "" | ||||||
|  | echo "" | ||||||
|  | echo -e "\033[37m\033[1mCreate cash flow cost (Ausgaben)..\033[m" | ||||||
|  | echo "" | ||||||
|  |  | ||||||
|  |  | ||||||
|  | found_cash_cost=false | ||||||
|  | while IFS='' read -r -d '' dir ; do | ||||||
|  |    found_cash_cost=true | ||||||
|  |    copy_file "$(basename "$dir")" "" | ||||||
|  | done < <(find "$src_dir_cash_cost/" -mindepth 1 -maxdepth 1 -type d  -print0) | ||||||
|  |  | ||||||
|  |  | ||||||
|  | # --- | ||||||
|  | # - Create zip archive | ||||||
|  | # --- | ||||||
|  |  | ||||||
|  | echo "" | ||||||
|  | echo "" | ||||||
|  | echo -e "\033[37m\033[1mCreate zip archive..\033[m" | ||||||
|  | echo "" | ||||||
|  |  | ||||||
|  | echononl "Backup file 'oopen-${year}-${month}.zip'.." | ||||||
|  | if [[ -f "${base_dir_cash_flow}/oopen-${year}-${month}.zip" ]]; then | ||||||
|  |    cp -a "${base_dir_cash_flow}/oopen-${year}-${month}.zip" \ | ||||||
|  |       "${base_dir_cash_flow}/oopen-${year}-${month}.${backup_time}.zip" > $logfile 2>&1 | ||||||
|  |    if [[ $? -eq 0 ]]; then | ||||||
|  |       echo_ok | ||||||
|  |    else | ||||||
|  |       echo_failed | ||||||
|  |       error $(cat $logfile) | ||||||
|  |    fi | ||||||
|  | else | ||||||
|  |    echo_skipped | ||||||
|  | fi | ||||||
|  |  | ||||||
|  | echononl "Change into dorectory '${base_dir_cash_flow}'.." | ||||||
|  | cd ${base_dir_cash_flow} > $logfile 2>&1 | ||||||
|  | if [[ $? -eq 0 ]]; then | ||||||
|  |    echo_ok | ||||||
|  | else | ||||||
|  |    echo_failed | ||||||
|  |    error $(cat $logfile) | ||||||
|  | fi | ||||||
|  |  | ||||||
|  |  | ||||||
|  | echononl "Create zip archive 'oopen-${year}-${month}.zip'.." | ||||||
|  | zip -r "oopen-${year}-${month}.zip" "${year}-${month}" > $logfile 2>&1 | ||||||
|  | if [[ $? -eq 0 ]]; then | ||||||
|  |    echo_ok | ||||||
|  | else | ||||||
|  |    echo_failed | ||||||
|  |    error $(cat $logfile) | ||||||
|  | fi | ||||||
|  |  | ||||||
|  |  | ||||||
|  | if ! $found_cash_receipts ; then | ||||||
|  |    warn "No cash flow receipts (Einnahmen) found." | ||||||
|  | fi | ||||||
|  | if ! $found_bank_transaction ; then | ||||||
|  |    error "No transaction volumes found." | ||||||
|  | fi | ||||||
|  | if ! $found_bank_statement ; then | ||||||
|  |    warn "No bank statement file found." | ||||||
|  | else | ||||||
|  |    echo | ||||||
|  | fi | ||||||
|  | if ! $found_contract_file ; then | ||||||
|  |    warn "No service contract file found." | ||||||
|  | else | ||||||
|  |    echo | ||||||
|  | fi | ||||||
|  |  | ||||||
|  | if ! $found_cash_cost ; then | ||||||
|  |    warn "No cash flow cost (Ausgaben) found." | ||||||
|  | fi | ||||||
|  |  | ||||||
|  |  | ||||||
|  | echo "" | ||||||
|  | clean_up 0 | ||||||
| @@ -8,7 +8,7 @@ logfile=$(mktemp) | |||||||
|  |  | ||||||
| office_dir="/home/chris/O.OPEN/Büro" | office_dir="/home/chris/O.OPEN/Büro" | ||||||
| base_dir_bank_statement="/home/chris/O.OPEN/Bank-Konten/Commerzbank/Geschaefts-Konto/Kontoauszüge" | base_dir_bank_statement="/home/chris/O.OPEN/Bank-Konten/Commerzbank/Geschaefts-Konto/Kontoauszüge" | ||||||
| src_base_dir_cash_flow="${office_dir}/Einnahmen/" | #src_base_dir_cash_flow="${office_dir}/Einnahmen/" | ||||||
|  |  | ||||||
| bill_receipts="Rechnungen Einnahmen" | bill_receipts="Rechnungen Einnahmen" | ||||||
| bill_cost="Rechnungen Ausgaben" | bill_cost="Rechnungen Ausgaben" | ||||||
| @@ -185,7 +185,7 @@ fi | |||||||
|  |  | ||||||
|  |  | ||||||
|  |  | ||||||
| src_dir_cash_receipts="${office_dir}/Einnahmen/${year}" | src_dir_cash_receipts="${office_dir}/Einnahmen/${year}/$month" | ||||||
| src_dir_cash_storno="${office_dir}/Einnahmen/${year}/Stornorechnungen" | src_dir_cash_storno="${office_dir}/Einnahmen/${year}/Stornorechnungen" | ||||||
| src_dir_cash_cost="${office_dir}/Ausgaben/${year}/$month" | src_dir_cash_cost="${office_dir}/Ausgaben/${year}/$month" | ||||||
| src_dir_bank_statement="$base_dir_bank_statement/${year}" | src_dir_bank_statement="$base_dir_bank_statement/${year}" | ||||||
| @@ -384,7 +384,8 @@ while IFS='' read -r -d '' _rg_pdf ; do | |||||||
|       echo_failed |       echo_failed | ||||||
|       error $(cat $logfile) |       error $(cat $logfile) | ||||||
|    fi |    fi | ||||||
| done < <(find "$src_dir_cash_receipts" -maxdepth 1 -type f -name "rg-${year}-${month}*.pdf" -print0) | #done < <(find "$src_dir_cash_receipts" -maxdepth 1 -type f -name "rg-${year}-${month}*.pdf" -print0) | ||||||
|  | done < <(find "$src_dir_cash_receipts" -maxdepth 1 -type f -name "*.pdf" -print0) | ||||||
|  |  | ||||||
| echo | echo | ||||||
| found_contract_file=false | found_contract_file=false | ||||||
|   | |||||||
							
								
								
									
										244
									
								
								make_cash_flow_dirs.sh
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										244
									
								
								make_cash_flow_dirs.sh
									
									
									
									
									
										Executable file
									
								
							| @@ -0,0 +1,244 @@ | |||||||
|  | #!/usr/bin/env bash | ||||||
|  |  | ||||||
|  | # ============= | ||||||
|  | # --- Some Definitions | ||||||
|  | # ============= | ||||||
|  |  | ||||||
|  | logfile=$(mktemp) | ||||||
|  |  | ||||||
|  | base_dir_costs=/home/chris/O.OPEN/Büro/Ausgaben | ||||||
|  | base_dir_receipts=/home/chris/O.OPEN/Büro/Einnahmen | ||||||
|  |  | ||||||
|  | dirs_costs="Hetzner InternetX Netcup STB-Telgmann Sinma Sonstige Telekom" | ||||||
|  | dirs_costs_telekom="Festnetz MobileData MobileFon" | ||||||
|  |  | ||||||
|  |  | ||||||
|  | default_year="$(date +%Y)" | ||||||
|  | default_month="$(date +%m)" | ||||||
|  |  | ||||||
|  |  | ||||||
|  | # --- | ||||||
|  | # --- DON'T MAKE CHANGES AFTER THIS LINE | ||||||
|  | # --- | ||||||
|  |  | ||||||
|  |  | ||||||
|  | # ============= | ||||||
|  | # --- Some functions | ||||||
|  | # ============= | ||||||
|  |  | ||||||
|  | clean_up() { | ||||||
|  |  | ||||||
|  |    rm -f $logfile | ||||||
|  |    exit $1 | ||||||
|  | } | ||||||
|  |  | ||||||
|  |  | ||||||
|  | echononl(){ | ||||||
|  |    echo X\\c > /tmp/shprompt$$ | ||||||
|  |    if [ `wc -c /tmp/shprompt$$ | awk '{print $1}'` -eq 1 ]; then | ||||||
|  |       echo "$*\\c" 1>&2 | ||||||
|  |    else | ||||||
|  |        echo -e -n "$*" 1>&2 | ||||||
|  |    fi | ||||||
|  |    rm /tmp/shprompt$$ | ||||||
|  | } | ||||||
|  |  | ||||||
|  | fatal(){ | ||||||
|  |    echo "" | ||||||
|  |    echo -e "\t[ \033[31m\033[1mfataler Fehler\033[m ]: $*" | ||||||
|  |    echo "" | ||||||
|  |    echo -e "\t\033[31m\033[1mInstalllation wird abgebrochen\033[m\033[m" | ||||||
|  |    echo "" | ||||||
|  |    clean_up 1 | ||||||
|  | } | ||||||
|  |  | ||||||
|  | error(){ | ||||||
|  |    echo "" | ||||||
|  |    echo -e "\t[ \033[31m\033[1mFehler\033[m ]: $*" | ||||||
|  |    echo "" | ||||||
|  | } | ||||||
|  |  | ||||||
|  | warn (){ | ||||||
|  |    echo "" | ||||||
|  |    echo -e "\t[ \033[33m\033[1mWarning\033[m ]: $*" | ||||||
|  |    echo "" | ||||||
|  | } | ||||||
|  |  | ||||||
|  | info (){ | ||||||
|  |    echo "" | ||||||
|  |    echo -e "\t[ \033[32m\033[1mInfo\033[m ]: $*" | ||||||
|  |    echo "" | ||||||
|  | } | ||||||
|  |  | ||||||
|  | echo_ok() { | ||||||
|  |    echo -e "\033[80G[ \033[32mok\033[m ]" | ||||||
|  | } | ||||||
|  | echo_failed(){ | ||||||
|  |    echo -e "\033[80G[ \033[1;31mfailed\033[m ]" | ||||||
|  | } | ||||||
|  | echo_skipped() { | ||||||
|  |    echo -e "\033[80G[ \033[33m\033[1mskipped\033[m ]" | ||||||
|  | } | ||||||
|  |  | ||||||
|  | trap clean_up SIGHUP SIGINT SIGTERM | ||||||
|  |  | ||||||
|  | ## --- | ||||||
|  | ## --- END: functions | ||||||
|  |  | ||||||
|  |  | ||||||
|  | clear | ||||||
|  | echo | ||||||
|  | echo -e "\t\033[32mSkript erstellt Verzeichnisstruktur für monatliche Bilanz\033[m" | ||||||
|  | echo | ||||||
|  | echo | ||||||
|  | echo | ||||||
|  |  | ||||||
|  | echo "" | ||||||
|  | echo -e "\033[32m--\033[m" | ||||||
|  | echo "" | ||||||
|  | echo "Für welches Jahr (JJJJ) soll die Verzeichnisstruktur erstellt werden?" | ||||||
|  | echo "" | ||||||
|  | year="" | ||||||
|  | if [[ -n "$default_year" ]] ; then | ||||||
|  |    echononl "Jahr [${default_year}]: " | ||||||
|  |    read year | ||||||
|  |    if [[ "X$year" = "X" ]]; then | ||||||
|  |       year="$default_year" | ||||||
|  |    fi | ||||||
|  | else | ||||||
|  |    echononl "Jahr [JJJJ]: " | ||||||
|  |    read year | ||||||
|  |    while [ "X$year" = "X" ] ; do | ||||||
|  |       echo -e "\n\t\033[33m\033[1mDie Angabe von 'Jahr' ist erforderlich!\033[m\n" | ||||||
|  |       echononl "Jahr [JJJJ]: " | ||||||
|  |       read year | ||||||
|  |    done | ||||||
|  | fi | ||||||
|  | year_short="$(echo ${year:${#year} - 2})" | ||||||
|  |  | ||||||
|  | echo "" | ||||||
|  | echo -e "\033[32m--\033[m" | ||||||
|  | echo "" | ||||||
|  | echo "Für welche Monat (MM) soll die Verzeichnisstruktur erstellt werden?" | ||||||
|  | echo "" | ||||||
|  | month="" | ||||||
|  | if [[ -n "$default_month" ]] ; then | ||||||
|  |    echononl "Monat [${default_month}]: " | ||||||
|  |    read month | ||||||
|  |    if [[ "X$month" = "X" ]]; then | ||||||
|  |       month="$default_month" | ||||||
|  |    fi | ||||||
|  | else | ||||||
|  |    echononl "Monat [MM]: " | ||||||
|  |    read month | ||||||
|  |    while [ "X$month" = "X" ] ; do | ||||||
|  |       echo -e "\n\t\033[33m\033[1mDie Angabe von 'Monat' ist erforderlich!\033[m\n" | ||||||
|  |       echononl "Monat [MM]: " | ||||||
|  |       read month | ||||||
|  |    done | ||||||
|  | fi | ||||||
|  |     | ||||||
|  |  | ||||||
|  | echo | ||||||
|  | echo -e "\t\033[32mErstelle die Verzeichnisstruktur für die monatlich Bilanz \033[1m${month}/${year}\033[m" | ||||||
|  | echo | ||||||
|  |  | ||||||
|  | info "Continue creating the folder structure type uppercase 'YES'" | ||||||
|  | echo -e -n "\033[1mContinue:\033[m " | ||||||
|  | read OK | ||||||
|  |  | ||||||
|  | if [[ "$OK" != "YES" ]] ; then | ||||||
|  |    fatal "Abort by user request - Answer as not 'YES'" | ||||||
|  | fi | ||||||
|  |  | ||||||
|  | echo "" | ||||||
|  | echo "" | ||||||
|  |  | ||||||
|  | echononl "Create folder '${base_dir_receipts}/$year'.." | ||||||
|  | if [[ ! -d "${base_dir_receipts}/$year" ]]; then | ||||||
|  |    mkdir "${base_dir_receipts}/$year" > $logfile 2>&1 | ||||||
|  |    if [[ $? -eq 0 ]]; then | ||||||
|  |       echo_ok | ||||||
|  |    else | ||||||
|  |       echo_failed | ||||||
|  |       error $(cat $logfile) | ||||||
|  |    fi | ||||||
|  | else | ||||||
|  |    echo_skipped | ||||||
|  | fi | ||||||
|  |  | ||||||
|  | echononl "Create folder '${base_dir_receipts}/${year}/$month'.." | ||||||
|  | if [[ ! -d "${base_dir_receipts}/${year}/$month" ]]; then | ||||||
|  |    mkdir "${base_dir_receipts}/${year}/$month"  > $logfile 2>&1 | ||||||
|  |    if [[ $? -eq 0 ]]; then | ||||||
|  |       echo_ok | ||||||
|  |    else | ||||||
|  |       echo_failed | ||||||
|  |       error $(cat $logfile) | ||||||
|  |    fi | ||||||
|  | else | ||||||
|  |    echo_skipped | ||||||
|  | fi | ||||||
|  |  | ||||||
|  | echo "" | ||||||
|  |  | ||||||
|  | echononl "Create folder '${base_dir_costs}/$year'.." | ||||||
|  | if [[ ! -d "${base_dir_costs}/$year" ]]; then | ||||||
|  |    mkdir "${base_dir_costs}/$year" > $logfile 2>&1 | ||||||
|  |    if [[ $? -eq 0 ]]; then | ||||||
|  |       echo_ok | ||||||
|  |    else | ||||||
|  |       echo_failed | ||||||
|  |       error $(cat $logfile) | ||||||
|  |    fi | ||||||
|  | else | ||||||
|  |    echo_skipped | ||||||
|  | fi | ||||||
|  |  | ||||||
|  | echononl "Create folder '${base_dir_costs}/${year}/$month'.." | ||||||
|  | if [[ ! -d "${base_dir_costs}/${year}/$month" ]]; then | ||||||
|  |    mkdir "${base_dir_costs}/${year}/$month"  > $logfile 2>&1 | ||||||
|  |    if [[ $? -eq 0 ]]; then | ||||||
|  |       echo_ok | ||||||
|  |    else | ||||||
|  |       echo_failed | ||||||
|  |       error $(cat $logfile) | ||||||
|  |    fi | ||||||
|  | else | ||||||
|  |    echo_skipped | ||||||
|  | fi | ||||||
|  |  | ||||||
|  | for _dir in $dirs_costs ; do | ||||||
|  |    echononl "Create folder '${base_dir_costs}/${year}/${month}/$_dir'.." | ||||||
|  |    if [[ ! -d "${base_dir_costs}/${year}/${month}/$_dir" ]]; then | ||||||
|  |       mkdir "${base_dir_costs}/${year}/${month}/$_dir"  > $logfile 2>&1 | ||||||
|  |       if [[ $? -eq 0 ]]; then | ||||||
|  |          echo_ok | ||||||
|  |       else | ||||||
|  |          echo_failed | ||||||
|  |          error $(cat $logfile) | ||||||
|  |       fi | ||||||
|  |    else | ||||||
|  |       echo_skipped | ||||||
|  |    fi | ||||||
|  |  | ||||||
|  |    if [[ "$_dir" = "Telekom" ]]; then | ||||||
|  |       for _dir_telekom in $dirs_costs_telekom ; do | ||||||
|  |          echononl "Create folder '${base_dir_costs}/${year}/${month}/${_dir}/$_dir_telekom'.." | ||||||
|  |          if [[ ! -d "${base_dir_costs}/${year}/${month}/${_dir}/$_dir_telekom" ]] ; then | ||||||
|  |             mkdir "${base_dir_costs}/${year}/${month}/${_dir}/$_dir_telekom"  > $logfile 2>&1 | ||||||
|  |             if [[ $? -eq 0 ]]; then | ||||||
|  |                echo_ok | ||||||
|  |             else | ||||||
|  |                echo_failed | ||||||
|  |                error $(cat $logfile) | ||||||
|  |             fi | ||||||
|  |          else | ||||||
|  |             echo_skipped | ||||||
|  |          fi | ||||||
|  |       done | ||||||
|  |    fi | ||||||
|  | done | ||||||
|  |  | ||||||
|  | echo "" | ||||||
|  | clean_up 0 | ||||||
		Reference in New Issue
	
	Block a user