From cb1ec158c0632ca6177057ba867a59cdd0566ea4 Mon Sep 17 00:00:00 2001 From: Ryan Higgins Date: Mon, 19 Nov 2007 17:31:57 -0600 Subject: [PATCH] Adding calendar widget to circulation/stickyduedate Signed-off-by: Chris Cormack Signed-off-by: Joshua Ferraro --- C4/Circulation.pm | 68 ++-- C4/SIP/ILS/Transaction/Checkout.pm | 2 +- circ/circulation.pl | 34 +- .../prog/en/modules/circ/circulation.tmpl | 369 +++--------------- 4 files changed, 102 insertions(+), 371 deletions(-) diff --git a/C4/Circulation.pm b/C4/Circulation.pm index 362b29aded..018f649da5 100644 --- a/C4/Circulation.pm +++ b/C4/Circulation.pm @@ -633,14 +633,14 @@ sub itemissues { =head2 CanBookBeIssued $issuingimpossible, $needsconfirmation = - CanBookBeIssued( $borrower, $barcode, $year, $month, $day, $inprocess ); - + CanBookBeIssued( $borrower, $barcode, $duedatespec, $inprocess ); +C<$duedatespec> is a C4::Dates object. C<$issuingimpossible> and C<$needsconfirmation> are some hashref. =cut sub CanBookBeIssued { - my ( $borrower, $barcode, $year, $month, $day, $inprocess ) = @_; + my ( $borrower, $barcode, $duedate, $inprocess ) = @_; my %needsconfirmation; # filled with problems that needs confirmations my %issuingimpossible; # filled with problems that causes the issue to be IMPOSSIBLE my $item = GetItem(GetItemnumberFromBarcode( $barcode )); @@ -648,10 +648,9 @@ sub CanBookBeIssued { my $dbh = C4::Context->dbh; # - # DUE DATE is OK ? + # DUE DATE is OK ? -- should already have checked. # - my ( $duedate, $invalidduedate ) = fixdate( $year, $month, $day ); - $issuingimpossible{INVALID_DATE} = 1 if ($invalidduedate); + #$issuingimpossible{INVALID_DATE} = 1 unless ($duedate); # # BORROWER STATUS @@ -680,7 +679,7 @@ sub CanBookBeIssued { # DEBTS my ($amount) = - C4::Members::GetMemberAccountRecords( $borrower->{'borrowernumber'}, $duedate ); + C4::Members::GetMemberAccountRecords( $borrower->{'borrowernumber'}, '' && $duedate->output('iso') ); if ( C4::Context->preference("IssuingInProcess") ) { my $amountlimit = C4::Context->preference("noissuescharge"); if ( $amount > $amountlimit && !$inprocess ) { @@ -943,30 +942,30 @@ if ($borrower and $barcode and $barcodecheck ne '0'){ (borrowernumber, itemnumber,issuedate, date_due, branchcode) VALUES (?,?,?,?,?)" ); - my $itype=(C4::Context->preference('item-level_itypes')) ? $biblio->{'itype'} : $biblio->{'itemtype'} ; - my $loanlength = GetLoanLength( - $borrower->{'categorycode'}, - $itype, - $borrower->{'branchcode'} - ); - $datedue = time + ($loanlength) * 86400; - my @datearr = localtime($datedue); - my $dateduef = - sprintf("%04d-%02d-%02d", 1900 + $datearr[5], $datearr[4] + 1, $datearr[3]); + my $dateduef; if ($date) { $dateduef = $date; - } - $dateduef=CheckValidDatedue($dateduef,$item->{'itemnumber'},C4::Context->userenv->{'branch'}); - # if ReturnBeforeExpiry ON the datedue can't be after borrower expirydate - if ( C4::Context->preference('ReturnBeforeExpiry') - && $dateduef gt $borrower->{dateexpiry} ) - { - $dateduef = $borrower->{dateexpiry}; - } - $sth->execute( + } else { + my $itype=(C4::Context->preference('item-level_itypes')) ? $biblio->{'itype'} : $biblio->{'itemtype'} ; + my $loanlength = GetLoanLength( + $borrower->{'categorycode'}, + $itype, + $borrower->{'branchcode'} + ); + $datedue = time + ($loanlength) * 86400; + my @datearr = localtime($datedue); + $dateduef = C4::Dates->new( sprintf("%04d-%02d-%02d", 1900 + $datearr[5], $datearr[4] + 1, $datearr[3]), 'iso'); + $dateduef=CheckValidDatedue($dateduef,$item->{'itemnumber'},C4::Context->userenv->{'branch'}); + + # if ReturnBeforeExpiry ON the datedue can't be after borrower expirydate + if ( C4::Context->preference('ReturnBeforeExpiry') && $dateduef gt $borrower->{dateexpiry} ) { + $dateduef = $borrower->{dateexpiry}; + } + }; + $sth->execute( $borrower->{'borrowernumber'}, $item->{'itemnumber'}, - strftime( "%Y-%m-%d", localtime ),$dateduef, C4::Context->userenv->{'branch'} + strftime( "%Y-%m-%d", localtime ),$dateduef->output('iso'), C4::Context->userenv->{'branch'} ); $sth->finish; $item->{'issues'}++; @@ -1602,7 +1601,7 @@ sub AddRenewal { # If the due date wasn't specified, calculate it by adding the # book's loan length to today's date. - if ( $datedue eq "" ) { + unless ( $datedue ) { my $biblio = GetBiblioFromItemNumber($itemnumber); my $borrower = C4::Members::GetMemberDetails( $borrowernumber, 0 ); @@ -1615,7 +1614,7 @@ sub AddRenewal { #FIXME -- where's the calendar ? my ( $due_year, $due_month, $due_day ) = Add_Delta_DHMS( Today_and_Now(), $loanlength, 0, 0, 0 ); - $datedue = "$due_year-$due_month-$due_day"; + $datedue = C4::Dates->new( "$due_year-$due_month-$due_day",'iso'); $datedue=CheckValidDatedue($datedue,$itemnumber,$branch); } @@ -1638,12 +1637,11 @@ sub AddRenewal { AND itemnumber=? AND returndate IS NULL" ); - $sth->execute( $datedue, $renews, $borrowernumber, $itemnumber ); + $sth->execute( $datedue->output('iso'), $renews, $borrowernumber, $itemnumber ); $sth->finish; # Log the renewal - # Charge a new rental fee, if applicable? my ( $charge, $type ) = GetIssuingCharges( $itemnumber, $borrowernumber ); if ( $charge > 0 ) { @@ -1899,9 +1897,11 @@ C<$date_due> = returndate calculate with no day check C<$itemnumber> = itemnumber C<$branchcode> = localisation of issue =cut -sub CheckValidDatedue{ +# Why not create calendar object? - +# TODO add 'duedate' option to useDaysMode . +sub CheckValidDatedue { my ($date_due,$itemnumber,$branchcode)=@_; -my @datedue=split('-',$date_due); +my @datedue=split('-',$date_due->output('iso')); my $years=$datedue[0]; my $month=$datedue[1]; my $day=$datedue[2]; @@ -1917,7 +1917,7 @@ for (my $i=0;$i<2;$i++){ (($years,$month,$day) = Add_Delta_Days($years,$month,$day, 1))if ($i ne '1'); } } -my $newdatedue=$years."-".$month."-".$day; +my $newdatedue=C4::Dates->new( $years."-".$month."-".$day,'iso'); return $newdatedue; } =head2 CheckRepeatableHolidays diff --git a/C4/SIP/ILS/Transaction/Checkout.pm b/C4/SIP/ILS/Transaction/Checkout.pm index e86b621520..07d55ea1f6 100644 --- a/C4/SIP/ILS/Transaction/Checkout.pm +++ b/C4/SIP/ILS/Transaction/Checkout.pm @@ -51,7 +51,7 @@ sub do_checkout { my $borrower = GetMember( $patron_barcode, 'cardnumber' ); # use Data::Dumper; # warn Dumper $borrower; - my ($issuingimpossible,$needsconfirmation) = CanBookBeIssued ( $borrower, $barcode, 0, 0, 0, 0 ); + my ($issuingimpossible,$needsconfirmation) = CanBookBeIssued ( $borrower, $barcode ); my $noerror=1; foreach my $impossible ( keys %$issuingimpossible ) { # do something here so we pass these errors diff --git a/circ/circulation.pl b/circ/circulation.pl index c68427c1e1..db987ae4ac 100755 --- a/circ/circulation.pl +++ b/circ/circulation.pl @@ -115,6 +115,7 @@ my $year = $query->param('year'); my $month = $query->param('month'); my $day = $query->param('day'); my $stickyduedate = $query->param('stickyduedate'); +my $duedatespec = $query->param('duedatespec'); my $issueconfirmed = $query->param('issueconfirmed'); my $cancelreserve = $query->param('cancelreserve'); my $organisation = $query->param('organisations'); @@ -129,6 +130,16 @@ my $print = $query->param('print'); # } # +my ($datedue,$invalidduedate); +if($duedatespec) { + $datedue= C4::Dates->new($duedatespec ); + $invalidduedate=1 unless $datedue; +} +#if (defined($year)) { +# $duedatespec = "$year-$month-$day"; +#} else { +# ($year, $month, $day) = ($duedatespec) ? split /-/, $duedatespec : (0,0,0); +#} my @datearr = localtime( time() ); @@ -185,7 +196,7 @@ if ($findborrower) { # get the borrower information..... my $borrower; my @lines; - +warn $borrowernumber; if ($borrowernumber) { $borrower = GetMemberDetails( $borrowernumber, 0 ); my ( $od, $issue, $fines ) = GetMemberIssuesAndFines( $borrowernumber ); @@ -234,16 +245,15 @@ if ($borrowernumber) { # if ($barcode) { - $barcode = cuecatbarcodedecode($barcode); - my ( $datedue, $invalidduedate ) = fixdate( $year, $month, $day ); - if ($issueconfirmed) { + # $barcode = cuecatbarcodedecode($barcode); + + if ($issueconfirmed) { AddIssue( $borrower, $barcode, $datedue, $cancelreserve ); $inprocess = 1; } else { my ( $error, $question ) = - CanBookBeIssued( $borrower, $barcode, $year, $month, $day, - $inprocess ); + CanBookBeIssued( $borrower, $barcode, $datedue , $inprocess ); my $noerror = 1; my $noquestion = 1; # Get the item title for more information @@ -645,13 +655,8 @@ $template->param( # set return date if stickyduedate if ($stickyduedate) { - my $t_year = "year" . $year; - my $t_month = "month" . $month; - my $t_day = "day" . $day; $template->param( - $t_year => 1, - $t_month => 1, - $t_day => 1, + duedatespec => $duedatespec, ); } @@ -660,7 +665,8 @@ if ($stickyduedate) { #} $template->param( - SpecifyDueDate => C4::Context->preference("SpecifyDueDate") + SpecifyDueDate => C4::Context->preference("SpecifyDueDate"), + CircAutocompl => C4::Context->preference("CircAutocompl") , + DHTMLformat => C4::Dates->DHTMLcalendar(), ); -$template->param( CircAutocompl => C4::Context->preference("CircAutocompl") ); output_html_with_http_headers $query, $cookie, $template->output; diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tmpl b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tmpl index 8b0c7b1d37..3841bd6267 100755 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tmpl +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tmpl @@ -12,7 +12,7 @@ }); //]]> - + @@ -198,327 +198,52 @@ No patron matched -

- - - - - - - -

- - - - - " /> - " /> - " /> - - - - " /> - - -
- -
- - +

+ " /> + /lib/calendar/cal.gif" alt="Show Calendar" border="0" id="CalendarDueDate" style="cursor: pointer;" valign="top" /> + + + + checked="1" /> + + " /> + " /> + " /> + + + + " /> + + +

+ +
+

+
-- 2.39.5