Exemplo n.º 1
0
 function validate_cancel_input()
 {
     $result = new Result();
     if (!isset($_POST['leave_to_cancel']) || empty($_POST['leave_to_cancel'])) {
         $result->setResult(FALSE);
         $result->addError("Please select leave to cancel");
     }
     return $result;
 }
Exemplo n.º 2
0
 function is_valid_casual_leave($emp_id, $leave_start_date, $leave_end_date)
 {
     $result = new Result();
     // check if leave is comming into already taken leaves period
     $this->load->model('leave/leave_helper', 'lh');
     $clash_verification = $this->lh->verify_leaves_period($emp_id, $leave_start_date, $leave_end_date);
     $result->updateResult($clash_verification);
     // check if valid balance of casual leaves
     $avail_bal = $this->get_casual_leave_balance($emp_id);
     $applied_period = strtotime($leave_end_date) - strtotime($leave_start_date);
     $applied_period = floor($applied_period / (60 * 60 * 24)) + 1;
     if ($avail_bal < $applied_period) {
         $result->setResult(FALSE);
         $error = "Your leave length is more than available balance. " . "Your available casual leave balance is " . $avail_bal;
         $result->addError($error);
     }
     // check for maximum allowed casual leaves in one stretch
     if ($applied_period > 5) {
         $result->setResult(FALSE);
         $error = "You can take atmost 5 casual leaves in one stretch.";
         $result->addError($error);
     }
     return $result;
 }
Exemplo n.º 3
0
 function is_valid_restricted_leave($emp_id, $leave_date)
 {
     $result = new Result();
     // modify date to match db date format
     $leave_date = date('Y-m-d', strtotime($leave_date));
     // check if restricted holiday available
     $sql = "SELECT * FROM " . Leave_constants::$TABLE_RESTRICTED_HOLIDAYS . " WHERE holiday_date = '{$leave_date}'";
     $query = $this->db->query($sql);
     if ($query->num_rows() == 0) {
         $result->setResult(FALSE);
         $result->addError("No restricted holiday available.");
     }
     // check if leave is comming into already taken leaves period
     $this->load->model('leave/leave_helper', 'lh');
     $clash_verification = $this->lh->verify_leaves_period($emp_id, $leave_date, $leave_date);
     $result->updateResult($clash_verification);
     // check if balance for leave available
     $balance = $this->get_restricted_leave_balance($emp_id);
     if ($balance < 1) {
         $result->setResult(FALSE);
         $result->addError("Your don't have restricted leaves left.");
     }
     return $result;
 }
Exemplo n.º 4
0
 /**
  * Добавление сущности
  *
  * @param $data
  */
 public function add($data)
 {
     $data = $this->factoryEntity($data)->toArray();
     // Фильтруем данные
     $data = $this->filterOnAdd($data);
     // Валидируем данные
     $validator = $this->validateOnAdd($data);
     $result = new Result();
     if ($validator->isValid()) {
         try {
             $id = $this->insert($this->getName(), $data);
             if (!$id) {
                 $result->addError('Add ' . $this->getName() . ' failed', 'add_product_failed');
             }
         } catch (Exception $e) {
             $result->addError($e->getMessage(), $e->getCode());
         }
     }
     return $result->setResult($id);
 }
Exemplo n.º 5
0
 function check_for_weekend()
 {
     // result to resturn
     $result = new Result();
     $time = $this->leave_start_time;
     while ($this->leave_end_time >= $time) {
         $day_of_week = date('w', $time);
         if ($day_of_week == 0 || $day_of_week == 6) {
             $result->setResult(FALSE);
             $result->addError("Your leave includes weekend(s) please break it around them.");
             break;
         }
         $time += 24 * 60 * 60;
     }
     return $result;
 }
Exemplo n.º 6
0
 function is_valid_date_field()
 {
     // validate emptiness and format of date
     // start date <= end date
     // start date > todays date
     // start date must be less than 3 months from today
     // result to return
     $result = new Result();
     // check for valid start date
     $start_date = strtotime($_POST[Leave_application::LEAVE_START_DATE]);
     if (empty($start_date) || $start_date == FALSE) {
         $result->setResult(FALSE);
         $result->addError("Invalid start date format. It should be in format mm/dd/yyyy");
     }
     // check for valid end date if not restricted leave
     if (Leave_constants::$TYPE_RESTRICTED_LEAVE != $_POST[Leave_application::LEAVE_TYPE]) {
         // check for empty or invalid date field
         $end_date = strtotime($_POST[Leave_application::LEAVE_END_DATE]);
         if (empty($end_date) || $end_date == FALSE) {
             $result->setResult(FALSE);
             $result->addError("Invalid end date format. It should be in format mm/dd/yyyy");
         }
         // check if start date <= end date
         $diff = $end_date - $start_date;
         if ($diff < 0) {
             $result->setResult(FALSE);
             $result->addError("End date can not be before start date. Valid date format mm/dd/yyyy");
         }
     }
     // check if start date > todays date
     $today = strtotime(date('Y-m-d'));
     $diff = $start_date - $today;
     if ($diff <= 0) {
         $result->setResult(FALSE);
         $result->addError("Start date should be after today's date. Valid date format mm/dd/yyyy");
     }
     // leave can be applied only before 90 days from today
     $three_months_time = 90 * 24 * 60 * 60;
     if ($diff > $three_months_time) {
         $result->setResult(FALSE);
         $result->addError("Leave can be applied within 90 days from today");
     }
     return $result;
 }