Example #1
0
// handle post request
if (isset($_POST['apply'])) {
    //prpost();
    if (!isset($_POST['student_ids'])) {
        $html->echoError("Please select students");
    } elseif (!isset($_POST['months'])) {
        $html->echoError("Please select months");
    } else {
        foreach ($_POST['student_ids'] as $stId) {
            $student = $students[$stId];
            $class = $student->clas();
            foreach ($_POST['months'] as $m) {
                // check if a voucher is already present for that month
                // if not present, add a new fee voucher
                // if present, add fee detail to it
                if (!($feeVoucher = Fee_voucher::findOneByCondition("student_id={$stId} and month={$m}"))) {
                    $feeVoucher = new Fee_voucher();
                    $feeVoucher->student_id->val = $student->id->val;
                    $y = $m >= $class->starting_month->val ? $class->session->val : $class->session->val + 1;
                    $d = $student->last_date_for_fee_submission->val;
                    $feeVoucher->month->val = $m;
                    $feeVoucher->year->val = $y;
                    $feeVoucher->last_date->val = "{$y}-{$m}-{$d}";
                    $feeVoucher->issue_date->val = "{$y}-{$m}-01";
                    if (!$feeVoucher->dbSave()) {
                        $html->echoError("Fee Voucher not already saved. Failed to create a new one.");
                    }
                }
                // create fee voucher detail
                $feeDetail = new Fee_voucher_datail();
                $feeDetail->fee_voucher_id->val = $feeVoucher->id->val;