Payroll entry customization

When i create a payroll entry and submit it a journal entry is made automatically.

I want to make one more journal entry (automation), with addition to this journal entry

how to do this automation, i know what account to select, i know the amount basically the amount is 18.75% of the below amount

Please help, any help is much appreciated
@NCP bro please look once, let me know anything

Hi @Rajat96318,

You need to use a server script with specific logic for the scenario. This means you must understand both server scripts and client scripts.

Reference:

Additionally, review the code for the basic automated function that creates a document at the time of submitting payroll.

Thank You!

@NCP , thank you i have seen the video

i am using below server script

i have this server script, how do i that when i submit payroll entry, then this api is hit
help me with something

Tell me if i am doing wrong, writing api this way is bad, or how do i correctly do it
your help is much appreciated

Certain methods and import functions might not function properly on the server side. You may need to create a custom application and develop the required scenario. Additionally, explore the concept of hooks.

I hope this helps.

Thank You!

@NCP , i want to ask one approach correct me if i am wrong
i will upload this api in any python file, and call it when the payroll entry is made

when i click on this button “Submit salary slip” journal entry is made (because some code is written in backend)

i will add this api code in backend and call inside this button click in js (something like this).

Tell me is this approach wrong, give your suggestion, where it can go wrong.

No, I think you should watch the frappe.call video.

I recommend that you locate the code for the button and examine how it operates, what its actual path is. I believe you need to delve into the core functionality because we’ve only discussed the concept and how it works in basic functionality. So, I think you should learn on your own. Frappe offers a list of development courses, so find them and check them out.

@NCP bro the issue is resolved, below are the steps i did

  1. changed the “submit_salary_slips” funtionality to below code
const submit_salary_slip = function (frm) {
	frappe.confirm(__('This will submit Salary Slips and create accrual Journal Entry. Do you want to proceed?'),
		function () {
			frappe.call({
				method: 'submit_salary_slips',
				args: {},
				callback: function () {
					frm.events.refresh(frm);
					const docName = frm.doc.name;
					const docPostingDate = frm.doc.posting_date;
					const docCompany = frm.doc.company;
					frappe.call({
						method: 'myginne.api.journal_entry.add_journal_entry_data',
						args: {
							doc_name: docName,
							doc_posting_date: docPostingDate,
							doc_company: docCompany
						},
						// callback: function(response) {
						//     frappe.msgprint(response.message);
						// }
					});
				},
				doc: frm.doc,
				freeze: true,
				freeze_message: __('Submitting Salary Slips and creating Journal Entry...')
			});
		},
		function () {
			if (frappe.dom.freeze_count) {
				frappe.dom.unfreeze();
				frm.events.refresh(frm);
			}
		}
	);
};
  1. you can see a method myginne.api.journal_entry.add_journal_entry_data
    below is the api code
import frappe

@frappe.whitelist(allow_guest=True) 
def add_journal_entry_data(doc_name, doc_posting_date, doc_company):
    if doc_company != "myGINNY Infotech Pvt. Ltd. (India)":
        return 
    try:
        doctype_name = 'Journal Entry'
        data_list = [{}]  

        salary_slips = frappe.db.sql("""
            SELECT * FROM `tabSalary Slip`
            WHERE payroll_entry = %s
        """, (doc_name,), as_dict=True)
        total_basic_salary = 0

        # Iterate through each salary slip to calculate the total Basic Salary
        for salary_slip in salary_slips:
            earnings = frappe.get_all("Salary Detail",
                                       filters={"parent": salary_slip.name, "salary_component": "Basic Salary"},
                                       fields=["amount"],
                                       as_list=True)
            # Sum up the Basic Salary component for each salary slip
            total_basic_salary += sum(float(amount) for amount, in earnings)
            
        total_basic_salary = total_basic_salary * (0.1875)

        for entry_data in data_list:
            journal_entry = frappe.get_doc({
                "doctype": doctype_name,
                "company": "myGINNY Infotech Pvt. Ltd. (India)",
                "posting_date": doc_posting_date,
            })

            # Hardcoded values for Journal Entry Account child table
            hardcoded_entries = [
                {
                    "account": "Accumulated Depreciation - MGI",
                    "debit_in_account_currency": total_basic_salary,
                    "credit_in_account_currency": 0,
                    "reference_type":"",
                    "reference_name":""
                },
                {
                    "account": "Buildings - MGI",
                    "debit_in_account_currency": 0,
                    "credit_in_account_currency": total_basic_salary,
                    "reference_type":"Payroll Entry",
                    "reference_name":doc_name
                }
            ]

            # Create Journal Entry Account child table entries
            for entry in hardcoded_entries:
                journal_entry.append("accounts", {  
                    "doctype": "Journal Entry Account",
                    "account": entry["account"],
                    "debit_in_account_currency": entry["debit_in_account_currency"],
                    "credit_in_account_currency": entry["credit_in_account_currency"],
                    "reference_type":entry["reference_type"],
                    "reference_name":entry["reference_name"]
                })
            
            journal_entry.insert(ignore_permissions=True)
            journal_entry.submit()
            frappe.db.commit()

        # return {'message': doc_name}

    except Exception as e:
        frappe.log_error(frappe.get_traceback(), 'Custom Journal Entry Data API Error')
        return {'message': str(e)}


now when the “Submit Salary Slips” is clicked and when Yes is clicked then two journal entry is made against this payroll entry

when the make bank entry is done then third journal entry is made :slight_smile:

:clap: @Rajat96318

1 Like