});
}
+ service.fetchXact = function(id) {
+ return egCore.pcrud.retrieve('mobts', id,
+ { flesh : 5,
+ flesh_fields : {
+ mobts : ['circulation','grocery'],
+ circ : ['target_copy'],
+ acp : ['call_number','location'],
+ acn : ['record'],
+ bre : ['simple_record']
+ },
+ select : { bre : ['id'] } // avoid MARC
+ },
+ {authoritative : true}
+ ).then(function(xact) {
+ xact.billing_location(egCore.org.get(xact.billing_location()));
+ return xact;
+ });
+ }
+
+ service.fetchBills = function(xact_id) {
+ return egCore.net.request(
+ 'open-ils.circ',
+ 'open-ils.circ.money.billing.retrieve.all.authoritative',
+ egCore.auth.token(), xact_id
+ );
+ }
+
+ service.fetchPayments = function(xact_id) {
+ return egCore.net.request(
+ 'open-ils.circ',
+ 'open-ils.circ.money.payment.retrieve.all.authoritative',
+ egCore.auth.token(), xact_id
+ );
+ }
+
+ service.voidBills = function(bill_ids) {
+ return egCore.net.requestWithParamList(
+ 'open-ils.circ',
+ 'open-ils.circ.money.billing.void',
+ [egCore.auth.token()].concat(bill_ids)
+ ).then(function(resp) {
+ if (evt = egCore.evt.parse(resp)) return alert(evt);
+ return resp;
+ });
+ }
+
+ service.updateBillNotes = function(note, ids) {
+ return egCore.net.requestWithParamList(
+ 'open-ils.circ',
+ 'open-ils.circ.money.billing.note.edit',
+ [egCore.auth.token(), note].concat(ids)
+ ).then(function(resp) {
+ if (evt = egCore.evt.parse(resp)) return alert(evt);
+ return resp;
+ });
+ }
+
+ service.updatePaymentNotes = function(note, ids) {
+ return egCore.net.requestWithParamList(
+ 'open-ils.circ',
+ 'open-ils.circ.money.payment.note.edit',
+ [egCore.auth.token(), note].concat(ids)
+ ).then(function(resp) {
+ if (evt = egCore.evt.parse(resp)) return alert(evt);
+ return resp;
+ });
+ }
+
return service;
}])
$scope.applyPayment = function() {
if ($scope.annotate_payment) {
egPromptDialog.open(
- egCore.strings.ANNOTATE_PAYMENT_MSG,
+ egCore.strings.ANNOTATE_PAYMENT_MSG, '',
{ok : function(value) {sendPayment(value)}}
);
} else {
$scope.voidAllBillings = function(items) {
angular.forEach(items, function(item) {
- egCore.net.request(
- 'open-ils.circ',
- 'open-ils.circ.money.billing.retrieve.all.authoritative',
- egCore.auth.token(), item.id
- ).then(function(bills) {
+
+ billSvc.fetchBills(item.id).then(function(bills) {
var bill_ids = [];
var cents = 0;
angular.forEach(bills, function(b) {
// TODO: alert of pending voiding
- egCore.net.requestWithParamList(
- 'open-ils.circ',
- 'open-ils.circ.money.billing.void',
- [egCore.auth.token()].concat(bill_ids)
- ).then(function(resp) {
- if (evt = egCore.evt.parse(resp)) return alert(evt);
+ billSvc.voidBills(bill_ids).then(function() {
refreshDisplay();
});
});
$location.path('/circ/patron/' +
patronSvc.current.id() + '/bill/' + all[0].id);
}
+
+ $scope.activateBill = function(xact) {
+ $scope.showFullDetails([xact]);
+ }
+
}])
/**
* Displays details of a single transaction
*/
.controller('XactDetailsCtrl',
- ['$scope','$q','$routeParams','egCore','egGridDataProvider',
-function($scope, $q , $routeParams , egCore , egGridDataProvider) {
+ ['$scope','$q','$routeParams','egCore','egGridDataProvider','patronSvc','billSvc','egPromptDialog',
+function($scope, $q , $routeParams , egCore , egGridDataProvider , patronSvc , billSvc , egPromptDialog) {
$scope.initTab('bills', $routeParams.id);
var xact_id = $routeParams.xact_id;
var bills = [];
var payments = [];
- egCore.pcrud.retrieve('mobts', xact_id,
- { flesh : 5,
- flesh_fields : {
- mobts : ['circulation','grocery'],
- circ : ['target_copy'],
- acp : ['call_number'],
- acn : ['record'],
- bre : ['simple_record']
- },
- // avoid fetching the MARC blob by specifying which
- // fields on the bre to select. More may be needed.
- // note that fleshed fields are explicitly selected.
- select : { bre : ['id'] }
- },
- {authoritative : true}
- ).then(function(xact) {
- xact.billing_location(egCore.org.get(xact.billing_location()));
- $scope.xact = xact;
- });
-
// --- bills grid
var billProvider = egGridDataProvider.instance();
billProvider.get = function(offset, count) {
billProvider.itemFieldValue = billProvider.nestedItemFieldValue;
$scope.billGridProvider = billProvider;
- egCore.net.request(
- 'open-ils.circ',
- 'open-ils.circ.money.billing.retrieve.all.authoritative',
- egCore.auth.token(), xact_id
- ).then(function(mbs) {
- bills = mbs;
- billProvider.increment();
- });
-
// --- payments grid
var paymentProvider = egGridDataProvider.instance();
paymentProvider.get = function(offset, count) {
paymentProvider.itemFieldValue = paymentProvider.nestedItemFieldValue;
$scope.paymentGridProvider = paymentProvider;
- egCore.net.request(
- 'open-ils.circ',
- 'open-ils.circ.money.payment.retrieve.all.authoritative',
- egCore.auth.token(), xact_id
- ).then(function(mps) {
- payments = mps;
- paymentProvider.increment();
+ // -- actions
+ $scope.voidBillings = function(bill_list) {
+ var bill_ids = [];
+ angular.forEach(bill_list, function(b) {
+ if (b.voided() != 't') bill_ids.push(b.id());
+ });
+
+ if (bill_ids.length == 0) {
+ // TODO: warn
+ return;
+ }
+
+ billSvc.voidBills(bill_ids).then(function() {
+
+ // refresh bills and summary data
+ // note: no need to update payments
+ patronSvc.fetchUserStats();
+
+ billSvc.fetchXact(xact_id).then(function(xact) {
+ $scope.xact = xact
+ });
+
+ billSvc.fetchBills(xact_id).then(function(bs) {
+ bills = bs;
+ billProvider.increment();
+ });
+ });
+ }
+
+ // batch-edit billing and payment notes, depending on 'type'
+ function editNotes(selected, type) {
+ var notes = selected.map(function(b){ return b.note() }).join(',');
+ var ids = selected.map(function(b){ return b.id() });
+
+ // show the note edit prompt
+ egPromptDialog.open(
+ egCore.strings.EDIT_BILL_PAY_NOTE, notes, {
+ ids : ''+ids,
+ ok : function(value) {
+
+ var func = 'updateBillNotes';
+ if (type == 'payment') func = 'updatePaymentNotes';
+
+ billSvc[func](value, ids).then(function() {
+
+ if (type == 'payment') {
+ billSvc.fetchPayments(xact_id).then(function(ps) {
+ payments = ps;
+ paymentProvider.increment();
+ });
+
+ } else {
+ billSvc.fetchBills(xact_id).then(function(bs) {
+ bills = bs;
+ billProvider.increment();
+ });
+ }
+ });
+ }
+ }
+ );
+ }
+
+ $scope.editBillNotes = function(selected) {
+ editNotes(selected, 'bill');
+ }
+
+ $scope.editPaymentNotes = function(selected) {
+ editNotes(selected, 'payment');
+ }
+
+ // -- retrieve our data
+ billSvc.fetchXact(xact_id).then(function(xact) {
+ $scope.xact = xact;
});
+ billSvc.fetchBills(xact_id).then(function(bs) {
+ bills = bs;
+ billProvider.increment();
+ });
+
+ billSvc.fetchPayments(xact_id).then(function(ps) {
+ payments = ps;
+ paymentProvider.increment();
+ });
}])