[open-ils-commits] r12615 - trunk/Open-ILS/src/perlmods/OpenILS/Application/Trigger/Reactor (erickson)

svn at svn.open-ils.org svn at svn.open-ils.org
Thu Mar 19 15:02:33 EDT 2009


Author: erickson
Date: 2009-03-19 15:02:30 -0400 (Thu, 19 Mar 2009)
New Revision: 12615

Added:
   trunk/Open-ILS/src/perlmods/OpenILS/Application/Trigger/Reactor/ApplyCircFee.pm
Log:
reactor to apply fees to a circulation

Added: trunk/Open-ILS/src/perlmods/OpenILS/Application/Trigger/Reactor/ApplyCircFee.pm
===================================================================
--- trunk/Open-ILS/src/perlmods/OpenILS/Application/Trigger/Reactor/ApplyCircFee.pm	                        (rev 0)
+++ trunk/Open-ILS/src/perlmods/OpenILS/Application/Trigger/Reactor/ApplyCircFee.pm	2009-03-19 19:02:30 UTC (rev 12615)
@@ -0,0 +1,64 @@
+package OpenILS::Application::Trigger::Reactor::ApplyCircFee;
+use base 'OpenILS::Application::Trigger::Reactor';
+use strict; use warnings;
+use Error qw/:try/;
+use OpenSRF::Utils::Logger qw/:logger/;
+use OpenILS::Utils::Fieldmapper;
+use OpenILS::Utils::CStoreEditor q/:funcs/;
+
+
+sub ABOUT {
+    return <<ABOUT;
+    
+    Creates a bill (money.billing) for the configured amount, 
+    linked to the circulation.
+
+    Required event parameters:
+        "amount" The amount to bill
+        "btype" The config.billing_type ID
+    Optional event parameters:
+        "note" Billing note
+
+ABOUT
+}
+
+sub handler {
+    my $self = shift;
+    my $env = shift;
+
+    my $circ = $$env{target};
+    my $amount = $$env{params}{amount};
+    my $btype = $$env{params}{btype};
+    my $note = $$env{params}{note};
+
+    unless($circ and $amount and $btype) {
+        $logger->error("ApplyCircFee requires 'amount' and 'btype' params");
+        return 0;
+    }
+        
+    my $e = new_editor(xact => 1);
+    my $type = $e->retrieve_config_billing_type($btype);
+
+    unless($type) {
+        $logger->error("'$btype' is not a valid config.billing_type ID");
+        $e->rollback;
+        return 0;
+    }
+
+    my $bill = Fieldmapper::money::billing->new;
+    $bill->xact($circ->id);
+    $bill->amount($amount);
+    $bill->note($note);
+    $bill->btype($btype);
+    $bill->billing_type($type->name);
+
+    unless( $e->create_money_billing($bill) ) {
+        $e->rollback;
+        return 0;
+    }
+        
+    $e->commit;
+    return 1;
+}
+
+1;



More information about the open-ils-commits mailing list