(sitka) RT17757, Provide a workaround for dupe payments
authorSteven Chan <schan@sitka.bclibraries.ca>
Tue, 19 Nov 2013 23:22:41 +0000 (15:22 -0800)
committerSteven Chan <schan@sitka.bclibraries.ca>
Thu, 21 Nov 2013 21:40:51 +0000 (13:40 -0800)
The current payment interface of the staff client is producing duplicate
payments, albeit infrequently. For example, the following sequence of
payments is indicative of the problem.

A B C
1 1 1
2 2 2
3 1 1
4 2 2

where
A = payment ID
B = bill ID
C = payment amount

and where all payments have the same timestamp.

For the given sequence, payments 3 and 4 would be duplicates of 1 and 2.

The workaround will not generate payments 3 and 4 for bills 1 and 2,
because the modified for loop will have seen a payment for bills 1 and 2
already.  The workaround is sufficient for handling the current
interface, because it normally generates one payment per bill.

Moreover, if duplicates are seen, they will be counted and the final
count will be sent to an unhandled URL extemporaneously so that we will
get an indication of the problem.

Also, to improve the efficiency of the for loop, bill ID is cached per
loop, because the value is referenced several times.

Signed-off-by: Steven Chan <schan@sitka.bclibraries.ca>
Open-ILS/xul/staff_client/server/patron/bill2.js

index 421b147..cb84547 100644 (file)
@@ -229,15 +229,34 @@ function tally_pending() {
         var tb = $('payment');
         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();
-        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) ] ); }
+        var bill_ids = g.bill_list.dump_retrieve_ids();
+
+        var seen = { '0':0 };
+        for (var i = 0, _l = bill_ids.length; i < _l; i++) {
+            var bill_id = bill_ids[i];
+            var row_params = g.row_map[bill_id];
+            if (g.check_map[bill_id]) { 
+                if (typeof seen[bill_id] === 'undefined') {
+                    var value = util.money.dollars_float_to_cents_integer( row_params.row.my.payment_pending );
+                    payment_pending += value;
+                    if (value != '0.00') { payments.push( [ bill_id, util.money.cents_as_dollars(value) ] ); }
+                }
+                else {
+                    seen[bill_id] = '';
+                    seen[0]++;
+                }
             }
         }
+
+        // if bill list contained duplicates, asynchronously send number of
+        // duplicates to an unhandled URL so that it will be recorded in an
+        // access log
+        if (seen[0] > 0) {
+            var xhr = new XMLHttpRequest();
+            xhr.open('GET', '/debug?duplicate_bills=' + seen[0], true);
+            xhr.send();
+        }
+        
         var change_pending = payment_tendered - payment_pending;
         $('pending_payment').value = util.money.cents_as_dollars( payment_pending );
         $('pending_change').value = util.money.cents_as_dollars( change_pending );