mirror of
https://github.com/frappe/erpnext.git
synced 2026-06-06 05:39:12 +00:00
restructured erpnext and deleted unwanted
This commit is contained in:
0
selling/search_criteria/__init__.py
Normal file
0
selling/search_criteria/__init__.py
Normal file
@@ -0,0 +1,4 @@
|
||||
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 @@
|
||||
[
|
||||
{
|
||||
'add_col': "(`tabDelivery Note Detail`.`qty`- ifnull(`tabDelivery Note Detail`.`installed_qty`, 0)) AS 'Pending to Install'",
|
||||
'add_cond': '`tabDelivery Note Detail`.`qty` > ifnull(`tabDelivery Note Detail`.`installed_qty`, 0)',
|
||||
'add_tab': None,
|
||||
'columns': 'Delivery Note\x01ID,Delivery Note\x01Status,Delivery Note\x01Customer,Delivery Note\x01Customer Name,Delivery Note\x01Contact Person,Delivery Note\x01Voucher Date,Delivery Note Detail\x01Item Code,Delivery Note Detail\x01Item Name,Delivery Note Detail\x01Quantity,Delivery Note Detail\x01Installed Qty,Delivery Note\x01% Installed',
|
||||
'creation': '2011-05-09 11:04:19',
|
||||
'criteria_name': 'Delivered Items to be Install',
|
||||
'custom_query': '',
|
||||
'description': 'Delivered Items to be Install',
|
||||
'dis_filters': None,
|
||||
'disabled': None,
|
||||
'doc_type': 'Delivery Note Detail',
|
||||
'docstatus': 0,
|
||||
'doctype': 'Search Criteria',
|
||||
'filters': "{'Delivery Note\x01Saved':1,'Delivery Note\x01Submitted':1,'Delivery Note\x01Status':'','Delivery Note\x01Fiscal Year':''}",
|
||||
'graph_series': None,
|
||||
'graph_values': None,
|
||||
'group_by': None,
|
||||
'idx': None,
|
||||
'modified': '2011-03-29 14:08:46',
|
||||
'modified_by': 'Administrator',
|
||||
'module': 'CRM',
|
||||
'name': 'delivered_items_to_be_install',
|
||||
'owner': 'Administrator',
|
||||
'page_len': 50,
|
||||
'parent': None,
|
||||
'parent_doc_type': 'Delivery Note',
|
||||
'parentfield': None,
|
||||
'parenttype': None,
|
||||
'report_script': None,
|
||||
'server_script': None,
|
||||
'sort_by': '`tabDelivery Note`.`name`',
|
||||
'sort_order': 'DESC',
|
||||
'standard': 'Yes'
|
||||
}
|
||||
]
|
||||
@@ -0,0 +1,37 @@
|
||||
[
|
||||
{
|
||||
'add_col': "SUM(`tabDelivery Note Detail`.`qty` - `tabDelivery Note Detail`.`billed_qty`) AS 'Pending Qty'\nSUM((`tabDelivery Note Detail`.`qty` - `tabDelivery Note Detail`.`billed_qty`) * `tabDelivery Note Detail`.`basic_rate`) AS 'Pending Amount'",
|
||||
'add_cond': "`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",
|
||||
'add_tab': None,
|
||||
'columns': '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 Detail\x01Item Code,Delivery Note Detail\x01Against Document No,Delivery Note Detail\x01Document Type,Delivery Note Detail\x01Against Document Detail No',
|
||||
'creation': '2010-08-08 17:09:31',
|
||||
'criteria_name': 'Delivery Note Itemwise Pending To Bill',
|
||||
'custom_query': '',
|
||||
'description': None,
|
||||
'dis_filters': None,
|
||||
'disabled': None,
|
||||
'doc_type': 'Delivery Note Detail',
|
||||
'docstatus': 0,
|
||||
'doctype': 'Search Criteria',
|
||||
'filters': "{'Delivery Note\x01Saved':1,'Delivery Note\x01Submitted':1,'Delivery Note\x01Status':'','Delivery Note\x01Company Name':'','Delivery Note\x01Fiscal Year':''}",
|
||||
'graph_series': None,
|
||||
'graph_values': None,
|
||||
'group_by': '`tabDelivery Note Detail`.item_code, `tabDelivery Note`.`name`',
|
||||
'idx': None,
|
||||
'modified': '2010-04-06 17:22:13',
|
||||
'modified_by': 'Administrator',
|
||||
'module': 'CRM',
|
||||
'name': 'delivery_note_itemwise_pending_to_bill',
|
||||
'owner': 'jai@webnotestech.com',
|
||||
'page_len': 50,
|
||||
'parent': None,
|
||||
'parent_doc_type': 'Delivery Note',
|
||||
'parentfield': None,
|
||||
'parenttype': None,
|
||||
'report_script': '',
|
||||
'server_script': None,
|
||||
'sort_by': '`tabDelivery Note`.`name`',
|
||||
'sort_order': 'DESC',
|
||||
'standard': 'Yes'
|
||||
}
|
||||
]
|
||||
@@ -0,0 +1,6 @@
|
||||
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'
|
||||
}
|
||||
]
|
||||
47
selling/search_criteria/follow_up_report/follow_up_report.js
Normal file
47
selling/search_criteria/follow_up_report/follow_up_report.js
Normal file
@@ -0,0 +1,47 @@
|
||||
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:'Follow up on', fieldtype:'Select', options:''+NEWLINE+'Lead'+NEWLINE+'Enquiry'+NEWLINE+'Quotation',ignore : 1,parent:'Follow up', in_first_page : 1, single_select :1});
|
||||
this.add_filter({fieldname:'lead_name', label:'Lead', fieldtype:'Link', options:'Lead', report_default:'', ignore : 1, parent:'Follow up', in_first_page : 1});
|
||||
this.add_filter({fieldname:'enq_name', label:'Enquiry', fieldtype:'Link', options:'Enquiry', report_default:'', ignore : 1, parent:'Follow up', in_first_page : 1});
|
||||
this.add_filter({fieldname:'qtn_name', label:'Quotation', fieldtype:'Link', options:'Quotation', report_default:'', ignore : 1, parent:'Follow up', in_first_page : 1});
|
||||
|
||||
this.get_filter('Follow up', 'Follow up type').set_as_single();
|
||||
this.set_filter_properties('Follow up', 'Follow up by', {filter_hide:0, in_first_page : 1});
|
||||
this.set_filter_properties('Follow up', 'Follow up type', {filter_hide:0, in_first_page : 1});
|
||||
this.set_filter_properties('Follow up', 'From Date', {filter_hide:0, in_first_page : 1});
|
||||
this.set_filter_properties('Follow up', 'To Date', {filter_hide:0, in_first_page : 1});
|
||||
|
||||
this.orig_sort_list = [['Date','`tabFollow up`.`date`'],['Document Type','`tabFollow up`.`parenttype`'],['Document','`tabFollow up`.`parent`'],['Follow Up By','`tabFollow up`.`follow_up_by`'],['Follow Up Type','`tabFollow up`.`follow_up_type`']];
|
||||
}
|
||||
|
||||
|
||||
report.get_query = function() {
|
||||
var lead_id = this.filter_fields_dict['Follow up'+FILTER_SEP+'Lead'].get_value();
|
||||
var enq_id = this.filter_fields_dict['Follow up'+FILTER_SEP+'Enquiry'].get_value();
|
||||
var quo_id = this.filter_fields_dict['Follow up'+FILTER_SEP+'Quotation'].get_value();
|
||||
|
||||
var follow_up_on = this.filter_fields_dict['Follow up'+FILTER_SEP+'Follow up on'].get_value();
|
||||
var follow_up_by = this.filter_fields_dict['Follow up'+FILTER_SEP+'Follow up by'].get_value();
|
||||
|
||||
var on_type = this.filter_fields_dict['Follow up'+FILTER_SEP+'Follow up type'].get_value();
|
||||
var from_date = this.filter_fields_dict['Follow up'+FILTER_SEP+'From Date'].get_value();
|
||||
var to_date = this.filter_fields_dict['Follow up'+FILTER_SEP+'To Date'].get_value();
|
||||
|
||||
var cond = 'parenttype IN ("Lead","Enquiry","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 == 'Enquiry' && 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 `tabFollow up`.`parenttype`, `tabFollow up`.`parent`, `tabFollow up`.`date`, `tabFollow up`.`notes`, `tabFollow up`.`follow_up_type`, `tabFollow up`.`follow_up_by` FROM `tabFollow up` WHERE '+cond+' ORDER BY '+sel_val(this.dt.sort_sel)+' '+this.dt.sort_order;
|
||||
return q;
|
||||
}
|
||||
16
selling/search_criteria/follow_up_report/follow_up_report.py
Normal file
16
selling/search_criteria/follow_up_report/follow_up_report.py
Normal file
@@ -0,0 +1,16 @@
|
||||
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,37 @@
|
||||
[
|
||||
{
|
||||
'add_col': None,
|
||||
'add_cond': None,
|
||||
'add_tab': None,
|
||||
'columns': 'Lead\x01ID,Follow up\x01Date,Follow up\x01Notes,Follow up\x01Follow up type',
|
||||
'creation': '2010-08-13 11:09:21',
|
||||
'criteria_name': 'Follow-up Report',
|
||||
'custom_query': '',
|
||||
'description': None,
|
||||
'dis_filters': None,
|
||||
'disabled': None,
|
||||
'doc_type': 'Follow up',
|
||||
'docstatus': 0,
|
||||
'doctype': 'Search Criteria',
|
||||
'filters': "{'Lead\x01Status':'','Lead\x01Source':'','Lead\x01Lead Type':'','Lead\x01Rating':'','Lead\x01Market Segment':'','Lead\x01Fiscal Year':''}",
|
||||
'graph_series': None,
|
||||
'graph_values': None,
|
||||
'group_by': None,
|
||||
'idx': None,
|
||||
'modified': '2010-08-12 16:33:19',
|
||||
'modified_by': 'Administrator',
|
||||
'module': 'CRM',
|
||||
'name': 'follow-up_report',
|
||||
'owner': 'ashwini@webnotestech.com',
|
||||
'page_len': 50,
|
||||
'parent': None,
|
||||
'parent_doc_type': 'Lead',
|
||||
'parentfield': None,
|
||||
'parenttype': None,
|
||||
'report_script': None,
|
||||
'server_script': None,
|
||||
'sort_by': '`tabLead`.`name`',
|
||||
'sort_order': 'DESC',
|
||||
'standard': 'Yes'
|
||||
}
|
||||
]
|
||||
0
selling/search_criteria/gross_profit/__init__.py
Normal file
0
selling/search_criteria/gross_profit/__init__.py
Normal file
16
selling/search_criteria/gross_profit/gross_profit.js
Normal file
16
selling/search_criteria/gross_profit/gross_profit.js
Normal file
@@ -0,0 +1,16 @@
|
||||
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 Detail'+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 Detail'+FILTER_SEP +'Item Code'].df.in_first_page = 1;
|
||||
this.filter_fields_dict['Delivery Note'+FILTER_SEP +'Project Name'].df.in_first_page = 1;
|
||||
}
|
||||
61
selling/search_criteria/gross_profit/gross_profit.py
Normal file
61
selling/search_criteria/gross_profit/gross_profit.py
Normal file
@@ -0,0 +1,61 @@
|
||||
# Add Columns
|
||||
# ------------
|
||||
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 Detail` 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)
|
||||
37
selling/search_criteria/gross_profit/gross_profit.txt
Normal file
37
selling/search_criteria/gross_profit/gross_profit.txt
Normal file
@@ -0,0 +1,37 @@
|
||||
[
|
||||
{
|
||||
'add_col': None,
|
||||
'add_cond': None,
|
||||
'add_tab': None,
|
||||
'columns': 'Delivery Note\x01ID,Delivery Note\x01Posting Date,Delivery Note\x01Posting Time,Delivery Note Detail\x01Item Code,Delivery Note Detail\x01Item Name,Delivery Note Detail\x01Description,Delivery Note\x01Project Name,Delivery Note Detail\x01Quantity,Delivery Note Detail\x01Rate*,Delivery Note Detail\x01Amount*',
|
||||
'creation': '2010-12-14 10:33:09',
|
||||
'criteria_name': 'Gross Profit',
|
||||
'custom_query': '',
|
||||
'description': 'Invoice wise',
|
||||
'dis_filters': None,
|
||||
'disabled': None,
|
||||
'doc_type': 'Delivery Note Detail',
|
||||
'docstatus': 0,
|
||||
'doctype': 'Search Criteria',
|
||||
'filters': "{'Delivery Note\x01Submitted':1,'Delivery Note\x01Status':'','Delivery Note\x01Fiscal Year':''}",
|
||||
'graph_series': None,
|
||||
'graph_values': None,
|
||||
'group_by': None,
|
||||
'idx': None,
|
||||
'modified': '2010-11-10 12:39:03',
|
||||
'modified_by': 'Administrator',
|
||||
'module': 'CRM',
|
||||
'name': 'gross_profit',
|
||||
'owner': 'Administrator',
|
||||
'page_len': 50,
|
||||
'parent': None,
|
||||
'parent_doc_type': 'Delivery Note',
|
||||
'parentfield': None,
|
||||
'parenttype': None,
|
||||
'report_script': None,
|
||||
'server_script': None,
|
||||
'sort_by': '`tabDelivery Note`.`name`',
|
||||
'sort_order': 'DESC',
|
||||
'standard': 'Yes'
|
||||
}
|
||||
]
|
||||
@@ -0,0 +1,7 @@
|
||||
report.customize_filters = function() {
|
||||
this.filter_fields_dict['Delivery Note'+FILTER_SEP +'From Voucher Date'].df['report_default'] = sys_defaults.year_start_date;
|
||||
this.filter_fields_dict['Delivery Note'+FILTER_SEP +'To Voucher Date'].df['report_default'] = dateutil.obj_to_str(new Date());
|
||||
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,17 @@
|
||||
out=[]
|
||||
qty,amt,bil_qty=0,0,0
|
||||
|
||||
for r in res:
|
||||
qty += flt(r[col_idx['Quantity']])
|
||||
amt += flt(r[col_idx['Amount*']])
|
||||
bil_qty += flt(r[col_idx['Billed Qty']])
|
||||
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 Qty']] = bil_qty
|
||||
out.append(l_row)
|
||||
@@ -0,0 +1,37 @@
|
||||
[
|
||||
{
|
||||
'add_col': None,
|
||||
'add_cond': None,
|
||||
'add_tab': None,
|
||||
'columns': 'Delivery Note\x01ID,Delivery Note Detail\x01Item Code,Delivery Note Detail\x01Item Name,Delivery Note Detail\x01Quantity,Delivery Note Detail\x01Rate*,Delivery Note Detail\x01Amount*,Delivery Note Detail\x01Billed Qty,Delivery Note\x01Company',
|
||||
'creation': '2010-11-10 15:04:42',
|
||||
'criteria_name': 'Itemwise Delivery Details',
|
||||
'custom_query': '',
|
||||
'description': None,
|
||||
'dis_filters': None,
|
||||
'disabled': None,
|
||||
'doc_type': 'Delivery Note Detail',
|
||||
'docstatus': 0,
|
||||
'doctype': 'Search Criteria',
|
||||
'filters': "{'Delivery Note\x01Submitted':1,'Delivery Note\x01Status':'','Delivery Note\x01From Voucher Date\x01lower':'','Delivery Note\x01To Voucher Date\x01upper':'','Delivery Note\x01Fiscal Year':''}",
|
||||
'graph_series': None,
|
||||
'graph_values': None,
|
||||
'group_by': None,
|
||||
'idx': None,
|
||||
'modified': '2010-10-26 09:10:53',
|
||||
'modified_by': 'Administrator',
|
||||
'module': 'CRM',
|
||||
'name': 'itemwise_delivery_details',
|
||||
'owner': 'Administrator',
|
||||
'page_len': 50,
|
||||
'parent': None,
|
||||
'parent_doc_type': 'Delivery Note',
|
||||
'parentfield': None,
|
||||
'parenttype': None,
|
||||
'report_script': None,
|
||||
'server_script': None,
|
||||
'sort_by': '`tabDelivery Note`.`name`',
|
||||
'sort_order': 'DESC',
|
||||
'standard': 'Yes'
|
||||
}
|
||||
]
|
||||
@@ -0,0 +1,11 @@
|
||||
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 Detail'+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,19 @@
|
||||
out=[]
|
||||
qty,amt,del_qty,bil_qty=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']])
|
||||
bil_qty += flt(r[col_idx['Billed Qty']])
|
||||
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 Qty']] = bil_qty
|
||||
out.append(l_row)
|
||||
@@ -0,0 +1,37 @@
|
||||
[
|
||||
{
|
||||
'add_col': None,
|
||||
'add_cond': None,
|
||||
'add_tab': None,
|
||||
'columns': 'Sales Order\x01ID,Sales Order\x01Customer,Sales Order Detail\x01Item Code,Sales Order Detail\x01Item Name,Sales Order Detail\x01Quantity,Sales Order Detail\x01Basic Rate*,Sales Order Detail\x01Amount*,Sales Order Detail\x01Delivered Qty,Sales Order Detail\x01Billed Qty,Sales Order\x01Company',
|
||||
'creation': '2010-09-01 15:47:57',
|
||||
'criteria_name': 'Itemwise Sales Details',
|
||||
'custom_query': '',
|
||||
'description': None,
|
||||
'dis_filters': None,
|
||||
'disabled': None,
|
||||
'doc_type': 'Sales Order Detail',
|
||||
'docstatus': 0,
|
||||
'doctype': 'Search Criteria',
|
||||
'filters': "{'Sales Order\x01Submitted':1,'Sales Order\x01Status':'','Sales Order\x01Fiscal Year':''}",
|
||||
'graph_series': None,
|
||||
'graph_values': None,
|
||||
'group_by': '',
|
||||
'idx': None,
|
||||
'modified': '2010-08-30 12:22:47',
|
||||
'modified_by': 'Administrator',
|
||||
'module': 'CRM',
|
||||
'name': 'itemwise_sales_details',
|
||||
'owner': 'Administrator',
|
||||
'page_len': 50,
|
||||
'parent': None,
|
||||
'parent_doc_type': 'Sales Order',
|
||||
'parentfield': None,
|
||||
'parenttype': None,
|
||||
'report_script': None,
|
||||
'server_script': None,
|
||||
'sort_by': '`tabSales Order`.`name`',
|
||||
'sort_order': 'DESC',
|
||||
'standard': 'Yes'
|
||||
}
|
||||
]
|
||||
@@ -0,0 +1,2 @@
|
||||
this.mytabs.items['Select Columns'].hide();
|
||||
this.mytabs.items['More Filters'].hide();
|
||||
@@ -0,0 +1,7 @@
|
||||
total = 0.0
|
||||
monthlist = ['','Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec']
|
||||
for r in res:
|
||||
r[0] = monthlist[r[0]]
|
||||
total += r[1]
|
||||
|
||||
colwidths[col_idx['Total Despatched']] = '200px'
|
||||
@@ -0,0 +1,37 @@
|
||||
[
|
||||
{
|
||||
'add_col': "month(`tabDelivery Note`.posting_date) AS 'Sales Month'\nsum(`tabDelivery Note`.net_total) AS 'Total Despatched'",
|
||||
'add_cond': '`tabDelivery Note`.net_total > 10',
|
||||
'add_tab': None,
|
||||
'columns': '',
|
||||
'creation': '2010-08-08 17:09:31',
|
||||
'criteria_name': 'Monthly Despatched Trend',
|
||||
'custom_query': '',
|
||||
'description': 'Monthly Despatched Trend',
|
||||
'dis_filters': None,
|
||||
'disabled': None,
|
||||
'doc_type': 'Delivery Note',
|
||||
'docstatus': 0,
|
||||
'doctype': 'Search Criteria',
|
||||
'filters': "{'Delivery Note\x01Submitted':1,'Delivery Note\x01Status':'','Delivery Note\x01Chargeable':'Yes','Delivery Note\x01Department':'','Delivery Note\x01Type':'','Delivery Note\x01Company Name':'Janak Healthcare Pvt Ltd','Delivery Note\x01Fiscal Year':'2009-2010'}",
|
||||
'graph_series': 'Despatched Month',
|
||||
'graph_values': 'Total Despatched',
|
||||
'group_by': 'month(`tabDelivery Note`.Posting_date)',
|
||||
'idx': None,
|
||||
'modified': '2010-06-07 15:19:13',
|
||||
'modified_by': 'Administrator',
|
||||
'module': 'CRM',
|
||||
'name': 'monthly_despatched_trend',
|
||||
'owner': 'Administrator',
|
||||
'page_len': 50,
|
||||
'parent': None,
|
||||
'parent_doc_type': None,
|
||||
'parentfield': None,
|
||||
'parenttype': None,
|
||||
'report_script': None,
|
||||
'server_script': None,
|
||||
'sort_by': '`Sales Month`',
|
||||
'sort_order': 'DESC',
|
||||
'standard': 'Yes'
|
||||
}
|
||||
]
|
||||
@@ -0,0 +1,19 @@
|
||||
report.customize_filters = function() {
|
||||
this.hide_all_filters();
|
||||
this.add_filter({fieldname:'transaction_date', label:'Sales Order Date', fieldtype:'Date', parent:'Sales Order', in_first_page : 1,default:''});
|
||||
|
||||
//this.filter_fields_dict['Sales Order'+FILTER_SEP +'Territory'].df.filter_hide = 0;
|
||||
//this.filter_fields_dict['Sales Order'+FILTER_SEP +'Sales Order Date'].df.filter_hide = 0;
|
||||
//this.filter_fields_dict['Sales Order'+FILTER_SEP +'Sales Order Date'].df.in_first_page = 1;
|
||||
|
||||
this.filter_fields_dict['Sales Order Detail'+FILTER_SEP +'Item Code'].df.filter_hide = 0;
|
||||
this.filter_fields_dict['Sales Order Detail'+FILTER_SEP +'Item Code'].df.in_first_page = 1;
|
||||
|
||||
this.filter_fields_dict['Sales Order'+FILTER_SEP +'Company'].df.filter_hide = 0;
|
||||
this.filter_fields_dict['Sales Order'+FILTER_SEP +'Company'].df.in_first_page = 1;
|
||||
|
||||
this.filter_fields_dict['Sales Order'+FILTER_SEP +'Company'].df['report_default'] = sys_defaults.company;
|
||||
|
||||
//this.mytabs.items['Select Columns'].hide();
|
||||
//this.mytabs.items['More Filters'].hide();
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
[
|
||||
{
|
||||
'add_col': None,
|
||||
'add_cond': '',
|
||||
'add_tab': None,
|
||||
'columns': 'Sales Order Detail\x01Item Code,Sales Order Detail\x01Quantity,Sales Order Detail\x01Delivered Qty,Sales Order Detail\x01Billed Qty',
|
||||
'creation': '2010-08-08 17:09:31',
|
||||
'criteria_name': 'Periodic Sales Summary',
|
||||
'custom_query': '',
|
||||
'description': None,
|
||||
'dis_filters': 'fiscal_year',
|
||||
'disabled': 1,
|
||||
'doc_type': 'Sales Order Detail',
|
||||
'docstatus': 0,
|
||||
'doctype': 'Search Criteria',
|
||||
'filters': "{'Sales Order\x01Submitted':1,'Sales Order\x01Company Name':'','Sales Order\x01Fiscal Year':''}",
|
||||
'graph_series': None,
|
||||
'graph_values': None,
|
||||
'group_by': '`tabSales Order Detail`.`item_code`',
|
||||
'idx': None,
|
||||
'modified': '2010-06-03 13:09:00',
|
||||
'modified_by': 'Administrator',
|
||||
'module': 'CRM',
|
||||
'name': 'periodic_sales_summary',
|
||||
'owner': 'Administrator',
|
||||
'page_len': 50,
|
||||
'parent': None,
|
||||
'parent_doc_type': 'Sales Order',
|
||||
'parentfield': None,
|
||||
'parenttype': None,
|
||||
'report_script': None,
|
||||
'server_script': '',
|
||||
'sort_by': '`tabSales Order Detail`.`item_code`',
|
||||
'sort_order': 'DESC',
|
||||
'standard': 'Yes'
|
||||
}
|
||||
]
|
||||
@@ -0,0 +1,9 @@
|
||||
report.customize_filters = function() {
|
||||
this.hide_all_filters();
|
||||
this.filter_fields_dict['Sales Order'+FILTER_SEP +'Sales Partner'].df.filter_hide = 0;
|
||||
this.filter_fields_dict['Sales Order'+FILTER_SEP +'Sales Partner'].df.in_first_page = 1;
|
||||
}
|
||||
|
||||
|
||||
this.mytabs.items['Select Columns'].hide();
|
||||
this.mytabs.items['More Filters'].hide();
|
||||
@@ -0,0 +1,8 @@
|
||||
coltypes[col_idx['Average Commission Rate']] = 'Currency'
|
||||
colwidths[col_idx['Average Commission Rate']] = '200px'
|
||||
|
||||
coltypes[col_idx['Net Total']] = 'Currency'
|
||||
colwidths[col_idx['Net Total']] = '150px'
|
||||
|
||||
coltypes[col_idx['Total Commission']] = 'Currency'
|
||||
colwidths[col_idx['Total Commission']] = '150px'
|
||||
@@ -0,0 +1,37 @@
|
||||
[
|
||||
{
|
||||
'add_col': "SUM(`tabSales Order`.`total_commission`) AS 'Total Commission'\nSUM(`tabSales Order`.`net_total`) AS 'Net Total'\n((SUM(`tabSales Order`.`total_commission`) / SUM(`tabSales Order`.`net_total`)) * 100) AS 'Average Commission Rate'",
|
||||
'add_cond': '`tabSales Order`.`net_total` > 0',
|
||||
'add_tab': None,
|
||||
'columns': 'Sales Order\x01Business Associate',
|
||||
'creation': '2010-08-26 11:52:27',
|
||||
'criteria_name': 'Sales Agentwise Commission',
|
||||
'custom_query': '',
|
||||
'description': 'Sales Agentwise Commission',
|
||||
'dis_filters': None,
|
||||
'disabled': 1,
|
||||
'doc_type': 'Sales Order',
|
||||
'docstatus': 0,
|
||||
'doctype': 'Search Criteria',
|
||||
'filters': "{'Sales Order\x01Submitted':1}",
|
||||
'graph_series': '',
|
||||
'graph_values': '',
|
||||
'group_by': '`tabSales Order`.`sales_partner`',
|
||||
'idx': None,
|
||||
'modified': '2010-08-26 11:48:17',
|
||||
'modified_by': 'Administrator',
|
||||
'module': 'CRM',
|
||||
'name': 'sales_agentwise_commission',
|
||||
'owner': 'Administrator',
|
||||
'page_len': 50,
|
||||
'parent': None,
|
||||
'parent_doc_type': None,
|
||||
'parentfield': None,
|
||||
'parenttype': None,
|
||||
'report_script': None,
|
||||
'server_script': None,
|
||||
'sort_by': '',
|
||||
'sort_order': 'DESC',
|
||||
'standard': 'Yes'
|
||||
}
|
||||
]
|
||||
@@ -0,0 +1,4 @@
|
||||
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 @@
|
||||
[
|
||||
{
|
||||
'add_col': '(`tabSales Order Detail`.qty - ifnull(`tabSales Order Detail`.delivered_qty, 0)) AS "Qty To Deliver"\n(`tabSales Order Detail`.qty - ifnull(`tabSales Order Detail`.billed_qty, 0)) AS "Qty To Bill"\n(`tabSales Order Detail`.qty - ifnull(`tabSales Order Detail`.delivered_qty, 0))*`tabSales Order Detail`.basic_rate AS "Amount To Deliver"\n(`tabSales Order Detail`.qty - ifnull(`tabSales Order Detail`.billed_qty, 0))*`tabSales Order Detail`.basic_rate AS "Amount To Bill"',
|
||||
'add_cond': '(`tabSales Order Detail`.qty - ifnull(`tabSales Order Detail`.delivered_qty, 0) > 0 or `tabSales Order Detail`.qty - ifnull(`tabSales Order Detail`.billed_qty, 0) > 0)\n`tabSales Order`.status != "Stopped"',
|
||||
'add_tab': None,
|
||||
'columns': 'Sales Order\x01ID,Sales Order\x01Sales Order Date,Sales Order\x01Customer,Sales Order\x01Customer Name,Sales Order Detail\x01Item Code,Sales Order Detail\x01Item Name,Sales Order Detail\x01Description,Sales Order Detail\x01Quantity,Sales Order Detail\x01Delivered Qty,Sales Order Detail\x01Billed Qty',
|
||||
'creation': '2011-05-09 11:04:19',
|
||||
'criteria_name': 'Sales Order Pending Items1',
|
||||
'custom_query': '',
|
||||
'description': 'Sales Order Pending Items',
|
||||
'dis_filters': None,
|
||||
'disabled': None,
|
||||
'doc_type': 'Sales Order Detail',
|
||||
'docstatus': 0,
|
||||
'doctype': 'Search Criteria',
|
||||
'filters': "{'Sales Order\x01Submitted':1,'Sales Order\x01Status':'','Sales Order\x01Fiscal Year':''}",
|
||||
'graph_series': None,
|
||||
'graph_values': None,
|
||||
'group_by': None,
|
||||
'idx': None,
|
||||
'modified': '2011-05-09 11:08:05',
|
||||
'modified_by': 'Administrator',
|
||||
'module': 'CRM',
|
||||
'name': 'sales_order_pending_items1',
|
||||
'owner': 'Administrator',
|
||||
'page_len': 50,
|
||||
'parent': None,
|
||||
'parent_doc_type': 'Sales Order',
|
||||
'parentfield': None,
|
||||
'parenttype': None,
|
||||
'report_script': None,
|
||||
'server_script': None,
|
||||
'sort_by': '`tabSales Order`.`name`',
|
||||
'sort_order': 'DESC',
|
||||
'standard': 'Yes'
|
||||
}
|
||||
]
|
||||
4
selling/search_criteria/sales_orderwise_booking_
Normal file
4
selling/search_criteria/sales_orderwise_booking_
Normal file
@@ -0,0 +1,4 @@
|
||||
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 @@
|
||||
[
|
||||
{
|
||||
'add_col': "SUM(CASE WHEN `tabSales Order`.`status` = 'Stopped' THEN (`tabSales Order Detail`.`delivered_qty` * `tabSales Order Detail`.`basic_rate`) ELSE (`tabSales Order Detail`.`qty` * `tabSales Order Detail`.`basic_rate`) END) AS 'Booking Total'\nSUM(`tabSales Order Detail`.`delivered_qty` * `tabSales Order Detail`.`basic_rate`) AS 'Delivered Amount'",
|
||||
'add_cond': '',
|
||||
'add_tab': None,
|
||||
'columns': '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',
|
||||
'creation': '2010-09-01 15:47:57',
|
||||
'criteria_name': 'Sales Orderwise Booking & Delivery Summary',
|
||||
'custom_query': '',
|
||||
'description': 'Sales Orderwise Booking & Delivery Summary',
|
||||
'dis_filters': None,
|
||||
'disabled': None,
|
||||
'doc_type': 'Sales Order Detail',
|
||||
'docstatus': 0,
|
||||
'doctype': 'Search Criteria',
|
||||
'filters': "{'Sales Order\x01Submitted':1,'Sales Order\x01Status':'','Sales Order\x01Fiscal Year':''}",
|
||||
'graph_series': None,
|
||||
'graph_values': None,
|
||||
'group_by': '`tabSales Order`.`name`',
|
||||
'idx': None,
|
||||
'modified': '2010-08-30 12:48:21',
|
||||
'modified_by': 'Administrator',
|
||||
'module': 'CRM',
|
||||
'name': 'sales_orderwise_booking_&_delivery_summary',
|
||||
'owner': 'Administrator',
|
||||
'page_len': 50,
|
||||
'parent': None,
|
||||
'parent_doc_type': 'Sales Order',
|
||||
'parentfield': None,
|
||||
'parenttype': None,
|
||||
'report_script': '',
|
||||
'server_script': None,
|
||||
'sort_by': '`tabSales Order`.`name`',
|
||||
'sort_order': 'DESC',
|
||||
'standard': 'Yes'
|
||||
}
|
||||
]
|
||||
@@ -0,0 +1,4 @@
|
||||
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 @@
|
||||
[
|
||||
{
|
||||
'add_col': 'SUM((`tabSales Order Detail`.`qty` - ifnull(`tabSales Order Detail`.`billed_qty`, 0)) * `tabSales Order Detail`.`basic_rate`) AS "Pending Amount"',
|
||||
'add_cond': '`tabSales Order`.status != "Stopped"\n`tabSales Order`.order_type!="Maintenance"',
|
||||
'add_tab': None,
|
||||
'columns': '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',
|
||||
'creation': '2011-05-09 11:04:19',
|
||||
'criteria_name': 'Sales Orderwise Pending Amount To Bill',
|
||||
'custom_query': '',
|
||||
'description': 'Sales Orderwise Pending Amount To Bill',
|
||||
'dis_filters': None,
|
||||
'disabled': None,
|
||||
'doc_type': 'Sales Order Detail',
|
||||
'docstatus': 0,
|
||||
'doctype': 'Search Criteria',
|
||||
'filters': "{'Sales Order\x01Saved':1,'Sales Order\x01Submitted':1,'Sales Order\x01Company Name':'','Sales Order\x01Fiscal Year':''}",
|
||||
'graph_series': None,
|
||||
'graph_values': None,
|
||||
'group_by': '`tabSales Order`.`name`',
|
||||
'idx': None,
|
||||
'modified': '2011-03-29 14:06:13',
|
||||
'modified_by': 'Administrator',
|
||||
'module': 'CRM',
|
||||
'name': 'sales_orderwise_pending_amount_to_bill',
|
||||
'owner': 'dhanalekshmi@webnotestech.com',
|
||||
'page_len': 50,
|
||||
'parent': None,
|
||||
'parent_doc_type': 'Sales Order',
|
||||
'parentfield': None,
|
||||
'parenttype': None,
|
||||
'report_script': None,
|
||||
'server_script': None,
|
||||
'sort_by': '`tabSales Order`.`name`',
|
||||
'sort_order': 'DESC',
|
||||
'standard': 'Yes'
|
||||
}
|
||||
]
|
||||
@@ -0,0 +1,37 @@
|
||||
[
|
||||
{
|
||||
'add_col': 'SUM(`tabSales Order Detail`.`qty` - ifnull(`tabSales Order Detail`.`delivered_qty`, 0)) AS "Pending Qty"',
|
||||
'add_cond': '`tabSales Order`.status != "Stopped"\n`tabSales Order Detail`.`qty` > ifnull(`tabSales Order Detail`.`delivered_qty`, 0)',
|
||||
'add_tab': None,
|
||||
'columns': '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',
|
||||
'creation': '2011-05-09 11:04:19',
|
||||
'criteria_name': 'Sales Orderwise Pending Qty To Deliver',
|
||||
'custom_query': '',
|
||||
'description': 'Sales Orderwise Pending Qty To Deliver',
|
||||
'dis_filters': None,
|
||||
'disabled': None,
|
||||
'doc_type': 'Sales Order Detail',
|
||||
'docstatus': 0,
|
||||
'doctype': 'Search Criteria',
|
||||
'filters': "{'Sales Order\x01Saved':1,'Sales Order\x01Submitted':1,'Sales Order\x01Status':'','Sales Order\x01Fiscal Year':''}",
|
||||
'graph_series': None,
|
||||
'graph_values': None,
|
||||
'group_by': '`tabSales Order`.`name`',
|
||||
'idx': None,
|
||||
'modified': '2011-03-29 14:02:58',
|
||||
'modified_by': 'Administrator',
|
||||
'module': 'CRM',
|
||||
'name': 'sales_orderwise_pending_qty_to_deliver',
|
||||
'owner': 'dhanalekshmi@webnotestech.com',
|
||||
'page_len': 50,
|
||||
'parent': None,
|
||||
'parent_doc_type': 'Sales Order',
|
||||
'parentfield': None,
|
||||
'parenttype': None,
|
||||
'report_script': '',
|
||||
'server_script': None,
|
||||
'sort_by': '`tabSales Order`.`name`',
|
||||
'sort_order': 'DESC',
|
||||
'standard': 'Yes'
|
||||
}
|
||||
]
|
||||
@@ -0,0 +1,45 @@
|
||||
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 = 'Receivable Voucher';
|
||||
|
||||
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,"")!=""';
|
||||
}
|
||||
if(under =='Receivable Voucher')
|
||||
tab = 'RV';
|
||||
else
|
||||
tab = under;
|
||||
|
||||
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'+tab+' Detail` 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,125 @@
|
||||
# validate Filters
|
||||
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')
|
||||
period = filter_values.get('period')
|
||||
under = filter_values.get('under')
|
||||
if under == 'Sales Invoice': under = 'Receivable Voucher'
|
||||
sales_person = filter_values.get('sales_person')
|
||||
target_on = filter_values.get('target_on')
|
||||
|
||||
|
||||
# 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
|
||||
|
||||
|
||||
|
||||
# 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) * 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 = '%s' and t2.item_group = '%s' and t1.docstatus = 1 and t1.%s between '%s' and '%s' "%(under, (under == 'Receivable Voucher') and 'RV' or 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 Detail` 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 == 'Receivable Voucher') and 'RV' or 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,37 @@
|
||||
[
|
||||
{
|
||||
'add_col': None,
|
||||
'add_cond': None,
|
||||
'add_tab': None,
|
||||
'columns': '',
|
||||
'creation': '2010-12-14 10:33:09',
|
||||
'criteria_name': 'Sales Persons Target Variance (Item Group wise)',
|
||||
'custom_query': '',
|
||||
'description': None,
|
||||
'dis_filters': None,
|
||||
'disabled': None,
|
||||
'doc_type': 'Target Detail',
|
||||
'docstatus': 0,
|
||||
'doctype': 'Search Criteria',
|
||||
'filters': "{'Sales Person\x01Country':'','Sales Person\x01State':'','Target Detail\x01Fiscal Year':''}",
|
||||
'graph_series': None,
|
||||
'graph_values': None,
|
||||
'group_by': None,
|
||||
'idx': None,
|
||||
'modified': '2010-09-25 17:22:58',
|
||||
'modified_by': 'Administrator',
|
||||
'module': 'CRM',
|
||||
'name': 'sales_persons_target_variance_item_group_wise',
|
||||
'owner': 'Administrator',
|
||||
'page_len': 50,
|
||||
'parent': None,
|
||||
'parent_doc_type': 'Sales Person',
|
||||
'parentfield': None,
|
||||
'parenttype': None,
|
||||
'report_script': None,
|
||||
'server_script': None,
|
||||
'sort_by': '`tabTarget Detail`.`target_amount`',
|
||||
'sort_order': 'DESC',
|
||||
'standard': 'Yes'
|
||||
}
|
||||
]
|
||||
0
selling/search_criteria/sales_personwise_transaction_summary/__init__.py
Executable file
0
selling/search_criteria/sales_personwise_transaction_summary/__init__.py
Executable file
@@ -0,0 +1,40 @@
|
||||
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 = 'Receivable Voucher';
|
||||
date_fld = 'voucher_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,13 @@
|
||||
if filter_values.get('based_on') == 'Sales Invoice':
|
||||
based_on_dt = 'Receivable Voucher'
|
||||
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,37 @@
|
||||
[
|
||||
{
|
||||
'add_col': None,
|
||||
'add_cond': None,
|
||||
'add_tab': None,
|
||||
'columns': 'Sales Person\x01ID',
|
||||
'creation': '2011-06-07 16:58:27',
|
||||
'criteria_name': 'Sales Personwise Transaction Summary',
|
||||
'custom_query': '',
|
||||
'description': None,
|
||||
'dis_filters': None,
|
||||
'disabled': None,
|
||||
'doc_type': 'Sales Person',
|
||||
'docstatus': 0,
|
||||
'doctype': 'Search Criteria',
|
||||
'filters': "{'Sales Person\x01Saved':1,'Sales Person\x01Submitted':1,'Sales Person\x01Country':'','Sales Person\x01State':''}",
|
||||
'graph_series': None,
|
||||
'graph_values': None,
|
||||
'group_by': None,
|
||||
'idx': None,
|
||||
'modified': '2011-02-24 17:35:32',
|
||||
'modified_by': 'Administrator',
|
||||
'module': 'CRM',
|
||||
'name': 'sales_personwise_transaction_summary',
|
||||
'owner': 'Administrator',
|
||||
'page_len': 50,
|
||||
'parent': None,
|
||||
'parent_doc_type': None,
|
||||
'parentfield': None,
|
||||
'parenttype': None,
|
||||
'report_script': None,
|
||||
'server_script': None,
|
||||
'sort_by': '`tabSales Person`.`name`',
|
||||
'sort_order': 'DESC',
|
||||
'standard': 'Yes'
|
||||
}
|
||||
]
|
||||
@@ -0,0 +1,27 @@
|
||||
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+'Receivable Voucher',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,110 @@
|
||||
# validate Filters
|
||||
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 == 'Receivable Voucher') 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 == 'Receivable Voucher') 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,37 @@
|
||||
[
|
||||
{
|
||||
'add_col': None,
|
||||
'add_cond': None,
|
||||
'add_tab': None,
|
||||
'columns': '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',
|
||||
'creation': '2010-08-08 17:09:32',
|
||||
'criteria_name': 'Target Variance Report',
|
||||
'custom_query': '',
|
||||
'description': None,
|
||||
'dis_filters': None,
|
||||
'disabled': 0,
|
||||
'doc_type': 'Target Detail',
|
||||
'docstatus': 0,
|
||||
'doctype': 'Search Criteria',
|
||||
'filters': "{'Sales Person\x01Saved':1,'Sales Person\x01Submitted':1,'Sales Person\x01Country':'','Sales Person\x01State':'','Target Detail\x01Fiscal Year':''}",
|
||||
'graph_series': None,
|
||||
'graph_values': None,
|
||||
'group_by': None,
|
||||
'idx': None,
|
||||
'modified': '2010-06-23 12:27:37',
|
||||
'modified_by': 'Administrator',
|
||||
'module': 'CRM',
|
||||
'name': 'target_variance_report',
|
||||
'owner': 'harshada@webnotestech.com',
|
||||
'page_len': 50,
|
||||
'parent': None,
|
||||
'parent_doc_type': 'Sales Person',
|
||||
'parentfield': None,
|
||||
'parenttype': None,
|
||||
'report_script': None,
|
||||
'server_script': None,
|
||||
'sort_by': '',
|
||||
'sort_order': 'DESC',
|
||||
'standard': 'Yes'
|
||||
}
|
||||
]
|
||||
@@ -0,0 +1,45 @@
|
||||
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 = 'Receivable Voucher';
|
||||
|
||||
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 =='Receivable Voucher')
|
||||
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,127 @@
|
||||
# validate Filters
|
||||
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 = 'Receivable Voucher'
|
||||
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 == 'Receivable Voucher') 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 == 'Receivable Voucher') 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,37 @@
|
||||
[
|
||||
{
|
||||
'add_col': None,
|
||||
'add_cond': None,
|
||||
'add_tab': None,
|
||||
'columns': '',
|
||||
'creation': '2010-12-14 10:33:09',
|
||||
'criteria_name': 'Territories Target Variance (Item Group wise)',
|
||||
'custom_query': '',
|
||||
'description': None,
|
||||
'dis_filters': None,
|
||||
'disabled': None,
|
||||
'doc_type': 'Target Detail',
|
||||
'docstatus': 0,
|
||||
'doctype': 'Search Criteria',
|
||||
'filters': "{'Sales Person\x01Country':'','Sales Person\x01State':'','Target Detail\x01Fiscal Year':''}",
|
||||
'graph_series': None,
|
||||
'graph_values': None,
|
||||
'group_by': None,
|
||||
'idx': None,
|
||||
'modified': '2010-11-25 13:18:22',
|
||||
'modified_by': 'Administrator',
|
||||
'module': 'CRM',
|
||||
'name': 'territories_target_variance_item_group_wise',
|
||||
'owner': 'Administrator',
|
||||
'page_len': 50,
|
||||
'parent': None,
|
||||
'parent_doc_type': 'Sales Person',
|
||||
'parentfield': None,
|
||||
'parenttype': None,
|
||||
'report_script': None,
|
||||
'server_script': None,
|
||||
'sort_by': '`tabTarget Detail`.`target_amount`',
|
||||
'sort_order': 'DESC',
|
||||
'standard': 'Yes'
|
||||
}
|
||||
]
|
||||
@@ -0,0 +1,107 @@
|
||||
# Add Columns
|
||||
# ------------
|
||||
based_on = filter_values.get('based_on')
|
||||
|
||||
columns = [[based_on,'Data','150px',''],
|
||||
['Total Qty','Currency','150px',''],
|
||||
['Revenue','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
|
||||
|
||||
|
||||
|
||||
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
|
||||
|
||||
|
||||
|
||||
for r in res:
|
||||
|
||||
qty, rate, amt, tot_val_rate, val_amount = 0, 0, 0, 0,0
|
||||
cn = make_child_lst(based_on,r[0].strip())
|
||||
|
||||
|
||||
|
||||
if based_on == 'Item Group':
|
||||
|
||||
dn = sql("select name from `tabItem` where item_group in %s"%(cn))
|
||||
for n in dn:
|
||||
|
||||
dt = sql("select sum(qty),sum(amount) from `tabDelivery Note Detail` where item_code ='%s' and docstatus = 1"%n[0])
|
||||
|
||||
qty += dt[0][0] and dt[0][0] or 0
|
||||
amt += dt[0][1] and dt[0][1] or 0
|
||||
prt = sql("select distinct t1.name from `tabDelivery Note` t1, `tabDelivery Note Detail` t2 where t1.name = t2.parent and t2.item_code = '%s' and t1.docstatus = 1 and t2.docstatus =1 order by t1.name"%n[0])
|
||||
for p in prt:
|
||||
d1 = sql("select qty from `tabDelivery Note Detail` where parent = '%s' and parenttype ='Delivery Note' and docstatus =1 and item_code = '%s'"%(p[0],n[0]))
|
||||
for t in d1:
|
||||
tot_val_rate = 0
|
||||
packing_list_items = sql("select item_code, warehouse, qty from `tabDelivery Note Packing Detail` where parent = '%s' and parent_item = '%s' and docstatus = 1 order by item_code, warehouse, qty"%(p[0],n[0]))
|
||||
|
||||
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], p[0]))
|
||||
|
||||
val_rate = val_rate and val_rate[0][0] or 0
|
||||
|
||||
tot_val_rate += t[0] and (flt(val_rate) * flt(d[2]) / flt(t[0])) or 0
|
||||
val_amount += flt(tot_val_rate) * flt(t[0])
|
||||
elif based_on == 'Territory':
|
||||
|
||||
|
||||
dn = sql("select name from `tabDelivery Note` where territory in %s and docstatus =1 order by name"%(cn))
|
||||
|
||||
for n in dn:
|
||||
|
||||
dt = sql("select sum(qty), sum(amount) from `tabDelivery Note Detail` where parent = '%s' and docstatus = 1"%n[0])
|
||||
qty += dt[0][0] and dt[0][0] or 0
|
||||
amt += dt[0][1] and dt[0][1] or 0
|
||||
|
||||
d1 = sql("select item_code,qty from `tabDelivery Note Detail` where parent = '%s' and parenttype ='Delivery Note' and docstatus =1"%n[0])
|
||||
|
||||
for t in d1:
|
||||
tot_val_rate = 0
|
||||
packing_list_items = sql("select item_code, warehouse, qty from `tabDelivery Note Packing Detail` where parent = '%s' and parent_item = '%s' and docstatus = 1 order by item_code, warehouse,qty"%(n[0],t[0]))
|
||||
|
||||
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], n[0]))
|
||||
val_rate = val_rate and val_rate[0][0] or 0
|
||||
|
||||
tot_val_rate += t[1] and (flt(val_rate) * flt(d[2]) / flt(t[1])) or 0
|
||||
val_amount += flt(tot_val_rate) * flt(t[1])
|
||||
r.append(fmt_money(qty))
|
||||
|
||||
r.append(fmt_money(amt))
|
||||
gp = flt(r[col_idx['Revenue']]) - flt(val_amount)
|
||||
|
||||
if val_amount: gp_percent = gp * 100 / flt(val_amount)
|
||||
else: gp_percent = gp
|
||||
gp_percent = '%0.2f'%gp_percent
|
||||
|
||||
|
||||
|
||||
r.append(fmt_money(val_amount))
|
||||
r.append(fmt_money(gp_percent))
|
||||
r.append(fmt_money(gp))
|
||||
@@ -0,0 +1,37 @@
|
||||
[
|
||||
{
|
||||
'add_col': None,
|
||||
'add_cond': None,
|
||||
'add_tab': None,
|
||||
'columns': None,
|
||||
'creation': '2010-12-14 17:52:48',
|
||||
'criteria_name': 'Territory, Item Group wise GP',
|
||||
'custom_query': '',
|
||||
'description': None,
|
||||
'dis_filters': None,
|
||||
'disabled': None,
|
||||
'doc_type': 'Delivery Note',
|
||||
'docstatus': 0,
|
||||
'doctype': 'Search Criteria',
|
||||
'filters': "{'Delivery Note\x01Status':'','Delivery Note\x01Fiscal Year':''}",
|
||||
'graph_series': None,
|
||||
'graph_values': None,
|
||||
'group_by': None,
|
||||
'idx': None,
|
||||
'modified': '2011-05-09 14:40:26',
|
||||
'modified_by': 'Administrator',
|
||||
'module': 'CRM',
|
||||
'name': 'territory_item_group_wise_gp',
|
||||
'owner': 'harshada@webnotestech.com',
|
||||
'page_len': 50,
|
||||
'parent': None,
|
||||
'parent_doc_type': None,
|
||||
'parentfield': None,
|
||||
'parenttype': None,
|
||||
'report_script': '',
|
||||
'server_script': None,
|
||||
'sort_by': None,
|
||||
'sort_order': 'DESC',
|
||||
'standard': 'Yes'
|
||||
}
|
||||
]
|
||||
@@ -0,0 +1,6 @@
|
||||
report.customize_filters = function() {
|
||||
this.add_filter({fieldname:'based_on', label:'Based On', fieldtype:'Select', options:'Sales Order'+NEWLINE+'Delivery Note'+NEWLINE+'Receivable Voucher',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,188 @@
|
||||
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,37 @@
|
||||
[
|
||||
{
|
||||
'add_col': None,
|
||||
'add_cond': None,
|
||||
'add_tab': None,
|
||||
'columns': 'Territory\x01ID',
|
||||
'creation': '2010-08-08 17:09:31',
|
||||
'criteria_name': 'Territory Sales - Variance Report',
|
||||
'custom_query': '',
|
||||
'description': None,
|
||||
'dis_filters': None,
|
||||
'disabled': None,
|
||||
'doc_type': 'Territory',
|
||||
'docstatus': 0,
|
||||
'doctype': 'Search Criteria',
|
||||
'filters': "{'Territory\x01State':'','Territory\x01Based On':'Sales Order','Territory\x01Fiscal Year':'2009-2010','Territory\x01Company':'Alpha Company','Territory\x01Period':'Quarterly'}",
|
||||
'graph_series': None,
|
||||
'graph_values': None,
|
||||
'group_by': '',
|
||||
'idx': None,
|
||||
'modified': '2010-03-30 16:48:42',
|
||||
'modified_by': 'Administrator',
|
||||
'module': 'CRM',
|
||||
'name': 'territory_sales_-_variance_report',
|
||||
'owner': 'Administrator',
|
||||
'page_len': 50,
|
||||
'parent': None,
|
||||
'parent_doc_type': None,
|
||||
'parentfield': None,
|
||||
'parenttype': None,
|
||||
'report_script': None,
|
||||
'server_script': None,
|
||||
'sort_by': 'ID',
|
||||
'sort_order': 'DESC',
|
||||
'standard': 'Yes'
|
||||
}
|
||||
]
|
||||
@@ -0,0 +1,12 @@
|
||||
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,206 @@
|
||||
# validate Filters
|
||||
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 = 'Receivable Voucher'
|
||||
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 == 'Receivable Voucher') 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 == 'Receivable Voucher') 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,37 @@
|
||||
[
|
||||
{
|
||||
'add_col': None,
|
||||
'add_cond': None,
|
||||
'add_tab': None,
|
||||
'columns': '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',
|
||||
'creation': '2010-12-14 10:33:08',
|
||||
'criteria_name': 'Total Target Variance Report',
|
||||
'custom_query': None,
|
||||
'description': None,
|
||||
'dis_filters': None,
|
||||
'disabled': None,
|
||||
'doc_type': 'Target Detail',
|
||||
'docstatus': 0,
|
||||
'doctype': 'Search Criteria',
|
||||
'filters': "{'Sales Person\x01Saved':1,'Sales Person\x01Submitted':1,'Sales Person\x01Country':'','Sales Person\x01State':'','Target Detail\x01Fiscal Year':''}",
|
||||
'graph_series': None,
|
||||
'graph_values': None,
|
||||
'group_by': None,
|
||||
'idx': None,
|
||||
'modified': '2010-11-30 15:15:34',
|
||||
'modified_by': 'Administrator',
|
||||
'module': 'CRM',
|
||||
'name': 'total_target_variance_report',
|
||||
'owner': 'Administrator',
|
||||
'page_len': 50,
|
||||
'parent': None,
|
||||
'parent_doc_type': 'Sales Person',
|
||||
'parentfield': None,
|
||||
'parenttype': None,
|
||||
'report_script': None,
|
||||
'server_script': None,
|
||||
'sort_by': '`tabSales Person`.`name`',
|
||||
'sort_order': 'DESC',
|
||||
'standard': 'Yes'
|
||||
}
|
||||
]
|
||||
0
selling/search_criteria/variance_report/__init__.py
Normal file
0
selling/search_criteria/variance_report/__init__.py
Normal file
12
selling/search_criteria/variance_report/variance_report.js
Normal file
12
selling/search_criteria/variance_report/variance_report.js
Normal file
@@ -0,0 +1,12 @@
|
||||
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+'Receivable Voucher',report_default:'Sales Order',ignore : 1, parent:'Target Detail'});
|
||||
}
|
||||
|
||||
//this.mytabs.items['Select Columns'].hide()
|
||||
503
selling/search_criteria/variance_report/variance_report.py
Normal file
503
selling/search_criteria/variance_report/variance_report.py
Normal file
@@ -0,0 +1,503 @@
|
||||
# Add columns
|
||||
# -----------
|
||||
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 == 'Receivable Voucher':
|
||||
under_detail = 'RV'
|
||||
dt = 'voucher_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)
|
||||
37
selling/search_criteria/variance_report/variance_report.txt
Normal file
37
selling/search_criteria/variance_report/variance_report.txt
Normal file
@@ -0,0 +1,37 @@
|
||||
[
|
||||
{
|
||||
'add_col': None,
|
||||
'add_cond': None,
|
||||
'add_tab': None,
|
||||
'columns': '',
|
||||
'creation': '2010-08-08 17:09:31',
|
||||
'criteria_name': 'Variance Report',
|
||||
'custom_query': None,
|
||||
'description': None,
|
||||
'dis_filters': None,
|
||||
'disabled': None,
|
||||
'doc_type': 'Target Detail',
|
||||
'docstatus': 0,
|
||||
'doctype': 'Search Criteria',
|
||||
'filters': "{'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'}",
|
||||
'graph_series': None,
|
||||
'graph_values': None,
|
||||
'group_by': None,
|
||||
'idx': None,
|
||||
'modified': '2010-05-05 11:13:12',
|
||||
'modified_by': 'Administrator',
|
||||
'module': 'CRM',
|
||||
'name': 'variance_report',
|
||||
'owner': 'Administrator',
|
||||
'page_len': 50,
|
||||
'parent': None,
|
||||
'parent_doc_type': 'Territory',
|
||||
'parentfield': None,
|
||||
'parenttype': None,
|
||||
'report_script': None,
|
||||
'server_script': None,
|
||||
'sort_by': 'ID',
|
||||
'sort_order': 'DESC',
|
||||
'standard': 'Yes'
|
||||
}
|
||||
]
|
||||
Reference in New Issue
Block a user