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