From: Kyle Huckins Date: Tue, 9 May 2017 17:58:34 +0000 (-0700) Subject: CAT-117 Emailed receipts in SCKO X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=5f5a3c4d096f3c9ac411339761388dea55ffa0c5;p=working%2FEvergreen.git CAT-117 Emailed receipts in SCKO Add email self-checkout receipt functionality, including sql hooks into deploy and revert folder for getting circ data under email-selfcheck-receipt.sql Signed-off-by: Kyle Huckins Signed-off-by: Skye Howard Changes to be committed: modified: KCLS/openils/var/templates_kcls/circ/selfcheck/main.tt2 new file: KCLS/sql/schema/deploy/selfcheck-email-receipts.sql new file: KCLS/sql/schema/revert/selfcheck-email-receipts.sql modified: KCLS/sql/schema/sqitch.plan new file: KCLS/sql/schema/verify/selfcheck-email-receipts.sql modified: Open-ILS/web/js/ui/kcls/circ/selfcheck/selfcheck.js --- diff --git a/KCLS/openils/var/templates_kcls/circ/selfcheck/main.tt2 b/KCLS/openils/var/templates_kcls/circ/selfcheck/main.tt2 index 60e31c2a05..42a1f155fc 100644 --- a/KCLS/openils/var/templates_kcls/circ/selfcheck/main.tt2 +++ b/KCLS/openils/var/templates_kcls/circ/selfcheck/main.tt2 @@ -213,6 +213,10 @@ function switchTo(str,subpage) {
logout with receipt
logout without receipt
+
+ +
back to checkout Back to Checkout
diff --git a/KCLS/sql/schema/deploy/selfcheck-email-receipts.sql b/KCLS/sql/schema/deploy/selfcheck-email-receipts.sql new file mode 100644 index 0000000000..981a9d43f9 --- /dev/null +++ b/KCLS/sql/schema/deploy/selfcheck-email-receipts.sql @@ -0,0 +1,86 @@ +-- Deploy kcls-evergreen:selfcheck-email-receipts to pg +--requires 2.7-to-2.9-upgrade-part-2 +BEGIN; + +DO $$ +BEGIN + IF evergreen.insert_on_deploy() THEN + INSERT INTO action_trigger.hook ( + key, + core_type, + description, + passive + ) VALUES ( + 'email.selfcheck.checkout', + 'circ', + 'Formats circ objects for self-checkout email.', + TRUE + ); + + INSERT INTO action_trigger.event_definition ( + active, + owner, + name, + hook, + validator, + reactor, + group_field, + template ) + VALUES ( + TRUE, + 1, + 'Email Self-Checkout Receipt', + 'email.selfcheck.checkout', + 'NOOP_True', + 'SendEmail', + 'usr', + $email_receipt_template$ +[%- USE date -%] +[%- user = target.0.usr -%] +To: [%- params.recipient_email || user.email %] +From: [%- params.sender_email || helpers.get_org_setting(target.0.circ_lib.id, 'org.bounced_emails') || lib.email || default_sender %] + Subject: Checkout Receipt + + Dear [% user.first_given_name %], + + You checked out the following items: + +[% FOR circ IN target %] + [%- copy_details = helpers.get_copy_bib_basics(circ.target_copy.id) -%] + Title: [% copy_details.title %] + Author: [% copy_details.author %] + Call Number: [% circ.target_copy.call_number.label %] + Barcode: [% circ.target_copy.barcode %] + Due Date: [% date.format(helpers.format_date(circ.due_date), '%m/%d/%Y') %] + Library: [% circ.circ_lib.name %] + + [% END %] + $email_receipt_template$); + + + + INSERT INTO action_trigger.environment ( + event_def, + path + ) VALUES ( + currval('action_trigger.event_definition_id_seq'), + 'target_copy.call_number' + ), ( + currval('action_trigger.event_definition_id_seq'), + 'target_copy.location' + ), ( + currval('action_trigger.event_definition_id_seq'), + 'usr' + ), ( + currval('action_trigger.event_definition_id_seq'), + 'circ_lib' + ); + + + END IF; +END $$; + +COMMIT; + + + diff --git a/KCLS/sql/schema/revert/selfcheck-email-receipts.sql b/KCLS/sql/schema/revert/selfcheck-email-receipts.sql new file mode 100644 index 0000000000..981ead13cc --- /dev/null +++ b/KCLS/sql/schema/revert/selfcheck-email-receipts.sql @@ -0,0 +1,25 @@ +-- Revert kcls-evergreen:selfcheck-email-receipts from pg + +BEGIN; + +DO $$ +BEGIN + IF evergreen.insert_on_deploy() THEN + + DELETE FROM action_trigger.environment WHERE event_def = + (SELECT id FROM action_trigger.event_definition + WHERE active and hook = 'email.selfcheck.checkout'); + + DELETE FROM action_trigger.event WHERE event_def=(select id from action_trigger.event_definition where active and hook='email.selfcheck.checkout'); + + DELETE FROM action_trigger.event_definition + + DELETE FROM action_trigger.hook WHERE key = 'email.selfcheck.checkout'; + WHERE active and + hook = 'email.selfcheck.checkout' AND + name = 'Email Self-Checkout Receipt'; + + END IF; -- insert-on-deploy +END $$; + +COMMIT; diff --git a/KCLS/sql/schema/sqitch.plan b/KCLS/sql/schema/sqitch.plan index 70cf22b5ad..97432bea26 100644 --- a/KCLS/sql/schema/sqitch.plan +++ b/KCLS/sql/schema/sqitch.plan @@ -52,3 +52,4 @@ hold-targeter-v2 [2.7-to-2.9-upgrade-part-2] 2017-03-10T16:53:06Z Bill Erickson 2.9-to-2.10-upgrade [2.7-to-2.9-upgrade-part-2] 2017-06-26T15:44:46Z Bill Erickson,,, # KCLS 2.9 to 2.10 SQL upgrade org-phones [2.9-to-2.10-upgrade] 2017-11-22T16:23:27Z Bill Erickson,,, # Add a pile of org unit phone numbers 2.9-to-2.10-upgrade-reingest [org-phones] 2017-06-26T19:01:20Z Bill Erickson,,, # KCLS 2.9 to 2.10 SQL Data Ingests +selfcheck-email-receipts [2.7-to-2.9-upgrade-part-2] 2017-04-21T19:02:22Z Victoria Lewis # Self Checkout email receipts diff --git a/KCLS/sql/schema/verify/selfcheck-email-receipts.sql b/KCLS/sql/schema/verify/selfcheck-email-receipts.sql new file mode 100644 index 0000000000..07d91ea167 --- /dev/null +++ b/KCLS/sql/schema/verify/selfcheck-email-receipts.sql @@ -0,0 +1,7 @@ +-- Verify kcls-evergreen:selfcheck-email-receipts on pg + +BEGIN; + +-- XXX Add verifications here. + +ROLLBACK; diff --git a/Open-ILS/web/js/ui/kcls/circ/selfcheck/selfcheck.js b/Open-ILS/web/js/ui/kcls/circ/selfcheck/selfcheck.js index 8b42dc2a7e..6b9fcb02bf 100644 --- a/Open-ILS/web/js/ui/kcls/circ/selfcheck/selfcheck.js +++ b/Open-ILS/web/js/ui/kcls/circ/selfcheck/selfcheck.js @@ -64,7 +64,7 @@ function selfckResetTimer() { console.log('Starting new login timer'); // do not show a warning dialog if the inactivity timeout - // occurs during the login stage. + // occurs between entering a barcode and password. selfckStartTimer(!Boolean(selfCheckManager.patron)); } @@ -220,6 +220,7 @@ SelfCheckManager.prototype.init = function() { 'oils-selfck-nav-logout-print' : function() { self.logoutPatron(true); }, 'oils-selfck-items-out-details-link' : function() { self.drawItemsOutPage(); }, //'oils-selfck-print-list-link' : function() { self.printList(); } + 'oils-selfck-nav-logout-email' : function() { self.logoutPatronWithEmail(true); } } for(var id in linkHandlers) { @@ -474,8 +475,11 @@ SelfCheckManager.prototype.loginPatron = function(barcode_or_usrname, passwd) { dojo.byId('oils-selfck-status-div2').innerHTML = ''; dojo.byId('oils-selfck-status-div3').innerHTML = ''; openils.Util.hide('back_to_login'); - this.drawCircPage(); + if(this.patron.email() && this.patron.email().match(/.+@.+/) != null){ + openils.Util.removeCSSClass( dojo.byId('oils-selfck-nav-logout-email'), 'hidden' ); } + this.drawCircPage(); + } } @@ -598,7 +602,7 @@ SelfCheckManager.prototype.updateFinesSummary = function() { oncomplete : function(r) { var summary = openils.Util.readResponse(r); var finesSum = dojo.byId('acct_fines'); - var bal = summary.balance_owed(); + var bal = summary ? summary.balance_owed() : 0; var bal2 = parseFloat(bal); if(bal2>0) {finesSum.style.color="red"; openils.Util.show('oils-selfck-pay-fines-link');} @@ -1344,7 +1348,7 @@ SelfCheckManager.prototype.printSessionReceipt = function(callback) { var self = this; fieldmapper.standardRequest( ['open-ils.circ', 'open-ils.circ.fire_circ_trigger_events'], - { + { async : false, params : params, oncomplete : function(r) { @@ -1383,7 +1387,7 @@ SelfCheckManager.prototype.printData = function(data, numItems, callback) { setTimeout( function() { win.close(); // close the print window - if(callback) callback(); // fire optional post-print callback + if(callback) callback(); // fire callback to return to main page }, sleepTime ); @@ -1431,6 +1435,56 @@ SelfCheckManager.prototype.printItemsOutReceipt = function(callback) { } ); } +/**Send email receipt for this session's checkouts + */ +SelfCheckManager.prototype.emailSessionReceipt = function(callback) { + + var circIds = []; + var circCtx = []; // circ context data. in this case, renewal_failure info + + // collect the circs and failure info + dojo.forEach( + this.checkouts, + function(blob) { + circIds.push(blob.circ); + circCtx.push({renewal_failure:blob.renewal_failure}); + } + ); + var params = [ + this.authtoken, + this.staff.ws_ou(), + null, + 'email.selfcheck.checkout', + 'print-on-demand', + circIds, + circCtx + ]; + + var self = this; + fieldmapper.standardRequest( + ['open-ils.circ', 'open-ils.circ.fire_circ_trigger_events'], + { + async : false, + params : params, + oncomplete : function(r) { + var resp = openils.Util.readResponse(r); + var output = resp.template_output(); + if(output) { + if (callback) callback(); + } else { + var error = resp.error_output(); + if(error) { + throw new Error("Error creating receipt: " + error.data()); + } else { + throw new Error("No receipt data returned from server"); + } + } + } + } + ); +} + + /** * Print a receipt for this user's items out @@ -1561,6 +1615,21 @@ SelfCheckManager.prototype.printFinesReceipt = function(callback) { ); } +/** + * Logout the patron and return to the login page + */ +SelfCheckManager.prototype.logoutPatronWithEmail = function(email) { + var return_url = this.cgi.param('return-to') || location.href; + if(email && this.checkouts.length) { + this.emailSessionReceipt( + function() { + location.href = return_url; + } + ); + } else { + location.href = return_url; + } +} /** * Logout the patron and return to the login page @@ -1568,12 +1637,12 @@ SelfCheckManager.prototype.printFinesReceipt = function(callback) { SelfCheckManager.prototype.logoutPatron = function(print) { var return_url = this.cgi.param('return-to') || location.href; - progressDialog.show(true); // prevent patron from clicking logout link twice if(print && this.checkouts.length) { this.printSessionReceipt( function() { - location.href = return_url; + //also closes progress dialog + location.href = return_url; } ); } else { @@ -1615,12 +1684,5 @@ openils.Util.addOnLoad( selfCheckManager.init(); openils.Util.registerEnterHandler(dojo.byId('patron-login-username'), function(){checkLogin();}); openils.Util.registerEnterHandler(dojo.byId('patron-login-password'), function(){selfCheckMgr.loginPatron(dojo.byId('patron-login-username').value,dojo.byId('patron-login-password').value);}); - - // If we have a return-to address, start the login timer - // before the patron logs in, so we can revert back to - // our return-to page if the patron never logs in. - if (selfCheckManager.cgi.param('return-to')) { - selfckResetTimer(); - } } );