public function executeInsertPaymentJournal() { $student_course = StudentCoursePeer::retrieveByPK($this->getRequestParameter('id')); $stu = StudentPeer::retrieveByPK($this->getRequestParameter('student_id')); $accal = $student_course->getAcademicCalendar(); $job = JobPeer::retrieveByCode($this->getModuleName()); $academic_process = $job->getAcademicProcess(); $this->forward404Unless($student_course && $stu && $accal && $job && $academic_process); // $c = new Criteria(); // $c->add(AcademicCostPeer::ACADEMIC_CALENDAR_ID, $accal->getId()); // $c->add(AcademicProcessPeer::CODE, $academic_process->getCode()); // $c->addJoin(AcademicProcessPeer::ID, AcademicCostPeer::ACADEMIC_PROCESS_ID); // $costs = AcademicCostPeer::doSelect($c); #$c = new Criteria(); #$c->add(StudentCoursePeer::STUDENT_ID, $stu->getId()); #$c->add(SubjectAccalPeer::ACADEMIC_CALENDAR_ID, $accal->getId()); #$c->add(StudentCoursePeer::STATUS, StudentCourse::STATUS_APPROVED); #$c->addJoin(SubjectAccalPeer::ID, StudentCoursePeer::SUBJECT_ACCAL_ID); #$scs = StudentCoursePeer::doSelect($c); $paids = $this->getRequestParameter('paid'); foreach ($paids as $key => $val) { $c = AcademicCostPeer::retrieveByPK($key); $payment_journal = new PaymentJournal(); $payment_journal->setAcademicCost($c); $payment_journal->setJob($job); $payment_journal->setPayer($stu->getId()); #$amount = 0; #if ($c->getAcademicCostComponent()->getUnit() == AcademicCostComponent::UNIT_CREDIT) { # foreach ($scs as $sc) { # $amount += $c->getAmount() * $sc->getSubjectAccal()->getSubject()->getCredit(); # } #} elseif ($c->getAcademicCostComponent()->getUnit() == AcademicCostComponent::UNIT_SUBJECT) { # foreach ($scs as $sc) { # $amount += $c->getAmount(); # } #} else { $amount = $c->getAmount(); #} $payment_journal->setAmount($amount); $payment_journal->setPaid($val); $payment_journal->setReceivable($amount - $val); $payment_journal->setAcademicProcess($academic_process); $payment_journal->setPayerType(PaymentJournal::PAYER_TYPE_STUDENT); if ($amount - $val == 0) { $payment_journal->setStatus('S'); } elseif ($amount - $val > 0) { $payment_journal->setStatus('M'); } elseif ($amount - $val < 0) { $payment_journal->setStatus('P'); } $payment_journal->save(); $ph = new PaymentHistory(); $ph->setPaymentJournal($payment_journal); $ph->setAmount($val); $ph->save(); } // activate all paid credit if ($this->hasRequestParameter('status[student_course]') && $this->getRequestParameter('status[student_course]') == 1) { $c = new Criteria(); $c->add(StudentCoursePeer::STUDENT_ID, $stu->getId()); $c->add(StudentCoursePeer::STATUS, StudentCourse::STATUS_APPROVED); $approved_scs = StudentCoursePeer::doSelect($c); foreach ($approved_scs as $asc) { $asc->setStatus(StudentCourse::STATUS_ACTIVE); $asc->save(); } } // change student status to active if ($this->hasRequestParameter('status[student]') && $this->getRequestParameter('status[student]') == Student::STATUS_ACTIVE) { $stu->setStatus(Student::STATUS_ACTIVE); $stu->setAcademicCalendarId($accal->getId()); $stu->save(); } return $this->redirect('student_course/list?student_id=' . $stu->getId()); }
public function executeSave() { $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'); $params = array(); foreach (explode('&', $this->getRequestParameter('month_list_ser')) as $p) { $p = explode('=', $p); $params[rawurldecode($p[0])][] = rawurldecode($p[1]); } if (array_key_exists('months', $params)) { foreach ($params['months'] as $month_id) { $payment_student = new PaymentJournal(); $student = StudentPeer::retrieveByPK($this->getRequestParameter('student_id')); $c = new Criteria(); $c->add(StudentTypePeer::STUDENT_ID, $student->getId()); $stu_type = StudentTypePeer::doSelectOne($c); $cr = new Criteria(); $cton1 = $cr->getNewCriterion(AcademicCostPeer::PAYER_TYPE_ID, $stu_type->getPayerTypeId(), Criteria::IN); $cton2 = $cr->getNewCriterion(AcademicCostPeer::ACADEMIC_PROCESS_ID, 2, Criteria::IN); $cton3 = $cr->getNewCriterion(AcademicCostPeer::ACADEMIC_CALENDAR_ID, $student->getAcademicCalendarId(), Criteria::IN); $cton4 = $cr->getNewCriterion(AcademicCostPeer::ACADEMIC_CALENDAR_ID, $student->getAcademicCalendar()->getParent(), Criteria::IN); $cton3->addOr($cton4); $cton2->addAnd($cton3); $cton1->addAnd($cton2); $cr->add($cton1); $ac_cost = AcademicCostPeer::doSelectOne($cr); $payment_student->setPayer($this->getRequestParameter('student_id')); $payment_student->setAcademicCostId($ac_cost->getId()); $payment_student->setAcademicProcessId($ac_cost->getAcademicProcessId()); $payment_student->setAmount($ac_cost->getAmount()); $payment_student->setPaid($ac_cost->getAmount()); $payment_student->setReceivable($ac_cost->getAmount() - $ac_cost->getAmount()); $payment_student->setPaidAt($this->getRequestParameter('paid_at')); $payment_student->setPayerType(PaymentJournal::PAYER_TYPE_STUDENT); $payment_student->setPaymentModelId($this->getRequestParameter('payment_model_id')); $payment_student->setYear($this->getRequestParameter('year')); $payment_student->setMonth($month_id); $payment_student->setStatus('S'); $payment_student->save(); $amount_changed = $ac_cost->getAmount(); if ($amount_changed != 0) { $ph = new PaymentHistory(); $ph->setPaymentJournal($payment_student); $ph->setAmount($amount_changed); $ph->save(); } } } return $this->redirect('payment_student/list'); #return $this->forward('payment_student', 'preview?student_id='.$this->getRequestParameter('student_id').'&paid_at='.$this->getRequestParameter('paid_at').'&payment_model_id='.$this->getRequestParameter('payment_model_id').'&year='.$this->getRequestParameter('year')); #return $this->redirect('payment_student/preview?student_id='.$this->getRequestParameter('student_id').'&paid_at='.$this->getRequestParameter('paid_at').'&payment_model_id='.$this->getRequestParameter('payment_model_id').'&year='.$this->getRequestParameter('year')); #return $this->redirect('payment_student/list', # 'before'=>"window.open('".$this->getController()->genUrl('/payment_student/printForm'). # "?student_id='+$('student_id').value+'&paid_at='+$('paid_at').value+'&payment_model_id='+$('payment_model_id').value+'&year='+$('year').value, # 'link', # 'height=480,width=640,toolbar=no,menubar=no,scrollbars=yes,resizable=yes,location=no,directories=no,status=no' # )") }
public function executeUpdateSpp() { $user_id = $this->getContext()->getUser()->getAttribute('user_id', null, 'bo'); $student = StudentPeer::retrieveByPk($this->getRequestParameter('student_id')); $this->forward404Unless($student); $academic_cost = AcademicCostPeer::retrieveByPk($this->getRequestParameter('academic_cost_id')); $this->forward404Unless($academic_cost); $paid_at = $this->getRequestParameter('paid_at'); $year = $this->getRequestParameter('year'); $month_list_ser = $this->getRequestParameter('month_list_ser'); $params = array(); foreach (explode('&', $this->getRequestParameter('month_list_ser')) as $p) { $p = explode('=', $p); $params[rawurldecode($p[0])][] = rawurldecode($p[1]); } if (array_key_exists('months', $params)) { $total_cost = 0; foreach ($params['months'] as $month_id) { $payment_student = new PaymentJournal(); $ac_cost = AcademicCostPeer::retrieveByPK($this->getRequestParameter('academic_cost_id')); $payment_student->setPayer($this->getRequestParameter('student_id')); $payment_student->setAcademicCostId($ac_cost->getId()); $payment_student->setAcademicProcessId($ac_cost->getAcademicProcessId()); $payment_student->setAmount($ac_cost->getAmount()); $payment_student->setPaid($ac_cost->getAmount()); $payment_student->setReceivable($ac_cost->getAmount() - $ac_cost->getAmount()); $payment_student->setPaidAt($this->getRequestParameter('paid_at')); $payment_student->setPayerType(PaymentJournal::PAYER_TYPE_STUDENT); $payment_student->setPaymentModelId(2); $payment_student->setYear($this->getRequestParameter('year')); $payment_student->setMonth($month_id); $payment_student->setStatus('S'); $payment_student->setTransactionStatusId(1); $payment_student->setJobId($user_id); $payment_student->save(); $total_cost += $payment_student->getAmount(); $amount_changed = $ac_cost->getAmount(); if ($amount_changed != 0) { $ph = new PaymentHistory(); $ph->setPaymentJournal($payment_student); $ph->setAmount($amount_changed); $ph->setStatus($payment_student->getStatus()); $ph->setReceivable($payment_student->getReceivable()); $ph->setAcademicCostId($payment_student->getAcademicCostId()); $ph->setMonth($payment_student->getMonth()); $ph->setCredit($payment_student->getMonth()); $ph->save(); } } } $this->student = $student; $this->academic_cost = $academic_cost; $this->paid_at = $paid_at; $this->year = $year; $this->month_list_ser = $month_list_ser; $this->getRequest()->setParameter('student_id', $student->getId()); $this->getRequest()->setParameter('academic_cost_id', $academic_cost->getId()); $this->getRequest()->setParameter('paid_at', $paid_at); $this->getRequest()->setParameter('year', $year); return $this->forward('student_payment', 'previewSpp'); }