/**
  *
  * @param <type> $request
  * @return <type>
  */
 public function execute($request)
 {
     $this->setLayout(false);
     sfConfig::set('sf_web_debug', false);
     sfConfig::set('sf_debug', false);
     if ($this->getRequest()->isXmlHttpRequest()) {
         $this->getResponse()->setHttpHeader('Content-Type', 'application/json; charset=utf-8');
     }
     $curId = $request->getParameter('curId');
     $payGradeId = $request->getParameter('payGradeId');
     $service = new PayGradeService();
     $status = $service->getCurrencyByCurrencyIdAndPayGradeId($curId, $payGradeId);
     return $this->renderText(json_encode($status->toArray()));
 }
 /**
  * Get Min and Max salary for given salary grade and currency
  *
  * @param sfWebRequest $request
  * @return JSON formatted JobSpec object
  */
 public function execute($request)
 {
     $this->setLayout(false);
     sfConfig::set('sf_web_debug', false);
     sfConfig::set('sf_debug', false);
     $salaryGrade = $request->getParameter('salaryGrade');
     $currency = $request->getParameter('currency');
     $minMax = array();
     if ($this->getRequest()->isXmlHttpRequest()) {
         $this->getResponse()->setHttpHeader('Content-Type', 'application/json; charset=utf-8');
     }
     if (!empty($salaryGrade) && !empty($currency)) {
         $service = new PayGradeService();
         $salaryCurrency = $service->getCurrencyByCurrencyIdAndPayGradeId($currency, $salaryGrade);
         if ($salaryCurrency) {
             $minMax = array('min' => $salaryCurrency->minSalary, 'max' => $salaryCurrency->maxSalary);
         }
     }
     return $this->renderText(json_encode($minMax));
 }
Ejemplo n.º 3
0
 public function postValidate($validator, $values)
 {
     $service = new PayGradeService();
     $salaryGrade = $values['sal_grd_code'];
     $salary = $values['basic_salary'];
     if (!empty($salaryGrade)) {
         $salaryDetail = $service->getCurrencyByCurrencyIdAndPayGradeId($values['currency_id'], $salaryGrade);
         if (empty($salaryDetail)) {
             $message = sfContext::getInstance()->getI18N()->__('Invalid Salary Grade.');
             $error = new sfValidatorError($validator, $message);
             throw new sfValidatorErrorSchema($validator, array('' => $error));
         } else {
             if (!empty($salaryDetail->minSalary) && $salary < $salaryDetail->minSalary || !empty($salaryDetail->maxSalary) && $salary > $salaryDetail->maxSalary) {
                 $message = sfContext::getInstance()->getI18N()->__('Salary should be within min and max');
                 $error = new sfValidatorError($validator, $message);
                 throw new sfValidatorErrorSchema($validator, array('basic_salary' => $error));
             }
         }
     } else {
         $values['sal_grd_code'] = null;
     }
     // cleanup cmbPayPeriod
     $payPeriod = $values['payperiod_code'];
     if ($payPeriod == '0' || ($payPeriod = '')) {
         $values['payperiod_code'] = null;
     }
     // Convert salary to a string. Since database field is a string field.
     // Otherwise, it may be converted to a string using scientific notation when encrypting.
     //
     // Remove trailing zeros - will always have decimal point, so
     // only trailing decimals are removed.
     $formattedSalary = rtrim(sprintf("%.2F", $salary), '0');
     // Remove decimal point (if it is the last char).
     $formattedSalary = rtrim($formattedSalary, '.');
     $values['basic_salary'] = $formattedSalary;
     return $values;
 }