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 2073-2206
sub GetParcels {
Link Here
|
2073 |
|
2073 |
|
2074 |
#------------------------------------------------------------# |
2074 |
#------------------------------------------------------------# |
2075 |
|
2075 |
|
2076 |
=head3 GetLateOrders |
|
|
2077 |
|
2078 |
@results = &GetLateOrders; |
2079 |
|
2080 |
Searches for bookseller with late orders. |
2081 |
|
2082 |
return: |
2083 |
the table of supplier with late issues. This table is full of hashref. |
2084 |
|
2085 |
=cut |
2086 |
|
2087 |
sub GetLateOrders { |
2088 |
my $delay = shift; |
2089 |
my $supplierid = shift; |
2090 |
my $branch = shift; |
2091 |
my $estimateddeliverydatefrom = shift; |
2092 |
my $estimateddeliverydateto = shift; |
2093 |
|
2094 |
my $dbh = C4::Context->dbh; |
2095 |
|
2096 |
#BEWARE, order of parenthesis and LEFT JOIN is important for speed |
2097 |
my $dbdriver = C4::Context->config("db_scheme") || "mysql"; |
2098 |
|
2099 |
my @query_params = (); |
2100 |
my $select = " |
2101 |
SELECT aqbasket.basketno, |
2102 |
aqorders.ordernumber AS ordernumber, |
2103 |
DATE(aqbasket.closedate) AS orderdate, |
2104 |
aqbasket.basketname AS basketname, |
2105 |
aqbasket.basketgroupid AS basketgroupid, |
2106 |
aqbasketgroups.name AS basketgroupname, |
2107 |
aqorders.rrp AS unitpricesupplier, |
2108 |
aqorders.ecost AS unitpricelib, |
2109 |
aqorders.claims_count AS claims_count, |
2110 |
aqorders.claimed_date AS claimed_date, |
2111 |
aqorders.order_internalnote AS internalnote, |
2112 |
aqorders.order_vendornote AS vendornote, |
2113 |
aqbudgets.budget_name AS budget, |
2114 |
borrowers.branchcode AS branch, |
2115 |
aqbooksellers.name AS supplier, |
2116 |
aqbooksellers.id AS supplierid, |
2117 |
biblio.author, biblio.title, |
2118 |
biblioitems.publishercode AS publisher, |
2119 |
biblioitems.publicationyear, |
2120 |
biblioitems.isbn AS isbn, |
2121 |
ADDDATE(aqbasket.closedate, INTERVAL aqbooksellers.deliverytime DAY) AS estimateddeliverydate, |
2122 |
"; |
2123 |
my $from = " |
2124 |
FROM |
2125 |
aqorders LEFT JOIN biblio ON biblio.biblionumber = aqorders.biblionumber |
2126 |
LEFT JOIN biblioitems ON biblioitems.biblionumber = biblio.biblionumber |
2127 |
LEFT JOIN aqbudgets ON aqorders.budget_id = aqbudgets.budget_id, |
2128 |
aqbasket LEFT JOIN borrowers ON aqbasket.authorisedby = borrowers.borrowernumber |
2129 |
LEFT JOIN aqbooksellers ON aqbasket.booksellerid = aqbooksellers.id |
2130 |
LEFT JOIN aqbasketgroups ON aqbasket.basketgroupid = aqbasketgroups.id |
2131 |
WHERE aqorders.basketno = aqbasket.basketno |
2132 |
AND ( datereceived IS NULL |
2133 |
OR aqorders.quantityreceived < aqorders.quantity |
2134 |
) |
2135 |
AND aqbasket.closedate IS NOT NULL |
2136 |
AND aqorders.datecancellationprinted IS NULL |
2137 |
"; |
2138 |
if ($dbdriver eq "mysql") { |
2139 |
$select .= " |
2140 |
aqorders.quantity - COALESCE(aqorders.quantityreceived,0) AS quantity, |
2141 |
(aqorders.quantity - COALESCE(aqorders.quantityreceived,0)) * aqorders.rrp AS subtotal, |
2142 |
DATEDIFF(CAST(now() AS date),closedate) AS latesince |
2143 |
"; |
2144 |
if ( defined $delay ) { |
2145 |
$from .= " AND (closedate <= DATE_SUB(CAST(now() AS date),INTERVAL ? DAY)) " ; |
2146 |
push @query_params, $delay; |
2147 |
} |
2148 |
$from .= " AND aqorders.quantity - COALESCE(aqorders.quantityreceived,0) <> 0"; |
2149 |
} else { |
2150 |
# FIXME: account for IFNULL as above |
2151 |
$select .= " |
2152 |
aqorders.quantity AS quantity, |
2153 |
aqorders.quantity * aqorders.rrp AS subtotal, |
2154 |
(CAST(now() AS date) - closedate) AS latesince |
2155 |
"; |
2156 |
if ( defined $delay ) { |
2157 |
$from .= " AND (closedate <= (CAST(now() AS date) -(INTERVAL ? DAY)) "; |
2158 |
push @query_params, $delay; |
2159 |
} |
2160 |
$from .= " AND aqorders.quantity <> 0"; |
2161 |
} |
2162 |
if (defined $supplierid) { |
2163 |
$from .= ' AND aqbasket.booksellerid = ? '; |
2164 |
push @query_params, $supplierid; |
2165 |
} |
2166 |
if (defined $branch) { |
2167 |
$from .= ' AND borrowers.branchcode LIKE ? '; |
2168 |
push @query_params, $branch; |
2169 |
} |
2170 |
|
2171 |
if ( defined $estimateddeliverydatefrom or defined $estimateddeliverydateto ) { |
2172 |
$from .= ' AND aqbooksellers.deliverytime IS NOT NULL '; |
2173 |
} |
2174 |
if ( defined $estimateddeliverydatefrom ) { |
2175 |
$from .= ' AND ADDDATE(aqbasket.closedate, INTERVAL aqbooksellers.deliverytime DAY) >= ?'; |
2176 |
push @query_params, $estimateddeliverydatefrom; |
2177 |
} |
2178 |
if ( defined $estimateddeliverydateto ) { |
2179 |
$from .= ' AND ADDDATE(aqbasket.closedate, INTERVAL aqbooksellers.deliverytime DAY) <= ?'; |
2180 |
push @query_params, $estimateddeliverydateto; |
2181 |
} |
2182 |
if ( defined $estimateddeliverydatefrom and not defined $estimateddeliverydateto ) { |
2183 |
$from .= ' AND ADDDATE(aqbasket.closedate, INTERVAL aqbooksellers.deliverytime DAY) <= CAST(now() AS date)'; |
2184 |
} |
2185 |
if (C4::Context->preference("IndependentBranches") |
2186 |
&& !C4::Context->IsSuperLibrarian() ) { |
2187 |
$from .= ' AND borrowers.branchcode LIKE ? '; |
2188 |
push @query_params, C4::Context->userenv->{branch}; |
2189 |
} |
2190 |
$from .= " AND orderstatus <> 'cancelled' "; |
2191 |
my $query = "$select $from \nORDER BY latesince, basketno, borrowers.branchcode, supplier"; |
2192 |
$debug and print STDERR "GetLateOrders query: $query\nGetLateOrders args: " . join(" ",@query_params); |
2193 |
my $sth = $dbh->prepare($query); |
2194 |
$sth->execute(@query_params); |
2195 |
my @results; |
2196 |
while (my $data = $sth->fetchrow_hashref) { |
2197 |
push @results, $data; |
2198 |
} |
2199 |
return @results; |
2200 |
} |
2201 |
|
2202 |
#------------------------------------------------------------# |
2203 |
|
2204 |
=head3 GetHistory |
2076 |
=head3 GetHistory |
2205 |
|
2077 |
|
2206 |
\@order_loop = GetHistory( %params ); |
2078 |
\@order_loop = GetHistory( %params ); |
2207 |
- |
|
|