diff --git a/brewman/brewman/__init__.py b/brewman/brewman/__init__.py index 8d983166..92e8b8d1 100644 --- a/brewman/brewman/__init__.py +++ b/brewman/brewman/__init__.py @@ -104,6 +104,8 @@ def main(global_config, **settings): add_route(config, 'product_ledger', '/ProductLedger', has_list=False) add_route(config, 'trial_balance', '/TrialBalance', has_list=False, variable='date') + config.add_route('api_net_transactions', '/api/NetTransactions') + config.add_route('net_transactions', '/NetTransactions') add_route(config, 'closing_stock', '/ClosingStock', has_list=False, variable='date') add_route(config, 'cash_flow', '/CashFlow', has_list=False) diff --git a/brewman/brewman/static/partial/net-transactions.html b/brewman/brewman/static/partial/net-transactions.html new file mode 100644 index 00000000..9a0565a8 --- /dev/null +++ b/brewman/brewman/static/partial/net-transactions.html @@ -0,0 +1,36 @@ +
+ Net Transactions +
+ + +
+ + + +
+
+
+ + +
+ + + + + + + + + + + + + + + + + +
TypeNameDebitCredit
{{item.Type}}{{item.Name}}{{item.Debit}}{{item.Credit}}
+
+
+
diff --git a/brewman/brewman/static/scripts/angular_service.js b/brewman/brewman/static/scripts/angular_service.js index 38599693..2997870f 100644 --- a/brewman/brewman/static/scripts/angular_service.js +++ b/brewman/brewman/static/scripts/angular_service.js @@ -122,6 +122,10 @@ overlord_service.factory('ProfitLoss', ['$resource', function ($resource) { return $resource('/api/ProfitLoss'); }]); +overlord_service.factory('NetTransactions', ['$resource', function ($resource) { + return $resource('/api/NetTransactions'); +}]); + overlord_service.factory('PurchaseEntries', ['$resource', function ($resource) { return $resource('/api/PurchaseEntries'); }]); diff --git a/brewman/brewman/static/scripts/net-transactions.js b/brewman/brewman/static/scripts/net-transactions.js new file mode 100644 index 00000000..df443dfa --- /dev/null +++ b/brewman/brewman/static/scripts/net-transactions.js @@ -0,0 +1,29 @@ +'use strict'; + +function NetTransactionsCtrl($scope, $location, net_transactions) { + $scope.info = net_transactions; + $scope.show = function () { + $location.path('/NetTransactions').search({StartDate:$scope.info.StartDate, FinishDate:$scope.info.FinishDate}); + }; + $('#txtStartDate').focus(); +} + +NetTransactionsCtrl.resolve = { + net_transactions:function ($q, $route, NetTransactions) { + var deferred = $q.defer(); + + var start_date = $route.current.params.StartDate; + var finish_date = $route.current.params.FinishDate; + + var successCb = function(result){ + deferred.resolve(result); + }; + + if (typeof start_date === 'undefined' || typeof finish_date === 'undefined') { + NetTransactions.get({}, successCb); + } else { + NetTransactions.get({StartDate:start_date, FinishDate:finish_date}, successCb); + } + return deferred.promise; + } +}; \ No newline at end of file diff --git a/brewman/brewman/static/scripts/overlord.js b/brewman/brewman/static/scripts/overlord.js index 14f7d487..ab32b478 100644 --- a/brewman/brewman/static/scripts/overlord.js +++ b/brewman/brewman/static/scripts/overlord.js @@ -49,6 +49,7 @@ var overlord = angular.module('overlord', ['overlord.directive', 'overlord.filte when('/Daybook', {templateUrl: '/partial/daybook.html', controller: DaybookCtrl, resolve: DaybookCtrl.resolve}). when('/Unposted', {templateUrl: '/partial/unposted.html', controller: UnpostedCtrl, resolve: UnpostedCtrl.resolve}). when('/ProfitLoss', {templateUrl: '/partial/profit-loss.html', controller: ProfitLossCtrl, resolve: ProfitLossCtrl.resolve}). + when('/NetTransactions', {templateUrl: '/partial/net-transactions.html', controller: NetTransactionsCtrl, resolve: NetTransactionsCtrl.resolve}). when('/PurchaseEntries', {templateUrl: '/partial/purchase-entries.html', controller: PurchaseEntriesCtrl, resolve: PurchaseEntriesCtrl.resolve}). when('/EmployeeFunctions', {templateUrl: '/partial/employee-functions.html', controller: EmployeeFunctionsCtrl}). diff --git a/brewman/brewman/templates/angular_base.mako b/brewman/brewman/templates/angular_base.mako index 84f3e429..6c78bcc3 100644 --- a/brewman/brewman/templates/angular_base.mako +++ b/brewman/brewman/templates/angular_base.mako @@ -57,6 +57,7 @@ + @@ -130,6 +131,7 @@ diff --git a/brewman/brewman/views/auth/client.py b/brewman/brewman/views/auth/client.py index ed3519ff..f8629285 100644 --- a/brewman/brewman/views/auth/client.py +++ b/brewman/brewman/views/auth/client.py @@ -11,6 +11,8 @@ from brewman.models.validation_exception import TryCatchFunction @view_config(request_method='GET', route_name='client_list', renderer='brewman:templates/angular_base.mako', permission='Clients') +@view_config(request_method='GET', route_name='client_id', renderer='brewman:templates/angular_base.mako', + permission='Clients') def html(request): return {} diff --git a/brewman/brewman/views/reports/net_transactions.py b/brewman/brewman/views/reports/net_transactions.py new file mode 100644 index 00000000..7114b529 --- /dev/null +++ b/brewman/brewman/views/reports/net_transactions.py @@ -0,0 +1,50 @@ +import datetime +from sqlalchemy.sql.expression import func, desc + +from pyramid.view import view_config + +from brewman.models import DBSession +from brewman.models.master import LedgerBase + +from brewman.models.voucher import Voucher, Journal, VoucherType +from brewman.views.services.session import session_period_finish, session_period_start + + +@view_config(request_method='GET', route_name='net_transactions', renderer='brewman:templates/angular_base.mako', + permission='Net Transactions') +def html(request): + return {} + + +@view_config(request_method='GET', route_name='api_net_transactions', renderer='json', permission='Net Transactions') +def report(request): + start_date = request.GET.get('StartDate', None) + finish_date = request.GET.get('FinishDate', None) + if start_date and finish_date: + return {'StartDate': start_date, 'FinishDate': finish_date, 'Body': build_report(start_date, finish_date)} + else: + return {'StartDate': session_period_start(request), + 'FinishDate': session_period_finish(request), 'Body': []} + + +def build_report(start_date, finish_date): + if not isinstance(start_date, datetime.datetime): + start_date = datetime.datetime.strptime(start_date, '%d-%b-%Y') + if not isinstance(finish_date, datetime.datetime): + finish_date = datetime.datetime.strptime(finish_date, '%d-%b-%Y') + + amount_sum = func.sum(Journal.amount * Journal.debit).label('Amount') + query = DBSession.query(LedgerBase, amount_sum) \ + .join(Journal.voucher).join(Journal.ledger) \ + .filter(Voucher.date >= start_date) \ + .filter(Voucher.date <= finish_date) \ + .filter(Voucher.type != VoucherType.by_name('Issue').id) \ + .group_by(LedgerBase).order_by(LedgerBase.type).order_by(desc(func.abs(amount_sum))).all() + + body = [] + for ledger, amount in query: + if amount != 0: + tag = 'Debit' if amount > 0 else 'Credit' + val = "\u20B9 {0:,.2f} Dr".format(amount) if amount > 0 else "\u20B9 {0:,.2f} Cr".format(amount * -1) + body.append({'Type': ledger.type_object.name, 'Name': ledger.name, tag: val}) + return body diff --git a/brewman/brewman/views/reports/trial_balance.py b/brewman/brewman/views/reports/trial_balance.py index e5e7a544..893431b1 100644 --- a/brewman/brewman/views/reports/trial_balance.py +++ b/brewman/brewman/views/reports/trial_balance.py @@ -13,7 +13,7 @@ from brewman.views.services.session import session_period_finish permission='Trial Balance') @view_config(request_method='GET', route_name='trial_balance_date', renderer='brewman:templates/angular_base.mako', permission='Trial Balance') -def ledger_display_get(request): +def html(request): return {} @view_config(request_method='GET', route_name='api_trial_balance', renderer='json', permission='Trial Balance')