芝麻web文件管理V1.00
编辑当前文件:/home/qrafawbu/qrafiqxcreativeagency.com/accounts/office/app/DataTables/ContractsDataTable.php
editContractPermission = user()->permission('edit_contract'); $this->deleteContractPermission = user()->permission('delete_contract'); $this->addContractPermission = user()->permission('add_contract'); $this->viewContractPermission = user()->permission('view_contract'); } /** * Build DataTable class. * * @param mixed $query Results from query() method. * @return \Yajra\DataTables\DataTableAbstract */ public function dataTable($query) { $datatables = datatables()->eloquent($query); // Custom Fields For export $customFieldColumns = CustomField::customFieldData($datatables, Contract::CUSTOM_FIELD_MODEL); return $datatables ->addColumn('check', function ($row) { return '
'; }) ->addColumn('action', function ($row) { $action = '
'; $action .= '
' . __('app.view') . '
'; if (!$row->company_sign && user()->company_id == $row->company_id) { $action .= '
' . trans('modules.estimates.companysignature') . '
'; } if (!$row->signature) { $action .= '
' . __('modules.proposal.publicLink') . '
'; } if ($this->addContractPermission == 'all' || $this->addContractPermission == 'added') { $action .= '
' . __('app.copy') . ' ' . __('app.menu.contract') . '
'; } if ( $this->editContractPermission == 'all' || ($this->editContractPermission == 'added' && user()->id == $row->added_by) || ($this->editContractPermission == 'owned' && user()->id == $row->client_id) || ($this->editContractPermission == 'both' && (user()->id == $row->client_id || user()->id == $row->added_by)) ) { $action .= '
' . trans('app.edit') . '
'; } if ( $this->deleteContractPermission == 'all' || ($this->deleteContractPermission == 'added' && user()->id == $row->added_by) || ($this->deleteContractPermission == 'owned' && user()->id == $row->client_id) || ($this->deleteContractPermission == 'both' && (user()->id == $row->client_id || user()->id == $row->added_by)) ) { $action .= '
' . trans('app.delete') . '
'; } $action .= '
' . trans('app.download') . '
'; $action .= '
'; return $action; }) ->editColumn('project_name', function ($row) { if ($row->project_id != null) { return '
' . $row->project->project_name . '
'; } return '--'; }) ->addColumn('contract_subject', function ($row) { return $row->subject; }) ->editColumn('subject', function ($row) { $signed = ''; if ($row->signature) { $signed = '
' . __('app.signed') . '
'; } return '
' . $row->subject . '
' . $signed . '
'; }) ->editColumn('start_date', function ($row) { return $row->start_date->translatedFormat($this->company->date_format); }) ->editColumn('end_date', function ($row) { if (is_null($row->end_date)) { return '--'; } return $row->end_date == null ? $row->end_date : $row->end_date->translatedFormat($this->company->date_format); }) ->editColumn('amount', function ($row) { return currency_format($row->amount, $row->currency->id); }) ->addColumn('client_name', function ($row) { return $row->client->name; }) ->editColumn('client.name', function ($row) { return '
' . ($row->client->salutation ? $row->client->salutation->label() . ' ' : '') . $row->client->name . '
' . $row->client->clientDetails->company_name . '
'; }) ->editColumn('signature', function ($row) { if ($row->signature) { return __('app.signed'); } })->editColumn('contract_number', function ($row) { return '
' . $row->contract_number . '
'; }) ->addIndexColumn() ->smart(false) ->setRowId(function ($row) { return 'row-' . $row->id; }) ->rawColumns(array_merge(['project_name','action', 'client.name', 'check', 'subject','contract_number'], $customFieldColumns)); } /** * @param Contract $model * @property-read \App\Models\Award $title * @return \Illuminate\Database\Eloquent\Builder */ public function query(Contract $model) { $request = $this->request(); $startDate = null; $endDate = null; if ($request->startDate !== null && $request->startDate != 'null' && $request->startDate != '') { $startDate = Carbon::createFromFormat($this->company->date_format, $request->startDate)->toDateString(); } if ($request->endDate !== null && $request->endDate != 'null' && $request->endDate != '') { $endDate = Carbon::createFromFormat($this->company->date_format, $request->endDate)->toDateString(); } $model = $model->with( [ 'project' => function ($q) { $q->withTrashed(); $q->select('id', 'project_name', 'project_short_code', 'client_id'); }, 'currency:id,currency_symbol,currency_code', 'project.client', 'client', 'project.clientdetails' ] )->with('contractType', 'client', 'signature', 'client.clientDetails') ->join('users', 'users.id', '=', 'contracts.client_id') ->join('client_details', 'users.id', '=', 'client_details.user_id') ->select('contracts.*'); if ($startDate !== null && $endDate !== null) { $model->where(function ($q) use ($startDate, $endDate) { $q->whereBetween(DB::raw('DATE(contracts.`end_date`)'), [$startDate, $endDate]); $q->orWhereBetween(DB::raw('DATE(contracts.`start_date`)'), [$startDate, $endDate]); }); } if ($request->client != 'all' && !is_null($request->client)) { $model = $model->where('contracts.client_id', '=', $request->client); } if ($request->contract_type != 'all' && !is_null($request->contract_type)) { $model = $model->where('contracts.contract_type_id', '=', $request->contract_type); } if (request('signed') == 'yes') { $model = $model->has('signature'); } if ($request->searchText != '') { $model = $model->where(function ($query) { $query->where('contracts.subject', 'like', '%' . request('searchText') . '%') ->orWhere('contracts.amount', 'like', '%' . request('searchText') . '%') ->orWhere('client_details.company_name', 'like', '%' . request('searchText') . '%'); }) ->orWhere(function ($query) { $query->whereHas('project', function ($q) { $q->where('project_name', 'like', '%' . request('searchText') . '%') ->orWhere('project_short_code', 'like', '%' . request('searchText') . '%'); // project short code }); }); } if ($this->viewContractPermission == 'added') { $model = $model->where('contracts.added_by', '=', user()->id); } if ($this->viewContractPermission == 'owned') { $model = $model->where('contracts.client_id', '=', user()->id); } if ($this->viewContractPermission == 'both') { $model = $model->where(function ($query) { $query->where('contracts.added_by', '=', user()->id) ->orWhere('contracts.client_id', '=', user()->id); }); } return $model; } /** * Optional method if you want to use html builder. * * @property-read \App\Models\Award $title * @return \Yajra\DataTables\Html\Builder */ public function html() { $dataTable = $this->setBuilder('contracts-table') ->parameters([ 'initComplete' => 'function () { window.LaravelDataTables["contracts-table"].buttons().container() .appendTo( "#table-actions") }', 'fnDrawCallback' => 'function( oSettings ) { // }', /* 'buttons' => ['excel'] */ ]); 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, 'visible' => !in_array('client', user_roles()) ], __('modules.contracts.contractNumber') => ['data' => 'contract_number', 'name' => 'contract_number', 'title' => '#'], __('app.subject') => ['data' => 'subject', 'name' => 'subject', 'exportable' => false, 'title' => __('app.subject')], __('app.menu.contract') . ' ' . __('app.subject') => ['data' => 'contract_subject', 'name' => 'subject', 'visible' => false, 'title' => __('app.menu.contract')], __('app.client') => ['data' => 'client.name', 'name' => 'client.name', 'exportable' => false, 'title' => __('app.client'), 'visible' => !in_array('client', user_roles())], __('app.customers') => ['data' => 'client_name', 'name' => 'client.name', 'visible' => false, 'title' => __('app.customers')], __('app.project') => ['data' => 'project_name', 'name' => 'project.project_name', 'title' => __('app.project')], __('app.amount') => ['data' => 'amount', 'name' => 'amount', 'title' => __('app.amount')], __('app.startDate') => ['data' => 'start_date', 'name' => 'start_date', 'title' => __('app.startDate')], __('app.endDate') => ['data' => 'end_date', 'name' => 'end_date', 'title' => __('app.endDate')], __('app.signature') => ['data' => 'signature', 'name' => 'signature', 'visible' => false, 'title' => __('app.signature')] ]; $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 Contract()), $action); } }