X-Git-Url: http://git.rot13.org/?a=blobdiff_plain;f=circ%2Fcirculation.pl;h=b4a0cebb86f80a2bab1c4656e301ca26fe321ddf;hb=100e6a9808ead4ee8d951da59ead1550e75bb4c3;hp=e284307ba9f0cd260ef2c5559062f49b60a9c88a;hpb=a72d9621ae5ffe8fdca6179aa64ee403c43fce4b;p=koha.git diff --git a/circ/circulation.pl b/circ/circulation.pl index e284307ba9..b4a0cebb86 100755 --- a/circ/circulation.pl +++ b/circ/circulation.pl @@ -1,9 +1,9 @@ #!/usr/bin/perl -# 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 +# 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 # @@ -24,447 +24,707 @@ use strict; use CGI; -use C4::Circulation::Circ2; -use C4::Search; use C4::Output; use C4::Print; -use DBI; use C4::Auth; -use C4::Interface::CGI::Output; -use C4::Koha; -use HTML::Template; use C4::Date; +use C4::Branch; # GetBranches +use C4::Koha; # GetPrinter +use C4::Circulation; +use C4::Members; +use C4::Biblio; +use C4::Reserves; + +use Date::Calc qw( + Today + Today_and_Now + Add_Delta_YM + Add_Delta_Days + Date_to_Days +); -my $query=new CGI; -#my ($loggedinuser, $sessioncookie, $sessionID) = checkauth -# ($query, 0, { circulate => 1 }); -my ($template, $loggedinuser, $cookie) = get_template_and_user - ({ - template_name => 'circ/circulation.tmpl', - query => $query, - type => "intranet", - authnotrequired => 0, - flagsrequired => { circulate => 1 }, - }); +# +# PARAMETERS READING +# +my $query = new CGI; + +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); -my %env; -my $linecolor1='#ffffcc'; -my $linecolor2='white'; +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'); -my $branches = getbranches(); -my $printers = getprinters(\%env); +#set up cookie..... +# 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 $branch = getbranch($query, $branches); -my $printer = getprinter($query, $printers); +my @datearr = localtime( time() ); -#set up cookie..... -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'); +# 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 $inprocess = $query->param('inprocess'); +if ( $barcode eq '' ) { + $inprocess = ''; +} +else { +} -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])); -#warn $todaysdate; +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 ($count,$borrowers)=BornameSearch(\%env,$findborrower,'web'); - 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 $borrowernumber = $query->param('borrnumber'); -my $bornum = $query->param('borrnumber'); -# check and see if we should print -my $print=$query->param('print'); -my $barcode = $query->param('barcode'); -if ($barcode eq '' && $print eq 'maybe'){ - $print = 'yes'; -} -if ($print eq 'yes' && $borrowernumber ne ''){ - printslip(\%env,$borrowernumber); - $query->param('borrnumber',''); - $borrowernumber=''; + 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; + } } # 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 (my $qnumber = $query->param('questionnumber')) { - $responses{$qnumber} = $query->param('answer'); +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" + ); + } + # 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 + ); } -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 the barcode is set if ($barcode) { - $barcode = cuecatbarcodedecode($barcode); - my ($datedue, $invalidduedate) = fixdate($year, $month, $day); - - unless ($invalidduedate) { - $env{'datedue'}=$datedue; - 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); - } + $barcode = cuecatbarcodedecode($barcode); + 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, $flags) = getpatroninformation(\%env,$borrowernumber,0); + $borrower = GetMemberDetails( $borrowernumber, 0 ); } ################################################################################## -# HTML code.... - -my $responsesform = ''; -foreach (keys %responses) { - $responsesform.="\n"; -} -my $questionform; -my $stickyduedate; -if ($question) { - $stickyduedate=$query->param('stickyduedate'); -} - +# BUILD HTML +# show all reserves of this borrower, and the position of the reservation .... +if ($borrowernumber) { -# 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.="