validation for stop date added
diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.js b/erpnext/accounts/doctype/sales_invoice/sales_invoice.js
index 194c364..32195dd 100644
--- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.js
+++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.js
@@ -740,6 +740,26 @@
 	}
 })
 
+frappe.ui.form.on('Sales Invoice Item', {
+	service_stop_date: function(frm, cdt, cdn) {
+		var child = locals[cdt][cdn];
+
+		if(child.service_stop_date) {
+			let start_date = Date.parse(child.service_start_date);
+			let end_date = Date.parse(child.service_end_date);
+			let stop_date = Date.parse(child.service_stop_date);
+
+			if(stop_date < start_date) {
+				frappe.model.set_value(cdt, cdn, "service_stop_date", "");
+				frappe.throw(__("Service Stop Date cannot be before Service Start Date"));
+			} else if (stop_date > end_date) {
+				frappe.model.set_value(cdt, cdn, "service_stop_date", "");
+				frappe.throw(__("Service Stop Date cannot be after Service End Date"));
+			}
+		}
+	}
+})
+
 var calculate_total_billing_amount =  function(frm) {
 	var doc = frm.doc;
 
diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py
index fd77d4b..1623227 100644
--- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py
+++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py
@@ -89,6 +89,9 @@
 			self.update_current_stock()
 			self.validate_delivery_note()
 
+		# validate service stop date to lie in between start and end date
+		self.validate_service_stop_date()
+
 		if not self.is_opening:
 			self.is_opening = 'No'
 
@@ -530,6 +533,16 @@
 				if frappe.db.get_value("Sales Order Item", item.so_detail, "delivered_by_supplier"):
 					frappe.throw(_("Could not update stock, invoice contains drop shipping item."))
 
+	def validate_service_stop_date(self):
+		frappe.errprint("here")
+		for item in self.items:
+			print(date_diff(item.service_stop_date, item.service_start_date))
+			if item.enable_deferred_revenue:
+				if date_diff(item.service_stop_date, item.service_start_date) < 0:
+					frappe.throw(_("Service Stop Date cannot be before Service Start Date"))
+				elif date_diff(item.service_stop_date, item.service_end_date) > 0:
+					frappe.throw(_("Service Stop Date cannot be after Service End Date"))
+
 	def update_current_stock(self):
 		for d in self.get('items'):
 			if d.item_code and d.warehouse: