Bug 14920: Remove C4::Dates from circ/reserveratios.pl
authorMarc Véron <veron@veron.ch>
Tue, 29 Sep 2015 12:22:33 +0000 (14:22 +0200)
committerTomas Cohen Arazi <tomascohen@theke.io>
Tue, 13 Oct 2015 14:39:01 +0000 (11:39 -0300)
This patch removes C4::Dates from circ/reserveratios.pl

To test:
- Make sure you have many holds for biblios with not so much items (e.g. 5 holds, 1 item)
  or follow hint below
- Go to Home > Circulation > Hold ratios
- Verify that everything works the same without an dwith patch

Hint: To get a big table you can set 'Hod ratio' in the filter to 0.1  (default value is 3).
This was will trigger biblios with less holds than items.

Signed-off-by: Hector Castro <hector.hecaxmmx@gmail.com>
Works as advertised. Tested with dateformat syspref, datepiker Ok

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
circ/reserveratios.pl
koha-tmpl/intranet-tmpl/prog/en/modules/circ/reserveratios.tt

index 9675674..27cc86c 100755 (executable)
@@ -27,10 +27,10 @@ use Date::Calc qw/Today Add_Delta_YM/;
 use C4::Context;
 use C4::Output;
 use C4::Auth;
-use C4::Dates qw/format_date format_date_in_iso/;
 use C4::Debug;
 use C4::Biblio qw/GetMarcBiblio GetRecordValue GetFrameworkCode/;
 use C4::Acquisition qw/GetOrdersByBiblionumber/;
+use Koha::DateUtils;
 
 my $input = new CGI;
 my $startdate       = $input->param('from');
@@ -55,22 +55,21 @@ if ($booksellerid && $basketno) {
      $template->param( booksellerid => $booksellerid, basketno => $basketno );
 }
 
-my ( $year, $month, $day ) = Today();
-my $todaysdate     = sprintf("%-04.4d-%-02.2d-%02.2d", $year, $month, $day);
-# Find yesterday for the default shelf pull start and end dates
-#    A default of the prior years's holds is a reasonable way to pull holds 
-my $datelastyear = sprintf("%-04.4d-%-02.2d-%02.2d", Add_Delta_YM($year, $month, $day, -1, 0));
+$startdate = eval { output_pref( { dt => dt_from_string( $startdate ), dateonly => 1, dateformat => 'iso' } ); };
+$enddate = eval { output_pref( { dt => dt_from_string( $enddate ), dateonly => 1, dateformat => 'iso' } ); };
+
+my $todaysdate_dt = dt_from_string;
+my $todaysdate  = output_pref( { dt => $todaysdate_dt, dateonly => 1, dateformat => 'iso' } );
+
+#    A default of the prior years's holds is a reasonable way to pull holds
+my $datelastyear_dt = $todaysdate_dt->subtract( days => 1);
+my $datelastyear = output_pref( { dt => $datelastyear_dt, dateonly => 1, dateformat => 'iso' } );
+
+$startdate = $datelastyear unless $startdate;
+$enddate = $todaysdate unless $enddate;
 
-#              Predefine the start and end dates if they are not already defined
-#              Check if null, should string match, if so set start and end date to yesterday
-if (!defined($startdate) or $startdate !~ s/^\s*(\S+)\s*$/$1/) {   # strip spaces, remove Taint
-       $startdate = format_date($datelastyear);
-}
-if (!defined($enddate)   or $enddate   !~ s/^\s*(\S+)\s*$/$1/) {   # strip spaces, remove Taint
-       $enddate   = format_date($todaysdate);
-}
 if (!defined($ratio)) {
-       $ratio = 3;
+    $ratio = 3;
 }
 # Force to be a number
 $ratio += 0;
@@ -80,15 +79,15 @@ if ($ratio <= 0) {
 
 my $dbh    = C4::Context->dbh;
 my $sqldatewhere = "";
-$debug and warn format_date_in_iso($startdate) . "\n" . format_date_in_iso($enddate);
+$debug and warn output_pref({ dt => dt_from_string( $startdate ), dateformat => 'iso', dateonly => 1 }) . "\n" . output_pref({ dt => dt_from_string( $enddate ), dateformat => 'iso', dateonly => 1 });
 my @query_params = ();
 if ($startdate) {
     $sqldatewhere .= " AND reservedate >= ?";
-    push @query_params, format_date_in_iso($startdate);
+    push @query_params, $startdate ;
 }
 if ($enddate) {
     $sqldatewhere .= " AND reservedate <= ?";
-    push @query_params, format_date_in_iso($enddate);
+    push @query_params, $enddate;
 }
 
 my $nfl_comparison = $include_ordered ? '<=' : '=';
@@ -146,7 +145,7 @@ while ( my $data = $sth->fetchrow_hashref ) {
     push(
         @reservedata,
         {
-            reservedate        => format_date( $data->{reservedate} ),
+            reservedate        => $data->{reservedate},
             priority           => $data->{priority},
             name               => $data->{borrower},
             title              => $data->{title},
@@ -178,7 +177,7 @@ for my $rd ( @reservedata ) {
 
 $template->param(
     ratio_atleast1  => $ratio_atleast1,
-    todaysdate      => format_date($todaysdate),
+    todaysdate      => $todaysdate,
     from            => $startdate,
     to              => $enddate,
     ratio           => $ratio,
index 80fe4aa..67f4226 100644 (file)
@@ -1,3 +1,4 @@
+[% USE KohaDates %]
 [% INCLUDE 'doc-head-open.inc' %]
 <title>Koha &rsaquo; Circulation &rsaquo; Hold ratios</title>
 [% INCLUDE 'doc-head-close.inc' %]
@@ -42,8 +43,8 @@
     <div id="yui-main">
     <div class="yui-b">
 <h1>Hold ratios to calculate items needed</h1>
-   <h3>Calculated on [% todaysdate %]. From [% from %]
-    to [% to %]</h3>
+   <h3>Calculated on [% todaysdate | $KohaDates %]. From [% from | $KohaDates %]
+    to [% to | $KohaDates %]</h3>
 <p>These items have a hold ratio &ge; [% ratio %].</p>
 <div class="sql">[% sql %]</div>
 
 
     <li>
         <label for="from">Start date:</label>
-        <input type="text" size="10" id="from" name="from" value="[% from %]" class="datepickerfrom" />
+        <input type="text" size="10" id="from" name="from" value="[% from | $KohaDates %]" class="datepickerfrom" />
     </li>
 
     <li>
         <label for="to">End date:</label>
-        <input size="10" id="to" name="to" value="[% to %]" type="text" class="datepickerto" />
+        <input size="10" id="to" name="to" value="[% to | $KohaDates %]" type="text" class="datepickerto" />
     </li>
 </ol>
 (inclusive)