Lines 66-72
BEGIN {
Link Here
|
66 |
&GetBasketgroups &ReOpenBasketgroup |
66 |
&GetBasketgroups &ReOpenBasketgroup |
67 |
|
67 |
|
68 |
&DelOrder &ModOrder &GetOrder &GetOrders &GetOrdersByBiblionumber |
68 |
&DelOrder &ModOrder &GetOrder &GetOrders &GetOrdersByBiblionumber |
69 |
&GetLateOrders &GetOrderFromItemnumber |
69 |
&GetOrderFromItemnumber |
70 |
&SearchOrders &GetHistory &GetRecentAcqui |
70 |
&SearchOrders &GetHistory &GetRecentAcqui |
71 |
&ModReceiveOrder &CancelReceipt |
71 |
&ModReceiveOrder &CancelReceipt |
72 |
&TransferOrder |
72 |
&TransferOrder |
Lines 2135-2268
sub GetParcels {
Link Here
|
2135 |
|
2135 |
|
2136 |
#------------------------------------------------------------# |
2136 |
#------------------------------------------------------------# |
2137 |
|
2137 |
|
2138 |
=head3 GetLateOrders |
|
|
2139 |
|
2140 |
@results = &GetLateOrders; |
2141 |
|
2142 |
Searches for bookseller with late orders. |
2143 |
|
2144 |
return: |
2145 |
the table of supplier with late issues. This table is full of hashref. |
2146 |
|
2147 |
=cut |
2148 |
|
2149 |
sub GetLateOrders { |
2150 |
my $delay = shift; |
2151 |
my $supplierid = shift; |
2152 |
my $branch = shift; |
2153 |
my $estimateddeliverydatefrom = shift; |
2154 |
my $estimateddeliverydateto = shift; |
2155 |
|
2156 |
my $dbh = C4::Context->dbh; |
2157 |
|
2158 |
#BEWARE, order of parenthesis and LEFT JOIN is important for speed |
2159 |
my $dbdriver = C4::Context->config("db_scheme") || "mysql"; |
2160 |
|
2161 |
my @query_params = (); |
2162 |
my $select = " |
2163 |
SELECT aqbasket.basketno, |
2164 |
aqorders.ordernumber AS ordernumber, |
2165 |
DATE(aqbasket.closedate) AS orderdate, |
2166 |
aqbasket.basketname AS basketname, |
2167 |
aqbasket.basketgroupid AS basketgroupid, |
2168 |
aqbasketgroups.name AS basketgroupname, |
2169 |
aqorders.rrp AS unitpricesupplier, |
2170 |
aqorders.ecost AS unitpricelib, |
2171 |
aqorders.claims_count AS claims_count, |
2172 |
aqorders.claimed_date AS claimed_date, |
2173 |
aqorders.order_internalnote AS internalnote, |
2174 |
aqorders.order_vendornote AS vendornote, |
2175 |
aqbudgets.budget_name AS budget, |
2176 |
borrowers.branchcode AS branch, |
2177 |
aqbooksellers.name AS supplier, |
2178 |
aqbooksellers.id AS supplierid, |
2179 |
biblio.author, biblio.title, |
2180 |
biblioitems.publishercode AS publisher, |
2181 |
biblioitems.publicationyear, |
2182 |
biblioitems.isbn AS isbn, |
2183 |
ADDDATE(aqbasket.closedate, INTERVAL aqbooksellers.deliverytime DAY) AS estimateddeliverydate, |
2184 |
"; |
2185 |
my $from = " |
2186 |
FROM |
2187 |
aqorders LEFT JOIN biblio ON biblio.biblionumber = aqorders.biblionumber |
2188 |
LEFT JOIN biblioitems ON biblioitems.biblionumber = biblio.biblionumber |
2189 |
LEFT JOIN aqbudgets ON aqorders.budget_id = aqbudgets.budget_id, |
2190 |
aqbasket LEFT JOIN borrowers ON aqbasket.authorisedby = borrowers.borrowernumber |
2191 |
LEFT JOIN aqbooksellers ON aqbasket.booksellerid = aqbooksellers.id |
2192 |
LEFT JOIN aqbasketgroups ON aqbasket.basketgroupid = aqbasketgroups.id |
2193 |
WHERE aqorders.basketno = aqbasket.basketno |
2194 |
AND ( datereceived IS NULL |
2195 |
OR aqorders.quantityreceived < aqorders.quantity |
2196 |
) |
2197 |
AND aqbasket.closedate IS NOT NULL |
2198 |
AND aqorders.datecancellationprinted IS NULL |
2199 |
"; |
2200 |
if ($dbdriver eq "mysql") { |
2201 |
$select .= " |
2202 |
aqorders.quantity - COALESCE(aqorders.quantityreceived,0) AS quantity, |
2203 |
(aqorders.quantity - COALESCE(aqorders.quantityreceived,0)) * aqorders.rrp AS subtotal, |
2204 |
DATEDIFF(CAST(now() AS date),closedate) AS latesince |
2205 |
"; |
2206 |
if ( defined $delay ) { |
2207 |
$from .= " AND (closedate <= DATE_SUB(CAST(now() AS date),INTERVAL ? DAY)) " ; |
2208 |
push @query_params, $delay; |
2209 |
} |
2210 |
$from .= " AND aqorders.quantity - COALESCE(aqorders.quantityreceived,0) <> 0"; |
2211 |
} else { |
2212 |
# FIXME: account for IFNULL as above |
2213 |
$select .= " |
2214 |
aqorders.quantity AS quantity, |
2215 |
aqorders.quantity * aqorders.rrp AS subtotal, |
2216 |
(CAST(now() AS date) - closedate) AS latesince |
2217 |
"; |
2218 |
if ( defined $delay ) { |
2219 |
$from .= " AND (closedate <= (CAST(now() AS date) -(INTERVAL ? DAY)) "; |
2220 |
push @query_params, $delay; |
2221 |
} |
2222 |
$from .= " AND aqorders.quantity <> 0"; |
2223 |
} |
2224 |
if (defined $supplierid) { |
2225 |
$from .= ' AND aqbasket.booksellerid = ? '; |
2226 |
push @query_params, $supplierid; |
2227 |
} |
2228 |
if (defined $branch) { |
2229 |
$from .= ' AND borrowers.branchcode LIKE ? '; |
2230 |
push @query_params, $branch; |
2231 |
} |
2232 |
|
2233 |
if ( defined $estimateddeliverydatefrom or defined $estimateddeliverydateto ) { |
2234 |
$from .= ' AND aqbooksellers.deliverytime IS NOT NULL '; |
2235 |
} |
2236 |
if ( defined $estimateddeliverydatefrom ) { |
2237 |
$from .= ' AND ADDDATE(aqbasket.closedate, INTERVAL aqbooksellers.deliverytime DAY) >= ?'; |
2238 |
push @query_params, $estimateddeliverydatefrom; |
2239 |
} |
2240 |
if ( defined $estimateddeliverydateto ) { |
2241 |
$from .= ' AND ADDDATE(aqbasket.closedate, INTERVAL aqbooksellers.deliverytime DAY) <= ?'; |
2242 |
push @query_params, $estimateddeliverydateto; |
2243 |
} |
2244 |
if ( defined $estimateddeliverydatefrom and not defined $estimateddeliverydateto ) { |
2245 |
$from .= ' AND ADDDATE(aqbasket.closedate, INTERVAL aqbooksellers.deliverytime DAY) <= CAST(now() AS date)'; |
2246 |
} |
2247 |
if (C4::Context->preference("IndependentBranches") |
2248 |
&& !C4::Context->IsSuperLibrarian() ) { |
2249 |
$from .= ' AND borrowers.branchcode LIKE ? '; |
2250 |
push @query_params, C4::Context->userenv->{branch}; |
2251 |
} |
2252 |
$from .= " AND orderstatus <> 'cancelled' "; |
2253 |
my $query = "$select $from \nORDER BY latesince, basketno, borrowers.branchcode, supplier"; |
2254 |
$debug and print STDERR "GetLateOrders query: $query\nGetLateOrders args: " . join(" ",@query_params); |
2255 |
my $sth = $dbh->prepare($query); |
2256 |
$sth->execute(@query_params); |
2257 |
my @results; |
2258 |
while (my $data = $sth->fetchrow_hashref) { |
2259 |
push @results, $data; |
2260 |
} |
2261 |
return @results; |
2262 |
} |
2263 |
|
2264 |
#------------------------------------------------------------# |
2265 |
|
2266 |
=head3 GetHistory |
2138 |
=head3 GetHistory |
2267 |
|
2139 |
|
2268 |
\@order_loop = GetHistory( %params ); |
2140 |
\@order_loop = GetHistory( %params ); |
2269 |
- |
|
|