Merge branch 'develop' of https://github.com/DigiThinkIT/erpnext into DigiThinkIT-develop
diff --git a/erpnext/accounts/doctype/account/account.py b/erpnext/accounts/doctype/account/account.py
index ced1e85..cedaf60 100644
--- a/erpnext/accounts/doctype/account/account.py
+++ b/erpnext/accounts/doctype/account/account.py
@@ -171,7 +171,7 @@
 				
 			old_warehouse = cstr(frappe.db.get_value("Account", self.name, "warehouse"))
 			if old_warehouse != cstr(self.warehouse):
-				if old_warehouse:
+				if old_warehouse and frappe.db.exists("Warehouse", old_warehouse):
 					self.validate_warehouse(old_warehouse)
 				if self.warehouse:
 					self.validate_warehouse(self.warehouse)
diff --git a/erpnext/accounts/doctype/account/account_tree.js b/erpnext/accounts/doctype/account/account_tree.js
index bd0b8f2..8aee1ba 100644
--- a/erpnext/accounts/doctype/account/account_tree.js
+++ b/erpnext/accounts/doctype/account/account_tree.js
@@ -49,4 +49,23 @@
 				+ '</span>').insertBefore(node.$ul);
 		}
 	},
+	toolbar: [
+		{
+			condition: function(node) {
+				return !node.root && frappe.boot.user.can_read.indexOf("GL Entry") !== -1
+			},
+			label: __("View Ledger"),
+			click: function(node, btn) {
+				frappe.route_options = {
+					"account": node.label,
+					"from_date": sys_defaults.year_start_date,
+					"to_date": sys_defaults.year_end_date,
+					"company": frappe.defaults.get_default('company') ? frappe.defaults.get_default('company'): ""
+				};
+				frappe.set_route("query-report", "General Ledger");
+			},
+			btnClass: "hidden-xs"
+		}
+	],
+	extend_toolbar: true
 }
\ No newline at end of file
diff --git a/erpnext/accounts/doctype/accounts_settings/accounts_settings.json b/erpnext/accounts/doctype/accounts_settings/accounts_settings.json
index a02e591..c389b5c 100644
--- a/erpnext/accounts/doctype/accounts_settings/accounts_settings.json
+++ b/erpnext/accounts/doctype/accounts_settings/accounts_settings.json
@@ -10,11 +10,13 @@
  "doctype": "DocType", 
  "document_type": "Other", 
  "editable_grid": 1, 
+ "engine": "InnoDB", 
  "fields": [
   {
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "default": "1", 
    "description": "If enabled, the system will post accounting entries for inventory automatically.", 
    "fieldname": "auto_accounting_for_stock", 
@@ -41,6 +43,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "description": "Accounting entry frozen up to this date, nobody can do / modify entry except role specified below.", 
    "fieldname": "acc_frozen_upto", 
    "fieldtype": "Date", 
@@ -66,6 +69,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "description": "Users with this role are allowed to set frozen accounts and create / modify accounting entries against frozen accounts", 
    "fieldname": "frozen_accounts_modifier", 
    "fieldtype": "Link", 
@@ -92,6 +96,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "column_break_4", 
    "fieldtype": "Column Break", 
    "hidden": 0, 
@@ -116,6 +121,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "description": "Role that is allowed to submit transactions that exceed credit limits set.", 
    "fieldname": "credit_controller", 
    "fieldtype": "Link", 
@@ -142,6 +148,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "check_supplier_invoice_uniqueness", 
    "fieldtype": "Check", 
    "hidden": 0, 
@@ -162,6 +169,59 @@
    "search_index": 0, 
    "set_only_once": 0, 
    "unique": 0
+  }, 
+  {
+   "allow_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
+   "fieldname": "make_payment_via_journal_entry", 
+   "fieldtype": "Check", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 0, 
+   "in_list_view": 0, 
+   "label": "Make Payment via Journal Entry", 
+   "length": 0, 
+   "no_copy": 0, 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 0, 
+   "print_hide_if_no_value": 0, 
+   "read_only": 0, 
+   "report_hide": 0, 
+   "reqd": 0, 
+   "search_index": 0, 
+   "set_only_once": 0, 
+   "unique": 0
+  }, 
+  {
+   "allow_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
+   "default": "1", 
+   "fieldname": "unlink_payment_on_cancellation_of_invoice", 
+   "fieldtype": "Check", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 0, 
+   "in_list_view": 0, 
+   "label": "Unlink Payment on Cancellation of Invoice", 
+   "length": 0, 
+   "no_copy": 0, 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 0, 
+   "print_hide_if_no_value": 0, 
+   "read_only": 0, 
+   "report_hide": 0, 
+   "reqd": 0, 
+   "search_index": 0, 
+   "set_only_once": 0, 
+   "unique": 0
   }
  ], 
  "hide_heading": 0, 
@@ -175,7 +235,7 @@
  "issingle": 1, 
  "istable": 0, 
  "max_attachments": 0, 
- "modified": "2016-07-14 14:32:06.056888", 
+ "modified": "2016-10-20 16:12:38.595075", 
  "modified_by": "Administrator", 
  "module": "Accounts", 
  "name": "Accounts Settings", 
@@ -191,6 +251,7 @@
    "export": 0, 
    "if_owner": 0, 
    "import": 0, 
+   "is_custom": 0, 
    "permlevel": 0, 
    "print": 1, 
    "read": 1, 
diff --git a/erpnext/accounts/doctype/cost_center/cost_center.json b/erpnext/accounts/doctype/cost_center/cost_center.json
index 5f78a5b..ba32439 100644
--- a/erpnext/accounts/doctype/cost_center/cost_center.json
+++ b/erpnext/accounts/doctype/cost_center/cost_center.json
@@ -10,6 +10,7 @@
  "docstatus": 0, 
  "doctype": "DocType", 
  "document_type": "Setup", 
+ "editable_grid": 0, 
  "fields": [
   {
    "allow_on_submit": 0, 
@@ -249,14 +250,15 @@
  "hide_toolbar": 0, 
  "icon": "icon-money", 
  "idx": 1, 
- "in_create": 0, 
+ "image_view": 0, 
+ "in_create": 1, 
  "in_dialog": 0, 
  "is_submittable": 0, 
  "issingle": 0, 
  "istable": 0, 
  "max_attachments": 0, 
  "menu_index": 0, 
- "modified": "2016-05-16 15:23:14.770933", 
+ "modified": "2016-10-18 14:22:00.207907", 
  "modified_by": "Administrator", 
  "module": "Accounts", 
  "name": "Cost Center", 
@@ -368,6 +370,5 @@
  "read_only_onload": 0, 
  "search_fields": "parent_cost_center, is_group", 
  "sort_order": "ASC", 
- "track_seen": 0, 
- "version": 0
+ "track_seen": 0
 }
\ No newline at end of file
diff --git a/erpnext/accounts/doctype/journal_entry/journal_entry.json b/erpnext/accounts/doctype/journal_entry/journal_entry.json
index 9d4ad48..969af5a 100644
--- a/erpnext/accounts/doctype/journal_entry/journal_entry.json
+++ b/erpnext/accounts/doctype/journal_entry/journal_entry.json
@@ -3,16 +3,19 @@
  "allow_import": 1, 
  "allow_rename": 0, 
  "autoname": "naming_series:", 
+ "beta": 0, 
  "creation": "2013-03-25 10:53:52", 
  "custom": 0, 
  "docstatus": 0, 
  "doctype": "DocType", 
  "document_type": "Document", 
+ "editable_grid": 0, 
  "fields": [
   {
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "entry_type_and_date", 
    "fieldtype": "Section Break", 
    "hidden": 0, 
@@ -38,6 +41,7 @@
    "allow_on_submit": 1, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "default": "", 
    "fieldname": "title", 
    "fieldtype": "Data", 
@@ -64,6 +68,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "default": "Journal Entry", 
    "fieldname": "voucher_type", 
    "fieldtype": "Select", 
@@ -92,6 +97,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "naming_series", 
    "fieldtype": "Select", 
    "hidden": 0, 
@@ -119,6 +125,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "column_break1", 
    "fieldtype": "Column Break", 
    "hidden": 0, 
@@ -144,6 +151,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "posting_date", 
    "fieldtype": "Date", 
    "hidden": 0, 
@@ -170,6 +178,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "company", 
    "fieldtype": "Link", 
    "hidden": 0, 
@@ -197,6 +206,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "2_add_edit_gl_entries", 
    "fieldtype": "Section Break", 
    "hidden": 0, 
@@ -223,6 +233,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "accounts", 
    "fieldtype": "Table", 
    "hidden": 0, 
@@ -250,6 +261,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "section_break99", 
    "fieldtype": "Section Break", 
    "hidden": 0, 
@@ -273,6 +285,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "description": "", 
    "fieldname": "cheque_no", 
    "fieldtype": "Data", 
@@ -300,6 +313,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "cheque_date", 
    "fieldtype": "Date", 
    "hidden": 0, 
@@ -326,6 +340,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "user_remark", 
    "fieldtype": "Small Text", 
    "hidden": 0, 
@@ -352,6 +367,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "column_break99", 
    "fieldtype": "Column Break", 
    "hidden": 0, 
@@ -375,6 +391,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "total_debit", 
    "fieldtype": "Currency", 
    "hidden": 0, 
@@ -402,6 +419,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "total_credit", 
    "fieldtype": "Currency", 
    "hidden": 0, 
@@ -429,6 +447,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "depends_on": "difference", 
    "fieldname": "difference", 
    "fieldtype": "Currency", 
@@ -457,6 +476,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "depends_on": "difference", 
    "fieldname": "get_balance", 
    "fieldtype": "Button", 
@@ -483,6 +503,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "multi_currency", 
    "fieldtype": "Check", 
    "hidden": 0, 
@@ -506,8 +527,36 @@
   }, 
   {
    "allow_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
+   "fieldname": "total_amount_currency", 
+   "fieldtype": "Link", 
+   "hidden": 1, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 0, 
+   "in_list_view": 0, 
+   "label": "Total Amount Currency", 
+   "length": 0, 
+   "no_copy": 1, 
+   "options": "Currency", 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 1, 
+   "print_hide_if_no_value": 0, 
+   "read_only": 1, 
+   "report_hide": 1, 
+   "reqd": 0, 
+   "search_index": 0, 
+   "set_only_once": 0, 
+   "unique": 0
+  }, 
+  {
+   "allow_on_submit": 0, 
    "bold": 1, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "total_amount", 
    "fieldtype": "Currency", 
    "hidden": 1, 
@@ -518,7 +567,7 @@
    "label": "Total Amount", 
    "length": 0, 
    "no_copy": 1, 
-   "options": "Company:company:default_currency", 
+   "options": "total_amount_currency", 
    "permlevel": 0, 
    "print_hide": 0, 
    "print_hide_if_no_value": 0, 
@@ -533,6 +582,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "total_amount_in_words", 
    "fieldtype": "Data", 
    "hidden": 1, 
@@ -557,6 +607,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 1, 
+   "columns": 0, 
    "fieldname": "reference", 
    "fieldtype": "Section Break", 
    "hidden": 0, 
@@ -582,6 +633,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "clearance_date", 
    "fieldtype": "Date", 
    "hidden": 0, 
@@ -608,6 +660,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "description": "", 
    "fieldname": "remark", 
    "fieldtype": "Small Text", 
@@ -635,6 +688,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "column_break98", 
    "fieldtype": "Column Break", 
    "hidden": 0, 
@@ -658,6 +712,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "bill_no", 
    "fieldtype": "Data", 
    "hidden": 0, 
@@ -684,6 +739,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "bill_date", 
    "fieldtype": "Date", 
    "hidden": 0, 
@@ -710,6 +766,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "due_date", 
    "fieldtype": "Date", 
    "hidden": 0, 
@@ -736,6 +793,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 1, 
+   "columns": 0, 
    "depends_on": "eval:doc.voucher_type == 'Write Off Entry'", 
    "fieldname": "write_off", 
    "fieldtype": "Section Break", 
@@ -762,6 +820,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "default": "Accounts Receivable", 
    "depends_on": "eval:doc.voucher_type == 'Write Off Entry'", 
    "fieldname": "write_off_based_on", 
@@ -789,6 +848,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "depends_on": "eval:doc.voucher_type == 'Write Off Entry'", 
    "fieldname": "get_outstanding_invoices", 
    "fieldtype": "Button", 
@@ -815,6 +875,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "column_break_30", 
    "fieldtype": "Column Break", 
    "hidden": 0, 
@@ -839,6 +900,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "depends_on": "eval:doc.voucher_type == 'Write Off Entry'", 
    "fieldname": "write_off_amount", 
    "fieldtype": "Currency", 
@@ -865,6 +927,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 1, 
+   "columns": 0, 
    "fieldname": "printing_settings", 
    "fieldtype": "Section Break", 
    "hidden": 0, 
@@ -890,6 +953,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "pay_to_recd_from", 
    "fieldtype": "Data", 
    "hidden": 0, 
@@ -914,6 +978,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "column_break_35", 
    "fieldtype": "Column Break", 
    "hidden": 0, 
@@ -938,6 +1003,7 @@
    "allow_on_submit": 1, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "letter_head", 
    "fieldtype": "Link", 
    "hidden": 0, 
@@ -963,6 +1029,7 @@
    "allow_on_submit": 1, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "select_print_heading", 
    "fieldtype": "Link", 
    "hidden": 0, 
@@ -990,6 +1057,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 1, 
+   "columns": 0, 
    "fieldname": "addtional_info", 
    "fieldtype": "Section Break", 
    "hidden": 0, 
@@ -1016,6 +1084,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "column_break3", 
    "fieldtype": "Column Break", 
    "hidden": 0, 
@@ -1041,6 +1110,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "default": "No", 
    "description": "", 
    "fieldname": "is_opening", 
@@ -1070,6 +1140,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "depends_on": "eval:inList([\"Credit Note\", \"Debit Note\"], doc.voucher_type)", 
    "fieldname": "stock_entry", 
    "fieldtype": "Link", 
@@ -1097,6 +1168,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "amended_from", 
    "fieldtype": "Link", 
    "hidden": 0, 
@@ -1125,6 +1197,7 @@
  "hide_toolbar": 0, 
  "icon": "icon-file-text", 
  "idx": 176, 
+ "image_view": 0, 
  "in_create": 0, 
  "in_dialog": 0, 
  "is_submittable": 1, 
@@ -1132,7 +1205,7 @@
  "istable": 0, 
  "max_attachments": 0, 
  "menu_index": 0, 
- "modified": "2016-04-06 05:33:21.851581", 
+ "modified": "2016-10-03 10:13:49.458343", 
  "modified_by": "Administrator", 
  "module": "Accounts", 
  "name": "Journal Entry", 
@@ -1148,6 +1221,7 @@
    "export": 0, 
    "if_owner": 0, 
    "import": 0, 
+   "is_custom": 0, 
    "permlevel": 0, 
    "print": 1, 
    "read": 1, 
@@ -1168,6 +1242,7 @@
    "export": 0, 
    "if_owner": 0, 
    "import": 0, 
+   "is_custom": 0, 
    "permlevel": 0, 
    "print": 1, 
    "read": 1, 
@@ -1188,6 +1263,7 @@
    "export": 0, 
    "if_owner": 0, 
    "import": 0, 
+   "is_custom": 0, 
    "permlevel": 0, 
    "print": 1, 
    "read": 1, 
@@ -1199,6 +1275,7 @@
    "write": 0
   }
  ], 
+ "quick_entry": 0, 
  "read_only": 0, 
  "read_only_onload": 1, 
  "search_fields": "voucher_type,posting_date, due_date, cheque_no", 
diff --git a/erpnext/accounts/doctype/journal_entry/journal_entry.py b/erpnext/accounts/doctype/journal_entry/journal_entry.py
index 4e00c32..083ba6f 100644
--- a/erpnext/accounts/doctype/journal_entry/journal_entry.py
+++ b/erpnext/accounts/doctype/journal_entry/journal_entry.py
@@ -62,11 +62,13 @@
 
 	def on_cancel(self):
 		from erpnext.accounts.utils import unlink_ref_doc_from_payment_entries
+		from erpnext.hr.doctype.salary_slip.salary_slip import unlink_ref_doc_from_salary_slip
 		unlink_ref_doc_from_payment_entries(self.doctype, self.name)
-
+		unlink_ref_doc_from_salary_slip(self.name)		
 		self.make_gl_entries(1)
 		self.update_advance_paid()
 		self.update_expense_claim()
+		
 
 	def validate_party(self):
 		for d in self.get("accounts"):
@@ -381,6 +383,7 @@
 
 	def set_total_amount(self, amt, currency):
 		self.total_amount = amt
+		self.total_amount_currency = currency
 		from frappe.utils import money_in_words
 		self.total_amount_in_words = money_in_words(amt, currency)
 
diff --git a/erpnext/accounts/doctype/payment_entry/payment_entry.js b/erpnext/accounts/doctype/payment_entry/payment_entry.js
index 5e6fc53..6ecd8fa 100644
--- a/erpnext/accounts/doctype/payment_entry/payment_entry.js
+++ b/erpnext/accounts/doctype/payment_entry/payment_entry.js
@@ -504,6 +504,18 @@
 		});
 	},
 
+	allocate_payment_amount: function(frm) {
+		if(frm.doc.payment_type == 'Internal Transfer'){
+			return
+		}
+
+		if(frm.doc.references.length == 0){
+			frm.events.get_outstanding_documents(frm);
+		}
+
+		frm.events.allocate_party_amount_against_ref_docs(frm, frm.doc.received_amount);
+	},
+
 	allocate_party_amount_against_ref_docs: function(frm, paid_amount) {
 		var total_positive_outstanding_including_order = 0;
 		var total_negative_outstanding = 0;
@@ -545,22 +557,24 @@
 		}
 
 		$.each(frm.doc.references || [], function(i, row) {
-			row.allocated_amount = 0
+			row.allocated_amount = 0 //If allocate payment amount checkbox is unchecked, set zero to allocate amount
+			if(frm.doc.allocate_payment_amount){
+				if(row.outstanding_amount > 0 && allocated_positive_outstanding > 0) {
+					if(row.outstanding_amount >= allocated_positive_outstanding)
+							row.allocated_amount = allocated_positive_outstanding;
+					else row.allocated_amount = row.outstanding_amount;
 
-			if(row.outstanding_amount > 0 && allocated_positive_outstanding > 0) {
-				if(row.outstanding_amount >= allocated_positive_outstanding)
-						row.allocated_amount = allocated_positive_outstanding;
-				else row.allocated_amount = row.outstanding_amount;
+					allocated_positive_outstanding -= flt(row.allocated_amount);
+				} else if (row.outstanding_amount < 0 && allocated_negative_outstanding) {
+					if(Math.abs(row.outstanding_amount) >= allocated_negative_outstanding)
+						row.allocated_amount = -1*allocated_negative_outstanding;
+					else row.allocated_amount = row.outstanding_amount;
 
-				allocated_positive_outstanding -= flt(row.allocated_amount);
-			} else if (row.outstanding_amount < 0 && allocated_negative_outstanding) {
-				if(Math.abs(row.outstanding_amount) >= allocated_negative_outstanding)
-					row.allocated_amount = -1*allocated_negative_outstanding;
-				else row.allocated_amount = row.outstanding_amount;
-
-				allocated_negative_outstanding -= Math.abs(flt(row.allocated_amount));
+					allocated_negative_outstanding -= Math.abs(flt(row.allocated_amount));
+				}
 			}
 		})
+
 		frm.refresh_fields()
 		frm.events.set_total_allocated_amount(frm);
 	},
diff --git a/erpnext/accounts/doctype/payment_entry/payment_entry.json b/erpnext/accounts/doctype/payment_entry/payment_entry.json
index 2057d07..6018571 100644
--- a/erpnext/accounts/doctype/payment_entry/payment_entry.json
+++ b/erpnext/accounts/doctype/payment_entry/payment_entry.json
@@ -777,6 +777,34 @@
    "bold": 0, 
    "collapsible": 0, 
    "columns": 0, 
+   "default": "1", 
+   "depends_on": "eval:in_list(['Pay', 'Receive'], doc.payment_type)", 
+   "fieldname": "allocate_payment_amount", 
+   "fieldtype": "Check", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 0, 
+   "in_list_view": 0, 
+   "label": "Allocate Payment Amount", 
+   "length": 0, 
+   "no_copy": 0, 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 0, 
+   "print_hide_if_no_value": 0, 
+   "read_only": 0, 
+   "report_hide": 0, 
+   "reqd": 0, 
+   "search_index": 0, 
+   "set_only_once": 0, 
+   "unique": 0
+  }, 
+  {
+   "allow_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
    "depends_on": "", 
    "fieldname": "references", 
    "fieldtype": "Table", 
@@ -1426,7 +1454,7 @@
  "issingle": 0, 
  "istable": 0, 
  "max_attachments": 0, 
- "modified": "2016-09-05 11:06:18.183458", 
+ "modified": "2016-09-28 18:20:47.625383", 
  "modified_by": "Administrator", 
  "module": "Accounts", 
  "name": "Payment Entry", 
diff --git a/erpnext/accounts/doctype/payment_entry/payment_entry.py b/erpnext/accounts/doctype/payment_entry/payment_entry.py
index 179a321..7b9bf16 100644
--- a/erpnext/accounts/doctype/payment_entry/payment_entry.py
+++ b/erpnext/accounts/doctype/payment_entry/payment_entry.py
@@ -669,6 +669,7 @@
 	pe.paid_to_account_currency = party_account_currency if payment_type=="Pay" else bank.account_currency
 	pe.paid_amount = paid_amount
 	pe.received_amount = received_amount
+	pe.allocate_payment_amount = 1
 	
 	pe.append("references", {
 		"reference_doctype": dt,
diff --git a/erpnext/accounts/doctype/payment_request/payment_request.py b/erpnext/accounts/doctype/payment_request/payment_request.py
index 84a8e82..26663fd 100644
--- a/erpnext/accounts/doctype/payment_request/payment_request.py
+++ b/erpnext/accounts/doctype/payment_request/payment_request.py
@@ -65,7 +65,7 @@
 		data = frappe.db.get_value(self.reference_doctype, self.reference_name,
 			["company", "customer_name"], as_dict=1)
 		
-		controller = get_integration_controller(self.payment_gateway, setup=False)
+		controller = get_integration_controller(self.payment_gateway)
 		controller.validate_transaction_currency(self.currency)
 		
 		return controller.get_payment_url(**{
diff --git a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.json b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.json
index 836a2e0..bad511e 100755
--- a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.json
+++ b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.json
@@ -15,6 +15,7 @@
    "allow_on_submit": 1, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "default": "{supplier_name}", 
    "fieldname": "title", 
    "fieldtype": "Data", 
@@ -41,6 +42,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "naming_series", 
    "fieldtype": "Select", 
    "hidden": 0, 
@@ -68,6 +70,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "supplier", 
    "fieldtype": "Link", 
    "hidden": 0, 
@@ -95,6 +98,7 @@
    "allow_on_submit": 0, 
    "bold": 1, 
    "collapsible": 0, 
+   "columns": 0, 
    "depends_on": "supplier", 
    "fieldname": "supplier_name", 
    "fieldtype": "Data", 
@@ -122,6 +126,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "description": "", 
    "fieldname": "bill_no", 
    "fieldtype": "Data", 
@@ -149,6 +154,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "is_paid", 
    "fieldtype": "Check", 
    "hidden": 0, 
@@ -174,6 +180,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "default": "0", 
    "fieldname": "is_return", 
    "fieldtype": "Check", 
@@ -184,7 +191,7 @@
    "in_list_view": 0, 
    "label": "Is Return", 
    "length": 0, 
-   "no_copy": 0, 
+   "no_copy": 1, 
    "permlevel": 0, 
    "precision": "", 
    "print_hide": 1, 
@@ -200,6 +207,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "column_break1", 
    "fieldtype": "Column Break", 
    "hidden": 0, 
@@ -225,6 +233,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "default": "Today", 
    "fieldname": "posting_date", 
    "fieldtype": "Date", 
@@ -252,6 +261,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "due_date", 
    "fieldtype": "Date", 
    "hidden": 0, 
@@ -278,6 +288,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "bill_date", 
    "fieldtype": "Date", 
    "hidden": 0, 
@@ -304,6 +315,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "amended_from", 
    "fieldtype": "Link", 
    "hidden": 0, 
@@ -331,6 +343,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "company", 
    "fieldtype": "Link", 
    "hidden": 0, 
@@ -356,6 +369,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "depends_on": "is_return", 
    "fieldname": "return_against", 
    "fieldtype": "Link", 
@@ -366,7 +380,7 @@
    "in_list_view": 0, 
    "label": "Return Against Purchase Invoice", 
    "length": 0, 
-   "no_copy": 0, 
+   "no_copy": 1, 
    "options": "Purchase Invoice", 
    "permlevel": 0, 
    "precision": "", 
@@ -383,6 +397,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 1, 
+   "columns": 0, 
    "fieldname": "section_addresses", 
    "fieldtype": "Section Break", 
    "hidden": 0, 
@@ -408,6 +423,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "supplier_address", 
    "fieldtype": "Link", 
    "hidden": 0, 
@@ -433,6 +449,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "contact_person", 
    "fieldtype": "Link", 
    "hidden": 0, 
@@ -458,6 +475,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "depends_on": "", 
    "fieldname": "address_display", 
    "fieldtype": "Small Text", 
@@ -483,6 +501,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "contact_display", 
    "fieldtype": "Small Text", 
    "hidden": 0, 
@@ -507,6 +526,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "contact_mobile", 
    "fieldtype": "Small Text", 
    "hidden": 0, 
@@ -531,6 +551,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "contact_email", 
    "fieldtype": "Small Text", 
    "hidden": 0, 
@@ -555,6 +576,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "col_break_address", 
    "fieldtype": "Column Break", 
    "hidden": 0, 
@@ -579,6 +601,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "depends_on": "", 
    "fieldname": "shipping_address", 
    "fieldtype": "Link", 
@@ -606,6 +629,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "shipping_address_display", 
    "fieldtype": "Small Text", 
    "hidden": 0, 
@@ -631,6 +655,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 1, 
+   "columns": 0, 
    "fieldname": "currency_and_price_list", 
    "fieldtype": "Section Break", 
    "hidden": 0, 
@@ -656,6 +681,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "currency", 
    "fieldtype": "Link", 
    "hidden": 0, 
@@ -683,6 +709,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "description": "", 
    "fieldname": "conversion_rate", 
    "fieldtype": "Float", 
@@ -711,6 +738,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "column_break2", 
    "fieldtype": "Column Break", 
    "hidden": 0, 
@@ -734,6 +762,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "buying_price_list", 
    "fieldtype": "Link", 
    "hidden": 0, 
@@ -759,6 +788,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "price_list_currency", 
    "fieldtype": "Link", 
    "hidden": 0, 
@@ -784,6 +814,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "plc_conversion_rate", 
    "fieldtype": "Float", 
    "hidden": 0, 
@@ -809,6 +840,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "ignore_pricing_rule", 
    "fieldtype": "Check", 
    "hidden": 0, 
@@ -833,6 +865,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "items_section", 
    "fieldtype": "Section Break", 
    "hidden": 0, 
@@ -859,6 +892,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "default": "0", 
    "fieldname": "update_stock", 
    "fieldtype": "Check", 
@@ -885,6 +919,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "items", 
    "fieldtype": "Table", 
    "hidden": 0, 
@@ -912,6 +947,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "section_break_26", 
    "fieldtype": "Section Break", 
    "hidden": 0, 
@@ -935,6 +971,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "base_total", 
    "fieldtype": "Currency", 
    "hidden": 0, 
@@ -961,6 +998,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "description": "", 
    "fieldname": "base_net_total", 
    "fieldtype": "Currency", 
@@ -989,6 +1027,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "column_break_28", 
    "fieldtype": "Column Break", 
    "hidden": 0, 
@@ -1012,6 +1051,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "total", 
    "fieldtype": "Currency", 
    "hidden": 0, 
@@ -1038,6 +1078,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "net_total", 
    "fieldtype": "Currency", 
    "hidden": 0, 
@@ -1065,6 +1106,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "taxes_section", 
    "fieldtype": "Section Break", 
    "hidden": 0, 
@@ -1091,6 +1133,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "taxes_and_charges", 
    "fieldtype": "Link", 
    "hidden": 0, 
@@ -1118,6 +1161,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "taxes", 
    "fieldtype": "Table", 
    "hidden": 0, 
@@ -1145,6 +1189,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "other_charges_calculation", 
    "fieldtype": "HTML", 
    "hidden": 0, 
@@ -1170,6 +1215,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "totals", 
    "fieldtype": "Section Break", 
    "hidden": 0, 
@@ -1196,6 +1242,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "base_taxes_and_charges_added", 
    "fieldtype": "Currency", 
    "hidden": 0, 
@@ -1223,6 +1270,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "base_taxes_and_charges_deducted", 
    "fieldtype": "Currency", 
    "hidden": 0, 
@@ -1250,6 +1298,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "base_total_taxes_and_charges", 
    "fieldtype": "Currency", 
    "hidden": 0, 
@@ -1277,6 +1326,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "column_break_40", 
    "fieldtype": "Column Break", 
    "hidden": 0, 
@@ -1301,6 +1351,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "taxes_and_charges_added", 
    "fieldtype": "Currency", 
    "hidden": 0, 
@@ -1328,6 +1379,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "taxes_and_charges_deducted", 
    "fieldtype": "Currency", 
    "hidden": 0, 
@@ -1355,6 +1407,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "total_taxes_and_charges", 
    "fieldtype": "Currency", 
    "hidden": 0, 
@@ -1382,6 +1435,7 @@
    "bold": 0, 
    "collapsible": 1, 
    "collapsible_depends_on": "discount_amount", 
+   "columns": 0, 
    "fieldname": "section_break_44", 
    "fieldtype": "Section Break", 
    "hidden": 0, 
@@ -1407,6 +1461,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "default": "Grand Total", 
    "fieldname": "apply_discount_on", 
    "fieldtype": "Select", 
@@ -1434,6 +1489,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "base_discount_amount", 
    "fieldtype": "Currency", 
    "hidden": 0, 
@@ -1460,6 +1516,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "column_break_46", 
    "fieldtype": "Column Break", 
    "hidden": 0, 
@@ -1484,6 +1541,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "additional_discount_percentage", 
    "fieldtype": "Float", 
    "hidden": 0, 
@@ -1509,6 +1567,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "discount_amount", 
    "fieldtype": "Currency", 
    "hidden": 0, 
@@ -1535,6 +1594,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "section_break_49", 
    "fieldtype": "Section Break", 
    "hidden": 0, 
@@ -1559,6 +1619,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "base_grand_total", 
    "fieldtype": "Currency", 
    "hidden": 0, 
@@ -1586,6 +1647,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "description": "", 
    "fieldname": "base_in_words", 
    "fieldtype": "Data", 
@@ -1613,6 +1675,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "column_break8", 
    "fieldtype": "Column Break", 
    "hidden": 0, 
@@ -1638,6 +1701,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "grand_total", 
    "fieldtype": "Currency", 
    "hidden": 0, 
@@ -1665,6 +1729,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "in_words", 
    "fieldtype": "Data", 
    "hidden": 0, 
@@ -1691,6 +1756,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "total_advance", 
    "fieldtype": "Currency", 
    "hidden": 0, 
@@ -1718,6 +1784,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "outstanding_amount", 
    "fieldtype": "Currency", 
    "hidden": 0, 
@@ -1746,6 +1813,7 @@
    "bold": 0, 
    "collapsible": 1, 
    "collapsible_depends_on": "paid_amount", 
+   "columns": 0, 
    "depends_on": "eval:doc.is_paid===1||(doc.advances && doc.advances.length>0)", 
    "fieldname": "payments_section", 
    "fieldtype": "Section Break", 
@@ -1772,6 +1840,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "mode_of_payment", 
    "fieldtype": "Link", 
    "hidden": 0, 
@@ -1798,6 +1867,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "cash_bank_account", 
    "fieldtype": "Link", 
    "hidden": 0, 
@@ -1824,6 +1894,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "col_br_payments", 
    "fieldtype": "Column Break", 
    "hidden": 0, 
@@ -1848,6 +1919,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "depends_on": "is_paid", 
    "fieldname": "paid_amount", 
    "fieldtype": "Currency", 
@@ -1875,6 +1947,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "base_paid_amount", 
    "fieldtype": "Currency", 
    "hidden": 0, 
@@ -1902,6 +1975,7 @@
    "bold": 0, 
    "collapsible": 1, 
    "collapsible_depends_on": "write_off_amount", 
+   "columns": 0, 
    "depends_on": "grand_total", 
    "fieldname": "write_off", 
    "fieldtype": "Section Break", 
@@ -1928,6 +2002,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "write_off_amount", 
    "fieldtype": "Currency", 
    "hidden": 0, 
@@ -1953,6 +2028,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "base_write_off_amount", 
    "fieldtype": "Currency", 
    "hidden": 0, 
@@ -1979,6 +2055,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "column_break_61", 
    "fieldtype": "Column Break", 
    "hidden": 0, 
@@ -2003,6 +2080,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "depends_on": "eval:flt(doc.write_off_amount)!=0", 
    "fieldname": "write_off_account", 
    "fieldtype": "Link", 
@@ -2029,6 +2107,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "depends_on": "eval:flt(doc.write_off_amount)!=0", 
    "fieldname": "write_off_cost_center", 
    "fieldtype": "Link", 
@@ -2056,6 +2135,7 @@
    "bold": 0, 
    "collapsible": 1, 
    "collapsible_depends_on": "advances", 
+   "columns": 0, 
    "fieldname": "advances_section", 
    "fieldtype": "Section Break", 
    "hidden": 0, 
@@ -2082,6 +2162,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "get_advances", 
    "fieldtype": "Button", 
    "hidden": 0, 
@@ -2108,6 +2189,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "advances", 
    "fieldtype": "Table", 
    "hidden": 0, 
@@ -2136,6 +2218,7 @@
    "bold": 0, 
    "collapsible": 1, 
    "collapsible_depends_on": "terms", 
+   "columns": 0, 
    "fieldname": "terms_section_break", 
    "fieldtype": "Section Break", 
    "hidden": 0, 
@@ -2161,6 +2244,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "tc_name", 
    "fieldtype": "Link", 
    "hidden": 0, 
@@ -2186,6 +2270,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "terms", 
    "fieldtype": "Text Editor", 
    "hidden": 0, 
@@ -2210,6 +2295,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "raw_materials_supplied", 
    "fieldtype": "Section Break", 
    "hidden": 0, 
@@ -2235,6 +2321,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "default": "No", 
    "fieldname": "is_subcontracted", 
    "fieldtype": "Select", 
@@ -2262,6 +2349,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "supplier_warehouse", 
    "fieldtype": "Link", 
    "hidden": 0, 
@@ -2290,6 +2378,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "supplied_items", 
    "fieldtype": "Table", 
    "hidden": 0, 
@@ -2316,6 +2405,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 1, 
+   "columns": 0, 
    "fieldname": "printing_settings", 
    "fieldtype": "Section Break", 
    "hidden": 0, 
@@ -2341,6 +2431,7 @@
    "allow_on_submit": 1, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "letter_head", 
    "fieldtype": "Link", 
    "hidden": 0, 
@@ -2367,6 +2458,7 @@
    "allow_on_submit": 1, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "select_print_heading", 
    "fieldtype": "Link", 
    "hidden": 0, 
@@ -2394,6 +2486,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "language", 
    "fieldtype": "Data", 
    "hidden": 0, 
@@ -2419,6 +2512,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 1, 
+   "columns": 0, 
    "fieldname": "more_info", 
    "fieldtype": "Section Break", 
    "hidden": 0, 
@@ -2445,6 +2539,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "description": "", 
    "fieldname": "credit_to", 
    "fieldtype": "Link", 
@@ -2473,6 +2568,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "party_account_currency", 
    "fieldtype": "Link", 
    "hidden": 1, 
@@ -2499,6 +2595,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "default": "No", 
    "description": "", 
    "fieldname": "is_opening", 
@@ -2528,6 +2625,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "against_expense_account", 
    "fieldtype": "Small Text", 
    "hidden": 1, 
@@ -2554,6 +2652,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "column_break_63", 
    "fieldtype": "Column Break", 
    "hidden": 0, 
@@ -2577,6 +2676,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "posting_time", 
    "fieldtype": "Time", 
    "hidden": 0, 
@@ -2604,6 +2704,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "remarks", 
    "fieldtype": "Small Text", 
    "hidden": 0, 
@@ -2630,6 +2731,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "description": "Warehouse where you are maintaining stock of rejected items", 
    "fieldname": "rejected_warehouse", 
    "fieldtype": "Link", 
@@ -2658,6 +2760,7 @@
    "bold": 0, 
    "collapsible": 1, 
    "collapsible_depends_on": "is_recurring", 
+   "columns": 0, 
    "depends_on": "eval:doc.docstatus<2", 
    "fieldname": "recurring_invoice", 
    "fieldtype": "Section Break", 
@@ -2684,6 +2787,7 @@
    "allow_on_submit": 1, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "depends_on": "eval:doc.docstatus<2", 
    "description": "", 
    "fieldname": "is_recurring", 
@@ -2710,6 +2814,7 @@
    "allow_on_submit": 1, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "depends_on": "eval:doc.is_recurring==1", 
    "description": "Select the period when the invoice will be generated automatically", 
    "fieldname": "recurring_type", 
@@ -2737,6 +2842,7 @@
    "allow_on_submit": 1, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "depends_on": "eval:doc.is_recurring==1", 
    "description": "Start date of current invoice's period", 
    "fieldname": "from_date", 
@@ -2763,6 +2869,7 @@
    "allow_on_submit": 1, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "depends_on": "eval:doc.is_recurring==1", 
    "description": "End date of current invoice's period", 
    "fieldname": "to_date", 
@@ -2789,6 +2896,7 @@
    "allow_on_submit": 1, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "depends_on": "eval:doc.is_recurring && doc.recurring_id === doc.name", 
    "fieldname": "submit_on_creation", 
    "fieldtype": "Check", 
@@ -2815,6 +2923,7 @@
    "allow_on_submit": 1, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "depends_on": "eval:doc.is_recurring && doc.recurring_id === doc.name", 
    "description": "", 
    "fieldname": "notify_by_email", 
@@ -2842,6 +2951,7 @@
    "allow_on_submit": 1, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "depends_on": "eval:doc.is_recurring==1", 
    "description": "The day of the month on which auto invoice will be generated e.g. 05, 28 etc", 
    "fieldname": "repeat_on_day_of_month", 
@@ -2868,6 +2978,7 @@
    "allow_on_submit": 1, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "depends_on": "eval:doc.is_recurring==1", 
    "description": "The date on which recurring invoice will be stop", 
    "fieldname": "end_date", 
@@ -2894,6 +3005,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "column_break_82", 
    "fieldtype": "Column Break", 
    "hidden": 0, 
@@ -2918,6 +3030,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "depends_on": "eval:doc.is_recurring==1", 
    "description": "The date on which next invoice will be generated. It is generated on submit.", 
    "fieldname": "next_date", 
@@ -2944,6 +3057,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "depends_on": "eval:doc.is_recurring==1", 
    "description": "The unique id for tracking all recurring invoices. It is generated on submit.", 
    "fieldname": "recurring_id", 
@@ -2970,6 +3084,7 @@
    "allow_on_submit": 1, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "depends_on": "eval:doc.is_recurring==1", 
    "description": "Enter email id separated by commas, invoice will be mailed automatically on particular date", 
    "fieldname": "notification_email_address", 
@@ -2996,6 +3111,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "depends_on": "eval:doc.is_recurring==1", 
    "fieldname": "recurring_print_format", 
    "fieldtype": "Link", 
@@ -3032,7 +3148,7 @@
  "istable": 0, 
  "max_attachments": 0, 
  "menu_index": 0, 
- "modified": "2016-08-24 12:50:15.777689", 
+ "modified": "2016-09-23 18:02:45.349273", 
  "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 adc30e2..1c9bcbc 100644
--- a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py
+++ b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py
@@ -58,7 +58,7 @@
 		self.check_for_closed_status()
 		self.validate_with_previous_doc()
 		self.validate_uom_is_integer("uom", "qty")
-		self.set_expense_account()
+		self.set_expense_account(for_validate=True)
 		self.set_against_expense_account()
 		self.validate_write_off_account()
 		self.validate_multiple_billing("Purchase Receipt", "pr_detail", "amount", "items")
@@ -71,7 +71,7 @@
 			frappe.throw(_("Cash or Bank Account is mandatory for making payment entry"))
 
 		if flt(self.paid_amount) + flt(self.write_off_amount) \
-				- flt(self.base_grand_total) > 1/(10**(self.precision("base_grand_total") + 1)):
+				- flt(self.grand_total) > 1/(10**(self.precision("base_grand_total") + 1)):
 			frappe.throw(_("""Paid amount + Write Off Amount can not be greater than Grand Total"""))
 
 	def create_remarks(self):
@@ -155,7 +155,7 @@
 
 		super(PurchaseInvoice, self).validate_warehouse()
 
-	def set_expense_account(self):
+	def set_expense_account(self, for_validate=False):
 		auto_accounting_for_stock = cint(frappe.defaults.get_global_default("auto_accounting_for_stock"))
 
 		if auto_accounting_for_stock:
@@ -181,7 +181,7 @@
 				else:
 					item.expense_account = stock_not_billed_account
 
-			elif not item.expense_account:
+			elif not item.expense_account and for_validate:
 				throw(_("Expense account is mandatory for item {0}").format(item.item_code or item.item_name))
 
 	def set_against_expense_account(self):
@@ -372,7 +372,7 @@
 			if flt(item.base_net_amount):
 				account_currency = get_account_currency(item.expense_account)
 
-				if self.update_stock and self.auto_accounting_for_stock:
+				if self.update_stock and self.auto_accounting_for_stock and item.item_code in stock_items:
 					val_rate_db_precision = 6 if cint(item.precision("valuation_rate")) <= 6 else 9
 
 					# warehouse account
@@ -578,7 +578,8 @@
 
 		if not self.is_return:
 			from erpnext.accounts.utils import unlink_ref_doc_from_payment_entries
-			unlink_ref_doc_from_payment_entries(self.doctype, self.name)
+			if frappe.db.get_single_value('Accounts Settings', 'unlink_payment_on_cancellation_of_invoice'):
+				unlink_ref_doc_from_payment_entries(self.doctype, self.name)
 
 			self.update_prevdoc_status()
 			self.update_billing_status_for_zero_amount_refdoc("Purchase Order")
diff --git a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice_dashboard.py b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice_dashboard.py
index 9b950db..d4a82c5 100644
--- a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice_dashboard.py
+++ b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice_dashboard.py
@@ -1,31 +1,32 @@
 from frappe import _
 
-data = {
-	'fieldname': 'purchase_invoice',
-	'non_standard_fieldnames': {
-		'Delivery Note': 'against_sales_invoice',
-		'Journal Entry': 'reference_name',
-		'Payment Entry': 'reference_name',
-		'Payment Request': 'reference_name',
-		'Landed Cost Voucher': 'receipt_document',
-		'Purchase Invoice': 'return_against'
-	},
-	'internal_links': {
-		'Purchase Order': ['items', 'sales_order'],
-		'Purchase Receipt': ['items', 'delivery_note'],
-	},
-	'transactions': [
-		{
-			'label': _('Payment'),
-			'items': ['Payment Entry', 'Payment Request', 'Journal Entry']
+def get_data():
+	return {
+		'fieldname': 'purchase_invoice',
+		'non_standard_fieldnames': {
+			'Delivery Note': 'against_sales_invoice',
+			'Journal Entry': 'reference_name',
+			'Payment Entry': 'reference_name',
+			'Payment Request': 'reference_name',
+			'Landed Cost Voucher': 'receipt_document',
+			'Purchase Invoice': 'return_against'
 		},
-		{
-			'label': _('Reference'),
-			'items': ['Purchase Order', 'Purchase Receipt', 'Asset', 'Landed Cost Voucher']
+		'internal_links': {
+			'Purchase Order': ['items', 'sales_order'],
+			'Purchase Receipt': ['items', 'delivery_note'],
 		},
-		{
-			'label': _('Returns'),
-			'items': ['Purchase Invoice']
-		},
-	]
-}
\ No newline at end of file
+		'transactions': [
+			{
+				'label': _('Payment'),
+				'items': ['Payment Entry', 'Payment Request', 'Journal Entry']
+			},
+			{
+				'label': _('Reference'),
+				'items': ['Purchase Order', 'Purchase Receipt', 'Asset', 'Landed Cost Voucher']
+			},
+			{
+				'label': _('Returns'),
+				'items': ['Purchase Invoice']
+			},
+		]
+	}
\ No newline at end of file
diff --git a/erpnext/accounts/doctype/purchase_invoice/test_purchase_invoice.py b/erpnext/accounts/doctype/purchase_invoice/test_purchase_invoice.py
index 4ea18ac..b4b8444 100644
--- a/erpnext/accounts/doctype/purchase_invoice/test_purchase_invoice.py
+++ b/erpnext/accounts/doctype/purchase_invoice/test_purchase_invoice.py
@@ -6,7 +6,7 @@
 import unittest
 import frappe
 import frappe.model
-from frappe.utils import cint, flt, today
+from frappe.utils import cint, flt, today, nowdate
 import frappe.defaults
 from erpnext.stock.doctype.purchase_receipt.test_purchase_receipt import set_perpetual_inventory, \
 	test_records as pr_test_records
@@ -17,6 +17,12 @@
 test_ignore = ["Serial No"]
 
 class TestPurchaseInvoice(unittest.TestCase):
+	def setUp(self):
+		unlink_payment_on_cancel_of_invoice()
+
+	def tearDown(self):
+		unlink_payment_on_cancel_of_invoice(0)
+
 	def test_gl_entries_without_auto_accounting_for_stock(self):
 		set_perpetual_inventory(0)
 		self.assertTrue(not cint(frappe.defaults.get_global_default("auto_accounting_for_stock")))
@@ -55,6 +61,27 @@
 
 		set_perpetual_inventory(0)
 
+	def test_payment_entry_unlink_against_purchase_invoice(self):
+		from erpnext.accounts.doctype.payment_entry.test_payment_entry import get_payment_entry
+		unlink_payment_on_cancel_of_invoice(0)
+
+		pi_doc = make_purchase_invoice()
+
+		pe = get_payment_entry("Purchase Invoice", pi_doc.name, bank_account="_Test Bank - _TC")
+		pe.reference_no = "1"
+		pe.reference_date = nowdate()
+		pe.paid_from_account_currency = pi_doc.currency
+		pe.paid_to_account_currency = pi_doc.currency
+		pe.source_exchange_rate = 1
+		pe.target_exchange_rate = 1
+		pe.paid_amount = pi_doc.grand_total
+		pe.save(ignore_permissions=True)
+		pe.submit()
+
+		pi_doc = frappe.get_doc('Purchase Invoice', pi_doc.name)
+
+		self.assertRaises(frappe.LinkExistsError, pi_doc.cancel)
+
 	def test_gl_entries_with_auto_accounting_for_stock_against_pr(self):
 		set_perpetual_inventory(1)
 		self.assertEqual(cint(frappe.defaults.get_global_default("auto_accounting_for_stock")), 1)
@@ -411,6 +438,11 @@
 		self.assertEquals(frappe.db.get_value("Serial No", pi.get("items")[0].rejected_serial_no,
 			"warehouse"), pi.get("items")[0].rejected_warehouse)
 
+def unlink_payment_on_cancel_of_invoice(enable=1):
+	accounts_settings = frappe.get_doc("Accounts Settings")
+	accounts_settings.unlink_payment_on_cancellation_of_invoice = enable
+	accounts_settings.save()
+
 def make_purchase_invoice(**args):
 	pi = frappe.new_doc("Purchase Invoice")
 	args = frappe._dict(args)
@@ -455,4 +487,4 @@
 			pi.submit()
 	return pi
 
-test_records = frappe.get_test_records('Purchase Invoice')
+test_records = frappe.get_test_records('Purchase Invoice')
\ No newline at end of file
diff --git a/erpnext/accounts/doctype/salary_component_account/salary_component_account.json b/erpnext/accounts/doctype/salary_component_account/salary_component_account.json
index 6bbde22..6ba820e 100644
--- a/erpnext/accounts/doctype/salary_component_account/salary_component_account.json
+++ b/erpnext/accounts/doctype/salary_component_account/salary_component_account.json
@@ -14,6 +14,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "company", 
    "fieldtype": "Link", 
    "hidden": 0, 
@@ -40,7 +41,8 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
-   "description": "Default Bank / Cash account will be automatically updated in POS Invoice when this mode is selected.", 
+   "columns": 0, 
+   "description": "Default Bank / Cash account will be automatically updated in Salary Journal Entry when this mode is selected.", 
    "fieldname": "default_account", 
    "fieldtype": "Link", 
    "hidden": 0, 
@@ -74,7 +76,7 @@
  "issingle": 0, 
  "istable": 1, 
  "max_attachments": 0, 
- "modified": "2016-07-27 17:24:24.956896", 
+ "modified": "2016-09-02 07:49:06.567389", 
  "modified_by": "Administrator", 
  "module": "Accounts", 
  "name": "Salary Component Account", 
diff --git a/erpnext/accounts/doctype/sales_invoice/pos.py b/erpnext/accounts/doctype/sales_invoice/pos.py
index 5ed25b4..1d1a122 100644
--- a/erpnext/accounts/doctype/sales_invoice/pos.py
+++ b/erpnext/accounts/doctype/sales_invoice/pos.py
@@ -15,6 +15,7 @@
 	doc = frappe.new_doc('Sales Invoice')
 	doc.is_pos = 1;
 	pos_profile = get_pos_profile(doc.company) or {}
+	if not doc.company: doc.company = pos_profile.get('company')
 	doc.update_stock = pos_profile.get('update_stock')
 
 	if pos_profile.get('name'):
@@ -63,7 +64,7 @@
 	doc.naming_series = pos_profile.get('naming_series') or 'SINV-'
 	doc.letter_head = pos_profile.get('letter_head') or company_data.default_letter_head
 	doc.ignore_pricing_rule = pos_profile.get('ignore_pricing_rule') or 0
-	doc.apply_discount_on = pos_profile.get('apply_discount_on') or ''
+	doc.apply_discount_on = pos_profile.get('apply_discount_on') if pos_profile.get('apply_discount') else ''
 	doc.customer_group = pos_profile.get('customer_group') or get_root('Customer Group')
 	doc.territory = pos_profile.get('territory') or get_root('Territory')
 
@@ -235,10 +236,4 @@
 		si_doc.docstatus = 0
 		si_doc.flags.ignore_mandatory = True
 		si_doc.insert()
-		make_scheduler_log(e, si_doc.name)
-
-def make_scheduler_log(e, sales_invoice):
-	scheduler_log = frappe.new_doc('Scheduler Log')
-	scheduler_log.error = e
-	scheduler_log.sales_invoice = sales_invoice
-	scheduler_log.save(ignore_permissions=True)
\ No newline at end of file
+		frappe.log_error(frappe.get_traceback())
diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.json b/erpnext/accounts/doctype/sales_invoice/sales_invoice.json
index 8e65061..15a7112 100644
--- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.json
+++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.json
@@ -191,7 +191,7 @@
    "in_list_view": 0, 
    "label": "Is Return", 
    "length": 0, 
-   "no_copy": 0, 
+   "no_copy": 1, 
    "permlevel": 0, 
    "precision": "", 
    "print_hide": 1, 
@@ -342,6 +342,34 @@
    "bold": 0, 
    "collapsible": 0, 
    "columns": 0, 
+   "fieldname": "project", 
+   "fieldtype": "Link", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 1, 
+   "in_list_view": 0, 
+   "label": "Project", 
+   "length": 0, 
+   "no_copy": 0, 
+   "oldfieldname": "project_name", 
+   "oldfieldtype": "Link", 
+   "options": "Project", 
+   "permlevel": 0, 
+   "print_hide": 0, 
+   "print_hide_if_no_value": 0, 
+   "read_only": 0, 
+   "report_hide": 0, 
+   "reqd": 0, 
+   "search_index": 0, 
+   "set_only_once": 0, 
+   "unique": 0
+  }, 
+  {
+   "allow_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "amended_from", 
    "fieldtype": "Link", 
    "hidden": 0, 
@@ -380,7 +408,7 @@
    "in_list_view": 0, 
    "label": "Return Against Sales Invoice", 
    "length": 0, 
-   "no_copy": 0, 
+   "no_copy": 1, 
    "options": "Sales Invoice", 
    "permlevel": 0, 
    "precision": "", 
@@ -2878,21 +2906,22 @@
    "bold": 0, 
    "collapsible": 0, 
    "columns": 0, 
-   "fieldname": "project", 
+   "depends_on": "", 
+   "fieldname": "campaign", 
    "fieldtype": "Link", 
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 1, 
+   "in_filter": 0, 
    "in_list_view": 0, 
-   "label": "Project", 
+   "label": "Campaign", 
    "length": 0, 
    "no_copy": 0, 
-   "oldfieldname": "project_name", 
+   "oldfieldname": "campaign", 
    "oldfieldtype": "Link", 
-   "options": "Project", 
+   "options": "Campaign", 
    "permlevel": 0, 
-   "print_hide": 0, 
+   "print_hide": 1, 
    "print_hide_if_no_value": 0, 
    "read_only": 0, 
    "report_hide": 0, 
@@ -2931,35 +2960,6 @@
    "bold": 0, 
    "collapsible": 0, 
    "columns": 0, 
-   "depends_on": "", 
-   "fieldname": "campaign", 
-   "fieldtype": "Link", 
-   "hidden": 0, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 0, 
-   "in_list_view": 0, 
-   "label": "Campaign", 
-   "length": 0, 
-   "no_copy": 0, 
-   "oldfieldname": "campaign", 
-   "oldfieldtype": "Link", 
-   "options": "Campaign", 
-   "permlevel": 0, 
-   "print_hide": 1, 
-   "print_hide_if_no_value": 0, 
-   "read_only": 0, 
-   "report_hide": 0, 
-   "reqd": 0, 
-   "search_index": 0, 
-   "set_only_once": 0, 
-   "unique": 0
-  }, 
-  {
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
    "fieldname": "source", 
    "fieldtype": "Link", 
    "hidden": 0, 
@@ -3867,7 +3867,7 @@
  "istable": 0, 
  "max_attachments": 0, 
  "menu_index": 0, 
- "modified": "2016-09-16 06:09:01.246951", 
+ "modified": "2016-09-24 15:54:33.104276", 
  "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 3c46a16..521b0eb 100644
--- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py
+++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py
@@ -136,7 +136,8 @@
 		self.check_close_sales_order("sales_order")
 
 		from erpnext.accounts.utils import unlink_ref_doc_from_payment_entries
-		unlink_ref_doc_from_payment_entries(self.doctype, self.name)
+		if frappe.db.get_single_value('Accounts Settings', 'unlink_payment_on_cancellation_of_invoice'):
+			unlink_ref_doc_from_payment_entries(self.doctype, self.name)
 
 		if self.is_return:
 			# NOTE status updating bypassed for is_return
diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice_dashboard.py b/erpnext/accounts/doctype/sales_invoice/sales_invoice_dashboard.py
index f494303..20d4613 100644
--- a/erpnext/accounts/doctype/sales_invoice/sales_invoice_dashboard.py
+++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice_dashboard.py
@@ -1,30 +1,31 @@
 from frappe import _
 
-data = {
-	'fieldname': 'sales_invoice',
-	'non_standard_fieldnames': {
-		'Delivery Note': 'against_sales_invoice',
-		'Journal Entry': 'reference_name',
-		'Payment Entry': 'reference_name',
-		'Payment Request': 'reference_name',
-		'Sales Invoice': 'return_against'
-	},
-	'internal_links': {
-		'Sales Order': ['items', 'sales_order'],
-		'Delivery Note': ['items', 'delivery_note'],
-	},
-	'transactions': [
-		{
-			'label': _('Payment'),
-			'items': ['Payment Entry', 'Payment Request', 'Journal Entry']
+def get_data():
+	return {
+		'fieldname': 'sales_invoice',
+		'non_standard_fieldnames': {
+			'Delivery Note': 'against_sales_invoice',
+			'Journal Entry': 'reference_name',
+			'Payment Entry': 'reference_name',
+			'Payment Request': 'reference_name',
+			'Sales Invoice': 'return_against'
 		},
-		{
-			'label': _('Reference'),
-			'items': ['Timesheet', 'Delivery Note', 'Sales Order']
+		'internal_links': {
+			'Sales Order': ['items', 'sales_order'],
+			'Delivery Note': ['items', 'delivery_note'],
 		},
-		{
-			'label': _('Returns'),
-			'items': ['Sales Invoice']
-		},
-	]
-}
\ No newline at end of file
+		'transactions': [
+			{
+				'label': _('Payment'),
+				'items': ['Payment Entry', 'Payment Request', 'Journal Entry']
+			},
+			{
+				'label': _('Reference'),
+				'items': ['Timesheet', 'Delivery Note', 'Sales Order']
+			},
+			{
+				'label': _('Returns'),
+				'items': ['Sales Invoice']
+			},
+		]
+	}
\ No newline at end of file
diff --git a/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py b/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py
index 1bb7b1c..83fc83c 100644
--- a/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py
+++ b/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py
@@ -4,8 +4,9 @@
 
 import frappe
 import unittest, copy
-from frappe.utils import nowdate, add_days, flt
+from frappe.utils import nowdate, add_days, flt, nowdate
 from erpnext.stock.doctype.stock_entry.test_stock_entry import make_stock_entry, get_qty_after_transaction
+from erpnext.accounts.doctype.purchase_invoice.test_purchase_invoice import unlink_payment_on_cancel_of_invoice
 from erpnext.stock.doctype.purchase_receipt.test_purchase_receipt import set_perpetual_inventory
 from erpnext.exceptions import InvalidAccountCurrency, InvalidCurrency
 from erpnext.stock.doctype.serial_no.serial_no import SerialNoWarehouseError
@@ -19,6 +20,12 @@
 		w.submit()
 		return w
 
+	def setUp(self):
+		unlink_payment_on_cancel_of_invoice()
+
+	def tearDown(self):
+		unlink_payment_on_cancel_of_invoice(0)
+
 	def test_timestamp_change(self):
 		w = frappe.copy_doc(test_records[0])
 		w.docstatus = 0
@@ -78,6 +85,28 @@
 		self.assertEquals(si.base_grand_total, 1627.05)
 		self.assertEquals(si.grand_total, 1627.05)
 
+	def test_payment_entry_unlink_against_invoice(self):
+		from erpnext.accounts.doctype.payment_entry.test_payment_entry import get_payment_entry
+		si = frappe.copy_doc(test_records[0])
+		si.is_pos = 0
+		si.insert()
+		si.submit()
+
+		pe = get_payment_entry("Sales Invoice", si.name, bank_account="_Test Bank - _TC")
+		pe.reference_no = "1"
+		pe.reference_date = nowdate()
+		pe.paid_from_account_currency = si.currency
+		pe.paid_to_account_currency = si.currency
+		pe.source_exchange_rate = 1
+		pe.target_exchange_rate = 1
+		pe.paid_amount = si.grand_total
+		pe.insert()
+		pe.submit()
+
+		unlink_payment_on_cancel_of_invoice(0)
+		si = frappe.get_doc('Sales Invoice', si.name)
+		self.assertRaises(frappe.LinkExistsError, si.cancel)
+
 	def test_sales_invoice_calculation_export_currency(self):
 		si = frappe.copy_doc(test_records[2])
 		si.currency = "USD"
diff --git a/erpnext/accounts/doctype/sales_taxes_and_charges_template/sales_taxes_and_charges_template.py b/erpnext/accounts/doctype/sales_taxes_and_charges_template/sales_taxes_and_charges_template.py
index 28964bb..3947450 100644
--- a/erpnext/accounts/doctype/sales_taxes_and_charges_template/sales_taxes_and_charges_template.py
+++ b/erpnext/accounts/doctype/sales_taxes_and_charges_template/sales_taxes_and_charges_template.py
@@ -4,12 +4,18 @@
 from __future__ import unicode_literals
 import frappe
 from frappe import _
+from frappe.utils import flt
 from frappe.model.document import Document
 from erpnext.controllers.accounts_controller import validate_taxes_and_charges, validate_inclusive_tax
 
 class SalesTaxesandChargesTemplate(Document):
 	def validate(self):
 		valdiate_taxes_and_charges_template(self)
+		
+	def set_missing_values(self):
+		for data in self.taxes:
+			if data.charge_type == 'On Net Total' and flt(data.rate) == 0.0:
+				data.rate = frappe.db.get_value('Account', data.account_head, 'tax_rate')
 
 def valdiate_taxes_and_charges_template(doc):
 	# default should not be disabled
diff --git a/erpnext/accounts/general_ledger.py b/erpnext/accounts/general_ledger.py
index 4af197e..392902c 100644
--- a/erpnext/accounts/general_ledger.py
+++ b/erpnext/accounts/general_ledger.py
@@ -168,8 +168,8 @@
 
 	if not gl_entries:
 		gl_entries = frappe.db.sql("""
-			select account, posting_date, party_type, party, cost_center, fiscal_year,
-			voucher_type, voucher_no, against_voucher_type, against_voucher, cost_center
+			select account, posting_date, party_type, party, cost_center, fiscal_year,voucher_type,
+			voucher_no, against_voucher_type, against_voucher, cost_center, company
 			from `tabGL Entry`
 			where voucher_type=%s and voucher_no=%s""", (voucher_type, voucher_no), as_dict=True)
 
diff --git a/erpnext/accounts/page/pos/pos.js b/erpnext/accounts/page/pos/pos.js
index de85621..dbcfc2a 100644
--- a/erpnext/accounts/page/pos/pos.js
+++ b/erpnext/accounts/page/pos/pos.js
@@ -15,13 +15,11 @@
 	window.onbeforeunload = function () {
 		return wrapper.pos.beforeunload()
 	}
-	wrapper.pos.on_refresh_page()
 }
 
 
 erpnext.pos.PointOfSale = erpnext.taxes_and_totals.extend({
 	init: function(wrapper){
-		this.load = true;
 		this.page = wrapper.page;
 		this.wrapper = $(wrapper).find('.page-content');
 		this.set_indicator();
@@ -31,17 +29,6 @@
 		this.si_docs = this.get_doc_from_localstorage();
 	},
 
-	on_refresh_page: function() {
-		var me = this;
-		if(this.load){
-			this.load = false;
-		}else if(this.connection_status){
-			this.onload();
-		}else{
-			this.create_new();
-		}
-	},
-
 	beforeunload: function(e){
 		if(this.connection_status == false && frappe.get_route()[0] == "pos"){
 			e = e || window.event;
@@ -111,6 +98,10 @@
 			})
 		});
 
+		this.page.add_menu_item(__("Sync Offline Invoices"), function(){
+			me.sync_sales_invoice()
+		});
+
 		this.page.add_menu_item(__("POS Profile"), function() {
 			frappe.set_route('List', 'POS Profile');
 		});
@@ -367,11 +358,14 @@
 	get_customers: function(key){
 		var me = this;
 		key = key.toLowerCase().trim()
+		var re = new RegExp('%', 'g');
+		var reg = new RegExp(key.replace(re, '\\w*\\s*[a-zA-Z0-9]*'))
+
 		if(key){
 			return $.grep(this.customers, function(data) {
-				if(data.name.toLowerCase().match(key)
-					|| data.customer_name.toLowerCase().match(key)
-					|| (data.customer_group && data.customer_group.toLowerCase().match(key))){
+				if(reg.test(data.name.toLowerCase())
+					|| reg.test(data.customer_name.toLowerCase())
+					|| (data.customer_group && reg.test(data.customer_group.toLowerCase()))){
 					return data
 				}
 			})
@@ -395,7 +389,7 @@
 
 		if (this.items) {
 			$.each(this.items, function(index, obj) {
-				if(index < 16){
+				if(index < 30){
 					$(frappe.render_template("pos_item", {
 						item_code: obj.name,
 						item_price: format_currency(obj.price_list_rate, obj.currency),
@@ -439,7 +433,9 @@
 			})
 		}
 
-		key = this.search.$input.val().toLowerCase();
+		key =  this.search.$input.val().toLowerCase();
+		var re = new RegExp('%', 'g');
+		var reg = new RegExp(key.replace(re, '[\\w*\\s*[a-zA-Z0-9]*]*'))
 		search_status = true
 
 		if(key){
@@ -455,8 +451,8 @@
 					} else if(item.barcode == me.search.$input.val()) {
 						search_status = false;
 						return item.barcode == me.search.$input.val();
-					} else if((item.item_code.toLowerCase().match(key)) ||
-						(item.item_name.toLowerCase().match(key)) || (item.item_group.toLowerCase().match(key))) {
+					} else if(reg.test(item.item_code.toLowerCase()) || reg.test(item.description.toLowerCase()) ||
+					reg.test(item.item_name.toLowerCase()) || reg.test(item.item_group.toLowerCase()) ){
 						return true
 					}
 				}
diff --git a/erpnext/accounts/report/accounts_receivable/accounts_receivable.py b/erpnext/accounts/report/accounts_receivable/accounts_receivable.py
index e1f4f80..f6e1629 100644
--- a/erpnext/accounts/report/accounts_receivable/accounts_receivable.py
+++ b/erpnext/accounts/report/accounts_receivable/accounts_receivable.py
@@ -93,9 +93,10 @@
 		data = []
 		for gle in self.get_entries_till(self.filters.report_date, args.get("party_type")):
 			if self.is_receivable_or_payable(gle, dr_or_cr, future_vouchers):
-				outstanding_amount = self.get_outstanding_amount(gle, self.filters.report_date, dr_or_cr)
+				outstanding_amount = flt(self.get_outstanding_amount(gle, 
+					self.filters.report_date, dr_or_cr), currency_precision)
+					
 				if abs(outstanding_amount) > 0.1/10**currency_precision:
-
 					row = [gle.posting_date, gle.party]
 
 					# customer / supplier name
@@ -124,6 +125,10 @@
 					row += get_ageing_data(cint(self.filters.range1), cint(self.filters.range2),
 						cint(self.filters.range3), self.age_as_on, entry_date, outstanding_amount)
 
+					# issue 6371-Ageing buckets should not have amounts if due date is not reached
+					if self.filters.ageing_based_on == "Due Date" and getdate(due_date) > getdate(self.filters.report_date):
+						row[-1]=row[-2]=row[-3]=row[-4]=0
+
 					if self.filters.get(scrub(args.get("party_type"))):
 						row.append(gle.account_currency)
 					else:
@@ -214,14 +219,16 @@
 			conditions, values = self.prepare_conditions(party_type)
 
 			if self.filters.get(scrub(party_type)):
-				select_fields = "debit_in_account_currency as debit, credit_in_account_currency as credit"
+				select_fields = "sum(debit_in_account_currency) as debit, sum(credit_in_account_currency) as credit"
 			else:
-				select_fields = "debit, credit"
+				select_fields = "sum(debit) as debit, sum(credit) as credit"
 
-			self.gl_entries = frappe.db.sql("""select name, posting_date, account, party_type, party,
-				voucher_type, voucher_no, against_voucher_type, against_voucher, account_currency, remarks, {0}
+			self.gl_entries = frappe.db.sql("""select name, posting_date, account, party_type, party, 
+				voucher_type, voucher_no, against_voucher_type, against_voucher, 
+				account_currency, remarks, {0}
 				from `tabGL Entry`
 				where docstatus < 2 and party_type=%s and (party is not null and party != '') {1}
+				group by voucher_type, voucher_no, against_voucher_type, against_voucher, party
 				order by posting_date, party"""
 				.format(select_fields, conditions), values, as_dict=True)
 
diff --git a/erpnext/accounts/report/balance_sheet/balance_sheet.py b/erpnext/accounts/report/balance_sheet/balance_sheet.py
index d2626cd..5547b49 100644
--- a/erpnext/accounts/report/balance_sheet/balance_sheet.py
+++ b/erpnext/accounts/report/balance_sheet/balance_sheet.py
@@ -14,17 +14,31 @@
 	liability = get_data(filters.company, "Liability", "Credit", period_list, only_current_fiscal_year=False)
 	equity = get_data(filters.company, "Equity", "Credit", period_list, only_current_fiscal_year=False)
 
-	provisional_profit_loss = get_provisional_profit_loss(asset, liability, equity,
+	provisional_profit_loss,total_credit  = get_provisional_profit_loss(asset, liability, equity,
 		period_list, filters.company)
 
-	message = check_opening_balance(asset, liability, equity)
+	message,opening_balance = check_opening_balance(asset, liability, equity)
 
 	data = []
 	data.extend(asset or [])
 	data.extend(liability or [])
 	data.extend(equity or [])
+	if opening_balance and round(opening_balance,2) !=0:
+		unclosed ={
+			"account_name": "'" + _("Unclosed Fiscal Years Profit / Loss (Credit)") + "'",
+			"account": None,
+			"warn_if_negative": True,
+			"currency": frappe.db.get_value("Company", filters.company, "default_currency")
+		}
+		for period in period_list:
+			unclosed[period.key] = opening_balance
+			provisional_profit_loss[period.key] = provisional_profit_loss[period.key] - opening_balance
+		unclosed["total"]=opening_balance
+		data.append(unclosed)
+		
 	if provisional_profit_loss:
 		data.append(provisional_profit_loss)
+	data.append(total_credit)		
 
 	columns = get_columns(filters.periodicity, period_list, company=filters.company)
 	
@@ -34,14 +48,20 @@
 
 def get_provisional_profit_loss(asset, liability, equity, period_list, company):
 	if asset and (liability or equity):
-		total=0
+		total = total_row_total=0
+		currency = frappe.db.get_value("Company", company, "default_currency")
 		provisional_profit_loss = {
 			"account_name": "'" + _("Provisional Profit / Loss (Credit)") + "'",
 			"account": None,
 			"warn_if_negative": True,
-			"currency": frappe.db.get_value("Company", company, "default_currency")
+			"currency": currency
 		}
-
+		total_row = {
+			"account_name": "'" + _("Total (Credit)") + "'",
+			"account": None,
+			"warn_if_negative": True,
+			"currency": currency
+		}
 		has_value = False
 
 		for period in period_list:
@@ -52,15 +72,20 @@
 				effective_liability += flt(equity[-2].get(period.key))
 
 			provisional_profit_loss[period.key] = flt(asset[-2].get(period.key)) - effective_liability
+			total_row[period.key] = effective_liability + provisional_profit_loss[period.key]
 
 			if provisional_profit_loss[period.key]:
 				has_value = True
 
 			total += flt(provisional_profit_loss[period.key])
 			provisional_profit_loss["total"] = total
+			
+			total_row_total += flt(total_row[period.key])
+			total_row["total"] = total_row_total
 
 		if has_value:
-			return provisional_profit_loss
+			return provisional_profit_loss, total_row
+		return None,total_row
 
 def check_opening_balance(asset, liability, equity):
 	# Check if previous year balance sheet closed
@@ -73,7 +98,8 @@
 		opening_balance -= flt(equity[0].get("opening_balance", 0))
 
 	if opening_balance:
-		return _("Previous Financial Year is not closed")
+		return _("Previous Financial Year is not closed"),opening_balance
+	return None,None
 		
 def get_chart_data(columns, asset, liability, equity):
 	x_intervals = ['x'] + [d.get("label") for d in columns[2:]]
diff --git a/erpnext/accounts/report/budget_variance_report/budget_variance_report.py b/erpnext/accounts/report/budget_variance_report/budget_variance_report.py
index b67e2b6..0be0b3d 100644
--- a/erpnext/accounts/report/budget_variance_report/budget_variance_report.py
+++ b/erpnext/accounts/report/budget_variance_report/budget_variance_report.py
@@ -64,7 +64,7 @@
 	return frappe.db.sql("""
 			select b.cost_center, b.monthly_distribution, ba.account, ba.budget_amount
 			from `tabBudget` b, `tabBudget Account` ba
-			where b.name=ba.parent and b.fiscal_year=%s and b.company=%s
+			where b.name=ba.parent and b.docstatus = 1 and b.fiscal_year=%s and b.company=%s 
 		""", (filters.fiscal_year, filters.company), as_dict=True)
 
 #Get target distribution details of accounts of cost center
@@ -84,8 +84,9 @@
 	ac_details = frappe.db.sql("""select gl.account, gl.debit, gl.credit,
 		MONTHNAME(gl.posting_date) as month_name, b.cost_center
 		from `tabGL Entry` gl, `tabBudget Account` ba, `tabBudget` b
-		where 
+		where
 			b.name = ba.parent
+			and b.docstatus = 1
 			and ba.account=gl.account 
 			and gl.fiscal_year=%s 
 			and b.cost_center=%s
diff --git a/erpnext/accounts/report/cash_flow/cash_flow.py b/erpnext/accounts/report/cash_flow/cash_flow.py
index 24c5cd2..182878a 100644
--- a/erpnext/accounts/report/cash_flow/cash_flow.py
+++ b/erpnext/accounts/report/cash_flow/cash_flow.py
@@ -60,7 +60,6 @@
 	company_currency = frappe.db.get_value("Company", filters.company, "default_currency")
 	
 	for cash_flow_account in cash_flow_accounts:
-
 		section_data = []
 		data.append({
 			"account_name": cash_flow_account['section_header'], 
@@ -83,7 +82,8 @@
 			account_data = get_account_type_based_data(filters.company, 
 				account['account_type'], period_list, filters.accumulated_values)
 			account_data.update({
-				"account_name": account['label'], 
+				"account_name": account['label'],
+				"account": account['label'], 
 				"indent": 1,
 				"parent_account": cash_flow_account['section_header'],
 				"currency": company_currency
@@ -136,7 +136,7 @@
 def add_total_row_account(out, data, label, period_list, currency):
 	total_row = {
 		"account_name": "'" + _("{0}").format(label) + "'",
-		"account": None,
+		"account": "'" + _("{0}").format(label) + "'",
 		"currency": currency
 	}
 	for row in data:
diff --git a/erpnext/accounts/report/gross_profit/gross_profit.py b/erpnext/accounts/report/gross_profit/gross_profit.py
index a052821..3451238 100644
--- a/erpnext/accounts/report/gross_profit/gross_profit.py
+++ b/erpnext/accounts/report/gross_profit/gross_profit.py
@@ -17,7 +17,7 @@
 	source = gross_profit_data.grouped_data if filters.get("group_by") != "Invoice" else gross_profit_data.data
 
 	group_wise_columns = frappe._dict({
-		"invoice": ["parent", "customer", "posting_date","item_code", "item_name","item_group", "brand", "description", \
+		"invoice": ["parent", "customer", "customer_group", "posting_date","item_code", "item_name","item_group", "brand", "description", \
 			"warehouse", "qty", "base_rate", "buying_rate", "base_amount",
 			"buying_amount", "gross_profit", "gross_profit_percent", "project"],
 		"item_code": ["item_code", "item_name", "brand", "description", "qty", "base_rate",
diff --git a/erpnext/accounts/report/profit_and_loss_statement/profit_and_loss_statement.py b/erpnext/accounts/report/profit_and_loss_statement/profit_and_loss_statement.py
index 6b7f490..747eb43 100644
--- a/erpnext/accounts/report/profit_and_loss_statement/profit_and_loss_statement.py
+++ b/erpnext/accounts/report/profit_and_loss_statement/profit_and_loss_statement.py
@@ -34,7 +34,7 @@
 		total = 0
 		net_profit_loss = {
 			"account_name": "'" + _("Net Profit / Loss") + "'",
-			"account": None,
+			"account": "'" + _("Net Profit / Loss") + "'",
 			"warn_if_negative": True,
 			"currency": frappe.db.get_value("Company", company, "default_currency")
 		}
diff --git a/erpnext/accounts/report/profitability_analysis/profitability_analysis.js b/erpnext/accounts/report/profitability_analysis/profitability_analysis.js
index 4b9a1af..a25fa56 100644
--- a/erpnext/accounts/report/profitability_analysis/profitability_analysis.js
+++ b/erpnext/accounts/report/profitability_analysis/profitability_analysis.js
@@ -14,7 +14,7 @@
 			},
 			{
 				"fieldname": "based_on",
-				"label": __("Baed On"),
+				"label": __("Based On"),
 				"fieldtype": "Select",
 				"options": "Cost Center\nProject",
 				"default": "Cost Center",
diff --git a/erpnext/accounts/report/trial_balance/trial_balance.js b/erpnext/accounts/report/trial_balance/trial_balance.js
index 9943e5d..ff198e9 100644
--- a/erpnext/accounts/report/trial_balance/trial_balance.js
+++ b/erpnext/accounts/report/trial_balance/trial_balance.js
@@ -55,6 +55,11 @@
 				"label": __("Show zero values"),
 				"fieldtype": "Check"
 			},
+			{
+				"fieldname": "show_unclosed_fy_pl_balances",
+				"label": __("Show unclosed fiscal year's P&L balances"),
+				"fieldtype": "Check"
+			}
 		],
 		"formatter": erpnext.financial_statements.formatter,
 		"tree": true,
diff --git a/erpnext/accounts/report/trial_balance/trial_balance.py b/erpnext/accounts/report/trial_balance/trial_balance.py
index 5401902..7609d1d 100644
--- a/erpnext/accounts/report/trial_balance/trial_balance.py
+++ b/erpnext/accounts/report/trial_balance/trial_balance.py
@@ -87,8 +87,10 @@
 
 
 def get_rootwise_opening_balances(filters, report_type):
-	additional_conditions = " and posting_date >= %(year_start_date)s" \
-		if report_type == "Profit and Loss" else ""
+	additional_conditions = ""
+	if not filters.show_unclosed_fy_pl_balances:
+		additional_conditions = " and posting_date >= %(year_start_date)s" \
+			if report_type == "Profit and Loss" else ""
 
 	if not flt(filters.with_period_closing_entry):
 		additional_conditions += " and ifnull(voucher_type, '')!='Period Closing Voucher'"
diff --git a/erpnext/accounts/utils.py b/erpnext/accounts/utils.py
index eefdc1d..f3dc7ba 100644
--- a/erpnext/accounts/utils.py
+++ b/erpnext/accounts/utils.py
@@ -701,4 +701,4 @@
 
 	except frappe.DuplicateEntryError:
 		# already exists, due to a reinstall?
-		pass
+		pass
\ No newline at end of file
diff --git a/erpnext/buying/doctype/purchase_order/purchase_order.json b/erpnext/buying/doctype/purchase_order/purchase_order.json
index 923a3ed..8177b57 100644
--- a/erpnext/buying/doctype/purchase_order/purchase_order.json
+++ b/erpnext/buying/doctype/purchase_order/purchase_order.json
@@ -9,11 +9,13 @@
  "docstatus": 0, 
  "doctype": "DocType", 
  "document_type": "Document", 
+ "editable_grid": 0, 
  "fields": [
   {
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "supplier_section", 
    "fieldtype": "Section Break", 
    "hidden": 0, 
@@ -39,6 +41,7 @@
    "allow_on_submit": 1, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "default": "{supplier_name}", 
    "fieldname": "title", 
    "fieldtype": "Data", 
@@ -65,6 +68,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "naming_series", 
    "fieldtype": "Select", 
    "hidden": 0, 
@@ -92,6 +96,7 @@
    "allow_on_submit": 0, 
    "bold": 1, 
    "collapsible": 0, 
+   "columns": 0, 
    "description": "", 
    "fieldname": "supplier", 
    "fieldtype": "Link", 
@@ -120,6 +125,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "depends_on": "eval:doc.supplier && doc.docstatus===0 && (!(doc.items && doc.items.length) || (doc.items.length==1 && !doc.items[0].item_code))", 
    "fieldname": "get_items_from_open_material_requests", 
    "fieldtype": "Button", 
@@ -146,6 +152,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "default": "No", 
    "fieldname": "is_subcontracted", 
    "fieldtype": "Select", 
@@ -172,6 +179,7 @@
    "allow_on_submit": 0, 
    "bold": 1, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "supplier_name", 
    "fieldtype": "Data", 
    "hidden": 0, 
@@ -196,6 +204,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "column_break1", 
    "fieldtype": "Column Break", 
    "hidden": 0, 
@@ -222,6 +231,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "default": "Today", 
    "fieldname": "transaction_date", 
    "fieldtype": "Date", 
@@ -249,6 +259,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "amended_from", 
    "fieldtype": "Link", 
    "hidden": 0, 
@@ -276,6 +287,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "description": "", 
    "fieldname": "company", 
    "fieldtype": "Link", 
@@ -305,6 +317,7 @@
    "bold": 0, 
    "collapsible": 0, 
    "collapsible_depends_on": "", 
+   "columns": 0, 
    "fieldname": "drop_ship", 
    "fieldtype": "Section Break", 
    "hidden": 0, 
@@ -330,6 +343,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "depends_on": "", 
    "fieldname": "customer", 
    "fieldtype": "Link", 
@@ -357,6 +371,7 @@
    "allow_on_submit": 0, 
    "bold": 1, 
    "collapsible": 0, 
+   "columns": 0, 
    "depends_on": "", 
    "fieldname": "customer_name", 
    "fieldtype": "Data", 
@@ -383,6 +398,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "column_break_19", 
    "fieldtype": "Column Break", 
    "hidden": 0, 
@@ -407,6 +423,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "depends_on": "", 
    "fieldname": "customer_contact_person", 
    "fieldtype": "Link", 
@@ -434,6 +451,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "customer_contact_display", 
    "fieldtype": "Small Text", 
    "hidden": 1, 
@@ -459,6 +477,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "customer_contact_mobile", 
    "fieldtype": "Small Text", 
    "hidden": 1, 
@@ -484,6 +503,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "customer_contact_email", 
    "fieldtype": "Code", 
    "hidden": 1, 
@@ -510,6 +530,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 1, 
+   "columns": 0, 
    "fieldname": "section_addresses", 
    "fieldtype": "Section Break", 
    "hidden": 0, 
@@ -535,6 +556,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "supplier_address", 
    "fieldtype": "Link", 
    "hidden": 0, 
@@ -560,6 +582,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "contact_person", 
    "fieldtype": "Link", 
    "hidden": 0, 
@@ -585,6 +608,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "depends_on": "", 
    "fieldname": "address_display", 
    "fieldtype": "Small Text", 
@@ -610,6 +634,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "contact_display", 
    "fieldtype": "Small Text", 
    "hidden": 0, 
@@ -634,6 +659,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "contact_mobile", 
    "fieldtype": "Small Text", 
    "hidden": 0, 
@@ -658,6 +684,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "contact_email", 
    "fieldtype": "Small Text", 
    "hidden": 0, 
@@ -682,6 +709,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "col_break_address", 
    "fieldtype": "Column Break", 
    "hidden": 0, 
@@ -706,6 +734,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "depends_on": "", 
    "fieldname": "shipping_address", 
    "fieldtype": "Link", 
@@ -733,6 +762,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "shipping_address_display", 
    "fieldtype": "Small Text", 
    "hidden": 0, 
@@ -758,6 +788,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 1, 
+   "columns": 0, 
    "fieldname": "currency_and_price_list", 
    "fieldtype": "Section Break", 
    "hidden": 0, 
@@ -783,6 +814,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "currency", 
    "fieldtype": "Link", 
    "hidden": 0, 
@@ -810,6 +842,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "description": "", 
    "fieldname": "conversion_rate", 
    "fieldtype": "Float", 
@@ -838,6 +871,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "cb_price_list", 
    "fieldtype": "Column Break", 
    "hidden": 0, 
@@ -861,6 +895,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "buying_price_list", 
    "fieldtype": "Link", 
    "hidden": 0, 
@@ -886,6 +921,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "price_list_currency", 
    "fieldtype": "Link", 
    "hidden": 0, 
@@ -911,6 +947,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "plc_conversion_rate", 
    "fieldtype": "Float", 
    "hidden": 0, 
@@ -936,6 +973,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "ignore_pricing_rule", 
    "fieldtype": "Check", 
    "hidden": 0, 
@@ -960,6 +998,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "items_section", 
    "fieldtype": "Section Break", 
    "hidden": 0, 
@@ -986,6 +1025,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "items", 
    "fieldtype": "Table", 
    "hidden": 0, 
@@ -1013,6 +1053,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "depends_on": "eval:doc.docstatus===0 && (doc.items && doc.items.length)", 
    "fieldname": "get_last_purchase_rate", 
    "fieldtype": "Button", 
@@ -1039,6 +1080,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "sb_last_purchase", 
    "fieldtype": "Section Break", 
    "hidden": 0, 
@@ -1062,6 +1104,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "base_total", 
    "fieldtype": "Currency", 
    "hidden": 0, 
@@ -1088,6 +1131,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "base_net_total", 
    "fieldtype": "Currency", 
    "hidden": 0, 
@@ -1115,6 +1159,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "column_break_26", 
    "fieldtype": "Column Break", 
    "hidden": 0, 
@@ -1138,6 +1183,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "total", 
    "fieldtype": "Currency", 
    "hidden": 0, 
@@ -1164,6 +1210,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "net_total", 
    "fieldtype": "Currency", 
    "hidden": 0, 
@@ -1191,6 +1238,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "taxes_section", 
    "fieldtype": "Section Break", 
    "hidden": 0, 
@@ -1217,6 +1265,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "description": "", 
    "fieldname": "taxes_and_charges", 
    "fieldtype": "Link", 
@@ -1245,6 +1294,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "taxes", 
    "fieldtype": "Table", 
    "hidden": 0, 
@@ -1272,6 +1322,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "other_charges_calculation", 
    "fieldtype": "HTML", 
    "hidden": 0, 
@@ -1297,6 +1348,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "totals", 
    "fieldtype": "Section Break", 
    "hidden": 0, 
@@ -1323,6 +1375,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "base_taxes_and_charges_added", 
    "fieldtype": "Currency", 
    "hidden": 0, 
@@ -1350,6 +1403,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "base_taxes_and_charges_deducted", 
    "fieldtype": "Currency", 
    "hidden": 0, 
@@ -1377,6 +1431,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "base_total_taxes_and_charges", 
    "fieldtype": "Currency", 
    "hidden": 0, 
@@ -1404,6 +1459,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "column_break_39", 
    "fieldtype": "Column Break", 
    "hidden": 0, 
@@ -1428,6 +1484,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "taxes_and_charges_added", 
    "fieldtype": "Currency", 
    "hidden": 0, 
@@ -1455,6 +1512,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "taxes_and_charges_deducted", 
    "fieldtype": "Currency", 
    "hidden": 0, 
@@ -1482,6 +1540,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "total_taxes_and_charges", 
    "fieldtype": "Currency", 
    "hidden": 0, 
@@ -1509,6 +1568,7 @@
    "bold": 0, 
    "collapsible": 1, 
    "collapsible_depends_on": "discount_amount", 
+   "columns": 0, 
    "fieldname": "discount_section", 
    "fieldtype": "Section Break", 
    "hidden": 0, 
@@ -1534,6 +1594,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "default": "Grand Total", 
    "fieldname": "apply_discount_on", 
    "fieldtype": "Select", 
@@ -1561,6 +1622,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "base_discount_amount", 
    "fieldtype": "Currency", 
    "hidden": 0, 
@@ -1587,6 +1649,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "column_break_45", 
    "fieldtype": "Column Break", 
    "hidden": 0, 
@@ -1611,6 +1674,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "additional_discount_percentage", 
    "fieldtype": "Float", 
    "hidden": 0, 
@@ -1636,6 +1700,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "discount_amount", 
    "fieldtype": "Currency", 
    "hidden": 0, 
@@ -1662,6 +1727,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "totals_section", 
    "fieldtype": "Section Break", 
    "hidden": 0, 
@@ -1686,6 +1752,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "base_grand_total", 
    "fieldtype": "Currency", 
    "hidden": 0, 
@@ -1713,6 +1780,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "description": "In Words will be visible once you save the Purchase Order.", 
    "fieldname": "base_in_words", 
    "fieldtype": "Data", 
@@ -1740,6 +1808,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "base_rounded_total", 
    "fieldtype": "Currency", 
    "hidden": 0, 
@@ -1767,6 +1836,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "column_break4", 
    "fieldtype": "Column Break", 
    "hidden": 0, 
@@ -1791,6 +1861,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "grand_total", 
    "fieldtype": "Currency", 
    "hidden": 0, 
@@ -1818,6 +1889,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "in_words", 
    "fieldtype": "Data", 
    "hidden": 0, 
@@ -1844,6 +1916,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "advance_paid", 
    "fieldtype": "Currency", 
    "hidden": 0, 
@@ -1870,6 +1943,7 @@
    "bold": 0, 
    "collapsible": 1, 
    "collapsible_depends_on": "terms", 
+   "columns": 0, 
    "fieldname": "terms_section_break", 
    "fieldtype": "Section Break", 
    "hidden": 0, 
@@ -1896,6 +1970,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "tc_name", 
    "fieldtype": "Link", 
    "hidden": 0, 
@@ -1923,6 +1998,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "terms", 
    "fieldtype": "Text Editor", 
    "hidden": 0, 
@@ -1949,6 +2025,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 1, 
+   "columns": 0, 
    "fieldname": "more_info", 
    "fieldtype": "Section Break", 
    "hidden": 0, 
@@ -1974,6 +2051,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "default": "Draft", 
    "fieldname": "status", 
    "fieldtype": "Select", 
@@ -2002,6 +2080,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "ref_sq", 
    "fieldtype": "Data", 
    "hidden": 1, 
@@ -2028,6 +2107,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "party_account_currency", 
    "fieldtype": "Link", 
    "hidden": 1, 
@@ -2054,6 +2134,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "column_break_74", 
    "fieldtype": "Column Break", 
    "hidden": 0, 
@@ -2078,6 +2159,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "depends_on": "eval:!doc.__islocal", 
    "description": "", 
    "fieldname": "per_received", 
@@ -2106,6 +2188,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "depends_on": "eval:!doc.__islocal", 
    "description": "", 
    "fieldname": "per_billed", 
@@ -2134,6 +2217,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 1, 
+   "columns": 0, 
    "fieldname": "column_break5", 
    "fieldtype": "Section Break", 
    "hidden": 0, 
@@ -2161,6 +2245,7 @@
    "allow_on_submit": 1, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "letter_head", 
    "fieldtype": "Link", 
    "hidden": 0, 
@@ -2188,6 +2273,7 @@
    "allow_on_submit": 1, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "select_print_heading", 
    "fieldtype": "Link", 
    "hidden": 0, 
@@ -2215,6 +2301,59 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
+   "fieldname": "column_break_86", 
+   "fieldtype": "Column Break", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 0, 
+   "in_list_view": 0, 
+   "length": 0, 
+   "no_copy": 0, 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 0, 
+   "print_hide_if_no_value": 0, 
+   "read_only": 0, 
+   "report_hide": 0, 
+   "reqd": 0, 
+   "search_index": 0, 
+   "set_only_once": 0, 
+   "unique": 0
+  }, 
+  {
+   "allow_on_submit": 1, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
+   "description": "", 
+   "fieldname": "group_same_items", 
+   "fieldtype": "Check", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 0, 
+   "in_list_view": 0, 
+   "label": "Group same items", 
+   "length": 0, 
+   "no_copy": 0, 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 1, 
+   "print_hide_if_no_value": 0, 
+   "read_only": 0, 
+   "report_hide": 0, 
+   "reqd": 0, 
+   "search_index": 0, 
+   "set_only_once": 0, 
+   "unique": 0
+  }, 
+  {
+   "allow_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
    "default": "", 
    "fieldname": "language", 
    "fieldtype": "Data", 
@@ -2243,6 +2382,7 @@
    "bold": 0, 
    "collapsible": 1, 
    "collapsible_depends_on": "supplied_items", 
+   "columns": 0, 
    "description": "", 
    "fieldname": "raw_material_details", 
    "fieldtype": "Section Break", 
@@ -2270,6 +2410,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "supplied_items", 
    "fieldtype": "Table", 
    "hidden": 0, 
@@ -2298,6 +2439,7 @@
    "bold": 0, 
    "collapsible": 1, 
    "collapsible_depends_on": "is_recurring", 
+   "columns": 0, 
    "fieldname": "recurring_order", 
    "fieldtype": "Section Break", 
    "hidden": 0, 
@@ -2323,6 +2465,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "column_break", 
    "fieldtype": "Column Break", 
    "hidden": 0, 
@@ -2347,6 +2490,7 @@
    "allow_on_submit": 1, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "depends_on": "eval:doc.docstatus<2", 
    "description": "", 
    "fieldname": "is_recurring", 
@@ -2373,6 +2517,7 @@
    "allow_on_submit": 1, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "depends_on": "is_recurring", 
    "description": "", 
    "fieldname": "recurring_id", 
@@ -2400,6 +2545,7 @@
    "allow_on_submit": 1, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "depends_on": "eval:doc.is_recurring && doc.recurring_id === doc.name", 
    "description": "", 
    "fieldname": "recurring_type", 
@@ -2427,6 +2573,7 @@
    "allow_on_submit": 1, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "depends_on": "eval:doc.is_recurring && doc.recurring_id === doc.name", 
    "description": "", 
    "fieldname": "repeat_on_day_of_month", 
@@ -2453,6 +2600,7 @@
    "allow_on_submit": 1, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "depends_on": "eval:doc.is_recurring && doc.recurring_id === doc.name", 
    "description": "", 
    "fieldname": "end_date", 
@@ -2479,6 +2627,7 @@
    "allow_on_submit": 1, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "depends_on": "eval:doc.is_recurring && doc.recurring_id === doc.name", 
    "fieldname": "submit_on_creation", 
    "fieldtype": "Check", 
@@ -2505,6 +2654,7 @@
    "allow_on_submit": 1, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "depends_on": "eval:doc.is_recurring && doc.recurring_id === doc.name", 
    "description": "", 
    "fieldname": "notify_by_email", 
@@ -2532,6 +2682,7 @@
    "allow_on_submit": 1, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "depends_on": "eval:doc.is_recurring && doc.notify_by_email && doc.recurring_id === doc.name", 
    "description": "", 
    "fieldname": "notification_email_address", 
@@ -2559,6 +2710,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "depends_on": "eval:doc.is_recurring && doc.notify_by_email && doc.recurring_id === doc.name", 
    "fieldname": "recurring_print_format", 
    "fieldtype": "Link", 
@@ -2586,6 +2738,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "column_break83", 
    "fieldtype": "Column Break", 
    "hidden": 0, 
@@ -2610,6 +2763,7 @@
    "allow_on_submit": 1, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "depends_on": "is_recurring", 
    "description": "", 
    "fieldname": "from_date", 
@@ -2636,6 +2790,7 @@
    "allow_on_submit": 1, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "depends_on": "is_recurring", 
    "description": "", 
    "fieldname": "to_date", 
@@ -2662,6 +2817,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "depends_on": "is_recurring", 
    "description": "", 
    "fieldname": "next_date", 
@@ -2696,7 +2852,7 @@
  "issingle": 0, 
  "istable": 0, 
  "max_attachments": 0, 
- "modified": "2016-07-07 11:32:05.248626", 
+ "modified": "2016-10-20 03:07:24.683178", 
  "modified_by": "Administrator", 
  "module": "Buying", 
  "name": "Purchase Order", 
@@ -2712,6 +2868,7 @@
    "export": 0, 
    "if_owner": 0, 
    "import": 0, 
+   "is_custom": 0, 
    "permlevel": 0, 
    "print": 0, 
    "read": 1, 
@@ -2732,6 +2889,7 @@
    "export": 0, 
    "if_owner": 0, 
    "import": 0, 
+   "is_custom": 0, 
    "permlevel": 0, 
    "print": 1, 
    "read": 1, 
@@ -2752,6 +2910,7 @@
    "export": 0, 
    "if_owner": 0, 
    "import": 0, 
+   "is_custom": 0, 
    "permlevel": 0, 
    "print": 1, 
    "read": 1, 
@@ -2772,6 +2931,7 @@
    "export": 0, 
    "if_owner": 0, 
    "import": 0, 
+   "is_custom": 0, 
    "permlevel": 1, 
    "print": 0, 
    "read": 1, 
diff --git a/erpnext/buying/doctype/purchase_order/purchase_order.py b/erpnext/buying/doctype/purchase_order/purchase_order.py
index 79b22ae..54ca07b 100644
--- a/erpnext/buying/doctype/purchase_order/purchase_order.py
+++ b/erpnext/buying/doctype/purchase_order/purchase_order.py
@@ -155,6 +155,30 @@
 		if date_diff and date_diff[0][0]:
 			msgprint(_("{0} {1} has been modified. Please refresh.").format(self.doctype, self.name),
 				raise_exception=True)
+				
+	def before_print(self):
+		if self.get("group_same_items"):
+			
+			group_item_qty = {}
+			group_item_amount = {}
+
+			for item in self.items:
+				group_item_qty[item.item_code] = group_item_qty.get(item.item_code, 0) + item.qty
+				group_item_amount[item.item_code] = group_item_amount.get(item.item_code, 0) + item.amount
+				
+			duplicate_list = []
+			
+			for item in self.items:
+				if item.item_code in group_item_qty:
+					item.qty = group_item_qty[item.item_code]
+					item.amount = group_item_amount[item.item_code]
+					del group_item_qty[item.item_code]
+				else:
+					duplicate_list.append(item)
+					
+			for item in duplicate_list:
+				self.remove(item)
+				
 
 	def update_status(self, status):
 		self.check_modified_date()
@@ -302,6 +326,11 @@
 		target.amount = flt(obj.amount) - flt(obj.billed_amt)
 		target.base_amount = target.amount * flt(source_parent.conversion_rate)
 		target.qty = target.amount / flt(obj.rate) if (flt(obj.rate) and flt(obj.billed_amt)) else flt(obj.qty)
+		
+		item = frappe.db.get_value("Item", target.item_code, ["item_group", "buying_cost_center"], as_dict=1)
+		target.cost_center = frappe.db.get_value("Project", obj.project, "cost_center") \
+			or item.buying_cost_center \
+			or frappe.db.get_value("Item Group", item.item_group, "default_cost_center")
 
 	doc = get_mapped_doc("Purchase Order", source_name,	{
 		"Purchase Order": {
diff --git a/erpnext/buying/doctype/purchase_order/purchase_order_dashboard.py b/erpnext/buying/doctype/purchase_order/purchase_order_dashboard.py
index 61a9700..5e460df 100644
--- a/erpnext/buying/doctype/purchase_order/purchase_order_dashboard.py
+++ b/erpnext/buying/doctype/purchase_order/purchase_order_dashboard.py
@@ -1,24 +1,25 @@
 from frappe import _
 
-data = {
-	'fieldname': 'purchase_order',
-	'internal_links': {
-		'Material Request': ['items', 'material_request'],
-		'Supplier Quotation': ['items', 'supplier_quotation'],
-		'Project': ['project'],
-	},
-	'transactions': [
-		{
-			'label': _('Related'),
-			'items': ['Purchase Receipt', 'Purchase Invoice']
+def get_data():
+	return {
+		'fieldname': 'purchase_order',
+		'internal_links': {
+			'Material Request': ['items', 'material_request'],
+			'Supplier Quotation': ['items', 'supplier_quotation'],
+			'Project': ['project'],
 		},
-		{
-			'label': _('Reference'),
-			'items': ['Material Request', 'Supplier Quotation', 'Project']
-		},
-		{
-			'label': _('Sub-contracting'),
-			'items': ['Stock Entry']
-		},
-	]
-}
\ No newline at end of file
+		'transactions': [
+			{
+				'label': _('Related'),
+				'items': ['Purchase Receipt', 'Purchase Invoice']
+			},
+			{
+				'label': _('Reference'),
+				'items': ['Material Request', 'Supplier Quotation', 'Project']
+			},
+			{
+				'label': _('Sub-contracting'),
+				'items': ['Stock Entry']
+			},
+		]
+	}
\ No newline at end of file
diff --git a/erpnext/buying/doctype/purchase_order/test_purchase_order.py b/erpnext/buying/doctype/purchase_order/test_purchase_order.py
index c24bcdc..d4a0d07 100644
--- a/erpnext/buying/doctype/purchase_order/test_purchase_order.py
+++ b/erpnext/buying/doctype/purchase_order/test_purchase_order.py
@@ -110,6 +110,37 @@
 		po.update_status("Closed")
 
 		self.assertEquals(get_ordered_qty(item_code="_Test Item", warehouse="_Test Warehouse - _TC"), existing_ordered_qty)
+		
+	def test_group_same_items(self):
+		frappe.get_doc({
+			"doctype": "Purchase Order",
+			"company": "_Test Company",
+			"supplier" : "_Test Supplier",
+			"is_subcontracted" : "No",
+			"currency" : frappe.db.get_value("Company", "_Test Company", "default_currency"),
+			"conversion_factor" : 1,
+			"items" : get_same_items(),
+			"group_same_items": 1
+		}).insert()
+
+		
+def get_same_items():	
+	return [
+				{
+					"item_code": "_Test FG Item",
+					"warehouse": "_Test Warehouse - _TC",
+					"qty": 1,
+					"rate": 500,
+					"schedule_date": add_days(nowdate(), 1)
+				},
+				{
+					"item_code": "_Test FG Item",
+					"warehouse": "_Test Warehouse - _TC",
+					"qty": 4,
+					"rate": 500,
+					"schedule_date": add_days(nowdate(), 1)
+				}
+			]		
 
 def create_purchase_order(**args):
 	po = frappe.new_doc("Purchase Order")
diff --git a/erpnext/buying/doctype/request_for_quotation/request_for_quotation.json b/erpnext/buying/doctype/request_for_quotation/request_for_quotation.json
index e48e1dc..7525e44 100644
--- a/erpnext/buying/doctype/request_for_quotation/request_for_quotation.json
+++ b/erpnext/buying/doctype/request_for_quotation/request_for_quotation.json
@@ -15,6 +15,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "naming_series", 
    "fieldtype": "Select", 
    "hidden": 0, 
@@ -43,6 +44,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "description": "", 
    "fieldname": "company", 
    "fieldtype": "Link", 
@@ -72,6 +74,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "description": "For individual supplier", 
    "fieldname": "vendor", 
    "fieldtype": "Link", 
@@ -99,6 +102,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "column_break1", 
    "fieldtype": "Column Break", 
    "hidden": 0, 
@@ -126,6 +130,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "transaction_date", 
    "fieldtype": "Date", 
    "hidden": 0, 
@@ -153,6 +158,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "suppliers_section", 
    "fieldtype": "Section Break", 
    "hidden": 0, 
@@ -178,6 +184,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "suppliers", 
    "fieldtype": "Table", 
    "hidden": 0, 
@@ -204,6 +211,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "items_section", 
    "fieldtype": "Section Break", 
    "hidden": 0, 
@@ -231,6 +239,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "items", 
    "fieldtype": "Table", 
    "hidden": 0, 
@@ -259,6 +268,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "supplier_response_section", 
    "fieldtype": "Section Break", 
    "hidden": 0, 
@@ -284,6 +294,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "standard_reply", 
    "fieldtype": "Link", 
    "hidden": 0, 
@@ -310,6 +321,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "message_for_supplier", 
    "fieldtype": "Text Editor", 
    "hidden": 0, 
@@ -336,6 +348,7 @@
    "bold": 0, 
    "collapsible": 1, 
    "collapsible_depends_on": "terms", 
+   "columns": 0, 
    "fieldname": "terms_section_break", 
    "fieldtype": "Section Break", 
    "hidden": 0, 
@@ -363,6 +376,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "tc_name", 
    "fieldtype": "Link", 
    "hidden": 0, 
@@ -391,6 +405,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "terms", 
    "fieldtype": "Text Editor", 
    "hidden": 0, 
@@ -418,6 +433,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 1, 
+   "columns": 0, 
    "fieldname": "printing_settings", 
    "fieldtype": "Section Break", 
    "hidden": 0, 
@@ -443,6 +459,7 @@
    "allow_on_submit": 1, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "select_print_heading", 
    "fieldtype": "Link", 
    "hidden": 0, 
@@ -471,6 +488,7 @@
    "allow_on_submit": 1, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "letter_head", 
    "fieldtype": "Link", 
    "hidden": 0, 
@@ -499,6 +517,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 1, 
+   "columns": 0, 
    "fieldname": "more_info", 
    "fieldtype": "Section Break", 
    "hidden": 0, 
@@ -526,6 +545,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "status", 
    "fieldtype": "Select", 
    "hidden": 0, 
@@ -554,6 +574,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "fiscal_year", 
    "fieldtype": "Link", 
    "hidden": 0, 
@@ -582,6 +603,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "column_break3", 
    "fieldtype": "Column Break", 
    "hidden": 0, 
@@ -606,6 +628,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "amended_from", 
    "fieldtype": "Link", 
    "hidden": 0, 
@@ -639,8 +662,8 @@
  "issingle": 0, 
  "istable": 0, 
  "max_attachments": 0, 
- "modified": "2016-08-01 08:45:39.777405", 
- "modified_by": "Administrator", 
+ "modified": "2016-09-29 11:56:57.123429", 
+ "modified_by": "neil@frappe.io", 
  "module": "Buying", 
  "name": "Request for Quotation", 
  "name_case": "", 
@@ -732,26 +755,6 @@
    "cancel": 0, 
    "create": 0, 
    "delete": 0, 
-   "email": 1, 
-   "export": 0, 
-   "if_owner": 0, 
-   "import": 0, 
-   "permlevel": 0, 
-   "print": 1, 
-   "read": 1, 
-   "report": 1, 
-   "role": "Supplier", 
-   "set_user_permissions": 0, 
-   "share": 0, 
-   "submit": 0, 
-   "write": 0
-  }, 
-  {
-   "amend": 0, 
-   "apply_user_permissions": 0, 
-   "cancel": 0, 
-   "create": 0, 
-   "delete": 0, 
    "email": 0, 
    "export": 0, 
    "if_owner": 0, 
diff --git a/erpnext/buying/doctype/request_for_quotation/request_for_quotation.py b/erpnext/buying/doctype/request_for_quotation/request_for_quotation.py
index 482a2ae..78af1ef 100644
--- a/erpnext/buying/doctype/request_for_quotation/request_for_quotation.py
+++ b/erpnext/buying/doctype/request_for_quotation/request_for_quotation.py
@@ -192,8 +192,6 @@
 	if isinstance(doc, basestring):
 		doc = json.loads(doc)
 
-	validate_duplicate_supplier_quotation(doc)
-
 	try:
 		sq_doc = frappe.get_doc({
 			"doctype": "Supplier Quotation",
@@ -245,13 +243,3 @@
 		args = doc.get('suppliers')[cint(supplier_idx) - 1]
 		doc.update_supplier_part_no(args)
 		return doc
-
-@frappe.whitelist()
-def validate_duplicate_supplier_quotation(args):
-	data = frappe.db.sql("""select sq.name as name from `tabSupplier Quotation` sq, 
-		`tabSupplier Quotation Item` sqi where sqi.parent = sq.name and sq.supplier = %(supplier)s 
-		and sqi.request_for_quotation = %(rfq)s and sq.docstatus < 2""",
-		{'supplier': args.get('supplier'), 'rfq': args.get('name')}, as_dict=True)
-
-	if data and data[0] and data[0].name:
-		frappe.throw(_("Already supplier quotation has created"))
diff --git a/erpnext/buying/doctype/request_for_quotation/request_for_quotation_dashboard.py b/erpnext/buying/doctype/request_for_quotation/request_for_quotation_dashboard.py
index 4bb4d76..ba09d3f 100644
--- a/erpnext/buying/doctype/request_for_quotation/request_for_quotation_dashboard.py
+++ b/erpnext/buying/doctype/request_for_quotation/request_for_quotation_dashboard.py
@@ -1,12 +1,13 @@
 from frappe import _
 
-data = {
-	'docstatus': 1,
-	'fieldname': 'request_for_quotation',
-	'transactions': [
-		{
-			'label': _('Related'),
-			'items': ['Supplier Quotation']
-		},
-	]
-}
\ No newline at end of file
+def get_data():
+	return {
+		'docstatus': 1,
+		'fieldname': 'request_for_quotation',
+		'transactions': [
+			{
+				'label': _('Related'),
+				'items': ['Supplier Quotation']
+			},
+		]
+	}
\ No newline at end of file
diff --git a/erpnext/buying/doctype/supplier/supplier_dashboard.py b/erpnext/buying/doctype/supplier/supplier_dashboard.py
index ab123e2..4f01f58 100644
--- a/erpnext/buying/doctype/supplier/supplier_dashboard.py
+++ b/erpnext/buying/doctype/supplier/supplier_dashboard.py
@@ -1,17 +1,18 @@
 from frappe import _
 
-data = {
-	'heatmap': True,
-	'heatmap_message': _('This is based on transactions against this Supplier. See timeline below for details'),
-	'fieldname': 'supplier',
-	'transactions': [
-		{
-			'label': _('Procurement'),
-			'items': ['Request for Quotation', 'Supplier Quotation']
-		},
-		{
-			'label': _('Orders'),
-			'items': ['Purchase Order', 'Purchase Receipt', 'Purchase Invoice']
-		}
-	]
-}
\ No newline at end of file
+def get_data():
+	return {
+		'heatmap': True,
+		'heatmap_message': _('This is based on transactions against this Supplier. See timeline below for details'),
+		'fieldname': 'supplier',
+		'transactions': [
+			{
+				'label': _('Procurement'),
+				'items': ['Request for Quotation', 'Supplier Quotation']
+			},
+			{
+				'label': _('Orders'),
+				'items': ['Purchase Order', 'Purchase Receipt', 'Purchase Invoice']
+			}
+		]
+	}
\ No newline at end of file
diff --git a/erpnext/buying/doctype/supplier_quotation/supplier_quotation_dashboard.py b/erpnext/buying/doctype/supplier_quotation/supplier_quotation_dashboard.py
index 6c8ae7c..80f946e 100644
--- a/erpnext/buying/doctype/supplier_quotation/supplier_quotation_dashboard.py
+++ b/erpnext/buying/doctype/supplier_quotation/supplier_quotation_dashboard.py
@@ -1,20 +1,21 @@
 from frappe import _
 
-data = {
-	'fieldname': 'supplier_quotation',
-	'internal_links': {
-		'Material Request': ['items', 'material_request'],
-		'Request for Quotation': ['items', 'request_for_quotation'],
-		'Project': ['items', 'project'],
-	},
-	'transactions': [
-		{
-			'label': _('Related'),
-			'items': ['Purchase Order']
+def get_data():
+	return {
+		'fieldname': 'supplier_quotation',
+		'internal_links': {
+			'Material Request': ['items', 'material_request'],
+			'Request for Quotation': ['items', 'request_for_quotation'],
+			'Project': ['items', 'project'],
 		},
-		{
-			'label': _('Reference'),
-			'items': ['Material Request', 'Request for Quotation', 'Project']
-		},
-	]
-}
+		'transactions': [
+			{
+				'label': _('Related'),
+				'items': ['Purchase Order']
+			},
+			{
+				'label': _('Reference'),
+				'items': ['Material Request', 'Request for Quotation', 'Project']
+			},
+		]
+	}
diff --git a/erpnext/config/projects.py b/erpnext/config/projects.py
index e6c9578..87174a4 100644
--- a/erpnext/config/projects.py
+++ b/erpnext/config/projects.py
@@ -19,7 +19,7 @@
 				},
 				{
 					"type": "report",
-					"route": "Gantt/Task",
+					"route": "List/Task/Gantt",
 					"doctype": "Task",
 					"name": "Gantt Chart",
 					"description": _("Gantt chart of all tasks.")
diff --git a/erpnext/controllers/accounts_controller.py b/erpnext/controllers/accounts_controller.py
index 8927da7..3d2f16b 100644
--- a/erpnext/controllers/accounts_controller.py
+++ b/erpnext/controllers/accounts_controller.py
@@ -26,6 +26,9 @@
 
 		return self.__company_currency
 
+	def onload(self):
+		self.get("__onload").make_payment_via_journal_entry = frappe.db.get_single_value('Accounts Settings', 'make_payment_via_journal_entry')
+
 	def validate(self):
 		if self.get("_action") and self._action != "update_after_submit":
 			self.set_missing_values(for_validate=True)
@@ -144,7 +147,7 @@
 				self.conversion_rate = get_exchange_rate(self.currency,
 					self.company_currency)
 
-	def set_missing_item_details(self):
+	def set_missing_item_details(self, for_validate=False):
 		"""set missing item values"""
 		from erpnext.stock.get_item_details import get_item_details
 
@@ -196,7 +199,7 @@
 								(1.0 - (flt(item.discount_percentage) / 100.0)), item.precision("rate"))
 
 			if self.doctype == "Purchase Invoice":
-				self.set_expense_account()
+				self.set_expense_account(for_validate)
 
 	def set_taxes(self):
 		if not self.meta.get_field("taxes"):
diff --git a/erpnext/controllers/buying_controller.py b/erpnext/controllers/buying_controller.py
index f7181d7..865514b 100644
--- a/erpnext/controllers/buying_controller.py
+++ b/erpnext/controllers/buying_controller.py
@@ -62,7 +62,7 @@
 		if getattr(self, "supplier", None):
 			self.update_if_missing(get_party_details(self.supplier, party_type="Supplier", ignore_permissions=self.flags.ignore_permissions))
 
-		self.set_missing_item_details()
+		self.set_missing_item_details(for_validate)
 
 	def set_supplier_from_item_default(self):
 		if self.meta.get_field("supplier") and not self.supplier:
diff --git a/erpnext/controllers/selling_controller.py b/erpnext/controllers/selling_controller.py
index b9b94f5..68e9155 100644
--- a/erpnext/controllers/selling_controller.py
+++ b/erpnext/controllers/selling_controller.py
@@ -8,6 +8,7 @@
 from frappe import _, throw
 from erpnext.stock.get_item_details import get_bin_details
 from erpnext.stock.utils import get_incoming_rate
+from erpnext.stock.stock_ledger import get_valuation_rate
 
 from erpnext.controllers.stock_controller import StockController
 
@@ -23,6 +24,7 @@
 			self.grand_total)
 
 	def onload(self):
+		super(SellingController, self).onload()
 		if self.doctype in ("Sales Order", "Delivery Note", "Sales Invoice"):
 			for item in self.get("items"):
 				item.update(get_bin_details(item.item_code,
@@ -31,6 +33,7 @@
 	def validate(self):
 		super(SellingController, self).validate()
 		self.validate_max_discount()
+		self.validate_selling_price()
 		check_active_sales_items(self)
 
 	def set_missing_values(self, for_validate=False):
@@ -160,6 +163,29 @@
 			if discount and flt(d.discount_percentage) > discount:
 				frappe.throw(_("Maxiumm discount for Item {0} is {1}%").format(d.item_code, discount))
 
+	def validate_selling_price(self):
+		if not frappe.db.get_single_value("Selling Settings", "validate_selling_price"):
+			return
+
+		for it in self.get("items"):
+			last_purchase_rate, is_stock_item = frappe.db.get_value("Item", it.name, ["last_purchase_rate", "is_stock_item"])
+
+			if flt(it.base_rate) < flt(last_purchase_rate):
+				throw(it.name, last_purchase_rate, "last purchase rate")
+
+			last_valuation_rate = frappe.db.sql("""
+				SELECT valuation_rate FROM `tabStock Ledger Entry` WHERE item_code = %s
+				AND warehouse = %s AND valuation_rate > 0
+				ORDER BY posting_date DESC, posting_time DESC, name DESC LIMIT 1
+				""", (it.item_code, it.warehouse))
+
+			if is_stock_item and flt(it.base_rate) < flt(last_valuation_rate):
+				throw_message(it.name, last_valuation_rate, "valuation rate")
+
+		def throw_message(item_name, rate, ref_rate_field):
+			frappe.throw(_("""Selling price for item {0} is lower than its {1}. Selling price should be atleast {2}""")
+				.format(item_name, ref_rate_field, rate))
+
 	def get_item_list(self):
 		il = []
 		for d in self.get("items"):
@@ -229,7 +255,7 @@
 				status = frappe.db.get_value("Sales Order", d.get(ref_fieldname), "status")
 				if status == "Closed":
 					frappe.throw(_("Sales Order {0} is {1}").format(d.get(ref_fieldname), status))
-					
+
 	def update_reserved_qty(self):
 		so_map = {}
 		for d in self.get("items"):
@@ -309,7 +335,7 @@
 			item = frappe.db.sql("""select docstatus,
 				income_account from tabItem where name = %s""",
 				d.item_code, as_dict=True)[0]
-                
+
 			if getattr(d, "income_account", None) and not item.income_account:
 				frappe.db.set_value("Item", d.item_code, "income_account",
 					d.income_account)
diff --git a/erpnext/controllers/status_updater.py b/erpnext/controllers/status_updater.py
index 7be6acd..157c385 100644
--- a/erpnext/controllers/status_updater.py
+++ b/erpnext/controllers/status_updater.py
@@ -301,12 +301,7 @@
 			ref_doc = frappe.get_doc(ref_dt, ref_dn)
 
 			ref_doc.db_set("per_billed", per_billed)
-
-			if frappe.get_meta(ref_dt).get_field("billing_status"):
-				if per_billed < 0.001: billing_status = "Not Billed"
-				elif per_billed >= 99.99: billing_status = "Fully Billed"
-				else: billing_status = "Partly Billed"
-				ref_doc.db_set('billing_status', billing_status)
+			ref_doc.set_status(update=True)
 
 def get_tolerance_for(item_code, item_tolerance={}, global_tolerance=None):
 	"""
diff --git a/erpnext/controllers/stock_controller.py b/erpnext/controllers/stock_controller.py
index 3f25e02..aa84929 100644
--- a/erpnext/controllers/stock_controller.py
+++ b/erpnext/controllers/stock_controller.py
@@ -276,12 +276,18 @@
 def compare_existing_and_expected_gle(existing_gle, expected_gle):
 	matched = True
 	for entry in expected_gle:
+		account_existed = False
 		for e in existing_gle:
-			if entry.account==e.account and entry.against_account==e.against_account \
-				and (not entry.cost_center or not e.cost_center or entry.cost_center==e.cost_center) \
-				and (entry.debit != e.debit or entry.credit != e.credit):
-					matched = False
-					break
+			if entry.account == e.account:
+				account_existed = True
+			if entry.account == e.account and entry.against_account == e.against_account \
+					and (not entry.cost_center or not e.cost_center or entry.cost_center == e.cost_center) \
+					and (entry.debit != e.debit or entry.credit != e.credit):
+				matched = False
+				break
+		if not account_existed:
+			matched = False
+			break
 	return matched
 
 def get_future_stock_vouchers(posting_date, posting_time, for_warehouses=None, for_items=None):
diff --git a/erpnext/controllers/taxes_and_totals.py b/erpnext/controllers/taxes_and_totals.py
index d8b5e2e..2369143 100644
--- a/erpnext/controllers/taxes_and_totals.py
+++ b/erpnext/controllers/taxes_and_totals.py
@@ -338,7 +338,7 @@
 			tax.item_wise_tax_detail = json.dumps(tax.item_wise_tax_detail, separators=(',', ':'))
 
 	def set_discount_amount(self):
-		if not self.doc.discount_amount and self.doc.additional_discount_percentage:
+		if self.doc.additional_discount_percentage:
 			self.doc.discount_amount = flt(flt(self.doc.get(scrub(self.doc.apply_discount_on)))
 				* self.doc.additional_discount_percentage / 100, self.doc.precision("discount_amount"))
 
diff --git a/erpnext/controllers/trends.py b/erpnext/controllers/trends.py
index 080d749..d991c15 100644
--- a/erpnext/controllers/trends.py
+++ b/erpnext/controllers/trends.py
@@ -49,10 +49,10 @@
 		posting_date = 't1.posting_date'
 
 	if conditions["based_on_select"] in ["t1.project,", "t2.project,"]:
-		cond = 'and '+ conditions["based_on_select"][:-1] +' IS Not NULL'
+		cond = ' and '+ conditions["based_on_select"][:-1] +' IS Not NULL'
 	
 	if conditions.get('trans') in ['Sales Order', 'Purchase Order']:
-		cond += "and t1.status != 'Closed'"
+		cond += " and t1.status != 'Closed'"
 
 	year_start_date, year_end_date = frappe.db.get_value("Fiscal Year",
 		filters.get('fiscal_year'), ["year_start_date", "year_end_date"])
diff --git a/erpnext/crm/doctype/opportunity/opportunity_dashboard.py b/erpnext/crm/doctype/opportunity/opportunity_dashboard.py
index 782acfd..5fc8302 100644
--- a/erpnext/crm/doctype/opportunity/opportunity_dashboard.py
+++ b/erpnext/crm/doctype/opportunity/opportunity_dashboard.py
@@ -1,14 +1,12 @@
 from frappe import _
 
-data = {
-	'fieldname': 'opportunity',
-	'non_standard_fieldnames': {
-		'Quotation': 'prevdoc_docname'
-	},
-	'transactions': [
-		{
-			'label': _('Related'),
-			'items': ['Quotation', 'Supplier Quotation']
-		},
-	]
-}
\ No newline at end of file
+def get_data():
+	return {
+		'fieldname': 'prevdoc_docname',
+		'transactions': [
+			{
+				'label': _('Related'),
+				'items': ['Quotation', 'Supplier Quotation']
+			},
+		]
+	}
\ No newline at end of file
diff --git a/erpnext/demo/setup/setup_data.py b/erpnext/demo/setup/setup_data.py
index d279a64..f25bbc3 100644
--- a/erpnext/demo/setup/setup_data.py
+++ b/erpnext/demo/setup/setup_data.py
@@ -130,7 +130,7 @@
 		ss.from_date = e.date_of_joining if (e.date_of_joining
 			and e.date_of_joining > f.year_start_date) else f.year_start_date
 		ss.to_date = f.year_end_date
-
+		ss.payment_account = frappe.get_value('Account', {'account_type': 'Cash', 'company': erpnext.get_default_company(),'is_group':0}, "name")
 	ss.append('earnings', {
 		'salary_component': 'Basic',
 		"abbr":'B',
diff --git a/erpnext/demo/user/hr.py b/erpnext/demo/user/hr.py
index 2b80afb..2686987 100644
--- a/erpnext/demo/user/hr.py
+++ b/erpnext/demo/user/hr.py
@@ -1,5 +1,5 @@
 from __future__ import unicode_literals
-import frappe
+import frappe, erpnext
 import random
 from frappe.utils import random_string, add_days, cint
 from erpnext.projects.doctype.timesheet.test_timesheet import make_timesheet
@@ -24,18 +24,14 @@
 		process_payroll.company = frappe.flags.company
 		process_payroll.month = prev_month
 		process_payroll.fiscal_year = year
-		process_payroll.create_sal_slip()
+		process_payroll.from_date = frappe.flags.current_date
+		process_payroll.to_date = add_days(frappe.flags.current_date, random.randint(0, 30))
+		process_payroll.reference_number = "DemoRef23"
+		process_payroll.reference_date = frappe.flags.current_date
+		process_payroll.payment_account = frappe.get_value('Account', {'account_type': 'Cash', 'company': erpnext.get_default_company(),'is_group':0}, "name")
 		process_payroll.submit_salary_slip()
-		r = process_payroll.make_journal_entry(frappe.get_value('Account',
-			{'account_name': 'Salary'}))
-
-		journal_entry = frappe.get_doc(r)
-		journal_entry.cheque_no = random_string(10)
-		journal_entry.cheque_date = frappe.flags.current_date
-		journal_entry.posting_date = frappe.flags.current_date
-		journal_entry.insert()
-		journal_entry.submit()
-	
+		process_payroll.make_journal_entry()
+		
 	if frappe.db.get_global('demo_hr_user'):
 		make_timesheet_records()
 	
diff --git a/erpnext/docs/assets/img/accounts/account-settings.png b/erpnext/docs/assets/img/accounts/account-settings.png
index 943aa3d..dfe2abe 100644
--- a/erpnext/docs/assets/img/accounts/account-settings.png
+++ b/erpnext/docs/assets/img/accounts/account-settings.png
Binary files differ
diff --git a/erpnext/docs/assets/img/accounts/fiscal-year.png b/erpnext/docs/assets/img/accounts/fiscal-year.png
index 2dbf0a2..c320a5c 100644
--- a/erpnext/docs/assets/img/accounts/fiscal-year.png
+++ b/erpnext/docs/assets/img/accounts/fiscal-year.png
Binary files differ
diff --git a/erpnext/docs/assets/img/accounts/journal-entry.png b/erpnext/docs/assets/img/accounts/journal-entry.png
index d4a4e21..c6a2a64 100644
--- a/erpnext/docs/assets/img/accounts/journal-entry.png
+++ b/erpnext/docs/assets/img/accounts/journal-entry.png
Binary files differ
diff --git a/erpnext/docs/assets/img/accounts/pos-sales-invoice.png b/erpnext/docs/assets/img/accounts/pos-sales-invoice.png
new file mode 100644
index 0000000..3a115ed
--- /dev/null
+++ b/erpnext/docs/assets/img/accounts/pos-sales-invoice.png
Binary files differ
diff --git a/erpnext/docs/assets/img/buying/material-request-flowchart.png b/erpnext/docs/assets/img/buying/material-request-flowchart.png
new file mode 100644
index 0000000..8ed0e39
--- /dev/null
+++ b/erpnext/docs/assets/img/buying/material-request-flowchart.png
Binary files differ
diff --git a/erpnext/docs/assets/img/buying/material-request.png b/erpnext/docs/assets/img/buying/material-request.png
index 34005b2..2bb4c88 100644
--- a/erpnext/docs/assets/img/buying/material-request.png
+++ b/erpnext/docs/assets/img/buying/material-request.png
Binary files differ
diff --git a/erpnext/docs/assets/img/fleet-management/__init__.py b/erpnext/docs/assets/img/fleet-management/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/erpnext/docs/assets/img/fleet-management/__init__.py
diff --git a/erpnext/docs/assets/img/fleet-management/expense-claim-3.1.png b/erpnext/docs/assets/img/fleet-management/expense-claim-3.1.png
new file mode 100644
index 0000000..6aa4d69
--- /dev/null
+++ b/erpnext/docs/assets/img/fleet-management/expense-claim-3.1.png
Binary files differ
diff --git a/erpnext/docs/assets/img/fleet-management/expense-claim-3.2.png b/erpnext/docs/assets/img/fleet-management/expense-claim-3.2.png
new file mode 100644
index 0000000..9376988
--- /dev/null
+++ b/erpnext/docs/assets/img/fleet-management/expense-claim-3.2.png
Binary files differ
diff --git a/erpnext/docs/assets/img/fleet-management/vehicle-1.1.png b/erpnext/docs/assets/img/fleet-management/vehicle-1.1.png
new file mode 100644
index 0000000..b40912d
--- /dev/null
+++ b/erpnext/docs/assets/img/fleet-management/vehicle-1.1.png
Binary files differ
diff --git a/erpnext/docs/assets/img/fleet-management/vehicle-1.2.png b/erpnext/docs/assets/img/fleet-management/vehicle-1.2.png
new file mode 100644
index 0000000..8a8695e
--- /dev/null
+++ b/erpnext/docs/assets/img/fleet-management/vehicle-1.2.png
Binary files differ
diff --git a/erpnext/docs/assets/img/fleet-management/vehicle-1.3.png b/erpnext/docs/assets/img/fleet-management/vehicle-1.3.png
new file mode 100644
index 0000000..8110454
--- /dev/null
+++ b/erpnext/docs/assets/img/fleet-management/vehicle-1.3.png
Binary files differ
diff --git a/erpnext/docs/assets/img/fleet-management/vehicle-expenses.png b/erpnext/docs/assets/img/fleet-management/vehicle-expenses.png
new file mode 100644
index 0000000..166717c
--- /dev/null
+++ b/erpnext/docs/assets/img/fleet-management/vehicle-expenses.png
Binary files differ
diff --git a/erpnext/docs/assets/img/fleet-management/vehicle-log-2.1.png b/erpnext/docs/assets/img/fleet-management/vehicle-log-2.1.png
new file mode 100644
index 0000000..f859b42
--- /dev/null
+++ b/erpnext/docs/assets/img/fleet-management/vehicle-log-2.1.png
Binary files differ
diff --git a/erpnext/docs/assets/img/fleet-management/vehicle-log-2.2.png b/erpnext/docs/assets/img/fleet-management/vehicle-log-2.2.png
new file mode 100644
index 0000000..12d3187
--- /dev/null
+++ b/erpnext/docs/assets/img/fleet-management/vehicle-log-2.2.png
Binary files differ
diff --git a/erpnext/docs/assets/img/human-resources/bank-entry.png b/erpnext/docs/assets/img/human-resources/bank-entry.png
new file mode 100644
index 0000000..b870bc5
--- /dev/null
+++ b/erpnext/docs/assets/img/human-resources/bank-entry.png
Binary files differ
diff --git a/erpnext/docs/assets/img/human-resources/process-payroll.png b/erpnext/docs/assets/img/human-resources/process-payroll.png
index ebbd9ae..2e2fbed 100644
--- a/erpnext/docs/assets/img/human-resources/process-payroll.png
+++ b/erpnext/docs/assets/img/human-resources/process-payroll.png
Binary files differ
diff --git a/erpnext/docs/assets/img/human-resources/salary-structure-account.png b/erpnext/docs/assets/img/human-resources/salary-structure-account.png
new file mode 100644
index 0000000..bd37ee0
--- /dev/null
+++ b/erpnext/docs/assets/img/human-resources/salary-structure-account.png
Binary files differ
diff --git a/erpnext/docs/assets/img/human-resources/salary-structure.png b/erpnext/docs/assets/img/human-resources/salary-structure.png
index a135092..71f6013 100644
--- a/erpnext/docs/assets/img/human-resources/salary-structure.png
+++ b/erpnext/docs/assets/img/human-resources/salary-structure.png
Binary files differ
diff --git a/erpnext/docs/user/manual/en/accounts/index.txt b/erpnext/docs/user/manual/en/accounts/index.txt
index d7c405a..6ba9337 100644
--- a/erpnext/docs/user/manual/en/accounts/index.txt
+++ b/erpnext/docs/user/manual/en/accounts/index.txt
@@ -3,6 +3,7 @@
 sales-invoice
 point-of-sale-pos-invoice
 purchase-invoice
+payments
 journal-entry
 payment-entry
 multi-currency-accounting
diff --git a/erpnext/docs/user/manual/en/accounts/managing-fixed-assets.md b/erpnext/docs/user/manual/en/accounts/managing-fixed-assets.md
index f8dbe1d..8eefe7f 100644
--- a/erpnext/docs/user/manual/en/accounts/managing-fixed-assets.md
+++ b/erpnext/docs/user/manual/en/accounts/managing-fixed-assets.md
@@ -62,7 +62,7 @@
 On submission of the invoice, the "Fixed Asset Account" will be debited and payable account will be credited. It also updates purchase date, supplier and Purchase Invoice no. in the Asset master.
 
 
-## Sale an Asset
+## Sell an Asset
 
 To sale an asset, open the asset record and create a Sales Invoice by clicking on "Sale Asset". On submission of the Sales Invoice, following entries will take place:
 
diff --git a/erpnext/docs/user/manual/en/accounts/payments.md b/erpnext/docs/user/manual/en/accounts/payments.md
new file mode 100644
index 0000000..7e5aab3
--- /dev/null
+++ b/erpnext/docs/user/manual/en/accounts/payments.md
@@ -0,0 +1,48 @@
+Payment can be made against following transactions.
+
+  1. Sales Invoice.
+  2. Purchase Invoice.
+  3. Sales Order (Advance Payment)
+  4. Purchase Order (Advance Payment)
+  
+In ERPNext, there is two options through which user can capture the payment
+
+  1. Payment Entry(Default).
+  2. Journal Entry.
+  
+## Payment Entry
+
+####Step 1: Make Payment
+
+On submitting a document against which Payment Entry can be made, you will find Make Payment button.
+
+<img class="screenshot" alt="Making Payment" src="{{docs_base_url}}/assets/img/accounts/payment-entry-1.png">
+
+####Step 2: Payment Entry
+
+<img class="screenshot" alt="Making Payment" src="{{docs_base_url}}/assets/img/accounts/payment-entry-9.png">
+
+For more details about payment entry [check here.](https://frappe.github.io/erpnext/user/manual/en/accounts/payment-entry)
+
+## Journal Entry
+
+To make paymant using journal entry, check below steps
+
+####Step 1: Activate Payment via Journal Entry
+
+Goto Accounts Settings > checked Make Payment via Journal Entry
+
+<img class="screenshot" alt="Making Payment" src="{{docs_base_url}}/assets/img/accounts/account-settings.png">
+
+####Step 2: Make Payment
+
+On submitting a document against which Journal Entry can be made, you will find Make Payment button.
+
+<img class="screenshot" alt="Making Payment" src="{{docs_base_url}}/assets/img/accounts/payment-entry-1.png">
+
+####Step 3: Journal Entry
+
+Save and submit the journal entry to record the payament against the invoice
+<img class="screenshot" alt="Making Payment" src="{{docs_base_url}}/assets/img/accounts/journal-entry.png">
+
+For more details about journal entry [check here.](https://frappe.github.io/erpnext/user/manual/en/accounts/journal-entry)
\ No newline at end of file
diff --git a/erpnext/docs/user/manual/en/accounts/sales-invoice.md b/erpnext/docs/user/manual/en/accounts/sales-invoice.md
index f9a453e..fb132e7 100644
--- a/erpnext/docs/user/manual/en/accounts/sales-invoice.md
+++ b/erpnext/docs/user/manual/en/accounts/sales-invoice.md
@@ -2,9 +2,9 @@
 
 You can create a Sales Invoice directly from
 
-> Accounting > Documents > Sales Invoice > New Sales Invoice
+> Accounts > Billing > Sales Invoice > New Sales Invoice
 
-or Click on Make Invoice at the right hand corner of the Delivery Note.
+or you can Make a new Sales Invoice after you submit the Delivery Note.
 
 <img class="screenshot" alt="Sales Invoice" src="{{docs_base_url}}/assets/img/accounts/sales-invoice.png">
 
@@ -54,6 +54,16 @@
 ERPNext will automatically create new Invoices and mail it to the email ids
 you set.
 
+#### POS Invoices
+
+Consider a scenario where retail transaction is carried out. For e.g: A retail shop.
+If you check the **Is POS** checkbox, then all your **POS Profile** data is fetched
+into the Sales Invoice and you can easily make payments.
+Also, if you check the **Update Stock** the stock will also update automatically,
+without the need of a Delivery Note.
+
+<img class="screenshot" alt="POS Invoice" src="{{docs_base_url}}/assets/img/accounts/pos-sales-invoice.png">
+
 * * *
 
 #### "Pro Forma" Invoice
diff --git a/erpnext/docs/user/manual/en/accounts/setup/accounts-settings.md b/erpnext/docs/user/manual/en/accounts/setup/accounts-settings.md
index 5242b39..e920b65 100644
--- a/erpnext/docs/user/manual/en/accounts/setup/accounts-settings.md
+++ b/erpnext/docs/user/manual/en/accounts/setup/accounts-settings.md
@@ -7,4 +7,8 @@
 
 * Credit Controller: Role that is allowed to submit transactions that exceed credit limits set.
 
+* Make Payment via Journal Entry: If checked, on invoice if uer has clicked on payment system open the journal entry else payment entry
+
+* Unlink Payment on Cancellation of Invoice: If checked system inlink the payment against the invoice else shows the link error.
+
 {next}
\ No newline at end of file
diff --git a/erpnext/docs/user/manual/en/accounts/setup/fiscal-year.md b/erpnext/docs/user/manual/en/accounts/setup/fiscal-year.md
index 618d20b..4a1195a 100644
--- a/erpnext/docs/user/manual/en/accounts/setup/fiscal-year.md
+++ b/erpnext/docs/user/manual/en/accounts/setup/fiscal-year.md
@@ -18,6 +18,11 @@
 income will be for that year, and can adjust their expenses to maintain their
 desired profit margins.
 
+To set the Fiscal Year as default, click on the 'Default' button.
+
+In case you have multiple companies sharing the same Fiscal Year, you can add
+it into the grid as shown below.
+
 <img class="screenshot" alt="Fiscal Year" src="{{docs_base_url}}/assets/img/accounts/fiscal-year.png">
 
 {next}
diff --git a/erpnext/docs/user/manual/en/buying/supplier.md b/erpnext/docs/user/manual/en/buying/supplier.md
index 45ec6b1..89107db 100644
--- a/erpnext/docs/user/manual/en/buying/supplier.md
+++ b/erpnext/docs/user/manual/en/buying/supplier.md
@@ -2,7 +2,7 @@
 
 You can create a new Supplier from:
 
-`Buying > Documents > Supplier > New Supplier`
+`Explore > Supplier > New Supplier`
 
 <img class="screenshot" alt="Supplier Master" src="{{docs_base_url}}/assets/img/buying/supplier-master.png">
 
diff --git a/erpnext/docs/user/manual/en/fleet_management/__init__.py b/erpnext/docs/user/manual/en/fleet_management/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/erpnext/docs/user/manual/en/fleet_management/__init__.py
diff --git a/erpnext/docs/user/manual/en/fleet_management/index.md b/erpnext/docs/user/manual/en/fleet_management/index.md
new file mode 100644
index 0000000..8ae3b7c
--- /dev/null
+++ b/erpnext/docs/user/manual/en/fleet_management/index.md
@@ -0,0 +1,64 @@
+Fleet Management module helps your Organization manage their fleet of vehicles and track their expenses.
+
+To use Fleet Management in ERPNext,
+
+  1. Set Up a Vehicle.
+  2. Enter Vehicle Logs regularly.
+  3. Make Expense Claims for Vehicle Expenses.
+  4. View Reports for Vehicle Expenses.
+
+### Vehicle Set Up
+
+The Vehicle Set Up allows you to define the different types of Vehicles in your Organization.It acts as the Vehicle Master for Fleet Management. 
+
+To create a new Vehicle go to:
+
+ERPNext > Vehicle
+
+* Enter License Plate,Make,Model,Odometer Value,Fuel Type and Fuel UOM for a quick entry.
+
+	<img class="screenshot" alt="Vehicle" src="{{docs_base_url}}/assets/img/fleet-management/vehicle-1.1.png">
+
+* Enter details like Insurance,Chassis,Vehicle Value,Location and Employee.
+
+	<img class="screenshot" alt="Vehicle" src="{{docs_base_url}}/assets/img/fleet-management/vehicle-1.2.png">
+
+* Enter Vehicle attributes like color,wheels,doors and last carbon check 
+
+	<img class="screenshot" alt="Vehicle" src="{{docs_base_url}}/assets/img/fleet-management/vehicle-1.3.png">
+
+### Vehicle Log
+
+Vehicle Log is used to enter Odometer readings,Fuel Expenses and Service Expense details.
+
+To create a new Vehicle Log go to:
+
+ERPNext > Vehicle Log
+
+* Enter License Plate,Employee,Date,Odometer reading for a quick entry.
+
+	<img class="screenshot" alt="Vehicle Log" src="{{docs_base_url}}/assets/img/fleet-management/vehicle-log-2.1.png">
+
+* Enter Refuelling details,Service details if applicable.
+
+	<img class="screenshot" alt="Vehicle Log" src="{{docs_base_url}}/assets/img/fleet-management/vehicle-log-2.2.png">
+
+### Make Expense Claim
+
+* Click on Make Expense Claim button .This button appears only in case of Submitted Vehicle Logs.
+
+	<img class="screenshot" alt="Vehicle Log" src="{{docs_base_url}}/assets/img/fleet-management/expense-claim-3.1.png">
+
+When you click on 'Make Expense Claim',
+
+  1. The date,employee,expense total are copied over to the created Expense Claim.
+  2. The sum of Fuel Expenses and Service Expenses is copied over to Expense Claim Amount.
+  3. Employee can submit the Expense Claim for further processing.
+
+	<img class="screenshot" alt="Vehicle Log" src="{{docs_base_url}}/assets/img/fleet-management/expense-claim-3.2.png">
+
+### Vehicle Expenses Report
+
+* To track and monitor Vehicle Expenses you can use the Vehicle Expenses report.This report gives a one stop view of all your vehicle expenses month wise.
+
+	<img class="screenshot" alt="Vehicle Log" src="{{docs_base_url}}/assets/img/fleet-management/vehicle-expenses.png">
diff --git a/erpnext/docs/user/manual/en/fleet_management/index.txt b/erpnext/docs/user/manual/en/fleet_management/index.txt
new file mode 100644
index 0000000..2da8e7b
--- /dev/null
+++ b/erpnext/docs/user/manual/en/fleet_management/index.txt
@@ -0,0 +1,3 @@
+Vehicle
+Vehicle Log
+Vehicle Expenses
\ No newline at end of file
diff --git a/erpnext/docs/user/manual/en/human-resources/salary-and-payroll.md b/erpnext/docs/user/manual/en/human-resources/salary-and-payroll.md
index 62933df..286df14 100644
--- a/erpnext/docs/user/manual/en/human-resources/salary-and-payroll.md
+++ b/erpnext/docs/user/manual/en/human-resources/salary-and-payroll.md
@@ -81,6 +81,12 @@
   * Only Formula  
   * Only Amount
   
+#### Figure 1.5:Account Details
+
+<img class="screenshot" alt="Salary Structure" src="{{docs_base_url}}/assets/img/human-resources/salary-structure-account.png">  
+
+  * Select Mode of Payment and Payment Account for the Salary Slips which will be generated using this Salary Structure
+  
 Save the Salary Structure.
 
 In conditions and formulas, 
@@ -128,8 +134,10 @@
 In Process Payroll,
 
   1. Select the Company for which you want to create the Salary Slips.
-  2. Select the Month and the Year for which you want to create the Salary Slips.
-  3. Click on “Create Salary Slips”. This will create Salary Slip records for each active Employee for the month selected. If the Salary Slips are created, the system will not create any more Salary Slips. All updates will be shown in the “Activity Log” section.
+  2. Check "Salary Slip based on Timesheet" if you want to process timesheet based Salary Slips.
+  3. Select the From Date and To Date or Fiscal year and month for which you want to create the Salary Slips.
+  3. Select the Payment Account.
+  3. Click on “Create Salary Slips”. This will create Salary Slip records for each active Employee for the time period selected. If the Salary Slips are created, the system will not create any more Salary Slips. All updates will be shown in the “Activity Log” section.
   4. Once all Salary Slips are created, you can check if they are created correctly or edit it if you want to deduct Leave Without Pay (LWP).
   5. After checking, you can “Submit” them all together by clicking on “Submit Salary Slips”. 1. If you want them to be automatically emailed to the Employee, make sure to check the “Send Email” box.
 
@@ -144,12 +152,19 @@
 with access to the company’s accounts will not have access to the individual
 salaries.
 
-The salary payment entry is a Journal Entry entry that debits the total
-salary of all Employees to the Salary Account and credits the company’s bank
-Account.
+The salary payment entry is a Journal Entry that debits the total of the
+earning type salary component and credits the total of deduction type salary 
+component of all Employees to the default account set at Salary Component level 
+for each component.
 
 To generate your salary payment voucher from Process Payroll, click on
-“Make Bank Voucher” and a new Journal Entry with the total salaries will be
+“Make Bank Entry”. It will ask to enter the Bank Transaction Reference Number and date.
+Click on "Make" and a new Journal Entry with the total salary components will be
 created.
 
+#### Figure 3.1: Make Bank Entry
+
+<img class="screenshot" alt="Process Payroll" src="{{docs_base_url}}/assets/img/human-resources/bank-entry.png">
+
+
 {next}
diff --git a/erpnext/docs/user/manual/en/selling/setup/product-bundle.md b/erpnext/docs/user/manual/en/selling/setup/product-bundle.md
index fa7f948..123eeaf 100644
--- a/erpnext/docs/user/manual/en/selling/setup/product-bundle.md
+++ b/erpnext/docs/user/manual/en/selling/setup/product-bundle.md
@@ -1,9 +1,7 @@
 #Product Bundle
 
-Product Bundle stands for Sales Bill-of-Material. It's a master where you can list item which are bundled together and 
-sold as one item. For instance, when laptop is delivered, you need to ensure that charger, mouse and laptop bag are 
-delivered and stock level of these items gets affected. To address this scenario, you can set create Product Bundle for 
-the main item, i.e. laptop, and list deliverable items i.e. laptop + charger + other accessories as child items.
+Product Bundle can be seen as something like a "Bill-of-Material" on the Sales side. It's a master where you can list existing items which are bundled together and sold as a set (or bundle). For instance, when you sell a laptop, you need to ensure that charger, mouse and laptop bag are delivered with it and stock levels of these items get affected. 
+To address this scenario, you can set create a Product Bundle for the main item, i.e. laptop, and list deliverable items i.e. laptop + charger + mouse + laptop bag as so-called "Child Items".
   
 Following are the steps on how to setup Product Bundle master, and how is it used in the sales transactions.
 
@@ -17,25 +15,27 @@
 
 ###Select Parent Item
 
-In Product Bundle master, there are two sections. Product Bundle Item and Package Item.
+In Product Bundle master, there are two sections. The "Parent Item" and a List of items to be shipped (Child Items).
 
-In Product Bundle item, you will select a Parent Item. The parent item must be a <b>non-stock item</b>. 
-This is non-stock item because there is no stock maintained for it but only the Package Items. 
+The "Parent Item" must be a so called <b>non-stock item</b>. The "Parent Item" is to be seen more like a vessel or virtual item and not a physical product.
+To create a <b>non-stock item</b> you have to unmark "Maintain Stock" in the Item Form.
+This is non-stock item because there is no stock maintained for it but only for the "Child Items". 
 If you want to maintain stock for the Parent Item, then you must create a regular Bill of Material (BOM) 
 and package them using a Stock Entry Transactions.
 
 ###Select Child Items
 
 In Package Item section, you will list all the child items for which we maintain stock and is delivered to customer.
+Remember: The "Parent Item" is just virtual, so your main product (a laptop in our example here) also has to be listed on the List of Child (or Package) Items
 
 ###Product Bundle in the Sales Transactions
 
-When making Sales transactions like Sales Invoice, Sales Order and Delivery Note, 
-Parent Item will be selected in the main item table.
+When making Sales transactions (Sales Invoice, Sales Order, Delivery Note) 
+the Parent Item will be selected in the main item table.
 
 <img class="screenshot" alt="Product Bundle" src="{{docs_base_url}}/assets/img/selling/product-bundle.gif">
 
-On selection on Parent Item in the main item table, its child items will be fetched in Packing List 
+On selection of a Parent Item in the main item table, its child items will be fetched in Packing List 
 table of the transaction. If child item is the serialized item, you will be able to specify its Serial Mo. 
 in packing List table itself. On submission of transaction, system will reduce the stock level of child items from 
 warehouse specified in Packing List table.
diff --git a/erpnext/docs/user/manual/en/stock/material-request.md b/erpnext/docs/user/manual/en/stock/material-request.md
index 8afda60..d707dd7 100644
--- a/erpnext/docs/user/manual/en/stock/material-request.md
+++ b/erpnext/docs/user/manual/en/stock/material-request.md
@@ -1,7 +1,7 @@
 A Material Request is a simple document identifying a requirement of a set of
 Items (products or services) for a particular reason.
 
-![Workflow]({{docs_base_url}}/assets/old_images/erpnext/material-request-workflow.jpg)
+![Workflow]({{docs_base_url}}/assets/img/buying/material-request-flowchart.png)
 
 To generate a Material Request manually go to:
 
@@ -25,6 +25,8 @@
 * Material Issue - If the requested material is to be Issued.
 * Manufacture - If the requested material is to be Produced.
 
+The User can also raise a [Request For Quotation]({{docs_base_url}}/user/manual/en/buying/request-for-quotation.html) against a Material Request. To create a Request For Quotation the user can click on 'Make'.
+
 > Info: Material Request is not mandatory. It is ideal if you have centralized
 buying so that you can collect this information from various departments.
 
diff --git a/erpnext/docs/user/videos/learn/data-import-tool.md b/erpnext/docs/user/videos/learn/data-import-tool.md
index 10cd00f..a3272e9 100644
--- a/erpnext/docs/user/videos/learn/data-import-tool.md
+++ b/erpnext/docs/user/videos/learn/data-import-tool.md
@@ -1,8 +1,7 @@
 # Data Import Tool
 
-<iframe width="660" height="371" src="https://www.youtube.com/embed/6wiriRKPhmg" frameborder="0" allowfullscreen></iframe>
+<iframe width="660" height="371" src="https://www.youtube.com/embed/Ta2Xx3QoK3E" frameborder="0" allowfullscreen></iframe>
 
-**Duration: 3:24**
+**Duration: 6:32**
 
-This video walks you through on importing data in ERPNext from spreadsheet files. This tools allows you in faster migration of masters and transactions from legacy system into ERPNext. You can also use this tool to export data from ERPNext, and keep it as a backup
-of specific document type.
+This video walks you through on importing data in ERPNext from spreadsheet files. This tools allows you in faster migration of masters and transactions from legacy system into ERPNext. You can also use this tool to export data from ERPNext, and keep it as a backup of specific document type.
diff --git a/erpnext/fleet_management/__init__.py b/erpnext/fleet_management/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/erpnext/fleet_management/__init__.py
diff --git a/erpnext/fleet_management/doctype/__init__.py b/erpnext/fleet_management/doctype/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/erpnext/fleet_management/doctype/__init__.py
diff --git a/erpnext/fleet_management/doctype/vehicle/__init__.py b/erpnext/fleet_management/doctype/vehicle/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/erpnext/fleet_management/doctype/vehicle/__init__.py
diff --git a/erpnext/fleet_management/doctype/vehicle/test_vehicle.py b/erpnext/fleet_management/doctype/vehicle/test_vehicle.py
new file mode 100644
index 0000000..6431977
--- /dev/null
+++ b/erpnext/fleet_management/doctype/vehicle/test_vehicle.py
@@ -0,0 +1,24 @@
+# -*- coding: utf-8 -*-
+# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
+# See license.txt
+from __future__ import unicode_literals
+
+import frappe
+import unittest
+from frappe.utils import nowdate,flt, cstr,random_string
+# test_records = frappe.get_test_records('Vehicle')
+
+class TestVehicle(unittest.TestCase):
+	def test_make_vehicle(self):
+		vehicle = frappe.get_doc({
+			"doctype": "Vehicle",
+			"license_plate": random_string(10).upper(),
+			"make": "Maruti",
+			"model": "PCM",
+			"last_odometer":5000,
+			"acquisition_date":frappe.utils.nowdate(),
+			"location": "Mumbai",
+			"chassis_no": "1234ABCD",
+			"vehicle_value":frappe.utils.flt(500000)
+		})
+		vehicle.insert()
diff --git a/erpnext/fleet_management/doctype/vehicle/vehicle.js b/erpnext/fleet_management/doctype/vehicle/vehicle.js
new file mode 100644
index 0000000..f12c434
--- /dev/null
+++ b/erpnext/fleet_management/doctype/vehicle/vehicle.js
@@ -0,0 +1,8 @@
+// Copyright (c) 2016, Frappe Technologies Pvt. Ltd. and contributors
+// For license information, please see license.txt
+
+frappe.ui.form.on('Vehicle', {
+	refresh: function(frm) {
+
+	}
+});
diff --git a/erpnext/fleet_management/doctype/vehicle/vehicle.json b/erpnext/fleet_management/doctype/vehicle/vehicle.json
new file mode 100644
index 0000000..5dec1e3
--- /dev/null
+++ b/erpnext/fleet_management/doctype/vehicle/vehicle.json
@@ -0,0 +1,764 @@
+{
+ "allow_copy": 0, 
+ "allow_import": 0, 
+ "allow_rename": 0, 
+ "autoname": "field:license_plate", 
+ "beta": 0, 
+ "creation": "2016-09-03 03:33:27.680331", 
+ "custom": 0, 
+ "docstatus": 0, 
+ "doctype": "DocType", 
+ "document_type": "Document", 
+ "editable_grid": 1, 
+ "fields": [
+  {
+   "allow_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
+   "fieldname": "license_plate", 
+   "fieldtype": "Data", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 1, 
+   "in_list_view": 0, 
+   "label": "License Plate", 
+   "length": 0, 
+   "no_copy": 1, 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 0, 
+   "print_hide_if_no_value": 0, 
+   "read_only": 0, 
+   "report_hide": 0, 
+   "reqd": 1, 
+   "search_index": 0, 
+   "set_only_once": 0, 
+   "unique": 1
+  }, 
+  {
+   "allow_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
+   "fieldname": "make", 
+   "fieldtype": "Data", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 0, 
+   "in_list_view": 0, 
+   "label": "Make", 
+   "length": 0, 
+   "no_copy": 0, 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 0, 
+   "print_hide_if_no_value": 0, 
+   "read_only": 0, 
+   "report_hide": 0, 
+   "reqd": 1, 
+   "search_index": 0, 
+   "set_only_once": 0, 
+   "unique": 0
+  }, 
+  {
+   "allow_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
+   "fieldname": "column_break_3", 
+   "fieldtype": "Column Break", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 0, 
+   "in_list_view": 0, 
+   "length": 0, 
+   "no_copy": 0, 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 0, 
+   "print_hide_if_no_value": 0, 
+   "read_only": 0, 
+   "report_hide": 0, 
+   "reqd": 0, 
+   "search_index": 0, 
+   "set_only_once": 0, 
+   "unique": 0
+  }, 
+  {
+   "allow_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
+   "fieldname": "model", 
+   "fieldtype": "Data", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 1, 
+   "in_list_view": 1, 
+   "label": "Model", 
+   "length": 0, 
+   "no_copy": 0, 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 0, 
+   "print_hide_if_no_value": 0, 
+   "read_only": 0, 
+   "report_hide": 0, 
+   "reqd": 1, 
+   "search_index": 0, 
+   "set_only_once": 0, 
+   "unique": 0
+  }, 
+  {
+   "allow_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
+   "fieldname": "vehicle_details", 
+   "fieldtype": "Section Break", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 0, 
+   "in_list_view": 0, 
+   "label": "Details", 
+   "length": 0, 
+   "no_copy": 0, 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 0, 
+   "print_hide_if_no_value": 0, 
+   "read_only": 0, 
+   "report_hide": 0, 
+   "reqd": 0, 
+   "search_index": 0, 
+   "set_only_once": 0, 
+   "unique": 0
+  }, 
+  {
+   "allow_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
+   "fieldname": "last_odometer", 
+   "fieldtype": "Int", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 1, 
+   "in_list_view": 1, 
+   "label": "Odometer Value (Last)", 
+   "length": 0, 
+   "no_copy": 1, 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 0, 
+   "print_hide_if_no_value": 0, 
+   "read_only": 0, 
+   "report_hide": 0, 
+   "reqd": 1, 
+   "search_index": 0, 
+   "set_only_once": 1, 
+   "unique": 0
+  }, 
+  {
+   "allow_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
+   "fieldname": "acquisition_date", 
+   "fieldtype": "Date", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 1, 
+   "in_list_view": 0, 
+   "label": "Acquisition Date", 
+   "length": 0, 
+   "no_copy": 0, 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 0, 
+   "print_hide_if_no_value": 0, 
+   "read_only": 0, 
+   "report_hide": 0, 
+   "reqd": 0, 
+   "search_index": 0, 
+   "set_only_once": 0, 
+   "unique": 0
+  }, 
+  {
+   "allow_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
+   "fieldname": "location", 
+   "fieldtype": "Data", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 0, 
+   "in_list_view": 0, 
+   "label": "Location", 
+   "length": 0, 
+   "no_copy": 0, 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 0, 
+   "print_hide_if_no_value": 0, 
+   "read_only": 0, 
+   "report_hide": 0, 
+   "reqd": 0, 
+   "search_index": 0, 
+   "set_only_once": 0, 
+   "unique": 0
+  }, 
+  {
+   "allow_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
+   "fieldname": "column_break_8", 
+   "fieldtype": "Column Break", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 0, 
+   "in_list_view": 0, 
+   "length": 0, 
+   "no_copy": 0, 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 0, 
+   "print_hide_if_no_value": 0, 
+   "read_only": 0, 
+   "report_hide": 0, 
+   "reqd": 0, 
+   "search_index": 0, 
+   "set_only_once": 0, 
+   "unique": 0
+  }, 
+  {
+   "allow_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
+   "fieldname": "chassis_no", 
+   "fieldtype": "Data", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 0, 
+   "in_list_view": 0, 
+   "label": "Chassis No", 
+   "length": 0, 
+   "no_copy": 0, 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 0, 
+   "print_hide_if_no_value": 0, 
+   "read_only": 0, 
+   "report_hide": 0, 
+   "reqd": 0, 
+   "search_index": 0, 
+   "set_only_once": 0, 
+   "unique": 0
+  }, 
+  {
+   "allow_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
+   "fieldname": "vehicle_value", 
+   "fieldtype": "Currency", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 0, 
+   "in_list_view": 1, 
+   "label": "Vehicle Value", 
+   "length": 0, 
+   "no_copy": 0, 
+   "options": "", 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 0, 
+   "print_hide_if_no_value": 1, 
+   "read_only": 0, 
+   "report_hide": 0, 
+   "reqd": 0, 
+   "search_index": 0, 
+   "set_only_once": 0, 
+   "unique": 0
+  }, 
+  {
+   "allow_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
+   "fieldname": "employee", 
+   "fieldtype": "Link", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 0, 
+   "in_list_view": 0, 
+   "label": "Employee", 
+   "length": 0, 
+   "no_copy": 0, 
+   "options": "Employee", 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 0, 
+   "print_hide_if_no_value": 0, 
+   "read_only": 0, 
+   "report_hide": 0, 
+   "reqd": 0, 
+   "search_index": 0, 
+   "set_only_once": 0, 
+   "unique": 0
+  }, 
+  {
+   "allow_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
+   "fieldname": "insurance_details", 
+   "fieldtype": "Section Break", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 0, 
+   "in_list_view": 0, 
+   "label": "Insurance Details", 
+   "length": 0, 
+   "no_copy": 0, 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 0, 
+   "print_hide_if_no_value": 0, 
+   "read_only": 0, 
+   "report_hide": 0, 
+   "reqd": 0, 
+   "search_index": 0, 
+   "set_only_once": 0, 
+   "unique": 0
+  }, 
+  {
+   "allow_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
+   "fieldname": "insurance_company", 
+   "fieldtype": "Data", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 1, 
+   "in_list_view": 0, 
+   "label": "Insurance Company", 
+   "length": 0, 
+   "no_copy": 0, 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 0, 
+   "print_hide_if_no_value": 0, 
+   "read_only": 0, 
+   "report_hide": 0, 
+   "reqd": 0, 
+   "search_index": 0, 
+   "set_only_once": 0, 
+   "unique": 0
+  }, 
+  {
+   "allow_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
+   "fieldname": "policy_no", 
+   "fieldtype": "Data", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 1, 
+   "in_list_view": 0, 
+   "label": "Policy No", 
+   "length": 0, 
+   "no_copy": 0, 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 0, 
+   "print_hide_if_no_value": 0, 
+   "read_only": 0, 
+   "report_hide": 0, 
+   "reqd": 0, 
+   "search_index": 0, 
+   "set_only_once": 0, 
+   "unique": 0
+  }, 
+  {
+   "allow_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
+   "fieldname": "column_break_15", 
+   "fieldtype": "Column Break", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 0, 
+   "in_list_view": 0, 
+   "length": 0, 
+   "no_copy": 0, 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 0, 
+   "print_hide_if_no_value": 0, 
+   "read_only": 0, 
+   "report_hide": 0, 
+   "reqd": 0, 
+   "search_index": 0, 
+   "set_only_once": 0, 
+   "unique": 0
+  }, 
+  {
+   "allow_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
+   "fieldname": "start_date", 
+   "fieldtype": "Date", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 0, 
+   "in_list_view": 0, 
+   "label": "Start Date", 
+   "length": 0, 
+   "no_copy": 0, 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 0, 
+   "print_hide_if_no_value": 0, 
+   "read_only": 0, 
+   "report_hide": 0, 
+   "reqd": 0, 
+   "search_index": 0, 
+   "set_only_once": 0, 
+   "unique": 0
+  }, 
+  {
+   "allow_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
+   "fieldname": "end_date", 
+   "fieldtype": "Date", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 0, 
+   "in_list_view": 0, 
+   "label": "End Date", 
+   "length": 0, 
+   "no_copy": 0, 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 0, 
+   "print_hide_if_no_value": 0, 
+   "read_only": 0, 
+   "report_hide": 0, 
+   "reqd": 0, 
+   "search_index": 0, 
+   "set_only_once": 0, 
+   "unique": 0
+  }, 
+  {
+   "allow_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
+   "fieldname": "additional_details", 
+   "fieldtype": "Section Break", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 0, 
+   "in_list_view": 0, 
+   "label": "Additional Details", 
+   "length": 0, 
+   "no_copy": 0, 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 0, 
+   "print_hide_if_no_value": 0, 
+   "read_only": 0, 
+   "report_hide": 0, 
+   "reqd": 0, 
+   "search_index": 0, 
+   "set_only_once": 0, 
+   "unique": 0
+  }, 
+  {
+   "allow_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
+   "fieldname": "fuel_type", 
+   "fieldtype": "Select", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 0, 
+   "in_list_view": 1, 
+   "label": "Fuel Type", 
+   "length": 0, 
+   "no_copy": 0, 
+   "options": "Petrol\nDiesel\nNatural Gas\nElectric", 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 0, 
+   "print_hide_if_no_value": 0, 
+   "read_only": 0, 
+   "report_hide": 0, 
+   "reqd": 1, 
+   "search_index": 0, 
+   "set_only_once": 0, 
+   "unique": 0
+  }, 
+  {
+   "allow_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
+   "default": "Litre", 
+   "fieldname": "uom", 
+   "fieldtype": "Link", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 0, 
+   "in_list_view": 1, 
+   "label": "Fuel UOM", 
+   "length": 0, 
+   "no_copy": 0, 
+   "options": "UOM", 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 0, 
+   "print_hide_if_no_value": 0, 
+   "read_only": 0, 
+   "report_hide": 0, 
+   "reqd": 1, 
+   "search_index": 0, 
+   "set_only_once": 0, 
+   "unique": 0
+  }, 
+  {
+   "allow_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
+   "fieldname": "carbon_check_date", 
+   "fieldtype": "Date", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 0, 
+   "in_list_view": 0, 
+   "label": "Last Carbon Check", 
+   "length": 0, 
+   "no_copy": 0, 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 0, 
+   "print_hide_if_no_value": 0, 
+   "read_only": 0, 
+   "report_hide": 0, 
+   "reqd": 0, 
+   "search_index": 0, 
+   "set_only_once": 0, 
+   "unique": 0
+  }, 
+  {
+   "allow_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
+   "fieldname": "column_break_21", 
+   "fieldtype": "Column Break", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 0, 
+   "in_list_view": 0, 
+   "length": 0, 
+   "no_copy": 0, 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 0, 
+   "print_hide_if_no_value": 0, 
+   "read_only": 0, 
+   "report_hide": 0, 
+   "reqd": 0, 
+   "search_index": 0, 
+   "set_only_once": 0, 
+   "unique": 0
+  }, 
+  {
+   "allow_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
+   "fieldname": "color", 
+   "fieldtype": "Data", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 0, 
+   "in_list_view": 0, 
+   "label": "Color", 
+   "length": 0, 
+   "no_copy": 0, 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 0, 
+   "print_hide_if_no_value": 0, 
+   "read_only": 0, 
+   "report_hide": 0, 
+   "reqd": 0, 
+   "search_index": 0, 
+   "set_only_once": 0, 
+   "unique": 0
+  }, 
+  {
+   "allow_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
+   "fieldname": "wheels", 
+   "fieldtype": "Int", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 0, 
+   "in_list_view": 0, 
+   "label": "Wheels", 
+   "length": 0, 
+   "no_copy": 0, 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 0, 
+   "print_hide_if_no_value": 0, 
+   "read_only": 0, 
+   "report_hide": 0, 
+   "reqd": 0, 
+   "search_index": 0, 
+   "set_only_once": 0, 
+   "unique": 0
+  }, 
+  {
+   "allow_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
+   "fieldname": "doors", 
+   "fieldtype": "Int", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 0, 
+   "in_list_view": 0, 
+   "label": "Doors", 
+   "length": 0, 
+   "no_copy": 0, 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 0, 
+   "print_hide_if_no_value": 0, 
+   "read_only": 0, 
+   "report_hide": 0, 
+   "reqd": 0, 
+   "search_index": 0, 
+   "set_only_once": 0, 
+   "unique": 0
+  }, 
+  {
+   "allow_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
+   "fieldname": "amended_from", 
+   "fieldtype": "Link", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 0, 
+   "in_list_view": 0, 
+   "label": "Amended From", 
+   "length": 0, 
+   "no_copy": 1, 
+   "options": "Vehicle", 
+   "permlevel": 0, 
+   "print_hide": 1, 
+   "print_hide_if_no_value": 0, 
+   "read_only": 1, 
+   "report_hide": 0, 
+   "reqd": 0, 
+   "search_index": 0, 
+   "set_only_once": 0, 
+   "unique": 0
+  }
+ ], 
+ "hide_heading": 0, 
+ "hide_toolbar": 0, 
+ "idx": 0, 
+ "image_view": 0, 
+ "in_create": 0, 
+ "in_dialog": 0, 
+ "is_submittable": 0, 
+ "issingle": 0, 
+ "istable": 0, 
+ "max_attachments": 0, 
+ "modified": "2016-09-20 11:39:45.446271", 
+ "modified_by": "Administrator", 
+ "module": "Fleet Management", 
+ "name": "Vehicle", 
+ "name_case": "", 
+ "owner": "Administrator", 
+ "permissions": [
+  {
+   "amend": 0, 
+   "apply_user_permissions": 0, 
+   "cancel": 0, 
+   "create": 1, 
+   "delete": 1, 
+   "email": 1, 
+   "export": 1, 
+   "if_owner": 0, 
+   "import": 0, 
+   "permlevel": 0, 
+   "print": 1, 
+   "read": 1, 
+   "report": 1, 
+   "role": "Fleet Manager", 
+   "set_user_permissions": 0, 
+   "share": 1, 
+   "submit": 0, 
+   "write": 1
+  }
+ ], 
+ "quick_entry": 1, 
+ "read_only": 0, 
+ "read_only_onload": 0, 
+ "search_fields": "license_plate,location,model", 
+ "sort_field": "modified", 
+ "sort_order": "DESC", 
+ "title_field": "", 
+ "track_seen": 0
+}
\ No newline at end of file
diff --git a/erpnext/fleet_management/doctype/vehicle/vehicle.py b/erpnext/fleet_management/doctype/vehicle/vehicle.py
new file mode 100644
index 0000000..ef5bfe5
--- /dev/null
+++ b/erpnext/fleet_management/doctype/vehicle/vehicle.py
@@ -0,0 +1,14 @@
+# -*- coding: utf-8 -*-
+# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and contributors
+# For license information, please see license.txt
+
+from __future__ import unicode_literals
+import frappe
+from frappe import _
+from frappe.utils import getdate
+from frappe.model.document import Document
+
+class Vehicle(Document):
+	def validate(self):
+		if getdate(self.start_date) > getdate(self.end_date):
+			frappe.throw(_("Insurance Start date should be less than Insurance End date"))
\ No newline at end of file
diff --git a/erpnext/fleet_management/doctype/vehicle/vehicle_dashboard.py b/erpnext/fleet_management/doctype/vehicle/vehicle_dashboard.py
new file mode 100644
index 0000000..2c1c4c3
--- /dev/null
+++ b/erpnext/fleet_management/doctype/vehicle/vehicle_dashboard.py
@@ -0,0 +1,13 @@
+from frappe import _
+
+data = {
+	'heatmap': True,
+	'heatmap_message': _('This is based on logs against this Vehicle. See timeline below for details'),
+	'fieldname': 'license_plate',
+	'transactions': [
+		{
+			'label': _('Logs'),
+			'items': ['Vehicle Log']
+		}
+	]
+}
\ No newline at end of file
diff --git a/erpnext/fleet_management/doctype/vehicle_log/__init__.py b/erpnext/fleet_management/doctype/vehicle_log/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/erpnext/fleet_management/doctype/vehicle_log/__init__.py
diff --git a/erpnext/fleet_management/doctype/vehicle_log/test_vehicle_log.py b/erpnext/fleet_management/doctype/vehicle_log/test_vehicle_log.py
new file mode 100644
index 0000000..71c1d91
--- /dev/null
+++ b/erpnext/fleet_management/doctype/vehicle_log/test_vehicle_log.py
@@ -0,0 +1,39 @@
+# -*- coding: utf-8 -*-
+# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
+# See license.txt
+from __future__ import unicode_literals
+
+import frappe
+import unittest
+from frappe.utils import nowdate,flt, cstr,random_string
+# test_records = frappe.get_test_records('Vehicle Log')
+class TestVehicleLog(unittest.TestCase):
+	def test_make_vehicle_log(self):
+		license_plate=random_string(10).upper()
+		employee_id=frappe.db.sql("""select name from `tabEmployee` order by modified desc limit 1""")[0][0]
+		vehicle = frappe.get_doc({
+			"doctype": "Vehicle",
+			"license_plate": cstr(license_plate),
+			"make": "Maruti",
+			"model": "PCM",
+			"last_odometer":5000,
+			"acquisition_date":frappe.utils.nowdate(),
+			"location": "Mumbai",
+			"chassis_no": "1234ABCD",
+			"vehicle_value":frappe.utils.flt(500000)
+		})
+		try:
+			vehicle.insert()
+		except frappe.DuplicateEntryError:
+			pass
+		vehicle_log = frappe.get_doc({
+			"doctype": "Vehicle Log",
+			"license_plate": cstr(license_plate),
+			"employee":employee_id,
+			"date":frappe.utils.nowdate(),
+			"odometer":5010,
+			"fuel_qty":frappe.utils.flt(50),
+			"price": frappe.utils.flt(500)
+		})
+		vehicle_log.insert()
+		vehicle_log.submit()
\ No newline at end of file
diff --git a/erpnext/fleet_management/doctype/vehicle_log/vehicle_log.js b/erpnext/fleet_management/doctype/vehicle_log/vehicle_log.js
new file mode 100644
index 0000000..1ccf347
--- /dev/null
+++ b/erpnext/fleet_management/doctype/vehicle_log/vehicle_log.js
@@ -0,0 +1,33 @@
+// Copyright (c) 2016, Frappe Technologies Pvt. Ltd. and contributors
+// For license information, please see license.txt
+
+frappe.ui.form.on("Vehicle Log", {
+	refresh: function(frm,cdt,cdn) {
+		vehicle_log=frappe.model.get_doc(cdt,cdn);
+		if (vehicle_log.license_plate) {
+			frappe.call({
+				method: "erpnext.fleet_management.doctype.vehicle_log.vehicle_log.get_make_model",
+				args: {
+					license_plate: vehicle_log.license_plate
+				},
+				callback: function(r) {
+					frappe.model.set_value(cdt, cdn, ("model"), r.message[0]);
+					frappe.model.set_value(cdt, cdn, ("make"), r.message[1]);
+				}
+			})
+		}
+	},
+	expense_claim: function(frm){
+			frappe.call({
+				method: "erpnext.fleet_management.doctype.vehicle_log.vehicle_log.make_expense_claim",
+				args:{
+					docname: frm.doc.name
+				},
+				callback: function(r){
+					var doc = frappe.model.sync(r.message);
+					frappe.set_route('Form', 'Expense Claim', r.message.name);
+					}
+			})
+	}
+});
+
diff --git a/erpnext/fleet_management/doctype/vehicle_log/vehicle_log.json b/erpnext/fleet_management/doctype/vehicle_log/vehicle_log.json
new file mode 100644
index 0000000..9381852
--- /dev/null
+++ b/erpnext/fleet_management/doctype/vehicle_log/vehicle_log.json
@@ -0,0 +1,634 @@
+{
+ "allow_copy": 0, 
+ "allow_import": 0, 
+ "allow_rename": 0, 
+ "autoname": "naming_series:", 
+ "beta": 0, 
+ "creation": "2016-09-03 14:14:51.788550", 
+ "custom": 0, 
+ "docstatus": 0, 
+ "doctype": "DocType", 
+ "document_type": "Document", 
+ "editable_grid": 1, 
+ "fields": [
+  {
+   "allow_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
+   "fieldname": "vehicle_section", 
+   "fieldtype": "Section Break", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 0, 
+   "in_list_view": 0, 
+   "length": 0, 
+   "no_copy": 0, 
+   "options": "icon-user", 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 0, 
+   "print_hide_if_no_value": 0, 
+   "read_only": 0, 
+   "report_hide": 0, 
+   "reqd": 0, 
+   "search_index": 0, 
+   "set_only_once": 0, 
+   "unique": 0
+  }, 
+  {
+   "allow_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
+   "fieldname": "naming_series", 
+   "fieldtype": "Select", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 0, 
+   "in_list_view": 0, 
+   "label": "Series", 
+   "length": 0, 
+   "no_copy": 1, 
+   "options": "VLOG.", 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 1, 
+   "print_hide_if_no_value": 0, 
+   "read_only": 0, 
+   "report_hide": 0, 
+   "reqd": 1, 
+   "search_index": 0, 
+   "set_only_once": 0, 
+   "unique": 0
+  }, 
+  {
+   "allow_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
+   "fieldname": "license_plate", 
+   "fieldtype": "Link", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 1, 
+   "in_list_view": 1, 
+   "label": "License Plate", 
+   "length": 0, 
+   "no_copy": 0, 
+   "options": "Vehicle", 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 0, 
+   "print_hide_if_no_value": 0, 
+   "read_only": 0, 
+   "report_hide": 0, 
+   "reqd": 1, 
+   "search_index": 0, 
+   "set_only_once": 0, 
+   "unique": 0
+  }, 
+  {
+   "allow_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
+   "fieldname": "employee", 
+   "fieldtype": "Link", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 0, 
+   "in_list_view": 1, 
+   "label": "Employee", 
+   "length": 0, 
+   "no_copy": 0, 
+   "options": "Employee", 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 0, 
+   "print_hide_if_no_value": 0, 
+   "read_only": 0, 
+   "report_hide": 0, 
+   "reqd": 1, 
+   "search_index": 0, 
+   "set_only_once": 0, 
+   "unique": 0
+  }, 
+  {
+   "allow_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
+   "fieldname": "column_break_4", 
+   "fieldtype": "Column Break", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 0, 
+   "in_list_view": 0, 
+   "length": 0, 
+   "no_copy": 0, 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 0, 
+   "print_hide_if_no_value": 0, 
+   "read_only": 0, 
+   "report_hide": 0, 
+   "reqd": 0, 
+   "search_index": 0, 
+   "set_only_once": 0, 
+   "unique": 0
+  }, 
+  {
+   "allow_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
+   "fieldname": "column_break_7", 
+   "fieldtype": "Column Break", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 0, 
+   "in_list_view": 0, 
+   "length": 0, 
+   "no_copy": 0, 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 0, 
+   "print_hide_if_no_value": 0, 
+   "read_only": 0, 
+   "report_hide": 0, 
+   "reqd": 0, 
+   "search_index": 0, 
+   "set_only_once": 0, 
+   "unique": 0
+  }, 
+  {
+   "allow_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
+   "fieldname": "model", 
+   "fieldtype": "Read Only", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 0, 
+   "in_list_view": 0, 
+   "label": "Model", 
+   "length": 0, 
+   "no_copy": 0, 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 0, 
+   "print_hide_if_no_value": 0, 
+   "read_only": 0, 
+   "report_hide": 0, 
+   "reqd": 0, 
+   "search_index": 0, 
+   "set_only_once": 0, 
+   "unique": 0
+  }, 
+  {
+   "allow_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
+   "fieldname": "make", 
+   "fieldtype": "Read Only", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 0, 
+   "in_list_view": 0, 
+   "label": "Make", 
+   "length": 0, 
+   "no_copy": 0, 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 0, 
+   "print_hide_if_no_value": 0, 
+   "read_only": 0, 
+   "report_hide": 0, 
+   "reqd": 0, 
+   "search_index": 0, 
+   "set_only_once": 0, 
+   "unique": 0
+  }, 
+  {
+   "allow_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
+   "fieldname": "odometer_reading", 
+   "fieldtype": "Section Break", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 0, 
+   "in_list_view": 0, 
+   "label": "Odometer Reading", 
+   "length": 0, 
+   "no_copy": 0, 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 0, 
+   "print_hide_if_no_value": 0, 
+   "read_only": 0, 
+   "report_hide": 0, 
+   "reqd": 0, 
+   "search_index": 0, 
+   "set_only_once": 0, 
+   "unique": 0
+  }, 
+  {
+   "allow_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
+   "fieldname": "date", 
+   "fieldtype": "Date", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 0, 
+   "in_list_view": 0, 
+   "label": "Date", 
+   "length": 0, 
+   "no_copy": 0, 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 0, 
+   "print_hide_if_no_value": 0, 
+   "read_only": 0, 
+   "report_hide": 0, 
+   "reqd": 1, 
+   "search_index": 0, 
+   "set_only_once": 0, 
+   "unique": 0
+  }, 
+  {
+   "allow_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
+   "fieldname": "odometer", 
+   "fieldtype": "Int", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 0, 
+   "in_list_view": 0, 
+   "label": "Odometer", 
+   "length": 0, 
+   "no_copy": 0, 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 0, 
+   "print_hide_if_no_value": 0, 
+   "read_only": 0, 
+   "report_hide": 0, 
+   "reqd": 1, 
+   "search_index": 0, 
+   "set_only_once": 0, 
+   "unique": 0
+  }, 
+  {
+   "allow_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 1, 
+   "columns": 0, 
+   "fieldname": "refuelling_details", 
+   "fieldtype": "Section Break", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 0, 
+   "in_list_view": 0, 
+   "label": "Refuelling Details", 
+   "length": 0, 
+   "no_copy": 0, 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 0, 
+   "print_hide_if_no_value": 0, 
+   "read_only": 0, 
+   "report_hide": 0, 
+   "reqd": 0, 
+   "search_index": 0, 
+   "set_only_once": 0, 
+   "unique": 0
+  }, 
+  {
+   "allow_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
+   "fieldname": "fuel_qty", 
+   "fieldtype": "Float", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 0, 
+   "in_list_view": 0, 
+   "label": "Fuel Qty", 
+   "length": 0, 
+   "no_copy": 0, 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 0, 
+   "print_hide_if_no_value": 0, 
+   "read_only": 0, 
+   "report_hide": 0, 
+   "reqd": 0, 
+   "search_index": 0, 
+   "set_only_once": 0, 
+   "unique": 0
+  }, 
+  {
+   "allow_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
+   "fieldname": "price", 
+   "fieldtype": "Currency", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 0, 
+   "in_list_view": 0, 
+   "label": "Fuel Price", 
+   "length": 0, 
+   "no_copy": 0, 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 0, 
+   "print_hide_if_no_value": 0, 
+   "read_only": 0, 
+   "report_hide": 0, 
+   "reqd": 0, 
+   "search_index": 0, 
+   "set_only_once": 0, 
+   "unique": 0
+  }, 
+  {
+   "allow_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
+   "fieldname": "column_break_15", 
+   "fieldtype": "Column Break", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 0, 
+   "in_list_view": 0, 
+   "length": 0, 
+   "no_copy": 0, 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 0, 
+   "print_hide_if_no_value": 0, 
+   "read_only": 0, 
+   "report_hide": 0, 
+   "reqd": 0, 
+   "search_index": 0, 
+   "set_only_once": 0, 
+   "unique": 0
+  }, 
+  {
+   "allow_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
+   "fieldname": "supplier", 
+   "fieldtype": "Link", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 0, 
+   "in_list_view": 0, 
+   "label": "Supplier", 
+   "length": 0, 
+   "no_copy": 0, 
+   "options": "Supplier", 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 0, 
+   "print_hide_if_no_value": 0, 
+   "read_only": 0, 
+   "report_hide": 0, 
+   "reqd": 0, 
+   "search_index": 0, 
+   "set_only_once": 0, 
+   "unique": 0
+  }, 
+  {
+   "allow_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
+   "fieldname": "invoice", 
+   "fieldtype": "Data", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 0, 
+   "in_list_view": 0, 
+   "label": "Invoice Ref", 
+   "length": 0, 
+   "no_copy": 0, 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 0, 
+   "print_hide_if_no_value": 0, 
+   "read_only": 0, 
+   "report_hide": 0, 
+   "reqd": 0, 
+   "search_index": 0, 
+   "set_only_once": 0, 
+   "unique": 0
+  }, 
+  {
+   "allow_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 1, 
+   "columns": 0, 
+   "fieldname": "service_details", 
+   "fieldtype": "Section Break", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 0, 
+   "in_list_view": 0, 
+   "label": "Service_Details", 
+   "length": 0, 
+   "no_copy": 0, 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 0, 
+   "print_hide_if_no_value": 0, 
+   "read_only": 0, 
+   "report_hide": 0, 
+   "reqd": 0, 
+   "search_index": 0, 
+   "set_only_once": 0, 
+   "unique": 0
+  }, 
+  {
+   "allow_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
+   "fieldname": "service_detail", 
+   "fieldtype": "Table", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 0, 
+   "in_list_view": 0, 
+   "label": "Service Detail", 
+   "length": 0, 
+   "no_copy": 0, 
+   "options": "Vehicle Service", 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 0, 
+   "print_hide_if_no_value": 0, 
+   "read_only": 0, 
+   "report_hide": 0, 
+   "reqd": 0, 
+   "search_index": 0, 
+   "set_only_once": 0, 
+   "unique": 0
+  }, 
+  {
+   "allow_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
+   "fieldname": "section_break_20", 
+   "fieldtype": "Section Break", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 0, 
+   "in_list_view": 0, 
+   "length": 0, 
+   "no_copy": 0, 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 0, 
+   "print_hide_if_no_value": 0, 
+   "read_only": 0, 
+   "report_hide": 0, 
+   "reqd": 0, 
+   "search_index": 0, 
+   "set_only_once": 0, 
+   "unique": 0
+  }, 
+  {
+   "allow_on_submit": 1, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
+   "depends_on": "eval:doc.docstatus==1", 
+   "fieldname": "expense_claim", 
+   "fieldtype": "Button", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 0, 
+   "in_list_view": 0, 
+   "label": "Make Expense Claim", 
+   "length": 0, 
+   "no_copy": 0, 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 0, 
+   "print_hide_if_no_value": 0, 
+   "read_only": 0, 
+   "report_hide": 0, 
+   "reqd": 0, 
+   "search_index": 0, 
+   "set_only_once": 0, 
+   "unique": 0
+  }, 
+  {
+   "allow_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
+   "fieldname": "amended_from", 
+   "fieldtype": "Link", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 0, 
+   "in_list_view": 0, 
+   "label": "Amended From", 
+   "length": 0, 
+   "no_copy": 1, 
+   "options": "Vehicle Log", 
+   "permlevel": 0, 
+   "print_hide": 1, 
+   "print_hide_if_no_value": 0, 
+   "read_only": 1, 
+   "report_hide": 0, 
+   "reqd": 0, 
+   "search_index": 0, 
+   "set_only_once": 0, 
+   "unique": 0
+  }
+ ], 
+ "hide_heading": 0, 
+ "hide_toolbar": 0, 
+ "idx": 0, 
+ "image_view": 0, 
+ "in_create": 0, 
+ "in_dialog": 0, 
+ "is_submittable": 1, 
+ "issingle": 0, 
+ "istable": 0, 
+ "max_attachments": 0, 
+ "modified": "2016-09-17 15:44:02.397851", 
+ "modified_by": "Administrator", 
+ "module": "Fleet Management", 
+ "name": "Vehicle Log", 
+ "name_case": "", 
+ "owner": "Administrator", 
+ "permissions": [
+  {
+   "amend": 0, 
+   "apply_user_permissions": 0, 
+   "cancel": 1, 
+   "create": 1, 
+   "delete": 1, 
+   "email": 1, 
+   "export": 1, 
+   "if_owner": 0, 
+   "import": 0, 
+   "permlevel": 0, 
+   "print": 1, 
+   "read": 1, 
+   "report": 1, 
+   "role": "Fleet Manager", 
+   "set_user_permissions": 0, 
+   "share": 1, 
+   "submit": 1, 
+   "write": 1
+  }
+ ], 
+ "quick_entry": 1, 
+ "read_only": 0, 
+ "read_only_onload": 0, 
+ "sort_field": "modified", 
+ "sort_order": "DESC", 
+ "title_field": "", 
+ "track_seen": 0
+}
\ No newline at end of file
diff --git a/erpnext/fleet_management/doctype/vehicle_log/vehicle_log.py b/erpnext/fleet_management/doctype/vehicle_log/vehicle_log.py
new file mode 100644
index 0000000..ceea493
--- /dev/null
+++ b/erpnext/fleet_management/doctype/vehicle_log/vehicle_log.py
@@ -0,0 +1,57 @@
+# -*- coding: utf-8 -*-
+# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and contributors
+# For license information, please see license.txt
+
+from __future__ import unicode_literals
+import frappe
+from frappe import _
+from frappe.utils import flt, cstr
+from frappe.model.mapper import get_mapped_doc
+from frappe.model.document import Document
+
+class VehicleLog(Document):
+	def validate(self):
+		last_odometer=frappe.db.get_value("Vehicle", self.license_plate, "last_odometer")
+		if flt(self.odometer) < flt(last_odometer):
+			frappe.throw(_("Current Odometer reading entered should be greater than initial Vehicle Odometer {0}").format(last_odometer))
+		for service_detail in self.service_detail:
+			if (service_detail.service_item or service_detail.type or service_detail.frequency or service_detail.expense_amount):
+					if not (service_detail.service_item and service_detail.type and service_detail.frequency and service_detail.expense_amount):
+							frappe.throw(_("Service Item,Type,frequency and expense amount are required"))
+							
+	def on_submit(self):
+		frappe.db.sql("update `tabVehicle` set last_odometer=%s where license_plate=%s",
+			(self.odometer, self.license_plate))
+	
+@frappe.whitelist()
+def get_make_model(license_plate):
+	vehicle=frappe.get_doc("Vehicle",license_plate)
+	return (vehicle.make,vehicle.model)
+
+@frappe.whitelist()
+def make_expense_claim(docname):
+	def check_exp_claim_exists():
+		exp_claim = frappe.db.sql("""select name from `tabExpense Claim` where vehicle_log=%s""",vehicle_log.name)
+		return exp_claim[0][0] if exp_claim else ""
+	def calc_service_exp():
+		total_exp_amt=0
+		exp_claim = check_exp_claim_exists()
+		if exp_claim:
+			frappe.throw(_("Expense Claim {0} already exists for the Vehicle Log").format(exp_claim))
+		for serdetail in vehicle_log.service_detail:
+			total_exp_amt = total_exp_amt + serdetail.expense_amount
+		return total_exp_amt
+		
+	vehicle_log = frappe.get_doc("Vehicle Log", docname)
+	exp_claim = frappe.new_doc("Expense Claim")
+	exp_claim.employee=vehicle_log.employee
+	exp_claim.vehicle_log=vehicle_log.name
+	exp_claim.remark=_("Expense Claim for Vehicle Log {0}").format(vehicle_log.name)
+	fuel_price=vehicle_log.price
+	total_claim_amt=calc_service_exp() + fuel_price
+	exp_claim.append("expenses",{
+		"expense_date":vehicle_log.date,
+		"description":_("Vehicle Expenses"),
+		"claim_amount":total_claim_amt
+	})
+	return exp_claim.as_dict()
diff --git a/erpnext/fleet_management/doctype/vehicle_service/__init__.py b/erpnext/fleet_management/doctype/vehicle_service/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/erpnext/fleet_management/doctype/vehicle_service/__init__.py
diff --git a/erpnext/fleet_management/doctype/vehicle_service/vehicle_service.json b/erpnext/fleet_management/doctype/vehicle_service/vehicle_service.json
new file mode 100644
index 0000000..6b80efc
--- /dev/null
+++ b/erpnext/fleet_management/doctype/vehicle_service/vehicle_service.json
@@ -0,0 +1,144 @@
+{
+ "allow_copy": 0, 
+ "allow_import": 0, 
+ "allow_rename": 0, 
+ "beta": 0, 
+ "creation": "2016-09-03 19:20:14.561962", 
+ "custom": 0, 
+ "docstatus": 0, 
+ "doctype": "DocType", 
+ "document_type": "Document", 
+ "editable_grid": 1, 
+ "fields": [
+  {
+   "allow_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
+   "fieldname": "service_item", 
+   "fieldtype": "Select", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 0, 
+   "in_list_view": 1, 
+   "label": "Service Item", 
+   "length": 0, 
+   "no_copy": 0, 
+   "options": "\nBrake Oil\nBrake Pad\nClutch Plate\nEngine Oil\nOil Change\nWheels", 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 0, 
+   "print_hide_if_no_value": 0, 
+   "read_only": 0, 
+   "report_hide": 0, 
+   "reqd": 0, 
+   "search_index": 0, 
+   "set_only_once": 0, 
+   "unique": 0
+  }, 
+  {
+   "allow_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
+   "fieldname": "type", 
+   "fieldtype": "Select", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 0, 
+   "in_list_view": 1, 
+   "label": "Type", 
+   "length": 0, 
+   "no_copy": 0, 
+   "options": "\nInspection\nService\nChange", 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 0, 
+   "print_hide_if_no_value": 0, 
+   "read_only": 0, 
+   "report_hide": 0, 
+   "reqd": 0, 
+   "search_index": 0, 
+   "set_only_once": 0, 
+   "unique": 0
+  }, 
+  {
+   "allow_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
+   "fieldname": "frequency", 
+   "fieldtype": "Select", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 0, 
+   "in_list_view": 1, 
+   "label": "Frequency", 
+   "length": 0, 
+   "no_copy": 0, 
+   "options": "\nMileage\nMonthly\nQuarterly\nHalf Yearly\nYearly", 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 0, 
+   "print_hide_if_no_value": 0, 
+   "read_only": 0, 
+   "report_hide": 0, 
+   "reqd": 0, 
+   "search_index": 0, 
+   "set_only_once": 0, 
+   "unique": 0
+  }, 
+  {
+   "allow_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
+   "fieldname": "expense_amount", 
+   "fieldtype": "Currency", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 0, 
+   "in_list_view": 1, 
+   "label": "Expense", 
+   "length": 0, 
+   "no_copy": 0, 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 0, 
+   "print_hide_if_no_value": 0, 
+   "read_only": 0, 
+   "report_hide": 0, 
+   "reqd": 0, 
+   "search_index": 0, 
+   "set_only_once": 0, 
+   "unique": 0
+  }
+ ], 
+ "hide_heading": 0, 
+ "hide_toolbar": 0, 
+ "idx": 0, 
+ "image_view": 0, 
+ "in_create": 0, 
+ "in_dialog": 0, 
+ "is_submittable": 0, 
+ "issingle": 0, 
+ "istable": 1, 
+ "max_attachments": 0, 
+ "modified": "2016-09-20 07:29:50.852748", 
+ "modified_by": "Administrator", 
+ "module": "Fleet Management", 
+ "name": "Vehicle Service", 
+ "name_case": "", 
+ "owner": "Administrator", 
+ "permissions": [], 
+ "quick_entry": 1, 
+ "read_only": 0, 
+ "read_only_onload": 0, 
+ "sort_field": "modified", 
+ "sort_order": "DESC", 
+ "track_seen": 0
+}
\ No newline at end of file
diff --git a/erpnext/fleet_management/doctype/vehicle_service/vehicle_service.py b/erpnext/fleet_management/doctype/vehicle_service/vehicle_service.py
new file mode 100644
index 0000000..18ed782
--- /dev/null
+++ b/erpnext/fleet_management/doctype/vehicle_service/vehicle_service.py
@@ -0,0 +1,10 @@
+# -*- coding: utf-8 -*-
+# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and contributors
+# For license information, please see license.txt
+
+from __future__ import unicode_literals
+import frappe
+from frappe.model.document import Document
+
+class VehicleService(Document):
+	pass
diff --git a/erpnext/fleet_management/report/__init__.py b/erpnext/fleet_management/report/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/erpnext/fleet_management/report/__init__.py
diff --git a/erpnext/fleet_management/report/vehicle_expenses/__init__.py b/erpnext/fleet_management/report/vehicle_expenses/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/erpnext/fleet_management/report/vehicle_expenses/__init__.py
diff --git a/erpnext/fleet_management/report/vehicle_expenses/vehicle_expenses.js b/erpnext/fleet_management/report/vehicle_expenses/vehicle_expenses.js
new file mode 100644
index 0000000..8a05c81
--- /dev/null
+++ b/erpnext/fleet_management/report/vehicle_expenses/vehicle_expenses.js
@@ -0,0 +1,41 @@
+// Copyright (c) 2016, Frappe Technologies Pvt. Ltd. and contributors
+// For license information, please see license.txt
+frappe.require("assets/erpnext/js/financial_statements.js", function() {
+	frappe.query_reports["Vehicle Expenses"] = {
+		"filters": [
+			{
+				"fieldname": "fiscal_year",
+				"label": __("Fiscal Year"),
+				"fieldtype": "Link",
+				"options": "Fiscal Year",
+				"default": frappe.defaults.get_user_default("fiscal_year"),
+				"reqd": 1,
+				"on_change": function(query_report) {
+					var fiscal_year = query_report.get_values().fiscal_year;
+					if (!fiscal_year) {
+						return;
+					}
+					frappe.model.with_doc("Fiscal Year", fiscal_year, function(r) {
+						var fy = frappe.model.get_doc("Fiscal Year", fiscal_year);
+						frappe.query_report_filters_by_name.from_date.set_input(fy.year_start_date);
+						frappe.query_report_filters_by_name.to_date.set_input(fy.year_end_date);
+						query_report.trigger_refresh();
+					});
+				}
+			},
+			{
+				"fieldname": "from_date",
+				"label": __("From Date"),
+				"fieldtype": "Date",
+				"default": frappe.defaults.get_user_default("year_start_date"),
+			},
+			{
+				"fieldname": "to_date",
+				"label": __("To Date"),
+				"fieldtype": "Date",
+				"default": frappe.defaults.get_user_default("year_end_date"),
+			}
+		]
+	}
+});
+
diff --git a/erpnext/fleet_management/report/vehicle_expenses/vehicle_expenses.json b/erpnext/fleet_management/report/vehicle_expenses/vehicle_expenses.json
new file mode 100644
index 0000000..380c873
--- /dev/null
+++ b/erpnext/fleet_management/report/vehicle_expenses/vehicle_expenses.json
@@ -0,0 +1,18 @@
+{
+ "add_total_row": 0, 
+ "apply_user_permissions": 1, 
+ "creation": "2016-09-09 03:33:40.605734", 
+ "disabled": 0, 
+ "docstatus": 0, 
+ "doctype": "Report", 
+ "idx": 0, 
+ "is_standard": "Yes", 
+ "modified": "2016-09-18 08:54:12.080753", 
+ "modified_by": "Administrator", 
+ "module": "Fleet Management", 
+ "name": "Vehicle Expenses", 
+ "owner": "Administrator", 
+ "ref_doctype": "Vehicle", 
+ "report_name": "Vehicle Expenses", 
+ "report_type": "Script Report"
+}
\ No newline at end of file
diff --git a/erpnext/fleet_management/report/vehicle_expenses/vehicle_expenses.py b/erpnext/fleet_management/report/vehicle_expenses/vehicle_expenses.py
new file mode 100644
index 0000000..717a94f
--- /dev/null
+++ b/erpnext/fleet_management/report/vehicle_expenses/vehicle_expenses.py
@@ -0,0 +1,81 @@
+# Copyright (c) 2013, Frappe Technologies Pvt. Ltd. and contributors
+# For license information, please see license.txt
+
+from __future__ import unicode_literals
+import frappe
+from frappe import _
+from frappe.utils import flt,cstr
+from erpnext.accounts.report.financial_statements import get_period_list
+
+def execute(filters=None):
+	period_list = get_period_list(2016, 2016,"Monthly")
+	for period in period_list:
+		pass
+	columns, data = [], []
+	columns=get_columns()
+	data=get_log_data(filters)
+	chart=get_chart_data(data,period_list)
+	return columns,data,None,chart
+	
+def get_columns():
+	columns = [_("License") + ":Link/Vehicle:100", _("Make") + ":data:50",
+				_("Model") + ":data:50", _("Location") + ":data:100",
+				_("Log") + ":Link/Vehicle Log:100", _("Odometer") + ":Int:80",
+				_("Date") + ":Date:100", _("Fuel Qty") + ":Float:80",
+				_("Fuel Price") + ":Float:100",_("Service Expense") + ":Float:100"
+	]
+	return columns
+
+def get_log_data(filters):
+	conditions=""
+	if filters.from_date:
+		conditions += " and date >= %(from_date)s"
+	if filters.to_date:
+		conditions += " and date <= %(to_date)s"
+	data = frappe.db.sql("""select vhcl.license_plate as "License",vhcl.make as "Make",vhcl.model as "Model",
+							vhcl.location as "Location",log.name as "Log",log.odometer as "Odometer",log.date as "Date",
+							log.fuel_qty as "Fuel Qty",log.price as "Fuel Price"
+							from `tabVehicle` vhcl,`tabVehicle Log` log
+							where vhcl.license_plate = log.license_plate and log.docstatus = 1 %s
+							order by date""" % (conditions,),filters, as_dict=1)
+	dl=list(data)
+	for row in dl:
+		row["Service Expense"]= get_service_expense(row["Log"])
+	return dl
+	
+def get_service_expense(logname):
+	expense_amount = frappe.db.sql("""select sum(expense_amount) 
+										from `tabVehicle Log` log,`tabVehicle Service` ser 
+										where ser.parent=log.name and log.name=%s""",logname)
+	return flt(expense_amount[0][0]) if expense_amount else 0
+	
+def get_chart_data(data,period_list):
+	fuel_exp_data,service_exp_data,fueldata,servicedata = [],[],[],[]
+	service_exp_data = []
+	fueldata = []
+	for period in period_list:
+		total_fuel_exp=0
+		total_ser_exp=0
+		for row in data:
+			if row["Date"] <= period.to_date and row["Date"] >= period.from_date:
+				total_fuel_exp+=flt(row["Fuel Price"])
+				total_ser_exp+=flt(row["Service Expense"])
+		fueldata.append([period.key,total_fuel_exp])
+		servicedata.append([period.key,total_ser_exp])
+
+	x_intervals = ['x'] + [period.key for period in period_list]
+	fuel_exp_data= [row[1] for row in fueldata]
+	service_exp_data= [row[1] for row in servicedata]
+	columns = [x_intervals]
+	if fuel_exp_data:
+		columns.append(["Fuel Expenses"]+ fuel_exp_data)
+	if service_exp_data:
+		columns.append(["Service Expenses"]+ service_exp_data)
+	chart = {
+		"data": {
+			'x': 'x',
+			'columns': columns
+		}
+	}
+	chart["chart_type"] = "line"
+	return chart
\ No newline at end of file
diff --git a/erpnext/hooks.py b/erpnext/hooks.py
index 43ae234..8b8d3c9 100644
--- a/erpnext/hooks.py
+++ b/erpnext/hooks.py
@@ -101,17 +101,25 @@
 
 portal_menu_items = [
 	{"title": _("Projects"), "route": "/project", "reference_doctype": "Project"},
-	{"title": _("Request for Quotations"), "route": "/rfq", "reference_doctype": "Request for Quotation"},
-	{"title": _("Supplier Quotation"), "route": "/quotations", "reference_doctype": "Supplier Quotation"},
-	{"title": _("Orders"), "route": "/orders", "reference_doctype": "Sales Order"},
-	{"title": _("Invoices"), "route": "/invoices", "reference_doctype": "Sales Invoice"},
-	{"title": _("Shipments"), "route": "/shipments", "reference_doctype": "Delivery Note"},
-	{"title": _("Issues"), "route": "/issues", "reference_doctype": "Issue", "show_always": True},
+	{"title": _("Request for Quotations"), "route": "/rfq", "reference_doctype": "Request for Quotation", "role": "Supplier"},
+	{"title": _("Supplier Quotation"), "route": "/quotations", "reference_doctype": "Supplier Quotation", "role": "Supplier"},
+	{"title": _("Orders"), "route": "/orders", "reference_doctype": "Sales Order", "role":"Customer"},
+	{"title": _("Invoices"), "route": "/invoices", "reference_doctype": "Sales Invoice", "role":"Customer"},
+	{"title": _("Shipments"), "route": "/shipments", "reference_doctype": "Delivery Note", "role":"Customer"},
+	{"title": _("Issues"), "route": "/issues", "reference_doctype": "Issue", "role":"Customer"},
 	{"title": _("Addresses"), "route": "/addresses", "reference_doctype": "Address"},
 	{"title": _("Announcements"), "route": "/announcement", "reference_doctype": "Announcement"},
-	{"title": _("Courses"), "route": "/course", "reference_doctype": "Course"},
-	{"title": _("Assessment Schedule"), "route": "/assessment", "reference_doctype": "Assessment"},
-	{"title": _("Fees"), "route": "/fees", "reference_doctype": "Fees"}
+	{"title": _("Courses"), "route": "/course", "reference_doctype": "Course", "role":"Student"},
+	{"title": _("Assessment Schedule"), "route": "/assessment", "reference_doctype": "Assessment", "role":"Student"},
+	{"title": _("Fees"), "route": "/fees", "reference_doctype": "Fees", "role":"Student"}
+]
+
+default_roles = [
+	{'role': 'Customer', 'doctype':'Contact', 'email_field': 'email_id',
+		'filters': {'ifnull(customer, "")': ('!=', '')}},
+	{'role': 'Supplier', 'doctype':'Contact', 'email_field': 'email_id',
+		'filters': {'ifnull(supplier, "")': ('!=', '')}},
+	{'role': 'Student', 'doctype':'Student', 'email_field': 'student_email_id'}
 ]
 
 has_website_permission = {
diff --git a/erpnext/hr/doctype/employee/employee.js b/erpnext/hr/doctype/employee/employee.js
index f69f4e5..98f9f6e 100755
--- a/erpnext/hr/doctype/employee/employee.js
+++ b/erpnext/hr/doctype/employee/employee.js
@@ -40,6 +40,24 @@
 				"Ms": "Female"
 			}[this.frm.doc.salutation]);
 		}
+	},
+	
+});
+frappe.ui.form.on('Employee',{
+	prefered_contact_email:function(frm){
+		frm.events.update_contact(frm)
+	},
+	personal_email:function(frm){
+		frm.events.update_contact(frm)
+	},
+	company_email:function(frm){
+		frm.events.update_contact(frm)
+	},
+	user_id:function(frm){
+		frm.events.update_contact(frm)
+	},
+	update_contact:function(frm){
+		frm.set_value("prefered_email",frm.fields_dict[frappe.model.scrub(frm.doc.prefered_contact_email)].value)
 	}
 });
 cur_frm.cscript = new erpnext.hr.EmployeeController({frm: cur_frm});
diff --git a/erpnext/hr/doctype/employee/employee.json b/erpnext/hr/doctype/employee/employee.json
index 8311235..a99d874 100644
--- a/erpnext/hr/doctype/employee/employee.json
+++ b/erpnext/hr/doctype/employee/employee.json
@@ -987,7 +987,59 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
-   "columns": 0, 
+   "default": "", 
+   "fieldname": "prefered_contact_email", 
+   "fieldtype": "Select", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 0,
+   "in_list_view": 0, 
+   "label": "Prefered Contact Email", 
+   "length": 0, 
+   "no_copy": 0, 
+   "options": "\nCompany Email\nPersonal Email\nUser ID", 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 0, 
+   "print_hide_if_no_value": 0, 
+   "read_only": 0, 
+   "report_hide": 0, 
+   "reqd": 0, 
+   "search_index": 0, 
+   "set_only_once": 0, 
+   "unique": 0
+  }, 
+  {
+   "allow_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "fieldname": "prefered_email", 
+   "fieldtype": "Data", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 0,
+   "in_list_view": 0, 
+   "label": "Prefered Email", 
+   "length": 0, 
+   "no_copy": 0, 
+   "options": "Email", 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 0, 
+   "print_hide_if_no_value": 0, 
+   "read_only": 1, 
+   "report_hide": 0, 
+   "reqd": 0, 
+   "search_index": 0, 
+   "set_only_once": 0, 
+   "unique": 0
+  }, 
+  {
+   "allow_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
    "fieldname": "cell_number", 
    "fieldtype": "Data", 
    "hidden": 0, 
@@ -2033,7 +2085,7 @@
  "issingle": 0, 
  "istable": 0, 
  "max_attachments": 0, 
- "modified": "2016-09-21 18:12:12.474098", 
+ "modified": "2016-10-18 18:12:12.474098", 
  "modified_by": "Administrator", 
  "module": "HR", 
  "name": "Employee", 
diff --git a/erpnext/hr/doctype/employee/employee_dashboard.py b/erpnext/hr/doctype/employee/employee_dashboard.py
index 420c1df..7de305d 100644
--- a/erpnext/hr/doctype/employee/employee_dashboard.py
+++ b/erpnext/hr/doctype/employee/employee_dashboard.py
@@ -1,25 +1,26 @@
 from frappe import _
 
-data = {
-	'heatmap': True,
-	'heatmap_message': _('This is based on the attendance of this Employee'),
-	'fieldname': 'employee',
-	'transactions': [
-		{
-			'label': _('Leave and Attendance'),
-			'items': ['Attendance', 'Leave Application', 'Leave Allocation']
-		},
-		{
-			'label': _('Payroll'),
-			'items': ['Salary Structure', 'Salary Slip', 'Timesheet']
-		},
-		{
-			'label': _('Expense'),
-			'items': ['Expense Claim']
-		},
-		{
-			'label': _('Evaluation'),
-			'items': ['Appraisal']
-		}
-	]
-}
\ No newline at end of file
+def get_data():
+	return {
+		'heatmap': True,
+		'heatmap_message': _('This is based on the attendance of this Employee'),
+		'fieldname': 'employee',
+		'transactions': [
+			{
+				'label': _('Leave and Attendance'),
+				'items': ['Attendance', 'Leave Application', 'Leave Allocation']
+			},
+			{
+				'label': _('Payroll'),
+				'items': ['Salary Structure', 'Salary Slip', 'Timesheet']
+			},
+			{
+				'label': _('Expense'),
+				'items': ['Expense Claim']
+			},
+			{
+				'label': _('Evaluation'),
+				'items': ['Appraisal']
+			}
+		]
+	}
\ No newline at end of file
diff --git a/erpnext/hr/doctype/expense_claim/expense_claim.js b/erpnext/hr/doctype/expense_claim/expense_claim.js
index bcd8bc0..8b3c451 100644
--- a/erpnext/hr/doctype/expense_claim/expense_claim.js
+++ b/erpnext/hr/doctype/expense_claim/expense_claim.js
@@ -129,9 +129,6 @@
 	doc.total_sanctioned_amount = 0;
 	$.each((doc.expenses || []), function(i, d) {
 		doc.total_claimed_amount += d.claim_amount;
-		if(d.sanctioned_amount==null) {
-			d.sanctioned_amount = d.claim_amount;
-		}
 		doc.total_sanctioned_amount += d.sanctioned_amount;
 	});
 
@@ -144,17 +141,6 @@
 	cur_frm.cscript.calculate_total(doc,cdt,cdn);
 }
 
-cur_frm.cscript.claim_amount = function(doc,cdt,cdn){
-	cur_frm.cscript.calculate_total(doc,cdt,cdn);
-
-	var child = locals[cdt][cdn];
-	refresh_field("sanctioned_amount", child.name, child.parentfield);
-}
-
-cur_frm.cscript.sanctioned_amount = function(doc,cdt,cdn){
-	cur_frm.cscript.calculate_total(doc,cdt,cdn);
-}
-
 cur_frm.cscript.on_submit = function(doc, cdt, cdn) {
 	if(cint(frappe.boot.notification_settings && frappe.boot.notification_settings.expense_claim)) {
 		cur_frm.email_doc(frappe.boot.notification_settings.expense_claim_message);
@@ -172,6 +158,25 @@
 	}
 }
 
+frappe.ui.form.on("Expense Claim Detail", {
+	claim_amount: function(frm, cdt, cdn) {
+		var child = locals[cdt][cdn];
+		var doc = frm.doc;
+
+		if(!child.sanctioned_amount){
+			frappe.model.set_value(cdt, cdn, 'sanctioned_amount', child.claim_amount)
+		}
+
+		cur_frm.cscript.calculate_total(doc,cdt,cdn);
+	},
+
+	sanctioned_amount: function(frm, cdt, cdn) {
+		var doc = frm.doc;
+		cur_frm.cscript.calculate_total(doc,cdt,cdn);
+	}
+})
+
+
 frappe.ui.form.on("Expense Claim", "employee_name", function(frm) {
 	erpnext.expense_claim.set_title(frm);
 });
diff --git a/erpnext/hr/doctype/expense_claim/expense_claim.json b/erpnext/hr/doctype/expense_claim/expense_claim.json
index 035f7de..f2a14c5 100644
--- a/erpnext/hr/doctype/expense_claim/expense_claim.json
+++ b/erpnext/hr/doctype/expense_claim/expense_claim.json
@@ -3,16 +3,19 @@
  "allow_import": 1, 
  "allow_rename": 0, 
  "autoname": "naming_series:", 
+ "beta": 0, 
  "creation": "2013-01-10 16:34:14", 
  "custom": 0, 
  "docstatus": 0, 
  "doctype": "DocType", 
  "document_type": "Setup", 
+ "editable_grid": 0, 
  "fields": [
   {
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "default": "EXP", 
    "fieldname": "naming_series", 
    "fieldtype": "Select", 
@@ -40,6 +43,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "default": "Draft", 
    "depends_on": "eval:!doc.__islocal", 
    "fieldname": "approval_status", 
@@ -69,6 +73,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "description": "A user with \"Expense Approver\" role", 
    "fieldname": "exp_approver", 
    "fieldtype": "Link", 
@@ -98,6 +103,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "column_break0", 
    "fieldtype": "Column Break", 
    "hidden": 0, 
@@ -123,6 +129,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "total_claimed_amount", 
    "fieldtype": "Currency", 
    "hidden": 0, 
@@ -151,6 +158,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "total_sanctioned_amount", 
    "fieldtype": "Currency", 
    "hidden": 0, 
@@ -179,6 +187,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "expense_details", 
    "fieldtype": "Section Break", 
    "hidden": 0, 
@@ -204,6 +213,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "expenses", 
    "fieldtype": "Table", 
    "hidden": 0, 
@@ -231,6 +241,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "sb1", 
    "fieldtype": "Section Break", 
    "hidden": 0, 
@@ -255,6 +266,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "default": "Today", 
    "fieldname": "posting_date", 
    "fieldtype": "Date", 
@@ -282,6 +294,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "employee", 
    "fieldtype": "Link", 
    "hidden": 0, 
@@ -309,6 +322,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "employee_name", 
    "fieldtype": "Data", 
    "hidden": 0, 
@@ -336,6 +350,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "company", 
    "fieldtype": "Link", 
    "hidden": 0, 
@@ -363,6 +378,34 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
+   "fieldname": "vehicle_log", 
+   "fieldtype": "Link", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 0, 
+   "in_list_view": 0, 
+   "label": "Vehicle Log", 
+   "length": 0, 
+   "no_copy": 0, 
+   "options": "Vehicle Log", 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 0, 
+   "print_hide_if_no_value": 0, 
+   "read_only": 1, 
+   "report_hide": 0, 
+   "reqd": 0, 
+   "search_index": 0, 
+   "set_only_once": 0, 
+   "unique": 0
+  }, 
+  {
+   "allow_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "cb1", 
    "fieldtype": "Column Break", 
    "hidden": 0, 
@@ -386,6 +429,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "total_amount_reimbursed", 
    "fieldtype": "Currency", 
    "hidden": 0, 
@@ -412,6 +456,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "remark", 
    "fieldtype": "Small Text", 
    "hidden": 0, 
@@ -438,6 +483,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "project", 
    "fieldtype": "Link", 
    "hidden": 0, 
@@ -464,6 +510,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "task", 
    "fieldtype": "Link", 
    "hidden": 0, 
@@ -490,6 +537,7 @@
    "allow_on_submit": 1, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "default": "{employee_name}", 
    "fieldname": "title", 
    "fieldtype": "Data", 
@@ -516,6 +564,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "email_id", 
    "fieldtype": "Data", 
    "hidden": 1, 
@@ -542,6 +591,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "amended_from", 
    "fieldtype": "Link", 
    "hidden": 0, 
@@ -571,6 +621,7 @@
  "hide_toolbar": 0, 
  "icon": "icon-money", 
  "idx": 1, 
+ "image_view": 0, 
  "in_create": 0, 
  "in_dialog": 0, 
  "is_submittable": 1, 
@@ -578,7 +629,7 @@
  "istable": 0, 
  "max_attachments": 0, 
  "menu_index": 0, 
- "modified": "2016-03-03 04:00:28.190351", 
+ "modified": "2016-09-22 05:17:31.428020", 
  "modified_by": "Administrator", 
  "module": "HR", 
  "name": "Expense Claim", 
@@ -668,11 +719,13 @@
    "write": 1
   }
  ], 
+ "quick_entry": 0, 
  "read_only": 0, 
  "read_only_onload": 0, 
  "search_fields": "approval_status,employee,employee_name", 
  "sort_field": "modified", 
  "sort_order": "DESC", 
  "timeline_field": "employee", 
- "title_field": "title"
+ "title_field": "title", 
+ "track_seen": 0
 }
\ No newline at end of file
diff --git a/erpnext/hr/doctype/holiday_list/holiday_list_calendar.js b/erpnext/hr/doctype/holiday_list/holiday_list_calendar.js
index 3cc8dd5..507d070 100644
--- a/erpnext/hr/doctype/holiday_list/holiday_list_calendar.js
+++ b/erpnext/hr/doctype/holiday_list/holiday_list_calendar.js
@@ -3,8 +3,8 @@
 
 frappe.views.calendar["Holiday List"] = {
 	field_map: {
-		"start": "holiday_date",
-		"end": "holiday_date",
+		"start": "from_date",
+		"end": "to_date",
 		"id": "name",
 		"title": "description",
 		"allDay": "allDay"
diff --git a/erpnext/hr/doctype/hr_settings/hr_settings.json b/erpnext/hr/doctype/hr_settings/hr_settings.json
index d7892c7..d0f7c20 100644
--- a/erpnext/hr/doctype/hr_settings/hr_settings.json
+++ b/erpnext/hr/doctype/hr_settings/hr_settings.json
@@ -167,7 +167,7 @@
    "bold": 0, 
    "collapsible": 0, 
    "default": "1", 
-   "description": "", 
+   "description": "Emails salary slip to employee based on preferred email selected in Employee", 
    "fieldname": "email_salary_slip_to_employee", 
    "fieldtype": "Check", 
    "hidden": 0, 
@@ -226,7 +226,7 @@
  "issingle": 1, 
  "istable": 0, 
  "max_attachments": 0, 
- "modified": "2016-08-10 12:32:39.780599", 
+ "modified": "2016-09-21 11:28:50.687129", 
  "modified_by": "Administrator", 
  "module": "HR", 
  "name": "HR Settings", 
diff --git a/erpnext/hr/doctype/leave_allocation/leave_allocation.js b/erpnext/hr/doctype/leave_allocation/leave_allocation.js
index d01f1ba..b7e1f45 100755
--- a/erpnext/hr/doctype/leave_allocation/leave_allocation.js
+++ b/erpnext/hr/doctype/leave_allocation/leave_allocation.js
@@ -11,6 +11,13 @@
 			return {
 				query: "erpnext.controllers.queries.employee_query"
 			}
+		});
+		frm.set_query("leave_type", function() {
+			return {
+				filters: {
+					is_lwp: 0
+				}
+			}
 		})
 	},
 
diff --git a/erpnext/hr/doctype/leave_allocation/leave_allocation.py b/erpnext/hr/doctype/leave_allocation/leave_allocation.py
index 86ed187..3473fd8 100755
--- a/erpnext/hr/doctype/leave_allocation/leave_allocation.py
+++ b/erpnext/hr/doctype/leave_allocation/leave_allocation.py
@@ -23,6 +23,7 @@
 		self.validate_back_dated_allocation()
 		self.set_total_leaves_allocated()
 		self.validate_total_leaves_allocated()
+		self.validate_lwp()
 		set_employee_name(self)
 
 	def on_update_after_submit(self):
@@ -37,6 +38,10 @@
 	def validate_period(self):
 		if date_diff(self.to_date, self.from_date) <= 0:
 			frappe.throw(_("To date cannot be before from date"))
+			
+	def validate_lwp(self):
+		if frappe.db.get_value("Leave Type", self.leave_type, "is_lwp"):
+			frappe.throw(_("Leave Type {0} cannot be allocated since it is leave without pay").format(self.leave_type))
 
 	def validate_new_leaves_allocated_value(self):
 		"""validate that leave allocation is in multiples of 0.5"""
diff --git a/erpnext/hr/doctype/leave_application/leave_application.py b/erpnext/hr/doctype/leave_application/leave_application.py
index 0aabd27..c1a9a06 100755
--- a/erpnext/hr/doctype/leave_application/leave_application.py
+++ b/erpnext/hr/doctype/leave_application/leave_application.py
@@ -97,12 +97,19 @@
 				.format(formatdate(future_allocation[0].from_date), future_allocation[0].name))
 
 	def validate_salary_processed_days(self):
-		last_processed_pay_slip = frappe.db.sql("""select start_date, end_date from `tabSalary Slip`
-						where docstatus != 2 and employee = %s and ((%s between start_date and end_date) or (%s between start_date and end_date)) order by modified desc limit 1""",(self.employee, self.to_date, self.from_date))
+		if not frappe.db.get_value("Leave Type", self.leave_type, "is_lwp"):
+			return
+			
+		last_processed_pay_slip = frappe.db.sql("""
+			select start_date, end_date from `tabSalary Slip`
+			where docstatus != 2 and employee = %s 
+			and ((%s between start_date and end_date) or (%s between start_date and end_date)) 
+			order by modified desc limit 1
+		""",(self.employee, self.to_date, self.from_date))
 
 		if last_processed_pay_slip:
-			frappe.throw(_("Salary already processed for period between {0} and {1}, Leave application period cannot be between this date range.").
-					format(formatdate(last_processed_pay_slip[0][0]), formatdate(last_processed_pay_slip[0][1])))
+			frappe.throw(_("Salary already processed for period between {0} and {1}, Leave application period cannot be between this date range.").format(formatdate(last_processed_pay_slip[0][0]), 
+				formatdate(last_processed_pay_slip[0][1])))
 
 
 	def show_block_day_warning(self):
diff --git a/erpnext/hr/doctype/leave_application/leave_application_list.js b/erpnext/hr/doctype/leave_application/leave_application_list.js
index f82dfb2..966d1aa 100644
--- a/erpnext/hr/doctype/leave_application/leave_application_list.js
+++ b/erpnext/hr/doctype/leave_application/leave_application_list.js
@@ -1,5 +1,5 @@
 frappe.listview_settings['Leave Application'] = {
-	add_fields: ["status", "leave_type", "employee", "employee_name", "total_leave_days", "from_date"],
+	add_fields: ["status", "leave_type", "employee", "employee_name", "total_leave_days", "from_date", "to_date"],
 	filters:[["status","!=", "Rejected"]],
 	get_indicator: function(doc) {
 		return [__(doc.status), frappe.utils.guess_colour(doc.status),
diff --git a/erpnext/hr/doctype/process_payroll/process_payroll.js b/erpnext/hr/doctype/process_payroll/process_payroll.js
index 1c60a5f..6c057e1 100644
--- a/erpnext/hr/doctype/process_payroll/process_payroll.js
+++ b/erpnext/hr/doctype/process_payroll/process_payroll.js
@@ -1,6 +1,62 @@
 // Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
 // License: GNU General Public License v3. See license.txt
 
+frappe.ui.form.on("Process Payroll", {
+	refresh: function(frm) {
+		frm.disable_save();
+		frm.trigger("toggle_fields");
+		frm.trigger("set_month_dates");
+	},
+	
+	month: function(frm) {
+		frm.trigger("set_month_dates");
+	},
+	
+	fiscal_year: function(frm) {
+		frm.trigger("set_month_dates");
+	},
+	
+	salary_slip_based_on_timesheet: function(frm) {
+		frm.trigger("toggle_fields")
+	},
+
+	toggle_fields: function(frm) {
+		frm.toggle_display(['from_date','to_date'],
+			cint(frm.doc.salary_slip_based_on_timesheet)==1);
+		frm.toggle_display(['fiscal_year', 'month'],
+			cint(frm.doc.salary_slip_based_on_timesheet)==0);
+	},
+	
+	set_month_dates: function(frm) {
+		if (!frm.doc.salary_slip_based_on_timesheet){
+			frappe.call({
+				method:'erpnext.hr.doctype.process_payroll.process_payroll.get_month_details',
+				args:{
+					year: frm.doc.fiscal_year, 
+					month: frm.doc.month
+				},
+				callback: function(r){
+					if (r.message){
+						frm.set_value('from_date', r.message.month_start_date);
+						frm.set_value('to_date', r.message.month_end_date);			
+					}
+				}
+			})
+		}
+	}
+})
+
+cur_frm.cscript.onload = function(doc,cdt,cdn){
+		if(!doc.month) {
+			var today=new Date();
+			month = (today.getMonth()+01).toString();
+			if(month.length>1) doc.month = month;
+			else doc.month = '0'+month;
+		}
+		if(!doc.fiscal_year) doc.fiscal_year = sys_defaults['fiscal_year'];
+		refresh_many(['month', 'fiscal_year']);
+}
+
 cur_frm.cscript.display_activity_log = function(msg) {
 	if(!cur_frm.ss_html)
 		cur_frm.ss_html = $a(cur_frm.fields_dict['activity_log'].wrapper,'div');
@@ -26,7 +82,7 @@
 cur_frm.cscript.submit_salary_slip = function(doc, cdt, cdn) {
 	cur_frm.cscript.display_activity_log("");
 
-	frappe.confirm(__("Do you really want to Submit all Salary Slip for month {0} and year {1}", [doc.month, doc.fiscal_year]), function() {
+	frappe.confirm(__("Do you really want to Submit all Salary Slip for Account {0} from {1} to {2}", [doc.payment_account, doc.from_date, doc.to_date]), function() {
 		// clear all in locals
 		if(locals["Salary Slip"]) {
 			$.each(locals["Salary Slip"], function(name, d) {
@@ -44,22 +100,45 @@
 }
 
 cur_frm.cscript.make_bank_entry = function(doc,cdt,cdn){
-    if(doc.company && doc.month && doc.fiscal_year){
-    	cur_frm.cscript.make_jv(doc, cdt, cdn);
+    if(doc.company && doc.from_date && doc.to_date){
+		return cur_frm.cscript.reference_entry(doc,cdt,cdn);
     } else {
-  	  msgprint(__("Company, Month and Fiscal Year is mandatory"));
+  	  msgprint(__("Company, From Date and To Date is mandatory"));
     }
 }
 
-cur_frm.cscript.make_jv = function(doc, dt, dn) {
-	return $c_obj(doc, 'make_journal_entry', '', function(r) {
-		var doc = frappe.model.sync(r.message)[0];
-		frappe.set_route("Form", doc.doctype, doc.name);
+cur_frm.cscript.reference_entry = function(doc,cdt,cdn){
+	var dialog = new frappe.ui.Dialog({
+		title: __("Bank Transaction Reference"),
+		fields: [
+			{
+				"label": __("Reference Number"), 
+				"fieldname": "reference_number",
+				"fieldtype": "Data", 
+				"reqd": 1
+			},
+			{
+				"label": __("Reference Date"), 
+				"fieldname": "reference_date",
+				"fieldtype": "Date", 
+				"reqd": 1,
+				"default": get_today()
+			}
+		]
 	});
-}
-
-frappe.ui.form.on("Process Payroll", {
-	refresh: function(frm) {
-		frm.disable_save();
-	}
-})
+	dialog.set_primary_action(__("Make"), function() {
+		args = dialog.get_values();
+		if(!args) return;
+		dialog.hide();
+		return frappe.call({
+			doc: cur_frm.doc,
+			method: "make_journal_entry",
+			args: {"reference_number": args.reference_number, "reference_date":args.reference_date},
+			callback: function(r) {
+				if (r.message)
+					cur_frm.cscript.display_activity_log(r.message);
+			}
+		});
+	});
+	dialog.show();
+}
\ No newline at end of file
diff --git a/erpnext/hr/doctype/process_payroll/process_payroll.json b/erpnext/hr/doctype/process_payroll/process_payroll.json
index 8d8124b..13d3191 100644
--- a/erpnext/hr/doctype/process_payroll/process_payroll.json
+++ b/erpnext/hr/doctype/process_payroll/process_payroll.json
@@ -8,11 +8,13 @@
  "docstatus": 0, 
  "doctype": "DocType", 
  "document_type": "Other", 
+ "editable_grid": 0, 
  "fields": [
   {
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "section_break0", 
    "fieldtype": "Section Break", 
    "hidden": 0, 
@@ -37,6 +39,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "column_break0", 
    "fieldtype": "Column Break", 
    "hidden": 0, 
@@ -61,6 +64,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "company", 
    "fieldtype": "Link", 
    "hidden": 0, 
@@ -86,6 +90,59 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
+   "default": "Today", 
+   "fieldname": "posting_date", 
+   "fieldtype": "Date", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 0, 
+   "in_list_view": 0, 
+   "label": "Posting Date", 
+   "length": 0, 
+   "no_copy": 0, 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 0, 
+   "print_hide_if_no_value": 0, 
+   "read_only": 0, 
+   "report_hide": 0, 
+   "reqd": 1, 
+   "search_index": 0, 
+   "set_only_once": 0, 
+   "unique": 0
+  }, 
+  {
+   "allow_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
+   "fieldname": "column_break1", 
+   "fieldtype": "Column Break", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 0, 
+   "in_list_view": 0, 
+   "length": 0, 
+   "no_copy": 0, 
+   "permlevel": 0, 
+   "print_hide": 0, 
+   "print_hide_if_no_value": 0, 
+   "read_only": 0, 
+   "report_hide": 0, 
+   "reqd": 0, 
+   "search_index": 0, 
+   "set_only_once": 0, 
+   "unique": 0, 
+   "width": "50%"
+  }, 
+  {
+   "allow_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "branch", 
    "fieldtype": "Link", 
    "hidden": 0, 
@@ -111,30 +168,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
-   "fieldname": "column_break1", 
-   "fieldtype": "Column Break", 
-   "hidden": 0, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 0, 
-   "in_list_view": 0, 
-   "length": 0, 
-   "no_copy": 0, 
-   "permlevel": 0, 
-   "print_hide": 0, 
-   "print_hide_if_no_value": 0, 
-   "read_only": 0, 
-   "report_hide": 0, 
-   "reqd": 0, 
-   "search_index": 0, 
-   "set_only_once": 0, 
-   "unique": 0, 
-   "width": "50%"
-  }, 
-  {
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "department", 
    "fieldtype": "Link", 
    "hidden": 0, 
@@ -160,6 +194,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "designation", 
    "fieldtype": "Link", 
    "hidden": 0, 
@@ -185,6 +220,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "section_break_8", 
    "fieldtype": "Section Break", 
    "hidden": 0, 
@@ -209,9 +245,10 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "salary_slip_based_on_timesheet", 
    "fieldtype": "Check", 
-   "hidden": 1, 
+   "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
@@ -234,14 +271,15 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
-   "fieldname": "select_payroll_year_and_month", 
+   "columns": 0, 
+   "fieldname": "select_payroll_period", 
    "fieldtype": "Section Break", 
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 0, 
-   "label": "Select Payroll Year and Month", 
+   "label": "Select Payroll Period", 
    "length": 0, 
    "no_copy": 0, 
    "permlevel": 0, 
@@ -259,6 +297,33 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
+   "fieldname": "from_date", 
+   "fieldtype": "Data", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 0, 
+   "in_list_view": 0, 
+   "label": "From", 
+   "length": 0, 
+   "no_copy": 0, 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 0, 
+   "print_hide_if_no_value": 0, 
+   "read_only": 0, 
+   "report_hide": 0, 
+   "reqd": 0, 
+   "search_index": 0, 
+   "set_only_once": 0, 
+   "unique": 0
+  }, 
+  {
+   "allow_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "fiscal_year", 
    "fieldtype": "Link", 
    "hidden": 0, 
@@ -284,6 +349,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "column_break_11", 
    "fieldtype": "Column Break", 
    "hidden": 0, 
@@ -308,6 +374,33 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
+   "fieldname": "to_date", 
+   "fieldtype": "Data", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 0, 
+   "in_list_view": 0, 
+   "label": "To", 
+   "length": 0, 
+   "no_copy": 0, 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 0, 
+   "print_hide_if_no_value": 0, 
+   "read_only": 0, 
+   "report_hide": 0, 
+   "reqd": 0, 
+   "search_index": 0, 
+   "set_only_once": 0, 
+   "unique": 0
+  }, 
+  {
+   "allow_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "month", 
    "fieldtype": "Select", 
    "hidden": 0, 
@@ -333,32 +426,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
-   "default": "Today", 
-   "fieldname": "posting_date", 
-   "fieldtype": "Date", 
-   "hidden": 0, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 0,
-   "in_list_view": 0, 
-   "label": "Posting Date", 
-   "length": 0, 
-   "no_copy": 0, 
-   "permlevel": 0, 
-   "precision": "", 
-   "print_hide": 0, 
-   "print_hide_if_no_value": 0, 
-   "read_only": 0, 
-   "report_hide": 0, 
-   "reqd": 1, 
-   "search_index": 0, 
-   "set_only_once": 0, 
-   "unique": 0
-  }, 
-  {
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "process_payroll", 
    "fieldtype": "Section Break", 
    "hidden": 0, 
@@ -384,6 +452,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "column_break2", 
    "fieldtype": "Column Break", 
    "hidden": 0, 
@@ -408,6 +477,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "description": "Creates salary slip for above mentioned criteria.", 
    "fieldname": "create_salary_slip", 
    "fieldtype": "Button", 
@@ -433,6 +503,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "column_break3", 
    "fieldtype": "Column Break", 
    "hidden": 0, 
@@ -457,6 +528,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "description": "Submit all salary slips for the above selected criteria", 
    "fieldname": "submit_salary_slip", 
    "fieldtype": "Button", 
@@ -482,16 +554,19 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
-   "fieldname": "column_break4", 
-   "fieldtype": "Column Break", 
+   "columns": 0, 
+   "fieldname": "account", 
+   "fieldtype": "Section Break", 
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 0, 
+   "label": "Account", 
    "length": 0, 
    "no_copy": 0, 
    "permlevel": 0, 
+   "precision": "", 
    "print_hide": 0, 
    "print_hide_if_no_value": 0, 
    "read_only": 0, 
@@ -499,13 +574,42 @@
    "reqd": 0, 
    "search_index": 0, 
    "set_only_once": 0, 
-   "unique": 0, 
-   "width": "25%"
+   "unique": 0
   }, 
   {
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
+   "description": "Select Payment Account to make Bank Entry", 
+   "fieldname": "payment_account", 
+   "fieldtype": "Link", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 0, 
+   "in_list_view": 0, 
+   "label": "Payment Account", 
+   "length": 0, 
+   "no_copy": 0, 
+   "options": "Account", 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 0, 
+   "print_hide_if_no_value": 0, 
+   "read_only": 0, 
+   "report_hide": 0, 
+   "reqd": 0, 
+   "search_index": 0, 
+   "set_only_once": 0, 
+   "unique": 0
+  }, 
+  {
+   "allow_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
+   "depends_on": "payment_account", 
    "description": "Create Bank Entry for the total salary paid for the above selected criteria", 
    "fieldname": "make_bank_entry", 
    "fieldtype": "Button", 
@@ -531,6 +635,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "section_break2", 
    "fieldtype": "Section Break", 
    "hidden": 0, 
@@ -554,6 +659,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "activity_log", 
    "fieldtype": "HTML", 
    "hidden": 0, 
@@ -586,7 +692,7 @@
  "issingle": 1, 
  "istable": 0, 
  "max_attachments": 0, 
- "modified": "2016-09-19 15:12:54.090381", 
+ "modified": "2016-09-28 05:43:26.472928", 
  "modified_by": "Administrator", 
  "module": "HR", 
  "name": "Process Payroll", 
diff --git a/erpnext/hr/doctype/process_payroll/process_payroll.py b/erpnext/hr/doctype/process_payroll/process_payroll.py
index 3e6e3e0..f31ddfb 100644
--- a/erpnext/hr/doctype/process_payroll/process_payroll.py
+++ b/erpnext/hr/doctype/process_payroll/process_payroll.py
@@ -5,12 +5,13 @@
 import frappe
 from frappe.utils import cint, flt, nowdate
 from frappe import _
+import collections
+from collections import defaultdict
 
 from frappe.model.document import Document
 
 class ProcessPayroll(Document):
 
-
 	def get_emp_list(self):
 		"""
 			Returns list of active employees based on selected criteria
@@ -21,19 +22,20 @@
 
 		sal_struct = frappe.db.sql("""
 				select name from `tabSalary Structure`
-				where docstatus != 2 and
-				ifnull(salary_slip_based_on_timesheet,0) = 0""")
-
+				where docstatus != 2 and payment_account = '%(payment_account)s' and 
+				ifnull(salary_slip_based_on_timesheet,0) = %(salary_slip_based_on_timesheet)s"""% 
+				{"payment_account": self.payment_account, "salary_slip_based_on_timesheet":self.salary_slip_based_on_timesheet})
+		
 		if sal_struct:
 			cond += "and t2.parent IN %(sal_struct)s "
 
-		emp_list = frappe.db.sql("""
-			select t1.name
-			from `tabEmployee` t1, `tabSalary Structure Employee` t2
-			where t1.docstatus!=2 and t1.name = t2.employee
-		%s """% cond, {"sal_struct": sal_struct})
+			emp_list = frappe.db.sql("""
+				select t1.name
+				from `tabEmployee` t1, `tabSalary Structure Employee` t2
+				where t1.docstatus!=2 and t1.name = t2.employee
+			%s """% cond, {"sal_struct": sal_struct})
 
-		return emp_list
+			return emp_list
 
 
 	def get_filter_condition(self):
@@ -48,16 +50,15 @@
 
 
 	def get_joining_releiving_condition(self):
-		m = get_month_details(self.fiscal_year, self.month)
 		cond = """
-			and ifnull(t1.date_of_joining, '0000-00-00') <= '%(month_end_date)s'
-			and ifnull(t1.relieving_date, '2199-12-31') >= '%(month_start_date)s'
-		""" % m
+			and ifnull(t1.date_of_joining, '0000-00-00') <= '%(from_date)s'
+			and ifnull(t1.relieving_date, '2199-12-31') >= '%(to_date)s'
+		""" % {"from_date": self.from_date, "to_date": self.to_date}
 		return cond
 
 
 	def check_mandatory(self):
-		for f in ['company', 'month', 'fiscal_year']:
+		for f in ['company', 'from_date', 'to_date']:
 			if not self.get(f):
 				frappe.throw(_("Please set {0}").format(f))
 
@@ -65,27 +66,37 @@
 		"""
 			Creates salary slip for selected employees if already not created
 		"""
-
 		self.check_permission('write')
 
 		emp_list = self.get_emp_list()
 		ss_list = []
-		for emp in emp_list:
-			if not frappe.db.sql("""select name from `tabSalary Slip`
-					where docstatus!= 2 and employee = %s and month = %s and fiscal_year = %s and company = %s
-					""", (emp[0], self.month, self.fiscal_year, self.company)):
-				ss = frappe.get_doc({
-					"doctype": "Salary Slip",
-					"salary_slip_based_on_timesheet": 0,
-					"fiscal_year": self.fiscal_year,
-					"employee": emp[0],
-					"month": self.month,
-					"company": self.company,
-					"posting_date": self.posting_date,
-				})
-				ss.insert()
-				ss_list.append(ss.name)
-
+		if emp_list:
+			for emp in emp_list:
+				if not frappe.db.sql("""select name from `tabSalary Slip`
+						where docstatus!= 2 and employee = %s and start_date >= %s and end_date <= %s and company = %s
+						""", (emp[0], self.from_date, self.to_date, self.company)):
+					if self.salary_slip_based_on_timesheet:
+						ss = frappe.get_doc({
+							"doctype": "Salary Slip",
+							"salary_slip_based_on_timesheet": self.salary_slip_based_on_timesheet,
+							"start_date": self.from_date,
+							"end_date": self.to_date,
+							"employee": emp[0],
+							"company": self.company,
+							"posting_date": self.posting_date
+						})
+					else:
+						ss = frappe.get_doc({
+							"doctype": "Salary Slip",
+							"salary_slip_based_on_timesheet": self.salary_slip_based_on_timesheet,
+							"fiscal_year": self.fiscal_year,
+							"month": self.month,
+							"employee": emp[0],
+							"company": self.company,
+							"posting_date": self.posting_date
+						})	
+					ss.insert()
+					ss_list.append(ss.name)
 		return self.create_log(ss_list)
 
 
@@ -97,16 +108,17 @@
 		return log
 
 
-	def get_sal_slip_list(self):
+	def get_sal_slip_list(self, ss_status, as_dict=False):
 		"""
 			Returns list of salary slips based on selected criteria
-			which are not submitted
 		"""
 		cond = self.get_filter_condition()
+			
 		ss_list = frappe.db.sql("""
-			select t1.name from `tabSalary Slip` t1
-			where t1.docstatus = 0 and month = %s and fiscal_year = %s %s
-		""" % ('%s', '%s', cond), (self.month, self.fiscal_year))
+			select t1.name, t1.salary_structure from `tabSalary Slip` t1
+			where t1.docstatus = %s and t1.start_date >= %s and t1.end_date <= %s 
+			and (t1.journal_entry is null or t1.journal_entry = "") and ifnull(salary_slip_based_on_timesheet,0) = %s %s
+		""" % ('%s', '%s', '%s','%s', cond), (ss_status, self.from_date, self.to_date, self.salary_slip_based_on_timesheet), as_dict=as_dict)
 		return ss_list
 
 
@@ -116,16 +128,17 @@
 		"""
 		self.check_permission('write')
 
-		ss_list = self.get_sal_slip_list()
+		ss_list = self.get_sal_slip_list(ss_status=0)
 		not_submitted_ss = []
 		for ss in ss_list:
 			ss_obj = frappe.get_doc("Salary Slip",ss[0])
-			try:
-				ss_obj.submit()
-			except Exception,e:
+			if ss_obj.net_pay<0:
 				not_submitted_ss.append(ss[0])
-				frappe.msgprint(e)
-				continue
+			else:
+				try:
+					ss_obj.submit()
+				except Exception,e:
+					not_submitted_ss.append(ss[0])
 
 		return self.create_submit_log(ss_list, not_submitted_ss)
 
@@ -148,6 +161,7 @@
 				<b>Not Submitted Salary Slips: </b>\
 				<br><br> %s <br><br> \
 				Reason: <br>\
+				May be net pay is less than 0 <br>
 				May be company email id specified in employee master is not valid. <br> \
 				Please mention correct email id in employee master or if you don't want to \
 				send mail, uncheck 'Send Email' checkbox. <br>\
@@ -166,38 +180,105 @@
 		cond = self.get_filter_condition()
 		tot = frappe.db.sql("""
 			select sum(rounded_total) from `tabSalary Slip` t1
-			where t1.docstatus = 1 and month = %s and fiscal_year = %s %s
-		""" % ('%s', '%s', cond), (self.month, self.fiscal_year))
+			where t1.docstatus = 1 and start_date >= %s and end_date <= %s %s
+		""" % ('%s', '%s', cond), (self.from_date, self.to_date))
 
 		return flt(tot[0][0])
-
-
-	def make_journal_entry(self, salary_account = None):
+		
+	def get_salary_component_account(self, salary_component):
+		account = frappe.db.get_value("Salary Component Account",
+			{"parent": salary_component, "company": self.company}, "default_account")
+	
+		if not account:
+			frappe.throw(_("Please set default account in Salary Component {0}")
+				.format(salary_component))
+	
+		return account	
+		
+	def get_salary_components(self, component_type):
+		salary_slips = self.get_sal_slip_list(ss_status = 1, as_dict = True)
+		if salary_slips:
+			salary_components = frappe.db.sql("""select salary_component, amount, parentfield
+				from `tabSalary Detail` where parentfield = '%s' and parent in (%s)""" %
+				(component_type, ', '.join(['%s']*len(salary_slips))), tuple([d.name for d in salary_slips]), as_dict=True)				
+			return salary_components
+		
+	def get_salary_component_total(self, component_type = None):
+		salary_components = self.get_salary_components(component_type)
+		if salary_components:
+			component_dict = {}
+			for item in salary_components:			
+				component_dict[item['salary_component']] = component_dict.get(item['salary_component'], 0) + item['amount']
+			account_details = self.get_account(component_dict = component_dict)
+			return account_details
+			
+	def get_account(self, component_dict = None):
+		account_dict = {}
+		for s, a in component_dict.items():
+			account = self.get_salary_component_account(s)
+			account_dict[account] = account_dict.get(account, 0) + a		
+		return account_dict
+		
+	
+	def make_journal_entry(self, reference_number = None, reference_date = None):
 		self.check_permission('write')
+		earnings = self.get_salary_component_total(component_type = "earnings")
+		deductions = self.get_salary_component_total(component_type = "deductions")
+		jv_name = ""
 
-		amount = self.get_total_salary()
-		default_bank_account = frappe.db.get_value("Company", self.company,
-			"default_bank_account")
+		if earnings or deductions:
+			journal_entry = frappe.new_doc('Journal Entry')
+			journal_entry.voucher_type = 'Bank Entry'
+			journal_entry.user_remark = _('Payment of salary from {0} to {1}').format(self.from_date,
+				self.to_date)
+			journal_entry.company = self.company
+			journal_entry.posting_date = nowdate()
+		
+			account_amt_list = []
+			adjustment_amt = 0
+			for acc, amt in earnings.items():
+				adjustment_amt = adjustment_amt+amt
+				account_amt_list.append({
+						"account": acc,
+						"debit_in_account_currency": amt
+					})
+			for acc, amt in deductions.items():
+				adjustment_amt = adjustment_amt-amt
+				account_amt_list.append({
+						"account": acc,
+						"credit_in_account_currency": amt
+					})
+			account_amt_list.append({
+					"account": self.payment_account,
+					"credit_in_account_currency": adjustment_amt
+				})		
+			journal_entry.set("accounts", account_amt_list)
+			journal_entry.cheque_no = reference_number
+			journal_entry.cheque_date = reference_date
+			journal_entry.save()
+			try:
+				journal_entry.submit()
+				jv_name = journal_entry.name
+				self.update_salary_slip_status(jv_name = jv_name)
+			except Exception, e:
+				frappe.msgprint(e)
+		return self.create_jv_log(jv_name)
+	
 
-		journal_entry = frappe.new_doc('Journal Entry')
-		journal_entry.voucher_type = 'Bank Entry'
-		journal_entry.user_remark = _('Payment of salary for the month {0} and year {1}').format(self.month,
-			self.fiscal_year)
-		journal_entry.fiscal_year = self.fiscal_year
-		journal_entry.company = self.company
-		journal_entry.posting_date = nowdate()
-		journal_entry.set("accounts", [
-			{
-				"account": salary_account,
-				"debit_in_account_currency": amount
-			},
-			{
-				"account": default_bank_account,
-				"credit_in_account_currency": amount
-			},
-		])
+	def create_jv_log(self, jv_name):
+		log = "<p>" + _("No submitted Salary Slip found") + "</p>"
+		if jv_name:
+			log = "<b>" + _("Journal Entry Submitted") + "</b>\
+				%s" % '<br>''<a href="#Form/Journal Entry/{0}">{0}</a>'.format(jv_name)
+		return log	
+	
+	def update_salary_slip_status(self, jv_name = None):
+		ss_list = self.get_sal_slip_list(ss_status=1)
+		for ss in ss_list:
+			ss_obj = frappe.get_doc("Salary Slip",ss[0])
+			frappe.db.set_value("Salary Slip", ss_obj.name, "status", "Paid")
+			frappe.db.set_value("Salary Slip", ss_obj.name, "journal_entry", jv_name)
 
-		return journal_entry.as_dict()
 
 @frappe.whitelist()
 def get_month_details(year, month):
diff --git a/erpnext/hr/doctype/process_payroll/test_process_payroll.py b/erpnext/hr/doctype/process_payroll/test_process_payroll.py
new file mode 100644
index 0000000..4e3a588
--- /dev/null
+++ b/erpnext/hr/doctype/process_payroll/test_process_payroll.py
@@ -0,0 +1,27 @@
+# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
+# License: GNU General Public License v3. See license.txt
+from __future__ import unicode_literals
+
+import unittest
+import frappe
+import erpnext
+from frappe.utils import flt, add_months, cint, nowdate, getdate, add_days, random_string
+from frappe.utils.make_random import get_random
+
+class TestProcessPayroll(unittest.TestCase):
+	def test_process_payroll(self):
+		month = "11"
+		fiscal_year = "_Test Fiscal Year 2016"
+		payment_account = frappe.get_all("Account")[0].name
+		if not frappe.db.get_value("Salary Slip", {"fiscal_year": fiscal_year, "month": month}):
+			process_payroll = frappe.get_doc("Process Payroll", "Process Payroll")
+			process_payroll.company = erpnext.get_default_company()
+			process_payroll.month = month
+			process_payroll.fiscal_year = fiscal_year
+			process_payroll.from_date = "2016-11-01"
+			process_payroll.to_date = "2016-11-30"
+			process_payroll.payment_account = payment_account
+			process_payroll.create_sal_slip()
+			process_payroll.submit_salary_slip()
+			if process_payroll.get_sal_slip_list(ss_status = 1):
+				r = process_payroll.make_journal_entry(reference_number=random_string(10),reference_date=nowdate())
\ No newline at end of file
diff --git a/erpnext/hr/doctype/salary_component/salary_component.json b/erpnext/hr/doctype/salary_component/salary_component.json
index ca7378b..33fb793 100644
--- a/erpnext/hr/doctype/salary_component/salary_component.json
+++ b/erpnext/hr/doctype/salary_component/salary_component.json
@@ -70,6 +70,33 @@
    "bold": 0, 
    "collapsible": 0, 
    "columns": 0, 
+   "fieldname": "type", 
+   "fieldtype": "Select", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 0, 
+   "in_list_view": 0, 
+   "label": "Type", 
+   "length": 0, 
+   "no_copy": 0, 
+   "options": "Earning\nDeduction", 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 0, 
+   "print_hide_if_no_value": 0, 
+   "read_only": 0, 
+   "report_hide": 0, 
+   "reqd": 1, 
+   "search_index": 0, 
+   "set_only_once": 0, 
+   "unique": 0
+  }, 
+  {
+   "allow_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "description", 
    "fieldtype": "Small Text", 
    "hidden": 0, 
@@ -96,6 +123,31 @@
    "bold": 0, 
    "collapsible": 0, 
    "columns": 0, 
+   "fieldname": "section_break_5", 
+   "fieldtype": "Section Break", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 0, 
+   "in_list_view": 0, 
+   "length": 0, 
+   "no_copy": 0, 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 0, 
+   "print_hide_if_no_value": 0, 
+   "read_only": 0, 
+   "report_hide": 0, 
+   "reqd": 0, 
+   "search_index": 0, 
+   "set_only_once": 0, 
+   "unique": 0
+  }, 
+  {
+   "allow_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "accounts", 
    "fieldtype": "Table", 
    "hidden": 0, 
@@ -117,33 +169,6 @@
    "search_index": 0, 
    "set_only_once": 0, 
    "unique": 0
-  }, 
-  {
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "fieldname": "type", 
-   "fieldtype": "Select", 
-   "hidden": 0, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 0, 
-   "in_list_view": 0, 
-   "label": "Type", 
-   "length": 0, 
-   "no_copy": 0, 
-   "options": "Earning\nDeduction", 
-   "permlevel": 0, 
-   "precision": "", 
-   "print_hide": 0, 
-   "print_hide_if_no_value": 0, 
-   "read_only": 0, 
-   "report_hide": 0, 
-   "reqd": 1, 
-   "search_index": 0, 
-   "set_only_once": 0, 
-   "unique": 0
   }
  ], 
  "hide_heading": 0, 
@@ -157,7 +182,7 @@
  "issingle": 0, 
  "istable": 0, 
  "max_attachments": 0, 
- "modified": "2016-08-29 05:33:22.495594", 
+ "modified": "2016-08-31 08:08:47.359578", 
  "modified_by": "Administrator", 
  "module": "HR", 
  "name": "Salary Component", 
diff --git a/erpnext/hr/doctype/salary_slip/salary_slip.js b/erpnext/hr/doctype/salary_slip/salary_slip.js
index 4c60fba..bb27a42 100644
--- a/erpnext/hr/doctype/salary_slip/salary_slip.js
+++ b/erpnext/hr/doctype/salary_slip/salary_slip.js
@@ -13,6 +13,20 @@
 				}
 			}
 		}
+		frm.set_query("salary_component", "earnings", function() {
+			return {
+				filters: {
+					type: "earning"
+				}
+			}
+		})
+		frm.set_query("salary_component", "deductions", function() {
+			return {
+				filters: {
+					type: "deduction"
+				}
+			}
+		})
 	},
 
 	company: function(frm) {
diff --git a/erpnext/hr/doctype/salary_slip/salary_slip.json b/erpnext/hr/doctype/salary_slip/salary_slip.json
index c250cbd..40592c2 100644
--- a/erpnext/hr/doctype/salary_slip/salary_slip.json
+++ b/erpnext/hr/doctype/salary_slip/salary_slip.json
@@ -15,6 +15,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "column_break0", 
    "fieldtype": "Column Break", 
    "hidden": 0, 
@@ -40,14 +41,15 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "posting_date", 
    "fieldtype": "Date", 
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0,
+   "in_filter": 0, 
    "in_list_view": 0, 
-   "label": "posting Date", 
+   "label": "Posting Date", 
    "length": 0, 
    "no_copy": 0, 
    "permlevel": 0, 
@@ -65,6 +67,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "employee", 
    "fieldtype": "Link", 
    "hidden": 0, 
@@ -92,6 +95,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "employee_name", 
    "fieldtype": "Read Only", 
    "hidden": 0, 
@@ -119,6 +123,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "department", 
    "fieldtype": "Link", 
    "hidden": 0, 
@@ -146,6 +151,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "designation", 
    "fieldtype": "Link", 
    "hidden": 0, 
@@ -173,6 +179,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "branch", 
    "fieldtype": "Link", 
    "hidden": 0, 
@@ -200,6 +207,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "column_break1", 
    "fieldtype": "Column Break", 
    "hidden": 0, 
@@ -225,6 +233,60 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
+   "fieldname": "status", 
+   "fieldtype": "Select", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 0, 
+   "in_list_view": 0, 
+   "label": "Status", 
+   "length": 0, 
+   "no_copy": 0, 
+   "options": "Draft\nSubmitted\nPaid\nCancelled", 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 0, 
+   "print_hide_if_no_value": 0, 
+   "read_only": 1, 
+   "report_hide": 0, 
+   "reqd": 0, 
+   "search_index": 0, 
+   "set_only_once": 0, 
+   "unique": 0
+  }, 
+  {
+   "allow_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
+   "fieldname": "journal_entry", 
+   "fieldtype": "Data", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 0, 
+   "in_list_view": 0, 
+   "label": "Journal Entry", 
+   "length": 0, 
+   "no_copy": 0, 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 0, 
+   "print_hide_if_no_value": 0, 
+   "read_only": 1, 
+   "report_hide": 0, 
+   "reqd": 0, 
+   "search_index": 0, 
+   "set_only_once": 0, 
+   "unique": 0
+  }, 
+  {
+   "allow_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "company", 
    "fieldtype": "Link", 
    "hidden": 0, 
@@ -250,6 +312,7 @@
    "allow_on_submit": 1, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "letter_head", 
    "fieldtype": "Link", 
    "hidden": 0, 
@@ -275,6 +338,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "section_break_10", 
    "fieldtype": "Section Break", 
    "hidden": 0, 
@@ -299,6 +363,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "depends_on": "", 
    "fieldname": "salary_slip_based_on_timesheet", 
    "fieldtype": "Check", 
@@ -326,6 +391,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "depends_on": "", 
    "fieldname": "fiscal_year", 
    "fieldtype": "Link", 
@@ -354,6 +420,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "depends_on": "", 
    "fieldname": "month", 
    "fieldtype": "Select", 
@@ -383,6 +450,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "start_date", 
    "fieldtype": "Date", 
    "hidden": 0, 
@@ -408,6 +476,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "default": "Today", 
    "depends_on": "", 
    "fieldname": "end_date", 
@@ -435,6 +504,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "column_break_15", 
    "fieldtype": "Column Break", 
    "hidden": 0, 
@@ -459,6 +529,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "depends_on": "", 
    "fieldname": "salary_structure", 
    "fieldtype": "Link", 
@@ -486,6 +557,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "depends_on": "", 
    "fieldname": "total_days_in_month", 
    "fieldtype": "Float", 
@@ -513,6 +585,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "depends_on": "", 
    "fieldname": "leave_without_pay", 
    "fieldtype": "Float", 
@@ -540,6 +613,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "depends_on": "", 
    "fieldname": "payment_days", 
    "fieldtype": "Float", 
@@ -567,6 +641,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "depends_on": "", 
    "fieldname": "hourly_wages", 
    "fieldtype": "Section Break", 
@@ -593,6 +668,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "depends_on": "", 
    "fieldname": "timesheets", 
    "fieldtype": "Table", 
@@ -620,6 +696,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "column_break_20", 
    "fieldtype": "Column Break", 
    "hidden": 0, 
@@ -644,6 +721,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "total_working_hours", 
    "fieldtype": "Float", 
    "hidden": 0, 
@@ -669,6 +747,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "hour_rate", 
    "fieldtype": "Currency", 
    "hidden": 0, 
@@ -694,6 +773,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "depends_on": "", 
    "fieldname": "section_break_26", 
    "fieldtype": "Section Break", 
@@ -720,6 +800,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "bank_name", 
    "fieldtype": "Data", 
    "hidden": 0, 
@@ -746,6 +827,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "bank_account_no", 
    "fieldtype": "Data", 
    "hidden": 0, 
@@ -772,6 +854,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "column_break_01", 
    "fieldtype": "Column Break", 
    "hidden": 0, 
@@ -796,6 +879,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "amended_from", 
    "fieldtype": "Link", 
    "hidden": 0, 
@@ -823,6 +907,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "earning_deduction", 
    "fieldtype": "Section Break", 
    "hidden": 0, 
@@ -848,6 +933,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "earning", 
    "fieldtype": "Column Break", 
    "hidden": 0, 
@@ -874,6 +960,8 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
+   "depends_on": "", 
    "fieldname": "earnings", 
    "fieldtype": "Table", 
    "hidden": 0, 
@@ -901,6 +989,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "deduction", 
    "fieldtype": "Column Break", 
    "hidden": 0, 
@@ -927,6 +1016,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "deductions", 
    "fieldtype": "Table", 
    "hidden": 0, 
@@ -954,6 +1044,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "totals", 
    "fieldtype": "Section Break", 
    "hidden": 0, 
@@ -979,6 +1070,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "arrear_amount", 
    "fieldtype": "Currency", 
    "hidden": 0, 
@@ -1006,6 +1098,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "leave_encashment_amount", 
    "fieldtype": "Currency", 
    "hidden": 0, 
@@ -1033,6 +1126,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "gross_pay", 
    "fieldtype": "Currency", 
    "hidden": 0, 
@@ -1060,6 +1154,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "column_break_25", 
    "fieldtype": "Column Break", 
    "hidden": 0, 
@@ -1083,6 +1178,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "total_deduction", 
    "fieldtype": "Currency", 
    "hidden": 0, 
@@ -1110,6 +1206,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "description": "Gross Pay + Arrear Amount +Encashment Amount - Total Deduction", 
    "fieldname": "net_pay", 
    "fieldtype": "Currency", 
@@ -1138,6 +1235,7 @@
    "allow_on_submit": 0, 
    "bold": 1, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "rounded_total", 
    "fieldtype": "Currency", 
    "hidden": 0, 
@@ -1163,6 +1261,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "description": "Net Pay (in words) will be visible once you save the Salary Slip.", 
    "fieldname": "total_in_words", 
    "fieldtype": "Data", 
@@ -1198,7 +1297,7 @@
  "issingle": 0, 
  "istable": 0, 
  "max_attachments": 0, 
- "modified": "2016-09-19 15:15:06.809508", 
+ "modified": "2016-09-25 04:29:14.432800", 
  "modified_by": "Administrator", 
  "module": "HR", 
  "name": "Salary Slip", 
diff --git a/erpnext/hr/doctype/salary_slip/salary_slip.py b/erpnext/hr/doctype/salary_slip/salary_slip.py
index e761450..84a20d9 100644
--- a/erpnext/hr/doctype/salary_slip/salary_slip.py
+++ b/erpnext/hr/doctype/salary_slip/salary_slip.py
@@ -20,6 +20,7 @@
 		self.name = make_autoname('Sal Slip/' +self.employee + '/.#####')
 
 	def validate(self):
+		self.status = self.get_status()
 		self.validate_dates()
 		self.check_existing()
 		self.set_month_dates()
@@ -324,7 +325,8 @@
 			self.set(total_field, self.get(total_field) + flt(d.amount))
 
 	def calculate_net_pay(self):
-		self.calculate_component_amounts()
+		if self.salary_structure:
+			self.calculate_component_amounts()
 
 		disable_rounded_total = cint(frappe.db.get_value("Global Defaults", None, "disable_rounded_total"))
 
@@ -339,16 +341,21 @@
 			self.precision("net_pay") if disable_rounded_total else 0)
 
 	def on_submit(self):
-		self.update_status(self.name)
-		if(frappe.db.get_single_value("HR Settings", "email_salary_slip_to_employee")):
-			self.email_salary_slip()
+		if self.net_pay < 0:
+			frappe.throw(_("Net Pay cannot be less than 0"))
+		else:
+			self.set_status()
+			self.update_status(self.name)
+			if(frappe.db.get_single_value("HR Settings", "email_salary_slip_to_employee")):
+				self.email_salary_slip()
 
 	def on_cancel(self):
+		self.set_status()
 		self.update_status()
 
 	def email_salary_slip(self):
-		receiver = frappe.db.get_value("Employee", self.employee, "company_email") or \
-			frappe.db.get_value("Employee", self.employee, "personal_email")
+		receiver = frappe.db.get_value("Employee", self.employee, "prefered_email")
+
 		if receiver:
 			subj = 'Salary Slip - from {0} to {1}, fiscal year {2}'.format(self.start_date, self.end_date, self.fiscal_year)
 			frappe.sendmail([receiver], subject=subj, message = _("Please see attachment"),
@@ -364,3 +371,29 @@
 				timesheet.flags.ignore_validate_update_after_submit = True
 				timesheet.set_status()
 				timesheet.save()
+				
+	def set_status(self, status=None):
+		'''Get and update status'''
+		if not status:
+			status = self.get_status()
+		self.db_set("status", status)
+
+	def get_status(self):
+		if self.docstatus == 0:
+			status = "Draft"
+		elif self.docstatus == 1:
+			status = "Submitted"
+			if self.journal_entry:
+				status = "Paid"
+		elif self.docstatus == 2:
+			status = "Cancelled"
+		return status	
+
+def unlink_ref_doc_from_salary_slip(ref_no):
+	linked_ss = frappe.db.sql_list("""select name from `tabSalary Slip`
+	where journal_entry=%s and docstatus < 2""", (ref_no))
+	if linked_ss:
+		for ss in linked_ss:
+			ss_doc = frappe.get_doc("Salary Slip", ss)
+			frappe.db.set_value("Salary Slip", ss_doc.name, "status", "Submitted")
+			frappe.db.set_value("Salary Slip", ss_doc.name, "journal_entry", "")
diff --git a/erpnext/hr/doctype/salary_slip/test_salary_slip.py b/erpnext/hr/doctype/salary_slip/test_salary_slip.py
index 503996d..8bb9653 100644
--- a/erpnext/hr/doctype/salary_slip/test_salary_slip.py
+++ b/erpnext/hr/doctype/salary_slip/test_salary_slip.py
@@ -5,6 +5,7 @@
 import unittest
 import frappe
 import erpnext
+from frappe.utils.make_random import get_random
 from frappe.utils import today, now_datetime, getdate, cstr, add_years, nowdate
 from erpnext.hr.doctype.salary_structure.salary_structure import make_salary_slip
 from erpnext.hr.doctype.leave_application.test_leave_application import make_allocation_record
@@ -16,8 +17,6 @@
 		for dt in ["Leave Application", "Leave Allocation", "Salary Slip"]:
 			frappe.db.sql("delete from `tab%s`" % dt)
 
-		make_allocation_record(leave_type="_Test Leave Type LWP")
-		
 		self.make_holiday_list()
 		frappe.db.set_value("Company", erpnext.get_default_company(), "default_holiday_list", "Salary Slip Test Holiday List")
 
@@ -41,12 +40,12 @@
 
 		self.assertEquals(ss.total_days_in_month, 31)
 		self.assertEquals(ss.payment_days, 31)
-		self.assertEquals(ss.earnings[0].amount, 0)
-		self.assertEquals(ss.earnings[1].amount, 0)
-		self.assertEquals(ss.deductions[0].amount, 0)
-		self.assertEquals(ss.deductions[1].amount, 0)
-		self.assertEquals(ss.gross_pay, 0)
-		self.assertEquals(ss.net_pay, 0)
+		self.assertEquals(ss.earnings[0].amount, 5000)
+		self.assertEquals(ss.earnings[1].amount, 3000)
+		self.assertEquals(ss.deductions[0].amount, 5000)
+		self.assertEquals(ss.deductions[1].amount, 2500)
+		self.assertEquals(ss.gross_pay, 10500)
+		self.assertEquals(ss.net_pay, 3000)
 
 	def test_salary_slip_with_holidays_excluded(self):
 		frappe.db.set_value("HR Settings", None, "include_holidays_in_total_working_days", 0)
@@ -58,13 +57,13 @@
 
 		self.assertEquals(ss.total_days_in_month, 27)
 		self.assertEquals(ss.payment_days, 27)
-		self.assertEquals(ss.earnings[0].amount, 0)
+		self.assertEquals(ss.earnings[0].amount, 5000)
 		self.assertEquals(ss.earnings[0].default_amount, 5000)
-		self.assertEquals(ss.earnings[1].amount, 0)
-		self.assertEquals(ss.deductions[0].amount, 0)
-		self.assertEquals(ss.deductions[1].amount, 0)
-		self.assertEquals(ss.gross_pay, 0)
-		self.assertEquals(ss.net_pay, 0)
+		self.assertEquals(ss.earnings[1].amount, 3000)
+		self.assertEquals(ss.deductions[0].amount, 5000)
+		self.assertEquals(ss.deductions[1].amount, 2500)
+		self.assertEquals(ss.gross_pay, 10500)
+		self.assertEquals(ss.net_pay, 3000)
 		
 	def test_payment_days(self):
 		# Holidays not included in working days
@@ -144,6 +143,8 @@
 				"department": frappe.get_all("Department", fields="name")[0].name,
 				"gender": "Female",
 				"company_email": user,
+				"prefered_contact_email": "Company Email",
+				"prefered_email": user,
 				"status": "Active",
 				"employment_type": "Intern"
 			}).insert()
@@ -179,6 +180,7 @@
 			salary_slip.employee_name = frappe.get_value("Employee", {"name":frappe.db.get_value("Employee", {"user_id": user})}, "employee_name")
 			salary_slip.month = "12"
 			salary_slip.fiscal_year = "_Test Fiscal Year 2016"
+			salary_slip.posting_date = nowdate()
 			salary_slip.insert()
 			# salary_slip.submit()
 			salary_slip = salary_slip.name
@@ -202,7 +204,8 @@
 			"from_date": nowdate(),
 			"employees": get_employee_details(),
 			"earnings": get_earnings_component(),
-			"deductions": get_deductions_component()			
+			"deductions": get_deductions_component(),
+			"payment_account": get_random("Account")		
 		}).insert()
 	return sal_struct
 			
diff --git a/erpnext/hr/doctype/salary_structure/salary_structure.js b/erpnext/hr/doctype/salary_structure/salary_structure.js
index 0dce0a4..d3f362e 100755
--- a/erpnext/hr/doctype/salary_structure/salary_structure.js
+++ b/erpnext/hr/doctype/salary_structure/salary_structure.js
@@ -1,5 +1,6 @@
 // Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
 // License: GNU General Public License v3. See license.txt
+{% include "erpnext/public/js/controllers/accounts.js" %}
 
 cur_frm.add_fetch('employee', 'company', 'company');
 cur_frm.add_fetch('company', 'default_letter_head', 'letter_head');
diff --git a/erpnext/hr/doctype/salary_structure/salary_structure.json b/erpnext/hr/doctype/salary_structure/salary_structure.json
index 5abebef..4d14fdb 100644
--- a/erpnext/hr/doctype/salary_structure/salary_structure.json
+++ b/erpnext/hr/doctype/salary_structure/salary_structure.json
@@ -687,6 +687,111 @@
    "search_index": 0, 
    "set_only_once": 0, 
    "unique": 0
+  }, 
+  {
+   "allow_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
+   "fieldname": "account", 
+   "fieldtype": "Section Break", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 0, 
+   "in_list_view": 0, 
+   "label": "Account", 
+   "length": 0, 
+   "no_copy": 0, 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 0, 
+   "print_hide_if_no_value": 0, 
+   "read_only": 0, 
+   "report_hide": 0, 
+   "reqd": 0, 
+   "search_index": 0, 
+   "set_only_once": 0, 
+   "unique": 0
+  }, 
+  {
+   "allow_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
+   "fieldname": "mode_of_payment", 
+   "fieldtype": "Link", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 0, 
+   "in_list_view": 0, 
+   "label": "Mode of Payment", 
+   "length": 0, 
+   "no_copy": 0, 
+   "options": "Mode of Payment", 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 0, 
+   "print_hide_if_no_value": 0, 
+   "read_only": 0, 
+   "report_hide": 0, 
+   "reqd": 0, 
+   "search_index": 0, 
+   "set_only_once": 0, 
+   "unique": 0
+  }, 
+  {
+   "allow_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
+   "fieldname": "column_break_28", 
+   "fieldtype": "Column Break", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 0, 
+   "in_list_view": 0, 
+   "length": 0, 
+   "no_copy": 0, 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 0, 
+   "print_hide_if_no_value": 0, 
+   "read_only": 0, 
+   "report_hide": 0, 
+   "reqd": 0, 
+   "search_index": 0, 
+   "set_only_once": 0, 
+   "unique": 0
+  }, 
+  {
+   "allow_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
+   "fieldname": "payment_account", 
+   "fieldtype": "Link", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 0, 
+   "in_list_view": 0, 
+   "label": "Payment Account", 
+   "length": 0, 
+   "no_copy": 0, 
+   "options": "Account", 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 0, 
+   "print_hide_if_no_value": 0, 
+   "read_only": 0, 
+   "report_hide": 0, 
+   "reqd": 1, 
+   "search_index": 0, 
+   "set_only_once": 0, 
+   "unique": 0
   }
  ], 
  "hide_heading": 0, 
@@ -700,7 +805,7 @@
  "issingle": 0, 
  "istable": 0, 
  "max_attachments": 0, 
- "modified": "2016-08-23 12:49:41.258649", 
+ "modified": "2016-09-06 05:40:18.311581", 
  "modified_by": "Administrator", 
  "module": "HR", 
  "name": "Salary Structure", 
diff --git a/erpnext/hr/doctype/salary_structure/test_salary_structure.py b/erpnext/hr/doctype/salary_structure/test_salary_structure.py
index ef9231a..cd7ee47 100644
--- a/erpnext/hr/doctype/salary_structure/test_salary_structure.py
+++ b/erpnext/hr/doctype/salary_structure/test_salary_structure.py
@@ -5,6 +5,7 @@
 import frappe
 import unittest
 import erpnext
+from frappe.utils.make_random import get_random
 from frappe.utils import nowdate, add_days, add_years
 from erpnext.hr.doctype.salary_structure.salary_structure import make_salary_slip
 # test_records = frappe.get_test_records('Salary Structure')
@@ -85,11 +86,11 @@
 		if not sal_slip:
 			sal_slip = make_salary_slip_from_salary_structure(employee=frappe.get_value("Employee", {"employee_name":"test_employee@salary.com"}))
 			self.assertEquals(sal_slip.get("salary_structure"), 'Salary Structure Sample')
-			self.assertEquals(sal_slip.get("earnings")[0].amount, 0)
-			self.assertEquals(sal_slip.get("deductions")[0].amount, 0)
-			self.assertEquals(sal_slip.get("deductions")[1].amount, 0)
-			self.assertEquals(sal_slip.get("total_deduction"), 0)
-			self.assertEquals(sal_slip.get("net_pay"), 0)
+			self.assertEquals(sal_slip.get("earnings")[0].amount, 5000)
+			self.assertEquals(sal_slip.get("deductions")[0].amount, 5000)
+			self.assertEquals(sal_slip.get("deductions")[1].amount, 2500)
+			self.assertEquals(sal_slip.get("total_deduction"), 7500)
+			self.assertEquals(sal_slip.get("net_pay"), 7500)
 			
 		
 def make_salary_slip_from_salary_structure(employee):
@@ -98,6 +99,7 @@
 	sal_slip.employee_name = frappe.get_value("Employee", {"name":employee}, "employee_name")
 	sal_slip.month = "11"
 	sal_slip.fiscal_year = "_Test Fiscal Year 2016"
+	sal_slip.posting_date = nowdate()
 	sal_slip.insert()
 	sal_slip.submit()
 	return sal_slip	
@@ -111,7 +113,8 @@
 			"from_date": nowdate(),
 			"employees": get_employee_details(),
 			"earnings": get_earnings_component(),
-			"deductions": get_deductions_component()			
+			"deductions": get_deductions_component(),
+			"payment_account": frappe.get_all("Account")[0].name
 		}).insert()
 	return sal_struct
 			
@@ -123,7 +126,7 @@
 			"idx": 1
 			},
 			{"employee": frappe.get_value("Employee", {"employee_name":"test_employee_2@salary.com"}, "name"),
-			 "base": 2100,
+			 "base": 15000,
 			 "variable": 100,
 			 "idx": 2
 			}
@@ -148,7 +151,7 @@
 				{
 					"salary_component": 'HRA',
 					"abbr":'H',
-					"amount": 3000,
+					"amount": 10000,
 					"idx": 3
 				},
 				{
@@ -172,6 +175,7 @@
 				{
 					"salary_component": 'TDS',
 					"abbr":'T',
+					"condition": 'employment_type!="Intern"',
 					"formula": 'base*.5',
 					"idx": 2
 				},
diff --git a/erpnext/hr/report/monthly_salary_register/monthly_salary_register.py b/erpnext/hr/report/monthly_salary_register/monthly_salary_register.py
index 33f3784..2c6cf72 100644
--- a/erpnext/hr/report/monthly_salary_register/monthly_salary_register.py
+++ b/erpnext/hr/report/monthly_salary_register/monthly_salary_register.py
@@ -38,25 +38,25 @@
 	columns = [
 		_("Salary Slip ID") + ":Link/Salary Slip:150",_("Employee") + ":Link/Employee:120", _("Employee Name") + "::140", _("Branch") + ":Link/Branch:120",
 		_("Department") + ":Link/Department:120", _("Designation") + ":Link/Designation:120",
-		 _("Company") + ":Link/Company:120", _("Month") + "::80", _("Leave Without Pay") + ":Float:130", 
+		_("Company") + ":Link/Company:120", _("Month") + "::80", _("Leave Without Pay") + ":Float:130",
 		_("Payment Days") + ":Float:120"
 	]
 	
-	earning_types = frappe.db.sql_list("""select distinct salary_component from `tabSalary Detail`
-		where amount != 0 and parent in (%s)""" % 
-		(', '.join(['%s']*len(salary_slips))), tuple([d.name for d in salary_slips]))
-		
-	ded_types = frappe.db.sql_list("""select distinct salary_component from `tabSalary Detail`
-		where amount != 0 and parent in (%s)""" % 
-		(', '.join(['%s']*len(salary_slips))), tuple([d.name for d in salary_slips]))
-		
-	columns = columns + [(e + ":Currency:120") for e in earning_types] + \
-		["Arrear Amount:Currency:120", "Leave Encashment Amount:Currency:150", 
-		"Gross Pay:Currency:120"] + [(d + ":Currency:120") for d in ded_types] + \
-		["Total Deduction:Currency:120", "Net Pay:Currency:120"]
+	salary_components = {_("Earning"): [], _("Deduction"): []}
 
-	return columns, earning_types, ded_types
-	
+	for component in frappe.db.sql("""select distinct sd.salary_component, sc.type
+		from `tabSalary Detail` sd, `tabSalary Component` sc
+		where sc.name=sd.salary_component and sd.amount != 0 and sd.parent in (%s)""" %
+		(', '.join(['%s']*len(salary_slips))), tuple([d.name for d in salary_slips]), as_dict=1):
+		salary_components[component.type].append(component.salary_component)
+
+	columns = columns + [(e + ":Currency:120") for e in salary_components[_("Earning")]] + \
+		[ _("Arrear Amount") + ":Currency:120", _("Leave Encashment Amount") + ":Currency:150",
+		_("Gross Pay") + ":Currency:120"] + [(d + ":Currency:120") for d in salary_components[_("Deduction")]] + \
+		[_("Total Deduction") + ":Currency:120", _("Net Pay") + ":Currency:120"]
+
+	return columns, salary_components[_("Earning")], salary_components[_("Deduction")]
+
 def get_salary_slips(filters):
 	conditions, filters = get_conditions(filters)
 	salary_slips = frappe.db.sql("""select * from `tabSalary Slip` where docstatus = 1 %s
diff --git a/erpnext/manufacturing/doctype/production_order/production_order.py b/erpnext/manufacturing/doctype/production_order/production_order.py
index d598ee2..a0dc554 100644
--- a/erpnext/manufacturing/doctype/production_order/production_order.py
+++ b/erpnext/manufacturing/doctype/production_order/production_order.py
@@ -55,9 +55,11 @@
 				if not self.expected_delivery_date:
 					self.expected_delivery_date = so[0].delivery_date
 
-				self.project = so[0].project
+				if so[0].project:
+					self.project = so[0].project
 
-				self.validate_production_order_against_so()
+				if not self.material_request:
+					self.validate_production_order_against_so()
 			else:
 				frappe.throw(_("Sales Order {0} is not valid").format(self.sales_order))
 
@@ -115,7 +117,7 @@
 		'''Update status of production order if unknown'''
 		if not status:
 			status = self.get_status(status)
-			
+
 		if status != self.status:
 			self.db_set("status", status)
 
@@ -240,7 +242,7 @@
 			holidays[holiday_list] = holiday_list_days
 
 		return holidays[holiday_list]
-		
+
 	def make_time_logs(self, open_new=False):
 		"""Capacity Planning. Plan time logs based on earliest availablity of workstation after
 			Planned Start Date. Time logs will be created and remain in Draft mode and must be submitted
@@ -261,7 +263,7 @@
 			if d.workstation and d.status != 'Completed':
 				last_workstation_idx[d.workstation] = i # set last row index of workstation
 				self.set_start_end_time_for_workstation(d, workstation_list, last_workstation_idx.get(d.workstation))
-				
+
 				args = self.get_operations_data(d)
 				add_timesheet_detail(timesheet, args)
 				original_start_time = d.planned_start_time
@@ -366,7 +368,8 @@
 		if frappe.db.get_value("Item", self.production_item, "has_variants"):
 			frappe.throw(_("Production Order cannot be raised against a Item Template"), ItemHasVariantError)
 
-		validate_end_of_life(self.production_item)
+		if self.production_item:
+			validate_end_of_life(self.production_item)
 
 	def validate_qty(self):
 		if not self.qty > 0:
@@ -520,7 +523,7 @@
 	timesheet.production_order = production_order
 	return timesheet
 
-@frappe.whitelist()	
+@frappe.whitelist()
 def add_timesheet_detail(timesheet, args):
 	if isinstance(timesheet, unicode):
 		timesheet = frappe.get_doc('Timesheet', timesheet)
diff --git a/erpnext/manufacturing/doctype/production_order/production_order_list.js b/erpnext/manufacturing/doctype/production_order/production_order_list.js
index cce56cf..762beb0 100644
--- a/erpnext/manufacturing/doctype/production_order/production_order_list.js
+++ b/erpnext/manufacturing/doctype/production_order/production_order_list.js
@@ -1,6 +1,6 @@
 frappe.listview_settings['Production Order'] = {
 	add_fields: ["bom_no", "status", "sales_order", "qty",
-		"produced_qty", "expected_delivery_date"],
+		"produced_qty", "expected_delivery_date", "planned_start_date", "planned_end_date"],
 	filters: [["status", "!=", "Stopped"]],
 	get_indicator: function(doc) {
 		if(doc.status==="Submitted") {
diff --git a/erpnext/manufacturing/doctype/production_order/test_production_order.py b/erpnext/manufacturing/doctype/production_order/test_production_order.py
index d29544b..49db299 100644
--- a/erpnext/manufacturing/doctype/production_order/test_production_order.py
+++ b/erpnext/manufacturing/doctype/production_order/test_production_order.py
@@ -10,7 +10,9 @@
 from erpnext.manufacturing.doctype.production_order.production_order \
 	import make_stock_entry, ItemHasVariantError
 from erpnext.stock.doctype.stock_entry import test_stock_entry
+from erpnext.stock.doctype.item.test_item import get_total_projected_qty
 from erpnext.stock.utils import get_bin
+from erpnext.selling.doctype.sales_order.test_sales_order import make_sales_order
 
 class TestProductionOrder(unittest.TestCase):
 	def setUp(self):
@@ -172,6 +174,28 @@
 		self.assertEqual(self.bin1_at_start.projected_qty,
 			cint(bin1_on_cancel.projected_qty))
 
+	def test_projected_qty_for_production_and_sales_order(self):
+		before_production_order = get_bin(self.item, self.warehouse)
+		before_production_order.update_reserved_qty_for_production()
+
+		self.pro_order = make_prod_order_test_record(item="_Test FG Item", qty=2,
+			source_warehouse=self.warehouse)
+
+		after_production_order = get_bin(self.item, self.warehouse)
+
+		sales_order = make_sales_order(item = self.item, qty = 2)
+		after_sales_order = get_bin(self.item, self.warehouse)
+
+		self.assertEqual(cint(before_production_order.reserved_qty_for_production) + 2,
+			cint(after_sales_order.reserved_qty_for_production))
+		self.assertEqual(cint(before_production_order.projected_qty),
+			cint(after_sales_order.projected_qty) + 2)
+
+		total_projected_qty = get_total_projected_qty(self.item)
+
+		item_doc = frappe.get_doc('Item', self.item)
+		self.assertEqual(total_projected_qty,  item_doc.total_projected_qty)
+
 	def test_reserved_qty_for_production_on_stock_entry(self):
 		test_stock_entry.make_stock_entry(item_code="_Test Item",
 			target= self.warehouse, qty=100, basic_rate=100)
diff --git a/erpnext/modules.txt b/erpnext/modules.txt
index 609a3fe..4daf0eb 100644
--- a/erpnext/modules.txt
+++ b/erpnext/modules.txt
@@ -1,6 +1,7 @@
 Accounts
 CRM
 Buying
+Fleet Management
 Projects
 Selling
 Setup
diff --git a/erpnext/patches.txt b/erpnext/patches.txt
index 86580a2..e5cdb1a 100644
--- a/erpnext/patches.txt
+++ b/erpnext/patches.txt
@@ -282,7 +282,7 @@
 erpnext.patches.v7_0.convert_timelogbatch_to_timesheet
 erpnext.patches.v7_0.convert_timelog_to_timesheet
 erpnext.patches.v7_0.move_timelogbatch_from_salesinvoiceitem_to_salesinvoicetimesheet
-erpnext.patches.v7_0.remove_doctypes_and_reports
+erpnext.patches.v7_0.remove_doctypes_and_reports #2016-10-29
 erpnext.patches.v7_0.update_maintenance_module_in_doctype
 erpnext.patches.v7_0.update_prevdoc_values_for_supplier_quotation_item
 erpnext.patches.v7_0.rename_advance_table_fields
@@ -309,6 +309,7 @@
 erpnext.patches.v7_0.set_material_request_type_in_item
 erpnext.patches.v7_0.rename_examination_to_assessment
 erpnext.patches.v7_0.set_portal_settings
+erpnext.patches.v7_0.update_change_amount_account
 erpnext.patches.v7_0.repost_future_gle_for_purchase_invoice
 erpnext.patches.v7_0.fix_duplicate_icons
 erpnext.patches.v7_0.move_employee_parent_to_child_in_salary_structure
@@ -325,6 +326,19 @@
 execute:frappe.db.sql("update `tabTimesheet` ts, `tabEmployee` emp set ts.employee_name = emp.employee_name where emp.name = ts.employee and ts.employee_name is null and ts.employee is not null")
 erpnext.patches.v7_1.update_lead_source
 erpnext.patches.v7_1.fix_link_for_customer_from_lead
+execute:frappe.db.sql("delete from `tabTimesheet Detail` where NOT EXISTS (select name from `tabTimesheet` where name = `tabTimesheet Detail`.parent)")
 erpnext.patches.v7_0.update_mode_of_payment_type
+
+execute:frappe.reload_doctype('Employee') #2016-10-18
+execute:frappe.db.sql("update `tabEmployee` set prefered_contact_email = IFNULL(prefered_contact_email,'') ")
 execute:frappe.reload_doctype("Salary Slip")
 execute:frappe.db.sql("update `tabSalary Slip` set posting_date=creation")
+erpnext.patches.v7_1.update_portal_roles
+erpnext.patches.v7_1.set_total_amount_currency_in_je
+finally:erpnext.patches.v7_0.update_timesheet_communications
+erpnext.patches.v7_0.update_status_of_zero_amount_sales_order
+erpnext.patches.v7_1.add_field_for_task_dependent
+erpnext.patches.v7_0.repost_bin_qty_and_item_projected_qty
+erpnext.patches.v7_1.set_prefered_contact_email
+execute:frappe.db.sql("update `tabSingles` set value = 1 where field = 'unlink_payment_on_cancellation_of_invoice' and doctype = 'Accounts Settings'")
+execute:frappe.db.sql("update `tabStock Entry` set total_amount = null where purpose in('Repack', 'Manufacture')")
\ No newline at end of file
diff --git a/erpnext/patches/v7_0/create_warehouse_nestedset.py b/erpnext/patches/v7_0/create_warehouse_nestedset.py
index 8190fd7..8ae86f7 100644
--- a/erpnext/patches/v7_0/create_warehouse_nestedset.py
+++ b/erpnext/patches/v7_0/create_warehouse_nestedset.py
@@ -29,10 +29,11 @@
 			make_warehouse_nestedset(company)
 	else:
 		sle_against_companies = frappe.db.sql_list("""select distinct company from `tabStock Ledger Entry`""")
-		company = frappe.defaults.get_defaults().company
 
 		if len(sle_against_companies) == 1:
-			set_company_to_warehouse(company)
+			company = frappe.db.get_value("Company", sle_against_companies[0], 
+				fieldname=["name", "abbr"], as_dict=1)
+			set_company_to_warehouse(company.name)
 			make_warehouse_nestedset(company)
 
 		elif len(sle_against_companies) > 1:
diff --git a/erpnext/patches/v7_0/remove_doctypes_and_reports.py b/erpnext/patches/v7_0/remove_doctypes_and_reports.py
index 0a302b1..03461de 100644
--- a/erpnext/patches/v7_0/remove_doctypes_and_reports.py
+++ b/erpnext/patches/v7_0/remove_doctypes_and_reports.py
@@ -5,6 +5,22 @@
 		frappe.db.sql("""delete from `tabDocType`
 			where name in('Time Log Batch', 'Time Log Batch Detail', 'Time Log')""")
 
+	frappe.db.sql("""delete from `tabDocField` where parent in ('Time Log', 'Time Log Batch')""")
+	frappe.db.sql("""update `tabCustom Script` set dt = 'Timesheet' where dt = 'Time Log'""")
+
+	for data in frappe.db.sql(""" select label, fieldname from  `tabCustom Field` where dt = 'Time Log'""", as_dict=1):
+		custom_field = frappe.get_doc({
+			'doctype': 'Custom Field',
+			'label': data.label,
+			'dt': 'Timesheet Detail',
+			'fieldname': data.fieldname,
+			'fieldtype': data.fieldtype or "Data"
+		}).insert(ignore_permissions=True)
+
+	frappe.db.sql("""delete from `tabCustom Field` where dt = 'Time Log'""")
+	frappe.reload_doc('projects', 'doctype', 'timesheet')
+	frappe.reload_doc('projects', 'doctype', 'timesheet_detail')
+
 	report = "Daily Time Log Summary"
 	if frappe.db.exists("Report", report):
-		frappe.delete_doc('Report', report)
\ No newline at end of file
+		frappe.delete_doc('Report', report)
diff --git a/erpnext/patches/v7_0/repost_bin_qty_and_item_projected_qty.py b/erpnext/patches/v7_0/repost_bin_qty_and_item_projected_qty.py
new file mode 100644
index 0000000..97af20a
--- /dev/null
+++ b/erpnext/patches/v7_0/repost_bin_qty_and_item_projected_qty.py
@@ -0,0 +1,28 @@
+# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors
+# License: GNU General Public License v3. See license.txt
+
+from __future__ import unicode_literals
+import frappe
+from erpnext.stock.doctype.bin.bin import update_item_projected_qty
+
+def execute():
+	repost_bin_qty()
+	repost_item_projected_qty()
+
+def repost_bin_qty():
+	for bin in frappe.db.sql(""" select name from `tabBin` 
+		where (actual_qty + ordered_qty + indented_qty + planned_qty- reserved_qty - reserved_qty_for_production) != projected_qty """, as_dict=1):
+		bin_doc = frappe.get_doc('Bin', bin.name)
+		bin_doc.set_projected_qty()
+		bin_doc.db_set("projected_qty", bin_doc.projected_qty, update_modified = False)
+
+def repost_item_projected_qty():
+	for data in frappe.db.sql(""" select 
+			`tabBin`.item_code as item_code,
+			sum(`tabBin`.projected_qty) as projected_qty, 
+			`tabItem`.total_projected_qty as total_projected_qty 
+		from 
+			`tabBin`, `tabItem` 
+		where `tabBin`.item_code = `tabItem`.name 
+		group by `tabBin`.item_code having projected_qty <>  total_projected_qty """, as_dict=1):
+		update_item_projected_qty(data.item_code)
diff --git a/erpnext/patches/v7_0/set_portal_settings.py b/erpnext/patches/v7_0/set_portal_settings.py
index 3e3b729..d9b6400 100644
--- a/erpnext/patches/v7_0/set_portal_settings.py
+++ b/erpnext/patches/v7_0/set_portal_settings.py
@@ -9,10 +9,12 @@
 def execute():
 	for dt in ("assessment", "announcement", "course", "fees"):
 		frappe.reload_doc("schools", "doctype", dt)
-		
+
+	frappe.reload_doc('website', 'doctype', 'portal_menu_item')
+
 	frappe.get_doc('Portal Settings').sync_menu()
 	
 	if 'schools' in frappe.get_installed_apps():
 		domainify.setup_domain('Education')
 	else:
-		domainify.setup_sidebar_items(domainify.get_domain('Manufacturing'))
\ No newline at end of file
+		domainify.setup_sidebar_items(domainify.get_domain('Manufacturing'))
diff --git a/erpnext/patches/v7_0/update_change_amount_account.py b/erpnext/patches/v7_0/update_change_amount_account.py
new file mode 100644
index 0000000..1741095
--- /dev/null
+++ b/erpnext/patches/v7_0/update_change_amount_account.py
@@ -0,0 +1,19 @@
+from __future__ import unicode_literals
+import frappe
+from erpnext.accounts.doctype.journal_entry.journal_entry import get_default_bank_cash_account
+
+def execute():
+	frappe.reload_doc('accounts', 'doctype', 'sales_invoice')
+
+	for company in frappe.db.sql("""select company from `tabSales Invoice` 
+		where change_amount <> 0 and account_for_change_amount is null group by company""", as_list = 1):
+		cash_account = get_default_bank_cash_account(company[0], 'Cash').get('account')
+		if not cash_account:
+			bank_account = get_default_bank_cash_account(company[0], 'Bank').get('account')
+			cash_account = bank_account
+
+		if cash_account:
+			frappe.db.sql("""update `tabSales Invoice` 
+				set account_for_change_amount = %(cash_account)s where change_amount <> 0 
+				and company = %(company)s and account_for_change_amount is null""",
+				{'cash_account': cash_account, 'company': company[0]})
diff --git a/erpnext/patches/v7_0/update_status_of_zero_amount_sales_order.py b/erpnext/patches/v7_0/update_status_of_zero_amount_sales_order.py
new file mode 100644
index 0000000..9b2b247
--- /dev/null
+++ b/erpnext/patches/v7_0/update_status_of_zero_amount_sales_order.py
@@ -0,0 +1,7 @@
+from __future__ import unicode_literals
+import frappe
+
+def execute():
+	for data in frappe.get_all('Sales Order', fields = ["name"], filters = [["docstatus", "=", "1"], ["grand_total", "=", "0"]]):
+		sales_order = frappe.get_doc('Sales Order', data.name)
+		sales_order.set_status(update=True, update_modified = False)
\ No newline at end of file
diff --git a/erpnext/patches/v7_0/update_timesheet_communications.py b/erpnext/patches/v7_0/update_timesheet_communications.py
new file mode 100644
index 0000000..203471e
--- /dev/null
+++ b/erpnext/patches/v7_0/update_timesheet_communications.py
@@ -0,0 +1,27 @@
+from __future__ import unicode_literals
+import frappe
+
+def execute():
+	if frappe.db.table_exists("Time Log"):
+		timesheet = frappe.db.sql("""SELECT ts.name AS name, tl.name AS timelogname,
+				tl.modified AS modified, tl.modified_by AS modified_by, tl.creation AS creation, tl.owner AS owner
+			FROM 
+				`tabTimesheet` ts, `tabTimesheet Detail` tsd, `tabTime Log` tl
+			WHERE 
+				tsd.parent = ts.name AND tl.from_time = tsd.from_time AND tl.to_time = tsd.to_time 
+				AND tl.hours = tsd.hours AND tl.billing_rate = tsd.billing_rate AND tsd.idx=1 
+				AND tl.docstatus < 2""", as_dict=1)
+				
+		for data in timesheet:
+			frappe.db.sql(""" update `tabTimesheet` set creation = %(creation)s,
+				owner = %(owner)s, modified = %(modified)s, modified_by = %(modified_by)s
+				where name = %(name)s""", data)
+								
+			frappe.db.sql("""
+				update 
+					tabCommunication 
+				set 
+					reference_doctype = "Timesheet", reference_name = %(timesheet)s
+				where 
+					reference_doctype = "Time Log" and reference_name = %(timelog)s
+			""", {'timesheet': data.name, 'timelog': data.timelogname}, auto_commit=1)
diff --git a/erpnext/patches/v7_1/add_field_for_task_dependent.py b/erpnext/patches/v7_1/add_field_for_task_dependent.py
new file mode 100644
index 0000000..96daa13
--- /dev/null
+++ b/erpnext/patches/v7_1/add_field_for_task_dependent.py
@@ -0,0 +1,9 @@
+import frappe
+
+def execute():
+	frappe.reload_doctype('Task')
+	for t in frappe.get_all('Task', fields=['name']):
+		task = frappe.get_doc('Task', t.name)
+		task.update_depends_on()
+		if task.depends_on_tasks:
+			task.db_set('depends_on_tasks', task.depends_on_tasks, update_modified=False)
diff --git a/erpnext/patches/v7_1/set_prefered_contact_email.py b/erpnext/patches/v7_1/set_prefered_contact_email.py
new file mode 100644
index 0000000..d662e0d
--- /dev/null
+++ b/erpnext/patches/v7_1/set_prefered_contact_email.py
@@ -0,0 +1,19 @@
+from __future__ import unicode_literals
+import frappe
+
+def execute():
+	for d in frappe.get_all("Employee"):
+		employee = frappe.get_doc("Employee", d.name)
+		if employee.company_email:
+			employee.prefered_contact_email = "Company Email"
+			employee.prefered_email = employee.company_email
+		elif employee.personal_email:
+			employee.prefered_contact_email = "Personal Email"
+			employee.prefered_email = employee.personal_email
+		elif employee.user_id:
+			employee.prefered_contact_email = "User ID"
+			employee.prefered_email = employee.user_id
+		
+		employee.flags.ignore_mandatory = True
+		employee.flags.ignore_validate = True
+		employee.save()
\ No newline at end of file
diff --git a/erpnext/patches/v7_1/set_total_amount_currency_in_je.py b/erpnext/patches/v7_1/set_total_amount_currency_in_je.py
new file mode 100644
index 0000000..eb4a347
--- /dev/null
+++ b/erpnext/patches/v7_1/set_total_amount_currency_in_je.py
@@ -0,0 +1,23 @@
+import frappe
+from erpnext import get_default_currency
+
+def execute():
+	frappe.reload_doc("accounts", "doctype", "journal_entry")
+
+	frappe.db.sql(""" update `tabJournal Entry` set total_amount_currency = %s
+		where ifnull(multi_currency, 0) = 0
+		and (pay_to_recd_from is not null or pay_to_recd_from != "") """, get_default_currency())
+
+	for je in frappe.db.sql(""" select name from `tabJournal Entry` where multi_currency = 1
+		and (pay_to_recd_from is not null or pay_to_recd_from != "")""", as_dict=1):
+
+		doc = frappe.get_doc("Journal Entry", je.name)
+		for d in doc.get('accounts'):
+			if d.party_type and d.party:
+				total_amount_currency = d.account_currency
+
+			elif frappe.db.get_value("Account", d.account, "account_type") in ["Bank", "Cash"]:
+				total_amount_currency = d.account_currency
+
+		frappe.db.set_value("Journal Entry", je.name, "total_amount_currency",
+			total_amount_currency, update_modified=False)
diff --git a/erpnext/patches/v7_1/update_portal_roles.py b/erpnext/patches/v7_1/update_portal_roles.py
new file mode 100644
index 0000000..695f998
--- /dev/null
+++ b/erpnext/patches/v7_1/update_portal_roles.py
@@ -0,0 +1,20 @@
+import frappe
+
+def execute():
+	frappe.reload_doctype('Role')
+	for role_name in ('Customer', 'Supplier', 'Student'):
+		if frappe.db.exists('Role', role_name):
+			frappe.db.set_value('Role', role_name, 'desk_access', 0)
+		else:
+			frappe.get_doc(dict(doctype='Role', role_name=role_name, desk_access=0)).insert()
+
+
+	# set customer, supplier roles
+	for c in frappe.get_all('Contact', fields=['user'], filters={'ifnull(user, "")': ('!=', '')}):
+		user = frappe.get_doc('User', c.user)
+		user.set_default_roles()
+		user.flags.ignore_validate = True
+		user.flags.ignore_mandatory = True
+		user.save()
+
+
diff --git a/erpnext/portal/doctype/homepage/homepage.js b/erpnext/portal/doctype/homepage/homepage.js
index 100074f..0b07814 100644
--- a/erpnext/portal/doctype/homepage/homepage.js
+++ b/erpnext/portal/doctype/homepage/homepage.js
@@ -2,6 +2,14 @@
 // For license information, please see license.txt
 
 frappe.ui.form.on('Homepage', {
+	setup: function(frm) {
+		frm.fields_dict["products"].grid.get_field("item_code").get_query = function(){
+			return {
+				filters: {'show_in_website': 1}
+			}
+		}
+	},
+
 	refresh: function(frm) {
 
 	},
@@ -35,5 +43,12 @@
 				}
 			});
 		}
+	},
+
+	view: function(frm, cdt, cdn){
+		var child= locals[cdt][cdn]
+		if(child.item_code && frm.doc.products_url){
+			window.location.href = frm.doc.products_url + '/' + encodeURIComponent(child.item_code);
+		}
 	}
 });
diff --git a/erpnext/projects/doctype/project/project.js b/erpnext/projects/doctype/project/project.js
index ee2db46..5f48a93 100644
--- a/erpnext/projects/doctype/project/project.js
+++ b/erpnext/projects/doctype/project/project.js
@@ -43,9 +43,8 @@
 
 			if(frappe.model.can_read("Task")) {
 				frm.add_custom_button(__("Gantt Chart"), function() {
-					frappe.route_options = {"project": frm.doc.name,
-						"start": frm.doc.expected_start_date, "end": frm.doc.expected_end_date};
-					frappe.set_route("Gantt", "Task");
+					frappe.route_options = {"project": frm.doc.name};
+					frappe.set_route("List", "Task", "Gantt");
 				});
 			}
 
diff --git a/erpnext/projects/doctype/project/project_dashboard.py b/erpnext/projects/doctype/project/project_dashboard.py
index b36df88..0ac7d6f 100644
--- a/erpnext/projects/doctype/project/project_dashboard.py
+++ b/erpnext/projects/doctype/project/project_dashboard.py
@@ -1,25 +1,26 @@
 from frappe import _
 
-data = {
-	'heatmap': True,
-	'heatmap_message': _('This is based on the Time Sheets created against this project'),
-	'fieldname': 'project',
-	'transactions': [
-		{
-			'label': _('Project'),
-			'items': ['Task', 'Timesheet', 'Expense Claim', 'Issue']
-		},
-		{
-			'label': _('Material'),
-			'items': ['Material Request', 'BOM', 'Stock Entry']
-		},
-		{
-			'label': _('Sales'),
-			'items': ['Sales Order', 'Delivery Note', 'Sales Invoice']
-		},
-		{
-			'label': _('Purchase'),
-			'items': ['Purchase Order', 'Purchase Receipt', 'Purchase Invoice']
-		},
-	]
-}
+def get_data():
+	return {
+		'heatmap': True,
+		'heatmap_message': _('This is based on the Time Sheets created against this project'),
+		'fieldname': 'project',
+		'transactions': [
+			{
+				'label': _('Project'),
+				'items': ['Task', 'Timesheet', 'Expense Claim', 'Issue']
+			},
+			{
+				'label': _('Material'),
+				'items': ['Material Request', 'BOM', 'Stock Entry']
+			},
+			{
+				'label': _('Sales'),
+				'items': ['Sales Order', 'Delivery Note', 'Sales Invoice']
+			},
+			{
+				'label': _('Purchase'),
+				'items': ['Purchase Order', 'Purchase Receipt', 'Purchase Invoice']
+			},
+		]
+	}
diff --git a/erpnext/projects/doctype/task/task.json b/erpnext/projects/doctype/task/task.json
index 94ec8a1..46c8746 100644
--- a/erpnext/projects/doctype/task/task.json
+++ b/erpnext/projects/doctype/task/task.json
@@ -9,11 +9,13 @@
  "docstatus": 0, 
  "doctype": "DocType", 
  "document_type": "Setup", 
+ "editable_grid": 0, 
  "fields": [
   {
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "subject", 
    "fieldtype": "Data", 
    "hidden": 0, 
@@ -40,6 +42,7 @@
    "allow_on_submit": 0, 
    "bold": 1, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "project", 
    "fieldtype": "Link", 
    "hidden": 0, 
@@ -67,6 +70,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "column_break0", 
    "fieldtype": "Column Break", 
    "hidden": 0, 
@@ -93,6 +97,7 @@
    "allow_on_submit": 0, 
    "bold": 1, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "status", 
    "fieldtype": "Select", 
    "hidden": 0, 
@@ -120,6 +125,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "priority", 
    "fieldtype": "Select", 
    "hidden": 0, 
@@ -147,6 +153,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "section_break_10", 
    "fieldtype": "Section Break", 
    "hidden": 0, 
@@ -171,6 +178,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "exp_start_date", 
    "fieldtype": "Date", 
    "hidden": 0, 
@@ -197,6 +205,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "default": "0", 
    "description": "", 
    "fieldname": "expected_time", 
@@ -225,6 +234,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "column_break_11", 
    "fieldtype": "Column Break", 
    "hidden": 0, 
@@ -249,6 +259,7 @@
    "allow_on_submit": 0, 
    "bold": 1, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "exp_end_date", 
    "fieldtype": "Date", 
    "hidden": 0, 
@@ -275,6 +286,33 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
+   "fieldname": "progress", 
+   "fieldtype": "Percent", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 0, 
+   "in_list_view": 0, 
+   "label": "Progress", 
+   "length": 0, 
+   "no_copy": 0, 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 0, 
+   "print_hide_if_no_value": 0, 
+   "read_only": 0, 
+   "report_hide": 0, 
+   "reqd": 0, 
+   "search_index": 0, 
+   "set_only_once": 0, 
+   "unique": 0
+  }, 
+  {
+   "allow_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "section_break0", 
    "fieldtype": "Section Break", 
    "hidden": 0, 
@@ -300,6 +338,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "description", 
    "fieldtype": "Text Editor", 
    "hidden": 0, 
@@ -328,6 +367,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "section_break", 
    "fieldtype": "Section Break", 
    "hidden": 0, 
@@ -353,6 +393,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "depends_on", 
    "fieldtype": "Table", 
    "hidden": 0, 
@@ -379,6 +420,33 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
+   "fieldname": "depends_on_tasks", 
+   "fieldtype": "Read Only", 
+   "hidden": 1, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 0, 
+   "in_list_view": 0, 
+   "label": "depends_on_tasks", 
+   "length": 0, 
+   "no_copy": 0, 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 0, 
+   "print_hide_if_no_value": 0, 
+   "read_only": 0, 
+   "report_hide": 0, 
+   "reqd": 0, 
+   "search_index": 0, 
+   "set_only_once": 0, 
+   "unique": 0
+  }, 
+  {
+   "allow_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
    "description": "", 
    "fieldname": "actual", 
    "fieldtype": "Section Break", 
@@ -407,6 +475,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "act_start_date", 
    "fieldtype": "Date", 
    "hidden": 0, 
@@ -433,6 +502,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "default": "", 
    "description": "", 
    "fieldname": "actual_time", 
@@ -461,6 +531,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "column_break_15", 
    "fieldtype": "Column Break", 
    "hidden": 0, 
@@ -485,6 +556,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "act_end_date", 
    "fieldtype": "Date", 
    "hidden": 0, 
@@ -511,6 +583,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "section_break_17", 
    "fieldtype": "Section Break", 
    "hidden": 0, 
@@ -535,6 +608,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "total_costing_amount", 
    "fieldtype": "Currency", 
    "hidden": 0, 
@@ -562,6 +636,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "total_expense_claim", 
    "fieldtype": "Currency", 
    "hidden": 0, 
@@ -588,6 +663,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "column_break_20", 
    "fieldtype": "Column Break", 
    "hidden": 0, 
@@ -612,6 +688,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "total_billing_amount", 
    "fieldtype": "Currency", 
    "hidden": 0, 
@@ -637,6 +714,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "more_details", 
    "fieldtype": "Section Break", 
    "hidden": 0, 
@@ -661,6 +739,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "depends_on": "eval:doc.status == \"Closed\" || doc.status == \"Pending Review\"", 
    "fieldname": "review_date", 
    "fieldtype": "Date", 
@@ -688,6 +767,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "depends_on": "eval:doc.status == \"Closed\"", 
    "fieldname": "closing_date", 
    "fieldtype": "Date", 
@@ -715,6 +795,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "column_break_22", 
    "fieldtype": "Column Break", 
    "hidden": 0, 
@@ -738,6 +819,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "company", 
    "fieldtype": "Link", 
    "hidden": 0, 
@@ -772,7 +854,7 @@
  "istable": 0, 
  "max_attachments": 5, 
  "menu_index": 0, 
- "modified": "2016-06-20 17:31:00.798534", 
+ "modified": "2016-10-03 15:12:56.078675", 
  "modified_by": "Administrator", 
  "module": "Projects", 
  "name": "Task", 
@@ -788,6 +870,7 @@
    "export": 0, 
    "if_owner": 0, 
    "import": 0, 
+   "is_custom": 0, 
    "permlevel": 0, 
    "print": 1, 
    "read": 1, 
diff --git a/erpnext/projects/doctype/task/task.py b/erpnext/projects/doctype/task/task.py
index b918e3a..34b9ed5 100644
--- a/erpnext/projects/doctype/task/task.py
+++ b/erpnext/projects/doctype/task/task.py
@@ -29,6 +29,7 @@
 	def validate(self):
 		self.validate_dates()
 		self.validate_status()
+		self.update_depends_on()
 
 	def validate_dates(self):
 		if self.exp_start_date and self.exp_end_date and getdate(self.exp_start_date) > getdate(self.exp_end_date):
@@ -46,6 +47,12 @@
 			from frappe.desk.form.assign_to import clear
 			clear(self.doctype, self.name)
 
+	def update_depends_on(self):
+		depends_on_tasks = ""
+		for d in self.depends_on:
+			depends_on_tasks += d.task + ","
+		self.depends_on_tasks = depends_on_tasks
+
 	def on_update(self):
 		self.check_recursion()
 		self.reschedule_dependent_tasks()
@@ -156,5 +163,3 @@
 		and exp_end_date < CURDATE()
 		and `status` not in ('Closed', 'Cancelled')""")
 		
-
-		
diff --git a/erpnext/projects/doctype/task/task_list.js b/erpnext/projects/doctype/task/task_list.js
index d24e1ac..4bfa781 100644
--- a/erpnext/projects/doctype/task/task_list.js
+++ b/erpnext/projects/doctype/task/task_list.js
@@ -1,5 +1,6 @@
 frappe.listview_settings['Task'] = {
-	add_fields: ["project", "status", "priority", "exp_start_date", "exp_end_date", "subject"],
+	add_fields: ["project", "status", "priority", "exp_start_date",
+		"exp_end_date", "subject", "progress", "depends_on_tasks"],
 	filters: [["status", "=", "Open"]],
 	onload: function(listview) {
 		var method = "erpnext.projects.doctype.task.task.set_multiple_status";
diff --git a/erpnext/projects/doctype/timesheet/test_timesheet.py b/erpnext/projects/doctype/timesheet/test_timesheet.py
index 369be6d..98866ab 100644
--- a/erpnext/projects/doctype/timesheet/test_timesheet.py
+++ b/erpnext/projects/doctype/timesheet/test_timesheet.py
@@ -6,6 +6,7 @@
 import frappe
 import unittest
 import datetime
+from frappe.utils.make_random import get_random
 from frappe.utils import now_datetime, nowdate
 from erpnext.projects.doctype.timesheet.timesheet import OverlapError
 from erpnext.projects.doctype.timesheet.timesheet import make_salary_slip, make_sales_invoice
@@ -30,7 +31,7 @@
 
 		self.assertEquals(salary_slip.total_working_hours, 2)
 		self.assertEquals(salary_slip.hour_rate, 50)
-		self.assertEquals(salary_slip.net_pay, 50)
+		self.assertEquals(salary_slip.net_pay, 150)
 		self.assertEquals(salary_slip.timesheets[0].time_sheet, timesheet.name)
 		self.assertEquals(salary_slip.timesheets[0].working_hours, 2)
 		
@@ -78,7 +79,8 @@
 		salary_structure.from_date = nowdate()
 		salary_structure.salary_component = "Basic"
 		salary_structure.hour_rate = 50.0
-		salary_structure.company= "_Test Company"
+		salary_structure.company = "_Test Company"
+		salary_structure.payment_account = get_random("Account")
 
 		salary_structure.set('employees', [])
 		salary_structure.set('earnings', [])
diff --git a/erpnext/projects/doctype/timesheet/timesheet.py b/erpnext/projects/doctype/timesheet/timesheet.py
index 3b8f939..60435bc 100644
--- a/erpnext/projects/doctype/timesheet/timesheet.py
+++ b/erpnext/projects/doctype/timesheet/timesheet.py
@@ -163,7 +163,7 @@
 
 	def validate_dates(self):
 		for data in self.time_logs:
-			if time_diff_in_hours(data.to_time, data.from_time) < 0:
+			if data.from_time and data.to_time and time_diff_in_hours(data.to_time, data.from_time) < 0:
 				frappe.throw(_("To date cannot be before from date"))
 
 	def validate_time_logs(self):
@@ -345,6 +345,7 @@
 	target.salary_slip_based_on_timesheet = 1
 	target.start_date = doc.start_date
 	target.end_date = doc.end_date
+	target.posting_date = doc.modified
 
 @frappe.whitelist()
 def get_activity_cost(employee=None, activity_type=None):
diff --git a/erpnext/projects/doctype/timesheet/timesheet_calendar.js b/erpnext/projects/doctype/timesheet/timesheet_calendar.js
index a41ba38..ad81de6 100644
--- a/erpnext/projects/doctype/timesheet/timesheet_calendar.js
+++ b/erpnext/projects/doctype/timesheet/timesheet_calendar.js
@@ -1,10 +1,10 @@
 frappe.views.calendar["Timesheet"] = {
 	field_map: {
-		"start": "from_time",
-		"end": "to_time",
+		"start": "start_date",
+		"end": "end_date",
 		"name": "parent",
-		"id": "parent",
-		"title": "activity_type",
+		"id": "name",
+		"title": "name",
 		"allDay": "allDay",
 		"child_name": "name"
 	},
diff --git a/erpnext/projects/doctype/timesheet/timesheet_list.js b/erpnext/projects/doctype/timesheet/timesheet_list.js
index c538fa1..1b200f8 100644
--- a/erpnext/projects/doctype/timesheet/timesheet_list.js
+++ b/erpnext/projects/doctype/timesheet/timesheet_list.js
@@ -1,5 +1,5 @@
 frappe.listview_settings['Timesheet'] = {
-	add_fields: ["status", "total_hours"],
+	add_fields: ["status", "total_hours", "start_date", "end_date"],
 	get_indicator: function(doc) {
 		if (doc.status== "Billed") {
 			return [__("Billed"), "green", "status,=," + "Billed"]
diff --git a/erpnext/public/css/website.css b/erpnext/public/css/website.css
index ab3beb0..2bfcd3e 100644
--- a/erpnext/public/css/website.css
+++ b/erpnext/public/css/website.css
@@ -2,6 +2,9 @@
   font-size: 18px;
   line-height: 200%;
 }
+.web-page-content {
+  margin-bottom: 30px;
+}
 .item-stock {
   margin-bottom: 10px !important;
 }
diff --git a/erpnext/public/js/controllers/accounts.js b/erpnext/public/js/controllers/accounts.js
index 37ce5de..c1c3553 100644
--- a/erpnext/public/js/controllers/accounts.js
+++ b/erpnext/public/js/controllers/accounts.js
@@ -81,6 +81,14 @@
 	}
 })
 
+frappe.ui.form.on('Salary Structure', {
+	mode_of_payment: function(frm) {
+		get_payment_mode_account(frm, frm.doc.mode_of_payment, function(account){
+			frm.set_value("payment_account", account);
+		})
+	}
+})
+
 get_payment_mode_account = function(frm, mode_of_payment, callback){
 	return  frappe.call({
 		method: "erpnext.accounts.doctype.sales_invoice.sales_invoice.get_bank_cash_account",
diff --git a/erpnext/public/js/controllers/taxes_and_totals.js b/erpnext/public/js/controllers/taxes_and_totals.js
index 189b56f..f642da1 100644
--- a/erpnext/public/js/controllers/taxes_and_totals.js
+++ b/erpnext/public/js/controllers/taxes_and_totals.js
@@ -14,11 +14,11 @@
 			item.total_margin = item.price_list_rate + item.margin_rate_or_amount;
 		}
 
-		item.rate = flt(item.total_margin , 2);
+		item.rate = flt(item.total_margin , precision("rate", item));
 
 		if(item.discount_percentage){
 			discount_value = flt(item.total_margin) * flt(item.discount_percentage) / 100;
-			item.rate = flt((item.total_margin) - (discount_value), precision('rate'));
+			item.rate = flt((item.total_margin) - (discount_value), precision('rate', item));
 		}
 	},
 
diff --git a/erpnext/public/js/controllers/transaction.js b/erpnext/public/js/controllers/transaction.js
index a928a9a..0244cf3 100644
--- a/erpnext/public/js/controllers/transaction.js
+++ b/erpnext/public/js/controllers/transaction.js
@@ -979,7 +979,7 @@
 
 	make_payment_entry: function() {
 		return frappe.call({
-			method: "erpnext.accounts.doctype.payment_entry.payment_entry.get_payment_entry",
+			method: cur_frm.cscript.get_method_for_payment(),
 			args: {
 				"dt": cur_frm.doc.doctype,
 				"dn": cur_frm.doc.name
@@ -990,5 +990,18 @@
 				// cur_frm.refresh_fields()
 			}
 		});
+	},
+
+	get_method_for_payment: function(){
+		method = "erpnext.accounts.doctype.payment_entry.payment_entry.get_payment_entry"
+		if(cur_frm.doc.__onload && cur_frm.doc.__onload.make_payment_via_journal_entry){
+			if(in_list(['Sales Invoice', 'Purchase Invoice'],  cur_frm.doc.doctype)){
+				method = "erpnext.accounts.doctype.journal_entry.journal_entry.get_payment_entry_against_invoice"
+			}else {
+				method= "erpnext.accounts.doctype.journal_entry.journal_entry.get_payment_entry_against_order"
+			}
+		}
+
+		return method
 	}
 });
\ No newline at end of file
diff --git a/erpnext/public/js/shopping_cart.js b/erpnext/public/js/shopping_cart.js
index f5819a8..ace7fd8 100644
--- a/erpnext/public/js/shopping_cart.js
+++ b/erpnext/public/js/shopping_cart.js
@@ -10,7 +10,7 @@
 		$('.navbar li[data-label="User"] a')
 			.html('<i class="icon-fixed-width icon-user"></i> ' + full_name);
 	}
-	
+
 	// update login
 	shopping_cart.show_shoppingcart_dropdown();
 	shopping_cart.set_cart_count();
@@ -32,7 +32,7 @@
 			}
 		});
 	},
-	
+
 	update_cart: function(opts) {
 		if(!full_name || full_name==="Guest") {
 			if(localStorage) {
@@ -50,10 +50,10 @@
 				},
 				btn: opts.btn,
 				callback: function(r) {
-					shopping_cart.set_cart_count();	
+					shopping_cart.set_cart_count();
 					if (r.message.shopping_cart_menu) {
 						$('.shopping-cart-menu').html(r.message.shopping_cart_menu);
-					}					
+					}
 					if(opts.callback)
 						opts.callback(r);
 				}
@@ -63,11 +63,11 @@
 
 	set_cart_count: function() {
 		var cart_count = getCookie("cart_count");
-		
+
 		if(cart_count) {
-			$(".shopping-cart").toggle(true);	
-		}		
-		
+			$(".shopping-cart").toggleClass('hidden', true);
+		}
+
 		var $cart = $('.cart-icon');
 		var $badge = $cart.find("#cart-count");
 
@@ -88,7 +88,7 @@
 			$badge.remove();
 		}
 	},
-	
+
 	shopping_cart_update: function(item_code, newVal, cart_dropdown) {
 		frappe.freeze();
 		shopping_cart.update_cart({
@@ -103,20 +103,20 @@
 					$(".cart-tax-items").html(r.message.taxes);
 					if (cart_dropdown != true) {
 						$(".cart-icon").hide();
-					}					
+					}
 				}
 			},
 		});
 	},
-	
-	
+
+
 	bind_dropdown_cart_buttons: function() {
 		$(".cart-icon").on('click', '.number-spinner button', function () {
 			var btn = $(this),
 				input = btn.closest('.number-spinner').find('input'),
 				oldValue = input.val().trim(),
 				newVal = 0;
-			
+
 				if (btn.attr('data-dir') == 'up') {
 					newVal = parseInt(oldValue) + 1;
 				} else {
@@ -125,11 +125,11 @@
 					}
 			}
 			input.val(newVal);
-			var item_code = input.attr("data-item-code"); 
+			var item_code = input.attr("data-item-code");
 			shopping_cart.shopping_cart_update(item_code, newVal, true);
 			return false;
 		});
-		
+
 	},
-	
+
 });
diff --git a/erpnext/public/less/website.less b/erpnext/public/less/website.less
index 37d69e0..ce36e5f 100644
--- a/erpnext/public/less/website.less
+++ b/erpnext/public/less/website.less
@@ -8,6 +8,10 @@
 	line-height: 200%;
 }
 
+.web-page-content {
+	margin-bottom: 30px;
+}
+
 .item-stock {
 	margin-bottom: 10px !important;
 }
diff --git a/erpnext/schools/doctype/program_enrollment/program_enrollment.py b/erpnext/schools/doctype/program_enrollment/program_enrollment.py
index a15a070..02c6fe7 100644
--- a/erpnext/schools/doctype/program_enrollment/program_enrollment.py
+++ b/erpnext/schools/doctype/program_enrollment/program_enrollment.py
@@ -11,6 +11,8 @@
 class ProgramEnrollment(Document):
 	def validate(self):
 		self.validate_duplication()
+		if not self.student_name:
+			self.student_name = frappe.db.get_value("Student", self.student, "title")
 	
 	def on_submit(self):
 		self.update_student_joining_date()
diff --git a/erpnext/schools/doctype/student/student.json b/erpnext/schools/doctype/student/student.json
index 22e229c..c4b8667 100644
--- a/erpnext/schools/doctype/student/student.json
+++ b/erpnext/schools/doctype/student/student.json
@@ -386,7 +386,7 @@
    "collapsible": 0, 
    "columns": 0, 
    "fieldname": "nationality", 
-   "fieldtype": "Link", 
+   "fieldtype": "Data", 
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
@@ -395,7 +395,7 @@
    "label": "Nationality", 
    "length": 0, 
    "no_copy": 0, 
-   "options": "Country", 
+   "options": "", 
    "permlevel": 0, 
    "precision": "", 
    "print_hide": 0, 
@@ -762,7 +762,7 @@
  "istable": 0, 
  "max_attachments": 0, 
  "menu_index": 0, 
- "modified": "2016-09-08 06:29:27.702968", 
+ "modified": "2016-10-07 15:36:39.936505", 
  "modified_by": "Administrator", 
  "module": "Schools", 
  "name": "Student", 
@@ -779,6 +779,7 @@
    "export": 1, 
    "if_owner": 0, 
    "import": 0, 
+   "is_custom": 0, 
    "permlevel": 0, 
    "print": 1, 
    "read": 1, 
diff --git a/erpnext/schools/doctype/student/student_dashboard.py b/erpnext/schools/doctype/student/student_dashboard.py
index 9322986..6d95168 100644
--- a/erpnext/schools/doctype/student/student_dashboard.py
+++ b/erpnext/schools/doctype/student/student_dashboard.py
@@ -1,15 +1,16 @@
 from frappe import _
 
-data = {
-	'heatmap': True,
-	'heatmap_message': _('This is based on the attendance of this Student'),
-	'fieldname': 'student',
-	'transactions': [
-		{
-			'items': ['Student Log', 'Student Group', 'Student Attendance']
-		},
-		{
-			'items': ['Program Enrollment', 'Fees', 'Assessment']
-		}
-	]
-}
\ No newline at end of file
+def get_data():
+	return {
+		'heatmap': True,
+		'heatmap_message': _('This is based on the attendance of this Student'),
+		'fieldname': 'student',
+		'transactions': [
+			{
+				'items': ['Student Log', 'Student Group', 'Student Attendance']
+			},
+			{
+				'items': ['Program Enrollment', 'Fees', 'Assessment', 'Guardian']
+			}
+		]
+	}
\ No newline at end of file
diff --git a/erpnext/schools/doctype/student_admission/student_admission.js b/erpnext/schools/doctype/student_admission/student_admission.js
index 48f4c46..d7f7454 100644
--- a/erpnext/schools/doctype/student_admission/student_admission.js
+++ b/erpnext/schools/doctype/student_admission/student_admission.js
@@ -8,7 +8,7 @@
 			frm.refresh_field("route");
 		}
 	},
-	
+
 	academic_year: function(frm) {
 		frm.trigger("program");
 	}
diff --git a/erpnext/schools/doctype/student_admission/student_admission.json b/erpnext/schools/doctype/student_admission/student_admission.json
index e757ae1..77a3236 100644
--- a/erpnext/schools/doctype/student_admission/student_admission.json
+++ b/erpnext/schools/doctype/student_admission/student_admission.json
@@ -1,8 +1,8 @@
 {
  "allow_copy": 0, 
  "allow_import": 0, 
- "allow_rename": 0, 
- "autoname": "field:route", 
+ "allow_rename": 1, 
+ "autoname": "", 
  "beta": 0, 
  "creation": "2016-09-13 03:05:27.154713", 
  "custom": 0, 
@@ -121,6 +121,32 @@
    "bold": 0, 
    "collapsible": 0, 
    "columns": 0, 
+   "fieldname": "naming_series_for_student_applicant", 
+   "fieldtype": "Data", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 0, 
+   "in_list_view": 0, 
+   "label": "Naming Series (for Student Applicant)", 
+   "length": 0, 
+   "no_copy": 0, 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 0, 
+   "print_hide_if_no_value": 0, 
+   "read_only": 0, 
+   "report_hide": 0, 
+   "reqd": 0, 
+   "search_index": 0, 
+   "set_only_once": 0, 
+   "unique": 0
+  }, 
+  {
+   "allow_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "publish", 
    "fieldtype": "Check", 
    "hidden": 0, 
@@ -189,7 +215,7 @@
    "print_hide_if_no_value": 0, 
    "read_only": 0, 
    "report_hide": 0, 
-   "reqd": 1, 
+   "reqd": 0, 
    "search_index": 0, 
    "set_only_once": 0, 
    "unique": 0
@@ -389,7 +415,7 @@
  "issingle": 0, 
  "istable": 0, 
  "max_attachments": 0, 
- "modified": "2016-09-15 07:03:55.581346", 
+ "modified": "2016-10-04 02:44:28.480942", 
  "modified_by": "Administrator", 
  "module": "Schools", 
  "name": "Student Admission", 
@@ -406,6 +432,7 @@
    "export": 1, 
    "if_owner": 0, 
    "import": 0, 
+   "is_custom": 0, 
    "permlevel": 0, 
    "print": 1, 
    "read": 1, 
diff --git a/erpnext/schools/doctype/student_admission/student_admission.py b/erpnext/schools/doctype/student_admission/student_admission.py
index c4384e2..b0c7b55 100644
--- a/erpnext/schools/doctype/student_admission/student_admission.py
+++ b/erpnext/schools/doctype/student_admission/student_admission.py
@@ -11,15 +11,19 @@
 	website = frappe._dict(
 		template = "templates/generators/student_admission.html",
 		condition_field = "publish",
-		page_title_field = "route"
+		page_title_field = "title"
 	)
 
+	def autoname(self):
+		if not self.title:
+			self.title = self.get_title()
+		self.name = self.title
+
 	def get_context(self, context):
 		context.parents = [{'name': 'admissions', 'title': _('All Student Admissions') }]
-		
-	def validate(self):
-		if not self.title:
-			self.title = self.program + " admissions for " + self.academic_year
+
+	def get_title(self):
+		return _("Admissions for {0}").format(self.academic_term)
 
 def get_list_context(context):
 	context.title = _("Student Admissions")
diff --git a/erpnext/schools/doctype/student_applicant/student_applicant.js b/erpnext/schools/doctype/student_applicant/student_applicant.js
index 6857a66..36baa80 100644
--- a/erpnext/schools/doctype/student_applicant/student_applicant.js
+++ b/erpnext/schools/doctype/student_applicant/student_applicant.js
@@ -4,22 +4,22 @@
 			frm.add_custom_button(__("Approve"), function() {
 				frm.set_value("application_status", "Approved");
 				frm.save_or_update();
-				
-			}).addClass("btn-primary");
-			
+
+			}, 'Actions');
+
 			frm.add_custom_button(__("Reject"), function() {
 				frm.set_value("application_status", "Rejected");
 				frm.save_or_update();
-			}).addClass("btn-danger");
+			}, 'Actions');
 		}
-		
+
 		if(frm.doc.application_status== "Approved" && frm.doc.docstatus== 1 ) {
 			frm.add_custom_button(__("Enroll"), function() {
 				frm.events.enroll(frm)
 			}).addClass("btn-primary");
 		}
 	},
-	
+
 	enroll: function(frm) {
 		frappe.model.open_mapped_doc({
 			method: "erpnext.schools.api.enroll_student",
diff --git a/erpnext/schools/doctype/student_applicant/student_applicant.json b/erpnext/schools/doctype/student_applicant/student_applicant.json
index ae99488..e60a54e 100644
--- a/erpnext/schools/doctype/student_applicant/student_applicant.json
+++ b/erpnext/schools/doctype/student_applicant/student_applicant.json
@@ -6,10 +6,12 @@
  "beta": 0, 
  "creation": "2015-09-11 11:50:09.740807", 
  "custom": 0, 
+ "default_print_format": "", 
  "docstatus": 0, 
  "doctype": "DocType", 
  "document_type": "Document", 
  "editable_grid": 0, 
+ "engine": "InnoDB", 
  "fields": [
   {
    "allow_on_submit": 0, 
@@ -121,6 +123,32 @@
    "bold": 0, 
    "collapsible": 0, 
    "columns": 0, 
+   "fieldname": "paid", 
+   "fieldtype": "Check", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 0, 
+   "in_list_view": 0, 
+   "label": "Paid", 
+   "length": 0, 
+   "no_copy": 0, 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 0, 
+   "print_hide_if_no_value": 0, 
+   "read_only": 0, 
+   "report_hide": 0, 
+   "reqd": 0, 
+   "search_index": 0, 
+   "set_only_once": 0, 
+   "unique": 0
+  }, 
+  {
+   "allow_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "column_break_8", 
    "fieldtype": "Column Break", 
    "hidden": 0, 
@@ -156,7 +184,7 @@
    "label": "Naming Series", 
    "length": 0, 
    "no_copy": 0, 
-   "options": "AP.", 
+   "options": "AP", 
    "permlevel": 0, 
    "precision": "", 
    "print_hide": 0, 
@@ -256,6 +284,33 @@
    "bold": 0, 
    "collapsible": 0, 
    "columns": 0, 
+   "fieldname": "student_admission", 
+   "fieldtype": "Link", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 0, 
+   "in_list_view": 0, 
+   "label": "Student Admission", 
+   "length": 0, 
+   "no_copy": 0, 
+   "options": "Student Admission", 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 0, 
+   "print_hide_if_no_value": 0, 
+   "read_only": 0, 
+   "report_hide": 0, 
+   "reqd": 0, 
+   "search_index": 0, 
+   "set_only_once": 0, 
+   "unique": 0
+  }, 
+  {
+   "allow_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "image", 
    "fieldtype": "Attach Image", 
    "hidden": 1, 
@@ -865,7 +920,7 @@
  "istable": 0, 
  "max_attachments": 0, 
  "menu_index": 0, 
- "modified": "2016-09-08 06:40:54.242322", 
+ "modified": "2016-10-10 06:19:19.319038", 
  "modified_by": "Administrator", 
  "module": "Schools", 
  "name": "Student Applicant", 
@@ -882,6 +937,7 @@
    "export": 1, 
    "if_owner": 0, 
    "import": 1, 
+   "is_custom": 0, 
    "permlevel": 0, 
    "print": 1, 
    "read": 1, 
@@ -891,6 +947,27 @@
    "share": 1, 
    "submit": 1, 
    "write": 1
+  }, 
+  {
+   "amend": 0, 
+   "apply_user_permissions": 0, 
+   "cancel": 0, 
+   "create": 0, 
+   "delete": 0, 
+   "email": 1, 
+   "export": 0, 
+   "if_owner": 1, 
+   "import": 0, 
+   "is_custom": 0, 
+   "permlevel": 0, 
+   "print": 1, 
+   "read": 1, 
+   "report": 0, 
+   "role": "Guest", 
+   "set_user_permissions": 0, 
+   "share": 0, 
+   "submit": 0, 
+   "write": 0
   }
  ], 
  "quick_entry": 1, 
diff --git a/erpnext/schools/doctype/student_applicant/student_applicant.py b/erpnext/schools/doctype/student_applicant/student_applicant.py
index 5ef72cb..047c702 100644
--- a/erpnext/schools/doctype/student_applicant/student_applicant.py
+++ b/erpnext/schools/doctype/student_applicant/student_applicant.py
@@ -8,6 +8,18 @@
 from frappe.model.document import Document
 
 class StudentApplicant(Document):
+	def autoname(self):
+		from frappe.model.naming import set_name_by_naming_series
+		if self.student_admission:
+			naming_series = frappe.db.get_value('Student Admission', self.student_admission,
+				'naming_series_for_student_applicant')
+			print naming_series
+
+			if naming_series:
+				self.naming_series = naming_series
+
+		set_name_by_naming_series(self)
+
 	def validate(self):
 		self.title = " ".join(filter(None, [self.first_name, self.middle_name, self.last_name]))
 
@@ -15,3 +27,6 @@
 		student = frappe.get_list("Student",  filters= {"student_applicant": self.name})
 		if student:
 			frappe.throw(_("Cannot change status as student {0} is linked with student application {1}").format(student[0].name, self.name))
+
+	def on_payment_authorized(self, *args, **kwargs):
+		self.db_set('paid', 1)
diff --git a/erpnext/schools/doctype/student_applicant/student_applicant_list.js b/erpnext/schools/doctype/student_applicant/student_applicant_list.js
index 43402d8..817a728 100644
--- a/erpnext/schools/doctype/student_applicant/student_applicant_list.js
+++ b/erpnext/schools/doctype/student_applicant/student_applicant_list.js
@@ -1,7 +1,11 @@
 frappe.listview_settings['Student Applicant'] = {
-	add_fields: [ "application_status"],
+	add_fields: [ "application_status", 'paid'],
+	has_indicator_for_draft: 1,
 	get_indicator: function(doc) {
-		if (doc.application_status=="Applied") {
+		if (doc.paid) {
+			return [__("Paid"), "green", "paid,=,Yes"];
+		}
+		else if (doc.application_status=="Applied") {
 			return [__("Applied"), "orange", "application_status,=,Applied"];
 		}
 		else if (doc.application_status=="Approved") {
diff --git a/erpnext/selling/doctype/customer/customer_dashboard.py b/erpnext/selling/doctype/customer/customer_dashboard.py
index b65c199..681b04a 100644
--- a/erpnext/selling/doctype/customer/customer_dashboard.py
+++ b/erpnext/selling/doctype/customer/customer_dashboard.py
@@ -1,25 +1,26 @@
 from frappe import _
 
-data = {
-	'heatmap': True,
-	'heatmap_message': _('This is based on transactions against this Customer. See timeline below for details'),
-	'fieldname': 'customer',
-	'transactions': [
-		{
-			'label': _('Pre Sales'),
-			'items': ['Opportunity', 'Quotation']
-		},
-		{
-			'label': _('Orders'),
-			'items': ['Sales Order', 'Delivery Note', 'Sales Invoice']
-		},
-		{
-			'label': _('Support'),
-			'items': ['Issue']
-		},
-		{
-			'label': _('Projects'),
-			'items': ['Project']
-		}
-	]
-}
\ No newline at end of file
+def get_data():
+	return {
+		'heatmap': True,
+		'heatmap_message': _('This is based on transactions against this Customer. See timeline below for details'),
+		'fieldname': 'customer',
+		'transactions': [
+			{
+				'label': _('Pre Sales'),
+				'items': ['Opportunity', 'Quotation']
+			},
+			{
+				'label': _('Orders'),
+				'items': ['Sales Order', 'Delivery Note', 'Sales Invoice']
+			},
+			{
+				'label': _('Support'),
+				'items': ['Issue']
+			},
+			{
+				'label': _('Projects'),
+				'items': ['Project']
+			}
+		]
+	}
\ No newline at end of file
diff --git a/erpnext/selling/doctype/quotation/quotation_dashboard.py b/erpnext/selling/doctype/quotation/quotation_dashboard.py
index 80dc6aa..e572a92 100644
--- a/erpnext/selling/doctype/quotation/quotation_dashboard.py
+++ b/erpnext/selling/doctype/quotation/quotation_dashboard.py
@@ -1,11 +1,12 @@
 from frappe import _
 
-data = {
-	'fieldname': 'prevdoc_docname',
-	'transactions': [
-		{
-			'label': _('Related'),
-			'items': ['Sales Order']
-		},
-	]
-}
\ No newline at end of file
+def get_data():
+	return {
+		'fieldname': 'prevdoc_docname',
+		'transactions': [
+			{
+				'label': _('Related'),
+				'items': ['Sales Order']
+			},
+		]
+	}
\ No newline at end of file
diff --git a/erpnext/selling/doctype/sales_order/sales_order.py b/erpnext/selling/doctype/sales_order/sales_order.py
index 0435141..acae0e5 100644
--- a/erpnext/selling/doctype/sales_order/sales_order.py
+++ b/erpnext/selling/doctype/sales_order/sales_order.py
@@ -442,6 +442,11 @@
 		target.amount = flt(source.amount) - flt(source.billed_amt)
 		target.base_amount = target.amount * flt(source_parent.conversion_rate)
 		target.qty = target.amount / flt(source.rate) if (source.rate and source.billed_amt) else source.qty
+		
+		item = frappe.db.get_value("Item", target.item_code, ["item_group", "selling_cost_center"], as_dict=1)
+		target.cost_center = frappe.db.get_value("Project", source_parent.project, "cost_center") \
+			or item.selling_cost_center \
+			or frappe.db.get_value("Item Group", item.item_group, "default_cost_center")
 
 	doclist = get_mapped_doc("Sales Order", source_name, {
 		"Sales Order": {
diff --git a/erpnext/selling/doctype/sales_order/sales_order_dashboard.py b/erpnext/selling/doctype/sales_order/sales_order_dashboard.py
index feda39d..51f81f8 100644
--- a/erpnext/selling/doctype/sales_order/sales_order_dashboard.py
+++ b/erpnext/selling/doctype/sales_order/sales_order_dashboard.py
@@ -1,33 +1,34 @@
 from frappe import _
 
-data = {
-	'fieldname': 'sales_order',
-	'non_standard_fieldnames': {
-		'Delivery Note': 'against_sales_order',
-	},
-	'internal_links': {
-		'Quotation': ['items', 'prevdoc_docname']
-	},
-	'transactions': [
-		{
-			'label': _('Fulfillment'),
-			'items': ['Sales Invoice', 'Delivery Note']
+def get_data():
+	return {
+		'fieldname': 'sales_order',
+		'non_standard_fieldnames': {
+			'Delivery Note': 'against_sales_order',
 		},
-		{
-			'label': _('Purchasing'),
-			'items': ['Material Request', 'Purchase Order']
+		'internal_links': {
+			'Quotation': ['items', 'prevdoc_docname']
 		},
-		{
-			'label': _('Projects'),
-			'items': ['Project']
-		},
-		{
-			'label': _('Manufacturing'),
-			'items': ['Production Order']
-		},
-		{
-			'label': _('Reference'),
-			'items': ['Quotation']
-		},
-	]
-}
\ No newline at end of file
+		'transactions': [
+			{
+				'label': _('Fulfillment'),
+				'items': ['Sales Invoice', 'Delivery Note']
+			},
+			{
+				'label': _('Purchasing'),
+				'items': ['Material Request', 'Purchase Order']
+			},
+			{
+				'label': _('Projects'),
+				'items': ['Project']
+			},
+			{
+				'label': _('Manufacturing'),
+				'items': ['Production Order']
+			},
+			{
+				'label': _('Reference'),
+				'items': ['Quotation']
+			},
+		]
+	}
\ No newline at end of file
diff --git a/erpnext/selling/doctype/sales_order/test_sales_order.py b/erpnext/selling/doctype/sales_order/test_sales_order.py
index f687868..9922a15 100644
--- a/erpnext/selling/doctype/sales_order/test_sales_order.py
+++ b/erpnext/selling/doctype/sales_order/test_sales_order.py
@@ -5,6 +5,7 @@
 from frappe.utils import flt, add_days
 import frappe.permissions
 import unittest
+from erpnext.stock.doctype.item.test_item import get_total_projected_qty
 from erpnext.selling.doctype.sales_order.sales_order \
 	import make_material_request, make_delivery_note, make_sales_invoice, WarehouseRequired
 
@@ -124,8 +125,16 @@
 		dn = create_dn_against_so(so.name, 15)
 		self.assertEqual(get_reserved_qty(), existing_reserved_qty)
 
+		total_projected_qty = get_total_projected_qty('_Test Item')
+		item_doc_before_cancel = frappe.get_doc('Item', '_Test Item')
+		self.assertEqual(total_projected_qty,  item_doc_before_cancel.total_projected_qty)
+
 		dn.cancel()
 		self.assertEqual(get_reserved_qty(), existing_reserved_qty + 10)
+
+		total_projected_qty = get_total_projected_qty('_Test Item')
+		item_doc_after_cancel = frappe.get_doc('Item', '_Test Item')
+		self.assertEqual(total_projected_qty,  item_doc_after_cancel.total_projected_qty)
 		
 	def test_reserved_qty_for_over_delivery_via_sales_invoice(self):
 		# set over-delivery tolerance
@@ -141,6 +150,10 @@
 		si.get("items")[0].qty = 12
 		si.insert()
 		si.submit()
+
+		total_projected_qty = get_total_projected_qty('_Test Item')
+		item_doc = frappe.get_doc('Item', '_Test Item')
+		self.assertEqual(total_projected_qty,  item_doc.total_projected_qty)
 		
 		self.assertEqual(get_reserved_qty(), existing_reserved_qty)
 		
@@ -150,6 +163,9 @@
 
 		si.cancel()
 		self.assertEqual(get_reserved_qty(), existing_reserved_qty + 10)
+		total_projected_qty = get_total_projected_qty('_Test Item')
+		item_doc = frappe.get_doc('Item', '_Test Item')
+		self.assertEqual(total_projected_qty,  item_doc.total_projected_qty)
 		
 		so.load_from_db()
 		self.assertEqual(so.get("items")[0].delivered_qty, 0)
@@ -178,6 +194,10 @@
 		self.assertEqual(get_reserved_qty("_Test Item"), existing_reserved_qty_item1)
 		self.assertEqual(get_reserved_qty("_Test Item Home Desktop 100"), existing_reserved_qty_item2)
 
+		total_projected_qty = get_total_projected_qty('_Test Item')
+		item_doc = frappe.get_doc('Item', '_Test Item')
+		self.assertEqual(total_projected_qty,  item_doc.total_projected_qty)
+
 		# unclose so
 		so.load_from_db()
 		so.update_status('Draft')
@@ -211,6 +231,10 @@
 
 		dn = create_dn_against_so(so.name, 15)
 
+		total_projected_qty = get_total_projected_qty('_Test Item')
+		item_doc = frappe.get_doc('Item', '_Test Item')
+		self.assertEqual(total_projected_qty,  item_doc.total_projected_qty)
+
 		self.assertEqual(get_reserved_qty("_Test Item"), existing_reserved_qty_item1)
 		self.assertEqual(get_reserved_qty("_Test Item Home Desktop 100"),
 			existing_reserved_qty_item2)
@@ -427,6 +451,13 @@
 
 		self.assertEquals(abs(flt(reserved_qty)), existing_reserved_qty_for_dn_item)
 
+	def test_total_projected_qty_against_sales_order(self):
+		so = make_sales_order(item = '_Test Item')
+		total_projected_qty = get_total_projected_qty('_Test Item')
+
+		item_doc = frappe.get_doc('Item', '_Test Item')
+		self.assertEqual(total_projected_qty,  item_doc.total_projected_qty)
+
 	def test_reserved_qty_for_closing_so(self):
 		bin = frappe.get_all("Bin", filters={"item_code": "_Test Item", "warehouse": "_Test Warehouse - _TC"},
 			fields=["reserved_qty"])
diff --git a/erpnext/selling/doctype/selling_settings/selling_settings.js b/erpnext/selling/doctype/selling_settings/selling_settings.js
new file mode 100644
index 0000000..cf6fb28
--- /dev/null
+++ b/erpnext/selling/doctype/selling_settings/selling_settings.js
@@ -0,0 +1,8 @@
+// Copyright (c) 2016, Frappe Technologies Pvt. Ltd. and contributors
+// For license information, please see license.txt
+
+frappe.ui.form.on('Selling Settings', {
+	refresh: function(frm) {
+
+	}
+});
diff --git a/erpnext/selling/doctype/selling_settings/selling_settings.json b/erpnext/selling/doctype/selling_settings/selling_settings.json
index affa38b..dd9bcd7 100644
--- a/erpnext/selling/doctype/selling_settings/selling_settings.json
+++ b/erpnext/selling/doctype/selling_settings/selling_settings.json
@@ -2,29 +2,36 @@
  "allow_copy": 0, 
  "allow_import": 0, 
  "allow_rename": 0, 
+ "beta": 0, 
  "creation": "2013-06-25 10:25:16", 
  "custom": 0, 
  "description": "Settings for Selling Module", 
  "docstatus": 0, 
  "doctype": "DocType", 
  "document_type": "Other", 
+ "editable_grid": 0, 
+ "engine": "InnoDB", 
  "fields": [
   {
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "default": "Customer Name", 
    "fieldname": "cust_master_name", 
    "fieldtype": "Select", 
    "hidden": 0, 
    "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 1, 
    "label": "Customer Naming By", 
+   "length": 0, 
    "no_copy": 0, 
    "options": "Customer Name\nNaming Series", 
    "permlevel": 0, 
    "print_hide": 0, 
+   "print_hide_if_no_value": 0, 
    "read_only": 0, 
    "report_hide": 0, 
    "reqd": 0, 
@@ -36,17 +43,21 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "campaign_naming_by", 
    "fieldtype": "Select", 
    "hidden": 0, 
    "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 1, 
    "label": "Campaign Naming By", 
+   "length": 0, 
    "no_copy": 0, 
    "options": "Campaign Name\nNaming Series", 
    "permlevel": 0, 
    "print_hide": 0, 
+   "print_hide_if_no_value": 0, 
    "read_only": 0, 
    "report_hide": 0, 
    "reqd": 0, 
@@ -58,18 +69,22 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "description": "", 
    "fieldname": "customer_group", 
    "fieldtype": "Link", 
    "hidden": 0, 
    "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 1, 
    "label": "Default Customer Group", 
+   "length": 0, 
    "no_copy": 0, 
    "options": "Customer Group", 
    "permlevel": 0, 
    "print_hide": 0, 
+   "print_hide_if_no_value": 0, 
    "read_only": 0, 
    "report_hide": 0, 
    "reqd": 0, 
@@ -81,18 +96,22 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "description": "", 
    "fieldname": "territory", 
    "fieldtype": "Link", 
    "hidden": 0, 
    "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 1, 
    "label": "Default Territory", 
+   "length": 0, 
    "no_copy": 0, 
    "options": "Territory", 
    "permlevel": 0, 
    "print_hide": 0, 
+   "print_hide_if_no_value": 0, 
    "read_only": 0, 
    "report_hide": 0, 
    "reqd": 0, 
@@ -104,17 +123,21 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "selling_price_list", 
    "fieldtype": "Link", 
    "hidden": 0, 
    "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 1, 
    "label": "Default Price List", 
+   "length": 0, 
    "no_copy": 0, 
    "options": "Price List", 
    "permlevel": 0, 
    "print_hide": 0, 
+   "print_hide_if_no_value": 0, 
    "read_only": 0, 
    "report_hide": 0, 
    "reqd": 0, 
@@ -126,15 +149,19 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "column_break_5", 
    "fieldtype": "Column Break", 
    "hidden": 0, 
    "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 0, 
+   "length": 0, 
    "no_copy": 0, 
    "permlevel": 0, 
    "print_hide": 0, 
+   "print_hide_if_no_value": 0, 
    "read_only": 0, 
    "report_hide": 0, 
    "reqd": 0, 
@@ -146,17 +173,21 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "so_required", 
    "fieldtype": "Select", 
    "hidden": 0, 
    "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 0, 
    "label": "Sales Order Required", 
+   "length": 0, 
    "no_copy": 0, 
    "options": "No\nYes", 
    "permlevel": 0, 
    "print_hide": 0, 
+   "print_hide_if_no_value": 0, 
    "read_only": 0, 
    "report_hide": 0, 
    "reqd": 0, 
@@ -168,17 +199,21 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "dn_required", 
    "fieldtype": "Select", 
    "hidden": 0, 
    "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 0, 
    "label": "Delivery Note Required", 
+   "length": 0, 
    "no_copy": 0, 
    "options": "No\nYes", 
    "permlevel": 0, 
    "print_hide": 0, 
+   "print_hide_if_no_value": 0, 
    "read_only": 0, 
    "report_hide": 0, 
    "reqd": 0, 
@@ -190,16 +225,20 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "maintain_same_sales_rate", 
    "fieldtype": "Check", 
    "hidden": 0, 
    "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 0, 
    "label": "Maintain Same Rate Throughout Sales Cycle", 
+   "length": 0, 
    "no_copy": 0, 
    "permlevel": 0, 
    "print_hide": 0, 
+   "print_hide_if_no_value": 0, 
    "read_only": 0, 
    "report_hide": 0, 
    "reqd": 0, 
@@ -211,16 +250,20 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "editable_price_list_rate", 
    "fieldtype": "Check", 
    "hidden": 0, 
    "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 0, 
    "label": "Allow user to edit Price List Rate in transactions", 
+   "length": 0, 
    "no_copy": 0, 
    "permlevel": 0, 
    "print_hide": 0, 
+   "print_hide_if_no_value": 0, 
    "read_only": 0, 
    "report_hide": 0, 
    "reqd": 0, 
@@ -232,17 +275,21 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "allow_multiple_items", 
    "fieldtype": "Check", 
    "hidden": 0, 
    "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 0, 
    "label": "Allow Item to be added multiple times in a transaction", 
+   "length": 0, 
    "no_copy": 0, 
    "permlevel": 0, 
    "precision": "", 
    "print_hide": 0, 
+   "print_hide_if_no_value": 0, 
    "read_only": 0, 
    "report_hide": 0, 
    "reqd": 0, 
@@ -254,17 +301,47 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "allow_against_multiple_purchase_orders", 
    "fieldtype": "Check", 
    "hidden": 0, 
    "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 0, 
    "label": "Allow multiple Sales Orders against a Customer's Purchase Order", 
+   "length": 0, 
    "no_copy": 0, 
    "permlevel": 0, 
    "precision": "", 
    "print_hide": 0, 
+   "print_hide_if_no_value": 0, 
+   "read_only": 0, 
+   "report_hide": 0, 
+   "reqd": 0, 
+   "search_index": 0, 
+   "set_only_once": 0, 
+   "unique": 0
+  }, 
+  {
+   "allow_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
+   "fieldname": "validate_selling_price", 
+   "fieldtype": "Check", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 0, 
+   "in_list_view": 0, 
+   "label": "Validate Selling Price for Item against Purchase Rate or Valuation Rate", 
+   "length": 0, 
+   "no_copy": 0, 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 0, 
+   "print_hide_if_no_value": 0, 
    "read_only": 0, 
    "report_hide": 0, 
    "reqd": 0, 
@@ -277,12 +354,14 @@
  "hide_toolbar": 0, 
  "icon": "icon-cog", 
  "idx": 1, 
+ "image_view": 0, 
  "in_create": 0, 
  "in_dialog": 0, 
  "is_submittable": 0, 
  "issingle": 1, 
  "istable": 0, 
- "modified": "2015-08-27 02:42:56.512460", 
+ "max_attachments": 0, 
+ "modified": "2016-10-20 08:17:45.621151", 
  "modified_by": "Administrator", 
  "module": "Selling", 
  "name": "Selling Settings", 
@@ -298,6 +377,7 @@
    "export": 0, 
    "if_owner": 0, 
    "import": 0, 
+   "is_custom": 0, 
    "permlevel": 0, 
    "print": 1, 
    "read": 1, 
@@ -309,6 +389,10 @@
    "write": 1
   }
  ], 
+ "quick_entry": 0, 
  "read_only": 0, 
- "read_only_onload": 0
+ "read_only_onload": 0, 
+ "sort_field": "modified", 
+ "sort_order": "DESC", 
+ "track_seen": 0
 }
\ No newline at end of file
diff --git a/erpnext/selling/report/sales_person_wise_transaction_summary/sales_person_wise_transaction_summary.json b/erpnext/selling/report/sales_person_wise_transaction_summary/sales_person_wise_transaction_summary.json
index 0612dc0..af28e20 100644
--- a/erpnext/selling/report/sales_person_wise_transaction_summary/sales_person_wise_transaction_summary.json
+++ b/erpnext/selling/report/sales_person_wise_transaction_summary/sales_person_wise_transaction_summary.json
@@ -1,5 +1,5 @@
 {
- "add_total_row": 0, 
+ "add_total_row": 1, 
  "apply_user_permissions": 1, 
  "creation": "2013-05-03 11:31:05", 
  "disabled": 0, 
@@ -7,7 +7,7 @@
  "doctype": "Report", 
  "idx": 1, 
  "is_standard": "Yes", 
- "modified": "2016-01-28 04:22:49.476068", 
+ "modified": "2016-10-05 12:26:15.736596", 
  "modified_by": "Administrator", 
  "module": "Selling", 
  "name": "Sales Person-wise Transaction Summary", 
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 e9930f3..0c6914d 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
@@ -39,7 +39,7 @@
 		_("Customer") + ":Link/Customer:140", _("Territory") + ":Link/Territory:100", _("Posting Date") + ":Date:100",
 		_("Item Code") + ":Link/Item:120", _("Item Group") + ":Link/Item Group:120",
 		_("Brand") + ":Link/Brand:120", _("Qty") + ":Float:100", _("Amount") + ":Currency:120",
-		_("Sales Person") + ":Link/Sales Person:140", _("Contribution %") + ":Float:110",
+		_("Sales Person") + ":Link/Sales Person:140", _("Contribution %") + "::110",
 		_("Contribution Amount") + ":Currency:140"]
 
 def get_entries(filters):
diff --git a/erpnext/setup/doctype/company/delete_company_transactions.py b/erpnext/setup/doctype/company/delete_company_transactions.py
index 7e1681c..8f058e8 100644
--- a/erpnext/setup/doctype/company/delete_company_transactions.py
+++ b/erpnext/setup/doctype/company/delete_company_transactions.py
@@ -18,7 +18,6 @@
 			frappe.PermissionError)
 
 	delete_bins(company_name)
-	delete_time_sheets(company_name)
 	delete_lead_addresses(company_name)
 
 	for doctype in frappe.db.sql_list("""select parent from
@@ -70,14 +69,6 @@
 	frappe.db.sql("""delete from tabBin where warehouse in
 			(select name from tabWarehouse where company=%s)""", company_name)
 
-def delete_time_sheets(company_name):
-	# Delete Time Logs as it is linked to Production Order / Project / Task, which are linked to company
-	frappe.db.sql("""
-		delete from `tabTimesheet`
-		where
-			company=%(company)s
-	""", {"company": company_name})
-
 def delete_lead_addresses(company_name):
 	"""Delete addresses to which leads are linked"""
 	for lead in frappe.get_all("Lead", filters={"company": company_name}):
diff --git a/erpnext/setup/doctype/email_digest/email_digest.py b/erpnext/setup/doctype/email_digest/email_digest.py
index 7ec04c8..ac999ed 100644
--- a/erpnext/setup/doctype/email_digest/email_digest.py
+++ b/erpnext/setup/doctype/email_digest/email_digest.py
@@ -340,13 +340,13 @@
 		count = 0
 		for account in accounts:
 			balance += (get_balance_on(account, date = self.future_to_date)
-				- get_balance_on(account, date = self.future_from_date))
+				- get_balance_on(account, date = self.future_from_date - timedelta(days=1)))
 
 			count += (get_count_on(account,fieldname, date = self.future_to_date )
-				- get_count_on(account,fieldname, date = self.future_from_date))
+				- get_count_on(account,fieldname, date = self.future_from_date - timedelta(days=1)))
 
 			past_balance += (get_balance_on(account, date = self.past_to_date)
-				- get_balance_on(account, date = self.past_from_date))
+				- get_balance_on(account, date = self.past_from_date - timedelta(days=1)))
 
 		return balance, past_balance, count
 
diff --git a/erpnext/setup/doctype/email_digest/templates/default.html b/erpnext/setup/doctype/email_digest/templates/default.html
index 0500dc1..78acbd9 100644
--- a/erpnext/setup/doctype/email_digest/templates/default.html
+++ b/erpnext/setup/doctype/email_digest/templates/default.html
@@ -43,7 +43,8 @@
 
 <!-- issue list -->
 {% if issue_list %}
-<h4 style="{{ section_head }}">{{ _("Open Issues ") }}<span class="badge">({{ issue_count }})</span></h4>
+<h4 style="{{ section_head }}">{{ _("Open Issues ") }}
+	<span class="badge">({{ issue_count }})</span></h4>
 <div>
 {% for t in issue_list %}
     <div style="{{ line_item }}">
@@ -66,7 +67,8 @@
 
 <!-- project list -->
 {% if project_list %}
-<h4 style="{{ section_head }}">{{ _("Open Projects ") }}<span class="badge">({{ project_count }})</span></h4>
+<h4 style="{{ section_head }}">{{ _("Open Projects ") }}
+	<span class="badge">({{ project_count }})</span></h4>
 <div>
 {% for t in project_list %}
     <div style="{{ line_item }}">
@@ -92,7 +94,8 @@
 
 <!-- events -->
 {% if events %}
-<h4 style="{{ section_head }}">{{ _("Upcoming Calendar Events ") }}<span class="badge">({{ event_count }})</span></h4>
+<h4 style="{{ section_head }}">{{ _("Upcoming Calendar Events ") }}
+	<span class="badge">({{ event_count }})</span></h4>
 <div>
 {% for e in events %}
     {% if loop.index==1 or events[loop.index-1].date != e.date %}
@@ -124,7 +127,8 @@
 
 <!-- todo list -->
 {% if todo_list %}
-<h4 style="{{ section_head }}">{{ _("Open To Do ") }}<span class="badge">({{ todo_count }})</span></h4>
+<h4 style="{{ section_head }}">{{ _("Open To Do ") }}
+	<span class="badge">({{ todo_count }})</span></h4>
 <div>
 {% for t in todo_list %}
     <div style="{{ line_item }}">
diff --git a/erpnext/setup/doctype/naming_series/naming_series.py b/erpnext/setup/doctype/naming_series/naming_series.py
index 33deea4..60a1270 100644
--- a/erpnext/setup/doctype/naming_series/naming_series.py
+++ b/erpnext/setup/doctype/naming_series/naming_series.py
@@ -24,7 +24,8 @@
 			try:
 				options = self.get_options(d)
 			except frappe.DoesNotExistError:
-				frappe.pass_does_not_exist_error()
+				frappe.msgprint('Unable to find DocType {0}'.format(d))
+				#frappe.pass_does_not_exist_error()
 				continue
 
 			if options:
diff --git a/erpnext/setup/doctype/notification_control/notification_control.js b/erpnext/setup/doctype/notification_control/notification_control.js
index c8e199b..7f58ede 100644
--- a/erpnext/setup/doctype/notification_control/notification_control.js
+++ b/erpnext/setup/doctype/notification_control/notification_control.js
@@ -9,7 +9,9 @@
 		frm.set_value("custom_message", frm.doc[frm.events.get_fieldname(frm)]);
 	},
 	set_message: function(frm) {
-		frm.set_value(frm.events.get_fieldname(frm), frm.doc.custom_message);
+		if(frm.doc.select_transaction && frm.doc.select_transaction !== "") {
+			frm.set_value(frm.events.get_fieldname(frm), frm.doc.custom_message);
+		}
 		frm.save();
 	},
 	get_fieldname: function(frm) {
diff --git a/erpnext/setup/doctype/sales_partner/sales_partner.js b/erpnext/setup/doctype/sales_partner/sales_partner.js
index cb66b7f..143bf44 100644
--- a/erpnext/setup/doctype/sales_partner/sales_partner.js
+++ b/erpnext/setup/doctype/sales_partner/sales_partner.js
@@ -12,9 +12,3 @@
 		erpnext.utils.render_address_and_contact(cur_frm);
 	}
 }
-
-cur_frm.fields_dict['targets'].grid.get_field("item_group").get_query = function(doc, dt, dn) {
-  return{
-  	filters:{ 'is_group': 0 }
-  }
-}
diff --git a/erpnext/setup/doctype/uom/uom.json b/erpnext/setup/doctype/uom/uom.json
index 99f97fe..cea21de 100644
--- a/erpnext/setup/doctype/uom/uom.json
+++ b/erpnext/setup/doctype/uom/uom.json
@@ -1,7 +1,7 @@
 {
  "allow_copy": 0, 
  "allow_import": 1, 
- "allow_rename": 0, 
+ "allow_rename": 1, 
  "autoname": "field:uom_name", 
  "beta": 0, 
  "creation": "2013-01-10 16:34:24", 
@@ -15,6 +15,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "uom_name", 
    "fieldtype": "Data", 
    "hidden": 0, 
@@ -41,6 +42,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "description": "Check this to disallow fractions. (for Nos)", 
    "fieldname": "must_be_whole_number", 
    "fieldtype": "Check", 
@@ -74,7 +76,7 @@
  "issingle": 0, 
  "istable": 0, 
  "max_attachments": 0, 
- "modified": "2016-07-25 05:24:25.434534", 
+ "modified": "2016-09-23 17:58:21.574996", 
  "modified_by": "Administrator", 
  "module": "Setup", 
  "name": "UOM", 
@@ -144,5 +146,6 @@
  "quick_entry": 1, 
  "read_only": 0, 
  "read_only_onload": 0, 
+ "sort_order": "ASC", 
  "track_seen": 0
 }
\ No newline at end of file
diff --git a/erpnext/setup/install.py b/erpnext/setup/install.py
index 3337b1f..9971baa 100644
--- a/erpnext/setup/install.py
+++ b/erpnext/setup/install.py
@@ -26,7 +26,8 @@
 		return False
 
 def set_single_defaults():
-	for dt in frappe.db.sql_list("""select name from `tabDocType` where issingle=1"""):
+	for dt in ('Accounts Settings', 'Print Settings', 'HR Settings', 'Buying Settings',
+		'Selling Settings', 'Stock Settings'):
 		default_values = frappe.db.sql("""select fieldname, `default` from `tabDocField`
 			where parent=%s""", dt)
 		if default_values:
@@ -37,6 +38,8 @@
 				b.save()
 			except frappe.MandatoryError:
 				pass
+			except frappe.ValidationError:
+				pass
 
 	frappe.db.set_default("date_format", "dd-mm-yyyy")
 
diff --git a/erpnext/setup/setup_wizard/data/country_wise_tax.json b/erpnext/setup/setup_wizard/data/country_wise_tax.json
new file mode 100644
index 0000000..06f7f09
--- /dev/null
+++ b/erpnext/setup/setup_wizard/data/country_wise_tax.json
@@ -0,0 +1,1380 @@
+{
+	"Albania": {
+		"Albania VAT": {
+			"account_name": "VAT",
+			"tax_rate": 20.00
+		}
+	},
+	"Algeria": {
+		"Algeria VAT 17%": {
+			"account_name": "VAT 17%",
+			"tax_rate": 17.00,
+			"default": 1
+		},
+		"Algeria VAT 7%": {
+			"account_name": "VAT 7%",
+			"tax_rate": 7.00
+		}
+	},
+
+	"Andorra": {
+		"Andorra VAT": {
+			"account_name": "VAT",
+			"tax_rate": 4.50
+		}
+	},
+
+	"Angola": {
+		"Angola VAT": {
+			"account_name": "VAT",
+			"tax_rate": 10.00
+		}
+	},
+
+	"Antigua And Barbuda": {
+		"Antigua & Barbuda Sales Tax": {
+			"account_name": "ABST",
+			"tax_rate": 15.00
+		}
+	},
+
+	"Argentina": {
+		"Argentina Tax": {
+			"account_name": "VAT",
+			"tax_rate": 21.00
+		}
+	},
+
+	"Armenia": {
+		"Armenia Tax": {
+			"account_name": "VAT",
+			"tax_rate": 20.00
+		}
+	},
+
+	"Aruba": {
+		"Aruba Tax": {
+			"account_name": "VAT",
+			"tax_rate": 1.50
+		}
+	},
+
+	"Australia": {
+		"Australia GST1": {
+			"account_name": "GST 10%",
+			"tax_rate": 10.00,
+			"default": 1
+		},
+		"Australia GST 2%": {
+			"account_name": "GST 2%",
+			"tax_rate": 2
+		}
+	},
+
+	"Austria": {
+		"Austria Tax": {
+			"account_name": "VAT",
+			"tax_rate": 20.00
+		}
+	},
+
+	"Azerbaijan": {
+		"Azerbaijan Tax": {
+			"account_name": "GST",
+			"tax_rate": 18.00
+		}
+	},
+
+	"Bahamas": {
+		"Bahamas Tax": {
+			"account_name": "VAT",
+			"tax_rate": 7.50
+		}
+	},
+
+	"Bangladesh": {
+		"Bangladesh Tax": {
+			"account_name": "VAT",
+			"tax_rate": 15.00
+		}
+	},
+
+	"Barbados": {
+		"Barbados Tax": {
+			"account_name": "VAT",
+			"tax_rate": 17.50
+		}
+	},
+
+	"Belarus": {
+		"Belarus Tax": {
+			"account_name": "VAT",
+			"tax_rate": 20.00
+		}
+	},
+
+	"Belgium": {
+		"Belgium VAT 21%": {
+			"account_name": "VAT 21%",
+			"tax_rate": 21.00,
+			"default": 1
+		},
+		"Belgium VAT 12%": {
+			"account_name": "VAT 12%",
+			"tax_rate": 12
+		}
+	},
+
+	"Belize": {
+		"Belize Tax": {
+			"account_name": "GST",
+			"tax_rate": 12.50
+		}
+	},
+
+	"Benin": {
+		"Benin Tax": {
+			"account_name": "VAT",
+			"tax_rate": 18.00
+		}
+	},
+
+	"Bhutan": {
+		"Bhutan Tax": {
+			"account_name": "VAT",
+			"tax_rate": 50.00
+		}
+	},
+
+	"Bolivia": {
+		"Bolivia Tax": {
+			"account_name": "VAT",
+			"tax_rate": 13.00
+		}
+	},
+
+	"Bosnia and Herzegovina": {
+		"Bosnia & Herzegovina Tax": {
+			"account_name": "VAT",
+			"tax_rate": 17.00
+		}
+	},
+
+	"Botswana": {
+		"Botswana Tax": {
+			"account_name": "VAT",
+			"tax_rate": 12.00
+		}
+	},
+
+	"Brazil": {
+		"Brazil ICMS 19%": {
+			"account_name": "ICMS 19%",
+			"tax_rate": 19.00,
+			"default": 1
+		},
+		"Brazil ICMS 17%": {
+			"account_name": "ICMS 17%",
+			"tax_rate": 17.00
+		},
+		"Brazil PIS 1.65%": {
+			"account_name": "PIS 1.65%",
+			"tax_rate": 1.65
+		},
+		"Brazil COFINS 7.6%": {
+			"account_name": "COFINS 7.6%",
+			"tax_rate": 7.6
+		},
+		"Brazil COFINS 5.0%": {
+			"account_name": "ISS 5%",
+			"tax_rate": 5.0
+		}
+	},
+
+	"Bulgaria": {
+		"Bulgaria VAT 20%": {
+			"account_name": "VAT 20%",
+			"tax_rate": 20.00,
+			"default": 1
+		},
+		"Bulgaria VAT 7%": {
+			"account_name": "VAT 7%",
+			"tax_rate": 7.00
+		}
+	},
+
+	"Burkina Faso": {
+		"Burkina Faso Tax": {
+			"account_name": "VAT",
+			"tax_rate": 18.00
+		}
+	},
+
+	"Burundi": {
+		"Burundi Tax": {
+			"account_name": "VAT",
+			"tax_rate": 18.00
+		}
+	},
+
+	"Cambodia": {
+		"Cambodia Tax": {
+			"account_name": "VAT",
+			"tax_rate": 10.00
+		}
+	},
+
+	"Cameroon": {
+		"Cameroon Tax": {
+			"account_name": "VAT",
+			"tax_rate": 19.25
+		}
+	},
+
+	"Canada": {
+		"Canada GST 5%": {
+			"account_name": "GST",
+			"tax_rate": 5.00,
+			"default": 1
+		},
+		"Canada HST 15%": {
+			"account_name": "HST",
+			"tax_rate": 15.00
+		},
+		"Canada PST 8%": {
+			"account_name": "PST 8%",
+			"tax_rate": 8.00
+		},
+		"Canada PST 7%": {
+			"account_name": "PST 7%",
+			"tax_rate": 7.00
+		},
+		"Canada PST 5%": {
+			"account_name": "PST 5%",
+			"tax_rate": 5.00
+		}
+	},
+
+	"Cape Verde": {
+		"Cape Verde Tax": {
+			"account_name": "VAT",
+			"tax_rate": 15.00
+		}
+	},
+
+	"Central African Republic": {
+		"Central African Republic Tax": {
+			"account_name": "VAT",
+			"tax_rate": 19.00
+		}
+	},
+
+	"Chad": {
+		"Chad Tax": {
+			"account_name": "VAT",
+			"tax_rate": 18.00
+		}
+	},
+
+	"Chile": {
+		"Chile Tax": {
+			"account_name": "VAT",
+			"tax_rate": 19.00
+		}
+	},
+
+	"China": {
+		"China Tax": {
+			"account_name": "VAT",
+			"tax_rate": 17.00
+		}
+	},
+
+	"Colombia": {
+		"Colombia Tax": {
+			"account_name": "VAT",
+			"tax_rate": 16.00
+		}
+	},
+
+	"Comoros": {
+		"Comoros Tax": {
+			"account_name": "VAT",
+			"tax_rate": 10.00
+		}
+	},
+
+	"Congo": {
+		"Congo Tax": {
+			"account_name": "VAT",
+			"tax_rate": 16.00
+		}
+	},
+
+	"Costa Rica": {
+		"Costa Rica": {
+			"account_name": "VAT",
+			"tax_rate": 13.00
+		}
+	},
+
+	"Croatia": {
+		"Croatia VAT 25%": {
+			"account_name": "VAT 25%",
+			"tax_rate": 25.00,
+			"default": 1
+		},
+		"Croatia VAT 10%": {
+			"account_name": "VAT 10%",
+			"tax_rate": 10.00
+		}
+	},
+
+	"Cuba": {
+		"Cuba Tax": {
+			"account_name": "VAT",
+			"tax_rate": 20.00
+		}
+	},
+
+	"Cyprus": {
+		"Cyprus Tax": {
+			"account_name": "VAT",
+			"tax_rate": 18.00
+		}
+	},
+
+	"Czech Republic": {
+		"Czech Republic VAT 21%": {
+			"account_name": "VAT 21%",
+			"tax_rate": 21.00,
+			"default": 1
+		},
+		"Czech Republic VAT 15%": {
+			"account_name": "VAT 15%",
+			"tax_rate": 15.00
+		}
+	},
+
+	"Denmark": {
+		"Denmark Tax": {
+			"account_name": "VAT",
+			"tax_rate": 25.00
+		}
+	},
+
+	"Djibouti": {
+		"Dijbouti Tax": {
+			"account_name": "VAT",
+			"tax_rate": 33.00
+		}
+	},
+
+	"Dominica": {
+		"Dominica Tax": {
+			"account_name": "VAT",
+			"tax_rate": 15.00
+		}
+	},
+
+	"Dominican Republic": {
+		"Dominican Republic Tax": {
+			"account_name": "ITBIS",
+			"tax_rate": 16.00
+		}
+	},
+
+	"Ecuador": {
+		"Ecuador Tax": {
+			"account_name": "VAT",
+			"tax_rate": 12.00
+		}
+	},
+
+	"Egypt": {
+		"Egypt Tax": {
+			"account_name": "GST",
+			"tax_rate": 10.00
+		}
+	},
+
+	"El Salvador": {
+		"El Salvador Tax": {
+			"account_name": "VAT",
+			"tax_rate": 13.00
+		}
+	},
+
+	"Equatorial Guinea": {
+		"Equatorial Guinea": {
+			"account_name": "VAT",
+			"tax_rate": 15.00
+		}
+	},
+
+	"Eritrea": {
+		"Eritrea Tax": {
+			"account_name": "VAT",
+			"tax_rate": 4.00
+		}
+	},
+
+	"Estonia": {
+		"Estonia Tax": {
+			"account_name": "VAT",
+			"tax_rate": 20.00
+		}
+	},
+
+	"Ethiopia": {
+		"Ethiopia Tax": {
+			"account_name": "VAT",
+			"tax_rate": 15.00
+		}
+	},
+
+	"Fiji": {
+		"Fiji Tax": {
+			"account_name": "VAT",
+			"tax_rate": 15.00
+		}
+	},
+
+	"Finland": {
+		"Finland Tax": {
+			"account_name": "VAT",
+			"tax_rate": 24.00
+		}
+	},
+
+	"France": {
+		"France VAT 19.6%": {
+			"account_name": "VAT 19.6%",
+			"tax_rate": 19.6,
+			"default": 1
+		},
+		"France VAT 5.5%": {
+			"account_name": "VAT 5.5%",
+			"tax_rate": 5.5
+		}
+	},
+
+	"Gabon": {
+		"Gabon Tax": {
+			"account_name": "VAT",
+			"tax_rate": 18.00
+		}
+	},
+
+	"Gambia": {
+		"Gambia Tax": {
+			"account_name": "VAT",
+			"tax_rate": 15.00
+		}
+	},
+
+	"Georgia": {
+		"Georgia Tax": {
+			"account_name": "VAT",
+			"tax_rate": 18.00
+		}
+	},
+
+	"Germany": {
+		"Germany VAT 19%": {
+			"account_name": "VAT 19%",
+			"tax_rate": 19.00,
+			"default": 1
+		},
+		"Germany VAT 7%": {
+			"account_name": "VAT 7%",
+			"tax_rate": 7.00
+		}
+	},
+
+	"Ghana": {
+		"Ghana Tax": {
+			"account_name": "VAT",
+			"tax_rate": 15.00
+		}
+	},
+
+	"Greece": {
+		"Greece VAT 23%": {
+			"account_name": "VAT 23%",
+			"tax_rate": 23.00,
+			"default": 1
+		},
+		"Greece VAT 9%": {
+			"account_name": "VAT 9%",
+			"tax_rate": 9.00
+		}
+	},
+
+	"Grenada": {
+		"Grenada Tax": {
+			"account_name": "VAT",
+			"tax_rate": 15.00
+		}
+	},
+
+	"Guam": {
+		"Guam Tax": {
+			"account_name": "VAT",
+			"tax_rate": 4.00
+		}
+	},
+
+	"Guatemala": {
+		"Guatemala Tax": {
+			"account_name": "IVA",
+			"tax_rate": 12.00
+		}
+	},
+
+	"Guinea": {
+		"Guinea Tax": {
+			"account_name": "VAT",
+			"tax_rate": 18.00
+		}
+	},
+
+	"Guyana": {
+		"Guyana Tax": {
+			"account_name": "GST",
+			"tax_rate": 16.00
+		}
+	},
+
+	"Haiti": {
+		"Haiti Tax": {
+			"account_name": "VAT",
+			"tax_rate": 10.00
+		}
+	},
+
+	"Honduras": {
+		"Honduras Tax": {
+			"account_name": "VAT",
+			"tax_rate": 15.00
+		}
+	},
+
+	"Hungary": {
+		"Hungary Tax": {
+			"account_name": "VAT",
+			"tax_rate": 27.00
+		}
+	},
+
+	"Iceland": {
+		"Iceland VAT 25.5%": {
+			"account_name": "VAT 25.5%",
+			"tax_rate": 25.5,
+			"default": 1
+		},
+		"Iceland VAT 7.5%": {
+			"account_name": "VAT 7.5%",
+			"tax_rate": 7.5
+		}
+	},
+
+	"India": {
+		"India VAT 5%": {
+			"account_name": "VAT 5%",
+			"tax_rate": 5.00,
+			"default": 1
+		},
+		"India VAT 4%": {
+			"account_name": "VAT 4%",
+			"tax_rate": 4.00
+		},
+		"India VAT 14%": {
+			"account_name": "VAT 14%",
+			"tax_rate": 14.00
+		}
+	},
+
+	"Indonesia": {
+		"Indonesia Tax": {
+			"account_name": "VAT",
+			"tax_rate": 10.00
+		}
+	},
+
+	"Iran": {
+		"Iran Tax": {
+			"account_name": "VAT",
+			"tax_rate": 7.00
+		}
+	},
+
+	"Ireland": {
+		"Ireland Tax": {
+			"account_name": "VAT",
+			"tax_rate": 23.00
+		}
+	},
+
+	"Isle Of Man": {
+		"Isle of Man VAT 20%": {
+			"account_name": "VAT",
+			"tax_rate": 20.00,
+			"default": 1
+		},
+		"Isle of Man VAT 5%": {
+			"account_name": "VAT",
+			"tax_rate": 5.00
+		}
+	},
+
+	"Israel": {
+		"Israel Tax": {
+			"account_name": "VAT",
+			"tax_rate": 18.00
+		}
+	},
+
+	"Italy": {
+		"Italy Tax": {
+			"account_name": "VAT",
+			"tax_rate": 22.00
+		}
+	},
+
+	"Ivory Coast": {
+		"Ivory Coast": {
+			"account_name": "Metric",
+			"tax_rate": 18.00
+		}
+	},
+
+	"Jamaica": {
+		"Jamaica Tax": {
+			"account_name": "GCT",
+			"tax_rate": 16.50
+		}
+	},
+
+	"Japan": {
+		"Japan Tax": {
+			"account_name": "CT",
+			"tax_rate": 5.00
+		}
+	},
+
+	"Jordan": {
+		"Jordan Tax": {
+			"account_name": "VAT",
+			"tax_rate": 16.00
+		}
+	},
+
+	"Kazakhstan": {
+		"Kazakhstan Tax": {
+			"account_name": "VAT",
+			"tax_rate": 12.00
+		}
+	},
+
+	"Kenya": {
+		"Kenya Tax": {
+			"account_name": "VAT",
+			"tax_rate": 16.00
+		}
+	},
+
+	"Kosovo": {
+		"Kosovo Tax": {
+			"account_name": "VAT",
+			"tax_rate": 16.00
+		}
+	},
+
+	"Kyrgyzstan": {
+		"Kyrgyztan Tax": {
+			"account_name": "VAT",
+			"tax_rate": 12.00
+		}
+	},
+
+	"Lao People's Democratic Republic": {
+		"Lao Republic Tax": {
+			"account_name": "VAT",
+			"tax_rate": 10.00
+		}
+	},
+
+	"Latvia": {
+		"Latvia Tax": {
+			"account_name": "VAT",
+			"tax_rate": 20.00
+		}
+	},
+
+	"Lebanon": {
+		"Lebanon Tax": {
+			"account_name": "VAT",
+			"tax_rate": 10.00
+		}
+	},
+
+	"Liechtenstein": {
+		"Liechtenstein Tax": {
+			"account_name": "VAT",
+			"tax_rate": 8.00
+		}
+	},
+
+	"Lithuania": {
+		"Lithunia Tax": {
+			"account_name": "VAT",
+			"tax_rate": 21.00
+		}
+	},
+
+	"Luxembourg": {
+		"Luxembourg VAT 15%": {
+			"account_name": "VAT 15%",
+			"tax_rate": 15.00,
+			"default": 1
+		},
+		"Luxembourg VAT 3%": {
+			"account_name": "VAT 3%",
+			"tax_rate": 3.00
+		}
+	},
+
+	"Macedonia": {
+		"Macedonia VAT 18%": {
+			"account_name": "VAT",
+			"tax_rate": 18.00,
+			"default": 1
+		},
+		"Macedonia VAT 5%": {
+			"account_name": "VAT",
+			"tax_rate": 5.00
+		}
+	},
+
+	"Madagascar": {
+		"Madagascar Tax": {
+			"account_name": "VAT",
+			"tax_rate": 20.00
+		}
+	},
+
+	"Malawi": {
+		"Malawi Tax": {
+			"account_name": "VAT",
+			"tax_rate": 16.50
+		}
+	},
+
+	"Malaysia": {
+		"Malaysia GST 6%": {
+			"account_name": "GST",
+			"tax_rate": 6.00,
+			"default": 1
+		},
+		"Malaysia GST 5%": {
+			"account_name": "GST",
+			"tax_rate": 5.00
+		},
+		"Malaysia GST 10%": {
+			"account_name": "GST",
+			"tax_rate": 10.00
+		}
+	},
+
+	"Mali": {
+		"Mali Tax": {
+			"account_name": "VAT",
+			"tax_rate": 18.00
+		}
+	},
+
+	"Malta": {
+		"Malta Tax": {
+			"account_name": "VAT",
+			"tax_rate": 18.00
+		}
+	},
+
+	"Mauritania": {
+		"Mauritania Tax": {
+			"account_name": "VAT",
+			"tax_rate": 18.00
+		}
+	},
+
+	"Mauritius": {
+		"Mauritius Tax": {
+			"account_name": "VAT",
+			"tax_rate": 15.00
+		}
+	},
+
+	"Mexico": {
+		"Mexico Tax": {
+			"account_name": "IVA",
+			"tax_rate": 16.00
+		}
+	},
+
+	"Micronesia": {
+		"Micronesia Tax": {
+			"account_name": "VAT",
+			"tax_rate": 5.00
+		}
+	},
+
+	"Moldova": {
+		"Moldova VAT 20%": {
+			"account_name": "VAT 20%",
+			"tax_rate": 20.00,
+			"default": 1
+		},
+		"Moldova VAT 8%": {
+			"account_name": "VAT 8%",
+			"tax_rate": 8.00
+		}
+	},
+
+	"Monaco": {
+		"Monaco Tax 19.6%": {
+			"account_name": "VAT 19.6%",
+			"tax_rate": 19.6,
+			"default": 1
+		},
+		"Monaco Tax 5.5%": {
+			"account_name": "VAT 5,5%",
+			"tax_rate": 5.5
+		}
+	},
+
+	"Mongolia": {
+		"Mongolia Tax": {
+			"account_name": "VAT",
+			"tax_rate": 10.00
+		}
+	},
+
+	"Montenegro": {
+		"Montenegro Tax 17%": {
+			"account_name": "VAT 17%",
+			"tax_rate": 17.00,
+			"default": 1
+		},
+		"Montenegro Tax 7%": {
+			"account_name": "VAT 7%",
+			"tax_rate": 7.00
+		}
+	},
+
+	"Morocco": {
+		"Morroco VAT 20%": {
+			"account_name": "VAT 20%",
+			"tax_rate": 20.00,
+			"default": 1
+		},
+		"Morroco VAT 10%": {
+			"account_name": "VAT 10%",
+			"tax_rate": 10.00
+		}
+	},
+
+	"Mozambique": {
+		"Mozambique Tax": {
+			"account_name": "VAT",
+			"tax_rate": 17.00
+		}
+	},
+
+	"Myanmar": {
+		"Myanamar Tax": {
+			"account_name": "VAT",
+			"tax_rate": 30.00
+		}
+	},
+
+	"Namibia": {
+		"Namibia Tax": {
+			"account_name": "VAT",
+			"tax_rate": 15.00
+		}
+	},
+
+	"Nepal": {
+		"Nepal Tax": {
+			"account_name": "VAT",
+			"tax_rate": 13.00
+		}
+	},
+
+	"Netherlands": {
+		"Netherlands VAT 21%": {
+			"account_name": "VAT 21%",
+			"tax_rate": 21.00,
+			"default": 1
+		},
+		"Netherlands VAT 6%": {
+			"account_name": "VAT 6%",
+			"tax_rate": 6.00
+		}
+	},
+
+	"New Zealand": {
+		"New Zealand": {
+			"account_name": "GST",
+			"tax_rate": 15.00
+		}
+	},
+
+	"Nicaragua": {
+		"Nicaragua Tax": {
+			"account_name": "VAT",
+			"tax_rate": 15.00
+		}
+	},
+
+	"Nigeria": {
+		"Nigeria Tax": {
+			"account_name": "VAT",
+			"tax_rate": 5
+		}
+	},
+
+	"North Korea": {
+		"North Korea": {
+			"account_name": "VAT",
+			"tax_rate": 15.00
+		}
+	},
+
+	"Norway": {
+		"Norway VAT 25%": {
+			"account_name": "VAT 25%",
+			"tax_rate": 25.00,
+			"default": 1
+		},
+		"Norway VAT 12%": {
+			"account_name": "VAT 12%",
+			"tax_rate": 12.00
+		}
+	},
+
+	"Pakistan": {
+		"Pakistan Tax": {
+			"account_name": "GST",
+			"tax_rate": 17.00
+		}
+	},
+
+	"Panama": {
+		"Panama Tax": {
+			"account_name": "VAT",
+			"tax_rate": 7.00
+		}
+	},
+
+	"Papua New Guinea": {
+		"Papua New Guinea Tax": {
+			"account_name": "VAT",
+			"tax_rate": 10.00
+		}
+	},
+
+	"Paraguay": {
+		"Paraguay Tax": {
+			"account_name": "VAT",
+			"tax_rate": 10.00
+		}
+	},
+
+	"Peru": {
+		"Peru Tax": {
+			"account_name": "VAT",
+			"tax_rate": 16.00
+		}
+	},
+
+	"Philippines": {
+		"Philippines Tax": {
+			"account_name": "VAT",
+			"tax_rate": 12.00
+		}
+	},
+
+	"Poland": {
+		"Poland VAT 23%": {
+			"account_name": "VAT 23%",
+			"tax_rate": 23.00,
+			"default": 1
+		},
+		"Poland VAT 7%": {
+			"account_name": "VAT 7%",
+			"tax_rate": 7
+		}
+	},
+
+	"Portugal": {
+		"Portugal Tax": {
+			"account_name": "VAT",
+			"tax_rate": 23.00
+		}
+	},
+
+	"Republic Of The Congo": {
+		"Congo Tax": {
+			"account_name": "VAT",
+			"tax_rate": 18.00
+		}
+	},
+
+	"Romania": {
+		"Romania Tax": {
+			"account_name": "VAT",
+			"tax_rate": 24.00
+		}
+	},
+
+	"Russia": {
+		"Russia VAT 18%": {
+			"account_name": "VAT 18%",
+			"tax_rate": 18.00,
+			"default": 1
+		},
+		"Russia VAT 10%": {
+			"account_name": "VAT 10%",
+			"tax_rate": 10.00
+		}
+	},
+
+	"Rwanda": {
+		"Rwanda Tax": {
+			"account_name": "VAT",
+			"tax_rate": 18.00
+		}
+	},
+
+	"Senegal": {
+		"Senegal Tax": {
+			"account_name": "VAT",
+			"tax_rate": 18.00
+		}
+	},
+
+	"Serbia": {
+		"Serbia Tax": {
+			"account_name": "VAT",
+			"tax_rate": 20.00
+		}
+	},
+
+	"Seychelles": {
+		"Seychelles Tax": {
+			"account_name": "VAT",
+			"tax_rate": 15.00
+		}
+	},
+
+	"Sierra Leone": {
+		"Sierra Leone Tax": {
+			"account_name": "VAT",
+			"tax_rate": 15.00
+		}
+	},
+
+	"Singapore": {
+		"Singapore Tax": {
+			"account_name": "GST",
+			"tax_rate": 7.00
+		}
+	},
+
+	"Slovakia": {
+		"Slovakia VAT 20%": {
+			"account_name": "VAT 20%",
+			"tax_rate": 20.00,
+			"default": 1
+		},
+		"Slovakia VAT 10%": {
+			"account_name": "VAT 10%",
+			"tax_rate": 10.00
+		}
+	},
+
+	"Slovenia": {
+		"Slovenia VAT 22%": {
+			"account_name": "VAT 22%",
+			"tax_rate": 22.00,
+			"default": 1
+		},
+		"Slovenia VAT 8.5%": {
+			"account_name": "VAT 8.5%",
+			"tax_rate": 8.50
+		}
+	},
+
+	"Solomon Islands": {
+		"Solomon Islands Tax": {
+			"account_name": "VAT",
+			"tax_rate": 15.00
+		}
+	},
+
+	"Somalia": {
+		"Somalia Tax": {
+			"account_name": "VAT",
+			"tax_rate": 10.00
+		}
+	},
+
+	"South Africa": {
+		"South Africa Tax": {
+			"account_name": "VAT",
+			"tax_rate": 14.00
+		}
+	},
+
+	"South Korea": {
+		"South Korea Tax": {
+			"account_name": "VAT",
+			"tax_rate": 10.00
+		}
+	},
+
+	"Spain": {
+		"Spain Tax": {
+			"account_name": "VAT",
+			"tax_rate": 21.00
+		}
+	},
+
+	"Sri Lanka": {
+		"Sri Lanka Tax": {
+			"account_name": "VAT",
+			"tax_rate": 12.00
+		}
+	},
+
+	"St Lucia": {
+		"St Lucia Tax": {
+			"account_name": "VAT",
+			"tax_rate": 15.00
+		}
+	},
+
+	"Sudan": {
+		"Sudan Tax": {
+			"account_name": "VAT",
+			"tax_rate": 10.00
+		}
+	},
+
+	"Suriname": {
+		"Suriname Tax": {
+			"account_name": "VAT",
+			"tax_rate": 10.00
+		}
+	},
+
+	"Swaziland": {
+		"Swaziland tax": {
+			"account_name": "VAT",
+			"tax_rate": 14.00
+		}
+	},
+
+	"Sweden": {
+		"Sweden Tax": {
+			"account_name": "VAT",
+			"tax_rate": 25.00
+		}
+	},
+
+	"Switzerland": {
+		"Switzerland VAT 8%": {
+			"account_name": "VAT 8%",
+			"tax_rate": 8.00,
+			"default": 1
+		},
+		"Switzerland VAT 2.4%": {
+			"account_name": "VAT 2.4%",
+			"tax_rate": 2.40
+		}
+	},
+
+	"Taiwan": {
+		"Taiwan Tax": {
+			"account_name": "VAT",
+			"tax_rate": 5.00
+		}
+	},
+
+	"Tajikistan": {
+		"Tajikistan Tax": {
+			"account_name": "VAT",
+			"tax_rate": 20
+		}
+	},
+
+	"Tanzania": {
+		"Tanzania Tax": {
+			"account_name": "VAT",
+			"tax_rate": 18.00
+		}
+	},
+
+	"Thailand": {
+		"Thailand Tax": {
+			"account_name": "VAT",
+			"tax_rate": 7.00
+		}
+	},
+
+	"Togo": {
+		"Togo Tax": {
+			"account_name": "VAT",
+			"tax_rate": 18.00
+		}
+	},
+
+	"Tonga": {
+		"Tonga Tax": {
+			"account_name": "VAT",
+			"tax_rate": 15.00
+		}
+	},
+
+	"Trinidad And Tobago": {
+		"Trinidad & Tobago Tax": {
+			"account_name": "VAT",
+			"tax_rate": 15.00
+		}
+	},
+
+	"Tunisia": {
+		"Tunisia VAT 18%": {
+			"account_name": "VAT 18%",
+			"tax_rate": 18.00,
+			"default": 1
+		},
+		"Tunisia VAT 12%": {
+			"account_name": "VAT 12%",
+			"tax_rate": 12.00
+		},
+		"Tunisia VAT 6%": {
+			"account_name": "VAT 6%",
+			"tax_rate": 6.00
+		}
+	},
+
+	"Turkey": {
+		"Turkey Tax": {
+			"account_name": "VAT 18%",
+			"tax_rate": 18.00
+		}
+	},
+
+	"Turkmenistan": {
+		"Turkmenistan Tax": {
+			"account_name": "VAT",
+			"tax_rate": 20.00
+		}
+	},
+
+	"Uganda": {
+		"Uganda Tax": {
+			"account_name": "VAT",
+			"tax_rate": 18.00
+		}
+	},
+
+	"Ukraine": {
+		"Ukraine Tax": {
+			"account_name": "VAT",
+			"tax_rate": 20.00
+		}
+	},
+
+	"United Kingdom": {
+		"United Kingdom Tax": {
+			"account_name": "VAT",
+			"tax_rate": 20.00
+		}
+	},
+
+	"United States": {
+		"US ST 6%": {
+			"account_name": "ST 6%",
+			"tax_rate": 6.00,
+			"default": 1
+		},
+		"US ST 4%": {
+			"account_name": "ST 4%",
+			"tax_rate": 4.00
+		},
+		"US ST 6.25%": {
+			"account_name": "ST 6.25%",
+			"tax_rate": 6.25
+		}
+	},
+
+	"Uruguay": {
+		"Uruguay Tax": {
+			"account_name": "VAT",
+			"tax_rate": 22.00
+		}
+	},
+
+	"Uzbekistan": {
+		"Uzbekistan Tax": {
+			"account_name": "VAT",
+			"tax_rate": 20.00
+		}
+	},
+
+	"Vanuatu": {
+		"Vanuatu Tax": {
+			"account_name": "VAT",
+			"tax_rate": 12.50
+		}
+	},
+
+	"Venezuela": {
+		"Venezuela Tax": {
+			"account_name": "VAT",
+			"tax_rate": 12.00
+		}
+	},
+
+	"Vietnam": {
+		"Vietnam Tax": {
+			"account_name": "VAT",
+			"tax_rate": 10.00
+		}
+	},
+
+	"Yemen": {
+		"Yemen Tax": {
+			"account_name": "VAT",
+			"tax_rate": 5.00
+		}
+	},
+
+	"Zambia": {
+		"Zambia Tax": {
+			"account_name": "VAT",
+			"tax_rate": 16.00
+		}
+	},
+
+	"Zimbabwe": {
+		"Zimbabwe Tax": {
+			"account_name": "VAT",
+			"tax_rate": 15.00
+		}
+	}
+}
\ No newline at end of file
diff --git a/erpnext/setup/setup_wizard/domainify.py b/erpnext/setup/setup_wizard/domainify.py
index 05af9a6..2b87cc0 100644
--- a/erpnext/setup/setup_wizard/domainify.py
+++ b/erpnext/setup/setup_wizard/domainify.py
@@ -18,7 +18,7 @@
 			'set_value': [
 				['Stock Settings', None, 'show_barcode_field', 1]
 			],
-			'remove_sidebar_items': ['/announcement', '/course', '/assessment', '/fees']
+			'default_portal_role': 'Customer'
 		},
 
 		'Retail': {
@@ -32,7 +32,7 @@
 			'set_value': [
 				['Stock Settings', None, 'show_barcode_field', 1]
 			],
-			'remove_sidebar_items': ['/announcement', '/course', '/assessment', '/fees']
+			'default_portal_role': 'Customer'
 		},
 
 		'Distribution': {
@@ -45,7 +45,7 @@
 			'set_value': [
 				['Stock Settings', None, 'show_barcode_field', 1]
 			],
-			'remove_sidebar_items': ['/announcement', '/course', '/assessment', '/fees']
+			'default_portal_role': 'Customer'
 		},
 
 		'Services': {
@@ -58,14 +58,15 @@
 			'set_value': [
 				['Stock Settings', None, 'show_barcode_field', 0]
 			],
-			'remove_sidebar_items': ['/announcement', '/course', '/assessment', '/fees']
+			'default_portal_role': 'Customer'
 		},
 		'Education': {
 			'desktop_icons': ['Student', 'Program', 'Course', 'Student Group', 'Instructor',
 				'Fees',  'ToDo', 'Schools'],
 			'allow_roles': ['Academics User', 'Accounts User', 'Accounts Manager', 'Item Manager',
-				'Website Manager', 'HR User', 'HR Manager', 'Purchase User', 'Purchase Manager'],
-			'allow_sidebar_items': ['/announcement', '/course', '/assessment', '/fees']
+				'Website Manager', 'HR User', 'HR Manager', 'Purchase User', 'Purchase Manager',
+				'Student'],
+			'default_portal_role': 'Student'
 		},
 	}
 	if not domain in data:
@@ -80,6 +81,8 @@
 	setup_properties(data)
 	set_values(data)
 	setup_sidebar_items(data)
+	if data.get('default_portal_role'):
+		frappe.db.set_value('Portal Settings', None, 'default_role', data.get('default_portal_role'))
 	frappe.clear_cache()
 
 def setup_desktop_icons(data):
diff --git a/erpnext/setup/setup_wizard/install_fixtures.py b/erpnext/setup/setup_wizard/install_fixtures.py
index 1f14ddf..a80e6d9 100644
--- a/erpnext/setup/setup_wizard/install_fixtures.py
+++ b/erpnext/setup/setup_wizard/install_fixtures.py
@@ -13,7 +13,6 @@
 
 def install(country=None):
 	records = [
-
 		# address template
 		{'doctype':"Address Template", "country": country},
 
diff --git a/erpnext/setup/setup_wizard/setup_wizard.py b/erpnext/setup/setup_wizard/setup_wizard.py
index 945dfb1..7c65f88 100644
--- a/erpnext/setup/setup_wizard/setup_wizard.py
+++ b/erpnext/setup/setup_wizard/setup_wizard.py
@@ -4,6 +4,8 @@
 from __future__ import unicode_literals
 import frappe, copy
 
+import os
+import json
 from frappe.utils import cstr, flt, getdate
 from frappe import _
 from frappe.utils.file_manager import save_file
@@ -15,541 +17,573 @@
 from erpnext.setup.setup_wizard.domainify import setup_domain
 
 def setup_complete(args=None):
-    if frappe.db.sql("select name from tabCompany"):
-        frappe.throw(_("Setup Already Complete!!"))
+	if frappe.db.sql("select name from tabCompany"):
+		frappe.throw(_("Setup Already Complete!!"))
 
-    install_fixtures.install(args.get("country"))
+	install_fixtures.install(args.get("country"))
 
-    create_price_lists(args)
-    create_fiscal_year_and_company(args)
-    create_users(args)
-    set_defaults(args)
-    create_territories()
-    create_feed_and_todo()
-    create_email_digest()
-    create_letter_head(args)
-    create_taxes(args)
-    create_items(args)
-    create_customers(args)
-    create_suppliers(args)
+	create_price_lists(args)
+	create_fiscal_year_and_company(args)
+	create_sales_tax(args)
+	create_users(args)
+	set_defaults(args)
+	create_territories()
+	create_feed_and_todo()
+	create_email_digest()
+	create_letter_head(args)
+	create_taxes(args)
+	create_items(args)
+	create_customers(args)
+	create_suppliers(args)
 
-    if args.domain.lower() == 'education':
-        create_academic_year()
-        create_academic_term()
-        create_program(args)
-        create_course(args)
-        create_instructor(args)
-        create_room(args)
+	if args.domain.lower() == 'education':
+		create_academic_year()
+		create_academic_term()
+		create_program(args)
+		create_course(args)
+		create_instructor(args)
+		create_room(args)
 
-    if args.get('setup_website'):
-        website_maker(args)
+	if args.get('setup_website'):
+		website_maker(args)
 
-    create_logo(args)
+	create_logo(args)
 
-    frappe.local.message_log = []
-    setup_domain(args.get('domain'))
+	frappe.local.message_log = []
+	setup_domain(args.get('domain'))
 
-    frappe.db.commit()
-    login_as_first_user(args)
+	frappe.db.commit()
+	login_as_first_user(args)
 
-    frappe.db.commit()
-    frappe.clear_cache()
+	frappe.db.commit()
+	frappe.clear_cache()
 
-    if args.get("add_sample_data"):
-        try:
-            make_sample_data()
-            frappe.clear_cache()
-        except:
-            # clear message
-            if frappe.message_log:
-                frappe.message_log.pop()
+	if args.get("add_sample_data"):
+		try:
+			make_sample_data()
+			frappe.clear_cache()
+		except:
+			# clear message
+			if frappe.message_log:
+				frappe.message_log.pop()
 
-            pass
-
+			pass
+ 
 def create_fiscal_year_and_company(args):
-    if (args.get('fy_start_date')):
-        curr_fiscal_year = get_fy_details(args.get('fy_start_date'), args.get('fy_end_date'))
-        frappe.get_doc({
-        "doctype":"Fiscal Year",
-        'year': curr_fiscal_year,
-        'year_start_date': args.get('fy_start_date'),
-        'year_end_date': args.get('fy_end_date'),
-        }).insert()
-        args["curr_fiscal_year"] = curr_fiscal_year
+	if (args.get('fy_start_date')):
+		curr_fiscal_year = get_fy_details(args.get('fy_start_date'), args.get('fy_end_date'))
+		frappe.get_doc({
+		"doctype":"Fiscal Year",
+		'year': curr_fiscal_year,
+		'year_start_date': args.get('fy_start_date'),
+		'year_end_date': args.get('fy_end_date'),
+		}).insert()
+		args["curr_fiscal_year"] = curr_fiscal_year
 
-    # Company
-    if (args.get('company_name')):
-        frappe.get_doc({
-            "doctype":"Company",
-            'company_name':args.get('company_name').strip(),
-            'abbr':args.get('company_abbr'),
-            'default_currency':args.get('currency'),
-            'country': args.get('country'),
-            'chart_of_accounts': args.get(('chart_of_accounts')),
-            'domain': args.get('domain')
-        }).insert()
+	# Company
+	if (args.get('company_name')):
+		frappe.get_doc({
+			"doctype":"Company",
+			'company_name':args.get('company_name').strip(),
+			'abbr':args.get('company_abbr'),
+			'default_currency':args.get('currency'),
+			'country': args.get('country'),
+			'chart_of_accounts': args.get(('chart_of_accounts')),
+			'domain': args.get('domain')
+		}).insert()
 
-        #Enable shopping cart
-        enable_shopping_cart(args)
+		#Enable shopping cart
+		enable_shopping_cart(args)
 
-        # Bank Account
-        create_bank_account(args)
+		# Bank Account
+		create_bank_account(args)
 
 def enable_shopping_cart(args):
-    frappe.get_doc({
-        "doctype": "Shopping Cart Settings",
-        "enabled": 1,
-        'company': args.get('company_name').strip(),
-        'price_list': frappe.db.get_value("Price List", {"selling": 1}),
-        'default_customer_group': _("Individual"),
-        'quotation_series': "QTN-",
-    }).insert()
+	frappe.get_doc({
+		"doctype": "Shopping Cart Settings",
+		"enabled": 1,
+		'company': args.get('company_name').strip(),
+		'price_list': frappe.db.get_value("Price List", {"selling": 1}),
+		'default_customer_group': _("Individual"),
+		'quotation_series': "QTN-",
+	}).insert()
 
 def create_bank_account(args):
-    if args.get("bank_account"):
-        company_name = args.get('company_name').strip()
-        bank_account_group =  frappe.db.get_value("Account",
-            {"account_type": "Bank", "is_group": 1, "root_type": "Asset",
-                "company": company_name})
-        if bank_account_group:
-            bank_account = frappe.get_doc({
-                "doctype": "Account",
-                'account_name': args.get("bank_account"),
-                'parent_account': bank_account_group,
-                'is_group':0,
-                'company': company_name,
-                "account_type": "Bank",
-            })
-            try:
-                return bank_account.insert()
-            except RootNotEditable:
-                frappe.throw(_("Bank account cannot be named as {0}").format(args.get("bank_account")))
-            except frappe.DuplicateEntryError:
-                # bank account same as a CoA entry
-                pass
+	if args.get("bank_account"):
+		company_name = args.get('company_name').strip()
+		bank_account_group =  frappe.db.get_value("Account",
+			{"account_type": "Bank", "is_group": 1, "root_type": "Asset",
+				"company": company_name})
+		if bank_account_group:
+			bank_account = frappe.get_doc({
+				"doctype": "Account",
+				'account_name': args.get("bank_account"),
+				'parent_account': bank_account_group,
+				'is_group':0,
+				'company': company_name,
+				"account_type": "Bank",
+			})
+			try:
+				return bank_account.insert()
+			except RootNotEditable:
+				frappe.throw(_("Bank account cannot be named as {0}").format(args.get("bank_account")))
+			except frappe.DuplicateEntryError:
+				# bank account same as a CoA entry
+				pass
 
 def create_price_lists(args):
-    for pl_type, pl_name in (("Selling", _("Standard Selling")), ("Buying", _("Standard Buying"))):
-        frappe.get_doc({
-            "doctype": "Price List",
-            "price_list_name": pl_name,
-            "enabled": 1,
-            "buying": 1 if pl_type == "Buying" else 0,
-            "selling": 1 if pl_type == "Selling" else 0,
-            "currency": args["currency"]
-        }).insert()
+	for pl_type, pl_name in (("Selling", _("Standard Selling")), ("Buying", _("Standard Buying"))):
+		frappe.get_doc({
+			"doctype": "Price List",
+			"price_list_name": pl_name,
+			"enabled": 1,
+			"buying": 1 if pl_type == "Buying" else 0,
+			"selling": 1 if pl_type == "Selling" else 0,
+			"currency": args["currency"]
+		}).insert()
 
 def set_defaults(args):
-    # enable default currency
-    frappe.db.set_value("Currency", args.get("currency"), "enabled", 1)
+	# enable default currency
+	frappe.db.set_value("Currency", args.get("currency"), "enabled", 1)
 
-    global_defaults = frappe.get_doc("Global Defaults", "Global Defaults")
-    global_defaults.update({
-        'current_fiscal_year': args.curr_fiscal_year,
-        'default_currency': args.get('currency'),
-        'default_company':args.get('company_name').strip(),
-        "country": args.get("country"),
-    })
+	global_defaults = frappe.get_doc("Global Defaults", "Global Defaults")
+	global_defaults.update({
+		'current_fiscal_year': args.curr_fiscal_year,
+		'default_currency': args.get('currency'),
+		'default_company':args.get('company_name').strip(),
+		"country": args.get("country"),
+	})
 
-    global_defaults.save()
+	global_defaults.save()
 
-    frappe.db.set_value("System Settings", None, "email_footer_address", args.get("company"))
+	frappe.db.set_value("System Settings", None, "email_footer_address", args.get("company"))
 
-    accounts_settings = frappe.get_doc("Accounts Settings")
-    accounts_settings.auto_accounting_for_stock = 1
-    accounts_settings.save()
+	accounts_settings = frappe.get_doc("Accounts Settings")
+	accounts_settings.auto_accounting_for_stock = 1
+	accounts_settings.save()
 
-    stock_settings = frappe.get_doc("Stock Settings")
-    stock_settings.item_naming_by = "Item Code"
-    stock_settings.valuation_method = "FIFO"
-    stock_settings.default_warehouse = frappe.db.get_value('Warehouse', {'warehouse_name': _('Stores')})
-    stock_settings.stock_uom = _("Nos")
-    stock_settings.auto_indent = 1
-    stock_settings.auto_insert_price_list_rate_if_missing = 1
-    stock_settings.automatically_set_serial_nos_based_on_fifo = 1
-    stock_settings.save()
+	stock_settings = frappe.get_doc("Stock Settings")
+	stock_settings.item_naming_by = "Item Code"
+	stock_settings.valuation_method = "FIFO"
+	stock_settings.default_warehouse = frappe.db.get_value('Warehouse', {'warehouse_name': _('Stores')})
+	stock_settings.stock_uom = _("Nos")
+	stock_settings.auto_indent = 1
+	stock_settings.auto_insert_price_list_rate_if_missing = 1
+	stock_settings.automatically_set_serial_nos_based_on_fifo = 1
+	stock_settings.save()
 
-    selling_settings = frappe.get_doc("Selling Settings")
-    selling_settings.cust_master_name = "Customer Name"
-    selling_settings.so_required = "No"
-    selling_settings.dn_required = "No"
-    selling_settings.save()
+	selling_settings = frappe.get_doc("Selling Settings")
+	selling_settings.cust_master_name = "Customer Name"
+	selling_settings.so_required = "No"
+	selling_settings.dn_required = "No"
+	selling_settings.save()
 
-    buying_settings = frappe.get_doc("Buying Settings")
-    buying_settings.supp_master_name = "Supplier Name"
-    buying_settings.po_required = "No"
-    buying_settings.pr_required = "No"
-    buying_settings.maintain_same_rate = 1
-    buying_settings.save()
+	buying_settings = frappe.get_doc("Buying Settings")
+	buying_settings.supp_master_name = "Supplier Name"
+	buying_settings.po_required = "No"
+	buying_settings.pr_required = "No"
+	buying_settings.maintain_same_rate = 1
+	buying_settings.save()
 
-    notification_control = frappe.get_doc("Notification Control")
-    notification_control.quotation = 1
-    notification_control.sales_invoice = 1
-    notification_control.purchase_order = 1
-    notification_control.save()
+	notification_control = frappe.get_doc("Notification Control")
+	notification_control.quotation = 1
+	notification_control.sales_invoice = 1
+	notification_control.purchase_order = 1
+	notification_control.save()
 
-    hr_settings = frappe.get_doc("HR Settings")
-    hr_settings.emp_created_by = "Naming Series"
-    hr_settings.save()
+	hr_settings = frappe.get_doc("HR Settings")
+	hr_settings.emp_created_by = "Naming Series"
+	hr_settings.save()
 
 def create_feed_and_todo():
-    """update Activity feed and create todo for creation of item, customer, vendor"""
-    add_info_comment(**{
-        "subject": _("ERPNext Setup Complete!")
-    })
+	"""update Activity feed and create todo for creation of item, customer, vendor"""
+	add_info_comment(**{
+		"subject": _("ERPNext Setup Complete!")
+	})
 
 def create_email_digest():
-    from frappe.utils.user import get_system_managers
-    system_managers = get_system_managers(only_name=True)
-    if not system_managers:
-        return
+	from frappe.utils.user import get_system_managers
+	system_managers = get_system_managers(only_name=True)
+	if not system_managers:
+		return
 
-    companies = frappe.db.sql_list("select name FROM `tabCompany`")
-    for company in companies:
-        if not frappe.db.exists("Email Digest", "Default Weekly Digest - " + company):
-            edigest = frappe.get_doc({
-                "doctype": "Email Digest",
-                "name": "Default Weekly Digest - " + company,
-                "company": company,
-                "frequency": "Weekly",
-                "recipient_list": "\n".join(system_managers)
-            })
+	companies = frappe.db.sql_list("select name FROM `tabCompany`")
+	for company in companies:
+		if not frappe.db.exists("Email Digest", "Default Weekly Digest - " + company):
+			edigest = frappe.get_doc({
+				"doctype": "Email Digest",
+				"name": "Default Weekly Digest - " + company,
+				"company": company,
+				"frequency": "Weekly",
+				"recipient_list": "\n".join(system_managers)
+			})
 
-            for df in edigest.meta.get("fields", {"fieldtype": "Check"}):
-                if df.fieldname != "scheduler_errors":
-                    edigest.set(df.fieldname, 1)
+			for df in edigest.meta.get("fields", {"fieldtype": "Check"}):
+				if df.fieldname != "scheduler_errors":
+					edigest.set(df.fieldname, 1)
 
-            edigest.insert()
+			edigest.insert()
 
-    # scheduler errors digest
-    if companies:
-        edigest = frappe.new_doc("Email Digest")
-        edigest.update({
-            "name": "Scheduler Errors",
-            "company": companies[0],
-            "frequency": "Daily",
-            "recipient_list": "\n".join(system_managers),
-            "scheduler_errors": 1,
-            "enabled": 1
-        })
-        edigest.insert()
+	# scheduler errors digest
+	if companies:
+		edigest = frappe.new_doc("Email Digest")
+		edigest.update({
+			"name": "Scheduler Errors",
+			"company": companies[0],
+			"frequency": "Daily",
+			"recipient_list": "\n".join(system_managers),
+			"scheduler_errors": 1,
+			"enabled": 1
+		})
+		edigest.insert()
 
 def get_fy_details(fy_start_date, fy_end_date):
-    start_year = getdate(fy_start_date).year
-    if start_year == getdate(fy_end_date).year:
-        fy = cstr(start_year)
-    else:
-        fy = cstr(start_year) + '-' + cstr(start_year + 1)
-    return fy
+	start_year = getdate(fy_start_date).year
+	if start_year == getdate(fy_end_date).year:
+		fy = cstr(start_year)
+	else:
+		fy = cstr(start_year) + '-' + cstr(start_year + 1)
+	return fy
+	
+def create_sales_tax(args):
+	country_wise_tax = get_country_wise_tax(args.get("country"))
+	if len(country_wise_tax)>0:
+		for sales_tax, tax_data in country_wise_tax.items():
+			make_tax_account_and_template(args.get("company_name").strip(), 
+				tax_data.get('account_name'), tax_data.get('tax_rate'), sales_tax)
+
+def get_country_wise_tax(country):
+	data = {}
+	with open (os.path.join(os.path.dirname(__file__), "data", "country_wise_tax.json")) as countrywise_tax:
+		data = json.load(countrywise_tax).get(country)
+
+	return data
 
 def create_taxes(args):
+	for i in xrange(1,6):
+		if args.get("tax_" + str(i)):
+			# replace % in case someone also enters the % symbol
+			tax_rate = cstr(args.get("tax_rate_" + str(i)) or "").replace("%", "")
+			account_name = args.get("tax_" + str(i))
 
-    for i in xrange(1,6):
-        if args.get("tax_" + str(i)):
-            # replace % in case someone also enters the % symbol
-            tax_rate = cstr(args.get("tax_rate_" + str(i)) or "").replace("%", "")
+			make_tax_account_and_template(args.get("company_name").strip(), account_name, tax_rate)
+			
+def make_tax_account_and_template(company, account_name, tax_rate, template_name=None):
+	try:
+		account = make_tax_account(company, account_name, tax_rate)
+		if account:
+			make_sales_and_purchase_tax_templates(account, template_name)
+	except frappe.NameError, e:
+		if e.args[2][0]==1062:
+			pass
+		else:
+			raise
+	except RootNotEditable, e:
+		pass
+				
+def get_tax_account_group(company):
+	tax_group = frappe.db.get_value("Account", 
+		{"account_name": "Duties and Taxes", "is_group": 1, "company": company})
+	if not tax_group:
+		tax_group = frappe.db.get_value("Account", {"is_group": 1, "root_type": "Liability", 
+				"account_type": "Tax", "company": company})
+				
+	return tax_group
 
-            try:
-                tax_group = frappe.db.get_value("Account", {"company": args.get("company_name"),
-                    "is_group": 1, "account_type": "Tax", "root_type": "Liability"})
-                if tax_group:
-                    account = make_tax_head(args, i, tax_group, tax_rate)
-                    make_sales_and_purchase_tax_templates(account)
+def make_tax_account(company, account_name, tax_rate):
+	tax_group = get_tax_account_group(company)
+	if tax_group:
+		return frappe.get_doc({
+			"doctype":"Account",
+			"company": company,
+			"parent_account": tax_group,
+			"account_name": account_name,
+			"is_group": 0,
+			"report_type": "Balance Sheet",
+			"root_type": "Liability",
+			"account_type": "Tax",
+			"tax_rate": flt(tax_rate) if tax_rate else None
+		}).insert(ignore_permissions=True)
 
-            except frappe.NameError, e:
-                if e.args[2][0]==1062:
-                    pass
-                else:
-                    raise
-            except RootNotEditable, e:
-                pass
+def make_sales_and_purchase_tax_templates(account, template_name=None):
+	if not template_name:
+		template_name = account.name
+		
+	sales_tax_template = {
+		"doctype": "Sales Taxes and Charges Template",
+		"title": template_name,
+		"company": account.company,
+		"taxes": [{
+			"category": "Valuation and Total",
+			"charge_type": "On Net Total",
+			"account_head": account.name,
+			"description": "{0} @ {1}".format(account.account_name, account.tax_rate),
+			"rate": account.tax_rate
+		}]
+	}
 
-def make_tax_head(args, i, tax_group, tax_rate):
-    return frappe.get_doc({
-        "doctype":"Account",
-        "company": args.get("company_name").strip(),
-        "parent_account": tax_group,
-        "account_name": args.get("tax_" + str(i)),
-        "is_group": 0,
-        "report_type": "Balance Sheet",
-        "account_type": "Tax",
-        "tax_rate": flt(tax_rate) if tax_rate else None
-    }).insert(ignore_permissions=True)
+	# Sales
+	frappe.get_doc(copy.deepcopy(sales_tax_template)).insert(ignore_permissions=True)
 
-def make_sales_and_purchase_tax_templates(account):
-    doc = {
-        "doctype": "Sales Taxes and Charges Template",
-        "title": account.name,
-        "taxes": [{
-            "category": "Valuation and Total",
-            "charge_type": "On Net Total",
-            "account_head": account.name,
-            "description": "{0} @ {1}".format(account.account_name, account.tax_rate),
-            "rate": account.tax_rate
-        }]
-    }
-
-    # Sales
-    frappe.get_doc(copy.deepcopy(doc)).insert()
-
-    # Purchase
-    doc["doctype"] = "Purchase Taxes and Charges Template"
-    frappe.get_doc(copy.deepcopy(doc)).insert()
+	# Purchase
+	purchase_tax_template = copy.deepcopy(sales_tax_template)
+	purchase_tax_template["doctype"] = "Purchase Taxes and Charges Template"
+	frappe.get_doc(purchase_tax_template).insert(ignore_permissions=True)
 
 def create_items(args):
-    for i in xrange(1,6):
-        item = args.get("item_" + str(i))
-        if item:
-            item_group = args.get("item_group_" + str(i))
-            is_sales_item = args.get("is_sales_item_" + str(i))
-            is_purchase_item = args.get("is_purchase_item_" + str(i))
-            is_stock_item = item_group!=_("Services")
-            default_warehouse = ""
-            if is_stock_item:
-                default_warehouse = frappe.db.get_value("Warehouse", filters={
-                    "warehouse_name": _("Finished Goods") if is_sales_item else _("Stores"),
-                    "company": args.get("company_name").strip()
-                })
+	for i in xrange(1,6):
+		item = args.get("item_" + str(i))
+		if item:
+			item_group = args.get("item_group_" + str(i))
+			is_sales_item = args.get("is_sales_item_" + str(i))
+			is_purchase_item = args.get("is_purchase_item_" + str(i))
+			is_stock_item = item_group!=_("Services")
+			default_warehouse = ""
+			if is_stock_item:
+				default_warehouse = frappe.db.get_value("Warehouse", filters={
+					"warehouse_name": _("Finished Goods") if is_sales_item else _("Stores"),
+					"company": args.get("company_name").strip()
+				})
 
-            try:
-                frappe.get_doc({
-                    "doctype":"Item",
-                    "item_code": item,
-                    "item_name": item,
-                    "description": item,
-                    "show_in_website": 1,
-                    "is_sales_item": is_sales_item,
-                    "is_purchase_item": is_purchase_item,
-                    "is_stock_item": is_stock_item and 1 or 0,
-                    "item_group": item_group,
-                    "stock_uom": args.get("item_uom_" + str(i)),
-                    "default_warehouse": default_warehouse
-                }).insert()
+			try:
+				frappe.get_doc({
+					"doctype":"Item",
+					"item_code": item,
+					"item_name": item,
+					"description": item,
+					"show_in_website": 1,
+					"is_sales_item": is_sales_item,
+					"is_purchase_item": is_purchase_item,
+					"is_stock_item": is_stock_item and 1 or 0,
+					"item_group": item_group,
+					"stock_uom": args.get("item_uom_" + str(i)),
+					"default_warehouse": default_warehouse
+				}).insert()
 
-                if args.get("item_img_" + str(i)):
-                    item_image = args.get("item_img_" + str(i)).split(",")
-                    if len(item_image)==3:
-                        filename, filetype, content = item_image
-                        fileurl = save_file(filename, content, "Item", item, decode=True).file_url
-                        frappe.db.set_value("Item", item, "image", fileurl)
+				if args.get("item_img_" + str(i)):
+					item_image = args.get("item_img_" + str(i)).split(",")
+					if len(item_image)==3:
+						filename, filetype, content = item_image
+						fileurl = save_file(filename, content, "Item", item, decode=True).file_url
+						frappe.db.set_value("Item", item, "image", fileurl)
 
-                if args.get("item_price_" + str(i)):
-                    item_price = flt(args.get("item_price_" + str(i)))
+				if args.get("item_price_" + str(i)):
+					item_price = flt(args.get("item_price_" + str(i)))
 
-                    if is_sales_item:
-                        price_list_name = frappe.db.get_value("Price List", {"selling": 1})
-                        make_item_price(item, price_list_name, item_price)
+					if is_sales_item:
+						price_list_name = frappe.db.get_value("Price List", {"selling": 1})
+						make_item_price(item, price_list_name, item_price)
 
-                    if is_purchase_item:
-                        price_list_name = frappe.db.get_value("Price List", {"buying": 1})
-                        make_item_price(item, price_list_name, item_price)
+					if is_purchase_item:
+						price_list_name = frappe.db.get_value("Price List", {"buying": 1})
+						make_item_price(item, price_list_name, item_price)
 
-            except frappe.NameError:
-                pass
+			except frappe.NameError:
+				pass
 
 def make_item_price(item, price_list_name, item_price):
-    frappe.get_doc({
-        "doctype": "Item Price",
-        "price_list": price_list_name,
-        "item_code": item,
-        "price_list_rate": item_price
-    }).insert()
+	frappe.get_doc({
+		"doctype": "Item Price",
+		"price_list": price_list_name,
+		"item_code": item,
+		"price_list_rate": item_price
+	}).insert()
 
 
 def create_customers(args):
-    for i in xrange(1,6):
-        customer = args.get("customer_" + str(i))
-        if customer:
-            try:
-                doc = frappe.get_doc({
-                    "doctype":"Customer",
-                    "customer_name": customer,
-                    "customer_type": "Company",
-                    "customer_group": _("Commercial"),
-                    "territory": args.get("country"),
-                    "company": args.get("company_name").strip()
-                }).insert()
+	for i in xrange(1,6):
+		customer = args.get("customer_" + str(i))
+		if customer:
+			try:
+				doc = frappe.get_doc({
+					"doctype":"Customer",
+					"customer_name": customer,
+					"customer_type": "Company",
+					"customer_group": _("Commercial"),
+					"territory": args.get("country"),
+					"company": args.get("company_name").strip()
+				}).insert()
 
-                if args.get("customer_contact_" + str(i)):
-                    create_contact(args.get("customer_contact_" + str(i)),
-                        "customer", doc.name)
-            except frappe.NameError:
-                pass
+				if args.get("customer_contact_" + str(i)):
+					create_contact(args.get("customer_contact_" + str(i)),
+						"customer", doc.name)
+			except frappe.NameError:
+				pass
 
 def create_suppliers(args):
-    for i in xrange(1,6):
-        supplier = args.get("supplier_" + str(i))
-        if supplier:
-            try:
-                doc = frappe.get_doc({
-                    "doctype":"Supplier",
-                    "supplier_name": supplier,
-                    "supplier_type": _("Local"),
-                    "company": args.get("company_name").strip()
-                }).insert()
+	for i in xrange(1,6):
+		supplier = args.get("supplier_" + str(i))
+		if supplier:
+			try:
+				doc = frappe.get_doc({
+					"doctype":"Supplier",
+					"supplier_name": supplier,
+					"supplier_type": _("Local"),
+					"company": args.get("company_name").strip()
+				}).insert()
 
-                if args.get("supplier_contact_" + str(i)):
-                    create_contact(args.get("supplier_contact_" + str(i)),
-                        "supplier", doc.name)
-            except frappe.NameError:
-                pass
+				if args.get("supplier_contact_" + str(i)):
+					create_contact(args.get("supplier_contact_" + str(i)),
+						"supplier", doc.name)
+			except frappe.NameError:
+				pass
 
 def create_contact(contact, party_type, party):
-    """Create contact based on given contact name"""
-    contact = contact.strip().split(" ")
+	"""Create contact based on given contact name"""
+	contact = contact.strip().split(" ")
 
-    frappe.get_doc({
-        "doctype":"Contact",
-        party_type: party,
-        "first_name":contact[0],
-        "last_name": len(contact) > 1 and contact[1] or ""
-    }).insert()
+	frappe.get_doc({
+		"doctype":"Contact",
+		party_type: party,
+		"first_name":contact[0],
+		"last_name": len(contact) > 1 and contact[1] or ""
+	}).insert()
 
 def create_letter_head(args):
-    if args.get("attach_letterhead"):
-        frappe.get_doc({
-            "doctype":"Letter Head",
-            "letter_head_name": _("Standard"),
-            "is_default": 1
-        }).insert()
+	if args.get("attach_letterhead"):
+		frappe.get_doc({
+			"doctype":"Letter Head",
+			"letter_head_name": _("Standard"),
+			"is_default": 1
+		}).insert()
 
-        attach_letterhead = args.get("attach_letterhead").split(",")
-        if len(attach_letterhead)==3:
-            filename, filetype, content = attach_letterhead
-            fileurl = save_file(filename, content, "Letter Head", _("Standard"), decode=True).file_url
-            frappe.db.set_value("Letter Head", _("Standard"), "content", "<img src='%s' style='max-width: 100%%;'>" % fileurl)
+		attach_letterhead = args.get("attach_letterhead").split(",")
+		if len(attach_letterhead)==3:
+			filename, filetype, content = attach_letterhead
+			fileurl = save_file(filename, content, "Letter Head", _("Standard"), decode=True).file_url
+			frappe.db.set_value("Letter Head", _("Standard"), "content", "<img src='%s' style='max-width: 100%%;'>" % fileurl)
 
 def create_logo(args):
-    if args.get("attach_logo"):
-        attach_logo = args.get("attach_logo").split(",")
-        if len(attach_logo)==3:
-            filename, filetype, content = attach_logo
-            fileurl = save_file(filename, content, "Website Settings", "Website Settings",
-                decode=True).file_url
-            frappe.db.set_value("Website Settings", "Website Settings", "brand_html",
-                "<img src='{0}' style='max-width: 40px; max-height: 25px;'> {1}".format(fileurl, args.get("company_name").strip()))
+	if args.get("attach_logo"):
+		attach_logo = args.get("attach_logo").split(",")
+		if len(attach_logo)==3:
+			filename, filetype, content = attach_logo
+			fileurl = save_file(filename, content, "Website Settings", "Website Settings",
+				decode=True).file_url
+			frappe.db.set_value("Website Settings", "Website Settings", "brand_html",
+				"<img src='{0}' style='max-width: 40px; max-height: 25px;'> {1}".format(fileurl, args.get("company_name").strip()))
 
 def create_territories():
-    """create two default territories, one for home country and one named Rest of the World"""
-    from frappe.utils.nestedset import get_root_of
-    country = frappe.db.get_default("country")
-    root_territory = get_root_of("Territory")
-    for name in (country, _("Rest Of The World")):
-        if name and not frappe.db.exists("Territory", name):
-            frappe.get_doc({
-                "doctype": "Territory",
-                "territory_name": name.replace("'", ""),
-                "parent_territory": root_territory,
-                "is_group": "No"
-            }).insert()
+	"""create two default territories, one for home country and one named Rest of the World"""
+	from frappe.utils.nestedset import get_root_of
+	country = frappe.db.get_default("country")
+	root_territory = get_root_of("Territory")
+	for name in (country, _("Rest Of The World")):
+		if name and not frappe.db.exists("Territory", name):
+			frappe.get_doc({
+				"doctype": "Territory",
+				"territory_name": name.replace("'", ""),
+				"parent_territory": root_territory,
+				"is_group": "No"
+			}).insert()
 
 def login_as_first_user(args):
-    if args.get("email") and hasattr(frappe.local, "login_manager"):
-        frappe.local.login_manager.login_as(args.get("email"))
+	if args.get("email") and hasattr(frappe.local, "login_manager"):
+		frappe.local.login_manager.login_as(args.get("email"))
 
 def create_users(args):
-    if frappe.session.user == 'Administrator':
-        return
+	if frappe.session.user == 'Administrator':
+		return
 
-    # create employee for self
-    emp = frappe.get_doc({
-        "doctype": "Employee",
-        "employee_name": " ".join(filter(None, [args.get("first_name"), args.get("last_name")])),
-        "user_id": frappe.session.user,
-        "status": "Active",
-        "company": args.get("company_name")
-    })
-    emp.flags.ignore_mandatory = True
-    emp.insert(ignore_permissions = True)
+	# create employee for self
+	emp = frappe.get_doc({
+		"doctype": "Employee",
+		"employee_name": " ".join(filter(None, [args.get("first_name"), args.get("last_name")])),
+		"user_id": frappe.session.user,
+		"status": "Active",
+		"company": args.get("company_name")
+	})
+	emp.flags.ignore_mandatory = True
+	emp.insert(ignore_permissions = True)
 
-    for i in xrange(1,5):
-        email = args.get("user_email_" + str(i))
-        fullname = args.get("user_fullname_" + str(i))
-        if email:
-            if not fullname:
-                fullname = email.split("@")[0]
+	for i in xrange(1,5):
+		email = args.get("user_email_" + str(i))
+		fullname = args.get("user_fullname_" + str(i))
+		if email:
+			if not fullname:
+				fullname = email.split("@")[0]
 
-            parts = fullname.split(" ", 1)
+			parts = fullname.split(" ", 1)
 
-            user = frappe.get_doc({
-                "doctype": "User",
-                "email": email,
-                "first_name": parts[0],
-                "last_name": parts[1] if len(parts) > 1 else "",
-                "enabled": 1,
-                "user_type": "System User"
-            })
+			user = frappe.get_doc({
+				"doctype": "User",
+				"email": email,
+				"first_name": parts[0],
+				"last_name": parts[1] if len(parts) > 1 else "",
+				"enabled": 1,
+				"user_type": "System User"
+			})
 
-            # default roles
-            user.append_roles("Projects User", "Stock User", "Support Team")
+			# default roles
+			user.append_roles("Projects User", "Stock User", "Support Team")
 
-            if args.get("user_sales_" + str(i)):
-                user.append_roles("Sales User", "Sales Manager", "Accounts User")
-            if args.get("user_purchaser_" + str(i)):
-                user.append_roles("Purchase User", "Purchase Manager", "Accounts User")
-            if args.get("user_accountant_" + str(i)):
-                user.append_roles("Accounts Manager", "Accounts User")
+			if args.get("user_sales_" + str(i)):
+				user.append_roles("Sales User", "Sales Manager", "Accounts User")
+			if args.get("user_purchaser_" + str(i)):
+				user.append_roles("Purchase User", "Purchase Manager", "Accounts User")
+			if args.get("user_accountant_" + str(i)):
+				user.append_roles("Accounts Manager", "Accounts User")
 
-            user.flags.delay_emails = True
+			user.flags.delay_emails = True
 
-            if not frappe.db.get_value("User", email):
-                user.insert(ignore_permissions=True)
+			if not frappe.db.get_value("User", email):
+				user.insert(ignore_permissions=True)
 
-                # create employee
-                emp = frappe.get_doc({
-                    "doctype": "Employee",
-                    "employee_name": fullname,
-                    "user_id": email,
-                    "status": "Active",
-                    "company": args.get("company_name")
-                })
-                emp.flags.ignore_mandatory = True
-                emp.insert(ignore_permissions = True)
+				# create employee
+				emp = frappe.get_doc({
+					"doctype": "Employee",
+					"employee_name": fullname,
+					"user_id": email,
+					"status": "Active",
+					"company": args.get("company_name")
+				})
+				emp.flags.ignore_mandatory = True
+				emp.insert(ignore_permissions = True)
 
 def create_academic_term():
-    at = ["Semester 1", "Semester 2", "Semester 3"]
-    ay = ["2013-14", "2014-15", "2015-16", "2016-17", "2017-18"]
-    for y in ay:
-        for t in at:
-            academic_term = frappe.new_doc("Academic Term")
-            academic_term.academic_year = y
-            academic_term.term_name = t
-            academic_term.save()
+	at = ["Semester 1", "Semester 2", "Semester 3"]
+	ay = ["2013-14", "2014-15", "2015-16", "2016-17", "2017-18"]
+	for y in ay:
+		for t in at:
+			academic_term = frappe.new_doc("Academic Term")
+			academic_term.academic_year = y
+			academic_term.term_name = t
+			academic_term.save()
 
 def create_academic_year():
-    ac = ["2013-14", "2014-15", "2015-16", "2016-17", "2017-18"]
-    for d in ac:
-        academic_year = frappe.new_doc("Academic Year")
-        academic_year.academic_year_name = d
-        academic_year.save()
+	ac = ["2013-14", "2014-15", "2015-16", "2016-17", "2017-18"]
+	for d in ac:
+		academic_year = frappe.new_doc("Academic Year")
+		academic_year.academic_year_name = d
+		academic_year.save()
 
 def create_program(args):
-    for i in xrange(1,6):
-        if args.get("program_" + str(i)):
-            program = frappe.new_doc("Program")
-            program.program_name = args.get("program_" + str(i))
-            program.save()
+	for i in xrange(1,6):
+		if args.get("program_" + str(i)):
+			program = frappe.new_doc("Program")
+			program.program_name = args.get("program_" + str(i))
+			program.save()
 
 def create_course(args):
-    for i in xrange(1,6):
-        if args.get("course_" + str(i)):
-            course = frappe.new_doc("Course")
-            course.course_name = args.get("course_" + str(i))
-            course.save()
+	for i in xrange(1,6):
+		if args.get("course_" + str(i)):
+			course = frappe.new_doc("Course")
+			course.course_name = args.get("course_" + str(i))
+			course.save()
 
 def create_instructor(args):
-    for i in xrange(1,6):
-        if args.get("instructor_" + str(i)):
-            instructor = frappe.new_doc("Instructor")
-            instructor.instructor_name = args.get("instructor_" + str(i))
-            instructor.save()
+	for i in xrange(1,6):
+		if args.get("instructor_" + str(i)):
+			instructor = frappe.new_doc("Instructor")
+			instructor.instructor_name = args.get("instructor_" + str(i))
+			instructor.save()
 
 def create_room(args):
-    for i in xrange(1,6):
-        if args.get("room_" + str(i)):
-            room = frappe.new_doc("Room")
-            room.room_name = args.get("room_" + str(i))
-            room.seating_capacity = args.get("room_capacity_" + str(i))
-            room.save()
+	for i in xrange(1,6):
+		if args.get("room_" + str(i)):
+			room = frappe.new_doc("Room")
+			room.room_name = args.get("room_" + str(i))
+			room.seating_capacity = args.get("room_capacity_" + str(i))
+			room.save()
 
 
diff --git a/erpnext/stock/doctype/bin/bin.py b/erpnext/stock/doctype/bin/bin.py
index 2378e3f..ece8220 100644
--- a/erpnext/stock/doctype/bin/bin.py
+++ b/erpnext/stock/doctype/bin/bin.py
@@ -14,18 +14,18 @@
 			self.stock_uom = frappe.db.get_value('Item', self.item_code, 'stock_uom')
 
 		self.validate_mandatory()
-
-		self.projected_qty = flt(self.actual_qty) + flt(self.ordered_qty) + \
-			flt(self.indented_qty) + flt(self.planned_qty) - flt(self.reserved_qty)
-		
+		self.set_projected_qty()
 		self.block_transactions_against_group_warehouse()
 
+	def on_update(self):
+		update_item_projected_qty(self.item_code)
+
 	def validate_mandatory(self):
 		qf = ['actual_qty', 'reserved_qty', 'ordered_qty', 'indented_qty']
 		for f in qf:
 			if (not getattr(self, f, None)) or (not self.get(f)):
 				self.set(f, 0.0)
-	
+
 	def block_transactions_against_group_warehouse(self):
 		from erpnext.stock.utils import is_group_warehouse
 		is_group_warehouse(self.warehouse)
@@ -72,9 +72,7 @@
 		self.indented_qty = flt(self.indented_qty) + flt(args.get("indented_qty"))
 		self.planned_qty = flt(self.planned_qty) + flt(args.get("planned_qty"))
 
-		self.set_projected_qty()
 		self.save()
-		update_item_projected_qty(self.item_code)
 
 	def set_projected_qty(self):
 		self.projected_qty = (flt(self.actual_qty) + flt(self.ordered_qty)
diff --git a/erpnext/stock/doctype/delivery_note/delivery_note.json b/erpnext/stock/doctype/delivery_note/delivery_note.json
index 1ab1abe..01924a9 100644
--- a/erpnext/stock/doctype/delivery_note/delivery_note.json
+++ b/erpnext/stock/doctype/delivery_note/delivery_note.json
@@ -362,7 +362,7 @@
    "in_list_view": 0, 
    "label": "Is Return", 
    "length": 0, 
-   "no_copy": 0, 
+   "no_copy": 1, 
    "permlevel": 0, 
    "precision": "", 
    "print_hide": 1, 
@@ -389,7 +389,7 @@
    "in_list_view": 0, 
    "label": "Return Against Delivery Note", 
    "length": 0, 
-   "no_copy": 0, 
+   "no_copy": 1, 
    "options": "Delivery Note", 
    "permlevel": 0, 
    "precision": "", 
@@ -2908,7 +2908,7 @@
  "istable": 0, 
  "max_attachments": 0, 
  "menu_index": 0, 
- "modified": "2016-09-16 05:55:36.487662", 
+ "modified": "2016-09-23 18:01:54.003673", 
  "modified_by": "Administrator", 
  "module": "Stock", 
  "name": "Delivery Note", 
diff --git a/erpnext/stock/doctype/delivery_note/delivery_note_dashboard.py b/erpnext/stock/doctype/delivery_note/delivery_note_dashboard.py
index c2b54f8..adbfa4d 100644
--- a/erpnext/stock/doctype/delivery_note/delivery_note_dashboard.py
+++ b/erpnext/stock/doctype/delivery_note/delivery_note_dashboard.py
@@ -1,26 +1,27 @@
 from frappe import _
 
-data = {
-	'fieldname': 'delivery_note_no',
-	'non_standard_fieldnames': {
-		'Sales Invoice': 'delivery_note',
-		'Packing Slip': 'delivery_note',
-	},
-	'internal_links': {
-		'Sales Order': ['items', 'against_sales_order'],
-	},
-	'transactions': [
-		{
-			'label': _('Related'),
-			'items': ['Sales Invoice', 'Packing Slip']
+def get_data():
+	return {
+		'fieldname': 'delivery_note_no',
+		'non_standard_fieldnames': {
+			'Sales Invoice': 'delivery_note',
+			'Packing Slip': 'delivery_note',
 		},
-		{
-			'label': _('Reference'),
-			'items': ['Sales Order', 'Quality Inspection']
+		'internal_links': {
+			'Sales Order': ['items', 'against_sales_order'],
 		},
-		{
-			'label': _('Returns'),
-			'items': ['Stock Entry']
-		},
-	]
-}
\ No newline at end of file
+		'transactions': [
+			{
+				'label': _('Related'),
+				'items': ['Sales Invoice', 'Packing Slip']
+			},
+			{
+				'label': _('Reference'),
+				'items': ['Sales Order', 'Quality Inspection']
+			},
+			{
+				'label': _('Returns'),
+				'items': ['Stock Entry']
+			},
+		]
+	}
\ No newline at end of file
diff --git a/erpnext/stock/doctype/item/item.py b/erpnext/stock/doctype/item/item.py
index 454fc70..e9d4cb3 100644
--- a/erpnext/stock/doctype/item/item.py
+++ b/erpnext/stock/doctype/item/item.py
@@ -567,7 +567,7 @@
 		existing_allow_negative_stock = frappe.db.get_value("Stock Settings", None, "allow_negative_stock")
 		frappe.db.set_value("Stock Settings", None, "allow_negative_stock", 1)
 
-		for warehouse in frappe.db.sql("select name from `tabWarehouse`"):
+		for warehouse in frappe.db.sql("select name from `tabWarehouse` where is_group = 0"):
 			repost_stock(new_name, warehouse[0])
 
 		frappe.db.set_value("Stock Settings", None, "allow_negative_stock", existing_allow_negative_stock)
diff --git a/erpnext/stock/doctype/item/item_dashboard.py b/erpnext/stock/doctype/item/item_dashboard.py
index e0f1c21..b40b196 100644
--- a/erpnext/stock/doctype/item/item_dashboard.py
+++ b/erpnext/stock/doctype/item/item_dashboard.py
@@ -1,45 +1,46 @@
 from frappe import _
 
-data = {
-	'heatmap': True,
-	'heatmap_message': _('This is based on stock movement. See {0} for details')\
-		.format('<a href="#query-report/Stock Ledger">' + _('Stock Ledger') + '</a>'),
-	'fieldname': 'item_code',
-	'non_standard_fieldnames': {
-		'Production Order': 'production_item',
-		'Product Bundle': 'new_item_code',
-		'BOM': 'item',
-		'Batch': 'item'
-	},
-	'transactions': [
-		{
-			'label': _('Groups'),
-			'items': ['BOM', 'Product Bundle']
+def get_data():
+	return {
+		'heatmap': True,
+		'heatmap_message': _('This is based on stock movement. See {0} for details')\
+			.format('<a href="#query-report/Stock Ledger">' + _('Stock Ledger') + '</a>'),
+		'fieldname': 'item_code',
+		'non_standard_fieldnames': {
+			'Production Order': 'production_item',
+			'Product Bundle': 'new_item_code',
+			'BOM': 'item',
+			'Batch': 'item'
 		},
-		{
-			'label': _('Pricing'),
-			'items': ['Item Price', 'Pricing Rule']
-		},
-		{
-			'label': _('Sell'),
-			'items': ['Quotation', 'Sales Order', 'Delivery Note', 'Sales Invoice']
-		},
-		{
-			'label': _('Buy'),
-			'items': ['Material Request', 'Supplier Quotation', 'Request for Quotation',
-				'Purchase Order', 'Purchase Invoice']
-		},
-		{
-			'label': _('Traceability'),
-			'items': ['Serial No', 'Batch']
-		},
-		{
-			'label': _('Move'),
-			'items': ['Stock Entry']
-		},
-		{
-			'label': _('Manufacture'),
-			'items': ['Production Order']
-		}
-	]
-}
\ No newline at end of file
+		'transactions': [
+			{
+				'label': _('Groups'),
+				'items': ['BOM', 'Product Bundle']
+			},
+			{
+				'label': _('Pricing'),
+				'items': ['Item Price', 'Pricing Rule']
+			},
+			{
+				'label': _('Sell'),
+				'items': ['Quotation', 'Sales Order', 'Delivery Note', 'Sales Invoice']
+			},
+			{
+				'label': _('Buy'),
+				'items': ['Material Request', 'Supplier Quotation', 'Request for Quotation',
+					'Purchase Order', 'Purchase Invoice']
+			},
+			{
+				'label': _('Traceability'),
+				'items': ['Serial No', 'Batch']
+			},
+			{
+				'label': _('Move'),
+				'items': ['Stock Entry']
+			},
+			{
+				'label': _('Manufacture'),
+				'items': ['Production Order']
+			}
+		]
+	}
\ No newline at end of file
diff --git a/erpnext/stock/doctype/item/test_item.py b/erpnext/stock/doctype/item/test_item.py
index bd617c6..aceefc0 100644
--- a/erpnext/stock/doctype/item/test_item.py
+++ b/erpnext/stock/doctype/item/test_item.py
@@ -177,4 +177,10 @@
 		variant.item_name = "_Test Variant Item-S"
 		variant.save()
 
+def get_total_projected_qty(item):
+	total_qty = frappe.db.sql(""" select sum(projected_qty) as projected_qty from tabBin
+		where item_code = %(item)s""", {'item': item}, as_dict=1)
+
+	return total_qty[0].projected_qty if total_qty else 0.0
+
 test_records = frappe.get_test_records('Item')
diff --git a/erpnext/stock/doctype/material_request/material_request.py b/erpnext/stock/doctype/material_request/material_request.py
index 0be2bae..06df636 100644
--- a/erpnext/stock/doctype/material_request/material_request.py
+++ b/erpnext/stock/doctype/material_request/material_request.py
@@ -75,7 +75,7 @@
 		pc_obj = frappe.get_doc('Purchase Common')
 		pc_obj.validate_for_items(self)
 
-		self.set_title()
+		# self.set_title()
 
 
 		# self.validate_qty_against_so()
diff --git a/erpnext/stock/doctype/material_request/material_request_dashboard.py b/erpnext/stock/doctype/material_request/material_request_dashboard.py
index eab38b2..751c723 100644
--- a/erpnext/stock/doctype/material_request/material_request_dashboard.py
+++ b/erpnext/stock/doctype/material_request/material_request_dashboard.py
@@ -1,15 +1,17 @@
 from frappe import _
 
-data = {
-	'fieldname': 'material_request',
-	'transactions': [
-		{
-			'label': _('Related'),
-			'items': ['Request for Quotation', 'Supplier Quotation', 'Purchase Order']
-		},
-		{
-			'label': _('Manufacturing'),
-			'items': ['Production Order']
-		},
-	]
-}
\ No newline at end of file
+
+def get_data():
+	return {
+		'fieldname': 'material_request',
+		'transactions': [
+			{
+				'label': _('Related'),
+				'items': ['Request for Quotation', 'Supplier Quotation', 'Purchase Order']
+			},
+			{
+				'label': _('Manufacturing'),
+				'items': ['Production Order']
+			}
+		]
+	}
\ No newline at end of file
diff --git a/erpnext/stock/doctype/material_request/test_material_request.py b/erpnext/stock/doctype/material_request/test_material_request.py
index ebdfa5a..8f43acd 100644
--- a/erpnext/stock/doctype/material_request/test_material_request.py
+++ b/erpnext/stock/doctype/material_request/test_material_request.py
@@ -66,7 +66,6 @@
 				"posting_date": "2013-03-01",
 				"posting_time": "00:00:00",
 				"purpose": "Material Receipt",
-				"fiscal_year": "_Test Fiscal Year 2013",
 				"items": [
 					{
 						"conversion_factor": 1.0,
@@ -79,6 +78,7 @@
 						"transfer_qty": qty1,
 						"uom": "_Test UOM 1",
 						"t_warehouse": warehouse or "_Test Warehouse 1 - _TC",
+						"cost_center": "_Test Cost Center - _TC"
 					},
 					{
 						"conversion_factor": 1.0,
@@ -91,6 +91,7 @@
 						"transfer_qty": qty2,
 						"uom": "_Test UOM 1",
 						"t_warehouse": warehouse or "_Test Warehouse 1 - _TC",
+						"cost_center": "_Test Cost Center - _TC"
 					}
 				]
 			})
diff --git a/erpnext/stock/doctype/material_request_item/material_request_item.json b/erpnext/stock/doctype/material_request_item/material_request_item.json
index dd087c4..f7ca7d9 100644
--- a/erpnext/stock/doctype/material_request_item/material_request_item.json
+++ b/erpnext/stock/doctype/material_request_item/material_request_item.json
@@ -343,7 +343,7 @@
    "bold": 1, 
    "collapsible": 0, 
    "columns": 2, 
-   "default": "Today", 
+   "default": "", 
    "fieldname": "schedule_date", 
    "fieldtype": "Date", 
    "hidden": 0, 
@@ -705,7 +705,7 @@
  "issingle": 0, 
  "istable": 1, 
  "max_attachments": 0, 
- "modified": "2016-09-18 14:38:38.517137", 
+ "modified": "2016-10-17 04:58:33.317145", 
  "modified_by": "Administrator", 
  "module": "Stock", 
  "name": "Material Request Item", 
diff --git a/erpnext/stock/doctype/purchase_receipt/purchase_receipt.json b/erpnext/stock/doctype/purchase_receipt/purchase_receipt.json
index f10b634..0a6ec9f 100755
--- a/erpnext/stock/doctype/purchase_receipt/purchase_receipt.json
+++ b/erpnext/stock/doctype/purchase_receipt/purchase_receipt.json
@@ -9,11 +9,13 @@
  "docstatus": 0, 
  "doctype": "DocType", 
  "document_type": "Document", 
+ "editable_grid": 1, 
  "fields": [
   {
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "supplier_section", 
    "fieldtype": "Section Break", 
    "hidden": 0, 
@@ -39,6 +41,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "column_break0", 
    "fieldtype": "Column Break", 
    "hidden": 0, 
@@ -65,6 +68,7 @@
    "allow_on_submit": 1, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "default": "{supplier_name}", 
    "fieldname": "title", 
    "fieldtype": "Data", 
@@ -91,6 +95,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "default": "", 
    "fieldname": "naming_series", 
    "fieldtype": "Select", 
@@ -119,6 +124,7 @@
    "allow_on_submit": 0, 
    "bold": 1, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "supplier", 
    "fieldtype": "Link", 
    "hidden": 0, 
@@ -148,6 +154,7 @@
    "allow_on_submit": 0, 
    "bold": 1, 
    "collapsible": 0, 
+   "columns": 0, 
    "depends_on": "supplier", 
    "fieldname": "supplier_name", 
    "fieldtype": "Data", 
@@ -173,6 +180,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "column_break1", 
    "fieldtype": "Column Break", 
    "hidden": 0, 
@@ -199,6 +207,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "default": "Today", 
    "fieldname": "posting_date", 
    "fieldtype": "Date", 
@@ -228,6 +237,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "description": "Time at which materials were received", 
    "fieldname": "posting_time", 
    "fieldtype": "Time", 
@@ -257,6 +267,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "description": "", 
    "fieldname": "company", 
    "fieldtype": "Link", 
@@ -287,6 +298,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "is_return", 
    "fieldtype": "Check", 
    "hidden": 0, 
@@ -296,7 +308,7 @@
    "in_list_view": 0, 
    "label": "Is Return", 
    "length": 0, 
-   "no_copy": 0, 
+   "no_copy": 1, 
    "permlevel": 0, 
    "precision": "", 
    "print_hide": 1, 
@@ -312,6 +324,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "depends_on": "is_return", 
    "fieldname": "return_against", 
    "fieldtype": "Link", 
@@ -322,7 +335,7 @@
    "in_list_view": 0, 
    "label": "Return Against Purchase Receipt", 
    "length": 0, 
-   "no_copy": 0, 
+   "no_copy": 1, 
    "options": "Purchase Receipt", 
    "permlevel": 0, 
    "precision": "", 
@@ -339,6 +352,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 1, 
+   "columns": 0, 
    "fieldname": "section_addresses", 
    "fieldtype": "Section Break", 
    "hidden": 0, 
@@ -364,6 +378,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "supplier_address", 
    "fieldtype": "Link", 
    "hidden": 0, 
@@ -389,6 +404,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "contact_person", 
    "fieldtype": "Link", 
    "hidden": 0, 
@@ -414,6 +430,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "depends_on": "", 
    "fieldname": "address_display", 
    "fieldtype": "Small Text", 
@@ -439,6 +456,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "contact_display", 
    "fieldtype": "Small Text", 
    "hidden": 0, 
@@ -463,6 +481,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "contact_mobile", 
    "fieldtype": "Small Text", 
    "hidden": 0, 
@@ -487,6 +506,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "contact_email", 
    "fieldtype": "Small Text", 
    "hidden": 0, 
@@ -511,6 +531,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "col_break_address", 
    "fieldtype": "Column Break", 
    "hidden": 0, 
@@ -535,6 +556,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "depends_on": "", 
    "fieldname": "shipping_address", 
    "fieldtype": "Link", 
@@ -562,6 +584,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "shipping_address_display", 
    "fieldtype": "Small Text", 
    "hidden": 0, 
@@ -587,6 +610,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 1, 
+   "columns": 0, 
    "fieldname": "currency_and_price_list", 
    "fieldtype": "Section Break", 
    "hidden": 0, 
@@ -612,6 +636,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "currency", 
    "fieldtype": "Link", 
    "hidden": 0, 
@@ -639,6 +664,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "description": "Rate at which supplier's currency is converted to company's base currency", 
    "fieldname": "conversion_rate", 
    "fieldtype": "Float", 
@@ -667,6 +693,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "column_break2", 
    "fieldtype": "Column Break", 
    "hidden": 0, 
@@ -693,6 +720,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "buying_price_list", 
    "fieldtype": "Link", 
    "hidden": 0, 
@@ -718,6 +746,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "depends_on": "buying_price_list", 
    "fieldname": "price_list_currency", 
    "fieldtype": "Link", 
@@ -744,6 +773,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "depends_on": "buying_price_list", 
    "fieldname": "plc_conversion_rate", 
    "fieldtype": "Float", 
@@ -770,6 +800,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "ignore_pricing_rule", 
    "fieldtype": "Check", 
    "hidden": 0, 
@@ -794,6 +825,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "items_section", 
    "fieldtype": "Section Break", 
    "hidden": 0, 
@@ -820,6 +852,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "items", 
    "fieldtype": "Table", 
    "hidden": 0, 
@@ -847,6 +880,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "get_current_stock", 
    "fieldtype": "Button", 
    "hidden": 0, 
@@ -873,6 +907,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "section_break0", 
    "fieldtype": "Section Break", 
    "hidden": 0, 
@@ -897,6 +932,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "base_total", 
    "fieldtype": "Currency", 
    "hidden": 0, 
@@ -923,6 +959,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "base_net_total", 
    "fieldtype": "Currency", 
    "hidden": 0, 
@@ -952,6 +989,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "column_break_27", 
    "fieldtype": "Column Break", 
    "hidden": 0, 
@@ -975,6 +1013,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "total", 
    "fieldtype": "Currency", 
    "hidden": 0, 
@@ -1001,6 +1040,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "net_total", 
    "fieldtype": "Currency", 
    "hidden": 0, 
@@ -1028,6 +1068,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "description": "Add / Edit Taxes and Charges", 
    "fieldname": "taxes_section", 
    "fieldtype": "Section Break", 
@@ -1055,6 +1096,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "description": "", 
    "fieldname": "taxes_and_charges", 
    "fieldtype": "Link", 
@@ -1083,6 +1125,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "taxes", 
    "fieldtype": "Table", 
    "hidden": 0, 
@@ -1110,6 +1153,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "other_charges_calculation", 
    "fieldtype": "HTML", 
    "hidden": 0, 
@@ -1135,6 +1179,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "description": "", 
    "fieldname": "totals", 
    "fieldtype": "Section Break", 
@@ -1162,6 +1207,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "base_taxes_and_charges_added", 
    "fieldtype": "Currency", 
    "hidden": 0, 
@@ -1189,6 +1235,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "base_taxes_and_charges_deducted", 
    "fieldtype": "Currency", 
    "hidden": 0, 
@@ -1216,6 +1263,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "base_total_taxes_and_charges", 
    "fieldtype": "Currency", 
    "hidden": 0, 
@@ -1243,6 +1291,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "column_break3", 
    "fieldtype": "Column Break", 
    "hidden": 0, 
@@ -1268,6 +1317,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "taxes_and_charges_added", 
    "fieldtype": "Currency", 
    "hidden": 0, 
@@ -1295,6 +1345,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "taxes_and_charges_deducted", 
    "fieldtype": "Currency", 
    "hidden": 0, 
@@ -1322,6 +1373,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "total_taxes_and_charges", 
    "fieldtype": "Currency", 
    "hidden": 0, 
@@ -1349,6 +1401,7 @@
    "bold": 0, 
    "collapsible": 1, 
    "collapsible_depends_on": "discount_amount", 
+   "columns": 0, 
    "fieldname": "section_break_42", 
    "fieldtype": "Section Break", 
    "hidden": 0, 
@@ -1374,6 +1427,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "default": "Grand Total", 
    "fieldname": "apply_discount_on", 
    "fieldtype": "Select", 
@@ -1401,6 +1455,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "base_discount_amount", 
    "fieldtype": "Currency", 
    "hidden": 0, 
@@ -1427,6 +1482,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "column_break_44", 
    "fieldtype": "Column Break", 
    "hidden": 0, 
@@ -1451,6 +1507,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "additional_discount_percentage", 
    "fieldtype": "Float", 
    "hidden": 0, 
@@ -1476,6 +1533,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "discount_amount", 
    "fieldtype": "Currency", 
    "hidden": 0, 
@@ -1502,6 +1560,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "section_break_46", 
    "fieldtype": "Section Break", 
    "hidden": 0, 
@@ -1526,6 +1585,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "base_grand_total", 
    "fieldtype": "Currency", 
    "hidden": 0, 
@@ -1553,6 +1613,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "description": "", 
    "fieldname": "base_in_words", 
    "fieldtype": "Data", 
@@ -1580,6 +1641,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "base_rounded_total", 
    "fieldtype": "Currency", 
    "hidden": 0, 
@@ -1607,6 +1669,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "column_break_50", 
    "fieldtype": "Column Break", 
    "hidden": 0, 
@@ -1631,6 +1694,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "grand_total", 
    "fieldtype": "Currency", 
    "hidden": 0, 
@@ -1658,6 +1722,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "in_words", 
    "fieldtype": "Data", 
    "hidden": 0, 
@@ -1685,6 +1750,7 @@
    "bold": 0, 
    "collapsible": 1, 
    "collapsible_depends_on": "terms", 
+   "columns": 0, 
    "fieldname": "terms_section_break", 
    "fieldtype": "Section Break", 
    "hidden": 0, 
@@ -1711,6 +1777,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "tc_name", 
    "fieldtype": "Link", 
    "hidden": 0, 
@@ -1738,6 +1805,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "terms", 
    "fieldtype": "Text Editor", 
    "hidden": 0, 
@@ -1765,6 +1833,7 @@
    "bold": 0, 
    "collapsible": 1, 
    "collapsible_depends_on": "supplied_items", 
+   "columns": 0, 
    "description": "", 
    "fieldname": "raw_material_details", 
    "fieldtype": "Section Break", 
@@ -1792,6 +1861,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "default": "No", 
    "description": "", 
    "fieldname": "is_subcontracted", 
@@ -1821,6 +1891,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "description": "", 
    "fieldname": "supplier_warehouse", 
    "fieldtype": "Link", 
@@ -1851,6 +1922,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "supplied_items", 
    "fieldtype": "Table", 
    "hidden": 0, 
@@ -1878,6 +1950,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "bill_no", 
    "fieldtype": "Data", 
    "hidden": 1, 
@@ -1904,6 +1977,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "bill_date", 
    "fieldtype": "Date", 
    "hidden": 1, 
@@ -1930,6 +2004,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 1, 
+   "columns": 0, 
    "fieldname": "more_info", 
    "fieldtype": "Section Break", 
    "hidden": 0, 
@@ -1956,6 +2031,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "default": "Draft", 
    "fieldname": "status", 
    "fieldtype": "Select", 
@@ -1986,6 +2062,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "description": "Warehouse where you are maintaining stock of rejected items", 
    "fieldname": "rejected_warehouse", 
    "fieldtype": "Link", 
@@ -2014,6 +2091,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "amended_from", 
    "fieldtype": "Link", 
    "hidden": 1, 
@@ -2043,6 +2121,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "range", 
    "fieldtype": "Data", 
    "hidden": 1, 
@@ -2069,6 +2148,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "column_break4", 
    "fieldtype": "Column Break", 
    "hidden": 0, 
@@ -2095,6 +2175,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "per_billed", 
    "fieldtype": "Percent", 
    "hidden": 0, 
@@ -2120,6 +2201,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 1, 
+   "columns": 0, 
    "fieldname": "printing_settings", 
    "fieldtype": "Section Break", 
    "hidden": 0, 
@@ -2145,6 +2227,7 @@
    "allow_on_submit": 1, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "letter_head", 
    "fieldtype": "Link", 
    "hidden": 0, 
@@ -2170,6 +2253,7 @@
    "allow_on_submit": 1, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "select_print_heading", 
    "fieldtype": "Link", 
    "hidden": 0, 
@@ -2197,6 +2281,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "language", 
    "fieldtype": "Data", 
    "hidden": 0, 
@@ -2222,6 +2307,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "other_details", 
    "fieldtype": "HTML", 
    "hidden": 1, 
@@ -2250,6 +2336,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "instructions", 
    "fieldtype": "Small Text", 
    "hidden": 0, 
@@ -2276,6 +2363,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "remarks", 
    "fieldtype": "Small Text", 
    "hidden": 0, 
@@ -2301,6 +2389,7 @@
    "bold": 0, 
    "collapsible": 1, 
    "collapsible_depends_on": "transporter_name", 
+   "columns": 0, 
    "fieldname": "transporter_info", 
    "fieldtype": "Section Break", 
    "hidden": 0, 
@@ -2326,6 +2415,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "transporter_name", 
    "fieldtype": "Data", 
    "hidden": 0, 
@@ -2352,6 +2442,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "column_break5", 
    "fieldtype": "Column Break", 
    "hidden": 0, 
@@ -2377,6 +2468,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "description": "", 
    "fieldname": "lr_no", 
    "fieldtype": "Data", 
@@ -2406,6 +2498,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "description": "", 
    "fieldname": "lr_date", 
    "fieldtype": "Date", 
@@ -2444,7 +2537,7 @@
  "istable": 0, 
  "max_attachments": 0, 
  "menu_index": 0, 
- "modified": "2016-06-30 13:42:23.310309", 
+ "modified": "2016-09-23 18:02:17.332333", 
  "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 20630b2..6d6ae97 100644
--- a/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py
+++ b/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py
@@ -4,9 +4,9 @@
 from __future__ import unicode_literals
 import frappe
 
-from frappe.utils import flt, cint
+from frappe.utils import flt, cint, nowdate
 
-from frappe import _
+from frappe import throw, _
 import frappe.defaults
 
 from erpnext.controllers.buying_controller import BuyingController
@@ -58,6 +58,10 @@
 
 		pc_obj = frappe.get_doc('Purchase Common')
 		self.check_for_closed_status(pc_obj)
+		
+		if self.posting_date > nowdate():
+			throw(_("Posting Date cannot be future date"))
+		
 
 	def validate_with_previous_doc(self):
 		super(PurchaseReceipt, self).validate_with_previous_doc({
diff --git a/erpnext/stock/doctype/purchase_receipt/purchase_receipt_dashboard.py b/erpnext/stock/doctype/purchase_receipt/purchase_receipt_dashboard.py
index 3278032..7059c91 100644
--- a/erpnext/stock/doctype/purchase_receipt/purchase_receipt_dashboard.py
+++ b/erpnext/stock/doctype/purchase_receipt/purchase_receipt_dashboard.py
@@ -1,28 +1,29 @@
 from frappe import _
 
-data = {
-	'fieldname': 'purchase_receipt_no',
-	'non_standard_fieldnames': {
-		'Purchase Invoice': 'purchase_receipt',
-		'Landed Cost Voucher': 'receipt_document'
-	},
-	'internal_links': {
-		'Purchase Order': ['items', 'purchase_order'],
-		'Project': ['items', 'project'],
-		'Quality Inspection': ['items', 'qa_no'],
-	},
-	'transactions': [
-		{
-			'label': _('Related'),
-			'items': ['Purchase Invoice', 'Landed Cost Voucher']
+def get_data():
+	return {
+		'fieldname': 'purchase_receipt_no',
+		'non_standard_fieldnames': {
+			'Purchase Invoice': 'purchase_receipt',
+			'Landed Cost Voucher': 'receipt_document'
 		},
-		{
-			'label': _('Reference'),
-			'items': ['Purchase Order', 'Quality Inspection', 'Project']
+		'internal_links': {
+			'Purchase Order': ['items', 'purchase_order'],
+			'Project': ['items', 'project'],
+			'Quality Inspection': ['items', 'qa_no'],
 		},
-		{
-			'label': _('Returns'),
-			'items': ['Stock Entry']
-		},
-	]
-}
\ No newline at end of file
+		'transactions': [
+			{
+				'label': _('Related'),
+				'items': ['Purchase Invoice', 'Landed Cost Voucher']
+			},
+			{
+				'label': _('Reference'),
+				'items': ['Purchase Order', 'Quality Inspection', 'Project']
+			},
+			{
+				'label': _('Returns'),
+				'items': ['Stock Entry']
+			},
+		]
+	}
\ No newline at end of file
diff --git a/erpnext/stock/doctype/stock_entry/stock_entry.js b/erpnext/stock/doctype/stock_entry/stock_entry.js
index 7c9e1e6..85166a6 100644
--- a/erpnext/stock/doctype/stock_entry/stock_entry.js
+++ b/erpnext/stock/doctype/stock_entry/stock_entry.js
@@ -348,6 +348,7 @@
 }
 
 cur_frm.cscript.purpose = function(doc, cdt, cdn) {
+	cur_frm.fields_dict.items.grid.refresh();
 	cur_frm.cscript.toggle_related_fields(doc);
 }
 
diff --git a/erpnext/stock/doctype/stock_entry/stock_entry.json b/erpnext/stock/doctype/stock_entry/stock_entry.json
index 0ab80c2..8e31332 100644
--- a/erpnext/stock/doctype/stock_entry/stock_entry.json
+++ b/erpnext/stock/doctype/stock_entry/stock_entry.json
@@ -3,16 +3,20 @@
  "allow_import": 1, 
  "allow_rename": 0, 
  "autoname": "naming_series:", 
+ "beta": 0, 
  "creation": "2013-04-09 11:43:55", 
  "custom": 0, 
  "docstatus": 0, 
  "doctype": "DocType", 
  "document_type": "Document", 
+ "editable_grid": 0, 
+ "engine": "InnoDB", 
  "fields": [
   {
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "items_section", 
    "fieldtype": "Section Break", 
    "hidden": 0, 
@@ -38,6 +42,7 @@
    "allow_on_submit": 1, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "default": "{purpose}", 
    "fieldname": "title", 
    "fieldtype": "Data", 
@@ -64,6 +69,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "naming_series", 
    "fieldtype": "Select", 
    "hidden": 0, 
@@ -91,6 +97,7 @@
    "allow_on_submit": 0, 
    "bold": 1, 
    "collapsible": 0, 
+   "columns": 0, 
    "default": "Material Issue", 
    "fieldname": "purpose", 
    "fieldtype": "Select", 
@@ -119,6 +126,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "company", 
    "fieldtype": "Link", 
    "hidden": 0, 
@@ -146,6 +154,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "depends_on": "eval:in_list([\"Material Transfer for Manufacture\", \"Manufacture\"], doc.purpose)", 
    "fieldname": "production_order", 
    "fieldtype": "Link", 
@@ -174,6 +183,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "depends_on": "eval:doc.purpose==\"Subcontract\"", 
    "fieldname": "purchase_order", 
    "fieldtype": "Link", 
@@ -201,6 +211,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "depends_on": "eval:doc.purpose==\"Sales Return\"", 
    "fieldname": "delivery_note_no", 
    "fieldtype": "Link", 
@@ -229,6 +240,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "depends_on": "eval:doc.purpose==\"Sales Return\"", 
    "fieldname": "sales_invoice_no", 
    "fieldtype": "Link", 
@@ -255,6 +267,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "depends_on": "eval:doc.purpose==\"Purchase Return\"", 
    "fieldname": "purchase_receipt_no", 
    "fieldtype": "Link", 
@@ -283,6 +296,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "depends_on": "eval:in_list([\"Material Issue\", \"Material Transfer\", \"Manufacture\", \"Repack\", \t\t\t\t\t\"Subcontract\", \"Material Transfer for Manufacture\"], doc.purpose)", 
    "fieldname": "from_bom", 
    "fieldtype": "Check", 
@@ -309,6 +323,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "col2", 
    "fieldtype": "Column Break", 
    "hidden": 0, 
@@ -335,6 +350,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "default": "Today", 
    "fieldname": "posting_date", 
    "fieldtype": "Date", 
@@ -362,6 +378,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "posting_time", 
    "fieldtype": "Time", 
    "hidden": 0, 
@@ -388,6 +405,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "depends_on": "eval: doc.from_bom && (doc.purpose!==\"Sales Return\" && doc.purpose!==\"Purchase Return\")", 
    "fieldname": "sb1", 
    "fieldtype": "Section Break", 
@@ -413,6 +431,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "depends_on": "from_bom", 
    "fieldname": "bom_no", 
    "fieldtype": "Link", 
@@ -439,6 +458,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "depends_on": "from_bom", 
    "description": "As per Stock UOM", 
    "fieldname": "fg_completed_qty", 
@@ -467,6 +487,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "cb1", 
    "fieldtype": "Column Break", 
    "hidden": 0, 
@@ -490,6 +511,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "default": "1", 
    "depends_on": "from_bom", 
    "description": "Including items for sub assemblies", 
@@ -517,6 +539,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "depends_on": "from_bom", 
    "fieldname": "get_items", 
    "fieldtype": "Button", 
@@ -543,6 +566,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "section_break_12", 
    "fieldtype": "Section Break", 
    "hidden": 0, 
@@ -567,6 +591,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "from_warehouse", 
    "fieldtype": "Link", 
    "hidden": 0, 
@@ -594,6 +619,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "cb0", 
    "fieldtype": "Column Break", 
    "hidden": 0, 
@@ -617,6 +643,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "to_warehouse", 
    "fieldtype": "Link", 
    "hidden": 0, 
@@ -644,6 +671,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "sb0", 
    "fieldtype": "Section Break", 
    "hidden": 0, 
@@ -668,6 +696,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "items", 
    "fieldtype": "Table", 
    "hidden": 0, 
@@ -695,6 +724,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "description": "", 
    "fieldname": "get_stock_and_rate", 
    "fieldtype": "Button", 
@@ -722,6 +752,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "section_break_19", 
    "fieldtype": "Section Break", 
    "hidden": 0, 
@@ -746,6 +777,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "total_incoming_value", 
    "fieldtype": "Currency", 
    "hidden": 0, 
@@ -772,6 +804,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "column_break_22", 
    "fieldtype": "Column Break", 
    "hidden": 0, 
@@ -796,6 +829,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "total_outgoing_value", 
    "fieldtype": "Currency", 
    "hidden": 0, 
@@ -822,6 +856,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "value_difference", 
    "fieldtype": "Currency", 
    "hidden": 0, 
@@ -849,6 +884,7 @@
    "bold": 0, 
    "collapsible": 1, 
    "collapsible_depends_on": "total_additional_costs", 
+   "columns": 0, 
    "fieldname": "additional_costs_section", 
    "fieldtype": "Section Break", 
    "hidden": 0, 
@@ -874,6 +910,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "additional_costs", 
    "fieldtype": "Table", 
    "hidden": 0, 
@@ -900,6 +937,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "total_additional_costs", 
    "fieldtype": "Currency", 
    "hidden": 0, 
@@ -926,6 +964,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 1, 
+   "columns": 0, 
    "depends_on": "eval: in_list([\"Sales Return\", \"Purchase Return\", \"Subcontract\"], doc.purpose)", 
    "fieldname": "contact_section", 
    "fieldtype": "Section Break", 
@@ -951,6 +990,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "depends_on": "eval:doc.purpose==\"Purchase Return\" || doc.purpose==\"Subcontract\"", 
    "fieldname": "supplier", 
    "fieldtype": "Link", 
@@ -979,6 +1019,7 @@
    "allow_on_submit": 0, 
    "bold": 1, 
    "collapsible": 0, 
+   "columns": 0, 
    "depends_on": "eval:doc.purpose==\"Purchase Return\" || doc.purpose==\"Subcontract\"", 
    "fieldname": "supplier_name", 
    "fieldtype": "Data", 
@@ -1006,6 +1047,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "depends_on": "eval:doc.purpose==\"Purchase Return\" || doc.purpose==\"Subcontract\"", 
    "fieldname": "supplier_address", 
    "fieldtype": "Small Text", 
@@ -1033,6 +1075,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "column_break_39", 
    "fieldtype": "Column Break", 
    "hidden": 0, 
@@ -1057,6 +1100,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "depends_on": "eval:doc.purpose==\"Sales Return\"", 
    "fieldname": "customer", 
    "fieldtype": "Link", 
@@ -1085,6 +1129,7 @@
    "allow_on_submit": 0, 
    "bold": 1, 
    "collapsible": 0, 
+   "columns": 0, 
    "depends_on": "eval:doc.purpose==\"Sales Return\"", 
    "fieldname": "customer_name", 
    "fieldtype": "Data", 
@@ -1112,6 +1157,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "depends_on": "eval:doc.purpose==\"Sales Return\"", 
    "fieldname": "customer_address", 
    "fieldtype": "Small Text", 
@@ -1139,6 +1185,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 1, 
+   "columns": 0, 
    "fieldname": "printing_settings", 
    "fieldtype": "Section Break", 
    "hidden": 0, 
@@ -1164,6 +1211,7 @@
    "allow_on_submit": 1, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "select_print_heading", 
    "fieldtype": "Link", 
    "hidden": 0, 
@@ -1191,6 +1239,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "letter_head", 
    "fieldtype": "Link", 
    "hidden": 0, 
@@ -1217,6 +1266,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 1, 
+   "columns": 0, 
    "fieldname": "more_info", 
    "fieldtype": "Section Break", 
    "hidden": 0, 
@@ -1242,6 +1292,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "project", 
    "fieldtype": "Link", 
    "hidden": 0, 
@@ -1268,6 +1319,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "remarks", 
    "fieldtype": "Text", 
    "hidden": 0, 
@@ -1294,6 +1346,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "col5", 
    "fieldtype": "Column Break", 
    "hidden": 0, 
@@ -1319,6 +1372,8 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
+   "depends_on": "total_amount", 
    "fieldname": "total_amount", 
    "fieldtype": "Currency", 
    "hidden": 0, 
@@ -1332,7 +1387,7 @@
    "options": "Company:company:default_currency", 
    "permlevel": 0, 
    "print_hide": 0, 
-   "print_hide_if_no_value": 0, 
+   "print_hide_if_no_value": 1, 
    "read_only": 1, 
    "report_hide": 0, 
    "reqd": 0, 
@@ -1344,6 +1399,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "amended_from", 
    "fieldtype": "Link", 
    "hidden": 0, 
@@ -1371,6 +1427,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "credit_note", 
    "fieldtype": "Link", 
    "hidden": 1, 
@@ -1398,13 +1455,14 @@
  "hide_toolbar": 0, 
  "icon": "icon-file-text", 
  "idx": 1, 
+ "image_view": 0, 
  "in_create": 0, 
  "in_dialog": 0, 
  "is_submittable": 1, 
  "issingle": 0, 
  "istable": 0, 
  "max_attachments": 0, 
- "modified": "2016-09-08 06:40:03.284036", 
+ "modified": "2016-10-19 16:11:22.110926", 
  "modified_by": "Administrator", 
  "module": "Stock", 
  "name": "Stock Entry", 
@@ -1420,6 +1478,7 @@
    "export": 0, 
    "if_owner": 0, 
    "import": 0, 
+   "is_custom": 0, 
    "permlevel": 0, 
    "print": 1, 
    "read": 1, 
@@ -1440,6 +1499,7 @@
    "export": 0, 
    "if_owner": 0, 
    "import": 0, 
+   "is_custom": 0, 
    "permlevel": 0, 
    "print": 1, 
    "read": 1, 
@@ -1460,6 +1520,7 @@
    "export": 0, 
    "if_owner": 0, 
    "import": 0, 
+   "is_custom": 0, 
    "permlevel": 0, 
    "print": 1, 
    "read": 1, 
@@ -1480,6 +1541,7 @@
    "export": 0, 
    "if_owner": 0, 
    "import": 0, 
+   "is_custom": 0, 
    "permlevel": 0, 
    "print": 1, 
    "read": 1, 
@@ -1491,6 +1553,7 @@
    "write": 1
   }
  ], 
+ "quick_entry": 0, 
  "read_only": 0, 
  "read_only_onload": 0, 
  "search_fields": "posting_date, from_warehouse, to_warehouse, purpose, remarks", 
diff --git a/erpnext/stock/doctype/stock_entry/stock_entry.py b/erpnext/stock/doctype/stock_entry/stock_entry.py
index 44782d5..ec3873e 100644
--- a/erpnext/stock/doctype/stock_entry/stock_entry.py
+++ b/erpnext/stock/doctype/stock_entry/stock_entry.py
@@ -319,7 +319,9 @@
 		self.value_difference = self.total_incoming_value - self.total_outgoing_value
 
 	def set_total_amount(self):
-		self.total_amount = sum([flt(item.amount) for item in self.get("items")])
+		self.total_amount = None
+		if self.purpose not in ['Manufacture', 'Repack']:
+			self.total_amount = sum([flt(item.amount) for item in self.get("items")])
 
 	def validate_purchase_order(self):
 		"""Throw exception if more raw material is transferred against Purchase Order than in
diff --git a/erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.js b/erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.js
index c70613b..2b031d1 100644
--- a/erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.js
+++ b/erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.js
@@ -75,6 +75,9 @@
 					frappe.model.set_value(cdt, cdn, "valuation_rate", r.message.rate);
 					frappe.model.set_value(cdt, cdn, "current_qty", r.message.qty);
 					frappe.model.set_value(cdt, cdn, "current_valuation_rate", r.message.rate);
+					frappe.model.set_value(cdt, cdn, "current_amount", r.message.rate * r.message.qty);
+					frappe.model.set_value(cdt, cdn, "amount", r.message.rate * r.message.qty);
+					
 				}
 			});
 		}
@@ -92,7 +95,15 @@
 				}
 			});
 		}
-	}	
+	},
+	set_amount_quantity: function(doc, cdt, cdn) {
+		var d = frappe.model.get_doc(cdt, cdn);
+		if (d.qty & d.valuation_rate) {
+			frappe.model.set_value(cdt, cdn, "amount", flt(d.qty) * flt(d.valuation_rate));
+			frappe.model.set_value(cdt, cdn, "quantity_difference", flt(d.qty) - flt(d.current_qty));
+			frappe.model.set_value(cdt, cdn, "amount_difference", flt(d.amount) - flt(d.current_amount));
+		}
+	}
 });
 
 frappe.ui.form.on("Stock Reconciliation Item", {
@@ -104,7 +115,14 @@
 	},
 	item_code: function(frm, cdt, cdn) {
 		frm.events.set_valuation_rate_and_qty(frm, cdt, cdn);
+	},
+	qty: function(frm, cdt, cdn) {
+		frm.events.set_amount_quantity(frm, cdt, cdn);
+	},
+	valuation_rate: function(frm, cdt, cdn) {
+		frm.events.set_amount_quantity(frm, cdt, cdn);
 	}
+	
 });
 
 erpnext.stock.StockReconciliation = erpnext.stock.StockController.extend({
diff --git a/erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.json b/erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.json
index 291f14d..0c1c10c 100644
--- a/erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.json
+++ b/erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.json
@@ -389,7 +389,7 @@
  "istable": 0, 
  "max_attachments": 1, 
  "menu_index": 0, 
- "modified": "2016-09-02 04:09:18.909485", 
+ "modified": "2016-10-05 13:03:39.887647", 
  "modified_by": "Administrator", 
  "module": "Stock", 
  "name": "Stock Reconciliation", 
@@ -405,6 +405,7 @@
    "export": 0, 
    "if_owner": 0, 
    "import": 0, 
+   "is_custom": 0, 
    "permlevel": 0, 
    "print": 0, 
    "read": 1, 
diff --git a/erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.py b/erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.py
index 0f5cb96..4ab49e5 100644
--- a/erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.py
+++ b/erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.py
@@ -27,6 +27,7 @@
 		self.remove_items_with_no_change()
 		self.validate_data()
 		self.validate_expense_account()
+		self.set_total_qty_and_amount()
 
 	def on_submit(self):
 		self.update_stock_ledger()
@@ -236,6 +237,13 @@
 		elif not frappe.db.sql("""select name from `tabStock Ledger Entry` limit 1"""):
 			if frappe.db.get_value("Account", self.expense_account, "report_type") == "Profit and Loss":
 				frappe.throw(_("Difference Account must be a Asset/Liability type account, since this Stock Reconciliation is an Opening Entry"), OpeningEntryAccountError)
+				
+	def set_total_qty_and_amount(self):
+		for d in self.get("items"):
+			d.amount = flt(d.qty) * flt(d.valuation_rate)
+			d.current_amount = flt(d.current_qty) * flt(d.current_valuation_rate)
+			d.quantity_difference = flt(d.qty) - flt(d.current_qty)
+			d.amount_difference = flt(d.amount) - flt(d.current_amount)
 
 	def get_items_for(self, warehouse):
 		self.items = []
diff --git a/erpnext/stock/doctype/stock_reconciliation_item/stock_reconciliation_item.json b/erpnext/stock/doctype/stock_reconciliation_item/stock_reconciliation_item.json
index efd0dee..5452aa1 100644
--- a/erpnext/stock/doctype/stock_reconciliation_item/stock_reconciliation_item.json
+++ b/erpnext/stock/doctype/stock_reconciliation_item/stock_reconciliation_item.json
@@ -173,7 +173,7 @@
    "bold": 0, 
    "collapsible": 0, 
    "columns": 2, 
-   "description": "Do not include symbols (ex. $)", 
+   "description": "", 
    "fieldname": "valuation_rate", 
    "fieldtype": "Currency", 
    "hidden": 0, 
@@ -200,6 +200,32 @@
    "bold": 0, 
    "collapsible": 0, 
    "columns": 0, 
+   "fieldname": "amount", 
+   "fieldtype": "Currency", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 0, 
+   "in_list_view": 0, 
+   "label": "Amount", 
+   "length": 0, 
+   "no_copy": 0, 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 0, 
+   "print_hide_if_no_value": 0, 
+   "read_only": 1, 
+   "report_hide": 0, 
+   "reqd": 0, 
+   "search_index": 0, 
+   "set_only_once": 0, 
+   "unique": 0
+  }, 
+  {
+   "allow_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "section_break_3", 
    "fieldtype": "Section Break", 
    "hidden": 0, 
@@ -207,6 +233,7 @@
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 0, 
+   "label": "Before reconciliation", 
    "length": 0, 
    "no_copy": 0, 
    "permlevel": 0, 
@@ -225,7 +252,7 @@
    "bold": 0, 
    "collapsible": 0, 
    "columns": 0, 
-   "description": "Before reconciliation", 
+   "description": "", 
    "fieldname": "current_qty", 
    "fieldtype": "Float", 
    "hidden": 0, 
@@ -277,9 +304,9 @@
    "bold": 0, 
    "collapsible": 0, 
    "columns": 0, 
-   "description": "Before reconciliation", 
+   "description": "", 
    "fieldname": "current_valuation_rate", 
-   "fieldtype": "Read Only", 
+   "fieldtype": "Currency", 
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
@@ -298,6 +325,135 @@
    "search_index": 0, 
    "set_only_once": 0, 
    "unique": 0
+  }, 
+  {
+   "allow_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
+   "description": "", 
+   "fieldname": "current_amount", 
+   "fieldtype": "Currency", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 0, 
+   "in_list_view": 0, 
+   "label": "Current Amount", 
+   "length": 0, 
+   "no_copy": 0, 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 0, 
+   "print_hide_if_no_value": 0, 
+   "read_only": 1, 
+   "report_hide": 0, 
+   "reqd": 0, 
+   "search_index": 0, 
+   "set_only_once": 0, 
+   "unique": 0
+  }, 
+  {
+   "allow_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
+   "fieldname": "section_break_14", 
+   "fieldtype": "Section Break", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 0, 
+   "in_list_view": 0, 
+   "length": 0, 
+   "no_copy": 0, 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 0, 
+   "print_hide_if_no_value": 0, 
+   "read_only": 0, 
+   "report_hide": 0, 
+   "reqd": 0, 
+   "search_index": 0, 
+   "set_only_once": 0, 
+   "unique": 0
+  }, 
+  {
+   "allow_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
+   "fieldname": "quantity_difference", 
+   "fieldtype": "Read Only", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 0, 
+   "in_list_view": 0, 
+   "label": "Quantity Difference", 
+   "length": 0, 
+   "no_copy": 0, 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 0, 
+   "print_hide_if_no_value": 0, 
+   "read_only": 0, 
+   "report_hide": 0, 
+   "reqd": 0, 
+   "search_index": 0, 
+   "set_only_once": 0, 
+   "unique": 0
+  }, 
+  {
+   "allow_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
+   "fieldname": "column_break_16", 
+   "fieldtype": "Column Break", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 0, 
+   "in_list_view": 0, 
+   "length": 0, 
+   "no_copy": 0, 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 0, 
+   "print_hide_if_no_value": 0, 
+   "read_only": 0, 
+   "report_hide": 0, 
+   "reqd": 0, 
+   "search_index": 0, 
+   "set_only_once": 0, 
+   "unique": 0
+  }, 
+  {
+   "allow_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
+   "fieldname": "amount_difference", 
+   "fieldtype": "Currency", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 0, 
+   "in_list_view": 0, 
+   "label": "Amount Difference", 
+   "length": 0, 
+   "no_copy": 0, 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 0, 
+   "print_hide_if_no_value": 0, 
+   "read_only": 1, 
+   "report_hide": 0, 
+   "reqd": 0, 
+   "search_index": 0, 
+   "set_only_once": 0, 
+   "unique": 0
   }
  ], 
  "hide_heading": 0, 
@@ -311,7 +467,7 @@
  "istable": 1, 
  "max_attachments": 0, 
  "menu_index": 0, 
- "modified": "2016-09-05 07:10:19.571562", 
+ "modified": "2016-09-28 06:43:53.764287", 
  "modified_by": "Administrator", 
  "module": "Stock", 
  "name": "Stock Reconciliation Item", 
diff --git a/erpnext/stock/doctype/warehouse/warehouse.py b/erpnext/stock/doctype/warehouse/warehouse.py
index f657ebf..8e7941c 100644
--- a/erpnext/stock/doctype/warehouse/warehouse.py
+++ b/erpnext/stock/doctype/warehouse/warehouse.py
@@ -150,7 +150,10 @@
 		return new_warehouse
 
 	def rename_account_for(self, olddn, newdn, merge):
-		old_account = self.get_account(olddn)
+		if self.is_group:
+			old_account = self.get_account()
+		else:
+			old_account = self.get_account(olddn)
 
 		if old_account:
 			new_account = None
diff --git a/erpnext/stock/get_item_details.py b/erpnext/stock/get_item_details.py
index 1e3bd8a..e5dd735 100644
--- a/erpnext/stock/get_item_details.py
+++ b/erpnext/stock/get_item_details.py
@@ -328,10 +328,11 @@
 
 @frappe.whitelist()
 def get_pos_profile(company):
+	condition = "and company = '%s'"%(company) if company else ''
 	pos_profile = frappe.db.sql("""select * from `tabPOS Profile` where user = %s
-		and company = %s""", (frappe.session['user'], company), as_dict=1)
+		{cond}""".format(cond=condition), (frappe.session['user']), as_dict=1)
 
-	if not pos_profile:
+	if not pos_profile and company:
 		pos_profile = frappe.db.sql("""select * from `tabPOS Profile`
 			where ifnull(user,'') = '' and company = %s""", company, as_dict=1)
 
diff --git a/erpnext/stock/stock_balance.py b/erpnext/stock/stock_balance.py
index 22fa12a..096f6c0 100644
--- a/erpnext/stock/stock_balance.py
+++ b/erpnext/stock/stock_balance.py
@@ -230,7 +230,7 @@
 				pass
 
 def repost_all_stock_vouchers():
-	warehouses_with_account = frappe.db.sql_list("""select master_name from tabAccount
+	warehouses_with_account = frappe.db.sql_list("""select warehouse from tabAccount
 		where ifnull(account_type, '') = 'Stock' and (warehouse is not null and warehouse != '')
 		and is_group=0""")
 
@@ -244,7 +244,7 @@
 	i = 0
 	for voucher_type, voucher_no in vouchers:
 		i+=1
-		print i, "/", len(vouchers)
+		print i, "/", len(vouchers), voucher_type, voucher_no
 		try:
 			for dt in ["Stock Ledger Entry", "GL Entry"]:
 				frappe.db.sql("""delete from `tab%s` where voucher_type=%s and voucher_no=%s"""%
diff --git a/erpnext/support/doctype/warranty_claim/warranty_claim.js b/erpnext/support/doctype/warranty_claim/warranty_claim.js
index cf9d806..9fed265 100644
--- a/erpnext/support/doctype/warranty_claim/warranty_claim.js
+++ b/erpnext/support/doctype/warranty_claim/warranty_claim.js
@@ -37,7 +37,7 @@
 
 cur_frm.cscript.onload = function(doc,cdt,cdn){
 	if(!doc.status)
-		set_multiple(dt,dn,{status:'Open'});
+		set_multiple(cdt,cdn,{status:'Open'});
 }
 
 cur_frm.fields_dict['customer_address'].get_query = function(doc, cdt, cdn) {
diff --git a/erpnext/support/doctype/warranty_claim/warranty_claim.py b/erpnext/support/doctype/warranty_claim/warranty_claim.py
index b4427be..a3428a2 100644
--- a/erpnext/support/doctype/warranty_claim/warranty_claim.py
+++ b/erpnext/support/doctype/warranty_claim/warranty_claim.py
@@ -19,7 +19,7 @@
 		if session['user'] != 'Guest' and not self.customer:
 			frappe.throw(_("Customer is required"))
 
-		if self.status=="Closed" and \
+		if self.status=="Closed" and not self.resolution_date and \
 			frappe.db.get_value("Warranty Claim", self.name, "status")!="Closed":
 			self.resolution_date = now_datetime()
 
diff --git a/erpnext/templates/emails/request_for_quotation.html b/erpnext/templates/emails/request_for_quotation.html
index aedd8e2..b4dfb88 100644
--- a/erpnext/templates/emails/request_for_quotation.html
+++ b/erpnext/templates/emails/request_for_quotation.html
@@ -4,8 +4,8 @@
 <p>{{_("Please click on the following link to set your new password")}}:</p>
 <p><a href="{{ update_password_link }}">{{ update_password_link }}</a></p>
 {% else %}
-<p>{{_("Request for quotation can be access by clicking following link")}}:</p>
+<p>{{_("The request for quotation can be accessed by clicking on the following link")}}:</p>
 <p><a href="{{ rfq_link }}">Submit your Quotation</a></p>
 {% endif %}
 <p>{{_("Thank you")}},<br>
-{{ user_fullname }}</p>
\ No newline at end of file
+{{ user_fullname }}</p>
diff --git a/erpnext/templates/generators/student_admission.html b/erpnext/templates/generators/student_admission.html
index 7eb9226..ae70df8 100644
--- a/erpnext/templates/generators/student_admission.html
+++ b/erpnext/templates/generators/student_admission.html
@@ -16,38 +16,10 @@
 <div>{{ introduction }}</div>
 {% endif %}
 
-{%- if eligibility -%}
-<h3> Eligibility </h3>
-<div>{{ eligibility }}</div>
-{% endif %}
-
-<table class="table table-bordered" style="margin-top: 20px; width: 30%">
-	<tr>
-		<th> Program</th>
-		<td>{{ program }} </td>
-	</tr>
-	<tr>
-		<th> Academic Year</th>
-		<td>{{ academic_year }} </td>
-	</tr>
-	<tr>
-		<th> Admission Start Date</th>
-		<td>{{ frappe.utils.formatdate(admission_start_date) }}</td>
-	</tr>
-	<tr>
-		<th> Admission End Date</th>
-		<td>{{ frappe.utils.formatdate(admission_end_date) }}</td>
-	</tr>
-	<tr>
-		<th> Application Fee</th>
-		<td>{{ frappe.utils.fmt_money(application_fee, 2, currency) }}</td>
-	</tr>
-</table>
-
 {%- if application_form_route -%}
 <p>
 	<a class='btn btn-primary'
-	href='/{{ doc.application_form_route }}?program={{ doc.program }}&academic_year={{ doc.academic_year }}&new=1'>
+	href='/{{ doc.application_form_route }}'>
 	{{ _("Apply Now") }}</a>
 </p>
 {% endif %}
diff --git a/erpnext/templates/includes/navbar/navbar_items.html b/erpnext/templates/includes/navbar/navbar_items.html
index c7af2fd..f0c780d 100644
--- a/erpnext/templates/includes/navbar/navbar_items.html
+++ b/erpnext/templates/includes/navbar/navbar_items.html
@@ -1,7 +1,7 @@
 {% extends 'frappe/templates/includes/navbar/navbar_items.html' %}
 
 {% block navbar_right_extension %}
-	<li class="shopping-cart">
+	<li class="shopping-cart hidden">
 		<div class="cart-icon small">
 			<a class="dropdown-toggle" href="#" data-toggle="dropdown" id="navLogin">
 				Cart <span class="badge-wrapper" id="cart-count"></span>
diff --git a/erpnext/templates/includes/rfq.js b/erpnext/templates/includes/rfq.js
index 42dcc3a..46357d4 100644
--- a/erpnext/templates/includes/rfq.js
+++ b/erpnext/templates/includes/rfq.js
@@ -18,6 +18,7 @@
 		this.change_rate();
 		this.terms();
 		this.submit_rfq();
+		this.navigate_quotations();
 	},
 
 	onfocus_select_all: function(){
@@ -89,5 +90,12 @@
 				}
 			})
 		})
+	},
+
+	navigate_quotations: function() {
+		$('.quotations').click(function(){
+			name = $(this).attr('idx')
+			window.location.href = "/quotations/" + encodeURIComponent(name);
+		})
 	}
 })
diff --git a/erpnext/templates/pages/order.py b/erpnext/templates/pages/order.py
index 1a40280..296b907 100644
--- a/erpnext/templates/pages/order.py
+++ b/erpnext/templates/pages/order.py
@@ -14,10 +14,10 @@
 		context.doc.set_indicator()
 
 	context.parents = frappe.form_dict.parents
-	context.payment_ref = frappe.db.get_value("Payment Request", 
+	context.payment_ref = frappe.db.get_value("Payment Request",
 		{"reference_name": frappe.form_dict.name}, "name")
 
 	context.enabled_checkout = frappe.get_doc("Shopping Cart Settings").enable_checkout
 
-	if not context.doc.has_website_permission("read"):
+	if not frappe.has_website_permission(context.doc):
 		frappe.throw(_("Not Permitted"), frappe.PermissionError)
diff --git a/erpnext/templates/pages/rfq.html b/erpnext/templates/pages/rfq.html
index a2b6a66..591d046 100644
--- a/erpnext/templates/pages/rfq.html
+++ b/erpnext/templates/pages/rfq.html
@@ -68,6 +68,31 @@
 				<textarea class="form-control terms-feedback" style="height: 100px;"></textarea>
 			</div>
 		</div>
+		<hr>
+		<div class="row">
+			<div class="result">
+				<div class="col-xs-12">
+					<p class="text-muted small">{{ _("Quotations: ") }}</p>
+					{% if doc.rfq_links %}
+						{% for d in doc.rfq_links %}
+							<div class="web-list-item transaction-list-item quotations" idx="{{d.name}}">
+								<div class="row">
+									<div class="col-sm-6">
+										<span class="indicator darkgrey"><a href="/quotations/{{d.name}}">{{d.name}}</a></span>
+									</div>
+									<div class="col-sm-3">
+										<span class="small darkgrey">{{d.status}}</span>
+									</div>
+									<div class="col-sm-3">
+										<span class="small darkgrey">{{d.transaction_date}}</span>
+									</div>
+								</div>
+							</div>
+						{% endfor %}
+					{% endif %}
+				</div>
+			</div>
+		</div>
     </div>
 </div>
 
diff --git a/erpnext/templates/pages/rfq.py b/erpnext/templates/pages/rfq.py
index decae41..abc2890 100644
--- a/erpnext/templates/pages/rfq.py
+++ b/erpnext/templates/pages/rfq.py
@@ -4,6 +4,7 @@
 from __future__ import unicode_literals
 import frappe
 from frappe import _
+from frappe.utils import formatdate
 from erpnext.controllers.website_list_for_contact import (get_customers_suppliers,
 					get_party_details)
 
@@ -13,6 +14,7 @@
 	context.doc = frappe.get_doc(frappe.form_dict.doctype, frappe.form_dict.name)
 	context.parents = frappe.form_dict.parents
 	context.doc.supplier = get_supplier()
+	context.doc.rfq_links = get_link_quotation(context.doc.supplier, context.doc.name)
 	unauthorized_user(context.doc.supplier)
 	update_supplier_details(context)
 	context["title"] = frappe.form_dict.name
@@ -41,4 +43,18 @@
 	context.doc.currency = supplier_doc.default_currency or frappe.db.get_value("Company", context.doc.company, "default_currency")
 	context.doc.currency_symbol = frappe.db.get_value("Currency", context.doc.currency, "symbol")
 	context.doc.number_format = frappe.db.get_value("Currency", context.doc.currency, "number_format")
-	context.doc.buying_price_list = supplier_doc.default_price_list or ''
\ No newline at end of file
+	context.doc.buying_price_list = supplier_doc.default_price_list or ''
+
+def get_link_quotation(supplier, rfq):
+	quotation = frappe.db.sql(""" select distinct `tabSupplier Quotation Item`.parent as name,
+		`tabSupplier Quotation`.status, `tabSupplier Quotation`.transaction_date from
+		`tabSupplier Quotation Item`, `tabSupplier Quotation` where `tabSupplier Quotation`.docstatus < 2 and
+		`tabSupplier Quotation Item`.request_for_quotation =%(name)s and
+		`tabSupplier Quotation Item`.parent = `tabSupplier Quotation`.name and
+		`tabSupplier Quotation`.supplier = %(supplier)s order by `tabSupplier Quotation`.creation desc""",
+		{'name': rfq, 'supplier': supplier}, as_dict=1)
+
+	for data in quotation:
+		data.transaction_date = formatdate(data.transaction_date)
+
+	return quotation or None
diff --git a/erpnext/templates/print_formats/includes/item_table_description.html b/erpnext/templates/print_formats/includes/item_table_description.html
index e8a98f0..e99d712 100644
--- a/erpnext/templates/print_formats/includes/item_table_description.html
+++ b/erpnext/templates/print_formats/includes/item_table_description.html
@@ -2,9 +2,8 @@
 {%- set compact_fields = doc.flags.compact_item_fields -%}
 
 {% if doc.in_format_data("image") and doc.get("image") and not doc.is_print_hide("image")-%}
-<div class="pull-left" style="width: 20%; margin-right: 10px;">
-	<div class="square-image" style="background-image: url('{{ doc.image }}')">
-	</div>
+<div class="pull-left" style="max-width: 40%; margin-right: 10px;">
+	<img class="print-item-image" src="{{ doc.image }}" alt="">
 </div>
 {%- endif %}
 
diff --git a/erpnext/translations/fr.csv b/erpnext/translations/fr.csv
index 6292472..577bdf7 100644
--- a/erpnext/translations/fr.csv
+++ b/erpnext/translations/fr.csv
@@ -413,7 +413,7 @@
 DocType: Account,Cost of Goods Sold,Coût des marchandises vendues
 DocType: Purchase Invoice,Yearly,Annuel
 apps/erpnext/erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.py +225,Please enter Cost Center,S'il vous plaît entrer Centre de coûts
-DocType: Journal Entry Account,Sales Order,Bon de commande
+DocType: Journal Entry Account,Sales Order,commande client
 apps/erpnext/erpnext/accounts/report/gross_profit/gross_profit.py +68,Avg. Selling Rate,Moy. Taux de vente
 DocType: Assessment,Examiner Name,Nom de l&#39;examinateur
 apps/erpnext/erpnext/utilities/transaction_base.py +149,Quantity cannot be a fraction in row {0},La quantité ne peut pas être une fraction à la ligne {0}
@@ -1007,7 +1007,7 @@
 DocType: GL Entry,Against,Contre
 DocType: Item,Default Selling Cost Center,Coût des marchandises vendues
 DocType: Sales Partner,Implementation Partner,Partenaire de mise en œuvre
-apps/erpnext/erpnext/controllers/selling_controller.py +231,Sales Order {0} is {1},Bon de commande {0} est {1}
+apps/erpnext/erpnext/controllers/selling_controller.py +231,Sales Order {0} is {1},commande client {0} est {1}
 DocType: Opportunity,Contact Info,Information de contact
 apps/erpnext/erpnext/config/stock.py +299,Making Stock Entries,Faire des entrées stock
 DocType: Packing Slip,Net Weight UOM,Unité de mesure Poids Net
@@ -1152,7 +1152,7 @@
 ,Accounts Payable Summary,Le résumé des comptes à payer
 apps/erpnext/erpnext/accounts/doctype/gl_entry/gl_entry.py +196,Not authorized to edit frozen Account {0},N'êtes pas autorisé à modifier le compte gelé {0}
 DocType: Journal Entry,Get Outstanding Invoices,Obtenez les factures impayées
-apps/erpnext/erpnext/manufacturing/doctype/production_order/production_order.py +62,Sales Order {0} is not valid,Bon de commande {0} invalide
+apps/erpnext/erpnext/manufacturing/doctype/production_order/production_order.py +62,Sales Order {0} is not valid,commande client {0} invalide
 apps/erpnext/erpnext/setup/doctype/company/company.py +185,"Sorry, companies cannot be merged","Désolé , les entreprises ne peuvent pas être fusionnés"
 apps/erpnext/erpnext/stock/doctype/material_request/material_request.py +139,"The total Issue / Transfer quantity {0} in Material Request {1}  \
 							cannot be greater than requested quantity {2} for Item {3}",La quantité Problème / transfert total {0} dans Material Request {1} \ ne peut pas être supérieure à la quantité demandée {2} pour le poste {3}
@@ -1607,7 +1607,7 @@
 apps/erpnext/erpnext/controllers/buying_controller.py +300,Row #{0}: Rejected Warehouse is mandatory against rejected Item {1},Row # {0}: Entrepôt Rejeté est obligatoire contre Item rejeté {1}
 apps/erpnext/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.js +731,Payment,Paiement
 DocType: Production Order Operation,Actual Time and Cost,Temps réel et coût
-apps/erpnext/erpnext/stock/doctype/material_request/material_request.py +54,Material Request of maximum {0} can be made for Item {1} against Sales Order {2},Demande de Matériel d'un maximum de {0} peut être faite pour l'article {1} par rapport au bon de commande {2}
+apps/erpnext/erpnext/stock/doctype/material_request/material_request.py +54,Material Request of maximum {0} can be made for Item {1} against Sales Order {2},Demande de Matériel d'un maximum de {0} peut être faite pour l'article {1} par rapport au commande client {2}
 DocType: Employee,Salutation,Titre
 DocType: Pricing Rule,Brand,Marque
 DocType: Course,Course Abbreviation,Abréviation de cours
@@ -1883,7 +1883,7 @@
 DocType: Quality Inspection,In Process,En cours
 DocType: Authorization Rule,Itemwise Discount,Remise (par Article)
 apps/erpnext/erpnext/config/accounts.py +69,Tree of financial accounts.,Arbre des comptes financiers.
-apps/erpnext/erpnext/accounts/doctype/journal_entry/journal_entry.py +334,{0} against Sales Order {1},{0} contre le bon de commande de vente {1}
+apps/erpnext/erpnext/accounts/doctype/journal_entry/journal_entry.py +334,{0} against Sales Order {1},{0} contre le commande client de vente {1}
 DocType: Account,Fixed Asset,Actifs immobilisés
 apps/erpnext/erpnext/config/stock.py +304,Serialized Inventory,Inventaire sérialisé
 DocType: Activity Type,Default Billing Rate,Prix facturation par défaut
@@ -2182,7 +2182,7 @@
 DocType: Purchase Receipt Item,Recd Quantity,Quantité reçue
 apps/erpnext/erpnext/schools/doctype/program_enrollment/program_enrollment.py +54,Fee Records Created - {0},Records Fee Créé - {0}
 DocType: Asset Category Account,Asset Category Account,Catégorie d&#39;actif compte
-apps/erpnext/erpnext/manufacturing/doctype/production_order/production_order.py +103,Cannot produce more Item {0} than Sales Order quantity {1},Ne peut pas produire plus d'article {0} que de la qté du bon de commande {1}
+apps/erpnext/erpnext/manufacturing/doctype/production_order/production_order.py +103,Cannot produce more Item {0} than Sales Order quantity {1},Ne peut pas produire plus d'article {0} que de la qté du commande client {1}
 apps/erpnext/erpnext/accounts/doctype/journal_entry/journal_entry.py +504,Stock Entry {0} is not submitted,Entrée stock {0} est pas soumis
 DocType: Payment Reconciliation,Bank / Cash Account,Banque et liquidités
 DocType: Tax Rule,Billing City,Ville de facturation
@@ -2532,7 +2532,7 @@
 DocType: Program Enrollment Tool,Get Students,Obtenez étudiants
 DocType: Serial No,Under Warranty,Sous garantie
 apps/erpnext/erpnext/accounts/doctype/sales_invoice/sales_invoice.js +490,[Error],[Erreur]
-DocType: Sales Order,In Words will be visible once you save the Sales Order.,En Toutes Lettres. Sera visible une fois que vous enregistrerez le bon de commande.
+DocType: Sales Order,In Words will be visible once you save the Sales Order.,En Toutes Lettres. Sera visible une fois que vous enregistrerez le commande client.
 ,Employee Birthday,Anniversaire de l'employé
 apps/erpnext/erpnext/controllers/status_updater.py +175,Limit Crossed,Limite Crossed
 apps/erpnext/erpnext/setup/setup_wizard/industry_type.py +55,Venture Capital,Capital Risque
@@ -2769,7 +2769,7 @@
 apps/erpnext/erpnext/accounts/page/pos/pos.js +1190,Please select customer,S&#39;il vous plaît sélectionner client
 DocType: C-Form,I,I
 DocType: Company,Asset Depreciation Cost Center,Asset Centre Amortissements
-DocType: Sales Order Item,Sales Order Date,Date du bon de Commande
+DocType: Sales Order Item,Sales Order Date,Date du commande client
 DocType: Sales Invoice Item,Delivered Qty,Qté livrée
 DocType: Production Planning Tool,"If checked, all the children of each production item will be included in the Material Requests.","Si elle est cochée, tous les enfants de chaque élément de production seront inclus dans les demandes de matériel."
 apps/erpnext/erpnext/stock/doctype/warehouse/warehouse.py +86,Warehouse {0}: Company is mandatory,Entrepôt {0}: Société est obligatoire
@@ -3459,7 +3459,7 @@
 apps/erpnext/erpnext/accounts/report/sales_register/sales_register.py +69,Customer Id,Client Id
 apps/erpnext/erpnext/hr/doctype/employee_attendance_tool/employee_attendance_tool.js +176,Mark Absent,Marquer absent
 DocType: Journal Entry Account,Exchange Rate,Taux de change
-apps/erpnext/erpnext/accounts/doctype/sales_invoice/sales_invoice.py +471,Sales Order {0} is not submitted,Bon de commande {0} n'a pas été transmis
+apps/erpnext/erpnext/accounts/doctype/sales_invoice/sales_invoice.py +471,Sales Order {0} is not submitted,commande client {0} n'a pas été transmis
 DocType: Homepage,Tag Line,Tag ligne
 DocType: Fee Component,Fee Component,Component Fee
 apps/erpnext/erpnext/buying/doctype/purchase_order/purchase_order.js +857,Add items from,Ajouter des articles de
diff --git a/erpnext/utilities/address_and_contact.py b/erpnext/utilities/address_and_contact.py
index 324f679..36879d2 100644
--- a/erpnext/utilities/address_and_contact.py
+++ b/erpnext/utilities/address_and_contact.py
@@ -29,7 +29,6 @@
 	for df in (links.get("permitted_links") + links.get("not_permitted_links")):
 		doctype = df.options
 		name = doc.get(df.fieldname)
-
 		names.append(name)
 
 		if name and frappe.has_permission(doctype, ptype, doc=name):
@@ -37,9 +36,7 @@
 
 	if not any(names):
 		return True
-
-	else:
-		return False
+	return False
 
 def get_permission_query_conditions_for_contact(user):
 	return get_permission_query_conditions("Contact")
diff --git a/patches.txt b/patches.txt
deleted file mode 100644
index 8f127fe..0000000
--- a/patches.txt
+++ /dev/null
@@ -1 +0,0 @@
-bench.patches.v3.deprecate_old_config