Lines 2117-2127
sub GetLateOrders {
Link Here
|
2117 |
#BEWARE, order of parenthesis and LEFT JOIN is important for speed |
2117 |
#BEWARE, order of parenthesis and LEFT JOIN is important for speed |
2118 |
my $dbdriver = C4::Context->config("db_scheme") || "mysql"; |
2118 |
my $dbdriver = C4::Context->config("db_scheme") || "mysql"; |
2119 |
|
2119 |
|
|
|
2120 |
my $lateOrderSort = C4::Context->preference("AcqLateOrderUseCreationDate"); |
2121 |
my $aqbasketSortField = ( $lateOrderSort eq 'creation' ? 'creationdate' : 'closedate' ); |
2122 |
|
2120 |
my @query_params = (); |
2123 |
my @query_params = (); |
2121 |
my $select = " |
2124 |
my $select = " |
2122 |
SELECT aqbasket.basketno, |
2125 |
SELECT aqbasket.basketno, |
2123 |
aqorders.ordernumber, |
2126 |
aqorders.ordernumber, |
2124 |
DATE(aqbasket.closedate) AS orderdate, |
2127 |
DATE(aqbasket.${aqbasketSortField}) AS orderdate, |
2125 |
aqbasket.basketname AS basketname, |
2128 |
aqbasket.basketname AS basketname, |
2126 |
aqbasket.basketgroupid AS basketgroupid, |
2129 |
aqbasket.basketgroupid AS basketgroupid, |
2127 |
aqbasketgroups.name AS basketgroupname, |
2130 |
aqbasketgroups.name AS basketgroupname, |
Lines 2159-2168
sub GetLateOrders {
Link Here
|
2159 |
$select .= " |
2162 |
$select .= " |
2160 |
aqorders.quantity - COALESCE(aqorders.quantityreceived,0) AS quantity, |
2163 |
aqorders.quantity - COALESCE(aqorders.quantityreceived,0) AS quantity, |
2161 |
(aqorders.quantity - COALESCE(aqorders.quantityreceived,0)) * aqorders.rrp AS subtotal, |
2164 |
(aqorders.quantity - COALESCE(aqorders.quantityreceived,0)) * aqorders.rrp AS subtotal, |
2162 |
DATEDIFF(CAST(now() AS date),closedate) AS latesince |
2165 |
DATEDIFF(CAST(now() AS date),${aqbasketSortField}) AS latesince |
2163 |
"; |
2166 |
"; |
2164 |
if ( defined $delay ) { |
2167 |
if ( defined $delay ) { |
2165 |
$from .= " AND (closedate <= DATE_SUB(CAST(now() AS date),INTERVAL ? DAY)) " ; |
2168 |
$from .= " AND (${aqbasketSortField} <= DATE_SUB(CAST(now() AS date),INTERVAL ? DAY)) " ; |
2166 |
push @query_params, $delay; |
2169 |
push @query_params, $delay; |
2167 |
} |
2170 |
} |
2168 |
$having = " |
2171 |
$having = " |
Lines 2175-2184
sub GetLateOrders {
Link Here
|
2175 |
$select .= " |
2178 |
$select .= " |
2176 |
aqorders.quantity AS quantity, |
2179 |
aqorders.quantity AS quantity, |
2177 |
aqorders.quantity * aqorders.rrp AS subtotal, |
2180 |
aqorders.quantity * aqorders.rrp AS subtotal, |
2178 |
(CAST(now() AS date) - closedate) AS latesince |
2181 |
(CAST(now() AS date) - ${aqbasketSortField}) AS latesince |
2179 |
"; |
2182 |
"; |
2180 |
if ( defined $delay ) { |
2183 |
if ( defined $delay ) { |
2181 |
$from .= " AND (closedate <= (CAST(now() AS date) -(INTERVAL ? DAY)) "; |
2184 |
$from .= " AND (${aqbasketSortField} <= (CAST(now() AS date) -(INTERVAL ? DAY)) "; |
2182 |
push @query_params, $delay; |
2185 |
push @query_params, $delay; |
2183 |
} |
2186 |
} |
2184 |
} |
2187 |
} |