2020-01-20 02:31:58 +01:00
|
|
|
<?php
|
|
|
|
/**
|
2020-09-06 11:38:10 +02:00
|
|
|
* Invoice Ninja (https://invoiceninja.com).
|
2020-01-20 02:31:58 +01:00
|
|
|
*
|
|
|
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
|
|
|
*
|
2021-01-03 22:54:54 +01:00
|
|
|
* @copyright Copyright (c) 2021. Invoice Ninja LLC (https://invoiceninja.com)
|
2020-01-20 02:31:58 +01:00
|
|
|
*
|
|
|
|
* @license https://opensource.org/licenses/AAL
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
2020-11-03 13:39:41 +01:00
|
|
|
use App\Events\Vendor\VendorWasCreated;
|
|
|
|
use App\Events\Vendor\VendorWasUpdated;
|
2020-09-23 02:16:19 +02:00
|
|
|
use App\Factory\VendorFactory;
|
2020-01-20 02:31:58 +01:00
|
|
|
use App\Filters\VendorFilters;
|
2020-09-23 02:16:19 +02:00
|
|
|
use App\Http\Requests\Vendor\CreateVendorRequest;
|
|
|
|
use App\Http\Requests\Vendor\DestroyVendorRequest;
|
|
|
|
use App\Http\Requests\Vendor\EditVendorRequest;
|
|
|
|
use App\Http\Requests\Vendor\ShowVendorRequest;
|
|
|
|
use App\Http\Requests\Vendor\StoreVendorRequest;
|
|
|
|
use App\Http\Requests\Vendor\UpdateVendorRequest;
|
2021-02-15 22:14:30 +01:00
|
|
|
use App\Http\Requests\Vendor\UploadVendorRequest;
|
2021-03-07 22:32:38 +01:00
|
|
|
use App\Models\Account;
|
2020-01-20 02:31:58 +01:00
|
|
|
use App\Models\Vendor;
|
2020-01-20 05:53:40 +01:00
|
|
|
use App\Repositories\VendorRepository;
|
|
|
|
use App\Transformers\VendorTransformer;
|
2020-11-03 13:39:41 +01:00
|
|
|
use App\Utils\Ninja;
|
2020-01-20 02:31:58 +01:00
|
|
|
use App\Utils\Traits\BulkOptions;
|
|
|
|
use App\Utils\Traits\MakesHash;
|
2021-02-15 22:14:30 +01:00
|
|
|
use App\Utils\Traits\SavesDocuments;
|
2020-01-20 02:31:58 +01:00
|
|
|
use App\Utils\Traits\Uploadable;
|
|
|
|
use Illuminate\Http\Request;
|
2020-10-28 11:10:49 +01:00
|
|
|
use Illuminate\Http\Response;
|
2020-01-20 02:31:58 +01:00
|
|
|
|
|
|
|
/**
|
2020-09-06 11:38:10 +02:00
|
|
|
* Class VendorController.
|
2020-01-20 02:31:58 +01:00
|
|
|
*/
|
|
|
|
class VendorController extends BaseController
|
|
|
|
{
|
|
|
|
use MakesHash;
|
|
|
|
use Uploadable;
|
|
|
|
use BulkOptions;
|
2021-02-15 22:14:30 +01:00
|
|
|
use SavesDocuments;
|
2020-01-20 02:31:58 +01:00
|
|
|
|
|
|
|
protected $entity_type = Vendor::class;
|
|
|
|
|
|
|
|
protected $entity_transformer = VendorTransformer::class;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var Vendorepository
|
|
|
|
*/
|
|
|
|
protected $vendor_repo;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* VendorController constructor.
|
2020-10-28 11:10:49 +01:00
|
|
|
* @param VendorRepository $vendor_repo
|
2020-01-20 02:31:58 +01:00
|
|
|
*/
|
|
|
|
public function __construct(VendorRepository $vendor_repo)
|
|
|
|
{
|
|
|
|
parent::__construct();
|
|
|
|
|
|
|
|
$this->vendor_repo = $vendor_repo;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-10-28 11:10:49 +01:00
|
|
|
* @OA\Get(
|
2020-01-20 02:31:58 +01:00
|
|
|
* path="/api/v1/vendors",
|
|
|
|
* operationId="getVendors",
|
|
|
|
* tags={"vendors"},
|
|
|
|
* summary="Gets a list of vendors",
|
|
|
|
* description="Lists vendors, search and filters allow fine grained lists to be generated.
|
|
|
|
|
2020-10-28 11:10:49 +01:00
|
|
|
Query parameters can be added to performed more fine grained filtering of the vendors, these are handled by the VendorFilters class which defines the methods available",
|
2020-01-20 02:31:58 +01:00
|
|
|
* @OA\Parameter(ref="#/components/parameters/X-Api-Secret"),
|
|
|
|
* @OA\Parameter(ref="#/components/parameters/X-Api-Token"),
|
|
|
|
* @OA\Parameter(ref="#/components/parameters/X-Requested-With"),
|
|
|
|
* @OA\Parameter(ref="#/components/parameters/include"),
|
|
|
|
* @OA\Parameter(ref="#/components/parameters/index"),
|
|
|
|
* @OA\Response(
|
|
|
|
* response=200,
|
|
|
|
* description="A list of vendors",
|
2020-06-21 23:30:25 +02:00
|
|
|
* @OA\Header(header="X-MINIMUM-CLIENT-VERSION", ref="#/components/headers/X-MINIMUM-CLIENT-VERSION"),
|
2020-01-20 02:31:58 +01:00
|
|
|
* @OA\Header(header="X-RateLimit-Remaining", ref="#/components/headers/X-RateLimit-Remaining"),
|
|
|
|
* @OA\Header(header="X-RateLimit-Limit", ref="#/components/headers/X-RateLimit-Limit"),
|
|
|
|
* @OA\JsonContent(ref="#/components/schemas/Vendor"),
|
|
|
|
* ),
|
|
|
|
* @OA\Response(
|
|
|
|
* response=422,
|
|
|
|
* description="Validation error",
|
|
|
|
* @OA\JsonContent(ref="#/components/schemas/ValidationError"),
|
|
|
|
* ),
|
|
|
|
* @OA\Response(
|
|
|
|
* response="default",
|
|
|
|
* description="Unexpected Error",
|
|
|
|
* @OA\JsonContent(ref="#/components/schemas/Error"),
|
|
|
|
* ),
|
|
|
|
* )
|
2020-10-28 11:10:49 +01:00
|
|
|
* @param VendorFilters $filters
|
|
|
|
* @return Response|mixed
|
2020-01-20 02:31:58 +01:00
|
|
|
*/
|
|
|
|
public function index(VendorFilters $filters)
|
|
|
|
{
|
|
|
|
$vendors = Vendor::filter($filters);
|
|
|
|
|
|
|
|
return $this->listResponse($vendors);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Display the specified resource.
|
|
|
|
*
|
2020-10-28 11:10:49 +01:00
|
|
|
* @param ShowVendorRequest $request
|
|
|
|
* @param Vendor $vendor
|
|
|
|
* @return Response
|
2020-01-20 02:31:58 +01:00
|
|
|
*
|
|
|
|
*
|
|
|
|
* @OA\Get(
|
|
|
|
* path="/api/v1/vendors/{id}",
|
|
|
|
* operationId="showVendor",
|
|
|
|
* tags={"vendors"},
|
|
|
|
* summary="Shows a client",
|
|
|
|
* description="Displays a client by id",
|
|
|
|
* @OA\Parameter(ref="#/components/parameters/X-Api-Secret"),
|
|
|
|
* @OA\Parameter(ref="#/components/parameters/X-Api-Token"),
|
|
|
|
* @OA\Parameter(ref="#/components/parameters/X-Requested-With"),
|
|
|
|
* @OA\Parameter(ref="#/components/parameters/include"),
|
|
|
|
* @OA\Parameter(
|
|
|
|
* name="id",
|
|
|
|
* in="path",
|
|
|
|
* description="The Vendor Hashed ID",
|
|
|
|
* example="D2J234DFA",
|
|
|
|
* required=true,
|
|
|
|
* @OA\Schema(
|
|
|
|
* type="string",
|
|
|
|
* format="string",
|
|
|
|
* ),
|
|
|
|
* ),
|
|
|
|
* @OA\Response(
|
|
|
|
* response=200,
|
|
|
|
* description="Returns the vendor object",
|
2020-06-21 23:30:25 +02:00
|
|
|
* @OA\Header(header="X-MINIMUM-CLIENT-VERSION", ref="#/components/headers/X-MINIMUM-CLIENT-VERSION"),
|
2020-01-20 02:31:58 +01:00
|
|
|
* @OA\Header(header="X-RateLimit-Remaining", ref="#/components/headers/X-RateLimit-Remaining"),
|
|
|
|
* @OA\Header(header="X-RateLimit-Limit", ref="#/components/headers/X-RateLimit-Limit"),
|
|
|
|
* @OA\JsonContent(ref="#/components/schemas/Vendor"),
|
|
|
|
* ),
|
|
|
|
* @OA\Response(
|
|
|
|
* response=422,
|
|
|
|
* description="Validation error",
|
|
|
|
* @OA\JsonContent(ref="#/components/schemas/ValidationError"),
|
|
|
|
*
|
|
|
|
* ),
|
|
|
|
* @OA\Response(
|
|
|
|
* response="default",
|
|
|
|
* description="Unexpected Error",
|
|
|
|
* @OA\JsonContent(ref="#/components/schemas/Error"),
|
|
|
|
* ),
|
|
|
|
* )
|
|
|
|
*/
|
|
|
|
public function show(ShowVendorRequest $request, Vendor $vendor)
|
|
|
|
{
|
|
|
|
return $this->itemResponse($vendor);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Show the form for editing the specified resource.
|
|
|
|
*
|
2020-10-28 11:10:49 +01:00
|
|
|
* @param EditVendorRequest $request
|
|
|
|
* @param Vendor $vendor
|
|
|
|
* @return Response
|
2020-01-20 02:31:58 +01:00
|
|
|
*
|
|
|
|
*
|
|
|
|
* @OA\Get(
|
|
|
|
* path="/api/v1/vendors/{id}/edit",
|
|
|
|
* operationId="editVendor",
|
|
|
|
* tags={"vendors"},
|
|
|
|
* summary="Shows a client for editting",
|
|
|
|
* description="Displays a client by id",
|
|
|
|
* @OA\Parameter(ref="#/components/parameters/X-Api-Secret"),
|
|
|
|
* @OA\Parameter(ref="#/components/parameters/X-Api-Token"),
|
|
|
|
* @OA\Parameter(ref="#/components/parameters/X-Requested-With"),
|
|
|
|
* @OA\Parameter(ref="#/components/parameters/include"),
|
|
|
|
* @OA\Parameter(
|
|
|
|
* name="id",
|
|
|
|
* in="path",
|
|
|
|
* description="The Vendor Hashed ID",
|
|
|
|
* example="D2J234DFA",
|
|
|
|
* required=true,
|
|
|
|
* @OA\Schema(
|
|
|
|
* type="string",
|
|
|
|
* format="string",
|
|
|
|
* ),
|
|
|
|
* ),
|
|
|
|
* @OA\Response(
|
|
|
|
* response=200,
|
|
|
|
* description="Returns the client object",
|
2020-06-21 23:30:25 +02:00
|
|
|
* @OA\Header(header="X-MINIMUM-CLIENT-VERSION", ref="#/components/headers/X-MINIMUM-CLIENT-VERSION"),
|
2020-01-20 02:31:58 +01:00
|
|
|
* @OA\Header(header="X-RateLimit-Remaining", ref="#/components/headers/X-RateLimit-Remaining"),
|
|
|
|
* @OA\Header(header="X-RateLimit-Limit", ref="#/components/headers/X-RateLimit-Limit"),
|
|
|
|
* @OA\JsonContent(ref="#/components/schemas/Vendor"),
|
|
|
|
* ),
|
|
|
|
* @OA\Response(
|
|
|
|
* response=422,
|
|
|
|
* description="Validation error",
|
|
|
|
* @OA\JsonContent(ref="#/components/schemas/ValidationError"),
|
|
|
|
*
|
|
|
|
* ),
|
|
|
|
* @OA\Response(
|
|
|
|
* response="default",
|
|
|
|
* description="Unexpected Error",
|
|
|
|
* @OA\JsonContent(ref="#/components/schemas/Error"),
|
|
|
|
* ),
|
|
|
|
* )
|
|
|
|
*/
|
|
|
|
public function edit(EditVendorRequest $request, Vendor $vendor)
|
|
|
|
{
|
|
|
|
return $this->itemResponse($vendor);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Update the specified resource in storage.
|
|
|
|
*
|
2020-10-28 11:10:49 +01:00
|
|
|
* @param UpdateVendorRequest $request
|
|
|
|
* @param Vendor $vendor
|
|
|
|
* @return Response
|
2020-01-20 02:31:58 +01:00
|
|
|
*
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @OA\Put(
|
|
|
|
* path="/api/v1/vendors/{id}",
|
|
|
|
* operationId="updateVendor",
|
|
|
|
* tags={"vendors"},
|
|
|
|
* summary="Updates a client",
|
|
|
|
* description="Handles the updating of a client by id",
|
|
|
|
* @OA\Parameter(ref="#/components/parameters/X-Api-Secret"),
|
|
|
|
* @OA\Parameter(ref="#/components/parameters/X-Api-Token"),
|
|
|
|
* @OA\Parameter(ref="#/components/parameters/X-Requested-With"),
|
|
|
|
* @OA\Parameter(ref="#/components/parameters/include"),
|
|
|
|
* @OA\Parameter(
|
|
|
|
* name="id",
|
|
|
|
* in="path",
|
|
|
|
* description="The Vendor Hashed ID",
|
|
|
|
* example="D2J234DFA",
|
|
|
|
* required=true,
|
|
|
|
* @OA\Schema(
|
|
|
|
* type="string",
|
|
|
|
* format="string",
|
|
|
|
* ),
|
|
|
|
* ),
|
|
|
|
* @OA\Response(
|
|
|
|
* response=200,
|
|
|
|
* description="Returns the client object",
|
2020-06-21 23:30:25 +02:00
|
|
|
* @OA\Header(header="X-MINIMUM-CLIENT-VERSION", ref="#/components/headers/X-MINIMUM-CLIENT-VERSION"),
|
2020-01-20 02:31:58 +01:00
|
|
|
* @OA\Header(header="X-RateLimit-Remaining", ref="#/components/headers/X-RateLimit-Remaining"),
|
|
|
|
* @OA\Header(header="X-RateLimit-Limit", ref="#/components/headers/X-RateLimit-Limit"),
|
|
|
|
* @OA\JsonContent(ref="#/components/schemas/Vendor"),
|
|
|
|
* ),
|
|
|
|
* @OA\Response(
|
|
|
|
* response=422,
|
|
|
|
* description="Validation error",
|
|
|
|
* @OA\JsonContent(ref="#/components/schemas/ValidationError"),
|
|
|
|
*
|
|
|
|
* ),
|
|
|
|
* @OA\Response(
|
|
|
|
* response="default",
|
|
|
|
* description="Unexpected Error",
|
|
|
|
* @OA\JsonContent(ref="#/components/schemas/Error"),
|
|
|
|
* ),
|
|
|
|
* )
|
|
|
|
*/
|
|
|
|
public function update(UpdateVendorRequest $request, Vendor $vendor)
|
|
|
|
{
|
2020-03-21 06:37:30 +01:00
|
|
|
if ($request->entityIsDeleted($vendor)) {
|
2020-01-20 02:31:58 +01:00
|
|
|
return $request->disallowUpdate();
|
2020-03-21 06:37:30 +01:00
|
|
|
}
|
2020-01-20 02:31:58 +01:00
|
|
|
|
2020-09-23 02:16:19 +02:00
|
|
|
$vendor = $this->vendor_repo->save($request->all(), $vendor);
|
2020-01-20 02:31:58 +01:00
|
|
|
|
|
|
|
$this->uploadLogo($request->file('company_logo'), $vendor->company, $vendor);
|
|
|
|
|
2020-11-03 13:39:41 +01:00
|
|
|
event(new VendorWasUpdated($vendor, $vendor->company, Ninja::eventVars()));
|
|
|
|
|
2020-01-20 02:31:58 +01:00
|
|
|
return $this->itemResponse($vendor->fresh());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Show the form for creating a new resource.
|
|
|
|
*
|
2020-10-28 11:10:49 +01:00
|
|
|
* @param CreateVendorRequest $request
|
|
|
|
* @return Response
|
2020-01-20 02:31:58 +01:00
|
|
|
*
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @OA\Get(
|
|
|
|
* path="/api/v1/vendors/create",
|
|
|
|
* operationId="getVendorsCreate",
|
|
|
|
* tags={"vendors"},
|
|
|
|
* summary="Gets a new blank client object",
|
|
|
|
* description="Returns a blank object with default values",
|
|
|
|
* @OA\Parameter(ref="#/components/parameters/X-Api-Secret"),
|
|
|
|
* @OA\Parameter(ref="#/components/parameters/X-Api-Token"),
|
|
|
|
* @OA\Parameter(ref="#/components/parameters/X-Requested-With"),
|
|
|
|
* @OA\Parameter(ref="#/components/parameters/include"),
|
|
|
|
* @OA\Response(
|
|
|
|
* response=200,
|
|
|
|
* description="A blank client object",
|
2020-06-21 23:30:25 +02:00
|
|
|
* @OA\Header(header="X-MINIMUM-CLIENT-VERSION", ref="#/components/headers/X-MINIMUM-CLIENT-VERSION"),
|
2020-01-20 02:31:58 +01:00
|
|
|
* @OA\Header(header="X-RateLimit-Remaining", ref="#/components/headers/X-RateLimit-Remaining"),
|
|
|
|
* @OA\Header(header="X-RateLimit-Limit", ref="#/components/headers/X-RateLimit-Limit"),
|
|
|
|
* @OA\JsonContent(ref="#/components/schemas/Vendor"),
|
|
|
|
* ),
|
|
|
|
* @OA\Response(
|
|
|
|
* response=422,
|
|
|
|
* description="Validation error",
|
|
|
|
* @OA\JsonContent(ref="#/components/schemas/ValidationError"),
|
|
|
|
*
|
|
|
|
* ),
|
|
|
|
* @OA\Response(
|
|
|
|
* response="default",
|
|
|
|
* description="Unexpected Error",
|
|
|
|
* @OA\JsonContent(ref="#/components/schemas/Error"),
|
|
|
|
* ),
|
|
|
|
* )
|
|
|
|
*/
|
|
|
|
public function create(CreateVendorRequest $request)
|
|
|
|
{
|
|
|
|
$vendor = VendorFactory::create(auth()->user()->company()->id, auth()->user()->id);
|
|
|
|
|
|
|
|
return $this->itemResponse($vendor);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Store a newly created resource in storage.
|
|
|
|
*
|
2020-10-28 11:10:49 +01:00
|
|
|
* @param StoreVendorRequest $request
|
|
|
|
* @return Response
|
2020-01-20 02:31:58 +01:00
|
|
|
*
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @OA\Post(
|
|
|
|
* path="/api/v1/vendors",
|
|
|
|
* operationId="storeVendor",
|
|
|
|
* tags={"vendors"},
|
|
|
|
* summary="Adds a client",
|
|
|
|
* description="Adds an client to a company",
|
|
|
|
* @OA\Parameter(ref="#/components/parameters/X-Api-Secret"),
|
|
|
|
* @OA\Parameter(ref="#/components/parameters/X-Api-Token"),
|
|
|
|
* @OA\Parameter(ref="#/components/parameters/X-Requested-With"),
|
|
|
|
* @OA\Parameter(ref="#/components/parameters/include"),
|
|
|
|
* @OA\Response(
|
|
|
|
* response=200,
|
|
|
|
* description="Returns the saved client object",
|
2020-06-21 23:30:25 +02:00
|
|
|
* @OA\Header(header="X-MINIMUM-CLIENT-VERSION", ref="#/components/headers/X-MINIMUM-CLIENT-VERSION"),
|
2020-01-20 02:31:58 +01:00
|
|
|
* @OA\Header(header="X-RateLimit-Remaining", ref="#/components/headers/X-RateLimit-Remaining"),
|
|
|
|
* @OA\Header(header="X-RateLimit-Limit", ref="#/components/headers/X-RateLimit-Limit"),
|
|
|
|
* @OA\JsonContent(ref="#/components/schemas/Vendor"),
|
|
|
|
* ),
|
|
|
|
* @OA\Response(
|
|
|
|
* response=422,
|
|
|
|
* description="Validation error",
|
|
|
|
* @OA\JsonContent(ref="#/components/schemas/ValidationError"),
|
|
|
|
*
|
|
|
|
* ),
|
|
|
|
* @OA\Response(
|
|
|
|
* response="default",
|
|
|
|
* description="Unexpected Error",
|
|
|
|
* @OA\JsonContent(ref="#/components/schemas/Error"),
|
|
|
|
* ),
|
|
|
|
* )
|
|
|
|
*/
|
|
|
|
public function store(StoreVendorRequest $request)
|
|
|
|
{
|
2020-09-23 02:16:19 +02:00
|
|
|
$vendor = $this->vendor_repo->save($request->all(), VendorFactory::create(auth()->user()->company()->id, auth()->user()->id));
|
2020-01-20 02:31:58 +01:00
|
|
|
|
|
|
|
$vendor->load('contacts', 'primary_contact');
|
|
|
|
|
|
|
|
$this->uploadLogo($request->file('company_logo'), $vendor->company, $vendor);
|
|
|
|
|
2020-11-03 06:44:50 +01:00
|
|
|
event(new VendorWasCreated($vendor, $vendor->company, Ninja::eventVars()));
|
|
|
|
|
2020-01-20 02:31:58 +01:00
|
|
|
return $this->itemResponse($vendor);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Remove the specified resource from storage.
|
|
|
|
*
|
2020-10-28 11:10:49 +01:00
|
|
|
* @param DestroyVendorRequest $request
|
|
|
|
* @param Vendor $vendor
|
|
|
|
* @return Response
|
2020-01-20 02:31:58 +01:00
|
|
|
*
|
|
|
|
*
|
2020-10-28 11:10:49 +01:00
|
|
|
* @throws \Exception
|
2020-01-20 02:31:58 +01:00
|
|
|
* @OA\Delete(
|
|
|
|
* path="/api/v1/vendors/{id}",
|
|
|
|
* operationId="deleteVendor",
|
|
|
|
* tags={"vendors"},
|
|
|
|
* summary="Deletes a client",
|
|
|
|
* description="Handles the deletion of a client by id",
|
|
|
|
* @OA\Parameter(ref="#/components/parameters/X-Api-Secret"),
|
|
|
|
* @OA\Parameter(ref="#/components/parameters/X-Api-Token"),
|
|
|
|
* @OA\Parameter(ref="#/components/parameters/X-Requested-With"),
|
|
|
|
* @OA\Parameter(ref="#/components/parameters/include"),
|
|
|
|
* @OA\Parameter(
|
|
|
|
* name="id",
|
|
|
|
* in="path",
|
|
|
|
* description="The Vendor Hashed ID",
|
|
|
|
* example="D2J234DFA",
|
|
|
|
* required=true,
|
|
|
|
* @OA\Schema(
|
|
|
|
* type="string",
|
|
|
|
* format="string",
|
|
|
|
* ),
|
|
|
|
* ),
|
|
|
|
* @OA\Response(
|
|
|
|
* response=200,
|
|
|
|
* description="Returns a HTTP status",
|
2020-06-21 23:30:25 +02:00
|
|
|
* @OA\Header(header="X-MINIMUM-CLIENT-VERSION", ref="#/components/headers/X-MINIMUM-CLIENT-VERSION"),
|
2020-01-20 02:31:58 +01:00
|
|
|
* @OA\Header(header="X-RateLimit-Remaining", ref="#/components/headers/X-RateLimit-Remaining"),
|
|
|
|
* @OA\Header(header="X-RateLimit-Limit", ref="#/components/headers/X-RateLimit-Limit"),
|
|
|
|
* ),
|
|
|
|
* @OA\Response(
|
|
|
|
* response=422,
|
|
|
|
* description="Validation error",
|
|
|
|
* @OA\JsonContent(ref="#/components/schemas/ValidationError"),
|
|
|
|
*
|
|
|
|
* ),
|
|
|
|
* @OA\Response(
|
|
|
|
* response="default",
|
|
|
|
* description="Unexpected Error",
|
|
|
|
* @OA\JsonContent(ref="#/components/schemas/Error"),
|
|
|
|
* ),
|
|
|
|
* )
|
|
|
|
*/
|
|
|
|
public function destroy(DestroyVendorRequest $request, Vendor $vendor)
|
|
|
|
{
|
|
|
|
//may not need these destroy routes as we are using actions to 'archive/delete'
|
|
|
|
$vendor->delete();
|
|
|
|
|
2021-01-17 05:28:03 +01:00
|
|
|
return $this->itemResponse($vendor->fresh());
|
2020-01-20 02:31:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-09-06 11:38:10 +02:00
|
|
|
* Perform bulk actions on the list view.
|
2020-01-20 02:31:58 +01:00
|
|
|
*
|
2020-10-28 11:10:49 +01:00
|
|
|
* @return Response
|
2020-01-20 02:31:58 +01:00
|
|
|
*
|
|
|
|
*
|
|
|
|
* @OA\Post(
|
|
|
|
* path="/api/v1/vendors/bulk",
|
|
|
|
* operationId="bulkVendors",
|
|
|
|
* tags={"vendors"},
|
|
|
|
* summary="Performs bulk actions on an array of vendors",
|
|
|
|
* description="",
|
|
|
|
* @OA\Parameter(ref="#/components/parameters/X-Api-Secret"),
|
|
|
|
* @OA\Parameter(ref="#/components/parameters/X-Api-Token"),
|
|
|
|
* @OA\Parameter(ref="#/components/parameters/X-Requested-With"),
|
|
|
|
* @OA\Parameter(ref="#/components/parameters/index"),
|
|
|
|
* @OA\RequestBody(
|
|
|
|
* description="User credentials",
|
|
|
|
* required=true,
|
|
|
|
* @OA\MediaType(
|
|
|
|
* mediaType="application/json",
|
|
|
|
* @OA\Schema(
|
|
|
|
* type="array",
|
|
|
|
* @OA\Items(
|
|
|
|
* type="integer",
|
|
|
|
* description="Array of hashed IDs to be bulk 'actioned",
|
|
|
|
* example="[0,1,2,3]",
|
|
|
|
* ),
|
|
|
|
* )
|
|
|
|
* )
|
|
|
|
* ),
|
|
|
|
* @OA\Response(
|
|
|
|
* response=200,
|
|
|
|
* description="The Vendor User response",
|
2020-06-21 23:30:25 +02:00
|
|
|
* @OA\Header(header="X-MINIMUM-CLIENT-VERSION", ref="#/components/headers/X-MINIMUM-CLIENT-VERSION"),
|
2020-01-20 02:31:58 +01:00
|
|
|
* @OA\Header(header="X-RateLimit-Remaining", ref="#/components/headers/X-RateLimit-Remaining"),
|
|
|
|
* @OA\Header(header="X-RateLimit-Limit", ref="#/components/headers/X-RateLimit-Limit"),
|
|
|
|
* @OA\JsonContent(ref="#/components/schemas/Vendor"),
|
|
|
|
* ),
|
|
|
|
* @OA\Response(
|
|
|
|
* response=422,
|
|
|
|
* description="Validation error",
|
|
|
|
* @OA\JsonContent(ref="#/components/schemas/ValidationError"),
|
|
|
|
* ),
|
|
|
|
* @OA\Response(
|
|
|
|
* response="default",
|
|
|
|
* description="Unexpected Error",
|
|
|
|
* @OA\JsonContent(ref="#/components/schemas/Error"),
|
|
|
|
* ),
|
|
|
|
* )
|
|
|
|
*/
|
|
|
|
public function bulk()
|
|
|
|
{
|
|
|
|
$action = request()->input('action');
|
2020-09-06 11:38:10 +02:00
|
|
|
|
2020-01-20 02:31:58 +01:00
|
|
|
$ids = request()->input('ids');
|
|
|
|
$vendors = Vendor::withTrashed()->find($this->transformKeys($ids));
|
2020-09-06 11:38:10 +02:00
|
|
|
|
2020-01-20 02:31:58 +01:00
|
|
|
$vendors->each(function ($vendor, $key) use ($action) {
|
|
|
|
if (auth()->user()->can('edit', $vendor)) {
|
2020-09-23 02:16:19 +02:00
|
|
|
$this->vendor_repo->{$action}($vendor);
|
2020-01-20 02:31:58 +01:00
|
|
|
}
|
|
|
|
});
|
2020-09-06 11:38:10 +02:00
|
|
|
|
2020-01-20 02:31:58 +01:00
|
|
|
return $this->listResponse(Vendor::withTrashed()->whereIn('id', $this->transformKeys($ids)));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-09-06 11:38:10 +02:00
|
|
|
* Returns a client statement.
|
2020-01-20 02:31:58 +01:00
|
|
|
*
|
2020-10-28 11:10:49 +01:00
|
|
|
* @return void [type] [description]
|
2020-01-20 02:31:58 +01:00
|
|
|
*/
|
|
|
|
public function statement()
|
|
|
|
{
|
|
|
|
//todo
|
|
|
|
}
|
2021-02-15 22:14:30 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Update the specified resource in storage.
|
|
|
|
*
|
|
|
|
* @param UploadVendorRequest $request
|
|
|
|
* @param Vendor $vendor
|
|
|
|
* @return Response
|
|
|
|
*
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @OA\Put(
|
|
|
|
* path="/api/v1/vendors/{id}/upload",
|
|
|
|
* operationId="uploadVendor",
|
|
|
|
* tags={"vendors"},
|
|
|
|
* summary="Uploads a document to a vendor",
|
|
|
|
* description="Handles the uploading of a document to a vendor",
|
|
|
|
* @OA\Parameter(ref="#/components/parameters/X-Api-Secret"),
|
|
|
|
* @OA\Parameter(ref="#/components/parameters/X-Api-Token"),
|
|
|
|
* @OA\Parameter(ref="#/components/parameters/X-Requested-With"),
|
|
|
|
* @OA\Parameter(ref="#/components/parameters/include"),
|
|
|
|
* @OA\Parameter(
|
|
|
|
* name="id",
|
|
|
|
* in="path",
|
|
|
|
* description="The Vendor Hashed ID",
|
|
|
|
* example="D2J234DFA",
|
|
|
|
* required=true,
|
|
|
|
* @OA\Schema(
|
|
|
|
* type="string",
|
|
|
|
* format="string",
|
|
|
|
* ),
|
|
|
|
* ),
|
|
|
|
* @OA\Response(
|
|
|
|
* response=200,
|
|
|
|
* description="Returns the Vendor object",
|
|
|
|
* @OA\Header(header="X-MINIMUM-CLIENT-VERSION", ref="#/components/headers/X-MINIMUM-CLIENT-VERSION"),
|
|
|
|
* @OA\Header(header="X-RateLimit-Remaining", ref="#/components/headers/X-RateLimit-Remaining"),
|
|
|
|
* @OA\Header(header="X-RateLimit-Limit", ref="#/components/headers/X-RateLimit-Limit"),
|
|
|
|
* @OA\JsonContent(ref="#/components/schemas/Vendor"),
|
|
|
|
* ),
|
|
|
|
* @OA\Response(
|
|
|
|
* response=422,
|
|
|
|
* description="Validation error",
|
|
|
|
* @OA\JsonContent(ref="#/components/schemas/ValidationError"),
|
|
|
|
*
|
|
|
|
* ),
|
|
|
|
* @OA\Response(
|
|
|
|
* response="default",
|
|
|
|
* description="Unexpected Error",
|
|
|
|
* @OA\JsonContent(ref="#/components/schemas/Error"),
|
|
|
|
* ),
|
|
|
|
* )
|
|
|
|
*/
|
|
|
|
public function upload(UploadVendorRequest $request, Vendor $vendor)
|
|
|
|
{
|
|
|
|
|
2021-03-07 22:32:38 +01:00
|
|
|
if(!$this->checkFeature(Account::FEATURE_DOCUMENTS))
|
|
|
|
return $this->featureFailure();
|
|
|
|
|
2021-02-15 22:14:30 +01:00
|
|
|
if ($request->has('documents'))
|
|
|
|
$this->saveDocuments($request->file('documents'), $vendor);
|
|
|
|
|
|
|
|
return $this->itemResponse($vendor->fresh());
|
|
|
|
|
|
|
|
}
|
2020-01-20 02:31:58 +01:00
|
|
|
}
|