@NCP bro the issue is resolved, below are the steps i did
- 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);
}
}
);
};
- 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