This controller handles all actions related to Suppliers for the Snipe-IT Asset Management application.
More...
This controller handles all actions related to Suppliers for the Snipe-IT Asset Management application.
- Version
- v1.0
Definition at line 23 of file SuppliersController.php.
App\Http\Controllers\SuppliersController::getCreate |
( |
| ) |
|
Supplier create.
- Returns
- View
Definition at line 45 of file SuppliersController.php.
47 return View::make(
'suppliers/edit')->with(
'supplier',
new Supplier);
App\Http\Controllers\SuppliersController::getDatatable |
( |
| ) |
|
Definition at line 242 of file SuppliersController.php.
244 $suppliers = Supplier::select(array(
'id',
'name',
'address',
'address2',
'city',
'state',
'country',
'fax',
'phone',
'email',
'contact'))
245 ->whereNull(
'deleted_at');
247 if (Input::has(
'search')) {
248 $suppliers = $suppliers->TextSearch(e(Input::get(
'search')));
251 if (Input::has(
'offset')) {
252 $offset = e(Input::get(
'offset'));
257 if (Input::has(
'limit')) {
258 $limit = e(Input::get(
'limit'));
263 $allowed_columns = [
'id',
'name',
'address',
'phone',
'contact',
'fax',
'email'];
264 $order = Input::get(
'order') ===
'asc' ?
'asc' :
'desc';
265 $sort = in_array(Input::get(
'sort'), $allowed_columns) ? Input::get(
'sort') :
'created_at';
267 $suppliers->orderBy($sort, $order);
269 $suppliersCount = $suppliers->count();
270 $suppliers = $suppliers->skip($offset)->take($limit)->get();
274 foreach ($suppliers as $supplier) {
275 $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>';
278 'id' => $supplier->id,
279 'name' => (
string)link_to(
'admin/settings/suppliers/'.$supplier->id.
'/view', e($supplier->name)),
280 'contact' => e($supplier->contact),
281 'address' => e($supplier->address).
' '.e($supplier->address2).
' '.e($supplier->city).
' '.e($supplier->state).
' '.e($supplier->country),
282 'phone' => e($supplier->phone),
283 'fax' => e($supplier->fax),
284 'email' => ($supplier->email!=
'') ?
'<a href="mailto:'.e($supplier->email).
'">'.e($supplier->email).
'</a>' :
'',
285 'assets' => $supplier->num_assets(),
286 'licenses' => $supplier->num_licenses(),
287 'actions' => $actions
291 $data = array(
'total' => $suppliersCount,
'rows' => $rows);
App\Http\Controllers\SuppliersController::getDelete |
( |
|
$supplierId | ) |
|
Delete the given supplier.
- Parameters
-
- Returns
- Redirect
Definition at line 195 of file SuppliersController.php.
198 if (is_null($supplier = Supplier::find($supplierId))) {
200 return Redirect::to(
'admin/settings/suppliers')->with(
'error', trans(
'admin/suppliers/message.not_found'));
203 if ($supplier->num_assets() > 0) {
206 return Redirect::to(
'admin/settings/suppliers')->with(
'error', trans(
'admin/suppliers/message.assoc_users'));
213 return Redirect::to(
'admin/settings/suppliers')->with(
'success', trans(
'admin/suppliers/message.delete.success'));
App\Http\Controllers\SuppliersController::getEdit |
( |
|
$supplierId = null | ) |
|
Supplier update.
- Parameters
-
- Returns
- View
Definition at line 124 of file SuppliersController.php.
127 if (is_null($supplier = Supplier::find($supplierId))) {
129 return Redirect::to(
'admin/settings/suppliers')->with(
'error', trans(
'admin/suppliers/message.does_not_exist'));
133 return View::make(
'suppliers/edit', compact(
'supplier'));
App\Http\Controllers\SuppliersController::getIndex |
( |
| ) |
|
Show a list of all suppliers.
- Returns
- View
Definition at line 30 of file SuppliersController.php.
33 $suppliers = Supplier::orderBy(
'created_at',
'DESC')->get();
36 return View::make(
'suppliers/index', compact(
'suppliers'));
App\Http\Controllers\SuppliersController::getView |
( |
|
$supplierId = null | ) |
|
Get the asset information to present to the supplier view page.
- Parameters
-
- Returns
- View
Definition at line 225 of file SuppliersController.php.
227 $supplier = Supplier::find($supplierId);
229 if (isset($supplier->id)) {
230 return View::make(
'suppliers/view', compact(
'supplier'));
233 $error = trans(
'admin/suppliers/message.does_not_exist', compact(
'id'));
236 return Redirect::route(
'suppliers')->with(
'error', $error);
App\Http\Controllers\SuppliersController::postCreate |
( |
| ) |
|
Supplier create form processing.
- Returns
- Redirect
Definition at line 56 of file SuppliersController.php.
63 $supplier =
new Supplier;
65 $supplier->name = e(Input::get(
'name'));
66 $supplier->address = e(Input::get(
'address'));
67 $supplier->address2 = e(Input::get(
'address2'));
68 $supplier->city = e(Input::get(
'city'));
69 $supplier->state = e(Input::get(
'state'));
70 $supplier->country = e(Input::get(
'country'));
71 $supplier->zip = e(Input::get(
'zip'));
72 $supplier->contact = e(Input::get(
'contact'));
73 $supplier->phone = e(Input::get(
'phone'));
74 $supplier->fax = e(Input::get(
'fax'));
75 $supplier->email = e(Input::get(
'email'));
76 $supplier->notes = e(Input::get(
'notes'));
77 $supplier->url = $supplier->addhttp(e(Input::get(
'url')));
78 $supplier->user_id = Auth::user()->id;
83 if (Input::file(
'image')) {
84 $image = Input::file(
'image');
85 $file_name = str_random(25).
".".$image->getClientOriginalExtension();
86 $path = public_path(
'uploads/suppliers/'.$file_name);
87 Image::make($image->getRealPath())->resize(300, null,
function ($constraint) {
88 $constraint->aspectRatio();
89 $constraint->upsize();
91 $supplier->image = $file_name;
95 if ($supplier->save()) {
97 return Redirect::to(
"admin/settings/suppliers")->with(
'success', trans(
'admin/suppliers/message.create.success'));
101 return Redirect::back()->withInput()->withErrors($supplier->getErrors());
App\Http\Controllers\SuppliersController::postEdit |
( |
|
$supplierId = null | ) |
|
Supplier update form processing page.
- Parameters
-
- Returns
- Redirect
Definition at line 143 of file SuppliersController.php.
146 if (is_null($supplier = Supplier::find($supplierId))) {
148 return Redirect::to(
'admin/settings/suppliers')->with(
'error', trans(
'admin/suppliers/message.does_not_exist'));
152 $supplier->name = e(Input::get(
'name'));
153 $supplier->address = e(Input::get(
'address'));
154 $supplier->address2 = e(Input::get(
'address2'));
155 $supplier->city = e(Input::get(
'city'));
156 $supplier->state = e(Input::get(
'state'));
157 $supplier->country = e(Input::get(
'country'));
158 $supplier->zip = e(Input::get(
'zip'));
159 $supplier->contact = e(Input::get(
'contact'));
160 $supplier->phone = e(Input::get(
'phone'));
161 $supplier->fax = e(Input::get(
'fax'));
162 $supplier->email = e(Input::get(
'email'));
163 $supplier->url = $supplier->addhttp(e(Input::get(
'url')));
164 $supplier->notes = e(Input::get(
'notes'));
166 if (Input::file(
'image')) {
167 $image = Input::file(
'image');
168 $file_name = str_random(25).
".".$image->getClientOriginalExtension();
169 $path = public_path(
'uploads/suppliers/'.$file_name);
170 Image::make($image->getRealPath())->resize(300, null,
function ($constraint) {
171 $constraint->aspectRatio();
172 $constraint->upsize();
174 $supplier->image = $file_name;
177 if (Input::get(
'image_delete') == 1 && Input::file(
'image') ==
"") {
178 $supplier->image = null;
181 if ($supplier->save()) {
182 return Redirect::to(
"admin/settings/suppliers")->with(
'success', trans(
'admin/suppliers/message.update.success'));
185 return Redirect::back()->withInput()->withErrors($supplier->getErrors());
App\Http\Controllers\SuppliersController::store |
( |
| ) |
|
Definition at line 105 of file SuppliersController.php.
107 $supplier=
new Supplier;
108 $supplier->name=$new[
'name'];
109 $supplier->user_id = Auth::user()->id;
111 if ($supplier->save()) {
112 return JsonResponse::create($supplier);
114 return JsonResponse::create([
"error" =>
"Failed validation: ".print_r($supplier->getErrors(),
true)], 500);
115 return JsonResponse::create([
"error" =>
"Couldn't save Supplier"]);
The documentation for this class was generated from the following file: