4 angular.module('egPatronApp')
7 ['$q','egCore','egWorkLog','patronSvc',
8 function($q , egCore , egWorkLog , patronSvc) {
12 // fetch org unit settings specific to the bills display
13 service.fetchBillSettings = function() {
14 if (service.settings) return $q.when(service.settings);
15 return egCore.org.settings(
16 ['ui.circ.billing.uncheck_bills_and_unfocus_payment_box','ui.circ.billing.amount_warn','ui.circ.billing.amount_limit','circ.staff_client.do_not_auto_attempt_print']
17 ).then(function(s) {return service.settings = s});
20 // user billing summary
21 service.fetchSummary = function() {
22 return egCore.pcrud.retrieve(
23 'mous', service.userId, {}, {authoritative : true})
24 .then(function(summary) {return service.summary = summary})
27 service.applyPayment = function(type, payments, note, check, cc_args) {
28 return egCore.net.request(
30 'open-ils.circ.money.payment',
31 egCore.auth.token(), {
32 userid : service.userId,
40 patronSvc.current.last_xact_id()
41 ).then(function(resp) {
42 console.debug('payments: ' + js2JSON(resp));
43 var total = 0; angular.forEach(payments,function(p) { total += p[1]; });
46 case 'cash_payment' : msg = egCore.strings.EG_WORK_LOG_CASH_PAYMENT; break;
47 case 'check_payment' : msg = egCore.strings.EG_WORK_LOG_CHECK_PAYMENT; break;
48 case 'credit_card_payment' : msg = egCore.strings.EG_WORK_LOG_CREDIT_CARD_PAYMENT; break;
49 case 'credit_payment' : msg = egCore.strings.EG_WORK_LOG_CREDIT_PAYMENT; break;
50 case 'work_payment' : msg = egCore.strings.EG_WORK_LOG_WORK_PAYMENT; break;
51 case 'forgive_payment' : msg = egCore.strings.EG_WORK_LOG_FORGIVE_PAYMENT; break;
52 case 'goods_payment' : msg = egCore.strings.EG_WORK_LOG_GOODS_PAYMENT; break;
56 'action' : 'paid_bill',
57 'patron_id' : service.userId,
58 'total_amount' : total
61 if (evt = egCore.evt.parse(resp))
64 // payment API returns the update xact id so we can track it
65 // for future payments without having to refresh the user.
66 patronSvc.current.last_xact_id(resp.last_xact_id);
71 service.fetchBills = function(xact_id) {
73 return egCore.pcrud.search('mb',
74 {xact : xact_id}, null,
75 {authoritative : true}
77 function() {return bills},
79 function(bill) {bills.push(bill); return bill}
83 // TODO: no longer needed?
84 service.fetchPayments = function(xact_id) {
85 return egCore.net.request(
87 'open-ils.circ.money.payment.retrieve.all.authoritative',
88 egCore.auth.token(), xact_id
92 service.voidBills = function(bill_ids) {
93 return egCore.net.requestWithParamList(
95 'open-ils.circ.money.billing.void',
96 [egCore.auth.token()].concat(bill_ids)
97 ).then(function(resp) {
98 if (evt = egCore.evt.parse(resp)) return alert(evt);
103 service.adjustBillsToZero = function(bill_ids) {
104 return egCore.net.request(
106 'open-ils.circ.money.billable_xact.adjust_to_zero',
109 ).then(function(resp) {
110 if (evt = egCore.evt.parse(resp)) return alert(evt);
115 service.updateBillNotes = function(note, ids) {
116 return egCore.net.requestWithParamList(
118 'open-ils.circ.money.billing.note.edit',
119 [egCore.auth.token(), note].concat(ids)
120 ).then(function(resp) {
121 if (evt = egCore.evt.parse(resp)) return alert(evt);
126 service.updatePaymentNotes = function(note, ids) {
127 return egCore.net.requestWithParamList(
129 'open-ils.circ.money.payment.note.edit',
130 [egCore.auth.token(), note].concat(ids)
131 ).then(function(resp) {
132 if (evt = egCore.evt.parse(resp)) return alert(evt);
144 .controller('PatronBillsCtrl',
145 ['$scope','$q','$routeParams','egCore','egConfirmDialog','$location',
146 'egGridDataProvider','billSvc','patronSvc','egPromptDialog', 'egAlertDialog',
147 'egBilling','$uibModal',
148 function($scope , $q , $routeParams , egCore , egConfirmDialog , $location,
149 egGridDataProvider , billSvc , patronSvc , egPromptDialog, egAlertDialog,
150 egBilling , $uibModal) {
152 $scope.initTab('bills', $routeParams.id);
153 billSvc.userId = $routeParams.id;
155 // set up some defaults
156 $scope.check_number = null;
157 $scope.payment_amount = null;
158 $scope.session_voided = 0;
159 $scope.payment_type = 'cash_payment';
160 $scope.focus_payment = true;
161 $scope.annotate_payment = false;
162 $scope.receipt_count = 1;
163 $scope.receipt_on_pay = { isChecked: false };
164 $scope.warn_amount = 1000;
165 $scope.max_amount = 100000;
166 $scope.amount_verified = false;
167 $scope.disable_auto_print = false;
169 // check receipt_on_pay setting default persisted
170 egCore.hatch.getItem('circ.bills.receiptonpay')
171 .then(function(rcptOnPay){
172 if (rcptOnPay) $scope.receipt_on_pay.isChecked = rcptOnPay;
175 // pre-define list-returning funcs in case we access them
176 // before the grid instantiates
177 $scope.gridControls = {
178 focusRowSelector : false,
179 selectedItems : function(){return []},
180 allItems : function(){return []},
181 itemRetrieved : function(item) {
182 item.payment_pending = 0;
184 activateItem : function(item) {
185 $scope.showFullDetails([item]);
187 setQuery : function() {
189 usr : billSvc.userId,
191 'summary.balance_owed' : {'<>' : 0}
194 setSort : function() {
195 return ['xact_start'];
199 billSvc.fetchSummary().then(function(s) {$scope.summary = s});
201 // given a payment amount, determines how much of that is applied
202 // to selected transactions and how much is left over (change).
203 function pending_payment_info() {
204 var amt = $scope.payment_amount || 0;
205 if (amt >= $scope.owed_selected()) {
207 payment : $scope.owed_selected(),
208 change : amt - $scope.owed_selected()
211 return {payment : amt, change : 0};
214 // calculates amount owed, billed, and paid for selected items
215 // TODO: move me to service
216 function selected_payment_info() {
217 var info = {owed : 0, billed : 0, paid : 0};
218 angular.forEach($scope.gridControls.selectedItems(), function(item) {
219 info.owed += Number(item['summary.balance_owed']) * 100;
220 info.billed += Number(item['summary.total_owed']) * 100;
221 info.paid += Number(item['summary.total_paid']) * 100;
229 $scope.pending_payment = function() {
230 return pending_payment_info().payment;
232 $scope.pending_change = function() {
233 return pending_payment_info().change;
235 $scope.owed_selected = function() {
236 return selected_payment_info().owed;
238 $scope.billed_selected = function() {
239 return selected_payment_info().billed;
241 $scope.paid_selected = function() {
242 return selected_payment_info().paid;
244 $scope.refunds_available = function() {
246 angular.forEach($scope.gridControls.allItems(), function(item) {
247 if (item['summary.balance_owed'] < 0)
248 amount += item['summary.balance_owed'] * 100;
250 return -(amount / 100);
252 $scope.invalid_check_number = function() {
253 return $scope.payment_type == 'check_payment' && ! $scope.check_number;
256 // update the item.payment_pending value each time the user
257 // selects different transactions to pay against.
259 function() {return $scope.gridControls.selectedItems()},
260 function() {updatePendingColumn()},
264 // update the item.payment_pending for each (selected)
265 // transaction any time the user-entered payment amount is modified
266 $scope.$watch('payment_amount', updatePendingColumn);
268 // updates the value of the payment_pending column in the grid.
269 // This has to be managed manually since the display value in the grid
270 // is derived from the value on the stored item and not the contents
271 // of our local scope variables.
272 function updatePendingColumn() {
273 // reset all to zero..
274 angular.forEach($scope.gridControls.allItems(),
275 function(item) {item.payment_pending = 0});
277 var payment_amount = $scope.pending_payment();
279 var selected = $scope.gridControls.selectedItems();
280 for (var i = 0; i < selected.length; i++) { // for/break
281 var item = selected[i];
282 var owed = Number(item['summary.balance_owed']);
284 if (payment_amount > owed) {
285 // pending payment exceeds balance of current item.
286 // pay the entire item.
287 item.payment_pending = owed;
288 payment_amount -= owed;
291 // balance owed on the current item matches or exceeds
292 // the pending payment. Apply the full remainder of
293 // the payment to this item.. and we're done.
294 item.payment_pending = payment_amount;
300 // builds payment arrays ([xact_id, ammount]) for all transactions
301 // which have a pending payment amount.
302 function generatePayments() {
304 angular.forEach($scope.gridControls.selectedItems(), function(item) {
305 if (item.payment_pending == 0) return;
306 payments.push([item.id, item.payment_pending]);
311 function refreshDisplay() {
312 patronSvc.fetchUserStats();
313 billSvc.fetchSummary().then(function(s) {$scope.summary = s});
314 $scope.payment_amount = null;
315 $scope.gridControls.refresh();
318 // generates payments, collects user note if needed, and sends payment
320 function sendPayment(note, cc_args) {
321 var make_payments = generatePayments();
322 billSvc.applyPayment($scope.payment_type,
323 make_payments, note, $scope.check_number, cc_args)
324 .then(function(payment_ids) {
326 if (!$scope.disable_auto_print && $scope.receipt_on_pay.isChecked) {
328 $scope.payment_type, payment_ids, make_payments, note);
335 $scope.onReceiptOnPayChanged = function(){
336 egCore.hatch.setItem('circ.bills.receiptonpay', $scope.receipt_on_pay.isChecked);
339 function printReceipt(type, payment_ids, payments_made, note) {
340 var payment_blobs = [];
341 angular.forEach(payments_made, function(payment) {
342 var xact_id = payment[0];
344 // find the original transaction in the grid..
345 var xact = $scope.gridControls.allItems().filter(
346 function(item) {return item.id == xact_id})[0];
349 xact : egCore.idl.flatToNestedHash(xact),
354 console.log(js2JSON(payment_blobs[0]));
356 // page data not yet refreshed, capture data from current scope
360 previous_balance : Number($scope.summary.balance_owed()),
361 payment_total : Number($scope.payment_amount),
362 payment_applied : $scope.pending_payment(),
363 amount_voided : Number($scope.session_voided),
364 change_given : $scope.pending_change(),
365 payments : payment_blobs,
366 current_location : egCore.idl.toHash(
367 egCore.org.get(egCore.auth.user().ws_ou()))
370 print_data.new_balance = (
371 print_data.previous_balance * 100 -
372 print_data.payment_applied * 100) / 100;
374 for (var i = 0; i < $scope.receipt_count; i++) {
377 template : 'bill_payment',
383 $scope.showHistory = function() {
384 $location.path('/circ/patron/' +
385 patronSvc.current.id() + '/bill_history/transactions');
388 // For now, only adds billing to first selected item.
389 // Could do batches later if needed
390 $scope.addBilling = function(all) {
392 egBilling.showBillDialog({
393 xact : egCore.idl.flatToNestedHash(all[0]),
394 patron : $scope.patron()
395 }).then(refreshDisplay);
399 $scope.showBillDialog = function($event) {
400 egBilling.showBillDialog({
401 patron : $scope.patron()
402 }).then(refreshDisplay);
405 // Select refunds adds all refunds to the existing selection.
406 // It does not /only/ select refunds
407 $scope.selectRefunds = function() {
408 var ids = $scope.gridControls.selectedItems().map(
409 function(i) { return i.id });
410 angular.forEach($scope.gridControls.allItems(), function(item) {
411 if (Number(item['summary.balance_owed']) < 0)
414 $scope.gridControls.selectItems(ids);
418 // determine on initial page load when all of the grid rows should
420 var selectOnLoad = true;
421 billSvc.fetchBillSettings().then(function(s) {
422 if (s['ui.circ.billing.uncheck_bills_and_unfocus_payment_box']) {
423 $scope.focus_payment = false; // de-focus the payment box
424 $scope.gridControls.focusRowSelector = true;
425 selectOnLoad = false;
426 // if somehow the grid finishes rendering before our settings
427 // arrive, manually de-select everything.
428 $scope.gridControls.selectItems([]);
430 if (s['ui.circ.billing.amount_warn']) {
431 $scope.warn_amount = Number(s['ui.circ.billing.amount_warn']);
433 if (s['ui.circ.billing.amount_limit']) {
434 $scope.max_amount = Number(s['ui.circ.billing.amount_limit']);
436 if (s['circ.staff_client.do_not_auto_attempt_print'] && angular.isArray(s['circ.staff_client.do_not_auto_attempt_print'])) {
437 $scope.disable_auto_print = Boolean(
438 s['circ.staff_client.do_not_auto_attempt_print'].indexOf('Bill Pay') > -1
443 $scope.gridControls.allItemsRetrieved = function() {
445 selectOnLoad = false; // only for initial controller load.
446 // select all non-refund items
447 $scope.gridControls.selectItems(
448 $scope.gridControls.allItems()
449 .filter(function(i) {return i['summary.balance_owed'] > 0})
450 .map(function(i){return i.id})
457 $scope.printBills = function(selected) {
458 if (!selected.length) return;
459 // bills print receipt assumes nested hashes, but our grid
460 // stores flattener data. Fetch the selected xacts as
461 // fleshed pcrud objects and hashify.
462 // (Consider an alternate approach..)
463 var ids = selected.map(function(t){ return t.id });
465 egCore.pcrud.search('mbt',
467 {flesh : 1, flesh_fields : {'mbt' : ['summary']}},
468 {authoritative : true}
473 template : 'bills_current',
475 transactions : xacts,
476 current_location : egCore.idl.toHash(
477 egCore.org.get(egCore.auth.user().ws_ou()))
483 xacts.push(egCore.idl.toHash(xact));
488 $scope.applyPayment = function() {
490 if ($scope.payment_amount > $scope.max_amount ) {
492 egCore.strings.PAYMENT_OVER_MAX,
493 { max_amount : ''+$scope.max_amount,
495 $scope.payment_amount = 0;
502 verify_payment_amount().then(
503 function() { // amount confirmed
504 add_payment_note().then(function(pay_note) {
505 add_cc_args().then(function(cc_args) {
506 sendPayment(pay_note.value, cc_args);
510 function() { // amount rejected
511 console.warn('payment amount rejected');
512 $scope.payment_amount = 0;
517 function verify_payment_amount() {
518 if ($scope.payment_amount < $scope.warn_amount)
521 return egConfirmDialog.open(
522 egCore.strings.PAYMENT_WARN_AMOUNT_TITLE,
523 egCore.strings.PAYMENT_WARN_AMOUNT,
524 {payment_amount : ''+$scope.payment_amount}
528 function add_payment_note() {
529 if (!$scope.annotate_payment) return $q.when();
530 return egPromptDialog.open(
531 egCore.strings.ANNOTATE_PAYMENT_MSG, '').result;
534 function add_cc_args() {
535 if ($scope.payment_type != 'credit_card_payment')
538 return $uibModal.open({
539 templateUrl : './circ/patron/t_cc_payment_dialog',
542 '$scope','$uibModalInstance',
543 function($scope , $uibModalInstance) {
547 where_process : '1', // internal=1 ; external=0
548 type : 'VISA', // external only
549 billing_first : patronSvc.current.first_given_name(),
550 billing_last : patronSvc.current.family_name()
554 var addr = patronSvc.current.billing_address() ||
555 patronSvc.current.mailing_address();
557 var cc = $scope.context.cc;
558 cc.billing_address = addr.street1() +
559 (addr.street2() ? ' ' + addr.street2() : '');
560 cc.billing_city = addr.city();
561 cc.billing_state = addr.state();
562 cc.billing_zip = addr.post_code();
565 $scope.ok = function() {
566 $uibModalInstance.close($scope.context.cc);
569 $scope.cancel = function() {
570 $uibModalInstance.dismiss();
577 $scope.voidAllBillings = function(items) {
581 angular.forEach(items, function(item) {
583 billSvc.fetchBills(item.id).then(function(bills) {
584 angular.forEach(bills, function(b) {
585 if (b.voided() != 't') {
586 cents += b.amount() * 100;
587 bill_ids.push(b.id())
591 if (bill_ids.length == 0) {
600 $q.all(promises).then(function(){
601 egCore.audio.play('warning.circ.void_billings_confirmation');
602 egConfirmDialog.open(
603 egCore.strings.CONFIRM_VOID_BILLINGS, '',
604 { billIds : ''+bill_ids,
605 amount : ''+(cents/100),
607 billSvc.voidBills(bill_ids).then(function() {
608 $scope.session_voided =
609 ($scope.session_voided * 100 + cents) / 100;
618 $scope.adjustToZero = function(items) {
619 if (items.length == 0) return;
621 var ids = items.map(function(item) {return item.id});
623 egCore.audio.play('warning.circ.adjust_to_zero_confirmation');
624 egConfirmDialog.open(
625 egCore.strings.CONFIRM_ADJUST_TO_ZERO, '',
628 billSvc.adjustBillsToZero(ids).then(function() {
637 // note this is functionally equivalent to selecting a neg. transaction
638 // then clicking Apply Payment -- this just adds a speed bump (ditto
640 $scope.refundXact = function(all) {
641 var items = all.filter(function(item) {
642 return item['summary.balance_owed'] < 0
645 if (items.length == 0) return;
647 var ids = items.map(function(item) {return item.id});
649 egCore.audio.play('warning.circ.refund_confirmation');
650 egConfirmDialog.open(
651 egCore.strings.CONFIRM_REFUND_PAYMENT, '',
654 // reset the received payment amount. this ensures
655 // we're not mingling payments with refunds.
656 $scope.payment_amount = 0;
662 // direct the user to the transaction details page
663 $scope.showFullDetails = function(all) {
665 $location.path('/circ/patron/' +
666 patronSvc.current.id() + '/bill/' + all[0].id);
669 $scope.activateBill = function(xact) {
670 $scope.showFullDetails([xact]);
676 * Displays details of a single transaction
678 .controller('XactDetailsCtrl',
679 ['$scope','$q','$routeParams','egCore','egGridDataProvider','patronSvc','billSvc','egPromptDialog','egBilling','egConfirmDialog',
680 function($scope, $q , $routeParams , egCore , egGridDataProvider , patronSvc , billSvc , egPromptDialog , egBilling , egConfirmDialog ) {
682 $scope.initTab('bills', $routeParams.id);
683 var xact_id = $routeParams.xact_id;
685 var xactGrid = $scope.xactGridControls = {
686 setQuery : function() { return {xact : xact_id} },
687 setSort : function() { return ['billing_ts'] }
690 var paymentGrid = $scope.paymentGridControls = {
691 setQuery : function() { return {xact : xact_id} },
692 setSort : function() { return ['payment_ts'] }
696 $scope.voidBillings = function(bill_list) {
699 angular.forEach(bill_list, function(b) {
700 if (b.voided != 't') {
701 cents += b.amount * 100;
706 if (bill_ids.length == 0) {
711 egCore.audio.play('warning.circ.void_billings_confirmation');
712 egConfirmDialog.open(
713 egCore.strings.CONFIRM_VOID_BILLINGS, '',
714 { billIds : ''+bill_ids,
715 amount : ''+(cents/100),
717 billSvc.voidBills(bill_ids).then(function() {
718 // TODO? $scope.session_voided = ...
720 // refresh bills and summary data
721 // note: no need to update payments
722 patronSvc.fetchUserStats();
724 egBilling.fetchXact(xact_id).then(function(xact) {
735 // batch-edit billing and payment notes, depending on 'type'
736 function editNotes(selected, type) {
737 var notes = selected.map(function(b){ return b.note }).join(',');
738 var ids = selected.map(function(b){ return b.id });
740 // show the note edit prompt
742 egCore.strings.EDIT_BILL_PAY_NOTE, notes, {
744 ok : function(value) {
746 var func = 'updateBillNotes';
747 if (type == 'payment') func = 'updatePaymentNotes';
749 billSvc[func](value, ids).then(function() {
750 if (type == 'payment') {
751 paymentGrid.refresh();
761 $scope.editBillNotes = function(selected) {
762 editNotes(selected, 'bill');
765 $scope.editPaymentNotes = function(selected) {
766 editNotes(selected, 'payment');
769 // -- retrieve our data
770 $scope.total_circs = 0; // start with 0 instead of undefined
771 egBilling.fetchXact(xact_id).then(function(xact) {
774 var copyId = xact.circulation().target_copy().id();
776 egCore.pcrud.search('circbyyr',
777 {copy : copyId}, null, {atomic : true})
778 .then(function(counts) {
779 angular.forEach(counts, function(count) {
780 circ_count += Number(count.count());
782 $scope.total_circs = circ_count;
784 // set the title. only needs to be done on initial page load
785 if (xact.circulation()) {
786 if (xact.circulation().target_copy().call_number().id() == -1) {
787 $scope.title = xact.circulation().target_copy().dummy_title();
789 // TODO: shared bib service?
790 $scope.title = xact.circulation().target_copy()
791 .call_number().record().simple_record().title();
792 $scope.title_id = xact.circulation().target_copy()
793 .call_number().record().id();
800 .controller('BillHistoryCtrl',
801 ['$scope','$q','$routeParams','egCore','patronSvc','billSvc','egPromptDialog','$location',
802 function($scope, $q , $routeParams , egCore , patronSvc , billSvc , egPromptDialog , $location) {
804 $scope.initTab('bills', $routeParams.id);
805 billSvc.userId = $routeParams.id;
806 $scope.bill_tab = $routeParams.history_tab;
809 // link page controller actions defined by sub-controllers here
812 var start = new Date(); // now - 1 year
813 start.setFullYear(start.getFullYear() - 1),
816 xact_finish : new Date()
819 $scope.date_range = function() {
820 var start = $scope.dates.xact_start.toISOString().replace(/T.*/,'');
821 var end = $scope.dates.xact_finish.toISOString().replace(/T.*/,'');
822 var today = new Date().toISOString().replace(/T.*/,'');
823 if (end == today) end = 'now';
829 .controller('BillXactHistoryCtrl',
830 ['$scope','$q','egCore','patronSvc','billSvc','egPromptDialog','$location','egBilling',
831 function($scope, $q , egCore , patronSvc , billSvc , egPromptDialog , $location , egBilling) {
833 // generate a grid query with the current date widget values.
834 function current_grid_query() {
837 {'summary.balance_owed' : {'<>' : 0}},
838 {'summary.last_payment_ts' : {'<>' : null}}
840 xact_start : {between : $scope.date_range()},
845 $scope.gridControls = {
846 selectedItems : function(){return []},
847 activateItem : function(item) {
848 $scope.showFullDetails([item]);
850 // this sets the query on page load
851 setQuery : current_grid_query
854 $scope.actions.apply_date_range = function() {
855 // tells the grid to re-draw itself with the new query
856 $scope.gridControls.setQuery(current_grid_query());
859 // TODO; move me to service
860 function selected_payment_info() {
861 var info = {owed : 0, billed : 0, paid : 0};
862 angular.forEach($scope.gridControls.selectedItems(), function(item) {
863 info.owed += Number(item['summary.balance_owed']) * 100;
864 info.billed += Number(item['summary.total_owed']) * 100;
865 info.paid += Number(item['summary.total_paid']) * 100;
873 $scope.totals.selected_billed = function() {
874 return selected_payment_info().billed;
876 $scope.totals.selected_paid = function() {
877 return selected_payment_info().paid;
880 $scope.showFullDetails = function(all) {
882 $location.path('/circ/patron/' +
883 patronSvc.current.id() + '/bill/' + all[0].id);
886 // For now, only adds billing to first selected item.
887 // Could do batches later if needed
888 $scope.addBilling = function(all) {
890 egBilling.showBillDialog({
891 xact : egCore.idl.flatToNestedHash(all[0]),
892 patron : $scope.patron()
894 $scope.gridControls.refresh();
895 patronSvc.fetchUserStats();
900 $scope.printBills = function(selected) { // FIXME: refactor me
901 if (!selected.length) return;
902 // bills print receipt assumes nested hashes, but our grid
903 // stores flattener data. Fetch the selected xacts as
904 // fleshed pcrud objects and hashify.
905 // (Consider an alternate approach..)
906 var ids = selected.map(function(t){ return t.id });
908 egCore.pcrud.search('mbt',
910 {flesh : 1, flesh_fields : {'mbt' : ['summary']}},
911 {authoritative : true}
916 template : 'bills_historical',
918 transactions : xacts,
919 current_location : egCore.idl.toHash(
920 egCore.org.get(egCore.auth.user().ws_ou()))
926 xacts.push(egCore.idl.toHash(xact));
934 .controller('BillPaymentHistoryCtrl',
935 ['$scope','$q','egCore','patronSvc','billSvc','$location',
936 function($scope, $q , egCore , patronSvc , billSvc , $location) {
938 // generate a grid query with the current date widget values.
939 function current_grid_query() {
941 'payment_ts' : {between : $scope.date_range()},
942 'xact.usr' : billSvc.userId
946 $scope.gridControls = {
947 selectedItems : function(){return []},
948 activateItem : function(item) {
949 $scope.showFullDetails([item]);
951 setSort : function() {
952 return [{'payment_ts' : 'DESC'}, 'id'];
954 setQuery : current_grid_query
957 $scope.actions.apply_date_range = function() {
958 // tells the grid to re-draw itself with the new query
959 $scope.gridControls.setQuery(current_grid_query());
962 $scope.showFullDetails = function(all) {
964 $location.path('/circ/patron/' +
965 patronSvc.current.id() + '/bill/' + all[0]['xact.id']);
968 $scope.totals.selected_paid = function() {
970 angular.forEach($scope.gridControls.selectedItems(), function(payment) {
971 paid += Number(payment.amount) * 100;