From 421fae24f1cdcbe0ccc18de784454d0ca07ebe90 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Marc=20V=C3=A9ron?= Date: Fri, 9 Oct 2015 18:48:30 +0200 Subject: [PATCH] Bug 14903: Remove C4::Dates from circ/circulation.pl (and more) Patch to remove deprectated C4::Dates from: - circ/circulation.pl - C4/Circulation.pm - koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tt To test: - Apply patch - Go to the checkout site (Home > Circulation > Checkouts) - Verify that data displays properly (including for users with a card that expires in the near future, see syspref 'NotifyBorrowerDeparture') - Search for regressions - prove -v t/db_dependent/Circulation.t (Amended following comment #9 / #11 25.10.2015 /mv) Signed-off-by: Mirko Tietgen Signed-off-by: Jonathan Druart Signed-off-by: Tomas Cohen Arazi --- C4/Circulation.pm | 23 +++++++--------- circ/circulation.pl | 26 +++++++++---------- .../prog/en/modules/circ/circulation.tt | 12 ++++----- 3 files changed, 28 insertions(+), 33 deletions(-) diff --git a/C4/Circulation.pm b/C4/Circulation.pm index 43b8f93fcd..18cc9d5ebe 100644 --- a/C4/Circulation.pm +++ b/C4/Circulation.pm @@ -22,14 +22,13 @@ package C4::Circulation; use strict; #use warnings; FIXME - Bug 2505 use DateTime; +use Koha::DateUtils; use C4::Context; use C4::Stats; use C4::Reserves; use C4::Biblio; use C4::Items; use C4::Members; -use C4::Dates; -use C4::Dates qw(format_date); use C4::Accounts; use C4::ItemCirculationAlertPreference; use C4::Message; @@ -657,7 +656,7 @@ sub itemissues { =head2 CanBookBeIssued ( $issuingimpossible, $needsconfirmation ) = CanBookBeIssued( $borrower, - $barcode, $duedatespec, $inprocess, $ignore_reserves ); + $barcode, $duedate, $inprocess, $ignore_reserves ); Check if a book can be issued. @@ -669,7 +668,7 @@ C<$issuingimpossible> and C<$needsconfirmation> are some hashref. =item C<$barcode> is the bar code of the book being issued. -=item C<$duedatespec> is a C4::Dates object. +=item C<$duedates> is a DateTime object. =item C<$inprocess> boolean switch =item C<$ignore_reserves> boolean switch @@ -1035,7 +1034,7 @@ sub CanBookBeIssued { $needsconfirmation{'rescardnumber'} = $resborrower->{'cardnumber'}; $needsconfirmation{'resborrowernumber'} = $resborrower->{'borrowernumber'}; $needsconfirmation{'resbranchname'} = $branchname; - $needsconfirmation{'reswaitingdate'} = format_date($res->{'waitingdate'}); + $needsconfirmation{'reswaitingdate'} = $res->{'waitingdate'}; } elsif ( $restype eq "Reserved" ) { # The item is on reserve for someone else. @@ -1045,7 +1044,7 @@ sub CanBookBeIssued { $needsconfirmation{'rescardnumber'} = $resborrower->{'cardnumber'}; $needsconfirmation{'resborrowernumber'} = $resborrower->{'borrowernumber'}; $needsconfirmation{'resbranchname'} = $branchname; - $needsconfirmation{'resreservedate'} = format_date($res->{'reservedate'}); + $needsconfirmation{'resreservedate'} = $res->{'reservedate'}; } } } @@ -1212,13 +1211,13 @@ Issue a book. Does no check, they are done in CanBookBeIssued. If we reach this =item C<$barcode> is the barcode of the item being issued. -=item C<$datedue> is a C4::Dates object for the max date of return, i.e. the date due (optional). +=item C<$datedue> is a DateTime object for the max date of return, i.e. the date due (optional). Calculated if empty. =item C<$cancelreserve> is 1 to override and cancel any pending reserves for the item (optional). =item C<$issuedate> is the date to issue the item in iso (YYYY-MM-DD) format (optional). -Defaults to today. Unlike C<$datedue>, NOT a C4::Dates object, unfortunately. +Defaults to today. Unlike C<$datedue>, NOT a DateTime object, unfortunately. AddIssue does the following things : @@ -1905,7 +1904,7 @@ sub AddReturn { # define circControlBranch only if dropbox mode is set # don't allow dropbox mode to create an invalid entry in issues (issuedate > today) # FIXME: check issuedate > returndate, factoring in holidays - #$circControlBranch = _GetCircControlBranch($item,$borrower) unless ( $item->{'issuedate'} eq C4::Dates->today('iso') );; + $circControlBranch = _GetCircControlBranch($item,$borrower); $issue->{'overdue'} = DateTime->compare($issue->{'date_due'}, $dropboxdate ) == -1 ? 1 : 0; } @@ -2851,7 +2850,7 @@ C<$itemnumber> is the number of the item to renew. C<$branch> is the library where the renewal took place (if any). The library that controls the circ policies for the renewal is retrieved from the issues record. -C<$datedue> can be a C4::Dates object used to set the due date. +C<$datedue> can be a DateTime object used to set the due date. C<$lastreneweddate> is an optional ISO-formatted date used to set issues.lastreneweddate. If this parameter is not supplied, lastreneweddate is set to the current date. @@ -3435,7 +3434,7 @@ $newdatedue = CalcDateDue($startdate,$itemtype,$branchcode,$borrower); this function calculates the due date given the start date and configured circulation rules, checking against the holidays calendar as per the 'useDaysMode' syspref. -C<$startdate> = C4::Dates object representing start date of loan period (assumed to be today) +C<$startdate> = DateTime object representing start date of loan period (assumed to be today) C<$itemtype> = itemtype code of item in question C<$branch> = location whose calendar to use C<$borrower> = Borrower object @@ -3877,8 +3876,6 @@ sub TransferSlip { my $item = GetItem( $itemnumber, $barcode ) or return; - my $pulldate = C4::Dates->new(); - return C4::Letters::GetPreparedLetter ( module => 'circulation', letter_code => 'TRANSFERSLIP', diff --git a/circ/circulation.pl b/circ/circulation.pl index d42be298e8..1812061ebf 100755 --- a/circ/circulation.pl +++ b/circ/circulation.pl @@ -30,7 +30,6 @@ use DateTime::Duration; use C4::Output; use C4::Print; use C4::Auth qw/:DEFAULT get_session haspermission/; -use C4::Dates qw/format_date/; use C4::Branch; # GetBranches use C4::Koha; # GetPrinter use C4::Circulation; @@ -175,6 +174,8 @@ for my $barcode ( @$barcodes ) { my $stickyduedate = $query->param('stickyduedate') || $session->param('stickyduedate'); my $duedatespec = $query->param('duedatespec') || $session->param('stickyduedate'); +$duedatespec = eval { output_pref( { dt => dt_from_string( $duedatespec ), dateformat => 'iso' }); }; + my $issueconfirmed = $query->param('issueconfirmed'); my $cancelreserve = $query->param('cancelreserve'); my $print = $query->param('print') || q{}; @@ -202,18 +203,15 @@ if( $onsite_checkout && !$duedatespec_allow ) { $datedue = output_pref({ dt => dt_from_string, dateonly => 1, dateformat => 'iso' }); $datedue .= ' 23:59:00'; } elsif( $duedatespec_allow ) { - if ($duedatespec) { - if ($duedatespec =~ C4::Dates->regexp('syspref')) { - $datedue = dt_from_string($duedatespec); - } else { + if ($datedue) { + $datedue = eval { dt_from_string( $datedue ) }; + if (! $datedue ) { $invalidduedate = 1; - $template->param(IMPOSSIBLE=>1, INVALID_DATE=>$duedatespec); + $template->param( IMPOSSIBLE=>1, INVALID_DATE=>$datedue ); } } } -our $todaysdate = C4::Dates->new->output('iso'); - # check and see if we should print if ( @$barcodes == 0 && $print eq 'maybe' ) { $print = 'yes'; @@ -295,7 +293,7 @@ if ($borrowernumber) { noissues => ($force_allow_issue) ? 0 : "1", forceallow => $force_allow_issue, expired => "1", - renewaldate => format_date("$renew_year-$renew_month-$renew_day") + renewaldate => "$renew_year-$renew_month-$renew_day", ); } # check for NotifyBorrowerDeparture @@ -304,8 +302,9 @@ if ($borrowernumber) { Date_to_Days( $today_year, $today_month, $today_day ) ) { # borrower card soon to expire warn librarian - $template->param("warndeparture" => format_date($borrower->{dateexpiry}), - flagged => "1",); + $template->param( "warndeparture" => $borrower->{dateexpiry} , + flagged => "1" + ); if (C4::Context->preference('ReturnBeforeExpiry')){ $template->param("returnbeforeexpiry" => 1); } @@ -323,8 +322,7 @@ if ($borrowernumber) { ); if ( $borrower->{debarred} ne "9999-12-31" ) { - $template->param( 'userdebarreddate' => - C4::Dates::format_date( $borrower->{debarred} ) ); + $template->param( 'userdebarreddate' => $borrower->{debarred} ); } } @@ -590,7 +588,7 @@ $template->param( printer => $printer, printername => $printer, was_renewed => $query->param('was_renewed') ? 1 : 0, - expiry => format_date($borrower->{'dateexpiry'}), + expiry => $borrower->{'dateexpiry'}, roadtype => $roadtype, amountold => $amountold, barcodes => $barcodes, diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tt index 4573c0d6e7..322a0824cc 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tt @@ -190,7 +190,7 @@ $(document).ready(function() { -[% IF ( was_renewed ) %]
Patron's account has been renewed until [% expiry %]
[% END %] +[% IF ( was_renewed ) %]
Patron's account has been renewed until [% expiry | $KohaDates %]
[% END %] [% IF additional_materials %]
Note about the accompanying materials:
@@ -237,11 +237,11 @@ $(document).ready(function() { [% END %] [% IF ( RESERVE_WAITING ) %] -
  • Item [% getTitleMessageIteminfo %] ([% getBarcodeMessageIteminfo %]) has been waiting for [% resfirstname %] [% ressurname %] ([% rescardnumber %]) at [% resbranchname %] since [% reswaitingdate %]
  • +
  • Item [% getTitleMessageIteminfo %] ([% getBarcodeMessageIteminfo %]) has been waiting for [% resfirstname %] [% ressurname %] ([% rescardnumber %]) at [% resbranchname %] since [% reswaitingdate | $KohaDates %]
  • [% END %] [% IF ( RESERVED ) %] -
  • Item [% getTitleMessageIteminfo %] ([% getBarcodeMessageIteminfo %]) has been on hold for [% resfirstname %] [% ressurname %] ([% rescardnumber %]) at [% resbranchname %] since [% resreservedate %]
  • +
  • Item [% getTitleMessageIteminfo %] ([% getBarcodeMessageIteminfo %]) has been on hold for [% resfirstname %] [% ressurname %] ([% rescardnumber %]) at [% resbranchname %] since [% resreservedate | $KohaDates %]
  • [% END %] [% IF ( ISSUED_TO_ANOTHER ) %] @@ -724,7 +724,7 @@ No patron matched [% message %] [% IF ( warndeparture ) %]
  • Expiration: Patron's card will expire soon. - Patron's card expires on [% expiry %] Renew or Edit Details + Patron's card expires on [% expiry | $KohaDates %] Renew or Edit Details
  • [% END %] @@ -737,7 +737,7 @@ No patron matched [% message %] [% IF ( expired ) %]
  • Expiration: Patron's card has expired. - [% IF ( expiry ) %]Patron's card expired on [% expiry %][% END %] Renew or Edit Details + [% IF ( expiry ) %]Patron's card expired on [% expiry | $KohaDates %][% END %] Renew or Edit Details
  • [% END %] @@ -755,7 +755,7 @@ No patron matched [% message %] Restricted: Patron's account is restricted [% IF ( userdebarreddate ) %] - until [% userdebarreddate %] + until [% userdebarreddate | $KohaDates %] [% END %] [% IF ( debarredcomment ) %] -- 2.39.5