[Koha-cvs] koha/C4/Circulation Circ2.pm Fines.pm

Tumer Garip tgarip at neu.edu.tr
Sat Sep 2 00:05:51 CEST 2006


CVSROOT:	/sources/koha
Module name:	koha
Changes by:	Tumer Garip <tgarip1957>	06/09/01 22:05:51

Modified files:
	C4/Circulation : Circ2.pm Fines.pm 

Log message:
	New XML handling of data

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/koha/C4/Circulation/Circ2.pm?cvsroot=koha&r1=1.115&r2=1.116
http://cvs.savannah.gnu.org/viewcvs/koha/C4/Circulation/Fines.pm?cvsroot=koha&r1=1.15&r2=1.16

Patches:
Index: Circ2.pm
===================================================================
RCS file: /sources/koha/koha/C4/Circulation/Circ2.pm,v
retrieving revision 1.115
retrieving revision 1.116
diff -u -b -r1.115 -r1.116
--- Circ2.pm	25 Aug 2006 21:07:08 -0000	1.115
+++ Circ2.pm	1 Sep 2006 22:05:51 -0000	1.116
@@ -3,7 +3,7 @@
 
 package C4::Circulation::Circ2;
 
-# $Id: Circ2.pm,v 1.115 2006/08/25 21:07:08 tgarip1957 Exp $
+# $Id: Circ2.pm,v 1.116 2006/09/01 22:05:51 tgarip1957 Exp $
 
 #package to deal with Returns
 #written 3/11/99 by olwen at katipo.co.nz
@@ -81,6 +81,7 @@
 	&calc_charges 
 	&listitemsforinventory 
 	&itemseen 
+	&itemseenbarcode
 	&fixdate 
 	&itemissues 
 	&patronflags
@@ -176,7 +177,7 @@
 						where itemnumber = ?
 									and issues.borrowernumber = borrowers.borrowernumber
 									and returndate is not NULL
-									order by returndate desc,timestamp desc ,limit 2") ;
+									order by returndate desc,timestamp desc limit 2") ;
         $sth2->execute($data->{'itemnumber'}) ;
 #        for (my $i2 = 0; $i2 < 2; $i2++) { # FIXME : error if there is less than 3 pple borrowing this item
 my $i2=0;
@@ -211,26 +212,26 @@
 my $sth=$dbh->prepare("select biblionumber from items where itemnumber=?");
 	$sth->execute($itemnumber);
 my ($biblionumber)=$sth->fetchrow; 
-MARCmoditemonefield($dbh,$biblionumber,$itemnumber,'itemlost',"0",1);
+XMLmoditemonefield($dbh,$biblionumber,$itemnumber,'itemlost',"0",1);
 # find today's date
 my ($sec,$min,$hour,$mday,$mon,$year) = localtime();
 	$year += 1900;
 	$mon += 1;
 	my $timestamp = sprintf("%4d%02d%02d%02d%02d%02d.0",
 		$year,$mon,$mday,$hour,$min,$sec);
-MARCmoditemonefield($dbh,$biblionumber,$itemnumber,'datelastseen', $timestamp);	
+XMLmoditemonefield($dbh,$biblionumber,$itemnumber,'datelastseen', $timestamp);	
 }
 sub itemseenbarcode {
 	my ($dbh,$barcode) = @_;
 my $sth=$dbh->prepare("select biblionumber,itemnumber from items where barcode=$barcode");
 	$sth->execute();
 my ($biblionumber,$itemnumber)=$sth->fetchrow; 
-MARCmoditemonefield($dbh,$biblionumber,$itemnumber,'itemlost',"0",1);
+XMLmoditemonefield($dbh,$biblionumber,$itemnumber,'itemlost',"0",1);
 my ($sec,$min,$hour,$mday,$mon,$year) = localtime();
 	$year += 1900;
 	$mon += 1;
 my $timestamp = sprintf("%4d%02d%02d%02d%02d%02d.0",$year,$mon,$mday,$hour,$min,$sec);
-MARCmoditemonefield($dbh,$biblionumber,$itemnumber,'datelastseen', $timestamp);	
+XMLmoditemonefield($dbh,$biblionumber,$itemnumber,'datelastseen', $timestamp);	
 }
 
 sub listitemsforinventory {
@@ -352,12 +353,14 @@
 # returns a hash of item information together with biblio given either the itemnumber or the barcode
 	my ($env, $itemnumber, $barcode) = @_;
 	my $dbh=C4::Context->dbh;
-	my ($itemrecord)=MARCgetitem($dbh,$itemnumber,$barcode);
-	my $iteminformation=MARCmarc2koha($dbh,$itemrecord,"holdings");
+	my ($itemrecord)=XMLgetitem($dbh,$itemnumber,$barcode);
+	 my $itemhash=XML_xml2hash_onerecord($itemrecord);	
+	my $iteminformation=XMLmarc2koha_onerecord($dbh,$itemhash,"holdings");
 ##Now get full biblio details from MARC
 	if ($iteminformation) {
-my ($record)=MARCgetbiblio($dbh,$iteminformation->{'biblionumber'});
-my $biblio=MARCmarc2koha($dbh,$record,"biblios");
+my ($record)=XMLgetbiblio($dbh,$iteminformation->{'biblionumber'});
+	my $recordhash=XML_xml2hash_onerecord($record);
+my $biblio=XMLmarc2koha_onerecord($dbh,$recordhash,"biblios");
 		foreach my $field (keys %$biblio){
 		$iteminformation->{$field}=$biblio->{$field};
 		} 
@@ -505,7 +508,7 @@
 my $sth=$dbh->prepare("select biblionumber from items where itemnumber=$itemnumber");
 	$sth->execute();
 my ($biblionumber)=$sth->fetchrow; 
-MARCmoditemonefield($dbh,$biblionumber,$itemnumber,'holdingbranch',$holdingbranch,1);
+XMLmoditemonefield($dbh,$biblionumber,$itemnumber,'holdingbranch',$holdingbranch,1);
 	$sth->finish;
 }
 
@@ -894,10 +897,12 @@
 # issuing book. We already have checked it can be issued, so, just issue it !
 #
 sub issuebook {
+### fix me STOP using koha hashes, change so that XML hash is used
 	my ($env,$borrower,$barcode,$date,$cancelreserve) = @_;
 	my $dbh = C4::Context->dbh;
-	my ($itemrecord)=MARCgetitem($dbh,"",$barcode);
-	my $iteminformation=MARCmarc2koha($dbh,$itemrecord,"holdings");
+	my ($itemrecord)=XMLgetitem($dbh,"",$barcode);
+	 $itemrecord=XML_xml2hash_onerecord($itemrecord);
+	my $iteminformation=XMLmarc2koha_onerecord($dbh,$itemrecord,"holdings");
 	my $error;
 #
 # check if we just renew the issue.
@@ -995,17 +1000,17 @@
 		$sth->finish;
 		$iteminformation->{'issues'}++;
 ##Record in MARC the new data ,date_due as due date,issue count and the borrowernumber
-		&MARCkoha2marcOnefield($itemrecord, "issues", $iteminformation->{'issues'},"holdings");
-		&MARCkoha2marcOnefield($itemrecord, "date_due", $dateduef,"holdings");
-		&MARCkoha2marcOnefield($itemrecord, "borrowernumber", $borrower->{'borrowernumber'},"holdings");
-		&MARCkoha2marcOnefield($itemrecord, "itemlost", "0","holdings");
+		$itemrecord=XML_writeline($itemrecord, "issues", $iteminformation->{'issues'},"holdings");
+		$itemrecord=XML_writeline($itemrecord, "date_due", $dateduef,"holdings");
+		$itemrecord=XML_writeline($itemrecord, "borrowernumber", $borrower->{'borrowernumber'},"holdings");
+		$itemrecord=XML_writeline($itemrecord, "itemlost", "0","holdings");
 		# find today's date as timestamp
 		my ($sec,$min,$hour,$mday,$mon,$year) = localtime();
 		$year += 1900;
 		$mon += 1;
 		my $timestamp = sprintf("%4d%02d%02d%02d%02d%02d.0",
 		$year,$mon,$mday,$hour,$min,$sec);
-		&MARCkoha2marcOnefield($itemrecord, "datelastseen", $timestamp,"holdings");
+		$itemrecord=XML_writeline($itemrecord, "datelastseen", $timestamp,"holdings");
 		##Now update the zebradb
 		NEWmoditem($dbh,$itemrecord,$iteminformation->{'biblionumber'},$iteminformation->{'itemnumber'});
 		# If it costs to borrow this book, charge it to the patron's account.
@@ -1140,8 +1145,9 @@
 	my $doreturn = 1;
 	die '$branch not defined' unless defined $branch; # just in case (bug 170)
 	# get information on item
-	my ($itemrecord)=MARCgetitem($dbh,"",$barcode);
-	my $iteminformation=MARCmarc2koha($dbh,$itemrecord,"holdings");
+	my ($itemrecord)=XMLgetitem($dbh,"",$barcode);
+	$itemrecord=XML_xml2hash_onerecord($itemrecord);
+	my $iteminformation=XMLmarc2koha_onerecord($dbh,$itemrecord,"holdings");
 	if (not $iteminformation) {
 		$messages->{'BadBarcode'} = $barcode;
 		$doreturn = 0;
@@ -1171,8 +1177,8 @@
 		$messages->{'WasReturned'} = 1; # FIXME is the "= 1" right?
 	
 		$sth->finish;
-	&MARCkoha2marcOnefield($itemrecord, "date_due", "","holdings");
-	&MARCkoha2marcOnefield($itemrecord, "borrowernumber", "","holdings");
+	$itemrecord=XML_writeline($itemrecord, "date_due", "","holdings");
+	$itemrecord=XML_writeline($itemrecord, "borrowernumber", "","holdings");
 	}
 	my ($transfered, $mess, $item) = transferbook($branch, $barcode, 1);
 	my ($sec,$min,$hour,$mday,$mon,$year) = localtime();
@@ -1180,7 +1186,7 @@
 		$mon += 1;
 		my $timestamp = sprintf("%4d%02d%02d%02d%02d%02d.0",
 		$year,$mon,$mday,$hour,$min,$sec);
-		&MARCkoha2marcOnefield($itemrecord, "datelastseen", $timestamp,"holdings");
+		$itemrecord=XML_writeline($itemrecord, "datelastseen", $timestamp,"holdings");
 		
 		
 	($borrower) = getpatroninformation(\%env, $currentborrower, 0);
@@ -1193,7 +1199,7 @@
 	if ($iteminformation->{'itemlost'}) {
 		fixaccountforlostandreturned($iteminformation, $borrower);
 		$messages->{'WasLost'} = 1; # FIXME is the "= 1" right?
-		&MARCkoha2marcOnefield($itemrecord, "itemlost", "","holdings");
+		$itemrecord=XML_writeline($itemrecord, "itemlost", "","holdings");
 	}
 ####WARNING-- FIXME#########	
 ### The following new script is commented out
@@ -1224,7 +1230,7 @@
 # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # 
 	# fix up the overdues in accounts...
 	fixoverduesonreturn($borrower->{'borrowernumber'}, $iteminformation->{'itemnumber'});
-	&MARCkoha2marcOnefield($itemrecord, "itemoverdue", "","holdings");
+	$itemrecord=XML_writeline($itemrecord, "itemoverdue", "","holdings");
 	# find reserves.....
 	my ($resfound, $resrec) = CheckReserves($iteminformation->{'itemnumber'});
 	if ($resfound) {
@@ -1465,19 +1471,16 @@
 	my $today = (1900+$datearr[5]).sprintf ("%02d", ($datearr[4]+1)).sprintf ("%02d", $datearr[3]);
 	my @overdueitems;
 	my $count = 0;
-	my $sth = $dbh->prepare("SELECT issues.* , i.biblionumber as biblionumber FROM issues, items i
+	my $sth = $dbh->prepare("SELECT issues.* , i.biblionumber as biblionumber,b.* FROM issues, items i,biblio b
 			WHERE  i.itemnumber=issues.itemnumber
+				AND i.biblionumber=b.biblionumber
 				AND issues.borrowernumber  = ?
 				AND issues.returndate is NULL
 				AND issues.date_due < ?");
 	$sth->execute($bornum,$today);
 	while (my $data = $sth->fetchrow_hashref) {
-	my ($record)=MARCgetbiblio($dbh,$data->{biblionumber});
-	my $bibliodata=MARCmarc2koha($dbh,$record,"biblios");
-	foreach my $field (keys % $data){
-	$bibliodata->{$field}=$data->{$field};
-	}
-	push (@overdueitems, $bibliodata);
+	
+	push (@overdueitems, $data);
 	$count++;
 	}
 	$sth->finish;
@@ -1660,25 +1663,20 @@
 	my $todaysdate = (1900+$datearr[5])."-".sprintf ("%0.2d", ($datearr[4]+1))."-".sprintf ("%0.2d", $datearr[3]);
 	my $counter = 0;
 	my $select = "SELECT *
-			FROM issues,items
+			FROM issues,items,biblio
 			WHERE issues.borrowernumber  = ?
 			AND issues.itemnumber      = items.itemnumber
+			AND items.biblionumber      = biblio.biblionumber
 			AND issues.returndate      IS NULL
 			ORDER BY issues.date_due";
 	#    print $select;
 	my $sth=$dbh->prepare($select);
 	$sth->execute($borrowernumber);
 	while (my $data = $sth->fetchrow_hashref) {
-	my ($record)=MARCgetbiblio($dbh,$data->{biblionumber},1);
-	 $bibliodata=MARCmarc2koha($dbh,$record,"biblios");
-		foreach my $field (keys %$data){
-		$bibliodata->{$field}=$data->{$field};
-		}
-	 	$bibliodata->{'date_due'} = $data->{'date_due'};
-		if ($bibliodata->{'date_due'}  lt $todaysdate) {
-			$bibliodata->{'overdue'} = 1;
+		if ($data->{'date_due'}  lt $todaysdate) {
+			$data->{'overdue'} = 1;
 		}
-		$currentissues{$counter} = $bibliodata;
+		$currentissues{$counter} = $data;
 		$counter++;
 	}
 	$sth->finish;
@@ -1741,12 +1739,14 @@
 		## faculty members and privileged get renewal whatever the case may be
 		if ($borrower->{'categorycode'} eq 'F' ||$borrower->{'categorycode'} eq 'P'){
 		$renewokay = 1;
+		return $renewokay;
 		}
 	}
 	# FIXME - I think this function could be redone to use only one SQL call.
-	my $sth1 = $dbh->prepare("select * from issues,items
+	my $sth1 = $dbh->prepare("select * from issues,items,biblio
 								where (borrowernumber = ?)
 								and (issues.itemnumber = ?)
+								and items.biblionumber=biblio.biblionumber
 								and returndate is null
 								and items.itemnumber=issues.itemnumber");
 	$sth1->execute($bornum,$itemnumber);
@@ -1754,11 +1754,8 @@
 		# Found a matching item
 	
 		# See if this item may be renewed. 
-		my ($record)=MARCgetbiblio($dbh,$data1->{biblionumber});
-		
-		my $bibliodata=MARCmarc2koha($dbh,$record,"biblios");
 		my $sth2 = $dbh->prepare("select renewalsallowed from itemtypes	where itemtypes.itemtype=?");
-		$sth2->execute($bibliodata->{itemtype});
+		$sth2->execute($data1->{itemtype});
 		if (my $data2=$sth2->fetchrow_hashref) {
 		$renews = $data2->{'renewalsallowed'};
 		}
@@ -1766,7 +1763,7 @@
 			$renewokay= 1;
 		}else{
 			if (C4::Context->preference("strictrenewals")){
-			$renewokay=3 unless $renewokay==1;
+			$renewokay=3 ;
 			}
 		}
 		$sth2->finish;
@@ -1815,9 +1812,8 @@
 	$sth->execute($startdate);
 	my $difference = $sth->fetchrow;
 	$sth->finish;
-
 	if  ($difference < 0) {
-	$renewokay=2 unless $renewokay==1;
+	$renewokay=2 ;
 	}
 }##strictrenewals
 	return($renewokay);
@@ -1903,7 +1899,7 @@
 
 	## Update items and marc record with new date -T.G
 	my $iteminformation = getiteminformation($env, $itemnumber,0);
-	&MARCmoditemonefield($dbh,$iteminformation->{'biblionumber'},$iteminformation->{'itemnumber'},'date_due',$datedue);
+	&XMLmoditemonefield($dbh,$iteminformation->{'biblionumber'},$iteminformation->{'itemnumber'},'date_due',$datedue);
 		
 	# Log the renewal
 	UpdateStats($env,$env->{'branchcode'},'renew','','',$itemnumber);
@@ -1953,16 +1949,13 @@
 	my $charge=0;
 	my $dbh = C4::Context->dbh;
 	my $item_type;
-	my $sth= $dbh->prepare("select biblionumber from items where itemnumber=?");
+	my $sth= $dbh->prepare("select itemtype from biblio,items where items.biblionumber=biblio.biblionumber and itemnumber=?");
 	$sth->execute($itemnumber);
-	my $data1=$sth->fetchrow;
+	my $itemtype=$sth->fetchrow;
 	$sth->finish;
-	my ($record)=MARCgetbiblio($dbh,$data1);
 		
-		my $bibliodata=MARCmarc2koha($dbh,$record,"biblios");
-	# Get the book's item type and rental charge (via its biblioitem).
 	my $sth1= $dbh->prepare("select rentalcharge from itemtypes where  itemtypes.itemtype=?");
-	$sth1->execute($bibliodata->{itemtype});
+	$sth1->execute($itemtype);
 	
 	$charge = $sth1->fetchrow;
 	my $q2 = "select rentaldiscount from issuingrules,borrowers
@@ -1970,7 +1963,7 @@
               and (borrowers.categorycode = issuingrules.categorycode)
               and (issuingrules.itemtype = ?)";
             my $sth2=$dbh->prepare($q2);
-            $sth2->execute($bornum,$bibliodata->{itemtype});
+            $sth2->execute($bornum,$itemtype);
     if (my $data2=$sth2->fetchrow_hashref) {
 		my $discount = $data2->{'rentaldiscount'};
 		if ($discount eq 'NULL') {
@@ -1982,7 +1975,7 @@
         $sth2->finish;
         
 	$sth1->finish;
-	return ($charge,$bibliodata->{itemtype});
+	return ($charge,$itemtype);
 }
 
 

Index: Fines.pm
===================================================================
RCS file: /sources/koha/koha/C4/Circulation/Fines.pm,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -b -r1.15 -r1.16
--- Fines.pm	25 Aug 2006 21:07:08 -0000	1.15
+++ Fines.pm	1 Sep 2006 22:05:51 -0000	1.16
@@ -1,6 +1,6 @@
-package C4::Circulation::Fines;
+package C4::Circulation::Fines2;
 
-# $Id: Fines.pm,v 1.15 2006/08/25 21:07:08 tgarip1957 Exp $
+# $Id: Fines.pm,v 1.16 2006/09/01 22:05:51 tgarip1957 Exp $
 
 # Copyright 2000-2002 Katipo Communications
 #
@@ -49,7 +49,7 @@
 =cut
 
 @ISA = qw(Exporter);
- at EXPORT = qw(&Getoverdues &CalcFine &BorType &UpdateFine &ReplacementCost &GetFine &ReplacementCost2);
+ at EXPORT = qw(&Getoverdues &CalcFine &BorType &UpdateFine &ReplacementCost);
 
 =item Getoverdues
 
@@ -261,13 +261,11 @@
   } else {
     # I think this else-clause deals with the case where we're adding
     # a new fine.
-    my $sth4=$dbh->prepare("select biblio.marc from biblio ,items where items.itemnumber=?
+    my $sth4=$dbh->prepare("select title from biblio ,items where items.itemnumber=?
     and biblio.biblionumber=items.biblionumber");
     $sth4->execute($itemnum);
-    my $marc=$sth4->fetchrow;
+    my $title=$sth4->fetchrow;
     $sth4->finish;
-my $record=MARC::File::USMARC::decode($marc,\&func_title);
-my $title=$record->title();
  #   print "not in account";
     my $sth3=$dbh->prepare("Select max(accountno) from accountlines");
     $sth3->execute;
@@ -285,11 +283,7 @@
   $sth->finish;
 }
 
-  sub func_title {
-        my ($tagno,$tagdata) = @_;
-  my ($titlef,$subf)=&MARCfind_marc_from_kohafield("title","biblios");
-        return ($tagno == $titlef );
-    }
+
 
 =item BorType
 
@@ -327,36 +321,12 @@
 sub ReplacementCost{
   my ($itemnumber)=@_;
   my $dbh = C4::Context->dbh;
-  my ($itemrecord)=MARCgetitem($dbh,$itemnumber);
- my $data=MARCmarc2koha($dbh,$itemrecord,"holdings"); 
-  return($data->{'replacementprice'});
-}
-sub GetFine {
-    my ( $itemnum, $bornum ) = @_;
-    my $dbh   = C4::Context->dbh();
-    my $query = "SELECT sum(amountoutstanding) FROM accountlines 
-    where accounttype like 'F%'  
-  AND amountoutstanding > 0 AND itemnumber = ? AND borrowernumber=?";
-    my $sth = $dbh->prepare($query);
-    $sth->execute( $itemnum, $bornum );
-    my $data = $sth->fetchrow_hashref();
-    $sth->finish();
-    $dbh->disconnect();
-    return ( $data->{'sum(amountoutstanding)'} );
+  my ($itemrecord)=XMLgetitem($dbh,$itemnumber);
+$itemrecord=XML_xml2hash_onerecord($itemrecord);
+ my $replacementprice=XML_readline_onerecord($itemrecord,"replacementprice","holdings"); 
+  return($replacementprice);
 }
 
-sub ReplacementCost2 {
-    my ( $itemnum, $bornum ) = @_;
-    my $dbh   = C4::Context->dbh();
-    my $query = "SELECT amountoutstanding FROM accountlines
-    where accounttype like 'L'  AND amountoutstanding > 0 AND
-  itemnumber = ? AND borrowernumber= ?";
-    my $sth = $dbh->prepare($query);
-    $sth->execute( $itemnum, $bornum );
-    my $data = $sth->fetchrow_hashref();
-    $sth->finish();
-    $dbh->disconnect();
-    return ( $data->{'amountoutstanding'} );
 1;
 __END__
 





More information about the Koha-cvs mailing list