X-Git-Url: http://git.rot13.org/?a=blobdiff_plain;f=C4%2FBookseller.pm;h=dff325ef1f1b8700c967491e5be2c55ae342e94d;hb=7d71d9507202ff667776bf9cb6de0bf2603ad0dd;hp=3b1e58f5633fb45a22d4ef3d3a15d98393f13476;hpb=469f36d38fe3ea82013d40b95892dfb7605b4e5f;p=koha.git diff --git a/C4/Bookseller.pm b/C4/Bookseller.pm index 3b1e58f563..dff325ef1f 100644 --- a/C4/Bookseller.pm +++ b/C4/Bookseller.pm @@ -5,33 +5,26 @@ package C4::Bookseller; # # 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 2 of the License, or (at your option) any later -# version. +# 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. +# 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, write to the Free Software Foundation, Inc., -# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +# You should have received a copy of the GNU General Public License +# along with Koha; if not, see . use strict; use warnings; use base qw( Exporter ); -use C4::Bookseller::Contact; - -# set the version for version checking -our $VERSION = 3.07.00.049; our @EXPORT_OK = qw( GetBooksellersWithLateOrders - ModBookseller - DelBookseller - AddBookseller ); =head1 NAME @@ -77,8 +70,6 @@ sub GetBooksellersWithLateOrders { OR datereceived IS NULL OR aqorders.quantityreceived < aqorders.quantity ) - AND aqorders.rrp <> 0 - AND aqorders.ecost <> 0 AND aqorders.quantity - COALESCE(aqorders.quantityreceived,0) <> 0 AND aqbasket.closedate IS NOT NULL "; @@ -115,139 +106,6 @@ sub GetBooksellersWithLateOrders { return %supplierlist; } -#--------------------------------------------------------------------# - -=head2 AddBookseller - -$id = &AddBookseller($bookseller); - -Creates a new bookseller. C<$bookseller> is a reference-to-hash whose -keys are the fields of the aqbooksellers table in the Koha database. -All fields must be present. - -Returns the ID of the newly-created bookseller. - -=cut - -sub AddBookseller { - my ($data, $contacts) = @_; - my $dbh = C4::Context->dbh; - my $query = q| - INSERT INTO aqbooksellers - ( - name, address1, address2, address3, address4, - postal, phone, accountnumber,fax, url, - active, listprice, invoiceprice, gstreg, - listincgst,invoiceincgst, gstrate, discount, notes, - deliverytime - ) - VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?) | - ; - my $sth = $dbh->prepare($query); - $sth->execute( - $data->{'name'}, $data->{'address1'}, - $data->{'address2'}, $data->{'address3'}, - $data->{'address4'}, $data->{'postal'}, - $data->{'phone'}, $data->{'accountnumber'}, - $data->{'fax'}, $data->{'url'}, - $data->{'active'}, $data->{'listprice'}, - $data->{'invoiceprice'}, $data->{'gstreg'}, - $data->{'listincgst'}, $data->{'invoiceincgst'}, - $data->{'gstrate'}, $data->{'discount'}, - $data->{notes}, $data->{deliverytime}, - ); - - # return the id of this new supplier - my $id = $dbh->{'mysql_insertid'}; - if ($id && $contacts) { - foreach my $contact (@$contacts) { - $contact = C4::Bookseller::Contact->new( $contact ) - unless ref $contacts eq 'C4::Bookseller::Contact'; - $contact->bookseller($id); - $contact->save(); - } - } - return $id; -} - -#-----------------------------------------------------------------# - -=head2 ModBookseller - -ModBookseller($bookseller); - -Updates the information for a given bookseller. C<$bookseller> is a -reference-to-hash whose keys are the fields of the aqbooksellers table -in the Koha database. It must contain entries for all of the fields. -The entry to modify is determined by C<$bookseller-E{id}>. - -The easiest way to get all of the necessary fields is to look up a -book seller with C, modify what's necessary, then call -C<&ModBookseller> with the result. - -=cut - -sub ModBookseller { - my ($data, $contacts) = @_; - my $dbh = C4::Context->dbh; - return unless $data->{'id'}; - my $query = 'UPDATE aqbooksellers - SET name=?,address1=?,address2=?,address3=?,address4=?, - postal=?,phone=?,accountnumber=?,fax=?,url=?, - active=?,listprice=?, invoiceprice=?, - gstreg=?,listincgst=?,invoiceincgst=?, - discount=?,notes=?,gstrate=?,deliverytime=? - WHERE id=?'; - my $sth = $dbh->prepare($query); - my $cnt = $sth->execute( - $data->{'name'}, $data->{'address1'}, - $data->{'address2'}, $data->{'address3'}, - $data->{'address4'}, $data->{'postal'}, - $data->{'phone'}, $data->{'accountnumber'}, - $data->{'fax'}, $data->{'url'}, - $data->{'active'}, $data->{'listprice'}, - $data->{'invoiceprice'}, $data->{'gstreg'}, - $data->{'listincgst'}, $data->{'invoiceincgst'}, - $data->{'discount'}, $data->{'notes'}, - $data->{'gstrate'}, $data->{deliverytime}, - $data->{'id'} - ); - $contacts ||= $data->{'contacts'}; - my $contactquery = "DELETE FROM aqcontacts WHERE booksellerid = ?"; - my @contactparams = ($data->{'id'}); - if ($contacts) { - foreach my $contact (@$contacts) { - $contact = C4::Bookseller::Contact->new( $contact ) - unless ref $contacts eq 'C4::Bookseller::Contact'; - $contact->bookseller($data->{'id'}); - $contact->save(); - push @contactparams, $contact->id if $contact->id; - } - if ($#contactparams > 0) { - $contactquery .= ' AND id NOT IN (' . ('?, ' x ($#contactparams - 1)) . '?);'; - } - } - $sth = $dbh->prepare($contactquery); - $sth->execute(@contactparams); - return $cnt; -} - -=head2 DelBookseller - -DelBookseller($booksellerid); - -delete the supplier record identified by $booksellerid -This sub assumes it is called only if the supplier has no order. - -=cut - -sub DelBookseller { - my $id = shift; - my $dbh = C4::Context->dbh; - my $sth = $dbh->prepare('DELETE FROM aqbooksellers WHERE id=?'); - return $sth->execute($id); -} - 1; __END__