X-Git-Url: http://git.rot13.org/?a=blobdiff_plain;f=admin%2Fsmart-rules.pl;h=8e5a2d5802c40d00bef9e8c98945107ee857c5e0;hb=67942f7432e8706c460e7f8e36178c0cd60333f7;hp=d015ec2a0079533ca6d0a526188764a307b9dd10;hpb=1e98195b1014f9b0680be9d6ea9e8e8132821158;p=koha.git diff --git a/admin/smart-rules.pl b/admin/smart-rules.pl index d015ec2a00..8e5a2d5802 100755 --- a/admin/smart-rules.pl +++ b/admin/smart-rules.pl @@ -1,6 +1,6 @@ #!/usr/bin/perl -# vim: et ts=4 sw=4 # Copyright 2000-2002 Katipo Communications +# copyright 2010 BibLibre # # This file is part of Koha. # @@ -18,7 +18,7 @@ # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. use strict; -#use warnings; FIXME - Bug 2505 +use warnings; use CGI; use C4::Context; use C4::Output; @@ -26,8 +26,9 @@ use C4::Auth; use C4::Koha; use C4::Debug; use C4::Branch; # GetBranches +use C4::Dates qw/format_date format_date_in_iso/; -my $input = new CGI; +my $input = CGI->new; my $dbh = C4::Context->dbh; # my $flagsrequired; @@ -99,9 +100,9 @@ elsif ($op eq 'delete-branch-item') { } # save the values entered elsif ($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, renewalsallowed, reservesallowed, issuelength, fine, finedays, firstremind, chargeperiod,rentaldiscount) VALUES(?,?,?,?,?,?,?,?,?,?,?,?)"); - my $sth_update=$dbh->prepare("UPDATE issuingrules SET fine=?, finedays=?, firstremind=?, chargeperiod=?, maxissueqty=?, renewalsallowed=?, reservesallowed=?, issuelength=?, rentaldiscount=? WHERE branchcode=? AND categorycode=? AND itemtype=?"); + 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, renewalsallowed, reservesallowed, issuelength, lengthunit, hardduedate, hardduedatecompare, fine, finedays, firstremind, chargeperiod,rentaldiscount) VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)'); + my $sth_update=$dbh->prepare("UPDATE issuingrules SET fine=?, finedays=?, firstremind=?, chargeperiod=?, maxissueqty=?, renewalsallowed=?, reservesallowed=?, issuelength=?, lengthunit = ?, hardduedate=?, hardduedatecompare=?, rentaldiscount=? WHERE branchcode=? AND categorycode=? AND itemtype=?"); my $br = $branch; # branch my $bor = $input->param('categorycode'); # borrower category @@ -116,21 +117,26 @@ elsif ($op eq 'add') { $maxissueqty =~ s/\s//g; $maxissueqty = undef if $maxissueqty !~ /^\d+/; my $issuelength = $input->param('issuelength'); + my $lengthunit = $input->param('lengthunit'); + my $hardduedate = $input->param('hardduedate'); + $hardduedate = format_date_in_iso($hardduedate); + my $hardduedatecompare = $input->param('hardduedatecompare'); my $rentaldiscount = $input->param('rentaldiscount'); $debug and 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, $finedays,$firstremind, $chargeperiod, $maxissueqty, $renewalsallowed,$reservesallowed, $issuelength,$rentaldiscount, $br,$bor,$cat); + $sth_update->execute($fine, $finedays,$firstremind, $chargeperiod, $maxissueqty, $renewalsallowed,$reservesallowed, $issuelength,$lengthunit, $hardduedate,$hardduedatecompare,$rentaldiscount, $br,$bor,$cat); } else { - $sth_insert->execute($br,$bor,$cat,$maxissueqty,$renewalsallowed,$reservesallowed,$issuelength,$fine,$finedays,$firstremind,$chargeperiod,$rentaldiscount); + $sth_insert->execute($br,$bor,$cat,$maxissueqty,$renewalsallowed,$reservesallowed,$issuelength,$lengthunit,$hardduedate,$hardduedatecompare,$fine,$finedays,$firstremind,$chargeperiod,$rentaldiscount); } } elsif ($op eq "set-branch-defaults") { my $categorycode = $input->param('categorycode'); my $maxissueqty = $input->param('maxissueqty'); my $holdallowed = $input->param('holdallowed'); + my $returnbranch = $input->param('returnbranch'); $maxissueqty =~ s/\s//g; $maxissueqty = undef if $maxissueqty !~ /^\d+/; $holdallowed =~ s/\s//g; @@ -140,34 +146,34 @@ elsif ($op eq "set-branch-defaults") { my $sth_search = $dbh->prepare("SELECT count(*) AS total FROM default_circ_rules"); my $sth_insert = $dbh->prepare("INSERT INTO default_circ_rules - (maxissueqty, holdallowed) - VALUES (?, ?)"); + (maxissueqty, holdallowed, returnbranch) + VALUES (?, ?, ?)"); my $sth_update = $dbh->prepare("UPDATE default_circ_rules - SET maxissueqty = ?, holdallowed = ?"); + SET maxissueqty = ?, holdallowed = ?, returnbranch = ?"); $sth_search->execute(); my $res = $sth_search->fetchrow_hashref(); if ($res->{total}) { - $sth_update->execute($maxissueqty, $holdallowed); + $sth_update->execute($maxissueqty, $holdallowed, $returnbranch); } else { - $sth_insert->execute($maxissueqty, $holdallowed); + $sth_insert->execute($maxissueqty, $holdallowed, $returnbranch); } } else { my $sth_search = $dbh->prepare("SELECT count(*) AS total FROM default_branch_circ_rules WHERE branchcode = ?"); my $sth_insert = $dbh->prepare("INSERT INTO default_branch_circ_rules - (branchcode, maxissueqty, holdallowed) - VALUES (?, ?, ?)"); + (branchcode, maxissueqty, holdallowed, returnbranch) + VALUES (?, ?, ?, ?)"); my $sth_update = $dbh->prepare("UPDATE default_branch_circ_rules - SET maxissueqty = ?, holdallowed = ? + SET maxissueqty = ?, holdallowed = ?, returnbranch = ? WHERE branchcode = ?"); $sth_search->execute($branch); my $res = $sth_search->fetchrow_hashref(); if ($res->{total}) { - $sth_update->execute($maxissueqty, $holdallowed, $branch); + $sth_update->execute($maxissueqty, $holdallowed, $returnbranch, $branch); } else { - $sth_insert->execute($branch, $maxissueqty, $holdallowed); + $sth_insert->execute($branch, $maxissueqty, $holdallowed, $returnbranch); } } } @@ -254,6 +260,7 @@ elsif ($op eq "add-branch-cat") { elsif ($op eq "add-branch-item") { my $itemtype = $input->param('itemtype'); my $holdallowed = $input->param('holdallowed'); + my $returnbranch = $input->param('returnbranch'); $holdallowed =~ s/\s//g; $holdallowed = undef if $holdallowed !~ /^\d+/; @@ -262,34 +269,34 @@ elsif ($op eq "add-branch-item") { my $sth_search = $dbh->prepare("SELECT count(*) AS total FROM default_circ_rules"); my $sth_insert = $dbh->prepare("INSERT INTO default_circ_rules - (holdallowed) - VALUES (?)"); + (holdallowed, returnbranch) + VALUES (?, ?)"); my $sth_update = $dbh->prepare("UPDATE default_circ_rules - SET holdallowed = ?"); + SET holdallowed = ?, returnbranch = ?"); $sth_search->execute(); my $res = $sth_search->fetchrow_hashref(); if ($res->{total}) { - $sth_update->execute($holdallowed); + $sth_update->execute($holdallowed, $returnbranch); } else { - $sth_insert->execute($holdallowed); + $sth_insert->execute($holdallowed, $returnbranch); } } else { my $sth_search = $dbh->prepare("SELECT count(*) AS total FROM default_branch_item_rules WHERE itemtype = ?"); my $sth_insert = $dbh->prepare("INSERT INTO default_branch_item_rules - (itemtype, holdallowed) - VALUES (?, ?)"); + (itemtype, holdallowed, returnbranch) + VALUES (?, ?, ?)"); my $sth_update = $dbh->prepare("UPDATE default_branch_item_rules - SET holdallowed = ? + SET holdallowed = ?, returnbranch = ? WHERE itemtype = ?"); $sth_search->execute($itemtype); my $res = $sth_search->fetchrow_hashref(); if ($res->{total}) { - $sth_update->execute($holdallowed, $itemtype); + $sth_update->execute($holdallowed, $returnbranch, $itemtype); } else { - $sth_insert->execute($itemtype, $holdallowed); + $sth_insert->execute($itemtype, $holdallowed, $returnbranch); } } } elsif ($itemtype eq "*") { @@ -297,17 +304,17 @@ elsif ($op eq "add-branch-item") { FROM default_branch_circ_rules WHERE branchcode = ?"); my $sth_insert = $dbh->prepare("INSERT INTO default_branch_circ_rules - (branchcode, holdallowed) - VALUES (?, ?)"); + (branchcode, holdallowed, returnbranch) + VALUES (?, ?, ?)"); my $sth_update = $dbh->prepare("UPDATE default_branch_circ_rules - SET holdallowed = ? + SET holdallowed = ?, returnbranch = ? WHERE branchcode = ?"); $sth_search->execute($branch); my $res = $sth_search->fetchrow_hashref(); if ($res->{total}) { - $sth_update->execute($holdallowed, $branch); + $sth_update->execute($holdallowed, $returnbranch, $branch); } else { - $sth_insert->execute($branch, $holdallowed); + $sth_insert->execute($branch, $holdallowed, $returnbranch); } } else { my $sth_search = $dbh->prepare("SELECT count(*) AS total @@ -315,19 +322,19 @@ elsif ($op eq "add-branch-item") { WHERE branchcode = ? AND itemtype = ?"); my $sth_insert = $dbh->prepare("INSERT INTO branch_item_rules - (branchcode, itemtype, holdallowed) - VALUES (?, ?, ?)"); + (branchcode, itemtype, holdallowed, returnbranch) + VALUES (?, ?, ?, ?)"); my $sth_update = $dbh->prepare("UPDATE branch_item_rules - SET holdallowed = ? + SET holdallowed = ?, returnbranch = ? WHERE branchcode = ? AND itemtype = ?"); $sth_search->execute($branch, $itemtype); my $res = $sth_search->fetchrow_hashref(); if ($res->{total}) { - $sth_update->execute($holdallowed, $branch, $itemtype); + $sth_update->execute($holdallowed, $returnbranch, $branch, $itemtype); } else { - $sth_insert->execute($branch, $itemtype, $holdallowed); + $sth_insert->execute($branch, $itemtype, $holdallowed, $returnbranch); } } } @@ -335,12 +342,11 @@ elsif ($op eq "add-branch-item") { my $branches = GetBranches(); my @branchloop; for my $thisbranch (sort { $branches->{$a}->{branchname} cmp $branches->{$b}->{branchname} } keys %$branches) { - my $selected = 1 if $thisbranch eq $branch; - my %row =(value => $thisbranch, - selected => $selected, - branchname => $branches->{$thisbranch}->{'branchname'}, - ); - push @branchloop, \%row; + push @branchloop, { + value => $thisbranch, + selected => $thisbranch eq $branch, + branchname => $branches->{$thisbranch}->{'branchname'}, + }; } my $sth=$dbh->prepare("SELECT description,categorycode FROM categories ORDER BY description"); @@ -372,11 +378,20 @@ my $sth2 = $dbh->prepare(" $sth2->execute($branch); while (my $row = $sth2->fetchrow_hashref) { + $row->{'current_branch'} ||= $row->{'branchcode'}; $row->{'humanitemtype'} ||= $row->{'itemtype'}; $row->{'default_humanitemtype'} = 1 if $row->{'humanitemtype'} eq '*'; $row->{'humancategorycode'} ||= $row->{'categorycode'}; $row->{'default_humancategorycode'} = 1 if $row->{'humancategorycode'} eq '*'; $row->{'fine'} = sprintf('%.2f', $row->{'fine'}); + if ($row->{'hardduedate'} ne '0000-00-00') { + $row->{'hardduedate'} = format_date( $row->{'hardduedate'}); + $row->{'hardduedatebefore'} = 1 if ($row->{'hardduedatecompare'} == -1); + $row->{'hardduedateexact'} = 1 if ($row->{'hardduedatecompare'} == 0); + $row->{'hardduedateafter'} = 1 if ($row->{'hardduedatecompare'} == 1); + } else { + $row->{'hardduedate'} = 0; + } push @row_loop, $row; } $sth->finish; @@ -413,7 +428,7 @@ foreach my $entry (@sorted_branch_cat_rules, @sorted_row_loop) { $entry->{unlimited_maxissueqty} = 1 unless defined($entry->{maxissueqty}); } -my @sorted_row_loop = sort by_category_and_itemtype @row_loop; +@sorted_row_loop = sort by_category_and_itemtype @row_loop; my $sth_branch_item; if ($branch eq "*") { @@ -472,6 +487,7 @@ if ($defaults) { $template->param(default_holdallowed_same => 1) if($defaults->{holdallowed} == 1); $template->param(default_holdallowed_any => 1) if($defaults->{holdallowed} == 2); $template->param(default_maxissueqty => $defaults->{maxissueqty}); + $template->param(default_returnbranch => $defaults->{returnbranch}); } $template->param(default_rules => ($defaults ? 1 : 0));