/** * @return bool */ public function autoInsertFee_voucher_datail() { if ($this->getChildRecs('Fee_voucher_datail')) { return true; } // get default installments $student = new Student($this->student_id->val); $class = new Clas($student->class_id->val); $defInstallments = Default_installment::findByCondition("config_class_id = " . $class->config()->id->val . " AND month = '" . $this->month->val . "'"); if (!$defInstallments) { return true; } foreach ($defInstallments as $dInsId => $defIns) { if ($defIns instanceof Default_installment) { } $feeVoucherDetail = new Fee_voucher_datail(); $feeVoucherDetail->fee_voucher_id->val = $this->id->val; // if the student has a special discount, default installments will not apply to them: if ($student->annual_dues->val < $class->config()->annual_dues->val) { global $db; $feeVoucherDetail->fee_category_id->val = $db->gfv("id", "config_fee_categories", "category = 'Tuition Fee'"); $feeVoucherDetail->amount->val = $student->annual_dues->val / count($class->config()->defInstallments()); //$feeVoucherDetail->pr("this is being inserted"); } else { $feeVoucherDetail->fee_category_id->val = $defIns->fee_category_id->val; $feeVoucherDetail->amount->val = $defIns->amount->val; //$feeVoucherDetail->pr("default being inserted"); } if (!$feeVoucherDetail->dbSave()) { //$feeVoucherDetail->pr(); } } return true; }
/** * @return Default_installment[] */ function defaultInstallments() { $class = new Clas($this->class_id->val); return Default_installment::findByCondition("config_class_id = " . $class->config()->id->val); }