View | Details | Raw Unified | Return to bug 5063
Collapse All | Expand All

(-)a/C4/Bookseller.pm (-105 / +67 lines)
Lines 1-6 Link Here
1
package C4::Bookseller;
1
package C4::Bookseller;
2
2
3
# Copyright 2000-2002 Katipo Communications
3
# Copyright 2000-2002 Katipo Communications
4
# Copyright 2010 PTFS Europe
4
#
5
#
5
# This file is part of Koha.
6
# This file is part of Koha.
6
#
7
#
Lines 18-40 package C4::Bookseller; Link Here
18
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
20
20
use strict;
21
use strict;
21
#use warnings; FIXME - Bug 2505
22
use warnings;
22
23
23
use vars qw($VERSION @ISA @EXPORT);
24
use base qw( Exporter );
24
25
BEGIN {
26
	# set the version for version checking
27
	$VERSION = 3.01;
28
    require Exporter;
29
	@ISA    = qw(Exporter);
30
	@EXPORT = qw(
31
		&GetBookSeller &GetBooksellersWithLateOrders &GetBookSellerFromId
32
		&ModBookseller
33
		&DelBookseller
34
		&AddBookseller
35
	);
36
}
37
25
26
# set the version for version checking
27
our $VERSION   = 4.01;
28
our @EXPORT_OK = qw(
29
  GetBookSeller GetBooksellersWithLateOrders GetBookSellerFromId
30
  ModBookseller
31
  DelBookseller
32
  AddBookseller
33
);
38
34
39
=head1 NAME
35
=head1 NAME
40
36
Lines 54-145 a bookseller. Link Here
54
50
55
=head2 GetBookSeller
51
=head2 GetBookSeller
56
52
57
@results = &GetBookSeller($searchstring);
53
@results = GetBookSeller($searchstring);
58
54
59
Looks up a book seller. C<$searchstring> may be either a book seller
55
Looks up a book seller. C<$searchstring> may be either a book seller
60
ID, or a string to look for in the book seller's name.
56
ID, or a string to look for in the book seller's name.
61
57
62
C<@results> is an array of references-to-hash, whose keys are the fields of of the
58
C<@results> is an array of hash_refs whose keys are the fields of of the
63
aqbooksellers table in the Koha database.
59
aqbooksellers table in the Koha database.
64
60
65
=cut
61
=cut
66
62
67
# FIXME: This function is badly named.  It should be something like 
63
sub GetBookSeller {
68
# SearchBookSellersByName.  It is NOT a singular return value.
64
    my $searchstring = shift;
65
    $searchstring = q{%} . $searchstring . q{%};
66
    my $query =
67
'select aqbooksellers.*, count(*) as basketcount from aqbooksellers left join aqbasket '
68
      . 'on aqbasket.booksellerid = aqbooksellers.id where name lIke ? group by aqbooksellers.id order by name';
69
70
    my $dbh           = C4::Context->dbh;
71
    my $sth           = $dbh->prepare($query);
72
    $sth->execute($searchstring);
73
    my $resultset_ref = $sth->fetchall_arrayref( {} );
74
    return @{$resultset_ref};
75
}
69
76
70
sub GetBookSeller($) {
77
sub GetBookSellerFromId {
71
    my ($searchstring) = @_;
78
    my $id = shift or return;
72
    my $dbh = C4::Context->dbh;
79
    my $dbh = C4::Context->dbh;
73
    my $query = "SELECT * FROM aqbooksellers WHERE name LIKE ?";
80
    my $vendor =
74
    my $sth =$dbh->prepare($query);
81
      $dbh->selectrow_hashref( 'SELECT * FROM aqbooksellers WHERE id = ?',
75
    $sth->execute( "%$searchstring%" );
82
        {}, $id );
76
    my @results;
83
    if ($vendor) {
77
    # count how many baskets this bookseller has.
84
        ( $vendor->{basketcount} ) = $dbh->selectrow_array(
78
    # if it has none, the bookseller can be deleted
85
            'SELECT count(*) FROM aqbasket where booksellerid = ?',
79
    my $sth2 = $dbh->prepare("SELECT count(*) FROM aqbasket WHERE booksellerid=?");
86
            {}, $id );
80
    while ( my $data = $sth->fetchrow_hashref ) {
81
        $sth2->execute($data->{id});
82
        $data->{basketcount} = $sth2->fetchrow();
83
        push( @results, $data );
84
    }
87
    }
85
    $sth->finish;
88
    return $vendor;
86
    return  @results ;
87
}
89
}
88
90
89
90
sub GetBookSellerFromId($) {
91
	my $id = shift or return;
92
	my $dbh = C4::Context->dbh();
93
	my $query = "SELECT * FROM aqbooksellers WHERE id = ?";
94
	my $sth =$dbh->prepare($query);
95
	$sth->execute( $id );
96
	if (my $data = $sth->fetchrow_hashref()){
97
		my $sth2 = $dbh->prepare("SELECT count(*) FROM aqbasket WHERE booksellerid=?");
98
		$sth2->execute($id);
99
		$data->{basketcount}=$sth2->fetchrow();
100
		return $data;
101
	}
102
	return;
103
}
104
#-----------------------------------------------------------------#
91
#-----------------------------------------------------------------#
105
92
106
=head2 GetBooksellersWithLateOrders
93
=head2 GetBooksellersWithLateOrders
107
94
108
%results = &GetBooksellersWithLateOrders;
95
%results = GetBooksellersWithLateOrders($delay);
109
96
110
Searches for suppliers with late orders.
97
Searches for suppliers with late orders.
111
98
112
=cut
99
=cut
113
100
114
sub GetBooksellersWithLateOrders {
101
sub GetBooksellersWithLateOrders {
115
    my ($delay,$branch) = @_; 	# FIXME: Branch argument unused.
102
    my $delay = shift;
116
    my $dbh   = C4::Context->dbh;
103
    my $dbh   = C4::Context->dbh;
117
104
118
# FIXME NOT quite sure that this operation is valid for DBMs different from Mysql, HOPING so
105
    # TODO delay should be verified
119
# should be tested with other DBMs
106
    my $query_string =
120
107
      "SELECT DISTINCT aqbasket.booksellerid, aqbooksellers.name
121
    my $strsth;
108
    FROM aqorders LEFT JOIN aqbasket ON aqorders.basketno=aqbasket.basketno
122
    my $dbdriver = C4::Context->config("db_scheme") || "mysql";
109
    LEFT JOIN aqbooksellers ON aqbasket.booksellerid = aqbooksellers.id
123
    if ( $dbdriver eq "mysql" ) {
110
    WHERE (closedate < DATE_SUB(CURDATE( ),INTERVAL $delay DAY)
124
        $strsth = "
111
    AND (datereceived = '' OR datereceived IS NULL))";
125
            SELECT DISTINCT aqbasket.booksellerid, aqbooksellers.name
126
            FROM aqorders LEFT JOIN aqbasket ON aqorders.basketno=aqbasket.basketno
127
            LEFT JOIN aqbooksellers ON aqbasket.booksellerid = aqbooksellers.id
128
            WHERE (closedate < DATE_SUB(CURDATE( ),INTERVAL $delay DAY)
129
                AND (datereceived = '' OR datereceived IS NULL))
130
        ";
131
    }
132
    else {
133
        $strsth = "
134
            SELECT DISTINCT aqbasket.booksellerid, aqbooksellers.name
135
            FROM aqorders LEFT JOIN aqbasket ON aqorders.basketno=aqbasket.basketno
136
            LEFT JOIN aqbooksellers ON aqbasket.aqbooksellerid = aqbooksellers.id
137
            WHERE (closedate < (CURDATE( )-(INTERVAL $delay DAY)))
138
                AND (datereceived = '' OR datereceived IS NULL))
139
        ";
140
    }
141
112
142
    my $sth = $dbh->prepare($strsth);
113
    my $sth = $dbh->prepare($query_string);
143
    $sth->execute;
114
    $sth->execute;
144
    my %supplierlist;
115
    my %supplierlist;
145
    while ( my ( $id, $name ) = $sth->fetchrow ) {
116
    while ( my ( $id, $name ) = $sth->fetchrow ) {
Lines 165-172 Returns the ID of the newly-created bookseller. Link Here
165
136
166
sub AddBookseller {
137
sub AddBookseller {
167
    my ($data) = @_;
138
    my ($data) = @_;
168
    my $dbh = C4::Context->dbh;
139
    my $dbh    = C4::Context->dbh;
169
    my $query = "
140
    my $query  = q|
170
        INSERT INTO aqbooksellers
141
        INSERT INTO aqbooksellers
171
            (
142
            (
172
                name,      address1,      address2,   address3,      address4,
143
                name,      address1,      address2,   address3,      address4,
Lines 176-183 sub AddBookseller { Link Here
176
                listincgst,invoiceincgst, gstrate,    discount,
147
                listincgst,invoiceincgst, gstrate,    discount,
177
                notes
148
                notes
178
            )
149
            )
179
        VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)
150
        VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?) |
180
    ";
151
      ;
181
    my $sth = $dbh->prepare($query);
152
    my $sth = $dbh->prepare($query);
182
    $sth->execute(
153
    $sth->execute(
183
        $data->{'name'},         $data->{'address1'},
154
        $data->{'name'},         $data->{'address1'},
Lines 196-216 sub AddBookseller { Link Here
196
    );
167
    );
197
168
198
    # return the id of this new supplier
169
    # return the id of this new supplier
199
    # FIXME: no protection against simultaneous addition: max(id) might be wrong!
170
    return $dbh->{'mysql_insertid'};
200
    $query = "
201
        SELECT max(id)
202
        FROM   aqbooksellers
203
    ";
204
    $sth = $dbh->prepare($query);
205
    $sth->execute;
206
    return scalar($sth->fetchrow);
207
}
171
}
208
172
209
#-----------------------------------------------------------------#
173
#-----------------------------------------------------------------#
210
174
211
=head2 ModBookseller
175
=head2 ModBookseller
212
176
213
&ModBookseller($bookseller);
177
ModBookseller($bookseller);
214
178
215
Updates the information for a given bookseller. C<$bookseller> is a
179
Updates the information for a given bookseller. C<$bookseller> is a
216
reference-to-hash whose keys are the fields of the aqbooksellers table
180
reference-to-hash whose keys are the fields of the aqbooksellers table
Lines 226-242 C<&ModBookseller> with the result. Link Here
226
sub ModBookseller {
190
sub ModBookseller {
227
    my ($data) = @_;
191
    my ($data) = @_;
228
    my $dbh    = C4::Context->dbh;
192
    my $dbh    = C4::Context->dbh;
229
    my $query = "
193
    my $query  = 'UPDATE aqbooksellers
230
        UPDATE aqbooksellers
231
        SET name=?,address1=?,address2=?,address3=?,address4=?,
194
        SET name=?,address1=?,address2=?,address3=?,address4=?,
232
            postal=?,phone=?,fax=?,url=?,contact=?,contpos=?,
195
            postal=?,phone=?,fax=?,url=?,contact=?,contpos=?,
233
            contphone=?,contfax=?,contaltphone=?,contemail=?,
196
            contphone=?,contfax=?,contaltphone=?,contemail=?,
234
            contnotes=?,active=?,listprice=?, invoiceprice=?,
197
            contnotes=?,active=?,listprice=?, invoiceprice=?,
235
            gstreg=?,listincgst=?,invoiceincgst=?,
198
            gstreg=?,listincgst=?,invoiceincgst=?,
236
            discount=?, notes=?, gstrate=?
199
            discount=?,notes=?,gstrate=?
237
        WHERE id=?
200
        WHERE id=?';
238
    ";
201
    my $sth = $dbh->prepare($query);
239
    my $sth    = $dbh->prepare($query);
240
    $sth->execute(
202
    $sth->execute(
241
        $data->{'name'},         $data->{'address1'},
203
        $data->{'name'},         $data->{'address1'},
242
        $data->{'address2'},     $data->{'address3'},
204
        $data->{'address2'},     $data->{'address3'},
Lines 249-275 sub ModBookseller { Link Here
249
        $data->{'active'},       $data->{'listprice'},
211
        $data->{'active'},       $data->{'listprice'},
250
        $data->{'invoiceprice'}, $data->{'gstreg'},
212
        $data->{'invoiceprice'}, $data->{'gstreg'},
251
        $data->{'listincgst'},   $data->{'invoiceincgst'},
213
        $data->{'listincgst'},   $data->{'invoiceincgst'},
252
        $data->{'discount'},
214
        $data->{'discount'},     $data->{'notes'},
253
        $data->{'notes'},        $data->{'gstrate'},
215
        $data->{'gstrate'},      $data->{'id'}
254
        $data->{'id'}
255
    );
216
    );
256
    $sth->finish;
217
    return;
257
}
218
}
258
219
259
=head2 DelBookseller
220
=head2 DelBookseller
260
221
261
&DelBookseller($booksellerid);
222
DelBookseller($booksellerid);
262
223
263
delete the supplier identified by $booksellerid
224
delete the supplier record identified by $booksellerid
264
This sub can be called only if the supplier has no order.
225
This sub assumes it is called only if the supplier has no order.
265
226
266
=cut
227
=cut
267
228
268
sub DelBookseller {
229
sub DelBookseller {
269
    my ($id) = @_;
230
    my $id  = shift;
270
    my $dbh=C4::Context->dbh;
231
    my $dbh = C4::Context->dbh;
271
    my $sth=$dbh->prepare("DELETE FROM aqbooksellers WHERE id=?");
232
    my $sth = $dbh->prepare('DELETE FROM aqbooksellers WHERE id=?');
272
    $sth->execute($id);
233
    $sth->execute($id);
234
    return;
273
}
235
}
274
236
275
1;
237
1;
(-)a/acqui/basket.pl (-1 / +1 lines)
Lines 29-35 use CGI; Link Here
29
use C4::Acquisition;
29
use C4::Acquisition;
30
use C4::Budgets;
30
use C4::Budgets;
31
31
32
use C4::Bookseller;
32
use C4::Bookseller qw( GetBookSellerFromId);
33
use C4::Dates qw/format_date/;
33
use C4::Dates qw/format_date/;
34
use C4::Debug;
34
use C4::Debug;
35
35
(-)a/acqui/booksellers.pl (-1 / +1 lines)
Lines 62-68 use CGI; Link Here
62
62
63
use C4::Acquisition;
63
use C4::Acquisition;
64
use C4::Dates qw/format_date/;
64
use C4::Dates qw/format_date/;
65
use C4::Bookseller;
65
use C4::Bookseller qw/ GetBookSellerFromId GetBookSeller /;
66
use C4::Members qw/GetMember/;
66
use C4::Members qw/GetMember/;
67
67
68
my $query = new CGI;
68
my $query = new CGI;
(-)a/acqui/lateorders.pl (-2 / +2 lines)
Lines 45-51 To know on which branch this script have to display late order. Link Here
45
use strict;
45
use strict;
46
use warnings;
46
use warnings;
47
use CGI;
47
use CGI;
48
use C4::Bookseller;
48
use C4::Bookseller qw( GetBooksellersWithLateOrders );
49
use C4::Auth;
49
use C4::Auth;
50
use C4::Koha;
50
use C4::Koha;
51
use C4::Output;
51
use C4::Output;
Lines 76-82 unless ($delay =~ /^\d{1,3}$/) { Link Here
76
	$delay = 30;	#default value for delay
76
	$delay = 30;	#default value for delay
77
}
77
}
78
78
79
my %supplierlist = GetBooksellersWithLateOrders($delay,$branch);
79
my %supplierlist = GetBooksellersWithLateOrders($delay);
80
my (@sloopy);	# supplier loop
80
my (@sloopy);	# supplier loop
81
foreach (keys %supplierlist){
81
foreach (keys %supplierlist){
82
	push @sloopy, (($supplierid and $supplierid eq $_ )            ? 
82
	push @sloopy, (($supplierid and $supplierid eq $_ )            ? 
(-)a/acqui/neworderbiblio.pl (-1 / +1 lines)
Lines 60-66 use strict; Link Here
60
60
61
use C4::Search;
61
use C4::Search;
62
use CGI;
62
use CGI;
63
use C4::Bookseller;
63
use C4::Bookseller qw/ GetBookSellerFromId /;
64
use C4::Biblio;
64
use C4::Biblio;
65
use C4::Auth;
65
use C4::Auth;
66
use C4::Output;
66
use C4::Output;
(-)a/acqui/neworderempty.pl (-1 / +1 lines)
Lines 77-83 use C4::Budgets; Link Here
77
use C4::Input;
77
use C4::Input;
78
use C4::Dates;
78
use C4::Dates;
79
79
80
use C4::Bookseller;		# GetBookSellerFromId
80
use C4::Bookseller  qw/ GetBookSellerFromId /;
81
use C4::Acquisition;
81
use C4::Acquisition;
82
use C4::Suggestions;	# GetSuggestion
82
use C4::Suggestions;	# GetSuggestion
83
use C4::Biblio;			# GetBiblioData
83
use C4::Biblio;			# GetBiblioData
(-)a/acqui/newordersuggestion.pl (-1 / +1 lines)
Lines 93-99 use CGI; Link Here
93
use C4::Auth;    # get_template_and_user
93
use C4::Auth;    # get_template_and_user
94
use C4::Output;
94
use C4::Output;
95
use C4::Suggestions;
95
use C4::Suggestions;
96
use C4::Bookseller;
96
use C4::Bookseller qw/ GetBookSellerFromId /;
97
use C4::Biblio;
97
use C4::Biblio;
98
98
99
my $input = new CGI;
99
my $input = new CGI;
(-)a/acqui/orderreceive.pl (-1 / +1 lines)
Lines 69-75 use C4::Acquisition; Link Here
69
use C4::Auth;
69
use C4::Auth;
70
use C4::Output;
70
use C4::Output;
71
use C4::Dates qw/format_date/;
71
use C4::Dates qw/format_date/;
72
use C4::Bookseller;
72
use C4::Bookseller qw/ GetBookSellerFromId /;
73
use C4::Members;
73
use C4::Members;
74
use C4::Branch;    # GetBranches
74
use C4::Branch;    # GetBranches
75
use C4::Items;
75
use C4::Items;
(-)a/acqui/parcel.pl (-1 / +1 lines)
Lines 61-67 use strict; Link Here
61
use C4::Auth;
61
use C4::Auth;
62
use C4::Acquisition;
62
use C4::Acquisition;
63
use C4::Budgets;
63
use C4::Budgets;
64
use C4::Bookseller;
64
use C4::Bookseller qw/ GetBookSellerFromId /;
65
use C4::Biblio;
65
use C4::Biblio;
66
use C4::Items;
66
use C4::Items;
67
use CGI;
67
use CGI;
(-)a/acqui/parcels.pl (-1 / +1 lines)
Lines 74-80 use C4::Output; Link Here
74
74
75
use C4::Dates qw/format_date/;
75
use C4::Dates qw/format_date/;
76
use C4::Acquisition;
76
use C4::Acquisition;
77
use C4::Bookseller;
77
use C4::Bookseller qw/ GetBookSellerFromId /;
78
78
79
my $input          = CGI->new;
79
my $input          = CGI->new;
80
my $supplierid     = $input->param('supplierid');
80
my $supplierid     = $input->param('supplierid');
(-)a/acqui/supplier.pl (-1 / +1 lines)
Lines 49-55 use C4::Output; Link Here
49
use C4::Dates qw/format_date /;
49
use C4::Dates qw/format_date /;
50
use CGI;
50
use CGI;
51
51
52
use C4::Bookseller;
52
use C4::Bookseller qw( GetBookSellerFromId DelBookseller );
53
use C4::Budgets;
53
use C4::Budgets;
54
54
55
my $query    = CGI->new;
55
my $query    = CGI->new;
(-)a/acqui/updatesupplier.pl (-1 / +2 lines)
Lines 48-54 use strict; Link Here
48
#use warnings; FIXME - Bug 2505
48
#use warnings; FIXME - Bug 2505
49
use C4::Context;
49
use C4::Context;
50
use C4::Auth;
50
use C4::Auth;
51
use C4::Bookseller;
51
52
use C4::Bookseller qw( ModBookseller AddBookseller );
52
use C4::Biblio;
53
use C4::Biblio;
53
use C4::Output;
54
use C4::Output;
54
use CGI;
55
use CGI;
(-)a/serials/acqui-search-result.pl (-1 / +1 lines)
Lines 47-53 use C4::Output; Link Here
47
use CGI;
47
use CGI;
48
use C4::Acquisition;
48
use C4::Acquisition;
49
use C4::Dates qw/format_date/;
49
use C4::Dates qw/format_date/;
50
use C4::Bookseller;
50
use C4::Bookseller qw( GetBookSeller );
51
51
52
my $query=new CGI;
52
my $query=new CGI;
53
my ($template, $loggedinuser, $cookie)
53
my ($template, $loggedinuser, $cookie)
(-)a/serials/claims.pl (-1 / +1 lines)
Lines 24-30 use C4::Auth; Link Here
24
use C4::Serials;
24
use C4::Serials;
25
use C4::Acquisition;
25
use C4::Acquisition;
26
use C4::Output;
26
use C4::Output;
27
use C4::Bookseller;
27
use C4::Bookseller qw( GetBookSeller );
28
use C4::Context;
28
use C4::Context;
29
use C4::Letters;
29
use C4::Letters;
30
use C4::Branch;    # GetBranches GetBranchesLoop
30
use C4::Branch;    # GetBranches GetBranchesLoop
(-)a/t/db_dependent/Acquisition.t (-1 / +1 lines)
Lines 7-13 use strict; Link Here
7
use warnings;
7
use warnings;
8
use Data::Dumper;
8
use Data::Dumper;
9
9
10
use C4::Bookseller;
10
use C4::Bookseller qw( GetBookSellerFromId );
11
11
12
use Test::More tests => 37;
12
use Test::More tests => 37;
13
13
(-)a/t/db_dependent/lib/KohaTest.pm (-2 / +1 lines)
Lines 10-16 plan skip_all => "Test::Class required for performing database tests" if $@; Link Here
10
10
11
use C4::Auth;
11
use C4::Auth;
12
use C4::Biblio;
12
use C4::Biblio;
13
use C4::Bookseller;
13
use C4::Bookseller qw( AddBookseller );
14
use C4::Context;
14
use C4::Context;
15
use C4::Items;
15
use C4::Items;
16
use C4::Members;
16
use C4::Members;
17
- 

Return to bug 5063