X-Git-Url: http://koha-dev.rot13.org:8081/gitweb/?a=blobdiff_plain;ds=sidebyside;f=circ%2Fcirculation.pl;h=5d1474b4d4b61c25cc8a5e97f51d458184ffec59;hb=0b66bd800d9c5137240e48c2821a6871427d169d;hp=6ba69144bb5e4b9e98f2e0ffd6c5c7faf0cb1f4e;hpb=d06de68d9ee05fadbab8586f7ee17ac28839a0c9;p=koha-ffzg.git
diff --git a/circ/circulation.pl b/circ/circulation.pl
index 6ba69144bb..5d1474b4d4 100755
--- a/circ/circulation.pl
+++ b/circ/circulation.pl
@@ -1,447 +1,733 @@
#!/usr/bin/perl
-#written 8/5/2002 by Finlay
-#script to execute issuing of books
+# Please use 8-character tabs for this file (indents are every 4 characters)
+
+# written 8/5/2002 by Finlay
+# script to execute issuing of books
+
+# Copyright 2000-2002 Katipo Communications
+#
+# This file is part of Koha.
+#
+# Koha is free software; you can redistribute it and/or modify it under the
+# terms of the GNU General Public License as published by the Free Software
+# Foundation; either version 2 of the License, or (at your option) any later
+# version.
+#
+# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+# A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along with
+# Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
+# Suite 330, Boston, MA 02111-1307 USA
use strict;
use CGI;
-use C4::Circulation::Circ2;
-use C4::Search;
use C4::Output;
-
-
-my %env;
-my $headerbackgroundcolor='#99cc33';
-my $circbackgroundcolor='#ffffcc';
-my $circbackgroundcolor='white';
-my $linecolor1='#ffffcc';
-my $linecolor2='white';
-my $backgroundimage="/images/background-mem.gif";
-
-my $branches = getbranches();
-my $printers = getprinters(\%env);
-
+use C4::Print;
+use C4::Auth;
+use C4::Date;
+use C4::Interface::CGI::Output;
+use C4::Branch; # GetBranches
+use C4::Koha; # GetPrinter
+use Date::Calc qw(
+ Today
+ Today_and_Now
+ Add_Delta_YM
+ Add_Delta_Days
+ Date_to_Days
+);
+
+use C4::Circulation;
+use C4::Members;
+use C4::Biblio;
+use C4::Reserves2;
+
+#
+# PARAMETERS READING
+#
my $query = new CGI;
-my $branch = $query->param("branch");
-my $printer = $query->param("printer");
+my ( $template, $loggedinuser, $cookie ) = get_template_and_user (
+ {
+ template_name => 'circ/circulation.tmpl',
+ query => $query,
+ type => "intranet",
+ authnotrequired => 0,
+ flagsrequired => { circulate => 1 },
+ }
+);
+my $branches = GetBranches();
+
+my $printers = GetPrinters();
+my $printer = GetPrinter($query, $printers);
-($branch) || ($branch=$query->cookie('branch')) ;
-($printer) || ($printer=$query->cookie('printer')) ;
+my $findborrower = $query->param('findborrower');
+$findborrower =~ s|,| |g;
+#$findborrower =~ s|'| |g;
+my $borrowernumber = $query->param('borrowernumber');
+
+# new op dev the branch and the printer are now defined by the userenv
+my $branch = C4::Context->userenv->{'branch'};
+my $printer = C4::Context->userenv->{'branchprinter'};
+
+# If Autolocated is not activated, we show the Circulation Parameters to chage settings of librarian
+ if (C4::Context->preference("AutoLocation") ne 1)
+ {
+ $template->param(
+ ManualLocation => 1,
+ );
+ }
+
+my $barcode = $query->param('barcode') || '';
+my $year = $query->param('year');
+my $month = $query->param('month');
+my $day = $query->param('day');
+my $stickyduedate = $query->param('stickyduedate');
+my $issueconfirmed = $query->param('issueconfirmed');
+my $cancelreserve = $query->param('cancelreserve');
+my $organisation = $query->param('organisations');
+my $print = $query->param('print');
#set up cookie.....
-my $info = '';
-my $branchcookie;
-my $printercookie;
-if ($query->param('setcookies')) {
- $branchcookie = $query->cookie(-name=>'branch', -value=>"$branch", -expires=>'+1y');
- $printercookie = $query->cookie(-name=>'printer', -value=>"$printer", -expires=>'+1y');
+# my $branchcookie;
+# my $printercookie;
+# if ($query->param('setcookies')) {
+# $branchcookie = $query->cookie(-name=>'branch', -value=>"$branch", -expires=>'+1y');
+# $printercookie = $query->cookie(-name=>'printer', -value=>"$printer", -expires=>'+1y');
+# }
+#
+
+
+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] ) );
+
+# check and see if we should print
+if ( $barcode eq '' && $print eq 'maybe' ) {
+ $print = 'yes';
}
-$env{'branchcode'}=$branch;
-$env{'printer'}=$printer;
-$env{'queue'}=$printer;
-
-my @datearr = localtime(time());
-my $todaysdate = (1900+$datearr[5]).sprintf ("%0.2d", ($datearr[4]+1)).sprintf ("%0.2d", $datearr[3]);
+my $inprocess = $query->param('inprocess');
+if ( $barcode eq '' ) {
+ $inprocess = '';
+}
+else {
+}
+if ( $barcode eq '' && $query->param('charges') eq 'yes' ) {
+ $template->param(
+ PAYCHARGES => 'yes',
+ borrowernumber => $borrowernumber
+ );
+}
+if ( $print eq 'yes' && $borrowernumber ne '' ) {
+ printslip( $borrowernumber );
+ $query->param( 'borrowernumber', '' );
+ $borrowernumber = '';
+}
-my $message;
-my $borrowerslist;
+#
+# STEP 2 : FIND BORROWER
# if there is a list of find borrowers....
-my $findborrower = $query->param('findborrower');
+#
+my $borrowerslist;
+my $message;
if ($findborrower) {
- my ($borrowers, $flags) = findborrower(\%env, $findborrower);
- my @borrowers=@$borrowers;
- if ($#borrowers == -1) {
- $query->param('findborrower', '');
- $message = "No borrower matched '$findborrower'";
- } elsif ($#borrowers == 0) {
- $query->param('borrnumber', $borrowers[0]->{'borrowernumber'});
- $query->param('barcode','');
- } else {
- $borrowerslist = \@borrowers;
+ my ( $count, $borrowers ) =
+ SearchBorrower($findborrower, 'cardnumber', 'web' );
+ my @borrowers = @$borrowers;
+ if ( $#borrowers == -1 ) {
+ $query->param( 'findborrower', '' );
+ $message = "'$findborrower'";
+ }
+ elsif ( $#borrowers == 0 ) {
+ $query->param( 'borrowernumber', $borrowers[0]->{'borrowernumber'} );
+ $query->param( 'barcode', '' );
+ $borrowernumber = $borrowers[0]->{'borrowernumber'};
+ }
+ else {
+ $borrowerslist = \@borrowers;
}
}
-my $borrowernumber = $query->param('borrnumber');
-
-# get the currently issued books......
+# get the borrower information.....
my $borrower;
-my $flags;
-if ($borrowernumber) {
- ($borrower, $flags) = getpatroninformation(\%env,$borrowernumber,0);
-}
+my @lines;
-# get the responses to any questions.....
-my %responses;
-foreach (sort $query->param) {
- if ($_ =~ /response-(\d*)/) {
- $responses{$1} = $query->param($_);
+if ($borrowernumber) {
+ $borrower = GetMemberDetails( $borrowernumber, 0 );
+ my ( $od, $issue, $fines ) = GetBorrowerIssuesAndFines( $borrowernumber );
+
+ # 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"
+ );
}
-}
-if (my $qnumber = $query->param('questionnumber')) {
- $responses{$qnumber} = $query->param('answer');
+ # check for NotifyBorrowerDeparture
+ if (C4::Context->preference('NotifyBorrowerDeparture') &&
+ Date_to_Days(Add_Delta_Days($warning_year,$warning_month,$warning_day,- C4::Context->preference('NotifyBorrowerDeparture'))) <
+ Date_to_Days( $today_year, $today_month, $today_day ) )
+ {
+ $template->param("warndeparture" => 1);
+ }
+ $template->param(
+ overduecount => $od,
+ issuecount => $issue,
+ finetotal => $fines
+ );
}
-
-# if the barcode is set
-my $barcode = $query->param('barcode');
-my ($iteminformation, $duedate, $rejected, $question, $questionnumber, $defaultanswer);
-
-my $year=$query->param('year');
-my $month=$query->param('month');
-my $day=$query->param('day');
-
+#
+# STEP 3 : ISSUING
+#
+#
if ($barcode) {
$barcode = cuecatbarcodedecode($barcode);
- my ($datedue, $invalidduedate) = fixdate($year, $month, $day);
-
- unless ($invalidduedate) {
- my @time=localtime(time);
- my $date= (1900+$time[5])."-".($time[4]+1)."-".$time[3];
- ($iteminformation, $duedate, $rejected, $question, $questionnumber, $defaultanswer, $message)
- = issuebook(\%env, $borrower, $barcode, \%responses, $date);
+ my ( $datedue, $invalidduedate ) = fixdate( $year, $month, $day );
+ if ($issueconfirmed) {
+ AddIssue( $borrower, $barcode, $datedue, $cancelreserve );
+ $inprocess = 1;
+ }
+ else {
+ my ( $error, $question ) =
+ CanBookBeIssued( $borrower, $barcode, $year, $month, $day,
+ $inprocess );
+ my $noerror = 1;
+ my $noquestion = 1;
+# Get the item title for more information
+ my $getmessageiteminfo = GetBiblioFromItemNumber( undef, $barcode );
+
+ foreach my $impossible ( keys %$error ) {
+ $template->param(
+ $impossible => $$error{$impossible},
+ IMPOSSIBLE => 1
+ );
+ $noerror = 0;
+ }
+ foreach my $needsconfirmation ( keys %$question ) {
+ $template->param(
+ $needsconfirmation => $$question{$needsconfirmation},
+ getTitleMessageIteminfo => $getmessageiteminfo->{'title'},
+ NEEDSCONFIRMATION => 1
+ );
+ $noquestion = 0;
+ }
+ $template->param(
+ day => $day,
+ month => $month,
+ year => $year
+ );
+ if ( $noerror && ( $noquestion || $issueconfirmed ) ) {
+ AddIssue( $borrower, $barcode, $datedue );
+ $inprocess = 1;
+ }
}
+
+# FIXME If the issue is confirmed, we launch another time borrdata2, now display the issue count after issue
+ my ( $od, $issue, $fines ) = GetBorrowerIssuesAndFines( $borrowernumber );
+ $template->param(
+ issuecount => $issue,
+ );
}
+# reload the borrower info for the sake of reseting the flags.....
+if ($borrowernumber) {
+ $borrower = GetMemberDetails( $borrowernumber, 0 );
+}
##################################################################################
-# HTML code....
-
-
-my $rejectedtext;
-if ($rejected) {
- if ($rejected == -1) {
- } else {
- $rejectedtext = << "EOF";
-
-Error Issuing Book |
-$rejected |
-
-
-EOF
- }
-}
+# BUILD HTML
+# show all reserves of this borrower, and the position of the reservation ....
+if ($borrowernumber) {
-my $selectborrower;
-if ($borrowerslist) {
- $selectborrower = <<"EOF";
-
-EOF
-
-my $responsesform = '';
-foreach (keys %responses) {
- $responsesform.="\n";
-}
-my $questionform;
-if ($question) {
- my $stickyduedate=$query->param('stickyduedate');
- $questionform = <<"EOF";
-
-
-Issuing Question |
-
-Attempting to issue $iteminformation->{'title'}
-by $iteminformation->{'author'} to $borrower->{'firstname'} $borrower->{'surname'}.
-
-$question
- |
|
-
-
- |
-
-
-
-EOF
+ # return result to the template
+ $template->param(
+ countreserv => scalar @reservloop,
+ reservloop => \@reservloop ,
+ WaitingReserveLoop => \@WaitingReserveLoop,
+ );
}
+# make the issued books table.
+my $todaysissues = '';
+my $previssues = '';
+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
-# Barcode entry box, with hidden inputs attached....
-my $counter = 1;
-my $dayoptions = '';
-my $monthoptions = '';
-my $yearoptions = '';
-for (my $i=1; $i<32; $i++) {
- my $selected='';
- if (($query->param('stickyduedate')) && ($day==$i)) {
- $selected='selected';
- }
- $dayoptions.="