diff --git a/jey_erp/custom_fields.py b/jey_erp/custom_fields.py index 41d39b7..a10c77b 100644 --- a/jey_erp/custom_fields.py +++ b/jey_erp/custom_fields.py @@ -1526,7 +1526,11 @@ def create_custom_fields(): insert_after='employer_name', read_only=1 ) - ] + ], + + # ===================================================== + # EMPLOYEE - AMAS DATA INTEGRATION + # ===================================================== } for doctype, fields in custom_fields.items(): diff --git a/jey_erp/hooks.py b/jey_erp/hooks.py index 9b24eaa..e3229fd 100644 --- a/jey_erp/hooks.py +++ b/jey_erp/hooks.py @@ -20,7 +20,8 @@ app_include_js = [ doctype_js = { "Payment Entry": "/public/js/payment_entry_mod.js", "Account": "/public/js/account_tree_custom.js", - "Sales Invoice": "public/js/sales_invoice.js" + "Sales Invoice": "public/js/sales_invoice.js", + "Employee": "public/js/employee.js" } # override_doctype_class = { diff --git a/jey_erp/public/js/employee.js b/jey_erp/public/js/employee.js new file mode 100644 index 0000000..584a5ba --- /dev/null +++ b/jey_erp/public/js/employee.js @@ -0,0 +1,115 @@ +frappe.ui.form.on('Employee', { + refresh: function(frm) { + // Find linked AMAS Employees record via reverse link + find_amas_employee(frm); + } +}); + +function find_amas_employee(frm) { + // Search for AMAS Employees record where employee = this Employee + frappe.call({ + method: 'frappe.client.get_list', + args: { + doctype: 'Amas Employees', + filters: { employee: frm.doc.name }, + fields: ['name', 'contract_html', 'full_name'], + limit: 1 + }, + callback: function(r) { + if (r.message && r.message.length > 0) { + const amas_employee = r.message[0]; + + // Add button to view AMAS Employees record + frm.add_custom_button(__('View AMAS Data'), function() { + frappe.set_route('Form', 'Amas Employees', amas_employee.name); + }, __('AMAS')); + + // Show contract button if contract exists + if (amas_employee.contract_html && amas_employee.contract_html.trim().length > 0) { + frm.add_custom_button(__('View Contract'), function() { + show_contract_dialog(amas_employee.contract_html, amas_employee.full_name); + }, __('AMAS')); + } + } + } + }); +} + +function show_contract_dialog(html_content, employee_name) { + // Create dialog with proper size + const d = new frappe.ui.Dialog({ + title: __('Employment Contract') + (employee_name ? ': ' + employee_name : ''), + size: 'large', + fields: [ + { + fieldname: 'contract_preview', + fieldtype: 'HTML', + options: '
' + } + ], + primary_action_label: __('Print'), + primary_action: function() { + // Get iframe and trigger print + const iframe = document.getElementById('contract-iframe'); + if (iframe && iframe.contentWindow) { + iframe.contentWindow.print(); + } + }, + secondary_action_label: __('Close') + }); + + d.show(); + + // Set dialog to full width + d.$wrapper.find('.modal-dialog').css({ + 'max-width': '90%', + 'width': '90%', + 'margin': '30px auto' + }); + + // Wait for dialog to fully render, then create iframe + setTimeout(() => { + const wrapper = d.$wrapper.find('#contract-iframe-wrapper'); + + // Create iframe with proper styling + wrapper.html(` + + `); + + // Wait a bit more for iframe to be added to DOM + setTimeout(() => { + const iframe = d.$wrapper.find('#contract-iframe')[0]; + + if (iframe) { + // Wrap content in proper HTML structure + const full_html = ` + + + + + + +${html_content} + +`; + + // Use contentWindow.document.write for better compatibility + const doc = iframe.contentDocument || iframe.contentWindow.document; + doc.open(); + doc.write(full_html); + doc.close(); + } + }, 200); + }, 100); +}