From 44e8051578e1197d40129449683ec28db0eee93f Mon Sep 17 00:00:00 2001
From: Bill Erickson
Date: Wed, 4 Jun 2014 10:36:50 -0400
Subject: [PATCH] payment receipts
Signed-off-by: Bill Erickson
---
.../src/templates/staff/circ/patron/t_bills.tt2 | 21 +++++++
.../templates/staff/circ/patron/t_bills_list.tt2 | 5 +-
.../staff/share/print_templates/t_bill_payment.tt2 | 68 ++++++++++++++++++++++
.../web/js/ui/default/staff/circ/patron/app.js | 18 ++++--
.../web/js/ui/default/staff/circ/patron/bills.js | 53 ++++++++++++++++-
Open-ILS/web/js/ui/default/staff/services/idl.js | 26 +++++++++
6 files changed, 184 insertions(+), 7 deletions(-)
create mode 100644 Open-ILS/src/templates/staff/share/print_templates/t_bill_payment.tt2
diff --git a/Open-ILS/src/templates/staff/circ/patron/t_bills.tt2 b/Open-ILS/src/templates/staff/circ/patron/t_bills.tt2
index 6d68f83a08..b8ab9177ac 100644
--- a/Open-ILS/src/templates/staff/circ/patron/t_bills.tt2
+++ b/Open-ILS/src/templates/staff/circ/patron/t_bills.tt2
@@ -86,3 +86,24 @@
[% INCLUDE 'staff/circ/patron/t_bills_list.tt2' %]
+
+
+
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 0e31b75705..e1058f6722 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
@@ -51,6 +51,9 @@
+
+
+
{{item.title}}
@@ -60,7 +63,7 @@
label="[% l('Record ID') %]" name="record_id" required hidden>
-
{{item.copy_barcode}}
diff --git a/Open-ILS/src/templates/staff/share/print_templates/t_bill_payment.tt2 b/Open-ILS/src/templates/staff/share/print_templates/t_bill_payment.tt2
new file mode 100644
index 0000000000..766c9c6af0
--- /dev/null
+++ b/Open-ILS/src/templates/staff/share/print_templates/t_bill_payment.tt2
@@ -0,0 +1,68 @@
+Welcome to {{current_location.name}}!
+A receipt of your transaction:
+
+
+
+ | [% l('Original Balance:') %] |
+ {{previous_balance | currency}} |
+
+
+ | [% l('Payment Method:') %] |
+
+
+ [% l('Cash') %]
+ [% l('Check') %]
+ [% l('Credit Card') %]
+ [% l('Patron Credit') %]
+ [% l('Work') %]
+ [% l('Forgive') %]
+ [% l('Goods') %]
+
+ |
+
+
+ | [% l('Payment Received:') %] |
+ {{payment_total | currency}} |
+
+
+ | [% l('Payment Applied:') %] |
+ {{payment_applied | currency}} |
+
+
+ | [% l('Billings Voided:') %] |
+ {{amount_voided | currency}} |
+
+
+ | [% l('Change Given:') %] |
+ {{change_given | currency}} |
+
+
+ | [% l('New Balance:') %] |
+ {{new_balance | currency}} |
+
+
+
+[% l('Note: [_1]', '{{payment_note}}') %]
+
+
+[% l('Specific Bills') %]
+
+
+
+
+ | [% l('Bill # [_1]', '{{payment.xact.id}}') %] |
+ {{payment.xact.summary.last_billing_type}} |
+ [% l('Received: [_1]', '{{payment.amount | currency}}') %] |
+
+
+ | {{payment.xact.copy_barcode}} |
+ {{payment.xact.title}} |
+
+
+
+
+
+
+
+
+{{current_location.shortname}} {{today | date:'short'}}
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 d6a7e91069..9dc5e36338 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
@@ -177,8 +177,13 @@ function($q , $timeout , $location , egCore, egUser , $locale) {
service.setDefault = function(id, user, force) {
if (user) {
if (!force && service.current &&
- service.current.id() == user.id())
- return $q.when();
+ service.current.id() == user.id()) {
+ if (service.patron_stats) {
+ return $q.when();
+ } else {
+ return service.fetchUserStats();
+ }
+ }
service.resetPatronLists();
service.current = user;
@@ -186,8 +191,13 @@ function($q , $timeout , $location , egCore, egUser , $locale) {
return service.fetchUserStats();
} else if (id) {
- if (!force && service.current && service.current.id() == id)
- return $q.when();
+ if (!force && service.current && service.current.id() == id) {
+ if (service.patron_stats) {
+ return $q.when();
+ } else {
+ return service.fetchUserStats();
+ }
+ }
service.resetPatronLists();
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 218b9b5a89..5b4cf1490d 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
@@ -44,6 +44,7 @@ function($q , egCore , patronSvc) {
// payment API returns the update xact id so we can track it
// for future payments without having to refresh the user.
patronSvc.current.last_xact_id(resp.last_xact_id);
+ return resp.payments;
});
}
@@ -225,6 +226,8 @@ function($scope , $q , $routeParams , egCore , egConfirmDialog , $location,
$scope.payment_type = 'cash_payment';
$scope.focus_payment = true;
$scope.annotate_payment = false;
+ $scope.receipt_count = 1;
+ $scope.receipt_on_pay = false;
$scope.gridRevision = 0;
// pre-define list-returning funcs in case we access them
@@ -370,14 +373,60 @@ function($scope , $q , $routeParams , egCore , egConfirmDialog , $location,
// generates payments, collects user note if needed, and sends payment
// to server.
function sendPayment(note) {
+ var make_payments = generatePayments();
billSvc.applyPayment(
- $scope.payment_type, generatePayments(), note)
- .then(function() {
+ $scope.payment_type, make_payments, note)
+ .then(function(payment_ids) {
+
+ if ($scope.receipt_on_pay) {
+ printReceipt(
+ $scope.payment_type, payment_ids, make_payments, note);
+ }
+
refreshDisplay();
billSvc.fetchSummary().then(function(s) {$scope.summary = s});
})
}
+ function printReceipt(type, payment_ids, payments_made, note) {
+ var payment_blobs = [];
+ angular.forEach(payments_made, function(payment) {
+ var xact_id = payment[0];
+
+ // find the original transaction in the grid..
+ var xact = $scope.gridControls.allItems().filter(
+ function(item) {return item.id == xact_id})[0];
+
+ payment_blobs.push({
+ xact : egCore.idl.flatToNestedHash(xact),
+ amount : payment[1]
+ });
+ });
+
+ console.log(js2JSON(payment_blobs[0]));
+
+ // page data not yet refreshed, capture data from current scope
+ var print_data = {
+ previous_balance : $scope.summary.balance_owed,
+ payment_total : $scope.payment_amount,
+ payment_applied : $scope.pending_payment(),
+ amount_voided : $scope.session_voided,
+ change_given : $scope.pending_change(),
+ payments : payment_blobs,
+ current_location : egCore.idl.toHash(
+ egCore.org.get(egCore.auth.user().ws_ou()))
+ }
+
+ print_data.new_balance = (
+ print_data.previous_balance * 100 -
+ print_data.payment_applied * 100) / 100;
+
+ for (var i = 0; i < $scope.receipt_count; i++) {
+ egCore.hatch.printFromTemplate(
+ 'receipt', 'bill_payment', print_data);
+ }
+ }
+
$scope.showHistory = function() {
$location.path('/circ/patron/' +
patronSvc.current.id() + '/bill_history/transactions');
diff --git a/Open-ILS/web/js/ui/default/staff/services/idl.js b/Open-ILS/web/js/ui/default/staff/services/idl.js
index 8ad4b668dd..1fe712935d 100644
--- a/Open-ILS/web/js/ui/default/staff/services/idl.js
+++ b/Open-ILS/web/js/ui/default/staff/services/idl.js
@@ -99,6 +99,32 @@ angular.module('egCoreMod')
return hash;
}
+ // Transforms a flattened hash (see toHash() or egGridFlatDataProvider)
+ // to a nested hash.
+ //
+ // e.g. {"call_number.label" : "foo"} => {"call_number":{"label":"foo"}}
+ service.flatToNestedHash = function(obj) {
+ var hash = {};
+ angular.forEach(obj, function(val, key) {
+ var parts = key.split('.');
+ var sub_hash = hash;
+ var last_key;
+ for (var i = 0; i < parts.length; i++) {
+ var part = parts[i];
+ if (i == parts.length - 1) {
+ sub_hash[part] = val;
+ break;
+ } else {
+ if (!sub_hash[part])
+ sub_hash[part] = {};
+ sub_hash = sub_hash[part];
+ }
+ }
+ });
+
+ return hash;
+ }
+
return service;
}]);
--
2.11.0