Posting date trigger function commonified
diff --git a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.js b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.js
index 42a285a..07dbf72 100644
--- a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.js
+++ b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.js
@@ -69,32 +69,6 @@
 		}
 	},
 	
-	posting_date: function() {
-		var me = this;
-		if (this.frm.doc.posting_date) {
-			if (this.frm.doc.supplier) {
-				return frappe.call({
-					method: "erpnext.accounts.party.get_due_date",
-					args: {
-						"posting_date": me.frm.doc.posting_date,
-						"party_type": "Supplier",
-						"party": me.frm.doc.supplier,
-						"company": me.frm.doc.company
-					}, 
-					callback: function(r, rt) {
-						if(r.message) {
-							me.frm.set_value("due_date", r.message);
-						}
-						erpnext.get_fiscal_year(me.frm.doc.company, me.frm.doc.posting_date);
-					}
-				})
-			} else {
-				erpnext.get_fiscal_year(me.frm.doc.company, me.frm.doc.posting_date);
-			}
-		}
-		
-	},
-
 	supplier: function() {
 		var me = this;
 		if(this.frm.updating_party_details)
diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.js b/erpnext/accounts/doctype/sales_invoice/sales_invoice.js
index ea33d48..3bb9aa0 100644
--- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.js
+++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.js
@@ -146,33 +146,6 @@
 			}
 		}
 	},
-	
-	posting_date: function() {
-		var me = this;
-		if (this.frm.doc.posting_date) {
-			if (this.frm.doc.customer) {
-				return frappe.call({
-					method: "erpnext.accounts.party.get_due_date",
-					args: {
-						"posting_date": me.frm.doc.posting_date,
-						"party_type": "Customer",
-						"party": me.frm.doc.customer,
-						"company": me.frm.doc.company
-					}, 
-					callback: function(r, rt) {
-						if(r.message) {
-							me.frm.set_value("due_date", r.message);
-						}
-						erpnext.get_fiscal_year(me.frm.doc.company, me.frm.doc.posting_date);
-					}
-				})
-			} else {
-				erpnext.get_fiscal_year(me.frm.doc.company, me.frm.doc.posting_date);
-			}
-		}
-		
-	},
-	
 
 	customer: function() {
 		var me = this;
diff --git a/erpnext/public/js/controllers/transaction.js b/erpnext/public/js/controllers/transaction.js
index 1ec8489..953800d 100644
--- a/erpnext/public/js/controllers/transaction.js
+++ b/erpnext/public/js/controllers/transaction.js
@@ -254,7 +254,29 @@
 	},
 
 	posting_date: function() {
-		erpnext.get_fiscal_year(this.frm.doc.company, this.frm.doc.posting_date);
+		var me = this;
+		if (this.frm.doc.posting_date) {
+			if ((this.frm.doc.doctype == "Sales Invoice" && this.frm.doc.customer) || 
+				(this.frm.doc.doctype == "Purchase Invoice" && this.frm.doc.supplier)) {
+				return frappe.call({
+					method: "erpnext.accounts.party.get_due_date",
+					args: {
+						"posting_date": me.frm.doc.posting_date,
+						"party_type": me.frm.doc.doctype == "Sales Invoice" ? "Customer" : "Supplier",
+						"party": me.frm.doc.doctype == "Sales Invoice" ? me.frm.doc.customer : me.frm.doc.supplier,
+						"company": me.frm.doc.company
+					}, 
+					callback: function(r, rt) {
+						if(r.message) {
+							me.frm.set_value("due_date", r.message);
+						}
+						erpnext.get_fiscal_year(me.frm.doc.company, me.frm.doc.posting_date);
+					}
+				})
+			} else {
+				erpnext.get_fiscal_year(me.frm.doc.company, me.frm.doc.posting_date);
+			}
+		}
 	},
 
 	get_company_currency: function() {