Merge pull request #2283 from neilLasrado/employee-reports-to

employee cannot report to himself validation added to employee doctype
diff --git a/erpnext/accounts/doctype/c_form/c_form.js b/erpnext/accounts/doctype/c_form/c_form.js
index 3bcfa5e..e4046d5 100644
--- a/erpnext/accounts/doctype/c_form/c_form.js
+++ b/erpnext/accounts/doctype/c_form/c_form.js
@@ -3,6 +3,8 @@
 
 //c-form js file
 // -----------------------------
+frappe.require("assets/erpnext/js/utils.js");
+
 cur_frm.fields_dict.invoice_details.grid.get_field("invoice_no").get_query = function(doc) {
 	return {
 		filters: {
@@ -22,4 +24,12 @@
 cur_frm.cscript.invoice_no = function(doc, cdt, cdn) {
 	var d = locals[cdt][cdn];
 	return get_server_fields('get_invoice_details', d.invoice_no, 'invoice_details', doc, cdt, cdn, 1);
+}
+
+cur_frm.cscript.company = function(doc, cdt, cdn) {
+	erpnext.get_fiscal_year(doc.company, doc.received_date);
+}
+
+cur_frm.cscript.received_date = function(doc, cdt, cdn){
+	erpnext.get_fiscal_year(doc.company, doc.received_date);
 }
\ No newline at end of file
diff --git a/erpnext/accounts/doctype/fiscal_year/fiscal_year.json b/erpnext/accounts/doctype/fiscal_year/fiscal_year.json
index 0f7aefd..3927c4f 100644
--- a/erpnext/accounts/doctype/fiscal_year/fiscal_year.json
+++ b/erpnext/accounts/doctype/fiscal_year/fiscal_year.json
@@ -39,23 +39,17 @@
    "reqd": 1
   }, 
   {
-   "default": "No", 
-   "description": "Entries are not allowed against this Fiscal Year if the year is closed.", 
-   "fieldname": "is_fiscal_year_closed", 
-   "fieldtype": "Select", 
-   "in_list_view": 1, 
-   "label": "Year Closed", 
-   "no_copy": 1, 
-   "oldfieldname": "is_fiscal_year_closed", 
-   "oldfieldtype": "Select", 
-   "options": "\nNo\nYes", 
+   "fieldname": "fiscal_year_companies", 
+   "fieldtype": "Table", 
+   "label": "Fiscal Year Companies", 
+   "options": "Fiscal Year Company", 
    "permlevel": 0, 
-   "reqd": 0
+   "precision": ""
   }
  ], 
  "icon": "icon-calendar", 
  "idx": 1, 
- "modified": "2014-07-14 05:30:56.843180", 
+ "modified": "2014-10-07 12:23:41.679419", 
  "modified_by": "Administrator", 
  "module": "Accounts", 
  "name": "Fiscal Year", 
diff --git a/erpnext/accounts/doctype/fiscal_year_company/__init__.py b/erpnext/accounts/doctype/fiscal_year_company/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/erpnext/accounts/doctype/fiscal_year_company/__init__.py
diff --git a/erpnext/accounts/doctype/fiscal_year_company/fiscal_year_company.json b/erpnext/accounts/doctype/fiscal_year_company/fiscal_year_company.json
new file mode 100644
index 0000000..5de4d3c
--- /dev/null
+++ b/erpnext/accounts/doctype/fiscal_year_company/fiscal_year_company.json
@@ -0,0 +1,51 @@
+{
+ "allow_copy": 0, 
+ "allow_import": 0, 
+ "allow_rename": 0, 
+ "creation": "2014-10-02 13:35:44.155278", 
+ "custom": 0, 
+ "docstatus": 0, 
+ "doctype": "DocType", 
+ "document_type": "Master", 
+ "fields": [
+  {
+   "allow_on_submit": 0, 
+   "fieldname": "company", 
+   "fieldtype": "Link", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "in_filter": 0, 
+   "in_list_view": 1, 
+   "label": "Company", 
+   "no_copy": 0, 
+   "options": "Company", 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 0, 
+   "read_only": 0, 
+   "report_hide": 0, 
+   "reqd": 0, 
+   "search_index": 0, 
+   "set_only_once": 0, 
+   "unique": 0
+  }
+ ], 
+ "hide_heading": 0, 
+ "hide_toolbar": 0, 
+ "in_create": 0, 
+ "in_dialog": 0, 
+ "is_submittable": 0, 
+ "issingle": 0, 
+ "istable": 1, 
+ "modified": "2014-10-02 13:35:44.155278", 
+ "modified_by": "Administrator", 
+ "module": "Accounts", 
+ "name": "Fiscal Year Company", 
+ "name_case": "", 
+ "owner": "Administrator", 
+ "permissions": [], 
+ "read_only": 0, 
+ "read_only_onload": 0, 
+ "sort_field": "modified", 
+ "sort_order": "DESC"
+}
\ No newline at end of file
diff --git a/erpnext/accounts/doctype/fiscal_year_company/fiscal_year_company.py b/erpnext/accounts/doctype/fiscal_year_company/fiscal_year_company.py
new file mode 100644
index 0000000..76a8bd4
--- /dev/null
+++ b/erpnext/accounts/doctype/fiscal_year_company/fiscal_year_company.py
@@ -0,0 +1,9 @@
+# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors and contributors
+# For license information, please see license.txt
+
+from __future__ import unicode_literals
+import frappe
+from frappe.model.document import Document
+
+class FiscalYearCompany(Document):
+	pass
diff --git a/erpnext/accounts/doctype/journal_voucher/journal_voucher.js b/erpnext/accounts/doctype/journal_voucher/journal_voucher.js
index 69269d0..a346f6c 100644
--- a/erpnext/accounts/doctype/journal_voucher/journal_voucher.js
+++ b/erpnext/accounts/doctype/journal_voucher/journal_voucher.js
@@ -2,6 +2,7 @@
 // License: GNU General Public License v3. See license.txt
 
 frappe.provide("erpnext.accounts");
+frappe.require("assets/erpnext/js/utils.js");
 
 erpnext.accounts.JournalVoucher = frappe.ui.form.Controller.extend({
 	onload: function() {
@@ -153,6 +154,11 @@
 
 cur_frm.cscript.company = function(doc, cdt, cdn) {
 	cur_frm.refresh_fields();
+	erpnext.get_fiscal_year(doc.company, doc.posting_date);
+}
+
+cur_frm.cscript.posting_date = function(doc, cdt, cdn){
+	erpnext.get_fiscal_year(doc.company, doc.posting_date);
 }
 
 cur_frm.cscript.is_opening = function(doc, cdt, cdn) {
diff --git a/erpnext/accounts/doctype/journal_voucher/journal_voucher.json b/erpnext/accounts/doctype/journal_voucher/journal_voucher.json
index 1638296..180a211 100644
--- a/erpnext/accounts/doctype/journal_voucher/journal_voucher.json
+++ b/erpnext/accounts/doctype/journal_voucher/journal_voucher.json
@@ -389,20 +389,6 @@
    "report_hide": 1
   }, 
   {
-   "fieldname": "fiscal_year", 
-   "fieldtype": "Link", 
-   "in_filter": 1, 
-   "label": "Fiscal Year", 
-   "oldfieldname": "fiscal_year", 
-   "oldfieldtype": "Select", 
-   "options": "Fiscal Year", 
-   "permlevel": 0, 
-   "print_hide": 1, 
-   "read_only": 0, 
-   "reqd": 1, 
-   "search_index": 1
-  }, 
-  {
    "fieldname": "company", 
    "fieldtype": "Link", 
    "in_filter": 1, 
@@ -417,6 +403,20 @@
    "search_index": 1
   }, 
   {
+   "fieldname": "fiscal_year", 
+   "fieldtype": "Link", 
+   "in_filter": 1, 
+   "label": "Fiscal Year", 
+   "oldfieldname": "fiscal_year", 
+   "oldfieldtype": "Select", 
+   "options": "Fiscal Year", 
+   "permlevel": 0, 
+   "print_hide": 1, 
+   "read_only": 0, 
+   "reqd": 1, 
+   "search_index": 1
+  }, 
+  {
    "allow_on_submit": 1, 
    "fieldname": "select_print_heading", 
    "fieldtype": "Link", 
@@ -447,7 +447,7 @@
  "icon": "icon-file-text", 
  "idx": 1, 
  "is_submittable": 1, 
- "modified": "2014-09-09 05:35:31.217863", 
+ "modified": "2014-10-02 14:51:20.624847", 
  "modified_by": "Administrator", 
  "module": "Accounts", 
  "name": "Journal Voucher", 
diff --git a/erpnext/accounts/utils.py b/erpnext/accounts/utils.py
index cf57a61..0c108a4 100644
--- a/erpnext/accounts/utils.py
+++ b/erpnext/accounts/utils.py
@@ -12,26 +12,29 @@
 class FiscalYearError(frappe.ValidationError): pass
 class BudgetError(frappe.ValidationError): pass
 
+@frappe.whitelist()
+def get_fiscal_year(date=None, fiscal_year=None, label="Date", verbose=1, company=None):
+	return get_fiscal_years(date, fiscal_year, label, verbose, company)[0]
 
-def get_fiscal_year(date=None, fiscal_year=None, label="Date", verbose=1):
-	return get_fiscal_years(date, fiscal_year, label, verbose)[0]
-
-def get_fiscal_years(date=None, fiscal_year=None, label="Date", verbose=1):
+def get_fiscal_years(date=None, fiscal_year=None, label="Date", verbose=1, company=None):
 	# if year start date is 2012-04-01, year end date should be 2013-03-31 (hence subdate)
 	cond = ""
 	if fiscal_year:
 		cond = "name = '%s'" % fiscal_year.replace("'", "\'")
+	elif company:
+		cond = """('%s' in (select company from `tabFiscal Year Company`
+			where `tabFiscal Year Company`.parent = `tabFiscal Year`.name)) 
+			and '%s' >= year_start_date and '%s' <= year_end_date """ %(company.replace("'", "\'"), date, date)
 	else:
-		cond = "'%s' >= year_start_date and '%s' <= year_end_date" % \
-			(date, date)
+		cond = "'%s' >= year_start_date and '%s' <= year_end_date" %(date, date)
+
 	fy = frappe.db.sql("""select name, year_start_date, year_end_date
 		from `tabFiscal Year` where %s order by year_start_date desc""" % cond)
 
 	if not fy:
 		error_msg = _("""{0} {1} not in any Fiscal Year""").format(label, formatdate(date))
-		if verbose: frappe.msgprint(error_msg)
+		if verbose==1: frappe.msgprint(error_msg)
 		raise FiscalYearError, error_msg
-
 	return fy
 
 def validate_fiscal_year(date, fiscal_year, label="Date"):
diff --git a/erpnext/buying/doctype/purchase_order/purchase_order.js b/erpnext/buying/doctype/purchase_order/purchase_order.js
index 9433ebe..8c2b1a2 100644
--- a/erpnext/buying/doctype/purchase_order/purchase_order.js
+++ b/erpnext/buying/doctype/purchase_order/purchase_order.js
@@ -209,5 +209,4 @@
 cur_frm.cscript.send_sms = function() {
 	frappe.require("assets/erpnext/js/sms_manager.js");
 	var sms_man = new SMSManager(cur_frm.doc);
-}
-
+}
\ No newline at end of file
diff --git a/erpnext/buying/doctype/supplier_quotation/supplier_quotation.js b/erpnext/buying/doctype/supplier_quotation/supplier_quotation.js
index b8d40ca..b9286a1 100644
--- a/erpnext/buying/doctype/supplier_quotation/supplier_quotation.js
+++ b/erpnext/buying/doctype/supplier_quotation/supplier_quotation.js
@@ -71,4 +71,4 @@
 	return {
 		filters:{'supplier': doc.supplier}
 	}
-}
+}
\ 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 a4ba2eb..e070b3f 100644
--- a/erpnext/hr/doctype/expense_claim/expense_claim.js
+++ b/erpnext/hr/doctype/expense_claim/expense_claim.js
@@ -153,4 +153,4 @@
 	if(cint(frappe.boot.notification_settings && frappe.boot.notification_settings.expense_claim)) {
 		cur_frm.email_doc(frappe.boot.notification_settings.expense_claim_message);
 	}
-}
+}
\ No newline at end of file
diff --git a/erpnext/hr/doctype/expense_claim/expense_claim.json b/erpnext/hr/doctype/expense_claim/expense_claim.json
index 15ef03e..a82ef90 100644
--- a/erpnext/hr/doctype/expense_claim/expense_claim.json
+++ b/erpnext/hr/doctype/expense_claim/expense_claim.json
@@ -90,6 +90,16 @@
    "permlevel": 0
   }, 
   {
+   "fieldname": "posting_date", 
+   "fieldtype": "Date", 
+   "in_filter": 1, 
+   "label": "Posting Date", 
+   "oldfieldname": "posting_date", 
+   "oldfieldtype": "Date", 
+   "permlevel": 0, 
+   "reqd": 1
+  }, 
+  {
    "fieldname": "employee", 
    "fieldtype": "Link", 
    "in_filter": 1, 
@@ -115,17 +125,6 @@
    "width": "150px"
   }, 
   {
-   "fieldname": "fiscal_year", 
-   "fieldtype": "Link", 
-   "in_filter": 1, 
-   "label": "Fiscal Year", 
-   "oldfieldname": "fiscal_year", 
-   "oldfieldtype": "Select", 
-   "options": "Fiscal Year", 
-   "permlevel": 0, 
-   "reqd": 1
-  }, 
-  {
    "fieldname": "company", 
    "fieldtype": "Link", 
    "in_filter": 1, 
@@ -137,21 +136,22 @@
    "reqd": 1
   }, 
   {
+   "fieldname": "fiscal_year", 
+   "fieldtype": "Link", 
+   "in_filter": 1, 
+   "label": "Fiscal Year", 
+   "oldfieldname": "fiscal_year", 
+   "oldfieldtype": "Select", 
+   "options": "Fiscal Year", 
+   "permlevel": 0, 
+   "reqd": 1
+  }, 
+  {
    "fieldname": "cb1", 
    "fieldtype": "Column Break", 
    "permlevel": 0
   }, 
   {
-   "fieldname": "posting_date", 
-   "fieldtype": "Date", 
-   "in_filter": 1, 
-   "label": "Posting Date", 
-   "oldfieldname": "posting_date", 
-   "oldfieldtype": "Date", 
-   "permlevel": 0, 
-   "reqd": 1
-  }, 
-  {
    "allow_on_submit": 0, 
    "fieldname": "remark", 
    "fieldtype": "Small Text", 
@@ -190,7 +190,7 @@
  "icon": "icon-money", 
  "idx": 1, 
  "is_submittable": 1, 
- "modified": "2014-08-27 07:08:48.454580", 
+ "modified": "2014-10-07 18:22:14.689567", 
  "modified_by": "Administrator", 
  "module": "HR", 
  "name": "Expense Claim", 
@@ -206,7 +206,6 @@
    "read": 1, 
    "report": 1, 
    "role": "Employee", 
-   "user_permission_doctypes": "[\"Company\",\"Employee\",\"Expense Claim\",\"Fiscal Year\"]", 
    "write": 1
   }, 
   {
@@ -222,7 +221,6 @@
    "report": 1, 
    "role": "Expense Approver", 
    "submit": 1, 
-   "user_permission_doctypes": "[\"Expense Claim\",\"User\"]", 
    "write": 1
   }, 
   {
@@ -238,7 +236,6 @@
    "report": 1, 
    "role": "HR User", 
    "submit": 1, 
-   "user_permission_doctypes": "[\"Company\",\"Expense Claim\",\"Fiscal Year\"]", 
    "write": 1
   }
  ], 
diff --git a/erpnext/public/js/transaction.js b/erpnext/public/js/transaction.js
index 3a12485..41b3842 100644
--- a/erpnext/public/js/transaction.js
+++ b/erpnext/public/js/transaction.js
@@ -3,6 +3,8 @@
 
 frappe.provide("erpnext");
 frappe.require("assets/erpnext/js/controllers/stock_controller.js");
+frappe.require("assets/erpnext/js/utils.js");
+
 
 erpnext.TransactionController = erpnext.stock.StockController.extend({
 	onload: function() {
@@ -205,22 +207,37 @@
 	},
 
 	company: function() {
-		if(this.frm.doc.company && this.frm.fields_dict.currency) {
-			var company_currency = this.get_company_currency();
-			if (!this.frm.doc.currency) {
-				this.frm.set_value("currency", company_currency);
-			}
+		var me = this;
+		var fn = function() {
+			if(me.frm.doc.company && me.frm.fields_dict.currency) {
+				var company_currency = me.get_company_currency();
+				if (!me.frm.doc.currency) {
+					me.frm.set_value("currency", company_currency);
+				}
 
-			if (this.frm.doc.currency == company_currency) {
-				this.frm.set_value("conversion_rate", 1.0);
-			}
-			if (this.frm.doc.price_list_currency == company_currency) {
-				this.frm.set_value('plc_conversion_rate', 1.0);
-			}
+				if (me.frm.doc.currency == company_currency) {
+					me.frm.set_value("conversion_rate", 1.0);
+				}
+				if (me.frm.doc.price_list_currency == company_currency) {
+					me.frm.set_value('plc_conversion_rate', 1.0);
+				}
 
-			this.frm.script_manager.trigger("currency");
-			this.apply_pricing_rule();
+				me.frm.script_manager.trigger("currency");
+				me.apply_pricing_rule();
+			}	
 		}
+		
+		if (this.frm.doc.posting_date) var date = this.frm.doc.posting_date;
+		else var date = this.frm.doc.transaction_date;
+		erpnext.get_fiscal_year(this.frm.doc.company, date, fn);
+	},
+
+	transaction_date: function() {
+		erpnext.get_fiscal_year(this.frm.doc.company, this.frm.doc.transaction_date);
+	},
+
+	posting_date: function() {
+		erpnext.get_fiscal_year(this.frm.doc.company, this.frm.doc.posting_date);
 	},
 
 	get_company_currency: function() {
diff --git a/erpnext/public/js/utils.js b/erpnext/public/js/utils.js
index ef7d03e..f72bcc4 100644
--- a/erpnext/public/js/utils.js
+++ b/erpnext/public/js/utils.js
@@ -12,6 +12,22 @@
 			return frappe.boot.sysdefaults.currency;
 	},
 
+	get_fiscal_year: function(company, date, fn) {
+		frappe.call({
+			type:"GET",
+			method: "erpnext.accounts.utils.get_fiscal_year",
+			args: {
+				"company": company,
+				"date": date,
+				"verbose": '0'
+			},
+			callback: function(r) {
+				if (r.message)	cur_frm.set_value("fiscal_year", r.message[0]);
+				if (fn) fn();
+			}
+		});
+	},
+
 	toggle_naming_series: function() {
 		if(cur_frm.fields_dict.naming_series) {
 			cur_frm.toggle_display("naming_series", cur_frm.doc.__islocal?true:false);
diff --git a/erpnext/selling/doctype/installation_note/installation_note.js b/erpnext/selling/doctype/installation_note/installation_note.js
index e8dee46..60e2f72 100644
--- a/erpnext/selling/doctype/installation_note/installation_note.js
+++ b/erpnext/selling/doctype/installation_note/installation_note.js
@@ -4,6 +4,7 @@
 cur_frm.cscript.tname = "Installation Note Item";
 cur_frm.cscript.fname = "installed_item_details";
 
+frappe.require("assets/erpnext/js/utils.js");
 
 frappe.ui.form.on_change("Installation Note", "customer",
 	function(frm) { erpnext.utils.get_party_details(frm); });
@@ -69,3 +70,11 @@
 });
 
 $.extend(cur_frm.cscript, new erpnext.selling.InstallationNote({frm: cur_frm}));
+
+cur_frm.cscript.company = function(doc, cdt, cdn) {
+	erpnext.get_fiscal_year(doc.company, doc.inst_date);
+}
+
+cur_frm.cscript.inst_date = function(doc, cdt, cdn){
+	erpnext.get_fiscal_year(doc.company, doc.inst_date);
+}
\ No newline at end of file
diff --git a/erpnext/selling/doctype/opportunity/opportunity.js b/erpnext/selling/doctype/opportunity/opportunity.js
index df84d72..b29c03a 100644
--- a/erpnext/selling/doctype/opportunity/opportunity.js
+++ b/erpnext/selling/doctype/opportunity/opportunity.js
@@ -8,6 +8,7 @@
 
 
 frappe.provide("erpnext.selling");
+frappe.require("assets/erpnext/js/utils.js");
 cur_frm.email_field = "contact_email";
 
 // TODO commonify this code
@@ -145,3 +146,10 @@
 	var sms_man = new SMSManager(cur_frm.doc);
 }
 
+cur_frm.cscript.company = function(doc, cdt, cdn) {
+	erpnext.get_fiscal_year(doc.company, doc.transaction_date);
+}
+
+cur_frm.cscript.transaction_date = function(doc, cdt, cdn){
+	erpnext.get_fiscal_year(doc.company, doc.transaction_date);
+}
\ No newline at end of file
diff --git a/erpnext/selling/doctype/opportunity/opportunity.json b/erpnext/selling/doctype/opportunity/opportunity.json
index 270fe77..a47b21f 100644
--- a/erpnext/selling/doctype/opportunity/opportunity.json
+++ b/erpnext/selling/doctype/opportunity/opportunity.json
@@ -272,13 +272,13 @@
    "width": "50px"
   }, 
   {
-   "fieldname": "fiscal_year", 
+   "fieldname": "company", 
    "fieldtype": "Link", 
    "in_filter": 1, 
-   "label": "Fiscal Year", 
-   "oldfieldname": "fiscal_year", 
-   "oldfieldtype": "Select", 
-   "options": "Fiscal Year", 
+   "label": "Company", 
+   "oldfieldname": "company", 
+   "oldfieldtype": "Link", 
+   "options": "Company", 
    "permlevel": 0, 
    "print_hide": 1, 
    "read_only": 0, 
@@ -307,13 +307,13 @@
    "read_only": 0
   }, 
   {
-   "fieldname": "company", 
+   "fieldname": "fiscal_year", 
    "fieldtype": "Link", 
    "in_filter": 1, 
-   "label": "Company", 
-   "oldfieldname": "company", 
-   "oldfieldtype": "Link", 
-   "options": "Company", 
+   "label": "Fiscal Year", 
+   "oldfieldname": "fiscal_year", 
+   "oldfieldtype": "Select", 
+   "options": "Fiscal Year", 
    "permlevel": 0, 
    "print_hide": 1, 
    "read_only": 0, 
@@ -388,7 +388,7 @@
  "icon": "icon-info-sign", 
  "idx": 1, 
  "is_submittable": 1, 
- "modified": "2014-09-11 18:53:14.037512", 
+ "modified": "2014-10-07 18:12:19.104820", 
  "modified_by": "Administrator", 
  "module": "Selling", 
  "name": "Opportunity", 
@@ -396,6 +396,7 @@
  "permissions": [
   {
    "amend": 1, 
+   "apply_user_permissions": 1, 
    "cancel": 1, 
    "create": 1, 
    "delete": 1, 
diff --git a/erpnext/selling/doctype/quotation/quotation.js b/erpnext/selling/doctype/quotation/quotation.js
index 5f25446..857a259 100644
--- a/erpnext/selling/doctype/quotation/quotation.js
+++ b/erpnext/selling/doctype/quotation/quotation.js
@@ -169,5 +169,4 @@
 cur_frm.cscript.send_sms = function() {
 	frappe.require("assets/erpnext/js/sms_manager.js");
 	var sms_man = new SMSManager(cur_frm.doc);
-}
-
+}
\ No newline at end of file
diff --git a/erpnext/selling/doctype/sales_order/sales_order.js b/erpnext/selling/doctype/sales_order/sales_order.js
index 628e43e..65b91f4 100644
--- a/erpnext/selling/doctype/sales_order/sales_order.js
+++ b/erpnext/selling/doctype/sales_order/sales_order.js
@@ -198,4 +198,4 @@
 cur_frm.cscript.send_sms = function() {
 	frappe.require("assets/erpnext/js/sms_manager.js");
 	var sms_man = new SMSManager(cur_frm.doc);
-};
+};
\ No newline at end of file
diff --git a/erpnext/stock/doctype/material_request/material_request.js b/erpnext/stock/doctype/material_request/material_request.js
index 3729b55..147a3b1 100644
--- a/erpnext/stock/doctype/material_request/material_request.js
+++ b/erpnext/stock/doctype/material_request/material_request.js
@@ -6,6 +6,8 @@
 
 {% include 'buying/doctype/purchase_common/purchase_common.js' %};
 
+frappe.require("assets/erpnext/js/utils.js");
+
 erpnext.buying.MaterialRequestController = erpnext.buying.BuyingController.extend({
 	onload: function(doc) {
 		this._super();
@@ -194,4 +196,4 @@
 cur_frm.cscript.send_sms = function() {
 	frappe.require("assets/erpnext/js/sms_manager.js");
 	var sms_man = new SMSManager(cur_frm.doc);
-}
+}
\ 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 96dee3d..d961b40 100644
--- a/erpnext/stock/doctype/stock_entry/stock_entry.js
+++ b/erpnext/stock/doctype/stock_entry/stock_entry.js
@@ -1,10 +1,10 @@
-// Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors
-// License: GNU General Public License v3. See license.txt
+// Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors // License: GNU General Public License v3. See license.txt
 
 cur_frm.cscript.tname = "Stock Entry Detail";
 cur_frm.cscript.fname = "mtn_details";
 
 frappe.require("assets/erpnext/js/controllers/stock_controller.js");
+frappe.require("assets/erpnext/js/utils.js");
 frappe.provide("erpnext.stock");
 
 erpnext.stock.StockEntry = erpnext.stock.StockController.extend({
@@ -462,4 +462,12 @@
 	return { query: "erpnext.controllers.queries.supplier_query" }
 }
 cur_frm.add_fetch('production_order', 'total_fixed_cost', 'total_fixed_cost');
-cur_frm.add_fetch('bom_no', 'total_fixed_cost', 'total_fixed_cost');
\ No newline at end of file
+cur_frm.add_fetch('bom_no', 'total_fixed_cost', 'total_fixed_cost');
+
+cur_frm.cscript.company = function(doc, cdt, cdn) {
+	erpnext.get_fiscal_year(doc.company, doc.posting_date);
+}
+
+cur_frm.cscript.posting_date = function(doc, cdt, cdn){
+	erpnext.get_fiscal_year(doc.company, doc.posting_date);
+}
diff --git a/erpnext/stock/doctype/stock_entry/stock_entry.json b/erpnext/stock/doctype/stock_entry/stock_entry.json
index 5f78758..8cbfbef 100644
--- a/erpnext/stock/doctype/stock_entry/stock_entry.json
+++ b/erpnext/stock/doctype/stock_entry/stock_entry.json
@@ -510,17 +510,6 @@
    "read_only": 1
   }, 
   {
-   "fieldname": "fiscal_year", 
-   "fieldtype": "Link", 
-   "in_filter": 0, 
-   "label": "Fiscal Year", 
-   "options": "Fiscal Year", 
-   "permlevel": 0, 
-   "print_hide": 1, 
-   "read_only": 0, 
-   "reqd": 1
-  }, 
-  {
    "allow_on_submit": 0, 
    "fieldname": "company", 
    "fieldtype": "Link", 
@@ -539,6 +528,17 @@
    "search_index": 0
   }, 
   {
+   "fieldname": "fiscal_year", 
+   "fieldtype": "Link", 
+   "in_filter": 0, 
+   "label": "Fiscal Year", 
+   "options": "Fiscal Year", 
+   "permlevel": 0, 
+   "print_hide": 1, 
+   "read_only": 0, 
+   "reqd": 1
+  }, 
+  {
    "allow_on_submit": 1, 
    "fieldname": "select_print_heading", 
    "fieldtype": "Link", 
@@ -585,7 +585,7 @@
  "is_submittable": 1, 
  "issingle": 0, 
  "max_attachments": 0, 
- "modified": "2014-09-16 15:56:37.514676", 
+ "modified": "2014-10-03 14:55:44.916658", 
  "modified_by": "Administrator", 
  "module": "Stock", 
  "name": "Stock Entry", 
diff --git a/erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.js b/erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.js
index 432a999..27ed872 100644
--- a/erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.js
+++ b/erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.js
@@ -2,6 +2,7 @@
 // License: GNU General Public License v3. See license.txt
 
 frappe.require("assets/erpnext/js/controllers/stock_controller.js");
+frappe.require("assets/erpnext/js/utils.js");
 frappe.provide("erpnext.stock");
 
 erpnext.stock.StockReconciliation = erpnext.stock.StockController.extend({
@@ -159,3 +160,11 @@
 });
 
 cur_frm.cscript = new erpnext.stock.StockReconciliation({frm: cur_frm});
+
+cur_frm.cscript.company = function(doc, cdt, cdn) {
+	erpnext.get_fiscal_year(doc.company, doc.posting_date);
+}
+
+cur_frm.cscript.posting_date = function(doc, cdt, cdn){
+	erpnext.get_fiscal_year(doc.company, doc.posting_date);
+}
\ No newline at end of file
diff --git a/erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.json b/erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.json
index daba967..0035fe7 100644
--- a/erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.json
+++ b/erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.json
@@ -1,5 +1,5 @@
 {
-  "allow_copy": 1, 
+ "allow_copy": 1, 
  "autoname": "SR/.######", 
  "creation": "2013-03-28 10:35:31", 
  "description": "This tool helps you to update or fix the quantity and valuation of stock in the system. It is typically used to synchronise the system values and what actually exists in your warehouses.", 
@@ -42,6 +42,14 @@
    "read_only": 1
   }, 
   {
+   "fieldname": "company", 
+   "fieldtype": "Link", 
+   "label": "Company", 
+   "options": "Company", 
+   "permlevel": 0, 
+   "reqd": 1
+  }, 
+  {
    "fieldname": "fiscal_year", 
    "fieldtype": "Link", 
    "label": "Fiscal Year", 
@@ -51,14 +59,6 @@
    "reqd": 1
   }, 
   {
-   "fieldname": "company", 
-   "fieldtype": "Link", 
-   "label": "Company", 
-   "options": "Company", 
-   "permlevel": 0, 
-   "reqd": 1
-  }, 
-  {
    "depends_on": "eval:cint(sys_defaults.auto_accounting_for_stock)", 
    "fieldname": "expense_account", 
    "fieldtype": "Link", 
@@ -118,7 +118,7 @@
  "idx": 1, 
  "is_submittable": 1, 
  "max_attachments": 1, 
- "modified": "2014-05-26 03:05:54.024413", 
+ "modified": "2014-10-08 12:47:52.102135", 
  "modified_by": "Administrator", 
  "module": "Stock", 
  "name": "Stock Reconciliation", 
diff --git a/erpnext/support/doctype/customer_issue/customer_issue.js b/erpnext/support/doctype/customer_issue/customer_issue.js
index 67a265d..bcc59ea 100644
--- a/erpnext/support/doctype/customer_issue/customer_issue.js
+++ b/erpnext/support/doctype/customer_issue/customer_issue.js
@@ -2,6 +2,7 @@
 // License: GNU General Public License v3. See license.txt
 
 frappe.provide("erpnext.support");
+frappe.require("assets/erpnext/js/utils.js");
 
 frappe.ui.form.on_change("Customer Issue", "customer", function(frm) {
 	erpnext.utils.get_party_details(frm) });
@@ -89,3 +90,11 @@
 
 cur_frm.fields_dict.customer.get_query = function(doc,cdt,cdn) {
 	return{	query: "erpnext.controllers.queries.customer_query" } }
+
+cur_frm.cscript.company = function(doc, cdt, cdn) {
+	erpnext.get_fiscal_year(doc.company, doc.complaint_date);
+}
+
+cur_frm.cscript.complaint_date = function(doc, cdt, cdn){
+	erpnext.get_fiscal_year(doc.company, doc.complaint_date);
+}
\ No newline at end of file
diff --git a/erpnext/support/doctype/maintenance_visit/maintenance_visit.js b/erpnext/support/doctype/maintenance_visit/maintenance_visit.js
index e9a7c84..ffdcb3e 100644
--- a/erpnext/support/doctype/maintenance_visit/maintenance_visit.js
+++ b/erpnext/support/doctype/maintenance_visit/maintenance_visit.js
@@ -2,6 +2,7 @@
 // License: GNU General Public License v3. See license.txt
 
 frappe.provide("erpnext.support");
+frappe.require("assets/erpnext/js/utils.js");
 
 frappe.ui.form.on_change("Maintenance Visit", "customer", function(frm) {
 	erpnext.utils.get_party_details(frm) });
@@ -92,3 +93,11 @@
 cur_frm.fields_dict.customer.get_query = function(doc,cdt,cdn) {
 	return {query: "erpnext.controllers.queries.customer_query" }
 }
+
+cur_frm.cscript.company = function(doc, cdt, cdn) {
+	erpnext.get_fiscal_year(doc.company, doc.mntc_date);
+}
+
+cur_frm.cscript.mntc_date = function(doc, cdt, cdn){
+	erpnext.get_fiscal_year(doc.company, doc.mntc_date);
+}
\ No newline at end of file