Esempio n. 1
0
 public function getDatatable()
 {
     $suppliers = Supplier::select(array('id', 'name', 'address', 'address2', 'city', 'state', 'country', 'fax', 'phone', 'email', 'contact'))->whereNull('deleted_at');
     if (Input::has('search')) {
         $suppliers = $suppliers->TextSearch(e(Input::get('search')));
     }
     if (Input::has('offset')) {
         $offset = e(Input::get('offset'));
     } else {
         $offset = 0;
     }
     if (Input::has('limit')) {
         $limit = e(Input::get('limit'));
     } else {
         $limit = 50;
     }
     $allowed_columns = ['id', 'name', 'address', 'phone', 'contact', 'fax', 'email'];
     $order = Input::get('order') === 'asc' ? 'asc' : 'desc';
     $sort = in_array(Input::get('sort'), $allowed_columns) ? Input::get('sort') : 'created_at';
     $suppliers->orderBy($sort, $order);
     $suppliersCount = $suppliers->count();
     $suppliers = $suppliers->skip($offset)->take($limit)->get();
     $rows = array();
     foreach ($suppliers as $supplier) {
         $actions = '<a href="' . route('update/supplier', $supplier->id) . '" class="btn btn-warning btn-sm" style="margin-right:5px;"><i class="fa fa-pencil icon-white"></i></a><a data-html="false" class="btn delete-asset btn-danger btn-sm" data-toggle="modal" href="' . route('delete/supplier', $supplier->id) . '" data-content="' . trans('admin/suppliers/message.delete.confirm') . '" data-title="' . trans('general.delete') . ' ' . htmlspecialchars($supplier->name) . '?" onClick="return false;"><i class="fa fa-trash icon-white"></i></a>';
         $rows[] = array('id' => $supplier->id, 'name' => (string) link_to('admin/settings/suppliers/' . $supplier->id . '/view', e($supplier->name)), 'contact' => e($supplier->contact), 'address' => e($supplier->address) . ' ' . e($supplier->address2) . ' ' . e($supplier->city) . ' ' . e($supplier->state) . ' ' . e($supplier->country), 'phone' => e($supplier->phone), 'fax' => e($supplier->fax), 'email' => $supplier->email != '' ? '<a href="mailto:' . e($supplier->email) . '">' . e($supplier->email) . '</a>' : '', 'assets' => $supplier->num_assets(), 'licenses' => $supplier->num_licenses(), 'actions' => $actions);
     }
     $data = array('total' => $suppliersCount, 'rows' => $rows);
     return $data;
 }