Exemplo n.º 1
0
def accounting_edit_transaction(transaction_id):
    banks = DB.Bank.query.all()
    transaction = DB.Transaction.query.get(transaction_id)
    form = forms.EditTransaction(obj=transaction)
    form.bank_id.choices = [(bank.id, bank.name) for bank in banks]
    form.category_id.choices = accounting_categories()
    if form.validate_on_submit():
        confirmation = app.config['CHANGE_MSG']
        atributes = ['date', 'facturation_date', 'is_revenue', 'amount', 'to_from', 'description',
            'category_id', 'bank_id', 'bank_statement_number']
        for atribute in atributes:
            old_value = getattr(transaction, str(atribute))
            new_value = request.form.get(atribute)
            if atribute == 'is_revenue':
                if new_value == '1':
                    new_value = True
                elif new_value == '0':
                    new_value = False
            if str(new_value) != str(old_value):
                if atribute == 'facturation_date' and new_value == '':
                    new_value = request.form.get('date')
                setattr(transaction, atribute, new_value)
                confirmation = add_confirmation(confirmation, str(atribute) +
                    " = " + str(new_value) + " (was " + str(old_value) + ")")
            transaction.date_filed
        DB.db.session.commit()

        uploadconfirmation = upload_attachments(request, attachments, transaction, DB)

        confirmation = add_confirmation(confirmation, uploadconfirmation)
        return_flash(confirmation)
        return redirect(request.url)
    return render_template('accounting/edit_transaction.html', form=form, transaction=transaction)
Exemplo n.º 2
0
def accounting_log(page):
    log = DB.Transaction.query.filter(DB.Transaction.date_filed != None).order_by(DB.Transaction.date.desc())
    banks = DB.Bank.query.order_by(DB.Bank.id).all()

    form = forms.FilterTransaction()
    form.bank_id.choices = [("","filter by bank")]
    form.bank_id.choices.extend([(str(bank.id), bank.name) for bank in banks])
    form.category_id.choices = [("","filter by category")]
    form.category_id.choices.extend(accounting_categories())

    for item in ['is_revenue', 'bank_id', 'category_id']:
        field = request.args.get(item)
        if field:
            setattr(form[item], 'data', field)
            log = log.filter(getattr(DB.Transaction, item) == field)

    item_count = len(log.all())
    log = log.paginate(page, app.config['ITEMS_PER_PAGE'], False).items
    if not log and page != 1:
        abort(404)
    pagination = Pagination(page, app.config['ITEMS_PER_PAGE'], item_count)

    if form.validate_on_submit():
        args = request.view_args.copy()
        for field in [ "is_revenue", "bank_id", "category_id"]:
            if request.form[field] != '':
                args[field] = request.form[field]
        return redirect(url_for('accounting_log', **args))
    return render_template('accounting/log.html', log=log, form=form, pagination=pagination)
Exemplo n.º 3
0
def accounting_log(page):
    log = DB.Transaction.query.filter(
        DB.Transaction.date_filed != None).order_by(
            DB.Transaction.date.desc(),
            DB.Transaction.bank_statement_number.desc())
    banks = DB.Bank.query.order_by(DB.Bank.id).all()

    form = forms.FilterTransaction()
    form.bank_id.choices = [("", "filter by bank")]
    form.bank_id.choices.extend([(str(bank.id), bank.name) for bank in banks])
    form.category_id.choices = [("", "filter by category")]
    form.category_id.choices.extend(accounting_categories())

    for item in ['is_revenue', 'bank_id', 'category_id']:
        field = request.args.get(item)
        if field:
            setattr(form[item], 'data', field)
            log = log.filter(getattr(DB.Transaction, item) == field)

    item_count = len(log.all())
    log = log.paginate(page, app.config['ITEMS_PER_PAGE'], False).items
    if not log and page != 1:
        abort(404)
    pagination = Pagination(page, app.config['ITEMS_PER_PAGE'], item_count)

    if form.validate_on_submit():
        args = request.view_args.copy()
        for field in ["is_revenue", "bank_id", "category_id"]:
            if request.form[field] != '':
                args[field] = request.form[field]
        return redirect(url_for('accounting_log', **args))
    return render_template('accounting/log.html',
                           log=log,
                           form=form,
                           pagination=pagination)
Exemplo n.º 4
0
def accounting_approve_reimbursement(transaction_id):
    banks = DB.Bank.query.order_by(DB.Bank.id).all()
    transaction = DB.Transaction.query.get(transaction_id)
    form = forms.ApproveReimbursement(obj=transaction)
    form.bank_id.choices = [(bank.id, bank.name) for bank in banks]
    form.category_id.choices = accounting_categories(IN=False)
    del form.is_revenue
    if form.validate_on_submit():
        transaction.date = request.form["date"]
        transaction.facturation_date = request.form["date"]
        transaction.amount = request.form["amount"]
        transaction.to_from = request.form["to_from"]
        transaction.description = request.form["description"]
        transaction.category_id = request.form["category_id"]
        transaction.bank_id = request.form["bank_id"]
        transaction.bank_statement_number = request.form["bank_statement_number"]
        transaction.date_filed = date.today()
        transaction.filed_by_id = current_user.id
        DB.db.session.commit()

        upload_attachments(request, attachments, transaction, DB)

        flash("the transaction was filed", "confirmation")
        return redirect(url_for('accounting_approve_reimbursements'))
    return render_template('accounting/approve_reimbursement.html', form=form, transaction=transaction )
Exemplo n.º 5
0
def accounting_approve_reimbursement(transaction_id):
    banks = DB.Bank.query.order_by(DB.Bank.id).all()
    transaction = DB.Transaction.query.get(transaction_id)
    form = forms.ApproveReimbursement(obj=transaction)
    form.bank_id.choices = [(bank.id, bank.name) for bank in banks]
    form.category_id.choices = accounting_categories(IN=False)
    del form.is_revenue
    if form.validate_on_submit():
        transaction.date = string_to_date(request.form["date"])
        transaction.facturation_date = string_to_date(request.form["date"])
        transaction.amount = request.form["amount"]
        transaction.to_from = request.form["to_from"]
        transaction.description = request.form["description"]
        transaction.category_id = request.form["category_id"]
        transaction.bank_id = request.form["bank_id"]
        transaction.bank_statement_number = request.form[
            "bank_statement_number"]
        transaction.date_filed = date.today()
        transaction.filed_by_id = current_user.id
        DB.db.session.commit()

        upload_attachments(request, attachments, transaction, DB)

        flash("the transaction was filed", "confirmation")
        return redirect(url_for('accounting_approve_reimbursements'))
    return render_template('accounting/approve_reimbursement.html',
                           form=form,
                           transaction=transaction)
Exemplo n.º 6
0
def accounting_edit_transaction(transaction_id):
    banks = DB.Bank.query.all()
    transaction = DB.Transaction.query.get(transaction_id)
    form = forms.EditTransaction(obj=transaction)
    form.bank_id.choices = [(bank.id, bank.name) for bank in banks]
    form.category_id.choices = accounting_categories()
    if form.validate_on_submit():
        confirmation = app.config["CHANGE_MSG"]
        atributes = [
            "date",
            "facturation_date",
            "is_revenue",
            "amount",
            "to_from",
            "description",
            "category_id",
            "bank_id",
            "bank_statement_number",
        ]
        for atribute in atributes:
            old_value = getattr(transaction, str(atribute))
            new_value = request.form.get(atribute)
            if atribute == "is_revenue":
                if new_value == "1":
                    new_value = True
                elif new_value == "0":
                    new_value = False
            elif atribute in ["date", "facturation_date"]:
                new_value = string_to_date(request.form.get(atribute))
            if str(new_value) != str(old_value):
                if atribute == "facturation_date" and new_value == "":
                    new_value = request.form.get("date")
                setattr(transaction, atribute, new_value)
                confirmation = add_confirmation(
                    confirmation, str(atribute) + " = " + str(new_value) + " (was " + str(old_value) + ")"
                )
            transaction.date_filed
        DB.db.session.commit()

        uploadconfirmation = upload_attachments(request, attachments, transaction, DB)

        confirmation = add_confirmation(confirmation, uploadconfirmation)
        return_flash(confirmation)
        return redirect(request.url)
    return render_template("accounting/edit_transaction.html", form=form, transaction=transaction)
Exemplo n.º 7
0
def accounting_add_transaction():
    banks = DB.Bank.query.order_by(DB.Bank.id).all()
    form = forms.AddTransaction()
    form.bank_id.choices = [(bank.id, bank.name) for bank in banks]
    form.category_id.choices = accounting_categories()
    if form.validate_on_submit():
        if request.form["facturation_date"] != '':
            facturation_date = string_to_date(request.form["facturation_date"])
        else:
            facturation_date = string_to_date(request.form["date"])
        # convert empty string to None if necessary to prevent a crash
        if request.form["bank_statement_number"] == '':
            bank_statement_number = None
        else:
            bank_statement_number = request.form["bank_statement_number"]
        transaction = DB.Transaction(
            date=string_to_date(request.form["date"]),
            facturation_date=facturation_date,
            is_revenue=request.form["is_revenue"],
            amount=request.form["amount"],
            to_from=request.form["to_from"],
            description=request.form["description"],
            category_id=request.form["category_id"],
            bank_id=request.form["bank_id"],
            bank_statement_number=bank_statement_number,
            date_filed=date.today(),
            filed_by_id=current_user.id)
        DB.db.session.add(transaction)
        DB.db.session.commit()

        upload_attachments(request, attachments, transaction, DB)

        if request.form["category_id"] == '6':
            id = DB.Transaction.query.order_by(
                DB.Transaction.id.desc()).first()
            return redirect(url_for('topup_bar_account', transaction_id=id.id))
        elif request.form["category_id"] == '8':
            id = DB.Transaction.query.order_by(
                DB.Transaction.id.desc()).first()
            return redirect(url_for('file_membershipfee',
                                    transaction_id=id.id))
        return redirect(url_for('accounting_log'))

        flash("the transaction was filed", "confirmation")
    return render_template('accounting/add_transaction.html', form=form)
Exemplo n.º 8
0
def accounting_edit_transaction(transaction_id):
    banks = DB.Bank.query.all()
    transaction = DB.Transaction.query.get(transaction_id)
    form = forms.EditTransaction(obj=transaction)
    form.bank_id.choices = [(bank.id, bank.name) for bank in banks]
    form.category_id.choices = accounting_categories()
    if form.validate_on_submit():
        confirmation = app.config['CHANGE_MSG']
        atributes = [
            'date', 'facturation_date', 'is_revenue', 'amount', 'to_from',
            'description', 'category_id', 'bank_id', 'bank_statement_number'
        ]
        for atribute in atributes:
            old_value = getattr(transaction, str(atribute))
            new_value = request.form.get(atribute)
            if atribute == 'is_revenue':
                if new_value == '1':
                    new_value = True
                elif new_value == '0':
                    new_value = False
            elif atribute in ['date', 'facturation_date']:
                new_value = string_to_date(request.form.get(atribute))
            if str(new_value) != str(old_value):
                if atribute == 'facturation_date' and new_value == '':
                    new_value = request.form.get('date')
                setattr(transaction, atribute, new_value)
                confirmation = add_confirmation(
                    confirmation,
                    str(atribute) + " = " + str(new_value) + " (was " +
                    str(old_value) + ")")
            transaction.date_filed
        DB.db.session.commit()

        uploadconfirmation = upload_attachments(request, attachments,
                                                transaction, DB)

        confirmation = add_confirmation(confirmation, uploadconfirmation)
        return_flash(confirmation)
        return redirect(request.url)
    return render_template('accounting/edit_transaction.html',
                           form=form,
                           transaction=transaction)
Exemplo n.º 9
0
def accounting_add_transaction():
    banks = DB.Bank.query.order_by(DB.Bank.id).all()
    form = forms.AddTransaction()
    form.bank_id.choices = [(bank.id, bank.name) for bank in banks]
    form.category_id.choices = accounting_categories()
    if form.validate_on_submit():
        if request.form["facturation_date"] != '':
            facturation_date = string_to_date(request.form["facturation_date"])
        else:
            facturation_date = string_to_date(request.form["date"])
        # convert empty string to None if necessary to prevent a crash
        if request.form["bank_statement_number"] == '':
            bank_statement_number = None
        else:
            bank_statement_number = request.form["bank_statement_number"]
        transaction = DB.Transaction(date=string_to_date(request.form["date"]),
                                     facturation_date=facturation_date,
                                     is_revenue=request.form["is_revenue"],
                                     amount=request.form["amount"],
                                     to_from=request.form["to_from"],
                                     description=request.form["description"],
                                     category_id=request.form["category_id"],
                                     bank_id=request.form["bank_id"],
                                     bank_statement_number=bank_statement_number,
                                     date_filed=date.today(),
                                     filed_by_id=current_user.id)
        DB.db.session.add(transaction)
        DB.db.session.commit()

        upload_attachments(request, attachments, transaction, DB)

        if request.form["category_id"] == '6':
            id = DB.Transaction.query.order_by(DB.Transaction.id.desc()).first()
            return redirect(url_for('topup_bar_account', transaction_id=id.id))
        elif request.form["category_id"] == '8':
            id = DB.Transaction.query.order_by(DB.Transaction.id.desc()).first()
            return redirect(url_for('file_membershipfee', transaction_id=id.id))
        return redirect(url_for('accounting_log'))

        flash("the transaction was filed", "confirmation")
    return render_template('accounting/add_transaction.html', form=form)