Merge pull request #2842 from nabinhait/foreign_currency_calc

Foreign currency calc
diff --git a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.js b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.js
index 6f16dcd..8040c41 100644
--- a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.js
+++ b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.js
@@ -3,7 +3,6 @@
 
 frappe.provide("erpnext.accounts");
 {% include 'buying/doctype/purchase_common/purchase_common.js' %};
-{% include 'accounts/doctype/purchase_taxes_and_charges_master/purchase_taxes_and_charges_master.js' %}
 
 erpnext.accounts.PurchaseInvoice = erpnext.buying.BuyingController.extend({
 	onload: function() {
diff --git a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.json b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.json
index eb756de..bd8199c 100755
--- a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.json
+++ b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.json
@@ -264,6 +264,16 @@
    "permlevel": 0
   }, 
   {
+   "fieldname": "base_total", 
+   "fieldtype": "Currency", 
+   "label": "Total (Company Currency)", 
+   "options": "Company:company:default_currency", 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 1, 
+   "read_only": 1
+  }, 
+  {
    "description": "Will be calculated automatically when you enter the details", 
    "fieldname": "base_net_total", 
    "fieldtype": "Currency", 
@@ -281,6 +291,17 @@
    "permlevel": 0
   }, 
   {
+   "fieldname": "total", 
+   "fieldtype": "Currency", 
+   "hidden": 0, 
+   "label": "Total", 
+   "options": "currency", 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 1, 
+   "read_only": 1
+  }, 
+  {
    "fieldname": "net_total", 
    "fieldtype": "Currency", 
    "label": "Net Total", 
@@ -373,35 +394,10 @@
    "read_only": 1
   }, 
   {
-   "fieldname": "base_grand_total", 
-   "fieldtype": "Currency", 
-   "label": "Grand Total (Company Currency)", 
-   "oldfieldname": "grand_total", 
-   "oldfieldtype": "Currency", 
-   "options": "Company:company:default_currency", 
-   "permlevel": 0, 
-   "print_hide": 1, 
-   "read_only": 1
-  }, 
-  {
-   "description": "In Words will be visible once you save the Purchase Invoice.", 
-   "fieldname": "base_in_words", 
-   "fieldtype": "Data", 
-   "label": "In Words (Company Currency)", 
-   "oldfieldname": "in_words", 
-   "oldfieldtype": "Data", 
-   "permlevel": 0, 
-   "print_hide": 1, 
-   "read_only": 1
-  }, 
-  {
-   "fieldname": "column_break8", 
+   "fieldname": "column_break_40", 
    "fieldtype": "Column Break", 
-   "oldfieldtype": "Column Break", 
    "permlevel": 0, 
-   "print_hide": 1, 
-   "read_only": 0, 
-   "width": "50%"
+   "precision": ""
   }, 
   {
    "fieldname": "taxes_and_charges_added", 
@@ -434,6 +430,84 @@
    "precision": ""
   }, 
   {
+   "fieldname": "section_break_44", 
+   "fieldtype": "Section Break", 
+   "permlevel": 0, 
+   "precision": ""
+  }, 
+  {
+   "default": "Grand Total", 
+   "fieldname": "apply_discount_on", 
+   "fieldtype": "Select", 
+   "label": "Apply Discount On", 
+   "options": "\nGrand Total\nNet Total", 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 1
+  }, 
+  {
+   "fieldname": "column_break_46", 
+   "fieldtype": "Column Break", 
+   "permlevel": 0, 
+   "precision": ""
+  }, 
+  {
+   "fieldname": "discount_amount", 
+   "fieldtype": "Currency", 
+   "label": "Discount Amount", 
+   "options": "currency", 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 1
+  }, 
+  {
+   "fieldname": "base_discount_amount", 
+   "fieldtype": "Currency", 
+   "label": "Discount Amount (Company Currency)", 
+   "options": "Company:company:default_currency", 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 1, 
+   "read_only": 1
+  }, 
+  {
+   "fieldname": "section_break_49", 
+   "fieldtype": "Section Break", 
+   "permlevel": 0, 
+   "precision": ""
+  }, 
+  {
+   "fieldname": "base_grand_total", 
+   "fieldtype": "Currency", 
+   "label": "Grand Total (Company Currency)", 
+   "oldfieldname": "grand_total", 
+   "oldfieldtype": "Currency", 
+   "options": "Company:company:default_currency", 
+   "permlevel": 0, 
+   "print_hide": 1, 
+   "read_only": 1
+  }, 
+  {
+   "description": "In Words will be visible once you save the Purchase Invoice.", 
+   "fieldname": "base_in_words", 
+   "fieldtype": "Data", 
+   "label": "In Words (Company Currency)", 
+   "oldfieldname": "in_words", 
+   "oldfieldtype": "Data", 
+   "permlevel": 0, 
+   "print_hide": 1, 
+   "read_only": 1
+  }, 
+  {
+   "fieldname": "column_break8", 
+   "fieldtype": "Column Break", 
+   "oldfieldtype": "Column Break", 
+   "permlevel": 0, 
+   "print_hide": 1, 
+   "read_only": 0, 
+   "width": "50%"
+  }, 
+  {
    "fieldname": "grand_total", 
    "fieldtype": "Currency", 
    "in_list_view": 1, 
@@ -888,7 +962,7 @@
  "icon": "icon-file-text", 
  "idx": 1, 
  "is_submittable": 1, 
- "modified": "2015-02-20 05:16:22.693978", 
+ "modified": "2015-02-23 15:33:28.554922", 
  "modified_by": "Administrator", 
  "module": "Accounts", 
  "name": "Purchase Invoice", 
diff --git a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py
index 4e0570f..a289c03 100644
--- a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py
+++ b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py
@@ -275,36 +275,36 @@
 		# tax table gl entries
 		valuation_tax = {}
 		for tax in self.get("taxes"):
-			if tax.category in ("Total", "Valuation and Total") and flt(tax.tax_amount):
+			if tax.category in ("Total", "Valuation and Total") and flt(tax.base_tax_amount_after_discount_amount):
 				gl_entries.append(
 					self.get_gl_dict({
 						"account": tax.account_head,
 						"against": self.credit_to,
-						"debit": tax.add_deduct_tax == "Add" and tax.tax_amount or 0,
-						"credit": tax.add_deduct_tax == "Deduct" and tax.tax_amount or 0,
+						"debit": tax.add_deduct_tax == "Add" and tax.base_tax_amount_after_discount_amount or 0,
+						"credit": tax.add_deduct_tax == "Deduct" and tax.base_tax_amount_after_discount_amount or 0,
 						"remarks": self.remarks,
 						"cost_center": tax.cost_center
 					})
 				)
 
 			# accumulate valuation tax
-			if tax.category in ("Valuation", "Valuation and Total") and flt(tax.tax_amount):
+			if tax.category in ("Valuation", "Valuation and Total") and flt(tax.base_tax_amount_after_discount_amount):
 				if auto_accounting_for_stock and not tax.cost_center:
 					frappe.throw(_("Cost Center is required in row {0} in Taxes table for type {1}").format(tax.idx, _(tax.category)))
 				valuation_tax.setdefault(tax.cost_center, 0)
 				valuation_tax[tax.cost_center] += \
-					(tax.add_deduct_tax == "Add" and 1 or -1) * flt(tax.tax_amount)
+					(tax.add_deduct_tax == "Add" and 1 or -1) * flt(tax.base_tax_amount_after_discount_amount)
 
 		# item gl entries
 		negative_expense_to_be_booked = 0.0
 		stock_items = self.get_stock_items()
 		for item in self.get("items"):
-			if flt(item.base_amount):
+			if flt(item.base_net_amount):
 				gl_entries.append(
 					self.get_gl_dict({
 						"account": item.expense_account,
 						"against": self.credit_to,
-						"debit": item.base_amount,
+						"debit": item.base_net_amount,
 						"remarks": self.remarks,
 						"cost_center": item.cost_center
 					})
diff --git a/erpnext/accounts/doctype/purchase_invoice_item/purchase_invoice_item.json b/erpnext/accounts/doctype/purchase_invoice_item/purchase_invoice_item.json
index 33ccb27..54b633b 100755
--- a/erpnext/accounts/doctype/purchase_invoice_item/purchase_invoice_item.json
+++ b/erpnext/accounts/doctype/purchase_invoice_item/purchase_invoice_item.json
@@ -195,6 +195,58 @@
    "read_only": 1
   }, 
   {
+   "fieldname": "section_break_22", 
+   "fieldtype": "Section Break", 
+   "permlevel": 0, 
+   "precision": ""
+  }, 
+  {
+   "fieldname": "net_rate", 
+   "fieldtype": "Currency", 
+   "label": "Net Rate", 
+   "options": "currency", 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 1, 
+   "read_only": 1
+  }, 
+  {
+   "fieldname": "net_amount", 
+   "fieldtype": "Currency", 
+   "label": "Net Amount", 
+   "options": "currency", 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 1, 
+   "read_only": 1
+  }, 
+  {
+   "fieldname": "column_break_25", 
+   "fieldtype": "Column Break", 
+   "permlevel": 0, 
+   "precision": ""
+  }, 
+  {
+   "fieldname": "base_net_rate", 
+   "fieldtype": "Currency", 
+   "label": "Net Rate (Company Currency)", 
+   "options": "Company:company:default_currency", 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 1, 
+   "read_only": 1
+  }, 
+  {
+   "fieldname": "base_net_amount", 
+   "fieldtype": "Currency", 
+   "label": "Net Amount (Company Currency)", 
+   "options": "Company:company:default_currency", 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 1, 
+   "read_only": 1
+  }, 
+  {
    "fieldname": "accounting", 
    "fieldtype": "Section Break", 
    "label": "Accounting", 
@@ -399,7 +451,7 @@
  ], 
  "idx": 1, 
  "istable": 1, 
- "modified": "2015-02-19 01:07:01.060411", 
+ "modified": "2015-02-23 15:35:32.895515", 
  "modified_by": "Administrator", 
  "module": "Accounts", 
  "name": "Purchase Invoice Item", 
diff --git a/erpnext/accounts/doctype/purchase_taxes_and_charges/purchase_taxes_and_charges.json b/erpnext/accounts/doctype/purchase_taxes_and_charges/purchase_taxes_and_charges.json
index 8244d12..057383a 100644
--- a/erpnext/accounts/doctype/purchase_taxes_and_charges/purchase_taxes_and_charges.json
+++ b/erpnext/accounts/doctype/purchase_taxes_and_charges/purchase_taxes_and_charges.json
@@ -53,17 +53,13 @@
    "read_only": 0
   }, 
   {
-   "fieldname": "description", 
-   "fieldtype": "Small Text", 
-   "in_list_view": 1, 
-   "label": "Description", 
-   "oldfieldname": "description", 
-   "oldfieldtype": "Small Text", 
+   "description": "If checked, the tax amount will be considered as already included in the Print Rate / Print Amount", 
+   "fieldname": "included_in_print_rate", 
+   "fieldtype": "Check", 
+   "label": "Is this Tax included in Basic Rate?", 
    "permlevel": 0, 
-   "print_width": "300px", 
-   "read_only": 0, 
-   "reqd": 1, 
-   "width": "300px"
+   "precision": "", 
+   "report_hide": 1
   }, 
   {
    "fieldname": "col_break1", 
@@ -95,6 +91,19 @@
    "read_only": 0
   }, 
   {
+   "fieldname": "description", 
+   "fieldtype": "Small Text", 
+   "in_list_view": 1, 
+   "label": "Description", 
+   "oldfieldname": "description", 
+   "oldfieldtype": "Small Text", 
+   "permlevel": 0, 
+   "print_width": "300px", 
+   "read_only": 0, 
+   "reqd": 1, 
+   "width": "300px"
+  }, 
+  {
    "fieldname": "rate", 
    "fieldtype": "Float", 
    "in_list_view": 1, 
@@ -106,25 +115,77 @@
    "reqd": 0
   }, 
   {
+   "fieldname": "section_break_9", 
+   "fieldtype": "Section Break", 
+   "permlevel": 0, 
+   "precision": ""
+  }, 
+  {
    "fieldname": "tax_amount", 
    "fieldtype": "Currency", 
    "in_list_view": 1, 
    "label": "Amount", 
    "oldfieldname": "tax_amount", 
    "oldfieldtype": "Currency", 
-   "options": "Company:company:default_currency", 
+   "options": "currency", 
    "permlevel": 0, 
    "read_only": 1, 
    "reqd": 0
   }, 
   {
+   "fieldname": "tax_amount_after_discount_amount", 
+   "fieldtype": "Currency", 
+   "label": "Tax Amount After Discount Amount", 
+   "options": "currency", 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 1, 
+   "read_only": 1
+  }, 
+  {
    "fieldname": "total", 
    "fieldtype": "Currency", 
    "label": "Total", 
    "oldfieldname": "total", 
    "oldfieldtype": "Currency", 
+   "options": "currency", 
+   "permlevel": 0, 
+   "read_only": 1
+  }, 
+  {
+   "fieldname": "column_break_14", 
+   "fieldtype": "Column Break", 
+   "permlevel": 0, 
+   "precision": ""
+  }, 
+  {
+   "fieldname": "base_tax_amount", 
+   "fieldtype": "Currency", 
+   "label": "Amount (Company Currency)", 
    "options": "Company:company:default_currency", 
    "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 1, 
+   "read_only": 1
+  }, 
+  {
+   "fieldname": "base_total", 
+   "fieldtype": "Currency", 
+   "hidden": 1, 
+   "label": "Total (Company Currency)", 
+   "options": "Company:company:default_currency", 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 1
+  }, 
+  {
+   "fieldname": "base_tax_amount_after_discount_amount", 
+   "fieldtype": "Currency", 
+   "label": "Tax Amount After Discount Amount", 
+   "options": "Company:company:default_currency", 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 1, 
    "read_only": 1
   }, 
   {
@@ -155,7 +216,7 @@
  "hide_heading": 1, 
  "idx": 1, 
  "istable": 1, 
- "modified": "2015-02-19 01:07:01.581115", 
+ "modified": "2015-02-23 15:01:31.895131", 
  "modified_by": "Administrator", 
  "module": "Accounts", 
  "name": "Purchase Taxes and Charges", 
diff --git a/erpnext/accounts/doctype/purchase_taxes_and_charges_master/purchase_taxes_and_charges_master.js b/erpnext/accounts/doctype/purchase_taxes_and_charges_master/purchase_taxes_and_charges_master.js
index 4f91c56..09f2e8d 100644
--- a/erpnext/accounts/doctype/purchase_taxes_and_charges_master/purchase_taxes_and_charges_master.js
+++ b/erpnext/accounts/doctype/purchase_taxes_and_charges_master/purchase_taxes_and_charges_master.js
@@ -3,78 +3,7 @@
 
 {% include "public/js/controllers/accounts.js" %}
 
-cur_frm.cscript.refresh = function(doc, cdt, cdn) {
-	cur_frm.set_footnote(frappe.markdown(cur_frm.meta.description));
-}
-
-// For customizing print
-cur_frm.pformat.net_total = function(doc) {
-	return '';
-}
-
-cur_frm.pformat.grand_total = function(doc) {
-	return '';
-}
-
-cur_frm.pformat.in_words = function(doc) {
-	return '';
-}
-
-cur_frm.pformat.taxes= function(doc) {
-
-	//function to make row of table
-	var make_row = function(title, val, bold) {
-		var bstart = '<b>'; var bend = '</b>';
-		return '<tr><td style="width:50%;">' + (bold?bstart:'') + title + (bold?bend:'') + '</td>'
-			+ '<td style="width:25%;text-align:right;"></td>'
-			+ '<td style="width:25%;text-align:right;">' + format_currency(val, doc.currency) + '</td>'
-			+ '</tr>';
-	}
-
-	function convert_rate(val) {
-		var new_val = flt(val)/flt(doc.conversion_rate);
-		return new_val;
-	}
-
-	function print_hide(fieldname) {
-		var doc_field = frappe.meta.get_docfield(doc.doctype, fieldname, doc.name);
-		return doc_field.print_hide;
-	}
-
-	var cl = doc.taxes || [];
-
-	// outer table
-	var out='<div><table class="noborder" style="width:100%">\
-	<tr><td style="width: 60%"></td><td>';
-
-	// main table
-	out +='<table class="noborder" style="width:100%">';
-	if(!print_hide('net_total'))
-		out += make_row('Net Total', doc.net_total, 1);
-
-	// add rows
-	if(cl.length){
-		for(var i=0; i<cl.length; i++) {
-			out += make_row(cl[i].description, convert_rate(cl[i].tax_amount), 0);
-		}
-	}
-
-	// grand total
-	if(!print_hide('grand_total'))
-		out += make_row('Grand Total', doc.grand_total, 1);
-
-	if(doc.in_words && !print_hide('in_words')) {
-		out += '</table></td></tr>';
-		out += '<tr><td colspan = "2">';
-		out += '<table><tr><td style="width:25%;"><b>In Words</b></td>';
-		out += '<td style="width:50%;">' + doc.in_words + '</td></tr>';
-	}
-
-	out +='</table></td></tr></table></div>';
-	return out;
-}
-
-cur_frm.cscript.add_deduct_tax = function(doc, cdt, cdn) {
+frappe.ui.form.on("Purchase Taxes and Charges", "add_deduct_tax", function(doc, cdt, cdn) {
 	var d = locals[cdt][cdn];
 
 	if(!d.category && d.add_deduct_tax) {
@@ -85,96 +14,5 @@
 		msgprint(__("Cannot deduct when category is for 'Valuation' or 'Valuation and Total'"));
 		d.add_deduct_tax = '';
 	}
-}
-
-cur_frm.cscript.charge_type = function(doc, cdt, cdn) {
-	var d = locals[cdt][cdn];
-
-	if(!d.category && d.charge_type) {
-		msgprint(__("Please select Category first"));
-		d.charge_type = '';
-	}
-	else if(d.idx == 1 && (d.charge_type == 'On Previous Row Amount' || d.charge_type == 'On Previous Row Total')) {
-		msgprint(__("Cannot select charge type as 'On Previous Row Amount' or 'On Previous Row Total' for first row"));
-		d.charge_type = '';
-	}
-	else if((d.category == 'Valuation' || d.category == 'Valuation and Total') && (d.charge_type == 'On Previous Row Amount' || d.charge_type == 'On Previous Row Total')) {
-		msgprint(__("Cannot select charge type as 'On Previous Row Amount' or 'On Previous Row Total' for valuation. You can select only 'Total' option for previous row amount or previous row total"));
-		d.charge_type = '';
-	}
-
-	validated = false;
-	refresh_field('charge_type', d.name, 'taxes');
-
-	cur_frm.cscript.row_id(doc, cdt, cdn);
-	cur_frm.cscript.rate(doc, cdt, cdn);
-	cur_frm.cscript.tax_amount(doc, cdt, cdn);
-}
-
-
-cur_frm.cscript.row_id = function(doc, cdt, cdn) {
-	var d = locals[cdt][cdn];
-
-	if(!d.charge_type && d.row_id) {
-		msgprint(__("Please select charge type first"));
-		d.row_id = '';
-	}
-	else if((d.charge_type == 'Actual' || d.charge_type == 'On Net Total') && d.row_id) {
-		msgprint(__("Can refer row only if the charge type is 'On Previous Row Amount' or 'Previous Row Total'"));
-		d.row_id = '';
-	}
-	else if((d.charge_type == 'On Previous Row Amount' || d.charge_type == 'On Previous Row Total') && d.row_id) {
-		if(d.row_id >= d.idx){
-			msgprint(__("Cannot refer row number greater than or equal to current row number for this Charge type"));
-			d.row_id = '';
-		}
-	}
-	validated = false;
-	refresh_field('row_id', d.name, 'taxes');
-}
-
-cur_frm.set_query("account_head", "taxes", function(doc) {
-	return {
-		query: "erpnext.controllers.queries.tax_account_query",
-		filters: {
-			"account_type": ["Tax", "Chargeable", "Expense Account"],
-			"company": doc.company
-		}
-	}
+	refresh_field('add_deduct_tax', d.name, 'taxes');
 });
-
-cur_frm.fields_dict['taxes'].grid.get_field("cost_center").get_query = function(doc) {
-	return {
-		filters: {
-			'company': doc.company,
-			'group_or_ledger': "Ledger"
-		}
-	}
-}
-
-cur_frm.cscript.rate = function(doc, cdt, cdn) {
-	var d = locals[cdt][cdn];
-
-	if(!d.charge_type && d.rate) {
-		msgprint(__("Please select Charge Type first"));
-		d.rate = '';
-	}
-	validated = false;
-	refresh_field('rate', d.name, 'taxes');
-}
-
-cur_frm.cscript.tax_amount = function(doc, cdt, cdn) {
-	var d = locals[cdt][cdn];
-
-	if(!d.charge_type && d.tax_amount) {
-		msgprint(__("Please select Charge Type first"));
-		d.tax_amount = '';
-	}
-	else if(d.charge_type && d.tax_amount) {
-		msgprint(__("Cannot directly set amount. For 'Actual' charge type, use the rate field"));
-		d.tax_amount = '';
-	}
-
-	validated = false;
-	refresh_field('tax_amount', d.name, 'taxes');
-}
diff --git a/erpnext/accounts/doctype/purchase_taxes_and_charges_master/purchase_taxes_and_charges_master.py b/erpnext/accounts/doctype/purchase_taxes_and_charges_master/purchase_taxes_and_charges_master.py
index e93c572..b004a2e 100644
--- a/erpnext/accounts/doctype/purchase_taxes_and_charges_master/purchase_taxes_and_charges_master.py
+++ b/erpnext/accounts/doctype/purchase_taxes_and_charges_master/purchase_taxes_and_charges_master.py
@@ -2,8 +2,11 @@
 # License: GNU General Public License v3. See license.txt
 
 from __future__ import unicode_literals
-import frappe
 from frappe.model.document import Document
+from erpnext.controllers.accounts_controller import validate_taxes_and_charges, validate_inclusive_tax
 
 class PurchaseTaxesandChargesMaster(Document):
-	pass
+	def validate(self):
+		for tax in self.get("taxes"):
+			validate_taxes_and_charges(tax)
+			validate_inclusive_tax(tax, self)
diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.js b/erpnext/accounts/doctype/sales_invoice/sales_invoice.js
index bbc0dd2..4670303 100644
--- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.js
+++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.js
@@ -5,7 +5,6 @@
 cur_frm.pformat.print_heading = 'Invoice';
 
 {% include 'selling/sales_common.js' %};
-{% include 'accounts/doctype/sales_taxes_and_charges_master/sales_taxes_and_charges_master.js' %}
 
 frappe.provide("erpnext.accounts");
 erpnext.accounts.SalesInvoiceController = erpnext.selling.SellingController.extend({
diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.json b/erpnext/accounts/doctype/sales_invoice/sales_invoice.json
index 61eb191..d7837a2 100644
--- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.json
+++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.json
@@ -332,6 +332,16 @@
    "permlevel": 0
   }, 
   {
+   "fieldname": "base_total", 
+   "fieldtype": "Currency", 
+   "label": "Total (Company Currency)", 
+   "options": "Company:company:default_currency", 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 1, 
+   "read_only": 1
+  }, 
+  {
    "fieldname": "base_net_total", 
    "fieldtype": "Currency", 
    "label": "Net Total (Company Currency)", 
@@ -349,6 +359,16 @@
    "permlevel": 0
   }, 
   {
+   "fieldname": "total", 
+   "fieldtype": "Currency", 
+   "label": "Total", 
+   "options": "currency", 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 1, 
+   "read_only": 1
+  }, 
+  {
    "fieldname": "net_total", 
    "fieldtype": "Currency", 
    "label": "Net Total", 
@@ -432,6 +452,12 @@
    "read_only": 1
   }, 
   {
+   "fieldname": "column_break_47", 
+   "fieldtype": "Column Break", 
+   "permlevel": 0, 
+   "precision": ""
+  }, 
+  {
    "fieldname": "base_total_taxes_and_charges", 
    "fieldtype": "Currency", 
    "label": "Total Taxes and Charges (Company Currency)", 
@@ -443,7 +469,23 @@
    "read_only": 1
   }, 
   {
-   "fieldname": "column_break_45", 
+   "fieldname": "section_break_49", 
+   "fieldtype": "Section Break", 
+   "permlevel": 0, 
+   "precision": ""
+  }, 
+  {
+   "default": "Grand Total", 
+   "fieldname": "apply_discount_on", 
+   "fieldtype": "Select", 
+   "label": "Apply Discount On", 
+   "options": "\nGrand Total\nNet Total", 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 1
+  }, 
+  {
+   "fieldname": "column_break_51", 
    "fieldtype": "Column Break", 
    "permlevel": 0
   }, 
@@ -1202,7 +1244,7 @@
  "icon": "icon-file-text", 
  "idx": 1, 
  "is_submittable": 1, 
- "modified": "2015-02-20 05:16:19.256361", 
+ "modified": "2015-02-23 15:53:37.894033", 
  "modified_by": "Administrator", 
  "module": "Accounts", 
  "name": "Sales Invoice", 
diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py
index f3ff9e1..3b901c4 100644
--- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py
+++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py
@@ -496,12 +496,12 @@
 
 	def make_tax_gl_entries(self, gl_entries):
 		for tax in self.get("taxes"):
-			if flt(tax.tax_amount_after_discount_amount):
+			if flt(tax.base_tax_amount_after_discount_amount):
 				gl_entries.append(
 					self.get_gl_dict({
 						"account": tax.account_head,
 						"against": self.debit_to,
-						"credit": flt(tax.tax_amount_after_discount_amount),
+						"credit": flt(tax.base_tax_amount_after_discount_amount),
 						"remarks": self.remarks,
 						"cost_center": tax.cost_center
 					})
@@ -510,12 +510,12 @@
 	def make_item_gl_entries(self, gl_entries):
 		# income account gl entries
 		for item in self.get("items"):
-			if flt(item.base_amount):
+			if flt(item.base_net_amount):
 				gl_entries.append(
 					self.get_gl_dict({
 						"account": item.income_account,
 						"against": self.debit_to,
-						"credit": item.base_amount,
+						"credit": item.base_net_amount,
 						"remarks": self.remarks,
 						"cost_center": item.cost_center
 					})
diff --git a/erpnext/accounts/doctype/sales_invoice_item/sales_invoice_item.json b/erpnext/accounts/doctype/sales_invoice_item/sales_invoice_item.json
index b87c632..e720f1b 100644
--- a/erpnext/accounts/doctype/sales_invoice_item/sales_invoice_item.json
+++ b/erpnext/accounts/doctype/sales_invoice_item/sales_invoice_item.json
@@ -202,6 +202,58 @@
    "read_only": 1
   }, 
   {
+   "fieldname": "section_break_21", 
+   "fieldtype": "Section Break", 
+   "permlevel": 0, 
+   "precision": ""
+  }, 
+  {
+   "fieldname": "net_rate", 
+   "fieldtype": "Currency", 
+   "label": "Net Rate", 
+   "options": "currency", 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 1, 
+   "read_only": 1
+  }, 
+  {
+   "fieldname": "net_amount", 
+   "fieldtype": "Currency", 
+   "label": "Net Amount", 
+   "options": "currency", 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 1, 
+   "read_only": 1
+  }, 
+  {
+   "fieldname": "column_break_24", 
+   "fieldtype": "Column Break", 
+   "permlevel": 0, 
+   "precision": ""
+  }, 
+  {
+   "fieldname": "base_net_rate", 
+   "fieldtype": "Currency", 
+   "label": "Net Rate (Company Currency)", 
+   "options": "Company:company:default_currency", 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 1, 
+   "read_only": 1
+  }, 
+  {
+   "fieldname": "base_net_amount", 
+   "fieldtype": "Currency", 
+   "label": "Net Amount (Company Currency)", 
+   "options": "Company:company:default_currency", 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 1, 
+   "read_only": 1
+  }, 
+  {
    "fieldname": "accounting", 
    "fieldtype": "Section Break", 
    "label": "Accounting", 
@@ -439,7 +491,7 @@
  ], 
  "idx": 1, 
  "istable": 1, 
- "modified": "2015-02-19 01:07:01.862525", 
+ "modified": "2015-02-23 15:55:23.143072", 
  "modified_by": "Administrator", 
  "module": "Accounts", 
  "name": "Sales Invoice Item", 
diff --git a/erpnext/accounts/doctype/sales_taxes_and_charges/sales_taxes_and_charges.json b/erpnext/accounts/doctype/sales_taxes_and_charges/sales_taxes_and_charges.json
index 06c981f..2322550 100644
--- a/erpnext/accounts/doctype/sales_taxes_and_charges/sales_taxes_and_charges.json
+++ b/erpnext/accounts/doctype/sales_taxes_and_charges/sales_taxes_and_charges.json
@@ -1,5 +1,5 @@
 {
- "autoname": "hash", 
+ "autoname": "INVTD.######", 
  "creation": "2013-04-24 11:39:32", 
  "docstatus": 0, 
  "doctype": "DocType", 
@@ -26,24 +26,6 @@
    "permlevel": 0
   }, 
   {
-   "fieldname": "description", 
-   "fieldtype": "Small Text", 
-   "in_list_view": 1, 
-   "label": "Description", 
-   "oldfieldname": "description", 
-   "oldfieldtype": "Small Text", 
-   "permlevel": 0, 
-   "print_width": "300px", 
-   "reqd": 1, 
-   "width": "300px"
-  }, 
-  {
-   "fieldname": "col_break_1", 
-   "fieldtype": "Column Break", 
-   "permlevel": 0, 
-   "width": "50%"
-  }, 
-  {
    "fieldname": "account_head", 
    "fieldtype": "Link", 
    "in_list_view": 0, 
@@ -77,26 +59,22 @@
    "reqd": 1
   }, 
   {
-   "fieldname": "tax_amount", 
-   "fieldtype": "Currency", 
-   "in_list_view": 1, 
-   "label": "Amount", 
-   "oldfieldname": "tax_amount", 
-   "oldfieldtype": "Currency", 
-   "options": "Company:company:default_currency", 
+   "fieldname": "col_break_1", 
+   "fieldtype": "Column Break", 
    "permlevel": 0, 
-   "read_only": 1, 
-   "reqd": 0
+   "width": "50%"
   }, 
   {
-   "fieldname": "total", 
-   "fieldtype": "Currency", 
-   "label": "Total", 
-   "oldfieldname": "total", 
-   "oldfieldtype": "Currency", 
-   "options": "Company:company:default_currency", 
+   "fieldname": "description", 
+   "fieldtype": "Small Text", 
+   "in_list_view": 1, 
+   "label": "Description", 
+   "oldfieldname": "description", 
+   "oldfieldtype": "Small Text", 
    "permlevel": 0, 
-   "read_only": 1
+   "print_width": "300px", 
+   "reqd": 1, 
+   "width": "300px"
   }, 
   {
    "allow_on_submit": 0, 
@@ -112,11 +90,72 @@
    "width": "150px"
   }, 
   {
-   "depends_on": "eval:parent.discount_amount", 
+   "fieldname": "section_break_9", 
+   "fieldtype": "Section Break", 
+   "permlevel": 0, 
+   "precision": ""
+  }, 
+  {
+   "fieldname": "tax_amount", 
+   "fieldtype": "Currency", 
+   "in_list_view": 1, 
+   "label": "Amount", 
+   "options": "currency", 
+   "permlevel": 0, 
+   "precision": ""
+  }, 
+  {
+   "fieldname": "total", 
+   "fieldtype": "Currency", 
+   "label": "Total", 
+   "options": "currency", 
+   "permlevel": 0, 
+   "precision": "", 
+   "read_only": 1
+  }, 
+  {
    "fieldname": "tax_amount_after_discount_amount", 
    "fieldtype": "Currency", 
-   "hidden": 0, 
    "label": "Tax Amount After Discount Amount", 
+   "options": "currency", 
+   "permlevel": 0, 
+   "precision": "", 
+   "read_only": 1
+  }, 
+  {
+   "fieldname": "column_break_13", 
+   "fieldtype": "Column Break", 
+   "permlevel": 0, 
+   "precision": ""
+  }, 
+  {
+   "fieldname": "base_tax_amount", 
+   "fieldtype": "Currency", 
+   "in_list_view": 0, 
+   "label": "Amount (Company Currency)", 
+   "oldfieldname": "tax_amount", 
+   "oldfieldtype": "Currency", 
+   "options": "Company:company:default_currency", 
+   "permlevel": 0, 
+   "read_only": 1, 
+   "reqd": 0
+  }, 
+  {
+   "fieldname": "base_total", 
+   "fieldtype": "Currency", 
+   "label": "Total (Company Currency)", 
+   "oldfieldname": "total", 
+   "oldfieldtype": "Currency", 
+   "options": "Company:company:default_currency", 
+   "permlevel": 0, 
+   "read_only": 1
+  }, 
+  {
+   "depends_on": "eval:parent.discount_amount", 
+   "fieldname": "base_tax_amount_after_discount_amount", 
+   "fieldtype": "Currency", 
+   "hidden": 0, 
+   "label": "Tax Amount After Discount Amount (Company Currency)", 
    "options": "Company:company:default_currency", 
    "permlevel": 0, 
    "read_only": 1
@@ -147,7 +186,7 @@
  "hide_heading": 1, 
  "idx": 1, 
  "istable": 1, 
- "modified": "2015-02-19 01:07:02.165094", 
+ "modified": "2015-02-23 12:36:02.213508", 
  "modified_by": "Administrator", 
  "module": "Accounts", 
  "name": "Sales Taxes and Charges", 
diff --git a/erpnext/accounts/doctype/sales_taxes_and_charges_master/sales_taxes_and_charges_master.js b/erpnext/accounts/doctype/sales_taxes_and_charges_master/sales_taxes_and_charges_master.js
index af744e9..b5dc38f 100644
--- a/erpnext/accounts/doctype/sales_taxes_and_charges_master/sales_taxes_and_charges_master.js
+++ b/erpnext/accounts/doctype/sales_taxes_and_charges_master/sales_taxes_and_charges_master.js
@@ -7,168 +7,3 @@
 	if(doc.doctype === "Sales Taxes and Charges Master")
 		erpnext.add_applicable_territory();
 }
-
-cur_frm.cscript.refresh = function(doc, cdt, cdn) {
-	cur_frm.set_footnote(frappe.markdown(cur_frm.meta.description));
-}
-
-// For customizing print
-cur_frm.pformat.net_total = function(doc) {
-	return '';
-}
-
-cur_frm.pformat.discount_amount = function(doc) {
-	return '';
-}
-
-cur_frm.pformat.grand_total = function(doc) {
-	return '';
-}
-
-cur_frm.pformat.rounded_total = function(doc) {
-	return '';
-}
-
-cur_frm.pformat.in_words = function(doc) {
-	return '';
-}
-
-cur_frm.pformat.taxes= function(doc){
-	//function to make row of table
-	var make_row = function(title, val, bold){
-		var bstart = '<b>'; var bend = '</b>';
-		return '<tr><td style="width:50%;">' + (bold?bstart:'') + title + (bold?bend:'') + '</td>'
-			+ '<td style="width:50%;text-align:right;">' + format_currency(val, doc.currency) + '</td>'
-			+ '</tr>';
-	}
-
-	function convert_rate(val) {
-		var new_val = flt(val)/flt(doc.conversion_rate);
-		return new_val;
-	}
-
-	function print_hide(fieldname) {
-		var doc_field = frappe.meta.get_docfield(doc.doctype, fieldname, doc.name);
-		return doc_field.print_hide;
-	}
-
-	out ='';
-	if (!doc.print_without_amount) {
-		var cl = doc.taxes || [];
-
-		// outer table
-		var out='<div><table class="noborder" style="width:100%"><tr><td style="width: 60%"></td><td>';
-
-		// main table
-
-		out +='<table class="noborder" style="width:100%">';
-
-		if(!print_hide('net_total')) {
-			out += make_row('Net Total', doc.net_total, 1);
-		}
-
-		// add rows
-		if(cl.length){
-			for(var i=0;i<cl.length;i++) {
-				if(convert_rate(cl[i].tax_amount)!=0 && !cl[i].included_in_print_rate)
-					out += make_row(cl[i].description, convert_rate(cl[i].tax_amount), 0);
-			}
-		}
-
-		// Discount Amount
-		if(!print_hide('discount_amount') && doc.discount_amount)
-			out += make_row('Discount Amount', doc.discount_amount, 0);
-
-		// grand total
-		if(!print_hide('grand_total'))
-			out += make_row('Grand Total', doc.grand_total, 1);
-
-		if(!print_hide('rounded_total'))
-			out += make_row('Rounded Total', doc.rounded_total, 1);
-
-		if(doc.in_words && !print_hide('in_words')) {
-			out +='</table></td></tr>';
-			out += '<tr><td colspan = "2">';
-			out += '<table><tr><td style="width:25%;"><b>In Words</b></td>';
-			out += '<td style="width:50%;">' + doc.in_words + '</td></tr>';
-		}
-		out += '</table></td></tr></table></div>';
-	}
-	return out;
-}
-
-cur_frm.cscript.charge_type = function(doc, cdt, cdn) {
-	var d = locals[cdt][cdn];
-	if(d.idx == 1 && (d.charge_type == 'On Previous Row Amount' || d.charge_type == 'On Previous Row Total')) {
-		msgprint(__("Cannot select charge type as 'On Previous Row Amount' or 'On Previous Row Total' for first row"));
-		d.charge_type = '';
-	}
-	validated = false;
-	refresh_field('charge_type', d.name, 'taxes');
-	cur_frm.cscript.row_id(doc, cdt, cdn);
-	cur_frm.cscript.rate(doc, cdt, cdn);
-	cur_frm.cscript.tax_amount(doc, cdt, cdn);
-}
-
-cur_frm.cscript.row_id = function(doc, cdt, cdn) {
-	var d = locals[cdt][cdn];
-	if(!d.charge_type && d.row_id) {
-		msgprint(__("Please select Charge Type first"));
-		d.row_id = '';
-	}
-	else if((d.charge_type == 'Actual' || d.charge_type == 'On Net Total') && d.row_id) {
-		msgprint(__("Can refer row only if the charge type is 'On Previous Row Amount' or 'Previous Row Total'"));
-		d.row_id = '';
-	}
-	else if((d.charge_type == 'On Previous Row Amount' || d.charge_type == 'On Previous Row Total') && d.row_id) {
-		if(d.row_id >= d.idx){
-			msgprint(__("Cannot refer row number greater than or equal to current row number for this Charge type"));
-			d.row_id = '';
-		}
-	}
-	validated = false;
-	refresh_field('row_id', d.name, 'taxes');
-}
-
-/*---------------------- Get rate if account_head has account_type as TAX or CHARGEABLE-------------------------------------*/
-
-cur_frm.fields_dict['taxes'].grid.get_field("account_head").get_query = function(doc,cdt,cdn) {
-	return{
-		query: "erpnext.controllers.queries.tax_account_query",
-    	filters: {
-			"account_type": ["Tax", "Chargeable", "Income Account"],
-			"company": doc.company
-		}
-	}
-}
-
-cur_frm.fields_dict['taxes'].grid.get_field("cost_center").get_query = function(doc) {
-	return{
-		'company': doc.company,
-		'group_or_ledger': "Ledger"
-	}
-}
-
-cur_frm.cscript.rate = function(doc, cdt, cdn) {
-	var d = locals[cdt][cdn];
-	if(!d.charge_type && d.rate) {
-		msgprint(__("Please select Charge Type first"));
-		d.rate = '';
-	}
-	validated = false;
-	refresh_field('rate', d.name, 'taxes');
-}
-
-cur_frm.cscript.tax_amount = function(doc, cdt, cdn) {
-	var d = locals[cdt][cdn];
-	if(!d.charge_type && d.tax_amount) {
-		msgprint(__("Please select Charge Type first"));
-		d.tax_amount = '';
-	}
-	else if(d.charge_type && d.tax_amount) {
-		msgprint(__("Cannot directly set amount. For 'Actual' charge type, use the rate field"));
-		d.tax_amount = '';
-	}
-	validated = false;
-	refresh_field('tax_amount', d.name, 'taxes');
-};
diff --git a/erpnext/accounts/doctype/sales_taxes_and_charges_master/sales_taxes_and_charges_master.py b/erpnext/accounts/doctype/sales_taxes_and_charges_master/sales_taxes_and_charges_master.py
index 6ab5ab2..4317f2a 100644
--- a/erpnext/accounts/doctype/sales_taxes_and_charges_master/sales_taxes_and_charges_master.py
+++ b/erpnext/accounts/doctype/sales_taxes_and_charges_master/sales_taxes_and_charges_master.py
@@ -3,8 +3,8 @@
 
 from __future__ import unicode_literals
 import frappe
-from frappe.utils import cint
 from frappe.model.document import Document
+from erpnext.controllers.accounts_controller import validate_taxes_and_charges, validate_inclusive_tax
 
 class SalesTaxesandChargesMaster(Document):
 	def validate(self):
@@ -15,3 +15,8 @@
 
 		# at least one territory
 		self.validate_table_has_rows("territories")
+
+		for tax in self.get("taxes"):
+			validate_taxes_and_charges(tax)
+			validate_inclusive_tax(tax, self)
+
diff --git a/erpnext/accounts/report/gross_profit/gross_profit.py b/erpnext/accounts/report/gross_profit/gross_profit.py
index d212965..7ea9af9 100644
--- a/erpnext/accounts/report/gross_profit/gross_profit.py
+++ b/erpnext/accounts/report/gross_profit/gross_profit.py
@@ -95,7 +95,7 @@
 			if self.skip_row(row, self.sales_boms):
 				continue
 
-			row.selling_amount = flt(row.base_amount)
+			row.selling_amount = flt(row.base_net_amount)
 
 			sales_boms = self.sales_boms.get(row.parenttype, {}).get(row.name, frappe._dict())
 
@@ -175,7 +175,7 @@
 		# sorted by posting_date desc, posting_time desc
 		if item_code in self.non_stock_items:
 			# average purchasing rate for non-stock items
-			item_rate = frappe.db.sql("""select sum(base_amount) / sum(qty)
+			item_rate = frappe.db.sql("""select sum(base_net_amount) / sum(qty)
 				from `tabPurchase Invoice Item`
 				where item_code = %s and docstatus=1""", item_code)
 
@@ -211,7 +211,7 @@
 				si.customer, si.customer_group, si.territory,
 				item.item_code, item.item_name, item.description, item.warehouse,
 				item.item_group, item.brand, item.dn_detail, item.delivery_note,
-				item.qty, item.base_rate, item.base_amount, item.name as "item_row",
+				item.qty, item.base_net_rate, item.base_net_amount, item.name as "item_row",
 				sales.sales_person, sales.sales_designation, sales.allocated_amount,
 				sales.incentives
 			from `tabSales Invoice` si
diff --git a/erpnext/accounts/report/item_wise_purchase_register/item_wise_purchase_register.py b/erpnext/accounts/report/item_wise_purchase_register/item_wise_purchase_register.py
index 27f1249..4a8427e 100644
--- a/erpnext/accounts/report/item_wise_purchase_register/item_wise_purchase_register.py
+++ b/erpnext/accounts/report/item_wise_purchase_register/item_wise_purchase_register.py
@@ -28,13 +28,13 @@
 		expense_account = d.expense_account or aii_account_map.get(d.company)
 		row = [d.item_code, d.item_name, d.item_group, d.parent, d.posting_date, d.supplier,
 			d.supplier_name, d.credit_to, d.project_name, d.company, d.purchase_order,
-			purchase_receipt, expense_account, d.qty, d.base_rate, d.base_amount]
+			purchase_receipt, expense_account, d.qty, d.base_net_rate, d.base_net_amount]
 
 		for tax in tax_accounts:
 			row.append(item_tax.get(d.parent, {}).get(d.item_code, {}).get(tax, 0))
 
 		total_tax = sum(row[last_col:])
-		row += [total_tax, d.base_amount + total_tax]
+		row += [total_tax, d.base_net_amount + total_tax]
 
 		data.append(row)
 
@@ -70,7 +70,7 @@
 	return frappe.db.sql("""select pi_item.parent, pi.posting_date, pi.credit_to, pi.company,
 		pi.supplier, pi.remarks, pi.base_net_total, pi_item.item_code, pi_item.item_name, pi_item.item_group,
 		pi_item.project_name, pi_item.purchase_order, pi_item.purchase_receipt, pi_item.po_detail
-		pi_item.expense_account, pi_item.qty, pi_item.base_rate, pi_item.base_amount, pi.supplier_name
+		pi_item.expense_account, pi_item.qty, pi_item.base_net_rate, pi_item.base_net_amount, pi.supplier_name
 		from `tabPurchase Invoice` pi, `tabPurchase Invoice Item` pi_item
 		where pi.name = pi_item.parent and pi.docstatus = 1 %s %s
 		order by pi.posting_date desc, pi_item.item_code desc""" % (conditions, match_conditions), filters, as_dict=1)
@@ -86,7 +86,7 @@
 	for d in item_list:
 		invoice_wise_items.setdefault(d.parent, []).append(d)
 
-	tax_details = frappe.db.sql("""select parent, account_head, item_wise_tax_detail, charge_type, tax_amount
+	tax_details = frappe.db.sql("""select parent, account_head, item_wise_tax_detail, charge_type, base_tax_amount_after_discount_amount
 		from `tabPurchase Taxes and Charges` where parenttype = 'Purchase Invoice'
 		and docstatus = 1 and ifnull(account_head, '') != '' and category in ('Total', 'Valuation and Total')
 		and parent in (%s)""" % ', '.join(['%s']*len(invoice_wise_items)), tuple(invoice_wise_items.keys()))
@@ -107,7 +107,7 @@
 		elif charge_type == "Actual" and tax_amount:
 			for d in invoice_wise_items.get(parent, []):
 				item_tax.setdefault(parent, {}).setdefault(d.item_code, {})[account_head] = \
-					(tax_amount * d.base_amount) / d.base_net_total
+					(tax_amount * d.base_net_amount) / d.base_net_total
 
 	tax_accounts.sort()
 	columns += [account_head + ":Currency:80" for account_head in tax_accounts]
diff --git a/erpnext/accounts/report/item_wise_sales_register/item_wise_sales_register.py b/erpnext/accounts/report/item_wise_sales_register/item_wise_sales_register.py
index fef397f..524773e 100644
--- a/erpnext/accounts/report/item_wise_sales_register/item_wise_sales_register.py
+++ b/erpnext/accounts/report/item_wise_sales_register/item_wise_sales_register.py
@@ -26,13 +26,13 @@
 
 		row = [d.item_code, d.item_name, d.item_group, d.parent, d.posting_date, d.customer, d.customer_name,
 			d.customer_group, d.debit_to, d.territory, d.project_name, d.company, d.sales_order,
-			delivery_note, d.income_account, d.qty, d.base_rate, d.base_amount]
+			delivery_note, d.income_account, d.qty, d.base_net_rate, d.base_net_amount]
 
 		for tax in tax_accounts:
 			row.append(item_tax.get(d.parent, {}).get(d.item_code, {}).get(tax, 0))
 
 		total_tax = sum(row[last_col:])
-		row += [total_tax, d.base_amount + total_tax]
+		row += [total_tax, d.base_net_amount + total_tax]
 
 		data.append(row)
 
@@ -69,7 +69,7 @@
 	return frappe.db.sql("""select si_item.parent, si.posting_date, si.debit_to, si.project_name,
 		si.customer, si.remarks, si.territory, si.company, si.base_net_total, si_item.item_code, si_item.item_name,
 		si_item.item_group, si_item.sales_order, si_item.delivery_note, si_item.income_account,
-		si_item.qty, si_item.base_rate, si_item.base_amount, si.customer_name,
+		si_item.qty, si_item.base_net_rate, si_item.base_net_amount, si.customer_name,
 		si.customer_group, si_item.so_detail
 		from `tabSales Invoice` si, `tabSales Invoice Item` si_item
 		where si.name = si_item.parent and si.docstatus = 1 %s
@@ -83,7 +83,8 @@
 	for d in item_list:
 		invoice_wise_items.setdefault(d.parent, []).append(d)
 
-	tax_details = frappe.db.sql("""select parent, account_head, item_wise_tax_detail, charge_type, tax_amount
+	tax_details = frappe.db.sql("""select parent, account_head, item_wise_tax_detail,
+		charge_type, base_tax_amount_after_discount_amount
 		from `tabSales Taxes and Charges` where parenttype = 'Sales Invoice'
 		and docstatus = 1 and ifnull(account_head, '') != ''
 		and parent in (%s)""" % ', '.join(['%s']*len(invoice_wise_items)),
@@ -104,7 +105,7 @@
 		elif charge_type == "Actual" and tax_amount:
 			for d in invoice_wise_items.get(parent, []):
 				item_tax.setdefault(parent, {}).setdefault(d.item_code, {})[account_head] = \
-					flt((tax_amount * d.base_amount) / d.base_net_total)
+					flt((tax_amount * d.base_net_amount) / d.base_net_total)
 
 	tax_accounts.sort()
 	columns += [account_head + ":Currency:80" for account_head in tax_accounts]
diff --git a/erpnext/accounts/report/purchase_register/purchase_register.py b/erpnext/accounts/report/purchase_register/purchase_register.py
index 724b678..1e92733 100644
--- a/erpnext/accounts/report/purchase_register/purchase_register.py
+++ b/erpnext/accounts/report/purchase_register/purchase_register.py
@@ -114,7 +114,7 @@
 
 
 def get_invoice_expense_map(invoice_list):
-	expense_details = frappe.db.sql("""select parent, expense_account, sum(base_amount) as amount
+	expense_details = frappe.db.sql("""select parent, expense_account, sum(base_net_amount) as amount
 		from `tabPurchase Invoice Item` where parent in (%s) group by parent, expense_account""" %
 		', '.join(['%s']*len(invoice_list)), tuple([inv.name for inv in invoice_list]), as_dict=1)
 
@@ -126,7 +126,7 @@
 	return invoice_expense_map
 
 def get_invoice_tax_map(invoice_list, invoice_expense_map, expense_accounts):
-	tax_details = frappe.db.sql("""select parent, account_head, sum(tax_amount) as tax_amount
+	tax_details = frappe.db.sql("""select parent, account_head, sum(base_tax_amount_after_discount_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)
 
diff --git a/erpnext/accounts/report/sales_register/sales_register.py b/erpnext/accounts/report/sales_register/sales_register.py
index 3bd82b6..5fa03f7 100644
--- a/erpnext/accounts/report/sales_register/sales_register.py
+++ b/erpnext/accounts/report/sales_register/sales_register.py
@@ -78,7 +78,7 @@
 
 		tax_accounts = 	frappe.db.sql_list("""select distinct account_head
 			from `tabSales Taxes and Charges` where parenttype = 'Sales Invoice'
-			and docstatus = 1 and ifnull(tax_amount_after_discount_amount, 0) != 0
+			and docstatus = 1 and ifnull(base_tax_amount_after_discount_amount, 0) != 0
 			and parent in (%s) order by account_head""" %
 			', '.join(['%s']*len(invoice_list)), tuple([inv.name for inv in invoice_list]))
 
@@ -113,7 +113,7 @@
 		conditions, filters, as_dict=1)
 
 def get_invoice_income_map(invoice_list):
-	income_details = frappe.db.sql("""select parent, income_account, sum(base_amount) as amount
+	income_details = frappe.db.sql("""select parent, income_account, sum(base_net_amount) as amount
 		from `tabSales Invoice Item` where parent in (%s) group by parent, income_account""" %
 		', '.join(['%s']*len(invoice_list)), tuple([inv.name for inv in invoice_list]), as_dict=1)
 
@@ -126,7 +126,7 @@
 
 def get_invoice_tax_map(invoice_list, invoice_income_map, income_accounts):
 	tax_details = frappe.db.sql("""select parent, account_head,
-		sum(tax_amount_after_discount_amount) as tax_amount
+		sum(base_tax_amount_after_discount_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)
 
diff --git a/erpnext/buying/doctype/purchase_common/purchase_common.js b/erpnext/buying/doctype/purchase_common/purchase_common.js
index 6759550..414134a 100644
--- a/erpnext/buying/doctype/purchase_common/purchase_common.js
+++ b/erpnext/buying/doctype/purchase_common/purchase_common.js
@@ -2,9 +2,11 @@
 // License: GNU General Public License v3. See license.txt
 
 frappe.provide("erpnext.buying");
-frappe.require("assets/erpnext/js/controllers/transaction.js");
 
-{% include "public/js/controllers/accounts.js" %};
+cur_frm.cscript.tax_table = "Purchase Taxes and Charges";
+{% include 'accounts/doctype/purchase_taxes_and_charges_master/purchase_taxes_and_charges_master.js' %}
+
+frappe.require("assets/erpnext/js/controllers/transaction.js");
 
 cur_frm.email_field = "contact_email";
 
@@ -90,20 +92,6 @@
 		this.price_list_rate(doc, cdt, cdn);
 	},
 
-	rate: function(doc, cdt, cdn) {
-		var item = frappe.get_doc(cdt, cdn);
-		frappe.model.round_floats_in(item, ["rate", "discount_percentage"]);
-
-		if(item.price_list_rate) {
-			item.discount_percentage = flt((1 - item.rate / item.price_list_rate) * 100.0,
-				precision("discount_percentage", item));
-		} else {
-			item.discount_percentage = 0.0;
-		}
-
-		this.calculate_taxes_and_totals();
-	},
-
 	uom: function(doc, cdt, cdn) {
 		var me = this;
 		var item = frappe.get_doc(cdt, cdn);
@@ -180,97 +168,6 @@
 			this.frm.doc.outstanding_amount = flt(this.frm.doc.total_amount_to_pay - this.frm.doc.total_advance,
 				precision("outstanding_amount"));
 		}
-	},
-
-	change_form_labels: function(company_currency) {
-		var me = this;
-		var field_label_map = {};
-
-		var setup_field_label_map = function(fields_list, currency) {
-			$.each(fields_list, function(i, fname) {
-				var docfield = frappe.meta.docfield_map[me.frm.doc.doctype][fname];
-				if(docfield) {
-					var label = __(docfield.label || "").replace(/\([^\)]*\)/g, "");
-					field_label_map[fname] = label.trim() + " (" + currency + ")";
-				}
-			});
-		};
-
-
-		setup_field_label_map(["base_net_total", "base_total_taxes_and_charges", "base_grand_total", "base_in_words",
-			"base_taxes_and_charges_added", "base_taxes_and_charges_deducted",
-			"outstanding_amount", "total_advance", "total_amount_to_pay", "base_rounded_total"],
-			company_currency);
-
-		setup_field_label_map(["net_total", "grand_total", "in_words",
-			"taxes_and_charges_added", "taxes_and_charges_deducted"], this.frm.doc.currency);
-
-		cur_frm.set_df_property("conversion_rate", "description", "1 " + this.frm.doc.currency
-			+ " = [?] " + company_currency);
-
-		if(this.frm.doc.price_list_currency && this.frm.doc.price_list_currency!=company_currency) {
-			cur_frm.set_df_property("plc_conversion_rate", "description", "1 " + this.frm.doc.price_list_currency
-				+ " = [?] " + company_currency);
-		}
-
-		// toggle fields
-		this.frm.toggle_display(["conversion_rate", "base_net_total", "base_grand_total",
-			"base_in_words", "base_taxes_and_charges_added", "base_taxes_and_charges_deducted"],
-			this.frm.doc.currency !== company_currency);
-
-		this.frm.toggle_display(["plc_conversion_rate", "price_list_currency"],
-			this.frm.doc.price_list_currency !== company_currency);
-
-		// set labels
-		$.each(field_label_map, function(fname, label) {
-			me.frm.fields_dict[fname].set_label(label);
-		});
-
-	},
-
-	change_grid_labels: function(company_currency) {
-		var me = this;
-		var field_label_map = {};
-
-		var setup_field_label_map = function(fields_list, currency, parentfield) {
-			var grid_doctype = me.frm.fields_dict[parentfield].grid.doctype;
-			$.each(fields_list, function(i, fname) {
-				var docfield = frappe.meta.docfield_map[grid_doctype][fname];
-				if(docfield) {
-					var label = __(docfield.label || "").replace(/\([^\)]*\)/g, "");
-					field_label_map[grid_doctype + "-" + fname] =
-						label.trim() + " (" + currency + ")";
-				}
-			});
-		};
-
-		setup_field_label_map(["base_rate", "base_price_list_rate", "base_amount", "base_rate"],
-			company_currency, "items");
-
-			setup_field_label_map(["rate", "price_list_rate", "amount"], this.frm.doc.currency, "items");
-
-		if(this.frm.fields_dict["taxes"]) {
-			setup_field_label_map(["tax_amount", "total"], company_currency, "taxes");
-		}
-
-		if(this.frm.fields_dict["advances"]) {
-			setup_field_label_map(["advance_amount", "allocated_amount"], company_currency,
-				"advances");
-		}
-
-		// toggle columns
-		var item_grid = this.frm.fields_dict["items"].grid;
-		var fieldnames = $.map(["base_rate", "base_price_list_rate", "base_amount", "base_rate"], function(fname) {
-			return frappe.meta.get_docfield(item_grid.doctype, fname, me.frm.docname) ? fname : null;
-		});
-
-		item_grid.set_column_disp(fieldnames, this.frm.doc.currency != company_currency);
-
-		// set labels
-		var $wrapper = $(this.frm.wrapper);
-		$.each(field_label_map, function(fname, label) {
-			$wrapper.find('[data-grid-fieldname="'+fname+'"]').text(label);
-		});
 	}
 });
 cur_frm.add_fetch('project_name', 'cost_center', 'cost_center');
diff --git a/erpnext/buying/doctype/purchase_order/purchase_order.js b/erpnext/buying/doctype/purchase_order/purchase_order.js
index b1eee0e..27ea0d4 100644
--- a/erpnext/buying/doctype/purchase_order/purchase_order.js
+++ b/erpnext/buying/doctype/purchase_order/purchase_order.js
@@ -4,7 +4,6 @@
 frappe.provide("erpnext.buying");
 
 {% include 'buying/doctype/purchase_common/purchase_common.js' %};
-{% include 'accounts/doctype/purchase_taxes_and_charges_master/purchase_taxes_and_charges_master.js' %}
 
 erpnext.buying.PurchaseOrderController = erpnext.buying.BuyingController.extend({
 	refresh: function(doc, cdt, cdn) {
diff --git a/erpnext/buying/doctype/purchase_order/purchase_order.json b/erpnext/buying/doctype/purchase_order/purchase_order.json
index 2698f24..6776535 100644
--- a/erpnext/buying/doctype/purchase_order/purchase_order.json
+++ b/erpnext/buying/doctype/purchase_order/purchase_order.json
@@ -225,11 +225,29 @@
    "permlevel": 0
   }, 
   {
+   "fieldname": "get_last_purchase_rate", 
+   "fieldtype": "Button", 
+   "label": "Get Last Purchase Rate", 
+   "oldfieldtype": "Button", 
+   "permlevel": 0, 
+   "print_hide": 0
+  }, 
+  {
    "fieldname": "sb_last_purchase", 
    "fieldtype": "Section Break", 
    "permlevel": 0
   }, 
   {
+   "fieldname": "base_total", 
+   "fieldtype": "Currency", 
+   "label": "Total (Company Currency)", 
+   "options": "Company:company:default_currency", 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 1, 
+   "read_only": 1
+  }, 
+  {
    "fieldname": "base_net_total", 
    "fieldtype": "Currency", 
    "label": "Net Total (Company Currency)", 
@@ -248,6 +266,16 @@
    "permlevel": 0
   }, 
   {
+   "fieldname": "total", 
+   "fieldtype": "Currency", 
+   "label": "Total", 
+   "options": "currency", 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 1, 
+   "read_only": 1
+  }, 
+  {
    "fieldname": "net_total", 
    "fieldtype": "Currency", 
    "label": "Net Total", 
@@ -260,14 +288,6 @@
    "read_only": 1
   }, 
   {
-   "fieldname": "get_last_purchase_rate", 
-   "fieldtype": "Button", 
-   "label": "Get Last Purchase Rate", 
-   "oldfieldtype": "Button", 
-   "permlevel": 0, 
-   "print_hide": 0
-  }, 
-  {
    "fieldname": "taxes_section", 
    "fieldtype": "Section Break", 
    "label": "Taxes and Charges", 
@@ -352,6 +372,93 @@
    "read_only": 1
   }, 
   {
+   "fieldname": "column_break_39", 
+   "fieldtype": "Column Break", 
+   "permlevel": 0, 
+   "precision": ""
+  }, 
+  {
+   "fieldname": "taxes_and_charges_added", 
+   "fieldtype": "Currency", 
+   "label": "Taxes and Charges Added", 
+   "no_copy": 0, 
+   "oldfieldname": "other_charges_added_import", 
+   "oldfieldtype": "Currency", 
+   "options": "currency", 
+   "permlevel": 0, 
+   "print_hide": 1, 
+   "read_only": 1, 
+   "report_hide": 0
+  }, 
+  {
+   "fieldname": "taxes_and_charges_deducted", 
+   "fieldtype": "Currency", 
+   "label": "Taxes and Charges Deducted", 
+   "no_copy": 0, 
+   "oldfieldname": "other_charges_deducted_import", 
+   "oldfieldtype": "Currency", 
+   "options": "currency", 
+   "permlevel": 0, 
+   "print_hide": 1, 
+   "read_only": 1, 
+   "report_hide": 0
+  }, 
+  {
+   "fieldname": "total_taxes_and_charges", 
+   "fieldtype": "Currency", 
+   "label": "Total Taxes and Charges", 
+   "options": "currency", 
+   "permlevel": 0, 
+   "precision": "", 
+   "read_only": 1
+  }, 
+  {
+   "fieldname": "discount_section", 
+   "fieldtype": "Section Break", 
+   "permlevel": 0, 
+   "precision": ""
+  }, 
+  {
+   "default": "Grand Total", 
+   "fieldname": "apply_discount_on", 
+   "fieldtype": "Select", 
+   "label": "Apply Discount On", 
+   "options": "\nGrand Total\nNet Total", 
+   "permlevel": 0, 
+   "precision": ""
+  }, 
+  {
+   "fieldname": "column_break_45", 
+   "fieldtype": "Column Break", 
+   "permlevel": 0, 
+   "precision": ""
+  }, 
+  {
+   "fieldname": "discount_amount", 
+   "fieldtype": "Currency", 
+   "label": "Discount Amount", 
+   "options": "currency", 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 1
+  }, 
+  {
+   "fieldname": "base_discount_amount", 
+   "fieldtype": "Currency", 
+   "label": "Discount Amount (Company Currency)", 
+   "options": "Company:company:default_currency", 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 1, 
+   "read_only": 1
+  }, 
+  {
+   "fieldname": "totals_section", 
+   "fieldtype": "Section Break", 
+   "permlevel": 0, 
+   "precision": ""
+  }, 
+  {
    "fieldname": "base_grand_total", 
    "fieldtype": "Currency", 
    "label": "Grand Total (Company Currency)", 
@@ -401,40 +508,6 @@
    "print_hide": 0
   }, 
   {
-   "fieldname": "taxes_and_charges_added", 
-   "fieldtype": "Currency", 
-   "label": "Taxes and Charges Added", 
-   "no_copy": 0, 
-   "oldfieldname": "other_charges_added_import", 
-   "oldfieldtype": "Currency", 
-   "options": "currency", 
-   "permlevel": 0, 
-   "print_hide": 1, 
-   "read_only": 1, 
-   "report_hide": 0
-  }, 
-  {
-   "fieldname": "taxes_and_charges_deducted", 
-   "fieldtype": "Currency", 
-   "label": "Taxes and Charges Deducted", 
-   "no_copy": 0, 
-   "oldfieldname": "other_charges_deducted_import", 
-   "oldfieldtype": "Currency", 
-   "options": "currency", 
-   "permlevel": 0, 
-   "print_hide": 1, 
-   "read_only": 1, 
-   "report_hide": 0
-  }, 
-  {
-   "fieldname": "total_taxes_and_charges", 
-   "fieldtype": "Currency", 
-   "label": "Total Taxes and Charges", 
-   "options": "currency", 
-   "permlevel": 0, 
-   "precision": ""
-  }, 
-  {
    "fieldname": "grand_total", 
    "fieldtype": "Currency", 
    "in_list_view": 1, 
@@ -783,7 +856,7 @@
  "icon": "icon-file-text", 
  "idx": 1, 
  "is_submittable": 1, 
- "modified": "2015-02-20 05:16:19.990723", 
+ "modified": "2015-02-23 15:10:05.156787", 
  "modified_by": "Administrator", 
  "module": "Buying", 
  "name": "Purchase Order", 
diff --git a/erpnext/buying/doctype/purchase_order_item/purchase_order_item.json b/erpnext/buying/doctype/purchase_order_item/purchase_order_item.json
index b0ba316..58af076 100755
--- a/erpnext/buying/doctype/purchase_order_item/purchase_order_item.json
+++ b/erpnext/buying/doctype/purchase_order_item/purchase_order_item.json
@@ -282,6 +282,58 @@
    "read_only": 1
   }, 
   {
+   "fieldname": "section_break_29", 
+   "fieldtype": "Section Break", 
+   "permlevel": 0, 
+   "precision": ""
+  }, 
+  {
+   "fieldname": "net_rate", 
+   "fieldtype": "Currency", 
+   "label": "Net Rate", 
+   "options": "currency", 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 1, 
+   "read_only": 1
+  }, 
+  {
+   "fieldname": "net_amount", 
+   "fieldtype": "Currency", 
+   "label": "Net Amount", 
+   "options": "currency", 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 1, 
+   "read_only": 1
+  }, 
+  {
+   "fieldname": "column_break_32", 
+   "fieldtype": "Column Break", 
+   "permlevel": 0, 
+   "precision": ""
+  }, 
+  {
+   "fieldname": "base_net_rate", 
+   "fieldtype": "Currency", 
+   "label": "Net Rate (Company Currency)", 
+   "options": "Company:company:default_currency", 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 1, 
+   "read_only": 1
+  }, 
+  {
+   "fieldname": "base_net_amount", 
+   "fieldtype": "Currency", 
+   "label": "Net Amount (Company Currency)", 
+   "options": "Company:company:default_currency", 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 1, 
+   "read_only": 1
+  }, 
+  {
    "fieldname": "warehouse_and_reference", 
    "fieldtype": "Section Break", 
    "label": "Warehouse and Reference", 
@@ -484,7 +536,7 @@
  ], 
  "idx": 1, 
  "istable": 1, 
- "modified": "2015-02-19 01:07:01.224244", 
+ "modified": "2015-02-23 12:21:53.399279", 
  "modified_by": "Administrator", 
  "module": "Buying", 
  "name": "Purchase Order Item", 
diff --git a/erpnext/buying/doctype/supplier_quotation/supplier_quotation.js b/erpnext/buying/doctype/supplier_quotation/supplier_quotation.js
index 9c2bbed..ecd9185 100644
--- a/erpnext/buying/doctype/supplier_quotation/supplier_quotation.js
+++ b/erpnext/buying/doctype/supplier_quotation/supplier_quotation.js
@@ -3,7 +3,6 @@
 
 // attach required files
 {% include 'buying/doctype/purchase_common/purchase_common.js' %};
-{% include 'accounts/doctype/purchase_taxes_and_charges_master/purchase_taxes_and_charges_master.js' %}
 
 erpnext.buying.SupplierQuotationController = erpnext.buying.BuyingController.extend({
 	refresh: function() {
diff --git a/erpnext/buying/doctype/supplier_quotation/supplier_quotation.json b/erpnext/buying/doctype/supplier_quotation/supplier_quotation.json
index 99471ca..0ed6023 100644
--- a/erpnext/buying/doctype/supplier_quotation/supplier_quotation.json
+++ b/erpnext/buying/doctype/supplier_quotation/supplier_quotation.json
@@ -229,6 +229,16 @@
    "permlevel": 0
   }, 
   {
+   "fieldname": "base_total", 
+   "fieldtype": "Currency", 
+   "label": "Total (Company Currency)", 
+   "options": "Company:company:default_currency", 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 1, 
+   "read_only": 1
+  }, 
+  {
    "fieldname": "base_net_total", 
    "fieldtype": "Currency", 
    "label": "Net Total (Company Currency)", 
@@ -247,6 +257,16 @@
    "permlevel": 0
   }, 
   {
+   "fieldname": "total", 
+   "fieldtype": "Currency", 
+   "label": "Total", 
+   "options": "currency", 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 1, 
+   "read_only": 1
+  }, 
+  {
    "fieldname": "net_total", 
    "fieldtype": "Currency", 
    "label": "Net Total", 
@@ -342,45 +362,10 @@
    "read_only": 1
   }, 
   {
-   "fieldname": "base_grand_total", 
-   "fieldtype": "Currency", 
-   "label": "Grand Total (Company Currency)", 
-   "no_copy": 1, 
-   "oldfieldname": "grand_total", 
-   "oldfieldtype": "Currency", 
-   "options": "Company:company:default_currency", 
-   "permlevel": 0, 
-   "print_hide": 1, 
-   "read_only": 1
-  }, 
-  {
-   "fieldname": "base_rounded_total", 
-   "fieldtype": "Currency", 
-   "label": "Rounded Total (Company Currency)", 
-   "oldfieldname": "rounded_total", 
-   "oldfieldtype": "Currency", 
-   "options": "Company:company:default_currency", 
-   "permlevel": 0, 
-   "print_hide": 1, 
-   "read_only": 1
-  }, 
-  {
-   "description": "In Words will be visible once you save the Purchase Order.", 
-   "fieldname": "base_in_words", 
-   "fieldtype": "Data", 
-   "label": "In Words (Company Currency)", 
-   "oldfieldname": "in_words", 
-   "oldfieldtype": "Data", 
-   "permlevel": 0, 
-   "print_hide": 1, 
-   "read_only": 1
-  }, 
-  {
-   "fieldname": "column_break4", 
+   "fieldname": "column_break_37", 
    "fieldtype": "Column Break", 
-   "oldfieldtype": "Column Break", 
    "permlevel": 0, 
-   "print_hide": 0
+   "precision": ""
   }, 
   {
    "fieldname": "taxes_and_charges_added", 
@@ -414,9 +399,98 @@
    "label": "Total Taxes and Charges", 
    "options": "currency", 
    "permlevel": 0, 
+   "precision": "", 
+   "read_only": 1
+  }, 
+  {
+   "fieldname": "section_break_41", 
+   "fieldtype": "Section Break", 
+   "permlevel": 0, 
    "precision": ""
   }, 
   {
+   "default": "Grand Total", 
+   "fieldname": "apply_discount_on", 
+   "fieldtype": "Select", 
+   "label": "Apply Discount On", 
+   "options": "\nGrand Total\nNet Total", 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 1
+  }, 
+  {
+   "fieldname": "column_break_43", 
+   "fieldtype": "Column Break", 
+   "permlevel": 0, 
+   "precision": ""
+  }, 
+  {
+   "fieldname": "discount_amount", 
+   "fieldtype": "Currency", 
+   "label": "Discount Amount", 
+   "options": "currency", 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 1
+  }, 
+  {
+   "fieldname": "base_discount_amount", 
+   "fieldtype": "Currency", 
+   "label": "Discount Amount (Company Currency)", 
+   "options": "Company:company:default_currency", 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 1, 
+   "read_only": 1
+  }, 
+  {
+   "fieldname": "section_break_46", 
+   "fieldtype": "Section Break", 
+   "permlevel": 0, 
+   "precision": ""
+  }, 
+  {
+   "fieldname": "base_grand_total", 
+   "fieldtype": "Currency", 
+   "label": "Grand Total (Company Currency)", 
+   "no_copy": 1, 
+   "oldfieldname": "grand_total", 
+   "oldfieldtype": "Currency", 
+   "options": "Company:company:default_currency", 
+   "permlevel": 0, 
+   "print_hide": 1, 
+   "read_only": 1
+  }, 
+  {
+   "description": "In Words will be visible once you save the Purchase Order.", 
+   "fieldname": "base_in_words", 
+   "fieldtype": "Data", 
+   "label": "In Words (Company Currency)", 
+   "oldfieldname": "in_words", 
+   "oldfieldtype": "Data", 
+   "permlevel": 0, 
+   "print_hide": 1, 
+   "read_only": 1
+  }, 
+  {
+   "fieldname": "base_rounded_total", 
+   "fieldtype": "Currency", 
+   "label": "Rounded Total (Company Currency)", 
+   "oldfieldname": "rounded_total", 
+   "oldfieldtype": "Currency", 
+   "options": "Company:company:default_currency", 
+   "permlevel": 0, 
+   "print_hide": 1, 
+   "read_only": 1
+  }, 
+  {
+   "fieldname": "column_break4", 
+   "fieldtype": "Column Break", 
+   "oldfieldtype": "Column Break", 
+   "permlevel": 0, 
+   "print_hide": 0
+  }, 
+  {
    "fieldname": "grand_total", 
    "fieldtype": "Currency", 
    "in_list_view": 1, 
@@ -583,7 +657,7 @@
  "icon": "icon-shopping-cart", 
  "idx": 1, 
  "is_submittable": 1, 
- "modified": "2015-02-20 05:16:21.307774", 
+ "modified": "2015-02-23 15:24:02.428061", 
  "modified_by": "Administrator", 
  "module": "Buying", 
  "name": "Supplier Quotation", 
@@ -673,7 +747,7 @@
   }
  ], 
  "read_only_onload": 1, 
- "search_fields": "status, transaction_date, supplier,base_grand_total", 
+ "search_fields": "status, transaction_date, supplier,grand_total", 
  "sort_field": "modified", 
  "sort_order": "DESC", 
  "title_field": "supplier_name"
diff --git a/erpnext/buying/doctype/supplier_quotation_item/supplier_quotation_item.json b/erpnext/buying/doctype/supplier_quotation_item/supplier_quotation_item.json
index 4e736de..59e3da4 100644
--- a/erpnext/buying/doctype/supplier_quotation_item/supplier_quotation_item.json
+++ b/erpnext/buying/doctype/supplier_quotation_item/supplier_quotation_item.json
@@ -226,6 +226,57 @@
    "read_only": 1
   }, 
   {
+   "fieldname": "section_break_24", 
+   "fieldtype": "Section Break", 
+   "permlevel": 0, 
+   "precision": ""
+  }, 
+  {
+   "fieldname": "net_rate", 
+   "fieldtype": "Currency", 
+   "label": "Net Rate", 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 1, 
+   "read_only": 1
+  }, 
+  {
+   "fieldname": "net_amount", 
+   "fieldtype": "Currency", 
+   "label": "Net Amount", 
+   "options": "currency", 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 1, 
+   "read_only": 1
+  }, 
+  {
+   "fieldname": "column_break_27", 
+   "fieldtype": "Column Break", 
+   "permlevel": 0, 
+   "precision": ""
+  }, 
+  {
+   "fieldname": "base_net_rate", 
+   "fieldtype": "Currency", 
+   "label": "Net Rate (Company Currency)", 
+   "options": "Company:company:default_currency", 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 1, 
+   "read_only": 1
+  }, 
+  {
+   "fieldname": "base_net_amount", 
+   "fieldtype": "Currency", 
+   "label": "Net Amount (Company Currency)", 
+   "options": "Company:company:default_currency", 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 1, 
+   "read_only": 1
+  }, 
+  {
    "fieldname": "warehouse_and_reference", 
    "fieldtype": "Section Break", 
    "label": "Warehouse and Reference", 
@@ -360,7 +411,7 @@
  ], 
  "idx": 1, 
  "istable": 1, 
- "modified": "2015-02-19 01:07:02.403267", 
+ "modified": "2015-02-23 15:28:03.712608", 
  "modified_by": "Administrator", 
  "module": "Buying", 
  "name": "Supplier Quotation Item", 
diff --git a/erpnext/buying/page/purchase_analytics/purchase_analytics.js b/erpnext/buying/page/purchase_analytics/purchase_analytics.js
index 470e44c..6afad76 100644
--- a/erpnext/buying/page/purchase_analytics/purchase_analytics.js
+++ b/erpnext/buying/page/purchase_analytics/purchase_analytics.js
@@ -209,7 +209,7 @@
 				if (posting_date >= from_date && posting_date <= to_date) {
 					var item = me.item_by_name[tl[me.tree_grid.item_key]] ||
 						me.item_by_name['Not Set'];
-					item[me.column_map[tl.posting_date].field] += (is_val ? tl.base_amount : tl.qty);
+					item[me.column_map[tl.posting_date].field] += (is_val ? tl.base_net_amount : tl.qty);
 				}
 			}
 		});
diff --git a/erpnext/controllers/accounts_controller.py b/erpnext/controllers/accounts_controller.py
index c0a63cd..e486989 100644
--- a/erpnext/controllers/accounts_controller.py
+++ b/erpnext/controllers/accounts_controller.py
@@ -4,7 +4,7 @@
 from __future__ import unicode_literals
 import frappe
 from frappe import _, throw
-from frappe.utils import today, flt
+from frappe.utils import today, flt, cint
 from erpnext.setup.utils import get_company_currency, get_exchange_rate
 from erpnext.accounts.utils import get_fiscal_year, validate_fiscal_year
 from erpnext.utilities.transaction_base import TransactionBase
@@ -357,3 +357,32 @@
 	if not conversion_rate:
 		throw(_("{0} is mandatory. Maybe Currency Exchange record is not created for {1} to {2}.").format(
 			conversion_rate_label, currency, company_currency))
+
+def validate_taxes_and_charges(tax):
+	if tax.charge_type in ['Actual', 'On Net Total'] and tax.row_id:
+		frappe.throw(_("Can refer row only if the charge type is 'On Previous Row Amount' or 'Previous Row Total'"))
+	elif tax.charge_type in ['On Previous Row Amount', 'On Previous Row Total']:
+		if cint(tax.idx) == 1:
+			frappe.throw(_("Cannot select charge type as 'On Previous Row Amount' or 'On Previous Row Total' for first row"))
+		elif not tax.row_id:
+			frappe.throw(_("Please specify a valid Row ID for row {0} in table {1}".format(tax.idx, _(tax.doctype))))
+		elif tax.row_id and cint(tax.row_id) >= cint(tax.idx):
+			frappe.throw(_("Cannot refer row number greater than or equal to current row number for this Charge type"))
+
+def validate_inclusive_tax(tax, doc):
+	def _on_previous_row_error(row_range):
+		throw(_("To include tax in row {0} in Item rate, taxes in rows {1} must also be included").format(tax.idx,
+			row_range))
+
+	if cint(getattr(tax, "included_in_print_rate", None)):
+		if tax.charge_type == "Actual":
+			# inclusive tax cannot be of type Actual
+			throw(_("Charge of type 'Actual' in row {0} cannot be included in Item Rate").format(tax.idx))
+		elif tax.charge_type == "On Previous Row Amount" and \
+				not cint(doc.get("taxes")[cint(tax.row_id) - 1].included_in_print_rate):
+			# referred row should also be inclusive
+			_on_previous_row_error(tax.row_id)
+		elif tax.charge_type == "On Previous Row Total" and \
+				not all([cint(t.included_in_print_rate) for t in doc.get("taxes")[:cint(tax.row_id) - 1]]):
+			# all rows about the reffered tax should be inclusive
+			_on_previous_row_error("1 - %d" % (tax.row_id,))
diff --git a/erpnext/controllers/buying_controller.py b/erpnext/controllers/buying_controller.py
index 5e27b3a..7d01f81 100644
--- a/erpnext/controllers/buying_controller.py
+++ b/erpnext/controllers/buying_controller.py
@@ -14,7 +14,7 @@
 
 class BuyingController(StockController):
 	def __setup__(self):
-		if hasattr(self, "items"):
+		if hasattr(self, "taxes"):
 			self.print_templates = {
 				"taxes": "templates/print_formats/includes/taxes.html"
 			}
@@ -94,16 +94,16 @@
 		for d in self.get(parentfield):
 			if d.item_code and d.item_code in stock_items:
 				stock_items_qty += flt(d.qty)
-				stock_items_amount += flt(d.base_amount)
+				stock_items_amount += flt(d.base_net_amount)
 				last_stock_item_idx = d.idx
 
-		total_valuation_amount = sum([flt(d.tax_amount) for d in self.get("taxes")
+		total_valuation_amount = sum([flt(d.base_tax_amount_after_discount_amount) for d in self.get("taxes")
 			if d.category in ["Valuation", "Valuation and Total"]])
 
 		valuation_amount_adjustment = total_valuation_amount
 		for i, item in enumerate(self.get(parentfield)):
 			if item.item_code and item.qty and item.item_code in stock_items:
-				item_proportion = flt(item.base_amount) / stock_items_amount if stock_items_amount \
+				item_proportion = flt(item.base_net_amount) / stock_items_amount if stock_items_amount \
 					else flt(item.qty) / stock_items_qty
 
 				if i == (last_stock_item_idx - 1):
@@ -124,7 +124,7 @@
 				landed_cost_voucher_amount = flt(item.landed_cost_voucher_amount) \
 					if self.doctype == "Purchase Receipt" else 0.0
 
-				item.valuation_rate = ((item.base_amount + item.item_tax_amount + rm_supp_cost
+				item.valuation_rate = ((item.base_net_amount + item.item_tax_amount + rm_supp_cost
 					 + landed_cost_voucher_amount) / qty_in_stock_uom)
 			else:
 				item.valuation_rate = 0.0
diff --git a/erpnext/controllers/selling_controller.py b/erpnext/controllers/selling_controller.py
index e6ec2af..9cee583 100644
--- a/erpnext/controllers/selling_controller.py
+++ b/erpnext/controllers/selling_controller.py
@@ -12,7 +12,7 @@
 
 class SellingController(StockController):
 	def __setup__(self):
-		if hasattr(self, "items"):
+		if hasattr(self, "taxes"):
 			self.print_templates = {
 				"taxes": "templates/print_formats/includes/taxes.html"
 			}
diff --git a/erpnext/controllers/taxes_and_totals.py b/erpnext/controllers/taxes_and_totals.py
index d9bac98..c786d2a 100644
--- a/erpnext/controllers/taxes_and_totals.py
+++ b/erpnext/controllers/taxes_and_totals.py
@@ -3,15 +3,16 @@
 
 from __future__ import unicode_literals
 import json
-from frappe import _, throw
+import frappe
+from frappe import _
 from frappe.utils import cint, flt, rounded
 from erpnext.setup.utils import get_company_currency
-from erpnext.controllers.accounts_controller import validate_conversion_rate
+from erpnext.controllers.accounts_controller import validate_conversion_rate, \
+	validate_taxes_and_charges, validate_inclusive_tax
 
 class calculate_taxes_and_totals(object):
 	def __init__(self, doc):
 		self.doc = doc
-
 		self.calculate()
 
 	def calculate(self):
@@ -25,6 +26,15 @@
 			self.calculate_total_advance()
 
 	def _calculate(self):
+		self.calculate_item_values()
+		self.initialize_taxes()
+		self.determine_exclusive_rate()
+		self.calculate_net_total()
+		self.calculate_taxes()
+		self.calculate_totals()
+		self._cleanup()
+
+	def validate_conversion_rate(self):
 		# validate conversion rate
 		company_currency = get_company_currency(self.doc.company)
 		if not self.doc.currency or self.doc.currency == company_currency:
@@ -36,17 +46,6 @@
 
 		self.doc.conversion_rate = flt(self.doc.conversion_rate)
 
-		self.calculate_item_values()
-		self.initialize_taxes()
-
-		if self.doc.doctype in ["Quotation", "Sales Order", "Delivery Note", "Sales Invoice"]:
-			self.determine_exclusive_rate()
-
-		self.calculate_net_total()
-		self.calculate_taxes()
-		self.calculate_totals()
-		self._cleanup()
-
 	def calculate_item_values(self):
 		if not self.discount_amount_applied:
 			for item in self.doc.get("items"):
@@ -55,69 +54,44 @@
 				if item.discount_percentage == 100:
 					item.rate = 0.0
 				elif not item.rate:
-					item.rate = flt(item.price_list_rate * (1.0 - (item.discount_percentage / 100.0)),
-						self.doc.precision("rate", item))
+					item.rate = flt(item.price_list_rate *
+						(1.0 - (item.discount_percentage / 100.0)), item.precision("rate"))
 
-				item.amount = flt(item.rate * item.qty,	self.doc.precision("amount", item))
-				item.item_tax_amount = 0.0;
+				item.net_rate = item.rate
+				item.amount = flt(item.rate * item.qty,	item.precision("amount"))
+				item.net_amount = item.amount
 
-				self._set_in_company_currency(item, "price_list_rate", "base_price_list_rate")
-				self._set_in_company_currency(item, "rate", "base_rate")
-				self._set_in_company_currency(item, "amount", "base_amount")
+				self._set_in_company_currency(item, ["price_list_rate", "rate", "net_rate", "amount", "net_amount"])
 
-	def _set_in_company_currency(self, item, print_field, base_field):
+				item.item_tax_amount = 0.0
+
+	def _set_in_company_currency(self, doc, fields):
 		"""set values in base currency"""
-		value_in_company_currency = flt(self.doc.conversion_rate *
-			flt(item.get(print_field), self.doc.precision(print_field, item)), self.doc.precision(base_field, item))
-		item.set(base_field, value_in_company_currency)
+		for f in fields:
+			val = flt(flt(doc.get(f), doc.precision(f)) * self.doc.conversion_rate, doc.precision("base_" + f))
+			doc.set("base_" + f, val)
 
 	def initialize_taxes(self):
 		for tax in self.doc.get("taxes"):
+			validate_taxes_and_charges(tax)
+			validate_inclusive_tax(tax, self.doc)
+
 			tax.item_wise_tax_detail = {}
 			tax_fields = ["total", "tax_amount_after_discount_amount",
 				"tax_amount_for_current_item", "grand_total_for_current_item",
 				"tax_fraction_for_current_item", "grand_total_fraction_for_current_item"]
 
-			if not self.discount_amount_applied:
-				tax_fields.append("tax_amount")
+			if tax.charge_type != "Actual" and \
+				not (self.discount_amount_applied and self.doc.apply_discount_on=="Grand Total"):
+					tax_fields.append("tax_amount")
 
 			for fieldname in tax_fields:
 				tax.set(fieldname, 0.0)
 
-			self.validate_on_previous_row(tax)
-			self.validate_inclusive_tax(tax)
 			self.doc.round_floats_in(tax)
 
-	def validate_on_previous_row(self, tax):
-		"""
-			validate if a valid row id is mentioned in case of
-			On Previous Row Amount and On Previous Row Total
-		"""
-		if tax.charge_type in ["On Previous Row Amount", "On Previous Row Total"] and \
-				(not tax.row_id or cint(tax.row_id) >= tax.idx):
-			throw(_("Please specify a valid Row ID for {0} in row {1}").format(_(tax.doctype), tax.idx))
-
-	def validate_inclusive_tax(self, tax):
-		def _on_previous_row_error(row_range):
-			throw(_("To include tax in row {0} in Item rate, taxes in rows {1} must also be included").format(tax.idx,
-				row_range))
-
-		if cint(getattr(tax, "included_in_print_rate", None)):
-			if tax.charge_type == "Actual":
-				# inclusive tax cannot be of type Actual
-				throw(_("Charge of type 'Actual' in row {0} cannot be included in Item Rate").format(tax.idx))
-			elif tax.charge_type == "On Previous Row Amount" and \
-					not cint(self.doc.get("taxes")[cint(tax.row_id) - 1].included_in_print_rate):
-				# referred row should also be inclusive
-				_on_previous_row_error(tax.row_id)
-			elif tax.charge_type == "On Previous Row Total" and \
-					not all([cint(t.included_in_print_rate) for t in self.doc.get("taxes")[:cint(tax.row_id) - 1]]):
-				# all rows about the reffered tax should be inclusive
-				_on_previous_row_error("1 - %d" % (tax.row_id,))
-
 	def determine_exclusive_rate(self):
 		if not any((cint(tax.included_in_print_rate) for tax in self.doc.get("taxes"))):
-			# no inclusive tax
 			return
 
 		for item in self.doc.get("items"):
@@ -136,18 +110,24 @@
 				cumulated_tax_fraction += tax.tax_fraction_for_current_item
 
 			if cumulated_tax_fraction and not self.discount_amount_applied and item.qty:
-				item.base_amount = flt((item.amount * self.doc.conversion_rate) /
-					(1 + cumulated_tax_fraction), self.doc.precision("base_amount", item))
+				item.net_amount = flt(item.amount / (1 + cumulated_tax_fraction), item.precision("net_amount"))
+				item.net_rate = flt(item.net_amount / item.qty, item.precision("net_rate"))
+				item.discount_percentage = flt(item.discount_percentage, item.precision("discount_percentage"))
 
-				item.base_rate = flt(item.base_amount / item.qty, self.doc.precision("base_rate", item))
-				item.discount_percentage = flt(item.discount_percentage, self.doc.precision("discount_percentage", item))
 
-				if item.discount_percentage == 100:
-					item.base_price_list_rate = item.base_rate
-					item.base_rate = 0.0
-				else:
-					item.base_price_list_rate = flt(item.base_rate / (1 - (item.discount_percentage / 100.0)),
-						self.doc.precision("base_price_list_rate", item))
+				self._set_in_company_currency(item, ["net_rate", "net_amount"])
+
+				# below part need to be fixed???
+
+				# if item.discount_percentage == 100:
+				# 	item.price_list_rate = item.net_rate
+				# 	item.base_price_list_rate = flt(item.price_list_rate*self.doc.conversion_rate,
+				# 		self.doc.precision("base_price_list_rate", item))
+				# 	item.rate = item.base_rate = item.net_rate = item.base_net_rate = 0.0
+				# else:
+				# 	item.base_price_list_rate = flt(item.net_rate / (1 - (item.discount_percentage / 100.0)),
+				# 		self.doc.precision("price_list_rate", item))
+
 
 	def _load_item_tax_rate(self, item_tax_rate):
 		return json.loads(item_tax_rate) if item_tax_rate else {}
@@ -182,17 +162,19 @@
 			return tax.rate
 
 	def calculate_net_total(self):
-		self.doc.base_net_total = self.doc.net_total = 0.0
+		self.doc.total = self.doc.base_total = self.doc.net_total = self.doc.base_net_total = 0.0
 
 		for item in self.doc.get("items"):
-			self.doc.base_net_total += item.base_amount
-			self.doc.net_total += item.amount
+			self.doc.total += item.amount
+			self.doc.base_total += item.base_amount
+			self.doc.net_total += item.net_amount
+			self.doc.base_net_total += item.base_net_amount
 
-		self.doc.round_floats_in(self.doc, ["base_net_total", "net_total"])
+		self.doc.round_floats_in(self.doc, ["total", "base_total", "net_total", "base_net_total"])
 
 	def calculate_taxes(self):
 		# maintain actual tax rate based on idx
-		actual_tax_dict = dict([[tax.idx, flt(tax.rate, self.doc.precision("tax_amount", tax))]
+		actual_tax_dict = dict([[tax.idx, flt(tax.tax_amount, tax.precision("tax_amount"))]
 			for tax in self.doc.get("taxes") if tax.charge_type == "Actual"])
 
 		for n, item in enumerate(self.doc.get("items")):
@@ -208,14 +190,16 @@
 					if n == len(self.doc.get("items")) - 1:
 						current_tax_amount += actual_tax_dict[tax.idx]
 
+				# accumulate tax amount into tax.tax_amount
+				if tax.charge_type != "Actual" and \
+					not (self.discount_amount_applied and self.doc.apply_discount_on=="Grand Total"):
+						tax.tax_amount += current_tax_amount
+
 				# store tax_amount for current item as it will be used for
 				# charge type = 'On Previous Row Amount'
 				tax.tax_amount_for_current_item = current_tax_amount
 
-				# accumulate tax amount into tax.tax_amount
-				if not self.discount_amount_applied:
-					tax.tax_amount += current_tax_amount
-
+				# set tax after discount
 				tax.tax_amount_after_discount_amount += current_tax_amount
 
 				if getattr(tax, "category", None):
@@ -230,12 +214,10 @@
 				# note: grand_total_for_current_item contains the contribution of
 				# item's amount, previously applied tax and the current tax on that item
 				if i==0:
-					tax.grand_total_for_current_item = flt(item.base_amount + current_tax_amount,
-						self.doc.precision("total", tax))
+					tax.grand_total_for_current_item = flt(item.net_amount + current_tax_amount)
 				else:
 					tax.grand_total_for_current_item = \
-						flt(self.doc.get("taxes")[i-1].grand_total_for_current_item +
-							current_tax_amount, self.doc.precision("total", tax))
+						self.doc.get("taxes")[i-1].grand_total_for_current_item + current_tax_amount
 
 				# in tax.total, accumulate grand total of each item
 				tax.total += tax.grand_total_for_current_item
@@ -245,8 +227,9 @@
 					self.round_off_totals(tax)
 
 					# adjust Discount Amount loss in last tax iteration
-					if i == (len(self.doc.get("taxes")) - 1) and self.discount_amount_applied:
-						self.adjust_discount_amount_loss(tax)
+					if i == (len(self.doc.get("taxes")) - 1) and self.discount_amount_applied \
+						and self.doc.apply_discount_on == "Grand Total":
+							self.adjust_discount_amount_loss(tax)
 
 	def get_current_tax_amount(self, item, tax, item_tax_map):
 		tax_rate = self._get_tax_rate(tax, item_tax_map)
@@ -254,12 +237,11 @@
 
 		if tax.charge_type == "Actual":
 			# distribute the tax amount proportionally to each item row
-			actual = flt(tax.rate, self.doc.precision("tax_amount", tax))
-			current_tax_amount = (self.doc.base_net_total
-				and ((item.base_amount / self.doc.base_net_total) * actual)
-				or 0)
+			actual = flt(tax.tax_amount, tax.precision("tax_amount"))
+			current_tax_amount = item.net_amount*actual / self.doc.net_total if self.doc.net_total else 0.0
+
 		elif tax.charge_type == "On Net Total":
-			current_tax_amount = (tax_rate / 100.0) * item.base_amount
+			current_tax_amount = (tax_rate / 100.0) * item.net_amount
 		elif tax.charge_type == "On Previous Row Amount":
 			current_tax_amount = (tax_rate / 100.0) * \
 				self.doc.get("taxes")[cint(tax.row_id) - 1].tax_amount_for_current_item
@@ -267,72 +249,68 @@
 			current_tax_amount = (tax_rate / 100.0) * \
 				self.doc.get("taxes")[cint(tax.row_id) - 1].grand_total_for_current_item
 
-		current_tax_amount = flt(current_tax_amount, self.doc.precision("tax_amount", tax))
+		# current_tax_amount = flt(current_tax_amount, tax.precision("tax_amount", tax))
 
-		# store tax breakup for each item
-		key = item.item_code or item.item_name
-		if tax.item_wise_tax_detail.get(key):
-			item_wise_tax_amount = tax.item_wise_tax_detail[key][1] + current_tax_amount
-			tax.item_wise_tax_detail[key] = [tax_rate,item_wise_tax_amount]
-		else:
-			tax.item_wise_tax_detail[key] = [tax_rate,current_tax_amount]
+		self.set_item_wise_tax(item, tax, tax_rate, current_tax_amount)
 
 		return current_tax_amount
 
+	def set_item_wise_tax(self, item, tax, tax_rate, current_tax_amount):
+		# store tax breakup for each item
+		key = item.item_code or item.item_name
+		item_wise_tax_amount = current_tax_amount*self.doc.conversion_rate
+		if tax.item_wise_tax_detail.get(key):
+			item_wise_tax_amount += tax.item_wise_tax_detail[key][1]
+
+		tax.item_wise_tax_detail[key] = [tax_rate,flt(item_wise_tax_amount, tax.precision("base_tax_amount"))]
+
 	def round_off_totals(self, tax):
-		tax.total = flt(tax.total, self.doc.precision("total", tax))
-		tax.tax_amount = flt(tax.tax_amount, self.doc.precision("tax_amount", tax))
-		tax.tax_amount_after_discount_amount = flt(tax.tax_amount_after_discount_amount,
-			self.doc.precision("tax_amount", tax))
+		tax.total = flt(tax.total, tax.precision("total"))
+		tax.tax_amount = flt(tax.tax_amount, tax.precision("tax_amount"))
+		tax.tax_amount_after_discount_amount = flt(tax.tax_amount_after_discount_amount, tax.precision("tax_amount"))
+
+		self._set_in_company_currency(tax, ["total", "tax_amount", "tax_amount_after_discount_amount"])
 
 	def adjust_discount_amount_loss(self, tax):
-		discount_amount_loss = self.doc.base_grand_total - flt(self.doc.base_discount_amount) - tax.total
+		discount_amount_loss = self.doc.grand_total - flt(self.doc.discount_amount) - tax.total
 		tax.tax_amount_after_discount_amount = flt(tax.tax_amount_after_discount_amount +
 			discount_amount_loss, self.doc.precision("tax_amount", tax))
 		tax.total = flt(tax.total + discount_amount_loss, self.doc.precision("total", tax))
 
 	def calculate_totals(self):
-		self.doc.base_grand_total = flt(self.doc.get("taxes")[-1].total
-			if self.doc.get("taxes") else self.doc.base_net_total)
-
-		self.doc.base_total_taxes_and_charges = flt(self.doc.base_grand_total - self.doc.base_net_total,
-			self.doc.precision("base_total_taxes_and_charges"))
+		self.doc.grand_total = flt(self.doc.get("taxes")[-1].total
+			if self.doc.get("taxes") else self.doc.net_total)
 
 		if self.doc.doctype in ["Quotation", "Sales Order", "Delivery Note", "Sales Invoice"]:
-			self.doc.grand_total = flt(self.doc.base_grand_total / self.doc.conversion_rate) \
-				if (self.doc.base_total_taxes_and_charges or self.doc.discount_amount) else self.doc.net_total
-
-			self.doc.total_taxes_and_charges = flt(self.doc.grand_total - self.doc.net_total +
-				flt(self.doc.discount_amount), self.doc.precision("total_taxes_and_charges"))
+			self.doc.base_grand_total = flt(self.doc.grand_total * self.doc.conversion_rate) \
+				if self.doc.total_taxes_and_charges else self.doc.base_net_total
 		else:
-			self.doc.base_taxes_and_charges_added, self.doc.base_taxes_and_charges_deducted = 0.0, 0.0
+			self.doc.taxes_and_charges_added, self.taxes_and_charges_deducted = 0.0, 0.0
 			for tax in self.doc.get("taxes"):
 				if tax.category in ["Valuation and Total", "Total"]:
 					if tax.add_deduct_tax == "Add":
-						self.doc.base_taxes_and_charges_added += flt(tax.tax_amount)
+						self.doc.taxes_and_charges_added += flt(tax.tax_amount)
 					else:
-						self.doc.base_taxes_and_charges_deducted += flt(tax.tax_amount)
+						self.doc.taxes_and_charges_deducted += flt(tax.tax_amount)
 
-			self.doc.round_floats_in(self.doc, ["base_taxes_and_charges_added", "base_taxes_and_charges_deducted"])
+			self.doc.round_floats_in(self.doc, ["taxes_and_charges_added", "taxes_and_charges_deducted"])
 
-			self.doc.grand_total = flt(self.doc.base_grand_total / self.doc.conversion_rate) \
-				if (self.doc.base_taxes_and_charges_added or self.doc.base_taxes_and_charges_deducted) else self.doc.net_total
+			self.doc.base_grand_total = flt(self.doc.grand_total * self.doc.conversion_rate) \
+				if (self.doc.taxes_and_charges_added or self.doc.taxes_and_charges_deducted) \
+				else self.doc.base_net_total
 
-			self.doc.total_taxes_and_charges = flt(self.doc.grand_total - self.doc.net_total,
-				self.doc.precision("total_taxes_and_charges"))
+			self._set_in_company_currency(self.doc, ["taxes_and_charges_added", "taxes_and_charges_deducted"])
 
-			self.doc.taxes_and_charges_added = flt(self.doc.base_taxes_and_charges_added / self.doc.conversion_rate,
-				self.doc.precision("taxes_and_charges_added"))
-			self.doc.taxes_and_charges_deducted = flt(self.doc.base_taxes_and_charges_deducted / self.doc.conversion_rate,
-				self.doc.precision("taxes_and_charges_deducted"))
+		self.doc.total_taxes_and_charges = flt(self.doc.grand_total - self.doc.net_total,
+			self.doc.precision("total_taxes_and_charges"))
 
-		self.doc.base_grand_total = flt(self.doc.base_grand_total, self.doc.precision("base_grand_total"))
-		self.doc.grand_total = flt(self.doc.grand_total, self.doc.precision("grand_total"))
+		self._set_in_company_currency(self.doc, ["total_taxes_and_charges"])
+		self.doc.round_floats_in(self.doc, ["grand_total", "base_grand_total"])
 
-		if self.doc.meta.get_field("base_rounded_total"):
-			self.doc.base_rounded_total = rounded(self.doc.base_grand_total)
 		if self.doc.meta.get_field("rounded_total"):
 			self.doc.rounded_total = rounded(self.doc.grand_total)
+		if self.doc.meta.get_field("base_rounded_total"):
+			self.doc.base_rounded_total = rounded(self.doc.base_grand_total)
 
 	def _cleanup(self):
 		for tax in self.doc.get("taxes"):
@@ -340,43 +318,50 @@
 
 	def apply_discount_amount(self):
 		if self.doc.discount_amount:
+			if not self.doc.apply_discount_on:
+				frappe.throw(_("Please select Apply Discount On"))
+
 			self.doc.base_discount_amount = flt(self.doc.discount_amount * self.doc.conversion_rate,
 				self.doc.precision("base_discount_amount"))
 
-			grand_total_for_discount_amount = self.get_grand_total_for_discount_amount()
+			total_for_discount_amount = self.get_total_for_discount_amount()
 
-			if grand_total_for_discount_amount:
+			if total_for_discount_amount:
 				# calculate item amount after Discount Amount
 				for item in self.doc.get("items"):
-					distributed_amount = flt(self.doc.base_discount_amount) * item.base_amount / grand_total_for_discount_amount
-					item.base_amount = flt(item.base_amount - distributed_amount, self.doc.precision("base_amount", item))
+					distributed_amount = flt(self.doc.discount_amount) * item.net_amount / total_for_discount_amount
+					item.net_amount = flt(item.net_amount - distributed_amount, item.precision("net_amount"))
+					item.net_rate = flt(item.net_amount / item.qty, item.precision("net_rate"))
+
+					self._set_in_company_currency(item, ["net_rate", "net_amount"])
 
 				self.discount_amount_applied = True
 				self._calculate()
 		else:
 			self.doc.base_discount_amount = 0
 
-	def get_grand_total_for_discount_amount(self):
-		actual_taxes_dict = {}
+	def get_total_for_discount_amount(self):
+		if self.doc.apply_discount_on == "Net Total":
+			return self.doc.net_total
+		else:
+			actual_taxes_dict = {}
 
-		for tax in self.doc.get("taxes"):
-			if tax.charge_type == "Actual":
-				actual_taxes_dict.setdefault(tax.idx, tax.tax_amount)
-			elif tax.row_id in actual_taxes_dict:
-				actual_tax_amount = flt(actual_taxes_dict.get(tax.row_id, 0)) * flt(tax.rate) / 100
-				actual_taxes_dict.setdefault(tax.idx, actual_tax_amount)
+			for tax in self.doc.get("taxes"):
+				if tax.charge_type == "Actual":
+					actual_taxes_dict.setdefault(tax.idx, tax.tax_amount)
+				elif tax.row_id in actual_taxes_dict:
+					actual_tax_amount = flt(actual_taxes_dict.get(tax.row_id, 0)) * flt(tax.rate) / 100
+					actual_taxes_dict.setdefault(tax.idx, actual_tax_amount)
 
-		grand_total_for_discount_amount = flt(self.doc.base_grand_total - sum(actual_taxes_dict.values()),
-			self.doc.precision("base_grand_total"))
-		return grand_total_for_discount_amount
+			return flt(self.doc.grand_total - sum(actual_taxes_dict.values()), self.doc.precision("grand_total"))
 
 
 	def calculate_total_advance(self):
 		if self.doc.docstatus < 2:
-			sum_of_allocated_amount = sum([flt(adv.allocated_amount, self.doc.precision("allocated_amount", adv))
+			total_allocated_amount = sum([flt(adv.allocated_amount, adv.precision("allocated_amount"))
 				for adv in self.doc.get("advances")])
 
-			self.doc.total_advance = flt(sum_of_allocated_amount, self.doc.precision("total_advance"))
+			self.doc.total_advance = flt(total_allocated_amount, self.doc.precision("total_advance"))
 
 			if self.doc.docstatus == 0:
 				self.calculate_outstanding_amount()
diff --git a/erpnext/controllers/trends.py b/erpnext/controllers/trends.py
index c2d5e00..dc7039e 100644
--- a/erpnext/controllers/trends.py
+++ b/erpnext/controllers/trends.py
@@ -132,9 +132,9 @@
 	else:
 		pwc = [_(filters.get("fiscal_year")) + " ("+_("Qty") + "):Float:120",
 			_(filters.get("fiscal_year")) + " ("+ _("Amt") + "):Currency:120"]
-		query_details = " SUM(t2.qty), SUM(t2.base_amount),"
+		query_details = " SUM(t2.qty), SUM(t2.base_net_amount),"
 
-	query_details += 'SUM(t2.qty), SUM(t2.base_amount)'
+	query_details += 'SUM(t2.qty), SUM(t2.base_net_amount)'
 	return pwc, query_details
 
 def get_period_wise_columns(bet_dates, period, pwc):
@@ -147,7 +147,7 @@
 
 def get_period_wise_query(bet_dates, trans_date, query_details):
 	query_details += """SUM(IF(t1.%(trans_date)s BETWEEN '%(sd)s' AND '%(ed)s', t2.qty, NULL)),
-					SUM(IF(t1.%(trans_date)s BETWEEN '%(sd)s' AND '%(ed)s', t2.base_amount, NULL)),
+					SUM(IF(t1.%(trans_date)s BETWEEN '%(sd)s' AND '%(ed)s', t2.base_net_amount, NULL)),
 				""" % {"trans_date": trans_date, "sd": bet_dates[0],"ed": bet_dates[1]}
 	return query_details
 
diff --git a/erpnext/patches.txt b/erpnext/patches.txt
index 05b92b1..f6ac860 100644
--- a/erpnext/patches.txt
+++ b/erpnext/patches.txt
@@ -112,7 +112,6 @@
 erpnext.patches.v5_0.update_item_name_in_bom
 erpnext.patches.v5_0.rename_customer_issue
 erpnext.patches.v5_0.rename_total_fields
-erpnext.patches.v5_0.replace_renamed_fields_in_custom_script_and_print_formats
 erpnext.patches.v5_0.new_crm_module
 erpnext.patches.v5_0.rename_customer_issue
 erpnext.patches.v5_0.update_material_transfer_for_manufacture
@@ -124,3 +123,5 @@
 erpnext.patches.v5_0.update_projects
 erpnext.patches.v5_0.item_patches
 erpnext.patches.v5_0.update_journal_entry_title
+erpnext.patches.v5_0.taxes_and_totals_in_party_currency
+erpnext.patches.v5_0.replace_renamed_fields_in_custom_scripts_and_print_formats
diff --git a/erpnext/patches/v4_0/set_naming_series_property_setter.py b/erpnext/patches/v4_0/set_naming_series_property_setter.py
index bd4ed91..ff241ae 100644
--- a/erpnext/patches/v4_0/set_naming_series_property_setter.py
+++ b/erpnext/patches/v4_0/set_naming_series_property_setter.py
@@ -35,7 +35,6 @@
 def execute():
 	series_to_set = get_series_to_set()
 	for doctype, opts in series_to_set.items():
-		print "Setting naming series", doctype, opts
 		set_series(doctype, opts["options"], opts["default"])
 
 def set_series(doctype, options, default):
diff --git a/erpnext/patches/v5_0/replace_renamed_fields_in_custom_script_and_print_formats.py b/erpnext/patches/v5_0/replace_renamed_fields_in_custom_scripts_and_print_formats.py
similarity index 88%
rename from erpnext/patches/v5_0/replace_renamed_fields_in_custom_script_and_print_formats.py
rename to erpnext/patches/v5_0/replace_renamed_fields_in_custom_scripts_and_print_formats.py
index f8775c1..7fe775b 100644
--- a/erpnext/patches/v5_0/replace_renamed_fields_in_custom_script_and_print_formats.py
+++ b/erpnext/patches/v5_0/replace_renamed_fields_in_custom_scripts_and_print_formats.py
@@ -21,9 +21,10 @@
 	from erpnext.patches.v5_0.rename_table_fieldnames import rename_map
 
 	renamed_fields = (
+		("base_amount", "base_net_amount"),
 		("net_total", "base_net_total"),
-		("net_total_export", "net_total"),
-		("net_total_import", "net_total"),
+		("net_total_export", "total"),
+		("net_total_import", "total"),
 		("other_charges_total", "base_total_taxes_and_charges"),
 		("other_charges_total_export", "total_taxes_and_charges"),
 		("other_charges_added", "base_taxes_and_charges_added"),
@@ -39,7 +40,9 @@
 		("rounded_total_import", "rounded_total"),
 		("in_words", "base_in_words"),
 		("in_words_export", "in_words"),
-		("in_words_import", "in_words")
+		("in_words_import", "in_words"),
+		("tax_amount", "base_tax_amount"),
+		("tax_amount_after_discount_amount", "base_tax_amount_after_discount_amount"),
 	)
 
 	for fields in rename_map.values():
diff --git a/erpnext/patches/v5_0/taxes_and_totals_in_party_currency.py b/erpnext/patches/v5_0/taxes_and_totals_in_party_currency.py
new file mode 100644
index 0000000..b588971
--- /dev/null
+++ b/erpnext/patches/v5_0/taxes_and_totals_in_party_currency.py
@@ -0,0 +1,66 @@
+
+# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors
+# License: GNU General Public License v3. See license.txt
+
+import frappe
+
+def execute():
+	selling_doctypes = ["Quotation", "Sales Order", "Delivery Note", "Sales Invoice"]
+	buying_doctypes = ["Supplier Quotation", "Purchase Order", "Purchase Receipt", "Purchase Invoice"]
+
+	for dt in selling_doctypes:
+		update_values(dt, "Sales Taxes and Charges")
+
+	for dt in buying_doctypes:
+		update_values(dt, "Purchase Taxes and Charges")
+
+def update_values(dt, tax_table):
+	frappe.reload_doctype(dt)
+	frappe.reload_doctype(dt + " Item")
+	frappe.reload_doctype(tax_table)
+
+	# update net_total, discount_on
+	frappe.db.sql("""
+		UPDATE
+			`tab{0}`
+		SET
+			total = net_total,
+			base_total = net_total*conversion_rate,
+			net_total = base_net_total / conversion_rate,
+			apply_discount_on = "Grand Total"
+		WHERE
+			docstatus < 2
+	""".format(dt))
+
+
+	# update net_amount
+	frappe.db.sql("""
+		UPDATE
+			`tab{0}` par, `tab{1}` item
+		SET
+			item.base_net_amount = item.base_amount,
+			item.base_net_rate = item.base_rate,
+			item.net_amount = item.base_net_amount / par.conversion_rate,
+			item.net_rate = item.base_net_rate / par.conversion_rate,
+			item.base_amount = item.amount * par.conversion_rate,
+			item.base_rate = item.rate * par.conversion_rate
+		WHERE
+			par.name = item.parent
+			and par.docstatus < 2
+	""".format(dt, dt + " Item"))
+
+	# update tax in party currency
+	frappe.db.sql("""
+		UPDATE
+			`tab{0}` par, `tab{1}` tax
+		SET
+			tax.base_tax_amount = tax.tax_amount,
+			tax.tax_amount = tax.base_tax_amount / par.conversion_rate,
+			tax.base_total = tax.total,
+			tax.total = tax.base_total / conversion_rate,
+			tax.base_tax_amount_after_discount_amount = tax.tax_amount_after_discount_amount,
+			tax.tax_amount_after_discount_amount = tax.base_tax_amount_after_discount_amount / conversion_rate
+		WHERE
+			par.name = tax.parent
+			and par.docstatus < 2
+	""".format(dt, tax_table))
diff --git a/erpnext/projects/doctype/time_log/time_log.js b/erpnext/projects/doctype/time_log/time_log.js
index 5f7e846..eb2e1a0 100644
--- a/erpnext/projects/doctype/time_log/time_log.js
+++ b/erpnext/projects/doctype/time_log/time_log.js
@@ -77,7 +77,6 @@
 			},
 			callback: function(r) {
 				if(!r.exc) {
-					console.log(r.message)
 					cur_frm.set_value("workstation", r.message)
 				}
 			}
diff --git a/erpnext/projects/report/project_wise_stock_tracking/project_wise_stock_tracking.py b/erpnext/projects/report/project_wise_stock_tracking/project_wise_stock_tracking.py
index 538b7ed..9146e42 100644
--- a/erpnext/projects/report/project_wise_stock_tracking/project_wise_stock_tracking.py
+++ b/erpnext/projects/report/project_wise_stock_tracking/project_wise_stock_tracking.py
@@ -13,19 +13,19 @@
 
 	data = []
 	for project in proj_details:
-		data.append([project.name, pr_item_map.get(project.name, 0), 
-			se_item_map.get(project.name, 0), dn_item_map.get(project.name, 0), 
-			project.project_name, project.status, project.company, 
-			project.customer, project.project_value, project.project_start_date, 
+		data.append([project.name, pr_item_map.get(project.name, 0),
+			se_item_map.get(project.name, 0), dn_item_map.get(project.name, 0),
+			project.project_name, project.status, project.company,
+			project.customer, project.project_value, project.project_start_date,
 			project.completion_date])
 
-	return columns, data 
+	return columns, data
 
 def get_columns():
 	return [_("Project Id") + ":Link/Project:140", _("Cost of Purchased Items") + ":Currency:160",
-		_("Cost of Issued Items") + ":Currency:160", _("Cost of Delivered Items") + ":Currency:160", 
-		_("Project Name") + "::120", _("Project Status") + "::120", _("Company") + ":Link/Company:100", 
-		_("Customer") + ":Link/Customer:140", _("Project Value") + ":Currency:120", 
+		_("Cost of Issued Items") + ":Currency:160", _("Cost of Delivered Items") + ":Currency:160",
+		_("Project Name") + "::120", _("Project Status") + "::120", _("Company") + ":Link/Company:100",
+		_("Customer") + ":Link/Customer:140", _("Project Value") + ":Currency:120",
 		_("Project Start Date") + ":Date:120", _("Completion Date") + ":Date:120"]
 
 def get_project_details():
@@ -33,8 +33,8 @@
 		project_start_date, completion_date from tabProject where docstatus < 2""", as_dict=1)
 
 def get_purchased_items_cost():
-	pr_items = frappe.db.sql("""select project_name, sum(base_amount) as amount
-		from `tabPurchase Receipt Item` where ifnull(project_name, '') != '' 
+	pr_items = frappe.db.sql("""select project_name, sum(base_net_amount) as amount
+		from `tabPurchase Receipt Item` where ifnull(project_name, '') != ''
 		and docstatus = 1 group by project_name""", as_dict=1)
 
 	pr_item_map = {}
@@ -46,7 +46,7 @@
 def get_issued_items_cost():
 	se_items = frappe.db.sql("""select se.project_name, sum(se_item.amount) as amount
 		from `tabStock Entry` se, `tabStock Entry Detail` se_item
-		where se.name = se_item.parent and se.docstatus = 1 and ifnull(se_item.t_warehouse, '') = '' 
+		where se.name = se_item.parent and se.docstatus = 1 and ifnull(se_item.t_warehouse, '') = ''
 		and ifnull(se.project_name, '') != '' group by se.project_name""", as_dict=1)
 
 	se_item_map = {}
@@ -56,14 +56,14 @@
 	return se_item_map
 
 def get_delivered_items_cost():
-	dn_items = frappe.db.sql("""select dn.project_name, sum(dn_item.base_amount) as amount
+	dn_items = frappe.db.sql("""select dn.project_name, sum(dn_item.base_net_amount) as amount
 		from `tabDelivery Note` dn, `tabDelivery Note Item` dn_item
 		where dn.name = dn_item.parent and dn.docstatus = 1 and ifnull(dn.project_name, '') != ''
 		group by dn.project_name""", as_dict=1)
 
-	si_items = frappe.db.sql("""select si.project_name, sum(si_item.base_amount) as amount
+	si_items = frappe.db.sql("""select si.project_name, sum(si_item.base_net_amount) as amount
 		from `tabSales Invoice` si, `tabSales Invoice Item` si_item
-		where si.name = si_item.parent and si.docstatus = 1 and ifnull(si.update_stock, 0) = 1 
+		where si.name = si_item.parent and si.docstatus = 1 and ifnull(si.update_stock, 0) = 1
 		and ifnull(si.is_pos, 0) = 1 and ifnull(si.project_name, '') != ''
 		group by si.project_name""", as_dict=1)
 
@@ -75,4 +75,4 @@
 	for item in si_items:
 		dn_item_map.setdefault(item.project_name, item.amount)
 
-	return dn_item_map
\ No newline at end of file
+	return dn_item_map
diff --git a/erpnext/public/js/controllers/accounts.js b/erpnext/public/js/controllers/accounts.js
index 03e1890..d0f27bc 100644
--- a/erpnext/public/js/controllers/accounts.js
+++ b/erpnext/public/js/controllers/accounts.js
@@ -1,3 +1,5 @@
+// Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors
+// License: GNU General Public License v3. See license.txt
 
 // get tax rate
 cur_frm.cscript.account_head = function(doc, cdt, cdn) {
@@ -8,7 +10,7 @@
 	} else if(d.account_head && d.charge_type!=="Actual") {
 		frappe.call({
 			type:"GET",
-			method: "erpnext.controllers.accounts_controller.get_tax_rate", 
+			method: "erpnext.controllers.accounts_controller.get_tax_rate",
 			args: {"account_head":d.account_head},
 			callback: function(r) {
 			  frappe.model.set_value(cdt, cdn, "rate", r.message || 0);
@@ -16,3 +18,187 @@
 		})
 	}
 }
+
+cur_frm.cscript.validate_taxes_and_charges = function(cdt, cdn) {
+	var d = locals[cdt][cdn];
+	var msg = "";
+	if(!d.charge_type && (d.row_id || d.rate || d.tax_amount)) {
+		msg = __("Please select Charge Type first");
+		d.row_id = "";
+		d.rate = d.tax_amount = 0.0;
+	} else if((d.charge_type == 'Actual' || d.charge_type == 'On Net Total') && d.row_id) {
+		msg = __("Can refer row only if the charge type is 'On Previous Row Amount' or 'Previous Row Total'");
+		d.row_id = "";
+	} else if((d.charge_type == 'On Previous Row Amount' || d.charge_type == 'On Previous Row Total') && d.row_id) {
+		if (d.idx == 1) {
+			msg = __("Cannot select charge type as 'On Previous Row Amount' or 'On Previous Row Total' for first row");
+			d.charge_type = '';
+		} else if (!d.row_id) {
+			msg = __("Please specify a valid Row ID for row {0} in table {1}", [d.idx, __(d.doctype)]);
+			d.row_id = "";
+		} else if(d.row_id && d.row_id >= d.idx) {
+			msg = __("Cannot refer row number greater than or equal to current row number for this Charge type");
+			d.row_id = "";
+		}
+	}
+	if(msg) {
+		validated = false;
+		refresh_field("taxes");
+		frappe.throw(msg);
+	}
+
+}
+
+cur_frm.cscript.validate_inclusive_tax = function(tax) {
+	var actual_type_error = function() {
+		var msg = __("Actual type tax cannot be included in Item rate in row {0}", [tax.idx])
+		frappe.throw(msg);
+	};
+
+	var on_previous_row_error = function(row_range) {
+		var msg = __("For row {0} in {1}. To include {2} in Item rate, rows {3} must also be included",
+			[tax.idx, __(tax.doctype), tax.charge_type, row_range])
+		frappe.throw(msg);
+	};
+
+	if(cint(tax.included_in_print_rate)) {
+		if(tax.charge_type == "Actual") {
+			// inclusive tax cannot be of type Actual
+			actual_type_error();
+		} else if(tax.charge_type == "On Previous Row Amount" &&
+			!cint(this.frm.doc["taxes"][tax.row_id - 1].included_in_print_rate)) {
+				// referred row should also be an inclusive tax
+				on_previous_row_error(tax.row_id);
+		} else if(tax.charge_type == "On Previous Row Total") {
+			var taxes_not_included = $.map(this.frm.doc["taxes"].slice(0, tax.row_id),
+				function(t) { return cint(t.included_in_print_rate) ? null : t; });
+			if(taxes_not_included.length > 0) {
+				// all rows above this tax should be inclusive
+				on_previous_row_error(tax.row_id == 1 ? "1" : "1 - " + tax.row_id);
+			}
+		}
+	}
+}
+
+frappe.ui.form.on(cur_frm.cscript.tax_table, "row_id", function(frm, cdt, cdn) {
+	cur_frm.cscript.validate_taxes_and_charges(cdt, cdn);
+});
+
+frappe.ui.form.on(cur_frm.cscript.tax_table, "rate", function(frm, cdt, cdn) {
+	cur_frm.cscript.validate_taxes_and_charges(cdt, cdn);
+});
+
+frappe.ui.form.on(cur_frm.cscript.tax_table, "tax_amount", function(frm, cdt, cdn) {
+	cur_frm.cscript.validate_taxes_and_charges(cdt, cdn);
+});
+
+frappe.ui.form.on(cur_frm.cscript.tax_table, "charge_type", function(frm, cdt, cdn) {
+	cur_frm.cscript.validate_taxes_and_charges(cdt, cdn);
+});
+
+frappe.ui.form.on(cur_frm.cscript.tax_table, "included_in_print_rate", function(frm, cdt, cdn) {
+	var tax = frappe.get_doc(cdt, cdn);
+	try {
+		cur_frm.cscript.validate_taxes_and_charges(cdt, cdn);
+		cur_frm.cscript.validate_inclusive_tax(tax);
+	} catch(e) {
+		tax.included_in_print_rate = 0;
+		refresh_field("included_in_print_rate", tax.name, tax.parentfield);
+		throw e;
+	}
+});
+
+cur_frm.set_query("account_head", "taxes", function(doc) {
+	if(cur_frm.cscript.tax_table == "Sales Taxes and Charges") {
+		var account_type = ["Tax", "Chargeable", "Expense Account"];
+	} else {
+		var account_type = ["Tax", "Chargeable", "Income Account"];
+	}
+
+	return {
+		query: "erpnext.controllers.queries.tax_account_query",
+		filters: {
+			"account_type": account_type,
+			"company": doc.company
+		}
+	}
+});
+
+cur_frm.set_query("cost_center", "taxes", function(doc) {
+	return {
+		filters: {
+			'company': doc.company,
+			'group_or_ledger': "Ledger"
+		}
+	}
+});
+
+// For customizing print
+cur_frm.pformat.total = function(doc) { return ''; }
+cur_frm.pformat.discount_amount = function(doc) { return ''; }
+cur_frm.pformat.grand_total = function(doc) { return ''; }
+cur_frm.pformat.rounded_total = function(doc) { return ''; }
+cur_frm.pformat.in_words = function(doc) { return ''; }
+
+cur_frm.pformat.taxes= function(doc){
+	//function to make row of table
+	var make_row = function(title, val, bold, is_negative) {
+		var bstart = '<b>'; var bend = '</b>';
+		return '<tr><td style="width:50%;">' + (bold?bstart:'') + title + (bold?bend:'') + '</td>'
+			+ '<td style="width:50%;text-align:right;">' + (is_negative ? '- ' : '')
+		+ format_currency(val, doc.currency) + '</td></tr>';
+	}
+
+	function print_hide(fieldname) {
+		var doc_field = frappe.meta.get_docfield(doc.doctype, fieldname, doc.name);
+		return doc_field.print_hide;
+	}
+
+	out ='';
+	if (!doc.print_without_amount) {
+		var cl = doc.taxes || [];
+
+		// outer table
+		var out='<div><table class="noborder" style="width:100%"><tr><td style="width: 60%"></td><td>';
+
+		// main table
+
+		out +='<table class="noborder" style="width:100%">';
+
+		if(!print_hide('total')) {
+			out += make_row('Total', doc.total, 1);
+		}
+
+		// Discount Amount on net total
+		if(!print_hide('discount_amount') && doc.apply_discount_on == "Net Total" && doc.discount_amount)
+			out += make_row('Discount Amount', doc.discount_amount, 0, 1);
+
+		// add rows
+		if(cl.length){
+			for(var i=0;i<cl.length;i++) {
+				if(cl[i].tax_amount!=0 && !cl[i].included_in_print_rate)
+					out += make_row(cl[i].description, cl[i].tax_amount, 0);
+			}
+		}
+
+		// Discount Amount on grand total
+		if(!print_hide('discount_amount') && doc.apply_discount_on == "Grand Total" && doc.discount_amount)
+			out += make_row('Discount Amount', doc.discount_amount, 0, 1);
+
+		// grand total
+		if(!print_hide('grand_total'))
+			out += make_row('Grand Total', doc.grand_total, 1);
+
+		if(!print_hide('rounded_total'))
+			out += make_row('Rounded Total', doc.rounded_total, 1);
+
+		if(doc.in_words && !print_hide('in_words')) {
+			out +='</table></td></tr>';
+			out += '<tr><td colspan = "2">';
+			out += '<table><tr><td style="width:25%;"><b>In Words</b></td>';
+			out += '<td style="width:50%;">' + doc.in_words + '</td></tr>';
+		}
+		out += '</table></td></tr></table></div>';
+	}
+	return out;
+}
diff --git a/erpnext/public/js/controllers/taxes_and_totals.js b/erpnext/public/js/controllers/taxes_and_totals.js
index 663f6ab..a3fff91 100644
--- a/erpnext/public/js/controllers/taxes_and_totals.js
+++ b/erpnext/public/js/controllers/taxes_and_totals.js
@@ -38,22 +38,47 @@
 		this.show_item_wise_taxes();
 	},
 
+	validate_conversion_rate: function() {
+		this.frm.doc.conversion_rate = flt(this.frm.doc.conversion_rate, precision("conversion_rate"));
+		var conversion_rate_label = frappe.meta.get_label(this.frm.doc.doctype, "conversion_rate",
+			this.frm.doc.name);
+		var company_currency = this.get_company_currency();
+
+		if(!this.frm.doc.conversion_rate) {
+			frappe.throw(repl('%(conversion_rate_label)s' +
+				__(' is mandatory. Maybe Currency Exchange record is not created for ') +
+				'%(from_currency)s' + __(" to ") + '%(to_currency)s',
+				{
+					"conversion_rate_label": conversion_rate_label,
+					"from_currency": this.frm.doc.currency,
+					"to_currency": company_currency
+				}));
+		}
+	},
+
 	calculate_item_values: function() {
 		var me = this;
 
 		if (!this.discount_amount_applied) {
 			$.each(this.frm.doc["items"] || [], function(i, item) {
 				frappe.model.round_floats_in(item);
+				item.net_rate = item.rate;
 				item.amount = flt(item.rate * item.qty, precision("amount", item));
+				item.net_amount = item.amount;
 				item.item_tax_amount = 0.0;
 
-				$.each(["price_list_rate", "rate", "amount"], function(i, f) {
-					item["base_" + f] = flt(item[f] * me.frm.doc.conversion_rate, precision("base_" + f, item));
-				})
+				me.set_in_company_currency(item, ["price_list_rate", "rate", "amount", "net_rate", "net_amount"]);
 			});
 		}
 	},
 
+	set_in_company_currency: function(doc, fields) {
+		var me = this;
+		$.each(fields, function(i, f) {
+			doc["base_"+f] = flt(flt(doc[f], precision(f, doc)) * me.frm.doc.conversion_rate, precision("base_" + f, doc));
+		})
+	},
+
 	initialize_taxes: function() {
 		var me = this;
 
@@ -63,21 +88,27 @@
 				"tax_amount_for_current_item", "grand_total_for_current_item",
 				"tax_fraction_for_current_item", "grand_total_fraction_for_current_item"]
 
-			if (!me.discount_amount_applied)
-				tax_fields.push("tax_amount");
+			if (cstr(tax.charge_type) != "Actual" &&
+				!(me.discount_amount_applied && me.frm.doc.apply_discount_on=="Grand Total"))
+					tax_fields.push("tax_amount");
 
 			$.each(tax_fields, function(i, fieldname) { tax[fieldname] = 0.0 });
 
-			me.validate_on_previous_row(tax);
+			cur_frm.cscript.validate_taxes_and_charges(tax.doctype, tax.name);
 			me.validate_inclusive_tax(tax);
 			frappe.model.round_floats_in(tax);
 		});
 	},
 
 	determine_exclusive_rate: function() {
-		if(!in_list(["Quotation", "Sales Order", "Delivery Note", "Sales Invoice"], this.frm.doc.doctype)) return;
-
 		var me = this;
+
+		var has_inclusive_tax = false;
+		$.each(me.frm.doc["taxes"] || [], function(i, row) {
+			if(cint(row.included_in_print_rate)) has_inclusive_tax = true;
+		})
+		if(has_inclusive_tax==false) return;
+
 		$.each(me.frm.doc["items"] || [], function(n, item) {
 			var item_tax_map = me._load_item_tax_rate(item.item_tax_rate);
 			var cumulated_tax_fraction = 0.0;
@@ -97,19 +128,18 @@
 			});
 
 			if(cumulated_tax_fraction && !me.discount_amount_applied) {
-				item.base_amount = flt(
-					(item.amount * me.frm.doc.conversion_rate) / (1 + cumulated_tax_fraction),
-					precision("base_amount", item));
+				item.net_amount = flt(item.amount / (1 + cumulated_tax_fraction), precision("net_amount", item));
+				item.net_rate = flt(item.net_amount / item.qty, precision("net_rate", item));
 
-				item.base_rate = flt(item.base_amount / item.qty, precision("base_rate", item));
+				me.set_in_company_currency(item, ["net_rate", "net_amount"]);
 
-				if(item.discount_percentage == 100) {
-					item.base_price_list_rate = item.base_rate;
-					item.base_rate = 0.0;
-				} else {
-					item.base_price_list_rate = flt(item.base_rate / (1 - item.discount_percentage / 100.0),
-						precision("base_price_list_rate", item));
-				}
+				// if(item.discount_percentage == 100) {
+				// 	item.base_price_list_rate = item.base_rate;
+				// 	item.base_rate = 0.0;
+				// } else {
+				// 	item.base_price_list_rate = flt(item.base_rate / (1 - item.discount_percentage / 100.0),
+				// 		precision("base_price_list_rate", item));
+				// }
 			}
 		});
 	},
@@ -140,20 +170,21 @@
 
 	_get_tax_rate: function(tax, item_tax_map) {
 		return (keys(item_tax_map).indexOf(tax.account_head) != -1) ?
-			flt(item_tax_map[tax.account_head], precision("rate", tax)) :
-			tax.rate;
+			flt(item_tax_map[tax.account_head], precision("rate", tax)) : tax.rate;
 	},
 
 	calculate_net_total: function() {
 		var me = this;
-		this.frm.doc.base_net_total = this.frm.doc.net_total = 0.0;
+		this.frm.doc.total = this.frm.doc.base_total = this.frm.doc.net_total = this.frm.doc.base_net_total = 0.0;
 
 		$.each(this.frm.doc["items"] || [], function(i, item) {
-			me.frm.doc.base_net_total += item.base_amount;
-			me.frm.doc.net_total += item.amount;
+			me.frm.doc.total += item.amount;
+			me.frm.doc.base_total += item.base_amount;
+			me.frm.doc.net_total += item.net_amount;
+			me.frm.doc.base_net_total += item.base_net_amount;
 		});
 
-		frappe.model.round_floats_in(this.frm.doc, ["base_net_total", "net_total"]);
+		frappe.model.round_floats_in(this.frm.doc, ["total", "base_total", "net_total", "base_net_total"]);
 	},
 
 	calculate_taxes: function() {
@@ -163,7 +194,7 @@
 		// maintain actual tax rate based on idx
 		$.each(this.frm.doc["taxes"] || [], function(i, tax) {
 			if (tax.charge_type == "Actual") {
-				actual_tax_dict[tax.idx] = flt(tax.rate, precision("tax_amount", tax));
+				actual_tax_dict[tax.idx] = flt(tax.tax_amount, precision("tax_amount", tax));
 			}
 		});
 
@@ -182,14 +213,16 @@
 					}
 				}
 
+				// accumulate tax amount into tax.tax_amount
+				if (tax.charge_type != "Actual" &&
+					!(me.discount_amount_applied && me.frm.doc.apply_discount_on=="Grand Total"))
+						tax.tax_amount += current_tax_amount;
+
 				// store tax_amount for current item as it will be used for
 				// charge type = 'On Previous Row Amount'
 				tax.tax_amount_for_current_item = current_tax_amount;
 
-				// accumulate tax amount into tax.tax_amount
-				if (!me.discount_amount_applied)
-					tax.tax_amount += current_tax_amount;
-
+				// tax amount after discount amount
 				tax.tax_amount_after_discount_amount += current_tax_amount;
 
 				// for buying
@@ -205,12 +238,10 @@
 				// note: grand_total_for_current_item contains the contribution of
 				// item's amount, previously applied tax and the current tax on that item
 				if(i==0) {
-					tax.grand_total_for_current_item = flt(item.base_amount + current_tax_amount,
-						precision("total", tax));
+					tax.grand_total_for_current_item = flt(item.net_amount + current_tax_amount);
 				} else {
 					tax.grand_total_for_current_item =
-						flt(me.frm.doc["taxes"][i-1].grand_total_for_current_item + current_tax_amount,
-							precision("total", tax));
+						flt(me.frm.doc["taxes"][i-1].grand_total_for_current_item + current_tax_amount);
 				}
 
 				// in tax.total, accumulate grand total for each item
@@ -221,7 +252,7 @@
 					me.round_off_totals(tax);
 
 					// adjust Discount Amount loss in last tax iteration
-					if ((i == me.frm.doc["taxes"].length - 1) && me.discount_amount_applied)
+					if ((i == me.frm.doc["taxes"].length - 1) && me.discount_amount_applied && me.frm.doc.apply_discount_on == "Grand Total")
 						me.adjust_discount_amount_loss(tax);
 				}
 			});
@@ -238,12 +269,12 @@
 
 		if(tax.charge_type == "Actual") {
 			// distribute the tax amount proportionally to each item row
-			var actual = flt(tax.rate, precision("tax_amount", tax));
-			current_tax_amount = this.frm.doc.base_net_total ?
-			((item.base_amount / this.frm.doc.base_net_total) * actual) : 0.0;
+			var actual = flt(tax.tax_amount, precision("tax_amount", tax));
+			current_tax_amount = this.frm.doc.net_total ?
+				((item.net_amount / this.frm.doc.net_total) * actual) : 0.0;
 
 		} else if(tax.charge_type == "On Net Total") {
-			current_tax_amount = (tax_rate / 100.0) * item.base_amount;
+			current_tax_amount = (tax_rate / 100.0) * item.net_amount;
 
 		} else if(tax.charge_type == "On Previous Row Amount") {
 			current_tax_amount = (tax_rate / 100.0) *
@@ -254,31 +285,90 @@
 				this.frm.doc["taxes"][cint(tax.row_id) - 1].grand_total_for_current_item;
 		}
 
-		current_tax_amount = flt(current_tax_amount, precision("tax_amount", tax));
+		// current_tax_amount = flt(current_tax_amount, precision("tax_amount", tax));
 
-		// store tax breakup for each item
-		tax.item_wise_tax_detail[item.item_code || item.item_name] = [tax_rate, current_tax_amount];
+		this.set_item_wise_tax(item, tax, tax_rate, current_tax_amount);
 
 		return current_tax_amount;
 	},
 
+	set_item_wise_tax: function(item, tax, tax_rate, current_tax_amount) {
+		// store tax breakup for each item
+		var key = item.item_code || item.item_name;
+		var item_wise_tax_amount = current_tax_amount * this.frm.doc.conversion_rate;
+		if (tax.item_wise_tax_detail && tax.item_wise_tax_detail[key])
+			item_wise_tax_amount += tax.item_wise_tax_detail[key][1]
+
+		tax.item_wise_tax_detail[key] = [tax_rate,flt(item_wise_tax_amount, precision("base_tax_amount", tax))]
+
+	},
+
 	round_off_totals: function(tax) {
 		tax.total = flt(tax.total, precision("total", tax));
 		tax.tax_amount = flt(tax.tax_amount, precision("tax_amount", tax));
-		tax.tax_amount_after_discount_amount = flt(tax.tax_amount_after_discount_amount,
-			precision("tax_amount", tax));
+		tax.tax_amount_after_discount_amount = flt(tax.tax_amount_after_discount_amount, precision("tax_amount", tax));
+
+		this.set_in_company_currency(tax, ["total", "tax_amount", "tax_amount_after_discount_amount"]);
 	},
 
 	adjust_discount_amount_loss: function(tax) {
-		var discount_amount_loss = this.frm.doc.base_grand_total - flt(this.frm.doc.base_discount_amount) - tax.total;
+		var discount_amount_loss = this.frm.doc.grand_total - flt(this.frm.doc.discount_amount) - tax.total;
 		tax.tax_amount_after_discount_amount = flt(tax.tax_amount_after_discount_amount +
 			discount_amount_loss, precision("tax_amount", tax));
 		tax.total = flt(tax.total + discount_amount_loss, precision("total", tax));
 	},
 
+	calculate_totals: function() {
+		// Changing sequence can cause roundiing issue and on-screen discrepency
+		var me = this;
+		var tax_count = this.frm.doc["taxes"] ? this.frm.doc["taxes"].length : 0;
+		this.frm.doc.grand_total = flt(tax_count ? this.frm.doc["taxes"][tax_count - 1].total : this.frm.doc.net_total);
+
+		if(in_list(["Quotation", "Sales Order", "Delivery Note", "Sales Invoice"], this.frm.doc.doctype)) {
+			this.frm.doc.base_grand_total = (this.frm.doc.total_taxes_and_charges) ?
+				flt(this.frm.doc.grand_total * this.frm.doc.conversion_rate) : this.frm.doc.base_net_total;
+		} else {
+			// other charges added/deducted
+			this.frm.doc.taxes_and_charges_added = this.frm.doc.taxes_and_charges_deducted = 0.0;
+			if(tax_count) {
+				$.each(this.frm.doc["taxes"] || [], function(i, tax) {
+					if (in_list(["Valuation and Total", "Total"], tax.category)) {
+						if(tax.add_deduct_tax == "Add") {
+							me.frm.doc.taxes_and_charges_added += flt(tax.tax_amount);
+						} else {
+							me.frm.doc.taxes_and_charges_deducted += flt(tax.tax_amount);
+						}
+					}
+				})
+
+				frappe.model.round_floats_in(this.frm.doc, ["taxes_and_charges_added", "taxes_and_charges_deducted"]);
+			}
+
+			this.frm.doc.base_grand_total = flt((this.frm.doc.taxes_and_charges_added || this.frm.doc.taxes_and_charges_deducted) ?
+				flt(this.frm.doc.grand_total * this.frm.doc.conversion_rate) : this.frm.doc.base_net_total);
+
+			this.set_in_company_currency(this.frm.doc, ["taxes_and_charges_added", "taxes_and_charges_deducted"]);
+		}
+
+		this.frm.doc.total_taxes_and_charges = flt(this.frm.doc.grand_total - this.frm.doc.net_total,
+			precision("total_taxes_and_charges"));
+
+		this.set_in_company_currency(this.frm.doc, ["total_taxes_and_charges"]);
+
+		// Round grand total as per precision
+		frappe.model.round_floats_in(this.frm.doc, ["grand_total", "base_grand_total"]);
+
+		// rounded totals
+		if(frappe.meta.get_docfield(this.frm.doc.doctype, "rounded_total", this.frm.doc.name)) {
+			this.frm.doc.rounded_total = Math.round(this.frm.doc.grand_total);
+		}
+		if(frappe.meta.get_docfield(this.frm.doc.doctype, "base_rounded_total", this.frm.doc.name)) {
+			this.frm.doc.base_rounded_total = Math.round(this.frm.doc.base_grand_total);
+		}
+	},
 
 	_cleanup: function() {
-		this.frm.doc.base_in_words = this.frm.doc.in_words = this.frm.doc.in_words = "";
+		this.frm.doc.base_in_words = this.frm.doc.in_words = "";
 
 		if(this.frm.doc["items"] && this.frm.doc["items"].length) {
 			if(!frappe.meta.get_docfield(this.frm.doc["items"][0].doctype, "item_tax_amount", this.frm.doctype)) {
@@ -288,7 +378,6 @@
 			}
 		}
 
-
 		if(this.frm.doc["taxes"] && this.frm.doc["taxes"].length) {
 			var temporary_fields = ["tax_amount_for_current_item", "grand_total_for_current_item",
 				"tax_fraction_for_current_item", "grand_total_fraction_for_current_item"]
@@ -307,79 +396,26 @@
 		}
 	},
 
-	calculate_totals: function() {
-		// Changing sequence can cause roundiing issue and on-screen discrepency
-
-		var tax_count = this.frm.doc["taxes"] ? this.frm.doc["taxes"].length : 0;
-		this.frm.doc.base_grand_total = flt(tax_count ? this.frm.doc["taxes"][tax_count - 1].total : this.frm.doc.base_net_total);
-
-		this.frm.doc.base_total_taxes_and_charges = flt(this.frm.doc.base_grand_total - this.frm.doc.base_net_total,
-			precision("base_total_taxes_and_charges"));
-
-		if(in_list(["Quotation", "Sales Order", "Delivery Note", "Sales Invoice"], this.frm.doc.doctype)) {
-			this.frm.doc.grand_total = (this.frm.doc.base_total_taxes_and_charges || this.frm.doc.discount_amount) ?
-				flt(this.frm.doc.base_grand_total / this.frm.doc.conversion_rate) : this.frm.doc.net_total;
-
-			this.frm.doc.total_taxes_and_charges = flt(this.frm.doc.grand_total - this.frm.doc.net_total
-				+ flt(this.frm.doc.discount_amount), precision("total_taxes_and_charges"));
-		} else {
-			// other charges added/deducted
-			this.frm.doc.base_taxes_and_charges_added = 0.0
-			this.frm.doc.base_taxes_and_charges_deducted = 0.0
-			if(tax_count) {
-				this.frm.doc.base_taxes_and_charges_added = frappe.utils.sum($.map(this.frm.doc["taxes"],
-					function(tax) { return (tax.add_deduct_tax == "Add"
-						&& in_list(["Valuation and Total", "Total"], tax.category)) ?
-						tax.tax_amount : 0.0; }));
-
-				this.frm.doc.base_taxes_and_charges_deducted = frappe.utils.sum($.map(this.frm.doc["taxes"],
-					function(tax) { return (tax.add_deduct_tax == "Deduct"
-						&& in_list(["Valuation and Total", "Total"], tax.category)) ?
-						tax.tax_amount : 0.0; }));
-
-				frappe.model.round_floats_in(this.frm.doc,
-					["base_taxes_and_charges_added", "base_taxes_and_charges_deducted"]);
-			}
-
-			this.frm.doc.grand_total = flt((this.frm.doc.base_taxes_and_charges_added || this.frm.doc.base_taxes_and_charges_deducted) ?
-				flt(this.frm.doc.base_grand_total / this.frm.doc.conversion_rate) : this.frm.doc.net_total);
-
-			this.frm.doc.total_taxes_and_charges = flt(this.frm.doc.grand_total - this.frm.doc.net_total,
-				precision("total_taxes_and_charges"));
-
-			this.frm.doc.taxes_and_charges_added = flt(this.frm.doc.base_taxes_and_charges_added /
-				this.frm.doc.conversion_rate, precision("taxes_and_charges_added"));
-			this.frm.doc.taxes_and_charges_deducted = flt(this.frm.doc.base_taxes_and_charges_deducted /
-				this.frm.doc.conversion_rate, precision("taxes_and_charges_deducted"));
-		}
-
-		// Round grand total as per precision
-		this.frm.doc.base_grand_total = flt(this.frm.doc.base_grand_total, precision("base_grand_total"));
-		this.frm.doc.grand_total = flt(this.frm.doc.grand_total, precision("grand_total"));
-
-		// rounded totals
-		if(frappe.meta.get_docfield(this.frm.doc.doctype, "base_rounded_total", this.frm.doc.name)) {
-			this.frm.doc.base_rounded_total = Math.round(this.frm.doc.base_grand_total);
-		}
-		if(frappe.meta.get_docfield(this.frm.doc.doctype, "rounded_total", this.frm.doc.name)) {
-			this.frm.doc.rounded_total = Math.round(this.frm.doc.grand_total);
-		}
-	},
-
 	apply_discount_amount: function() {
 		var me = this;
 		var distributed_amount = 0.0;
 
 		if (this.frm.doc.discount_amount) {
+			if(!this.frm.doc.apply_discount_on)
+				frappe.throw(__("Please select Apply Discount On"));
+
 			this.frm.set_value("base_discount_amount",
 				flt(this.frm.doc.discount_amount * this.frm.doc.conversion_rate, precision("base_discount_amount")))
 
-			var grand_total_for_discount_amount = this.get_grand_total_for_discount_amount();
+			var total_for_discount_amount = this.get_total_for_discount_amount();
 			// calculate item amount after Discount Amount
-			if (grand_total_for_discount_amount) {
+			if (total_for_discount_amount) {
 				$.each(this.frm.doc["items"] || [], function(i, item) {
-					distributed_amount = flt(me.frm.doc.base_discount_amount) * item.base_amount / grand_total_for_discount_amount;
-					item.base_amount = flt(item.base_amount - distributed_amount, precision("base_amount", item));
+					distributed_amount = flt(me.frm.doc.discount_amount) * item.net_amount / total_for_discount_amount;
+					item.net_amount = flt(item.net_amount - distributed_amount, precision("base_amount", item));
+					item.net_rate = flt(item.net_amount / item.qty, precision("net_rate", item));
+
+					me.set_in_company_currency(item, ["net_rate", "net_amount"]);
 				});
 
 				this.discount_amount_applied = true;
@@ -390,34 +426,37 @@
 		}
 	},
 
-	get_grand_total_for_discount_amount: function() {
+	get_total_for_discount_amount: function() {
 		var me = this;
-		var total_actual_tax = 0.0;
-		var actual_taxes_dict = {};
 
-		$.each(this.frm.doc["taxes"] || [], function(i, tax) {
-			if (tax.charge_type == "Actual")
-				actual_taxes_dict[tax.idx] = tax.tax_amount;
-			else if (actual_taxes_dict[tax.row_id] !== null) {
-				actual_tax_amount = flt(actual_taxes_dict[tax.row_id]) * flt(tax.rate) / 100;
-				actual_taxes_dict[tax.idx] = actual_tax_amount;
-			}
-		});
+		if(this.frm.doc.apply_discount_on == "Net Total") {
+			return this.frm.doc.net_total
+		} else {
+			var total_actual_tax = 0.0;
+			var actual_taxes_dict = {};
 
-		$.each(actual_taxes_dict, function(key, value) {
-			if (value)
-				total_actual_tax += value;
-		});
+			$.each(this.frm.doc["taxes"] || [], function(i, tax) {
+				if (tax.charge_type == "Actual")
+					actual_taxes_dict[tax.idx] = tax.tax_amount;
+				else if (actual_taxes_dict[tax.row_id] !== null) {
+					actual_tax_amount = flt(actual_taxes_dict[tax.row_id]) * flt(tax.rate) / 100;
+					actual_taxes_dict[tax.idx] = actual_tax_amount;
+				}
+			});
 
-		grand_total_for_discount_amount = flt(this.frm.doc.base_grand_total - total_actual_tax,
-			precision("base_grand_total"));
-		return grand_total_for_discount_amount;
+			$.each(actual_taxes_dict, function(key, value) {
+				if (value) total_actual_tax += value;
+			});
+
+			return flt(this.frm.doc.grand_total - total_actual_tax, precision("grand_total"));
+		}
 	},
 
 	calculate_total_advance: function(update_paid_amount) {
-		this.frm.doc.total_advance = flt(frappe.utils.sum(
-			$.map(this.frm.doc["advances"] || [], function(adv) { return adv.allocated_amount })
-		), precision("total_advance"));
+		var total_allocated_amount = frappe.utils.sum($.map(this.frm.doc["advances"] || [], function(adv) {
+			return flt(adv.allocated_amount, precision("allocated_amount", adv))
+		}));
+		this.frm.doc.total_advance = flt(total_allocated_amount, precision("total_advance"));
 
 		this.calculate_outstanding_amount(update_paid_amount);
 	}
diff --git a/erpnext/public/js/controllers/transaction.js b/erpnext/public/js/controllers/transaction.js
index 1dca837..3f9846f 100644
--- a/erpnext/public/js/controllers/transaction.js
+++ b/erpnext/public/js/controllers/transaction.js
@@ -274,23 +274,6 @@
 		this.apply_pricing_rule(frappe.get_doc(cdt, cdn), true);
 	},
 
-	// tax rate
-	rate: function(doc, cdt, cdn) {
-		this.calculate_taxes_and_totals();
-	},
-
-	row_id: function(doc, cdt, cdn) {
-		var tax = frappe.get_doc(cdt, cdn);
-		try {
-			this.validate_on_previous_row(tax);
-			this.calculate_taxes_and_totals();
-		} catch(e) {
-			tax.row_id = null;
-			refresh_field("row_id", tax.name, tax.parentfield);
-			throw e;
-		}
-	},
-
 	set_dynamic_labels: function() {
 		// What TODO? should we make price list system non-mandatory?
 		this.frm.toggle_reqd("plc_conversion_rate",
@@ -302,6 +285,113 @@
 		this.frm.refresh_fields();
 	},
 
+	change_form_labels: function(company_currency) {
+		var me = this;
+		var field_label_map = {};
+
+		var setup_field_label_map = function(fields_list, currency) {
+			$.each(fields_list, function(i, fname) {
+				var docfield = frappe.meta.docfield_map[me.frm.doc.doctype][fname];
+				if(docfield) {
+					var label = __(docfield.label || "").replace(/\([^\)]*\)/g, "");
+					field_label_map[fname] = label.trim() + " (" + currency + ")";
+				}
+			});
+		};
+		setup_field_label_map(["base_total", "base_net_total", "base_total_taxes_and_charges",
+			"base_discount_amount", "base_grand_total", "base_rounded_total", "base_in_words",
+			"base_taxes_and_charges_added", "base_taxes_and_charges_deducted", "total_amount_to_pay",
+			"outstanding_amount", "total_advance", "paid_amount", "write_off_amount"], company_currency);
+
+		setup_field_label_map(["total", "net_total", "total_taxes_and_charges", "discount_amount",
+			"grand_total", "taxes_and_charges_added", "taxes_and_charges_deducted",
+			"rounded_total", "in_words"], this.frm.doc.currency);
+
+		cur_frm.set_df_property("conversion_rate", "description", "1 " + this.frm.doc.currency
+			+ " = [?] " + company_currency)
+
+		if(this.frm.doc.price_list_currency && this.frm.doc.price_list_currency!=company_currency) {
+			cur_frm.set_df_property("plc_conversion_rate", "description", "1 " + this.frm.doc.price_list_currency
+				+ " = [?] " + company_currency)
+		}
+
+		// toggle fields
+		this.frm.toggle_display(["conversion_rate", "base_total", "base_net_total", "base_total_taxes_and_charges",
+			"base_taxes_and_charges_added", "base_taxes_and_charges_deducted",
+			"base_grand_total", "base_rounded_total", "base_in_words", "base_discount_amount"],
+			this.frm.doc.currency != company_currency);
+
+		this.frm.toggle_display(["plc_conversion_rate", "price_list_currency"],
+			this.frm.doc.price_list_currency != company_currency);
+
+		// set labels
+		$.each(field_label_map, function(fname, label) {
+			me.frm.fields_dict[fname].set_label(label);
+		});
+
+	},
+
+	change_grid_labels: function(company_currency) {
+		var me = this;
+		var field_label_map = {};
+
+		var setup_field_label_map = function(fields_list, currency, parentfield) {
+			var grid_doctype = me.frm.fields_dict[parentfield].grid.doctype;
+			$.each(fields_list, function(i, fname) {
+				var docfield = frappe.meta.docfield_map[grid_doctype][fname];
+				if(docfield) {
+					var label = __(docfield.label || "").replace(/\([^\)]*\)/g, "");
+					field_label_map[grid_doctype + "-" + fname] =
+						label.trim() + " (" + currency + ")";
+				}
+			});
+		}
+
+		setup_field_label_map(["base_rate", "base_net_rate", "base_price_list_rate", "base_amount", "base_net_amount"],
+			company_currency, "items");
+
+		setup_field_label_map(["rate", "net_rate", "price_list_rate", "amount", "net_amount"],
+			this.frm.doc.currency, "items");
+
+		if(this.frm.fields_dict["taxes"]) {
+			setup_field_label_map(["tax_amount", "total", "tax_amount_after_discount"], this.frm.doc.currency, "taxes");
+
+			setup_field_label_map(["base_tax_amount", "base_total", "base_tax_amount_after_discount"], company_currency, "taxes");
+		}
+
+		if(this.frm.fields_dict["advances"]) {
+			setup_field_label_map(["advance_amount", "allocated_amount"], company_currency, "advances");
+		}
+
+		// toggle columns
+		var item_grid = this.frm.fields_dict["items"].grid;
+		$.each(["base_rate", "base_price_list_rate", "base_amount"], function(i, fname) {
+			if(frappe.meta.get_docfield(item_grid.doctype, fname))
+				item_grid.set_column_disp(fname, me.frm.doc.currency != company_currency);
+		});
+
+		var show = (cint(cur_frm.doc.discount_amount)) ||
+			((cur_frm.doc.taxes || []).filter(function(d) {return d.included_in_print_rate===1}).length);
+
+		$.each(["net_rate", "net_amount"], function(i, fname) {
+			if(frappe.meta.get_docfield(item_grid.doctype, fname))
+				item_grid.set_column_disp(fname, show);
+		});
+
+		$.each(["base_net_rate", "base_net_amount"], function(i, fname) {
+			if(frappe.meta.get_docfield(item_grid.doctype, fname))
+				item_grid.set_column_disp(fname, (show && (me.frm.doc.currency != company_currency)));
+		});
+
+		// set labels
+		var $wrapper = $(this.frm.wrapper);
+		$.each(field_label_map, function(fname, label) {
+			fname = fname.split("-");
+			var df = frappe.meta.get_docfield(fname[0], fname[1], me.frm.doc.name);
+			if(df) df.label = label;
+		});
+	},
+
 	recalculate: function() {
 		this.calculate_taxes_and_totals();
 	},
@@ -409,9 +499,7 @@
 	apply_price_list: function(item) {
 		var me = this;
 		var args = this._get_args(item);
-		if(!args.item_list.length) {
-			return;
-		}
+
 		return this.frm.call({
 			method: "erpnext.stock.get_item_details.apply_price_list",
 			args: {	args: args },
@@ -421,66 +509,15 @@
 					me.frm.set_value("price_list_currency", r.message.parent.price_list_currency);
 					me.frm.set_value("plc_conversion_rate", r.message.parent.plc_conversion_rate);
 					me.in_apply_price_list = false;
-					me._set_values_for_item_list(r.message.children);
+
+					if(args.item_list.length) {
+						me._set_values_for_item_list(r.message.children);
+					}
 				}
 			}
 		});
 	},
 
-	included_in_print_rate: function(doc, cdt, cdn) {
-		var tax = frappe.get_doc(cdt, cdn);
-		try {
-			this.validate_on_previous_row(tax);
-			this.validate_inclusive_tax(tax);
-			this.calculate_taxes_and_totals();
-		} catch(e) {
-			tax.included_in_print_rate = 0;
-			refresh_field("included_in_print_rate", tax.name, tax.parentfield);
-			throw e;
-		}
-	},
-
-	validate_on_previous_row: function(tax) {
-		// validate if a valid row id is mentioned in case of
-		// On Previous Row Amount and On Previous Row Total
-		if((["On Previous Row Amount", "On Previous Row Total"].indexOf(tax.charge_type) != -1) &&
-			(!tax.row_id || cint(tax.row_id) >= tax.idx)) {
-				var msg = __("Please specify a valid Row ID for row {0} in table {1}", [tax.idx, __(tax.doctype)])
-				frappe.throw(msg);
-			}
-	},
-
-	validate_inclusive_tax: function(tax) {
-		var actual_type_error = function() {
-			var msg = __("Actual type tax cannot be included in Item rate in row {0}", [tax.idx])
-			frappe.throw(msg);
-		};
-
-		var on_previous_row_error = function(row_range) {
-			var msg = __("For row {0} in {1}. To include {2} in Item rate, rows {3} must also be included",
-				[tax.idx, __(tax.doctype), tax.charge_type, row_range])
-			frappe.throw(msg);
-		};
-
-		if(cint(tax.included_in_print_rate)) {
-			if(tax.charge_type == "Actual") {
-				// inclusive tax cannot be of type Actual
-				actual_type_error();
-			} else if(tax.charge_type == "On Previous Row Amount" &&
-				!cint(this.frm.doc["taxes"][tax.row_id - 1].included_in_print_rate)) {
-					// referred row should also be an inclusive tax
-					on_previous_row_error(tax.row_id);
-			} else if(tax.charge_type == "On Previous Row Total") {
-				var taxes_not_included = $.map(this.frm.doc["taxes"].slice(0, tax.row_id),
-					function(t) { return cint(t.included_in_print_rate) ? null : t; });
-				if(taxes_not_included.length > 0) {
-					// all rows above this tax should be inclusive
-					on_previous_row_error(tax.row_id == 1 ? "1" : "1 - " + tax.row_id);
-				}
-			}
-		}
-	},
-
 	get_item_wise_taxes_html: function() {
 		var item_tax = {};
 		var tax_accounts = [];
@@ -560,24 +597,6 @@
 		return valid;
 	},
 
-	validate_conversion_rate: function() {
-		this.frm.doc.conversion_rate = flt(this.frm.doc.conversion_rate, precision("conversion_rate"));
-		var conversion_rate_label = frappe.meta.get_label(this.frm.doc.doctype, "conversion_rate",
-			this.frm.doc.name);
-		var company_currency = this.get_company_currency();
-
-		if(!this.frm.doc.conversion_rate) {
-			frappe.throw(repl('%(conversion_rate_label)s' +
-				__(' is mandatory. Maybe Currency Exchange record is not created for ') +
-				'%(from_currency)s' + __(" to ") + '%(to_currency)s',
-				{
-					"conversion_rate_label": conversion_rate_label,
-					"from_currency": this.frm.doc.currency,
-					"to_currency": company_currency
-				}));
-		}
-	},
-
 	get_terms: function() {
 		var me = this;
 		if(this.frm.doc.tc_name) {
@@ -656,3 +675,40 @@
 		}
 	}
 });
+
+frappe.ui.form.on(cur_frm.doctype + "Item", "rate", function(frm, cdt, cdn) {
+	var item = frappe.get_doc(cdt, cdn);
+	frappe.model.round_floats_in(item, ["rate", "price_list_rate"]);
+
+	if(item.price_list_rate) {
+		item.discount_percentage = flt((1 - item.rate / item.price_list_rate) * 100.0, precision("discount_percentage", item));
+	} else {
+		item.discount_percentage = 0.0;
+	}
+
+	cur_frm.cscript.calculate_taxes_and_totals();
+})
+
+frappe.ui.form.on(cur_frm.cscript.tax_table, "rate", function(frm, cdt, cdn) {
+	cur_frm.cscript.calculate_taxes_and_totals();
+})
+
+frappe.ui.form.on(cur_frm.cscript.tax_table, "tax_amount", function(frm, cdt, cdn) {
+	cur_frm.cscript.calculate_taxes_and_totals();
+})
+
+frappe.ui.form.on(cur_frm.cscript.tax_table, "row_id", function(frm, cdt, cdn) {
+	cur_frm.cscript.calculate_taxes_and_totals();
+})
+
+frappe.ui.form.on(cur_frm.cscript.tax_table, "included_in_print_rate", function(frm, cdt, cdn) {
+	cur_frm.cscript.calculate_taxes_and_totals();
+})
+
+frappe.ui.form.on(cur_frm.doctype, "apply_discount_on", function(frm) {
+	cur_frm.cscript.calculate_taxes_and_totals();
+})
+
+frappe.ui.form.on(cur_frm.doctype, "discount_amount", function(frm) {
+	cur_frm.cscript.calculate_taxes_and_totals();
+})
diff --git a/erpnext/public/js/feature_setup.js b/erpnext/public/js/feature_setup.js
index bb83170..259c2cf 100644
--- a/erpnext/public/js/feature_setup.js
+++ b/erpnext/public/js/feature_setup.js
@@ -111,34 +111,54 @@
 		'Sales Order': {'items':['page_break']}
 	},
 	'fs_exports': {
-		'Delivery Note': {'fields':['conversion_rate','currency','base_grand_total','base_in_words','base_rounded_total'],'items':['base_price_list_rate','base_amount','base_rate']},
+		'Delivery Note': {
+			'fields': ['conversion_rate','currency','base_grand_total','base_in_words','base_rounded_total',
+				'base_total', 'base_net_total', 'base_discount_amount', 'base_total_taxes_and_charges'],
+			'items': ['base_price_list_rate','base_amount','base_rate', 'base_net_rate', 'base_net_amount']
+		},
 		'POS Setting': {'fields':['conversion_rate','currency']},
-		'Quotation': {'fields':['conversion_rate','currency','base_grand_total','base_in_words','base_rounded_total'],'items':['base_price_list_rate','base_amount','base_rate']},
-		'Sales Invoice': {'fields':['conversion_rate','currency','base_grand_total','base_in_words','base_rounded_total'],'items':['base_price_list_rate','base_amount','base_rate']},
+		'Quotation': {
+			'fields': ['conversion_rate','currency','base_grand_total','base_in_words','base_rounded_total',
+				'base_total', 'base_net_total', 'base_discount_amount', 'base_total_taxes_and_charges'],
+			'items': ['base_price_list_rate','base_amount','base_rate', 'base_net_rate', 'base_net_amount']
+		},
+		'Sales Invoice': {
+			'fields': ['conversion_rate','currency','base_grand_total','base_in_words','base_rounded_total',
+				'base_total', 'base_net_total', 'base_discount_amount', 'base_total_taxes_and_charges'],
+			'items': ['base_price_list_rate','base_amount','base_rate', 'base_net_rate', 'base_net_amount']
+		},
 		'Sales BOM': {'fields':['currency']},
-		'Sales Order': {'fields':['conversion_rate','currency','base_grand_total','base_in_words','base_rounded_total'],'items':['base_price_list_rate','base_amount','base_rate']}
+		'Sales Order': {
+			'fields': ['conversion_rate','currency','base_grand_total','base_in_words','base_rounded_total',
+				'base_total', 'base_net_total', 'base_discount_amount', 'base_total_taxes_and_charges'],
+			'items': ['base_price_list_rate','base_amount','base_rate', 'base_net_rate', 'base_net_amount']
+		}
 	},
 
 	'fs_imports': {
 		'Purchase Invoice': {
-			'fields': ['conversion_rate', 'currency', 'base_grand_total',
-		 		'base_in_words', 'base_net_total', 'base_taxes_and_charges_added',
-		 		'base_taxes_and_charges_deducted'],
-			'items': ['base_price_list_rate', 'base_amount','base_rate']
+			'fields': ['conversion_rate', 'currency', 'base_grand_total', 'base_discount_amount',
+		 		'base_in_words', 'base_total', 'base_net_total', 'base_taxes_and_charges_added',
+		 		'base_taxes_and_charges_deducted', 'base_total_taxes_and_charges'],
+			'items': ['base_price_list_rate', 'base_amount','base_rate', 'base_net_rate', 'base_net_amount']
 		},
 		'Purchase Order': {
-			'fields': ['conversion_rate','currency', 'base_grand_total',
-			'base_in_words', 'base_net_total', 'base_taxes_and_charges_added',
-			 'base_taxes_and_charges_deducted'],
-			'items': ['base_price_list_rate', 'base_amount','base_rate']
+			'fields': ['conversion_rate','currency', 'base_grand_total', 'base_discount_amount',
+				'base_in_words', 'base_total', 'base_net_total', 'base_taxes_and_charges_added',
+			 	'base_taxes_and_charges_deducted', 'base_total_taxes_and_charges'],
+			'items': ['base_price_list_rate', 'base_amount','base_rate', 'base_net_rate', 'base_net_amount']
 		},
 		'Purchase Receipt': {
-			'fields': ['conversion_rate', 'currency','base_grand_total', 'base_in_words',
-			 	'base_net_total', 'base_taxes_and_charges_added', 'base_taxes_and_charges_deducted'],
-			'items': ['base_price_list_rate','base_amount','base_rate']
+			'fields': ['conversion_rate', 'currency','base_grand_total', 'base_in_words', 'base_total',
+			 	'base_net_total', 'base_taxes_and_charges_added', 'base_taxes_and_charges_deducted',
+				'base_total_taxes_and_charges', 'base_discount_amount'],
+			'items': ['base_price_list_rate','base_amount','base_rate', 'base_net_rate', 'base_net_amount']
 		},
 		'Supplier Quotation': {
-			'fields':['conversion_rate','currency']
+			'fields': ['conversion_rate', 'currency','base_grand_total', 'base_in_words', 'base_total',
+			 	'base_net_total', 'base_taxes_and_charges_added', 'base_taxes_and_charges_deducted',
+				'base_total_taxes_and_charges', 'base_discount_amount'],
+			'items': ['base_price_list_rate','base_amount','base_rate', 'base_net_rate', 'base_net_amount']
 		}
 	},
 
diff --git a/erpnext/selling/doctype/quotation/quotation.js b/erpnext/selling/doctype/quotation/quotation.js
index 6657100..4767f51 100644
--- a/erpnext/selling/doctype/quotation/quotation.js
+++ b/erpnext/selling/doctype/quotation/quotation.js
@@ -3,7 +3,6 @@
 
 
 {% include 'selling/sales_common.js' %}
-{% include 'accounts/doctype/sales_taxes_and_charges_master/sales_taxes_and_charges_master.js' %}
 
 erpnext.selling.QuotationController = erpnext.selling.SellingController.extend({
 	onload: function(doc, dt, dn) {
@@ -25,7 +24,7 @@
 				cur_frm.add_custom_button(__('Set as Lost'),
 					cur_frm.cscript['Declare Order Lost'], "icon-exclamation", "btn-default");
 			}
-			
+
 		}
 
 		if (this.frm.doc.docstatus===0) {
@@ -159,4 +158,6 @@
 		cur_frm.email_doc(frappe.boot.notification_settings.quotation_message);
 }
 
-
+frappe.ui.form.on("Quotation Item", "items_on_form_rendered", function(frm, cdt, cdn) {
+	// enable tax_amount field if Actual
+})
diff --git a/erpnext/selling/doctype/quotation/quotation.json b/erpnext/selling/doctype/quotation/quotation.json
index 14bce04..675e6b0 100644
--- a/erpnext/selling/doctype/quotation/quotation.json
+++ b/erpnext/selling/doctype/quotation/quotation.json
@@ -313,8 +313,19 @@
    "read_only": 0
   }, 
   {
+   "fieldname": "base_total", 
+   "fieldtype": "Currency", 
+   "label": "Total (Company Currency)", 
+   "options": "Company:company:default_currency", 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 1, 
+   "read_only": 1
+  }, 
+  {
    "fieldname": "base_net_total", 
    "fieldtype": "Currency", 
+   "hidden": 0, 
    "label": "Net Total (Company Currency)", 
    "no_copy": 0, 
    "oldfieldname": "net_total", 
@@ -332,11 +343,22 @@
    "permlevel": 0
   }, 
   {
+   "fieldname": "total", 
+   "fieldtype": "Currency", 
+   "label": "Total", 
+   "options": "currency", 
+   "permlevel": 0, 
+   "precision": "", 
+   "read_only": 1
+  }, 
+  {
    "fieldname": "net_total", 
    "fieldtype": "Currency", 
+   "hidden": 0, 
    "label": "Net Total", 
    "options": "currency", 
    "permlevel": 0, 
+   "print_hide": 1, 
    "read_only": 1
   }, 
   {
@@ -389,6 +411,7 @@
    "oldfieldtype": "Table", 
    "options": "Sales Taxes and Charges", 
    "permlevel": 0, 
+   "print_hide": 0, 
    "read_only": 0
   }, 
   {
@@ -431,11 +454,22 @@
    "permlevel": 0
   }, 
   {
+   "default": "Grand Total", 
+   "fieldname": "apply_discount_on", 
+   "fieldtype": "Select", 
+   "label": "Apply Discount On", 
+   "options": "\nGrand Total\nNet Total", 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 1
+  }, 
+  {
    "fieldname": "discount_amount", 
    "fieldtype": "Currency", 
    "label": "Discount Amount", 
    "options": "currency", 
-   "permlevel": 0
+   "permlevel": 0, 
+   "print_hide": 1
   }, 
   {
    "fieldname": "base_discount_amount", 
@@ -810,7 +844,7 @@
  "idx": 1, 
  "is_submittable": 1, 
  "max_attachments": 1, 
- "modified": "2015-02-20 05:16:20.664025", 
+ "modified": "2015-02-23 01:18:17.421144", 
  "modified_by": "Administrator", 
  "module": "Selling", 
  "name": "Quotation", 
diff --git a/erpnext/selling/doctype/quotation_item/quotation_item.json b/erpnext/selling/doctype/quotation_item/quotation_item.json
index 23b0b18..da7996a 100644
--- a/erpnext/selling/doctype/quotation_item/quotation_item.json
+++ b/erpnext/selling/doctype/quotation_item/quotation_item.json
@@ -1,5 +1,5 @@
 {
- "autoname": "hash", 
+ "autoname": "QUOD/.#####", 
  "creation": "2013-03-07 11:42:57", 
  "docstatus": 0, 
  "doctype": "DocType", 
@@ -188,6 +188,16 @@
    "width": "100px"
   }, 
   {
+   "fieldname": "net_rate", 
+   "fieldtype": "Currency", 
+   "hidden": 0, 
+   "label": "Net Rate", 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 1, 
+   "read_only": 1
+  }, 
+  {
    "fieldname": "amount", 
    "fieldtype": "Currency", 
    "in_filter": 0, 
@@ -205,6 +215,16 @@
    "width": "100px"
   }, 
   {
+   "fieldname": "net_amount", 
+   "fieldtype": "Currency", 
+   "label": "Net Amount", 
+   "options": "currency", 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 1, 
+   "read_only": 1
+  }, 
+  {
    "fieldname": "col_break3", 
    "fieldtype": "Column Break", 
    "permlevel": 0
@@ -213,7 +233,7 @@
    "fieldname": "base_rate", 
    "fieldtype": "Currency", 
    "in_filter": 0, 
-   "label": "Basic Rate (Company Currency)", 
+   "label": "Rate (Company Currency)", 
    "oldfieldname": "basic_rate", 
    "oldfieldtype": "Currency", 
    "options": "Company:company:default_currency", 
@@ -226,6 +246,15 @@
    "width": "100px"
   }, 
   {
+   "fieldname": "base_net_rate", 
+   "fieldtype": "Currency", 
+   "label": "Net Rate (Company Currency)", 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 1, 
+   "read_only": 1
+  }, 
+  {
    "fieldname": "base_amount", 
    "fieldtype": "Currency", 
    "in_filter": 0, 
@@ -242,6 +271,16 @@
    "width": "100px"
   }, 
   {
+   "fieldname": "base_net_amount", 
+   "fieldtype": "Currency", 
+   "label": "Net Amount (Company Currency)", 
+   "options": "Company:company:default_currency", 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 1, 
+   "read_only": 1
+  }, 
+  {
    "fieldname": "pricing_rule", 
    "fieldtype": "Link", 
    "label": "Pricing Rule", 
@@ -349,7 +388,7 @@
  ], 
  "idx": 1, 
  "istable": 1, 
- "modified": "2015-02-19 01:07:01.742936", 
+ "modified": "2015-02-23 00:48:08.477241", 
  "modified_by": "Administrator", 
  "module": "Selling", 
  "name": "Quotation Item", 
diff --git a/erpnext/selling/doctype/sales_order/sales_order.js b/erpnext/selling/doctype/sales_order/sales_order.js
index 15b0e39..bc9d0d1 100644
--- a/erpnext/selling/doctype/sales_order/sales_order.js
+++ b/erpnext/selling/doctype/sales_order/sales_order.js
@@ -2,7 +2,6 @@
 // License: GNU General Public License v3. See license.txt
 
 {% include 'selling/sales_common.js' %}
-{% include 'accounts/doctype/sales_taxes_and_charges_master/sales_taxes_and_charges_master.js' %}
 
 erpnext.selling.SalesOrderController = erpnext.selling.SellingController.extend({
 	refresh: function(doc, dt, dn) {
diff --git a/erpnext/selling/doctype/sales_order/sales_order.json b/erpnext/selling/doctype/sales_order/sales_order.json
index 07649a2..db7cc80 100644
--- a/erpnext/selling/doctype/sales_order/sales_order.json
+++ b/erpnext/selling/doctype/sales_order/sales_order.json
@@ -326,6 +326,16 @@
    "permlevel": 0
   }, 
   {
+   "fieldname": "base_total", 
+   "fieldtype": "Currency", 
+   "label": "Total (Company Currency)", 
+   "options": "Company:company:default_currency", 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 1, 
+   "read_only": 1
+  }, 
+  {
    "fieldname": "base_net_total", 
    "fieldtype": "Currency", 
    "label": "Net Total (Company Currency)", 
@@ -344,6 +354,16 @@
    "permlevel": 0
   }, 
   {
+   "fieldname": "total", 
+   "fieldtype": "Currency", 
+   "label": "Total", 
+   "options": "currency", 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 1, 
+   "read_only": 1
+  }, 
+  {
    "fieldname": "net_total", 
    "fieldtype": "Currency", 
    "label": "Net Total", 
@@ -421,6 +441,12 @@
    "read_only": 1
   }, 
   {
+   "fieldname": "column_break_46", 
+   "fieldtype": "Column Break", 
+   "permlevel": 0, 
+   "precision": ""
+  }, 
+  {
    "fieldname": "base_total_taxes_and_charges", 
    "fieldtype": "Currency", 
    "label": "Total Taxes and Charges (Company Currency)", 
@@ -433,7 +459,23 @@
    "width": "150px"
   }, 
   {
-   "fieldname": "column_break_46", 
+   "fieldname": "section_break_48", 
+   "fieldtype": "Section Break", 
+   "permlevel": 0, 
+   "precision": ""
+  }, 
+  {
+   "default": "Grand Total", 
+   "fieldname": "apply_discount_on", 
+   "fieldtype": "Select", 
+   "label": "Apply Discount On", 
+   "options": "\nGrand Total\nNet Total", 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 1
+  }, 
+  {
+   "fieldname": "column_break_50", 
    "fieldtype": "Column Break", 
    "permlevel": 0
   }, 
@@ -1034,7 +1076,7 @@
  "idx": 1, 
  "is_submittable": 1, 
  "issingle": 0, 
- "modified": "2015-02-20 05:16:18.207123", 
+ "modified": "2015-02-23 15:40:17.414233", 
  "modified_by": "Administrator", 
  "module": "Selling", 
  "name": "Sales Order", 
diff --git a/erpnext/selling/doctype/sales_order_item/sales_order_item.json b/erpnext/selling/doctype/sales_order_item/sales_order_item.json
index 131ec4d..6ef423b 100644
--- a/erpnext/selling/doctype/sales_order_item/sales_order_item.json
+++ b/erpnext/selling/doctype/sales_order_item/sales_order_item.json
@@ -1,455 +1,507 @@
 {
- "autoname": "hash",
- "creation": "2013-03-07 11:42:58",
- "docstatus": 0,
- "doctype": "DocType",
+ "autoname": "hash", 
+ "creation": "2013-03-07 11:42:58", 
+ "docstatus": 0, 
+ "doctype": "DocType", 
  "fields": [
   {
-   "fieldname": "item_code",
-   "fieldtype": "Link",
-   "in_filter": 1,
-   "in_list_view": 1,
-   "label": "Item Code",
-   "oldfieldname": "item_code",
-   "oldfieldtype": "Link",
-   "options": "Item",
-   "permlevel": 0,
-   "print_width": "150px",
-   "read_only": 0,
-   "reqd": 1,
-   "search_index": 1,
+   "fieldname": "item_code", 
+   "fieldtype": "Link", 
+   "in_filter": 1, 
+   "in_list_view": 1, 
+   "label": "Item Code", 
+   "oldfieldname": "item_code", 
+   "oldfieldtype": "Link", 
+   "options": "Item", 
+   "permlevel": 0, 
+   "print_width": "150px", 
+   "read_only": 0, 
+   "reqd": 1, 
+   "search_index": 1, 
    "width": "150px"
-  },
+  }, 
   {
-   "fieldname": "customer_item_code",
-   "fieldtype": "Data",
-   "hidden": 1,
-   "label": "Customer's Item Code",
-   "permlevel": 0,
-   "print_hide": 1,
+   "fieldname": "customer_item_code", 
+   "fieldtype": "Data", 
+   "hidden": 1, 
+   "label": "Customer's Item Code", 
+   "permlevel": 0, 
+   "print_hide": 1, 
    "read_only": 1
-  },
+  }, 
   {
-   "fieldname": "col_break1",
-   "fieldtype": "Column Break",
+   "fieldname": "col_break1", 
+   "fieldtype": "Column Break", 
    "permlevel": 0
-  },
+  }, 
   {
-   "fieldname": "item_name",
-   "fieldtype": "Data",
-   "in_list_view": 1,
-   "label": "Item Name",
-   "oldfieldname": "item_name",
-   "oldfieldtype": "Data",
-   "permlevel": 0,
-   "print_hide": 1,
-   "print_width": "150",
-   "read_only": 0,
-   "reqd": 1,
+   "fieldname": "item_name", 
+   "fieldtype": "Data", 
+   "in_list_view": 1, 
+   "label": "Item Name", 
+   "oldfieldname": "item_name", 
+   "oldfieldtype": "Data", 
+   "permlevel": 0, 
+   "print_hide": 1, 
+   "print_width": "150", 
+   "read_only": 0, 
+   "reqd": 1, 
    "width": "150"
-  },
+  }, 
   {
-   "fieldname": "section_break_5",
-   "fieldtype": "Section Break",
-   "permlevel": 0,
+   "fieldname": "section_break_5", 
+   "fieldtype": "Section Break", 
+   "permlevel": 0, 
    "precision": ""
-  },
+  }, 
   {
-   "fieldname": "description",
-   "fieldtype": "Small Text",
-   "in_filter": 1,
-   "in_list_view": 1,
-   "label": "Description",
-   "oldfieldname": "description",
-   "oldfieldtype": "Small Text",
-   "permlevel": 0,
-   "print_width": "300px",
-   "read_only": 0,
-   "reqd": 1,
-   "search_index": 1,
+   "fieldname": "description", 
+   "fieldtype": "Small Text", 
+   "in_filter": 1, 
+   "in_list_view": 1, 
+   "label": "Description", 
+   "oldfieldname": "description", 
+   "oldfieldtype": "Small Text", 
+   "permlevel": 0, 
+   "print_width": "300px", 
+   "read_only": 0, 
+   "reqd": 1, 
+   "search_index": 1, 
    "width": "300px"
-  },
+  }, 
   {
-   "fieldname": "column_break_7",
-   "fieldtype": "Column Break",
-   "permlevel": 0,
+   "fieldname": "column_break_7", 
+   "fieldtype": "Column Break", 
+   "permlevel": 0, 
    "precision": ""
-  },
+  }, 
   {
-   "fieldname": "image",
-   "fieldtype": "Attach",
-   "hidden": 1,
-   "label": "Image",
-   "permlevel": 0,
-   "precision": "",
+   "fieldname": "image", 
+   "fieldtype": "Attach", 
+   "hidden": 1, 
+   "label": "Image", 
+   "permlevel": 0, 
+   "precision": "", 
    "print_hide": 1
-  },
+  }, 
   {
-   "fieldname": "image_view",
-   "fieldtype": "Image",
-   "label": "Image View",
-   "options": "image",
-   "permlevel": 0,
+   "fieldname": "image_view", 
+   "fieldtype": "Image", 
+   "label": "Image View", 
+   "options": "image", 
+   "permlevel": 0, 
    "precision": ""
-  },
+  }, 
   {
-   "fieldname": "quantity_and_rate",
-   "fieldtype": "Section Break",
-   "label": "Quantity and Rate",
+   "fieldname": "quantity_and_rate", 
+   "fieldtype": "Section Break", 
+   "label": "Quantity and Rate", 
    "permlevel": 0
-  },
+  }, 
   {
-   "fieldname": "qty",
-   "fieldtype": "Float",
-   "in_list_view": 1,
-   "label": "Quantity",
-   "oldfieldname": "qty",
-   "oldfieldtype": "Currency",
-   "permlevel": 0,
-   "print_width": "100px",
-   "read_only": 0,
-   "reqd": 1,
+   "fieldname": "qty", 
+   "fieldtype": "Float", 
+   "in_list_view": 1, 
+   "label": "Quantity", 
+   "oldfieldname": "qty", 
+   "oldfieldtype": "Currency", 
+   "permlevel": 0, 
+   "print_width": "100px", 
+   "read_only": 0, 
+   "reqd": 1, 
    "width": "100px"
-  },
+  }, 
   {
-   "fieldname": "price_list_rate",
-   "fieldtype": "Currency",
-   "label": "Price List Rate",
-   "oldfieldname": "ref_rate",
-   "oldfieldtype": "Currency",
-   "options": "currency",
-   "permlevel": 0,
-   "print_hide": 1,
-   "print_width": "70px",
-   "read_only": 1,
-   "reqd": 0,
+   "fieldname": "price_list_rate", 
+   "fieldtype": "Currency", 
+   "label": "Price List Rate", 
+   "oldfieldname": "ref_rate", 
+   "oldfieldtype": "Currency", 
+   "options": "currency", 
+   "permlevel": 0, 
+   "print_hide": 1, 
+   "print_width": "70px", 
+   "read_only": 1, 
+   "reqd": 0, 
    "width": "70px"
-  },
+  }, 
   {
-   "fieldname": "discount_percentage",
-   "fieldtype": "Percent",
-   "in_list_view": 1,
-   "label": "Discount(%)",
-   "oldfieldname": "adj_rate",
-   "oldfieldtype": "Float",
-   "permlevel": 0,
-   "print_hide": 1,
-   "print_width": "70px",
-   "read_only": 0,
+   "fieldname": "discount_percentage", 
+   "fieldtype": "Percent", 
+   "in_list_view": 1, 
+   "label": "Discount(%)", 
+   "oldfieldname": "adj_rate", 
+   "oldfieldtype": "Float", 
+   "permlevel": 0, 
+   "print_hide": 1, 
+   "print_width": "70px", 
+   "read_only": 0, 
    "width": "70px"
-  },
+  }, 
   {
-   "fieldname": "col_break2",
-   "fieldtype": "Column Break",
+   "fieldname": "col_break2", 
+   "fieldtype": "Column Break", 
    "permlevel": 0
-  },
+  }, 
   {
-   "fieldname": "stock_uom",
-   "fieldtype": "Link",
-   "hidden": 0,
-   "in_list_view": 1,
-   "label": "UOM",
-   "oldfieldname": "stock_uom",
-   "oldfieldtype": "Data",
-   "options": "UOM",
-   "permlevel": 0,
-   "print_width": "70px",
-   "read_only": 1,
-   "reqd": 0,
+   "fieldname": "stock_uom", 
+   "fieldtype": "Link", 
+   "hidden": 0, 
+   "in_list_view": 1, 
+   "label": "UOM", 
+   "oldfieldname": "stock_uom", 
+   "oldfieldtype": "Data", 
+   "options": "UOM", 
+   "permlevel": 0, 
+   "print_width": "70px", 
+   "read_only": 1, 
+   "reqd": 0, 
    "width": "70px"
-  },
+  }, 
   {
-   "fieldname": "base_price_list_rate",
-   "fieldtype": "Currency",
-   "label": "Price List Rate (Company Currency)",
-   "oldfieldname": "base_ref_rate",
-   "oldfieldtype": "Currency",
-   "options": "Company:company:default_currency",
-   "permlevel": 0,
-   "print_hide": 1,
-   "print_width": "100px",
-   "read_only": 1,
+   "fieldname": "base_price_list_rate", 
+   "fieldtype": "Currency", 
+   "label": "Price List Rate (Company Currency)", 
+   "oldfieldname": "base_ref_rate", 
+   "oldfieldtype": "Currency", 
+   "options": "Company:company:default_currency", 
+   "permlevel": 0, 
+   "print_hide": 1, 
+   "print_width": "100px", 
+   "read_only": 1, 
    "width": "100px"
-  },
+  }, 
   {
-   "fieldname": "section_break_simple1",
-   "fieldtype": "Section Break",
+   "fieldname": "section_break_simple1", 
+   "fieldtype": "Section Break", 
    "permlevel": 0
-  },
+  }, 
   {
-   "fieldname": "rate",
-   "fieldtype": "Currency",
-   "in_list_view": 1,
-   "label": "Rate",
-   "oldfieldname": "export_rate",
-   "oldfieldtype": "Currency",
-   "options": "currency",
-   "permlevel": 0,
-   "print_width": "100px",
-   "read_only": 0,
-   "reqd": 0,
+   "fieldname": "rate", 
+   "fieldtype": "Currency", 
+   "in_list_view": 1, 
+   "label": "Rate", 
+   "oldfieldname": "export_rate", 
+   "oldfieldtype": "Currency", 
+   "options": "currency", 
+   "permlevel": 0, 
+   "print_width": "100px", 
+   "read_only": 0, 
+   "reqd": 0, 
    "width": "100px"
-  },
+  }, 
   {
-   "fieldname": "amount",
-   "fieldtype": "Currency",
-   "in_list_view": 1,
-   "label": "Amount",
-   "no_copy": 0,
-   "oldfieldname": "export_amount",
-   "oldfieldtype": "Currency",
-   "options": "currency",
-   "permlevel": 0,
-   "print_width": "100px",
-   "read_only": 1,
-   "reqd": 0,
+   "fieldname": "amount", 
+   "fieldtype": "Currency", 
+   "in_list_view": 1, 
+   "label": "Amount", 
+   "no_copy": 0, 
+   "oldfieldname": "export_amount", 
+   "oldfieldtype": "Currency", 
+   "options": "currency", 
+   "permlevel": 0, 
+   "print_width": "100px", 
+   "read_only": 1, 
+   "reqd": 0, 
    "width": "100px"
-  },
+  }, 
   {
-   "fieldname": "col_break3",
-   "fieldtype": "Column Break",
+   "fieldname": "col_break3", 
+   "fieldtype": "Column Break", 
    "permlevel": 0
-  },
+  }, 
   {
-   "fieldname": "base_rate",
-   "fieldtype": "Currency",
-   "label": "Basic Rate (Company Currency)",
-   "oldfieldname": "basic_rate",
-   "oldfieldtype": "Currency",
-   "options": "Company:company:default_currency",
-   "permlevel": 0,
-   "print_hide": 1,
-   "print_width": "100px",
-   "read_only": 1,
-   "reqd": 0,
+   "fieldname": "base_rate", 
+   "fieldtype": "Currency", 
+   "label": "Basic Rate (Company Currency)", 
+   "oldfieldname": "basic_rate", 
+   "oldfieldtype": "Currency", 
+   "options": "Company:company:default_currency", 
+   "permlevel": 0, 
+   "print_hide": 1, 
+   "print_width": "100px", 
+   "read_only": 1, 
+   "reqd": 0, 
    "width": "100px"
-  },
+  }, 
   {
-   "fieldname": "base_amount",
-   "fieldtype": "Currency",
-   "label": "Amount (Company Currency)",
-   "no_copy": 0,
-   "oldfieldname": "amount",
-   "oldfieldtype": "Currency",
-   "options": "Company:company:default_currency",
-   "permlevel": 0,
-   "print_hide": 1,
-   "print_width": "100px",
-   "read_only": 1,
-   "reqd": 0,
+   "fieldname": "base_amount", 
+   "fieldtype": "Currency", 
+   "label": "Amount (Company Currency)", 
+   "no_copy": 0, 
+   "oldfieldname": "amount", 
+   "oldfieldtype": "Currency", 
+   "options": "Company:company:default_currency", 
+   "permlevel": 0, 
+   "print_hide": 1, 
+   "print_width": "100px", 
+   "read_only": 1, 
+   "reqd": 0, 
    "width": "100px"
-  },
+  }, 
   {
-   "fieldname": "pricing_rule",
-   "fieldtype": "Link",
-   "label": "Pricing Rule",
-   "options": "Pricing Rule",
-   "permlevel": 0,
+   "fieldname": "pricing_rule", 
+   "fieldtype": "Link", 
+   "label": "Pricing Rule", 
+   "options": "Pricing Rule", 
+   "permlevel": 0, 
    "read_only": 1
-  },
+  }, 
   {
-   "fieldname": "warehouse_and_reference",
-   "fieldtype": "Section Break",
-   "label": "Warehouse and Reference",
+   "fieldname": "section_break_24", 
+   "fieldtype": "Section Break", 
+   "permlevel": 0, 
+   "precision": ""
+  }, 
+  {
+   "fieldname": "net_rate", 
+   "fieldtype": "Currency", 
+   "label": "Net Rate", 
+   "options": "currency", 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 1, 
+   "read_only": 1
+  }, 
+  {
+   "fieldname": "net_amount", 
+   "fieldtype": "Currency", 
+   "label": "Net Amount", 
+   "options": "currency", 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 1, 
+   "read_only": 1
+  }, 
+  {
+   "fieldname": "column_break_27", 
+   "fieldtype": "Column Break", 
+   "permlevel": 0, 
+   "precision": ""
+  }, 
+  {
+   "fieldname": "base_net_rate", 
+   "fieldtype": "Currency", 
+   "label": "Net Rate (Company Currency)", 
+   "options": "Company:company:default_currency", 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 1, 
+   "read_only": 1
+  }, 
+  {
+   "fieldname": "base_net_amount", 
+   "fieldtype": "Currency", 
+   "label": "Net Amount (Company Currency)", 
+   "options": "Company:company:default_currency", 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 1, 
+   "read_only": 1
+  }, 
+  {
+   "fieldname": "warehouse_and_reference", 
+   "fieldtype": "Section Break", 
+   "label": "Warehouse and Reference", 
    "permlevel": 0
-  },
+  }, 
   {
-   "fieldname": "warehouse",
-   "fieldtype": "Link",
-   "in_list_view": 1,
-   "label": "Reserved Warehouse",
-   "no_copy": 0,
-   "oldfieldname": "reserved_warehouse",
-   "oldfieldtype": "Link",
-   "options": "Warehouse",
-   "permlevel": 0,
-   "print_hide": 1,
-   "print_width": "150px",
-   "read_only": 0,
-   "reqd": 0,
+   "fieldname": "warehouse", 
+   "fieldtype": "Link", 
+   "in_list_view": 1, 
+   "label": "Reserved Warehouse", 
+   "no_copy": 0, 
+   "oldfieldname": "reserved_warehouse", 
+   "oldfieldtype": "Link", 
+   "options": "Warehouse", 
+   "permlevel": 0, 
+   "print_hide": 1, 
+   "print_width": "150px", 
+   "read_only": 0, 
+   "reqd": 0, 
    "width": "150px"
-  },
+  }, 
   {
-   "fieldname": "prevdoc_docname",
-   "fieldtype": "Link",
-   "hidden": 0,
-   "in_filter": 1,
-   "label": "Quotation",
-   "no_copy": 1,
-   "oldfieldname": "prevdoc_docname",
-   "oldfieldtype": "Link",
-   "options": "Quotation",
-   "permlevel": 0,
-   "print_hide": 1,
-   "read_only": 1,
+   "fieldname": "prevdoc_docname", 
+   "fieldtype": "Link", 
+   "hidden": 0, 
+   "in_filter": 1, 
+   "label": "Quotation", 
+   "no_copy": 1, 
+   "oldfieldname": "prevdoc_docname", 
+   "oldfieldtype": "Link", 
+   "options": "Quotation", 
+   "permlevel": 0, 
+   "print_hide": 1, 
+   "read_only": 1, 
    "search_index": 1
-  },
+  }, 
   {
-   "fieldname": "brand",
-   "fieldtype": "Link",
-   "hidden": 1,
-   "in_filter": 1,
-   "label": "Brand Name",
-   "oldfieldname": "brand",
-   "oldfieldtype": "Link",
-   "options": "Brand",
-   "permlevel": 0,
-   "print_hide": 1,
-   "read_only": 1,
+   "fieldname": "brand", 
+   "fieldtype": "Link", 
+   "hidden": 1, 
+   "in_filter": 1, 
+   "label": "Brand Name", 
+   "oldfieldname": "brand", 
+   "oldfieldtype": "Link", 
+   "options": "Brand", 
+   "permlevel": 0, 
+   "print_hide": 1, 
+   "read_only": 1, 
    "search_index": 1
-  },
+  }, 
   {
-   "description": "",
-   "fieldname": "item_group",
-   "fieldtype": "Link",
-   "hidden": 1,
-   "in_filter": 1,
-   "label": "Item Group",
-   "oldfieldname": "item_group",
-   "oldfieldtype": "Link",
-   "options": "Item Group",
-   "permlevel": 0,
-   "print_hide": 1,
-   "read_only": 1,
+   "description": "", 
+   "fieldname": "item_group", 
+   "fieldtype": "Link", 
+   "hidden": 1, 
+   "in_filter": 1, 
+   "label": "Item Group", 
+   "oldfieldname": "item_group", 
+   "oldfieldtype": "Link", 
+   "options": "Item Group", 
+   "permlevel": 0, 
+   "print_hide": 1, 
+   "read_only": 1, 
    "search_index": 1
-  },
+  }, 
   {
-   "allow_on_submit": 1,
-   "fieldname": "page_break",
-   "fieldtype": "Check",
-   "label": "Page Break",
-   "oldfieldname": "page_break",
-   "oldfieldtype": "Check",
-   "permlevel": 0,
-   "print_hide": 1,
-   "read_only": 0,
+   "allow_on_submit": 1, 
+   "fieldname": "page_break", 
+   "fieldtype": "Check", 
+   "label": "Page Break", 
+   "oldfieldname": "page_break", 
+   "oldfieldtype": "Check", 
+   "permlevel": 0, 
+   "print_hide": 1, 
+   "read_only": 0, 
    "report_hide": 1
-  },
+  }, 
   {
-   "fieldname": "col_break4",
-   "fieldtype": "Column Break",
+   "fieldname": "col_break4", 
+   "fieldtype": "Column Break", 
    "permlevel": 0
-  },
+  }, 
   {
-   "allow_on_submit": 1,
-   "fieldname": "projected_qty",
-   "fieldtype": "Float",
-   "hidden": 0,
-   "label": "Projected Qty",
-   "no_copy": 1,
-   "oldfieldname": "projected_qty",
-   "oldfieldtype": "Currency",
-   "permlevel": 0,
-   "print_hide": 1,
-   "print_width": "70px",
-   "read_only": 1,
+   "allow_on_submit": 1, 
+   "fieldname": "projected_qty", 
+   "fieldtype": "Float", 
+   "hidden": 0, 
+   "label": "Projected Qty", 
+   "no_copy": 1, 
+   "oldfieldname": "projected_qty", 
+   "oldfieldtype": "Currency", 
+   "permlevel": 0, 
+   "print_hide": 1, 
+   "print_width": "70px", 
+   "read_only": 1, 
    "width": "70px"
-  },
+  }, 
   {
-   "allow_on_submit": 1,
-   "fieldname": "actual_qty",
-   "fieldtype": "Float",
-   "label": "Actual Qty",
-   "no_copy": 1,
-   "permlevel": 0,
-   "print_hide": 1,
-   "print_width": "70px",
-   "read_only": 1,
+   "allow_on_submit": 1, 
+   "fieldname": "actual_qty", 
+   "fieldtype": "Float", 
+   "label": "Actual Qty", 
+   "no_copy": 1, 
+   "permlevel": 0, 
+   "print_hide": 1, 
+   "print_width": "70px", 
+   "read_only": 1, 
    "width": "70px"
-  },
+  }, 
   {
-   "fieldname": "delivered_qty",
-   "fieldtype": "Float",
-   "hidden": 0,
-   "in_filter": 0,
-   "label": "Delivered Qty",
-   "no_copy": 1,
-   "oldfieldname": "delivered_qty",
-   "oldfieldtype": "Currency",
-   "permlevel": 0,
-   "print_hide": 1,
-   "print_width": "100px",
-   "read_only": 1,
-   "search_index": 0,
+   "fieldname": "delivered_qty", 
+   "fieldtype": "Float", 
+   "hidden": 0, 
+   "in_filter": 0, 
+   "label": "Delivered Qty", 
+   "no_copy": 1, 
+   "oldfieldname": "delivered_qty", 
+   "oldfieldtype": "Currency", 
+   "permlevel": 0, 
+   "print_hide": 1, 
+   "print_width": "100px", 
+   "read_only": 1, 
+   "search_index": 0, 
    "width": "100px"
-  },
+  }, 
   {
-   "fieldname": "billed_amt",
-   "fieldtype": "Currency",
-   "label": "Billed Amt",
-   "no_copy": 1,
-   "options": "currency",
-   "permlevel": 0,
-   "print_hide": 1,
+   "fieldname": "billed_amt", 
+   "fieldtype": "Currency", 
+   "label": "Billed Amt", 
+   "no_copy": 1, 
+   "options": "currency", 
+   "permlevel": 0, 
+   "print_hide": 1, 
    "read_only": 1
-  },
+  }, 
   {
-   "description": "For Production",
-   "fieldname": "planned_qty",
-   "fieldtype": "Float",
-   "hidden": 1,
-   "label": "Planned Quantity",
-   "no_copy": 1,
-   "oldfieldname": "planned_qty",
-   "oldfieldtype": "Currency",
-   "permlevel": 0,
-   "print_hide": 1,
-   "print_width": "50px",
-   "read_only": 1,
-   "report_hide": 1,
+   "description": "For Production", 
+   "fieldname": "planned_qty", 
+   "fieldtype": "Float", 
+   "hidden": 1, 
+   "label": "Planned Quantity", 
+   "no_copy": 1, 
+   "oldfieldname": "planned_qty", 
+   "oldfieldtype": "Currency", 
+   "permlevel": 0, 
+   "print_hide": 1, 
+   "print_width": "50px", 
+   "read_only": 1, 
+   "report_hide": 1, 
    "width": "50px"
-  },
+  }, 
   {
-   "description": "For Production",
-   "fieldname": "produced_qty",
-   "fieldtype": "Float",
-   "hidden": 1,
-   "label": "Produced Quantity",
-   "oldfieldname": "produced_qty",
-   "oldfieldtype": "Currency",
-   "permlevel": 0,
-   "print_hide": 1,
-   "print_width": "50px",
-   "read_only": 1,
-   "report_hide": 1,
+   "description": "For Production", 
+   "fieldname": "produced_qty", 
+   "fieldtype": "Float", 
+   "hidden": 1, 
+   "label": "Produced Quantity", 
+   "oldfieldname": "produced_qty", 
+   "oldfieldtype": "Currency", 
+   "permlevel": 0, 
+   "print_hide": 1, 
+   "print_width": "50px", 
+   "read_only": 1, 
+   "report_hide": 1, 
    "width": "50px"
-  },
+  }, 
   {
-   "fieldname": "item_tax_rate",
-   "fieldtype": "Small Text",
-   "hidden": 1,
-   "label": "Item Tax Rate",
-   "oldfieldname": "item_tax_rate",
-   "oldfieldtype": "Small Text",
-   "permlevel": 0,
-   "print_hide": 1,
-   "read_only": 1,
+   "fieldname": "item_tax_rate", 
+   "fieldtype": "Small Text", 
+   "hidden": 1, 
+   "label": "Item Tax Rate", 
+   "oldfieldname": "item_tax_rate", 
+   "oldfieldtype": "Small Text", 
+   "permlevel": 0, 
+   "print_hide": 1, 
+   "read_only": 1, 
    "report_hide": 1
-  },
+  }, 
   {
-   "description": "Used for Production Plan",
-   "fieldname": "transaction_date",
-   "fieldtype": "Date",
-   "hidden": 1,
-   "in_filter": 0,
-   "label": "Sales Order Date",
-   "oldfieldname": "transaction_date",
-   "oldfieldtype": "Date",
-   "permlevel": 0,
-   "print_hide": 1,
-   "read_only": 1,
-   "report_hide": 1,
+   "description": "Used for Production Plan", 
+   "fieldname": "transaction_date", 
+   "fieldtype": "Date", 
+   "hidden": 1, 
+   "in_filter": 0, 
+   "label": "Sales Order Date", 
+   "oldfieldname": "transaction_date", 
+   "oldfieldtype": "Date", 
+   "permlevel": 0, 
+   "print_hide": 1, 
+   "read_only": 1, 
+   "report_hide": 1, 
    "search_index": 0
   }
- ],
- "idx": 1,
- "istable": 1,
- "modified": "2015-02-19 01:07:02.025024",
- "modified_by": "Administrator",
- "module": "Selling",
- "name": "Sales Order Item",
- "owner": "Administrator",
- "permissions": [],
- "sort_field": "modified",
+ ], 
+ "idx": 1, 
+ "istable": 1, 
+ "modified": "2015-02-23 15:43:08.156543", 
+ "modified_by": "Administrator", 
+ "module": "Selling", 
+ "name": "Sales Order Item", 
+ "owner": "Administrator", 
+ "permissions": [], 
+ "sort_field": "modified", 
  "sort_order": "DESC"
-}
+}
\ No newline at end of file
diff --git a/erpnext/selling/page/sales_analytics/sales_analytics.js b/erpnext/selling/page/sales_analytics/sales_analytics.js
index bbe69d7..197b6ac 100644
--- a/erpnext/selling/page/sales_analytics/sales_analytics.js
+++ b/erpnext/selling/page/sales_analytics/sales_analytics.js
@@ -204,7 +204,7 @@
 				if (posting_date >= from_date && posting_date <= to_date) {
 					var item = me.item_by_name[tl[me.tree_grid.item_key]] ||
 						me.item_by_name['Not Set'];
-					item[me.column_map[tl.posting_date].field] += (is_val ? tl.base_amount : tl.qty);
+					item[me.column_map[tl.posting_date].field] += (is_val ? tl.base_net_amount : tl.qty);
 				}
 			}
 		});
diff --git a/erpnext/selling/report/sales_person_target_variance_item_group_wise/sales_person_target_variance_item_group_wise.py b/erpnext/selling/report/sales_person_target_variance_item_group_wise/sales_person_target_variance_item_group_wise.py
index 7471317..93dd74c 100644
--- a/erpnext/selling/report/sales_person_target_variance_item_group_wise/sales_person_target_variance_item_group_wise.py
+++ b/erpnext/selling/report/sales_person_target_variance_item_group_wise/sales_person_target_variance_item_group_wise.py
@@ -82,7 +82,7 @@
 def get_achieved_details(filters):
 	start_date, end_date = get_fiscal_year(fiscal_year = filters["fiscal_year"])[1:]
 
-	item_details = frappe.db.sql("""select soi.item_code, soi.qty, soi.base_amount, so.transaction_date,
+	item_details = frappe.db.sql("""select soi.item_code, soi.qty, soi.base_net_amount, so.transaction_date,
 		st.sales_person, MONTHNAME(so.transaction_date) as month_name
 		from `tabSales Order Item` soi, `tabSales Order` so, `tabSales Team` st
 		where soi.parent=so.name and so.docstatus=1 and
@@ -125,7 +125,7 @@
 				if (filters["target_on"] == "Amount"):
 					tav_dict.target = flt(sd.target_amount) * month_percentage / 100
 					if ad.month_name == month:
-							tav_dict.achieved += ad.base_amount
+							tav_dict.achieved += ad.base_net_amount
 
 	return sim_map
 
diff --git a/erpnext/selling/report/sales_person_wise_transaction_summary/sales_person_wise_transaction_summary.py b/erpnext/selling/report/sales_person_wise_transaction_summary/sales_person_wise_transaction_summary.py
index c970431..8cac80c 100644
--- a/erpnext/selling/report/sales_person_wise_transaction_summary/sales_person_wise_transaction_summary.py
+++ b/erpnext/selling/report/sales_person_wise_transaction_summary/sales_person_wise_transaction_summary.py
@@ -16,7 +16,7 @@
 		data.append([
 			d.name, d.customer, d.territory, d.posting_date, d.item_code,
 			item_details.get(d.item_code, {}).get("item_group"), item_details.get(d.item_code, {}).get("brand"),
-			d.qty, d.base_amount, d.sales_person, d.allocated_percentage, d.contribution_amt
+			d.qty, d.base_net_amount, d.sales_person, d.allocated_percentage, d.contribution_amt
 		])
 
 	return columns, data
@@ -36,8 +36,8 @@
 	date_field = filters["doc_type"] == "Sales Order" and "transaction_date" or "posting_date"
 	conditions, items = get_conditions(filters, date_field)
 	entries = frappe.db.sql("""select dt.name, dt.customer, dt.territory, dt.%s as posting_date,
-		dt_item.item_code, dt_item.qty, dt_item.base_amount, st.sales_person,
-		st.allocated_percentage, dt_item.base_amount*st.allocated_percentage/100 as contribution_amt
+		dt_item.item_code, dt_item.qty, dt_item.base_net_amount, st.sales_person,
+		st.allocated_percentage, dt_item.base_net_amount*st.allocated_percentage/100 as contribution_amt
 		from `tab%s` dt, `tab%s Item` dt_item, `tabSales Team` st
 		where st.parent = dt.name and dt.name = dt_item.parent and st.parenttype = %s
 		and dt.docstatus = 1 %s order by st.sales_person, dt.name desc""" %
diff --git a/erpnext/selling/report/territory_target_variance_item_group_wise/territory_target_variance_item_group_wise.py b/erpnext/selling/report/territory_target_variance_item_group_wise/territory_target_variance_item_group_wise.py
index 6c3a2c3..4f19c73 100644
--- a/erpnext/selling/report/territory_target_variance_item_group_wise/territory_target_variance_item_group_wise.py
+++ b/erpnext/selling/report/territory_target_variance_item_group_wise/territory_target_variance_item_group_wise.py
@@ -5,7 +5,6 @@
 import frappe
 from frappe import _, msgprint
 from frappe.utils import flt
-import time
 from erpnext.accounts.utils import get_fiscal_year
 from erpnext.controllers.trends import get_period_date_ranges, get_period_month_ranges
 
@@ -81,7 +80,7 @@
 def get_achieved_details(filters):
 	start_date, end_date = get_fiscal_year(fiscal_year = filters["fiscal_year"])[1:]
 
-	item_details = frappe.db.sql("""select soi.item_code, soi.qty, soi.base_amount, so.transaction_date,
+	item_details = frappe.db.sql("""select soi.item_code, soi.qty, soi.base_net_amount, so.transaction_date,
 		so.territory, MONTHNAME(so.transaction_date) as month_name
 		from `tabSales Order Item` soi, `tabSales Order` so
 		where soi.parent=so.name and so.docstatus=1 and so.transaction_date>=%s and
@@ -125,7 +124,7 @@
 				if (filters["target_on"] == "Amount"):
 					tav_dict.target = flt(td.target_amount) * month_percentage / 100
 					if ad.month_name == month:
-							tav_dict.achieved += ad.base_amount
+							tav_dict.achieved += ad.base_net_amount
 
 	return tim_map
 
diff --git a/erpnext/selling/sales_common.js b/erpnext/selling/sales_common.js
index 3a01ca0..85f4f73 100644
--- a/erpnext/selling/sales_common.js
+++ b/erpnext/selling/sales_common.js
@@ -2,11 +2,12 @@
 // License: GNU General Public License v3. See license.txt
 
 
+cur_frm.cscript.tax_table = "Sales Taxes and Charges";
+{% include 'accounts/doctype/sales_taxes_and_charges_master/sales_taxes_and_charges_master.js' %}
+
 frappe.provide("erpnext.selling");
 frappe.require("assets/erpnext/js/controllers/transaction.js");
 
-{% include "public/js/controllers/accounts.js" %};
-
 cur_frm.email_field = "contact_email";
 
 erpnext.selling.SellingController = erpnext.TransactionController.extend({
@@ -16,10 +17,6 @@
 		this.toggle_editable_price_list_rate();
 	},
 
-	onload_post_render: function() {
-		cur_frm.get_field("items").grid.set_multiple_add("item_code", "qty");
-	},
-
 	setup_queries: function() {
 		var me = this;
 
@@ -154,24 +151,6 @@
 		}
 	},
 
-	rate: function(doc, cdt, cdn) {
-		var item = frappe.get_doc(cdt, cdn);
-		frappe.model.round_floats_in(item, ["rate", "price_list_rate"]);
-
-		if(item.price_list_rate) {
-			item.discount_percentage = flt((1 - item.rate / item.price_list_rate) * 100.0,
-				precision("discount_percentage", item));
-		} else {
-			item.discount_percentage = 0.0;
-		}
-
-		this.calculate_taxes_and_totals();
-	},
-
-	discount_amount: function() {
-		this.calculate_taxes_and_totals();
-	},
-
 	commission_rate: function() {
 		this.calculate_commission();
 		refresh_field("total_commission");
@@ -321,98 +300,6 @@
 			}
 		}
 		refresh_field('sales_bom_help');
-	},
-
-	change_form_labels: function(company_currency) {
-		var me = this;
-		var field_label_map = {};
-
-		var setup_field_label_map = function(fields_list, currency) {
-			$.each(fields_list, function(i, fname) {
-				var docfield = frappe.meta.docfield_map[me.frm.doc.doctype][fname];
-				if(docfield) {
-					var label = __(docfield.label || "").replace(/\([^\)]*\)/g, "");
-					field_label_map[fname] = label.trim() + " (" + currency + ")";
-				}
-			});
-		};
-		setup_field_label_map(["base_net_total", "base_total_taxes_and_charges", "base_discount_amount", "base_grand_total",
-			"base_rounded_total", "base_in_words",
-			"outstanding_amount", "total_advance", "paid_amount", "write_off_amount"],
-			company_currency);
-
-		setup_field_label_map(["net_total", "total_taxes_and_charges", "discount_amount", "grand_total",
-			"rounded_total", "in_words"], this.frm.doc.currency);
-
-		cur_frm.set_df_property("conversion_rate", "description", "1 " + this.frm.doc.currency
-			+ " = [?] " + company_currency)
-
-		if(this.frm.doc.price_list_currency && this.frm.doc.price_list_currency!=company_currency) {
-			cur_frm.set_df_property("plc_conversion_rate", "description", "1 " + this.frm.doc.price_list_currency
-				+ " = [?] " + company_currency)
-		}
-
-		// toggle fields
-		this.frm.toggle_display(["conversion_rate", "base_net_total", "base_total_taxes_and_charges",
-			"base_grand_total", "base_rounded_total", "base_in_words", "base_discount_amount"],
-			this.frm.doc.currency != company_currency);
-
-		this.frm.toggle_display(["plc_conversion_rate", "price_list_currency"],
-			this.frm.doc.price_list_currency != company_currency);
-
-		// set labels
-		$.each(field_label_map, function(fname, label) {
-			me.frm.fields_dict[fname].set_label(label);
-		});
-	},
-
-	change_grid_labels: function(company_currency) {
-		var me = this;
-		var field_label_map = {};
-
-		var setup_field_label_map = function(fields_list, currency, parentfield) {
-			var grid_doctype = me.frm.fields_dict[parentfield].grid.doctype;
-			$.each(fields_list, function(i, fname) {
-				var docfield = frappe.meta.docfield_map[grid_doctype][fname];
-				if(docfield) {
-					var label = __(docfield.label || "").replace(/\([^\)]*\)/g, "");
-					field_label_map[grid_doctype + "-" + fname] =
-						label.trim() + " (" + currency + ")";
-				}
-			});
-		}
-
-		setup_field_label_map(["base_rate", "base_price_list_rate", "base_amount"],
-			company_currency, "items");
-
-		setup_field_label_map(["rate", "price_list_rate", "amount"],
-			this.frm.doc.currency, "items");
-
-		setup_field_label_map(["tax_amount", "total"], company_currency, "taxes");
-
-		if(this.frm.fields_dict["advances"]) {
-			setup_field_label_map(["advance_amount", "allocated_amount"], company_currency,
-				"advances");
-		}
-
-		// toggle columns
-		var item_grid = this.frm.fields_dict["items"].grid;
-		var show = (this.frm.doc.currency != company_currency) ||
-			((cur_frm.doc.taxes || []).filter(
-					function(d) { return d.included_in_print_rate===1}).length);
-
-		$.each(["base_rate", "base_price_list_rate", "base_amount"], function(i, fname) {
-			if(frappe.meta.get_docfield(item_grid.doctype, fname))
-				item_grid.set_column_disp(fname, show);
-		});
-
-		// set labels
-		var $wrapper = $(this.frm.wrapper);
-		$.each(field_label_map, function(fname, label) {
-			fname = fname.split("-");
-			var df = frappe.meta.get_docfield(fname[0], fname[1], me.frm.doc.name);
-			if(df) df.label = label;
-		});
 	}
 });
 
diff --git a/erpnext/setup/doctype/company/test_company.py b/erpnext/setup/doctype/company/test_company.py
index 06db121..32d0b0e 100644
--- a/erpnext/setup/doctype/company/test_company.py
+++ b/erpnext/setup/doctype/company/test_company.py
@@ -8,11 +8,8 @@
 
 class TestCompany(unittest.TestCase):
 	def atest_coa(self):
-		for country, chart_name in frappe.db.sql("""select country, chart_name 
+		for country, chart_name in frappe.db.sql("""select country, chart_name
 			from `tabChart of Accounts` where name = 'Deutscher Kontenplan SKR03'""", as_list=1):
-				print "Country: ", country
-				print "Chart Name: ", chart_name
-				
 				company_doc = frappe.get_doc({
 					"doctype": "Company",
 					"company_name": "_Test Company 2",
@@ -23,10 +20,10 @@
 				})
 
 				company_doc.insert()
-				self.assertTrue(frappe.db.sql("""select count(*) from tabAccount 
+				self.assertTrue(frappe.db.sql("""select count(*) from tabAccount
 					where company='_Test Company 2'""")[0][0] > 10)
-				
-				frappe.delete_doc("Company", "_Test Company 2")
-		
 
-test_records = frappe.get_test_records('Company')
\ No newline at end of file
+				frappe.delete_doc("Company", "_Test Company 2")
+
+
+test_records = frappe.get_test_records('Company')
diff --git a/erpnext/shopping_cart/cart.py b/erpnext/shopping_cart/cart.py
index 7b83616..754eccb 100644
--- a/erpnext/shopping_cart/cart.py
+++ b/erpnext/shopping_cart/cart.py
@@ -141,7 +141,7 @@
 		d["formatted_amount"] = fmt_money(d.get("amount"), currency=doc.currency)
 
 	for d in doc.get("taxes", []):
-		d["formatted_tax_amount"] = fmt_money(flt(d.get("tax_amount")) / doc.conversion_rate,
+		d["formatted_tax_amount"] = fmt_money(flt(d.get("tax_amount_after_discount_amount")),
 			currency=doc.currency)
 
 	doc.formatted_grand_total_export = fmt_money(doc.grand_total,
diff --git a/erpnext/startup/report_data_map.py b/erpnext/startup/report_data_map.py
index b864cbc..4bd0afe 100644
--- a/erpnext/startup/report_data_map.py
+++ b/erpnext/startup/report_data_map.py
@@ -174,7 +174,7 @@
 		}
 	},
 	"Sales Invoice Item": {
-		"columns": ["name", "parent", "item_code", "qty", "base_amount"],
+		"columns": ["name", "parent", "item_code", "qty", "base_net_amount"],
 		"conditions": ["docstatus=1", "ifnull(parent, '')!=''"],
 		"order_by": "parent",
 		"links": {
@@ -192,7 +192,7 @@
 		}
 	},
 	"Sales Order Item[Sales Analytics]": {
-		"columns": ["name", "parent", "item_code", "qty", "base_amount"],
+		"columns": ["name", "parent", "item_code", "qty", "base_net_amount"],
 		"conditions": ["docstatus=1", "ifnull(parent, '')!=''"],
 		"order_by": "parent",
 		"links": {
@@ -210,7 +210,7 @@
 		}
 	},
 	"Delivery Note Item[Sales Analytics]": {
-		"columns": ["name", "parent", "item_code", "qty", "base_amount"],
+		"columns": ["name", "parent", "item_code", "qty", "base_net_amount"],
 		"conditions": ["docstatus=1", "ifnull(parent, '')!=''"],
 		"order_by": "parent",
 		"links": {
@@ -242,7 +242,7 @@
 		}
 	},
 	"Purchase Invoice Item": {
-		"columns": ["name", "parent", "item_code", "qty", "base_amount"],
+		"columns": ["name", "parent", "item_code", "qty", "base_net_amount"],
 		"conditions": ["docstatus=1", "ifnull(parent, '')!=''"],
 		"order_by": "parent",
 		"links": {
@@ -260,7 +260,7 @@
 		}
 	},
 	"Purchase Order Item[Purchase Analytics]": {
-		"columns": ["name", "parent", "item_code", "qty", "base_amount"],
+		"columns": ["name", "parent", "item_code", "qty", "base_net_amount"],
 		"conditions": ["docstatus=1", "ifnull(parent, '')!=''"],
 		"order_by": "parent",
 		"links": {
@@ -278,7 +278,7 @@
 		}
 	},
 	"Purchase Receipt Item[Purchase Analytics]": {
-		"columns": ["name", "parent", "item_code", "qty", "base_amount"],
+		"columns": ["name", "parent", "item_code", "qty", "base_net_amount"],
 		"conditions": ["docstatus=1", "ifnull(parent, '')!=''"],
 		"order_by": "parent",
 		"links": {
diff --git a/erpnext/stock/doctype/delivery_note/delivery_note.js b/erpnext/stock/doctype/delivery_note/delivery_note.js
index 2743ffc..185c242 100644
--- a/erpnext/stock/doctype/delivery_note/delivery_note.js
+++ b/erpnext/stock/doctype/delivery_note/delivery_note.js
@@ -2,7 +2,6 @@
 // License: GNU General Public License v3. See license.txt
 
 {% include 'selling/sales_common.js' %};
-{% include 'accounts/doctype/sales_taxes_and_charges_master/sales_taxes_and_charges_master.js' %}
 
 frappe.provide("erpnext.stock");
 frappe.provide("erpnext.stock.delivery_note");
@@ -25,7 +24,7 @@
 			cur_frm.add_custom_button(__('Make Installation Note'), this.make_installation_note);
 
 		if (doc.docstatus==1) {
-			
+
 			this.show_stock_ledger();
 			this.show_general_ledger();
 		}
@@ -131,6 +130,7 @@
 		dn_item_fields['discount_percentage'].print_hide = 1;
 		dn_item_fields['price_list_rate'].print_hide = 1;
 		dn_item_fields['amount'].print_hide = 1;
+		dn_fields['taxes'].print_hide = 1;
 	} else {
 		if (dn_fields_copy['currency'].print_hide != 1)
 			dn_fields['currency'].print_hide = 0;
@@ -138,6 +138,8 @@
 			dn_item_fields['rate'].print_hide = 0;
 		if (dn_item_fields_copy['amount'].print_hide != 1)
 			dn_item_fields['amount'].print_hide = 0;
+		if (dn_fields_copy['taxes'].print_hide != 1)
+			dn_fields['taxes'].print_hide = 0;
 	}
 }
 
diff --git a/erpnext/stock/doctype/delivery_note/delivery_note.json b/erpnext/stock/doctype/delivery_note/delivery_note.json
index 6c8881e..a68f8cb 100644
--- a/erpnext/stock/doctype/delivery_note/delivery_note.json
+++ b/erpnext/stock/doctype/delivery_note/delivery_note.json
@@ -341,6 +341,16 @@
    "permlevel": 0
   }, 
   {
+   "fieldname": "base_total", 
+   "fieldtype": "Currency", 
+   "label": "Total (Company Currency)", 
+   "options": "Company:company:default_currency", 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 1, 
+   "read_only": 1
+  }, 
+  {
    "fieldname": "base_net_total", 
    "fieldtype": "Currency", 
    "label": "Net Total (Company Currency)", 
@@ -361,6 +371,16 @@
    "permlevel": 0
   }, 
   {
+   "fieldname": "total", 
+   "fieldtype": "Currency", 
+   "label": "Total", 
+   "options": "currency", 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 1, 
+   "read_only": 1
+  }, 
+  {
    "fieldname": "net_total", 
    "fieldtype": "Currency", 
    "label": "Net Total", 
@@ -444,6 +464,12 @@
    "read_only": 1
   }, 
   {
+   "fieldname": "column_break_47", 
+   "fieldtype": "Column Break", 
+   "permlevel": 0, 
+   "precision": ""
+  }, 
+  {
    "fieldname": "base_total_taxes_and_charges", 
    "fieldtype": "Currency", 
    "label": "Total Taxes and Charges (Company Currency)", 
@@ -457,7 +483,22 @@
    "width": "150px"
   }, 
   {
-   "fieldname": "column_break_47", 
+   "fieldname": "section_break_49", 
+   "fieldtype": "Section Break", 
+   "permlevel": 0, 
+   "precision": ""
+  }, 
+  {
+   "default": "Grand Total", 
+   "fieldname": "apply_discount_on", 
+   "fieldtype": "Select", 
+   "label": "Apply Discount On", 
+   "options": "\nGrand Total\nNet Total", 
+   "permlevel": 0, 
+   "precision": ""
+  }, 
+  {
+   "fieldname": "column_break_51", 
    "fieldtype": "Column Break", 
    "permlevel": 0
   }, 
@@ -1024,7 +1065,7 @@
  "idx": 1, 
  "in_create": 0, 
  "is_submittable": 1, 
- "modified": "2015-02-20 05:16:21.997931", 
+ "modified": "2015-02-23 15:49:10.972483", 
  "modified_by": "Administrator", 
  "module": "Stock", 
  "name": "Delivery Note", 
diff --git a/erpnext/stock/doctype/delivery_note_item/delivery_note_item.json b/erpnext/stock/doctype/delivery_note_item/delivery_note_item.json
index 2545b0a..adcf258 100644
--- a/erpnext/stock/doctype/delivery_note_item/delivery_note_item.json
+++ b/erpnext/stock/doctype/delivery_note_item/delivery_note_item.json
@@ -255,6 +255,58 @@
    "read_only": 1
   }, 
   {
+   "fieldname": "section_break_25", 
+   "fieldtype": "Section Break", 
+   "permlevel": 0, 
+   "precision": ""
+  }, 
+  {
+   "fieldname": "net_rate", 
+   "fieldtype": "Currency", 
+   "label": "Net Rate", 
+   "options": "currency", 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 1, 
+   "read_only": 1
+  }, 
+  {
+   "fieldname": "net_amount", 
+   "fieldtype": "Currency", 
+   "label": "Net Amount", 
+   "options": "currency", 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 1, 
+   "read_only": 1
+  }, 
+  {
+   "fieldname": "column_break_28", 
+   "fieldtype": "Column Break", 
+   "permlevel": 0, 
+   "precision": ""
+  }, 
+  {
+   "fieldname": "base_net_rate", 
+   "fieldtype": "Currency", 
+   "label": "Net Rate (Company Currency)", 
+   "options": "Company:company:default_currency", 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 1, 
+   "read_only": 1
+  }, 
+  {
+   "fieldname": "base_net_amount", 
+   "fieldtype": "Currency", 
+   "label": "Net Amount (Company Currency)", 
+   "options": "Company:company:default_currency", 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 1, 
+   "read_only": 1
+  }, 
+  {
    "fieldname": "warehouse_and_reference", 
    "fieldtype": "Section Break", 
    "label": "Warehouse and Reference", 
@@ -443,17 +495,6 @@
    "width": "150px"
   }, 
   {
-   "fieldname": "buying_amount", 
-   "fieldtype": "Currency", 
-   "hidden": 1, 
-   "label": "Buying Amount", 
-   "no_copy": 1, 
-   "options": "Company:company:default_currency", 
-   "permlevel": 0, 
-   "print_hide": 1, 
-   "read_only": 1
-  }, 
-  {
    "allow_on_submit": 1, 
    "fieldname": "page_break", 
    "fieldtype": "Check", 
@@ -467,7 +508,7 @@
  ], 
  "idx": 1, 
  "istable": 1, 
- "modified": "2015-02-19 01:06:59.675246", 
+ "modified": "2015-02-23 15:51:20.772564", 
  "modified_by": "Administrator", 
  "module": "Stock", 
  "name": "Delivery Note Item", 
diff --git a/erpnext/stock/doctype/purchase_receipt/purchase_receipt.js b/erpnext/stock/doctype/purchase_receipt/purchase_receipt.js
index 50a1073..a7e6620 100644
--- a/erpnext/stock/doctype/purchase_receipt/purchase_receipt.js
+++ b/erpnext/stock/doctype/purchase_receipt/purchase_receipt.js
@@ -2,7 +2,6 @@
 // License: GNU General Public License v3. See license.txt
 
 {% include 'buying/doctype/purchase_common/purchase_common.js' %};
-{% include 'accounts/doctype/purchase_taxes_and_charges_master/purchase_taxes_and_charges_master.js' %}
 
 frappe.provide("erpnext.stock");
 erpnext.stock.PurchaseReceiptController = erpnext.buying.BuyingController.extend({
diff --git a/erpnext/stock/doctype/purchase_receipt/purchase_receipt.json b/erpnext/stock/doctype/purchase_receipt/purchase_receipt.json
index 947c94c..7964dd2 100755
--- a/erpnext/stock/doctype/purchase_receipt/purchase_receipt.json
+++ b/erpnext/stock/doctype/purchase_receipt/purchase_receipt.json
@@ -223,12 +223,31 @@
    "reqd": 0
   }, 
   {
+   "fieldname": "get_current_stock", 
+   "fieldtype": "Button", 
+   "label": "Get Current Stock", 
+   "oldfieldtype": "Button", 
+   "options": "get_current_stock", 
+   "permlevel": 0, 
+   "print_hide": 1
+  }, 
+  {
    "fieldname": "section_break0", 
    "fieldtype": "Section Break", 
    "oldfieldtype": "Section Break", 
    "permlevel": 0
   }, 
   {
+   "fieldname": "base_total", 
+   "fieldtype": "Currency", 
+   "label": "Total (Company Currency)", 
+   "options": "Company:company:default_currency", 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 1, 
+   "read_only": 1
+  }, 
+  {
    "fieldname": "base_net_total", 
    "fieldtype": "Currency", 
    "label": "Net Total (Company Currency)", 
@@ -243,20 +262,22 @@
    "width": "150px"
   }, 
   {
-   "fieldname": "get_current_stock", 
-   "fieldtype": "Button", 
-   "label": "Get Current Stock", 
-   "oldfieldtype": "Button", 
-   "options": "get_current_stock", 
-   "permlevel": 0, 
-   "print_hide": 1
-  }, 
-  {
    "fieldname": "column_break_27", 
    "fieldtype": "Column Break", 
    "permlevel": 0
   }, 
   {
+   "fieldname": "total", 
+   "fieldtype": "Currency", 
+   "hidden": 0, 
+   "label": "Total", 
+   "options": "currency", 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 1, 
+   "read_only": 1
+  }, 
+  {
    "fieldname": "net_total", 
    "fieldtype": "Currency", 
    "label": "Net Total", 
@@ -347,39 +368,6 @@
    "read_only": 1
   }, 
   {
-   "fieldname": "base_grand_total", 
-   "fieldtype": "Currency", 
-   "label": "Grand Total (Company Currency)", 
-   "oldfieldname": "grand_total", 
-   "oldfieldtype": "Currency", 
-   "options": "Company:company:default_currency", 
-   "permlevel": 0, 
-   "print_hide": 1, 
-   "read_only": 1
-  }, 
-  {
-   "fieldname": "base_rounded_total", 
-   "fieldtype": "Currency", 
-   "label": "Rounded Total (Company Currency)", 
-   "oldfieldname": "rounded_total", 
-   "oldfieldtype": "Currency", 
-   "options": "Company:company:default_currency", 
-   "permlevel": 0, 
-   "print_hide": 1, 
-   "read_only": 1
-  }, 
-  {
-   "description": "In Words will be visible once you save the Purchase Receipt.", 
-   "fieldname": "base_in_words", 
-   "fieldtype": "Data", 
-   "label": "In Words (Company Currency)", 
-   "oldfieldname": "in_words", 
-   "oldfieldtype": "Data", 
-   "permlevel": 0, 
-   "print_hide": 1, 
-   "read_only": 1
-  }, 
-  {
    "fieldname": "column_break3", 
    "fieldtype": "Column Break", 
    "permlevel": 0, 
@@ -417,6 +405,92 @@
    "precision": ""
   }, 
   {
+   "fieldname": "section_break_42", 
+   "fieldtype": "Section Break", 
+   "permlevel": 0, 
+   "precision": ""
+  }, 
+  {
+   "default": "Grand Total", 
+   "fieldname": "apply_discount_on", 
+   "fieldtype": "Select", 
+   "label": "Apply Discount On", 
+   "options": "\nGrand Total\nNet Total", 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 1
+  }, 
+  {
+   "fieldname": "column_break_44", 
+   "fieldtype": "Column Break", 
+   "permlevel": 0, 
+   "precision": ""
+  }, 
+  {
+   "fieldname": "discount_amount", 
+   "fieldtype": "Currency", 
+   "label": "Discount Amount", 
+   "options": "currency", 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 1, 
+   "read_only": 0
+  }, 
+  {
+   "fieldname": "base_discount_amount", 
+   "fieldtype": "Currency", 
+   "label": "Discount Amount (Company Currency)", 
+   "options": "Company:company:default_currency", 
+   "permlevel": 0, 
+   "precision": "", 
+   "read_only": 1
+  }, 
+  {
+   "fieldname": "section_break_46", 
+   "fieldtype": "Section Break", 
+   "permlevel": 0, 
+   "precision": ""
+  }, 
+  {
+   "fieldname": "base_grand_total", 
+   "fieldtype": "Currency", 
+   "label": "Grand Total (Company Currency)", 
+   "oldfieldname": "grand_total", 
+   "oldfieldtype": "Currency", 
+   "options": "Company:company:default_currency", 
+   "permlevel": 0, 
+   "print_hide": 1, 
+   "read_only": 1
+  }, 
+  {
+   "description": "In Words will be visible once you save the Purchase Receipt.", 
+   "fieldname": "base_in_words", 
+   "fieldtype": "Data", 
+   "label": "In Words (Company Currency)", 
+   "oldfieldname": "in_words", 
+   "oldfieldtype": "Data", 
+   "permlevel": 0, 
+   "print_hide": 1, 
+   "read_only": 1
+  }, 
+  {
+   "fieldname": "base_rounded_total", 
+   "fieldtype": "Currency", 
+   "label": "Rounded Total (Company Currency)", 
+   "oldfieldname": "rounded_total", 
+   "oldfieldtype": "Currency", 
+   "options": "Company:company:default_currency", 
+   "permlevel": 0, 
+   "print_hide": 1, 
+   "read_only": 1
+  }, 
+  {
+   "fieldname": "column_break_50", 
+   "fieldtype": "Column Break", 
+   "permlevel": 0, 
+   "precision": ""
+  }, 
+  {
    "fieldname": "grand_total", 
    "fieldtype": "Currency", 
    "in_list_view": 1, 
@@ -775,7 +849,7 @@
  "icon": "icon-truck", 
  "idx": 1, 
  "is_submittable": 1, 
- "modified": "2015-02-20 05:16:24.035630", 
+ "modified": "2015-02-23 15:16:36.617354", 
  "modified_by": "Administrator", 
  "module": "Stock", 
  "name": "Purchase Receipt", 
diff --git a/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py b/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py
index 9395e84..48fbb15 100644
--- a/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py
+++ b/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py
@@ -295,7 +295,7 @@
 						"cost_center": d.cost_center,
 						"remarks": self.get("remarks") or _("Accounting Entry for Stock"),
 						"debit": flt(flt(d.valuation_rate, val_rate_db_precision) * flt(d.qty) * flt(d.conversion_factor),
-							self.precision("base_amount", d))
+							self.precision("base_net_amount", d))
 					}))
 
 					# stock received but not billed
@@ -304,7 +304,7 @@
 						"against": warehouse_account[d.warehouse],
 						"cost_center": d.cost_center,
 						"remarks": self.get("remarks") or _("Accounting Entry for Stock"),
-						"credit": flt(d.base_amount, self.precision("base_amount", d))
+						"credit": flt(d.base_net_amount, self.precision("base_net_amount", d))
 					}))
 
 					negative_expense_to_be_booked += flt(d.item_tax_amount)
@@ -330,14 +330,14 @@
 						}))
 
 					# divisional loss adjustment
-					if not self.get("other_charges"):
+					if not self.get("taxes"):
 						sle_valuation_amount = flt(flt(d.valuation_rate, val_rate_db_precision) * flt(d.qty) * flt(d.conversion_factor),
-								self.precision("base_amount", d))
+								self.precision("base_net_amount", d))
 
-						distributed_amount = flt(flt(d.base_amount, self.precision("base_amount", d))) + \
+						distributed_amount = flt(flt(d.base_net_amount, self.precision("base_net_amount", d))) + \
 							flt(d.landed_cost_voucher_amount) + flt(d.rm_supp_cost)
 
-						divisional_loss = flt(distributed_amount - sle_valuation_amount, self.precision("base_amount", d))
+						divisional_loss = flt(distributed_amount - sle_valuation_amount, self.precision("base_net_amount", d))
 						if divisional_loss:
 							gl_entries.append(self.get_gl_dict({
 								"account": stock_rbnb,
@@ -354,12 +354,12 @@
 		# Cost center-wise amount breakup for other charges included for valuation
 		valuation_tax = {}
 		for tax in self.get("taxes"):
-			if tax.category in ("Valuation", "Valuation and Total") and flt(tax.tax_amount):
+			if tax.category in ("Valuation", "Valuation and Total") and flt(tax.base_tax_amount_after_discount_amount):
 				if not tax.cost_center:
 					frappe.throw(_("Cost Center is required in row {0} in Taxes table for type {1}").format(tax.idx, _(tax.category)))
 				valuation_tax.setdefault(tax.cost_center, 0)
 				valuation_tax[tax.cost_center] += \
-					(tax.add_deduct_tax == "Add" and 1 or -1) * flt(tax.tax_amount)
+					(tax.add_deduct_tax == "Add" and 1 or -1) * flt(tax.base_tax_amount_after_discount_amount)
 
 		if negative_expense_to_be_booked and valuation_tax:
 			# Backward compatibility:
diff --git a/erpnext/stock/doctype/purchase_receipt_item/purchase_receipt_item.json b/erpnext/stock/doctype/purchase_receipt_item/purchase_receipt_item.json
index c29a270..e36686c 100755
--- a/erpnext/stock/doctype/purchase_receipt_item/purchase_receipt_item.json
+++ b/erpnext/stock/doctype/purchase_receipt_item/purchase_receipt_item.json
@@ -284,6 +284,58 @@
    "read_only": 1
   }, 
   {
+   "fieldname": "section_break_29", 
+   "fieldtype": "Section Break", 
+   "permlevel": 0, 
+   "precision": ""
+  }, 
+  {
+   "fieldname": "net_rate", 
+   "fieldtype": "Currency", 
+   "label": "Net Rate", 
+   "options": "currency", 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 1, 
+   "read_only": 1
+  }, 
+  {
+   "fieldname": "net_amount", 
+   "fieldtype": "Currency", 
+   "label": "Net Amount", 
+   "options": "currency", 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 1, 
+   "read_only": 1
+  }, 
+  {
+   "fieldname": "column_break_32", 
+   "fieldtype": "Column Break", 
+   "permlevel": 0, 
+   "precision": ""
+  }, 
+  {
+   "fieldname": "base_net_rate", 
+   "fieldtype": "Currency", 
+   "label": "Net Rate (Company Currency)", 
+   "options": "Company:company:default_currency", 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 1, 
+   "read_only": 1
+  }, 
+  {
+   "fieldname": "base_net_amount", 
+   "fieldtype": "Currency", 
+   "label": "Net Amount (Company Currency)", 
+   "options": "Company:company:default_currency", 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 1, 
+   "read_only": 1
+  }, 
+  {
    "fieldname": "warehouse_and_reference", 
    "fieldtype": "Section Break", 
    "label": "Warehouse and Reference", 
@@ -588,7 +640,7 @@
  ], 
  "idx": 1, 
  "istable": 1, 
- "modified": "2015-02-19 01:07:01.405923", 
+ "modified": "2015-02-23 15:19:26.294450", 
  "modified_by": "Administrator", 
  "module": "Stock", 
  "name": "Purchase Receipt Item", 
diff --git a/erpnext/stock/doctype/stock_ledger_entry/stock_ledger_entry.py b/erpnext/stock/doctype/stock_ledger_entry/stock_ledger_entry.py
index a6abe7c..8009b40 100644
--- a/erpnext/stock/doctype/stock_ledger_entry/stock_ledger_entry.py
+++ b/erpnext/stock/doctype/stock_ledger_entry/stock_ledger_entry.py
@@ -53,7 +53,7 @@
 
 	def validate_item(self):
 		item_det = frappe.db.sql("""select name, has_batch_no, docstatus,
-			is_stock_item, has_variants
+			is_stock_item, has_variants, stock_uom
 			from tabItem where name=%s""", self.item_code, as_dict=True)[0]
 
 		if item_det.is_stock_item != 'Yes':
diff --git a/erpnext/stock/get_item_details.py b/erpnext/stock/get_item_details.py
index d7ace2f..44f60d7 100644
--- a/erpnext/stock/get_item_details.py
+++ b/erpnext/stock/get_item_details.py
@@ -170,6 +170,8 @@
 		"base_rate": 0.0,
 		"amount": 0.0,
 		"base_amount": 0.0,
+		"net_rate": 0.0,
+		"net_amount": 0.0,
 		"discount_percentage": 0.0
 	})
 
diff --git a/erpnext/templates/print_formats/includes/taxes.html b/erpnext/templates/print_formats/includes/taxes.html
index 61a78a3..9704d7e 100644
--- a/erpnext/templates/print_formats/includes/taxes.html
+++ b/erpnext/templates/print_formats/includes/taxes.html
@@ -1,6 +1,21 @@
+{%- macro render_discount_amount(doc) -%}
+	{%- if doc.discount_amount -%}
+		<div class="row">
+			<div class="col-xs-5 text-right">
+				<label>{{ "Discount Amount" }}</label></div>
+			<div class="col-xs-7 text-right">
+				- {{ doc.get_formatted("discount_amount", doc) }}
+			</div>
+		</div>
+	{%- endif -%}
+{%- endmacro -%}
+
 <div class="row">
 	<div class="col-xs-6"></div>
 	<div class="col-xs-6">
+		{%- if doc.apply_discount_on == "Net Total" -%}
+			{{ render_discount_amount(doc) }}
+		{%- endif -%}
 		{%- for charge in data -%}
 			{%- if not charge.included_in_print_rate -%}
 			<div class="row">
@@ -13,5 +28,8 @@
 			</div>
 			{%- endif -%}
 		{%- endfor -%}
+		{%- if doc.apply_discount_on == "Grand Total" -%}
+			{{ render_discount_amount(doc) }}
+		{%- endif -%}
 	</div>
 </div>