From 43b29b60f6e67debb8dc679e0560377d32eb7c6f Mon Sep 17 00:00:00 2001 From: tipaul Date: Wed, 17 Sep 2003 10:22:25 +0000 Subject: [PATCH] fixing some bugs in charges.pl, script that fills the categoryitem table. The categoryitem table contains fines for every itemtype-borrowercategory. Should be templated and added to admin part of Koha (i'll take care of this next week probably) --- charges.pl | 6 +++--- updatecharges.pl | 23 +++++++++++++++-------- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/charges.pl b/charges.pl index 9da30a9d02..5e481aabbf 100755 --- a/charges.pl +++ b/charges.pl @@ -37,8 +37,8 @@ my ($loggedinuser, $cookie, $sessionID) = checkauth($input, 0, $flagsrequired); print $input->header; my $type=$input->param('type'); -print startpage(); -print startmenu('issue'); +# print startpage(); +# print startmenu('issue'); print "Each box needs to be filled in with fine,time to start charging,charging cycle
eg 1,7,7 = $1 fine, after 7 days, every 7 days"; @@ -72,7 +72,7 @@ while (my $data=$sth->fetchrow_hashref){ my $dat=$sth2->fetchrow_hashref; $sth2->finish; my $fine=$dat->{'fine'}+0; - $trow2[$i]="{'itemtype'}\" value=\"$fine,$dat->{'firstremind'},$dat->{'chargeperiod'}\" size=6>"; + $trow2[$i]="{'itemtype'}\" value=\"$fine,$dat->{'firstremind'},$dat->{'chargeperiod'}\" size=6>"; } print mktablerow(11,'white',$data->{'description'},@trow2); } diff --git a/updatecharges.pl b/updatecharges.pl index ba064706c2..c29f986ad3 100755 --- a/updatecharges.pl +++ b/updatecharges.pl @@ -41,17 +41,24 @@ my $dbh = C4::Context->dbh; my @names=$input->param(); foreach my $key (@names){ - - my $bor=substr($key,0,1); - my $cat=$key; - $cat =~ s/[A-Z]//i; + $key =~ /(.*)\.(.*)/; + my $bor=$1; + my $cat=$2; my $data=$input->param($key); my @dat=split(',',$data); # print "$bor $cat $dat[0] $dat[1] $dat[2]
"; - my $sth=$dbh->prepare("Update categoryitem set fine=?,firstremind=?,chargeperiod=? where - categorycode=? and itemtype=?"); - $sth->execute($dat[0],$dat[1],$dat[2],$bor,$cat); - $sth->finish; + my $sth_search = $dbh->prepare("select count(*) as total from categoryitem where categorycode=? and itemtype=?"); + my $sth_insert = $dbh->prepare("insert into categoryitem (categorycode,itemtype,fine,firstremind,chargeperiod) values (?,?,?,?,?)"); + my $sth_update=$dbh->prepare("Update categoryitem set fine=?,firstremind=?,chargeperiod=? where categorycode=? and itemtype=?"); + $sth_search->execute($bor,$cat); + my $res = $sth_search->fetchrow_hashref(); + if ($res->{total}) { + warn "UPDATE"; + $sth_update->execute($dat[0],$dat[1],$dat[2],$bor,$cat); + } else { + warn "INSERT"; + $sth_insert->execute($bor,$cat,$dat[0],$dat[1],$dat[2]); +} } print $input->redirect("/cgi-bin/koha/charges.pl"); #print endmenu('issue'); -- 2.39.5