芝麻web文件管理V1.00
编辑当前文件:/home/qrafawbu/qrafiqxcreativeagency.com/accounts/office/app/DataTables/OrdersDataTable.php
viewOrderPermission = user()->permission('view_order'); $this->deleteOrderPermission = user()->permission('delete_order'); $this->editOrderPermission = user()->permission('edit_order'); } /** * Build DataTable class. * * @param mixed $query Results from query() method. * @return \Yajra\DataTables\DataTableAbstract */ public function dataTable($query) { return datatables() ->eloquent($query) ->addIndexColumn() ->addColumn('action', function ($row) { $action = '
'; if (!in_array('client', user_roles()) && in_array($row->status, ['pending', 'on-hold', 'failed', 'processing']) && ($this->editOrderPermission == 'all' || (in_array($this->editOrderPermission, ['added', 'both']) && $row->added_by == user()->id))) { $action .= '
' . __('app.orderMarkAsComplete') . '
'; } $action .= '
' . __('app.view') . '
'; if ($this->viewOrderPermission == 'all' || ($this->viewOrderPermission == 'both' && ($row->added_by == user()->id || $row->client_id == user()->id)) || ($this->viewOrderPermission == 'owned' && $row->client_id == user()->id) || ($this->viewOrderPermission == 'added' && $row->added_by == user()->id)) { $action .= '
' . trans('app.download') . '
'; } if (!in_array('client', user_roles()) && !in_array($row->status, ['completed', 'canceled', 'refunded']) && ($this->editOrderPermission == 'all' || ($this->editOrderPermission == 'both' && ($row->added_by == user()->id || $row->client_id == user()->id)) || ($this->editOrderPermission == 'added' && $row->added_by == user()->id) || ($this->editOrderPermission == 'owned' && $row->client_id == user()->id))) { $action .= '
' . trans('app.edit') . '
'; } if (!in_array('client', user_roles()) && !in_array($row->status, ['completed', 'refunded']) && ($this->deleteOrderPermission == 'all' || ($this->deleteOrderPermission == 'both' && ($row->added_by == user()->id || $row->client_id == user()->id)) || ($this->deleteOrderPermission == 'added' && $row->added_by == user()->id) || ($this->deleteOrderPermission == 'owned' && $row->client_id == user()->id) )) { $action .= '
' . trans('app.delete') . '
'; } $action .= '
'; return $action; }) ->editColumn('order_number', function ($row) { return '
' . $row->order_number . '
'; }) ->addColumn('order', function ($row) { return $row->order_number; }) ->addColumn('order_number_export', function ($row) { return $row->order_number; }) ->addColumn('client_name', function ($row) { return $row->client->name; }) ->editColumn('name', function ($row) { $client = $row->client; return view('components.client', [ 'user' => $client ]); }) ->editColumn('status', function ($row) { if ((in_array('admin', user_roles()) || in_array('employee', user_roles())) && ($this->editOrderPermission == 'all' || ($this->editOrderPermission == 'both' && ($row->added_by == user()->id || $row->client_id == user()->id)) || ($this->editOrderPermission == 'added' && $row->added_by == user()->id) || ($this->editOrderPermission == 'owned' && $row->client_id == user()->id))) { $status = '
status, ['refunded', 'canceled']) ? 'disabled' : '') . '>'; if (in_array($row->status, ['pending', 'failed', 'on-hold', 'processing'])) { $status .= '
status == 'pending' ? 'selected' : '') . ' data-content="
' . __('app.pending') . '">' . __('app.pending') . '
'; } if (in_array($row->status, ['on-hold', 'pending', 'processing', 'failed'])) { $status .= '
status == 'on-hold' ? 'selected' : '') . ' data-content="
' . __('app.on-hold') . '">' . __('app.on-hold') . '
'; } if (in_array($row->status, ['failed', 'pending',])) { $status .= '
status == 'failed' ? 'selected' : '') . ' data-content="
' . __('app.failed') . '">' . __('app.failed') . '
'; } if (in_array($row->status, ['processing', 'pending', 'on-hold', 'failed'])) { $status .= '
status == 'processing' ? 'selected' : '') . ' data-content="
' . __('app.processing') . '">' . __('app.processing') . '
'; } if (in_array($row->status, ['completed', 'pending', 'on-hold', 'failed', 'processing'])) { $status .= '
status == 'completed' ? 'selected' : '') . ' data-content="
' . __('app.completed') . '">' . __('app.completed') . '
'; } if (in_array($row->status, ['canceled', 'on-hold', 'pending', 'failed', 'processing'])) { $status .= '
status == 'canceled' ? 'selected' : '') . ' data-content="
' . __('app.canceled') . '">' . __('app.canceled') . '
'; } if (in_array($row->status, ['refunded', 'completed'])) { $status .= '
status == 'refunded' ? 'selected' : '') . ' data-content="
' . __('app.refunded') . '">' . __('app.refunded') . '
'; } $status .= '
'; } else { $status = match ($row->status) { 'pending' => '
' . __('app.' . $row->status), 'on-hold' => '
' . __('app.' . $row->status), 'failed' => '
' . __('app.' . $row->status), 'processing' => '
' . __('app.' . $row->status), 'completed' => '
' . __('app.' . $row->status), 'canceled' => '
' . __('app.' . $row->status), default => '
' . __('app.' . $row->status), }; } return $status; }) ->editColumn('total', function ($row) { $currencyId = $row->currency->id; return currency_format($row->total, $currencyId); }) ->editColumn( 'order_date', function ($row) { return Carbon::parse($row->order_date)->timezone($this->company->timezone)->translatedFormat($this->company->date_format); } ) ->addColumn('order_status', function ($row) { return $row->status; }) ->orderColumn('order_number', 'created_at $1') ->orderColumn('name', 'client_id $1') ->rawColumns(['action', 'status', 'total', 'name', 'order_number']) ->removeColumn('currency_symbol') ->removeColumn('currency_code'); } /** * @return \Illuminate\Database\Eloquent\Builder */ public function query() { $request = $this->request(); $model = Order::with([ 'currency:id,currency_symbol,currency_code', 'client', 'payment' ]) ->with('client', 'client.session', 'client.clientDetails', 'payment') ->select('orders.id', 'orders.client_id', 'orders.currency_id', 'orders.total', 'orders.status', 'orders.order_date', 'orders.show_shipping_address', 'orders.added_by', 'orders.order_number', 'orders.custom_order_number'); if ($request->startDate !== null && $request->startDate != 'null' && $request->startDate != '') { $startDate = Carbon::createFromFormat($this->company->date_format, $request->startDate)->toDateString(); $model = $model->where(DB::raw('DATE(orders.`order_date`)'), '>=', $startDate); } if ($request->endDate !== null && $request->endDate != 'null' && $request->endDate != '') { $endDate = Carbon::createFromFormat($this->company->date_format, $request->endDate)->toDateString(); $model = $model->where(DB::raw('DATE(orders.`order_date`)'), '<=', $endDate); } if ($request->status != 'all' && !is_null($request->status)) { $model = $model->where('orders.status', '=', $request->status); } if ($request->clientID != 'all' && !is_null($request->clientID)) { $model = $model->where('orders.client_id', '=', $request->clientID); } if ($request->searchText != '') { $model->where(function ($query) { $query->where('orders.order_number', 'like', '%' . request('searchText') . '%') ->orWhere('orders.custom_order_number', 'like', '%' . request('searchText') . '%') ->orWhere('orders.total', 'like', '%' . request('searchText') . '%'); }); } if ($this->viewOrderPermission == 'added') { $model->where('orders.added_by', user()->id); } if ($this->viewOrderPermission == 'owned') { $model->where('orders.client_id', user()->id); } if ($this->viewOrderPermission == 'both') { $model->where(function ($query) { $query->where('orders.added_by', user()->id) ->orWhere('orders.client_id', user()->id); }); } if (in_array('client', user_roles())) { $model->where('orders.client_id', user()->id); } return $model; } /** * Optional method if you want to use html builder. * * @return \Yajra\DataTables\Html\Builder */ public function html() { $dataTable = $this->setBuilder('orders-table', 0) ->parameters([ 'initComplete' => 'function () { window.LaravelDataTables["orders-table"].buttons().container() .appendTo( "#table-actions") }', 'fnDrawCallback' => 'function( oSettings ) { $("#orders-table .select-picker").selectpicker(); $("body").tooltip({ selector: \'[data-toggle="tooltip"]\' }); }', ]); if (canDataTableExport()) { $dataTable->buttons(Button::make(['extend' => 'excel', 'text' => '
' . trans('app.exportExcel')])); } return $dataTable; } /** * Get columns. * * @return array */ protected function getColumns() { return [ __('app.id') => ['data' => 'id', 'name' => 'id', 'visible' => false, 'title' => __('app.id')], __('app.order') . __('app.no') => ['data' => 'order_number_export', 'name' => 'order_number_export', 'visible' => false, 'title' => __('app.order') . ' ' . __('app.no')], __('app.client_name') => ['data' => 'client_name', 'name' => 'project.client.name', 'visible' => false, 'title' => __('app.client_name')], __('app.client') => ['data' => 'name', 'name' => 'name', 'visible' => !in_array('client', user_roles()), 'exportable' => false, 'title' => __('app.client')], __('modules.invoices.total') => ['data' => 'total', 'name' => 'total', 'title' => __('modules.invoices.total')], __('modules.orders.orderDate') => ['data' => 'order_date', 'name' => 'order_date', 'title' => __('modules.orders.orderDate')], __('app.status') => ['data' => 'status', 'name' => 'status', 'width' => '10%', 'exportable' => false, 'title' => __('app.status')], __('app.order_status') => ['data' => 'order_status', 'name' => 'order_status', 'width' => '10%', 'visible' => false, 'title' => __('app.status')], Column::computed('action', __('app.action')) ->exportable(false) ->printable(false) ->orderable(false) ->searchable(false) ->width(150) ->addClass('text-right pr-20') ]; } }