From 947add3ff81978840c162341f833494ba260b12f Mon Sep 17 00:00:00 2001 From: Pianohacker Date: Sat, 23 Feb 2008 08:01:03 +1300 Subject: [PATCH] Added combined, line-wise smart-rules script for defining issuingrules. Also added template for "prog" set, and modified admin-home and -menu accordingly. Signed-off-by: Chris Cormack Signed-off-by: Joshua Ferraro --- admin/smart-rules.pl | 133 ++++++++++++++++++ .../prog/en/includes/admin-menu.inc | 1 + .../prog/en/modules/admin/admin-home.tmpl | 2 + .../prog/en/modules/admin/smart-rules.tmpl | 108 ++++++++++++++ 4 files changed, 244 insertions(+) create mode 100755 admin/smart-rules.pl create mode 100644 koha-tmpl/intranet-tmpl/prog/en/modules/admin/smart-rules.tmpl diff --git a/admin/smart-rules.pl b/admin/smart-rules.pl new file mode 100755 index 0000000000..4ad7ba5717 --- /dev/null +++ b/admin/smart-rules.pl @@ -0,0 +1,133 @@ +#!/usr/bin/perl +# vim: et ts=4 sw=4 +# Copyright 2000-2002 Katipo Communications +# +# This file is part of Koha. +# +# Koha is free software; you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation; either version 2 of the License, or (at your option) any later +# version. +# +# Koha is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with +# Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place, +# Suite 330, Boston, MA 02111-1307 USA + +use strict; +use CGI; +use C4::Context; +use C4::Output; +use C4::Auth; +use C4::Koha; +use C4::Branch; # GetBranches + +my $input = new CGI; +my $dbh = C4::Context->dbh; + +my $type=$input->param('type'); +my $branch = $input->param('branch'); +$branch="*" unless $branch; +my $op = $input->param('op'); + +# my $flagsrequired; +# $flagsrequired->{circulation}=1; +my ($template, $loggedinuser, $cookie) + = get_template_and_user({template_name => "admin/smart-rules.tmpl", + query => $input, + type => "intranet", + authnotrequired => 0, + flagsrequired => {parameters => 1}, + debug => 1, + }); + +if ($op =~ 'delete-(.*)-(.*)') { + my $itemtype = $1; + my $categorycode = $2; + warn "deleting $1 $2 $branch"; + + my $sth_Idelete = $dbh->prepare("delete from issuingrules where branchcode=? and categorycode=? and itemtype=?"); + $sth_Idelete->execute($branch, $categorycode, $itemtype); +} +# save the values entered +if ($op eq 'add') { + my $sth_search = $dbh->prepare("SELECT COUNT(*) AS total FROM issuingrules WHERE branchcode=? AND categorycode=? AND itemtype=?"); + my $sth_insert = $dbh->prepare("INSERT INTO issuingrules (branchcode, categorycode, itemtype, maxissueqty, issuelength, fine, firstremind, chargeperiod) VALUES(?,?,?,?,?,?,?,?)"); + my $sth_update=$dbh->prepare("UPDATE issuingrules SET fine=?, firstremind=?, chargeperiod=?, maxissueqty=?, issuelength=? WHERE branchcode=? AND categorycode=? AND itemtype=?"); + + my $br = $branch; # branch + my $bor = $input->param('categorycode'); # borrower category + my $cat = $input->param('itemtype'); # item type + my $fine = $input->param('fine'); + my $firstremind = $input->param('firstremind'); + my $chargeperiod = $input->param('chargeperiod'); + my $maxissueqty = $input->param('maxissueqty'); + my $issuelength = $input->param('issuelength'); + warn "Adding $br, $bor, $cat, $fine, $maxissueqty"; + + $sth_search->execute($br,$bor,$cat); + my $res = $sth_search->fetchrow_hashref(); + if ($res->{total}) { + $sth_update->execute($fine, $firstremind, $chargeperiod, $maxissueqty,$issuelength,$br,$bor,$cat); + } else { + $sth_insert->execute($br,$bor,$cat,$maxissueqty,$issuelength,$fine,$firstremind,$chargeperiod); + } +} +my $branches = GetBranches(); +my @branchloop; +foreach my $thisbranch (keys %$branches) { + my $selected = 1 if $thisbranch eq $branch; + my %row =(value => $thisbranch, + selected => $selected, + branchname => $branches->{$thisbranch}->{'branchname'}, + ); + push @branchloop, \%row; +} + +my $sth=$dbh->prepare("SELECT description,categorycode FROM categories ORDER BY description"); +$sth->execute; +my @category_loop; +while (my $data=$sth->fetchrow_hashref){ + push @category_loop,$data; +} + +my %row = (categorycode => "*", description => 'Any'); +push @category_loop, \%row; + +$sth->finish; +$sth=$dbh->prepare("SELECT description,itemtype FROM itemtypes ORDER BY description"); +$sth->execute; +# $i=0; +my $toggle= 1; +my @row_loop; +my @itemtypes; +while (my $row=$sth->fetchrow_hashref){ + push @itemtypes,$row; + +} +my %row = (itemtype => '*', description => 'Any'); +push @itemtypes,\%row; + +my $sth2 = $dbh->prepare("SELECT issuingrules.*, itemtypes.description AS humanitemtype, categories.description AS humancategorycode FROM issuingrules LEFT JOIN itemtypes ON (itemtypes.itemtype = issuingrules.itemtype) LEFT JOIN categories ON (categories.categorycode = issuingrules.categorycode) WHERE issuingrules.branchcode = ?"); +$sth2->execute($branch); + +while (my $row = $sth2->fetchrow_hashref) { + $row->{'humanitemtype'} ||= $row->{'itemtype'}; + $row->{'humanitemtype'} = 'Any' if $row->{'humanitemtype'} eq '*'; + $row->{'humancategorycode'} ||= $row->{'categorycode'}; + $row->{'humancategorycode'} = 'Any' if $row->{'humancategorycode'} eq '*'; + $row->{'fine'} = sprintf('%.2f', $row->{'fine'}); + push @row_loop, $row; +} +$sth->finish; +$template->param(categoryloop => \@category_loop, + itemtypeloop => \@itemtypes, + rules => \@row_loop, + branchloop => \@branchloop, + humanbranch => ($branch ne '*' ? $branches->{$branch}->{branchname} : ''), + branch => $branch + ); +output_html_with_http_headers $input, $cookie, $template->output; diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/admin-menu.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/admin-menu.inc index e34fdc68a0..708a5d0fdc 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/admin-menu.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/admin-menu.inc @@ -18,6 +18,7 @@
  • Road types
  • Circulation rules
  • Fines rules
  • +
  • Alternate issuing rules
  • Catalogue
    diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/admin-home.tmpl b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/admin-home.tmpl index d60d951f31..1e3d370ee1 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/admin-home.tmpl +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/admin-home.tmpl @@ -48,6 +48,8 @@
    Define circulation rules in a matrix for libraries / patrons / itemtypes / circ codes (number of checkouts, duration, fee, etc.).
    Fines rules
    Define fines in a matrix for libraries / patrons / itemtypes (cost, grace period, etc.).
    +
    Circulation and fines rules (alternate layout)
    +
    Define circulation rules and fines as a list
    diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/smart-rules.tmpl b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/smart-rules.tmpl new file mode 100644 index 0000000000..f732236b8a --- /dev/null +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/smart-rules.tmpl @@ -0,0 +1,108 @@ + +Koha › Administration › Issuing Rules + + + + + + + + + + + +
    + +
    +
    +
    +

    + + Defining issuing rules for "" + + Defining default issuing rules + +

    +
    +

    The rules are applied from most specific to less specific, using the first found in this order:

    +
      +
    • same branch, same borrower type, same item type
    • +
    • same branch, same borrower type, default item type
    • +
    • same branch, default borrower type, same item type
    • +
    • default branch, same borrower type, same item type
    • +
    • anything else
    • +
    +

    To modify a rule, create a new one with the same borrower type and item type.

    +
    +
    +
    + Select a branch : + +
    +
    + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    Item TypeBorrower TypeAmountGrace PeriodCharging IntervalAmount LoanableLoan time
    $ day(s) day(s) day(s) + -&branch=">Delete +
    + + + + $ day(s) day(s) day(s)"/>
    +
    +
    +
    + +
    +
    + +
    +
    + -- 2.39.5