From 62f184262e464edbe727b76c72b57b7121098afc Mon Sep 17 00:00:00 2001 From: Paul Poulain Date: Tue, 1 Sep 2009 15:00:54 +0200 Subject: [PATCH] (MT #1855) Make an Ajax+JSON search receiving orders This one, rewrite the SearchOrder function to deal with the search receiving an order. It implement an AJAX+JSON orders search engine. --- C4/Acquisition.pm | 53 ++++++++-------- acqui/parcel.pl | 42 +++++++++++++ .../prog/en/lib/yui/json/json-min.js | 7 +++ .../prog/en/modules/acqui/ajax.tmpl | 2 +- .../prog/en/modules/acqui/parcel.tmpl | 61 +++++++++++-------- 5 files changed, 114 insertions(+), 51 deletions(-) create mode 100644 koha-tmpl/intranet-tmpl/prog/en/lib/yui/json/json-min.js diff --git a/C4/Acquisition.pm b/C4/Acquisition.pm index c4fc0ca420..e446e2ae2b 100644 --- a/C4/Acquisition.pm +++ b/C4/Acquisition.pm @@ -1170,39 +1170,40 @@ C<@results> is an array of references-to-hash with the following keys: sub SearchOrder { #### -------- SearchOrder------------------------------- - my ($ordernumber, $search) = @_; + my ($ordernumber, $search, $supplierid, $basket) = @_; - if ($ordernumber) { - my $dbh = C4::Context->dbh; - my $query = - "SELECT * - FROM aqorders - LEFT JOIN biblio ON aqorders.biblionumber=biblio.biblionumber - LEFT JOIN biblioitems ON biblioitems.biblionumber=biblio.biblionumber - LEFT JOIN aqbasket ON aqorders.basketno = aqbasket.basketno - WHERE ((datecancellationprinted is NULL) - AND (aqorders.ordernumber=?))"; - my $sth = $dbh->prepare($query); - $sth->execute($ordernumber); - my $results = $sth->fetchall_arrayref({}); - $sth->finish; - return $results; - } else { - my $dbh = C4::Context->dbh; - my $query = + my $dbh = C4::Context->dbh; + my @args = (); + my $query = "SELECT * FROM aqorders LEFT JOIN biblio ON aqorders.biblionumber=biblio.biblionumber LEFT JOIN biblioitems ON biblioitems.biblionumber=biblio.biblionumber LEFT JOIN aqbasket ON aqorders.basketno = aqbasket.basketno - WHERE ((datecancellationprinted is NULL) - AND (biblio.title like ? OR biblioitems.isbn like ?))"; - my $sth = $dbh->prepare($query); - $sth->execute("%$search%","%$search%"); - my $results = $sth->fetchall_arrayref({}); - $sth->finish; - return $results; + WHERE (datecancellationprinted is NULL)"; + + if($ordernumber){ + $query .= " AND (aqorders.ordernumber=?)"; + push @args, $ordernumber; + } + if($search){ + $query .= " AND (biblio.title like ? OR biblio.author LIKE ? OR biblioitems.isbn like ?)"; + push @args, ("%$search%","%$search%","%$search%"); + } + if($supplierid){ + $query .= "AND aqbasket.booksellerid = ?"; + push @args, $supplierid; } + if($basket){ + $query .= "AND aqorders.basketno = ?"; + push @args, $basket; + } + + my $sth = $dbh->prepare($query); + $sth->execute(@args); + my $results = $sth->fetchall_arrayref({}); + $sth->finish; + return $results; } #------------------------------------------------------------# diff --git a/acqui/parcel.pl b/acqui/parcel.pl index 3a161eb33a..7b93a158f1 100755 --- a/acqui/parcel.pl +++ b/acqui/parcel.pl @@ -61,6 +61,7 @@ use C4::Items; use CGI; use C4::Output; use C4::Dates qw/format_date format_date_in_iso/; +use JSON; use strict; @@ -83,6 +84,47 @@ my $resultsperpage = $input->param('resultsperpage'); $resultsperpage = 20 unless ($resultsperpage); $startfrom=0 unless ($startfrom); +if($input->param('format') eq "json"){ + my ($template, $loggedinuser, $cookie) + = get_template_and_user({template_name => "acqui/ajax.tmpl", + query => $input, + type => "intranet", + authnotrequired => 0, + flagsrequired => {acquisition => 'order_receive'}, + debug => 1, + }); + + my @datas; + my $search = $input->param('search') || ''; + my $supplier = $input->param('supplierid') || ''; + my $basketno = $input->param('basketno') || ''; + my $orderno = $input->param('orderno') || ''; + + my $orders = SearchOrder($orderno, $search, $supplier, $basketno); + foreach my $order (@$orders){ + if($order->{quantityreceived} < $order->{quantity}){ + my $data = {}; + + $data->{basketno} = $order->{basketno}; + $data->{ordernumber} = $order->{ordernumber}; + $data->{title} = $order->{title}; + $data->{author} = $order->{author}; + $data->{biblionumber} = $order->{biblionumber}; + $data->{freight} = $order->{freight}; + $data->{quantrem} = $order->{quantity} - $order->{quantityreceived}; + $data->{quantity} = $order->{quantity}; + $data->{ecost} = $order->{ecost}; + $data->{ordertotal} = sprintf("%.2f",$order->{ecost}*$order->{quantity}); + push @datas, $data; + } + } + + my $json_text = to_json(\@datas); + $template->param(return => $json_text); + output_html_with_http_headers $input, $cookie, $template->output; + exit; +} + my ($template, $loggedinuser, $cookie) = get_template_and_user({template_name => "acqui/parcel.tmpl", query => $input, diff --git a/koha-tmpl/intranet-tmpl/prog/en/lib/yui/json/json-min.js b/koha-tmpl/intranet-tmpl/prog/en/lib/yui/json/json-min.js new file mode 100644 index 0000000000..574c0c0c94 --- /dev/null +++ b/koha-tmpl/intranet-tmpl/prog/en/lib/yui/json/json-min.js @@ -0,0 +1,7 @@ +/* +Copyright (c) 2009, Yahoo! Inc. All rights reserved. +Code licensed under the BSD License: +http://developer.yahoo.net/yui/license.txt +version: 2.7.0 +*/ +YAHOO.lang.JSON=(function(){var l=YAHOO.lang,_UNICODE_EXCEPTIONS=/[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,_ESCAPES=/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g,_VALUES=/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g,_BRACKETS=/(?:^|:|,)(?:\s*\[)+/g,_INVALID=/^[\],:{}\s]*$/,_SPECIAL_CHARS=/[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,_CHARS={"\b":"\\b","\t":"\\t","\n":"\\n","\f":"\\f","\r":"\\r",'"':'\\"',"\\":"\\\\"};function _revive(data,reviver){var walk=function(o,key){var k,v,value=o[key];if(value&&typeof value==="object"){for(k in value){if(l.hasOwnProperty(value,k)){v=walk(value,k);if(v===undefined){delete value[k];}else{value[k]=v;}}}}return reviver.call(o,key,value);};return typeof reviver==="function"?walk({"":data},""):data;}function _char(c){if(!_CHARS[c]){_CHARS[c]="\\u"+("0000"+(+(c.charCodeAt(0))).toString(16)).slice(-4);}return _CHARS[c];}function _prepare(s){return s.replace(_UNICODE_EXCEPTIONS,_char);}function _isValid(str){return l.isString(str)&&_INVALID.test(str.replace(_ESCAPES,"@").replace(_VALUES,"]").replace(_BRACKETS,""));}function _string(s){return'"'+s.replace(_SPECIAL_CHARS,_char)+'"';}function _stringify(h,key,d,w,pstack){var o=typeof w==="function"?w.call(h,key,h[key]):h[key],i,len,j,k,v,isArray,a;if(o instanceof Date){o=l.JSON.dateToString(o);}else{if(o instanceof String||o instanceof Boolean||o instanceof Number){o=o.valueOf();}}switch(typeof o){case"string":return _string(o);case"number":return isFinite(o)?String(o):"null";case"boolean":return String(o);case"object":if(o===null){return"null";}for(i=pstack.length-1;i>=0;--i){if(pstack[i]===o){return"null";}}pstack[pstack.length]=o;a=[];isArray=l.isArray(o);if(d>0){if(isArray){for(i=o.length-1;i>=0;--i){a[i]=_stringify(o,i,d-1,w,pstack)||"null";}}else{j=0;if(l.isArray(w)){for(i=0,len=w.length;i=0?d:1/0;return _stringify({"":o},"",d,w,[]);}return undefined;},dateToString:function(d){function _zeroPad(v){return v<10?"0"+v:v;}return d.getUTCFullYear()+"-"+_zeroPad(d.getUTCMonth()+1)+"-"+_zeroPad(d.getUTCDate())+"T"+_zeroPad(d.getUTCHours())+":"+_zeroPad(d.getUTCMinutes())+":"+_zeroPad(d.getUTCSeconds())+"Z";},stringToDate:function(str){if(/^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})Z$/.test(str)){var d=new Date();d.setUTCFullYear(RegExp.$1,(RegExp.$2|0)-1,RegExp.$3);d.setUTCHours(RegExp.$4,RegExp.$5,RegExp.$6);return d;}return str;}};})();YAHOO.register("json",YAHOO.lang.JSON,{version:"2.7.0",build:"1796"}); \ No newline at end of file diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/ajax.tmpl b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/ajax.tmpl index 13b3f76d1a..fa44f11d51 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/ajax.tmpl +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/ajax.tmpl @@ -1 +1 @@ - + \ No newline at end of file diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/parcel.tmpl b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/parcel.tmpl index 1dfaee7e24..ffb9303e6d 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/parcel.tmpl +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/parcel.tmpl @@ -3,6 +3,7 @@ Receipt Summary for Invoice on Receive Orders from +