2017-01-12 19:40:20 -08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers\Api;
|
|
|
|
|
|
|
|
use Illuminate\Http\Request;
|
|
|
|
use App\Http\Controllers\Controller;
|
2017-01-24 18:56:27 -08:00
|
|
|
use App\Http\Transformers\LicensesTransformer;
|
|
|
|
use App\Models\License;
|
|
|
|
use App\Models\Company;
|
2017-01-12 19:40:20 -08:00
|
|
|
|
|
|
|
class LicensesController extends Controller
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Display a listing of the resource.
|
|
|
|
*
|
|
|
|
* @author [A. Gianotto] [<snipe@snipe.net>]
|
|
|
|
* @since [v4.0]
|
|
|
|
*
|
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
*/
|
2017-01-24 18:56:27 -08:00
|
|
|
public function index(Request $request)
|
2017-01-12 19:40:20 -08:00
|
|
|
{
|
2017-01-24 18:56:27 -08:00
|
|
|
$this->authorize('view', License::class);
|
|
|
|
$licenses = Company::scopeCompanyables(License::with('company', 'licenseSeatsRelation', 'manufacturer'));
|
|
|
|
|
|
|
|
if ($request->has('search')) {
|
|
|
|
$licenses = $licenses->TextSearch($request->input('search'));
|
|
|
|
}
|
2017-03-11 02:49:24 -08:00
|
|
|
|
|
|
|
if ($request->has('company_id')) {
|
|
|
|
$licenses->where('company_id','=',$request->input('company_id'));
|
|
|
|
}
|
|
|
|
|
2017-03-11 02:57:19 -08:00
|
|
|
if ($request->has('name')) {
|
|
|
|
$licenses->where('licenses.name','=',$request->input('name'));
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($request->has('product_key')) {
|
|
|
|
$licenses->where('licenses.serial','=',$request->input('product_key'));
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($request->has('order_number')) {
|
|
|
|
$licenses->where('order_number','=',$request->input('order_number'));
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($request->has('purchase_order')) {
|
|
|
|
$licenses->where('purchase_order','=',$request->input('purchase_order'));
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($request->has('license_name')) {
|
|
|
|
$licenses->where('license_name','=',$request->input('license_name'));
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($request->has('license_email')) {
|
|
|
|
$licenses->where('license_email','=',$request->input('license_email'));
|
|
|
|
}
|
|
|
|
|
2017-03-11 02:49:24 -08:00
|
|
|
if ($request->has('manufacturer_id')) {
|
|
|
|
$licenses->where('manufacturer_id','=',$request->input('manufacturer_id'));
|
|
|
|
}
|
|
|
|
|
2017-03-11 02:57:19 -08:00
|
|
|
if ($request->has('depreciation_id')) {
|
|
|
|
$licenses->where('depreciation_id','=',$request->input('depreciation_id'));
|
|
|
|
}
|
|
|
|
|
2017-03-11 02:49:24 -08:00
|
|
|
if ($request->has('supplier_id')) {
|
|
|
|
$licenses->where('supplier_id','=',$request->input('supplier_id'));
|
|
|
|
}
|
|
|
|
|
2017-01-24 18:56:27 -08:00
|
|
|
$offset = request('offset', 0);
|
|
|
|
$limit = request('limit', 50);
|
|
|
|
|
2017-02-10 18:43:30 -08:00
|
|
|
$allowed_columns = ['id','name','purchase_cost','expiration_date','purchase_order','order_number','notes','purchase_date','serial','manufacturer','company','license_name','license_email'];
|
2017-01-24 18:56:27 -08:00
|
|
|
$order = $request->input('order') === 'asc' ? 'asc' : 'desc';
|
|
|
|
$sort = in_array($request->input('sort'), $allowed_columns) ? e($request->input('sort')) : 'created_at';
|
|
|
|
|
|
|
|
switch ($sort) {
|
|
|
|
case 'manufacturer':
|
|
|
|
$licenses = $licenses->OrderManufacturer($order);
|
|
|
|
break;
|
|
|
|
case 'company':
|
|
|
|
$licenses = $licenses->OrderCompany($order);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
$licenses = $licenses->orderBy($sort, $order);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
$total = $licenses->count();
|
|
|
|
$licenses = $licenses->skip($offset)->take($limit)->get();
|
|
|
|
return (new LicensesTransformer)->transformLicenses($licenses, $total);
|
|
|
|
|
2017-01-12 19:40:20 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-01-24 18:56:27 -08:00
|
|
|
|
|
|
|
|
2017-01-12 19:40:20 -08:00
|
|
|
/**
|
|
|
|
* Store a newly created resource in storage.
|
|
|
|
*
|
|
|
|
* @author [A. Gianotto] [<snipe@snipe.net>]
|
|
|
|
* @since [v4.0]
|
|
|
|
* @param \Illuminate\Http\Request $request
|
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
*/
|
|
|
|
public function store(Request $request)
|
|
|
|
{
|
|
|
|
//
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Display the specified resource.
|
|
|
|
*
|
|
|
|
* @author [A. Gianotto] [<snipe@snipe.net>]
|
|
|
|
* @param int $id
|
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
*/
|
|
|
|
public function show($id)
|
|
|
|
{
|
2017-05-18 22:10:45 -07:00
|
|
|
$license = License::find($id);
|
|
|
|
if (isset($license->id)) {
|
|
|
|
$license = $license->load('assignedusers', 'licenseSeats.user', 'licenseSeats.asset');
|
|
|
|
$this->authorize('view', $license);
|
|
|
|
return (new LicensesTransformer)->transformLicense($license);
|
|
|
|
}
|
|
|
|
return response()->json(Helper::formatStandardApiResponse('error', null, trans('admin/licenses/message.does_not_exist')), 200);
|
2017-01-12 19:40:20 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Update the specified resource in storage.
|
|
|
|
*
|
|
|
|
* @author [A. Gianotto] [<snipe@snipe.net>]
|
|
|
|
* @since [v4.0]
|
|
|
|
* @param \Illuminate\Http\Request $request
|
|
|
|
* @param int $id
|
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
*/
|
|
|
|
public function update(Request $request, $id)
|
|
|
|
{
|
|
|
|
//
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Remove the specified resource from storage.
|
|
|
|
*
|
|
|
|
* @author [A. Gianotto] [<snipe@snipe.net>]
|
|
|
|
* @since [v4.0]
|
|
|
|
* @param int $id
|
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
*/
|
|
|
|
public function destroy($id)
|
|
|
|
{
|
|
|
|
//
|
|
|
|
}
|
|
|
|
}
|