[Koha-cvs] koha/circ circulation.pl [rel_3_0]

Antoine Farnault antoine at koha-fr.org
Thu Nov 2 14:30:28 CET 2006


CVSROOT:	/sources/koha
Module name:	koha
Branch:		rel_3_0
Changes by:	Antoine Farnault <toins>	06/11/02 13:30:28

Modified files:
	circ           : circulation.pl 

Log message:
	use Date::Calc instead of Date::Manip & sync with dev_week.

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/koha/circ/circulation.pl?cvsroot=koha&only_with_tag=rel_3_0&r1=1.97.2.3&r2=1.97.2.4

Patches:
Index: circulation.pl
===================================================================
RCS file: /sources/koha/koha/circ/circulation.pl,v
retrieving revision 1.97.2.3
retrieving revision 1.97.2.4
diff -u -b -r1.97.2.3 -r1.97.2.4
--- circulation.pl	20 Sep 2006 15:47:49 -0000	1.97.2.3
+++ circulation.pl	2 Nov 2006 13:30:28 -0000	1.97.2.4
@@ -25,7 +25,6 @@
 use strict;
 use CGI;
 use C4::Circulation::Circ2;
-use C4::Search;
 use C4::Members;
 use C4::Output;
 use C4::Print;
@@ -33,12 +32,19 @@
 use C4::Interface::CGI::Output;
 use C4::Koha;
 use HTML::Template;
-use C4::Date;
-use Date::Manip;
+use Date::Calc qw(
+Today
+Today_and_Now
+Add_Delta_YM
+Date_to_Days
+);
+#use C4::Date;
 use C4::Biblio;
 use C4::Reserves2;
 use C4::Circulation::Date;
 
+use Data::Dumper; # FIXME :: don't forget to remove.
+
 #
 # PARAMETERS READING
 #
@@ -93,10 +99,8 @@
 
 my @datearr = localtime(time());
 # FIXME - Could just use POSIX::strftime("%Y%m%d", localtime);
-my $todaysdate =
-    ( 1900 + $datearr[5] )
-  . sprintf( "%0.2d", ( $datearr[4] + 1 ) )
-  . sprintf( "%0.2d", ( $datearr[3] ) );
+my $todaysdate = (1900+$datearr[5]).sprintf ("%0.2d", ($datearr[4]+1)).sprintf ("%0.2d", ($datearr[3]));
+
 
 # check and see if we should print
 if ( $barcode eq '' && $print eq 'maybe' ) {
@@ -152,37 +156,25 @@
 if ($borrowernumber) {
     $borrower = getpatroninformation( \%env, $borrowernumber, 0 );
     my ( $od, $issue, $fines ) = borrdata2( \%env, $borrowernumber );
-    my $warningdate =
-      DateCalc( $borrower->{'expiry'},
-        "- " . C4::Context->preference('NotifyBorrowerDeparture') . "  days" );
-    my $warning = Date_Cmp( ParseDate("today"), $warningdate );
-    if ( $warning > 0 ) {
-
-        #borrowercard expired
-        $template->param( warndeparture => $warning );
+	# Warningdate is the date that the warning starts appearing
+	my ($today_year,$today_month,$today_day) = Today();
+	my ($warning_year,$warning_month,$warning_day) = split /-/, $borrower->{'dateexpiry'};
+
+	# Renew day is calculated by adding the enrolment period to today
+	my ($renew_year,$renew_month,$renew_day) = Add_Delta_YM($today_year,$today_month,$today_day, $borrower->{'enrolmentperiod'},0); 
+	
+	# if the expiry date is before today
+	if (Date_to_Days($today_year,$today_month,$today_day) > Date_to_Days($warning_year,$warning_month,$warning_day)) {
+
+		#borrowercard expired or nearly expired, warn the librarian
+		$template->param(	flagged=>"1",
+							warndeparture=>"1",
+							renewaldate=>"$renew_year-$renew_month-$renew_day");
     }
-    my $reserved_waiting = GetWaitingReserves($borrowernumber);
-	my $reserved_num = scalar @$reserved_waiting;
-    if ($reserved_num > 0) {
-           for (my $i = 0; $i < $reserved_num; $i++) {
-                     my ($count,$line) = getbiblio($reserved_waiting->[$i]->{'biblionumber'});
-                     push(@lines, $line);
-           }
-          # warn Dumper(@lines);
-    }
-    
-    $template->param(
-        overduecount => $od,
+	$template->param(		overduecount => $od,
         issuecount   => $issue,
-        finetotal    => $fines,
-	returned_reserve => \@lines,
-    );
-    my $htdocs = C4::Context->config('intrahtdocs');
-    $picture = "/borrowerimages/" . $borrowernumber . ".jpg";
-    if ( -e $htdocs . "$picture" ) {
-        $template->param( picture => $picture );
+							finetotal => $fines);
     }
-}
 
 #
 # STEP 3 : ISSUING
@@ -305,19 +297,29 @@
 my @realtodayissues;
 my @realprevissues;
 my $allowborrow;
+## ADDED BY JF: new itemtype issuingrules counter stuff
+my $issued_itemtypes_loop;
+my $issued_itemtypes_count;
+my $issued_itemtypes_allowed_count; # hashref with total allowed by itemtype
+my $issued_itemtypes_remaining; # hashref with remaining
+my $issued_itemtypes_flags; #hashref that stores flags
+
 if ($borrower) {
 
 # get each issue of the borrower & separate them in todayissues & previous issues
     my @todaysissues;
     my @previousissues;
     my $issueslist = getissues($borrower);
-
+    warn "issueslist=>".Dumper($issueslist);
     # split in 2 arrays for today & previous
     my $dbh = C4::Context->dbh;
     foreach my $it ( keys %$issueslist ) {
         my $issuedate = $issueslist->{$it}->{'timestamp'};
         $issuedate =~ s/-//g;
         $issuedate = substr( $issuedate, 0, 8 );
+		# to let perl sort this correctly
+		$issueslist->{$it}->{'timestamp'} =~ s/(-|\:| )//g;
+#		warn "today: $todaysdate issue: $issuedate";
         if ( $todaysdate == $issuedate ) {
 	        ($issueslist->{$it}->{'charge'}, $issueslist->{$it}->{'itemtype_charge'})=calc_charges($dbh,$issueslist->{$it}->{'itemnumber'},$borrower->{'borrowernumber'});
 	        $issueslist->{$it}->{'charge'} = sprintf("%.2f",$issueslist->{$it}->{'charge'});
@@ -342,14 +344,15 @@
     my $od;    # overdues
     my $i = 0;
     my $togglecolor;
-
     # parses today & build Template array
-    foreach my $book ( sort { $b->{'timestamp'} <=> $a->{'timestamp'} }
-        @todaysissues )
-    {
+	foreach my $book (sort {$b->{'timestamp'} <=> $a->{'timestamp'}} @todaysissues){
+		#warn "TIMESTAMP".$book->{'timestamp'};
+		# ADDED BY JF: NEW ITEMTYPE COUNT DISPLAY
+		$issued_itemtypes_count->{$book->{'itemtype'}}++;
+	
         my $dd      = $book->{'date_due'};
         my $datedue = $book->{'date_due'};
-        $dd = format_date($dd);
+		#$dd=format_date($dd);
         $datedue =~ s/-//g;
         if ( $datedue < $todaysdate ) {
             $od = 1;
@@ -375,12 +378,14 @@
 
     # parses previous & build Template array
     $i = 0;
-    foreach my $book ( sort { $a->{'date_due'} cmp $b->{'date_due'} }
-        @previousissues )
-    {
+    foreach my $book (sort {$a->{'date_due'} cmp $b->{'date_due'}} @previousissues){
+
+		# ADDED BY JF: NEW ITEMTYPE COUNT DISPLAY
+		$issued_itemtypes_count->{$book->{'itemtype'}}++;
+
         my $dd      = $book->{'date_due'};
         my $datedue = $book->{'date_due'};
-        $dd = format_date($dd);
+		#$dd=format_date($dd);
         my $pcolor = '';
         my $od     = '';
         $datedue =~ s/-//g;
@@ -407,29 +412,47 @@
     }
 }
 
+#### ADDED BY JF FOR COUNTS BY ITEMTYPE RULES
+# FIXME: This should utilize all the issuingrules options rather than just the defaults
+# and it should be moved to a module
+my $dbh = C4::Context->dbh;
+# how many of each is allowed?
+my $issueqty_sth = $dbh->prepare("
+SELECT itemtypes.description AS description,issuingrules.itemtype,maxissueqty                                                           FROM issuingrules
+  LEFT JOIN itemtypes ON (itemtypes.itemtype=issuingrules.itemtype)
+  WHERE categorycode=?
+");
+my @issued_itemtypes_count;
+$issueqty_sth->execute("*");
+while (my $data = $issueqty_sth->fetchrow_hashref()) {
+    # subtract how many of each this borrower has
+	$data->{'count'} = $issued_itemtypes_count->{$data->{'description'}};
+    $data->{'left'} = ($data->{'maxissueqty'} - $issued_itemtypes_count->{$data->{'description'}});
+	# can't have a negative number of remaining 
+	if ($data->{'left'} < 0) { $data->{'left'} = "0" };
+	$data->{'flag'} = 1 unless ($data->{'maxissueqty'} > $data->{'count'});
+	unless (($data->{'maxissueqty'} < 1) || ($data->{'itemtype'} eq "*") || ($data->{'itemtype'} eq "CIRC")) {
+    	push @issued_itemtypes_count, $data;
+	}
+}
+my $issued_itemtypes_loop = \@issued_itemtypes_count;
+
+#### / JF
+
 my @values;
 my %labels;
 my $CGIselectborrower;
 if ($borrowerslist) {
-    foreach (
-        sort {
-            $a->{'surname'}
-              . $a->{'firstname'} cmp $b->{'surname'}
-              . $b->{'firstname'}
-        } @$borrowerslist
-      )
-    {
+	foreach (sort {$a->{'surname'}.$a->{'firstname'} cmp $b->{'surname'}.$b->{'firstname'}} @$borrowerslist){
         push @values, $_->{'borrowernumber'};
-        $labels{ $_->{'borrowernumber'} } =
-"$_->{'surname'}, $_->{'firstname'} ... ($_->{'cardnumber'} - $_->{'categorycode'}) ...  $_->{'streetaddress'} ";
+		$labels{$_->{'borrowernumber'}} ="$_->{'surname'}, $_->{'firstname'} ... ($_->{'cardnumber'} - $_->{'categorycode'}) ...  $_->{'address'} ";
     }
-    $CGIselectborrower = CGI::scrolling_list(
-        -name     => 'borrnumber',
+	$CGIselectborrower=CGI::scrolling_list( -name     => 'borrnumber',
         -values   => \@values,
         -labels   => \%labels,
         -size     => 7,
-        -multiple => 0
-    );
+	 			-tabindex=>'',
+				-multiple => 0 );
 }
 
 #title
@@ -460,7 +483,9 @@
 }
 
 $amountold = $temp[1];
+warn "borrowernumber=>".$borrowernumber;
 $template->param(
+		issued_itemtypes_count_loop => $issued_itemtypes_loop,
     findborrower      => $findborrower,
     borrower          => $borrower,
     borrowernumber    => $borrowernumber,
@@ -469,8 +494,9 @@
     printername       => $printer,
     firstname         => $borrower->{'firstname'},
     surname           => $borrower->{'surname'},
+    expiry               => $borrower->{'dateexpiry'}, #format_date($borrower->{'dateexpiry'}),
     categorycode      => $borrower->{'categorycode'},
-    streetaddress     => $borrower->{'streetaddress'},
+    streetaddress    => $borrower->{'address'},
     emailaddress      => $borrower->{'emailaddress'},
     borrowernotes     => $borrower->{'borrowernotes'},
     city              => $borrower->{'city'},
@@ -501,10 +527,16 @@
 }
 
 
-# if ($branchcookie) {
-#     $cookie=[$cookie, $branchcookie, $printercookie];
-# }
-
+#if ($branchcookie) {
+#$cookie=[$cookie, $branchcookie, $printercookie];
+#}
+
+$template->param(intranetcolorstylesheet => C4::Context->preference("intranetcolorstylesheet"),
+		intranetstylesheet => C4::Context->preference("intranetstylesheet"),
+		IntranetNav => C4::Context->preference("IntranetNav"),
+		patronimages => C4::Context->preference("patronimages"),
+		SpecifyDueDate => C4::Context->preference("SpecifyDueDate")
+		);
 output_html_with_http_headers $query, $cookie, $template->output;
 
 ####################################################################





More information about the Koha-cvs mailing list