158 lines
4.9 KiB
Python
Executable File
158 lines
4.9 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
"""
|
|
Maandelijkse Declaratie Helper Script
|
|
Maakt het genereren en versturen van rapporten eenvoudiger
|
|
Werkt op zowel Windows als Linux/Mac
|
|
"""
|
|
|
|
import argparse
|
|
import subprocess
|
|
import sys
|
|
import os
|
|
from datetime import datetime, timedelta
|
|
import calendar
|
|
|
|
def get_previous_month():
|
|
"""Bereken vorige maand en jaar"""
|
|
today = datetime.now()
|
|
first_day_current = today.replace(day=1)
|
|
last_month = first_day_current - timedelta(days=1)
|
|
return last_month.month, last_month.year
|
|
|
|
def show_header(month, year, email, user=None, summary=False):
|
|
"""Toon header informatie"""
|
|
print("=" * 50)
|
|
print("Maandelijkse Declaratie Generator")
|
|
print("=" * 50)
|
|
print(f"Periode: {calendar.month_name[month]} {year}")
|
|
print(f"Email: {email}")
|
|
if user:
|
|
print(f"Gebruiker: {user}")
|
|
if summary:
|
|
print("Modus: Alleen samenvatting")
|
|
print("=" * 50)
|
|
|
|
def run_command(cmd, shell=False):
|
|
"""Voer commando uit en toon output"""
|
|
try:
|
|
if os.name == 'nt': # Windows
|
|
# Op Windows, gebruik shell=True voor complexe commando's
|
|
result = subprocess.run(cmd, shell=True, capture_output=True, text=True, encoding='utf-8')
|
|
else: # Linux/Mac
|
|
result = subprocess.run(cmd, shell=shell, capture_output=True, text=True, encoding='utf-8')
|
|
|
|
if result.stdout:
|
|
print(result.stdout)
|
|
if result.stderr:
|
|
print(result.stderr, file=sys.stderr)
|
|
|
|
return result.returncode == 0
|
|
except Exception as e:
|
|
print(f"Fout bij uitvoeren commando: {e}")
|
|
return False
|
|
|
|
def main():
|
|
# Standaard waarden - vorige maand
|
|
default_month, default_year = get_previous_month()
|
|
|
|
parser = argparse.ArgumentParser(
|
|
description='Helper script voor maandelijkse declaratie rapporten',
|
|
formatter_class=argparse.RawDescriptionHelpFormatter,
|
|
epilog="""
|
|
Voorbeelden:
|
|
# Rapport vorige maand versturen
|
|
python monthly_declaration_helper.py
|
|
|
|
# Oktober 2024
|
|
python monthly_declaration_helper.py -m 10 -y 2024
|
|
|
|
# Toon rapport vorige maand op scherm
|
|
python monthly_declaration_helper.py -d
|
|
|
|
# Verstuur alleen samenvatting
|
|
python monthly_declaration_helper.py -s
|
|
|
|
# Rapport voor specifieke gebruiker
|
|
python monthly_declaration_helper.py -u 04A2CBA2C43C80
|
|
"""
|
|
)
|
|
|
|
parser.add_argument('-m', '--month', type=int, default=default_month,
|
|
choices=range(1, 13),
|
|
help=f'Maand (1-12). Standaard: {default_month} (vorige maand)')
|
|
parser.add_argument('-y', '--year', type=int, default=default_year,
|
|
help=f'Jaar. Standaard: {default_year}')
|
|
parser.add_argument('-u', '--user',
|
|
help='Filter op specifieke gebruiker/RFID tag (optioneel)')
|
|
parser.add_argument('-e', '--email', default='mark@markkors.nl',
|
|
help='Email adres (standaard: mark@markkors.nl)')
|
|
parser.add_argument('-s', '--summary', action='store_true',
|
|
help='Alleen samenvatting (geen details)')
|
|
parser.add_argument('-d', '--display', action='store_true',
|
|
help='Toon rapport op scherm (niet versturen)')
|
|
|
|
args = parser.parse_args()
|
|
|
|
# Toon header
|
|
show_header(args.month, args.year, args.email, args.user, args.summary)
|
|
|
|
# Database configuratie
|
|
db_config = {
|
|
'host': '192.168.178.201',
|
|
'port': '3307',
|
|
'user': 'steve',
|
|
'password': 'kS9R*xp17ZwCD@CV&E^N',
|
|
'price_user': 'alfen_user',
|
|
'price_password': '5uVgr%f%s2P5GR@3q!'
|
|
}
|
|
|
|
print("")
|
|
if args.display:
|
|
# Toon op scherm
|
|
print("Genereer rapport...")
|
|
|
|
cmd = [
|
|
'python', 'steve_monthly_declaration.py',
|
|
'--host', db_config['host'],
|
|
'--port', db_config['port'],
|
|
'--user', db_config['user'],
|
|
'--password', db_config['password'],
|
|
'--price-user', db_config['price_user'],
|
|
'--price-password', db_config['price_password'],
|
|
'--month', str(args.month),
|
|
'--year', str(args.year)
|
|
]
|
|
|
|
if args.user:
|
|
cmd.extend(['--user-filter', args.user])
|
|
if args.summary:
|
|
cmd.append('--summary')
|
|
|
|
success = run_command(cmd)
|
|
else:
|
|
# Verstuur per email
|
|
print("Genereer en verstuur rapport...")
|
|
|
|
cmd = [
|
|
'python', 'send_monthly_declaration.py',
|
|
'--month', str(args.month),
|
|
'--year', str(args.year),
|
|
'--email', args.email
|
|
]
|
|
|
|
if args.user:
|
|
cmd.extend(['--user', args.user])
|
|
if args.summary:
|
|
cmd.append('--summary')
|
|
|
|
success = run_command(cmd)
|
|
|
|
print("")
|
|
if success:
|
|
print("✓ Klaar!")
|
|
else:
|
|
print("✗ Er is een fout opgetreden")
|
|
sys.exit(1)
|
|
|
|
if __name__ == '__main__':
|
|
main() |