2019-04-02 08:36:49 +02:00
|
|
|
<?php
|
2019-05-11 05:32:07 +02:00
|
|
|
/**
|
|
|
|
* Invoice Ninja (https://invoiceninja.com)
|
|
|
|
*
|
|
|
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
|
|
|
*
|
2020-01-07 01:13:47 +01:00
|
|
|
* @copyright Copyright (c) 2020. Invoice Ninja LLC (https://invoiceninja.com)
|
2019-05-11 05:32:07 +02:00
|
|
|
*
|
|
|
|
* @license https://opensource.org/licenses/AAL
|
|
|
|
*/
|
2019-04-02 08:36:49 +02:00
|
|
|
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
2020-02-19 21:44:12 +01:00
|
|
|
use App\Factory\CloneInvoiceFactory;
|
|
|
|
use App\Factory\CloneInvoiceToQuoteFactory;
|
|
|
|
use App\Factory\CloneQuoteFactory;
|
|
|
|
use App\Factory\CloneQuoteToInvoiceFactory;
|
2019-05-02 13:07:38 +02:00
|
|
|
use App\Factory\QuoteFactory;
|
|
|
|
use App\Filters\QuoteFilters;
|
|
|
|
use App\Http\Requests\Quote\ActionQuoteRequest;
|
|
|
|
use App\Http\Requests\Quote\CreateQuoteRequest;
|
|
|
|
use App\Http\Requests\Quote\DestroyQuoteRequest;
|
|
|
|
use App\Http\Requests\Quote\EditQuoteRequest;
|
|
|
|
use App\Http\Requests\Quote\ShowQuoteRequest;
|
|
|
|
use App\Http\Requests\Quote\StoreQuoteRequest;
|
|
|
|
use App\Http\Requests\Quote\UpdateQuoteRequest;
|
2020-02-19 21:44:12 +01:00
|
|
|
use App\Models\Invoice;
|
2019-05-02 13:07:38 +02:00
|
|
|
use App\Models\Quote;
|
|
|
|
use App\Repositories\QuoteRepository;
|
2020-02-19 21:44:12 +01:00
|
|
|
use App\Transformers\InvoiceTransformer;
|
2019-05-02 13:07:38 +02:00
|
|
|
use App\Transformers\QuoteTransformer;
|
|
|
|
use App\Utils\Traits\MakesHash;
|
2019-04-02 08:36:49 +02:00
|
|
|
use Illuminate\Http\Request;
|
|
|
|
|
2019-05-02 13:07:38 +02:00
|
|
|
/**
|
|
|
|
* Class QuoteController
|
|
|
|
* @package App\Http\Controllers\QuoteController
|
|
|
|
*/
|
|
|
|
|
2019-04-02 08:36:49 +02:00
|
|
|
class QuoteController extends BaseController
|
|
|
|
{
|
2019-05-02 13:07:38 +02:00
|
|
|
use MakesHash;
|
|
|
|
|
|
|
|
protected $entity_type = Quote::class;
|
|
|
|
|
|
|
|
protected $entity_transformer = QuoteTransformer::class;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var QuoteRepository
|
|
|
|
*/
|
|
|
|
protected $quote_repo;
|
|
|
|
|
|
|
|
protected $base_repo;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* QuoteController constructor.
|
|
|
|
*
|
|
|
|
* @param \App\Repositories\QuoteRepository $Quote_repo The Quote repo
|
|
|
|
*/
|
|
|
|
public function __construct(QuoteRepository $quote_repo)
|
|
|
|
{
|
|
|
|
parent::__construct();
|
|
|
|
|
|
|
|
$this->quote_repo = $quote_repo;
|
|
|
|
}
|
|
|
|
|
2019-04-02 08:36:49 +02:00
|
|
|
/**
|
|
|
|
* Display a listing of the resource.
|
|
|
|
*
|
|
|
|
* @return \Illuminate\Http\Response
|
2019-10-07 06:29:16 +02:00
|
|
|
*
|
2019-12-30 22:59:12 +01:00
|
|
|
*
|
2019-10-07 06:29:16 +02:00
|
|
|
* @OA\Get(
|
|
|
|
* path="/api/v1/quotes",
|
|
|
|
* operationId="getQuotes",
|
|
|
|
* tags={"quotes"},
|
|
|
|
* summary="Gets a list of quotes",
|
|
|
|
* description="Lists quotes, search and filters allow fine grained lists to be generated.
|
|
|
|
|
|
|
|
Query parameters can be added to performed more fine grained filtering of the quotes, these are handled by the QuoteFilters class which defines the methods available",
|
|
|
|
* @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 list of quotes",
|
2019-10-07 08:31:26 +02:00
|
|
|
* @OA\Header(header="X-API-Version", ref="#/components/headers/X-API-Version"),
|
2019-10-07 06:29:16 +02: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/Quote"),
|
|
|
|
* ),
|
|
|
|
* @OA\Response(
|
|
|
|
* response=422,
|
|
|
|
* description="Validation error",
|
|
|
|
* @OA\JsonContent(ref="#/components/schemas/ValidationError"),
|
|
|
|
|
|
|
|
* ),
|
|
|
|
* @OA\Response(
|
2019-12-30 22:59:12 +01:00
|
|
|
* response="default",
|
2019-10-07 06:29:16 +02:00
|
|
|
* description="Unexpected Error",
|
|
|
|
* @OA\JsonContent(ref="#/components/schemas/Error"),
|
|
|
|
* ),
|
|
|
|
* )
|
|
|
|
*
|
2019-04-02 08:36:49 +02:00
|
|
|
*/
|
2019-10-07 06:29:16 +02:00
|
|
|
|
2019-05-02 13:07:38 +02:00
|
|
|
public function index(QuoteFilters $filters)
|
2019-04-02 08:36:49 +02:00
|
|
|
{
|
2019-05-02 13:07:38 +02:00
|
|
|
$quotes = Quote::filter($filters);
|
|
|
|
|
|
|
|
return $this->listResponse($quotes);
|
2019-04-02 08:36:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Show the form for creating a new resource.
|
|
|
|
*
|
|
|
|
* @return \Illuminate\Http\Response
|
2019-10-07 06:29:16 +02:00
|
|
|
*
|
2019-12-30 22:59:12 +01:00
|
|
|
*
|
|
|
|
*
|
2019-10-07 06:29:16 +02:00
|
|
|
* @OA\Get(
|
|
|
|
* path="/api/v1/quotes/create",
|
|
|
|
* operationId="getQuotesCreate",
|
|
|
|
* tags={"quotes"},
|
|
|
|
* summary="Gets a new blank Quote 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 Quote object",
|
2019-10-07 08:31:26 +02:00
|
|
|
* @OA\Header(header="X-API-Version", ref="#/components/headers/X-API-Version"),
|
2019-10-07 06:29:16 +02: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/Quote"),
|
|
|
|
* ),
|
|
|
|
* @OA\Response(
|
|
|
|
* response=422,
|
|
|
|
* description="Validation error",
|
|
|
|
* @OA\JsonContent(ref="#/components/schemas/ValidationError"),
|
|
|
|
*
|
|
|
|
* ),
|
|
|
|
* @OA\Response(
|
2019-12-30 22:59:12 +01:00
|
|
|
* response="default",
|
2019-10-07 06:29:16 +02:00
|
|
|
* description="Unexpected Error",
|
|
|
|
* @OA\JsonContent(ref="#/components/schemas/Error"),
|
|
|
|
* ),
|
|
|
|
* )
|
|
|
|
*
|
2019-04-02 08:36:49 +02:00
|
|
|
*/
|
2019-05-02 13:07:38 +02:00
|
|
|
public function create(CreateQuoteRequest $request)
|
2019-04-02 08:36:49 +02:00
|
|
|
{
|
2019-05-02 13:07:38 +02:00
|
|
|
$quote = QuoteFactory::create(auth()->user()->company()->id, auth()->user()->id);
|
|
|
|
|
|
|
|
return $this->itemResponse($quote);
|
2019-04-02 08:36:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Store a newly created resource in storage.
|
|
|
|
*
|
2019-05-02 13:07:38 +02:00
|
|
|
* @param \App\Http\Requests\Quote\StoreQuoteRequest $request The request
|
|
|
|
*
|
2019-04-02 08:36:49 +02:00
|
|
|
* @return \Illuminate\Http\Response
|
2019-10-07 06:29:16 +02:00
|
|
|
*
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @OA\Post(
|
|
|
|
* path="/api/v1/quotes",
|
|
|
|
* operationId="storeQuote",
|
|
|
|
* tags={"quotes"},
|
|
|
|
* summary="Adds a Quote",
|
|
|
|
* description="Adds an Quote to the system",
|
|
|
|
* @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 Quote object",
|
2019-10-07 08:31:26 +02:00
|
|
|
* @OA\Header(header="X-API-Version", ref="#/components/headers/X-API-Version"),
|
2019-10-07 06:29:16 +02: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/Quote"),
|
|
|
|
* ),
|
|
|
|
* @OA\Response(
|
|
|
|
* response=422,
|
|
|
|
* description="Validation error",
|
|
|
|
* @OA\JsonContent(ref="#/components/schemas/ValidationError"),
|
|
|
|
*
|
|
|
|
* ),
|
|
|
|
* @OA\Response(
|
2019-12-30 22:59:12 +01:00
|
|
|
* response="default",
|
2019-10-07 06:29:16 +02:00
|
|
|
* description="Unexpected Error",
|
|
|
|
* @OA\JsonContent(ref="#/components/schemas/Error"),
|
|
|
|
* ),
|
|
|
|
* )
|
|
|
|
*
|
2019-04-02 08:36:49 +02:00
|
|
|
*/
|
2019-05-02 13:07:38 +02:00
|
|
|
public function store(StoreQuoteRequest $request)
|
2019-04-02 08:36:49 +02:00
|
|
|
{
|
2019-12-17 23:40:15 +01:00
|
|
|
$quote = $this->quote_repo->save($request->all(), QuoteFactory::create(auth()->user()->company()->id, auth()->user()->id));
|
2019-05-02 13:07:38 +02:00
|
|
|
|
|
|
|
return $this->itemResponse($quote);
|
2019-04-02 08:36:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Display the specified resource.
|
|
|
|
*
|
2019-05-02 13:07:38 +02:00
|
|
|
* @param \App\Http\Requests\Quote\ShowQuoteRequest $request The request
|
|
|
|
* @param \App\Models\Quote $quote The quote
|
|
|
|
*
|
2019-04-02 08:36:49 +02:00
|
|
|
* @return \Illuminate\Http\Response
|
2019-10-07 06:29:16 +02:00
|
|
|
*
|
|
|
|
*
|
|
|
|
* @OA\Get(
|
|
|
|
* path="/api/v1/quotes/{id}",
|
|
|
|
* operationId="showQuote",
|
|
|
|
* tags={"quotes"},
|
|
|
|
* summary="Shows an Quote",
|
|
|
|
* description="Displays an Quote 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 Quote Hashed ID",
|
|
|
|
* example="D2J234DFA",
|
|
|
|
* required=true,
|
|
|
|
* @OA\Schema(
|
|
|
|
* type="string",
|
|
|
|
* format="string",
|
|
|
|
* ),
|
|
|
|
* ),
|
|
|
|
* @OA\Response(
|
|
|
|
* response=200,
|
|
|
|
* description="Returns the Quote object",
|
2019-10-07 08:31:26 +02:00
|
|
|
* @OA\Header(header="X-API-Version", ref="#/components/headers/X-API-Version"),
|
2019-10-07 06:29:16 +02: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/Quote"),
|
|
|
|
* ),
|
|
|
|
* @OA\Response(
|
|
|
|
* response=422,
|
|
|
|
* description="Validation error",
|
|
|
|
* @OA\JsonContent(ref="#/components/schemas/ValidationError"),
|
|
|
|
*
|
|
|
|
* ),
|
|
|
|
* @OA\Response(
|
2019-12-30 22:59:12 +01:00
|
|
|
* response="default",
|
2019-10-07 06:29:16 +02:00
|
|
|
* description="Unexpected Error",
|
|
|
|
* @OA\JsonContent(ref="#/components/schemas/Error"),
|
|
|
|
* ),
|
|
|
|
* )
|
|
|
|
*
|
2019-04-02 08:36:49 +02:00
|
|
|
*/
|
2019-05-02 13:07:38 +02:00
|
|
|
public function show(ShowQuoteRequest $request, Quote $quote)
|
2019-04-02 08:36:49 +02:00
|
|
|
{
|
2019-05-02 13:07:38 +02:00
|
|
|
return $this->itemResponse($quote);
|
2019-04-02 08:36:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Show the form for editing the specified resource.
|
|
|
|
*
|
2019-05-02 13:07:38 +02:00
|
|
|
* @param \App\Http\Requests\Quote\EditQuoteRequest $request The request
|
|
|
|
* @param \App\Models\Quote $quote The quote
|
|
|
|
*
|
2019-04-02 08:36:49 +02:00
|
|
|
* @return \Illuminate\Http\Response
|
2019-10-07 06:29:16 +02:00
|
|
|
*
|
2019-12-30 22:59:12 +01:00
|
|
|
*
|
2019-10-07 06:29:16 +02:00
|
|
|
* @OA\Get(
|
|
|
|
* path="/api/v1/quotes/{id}/edit",
|
|
|
|
* operationId="editQuote",
|
|
|
|
* tags={"quotes"},
|
|
|
|
* summary="Shows an Quote for editting",
|
|
|
|
* description="Displays an Quote 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 Quote Hashed ID",
|
|
|
|
* example="D2J234DFA",
|
|
|
|
* required=true,
|
|
|
|
* @OA\Schema(
|
|
|
|
* type="string",
|
|
|
|
* format="string",
|
|
|
|
* ),
|
|
|
|
* ),
|
|
|
|
* @OA\Response(
|
|
|
|
* response=200,
|
|
|
|
* description="Returns the Quote object",
|
2019-10-07 08:31:26 +02:00
|
|
|
* @OA\Header(header="X-API-Version", ref="#/components/headers/X-API-Version"),
|
2019-10-07 06:29:16 +02: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/Quote"),
|
|
|
|
* ),
|
|
|
|
* @OA\Response(
|
|
|
|
* response=422,
|
|
|
|
* description="Validation error",
|
|
|
|
* @OA\JsonContent(ref="#/components/schemas/ValidationError"),
|
|
|
|
*
|
|
|
|
* ),
|
|
|
|
* @OA\Response(
|
2019-12-30 22:59:12 +01:00
|
|
|
* response="default",
|
2019-10-07 06:29:16 +02:00
|
|
|
* description="Unexpected Error",
|
|
|
|
* @OA\JsonContent(ref="#/components/schemas/Error"),
|
|
|
|
* ),
|
|
|
|
* )
|
|
|
|
*
|
2019-12-30 22:59:12 +01:00
|
|
|
*/
|
2019-05-02 13:07:38 +02:00
|
|
|
public function edit(EditQuoteRequest $request, Quote $quote)
|
2019-04-02 08:36:49 +02:00
|
|
|
{
|
2019-05-02 13:07:38 +02:00
|
|
|
return $this->itemResponse($quote);
|
|
|
|
}
|
|
|
|
|
2019-04-02 08:36:49 +02:00
|
|
|
/**
|
|
|
|
* Update the specified resource in storage.
|
|
|
|
*
|
2019-05-02 13:07:38 +02:00
|
|
|
* @param \App\Http\Requests\Quote\UpdateQuoteRequest $request The request
|
|
|
|
* @param \App\Models\Quote $quote The quote
|
|
|
|
*
|
2019-04-02 08:36:49 +02:00
|
|
|
* @return \Illuminate\Http\Response
|
2019-10-07 06:29:16 +02:00
|
|
|
*
|
2019-12-30 22:59:12 +01:00
|
|
|
*
|
2019-10-07 06:29:16 +02:00
|
|
|
* @OA\Put(
|
|
|
|
* path="/api/v1/quotes/{id}",
|
|
|
|
* operationId="updateQuote",
|
|
|
|
* tags={"quotes"},
|
|
|
|
* summary="Updates an Quote",
|
|
|
|
* description="Handles the updating of an Quote 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 Quote Hashed ID",
|
|
|
|
* example="D2J234DFA",
|
|
|
|
* required=true,
|
|
|
|
* @OA\Schema(
|
|
|
|
* type="string",
|
|
|
|
* format="string",
|
|
|
|
* ),
|
|
|
|
* ),
|
|
|
|
* @OA\Response(
|
|
|
|
* response=200,
|
|
|
|
* description="Returns the Quote object",
|
2019-10-07 08:31:26 +02:00
|
|
|
* @OA\Header(header="X-API-Version", ref="#/components/headers/X-API-Version"),
|
2019-10-07 06:29:16 +02: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/Quote"),
|
|
|
|
* ),
|
|
|
|
* @OA\Response(
|
|
|
|
* response=422,
|
|
|
|
* description="Validation error",
|
|
|
|
* @OA\JsonContent(ref="#/components/schemas/ValidationError"),
|
|
|
|
*
|
|
|
|
* ),
|
|
|
|
* @OA\Response(
|
2019-12-30 22:59:12 +01:00
|
|
|
* response="default",
|
2019-10-07 06:29:16 +02:00
|
|
|
* description="Unexpected Error",
|
|
|
|
* @OA\JsonContent(ref="#/components/schemas/Error"),
|
|
|
|
* ),
|
|
|
|
* )
|
|
|
|
*
|
2019-04-02 08:36:49 +02:00
|
|
|
*/
|
2019-05-02 13:07:38 +02:00
|
|
|
public function update(UpdateQuoteRequest $request, Quote $quote)
|
2019-04-02 08:36:49 +02:00
|
|
|
{
|
2019-12-30 22:59:12 +01:00
|
|
|
if($request->entityIsDeleted($quote))
|
|
|
|
return $request->disallowUpdate();
|
|
|
|
|
2019-12-17 23:40:15 +01:00
|
|
|
$quote = $this->quote_repo->save($request->all(), $quote);
|
2019-05-02 13:07:38 +02:00
|
|
|
|
|
|
|
return $this->itemResponse($quote);
|
2019-04-02 08:36:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Remove the specified resource from storage.
|
|
|
|
*
|
2019-12-30 22:59:12 +01:00
|
|
|
* @param \App\Http\Requests\Quote\DestroyQuoteRequest $request
|
|
|
|
* @param \App\Models\Quote $quote
|
2019-05-02 13:07:38 +02:00
|
|
|
*
|
|
|
|
* @return \Illuminate\Http\Response
|
2019-10-07 06:29:16 +02:00
|
|
|
*
|
2019-12-30 22:59:12 +01:00
|
|
|
*
|
2019-10-07 06:29:16 +02:00
|
|
|
* @OA\Delete(
|
|
|
|
* path="/api/v1/quotes/{id}",
|
|
|
|
* operationId="deleteQuote",
|
|
|
|
* tags={"quotes"},
|
|
|
|
* summary="Deletes a Quote",
|
|
|
|
* description="Handles the deletion of an Quote 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 Quote Hashed ID",
|
|
|
|
* example="D2J234DFA",
|
|
|
|
* required=true,
|
|
|
|
* @OA\Schema(
|
|
|
|
* type="string",
|
|
|
|
* format="string",
|
|
|
|
* ),
|
|
|
|
* ),
|
|
|
|
* @OA\Response(
|
|
|
|
* response=200,
|
|
|
|
* description="Returns a HTTP status",
|
2019-10-07 08:31:26 +02:00
|
|
|
* @OA\Header(header="X-API-Version", ref="#/components/headers/X-API-Version"),
|
2019-10-07 06:29:16 +02: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(
|
2019-12-30 22:59:12 +01:00
|
|
|
* response="default",
|
2019-10-07 06:29:16 +02:00
|
|
|
* description="Unexpected Error",
|
|
|
|
* @OA\JsonContent(ref="#/components/schemas/Error"),
|
|
|
|
* ),
|
|
|
|
* )
|
|
|
|
*
|
2019-04-02 08:36:49 +02:00
|
|
|
*/
|
2019-05-02 13:07:38 +02:00
|
|
|
public function destroy(DestroyQuoteRequest $request, Quote $quote)
|
2019-04-02 08:36:49 +02:00
|
|
|
{
|
2019-05-02 13:07:38 +02:00
|
|
|
$quote->delete();
|
|
|
|
|
|
|
|
return response()->json([], 200);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Perform bulk actions on the list view
|
2019-12-30 22:59:12 +01:00
|
|
|
*
|
2019-05-02 13:07:38 +02:00
|
|
|
* @return Collection
|
2019-10-07 06:29:16 +02:00
|
|
|
*
|
2019-12-30 22:59:12 +01:00
|
|
|
*
|
2019-10-07 06:29:16 +02:00
|
|
|
* @OA\Post(
|
|
|
|
* path="/api/v1/quotes/bulk",
|
|
|
|
* operationId="bulkQuotes",
|
|
|
|
* tags={"quotes"},
|
|
|
|
* summary="Performs bulk actions on an array of quotes",
|
|
|
|
* 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(
|
2019-10-07 06:57:14 +02:00
|
|
|
* description="Hashed ids",
|
2019-10-07 06:29:16 +02:00
|
|
|
* 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,
|
2019-10-07 06:57:14 +02:00
|
|
|
* description="The Quote response",
|
2019-10-07 08:31:26 +02:00
|
|
|
* @OA\Header(header="X-API-Version", ref="#/components/headers/X-API-Version"),
|
2019-10-07 06:29:16 +02: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"),
|
2019-10-07 06:57:14 +02:00
|
|
|
* @OA\JsonContent(ref="#/components/schemas/Quote"),
|
2019-10-07 06:29:16 +02:00
|
|
|
* ),
|
|
|
|
* @OA\Response(
|
|
|
|
* response=422,
|
|
|
|
* description="Validation error",
|
|
|
|
* @OA\JsonContent(ref="#/components/schemas/ValidationError"),
|
|
|
|
|
|
|
|
* ),
|
|
|
|
* @OA\Response(
|
2019-12-30 22:59:12 +01:00
|
|
|
* response="default",
|
2019-10-07 06:29:16 +02:00
|
|
|
* description="Unexpected Error",
|
|
|
|
* @OA\JsonContent(ref="#/components/schemas/Error"),
|
|
|
|
* ),
|
|
|
|
* )
|
|
|
|
*
|
2019-05-02 13:07:38 +02:00
|
|
|
*/
|
|
|
|
public function bulk()
|
|
|
|
{
|
|
|
|
$action = request()->input('action');
|
|
|
|
|
|
|
|
$ids = request()->input('ids');
|
|
|
|
|
2019-11-21 09:38:57 +01:00
|
|
|
$quotes = Quote::withTrashed()->find($this->transformKeys($ids));
|
2019-05-02 13:07:38 +02:00
|
|
|
|
2019-12-30 22:59:12 +01:00
|
|
|
$quotes->each(function ($quote, $key) use ($action) {
|
|
|
|
if (auth()->user()->can('edit', $quote)) {
|
2019-11-25 10:38:55 +01:00
|
|
|
$this->quote_repo->{$action}($quote);
|
2019-12-30 22:59:12 +01:00
|
|
|
}
|
2019-05-02 13:07:38 +02:00
|
|
|
});
|
|
|
|
|
2019-11-21 09:38:57 +01:00
|
|
|
return $this->listResponse(Quote::withTrashed()->whereIn('id', $this->transformKeys($ids)));
|
2019-05-02 13:07:38 +02:00
|
|
|
}
|
|
|
|
|
2019-10-07 06:29:16 +02:00
|
|
|
/**
|
|
|
|
* Quote Actions
|
|
|
|
*
|
2019-12-30 22:59:12 +01:00
|
|
|
*
|
|
|
|
*
|
2019-10-07 06:29:16 +02:00
|
|
|
* @OA\Get(
|
|
|
|
* path="/api/v1/quotes/{id}/{action}",
|
|
|
|
* operationId="actionQuote",
|
|
|
|
* tags={"quotes"},
|
|
|
|
* summary="Performs a custom action on an Quote",
|
|
|
|
* description="Performs a custom action on an Quote.
|
2019-12-30 22:59:12 +01:00
|
|
|
|
2019-10-07 06:29:16 +02:00
|
|
|
The current range of actions are as follows
|
|
|
|
- clone_to_Quote
|
|
|
|
- clone_to_quote
|
|
|
|
- history
|
|
|
|
- delivery_note
|
|
|
|
- mark_paid
|
|
|
|
- download
|
|
|
|
- archive
|
|
|
|
- delete
|
|
|
|
- email",
|
|
|
|
* @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 Quote Hashed ID",
|
|
|
|
* example="D2J234DFA",
|
|
|
|
* required=true,
|
|
|
|
* @OA\Schema(
|
|
|
|
* type="string",
|
|
|
|
* format="string",
|
|
|
|
* ),
|
|
|
|
* ),
|
|
|
|
* @OA\Parameter(
|
|
|
|
* name="action",
|
|
|
|
* in="path",
|
|
|
|
* description="The action string to be performed",
|
|
|
|
* example="clone_to_quote",
|
|
|
|
* required=true,
|
|
|
|
* @OA\Schema(
|
|
|
|
* type="string",
|
|
|
|
* format="string",
|
|
|
|
* ),
|
2019-12-30 22:59:12 +01:00
|
|
|
* ),
|
2019-10-07 06:29:16 +02:00
|
|
|
* @OA\Response(
|
|
|
|
* response=200,
|
|
|
|
* description="Returns the Quote object",
|
2019-10-07 08:31:26 +02:00
|
|
|
* @OA\Header(header="X-API-Version", ref="#/components/headers/X-API-Version"),
|
2019-10-07 06:29:16 +02: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/Quote"),
|
|
|
|
* ),
|
|
|
|
* @OA\Response(
|
|
|
|
* response=422,
|
|
|
|
* description="Validation error",
|
|
|
|
* @OA\JsonContent(ref="#/components/schemas/ValidationError"),
|
|
|
|
*
|
|
|
|
* ),
|
|
|
|
* @OA\Response(
|
2019-12-30 22:59:12 +01:00
|
|
|
* response="default",
|
2019-10-07 06:29:16 +02:00
|
|
|
* description="Unexpected Error",
|
|
|
|
* @OA\JsonContent(ref="#/components/schemas/Error"),
|
|
|
|
* ),
|
|
|
|
* )
|
|
|
|
*
|
2019-12-30 22:59:12 +01:00
|
|
|
*/
|
2019-05-02 13:07:38 +02:00
|
|
|
public function action(ActionQuoteRequest $request, Quote $quote, $action)
|
|
|
|
{
|
|
|
|
switch ($action) {
|
|
|
|
case 'clone_to_invoice':
|
2020-02-19 21:44:12 +01:00
|
|
|
|
|
|
|
$this->entity_type = Invoice::class;
|
|
|
|
$this->entity_transformer = InvoiceTransformer::class;
|
|
|
|
|
|
|
|
$invoice = CloneQuoteToInvoiceFactory::create($quote, auth()->user()->id);
|
|
|
|
return $this->itemResponse($invoice);
|
2019-05-02 13:07:38 +02:00
|
|
|
break;
|
|
|
|
case 'clone_to_quote':
|
2020-02-19 21:44:12 +01:00
|
|
|
$quote = CloneQuoteFactory::create($quote, auth()->user()->id);
|
|
|
|
return $this->itemResponse($quote);
|
2019-05-02 13:07:38 +02:00
|
|
|
break;
|
|
|
|
case 'history':
|
|
|
|
# code...
|
|
|
|
break;
|
|
|
|
case 'delivery_note':
|
|
|
|
# code...
|
|
|
|
break;
|
|
|
|
case 'mark_paid':
|
|
|
|
# code...
|
|
|
|
break;
|
2019-11-25 10:38:55 +01:00
|
|
|
case 'download':
|
|
|
|
return response()->download(public_path($quote->pdf_file_path()));
|
|
|
|
break;
|
2019-05-02 13:07:38 +02:00
|
|
|
case 'archive':
|
2019-11-25 10:38:55 +01:00
|
|
|
$this->invoice_repo->archive($quote);
|
|
|
|
return $this->listResponse($quote);
|
2019-05-02 13:07:38 +02:00
|
|
|
break;
|
|
|
|
case 'delete':
|
2019-11-25 10:38:55 +01:00
|
|
|
$this->quote_repo->delete($quote);
|
|
|
|
return $this->listResponse($quote);
|
2019-05-02 13:07:38 +02:00
|
|
|
break;
|
|
|
|
case 'email':
|
2019-12-30 22:59:12 +01:00
|
|
|
return response()->json(['message'=>'email sent'], 200);
|
2019-05-02 13:07:38 +02:00
|
|
|
break;
|
|
|
|
default:
|
2019-12-30 22:59:12 +01:00
|
|
|
return response()->json(['message' => "The requested action `{$action}` is not available."], 400);
|
2019-05-02 13:07:38 +02:00
|
|
|
break;
|
|
|
|
}
|
2019-04-02 08:36:49 +02:00
|
|
|
}
|
2019-12-30 22:59:12 +01:00
|
|
|
}
|