How to create page break under customer print format

hi,

How can I limit item under table to 4 row and page break to second page with existing page header? Include page number
Besides that, I facing the issue for the doc.terms fields which having some format issue and cause entire custom print format run out.


My custom print template

{%- macro add_header(page_num, max_pages, doc, letter_head, no_letterhead) -%}
{% if letter_head and not no_letterhead %}

{{ letter_head }}

{% endif %}
{%- if doc.meta.is_submittable and doc.docstatus==0-%}

{{ _(“DRAFT”) }}


{%- endif -%}
{%- if doc.meta.is_submittable and doc.docstatus==2-%}

{{ _(“CANCELLED”) }}


{%- endif -%}
{% if max_pages > 1 %}

{{ _(“Page #{0} of {1}”).format(page_num, max_pages) }}


{% endif %}
{%- endmacro -%}

{{ add_header(0,1,doc,letter_head, no_letterhead) }}

{{ _("PROFORMA INVOICE") }}


To:
{{ doc.customer }}
Billing Address:
{{ doc.address_display }}
Delivery Place:
{{ doc.shipping_address }}
<div class="col-xs-5">
    <div class="row">
        <div class="col-xs-5 text-left"><label>Our No:</label></div>
        <div class="col-xs-7 ">{{ doc.name }} </div>
    </div>
    <div class="row">
        <div class="col-xs-5 text-left"> <label>Document Date:</label></div>
        <div class="col-xs-7 "> {{ doc.get_formatted("transaction_date") or ''}} </div>
    </div>
    <div class="row">
        <div class="col-xs-5 text-left"><label>Int.No:</label></div>
       <div class="col-xs-7 ">{{ doc.excel_po_no or '' }} </div>
    </div>
    <div class="row">
        <div class="col-xs-5 text-left"><label>Buyer:</label></div>
        <div class="col-xs-7 ">{{ doc.buyer or ''}} </div>
    </div>
    <div class="row">
        <div class="col-xs-5 text-left"><label>Ref PO:</label></div>
        <div class="col-xs-7 ">{{ doc.po_no or ''}} </div>
    </div>
    <div class="row">
        <div class="col-xs-5 text-left"><label>Style:</label></div>
        <div class="col-xs-7 ">{{ doc.style or ''}} </div>
    </div>
    <div class="row">
        <div class="col-xs-5 text-left"><label>Season:</label></div>
        <div class="col-xs-7 ">{{ doc.season or ''}} </div>
    </div>
    <div class="row">
        <div class="col-xs-5 text-left"><label>Payment Terms:</label></div>
        <div class="col-xs-7 ">{{ doc.terms_payment or ''}} </div>
    </div>
    <div class="row">
        <div class="col-xs-5 text-left"><label>Shipment Terms:</label></div>
        <div class="col-xs-7 ">{{ doc.term_of_prices or '' }} </div>
    </div>
</div>

{%- for row in doc.items -%} {%- endfor -%}
No Item Code Description Del. Date Qty Rate Amount
{{ row.idx }} {{ row.item_code }} {{ row.item_name }}
{%- if row.weight -%} Weight : {{ row.weight or '' }} GM/M2
{% endif %} {%- if row.spec1 -%} {{ row.spec1 or '' }} Weight : {{ row.spec_1_data or '' }} GM/M2
{% endif %} {%- if row.width -%} Width : {{ row.width or '' }}
{% endif %} {%- if row.colorway -%} Colorway : {{ row.colorway or '' }}
{% endif %} {%- if row.add_remarks -%} *{{ row.add_remarks or '' }}
{% endif %}
{{ row.get_formatted("schedule_date") or ''}} {{ row.qty }} {{ row.uom or row.stock_uom }} {{ row.get_formatted("rate", doc) }} {{ row.get_formatted("amount", doc) }}
{%- if doc.discount_amount -%} {%- endif -%} {%- for row in doc.taxes -%} {%- if not row.included_in_print_rate -%} {%- endif -%} {%- endfor -%}
{{ _("Sub Total") }} {{ doc.currency or ''}} {{ doc.get_formatted("total") }}
{{ _("Discount") }} {{ doc.currency or ''}} ({{ doc.get_formatted("discount_amount") }})
{{ "GST @ 7%" }} {{ doc.currency or ''}} {{ row.get_formatted("tax_amount", doc) }}
{{ _("Grand Total") }} {{ doc.currency or ''}} {{ doc.get_formatted("grand_total") }}
{% if doc.get("taxes", filters={"included_in_print_rate": 1}) %}

Taxes Included:

{%- for row in doc.taxes -%} {%- if row.included_in_print_rate -%} {%- endif -%} {%- endfor -%}
{{ row.description }} {{ row.get_formatted("tax_amount_after_discount_amount", doc) }}
{%- endif -%}

{% if doc.terms %} {{ _("Remark") }}: {{ doc.terms or "" }} {%- endif -%}

LC Bank Detail:

HANG SENG BANK LIMITED

ADDRESS: 83 DES VEOUX ROAD, CENTRAL HK

SWIFT CODE :HASEHKHH

BANK CODE: 024

TRADE ACCOUNT: 228847521

TT Bank Details:

SJ PTE LIMITED BANK NAME: HANGSENG BANK

BANK CODE: 024

SWIFT CODE: HASEHKHH

ACCOUNT NO: 774513477883

SJ PTE LIMITED

<img src="/files/Sign2.png"

________________________________

Please Chop & Sign

{{ doc.customer }}







________________________________

Please Chop & Sign

{% if not no_letterhead and footer %}
{{ footer }}
{% endif %}

{{ _("Page {0} of {1}").format('', '') }}

To force a page break, you can use

<div class="page-break"></div>

You can combine your items loop with a counter which will insert a page-break after every 4 items. Header and footer should be normally defined, then they will repeat on each page, e.g. like this

<!-- HEAD -->
<div id="header-html" class="hidden-pdf">
  {% set letter_head = frappe.get_doc("Letter Head", "Standard") %}
  {% if letter_head %}
	{{ letter_head.content }}
  {% else %}
	<p>Letter head Standard not found. Please define the letter head under print settings.</p>
  {% endif %}
</div>

and

<!-- page footer -->
<div id="footer-html" class="visible-pdf">
  {% if letter_head %}
	{{ letter_head.footer }}
  {% else %}
	<p>No letter head found. Please define a letter head under print settings and mark it as default</p>
  {% endif %}
  <p style="font-size: 6pt !important; text-align: right">
	{{ _("Page") }} <span class="page"></span> {{ _("of") }} <span class="topage"></span>
  </p>
</div>

As for the format issues of the doc.terms, I am not quite sure what they are. Maybe a screenshot might help…

1 Like

Thanks Lasalesi for the reply.
As my colleagues have left the company and i’m not ideas how this custom print template been build. possible to guide me how to input the page break under the code?

here the entire template quote:

{%- macro add_header(page_num, max_pages, doc, letter_head, no_letterhead) -%}
{% if letter_head and not no_letterhead %}

{{ letter_head }}

{% endif %}
{%- if doc.meta.is_submittable and doc.docstatus==0-%}

{{ _(“DRAFT”) }}


{%- endif -%}
{%- if doc.meta.is_submittable and doc.docstatus==2-%}

{{ _(“CANCELLED”) }}


{%- endif -%}
{% if max_pages > 1 %}

{{ _(“Page #{0} of {1}”).format(page_num, max_pages) }}


{% endif %}
{%- endmacro -%}

{{ add_header(0,1,doc,letter_head, no_letterhead) }}

{{ _("PROFORMA INVOICE") }}


To:
{{ doc.customer }}
Billing Address:
{{ doc.address_display }}
Delivery Place:
{{ doc.shipping_address }}
<div class="col-xs-5">
    <div class="row">
        <div class="col-xs-5 text-left"><label>Our No:</label></div>
        <div class="col-xs-7 ">{{ doc.name }} </div>
    </div>
    <div class="row">
        <div class="col-xs-5 text-left"> <label>Document Date:</label></div>
        <div class="col-xs-7 "> {{ doc.get_formatted("transaction_date") or ''}} </div>
    </div>
    <div class="row">
        <div class="col-xs-5 text-left"><label>Int.No:</label></div>
        <div class="col-xs-7 ">{{ doc.excel_po_no or '' }} </div>
    </div>
    <div class="row">
        <div class="col-xs-5 text-left"><label>Buyer:</label></div>
        <div class="col-xs-7 ">{{ doc.buyer or ''}} </div>
    </div>
    <div class="row">
        <div class="col-xs-5 text-left"><label>Ref PO:</label></div>
        <div class="col-xs-7 ">{{ doc.po_no or ''}} </div>
    </div>
    <div class="row">
        <div class="col-xs-5 text-left"><label>Style:</label></div>
        <div class="col-xs-7 ">{{ doc.style or ''}} </div>
    </div>
    <div class="row">
        <div class="col-xs-5 text-left"><label>Season:</label></div>
        <div class="col-xs-7 ">{{ doc.season or ''}} </div>
    </div>
    <div class="row">
        <div class="col-xs-5 text-left"><label>Payment Terms:</label></div>
        <div class="col-xs-7 ">{{ doc.terms_payment or ''}} </div>
    </div>
    <div class="row">
        <div class="col-xs-5 text-left"><label>Shipment Terms:</label></div>
        <div class="col-xs-7 ">{{ doc.term_of_prices or '' }} </div>
    </div>
</div>

—> TABLE
table class=“table table-bordered”>


No
Item Code
Description
Del. Date
Qty
Rate
Amount

{%- for row in doc.items -%}

{{ row.idx }}
{{ row.item_code }}
{{ row.item_name }}

{%- if row.weight -%}
Weight : {{ row.weight or ‘’ }} GM/M2

{% endif %}
{%- if row.spec1 -%}
{{ row.spec1 or ‘’ }} Weight : {{ row.spec_1_data or ‘’ }} GM/M2

{% endif %}
{%- if row.width -%}
Width : {{ row.width or ‘’ }}

{% endif %}
{%- if row.colorway -%}
Colorway : {{ row.colorway or ‘’ }}

{% endif %}
{%- if row.add_remarks -%}
*{{ row.add_remarks or ‘’ }}

{% endif %}


{{ row.get_formatted(“schedule_date”) or ‘’}}
{{ row.qty }} {{ row.uom or row.stock_uom }}
{{ row.get_formatted(“rate”, doc) }}
{{ row.get_formatted(“amount”, doc) }}

{%- endfor -%}

{%- if doc.discount_amount -%} {%- endif -%} {%- for row in doc.taxes -%} {%- if not row.included_in_print_rate -%} {%- endif -%} {%- endfor -%}
{{ _("Sub Total") }} {{ doc.currency or ''}} {{ doc.get_formatted("total") }}
{{ _("Discount") }} {{ doc.currency or ''}} ({{ doc.get_formatted("discount_amount") }})
{{ "GST @ 7%" }} {{ doc.currency or ''}} {{ row.get_formatted("tax_amount", doc) }}
{{ _("Grand Total") }} {{ doc.currency or ''}} {{ doc.get_formatted("grand_total") }}
{% if doc.get("taxes", filters={"included_in_print_rate": 1}) %}

Taxes Included:

{%- for row in doc.taxes -%} {%- if row.included_in_print_rate -%} {%- endif -%} {%- endfor -%}
{{ row.description }} {{ row.get_formatted("tax_amount_after_discount_amount", doc) }}
{%- endif -%}

{% if doc.terms %} {{ _("Remark") }}: {{ doc.terms or "" }} {%- endif -%}

LC Bank Detail:

HANG SENG BANK LIMITED

ADDRESS: HK

SWIFT CODE :HASEHKHH

BANK CODE: 024

TRADE ACCOUNT:

TT Bank Details:

BANK NAME: BANK

BANK CODE:1111

SWIFT CODE: HASEHKHH

ACCOUNT NO:

SJ PTE LIMITED

<img src="/files/Sign2.png"

________________________________

Please Chop & Sign

{{ doc.customer }}







________________________________

Please Chop & Sign

{% if not no_letterhead and footer %}
{{ footer }}
{% endif %}

{{ _("Page {0} of {1}").format('', '') }}

here how term and condition look

how can i do that ???
You can combine your items loop with a counter which will insert a page-break after every 4 items. Header and footer should be normally defined, then they will repeat on each page

Did you get an answer to this?