cleaning up, testing
authorerickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Wed, 28 Jun 2006 22:16:09 +0000 (22:16 +0000)
committererickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Wed, 28 Jun 2006 22:16:09 +0000 (22:16 +0000)
git-svn-id: svn://svn.open-ils.org/ILS/trunk@4823 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/src/javascript/backend/circ/circ_lib.js
Open-ILS/src/javascript/backend/circ/circ_permit_copy.js
Open-ILS/src/javascript/backend/circ/circ_permit_patron.js
Open-ILS/src/javascript/backend/penalty/patron_penalty.js
Open-ILS/src/perlmods/OpenILS/Application/Circ/ScriptBuilder.pm
Open-ILS/src/perlmods/OpenILS/Application/Penalty.pm
Open-ILS/src/support-scripts/test-scripts/circ_rules.pl

index 967a983..5a02712 100644 (file)
@@ -31,3 +31,73 @@ function isTrue(d) {
        return false;
 }
 
+
+
+/* collect the useful variables */
+var copy                                       = environment.copy;
+var volume                             = environment.volume;
+var title                              = environment.title;
+var recDescriptor              = environment.titleDescriptor;
+var patron                             = environment.patron;
+var isRenewal                  = environment.isRenewal;
+var patronItemsOut     = environment.patronItemsOut;
+var patronOverdueCount = environment.patronOverdueCount;
+var patronFines                = environment.patronFines;
+var patronProfile;
+var copyStatus;
+
+if( patron.profile ) patronProfile = patron.profile.name.toLowerCase();
+if( copy.status ) copyStatus = copy.status.name.toLowerCase();
+
+
+
+/*
+- at some point we should add a library of objects that map 
+codes to names (item_form, item_type, etc.)
+load_lib('item_form_map.js');
+var form_name = item_form_map[env.record_descriptor.item_form];
+*/
+
+
+
+/* logs a load of info */
+function log_vars( prefix ) {
+
+       var str = prefix + ' : ';
+
+       if(patron) {
+               str += ' Patron=' + patron.id;
+               str += ', Patron Barcode='      + patron.card.barcode;
+               str += ', Patron Username='+ patron.usrname;
+               str += ', Patron Library='      + patron.home_ou.name;
+               str += ', Patron Fines='        + patronFines;
+               str += ', Patron OverdueCount=' + patronOverdueCount;
+               str += ', Patron Items Out=' + patronItemsOut;
+       }
+
+       if(copy)        {
+               str += ', Copy=' + copy.id;
+               str += ', Copy Barcode=' + copy.barcode;
+               str += ', Copy status=' + copyStatus;
+               str += ', Copy location=' + copy.location.name;
+       }
+
+       if(volume)                      str += ', Volume='      + volume.id;
+       if(title)                       str += ', Record='      + title.id;
+
+       if(recDescriptor)       {
+               str += ', Record Descriptor=' + recDescriptor.id;
+               str += ', Item Type='                   + recDescriptor.item_type;
+               str += ', Item Form='                   + recDescriptor.item_form;
+               str += ', Item Lang='                   + recDescriptor.item_lang;
+               str += ', Item Audience='               + recDescriptor.audience;
+       }
+
+       str += ' Is Renewal: '  + ( (isTrue(isRenewal)) ? "yes" : "no" );
+
+
+       log_debug(str);
+}
+
+
+
index 6f3843e..f63a057 100644 (file)
@@ -2,38 +2,7 @@ function go() {
 
 /* load the lib script */
 load_lib('circ_lib.js');
-
-/* collect some useful variables */
-var copy                                       = environment.copy;
-var patron                             = environment.patron;
-var volume                             = environment.volume;
-var title                              = environment.title;
-var recDescriptor              = environment.titleDescriptor;
-var patronProfile              = patron.profile.name.toLowerCase();
-var copyStatus                 = copy.status.name.toLowerCase();
-var isRenewal                  = environment.isRenewal;
-
-/*
-- at some point we should add a library of objects that map 
-codes to names (item_form, item_type, etc.)
-load_lib('item_form_map.js');
-var form_name = item_form_map[env.record_descriptor.item_form];
-*/
-
-
-log_debug('circ_permit_copy: permit circ on ' +
-       '  Copy: '                                      + copy.id + 
-       ', Patron:'                                     + patron.id +
-       ', Patron Username:'            + patron.usrname +
-       ', Patron Library: '            + patron.home_ou.name +
-       ', Copy status: '                       + copyStatus +
-       ', Copy location: '             + copy.location.name +
-       ', Is Renewal: '                        + ( (isTrue(isRenewal)) ? "yes" : "no" ) +
-       ', Item Type: '                 + recDescriptor.item_type +
-       ', Item Form: '                 + recDescriptor.item_form +
-       ', Item Lang: '                 + recDescriptor.item_lang +
-       ', Item Audience: '             + recDescriptor.audience +
-       '');
+log_vars('circ_permit_copy');
 
 
 
index 9c97f14..b98614a 100644 (file)
@@ -1,56 +1,34 @@
 function go() {
 
-/* load the lib script */
+/* load the script library */
 load_lib('circ_lib.js');
+log_vars('circ_permit_patron');
 
 
-/* collect some useful variables */
-var patron                             = environment.patron;
-var patronProfile              = patron.profile.name.toLowerCase();
-var patronItemsOut     = environment.patronItemsOut;
-var patronFines                = environment.patronFines;
-var isRenewal                  = environment.isRenewal;
-
-
-log_debug('circ_permit_patron: permit circ on ' +
-       ', Patron:'                                     + patron.id +
-       ', Patron Username:'            + patron.usrname +
-       ', Patron Profile: '            + patronProfile +
-       ', Patron copies: '             + patronItemsOut +
-       ', Patron Library: '            + patron.home_ou.name +
-       ', Patron fines: '              + patronFines +
-       ', Is Renewal: '                        + ( (isRenewal) ? "yes" : "no" ) +
-       '');
-
 
+/* make sure they are not barred */
 if( isTrue(patron.barred) ) 
        result.events.push('PATRON_BARRED');
 
 
-/* define the items out limits */
-var PROFILES = {
+/* ---------------------------------------------------------------------
+       Set up the limits for the various profiles.
+       values of -1 mean there is no limit 
+       --------------------------------------------------------------------- */
+var PROFILES = {};
+PROFILES['class']                      = { itemsOutLimit : 10 };
+PROFILES['patrons']            = { itemsOutLimit : 10 };
+PROFILES['restricted'] = { itemsOutLimit : 2 };
+PROFILES['circulators'] = { itemsOutLimit : -1 };
+PROFILES['local system administrator'] = { itemsOutLimit : -1 };
+/* add profiles as necessary ... */
 
-       restricted : {
-               itemsOutLimit : 2,
-       },
-       patrons : {
-               itemsOutLimit : 10,
-       },
-       'class' : {
-               itemsOutLimit : 10,
-       },
-       'local system administrator' : {
-               itemsOut : -1,
-       },
-       circulators : {
-               itemsOut : -1,
-       }
 
 
-       /* Add profiles as necessary ... */
-}
-
 
+/* ---------------------------------------------------------------------
+       Check the items out count 
+       --------------------------------------------------------------------- */
 var profile = PROFILES[patronProfile];
 if( profile ) {
        if( patronItemsOut > 0 && patronItemsOut > profile.itemsOutLimit )
index 6530ae3..530eff3 100644 (file)
@@ -2,51 +2,16 @@ function go() {
 
 /* load the lib script */
 load_lib('../circ/circ_lib.js');
+log_vars('patron_penalty');
 
 
-/* collect some useful variables */
-var patron                                     = environment.patron;
-var patronProfile                      = patron.profile.name.toLowerCase();
-var patronFines                        = environment.patronFines;
-var patronOverdueCount = environment.patronOverdueCount;
-
-
-log_debug('Patron penalty script: ' +
-       ', Patron:'                                     + patron.id +
-       ', Patron Username:'            + patron.usrname +
-       ', Patron Profile: '            + patronProfile +
-       ', Patron Library: '            + patron.home_ou.name +
-       ', Patron fines: '              + patronFines +
-       ', Patron overdue: '            + patronOverdueCount +
-       '');
-
-
-var PROFILES = {
-       restricted : {
-               fineLimit : 0,
-               overdueLimit : 0,
-       },
-       patrons : {
-               fineLimit : 10,
-               overdueLimit : 10,
-       },
-       'class' : {
-               fineLimit : 10,
-               overdueLimit : 10,
-       },
-       circulators : {
-               fineLimit : -1,
-               overdueLimit : -1,
-       },
-       'local system administrator' : {
-               fineLimit : -1,
-               overdueLimit : -1,
-       }
-
-       /* Add profiles as necessary ... */
-}
-
-
+var PROFILES = {};
+PROFILES['class']                      = { fineLimit : 10, overdueLimit : 10 };
+PROFILES['patrons']            = { fineLimit : 10, overdueLimit : 10 };
+PROFILES['restricted'] = { fineLimit : 0, overdueLimit : 0 };
+PROFILES['circulators'] = { fineLimit : -1, overdueLimit : -1 };
+PROFILES['local system administrator'] = { fineLimit : -1, overdueLimit : -1 };
+/* add profiles as necessary ... */
 
 var profile = PROFILES[patronProfile];
 
index beee99c..26bbd9d 100644 (file)
@@ -4,6 +4,7 @@ use OpenILS::Utils::ScriptRunner;
 use OpenILS::Utils::CStoreEditor qw/:funcs/;
 use OpenILS::Application::AppUtils;
 use OpenILS::Application::Actor;
+use OpenSRF::Utils::Logger qw/$logger/;
 my $U = "OpenILS::Application::AppUtils";
 use Data::Dumper;
 
@@ -59,9 +60,9 @@ sub build_runner {
        $runner->insert( "$evt.requestor",      $ctx->{requestor}, 1);
        $runner->insert( "$evt.titleDescriptor", $ctx->{titleDescriptor}, 1);
 
-       $runner->insert( "$evt.patronItemsOut", $ctx->{patronItemsOut} );
-       $runner->insert( "$evt.patronOverdueCount", $ctx->{patronOverdue} );
-       $runner->insert( "$evt.patronFines", $ctx->{patronFines} );
+       $runner->insert( "$evt.patronItemsOut", $ctx->{patronItemsOut}, 1 );
+       $runner->insert( "$evt.patronOverdueCount", $ctx->{patronOverdue}, 1 );
+       $runner->insert( "$evt.patronFines", $ctx->{patronFines}, 1 );
 
        # circ script result
        $runner->insert("result", {});
@@ -168,11 +169,11 @@ sub fetch_user_data {
                @GROUP_LIST = @$s;
        }
 
-       warn 'patron profile = ' . $patron->profile . "\n";
        $patron->profile( 
                grep { $_->id == $patron->profile } @GROUP_LIST ) 
                unless ref $patron->profile;
-       warn 'patron profile = ' . $patron->profile->name . "\n";
+
+       $patron->card($e->retrieve_actor_card($patron->card));
 
        $ctx->{requestor} = $ctx->{requestor} || $e->requestor;
 
@@ -197,6 +198,9 @@ sub fetch_user_data {
                my $fines = 0;
                $fines += $_->balance_owed for @$fxacts;
                $ctx->{patronFines} = $fines;
+
+               $logger->debug("script_builder: patron fines determined to be $fines");
+               $logger->debug("script_builder: patron overdue count is " . $ctx->{patronOverdue});
        }
 
        return undef;
index 7f035d3..4656341 100644 (file)
@@ -98,8 +98,10 @@ sub patron_penalty {
                { fatal_penalties => \@fatals, info_penalties => \@infos });
 
        # - update the penalty info in the db if necessary
+       $logger->debug("update penalty settings = " . $$args{update});
+
        $evt = update_patron_penalties( 
-               patron    => $patron
+               patron    => $args->{patron}
                penalties => $all ) if $$args{update};
 
        # - The caller won't know it failed, so log it
@@ -119,9 +121,11 @@ sub update_patron_penalties {
        my %args      = @_;
        my $patron    = $args{patron};
        my $penalties = $args{penalties};
+       my $pid = $patron->id;
+
+       $logger->debug("updating penalties for patron $pid => @$penalties");
 
        my $session   = $U->start_db_session();
-       my $pid = ($patron) ? $patron->id : $args{patronid};
 
        # - fetch the current penalties
        my $existing = $session->request(
index 237b393..8c63e7d 100644 (file)
@@ -16,7 +16,8 @@ my $info_events       = 'result.infoEvents';
 # ---------------------------------------------------------------------
 # SCRIPT VARS
 # ----------------------------------------------------------------------
-my $patronid                                   = 3;
+#my $patronid                                  = 3;
+my $patronid                                   = 1000502;
 my $copyid                                             = 8000107;
 my $patron_items_out                   = 11;
 my $patron_overdue_count       = 11;