예제 #1
0
 public function action_addtask($project_id)
 {
     if (!($project = Model_Project::find($project_id))) {
         \Fuel\Core\Session::set_flash('error', "Cannot find the selected project # {$project_id}");
         \Fuel\Core\Response::redirect_back('user/projects');
     }
     $val = Model_Projecttask::validate('create');
     if (\Fuel\Core\Input::method() == 'POST') {
         if ($val->run()) {
             $projecttask = Model_Projecttask::forge(array('project_id' => Input::post('project_id'), 'user_id' => Input::post('user_id'), 'project_task_name_id' => Input::post('project_task_name_id'), 'hourly_rate' => Input::post('hourly_rate'), 'task_status' => 0, 'task_due' => Input::post('task_due'), 'project_task_description' => Input::post('project_task_description'), 'comment' => Input::post('comment'), 'priority' => Input::post('priority')));
             if ($projecttask and $projecttask->save()) {
                 Session::set_flash('success', e('Added task #' . $projecttask->id . '.'));
                 Response::redirect('user/projects/view/' . $project_id);
             } else {
                 Session::set_flash('error', e('Could not save task.'));
             }
         } else {
             \Fuel\Core\Session::set_flash('error', $val->error());
         }
     }
     $this->load_presenter($project, Model_Projecttask::forge(array('id' => 0, 'project_id' => $project->id, 'user_id' => $this->current_user->id, 'task_status' => 0, 'hourly_rate' => 456, 'task_due' => date('Y-m-d'))));
     $this->template->set_global('project_task_names', Model_Projecttaskname::find('all', array('order_by' => array(array('name', 'asc')))));
     $this->template->set_global('users', array(Model_User::find($this->current_user->id)));
     $this->template->set_global('priorities', THelper::get_priorities());
     $this->template->title = 'My Projects';
     $this->template->content = Fuel\Core\View::forge('user/projects/addtask');
 }
예제 #2
0
 public static function get_tasks($user_id, $client_id, $project_id, $month, $year, $status, $order_by = array())
 {
     $where = array();
     if ($client_id > 0) {
         $where[] = array('project.customer_id', $client_id);
     }
     if ($user_id > 0) {
         $where[] = array('user_id', $user_id);
     }
     if ($project_id > 0) {
         $where[] = array('project_id', $project_id);
     }
     $month_start = $year . '-01-01';
     $month_end = date('Y-m-t', strtotime($year . '-' . date('m') . '-01'));
     if (intval($month) > 0) {
         $month_start = $year . '-' . str_pad($month, 2, '0', STR_PAD_LEFT) . '-01 00:00:00';
         $month_end = date('Y-m-t 23:59:59', strtotime($year . '-' . str_pad($month, 2, '0', STR_PAD_LEFT) . '-01'));
     }
     $where[] = array('task_status', $status);
     $order_by_fields = array();
     foreach ($order_by as $key => $val) {
         switch ($key) {
             case 'deadline':
                 $order_by_fields = array('task_due' => $val == 0 ? 'desc' : 'asc');
                 break;
             case 'project':
                 $order_by_fields = array('project.name' => $val == 0 ? 'desc' : 'asc');
                 break;
             case 'assignedto':
                 $order_by_fields = array('user.username' => $val == 0 ? 'desc' : 'asc');
                 break;
             case 'task':
                 $order_by_fields = array('project_task_description' => $val == 0 ? 'desc' : 'asc');
                 break;
             case 'priority':
                 $order_by_fields = array('priority' => $val == 0 ? 'desc' : 'asc');
                 break;
         }
         break;
     }
     $data = Model_Projecttask::find('all', array('where' => $where, 'related' => array('user', 'project', 'project_task_name', 'project_task_logs' => array('where' => array(array('task_started', '>=', $month_start), array('task_started', '<=', $month_end)))), 'order_by' => count($order_by_fields) == 0 ? array('priority' => 'desc', 'project.name' => 'asc') : $order_by_fields));
     //        $where[] = array();
     //
     //        // join with tasks which have no logs
     //        $dormant_tasks = Model_Projecttask::find('all', array(
     //            'where' => $where,
     //            'related' => array(
     //                'user',
     //                'project',
     //                'project_task_name',
     //                ''
     //            )
     //        ));
     return $data;
 }
				    <th>TASK</th>
				    <th>BILLABLE?</th>
				    <th style="width: 800px;">COMMENT</th>
				</tr>
                            </thead>
                            <tbody>
                                    <?php 
foreach ($timezones as $zone) {
    ?>
                                
                                        <?php 
    $checked = false;
    $comment = '';
    $date = date('Y-m-d', $timestamp);
    $log = new Model_Projecttasklog(array('id' => 0, 'is_billable' => 0));
    $current_task = Model_Projecttask::forge(array('id' => 0));
    foreach ($today_logs as $item) {
        $zone_starts = strtotime(date($date . ' ' . $zone->starts));
        $zone_ends = strtotime(date($date . ' ' . $zone->ends));
        if (in_array($zone_starts, range(strtotime($item->task_started), strtotime($item->task_completed) - 1))) {
            $checked = true;
            $log = $item;
            $current_task = $item->get_project_task();
            break;
        }
    }
    ?>
                                    <tr> 
                                        <td nowrap>
                                            <div class="checkbox">
                                                <label>
예제 #4
0
 public function action_logtimes($timestamp = null)
 {
     if (!Auth\Auth::has_access('timesheets.read')) {
         Fuel\Core\Session::set_flash('error', 'You do not have access to view timesheets');
         Fuel\Core\Response::redirect('user');
     }
     if (!$timestamp) {
         $timestamp = \Fuel\Core\Date::forge()->get_timestamp();
         // today
     }
     if (Fuel\Core\Input::method() == 'POST') {
         try {
             // start a db transaction
             \Fuel\Core\DB::start_transaction();
             // find all logs for this task for this day
             $date = date('Y-m-d', $timestamp);
             $starts = date('Y-m-d 00:00:00', $timestamp);
             $ends = date('Y-m-d 23:59:59', $timestamp);
             $project_task_logs = Model_Projecttasklog::find('all', array('related' => array('project_task'), 'where' => array(array('project_task.user_id', $this->current_user->id), array('task_started', 'BETWEEN', array($starts, $ends)))));
             foreach ($project_task_logs as $log) {
                 $date_starts = date('Y-m-d', $timestamp);
                 $date_ends = date('Y-m-d 23:59:59', $timestamp);
                 if ($log->get_project_task()->user_id == $this->current_user->id) {
                     if (in_array(strtotime($log->task_started), range(strtotime($date_starts), strtotime($date_ends)))) {
                         // delete the logs
                         $log->delete();
                     }
                 }
             }
             // insert new logs
             if (Fuel\Core\Input::post('timeslots')) {
                 $date = date('Y-m-d', $timestamp);
                 $last_comment = '';
                 $last_task_id = '';
                 foreach (Fuel\Core\Input::post('timeslots') as $str) {
                     $times = explode('_', $str);
                     $is_billable = 0;
                     $task_started = $date . ' ' . $times[0] . ':00';
                     $task_completed = $date . ' ' . $times[1] . ':00';
                     $project_task_id_array = Fuel\Core\Input::post('project_task_id');
                     $task_id = $project_task_id_array["'{$str}'"];
                     if (Fuel\Core\Input::post('comment_' . $str) != '') {
                         $last_comment = Fuel\Core\Input::post('comment_' . $str);
                     }
                     if (intval(Fuel\Core\Input::post('is_billable_' . $str, '0')) == 1) {
                         $is_billable = 1;
                     }
                     if (empty($task_id)) {
                         $task_id = $last_task_id;
                     } else {
                         $last_task_id = $task_id;
                     }
                     if (empty($task_id)) {
                         continue;
                         // todo - display error
                     }
                     $task_log = Model_Projecttasklog::forge(array('project_task_id' => $task_id, 'comment' => $last_comment, 'task_started' => $task_started, 'task_completed' => $task_completed, 'is_billable' => $is_billable));
                     $task_log->save();
                 }
             }
             // commit to database
             \Fuel\Core\DB::commit_transaction();
             \Fuel\Core\Session::set_flash('success', 'Time logs saved successfully.');
             Fuel\Core\Response::redirect('user/timesheets/index/' . $timestamp);
         } catch (Exception $ex) {
             // rollback on error
             \Fuel\Core\DB::rollback_transaction();
             \Fuel\Core\Session::set_flash('error', $ex->getMessage());
             Fuel\Core\Response::redirect('user/timesheets/advanced/logtimes/' . $timestamp);
         }
     }
     $now = \Fuel\Core\Date::forge($timestamp)->format('mysql');
     $day_starts = date('Y-m-d 00:00:00', strtotime($now));
     $day_ends = date('Y-m-d 23:59:59', strtotime($now));
     $today_logs = Model_Projecttasklog::find('all', array('related' => array('project_task', 'project_task.project', 'project_task.project_task_name', 'project_task.user'), 'where' => array(array('task_started', 'BETWEEN', array($day_starts, $day_ends)), array('project_task.user_id', $this->current_user->id)), 'order_by' => array(array('task_started', 'asc'))));
     // todo: use DB::query() instead
     $this->template->set_global('today_logs', $today_logs);
     $this->template->set_global('projects', Model_Project::find('all', array('order_by' => array(array('name', 'asc')))));
     $this->template->set_global('timezones', Model_Timezone::find('all', array('order_by' => array(array('starts', 'asc')))));
     $this->template->set_global('my_tasks', Model_Projecttask::find('all', array('where' => array(array('user_id', $this->current_user->id)), 'related' => array('project_task_name'), 'order_by' => array(array('project_task_description', 'asc')))));
     $this->template->set_global('timestamp', $timestamp);
     $this->template->set_global('date', \Fuel\Core\Date::forge($timestamp)->format('mysql_date'));
     $this->template->title = 'Timesheets';
     $this->template->content = View::forge('user/timesheets/advanced/_advanced_form');
 }
예제 #5
0
 public static function get_dashboard_stats($user_id = null)
 {
     if ($user_id == null || !is_numeric($user_id) || intval($user_id) < 1) {
         $user_id = 0;
     }
     // load my open task
     if ($user_id > 0) {
         // load user's open tasks for quick access on dashboard
         $data['open_tasks'] = Model_Projecttask::find('all', array('where' => array(array('user_id', $user_id), array('task_status', 0)), 'related' => array('user', 'project', 'project_task_name'), 'order_by' => array('priority' => 'desc', 'project.name' => 'asc'), 'offset' => 0, 'limit' => 10));
         // load projects for this month (this user)
         $data['projects'] = Model_Projectmember::find('all', array('related' => array('user', 'project'), 'where' => array(array('user_id', $user_id), array('project.start_date', '>=', date('Y-m-01')), array('project.close_date', '<=', date('Y-m-t'))), 'order_by' => array('project.name' => 'asc')));
         // load user's times logged this month
         $data['logs'] = Model_Projecttasklog::find('all', array('related' => array('project_task'), 'where' => array(array('task_started', '>=', date('Y-m-01')), array('task_started', '<=', date('Y-m-t')), array('project_task.user_id', $user_id))));
     } else {
         // load open tasks for quick access on dashboard (Maximum of 10)
         $data['open_tasks'] = Model_Projecttask::find('all', array('where' => array(array('task_status', 0)), 'related' => array('user', 'project', 'project_task_name'), 'order_by' => array('priority' => 'desc', 'project.name' => 'asc'), 'offset' => 0, 'limit' => 10));
         // load projects for this month (all members)
         $data['projects'] = Model_Projectmember::find('all', array('related' => array('user', 'project'), 'where' => array(array('project.start_date', '>=', date('Y-m-01')), array('project.close_date', '<=', date('Y-m-t'))), 'order_by' => array('project.name' => 'asc')));
         // load all times logged this month
         $data['logs'] = Model_Projecttasklog::find('all', array('related' => array('project_task'), 'where' => array(array('task_started', '>=', date('Y-m-01')), array('task_started', '<=', date('Y-m-t')))));
     }
     $weekly['hours'] = 0;
     $weekly['billable-hours'] = 0;
     $weekly['billable-amount'] = 0;
     $weekly['unbillable-amount'] = 0;
     $weekly['unbillable-hours'] = 0;
     $monthly['hours'] = 0;
     $monthly['billable-hours'] = 0;
     $monthly['billable-amount'] = 0;
     $monthly['unbillable-amount'] = 0;
     $monthly['unbillable-hours'] = 0;
     $data['user_targets'] = array();
     $users = Model_User::find('all', array('order_by' => array(array('first_name', 'asc'), array('last_name', 'asc')), 'where' => array('id' => $user_id > 0 ? array('id', $user_id) : array('id', '>', 0))));
     foreach ($users as $user) {
         $data['user_targets']['_' . $user->id . '_'] = array('user' => $user, 'logged_billable' => 0, 'logged_unbillable' => 0);
     }
     foreach ($data['logs'] as $log) {
         $monthly['hours'] += $log->get_hours_spent();
         $monthly['billable-hours'] += $log->get_billable_hours_spent();
         $monthly['billable-amount'] += $log->project_task->hourly_rate * $log->get_billable_hours_spent();
         $monthly['unbillable-hours'] += $log->get_unbillable_hours_spent();
         $monthly['unbillable-amount'] += $log->project_task->hourly_rate * $log->get_unbillable_hours_spent();
         if (date('W') == date('W', strtotime($log->task_started))) {
             $weekly['hours'] += $log->get_hours_spent();
             $weekly['billable-hours'] += $log->get_billable_hours_spent();
             $weekly['billable-amount'] += $log->project_task->hourly_rate * $log->get_billable_hours_spent();
             $weekly['unbillable-hours'] += $log->get_unbillable_hours_spent();
             $weekly['unbillable-amount'] += $log->project_task->hourly_rate * $log->get_unbillable_hours_spent();
         }
         if (isset($data['user_targets']['_' . $log->get_project_task()->user_id . '_'])) {
             if ($log->task_is_billable()) {
                 $data['user_targets']['_' . $log->get_project_task()->user_id . '_']['logged_billable'] += $log->get_billable_hours_spent();
             } else {
                 $data['user_targets']['_' . $log->get_project_task()->user_id . '_']['logged_unbillable'] += $log->get_unbillable_hours_spent();
             }
         }
     }
     $data['weekly_stats'] = $weekly;
     $data['monthly_stats'] = $monthly;
     return $data;
 }
 public function get_project_task()
 {
     return !is_null($this->project_task) ? $this->project_task : Model_Projecttask::forge(array('id' => 0));
 }
예제 #7
0
 public static function action_reopentask($task_id = null)
 {
     if (!($task = Model_Projecttask::find($task_id))) {
         \Fuel\Core\Session::set_flash('error', 'Cannot find task # ' . $task_id);
         \Fuel\Core\Response::redirect_back('user/timesheets');
     }
     $task->task_status = 0;
     if ($task->save()) {
         \Fuel\Core\Session::set_flash('success', 'Successfully reopened task # ' . $task_id);
     } else {
         \Fuel\Core\Session::set_flash('error', 'Cannot reopen task # ' . $task_id);
     }
     \Fuel\Core\Response::redirect('user/timesheets/view/' . $task_id);
 }