Ejemplo n.º 1
0
def ExportAccountLedger(category, accountname):
    if request.method == 'POST':
        if request.form['export'] == 'Export':
            try:
                if request.form['export-data'] == 'csv':
                    file = AccountingAPI.GrabAccountEntriestoCSV(accountname)
                    response = make_response(file)
                    response.headers['Content-type'] = 'text/csv'
                    response.headers['Content-Disposition'] = 'attachement; filename = {}_ledger.csv'.format(accountname)
                    return response
                elif request.form['export-data'] == 'pdf':
                    data1, data2, data3 = AccountingAPI.GrabAccountEntries(accountname)
                    rendered = render_template('accounting/Account_Ledger.html', data1 = data1, data2 = data2, data3 = data3, AccountName = accountname)
                    pdf = pdfkit.from_string(rendered, False)
                    response = make_response(pdf)
                    response.headers['Content-type'] = 'application/pdf'
                    response.headers['Content-Disposition'] = 'attachement; filename = {}_Ledger.pdf'.format(accountname)
                    return response
            except Exception as e:
                flash(str(e), category = 'fail')
                return redirect(url_for('accounting.add_account', category = category, account = accountname))
    return redirect(url_for('accounting.add_account', category = category, account = accountname))
Ejemplo n.º 2
0
def GrabAccountEntries(AccountName):
    data1, data2, data3 = AccountingAPI.GrabAccountEntries(AccountName)
    return jsonify(info = data1, totals = data2, balances = data3)