3 $(document).ready(function() {
4 var loadIssuesTableDelayTimeoutId;
6 var barcodefield = $("#barcode");
8 var onHoldDueDateSet = false;
10 var onHoldChecked = function() {
11 var isChecked = false;
12 $('input[data-on-reserve]').each(function() {
13 if ($(this).is(':checked')) {
20 var showHideOnHoldRenewal = function() {
21 // Display the date input
22 if (onHoldChecked()) {
23 $('#newonholdduedate').show()
25 $('#newonholdduedate').hide();
29 // Handle the select all/none links for checkouts table columns
30 $("#CheckAllRenewals").on("click",function(){
31 $("#UncheckAllCheckins").click();
32 $(".renew:visible").prop("checked", true);
33 showHideOnHoldRenewal();
36 $("#UncheckAllRenewals").on("click",function(){
37 $(".renew:visible").prop("checked", false);
38 showHideOnHoldRenewal();
42 $("#CheckAllCheckins").on("click",function(){
43 $("#UncheckAllRenewals").click();
44 $(".checkin:visible").prop("checked", true);
47 $("#UncheckAllCheckins").on("click",function(){
48 $(".checkin:visible").prop("checked", false);
52 $("#newduedate").on("change", function() {
53 if (!onHoldDueDateSet) {
54 $('#newonholdduedate input').val($('#newduedate').val());
58 $("#newonholdduedate").on("change", function() {
59 onHoldDueDateSet = true;
62 // Don't allow both return and renew checkboxes to be checked
63 $(document).on("change", '.renew', function(){
64 if ( $(this).is(":checked") ) {
65 $( "#checkin_" + $(this).val() ).prop("checked", false);
68 $(document).on("change", '.checkin', function(){
69 if ( $(this).is(":checked") ) {
70 $( "#renew_" + $(this).val() ).prop("checked", false);
74 // Display on hold due dates input when an on hold item is
76 $(document).on('change', '.renew', function(){
77 showHideOnHoldRenewal();
80 $("#output_format > option:first-child").attr("selected", "selected");
81 $("select[name='csv_profile_id']").hide();
82 $(document).on("change", '#issues-table-output-format', function(){
83 if ( $(this).val() == 'csv' ) {
84 $("select[name='csv_profile_id']").show();
86 $("select[name='csv_profile_id']").hide();
90 // Clicking the table cell checks the checkbox inside it
91 $(document).on("click", 'td', function(e){
92 if(e.target.tagName.toLowerCase() == 'td'){
93 $(this).find("input:checkbox:visible").each( function() {
99 // Handle renewals and returns
100 $("#RenewCheckinChecked").on("click",function(){
101 $(".checkin:checked:visible").each(function() {
102 itemnumber = $(this).val();
104 $(this).replaceWith("<img id='checkin_" + itemnumber + "' src='" + interface + "/" + theme + "/img/spinner-small.gif' />");
107 itemnumber: itemnumber,
108 borrowernumber: borrowernumber,
109 branchcode: branchcode,
110 exempt_fine: $("#exemptfine").is(':checked')
114 url: "/cgi-bin/koha/svc/checkin",
116 success: function( data ) {
117 id = "#checkin_" + data.itemnumber;
120 if ( data.returned ) {
121 content = __("Checked in");
122 $(id).parent().parent().addClass('ok');
123 $('#date_due_' + data.itemnumber).html( __("Checked in") );
124 if ( data.patronnote != null ) {
125 $('.patron_note_' + data.itemnumber).html( __("Patron note") + ": " + data.patronnote);
128 content = __("Unable to check in");
129 $(id).parent().parent().addClass('warn');
132 $(id).replaceWith( content );
139 $(".confirm:checked:visible").each(function() {
140 itemnumber = $(this).val();
141 id = "#checkin_" + itemnumber;
142 materials = $(this).data('materials');
144 $(this).replaceWith("<span class='confirm' id='checkin_" + itemnumber + "'>" + __("Confirm") + " (<span>" + materials + "</span>): <input type='checkbox' class='checkin' name='checkin' value='" + itemnumber +"'></input></span>");
145 $(id).parent().parent().addClass('warn');
148 $(".renew:checked:visible").each(function() {
149 var override_limit = $("#override_limit").is(':checked') ? 1 : 0;
151 var isOnReserve = $(this).data().hasOwnProperty('onReserve');
153 var itemnumber = $(this).val();
155 $(this).parent().parent().replaceWith("<img id='renew_" + itemnumber + "' src='" + interface + "/" + theme + "/img/spinner-small.gif' />");
158 itemnumber: itemnumber,
159 borrowernumber: borrowernumber,
160 branchcode: branchcode,
161 override_limit: override_limit
164 if (UnseenRenewals) {
165 var ren = $("#renew_as_unseen_checkbox");
166 var renew_unseen = ren.length > 0 && ren.is(':checked') ? 1 : 0;
167 params.seen = renew_unseen === 1 ? 0 : 1;
170 // Determine which due date we need to use
171 var dueDate = isOnReserve ?
172 $("#newonholdduedate input").val() :
173 $("#newduedate").val();
175 if (dueDate && dueDate.length > 0) {
176 params.date_due = dueDate
180 url: "/cgi-bin/koha/svc/renew",
182 success: function( data ) {
183 var id = "#renew_" + data.itemnumber;
186 if ( data.renew_okay ) {
187 content = __("Renewed, due:") + " " + data.date_due;
188 $('#date_due_' + data.itemnumber).replaceWith( data.date_due );
190 content = __("Renew failed:") + " ";
191 if ( data.error == "no_checkout" ) {
192 content += __("not checked out");
193 } else if ( data.error == "too_many" ) {
194 content += __("too many renewals");
195 } else if ( data.error == "too_unseen" ) {
196 content += __("too many consecutive renewals without being seen by the library");
197 } else if ( data.error == "on_reserve" ) {
198 content += __("on hold");
199 } else if ( data.error == "restriction" ) {
200 content += __("Not allowed: patron restricted");
201 } else if ( data.error == "overdue" ) {
202 content += __("Not allowed: overdue");
203 } else if ( data.error ) {
204 content += data.error;
206 content += __("reason unknown");
210 $(id).replaceWith( content );
217 // Refocus on barcode field if it exists
218 if ( $("#barcode").length ) {
219 $("#barcode").focus();
222 // Prevent form submit
226 $("#RenewAll").on("click",function(){
227 $("#CheckAllRenewals").click();
228 $("#UncheckAllCheckins").click();
229 showHideOnHoldRenewal();
230 $("#RenewCheckinChecked").click();
232 // Prevent form submit
236 var ymd = flatpickr.formatDate(new Date(), "Y-m-d");
238 $('#issues-table').hide();
239 $('#issues-table-actions').hide();
240 $('#issues-table-load-immediately').change(function(){
241 if ( this.checked && typeof issuesTable === 'undefined') {
242 $('#issues-table-load-now-button').click();
244 barcodefield.focus();
246 $('#issues-table-load-now-button').click(function(){
247 if ( loadIssuesTableDelayTimeoutId ) clearTimeout(loadIssuesTableDelayTimeoutId);
249 barcodefield.focus();
253 $('#RenewCheckinChecked').on('click', function(){
254 RefreshIssuesTable();
257 if ( Cookies.get("issues-table-load-immediately-" + script) == "true" ) {
258 if ( LoadCheckoutsTableDelay ) {
259 loadIssuesTableDelayTimeoutId = setTimeout( function(){ LoadIssuesTable() }, LoadCheckoutsTableDelay * 1000);
263 $('#issues-table-load-immediately').prop('checked', true);
265 $('#issues-table-load-delay').hide();
267 $('#issues-table-load-immediately').on( "change", function(){
268 Cookies.set("issues-table-load-immediately-" + script, $(this).is(':checked'), { expires: 365, sameSite: 'Lax' });
271 function RefreshIssuesTable() {
272 var table = $('#issues-table').DataTable();
276 function LoadIssuesTable() {
277 $('#issues-table-loading-message').hide();
278 $('#issues-table').show();
279 $('#issues-table-actions').show();
281 var msg_loading = __('Loading... you may continue scanning.');
282 issuesTable = KohaTable("issues-table", {
284 "sEmptyTable" : msg_loading,
285 "sProcessing": msg_loading,
288 "dom": '<"table_controls"B>rt',
291 "mDataProp": function( oObj ) {
292 return oObj.sort_order;
296 "mDataProp": function( oObj ) {
297 if ( oObj.issued_today ) {
298 return "<strong>" + __("Today's checkouts") + "</strong>";
300 return "<strong>" + __("Previous checkouts") + "</strong>";
305 "mDataProp": "date_due",
309 "iDataSort": 2, // Sort on hidden unformatted date due column
310 "mDataProp": function( oObj ) {
311 var due = oObj.date_due_formatted;
312 if ( oObj.date_due_overdue ) {
313 due = "<span class='overdue'>" + due + "</span>";
316 due = "<span id='date_due_" + oObj.itemnumber + "' class='date_due'>" + due + "</span>";
318 if ( oObj.lost && oObj.claims_returned ) {
319 due += "<span class='lost claims_returned'>" + oObj.lost.escapeHtml() + "</span>";
320 } else if ( oObj.lost ) {
321 due += "<span class='lost'>" + oObj.lost.escapeHtml() + "</span>";
324 if ( oObj.damaged ) {
325 due += "<span class='dmg'>" + oObj.damaged.escapeHtml() + "</span>";
328 var patron_note = " <span class='patron_note_" + oObj.itemnumber + "'></span>";
329 due +="<br>" + patron_note;
335 "mDataProp": function ( oObj ) {
336 let title = "<span id='title_" + oObj.itemnumber + "' class='strong'><a href='/cgi-bin/koha/catalogue/detail.pl?biblionumber="
339 + (oObj.title ? oObj.title.escapeHtml() : '' );
341 $.each(oObj.subtitle, function( index, value ) {
342 title += " " + value.escapeHtml();
345 title += " " + oObj.part_number + " " + oObj.part_name;
347 if ( oObj.enumchron ) {
348 title += " <span class='item_enumeration'>(" + oObj.enumchron.escapeHtml() + ")</span>";
351 title += "</a></span>";
354 title += " " + __("by _AUTHOR_").replace( "_AUTHOR_", " " + oObj.author.escapeHtml() );
357 if ( oObj.itemnotes ) {
358 var span_class = "text-muted";
359 if ( flatpickr.formatDate( new Date(oObj.issuedate), "Y-m-d" ) == ymd ){
360 span_class = "circ-hlt";
362 title += " - <span class='" + span_class + " item-note-public'>" + oObj.itemnotes.escapeHtml() + "</span>";
365 if ( oObj.itemnotes_nonpublic ) {
366 var span_class = "text-danger";
367 if ( flatpickr.formatDate( new Date(oObj.issuedate), "Y-m-d" ) == ymd ){
368 span_class = "circ-hlt";
370 title += " - <span class='" + span_class + " item-note-nonpublic'>" + oObj.itemnotes_nonpublic.escapeHtml() + "</span>";
373 var onsite_checkout = '';
374 if ( oObj.onsite_checkout == 1 ) {
375 onsite_checkout += " <span class='onsite_checkout'>(" + __("On-site checkout") + ")</span>";
378 if ( oObj.recalled == 1 ) {
379 title += " - <span class='circ-hlt item-recalled'>" + __("This item has been recalled and the due date updated") + ".</span>";
383 + "<a href='/cgi-bin/koha/catalogue/moredetail.pl?biblionumber="
390 + (oObj.barcode ? oObj.barcode.escapeHtml() : "")
399 "mDataProp": function ( oObj ) {
400 return oObj.recordtype_description.escapeHtml();
404 "mDataProp": function ( oObj ) {
405 return oObj.itemtype_description.escapeHtml();
409 "mDataProp": function ( oObj ) {
410 return ( oObj.collection ? oObj.collection.escapeHtml() : '' );
414 "mDataProp": function ( oObj ) {
415 return ( oObj.location ? oObj.location.escapeHtml() : '' );
419 "mDataProp": function ( oObj ) {
420 return (oObj.homebranch ? oObj.homebranch.escapeHtml() : '' );
424 "mDataProp": "issuedate",
428 "iDataSort": 10, // Sort on hidden unformatted issuedate column
429 "mDataProp": "issuedate_formatted",
432 "mDataProp": function ( oObj ) {
433 return (oObj.branchname ? oObj.branchname.escapeHtml() : '' );
437 "mDataProp": function ( oObj ) {
438 return ( oObj.itemcallnumber ? oObj.itemcallnumber.escapeHtml() : '' );
442 "mDataProp": function ( oObj ) {
443 return ( oObj.copynumber ? oObj.copynumber.escapeHtml() : '' );
447 "mDataProp": function ( oObj ) {
448 if ( ! oObj.charge ) oObj.charge = 0;
449 return '<span style="text-align: right; display: block;">' + parseFloat(oObj.charge).format_price() + '<span>';
454 "mDataProp": function ( oObj ) {
455 if ( ! oObj.fine ) oObj.fine = 0;
456 return '<span style="text-align: right; display: block;">' + parseFloat(oObj.fine).format_price() + '<span>';
461 "mDataProp": function ( oObj ) {
462 if ( ! oObj.price ) oObj.price = 0;
463 return '<span style="text-align: right; display: block;">' + parseFloat(oObj.price).format_price() + '<span>';
469 "bVisible": AllowCirculate ? true : false,
470 "mDataProp": function ( oObj ) {
476 if ( oObj.can_renew ) {
478 } else if ( oObj.can_renew_error == "recalled" ) {
480 + "<a href='/cgi-bin/koha/recalls/request.pl?biblionumber=" + oObj.biblionumber + "'>" + __("Recalled") + "</a>"
483 span_style = "display: none";
484 span_class = "renewals-allowed-recalled";
485 } else if ( oObj.can_renew_error == "on_reserve" ) {
487 +"<a href='/cgi-bin/koha/reserve/request.pl?biblionumber=" + oObj.biblionumber + "'>" + __("On hold") + "</a>"
490 span_style = "display: none";
491 span_class = "renewals-allowed-on_reserve";
492 } else if ( oObj.can_renew_error == "too_many" ) {
493 msg += "<span class='renewals-disabled'>"
494 + __("Not renewable")
497 span_style = "display: none";
498 span_class = "renewals-allowed";
499 } else if ( oObj.can_renew_error == "too_unseen" ) {
501 + __("Must be renewed at the library")
503 span_class = "renewals-allowed";
504 } else if ( oObj.can_renew_error == "restriction" ) {
505 msg += "<span class='renewals-disabled'>"
506 + __("Not allowed: patron restricted")
509 span_style = "display: none";
510 span_class = "renewals-allowed";
511 } else if ( oObj.can_renew_error == "overdue" ) {
512 msg += "<span class='renewals-disabled'>"
513 + __("Not allowed: overdue")
516 span_style = "display: none";
517 span_class = "renewals-allowed";
518 } else if ( oObj.can_renew_error == "too_soon" ) {
519 msg += "<span class='renewals-disabled'>"
520 + __("No renewal before %s").format(oObj.can_renew_date)
523 span_style = "display: none";
524 span_class = "renewals-allowed";
525 } else if ( oObj.can_renew_error == "auto_too_soon" ) {
526 msg += "<span class='renewals-disabled'>"
527 + __("Scheduled for automatic renewal")
530 span_style = "display: none";
531 span_class = "renewals-allowed";
532 } else if ( oObj.can_renew_error == "auto_too_late" ) {
533 msg += "<span class='renewals-disabled'>"
534 + __("Can no longer be auto-renewed - number of checkout days exceeded")
537 span_style = "display: none";
538 span_class = "renewals-allowed";
539 } else if ( oObj.can_renew_error == "auto_too_much_oweing" ) {
540 msg += "<span class='renewals-disabled'>"
541 + __("Automatic renewal failed, patron has unpaid fines")
544 span_style = "display: none";
545 span_class = "renewals-allowed";
546 } else if ( oObj.can_renew_error == "auto_account_expired" ) {
547 msg += "<span class='renewals-disabled'>"
548 + __("Automatic renewal failed, account expired")
551 span_style = "display: none";
552 span_class = "renewals-allowed";
553 } else if ( oObj.can_renew_error == "auto_renew" ) {
554 msg += "<span class='renewals-disabled'>"
555 + __("Scheduled for automatic renewal")
558 span_style = "display: none";
559 span_class = "renewals-allowed";
560 } else if ( oObj.can_renew_error == "onsite_checkout" ) {
561 // Don't display something if it's an onsite checkout
562 } else if ( oObj.can_renew_error == "item_denied_renewal" ) {
563 content += "<span class='renewals-disabled'>"
564 + __("Renewal denied by syspref")
567 span_style = "display: none";
568 span_class = "renewals-allowed";
570 msg += "<span class='renewals-disabled'>"
571 + oObj.can_renew_error
574 span_style = "display: none";
575 span_class = "renewals-allowed";
578 var can_force_renew = ( oObj.onsite_checkout == 0 ) &&
579 ( oObj.can_renew_error != "on_reserve" || (oObj.can_renew_error == "on_reserve" && AllowRenewalOnHoldOverride))
581 var can_renew = ( oObj.renewals_remaining > 0 && ( !oObj.can_renew_error || oObj.can_renew_error == "too_unseen" ));
583 if ( can_renew || can_force_renew ) {
584 content += "<span style='padding: 0 1em;'>" + oObj.renewals_count + "</span>";
585 content += "<span class='" + span_class + "' style='" + span_style + "'>"
586 + "<input type='checkbox' ";
587 if ( oObj.date_due_overdue && can_renew ) {
588 content += "checked='checked' ";
590 if (oObj.can_renew_error == "on_reserve") {
591 content += "data-on-reserve ";
593 content += "class='renew' id='renew_" + oObj.itemnumber + "' name='renew' value='" + oObj.itemnumber +"'/>"
597 if ( can_renew || can_force_renew ) {
598 content += "<span class='renewals-info'>(";
599 content += __("%s of %s renewals remaining").format(oObj.renewals_remaining, oObj.renewals_allowed);
600 if (UnseenRenewals && oObj.unseen_allowed) {
601 content += __(" and %s of %s unseen renewals remaining").format(oObj.unseen_remaining, oObj.unseen_allowed);
603 content += ")</span>";
611 "bVisible": AllowCirculate ? true : false,
612 "mDataProp": function ( oObj ) {
613 if ( oObj.can_renew_error == "recalled" ) {
614 return "<a href='/cgi-bin/koha/recalls/request.pl?biblionumber=" + oObj.biblionumber + "'>" + __("Recalled") + "</a>";
615 } else if ( oObj.can_renew_error == "on_reserve" ) {
616 return "<a href='/cgi-bin/koha/reserve/request.pl?biblionumber=" + oObj.biblionumber + "'>" + __("On hold") + "</a>";
617 } else if ( oObj.materials ) {
618 return "<input type='checkbox' class='confirm' id='confirm_" + oObj.itemnumber + "' name='confirm' value='" + oObj.itemnumber + "' data-materials='" + oObj.materials.escapeHtml() + "'></input>";
620 return "<input type='checkbox' class='checkin' id='checkin_" + oObj.itemnumber + "' name='checkin' value='" + oObj.itemnumber +"'></input>";
625 "bVisible": ClaimReturnedLostValue ? true : false,
627 "mDataProp": function ( oObj ) {
630 if ( oObj.return_claim_id ) {
631 content = '<span class="badge">' + oObj.return_claim_created_on_formatted + '</span>';
632 } else if ( ClaimReturnedLostValue ) {
633 content = '<a class="btn btn-default btn-xs claim-returned-btn" data-itemnumber="' + oObj.itemnumber + '"><i class="fa fa-exclamation-circle"></i> ' + __("Claim returned") + '</a>';
635 content = '<a class="btn btn-default btn-xs" disabled="disabled" title="ClaimReturnedLostValue is not set, this feature is disabled"><i class="fa fa-exclamation-circle"></i> ' + __("Claim returned") + '</a>';
641 "bVisible": exports_enabled == 1 ? true : false,
643 "mDataProp": function ( oObj ) {
644 var s = "<input type='checkbox' name='itemnumbers' value='" + oObj.itemnumber + "' style='visibility:hidden;' />";
646 s += "<input type='checkbox' class='export' id='export_" + oObj.biblionumber + "' name='biblionumbers' value='" + oObj.biblionumber + "' />";
651 "fnFooterCallback": function ( nRow, aaData, iStart, iEnd, aiDisplay ) {
652 var total_charge = 0;
655 for ( var i=0; i < aaData.length; i++ ) {
656 total_charge += aaData[i]['charge'] * 1;
657 total_fine += aaData[i]['fine'] * 1;
658 total_price += aaData[i]['price'] * 1;
660 $("#totaldue").html(total_charge.format_price() );
661 $("#totalfine").html(total_fine.format_price() );
662 $("#totalprice").html(total_price.format_price() );
666 "bServerSide": false,
667 "sAjaxSource": '/cgi-bin/koha/svc/checkouts',
668 "fnServerData": function ( sSource, aoData, fnCallback ) {
669 aoData.push( { "name": "borrowernumber", "value": borrowernumber } );
671 $.getJSON( sSource, aoData, function (json) {
676 "dataSrc": "issued_today",
677 "startRender": function ( rows, group ) {
679 return __("Today's checkouts");
681 return __("Previous checkouts");
685 "fnInitComplete": function(oSettings, json) {
686 // Build a summary of checkouts grouped by itemtype
687 var checkoutsByItype = json.aaData.reduce(function (obj, row) {
688 obj[row.type_for_stat] = (obj[row.type_for_stat] || 0) + 1;
692 Object.keys(checkoutsByItype).sort().forEach(function (itype) {
694 .append($('<strong>').html(itype || __("No itemtype")))
695 .append(': ' + checkoutsByItype[itype]);
699 .addClass('checkouts-by-itemtype')
700 .append($('<summary>').html( __("Number of checkouts by item type") ))
702 .insertBefore(oSettings.nTableWrapper)
704 }, table_settings_issues_table);
706 if ( $("#issues-table").length ) {
707 $("#issues-table_processing").position({
708 of: $( "#issues-table" ),
714 // Don't load relatives' issues table unless it is clicked on
715 var relativesIssuesTable;
716 $("#relatives-issues-tab").click( function() {
717 if ( ! relativesIssuesTable ) {
718 relativesIssuesTable = KohaTable("relatives-issues-table", {
720 "dom": '<"table_controls"B>rt',
724 "mDataProp": "date_due",
728 "iDataSort": 0, // Sort on hidden unformatted date due column
729 "mDataProp": function( oObj ) {
730 var today = new Date();
731 var due = new Date( oObj.date_due );
733 return "<span class='overdue'>" + oObj.date_due_formatted + "</span>";
735 return oObj.date_due_formatted;
740 "mDataProp": function ( oObj ) {
741 let title = "<span class='strong'><a href='/cgi-bin/koha/catalogue/detail.pl?biblionumber="
744 + (oObj.title ? oObj.title.escapeHtml() : '' );
746 $.each(oObj.subtitle, function( index, value ) {
747 title += " " + value.escapeHtml();
750 title += " " + oObj.part_number + " " + oObj.part_name;
752 if ( oObj.enumchron ) {
753 title += " (" + oObj.enumchron.escapeHtml() + ")";
756 title += "</a></span>";
759 title += " " + __("by _AUTHOR_").replace( "_AUTHOR_", " " + oObj.author.escapeHtml() );
762 if ( oObj.itemnotes ) {
764 if ( flatpickr.formatDate( new Date(oObj.issuedate), "Y-m-d" ) == ymd ){
765 span_class = "circ-hlt";
767 title += " - <span class='" + span_class + "'>" + oObj.itemnotes.escapeHtml() + "</span>"
770 if ( oObj.itemnotes_nonpublic ) {
772 if ( flatpickr.formatDate( new Date(oObj.issuedate), "Y-m-d" ) == ymd ){
773 span_class = "circ-hlt";
775 title += " - <span class='" + span_class + "'>" + oObj.itemnotes_nonpublic.escapeHtml() + "</span>"
778 var onsite_checkout = '';
779 if ( oObj.onsite_checkout == 1 ) {
780 onsite_checkout += " <span class='onsite_checkout'>(" + __("On-site checkout") + ")</span>";
784 + "<a href='/cgi-bin/koha/catalogue/moredetail.pl?biblionumber="
791 + (oObj.barcode ? oObj.barcode.escapeHtml() : "")
800 "mDataProp": function ( oObj ) {
801 return oObj.recordtype_description.escapeHtml();
805 "mDataProp": function ( oObj ) {
806 return oObj.itemtype_description.escapeHtml();
810 "mDataProp": function ( oObj ) {
811 return ( oObj.collection ? oObj.collection.escapeHtml() : '' );
815 "mDataProp": function ( oObj ) {
816 return ( oObj.location ? oObj.location.escapeHtml() : '' );
820 "mDataProp": "issuedate",
824 "iDataSort": 7, // Sort on hidden unformatted issuedate column
825 "mDataProp": "issuedate_formatted",
828 "mDataProp": function ( oObj ) {
829 return ( oObj.branchname ? oObj.branchname.escapeHtml() : '' );
833 "mDataProp": function ( oObj ) {
834 return ( oObj.itemcallnumber ? oObj.itemcallnumber.escapeHtml() : '' );
838 "mDataProp": function ( oObj ) {
839 return ( oObj.copynumber ? oObj.copynumber.escapeHtml() : '' );
843 "mDataProp": function ( oObj ) {
844 if ( ! oObj.charge ) oObj.charge = 0;
845 return parseFloat(oObj.charge).toFixed(2);
849 "mDataProp": function ( oObj ) {
850 if ( ! oObj.fine ) oObj.fine = 0;
851 return parseFloat(oObj.fine).toFixed(2);
855 "mDataProp": function ( oObj ) {
856 if ( ! oObj.price ) oObj.price = 0;
857 return parseFloat(oObj.price).toFixed(2);
861 "mDataProp": function( oObj ) {
862 return "<a href='/cgi-bin/koha/members/moremember.pl?borrowernumber=" + oObj.borrowernumber + "'>"
863 + ( oObj.borrower.firstname ? oObj.borrower.firstname.escapeHtml() : "" )
865 ( oObj.borrower.surname ? oObj.borrower.surname.escapeHtml() : "" )
866 + " (" + ( oObj.borrower.cardnumber ? oObj.borrower.cardnumber.escapeHtml() : "" ) + ")</a>"
872 "bServerSide": false,
873 "sAjaxSource": '/cgi-bin/koha/svc/checkouts',
874 "fnServerData": function ( sSource, aoData, fnCallback ) {
875 $.each(relatives_borrowernumbers, function( index, value ) {
876 aoData.push( { "name": "borrowernumber", "value": value } );
879 $.getJSON( sSource, aoData, function (json) {
883 }, table_settings_relatives_issues_table);
887 if ( $("#relatives-issues-table").length ) {
888 $("#relatives-issues-table_processing").position({
889 of: $( "#relatives-issues-table" ),
894 if ( AllowRenewalLimitOverride || AllowRenewalOnHoldOverride ) {
895 $( '#override_limit' ).click( function () {
896 if ( this.checked ) {
897 if ( AllowRenewalLimitOverride ) {
898 $( '.renewals-allowed' ).show();
899 $( '.renewals-disabled' ).hide();
901 if ( AllowRenewalOnHoldOverride ) {
902 $( '.renewals-allowed-on_reserve' ).show();
905 $( '.renewals-allowed' ).hide();
906 $( '.renewals-allowed-on_reserve' ).hide();
907 $( '.renewals-disabled' ).show();
909 } ).prop('checked', false);
912 // Refresh after return claim
913 $('body').on('refreshClaimModal', function () {
914 refreshReturnClaimsTable();
915 issuesTable.api().ajax.reload();
918 // Don't load return claims table unless it is clicked on
919 var returnClaimsTable;
920 $("#return-claims-tab").click( function() {
921 refreshReturnClaimsTable();
924 function refreshReturnClaimsTable(){
925 loadReturnClaimsTable();
926 $("#return-claims-table").DataTable().ajax.reload();
928 function loadReturnClaimsTable() {
929 if ( ! returnClaimsTable ) {
930 returnClaimsTable = $("#return-claims-table").dataTable({
935 { "bSortable": false, "bSearchable": false, 'aTargets': ['NoSort'] },
936 { "sType": "anti-the", "aTargets": ["anti-the"] },
944 "mDataProp": function (oObj) {
945 if (oObj.resolution) {
946 return "is_resolved";
948 return "is_unresolved";
954 "mDataProp": function ( oObj ) {
955 let title = '<a class="return-claim-title strong" href="/cgi-bin/koha/catalogue/detail.pl?biblionumber=' + oObj.biblionumber + '">'
957 + ( oObj.subtitle ? " " + oObj.subtitle : "" )
958 + ( oObj.enumchron || "" )
961 title += ' by ' + oObj.author;
963 title += ' <a href="/cgi-bin/koha/catalogue/moredetail.pl?biblionumber='
968 + (oObj.barcode ? oObj.barcode.escapeHtml() : "")
975 "sClass": "return-claim-notes-td",
976 "mDataProp": function ( oObj ) {
977 let notes = '<span id="return-claim-notes-static-' + oObj.id + '" class="return-claim-notes" data-return-claim-id="' + oObj.id + '">';
982 notes += '<i style="float:right" class="fa-solid fa-pen-to-square" title="' + __("Double click to edit") + '"></i>';
987 "mDataProp": function ( oObj ) {
988 let created_on = new Date( oObj.created_on );
989 return created_on.toLocaleDateString();
993 "mDataProp": function ( oObj ) {
994 if ( oObj.updated_on ) {
995 let updated_on = new Date( oObj.updated_on );
996 return updated_on.toLocaleDateString();
1003 "mDataProp": function ( oObj ) {
1004 if ( ! oObj.resolution ) return "";
1006 let desc = '<strong>' + oObj.resolution_data.lib + '</strong> <i>(';
1007 if (oObj.resolved_by_data) desc += '<a href="/cgi-bin/koha/circ/circulation.pl?borrowernumber=' + oObj.resolved_by_data.borrowernumber + '">' + ( oObj.resolved_by_data.firstname || "" ) + " " + ( oObj.resolved_by_data.surname || "" ) + '</a>';
1008 desc += ', ' + oObj.resolved_on + ')</i>';
1013 "mDataProp": function ( oObj ) {
1014 let delete_html = oObj.resolved_on
1015 ? '<li><a href="#" class="return-claim-tools-delete" data-return-claim-id="' + oObj.id + '"><i class="fa fa-trash-can"></i> ' + __("Delete") + '</a></li>'
1017 let resolve_html = ! oObj.resolution
1018 ? '<li><a href="#" class="return-claim-tools-resolve" data-return-claim-id="' + oObj.id + '" data-current-lost-status="' + escape_str(oObj.itemlost) + '"><i class="fa fa-check-square"></i> ' + __("Resolve") + '</a></li>'
1021 return '<div class="btn-group">'
1022 + ' <button type="button" class="btn btn-default btn-xs dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">'
1023 + __("Actions") + ' <span class="caret"></span>'
1025 + ' <ul class="dropdown-menu">'
1026 + ' <li><a href="#" class="return-claim-tools-editnotes" data-return-claim-id="' + oObj.id + '"><i class="fa-solid fa-pencil" aria-hidden="true"></i> ' + __("Edit notes") + '</a></li>'
1035 "bProcessing": true,
1036 "bServerSide": false,
1037 "sAjaxSource": '/cgi-bin/koha/svc/return_claims',
1038 "fnServerData": function ( sSource, aoData, fnCallback ) {
1039 aoData.push( { "name": "borrowernumber", "value": borrowernumber } );
1041 $.getJSON( sSource, aoData, function (json) {
1042 let resolved = json.resolved;
1043 let unresolved = json.unresolved;
1045 if ( resolved > 0 ) {
1046 $('#return-claims-count-resolved').text(resolved)
1047 .removeClass('label-default')
1048 .addClass('label-success');
1050 $('#return-claims-count-resolved').text(resolved)
1051 .removeClass('label-success')
1052 .addClass('label-default');
1054 if ( unresolved > 0 ) {
1055 $('#return-claims-count-unresolved').text(unresolved)
1056 .removeClass('label-default')
1057 .addClass('label-warning');
1059 $('#return-claims-count-unresolved').text(unresolved)
1060 .removeClass('label-warning')
1061 .addClass('label-default');
1067 "search": { "search": "is_unresolved" },
1068 "footerCallback": function (row, data, start, end, display) {
1069 var api = this.api();
1070 // Total over all pages
1071 var colData = api.column(1).data();
1072 var is_unresolved = 0;
1073 var is_resolved = 0;
1074 colData.each(function( index, value ){
1075 if( index == "is_unresolved" ){ is_unresolved++; }
1076 if (index == "is_resolved") { is_resolved++; }
1079 $("#return-claims-controls").html( showClaimFilter( is_unresolved, is_resolved ) )
1085 function showClaimFilter( is_unresolved, is_resolved ){
1086 var showAll, showUnresolved;
1087 var total = Number( is_unresolved ) + Number( is_resolved );
1089 showAll = __nx("Show 1 claim", "Show all {count} claims", total, { count: total });
1093 if( is_unresolved > 0 ){
1094 showUnresolved = __nx("Show 1 unresolved claim", "Show {count} unresolved claims", is_unresolved, { count: is_unresolved })
1096 showUnresolved = "";
1098 $("#show_all_claims").html( showAll );
1099 $("#show_unresolved_claims").html( showUnresolved );
1102 $('body').on('click', '.return-claim-tools-editnotes', function() {
1103 let id = $(this).data('return-claim-id');
1104 $('#return-claim-notes-static-' + id).parent().dblclick();
1106 $('body').on('dblclick', '.return-claim-notes-td', function() {
1107 let elt = $(this).children('.return-claim-notes');
1108 let id = elt.data('return-claim-id');
1109 if ( $('#return-claim-notes-editor-textarea-' + id).length == 0 ) {
1110 let note = elt.text();
1112 ' <span id="return-claim-notes-editor-' + id + '">'
1113 + ' <textarea id="return-claim-notes-editor-textarea-' + id + '">' + note + '</textarea>'
1115 + ' <a class="btn btn-default btn-xs claim-returned-notes-editor-submit" data-return-claim-id="' + id + '"><i class="fa fa-save"></i> ' + __("Update") + '</a>'
1116 + ' <a class="claim-returned-notes-editor-cancel" data-return-claim-id="' + id + '" href="#">' + __("Cancel") + '</a>'
1119 $(editor).insertAfter( elt );
1123 $('body').on('click', '.claim-returned-notes-editor-submit', function(){
1124 let id = $(this).data('return-claim-id');
1125 let notes = $('#return-claim-notes-editor-textarea-' + id).val();
1129 updated_by: logged_in_user_borrowernumber
1132 $(this).parent().remove();
1135 url: '/api/v1/return_claims/' + id + '/notes',
1137 data: JSON.stringify(params),
1138 success: function( data ) {
1139 let notes = $('#return-claim-notes-static-' + id);
1140 notes.text(data.notes);
1147 $('body').on('click', '.claim-returned-notes-editor-cancel', function(){
1148 let id = $(this).data('return-claim-id');
1149 $(this).parent().remove();
1150 $('#return-claim-notes-static-' + id).show();
1153 // Hanld return claim deletion
1154 $('body').on('click', '.return-claim-tools-delete', function() {
1155 let confirmed = confirm(__("Are you sure you want to delete this return claim?"));
1157 let id = $(this).data('return-claim-id');
1160 url: '/api/v1/return_claims/' + id,
1162 success: function( data ) {
1163 refreshReturnClaimsTable();
1164 issuesTable.api().ajax.reload();
1170 $("#show_all_claims").on("click", function(e){
1172 $(".ctrl_link").removeClass("disabled");
1173 $(this).addClass("disabled");
1174 $("#return-claims-table").DataTable().search("").draw();
1177 $("#show_unresolved_claims").on("click", function (e) {
1179 $(".ctrl_link").removeClass("disabled");
1180 $(this).addClass("disabled");
1181 $("#return-claims-table").DataTable().search("is_unresolved").draw();