diff --git a/README.md b/README.md index 86a0bfa..a544adf 100644 --- a/README.md +++ b/README.md @@ -20,6 +20,17 @@ file overrides the upstream Thai for the standard labels the print formats show. print formats embed Sarabun (`public/fonts`, OFL) so PDFs render Thai on servers without a Thai system font. Switch a user or the print language to `th` to use it. +### Withholding tax certificate + +A Purchase Invoice with *Apply Tax Withholding Amount* gets a **Withholding Tax Certificate** +button that downloads the Revenue Department's Sec. 50 bis form (หนังสือรับรองการหักภาษี ณ ที่จ่าย, +two copies) as a PDF: the *Withholding Tax Certificate* print format lays the invoice's data +over the official form (`public/images`). The row the payment is reported on comes from +*Type of Income Paid* on the Tax Withholding Category (set for the shipped categories; pick it +for your own), and the ภ.ง.ด. return is ticked from the Supplier's type: ภ.ง.ด.53 for juristic +payees, ภ.ง.ด.1ก / 2 / 3 by income type for individuals. เล่มที่ / เลขที่ (certificate book +numbers) and ลำดับที่ (the line in the return) are left for the accountant. + ### Contributing This app uses `pre-commit` for code formatting and linting. Please [install pre-commit](https://pre-commit.com/#installation) and enable it for this repository: diff --git a/default_thai_company/hooks.py b/default_thai_company/hooks.py index f03d515..8a62ea8 100644 --- a/default_thai_company/hooks.py +++ b/default_thai_company/hooks.py @@ -43,7 +43,10 @@ required_apps = ["erpnext"] # page_js = {"page" : "public/js/file.js"} # include js in doctype views -doctype_js = {"Payment Entry": "public/js/payment_entry.js"} +doctype_js = { + "Payment Entry": "public/js/payment_entry.js", + "Purchase Invoice": "public/js/purchase_invoice.js", +} # doctype_list_js = {"doctype" : "public/js/doctype_list.js"} # doctype_tree_js = {"doctype" : "public/js/doctype_tree.js"} # doctype_calendar_js = {"doctype" : "public/js/doctype_calendar.js"} diff --git a/default_thai_company/public/js/purchase_invoice.js b/default_thai_company/public/js/purchase_invoice.js new file mode 100644 index 0000000..565ac2d --- /dev/null +++ b/default_thai_company/public/js/purchase_invoice.js @@ -0,0 +1,36 @@ +frappe.ui.form.on("Purchase Invoice", { + refresh(frm) { + frm.events.toggle_withholding_certificate(frm); + }, + + apply_tds(frm) { + frm.events.toggle_withholding_certificate(frm); + }, + + toggle_withholding_certificate(frm) { + const label = __("Withholding Tax Certificate"); + frm.remove_custom_button(label); + if (!frm.doc.apply_tds || frm.is_new() || frm.doc.docstatus === 2) return; + // The Withholding Tax Certificate print format renders the Revenue Department's + // Sec. 50 bis form (fixtures/print_format.json) as a PDF. + frm.add_custom_button(label, () => { + if (frm.is_dirty()) { + frappe.msgprint(__("Please save the document before generating the certificate.")); + return; + } + const params = new URLSearchParams({ + doctype: frm.doctype, + name: frm.docname, + format: "Withholding Tax Certificate", + no_letterhead: 1, + _lang: "th", + }); + const w = window.open( + frappe.urllib.get_full_url( + `/api/method/frappe.utils.print_format.download_pdf?${params}` + ) + ); + if (!w) frappe.msgprint(__("Please enable pop-ups")); + }); + }, +}); diff --git a/default_thai_company/translations/th.csv b/default_thai_company/translations/th.csv index c64b81e..8e210ef 100644 --- a/default_thai_company/translations/th.csv +++ b/default_thai_company/translations/th.csv @@ -60,6 +60,8 @@ Withholding Tax Payable,ภาษีหัก ณ ที่จ่ายค้า Withholding Tax Receivable,ภาษีถูกหัก ณ ที่จ่าย Output VAT,ภาษีขาย Input VAT,ภาษีซื้อ +Withholding Tax Certificate,หนังสือรับรองการหักภาษี ณ ที่จ่าย +Please save the document before generating the certificate.,กรุณาบันทึกเอกสารก่อนออกหนังสือรับรองการหักภาษี ณ ที่จ่าย Type of Income Paid,ประเภทเงินได้พึงประเมินที่จ่าย Salary and Wages - Sec. 40(1),เงินเดือน ค่าจ้าง ฯลฯ ตามมาตรา 40(1) Fees and Commissions - Sec. 40(2),ค่าธรรมเนียม ค่านายหน้า ฯลฯ ตามมาตรา 40(2)