X-Git-Url: http://git.rot13.org/?a=blobdiff_plain;f=C4%2FBookseller.pm;h=2471380c9f0ba740d9fea89ecc7edc927b313188;hb=b95c3134a8a38ba430f7d70173f91e055b4fa30e;hp=4ad42cb6f24b05d3a7df29b5b96dee6c00e7b2f7;hpb=ef8171ba425f766b67d9e139194b6a8d570e301e;p=koha.git diff --git a/C4/Bookseller.pm b/C4/Bookseller.pm index 4ad42cb6f2..2471380c9f 100644 --- a/C4/Bookseller.pm +++ b/C4/Bookseller.pm @@ -24,7 +24,7 @@ use warnings; use base qw( Exporter ); # set the version for version checking -our $VERSION = 4.01; +our $VERSION = 3.07.00.049; our @EXPORT_OK = qw( GetBookSeller GetBooksellersWithLateOrders GetBookSellerFromId ModBookseller @@ -63,9 +63,12 @@ aqbooksellers table in the Koha database. sub GetBookSeller { my $searchstring = shift; $searchstring = q{%} . $searchstring . q{%}; - my $query = -'select aqbooksellers.*, count(*) as basketcount from aqbooksellers left join aqbasket ' - . 'on aqbasket.booksellerid = aqbooksellers.id where name lIke ? group by aqbooksellers.id order by name'; + my $query = " + SELECT aqbooksellers.*, count(*) AS basketcount + FROM aqbooksellers + LEFT JOIN aqbasket ON aqbasket.booksellerid = aqbooksellers.id + WHERE name LIKE ? GROUP BY aqbooksellers.id ORDER BY name + "; my $dbh = C4::Context->dbh; my $sth = $dbh->prepare($query); @@ -84,6 +87,9 @@ sub GetBookSellerFromId { ( $vendor->{basketcount} ) = $dbh->selectrow_array( 'SELECT count(*) FROM aqbasket where booksellerid = ?', {}, $id ); + ( $vendor->{subscriptioncount} ) = $dbh->selectrow_array( + 'SELECT count(*) FROM subscription WHERE aqbooksellerid = ?', + {}, $id ); } return $vendor; } @@ -99,19 +105,48 @@ Searches for suppliers with late orders. =cut sub GetBooksellersWithLateOrders { - my $delay = shift; - my $dbh = C4::Context->dbh; - - # TODO delay should be verified - my $query_string = - "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 (closedate < DATE_SUB(CURDATE( ),INTERVAL $delay DAY) - AND (datereceived = '' OR datereceived IS NULL))"; - - my $sth = $dbh->prepare($query_string); - $sth->execute; + my ( $delay, $branch, $estimateddeliverydatefrom, $estimateddeliverydateto ) = @_; # FIXME: Branch argument unused. + 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 $strsth; + my @query_params = (); + my $dbdriver = C4::Context->config("db_scheme") || "mysql"; + $strsth = " + 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.rrp <> 0 + AND aqorders.ecost <> 0 + AND aqorders.quantity - COALESCE(aqorders.quantityreceived,0) <> 0 + AND aqbasket.closedate IS NOT NULL + "; + if ( defined $delay ) { + $strsth .= " AND (closedate <= DATE_SUB(CAST(now() AS date),INTERVAL ? DAY)) "; + push @query_params, $delay; + } + if ( defined $estimateddeliverydatefrom ) { + $strsth .= ' + AND aqbooksellers.deliverytime IS NOT NULL + AND ADDDATE(aqbasket.closedate, INTERVAL aqbooksellers.deliverytime DAY) >= ?'; + push @query_params, $estimateddeliverydatefrom; + } + if ( defined $estimateddeliverydatefrom and defined $estimateddeliverydateto ) { + $strsth .= ' AND ADDDATE(aqbasket.closedate, INTERVAL aqbooksellers.deliverytime DAY) <= ?'; + push @query_params, $estimateddeliverydateto; + } elsif ( defined $estimateddeliverydatefrom ) { + $strsth .= ' AND ADDDATE(aqbasket.closedate, INTERVAL aqbooksellers.deliverytime DAY) <= CAST(now() AS date)'; + } + + my $sth = $dbh->prepare($strsth); + $sth->execute( @query_params ); my %supplierlist; while ( my ( $id, $name ) = $sth->fetchrow ) { $supplierlist{$id} = $name; @@ -140,30 +175,31 @@ sub AddBookseller { my $query = q| INSERT INTO aqbooksellers ( - name, address1, address2, address3, address4, - postal, phone, fax, url, contact, - contpos, contphone, contfax, contaltphone, contemail, - contnotes, active, listprice, invoiceprice, gstreg, - listincgst,invoiceincgst, gstrate, discount, - notes + name, address1, address2, address3, address4, + postal, phone, accountnumber,fax, url, + contact, contpos, contphone, contfax, contaltphone, + contemail, contnotes, active, listprice, invoiceprice, + gstreg, listincgst, invoiceincgst,gstrate, discount, + notes, deliverytime ) - VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?) | + VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?) | ; my $sth = $dbh->prepare($query); $sth->execute( - $data->{'name'}, $data->{'address1'}, - $data->{'address2'}, $data->{'address3'}, - $data->{'address4'}, $data->{'postal'}, - $data->{'phone'}, $data->{'fax'}, - $data->{'url'}, $data->{'contact'}, - $data->{'contpos'}, $data->{'contphone'}, - $data->{'contfax'}, $data->{'contaltphone'}, - $data->{'contemail'}, $data->{'contnotes'}, - $data->{'active'}, $data->{'listprice'}, - $data->{'invoiceprice'}, $data->{'gstreg'}, - $data->{'listincgst'}, $data->{'invoiceincgst'}, - $data->{'gstrate'}, - $data->{'discount'}, $data->{'notes'} + $data->{name} ,$data->{address1}, + $data->{address2} ,$data->{address3}, + $data->{address4} ,$data->{postal}, + $data->{phone} ,$data->{accountnumber}, + $data->{fax}, + $data->{url} ,$data->{contact}, + $data->{contpos} ,$data->{contphone}, + $data->{contfax} ,$data->{contaltphone}, + $data->{contemail} ,$data->{contnotes}, + $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 @@ -192,18 +228,19 @@ sub ModBookseller { my $dbh = C4::Context->dbh; my $query = 'UPDATE aqbooksellers SET name=?,address1=?,address2=?,address3=?,address4=?, - postal=?,phone=?,fax=?,url=?,contact=?,contpos=?, + postal=?,phone=?,accountnumber=?,fax=?,url=?,contact=?,contpos=?, contphone=?,contfax=?,contaltphone=?,contemail=?, contnotes=?,active=?,listprice=?, invoiceprice=?, gstreg=?,listincgst=?,invoiceincgst=?, - discount=?,notes=?,gstrate=? + discount=?,notes=?,gstrate=?,deliverytime=? WHERE id=?'; my $sth = $dbh->prepare($query); $sth->execute( $data->{'name'}, $data->{'address1'}, $data->{'address2'}, $data->{'address3'}, $data->{'address4'}, $data->{'postal'}, - $data->{'phone'}, $data->{'fax'}, + $data->{'phone'}, $data->{'accountnumber'}, + $data->{'fax'}, $data->{'url'}, $data->{'contact'}, $data->{'contpos'}, $data->{'contphone'}, $data->{'contfax'}, $data->{'contaltphone'}, @@ -212,7 +249,9 @@ sub ModBookseller { $data->{'invoiceprice'}, $data->{'gstreg'}, $data->{'listincgst'}, $data->{'invoiceincgst'}, $data->{'discount'}, $data->{'notes'}, - $data->{'gstrate'}, $data->{'id'} + $data->{'gstrate'}, + $data->{deliverytime}, + $data->{'id'} ); return; }