# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
# License: GNU General Public License v3. See license.txt

from __future__ import unicode_literals
import frappe
from frappe import _
from frappe.utils import flt
from erpnext.accounts.report.financial_statements import (get_period_list, get_columns, get_data)

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, filters.company)

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

	columns = get_columns(period_list, filters.company)

	return columns, data

def get_net_profit_loss(income, expense, period_list, company):
	if income and expense:
		net_profit_loss = {
			"account_name": "'" + _("Net Profit / Loss") + "'",
			"account": None,
			"warn_if_negative": True,
			"currency": frappe.db.get_value("Company", company, "default_currency")
		}

		for period in period_list:
			net_profit_loss[period.key] = flt(income[-2][period.key] - expense[-2][period.key], 3)

		return net_profit_loss

@@ -486,32 +486,59 @@
 t%22, period_list,
+ filters.accumulated_value,
  ignore_closing_
@@ -620,16 +620,43 @@
 od_list,
+ filters.accumulated_value,
  ignore_
@@ -906,16 +906,36 @@
 columns(
+filters.periodicity,
 period_l
@@ -934,33 +934,32 @@
 period_list,
- 
 filters.
 company)%0A%0A%09r
@@ -942,31 +942,41 @@
 ist,filters.
-company
+accumulated_value
 )%0A%0A%09return c
@@ -1283,16 +1283,37 @@
 %22)%0A%09%09%7D%0A%0A
+%09%09has_value = False%0A%0A
 %09%09for pe
@@ -1423,17 +1423,197 @@
 ey%5D, 3)%0A
-%0A
+%09%09%09%0A%09%09%09if net_profit_loss%5Bperiod.key%5D:%0A%09%09%09%09has_value=True%0A%09%09%09%0A%09%09%09total_column=total_column+net_profit_loss%5Bperiod.key%5D%0A%09%09%09net_profit_loss%5B%22total%22%5D=total_column%0A%09%09%0A%09%09if has_value:%0A%0A%09
 %09%09return

Update profit_and_loss_statement.py