Chore: Removed redundant Running Total calculation from Ledger python view as it is not calculated client side.
This commit is contained in:
parent
248a841695
commit
358b235d8f
|
@ -51,7 +51,7 @@
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
<tr id="{{$index}}" ng-repeat="item in display.Body" ng-class="{danger:!item.Posted, warning:$index==selected}"
|
<tr id="{{$index}}" ng-repeat="item in display.Body" ng-class="{danger:!item.Posted && $index!=selected, warning:$index==selected}"
|
||||||
ng-click="setSelected($index)">
|
ng-click="setSelected($index)">
|
||||||
<td class="no-wrap">{{item.Date}}</td>
|
<td class="no-wrap">{{item.Date}}</td>
|
||||||
<td><a href="{{item.Url}}">{{item.Name}}</a></td>
|
<td><a href="{{item.Url}}">{{item.Name}}</a></td>
|
||||||
|
@ -65,9 +65,9 @@
|
||||||
<tfoot>
|
<tfoot>
|
||||||
<tr>
|
<tr>
|
||||||
<td class="no-wrap">{{display.Footer.Date}}</td>
|
<td class="no-wrap">{{display.Footer.Date}}</td>
|
||||||
<td>{{display.Footer.Name}}</td>
|
<td>Closing Balance</td>
|
||||||
<td>{{display.Footer.Type}}</td>
|
<td>Closing Balance</td>
|
||||||
<td>{{display.Footer.Narration}}</td>
|
<td></td>
|
||||||
<td class="text-right no-wrap">{{display.Footer.Debit | currency}}</td>
|
<td class="text-right no-wrap">{{display.Footer.Debit | currency}}</td>
|
||||||
<td class="text-right no-wrap">{{display.Footer.Credit | currency}}</td>
|
<td class="text-right no-wrap">{{display.Footer.Credit | currency}}</td>
|
||||||
<td class="text-right no-wrap">{{display.Footer.Running | accounting}}</td>
|
<td class="text-right no-wrap">{{display.Footer.Running | accounting}}</td>
|
||||||
|
|
|
@ -47,20 +47,21 @@ var LedgerCtrl = ['$scope', '$routeParams', '$location', 'dateFilter', 'ledger',
|
||||||
if (hidden.length !== 0) {
|
if (hidden.length !== 0) {
|
||||||
data = _.filter(data, function (item) {
|
data = _.filter(data, function (item) {
|
||||||
return !_.any(hidden, function (hi) {
|
return !_.any(hidden, function (hi) {
|
||||||
if (!item.hasOwnProperty('Url') && !hi.hasOwnProperty('Url')) {
|
return item.ID === hi;
|
||||||
return true;
|
|
||||||
} else if (item.hasOwnProperty('Url') !== hi.hasOwnProperty('Url')) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return item.Url === hi.Url;
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
_.forEach(data, function (item) {
|
_.forEach(data, function (item) {
|
||||||
debit += item.Debit;
|
if (item.Type !== 'Opening Balance') {
|
||||||
credit += item.Credit;
|
debit += item.Debit;
|
||||||
running = debit - credit;
|
credit += item.Credit;
|
||||||
|
if (item.Posted) {
|
||||||
|
running += item.Debit - item.Credit;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
running += item.Debit - item.Credit;
|
||||||
|
}
|
||||||
item.Running = running;
|
item.Running = running;
|
||||||
});
|
});
|
||||||
footer.Debit = debit;
|
footer.Debit = debit;
|
||||||
|
@ -92,8 +93,8 @@ var LedgerCtrl = ['$scope', '$routeParams', '$location', 'dateFilter', 'ledger',
|
||||||
if ($scope.selected > -1) {
|
if ($scope.selected > -1) {
|
||||||
$scope.$apply(function () {
|
$scope.$apply(function () {
|
||||||
var max = $scope.display.Body.length;
|
var max = $scope.display.Body.length;
|
||||||
$scope.hidden.push(angular.copy($scope.display.Body[$scope.selected]));
|
$scope.hidden.push($scope.display.Body[$scope.selected].ID);
|
||||||
if ($scope.selected === max -1) {
|
if ($scope.selected === max - 1) {
|
||||||
$scope.selected = max - 2;
|
$scope.selected = max - 2;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,16 +1,15 @@
|
||||||
import datetime
|
import datetime
|
||||||
|
import uuid
|
||||||
|
|
||||||
import pkg_resources
|
import pkg_resources
|
||||||
from pyramid.response import FileResponse
|
from pyramid.response import FileResponse
|
||||||
from sqlalchemy.orm import joinedload_all
|
from sqlalchemy.orm import joinedload_all
|
||||||
from sqlalchemy.sql.expression import func
|
from sqlalchemy.sql.expression import func
|
||||||
import uuid
|
|
||||||
|
|
||||||
from pyramid.view import view_config
|
from pyramid.view import view_config
|
||||||
|
|
||||||
from brewman.models import DBSession
|
from brewman.models import DBSession
|
||||||
from brewman.models.master import LedgerBase
|
from brewman.models.master import LedgerBase
|
||||||
from brewman.models.validation_exception import TryCatchFunction
|
from brewman.models.validation_exception import TryCatchFunction
|
||||||
|
|
||||||
from brewman.models.voucher import Voucher, Journal, VoucherType
|
from brewman.models.voucher import Voucher, Journal, VoucherType
|
||||||
from brewman.views.services.session import session_period_start, session_period_finish
|
from brewman.views.services.session import session_period_start, session_period_finish
|
||||||
from brewman.views.services.voucher import get_edit_url
|
from brewman.views.services.voucher import get_edit_url
|
||||||
|
@ -33,8 +32,8 @@ def show_blank(request):
|
||||||
@view_config(request_method='GET', route_name='api_ledger_id', renderer='json', permission='Ledger')
|
@view_config(request_method='GET', route_name='api_ledger_id', renderer='json', permission='Ledger')
|
||||||
@TryCatchFunction
|
@TryCatchFunction
|
||||||
def show_data(request):
|
def show_data(request):
|
||||||
id = request.matchdict['id']
|
ledger_id = request.matchdict['id']
|
||||||
ledger = LedgerBase.by_id(uuid.UUID(id))
|
ledger = LedgerBase.by_id(uuid.UUID(ledger_id))
|
||||||
start_date = request.GET.get('StartDate', session_period_start(request))
|
start_date = request.GET.get('StartDate', session_period_start(request))
|
||||||
finish_date = request.GET.get('FinishDate', session_period_finish(request))
|
finish_date = request.GET.get('FinishDate', session_period_finish(request))
|
||||||
info = {'StartDate': start_date, 'FinishDate': finish_date,
|
info = {'StartDate': start_date, 'FinishDate': finish_date,
|
||||||
|
@ -48,7 +47,7 @@ def build_report(request, info):
|
||||||
ledger_id = info['Ledger']['LedgerID']
|
ledger_id = info['Ledger']['LedgerID']
|
||||||
start_date = info['StartDate']
|
start_date = info['StartDate']
|
||||||
finish_date = info['FinishDate']
|
finish_date = info['FinishDate']
|
||||||
total_debit, total_credit, running_total, opening = opening_balance(ledger_id, start_date)
|
opening = opening_balance(ledger_id, start_date)
|
||||||
info['Body'].append(opening)
|
info['Body'].append(opening)
|
||||||
|
|
||||||
query = Voucher.query().options(joinedload_all(Voucher.journals, Journal.ledger, innerjoin=True)) \
|
query = Voucher.query().options(joinedload_all(Voucher.journals, Journal.ledger, innerjoin=True)) \
|
||||||
|
@ -65,37 +64,31 @@ def build_report(request, info):
|
||||||
name = ""
|
name = ""
|
||||||
for journal in voucher.journals:
|
for journal in voucher.journals:
|
||||||
if journal.ledger_id == ledger_id:
|
if journal.ledger_id == ledger_id:
|
||||||
if voucher.posted:
|
|
||||||
running_total += (journal.amount * journal.debit)
|
|
||||||
journal_debit = journal.debit
|
journal_debit = journal.debit
|
||||||
if journal.debit == 1:
|
if journal.debit == 1:
|
||||||
debit = journal.amount
|
debit = journal.amount
|
||||||
total_debit += journal.amount
|
|
||||||
credit = 0
|
credit = 0
|
||||||
else:
|
else:
|
||||||
credit = journal.amount
|
credit = journal.amount
|
||||||
total_credit += journal.amount
|
|
||||||
debit = 0
|
debit = 0
|
||||||
for journal in voucher.journals:
|
for journal in voucher.journals:
|
||||||
if journal.debit != journal_debit:
|
if journal.debit != journal_debit:
|
||||||
name += "{0} / ".format(journal.ledger.name)
|
name += "{0} / ".format(journal.ledger.name)
|
||||||
name = name[:-3]
|
name = name[:-3]
|
||||||
info['Body'].append(
|
info['Body'].append(
|
||||||
{'Date': voucher.date.strftime('%d-%b-%Y'), 'Name': name, 'Url': get_edit_url(request, voucher),
|
{'ID': voucher.id, 'Date': voucher.date.strftime('%d-%b-%Y'), 'Name': name,
|
||||||
'Type': VoucherType.by_id(voucher.type).name, 'Narration': voucher.narration, 'Debit': debit,
|
'Url': get_edit_url(request, voucher), 'Type': VoucherType.by_id(voucher.type).name,
|
||||||
'Credit': credit, 'Running': running_total, 'Posted': voucher.posted})
|
'Narration': voucher.narration, 'Debit': debit, 'Credit': credit, 'Posted': voucher.posted})
|
||||||
|
|
||||||
info['Footer'] = {'Date': finish_date, 'Name': 'Closing Balance', 'Type': 'Closing Balance',
|
info['Footer'] = {'Date': finish_date}
|
||||||
'Narration': '', 'Debit': total_debit, 'Credit': total_credit,
|
|
||||||
'Running': running_total, 'Posted': True}
|
|
||||||
|
|
||||||
|
|
||||||
def opening_balance(ledgerID, start_date):
|
def opening_balance(ledger_id, start_date):
|
||||||
opening = DBSession.query(func.sum(Journal.amount * Journal.debit)) \
|
opening = DBSession.query(func.sum(Journal.amount * Journal.debit)) \
|
||||||
.join(Journal.voucher) \
|
.join(Journal.voucher) \
|
||||||
.filter(Voucher.date < datetime.datetime.strptime(start_date, '%d-%b-%Y')) \
|
.filter(Voucher.date < datetime.datetime.strptime(start_date, '%d-%b-%Y')) \
|
||||||
.filter(Voucher.type != VoucherType.by_name('Issue').id) \
|
.filter(Voucher.type != VoucherType.by_name('Issue').id) \
|
||||||
.filter(Journal.ledger_id == ledgerID) \
|
.filter(Journal.ledger_id == ledger_id) \
|
||||||
.scalar()
|
.scalar()
|
||||||
opening = 0 if opening is None else opening
|
opening = 0 if opening is None else opening
|
||||||
if opening < 0:
|
if opening < 0:
|
||||||
|
@ -104,7 +97,7 @@ def opening_balance(ledgerID, start_date):
|
||||||
else:
|
else:
|
||||||
debit = opening
|
debit = opening
|
||||||
credit = 0
|
credit = 0
|
||||||
return 0, 0, opening, {'Date': start_date, 'Name': 'Opening Balance', 'Type': 'Opening Balance',
|
return {'Date': start_date, 'ID': 'OB', 'Name': 'Opening Balance', 'Type': 'Opening Balance',
|
||||||
'Narration': '', 'Debit': debit, 'Credit': credit, 'Running': opening, 'Posted': True}
|
'Narration': '', 'Debit': debit, 'Credit': credit, 'Posted': True}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue