sales analytics based on sales order/delivery note/sales invoice

This commit is contained in:
Nabin Hait 2013-01-24 18:24:33 +05:30
parent 665175e0c1
commit 96601597e3
2 changed files with 55 additions and 13 deletions

View File

@ -34,8 +34,10 @@ erpnext.SalesAnalytics = wn.views.TreeGridReport.extend({
page: wrapper,
parent: $(wrapper).find('.layout-main'),
appframe: wrapper.appframe,
doctypes: ["Item", "Item Group", "Customer", "Customer Group", "Company",
"Sales Invoice", "Sales Invoice Item", "Territory"],
doctypes: ["Item", "Item Group", "Customer", "Customer Group", "Company", "Territory",
"Fiscal Year", "Sales Invoice", "Sales Invoice Item",
"Sales Order", "Sales Order Item[Sales Analytics]",
"Delivery Note", "Delivery Note Item[Sales Analytics]"],
tree_grid: { show: true }
});
@ -45,13 +47,7 @@ erpnext.SalesAnalytics = wn.views.TreeGridReport.extend({
show: true,
item_key: "customer",
parent_field: "parent_customer_group",
formatter: function(item) {
// return repl('<a href="#Report2/stock-invoices/customer=%(enc_value)s">%(value)s</a>', {
// value: item.name,
// enc_value: encodeURIComponent(item.name)
// });
return item.name;
}
formatter: function(item) { return item.name; }
},
"Customer": {
label: "Customer",
@ -110,6 +106,8 @@ erpnext.SalesAnalytics = wn.views.TreeGridReport.extend({
filter: function(val, item, opts, me) {
return me.apply_zero_filter(val, item, opts, me);
}},
{fieldtype:"Select", label: "Based On", options:["Sales Invoice",
"Sales Order", "Delivery Note"]},
{fieldtype:"Select", label: "Value or Qty", options:["Value", "Quantity"]},
{fieldtype:"Select", label: "Company", link:"Company",
default_value: "Select Company..."},
@ -132,6 +130,10 @@ erpnext.SalesAnalytics = wn.views.TreeGridReport.extend({
this.filter_inputs.tree_type.change(function() {
me.filter_inputs.refresh.click();
});
this.filter_inputs.based_on.change(function() {
me.filter_inputs.refresh.click();
});
this.show_zero_check()
this.setup_plot_check();
@ -143,8 +145,6 @@ erpnext.SalesAnalytics = wn.views.TreeGridReport.extend({
prepare_data: function() {
var me = this;
if (!this.tl) {
this.make_transaction_list("Sales Invoice", "Sales Invoice Item");
// add 'Not Set' Customer & Item
// (Customer / Item are not mandatory!!)
wn.report_dump.data["Customer"].push({
@ -160,6 +160,10 @@ erpnext.SalesAnalytics = wn.views.TreeGridReport.extend({
id: "Not Set",
});
}
if (!this.tl || !this.tl[this.based_on]) {
this.make_transaction_list(this.based_on, this.based_on + " Item");
}
if(!this.data || me.item_type != me.tree_type) {
if(me.tree_type=='Customer') {
@ -214,11 +218,12 @@ erpnext.SalesAnalytics = wn.views.TreeGridReport.extend({
var to_date = dateutil.str_to_obj(this.to_date);
var is_val = this.value_or_qty == 'Value';
$.each(this.tl, function(i, tl) {
$.each(this.tl[this.based_on], function(i, tl) {
if (me.is_default('company') ? true : me.apply_filter(tl, "company")) {
var posting_date = dateutil.str_to_obj(tl.posting_date);
if (posting_date >= from_date && posting_date <= to_date) {
var item = me.item_by_name[tl[me.tree_grid.item_key]] || me.item_by_name['Not Set'];
var item = me.item_by_name[tl[me.tree_grid.item_key]] ||
me.item_by_name['Not Set'];
item[me.column_map[tl.posting_date].field] += (is_val ? tl.amount : tl.qty);
}
}

View File

@ -134,6 +134,7 @@ data_map = {
"warehouse": ["Warehouse", "name"]
},
},
"Sales Order Item": {
"columns": ["item_code", "(ifnull(qty, 0) - ifnull(delivered_qty, 0)) as qty",
"reserved_warehouse as warehouse"],
@ -185,6 +186,42 @@ data_map = {
"item_code": ["Item", "name"]
}
},
"Sales Order": {
"columns": ["name", "customer", "transaction_date as posting_date", "company"],
"conditions": ["docstatus=1"],
"order_by": "transaction_date",
"links": {
"customer": ["Customer", "name"],
"company":["Company", "name"]
}
},
"Sales Order Item[Sales Analytics]": {
"columns": ["parent", "item_code", "qty", "amount"],
"conditions": ["docstatus=1", "ifnull(parent, '')!=''"],
"order_by": "parent",
"links": {
"parent": ["Sales Order", "name"],
"item_code": ["Item", "name"]
}
},
"Delivery Note": {
"columns": ["name", "customer", "posting_date", "company"],
"conditions": ["docstatus=1"],
"order_by": "posting_date",
"links": {
"customer": ["Customer", "name"],
"company":["Company", "name"]
}
},
"Delivery Note Item[Sales Analytics]": {
"columns": ["parent", "item_code", "qty", "amount"],
"conditions": ["docstatus=1", "ifnull(parent, '')!=''"],
"order_by": "parent",
"links": {
"parent": ["Delivery Note", "name"],
"item_code": ["Item", "name"]
}
},
"Supplier": {
"columns": ["name", "if(supplier_name=name, '', supplier_name) as supplier_name",
"supplier_type as parent_supplier_type"],