Merge branch 'master' of github.com:webnotes/erpnext
diff --git a/accounts/report/item_wise_purchase_register/item_wise_purchase_register.py b/accounts/report/item_wise_purchase_register/item_wise_purchase_register.py
index 3840837..9093d11 100644
--- a/accounts/report/item_wise_purchase_register/item_wise_purchase_register.py
+++ b/accounts/report/item_wise_purchase_register/item_wise_purchase_register.py
@@ -21,7 +21,7 @@
 def execute(filters=None):
 	if not filters: filters = {}
 	columns = get_columns()
-	last_col = len(columns) - 1
+	last_col = len(columns)
 	
 	item_list = get_items(filters)
 	aii_account_map = get_aii_accounts()
@@ -35,8 +35,10 @@
 			d.purchase_receipt, expense_head, d.qty, d.rate, d.amount]
 		for tax in tax_accounts:
 			row.append(item_tax.get(d.parent, {}).get(d.item_code, {}).get(tax, 0))
-			
-		row.append(sum(row[last_col:]))
+
+		total_tax = sum(row[last_col:])
+		row += [total_tax, d.amount + total_tax]
+		
 		data.append(row)
 	
 	return columns, data
@@ -104,6 +106,6 @@
 	
 	tax_accounts.sort()
 	columns += [account_head + ":Currency:80" for account_head in tax_accounts]
-	columns.append("Total:Currency:80")
+	columns += ["Total Tax:Currency:80", "Total:Currency:80"]
 
 	return item_tax, tax_accounts
\ No newline at end of file
diff --git a/accounts/report/item_wise_sales_register/item_wise_sales_register.py b/accounts/report/item_wise_sales_register/item_wise_sales_register.py
index 9df994a..14d6863 100644
--- a/accounts/report/item_wise_sales_register/item_wise_sales_register.py
+++ b/accounts/report/item_wise_sales_register/item_wise_sales_register.py
@@ -21,7 +21,7 @@
 def execute(filters=None):
 	if not filters: filters = {}
 	columns = get_columns()
-	last_col = len(columns) - 1
+	last_col = len(columns)
 	
 	item_list = get_items(filters)
 	item_tax, tax_accounts = get_tax_accounts(item_list, columns)
@@ -35,7 +35,9 @@
 		for tax in tax_accounts:
 			row.append(item_tax.get(d.parent, {}).get(d.item_code, {}).get(tax, 0))
 			
-		row.append(sum(row[last_col:]))
+		total_tax = sum(row[last_col:])
+		row += [total_tax, d.amount + total_tax]
+		
 		data.append(row)
 	
 	return columns, data
@@ -100,6 +102,6 @@
 	
 	tax_accounts.sort()
 	columns += [account_head + ":Currency:80" for account_head in tax_accounts]
-	columns.append("Total:Currency:80")
+	columns += ["Total Tax:Currency:80", "Total:Currency:80"]
 
 	return item_tax, tax_accounts
\ No newline at end of file
diff --git a/accounts/report/purchase_register/purchase_register.py b/accounts/report/purchase_register/purchase_register.py
index 12b9316..0a4711f 100644
--- a/accounts/report/purchase_register/purchase_register.py
+++ b/accounts/report/purchase_register/purchase_register.py
@@ -31,7 +31,8 @@
 		return columns, invoice_list
 	
 	invoice_expense_map = get_invoice_expense_map(invoice_list)
-	invoice_expense_map, invoice_tax_map = get_invoice_tax_map(invoice_list, invoice_expense_map)
+	invoice_expense_map, invoice_tax_map = get_invoice_tax_map(invoice_list, 
+		invoice_expense_map, expense_accounts)
 	invoice_po_pr_map = get_invoice_po_pr_map(invoice_list)
 	account_map = get_account_details(invoice_list)
 
@@ -138,15 +139,18 @@
 	
 	return invoice_expense_map
 	
-def get_invoice_tax_map(invoice_list, invoice_expense_map):
+def get_invoice_tax_map(invoice_list, invoice_expense_map, expense_accounts):
 	tax_details = webnotes.conn.sql("""select parent, account_head, sum(tax_amount) as tax_amount
 		from `tabPurchase Taxes and Charges` where parent in (%s) group by parent, account_head""" % 
 		', '.join(['%s']*len(invoice_list)), tuple([inv.name for inv in invoice_list]), as_dict=1)
 	
 	invoice_tax_map = {}
 	for d in tax_details:
-		if d.account_head in invoice_expense_map.get(d.parent):
-			invoice_expense_map[d.parent][d.account_head] += flt(d.tax_amount)
+		if d.account_head in expense_accounts:
+			if invoice_expense_map[d.parent].has_key(d.account_head):
+				invoice_expense_map[d.parent][d.account_head] += flt(d.tax_amount)
+			else:
+				invoice_expense_map[d.parent][d.account_head] = flt(d.tax_amount)
 		else:
 			invoice_tax_map.setdefault(d.parent, webnotes._dict()).setdefault(d.account_head, [])
 			invoice_tax_map[d.parent][d.account_head] = flt(d.tax_amount)
@@ -180,4 +184,4 @@
 		where name in (%s)""" % ", ".join(["%s"]*len(accounts)), tuple(accounts), as_dict=1):
 			account_map[acc.name] = acc.parent_account
 						
-	return account_map	
+	return account_map
\ No newline at end of file
diff --git a/accounts/report/sales_register/sales_register.py b/accounts/report/sales_register/sales_register.py
index 653b5e6..87c5816 100644
--- a/accounts/report/sales_register/sales_register.py
+++ b/accounts/report/sales_register/sales_register.py
@@ -30,7 +30,8 @@
 		return columns, invoice_list
 	
 	invoice_income_map = get_invoice_income_map(invoice_list)
-	invoice_income_map, invoice_tax_map = get_invoice_tax_map(invoice_list, invoice_income_map)
+	invoice_income_map, invoice_tax_map = get_invoice_tax_map(invoice_list, 
+		invoice_income_map, income_accounts)
 	
 	invoice_so_dn_map = get_invoice_so_dn_map(invoice_list)
 	customer_map = get_customer_deatils(invoice_list)
@@ -137,15 +138,18 @@
 	
 	return invoice_income_map
 	
-def get_invoice_tax_map(invoice_list, invoice_income_map):
+def get_invoice_tax_map(invoice_list, invoice_income_map, income_accounts):
 	tax_details = webnotes.conn.sql("""select parent, account_head, sum(tax_amount) as tax_amount
 		from `tabSales Taxes and Charges` where parent in (%s) group by parent, account_head""" % 
 		', '.join(['%s']*len(invoice_list)), tuple([inv.name for inv in invoice_list]), as_dict=1)
 	
 	invoice_tax_map = {}
 	for d in tax_details:
-		if d.account_head in invoice_income_map.get(d.parent):
-			invoice_income_map[d.parent][d.account_head] += flt(d.tax_amount)
+		if d.account_head in income_accounts:
+			if invoice_income_map[d.parent].has_key(d.account_head):
+				invoice_income_map[d.parent][d.account_head] += flt(d.tax_amount)
+			else:
+				invoice_income_map[d.parent][d.account_head] = flt(d.tax_amount)
 		else:
 			invoice_tax_map.setdefault(d.parent, webnotes._dict()).setdefault(d.account_head, [])
 			invoice_tax_map[d.parent][d.account_head] = flt(d.tax_amount)
diff --git a/startup/schedule_handlers.py b/startup/schedule_handlers.py
index 99cc05b..28ff2ae 100644
--- a/startup/schedule_handlers.py
+++ b/startup/schedule_handlers.py
@@ -39,6 +39,10 @@
 	run_fn(flush)
 	
 def execute_daily():
+	# event reminders
+	from core.doctype.event.event import send_event_digest
+	run_fn(send_event_digest)
+	
 	# email digest
 	from setup.doctype.email_digest.email_digest import send
 	run_fn(send)