mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-16 03:29:16 +00:00
[search criteria] [cleanup] removed search criteria folders and files
This commit is contained in:
@@ -1 +0,0 @@
|
||||
from __future__ import unicode_literals
|
||||
@@ -1 +0,0 @@
|
||||
from __future__ import unicode_literals
|
||||
@@ -1,20 +0,0 @@
|
||||
// ERPNext - web based ERP (http://erpnext.com)
|
||||
// Copyright (C) 2012 Web Notes Technologies Pvt Ltd
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
report.customize_filters = function() {
|
||||
this.filter_fields_dict['Delivery Note'+FILTER_SEP +'Company'].df['report_default'] = sys_defaults.company;
|
||||
this.filter_fields_dict['Delivery Note'+FILTER_SEP +'Fiscal Year'].df['report_default'] = sys_defaults.fiscal_year;
|
||||
}
|
||||
@@ -1,30 +0,0 @@
|
||||
[
|
||||
{
|
||||
"owner": "Administrator",
|
||||
"docstatus": 0,
|
||||
"creation": "2012-04-03 12:49:51",
|
||||
"modified_by": "Administrator",
|
||||
"modified": "2012-04-03 12:49:51"
|
||||
},
|
||||
{
|
||||
"add_col": "(`tabDelivery Note Item`.`qty`- ifnull(`tabDelivery Note Item`.`installed_qty`, 0)) AS 'Pending to Install'",
|
||||
"parent_doc_type": "Delivery Note",
|
||||
"module": "Selling",
|
||||
"standard": "Yes",
|
||||
"sort_order": "DESC",
|
||||
"filters": "{'Delivery Note\u0001Saved':1,'Delivery Note\u0001Submitted':1,'Delivery Note\u0001Status':'','Delivery Note\u0001Fiscal Year':''}",
|
||||
"description": "Delivered Items to be Install",
|
||||
"doc_type": "Delivery Note Item",
|
||||
"name": "__common__",
|
||||
"add_cond": "`tabDelivery Note Item`.`qty` > ifnull(`tabDelivery Note Item`.`installed_qty`, 0)",
|
||||
"doctype": "Search Criteria",
|
||||
"sort_by": "`tabDelivery Note`.`name`",
|
||||
"page_len": 50,
|
||||
"criteria_name": "Delivered Items to be Install",
|
||||
"columns": "Delivery Note\u0001ID,Delivery Note\u0001Status,Delivery Note\u0001Customer,Delivery Note\u0001Customer Name,Delivery Note\u0001Contact Person,Delivery Note\u0001Voucher Date,Delivery Note Item\u0001Item Code,Delivery Note Item\u0001Item Name,Delivery Note Item\u0001Quantity,Delivery Note Item\u0001Installed Qty,Delivery Note\u0001% Installed"
|
||||
},
|
||||
{
|
||||
"name": "delivered_items_to_be_install",
|
||||
"doctype": "Search Criteria"
|
||||
}
|
||||
]
|
||||
@@ -1 +0,0 @@
|
||||
from __future__ import unicode_literals
|
||||
@@ -1,22 +0,0 @@
|
||||
// ERPNext - web based ERP (http://erpnext.com)
|
||||
// Copyright (C) 2012 Web Notes Technologies Pvt Ltd
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
report.customize_filters = function() {
|
||||
this.filter_fields_dict['Sales Order'+FILTER_SEP +'From Sales Order Date'].df['report_default'] = sys_defaults.year_start_date;
|
||||
this.filter_fields_dict['Sales Order'+FILTER_SEP +'To Sales Order Date'].df['report_default'] = dateutil.obj_to_str(new Date());
|
||||
this.filter_fields_dict['Sales Order'+FILTER_SEP +'Company'].df['report_default'] = sys_defaults.company;
|
||||
|
||||
}
|
||||
@@ -1,29 +0,0 @@
|
||||
[
|
||||
{
|
||||
"creation": "2012-05-14 18:20:52",
|
||||
"docstatus": 0,
|
||||
"modified": "2013-01-30 15:19:07",
|
||||
"modified_by": "Administrator",
|
||||
"owner": "Administrator"
|
||||
},
|
||||
{
|
||||
"columns": "Sales Order\u0001ID,Sales Order\u0001Status,Sales Order\u0001Sales Order Date,Sales Order\u0001Customer,Sales Order\u0001P.O. No,Sales Order\u0001Currency,Sales Order\u0001Grand Total (Export)",
|
||||
"criteria_name": "Draft Sales Orders",
|
||||
"custom_query": "",
|
||||
"description": "List of Open Sales orders filtered by period, customer and other details",
|
||||
"doc_type": "Sales Order",
|
||||
"doctype": "Search Criteria",
|
||||
"filters": "{\"Sales Order\\u0001Saved\":1,\"Sales Order\\u0001Submitted\":1,\"Sales Order\\u0001To Sales Order Date\\u0001upper\":\"2013-01-30\",\"Sales Order\\u0001Company\":\"Alpha\",\"Sales Order\\u0001Fiscal Year\":[\"\"],\"Sales Order\\u0001Status\":[\"Draft\"]}",
|
||||
"module": "Selling",
|
||||
"name": "__common__",
|
||||
"page_len": 50,
|
||||
"report_script": null,
|
||||
"sort_by": "`tabSales Order`.`name`",
|
||||
"sort_order": "DESC",
|
||||
"standard": "Yes"
|
||||
},
|
||||
{
|
||||
"doctype": "Search Criteria",
|
||||
"name": "draft_sales_orders"
|
||||
}
|
||||
]
|
||||
@@ -1 +0,0 @@
|
||||
from __future__ import unicode_literals
|
||||
@@ -1,63 +0,0 @@
|
||||
// ERPNext - web based ERP (http://erpnext.com)
|
||||
// Copyright (C) 2012 Web Notes Technologies Pvt Ltd
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
report.customize_filters = function() {
|
||||
this.mytabs.items['Select Columns'].hide()
|
||||
this.mytabs.items['More Filters'].hide()
|
||||
|
||||
this.hide_all_filters();
|
||||
this.add_filter({fieldname:'follow_up_on', label:'Communication on', fieldtype:'Select', options:''+NEWLINE+'Lead'+NEWLINE+'Opportunity'+NEWLINE+'Quotation',ignore : 1,parent:'Communication Log', in_first_page : 1, single_select :1});
|
||||
this.add_filter({fieldname:'lead_name', label:'Lead', fieldtype:'Link', options:'Lead', report_default:'', ignore : 1, parent:'Communication Log', in_first_page : 1});
|
||||
this.add_filter({fieldname:'enq_name', label:'Opportunity', fieldtype:'Link', options:'Opportunity', report_default:'', ignore : 1, parent:'Communication Log', in_first_page : 1});
|
||||
this.add_filter({fieldname:'qtn_name', label:'Quotation', fieldtype:'Link', options:'Quotation', report_default:'', ignore : 1, parent:'Communication Log', in_first_page : 1});
|
||||
|
||||
this.get_filter('Communication Log', 'Communication type').set_as_single();
|
||||
this.set_filter_properties('Communication Log', 'Communication by', {filter_hide:0, in_first_page : 1});
|
||||
this.set_filter_properties('Communication Log', 'Communication type', {filter_hide:0, in_first_page : 1});
|
||||
this.set_filter_properties('Communication Log', 'From Date', {filter_hide:0, in_first_page : 1});
|
||||
this.set_filter_properties('Communication Log', 'To Date', {filter_hide:0, in_first_page : 1});
|
||||
|
||||
this.orig_sort_list = [['Date','`tabCommunication Log`.`date`'],['Document Type','`tabCommunication Log`.`parenttype`'],['Document','`tabCommunication Log`.`parent`'],['Follow Up By','`tabCommunication Log`.`follow_up_by`'],['Follow Up Type','`tabCommunication Log`.`follow_up_type`']];
|
||||
}
|
||||
|
||||
|
||||
report.get_query = function() {
|
||||
var lead_id = this.filter_fields_dict['Communication Log'+FILTER_SEP+'Lead'].get_value();
|
||||
var enq_id = this.filter_fields_dict['Communication Log'+FILTER_SEP+'Opportunity'].get_value();
|
||||
var quo_id = this.filter_fields_dict['Communication Log'+FILTER_SEP+'Quotation'].get_value();
|
||||
|
||||
var follow_up_on = this.filter_fields_dict['Communication Log'+FILTER_SEP+'Communication on'].get_value();
|
||||
var follow_up_by = this.filter_fields_dict['Communication Log'+FILTER_SEP+'Communication by'].get_value();
|
||||
|
||||
var on_type = this.filter_fields_dict['Communication Log'+FILTER_SEP+'Communication type'].get_value();
|
||||
var from_date = this.filter_fields_dict['Communication Log'+FILTER_SEP+'From Date'].get_value();
|
||||
var to_date = this.filter_fields_dict['Communication Log'+FILTER_SEP+'To Date'].get_value();
|
||||
|
||||
var cond = 'parenttype IN ("Lead","Opportunity","Quotation")';
|
||||
if(follow_up_on) cond = 'parenttype = "'+follow_up_on+'"';
|
||||
|
||||
if((follow_up_on == 'Lead' && lead_id) || (lead_id && !follow_up_on)) cond +=' AND parent = "'+lead_id+'"';
|
||||
if((follow_up_on == 'Opportunity' && enq_id) || (enq_id && !follow_up_on)) cond +=' AND parent = "'+enq_id+'"';
|
||||
if((follow_up_on == 'Quotation' && quo_id) || (quo_id && !follow_up_on)) cond +=' AND parent = "'+quo_id+'"';
|
||||
|
||||
if(on_type) cond += ' AND follow_up_type ="'+on_type+'"';
|
||||
if(from_date) cond += ' AND date >="'+from_date+'"';
|
||||
if(to_date) cond += ' AND date <="'+to_date+'"';
|
||||
if(follow_up_by) cond += ' AND follow_up_by = "'+follow_up_by+'"';
|
||||
|
||||
var q ='SELECT distinct `tabCommunication Log`.`parenttype`, `tabCommunication Log`.`parent`, `tabCommunication Log`.`date`, `tabCommunication Log`.`notes`, `tabCommunication Log`.`follow_up_type`, `tabCommunication Log`.`follow_up_by` FROM `tabCommunication Log` WHERE '+cond+' ORDER BY '+sel_val(this.dt.sort_sel)+' '+this.dt.sort_order;
|
||||
return q;
|
||||
}
|
||||
@@ -1,33 +0,0 @@
|
||||
# ERPNext - web based ERP (http://erpnext.com)
|
||||
# Copyright (C) 2012 Web Notes Technologies Pvt Ltd
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
from __future__ import unicode_literals
|
||||
follow_up_on = filter_values.get('follow_up_on')
|
||||
|
||||
cols = [['Document Type', 'Data', '150px', '']
|
||||
,['Document', 'Link', '150px', follow_up_on]
|
||||
,['Follow Up Date', 'Date', '150px', '']
|
||||
,['Description','Data','300px','']
|
||||
,['Follow Up Type','Data','150px','']
|
||||
,['Follow Up By','Link','150px','Sales Person']
|
||||
]
|
||||
|
||||
for c in cols:
|
||||
colnames.append(c[0])
|
||||
coltypes.append(c[1])
|
||||
colwidths.append(c[2])
|
||||
coloptions.append(c[3])
|
||||
col_idx[c[0]] = len(colnames)-1
|
||||
@@ -1,27 +0,0 @@
|
||||
[
|
||||
{
|
||||
"owner": "ashwini@webnotestech.com",
|
||||
"docstatus": 0,
|
||||
"creation": "2012-04-03 12:49:51",
|
||||
"modified_by": "Administrator",
|
||||
"modified": "2012-04-03 12:49:51"
|
||||
},
|
||||
{
|
||||
"parent_doc_type": "Lead",
|
||||
"module": "Selling",
|
||||
"standard": "Yes",
|
||||
"sort_order": "DESC",
|
||||
"filters": "{'Lead\u0001Status':'','Lead\u0001Source':'','Lead\u0001Lead Type':'','Lead\u0001Rating':'','Lead\u0001Market Segment':'','Lead\u0001Fiscal Year':''}",
|
||||
"doc_type": "Communication Log",
|
||||
"name": "__common__",
|
||||
"doctype": "Search Criteria",
|
||||
"sort_by": "`tabLead`.`name`",
|
||||
"page_len": 50,
|
||||
"criteria_name": "Follow-up Report",
|
||||
"columns": "Lead\u0001ID,Communication Log\u0001Date,Communication Log\u0001Notes,Communication Log\u0001Communication Log type"
|
||||
},
|
||||
{
|
||||
"name": "follow-up_report",
|
||||
"doctype": "Search Criteria"
|
||||
}
|
||||
]
|
||||
@@ -1 +0,0 @@
|
||||
from __future__ import unicode_literals
|
||||
@@ -1,21 +0,0 @@
|
||||
// ERPNext - web based ERP (http://erpnext.com)
|
||||
// Copyright (C) 2012 Web Notes Technologies Pvt Ltd
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
report.customize_filters = function() {
|
||||
this.filter_fields_dict['Delivery Note'+FILTER_SEP +'From Posting Date'].df['report_default'] = sys_defaults.year_start_date;
|
||||
this.filter_fields_dict['Delivery Note'+FILTER_SEP +'To Posting Date'].df['report_default'] = dateutil.obj_to_str(new Date());
|
||||
|
||||
}
|
||||
@@ -1,34 +0,0 @@
|
||||
# ERPNext - web based ERP (http://erpnext.com)
|
||||
# Copyright (C) 2012 Web Notes Technologies Pvt Ltd
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
from __future__ import unicode_literals
|
||||
out=[]
|
||||
qty,amt,bill_amt=0,0,0
|
||||
|
||||
for r in res:
|
||||
qty += flt(r[col_idx['Quantity']])
|
||||
amt += flt(r[col_idx['Amount*']])
|
||||
bill_amt += flt(r[col_idx['Billed Amt']])
|
||||
out.append(r)
|
||||
|
||||
|
||||
#Add the totals row
|
||||
l_row = ['' for i in range(len(colnames))]
|
||||
l_row[col_idx['Item Name']] = '<b>TOTALS</b>'
|
||||
l_row[col_idx['Quantity']] = qty
|
||||
l_row[col_idx['Amount*']] = amt
|
||||
l_row[col_idx['Billed Amt']] = bill_amt
|
||||
out.append(l_row)
|
||||
@@ -1,27 +0,0 @@
|
||||
[
|
||||
{
|
||||
"owner": "Administrator",
|
||||
"docstatus": 0,
|
||||
"creation": "2012-04-23 12:46:00",
|
||||
"modified_by": "Administrator",
|
||||
"modified": "2012-05-03 18:13:49"
|
||||
},
|
||||
{
|
||||
"parent_doc_type": "Delivery Note",
|
||||
"module": "Selling",
|
||||
"standard": "Yes",
|
||||
"sort_order": "DESC",
|
||||
"filters": "{\"Delivery Note\\u0001Submitted\":1,\"Delivery Note\\u0001Status\":[\"\"],\"Delivery Note\\u0001Fiscal Year\":[\"\"]}",
|
||||
"doc_type": "Delivery Note Item",
|
||||
"name": "__common__",
|
||||
"doctype": "Search Criteria",
|
||||
"sort_by": "`tabDelivery Note`.`name`",
|
||||
"page_len": 50,
|
||||
"criteria_name": "Itemwise Delivery Details",
|
||||
"columns": "Delivery Note\u0001ID,Delivery Note Item\u0001Item Code,Delivery Note Item\u0001Item Name,Delivery Note Item\u0001Quantity,Delivery Note Item\u0001Rate*,Delivery Note Item\u0001Amount*,Delivery Note Item\u0001Billed Amt"
|
||||
},
|
||||
{
|
||||
"name": "itemwise_delivery_details",
|
||||
"doctype": "Search Criteria"
|
||||
}
|
||||
]
|
||||
@@ -1 +0,0 @@
|
||||
from __future__ import unicode_literals
|
||||
@@ -1,27 +0,0 @@
|
||||
// ERPNext - web based ERP (http://erpnext.com)
|
||||
// Copyright (C) 2012 Web Notes Technologies Pvt Ltd
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
report.customize_filters = function() {
|
||||
this.filter_fields_dict['Sales Order'+FILTER_SEP +'ID'].df.in_first_page = 1;
|
||||
this.filter_fields_dict['Sales Order'+FILTER_SEP +'From Sales Order Date'].df['report_default'] = sys_defaults.year_start_date;
|
||||
this.filter_fields_dict['Sales Order'+FILTER_SEP +'To Sales Order Date'].df['report_default'] = dateutil.obj_to_str(new Date());
|
||||
this.filter_fields_dict['Sales Order'+FILTER_SEP +'Company'].df['report_default'] = sys_defaults.company;
|
||||
this.filter_fields_dict['Sales Order Item'+FILTER_SEP +'Item Code'].df.in_first_page = 1;
|
||||
this.filter_fields_dict['Sales Order'+FILTER_SEP +'Status'].df.filter_hide = 1;
|
||||
}
|
||||
|
||||
//this.mytabs.items['Select Columns'].hide();
|
||||
this.mytabs.items['More Filters'].hide();
|
||||
@@ -1,36 +0,0 @@
|
||||
# ERPNext - web based ERP (http://erpnext.com)
|
||||
# Copyright (C) 2012 Web Notes Technologies Pvt Ltd
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
from __future__ import unicode_literals
|
||||
out=[]
|
||||
qty,amt,del_qty,bill_amt=0,0,0,0
|
||||
|
||||
for r in res:
|
||||
qty += flt(r[col_idx['Quantity']])
|
||||
amt += flt(r[col_idx['Amount*']])
|
||||
del_qty += flt(r[col_idx['Delivered Qty']])
|
||||
bill_amt += flt(r[col_idx['Billed Amt']])
|
||||
out.append(r)
|
||||
|
||||
|
||||
#Add the totals row
|
||||
l_row = ['' for i in range(len(colnames))]
|
||||
l_row[col_idx['Item Name']] = '<b>TOTALS</b>'
|
||||
l_row[col_idx['Quantity']] = qty
|
||||
l_row[col_idx['Amount*']] = amt
|
||||
l_row[col_idx['Delivered Qty']] = del_qty
|
||||
l_row[col_idx['Billed Amt']] = bill_amt
|
||||
out.append(l_row)
|
||||
@@ -1,27 +0,0 @@
|
||||
[
|
||||
{
|
||||
"owner": "Administrator",
|
||||
"docstatus": 0,
|
||||
"creation": "2012-04-23 12:46:00",
|
||||
"modified_by": "Administrator",
|
||||
"modified": "2012-05-03 18:18:31"
|
||||
},
|
||||
{
|
||||
"parent_doc_type": "Sales Order",
|
||||
"module": "Selling",
|
||||
"standard": "Yes",
|
||||
"sort_order": "DESC",
|
||||
"filters": "{\"Sales Order\\u0001Submitted\":1,\"Sales Order\\u0001Fiscal Year\":[\"\"],\"Sales Order\\u0001Status\":[\"\"]}",
|
||||
"doc_type": "Sales Order Item",
|
||||
"name": "__common__",
|
||||
"doctype": "Search Criteria",
|
||||
"sort_by": "`tabSales Order`.`name`",
|
||||
"page_len": 50,
|
||||
"criteria_name": "Itemwise Sales Details",
|
||||
"columns": "Sales Order\u0001ID,Sales Order\u0001Customer,Sales Order Item\u0001Item Code,Sales Order Item\u0001Item Name,Sales Order Item\u0001Quantity,Sales Order Item\u0001Basic Rate*,Sales Order Item\u0001Amount*,Sales Order Item\u0001Delivered Qty,Sales Order Item\u0001Billed Amt"
|
||||
},
|
||||
{
|
||||
"name": "itemwise_sales_details",
|
||||
"doctype": "Search Criteria"
|
||||
}
|
||||
]
|
||||
@@ -1 +0,0 @@
|
||||
from __future__ import unicode_literals
|
||||
@@ -1,21 +0,0 @@
|
||||
// ERPNext - web based ERP (http://erpnext.com)
|
||||
// Copyright (C) 2012 Web Notes Technologies Pvt Ltd
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
report.customize_filters = function() {
|
||||
this.filter_fields_dict['Lead'+FILTER_SEP +'Status'].df.filter_hide = 1;
|
||||
this.filter_fields_dict['Lead'+FILTER_SEP +'Fiscal Year'].df['report_default'] = sys_defaults.fiscal_year;
|
||||
}
|
||||
|
||||
@@ -1,27 +0,0 @@
|
||||
[
|
||||
{
|
||||
"owner": "Administrator",
|
||||
"docstatus": 0,
|
||||
"creation": "2012-04-03 12:49:51",
|
||||
"modified_by": "Administrator",
|
||||
"modified": "2012-04-03 12:49:51"
|
||||
},
|
||||
{
|
||||
"module": "Selling",
|
||||
"standard": "Yes",
|
||||
"sort_order": "DESC",
|
||||
"filters": "{'Lead\u0001Status':'','Lead\u0001Source':'','Lead\u0001Expected Month':'','Lead\u0001Industry':'','Lead\u0001Market Segment':'','Lead\u0001Rating':''}",
|
||||
"doc_type": "Lead",
|
||||
"name": "__common__",
|
||||
"add_cond": "`tabLead`.status!='Converted' \n`tabLead`.status!='Lead Lost' \n`tabLead`.status!='Not Interested'",
|
||||
"doctype": "Search Criteria",
|
||||
"sort_by": "`tabLead`.`name`",
|
||||
"page_len": 50,
|
||||
"criteria_name": "Lead-To follow up",
|
||||
"columns": "Lead\u0001ID,Lead\u0001Status,Lead\u0001Lead Name,Lead\u0001Lead Date,Lead\u0001Lead Owner,Lead\u0001Next Contact Date"
|
||||
},
|
||||
{
|
||||
"name": "lead-to_follow_up",
|
||||
"doctype": "Search Criteria"
|
||||
}
|
||||
]
|
||||
@@ -1,27 +0,0 @@
|
||||
// ERPNext - web based ERP (http://erpnext.com)
|
||||
// Copyright (C) 2012 Web Notes Technologies Pvt Ltd
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
report.customize_filters = function() {
|
||||
this.hide_all_filters();
|
||||
this.filter_fields_dict['Sales Order'+FILTER_SEP +'Customer'].df.filter_hide = 0;
|
||||
this.filter_fields_dict['Sales Order'+FILTER_SEP +'ID'].df.filter_hide = 0;
|
||||
this.filter_fields_dict['Sales Order'+FILTER_SEP +'Quotation No'].df.filter_hide = 0;
|
||||
this.filter_fields_dict['Sales Order'+FILTER_SEP +'Company'].df.filter_hide = 0;
|
||||
this.filter_fields_dict['Sales Order'+FILTER_SEP +'Sales Partner'].df.filter_hide = 0;
|
||||
this.filter_fields_dict['Sales Order'+FILTER_SEP +'Fiscal Year'].df.filter_hide = 0;
|
||||
this.filter_fields_dict['Sales Order'+FILTER_SEP +'From Sales Order Date'].df.filter_hide = 0;
|
||||
this.filter_fields_dict['Sales Order'+FILTER_SEP +'To Sales Order Date'].df.filter_hide = 0;
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
from __future__ import unicode_literals
|
||||
@@ -1,27 +0,0 @@
|
||||
[
|
||||
{
|
||||
"owner": "Administrator",
|
||||
"docstatus": 0,
|
||||
"creation": "2012-03-30 14:50:44",
|
||||
"modified_by": "Administrator",
|
||||
"modified": "2012-03-30 14:50:44"
|
||||
},
|
||||
{
|
||||
"module": "Selling",
|
||||
"standard": "Yes",
|
||||
"sort_order": "DESC",
|
||||
"filters": "{'Opportunity\u0001Fiscal Year':''}",
|
||||
"doc_type": "Opportunity",
|
||||
"name": "__common__",
|
||||
"add_cond": "`tabOpportunity`.name=`tabQuotation`.enq_no\n`tabOpportunity`.docstatus=1\n`tabQuotation`.status='Submitted'",
|
||||
"doctype": "Search Criteria",
|
||||
"sort_by": "`tabOpportunity`.`name`",
|
||||
"page_len": 50,
|
||||
"criteria_name": "Opportunity-To follow up",
|
||||
"columns": "Opportunity\u0001ID,Opportunity\u0001Owner,Opportunity\u0001Company,Opportunity\u0001Fiscal Year"
|
||||
},
|
||||
{
|
||||
"name": "opportunity-to_follow_up",
|
||||
"doctype": "Search Criteria"
|
||||
}
|
||||
]
|
||||
@@ -1 +0,0 @@
|
||||
from __future__ import unicode_literals
|
||||
@@ -1,30 +0,0 @@
|
||||
[
|
||||
{
|
||||
"owner": "Administrator",
|
||||
"docstatus": 0,
|
||||
"creation": "2012-04-03 12:49:52",
|
||||
"modified_by": "Administrator",
|
||||
"modified": "2012-04-03 12:49:52"
|
||||
},
|
||||
{
|
||||
"add_col": "SUM(CASE WHEN `tabSales Order`.`status` = 'Stopped' THEN (`tabSales Order Item`.`delivered_qty` * `tabSales Order Item`.`basic_rate`) ELSE (`tabSales Order Item`.`qty` * `tabSales Order Item`.`basic_rate`) END) AS 'Booking Total'\nSUM(`tabSales Order Item`.`delivered_qty` * `tabSales Order Item`.`basic_rate`) AS 'Delivered Amount'",
|
||||
"parent_doc_type": "Sales Order",
|
||||
"module": "Selling",
|
||||
"standard": "Yes",
|
||||
"sort_order": "DESC",
|
||||
"filters": "{'Sales Order\u0001Submitted':1,'Sales Order\u0001Status':'','Sales Order\u0001Fiscal Year':''}",
|
||||
"description": "Sales Orderwise Booking & Delivery Summary",
|
||||
"doc_type": "Sales Order Item",
|
||||
"name": "__common__",
|
||||
"doctype": "Search Criteria",
|
||||
"sort_by": "`tabSales Order`.`name`",
|
||||
"group_by": "`tabSales Order`.`name`",
|
||||
"page_len": 50,
|
||||
"criteria_name": "Sales Orderwise Booking & Delivery Summary",
|
||||
"columns": "Sales Order\u0001ID,Sales Order\u0001Status,Sales Order\u0001% Billed,Sales Order\u0001Sales Order Date,Sales Order\u0001Customer,Sales Order\u0001Customer Name,Sales Order\u0001Territory"
|
||||
},
|
||||
{
|
||||
"name": "sales_orderwise_booking_&_delivery_summary",
|
||||
"doctype": "Search Criteria"
|
||||
}
|
||||
]
|
||||
@@ -1 +0,0 @@
|
||||
from __future__ import unicode_literals
|
||||
@@ -1,20 +0,0 @@
|
||||
// ERPNext - web based ERP (http://erpnext.com)
|
||||
// Copyright (C) 2012 Web Notes Technologies Pvt Ltd
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
report.customize_filters = function() {
|
||||
this.filter_fields_dict['Sales Order'+FILTER_SEP +'Company'].df['report_default'] = sys_defaults.company;
|
||||
this.filter_fields_dict['Sales Order'+FILTER_SEP +'Fiscal Year'].df['report_default'] = sys_defaults.fiscal_year;
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
[
|
||||
{
|
||||
"owner": "dhanalekshmi@webnotestech.com",
|
||||
"docstatus": 0,
|
||||
"creation": "2012-04-03 12:49:52",
|
||||
"modified_by": "Administrator",
|
||||
"modified": "2012-04-03 12:49:52"
|
||||
},
|
||||
{
|
||||
"add_col": "SUM((`tabSales Order Item`.`qty` - ifnull(`tabSales Order Item`.`billed_qty`, 0)) * `tabSales Order Item`.`basic_rate`) AS \"Pending Amount\"",
|
||||
"parent_doc_type": "Sales Order",
|
||||
"module": "Selling",
|
||||
"standard": "Yes",
|
||||
"sort_order": "DESC",
|
||||
"filters": "{'Sales Order\u0001Saved':1,'Sales Order\u0001Submitted':1,'Sales Order\u0001Company Name':'','Sales Order\u0001Fiscal Year':''}",
|
||||
"description": "Sales Orderwise Pending Amount To Bill",
|
||||
"doc_type": "Sales Order Item",
|
||||
"name": "__common__",
|
||||
"add_cond": "`tabSales Order`.status != \"Stopped\"\n`tabSales Order`.order_type!=\"Maintenance\"",
|
||||
"doctype": "Search Criteria",
|
||||
"sort_by": "`tabSales Order`.`name`",
|
||||
"group_by": "`tabSales Order`.`name`",
|
||||
"page_len": 50,
|
||||
"criteria_name": "Sales Orderwise Pending Amount To Bill",
|
||||
"columns": "Sales Order\u0001ID,Sales Order\u0001Customer,Sales Order\u0001Customer Address,Sales Order\u0001Status,Sales Order\u0001% Delivered,Sales Order\u0001% Billed,Sales Order\u0001Company Name,Sales Order\u0001Sales Order Date,Sales Order\u0001Net Total,Sales Order\u0001Zone,Sales Order\u0001Territory,Sales Order\u0001Email Id"
|
||||
},
|
||||
{
|
||||
"name": "sales_orderwise_pending_amount_to_bill",
|
||||
"doctype": "Search Criteria"
|
||||
}
|
||||
]
|
||||
@@ -1 +0,0 @@
|
||||
from __future__ import unicode_literals
|
||||
@@ -1,31 +0,0 @@
|
||||
[
|
||||
{
|
||||
"owner": "dhanalekshmi@webnotestech.com",
|
||||
"docstatus": 0,
|
||||
"creation": "2012-04-03 12:49:52",
|
||||
"modified_by": "Administrator",
|
||||
"modified": "2012-04-03 12:49:52"
|
||||
},
|
||||
{
|
||||
"add_col": "SUM(`tabSales Order Item`.`qty` - ifnull(`tabSales Order Item`.`delivered_qty`, 0)) AS \"Pending Qty\"",
|
||||
"parent_doc_type": "Sales Order",
|
||||
"module": "Selling",
|
||||
"standard": "Yes",
|
||||
"sort_order": "DESC",
|
||||
"filters": "{'Sales Order\u0001Saved':1,'Sales Order\u0001Submitted':1,'Sales Order\u0001Status':'','Sales Order\u0001Fiscal Year':''}",
|
||||
"description": "Sales Orderwise Pending Qty To Deliver",
|
||||
"doc_type": "Sales Order Item",
|
||||
"name": "__common__",
|
||||
"add_cond": "`tabSales Order`.status != \"Stopped\"\n`tabSales Order Item`.`qty` > ifnull(`tabSales Order Item`.`delivered_qty`, 0)",
|
||||
"doctype": "Search Criteria",
|
||||
"sort_by": "`tabSales Order`.`name`",
|
||||
"group_by": "`tabSales Order`.`name`",
|
||||
"page_len": 50,
|
||||
"criteria_name": "Sales Orderwise Pending Qty To Deliver",
|
||||
"columns": "Sales Order\u0001ID,Sales Order\u0001Customer,Sales Order\u0001Customer Name,Sales Order\u0001Customer Address,Sales Order\u0001Status,Sales Order\u0001% Delivered,Sales Order\u0001% Billed,Sales Order\u0001Sales Order Date,Sales Order\u0001Territory,Sales Order\u0001Email Id"
|
||||
},
|
||||
{
|
||||
"name": "sales_orderwise_pending_qty_to_deliver",
|
||||
"doctype": "Search Criteria"
|
||||
}
|
||||
]
|
||||
@@ -1 +0,0 @@
|
||||
from __future__ import unicode_literals
|
||||
@@ -1,57 +0,0 @@
|
||||
// ERPNext - web based ERP (http://erpnext.com)
|
||||
// Copyright (C) 2012 Web Notes Technologies Pvt Ltd
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
report.customize_filters = function() {
|
||||
|
||||
this.hide_all_filters();
|
||||
|
||||
this.add_filter({fieldname:'sales_person', label:'Sales Person', fieldtype:'Link', options:'Sales Person',ignore : 1,parent:'Target Detail'});
|
||||
|
||||
this.add_filter({fieldname:'fiscal_year', label:'Fiscal Year', fieldtype:'Link', options:'Fiscal Year', report_default:sys_defaults.fiscal_year, ignore : 1, parent:'Target Detail'});
|
||||
|
||||
this.add_filter({fieldname:'period', label:'Period', fieldtype:'Select', options:'Monthly'+NEWLINE+'Quarterly'+NEWLINE+'Half Yearly'+NEWLINE+'Annual',report_default:'Quarterly',ignore : 1, parent:'Target Detail'});
|
||||
|
||||
this.add_filter({fieldname:'under', label:'Under',fieldtype:'Select', options:'Sales Order'+NEWLINE+'Delivery Note'+NEWLINE+'Sales Invoice',report_default:'Sales Order',ignore : 1, parent:'Target Detail'});
|
||||
|
||||
this.add_filter({fieldname : 'target_on', label:'Target On', fieldtype:'Select', options:'Quantity'+NEWLINE+'Amount',report_default:'Quantity',ignore : 1,parent:'Target Detail'});
|
||||
this.filter_fields_dict['Target Detail'+FILTER_SEP +'Sales Person'].df.in_first_page = 1;
|
||||
}
|
||||
this.mytabs.items['Select Columns'].hide();
|
||||
report.get_query = function() {
|
||||
|
||||
sales_person = this.filter_fields_dict['Target Detail'+FILTER_SEP+'Sales Person'].get_value();
|
||||
target_on = this.filter_fields_dict['Target Detail'+FILTER_SEP+'Target On'].get_value();
|
||||
under = this.filter_fields_dict['Target Detail'+FILTER_SEP+'Under'].get_value();
|
||||
if(under == 'Sales Invoice') under = 'Sales Invoice';
|
||||
|
||||
if(target_on == 'Quantity'){
|
||||
q1 = 't1.target_qty AS "Target Quantity"';
|
||||
q2 = '0 AS "Target Quantity"';
|
||||
cond1 = 'ifnull(t1.target_qty,"")!=""';
|
||||
cond2 = 'ifnull(t6.target_qty,"")!=""';
|
||||
}
|
||||
else{
|
||||
q1 = 't1.target_amount AS "Target Amount"';
|
||||
q2 = '0 AS "Target Amount"';
|
||||
cond1 = 'ifnull(t1.target_amount,"")!=""';
|
||||
cond2 = 'ifnull(t6.target_amount,"")!=""';
|
||||
}
|
||||
|
||||
var q ='SELECT t1.item_group AS "Item Group", '+q1+', t2.distribution_id AS "Distribution Id" FROM `tabTarget Detail` t1, `tabSales Person` t2 WHERE t1.parenttype = "Sales Person" AND t1.parent = "'+sales_person+'" AND t1.parent=t2.name AND ifnull(t1.item_group,"") != "" AND '+cond1+' UNION SELECT t3.item_group AS "Item Group", '+q2+',"" AS "Distribution Id" FROM `tab'+under+' Item` t3,`tabSales Team` t4,`tab'+under+'` t5 where t3.item_group NOT IN (SELECT t6.item_group AS "Item Group" FROM `tabTarget Detail` t6, `tabSales Person` t7 WHERE t6.parenttype = "Sales Person" AND t6.parent = "'+sales_person+'" AND t6.parent=t7.name AND '+cond2+') AND t4.sales_person = "'+sales_person+'" AND t3.parent = t5.name AND t4.parent = t5.name AND t5.docstatus = 1';
|
||||
|
||||
return q;
|
||||
|
||||
}
|
||||
@@ -1,145 +0,0 @@
|
||||
# ERPNext - web based ERP (http://erpnext.com)
|
||||
# Copyright (C) 2012 Web Notes Technologies Pvt Ltd
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
# validate Filters
|
||||
from __future__ import unicode_literals
|
||||
flt_dict = {'fiscal_year': 'Fiscal Year', 'period': 'Period', 'under' : 'Under', 'sales_person':'Sales Person', 'target_on':'Target On'}
|
||||
for f in flt_dict:
|
||||
if not filter_values.get(f):
|
||||
msgprint("Please Select " + cstr(flt_dict[f]))
|
||||
raise Exception
|
||||
|
||||
# Get Values from fliters
|
||||
fiscal_year = filter_values.get('fiscal_year')[0]
|
||||
period = filter_values.get('period')
|
||||
under = filter_values.get('under')
|
||||
sales_person = filter_values.get('sales_person')
|
||||
target_on = filter_values.get('target_on')
|
||||
|
||||
|
||||
# set colnames
|
||||
for d in ['Item Group', 'Total Target Allocated', 'Distribution Id']:
|
||||
colnames.append(d)
|
||||
coltypes.append('Data')
|
||||
colwidths.append('150px')
|
||||
coloptions.append('')
|
||||
col_idx[d] = len(colnames) - 1
|
||||
|
||||
|
||||
|
||||
# Set required field names
|
||||
based_on_fn = 'sales_person'
|
||||
|
||||
date_fn = (under == 'Sales Order' ) and 'transaction_date' or 'posting_date'
|
||||
|
||||
mon_list = []
|
||||
|
||||
data = {'start_date':0, 'end_date':1}
|
||||
|
||||
def make_month_list(append_colnames, start_date, mon_list, period, colnames, coltypes, colwidths, coloptions, col_idx):
|
||||
count = 1
|
||||
if period == 'Quarterly' or period == 'Half Yearly' or period == 'Annual': mon_list.append([str(start_date)])
|
||||
for m in range(12):
|
||||
# get last date
|
||||
last_date = str(sql("select LAST_DAY('%s')" % start_date)[0][0])
|
||||
|
||||
# make mon_list for Monthly Period
|
||||
if period == 'Monthly' :
|
||||
mon_list.append([start_date, last_date])
|
||||
# add months as Column names
|
||||
month_name = sql("select MONTHNAME('%s')" % start_date)[0][0]
|
||||
append_colnames(str(month_name)[:3], colnames, coltypes, colwidths, coloptions, col_idx)
|
||||
|
||||
# get start date
|
||||
start_date = str(sql("select DATE_ADD('%s',INTERVAL 1 DAY)" % last_date)[0][0])
|
||||
|
||||
# make mon_list for Quaterly Period
|
||||
if period == 'Quarterly' and count % 3 == 0:
|
||||
mon_list[len(mon_list) - 1 ].append(last_date)
|
||||
# add Column names
|
||||
append_colnames('Q '+ str(count / 3), colnames, coltypes, colwidths, coloptions, col_idx)
|
||||
if count != 12: mon_list.append([start_date])
|
||||
|
||||
# make mon_list for Half Yearly Period
|
||||
if period == 'Half Yearly' and count % 6 == 0 :
|
||||
mon_list[len(mon_list) - 1 ].append(last_date)
|
||||
# add Column Names
|
||||
append_colnames('H'+str(count / 6), colnames, coltypes, colwidths, coloptions, col_idx)
|
||||
if count != 12: mon_list.append([start_date])
|
||||
|
||||
# make mon_list for Annual Period
|
||||
if period == 'Annual' and count % 12 == 0:
|
||||
mon_list[len(mon_list) - 1 ].append(last_date)
|
||||
# add Column Names
|
||||
append_colnames('', colnames, coltypes, colwidths, coloptions, col_idx)
|
||||
count = count +1
|
||||
|
||||
def append_colnames(name, colnames, coltypes, colwidths, coloptions, col_idx):
|
||||
col = ['Target', 'Actual', 'Variance']
|
||||
for c in col:
|
||||
n = str(name) and ' (' + str(name) +')' or ''
|
||||
colnames.append(str(c) + n )
|
||||
coltypes.append('Currency')
|
||||
colwidths.append('150px')
|
||||
coloptions.append('')
|
||||
col_idx[str(c) + n ] = len(colnames) - 1
|
||||
|
||||
|
||||
|
||||
|
||||
# get start date
|
||||
start_date = webnotes.conn.get_value('Fiscal Year', fiscal_year, 'year_start_date')
|
||||
if not start_date:
|
||||
msgprint("Please Define Year Start Date for Fiscal Year " + str(fiscal_year))
|
||||
raise Exception
|
||||
start_date = start_date.strftime('%Y-%m-%d')
|
||||
|
||||
# make month list and columns
|
||||
make_month_list(append_colnames, start_date, mon_list, period, colnames, coltypes, colwidths, coloptions, col_idx)
|
||||
|
||||
|
||||
bc_obj = get_obj('Budget Control')
|
||||
for r in res:
|
||||
|
||||
count = 0
|
||||
|
||||
for idx in range(3, len(colnames), 3):
|
||||
|
||||
cidx = 2
|
||||
# ================= Calculate Target ==========================================
|
||||
r.append(bc_obj.get_monthly_budget(r[cidx], fiscal_year, mon_list[count][data['start_date']], mon_list[count][data['end_date']], r[cidx-1]))
|
||||
|
||||
#================== Actual Amount =============================================
|
||||
actual = 0
|
||||
|
||||
|
||||
#----------------------------------------------------------
|
||||
if target_on == "Quantity":
|
||||
|
||||
actual = sql("select sum(ifnull(t2.qty,0) * ifnull(t3.allocated_percentage,0) / 100) from `tab%s` t1, `tab%s Item` t2, `tabSales Team` t3 where t2.parent = t1.name and t3.parent = t1.name and t3.%s = '%s' and t2.item_group = '%s' and t1.docstatus = 1 and t1.%s between '%s' and '%s' "%(under, under, based_on_fn, sales_person, r[0].strip(), date_fn, mon_list[count][data['start_date']], mon_list[count][data['end_date']]))
|
||||
|
||||
#----------------------------------------------------------
|
||||
if target_on == "Amount":
|
||||
|
||||
actual = sql("select sum(ifnull(t2.amount,0) * ifnull(t3.allocated_percentage,0) / 100) from `tab%s` t1, `tab%s Item` t2, `tabSales Team` t3 where t2.parent = t1.name and t3.parent = t1.name and t3.%s = '%s' and t2.item_group = '%s' and t1.docstatus = 1 and t1.%s between '%s' and '%s' "%(under, under, based_on_fn, sales_person, r[0].strip(), date_fn, mon_list[count][data['start_date']], mon_list[count][data['end_date']]))
|
||||
#----------------------------------------------------------
|
||||
|
||||
actual = actual and flt(actual[0][0]) or 0
|
||||
r.append(actual)
|
||||
# ================ Variance ===================================================
|
||||
|
||||
r.append(r[idx] - r[idx + 1])
|
||||
|
||||
count = count +1
|
||||
@@ -1,26 +0,0 @@
|
||||
[
|
||||
{
|
||||
"owner": "Administrator",
|
||||
"docstatus": 0,
|
||||
"creation": "2012-04-03 12:49:52",
|
||||
"modified_by": "Administrator",
|
||||
"modified": "2012-04-03 12:49:52"
|
||||
},
|
||||
{
|
||||
"parent_doc_type": "Sales Person",
|
||||
"module": "Selling",
|
||||
"doctype": "Search Criteria",
|
||||
"sort_order": "DESC",
|
||||
"filters": "{'Sales Person\u0001Country':'','Sales Person\u0001State':'','Target Detail\u0001Fiscal Year':''}",
|
||||
"standard": "Yes",
|
||||
"doc_type": "Target Detail",
|
||||
"name": "__common__",
|
||||
"sort_by": "`tabTarget Detail`.`target_amount`",
|
||||
"page_len": 50,
|
||||
"criteria_name": "Sales Persons Target Variance (Item Group wise)"
|
||||
},
|
||||
{
|
||||
"name": "sales_persons_target_variance_item_group_wise",
|
||||
"doctype": "Search Criteria"
|
||||
}
|
||||
]
|
||||
@@ -1 +0,0 @@
|
||||
from __future__ import unicode_literals
|
||||
@@ -1,53 +0,0 @@
|
||||
// ERPNext - web based ERP (http://erpnext.com)
|
||||
// Copyright (C) 2012 Web Notes Technologies Pvt Ltd
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
report.customize_filters = function() {
|
||||
this.hide_all_filters();
|
||||
|
||||
//Add filter
|
||||
this.add_filter({fieldname:'based_on', label:'Based On', fieldtype:'Select', options:'Sales Order'+NEWLINE+'Delivery Note'+NEWLINE+'Sales Invoice', report_default:'Sales Order', ignore : 1,parent:'Sales Person', single_select :1, in_first_page:1});
|
||||
this.add_filter({fieldname:'transaction_date', label:'Date', fieldtype:'Date', options:'', ignore : 1,parent:'Sales Person', in_first_page:1});
|
||||
this.add_filter({fieldname:'voucher_id', label:'Voucher Id', fieldtype:'Data', options:'', ignore : 1,parent:'Sales Person', in_first_page:1});
|
||||
this.add_filter({fieldname:'territory', label:'Territory', fieldtype:'Link', options:'Territory', ignore : 1,parent:'Sales Person', in_first_page:1});
|
||||
this.add_filter({fieldname:'sales_person', label:'Sales Person', fieldtype:'Link', options:'Sales Person', ignore : 1,parent:'Sales Person', in_first_page:1});
|
||||
}
|
||||
|
||||
// hide sections
|
||||
this.mytabs.items['More Filters'].hide();
|
||||
this.mytabs.items['Select Columns'].hide();
|
||||
|
||||
// Get query
|
||||
report.get_query = function() {
|
||||
based_on = this.get_filter('Sales Person', 'Based On').get_value();
|
||||
from_date = this.get_filter('Sales Person', 'From Date').get_value();
|
||||
to_date = this.get_filter('Sales Person', 'To Date').get_value();
|
||||
vid = this.get_filter('Sales Person', 'Voucher Id').get_value();
|
||||
terr = this.get_filter('Sales Person', 'Territory').get_value();
|
||||
sp = this.get_filter('Sales Person', 'Sales Person').get_value();
|
||||
|
||||
date_fld = 'transaction_date';
|
||||
if(based_on == 'Sales Invoice' || based_on == "Delivery Note") date_fld = 'posting_date';
|
||||
|
||||
sp_cond = '';
|
||||
if (from_date) sp_cond += ' AND t1.' + date_fld + '>= "' + from_date + '"';
|
||||
if (to_date) sp_cond += ' AND t1.' + date_fld + '<= "' + to_date + '"';
|
||||
if (vid) sp_cond += ' AND t1.name LIKE "%' + vid + '%"';
|
||||
if (terr) sp_cond += ' AND t1.territory = "' + terr + '"';
|
||||
if (sp) sp_cond += ' AND t2.sales_person = "' + sp + '"';
|
||||
|
||||
return 'SELECT t1.`name`, t1.`customer_name`, t1.`territory`, t1.`' + date_fld + '`, t1.`net_total`, t1.`grand_total`, t2.`sales_person`, t2.`allocated_percentage`, t2.`allocated_amount` FROM `tab' + based_on + '` t1, `tabSales Team` t2 WHERE t1.docstatus=1 AND t2.`parenttype` = "' + based_on + '" AND t2.`parent` = t1.`name`' + sp_cond + ' ORDER BY t1.`name` DESC';
|
||||
}
|
||||
|
||||
@@ -1,30 +0,0 @@
|
||||
# ERPNext - web based ERP (http://erpnext.com)
|
||||
# Copyright (C) 2012 Web Notes Technologies Pvt Ltd
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
from __future__ import unicode_literals
|
||||
if filter_values.get('based_on') == 'Sales Invoice':
|
||||
based_on_dt = 'Sales Invoice'
|
||||
else:
|
||||
based_on_dt = filter_values.get('based_on')
|
||||
|
||||
cols = [[filter_values.get('based_on'), 'Link','150px', based_on_dt], ['Customer', 'Link','150px','Customer'], ['Territory', 'Link','120px','Territory'], ['Transaction Date', 'Date', '120px', ''], ['Net Total', 'Currency', '80px', ''], ['Grand Total', 'Currency', '80px', ''], ['Sales Person', 'Link', '150px', 'Sales Person'], ['% Contribution', 'Currency', '120px', ''], ['Contribution Amt', 'Currency', '120px', '']]
|
||||
|
||||
for c in cols:
|
||||
colnames.append(c[0])
|
||||
coltypes.append(c[1])
|
||||
colwidths.append(c[2])
|
||||
coloptions.append(c[3])
|
||||
col_idx[c[0]] = len(colnames)-1
|
||||
@@ -1,26 +0,0 @@
|
||||
[
|
||||
{
|
||||
"owner": "Administrator",
|
||||
"docstatus": 0,
|
||||
"creation": "2012-04-03 12:49:52",
|
||||
"modified_by": "Administrator",
|
||||
"modified": "2012-04-03 12:49:52"
|
||||
},
|
||||
{
|
||||
"module": "Selling",
|
||||
"standard": "Yes",
|
||||
"sort_order": "DESC",
|
||||
"filters": "{'Sales Person\u0001Saved':1,'Sales Person\u0001Submitted':1,'Sales Person\u0001Country':'','Sales Person\u0001State':''}",
|
||||
"doctype": "Search Criteria",
|
||||
"doc_type": "Sales Person",
|
||||
"name": "__common__",
|
||||
"sort_by": "`tabSales Person`.`name`",
|
||||
"page_len": 50,
|
||||
"criteria_name": "Sales Personwise Transaction Summary",
|
||||
"columns": "Sales Person\u0001ID"
|
||||
},
|
||||
{
|
||||
"name": "sales_personwise_transaction_summary",
|
||||
"doctype": "Search Criteria"
|
||||
}
|
||||
]
|
||||
@@ -1 +0,0 @@
|
||||
from __future__ import unicode_literals
|
||||
@@ -1,27 +0,0 @@
|
||||
[
|
||||
{
|
||||
"owner": "Administrator",
|
||||
"docstatus": 0,
|
||||
"creation": "2012-04-03 12:49:52",
|
||||
"modified_by": "Administrator",
|
||||
"modified": "2012-04-03 12:49:52"
|
||||
},
|
||||
{
|
||||
"module": "Selling",
|
||||
"standard": "Yes",
|
||||
"sort_order": "DESC",
|
||||
"filters": "{'Serial No\u0001Saved':1,'Serial No\u0001Submitted':1,'Serial No\u0001Status':'','Serial No\u0001Warranty Status':''}",
|
||||
"doc_type": "Serial No",
|
||||
"name": "__common__",
|
||||
"add_cond": "`tab Serial No`.month(amc_expiry_date)=month(now()) \n`tab Serial No`.year(amc_expiry_date)=year(now())",
|
||||
"doctype": "Search Criteria",
|
||||
"sort_by": "`tabSerial No`.`name`",
|
||||
"page_len": 50,
|
||||
"criteria_name": "Serial No-AMC expiring this month",
|
||||
"columns": "Serial No\u0001ID,Serial No\u0001Status,Serial No\u0001AMC Expiry Date,Serial No\u0001Customer Name"
|
||||
},
|
||||
{
|
||||
"name": "serial_no-amc_expiring_this_month",
|
||||
"doctype": "Search Criteria"
|
||||
}
|
||||
]
|
||||
@@ -1 +0,0 @@
|
||||
from __future__ import unicode_literals
|
||||
@@ -1,27 +0,0 @@
|
||||
[
|
||||
{
|
||||
"owner": "Administrator",
|
||||
"docstatus": 0,
|
||||
"creation": "2012-04-03 12:49:52",
|
||||
"modified_by": "Administrator",
|
||||
"modified": "2012-04-03 12:49:52"
|
||||
},
|
||||
{
|
||||
"module": "Selling",
|
||||
"standard": "Yes",
|
||||
"sort_order": "DESC",
|
||||
"filters": "{'Serial No\u0001Saved':1,'Serial No\u0001Submitted':1,'Serial No\u0001Status':'Issued','Serial No\u0001Maintenance Status':''}",
|
||||
"doc_type": "Serial No",
|
||||
"name": "__common__",
|
||||
"add_cond": "`tab Serial No`.docstatus!=2\n`tab Serial No`.maintenance_status='Under Warranty'\n`tab Serial No`.status!='Scrapped'\n`tab Serial No`.status!='Not in Use'\n`tab Serial No`.month(ifnull(warranty_expiry_date,0)) = month(now()) \n`tab Serial No`.yearmonth(ifnull(warranty_expiry_date,0)) = year(now())",
|
||||
"doctype": "Search Criteria",
|
||||
"sort_by": "`tabSerial No`.`name`",
|
||||
"page_len": 50,
|
||||
"criteria_name": "Serial No-Warranty expiring this month",
|
||||
"columns": "Serial No\u0001ID,Serial No\u0001Status,Serial No\u0001Warranty Expiry Date,Serial No\u0001Customer Name"
|
||||
},
|
||||
{
|
||||
"name": "serial_no-warranty_expiring_this_month",
|
||||
"doctype": "Search Criteria"
|
||||
}
|
||||
]
|
||||
@@ -1 +0,0 @@
|
||||
from __future__ import unicode_literals
|
||||
@@ -1,43 +0,0 @@
|
||||
// ERPNext - web based ERP (http://erpnext.com)
|
||||
// Copyright (C) 2012 Web Notes Technologies Pvt Ltd
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
report.customize_filters = function() {
|
||||
this.hide_all_filters();
|
||||
this.add_filter({fieldname:'based_on', label:'Based On', fieldtype:'Select', options:'Cost Center'+NEWLINE+'Sales Person'+NEWLINE+'Sales Partner',report_default:'Cost Center',ignore : 1,parent:'Target Detail'});
|
||||
this.add_filter({fieldname:'fiscal_year', label:'Fiscal Year', fieldtype:'Link', options:'Fiscal Year', report_default:sys_defaults.fiscal_year, ignore : 1, parent:'Target Detail'});
|
||||
this.add_filter({fieldname:'company', label:'Company', fieldtype:'Link', options:'Company',report_default:sys_defaults.company, ignore : 1, parent:'Target Detail'});
|
||||
this.add_filter({fieldname:'period', label:'Period', fieldtype:'Select', options:'Monthly'+NEWLINE+'Quarterly'+NEWLINE+'Half Yearly'+NEWLINE+'Annual',report_default:'Quarterly',ignore : 1, parent:'Target Detail'});
|
||||
this.add_filter({fieldname:'group_by', label:'Group By', fieldtype:'Select', options:NEWLINE+'Item Group',ignore : 1, parent:'Target Detail'});
|
||||
this.add_filter({fieldname:'under', label:'Under',fieldtype:'Select', options:'Sales Order'+NEWLINE+'Delivery Note'+NEWLINE+'Sales Invoice',report_default:'Sales Order',ignore : 1, parent:'Target Detail'});
|
||||
|
||||
}
|
||||
|
||||
report.get_query = function() {
|
||||
group_by = '';
|
||||
group_by = this.filter_fields_dict['Target Detail'+FILTER_SEP+'Group By'].get_value();
|
||||
based_on = this.filter_fields_dict['Target Detail'+FILTER_SEP+'Based On'].get_value();
|
||||
sel_fields = '`tabTarget Detail`.parent AS "' + cstr(based_on)+'"';
|
||||
cond = ' and ifnull(`tabTarget Detail`.item_group, "") = ""'
|
||||
if (group_by == 'Item Group'){
|
||||
sel_fields = cstr(sel_fields) + ', `tabTarget Detail`.item_group';
|
||||
cond = ' and ifnull(`tabTarget Detail`.item_group,"") != ""'
|
||||
}
|
||||
sel_fields = cstr(sel_fields) + ', `tabTarget Detail`.target_amount, `tabTarget Detail`.distribution_id';
|
||||
var q = 'SELECT '+ cstr(sel_fields) +' FROM `tabTarget Detail` WHERE `tabTarget Detail`.parenttype = "' + cstr(based_on) + '"'+ cstr(cond);
|
||||
return q
|
||||
}
|
||||
|
||||
this.mytabs.items['Select Columns'].hide();
|
||||
@@ -1,127 +0,0 @@
|
||||
# ERPNext - web based ERP (http://erpnext.com)
|
||||
# Copyright (C) 2012 Web Notes Technologies Pvt Ltd
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
# validate Filters
|
||||
from __future__ import unicode_literals
|
||||
flt_dict = {'fiscal_year': 'Fiscal Year', 'period': 'Period', 'company':'Company', 'under' : 'Under', 'based_on' : 'Based On'}
|
||||
for f in flt_dict:
|
||||
if not filter_values.get(f):
|
||||
msgprint("Please Select " + cstr(flt_dict[f]))
|
||||
raise Exception
|
||||
|
||||
# Get Values from fliters
|
||||
fiscal_year = filter_values.get('fiscal_year')
|
||||
period = filter_values.get('period')
|
||||
under = filter_values.get('under')
|
||||
based_on = filter_values.get('based_on')
|
||||
group_by = filter_values.get('group_by')
|
||||
|
||||
# Set required field names
|
||||
based_on_fn = (based_on == 'Cost Center') and 'cost_center' or (based_on == 'Sales Partner') and 'sales_partner' or (based_on == 'Sales Person') and 'sales_person'
|
||||
date_fn = (under == 'Sales Order' ) and 'transaction_date' or 'posting_date'
|
||||
|
||||
mon_list = []
|
||||
data = {'start_date':0, 'end_date':1}
|
||||
|
||||
def make_month_list(append_colnames, start_date, mon_list, period, colnames, coltypes, colwidths, coloptions, col_idx):
|
||||
count = 1
|
||||
if period == 'Quarterly' or period == 'Half Yearly' or period == 'Annual': mon_list.append([str(start_date)])
|
||||
for m in range(12):
|
||||
# get last date
|
||||
last_date = str(sql("select LAST_DAY('%s')" % start_date)[0][0])
|
||||
|
||||
# make mon_list for Monthly Period
|
||||
if period == 'Monthly' :
|
||||
mon_list.append([start_date, last_date])
|
||||
# add months as Column names
|
||||
month_name = sql("select MONTHNAME('%s')" % start_date)[0][0]
|
||||
append_colnames(str(month_name)[:3], colnames, coltypes, colwidths, coloptions, col_idx)
|
||||
|
||||
# get start date
|
||||
start_date = str(sql("select DATE_ADD('%s',INTERVAL 1 DAY)" % last_date)[0][0])
|
||||
|
||||
# make mon_list for Quaterly Period
|
||||
if period == 'Quarterly' and count % 3 == 0:
|
||||
mon_list[len(mon_list) - 1 ].append(last_date)
|
||||
# add Column names
|
||||
append_colnames('Q '+ str(count / 3), colnames, coltypes, colwidths, coloptions, col_idx)
|
||||
if count != 12: mon_list.append([start_date])
|
||||
|
||||
# make mon_list for Half Yearly Period
|
||||
if period == 'Half Yearly' and count % 6 == 0 :
|
||||
mon_list[len(mon_list) - 1 ].append(last_date)
|
||||
# add Column Names
|
||||
append_colnames('H'+str(count / 6), colnames, coltypes, colwidths, coloptions, col_idx)
|
||||
if count != 12: mon_list.append([start_date])
|
||||
|
||||
# make mon_list for Annual Period
|
||||
if period == 'Annual' and count % 12 == 0:
|
||||
mon_list[len(mon_list) - 1 ].append(last_date)
|
||||
# add Column Names
|
||||
append_colnames('', colnames, coltypes, colwidths, coloptions, col_idx)
|
||||
count = count +1
|
||||
|
||||
def append_colnames(name, colnames, coltypes, colwidths, coloptions, col_idx):
|
||||
col = ['Budget', 'Actual', 'Variance']
|
||||
for c in col:
|
||||
colnames.append(str(c) + ' (' + str(name) +')' )
|
||||
coltypes.append('Currency')
|
||||
colwidths.append('150px')
|
||||
coloptions.append('')
|
||||
col_idx[str(c) + ' (' + str(name) +')' ] = len(colnames) - 1
|
||||
|
||||
# make default columns
|
||||
coltypes[col_idx[based_on]] = 'Link'
|
||||
coloptions[col_idx[based_on]]= based_on
|
||||
|
||||
# get start date
|
||||
start_date = webnotes.conn.get_value('Fiscal Year', fiscal_year, 'year_start_date')
|
||||
if not start_date:
|
||||
msgprint("Please Define Year Start Date for Fiscal Year " + str(fiscal_year))
|
||||
raise Exception
|
||||
start_date = start_date.strftime('%Y-%m-%d')
|
||||
|
||||
# make month list and columns
|
||||
make_month_list(append_colnames, start_date, mon_list, period, colnames, coltypes, colwidths, coloptions, col_idx)
|
||||
|
||||
bc_obj = get_obj('Budget Control')
|
||||
for r in res:
|
||||
count = 0
|
||||
for idx in range((group_by == 'Item Group') and 4 or 3, len(colnames), 3):
|
||||
cidx = (group_by == 'Item Group') and 3 or 2
|
||||
# ================= Calculate Target ==========================================
|
||||
r.append(bc_obj.get_monthly_budget( r[cidx], fiscal_year, mon_list[count][data['start_date']], mon_list[count][data['end_date']], r[cidx-1]))
|
||||
|
||||
#================== Actual Amount =============================================
|
||||
actual = 0
|
||||
if based_on == 'Cost Center' or based_on == 'Sales Partner':
|
||||
if group_by =='Item Group':
|
||||
actual = sql("select sum(ifnull(t2.amount,0)) from `tab%s` t1, `tab%s Detail` t2, `tabItem` t3 where t2.parenttype = '%s' and t2.parent = t1.name and t1.%s = '%s' and t3.name = t2.item_code and t3.item_group = '%s' and t1.docstatus = 1 and t1.%s between '%s' and '%s'" % (under, (under == 'Sales Invoice') and 'RV' or under, under, based_on_fn, r[0], r[1], date_fn, mon_list[count][data['start_date']], mon_list[count][data['end_date']]))
|
||||
actual = flt(actual[0][0])
|
||||
else:
|
||||
actual = sql("select sum(ifnull(net_total,0)) from `tab%s` where %s = '%s' and docstatus = 1 and %s between '%s' and '%s' " % (under, based_on_fn, r[0], date_fn, mon_list[count][data['start_date']], mon_list[count][data['end_date']]))
|
||||
actual = flt(actual[0][0])
|
||||
elif based_on == 'Sales Person':
|
||||
if group_by =='Item Group':
|
||||
actual = sql("select sum(ifnull(t2.amount,0) * ifnull(t3.allocated_percentage,0) / 100) from `tab%s` t1, `tab%s Detail` t2, `tabSales Team` t3, `tabItem` t4 where t2.parent = t1.name and t3.parent = t1.name and t3.%s = '%s' and t4.name = t2.item_code and t4.item_group = '%s' and t1.docstatus != 2 and t1.docstatus = 1 and t1.%s between '%s' and '%s' "%(under, (under == 'Sales Invoice') and 'RV' or under, based_on_fn, r[0], r[1], date_fn, mon_list[count][data['start_date']], mon_list[count][data['end_date']]))
|
||||
actual = flt(actual[0][0])
|
||||
else:
|
||||
actual = sql("select sum(ifnull(t2.allocated_amount,0)) from `tab%s` t1, `tabSales Team` t2 where t2.%s = '%s' and t2.parenttype='%s' and t1.docstatus != 2 and t2.parent = t1.name and t1.%s between '%s' and '%s'"%(under, based_on_fn, r[0], under, date_fn, mon_list[count][data['start_date']], mon_list[count][data['end_date']]))
|
||||
actual = flt(actual[0][0])
|
||||
r.append(actual)
|
||||
# ================ Variance ===================================================
|
||||
r.append(r[idx] - r[idx + 1])
|
||||
count = count +1
|
||||
@@ -1,27 +0,0 @@
|
||||
[
|
||||
{
|
||||
"owner": "harshada@webnotestech.com",
|
||||
"docstatus": 0,
|
||||
"creation": "2012-04-03 12:49:53",
|
||||
"modified_by": "Administrator",
|
||||
"modified": "2012-04-03 12:49:53"
|
||||
},
|
||||
{
|
||||
"parent_doc_type": "Sales Person",
|
||||
"module": "Selling",
|
||||
"standard": "Yes",
|
||||
"disabled": 0,
|
||||
"sort_order": "DESC",
|
||||
"filters": "{'Sales Person\u0001Saved':1,'Sales Person\u0001Submitted':1,'Sales Person\u0001Country':'','Sales Person\u0001State':'','Target Detail\u0001Fiscal Year':''}",
|
||||
"doc_type": "Target Detail",
|
||||
"name": "__common__",
|
||||
"doctype": "Search Criteria",
|
||||
"page_len": 50,
|
||||
"criteria_name": "Target Variance Report",
|
||||
"columns": "Sales Person\u0001ID,Sales Person\u0001Owner,Sales Person\u0001Sales Person,Sales Person\u0001Country,Sales Person\u0001State,Target Detail\u0001Item Group,Target Detail\u0001Fiscal Year,Target Detail\u0001Target Amount"
|
||||
},
|
||||
{
|
||||
"name": "target_variance_report",
|
||||
"doctype": "Search Criteria"
|
||||
}
|
||||
]
|
||||
@@ -1 +0,0 @@
|
||||
from __future__ import unicode_literals
|
||||
@@ -1,61 +0,0 @@
|
||||
// ERPNext - web based ERP (http://erpnext.com)
|
||||
// Copyright (C) 2012 Web Notes Technologies Pvt Ltd
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
report.customize_filters = function() {
|
||||
|
||||
this.hide_all_filters();
|
||||
|
||||
this.add_filter({fieldname:'territory', label:'Territory', fieldtype:'Link', options:'Territory',ignore : 1,parent:'Target Detail'});
|
||||
|
||||
this.add_filter({fieldname:'fiscal_year', label:'Fiscal Year', fieldtype:'Link', options:'Fiscal Year', report_default:sys_defaults.fiscal_year, ignore : 1, parent:'Target Detail'});
|
||||
|
||||
this.add_filter({fieldname:'period', label:'Period', fieldtype:'Select', options:'Monthly'+NEWLINE+'Quarterly'+NEWLINE+'Half Yearly'+NEWLINE+'Annual',report_default:'Quarterly',ignore : 1, parent:'Target Detail'});
|
||||
|
||||
this.add_filter({fieldname:'under', label:'Under',fieldtype:'Select', options:'Sales Order'+NEWLINE+'Delivery Note'+NEWLINE+'Sales Invoice',report_default:'Sales Order',ignore : 1, parent:'Target Detail'});
|
||||
|
||||
this.add_filter({fieldname : 'target_on', label:'Target On', fieldtype:'Select', options:'Quantity'+NEWLINE+'Amount',report_default:'Quantity',ignore : 1,parent:'Target Detail'});
|
||||
this.filter_fields_dict['Target Detail'+FILTER_SEP +'Territory'].df.in_first_page = 1;
|
||||
}
|
||||
this.mytabs.items['Select Columns'].hide();
|
||||
report.get_query = function() {
|
||||
|
||||
territory = this.filter_fields_dict['Target Detail'+FILTER_SEP+'Territory'].get_value();
|
||||
target_on = this.filter_fields_dict['Target Detail'+FILTER_SEP+'Target On'].get_value();
|
||||
under = this.filter_fields_dict['Target Detail'+FILTER_SEP+'Under'].get_value();
|
||||
if(under == 'Sales Invoice') under = 'Sales Invoice';
|
||||
|
||||
if(target_on == 'Quantity'){
|
||||
q1 = 't1.target_qty AS "Target Quantity"';
|
||||
q2 = '0 AS "Target Quantity"';
|
||||
cond1 = 'ifnull(t1.target_qty,"")!=""';
|
||||
cond2 = 'ifnull(t5.target_qty,"")!=""';
|
||||
}
|
||||
else{
|
||||
q1 = 't1.target_amount AS "Target Amount"';
|
||||
q2 = '0 AS "Target Amount"';
|
||||
cond1 = 'ifnull(t1.target_amount,"")!=""';
|
||||
cond2 = 'ifnull(t5.target_amount,"")!=""';
|
||||
}
|
||||
if(under =='Sales Invoice')
|
||||
tab = 'RV';
|
||||
else
|
||||
tab = under;
|
||||
|
||||
var q ='SELECT distinct t1.item_group AS "Item Group", '+q1+', t2.distribution_id AS "Distribution Id" FROM `tabTarget Detail` t1, `tabTerritory` t2 WHERE t1.parenttype = "Territory" AND t1.parent = "'+territory+'" AND t1.parent=t2.name AND ifnull(t1.item_group,"")!="" AND '+cond1+' UNION SELECT distinct t3.item_group AS "Item Group", '+q2+',"" AS "Distribution Id" FROM `tab'+tab+' Detail` t3,`tab'+under+'` t4 where t3.item_group NOT IN (SELECT t5.item_group FROM `tabTarget Detail` t5, `tabTerritory` t6 WHERE t5.parenttype = "Territory" AND t5.parent = "'+territory+'" AND t5.parent=t6.name AND '+cond2+') AND t4.territory = "'+territory+'" AND t3.parent = t4.name AND t4.docstatus = 1';
|
||||
|
||||
return q;
|
||||
|
||||
}
|
||||
@@ -1,144 +0,0 @@
|
||||
# ERPNext - web based ERP (http://erpnext.com)
|
||||
# Copyright (C) 2012 Web Notes Technologies Pvt Ltd
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
# validate Filters
|
||||
from __future__ import unicode_literals
|
||||
flt_dict = {'fiscal_year': 'Fiscal Year', 'period': 'Period', 'under' : 'Under', 'territory':'Territory', 'target_on':'Target On'}
|
||||
for f in flt_dict:
|
||||
if not filter_values.get(f):
|
||||
msgprint("Please Select " + cstr(flt_dict[f]))
|
||||
raise Exception
|
||||
|
||||
# Get Values from fliters
|
||||
fiscal_year = filter_values.get('fiscal_year')
|
||||
period = filter_values.get('period')
|
||||
under = filter_values.get('under')
|
||||
if under == 'Sales Invoice': under = 'Sales Invoice'
|
||||
territory = filter_values.get('territory')
|
||||
target_on = filter_values.get('target_on')
|
||||
|
||||
|
||||
# Set required field names
|
||||
based_on_fn = 'territory'
|
||||
|
||||
date_fn = (under == 'Sales Order' ) and 'transaction_date' or 'posting_date'
|
||||
|
||||
mon_list = []
|
||||
|
||||
data = {'start_date':0, 'end_date':1}
|
||||
|
||||
def make_month_list(append_colnames, start_date, mon_list, period, colnames, coltypes, colwidths, coloptions, col_idx):
|
||||
count = 1
|
||||
if period == 'Quarterly' or period == 'Half Yearly' or period == 'Annual': mon_list.append([str(start_date)])
|
||||
for m in range(12):
|
||||
# get last date
|
||||
last_date = str(sql("select LAST_DAY('%s')" % start_date)[0][0])
|
||||
|
||||
# make mon_list for Monthly Period
|
||||
if period == 'Monthly' :
|
||||
mon_list.append([start_date, last_date])
|
||||
# add months as Column names
|
||||
month_name = sql("select MONTHNAME('%s')" % start_date)[0][0]
|
||||
append_colnames(str(month_name)[:3], colnames, coltypes, colwidths, coloptions, col_idx)
|
||||
|
||||
# get start date
|
||||
start_date = str(sql("select DATE_ADD('%s',INTERVAL 1 DAY)" % last_date)[0][0])
|
||||
|
||||
# make mon_list for Quaterly Period
|
||||
if period == 'Quarterly' and count % 3 == 0:
|
||||
mon_list[len(mon_list) - 1 ].append(last_date)
|
||||
# add Column names
|
||||
append_colnames('Q '+ str(count / 3), colnames, coltypes, colwidths, coloptions, col_idx)
|
||||
if count != 12: mon_list.append([start_date])
|
||||
|
||||
# make mon_list for Half Yearly Period
|
||||
if period == 'Half Yearly' and count % 6 == 0 :
|
||||
mon_list[len(mon_list) - 1 ].append(last_date)
|
||||
# add Column Names
|
||||
append_colnames('H'+str(count / 6), colnames, coltypes, colwidths, coloptions, col_idx)
|
||||
if count != 12: mon_list.append([start_date])
|
||||
|
||||
# make mon_list for Annual Period
|
||||
if period == 'Annual' and count % 12 == 0:
|
||||
mon_list[len(mon_list) - 1 ].append(last_date)
|
||||
# add Column Names
|
||||
append_colnames('', colnames, coltypes, colwidths, coloptions, col_idx)
|
||||
count = count +1
|
||||
|
||||
def append_colnames(name, colnames, coltypes, colwidths, coloptions, col_idx):
|
||||
col = ['Target', 'Actual', 'Variance']
|
||||
for c in col:
|
||||
n = str(name) and ' (' + str(name) +')' or ''
|
||||
colnames.append(str(c) + n )
|
||||
coltypes.append('Currency')
|
||||
colwidths.append('150px')
|
||||
coloptions.append('')
|
||||
col_idx[str(c) + n ] = len(colnames) - 1
|
||||
|
||||
|
||||
|
||||
# make default columns
|
||||
#coltypes[col_idx['Item Group']] = 'Link'
|
||||
#coloptions[col_idx['Item Group']]= 'Sales '
|
||||
|
||||
# get start date
|
||||
start_date = webnotes.conn.get_value('Fiscal Year', fiscal_year, 'year_start_date')
|
||||
if not start_date:
|
||||
msgprint("Please Define Year Start Date for Fiscal Year " + str(fiscal_year))
|
||||
raise Exception
|
||||
start_date = start_date.strftime('%Y-%m-%d')
|
||||
|
||||
# make month list and columns
|
||||
make_month_list(append_colnames, start_date, mon_list, period, colnames, coltypes, colwidths, coloptions, col_idx)
|
||||
|
||||
|
||||
|
||||
bc_obj = get_obj('Budget Control')
|
||||
for r in res:
|
||||
|
||||
count = 0
|
||||
|
||||
for idx in range(3, len(colnames), 3):
|
||||
|
||||
cidx = 2
|
||||
# ================= Calculate Target ==========================================
|
||||
r.append(bc_obj.get_monthly_budget(r[cidx], fiscal_year, mon_list[count][data['start_date']], mon_list[count][data['end_date']], r[cidx-1]))
|
||||
|
||||
#================== Actual Amount =============================================
|
||||
actual = 0
|
||||
|
||||
|
||||
|
||||
#----------------------------------------------------------
|
||||
if target_on == "Quantity":
|
||||
|
||||
actual = sql("select sum(ifnull(t2.qty,0)) from `tab%s` t1, `tab%s Detail` t2 where t2.parenttype = '%s' and t2.parent = t1.name and t1.%s = '%s' and t1.docstatus = 1 and t2.item_group = '%s' and t1.%s between '%s' and '%s'" % (under, (under == 'Sales Invoice') and 'RV' or under, under, based_on_fn, territory, r[0],date_fn, mon_list[count][data['start_date']], mon_list[count][data['end_date']]))
|
||||
|
||||
|
||||
#----------------------------------------------------------
|
||||
if target_on == "Amount":
|
||||
|
||||
actual = sql("select sum(ifnull(t2.amount,0)) from `tab%s` t1, `tab%s Detail` t2 where t2.parenttype = '%s' and t2.parent = t1.name and t1.%s = '%s' and t1.docstatus = 1 and t2.item_group = '%s' and t1.%s between '%s' and '%s'" % (under, (under == 'Sales Invoice') and 'RV' or under, under, based_on_fn, territory, r[0],date_fn, mon_list[count][data['start_date']], mon_list[count][data['end_date']]))
|
||||
|
||||
#----------------------------------------------------------
|
||||
|
||||
actual = actual and flt(actual[0][0]) or 0
|
||||
r.append(actual)
|
||||
# ================ Variance ===================================================
|
||||
|
||||
r.append(r[idx] - r[idx + 1])
|
||||
|
||||
count = count +1
|
||||
@@ -1,26 +0,0 @@
|
||||
[
|
||||
{
|
||||
"owner": "Administrator",
|
||||
"docstatus": 0,
|
||||
"creation": "2012-04-03 12:49:53",
|
||||
"modified_by": "Administrator",
|
||||
"modified": "2012-04-03 12:49:53"
|
||||
},
|
||||
{
|
||||
"parent_doc_type": "Sales Person",
|
||||
"module": "Selling",
|
||||
"doctype": "Search Criteria",
|
||||
"sort_order": "DESC",
|
||||
"filters": "{'Sales Person\u0001Country':'','Sales Person\u0001State':'','Target Detail\u0001Fiscal Year':''}",
|
||||
"standard": "Yes",
|
||||
"doc_type": "Target Detail",
|
||||
"name": "__common__",
|
||||
"sort_by": "`tabTarget Detail`.`target_amount`",
|
||||
"page_len": 50,
|
||||
"criteria_name": "Territories Target Variance (Item Group wise)"
|
||||
},
|
||||
{
|
||||
"name": "territories_target_variance_item_group_wise",
|
||||
"doctype": "Search Criteria"
|
||||
}
|
||||
]
|
||||
@@ -1 +0,0 @@
|
||||
from __future__ import unicode_literals
|
||||
@@ -1,22 +0,0 @@
|
||||
// ERPNext - web based ERP (http://erpnext.com)
|
||||
// Copyright (C) 2012 Web Notes Technologies Pvt Ltd
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
report.customize_filters = function() {
|
||||
this.add_filter({fieldname:'based_on', label:'Based On', fieldtype:'Select', options:'Sales Order'+NEWLINE+'Delivery Note'+NEWLINE+'Sales Invoice',report_default:'Sales Order',ignore : 1, parent:'Territory'});
|
||||
this.add_filter({fieldname:'fiscal_year', label:'Fiscal Year', fieldtype:'Link', options:'Fiscal Year', report_default:sys_defaults.fiscal_year, ignore : 1, parent:'Territory'});
|
||||
this.add_filter({fieldname:'company', label:'Company', fieldtype:'Link', options:'Company',report_default:sys_defaults.company, ignore : 1, parent:'Territory'});
|
||||
this.add_filter({fieldname:'period', label:'Period', fieldtype:'Select', options:'Monthly'+NEWLINE+'Quarterly'+NEWLINE+'Half Yearly'+NEWLINE+'Annual',report_default:'Quarterly',ignore : 1, parent:'Territory'});
|
||||
}
|
||||
@@ -1,205 +0,0 @@
|
||||
# ERPNext - web based ERP (http://erpnext.com)
|
||||
# Copyright (C) 2012 Web Notes Technologies Pvt Ltd
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
from __future__ import unicode_literals
|
||||
if filter_values.get('period'):
|
||||
period_values = filter_values['period']
|
||||
if len(period_values.split(NEWLINE))>1:
|
||||
msgprint("You can view report only for one period. Please select only one value in period.")
|
||||
raise Exception
|
||||
else:
|
||||
period = period_values.split(NEWLINE)[0]
|
||||
|
||||
if filter_values.get('based_on'):
|
||||
based_on = filter_values['based_on']
|
||||
if len(based_on.split(NEWLINE)) > 1:
|
||||
msgprint("You can view report based on only one criteria. Please select only one value in Based On.")
|
||||
raise Exception
|
||||
else:
|
||||
based_on = based_on.split(NEWLINE)[0]
|
||||
|
||||
if not filter_values.get('fiscal_year'):
|
||||
msgprint("Please Select Fiscal Year")
|
||||
raise Exception
|
||||
elif not filter_values.get('period'):
|
||||
msgprint("Please Select Period")
|
||||
raise Exception
|
||||
elif not filter_values.get('based_on'):
|
||||
msgprint("Please Select the Criteria on which you want your report to be based")
|
||||
raise Exception
|
||||
|
||||
fiscal_year = filter_values.get('fiscal_year')
|
||||
|
||||
# get fiscal year start date and start month
|
||||
# ---------------------------------------------------------
|
||||
year_start_date = sql("select year_start_date,MONTH(year_start_date) from `tabFiscal Year` where name = %s",fiscal_year)
|
||||
start_date = year_start_date and year_start_date[0][0] or ''
|
||||
start_month = year_start_date and year_start_date[0][1] or ''
|
||||
month_name = ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec']
|
||||
|
||||
# Add columns based on period
|
||||
# --------------------------------
|
||||
columns = []
|
||||
# ================ Annual ======================
|
||||
if period == 'Annual':
|
||||
columns.append(['Target','Currency','120px',''])
|
||||
columns.append(['Actual','Currency','120px',''])
|
||||
|
||||
# =========== Half Yearly ======================
|
||||
elif period == 'Half Yearly':
|
||||
columns.append(['Target (H1)','Currency','120px','']) # first half
|
||||
columns.append(['Actual (H1)','Currency','120px','']) # first half
|
||||
if start_month == 1: # this is case when fiscal year starts with JAN
|
||||
columns.append(['Target (H2)','Currency','120px',''])
|
||||
columns.append(['Actual (H2)','Currency','120px',''])
|
||||
else: #this is case when fiscal year starts with other than JAN
|
||||
columns.append(['Target (H2)','Currency','120px',''])
|
||||
columns.append(['Actual (H2)','Currency','120px',''])
|
||||
|
||||
# ================ Quarterly ===================
|
||||
elif period == 'Quarterly':
|
||||
length_1 = (len(month_name) - start_month + 1) / 3 #this gives the total no. of times we need to iterate for quarter
|
||||
val = length_1 % 4
|
||||
q_no = 1
|
||||
for i in range(length_1):
|
||||
value = 3*i + val
|
||||
columns.append(['Target (Q'+cstr(q_no)+')','Currency','120px',''])
|
||||
columns.append(['Actual (Q'+cstr(q_no)+')','Currency','120px',''])
|
||||
q_no += 1
|
||||
length_2 = (start_month - 1) / 3 #this gives the total no. of times we need to iterate for quarter (this is required only if fiscal year starts from april)
|
||||
for i in range(length_2):
|
||||
columns.append(['Target (Q'+cstr(q_no)+')','Currency','120px',''])
|
||||
columns.append(['Actual (Q'+cstr(q_no)+')','Currency','120px',''])
|
||||
q_no += 1;
|
||||
|
||||
|
||||
# =============== Monthly ======================
|
||||
elif period == 'Monthly':
|
||||
for i in range(start_month-1,len(month_name)):
|
||||
columns.append(['Target ('+month_name[i]+')','Currency','120px',''])
|
||||
columns.append(['Actual ('+month_name[i]+')','Currency','120px',''])
|
||||
|
||||
for i in range(start_month-1):
|
||||
columns.append(['Target('+month_name[i]+')','Currency','120px',''])
|
||||
columns.append(['Actual ('+month_name[i]+')','Currency','120px',''])
|
||||
|
||||
|
||||
|
||||
for c in columns:
|
||||
colnames.append(c[0])
|
||||
coltypes.append(c[1])
|
||||
colwidths.append(c[2])
|
||||
coloptions.append(c[3])
|
||||
col_idx[c[0]] = len(colnames)-1
|
||||
|
||||
|
||||
condition = ' docstatus = 1 and fiscal_year = "'+fiscal_year+'"'
|
||||
|
||||
|
||||
for r in res:
|
||||
query = ''
|
||||
|
||||
# ================= Annual Report ===============
|
||||
if period == 'Annual':
|
||||
|
||||
target = sql("select sum(target_amount) from `tabTarget Detail` where parent = %s and parenttype= 'Territory' and fiscal_year = %s ",(r[col_idx['ID']],fiscal_year))
|
||||
target = target and flt(target[0][0]) or 0
|
||||
r.append(target)
|
||||
|
||||
|
||||
so = sql("select sum(net_total) from `tab%s` where territory = '%s' and %s" % (based_on, r[col_idx['ID']],condition))
|
||||
so = so and flt(so[0][0]) or 0
|
||||
r.append(so)
|
||||
|
||||
# ================= Half Yearly Report ===============
|
||||
elif period == 'Half Yearly':
|
||||
target = sql("select sum(target_amount) from `tabTarget Detail` where parent = %s and parenttype= 'Territory' and fiscal_year = %s",(r[col_idx['ID']],fiscal_year))
|
||||
target = target and flt(flt(target[0][0])/2) or 0
|
||||
r.append(target)
|
||||
|
||||
query += ' MONTH(transaction_date) BETWEEN '+cstr(start_month)+' and '+cstr(start_month+5)
|
||||
so = sql("select sum(net_total) from `tab%s` where territory = '%s' and %s and %s" % (based_on, r[col_idx['ID']],condition,query))
|
||||
so = so and flt(so[0][0]) or 0
|
||||
r.append(so)
|
||||
|
||||
r.append(target)
|
||||
|
||||
query =''
|
||||
query += 'MONTH(transaction_date) NOT BETWEEN '+cstr(start_month)+' and '+cstr(start_month+5)
|
||||
so = sql("select sum(net_total) from `tab%s` where territory = '%s' and %s and %s" % (based_on, r[col_idx['ID']],condition,query))
|
||||
so = so and flt(so[0][0]) or 0
|
||||
r.append(so)
|
||||
query = ''
|
||||
|
||||
# =============== Quarterly Report ==============
|
||||
elif period == 'Quarterly':
|
||||
query = ''
|
||||
length_1 = (len(month_name) - start_month + 1) / 3; #this gives the total no. of times we need to iterate for quarter
|
||||
val = length_1 % 4;
|
||||
for i in range(length_1):
|
||||
value = 3*i + val;
|
||||
query +='SUM(CASE WHEN MONTH(transaction_date) BETWEEN '+cstr(value+1)+' AND '+cstr(value+3)+' THEN net_total ELSE NULL END),'
|
||||
length_2 = (start_month - 1) / 3; #this gives the total no. of times we need to iterate for quarter (this is required only if fiscal year starts from april)
|
||||
for i in range(length_2):
|
||||
query += 'SUM(CASE WHEN MONTH(transaction_date) BETWEEN '+cstr(3*i+1)+' AND '+cstr(3*i+3)+' THEN net_total ELSE NULL END)';
|
||||
|
||||
target = sql("select sum(target_amount) from `tabTarget Detail` where parent = %s and parenttype= 'Territory' and fiscal_year = %s",(r[col_idx['ID']],fiscal_year))
|
||||
target = target and flt(flt(target[0][0])/4) or 0
|
||||
|
||||
|
||||
so = sql("SELECT %s from `tab%s` where territory ='%s' and %s " %(query,based_on,r[col_idx['ID']],condition))
|
||||
i = 0
|
||||
length_l = 0
|
||||
for c in columns:
|
||||
if length_l == 0:
|
||||
r.append(target)
|
||||
length_l += 1
|
||||
else:
|
||||
so_total = so and flt(so[0][i]) or 0
|
||||
r.append(so_total)
|
||||
i +=1
|
||||
length_l = 0
|
||||
|
||||
# ================ Monthly Report ===============
|
||||
elif period == 'Monthly':
|
||||
query =''
|
||||
target = sql("select sum(target_amount) from `tabTarget Detail` where parent = %s and parenttype= 'Territory' and fiscal_year = %s",(r[col_idx['ID']],fiscal_year))
|
||||
#msgprint(target)
|
||||
target = target and flt(flt(target[0][0])/12) or 0
|
||||
|
||||
|
||||
# for loop is required twice coz fiscal year starts from April (this will also work if fiscal year starts in January)
|
||||
for i in range(start_month-1,len(month_name)):
|
||||
query += 'SUM(CASE WHEN MONTH(transaction_date) = '+cstr(i+1)+' THEN net_total ELSE NULL END),'
|
||||
|
||||
for i in range(start_month-1):
|
||||
if i != (start_month-2):
|
||||
query += 'SUM(CASE WHEN MONTH(transaction_date) = '+cstr(i+1)+' THEN net_total ELSE NULL END),'
|
||||
else:
|
||||
query += 'SUM(CASE WHEN MONTH(transaction_date) = '+cstr(i+1)+' THEN net_total ELSE NULL END)';
|
||||
so = sql("SELECT %s from `tab%s` where territory ='%s' and %s " %(query,based_on,r[col_idx['ID']],condition))
|
||||
|
||||
i = 0
|
||||
length_l = 0
|
||||
for c in columns:
|
||||
if length_l == 0:
|
||||
r.append(target)
|
||||
length_l += 1
|
||||
else:
|
||||
so_total = so and flt(so[0][i]) or 0
|
||||
r.append(so_total)
|
||||
i +=1
|
||||
length_l = 0
|
||||
@@ -1,26 +0,0 @@
|
||||
[
|
||||
{
|
||||
"owner": "Administrator",
|
||||
"docstatus": 0,
|
||||
"creation": "2012-04-03 12:49:53",
|
||||
"modified_by": "Administrator",
|
||||
"modified": "2012-04-03 12:49:53"
|
||||
},
|
||||
{
|
||||
"module": "Selling",
|
||||
"standard": "Yes",
|
||||
"sort_order": "DESC",
|
||||
"filters": "{'Territory\u0001State':'','Territory\u0001Based On':'Sales Order','Territory\u0001Fiscal Year':'2009-2010','Territory\u0001Company':'Alpha Company','Territory\u0001Period':'Quarterly'}",
|
||||
"doctype": "Search Criteria",
|
||||
"doc_type": "Territory",
|
||||
"name": "__common__",
|
||||
"sort_by": "ID",
|
||||
"page_len": 50,
|
||||
"criteria_name": "Territory Sales - Variance Report",
|
||||
"columns": "Territory\u0001ID"
|
||||
},
|
||||
{
|
||||
"name": "territory_sales_-_variance_report",
|
||||
"doctype": "Search Criteria"
|
||||
}
|
||||
]
|
||||
@@ -1 +0,0 @@
|
||||
from __future__ import unicode_literals
|
||||
@@ -1,28 +0,0 @@
|
||||
// ERPNext - web based ERP (http://erpnext.com)
|
||||
// Copyright (C) 2012 Web Notes Technologies Pvt Ltd
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
report.customize_filters = function() {
|
||||
this.hide_all_filters();
|
||||
this.add_filter({fieldname:'based_on', label:'Based On', fieldtype:'Select', options:'Territory'+NEWLINE+'Sales Person',report_default:'Territory',ignore : 1,parent:'Target Detail', single_select :1});
|
||||
this.add_filter({fieldname:'fiscal_year', label:'Fiscal Year', fieldtype:'Link', options:'Fiscal Year', report_default:sys_defaults.fiscal_year, ignore : 1, parent:'Target Detail'});
|
||||
this.add_filter({fieldname:'period', label:'Period', fieldtype:'Select', options:'Monthly'+NEWLINE+'Quarterly'+NEWLINE+'Half Yearly'+NEWLINE+'Annual',report_default:'Quarterly',ignore : 1, parent:'Target Detail', single_select :1});
|
||||
this.add_filter({fieldname:'under', label:'Under',fieldtype:'Select', options:'Sales Order'+NEWLINE+'Delivery Note'+NEWLINE+'Sales Invoice',report_default:'Sales Order',ignore : 1, parent:'Target Detail', single_select :1});
|
||||
this.add_filter({fieldname : 'target_on', label:'Target On', fieldtype:'Select', options:'Quantity'+NEWLINE+'Amount',report_default:'Quantity',ignore : 1,parent:'Target Detail', single_select :1});
|
||||
}
|
||||
report.aftertableprint = function(t) {
|
||||
$yt(t,'*',1,{whiteSpace:'pre'});
|
||||
}
|
||||
this.mytabs.items['Select Columns'].hide();
|
||||
@@ -1,223 +0,0 @@
|
||||
# ERPNext - web based ERP (http://erpnext.com)
|
||||
# Copyright (C) 2012 Web Notes Technologies Pvt Ltd
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
# validate Filters
|
||||
from __future__ import unicode_literals
|
||||
flt_dict = {'fiscal_year': 'Fiscal Year', 'period': 'Period', 'under' : 'Under', 'based_on' : 'Based On','target_on':'Target On'}
|
||||
for f in flt_dict:
|
||||
if not filter_values.get(f):
|
||||
msgprint("Please Select " + cstr(flt_dict[f]))
|
||||
raise Exception
|
||||
|
||||
# Get Values from fliters
|
||||
fiscal_year = filter_values.get('fiscal_year')
|
||||
period = filter_values.get('period')
|
||||
under = filter_values.get('under')
|
||||
if under == 'Sales Invoice': under = 'Sales Invoice'
|
||||
based_on = filter_values.get('based_on')
|
||||
target_on = filter_values.get('target_on')
|
||||
|
||||
#add distributed id field
|
||||
col = []
|
||||
col.append([based_on,'Date','150px',''])
|
||||
if target_on == 'Quantity':
|
||||
col.append(['Target Quantity','Currency','150px',''])
|
||||
else:
|
||||
col.append(['Target Amount','Currency','150px',''])
|
||||
col.append(['Distribution Id','Date','150px',''])
|
||||
|
||||
for c in col:
|
||||
colnames.append(c[0])
|
||||
coltypes.append(c[1])
|
||||
colwidths.append(c[2])
|
||||
coloptions.append(c[3])
|
||||
|
||||
col_idx[c[0]] = len(colnames)-1
|
||||
|
||||
def make_child_lst(based_on,name):
|
||||
rg = sql("select lft, rgt from `tab%s` where name = '%s'"%(based_on,name))
|
||||
ch_name = sql("select name from `tab%s` where lft between %d and %d"%(based_on,int(rg[0][0]),int(rg[0][1])))
|
||||
chl ='('
|
||||
flag = 1
|
||||
for c in ch_name:
|
||||
if flag == 1:
|
||||
chl += "'%s'"%c[0]
|
||||
flag = 2
|
||||
else:
|
||||
chl +=",'%s'"%c[0]
|
||||
|
||||
chl +=")"
|
||||
return chl
|
||||
|
||||
|
||||
def get_target(target_on,based_on,fiscal_year,r):
|
||||
|
||||
if target_on == 'Quantity':
|
||||
q1 = "select t1.target_qty "
|
||||
q2 = "select sum(t1.target_qty)"
|
||||
if target_on == 'Amount':
|
||||
q1 = "select t1.target_amount "
|
||||
q2 = "select sum(t1.target_amount)"
|
||||
|
||||
cond1 =" t1.fiscal_year ='%s' and t1.parent=t2.name and t1.parenttype = '%s' and t1.docstatus !=2"
|
||||
#----------------------------------------------------------------
|
||||
q = "select t1.name from `tabTarget Detail` t1, `tab%s` t2 where "+cond1+" and t2.name = '%s'"
|
||||
ch = sql(q%(based_on,fiscal_year,based_on,r))
|
||||
|
||||
return {'q1':q1,'q2':q2,'cond1':cond1,'ch':ch}
|
||||
|
||||
for r in res:
|
||||
|
||||
tt = get_target(target_on,based_on,fiscal_year,r[0].strip())
|
||||
|
||||
if tt['ch']:
|
||||
|
||||
cond2 = " ifnull(t1.item_group,'')='' and"
|
||||
qur = tt['q1']+"from `tabTarget Detail` t1, `tab%s` t2 where "+cond2+tt['cond1']+" and t2.name = '%s'"
|
||||
ret_amt = sql(qur%(based_on,fiscal_year,based_on,r[0].strip()))
|
||||
|
||||
#----------------------------------------------------------------
|
||||
if not ret_amt:
|
||||
qur = tt['q2']+"from `tabTarget Detail` t1, `tab%s` t2 where "+tt['cond1']+" and t2.name = '%s'"
|
||||
ret_amt = sql(qur%(based_on,fiscal_year,based_on,r[0].strip()))
|
||||
|
||||
#----------------------------------------------------------------
|
||||
else:
|
||||
node_lst = make_child_lst(based_on,r[0].strip())
|
||||
qur = tt['q2']+"from `tabTarget Detail` t1, `tab%s` t2 where "+tt['cond1']+" and t2.name in %s"
|
||||
ret_amt = sql(qur%(based_on,fiscal_year,based_on,node_lst))
|
||||
|
||||
#----------------------------------------------------------------
|
||||
ret_dis_id = sql("select distribution_id from `tab%s` where name = '%s'"%(based_on,r[0].strip()))
|
||||
|
||||
target_amt = ret_amt and flt(ret_amt[0][0]) or 0
|
||||
dis_id = ret_dis_id and ret_dis_id[0][0] or ''
|
||||
|
||||
r.append(target_amt)
|
||||
r.append(dis_id)
|
||||
|
||||
|
||||
# Set required field names
|
||||
based_on_fn = (based_on == 'Territory') and 'territory' or 'sales_person'
|
||||
|
||||
date_fn = (under == 'Sales Order' ) and 'transaction_date' or 'posting_date'
|
||||
|
||||
mon_list = []
|
||||
|
||||
data = {'start_date':0, 'end_date':1}
|
||||
|
||||
def make_month_list(append_colnames, start_date, mon_list, period, colnames, coltypes, colwidths, coloptions, col_idx):
|
||||
count = 1
|
||||
if period == 'Quarterly' or period == 'Half Yearly' or period == 'Annual': mon_list.append([str(start_date)])
|
||||
for m in range(12):
|
||||
# get last date
|
||||
last_date = str(sql("select LAST_DAY('%s')" % start_date)[0][0])
|
||||
|
||||
# make mon_list for Monthly Period
|
||||
if period == 'Monthly' :
|
||||
mon_list.append([start_date, last_date])
|
||||
# add months as Column names
|
||||
month_name = sql("select MONTHNAME('%s')" % start_date)[0][0]
|
||||
append_colnames(str(month_name)[:3], colnames, coltypes, colwidths, coloptions, col_idx)
|
||||
|
||||
# get start date
|
||||
start_date = str(sql("select DATE_ADD('%s',INTERVAL 1 DAY)" % last_date)[0][0])
|
||||
|
||||
# make mon_list for Quaterly Period
|
||||
if period == 'Quarterly' and count % 3 == 0:
|
||||
mon_list[len(mon_list) - 1 ].append(last_date)
|
||||
# add Column names
|
||||
append_colnames('Q '+ str(count / 3), colnames, coltypes, colwidths, coloptions, col_idx)
|
||||
if count != 12: mon_list.append([start_date])
|
||||
|
||||
# make mon_list for Half Yearly Period
|
||||
if period == 'Half Yearly' and count % 6 == 0 :
|
||||
mon_list[len(mon_list) - 1 ].append(last_date)
|
||||
# add Column Names
|
||||
append_colnames('H'+str(count / 6), colnames, coltypes, colwidths, coloptions, col_idx)
|
||||
if count != 12: mon_list.append([start_date])
|
||||
|
||||
# make mon_list for Annual Period
|
||||
if period == 'Annual' and count % 12 == 0:
|
||||
mon_list[len(mon_list) - 1 ].append(last_date)
|
||||
# add Column Names
|
||||
append_colnames('', colnames, coltypes, colwidths, coloptions, col_idx)
|
||||
count = count +1
|
||||
|
||||
def append_colnames(name, colnames, coltypes, colwidths, coloptions, col_idx):
|
||||
col = ['Target', 'Actual', 'Variance']
|
||||
for c in col:
|
||||
n = str(name) and ' (' + str(name) +')' or ''
|
||||
colnames.append(str(c) + n)
|
||||
coltypes.append('Currency')
|
||||
colwidths.append('150px')
|
||||
coloptions.append('')
|
||||
col_idx[str(c) + n ] = len(colnames) - 1
|
||||
|
||||
|
||||
|
||||
# make default columns
|
||||
#coltypes[col_idx[based_on]] = 'Link'
|
||||
#coloptions[col_idx[based_on]]= based_on
|
||||
|
||||
# get start date
|
||||
start_date = webnotes.conn.get_value('Fiscal Year', fiscal_year, 'year_start_date')
|
||||
if not start_date:
|
||||
msgprint("Please Define Year Start Date for Fiscal Year " + str(fiscal_year))
|
||||
raise Exception
|
||||
start_date = start_date.strftime('%Y-%m-%d')
|
||||
|
||||
# make month list and columns
|
||||
make_month_list(append_colnames, start_date, mon_list, period, colnames, coltypes, colwidths, coloptions, col_idx)
|
||||
|
||||
|
||||
bc_obj = get_obj('Budget Control')
|
||||
for r in res:
|
||||
count = 0
|
||||
|
||||
for idx in range(3, len(colnames), 3):
|
||||
cidx = 2
|
||||
|
||||
# ================= Calculate Target ==========================================
|
||||
r.append(bc_obj.get_monthly_budget( r[cidx], fiscal_year, mon_list[count][data['start_date']], mon_list[count][data['end_date']], r[cidx-1]))
|
||||
|
||||
#================== Actual Amount =============================================
|
||||
actual = 0
|
||||
|
||||
ch = make_child_lst(based_on,r[0].strip())
|
||||
|
||||
#----------------------------------------------------------
|
||||
if target_on == "Quantity":
|
||||
if based_on == "Territory":
|
||||
actual = sql("select sum(ifnull(t2.qty,0)) from `tab%s` t1, `tab%s Detail` t2 where t2.parenttype = '%s' and t2.parent = t1.name and t1.%s in %s and t1.docstatus = 1 and t1.%s between '%s' and '%s'" % (under, (under == 'Sales Invoice') and 'RV' or under, under, based_on_fn, ch, date_fn, mon_list[count][data['start_date']], mon_list[count][data['end_date']]))
|
||||
|
||||
elif based_on == 'Sales Person':
|
||||
actual = sql("select sum(ifnull(t2.qty,0) * ifnull(t3.allocated_percentage,0) / 100) from `tab%s` t1, `tab%s Detail` t2, `tabSales Team` t3 where t2.parent = t1.name and t3.parent = t1.name and t3.%s in %s and t1.docstatus != 2 and t1.docstatus = 1 and t1.%s between '%s' and '%s' "%(under, (under == 'Sales Invoice') and 'RV' or under, based_on_fn, ch, date_fn, mon_list[count][data['start_date']], mon_list[count][data['end_date']]))
|
||||
|
||||
#----------------------------------------------------------
|
||||
if target_on == "Amount":
|
||||
if based_on == 'Territory':
|
||||
|
||||
actual = sql("select sum(ifnull(net_total,0)) from `tab%s` where %s in %s and docstatus = 1 and %s between '%s' and '%s' " % (under, based_on_fn, ch, date_fn, mon_list[count][data['start_date']], mon_list[count][data['end_date']]))
|
||||
|
||||
elif based_on == 'Sales Person':
|
||||
actual = sql("select sum(ifnull(t2.allocated_amount,0)) from `tab%s` t1, `tabSales Team` t2 where t2.%s in %s and t2.parenttype='%s' and t1.docstatus != 2 and t2.parent = t1.name and t1.%s between '%s' and '%s'"%(under, based_on_fn, ch, under, date_fn, mon_list[count][data['start_date']], mon_list[count][data['end_date']]))
|
||||
#----------------------------------------------------------
|
||||
actual = flt(actual[0][0])
|
||||
r.append(actual)
|
||||
# ================ Variance ===================================================
|
||||
r.append(r[idx] - r[idx + 1])
|
||||
count = count +1
|
||||
@@ -1 +0,0 @@
|
||||
SELECT CONCAT(REPEAT(' ', COUNT(parent.name) - 1), node.name) AS name FROM `tab%(based_on)s` AS node,`tab%(based_on)s` AS parent WHERE node.lft BETWEEN parent.lft AND parent.rgt AND node.docstatus !=2 GROUP BY node.name ORDER BY node.lft
|
||||
@@ -1,27 +0,0 @@
|
||||
[
|
||||
{
|
||||
"owner": "Administrator",
|
||||
"docstatus": 0,
|
||||
"creation": "2012-04-03 12:49:53",
|
||||
"modified_by": "Administrator",
|
||||
"modified": "2012-04-03 12:49:53"
|
||||
},
|
||||
{
|
||||
"parent_doc_type": "Sales Person",
|
||||
"module": "Selling",
|
||||
"standard": "Yes",
|
||||
"sort_order": "DESC",
|
||||
"filters": "{'Sales Person\u0001Saved':1,'Sales Person\u0001Submitted':1,'Sales Person\u0001Country':'','Sales Person\u0001State':'','Target Detail\u0001Fiscal Year':''}",
|
||||
"doc_type": "Target Detail",
|
||||
"name": "__common__",
|
||||
"doctype": "Search Criteria",
|
||||
"sort_by": "`tabSales Person`.`name`",
|
||||
"page_len": 50,
|
||||
"criteria_name": "Total Target Variance Report",
|
||||
"columns": "Sales Person\u0001ID,Sales Person\u0001Owner,Sales Person\u0001Sales Person,Sales Person\u0001Country,Sales Person\u0001State,Sales Person\u0001lft,Sales Person\u0001rgt,Target Detail\u0001Item Group,Target Detail\u0001Fiscal Year,Target Detail\u0001Target Amount"
|
||||
},
|
||||
{
|
||||
"name": "total_target_variance_report",
|
||||
"doctype": "Search Criteria"
|
||||
}
|
||||
]
|
||||
@@ -1 +0,0 @@
|
||||
from __future__ import unicode_literals
|
||||
@@ -1,28 +0,0 @@
|
||||
// ERPNext - web based ERP (http://erpnext.com)
|
||||
// Copyright (C) 2012 Web Notes Technologies Pvt Ltd
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
report.customize_filters = function() {
|
||||
this.hide_all_filters();
|
||||
this.add_filter({fieldname:'based_on', label:'Based On', fieldtype:'Select', options:'Territory'+NEWLINE+'Sales Person'+NEWLINE+'Sales Partner',report_default:'Territory',ignore : 1,parent:'Target Detail'});
|
||||
this.add_filter({fieldname:'fiscal_year', label:'Fiscal Year', fieldtype:'Link', options:'Fiscal Year', report_default:sys_defaults.fiscal_year, ignore : 1, parent:'Target Detail'});
|
||||
this.add_filter({fieldname:'company', label:'Company', fieldtype:'Link', options:'Company',report_default:sys_defaults.company, ignore : 1, parent:'Target Detail'});
|
||||
this.add_filter({fieldname:'period', label:'Period', fieldtype:'Select', options:'Monthly'+NEWLINE+'Quarterly'+NEWLINE+'Half Yearly'+NEWLINE+'Annual',report_default:'Quarterly',ignore : 1, parent:'Target Detail'});
|
||||
// this.add_filter({fieldname:'item_group', label:'Item Group', fieldtype:'Link', options:'Item Group', ignore : 1, parent:'Target Detail'});
|
||||
this.add_filter({fieldname:'group_by', label:'Group By', fieldtype:'Select', options:NEWLINE+'Item Group',ignore : 1, parent:'Target Detail'});
|
||||
this.add_filter({fieldname:'under', label:'Under',fieldtype:'Select', options:'Sales Order'+NEWLINE+'Delivery Note'+NEWLINE+'Sales Invoice',report_default:'Sales Order',ignore : 1, parent:'Target Detail'});
|
||||
}
|
||||
|
||||
//this.mytabs.items['Select Columns'].hide()
|
||||
@@ -1,520 +0,0 @@
|
||||
# ERPNext - web based ERP (http://erpnext.com)
|
||||
# Copyright (C) 2012 Web Notes Technologies Pvt Ltd
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
# Add columns
|
||||
# -----------
|
||||
from __future__ import unicode_literals
|
||||
row_list = [['ID','Data','150px','']]
|
||||
|
||||
for r in row_list:
|
||||
colnames.append(r[0])
|
||||
coltypes.append(r[1])
|
||||
colwidths.append(r[2])
|
||||
coloptions.append(r[3])
|
||||
col_idx[r[0]] = len(colnames)-1
|
||||
|
||||
if not filter_values.get('fiscal_year'):
|
||||
msgprint("Please Select Fiscal Year")
|
||||
raise Exception
|
||||
elif not filter_values.get('period'):
|
||||
msgprint("Please Select Period")
|
||||
raise Exception
|
||||
elif not filter_values.get('based_on'):
|
||||
msgprint("Please Select the Criteria on which you want your report to be based")
|
||||
raise Exception
|
||||
elif not filter_values.get('group_by') and filter_values.get('item_group'):
|
||||
msgprint("Item Group cannot be selected if Group By is not Item Group")
|
||||
raise Exception
|
||||
|
||||
fiscal_year = filter_values.get('fiscal_year')
|
||||
period = filter_values.get('period')
|
||||
based_on = filter_values.get('based_on')
|
||||
group_by = filter_values.get('group_by')
|
||||
item_group = filter_values.get('item_group')
|
||||
msgprint(item_group)
|
||||
company = filter_values.get('company')
|
||||
under = filter_values.get('under')
|
||||
|
||||
#if filter_values.get('item_group'):
|
||||
# itm_grp = filter_values.get('item_group')
|
||||
|
||||
if based_on == 'Territory':
|
||||
based = 'territory'
|
||||
elif based_on == 'Sales Person':
|
||||
based = 'sales_person'
|
||||
elif based_on == 'Sales Partner':
|
||||
based = 'sales_partner'
|
||||
|
||||
|
||||
if under == 'Sales Invoice':
|
||||
under_detail = 'RV'
|
||||
dt = 'posting_date'
|
||||
else:
|
||||
under_detail = under
|
||||
dt = "transaction_date"
|
||||
|
||||
# get fiscal year start date and start month
|
||||
year_start_date = sql("select year_start_date,MONTH(year_start_date) from `tabFiscal Year` where name = %s",fiscal_year)
|
||||
start_date = year_start_date and year_start_date[0][0] or ''
|
||||
start_month = year_start_date and year_start_date[0][1] or ''
|
||||
month_name = ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec']
|
||||
|
||||
# Add columns based on period
|
||||
# --------------------------------
|
||||
columns = []
|
||||
if group_by == 'Item Group':
|
||||
columns.append(['Item Group','Data','120px',''])
|
||||
# ================ Annual ======================
|
||||
if period == 'Annual':
|
||||
columns.append(['Target','Currency','120px',''])
|
||||
columns.append(['Actual','Currency','120px',''])
|
||||
|
||||
# =========== Half Yearly ======================
|
||||
elif period == 'Half Yearly':
|
||||
columns.append(['Target (H1)','Currency','120px','']) # first half
|
||||
columns.append(['Actual (H1)','Currency','120px','']) # first half
|
||||
columns.append(['Target (H2)','Currency','120px',''])
|
||||
columns.append(['Actual (H2)','Currency','120px',''])
|
||||
|
||||
# ================ Quarterly ===================
|
||||
elif period == 'Quarterly':
|
||||
length_1 = (len(month_name) - start_month + 1) / 3 #this gives the total no. of times we need to iterate for quarter
|
||||
val = length_1 % 4
|
||||
q_no = 1
|
||||
for i in range(length_1):
|
||||
value = 3*i + val
|
||||
columns.append(['Target (Q'+cstr(q_no)+')','Currency','120px',''])
|
||||
columns.append(['Actual (Q'+cstr(q_no)+')','Currency','120px',''])
|
||||
q_no += 1
|
||||
length_2 = (start_month - 1) / 3 #this gives the total no. of times we need to iterate for quarter (this is required only if fiscal year starts from april)
|
||||
for i in range(length_2):
|
||||
columns.append(['Target (Q'+cstr(q_no)+')','Currency','120px',''])
|
||||
columns.append(['Actual (Q'+cstr(q_no)+')','Currency','120px',''])
|
||||
q_no += 1;
|
||||
|
||||
# =============== Monthly ======================
|
||||
elif period == 'Monthly':
|
||||
for i in range(start_month-1,len(month_name)):
|
||||
columns.append(['Target ('+month_name[i]+')','Currency','120px',''])
|
||||
columns.append(['Actual ('+month_name[i]+')','Currency','120px',''])
|
||||
|
||||
for i in range(start_month-1):
|
||||
columns.append(['Target('+month_name[i]+')','Currency','120px',''])
|
||||
columns.append(['Actual ('+month_name[i]+')','Currency','120px',''])
|
||||
|
||||
for c in columns:
|
||||
colnames.append(c[0])
|
||||
coltypes.append(c[1])
|
||||
colwidths.append(c[2])
|
||||
coloptions.append(c[3])
|
||||
col_idx[c[0]] = len(colnames)-1
|
||||
|
||||
out = []
|
||||
if company:
|
||||
condition = ' fiscal_year = "'+fiscal_year+'" and company = "'+company+'"'
|
||||
else:
|
||||
condition = ' fiscal_year = "'+fiscal_year+'"'
|
||||
|
||||
#=================== function for fetching allocated percentage in Distribution id according to period=============
|
||||
def get_budget_distribution(period,dist_id,fiscal_year):
|
||||
query = ''
|
||||
id1 = 1
|
||||
if period == 'Half Yearly':
|
||||
id2 = 6
|
||||
for i in range(2):
|
||||
query += 'SUM(CASE WHEN t2.idx BETWEEN '+str(id1)+' AND '+str(id2)+' THEN t2.percentage_allocation ELSE NULL END)'
|
||||
id1 += 6
|
||||
id2 += 6
|
||||
if i < 1 :
|
||||
query += ','
|
||||
|
||||
elif period == 'Quarterly':
|
||||
id2 = 3
|
||||
for i in range(4):
|
||||
query += 'SUM(CASE WHEN t2.idx BETWEEN '+str(id1)+' AND '+str(id2)+' THEN t2.percentage_allocation ELSE NULL END)'
|
||||
id1 += 3
|
||||
id2 += 3
|
||||
if i < 3 :
|
||||
query += ','
|
||||
|
||||
elif period == 'Monthly':
|
||||
for i in range(12):
|
||||
query += 'SUM(CASE WHEN t2.idx ='+str(id1)+' THEN t2.percentage_allocation ELSE NULL END)'
|
||||
id1 += 1
|
||||
if i < 11 :
|
||||
query += ','
|
||||
|
||||
# msgprint(query)
|
||||
|
||||
# Main Query
|
||||
dist = sql("select %s from `tabBudget Distribution` t1, `tabBudget Distribution Detail` t2 where t1.name = '%s' and t2.parent = t1.name and t1.fiscal_year = '%s'"%(query,dist_id,fiscal_year))
|
||||
dist = dist and dist[0] or 0
|
||||
# msgprint(dist)
|
||||
bug = []
|
||||
for i in dist:
|
||||
i = i and float(i) or 0
|
||||
bug.append(i)
|
||||
# msgprint(bug)
|
||||
return bug
|
||||
|
||||
|
||||
#============ function for appending target amt and actual amt in a proper order =======================
|
||||
def appending_func(ran,tl,lst,actual,flt):
|
||||
|
||||
c = 2
|
||||
for i in range(ran):
|
||||
#==== for each itemgroup their actual amt is appended/inserted between target amt
|
||||
if tl == 0:
|
||||
lst.insert(c,actual and flt(actual[0][i]) or 0)
|
||||
#======== here actual amt is appended/inserted b/w target amt for a particular territory/sales person/sales partner only if target is not zero
|
||||
elif tl == 1:
|
||||
# msgprint(lst)
|
||||
lst.insert(c,actual and flt(actual[0][i]) or 0)
|
||||
c += 2
|
||||
return lst
|
||||
|
||||
def get_target(tar_det,group_by,period,fiscal_year,rng,r,get_budget_distribution,flt):
|
||||
|
||||
grp,lst = [],[]
|
||||
list_range,tl = 0,0
|
||||
if group_by == 'Item Group':
|
||||
for i in tar_det:
|
||||
if i[0] != '':
|
||||
igrp = [i[0]]
|
||||
if i[2]:
|
||||
dist_id = i[2]
|
||||
dist = get_budget_distribution(period,dist_id,fiscal_year)
|
||||
for d in dist:
|
||||
t = flt(flt(flt(i[1]) * flt(d))/ 100)
|
||||
igrp.append(t)
|
||||
else:
|
||||
t = i and flt(i[1]/rng) or 0
|
||||
for i in range(rng):
|
||||
igrp.append(t)
|
||||
|
||||
grp.append(igrp)
|
||||
list_range +=1
|
||||
lst = [1,grp,list_range]
|
||||
|
||||
#============== Total target(on basis of whole target ) ============
|
||||
else:
|
||||
for i in tar_det:
|
||||
if i[0] == '':
|
||||
if i[2]:
|
||||
dist_id = i[2]
|
||||
dist = get_budget_distribution(period,dist_id,fiscal_year)
|
||||
for d in dist:
|
||||
t = flt((flt(i[1]) * flt(d))/ 100)
|
||||
r.append(t)
|
||||
else:
|
||||
tot_target = i and flt(i[1]/rng) or 0
|
||||
for i in range(rng):
|
||||
r.append(tot_target)
|
||||
tl = 1
|
||||
lst = [0,r,tl]
|
||||
return lst
|
||||
#============ report display function =====================
|
||||
for r in res:
|
||||
query = ''
|
||||
grp=[]
|
||||
list_range, count, ap, tot_target, tl = 0,0,0,0,0
|
||||
|
||||
#============= ANNUAL REPORT ===================
|
||||
if period == 'Annual':
|
||||
tar_det = sql("select item_group, target_amount, distribution_id from `tabTarget Detail` where parent = %s and parenttype = %s and fiscal_year = %s",(r[col_idx['ID']],based_on,fiscal_year))
|
||||
# msgprint(tar_det)
|
||||
|
||||
#================ Target based on individual item group ==============
|
||||
if group_by == 'Item Group':
|
||||
for i in tar_det:
|
||||
if i[0] != '':
|
||||
grp_target = i and flt(i[1]) or 0
|
||||
igrp = [i[0],grp_target]
|
||||
grp.append(igrp)
|
||||
# msgprint(grp)
|
||||
list_range +=1
|
||||
count = 3
|
||||
|
||||
#============== Total target(will be displayed only if target is specified by the user) ============
|
||||
else:
|
||||
for i in tar_det:
|
||||
# ======= here target is considered and not sum of target of item groups
|
||||
if i[0] == '':
|
||||
tot_target = tar_det and flt(i[1]) or 0
|
||||
# msgprint(tot_target)
|
||||
|
||||
#================== Actual Amount =============================================
|
||||
if based_on == 'Territory' or based_on == 'Sales Partner':
|
||||
|
||||
if group_by =='Item Group':
|
||||
|
||||
for i in grp:
|
||||
item_group = i[0]
|
||||
actual = sql("select sum(t2.amount) from `tab%s` t1, `tab%s Detail` t2, `tabItem` t3 where t2.parent = t1.name and t1.%s = '%s' and t3.name = t2.item_code and t3.item_group = '%s' and t1.docstatus = 1 and t1.docstatus != 2 and %s"%(under,under_detail,based,r[col_idx['ID']],item_group,condition))
|
||||
msgprint(actual)
|
||||
actual = actual and flt(actual[0][0]) or 0
|
||||
i.append(actual)
|
||||
|
||||
else:
|
||||
actual = sql("select sum(net_total) from `tab%s` where %s = '%s' and docstatus = 1 and %s" % (under, based, r[col_idx['ID']],condition))
|
||||
actual = actual and flt(actual[0][0]) or 0
|
||||
|
||||
elif based_on == 'Sales Person':
|
||||
if group_by =='Item Group':
|
||||
for i in grp:
|
||||
item_group = i[0]
|
||||
actual = sql("select sum(t2.amount) from `tab%s` t1, `tab%s Detail` t2, `tabSales Team` t3, `tabItem` t4 where t2.parent = t1.name and t3.parent = t1.name and t3.%s = '%s' and t4.name = t2.item_code and t4.item_group = '%s' and t1.docstatus != 2 and t1.docstatus = 1 and %s"%(under,under_detail,based,r[col_idx['ID']],item_group,condition))
|
||||
actual = actual and flt(actual[0][0]) or 0
|
||||
# msgprint(actual)
|
||||
i.append(actual)
|
||||
|
||||
else:
|
||||
actual = sql("select sum(t1.net_total) from `tab%s` t1, `tabSales Team` t2 where t2.%s = '%s' and t2.parenttype='%s' and t1.docstatus != 2 and t2.parent = t1.name and %s"%(under,based,r[col_idx['ID']],under,condition))
|
||||
actual = actual and flt(actual[0][0]) or 0
|
||||
# msgprint(actual)
|
||||
|
||||
# ================= Half Yearly Report ===============
|
||||
elif period == 'Half Yearly':
|
||||
tl = 0
|
||||
grp_target = []
|
||||
|
||||
tar_det = sql("select item_group, target_amount, distribution_id from `tabTarget Detail` where parent = %s and parenttype = %s and fiscal_year = %s",(r[col_idx['ID']],based_on,fiscal_year))
|
||||
# msgprint(tar_det)
|
||||
|
||||
tar = get_target(tar_det,group_by,period,fiscal_year,2,r,get_budget_distribution,flt)
|
||||
if tar[0] == 1:
|
||||
grp = tar[1]
|
||||
list_range = tar[2]
|
||||
count = 5
|
||||
else:
|
||||
r = tar[1]
|
||||
tl = tar[2]
|
||||
|
||||
#============= Actual Amount======================
|
||||
if group_by == 'Item Group':
|
||||
# first half
|
||||
query += 'SUM(CASE WHEN MONTH(t1.'+dt+') BETWEEN '+cstr(start_month)+' AND '+cstr(start_month+5)+' THEN t2.amount ELSE NULL END),'
|
||||
# second half
|
||||
query += 'SUM(CASE WHEN MONTH(t1.'+dt+') NOT BETWEEN '+cstr(start_month)+' AND '+cstr(start_month+5)+' THEN t2.amount ELSE NULL END)';
|
||||
|
||||
elif based_on != 'Sales Person':
|
||||
# first half
|
||||
query += 'SUM(CASE WHEN MONTH('+dt+') BETWEEN '+cstr(start_month)+' AND '+cstr(start_month+5)+' THEN net_total ELSE NULL END),'
|
||||
# second half
|
||||
query += 'SUM(CASE WHEN MONTH('+dt+') NOT BETWEEN '+cstr(start_month)+' AND '+cstr(start_month+5)+' THEN net_total ELSE NULL END)';
|
||||
|
||||
else:
|
||||
# first half
|
||||
query += 'SUM(CASE WHEN MONTH(t1.'+dt+') BETWEEN '+cstr(start_month)+' AND '+cstr(start_month+5)+' THEN t1.net_total ELSE NULL END),'
|
||||
# second half
|
||||
query += 'SUM(CASE WHEN MONTH(t1.'+dt+') NOT BETWEEN '+cstr(start_month)+' AND '+cstr(start_month+5)+' THEN t1.net_total ELSE NULL END)';
|
||||
|
||||
#=========== Main Query ===============
|
||||
if based_on == 'Territory' or based_on == 'Sales Partner':
|
||||
|
||||
if group_by =='Item Group':
|
||||
for i in grp:
|
||||
item_group = i[0]
|
||||
actual = sql("select %s from `tab%s` t1, `tab%s Detail` t2, `tabItem` t3 where t2.parent = t1.name and t1.%s = '%s' and t3.name = t2.item_code and t3.item_group = '%s' and t1.docstatus = 1 and t1.docstatus != 2 and %s"%(query,under,under_detail,based,r[col_idx['ID']],item_group,condition))
|
||||
# msgprint(actual)
|
||||
i = appending_func(2,tl,i,actual,flt)
|
||||
|
||||
else:
|
||||
actual = sql("select %s from `tab%s` where %s = '%s' and docstatus = 1 and %s" % (query,under, based, r[col_idx['ID']],condition))
|
||||
# msgprint(actual)
|
||||
|
||||
elif based_on == 'Sales Person':
|
||||
if group_by =='Item Group':
|
||||
for i in grp:
|
||||
item_group = i[0]
|
||||
actual = sql("select %s from `tab%s` t1, `tab%s Detail` t2, `tabSales Team` t3, `tabItem` t4 where t2.parent = t1.name and t3.parent = t1.name and t3.%s = '%s' and t4.name = t2.item_code and t4.item_group = '%s' and t1.docstatus != 2 and t1.docstatus = 1 and %s"%(query,under,under_detail,based,r[col_idx['ID']],item_group,condition))
|
||||
# msgprint(actual)
|
||||
i = appending_func(2,tl,i,actual,flt)
|
||||
else:
|
||||
actual = sql("select %s from `tab%s` t1, `tabSales Team` t2 where t2.%s = '%s' and t2.parenttype='%s' and t1.docstatus != 2 and t2.parent = t1.name and %s"%(query,under,based,r[col_idx['ID']],under,condition))
|
||||
# msgprint(actual)
|
||||
|
||||
if tl == 1:
|
||||
r = appending_func(2,tl,r,actual,flt)
|
||||
# msgprint(r)
|
||||
|
||||
#============== Quarterly Report =========================
|
||||
elif period == 'Quarterly':
|
||||
tl = 0
|
||||
grp_target = []
|
||||
tar_det = sql("select item_group, target_amount, distribution_id from `tabTarget Detail` where parent = %s and parenttype = %s and fiscal_year = %s",(r[col_idx['ID']],based_on,fiscal_year))
|
||||
|
||||
tar = get_target(tar_det,group_by,period,fiscal_year,4,r,get_budget_distribution,flt)
|
||||
if tar[0] == 1:
|
||||
grp = tar[1]
|
||||
list_range = tar[2]
|
||||
count = 9
|
||||
else:
|
||||
r = tar[1]
|
||||
tl = tar[2]
|
||||
|
||||
#======= Actual Amt ==================
|
||||
length_1 = (len(month_name) - start_month + 1) / 3; #this gives the total no. of times we need to iterate for quarter
|
||||
val = length_1 % 4;
|
||||
for i in range(length_1):
|
||||
value = 3*i + val;
|
||||
|
||||
if group_by == 'Item Group':
|
||||
query += 'SUM(CASE WHEN MONTH(t1.'+dt+') BETWEEN '+cstr(value+1)+' AND '+cstr(value+3)+' THEN t2.amount ELSE NULL END),'
|
||||
|
||||
elif based_on != 'Sales Person':
|
||||
query += 'SUM(CASE WHEN MONTH('+dt+') BETWEEN '+cstr(value+1)+' AND '+cstr(value+3)+' THEN net_total ELSE NULL END),'
|
||||
|
||||
else:
|
||||
query += 'SUM(CASE WHEN MONTH(t1.'+dt+') BETWEEN '+cstr(value+1)+' AND '+cstr(value+3)+' THEN t1.net_total ELSE NULL END),'
|
||||
|
||||
length_2 = (start_month - 1) / 3; #this gives the total no. of times we need to iterate for quarter (this is required only if fiscal year starts from april)
|
||||
for i in range(length_2):
|
||||
if group_by == 'Item Group':
|
||||
query += 'SUM(CASE WHEN MONTH(t1.'+dt+') BETWEEN '+cstr(3*i+1)+' AND '+cstr(3*i+3)+' THEN t2.amount ELSE NULL END)';
|
||||
|
||||
elif based_on != 'Sales Person':
|
||||
query += 'SUM(CASE WHEN MONTH('+dt+') BETWEEN '+cstr(3*i+1)+' AND '+cstr(3*i+3)+' THEN net_total ELSE NULL END)';
|
||||
|
||||
else:
|
||||
query += 'SUM(CASE WHEN MONTH(t1.'+dt+') BETWEEN '+cstr(3*i+1)+' AND '+cstr(3*i+3)+' THEN t1.net_total ELSE NULL END)';
|
||||
|
||||
#=========== Main Query ===============
|
||||
if based_on == 'Territory' or based_on == 'Sales Partner':
|
||||
|
||||
if group_by =='Item Group':
|
||||
for i in grp:
|
||||
item_group = i[0]
|
||||
actual = sql("select %s from `tab%s` t1, `tab%s Detail` t2, `tabItem` t3 where t2.parent = t1.name and t1.%s = '%s' and t3.name = t2.item_code and t3.item_group = '%s' and t1.docstatus = 1 and t1.docstatus != 2 and %s"%(query,under,under_detail,based,r[col_idx['ID']],item_group,condition))
|
||||
# msgprint(actual)
|
||||
#================common function
|
||||
i = appending_func(4,tl,i,actual,flt)
|
||||
|
||||
else:
|
||||
actual = sql("select %s from `tab%s` where %s = '%s' and docstatus = 1 and %s" % (query,under, based, r[col_idx['ID']],condition))
|
||||
# msgprint(actual)
|
||||
|
||||
elif based_on == 'Sales Person':
|
||||
if group_by =='Item Group':
|
||||
for i in grp:
|
||||
item_group = i[0]
|
||||
actual = sql("select %s from `tab%s` t1, `tab%s Detail` t2, `tabSales Team` t3, `tabItem` t4 where t2.parent = t1.name and t3.parent = t1.name and t3.%s = '%s' and t4.name = t2.item_code and t4.item_group = '%s' and t1.docstatus != 2 and t1.docstatus = 1 and %s"%(query,under,under_detail,based,r[col_idx['ID']],item_group,condition))
|
||||
# msgprint(actual)
|
||||
i = appending_func(4,tl,i,actual,flt)
|
||||
else:
|
||||
actual = sql("select %s from `tab%s` t1, `tabSales Team` t2 where t2.%s = '%s' and t2.parenttype='%s' and t1.docstatus != 2 and t2.parent = t1.name and %s"%(query,under,based,r[col_idx['ID']],under,condition))
|
||||
# msgprint(actual)
|
||||
|
||||
if tl == 1:
|
||||
r = appending_func(4,tl,r,actual,flt)
|
||||
# msgprint(r)
|
||||
|
||||
#================ Monthly Report ===========================
|
||||
elif period == 'Monthly':
|
||||
tl = 0
|
||||
grp_target = []
|
||||
tar_det = sql("select item_group, target_amount, distribution_id from `tabTarget Detail` where parent = %s and parenttype = %s and fiscal_year = %s",(r[col_idx['ID']],based_on,fiscal_year))
|
||||
|
||||
tar = get_target(tar_det,group_by,period,fiscal_year,12,r,get_budget_distribution,flt)
|
||||
if tar[0] == 1:
|
||||
grp = tar[1]
|
||||
list_range = tar[2]
|
||||
count = 25
|
||||
else:
|
||||
r = tar[1]
|
||||
tl = tar[2]
|
||||
|
||||
#======= Actual Amt ==================
|
||||
# for loop is required twice coz fiscal year starts from April (this will also work if fiscal year starts in January)
|
||||
for i in range(start_month-1,len(month_name)):
|
||||
if group_by == 'Item Group':
|
||||
query += 'SUM(CASE WHEN MONTH(t1.'+dt+') = '+cstr(i+1)+' THEN t2.amount ELSE NULL END),'
|
||||
|
||||
elif based_on != 'Sales Person':
|
||||
query += 'SUM(CASE WHEN MONTH('+dt+') = '+cstr(i+1)+' THEN net_total ELSE NULL END),'
|
||||
|
||||
else:
|
||||
query += 'SUM(CASE WHEN MONTH(t1.'+dt+') = '+cstr(i+1)+' THEN t1.net_total ELSE NULL END),'
|
||||
|
||||
for i in range(start_month-1):
|
||||
if i != (start_month-1):
|
||||
if group_by == 'Item Group':
|
||||
query += 'SUM(CASE WHEN MONTH(t1.'+dt+') = '+cstr(i+1)+' THEN t2.amount ELSE NULL END)'
|
||||
|
||||
elif based_on != 'Sales Person':
|
||||
query += 'SUM(CASE WHEN MONTH('+dt+') = '+cstr(i+1)+' THEN net_total ELSE NULL END)'
|
||||
|
||||
else:
|
||||
query += 'SUM(CASE WHEN MONTH(t1.'+dt+') = '+cstr(i+1)+' THEN t1.net_total ELSE NULL END)'
|
||||
|
||||
if i < (start_month -2):
|
||||
query += ','
|
||||
|
||||
#=========== Main Query ===============
|
||||
if based_on == 'Territory' or based_on == 'Sales Partner':
|
||||
|
||||
if group_by =='Item Group':
|
||||
for i in grp:
|
||||
item_group = i[0]
|
||||
actual = sql("select %s from `tab%s` t1, `tab%s Detail` t2, `tabItem` t3 where t2.parent = t1.name and t1.%s = '%s' and t3.name = t2.item_code and t3.item_group = '%s' and t1.docstatus = 1 and t1.docstatus != 2 and %s"%(query,under,under_detail,based,r[col_idx['ID']],item_group,condition))
|
||||
# msgprint(actual)
|
||||
#===============common function=====================
|
||||
i = appending_func(12,tl,i,actual,flt)
|
||||
|
||||
else:
|
||||
actual = sql("select %s from `tab%s` where %s = '%s' and docstatus = 1 and %s" % (query,under, based, r[col_idx['ID']],condition))
|
||||
# msgprint(actual)
|
||||
|
||||
elif based_on == 'Sales Person':
|
||||
if group_by =='Item Group':
|
||||
for i in grp:
|
||||
item_group = i[0]
|
||||
actual = sql("select %s from `tab%s` t1, `tab%s Detail` t2, `tabSales Team` t3, `tabItem` t4 where t2.parent = t1.name and t3.parent = t1.name and t3.%s = '%s' and t4.name = t2.item_code and t4.item_group = '%s' and t1.docstatus != 2 and t1.docstatus = 1 and %s"%(query,under,under_detail,based,r[col_idx['ID']],item_group,condition))
|
||||
# msgprint(actual)
|
||||
i = appending_func(12,tl,i,actual,flt)
|
||||
else:
|
||||
actual = sql("select %s from `tab%s` t1, `tabSales Team` t2 where t2.%s = '%s' and t2.parenttype='%s' and t1.docstatus != 2 and t2.parent = t1.name and %s"%(query,under,based,r[col_idx['ID']],under,condition))
|
||||
# msgprint(actual)
|
||||
|
||||
if tl == 1:
|
||||
r = appending_func(12,tl,r,actual,flt)
|
||||
# msgprint(r)
|
||||
|
||||
#-------------DISPLAY OF TARGET vs ACTUAL ON BASIS OF TOTAL TARGET / ITEM GROUP
|
||||
|
||||
if group_by == 'Item Group':
|
||||
for col in range(len(colnames)-1): # this would make all first row blank. just for look
|
||||
r.append('')
|
||||
|
||||
for des in range(list_range):
|
||||
if ap == 0:
|
||||
out.append(r)
|
||||
ap = 1
|
||||
t_row = ['' for i in range(len(colnames))]
|
||||
|
||||
for v in range(count):
|
||||
t_row[col_idx[colnames[v+1]]] = grp[des][v]
|
||||
# msgprint(t_row)
|
||||
out.append(t_row)
|
||||
|
||||
elif tot_target != 0 and period =='Annual':
|
||||
r.append(tot_target)
|
||||
r.append(actual)
|
||||
out.append(r)
|
||||
tot_target = 0
|
||||
|
||||
elif tl == 1:
|
||||
out.append(r)
|
||||
@@ -1 +0,0 @@
|
||||
SELECT DISTINCT t1.`name` FROM `tab%(based_on)s` t1, `tabTarget Detail` t2 WHERE t2.parent = t1.name and (t2.target_amount != 0 or t2.target_amount is not null)
|
||||
@@ -1,26 +0,0 @@
|
||||
[
|
||||
{
|
||||
"owner": "Administrator",
|
||||
"docstatus": 0,
|
||||
"creation": "2012-04-03 12:49:53",
|
||||
"modified_by": "Administrator",
|
||||
"modified": "2012-04-03 12:49:53"
|
||||
},
|
||||
{
|
||||
"parent_doc_type": "Territory",
|
||||
"module": "Selling",
|
||||
"doctype": "Search Criteria",
|
||||
"sort_order": "DESC",
|
||||
"filters": "{'Territory\u0001State':'','Target Detail\u0001Fiscal Year':'2009-2010','Target Detail\u0001Based On':'Territory','Target Detail\u0001Company':'Alpha Company','Target Detail\u0001Period':'Quarterly','Target Detail\u0001Under':'Sales Order'}",
|
||||
"standard": "Yes",
|
||||
"doc_type": "Target Detail",
|
||||
"name": "__common__",
|
||||
"sort_by": "ID",
|
||||
"page_len": 50,
|
||||
"criteria_name": "Variance Report"
|
||||
},
|
||||
{
|
||||
"name": "variance_report",
|
||||
"doctype": "Search Criteria"
|
||||
}
|
||||
]
|
||||
Reference in New Issue
Block a user