Language: PHP
Label: vulnerable
CWE: CWE-79 \u2014 Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting')
The product does not neutralize or incorrectly neutralizes user-controllable input before it is placed in output that is used as a web page that is served to other users.

Code:
function getEmployeePayableAmount(int $emp_id, string $salary_type) {
    global $table_prefeix;

    $emp_opening_balance_name = "emp_opening_". strtolower($salary_type);

    $empPayableAmount = easySelectD("
        select 
            emp_id,
            ( ( if(salary_amount_sum is null, 0, salary_amount_sum) - if(payment_items_amount_sum is null, 0, payment_items_amount_sum) ) + ({$emp_opening_balance_name}) ) as emp_payable_amount
        from {$table_prefeix}employees
        left join ( select salary_emp_id, salary_type, sum(salary_amount) as salary_amount_sum from {$table_prefeix}salaries where is_trash = 0 and salary_type='{$salary_type}' group by salary_emp_id ) as {$table_prefeix}salaries on salary_emp_id = emp_id
        left join ( select payment_items_employee, sum(payment_items_amount) as payment_items_amount_sum from {$table_prefeix}payment_items where is_trash = 0 and payment_items_type='{$salary_type}' group by payment_items_employee ) as get_payments_items on payment_items_employee = emp_id
        where emp_id = {$emp_id}
    ")["data"][0]["emp_payable_amount"];

    // if salary type is salary then add the installment amount with payable amount
    if($salary_type === "salary") {

        $paidLoan = easySelectD("
            select sum(loan_installment_paying_amount) as loan_paid_amount from {$table_prefeix}loan_installment where is_trash = 0 and loan_installment_provider = '{$emp_id}' group by loan_installment_provider
        ");

        $empPayableAmount -= $paidLoan ? $paidLoan["data"][0]["loan_paid_amount"] : 0;
    }

    return $empPayableAmount;

}