[fix] demo and process payroll for demo (#7224)

* [fix] demo and process payroll for demo

* [fix] set payroll dates
diff --git a/erpnext/accounts/utils.py b/erpnext/accounts/utils.py
index cec01a0..8e59d8f 100644
--- a/erpnext/accounts/utils.py
+++ b/erpnext/accounts/utils.py
@@ -110,7 +110,7 @@
 	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)))
 
@@ -178,7 +178,7 @@
 				voucher_type, voucher_no, against_voucher_type, against_voucher
 			FROM `tabGL Entry` gle
 			WHERE {0}""".format(" and ".join(cond)), as_dict=True)
-		
+
 		count = 0
 		for gle in entries:
 			if fieldname not in ('invoiced_amount','payables'):
@@ -196,12 +196,12 @@
 						WHERE docstatus < 2 and posting_date <= %(date)s and against_voucher = %(voucher_no)s
 						and party = %(party)s and name != %(name)s""".format(select_fields),
 						{"date": date, "voucher_no": gle.voucher_no, "party": gle.party, "name": gle.name})[0][0]
-					
+
 					outstanding_amount = flt(gle.get(dr_or_cr)) - flt(gle.get(cr_or_dr)) - payment_amount
 					currency_precision = get_currency_precision() or 2
 					if abs(flt(outstanding_amount)) > 0.1/10**currency_precision:
 						count += 1
-					
+
 		return count
 
 @frappe.whitelist()
@@ -209,7 +209,7 @@
 	if not args:
 		args = frappe.local.form_dict
 		args.pop("cmd")
-	
+
 	ac = frappe.new_doc("Account")
 
 	if args.get("ignore_permissions"):
@@ -220,7 +220,7 @@
 
 	if not ac.parent_account:
 		ac.parent_account = args.get("parent")
-	
+
 	ac.old_parent = ""
 	ac.freeze_account = "No"
 	if cint(ac.get("is_root")):
@@ -252,10 +252,10 @@
 		Cancel JV, Update aginst document, split if required and resubmit jv
 	"""
 	for d in args:
-		
-		check_if_advance_entry_modified(d)			
+
+		check_if_advance_entry_modified(d)
 		validate_allocated_amount(d)
-		
+
 		# cancel advance entry
 		doc = frappe.get_doc(d.voucher_type, d.voucher_no)
 
@@ -289,13 +289,13 @@
 	else:
 		party_account_field = "paid_from" if args.party_type == "Customer" else "paid_to"
 		if args.voucher_detail_no:
-			ret = frappe.db.sql("""select t1.name 			
-				from `tabPayment Entry` t1, `tabPayment Entry Reference` t2 
+			ret = frappe.db.sql("""select t1.name
+				from `tabPayment Entry` t1, `tabPayment Entry Reference` t2
 				where
-					t1.name = t2.parent and t1.docstatus = 1 
+					t1.name = t2.parent and t1.docstatus = 1
 					and t1.name = %(voucher_no)s and t2.name = %(voucher_detail_no)s
 					and t1.party_type = %(party_type)s and t1.party = %(party)s and t1.{0} = %(account)s
-					and t2.reference_doctype in ("", "Sales Order", "Purchase Order") 
+					and t2.reference_doctype in ("", "Sales Order", "Purchase Order")
 					and t2.allocated_amount = %(unadjusted_amount)s
 			""".format(party_account_field), args)
 		else:
@@ -367,7 +367,7 @@
 	# will work as update after submit
 	jv_obj.flags.ignore_validate_update_after_submit = True
 	jv_obj.save(ignore_permissions=True)
-	
+
 def update_reference_in_payment_entry(d, payment_entry):
 	reference_details = {
 		"reference_doctype": d.against_voucher_type,
@@ -377,44 +377,44 @@
 		"allocated_amount": d.allocated_amount,
 		"exchange_rate": d.exchange_rate
 	}
-		
+
 	if d.voucher_detail_no:
 		existing_row = payment_entry.get("references", {"name": d["voucher_detail_no"]})[0]
 		original_row = existing_row.as_dict().copy()
 		existing_row.update(reference_details)
-		
+
 		if d.allocated_amount < original_row.allocated_amount:
 			new_row = payment_entry.append("references")
 			new_row.docstatus = 1
 			for field in reference_details.keys():
 				new_row.set(field, original_row[field])
-			
+
 			new_row.allocated_amount = original_row.allocated_amount - d.allocated_amount
 	else:
 		new_row = payment_entry.append("references")
 		new_row.docstatus = 1
 		new_row.update(reference_details)
-		
+
 	payment_entry.flags.ignore_validate_update_after_submit = True
 	payment_entry.setup_party_account_field()
 	payment_entry.set_missing_values()
 	payment_entry.set_amounts()
 	payment_entry.save(ignore_permissions=True)
-	
+
 def unlink_ref_doc_from_payment_entries(ref_doc):
 	remove_ref_doc_link_from_jv(ref_doc.doctype, ref_doc.name)
 	remove_ref_doc_link_from_pe(ref_doc.doctype, ref_doc.name)
-	
+
 	frappe.db.sql("""update `tabGL Entry`
 		set against_voucher_type=null, against_voucher=null,
 		modified=%s, modified_by=%s
 		where against_voucher_type=%s and against_voucher=%s
 		and voucher_no != ifnull(against_voucher, '')""",
 		(now(), frappe.session.user, ref_doc.doctype, ref_doc.name))
-	
+
 	if ref_doc.doctype in ("Sales Invoice", "Purchase Invoice"):
 		ref_doc.set("advances", [])
-	
+
 		frappe.db.sql("""delete from `tab{0} Advance` where parent = %s"""
 			.format(ref_doc.doctype), ref_doc.name)
 
@@ -430,7 +430,7 @@
 			and docstatus < 2""", (now(), frappe.session.user, ref_type, ref_no))
 
 		frappe.msgprint(_("Journal Entries {0} are un-linked".format("\n".join(linked_jv))))
-		
+
 def remove_ref_doc_link_from_pe(ref_type, ref_no):
 	linked_pe = frappe.db.sql_list("""select parent from `tabPayment Entry Reference`
 		where reference_doctype=%s and reference_name=%s and docstatus < 2""", (ref_type, ref_no))
@@ -440,18 +440,18 @@
 			set allocated_amount=0, modified=%s, modified_by=%s
 			where reference_doctype=%s and reference_name=%s
 			and docstatus < 2""", (now(), frappe.session.user, ref_type, ref_no))
-			
+
 		for pe in linked_pe:
 			pe_doc = frappe.get_doc("Payment Entry", pe)
 			pe_doc.set_total_allocated_amount()
 			pe_doc.set_unallocated_amount()
 			pe_doc.clear_unallocated_reference_document_rows()
-			
-			frappe.db.sql("""update `tabPayment Entry` set total_allocated_amount=%s, 
-				base_total_allocated_amount=%s, unallocated_amount=%s, modified=%s, modified_by=%s 
-				where name=%s""", (pe_doc.total_allocated_amount, pe_doc.base_total_allocated_amount, 
+
+			frappe.db.sql("""update `tabPayment Entry` set total_allocated_amount=%s,
+				base_total_allocated_amount=%s, unallocated_amount=%s, modified=%s, modified_by=%s
+				where name=%s""", (pe_doc.total_allocated_amount, pe_doc.base_total_allocated_amount,
 					pe_doc.unallocated_amount, now(), frappe.session.user, pe))
-		
+
 		frappe.msgprint(_("Payment Entries {0} are un-linked".format("\n".join(linked_pe))))
 
 @frappe.whitelist()
@@ -562,7 +562,7 @@
 		from
 			`tabGL Entry` invoice_gl_entry
 		where
-			party_type = %(party_type)s and party = %(party)s 
+			party_type = %(party_type)s and party = %(party)s
 			and account = %(account)s and {dr_or_cr} > 0
 			{condition}
 			and ((voucher_type = 'Journal Entry'
@@ -590,9 +590,9 @@
 			'outstanding_amount': flt(d.invoice_amount - d.payment_amount, precision),
 			'due_date': frappe.db.get_value(d.voucher_type, d.voucher_no, "due_date"),
 		}))
-		
+
 	outstanding_invoices = sorted(outstanding_invoices, key=lambda k: k['due_date'] or getdate(nowdate()))
-	
+
 	return outstanding_invoices