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));
44 if (evt = egCore.evt.parse(resp)) {
45 // Ideally, all scenarios that lead to this alert appearing
46 // will be avoided by the application logic. Leave the alert
47 // in place now to root out any that remain to be addressed.
49 return $q.reject(''+evt);
52 var total = 0; angular.forEach(payments,function(p) { total += p[1]; });
55 case 'cash_payment' : msg = egCore.strings.EG_WORK_LOG_CASH_PAYMENT; break;
56 case 'check_payment' : msg = egCore.strings.EG_WORK_LOG_CHECK_PAYMENT; break;
57 case 'credit_card_payment' : msg = egCore.strings.EG_WORK_LOG_CREDIT_CARD_PAYMENT; break;
58 case 'credit_payment' : msg = egCore.strings.EG_WORK_LOG_CREDIT_PAYMENT; break;
59 case 'work_payment' : msg = egCore.strings.EG_WORK_LOG_WORK_PAYMENT; break;
60 case 'forgive_payment' : msg = egCore.strings.EG_WORK_LOG_FORGIVE_PAYMENT; break;
61 case 'goods_payment' : msg = egCore.strings.EG_WORK_LOG_GOODS_PAYMENT; break;
65 'action' : 'paid_bill',
66 'patron_id' : service.userId,
67 'total_amount' : total
71 // payment API returns the update xact id so we can track it
72 // for future payments without having to refresh the user.
73 patronSvc.current.last_xact_id(resp.last_xact_id);
78 service.fetchBills = function(xact_id) {
80 return egCore.pcrud.search('mb',
81 {xact : xact_id}, null,
82 {authoritative : true}
84 function() {return bills},
86 function(bill) {bills.push(bill); return bill}
90 // TODO: no longer needed?
91 service.fetchPayments = function(xact_id) {
92 return egCore.net.request(
94 'open-ils.circ.money.payment.retrieve.all.authoritative',
95 egCore.auth.token(), xact_id
99 service.voidBills = function(bill_ids) {
100 return egCore.net.requestWithParamList(
102 'open-ils.circ.money.billing.void',
103 [egCore.auth.token()].concat(bill_ids)
104 ).then(function(resp) {
105 if (evt = egCore.evt.parse(resp)) return alert(evt);
110 service.adjustBillsToZero = function(bill_ids) {
111 return egCore.net.request(
113 'open-ils.circ.money.billable_xact.adjust_to_zero',
116 ).then(function(resp) {
117 if (evt = egCore.evt.parse(resp)) return alert(evt);
122 service.updateBillNotes = function(note, ids) {
123 return egCore.net.requestWithParamList(
125 'open-ils.circ.money.billing.note.edit',
126 [egCore.auth.token(), note].concat(ids)
127 ).then(function(resp) {
128 if (evt = egCore.evt.parse(resp)) return alert(evt);
133 service.updatePaymentNotes = function(note, ids) {
134 return egCore.net.requestWithParamList(
136 'open-ils.circ.money.payment.note.edit',
137 [egCore.auth.token(), note].concat(ids)
138 ).then(function(resp) {
139 if (evt = egCore.evt.parse(resp)) return alert(evt);
151 .controller('PatronBillsCtrl',
152 ['$scope','$q','$routeParams','egCore','egConfirmDialog','$location',
153 'egGridDataProvider','billSvc','patronSvc','egPromptDialog', 'egAlertDialog',
154 'egBilling','$uibModal',
155 function($scope , $q , $routeParams , egCore , egConfirmDialog , $location,
156 egGridDataProvider , billSvc , patronSvc , egPromptDialog, egAlertDialog,
157 egBilling , $uibModal) {
159 $scope.initTab('bills', $routeParams.id);
160 billSvc.userId = $routeParams.id;
162 // set up some defaults
163 $scope.check_number = null;
164 $scope.payment_amount = null;
165 $scope.session_voided = 0;
166 $scope.payment_type = 'cash_payment';
167 $scope.focus_payment = true;
168 $scope.annotate_payment = false;
169 $scope.receipt_count = 1;
170 $scope.receipt_on_pay = { isChecked: false };
171 $scope.warn_amount = 1000;
172 $scope.max_amount = 100000;
173 $scope.amount_verified = false;
174 $scope.disable_auto_print = false;
176 // check receipt_on_pay setting default persisted
177 egCore.hatch.getItem('circ.bills.receiptonpay')
178 .then(function(rcptOnPay){
179 if (rcptOnPay) $scope.receipt_on_pay.isChecked = rcptOnPay;
182 // pre-define list-returning funcs in case we access them
183 // before the grid instantiates
184 $scope.gridControls = {
185 focusRowSelector : false,
186 selectedItems : function(){return []},
187 allItems : function(){return []},
188 itemRetrieved : function(item) {
189 item.payment_pending = 0;
191 activateItem : function(item) {
192 $scope.showFullDetails([item]);
194 setQuery : function() {
196 usr : billSvc.userId,
198 'summary.balance_owed' : {'<>' : 0}
201 setSort : function() {
202 return ['xact_start'];
206 billSvc.fetchSummary().then(function(s) {$scope.summary = s});
208 // given a payment amount, determines how much of that is applied
209 // to selected transactions and how much is left over (change).
210 function pending_payment_info() {
211 var amt = $scope.payment_amount || 0;
212 if (amt >= $scope.owed_selected()) {
214 payment : $scope.owed_selected(),
215 change : amt - $scope.owed_selected()
218 return {payment : amt, change : 0};
221 // calculates amount owed, billed, and paid for selected items
222 // TODO: move me to service
223 function selected_payment_info() {
224 var info = {owed : 0, billed : 0, paid : 0};
225 angular.forEach($scope.gridControls.selectedItems(), function(item) {
226 info.owed += Number(item['summary.balance_owed']) * 100;
227 info.billed += Number(item['summary.total_owed']) * 100;
228 info.paid += Number(item['summary.total_paid']) * 100;
236 $scope.pending_payment = function() {
237 return pending_payment_info().payment;
239 $scope.pending_change = function() {
240 return pending_payment_info().change;
242 $scope.owed_selected = function() {
243 return selected_payment_info().owed;
245 $scope.billed_selected = function() {
246 return selected_payment_info().billed;
248 $scope.paid_selected = function() {
249 return selected_payment_info().paid;
251 $scope.refunds_available = function() {
253 angular.forEach($scope.gridControls.allItems(), function(item) {
254 if (item['summary.balance_owed'] < 0)
255 amount += item['summary.balance_owed'] * 100;
257 return -(amount / 100);
259 $scope.invalid_check_number = function() {
260 return $scope.payment_type == 'check_payment' && ! $scope.check_number;
263 // update the item.payment_pending value each time the user
264 // selects different transactions to pay against.
266 function() {return $scope.gridControls.selectedItems()},
267 function() {updatePendingColumn()},
271 // update the item.payment_pending for each (selected)
272 // transaction any time the user-entered payment amount is modified
273 $scope.$watch('payment_amount', updatePendingColumn);
275 // updates the value of the payment_pending column in the grid.
276 // This has to be managed manually since the display value in the grid
277 // is derived from the value on the stored item and not the contents
278 // of our local scope variables.
279 function updatePendingColumn() {
280 // reset all to zero..
281 angular.forEach($scope.gridControls.allItems(),
282 function(item) {item.payment_pending = 0});
284 var payment_amount = $scope.pending_payment();
286 var selected = $scope.gridControls.selectedItems();
287 for (var i = 0; i < selected.length; i++) { // for/break
288 var item = selected[i];
289 var owed = Number(item['summary.balance_owed']);
291 if (payment_amount > owed) {
292 // pending payment exceeds balance of current item.
293 // pay the entire item.
294 item.payment_pending = owed;
295 payment_amount -= owed;
298 // balance owed on the current item matches or exceeds
299 // the pending payment. Apply the full remainder of
300 // the payment to this item.. and we're done.
301 item.payment_pending = payment_amount;
307 // builds payment arrays ([xact_id, ammount]) for all transactions
308 // which have a pending payment amount.
309 function generatePayments() {
311 angular.forEach($scope.gridControls.selectedItems(), function(item) {
312 if (item.payment_pending == 0) return;
313 payments.push([item.id, item.payment_pending]);
318 function refreshDisplay() {
319 patronSvc.fetchUserStats();
320 billSvc.fetchSummary().then(function(s) {$scope.summary = s});
321 $scope.payment_amount = null;
322 $scope.gridControls.refresh();
325 // generates payments, collects user note if needed, and sends payment
327 function sendPayment(note, cc_args) {
328 var make_payments = generatePayments();
329 billSvc.applyPayment($scope.payment_type,
330 make_payments, note, $scope.check_number, cc_args)
332 function(payment_ids) {
334 if (!$scope.disable_auto_print && $scope.receipt_on_pay.isChecked) {
336 $scope.payment_type, payment_ids, make_payments, note);
342 console.error('Payment was rejected: ' + msg);
347 $scope.onReceiptOnPayChanged = function(){
348 egCore.hatch.setItem('circ.bills.receiptonpay', $scope.receipt_on_pay.isChecked);
351 function printReceipt(type, payment_ids, payments_made, note) {
352 var payment_blobs = [];
353 angular.forEach(payments_made, function(payment) {
354 var xact_id = payment[0];
356 // find the original transaction in the grid..
357 var xact = $scope.gridControls.allItems().filter(
358 function(item) {return item.id == xact_id})[0];
361 xact : egCore.idl.flatToNestedHash(xact),
366 console.log(js2JSON(payment_blobs[0]));
368 // page data not yet refreshed, capture data from current scope
372 previous_balance : Number($scope.summary.balance_owed()),
373 payment_total : Number($scope.payment_amount),
374 payment_applied : $scope.pending_payment(),
375 amount_voided : Number($scope.session_voided),
376 change_given : $scope.pending_change(),
377 payments : payment_blobs,
378 current_location : egCore.idl.toHash(
379 egCore.org.get(egCore.auth.user().ws_ou()))
382 print_data.new_balance = (
383 print_data.previous_balance * 100 -
384 print_data.payment_applied * 100) / 100;
386 for (var i = 0; i < $scope.receipt_count; i++) {
389 template : 'bill_payment',
395 $scope.showHistory = function() {
396 $location.path('/circ/patron/' +
397 patronSvc.current.id() + '/bill_history/transactions');
400 // For now, only adds billing to first selected item.
401 // Could do batches later if needed
402 $scope.addBilling = function(all) {
404 egBilling.showBillDialog({
405 xact : egCore.idl.flatToNestedHash(all[0]),
406 patron : $scope.patron()
407 }).then(refreshDisplay);
411 $scope.showBillDialog = function($event) {
412 egBilling.showBillDialog({
413 patron : $scope.patron()
414 }).then(refreshDisplay);
417 // Select refunds adds all refunds to the existing selection.
418 // It does not /only/ select refunds
419 $scope.selectRefunds = function() {
420 var ids = $scope.gridControls.selectedItems().map(
421 function(i) { return i.id });
422 angular.forEach($scope.gridControls.allItems(), function(item) {
423 if (Number(item['summary.balance_owed']) < 0)
426 $scope.gridControls.selectItems(ids);
430 // determine on initial page load when all of the grid rows should
432 var selectOnLoad = true;
433 billSvc.fetchBillSettings().then(function(s) {
434 if (s['ui.circ.billing.uncheck_bills_and_unfocus_payment_box']) {
435 $scope.focus_payment = false; // de-focus the payment box
436 $scope.gridControls.focusRowSelector = true;
437 selectOnLoad = false;
438 // if somehow the grid finishes rendering before our settings
439 // arrive, manually de-select everything.
440 $scope.gridControls.selectItems([]);
442 if (s['ui.circ.billing.amount_warn']) {
443 $scope.warn_amount = Number(s['ui.circ.billing.amount_warn']);
445 if (s['ui.circ.billing.amount_limit']) {
446 $scope.max_amount = Number(s['ui.circ.billing.amount_limit']);
448 if (s['circ.staff_client.do_not_auto_attempt_print'] && angular.isArray(s['circ.staff_client.do_not_auto_attempt_print'])) {
449 $scope.disable_auto_print = Boolean(
450 s['circ.staff_client.do_not_auto_attempt_print'].indexOf('Bill Pay') > -1
455 $scope.gridControls.allItemsRetrieved = function() {
457 selectOnLoad = false; // only for initial controller load.
458 // select all non-refund items
459 $scope.gridControls.selectItems(
460 $scope.gridControls.allItems()
461 .filter(function(i) {return i['summary.balance_owed'] > 0})
462 .map(function(i){return i.id})
469 $scope.printBills = function(selected) {
470 if (!selected.length) return;
471 // bills print receipt assumes nested hashes, but our grid
472 // stores flattener data. Fetch the selected xacts as
473 // fleshed pcrud objects and hashify.
474 // (Consider an alternate approach..)
475 var ids = selected.map(function(t){ return t.id });
477 egCore.pcrud.search('mbt',
479 {flesh : 5, flesh_fields : {
480 'mbt' : ['summary', 'circulation'],
481 'circ' : ['target_copy'],
482 'acp' : ['call_number'],
484 'bre' : ['simple_record']
487 {authoritative : true}
492 template : 'bills_current',
494 transactions : xacts,
495 current_location : egCore.idl.toHash(
496 egCore.org.get(egCore.auth.user().ws_ou()))
503 billing_total : xact.billing_total(),
504 billings : xact.billings(),
505 grocery : xact.grocery(),
507 payment_total : xact.payment_total(),
508 payments : xact.payments(),
509 summary : egCore.idl.toHash(xact.summary()),
510 unrecovered : xact.unrecovered(),
511 xact_finish : xact.xact_finish(),
512 xact_start : xact.xact_start(),
514 if (xact.circulation()) {
515 newXact.copy_barcode = xact.circulation().target_copy().barcode(),
516 newXact.title = xact.circulation().target_copy().call_number().record().simple_record().title()
523 $scope.applyPayment = function() {
525 if ($scope.payment_amount > $scope.max_amount ) {
527 egCore.strings.PAYMENT_OVER_MAX,
528 { max_amount : ''+$scope.max_amount,
530 $scope.payment_amount = 0;
537 verify_payment_amount().then(
538 function() { // amount confirmed
539 add_payment_note().then(function(pay_note) {
540 add_cc_args().then(function(cc_args) {
541 var note_text = pay_note ? pay_note.value || '' : null;
542 sendPayment(note_text, cc_args);
546 function() { // amount rejected
547 console.warn('payment amount rejected');
548 $scope.payment_amount = 0;
553 function verify_payment_amount() {
554 if ($scope.payment_amount < $scope.warn_amount)
557 return egConfirmDialog.open(
558 egCore.strings.PAYMENT_WARN_AMOUNT_TITLE,
559 egCore.strings.PAYMENT_WARN_AMOUNT,
560 {payment_amount : ''+$scope.payment_amount}
564 function add_payment_note() {
565 if (!$scope.annotate_payment) return $q.when();
566 return egPromptDialog.open(
567 egCore.strings.ANNOTATE_PAYMENT_MSG, '').result;
570 function add_cc_args() {
571 if ($scope.payment_type != 'credit_card_payment')
574 return $uibModal.open({
575 templateUrl : './circ/patron/t_cc_payment_dialog',
578 '$scope','$uibModalInstance',
579 function($scope , $uibModalInstance) {
583 where_process : '1', // internal=1 ; external=0
584 type : 'VISA', // external only
585 billing_first : patronSvc.current.first_given_name(),
586 billing_last : patronSvc.current.family_name()
590 var addr = patronSvc.current.billing_address() ||
591 patronSvc.current.mailing_address();
593 var cc = $scope.context.cc;
594 cc.billing_address = addr.street1() +
595 (addr.street2() ? ' ' + addr.street2() : '');
596 cc.billing_city = addr.city();
597 cc.billing_state = addr.state();
598 cc.billing_zip = addr.post_code();
601 $scope.ok = function() {
602 // CC payment form is not a <form>,
603 // so apply validation manually.
604 if ( $scope.context.cc.where_process == 0 &&
605 !$scope.context.cc.approval_code)
608 $uibModalInstance.close($scope.context.cc);
611 $scope.cancel = function() {
612 $uibModalInstance.dismiss();
619 $scope.voidAllBillings = function(items) {
623 angular.forEach(items, function(item) {
625 billSvc.fetchBills(item.id).then(function(bills) {
626 angular.forEach(bills, function(b) {
627 if (b.voided() != 't') {
628 cents += b.amount() * 100;
629 bill_ids.push(b.id())
633 if (bill_ids.length == 0) {
642 $q.all(promises).then(function(){
643 egCore.audio.play('warning.circ.void_billings_confirmation');
644 egConfirmDialog.open(
645 egCore.strings.CONFIRM_VOID_BILLINGS, '',
646 { billIds : ''+bill_ids,
647 amount : ''+(cents/100),
649 billSvc.voidBills(bill_ids).then(function() {
650 $scope.session_voided =
651 ($scope.session_voided * 100 + cents) / 100;
660 $scope.adjustToZero = function(items) {
661 if (items.length == 0) return;
663 var ids = items.map(function(item) {return item.id});
665 egCore.audio.play('warning.circ.adjust_to_zero_confirmation');
666 egConfirmDialog.open(
667 egCore.strings.CONFIRM_ADJUST_TO_ZERO, '',
670 billSvc.adjustBillsToZero(ids).then(function() {
679 // note this is functionally equivalent to selecting a neg. transaction
680 // then clicking Apply Payment -- this just adds a speed bump (ditto
682 $scope.refundXact = function(all) {
683 var items = all.filter(function(item) {
684 return item['summary.balance_owed'] < 0
687 if (items.length == 0) return;
689 var ids = items.map(function(item) {return item.id});
691 egCore.audio.play('warning.circ.refund_confirmation');
692 egConfirmDialog.open(
693 egCore.strings.CONFIRM_REFUND_PAYMENT, '',
696 // reset the received payment amount. this ensures
697 // we're not mingling payments with refunds.
698 $scope.payment_amount = 0;
704 // direct the user to the transaction details page
705 $scope.showFullDetails = function(all) {
707 $location.path('/circ/patron/' +
708 patronSvc.current.id() + '/bill/' + all[0].id);
711 $scope.activateBill = function(xact) {
712 $scope.showFullDetails([xact]);
718 * Displays details of a single transaction
720 .controller('XactDetailsCtrl',
721 ['$scope','$q','$routeParams','egCore','egGridDataProvider','patronSvc','billSvc','egPromptDialog','egBilling','egConfirmDialog',
722 function($scope, $q , $routeParams , egCore , egGridDataProvider , patronSvc , billSvc , egPromptDialog , egBilling , egConfirmDialog ) {
724 $scope.initTab('bills', $routeParams.id);
725 var xact_id = $routeParams.xact_id;
727 var xactGrid = $scope.xactGridControls = {
728 setQuery : function() { return {xact : xact_id} },
729 setSort : function() { return ['billing_ts'] }
732 var paymentGrid = $scope.paymentGridControls = {
733 setQuery : function() { return {xact : xact_id} },
734 setSort : function() { return ['payment_ts'] }
738 $scope.voidBillings = function(bill_list) {
741 angular.forEach(bill_list, function(b) {
742 if (b.voided != 't') {
743 cents += b.amount * 100;
748 if (bill_ids.length == 0) {
753 egCore.audio.play('warning.circ.void_billings_confirmation');
754 egConfirmDialog.open(
755 egCore.strings.CONFIRM_VOID_BILLINGS, '',
756 { billIds : ''+bill_ids,
757 amount : ''+(cents/100),
759 billSvc.voidBills(bill_ids).then(function() {
760 // TODO? $scope.session_voided = ...
762 // refresh bills and summary data
763 // note: no need to update payments
764 patronSvc.fetchUserStats();
766 egBilling.fetchXact(xact_id).then(function(xact) {
777 // batch-edit billing and payment notes, depending on 'type'
778 function editNotes(selected, type) {
779 var notes = selected.map(function(b){ return b.note }).join(',');
780 var ids = selected.map(function(b){ return b.id });
782 // show the note edit prompt
784 egCore.strings.EDIT_BILL_PAY_NOTE, notes, {
786 ok : function(value) {
788 var func = 'updateBillNotes';
789 if (type == 'payment') func = 'updatePaymentNotes';
791 billSvc[func](value, ids).then(function() {
792 if (type == 'payment') {
793 paymentGrid.refresh();
803 $scope.editBillNotes = function(selected) {
804 editNotes(selected, 'bill');
807 $scope.editPaymentNotes = function(selected) {
808 editNotes(selected, 'payment');
811 // -- retrieve our data
812 $scope.total_circs = 0; // start with 0 instead of undefined
813 egBilling.fetchXact(xact_id).then(function(xact) {
816 var copyId = xact.circulation().target_copy().id();
818 egCore.pcrud.search('circbyyr',
819 {copy : copyId}, null, {atomic : true})
820 .then(function(counts) {
821 angular.forEach(counts, function(count) {
822 circ_count += Number(count.count());
824 $scope.total_circs = circ_count;
826 // set the title. only needs to be done on initial page load
827 if (xact.circulation()) {
828 if (xact.circulation().target_copy().call_number().id() == -1) {
829 $scope.title = xact.circulation().target_copy().dummy_title();
831 // TODO: shared bib service?
832 $scope.title = xact.circulation().target_copy()
833 .call_number().record().simple_record().title();
834 $scope.title_id = xact.circulation().target_copy()
835 .call_number().record().id();
842 .controller('BillHistoryCtrl',
843 ['$scope','$q','$routeParams','egCore','patronSvc','billSvc','egPromptDialog','$location',
844 function($scope, $q , $routeParams , egCore , patronSvc , billSvc , egPromptDialog , $location) {
846 $scope.initTab('bills', $routeParams.id);
847 billSvc.userId = $routeParams.id;
848 $scope.bill_tab = $routeParams.history_tab;
851 // link page controller actions defined by sub-controllers here
854 var start = new Date(); // now - 1 year
855 start.setFullYear(start.getFullYear() - 1),
858 xact_finish : new Date()
861 $scope.date_range = function() {
862 var start = $scope.dates.xact_start.toISOString().replace(/T.*/,'');
863 var end = $scope.dates.xact_finish.toISOString().replace(/T.*/,'');
864 var today = new Date().toISOString().replace(/T.*/,'');
865 if (end == today) end = 'now';
871 .controller('BillXactHistoryCtrl',
872 ['$scope','$q','egCore','patronSvc','billSvc','egPromptDialog','$location','egBilling',
873 function($scope, $q , egCore , patronSvc , billSvc , egPromptDialog , $location , egBilling) {
875 // generate a grid query with the current date widget values.
876 function current_grid_query() {
879 {'summary.balance_owed' : {'<>' : 0}},
880 {'summary.last_payment_ts' : {'<>' : null}}
882 xact_start : {between : $scope.date_range()},
887 $scope.gridControls = {
888 selectedItems : function(){return []},
889 activateItem : function(item) {
890 $scope.showFullDetails([item]);
892 // this sets the query on page load
893 setQuery : current_grid_query
896 $scope.actions.apply_date_range = function() {
897 // tells the grid to re-draw itself with the new query
898 $scope.gridControls.setQuery(current_grid_query());
901 // TODO; move me to service
902 function selected_payment_info() {
903 var info = {owed : 0, billed : 0, paid : 0};
904 angular.forEach($scope.gridControls.selectedItems(), function(item) {
905 info.owed += Number(item['summary.balance_owed']) * 100;
906 info.billed += Number(item['summary.total_owed']) * 100;
907 info.paid += Number(item['summary.total_paid']) * 100;
915 $scope.totals.selected_billed = function() {
916 return selected_payment_info().billed;
918 $scope.totals.selected_paid = function() {
919 return selected_payment_info().paid;
922 $scope.showFullDetails = function(all) {
924 $location.path('/circ/patron/' +
925 patronSvc.current.id() + '/bill/' + all[0].id);
928 // For now, only adds billing to first selected item.
929 // Could do batches later if needed
930 $scope.addBilling = function(all) {
932 egBilling.showBillDialog({
933 xact : egCore.idl.flatToNestedHash(all[0]),
934 patron : $scope.patron()
936 $scope.gridControls.refresh();
937 patronSvc.fetchUserStats();
942 $scope.printBills = function(selected) { // FIXME: refactor me
943 if (!selected.length) return;
944 // bills print receipt assumes nested hashes, but our grid
945 // stores flattener data. Fetch the selected xacts as
946 // fleshed pcrud objects and hashify.
947 // (Consider an alternate approach..)
948 var ids = selected.map(function(t){ return t.id });
950 egCore.pcrud.search('mbt',
952 {flesh : 5, flesh_fields : {
953 'mbt' : ['summary', 'circulation'],
954 'circ' : ['target_copy'],
955 'acp' : ['call_number'],
957 'bre' : ['simple_record']
960 {authoritative : true}
965 template : 'bills_historical',
967 transactions : xacts,
968 current_location : egCore.idl.toHash(
969 egCore.org.get(egCore.auth.user().ws_ou()))
976 billing_total : xact.billing_total(),
977 billings : xact.billings(),
978 grocery : xact.grocery(),
980 payment_total : xact.payment_total(),
981 payments : xact.payments(),
982 summary : egCore.idl.toHash(xact.summary()),
983 unrecovered : xact.unrecovered(),
984 xact_finish : xact.xact_finish(),
985 xact_start : xact.xact_start(),
987 if (xact.circulation()) {
988 newXact.copy_barcode = xact.circulation().target_copy().barcode(),
989 newXact.title = xact.circulation().target_copy().call_number().record().simple_record().title()
997 .controller('BillPaymentHistoryCtrl',
998 ['$scope','$q','egCore','patronSvc','billSvc','$location',
999 function($scope, $q , egCore , patronSvc , billSvc , $location) {
1001 // generate a grid query with the current date widget values.
1002 function current_grid_query() {
1004 'payment_ts' : {between : $scope.date_range()},
1005 'xact.usr' : billSvc.userId
1009 $scope.gridControls = {
1010 selectedItems : function(){return []},
1011 activateItem : function(item) {
1012 $scope.showFullDetails([item]);
1014 setSort : function() {
1015 return [{'payment_ts' : 'DESC'}, 'id'];
1017 setQuery : current_grid_query
1020 $scope.actions.apply_date_range = function() {
1021 // tells the grid to re-draw itself with the new query
1022 $scope.gridControls.setQuery(current_grid_query());
1025 $scope.showFullDetails = function(all) {
1027 $location.path('/circ/patron/' +
1028 patronSvc.current.id() + '/bill/' + all[0]['xact.id']);
1031 $scope.totals.selected_paid = function() {
1033 angular.forEach($scope.gridControls.selectedItems(), function(payment) {
1034 paid += Number(payment.amount) * 100;