예제 #1
0
def report_year(year):
    start = date(year, 1, 1)
    end = date(year + 1, 1, 1) - relativedelta(days=1)
    date_args = "date_start=%s&date_end=%s" % (start.strftime("%Y-%m-%d"), end.strftime("%Y-%m-%d"))
    worth = obtain_worth(end)
    aggregate = Minor.listForReport(start, end)
    (income, expense) = obtain_aggregate(aggregate)
    result = Minor.listForYearlyReport(year)
    month_table = init_table()
    table = {}
    for month in xrange(1, 13):
        table[month] = copy.deepcopy(month_table)
        table[month]["income"] = 0
        table[month]["expense"] = 0
        for (major, _, _) in table[1]["majors"]:
            table[month][("major", major)] = 0
    table["total"] = {}
    table["order"] = table[1]["order"]
    table["majors"] = table[1]["majors"]
    for minor_id in table["order"]:
        table["total"][minor_id] = 0
    for (major, _, _) in table["majors"]:
        table["total"][("major", major)] = 0
    for row in result:
        (major_id, major_name, isIncome, minor_name, _) = table[row.month][row.id]
        table[row.month][row.id] = (major_id, major_name, isIncome, minor_name, row.amount)
        table[row.month]["income" if isIncome else "expense"] += row.amount
        table[row.month][("major", major_id)] += row.amount
        table["total"][row.id] += row.amount
        table["total"][("major", major_id)] += row.amount
    return render_template(
        "report.html", year=year, table=table, worth=worth, income=income, expense=expense, date_args=date_args
    )
예제 #2
0
def report_last_days(days):
    end = date.today()
    start = end - relativedelta(days=(days - 1))
    date_args = "&date_start=%s&date_end=%s" % (start.strftime("%Y-%m-%d"), end.strftime("%Y-%m-%d"))
    worth = obtain_worth(end)
    result = Minor.listForReport(start, end)
    (income, expense) = obtain_aggregate(result)
    table = simple_minor_table(result)
    return render_template(
        "report.html", days=days, table=table, worth=worth, income=income, expense=expense, date_args=date_args
    )
예제 #3
0
def report_last_days(days):
    end = date.today()
    start = end - relativedelta(days=(days - 1))
    date_args = '&date_start=%s&date_end=%s' % \
                (start.strftime('%Y-%m-%d'), end.strftime('%Y-%m-%d'))
    worth = obtain_worth(end)
    result = Minor.listForReport(start, end)
    (income, expense) = obtain_aggregate(result)
    table = simple_minor_table(result)
    return render_template('report.html',
                           days=days,
                           table=table,
                           worth=worth,
                           income=income,
                           expense=expense,
                           date_args=date_args)
예제 #4
0
def report_month(year, month):
    start = date(year, month, 1)
    end = date(year, month, 1) + relativedelta(months=1) - relativedelta(days=1)
    date_args = "&date_start=%s&date_end=%s" % (start.strftime("%Y-%m-%d"), end.strftime("%Y-%m-%d"))
    worth = obtain_worth(end)
    result = Minor.listForReport(start, end)
    (income, expense) = obtain_aggregate(result)
    table = simple_minor_table(result)
    return render_template(
        "report.html",
        year=year,
        month=date(1900, month, 1).strftime("%B"),
        table=table,
        worth=worth,
        income=income,
        expense=expense,
        date_args=date_args,
    )
예제 #5
0
def report_month(year, month):
    start = date(year, month, 1)
    end = date(year, month,
               1) + relativedelta(months=1) - relativedelta(days=1)
    date_args = '&date_start=%s&date_end=%s' % \
                (start.strftime('%Y-%m-%d'), end.strftime('%Y-%m-%d'))
    worth = obtain_worth(end)
    result = Minor.listForReport(start, end)
    (income, expense) = obtain_aggregate(result)
    table = simple_minor_table(result)
    return render_template('report.html',
                           year=year,
                           month=date(1900, month, 1).strftime('%B'),
                           table=table,
                           worth=worth,
                           income=income,
                           expense=expense,
                           date_args=date_args)
예제 #6
0
def report_year(year):
    start = date(year, 1, 1)
    end = date(year + 1, 1, 1) - relativedelta(days=1)
    date_args = 'date_start=%s&date_end=%s' % \
                (start.strftime('%Y-%m-%d'), end.strftime('%Y-%m-%d'))
    worth = obtain_worth(end)
    aggregate = Minor.listForReport(start, end)
    (income, expense) = obtain_aggregate(aggregate)
    result = Minor.listForYearlyReport(year)
    month_table = init_table()
    table = {}
    for month in xrange(1, 13):
        table[month] = copy.deepcopy(month_table)
        table[month]['income'] = 0
        table[month]['expense'] = 0
        for (major, _, _) in table[1]['majors']:
            table[month][('major', major)] = 0
    table['total'] = {}
    table['order'] = table[1]['order']
    table['majors'] = table[1]['majors']
    for minor_id in table['order']:
        table['total'][minor_id] = 0
    for (major, _, _) in table['majors']:
        table['total'][('major', major)] = 0
    for row in result:
        (major_id, major_name, isIncome, minor_name,
         _) = table[row.month][row.id]
        table[row.month][row.id] = (major_id, major_name, isIncome, minor_name,
                                    row.amount)
        table[row.month]['income' if isIncome else 'expense'] += row.amount
        table[row.month][('major', major_id)] += row.amount
        table['total'][row.id] += row.amount
        table['total'][('major', major_id)] += row.amount
    return render_template('report.html',
                           year=year,
                           table=table,
                           worth=worth,
                           income=income,
                           expense=expense,
                           date_args=date_args)