BUG 8652: Add a default value for the lateorders
authorJonathan Druart <jonathan.druart@biblibre.com>
Tue, 14 Aug 2012 15:26:46 +0000 (17:26 +0200)
committerPaul Poulain <paul.poulain@biblibre.com>
Tue, 9 Oct 2012 09:27:39 +0000 (11:27 +0200)
- By default, the date from value is the today's date
- Replace C4::Dates with Koha::DateUtils

To test:
Check the page displays the late orders by default.
Add values for 'date from' and/or 'date to' and/or delay.
The date interval is based on the estimated delivery date and the delay
param is based on the closed date.

C4/Acquisition.pm
acqui/lateorders.pl

index 7d67e6f..83031be 100644 (file)
@@ -1828,16 +1828,19 @@ sub GetLateOrders {
         $from .= ' AND borrowers.branchcode LIKE ? ';
         push @query_params, $branch;
     }
+
+    if ( defined $estimateddeliverydatefrom or defined $estimateddeliverydateto ) {
+        $from .= ' AND aqbooksellers.deliverytime IS NOT NULL ';
+    }
     if ( defined $estimateddeliverydatefrom ) {
-        $from .= '
-            AND aqbooksellers.deliverytime IS NOT NULL
-            AND ADDDATE(aqbasket.closedate, INTERVAL aqbooksellers.deliverytime DAY) >= ?';
+        $from .= ' AND ADDDATE(aqbasket.closedate, INTERVAL aqbooksellers.deliverytime DAY) >= ?';
         push @query_params, $estimateddeliverydatefrom;
     }
-    if ( defined $estimateddeliverydatefrom and defined $estimateddeliverydateto ) {
+    if ( defined $estimateddeliverydateto ) {
         $from .= ' AND ADDDATE(aqbasket.closedate, INTERVAL aqbooksellers.deliverytime DAY) <= ?';
         push @query_params, $estimateddeliverydateto;
-    } elsif ( defined $estimateddeliverydatefrom ) {
+    }
+    if ( defined $estimateddeliverydatefrom and not defined $estimateddeliverydateto ) {
         $from .= ' AND ADDDATE(aqbasket.closedate, INTERVAL aqbooksellers.deliverytime DAY) <= CAST(now() AS date)';
     }
     if (C4::Context->preference("IndependantBranches")
index 3c66eb8..50e0f0e 100755 (executable)
@@ -43,8 +43,7 @@ To know on which branch this script have to display late order.
 
 =cut
 
-use strict;
-use warnings;
+use Modern::Perl;
 use CGI;
 use C4::Bookseller qw( GetBooksellersWithLateOrders );
 use C4::Auth;
@@ -54,6 +53,7 @@ use C4::Context;
 use C4::Acquisition;
 use C4::Letters;
 use C4::Branch; # GetBranches
+use Koha::DateUtils;
 
 my $input = new CGI;
 my ($template, $loggedinuser, $cookie) = get_template_and_user({
@@ -66,9 +66,30 @@ my ($template, $loggedinuser, $cookie) = get_template_and_user({
 });
 
 my $booksellerid = $input->param('booksellerid') || undef; # we don't want "" or 0
-my $delay      = $input->param('delay');
+my $delay        = $input->param('delay');
+
+# Get the "date from" param if !defined is today
 my $estimateddeliverydatefrom = $input->param('estimateddeliverydatefrom');
 my $estimateddeliverydateto   = $input->param('estimateddeliverydateto');
+
+my $estimateddeliverydatefrom_dt =
+  $estimateddeliverydatefrom
+  ? dt_from_string($estimateddeliverydatefrom)
+  : undef;
+
+# Get the "date to" param. If it is not defined and $delay is not defined too, it is the today's date.
+my $estimateddeliverydateto_dt = dt_from_string($estimateddeliverydateto);
+
+# Format the output of "date from" and "date to"
+if ($estimateddeliverydatefrom) {
+    $estimateddeliverydatefrom = output_pref($estimateddeliverydatefrom_dt);
+    $estimateddeliverydatefrom =~ s/ \d\d:\d\d$//;
+}
+if ($estimateddeliverydateto) {
+    $estimateddeliverydateto = output_pref($estimateddeliverydateto_dt);
+    $estimateddeliverydateto =~ s/ \d\d:\d\d$//;
+}
+
 my $branch     = $input->param('branch');
 my $op         = $input->param('op');
 
@@ -95,12 +116,17 @@ if ($op and $op eq "send_alert"){
     }
 }
 
-my %supplierlist = GetBooksellersWithLateOrders(
-    $delay,
-    $branch,
-    C4::Dates->new($estimateddeliverydatefrom)->output("iso"),
-    C4::Dates->new($estimateddeliverydateto)->output("iso")
-);
+my @parameters = ( $delay, $branch );
+if ($estimateddeliverydatefrom_dt) {
+    push @parameters, $estimateddeliverydatefrom_dt->ymd();
+}
+else {
+    push @parameters, undef;
+}
+if ($estimateddeliverydateto_dt) {
+    push @parameters, $estimateddeliverydateto_dt->ymd();
+}
+my %supplierlist = GetBooksellersWithLateOrders(@parameters);
 
 my (@sloopy);  # supplier loop
 foreach (keys %supplierlist){
@@ -113,13 +139,18 @@ $template->param(SUPPLIER_LOOP => \@sloopy);
 $template->param(Supplier=>$supplierlist{$booksellerid}) if ($booksellerid);
 $template->param(booksellerid=>$booksellerid) if ($booksellerid);
 
-my @lateorders = GetLateOrders(
-    $delay,
-    $booksellerid,
-    $branch,
-    C4::Dates->new($estimateddeliverydatefrom)->output("iso"),
-    C4::Dates->new($estimateddeliverydateto)->output("iso")
-);
+@parameters =
+  ( $delay, $booksellerid, $branch );
+if ($estimateddeliverydatefrom_dt) {
+    push @parameters, $estimateddeliverydatefrom_dt->ymd();
+}
+else {
+    push @parameters, undef;
+}
+if ($estimateddeliverydateto_dt) {
+    push @parameters, $estimateddeliverydateto_dt->ymd();
+}
+my @lateorders = GetLateOrders( @parameters );
 
 my $total;
 foreach (@lateorders){