Create grocery bill/payment to track the addition of patron credit.
authorBill Ott <bott@grpl.org>
Wed, 5 Aug 2015 17:38:09 +0000 (13:38 -0400)
committerBill Ott <bott@grpl.org>
Wed, 5 Aug 2015 17:38:09 +0000 (13:38 -0400)
Other than looking at credit_forward_balance in the usr auditor table, there is no other way to see where additional credit was added.

ToDo: something other than hard coding billing_type and btype.  These must match entries in config.billing_type

Signed-off-by: Bill Ott <bott@grpl.org>
Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/Money.pm

index 30e0ca9..8b79ca6 100644 (file)
@@ -603,6 +603,34 @@ sub _update_patron_credit {
     $patron->credit_forward_balance($patron->credit_forward_balance + $credit);
     return OpenILS::Event->new('NEGATIVE_PATRON_BALANCE') if $patron->credit_forward_balance < 0;
     $e->update_actor_user($patron) or return $e->die_event;
+
+    if ($credit > 0){
+        my $cbill = "Fieldmapper::money::grocery";
+        $cbill = $cbill->new;
+        $cbill->billing_location($e->requestor->ws_ou);
+        $cbill->note("New credit: $credit");
+        $cbill->usr($patron->id);
+        my $tid = $e->create_money_grocery($cbill);
+
+        my $billobj = "Fieldmapper::money::billing";
+        $billobj = $billobj->new;
+        $billobj->amount($credit);
+        $billobj->xact($tid);
+        $billobj->billing_type("Credit Added"); # text field, but for sanity, make it match config.billing_type
+        $billobj->btype(235);  # be sure ID matches config.billing_type id
+        $e->create_money_billing($billobj) or return $e->die_event;
+
+        my $payobj = "Fieldmapper::money::cash_payment";
+        $payobj = $payobj->new;
+        $payobj->amount($credit);
+        $payobj->amount_collected($credit);
+        $payobj->xact($tid);
+        $payobj->note("New credit: $credit");
+        $payobj->accepting_usr($e->requestor->id);
+        $payobj->cash_drawer($e->requestor->wsid);
+        $e->create_money_cash_payment($payobj) or return $e->die_event;
+    }
+
     return undef;
 }