Exemplo n.º 1
0
 public function getPaymentApplicantsJoinPaymentModel($criteria = null, $con = null)
 {
     include_once 'lib/model/om/BasePaymentApplicantPeer.php';
     if ($criteria === null) {
         $criteria = new Criteria();
     } elseif ($criteria instanceof Criteria) {
         $criteria = clone $criteria;
     }
     if ($this->collPaymentApplicants === null) {
         if ($this->isNew()) {
             $this->collPaymentApplicants = array();
         } else {
             $criteria->add(PaymentApplicantPeer::ACADEMIC_COST_ID, $this->getId());
             $this->collPaymentApplicants = PaymentApplicantPeer::doSelectJoinPaymentModel($criteria, $con);
         }
     } else {
         $criteria->add(PaymentApplicantPeer::ACADEMIC_COST_ID, $this->getId());
         if (!isset($this->lastPaymentApplicantCriteria) || !$this->lastPaymentApplicantCriteria->equals($criteria)) {
             $this->collPaymentApplicants = PaymentApplicantPeer::doSelectJoinPaymentModel($criteria, $con);
         }
     }
     $this->lastPaymentApplicantCriteria = $criteria;
     return $this->collPaymentApplicants;
 }
Exemplo n.º 2
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('')));
     /* ---- */
 }
Exemplo n.º 3
0
 public function executeUpdatePayment()
 {
     $user_id = $this->getContext()->getUser()->getAttribute('user_id', null, 'bo');
     $applicant = TestApplicantPeer::retrieveByPk($user_id);
     $this->forward404Unless($applicant);
     $applicant_detail = $applicant->getTestApplicantDetail();
     $tanggal = $this->getRequestParameter('thn') . '-' . $this->getRequestParameter('bln') . '-' . $this->getRequestParameter('tgl');
     $applicant->setStatus(StudentDetail::CONFIRM);
     $applicant->save();
     $reg_test_period = RegTestPeriodPeer::retrieveByPK($applicant->getRegTestPeriod1());
     $c = new Criteria();
     $cton1 = $c->getNewCriterion(AcademicCostPeer::ACADEMIC_CALENDAR_ID, $reg_test_period->getRegPeriod()->getAcademicCalendarId(), Criteria::IN);
     $cton2 = $c->getNewCriterion(AcademicCostPeer::ACADEMIC_PROCESS_ID, 1, Criteria::IN);
     $cton3 = $c->getNewCriterion(AcademicCostPeer::ACADEMIC_COST_COMPONENT_ID, 11, 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($this->getRequestParameter('payment_model_id'));
         $payment_applicant->setPaidAt($tanggal);
         $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());
         $payment_applicant->save();
     }
     #return $this->redirect('auth/finish');
     return $this->redirect('auth/test');
 }
Exemplo n.º 4
0
 public static function retrieveByPKs($pks, $con = null)
 {
     if ($con === null) {
         $con = Propel::getConnection(self::DATABASE_NAME);
     }
     $objs = null;
     if (empty($pks)) {
         $objs = array();
     } else {
         $criteria = new Criteria();
         $criteria->add(PaymentApplicantPeer::ID, $pks, Criteria::IN);
         $objs = PaymentApplicantPeer::doSelect($criteria, $con);
     }
     return $objs;
 }
Exemplo n.º 5
0
 public function fromArray($arr, $keyType = BasePeer::TYPE_PHPNAME)
 {
     $keys = PaymentApplicantPeer::getFieldNames($keyType);
     if (array_key_exists($keys[0], $arr)) {
         $this->setId($arr[$keys[0]]);
     }
     if (array_key_exists($keys[1], $arr)) {
         $this->setAcademicCostId($arr[$keys[1]]);
     }
     if (array_key_exists($keys[2], $arr)) {
         $this->setTestApplicantId($arr[$keys[2]]);
     }
     if (array_key_exists($keys[3], $arr)) {
         $this->setAcademicProcessId($arr[$keys[3]]);
     }
     if (array_key_exists($keys[4], $arr)) {
         $this->setAmount($arr[$keys[4]]);
     }
     if (array_key_exists($keys[5], $arr)) {
         $this->setPayerType($arr[$keys[5]]);
     }
     if (array_key_exists($keys[6], $arr)) {
         $this->setPaid($arr[$keys[6]]);
     }
     if (array_key_exists($keys[7], $arr)) {
         $this->setStatus($arr[$keys[7]]);
     }
     if (array_key_exists($keys[8], $arr)) {
         $this->setPaymentModelId($arr[$keys[8]]);
     }
     if (array_key_exists($keys[9], $arr)) {
         $this->setPaidAt($arr[$keys[9]]);
     }
 }