public function afterSave($created)
 {
     parent::afterSave($created);
     if (isset($this->data['ScheduleStatus'])) {
         $scheduleItems['schedule_id'] = $this->id;
         $scheduleItems['user_id'] = trim($this->data['ScheduleStatus']['user_id']);
         $scheduleItems['status'] = trim($this->data['ScheduleStatus']['status']);
         $scheduleItems['status_date'] = trim($this->data['ScheduleStatus']['status_date']);
         $scheduleItems['comments'] = trim($this->data['ScheduleStatus']['comment']);
         $scheduleItems['type'] = trim($this->data['ScheduleStatus']['type']);
         $this->ScheduleStatus->save($scheduleItems);
     }
 }
Exemplo n.º 2
0
 public function afterSave($created)
 {
     parent::afterSave($created);
     if (isset($this->data['ScheduleItem'])) {
         // delete
         App::uses("ScheduleItem", "ScheduleManager.Model");
         $scheduleItemModel = new ScheduleItem();
         //debug($this->id);
         //debug($this->data['ServiceEntry']['type']);exit;
         $scheduleItemModel->deleteAll(array('ScheduleItem.schedule_id' => $this->id, 'ScheduleItem.type' => $this->data['ServiceEntry']['type']));
         if (is_array($this->data['ScheduleItem'])) {
             // save
             $scheduleItems = array();
             $index = -1;
             foreach ($this->data['ScheduleItem'] as $scheduleItem) {
                 if (trim($scheduleItem['quantity']) == '' || $scheduleItem['quantity'] == 0 || trim($scheduleItem['code']) == '') {
                     continue;
                     // skip if no data
                 }
                 $index++;
                 $scheduleItems[$index]['schedule_id'] = $this->id;
                 $scheduleItems[$index]['purchase_order_id'] = $scheduleItem['purchase_order_id'];
                 $scheduleItems[$index]['code'] = trim($scheduleItem['code']);
                 $scheduleItems[$index]['quantity'] = trim($scheduleItem['quantity']);
                 $scheduleItems[$index]['reason'] = trim($scheduleItem['reason']);
                 $scheduleItems[$index]['type'] = trim($this->data['ServiceEntry']['type']);
                 $itemType = explode('|', $scheduleItems[$index]['code']);
                 if ($itemType[1] == 'item') {
                     $scheduleItems[$index]['item_id'] = trim($itemType[0]);
                 } elseif ($itemType[1] == 'cabinet') {
                     $scheduleItems[$index]['cabinet_id'] = trim($itemType[0]);
                 } elseif ($itemType[1] == 'door' || $itemType[1] == 'wall_door' || $itemType[1] == 'drawer') {
                     $scheduleItems[$index]['door_id'] = trim($itemType[0]);
                 }
             }
             if ($index >= 0) {
                 $flag = $scheduleItemModel->saveAll($scheduleItems);
             } else {
                 return false;
             }
         }
     } elseif (isset($this->data['ScheduleStatus'])) {
         $scheduleItems['schedule_id'] = $this->id;
         $scheduleItems['user_id'] = trim($this->data['ScheduleStatus']['user_id']);
         $scheduleItems['status'] = trim($this->data['ScheduleStatus']['status']);
         $scheduleItems['status_date'] = trim($this->data['ScheduleStatus']['status_date']);
         $scheduleItems['comments'] = trim($this->data['ScheduleStatus']['comment']);
         $scheduleItems['type'] = trim($this->data['ScheduleStatus']['type']);
         $this->ScheduleStatus->save($scheduleItems);
     }
 }
 public function afterSave($created)
 {
     parent::afterSave($created);
 }