fix/debugging aid for a type of duplicate payments collab/phasefx/duplicate_payments
authorJason Etheridge <jason@esilibrary.com>
Mon, 8 Aug 2011 21:15:00 +0000 (17:15 -0400)
committerJason Etheridge <jason@esilibrary.com>
Mon, 8 Aug 2011 21:15:00 +0000 (17:15 -0400)
I haven't been able to reproduce this but I've seen logs where a given
transaction id and payment amount was listed more than once for a given
payment request (open-ils.circ.money.payment).  I can imagine this
happening if util.list is lying to us when we call .dump_retrieve_ids
against the bill list.  This changeset catches that, but since it is
more of a workaround than a true fix, we also warn the user and attempt
to gather more information that may help us pin this down.

Signed-off-by: Jason Etheridge <jason@esilibrary.com>
Open-ILS/xul/staff_client/server/patron/bill2.js

index 76eb5af..3155e4f 100644 (file)
@@ -212,7 +212,7 @@ function default_focus() {
     try { $('payment').focus(); } catch(E) { alert('Error in default_focus(): ' + E); }
 }
 
-function tally_pending() {
+function tally_pending(for_real) {
     try {
         var payments = [];
         JSAN.use('util.money');
@@ -220,15 +220,51 @@ function tally_pending() {
         var payment_tendered = util.money.dollars_float_to_cents_integer( tb.value );
         var payment_pending = 0;
         var retrieve_ids = g.bill_list.dump_retrieve_ids();
+        var seen = {};
+        var danger = false;
         for (var i = 0; i < retrieve_ids.length; i++) {
             var row_params = g.row_map[retrieve_ids[i]];
-            if (g.check_map[retrieve_ids[i]]) { 
-                var value = util.money.dollars_float_to_cents_integer( row_params.row.my.payment_pending );
-                payment_pending += value;
-                if (value != '0.00') { payments.push( [ retrieve_ids[i], util.money.cents_as_dollars(value) ] ); }
+            if (g.check_map[retrieve_ids[i]]) {
+                if (typeof seen[ retrieve_ids[i] ] == 'undefined') {
+                    seen[ retrieve_ids[i] ] = 1;
+                    var value = util.money.dollars_float_to_cents_integer(
+                        row_params.row.my.payment_pending );
+                    payment_pending += value;
+                    if (value != '0.00') { payments.push(
+                        [ retrieve_ids[i], util.money.cents_as_dollars(value) ] ); }
+                } else {
+                    seen[ retrieve_ids[i] ]++;
+                    danger = true;
+                }
             }
         }
         var change_pending = payment_tendered - payment_pending;
+        if (danger && for_real) {
+            var proceed = g.error.yns_alert_formatted(
+                'Please copy the text from this dialog and paste into a support\n'
+                + 'or helpdesk ticket, along with the patron barcode, time of\n'
+                + 'occurence, your type of operating system, and any interesting\n'
+                + 'details such as network or staff client slowness, other error\n'
+                + 'dialogs around the same time, or anything else out of the norm.\n\n'
+                + js2JSON(seen)
+                + '\n\nWe have attempted to auto-correct the error. Please verify the\n'
+                + ' following amounts:\n\npayment tendered = '
+                + util.money.cents_as_dollars(payment_tendered)
+                + '\npayment pending = ' + util.money.cents_as_dollars(payment_pending)
+                + '\nchange pending = ' + util.money.cents_as_dollars(change_pending)
+                + '\n\nPress OK to continue with these amounts, Cancel otherwise',
+                'WARNING: duplicate payment bug encountered',
+                'OK',
+                'Cancel',
+                null,
+                ''
+            );
+            if (proceed != 0) {
+                payments = [];
+                payment_pending = 0;
+                change_pending = payment_tendered;
+            }
+        }
         $('pending_payment').value = util.money.cents_as_dollars( payment_pending );
         $('pending_change').value = util.money.cents_as_dollars( change_pending );
         $('change_due').value = util.money.cents_as_dollars( change_pending );
@@ -805,7 +841,7 @@ function apply_payment() {
         payment_blob.note = payment_blob.note || '';
         //payment_blob.cash_drawer = 1; // FIXME: get new Config() to work
         payment_blob.payment_type = $('payment_type').value;
-        var tally_blob = tally_pending();
+        var tally_blob = tally_pending(true);
         payment_blob.payments = tally_blob.payments;
         // Handle patron credit
         if ( payment_blob.payment_type == 'credit_payment' ) { // paying with patron credit