From 57624c2804e0b52f85cac31fd0955f2e78b61306 Mon Sep 17 00:00:00 2001 From: tanshu Date: Fri, 10 Feb 2017 00:09:32 +0530 Subject: [PATCH] Cash Flow updated with opening and closing cash balance --- .../app/cash-flow/cash-flow.controller.js | 5 +++ brewman/static/app/cash-flow/cash-flow.html | 43 ++++++++++++++++-- brewman/views/reports/cash_flow.py | 44 +++++++++++++------ 3 files changed, 74 insertions(+), 18 deletions(-) diff --git a/brewman/static/app/cash-flow/cash-flow.controller.js b/brewman/static/app/cash-flow/cash-flow.controller.js index daceb2dc..f2289f76 100644 --- a/brewman/static/app/cash-flow/cash-flow.controller.js +++ b/brewman/static/app/cash-flow/cash-flow.controller.js @@ -21,6 +21,11 @@ var CashFlowController = ['$scope', '$routeParams', '$location', 'asDateFilter', $scope.show = function () { $location.path('/CashFlow').search({StartDate: $scope.info.StartDate, FinishDate: $scope.info.FinishDate}); }; + $scope.total = function (type) { + return $scope.info.Body[type].reduce(function (accumulator, current) { + return accumulator + current.Amount; + }, 0); + }; $scope.foDate = true; }]; CashFlowController.resolve = { diff --git a/brewman/static/app/cash-flow/cash-flow.html b/brewman/static/app/cash-flow/cash-flow.html index cd593ecd..ccb3fb69 100644 --- a/brewman/static/app/cash-flow/cash-flow.html +++ b/brewman/static/app/cash-flow/cash-flow.html @@ -33,18 +33,53 @@ Name - Flow + Subtotal + Total - - + + {{item.Name}} {{item.Amount | currency | clr}} + + + + + + Cash flows from Operating activities + {{total('Operating') | currency | clr}} + + + {{item.Name}} + {{item.Amount | currency | clr}} + + + + + + Cash flows from Investing activities + {{total('Investing') | currency | clr}} + + + {{item.Name}} + {{item.Amount | currency | clr}} + + + + + + Cash flows from Financing activities + {{total('Financing') | currency | clr}} + + + {{item.Name}} + {{item.Amount | currency | clr}} + - {{item.Name}} + {{item.Name}} {{item.Amount | currency | clr}} diff --git a/brewman/views/reports/cash_flow.py b/brewman/views/reports/cash_flow.py index a35ee7bc..c0034488 100644 --- a/brewman/views/reports/cash_flow.py +++ b/brewman/views/reports/cash_flow.py @@ -1,14 +1,13 @@ import datetime + import pkg_resources from pyramid.response import FileResponse from sqlalchemy.orm.util import aliased from sqlalchemy.sql.expression import func, desc - from pyramid.view import view_config from brewman.models.master import LedgerBase, LedgerType - -from brewman.models.voucher import Voucher, Journal +from brewman.models.voucher import Voucher, Journal, VoucherType from brewman.views.services.session import session_period_start, session_period_finish @@ -40,7 +39,7 @@ def get_cash_flow_id(request): def build_report(request, start_date, finish_date): - report = {'StartDate': start_date, 'FinishDate': finish_date, 'Body': [], 'Footer': []} + report = {'StartDate': start_date, 'FinishDate': finish_date} sub_voucher = aliased(Voucher) sub_journal = aliased(Journal) sub_ledger = aliased(LedgerBase) @@ -84,19 +83,36 @@ def build_report(request, start_date, finish_date): 'Amount': amount * -1 } ) - for key, value in cf.items(): - if len(value) == 0: - continue - report['Body'].append({'Name': 'Cash flow from ' + key + ' activities'}) - for item in value: - report['Body'].append(item) + report['Body'] = cf - report['Footer'].append({'Name': 'Net Cash Flow', 'Amount': total_amount}) + opening = request.dbsession.query( + func.sum(Journal.amount * Journal.debit) + ).join(Journal.voucher).join( + Journal.ledger + ).filter(Voucher.date < start_date).filter( + Voucher.type != VoucherType.by_name('Issue').id + ).filter( + LedgerBase.type == LedgerType.by_name('Cash').id + ).scalar() + + closing = request.dbsession.query( + func.sum(Journal.amount * Journal.debit) + ).join(Journal.voucher).join( + Journal.ledger + ).filter(Voucher.date <= finish_date).filter( + Voucher.type != VoucherType.by_name('Issue').id + ).filter( + LedgerBase.type == LedgerType.by_name('Cash').id + ).scalar() + + report['Footer'] = [{'Name': 'Net increase in cash and cash equivalents', 'Amount': total_amount}, + {'Name': 'Cash and cash equivalents at beginning of period', 'Amount': opening}, + {'Name': 'Cash and cash equivalents at end of period', 'Amount': closing}] return report def build_report_id(request, ledger_type, start_date, finish_date): - report = {'StartDate': start_date, 'FinishDate': finish_date, 'Body': [], 'Footer': []} + report = {'StartDate': start_date, 'FinishDate': finish_date, 'Body': {'Details': []}} sub_voucher = aliased(Voucher) sub_journal = aliased(Journal) sub_ledger = aliased(LedgerBase) @@ -126,7 +142,7 @@ def build_report_id(request, ledger_type, start_date, finish_date): total_amount = 0 for ledger, amount in query: total_amount += (amount * -1) - report['Body'].append( + report['Body']['Details'].append( { 'Name': ledger.name, 'Url': request.route_url( @@ -137,5 +153,5 @@ def build_report_id(request, ledger_type, start_date, finish_date): } ) - report['Footer'].append({'Name': 'Total', 'Amount': total_amount}) + report['Footer'] = [{'Name': 'Total', 'Amount': total_amount}] return report