From 89600d2cabf7825f1fa96ba4ce7ed70d2c12a78c Mon Sep 17 00:00:00 2001 From: Tanshu Date: Sat, 13 Oct 2012 20:04:40 +0530 Subject: [PATCH] Receipt Done --- brewman/brewman/static/partial/receipt.html | 99 +++++++++++++++ .../brewman/static/scripts/autocomplete.js | 4 +- brewman/brewman/static/scripts/receipt.js | 32 +++-- brewman/brewman/templates/angular_base.mako | 1 + brewman/brewman/templates/base.mako | 1 + .../templates/transaction/receipt.mako | 117 ------------------ .../brewman/views/transactions/__init__.py | 4 + brewman/brewman/views/transactions/receipt.py | 32 ----- 8 files changed, 128 insertions(+), 162 deletions(-) create mode 100644 brewman/brewman/static/partial/receipt.html delete mode 100644 brewman/brewman/templates/transaction/receipt.mako delete mode 100644 brewman/brewman/views/transactions/receipt.py diff --git a/brewman/brewman/static/partial/receipt.html b/brewman/brewman/static/partial/receipt.html new file mode 100644 index 00000000..be356da2 --- /dev/null +++ b/brewman/brewman/static/partial/receipt.html @@ -0,0 +1,99 @@ +
+
+ + +
+ +
+
+
+ + +
+ +
+
+
+ + +
+ + +
+ +
+
+
+
+ + +
+ +
+ + +
+ +
+
+ +
+ + +
+ + + + + + + + + + + + + + + + + +
NameAmountDelete
{{journal.Ledger.Name}}{{journal.Amount}} + +
+
+
+
+ + +
+ +
+
+
+ + + + +
+
+ Created on {{voucher.CreationDate}} and Last Edited on {{voucher.LastEditDate}} by {{voucher.User}}. Posted + by {{voucher.Poster}} +
+
diff --git a/brewman/brewman/static/scripts/autocomplete.js b/brewman/brewman/static/scripts/autocomplete.js index 6d5e9f14..f1a9bd6a 100644 --- a/brewman/brewman/static/scripts/autocomplete.js +++ b/brewman/brewman/static/scripts/autocomplete.js @@ -7,8 +7,8 @@ when('/Payment', {templateUrl: '/partial/payment.html', controller: PaymentCtrl}). when('/Payment/:id', {templateUrl: '/partial/payment.html', controller: PaymentCtrl}). -// when('/Receipt', {templateUrl: '/partial/receipt.html', controller: ReceiptCtrl}). -// when('/Receipt/:id', {templateUrl: '/partial/receipt.html', controller: ReceiptCtrl}). + when('/Receipt', {templateUrl: '/partial/receipt.html', controller: ReceiptCtrl}). + when('/Receipt/:id', {templateUrl: '/partial/receipt.html', controller: ReceiptCtrl}). when('/Ledger', {templateUrl: '/partial/ledger.html', controller: LedgerCtrl}). when('/Ledger/:id', {templateUrl: '/partial/ledger.html', controller: LedgerCtrl}). diff --git a/brewman/brewman/static/scripts/receipt.js b/brewman/brewman/static/scripts/receipt.js index ec2a6eb2..7be50807 100644 --- a/brewman/brewman/static/scripts/receipt.js +++ b/brewman/brewman/static/scripts/receipt.js @@ -1,6 +1,11 @@ -function ReceiptCtrl($scope, Voucher) { - $scope.voucher = new Voucher(voucher); - $scope.ledgers = ledgers; +function ReceiptCtrl($scope, $routeParams, $location, Voucher, LedgerService) { + if (typeof $routeParams.id === 'undefined') { + $scope.voucher = Voucher.get({type:'Receipt'}); + } else { + $scope.voucher = Voucher.get({id:$routeParams.id}); + } + + $scope.ledgers = LedgerService.query({type:1}); $scope.addJournal = function () { for (var i = 0, l = this.voucher.Journals.length; i < l; i++) { @@ -24,6 +29,7 @@ delete $scope.name; $('#txtLedger').focus(); }; + $scope.removeJournal = function (journal) { var index = this.voucher.Journals.indexOf(journal); this.voucher.Journals.splice(index, 1); @@ -31,15 +37,17 @@ $scope.$watch('voucher.Journals', function (journals, oldValue) { var amount = 0; - for (var i = 0, l = journals.length; i < l; i++) { - if (journals[i].Debit === 1) { - var debitJournal = journals[i]; - } else { - amount += Number(journals[i].Amount); + if (typeof journals !== 'undefined') { + for (var i = 0, l = journals.length; i < l; i++) { + if (journals[i].Debit === 1) { + var debitJournal = journals[i]; + } else { + amount += Number(journals[i].Amount); + } + } + if (debitJournal.Amount !== amount) { + debitJournal.Amount = amount; } - } - if (debitJournal.Amount !== amount) { - debitJournal.Amount = amount; } }, true); @@ -54,6 +62,7 @@ $scope.save = function () { $scope.voucher.$save(function (u, putResponseHeaders) { $scope.toasts.push({Type:'Success', Message:u.Code}); + $location.path('/Receipt/' + u.VoucherID) }, function (data, status) { $scope.toasts.push({Type:'Error', Message:data.data}); }); @@ -62,6 +71,7 @@ $scope.delete = function () { $scope.voucher.$delete(function (u, putResponseHeaders) { $scope.toasts.push({Type:'Success', Message:''}); + $location.path('/Receipt') }, function (data, status) { $scope.toasts.push({Type:'Error', Message:data.data}); }); diff --git a/brewman/brewman/templates/angular_base.mako b/brewman/brewman/templates/angular_base.mako index 6725b910..b4eaa543 100644 --- a/brewman/brewman/templates/angular_base.mako +++ b/brewman/brewman/templates/angular_base.mako @@ -39,6 +39,7 @@ ${h.ScriptLink(request, 'journal.js')} ${h.ScriptLink(request, 'payment.js')} + ${h.ScriptLink(request, 'receipt.js')} ${h.ScriptLink(request, 'ledger.js')} ${h.ScriptLink(request, 'trial_balance.js')} diff --git a/brewman/brewman/templates/base.mako b/brewman/brewman/templates/base.mako index e3de6064..05f6344f 100644 --- a/brewman/brewman/templates/base.mako +++ b/brewman/brewman/templates/base.mako @@ -38,6 +38,7 @@ ${h.ScriptLink(request, 'journal.js')} ${h.ScriptLink(request, 'payment.js')} + ${h.ScriptLink(request, 'receipt.js')} ${h.ScriptLink(request, 'ledger.js')} ${h.ScriptLink(request, 'trial_balance.js')} diff --git a/brewman/brewman/templates/transaction/receipt.mako b/brewman/brewman/templates/transaction/receipt.mako deleted file mode 100644 index 084286ec..00000000 --- a/brewman/brewman/templates/transaction/receipt.mako +++ /dev/null @@ -1,117 +0,0 @@ -# -*- coding: utf-8 -*- -<%inherit file="../base.mako"/> -<%block name="header"> - ${h.ScriptLink(request, 'receipt.js')} - - - -<%block name="content"> -
- ${h.CsrfToken(request.session)} -
- - -
- -
-
-
- - -
- -
-
-
- - - -
- - -
- -
-
-
-
- - -
- -
- - -
- -
-
- -
- - -
- - - - - - - - - - - - - - - - - -
NameAmountDelete
{{journal.Ledger.Name}}{{journal.Amount}} - -
-
-
-
- - -
- -
-
-
- - - - -
-
- Created on {{voucher.CreationDate}} and Last Edited on {{voucher.LastEditDate}} by {{voucher.User}}. Posted - by {{voucher.Poster}} -
-
- \ No newline at end of file diff --git a/brewman/brewman/views/transactions/__init__.py b/brewman/brewman/views/transactions/__init__.py index c600a8af..ce1b9562 100644 --- a/brewman/brewman/views/transactions/__init__.py +++ b/brewman/brewman/views/transactions/__init__.py @@ -3,6 +3,10 @@ from pyramid.view import view_config from brewman.helpers import Literal +@view_config(request_method='GET', route_name='receipt_id', renderer='brewman:templates/angular_base.mako', + permission='Receipt Update') +@view_config(request_method='GET', route_name='receipt', renderer='brewman:templates/angular_base.mako', + permission='Receipt Create') @view_config(request_method='GET', route_name='journal_id', renderer='brewman:templates/angular_base.mako', permission='Journal Update') @view_config(request_method='GET', route_name='journal', renderer='brewman:templates/angular_base.mako', diff --git a/brewman/brewman/views/transactions/receipt.py b/brewman/brewman/views/transactions/receipt.py deleted file mode 100644 index b644edd6..00000000 --- a/brewman/brewman/views/transactions/receipt.py +++ /dev/null @@ -1,32 +0,0 @@ -import json -import uuid - -from pyramid.view import view_config -from brewman.helpers import Literal - -from brewman.models.voucher import Voucher - -from brewman.views import DecimalEncoder -from brewman.views.services.ledger import ledger_list -from brewman.views.services.voucher import voucher_info, blank_voucher -from brewman.views.transactions import session_current_date - - -@view_config(request_method='GET', route_name='receipt_id', renderer='brewman:templates/transaction/receipt.mako', - permission='Receipt Update') -@view_config(request_method='GET', route_name='receipt', renderer='brewman:templates/transaction/receipt.mako', - permission='Receipt Create') -def journal_get(request): - id = request.matchdict.get('id', None) - perms = Literal(json.dumps(request.session['perms'])) - ledgers = Literal(json.dumps(ledger_list(type=1))) - if id is None: - json_voucher = Literal(json.dumps(blank_voucher('Receipt', session_current_date(request)), cls=DecimalEncoder)) - else: - voucher = Voucher.by_id(uuid.UUID(id)) - json_voucher = Literal(json.dumps(voucher_info(voucher), cls=DecimalEncoder)) - return {'title': 'Hops n Grains - Receipt Entry', - 'id': id, - 'perms': perms, - 'ledgers': ledgers, - 'json_voucher': json_voucher}