forked from Koha-Community/Koha
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Bookseller.pm
117 lines (92 loc) · 3.7 KB
/
Bookseller.pm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
package C4::Bookseller;
# Copyright 2000-2002 Katipo Communications
# Copyright 2010 PTFS Europe
#
# This file is part of Koha.
#
# Koha is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# Koha is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Koha; if not, see <http://www.gnu.org/licenses>.
use strict;
use warnings;
use base qw( Exporter );
our @EXPORT_OK = qw(
GetBooksellersWithLateOrders
);
=head1 NAME
C4::Bookseller - Koha functions for dealing with booksellers.
=head1 SYNOPSIS
use C4::Bookseller;
=head1 DESCRIPTION
The functions in this module deal with booksellers. They allow to
add a new bookseller, to modify it or to get some informations around
a bookseller.
=head1 FUNCTIONS
=head2 GetBooksellersWithLateOrders
%results = GetBooksellersWithLateOrders( $delay, $estimateddeliverydatefrom, $estimateddeliverydateto );
Searches for suppliers with late orders.
=cut
sub GetBooksellersWithLateOrders {
my ( $delay, $estimateddeliverydatefrom, $estimateddeliverydateto ) = @_;
my $dbh = C4::Context->dbh;
# FIXME NOT quite sure that this operation is valid for DBMs different from Mysql, HOPING so
# should be tested with other DBMs
my $query;
my @query_params = ();
my $dbdriver = C4::Context->config("db_scheme") || "mysql";
$query = "
SELECT DISTINCT aqbasket.booksellerid, aqbooksellers.name
FROM aqorders LEFT JOIN aqbasket ON aqorders.basketno=aqbasket.basketno
LEFT JOIN aqbooksellers ON aqbasket.booksellerid = aqbooksellers.id
WHERE
( datereceived = ''
OR datereceived IS NULL
OR aqorders.quantityreceived < aqorders.quantity
)
AND aqorders.quantity - COALESCE(aqorders.quantityreceived,0) <> 0
AND aqbasket.closedate IS NOT NULL
";
if ( defined $delay && $delay >= 0 ) {
$query .= " AND (closedate <= DATE_SUB(CAST(now() AS date),INTERVAL ? + COALESCE(aqbooksellers.deliverytime,0) DAY)) ";
push @query_params, $delay;
} elsif ( $delay && $delay < 0 ){
warn 'WARNING: GetBooksellerWithLateOrders is called with a negative value';
return;
}
if ( defined $estimateddeliverydatefrom ) {
$query .= '
AND ADDDATE(aqbasket.closedate, INTERVAL COALESCE(aqbooksellers.deliverytime,0) DAY) >= ?';
push @query_params, $estimateddeliverydatefrom;
if ( defined $estimateddeliverydateto ) {
$query .= ' AND ADDDATE(aqbasket.closedate, INTERVAL COALESCE(aqbooksellers.deliverytime, 0) DAY) <= ?';
push @query_params, $estimateddeliverydateto;
} else {
$query .= ' AND ADDDATE(aqbasket.closedate, INTERVAL COALESCE(aqbooksellers.deliverytime, 0) DAY) <= CAST(now() AS date)';
}
}
if ( defined $estimateddeliverydateto ) {
$query .= ' AND ADDDATE(aqbasket.closedate, INTERVAL COALESCE(aqbooksellers.deliverytime,0) DAY) <= ?';
push @query_params, $estimateddeliverydateto;
}
my $sth = $dbh->prepare($query);
$sth->execute( @query_params );
my %supplierlist;
while ( my ( $id, $name ) = $sth->fetchrow ) {
$supplierlist{$id} = $name;
}
return %supplierlist;
}
1;
__END__
=head1 AUTHOR
Koha Development Team <http://koha-community.org/>
=cut