added new amas fields to employee

This commit is contained in:
Ali 2026-02-13 17:40:54 +04:00
parent 14453cbc43
commit 4d1739d352
3 changed files with 122 additions and 2 deletions

View File

@ -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():

View File

@ -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 = {

View File

@ -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: '<div id="contract-iframe-wrapper"></div>'
}
],
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(`
<iframe
id="contract-iframe"
style="width: 100%; height: 70vh; border: 1px solid #d1d8dd; border-radius: 4px;">
</iframe>
`);
// 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 = `<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<style>
/* Ensure print styles work correctly */
@media print {
body {
margin: 0;
padding: 20px;
}
}
</style>
</head>
<body>
${html_content}
</body>
</html>`;
// Use contentWindow.document.write for better compatibility
const doc = iframe.contentDocument || iframe.contentWindow.document;
doc.open();
doc.write(full_html);
doc.close();
}
}, 200);
}, 100);
}