<?php
include("../classes/manager.class.php");
$m = new Manager();
if ($_REQUEST['id']) {
    $id = $_REQUEST['id'];
    $dateset = $_REQUEST['dateset'];

    $LoanSalaryFilter = ' WHERE employee_id = "' . $id . '" AND status = "active"';
    $loanSalary = LoanSetupMart::GetLoanList($LoanSalaryFilter);
    $loanPerMonth = 0;
    if ($loanSalary) {
        $year = date('Y', strtotime($dateset));
        $month = date('m', strtotime($dateset));
        $currentDate = date('Y-m', strtotime($year . '-' . $month));
        foreach ($loanSalary AS $loanSalaryRow) {
            $startDate = date('Y-m', strtotime($loanSalaryRow->start_date));
            $endDate = date("Y-m", strtotime('+' . ($loanSalaryRow->installment) . ' month', strtotime($loanSalaryRow->start_date)));
            if ($currentDate >= $startDate && $currentDate <= $endDate) {
                $loanPerMonth = $loanSalaryRow->amount / $loanSalaryRow->installment;
            }
        }
    }
    echo $loanPerMonth;
}

?>