[UPDT] PAYROLL: Updated payslip generation to include employer contribution
This commit is contained in:
@@ -752,6 +752,7 @@ def generate_payslip(request):
|
||||
data["deduction"] = payslip["total_deductions"]
|
||||
data["net_pay"] = payslip["net_pay"]
|
||||
data["pay_data"] = json.loads(payslip["json_data"])
|
||||
calculate_employer_contribution(data)
|
||||
data["installments"] = payslip["installments"]
|
||||
instance = save_payslip(**data)
|
||||
instances.append(instance)
|
||||
@@ -1822,61 +1823,64 @@ def delete_attachments(request, _reimbursement_id):
|
||||
return redirect(view_reimbursement)
|
||||
|
||||
|
||||
from pprint import pprint
|
||||
|
||||
|
||||
@login_required
|
||||
@permission_required("payroll.view_payslip")
|
||||
def get_contribution_report(request):
|
||||
"""
|
||||
This method is used to get the contribution report
|
||||
"""
|
||||
employee_id = request.GET["employee_id"]
|
||||
pay_heads = Payslip.objects.filter(employee_id__id=employee_id).values_list(
|
||||
"pay_head_data", flat=True
|
||||
)
|
||||
employee_id = request.GET.get("employee_id")
|
||||
contribution_deductions = []
|
||||
deductions = []
|
||||
for head in pay_heads:
|
||||
for deduction in head["gross_pay_deductions"]:
|
||||
if deduction.get("deduction_id"):
|
||||
deductions.append(deduction)
|
||||
for deduction in head["basic_pay_deductions"]:
|
||||
if deduction.get("deduction_id"):
|
||||
deductions.append(deduction)
|
||||
for deduction in head["pretax_deductions"]:
|
||||
if deduction.get("deduction_id"):
|
||||
deductions.append(deduction)
|
||||
for deduction in head["post_tax_deductions"]:
|
||||
if deduction.get("deduction_id"):
|
||||
deductions.append(deduction)
|
||||
for deduction in head["tax_deductions"]:
|
||||
if deduction.get("deduction_id"):
|
||||
deductions.append(deduction)
|
||||
for deduction in head["net_deductions"]:
|
||||
deductions.append(deduction)
|
||||
|
||||
deductions.sort(key=lambda x: x["deduction_id"])
|
||||
grouped_deductions = {
|
||||
key: list(group)
|
||||
for key, group in groupby(deductions, key=lambda x: x["deduction_id"])
|
||||
}
|
||||
|
||||
for deduction_id, group in grouped_deductions.items():
|
||||
title = group[0]["title"]
|
||||
employee_contribution = sum(item.get("amount", 0) for item in group)
|
||||
employer_contribution = sum(
|
||||
item.get("employer_contribution_amount", 0) for item in group
|
||||
if employee_id:
|
||||
pay_heads = Payslip.objects.filter(employee_id__id=employee_id).values_list(
|
||||
"pay_head_data", flat=True
|
||||
)
|
||||
total_contribution = employee_contribution + employer_contribution
|
||||
if employer_contribution > 0:
|
||||
contribution_deductions.append(
|
||||
{
|
||||
"deduction_id": deduction_id,
|
||||
"title": title,
|
||||
"employee_contribution": employee_contribution,
|
||||
"employer_contribution": employer_contribution,
|
||||
"total_contribution": total_contribution,
|
||||
}
|
||||
)
|
||||
deductions = []
|
||||
for head in pay_heads:
|
||||
for deduction in head["gross_pay_deductions"]:
|
||||
if deduction.get("deduction_id"):
|
||||
deductions.append(deduction)
|
||||
for deduction in head["basic_pay_deductions"]:
|
||||
if deduction.get("deduction_id"):
|
||||
deductions.append(deduction)
|
||||
for deduction in head["pretax_deductions"]:
|
||||
if deduction.get("deduction_id"):
|
||||
deductions.append(deduction)
|
||||
for deduction in head["post_tax_deductions"]:
|
||||
if deduction.get("deduction_id"):
|
||||
deductions.append(deduction)
|
||||
for deduction in head["tax_deductions"]:
|
||||
if deduction.get("deduction_id"):
|
||||
deductions.append(deduction)
|
||||
for deduction in head["net_deductions"]:
|
||||
deductions.append(deduction)
|
||||
|
||||
deductions.sort(key=lambda x: x["deduction_id"])
|
||||
grouped_deductions = {
|
||||
key: list(group)
|
||||
for key, group in groupby(deductions, key=lambda x: x["deduction_id"])
|
||||
}
|
||||
|
||||
for deduction_id, group in grouped_deductions.items():
|
||||
title = group[0]["title"]
|
||||
employee_contribution = sum(item.get("amount", 0) for item in group)
|
||||
employer_contribution = sum(
|
||||
item.get("employer_contribution_amount", 0) for item in group
|
||||
)
|
||||
total_contribution = employee_contribution + employer_contribution
|
||||
if employer_contribution > 0:
|
||||
contribution_deductions.append(
|
||||
{
|
||||
"deduction_id": deduction_id,
|
||||
"title": title,
|
||||
"employee_contribution": employee_contribution,
|
||||
"employer_contribution": employer_contribution,
|
||||
"total_contribution": total_contribution,
|
||||
}
|
||||
)
|
||||
return render(
|
||||
request,
|
||||
"payroll/dashboard/contribution.html",
|
||||
|
||||
Reference in New Issue
Block a user