芝麻web文件管理V1.00
编辑当前文件:/home/qrafawbu/qrafiqxcreativeagency.com/accounts/office/app/DataTables/TimeLogsDataTable.php
editTimelogPermission = user()->permission('edit_timelogs'); $this->deleteTimelogPermission = user()->permission('delete_timelogs'); $this->viewTimelogPermission = user()->permission('view_timelogs'); $this->approveTimelogPermission = user()->permission('approve_timelogs'); $this->viewTimelogEarningsPermission = user()->permission('view_timelog_earnings'); } /** * @param mixed $query * @return \Yajra\DataTables\DataTableAbstract|\Yajra\DataTables\EloquentDataTable */ public function dataTable($query) { $datatables = datatables()->eloquent($query); $datatables->addIndexColumn(); $datatables->addColumn('check', function ($row) { return '
'; }); $datatables->addColumn('action', function ($row) { $action = '
'; $action .= '
' . __('app.view') . '
'; if (!is_null($row->end_time)) { if ($this->approveTimelogPermission == 'all') { if (!$row->approved) { $action .= '
' . trans('app.approve') . '
'; } } if ( $this->editTimelogPermission == 'all' || ($row->project_admin == user()->id) || ($this->editTimelogPermission == 'added' && $row->added_by == user()->id) || ($this->editTimelogPermission == 'owned' && (($row->project && $row->project->client_id == user()->id) || $row->user_id == user()->id) ) || ($this->editTimelogPermission == 'both' && (($row->project && $row->project->client_id == user()->id) || $row->user_id == user()->id || $row->added_by == user()->id)) ) { $action .= '
' . trans('app.edit') . '
'; } if ($this->deleteTimelogPermission == 'all' || ($this->deleteTimelogPermission == 'added' && user()->id == $row->added_by) || ($row->project_admin == user()->id) ) { $action .= '
' . trans('app.delete') . '
'; } } else { if ($this->editTimelogPermission == 'all' || ($this->editTimelogPermission == 'added' && user()->id == $row->added_by) || ($row->project_admin == user()->id) ) { $action .= '
' . trans('app.stop') . '
'; } } $action .= '
'; return $action; }); $datatables->addColumn('employee_name', function ($row) { return $row->user->name; }); $datatables->editColumn('name', function ($row) { return view('components.employee', [ 'user' => $row->user ]); }); $datatables->editColumn('start_time', function ($row) { return $row->start_time->timezone($this->company->timezone)->translatedFormat($this->company->date_format . ' ' . $this->company->time_format); }); $datatables->editColumn('end_time', function ($row) { if (!is_null($row->end_time)) { return $row->end_time->timezone($this->company->timezone)->translatedFormat($this->company->date_format . ' ' . $this->company->time_format); } elseif (!is_null($row->activeBreak)) { return "
" . __('modules.timeLogs.paused') . '
'; } else { return "
" . __('app.active') . '
'; } }); $datatables->editColumn('total_hours', function ($row) { if (is_null($row->end_time)) { $totalMinutes = (($row->activeBreak) ? $row->activeBreak->start_time->diffInMinutes($row->start_time) : now()->diffInMinutes($row->start_time)) - $row->breaks->sum('total_minutes'); $timeLog = '
' . CarbonInterval::formatHuman($totalMinutes) . '
'; /** @phpstan-ignore-line */ $timeLog .= '
'; } else { $totalMinutes = $row->total_minutes - $row->breaks->sum('total_minutes'); $timeLog = '
' . CarbonInterval::formatHuman($totalMinutes) . ' ' . '
'; /** @phpstan-ignore-line */ if ($row->approved) { $timeLog .= '
'; } } return $timeLog; }); $datatables->editColumn('earnings', function ($row) { if (is_null($row->hourly_rate)) { return '--'; } return currency_format($row->earnings, company()->currency_id); }); $datatables->editColumn('project_name', function ($row) { $name = ''; if (!is_null($row->project_id) && !is_null($row->task_id)) { $name .= '
' . $row->task->heading . '
' . $row->task->project->project_name . '
'; } else if (!is_null($row->project_id)) { $name .= '
' . $row->project->project_name . '
'; } else if (!is_null($row->task_id)) { $name .= '
' . $row->task->heading . '
'; } return $name; }); $datatables->addColumn('task_name', function ($row) { return !is_null($row->task_id) ? $row->task->heading : '--'; }); $datatables->addColumn('task_project_name', function ($row) { return !is_null($row->project_id) ? $row->project->project_name : '--'; }); $datatables->addColumn('short_code', function ($row) { if (!is_null($row->project)) { return $row->project->project_short_code; } else { return '--'; } }); $datatables->addIndexColumn(); $datatables->setRowId(function ($row) { return 'row-' . $row->id; }); $datatables->orderColumn('project_name', 'tasks.heading $1'); $datatables->removeColumn('project_id'); $datatables->removeColumn('total_minutes'); $datatables->removeColumn('task_id'); // Custom Fields For export $customFieldColumns = CustomField::customFieldData($datatables, ProjectTimeLog::CUSTOM_FIELD_MODEL); $datatables->rawColumns(array_merge(['end_time', 'action', 'project_name', 'name', 'total_hours', 'check'], $customFieldColumns)); return $datatables; } /** * @param ProjectTimeLog $model * @return \Illuminate\Database\Eloquent\Builder */ public function query(ProjectTimeLog $model) { $request = $this->request(); $projectId = $request->projectId; $employee = $request->employee; $taskId = $request->taskId; $approved = $request->approved; $invoice = $request->invoice; $model = $model->with('user', 'user.employeeDetail', 'user.employeeDetail.designation', 'user.session', 'task', 'task.project', 'breaks', 'activeBreak', 'project'); if (!in_array('client', user_roles()) && $request->has('project_admin') && $request->project_admin == 1) { $model->leftJoin('users', 'users.id', '=', 'project_time_logs.user_id') ->leftJoin('employee_details', 'users.id', '=', 'employee_details.user_id'); } else { $model->join('users', 'users.id', '=', 'project_time_logs.user_id') ->join('employee_details', 'users.id', '=', 'employee_details.user_id'); } $model = $model->leftJoin('designations', 'employee_details.designation_id', '=', 'designations.id') ->leftJoin('tasks', 'tasks.id', '=', 'project_time_logs.task_id') ->leftJoin('projects', 'projects.id', '=', 'tasks.project_id'); $model = $model->select('project_time_logs.id', 'project_time_logs.start_time', 'project_time_logs.end_time', 'project_time_logs.total_hours', 'project_time_logs.total_minutes', 'project_time_logs.memo', 'project_time_logs.user_id', 'tasks.project_id', 'project_time_logs.task_id', 'users.name', 'users.image', 'project_time_logs.hourly_rate', 'project_time_logs.earnings', 'project_time_logs.approved', 'tasks.heading', 'projects.project_name', 'designations.name as designation_name', 'project_time_logs.added_by', 'projects.project_admin'); if ($request->startDate !== null && $request->startDate != 'null' && $request->startDate != '') { $startDate = Carbon::createFromFormat($this->company->date_format, $request->startDate)->toDateString(); if (!is_null($startDate)) { $model->where(DB::raw('DATE(project_time_logs.`start_time`)'), '>=', $startDate); } } if ($request->endDate !== null && $request->endDate != 'null' && $request->endDate != '') { $endDate = Carbon::createFromFormat($this->company->date_format, $request->endDate)->toDateString(); if (!is_null($endDate)) { $model->where(function ($query) use ($endDate) { $query->where(DB::raw('DATE(project_time_logs.`end_time`)'), '<=', $endDate); }); } } if (!is_null($employee) && $employee !== 'all') { $model->where('project_time_logs.user_id', $employee); } if (!is_null($projectId) && $projectId !== 'all') { $model->where('tasks.project_id', '=', $projectId); } if (!is_null($taskId) && $taskId !== 'all') { $model->where('project_time_logs.task_id', '=', $taskId); } if (!is_null($approved) && $approved !== 'all') { if ($approved == 2) { $model->whereNull('project_time_logs.end_time'); } else { $model->where('project_time_logs.approved', '=', $approved); } } if (!is_null($invoice) && $invoice !== 'all') { if ($invoice == 0) { $model->whereNull('project_time_logs.invoice_id'); } else if ($invoice == 1) { $model->whereNotNull('project_time_logs.invoice_id'); } } if ($request->searchText != '') { $model->where(function ($query) { $query->where('tasks.heading', 'like', '%' . request('searchText') . '%') ->orWhere('project_time_logs.memo', 'like', '%' . request('searchText') . '%') ->orWhere('projects.project_name', 'like', '%' . request('searchText') . '%') ->orWhere('projects.project_short_code', 'like', '%' . request('searchText') . '%') ->orWhere('tasks.task_short_code', 'like', '%' . request('searchText') . '%'); }); }; if (($request->has('project_admin') && $request->project_admin != 1) || !$request->has('project_admin')) { if ($this->viewTimelogPermission == 'added') { $model->where('project_time_logs.added_by', user()->id); } if ($this->viewTimelogPermission == 'owned') { $model->where(function ($q) { $q->where('project_time_logs.user_id', '=', user()->id); if (in_array('client', user_roles())) { $q->orWhere('projects.client_id', '=', user()->id); } }); if ($projectId != 0 && $projectId != null && $projectId != 'all' && !in_array('client', user_roles())) { $model->where('projects.project_admin', '<>', user()->id); } } if ($this->viewTimelogPermission == 'both') { $model->where(function ($q) { $q->where('project_time_logs.user_id', '=', user()->id); $q->orWhere('project_time_logs.added_by', '=', user()->id); if (in_array('client', user_roles())) { $q->orWhere('projects.client_id', '=', user()->id); } }); } } $model->whereNull('tasks.deleted_at'); return $model; } /** * Optional method if you want to use html builder. * * @return \Yajra\DataTables\Html\Builder */ public function html() { $dataTable = $this->setBuilder('timelogs-table', 2) ->parameters([ 'initComplete' => 'function () { window.LaravelDataTables["timelogs-table"].buttons().container() .appendTo( "#table-actions") }', 'fnDrawCallback' => 'function( oSettings ) { $(".select-picker").selectpicker(); $("body").popover({ selector: \'[data-toggle="popover"]\', trigger: "hover", placement: "top", }) // $(\'[data-toggle="popover"]\').popover(); }', ]); if (canDataTableExport()) { $dataTable->buttons(Button::make(['extend' => 'excel', 'text' => '
' . trans('app.exportExcel')])); } return $dataTable; } /** * Get columns. * * @return array */ protected function getColumns() { $data = [ 'check' => [ 'title' => '
', 'exportable' => false, 'orderable' => false, 'searchable' => false ], '#' => ['data' => 'DT_RowIndex', 'orderable' => false, 'searchable' => false, 'visible' => !showId(), 'title' => '#'], __('app.id') => ['data' => 'id', 'name' => 'id', 'title' => __('app.id'), 'visible' => showId()], __('modules.taskCode') => ['data' => 'short_code', 'name' => 'project_short_code', 'title' => __('modules.taskCode')], __('app.task') => ['data' => 'project_name', 'name' => 'tasks.heading','exportable' => false, 'width' => '200', 'title' => __('app.task')], __('app.tasks') => ['data' => 'task_name', 'visible' => false, 'name' => 'task_name', 'title' => __('app.tasks')], __('app.project') => ['data' => 'task_project_name', 'visible' => false, 'name' => 'task_project_name', 'title' => __('app.project')], __('app.employee') => ['data' => 'name', 'name' => 'users.name', 'exportable' => false, 'title' => __('app.employee')], __('app.name') => ['data' => 'employee_name', 'name' => 'name', 'visible' => false, 'title' => __('app.name')], __('modules.timeLogs.startTime') => ['data' => 'start_time', 'name' => 'start_time', 'title' => __('modules.timeLogs.startTime')], __('modules.timeLogs.endTime') => ['data' => 'end_time', 'name' => 'end_time', 'title' => __('modules.timeLogs.endTime')], __('modules.timeLogs.totalHours') => ['data' => 'total_hours', 'name' => 'total_hours', 'title' => __('modules.timeLogs.totalHours')], __('app.earnings') => ['data' => 'earnings', 'name' => 'earnings', 'title' => __('app.earnings'), 'visible' => ($this->viewTimelogEarningsPermission == 'all'), 'exportable' => ($this->viewTimelogEarningsPermission == 'all')] ]; $action = [ Column::computed('action', __('app.action')) ->exportable(false) ->printable(false) ->orderable(false) ->searchable(false) ->addClass('text-right pr-20') ]; return array_merge($data, CustomFieldGroup::customFieldsDataMerge(new ProjectTimeLog()), $action); } }