Lines 1473-1485
sub GetLateOrders {
Link Here
|
1473 |
my $delay = shift; |
1473 |
my $delay = shift; |
1474 |
my $supplierid = shift; |
1474 |
my $supplierid = shift; |
1475 |
my $branch = shift; |
1475 |
my $branch = shift; |
|
|
1476 |
my $estimateddeliverydatefrom = shift; |
1477 |
my $estimateddeliverydateto = shift; |
1476 |
|
1478 |
|
1477 |
my $dbh = C4::Context->dbh; |
1479 |
my $dbh = C4::Context->dbh; |
1478 |
|
1480 |
|
1479 |
#BEWARE, order of parenthesis and LEFT JOIN is important for speed |
1481 |
#BEWARE, order of parenthesis and LEFT JOIN is important for speed |
1480 |
my $dbdriver = C4::Context->config("db_scheme") || "mysql"; |
1482 |
my $dbdriver = C4::Context->config("db_scheme") || "mysql"; |
1481 |
|
1483 |
|
1482 |
my @query_params = ($delay); # delay is the first argument regardless |
1484 |
my @query_params = (); |
1483 |
my $select = " |
1485 |
my $select = " |
1484 |
SELECT aqbasket.basketno, |
1486 |
SELECT aqbasket.basketno, |
1485 |
aqorders.ordernumber, |
1487 |
aqorders.ordernumber, |
Lines 1495-1500
sub GetLateOrders {
Link Here
|
1495 |
biblio.author, biblio.title, |
1497 |
biblio.author, biblio.title, |
1496 |
biblioitems.publishercode AS publisher, |
1498 |
biblioitems.publishercode AS publisher, |
1497 |
biblioitems.publicationyear, |
1499 |
biblioitems.publicationyear, |
|
|
1500 |
ADDDATE(aqbasket.closedate, INTERVAL aqbooksellers.deliverytime DAY) AS estimateddeliverydate, |
1498 |
"; |
1501 |
"; |
1499 |
my $from = " |
1502 |
my $from = " |
1500 |
FROM |
1503 |
FROM |
Lines 1508-1513
sub GetLateOrders {
Link Here
|
1508 |
OR datereceived IS NULL |
1511 |
OR datereceived IS NULL |
1509 |
OR aqorders.quantityreceived < aqorders.quantity |
1512 |
OR aqorders.quantityreceived < aqorders.quantity |
1510 |
) |
1513 |
) |
|
|
1514 |
AND aqbasket.closedate IS NOT NULL |
1511 |
AND (aqorders.datecancellationprinted IS NULL OR aqorders.datecancellationprinted='0000-00-00') |
1515 |
AND (aqorders.datecancellationprinted IS NULL OR aqorders.datecancellationprinted='0000-00-00') |
1512 |
"; |
1516 |
"; |
1513 |
my $having = ""; |
1517 |
my $having = ""; |
Lines 1515-1523
sub GetLateOrders {
Link Here
|
1515 |
$select .= " |
1519 |
$select .= " |
1516 |
aqorders.quantity - IFNULL(aqorders.quantityreceived,0) AS quantity, |
1520 |
aqorders.quantity - IFNULL(aqorders.quantityreceived,0) AS quantity, |
1517 |
(aqorders.quantity - IFNULL(aqorders.quantityreceived,0)) * aqorders.rrp AS subtotal, |
1521 |
(aqorders.quantity - IFNULL(aqorders.quantityreceived,0)) * aqorders.rrp AS subtotal, |
1518 |
DATEDIFF(CURDATE( ),closedate) AS latesince |
1522 |
DATEDIFF(CAST(now() AS date),closedate) AS latesince |
1519 |
"; |
1523 |
"; |
1520 |
$from .= " AND (closedate <= DATE_SUB(CURDATE( ),INTERVAL ? DAY)) "; |
1524 |
if ( defined $delay ) { |
|
|
1525 |
$from .= " AND (closedate <= DATE_SUB(CAST(now() AS date),INTERVAL ? DAY)) " ; |
1526 |
push @query_params, $delay; |
1527 |
} |
1521 |
$having = " |
1528 |
$having = " |
1522 |
HAVING quantity <> 0 |
1529 |
HAVING quantity <> 0 |
1523 |
AND unitpricesupplier <> 0 |
1530 |
AND unitpricesupplier <> 0 |
Lines 1528-1536
sub GetLateOrders {
Link Here
|
1528 |
$select .= " |
1535 |
$select .= " |
1529 |
aqorders.quantity AS quantity, |
1536 |
aqorders.quantity AS quantity, |
1530 |
aqorders.quantity * aqorders.rrp AS subtotal, |
1537 |
aqorders.quantity * aqorders.rrp AS subtotal, |
1531 |
(CURDATE - closedate) AS latesince |
1538 |
(CAST(now() AS date) - closedate) AS latesince |
1532 |
"; |
1539 |
"; |
1533 |
$from .= " AND (closedate <= (CURDATE -(INTERVAL ? DAY)) "; |
1540 |
if ( defined $delay ) { |
|
|
1541 |
$from .= " AND (closedate <= (CAST(now() AS date) -(INTERVAL ? DAY)) "; |
1542 |
push @query_params, $delay; |
1543 |
} |
1534 |
} |
1544 |
} |
1535 |
if (defined $supplierid) { |
1545 |
if (defined $supplierid) { |
1536 |
$from .= ' AND aqbasket.booksellerid = ? '; |
1546 |
$from .= ' AND aqbasket.booksellerid = ? '; |
Lines 1540-1545
sub GetLateOrders {
Link Here
|
1540 |
$from .= ' AND borrowers.branchcode LIKE ? '; |
1550 |
$from .= ' AND borrowers.branchcode LIKE ? '; |
1541 |
push @query_params, $branch; |
1551 |
push @query_params, $branch; |
1542 |
} |
1552 |
} |
|
|
1553 |
if ( defined $estimateddeliverydatefrom ) { |
1554 |
$from .= ' |
1555 |
AND aqbooksellers.deliverytime IS NOT NULL |
1556 |
AND ADDDATE(aqbasket.closedate, INTERVAL aqbooksellers.deliverytime DAY) >= ?'; |
1557 |
push @query_params, $estimateddeliverydatefrom; |
1558 |
} |
1559 |
if ( defined $estimateddeliverydatefrom and defined $estimateddeliverydateto ) { |
1560 |
$from .= ' AND ADDDATE(aqbasket.closedate, INTERVAL aqbooksellers.deliverytime DAY) <= ?'; |
1561 |
push @query_params, $estimateddeliverydateto; |
1562 |
} elsif ( defined $estimateddeliverydatefrom ) { |
1563 |
$from .= ' AND ADDDATE(aqbasket.closedate, INTERVAL aqbooksellers.deliverytime DAY) <= CAST(now() AS date)'; |
1564 |
} |
1543 |
if (C4::Context->preference("IndependantBranches") |
1565 |
if (C4::Context->preference("IndependantBranches") |
1544 |
&& C4::Context->userenv |
1566 |
&& C4::Context->userenv |
1545 |
&& C4::Context->userenv->{flags} != 1 ) { |
1567 |
&& C4::Context->userenv->{flags} != 1 ) { |