From 364e4f90615e3c62a277da47a48e3ab4dae51851 Mon Sep 17 00:00:00 2001 From: rangi Date: Wed, 7 Jun 2006 00:07:59 +0000 Subject: [PATCH] Katipo merging work Fixes for the ordersearch --- C4/Acquisition.pm | 71 +++++++++++++++++++++++++++++++++-------------- 1 file changed, 50 insertions(+), 21 deletions(-) diff --git a/C4/Acquisition.pm b/C4/Acquisition.pm index 3030371ac8..484df98cc7 100644 --- a/C4/Acquisition.pm +++ b/C4/Acquisition.pm @@ -397,6 +397,17 @@ sub receiveorder { $sth->execute( $quantrec, $invoiceno, $cost, $freight, $rrp, $biblio, $ordnum ); $sth->finish; + + # Allows libraries to change their bookfund during receiving orders + # allows them to adjust budgets + if ( C4::Context->preferene("LooseBudgets") ) { + my $sth = $dbh->prepare( +"UPDATE aqorderbreakdown SET bookfundid=? + WHERE ordernumber=?" + ); + $sth->execute( $bookfund, $ordnum ); + $sth->finish; + } } =item updaterecorder @@ -858,37 +869,55 @@ following keys: #' sub ordersearch { my ( $search, $id, $biblio, $catview ) = @_; - my $dbh = C4::Context->dbh; - my @data = split( ' ', $search ); - my @searchterms = ($id); + my $dbh = C4::Context->dbh; + my @data = split( ' ', $search ); + my @searchterms; + if ($id) { + @searchterms = ($id); + } map { push( @searchterms, "$_%", "% $_%" ) } @data; push( @searchterms, $search, $search, $biblio ); - my $sth = $dbh->prepare( -"Select biblio.*,biblioitems.*,aqorders.*,aqbasket.*,biblio.title from aqorders,biblioitems,biblio,aqbasket - where aqorders.biblioitemnumber = biblioitems.biblioitemnumber and - aqorders.basketno = aqbasket.basketno - and aqbasket.booksellerid = ? - and biblio.biblionumber=aqorders.biblionumber - and ((datecancellationprinted is NULL) - or (datecancellationprinted = '0000-00-00')) - and ((" + my $query; + if ($id) { + $query = + "SELECT *,biblio.title FROM aqorders,biblioitems,biblio,aqbasket + WHERE aqorders.biblioitemnumber = biblioitems.biblioitemnumber AND + aqorders.basketno = aqbasket.basketno + AND aqbasket.booksellerid = ? + AND biblio.biblionumber=aqorders.biblionumber + AND ((datecancellationprinted is NULL) + OR (datecancellationprinted = '0000-00-00')) + AND ((" . ( - join( " and ", + join( " AND ", map { "(biblio.title like ? or biblio.title like ?)" } @data ) ) - . ") or biblioitems.isbn=? or (aqorders.ordernumber=? and aqorders.biblionumber=?)) " + . ") OR biblioitems.isbn=? OR (aqorders.ordernumber=? AND aqorders.biblionumber=?)) "; + + } + else { + $query = + "SELECT *,biblio.title FROM aqorders,biblioitems,biblio,aqbasket + WHERE aqorders.biblioitemnumber = biblioitems.biblioitemnumber AND + aqorders.basketno = aqbasket.basketno + AND biblio.biblionumber=aqorders.biblionumber + AND ((datecancellationprinted is NULL) + OR (datecancellationprinted = '0000-00-00')) + AND (aqorders.quantityreceived < aqorders.quantity OR aqorders.quantityreceived is NULL) + AND ((" . ( - ( $catview ne 'yes' ) - ? " and (quantityreceived < quantity or quantityreceived is NULL)" - : "" + join( " AND ", + map { "(biblio.title like ? OR biblio.title like ?)" } @data ) ) - . " group by aqorders.ordernumber" - ); + . ") or biblioitems.isbn=? OR (aqorders.ordernumber=? AND aqorders.biblionumber=?)) "; + } + $query .= " GROUP BY aqorders.ordernumber"; + my $sth = $dbh->prepare($query); $sth->execute(@searchterms); my @results = (); - my $sth2 = $dbh->prepare("Select * from biblio where biblionumber=?"); + my $sth2 = $dbh->prepare("SELECT * FROM biblio WHERE biblionumber=?"); my $sth3 = - $dbh->prepare("Select * from aqorderbreakdown where ordernumber=?"); + $dbh->prepare("SELECT * FROM aqorderbreakdown WHERE ordernumber=?"); while ( my $data = $sth->fetchrow_hashref ) { $sth2->execute( $data->{'biblionumber'} ); my $data2 = $sth2->fetchrow_hashref; -- 2.39.5