]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/perlmods/OpenILS/Application/Trigger/Reactor/ApplyCircFee.pm
Whitespace. gah.
[Evergreen.git] / Open-ILS / src / perlmods / OpenILS / Application / Trigger / Reactor / ApplyCircFee.pm
1 package OpenILS::Application::Trigger::Reactor::ApplyCircFee;
2 use base 'OpenILS::Application::Trigger::Reactor';
3 use strict; use warnings;
4 use Error qw/:try/;
5 use OpenILS::Const qw/:const/;
6 use OpenILS::Utils::Fieldmapper;
7 use OpenSRF::Utils::Logger qw/:logger/;
8 use OpenILS::Utils::CStoreEditor q/:funcs/;
9
10
11 sub ABOUT {
12     return <<ABOUT;
13     
14     Creates a bill (money.billing) for the configured amount, linked to the circulation.
15     This reactor uses the Notification Fee billing type.
16     If an event definition template is defined, it will be used to generate the bill note.
17
18     Required event parameters:
19         "amount" The amount to bill
20
21 ABOUT
22 }
23
24 sub handler {
25     my $self = shift;
26     my $env = shift;
27
28     my $e = new_editor(xact => 1);
29     my $btype = $e->retrieve_config_billing_type(OILS_BILLING_TYPE_NOTIFICATION_FEE);
30
31     my $circ = $$env{target};
32     my $amount = $$env{params}{amount} || $btype->default_price;
33
34     unless($amount) {
35         $logger->error("ApplyCircFee needs a fee amount");
36         $e->rollback;
37         return 0;
38     }
39
40     my $bill = Fieldmapper::money::billing->new;
41     $bill->xact($circ->id);
42     $bill->amount($amount);
43     $bill->btype(OILS_BILLING_TYPE_NOTIFICATION_FEE);
44     $bill->billing_type($btype->name);
45     $bill->note($self->run_TT($env));
46
47     unless( $e->create_money_billing($bill) ) {
48         $e->rollback;
49         return 0;
50     }
51         
52     $e->commit;
53     return 1;
54 }
55
56 1;