BUG 8652: Add a default value for the lateorders

- 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.
This commit is contained in:
Jonathan Druart 2012-08-14 17:26:46 +02:00 committed by Paul Poulain
parent 37340e3718
commit 0f044d6c26
2 changed files with 55 additions and 21 deletions

View 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")

View File

@ -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){