CAT-117 Emailed receipts in SCKO
authorKyle Huckins <khuckins@catalyte.io>
Tue, 9 May 2017 17:58:34 +0000 (10:58 -0700)
committerBill Erickson <berickxx@gmail.com>
Thu, 21 Mar 2019 19:46:23 +0000 (15:46 -0400)
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 <khuckins@catalyte.io>
Signed-off-by: Skye Howard <showard@catalyte.io>
 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

KCLS/openils/var/templates_kcls/circ/selfcheck/main.tt2
KCLS/sql/schema/deploy/selfcheck-email-receipts.sql [new file with mode: 0644]
KCLS/sql/schema/revert/selfcheck-email-receipts.sql [new file with mode: 0644]
KCLS/sql/schema/sqitch.plan
KCLS/sql/schema/verify/selfcheck-email-receipts.sql [new file with mode: 0644]
Open-ILS/web/js/ui/kcls/circ/selfcheck/selfcheck.js

index 60e31c2..42a1f15 100644 (file)
@@ -213,6 +213,10 @@ function switchTo(str,subpage) {
           <div style="padding-bottom:5px;"><a href="javascript:;" id='oils-selfck-nav-logout-print'><img alt='logout with receipt' src="[% ctx.media_prefix %]/images/selfcheck/logoutbutton.jpg" style="" /></a></div>
           <div style=""><a href="javascript:;" id='oils-selfck-nav-logout'><img alt='logout without receipt' src="[% ctx.media_prefix %]/images/selfcheck/logoutwithoutreceiptbutton.jpg" style="" /></a></div>
         </div>
+        <div class="col-md-12 pad-vert-btn">
+          <button id='oils-selfck-nav-logout-email'  class='hidden' alt='logout and email receipt' style=""
+           class="btn btn-danger">Finish & Email Receipt</button>
+        </div>
         <div style="clear:both;padding-top:15px;padding-left:3px;">
           <a href="javascript:;" id="back_button" onclick="switchTo('step3');"><img alt='back to checkout' src="[% ctx.media_prefix %]/images/selfcheck/arrow.gif" /></a> <a href="javascript:;" onclick="switchTo('step3');"><span style="position:relative;top:-4px;left:2px;">Back to Checkout</span></a>
         </div>
diff --git a/KCLS/sql/schema/deploy/selfcheck-email-receipts.sql b/KCLS/sql/schema/deploy/selfcheck-email-receipts.sql
new file mode 100644 (file)
index 0000000..981a9d4
--- /dev/null
@@ -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 (file)
index 0000000..981ead1
--- /dev/null
@@ -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;
index 70cf22b..97432be 100644 (file)
@@ -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,,, <berick@kcls-dev-local> # KCLS 2.9 to 2.10 SQL upgrade
 org-phones [2.9-to-2.10-upgrade] 2017-11-22T16:23:27Z Bill Erickson,,, <berick@kcls-dev-local> # Add a pile of org unit phone numbers
 2.9-to-2.10-upgrade-reingest [org-phones] 2017-06-26T19:01:20Z Bill Erickson,,, <berick@kcls-dev-local> # 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 <vlewis@catalyte.io> # 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 (file)
index 0000000..07d91ea
--- /dev/null
@@ -0,0 +1,7 @@
+-- Verify kcls-evergreen:selfcheck-email-receipts on pg
+
+BEGIN;
+
+-- XXX Add verifications here.
+
+ROLLBACK;
index 8b42dc2..6b9fcb0 100644 (file)
@@ -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();
-        }
     }
 );