From 571520daf88f6fa38987a9844c0f76607ce86803 Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Tue, 10 Mar 2020 16:03:50 -0300 Subject: [PATCH] Bug 20212: Use API to render orders datatable --- .../prog/en/modules/acqui/histsearch.tt | 229 +++++++++++ .../prog/en/modules/acqui/parcel.tt | 381 +++++++++++++++--- 2 files changed, 556 insertions(+), 54 deletions(-) diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/histsearch.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/histsearch.tt index e4df869231..0101ed8287 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/histsearch.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/histsearch.tt @@ -29,6 +29,29 @@ [% PROCESS filter_form context => "main" %] [% END %] +
+ + + + + + + + + + + + + + + + + + + + +
Order line (parent)StatusBasketBasket creatorBasket groupManaging libraryInvoice numberSummaryVendorPlaced onReceived onQuantity receivedPending orderUnit costFund
+
[% IF ( order_loop ) %]

Search results

@@ -145,6 +168,212 @@ patron_input_name: 'created_by', field_to_retrieve: 'borrowernumber' }); + + var pendig_orders_tb = $("#histsearcht_api").api({ + "ajax": { + "url": "/api/v1/acquisitions/orders" + }, + "embed": [ + "basket.basket_group", + "biblio.active_orders_count", + "biblio.holds_count", + "biblio.items_count", + "biblio.suggestions.suggester", + "fund", + "holds_count", + "items" + ], + 'dom': 'C<"top pager"ilpfB><"#filter_c">tr<"bottom pager"ip>', + "columnDefs": [ + { "targets": [ "nosort" ],"sortable": false,"searchable": false }, + { "type": "anti-the", "targets" : [ "anti-the" ] }, + { "type": "title-string", "targets" : [ "title-string" ] } + ], + "columns": [ + { "data": "order_id" }, + { "data": "status" }, + { "data": "basket_id", + "render": function(data, type, row, meta) { + if (type != 'display') return data; + return "" + row.basket.name + " (" + data + ")"; + } + }, + { "data": function(row, type, val, meta) { + if ( type != 'display' ) return row.basket.basket_group_id; + if ( row.basket.basket_group_id == null ) { + return _("No basket group"); + } + else { + return "" + + row.basket.basket_group.name + " (" + row.basket.basket_group_id + ")"; + } + } + }, + { "data": "order_id", + "render": function(data, type, row, meta) { + if (type != 'display') return data; + return ""+data+""; + } + }, + { "data": function(row, type, val, meta) { + var result = ""+row.biblio.title+""; + if ( row.biblio.author != null ) + result += _(" by ") + row.biblio.author; + if ( row.biblio.isbn != null ) + result += " – " + row.biblio.isbn; + if ( row.biblio.publisher != null ) { + result += "
" + _("Publisher: ") + row.biblio.publisher; + if ( row.biblio.publication_year != null ) { + result += ", " + row.biblio.publication_year; + } + else if ( row.biblio.copyright_date != null ) { + result += row.biblio.copyright_date; + } + } + var suggestions = row.biblio.suggestions; + if ( suggestions != null && suggestions.length > 0 ) { + var suggestion = suggestions[0]; + if ( suggestion.suggestor != null ) { + var suggestor = suggestion.suggestor; + var suggested_by = []; + if ( suggestor.surname != null ) { + suggested_by.push(suggestor.surname); + } + if ( suggestor.firstname != null ) { + suggested_by.push(suggestor.firstname); + } + + result += "
" + _("Suggested by: ") + + '' + + suggested_by.join(", ") + + " (#" + suggestions[0].suggestionid + ")"; + } + } + + var internal_note = row.internal_note; + if ( internal_note != '' ) { + result += '

' + + _("Internal note: ") + + '' + internal_note + + ' [' + _("Change internal note") + ']

'; + } + else { + result += ' [' + _("Add internal note") + ']'; + } + + var vendor_note = row.vendor_note; + if ( vendor_note != '' ) { + result += '

' + + _("Vendor note: ") + + '' + vendor_note + '

'; + } + else { + result += ' [' + _("Add vendor note") + ']'; + } + + return result; + } + }, + { "data": function( row, type, val, meta) { + if (type != 'display') return data; + var result = '' + _('Order') + '
' + + '' + _("MARC") + '
' + + '' + _("Card") + ''; + return result; + } + }, + { "data": "replacement_price" }, + { "data": "quantity" }, + { "data": "ecost" }, + { "data": function ( row, type, val, meta ) { + return row.quantity * row.ecost; + } + }, + { "data": "fund_id", + "render": function(data, type, row, meta) { + if (type != 'display') return data; + return row.fund.name; + } + }, + { + "data": function( row, type, val, meta ) { + return '' + + _("Receive") + '
' + + '' + + _("Transfer") + ''; + } + }, + { + "data": function( row, type, val, meta ) { + var result = ""; + + if ( row.holds_count > 0 ) { + result += '' + + _("Can't cancel order") + '
'; + } + else { + result += '' + + _("Cancel order") + '
'; + } + + if ( row.items.length > 0 || + row.biblio.active_orders_count > 1 || + row.biblio.subscriptions_count > 0 || + row.bibio.holds_count > 0 ) { // biblio can be deleted + result += '' + + _("Can't cancel order and delete catalog record") + '
'; + } + else { + result += '' + + _("Cancel order and catalog record") + '
'; + } + + if ( row.items.length > 0 ) { + result += '' + (row.biblio.items_count - row.items.length) + _(" item(s) left") + '
'; + } + + if ( row.biblio.active_orders_count > 1 ) { + result += '' + + (row.biblio.active_orders_count - 1) + _(" order(s) left") + '
'; + } + + if ( row.biblio.subscriptions_count > 0 ) { + result += '' + + _("%s subscription(s) left").format(row.biblio.subscriptions_count) + + '
'; + } + + if ( row.biblio.holds_count > 0 ) { + result += '' + + _("%s hold(s) left").format(row.bibio.holds_count) + ''; + } + + return result; + } + } + ] + }); }); [% END %] diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/parcel.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/parcel.tt index 414844397c..e85d94a636 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/parcel.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/parcel.tt @@ -34,16 +34,16 @@
- [% IF ( receive_error ) %] -
-

Error adding items:

-
    - [% FOREACH error_loo IN error_loop %] -
  • [% error_loo.error_param | html %][% IF ( error_loo.error_duplicate_barcode ) %]Duplicate Barcode[% END %]
  • - [% END %] -
-
- [% END %] + [% IF ( receive_error ) %] +
+

Error adding items:

+
    + [% FOREACH error_loo IN error_loop %] +
  • [% error_loo.error_param | html %][% IF ( error_loo.error_duplicate_barcode ) %]Duplicate Barcode[% END %]
  • + [% END %] +
+
+ [% END %]

[% IF datereceived %] Receipt summary for [% name | html %] [% IF ( invoice ) %] [ [% invoice | html %] ] [% END %] on [% datereceived | $KohaDates %] @@ -55,12 +55,12 @@ [% IF ( success_delorder ) %]
The order has been successfully canceled.
[% ELSE %] - [% IF ( error_delitem ) %] -
The order has been canceled, although one or more items could not have been deleted.
- [% END %] - [% IF ( error_delbiblio ) %] -
The order has been canceled, although the record has not been deleted.
- [% END %] + [% IF ( error_delitem ) %] +
The order has been canceled, although one or more items could not have been deleted.
+ [% END %] + [% IF ( error_delbiblio ) %] +
The order has been canceled, although the record has not been deleted.
+ [% END %] [% END %] [% IF (error_cancelling_receipt) %] @@ -87,6 +87,26 @@

[% END %] +

Pending orders (api)

+ + + + + + + + + + + + + + + + + +
BasketBasket groupOrder lineSummaryMoreReplacement priceQuantityUnit costOrder costFund  
+ [% UNLESS no_orders_to_display %]

Invoice number: [% invoice | html %] Received by: [% logged_in_user.userid | html %] On: [% datereceived | $KohaDates %]

@@ -175,32 +195,32 @@ [% loop_order.ecost | $Price %] [% loop_order.total | $Price %] [% loop_order.budget_name | html %] - + Receive
Transfer - - - [% IF ( loop_order.left_holds_on_order ) %] + + + [% IF ( loop_order.left_holds_on_order ) %] [%# DONE %] Can't cancel order
- [% ELSE %] + [% ELSE %] [%# DONE %] Cancel order
- [% END %] - [% IF ( loop_order.can_del_bib ) %] + [% END %] [%# DONE %] + [% IF ( loop_order.can_del_bib ) %] [%# DONE %] Cancel order and catalog record
- [% ELSE %] + [% ELSE %] [%# DONE %] Can't cancel order and delete catalog record
[% END %] - [% IF ( loop_order.left_item ) %] + [% IF ( loop_order.left_item ) %] [%# DONE %] [% loop_order.items | html %] item(s) left
[% END %] - [% IF ( loop_order.left_biblio ) %] + [% IF ( loop_order.left_biblio ) %] [%# DONE %] [% loop_order.biblios | html %] order(s) left
[% END %] - [% IF ( loop_order.left_subscription ) %] + [% IF ( loop_order.left_subscription ) %] [%# DONE %] [% loop_order.subscriptions | html %] subscription(s) left
[% END %] - [% IF ( loop_order.left_holds ) %] + [% IF ( loop_order.left_holds ) %] [%# DONE %] [% loop_order.holds | html %] hold(s) left [% END %] @@ -365,12 +385,12 @@ [% END %] - [% END %] - + [% END %] + - [% ELSE %]There are no received orders.[% END %] + [% ELSE %]There are no received orders.[% END %]