From 2ea75d7dc9f9551c7c9bf2c00ce424b5551eacdb Mon Sep 17 00:00:00 2001 From: simith Date: Thu, 7 Aug 2014 14:19:52 -0400 Subject: [PATCH] Bug 12732 - Sort late orders by basket creation or closing date This fix permits to sort late orders by basket creation or closing date Modified: installer/data/mysql/sysprefs.sql -AcqLateOrderUseCreationDate preference added koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/acquisitions.pref -AcqLateOrderUseCreationDate preference added koha-tmpl/intranet-tmpl/prog/en/modules/acqui/lateorders.tt -Change "Order date" column acqui/lateorders.pl - C4/Acquisition.pm -Change sql Testing: I Apply the patch II Run updatedatabase.pl 0) Create 2 orders each one with different baskets; 1) Change the first basket date (table aqbasket, column creationdate and closedate) to 2014-07-13; 2) Change the second basket creationdate to 2014-07-12 and closedate to 2014-07-14; 3) Set AcqLateOrderUseCreationDate to Don't use the creation date of the basket to sort late order; 4) Validate sort by "close date" (second basket came first) and "Order close date" column; 5) Set AcqLateOrderUseCreationDate to Do use the creation date of the basket to sort late order; 6) Validate sort by "creation date" (first basket came first) and "Order creation date" column; sponsored by the CCSR ( http://www.ccsr.qc.ca ) --- C4/Acquisition.pm | 13 ++++++++----- acqui/lateorders.pl | 1 + installer/data/mysql/sysprefs.sql | 1 + koha-tmpl/intranet-tmpl/prog/en/modules/acqui/lateorders.tt | 2 +- .../prog/en/modules/admin/preferences/acquisitions.pref | 6 ++++++ 5 files changed, 17 insertions(+), 6 deletions(-) diff --git a/C4/Acquisition.pm b/C4/Acquisition.pm index 6ad5ff7..5bf3768 100644 --- a/C4/Acquisition.pm +++ b/C4/Acquisition.pm @@ -2039,11 +2039,14 @@ sub GetLateOrders { #BEWARE, order of parenthesis and LEFT JOIN is important for speed my $dbdriver = C4::Context->config("db_scheme") || "mysql"; + my $lateOrderSort = C4::Context->preference("AcqLateOrderUseCreationDate"); + my $aqbasketSortField = ( $lateOrderSort eq 'creation' ? 'creationdate' : 'closedate' ); + my @query_params = (); my $select = " SELECT aqbasket.basketno, aqorders.ordernumber, - DATE(aqbasket.closedate) AS orderdate, + DATE(aqbasket.${aqbasketSortField}) AS orderdate, aqbasket.basketname AS basketname, aqbasket.basketgroupid AS basketgroupid, aqbasketgroups.name AS basketgroupname, @@ -2081,10 +2084,10 @@ sub GetLateOrders { $select .= " aqorders.quantity - COALESCE(aqorders.quantityreceived,0) AS quantity, (aqorders.quantity - COALESCE(aqorders.quantityreceived,0)) * aqorders.rrp AS subtotal, - DATEDIFF(CAST(now() AS date),closedate) AS latesince + DATEDIFF(CAST(now() AS date),${aqbasketSortField}) AS latesince "; if ( defined $delay ) { - $from .= " AND (closedate <= DATE_SUB(CAST(now() AS date),INTERVAL ? DAY)) " ; + $from .= " AND (${aqbasketSortField} <= DATE_SUB(CAST(now() AS date),INTERVAL ? DAY)) " ; push @query_params, $delay; } $having = " @@ -2097,10 +2100,10 @@ sub GetLateOrders { $select .= " aqorders.quantity AS quantity, aqorders.quantity * aqorders.rrp AS subtotal, - (CAST(now() AS date) - closedate) AS latesince + (CAST(now() AS date) - ${aqbasketSortField}) AS latesince "; if ( defined $delay ) { - $from .= " AND (closedate <= (CAST(now() AS date) -(INTERVAL ? DAY)) "; + $from .= " AND (${aqbasketSortField} <= (CAST(now() AS date) -(INTERVAL ? DAY)) "; push @query_params, $delay; } } diff --git a/acqui/lateorders.pl b/acqui/lateorders.pl index fe1acc3..1d4346c 100755 --- a/acqui/lateorders.pl +++ b/acqui/lateorders.pl @@ -173,5 +173,6 @@ $template->param( estimateddeliverydateto => $estimateddeliverydateto, total => $total, intranetcolorstylesheet => C4::Context->preference("intranetcolorstylesheet"), + lateOrderSort => C4::Context->preference("AcqLateOrderUseCreationDate"), ); output_html_with_http_headers $input, $cookie, $template->output; diff --git a/installer/data/mysql/sysprefs.sql b/installer/data/mysql/sysprefs.sql index ef83c3d..32758ac 100644 --- a/installer/data/mysql/sysprefs.sql +++ b/installer/data/mysql/sysprefs.sql @@ -3,6 +3,7 @@ INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` ('AcqEnableFiles','0',NULL,'If enabled, allows librarians to upload and attach arbitrary files to invoice records.','YesNo'), ('AcqItemSetSubfieldsWhenReceiptIsCancelled','', '','Upon cancelling a receipt, update the items subfields if they were created when placing an order (e.g. o=5|a="bar foo")', 'Free'), ('AcqItemSetSubfieldsWhenReceived','','','Upon receiving items, update their subfields if they were created when placing an order (e.g. o=5|a="foo bar")','Free'), +('AcqLateOrderUseCreationDate', 'closing', 'creation|closing', 'Change late order default sort.', 'Choice'); ('AcquisitionDetails', '1', '', 'Hide/Show acquisition details on the biblio detail page.', 'YesNo'), ('AcqViewBaskets','user','user|branch|all','Define which baskets a user is allowed to view: his own only, any within his branch or all','Choice'), ('AcqWarnOnDuplicateInvoice','0','','Warn librarians when they try to create a duplicate invoice','YesNo'), diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/lateorders.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/lateorders.tt index 2363765..b53058c 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/lateorders.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/lateorders.tt @@ -116,7 +116,7 @@ $(document).ready(function() { [% ELSE %] [% END %] - Order date + Order [% lateOrderSort %] date Estimated delivery date Vendor Information diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/acquisitions.pref b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/acquisitions.pref index 0c45ed5..33a3a6d 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/acquisitions.pref +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/acquisitions.pref @@ -20,6 +20,12 @@ Acquisitions: 1: always ask for confirmation. 2: do not ask for confirmation. - + - pref: AcqLateOrderUseCreationDate + choices: + creation: Do + closing: Don't + - Use the creation date of the basket to sort late order. + - - Show baskets - pref: AcqViewBaskets choices: -- 1.9.1