Often you might want to see the total number of books entered in your koha catalogue. You can see that in the reports module by creating a report with the below given SQL code. But what if I you could see that on the home page of your Koha staff screen? Wouldn’t that be amazing?
You can do so by creating a report that fetches the total number of biblios and items from the database, and then with a simple jquery, you can fetch the results of this report in real-time to show a table on the Koha home screen.
Create SQL Report
SELECT homebranch, count(DISTINCT biblionumber) AS bibs,
count(itemnumber) AS items
FROM items
GROUP BY homebranch
ORDER BY homebranch ASC
Add JQuery to Staff Screen
Now go to the Koha administration screen, and under System Preferences, open the Staff interface tab from the left sidebar. You can search for the IntranetUserJS section, and copy and paste the following JQuery code.
//**Total Number of Books in Koha**//
$("label[for='sql_params_Reselectthesubjecttag']").hide()
$('#sql_params_Reselectthesubjecttag').hide();
$("#sql_params_Selectthesubject").change(function() {
var subval = $('#sql_params_Selectthesubject').val();
$("#sql_params_Reselectthesubjecttag").val(subval);
});
$(document).ready(function() {
if ( $('#main_intranet-main').length ) {
$.getJSON("http://10.2.3.4:8080/cgi-bin/koha/svc/report?id=12&annotated=1",
function(data) {
var branches = data[0].homebranch;
var bibs = data[0].bibs;
var items = data[0].items;
$('div.newsitem').prepend('<div class="newsitem" id="mystats"><table class="table table-striped" style="width: 100%; background: none;"><thead><th colspan="3" style="text-align: center; font-weight: bold; padding: 8px; line-height: 1.42857143; vertical-align: middle; text-transform: uppercase;">Collection</thead><tbody><tr><td><strong>Branch</strong></td><td><strong>Number of Records</strong></td><td><strong>Number of Copies</strong></td></tr><tr><td class="text-center">'+branches+'</td><td class="text-center">'+bibs+'</td><td class="text-center">'+items+'</td></tr></tbody></table></div>');
});
}
});
Note that in my case, the IP address for my KOHA server is 10.2.3.4. You will have to change it to your server IP. Similarly, the report I created had report ID 12. You must change it as per your report id when you create it in the Koha reports section.
Thats it. that’s how you create a block to show total number of books in you koha home screen.
Leave a Reply