Пример #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 major_detail(id):
    major = get_object_or_404(Major, Major.id == id)
    minors = Minor.listWithStats(id)
    num_items = 0
    for minor in minors:
        num_items += minor.count
    return render_template('major.html', 
            major=major, minors=minors, num_items=num_items)
Пример #3
0
def minor_edit(id):
    try:
        minor = Minor.get(Minor.id == id)
        minor.name = request.form['name']
        minor.major = request.form['major_id']
        minor.save()
    except:
        return jsonify(success=False)
    return jsonify(success=True)
Пример #4
0
def minor_edit(id):
    try:
        minor = Minor.get(Minor.id == id)
        minor.name = request.form['name']
        minor.major = request.form['major_id']
        minor.save()
    except:
        return jsonify(success=False)
    return jsonify(success=True)
Пример #5
0
def minor_add():
    try:
        major_id = request.form['major_id']
        major = get_object_or_404(Major, Major.id == major_id)
        minor = Minor.create(name=request.form['name'], major=major)
    except:
        flash('Category #%d not found.' % major_id, 'danger')
        return jsonify(success=False)
    flash('A new subcategory is added.', 'success')
    return jsonify(success=True)
Пример #6
0
def major_detail(id):
    major = get_object_or_404(Major, Major.id == id)
    minors = Minor.listWithStats(id)
    num_items = 0
    for minor in minors:
        num_items += minor.count
    return render_template('major.html',
                           major=major,
                           minors=minors,
                           num_items=num_items)
Пример #7
0
def minor_add():
    try:
        major_id = request.form['major_id']
        major = get_object_or_404(Major, Major.id == major_id)
        minor = Minor.create(name=request.form['name'], major=major)
    except:
        flash('Category #%d not found.' % major_id, 'danger')
        return jsonify(success=False)
    flash('A new subcategory is added.', 'success')
    return jsonify(success=True)
Пример #8
0
def major_add():
    if request.method == 'POST':
        if request.form.get('major_id'):
            major = get_object_or_404(Major, Major.id == request.form['major_id'])
            minors = Minor.listWithStats(request.form['major_id'])
            major.name = request.form['name']
            major.income = bool(request.form.get('income'))
            major.save()
            flash('Category #%d updated successfully.' % major.id, 'success')
        else: 
            major = Major.create(name=request.form['name'],
                                 income=bool(request.form.get('income')))
            minors = []
            for minor_name in string.split(request.form['minors'], ','):
                if len(minor_name) > 0:
                    minor = Minor.create(name=string.strip(minor_name), major=major)
                    minors.append(minor)
            flash('A category created successfully.', 'success')
        return render_template('major.html', major=major, minors=minors)
    return render_template('major.html')
Пример #9
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
    )
Пример #10
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)
Пример #11
0
def major_add():
    if request.method == 'POST':
        if request.form.get('major_id'):
            major = get_object_or_404(Major,
                                      Major.id == request.form['major_id'])
            minors = Minor.listWithStats(request.form['major_id'])
            major.name = request.form['name']
            major.income = bool(request.form.get('income'))
            major.save()
            flash('Category #%d updated successfully.' % major.id, 'success')
        else:
            major = Major.create(name=request.form['name'],
                                 income=bool(request.form.get('income')))
            minors = []
            for minor_name in string.split(request.form['minors'], ','):
                if len(minor_name) > 0:
                    minor = Minor.create(name=string.strip(minor_name),
                                         major=major)
                    minors.append(minor)
            flash('A category created successfully.', 'success')
        return render_template('major.html', major=major, minors=minors)
    return render_template('major.html')
Пример #12
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)
Пример #13
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,
    )
Пример #14
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)
Пример #15
0
def major_delete(id):
    major = get_object_or_404(Major, Major.id == id)
    major.delete_instance()
    minors = Minor.delete().where(Minor.major == id).execute()
    flash('Category #%d is deleted.' % id, 'success')
    return jsonify(success=True)
Пример #16
0
def major_delete(id):
    major = get_object_or_404(Major, Major.id == id)
    major.delete_instance()
    minors = Minor.delete().where(Minor.major == id).execute()
    flash('Category #%d is deleted.' % id, 'success')
    return jsonify(success=True)