Cash Flow updated with opening and closing cash balance

This commit is contained in:
tanshu 2017-02-10 00:09:32 +05:30
parent 2ac10f16c3
commit 57624c2804
3 changed files with 74 additions and 18 deletions
brewman
static/app/cash-flow
views/reports

@ -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 = {

@ -33,18 +33,53 @@
<thead>
<tr>
<th>Name</th>
<th>Flow</th>
<th>Subtotal</th>
<th>Total</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="item in info.Body">
<tbody ng-if="info.Body.Details.length">
<tr ng-repeat="item in info.Body.Details">
<td><a href="{{item.Url}}">{{item.Name}}</a></td>
<td class="text-right">{{item.Amount | currency | clr}}</td>
<td></td>
</tr>
</tbody>
<tbody ng-if="info.Body.Operating.length">
<tr>
<td colspan="2"><strong>Cash flows from Operating activities</strong></td>
<td class="text-right">{{total('Operating') | currency | clr}}</td>
</tr>
<tr ng-repeat="item in info.Body.Operating">
<td><a href="{{item.Url}}">{{item.Name}}</a></td>
<td class="text-right">{{item.Amount | currency | clr}}</td>
<td></td>
</tr>
</tbody>
<tbody ng-if="info.Body.Investing.length">
<tr>
<td colspan="2"><strong>Cash flows from Investing activities</strong></td>
<td class="text-right">{{total('Investing') | currency | clr}}</td>
</tr>
<tr ng-repeat="item in info.Body.Investing">
<td><a href="{{item.Url}}">{{item.Name}}</a></td>
<td class="text-right">{{item.Amount | currency | clr}}</td>
<td></td>
</tr>
</tbody>
<tbody ng-if="info.Body.Financing.length">
<tr>
<td colspan="2"><strong>Cash flows from Financing activities</strong></td>
<td class="text-right">{{total('Financing') | currency | clr}}</td>
</tr>
<tr ng-repeat="item in info.Body.Financing">
<td><a href="{{item.Url}}">{{item.Name}}</a></td>
<td class="text-right">{{item.Amount | currency | clr}}</td>
<td></td>
</tr>
</tbody>
<tfoot>
<tr ng-repeat="item in info.Footer">
<td>{{item.Name}}</td>
<td colspan="2"><em>{{item.Name}}</em></td>
<td class="text-right">{{item.Amount | currency | clr}}</td>
</tr>
</tfoot>

@ -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