芝麻web文件管理V1.00
编辑当前文件:/home/qrafawbu/qrafiqxcreativeagency.com/accounts/office/app/DataTables/LeaveDataTable.php
editLeavePermission = user()->permission('edit_leave'); $this->deleteLeavePermission = user()->permission('delete_leave'); $this->deleteApproveLeavePermission = user()->permission('delete_approve_leaves'); $this->viewLeavePermission = user()->permission('view_leave'); $this->approveRejectPermission = user()->permission('approve_or_reject_leaves'); $this->reportingPermission = LeaveSetting::value('manager_permission'); $this->reportingTo = EmployeeDetails::where('reporting_to', user()->id)->get(); } /** * Build DataTable class. * * @param mixed $query Results from query() method. * @return \Yajra\DataTables\DataTableAbstract */ public function dataTable($query) { return datatables() ->eloquent($query) ->addIndexColumn() ->addColumn('check', function ($row) { return '
'; }) ->addColumn('employee_name', function ($row) { return $row->user->name; }) ->editColumn('employee', function ($row) { return view('components.employee', [ 'user' => $row->user ]); }) ->editColumn('paid', function ($row) { return $row->type->paid == 1 ? __('app.yes') : __('app.no'); }) ->addColumn('leave_date', function ($row) { return Carbon::parse($row->leave_date)->translatedFormat($this->company->date_format) .' ('.Carbon::parse($row->leave_date)->translatedFormat('l').')'; }) ->addColumn('status', function ($row) { if ($row->status == 'approved') { $class = 'text-light-green'; $status = __('app.approved'); } else if ($row->status == 'pending') { $class = 'text-yellow'; $status = __('app.pending'); } else { $class = 'text-red'; $status = __('app.rejected'); } $leaveStatus = '
'; if($row->duration == 'multiple' && !is_null($row->unique_id)){ $leaveStatus = '
' . __('app.view') . ' '.__('app.status').'
'; } else{ $leaveStatus = '
' . $status; if($row->manager_status_permission === 'pre-approve'){ $leaveStatus .= '
'.__('modules.leaves.preApproved').'
'; } } $leaveStatus .= '
'; return $leaveStatus; }) ->addColumn('duration', function ($row) { $leave = '
'.(($row->duration == 'half day') ? __('modules.leaves.halfDay') : (($row->duration == 'multiple') ? __('modules.leaves.multiple') : __('app.'.$row->duration))) .'
'; if($row->count_multiple_leaves != 0){ $leave .= '
' . $row->count_multiple_leaves .' '.__('app.leave').'
'; } $leave .= '
'; return $leave; }) ->addColumn('leave_type', function ($row) { $type = '
' . $row->type_name . '
'; if ($row->duration == 'half day') { if (!is_null($row->half_day_type)) { $type .= '
' . (($row->half_day_type == 'first_half') ? __('modules.leaves.firstHalf') : __('modules.leaves.secondHalf')) . '
'; } else { $type .= '
' . __('modules.leaves.halfDay') . '
'; } } return $type; }) ->addColumn('action', function ($row) { $actions = '
'; if ($row->duration == 'multiple' && !is_null($row->unique_id)) { $actions .= '
' . __('app.view') . '
'; } else { $actions .= '
' . __('app.view') . '
'; } if ($row->status == 'pending' && ($row->duration != 'multiple' || is_null($row->unique_id)) && $this->approveRejectPermission == 'all') { $actions .= '
' . __('app.approve') . '
' . __('app.reject') . '
'; } if (($row->duration == 'multiple' && !is_null($row->unique_id)) && $this->approveRejectPermission == 'all') { $actions .= '
' . __('app.view') . ' '.__('modules.leaves.relatedLeave').'
'; } if ($row->status == 'pending' && $this->reportingTo && $row->user_id != user()->id && !in_array('admin', user_roles())) { if ($row->manager_status_permission == '' && !($this->reportingPermission == 'cannot-approve')) { $actions .= '
' . __('app.reject') . '
'; } if ($this->reportingPermission == 'approved' && $row->manager_status_permission == '') { $actions .= '
' . __('app.approve') . '
'; } elseif ($this->reportingPermission == 'pre-approve' && !$row->manager_status_permission) { $actions .= '
' . __('app.preApprove') . '
'; } } if ($row->status == 'pending' && ($row->duration != 'multiple' || is_null($row->unique_id))) { if ($this->editLeavePermission == 'all' || ($this->editLeavePermission == 'added' && user()->id == $row->added_by) || ($this->editLeavePermission == 'owned' && user()->id == $row->user_id) || ($this->editLeavePermission == 'both' && (user()->id == $row->user_id || user()->id == $row->added_by)) ) { $actions .= '
' . __('app.edit') . '
'; } } if ($this->deleteLeavePermission == 'all' || ($this->deleteLeavePermission == 'added' && user()->id == $row->added_by) || ($this->deleteLeavePermission == 'owned' && user()->id == $row->user_id) || ($this->deleteLeavePermission == 'both' && (user()->id == $row->user_id || user()->id == $row->added_by))) { if($row->status != 'approved'){ $actions .= '
' . __('app.delete') . '
'; } else { ($this->deleteApproveLeavePermission == 'all') ? $actions .= '
' . __('app.delete') . '
' : ''; } } $actions .= '
'; return $actions; }) ->smart(false) ->setRowId(function ($row) { return 'row-' . $row->id; }) ->rawColumns(['status', 'leave_type', 'action', 'check', 'employee', 'duration']); } /** * @param Leave $model * @return \Illuminate\Database\Eloquent\Builder */ public function query(Leave $model) { // Will check count leave from the start of the year or nor $setting = company(); $leavesList = $model->with('user', 'user.employeeDetail', 'user.employeeDetail.designation', 'user.session', 'type') ->join('leave_types', 'leave_types.id', 'leaves.leave_type_id') ->join('users', 'leaves.user_id', 'users.id') ->join('employee_details', 'employee_details.user_id', 'users.id') ->selectRaw('leaves.*, leave_types.color, leave_types.type_name, ( select count("lvs.id") from leaves as lvs where lvs.unique_id = leaves.unique_id and lvs.duration = \'multiple\') as count_multiple_leaves', ) ->groupByRaw('ifnull(leaves.unique_id, leaves.id)'); if (!is_null(request()->startDate)) { $startDate = Carbon::createFromFormat($this->company->date_format, request()->startDate)->toDateString(); $leavesList->whereRaw('Date(leaves.leave_date) >= ?', [$startDate]); } if (!is_null(request()->endDate)) { $endDate = Carbon::createFromFormat($this->company->date_format, request()->endDate)->toDateString(); $leavesList->whereRaw('Date(leaves.leave_date) <= ?', [$endDate]); } if (request()->employeeId != 'all' && request()->employeeId != '') { $leavesList->where('users.id', request()->employeeId); } if (request()->leave_year != '') { $leavesList->whereYear('leaves.leave_date', request()->leave_year); } if (request()->leaveTypeId != 'all' && request()->leaveTypeId != '') { $leavesList->where('leave_types.id', request()->leaveTypeId); } if (request()->status != 'all' && request()->status != '') { $leavesList->where('leaves.status', request()->status); } if (request()->searchText != '') { $leavesList->where('users.name', 'like', '%' . request()->searchText . '%'); } if ($this->viewLeavePermission == 'owned') { $leavesList->where(function ($q) { $q->orWhere('leaves.user_id', '=', user()->id); ($this->reportingPermission != 'cannot-approve') ? $q->orWhere('employee_details.reporting_to', user()->id) : ''; }); } if ($this->viewLeavePermission == 'added') { $leavesList->where(function ($q) { $q->orWhere('leaves.added_by', '=', user()->id); ($this->reportingPermission != 'cannot-approve') ? $q->orWhere('employee_details.reporting_to', user()->id) : ''; }); } if ($this->viewLeavePermission == 'both') { $leavesList->where(function ($q) { $q->orwhere('leaves.user_id', '=', user()->id); $q->orWhere('leaves.added_by', '=', user()->id); ($this->reportingPermission != 'cannot-approve') ? $q->orWhere('employee_details.reporting_to', user()->id) : ''; }); } return $leavesList; } /** * Optional method if you want to use html builder. * * @return \Yajra\DataTables\Html\Builder */ public function html() { $dataTable = $this->setBuilder('leaves-table', 2) ->parameters([ 'initComplete' => 'function () { window.LaravelDataTables["leaves-table"].buttons().container() .appendTo("#table-actions") }', 'fnDrawCallback' => 'function( oSettings ) { $("body").tooltip({ selector: \'[data-toggle="tooltip"]\' }); $(".statusChange").selectpicker(); }', ]); if (canDataTableExport()) { $dataTable->buttons(Button::make(['extend' => 'excel', 'text' => '
' . trans('app.exportExcel')])); } return $dataTable; } /** * Get columns. * * @return array */ protected function getColumns() { return [ 'check' => [ 'title' => '
', 'exportable' => false, 'orderable' => false, 'searchable' => false, 'visible' => ($this->viewLeavePermission == 'all') ], '#' => ['data' => 'DT_RowIndex', 'orderable' => false, 'searchable' => false, 'visible' => false, 'title' => '#'], __('app.id') => ['data' => 'id', 'name' => 'id', 'title' => __('app.id'), 'visible' => false], __('app.employee') => ['data' => 'employee', 'name' => 'user.name', 'exportable' => false, 'title' => __('app.employee')], __('app.employee') . ' ' => ['data' => 'employee_name', 'name' => 'user.name', 'visible' => false, 'title' => __('app.employee')], __('app.leaveDate') => ['data' => 'leave_date', 'name' => 'leaves.leave_date', 'title' => __('app.leaveDate')], __('app.duration') => ['data' => 'duration', 'name' => 'duration', 'title' => __('app.duration')], __('app.leaveStatus') => ['data' => 'status', 'name' => 'leaves.status', 'title' => __('app.leaveStatus')], __('app.leaveType') => ['data' => 'leave_type', 'name' => 'leave_types.type_name', 'title' => __('app.leaveType')], __('app.paid') => ['data' => 'paid', 'name' => 'leave_types.paid', 'title' => __('app.paid')], Column::computed('action', __('app.action')) ->exportable(false) ->printable(false) ->orderable(false) ->searchable(false) ->addClass('text-right pr-20') ]; } }