diff --git a/InvenTree/templates/js/translated/order.js b/InvenTree/templates/js/translated/order.js index 827436bfde..51bb21dee4 100644 --- a/InvenTree/templates/js/translated/order.js +++ b/InvenTree/templates/js/translated/order.js @@ -26,6 +26,7 @@ editPurchaseOrderLineItem, exportOrder, loadPurchaseOrderLineItemTable, + loadPurchaseOrderAdditionalLineItemTable loadPurchaseOrderTable, loadSalesOrderAllocationTable, loadSalesOrderLineItemTable, @@ -1397,6 +1398,230 @@ function loadPurchaseOrderLineItemTable(table, options={}) { } +/** + * Load a table displaying line items for a particular PurchaseOrder + * + * @param {String} table : HTML ID tag e.g. '#table' + * @param {Object} options : object which contains: + * - order {integer} : pk of the PurchaseOrder + * - status: {integer} : status code for the order + */ + function loadPurchaseOrderAdditionalLineItemTable(table, options={}) { + + options.table = table; + + options.params = options.params || {}; + + if (!options.order) { + console.log('ERROR: function called without order ID'); + return; + } + + if (!options.status) { + console.log('ERROR: function called without order status'); + return; + } + + options.params.order = options.order; + options.params.part_detail = true; + options.params.allocations = true; + + var filters = loadTableFilters('purchaseorderadditionallineitem'); + + for (var key in options.params) { + filters[key] = options.params[key]; + } + + options.url = options.url || '{% url "api-po-additional-line-list" %}'; + + var filter_target = options.filter_target || '#filter-list-purchase-order-additional-lines'; + + setupFilterList('purchaseorderadditionallineitem', $(table), filter_target); + + // Is the order pending? + var pending = options.status == {{ SalesOrderStatus.PENDING }}; + + // Table columns to display + var columns = [ + { + sortable: true, + field: 'reference', + title: '{% trans "Reference" %}', + switchable: true, + }, + { + sortable: true, + field: 'quantity', + title: '{% trans "Quantity" %}', + footerFormatter: function(data) { + return data.map(function(row) { + return +row['quantity']; + }).reduce(function(sum, i) { + return sum + i; + }, 0); + }, + switchable: false, + }, + { + sortable: true, + field: 'sale_price', + title: '{% trans "Unit Price" %}', + formatter: function(value, row) { + var formatter = new Intl.NumberFormat( + 'en-US', + { + style: 'currency', + currency: row.sale_price_currency + } + ); + + return formatter.format(row.sale_price); + } + }, + { + field: 'total_price', + sortable: true, + title: '{% trans "Total Price" %}', + formatter: function(value, row) { + var formatter = new Intl.NumberFormat( + 'en-US', + { + style: 'currency', + currency: row.sale_price_currency + } + ); + + return formatter.format(row.sale_price * row.quantity); + }, + footerFormatter: function(data) { + var total = data.map(function(row) { + return +row['sale_price'] * row['quantity']; + }).reduce(function(sum, i) { + return sum + i; + }, 0); + + var currency = (data.slice(-1)[0] && data.slice(-1)[0].sale_price_currency) || 'USD'; + + var formatter = new Intl.NumberFormat( + 'en-US', + { + style: 'currency', + currency: currency + } + ); + + return formatter.format(total); + } + } + ]; + + columns.push({ + field: 'notes', + title: '{% trans "Notes" %}', + }); + + if (pending) { + columns.push({ + field: 'buttons', + switchable: false, + formatter: function(value, row, index, field) { + + var html = `