mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-22 22:49:19 +00:00
Sourced wnframework-modules from Google Code as erpnext
This commit is contained in:
253
analysis/Module Def/Analysis/Analysis.txt
Normal file
253
analysis/Module Def/Analysis/Analysis.txt
Normal file
@@ -0,0 +1,253 @@
|
||||
[
|
||||
{
|
||||
'_last_update': '1300959286',
|
||||
'creation': '2010-11-30 17:31:05',
|
||||
'disabled': 'No',
|
||||
'docstatus': 0,
|
||||
'doctype': u'Module Def',
|
||||
'doctype_list': None,
|
||||
'file_list': None,
|
||||
'idx': None,
|
||||
'is_hidden': 'No',
|
||||
'last_updated_date': '2010-12-02 09:25:40',
|
||||
'modified': '2011-03-24 15:28:54',
|
||||
'modified_by': 'Administrator',
|
||||
'module_desc': None,
|
||||
'module_icon': 'chart.png',
|
||||
'module_label': 'Analysis',
|
||||
'module_name': 'Analysis',
|
||||
'module_page': None,
|
||||
'module_seq': 10,
|
||||
'name': 'Analysis',
|
||||
'owner': 'Administrator',
|
||||
'parent': None,
|
||||
'parentfield': None,
|
||||
'parenttype': None,
|
||||
'trash_reason': None,
|
||||
'widget_code': None
|
||||
},
|
||||
{
|
||||
'click_function': None,
|
||||
'creation': '2011-03-24 12:00:50',
|
||||
'description': None,
|
||||
'display_name': None,
|
||||
'doc_name': 'Reports',
|
||||
'doc_type': 'Separator',
|
||||
'docstatus': 0,
|
||||
'doctype': 'Module Def Item',
|
||||
'fields': None,
|
||||
'hide': None,
|
||||
'icon': None,
|
||||
'idx': 1,
|
||||
'modified': '2011-03-24 15:28:54',
|
||||
'modified_by': 'Administrator',
|
||||
'name': '000003012',
|
||||
'owner': 'Administrator',
|
||||
'parent': 'Analysis',
|
||||
'parentfield': 'items',
|
||||
'parenttype': 'Module Def'
|
||||
},
|
||||
{
|
||||
'click_function': None,
|
||||
'creation': '2011-03-24 12:00:50',
|
||||
'description': None,
|
||||
'display_name': 'Yearly Transaction Summary',
|
||||
'doc_name': 'Profile',
|
||||
'doc_type': 'Reports',
|
||||
'docstatus': 0,
|
||||
'doctype': 'Module Def Item',
|
||||
'fields': None,
|
||||
'hide': None,
|
||||
'icon': None,
|
||||
'idx': 2,
|
||||
'modified': '2011-03-24 15:28:54',
|
||||
'modified_by': 'Administrator',
|
||||
'name': '000003014',
|
||||
'owner': 'Administrator',
|
||||
'parent': 'Analysis',
|
||||
'parentfield': 'items',
|
||||
'parenttype': 'Module Def'
|
||||
},
|
||||
{
|
||||
'click_function': None,
|
||||
'creation': '2010-11-30 17:31:05',
|
||||
'description': 'A quick glance at your work in progress and pipeline',
|
||||
'display_name': 'Work in Progress Monitor',
|
||||
'doc_name': 'WIP Monitor',
|
||||
'doc_type': 'Pages',
|
||||
'docstatus': 0,
|
||||
'doctype': 'Module Def Item',
|
||||
'fields': None,
|
||||
'hide': None,
|
||||
'icon': 'magnifier.gif',
|
||||
'idx': 3,
|
||||
'modified': '2011-03-24 15:28:54',
|
||||
'modified_by': 'Administrator',
|
||||
'name': 'MDI00063',
|
||||
'owner': 'Administrator',
|
||||
'parent': 'Analysis',
|
||||
'parentfield': 'items',
|
||||
'parenttype': 'Module Def'
|
||||
},
|
||||
{
|
||||
'click_function': None,
|
||||
'creation': '2011-03-24 12:00:50',
|
||||
'description': 'Analyze trend of sales, purchase and stock over any period',
|
||||
'display_name': 'Monthly Trend Analyzer',
|
||||
'doc_name': 'Profile',
|
||||
'doc_type': 'Reports',
|
||||
'docstatus': 0,
|
||||
'doctype': 'Module Def Item',
|
||||
'fields': None,
|
||||
'hide': None,
|
||||
'icon': 'chart_bar.gif',
|
||||
'idx': 4,
|
||||
'modified': '2011-03-24 15:28:54',
|
||||
'modified_by': 'Administrator',
|
||||
'name': '000003013',
|
||||
'owner': 'saumil@webnotestech.com',
|
||||
'parent': 'Analysis',
|
||||
'parentfield': 'items',
|
||||
'parenttype': 'Module Def'
|
||||
},
|
||||
{
|
||||
'click_function': None,
|
||||
'creation': '2011-03-24 12:00:50',
|
||||
'description': None,
|
||||
'display_name': None,
|
||||
'doc_name': 'Reports',
|
||||
'doc_type': 'Separator',
|
||||
'docstatus': 0,
|
||||
'doctype': 'Module Def Item',
|
||||
'fields': None,
|
||||
'hide': None,
|
||||
'icon': None,
|
||||
'idx': 1,
|
||||
'modified': '2011-03-24 15:28:54',
|
||||
'modified_by': 'Administrator',
|
||||
'name': '000003012',
|
||||
'owner': 'Administrator',
|
||||
'parent': 'Analysis',
|
||||
'parentfield': 'items',
|
||||
'parenttype': 'Module Def'
|
||||
},
|
||||
{
|
||||
'click_function': None,
|
||||
'creation': '2011-03-24 12:00:50',
|
||||
'description': None,
|
||||
'display_name': 'Yearly Transaction Summary',
|
||||
'doc_name': 'Profile',
|
||||
'doc_type': 'Reports',
|
||||
'docstatus': 0,
|
||||
'doctype': 'Module Def Item',
|
||||
'fields': None,
|
||||
'hide': None,
|
||||
'icon': None,
|
||||
'idx': 2,
|
||||
'modified': '2011-03-24 15:28:54',
|
||||
'modified_by': 'Administrator',
|
||||
'name': '000003014',
|
||||
'owner': 'Administrator',
|
||||
'parent': 'Analysis',
|
||||
'parentfield': 'items',
|
||||
'parenttype': 'Module Def'
|
||||
},
|
||||
{
|
||||
'click_function': None,
|
||||
'creation': '2010-11-30 17:31:05',
|
||||
'description': 'A quick glance at your work in progress and pipeline',
|
||||
'display_name': 'Work in Progress Monitor',
|
||||
'doc_name': 'WIP Monitor',
|
||||
'doc_type': 'Pages',
|
||||
'docstatus': 0,
|
||||
'doctype': 'Module Def Item',
|
||||
'fields': None,
|
||||
'hide': None,
|
||||
'icon': 'magnifier.gif',
|
||||
'idx': 3,
|
||||
'modified': '2011-03-24 15:28:54',
|
||||
'modified_by': 'Administrator',
|
||||
'name': 'MDI00063',
|
||||
'owner': 'Administrator',
|
||||
'parent': 'Analysis',
|
||||
'parentfield': 'items',
|
||||
'parenttype': 'Module Def'
|
||||
},
|
||||
{
|
||||
'click_function': None,
|
||||
'creation': '2011-03-24 12:00:50',
|
||||
'description': 'Analyze trend of sales, purchase and stock over any period',
|
||||
'display_name': 'Monthly Trend Analyzer',
|
||||
'doc_name': 'Profile',
|
||||
'doc_type': 'Reports',
|
||||
'docstatus': 0,
|
||||
'doctype': 'Module Def Item',
|
||||
'fields': None,
|
||||
'hide': None,
|
||||
'icon': 'chart_bar.gif',
|
||||
'idx': 4,
|
||||
'modified': '2011-03-24 15:28:54',
|
||||
'modified_by': 'Administrator',
|
||||
'name': '000003013',
|
||||
'owner': 'saumil@webnotestech.com',
|
||||
'parent': 'Analysis',
|
||||
'parentfield': 'items',
|
||||
'parenttype': 'Module Def'
|
||||
},
|
||||
{
|
||||
'creation': '2010-11-30 17:31:05',
|
||||
'docstatus': 0,
|
||||
'doctype': 'Module Def Role',
|
||||
'idx': 1,
|
||||
'modified': '2011-03-24 15:28:54',
|
||||
'modified_by': 'Administrator',
|
||||
'name': 'MDR00004',
|
||||
'owner': 'saumil@webnotestech.com',
|
||||
'parent': 'Analysis',
|
||||
'parentfield': 'roles',
|
||||
'parenttype': 'Module Def',
|
||||
'role': 'Sales Manager'
|
||||
},
|
||||
{
|
||||
'creation': '2010-11-30 17:31:05',
|
||||
'docstatus': 0,
|
||||
'doctype': 'Module Def Role',
|
||||
'idx': 2,
|
||||
'modified': '2011-03-24 15:28:54',
|
||||
'modified_by': 'Administrator',
|
||||
'name': 'MDR00005',
|
||||
'owner': 'saumil@webnotestech.com',
|
||||
'parent': 'Analysis',
|
||||
'parentfield': 'roles',
|
||||
'parenttype': 'Module Def',
|
||||
'role': 'Purchase Manager'
|
||||
},
|
||||
{
|
||||
'creation': '2010-11-30 17:31:05',
|
||||
'docstatus': 0,
|
||||
'doctype': 'Module Def Role',
|
||||
'idx': 3,
|
||||
'modified': '2011-03-24 15:28:54',
|
||||
'modified_by': 'Administrator',
|
||||
'name': 'MDR00006',
|
||||
'owner': 'saumil@webnotestech.com',
|
||||
'parent': 'Analysis',
|
||||
'parentfield': 'roles',
|
||||
'parenttype': 'Module Def',
|
||||
'role': 'Material Manager'
|
||||
},
|
||||
{
|
||||
'creation': '2010-11-30 17:31:05',
|
||||
'docstatus': 0,
|
||||
'doctype': 'Module Def Role',
|
||||
'idx': 4,
|
||||
'modified': '2011-03-24 15:28:54',
|
||||
'modified_by': 'Administrator',
|
||||
'name': 'MDR00007',
|
||||
'owner': 'saumil@webnotestech.com',
|
||||
'parent': 'Analysis',
|
||||
'parentfield': 'roles',
|
||||
'parenttype': 'Module Def',
|
||||
'role': 'Accounts Manager'
|
||||
}
|
||||
]
|
||||
0
analysis/__init__.py
Normal file
0
analysis/__init__.py
Normal file
0
analysis/doctype/__init__.py
Normal file
0
analysis/doctype/__init__.py
Normal file
0
analysis/doctype/mis_control/__init__.py
Normal file
0
analysis/doctype/mis_control/__init__.py
Normal file
403
analysis/doctype/mis_control/mis_control.py
Normal file
403
analysis/doctype/mis_control/mis_control.py
Normal file
@@ -0,0 +1,403 @@
|
||||
# Please edit this list and import only required elements
|
||||
import webnotes
|
||||
|
||||
from webnotes.utils import add_days, add_months, add_years, cint, cstr, date_diff, default_fields, flt, fmt_money, formatdate, generate_hash, getTraceback, get_defaults, get_first_day, get_last_day, getdate, has_common, month_name, now, nowdate, replace_newlines, sendmail, set_default, str_esc_quote, user_format, validate_email_add
|
||||
from webnotes.model import db_exists
|
||||
from webnotes.model.doc import Document, addchild, removechild, getchildren, make_autoname, SuperDocType
|
||||
from webnotes.model.doclist import getlist, copy_doclist
|
||||
from webnotes.model.code import get_obj, get_server_obj, run_server_obj, updatedb, check_syntax
|
||||
from webnotes import session, form, is_testing, msgprint, errprint
|
||||
|
||||
set = webnotes.conn.set
|
||||
sql = webnotes.conn.sql
|
||||
get_value = webnotes.conn.get_value
|
||||
in_transaction = webnotes.conn.in_transaction
|
||||
convert_to_lists = webnotes.conn.convert_to_lists
|
||||
|
||||
# -----------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
class DocType:
|
||||
def __init__(self, doc, doclist):
|
||||
self.doc = doc
|
||||
self.doclist = doclist
|
||||
self.account_list = []
|
||||
self.ac_details = {} # key: account id, values: debit_or_credit, lft, rgt
|
||||
|
||||
self.roles = webnotes.user.get_roles()
|
||||
|
||||
self.period_list = []
|
||||
self.period_start_date = {}
|
||||
self.period_end_date = {}
|
||||
|
||||
self.fs_list = []
|
||||
self.root_bal = []
|
||||
self.flag = 0
|
||||
|
||||
# Get defaults on load of MIS, MIS - Comparison Report and Financial statements
|
||||
# ----------------------------------------------------
|
||||
def get_comp(self):
|
||||
ret = {}
|
||||
type = []
|
||||
comp = []
|
||||
# ------ get period -----------
|
||||
ret['period'] = ['Annual','Half Yearly','Quarterly','Monthly']
|
||||
|
||||
# ---- get companies ---------
|
||||
res = sql("select name from `tabCompany`")
|
||||
comp.append('All')
|
||||
for r in res:
|
||||
comp.append(r[0])
|
||||
#comp.append(r[0] for r in res)
|
||||
ret['company'] = comp
|
||||
|
||||
#--- to get fiscal year and start_date of that fiscal year -----
|
||||
res = sql("select name, year_start_date from `tabFiscal Year`")
|
||||
ret['fiscal_year'] = [r[0] for r in res]
|
||||
ret['start_dates'] = {}
|
||||
for r in res:
|
||||
ret['start_dates'][r[0]] = str(r[1])
|
||||
|
||||
#--- from month and to month (for MIS - Comparison Report) -------
|
||||
month_list = ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec']
|
||||
fiscal_start_month = sql("select MONTH(year_start_date) from `tabFiscal Year` where name = %s",(get_defaults()['fiscal_year']))
|
||||
fiscal_start_month = fiscal_start_month and fiscal_start_month[0][0] or 1
|
||||
mon = ['']
|
||||
for i in range(fiscal_start_month,13): mon.append(month_list[i-1])
|
||||
for i in range(0,fiscal_start_month-1): mon.append(month_list[i])
|
||||
ret['month'] = mon
|
||||
|
||||
# ------------------------ get MIS Type on basis of roles of session user ------------------------------------------
|
||||
if has_common(self.roles, ['Sales Manager']):
|
||||
type.append('Sales')
|
||||
if has_common(self.roles, ['Purchase Manager']):
|
||||
type.append('Purchase')
|
||||
ret['type'] = type
|
||||
return ret
|
||||
|
||||
# Gets Transactions type and Group By options based on module
|
||||
#------------------------------------------------------------------
|
||||
def get_trans_group(self,module):
|
||||
ret = {}
|
||||
st,group = [],[]
|
||||
if module == 'Sales':
|
||||
st = ['Quotation','Sales Order','Delivery Note','Receivable Voucher']
|
||||
group = ['Item','Item Group','Customer','Customer Group','Cost Center']
|
||||
elif module == 'Purchase':
|
||||
st = ['Purchase Order','Purchase Receipt','Payable Voucher']
|
||||
group = ['Item','Item Group','Supplier','Supplier Type']
|
||||
|
||||
ret['stmt_type'] = st
|
||||
ret['group_by'] = group
|
||||
|
||||
return ret
|
||||
|
||||
# Get Days based on month (for MIS Comparison Report)
|
||||
# --------------------------------------------------------
|
||||
def get_days(self,month):
|
||||
days = []
|
||||
ret = {}
|
||||
if month == 'Jan' or month == 'Mar' or month == 'May' or month == 'Jul' or month == 'Aug' or month == 'Oct' or month == 'Dec':
|
||||
for i in range(1,32):
|
||||
days.append(i)
|
||||
elif month == 'Apr' or month == 'Jun' or month == 'Sep' or month == 'Nov':
|
||||
for i in range(1,31):
|
||||
days.append(i)
|
||||
elif month == 'Feb':
|
||||
for i in range(1,29):
|
||||
days.append(i)
|
||||
ret['days'] = days
|
||||
return ret
|
||||
|
||||
# Get from date and to date based on fiscal year (for in summary - comparison report)
|
||||
# -----------------------------------------------------------------------------------------------------
|
||||
def dates(self,fiscal_year,from_date,to_date):
|
||||
import datetime
|
||||
ret = ''
|
||||
start_date = cstr(sql("select year_start_date from `tabFiscal Year` where name = %s",fiscal_year)[0][0])
|
||||
st_mon = cint(from_date.split('-')[1])
|
||||
ed_mon = cint(to_date.split('-')[1])
|
||||
st_day = cint(from_date.split('-')[2])
|
||||
ed_day = cint(to_date.split('-')[2])
|
||||
fiscal_start_month = cint(start_date.split('-')[1])
|
||||
next_fiscal_year = cint(start_date.split('-')[0]) + 1
|
||||
current_year = ''
|
||||
next_year = ''
|
||||
|
||||
#CASE - 1 : Jan - Mar (Valid)
|
||||
if st_mon < fiscal_start_month and ed_mon < fiscal_start_month:
|
||||
current_year = cint(start_date.split('-')[0]) + 1
|
||||
next_year = cint(start_date.split('-')[0]) + 1
|
||||
|
||||
# Case - 2 : Apr - Dec (Valid)
|
||||
elif st_mon >= fiscal_start_month and ed_mon <= 12 and ed_mon >= fiscal_start_month:
|
||||
current_year = cint(start_date.split('-')[0])
|
||||
next_year = cint(start_date.split('-')[0])
|
||||
|
||||
# Case 3 : Jan - May (Invalid)
|
||||
elif st_mon < fiscal_start_month and ed_mon >= fiscal_start_month:
|
||||
current_year = cint(start_date.split('-')[0]) + 1
|
||||
next_year = cint(start_date.split('-')[0]) + 2
|
||||
|
||||
# check whether from date is within fiscal year
|
||||
if datetime.date(current_year, st_mon, st_day) >= datetime.date(cint(start_date.split('-')[0]), cint(start_date.split('-')[1]), cint(start_date.split('-')[2])) and datetime.date(cint(current_year), cint(st_mon), cint(st_day)) < datetime.date((cint(start_date.split('-')[0])+1), cint(start_date.split('-')[1]), cint(start_date.split('-')[2])):
|
||||
begin_date = cstr(current_year)+"-"+cstr(st_mon)+"-"+cstr(st_day)
|
||||
else:
|
||||
msgprint("Please enter appropriate from date.")
|
||||
raise Exception
|
||||
# check whether to date is within fiscal year
|
||||
if datetime.date(next_year, ed_mon, ed_day) >= datetime.date(cint(start_date.split('-')[0]), cint(start_date.split('-')[1]), cint(start_date.split('-')[2])) and datetime.date(cint(next_year), cint(ed_mon), cint(ed_day)) < datetime.date(cint(start_date.split('-')[0])+1, cint(start_date.split('-')[1]), cint(start_date.split('-')[2])):
|
||||
end_date = cstr(next_year)+"-"+cstr(ed_mon)+"-"+cstr(ed_day)
|
||||
else:
|
||||
msgprint("Please enter appropriate to date.")
|
||||
raise Exception
|
||||
ret = begin_date+'~~~'+end_date
|
||||
return ret
|
||||
|
||||
# Get MIS Totals
|
||||
# ---------------
|
||||
def get_totals(self, args):
|
||||
args = eval(args)
|
||||
#msgprint(args)
|
||||
totals = sql("SELECT %s FROM %s WHERE %s %s %s %s" %(cstr(args['query_val']), cstr(args['tables']), cstr(args['company']), cstr(args['cond']), cstr(args['add_cond']), cstr(args['fil_cond'])), as_dict = 1)[0]
|
||||
#msgprint(totals)
|
||||
tot_keys = totals.keys()
|
||||
# return in flt because JSON doesn't accept Decimal
|
||||
for d in tot_keys:
|
||||
totals[d] = flt(totals[d])
|
||||
return totals
|
||||
|
||||
# Get Statement
|
||||
# -------------
|
||||
|
||||
def get_statement(self, arg):
|
||||
self.return_data = []
|
||||
|
||||
# define periods
|
||||
arg = eval(arg)
|
||||
pl = ''
|
||||
|
||||
self.define_periods(arg['year'], arg['period']) # declares 1.period_list i.e. (['Jan','Feb','Mar'...] or ['Q1','Q2'...] or ['FY2009-2010']) based on period
|
||||
# 2.period_start_date dict {'Jan':'01-01-2009'...}
|
||||
# 3.period_start_date dict {'Jan':'31-01-2009'...}
|
||||
self.return_data.append([4,'']+self.period_list)
|
||||
|
||||
|
||||
if arg['statement'] == 'Balance Sheet': pl = 'No'
|
||||
if arg['statement'] == 'Profit & Loss': pl = 'Yes'
|
||||
|
||||
self.get_children('',0,pl,arg['company'], arg['year'])
|
||||
|
||||
#self.balance_pl_statement(acct, arg['statement'])
|
||||
#msgprint(self.return_data)
|
||||
return self.return_data
|
||||
|
||||
# Get Children
|
||||
# ------------
|
||||
def get_children(self, parent_account, level, pl, company, fy):
|
||||
cl = sql("select distinct account_name, name, debit_or_credit, lft, rgt from `tabAccount` where ifnull(parent_account, '') = %s and ifnull(is_pl_account, 'No')=%s and company=%s order by name asc", (parent_account, pl, company))
|
||||
level0_diff = [0 for p in self.period_list]
|
||||
if pl=='Yes' and level==0: # switch for income & expenses
|
||||
cl = [c for c in cl]
|
||||
cl.reverse()
|
||||
if cl:
|
||||
for c in cl:
|
||||
self.ac_details[c[1]] = [c[2], c[3], c[4]]
|
||||
bal_list = self.get_period_balance(c[1], level, pl, company, fy)
|
||||
if level==0: # top level - put balances as totals
|
||||
self.return_data.append([level, c[0]] + ['' for b in bal_list])
|
||||
totals = bal_list
|
||||
for i in range(len(totals)): # make totals
|
||||
if c[2]=='Credit':
|
||||
level0_diff[i] += flt(totals[i])
|
||||
else:
|
||||
level0_diff[i] -= flt(totals[i])
|
||||
else:
|
||||
self.return_data.append([level, c[0]]+bal_list)
|
||||
|
||||
if level < 2:
|
||||
self.get_children(c[1], level+1, pl, company, fy)
|
||||
|
||||
# make totals - for top level
|
||||
# ---------------------------
|
||||
if level==0:
|
||||
# add rows for profit / loss in B/S
|
||||
if pl=='No':
|
||||
if c[2]=='Credit':
|
||||
self.return_data.append([1, 'Total Liabilities'] + totals)
|
||||
level0_diff = [-i for i in level0_diff] # convert to debit
|
||||
self.return_data.append([5, 'Profit/Loss (Provisional)'] + level0_diff)
|
||||
for i in range(len(totals)): # make totals
|
||||
level0_diff[i] = flt(totals[i]) + level0_diff[i]
|
||||
self.return_data.append([4, 'Total '+c[0]] + level0_diff)
|
||||
else:
|
||||
self.return_data.append([4, 'Total '+c[0]] + totals)
|
||||
|
||||
# add rows for profit / loss in P/L
|
||||
else:
|
||||
if c[2]=='Debit':
|
||||
self.return_data.append([1, 'Total Expenses (before Profit)'] + totals)
|
||||
self.return_data.append([5, 'Profit/Loss (Provisional)'] + level0_diff)
|
||||
for i in range(len(totals)): # make totals
|
||||
level0_diff[i] = flt(totals[i]) + level0_diff[i]
|
||||
self.return_data.append([4, 'Total '+c[0]] + level0_diff)
|
||||
else:
|
||||
self.return_data.append([4, 'Total '+c[0]] + totals)
|
||||
|
||||
# Define Periods
|
||||
# --------------
|
||||
|
||||
def define_periods(self, year, period):
|
||||
|
||||
# get year start date
|
||||
ysd = sql("select year_start_date from `tabFiscal Year` where name=%s", year)
|
||||
ysd = ysd and ysd[0][0] or ''
|
||||
|
||||
self.ysd = ysd
|
||||
|
||||
# year
|
||||
if period == 'Annual':
|
||||
pn = 'FY'+year
|
||||
self.period_list.append(pn)
|
||||
self.period_start_date[pn] = ysd
|
||||
self.period_end_date[pn] = get_last_day(get_first_day(ysd,0,11))
|
||||
|
||||
# quarter
|
||||
if period == 'Quarterly':
|
||||
for i in range(4):
|
||||
pn = 'Q'+str(i+1)
|
||||
self.period_list.append(pn)
|
||||
|
||||
self.period_start_date[pn] = get_first_day(ysd,0,i*3)
|
||||
self.period_end_date[pn] = get_last_day(get_first_day(ysd,0,((i+1)*3)-1))
|
||||
|
||||
# month
|
||||
if period == 'Monthly':
|
||||
mlist = ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec']
|
||||
for i in range(12):
|
||||
fd = get_first_day(ysd,0,i)
|
||||
pn = mlist[fd.month-1]
|
||||
self.period_list.append(pn)
|
||||
|
||||
self.period_start_date[pn] = fd
|
||||
self.period_end_date[pn] = get_last_day(fd)
|
||||
|
||||
# Get Balance For A Period
|
||||
# ------------------------
|
||||
|
||||
def get_period_balance(self, acc, level, pl, company, fy):
|
||||
debit_or_credit, lft, rgt = self.ac_details[acc]
|
||||
ret = []
|
||||
for p in self.period_list:
|
||||
sd, ed = self.period_start_date[p].strftime('%Y-%m-%d'), self.period_end_date[p].strftime('%Y-%m-%d')
|
||||
cond = "and t1.voucher_type != 'Period Closing Voucher'"
|
||||
if pl=='No':
|
||||
sd = self.ysd.strftime('%Y-%m-%d')
|
||||
cond = ""
|
||||
|
||||
bal = sql("select SUM(t1.debit), SUM(t1.credit) from `tabGL Entry` t1, `tabAccount` t2 WHERE t1.posting_date >= '%s' AND t1.posting_date <= '%s' AND t1.company = '%s' AND t1.account = t2.name AND t2.lft >= %s AND t2.rgt <= %s and ifnull(is_opening,'No') = 'No' %s" % (sd,ed,company,lft,rgt, cond))
|
||||
|
||||
|
||||
bal = bal and (flt(bal[0][0]) - flt(bal[0][1])) or 0
|
||||
if debit_or_credit == 'Credit' and bal:
|
||||
bal = -bal
|
||||
if pl=='No':
|
||||
op = sql("select opening from `tabAccount Balance` where account=%s and period=%s", (acc, fy))
|
||||
op = op and op[0][0] or 0
|
||||
bal += flt(op)
|
||||
|
||||
ret.append(bal)
|
||||
return ret
|
||||
|
||||
# Get Dashboard Amounts
|
||||
# ---------------------
|
||||
|
||||
def get_balance(self, acc, sd, ed, company, fy):
|
||||
a = sql("select account_name, name, debit_or_credit, lft, rgt, is_pl_account from `tabAccount` where account_name=%s and company=%s", (acc, company), as_dict=1)
|
||||
if a:
|
||||
a = a[0]
|
||||
bal = sql("select SUM(IFNULL(t1.debit,0)), SUM(IFNULL(t1.credit,0)) from `tabGL Entry` t1, `tabAccount` t2 WHERE t1.posting_date >= %s AND t1.posting_date <= %s AND t1.account = t2.name AND t2.lft >= %s AND t2.rgt <= %s and ifnull(is_opening, 'No') = 'No'", (sd,ed,a['lft'],a['rgt']))
|
||||
if a['debit_or_credit']=='Debit':
|
||||
bal = flt(flt(bal[0][0]) - flt(bal[0][1]))
|
||||
else:
|
||||
bal = flt(flt(bal[0][1]) - flt(bal[0][0]))
|
||||
|
||||
if a['is_pl_account']=='No':
|
||||
op = sql("select opening from `tabAccount Balance` where account=%s and period=%s", (acc, fy))
|
||||
op = op and op[0][0] or 0
|
||||
bal += flt(op)
|
||||
|
||||
return flt(bal)
|
||||
|
||||
else:
|
||||
msgprint("Did not find %s for %s" % (acc, company))
|
||||
return 0
|
||||
|
||||
def get_cur_balance(self, acc, company):
|
||||
bal = sql("select IFNULL(t1.balance,0) from `tabAccount Balance` t1, `tabAccount` t2 where t1.account = %s and t1.period=%s and t1.account = t2.name and t2.company=%s", (acc, self.fiscal_year, company))
|
||||
return bal and flt(bal[0][0]) or 0
|
||||
|
||||
def get_top_5_cust(self, company):
|
||||
rec_grp = sql("select receivables_group from tabCompany where name=%s", company)
|
||||
if rec_grp:
|
||||
pa_lft_rgt = sql("select lft, rgt from tabAccount where name=%s and company=%s", (rec_grp[0][0], company))[0]
|
||||
return sql("select t1.account_name, SUM(t2.debit) from tabAccount t1, `tabGL Entry` t2 where t1.lft > %s and t1.rgt < %s and t2.account = t1.name GROUP BY t1.name ORDER BY SUM(t2.debit) desc limit 5", (pa_lft_rgt[0], pa_lft_rgt[1]))
|
||||
else:
|
||||
return []
|
||||
|
||||
def get_top_5_exp(self, company):
|
||||
a = sql("select distinct account_name, name, debit_or_credit, lft, rgt from `tabAccount` where account_name=%s and company=%s", ('Expenses', company), as_dict=1)[0]
|
||||
return sql("select t1.account_name, SUM(t2.debit) from tabAccount t1, `tabGL Entry` t2 where t1.lft>%s and t1.rgt<%s and t1.group_or_ledger = 'Ledger' and t2.account = t1.name and t2.voucher_type != 'Period Closing Voucher' GROUP BY t1.name ORDER BY SUM(t2.debit) desc limit 5", (a['lft'],a['rgt']))
|
||||
|
||||
def bl(self, acc, company):
|
||||
dt = getdate(nowdate())
|
||||
|
||||
r = []
|
||||
# cur
|
||||
r.append(self.get_cur_balance(acc, company))
|
||||
# this month
|
||||
r.append(self.get_balance(acc, get_first_day(dt), get_last_day(dt), company, self.fiscal_year))
|
||||
# last month
|
||||
r.append(self.get_balance(acc, get_first_day(dt,0,-1), get_last_day(get_first_day(dt,0,-1)), company, self.fiscal_year))
|
||||
return r
|
||||
|
||||
def bl_bs(self, acc, company, sd):
|
||||
dt = getdate(nowdate())
|
||||
r = []
|
||||
# cur
|
||||
r.append(self.get_cur_balance(acc, company))
|
||||
# last month
|
||||
r.append(self.get_balance(acc, sd, get_last_day(get_first_day(dt,0,-1)), company, self.fiscal_year))
|
||||
# opening
|
||||
r.append(self.get_balance(acc, sd, sd, company, self.fiscal_year))
|
||||
return r
|
||||
|
||||
def get_dashboard_values(self, arg=''):
|
||||
d = get_defaults()
|
||||
self.fiscal_year = d['fiscal_year']
|
||||
if arg:
|
||||
company = arg
|
||||
else:
|
||||
company = d['company']
|
||||
|
||||
r = {}
|
||||
r['Income'] = self.bl('Income', company)
|
||||
r['Expenses'] = self.bl('Expenses', company)
|
||||
|
||||
r['Profit'] = []
|
||||
for i in range(3):
|
||||
r['Profit'].append(r['Income'][i] - r['Expenses'][i])
|
||||
|
||||
r['Current Assets'] = self.bl_bs('Current Assets', company, getdate(d['year_start_date']))
|
||||
r['Current Liabilities'] = self.bl_bs('Current Liabilities', company, getdate(d['year_start_date']))
|
||||
|
||||
r['Working Capital'] = []
|
||||
for i in range(3):
|
||||
r['Working Capital'].append(r['Current Assets'][i] - r['Current Liabilities'][i])
|
||||
|
||||
r['Bank Accounts'] = self.bl_bs('Bank Accounts', company, getdate(d['year_start_date']))
|
||||
|
||||
r['Top Customers'] = convert_to_lists(self.get_top_5_cust(company))
|
||||
r['Top Expenses'] = convert_to_lists(self.get_top_5_exp(company))
|
||||
|
||||
return r
|
||||
1
analysis/doctype/mis_control/mis_control.txt
Normal file
1
analysis/doctype/mis_control/mis_control.txt
Normal file
@@ -0,0 +1 @@
|
||||
[{'section_style': 'Simple', 'is_transaction_doc': None, 'creation': '2009-03-12 12:09:21', 'search_fields': None, 'module': 'Analysis', 'doctype': 'DocType', 'change_log': None, 'print_outline': '', 'owner': 'Administrator', 'in_dialog': None, 'in_create': None, 'read_only': None, 'allow_email': None, 'dt_template': None, 'hide_heading': None, 'issingle': 1, 'allow_rename': None, 'smallicon': '', 'allow_attach': None, 'show_in_menu': 0, 'max_attachments': None, 'version': 124, 'menu_index': None, 'docstatus': 0, 'allow_copy': None, 'istable': None, 'description': None, 'parent': None, 'server_code': '', 'allow_trash': None, 'allow_print': None, 'autoname': None, 'client_script_core': None, 'client_string': None, 'use_template': None, 'modified_by': 'Administrator', 'document_type': '', 'name': 'MIS Control', 'idx': None, 'hide_toolbar': None, 'colour': 'White:FFF', 'client_script': '', 'modified': '2010-10-25 17:20:04', 'server_code_error': ' ', 'name_case': '', 'parenttype': None, 'read_only_onload': None, 'server_code_core': None, 'server_code_compiled': None, 'parent_node': None, 'parentfield': None}]
|
||||
0
analysis/doctype/ta_control/__init__.py
Executable file
0
analysis/doctype/ta_control/__init__.py
Executable file
107
analysis/doctype/ta_control/ta_control.py
Executable file
107
analysis/doctype/ta_control/ta_control.py
Executable file
@@ -0,0 +1,107 @@
|
||||
# Please edit this list and import only required elements
|
||||
import webnotes
|
||||
|
||||
from webnotes.utils import add_days, add_months, add_years, cint, cstr, date_diff, default_fields, flt, fmt_money, formatdate, generate_hash, getTraceback, get_defaults, get_first_day, get_last_day, getdate, has_common, month_name, now, nowdate, replace_newlines, sendmail, set_default, str_esc_quote, user_format, validate_email_add
|
||||
from webnotes.model import db_exists
|
||||
from webnotes.model.doc import Document, addchild, removechild, getchildren, make_autoname, SuperDocType
|
||||
from webnotes.model.doclist import getlist, copy_doclist
|
||||
from webnotes.model.code import get_obj, get_server_obj, run_server_obj, updatedb, check_syntax
|
||||
from webnotes import session, form, is_testing, msgprint, errprint
|
||||
|
||||
set = webnotes.conn.set
|
||||
sql = webnotes.conn.sql
|
||||
get_value = webnotes.conn.get_value
|
||||
in_transaction = webnotes.conn.in_transaction
|
||||
convert_to_lists = webnotes.conn.convert_to_lists
|
||||
|
||||
# -----------------------------------------------------------------------------------------
|
||||
|
||||
class DocType:
|
||||
def __init__(self, d, dl):
|
||||
self.doc, self.doclist = d, dl
|
||||
|
||||
|
||||
# Define Globals
|
||||
# ---------------
|
||||
def define_globals(self, trans, fiscal_year):
|
||||
self.month_name = ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec']
|
||||
|
||||
if trans == 'Purchase Receipt' or trans == 'Delivery Note' or trans == 'Payable Voucher' or trans == 'Receivable Voucher':
|
||||
self.trans_date = 'posting_date'
|
||||
else:
|
||||
self.trans_date = 'transaction_date'
|
||||
|
||||
ysd = sql("select year_start_date from `tabFiscal Year` where name = %s",fiscal_year)[0][0]
|
||||
self.year_start_date = ysd.strftime('%Y-%m-%d')
|
||||
self.start_month = cint(self.year_start_date.split('-')[1])
|
||||
|
||||
|
||||
# Get Column Names and Query for Annual Trend
|
||||
# ---------------------------------------------
|
||||
def get_annual_trend_details(self, fiscal_year):
|
||||
col_names = [fiscal_year+' (Qty)', fiscal_year+' (Amt)']
|
||||
query_val = 'SUM(t2.qty) ,SUM(t2.amount),'
|
||||
return col_names, query_val
|
||||
|
||||
|
||||
# Get Column Names and Query for Half Yearly Trend
|
||||
# --------------------------------------------------
|
||||
def get_half_yearly_trend_details(self):
|
||||
first_half_start = self.year_start_date
|
||||
first_half_end = add_days(add_months(first_half_start,6),-1)
|
||||
second_half_start = add_days(first_half_end,1)
|
||||
second_half_end = add_days(add_months(second_half_start,6),-1)
|
||||
|
||||
col_names = ['First Half (Qty)', 'First Half (Amt)', 'Second Half (Qty)', 'Second Half (Amt)']
|
||||
|
||||
query_val = 'SUM(CASE WHEN t1.'+self.trans_date+' BETWEEN "'+first_half_start+'" AND "'+first_half_end+'" THEN t2.qty ELSE NULL END), SUM(CASE WHEN t1.'+self.trans_date+' BETWEEN "'+first_half_start+'" AND "'+first_half_end+'" THEN t2.amount ELSE NULL END), SUM(CASE WHEN t1.'+self.trans_date+' BETWEEN "'+second_half_start+'" AND "'+second_half_end+'" THEN t2.qty ELSE NULL END), SUM(CASE WHEN t1.'+self.trans_date+' BETWEEN "'+second_half_start+'" AND "'+second_half_end+'" THEN t2.amount ELSE NULL END),'
|
||||
|
||||
return col_names, query_val
|
||||
|
||||
|
||||
# Get Column Names and Query for Quarterly Trend
|
||||
# ------------------------------------------------
|
||||
def get_quarterly_trend_details(self):
|
||||
first_qsd, second_qsd, third_qsd, fourth_qsd = self.year_start_date, add_months(self.year_start_date,3), add_months(self.year_start_date,6), add_months(self.year_start_date,9)
|
||||
|
||||
first_qed, second_qed, third_qed, fourth_qed = add_days(add_months(first_qsd,3),-1), add_days(add_months(second_qsd,3),-1), add_days(add_months(third_qsd,3),-1), add_days(add_months(fourth_qsd,3),-1)
|
||||
|
||||
col_names = ['Q1 (Qty)','Q1 (Amt)','Q2 (Qty)','Q2 (Amt)','Q3 (Qty)','Q3 (Amt)','Q4 (Qty)','Q4 (Amt)']
|
||||
query_val = ''
|
||||
bet_dates = [[first_qsd,first_qed],[second_qsd,second_qed],[third_qsd,third_qed],[fourth_qsd,fourth_qed]]
|
||||
|
||||
for d in bet_dates:
|
||||
query_val += 'SUM(CASE WHEN t1.'+self.trans_date+' BETWEEN "'+d[0]+'" AND "'+d[1]+'" THEN t2.qty ELSE NULL END), SUM(CASE WHEN t1.'+self.trans_date+' BETWEEN "'+d[0]+'" AND "'+d[1]+'" THEN t2.amount ELSE NULL END),'
|
||||
|
||||
return col_names, query_val
|
||||
|
||||
|
||||
# Get Column Names and Query for Monthly Trend
|
||||
# -----------------------------------------------
|
||||
def get_monthly_trend_details(self):
|
||||
col_names, query_val = [], ''
|
||||
for i in range(self.start_month-1, len(self.month_name)):
|
||||
col_names.append(self.month_name[i]+' (Qty)')
|
||||
col_names.append(self.month_name[i]+' (Amt)')
|
||||
query_val += 'SUM(CASE WHEN MONTH(t1.'+self.trans_date+') = '+cstr(i+1)+' THEN t2.qty ELSE NULL END), SUM(CASE WHEN MONTH(t1.'+self.trans_date+') = '+cstr(i+1)+' THEN t2.amount ELSE NULL END),'
|
||||
|
||||
for i in range(0, self.start_month-1):
|
||||
col_names.append(self.month_name[i]+' (Qty)')
|
||||
col_names.append(self.month_name[i]+' (Amt)')
|
||||
query_val += 'SUM(CASE WHEN MONTH(t1.'+self.trans_date+') = '+cstr(i+1)+' THEN t2.qty ELSE NULL END), SUM(CASE WHEN MONTH(t1.'+self.trans_date+') = '+cstr(i+1)+' THEN t2.amount ELSE NULL END),'
|
||||
|
||||
return col_names, query_val
|
||||
|
||||
|
||||
# Get Single Year Trend's Query and Columns
|
||||
# -------------------------------------------
|
||||
def get_single_year_query_value(self, fiscal_year, period, trans, trans_det):
|
||||
self.define_globals(trans, fiscal_year)
|
||||
if period == 'Annual':
|
||||
return self.get_annual_trend_details(fiscal_year)
|
||||
elif period == 'Half Yearly':
|
||||
return self.get_half_yearly_trend_details()
|
||||
elif period == 'Quarterly':
|
||||
return self.get_quarterly_trend_details()
|
||||
elif period == 'Monthly':
|
||||
return self.get_monthly_trend_details()
|
||||
1
analysis/doctype/ta_control/ta_control.txt
Executable file
1
analysis/doctype/ta_control/ta_control.txt
Executable file
@@ -0,0 +1 @@
|
||||
[{'section_style': 'Simple', 'is_transaction_doc': None, 'creation': '2011-01-07 14:56:35', 'search_fields': None, 'module': 'Analysis', 'doctype': 'DocType', 'change_log': None, 'print_outline': None, 'owner': 'Administrator', 'in_dialog': None, 'in_create': 1, 'read_only': 1, 'allow_email': None, 'dt_template': None, 'hide_heading': None, 'issingle': 1, 'allow_rename': None, 'smallicon': None, 'allow_attach': None, 'show_in_menu': None, 'max_attachments': None, 'version': 1, 'menu_index': None, 'docstatus': 0, 'allow_copy': None, 'istable': None, 'description': None, 'parent': None, 'server_code': None, 'allow_trash': None, 'allow_print': None, 'autoname': None, 'client_script_core': None, 'client_string': None, 'use_template': None, 'modified_by': 'Administrator', 'document_type': None, 'name': 'TA Control', 'idx': None, 'hide_toolbar': None, 'colour': 'White:FFF', 'client_script': None, 'modified': '2011-01-07 14:56:35', 'server_code_error': None, 'name_case': None, 'parenttype': None, 'read_only_onload': None, 'server_code_core': None, 'server_code_compiled': None, 'parent_node': None, 'parentfield': None}]
|
||||
0
analysis/page/__init__.py
Normal file
0
analysis/page/__init__.py
Normal file
0
analysis/search_criteria/__init__.py
Normal file
0
analysis/search_criteria/__init__.py
Normal 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>'});
|
||||
}
|
||||
@@ -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)
|
||||
@@ -0,0 +1 @@
|
||||
SELECT DISTINCT name FROM tabDocType WHERE document_type="Transaction" AND ifnull(istable,0) = 0
|
||||
@@ -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'
|
||||
}
|
||||
]
|
||||
0
analysis/search_criteria/trend_analyzer/__init__.py
Normal file
0
analysis/search_criteria/trend_analyzer/__init__.py
Normal file
121
analysis/search_criteria/trend_analyzer/trend_analyzer.js
Normal file
121
analysis/search_criteria/trend_analyzer/trend_analyzer.js
Normal 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;
|
||||
}
|
||||
}
|
||||
160
analysis/search_criteria/trend_analyzer/trend_analyzer.py
Normal file
160
analysis/search_criteria/trend_analyzer/trend_analyzer.py
Normal 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)
|
||||
37
analysis/search_criteria/trend_analyzer/trend_analyzer.txt
Normal file
37
analysis/search_criteria/trend_analyzer/trend_analyzer.txt
Normal 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'
|
||||
}
|
||||
]
|
||||
@@ -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>'});
|
||||
}
|
||||
@@ -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)
|
||||
@@ -0,0 +1 @@
|
||||
SELECT DISTINCT name FROM tabDocType WHERE document_type="Transaction" AND ifnull(istable,0) = 0
|
||||
@@ -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'
|
||||
}
|
||||
]
|
||||
Reference in New Issue
Block a user