public function executeUpdate() { $i18n = new sfI18N(); $i18n->initialize($this->getContext()); $i18n->setCulture($this->getUser()->getCulture()); $action_i18n = $i18n->globalMessageFormat->format('save as new'); $action_type = $this->getRequestParameter('action_type'); $student = StudentPeer::retrieveByPK($this->getRequestParameter('student_id')); $this->forward404Unless($student); $this->student = $student; if ($action_type == $action_i18n || !$this->getRequestParameter('id')) { $student_leave = new StudentLeave(); $student_leave->setStatus(StudentLeave::STATUS_PROPOSED); } else { $student_leave = StudentLeavePeer::retrieveByPk($this->getRequestParameter('id')); $this->forward404Unless($student_leave); $student_leave->setStatus(StudentLeave::STATUS_CANCELED); } $student_leave->setId($this->getRequestParameter('id')); $student_leave->setStudentId($this->getRequestParameter('student_id')); $student_leave->setAcademicCalendarId($this->getRequestParameter('academic_calendar_id')); $student_leave->save(); $stu = $student_leave->getStudent(); if ($student_leave->getStatus() == StudentLeave::STATUS_ACTIVE) { // add payment journal $job = JobPeer::retrieveByCode($this->getModuleName()); $academic_process = $job->getAcademicProcess(); $c = new Criteria(); $c->add(AcademicCostPeer::ACADEMIC_PROCESS_ID, $academic_process->getId()); $c->add(AcademicCostPeer::ACADEMIC_CALENDAR_ID, $student_leave->getAcademicCalendarId()); $costs = AcademicCostPeer::doSelect($c); foreach ($costs as $c) { $pj = new PaymentJournal(); $pj->setPayer($stu->getId()); $pj->setAcademicCost($c); $pj->setJob($job); $pj->setAmount($c->getAmount()); $pj->setPaid($c->getAmount()); $pj->setReceivable(0); $pj->setAcademicProcess($academic_process); $pj->setPayerType(PaymentJournal::PAYER_TYPE_STUDENT); $pj->save(); $ph = new PaymentHistory(); $ph->setPaymentJournal($pj); $ph->setAmount($c->getAmount()); $ph->save(); } // set student status $stu->setStatus(Student::STATUS_INACTIVE); $stu->save(); // cancelled all student course $c = new Criteria(); $c->add(StudentCoursePeer::STUDENT_ID, $stu->getId()); $c->add(StudentCoursePeer::STATUS, array(StudentCourse::STATUS_PLANNED, StudentCourse::STATUS_APPROVED, StudentCourse::STATUS_ACTIVE), Criteria::IN); $scs = StudentCoursePeer::doSelect($c); foreach ($scs as $sc) { $sc->setStatus(StudentCourse::STATUS_CANCELED); $sc->save(); } } elseif ($student_leave->getStatus() == StudentLeave::STATUS_DONE) { $stu->setStatus(Student::STATUS_ACTIVE); $stu->save(); } return $this->redirect('student_leave_s/list?student_id=' . $student->getId()); }
public function executeUpdateStatus() { $i18n = new sfI18N(); $i18n->initialize($this->getContext()); $i18n->setCulture($this->getUser()->getCulture()); $action_i18n = $i18n->globalMessageFormat->format('save as new'); $action_type = $this->getRequestParameter('action_type'); $student = StudentPeer::retrieveByPk($this->getRequestParameter('id')); $this->forward404Unless($student); $student->setStatus($this->getRequestParameter('status')); $student->save(); $c = new Criteria(); $c->add(StudentLeavePeer::STUDENT_ID, $student->getId()); $student_leave = StudentLeavePeer::doSelectOne($c); if ($student_leave == null) { $student_leave = new StudentLeave(); } $student_leave->setAcademicCalendarId($this->getRequestParameter('academic_calendar_id')); $student_leave->setStatus($this->getRequestParameter('status')); $student_leave->setYear($this->getRequestParameter('year')); $student_leave->setEndDate($this->getRequestParameter('end_date')); $student_leave->setDetail($this->getRequestParameter('detail')); $student_leave->setNextSchool($this->getRequestParameter('next_school')); $student_leave->setNextLevel($this->getRequestParameter('next_level')); $student_leave->save(); if ($student->getStatus() == Student::STATUS_OVERDUE) { $c = new Criteria(); $c->add(StudentAccalPeer::STUDENT_ID, $student->getId()); $c->add(StudentAccalPeer::CLASS_GROUP_ID, $student->getClassGroupId()); $c->add(StudentAccalPeer::ACADEMIC_CALENDAR_ID, $student_leave->getAcademicCalendarId()); $student_accal = StudentAccalPeer::doSelectOne($c); if ($student_accal) { $student_accal->setStatus(Student::STATUS_OVERDUE); $student_accal->save(); /** $student_accal->delete(); **/ } } return $this->redirect('scholar/list'); }
public function addStudentLeave(StudentLeave $l) { $this->collStudentLeaves[] = $l; $l->setAcademicCalendar($this); }
public function addStudentLeave(StudentLeave $l) { $this->collStudentLeaves[] = $l; $l->setStudent($this); }