/**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new Servicecalls();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['Servicecalls'])) {
         $model->attributes = $_POST['Servicecalls'];
         if ($model->save()) {
             $this->redirect(array('view', 'id' => $model->id));
         }
     }
     $this->render('create', array('model' => $model));
 }
 public function insertservicecall($service)
 {
     $model = new Servicecalls();
     $model->service_reference_number = $service->service_reference_number;
     $model->engineer_email = $service->engineer_email;
     $model->engineer_user_id = $this->getuseridofengineerbyengineeremail($service->engineer_email);
     $model->callcenter_account_id = $service->gomobile_account_id;
     $model->customer_fullname = $service->customer_fullname;
     $model->customer_address = $service->customer_address;
     $model->customer_postcode = $service->customer_postcode;
     $model->data_recieved = json_encode($service->data);
     $model->jobstatus_id = 1;
     ///for new job
     ///communications needs to be initialised here
     //echo json_encode($service->allchatmessage);
     $chatarray['chats'] = array();
     $amica_chat_array = array();
     $amica_chat_array['date'] = $service->allchatmessage->chats->date;
     $amica_chat_array['person'] = $service->allchatmessage->chats->person;
     $amica_chat_array['message'] = $service->allchatmessage->chats->message;
     array_push($chatarray['chats'], $amica_chat_array);
     $model->communications = json_encode($chatarray);
     if ($model->save()) {
         return 'Successfully saved';
     } else {
         return 'Error in saving Please call support';
     }
 }