From 7e03c14a896809b37503bc06a596af9c877ae9e0 Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Fri, 30 May 2014 17:17:54 -0400 Subject: [PATCH] more bills history; grid updates Signed-off-by: Bill Erickson --- Open-ILS/examples/fm_IDL.xml | 9 +- .../templates/staff/circ/patron/t_bill_history.tt2 | 79 +++----------- .../staff/circ/patron/t_bill_history_payments.tt2 | 86 +++++++++++++++ .../staff/circ/patron/t_bill_history_xacts.tt2 | 53 +++++++++ .../templates/staff/circ/patron/t_bills_list.tt2 | 3 +- .../staff/circ/patron/t_search_results.tt2 | 2 +- Open-ILS/src/templates/staff/css/style.css.tt2 | 2 +- .../web/js/ui/default/staff/circ/patron/app.js | 15 ++- .../web/js/ui/default/staff/circ/patron/bills.js | 121 +++++++++++++-------- Open-ILS/web/js/ui/default/staff/services/grid.js | 45 +++++++- 10 files changed, 295 insertions(+), 120 deletions(-) create mode 100644 Open-ILS/src/templates/staff/circ/patron/t_bill_history_payments.tt2 create mode 100644 Open-ILS/src/templates/staff/circ/patron/t_bill_history_xacts.tt2 diff --git a/Open-ILS/examples/fm_IDL.xml b/Open-ILS/examples/fm_IDL.xml index eceafd0870..006a26cf6c 100644 --- a/Open-ILS/examples/fm_IDL.xml +++ b/Open-ILS/examples/fm_IDL.xml @@ -6764,7 +6764,7 @@ SELECT usr, - + @@ -6791,6 +6791,13 @@ SELECT usr, + + + + + + + diff --git a/Open-ILS/src/templates/staff/circ/patron/t_bill_history.tt2 b/Open-ILS/src/templates/staff/circ/patron/t_bill_history.tt2 index 1795ff052f..6739d7e6bf 100644 --- a/Open-ILS/src/templates/staff/circ/patron/t_bill_history.tt2 +++ b/Open-ILS/src/templates/staff/circ/patron/t_bill_history.tt2 @@ -15,71 +15,20 @@
-
-
-
[% l('Selected Billed:') %]
-
{{selected_billed() | currency}}
-
[% l('Selected Paid:') %]
-
{{selected_paid() | currency}}
-
-
[% l('Start Date:') %]
-
-
[% l('End Date:') %]
-
-
-
- - - - - - - - - - - - - - - - - {{item.title}} - - - - - - - {{item.copy_barcode}} - - - - - - - - - - - - - -
- +
+
[% l('Selected Billed:') %]
+
{{totals.selected_billed() | currency}}
+
[% l('Selected Paid:') %]
+
{{totals.selected_paid() | currency}}
+
+
[% l('Start Date:') %]
+
+
[% l('End Date:') %]
+
+
+
+ [% INCLUDE 'staff/circ/patron/t_bill_history_xacts.tt2' %] + [% INCLUDE 'staff/circ/patron/t_bill_history_payments.tt2' %]
diff --git a/Open-ILS/src/templates/staff/circ/patron/t_bill_history_payments.tt2 b/Open-ILS/src/templates/staff/circ/patron/t_bill_history_payments.tt2 new file mode 100644 index 0000000000..cba0df1679 --- /dev/null +++ b/Open-ILS/src/templates/staff/circ/patron/t_bill_history_payments.tt2 @@ -0,0 +1,86 @@ + +
+ + + + + + + + + + + + + + + {{item.title}} + + + + + + + {{item.copy_barcode}} + + + + + + + + + + + + + + + + +
+ diff --git a/Open-ILS/src/templates/staff/circ/patron/t_bill_history_xacts.tt2 b/Open-ILS/src/templates/staff/circ/patron/t_bill_history_xacts.tt2 new file mode 100644 index 0000000000..d3b87b096c --- /dev/null +++ b/Open-ILS/src/templates/staff/circ/patron/t_bill_history_xacts.tt2 @@ -0,0 +1,53 @@ + +
+ + + + + + + + + + + + + + + + {{item.title}} + + + + + + + {{item.copy_barcode}} + + + + + + + + + + + + +
+ diff --git a/Open-ILS/src/templates/staff/circ/patron/t_bills_list.tt2 b/Open-ILS/src/templates/staff/circ/patron/t_bills_list.tt2 index d090ae3e51..1a4bdf7729 100644 --- a/Open-ILS/src/templates/staff/circ/patron/t_bills_list.tt2 +++ b/Open-ILS/src/templates/staff/circ/patron/t_bills_list.tt2 @@ -6,7 +6,8 @@ activate-item="activateBill" on-item-retrieved="gridItemRetrieved" - on-selection-change="gridSelectionChanged" + selected-items="getSelectedItems" + all-items="getAllItems" revision="gridRevision" persist-key="circ.patron.bills"> diff --git a/Open-ILS/src/templates/staff/circ/patron/t_search_results.tt2 b/Open-ILS/src/templates/staff/circ/patron/t_search_results.tt2 index 16ba3da07b..7d74f43e20 100644 --- a/Open-ILS/src/templates/staff/circ/patron/t_search_results.tt2 +++ b/Open-ILS/src/templates/staff/circ/patron/t_search_results.tt2 @@ -4,7 +4,7 @@ main-label="[% l('Patron Search Results') %]" items-provider="patronSearchGridProvider" activate-item="activatePatron" - on-selection-change="gridSelectionChanged" + selected-items="getSelectedItems" persist-key="circ.patron.search"> diff --git a/Open-ILS/src/templates/staff/css/style.css.tt2 b/Open-ILS/src/templates/staff/css/style.css.tt2 index 8cf4d15891..c30215b1f8 100644 --- a/Open-ILS/src/templates/staff/css/style.css.tt2 +++ b/Open-ILS/src/templates/staff/css/style.css.tt2 @@ -113,7 +113,7 @@ table.list tr.selected td { .pad-horiz {padding : 0px 10px 0px 10px; } .pad-vert {padding : 20px 0px 10px 0px;} -/*#print-div { display: none; }*/ +#print-div { display: none; } /* by default, give all tab panes some top padding */ .tab-pane { padding-top: 20px; } diff --git a/Open-ILS/web/js/ui/default/staff/circ/patron/app.js b/Open-ILS/web/js/ui/default/staff/circ/patron/app.js index 5d59b3e76d..8bbd044739 100644 --- a/Open-ILS/web/js/ui/default/staff/circ/patron/app.js +++ b/Open-ILS/web/js/ui/default/staff/circ/patron/app.js @@ -486,11 +486,16 @@ function($scope, $q, $routeParams, $timeout, $window, $location, egCore, return {offset : 0}; } - $scope.gridSelectionChanged = function(all) { - if (all[0]) - patronSvc.setDefault(null, all[0]); - } - + $scope.getSelectedItems = function() {return []}; + $scope.$watch( + function() {return $scope.getSelectedItems()}, + function(list) { + if (list[0]) + patronSvc.setDefault(null, list[0]); + }, + true + ); + provider.get = function(offset, count) { var deferred = $q.defer(); diff --git a/Open-ILS/web/js/ui/default/staff/circ/patron/bills.js b/Open-ILS/web/js/ui/default/staff/circ/patron/bills.js index 323179ebe1..7bdbd586b0 100644 --- a/Open-ILS/web/js/ui/default/staff/circ/patron/bills.js +++ b/Open-ILS/web/js/ui/default/staff/circ/patron/bills.js @@ -215,7 +215,8 @@ function($scope , $q , $routeParams , egCore , egConfirmDialog , $location, $scope.annotate_payment = false; $scope.gridRevision = 0; var allItems = []; // all grid items (flattened mbt's) - var selectedItems = []; // selected grid items + // until the grid wakes up, return empty set + $scope.getSelectedItems = $scope.getAllItems = function() {return []}; billSvc.fetchSummary().then(function(s) {$scope.summary = s}); @@ -236,7 +237,7 @@ function($scope , $q , $routeParams , egCore , egConfirmDialog , $location, // TODO: move me to service function selected_payment_info() { var info = {owed : 0, billed : 0, paid : 0}; - angular.forEach(selectedItems, function(item) { + angular.forEach($scope.getSelectedItems(), function(item) { info.owed += Number(item['summary.balance_owed']) * 100; info.billed += Number(item['summary.total_owed']) * 100; info.paid += Number(item['summary.total_paid']) * 100; @@ -264,7 +265,7 @@ function($scope , $q , $routeParams , egCore , egConfirmDialog , $location, } $scope.refunds_available = function() { var amount = 0; - angular.forEach(allItems, function(item) { + angular.forEach($scope.getAllItems(), function(item) { if (item['summary.balance_owed'] < 0) amount += item['summary.balance_owed'] * 100; }); @@ -282,15 +283,15 @@ function($scope , $q , $routeParams , egCore , egConfirmDialog , $location, $scope.gridItemRetrieved = function(item) { item.payment_pending = 0; - allItems.push(item); } - $scope.gridSelectionChanged = function(all) { - // update the item.payment_pending value each time the user - // selects different transactions to pay against. - selectedItems = all; - updatePendingColumn(); - } + // update the item.payment_pending value each time the user + // selects different transactions to pay against. + $scope.$watch( + function() {return $scope.getSelectedItems()}, + function() {updatePendingColumn()}, + true + ); // update the item.payment_pending for each (selected) // transaction any time the user-entered payment amount is modified @@ -302,12 +303,14 @@ function($scope , $q , $routeParams , egCore , egConfirmDialog , $location, // of our local scope variables. function updatePendingColumn() { // reset all to zero.. - angular.forEach(allItems, function(item) {item.payment_pending = 0}); + angular.forEach($scope.getAllItems(), + function(item) {item.payment_pending = 0}); var payment_amount = $scope.pending_payment(); - for (var i = 0; i < selectedItems.length; i++) { // for/break - var item = selectedItems[i]; + var selected = $scope.getSelectedItems(); + for (var i = 0; i < selected.length; i++) { // for/break + var item = selected[i]; var owed = Number(item['summary.balance_owed']); if (payment_amount > owed) { @@ -330,7 +333,7 @@ function($scope , $q , $routeParams , egCore , egConfirmDialog , $location, // which have a pending payment amount. function generatePayments() { var payments = []; - angular.forEach(selectedItems, function(item) { + angular.forEach($scope.getSelectedItems(), function(item) { if (item.payment_pending == 0) return; payments.push([item.id, item.payment_pending]); }); @@ -406,8 +409,6 @@ function($scope , $q , $routeParams , egCore , egConfirmDialog , $location, } $scope.printBills = function(selected) { - console.log('HEREEE'); - // bills print receipt assumes nested hashes, but our grid // stores flattener data. Fetch the selected xacts as // fleshed pcrud objects. (Consider an alternate approach..) @@ -419,7 +420,8 @@ function($scope , $q , $routeParams , egCore , egConfirmDialog , $location, {authoritative : true} ).then( function() { - egCore.hatch.printFromTemplate('receipt', 'bills_current', + egCore.hatch.printFromTemplate( + 'receipt', 'bills_current', { transactions : xacts, current_location : egCore.idl.toHash( egCore.org.get(egCore.auth.user().ws_ou())) @@ -645,16 +647,35 @@ function($scope, $q , $routeParams , egCore , patronSvc , billSvc , egPromptDia $scope.initTab('bills', $routeParams.id); billSvc.userId = $routeParams.id; $scope.bill_tab = $routeParams.history_tab; + $scope.totals = {}; - var selectedItems = []; - $scope.gridSelectionChanged = function(selected) { - selectedItems = selected; + var start = new Date(); // now - 1 year + start.setFullYear(start.getFullYear() - 1), + $scope.dates = { + xact_start : start, + xact_finish : new Date() + } + + $scope.date_range = function() { + var start = $scope.dates.xact_start.toISOString().replace(/T.*/,''); + var end = $scope.dates.xact_finish.toISOString().replace(/T.*/,''); + var today = new Date().toISOString().replace(/T.*/,''); + if (end == today) end = 'now'; + return [start, end]; } +}]) + + +.controller('BillXactHistoryCtrl', + ['$scope','$q','egCore','patronSvc','billSvc','egPromptDialog','$location', +function($scope, $q , egCore , patronSvc , billSvc , egPromptDialog , $location) { + $scope.getSelectedItems = function() {return []}; + // TODO; move me to service function selected_payment_info() { var info = {owed : 0, billed : 0, paid : 0}; - angular.forEach(selectedItems, function(item) { + angular.forEach($scope.getSelectedItems(), function(item) { info.owed += Number(item['summary.balance_owed']) * 100; info.billed += Number(item['summary.total_owed']) * 100; info.paid += Number(item['summary.total_paid']) * 100; @@ -665,41 +686,23 @@ function($scope, $q , $routeParams , egCore , patronSvc , billSvc , egPromptDia return info; } - $scope.selected_billed = function() { + $scope.totals.selected_billed = function() { return selected_payment_info().billed; } - $scope.selected_paid = function() { + $scope.totals.selected_paid = function() { return selected_payment_info().paid; } - var start = new Date(); // now - 1 year - start.setFullYear(start.getFullYear() - 1), - $scope.dates = { - xact_start : start, - xact_finish : new Date() - } - $scope.xactQuery = function() { - // strip the time for our search purposes - var start = $scope.dates.xact_start.toISOString().replace(/T.*/,''); - var end = $scope.dates.xact_finish.toISOString().replace(/T.*/,''); - var today = new Date().toISOString().replace(/T.*/,''); - // open-ils.actor.user.transactions.history.have_bill_or_payment - var query = { + return { '-or' : [ {'summary.balance_owed' : {'<>' : 0}}, {'summary.last_payment_ts' : {'<>' : null}} ], - xact_start : {'>=' : start}, + xact_start : {between : $scope.date_range()}, usr : billSvc.userId } - - // end date of today implies that xacts with a null xact_finish - // are also acceptable - if (end < today) query.xact_finish = {'<=' : end}; - - return query; } $scope.showFullDetails = function(all) { @@ -711,7 +714,39 @@ function($scope, $q , $routeParams , egCore , patronSvc , billSvc , egPromptDia $scope.showFullDetails([xact]); } +}]) + +.controller('BillPaymentHistoryCtrl', + ['$scope','$q','egCore','patronSvc','billSvc','$location', +function($scope, $q , egCore , patronSvc , billSvc , $location) { + $scope.getSelectedItems = function() {return []}; + + $scope.paymentSort = [{'payment_ts' : 'DESC'}, 'id']; + $scope.paymentQuery = function() { + return { + 'payment_ts' : {between : $scope.date_range()}, + 'xact.usr' : billSvc.userId + } + } + + $scope.showFullDetails = function(all) { + if (all[0]) + $location.path('/circ/patron/' + + patronSvc.current.id() + '/bill/' + all[0]['xact.id']); + } + $scope.activatePayment = function(payment) { + $scope.showFullDetails([payment]); + } + + $scope.totals.selected_paid = function() { + var paid = 0; + angular.forEach($scope.getSelectedItems(), function(payment) { + paid += Number(payment.amount) * 100; + }); + return paid / 100; + } }]) + diff --git a/Open-ILS/web/js/ui/default/staff/services/grid.js b/Open-ILS/web/js/ui/default/staff/services/grid.js index 6be5c1b48c..446b635ffd 100644 --- a/Open-ILS/web/js/ui/default/staff/services/grid.js +++ b/Open-ILS/web/js/ui/default/staff/services/grid.js @@ -73,15 +73,31 @@ angular.module('egGridMod', // are absorbed by the grid. onItemRetrieved : '=', + // TODO: deprecated // function called with all selected items each time the // selection set changes - onSelectionChange : '=', + //onSelectionChange : '=', // function; if set, row index values will be hyperlinked and // the onclick for an item will call activateItem with the item // as the argument. activateItem : '=', + // Function. Returns an array of selected items to the caller. + // The contents of this function are defined by the grid and + // called by the caller. + selectedItems : '=', + + // Function. Returns an array of all grid items. + // The contents of this function are defined by the grid and + // called by the caller. + allItems : '=', + + // Function. Accepts an array of index values. + // The contents of this function are defined by the grid and + // called by the caller. + //setSelected : '=', + // if set, we watch this scope variable for changes. If it // changes, we refresh the grid. revision : '=' @@ -188,12 +204,13 @@ angular.module('egGridMod', delete $scope.autoFields; } + /* if (grid.onSelectionChange) { $scope.$watch('selected', function() { grid.onSelectionChange(grid.getSelectedItems()) }, true); } - + */ if (!grid.dataProvider) { @@ -245,6 +262,28 @@ angular.module('egGridMod', return grid.selectOneItem(index); } + // only link the caller mediation functions into + // the scope if the caller defines handlers. + if ($scope.selectedItems) { + console.log('updating selecte..'); + $scope.selectedItems = function() { + return grid.getSelectedItems() + }; + } + if ($scope.allItems) { + $scope.allItems = function() { + return grid.items; + } + } + if ($scope.setSelected) { + $scope.setSelected = function(ids) { + $scope.selected = {}; + angular.forEach(ids, function(id) { + $scope.selected[''+id] = true; + }); + } + } + $scope.itemFieldValue = grid.dataProvider.itemFieldValue; $scope.indexValue = function(item) { return grid.indexValue(item) @@ -705,7 +744,7 @@ angular.module('egGridMod', $scope.printCSV = function() { $scope.gridColumnPickerIsOpen = false; - egCore.hatch.print('text/plain', grid.generateCSV()) + egCore.hatch.print('default', 'text/plain', grid.generateCSV()) .then(function() { console.debug('print complete') }); } -- 2.11.0