3 # Copyright 2000-2002 Katipo Communications
5 # This file is part of Koha.
7 # Koha is free software; you can redistribute it and/or modify it under the
8 # terms of the GNU General Public License as published by the Free Software
9 # Foundation; either version 2 of the License, or (at your option) any later
12 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License along with
17 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
18 # Suite 330, Boston, MA 02111-1307 USA
27 use C4::Branch; # GetBranches
30 my $dbh = C4::Context->dbh;
32 my $type=$input->param('type');
33 my $branch = $input->param('branch');
34 $branch="" unless $branch;
35 my $op = $input->param('op');
38 # $flagsrequired->{circulation}=1;
39 my ($template, $loggedinuser, $cookie)
40 = get_template_and_user({template_name => "admin/finesrules.tmpl",
44 flagsrequired => {parameters => 1},
47 # save the values entered
49 my @names=$input->param();
50 my $sth_search = $dbh->prepare("select count(*) as total from issuingrules where branchcode=? and categorycode=? and itemtype=?");
52 my $sth_Finsert = $dbh->prepare("insert into issuingrules (branchcode,categorycode,itemtype,fine,firstremind,chargeperiod) values (?,?,?,?,?,?)");
53 my $sth_Fupdate=$dbh->prepare("Update issuingrules set fine=?,firstremind=?,chargeperiod=? where branchcode=? and categorycode=? and itemtype=?");
54 my $sth_Fdelete=$dbh->prepare("delete from issuingrules where branchcode=? and categorycode=? and itemtype=? and issuelength=0");
56 foreach my $key (@names){
58 if ($key =~ /F-(.*)-(.*)\.(.*)/) {
60 my $bor = $2; # borrower category
61 my $cat = $3; # item type
62 my $data=$input->param($key);
63 my ($fine,$firstremind,$chargeperiod)=split(',',$data);
64 # warn "$br $bor $cat $fine $firstremind $chargeperiod";
66 # $br="*" unless ($br);
67 $bor="*" unless ($bor);
68 $cat="*" unless ($cat);
69 $sth_search->execute($br,$bor,$cat);
70 my $res = $sth_search->fetchrow_hashref();
72 $sth_Fupdate->execute($fine,$firstremind,$chargeperiod,$br,$bor,$cat);
74 $sth_Finsert->execute($br,$bor,$cat,$fine,$firstremind,$chargeperiod);
80 my $branches = GetBranches;
82 foreach my $thisbranch (keys %$branches) {
83 my $selected = 1 if $thisbranch eq $branch;
84 my %row =(value => $thisbranch,
85 selected => $selected,
86 branchname => $branches->{$thisbranch}->{'branchname'},
88 push @branchloop, \%row;
91 my $sth=$dbh->prepare("Select description,categorycode from categories order by description");
96 while (my $data=$sth->fetchrow_hashref){
97 my %row = (in_title => $data->{'description'});
98 push @title_loop,\%row;
99 push @trow3,$data->{'categorycode'};
103 my %row = (in_title => "*");
104 push @title_loop, \%row;
108 $sth=$dbh->prepare("Select description,itemtype from itemtypes order by description");
114 while (my $row=$sth->fetchrow_hashref){
115 push @itemtypes,\$row;
118 $line->{itemtype} = "*";
119 $line->{description} = "*";
120 push @itemtypes,\$line;
122 foreach my $data (@itemtypes) {
125 if ( $toggle eq 1 ) {
130 for (my $i=0;$i<=$#trow3;$i++){
131 my $sth2=$dbh->prepare("select * from issuingrules where branchcode=? and categorycode=? and itemtype=?");
132 $sth2->execute($branch,$trow3[$i],$$data->{'itemtype'});
133 my $dat=$sth2->fetchrow_hashref;
135 my $fine=$dat->{'fine'}+0;
137 $finesvalue= "$fine,$dat->{'firstremind'},$dat->{'chargeperiod'}" if $fine+$dat->{'firstremind'}+$dat->{'chargeperiod'}>0;
138 my %row = (finesname=> "F-$branch-$trow3[$i].$$data->{'itemtype'}",
139 finesvalue => $finesvalue,
142 push @cell_loop,\%row;
144 my %row = (categorycode => $$data->{description},
146 push @row_loop, \%row;
150 $template->param(title => \@title_loop,
152 branchloop => \@branchloop,
154 intranetcolorstylesheet => C4::Context->preference("intranetcolorstylesheet"),
155 intranetstylesheet => C4::Context->preference("intranetstylesheet"),
156 IntranetNav => C4::Context->preference("IntranetNav"),
158 output_html_with_http_headers $input, $cookie, $template->output;