]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/src/support-scripts/test-scripts/indb_circ.pl
Fix empty statuses filter
[working/Evergreen.git] / Open-ILS / src / support-scripts / test-scripts / indb_circ.pl
1 #!/usr/bin/perl
2 require '../oils_header.pl';
3 use vars qw/$authtoken/;
4 use strict; use warnings;
5 use Time::HiRes qw/time/;
6 use OpenILS::Utils::CStoreEditor qw/:funcs/;
7 use Data::Dumper;
8 use Getopt::Long;
9
10 # ---------------------------------------------------------------
11 # Initial in-db-circ test code
12 # This script takes an org, user, and copy ID and prints out the
13 # circulation rules that would apply
14 # ---------------------------------------------------------------
15
16 my ($config, $org_id, $user_id, $copy_id, $copy_barcode) = 
17     ('/openils/conf/opensrf_core.xml', 326, 3, 301313, undef);
18
19 GetOptions(
20     'org=i' => \$org_id,
21     'user=i' => \$user_id,
22     'copy=i' => \$copy_id,
23     'barcode=s' => \$copy_barcode,
24 );
25
26 osrf_connect($config);
27
28 my $CIRC_TEST = {
29     select => {
30         aou => [{
31             transform => 'action.item_user_circ_test',
32             column => 'id',
33             params => [$copy_id, $user_id],
34             result_field => 'matchpoint',
35             alias => 'matchpoint'
36         }]
37     },
38     from => 'aou',
39     where => {id => $org_id}
40 };
41
42 my $e = new_editor();
43
44 my $start = time;
45 my $mp_id = $e->json_query($CIRC_TEST)->[0]->{matchpoint};
46
47 my $rule_set = $e->search_config_circ_matrix_ruleset([
48     {matchpoint => $mp_id},
49     {   flesh => 1,
50         flesh_fields => {
51             'ccmrs' => ['duration_rule', 'recurring_fine_rule', 'max_fine_rule']
52         }
53     }
54 ])->[0];
55
56 my $rundur = time - $start;
57
58 my $cp = $e->retrieve_asset_copy($copy_id);
59 my ($dur, $recf);
60
61 # get the actual duration
62 if($cp->loan_duration == 1) {
63     $dur = $rule_set->duration_rule->shrt;
64 } elsif($cp->loan_duration == 2) {
65     $dur = $rule_set->duration_rule->normal;
66 } else {
67     $dur = $rule_set->duration_rule->extended;
68 }
69
70 # get the recurring fine level
71 if($cp->fine_level == 1) {
72     $recf = $rule_set->recurring_fine_rule->low;
73 } elsif($cp->fine_level == 2) {
74     $recf = $rule_set->recurring_fine_rule->normal;
75 } else {
76     $recf = $rule_set->recurring_fine_rule->high;
77 }
78
79 print "Duration [".$rule_set->duration_rule->name."] = $dur\n";
80 print "Recurring fines [".$rule_set->recurring_fine_rule->name."; interval='".
81     $rule_set->recurring_fine_rule->recurrence_interval."'] = \$$recf\n";
82 print "Max fine [".$rule_set->max_fine_rule->name."] = \$".$rule_set->max_fine_rule->amount."\n";
83 print "took: $rundur\n";
84
85