i want that when i click any of the three salary slip, it should redirect to page where print format of salary slip is their (basically the print page)
or i want that only pdf is shown to employee.
example : 1) let say i click one of salary slip
i redirect to this page
but i want to redirect directly to below page
basically the url from
this → http://0.0.0.0:8003/app/salary-slip/Sal%20Slip%2FHR-EMP-00012%2F00016
to this → http://0.0.0.0:8003/app/print/Salary%20Slip/Sal%20Slip%2FHR-EMP-00012%2F00016
Anyone know the solution, please help
open to any suggestion
1 Like
NCP
March 9, 2024, 4:20pm
2
Hi @Rajat96318 ,
Please apply the code and reload and check it.
frappe.listview_settings["Salary Slip"] = {
onload: function(listview) {
if (!has_common(frappe.user_roles, ["Administrator", "System Manager", "HR Manager", "HR User"])) return;
listview.page.add_menu_item(__("Email Salary Slips"), () => {
if (!listview.get_checked_items().length) {
frappe.msgprint(__("Please select the salary slips to email"));
return;
}
frappe.confirm(__("Are you sure you want to email the selected salary slips?"), () => {
listview.call_for_selected_items("hrms.payroll.doctype.salary_slip.salary_slip.enqueue_email_salary_slips");
});
});
},
button: {
show: function (doc) {
return doc.name;
},
get_label: function () {
return __("View", null, "Access");
},
get_description: function (doc) {
return __("Open {0}", [`${__(doc.name)}: ${doc.employee}`]);
},
action: function (doc) {
window.open("/app/print/Salary Slip/"+doc.name);
},
},
}
please click on View then open the print preview.
Output:
We’ve just inserted the button code. In the onload method, it’s the default code for the salary slip, so let’s leave it there.
I hope this helps.
Thank You!
2 Likes
@NCP Thank you for your reply much appreciated, the solution is one step towards my requirement.
i have done what you told, but i want when i click the view button the pdf is opened directly.
like the window.open() should redirect to pdf url.
my pdf url is “http://0.0.0.0:8003/api/method/frappe.utils.print_format.download_pdf?doctype=Salary%20Slip&name=Sal%20Slip%2FHR-EMP-00007%2F00004&format=Payslip%20myginne%20india&no_letterhead=0&letterhead=Myginne&settings={}&_lang=en ”
but the above one is hard coded, how do i change such that the pdf opens directly.
Something like this i guess : /app/print/Salary Slip/"+doc.name
Help
NCP
March 10, 2024, 9:59am
4
Please open the PDF, check the URL, and set it according to the scenario.
NCP
March 10, 2024, 10:10am
6
Rajat96318:
{doc.name}
Why use curly brackets ?
Please check it.
"start_url"+doc.name+"&format ......"
Thank You!
1 Like
window.open(“/api/method/frappe.utils.print_format.download_pdf?doctype=Salary%20Slip&name=” + doc.name + “&format=Payslip%20myginne%20india&no_letterhead=0&letterhead=Myginne&settings=%7B%7D&_lang=en”);
yeah found just now
@NCP
its second step done, thank you man
Now their is one more problem, i have two print format. Let say A & B
Currently i have hard coded for one
How can i do, such that when clicked employee sees his salary slip format.
I think i have to do something more, can you tell how can i do this
1 Like
NCP
March 10, 2024, 10:17am
8
At that moment, you need to make a custom field called “print format name” and adjust it in the URL based on the chosen print format. So, if you pick print format A for a Salary Slip, it will display print format A.
1 Like
Yeah just as i thought.
Thank you for helping me in this task, i owe you man.
@NCP , i am stuck in a process which i thought, can you tell i am doing correct or something is wrong
this is my url : window.open(“/api/method/frappe.utils.print_format.download_pdf?doctype=Salary%20Slip&name=” + doc.name + “&format=Payslip%20Myginne%20” + doc.country + “&no_letterhead=0&letterhead=Myginne&settings=%7B%7D&_lang=en”);
i opened a country field in Salary slip which is either India/Egypt.
since the print format naming of both country is approx same except country name
India - Payslip Myginne India
Egypt - Payslip Myginne Egypt
Therefore i thought to change url like above.
Can you tell what is wrong
Help
NCP
March 10, 2024, 10:51am
11
Please check the url, url-parameter, and your field name. It’s a minor mistake. try to find and solve it.
@NCP , i have tried all
Below is the steps i did
added a country field (type : data) in Salary structure
added a country field (type : data) in Salary Slip, and added fetch from to : salary_structure.country
url change in code : window.open(“/api/method/frappe.utils.print_format.download_pdf?doctype=Salary%20Slip&name=” + doc.name + “&format=PaySlip%20Myginne%20”+doc.country+“&no_letterhead=0&letterhead=Myginne&settings=%7B%7D&_lang=en”);
when i click on view button the Standard Slip of erpnext is shown.
with this url : http://0.0.0.0:8003/api/method/frappe.utils.print_format.download_pdf?doctype=Salary%20Slip&name=Sal%20Slip/HR-EMP-00007/00005&format=Payslip%20Myginne%20undefined&no_letterhead=0&letterhead=Myginne&settings={}&_lang=en
Payslip%20Myginne%20undefined : this undefined is coming
u can see in below ss, India is present
what am i doing wrong, Help
can’t find the solution by this approach, i think i am very close to solution but can’t find it
NCP
March 10, 2024, 11:21am
13
first thing, the country should not be set in the URL. Please check the default URL and match it.
@NCP , yes i know in default url their is no country field
default url : http://0.0.0.0:8003/api/method/frappe.utils.print_format.download_pdf?doctype=Salary%20Slip&name=Sal%20Slip%2FHR-EMP-00007%2F00004&format=Payslip%20myginne%20india&no_letterhead=0&letterhead=Myginne&settings={}&_lang=en
but i want to manipulate the url such that
format=PaySlip%20Myginne%20India
changes to format=PaySlip%20Myginne%20"+doc.country+"
simply fetching the field value from salary slip.
i found out that doing doc.name, doc.employee etc fetches the value, i tried below code to test
frappe.msgprint(doc.employee);
but, doing doc.country, doc.total_working_days etc, don’t fetch value as doc.name etc does
why so?
does that mean i can’t do with this approach
can you help me with one test on your local for this problem
i will be thankful man
@NCP , i resolved the issue
this is updated js code
frappe.listview_settings[“Salary Slip”] = {
onload: function(listview) {
if (!has_common(frappe.user_roles, [“Administrator”, “System Manager”, “HR Manager”, “HR User”])) return;
listview.page.add_menu_item(__("Email Salary Slips"), () => {
if (!listview.get_checked_items().length) {
frappe.msgprint(__("Please select the salary slips to email"));
return;
}
frappe.confirm(__("Are you sure you want to email the selected salary slips?"), () => {
listview.call_for_selected_items("hrms.payroll.doctype.salary_slip.salary_slip.enqueue_email_salary_slips");
});
});
},
button: {
show: function (doc) {
return doc.name;
},
get_label: function () {
return __("View", null, "Access");
},
get_description: function (doc) {
return __("Open {0}", [`${__(doc.name)}: ${doc.employee}`]);
},
action: function (doc) {
frappe.call({
method: 'erpnext.payroll.doctype.salary_slip.salary_slip.get_employee_country',
args: {
employee_id: doc.employee
},
callback: function(r) {
var country = r.message;
var encodedCountry = encodeURIComponent(country);
window.open("/api/method/frappe.utils.print_format.download_pdf?doctype=Salary%20Slip&name=" + doc.name + "&format=PaySlip%20Myginne%20" + encodedCountry + "&no_letterhead=0&letterhead=Myginne&settings=%7B%7D&_lang=en");
}
});
},
},
}
this is the python code
import frappe
@frappe.whitelist ()
def get_employee_country(employee_id):
employee = frappe.get_doc(“Employee”, employee_id)
return employee.country
i fetched the country(custom field) from the employee doctype, so that my url is changed accordingly.
2 Likes