Exemple #1
0
 public function getParentalIndex()
 {
     $parentalIndex = "#" . str_pad($this->getId(), 3, '0', STR_PAD_LEFT);
     $this->level = 1;
     if ($this->getParent() !== null && $this->getParent() != 0) {
         $p = PaymentModelPeer::retrieveByPK($this->getParent());
         $parentalIndex = str_pad($p->getParentalIndex(), 3, '0', STR_PAD_LEFT) . "_" . $parentalIndex;
         $this->level += $p->level;
     }
     $this->parentalIndex = $parentalIndex;
     return $parentalIndex;
 }
Exemple #2
0
 public function getPaymentModel($con = null)
 {
     include_once 'lib/model/om/BasePaymentModelPeer.php';
     if ($this->aPaymentModel === null && $this->payment_model_id !== null) {
         $this->aPaymentModel = PaymentModelPeer::retrieveByPK($this->payment_model_id, $con);
     }
     return $this->aPaymentModel;
 }
Exemple #3
0
 public function executePaymentProcess()
 {
     $this->getEnquirer();
     if (!$this->filterUser(true)) {
         $this->jsonwrapper->print_json(array('success' => false, 'code' => 'security', 'message' => 'You must login to access this url.'));
     }
     $applicant = $this->pmbTools->getApplicant($this->user);
     if (!$applicant) {
         $this->jsonwrapper->show_json_error('Permission', 'You dont have permission to access this page');
     }
     if ($applicant->getStatus() != StudentDetail::BUY && $applicant->getStatus() != StudentDetail::WEB && $applicant->getStatus() != StudentDetail::CONFIRM) {
         $this->jsonwrapper->show_json_error('Permission', 'You dont have permission to access this page');
     }
     $param = $this->getAllRequestParameter();
     $valid = true;
     $error_message = array();
     /* payment method */
     if (empty($param['payment_method'])) {
         $error_message[] = array('field' => 'payment_method', 'message' => 'Please enter payment method');
         $valid = false;
     } else {
         $paymentMethod = PaymentModelPeer::retrieveByPK($param['payment_method']);
         if (!$paymentMethod) {
             $error_message[] = array('field' => 'payment_method', 'message' => 'Payment method not exist');
             $valid = false;
         }
     }
     /* payment date */
     if (empty($param['payment_date'])) {
         $error_message[] = array('field' => 'payment_date', 'message' => 'Please enter payment date');
         $valid = false;
     }
     if (!$valid) {
         $this->jsonwrapper->print_json(array('success' => false, 'code' => 'notvalid', 'error' => $error_message));
     }
     /* Start Transaction */
     $connection = Propel::getConnection('propel');
     $connection->begin();
     /* Set Up Registration Test Period */
     $regPeriod = $this->pmbTools->getRegistrationPeriod($applicant->getDepartment1());
     if (!$regPeriod) {
         $this->jsonwrapper->show_json_error('TestPeriod', 'Registration Period not found');
     }
     $c = new Criteria();
     $c->add(RegTestPeriodPeer::REG_PERIOD_ID, $regPeriod->getId());
     $regTestPeriods = RegTestPeriodPeer::doSelect($c);
     $save = false;
     foreach ($regTestPeriods as $reg_test_period) {
         $cw = new Criteria();
         $cw->add(TestSchedulePeer::REG_TEST_PERIOD_ID, $reg_test_period->getId());
         $cw->addAscendingorderByColumn(TestSchedulePeer::ID);
         $scheds = TestSchedulePeer::doSelect($cw);
         $s1 = array();
         foreach ($scheds as $s) {
             $s1[$s->getRegTestPeriodId()][] = array('reg_test_period_id' => $s->getRegTestPeriodId(), 'used' => $s->countTestApplScheds(), 'capacity' => $s->getCapacity(), 'sched' => $s);
         }
         foreach ($s1 as $s) {
             $c = new Criteria();
             $c->add(TestSchedulePeer::REG_TEST_PERIOD_ID, $reg_test_period->getId());
             $c->addJoin(TestApplSchedPeer::TEST_SCHEDULE_ID, TestSchedulePeer::ID);
             $c->add(TestApplSchedPeer::TEST_APPLICANT_ID, $applicant->getId());
             $tas = TestApplSchedPeer::doSelectOne($c);
             if ($tas == null) {
                 $i = 0;
                 while ($s[$i]) {
                     $sched = $s[$i];
                     if ($sched['used'] < $sched['capacity']) {
                         $tas = new TestApplSched();
                         $tas->setTestApplicant($applicant);
                         $tas->setTestSchedule($sched['sched']);
                         try {
                             $tas->save();
                             $save = true;
                         } catch (Exception $e) {
                             $connection->rollback();
                             $this->jsonwrapper->print_json(array('success' => false, 'code' => 'fail', 'message' => 'Error while save test applicant schedule, please try again later.'));
                         }
                         break;
                     }
                     $i++;
                 }
             }
         }
         if (!$save) {
             $connection->rollback();
             $this->jsonwrapper->print_json(array('success' => false, 'code' => 'fail', 'message' => 'Error.'));
         }
         $regTestPeriod = $reg_test_period;
         $applicant->setRegTestPeriod1($reg_test_period->getId());
         try {
             $applicant->save();
         } catch (Exception $e) {
             $connection->rollback();
             $this->jsonwrapper->print_json(array('success' => false, 'code' => 'fail', 'message' => 'Error while save test applicant registration test period, please try again later.'));
         }
         break;
     }
     /* Save new applicant code */
     $newCode = $this->pmbTools->generateApplicantCode(StudentDetail::WEB);
     $applicant->setStatus(StudentDetail::CONFIRM);
     $applicant->setCode($newCode);
     try {
         $applicant->save();
     } catch (Exception $e) {
         $connection->rollback();
         $this->jsonwrapper->print_json(array('success' => false, 'code' => 'fail', 'message' => 'Error while save the applicant data, please try again later.'));
     }
     /* Set Payment */
     $paymentDate = date('Y-m-d', strtotime($param['payment_date']));
     $c = new Criteria();
     $cton1 = $c->getNewCriterion(AcademicCostPeer::ACADEMIC_CALENDAR_ID, $regTestPeriod->getRegPeriod()->getAcademicCalendarId(), Criteria::IN);
     $cton2 = $c->getNewCriterion(AcademicCostPeer::ACADEMIC_PROCESS_ID, 1, Criteria::IN);
     $cton3 = $c->getNewCriterion(AcademicCostPeer::ACADEMIC_COST_COMPONENT_ID, 1, Criteria::IN);
     $cton2->addAnd($cton3);
     $cton1->addAnd($cton2);
     $c->add($cton1);
     $costs = AcademicCostPeer::doSelect($c);
     $total_cost = 0;
     foreach ($costs as $cost) {
         $c = new Criteria();
         $c->add(PaymentApplicantPeer::TEST_APPLICANT_ID, $applicant->getId());
         $payment_applicant = PaymentApplicantPeer::doSelectOne($c);
         if ($payment_applicant == null) {
             $payment_applicant = new PaymentApplicant();
         }
         $payment_applicant->setTestApplicant($applicant);
         $payment_applicant->setPaymentModelId($paymentMethod->getId());
         $payment_applicant->setPaidAt($paymentDate);
         $payment_applicant->setAcademicCostId($cost->getId());
         $payment_applicant->setAcademicProcessId(1);
         $payment_applicant->setAmount($cost->getAmount());
         $payment_applicant->setPayerType(PaymentJournal::PAYER_TYPE_APPLICANT);
         $payment_applicant->setStatus('S');
         $payment_applicant->setPaid($cost->getAmount());
         echo 'a';
         try {
             $payment_applicant->save();
         } catch (Exception $e) {
             $connection->rollback();
             $this->jsonwrapper->print_json(array('success' => false, 'code' => 'fail', 'message' => 'Error while save the data, please try again later.'));
         }
     }
     /* Commit Transaction */
     $connection->rollback();
     /*
     $connection->commit();
     */
     $this->jsonwrapper->print_json(array('success' => true, 'code' => 'success', 'message' => 'Data successfully saved', 'href' => $this->pmbTools->pmbUrl('')));
     /* ---- */
 }
Exemple #4
0
 public function executePrintForm()
 {
     $student = StudentPeer::retrieveByPK($this->getRequestParameter('student_id'));
     #$this->forward404Unless($student);
     $payment_model = PaymentModelPeer::retrieveByPK($this->getRequestParameter('payment_model_id'));
     #$this->forward404Unless($payment_model);
     $paid_at = $this->getRequestParameter('paid_at');
     $year = $this->getRequestParameter('year');
     $c = new Criteria();
     $c->add(PaymentJournalPeer::PAYER_TYPE, PaymentJournal::PAYER_TYPE_STUDENT);
     $c->add(PaymentJournalPeer::PAYER, $student->getId());
     $c->add(PaymentJournalPeer::ACADEMIC_PROCESS_ID, 2);
     $c->add(PaymentJournalPeer::STATUS, 'S');
     $c->add(PaymentJournalPeer::PAYMENT_MODEL_ID, $payment_model->getId());
     $c->add(PaymentJournalPeer::PAID_AT, $paid_at);
     $payments = PaymentJournal::doSelect($c);
     $total_cost = 0;
     foreach ($payments as $c) {
         $total_cost += $c->getAmount();
     }
     $this->student = $student;
     $this->payment_model = $payment_model;
     $this->paid_at = $paid_at;
     $this->year = $year;
     $this->actions = $actions;
     $this->subtitle = $student->toString();
     $this->type = '';
     $this->total_cost = $total_cost;
     $this->setViewClass('sfDomPDF');
     $this->payments = $payments;
 }
Exemple #5
0
 public function getPaymentModelRelatedByParent($con = null)
 {
     include_once 'lib/model/om/BasePaymentModelPeer.php';
     if ($this->aPaymentModelRelatedByParent === null && $this->parent !== null) {
         $this->aPaymentModelRelatedByParent = PaymentModelPeer::retrieveByPK($this->parent, $con);
     }
     return $this->aPaymentModelRelatedByParent;
 }