/** * @return Fee_voucher[] */ function autoInsertFee_voucher() { if ($feeVouchers = $this->getChildRecs('Fee_voucher')) { return $feeVouchers; } // get default installments $class = new Clas($this->class_id->val); $defInstallments = $this->defaultInstallments(); if (!$defInstallments) { return false; } $months = array(); // to make sure only one voucher is generated for each single month foreach ($defInstallments as $dInsId => $defIns) { $m = $defIns->month->val; if (!in_array($m, $months)) { //$defIns->pr(); $feeVoucher = new Fee_voucher(); //$feeVoucher->pr(); $feeVoucher->student_id->val = $this->id->val; $y = $m >= $class->starting_month->val ? $class->session->val : $class->session->val + 1; $d = $this->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()) { return false; } $months[] = $m; $feeVouchers[] = $feeVoucher; } } return $feeVouchers; }
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; $feeDetail->fee_category_id->val = $_POST['category'];
$monthDis = $filterOptions->filterFields['month']->displayVal(); $year = $filterOptions->filterFields['year']->val; $stName = $student->get_a_tag($student->name()); if (!$feeVouchers) { $html->echoError("No vouchers are saved for {$stName} for {$monthDis} {$year}"); } else { // hidden inputs for editable fields: $html->echoHiddenInputs(new Fee_voucher()); $html->echoHiddenInputs(new Fee_voucher_datail()); $html->echoHiddenInputs(new Fine_record()); $html->echoHiddenInputs(new Last_class_arrear()); // find voucher $stId = $student->id->val; $month = $filterOptions->filterFields['month']->val; $cond = "student_id = {$stId} AND month = '{$month}' AND year = {$year}"; if ($voucher = Fee_voucher::findByCondition($cond)) { // there should be only one voucher for one month if (count($voucher) > 1) { $html->echoError("More than one vouchers are saved for {$stName} for {$monthDis} {$year}"); } else { $voucher = array_shift($voucher); $voucher->showMarkup(); } } else { $html->echoError("No vouchers are saved for {$stName} for {$monthDis} {$year}"); } } if ($count % $vOptions->numCopiesPerPage == 0) { $html->pageBreak(); } // two vouchers per page