def download_ledger(request): from_date, to_date = utils.extractDateRange(request) company_ID = utils.get_company(request) accts = api_func('gl', 'accounts') response = HttpResponse(content_type='text/csv') response['Content-Disposition'] = 'attachment; filename="ledger.csv"' writer = csv.writer(response) header_row = [ 'id', 'date', 'comment', 'contra_accts', 'counterparty', 'amount', 'balance' ] for acct in accts: history = accountifie.reporting.api.history({ 'type': 'account', 'from_date': from_date, 'to_date': to_date, 'company_ID': company_ID, 'id': acct['id'] }) if len(history) > 0: writer.writerow([]) writer.writerow([acct['id'], acct['display_name'], acct['path']]) writer.writerow([]) writer.writerow(header_row) for idx in history.index: writer.writerow([history.loc[idx, col] for col in header_row]) return response
def balance_history(request, type, id): from_date, to_date = utils.extractDateRange(request) company_ID = utils.get_company(request) if type == 'account': cp = request.GET.get('cp',None) acct = api_func('gl', 'account', id) display_name = '%s: %s' %(acct['id'], acct['display_name']) history = accountifie.query.query_manager.QueryManager().pd_history(company_ID, 'account', acct['id'], from_date=from_date, to_date=to_date, cp=cp) if cp and not history.empty: history = history[history['counterparty']==cp] display_name += ' -- %s' % cp balance_history = history[['amount','date']].groupby('date').sum().cumsum().reset_index() column_titles = ['date', 'amount'] elif type == 'path': ref = id.replace('_','.') display_name = 'path: %s' % ref excl = request.GET['excl'].split(',') if request.GET.has_key('excl') else None incl = request.GET['incl'].split(',') if request.GET.has_key('incl') else None if excl: excl = [x.replace('_','.') for x in excl] display_name += ' -- excl %s' % ','.join(excl) if incl: incl = [x.replace('_','.') for x in incl] display_name += ' -- incl %s' % ','.join(incl) history = accountifie.query.query_manager.QueryManager().pd_history(company_ID, type, ref, from_date=from_date, to_date=to_date, excl_contra=excl, incl=incl) balance_history = history[['amount','date']].groupby('date').sum().cumsum().reset_index() column_titles = ['date', 'amount'] elif type == 'creditor': cp = request.GET.get('cp',None) cp_info = api_func('gl', 'counterparty', id) display_name = '%s: %s' %(cp_info['id'], cp_info['name']) history = accountifie.query.query_manager.QueryManager().pd_history(company_ID, 'account', '3000', from_date=from_date, to_date=to_date, cp=id) history = history[history['counterparty']==id] balance_history = history[['amount','date']].groupby('date').sum().cumsum().reset_index() column_titles = ['date', 'amount'] else: raise ValueError('This type of history is not supported') years = Year.objects.all() entries = [] if balance_history is not None: for i in balance_history.index: entries.append(create_row(balance_history.loc[i], column_titles)) context = {} context['display_name'] = display_name context['column_titles'] = column_titles context['history'] = entries context['years'] = years context['by_date_cleared'] = False context['from_date'] = from_date context['to_date'] = to_date return render_to_response('bal_history.html', RequestContext(request, context))
def download_ledger(request): from_date, to_date = utils.extractDateRange(request) company_ID = utils.get_company(request) accts = api_func('gl', 'accounts') response = HttpResponse(content_type='text/csv') response['Content-Disposition'] = 'attachment; filename="ledger.csv"' writer = csv.writer(response) header_row = ['id', 'date', 'comment', 'contra_accts', 'counterparty', 'amount', 'balance'] for acct in accts: history = accountifie.reporting.api.history({'type': 'account', 'from_date': from_date, 'to_date': to_date, 'company_ID': company_ID, 'id': acct['id']}) if len(history) > 0: writer.writerow([]) writer.writerow([acct['id'], acct['display_name'], acct['path']]) writer.writerow([]) writer.writerow(header_row) for idx in history.index: writer.writerow([history.loc[idx, col] for col in header_row]) return response
def history(request, type, id): from_date, to_date = utils.extractDateRange(request) start_date = settings.DATE_EARLY end_date = to_date company_ID = utils.get_company(request) if type == "account": cp = request.GET.get("cp", None) acct = api_func("gl", "account", id) display_name = "%s: %s" % (acct["id"], acct["display_name"]) history = accountifie.query.query_manager.QueryManager().pd_history( company_ID, "account", acct["id"], from_date=start_date, to_date=end_date, cp=cp ) if cp and not history.empty: history = history[history["counterparty"] == cp] history["balance"] = history["amount"].cumsum() display_name += " -- %s" % cp column_titles = ["id", "date", "comment", "contra_accts", "counterparty", "amount", "balance"] elif type == "path": ref = id.replace("_", ".") display_name = "path: %s" % ref excl = request.GET["excl"].split(",") if request.GET.has_key("excl") else None incl = request.GET["incl"].split(",") if request.GET.has_key("incl") else None if excl: excl = [x.replace("_", ".") for x in excl] display_name += " -- excl %s" % ",".join(excl) if incl: incl = [x.replace("_", ".") for x in incl] display_name += " -- incl %s" % ",".join(incl) history = accountifie.query.query_manager.QueryManager().pd_history( company_ID, type, ref, from_date=start_date, to_date=end_date, excl_contra=excl, incl=incl ) column_titles = ["id", "date", "comment", "account_id", "contra_accts", "counterparty", "amount", "balance"] elif type == "creditor": cp = request.GET.get("cp", None) cp_info = api_func("gl", "counterparty", id) display_name = "%s: %s" % (cp_info["id"], cp_info["name"]) history = accountifie.query.query_manager.QueryManager().pd_history( company_ID, "account", "3000", from_date=start_date, to_date=end_date, cp=id ) history = history[history["counterparty"] == id] history["balance"] = history["amount"].cumsum() column_titles = ["id", "date", "comment", "contra_accts", "amount", "balance"] else: raise ValueError("This type of history is not supported") years = Year.objects.all() entries = [] if (history is not None) and (history.empty is False): unused_history = history[history["date"] < from_date] used_history = history[history["date"] >= from_date] if len(unused_history) > 0: start_row = unused_history.iloc[-1] start_row["id"] = "None" start_row["date"] = from_date start_row["comment"] = "Opening Balance" start_row["contra_accts"] = "None" start_row["counterparty"] = "None" start_row["amount"] = 0 entries.append(create_row(start_row, column_titles)) for i in used_history.index: entries.append(create_row(history.loc[i], column_titles)) context = {} context["display_name"] = display_name context["column_titles"] = column_titles context["history"] = entries context["years"] = years context["by_date_cleared"] = False context["from_date"] = from_date context["to_date"] = to_date return render(request, "history.html", context)
def balance_history(request, type, id): from_date, to_date = utils.extractDateRange(request) company_ID = utils.get_company(request) if type == "account": cp = request.GET.get("cp", None) acct = api_func("gl", "account", id) display_name = "%s: %s" % (acct["id"], acct["display_name"]) history = accountifie.query.query_manager.QueryManager().pd_history( company_ID, "account", acct["id"], from_date=from_date, to_date=to_date, cp=cp ) if cp and not history.empty: history = history[history["counterparty"] == cp] display_name += " -- %s" % cp balance_history = history[["amount", "date"]].groupby("date").sum().cumsum().reset_index() column_titles = ["date", "amount"] elif type == "path": ref = id.replace("_", ".") display_name = "path: %s" % ref excl = request.GET["excl"].split(",") if request.GET.has_key("excl") else None incl = request.GET["incl"].split(",") if request.GET.has_key("incl") else None if excl: excl = [x.replace("_", ".") for x in excl] display_name += " -- excl %s" % ",".join(excl) if incl: incl = [x.replace("_", ".") for x in incl] display_name += " -- incl %s" % ",".join(incl) history = accountifie.query.query_manager.QueryManager().pd_history( company_ID, type, ref, from_date=from_date, to_date=to_date, excl_contra=excl, incl=incl ) balance_history = history[["amount", "date"]].groupby("date").sum().cumsum().reset_index() column_titles = ["date", "amount"] elif type == "creditor": cp = request.GET.get("cp", None) cp_info = api_func("gl", "counterparty", id) display_name = "%s: %s" % (cp_info["id"], cp_info["name"]) history = accountifie.query.query_manager.QueryManager().pd_history( company_ID, "account", "3000", from_date=from_date, to_date=to_date, cp=id ) history = history[history["counterparty"] == id] balance_history = history[["amount", "date"]].groupby("date").sum().cumsum().reset_index() column_titles = ["date", "amount"] else: raise ValueError("This type of history is not supported") years = Year.objects.all() entries = [] if balance_history is not None: for i in balance_history.index: entries.append(create_row(balance_history.loc[i], column_titles)) context = {} context["display_name"] = display_name context["column_titles"] = column_titles context["history"] = entries context["years"] = years context["by_date_cleared"] = False context["from_date"] = from_date context["to_date"] = to_date return render(request, "bal_history.html", context)
def history(request, type, id): from_date, to_date = utils.extractDateRange(request) start_date = settings.DATE_EARLY end_date = to_date company_ID = utils.get_company(request) if type == 'account': cp = request.GET.get('cp', None) acct = api_func('gl', 'account', id) display_name = '%s: %s' % (acct['id'], acct['display_name']) history = accountifie.query.query_manager.QueryManager().pd_history( company_ID, 'account', acct['id'], from_date=start_date, to_date=end_date, cp=cp) if cp and not history.empty: history = history[history['counterparty'] == cp] history['balance'] = history['amount'].cumsum() display_name += ' -- %s' % cp column_titles = [ 'id', 'date', 'comment', 'contra_accts', 'counterparty', 'amount', 'balance' ] elif type == 'path': ref = id.replace('_', '.') display_name = 'path: %s' % ref excl = request.GET['excl'].split(',') if request.GET.has_key( 'excl') else None incl = request.GET['incl'].split(',') if request.GET.has_key( 'incl') else None if excl: excl = [x.replace('_', '.') for x in excl] display_name += ' -- excl %s' % ','.join(excl) if incl: incl = [x.replace('_', '.') for x in incl] display_name += ' -- incl %s' % ','.join(incl) history = accountifie.query.query_manager.QueryManager().pd_history( company_ID, type, ref, from_date=start_date, to_date=end_date, excl_contra=excl, incl=incl) column_titles = [ 'id', 'date', 'comment', 'account_id', 'contra_accts', 'counterparty', 'amount', 'balance' ] elif type == 'creditor': cp = request.GET.get('cp', None) cp_info = api_func('gl', 'counterparty', id) display_name = '%s: %s' % (cp_info['id'], cp_info['name']) history = accountifie.query.query_manager.QueryManager().pd_history( company_ID, 'account', '3000', from_date=start_date, to_date=end_date, cp=id) history = history[history['counterparty'] == id] history['balance'] = history['amount'].cumsum() column_titles = [ 'id', 'date', 'comment', 'contra_accts', 'amount', 'balance' ] else: raise ValueError('This type of history is not supported') years = Year.objects.all() entries = [] if history is not None: unused_history = history[history['date'] < from_date] used_history = history[history['date'] >= from_date] if len(unused_history) > 0: start_row = unused_history.iloc[-1] start_row['id'] = 'None' start_row['date'] = from_date start_row['comment'] = 'Opening Balance' start_row['contra_accts'] = 'None' start_row['counterparty'] = 'None' start_row['amount'] = 0 entries.append(create_row(start_row, column_titles)) for i in used_history.index: entries.append(create_row(history.loc[i], column_titles)) context = {} context['display_name'] = display_name context['column_titles'] = column_titles context['history'] = entries context['years'] = years context['by_date_cleared'] = False context['from_date'] = from_date context['to_date'] = to_date return render_to_response('history.html', RequestContext(request, context))