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'));
 }
Ejemplo n.º 2
0
/***********************************************************************************************************************
 * task routes
 **********************************************************************************************************************/
Route::group(['prefix' => 'task'], function () {
    // route to task view; show a specific task.
    Route::get('{task}', ['as' => 'task.show', 'uses' => 'TaskController@show']);
    //    ->before('cache.before')->after('cache.after');
    // insert a task
    Route::post('create/', ['as' => 'task.create', 'uses' => 'TaskController@create']);
    // delete a task
    Route::post('{task}', ['as' => 'task.destroy', 'uses' => 'TaskController@destroy']);
});
// ajax call to list all tasks.
Route::get('get_all_tasks', function () {
    $data = [];
    $tasks = TaskType::all();
    foreach ($tasks as $task) {
        $data[] = ['id' => $task->id, 'type' => $task->type];
    }
    return $data;
});
/***********************************************************************************************************************
* taskType routes
 **********************************************************************************************************************/
//Route::post('taskType/create/', ['as' => 'taskType.create', 'uses' => 'TaskTypeController@create']);
// route taskType.show denotes that we hit the endpoint directly, i.e.: www.timetrax.com/taskType/1
Route::get('taskType/{taskType}', ['as' => 'taskType.show', 'uses' => 'TaskTypeController@show']);
// route taskType.task.show denotes that we entered via the task view, clicking a glyphicon...
Route::get('taskType/{taskType}/task/{task}', ['as' => 'taskType.task.show', 'uses' => 'TaskTypeController@show']);
// form request to insert a task type.
// This is the only way that I found to get this to work?