mirror of
https://github.com/frappe/erpnext.git
synced 2026-06-03 12:19:12 +00:00
moved directory structure
This commit is contained in:
1
selling/search_criteria/__init__.py
Normal file
1
selling/search_criteria/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
from __future__ import unicode_literals
|
||||
@@ -0,0 +1 @@
|
||||
from __future__ import unicode_literals
|
||||
@@ -0,0 +1,23 @@
|
||||
from __future__ import unicode_literals
|
||||
col_defs = [
|
||||
{'label': 'Id', 'type': 'Link', 'width': '', 'options': 'Customer'},
|
||||
{'label': 'Customer Name'},
|
||||
{'label': 'Address Line 1', 'width': '200px'},
|
||||
{'label': 'Address Line 2', 'width': '200px'},
|
||||
{'label': 'City'},
|
||||
{'label': 'State'},
|
||||
{'label': 'Pincode', 'width': '80px'},
|
||||
{'label': 'Country', 'width': '100px'},
|
||||
{'label': 'Contact First Name'},
|
||||
{'label': 'Contact Last Name'},
|
||||
{'label': 'Contact Phone', 'width': '100px'},
|
||||
{'label': 'Contact Mobile', 'width': '100px'},
|
||||
{'label': 'Contact Email'},
|
||||
]
|
||||
webnotes.msgprint(colnames)
|
||||
for col in col_defs:
|
||||
colnames.append(col['label'])
|
||||
coltypes.append(col.get('type') or 'Data')
|
||||
colwidths.append(col.get('width') or '150px')
|
||||
coloptions.append(col.get('options') or '')
|
||||
col_idx[col['label']] = len(colnames) - 1
|
||||
@@ -0,0 +1,26 @@
|
||||
select
|
||||
`tabCustomer`.name,
|
||||
`tabCustomer`.customer_name,
|
||||
`tabAddress`.address_line1,
|
||||
`tabAddress`.address_line2,
|
||||
`tabAddress`.city,
|
||||
`tabAddress`.state,
|
||||
`tabAddress`.pincode,
|
||||
`tabAddress`.country,
|
||||
`tabContact`.first_name,
|
||||
`tabContact`.last_name,
|
||||
`tabContact`.phone,
|
||||
`tabContact`.mobile_no,
|
||||
`tabContact`.email_id
|
||||
from
|
||||
`tabCustomer`
|
||||
left join `tabAddress` on (
|
||||
`tabAddress`.customer=`tabCustomer`.name and
|
||||
ifnull(`tabAddress`.is_primary_address, 0)=1
|
||||
)
|
||||
left join `tabContact` on (
|
||||
`tabContact`.customer=`tabCustomer`.name and
|
||||
ifnull(`tabContact`.is_primary_contact, 0)=1
|
||||
)
|
||||
order by
|
||||
`tabCustomer`.customer_name asc
|
||||
@@ -0,0 +1,31 @@
|
||||
# Search Criteria, customer_address_contact
|
||||
[
|
||||
|
||||
# These values are common in all dictionaries
|
||||
{
|
||||
'creation': '2012-04-17 11:29:10',
|
||||
'docstatus': 0,
|
||||
'modified': '2012-05-23 18:17:40',
|
||||
'modified_by': u'Administrator',
|
||||
'owner': u'Administrator'
|
||||
},
|
||||
|
||||
# These values are common for all Search Criteria
|
||||
{
|
||||
'columns': u'Customer\x01ID,Customer\x01Customer Name',
|
||||
'criteria_name': u'Customer Address Contact',
|
||||
'doc_type': u'Customer',
|
||||
'doctype': 'Search Criteria',
|
||||
'filters': u"{'Customer\x01Saved':1,'Customer\x01Submitted':1}",
|
||||
'module': u'Selling',
|
||||
'name': '__common__',
|
||||
'page_len': 50,
|
||||
'standard': u'Yes'
|
||||
},
|
||||
|
||||
# Search Criteria, customer_address_contact
|
||||
{
|
||||
'doctype': 'Search Criteria',
|
||||
'name': u'customer_address_contact'
|
||||
}
|
||||
]
|
||||
@@ -0,0 +1 @@
|
||||
from __future__ import unicode_literals
|
||||
@@ -0,0 +1,20 @@
|
||||
// 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;
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
# Search Criteria, delivered_items_to_be_install
|
||||
[
|
||||
|
||||
# These values are common in all dictionaries
|
||||
{
|
||||
'creation': '2012-04-03 12:49:51',
|
||||
'docstatus': 0,
|
||||
'modified': '2012-04-03 12:49:51',
|
||||
'modified_by': u'Administrator',
|
||||
'owner': u'Administrator'
|
||||
},
|
||||
|
||||
# These values are common for all Search Criteria
|
||||
{
|
||||
'add_col': u"(`tabDelivery Note Item`.`qty`- ifnull(`tabDelivery Note Item`.`installed_qty`, 0)) AS 'Pending to Install'",
|
||||
'add_cond': u'`tabDelivery Note Item`.`qty` > ifnull(`tabDelivery Note Item`.`installed_qty`, 0)',
|
||||
'columns': u'Delivery Note\x01ID,Delivery Note\x01Status,Delivery Note\x01Customer,Delivery Note\x01Customer Name,Delivery Note\x01Contact Person,Delivery Note\x01Voucher Date,Delivery Note Item\x01Item Code,Delivery Note Item\x01Item Name,Delivery Note Item\x01Quantity,Delivery Note Item\x01Installed Qty,Delivery Note\x01% Installed',
|
||||
'criteria_name': u'Delivered Items to be Install',
|
||||
'description': u'Delivered Items to be Install',
|
||||
'doc_type': u'Delivery Note Item',
|
||||
'doctype': 'Search Criteria',
|
||||
'filters': u"{'Delivery Note\x01Saved':1,'Delivery Note\x01Submitted':1,'Delivery Note\x01Status':'','Delivery Note\x01Fiscal Year':''}",
|
||||
'module': u'Selling',
|
||||
'name': '__common__',
|
||||
'page_len': 50,
|
||||
'parent_doc_type': u'Delivery Note',
|
||||
'sort_by': u'`tabDelivery Note`.`name`',
|
||||
'sort_order': u'DESC',
|
||||
'standard': u'Yes'
|
||||
},
|
||||
|
||||
# Search Criteria, delivered_items_to_be_install
|
||||
{
|
||||
'doctype': 'Search Criteria',
|
||||
'name': u'delivered_items_to_be_install'
|
||||
}
|
||||
]
|
||||
@@ -0,0 +1 @@
|
||||
from __future__ import unicode_literals
|
||||
@@ -0,0 +1,37 @@
|
||||
# Search Criteria, delivery_note_itemwise_pending_to_bill
|
||||
[
|
||||
|
||||
# These values are common in all dictionaries
|
||||
{
|
||||
'creation': '2012-04-03 12:49:51',
|
||||
'docstatus': 0,
|
||||
'modified': '2012-04-03 12:49:51',
|
||||
'modified_by': u'Administrator',
|
||||
'owner': u'jai@webnotestech.com'
|
||||
},
|
||||
|
||||
# These values are common for all Search Criteria
|
||||
{
|
||||
'add_col': u"SUM(`tabDelivery Note Item`.`qty` - `tabDelivery Note Item`.`billed_qty`) AS 'Pending Qty'\nSUM((`tabDelivery Note Item`.`qty` - `tabDelivery Note Item`.`billed_qty`) * `tabDelivery Note Item`.`basic_rate`) AS 'Pending Amount'",
|
||||
'add_cond': u"`tabDelivery Note`.status != 'Stopped'\nCASE WHEN `tabDelivery Note`.`per_billed` IS NULL OR `tabDelivery Note`.per_billed = '' THEN 0 < 100 ELSE `tabDelivery Note`.per_billed <100 END",
|
||||
'columns': u'Delivery Note\x01ID,Delivery Note\x01Owner,Delivery Note\x01Status,Delivery Note\x01Customer Name,Delivery Note\x01Voucher Date,Delivery Note\x01% Billed,Delivery Note\x01Posting Date,Delivery Note\x01Company Name,Delivery Note\x01Fiscal Year,Delivery Note Item\x01Item Code,Delivery Note Item\x01Against Document No,Delivery Note Item\x01Document Type,Delivery Note Item\x01Against Document Detail No',
|
||||
'criteria_name': u'Delivery Note Itemwise Pending To Bill',
|
||||
'doc_type': u'Delivery Note Item',
|
||||
'doctype': 'Search Criteria',
|
||||
'filters': u"{'Delivery Note\x01Saved':1,'Delivery Note\x01Submitted':1,'Delivery Note\x01Status':'','Delivery Note\x01Company Name':'','Delivery Note\x01Fiscal Year':''}",
|
||||
'group_by': u'`tabDelivery Note Item`.item_code, `tabDelivery Note`.`name`',
|
||||
'module': u'Selling',
|
||||
'name': '__common__',
|
||||
'page_len': 50,
|
||||
'parent_doc_type': u'Delivery Note',
|
||||
'sort_by': u'`tabDelivery Note`.`name`',
|
||||
'sort_order': u'DESC',
|
||||
'standard': u'Yes'
|
||||
},
|
||||
|
||||
# Search Criteria, delivery_note_itemwise_pending_to_bill
|
||||
{
|
||||
'doctype': 'Search Criteria',
|
||||
'name': u'delivery_note_itemwise_pending_to_bill'
|
||||
}
|
||||
]
|
||||
1
selling/search_criteria/draft_sales_orders/__init__.py
Normal file
1
selling/search_criteria/draft_sales_orders/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
from __future__ import unicode_literals
|
||||
@@ -0,0 +1,22 @@
|
||||
// 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;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
[
|
||||
{
|
||||
'add_col': None,
|
||||
'add_cond': None,
|
||||
'add_tab': None,
|
||||
'columns': 'Sales Order\x01ID,Sales Order\x01Status,Sales Order\x01Sales Order Date,Sales Order\x01Customer,Sales Order\x01P.O. No,Sales Order\x01Grand Total',
|
||||
'creation': '2010-08-08 17:09:31',
|
||||
'criteria_name': 'Draft Sales Orders',
|
||||
'custom_query': '',
|
||||
'description': 'List of Open Sales orders filtered by period, customer and other details',
|
||||
'dis_filters': None,
|
||||
'disabled': None,
|
||||
'doc_type': 'Sales Order',
|
||||
'docstatus': 0,
|
||||
'doctype': 'Search Criteria',
|
||||
'filters': "{'Sales Order\x01Saved':1,'Sales Order\x01Submitted':1,'Sales Order\x01Status':'Draft','Sales Order\x01Fiscal Year':''}",
|
||||
'graph_series': None,
|
||||
'graph_values': None,
|
||||
'group_by': None,
|
||||
'idx': None,
|
||||
'modified': '2010-06-01 15:19:41',
|
||||
'modified_by': 'Administrator',
|
||||
'module': 'CRM',
|
||||
'name': 'draft_sales_orders',
|
||||
'owner': 'Administrator',
|
||||
'page_len': 50,
|
||||
'parent': None,
|
||||
'parent_doc_type': None,
|
||||
'parentfield': None,
|
||||
'parenttype': None,
|
||||
'report_script': None,
|
||||
'server_script': None,
|
||||
'sort_by': '`tabSales Order`.`name`',
|
||||
'sort_order': 'DESC',
|
||||
'standard': 'Yes'
|
||||
}
|
||||
]
|
||||
1
selling/search_criteria/follow_up_report/__init__.py
Normal file
1
selling/search_criteria/follow_up_report/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
from __future__ import unicode_literals
|
||||
63
selling/search_criteria/follow_up_report/follow_up_report.js
Normal file
63
selling/search_criteria/follow_up_report/follow_up_report.js
Normal file
@@ -0,0 +1,63 @@
|
||||
// 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;
|
||||
}
|
||||
33
selling/search_criteria/follow_up_report/follow_up_report.py
Normal file
33
selling/search_criteria/follow_up_report/follow_up_report.py
Normal file
@@ -0,0 +1,33 @@
|
||||
# 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
|
||||
@@ -0,0 +1,34 @@
|
||||
# Search Criteria, follow-up_report
|
||||
[
|
||||
|
||||
# These values are common in all dictionaries
|
||||
{
|
||||
'creation': '2012-04-03 12:49:51',
|
||||
'docstatus': 0,
|
||||
'modified': '2012-04-03 12:49:51',
|
||||
'modified_by': u'Administrator',
|
||||
'owner': u'ashwini@webnotestech.com'
|
||||
},
|
||||
|
||||
# These values are common for all Search Criteria
|
||||
{
|
||||
'columns': u'Lead\x01ID,Communication Log\x01Date,Communication Log\x01Notes,Communication Log\x01Communication Log type',
|
||||
'criteria_name': u'Follow-up Report',
|
||||
'doc_type': u'Communication Log',
|
||||
'doctype': 'Search Criteria',
|
||||
'filters': u"{'Lead\x01Status':'','Lead\x01Source':'','Lead\x01Lead Type':'','Lead\x01Rating':'','Lead\x01Market Segment':'','Lead\x01Fiscal Year':''}",
|
||||
'module': u'Selling',
|
||||
'name': '__common__',
|
||||
'page_len': 50,
|
||||
'parent_doc_type': u'Lead',
|
||||
'sort_by': u'`tabLead`.`name`',
|
||||
'sort_order': u'DESC',
|
||||
'standard': u'Yes'
|
||||
},
|
||||
|
||||
# Search Criteria, follow-up_report
|
||||
{
|
||||
'doctype': 'Search Criteria',
|
||||
'name': u'follow-up_report'
|
||||
}
|
||||
]
|
||||
1
selling/search_criteria/gross_profit/__init__.py
Normal file
1
selling/search_criteria/gross_profit/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
from __future__ import unicode_literals
|
||||
32
selling/search_criteria/gross_profit/gross_profit.js
Normal file
32
selling/search_criteria/gross_profit/gross_profit.js
Normal file
@@ -0,0 +1,32 @@
|
||||
// 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.tabs['More Filters'].hide();
|
||||
this.hide_all_filters();
|
||||
this.filter_fields_dict['Delivery Note'+FILTER_SEP +'ID'].df.filter_hide = 0;
|
||||
this.filter_fields_dict['Delivery Note'+FILTER_SEP +'From Posting Date'].df.filter_hide = 0;
|
||||
this.filter_fields_dict['Delivery Note'+FILTER_SEP +'To Posting Date'].df.filter_hide = 0;
|
||||
this.filter_fields_dict['Delivery Note Item'+FILTER_SEP +'Item Code'].df.filter_hide = 0;
|
||||
this.filter_fields_dict['Delivery Note'+FILTER_SEP +'Project Name'].df.filter_hide = 0;
|
||||
|
||||
this.filter_fields_dict['Delivery Note'+FILTER_SEP +'ID'].df.in_first_page = 1;
|
||||
this.filter_fields_dict['Delivery Note'+FILTER_SEP +'From Posting Date'].df.in_first_page = 1;
|
||||
this.filter_fields_dict['Delivery Note'+FILTER_SEP +'To Posting Date'].df.in_first_page = 1;
|
||||
this.filter_fields_dict['Delivery Note Item'+FILTER_SEP +'Item Code'].df.in_first_page = 1;
|
||||
this.filter_fields_dict['Delivery Note'+FILTER_SEP +'Project Name'].df.in_first_page = 1;
|
||||
}
|
||||
78
selling/search_criteria/gross_profit/gross_profit.py
Normal file
78
selling/search_criteria/gross_profit/gross_profit.py
Normal file
@@ -0,0 +1,78 @@
|
||||
# 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
|
||||
colnames[colnames.index('Rate*')] = 'Rate'
|
||||
col_idx['Rate'] = col_idx['Rate*']
|
||||
col_idx.pop('Rate*')
|
||||
colnames[colnames.index('Amount*')] = 'Amount'
|
||||
col_idx['Amount'] = col_idx['Amount*']
|
||||
col_idx.pop('Amount*')
|
||||
|
||||
columns = [['Valuation Rate','Currency','150px',''],
|
||||
['Valuation Amount','Currency','150px',''],
|
||||
['Gross Profit (%)','Currrency','150px',''],
|
||||
['Gross Profit','Currency','150px','']]
|
||||
|
||||
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, tot_amount, tot_val_amount, tot_gross_profit = [], 0, 0, 0
|
||||
|
||||
for r in res:
|
||||
tot_val_rate = 0
|
||||
packing_list_items = sql("select item_code, warehouse, qty from `tabDelivery Note Packing Item` where parent = %s and parent_item = %s", (r[col_idx['ID']], r[col_idx['Item Code']]))
|
||||
for d in packing_list_items:
|
||||
if d[1]:
|
||||
val_rate = sql("select valuation_rate from `tabStock Ledger Entry` where item_code = %s and warehouse = %s and voucher_type = 'Delivery Note' and voucher_no = %s and is_cancelled = 'No'", (d[0], d[1], r[col_idx['ID']]))
|
||||
val_rate = val_rate and val_rate[0][0] or 0
|
||||
if r[col_idx['Quantity']]: tot_val_rate += (flt(val_rate) * flt(d[2]) / flt(r[col_idx['Quantity']]))
|
||||
else: tot_val_rate = 0
|
||||
|
||||
r.append(fmt_money(tot_val_rate))
|
||||
|
||||
val_amount = flt(tot_val_rate) * flt(r[col_idx['Quantity']])
|
||||
r.append(fmt_money(val_amount))
|
||||
|
||||
gp = flt(r[col_idx['Amount']]) - flt(val_amount)
|
||||
|
||||
if val_amount: gp_percent = gp * 100 / val_amount
|
||||
else: gp_percent = gp
|
||||
|
||||
r.append(fmt_money(gp_percent))
|
||||
r.append(fmt_money(gp))
|
||||
out.append(r)
|
||||
|
||||
tot_gross_profit += flt(gp)
|
||||
tot_amount += flt(r[col_idx['Amount']])
|
||||
tot_val_amount += flt(val_amount)
|
||||
|
||||
# Add Total Row
|
||||
# --------------
|
||||
l_row = ['' for i in range(len(colnames))]
|
||||
l_row[col_idx['Quantity']] = '<b>TOTALS</b>'
|
||||
l_row[col_idx['Amount']] = fmt_money(tot_amount)
|
||||
l_row[col_idx['Valuation Amount']] = fmt_money(tot_val_amount)
|
||||
if tot_val_amount: l_row[col_idx['Gross Profit (%)']] = fmt_money((tot_amount - tot_val_amount) * 100 / tot_val_amount)
|
||||
else: l_row[col_idx['Gross Profit (%)']] = fmt_money(tot_amount)
|
||||
l_row[col_idx['Gross Profit']] = fmt_money(tot_gross_profit)
|
||||
out.append(l_row)
|
||||
35
selling/search_criteria/gross_profit/gross_profit.txt
Normal file
35
selling/search_criteria/gross_profit/gross_profit.txt
Normal file
@@ -0,0 +1,35 @@
|
||||
# Search Criteria, gross_profit
|
||||
[
|
||||
|
||||
# These values are common in all dictionaries
|
||||
{
|
||||
'creation': '2012-04-03 12:49:51',
|
||||
'docstatus': 0,
|
||||
'modified': '2012-04-03 12:49:51',
|
||||
'modified_by': u'Administrator',
|
||||
'owner': u'Administrator'
|
||||
},
|
||||
|
||||
# These values are common for all Search Criteria
|
||||
{
|
||||
'columns': u'Delivery Note\x01ID,Delivery Note\x01Posting Date,Delivery Note\x01Posting Time,Delivery Note Item\x01Item Code,Delivery Note Item\x01Item Name,Delivery Note Item\x01Description,Delivery Note\x01Project Name,Delivery Note Item\x01Quantity,Delivery Note Item\x01Rate*,Delivery Note Item\x01Amount*',
|
||||
'criteria_name': u'Gross Profit',
|
||||
'description': u'Invoice wise',
|
||||
'doc_type': u'Delivery Note Item',
|
||||
'doctype': 'Search Criteria',
|
||||
'filters': u"{'Delivery Note\x01Submitted':1,'Delivery Note\x01Status':'','Delivery Note\x01Fiscal Year':''}",
|
||||
'module': u'Selling',
|
||||
'name': '__common__',
|
||||
'page_len': 50,
|
||||
'parent_doc_type': u'Delivery Note',
|
||||
'sort_by': u'`tabDelivery Note`.`name`',
|
||||
'sort_order': u'DESC',
|
||||
'standard': u'Yes'
|
||||
},
|
||||
|
||||
# Search Criteria, gross_profit
|
||||
{
|
||||
'doctype': 'Search Criteria',
|
||||
'name': u'gross_profit'
|
||||
}
|
||||
]
|
||||
@@ -0,0 +1 @@
|
||||
from __future__ import unicode_literals
|
||||
@@ -0,0 +1,21 @@
|
||||
// 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());
|
||||
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
# 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)
|
||||
@@ -0,0 +1,34 @@
|
||||
# Search Criteria, itemwise_delivery_details
|
||||
[
|
||||
|
||||
# These values are common in all dictionaries
|
||||
{
|
||||
'creation': '2012-04-23 12:46:00',
|
||||
'docstatus': 0,
|
||||
'modified': '2012-05-03 18:13:49',
|
||||
'modified_by': u'Administrator',
|
||||
'owner': u'Administrator'
|
||||
},
|
||||
|
||||
# These values are common for all Search Criteria
|
||||
{
|
||||
'columns': u'Delivery Note\x01ID,Delivery Note Item\x01Item Code,Delivery Note Item\x01Item Name,Delivery Note Item\x01Quantity,Delivery Note Item\x01Rate*,Delivery Note Item\x01Amount*,Delivery Note Item\x01Billed Amt',
|
||||
'criteria_name': u'Itemwise Delivery Details',
|
||||
'doc_type': u'Delivery Note Item',
|
||||
'doctype': 'Search Criteria',
|
||||
'filters': u'{"Delivery Note\\u0001Submitted":1,"Delivery Note\\u0001Status":[""],"Delivery Note\\u0001Fiscal Year":[""]}',
|
||||
'module': u'Selling',
|
||||
'name': '__common__',
|
||||
'page_len': 50,
|
||||
'parent_doc_type': u'Delivery Note',
|
||||
'sort_by': u'`tabDelivery Note`.`name`',
|
||||
'sort_order': u'DESC',
|
||||
'standard': u'Yes'
|
||||
},
|
||||
|
||||
# Search Criteria, itemwise_delivery_details
|
||||
{
|
||||
'doctype': 'Search Criteria',
|
||||
'name': u'itemwise_delivery_details'
|
||||
}
|
||||
]
|
||||
@@ -0,0 +1 @@
|
||||
from __future__ import unicode_literals
|
||||
@@ -0,0 +1,27 @@
|
||||
// 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();
|
||||
@@ -0,0 +1,36 @@
|
||||
# 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)
|
||||
@@ -0,0 +1,34 @@
|
||||
# Search Criteria, itemwise_sales_details
|
||||
[
|
||||
|
||||
# These values are common in all dictionaries
|
||||
{
|
||||
'creation': '2012-04-23 12:46:00',
|
||||
'docstatus': 0,
|
||||
'modified': '2012-05-03 18:18:31',
|
||||
'modified_by': u'Administrator',
|
||||
'owner': u'Administrator'
|
||||
},
|
||||
|
||||
# These values are common for all Search Criteria
|
||||
{
|
||||
'columns': u'Sales Order\x01ID,Sales Order\x01Customer,Sales Order Item\x01Item Code,Sales Order Item\x01Item Name,Sales Order Item\x01Quantity,Sales Order Item\x01Basic Rate*,Sales Order Item\x01Amount*,Sales Order Item\x01Delivered Qty,Sales Order Item\x01Billed Amt',
|
||||
'criteria_name': u'Itemwise Sales Details',
|
||||
'doc_type': u'Sales Order Item',
|
||||
'doctype': 'Search Criteria',
|
||||
'filters': u'{"Sales Order\\u0001Submitted":1,"Sales Order\\u0001Fiscal Year":[""],"Sales Order\\u0001Status":[""]}',
|
||||
'module': u'Selling',
|
||||
'name': '__common__',
|
||||
'page_len': 50,
|
||||
'parent_doc_type': u'Sales Order',
|
||||
'sort_by': u'`tabSales Order`.`name`',
|
||||
'sort_order': u'DESC',
|
||||
'standard': u'Yes'
|
||||
},
|
||||
|
||||
# Search Criteria, itemwise_sales_details
|
||||
{
|
||||
'doctype': 'Search Criteria',
|
||||
'name': u'itemwise_sales_details'
|
||||
}
|
||||
]
|
||||
1
selling/search_criteria/lead_to_follow_up/__init__.py
Normal file
1
selling/search_criteria/lead_to_follow_up/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
from __future__ import unicode_literals
|
||||
@@ -0,0 +1,21 @@
|
||||
// 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;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
# Search Criteria, lead-to_follow_up
|
||||
[
|
||||
|
||||
# These values are common in all dictionaries
|
||||
{
|
||||
'creation': '2012-04-03 12:49:51',
|
||||
'docstatus': 0,
|
||||
'modified': '2012-04-03 12:49:51',
|
||||
'modified_by': u'Administrator',
|
||||
'owner': u'Administrator'
|
||||
},
|
||||
|
||||
# These values are common for all Search Criteria
|
||||
{
|
||||
'add_cond': u"`tabLead`.status!='Converted' \n`tabLead`.status!='Lead Lost' \n`tabLead`.status!='Not Interested'",
|
||||
'columns': u'Lead\x01ID,Lead\x01Status,Lead\x01Lead Name,Lead\x01Lead Date,Lead\x01Lead Owner,Lead\x01Next Contact Date',
|
||||
'criteria_name': u'Lead-To follow up',
|
||||
'doc_type': u'Lead',
|
||||
'doctype': 'Search Criteria',
|
||||
'filters': u"{'Lead\x01Status':'','Lead\x01Source':'','Lead\x01Expected Month':'','Lead\x01Industry':'','Lead\x01Market Segment':'','Lead\x01Rating':''}",
|
||||
'module': u'Selling',
|
||||
'name': '__common__',
|
||||
'page_len': 50,
|
||||
'sort_by': u'`tabLead`.`name`',
|
||||
'sort_order': u'DESC',
|
||||
'standard': u'Yes'
|
||||
},
|
||||
|
||||
# Search Criteria, lead-to_follow_up
|
||||
{
|
||||
'doctype': 'Search Criteria',
|
||||
'name': u'lead-to_follow_up'
|
||||
}
|
||||
]
|
||||
@@ -0,0 +1,27 @@
|
||||
// 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;
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
from __future__ import unicode_literals
|
||||
@@ -0,0 +1,34 @@
|
||||
# Search Criteria, opportunity-to_follow_up
|
||||
[
|
||||
|
||||
# These values are common in all dictionaries
|
||||
{
|
||||
'creation': '2012-03-30 14:50:44',
|
||||
'docstatus': 0,
|
||||
'modified': '2012-03-30 14:50:44',
|
||||
'modified_by': u'Administrator',
|
||||
'owner': u'Administrator'
|
||||
},
|
||||
|
||||
# These values are common for all Search Criteria
|
||||
{
|
||||
'add_cond': u"`tabOpportunity`.name=`tabQuotation`.enq_no\n`tabOpportunity`.docstatus=1\n`tabQuotation`.status='Submitted'",
|
||||
'columns': u'Opportunity\x01ID,Opportunity\x01Owner,Opportunity\x01Company,Opportunity\x01Fiscal Year',
|
||||
'criteria_name': u'Opportunity-To follow up',
|
||||
'doc_type': u'Opportunity',
|
||||
'doctype': 'Search Criteria',
|
||||
'filters': u"{'Opportunity\x01Fiscal Year':''}",
|
||||
'module': u'Selling',
|
||||
'name': '__common__',
|
||||
'page_len': 50,
|
||||
'sort_by': u'`tabOpportunity`.`name`',
|
||||
'sort_order': u'DESC',
|
||||
'standard': u'Yes'
|
||||
},
|
||||
|
||||
# Search Criteria, opportunity-to_follow_up
|
||||
{
|
||||
'doctype': 'Search Criteria',
|
||||
'name': u'opportunity-to_follow_up'
|
||||
}
|
||||
]
|
||||
@@ -0,0 +1 @@
|
||||
from __future__ import unicode_literals
|
||||
@@ -0,0 +1,20 @@
|
||||
// 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;
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
# Search Criteria, sales_order_pending_items
|
||||
[
|
||||
|
||||
# These values are common in all dictionaries
|
||||
{
|
||||
'creation': '2012-05-14 14:54:44',
|
||||
'docstatus': 0,
|
||||
'modified': '2012-05-18 11:15:00',
|
||||
'modified_by': u'Administrator',
|
||||
'owner': u'Administrator'
|
||||
},
|
||||
|
||||
# These values are common for all Search Criteria
|
||||
{
|
||||
'add_col': u'(`tabSales Order Item`.qty - ifnull(`tabSales Order Item`.delivered_qty, 0)) AS "Qty To Deliver"\n(`tabSales Order Item`.qty - ifnull(`tabSales Order Item`.delivered_qty, 0))*`tabSales Order Item`.basic_rate AS "Amount To Deliver"\n(`tabSales Order Item`.qty - ifnull(`tabSales Order Item`.billed_qty, 0))*`tabSales Order Item`.basic_rate AS "Amount To Bill"',
|
||||
'add_cond': u'(`tabSales Order Item`.qty - ifnull(`tabSales Order Item`.delivered_qty, 0) > 0 or `tabSales Order Item`.qty - ifnull(`tabSales Order Item`.billed_qty, 0) > 0)\n`tabSales Order`.status != "Stopped"',
|
||||
'columns': u'Sales Order\x01ID,Sales Order\x01Sales Order Date,Sales Order\x01Customer,Sales Order Item\x01Item Code,Sales Order Item\x01Item Name,Sales Order Item\x01Description,Sales Order Item\x01Quantity,Sales Order Item\x01Delivered Qty',
|
||||
'criteria_name': u'Sales Order Pending Items',
|
||||
'description': u'Sales Order Pending Items',
|
||||
'doc_type': u'Sales Order Item',
|
||||
'doctype': 'Search Criteria',
|
||||
'filters': u'{"Sales Order\\u0001Submitted":1,"Sales Order\\u0001Fiscal Year":[],"Sales Order\\u0001Status":[]}',
|
||||
'module': u'Selling',
|
||||
'name': '__common__',
|
||||
'page_len': 50,
|
||||
'parent_doc_type': u'Sales Order',
|
||||
'sort_by': u'`tabSales Order`.`name`',
|
||||
'sort_order': u'DESC',
|
||||
'standard': u'Yes'
|
||||
},
|
||||
|
||||
# Search Criteria, sales_order_pending_items
|
||||
{
|
||||
'doctype': 'Search Criteria',
|
||||
'name': u'sales_order_pending_items'
|
||||
}
|
||||
]
|
||||
@@ -0,0 +1 @@
|
||||
from __future__ import unicode_literals
|
||||
@@ -0,0 +1,37 @@
|
||||
# Search Criteria, sales_orderwise_booking_&_delivery_summary
|
||||
[
|
||||
|
||||
# These values are common in all dictionaries
|
||||
{
|
||||
'creation': '2012-04-03 12:49:52',
|
||||
'docstatus': 0,
|
||||
'modified': '2012-04-03 12:49:52',
|
||||
'modified_by': u'Administrator',
|
||||
'owner': u'Administrator'
|
||||
},
|
||||
|
||||
# These values are common for all Search Criteria
|
||||
{
|
||||
'add_col': u"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'",
|
||||
'columns': u'Sales Order\x01ID,Sales Order\x01Status,Sales Order\x01% Billed,Sales Order\x01Sales Order Date,Sales Order\x01Customer,Sales Order\x01Customer Name,Sales Order\x01Territory',
|
||||
'criteria_name': u'Sales Orderwise Booking & Delivery Summary',
|
||||
'description': u'Sales Orderwise Booking & Delivery Summary',
|
||||
'doc_type': u'Sales Order Item',
|
||||
'doctype': 'Search Criteria',
|
||||
'filters': u"{'Sales Order\x01Submitted':1,'Sales Order\x01Status':'','Sales Order\x01Fiscal Year':''}",
|
||||
'group_by': u'`tabSales Order`.`name`',
|
||||
'module': u'Selling',
|
||||
'name': '__common__',
|
||||
'page_len': 50,
|
||||
'parent_doc_type': u'Sales Order',
|
||||
'sort_by': u'`tabSales Order`.`name`',
|
||||
'sort_order': u'DESC',
|
||||
'standard': u'Yes'
|
||||
},
|
||||
|
||||
# Search Criteria, sales_orderwise_booking_&_delivery_summary
|
||||
{
|
||||
'doctype': 'Search Criteria',
|
||||
'name': u'sales_orderwise_booking_&_delivery_summary'
|
||||
}
|
||||
]
|
||||
@@ -0,0 +1 @@
|
||||
from __future__ import unicode_literals
|
||||
@@ -0,0 +1,20 @@
|
||||
// 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;
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
# Search Criteria, sales_orderwise_pending_amount_to_bill
|
||||
[
|
||||
|
||||
# These values are common in all dictionaries
|
||||
{
|
||||
'creation': '2012-04-03 12:49:52',
|
||||
'docstatus': 0,
|
||||
'modified': '2012-04-03 12:49:52',
|
||||
'modified_by': u'Administrator',
|
||||
'owner': u'dhanalekshmi@webnotestech.com'
|
||||
},
|
||||
|
||||
# These values are common for all Search Criteria
|
||||
{
|
||||
'add_col': u'SUM((`tabSales Order Item`.`qty` - ifnull(`tabSales Order Item`.`billed_qty`, 0)) * `tabSales Order Item`.`basic_rate`) AS "Pending Amount"',
|
||||
'add_cond': u'`tabSales Order`.status != "Stopped"\n`tabSales Order`.order_type!="Maintenance"',
|
||||
'columns': u'Sales Order\x01ID,Sales Order\x01Customer,Sales Order\x01Customer Address,Sales Order\x01Status,Sales Order\x01% Delivered,Sales Order\x01% Billed,Sales Order\x01Company Name,Sales Order\x01Sales Order Date,Sales Order\x01Net Total,Sales Order\x01Zone,Sales Order\x01Territory,Sales Order\x01Email Id',
|
||||
'criteria_name': u'Sales Orderwise Pending Amount To Bill',
|
||||
'description': u'Sales Orderwise Pending Amount To Bill',
|
||||
'doc_type': u'Sales Order Item',
|
||||
'doctype': 'Search Criteria',
|
||||
'filters': u"{'Sales Order\x01Saved':1,'Sales Order\x01Submitted':1,'Sales Order\x01Company Name':'','Sales Order\x01Fiscal Year':''}",
|
||||
'group_by': u'`tabSales Order`.`name`',
|
||||
'module': u'Selling',
|
||||
'name': '__common__',
|
||||
'page_len': 50,
|
||||
'parent_doc_type': u'Sales Order',
|
||||
'sort_by': u'`tabSales Order`.`name`',
|
||||
'sort_order': u'DESC',
|
||||
'standard': u'Yes'
|
||||
},
|
||||
|
||||
# Search Criteria, sales_orderwise_pending_amount_to_bill
|
||||
{
|
||||
'doctype': 'Search Criteria',
|
||||
'name': u'sales_orderwise_pending_amount_to_bill'
|
||||
}
|
||||
]
|
||||
@@ -0,0 +1 @@
|
||||
from __future__ import unicode_literals
|
||||
@@ -0,0 +1,38 @@
|
||||
# Search Criteria, sales_orderwise_pending_qty_to_deliver
|
||||
[
|
||||
|
||||
# These values are common in all dictionaries
|
||||
{
|
||||
'creation': '2012-04-03 12:49:52',
|
||||
'docstatus': 0,
|
||||
'modified': '2012-04-03 12:49:52',
|
||||
'modified_by': u'Administrator',
|
||||
'owner': u'dhanalekshmi@webnotestech.com'
|
||||
},
|
||||
|
||||
# These values are common for all Search Criteria
|
||||
{
|
||||
'add_col': u'SUM(`tabSales Order Item`.`qty` - ifnull(`tabSales Order Item`.`delivered_qty`, 0)) AS "Pending Qty"',
|
||||
'add_cond': u'`tabSales Order`.status != "Stopped"\n`tabSales Order Item`.`qty` > ifnull(`tabSales Order Item`.`delivered_qty`, 0)',
|
||||
'columns': u'Sales Order\x01ID,Sales Order\x01Customer,Sales Order\x01Customer Name,Sales Order\x01Customer Address,Sales Order\x01Status,Sales Order\x01% Delivered,Sales Order\x01% Billed,Sales Order\x01Sales Order Date,Sales Order\x01Territory,Sales Order\x01Email Id',
|
||||
'criteria_name': u'Sales Orderwise Pending Qty To Deliver',
|
||||
'description': u'Sales Orderwise Pending Qty To Deliver',
|
||||
'doc_type': u'Sales Order Item',
|
||||
'doctype': 'Search Criteria',
|
||||
'filters': u"{'Sales Order\x01Saved':1,'Sales Order\x01Submitted':1,'Sales Order\x01Status':'','Sales Order\x01Fiscal Year':''}",
|
||||
'group_by': u'`tabSales Order`.`name`',
|
||||
'module': u'Selling',
|
||||
'name': '__common__',
|
||||
'page_len': 50,
|
||||
'parent_doc_type': u'Sales Order',
|
||||
'sort_by': u'`tabSales Order`.`name`',
|
||||
'sort_order': u'DESC',
|
||||
'standard': u'Yes'
|
||||
},
|
||||
|
||||
# Search Criteria, sales_orderwise_pending_qty_to_deliver
|
||||
{
|
||||
'doctype': 'Search Criteria',
|
||||
'name': u'sales_orderwise_pending_qty_to_deliver'
|
||||
}
|
||||
]
|
||||
@@ -0,0 +1 @@
|
||||
from __future__ import unicode_literals
|
||||
@@ -0,0 +1,57 @@
|
||||
// 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;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,145 @@
|
||||
# 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 = 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
|
||||
@@ -0,0 +1,33 @@
|
||||
# Search Criteria, sales_persons_target_variance_item_group_wise
|
||||
[
|
||||
|
||||
# These values are common in all dictionaries
|
||||
{
|
||||
'creation': '2012-04-03 12:49:52',
|
||||
'docstatus': 0,
|
||||
'modified': '2012-04-03 12:49:52',
|
||||
'modified_by': u'Administrator',
|
||||
'owner': u'Administrator'
|
||||
},
|
||||
|
||||
# These values are common for all Search Criteria
|
||||
{
|
||||
'criteria_name': u'Sales Persons Target Variance (Item Group wise)',
|
||||
'doc_type': u'Target Detail',
|
||||
'doctype': 'Search Criteria',
|
||||
'filters': u"{'Sales Person\x01Country':'','Sales Person\x01State':'','Target Detail\x01Fiscal Year':''}",
|
||||
'module': u'Selling',
|
||||
'name': '__common__',
|
||||
'page_len': 50,
|
||||
'parent_doc_type': u'Sales Person',
|
||||
'sort_by': u'`tabTarget Detail`.`target_amount`',
|
||||
'sort_order': u'DESC',
|
||||
'standard': u'Yes'
|
||||
},
|
||||
|
||||
# Search Criteria, sales_persons_target_variance_item_group_wise
|
||||
{
|
||||
'doctype': 'Search Criteria',
|
||||
'name': u'sales_persons_target_variance_item_group_wise'
|
||||
}
|
||||
]
|
||||
1
selling/search_criteria/sales_personwise_transaction_summary/__init__.py
Executable file
1
selling/search_criteria/sales_personwise_transaction_summary/__init__.py
Executable file
@@ -0,0 +1 @@
|
||||
from __future__ import unicode_literals
|
||||
@@ -0,0 +1,56 @@
|
||||
// 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 = 'Sales Invoice';
|
||||
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';
|
||||
}
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
# 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
|
||||
@@ -0,0 +1,33 @@
|
||||
# Search Criteria, sales_personwise_transaction_summary
|
||||
[
|
||||
|
||||
# These values are common in all dictionaries
|
||||
{
|
||||
'creation': '2012-04-03 12:49:52',
|
||||
'docstatus': 0,
|
||||
'modified': '2012-04-03 12:49:52',
|
||||
'modified_by': u'Administrator',
|
||||
'owner': u'Administrator'
|
||||
},
|
||||
|
||||
# These values are common for all Search Criteria
|
||||
{
|
||||
'columns': u'Sales Person\x01ID',
|
||||
'criteria_name': u'Sales Personwise Transaction Summary',
|
||||
'doc_type': u'Sales Person',
|
||||
'doctype': 'Search Criteria',
|
||||
'filters': u"{'Sales Person\x01Saved':1,'Sales Person\x01Submitted':1,'Sales Person\x01Country':'','Sales Person\x01State':''}",
|
||||
'module': u'Selling',
|
||||
'name': '__common__',
|
||||
'page_len': 50,
|
||||
'sort_by': u'`tabSales Person`.`name`',
|
||||
'sort_order': u'DESC',
|
||||
'standard': u'Yes'
|
||||
},
|
||||
|
||||
# Search Criteria, sales_personwise_transaction_summary
|
||||
{
|
||||
'doctype': 'Search Criteria',
|
||||
'name': u'sales_personwise_transaction_summary'
|
||||
}
|
||||
]
|
||||
@@ -0,0 +1 @@
|
||||
from __future__ import unicode_literals
|
||||
@@ -0,0 +1,34 @@
|
||||
# Search Criteria, serial_no-amc_expiring_this_month
|
||||
[
|
||||
|
||||
# These values are common in all dictionaries
|
||||
{
|
||||
'creation': '2012-04-03 12:49:52',
|
||||
'docstatus': 0,
|
||||
'modified': '2012-04-03 12:49:52',
|
||||
'modified_by': u'Administrator',
|
||||
'owner': u'Administrator'
|
||||
},
|
||||
|
||||
# These values are common for all Search Criteria
|
||||
{
|
||||
'add_cond': u'`tab Serial No`.month(amc_expiry_date)=month(now()) \n`tab Serial No`.year(amc_expiry_date)=year(now())',
|
||||
'columns': u'Serial No\x01ID,Serial No\x01Status,Serial No\x01AMC Expiry Date,Serial No\x01Customer Name',
|
||||
'criteria_name': u'Serial No-AMC expiring this month',
|
||||
'doc_type': u'Serial No',
|
||||
'doctype': 'Search Criteria',
|
||||
'filters': u"{'Serial No\x01Saved':1,'Serial No\x01Submitted':1,'Serial No\x01Status':'','Serial No\x01Warranty Status':''}",
|
||||
'module': u'Selling',
|
||||
'name': '__common__',
|
||||
'page_len': 50,
|
||||
'sort_by': u'`tabSerial No`.`name`',
|
||||
'sort_order': u'DESC',
|
||||
'standard': u'Yes'
|
||||
},
|
||||
|
||||
# Search Criteria, serial_no-amc_expiring_this_month
|
||||
{
|
||||
'doctype': 'Search Criteria',
|
||||
'name': u'serial_no-amc_expiring_this_month'
|
||||
}
|
||||
]
|
||||
@@ -0,0 +1 @@
|
||||
from __future__ import unicode_literals
|
||||
@@ -0,0 +1,34 @@
|
||||
# Search Criteria, serial_no-warranty_expiring_this_month
|
||||
[
|
||||
|
||||
# These values are common in all dictionaries
|
||||
{
|
||||
'creation': '2012-04-03 12:49:52',
|
||||
'docstatus': 0,
|
||||
'modified': '2012-04-03 12:49:52',
|
||||
'modified_by': u'Administrator',
|
||||
'owner': u'Administrator'
|
||||
},
|
||||
|
||||
# These values are common for all Search Criteria
|
||||
{
|
||||
'add_cond': u"`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())",
|
||||
'columns': u'Serial No\x01ID,Serial No\x01Status,Serial No\x01Warranty Expiry Date,Serial No\x01Customer Name',
|
||||
'criteria_name': u'Serial No-Warranty expiring this month',
|
||||
'doc_type': u'Serial No',
|
||||
'doctype': 'Search Criteria',
|
||||
'filters': u"{'Serial No\x01Saved':1,'Serial No\x01Submitted':1,'Serial No\x01Status':'Issued','Serial No\x01Maintenance Status':''}",
|
||||
'module': u'Selling',
|
||||
'name': '__common__',
|
||||
'page_len': 50,
|
||||
'sort_by': u'`tabSerial No`.`name`',
|
||||
'sort_order': u'DESC',
|
||||
'standard': u'Yes'
|
||||
},
|
||||
|
||||
# Search Criteria, serial_no-warranty_expiring_this_month
|
||||
{
|
||||
'doctype': 'Search Criteria',
|
||||
'name': u'serial_no-warranty_expiring_this_month'
|
||||
}
|
||||
]
|
||||
@@ -0,0 +1 @@
|
||||
from __future__ import unicode_literals
|
||||
@@ -0,0 +1,43 @@
|
||||
// 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();
|
||||
@@ -0,0 +1,127 @@
|
||||
# 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 = 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
|
||||
@@ -0,0 +1,34 @@
|
||||
# Search Criteria, target_variance_report
|
||||
[
|
||||
|
||||
# These values are common in all dictionaries
|
||||
{
|
||||
'creation': '2012-04-03 12:49:53',
|
||||
'docstatus': 0,
|
||||
'modified': '2012-04-03 12:49:53',
|
||||
'modified_by': u'Administrator',
|
||||
'owner': u'harshada@webnotestech.com'
|
||||
},
|
||||
|
||||
# These values are common for all Search Criteria
|
||||
{
|
||||
'columns': u'Sales Person\x01ID,Sales Person\x01Owner,Sales Person\x01Sales Person,Sales Person\x01Country,Sales Person\x01State,Target Detail\x01Item Group,Target Detail\x01Fiscal Year,Target Detail\x01Target Amount',
|
||||
'criteria_name': u'Target Variance Report',
|
||||
'disabled': 0,
|
||||
'doc_type': u'Target Detail',
|
||||
'doctype': 'Search Criteria',
|
||||
'filters': u"{'Sales Person\x01Saved':1,'Sales Person\x01Submitted':1,'Sales Person\x01Country':'','Sales Person\x01State':'','Target Detail\x01Fiscal Year':''}",
|
||||
'module': u'Selling',
|
||||
'name': '__common__',
|
||||
'page_len': 50,
|
||||
'parent_doc_type': u'Sales Person',
|
||||
'sort_order': u'DESC',
|
||||
'standard': u'Yes'
|
||||
},
|
||||
|
||||
# Search Criteria, target_variance_report
|
||||
{
|
||||
'doctype': 'Search Criteria',
|
||||
'name': u'target_variance_report'
|
||||
}
|
||||
]
|
||||
@@ -0,0 +1 @@
|
||||
from __future__ import unicode_literals
|
||||
@@ -0,0 +1,61 @@
|
||||
// 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;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,144 @@
|
||||
# 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 = 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
|
||||
@@ -0,0 +1,33 @@
|
||||
# Search Criteria, territories_target_variance_item_group_wise
|
||||
[
|
||||
|
||||
# These values are common in all dictionaries
|
||||
{
|
||||
'creation': '2012-04-03 12:49:53',
|
||||
'docstatus': 0,
|
||||
'modified': '2012-04-03 12:49:53',
|
||||
'modified_by': u'Administrator',
|
||||
'owner': u'Administrator'
|
||||
},
|
||||
|
||||
# These values are common for all Search Criteria
|
||||
{
|
||||
'criteria_name': u'Territories Target Variance (Item Group wise)',
|
||||
'doc_type': u'Target Detail',
|
||||
'doctype': 'Search Criteria',
|
||||
'filters': u"{'Sales Person\x01Country':'','Sales Person\x01State':'','Target Detail\x01Fiscal Year':''}",
|
||||
'module': u'Selling',
|
||||
'name': '__common__',
|
||||
'page_len': 50,
|
||||
'parent_doc_type': u'Sales Person',
|
||||
'sort_by': u'`tabTarget Detail`.`target_amount`',
|
||||
'sort_order': u'DESC',
|
||||
'standard': u'Yes'
|
||||
},
|
||||
|
||||
# Search Criteria, territories_target_variance_item_group_wise
|
||||
{
|
||||
'doctype': 'Search Criteria',
|
||||
'name': u'territories_target_variance_item_group_wise'
|
||||
}
|
||||
]
|
||||
@@ -0,0 +1 @@
|
||||
from __future__ import unicode_literals
|
||||
@@ -0,0 +1,22 @@
|
||||
// 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'});
|
||||
}
|
||||
@@ -0,0 +1,205 @@
|
||||
# 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
|
||||
@@ -0,0 +1,33 @@
|
||||
# Search Criteria, territory_sales_-_variance_report
|
||||
[
|
||||
|
||||
# These values are common in all dictionaries
|
||||
{
|
||||
'creation': '2012-04-03 12:49:53',
|
||||
'docstatus': 0,
|
||||
'modified': '2012-04-03 12:49:53',
|
||||
'modified_by': u'Administrator',
|
||||
'owner': u'Administrator'
|
||||
},
|
||||
|
||||
# These values are common for all Search Criteria
|
||||
{
|
||||
'columns': u'Territory\x01ID',
|
||||
'criteria_name': u'Territory Sales - Variance Report',
|
||||
'doc_type': u'Territory',
|
||||
'doctype': 'Search Criteria',
|
||||
'filters': u"{'Territory\x01State':'','Territory\x01Based On':'Sales Order','Territory\x01Fiscal Year':'2009-2010','Territory\x01Company':'Alpha Company','Territory\x01Period':'Quarterly'}",
|
||||
'module': u'Selling',
|
||||
'name': '__common__',
|
||||
'page_len': 50,
|
||||
'sort_by': u'ID',
|
||||
'sort_order': u'DESC',
|
||||
'standard': u'Yes'
|
||||
},
|
||||
|
||||
# Search Criteria, territory_sales_-_variance_report
|
||||
{
|
||||
'doctype': 'Search Criteria',
|
||||
'name': u'territory_sales_-_variance_report'
|
||||
}
|
||||
]
|
||||
@@ -0,0 +1 @@
|
||||
from __future__ import unicode_literals
|
||||
@@ -0,0 +1,28 @@
|
||||
// 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();
|
||||
@@ -0,0 +1,223 @@
|
||||
# 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 = 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
|
||||
@@ -0,0 +1 @@
|
||||
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
|
||||
@@ -0,0 +1,34 @@
|
||||
# Search Criteria, total_target_variance_report
|
||||
[
|
||||
|
||||
# These values are common in all dictionaries
|
||||
{
|
||||
'creation': '2012-04-03 12:49:53',
|
||||
'docstatus': 0,
|
||||
'modified': '2012-04-03 12:49:53',
|
||||
'modified_by': u'Administrator',
|
||||
'owner': u'Administrator'
|
||||
},
|
||||
|
||||
# These values are common for all Search Criteria
|
||||
{
|
||||
'columns': u'Sales Person\x01ID,Sales Person\x01Owner,Sales Person\x01Sales Person,Sales Person\x01Country,Sales Person\x01State,Sales Person\x01lft,Sales Person\x01rgt,Target Detail\x01Item Group,Target Detail\x01Fiscal Year,Target Detail\x01Target Amount',
|
||||
'criteria_name': u'Total Target Variance Report',
|
||||
'doc_type': u'Target Detail',
|
||||
'doctype': 'Search Criteria',
|
||||
'filters': u"{'Sales Person\x01Saved':1,'Sales Person\x01Submitted':1,'Sales Person\x01Country':'','Sales Person\x01State':'','Target Detail\x01Fiscal Year':''}",
|
||||
'module': u'Selling',
|
||||
'name': '__common__',
|
||||
'page_len': 50,
|
||||
'parent_doc_type': u'Sales Person',
|
||||
'sort_by': u'`tabSales Person`.`name`',
|
||||
'sort_order': u'DESC',
|
||||
'standard': u'Yes'
|
||||
},
|
||||
|
||||
# Search Criteria, total_target_variance_report
|
||||
{
|
||||
'doctype': 'Search Criteria',
|
||||
'name': u'total_target_variance_report'
|
||||
}
|
||||
]
|
||||
1
selling/search_criteria/variance_report/__init__.py
Normal file
1
selling/search_criteria/variance_report/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
from __future__ import unicode_literals
|
||||
28
selling/search_criteria/variance_report/variance_report.js
Normal file
28
selling/search_criteria/variance_report/variance_report.js
Normal file
@@ -0,0 +1,28 @@
|
||||
// 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()
|
||||
520
selling/search_criteria/variance_report/variance_report.py
Normal file
520
selling/search_criteria/variance_report/variance_report.py
Normal file
@@ -0,0 +1,520 @@
|
||||
# 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)
|
||||
@@ -0,0 +1 @@
|
||||
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)
|
||||
33
selling/search_criteria/variance_report/variance_report.txt
Normal file
33
selling/search_criteria/variance_report/variance_report.txt
Normal file
@@ -0,0 +1,33 @@
|
||||
# Search Criteria, variance_report
|
||||
[
|
||||
|
||||
# These values are common in all dictionaries
|
||||
{
|
||||
'creation': '2012-04-03 12:49:53',
|
||||
'docstatus': 0,
|
||||
'modified': '2012-04-03 12:49:53',
|
||||
'modified_by': u'Administrator',
|
||||
'owner': u'Administrator'
|
||||
},
|
||||
|
||||
# These values are common for all Search Criteria
|
||||
{
|
||||
'criteria_name': u'Variance Report',
|
||||
'doc_type': u'Target Detail',
|
||||
'doctype': 'Search Criteria',
|
||||
'filters': u"{'Territory\x01State':'','Target Detail\x01Fiscal Year':'2009-2010','Target Detail\x01Based On':'Territory','Target Detail\x01Company':'Alpha Company','Target Detail\x01Period':'Quarterly','Target Detail\x01Under':'Sales Order'}",
|
||||
'module': u'Selling',
|
||||
'name': '__common__',
|
||||
'page_len': 50,
|
||||
'parent_doc_type': u'Territory',
|
||||
'sort_by': u'ID',
|
||||
'sort_order': u'DESC',
|
||||
'standard': u'Yes'
|
||||
},
|
||||
|
||||
# Search Criteria, variance_report
|
||||
{
|
||||
'doctype': 'Search Criteria',
|
||||
'name': u'variance_report'
|
||||
}
|
||||
]
|
||||
Reference in New Issue
Block a user