Sourced wnframework-modules from Google Code as erpnext

This commit is contained in:
Pratik Vyas
2011-06-08 14:37:15 +05:30
commit c1e6e4c752
1680 changed files with 162635 additions and 0 deletions

View File

View File

@@ -0,0 +1,13 @@
report.customize_filters = function() {
this.mytabs.items['Select Columns'].hide()
this.hide_all_filters();
this.add_filter({fieldname:'fiscal_year', label:'Fiscal Year', fieldtype:'Link', options:'Fiscal Year', report_default:sys_defaults.fiscal_year, ignore : 1, parent:'DocType'});
this.add_filter({fieldname:'company', label:'Company', fieldtype:'Link', options:'Company', report_default:sys_defaults.company, ignore : 1, parent:'DocType'});
this.add_filter({fieldname:'period', label:'Period', fieldtype:'Select', options:'Monthly'+NEWLINE+'Quarterly'+NEWLINE+'Half Yearly'+NEWLINE+'Annual',ignore : 1, parent:'DocType'});
}
report.aftertableprint = function(t) {
$yt(t,'*',1,{NEWLINE:'<br>'});
}

View File

@@ -0,0 +1,151 @@
if filter_values.get('period'):
period_values = filter_values.get('period').split(NEWLINE)
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 len(period_values) > 2:
msgprint("You can view report only for one period. Please select only one value in period.")
raise Exception
else:
fiscal_year = filter_values.get('fiscal_year')
period = filter_values.get('period')
company = filter_values.get('company')
# 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 = []
columns.append(['ID','Data','150px',''])
columns.append(['Description','Data','150px',''])
# ================ Annual ======================
if period == 'Annual':
columns.append([fiscal_year,'Currency','150px',''])
# =========== Half Yearly ======================
elif period == 'Half Yearly':
columns.append([month_name[start_month-1]+' to '+month_name[start_month+4],'Currency','150px','']) # first half
if start_month == 1: # this is case when fiscal year starts with JAN
columns.append([month_name[start_month+5]+' to '+month_name[start_month+11],'Currency','150px',''])
else: #this is case when fiscal year starts with other than JAN
columns.append([month_name[start_month+5]+' to '+month_name[start_month-2],'Currency','150px',''])
columns.append(['Total','Currency','150px',''])
# ================ 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(['Q'+cstr(q_no)+' ('+month_name[value]+' to '+month_name[value+2]+')','Currency','150px',''])
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(['Q'+cstr(q_no)+' ('+month_name[3*i]+' to '+month_name[3*i+2]+')','Currency','150px',''])
q_no += 1;
columns.append(['Total','Currency','150px',''])
# =============== Monthly ======================
elif period == 'Monthly':
for i in range(start_month-1,len(month_name)):
columns.append([month_name[i],'Currency','150px',''])
for i in range(start_month-1):
columns.append([month_name[i],'Currency','150px',''])
columns.append(['Total','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 = []
if company:
condition = 'docstatus = 1 and fiscal_year = "'+fiscal_year+'" and company = "'+company+'"'
else:
condition = 'docstatus = 1 and fiscal_year = "'+fiscal_year+'"'
for r in res:
det = ''
list_range = 0
query = ''
# ================= Annual Report ===============
if period == 'Annual':
# Main Query
det = sql("SELECT count(*), SUM(net_total), MIN(net_total), MAX(net_total), AVG(net_total) from `tab%s` where %s" %(r[col_idx['ID']],condition))
list_range = 1
# ============ Half Yearly Report ===============
elif period == 'Half Yearly':
# first half
query += 'COUNT(CASE WHEN MONTH(transaction_date) BETWEEN '+cstr(start_month)+' AND '+cstr(start_month+5)+' THEN name ELSE NULL END),SUM(CASE WHEN MONTH(transaction_date) BETWEEN '+cstr(start_month)+' AND '+cstr(start_month+5)+' THEN net_total ELSE NULL END),MIN(CASE WHEN MONTH(transaction_date) BETWEEN '+cstr(start_month)+' AND '+cstr(start_month+5)+' THEN net_total ELSE NULL END),MAX(CASE WHEN MONTH(transaction_date) BETWEEN '+cstr(start_month)+' AND '+cstr(start_month+5)+' THEN net_total ELSE NULL END),AVG(CASE WHEN MONTH(transaction_date) BETWEEN '+cstr(start_month)+' AND '+cstr(start_month+5)+' THEN net_total ELSE NULL END),'
# second half
query += 'COUNT(CASE WHEN MONTH(transaction_date) NOT BETWEEN '+cstr(start_month)+' AND '+cstr(start_month+5)+' THEN name ELSE NULL END),SUM(CASE WHEN MONTH(transaction_date) NOT BETWEEN '+cstr(start_month)+' AND '+cstr(start_month+5)+' THEN net_total ELSE NULL END),MIN(CASE WHEN MONTH(transaction_date) NOT BETWEEN '+cstr(start_month)+' AND '+cstr(start_month+5)+' THEN net_total ELSE NULL END),MAX(CASE WHEN MONTH(transaction_date) NOT BETWEEN '+cstr(start_month)+' AND '+cstr(start_month+5)+' THEN net_total ELSE NULL END),AVG(CASE WHEN MONTH(transaction_date) NOT BETWEEN '+cstr(start_month)+' AND '+cstr(start_month+5)+' THEN net_total ELSE NULL END),'
# Main Query
det = sql("SELECT %s count(*), SUM(net_total), MIN(net_total), MAX(net_total), AVG(net_total) from `tab%s` where %s and transaction_date > CAST('%s' AS DATE)" %(query,r[col_idx['ID']],condition,start_date))
list_range = 3
# =============== Quarterly Report ==============
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;
for i in range(length_1):
value = 3*i + val;
query += 'COUNT(CASE WHEN MONTH(transaction_date) BETWEEN '+cstr(value+1)+' AND '+cstr(value+3)+' THEN name ELSE NULL END),SUM(CASE WHEN MONTH(transaction_date) BETWEEN '+cstr(value+1)+' AND '+cstr(value+3)+' THEN net_total ELSE NULL END),MIN(CASE WHEN MONTH(transaction_date) BETWEEN '+cstr(value+1)+' AND '+cstr(value+3)+' THEN net_total ELSE NULL END),MAX(CASE WHEN MONTH(transaction_date) BETWEEN '+cstr(value+1)+' AND '+cstr(value+3)+' THEN net_total ELSE NULL END),AVG(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 += 'COUNT(CASE WHEN MONTH(transaction_date) BETWEEN '+cstr(3*i+1)+' AND '+cstr(3*i+3)+' THEN name ELSE NULL END),SUM(CASE WHEN MONTH(transaction_date) BETWEEN '+cstr(3*i+1)+' AND '+cstr(3*i+3)+' THEN net_total ELSE NULL END),MIN(CASE WHEN MONTH(transaction_date) BETWEEN '+cstr(3*i+1)+' AND '+cstr(3*i+3)+' THEN net_total ELSE NULL END),MAX(CASE WHEN MONTH(transaction_date) BETWEEN '+cstr(3*i+1)+' AND '+cstr(3*i+3)+' THEN net_total ELSE NULL END),AVG(CASE WHEN MONTH(transaction_date) BETWEEN '+cstr(3*i+1)+' AND '+cstr(3*i+3)+' THEN net_total ELSE NULL END),';
# Main Query
det = sql("SELECT %s count(*), SUM(net_total), MIN(net_total), MAX(net_total), AVG(net_total) from `tab%s` where %s and transaction_date > CAST('%s' AS DATE)" %(query,r[col_idx['ID']],condition,start_date))
list_range = 5
# ================ Monthly Report ===============
elif period == 'Monthly':
# 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 += 'COUNT(CASE WHEN MONTH(transaction_date) = '+cstr(i+1)+' THEN name ELSE NULL END), SUM(CASE WHEN MONTH(transaction_date) = '+cstr(i+1)+' THEN net_total ELSE NULL END),MIN(CASE WHEN MONTH(transaction_date) = '+cstr(i+1)+' THEN net_total ELSE NULL END), MAX(CASE WHEN MONTH(transaction_date) = '+cstr(i+1)+' THEN net_total ELSE NULL END), AVG(CASE WHEN MONTH(transaction_date) = '+cstr(i+1)+' THEN net_total ELSE NULL END),'
# the above query calculates total_no, total_amt, min_amt, max_amt, avg_amt of doctypes in monthwise
for i in range(start_month-1):
query += 'COUNT(CASE WHEN MONTH(transaction_date) = '+cstr(i+1)+' THEN name ELSE NULL END), SUM(CASE WHEN MONTH(transaction_date) = '+cstr(i+1)+' THEN net_total ELSE NULL END),MIN(CASE WHEN MONTH(transaction_date) = '+cstr(i+1)+' THEN net_total ELSE NULL END), MAX(CASE WHEN MONTH(transaction_date) = '+cstr(i+1)+' THEN net_total ELSE NULL END), AVG(CASE WHEN MONTH(transaction_date) = '+cstr(i+1)+' THEN net_total ELSE NULL END),'
# Main Query
det = sql("SELECT %s count(*), SUM(net_total), MIN(net_total), MAX(net_total), AVG(net_total) from `tab%s` where %s and transaction_date > CAST('%s' AS DATE)" %(query,r[col_idx['ID']],condition,start_date))
list_range = 13
# bifurcate all values and append them in list
total_no,total_amt,min_amt,max_amt,avg_amt = [],[],[],[],[]
count = 0
# append values to list
for i in range(list_range):
total_no.append(cstr(det and det[0][count] or 0))
total_amt.append(cstr(det and det[0][count+1] or 0))
min_amt.append(cstr(det and det[0][count+2] or 0))
max_amt.append(cstr(det and det[0][count+3] or 0))
avg_amt.append(cstr(det and det[0][count+4] or 0))
count += 5
for col in range(len(colnames)-1): # this would make all first row blank. just for look
r.append('')
out.append(r)
d = [['Total No',total_no],['Total Amount',total_amt],['Min Amount',min_amt],['Max Amount',max_amt],['Avg Amount',avg_amt]]
for des in range(5):
t_row = ['' for i in range(len(colnames))]
t_row[col_idx['Description']] = d[des][0]
for v in range(list_range):
t_row[col_idx[colnames[v+2]]] = flt(d[des][1][v])
out.append(t_row)

View File

@@ -0,0 +1 @@
SELECT DISTINCT name FROM tabDocType WHERE document_type="Transaction" AND ifnull(istable,0) = 0

View File

@@ -0,0 +1,37 @@
[
{
'add_col': None,
'add_cond': None,
'add_tab': None,
'columns': 'Profile\x01ID',
'creation': '2010-09-20 13:00:41',
'criteria_name': 'Monthly Transaction Summary',
'custom_query': None,
'description': None,
'dis_filters': None,
'disabled': None,
'doc_type': 'Profile',
'docstatus': 0,
'doctype': 'Search Criteria',
'filters': "{'DocType\x01Period':'Monthly'}",
'graph_series': None,
'graph_values': None,
'group_by': None,
'idx': None,
'modified': '2010-09-17 16:02:25',
'modified_by': 'Administrator',
'module': 'Analysis',
'name': 'monthly_transaction_summary',
'owner': 'Administrator',
'page_len': None,
'parent': None,
'parent_doc_type': None,
'parentfield': None,
'parenttype': None,
'report_script': None,
'server_script': None,
'sort_by': '`tabProfile`.`name`',
'sort_order': 'DESC',
'standard': 'Yes'
}
]

View File

@@ -0,0 +1,121 @@
report.customize_filters = function() {
this.hide_all_filters();
this.add_filter({fieldname:'transaction', label:'Transaction', fieldtype:'Select', options:'Quotation'+NEWLINE+'Sales Order'+NEWLINE+'Delivery Note'+NEWLINE+'Sales Invoice'+NEWLINE+'Purchase Order'+NEWLINE+'Purchase Receipt'+NEWLINE+'Purchase Invoice',report_default:'Delivery Note',ignore : 1,parent:'Profile',in_first_page : 1,single_select : 1});
this.add_filter({fieldname:'period', label:'Period', fieldtype:'Select', options:'Monthly'+NEWLINE+'Quarterly'+NEWLINE+'Half Yearly'+NEWLINE+'Annual',report_default:'Quarterly',ignore : 1, parent:'Profile',in_first_page:1,single_select:1});
this.add_filter({fieldname:'based_on', label:'Based On', fieldtype:'Select', options:'Item'+NEWLINE+'Item Group'+NEWLINE+'Customer'+NEWLINE+'Customer Group'+NEWLINE+'Territory'+NEWLINE+'Supplier'+NEWLINE+'Supplier Type', ignore : 1, parent:'Profile', report_default:'Item', in_first_page : 1,single_select:1});
this.add_filter({fieldname:'group_by', label:'Group By', fieldtype:'Select', options:NEWLINE+'Item'+NEWLINE+'Customer'+NEWLINE+'Supplier', ignore : 1, parent:'Profile',single_select:1});
this.add_filter({fieldname:'order_type', label:'Order Type', fieldtype:'Select', options:NEWLINE+'Sales'+NEWLINE+'Maintenance',ignore : 1, parent:'Profile',single_select:1});
this.add_filter({fieldname:'company', label:'Company', fieldtype:'Link', options:'Company', report_default:sys_defaults.company, ignore : 1, parent:'Profile'});
this.set_filter_properties('Profile','Fiscal Year',{filter_hide:0, in_first_page:1, report_default: sys_defaults.fiscal_year});
this.get_filter('Profile', 'Fiscal Year').set_as_single();
// Add Filters
this.add_filter({fieldname:'item', label:'Item', fieldtype:'Link', options:'Item', ignore : 1, parent:'Profile'});
this.add_filter({fieldname:'item_group', label:'Item Group', fieldtype:'Link', options:'Item Group', ignore : 1, parent:'Profile'});
this.add_filter({fieldname:'customer', label:'Customer', fieldtype:'Link', options:'Customer', ignore : 1, parent:'Profile'});
this.add_filter({fieldname:'customer_group', label:'Customer Group', fieldtype:'Link', options:'Customer Group', ignore : 1, parent:'Profile'});
this.add_filter({fieldname:'territory', label:'Territory', fieldtype:'Link', options:'Territory', ignore : 1, parent:'Profile'});
this.add_filter({fieldname:'supplier', label:'Supplier', fieldtype:'Link', options:'Supplier', ignore : 1, parent:'Profile'});
this.add_filter({fieldname:'supplier_type', label:'Supplier Type', fieldtype:'Link', options:'Supplier Type', ignore : 1, parent:'Profile'});
}
this.mytabs.tabs['Select Columns'].hide();
report.aftertableprint = function(t) {
$yt(t,'*',1,{whiteSpace:'pre'});
}
var validate_values = function(trans,based_on,order_type) {
if(!fiscal_year){
msgprint("Please select Fiscal Year");
return 0;
}
if((in_list(['Quotation','Sales Order','Delivery Note','Sales Invoice'],trans) && in_list(['Supplier','Supplier Type'],based_on)) || (in_list(['Purchase Order','Purchase Receipt','Purchase Invoice'],trans) && in_list(['Customer','Customer Group','Territory'],based_on))){
msgprint("Sorry! You cannot fetch "+trans+" trend based on "+based_on);
return 0;
}
if(in_list(['Purchase Order','Purchase Receipt','Purchase Invoice'],trans) && order_type){
msgprint("Please deselect Order Type for "+trans);
return 0;
}
return 1;
}
report.get_query = function() {
trans = this.get_filter('Profile', 'Transaction').get_value();
order_type = this.get_filter('Profile', 'Order Type').get_value();
based_on = this.get_filter('Profile', 'Based On').get_value();
company = this.get_filter('Profile', 'Company').get_value();
fiscal_year = this.get_filter('Profile', 'Fiscal Year').get_value();
if(validate_values(trans,based_on,order_type)){
col = '';
add_cond = '';
add_col = '';
add_tables = '';
sp_cond = '';
if(trans == 'Sales Invoice') trans = 'Receivable Voucher';
else if(trans == 'Purchase Invoice') trans = 'Payable Voucher';
trans_det = trans+' Detail'
if(trans == 'Receivable Voucher') trans_det = 'RV Detail';
else if(trans == 'Payable Voucher') trans_det = 'PV Detail';
else if(trans == 'Purchase Order') trans_det = 'PO Detail';
if(order_type != '') add_code += ' AND t1.order_type = '+order_type;
switch(based_on){
case 'Item' : item = this.get_filter('Profile', 'Item').get_value();
col = 'DISTINCT t2.item_code, t3.item_name';
add_tables = ',tabItem t3';
add_cond += ' AND t2.item_code = t3.name';
if(item) add_cond += ' AND t2.item_code = "'+item+'"';
break;
case 'Customer' : cust = this.get_filter('Profile', 'Customer').get_value();
col = 'DISTINCT t1.customer, t3.territory';
add_tables = ',tabCustomer t3';
add_cond += ' AND t1.customer = t3.name';
if(cust) add_cond += ' AND t1.customer = "'+cust+'"';
break;
case 'Supplier' : supp = this.get_filter('Profile', 'Supplier').get_value();
col = 'DISTINCT t1.supplier, t3.supplier_type';
add_tables = ',tabSupplier t3';
add_cond += ' AND t1.supplier = t3.name';
if(supp) add_cond += ' AND t1.supplier = "'+supp+'"';
break;
case 'Supplier Type' : supp_type = this.get_filter('Profile', 'Supplier Type').get_value();
col = 'DISTINCT t3.supplier_type';
add_tables = ',tabSupplier t3';
add_cond += ' AND t1.supplier = t3.name';
if(supp_type) add_cond += ' AND t1.supplier_type = "'+supp_type+'"';
break;
case 'Item Group' : ig = this.get_filter('Profile', 'Item Group').get_value();
if(ig) sp_cond += ' AND parent.name = "'+ig+'"';
break;
case 'Customer Group' : cg = this.get_filter('Profile', 'Customer Group').get_value();
if(cg) sp_cond += ' AND parent.name = "'+cg+'"';
break;
case 'Territory' : ter = this.get_filter('Profile', 'Territory').get_value();
if(ter) sp_cond += ' AND parent.name = "'+ter+'"';
break;
}
if(based_on == 'Item' || based_on == 'Customer' || based_on == 'Supplier' || based_on == 'Supplier Type')
var q ='SELECT '+col+' FROM `tab'+trans+'` t1, `tab'+trans_det+'` t2 '+add_tables+' WHERE t1.fiscal_year = "'+fiscal_year+'" and t1.company = "'+company+'" and t2.parent = t1.name '+add_cond;
else
var q = 'SELECT CONCAT(REPEAT(" ", COUNT(parent.name) - 1), node.name) AS "Name" FROM `tab'+based_on+'` node,`tab'+based_on+'` parent WHERE node.lft BETWEEN parent.lft and parent.rgt and node.docstatus !=2 '+sp_cond+' GROUP BY node.name ORDER BY node.lft';
return q;
}
}

View File

@@ -0,0 +1,160 @@
# ********************************************* INITIALIZATION *******************************************
out = []
# Filter Values
# =============================================
based_on = filter_values.get('based_on')
group_by = filter_values.get('group_by')
trans = filter_values.get('transaction')
period = filter_values.get('period')
order_type = filter_values.get('order_type')
company = filter_values.get('company')
fiscal_year = filter_values.get('fiscal_year')
item = filter_values.get('item')
item_group = filter_values.get('item_group')
customer = filter_values.get('customer')
customer_group = filter_values.get('customer_group')
territory = filter_values.get('territory')
supplier = filter_values.get('supplier')
supplier_type = filter_values.get('supplier_type')
# ********************************************* SET DEFAULTS **************************************************
# Details Table
# --------------
if trans == 'Sales Invoice': trans = 'Receivable Voucher'
elif trans == 'Purchase Invoice': trans = 'Payable Voucher'
trans_det = trans+' Detail'
if trans == 'Receivable Voucher': trans_det = 'RV Detail'
elif trans == 'Payable Voucher': trans_det = 'PV Detail'
elif trans == 'Purchase Order': trans_det = 'PO Detail'
col_names, query_val = get_obj('TA Control').get_single_year_query_value(fiscal_year, period, trans, trans_det)
query_val += 'SUM(t2.qty), SUM(t2.amount)'
col_names.append('Total (Qty)')
col_names.append('Total (Amt)')
# ********************************************* VALIDATIONS ***************************************************
if (based_on in ['Customer','Customer Group','Territory'] and group_by == 'Supplier') or (based_on in ['Supplier','Supplier Type'] and group_by == 'Customer'):
msgprint("Sorry! You cannot group Trend Analyzer based on %s by %s" % (based_on,group_by))
raise Exception
if based_on == group_by:
msgprint("Based On and Group By value cannot be same for Trend Analyzer")
raise Exception
# ********************************************** ADD COLUMNS **********************************************
cols = [[based_on, 'Data', '300px', '']]
cr = 1
if based_on == 'Item':
cols.append(['Item Name','Data','200px',''])
cr = 2
elif based_on == 'Customer':
cols.append(['Territory','Link','150px','Territory'])
cr = 2
elif based_on == 'Supplier':
cols.append(['Supplier Type','Link','150px','Supplier Type'])
cr = 2
if group_by:
cr += 1
if group_by:
cols.append([group_by,'Data','150px',''])
for c in col_names:
cols.append([c,'Currency','150px',''])
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
# ******************************************* ADDITIONAL CONDITION ************************************************
add_cond = ' t2.parent = t1.name AND t1.company = "%s" AND t1.fiscal_year = "%s" and t1.docstatus = 1' % (company, fiscal_year)
add_tab = ' `tab'+trans+'` t1, `tab'+trans_det+'` t2'
if order_type: add_cond += ' AND t1.order_type = "%s"' % order_type
# Item
if item or based_on == 'Item':
add_cond += ' AND t2.item_code = "%s"' % (based_on != 'Item' and item or '%(value)s')
# Item Group
if item_group or based_on == 'Item Group':
add_tab += ' ,`tabItem` t3, `tabItem Group` t4 '
add_cond += ' AND t3.name = t2.item_code AND t3.item_group = t4.name and (t4.name = "%s" or t4.name IN (SELECT t5.name FROM `tabItem Group` t5,`tabItem Group` t6 WHERE t5.lft BETWEEN t6.lft and t6.rgt and t5.docstatus !=2 and ifnull(t5.is_group,"No") = "No" and t6.name = "%s"))' % (based_on != 'Item Group' and item_group or '%(value)s', based_on != 'Item Group' and item_group or '%(value)s')
# Customer
if customer or based_on == 'Customer':
add_cond += ' AND t1.customer = "%s"' % (based_on != 'Customer' and customer or '%(value)s')
# Customer Group
if customer_group or based_on == 'Customer Group':
add_tab += ' ,`tabCustomer` t7, `tabCustomer Group` t8 '
add_cond += ' AND t7.name = t1.customer AND t7.customer_group = t8.name and (t8.name = "%s" or t8.name IN (SELECT t9.name FROM `tabCustomer Group` t9,`tabCustomer Group` t10 WHERE t9.lft BETWEEN t10.lft and t10.rgt and t9.docstatus !=2 and ifnull(t9.is_group,"No") = "No" and t10.name = "%s"))' % (based_on != 'Customer Group' and customer_group or '%(value)s', based_on != 'Customer Group' and customer_group or '%(value)s')
# Territory
if territory or based_on == 'Territory':
add_tab += ' ,`tabTerritory` t11 '
add_cond += ' AND t1.territory = t11.name AND t1.territory = t11.name and (t11.name = "%s" or t11.name IN (SELECT t12.name FROM `tabTerritory` t12,`tabTerritory` t13 WHERE t12.lft BETWEEN t13.lft and t13.rgt and t12.docstatus !=2 and ifnull(t12.is_group,"No") = "No" and t13.name = "%s"))' % (based_on != 'Territory' and territory or '%(value)s', based_on != 'Territory' and territory or '%(value)s')
# Supplier
if supplier or based_on == 'Supplier':
add_cond += ' AND t1.supplier = "%s"' % (based_on != 'Supplier' and supplier or '%(value)s')
# Supplier Type
if supplier_type or based_on == 'Supplier Type':
add_tab += ' ,`tabSupplier` t14, `tabSupplier Type` t15 '
add_cond += ' AND t14.name = t1.supplier AND t14.supplier_type = t15.name and t15.name = "%s"' % (based_on != 'Supplier Type' and supplier_type or '%(value)s')
# Column to be seleted for group by condition
# ==============================================
sel_col = ''
if group_by == 'Item':
sel_col = 't2.item_code'
elif group_by == 'Customer':
sel_col = 't1.customer'
elif group_by == 'Supplier':
sel_col = 't1.supplier'
# ********************************************** Result Set ************************************************
for r in res:
main_det = sql("SELECT %s FROM %s WHERE %s" % (query_val, add_tab, add_cond % {'value':cstr(r[col_idx[based_on]]).strip()}))
if group_by:
for col in range(cr,cr+1): # this would make all first row blank. just for look
r.append('')
if main_det[0][len(colnames) - cr - 1]:
for d in range(len(colnames) - cr):
r.append(flt(main_det[0][d]))
out.append(r)
if group_by:
flag = 1
# check for root nodes
if based_on in ['Item Group','Customer Group','Territory']:
is_grp = sql("select is_group from `tab%s` where name = '%s'" % (based_on, cstr(r[col_idx[based_on]]).strip()))
is_grp = is_grp and cstr(is_grp[0][0]) or ''
if is_grp != 'No':
flag = 0
if flag == 1:
det = [x[0] for x in sql("SELECT DISTINCT %s FROM %s where %s" % (sel_col, add_tab, add_cond % {'value':cstr(r[col_idx[based_on]]).strip()}))]
for des in range(len(det)):
t_row = ['' for i in range(len(colnames))]
t_row[col_idx[group_by]] = cstr(det[des])
gr_det = sql("SELECT %s FROM %s WHERE %s = '%s' and %s" % (query_val, add_tab, sel_col, cstr(det[des]), add_cond % {'value':cstr(r[col_idx[based_on]]).strip()}))
for d in range(len(col_names)):
t_row[col_idx[col_names[d]]] = flt(gr_det[0][d])
out.append(t_row)

View File

@@ -0,0 +1,37 @@
[
{
'add_col': None,
'add_cond': None,
'add_tab': None,
'columns': 'Profile\x01ID,Profile\x01Owner',
'creation': '2010-12-14 10:33:09',
'criteria_name': 'Trend Analyzer',
'custom_query': '',
'description': None,
'dis_filters': None,
'disabled': None,
'doc_type': 'Profile',
'docstatus': 0,
'doctype': 'Search Criteria',
'filters': '{}',
'graph_series': None,
'graph_values': None,
'group_by': None,
'idx': None,
'modified': '2010-11-10 11:06:06',
'modified_by': 'Administrator',
'module': 'Analysis',
'name': 'trend_analyzer',
'owner': 'saumil@webnotestech.com',
'page_len': 50,
'parent': None,
'parent_doc_type': None,
'parentfield': None,
'parenttype': None,
'report_script': None,
'server_script': None,
'sort_by': '`tabProfile`.`name`',
'sort_order': 'DESC',
'standard': 'Yes'
}
]

View File

@@ -0,0 +1,12 @@
report.customize_filters = function() {
this.mytabs.items['Select Columns'].hide()
this.hide_all_filters();
this.add_filter({fieldname:'company', label:'Company', fieldtype:'Link', options:'Company', report_default:sys_defaults.company, ignore : 1, parent:'Profile'});
this.add_filter({fieldname:'from_fiscal_year', label:'From Fiscal Year', fieldtype:'Link', options:'Fiscal Year', report_default:sys_defaults.fiscal_year, ignore : 1, parent:'Profile'});
this.add_filter({fieldname:'to_fiscal_year', label:'To Fiscal Year', fieldtype:'Link', options:'Fiscal Year', report_default:sys_defaults.fiscal_year, ignore : 1, parent:'Profile'});
this.add_filter({fieldname:'date', label:'Date', fieldtype:'Date', options:'',ignore : 1, parent:'Profile'});
}
report.aftertableprint = function(t) {
$yt(t,'*',1,{NEWLINE:'<br>'});
}

View File

@@ -0,0 +1,115 @@
if not filter_values.get('from_fiscal_year'):
msgprint("Please Select From Fiscal Year")
raise Exception
elif not filter_values.get('to_fiscal_year'):
msgprint("Please Select To Fiscal Year")
raise Exception
else:
from_fiscal_year = filter_values.get('from_fiscal_year')
to_fiscal_year = filter_values.get('to_fiscal_year')
company = filter_values.get('company')
from_date = filter_values.get('date')
to_date = filter_values.get('date1')
if from_date != "" and to_date != "":
get_obj('MIS Control').dates(from_fiscal_year,from_date,to_date) # validate dates (i.e. dates should be between particular fiscal year)
# Add columns based on from and to fiscal year
# --------------------------------------------------------------------------------------------------
columns = []
columns.append(['ID','Data','150px',''])
columns.append(['Description','Data','150px',''])
columns.append([from_fiscal_year,'Data','150px','']) # append from fiscal year column
# === get no. of fiscal years between from and to fiscal year and append columns accordingly ========
start_year = from_fiscal_year.split('-')[1] # eg. from fiscal year 2008-2009 . this gives value 2009
end_year = to_fiscal_year.split('-')[0] # eg. to fiscal year 2009-2010 . this gives value 2009
diff = cint(end_year)-cint(start_year)
if diff > 0:
year = cint(start_year);
next_year = 0
f_year = ''
for i in range(1,diff+1):
next_year = cint(year)+1
f_year = cstr(year)+'-'+cstr(next_year)
columns.append([f_year,'Data','150px',''])
# ====================================================================================================
columns.append([to_fiscal_year,'Data','150px','']) # append to fiscal year column
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 = []
# =========================== condition for result ===================================================
if company:
condition = 'docstatus = 1 and company = "'+company+'"'
else:
condition = 'docstatus = 1'
# ====================================================================================================
for r in res:
det = ''
query = ''
list_range = 0
if from_date != "" and to_date != "":
date_1 = cstr(get_obj('MIS Control').dates(from_fiscal_year,from_date,to_date))
query += 'COUNT(CASE WHEN (fiscal_year = "'+from_fiscal_year+'" and (transaction_date BETWEEN CAST("'+date_1.split('~~~')[0]+'" AS DATE) AND CAST("'+date_1.split('~~~')[1]+'" AS DATE))) THEN name ELSE NULL END),SUM(CASE WHEN (fiscal_year = "'+from_fiscal_year+'" and (transaction_date BETWEEN CAST("'+date_1.split('~~~')[0]+'" AS DATE) AND CAST("'+date_1.split('~~~')[1]+'" AS DATE))) THEN net_total ELSE NULL END),MIN(CASE WHEN (fiscal_year = "'+from_fiscal_year+'" and (transaction_date BETWEEN CAST("'+date_1.split('~~~')[0]+'" AS DATE) AND CAST("'+date_1.split('~~~')[1]+'" AS DATE))) THEN net_total ELSE NULL END),MAX(CASE WHEN (fiscal_year = "'+from_fiscal_year+'" and (transaction_date BETWEEN CAST("'+date_1.split('~~~')[0]+'" AS DATE) AND CAST("'+date_1.split('~~~')[1]+'" AS DATE))) THEN net_total ELSE NULL END),AVG(CASE WHEN (fiscal_year = "'+from_fiscal_year+'" and (transaction_date BETWEEN CAST("'+date_1.split('~~~')[0]+'" AS DATE) AND CAST("'+date_1.split('~~~')[1]+'" AS DATE))) THEN net_total ELSE NULL END),'
else:
query += 'COUNT(CASE WHEN fiscal_year = "'+from_fiscal_year+'" THEN name ELSE NULL END),SUM(CASE WHEN fiscal_year = "'+from_fiscal_year+'" THEN net_total ELSE NULL END),MIN(CASE WHEN fiscal_year = "'+from_fiscal_year+'" THEN net_total ELSE NULL END),MAX(CASE WHEN fiscal_year = "'+from_fiscal_year+'" THEN net_total ELSE NULL END),AVG(CASE WHEN fiscal_year = "'+from_fiscal_year+'" THEN net_total ELSE NULL END),'
list_range += 1
if diff > 0:
year = cint(start_year);
next_year = 0
f_year = ''
for i in range(1,diff+1):
next_year = cint(year)+1;
f_year = cstr(year)+'-'+cstr(next_year);
if from_date != "" and to_date != "":
date_2 = cstr(get_obj('MIS Control').dates(f_year,from_date,to_date))
query += 'COUNT(CASE WHEN (fiscal_year = "'+f_year+'" and (transaction_date BETWEEN CAST("'+date_2.split('~~~')[0]+'" AS DATE) AND CAST("'+date_2.split('~~~')[1]+'" AS DATE))) THEN name ELSE NULL END),SUM(CASE WHEN (fiscal_year = "'+f_year+'" and (transaction_date BETWEEN CAST("'+date_2.split('~~~')[0]+'" AS DATE) AND CAST("'+date_2.split('~~~')[1]+'" AS DATE))) THEN net_total ELSE NULL END),MIN(CASE WHEN (fiscal_year = "'+f_year+'" and (transaction_date BETWEEN CAST("'+date_2.split('~~~')[0]+'" AS DATE) AND CAST("'+date_2.split('~~~')[1]+'" AS DATE))) THEN net_total ELSE NULL END),MAX(CASE WHEN (fiscal_year = "'+f_year+'" and (transaction_date BETWEEN CAST("'+date_2.split('~~~')[0]+'" AS DATE) AND CAST("'+date_2.split('~~~')[1]+'" AS DATE))) THEN net_total ELSE NULL END),AVG(CASE WHEN (fiscal_year = "'+f_year+'" and (transaction_date BETWEEN CAST("'+date_2.split('~~~')[0]+'" AS DATE) AND CAST("'+date_2.split('~~~')[1]+'" AS DATE))) THEN net_total ELSE NULL END),'
else:
query += 'COUNT(CASE WHEN fiscal_year = "'+f_year+'" THEN name ELSE NULL END),SUM(CASE WHEN fiscal_year = "'+f_year+'" THEN net_total ELSE NULL END),MIN(CASE WHEN fiscal_year = "'+f_year+'" THEN net_total ELSE NULL END),MAX(CASE WHEN fiscal_year = "'+f_year+'" THEN net_total ELSE NULL END),AVG(CASE WHEN fiscal_year = "'+f_year+'" THEN net_total ELSE NULL END),'
year += 1
list_range += 1
if from_date != "" and to_date != "":
date_3 = cstr(get_obj('MIS Control').dates(to_fiscal_year,from_date,to_date))
query += 'COUNT(CASE WHEN (fiscal_year = "'+to_fiscal_year+'" and (transaction_date BETWEEN CAST("'+date_3.split('~~~')[0]+'" AS DATE) AND CAST("'+date_3.split('~~~')[1]+'" AS DATE))) THEN name ELSE NULL END),SUM(CASE WHEN (fiscal_year = "'+to_fiscal_year+'" and (transaction_date BETWEEN CAST("'+date_3.split('~~~')[0]+'" AS DATE) AND CAST("'+date_3.split('~~~')[1]+'" AS DATE))) THEN net_total ELSE NULL END),MIN(CASE WHEN (fiscal_year = "'+to_fiscal_year+'" and (transaction_date BETWEEN CAST("'+date_3.split('~~~')[0]+'" AS DATE) AND CAST("'+date_3.split('~~~')[1]+'" AS DATE))) THEN net_total ELSE NULL END),MAX(CASE WHEN (fiscal_year = "'+to_fiscal_year+'" and (transaction_date BETWEEN CAST("'+date_3.split('~~~')[0]+'" AS DATE) AND CAST("'+date_3.split('~~~')[1]+'" AS DATE))) THEN net_total ELSE NULL END),AVG(CASE WHEN (fiscal_year = "'+to_fiscal_year+'" and (transaction_date BETWEEN CAST("'+date_3.split('~~~')[0]+'" AS DATE) AND CAST("'+date_3.split('~~~')[1]+'" AS DATE))) THEN net_total ELSE NULL END)'
else:
query += 'COUNT(CASE WHEN fiscal_year = "'+to_fiscal_year+'" THEN name ELSE NULL END),SUM(CASE WHEN fiscal_year = "'+to_fiscal_year+'" THEN net_total ELSE NULL END),MIN(CASE WHEN fiscal_year = "'+to_fiscal_year+'" THEN net_total ELSE NULL END),MAX(CASE WHEN fiscal_year = "'+to_fiscal_year+'" THEN net_total ELSE NULL END),AVG(CASE WHEN fiscal_year = "'+to_fiscal_year+'" THEN net_total ELSE NULL END)'
list_range += 1
# Main Query
det = sql("SELECT %s from `tab%s` where %s" %(query,r[col_idx['ID']],condition))
# bifurcate all values and append them in list
total_no,total_amt,min_amt,max_amt,avg_amt = [],[],[],[],[]
count = 0
# append values to list
for i in range(list_range):
total_no.append(cstr(det and det[0][count] or 0))
total_amt.append(cstr(det and det[0][count+1] or 0))
min_amt.append(cstr(det and det[0][count+2] or 0))
max_amt.append(cstr(det and det[0][count+3] or 0))
avg_amt.append(cstr(det and det[0][count+4] or 0))
count += 5
for col in range(len(colnames)-1): # this would make all first row blank. just for look
r.append('')
out.append(r)
d = [['Total No',total_no],['Total Amount',total_amt],['Min Amount',min_amt],['Max Amount',max_amt],['Avg Amount',avg_amt]]
for des in range(5):
t_row = ['' for i in range(len(colnames))]
t_row[col_idx['Description']] = d[des][0]
for v in range(list_range):
t_row[col_idx[colnames[v+2]]] = flt(d[des][1][v])
out.append(t_row)

View File

@@ -0,0 +1 @@
SELECT DISTINCT name FROM tabDocType WHERE document_type="Transaction" AND ifnull(istable,0) = 0

View File

@@ -0,0 +1,37 @@
[
{
'add_col': None,
'add_cond': None,
'add_tab': None,
'columns': 'Profile\x01ID',
'creation': '2010-09-20 13:00:41',
'criteria_name': 'Yearly Transaction Summary',
'custom_query': None,
'description': None,
'dis_filters': None,
'disabled': None,
'doc_type': 'Profile',
'docstatus': 0,
'doctype': 'Search Criteria',
'filters': "{'DocType\x01Fiscal Year':'2009-2010','DocType\x01Company':'Alpha Company','DocType\x01Period':'Monthly'}",
'graph_series': None,
'graph_values': None,
'group_by': None,
'idx': None,
'modified': '2010-09-17 16:03:04',
'modified_by': 'Administrator',
'module': 'Analysis',
'name': 'yearly_transaction_summary',
'owner': 'Administrator',
'page_len': None,
'parent': None,
'parent_doc_type': None,
'parentfield': None,
'parenttype': None,
'report_script': None,
'server_script': None,
'sort_by': '`tabProfile`.`name`',
'sort_order': 'DESC',
'standard': 'Yes'
}
]