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
26 use C4::Branch; # GetBranches
29 my $dbh = C4::Context->dbh;
31 my $type=$input->param('type');
32 my $branch = $input->param('branch');
33 $branch="*" unless $branch;
34 my $op = $input->param('op');
37 # $flagsrequired->{circulation}=1;
38 my ($template, $loggedinuser, $cookie)
39 = get_template_and_user({template_name => "admin/issuingrules.tmpl",
43 flagsrequired => {parameters => 1},
46 # save the values entered
48 my @names=$input->param();
49 my $sth_search = $dbh->prepare("SELECT branchcode FROM issuingrules WHERE branchcode=? and categorycode=? and itemtype=?");
51 my $sth_Iinsert = $dbh->prepare("INSERT INTO issuingrules (branchcode,categorycode,itemtype,maxissueqty,issuelength,rentaldiscount) VALUES (?,?,?,?,?,?)");
52 my $sth_Iupdate=$dbh->prepare("UPDATE issuingrules SET maxissueqty=?, issuelength=?, rentaldiscount=? WHERE branchcode=? AND categorycode=? AND itemtype=?");
53 my $sth_Idelete=$dbh->prepare("DELETE FROM issuingrules WHERE branchcode=? AND categorycode=? AND itemtype=?");
54 foreach my $key (@names){
56 if ($key =~ /I-(.*)-(.*)-(.*)/) {
57 my $br = base64_to_str($1); # branch
58 my $bor = base64_to_str($2); # borrower category
59 my $cat = base64_to_str($3); # item type
60 my $data=$input->param($key);
61 my ($issuelength,$maxissueqty,$rentaldiscount)=split(',',$data);
63 $sth_search->execute($br,$bor,$cat);
64 my $res = $sth_search->fetchrow_hashref();
65 warn "$br / $bor / $cat = ".$res->{'total'};
66 if ( $res->{'branchcode'} ne $br ) {
67 $sth_Iinsert->execute($br,$bor,$cat,$maxissueqty,$issuelength,$rentaldiscount);
69 $sth_Iupdate->execute($maxissueqty,$issuelength,$rentaldiscount,$br,$bor,$cat);
72 $sth_Idelete->execute($br,$bor,$cat);
77 my $branches = GetBranches;
79 foreach my $thisbranch (keys %$branches) {
80 my $selected = 1 if $thisbranch eq $branch;
81 my %row =(value => $thisbranch,
82 selected => $selected,
83 branchname => $branches->{$thisbranch}->{'branchname'},
85 push @branchloop, \%row;
88 my $sth=$dbh->prepare("SELECT description,categorycode FROM categories ORDER BY description");
92 while (my $data=$sth->fetchrow_hashref){
93 my %row = (in_title => $data->{'description'});
94 push @title_loop,\%row;
95 push @trow3,$data->{'categorycode'};
98 my %row = (in_title => "*");
99 push @title_loop, \%row;
103 $sth=$dbh->prepare("Select description,itemtype from itemtypes order by description");
108 while (my $row=$sth->fetchrow_hashref){
109 push @itemtypes,\$row;
112 $line->{itemtype} = "*";
113 $line->{description} = "*";
114 push @itemtypes,\$line;
116 foreach my $data (@itemtypes) {
119 if ( $toggle eq 1 ) {
124 for (my $i=0;$i<=$#trow3;$i++){
125 my $sth2=$dbh->prepare("SELECT * FROM issuingrules WHERE branchcode=? AND categorycode=? AND itemtype=?");
126 $sth2->execute($branch,$trow3[$i],$$data->{'itemtype'});
127 my $dat=$sth2->fetchrow_hashref;
129 my $fine=$dat->{'fine'};
130 my $maxissueqty = $dat->{'maxissueqty'};
131 my $issuelength = $dat->{'issuelength'};
133 $issuingvalue = "$issuelength,$maxissueqty" if $maxissueqty ne '';
134 my $issuingname = join("-", "I", map { str_to_base64($_) } ($branch, $trow3[$i], $$data->{itemtype}) );
135 my %row = (issuingname => $issuingname,
136 issuingvalue => $issuingvalue,
139 push @cell_loop,\%row;
141 my %row = (categorycode => $$data->{description},
142 total => ($$data->{itemtype} eq '*'?1:0),
145 push @row_loop, \%row;
149 $template->param(title => \@title_loop,
151 branchloop => \@branchloop,
154 output_html_with_http_headers $input, $cookie, $template->output;