mirror of
https://github.com/inventree/InvenTree.git
synced 2025-06-18 13:05:42 +00:00
Merge remote-tracking branch 'inventree/master' into drf-api-forms
# Conflicts: # InvenTree/InvenTree/static/css/inventree.css
This commit is contained in:
@ -769,6 +769,159 @@ function loadPartTestTemplateTable(table, options) {
|
||||
}
|
||||
|
||||
|
||||
function loadPriceBreakTable(table, options) {
|
||||
/*
|
||||
* Load PriceBreak table.
|
||||
*/
|
||||
|
||||
var name = options.name || 'pricebreak';
|
||||
var human_name = options.human_name || 'price break';
|
||||
var linkedGraph = options.linkedGraph || null;
|
||||
var chart = null;
|
||||
|
||||
table.inventreeTable({
|
||||
name: name,
|
||||
method: 'get',
|
||||
formatNoMatches: function() {
|
||||
return `{% trans "No ${human_name} information found" %}`;
|
||||
},
|
||||
url: options.url,
|
||||
onLoadSuccess: function(tableData) {
|
||||
if (linkedGraph) {
|
||||
// sort array
|
||||
tableData = tableData.sort((a,b)=>a.quantity-b.quantity);
|
||||
|
||||
// split up for graph definition
|
||||
var graphLabels = Array.from(tableData, x => x.quantity);
|
||||
var graphData = Array.from(tableData, x => parseFloat(x.price));
|
||||
|
||||
// destroy chart if exists
|
||||
if (chart){
|
||||
chart.destroy();
|
||||
}
|
||||
chart = loadLineChart(linkedGraph,
|
||||
{
|
||||
labels: graphLabels,
|
||||
datasets: [
|
||||
{
|
||||
label: '{% trans "Unit Price" %}',
|
||||
data: graphData,
|
||||
backgroundColor: 'rgba(255, 206, 86, 0.2)',
|
||||
borderColor: 'rgb(255, 206, 86)',
|
||||
stepped: true,
|
||||
fill: true,
|
||||
},]
|
||||
}
|
||||
);
|
||||
}
|
||||
},
|
||||
columns: [
|
||||
{
|
||||
field: 'pk',
|
||||
title: 'ID',
|
||||
visible: false,
|
||||
switchable: false,
|
||||
},
|
||||
{
|
||||
field: 'quantity',
|
||||
title: '{% trans "Quantity" %}',
|
||||
sortable: true,
|
||||
},
|
||||
{
|
||||
field: 'price',
|
||||
title: '{% trans "Price" %}',
|
||||
sortable: true,
|
||||
formatter: function(value, row, index) {
|
||||
var html = value;
|
||||
|
||||
html += `<div class='btn-group float-right' role='group'>`
|
||||
|
||||
html += makeIconButton('fa-edit icon-blue', `button-${name}-edit`, row.pk, `{% trans "Edit ${human_name}" %}`);
|
||||
html += makeIconButton('fa-trash-alt icon-red', `button-${name}-delete`, row.pk, `{% trans "Delete ${human_name}" %}`);
|
||||
|
||||
html += `</div>`;
|
||||
|
||||
return html;
|
||||
}
|
||||
},
|
||||
]
|
||||
});
|
||||
}
|
||||
|
||||
function loadLineChart(context, data) {
|
||||
return new Chart(context, {
|
||||
type: 'line',
|
||||
data: data,
|
||||
options: {
|
||||
responsive: true,
|
||||
maintainAspectRatio: false,
|
||||
plugins: {
|
||||
legend: {position: 'bottom'},
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function initPriceBreakSet(table, options) {
|
||||
|
||||
var part_id = options.part_id;
|
||||
var pb_human_name = options.pb_human_name;
|
||||
var pb_url_slug = options.pb_url_slug;
|
||||
var pb_url = options.pb_url;
|
||||
var pb_new_btn = options.pb_new_btn;
|
||||
var pb_new_url = options.pb_new_url;
|
||||
|
||||
var linkedGraph = options.linkedGraph || null;
|
||||
|
||||
loadPriceBreakTable(
|
||||
table,
|
||||
{
|
||||
name: pb_url_slug,
|
||||
human_name: pb_human_name,
|
||||
url: pb_url,
|
||||
linkedGraph: linkedGraph,
|
||||
}
|
||||
);
|
||||
|
||||
function reloadPriceBreakTable(){
|
||||
table.bootstrapTable("refresh");
|
||||
}
|
||||
|
||||
pb_new_btn.click(function() {
|
||||
launchModalForm(pb_new_url,
|
||||
{
|
||||
success: reloadPriceBreakTable,
|
||||
data: {
|
||||
part: part_id,
|
||||
}
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
table.on('click', `.button-${pb_url_slug}-delete`, function() {
|
||||
var pk = $(this).attr('pk');
|
||||
|
||||
launchModalForm(
|
||||
`/part/${pb_url_slug}/${pk}/delete/`,
|
||||
{
|
||||
success: reloadPriceBreakTable
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
table.on('click', `.button-${pb_url_slug}-edit`, function() {
|
||||
var pk = $(this).attr('pk');
|
||||
|
||||
launchModalForm(
|
||||
`/part/${pb_url_slug}/${pk}/edit/`,
|
||||
{
|
||||
success: reloadPriceBreakTable
|
||||
}
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
function loadStockPricingChart(context, data) {
|
||||
return new Chart(context, {
|
||||
type: 'bar',
|
||||
@ -824,3 +977,36 @@ function loadBomChart(context, data) {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function loadSellPricingChart(context, data) {
|
||||
return new Chart(context, {
|
||||
type: 'line',
|
||||
data: data,
|
||||
options: {
|
||||
responsive: true,
|
||||
maintainAspectRatio: false,
|
||||
plugins: {legend: {position: 'bottom'}},
|
||||
scales: {
|
||||
y: {
|
||||
type: 'linear',
|
||||
position: 'left',
|
||||
grid: {display: false},
|
||||
title: {
|
||||
display: true,
|
||||
text: '{% trans "Unit Price" %}'
|
||||
}
|
||||
},
|
||||
y1: {
|
||||
type: 'linear',
|
||||
position: 'right',
|
||||
grid: {display: false},
|
||||
titel: {
|
||||
display: true,
|
||||
text: '{% trans "Quantity" %}',
|
||||
position: 'right'
|
||||
}
|
||||
},
|
||||
},
|
||||
}
|
||||
});
|
||||
}
|
||||
|
Reference in New Issue
Block a user