payment entry fixes
diff --git a/erpnext/accounts/doctype/journal_entry/journal_entry.py b/erpnext/accounts/doctype/journal_entry/journal_entry.py
index 96b95f9..6f25220 100644
--- a/erpnext/accounts/doctype/journal_entry/journal_entry.py
+++ b/erpnext/accounts/doctype/journal_entry/journal_entry.py
@@ -519,7 +519,7 @@
 
 			if (d.party_type, d.party) not in party_balance:
 				party_balance[(d.party_type, d.party)] = get_balance_on(party_type=d.party_type,
-					party=d.party, date=self.posting_date)
+					party=d.party, date=self.posting_date, company=self.company)
 
 			d.account_balance = account_balance[d.account]
 			d.party_balance = party_balance[(d.party_type, d.party)]
@@ -553,6 +553,7 @@
 			"account_currency": account_details.account_currency,
 			"account_type": account_details.account_type
 		})
+	else: return frappe._dict()
 
 @frappe.whitelist()
 def get_payment_entry_against_order(dt, dn, amount=None, debit_in_account_currency=None, journal_entry=False, bank_account=None):
@@ -754,7 +755,7 @@
 	account = get_party_account(party_type, party, company)
 
 	account_balance = get_balance_on(account=account)
-	party_balance = get_balance_on(party_type=party_type, party=party)
+	party_balance = get_balance_on(party_type=party_type, party=party, company=company)
 
 	return {
 		"account": account,
diff --git a/erpnext/accounts/doctype/payment_entry/payment_entry.py b/erpnext/accounts/doctype/payment_entry/payment_entry.py
index 5ed14d5..28978cd 100644
--- a/erpnext/accounts/doctype/payment_entry/payment_entry.py
+++ b/erpnext/accounts/doctype/payment_entry/payment_entry.py
@@ -77,7 +77,7 @@
 		if self.party:
 			if not self.party_balance:
 				self.party_balance = get_balance_on(party_type=self.party_type,
-					party=self.party, date=self.posting_date)
+					party=self.party, date=self.posting_date, company=self.company)
 			
 			if not self.party_account:
 				party_account = get_party_account(self.party_type, self.party, self.company)
@@ -251,7 +251,7 @@
 				self.unallocated_amount = party_amount - self.total_allocated_amount
 				
 	def set_difference_amount(self):
-		base_unallocated_amount = self.unallocated_amount * \
+		base_unallocated_amount = flt(self.unallocated_amount) * \
 			(self.source_exchange_rate if self.payment_type=="Receive" else self.target_exchange_rate)
 			
 		base_party_amount = flt(self.base_total_allocated_amount) + flt(base_unallocated_amount)
@@ -669,9 +669,10 @@
 		"outstanding_amount": outstanding_amount,
 		"allocated_amount": outstanding_amount
 	})
-	
+
 	pe.setup_party_account_field()
 	pe.set_missing_values()
-	pe.set_exchange_rate()
-	pe.set_amounts()
+	if bank:
+		pe.set_exchange_rate()
+		pe.set_amounts()
 	return pe
\ No newline at end of file
diff --git a/erpnext/accounts/utils.py b/erpnext/accounts/utils.py
index 2d1b2db..635197f 100644
--- a/erpnext/accounts/utils.py
+++ b/erpnext/accounts/utils.py
@@ -53,7 +53,7 @@
 			throw(_("{0} '{1}' not in Fiscal Year {2}").format(label, formatdate(date), fiscal_year))
 
 @frappe.whitelist()
-def get_balance_on(account=None, date=None, party_type=None, party=None, in_account_currency=True):
+def get_balance_on(account=None, date=None, party_type=None, party=None, company=None, in_account_currency=True):
 	if not account and frappe.form_dict.get("account"):
 		account = frappe.form_dict.get("account")
 	if not date and frappe.form_dict.get("date"):
@@ -110,6 +110,9 @@
 	if party_type and party:
 		cond.append("""gle.party_type = "%s" and gle.party = "%s" """ %
 			(frappe.db.escape(party_type), frappe.db.escape(party, percent=False)))
+			
+	if company:
+		cond.append("""gle.company = "%s" """ % (frappe.db.escape(company, percent=False)))
 
 	if account or (party_type and party):
 		if in_account_currency: