2017-07-25 65 views
1

在這裏,我使用明智的時間安排和額外的時間安排明智地設置治療師的工作時間。 治療師南希fernadez時間安排是:如何解決codeigniter中的日曆任務問題?

  1. 額外的(附加)爲她工作的時間日期31-05-2017 10:00:00至14:00:00,即在12小時內爲10 :上午00時至下午2時
  2. 安排工作時間爲她的日期31-05-2017是14:00:00至19:00:00即在12小時是下午2:00至7:00

    南希fernadez是全天候上班,即上午10:00至下午7:00。

    問題: 我預訂的時間是從13:25到14:25,即下午01:25到02:25。它會給我像治療師不可用當時的錯誤...其實按照時間表南希可這個時候......

這裏是任務分配日曆的圖像

enter image description here

這裏,下面是我的MySQL查詢的其他工作時間爲她

SELECT SQL_CALC_FOUND_ROWS * 
FROM `extra_day` 
INNER JOIN `therapist` ON `thrp_id` = `exd_thrp_id` 
WHERE `exd_thrp_id` = '3' 
AND `exd_date` = '2017-05-31' 
AND `exd_from` <= '13:25:00' 
AND `exd_to` >= '14:25:00' 

這裏,是我下面的MySQL查詢的時間表明智的工作時間爲她

SELECT SQL_CALC_FOUND_ROWS s.*, CONCAT(th.thrp_fname, " ", th.thrp_surname) AS thrp_name 
FROM `schedule` `s` 
INNER JOIN `therapist` `th` ON `s`.`schd_thrp_id` = `th`.`thrp_id` 
WHERE `schd_thrp_id` = '3' 
AND `schd_day` = '3' 
AND `schd_from` <= '13:25:00' 

我用下面控制器

// check if therapist comes on this day (regular schedule or extra day) 
      $this->load->model('schedule_model'); 
      $schedule = $this->schedule_model->Get(NULL, array('schd_thrp_id' => $data['bk_thrp_id'], 
       'schd_day' => date('N', strtotime($data['bk_start'])), 
       'schd_from' => date('H:i:s', strtotime($data['bk_start'])) 
      )); 

      $this->load->model('additional_work_model'); 
      $additional_work = $this->additional_work_model->Get(NULL, array('exd_thrp_id' => $data['bk_thrp_id'], 
       'exd_date' => date('Y-m-d', strtotime($data['bk_start'])), 
       'exd_from' => date('H:i:s', strtotime($data['bk_start'])), 
       'exd_to' => date('H:i:s', strtotime($data['bk_end'])) 
      )); 
      if ($schedule['countFiltered'] == 0 && $additional_work['countFiltered'] == 0) { 
       $response['status'] = 'failure'; 
       $response['errormsg'] = 'Therapist not available.'; 
       return $response; 
      } 

請提問,如果檢查治療的有效性任何與問題相關的查詢

感謝您的幫助...

+0

你仍然沒有找到解決方案? – Nawin

+0

@Nawin,Nope我沒有找到 – Angel

回答

0

您需要更改查詢。因爲extra_dayexd_from條件工作,但exd_to條件將不起作用,因爲到時間只有14:00:00。而第二個查詢不會得到,因爲開始時間爲14:00:00,但您得到13:25:00。你需要加入這兩個表來得到結果。或者你需要給一定的條件一樣,如果員工工作extra_day行數

UPDATE

我與我的假設更改您的查詢,你可以改變它喜歡和連接查詢,你也可以改變你想要的表:

SELECT SQL_CALC_FOUND_ROWS *, exd_date, exd_from, exd_to 
FROM `extra_day` 
INNER JOIN `therapist` ON `thrp_id` = `exd_thrp_id` 
WHERE `exd_thrp_id` = '3' 
AND `exd_date` = '2017-05-31' 
AND `exd_from` <= '13:25:00' 
AND `exd_to` >= '14:25:00' 

SELECT SQL_CALC_FOUND_ROWS s.*, CONCAT(th.thrp_fname, " ", th.thrp_surname) AS thrp_name, schd_from 
FROM `schedule` `s` 
INNER JOIN `therapist` `th` ON `s`.`schd_thrp_id` = `th`.`thrp_id` 
WHERE `schd_thrp_id` = '3' 
AND `schd_day` = '3' 
AND `schd_from` <= '13:25:00' 

$this->load->model('schedule_model'); 
$schedule = $this->schedule_model->Get(NULL, array('schd_thrp_id' => $data['bk_thrp_id'], 
    'schd_day' => date('N', strtotime($data['bk_start'])), 
    'schd_from' => date('H:i:s', strtotime($data['bk_start'])) 
)); 

$this->load->model('additional_work_model'); 
$additional_work = $this->additional_work_model->Get(NULL, array('exd_thrp_id' => $data['bk_thrp_id'], 
    'exd_date' => date('Y-m-d', strtotime($data['bk_start'])), 
    'exd_from' => date('H:i:s', strtotime($data['bk_start'])), 
    'schd_to' => date('H:i:s', strtotime($data['bk_end'])) 
)); 
if($additional_work['exd_from'] <= date('H:i:s', strtotime($data['bk_start'])) && $schedule['schd_from'] >= date('H:i:s', strtotime($data['bk_start']))){ 
    $get_now_with_anymodel = $this->your_model->Get(NULL, array('exd_thrp_id' => $data['bk_thrp_id'], 
    'exd_date' => date('Y-m-d', strtotime($data['bk_start'])), 
    'exd_from' => date('H:i:s', strtotime($data['bk_start'])), 
    'exd_to' => date('H:i:s', strtotime($data['bk_end'])) 
    /* 
    Your Model query: 
    SELECT SQL_CALC_FOUND_ROWS *, exd_date, exd_from, exd_to 
    FROM `extra_day` AS A 
    INNER JOIN `therapist` AS B ON B.`thrp_id` = A.`exd_thrp_id` 
    INNER JOIN `schedule` AS C ON C.`schd_thrp_id` = A.`exd_thrp_id` 
    WHERE `exd_thrp_id` = '3' 
    AND `exd_date` = '2017-05-31' 
    AND A.`exd_from` <= '13:25:00' 
    AND C.`schd_to` >= '14:25:00' 
    */ 
)); 
} 

$ additional_work [「exd_from」]是從模型的返回結果改變它,怎麼樣,你返回數據

+0

是的,我知道。但我怎麼能改變查詢。我改變這個問題的查詢,然後它可能會影響到另一個預訂。 – Angel

+0

我無法加入兩個表格,因爲額外的工作和額外的工作是我的結構中的兩個不同的模型。如果我組合兩個表格,爲此我必須創建無效的新模型。如果我在其他預訂模式中加入兩張表格,那麼它會損害另一個預訂。 – Angel

+0

您有'schd_to'字段嗎? – Nawin