fiscal year auto fetch added to oppurtunity, quotation, material request, supplier quotation, expense claim doctypes + issues fixed
diff --git a/erpnext/buying/doctype/supplier_quotation/supplier_quotation.js b/erpnext/buying/doctype/supplier_quotation/supplier_quotation.js
index b8d40ca..13fb4e0 100644
--- a/erpnext/buying/doctype/supplier_quotation/supplier_quotation.js
+++ b/erpnext/buying/doctype/supplier_quotation/supplier_quotation.js
@@ -11,6 +11,8 @@
 {% include 'accounts/doctype/purchase_taxes_and_charges_master/purchase_taxes_and_charges_master.js' %}
 {% include 'accounts/doctype/sales_invoice/pos.js' %}
 
+frappe.require("assets/erpnext/js/utils.js");
+
 erpnext.buying.SupplierQuotationController = erpnext.buying.BuyingController.extend({
 	refresh: function() {
 		this._super();
@@ -72,3 +74,11 @@
 		filters:{'supplier': doc.supplier}
 	}
 }
+
+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/hr/doctype/expense_claim/expense_claim.js b/erpnext/hr/doctype/expense_claim/expense_claim.js
index a4ba2eb..a4a64d9 100644
--- a/erpnext/hr/doctype/expense_claim/expense_claim.js
+++ b/erpnext/hr/doctype/expense_claim/expense_claim.js
@@ -2,6 +2,7 @@
 // License: GNU General Public License v3. See license.txt
 
 frappe.provide("erpnext.hr");
+frappe.require("assets/erpnext/js/utils.js");
 
 erpnext.hr.ExpenseClaimController = frappe.ui.form.Controller.extend({
 	make_bank_voucher: function() {
@@ -154,3 +155,11 @@
 		cur_frm.email_doc(frappe.boot.notification_settings.expense_claim_message);
 	}
 }
+
+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/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 355a11c..8fce8e8 100644
--- a/erpnext/public/js/transaction.js
+++ b/erpnext/public/js/transaction.js
@@ -223,11 +223,11 @@
 			this.frm.script_manager.trigger("currency");
 			this.apply_pricing_rule();
 		}
-		erpnext.get_fiscal_year(this.frm.doc);
+		erpnext.get_fiscal_year(this.frm.doc.company, this.frm.doc.posting_date);
 	},
 
 	posting_date: function() {
-		erpnext.get_fiscal_year(this.frm.doc);
+		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 b508471..5a0e9d4 100644
--- a/erpnext/public/js/utils.js
+++ b/erpnext/public/js/utils.js
@@ -22,8 +22,7 @@
 				"verbose": '0'
 			},
 			callback: function(r) {
-				var arr = r.message
-				if (arr != null)	cur_frm.set_value("fiscal_year",arr[0]);
+				if (r.message)	cur_frm.set_value("fiscal_year", r.message[0]);
 			}
 		});
 	},
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..c00b6e1 100644
--- a/erpnext/selling/doctype/quotation/quotation.js
+++ b/erpnext/selling/doctype/quotation/quotation.js
@@ -12,6 +12,8 @@
 {% include 'accounts/doctype/sales_taxes_and_charges_master/sales_taxes_and_charges_master.js' %}
 {% include 'accounts/doctype/sales_invoice/pos.js' %}
 
+frappe.require("assets/erpnext/js/utils.js");
+
 erpnext.selling.QuotationController = erpnext.selling.SellingController.extend({
 	onload: function(doc, dt, dn) {
 		var me = this;
@@ -171,3 +173,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/stock/doctype/material_request/material_request.js b/erpnext/stock/doctype/material_request/material_request.js
index 3729b55..27dd728 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();
@@ -195,3 +197,11 @@
 	frappe.require("assets/erpnext/js/sms_manager.js");
 	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