[Koha-patches] [PATCH] Bug 8420: tool statisticfines.pl and hourly loan

Fridolyn SOMERS fridolyn.somers at biblibre.com
Mon Aug 27 09:44:09 CEST 2012


---
 C4/AuthoritiesMarc.pm                              |    6 +-
 authorities/authorities-home.pl                    |  106 +++++++++-----------
 .../prog/en/includes/authorities-search.inc        |   84 +++++++++++++++-
 .../en/modules/authorities/authorities-home.tt     |    9 --
 .../prog/en/modules/authorities/authorities.tt     |    9 --
 .../prog/en/modules/authorities/detail.tt          |   11 +-
 .../en/modules/authorities/searchresultlist.tt     |   24 ++---
 misc/cronjobs/staticfines.pl                       |   23 ++++-
 8 files changed, 162 insertions(+), 110 deletions(-)

diff --git a/C4/AuthoritiesMarc.pm b/C4/AuthoritiesMarc.pm
index 21ebd94..32bca1b 100644
--- a/C4/AuthoritiesMarc.pm
+++ b/C4/AuthoritiesMarc.pm
@@ -1039,8 +1039,10 @@ sub BuildSummary {
         }
 # // form
         foreach my $field ($record->field('7..')) {
-            my $lang = substr($field->subfield('8'),3,3);
-            push @otherscript, { lang => $lang, term => $field->subfield('a'), direction => 'ltr', field => $field->tag() };
+            my $lang = $field->subfield('8') || '';
+            $lang = substr($lang,3,3);
+            my $term = $field->subfield('a') || '';
+            push @otherscript, { lang => $lang, term => $term, direction => 'ltr', field => $field->tag() };
         }
     } else {
 # construct MARC21 summary
diff --git a/authorities/authorities-home.pl b/authorities/authorities-home.pl
index bc565d1..e7bfa16 100755
--- a/authorities/authorities-home.pl
+++ b/authorities/authorities-home.pl
@@ -21,6 +21,7 @@ use strict;
 use warnings;
 
 use CGI;
+use URI::Escape;
 use C4::Auth;
 
 use C4::Context;
@@ -32,13 +33,11 @@ use C4::Koha;    # XXX subfield_is_koha_internal_p
 use C4::Biblio;
 
 my $query = new CGI;
-my $op    = $query->param('op');
-$op ||= q{};
-my $authtypecode = $query->param('authtypecode');
-$authtypecode ||= q{};
-my $dbh = C4::Context->dbh;
+my $dbh   = C4::Context->dbh;
+my $op           = $query->param('op')           || '';
+my $authtypecode = $query->param('authtypecode') || '';
+my $authid       = $query->param('authid')       || '';
 
-my $authid = $query->param('authid');
 my ( $template, $loggedinuser, $cookie );
 
 my $authtypes = getauthtypes;
@@ -71,23 +70,32 @@ if ( $op eq "delete" ) {
     );
     &DelAuthority( $authid, 1 );
 
-    $op = "do_search";
+    if ( $query->param('operator') ) {
+        # query contains search params so perform search
+        $op = "do_search";
+    }
+    else {
+        $op = '';
+    }
 }
 if ( $op eq "do_search" ) {
-    my @marclist  = $query->param('marclist');
-    my @and_or    = $query->param('and_or');
-    my @excluding = $query->param('excluding');
-    my @operator  = $query->param('operator');
-    my $orderby   = $query->param('orderby');
-    my @value     = $query->param('value');
+    my $marclist  = $query->param('marclist')  || '';
+    my $and_or    = $query->param('and_or')    || '';
+    my $excluding = $query->param('excluding') || '';
+    my $operator  = $query->param('operator')  || '';
+    my $orderby   = $query->param('orderby')   || '';
+    my $value     = $query->param('value')     || '';
 
     my $startfrom      = $query->param('startfrom')      || 1;
     my $resultsperpage = $query->param('resultsperpage') || 20;
 
-    my ( $results, $total ) =
-      SearchAuthorities( \@marclist, \@and_or, \@excluding, \@operator, \@value,
-        ( $startfrom - 1 ) * $resultsperpage,
-        $resultsperpage, $authtypecode, $orderby );
+    my ( $results, $total ) = SearchAuthorities(
+        [$marclist],  [$and_or],
+        [$excluding], [$operator],
+        [$value], ( $startfrom - 1 ) * $resultsperpage,
+        $resultsperpage, $authtypecode,
+        $orderby
+    );
 
     ( $template, $loggedinuser, $cookie ) = get_template_and_user(
         {
@@ -101,61 +109,40 @@ if ( $op eq "do_search" ) {
     );
 
     $template->param(
-        marclist       => $query->param('marclist'),
-        and_or         => $query->param('and_or'),
-        excluding      => $query->param('excluding'),
-        operator       => $query->param('operator'),
-        orderby        => $query->param('orderby'),
-        value          => $query->param('value'),
-        authtypecode   => $query->param('authtypecode'),
+        marclist       => $marclist,
+        and_or         => $and_or,
+        excluding      => $excluding,
+        operator       => $operator,
+        orderby        => $orderby,
+        value          => $value,
+        authtypecode   => $authtypecode,
         startfrom      => $startfrom,
         resultsperpage => $resultsperpage,
     );
 
-    my @field_data = ();
-
     # we must get parameters once again. Because if there is a mainentry, it
     # has been replaced by something else during the search, thus the links
     # next/previous would not work anymore
-    my @marclist_ini = $query->param('marclist');
-    for ( my $i = 0 ; $i <= $#marclist ; $i++ ) {
-        if ( $value[$i] ) {
-            push @field_data, { term => "marclist", val => $marclist_ini[$i] };
-            if ( !defined $and_or[$i] ) {
-                $and_or[$i] = q{};
-            }
-            push @field_data, { term => "and_or", val => $and_or[$i] };
-            if ( !defined $excluding[$i] ) {
-                $excluding[$i] = q{};
-            }
-            push @field_data, { term => "excluding", val => $excluding[$i] };
-            push @field_data, { term => "operator",  val => $operator[$i] };
-            push @field_data, { term => "value",     val => $value[$i] };
-        }
-    }
 
     # construction of the url of each page
-    my $base_url =
-        'authorities-home.pl?'
-      . join( '&amp;', map { $_->{term} . '=' . $_->{val} } @field_data )
-      . '&amp;'
-      . join(
-        '&amp;',
-        map { $_->{term} . '=' . $_->{val} } (
-            { term => 'resultsperpage', val => $resultsperpage },
-            { term => 'type',           val => 'intranet' },
-            { term => 'op',             val => 'do_search' },
-            { term => 'authtypecode',   val => $authtypecode },
-            { term => 'orderby',        val => $orderby },
-        )
-      );
+    my $value_url = uri_escape($value);
+    my $base_url = "authorities-home.pl?"
+      ."marclist=$marclist"
+      ."&amp;and_or=$and_or"
+      ."&amp;excluding=$excluding"
+      ."&amp;operator=$operator"
+      ."&amp;value=$value_url"
+      ."&amp;resultsperpage=$resultsperpage"
+      ."&amp;type=intranet"
+      ."&amp;op=do_search"
+      ."&amp;authtypecode=$authtypecode"
+      ."&amp;orderby=$orderby";
 
     my $from = ( $startfrom - 1 ) * $resultsperpage + 1;
     my $to;
     if ( !defined $total ) {
         $total = 0;
     }
-
     if ( $total < $startfrom * $resultsperpage ) {
         $to = $total;
     }
@@ -191,7 +178,10 @@ if ( $op eq '' ) {
 
 }
 
-$template->param( authtypesloop => \@authtypesloop, );
+$template->param(
+    authtypesloop => \@authtypesloop,
+    op            => $op,
+);
 
 $template->{VARS}->{marcflavour} = C4::Context->preference("marcflavour");
 
diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/authorities-search.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/authorities-search.inc
index ca6f4af..f284491 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/includes/authorities-search.inc
+++ b/koha-tmpl/intranet-tmpl/prog/en/includes/authorities-search.inc
@@ -18,16 +18,42 @@
         [% END %]
         </select>
         <input type="hidden" name="marclist" value="mainmainentry" />
+        <input type="hidden" name="and_or" value="and" />
+        <input type="hidden" name="excluding" value="" />
         <select name="operator">
+            [% IF ( operator == 'contains' ) %]
+            <option value="contains" selected="selected">contains</option>
+            [% ELSE %]
             <option value="contains">contains</option>
+            [% END %]
+            [% IF ( operator == 'start' ) %]
+            <option value="start" selected="selected">starts with</option>
+            [% ELSE %]
             <option value="start">starts with</option>
+            [% END %]
+            [% IF ( operator == 'is' ) %]
+            <option value="is" selected="selected">is exactly</option>
+            [% ELSE %]
             <option value="is">is exactly</option>
+            [% END %]
         </select>
         <input id="value_anywhere" type="text" name="value" value="[% value %]" />
         <select name="orderby">
-            <option value="">None</option>
+            [% IF ( orderby == 'HeadingAsc' ) %]
             <option value="HeadingAsc" selected="selected">Heading A-Z</option>
+            [% ELSE %]
+            <option value="HeadingAsc">Heading A-Z</option>
+            [% END %]
+            [% IF ( orderby == 'HeadingDsc' ) %]
+            <option value="HeadingDsc" selected="selected">Heading Z-A</option>
+            [% ELSE %]
             <option value="HeadingDsc">Heading Z-A</option>
+            [% END %]
+            [% IF ( orderby == '' && op ) %]
+            <option value="" selected="selected">None</option>
+            [% ELSE %]
+            <option value="">None</option>
+            [% END %]
          </select>
          <input type="submit" class="submit" value="Submit" />
     </form>
@@ -51,16 +77,40 @@
         <input type="hidden" name="and_or" value="and" />
         <input type="hidden" name="excluding" value="" />
         <select name="operator">
+            [% IF ( operator == 'contains' ) %]
+            <option value="contains" selected="selected">contains</option>
+            [% ELSE %]
             <option value="contains">contains</option>
+            [% END %]
+            [% IF ( operator == 'start' ) %]
+            <option value="start" selected="selected">starts with</option>
+            [% ELSE %]
             <option value="start">starts with</option>
+            [% END %]
+            [% IF ( operator == 'is' ) %]
+            <option value="is" selected="selected">is exactly</option>
+            [% ELSE %]
             <option value="is">is exactly</option>
+            [% END %]
         </select>
         <input id="value_mainentry" type="text" name="value" value="[% value %]" />
         <select name="orderby">
-            <option value="">None</option>
+            [% IF ( orderby == 'HeadingAsc' ) %]
             <option value="HeadingAsc" selected="selected">Heading A-Z</option>
+            [% ELSE %]
+            <option value="HeadingAsc">Heading A-Z</option>
+            [% END %]
+            [% IF ( orderby == 'HeadingDsc' ) %]
+            <option value="HeadingDsc" selected="selected">Heading Z-A</option>
+            [% ELSE %]
             <option value="HeadingDsc">Heading Z-A</option>
-        </select>
+            [% END %]
+            [% IF ( orderby == '' && op ) %]
+            <option value="" selected="selected">None</option>
+            [% ELSE %]
+            <option value="">None</option>
+            [% END %]
+         </select>
         <input type="submit" class="submit" value="Submit" />
     </form>
     </div>
@@ -83,16 +133,40 @@
         <input type="hidden" name="and_or" value="and" />
         <input type="hidden" name="excluding" value="" />
         <select name="operator">
+            [% IF ( operator == 'contains' ) %]
+            <option value="contains" selected="selected">contains</option>
+            [% ELSE %]
             <option value="contains">contains</option>
+            [% END %]
+            [% IF ( operator == 'start' ) %]
+            <option value="start" selected="selected">starts with</option>
+            [% ELSE %]
             <option value="start">starts with</option>
+            [% END %]
+            [% IF ( operator == 'is' ) %]
+            <option value="is" selected="selected">is exactly</option>
+            [% ELSE %]
             <option value="is">is exactly</option>
+            [% END %]
         </select>
         <input id="value_mainmainentry" type="text" name="value" value="[% value %]" />
         <select name="orderby">
-            <option value="">None</option>
+            [% IF ( orderby == 'HeadingAsc' ) %]
             <option value="HeadingAsc" selected="selected">Heading A-Z</option>
+            [% ELSE %]
+            <option value="HeadingAsc">Heading A-Z</option>
+            [% END %]
+            [% IF ( orderby == 'HeadingDsc' ) %]
+            <option value="HeadingDsc" selected="selected">Heading Z-A</option>
+            [% ELSE %]
             <option value="HeadingDsc">Heading Z-A</option>
-        </select>
+            [% END %]
+            [% IF ( orderby == '' && op ) %]
+            <option value="" selected="selected">None</option>
+            [% ELSE %]
+            <option value="">None</option>
+            [% END %]
+         </select>
         <input type="submit" class="submit" value="Submit" />
     </form>
     </div>
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/authorities/authorities-home.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/authorities/authorities-home.tt
index 7d138ff..c0f322e 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/authorities/authorities-home.tt
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/authorities/authorities-home.tt
@@ -7,15 +7,6 @@ function Help() {
     newin=window.open("/cgi-bin/koha/help.pl","KohaHelp",'width=600,height=600,toolbar=false,scrollbars=yes');
 }
 
-function addauthority() {
-    X = document.forms[0].authtype.value;
-    window.location="/cgi-bin/koha/authorities/authorities.pl?authtypecode="+X;
-}
-function searchauthority() {
-    X = document.forms[0].authtype2.value;
-    Y = document.forms[0].value.value;
-    window.location="/cgi-bin/koha/authorities/authorities-home.pl?op=do_search&type=intranet&authtypecode="+X+"&value="+Y+"&marclist=&and_or=and&excluding=&operator=contains";
-}
 function confirm_deletion() {   // not really implemented, but required by phantom delAuthButton code in authorities-toolbar.inc
     return true;
 }
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/authorities/authorities.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/authorities/authorities.tt
index 352d518..5fc02ed 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/authorities/authorities.tt
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/authorities/authorities.tt
@@ -492,15 +492,6 @@ function unHideSubfield(index,labelindex) { // FIXME :: is it used ?
     label.style.display='none'; 
 }
 
-function addauthority() {
-    X = document.forms[0].authtype.value;
-    window.location="/cgi-bin/koha/authorities/authorities.pl?authtypecode="+X;
-}
-function searchauthority() {
-    X = document.forms[0].authtype2.value;
-    Y = document.forms[0].value.value;
-    window.location="/cgi-bin/koha/authorities/authorities-home.pl?op=do_search&type=intranet&authtypecode="+X+"&value="+Y+"&marclist=&and_or=and&excluding=&operator=contains";
-}
 //]]>
 </script>
 <link type="text/css" rel="stylesheet" href="[% themelang %]/css/addbiblio.css" />
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/authorities/detail.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/authorities/detail.tt
index e21f846..426bb5c 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/authorities/detail.tt
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/authorities/detail.tt
@@ -18,7 +18,7 @@
 function confirm_deletion() {
 	var is_confirmed = confirm('Are you sure you want to delete this authority?');
 	if (is_confirmed) {
-		window.location="authorities-home.pl?op=delete&amp;authid=[% authid %]";
+		window.location="authorities-home.pl?op=delete&authid=[% authid %]";
 	}
 }
 function Dopop(link) {
@@ -53,15 +53,6 @@ function Help() {
     newin=window.open("/cgi-bin/koha/help.pl","KohaHelp",'width=600,height=600,toolbar=false,scrollbars=yes');
 }
 
-function addauthority() {
-    X = document.forms[0].authtype.value;
-    window.location="/cgi-bin/koha/authorities/authorities.pl?authtypecode="+X;
-}
-function searchauthority() {
-    X = document.forms[0].authtype2.value;
-    Y = document.forms[0].value.value;
-    window.location="/cgi-bin/koha/authorities/authorities-home.pl?op=do_search&type=intranet&authtypecode="+X+"&value="+Y+"&marclist=&and_or=and&excluding=&operator=contains";
-}
 </script>
  [% END %]
 </head>
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/authorities/searchresultlist.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/authorities/searchresultlist.tt
index 6ac139a..90735fc 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/authorities/searchresultlist.tt
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/authorities/searchresultlist.tt
@@ -8,24 +8,24 @@ function confirm_deletion(id) {
     
     var is_confirmed = confirm('Are you sure you want to delete this authority?');
     if (is_confirmed) {
-      window.location="authorities-home.pl?op=delete&amp;authid="
-          + id
-          + "&amp;marclist=[% marclist %]&amp;and_or=[% and_or %]&amp;excluding=[% excluding %]&amp;operator=[%operator%]&amp;orderby=[% orderby %]&amp;value=[% value %]&amp;startfrom=[% startfrom %]&amp;resultsperpage=[% resultsperpage %]";
+      window.location="authorities-home.pl?op=delete"
+          + "&authid=" + id
+          + "&type=intranet"
+          + "&authtypecode=[% authtypecode %]"
+          + "&marclist=[% marclist %]"
+          + "&and_or=[% and_or %]"
+          + "&excluding=[% excluding %]"
+          + "&operator=[% operator %]"
+          + "&orderby=[% orderby %]"
+          + "&value=[% value |url %]"
+          + "&startfrom=[% startfrom %]"
+          + "&resultsperpage=[% resultsperpage %]";
     }
 }
 function Help() {
     newin=window.open("/cgi-bin/koha/help.pl","KohaHelp",'width=600,height=600,toolbar=false,scrollbars=yes');
 }
 
-function addauthority() {
-    X = document.forms[0].authtype.value;
-    window.location="/cgi-bin/koha/authorities/authorities.pl?authtypecode="+X;
-}
-function searchauthority() {
-    X = document.forms[0].authtype2.value;
-    Y = document.forms[0].value.value;
-    window.location="/cgi-bin/koha/authorities/authorities-home.pl?op=do_search&type=intranet&authtypecode="+X+"&value="+Y+"&marclist=&and_or=and&excluding=&operator=contains";
-}
 //]]>
 </script>
 </head>
diff --git a/misc/cronjobs/staticfines.pl b/misc/cronjobs/staticfines.pl
index 098fae6..b94ff2a 100755
--- a/misc/cronjobs/staticfines.pl
+++ b/misc/cronjobs/staticfines.pl
@@ -45,6 +45,7 @@ use C4::Biblio;
 use C4::Debug;            # supplying $debug and $cgi_debug
 use Getopt::Long;
 use List::MoreUtils qw/none/;
+use Koha::DateUtils;
 
 my $help    = 0;
 my $verbose = 0;
@@ -122,12 +123,19 @@ INIT {
       "Delimiter: '$delim'\n";
 }
 $debug and (defined $borrowernumberlimit) and print "--borrower limitation: borrower $borrowernumberlimit\n";
-my $data = (defined $borrowernumberlimit) ? checkoverdues($borrowernumberlimit) : Getoverdues();
+my ($numOverdueItems, $data);
+if (defined $borrowernumberlimit) {
+    ($numOverdueItems, $data) = checkoverdues($borrowernumberlimit);
+} else {
+    $data = Getoverdues();
+    $numOverdueItems = scalar @$data;
+}
 my $overdueItemsCounted = 0;
 my %calendars           = ();
 $today      = C4::Dates->new();
 $today_iso  = $today->output('iso');
-$today_days = Date_to_Days( split( /-/, $today_iso ) );
+my ($tyear, $tmonth, $tday) = split( /-/, $today_iso );
+$today_days = Date_to_Days( $tyear, $tmonth, $tday );
 
 for ( my $i = 0 ; $i < scalar(@$data) ; $i++ ) {
     my $datedue;
@@ -167,7 +175,7 @@ for ( my $i = 0 ; $i < scalar(@$data) ; $i++ ) {
         $calendars{$branchcode} = C4::Calendar->new( branchcode => $branchcode );
     }
     $calendar = $calendars{$branchcode};
-    my $isHoliday = $calendar->isHoliday( split '/', $today->output('metric') );
+    my $isHoliday = $calendar->isHoliday( $tday, $tmonth, $tyear );
 
     # Reassing datedue_days if -delay specified in commandline
     $bigdebug and warn "Using commandline supplied delay : $delay" if ($delay);
@@ -176,7 +184,13 @@ for ( my $i = 0 ; $i < scalar(@$data) ; $i++ ) {
     ( $datedue_days <= $today_days ) or next;    # or it's not overdue, right?
 
     $overdueItemsCounted++;
-    my ( $amount, $type, $unitcounttotal, $unitcount ) = CalcFine( $data->[$i], $borrower->{'categorycode'}, $branchcode, undef, undef, $datedue, $today );
+    my ( $amount, $type, $unitcounttotal, $unitcount ) = CalcFine( 
+        $data->[$i],
+        $borrower->{'categorycode'},
+        $branchcode, 
+        dt_from_string($datedue->output('iso')),
+        dt_from_string($today->output('iso')),
+    );
 
     # Reassign fine's amount if specified in command-line
     $amount = $catamounts{$borrower->{'categorycode'}} if (defined $catamounts{$borrower->{'categorycode'}});
@@ -224,7 +238,6 @@ for ( my $i = 0 ; $i < scalar(@$data) ; $i++ ) {
     }
 }
 
-my $numOverdueItems = scalar(@$data);
 if ($verbose) {
     print <<EOM;
 Fines assessment -- $today_iso
-- 
1.7.9.5



More information about the Koha-patches mailing list