yajra data table process

1. public function viewList() {
   try {
      return view("LocalSalesPermit::list");   } catch (\Exception $e) {
      Session::flash('error', CommonFunction::showErrorPublic($e->getMessage()));      return Redirect::back()->withInput();   }
}

2. $(document).ready(function () {
    $(function () {
        var t = $('#list').DataTable({
            "columnDefs": [ {
                "searchable": false,                "orderable": false,                "targets": 0            } ],            "order": [[ 0, 'asc' ]],            processing: true,            serverSide: true,            iDisplayLength: 25,            ajax: {
                url: '{{url("local-sales-permit/get-list")}}',                method: 'POST',                headers: {
                    'X-CSRF-TOKEN': '{{ csrf_token() }}'                }
            },            columns: [
                {data: 'sl_no', name: 'sl_no'},                {data: 'track_no', name: 'track_no'},                {data: 'applicant_name', name: 'applicant_name'},                {data: 'desk_name', name: 'desk_name'},                {data: 'status_name', name: 'status_name'},                {data: 'app_modified', name: 'app_modified'},                {data: 'action', name: 'action', orderable: true, searchable: true}
            ],            "aaSorting": []
        });        t.on( 'order.dt search.dt', function () {
            t.column(0, {search:'applied', order:'applied'}).nodes().each( function (cell, i) {
                cell.innerHTML = i+1;            } );        } ).draw();
    });});

3. public function getList()
{
   $viewMode = ACL::getAccsessRight('localSalesPermit', 'V');   $editMode = ACL::getAccsessRight('localSalesPermit', 'E');
   $userType = explode('x', CommonFunction::getUserType());   $applicationList = LocalSalesPermit::getApplicatoinList(0, $this->service_id);   return DataTables::of($applicationList)
      ->editColumn('track_no', function ($applicationList) {
         return $applicationList->track_no;      })
      ->addColumn('sl_no', function ($applicationList) {
         return '';      })
      ->addColumn('action', function ($applicationList) use ($viewMode, $editMode) {
         $link = '';         if ($viewMode) {
            $link = '<a href="' . url("local-sales-permit/view/" . Encryption::encodeId($applicationList->id)) . '" class="btn btn-primary btn-xs">Open</a>' . ' ';         }
         if (in_array($applicationList->status_id, [-1, 5]) and $editMode) {
            $link .= '<a href="' . url("local-sales-permit/list/edit/" . Encryption::encodeId($applicationList->id)) . '" class="btn btn-info btn-xs">Edit</a>' . ' ';         }
         return $link;      })
      ->editColumn('desk_name', function ($applicationList) use ($userType) {
         if ($applicationList->desk_name == "" || $applicationList->desk_name == null) {
            return 'Applicant';         } else {
            return ($userType[0] != 12) ? $applicationList->desk_name : 'N/A';         }
      })
      ->editColumn('status_name', function ($applicationList) {
            return $applicationList->status_name;      })
      ->editColumn('app_modified', function ($applicationList) {

         if ($applicationList->application_date == '0000-00-00') {
            return ' - ';         } else {
            return CommonFunction::updatedOn($applicationList->updated_at);         }
      })
      ->make(true);}


4. public static function getApplicatoinList($search_status_id = 0, $service_id = '') {
    $userId = CommonFunction::getUserId();    $userType = CommonFunction::getUserType();    $userDeskId = CommonFunction::getDeskId();
    $query = Processlist::leftJoin('local_sales_permit as lsp', 'process_list.record_id', '=', 'lsp.id')
        ->leftJoin('app_status', function($join) use($service_id) {
                $join->on('process_list.status_id', '=', 'app_status.status_id');            $join->on('app_status.service_id', '=', DB::raw($service_id));        })
        ->leftJoin('user_desk as ud', 'process_list.desk_id', '=', 'ud.desk_id')
        ->where('process_list.service_id', '=', $service_id)
        ->orderBy('lsp.created_at', 'DESC');    if ($userType == '5x505') { //Applicant        $query->where('lsp.created_by', $userId);    } elseif ($userType == '1x101') { // System Admin        $query->whereNotIn('process_list.status_id', [-1]);    } else { //For others desks        $query->whereNotIn('process_list.status_id', [-1, 5, 6])
            ->where('process_list.desk_id', $userDeskId);    }
    return $query->get([
        'lsp.*','app_status.status_name as status_name', 'process_list.status_id', 'process_list.track_no', 'ud.desk_name'    ]);}

Comments

Popular posts from this blog

Deploy laravel application to digital ocean droplet

WP register_post_type() with custom CMB2 meta box

Git post receive setup at server for git push to the production from local machine