1 package OpenILS::Application::Circ::ScriptBuilder;
2 use strict; use warnings;
3 use OpenILS::Utils::ScriptRunner;
4 use OpenILS::Utils::CStoreEditor qw/:funcs/;
5 use OpenILS::Application::AppUtils;
6 use OpenILS::Application::Actor;
7 my $U = "OpenILS::Application::AppUtils";
9 my $evt = "environment";
15 # -----------------------------------------------------------------------
25 # fetch_patron_circ_info - load info on items out, overdues, and fines.
27 # _direct - this is a hash of key/value pairs to shove directly into the
28 # script runner. Use this to cover data not covered by this module
29 # -----------------------------------------------------------------------
31 my( $class, $args ) = @_;
33 my $editor = $$args{editor} || new_editor();
35 $args->{_direct} = {} unless $args->{_direct};
37 fetch_bib_data($editor, $args);
38 fetch_user_data($editor, $args);
39 return build_runner($editor, $args);
46 my $runner = OpenILS::Utils::ScriptRunner->new;
48 $runner->insert( "$evt.patron", $ctx->{patron}, 1);
49 $runner->insert( "$evt.copy", $ctx->{copy}, 1);
50 $runner->insert( "$evt.volume", $ctx->{volume}, 1);
51 $runner->insert( "$evt.record", $ctx->{title}, 1);
52 $runner->insert( "$evt.requestor", $ctx->{requestor}, 1);
53 $runner->insert( "$evt.recordDescriptor", $ctx->{recordDescriptor}, 1);
55 $runner->insert( "$evt.patronItemsOut", $ctx->{patronItemsOut} );
56 $runner->insert( "$evt.patronOverdueCount", $ctx->{patronOverdue} );
57 $runner->insert( "$evt.patronFines", $ctx->{patronFines} );
60 $runner->insert("result", {});
61 $runner->insert("result.events", []);
62 $runner->insert('result.fatalEvents', []);
63 $runner->insert('result.infoEvents', []);
65 $runner->insert("$evt.$_", $ctx->{_direct}->{$_}) for keys %{$ctx->{_direct}};
67 $ctx->{runner} = $runner;
78 $ctx->{copy} = $e->retrieve_asset_copy($ctx->{copy_id})
81 } elsif( $ctx->{copy_barcode} ) {
83 $ctx->{copy} = $e->search_asset_copy(
84 {barcode => $ctx->{copy_barcode}}) or return $e->event;
85 $ctx->{copy} = $ctx->{copy}->[0];
89 return undef unless my $copy = $ctx->{copy};
91 # --------------------------------------------------------------------
92 # Fetch/Cache the copy status and location objects
93 # --------------------------------------------------------------------
95 my $s = $e->retrieve_all_config_copy_status();
97 $s = $e->retrieve_all_asset_copy_location();
98 @COPY_LOCATIONS = @$s;
99 $s = $e->retrieve_all_permission_grp_tree();
103 # Flesh the status and location
104 $copy->status( grep { $_->id == $copy->status } @COPY_STATUSES );
105 $copy->location( grep { $_->id == $copy->location } @COPY_LOCATIONS );
107 $ctx->{volume} = $e->retrieve_asset_call_number(
108 $ctx->{copy}->call_number) or return $e->event;
110 $ctx->{record} = $e->retrieve_biblio_record_entry(
111 $ctx->{volume}->record) or return $e->event;
113 $ctx->{recordDescriptor} = $e->search_metabib_record_descriptor(
114 { record => $ctx->{record}->id }) or return $e->event;
116 $ctx->{recordDescriptor} = $ctx->{recordDescriptor}->[0];
123 sub fetch_user_data {
126 if(!$ctx->{patron}) {
128 if( $ctx->{patron_id} ) {
129 $ctx->{patron} = $e->retrieve_actor_user($ctx->{patron_id});
131 } elsif( $ctx->{patron_barcode} ) {
133 my $card = $e->search_actor_card(
134 { barcode => $ctx->{patron_barcode} } ) or return $e->event;
136 $ctx->{patron} = $e->search_actor_user(
137 { card => $card->[0]->id }) or return $e->event;
138 $ctx->{patron} = $ctx->{patron}->[0];
142 return undef unless my $patron = $ctx->{patron};
144 $patron->home_ou( $e->retrieve_actor_org_unit($patron->home_ou) );
145 $patron->profile( grep { $_->id == $patron->profile } @GROUP_LIST );
147 $ctx->{requestor} = $ctx->{requestor} || $e->requestor;
149 # this could alter the requestor object within the editor..
150 #if( my $req = $ctx->{requestor} ) {
151 # $req->home_ou( $e->retrieve_actor_org_unit($requestor->home_ou) );
152 # $req->ws_ou( $e->retrieve_actor_org_unit($requestor->ws_ou) );
155 if( $ctx->{fetch_patron_circ_info} ) {
158 OpenILS::Application::Actor::_checked_out(1, $e, $patron->id);
160 $ctx->{patronOverdue} = $circ_counts->{overdue} || 0;
161 $ctx->{patronItemsOut} = $ctx->{patronOverdue} + $circ_counts->{out};
164 my $fxacts = $e->search_money_open_billable_transaction_summary(
165 { usr => $patron->id, balance_owed => { ">" => 0 } });
168 $fines += $_->balance_owed for @$fxacts;
169 $ctx->{patronFines} = $fines;