Merge pull request #25699 from Anuja-pawar/fix_process_statement_report

fix: Process Statement of Accounts formatting
diff --git a/erpnext/accounts/doctype/process_statement_of_accounts/process_statement_of_accounts.html b/erpnext/accounts/doctype/process_statement_of_accounts/process_statement_of_accounts.html
index f61aacb..db1fea1 100644
--- a/erpnext/accounts/doctype/process_statement_of_accounts/process_statement_of_accounts.html
+++ b/erpnext/accounts/doctype/process_statement_of_accounts/process_statement_of_accounts.html
@@ -1,24 +1,43 @@
-<h1 class="text-center" style="page-break-before:always">{{ filters.party[0] }}</h1>
-<h3 class="text-center">{{ _("Statement of Accounts") }}</h3>
+<div class="page-break">
+	<div id="header-html" class="hidden-pdf">
+		{% if letter_head %}
+		<div class="letter-head text-center">{{ letter_head.content }}</div>
+		<hr style="height:2px;border-width:0;color:black;background-color:black;">
+		{% endif %}
+	</div>
+	<div id="footer-html" class="visible-pdf">
+		{% if letter_head.footer %}
+		<div class="letter-head-footer">
+			<hr style="border-width:0;color:black;background-color:black;padding-bottom:2px;">
+			{{ letter_head.footer }}
+		</div>
+		{% endif %}
+	</div>
 
-<h5 class="text-center">
-    {{ frappe.format(filters.from_date, 'Date')}}
-	{{ _("to") }}
-	{{ frappe.format(filters.to_date, 'Date')}}
-</h5>
+	<h2 class="text-center">{{ _("STATEMENTS OF ACCOUNTS") }}</h2>
+	<div>
+		<h5 style="float: left;">{{ _("Customer: ") }} <b>{{filters.party[0] }}</b></h5>
+		<h5 style="float: right;">
+			{{ _("Date: ") }}
+			<b>{{ frappe.format(filters.from_date, 'Date')}}
+			{{ _("to") }}
+			{{ frappe.format(filters.to_date, 'Date')}}</b>
+			</h5>
+	</div>
+	<br>
 
-<table class="table table-bordered">
-	<thead>
-		<tr>
-			<th style="width: 12%">{{ _("Date") }}</th>
-			<th style="width: 15%">{{ _("Ref") }}</th>
-			<th style="width: 25%">{{ _("Party") }}</th>
-			<th style="width: 15%">{{ _("Debit") }}</th>
-			<th style="width: 15%">{{ _("Credit") }}</th>
-			<th style="width: 18%">{{ _("Balance (Dr - Cr)") }}</th>
-		</tr>
-	</thead>
-	<tbody>
+	<table class="table table-bordered">
+		<thead>
+			<tr>
+				<th style="width: 12%">{{ _("Date") }}</th>
+				<th style="width: 15%">{{ _("Reference") }}</th>
+				<th style="width: 25%">{{ _("Remarks") }}</th>
+				<th style="width: 15%">{{ _("Debit") }}</th>
+				<th style="width: 15%">{{ _("Credit") }}</th>
+				<th style="width: 18%">{{ _("Balance (Dr - Cr)") }}</th>
+			</tr>
+		</thead>
+		<tbody>
 		{% for row in data %}
 			<tr>
 			{% if(row.posting_date) %}
@@ -58,32 +77,34 @@
 			</tr>
 		{% endfor %}
 		</tbody>
-</table>
-<br><br>
-{% if ageing %}
-<h3 class="text-center">{{ _("Ageing Report Based On ") }} {{ ageing.ageing_based_on }}</h3>
-<h5 class="text-center">
-	{{ _("Up to " ) }}  {{ frappe.format(filters.to_date, 'Date')}}
-</h5>
-<br>
-
-<table class="table table-bordered">
-	<thead>
-		<tr>
-			<th style="width: 12%">30 Days</th>
-			<th style="width: 15%">60 Days</th>
-			<th style="width: 25%">90 Days</th>
-			<th style="width: 15%">120 Days</th>
-		</tr>
-	</thead>
-	<tbody>
-		<tr>
-			<td>{{ frappe.utils.fmt_money(ageing.range1, currency=filters.presentation_currency) }}</td>
-			<td>{{ frappe.utils.fmt_money(ageing.range2, currency=filters.presentation_currency) }}</td>
-			<td>{{ frappe.utils.fmt_money(ageing.range3, currency=filters.presentation_currency) }}</td>
-			<td>{{ frappe.utils.fmt_money(ageing.range4, currency=filters.presentation_currency) }}</td>
-		</tr>
-	</tbody>
-</table>
-{% endif %}
-<p class="text-right text-muted">Printed On {{ frappe.format(frappe.utils.get_datetime(), 'Datetime') }}</p>
\ No newline at end of file
+	</table>
+	<br>
+	{% if ageing %}
+	<h4 class="text-center">{{ _("Ageing Report based on ") }} {{ ageing.ageing_based_on }}
+		{{ _("up to " ) }}  {{ frappe.format(filters.to_date, 'Date')}}
+	</h4>
+	<table class="table table-bordered">
+		<thead>
+			<tr>
+				<th style="width: 25%">30 Days</th>
+				<th style="width: 25%">60 Days</th>
+				<th style="width: 25%">90 Days</th>
+				<th style="width: 25%">120 Days</th>
+			</tr>
+		</thead>
+		<tbody>
+			<tr>
+				<td>{{ frappe.utils.fmt_money(ageing.range1, currency=filters.presentation_currency) }}</td>
+				<td>{{ frappe.utils.fmt_money(ageing.range2, currency=filters.presentation_currency) }}</td>
+				<td>{{ frappe.utils.fmt_money(ageing.range3, currency=filters.presentation_currency) }}</td>
+				<td>{{ frappe.utils.fmt_money(ageing.range4, currency=filters.presentation_currency) }}</td>
+			</tr>
+		</tbody>
+	</table>
+	{% endif %}
+	{% if terms_and_conditions %}
+	<div>
+		{{ terms_and_conditions }}
+	</div>
+	{% endif %}
+</div>
diff --git a/erpnext/accounts/doctype/process_statement_of_accounts/process_statement_of_accounts.json b/erpnext/accounts/doctype/process_statement_of_accounts/process_statement_of_accounts.json
index 4be0e2e..922f636 100644
--- a/erpnext/accounts/doctype/process_statement_of_accounts/process_statement_of_accounts.json
+++ b/erpnext/accounts/doctype/process_statement_of_accounts/process_statement_of_accounts.json
@@ -1,6 +1,5 @@
 {
  "actions": [],
- "allow_workflow": 1,
  "autoname": "Prompt",
  "creation": "2020-05-22 16:46:18.712954",
  "doctype": "DocType",
@@ -28,9 +27,11 @@
   "customers",
   "preferences",
   "orientation",
-  "section_break_14",
   "include_ageing",
   "ageing_based_on",
+  "section_break_14",
+  "letter_head",
+  "terms_and_conditions",
   "section_break_1",
   "enable_auto_email",
   "section_break_18",
@@ -270,10 +271,22 @@
    "fieldname": "body",
    "fieldtype": "Text Editor",
    "label": "Body"
+  },
+  {
+   "fieldname": "letter_head",
+   "fieldtype": "Link",
+   "label": "Letter Head",
+   "options": "Letter Head"
+  },
+  {
+   "fieldname": "terms_and_conditions",
+   "fieldtype": "Link",
+   "label": "Terms and Conditions",
+   "options": "Terms and Conditions"
   }
  ],
  "links": [],
- "modified": "2020-08-08 08:47:09.185728",
+ "modified": "2021-05-13 12:44:19.574844",
  "modified_by": "Administrator",
  "module": "Accounts",
  "name": "Process Statement Of Accounts",
diff --git a/erpnext/accounts/doctype/process_statement_of_accounts/process_statement_of_accounts.py b/erpnext/accounts/doctype/process_statement_of_accounts/process_statement_of_accounts.py
index a0dbff3..cf79c03 100644
--- a/erpnext/accounts/doctype/process_statement_of_accounts/process_statement_of_accounts.py
+++ b/erpnext/accounts/doctype/process_statement_of_accounts/process_statement_of_accounts.py
@@ -64,6 +64,9 @@
 		tax_id = frappe.get_doc('Customer', entry.customer).tax_id
 		presentation_currency = get_party_account_currency('Customer', entry.customer, doc.company) \
 				or doc.currency or get_company_currency(doc.company)
+		if doc.letter_head:
+			from frappe.www.printview import get_letter_head
+			letter_head = get_letter_head(doc, 0)
 
 		filters= frappe._dict({
 			'from_date': doc.from_date,
@@ -91,8 +94,10 @@
 			continue
 
 		html = frappe.render_template(template_path, \
-			{"filters": filters, "data": res, "ageing": ageing[0] if (doc.include_ageing and ageing) else None})
-
+			{"filters": filters, "data": res, "ageing": ageing[0] if doc.include_ageing else None,
+				"letter_head": letter_head if doc.letter_head else None,
+				"terms_and_conditions": frappe.db.get_value('Terms and Conditions', doc.terms_and_conditions, 'terms')
+					if doc.terms_and_conditions else None})
 		html = frappe.render_template(base_template_path, {"body": html, \
 			"css": get_print_style(), "title": "Statement For " + entry.customer})
 		statement_dict[entry.customer] = html