Update: Changed the Reconcile report so that it shows all the unreconciled entries and also shows the balance according to the reconcile date.

This commit is contained in:
tanshu 2016-04-12 13:57:24 +05:30
parent 33c385ea91
commit e868a213b1
6 changed files with 87 additions and 56 deletions
brewman

@ -49,8 +49,8 @@
<th>Reconcile Date</th>
</tr>
</thead>
<tbody ng-repeat="item in info.Body">
<tr ng-class="{warning:item.IsReconciled}">
<tbody ng-repeat="item in body">
<tr ng-class="{danger:!item.IsReconciled && $index!=selected, warning:$index==selected}">
<td class="no-wrap">{{item.Date}}</td>
<td><a href="{{item.Url}}">{{item.Name}}</a></td>
<td class="text-right no-wrap">{{item.Debit | currency | clr}}</td>
@ -70,7 +70,7 @@
</td>
</tr>
<tr>
<td colspan="6"ng-class="{warning:item.IsReconciled}">
<td colspan="6"ng-class="{danger:!item.IsReconciled && $index!=selected, warning:$index==selected}">
<blockquote>
<p>{{item.Narration}}</p>
<small>{{item.Type}}</small>
@ -80,11 +80,11 @@
</tbody>
<tfoot>
<tr>
<td class="no-wrap">{{info.Footer.Date}}</td>
<td>{{info.Footer.Name}}</td>
<td class="text-right no-wrap">{{info.Footer.Debit | currency}}</td>
<td class="text-right no-wrap">{{info.Footer.Credit | currency}}</td>
<td class="text-right no-wrap">{{info.Footer.Running | accounting}}</td>
<td class="no-wrap"></td>
<td></td>
<td class="text-right no-wrap">{{footer.Debit | currency}}</td>
<td class="text-right no-wrap">{{footer.Credit | currency}}</td>
<td class="text-right no-wrap">{{footer.Running | accounting}}</td>
<td></td>
</tr>
</tfoot>

@ -35,15 +35,7 @@ var LedgerController = ['$scope', '$routeParams', '$location', 'asDateFilter', '
$scope.selected = index;
};
// Replace with $watchGroup in AngularJS 1.3+
$scope.$watch('hidden', function () {
var filtered = $scope.doFilter($scope.hidden, $scope.info.Body);
$scope.ledger = filtered.Body;
$scope.footer = filtered.Footer;
}, true);
$scope.$watch('info', function () {
$scope.$watch(['info', 'hidden'], function () {
var filtered = $scope.doFilter($scope.hidden, $scope.info.Body);
$scope.ledger = filtered.Body;
$scope.footer = filtered.Footer;

@ -14,15 +14,21 @@ var ReconcileController = ['$scope', '$routeParams', '$location', 'asDateFilter'
$location.path('/Reconcile/' + id).search('StartDate', startDate).search('FinishDate', finishDate);
}
};
$scope.save = function () {
var i, l,
len = $scope.info.Body.length;
for (i = 0, l = len; i < l; i++) {
var i,
len = $scope.body.length;
$scope.info.Body = $scope.body;
for (i = 0; i < len; i++) {
$scope.info.Body[i].ReconcileDate = asDate($scope.info.Body[i].ReconcileDate);
}
$scope.info.$save({StartDate: $routeParams.StartDate, FinishDate: $routeParams.FinishDate}, function (u, putResponseHeaders) {
$scope.info.$save({
StartDate: $routeParams.StartDate,
FinishDate: $routeParams.FinishDate
}, function (u, putResponseHeaders) {
$scope.toasts.push({Type: 'Success', Message: ''});
$scope.info = u;
$scope.doFilter();
}, function (data, status) {
$scope.toasts.push({Type: 'Danger', Message: data.data});
});
@ -46,22 +52,57 @@ var ReconcileController = ['$scope', '$routeParams', '$location', 'asDateFilter'
$scope.selected = index;
};
$scope.doFilter = function () {
var data = angular.copy($scope.info.Body),
debit = 0, credit = 0, running = 0;
data = data.sort(function (a, b) {
if (a.IsReconciled !== b.IsReconciled) {
return b.IsReconciled - a.IsReconciled;
}
var aDate = moment(a.ReconcileDate, 'DD-MMM-YYYY');
var bDate = moment(b.ReconcileDate, 'DD-MMM-YYYY');
return aDate - bDate;
});
_.forEach(data, function (item) {
if (item.Type !== 'Opening Balance') {
debit += item.Debit;
credit += item.Credit;
if (item.IsReconciled) {
running += item.Debit - item.Credit;
}
} else {
running += item.Debit - item.Credit;
}
item.Running = running;
});
$scope.body = data;
$scope.footer = {
Debit: debit,
Credit: credit,
Running: running
}
};
$scope.doFilter();
$scope.shortcuts = {
'up': function (e) {
if ($scope.selected > 0) {
$scope.$apply(function () {
$scope.selected = $scope.selected -= 1;
$scope.selected = Math.min(Math.max(0, $scope.selected - 1), $scope.ledger.length - 1);
});
$("#" + $scope.selected).scrollintoview({duration: 'fast'});
$("#" + $scope.selected).scrollintoview();
e.preventDefault();
}
},
'down': function (e) {
if ($scope.selected < $scope.info.Body.length - 1) {
$scope.$apply(function () {
$scope.selected = $scope.selected += 1;
$scope.selected = Math.min(Math.max(0, $scope.selected + 1), $scope.ledger.length - 1);
});
$("#" + $scope.selected).scrollintoview({duration: 'fast'});
$("#" + $scope.selected).scrollintoview();
e.preventDefault();
}
},
@ -70,6 +111,7 @@ var ReconcileController = ['$scope', '$routeParams', '$location', 'asDateFilter'
$scope.$apply(function () {
$location.path(path).search('StartDate', null).search('FinishDate', null);
});
e.preventDefault();
}
};
@ -91,5 +133,3 @@ ReconcileController.resolve = {
}
}]
};

@ -13,7 +13,6 @@ from brewman.models.validation_exception import TryCatchFunction
from brewman.models.voucher import Journal, Voucher, VoucherType, Batch, Inventory, SalaryDeduction, Fingerprint, \
Attendance, DbImage
__author__ = 'tanshu'

@ -223,7 +223,7 @@ def product_info(id):
def delete_with_data(product):
suspense_product = Product.by_id(Product.suspense())
suspense_batch = Batch.by_id(Batch.suspense())
query = Voucher.query().options(joinedload_all(Voucher.inventories, Inventory.product, innerjoin=True)) \
query = Voucher.query().options(joinedload_all(Voucher.inventories, Inventory.product, innerjoin=True) ) \
.filter(Voucher.inventories.any(Inventory.product_id == product.id)) \
.all()

@ -2,7 +2,7 @@ import datetime
import pkg_resources
from pyramid.response import FileResponse
from sqlalchemy.orm import joinedload_all
from sqlalchemy.sql.expression import func
from sqlalchemy.sql.expression import func, or_, and_
import uuid
from pyramid.view import view_config
@ -28,7 +28,7 @@ def html(request):
@view_config(request_method='GET', route_name='api_reconcile', renderer='json', permission='Reconcile')
def show_blank(request):
return {'StartDate': session_period_start(request),
'FinishDate': session_period_finish(request), 'Ledger': None, 'Body': [], 'Footer': {}}
'FinishDate': session_period_finish(request), 'Ledger': None, 'Body': []}
@view_config(request_method='GET', route_name='api_reconcile_id', renderer='json', permission='Reconcile')
@ -39,8 +39,7 @@ def show_data(request):
start_date = request.GET.get('StartDate', session_period_start(request))
finish_date = request.GET.get('FinishDate', session_period_finish(request))
info = {'StartDate': start_date, 'FinishDate': finish_date,
'Account': {'LedgerID': account.id, 'Name': account.name},
'Body': [], 'Footer': {}}
'Account': {'LedgerID': account.id, 'Name': account.name}, 'Body': []}
build_report(request, info)
return info
@ -49,15 +48,24 @@ def build_report(request, info):
ledger_id = info['Account']['LedgerID']
start_date = info['StartDate']
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)
query = Voucher.query().options(joinedload_all(Voucher.journals, Journal.ledger, innerjoin=True)) \
.filter(Voucher.journals.any(Journal.ledger_id == ledger_id)) \
.filter(Voucher.date >= datetime.datetime.strptime(start_date, '%d-%b-%Y')) \
.filter(Voucher.date <= datetime.datetime.strptime(finish_date, '%d-%b-%Y')) \
.filter(Voucher.type != VoucherType.by_name('Issue').id) \
.order_by(Voucher.reconcile_date).order_by(Voucher.last_edit_date).all()
query = Voucher.query().options(
joinedload_all(Voucher.journals, Journal.ledger, innerjoin=True)
).filter(
Voucher.journals.any(Journal.ledger_id == ledger_id)
).filter(
or_(
Voucher.is_reconciled == False,
and_(
Voucher.reconcile_date >= datetime.datetime.strptime(start_date, '%d-%b-%Y'),
Voucher.reconcile_date <= datetime.datetime.strptime(finish_date, '%d-%b-%Y')
)
)
).filter(
Voucher.type != VoucherType.by_name('Issue').id
).order_by(Voucher.is_reconciled).order_by(Voucher.reconcile_date).order_by(Voucher.last_edit_date).all()
for voucher in query:
debit = 0
@ -66,17 +74,13 @@ def build_report(request, info):
name = ""
for journal in voucher.journals:
if journal.ledger_id == ledger_id:
if voucher.posted:
running_total += (journal.amount * journal.debit)
journal_debit = journal.debit
if journal.debit == 1:
debit = journal.amount
total_debit += journal.amount
credit = ""
credit = 0
else:
credit = journal.amount
total_credit += journal.amount
debit = ""
debit = 0
for journal in voucher.journals:
if journal.debit != journal_debit:
name += "{0} / ".format(journal.ledger.name)
@ -84,18 +88,15 @@ def build_report(request, info):
info['Body'].append(
{'VoucherID': voucher.id, 'Date': voucher.date.strftime('%d-%b-%Y'), 'Name': name,
'Url': get_edit_url(request, voucher), 'Type': VoucherType.by_id(voucher.type).name,
'Narration': voucher.narration, 'Debit': debit, 'Credit': credit, 'Running': running_total,
'ReconcileDate': voucher.reconcile_date.strftime('%d-%b-%Y'), 'IsReconciled': voucher.is_reconciled})
info['Footer'] = {'Date': finish_date, 'Name': 'Closing Balance', 'Type': 'Closing Balance',
'Narration': '', 'Debit': total_debit, 'Credit': total_credit,
'Running': running_total, 'Posted': True}
'Narration': voucher.narration, 'Debit': debit, 'Credit': credit, 'IsReconciled': voucher.is_reconciled,
'ReconcileDate': voucher.reconcile_date.strftime('%d-%b-%Y')})
def opening_balance(ledgerID, start_date):
opening = DBSession.query(func.sum(Journal.amount * Journal.debit)) \
.join(Journal.voucher) \
.filter(Voucher.date < datetime.datetime.strptime(start_date, '%d-%b-%Y')) \
.filter(Voucher.reconcile_date < datetime.datetime.strptime(start_date, '%d-%b-%Y')) \
.filter(Voucher.is_reconciled == True) \
.filter(Voucher.type != VoucherType.by_name('Issue').id) \
.filter(Journal.ledger_id == ledgerID) \
.scalar()
@ -106,8 +107,8 @@ def opening_balance(ledgerID, start_date):
else:
debit = opening
credit = 0
return 0, 0, opening, {'Date': start_date, 'Name': 'Opening Balance', 'Type': 'Opening Balance',
'Narration': '', 'Debit': debit, 'Credit': credit, 'Running': opening, 'Posted': True}
return {'Date': start_date, 'ID': 'OB', 'Name': 'Opening Balance', 'Type': 'Opening Balance',
'Narration': '', 'Debit': debit, 'Credit': credit, 'Running': opening, 'Posted': True}
@view_config(request_method='POST', route_name='api_reconcile_id', renderer='json', permission='Reconcile')
@ -131,4 +132,3 @@ def save(request):
'Body': [], 'Footer': {}}
build_report(request, info)
return info