Skip to content

Commit

Permalink
Secondary Print Format (#209)
Browse files Browse the repository at this point in the history
* fix: customization on split payment entry

* changes to remove pre-commit error

* changes to remove pre-commit error

* new print format Secondery sample

* rename print format

* on header check number added

* cheque number added

* set print format

* payment currency added

* print format changes

* comma saperated on bothe tablec

* commit to solve linter test

* secondary print format with same attechment

* change field name in print format

* split pdf in two attechment

* comment to run lint

* fix: customization on split payment entry

* fix:resolve conflict

* fix: resolve conflict

* Check PDF name changes

---------

Co-authored-by: viralpatel15 <[email protected]>
  • Loading branch information
viralkansodiya and viralpatel15 authored Jun 29, 2024
1 parent 46a084a commit 9eda182
Show file tree
Hide file tree
Showing 5 changed files with 103 additions and 38 deletions.
35 changes: 29 additions & 6 deletions check_run/check_run/doctype/check_run/check_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,9 +272,10 @@ def get_eta(self, current, total, processing_time):

def create_payment_entries(self: Self, transactions: list[frappe._dict]) -> list[frappe._dict]:
settings = get_check_run_settings(self)
split = 5
if settings and settings.number_of_invoices_per_voucher:
split = settings.number_of_invoices_per_voucher
if not settings.secondary_print_format:
split = 5
if settings and settings.number_of_invoices_per_voucher:
split = settings.number_of_invoices_per_voucher
check_count = 0
_transactions = []
gl_account = frappe.get_value("Bank Account", self.bank_account, "account")
Expand All @@ -299,9 +300,12 @@ def create_payment_entries(self: Self, transactions: list[frappe._dict]) -> list
_group = list(__group)
if _group[0].party_type == "Supplier":
supplier_split = frappe.db.get_value("Supplier", party, "number_of_invoices_per_check_voucher")
split = supplier_split if supplier_split else split

if frappe.db.get_value("Mode of Payment", _group[0].mode_of_payment, "type") == "Bank":
if not settings.secondary_print_format:
split = supplier_split if supplier_split else split
if (
frappe.db.get_value("Mode of Payment", _group[0].mode_of_payment, "type") == "Bank"
and not settings.secondary_print_format
):
groups = list(zip_longest(*[iter(_group)] * split))
else:
groups = [_group] # type: ignore
Expand Down Expand Up @@ -433,6 +437,7 @@ def render_check_pdf(self: Self, reprint_check_number: int | None = None) -> Non
if reprint_check_number and reprint_check_number != "undefined":
self.initial_check_number = int(reprint_check_number)
output = PdfFileWriter()
se_print_output = PdfFileWriter()
transactions = json.loads(self.transactions)
check_increment = 0
_transactions = []
Expand All @@ -446,6 +451,14 @@ def render_check_pdf(self: Self, reprint_check_number: int | None = None) -> Non
mode_of_payment, docstatus = frappe.db.get_value(
"Payment Entry", pe, ["mode_of_payment", "docstatus"]
) or (None, None)
se_print_output = frappe.get_print(
"Payment Entry",
pe,
settings.secondary_print_format or frappe.get_meta("Payment Entry").default_print_format,
as_pdf=True,
output=se_print_output,
no_letterhead=0,
)
if docstatus == 1 and frappe.db.get_value("Mode of Payment", mode_of_payment, "type") == "Bank":
output = frappe.get_print(
"Payment Entry",
Expand Down Expand Up @@ -490,6 +503,15 @@ def render_check_pdf(self: Self, reprint_check_number: int | None = None) -> Non
save_file(
f"{self.name}.pdf", read_multi_pdf(output), "Check Run", self.name, "Home/Check Run", False, 0
)
save_file(
f"Chaque {self.name}.pdf",
read_multi_pdf(se_print_output),
"Check Run",
self.name,
"Home/Check Run",
False,
0,
)
frappe.db.commit()
frappe.publish_realtime("reload", "{}", doctype=self.doctype, docname=self.name)

Expand Down Expand Up @@ -875,6 +897,7 @@ def build_nacha_file_from_payment_entries(
return nacha_file


# Comment
@frappe.whitelist()
def get_check_run_settings(doc: CheckRun | str) -> CheckRunSettings:
doc = frappe._dict(json.loads(doc)) if isinstance(doc, str) else doc
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"validate_unique_check_number",
"column_break_9",
"number_of_invoices_per_voucher",
"secondary_print_format",
"split_by_address",
"automatically_release_on_hold_invoices",
"file_preview_threshold",
Expand Down Expand Up @@ -228,6 +229,14 @@
"label": "Validate Unique Check Number"
},
{

"fieldname": "secondary_print_format",
"fieldtype": "Link",
"label": "Secondary Print Format",
"options": "Print Format"
},
{

"default": "No",
"fieldname": "allow_stand_alone_debit_notes",
"fieldtype": "Select",
Expand Down Expand Up @@ -273,4 +282,4 @@
"sort_order": "DESC",
"states": [],
"track_changes": 1
}
}
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"absolute_value": 0,
"align_labels_right": 0,
"creation": "2024-03-06 04:31:54.619036",
"css": "@font-face {\n font-family: 'EntezareZohoor2';\n src: url('fonts/EntezareZohoor2.eot'), url('fonts/EntezareZohoor2.ttf') format('truetype'), url('fonts/EntezareZohoor2.svg') format('svg');\n font-weight: normal;\n font-style: normal;\n}\n\n.print-format {\n\tpadding: 0px;\n}\n@media screen {\n\t.print-format {\n\t\tpadding: 0in;\n\t}\n}\n#payer_check_window_block {\n top: 0.7cm; \n left: 0.7cm;\n height: 2.2cm;\n width: 8.8cm;\n position: absolute;\n \n}\n\n#payer_name_block{\n top: 0.1cm; \n left: 1cm;\n position: absolute;\n}\n\n#payee_address_window_block {\n top:4.9cm;\n left: 1.9cm;\n position: absolute; \n width: 8.8cm; \n height:2.2cm;\n}\n\n#address_block{\n top: 0.2cm; \n left: 0.2cm;\n position: relative;\n}\n\n\n\n#memo_block {\n top:7.1cm;\n left: 2cm;\n position: absolute; \n width: 6cm;\n}\n\n\n#check_section_1 {\n font-size: 15px;\n width:20.0cm;\n height:8.9cm;\n}\n\n#check_section_2 {\n height:8.9cm;\n}\n\n#check_section_3 {\n height:8.9cm;\n}\n\n\n#payer_name_block {\ntext-align: center; \n\n}\n\n#payer_name_block {\nwidth:4cm;\ntext-align: center; \nposition: absolute;\n}\n\n#bank_info_block {\nfont-size: 10px;\nwidth:2.5cm;\nheight:1.8cm;\ntext-align: center; \nposition: absolute;\n}\n\n\n#payment_in_words_block {\n font-size: 13px;\n}\n\n#memo_block {\nfont-size: 10px;\n}\n\n#signature_block {\ncolor: blue;\nfont-family: cursive;\n\n}\n#payment_amount_block{\n top:3.3cm;\n left: 17.6cm;\n\tposition: absolute; \n\tmin-width: 4cm;\n\n}\n\n.payment_reference_block {\npadding-left:1cm; \npadding-right:1cm; \n}\n\n.payment_name_cell {\ntext-align: right; \n}\n\n#payment_amount_number_block {\n top:3.3cm;\n left: 17.6cm;\n\tposition: absolute; \n\tmin-width: 4cm;\n}\n\n\n.right_stamp {\n top:2.8cm;\n left: 16.6cm;\n width: 3cm;\n\theight: 1.5cm;\n\tfont-size: 40px;\n \tfort-weight: bold;\n position: absolute; \n}\n\n.sig_stamp {\n top:6.3cm;\n left: 13.8cm;\n width: 3cm;\n\theight: 1.5cm;\n\tfont-size: 40px;\n \tfort-weight: bold;\n position: absolute; \n}\n\n.big_stamp {\n top:2.8cm;\n left: 6.1cm;\n width: 7cm;\n\theight: 3cm;\n\tfont-size: 80px;\n \tfort-weight: bold;\n position: absolute; \n}\n\n\n.stamp {\n\tmargin: 0px;\n\toverflow: hidden;\n display: flex;\n justify-content: space-around;\n align-items: center;\n vertical-align: middle;\n text-align: center;\n\n flex-direction: row;\n color: #555;\n\tfont-weight: 700;\n\tborder: 0.25rem solid #555;\n\tdisplay: inline-block;\n\t\n\ttext-transform: uppercase;\n\tborder-radius: 1rem;\n\tfont-family: 'Courier';\n\t-webkit-mask-image: url('https://s3-us-west-2.amazonaws.com/s.cdpn.io/8399/grunge.png');\n -webkit-mask-size: 944px 604px;\n mix-blend-mode: multiply;\n}\n\n\n.is-nope {\n color: #ff5858;\n border: 0.5rem double #D23;\n \t-webkit-mask-position: 2rem 3rem;\n \t\n \n}\n\n.is-draft {\n\tcolor: #ff5858;\n\tborder: 1rem double #ff5858;\n font-size: 6rem;\n font-family: \"Open sans\", Helvetica, Arial, sans-serif;\n border-radius: 0;\n padding: 0.5rem;\n} ",
"custom_format": 1,
"default_print_language": "en",
"disabled": 0,
"doc_type": "Payment Entry",
"docstatus": 0,
"doctype": "Print Format",
"font": "Default",
"font_size": 0,
"html": "<table class=\"table table-responsive-sm\">\r\n <tr>\r\n <td colspan=\"4\">\r\n Cheque Number: {{ doc.reference_no or '' }}\r\n </td>\r\n </tr>\r\n <tr>\r\n <td colspan=\"2\">{{doc.party_name}}</td>\r\n <td> {{ frappe.utils.formatdate(doc.reference_date) or '' }} </td>\r\n <td style=\"text-align:right;\" colspan=\"2\"> {{doc.get_formatted(\"base_paid_amount\")}} </td>\r\n <tr>\r\n <th> Date </th>\r\n <th style=\"text-align:left;\"> Reference </th>\r\n <th style=\"text-align:center;\"> Amount </th>\r\n <th style=\"text-align:right;\"> Payment </th>\r\n </tr>\r\n {% for reference in doc.references %}\r\n <tr>\r\n {% if reference.reference_doctype == 'Purchase Invoice' %}\r\n <td>{{ frappe.utils.formatdate(frappe.db.get_value(reference.reference_doctype, reference.reference_name, \"bill_date\")) or \"\"}}</td>\r\n <td style=\"text-align:left;\"> {{ frappe.db.get_value(reference.reference_doctype, reference.reference_name, \"bill_no\") or \"\" }}</td>\r\n {% elif reference.reference_doctype == 'Sales Invoice' %}\r\n <td style=\"text-align:left;\">{{ frappe.utils.formatdate(frappe.db.get_value(reference.reference_doctype, reference.reference_name, \"po_date\")) or \"\"}}</td>\r\n <td style=\"text-align:left;\"> {{ frappe.db.get_value(reference.reference_doctype, reference.reference_name, \"po_no\") or \"\" }}</td>\r\n {% elif reference.reference_doctype == 'Expense Claim' %}\r\n <td style=\"text-align:left;\">{{ frappe.utils.formatdate(frappe.db.get_value(reference.reference_doctype, reference.reference_name, \"posting_date\")) or \"&#160;\"}}</td>\r\n <td style=\"text-align:left;\"> {{ frappe.db.get_value(reference.reference_doctype, reference.reference_name, \"name\") or \"&#160;\" }}</td>\r\n {% elif reference.reference_doctype == 'Journal Entry' %}\r\n <td style=\"text-align:left;\"> {{ frappe.utils.formatdate(frappe.db.get_value(reference.reference_doctype, reference.reference_name, \"posting_date\")) or \"&#160;\"}}</td>\r\n <td style=\"text-align:left;\"> {{ frappe.db.get_value(reference.reference_doctype, reference.reference_name, \"name\") or \"&#160;\" }}</td>\r\n {% endif %}\r\n <td style=\"text-align:center;\"> {{ frappe.utils.fmt_money(reference.get_formatted('total_amount'), 2, 'USD')}}</td>\r\n <td style=\"text-align:right;\"> {{ reference.get_formatted('allocated_amount')}}</td>\r\n </tr>\r\n {% endfor %}\r\n</table>",
"idx": 0,
"line_breaks": 0,
"margin_bottom": 0.0,
"margin_left": 0.0,
"margin_right": 0.0,
"margin_top": 0.0,
"modified": "2024-03-28 01:38:34.472380",
"modified_by": "Administrator",
"module": "Check Run",
"name": "Example Secondary Print Format",
"owner": "Administrator",
"page_number": "Hide",
"print_format_builder": 0,
"print_format_builder_beta": 0,
"print_format_type": "Jinja",
"raw_printing": 0,
"show_section_headings": 0,
"standard": "Yes"
}
Loading

0 comments on commit 9eda182

Please sign in to comment.