/** * [saveModel - Save our worklog to the DB] * @param boolean $werklog [description] * @return [Eloquent model] [The saved worklog model] */ protected function saveModel($werklog = false) { if (Input::get('id')) { $werklog = Werklog::find(Input::get('id')); } if (!$werklog) { $werklog = new Werklog(); } // load relations $load_curr_company = $werklog->company; $load_curr_project = $werklog->project; $load_curr_user = $werklog->user; $load_curr_strippenkaart = $werklog->strippenkaart; $werklog->date = Input::get('date'); $werklog->company_id = Input::get('company_id'); $werklog->project_id = Input::get('project_id'); if (Input::get('strippenkaarten_id')) { $werklog->strippenkaarten_id = Input::get('strippenkaarten_id'); } $werklog->user_id = Input::get('user_id'); $werklog->minutes = Input::get('minutes'); $werklog->description = Input::get('description'); $werklog->comment = Input::get('comment'); $werklog->billable = Input::get('billable'); $werklog->processed = Input::get('processed'); $werklog->save(); return $werklog; }
/** * [store - jira weebhook handler] * @return [void] [] */ public function store() { $post_data = file_get_contents("php://input"); mail('*****@*****.**', 'jira_posted_data', $post_data); $reply = json_decode($post_data); $status_id = $reply->issue->fields->status->id; //error_log('status_id: '.$status_id); if ($status_id === Config::get('eenvoudcrm.jira_status_closed') || $status_id === Config::get('eenvoudcrm.jira_status_done')) { mail('*****@*****.**', 'jira_new_worklog', $post_data); $worklog = new Werklog(); $worklog->description = 'Issue ' . $reply->issue->id . ' - ' . $reply->issue->fields->summary; $worklog->minutes = (int) $reply->issue->fields->timetracking->timeSpentSeconds / 60.0; $worklog->date = date("Y-m-d"); $worklog->billable = 1; $jira_username = $reply->user->name; $user = User::whereRaw("username like '%" . $jira_username . "%'")->first(); if ($user) { $worklog->user_id = $user->id; } else { $worklog->user_id = Config::get('eenvoudcrm.default_user_id'); } $jira_id = $reply->issue->fields->project->id; $project = Project::where('jira_id', '=', $jira_id)->first(); if ($project) { $worklog->company_id = $project->company_id; $worklog->project_id = $project->id; } else { $worklog->company_id = Config::get('eenvoudcrm.default_company_id'); $worklog->project_id = Config::get('eenvoudcrm.default_project_id'); } try { $worklog->save(); } catch (Exception $e) { error_log(json_encode($e)); } } }
/** * [processRoadmapWorklogs - process withstanding roadmap logs] * @return [array] [the roadmap entries] */ public static function processRoadmapWorklogs() { // dates $today = date("Ymd"); $yesterday = date("Ymd", strtotime("yesterday")); // time entries $roadmap_project_id = Config::get('eenvoudcrm.main_roadmap_project_id'); list($worklog_entries_status, $worklog_entries) = IntegrationRoadmapController::getProjectWorklogEntries($roadmap_project_id, $yesterday, $today); if ($worklog_entries_status) { // foreach of the entries create a new worklog and save it foreach ($worklog_entries as $key => $value) { // check if this ID is unique $roadmap_id = $value->ID; $roadmap_worklogs = Werklog::where('roadmap_id', '=', $roadmap_id)->first(); if (!$roadmap_worklogs) { $worklog = new Werklog(); $date = explode("T", $value->Date, 2); $worklog->date = $date[0]; $worklog->roadmap_id = (int) $value->ID; // default project and company ID $worklog->project_id = null; $worklog->company_id = Config::get('eenvoudcrm.default_company_id'); //mail('*****@*****.**', 'resource_id', $value->Resource->ID); $user = User::where('roadmap_resource_id', '=', $value->Resource->ID)->first(); if ($user) { $worklog->user_id = $user->id; } else { $worklog->user_id = Config::get('eenvoudcrm.default_user_id'); } $worklog->minutes = round((double) $value->Time * 60.0); $worklog->description = $value->Description; $worklog->billable = 1; $worklog->processed = 0; $worklog->save(); } else { error_log('Roadmap worklogs: Skipping duplicated entry ' . $roadmap_id); } } return $worklog_entries; } return false; }