Example #1
0
def execute(filters=None):
	if cint(frappe.db.get_single_value('Accounts Settings', 'use_custom_cash_flow')):
		from erpnext.accounts.report.cash_flow.custom_cash_flow import execute as execute_custom
		return execute_custom(filters=filters)
		
	period_list = get_period_list(filters.from_fiscal_year, filters.to_fiscal_year, 
		filters.periodicity, filters.accumulated_values, filters.company)

	cash_flow_accounts = get_cash_flow_accounts()

	# compute net profit / loss
	income = get_data(filters.company, "Income", "Credit", period_list, filters=filters,
		accumulated_values=filters.accumulated_values, ignore_closing_entries=True, ignore_accumulated_values_for_fy= True)
	expense = get_data(filters.company, "Expense", "Debit", period_list, filters=filters,
		accumulated_values=filters.accumulated_values, ignore_closing_entries=True, ignore_accumulated_values_for_fy= True)
		
	net_profit_loss = get_net_profit_loss(income, expense, period_list, filters.company)

	data = []
	company_currency = frappe.get_cached_value('Company',  filters.company,  "default_currency")
	
	for cash_flow_account in cash_flow_accounts:
		section_data = []
		data.append({
			"account_name": cash_flow_account['section_header'], 
			"parent_account": None,
			"indent": 0.0, 
			"account": cash_flow_account['section_header']
		})

		if len(data) == 1:
			# add first net income in operations section
			if net_profit_loss:
				net_profit_loss.update({
					"indent": 1, 
					"parent_account": cash_flow_accounts[0]['section_header']
				})
				data.append(net_profit_loss)
				section_data.append(net_profit_loss)

		for account in cash_flow_account['account_types']:
			account_data = get_account_type_based_data(filters.company, 
				account['account_type'], period_list, filters.accumulated_values)
			account_data.update({
				"account_name": account['label'],
				"account": account['label'], 
				"indent": 1,
				"parent_account": cash_flow_account['section_header'],
				"currency": company_currency
			})
			data.append(account_data)
			section_data.append(account_data)

		add_total_row_account(data, section_data, cash_flow_account['section_footer'], 
			period_list, company_currency)

	add_total_row_account(data, data, _("Net Change in Cash"), period_list, company_currency)
	columns = get_columns(filters.periodicity, period_list, filters.accumulated_values, filters.company)

	return columns, data
def execute(filters=None):
	period_list = get_period_list(filters.from_fiscal_year, filters.to_fiscal_year, 
		filters.periodicity, filters.accumulated_values, filters.company)

	income = get_data(filters.company, "Income", "Credit", period_list, filters = filters,
		accumulated_values=filters.accumulated_values, 
		ignore_closing_entries=True, ignore_accumulated_values_for_fy= True)
		
	expense = get_data(filters.company, "Expense", "Debit", period_list, filters=filters,
		accumulated_values=filters.accumulated_values, 
		ignore_closing_entries=True, ignore_accumulated_values_for_fy= True)

	net_profit_loss = get_net_profit_loss(income, expense, period_list, filters.company)

	data = []
	data.extend(income or [])
	data.extend(expense or [])
	if net_profit_loss:
		data.append(net_profit_loss)

	columns = get_columns(filters.periodicity, period_list, filters.accumulated_values, filters.company)

	chart = get_chart_data(filters, columns, income, expense, net_profit_loss)

	return columns, data, None, chart
Example #3
0
def execute(filters=None):
    period_list = get_period_list(filters.fiscal_year,
                                  filters.periodicity,
                                  from_beginning=True)

    asset = get_data(filters.company, "Asset", "Debit", period_list,
                     filters.accumulated_value)
    liability = get_data(filters.company, "Liability", "Credit", period_list,
                         filters.accumulated_value)
    equity = get_data(filters.company, "Equity", "Credit", period_list,
                      filters.accumulated_value)
    provisional_profit_loss = get_provisional_profit_loss(
        asset, liability, equity, period_list)

    data = []
    data.extend(asset or [])
    data.extend(liability or [])
    data.extend(equity or [])
    if provisional_profit_loss:
        data.append(provisional_profit_loss)

    columns = get_columns(filters.periodicity, period_list,
                          filters.accumulated_value)

    return columns, data
def execute(filters=None):
	period_list = get_period_list(filters.from_fiscal_year, filters.to_fiscal_year,
		filters.period_start_date, filters.period_end_date, filters.filter_based_on, filters.periodicity,
		company=filters.company)

	income = get_data(filters.company, "Income", "Credit", period_list, filters = filters,
		accumulated_values=filters.accumulated_values,
		ignore_closing_entries=True, ignore_accumulated_values_for_fy= True)

	expense = get_data(filters.company, "Expense", "Debit", period_list, filters=filters,
		accumulated_values=filters.accumulated_values,
		ignore_closing_entries=True, ignore_accumulated_values_for_fy= True)

	net_profit_loss = get_net_profit_loss(income, expense, period_list, filters.company, filters.presentation_currency)

	data = []
	data.extend(income or [])
	data.extend(expense or [])
	if net_profit_loss:
		data.append(net_profit_loss)

	columns = get_columns(filters.periodicity, period_list, filters.accumulated_values, filters.company)

	chart = get_chart_data(filters, columns, income, expense, net_profit_loss)

	currency = filters.presentation_currency or frappe.get_cached_value('Company', filters.company, "default_currency")
	report_summary = get_report_summary(period_list, filters.periodicity, income, expense, net_profit_loss, currency)

	return columns, data, None, chart, report_summary
Example #5
0
def execute(filters=None):
    period_list = get_period_list(filters.fiscal_year, filters.periodicity)

    income = get_data(filters.company,
                      "Income",
                      "Credit",
                      period_list,
                      accumulated_values=filters.accumulated_values,
                      ignore_closing_entries=True)
    expense = get_data(filters.company,
                       "Expense",
                       "Debit",
                       period_list,
                       accumulated_values=filters.accumulated_values,
                       ignore_closing_entries=True)

    net_profit_loss = get_net_profit_loss(income, expense, period_list,
                                          filters.company)

    data = []
    data.extend(income or [])
    data.extend(expense or [])
    if net_profit_loss:
        data.append(net_profit_loss)

    columns = get_columns(filters.periodicity, period_list,
                          filters.accumulated_values, filters.company)

    chart = get_chart_data(filters, columns, income, expense, net_profit_loss)

    return columns, data, None, chart
Example #6
0
def execute(filters=None):
	if not filters.periodicity: filters.periodicity = "Monthly"
	period_list = get_period_list(
		filters.from_fiscal_year, filters.to_fiscal_year, filters.periodicity,
		filters.accumulated_values, filters.company
	)

	mappers = get_mappers_from_db()

	cash_flow_accounts = setup_mappers(mappers)

	# compute net profit / loss
	income = get_data(
		filters.company, "Income", "Credit", period_list, filters=filters,
		accumulated_values=filters.accumulated_values, ignore_closing_entries=True,
		ignore_accumulated_values_for_fy=True
	)

	expense = get_data(
		filters.company, "Expense", "Debit", period_list, filters=filters,
		accumulated_values=filters.accumulated_values, ignore_closing_entries=True,
		ignore_accumulated_values_for_fy=True
	)

	net_profit_loss = get_net_profit_loss(income, expense, period_list, filters.company)

	company_currency = frappe.get_cached_value('Company',  filters.company,  "default_currency")

	data = compute_data(filters, company_currency, net_profit_loss, period_list, mappers, cash_flow_accounts)

	_add_total_row_account(data, data, _("Net Change in Cash"), period_list, company_currency)
	columns = get_columns(filters.periodicity, period_list, filters.accumulated_values, filters.company)

	return columns, data
Example #7
0
def execute(filters=None):
	period_list = get_period_list(filters.from_date, filters.to_date,  
		filters.periodicity, filters.accumulated_values, filters.company)

	ignore_accumulated_values_for_fy = True
	if filters.periodicity == "Custom":
		ignore_accumulated_values_for_fy=False
	
	income = get_data(filters.company, "Income", "Credit", period_list, filters=filters,
		accumulated_values=filters.accumulated_values,
		ignore_closing_entries=True, ignore_accumulated_values_for_fy=ignore_accumulated_values_for_fy)

	expense = get_data(filters.company, "Expense", "Debit", period_list, filters=filters,
		accumulated_values=filters.accumulated_values,
		ignore_closing_entries=True, ignore_accumulated_values_for_fy=ignore_accumulated_values_for_fy)

	net_profit_loss = get_net_profit_loss(income, expense, period_list, filters.company, filters.presentation_currency)

	data = []
	data.extend(income or [])
	data.extend(expense or [])
	if net_profit_loss:
		data.append(net_profit_loss)

	columns = get_columns(filters.periodicity, period_list, filters.accumulated_values, filters.company)

	chart = get_chart_data(filters, columns, income, expense, net_profit_loss)

	return columns, data, None, chart
def get(filters=None):

	filters = frappe._dict({
		"from_fiscal_year" : filters.get("from_fiscal_year"),
		"to_fiscal_year" : filters.get("to_fiscal_year"),
		"periodicity": filters.get("periodicity"),
		"accumulated_values": 1,
		"company": filters.get("company")
	})

	period_list = get_period_list(filters.from_fiscal_year, filters.to_fiscal_year,
		filters.periodicity, filters.accumulated_values, filters.company)

	income = get_data(filters.company, "Income", "Credit", period_list, filters = filters,
		accumulated_values=filters.accumulated_values,
		ignore_closing_entries=True, ignore_accumulated_values_for_fy= True)

	expense = get_data(filters.company, "Expense", "Debit", period_list, filters=filters,
		accumulated_values=filters.accumulated_values,
		ignore_closing_entries=True, ignore_accumulated_values_for_fy= True)

	net_profit_loss = get_net_profit_loss(income, expense, period_list, filters.company, filters.presentation_currency)

	columns = get_columns(filters.periodicity, period_list, filters.accumulated_values, filters.company)

	chart = get_chart_data(filters, columns, income, expense, net_profit_loss)

	return chart
Example #9
0
def execute(filters=None):
    period_list = get_period_list(filters.from_fiscal_year,
                                  filters.to_fiscal_year, filters.periodicity)

    asset = get_data(filters.company,
                     "Asset",
                     "Debit",
                     period_list,
                     only_current_fiscal_year=False)
    liability = get_data(filters.company,
                         "Liability",
                         "Credit",
                         period_list,
                         only_current_fiscal_year=False)
    equity = get_data(filters.company,
                      "Equity",
                      "Credit",
                      period_list,
                      only_current_fiscal_year=False)

    provisional_profit_loss, total_credit = get_provisional_profit_loss(
        asset, liability, equity, period_list, filters.company)

    message, opening_balance = check_opening_balance(asset, liability, equity)

    data = []
    data.extend(asset or [])
    data.extend(liability or [])
    data.extend(equity or [])
    if opening_balance and round(opening_balance, 2) != 0:
        unclosed = {
            "account_name":
            "'" + _("Unclosed Fiscal Years Profit / Loss (Credit)") + "'",
            "account":
            None,
            "warn_if_negative":
            True,
            "currency":
            frappe.db.get_value("Company", filters.company, "default_currency")
        }
        for period in period_list:
            unclosed[period.key] = opening_balance
            provisional_profit_loss[period.key] = provisional_profit_loss[
                period.key] - opening_balance
        unclosed["total"] = opening_balance
        data.append(unclosed)

    if provisional_profit_loss:
        data.append(provisional_profit_loss)
    if total_credit:
        data.append(total_credit)

    columns = get_columns(filters.periodicity,
                          period_list,
                          company=filters.company)

    chart = get_chart_data(columns, asset, liability, equity)

    return columns, data, message, chart
Example #10
0
def execute(filters=None):
	period_list = get_period_list(filters.from_fiscal_year, filters.to_fiscal_year,
		filters.period_start_date, filters.period_end_date, filters.filter_based_on,
		filters.periodicity, company=filters.company)

	currency = filters.presentation_currency or frappe.get_cached_value('Company',  filters.company,  "default_currency")

	asset = get_data(filters.company, "Asset", "Debit", period_list,
		only_current_fiscal_year=False, filters=filters,
		accumulated_values=filters.accumulated_values)

	liability = get_data(filters.company, "Liability", "Credit", period_list,
		only_current_fiscal_year=False, filters=filters,
		accumulated_values=filters.accumulated_values)

	equity = get_data(filters.company, "Equity", "Credit", period_list,
		only_current_fiscal_year=False, filters=filters,
		accumulated_values=filters.accumulated_values)

	provisional_profit_loss, total_credit = get_provisional_profit_loss(asset, liability, equity,
		period_list, filters.company, currency)

	message, opening_balance = check_opening_balance(asset, liability, equity)

	data = []
	data.extend(asset or [])
	data.extend(liability or [])
	data.extend(equity or [])
	if opening_balance and round(opening_balance,2) !=0:
		unclosed ={
			"account_name": "'" + _("Unclosed Fiscal Years Profit / Loss (Credit)") + "'",
			"account": "'" + _("Unclosed Fiscal Years Profit / Loss (Credit)") + "'",
			"warn_if_negative": True,
			"currency": currency
		}
		for period in period_list:
			unclosed[period.key] = opening_balance
			if provisional_profit_loss:
				provisional_profit_loss[period.key] = provisional_profit_loss[period.key] - opening_balance

		unclosed["total"]=opening_balance
		data.append(unclosed)

	if provisional_profit_loss:
		data.append(provisional_profit_loss)
	if total_credit:
		data.append(total_credit)

	columns = get_columns(filters.periodicity, period_list, filters.accumulated_values, company=filters.company)

	chart = get_chart_data(filters, columns, asset, liability, equity)

	report_summary = get_report_summary(period_list, asset, liability, equity, provisional_profit_loss,
		total_credit, currency, filters)

	return columns, data, message, chart, report_summary
def execute(filters=None):
	periodicity = filters.get('periodicity')
	period_list = get_period_list(
			filters.get('from_fiscal_year'),
			filters.get('to_fiscal_year'),
			filters.get('periodicity')
		)
	columns = get_columns(periodicity, period_list)
	data = get_data(periodicity, period_list, filters)
	return columns, data
Example #12
0
def execute(filters=None):
	if not filters.periodicity:
		filters.periodicity = "Monthly"
	period_list = get_period_list(
		filters.from_fiscal_year,
		filters.to_fiscal_year,
		filters.period_start_date,
		filters.period_end_date,
		filters.filter_based_on,
		filters.periodicity,
		company=filters.company,
	)

	mappers = get_mappers_from_db()

	cash_flow_accounts = setup_mappers(mappers)

	# compute net profit / loss
	income = get_data(
		filters.company,
		"Income",
		"Credit",
		period_list,
		filters=filters,
		accumulated_values=filters.accumulated_values,
		ignore_closing_entries=True,
		ignore_accumulated_values_for_fy=True,
	)

	expense = get_data(
		filters.company,
		"Expense",
		"Debit",
		period_list,
		filters=filters,
		accumulated_values=filters.accumulated_values,
		ignore_closing_entries=True,
		ignore_accumulated_values_for_fy=True,
	)

	net_profit_loss = get_net_profit_loss(income, expense, period_list, filters.company)

	company_currency = frappe.get_cached_value("Company", filters.company, "default_currency")

	data = compute_data(
		filters, company_currency, net_profit_loss, period_list, mappers, cash_flow_accounts
	)

	_add_total_row_account(data, data, _("Net Change in Cash"), period_list, company_currency)
	columns = get_columns(
		filters.periodicity, period_list, filters.accumulated_values, filters.company
	)

	return columns, data
def execute(filters=None):
	period_list = get_period_list(filters.from_fiscal_year, filters.to_fiscal_year,
		filters.periodicity, filters.accumulated_values, filters.company)

	columns, data = [], []

	income = get_data(filters.company, "Income", "Credit", period_list, filters = filters,
		accumulated_values=filters.accumulated_values,
		ignore_closing_entries=True, ignore_accumulated_values_for_fy= True, total= False)

	expense = get_data(filters.company, "Expense", "Debit", period_list, filters=filters,
		accumulated_values=filters.accumulated_values,
		ignore_closing_entries=True, ignore_accumulated_values_for_fy= True, total= False)

	columns = get_columns(filters.periodicity, period_list, filters.accumulated_values, filters.company)


	gross_income = get_revenue(income, period_list)

	gross_expense = get_revenue(expense, period_list)

	if(len(gross_income)==0 and len(gross_expense)== 0):
		data.append({"account_name": "'" + _("Nothing is included in gross") + "'",
		"account": "'" + _("Nothing is included in gross") + "'"})

		return columns, data

	data.append({"account_name": "'" + _("Included in Gross Profit") + "'",
		"account": "'" + _("Included in Gross Profit") + "'"})

	data.append({})
	data.extend(gross_income or [])

	data.append({})
	data.extend(gross_expense or [])

	data.append({})
	gross_profit = get_profit(gross_income, gross_expense, period_list, filters.company, 'Gross Profit',filters.presentation_currency)
	data.append(gross_profit)

	non_gross_income = get_revenue(income, period_list, 0)
	data.append({})
	data.extend(non_gross_income or [])

	non_gross_expense = get_revenue(expense, period_list, 0)
	data.append({})
	data.extend(non_gross_expense or [])

	net_profit = get_net_profit(non_gross_income, gross_income, gross_expense, non_gross_expense, period_list, filters.company,filters.presentation_currency)
	data.append({})
	data.append(net_profit)

	return columns, data
Example #14
0
def execute(filters=None):
	period_list = get_period_list(filters.from_fiscal_year, filters.to_fiscal_year, 
		filters.periodicity, filters.accumulated_values, filters.company)

	asset = get_data(filters.company, "Asset", "Debit", period_list, 
		only_current_fiscal_year=False, filters=filters,
		accumulated_values=filters.accumulated_values, 
		ignore_closing_entries=True, ignore_accumulated_values_for_fy=True)
		
	liability = get_data(filters.company, "Liability", "Credit", period_list, 
		only_current_fiscal_year=False, filters=filters,
		accumulated_values=filters.accumulated_values, 
		ignore_closing_entries=True, ignore_accumulated_values_for_fy=True)
		
	equity = get_data(filters.company, "Equity", "Credit", period_list, 
		only_current_fiscal_year=False, filters=filters,
		accumulated_values=filters.accumulated_values, 
		ignore_closing_entries=True, ignore_accumulated_values_for_fy=True)

	provisional_profit_loss, total_credit = get_provisional_profit_loss(asset, liability, equity,
		period_list, filters.company)

	message, opening_balance = check_opening_balance(asset, liability, equity)

	data = []
	data.extend(asset or [])
	data.extend(liability or [])
	data.extend(equity or [])
	if opening_balance and round(opening_balance,2) !=0:
		unclosed ={
			"account_name": "'" + _("Unclosed Fiscal Years Profit / Loss (Credit)") + "'",
			"account": "'" + _("Unclosed Fiscal Years Profit / Loss (Credit)") + "'",
			"warn_if_negative": True,
			"currency": frappe.db.get_value("Company", filters.company, "default_currency")
		}
		for period in period_list:
			unclosed[period.key] = opening_balance
			if provisional_profit_loss:
				provisional_profit_loss[period.key] = provisional_profit_loss[period.key] - opening_balance
				
		unclosed["total"]=opening_balance
		data.append(unclosed)
		
	if provisional_profit_loss:
		data.append(provisional_profit_loss)
	if total_credit:
		data.append(total_credit)		

	columns = get_columns(filters.periodicity, period_list, filters.accumulated_values, company=filters.company)
	
	chart = get_chart_data(filters, columns, asset, liability, equity)

	return columns, data, message, chart
Example #15
0
def execute(filters=None):
	period_list = get_period_list(filters.fiscal_year, filters.periodicity)

	income = get_data(filters.company, "Income", "Credit", period_list, ignore_closing_entries=True)
	expense = get_data(filters.company, "Expense", "Debit", period_list, ignore_closing_entries=True)
	net_profit_loss = get_net_profit_loss(income, expense, period_list)

	data = []
	data.extend(income or [])
	data.extend(expense or [])
	if net_profit_loss:
		data.append(net_profit_loss)

	columns = get_columns(period_list)

	return columns, data
def execute(filters=None):
	period_list = get_period_list(filters.fiscal_year, filters.periodicity, from_beginning=True)

	asset = get_data(filters.company, "Asset", "Debit", period_list)
	liability = get_data(filters.company, "Liability", "Credit", period_list)
	equity = get_data(filters.company, "Equity", "Credit", period_list)
	provisional_profit_loss = get_provisional_profit_loss(asset, liability, equity, period_list)

	data = []
	data.extend(asset or [])
	data.extend(liability or [])
	data.extend(equity or [])
	if provisional_profit_loss:
		data.append(provisional_profit_loss)

	columns = get_columns(period_list)

	return columns, data
def execute(filters=None):
    period_list = make_period_list(filters.get('start_date'), filters.get('end_date'))

    income = get_data(
        filters.company,
        "Income",
        "Credit",
        period_list,
        filters=filters,
        accumulated_values=filters.accumulated_values,
        only_current_fiscal_year=False,
        ignore_closing_entries=True,
        ignore_accumulated_values_for_fy=False,
    )

    expense = get_data(
        filters.company,
        "Expense",
        "Debit",
        period_list,
        filters=filters,
        accumulated_values=filters.accumulated_values,
        only_current_fiscal_year=False,
        ignore_closing_entries=True,
        ignore_accumulated_values_for_fy=False,
    )

    net_profit_loss = get_net_profit_loss(
        income, expense, period_list, filters.company, filters.presentation_currency
    )

    data = []
    data.extend(income or [])
    data.extend(expense or [])
    if net_profit_loss:
        data.append(net_profit_loss)

    columns = get_columns(
        filters.periodicity, period_list, filters.accumulated_values, filters.company
    )

    chart = get_chart_data(filters, columns, income, expense, net_profit_loss)

    return columns, data, None, chart
Example #18
0
def execute(filters=None):
	period_list = get_period_list(filters.fiscal_year, filters.periodicity)
	
	asset = get_data(filters.company, "Asset", "Debit", period_list, only_current_fiscal_year=False)
	liability = get_data(filters.company, "Liability", "Credit", period_list, only_current_fiscal_year=False)
	equity = get_data(filters.company, "Equity", "Credit", period_list, only_current_fiscal_year=False)
	
	provisional_profit_loss = get_provisional_profit_loss(asset, liability, equity, 
		period_list, filters.company)

	data = []
	data.extend(asset or [])
	data.extend(liability or [])
	data.extend(equity or [])
	if provisional_profit_loss:
		data.append(provisional_profit_loss)

	columns = get_columns(filters.periodicity, period_list, company=filters.company)

	return columns, data
def execute(filters=None):
    period_list = get_period_list(filters.from_fiscal_year,
                                  filters.to_fiscal_year, filters.periodicity,
                                  filters.accumulated_values, filters.company)

    income = get_data(filters.company,
                      "Income",
                      "Credit",
                      period_list,
                      filters=filters,
                      accumulated_values=filters.accumulated_values,
                      ignore_closing_entries=True,
                      ignore_accumulated_values_for_fy=True)

    expense = get_data(filters.company,
                       "Expense",
                       "Debit",
                       period_list,
                       filters=filters,
                       accumulated_values=filters.accumulated_values,
                       ignore_closing_entries=True,
                       ignore_accumulated_values_for_fy=True)

    net_profit_loss = get_net_profit_loss(income, expense, period_list,
                                          filters.company)

    cost_of_goods_entries, expense = extract_cost_of_goods_sold(expense)
    print(expense[0])
    data = []
    data.extend(income or [])
    data.extend(cost_of_goods_entries or [])
    data.extend(expense or [])
    if net_profit_loss:
        data.append(net_profit_loss)

    columns = get_columns(filters.periodicity, period_list,
                          filters.accumulated_values, filters.company)

    chart = get_chart_data(filters, columns, income, expense, net_profit_loss)

    return columns, data, None, chart
Example #20
0
def execute(filters=None):
	period_list = get_period_list(filters.fiscal_year, filters.periodicity)
	
	asset = get_data(filters.company, "Asset", "Debit", period_list, only_current_fiscal_year=False)
	liability = get_data(filters.company, "Liability", "Credit", period_list, only_current_fiscal_year=False)
	equity = get_data(filters.company, "Equity", "Credit", period_list, only_current_fiscal_year=False)
	
	provisional_profit_loss,total_credit = get_provisional_profit_loss(asset, liability, equity, 
		period_list, filters.company)
	
	opening_balance = flt(asset[0].get("opening_balance", 0))
	if liability:
		opening_balance -= flt(liability[0].get("opening_balance", 0))
	if equity:
		opening_balance -= flt(equity[0].get("opening_balance", 0))

	data = []
	data.extend(asset or [])
	data.extend(liability or [])	
	data.extend(equity or [])
	if round(opening_balance,2) !=0:
		unclosed ={
			"account_name": "'" + _("Unclosed Fiscal Years Profit / Loss (Credit)") + "'",
			"account": None,
			"warn_if_negative": True,
			"currency": frappe.db.get_value("Company", filters.company, "default_currency")
		}
		for period in period_list:
			unclosed[period.key] = opening_balance
			provisional_profit_loss[period.key] = provisional_profit_loss[period.key] - opening_balance
		unclosed["total"]=opening_balance
		data.append(unclosed)
		
	if provisional_profit_loss:
		data.append(provisional_profit_loss)
	data.append(total_credit)		

	columns = get_columns(filters.periodicity, period_list, company=filters.company)

	return columns, data
Example #21
0
def execute(filters=None):
    period_list = get_period_list(filters.from_fiscal_year,
                                  filters.to_fiscal_year, filters.periodicity,
                                  filters.company)

    operation_accounts = {
        "section_name":
        "Operations",
        "section_footer":
        _("Net Cash from Operations"),
        "section_header":
        _("Cash Flow from Operations"),
        "account_types": [{
            "account_type": "Depreciation",
            "label": _("Depreciation")
        }, {
            "account_type": "Receivable",
            "label": _("Net Change in Accounts Receivable")
        }, {
            "account_type": "Payable",
            "label": _("Net Change in Accounts Payable")
        }, {
            "account_type": "Stock",
            "label": _("Net Change in Inventory")
        }]
    }

    investing_accounts = {
        "section_name":
        "Investing",
        "section_footer":
        _("Net Cash from Investing"),
        "section_header":
        _("Cash Flow from Investing"),
        "account_types": [{
            "account_type": "Fixed Asset",
            "label": _("Net Change in Fixed Asset")
        }]
    }

    financing_accounts = {
        "section_name":
        "Financing",
        "section_footer":
        _("Net Cash from Financing"),
        "section_header":
        _("Cash Flow from Financing"),
        "account_types": [{
            "account_type": "Equity",
            "label": _("Net Change in Equity")
        }]
    }

    # combine all cash flow accounts for iteration
    cash_flow_accounts = []
    cash_flow_accounts.append(operation_accounts)
    cash_flow_accounts.append(investing_accounts)
    cash_flow_accounts.append(financing_accounts)

    # compute net profit / loss
    income = get_data(filters.company,
                      "Income",
                      "Credit",
                      period_list,
                      accumulated_values=filters.accumulated_values,
                      ignore_closing_entries=True,
                      ignore_accumulated_values_for_fy=True)
    expense = get_data(filters.company,
                       "Expense",
                       "Debit",
                       period_list,
                       accumulated_values=filters.accumulated_values,
                       ignore_closing_entries=True,
                       ignore_accumulated_values_for_fy=True)

    net_profit_loss = get_net_profit_loss(income, expense, period_list,
                                          filters.company)

    data = []
    company_currency = frappe.db.get_value("Company", filters.company,
                                           "default_currency")

    for cash_flow_account in cash_flow_accounts:
        section_data = []
        data.append({
            "account_name": cash_flow_account['section_header'],
            "parent_account": None,
            "indent": 0.0,
            "account": cash_flow_account['section_header']
        })

        if len(data) == 1:
            # add first net income in operations section
            if net_profit_loss:
                net_profit_loss.update({
                    "indent":
                    1,
                    "parent_account":
                    operation_accounts['section_header']
                })
                data.append(net_profit_loss)
                section_data.append(net_profit_loss)

        for account in cash_flow_account['account_types']:
            account_data = get_account_type_based_data(
                filters.company, account['account_type'], period_list,
                filters.accumulated_values)
            account_data.update({
                "account_name":
                account['label'],
                "account":
                account['label'],
                "indent":
                1,
                "parent_account":
                cash_flow_account['section_header'],
                "currency":
                company_currency
            })
            data.append(account_data)
            section_data.append(account_data)

        add_total_row_account(data, section_data,
                              cash_flow_account['section_footer'], period_list,
                              company_currency)

    add_total_row_account(data, data, _("Net Change in Cash"), period_list,
                          company_currency)
    columns = get_columns(filters.periodicity, period_list,
                          filters.accumulated_values, filters.company)

    return columns, data
Example #22
0
def execute(filters=None):
    period_list = get_period_list(filters.from_date, filters.to_date,
                                  filters.periodicity,
                                  filters.accumulated_values, filters.company)

    ignore_accumulated_values_for_fy = True
    if filters.periodicity == "Custom":
        ignore_accumulated_values_for_fy = False

    #fetch data for the income and expense accounts
    income = get_data(
        filters.company,
        "Income",
        "Credit",
        period_list,
        filters=filters,
        accumulated_values=filters.accumulated_values,
        ignore_closing_entries=True,
        ignore_accumulated_values_for_fy=ignore_accumulated_values_for_fy)

    expense = get_data(
        filters.company,
        "Expense",
        "Debit",
        period_list,
        filters=filters,
        accumulated_values=filters.accumulated_values,
        ignore_closing_entries=True,
        ignore_accumulated_values_for_fy=ignore_accumulated_values_for_fy)

    #add the section for income
    data = []
    data.extend(income or [])

    #get direct and indirect expense account names
    gross_profit_loss = None
    direct_expense_account = frappe.get_value("Company", get_default_company(),
                                              "default_direct_expenses")
    indirect_expense_account = frappe.get_value("Company",
                                                get_default_company(),
                                                "default_indirect_expenses")
    company_abbr = get_company_default(get_default_company(), "abbr")
    direct_expenses = None

    for expense_item in expense:
        data.append(expense_item)

        #add gross profit line item on the PL statement
        if expense_item.get("group_account_summary",
                            False) and expense_item.get(
                                "_account") == direct_expense_account:
            direct_expenses = expense_item
            gross_profit_loss = get_profit_loss(income,
                                                expense_item,
                                                period_list,
                                                filters.company,
                                                "Gross Profit",
                                                indent=1,
                                                is_group=0)
            if gross_profit_loss:
                data.append(gross_profit_loss)
                gross_profit_loss = None

        #add the line for net operating income / loss
        if expense_item.get("group_account_summary",
                            False) and expense_item.get(
                                "_account") == indirect_expense_account:
            operating_profit_loss = get_profit_loss(
                income,
                expense_item,
                period_list,
                filters.company,
                "Net Operating Profit",
                indent=expense_item.get("indent"),
                is_group=0,
                direct_expenses=direct_expenses)
            if operating_profit_loss:
                data.append(operating_profit_loss)
                operating_profit_loss = None

    #add the line for net profit / loss
    net_profit_loss = get_net_profit_loss(income, expense, period_list,
                                          filters.company,
                                          filters.presentation_currency)
    if net_profit_loss:
        data.append(net_profit_loss)

    columns = get_columns(filters.periodicity, period_list,
                          filters.accumulated_values, filters.company)
    chart = get_chart_data(filters, columns, income, expense, net_profit_loss)

    return columns, data, None, chart
Example #23
0
def execute(filters=None):
    period_list = get_period_list(filters.from_fiscal_year,
                                  filters.to_fiscal_year,
                                  filters.period_start_date,
                                  filters.period_end_date,
                                  filters.filter_based_on, filters.periodicity,
                                  filters.accumulated_values, filters.company)

    columns, data = [], []

    income = get_data(filters.company,
                      "Income",
                      "Credit",
                      period_list,
                      filters=filters,
                      accumulated_values=filters.accumulated_values,
                      ignore_closing_entries=True,
                      ignore_accumulated_values_for_fy=True,
                      total=False)

    expense = get_data(filters.company,
                       "Expense",
                       "Debit",
                       period_list,
                       filters=filters,
                       accumulated_values=filters.accumulated_values,
                       ignore_closing_entries=True,
                       ignore_accumulated_values_for_fy=True,
                       total=False)

    columns = get_columns(filters.periodicity, period_list,
                          filters.accumulated_values, filters.company)

    gross_income = get_revenue(income, period_list)
    gross_expense = get_revenue(expense, period_list)

    if (len(gross_income) == 0 and len(gross_expense) == 0):
        data.append({
            "account_name": "'" + _("Nothing is included in gross") + "'",
            "account": "'" + _("Nothing is included in gross") + "'"
        })
        return columns, data

    # to avoid error eg: gross_income[0] : list index out of range
    if not gross_income:
        gross_income = [{}]
    if not gross_expense:
        gross_expense = [{}]

    data.append({
        "account_name": "'" + _("Included in Gross Profit") + "'",
        "account": "'" + _("Included in Gross Profit") + "'"
    })

    data.append({})
    data.extend(gross_income or [])

    data.append({})
    data.extend(gross_expense or [])

    data.append({})
    gross_profit = get_profit(gross_income, gross_expense, period_list,
                              filters.company, 'Gross Profit',
                              filters.presentation_currency)
    data.append(gross_profit)

    non_gross_income = get_revenue(income, period_list, 0)
    data.append({})
    data.extend(non_gross_income or [])

    non_gross_expense = get_revenue(expense, period_list, 0)
    data.append({})
    data.extend(non_gross_expense or [])

    net_profit = get_net_profit(non_gross_income, gross_income, gross_expense,
                                non_gross_expense, period_list,
                                filters.company, filters.presentation_currency)
    data.append({})
    data.append(net_profit)

    return columns, data
Example #24
0
def execute(filters=None):
	period_list = get_period_list(filters.from_fiscal_year, filters.to_fiscal_year, 
		filters.periodicity, filters.company)

	operation_accounts = {
		"section_name": "Operations",
		"section_footer": _("Net Cash from Operations"),
		"section_header": _("Cash Flow from Operations"),
		"account_types": [
			{"account_type": "Depreciation", "label": _("Depreciation")},
			{"account_type": "Receivable", "label": _("Net Change in Accounts Receivable")},
			{"account_type": "Payable", "label": _("Net Change in Accounts Payable")},
			{"account_type": "Stock", "label": _("Net Change in Inventory")}
		]
	}

	investing_accounts = {
		"section_name": "Investing",
		"section_footer": _("Net Cash from Investing"),
		"section_header": _("Cash Flow from Investing"),
		"account_types": [
			{"account_type": "Fixed Asset", "label": _("Net Change in Fixed Asset")}
		]
	}

	financing_accounts = {
		"section_name": "Financing",
		"section_footer": _("Net Cash from Financing"),
		"section_header": _("Cash Flow from Financing"),
		"account_types": [
			{"account_type": "Equity", "label": _("Net Change in Equity")}
		]
	}

	# combine all cash flow accounts for iteration
	cash_flow_accounts = []
	cash_flow_accounts.append(operation_accounts)
	cash_flow_accounts.append(investing_accounts)
	cash_flow_accounts.append(financing_accounts)

	# compute net profit / loss
	income = get_data(filters.company, "Income", "Credit", period_list, 
		accumulated_values=filters.accumulated_values, ignore_closing_entries=True, ignore_accumulated_values_for_fy= True)
	expense = get_data(filters.company, "Expense", "Debit", period_list, 
		accumulated_values=filters.accumulated_values, ignore_closing_entries=True, ignore_accumulated_values_for_fy= True)
		
	net_profit_loss = get_net_profit_loss(income, expense, period_list, filters.company)

	data = []
	company_currency = frappe.db.get_value("Company", filters.company, "default_currency")
	
	for cash_flow_account in cash_flow_accounts:
		section_data = []
		data.append({
			"account_name": cash_flow_account['section_header'], 
			"parent_account": None,
			"indent": 0.0, 
			"account": cash_flow_account['section_header']
		})

		if len(data) == 1:
			# add first net income in operations section
			if net_profit_loss:
				net_profit_loss.update({
					"indent": 1, 
					"parent_account": operation_accounts['section_header']
				})
				data.append(net_profit_loss)
				section_data.append(net_profit_loss)

		for account in cash_flow_account['account_types']:
			account_data = get_account_type_based_data(filters.company, 
				account['account_type'], period_list, filters.accumulated_values)
			account_data.update({
				"account_name": account['label'],
				"account": account['label'], 
				"indent": 1,
				"parent_account": cash_flow_account['section_header'],
				"currency": company_currency
			})
			data.append(account_data)
			section_data.append(account_data)

		add_total_row_account(data, section_data, cash_flow_account['section_footer'], 
			period_list, company_currency)

	add_total_row_account(data, data, _("Net Change in Cash"), period_list, company_currency)
	columns = get_columns(filters.periodicity, period_list, filters.accumulated_values, filters.company)

	return columns, data
Example #25
0
def execute(filters=None):
	period_list = get_period_list(filters.from_date, filters.to_date,
		filters.periodicity, company=filters.company)

	currency = filters.presentation_currency or frappe.get_cached_value('Company',  filters.company,  "default_currency")

	asset = get_data(filters.company, "Asset", "Debit", period_list,
		only_current_fiscal_year=False, filters=filters,
		accumulated_values=filters.accumulated_values)

	liability = get_data(filters.company, "Liability", "Credit", period_list,
		only_current_fiscal_year=False, filters=filters,
		accumulated_values=filters.accumulated_values)

	equity = get_data(filters.company, "Equity", "Credit", period_list,
		only_current_fiscal_year=False, filters=filters,
		accumulated_values=filters.accumulated_values)

	provisional_profit_loss, total_credit = get_provisional_profit_loss(asset, liability, equity,
		period_list, filters.company, currency)

	message, opening_balance = check_opening_balance(asset, liability, equity)

	data = []
	#add assets to the balance sheet report
	data.extend(asset or [])

	#add liabilities to the balance sheet report
	data.extend(liability or [])

	#add provisional profit/loss and adjust equity totals if books are not closed
	if len(equity) > 2 and provisional_profit_loss:
		equity = append_provisions_to_equity(equity, provisional_profit_loss, period_list)
		data.extend(equity or [])

	#specific case when equity is completely empty but we still need to add
	elif not equity and provisional_profit_loss:
		equity = create_equity_with_provisions(provisional_profit_loss, period_list)
		data.extend(equity)

	#add equity to the balance sheet report if there are no provisional profits/losses
	else:
		data.extend(equity or [])

	if opening_balance and round(opening_balance,2) !=0:
		unclosed ={
			"account_name": "'" + _("Unclosed Fiscal Years Profit / Loss (Credit)") + "'",
			"account": "'" + _("Unclosed Fiscal Years Profit / Loss (Credit)") + "'",
			"warn_if_negative": True,
			"currency": currency
		}
		for period in period_list:
			unclosed[period.key] = opening_balance
			if provisional_profit_loss:
				provisional_profit_loss[period.key] = provisional_profit_loss[period.key] - opening_balance

		unclosed["total"]=opening_balance
		data.append(unclosed)

	if total_credit:
		data.append({})
		data.append(total_credit)

	columns = get_columns(filters.periodicity, period_list, filters.accumulated_values, company=filters.company)
	chart = get_chart_data(filters, columns, asset, liability, equity)

	return columns, data, message, chart