minor fixes
diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py
index 2907149..cb65557 100644
--- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py
+++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py
@@ -1100,6 +1100,16 @@
 		for item in self.get('items'):
 			last_gl_entry = False
 
+			booking_end_date = getdate(add_days(today(), -1)) if not end_date else end_date
+			if booking_end_date < item.service_start_date or (item.service_stop_date and booking_end_date.month > item.service_stop_date.month):
+				continue
+			elif booking_end_date>=item.service_end_date:
+				last_gl_entry = True
+				booking_end_date = item.service_end_date
+			elif item.service_stop_date and item.service_stop_date<=booking_end_date:
+				last_gl_entry = True
+				booking_end_date = item.service_stop_date
+
 			booking_start_date = getdate(add_months(today(), -1)) if not start_date else start_date
 			booking_start_date = booking_start_date if booking_start_date>item.service_start_date else item.service_start_date
 
@@ -1115,24 +1125,13 @@
 				else:
 					booking_start_date = getdate(add_days(prev_gl_entry.posting_date, 1))
 
-			booking_end_date = getdate(add_days(today(), -1)) if not end_date else end_date
-			if item.service_stop_date and booking_end_date.month > item.service_stop_date.month:
-				continue
-			elif booking_end_date>=item.service_end_date:
-				last_gl_entry = True
-				booking_end_date = item.service_end_date
-			elif item.service_stop_date and item.service_stop_date<=booking_end_date:
-				last_gl_entry = True
-				booking_end_date = item.service_stop_date
-
 			total_days = date_diff(item.service_end_date, item.service_start_date)
 			total_booking_days = date_diff(booking_end_date, booking_start_date) + 1
 
 			account_currency = get_account_currency(item.income_account)
 			if not last_gl_entry:
-				base_amount = flt(item.base_net_amount*total_booking_days/flt(total_days), item.precision("base_net_amount"))
 				if account_currency==self.company_currency:
-					amount = base_amount
+					amount = flt(item.base_net_amount*total_booking_days/flt(total_days), item.precision("base_net_amount"))
 				else:
 					amount = flt(item.net_amount*total_booking_days/flt(total_days), item.precision("net_amount"))
 			else:
@@ -1141,9 +1140,9 @@
 					from `tabGL Entry` where company=%s and account=%s and voucher_type=%s and voucher_no=%s and voucher_detail_no=%s
 					group by voucher_detail_no
 				''', (self.company, item.deferred_revenue_account, "Sales Invoice", self.name, item.name), as_dict=True)[0]
-				base_amount = flt(item.base_net_amount - gl_entries_details.total_debit, item.precision("base_net_amount"))
+
 				if account_currency==self.company_currency:
-					amount = base_amount
+					amount = flt(item.base_net_amount - gl_entries_details.total_debit, item.precision("base_net_amount"))
 				else:
 					amount = flt(item.net_amount - gl_entries_details.total_debit_in_account_currency, item.precision("net_amount"))