Custom script code to fetch Leave Without Pay in salary slip

While creating Salary Slip, Leave Without Pay days not fetching automatically,so need custom script code to fetch Leave Without Pay in salary slip.

LWP will get fetched if the employe has created a Leave Application with the leave type = Leave without pay and the application has been approved by the leave approver.

Thank You.

But if the leave application is rejected and the employee is present then also it is considering as employee is on leave and deducting money from there salary.

Is there any solution for the same use case if application is rejected system should not done any action of salary deduction ???