Example #1
0
def berechne_order_typ(dauerauftrag_order):
    order_gesamt_raw = persisted_state.database_instance().order.content.copy()
    order_summe = get_wert_sum(order_gesamt_raw)
    dauerauftrag_order = get_wert_sum(dauerauftrag_order)

    return {
        'manual': from_double_to_german(order_summe - dauerauftrag_order),
        'dauerauftrag': from_double_to_german(dauerauftrag_order),
        'manual_raw': '%.2f' % (order_summe - dauerauftrag_order),
        'dauerauftrag_raw': '%.2f' % dauerauftrag_order
    }
def berechne_monatlich():
    aktuelle_dauerauftraege = persisted_state.database_instance().orderdauerauftrag.aktuelle_raw().copy()
    aktuelle_dauerauftraege = aktuelle_dauerauftraege[aktuelle_dauerauftraege.Wert > 0]

    isins = set(aktuelle_dauerauftraege.Depotwert.tolist())

    namen = []
    colors = []
    werte = []
    monatlich = []
    color_chooser = viewcore.get_generic_color_chooser(list(sorted(isins)))

    for isin in sorted(isins):
        name = persisted_state.database_instance().depotwerte.get_description_for(isin)
        wert = get_sum(aktuelle_dauerauftraege[aktuelle_dauerauftraege.Depotwert == isin])
        color = color_chooser.get_for_value(isin)

        namen.append(name)
        werte.append('%.2f' % wert)
        colors.append(color)
        monatlich.append({
            'name': name,
            'wert': from_double_to_german(wert),
            'color': color
        })

    return {
        'einzelwerte': monatlich,
        'colors': colors,
        'namen': namen,
        'werte': werte
    }
def _handle_request(request):
    depotwerte = persisted_state.database_instance().depotwerte
    order = persisted_state.database_instance().order
    depotauszuege = persisted_state.database_instance().depotauszuege

    if post_action_is(request, 'delete'):
        depotwerte.delete(int(request.values['delete_index']))
        return request_handler.create_redirect_context(
            '/uebersicht_depotwerte/')

    db = depotwerte.get_all()
    depotwerte_liste = []
    gesamt_buchungen = 0
    gesamt_wert = 0

    for row_index, row in db.iterrows():
        isin = row.ISIN
        buchungen = order.get_order_fuer_depotwert(isin)
        wert = depotauszuege.get_depotwert_by(isin)
        differenz = wert - buchungen
        typ = row.Typ

        depotwerte_liste.append({
            'index': row_index,
            'name': row.Name,
            'isin': isin,
            'typ': typ,
            'buchung': from_double_to_german(buchungen),
            'difference': from_double_to_german(differenz),
            'difference_is_negativ': differenz < 0,
            'wert': from_double_to_german(wert)
        })
        gesamt_buchungen += buchungen
        gesamt_wert += wert

    gesamt_difference = gesamt_wert - gesamt_buchungen
    gesamt = {
        'wert': from_double_to_german(gesamt_wert),
        'difference': from_double_to_german(gesamt_difference),
        'difference_is_negativ': gesamt_difference < 0,
        'buchung': from_double_to_german(gesamt_buchungen)
    }

    context = viewcore.generate_transactional_context('uebersicht_depotwerte')
    context['depotwerte'] = depotwerte_liste
    context['gesamt'] = gesamt
    return context
def _handle_request(request):
    sparbuchungen = persisted_state.database_instance().sparbuchungen
    if post_action_is(request, 'delete'):
        sparbuchungen.delete(int(request.values['delete_index']))
        return request_handler.create_redirect_context(
            '/uebersicht_sparbuchungen/')

    db = sparbuchungen.get_all()
    sparbuchungen_monatlich = {}
    datum_alt = None
    sparbuchungen_liste = []
    for row_index, row in db.iterrows():
        if not datum_alt:
            datum_alt = row.Datum
        if datum_alt.month != row.Datum.month or datum_alt.year != row.Datum.year:
            sparbuchungen_monatlich["" + str(datum_alt.year) + "." +
                                    str(datum_alt.month)] = sparbuchungen_liste
            sparbuchungen_liste = []
            datum_alt = row.Datum

        sparbuchungen_liste.append({
            'index': row_index,
            'datum': datum_to_german(row.Datum),
            'name': row.Name,
            'konto': row.Konto,
            'wert': from_double_to_german(row.Wert),
            'typ': row.Typ,
            'dynamisch': row.Dynamisch
        })

    if datum_alt:
        sparbuchungen_monatlich["" + str(datum_alt.year) + "." +
                                str(datum_alt.month)] = sparbuchungen_liste

    context = viewcore.generate_transactional_context(
        'uebersicht_sparbuchungen')
    context['alles'] = sparbuchungen_monatlich
    return context
def _handle_request(request):
    order = persisted_state.database_instance().order
    depotwerte = persisted_state.database_instance().depotwerte

    if post_action_is(request, 'delete'):
        order.delete(int(request.values['delete_index']))
        return request_handler.create_redirect_context('/uebersicht_order/')

    db = order.get_all()
    order_liste = []
    for row_index, row in db.iterrows():
        if row.Wert > 0:
            typ = TYP_KAUF
        else:
            typ = TYP_VERKAUF

        order_liste.append({
            'index':
            row_index,
            'Datum':
            datum_to_german(row.Datum),
            'Name':
            row.Name,
            'Konto':
            row.Konto,
            'Typ':
            typ,
            'Depotwert':
            depotwerte.get_description_for(row.Depotwert),
            'Wert':
            from_double_to_german(abs(row.Wert)),
            'Dynamisch':
            row.Dynamisch
        })

    context = viewcore.generate_transactional_context('uebersicht_order')
    context['order'] = order_liste
    return context
def _handle_request(request):
    einzelbuchungen = persisted_state.database_instance().einzelbuchungen
    if post_action_is(request, 'delete'):
        einzelbuchungen.delete(int(request.values['delete_index']))
        return request_handler.create_redirect_context('/uebersicht/')

    db = einzelbuchungen.get_all()
    ausgaben_monatlich = {}
    datum_alt = None
    ausgaben_liste = []
    for row_index, row in db.iterrows():
        if not datum_alt:
            datum_alt = row.Datum
        if datum_alt.month != row.Datum.month or datum_alt.year != row.Datum.year:
            ausgaben_monatlich["" + str(datum_alt.year) + "." + str(datum_alt.month)] = ausgaben_liste
            ausgaben_liste = []
            datum_alt = row.Datum

        link = 'addeinnahme'
        if row.Wert < 0:
            link = 'addausgabe'
        ausgaben_liste.append({
            'index': row_index,
            'datum': datum_to_german(row.Datum),
            'name': row.Name,
            'kategorie': row.Kategorie,
            'wert': from_double_to_german(row.Wert),
            'dynamisch': row.Dynamisch,
            'link': link,
            'tags': str(row.Tags)})

    if datum_alt:
        ausgaben_monatlich["" + str(datum_alt.year) + "." + str(datum_alt.month)] = ausgaben_liste

    context = viewcore.generate_transactional_context('uebersicht')
    context['alles'] = ausgaben_monatlich
    return context
Example #7
0
def _handle_request(request):
    sparkontos = persisted_state.database_instance().sparkontos
    if post_action_is(request, 'delete'):
        sparkontos.delete(int(request.values['delete_index']))
        return request_handler.create_redirect_context(
            '/uebersicht_sparkontos/')

    db = sparkontos.get_all()

    gesamt_kontostand = 0
    gesamt_aufbuchungen = 0
    sparkonto_liste = []

    for row_index, row in db.iterrows():
        aktueller_kontostand = 0
        aufbuchungen = 0

        kontoname = row.Kontoname
        kontotyp = row.Kontotyp

        if kontotyp == sparkontos.TYP_SPARKONTO or kontotyp == sparkontos.TYP_GENOSSENSCHAFTSANTEILE:
            aktueller_kontostand = persisted_state.database_instance(
            ).sparbuchungen.get_kontostand_fuer(kontoname)
            aufbuchungen = persisted_state.database_instance(
            ).sparbuchungen.get_aufbuchungen_fuer(kontoname)

        if kontotyp == sparkontos.TYP_DEPOT:
            aufbuchungen = persisted_state.database_instance(
            ).order.get_order_fuer(kontoname)
            aktueller_kontostand = persisted_state.database_instance(
            ).depotauszuege.get_kontostand_by(kontoname)

        gesamt_kontostand += aktueller_kontostand
        gesamt_aufbuchungen += aufbuchungen

        diff = aktueller_kontostand - aufbuchungen

        sparkonto_liste.append({
            'index':
            row_index,
            'kontoname':
            kontoname,
            'kontotyp':
            kontotyp,
            'wert':
            from_double_to_german(aktueller_kontostand),
            'difference':
            from_double_to_german(diff),
            'aufbuchungen':
            from_double_to_german(aufbuchungen),
            'difference_is_negativ':
            diff < 0
        })

    gesamt_diff = gesamt_kontostand - gesamt_aufbuchungen

    gesamt = {
        'wert': from_double_to_german(gesamt_kontostand),
        'difference': from_double_to_german(gesamt_diff),
        'aufbuchungen': from_double_to_german(gesamt_aufbuchungen),
        'difference_is_negativ': gesamt_diff < 0
    }

    context = viewcore.generate_transactional_context('uebersicht_sparkontos')
    context['sparkontos'] = sparkonto_liste
    context['gesamt'] = gesamt
    return context
Example #8
0
def handle_request(request):
    if not database_instance().sparkontos.get_depots():
        return viewcore.generate_error_context('add_depotauszug', NO_VALID_DEPOT_IN_DB)

    if not database_instance().depotwerte.get_depotwerte():
        return viewcore.generate_error_context('add_depotauszug', NO_VALID_SHARE_IN_DB)

    if post_action_is(request, 'add'):
        current_date = None
        for element in request.values:
            if element.startswith('datum_'):
                current_date = datum(request.values[element])
        if not current_date:
            return viewcore.generate_error_context('add_depotauszug', 'Interner Fehler <Kein Datum gefunden>.')
        konto = request.values['konto']

        if "edit_index" in request.values:
            for element in request.values:
                if element.startswith(KEY_WERT):
                    depotwert = element.split('_')[-1]
                    db_index = database_instance().depotauszuege.resolve_index(current_date, konto, depotwert)
                    value = request.values[element].replace(",", ".")
                    value = float(value)

                    if db_index is not None:
                        database_instance().depotauszuege.edit(db_index,
                                                               datum=current_date,
                                                               depotwert=depotwert,
                                                               wert="%.2f" % value,
                                                               konto=konto)
                        non_persisted_state.add_changed_depotauszuege(
                            {
                                'fa': 'pencil',
                                'datum': datum_to_german(current_date),
                                'wert': from_double_to_german(value),
                                'depotwert': depotwert,
                                'konto': konto
                            })
                    else:
                        database_instance().depotauszuege.add(datum=current_date,
                                                              depotwert=depotwert,
                                                              wert="%.2f" % value,
                                                              konto=konto)
                        non_persisted_state.add_changed_depotauszuege(
                            {
                                'fa': 'plus',
                                'datum': datum_to_german(current_date),
                                'wert': from_double_to_german(value),
                                'depotwert': depotwert,
                                'konto': konto
                            })


        else:

            result = database_instance().depotauszuege.get_by(current_date, konto)
            if len(result) > 0:
                return viewcore.generate_error_context('add_depotauszug',
                                                       'Für es besteht bereits ein Kontoauszug für {} am {}'.format(
                                                           konto,
                                                           datum_to_german(current_date)))

            for element in request.values:
                if element.startswith(KEY_WERT):
                    depotwert = element.split('_')[-1]
                    value = request.values[element].replace(",", ".")
                    value = float(value)

                    if value == 0 and not database_instance().depotauszuege.exists_wert(konto, depotwert):
                        continue

                    database_instance().depotauszuege.add(datum=current_date,
                                                          depotwert=depotwert,
                                                          wert="%.2f" % value,
                                                          konto=konto)
                    non_persisted_state.add_changed_depotauszuege(
                        {
                            'fa': 'plus',
                            'datum': datum_to_german(current_date),
                            'wert': from_double_to_german(value),
                            'depotwert': depotwert,
                            'konto': konto
                            })

    context = viewcore.generate_transactional_context('add_depotauszug')
    context['approve_title'] = 'Depotauszug hinzufügen'

    depotwerte = database_instance().depotwerte.get_depotwerte_descriptions()
    if post_action_is(request, 'edit'):
        print("Please edit:", request.values['edit_index'])
        db_index = int(request.values['edit_index'])
        db_row = database_instance().depotauszuege.get(db_index)

        edit_datum = db_row['Datum']
        edit_konto = db_row['Konto']
        db_row = database_instance().depotauszuege.get_by(edit_datum, edit_konto)

        filled_items = calculate_filled_items(db_row, depotwerte)
        empty_items = calculate_empty_items(depotwerte, filled_items)

        default_item = [{
            'datum': datum_to_string(edit_datum),
            'konto': edit_konto,
            'filled_items': filled_items,
            'empty_items': empty_items
        }]

        context['default_items'] = default_item
        context['bearbeitungsmodus'] = True
        context['edit_index'] = db_index
        context['approve_title'] = 'Depotauszug aktualisieren'

    if 'default_items' not in context:
        context['default_items'] = []
        for konto in database_instance().sparkontos.get_depots():
            default_datum = database_instance().depotauszuege.get_latest_datum_by(konto)
            if not default_datum:
                default_datum = date.today()

            db_row = database_instance().depotauszuege.get_by(default_datum, konto)

            filled_items = calculate_filled_items(db_row, depotwerte)
            empty_items = calculate_empty_items(depotwerte, filled_items)

            if len(filled_items) == 0:
                filled_items = empty_items
                empty_items = []

            default_item = {
                'datum': datum_to_string(date.today()),
                'konto': konto,
                'filled_items': filled_items,
                'empty_items': empty_items
            }
            context['default_items'].append(default_item)

    context['letzte_erfassung'] = reversed(non_persisted_state.get_changed_depotauszuege())
    return context
Example #9
0
def handle_request(request):
    context = viewcore.generate_transactional_context('addeinzelbuchung')
    context['element_titel'] = 'Neue Ausgabe'
    context['approve_title'] = 'Ausgabe hinzufügen'
    einzelbuchungen = persisted_state.database_instance().einzelbuchungen

    if post_action_is(request, 'add'):
        value = dezimal_float(request.values['wert']) * -1
        if 'edit_index' in request.values:
            database_index = int(request.values['edit_index'])
            datum_object = datum(request.values['date'])
            einzelbuchungen.edit(database_index, datum_object,
                                 request.values['kategorie'],
                                 request.values['name'], value)
            non_persisted_state.add_changed_einzelbuchungen({
                'fa':
                'pencil',
                'datum':
                datum_to_german(datum_object),
                'kategorie':
                request.values['kategorie'],
                'name':
                request.values['name'],
                'wert':
                from_double_to_german(value)
            })
        else:
            datum_object = datum(request.values['date'])
            einzelbuchungen.add(datum_object, request.values['kategorie'],
                                request.values['name'], value)

            non_persisted_state.add_changed_einzelbuchungen({
                'fa':
                'plus',
                'datum':
                datum_to_german(datum_object),
                'kategorie':
                request.values['kategorie'],
                'name':
                request.values['name'],
                'wert':
                from_double_to_german(value)
            })

    if post_action_is(request, 'edit'):
        db_index = int(request.values['edit_index'])

        selected_item = einzelbuchungen.get(db_index)
        selected_item['Datum'] = datum_to_string(selected_item['Datum'])
        selected_item['Wert'] = from_double_to_german(selected_item['Wert'] *
                                                      -1)
        context['default_item'] = selected_item

        context['bearbeitungsmodus'] = True
        context['edit_index'] = db_index
        context['set_kategorie'] = True
        context['element_titel'] = 'Einzelbuchung bearbeiten'
        context['active_name'] = 'Einzelbuchung bearbeiten'
        context['approve_title'] = 'Ausgabe aktualisieren'

    if 'default_item' not in context:
        context['default_item'] = {
            'Name': '',
            'Datum': '',
            'Wert': '',
        }

    context['kategorien'] = sorted(
        einzelbuchungen.get_kategorien_ausgaben(
            hide_ausgeschlossene_kategorien=True))
    context['letzte_erfassung'] = reversed(
        non_persisted_state.get_changed_einzelbuchungen())
    return context
Example #10
0
def handle_request(request):
    if request.method == 'POST' and request.values['action'] == 'add':
        value = dezimal_float(request.values['wert'])
        if request.values['typ'] == TYP_AUSGABE:
            value = value * -1

        if 'edit_index' in request.values:
            startdatum = datum(request.values['startdatum'])
            endedatum = datum(request.values['endedatum'])
            database_instance().dauerauftraege.edit(
                int(request.values['edit_index']), startdatum, endedatum,
                request.values['kategorie'], request.values['name'],
                request.values['rhythmus'], value)
            non_persisted_state.add_changed_dauerauftraege({
                'fa':
                'pencil',
                'startdatum':
                datum_to_german(startdatum),
                'endedatum':
                datum_to_german(endedatum),
                'kategorie':
                request.values['kategorie'],
                'name':
                request.values['name'],
                'rhythmus':
                request.values['rhythmus'],
                'wert':
                from_double_to_german(value)
            })
        else:
            startdatum = datum(request.values['startdatum'])
            endedatum = datum(request.values['endedatum'])
            database_instance().dauerauftraege.add(startdatum, endedatum,
                                                   request.values['kategorie'],
                                                   request.values['name'],
                                                   request.values['rhythmus'],
                                                   value)
            non_persisted_state.add_changed_dauerauftraege({
                'fa':
                'plus',
                'startdatum':
                datum_to_german(startdatum),
                'endedatum':
                datum_to_german(endedatum),
                'kategorie':
                request.values['kategorie'],
                'name':
                request.values['name'],
                'rhythmus':
                request.values['rhythmus'],
                'wert':
                from_double_to_german(value)
            })

    context = viewcore.generate_transactional_context('adddauerauftrag')
    context['approve_title'] = 'Dauerauftrag hinzufügen'

    if post_action_is(request, 'edit'):
        db_index = int(request.values['edit_index'])
        default_item = database_instance().dauerauftraege.get(db_index)
        default_item['Startdatum'] = datum_to_string(
            default_item['Startdatum'])
        default_item['Endedatum'] = datum_to_string(default_item['Endedatum'])
        default_item['Rhythmus'] = default_item['Rhythmus']

        if default_item['Wert'] < 0:
            default_item['typ'] = TYP_AUSGABE
        else:
            default_item['typ'] = TYPE_EINNAHME

        default_item['Wert'] = from_double_to_german(abs(default_item['Wert']))

        context['default_item'] = default_item
        context['bearbeitungsmodus'] = True
        context['edit_index'] = db_index
        context['approve_title'] = 'Dauerauftrag aktualisieren'
        context['element_titel'] = 'Dauerauftrag bearbeiten'
        context['active_name'] = 'Dauerauftrag bearbeiten'

    if 'default_item' not in context:
        context['default_item'] = {
            'Startdatum': '',
            'Endedatum': '',
            'typ': TYP_AUSGABE,
            'Rhythmus': ALL_FREQUENCY_NAMES[0],
            'Wert': '',
            'Name': ''
        }

    context['kategorien'] = sorted(
        database_instance().einzelbuchungen.get_alle_kategorien(
            hide_ausgeschlossene_kategorien=True))
    context['letzte_erfassung'] = reversed(
        non_persisted_state.get_changed_dauerauftraege())
    context['rhythmen'] = ALL_FREQUENCY_NAMES

    return context
Example #11
0
def handle_request(request):
    if not database_instance().sparkontos.get_sparfaehige_kontos():
        return viewcore.generate_error_context('add_sparbuchung',
                                               NO_VALID_SAVINGS_ACCOUNT_IN_DB)

    if post_action_is(request, 'add'):
        date = datum(request.values['datum'])
        value = request.values['wert'].replace(",", ".")
        value = float(value)

        if request.values[EIGENSCHAFT] == EIGENSCHAFT_AUSZAHLUNG:
            value = value * -1

        if "edit_index" in request.values:
            database_instance().sparbuchungen.edit(
                int(request.values['edit_index']),
                datum=date,
                name=request.values['name'],
                wert="%.2f" % value,
                typ=request.values['typ'],
                konto=request.values['konto'])
            non_persisted_state.add_changed_sparbuchungen({
                'fa':
                'pencil',
                'datum':
                datum_to_german(date),
                'wert':
                from_double_to_german(value),
                'name':
                request.values['name'],
                'typ':
                request.values['typ'],
                'konto':
                request.values['konto']
            })

        else:
            database_instance().sparbuchungen.add(
                datum=date,
                name=request.values['name'],
                wert="%.2f" % value,
                typ=request.values['typ'],
                konto=request.values['konto'])
            non_persisted_state.add_changed_sparbuchungen({
                'fa':
                'plus',
                'datum':
                datum_to_german(date),
                'wert':
                from_double_to_german(value),
                'name':
                request.values['name'],
                'typ':
                request.values['typ'],
                'konto':
                request.values['konto']
            })

    context = viewcore.generate_transactional_context('add_sparbuchung')
    context['approve_title'] = 'Sparbuchung hinzufügen'
    if post_action_is(request, 'edit'):
        print("Please edit:", request.values['edit_index'])
        db_index = int(request.values['edit_index'])
        db_row = database_instance().sparbuchungen.get(db_index)

        if db_row['Wert'] > 0:
            eigenschaft = EIGENSCHAFT_EINZAHLUNG
        else:
            eigenschaft = EIGENSCHAFT_AUSZAHLUNG

        default_item = {
            'edit_index': str(db_index),
            'datum': datum_to_string(db_row['Datum']),
            'name': db_row['Name'],
            'wert': from_double_to_german(abs(db_row['Wert'])),
            'typ': db_row['Typ'],
            'eigenschaft': eigenschaft,
            'konto': db_row['Konto']
        }

        context['default_item'] = default_item
        context['bearbeitungsmodus'] = True
        context['edit_index'] = db_index
        context['approve_title'] = 'Sparbuchung aktualisieren'

    if 'default_item' not in context:
        context['default_item'] = {
            'name': '',
            'wert': '',
            'datum': '',
            'typ': '',
            'konto': ''
        }

    context['kontos'] = database_instance().sparkontos.get_sparfaehige_kontos()
    context['typen'] = database_instance().sparbuchungen.AUFTRAGS_TYPEN
    context[EIGENSCHAFTEN] = [EIGENSCHAFT_EINZAHLUNG, EIGENSCHAFT_AUSZAHLUNG]
    context['letzte_erfassung'] = reversed(
        non_persisted_state.get_changed_sparbuchungen())
    return context
Example #12
0
def handle_request(request):
    if not database_instance().sparkontos.get_depots():
        return viewcore.generate_error_context('add_order',
                                               NO_VALID_DEPOT_IN_DB)

    if not database_instance().depotwerte.get_depotwerte():
        return viewcore.generate_error_context('add_order',
                                               NO_VALID_SHARE_IN_DB)

    if post_action_is(request, 'add'):
        date = datum(request.values['datum'])
        value = request.values['wert'].replace(",", ".")
        value = float(value)

        if request.values[TYP] == TYP_VERKAUF:
            value = value * -1

        if "edit_index" in request.values:
            database_instance().order.edit(
                int(request.values['edit_index']),
                datum=date,
                name=request.values['name'],
                wert="%.2f" % value,
                depotwert=request.values['depotwert'],
                konto=request.values['konto'])
            non_persisted_state.add_changed_order({
                'fa':
                'pencil',
                'datum':
                datum_to_german(date),
                'wert':
                from_double_to_german(abs(value)),
                'name':
                request.values['name'],
                TYP:
                request.values[TYP],
                'depotwert':
                request.values['depotwert'],
                'konto':
                request.values['konto']
            })

        else:
            database_instance().order.add(
                datum=date,
                name=request.values['name'],
                wert="%.2f" % value,
                depotwert=request.values['depotwert'],
                konto=request.values['konto'])
            non_persisted_state.add_changed_order({
                'fa':
                'plus',
                'datum':
                datum_to_german(date),
                'wert':
                from_double_to_german(value),
                'name':
                request.values['name'],
                TYP:
                request.values[TYP],
                'value':
                '%.2f' % abs(value),
                'depotwert':
                request.values['depotwert'],
                'konto':
                request.values['konto']
            })

    context = viewcore.generate_transactional_context('add_order')
    context['approve_title'] = 'Order hinzufügen'
    if post_action_is(request, 'edit'):
        print("Please edit:", request.values['edit_index'])
        db_index = int(request.values['edit_index'])
        db_row = database_instance().order.get(db_index)

        if db_row['Wert'] > 0:
            typ = TYP_KAUF
        else:
            typ = TYP_VERKAUF

        default_item = {
            'edit_index': str(db_index),
            'datum': datum_to_string(db_row['Datum']),
            'name': db_row['Name'],
            'wert': from_double_to_german(abs(db_row['Wert'])),
            'depotwert': db_row['Depotwert'],
            'typ': typ,
            'konto': db_row['Konto']
        }

        context['default_item'] = default_item
        context['bearbeitungsmodus'] = True
        context['edit_index'] = db_index
        context['approve_title'] = 'Order aktualisieren'

    if 'default_item' not in context:
        context['default_item'] = {
            'name': '',
            'wert': '',
            'datum': '',
            'depotwert': '',
            'konto': ''
        }

    context['kontos'] = database_instance().sparkontos.get_depots()
    context[TYPEN] = [TYP_KAUF, TYP_VERKAUF]
    context['depotwerte'] = database_instance(
    ).depotwerte.get_depotwerte_descriptions()
    context['letzte_erfassung'] = reversed(
        non_persisted_state.get_changed_order())
    return context
Example #13
0
def handle_request(request):
    if post_action_is(request, 'add'):
        date = datum(request.values['date'])
        value = request.values['wert'].replace(",", ".")
        value = float(value)
        value = value * -1
        if "edit_index" in request.values:
            database_instance().gemeinsamebuchungen.edit(
                int(request.values['edit_index']),
                datum=date,
                name=str(request.values['name']),
                kategorie=request.values['kategorie'],
                wert=value,
                person=request.values['person'])
            non_persisted_state.add_changed_gemeinsamebuchungen({
                'fa':
                'pencil',
                'datum':
                datum_to_german(date),
                'kategorie':
                request.values['kategorie'],
                'name':
                request.values['name'],
                'wert':
                from_double_to_german(value),
                'person':
                request.values['person']
            })

        else:
            database_instance().gemeinsamebuchungen.add(
                ausgaben_datum=date,
                kategorie=request.values['kategorie'],
                ausgaben_name=request.values['name'],
                wert="%.2f" % value,
                person=request.values['person'])
            non_persisted_state.add_changed_gemeinsamebuchungen({
                'fa':
                'plus',
                'datum':
                datum_to_german(date),
                'kategorie':
                request.values['kategorie'],
                'name':
                request.values['name'],
                'wert':
                from_double_to_german(value),
                'person':
                request.values['person']
            })

    context = viewcore.generate_transactional_context("addgemeinsam")
    context['approve_title'] = 'Gemeinsame Ausgabe hinzufügen'
    if post_action_is(request, 'edit'):
        print("Please edit:", request.values['edit_index'])
        db_index = int(request.values['edit_index'])
        db_row = database_instance().gemeinsamebuchungen.get(db_index)
        default_item = {
            'edit_index': str(db_index),
            'datum': datum_to_string(db_row['Datum']),
            'name': db_row['Name'],
            'wert': from_double_to_german(db_row['Wert'] * -1),
            'kategorie': db_row['Kategorie'],
            'person': db_row['Person']
        }

        context['default_item'] = default_item
        context['bearbeitungsmodus'] = True
        context['edit_index'] = db_index
        context['approve_title'] = 'Gemeinsame Ausgabe aktualisieren'

    if 'default_item' not in context:
        context['default_item'] = {'name': '', 'wert': '', 'datum': ''}

    context['personen'] = [
        database_instance().name,
        viewcore.name_of_partner()
    ]
    context['kategorien'] = sorted(
        database_instance().einzelbuchungen.get_kategorien_ausgaben(
            hide_ausgeschlossene_kategorien=True))
    context['letzte_erfassung'] = reversed(
        non_persisted_state.get_changed_gemeinsamebuchungen())
    return context
Example #14
0
def generate_konto_uebersicht(color_kontos, color_typen):
    sparkontos = persisted_state.database_instance().sparkontos

    gesamt_kontostand = 0
    gesamt_aufbuchungen = 0
    sparkonto_liste = []

    kontotypen_werte = dict.fromkeys(sparkontos.KONTO_TYPEN, 0)
    for typ in kontotypen_werte:
        kontotypen_werte[typ] = {'gesamt': 0, 'aufbuchungen': 0}

    db = sparkontos.get_all()
    for row_index, row in db.iterrows():
        aktueller_kontostand = 0
        aufbuchungen = 0

        kontoname = row.Kontoname
        kontotyp = row.Kontotyp

        if kontotyp == sparkontos.TYP_SPARKONTO or kontotyp == sparkontos.TYP_GENOSSENSCHAFTSANTEILE:
            aktueller_kontostand = persisted_state.database_instance(
            ).sparbuchungen.get_kontostand_fuer(kontoname)
            aufbuchungen = persisted_state.database_instance(
            ).sparbuchungen.get_aufbuchungen_fuer(kontoname)

        if kontotyp == sparkontos.TYP_DEPOT:
            aufbuchungen = persisted_state.database_instance(
            ).order.get_order_fuer(kontoname)
            aktueller_kontostand = persisted_state.database_instance(
            ).depotauszuege.get_kontostand_by(kontoname)

        gesamt_kontostand += aktueller_kontostand
        gesamt_aufbuchungen += aufbuchungen

        diff = aktueller_kontostand - aufbuchungen

        kontotypen_werte[kontotyp]['gesamt'] += aktueller_kontostand
        kontotypen_werte[kontotyp]['aufbuchungen'] += aufbuchungen

        sparkonto_liste.append({
            'index':
            row_index,
            'color':
            color_kontos.get_for_value(kontoname),
            'name':
            kontoname,
            'kontotyp':
            kontotyp,
            'wert':
            aktueller_kontostand,
            'difference':
            diff,
            'aufbuchungen':
            aufbuchungen,
            'wert_str':
            from_double_to_german(aktueller_kontostand),
            'difference_str':
            from_double_to_german(diff),
            'aufbuchungen_str':
            from_double_to_german(aufbuchungen),
            'difference_is_negativ':
            diff < 0
        })

    kontotypen_liste = []
    for kontotyp in kontotypen_werte:
        diff = kontotypen_werte[kontotyp]['gesamt'] - kontotypen_werte[
            kontotyp]['aufbuchungen']
        kontotypen_liste.append({
            'name':
            kontotyp,
            'color':
            color_typen.get_for_value(kontotyp),
            'wert':
            kontotypen_werte[kontotyp]['gesamt'],
            'wert_str':
            from_double_to_german(kontotypen_werte[kontotyp]['gesamt']),
            'aufbuchungen':
            kontotypen_werte[kontotyp]['aufbuchungen'],
            'aufbuchungen_str':
            from_double_to_german(kontotypen_werte[kontotyp]['aufbuchungen']),
            'difference':
            diff,
            'difference_str':
            from_double_to_german(diff)
        })

    gesamt_diff = gesamt_kontostand - gesamt_aufbuchungen

    gesamt = {
        'wert': gesamt_kontostand,
        'difference': gesamt_diff,
        'aufbuchungen': gesamt_aufbuchungen,
        'wert_str': from_double_to_german(gesamt_kontostand),
        'difference_str': from_double_to_german(gesamt_diff),
        'aufbuchungen_str': from_double_to_german(gesamt_aufbuchungen),
        'difference_is_negativ': gesamt_diff < 0
    }
    return gesamt, sparkonto_liste, kontotypen_liste
Example #15
0
def gesamt_uebersicht():
    einzelbuchungen = persisted_state.database_instance().einzelbuchungen
    sparkontos = persisted_state.database_instance().sparkontos
    min_jahr = einzelbuchungen.content.copy()[
        einzelbuchungen.content.copy().Kategorie != 'Sparen'].Datum.min().year
    max_jahr = date.today().year

    year_kontostaende = []

    gesamt_uebersicht = []
    for jahr in range(min_jahr, max_jahr + 1):
        buchungen_jahr = einzelbuchungen.select().select_year(
            jahr).content.copy()
        ausgaben = buchungen_jahr[buchungen_jahr.Wert < 0].copy()
        ausgaben = ausgaben[ausgaben.Kategorie != 'Sparen'].Wert.sum()
        einnahmen = buchungen_jahr[buchungen_jahr.Wert > 0].copy()
        einnahmen = einnahmen[einnahmen.Kategorie != 'Sparen'].Wert.sum()

        db = sparkontos.get_all()

        sparen_aufbuchung = 0
        gesamt_sparen = 0

        year_kontos = {}

        for row_index, row in db.iterrows():
            kontostand = 0
            aufbuchungen = 0

            sparbuchungen_year = persisted_state.database_instance(
            ).sparbuchungen.select_year(jahr)
            sparbuchungen_max_year = persisted_state.database_instance(
            ).sparbuchungen.select_max_year(jahr)
            depotauszuege_year = persisted_state.database_instance(
            ).depotauszuege.select_max_year(jahr)
            order_year = persisted_state.database_instance().order.select_year(
                jahr)

            kontoname = row.Kontoname
            kontotyp = row.Kontotyp

            if kontotyp == sparkontos.TYP_SPARKONTO or kontotyp == sparkontos.TYP_GENOSSENSCHAFTSANTEILE:
                kontostand = sparbuchungen_max_year.get_kontostand_fuer(
                    kontoname)
                aufbuchungen = sparbuchungen_year.get_aufbuchungen_fuer(
                    kontoname)

            if kontotyp == sparkontos.TYP_DEPOT:
                aufbuchungen = order_year.get_order_fuer(kontoname)
                kontostand = depotauszuege_year.get_kontostand_by(kontoname)

            year_kontos[kontoname] = {
                'kontostand': kontostand,
                'kontostand_str': from_double_to_german(kontostand),
                'aufbuchungen': aufbuchungen,
                'aufbuchungen_str': from_double_to_german(aufbuchungen),
                'name': kontoname
            }

            gesamt_sparen += kontostand
            sparen_aufbuchung += aufbuchungen

        year_kontos['Gesamt'] = {
            'kontostand': gesamt_sparen,
            'aufbuchungen': sparen_aufbuchung,
            'kontostand_str': from_double_to_german(gesamt_sparen),
            'aufbuchungen_str': from_double_to_german(sparen_aufbuchung),
            'name': 'Gesamt'
        }

        year_kontostaende.append(year_kontos)

        gesamt_uebersicht.append({
            'jahr': jahr,
            'ausgaben': ausgaben,
            'einnahmen': einnahmen,
            'sparen_aufbuchung': sparen_aufbuchung,
            'gesamt_sparen': gesamt_sparen,
        })

    return gesamt_uebersicht, year_kontostaende