X-Git-Url: http://git.rot13.org/?a=blobdiff_plain;f=C4%2FBookseller.pm;h=c8389a34410798a2b10159273da1c9efbe68e9ed;hb=3bca90eb0c0fc91f64f3e479ac6ab25e54d4f1aa;hp=f14bd026005141a81841432021f70495dd275f9e;hpb=ba6c8485ca7afdaaace20d021591ac532de55b3a;p=koha.git diff --git a/C4/Bookseller.pm b/C4/Bookseller.pm index f14bd02600..c8389a3441 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); @@ -102,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; @@ -201,7 +233,7 @@ sub ModBookseller { 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( @@ -218,7 +250,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; }