2018-11-12 10:45:54 +00:00
|
|
|
// Copyright (c) 2016, Frappe Technologies Pvt. Ltd. and contributors
|
|
|
|
// For license information, please see license.txt
|
|
|
|
/* eslint-disable */
|
|
|
|
|
|
|
|
frappe.query_reports["Sales Analytics"] = {
|
|
|
|
"filters": [
|
|
|
|
{
|
|
|
|
fieldname: "tree_type",
|
|
|
|
label: __("Tree Type"),
|
|
|
|
fieldtype: "Select",
|
2020-09-11 08:29:07 +00:00
|
|
|
options: ["Customer Group", "Customer", "Item Group", "Item", "Territory", "Order Type", "Project"],
|
2018-11-12 10:45:54 +00:00
|
|
|
default: "Customer",
|
|
|
|
reqd: 1
|
|
|
|
},
|
|
|
|
{
|
|
|
|
fieldname: "doc_type",
|
|
|
|
label: __("based_on"),
|
|
|
|
fieldtype: "Select",
|
|
|
|
options: ["Sales Order","Delivery Note","Sales Invoice"],
|
|
|
|
default: "Sales Invoice",
|
|
|
|
reqd: 1
|
|
|
|
},
|
|
|
|
{
|
|
|
|
fieldname: "value_quantity",
|
|
|
|
label: __("Value Or Qty"),
|
|
|
|
fieldtype: "Select",
|
|
|
|
options: [
|
|
|
|
{ "value": "Value", "label": __("Value") },
|
|
|
|
{ "value": "Quantity", "label": __("Quantity") },
|
|
|
|
],
|
|
|
|
default: "Value",
|
|
|
|
reqd: 1
|
|
|
|
},
|
|
|
|
{
|
|
|
|
fieldname: "from_date",
|
|
|
|
label: __("From Date"),
|
|
|
|
fieldtype: "Date",
|
|
|
|
default: frappe.defaults.get_user_default("year_start_date"),
|
|
|
|
reqd: 1
|
|
|
|
},
|
|
|
|
{
|
|
|
|
fieldname:"to_date",
|
|
|
|
label: __("To Date"),
|
|
|
|
fieldtype: "Date",
|
|
|
|
default: frappe.defaults.get_user_default("year_end_date"),
|
|
|
|
reqd: 1
|
|
|
|
},
|
|
|
|
{
|
|
|
|
fieldname: "company",
|
|
|
|
label: __("Company"),
|
|
|
|
fieldtype: "Link",
|
|
|
|
options: "Company",
|
|
|
|
default: frappe.defaults.get_user_default("Company"),
|
|
|
|
reqd: 1
|
|
|
|
},
|
|
|
|
{
|
|
|
|
fieldname: "range",
|
|
|
|
label: __("Range"),
|
|
|
|
fieldtype: "Select",
|
|
|
|
options: [
|
|
|
|
{ "value": "Weekly", "label": __("Weekly") },
|
|
|
|
{ "value": "Monthly", "label": __("Monthly") },
|
|
|
|
{ "value": "Quarterly", "label": __("Quarterly") },
|
|
|
|
{ "value": "Yearly", "label": __("Yearly") }
|
|
|
|
],
|
|
|
|
default: "Monthly",
|
|
|
|
reqd: 1
|
|
|
|
}
|
|
|
|
],
|
2018-11-30 10:45:43 +00:00
|
|
|
after_datatable_render: function(datatable_obj) {
|
|
|
|
$(datatable_obj.wrapper).find(".dt-row-0").find('input[type=checkbox]').click();
|
|
|
|
},
|
2018-11-12 10:45:54 +00:00
|
|
|
get_datatable_options(options) {
|
|
|
|
return Object.assign(options, {
|
|
|
|
checkboxColumn: true,
|
|
|
|
events: {
|
2020-12-16 09:11:04 +00:00
|
|
|
onCheckRow: function (data) {
|
|
|
|
if (!data) return;
|
|
|
|
const data_doctype = $(
|
|
|
|
data[2].html
|
|
|
|
)[0].attributes.getNamedItem("data-doctype").value;
|
|
|
|
const tree_type = frappe.query_report.filters[0].value;
|
|
|
|
if (data_doctype != tree_type) return;
|
|
|
|
|
2018-11-12 10:45:54 +00:00
|
|
|
row_name = data[2].content;
|
2018-12-15 10:06:09 +00:00
|
|
|
length = data.length;
|
|
|
|
|
2020-12-16 09:11:04 +00:00
|
|
|
if (tree_type == "Customer") {
|
|
|
|
row_values = data
|
|
|
|
.slice(4, length - 1)
|
|
|
|
.map(function (column) {
|
|
|
|
return column.content;
|
|
|
|
});
|
2019-10-12 17:32:53 +00:00
|
|
|
} else if (tree_type == "Item") {
|
2020-12-16 09:11:04 +00:00
|
|
|
row_values = data
|
|
|
|
.slice(5, length - 1)
|
|
|
|
.map(function (column) {
|
|
|
|
return column.content;
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
row_values = data
|
|
|
|
.slice(3, length - 1)
|
|
|
|
.map(function (column) {
|
|
|
|
return column.content;
|
|
|
|
});
|
2018-12-15 10:06:09 +00:00
|
|
|
}
|
|
|
|
|
2018-11-15 10:54:34 +00:00
|
|
|
entry = {
|
2020-12-16 09:11:04 +00:00
|
|
|
name: row_name,
|
|
|
|
values: row_values,
|
|
|
|
};
|
2018-11-12 10:45:54 +00:00
|
|
|
|
|
|
|
let raw_data = frappe.query_report.chart.data;
|
|
|
|
let new_datasets = raw_data.datasets;
|
|
|
|
|
2020-12-25 11:04:43 +00:00
|
|
|
let element_found = new_datasets.some((element, index, array)=>{
|
|
|
|
if(element.name == row_name){
|
|
|
|
array.splice(index, 1)
|
|
|
|
return true
|
2018-11-12 10:45:54 +00:00
|
|
|
}
|
2020-12-25 11:04:43 +00:00
|
|
|
return false
|
|
|
|
})
|
2018-11-12 10:45:54 +00:00
|
|
|
|
2020-12-25 11:04:43 +00:00
|
|
|
if (!element_found) {
|
2018-11-12 10:45:54 +00:00
|
|
|
new_datasets.push(entry);
|
|
|
|
}
|
|
|
|
|
|
|
|
let new_data = {
|
|
|
|
labels: raw_data.labels,
|
2020-12-16 09:11:04 +00:00
|
|
|
datasets: new_datasets,
|
|
|
|
};
|
|
|
|
chart_options = {
|
|
|
|
data: new_data,
|
|
|
|
type: "line",
|
|
|
|
};
|
|
|
|
frappe.query_report.render_chart(chart_options);
|
2018-11-12 10:45:54 +00:00
|
|
|
|
|
|
|
frappe.query_report.raw_chart_data = new_data;
|
|
|
|
},
|
2020-12-16 09:11:04 +00:00
|
|
|
},
|
|
|
|
});
|
2018-11-12 10:45:54 +00:00
|
|
|
},
|
|
|
|
}
|