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

View File

@ -21,6 +21,11 @@ var CashFlowController = ['$scope', '$routeParams', '$location', 'asDateFilter',
$scope.show = function () { $scope.show = function () {
$location.path('/CashFlow').search({StartDate: $scope.info.StartDate, FinishDate: $scope.info.FinishDate}); $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; $scope.foDate = true;
}]; }];
CashFlowController.resolve = { CashFlowController.resolve = {

View File

@ -33,18 +33,53 @@
<thead> <thead>
<tr> <tr>
<th>Name</th> <th>Name</th>
<th>Flow</th> <th>Subtotal</th>
<th>Total</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody ng-if="info.Body.Details.length">
<tr ng-repeat="item in info.Body"> <tr ng-repeat="item in info.Body.Details">
<td><a href="{{item.Url}}">{{item.Name}}</a></td> <td><a href="{{item.Url}}">{{item.Name}}</a></td>
<td class="text-right">{{item.Amount | currency | clr}}</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> </tr>
</tbody> </tbody>
<tfoot> <tfoot>
<tr ng-repeat="item in info.Footer"> <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> <td class="text-right">{{item.Amount | currency | clr}}</td>
</tr> </tr>
</tfoot> </tfoot>

View File

@ -1,14 +1,13 @@
import datetime import datetime
import pkg_resources import pkg_resources
from pyramid.response import FileResponse from pyramid.response import FileResponse
from sqlalchemy.orm.util import aliased from sqlalchemy.orm.util import aliased
from sqlalchemy.sql.expression import func, desc from sqlalchemy.sql.expression import func, desc
from pyramid.view import view_config from pyramid.view import view_config
from brewman.models.master import LedgerBase, LedgerType from brewman.models.master import LedgerBase, LedgerType
from brewman.models.voucher import Voucher, Journal, VoucherType
from brewman.models.voucher import Voucher, Journal
from brewman.views.services.session import session_period_start, session_period_finish 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): 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_voucher = aliased(Voucher)
sub_journal = aliased(Journal) sub_journal = aliased(Journal)
sub_ledger = aliased(LedgerBase) sub_ledger = aliased(LedgerBase)
@ -84,19 +83,36 @@ def build_report(request, start_date, finish_date):
'Amount': amount * -1 'Amount': amount * -1
} }
) )
for key, value in cf.items(): report['Body'] = cf
if len(value) == 0:
continue
report['Body'].append({'Name': 'Cash flow from ' + key + ' activities'})
for item in value:
report['Body'].append(item)
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 return report
def build_report_id(request, ledger_type, start_date, finish_date): 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_voucher = aliased(Voucher)
sub_journal = aliased(Journal) sub_journal = aliased(Journal)
sub_ledger = aliased(LedgerBase) sub_ledger = aliased(LedgerBase)
@ -126,7 +142,7 @@ def build_report_id(request, ledger_type, start_date, finish_date):
total_amount = 0 total_amount = 0
for ledger, amount in query: for ledger, amount in query:
total_amount += (amount * -1) total_amount += (amount * -1)
report['Body'].append( report['Body']['Details'].append(
{ {
'Name': ledger.name, 'Name': ledger.name,
'Url': request.route_url( '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 return report