/**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function destroy($memberId, $pointId)
 {
     $point = Point::find($pointId);
     $member = Member::find($memberId);
     $member->update(['total_points' => $member->total_points - $point->point]);
     $point->Delete('set null');
     return redirect()->action('MembersController@show', $memberId);
 }
 public function add()
 {
     $activeTab = Input::get('task_type_id') ? Input::get('task_type_id') : '1';
     $task_types = TaskType::all();
     $saleTypes = SaleType::all();
     $user = Auth::user();
     $point = intval(Input::get('point'));
     $task = Task::findOrFail(Input::get('task_id'));
     $pointAudit = new PointAudit();
     $pointAudit->point = $point * $task->value;
     $pointAudit->user_id = $user->id;
     $pointAudit->company_id = $user->company_id;
     $pointAudit->date = new \DateTime();
     $pointAudit->task_id = $task->id;
     $pointAudit->save();
     $pointID = $user->id . date("mdY");
     $pointEntity = Point::find($pointID);
     if ($pointEntity != null) {
         $pointEntity->points = $pointEntity->points + $point * $task->value;
         $pointEntity->update();
     } else {
         $pointEntity = new Point();
         $pointEntity->id = $pointID;
         $pointEntity->month = date("m");
         $pointEntity->year = date("Y");
         $pointEntity->user_id = $user->id;
         $pointEntity->company_id = $user->company_id;
         $pointEntity->points = $point * $task->value;
         $pointEntity->save();
     }
     $message = 'You have ' . ($pointAudit->point > 0 ? 'added' : 'adjusted') . ' <strong> ' . intval($point) . ' points</strong> to <strong>' . $task->name . '</strong>.';
     $today_total = $this->getTodaysStats();
     $today_target = 140;
     $isErr = false;
     return view('myStat.add', compact('user', 'today_total', 'task_types', 'tasks', 'activeTab', 'isErr', 'message', 'today_target', 'saleTypes'));
 }
 /**
  * Update the values of a point.
  *
  * @param int $id The id of the point
  *
  * @return mixed JSON object with the point data
  */
 public function update($id)
 {
     try {
         $point = Point::find($id);
         if (!$point->created_by == $this->user || !$this->user->role->name == 'admin') {
             return $this->respondRestricted('You did not create this point or you do not have the right role!');
         }
         $point->name = Input::get('name', $point->name);
         $point->description = Input::get('description', $point->description);
         $point->latitude = Input::get('longitude', $point->longitude);
         $point->longitude = Input::get('latitude', $point->latitude);
         $point->country = Input::get('country', $point->country);
         $point->updated_at = date('Y-m-d H:i:s');
         $point->updated_by = Auth::user()->id;
         if (!$point->save()) {
             return $this->respondInternalError('Could not save point!');
         }
         return Fractal::item($point, new PointTransformer())->responseJson(200);
     } catch (Exception $e) {
         return $this->respondWithError();
     }
 }