Esempio n. 1
0
def forecast_run_task(fcast_id,
                      report_id,
                      col_tag,
                      company_ID=utils.get_default_company(),
                      version='v1'):
    fcast = Forecast.objects.get(id=fcast_id)
    strategy = QueryManagerStrategyFactory().get('forecast')
    strategy.set_cache(fcast_id=fcast_id,
                       proj_gl_entries=fcast.get_gl_entries())

    report = accountifie.reporting.rptutils.get_report(report_id,
                                                       company_ID,
                                                       version=version)
    report.configure(col_tag=col_tag)
    report.set_gl_strategy(strategy)
    report_data = report.calcs()

    path = os.path.join(settings.DATA_ROOT,
                        'forecast_%s_%s.csv' % (fcast_id, report_id))
    f = open(path, 'wb')

    writer = csv.writer(f)
    writer.writerow([''] + report.column_order)
    map_values = lambda x: '' if x == '' else str(x['text'])
    for row in report_data:
        writer.writerow([row['label']] + [
            map_values(row[col])
            for col in [x for x in report.column_order if x in row]
        ])
    f.close()
Esempio n. 2
0
def glsnapshots_balances(request, snap_id):
    snapshot = models.GLSnapshot.objects.get(id=snap_id)
    snapshot_time = snapshot.snapped_at.isoformat()
    strategy = QueryManagerStrategyFactory().get('snapshot')
    strategy.set_cache(snapshot_time)

    report, is_report, format = report_prep(request, 'RecBalances')
    if not is_report:
        return report

    report.qm_strategy = strategy
    report.snapshot = snapshot
    report.columns = {
        'snapshot': 'snapshot',
        'current': 'current',
        'diff': 'diff'
    }

    report_data = report.calcs()

    if format == 'json':
        return HttpResponse(json.dumps(report_data, cls=DjangoJSONEncoder),
                            content_type="application/json")
    elif format == 'csv':
        response = HttpResponse(content_type='text/csv')
        response['Content-Disposition'] = 'attachment; filename="report.csv"'

        writer = csv.writer(response)
        writer.writerow([''] + report.column_order)
        map_values = lambda x: '' if x == '' else str(x['text']).replace(
            '-', '0')
        for row in report_data:
            writer.writerow(
                [row['label']] +
                [map_values(row[col]) for col in report.column_order])
        return response
    elif format == 'html':
        # not bootstrap ... the more custom style for more complex reports
        context = report.html_report_context()
        context['query_string'] = request.META['QUERY_STRING']
        context['rows'] = []
        for rec in report_data:
            context['rows'] += report.get_row(rec)

        return render_to_response('report.html',
                                  RequestContext(request, context))
    else:
        msg = "Sorry. This format is not recognised : %s" % format
        return render_to_response('404.html',
                                  RequestContext(request,
                                                 {'message': msg})), False
Esempio n. 3
0
def fcast_report(request, fcast_id, rpt_id):

    fcast = Forecast.objects.get(id=fcast_id)

    strategy = QueryManagerStrategyFactory().get('forecast')
    strategy.set_cache(fcast_id=fcast_id,
                       proj_gl_entries=fcast.get_gl_entries())

    report, is_report, format = report_prep(request,
                                            rpt_id,
                                            version='v1',
                                            strategy=strategy)
    if not is_report:
        return report

    report_data = report.calcs()

    if format == 'json':
        return HttpResponse(json.dumps(report_data, cls=DjangoJSONEncoder),
                            content_type="application/json")
    elif format == 'csv':
        response = HttpResponse(content_type='text/csv')
        response['Content-Disposition'] = 'attachment; filename="report.csv"'

        writer = csv.writer(response)
        writer.writerow([''] + report.column_order)
        map_values = lambda x: '' if x == '' else str(x['text'])
        for row in report_data:
            writer.writerow([row['label']] + [
                map_values(row[col])
                for col in [x for x in report.column_order if x in row]
            ])
        return response
    elif format == 'html':
        # not bootstrap ... the more custom style for more complex reports
        context = report.html_report_context()
        context['query_string'] = request.META['QUERY_STRING']
        context['rows'] = []
        for rec in report_data:
            context['rows'] += report.get_row(rec)

        return render_to_response('report.html',
                                  RequestContext(request, context))
    else:
        msg = "Sorry. This format is not recognised : %s" % format
        return render_to_response('404.html',
                                  RequestContext(request,
                                                 {'message': msg})), False
Esempio n. 4
0
def forecast_run_task(fcast_id, report_id, col_tag, company_ID=utils.get_default_company(), version='v1'):
    fcast = Forecast.objects.get(id=fcast_id)
    strategy = QueryManagerStrategyFactory().get('forecast')
    strategy.set_cache(fcast_id=fcast_id, proj_gl_entries=fcast.get_gl_entries())

    report = accountifie.reporting.rptutils.get_report(report_id, company_ID, version=version)
    report.configure(col_tag=col_tag)
    report.set_gl_strategy(strategy)
    report_data = report.calcs()

    path = os.path.join(settings.DATA_ROOT, 'forecast_%s_%s.csv' %( fcast_id, report_id))
    f = open(path, 'wb')

    writer = csv.writer(f)
    writer.writerow([''] + report.column_order)
    map_values = lambda x: '' if x=='' else str(x['text'])
    for row in report_data:
        writer.writerow([row['label']] + [map_values(row[col]) for col in [x for x in report.column_order if x in row]])
    f.close()
Esempio n. 5
0
def glsnapshots_balances(request, snap_id):
    snapshot = models.GLSnapshot.objects.get(id=snap_id)
    snapshot_time = snapshot.snapped_at.strftime('%Y-%m-%dT%H:%M:%S.0000ZZ')

    strategy = QueryManagerStrategyFactory().get('snapshot')
    strategy.set_cache(snapshot_time)

    report, is_report, format = report_prep(request, 'RecBalances')
    if not is_report:
        return report

    report.date = snapshot.closing_date
    report.qm_strategy = strategy
    report.snapshot = snapshot
    report.columns = {'snapshot': 'snapshot', 'current': 'current', 'diff': 'diff'}

    report_data = report.calcs()
    
    if format == 'json':
        return HttpResponse(json.dumps(report_data, cls=DjangoJSONEncoder), content_type="application/json")
    elif format == 'csv':
        response = HttpResponse(content_type='text/csv')
        response['Content-Disposition'] = 'attachment; filename="report.csv"'

        writer = csv.writer(response)
        writer.writerow([''] + report.column_order)
        map_values = lambda x: '' if x=='' else str(x['text']).replace('-','0')
        for row in report_data:
            writer.writerow([row['label']] + [map_values(row[col]) for col in report.column_order])
        return response
    elif format == 'html':
        # not bootstrap ... the more custom style for more complex reports
        context = report.html_report_context()
        context['query_string']=request.META['QUERY_STRING']
        context['rows'] = []
        for rec in report_data:
            context['rows'] += report.get_row(rec)

        return render(request, 'report.html', context)
    else:
        msg = "Sorry. This format is not recognised : %s" % format
        return render(request, '404.html', {'message': msg}), False
Esempio n. 6
0
def download_transactions(request):
    company_ID = utils.get_company(request)

    snapshot_time = datetime.datetime.now()
    strategy = QueryManagerStrategyFactory().get('snapshot')
    strategy.set_cache(None)

    trans = strategy.get_all_transactions(company_ID)

    all_accts_list = api_func('gl', 'account')
    all_accts = dict((r['id'], r) for r in all_accts_list)
    
    response = HttpResponse(content_type='text/csv')
    response['Content-Disposition'] = 'attachment; filename="transactions.csv"'
    writer = csv.writer(response)

    writer.writerow(['', '', '', '', '', '','debit', 'debit', 'debit', 'debit','credit', 'credit', 'credit', 'credit'])
    writer.writerow(['Id', 'dateEnd', 'date', 'type', 'comment', 'counterpartyId', 'amount', 'accountId', 
                    'account name','counterpartyId', 'amount', 'accountId', 'account name'])

    for ex in trans:
        first_line = ex['lines'][0]
        acct_id = first_line['accountId']
        acct = api_func('gl', 'account', acct_id)
        if (acct['role'] in ['asset', 'expense'] and float(first_line['amount']) >0) or \
            (acct['role'] in ['liability', 'income', 'capital'] and float(first_line['amount']) < 0):
            debit = ex['lines'][0]
            credit = ex['lines'][1]
        else:
            debit = ex['lines'][1]
            credit = ex['lines'][0]

        row = [ex[k] for k in ['bmoId', 'dateEnd', 'date', 'type', 'comment']]
        row += [debit[k] for k in ['counterpartyId', 'amount', 'accountId']]
        row.append(all_accts[debit['accountId']]['display_name'])
        row += [credit[k] for k in ['counterpartyId', 'amount', 'accountId']]
        row.append(all_accts[credit['accountId']]['display_name'])

        writer.writerow(row)

    return response
Esempio n. 7
0
def fcast_report(request, fcast_id, rpt_id):

    fcast = Forecast.objects.get(id=fcast_id)

    strategy = QueryManagerStrategyFactory().get('forecast')
    strategy.set_cache(fcast_id=fcast_id, proj_gl_entries=fcast.get_gl_entries())

    report, is_report, format = report_prep(request, rpt_id, version='v1', strategy=strategy)
    if not is_report:
        return report

    report_data = report.calcs()
    
    if format == 'json':
        return HttpResponse(json.dumps(report_data, cls=DjangoJSONEncoder), content_type="application/json")
    elif format == 'csv':
        response = HttpResponse(content_type='text/csv')
        response['Content-Disposition'] = 'attachment; filename="report.csv"'

        writer = csv.writer(response)
        writer.writerow([''] + report.column_order)
        map_values = lambda x: '' if x=='' else str(x['text'])
        for row in report_data:
            writer.writerow([row['label']] + [map_values(row[col]) for col in [x for x in report.column_order if x in row]])
        return response
    elif format == 'html':
        # not bootstrap ... the more custom style for more complex reports
        context = report.html_report_context()
        context['query_string']=request.META['QUERY_STRING']
        context['rows'] = []
        for rec in report_data:
            context['rows'] += report.get_row(rec)

        return render(request, 'report.html', context)
    else:
        msg = "Sorry. This format is not recognised : %s" % format
        return render(request, '404.html', {'message': msg}), False