How to use salary slip components in custom print format?

I want to create a print format for the salary slip and for that I’ve added a html code. I’m able to print few fields in the custom print format but salary components are not printing. I’m adding the html code snippet and screenshot of the salary slip.

<br>Salary Slip for {{ doc.month }}
</td>
</tr>
<tr height="20px"></tr>
<tr>
<th>Personnel No</th>
<td>{{ doc.employee }}</td>
<th>Days Payable</th>
<td>{{ doc.payment_days }}</td>
</tr>
<tr>
<th>Name</th>
<td>{{ frappe.db.get_value("Employee", doc.employee, "employee_name") or "" }}</td>
<tr height="20px"></tr>
<tr>
<th >Earnings</th>
<th>Amount in Rs.</th>
<th >Deductions</th>
<th>Amount in Rs.</th>
</tr>
<tr>
<td>Basic</td>
<td style="text-align:right;">{{ doc.Basic }}</td>
<td>PF Employee Contribution</td>
<td style="text-align:right;">{{ doc.pf }}</td>
</tr>
<tr>
<td>HRA</td>
<td style="text-align:right;">{{ doc.hra }}</td>
<td>ESI Employee Contribution</td>
<td style="text-align:right;">{{ doc.esi }}</td>
</tr>
<tr>
<td>Bonus</td>
<td style="text-align:right;">{{ doc.bonus }}</td>
<td>Professional Tax</td>
<td style="text-align:right;">{{ doc.professional_tax }}</td>
</tr>
<tr>
<td>Special Allowance</td>
<td style="text-align:right;">{{ doc.other_allowance }}</td>
<td></td>
<td></td>
</tr>
<tr>
<th>Gross Earnings</th>
<td style="text-align:right;">{{ doc.gross_pay }}</td>
<th >Gross Deductions</th>
<td style="text-align:right;">{{ doc.total_deduction }}</td>
</tr>
<tr height="20px"></tr>
<tr>
<td></td>
<td><strong>NET PAY</strong></td>
<td style="text-align:right;">{{ doc.net_pay }}</td>
<td></td>
</tr>

So, how can I print the Month name salary components values like Basic, HRA, etc. in this by using HTML code?

In ERPNext, the salary components within a salary slip document are entered into its child table designated as ‘Salary Details’. Consequently, it is not feasible to aggregate these values making use of “doc.” . Instead, it is mandatory to iterate through the child table and subsequently retrieve and display its values, as shown below :


<table style="width:100%;">
    <tr>
        <td colspan = "2" style="width : 50%">
            <table class="table table-bordered" style="border : 1px solid black; width : 100%">
                <tr>
                    <td><b>Earnings & Allowances</b></td>
                    <td><b>Amount in Rs.</b></td>
                </tr>
                {% for row in doc.earnings %}
                     <tr>
                         <td>{{ row.salary_component }} </td>
                         <td align = "right">{{ "{:,.2f}".format( row.amount | float ) }}</td>
                     </tr>
                {% endfor %}
            </table>
        </td>
        <td colspan = "2" style="width : 50%">
            <table class="table table-bordered" style="border : 1px solid black; width : 100%;">
                <tr>
                    <td><b>Deductions</b></td>
                    <td><b>Amount in Rs.</b></td>
                </tr>
                {% for row in doc.deductions %}
                    <tr>
                        <td>{{ row.salary_component }}</td>
                        <td align = "right">{{ "{:,.2f}".format( row.amount | float ) }}</td>
                    </tr>
                {% endfor %}
             </table>
         </td>
     </tr>
</table>

Hope it helps!

1 Like

@just_inquiring Hi,
This solution worked for me. Thank you so much for this solution.