From a92a5cbbbc95f55589021c176241671f0c458008 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 ) Signed-off-by: Paola Rossi --- C4/Acquisition.pm | 13 ++++++++----- acqui/lateorders.pl | 1 + installer/data/mysql/sysprefs.sql | 1 + .../intranet-tmpl/prog/en/modules/acqui/lateorders.tt | 2 +- .../prog/en/modules/admin/preferences/acquisitions.pref | 7 +++++++ 5 files changed, 18 insertions(+), 6 deletions(-) diff --git a/C4/Acquisition.pm b/C4/Acquisition.pm index 0cff235..1a7c196 100644 --- a/C4/Acquisition.pm +++ b/C4/Acquisition.pm @@ -2117,11 +2117,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, @@ -2159,10 +2162,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 = " @@ -2175,10 +2178,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 d43dbbe..974f75f 100755 --- a/acqui/lateorders.pl +++ b/acqui/lateorders.pl @@ -172,5 +172,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 03a3f1e..c857f61 100644 --- a/installer/data/mysql/sysprefs.sql +++ b/installer/data/mysql/sysprefs.sql @@ -2,6 +2,7 @@ INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` ('AcqCreateItem','ordering','ordering|receiving|cataloguing','Define when the item is created : when ordering, when receiving, or in cataloguing module','Choice'), ('AcqEnableFiles','0',NULL,'If enabled, allows librarians to upload and attach arbitrary files to invoice records.','YesNo'), ('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 efa0db6..a1a3947 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/lateorders.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/lateorders.tt @@ -111,7 +111,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 ac57f95..a6e9d11 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 @@ -57,6 +57,13 @@ Acquisitions: type: textarea - "You can use the following fields: price, quantity, budget_code, discount, sort1, sort2" - "
For example:
price: 947$a|947$c
quantity: 969$h
budget_code: 922$a" + - + - pref: AcqLateOrderUseCreationDate + choices: + creation: Do + closing: Don't + - Use the creation date of the basket to sort late order. + Printing: - - Use the -- 1.7.10.4