From f872568124f6554bf82df509c96a33d825fd4d6b Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Fri, 17 Jan 2020 13:07:34 -0300 Subject: [PATCH] [WIP] Bug 20212: Use the API to render orders --- api/v1/swagger/definitions/order.json | 4 +- api/v1/swagger/paths/acquisitions_orders.json | 16 +- .../prog/en/modules/acqui/histsearch.tt | 229 ++++++++++++++++ .../prog/en/modules/acqui/parcel.tt | 255 +++++++++++++++++- 4 files changed, 485 insertions(+), 19 deletions(-) diff --git a/api/v1/swagger/definitions/order.json b/api/v1/swagger/definitions/order.json index 0432f6dda3..df89fea079 100644 --- a/api/v1/swagger/definitions/order.json +++ b/api/v1/swagger/definitions/order.json @@ -302,9 +302,9 @@ "null" ] }, - "holds_count": { + "current_holds_count": { "type": "integer", - "description": "Holds count for associated items" + "description": "Current holds count for associated items" }, "fund": { "type": [ diff --git a/api/v1/swagger/paths/acquisitions_orders.json b/api/v1/swagger/paths/acquisitions_orders.json index 360f25b0ee..66f4e2f765 100644 --- a/api/v1/swagger/paths/acquisitions_orders.json +++ b/api/v1/swagger/paths/acquisitions_orders.json @@ -103,12 +103,12 @@ "basket.basket_group", "basket.creator", "biblio", - "biblio.active_orders_count", - "biblio.holds_count", - "biblio.items_count", + "biblio.active_orders+count", + "biblio.holds+count", + "biblio.items+count", "biblio.suggestions.suggester", "fund", - "holds_count", + "current_holds+count", "invoice", "items", "subscription" @@ -250,12 +250,12 @@ "basket.basket_group", "basket.creator", "biblio", - "biblio.active_orders_count", - "biblio.holds_count", - "biblio.items_count", + "biblio.active_orders+count", + "biblio.holds+count", + "biblio.items+count", "biblio.suggestions.suggester", "fund", - "holds_count", + "current_holds+count", "invoice", "items", "subscription" 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..f4a4e0c49d 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/parcel.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/parcel.tt @@ -3,6 +3,7 @@ [% USE Koha %] [% USE KohaDates %] [% USE Price %] +[% USE Currencies %] [% USE currency = format('%.2f') -%] [% PROCESS 'i18n.inc' %] [% SET footerjs = 1 %] @@ -87,6 +88,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 %]

@@ -181,26 +202,26 @@ 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 %] @@ -452,6 +473,7 @@ [% MACRO jsinclude BLOCK %] [% Asset.js("js/acquisitions-menu.js") | $raw %] [% INCLUDE 'datatables.inc' %] + [% INCLUDE 'currency.inc' %] [% Asset.js("lib/jquery/plugins/jquery.dataTables.columnFilter.js") | $raw %] [% Asset.js("lib/jquery/plugins/jquery.cookie.min.js") | $raw %] @@ -533,6 +555,221 @@ })); } + var pendig_orders_tb = $("#pending_orders").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", + "current_holds+count", + "items" + ], + 'dom': 'C<"top pager"ilpfB><"#filter_c">tr<"bottom pager"ip>', + "columns": [ + { "data": "basket_id", + "orderable": true, + "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 + ")"; + } + }, + "orderable": false // FIXME + }, + { "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.suggester != null ) { + var suggester = suggestion.suggester; + var suggested_by = []; + if ( suggester.surname != null ) { + suggested_by.push(suggester.surname); + } + if ( suggester.firstname != null ) { + suggested_by.push(suggester.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; + }, + "orderable": false // FIXME + }, + { "data": function( row, type, val, meta) { + var result = '' + _('Order') + '
' + + '' + _("MARC") + '
' + + '' + _("Card") + ''; + return result; + }, + "orderable": false + }, + { "data": "replacement_price", + "render": function(data, type, val, meta) { + if (type != 'display') return data; + return data.format_price(); + } + }, + { "data": "quantity" }, + { "data": "ecost", + "render": function(data, type, val, meta) { + if (type != 'display') return data; + return data.format_price(); + } + }, + { "data": function ( row, type, val, meta ) { + return (row.quantity * row.ecost).format_price(); + } + }, + { "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") + ''; + }, + "orderable": false + }, + { + "data": function( row, type, val, meta ) { + var result = ""; + + if ( row.current_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.biblio.items_count - 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; + }, + "orderable": false + } + ] + }); + + // Keep filters from finishreceive.pl to parcel.pl $.cookie("filter_parcel_summary", $("#summaryfilter").val()); $.cookie("filter_parcel_basketname", $("#basketfilter").val()); -- 2.17.1