2019-04-02 08:36:49 +02:00
|
|
|
<?php
|
2019-05-11 05:32:07 +02:00
|
|
|
/**
|
2020-09-06 11:38:10 +02:00
|
|
|
* Invoice Ninja (https://invoiceninja.com).
|
2019-05-11 05:32:07 +02:00
|
|
|
*
|
|
|
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
|
|
|
*
|
2023-01-28 23:21:40 +01:00
|
|
|
* @copyright Copyright (c) 2023. Invoice Ninja LLC (https://invoiceninja.com)
|
2019-05-11 05:32:07 +02:00
|
|
|
*
|
2021-06-16 08:58:16 +02:00
|
|
|
* @license https://www.elastic.co/licensing/elastic-license
|
2019-05-11 05:32:07 +02:00
|
|
|
*/
|
2019-04-02 08:36:49 +02:00
|
|
|
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
2020-11-03 11:19:32 +01:00
|
|
|
use App\Events\Quote\QuoteWasCreated;
|
|
|
|
use App\Events\Quote\QuoteWasUpdated;
|
2023-11-26 08:41:42 +01:00
|
|
|
use App\Factory\CloneQuoteFactory;
|
2020-02-19 21:44:12 +01:00
|
|
|
use App\Factory\CloneQuoteToInvoiceFactory;
|
2023-11-26 08:41:42 +01:00
|
|
|
use App\Factory\QuoteFactory;
|
|
|
|
use App\Filters\QuoteFilters;
|
|
|
|
use App\Http\Requests\Quote\ActionQuoteRequest;
|
|
|
|
use App\Http\Requests\Quote\BulkActionQuoteRequest;
|
|
|
|
use App\Http\Requests\Quote\CreateQuoteRequest;
|
|
|
|
use App\Http\Requests\Quote\DestroyQuoteRequest;
|
2019-05-02 13:07:38 +02:00
|
|
|
use App\Http\Requests\Quote\EditQuoteRequest;
|
|
|
|
use App\Http\Requests\Quote\ShowQuoteRequest;
|
|
|
|
use App\Http\Requests\Quote\StoreQuoteRequest;
|
|
|
|
use App\Http\Requests\Quote\UpdateQuoteRequest;
|
2021-02-15 21:58:19 +01:00
|
|
|
use App\Http\Requests\Quote\UploadQuoteRequest;
|
2023-11-26 08:41:42 +01:00
|
|
|
use App\Jobs\Quote\ZipQuotes;
|
|
|
|
use App\Models\Account;
|
|
|
|
use App\Models\Client;
|
|
|
|
use App\Models\Invoice;
|
|
|
|
use App\Models\Project;
|
|
|
|
use App\Models\Quote;
|
|
|
|
use App\Repositories\QuoteRepository;
|
|
|
|
use App\Services\PdfMaker\PdfMerge;
|
|
|
|
use App\Services\Template\TemplateAction;
|
|
|
|
use App\Transformers\InvoiceTransformer;
|
|
|
|
use App\Transformers\ProjectTransformer;
|
|
|
|
use App\Transformers\QuoteTransformer;
|
|
|
|
use App\Utils\Ninja;
|
|
|
|
use App\Utils\Traits\GeneratesCounter;
|
|
|
|
use App\Utils\Traits\MakesHash;
|
|
|
|
use App\Utils\Traits\SavesDocuments;
|
|
|
|
use Illuminate\Http\Request;
|
|
|
|
use Illuminate\Http\Response;
|
|
|
|
use Illuminate\Support\Facades\App;
|
|
|
|
use Illuminate\Support\Facades\Storage;
|
2019-04-02 08:36:49 +02:00
|
|
|
|
2019-05-02 13:07:38 +02:00
|
|
|
/**
|
2020-09-06 11:38:10 +02:00
|
|
|
* Class QuoteController.
|
2019-05-02 13:07:38 +02:00
|
|
|
*/
|
2019-04-02 08:36:49 +02:00
|
|
|
class QuoteController extends BaseController
|
|
|
|
{
|
2019-05-02 13:07:38 +02:00
|
|
|
use MakesHash;
|
2021-02-15 21:58:19 +01:00
|
|
|
use SavesDocuments;
|
2022-08-15 04:50:45 +02:00
|
|
|
use GeneratesCounter;
|
2019-05-02 13:07:38 +02:00
|
|
|
|
|
|
|
protected $entity_type = Quote::class;
|
|
|
|
|
|
|
|
protected $entity_transformer = QuoteTransformer::class;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var QuoteRepository
|
|
|
|
*/
|
|
|
|
protected $quote_repo;
|
|
|
|
|
|
|
|
protected $base_repo;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* QuoteController constructor.
|
|
|
|
*
|
2020-10-28 11:10:49 +01:00
|
|
|
* @param QuoteRepository $quote_repo
|
2019-05-02 13:07:38 +02:00
|
|
|
*/
|
|
|
|
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.
|
|
|
|
*
|
2020-10-28 11:10:49 +01:00
|
|
|
* @param QuoteFilters $filters
|
|
|
|
* @return 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.
|
2020-11-04 07:02:15 +01:00
|
|
|
*
|
|
|
|
* 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",
|
2023-02-10 10:21:10 +01:00
|
|
|
* @OA\Parameter(ref="#/components/parameters/X-API-TOKEN"),
|
2019-10-07 06:29:16 +02:00
|
|
|
* @OA\Parameter(ref="#/components/parameters/X-Requested-With"),
|
|
|
|
* @OA\Parameter(ref="#/components/parameters/include"),
|
|
|
|
* @OA\Response(
|
|
|
|
* response=200,
|
|
|
|
* description="A list of quotes",
|
2020-06-21 23:30:25 +02:00
|
|
|
* @OA\Header(header="X-MINIMUM-CLIENT-VERSION", ref="#/components/headers/X-MINIMUM-CLIENT-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 index(QuoteFilters $filters)
|
2019-04-02 08:36:49 +02:00
|
|
|
{
|
2019-05-02 13:07:38 +02:00
|
|
|
$quotes = Quote::filter($filters);
|
2020-09-06 11:38:10 +02:00
|
|
|
|
2019-05-02 13:07:38 +02:00
|
|
|
return $this->listResponse($quotes);
|
2019-04-02 08:36:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Show the form for creating a new resource.
|
|
|
|
*
|
2020-10-28 11:10:49 +01:00
|
|
|
* @param CreateQuoteRequest $request
|
|
|
|
* @return 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",
|
2023-02-10 10:21:10 +01:00
|
|
|
* @OA\Parameter(ref="#/components/parameters/X-API-TOKEN"),
|
2019-10-07 06:29:16 +02:00
|
|
|
* @OA\Parameter(ref="#/components/parameters/X-Requested-With"),
|
|
|
|
* @OA\Parameter(ref="#/components/parameters/include"),
|
|
|
|
* @OA\Response(
|
|
|
|
* response=200,
|
|
|
|
* description="A blank Quote object",
|
2020-06-21 23:30:25 +02:00
|
|
|
* @OA\Header(header="X-MINIMUM-CLIENT-VERSION", ref="#/components/headers/X-MINIMUM-CLIENT-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
|
|
|
{
|
2023-08-04 09:12:21 +02:00
|
|
|
/** @var \App\Models\User $user */
|
|
|
|
$user = auth()->user();
|
|
|
|
|
|
|
|
$quote = QuoteFactory::create($user->company()->id, $user->id);
|
2023-12-14 23:08:44 +01:00
|
|
|
$quote->date = now()->addSeconds($user->company()->utc_offset())->format('Y-m-d');
|
2019-05-02 13:07:38 +02:00
|
|
|
|
|
|
|
return $this->itemResponse($quote);
|
2019-04-02 08:36:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Store a newly created resource in storage.
|
|
|
|
*
|
2020-10-28 11:10:49 +01:00
|
|
|
* @param StoreQuoteRequest $request The request
|
2019-05-02 13:07:38 +02:00
|
|
|
*
|
2020-10-28 11:10:49 +01:00
|
|
|
* @return 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",
|
2023-02-10 10:21:10 +01:00
|
|
|
* @OA\Parameter(ref="#/components/parameters/X-API-TOKEN"),
|
2019-10-07 06:29:16 +02:00
|
|
|
* @OA\Parameter(ref="#/components/parameters/X-Requested-With"),
|
|
|
|
* @OA\Parameter(ref="#/components/parameters/include"),
|
|
|
|
* @OA\Response(
|
|
|
|
* response=200,
|
|
|
|
* description="Returns the saved Quote object",
|
2020-06-21 23:30:25 +02:00
|
|
|
* @OA\Header(header="X-MINIMUM-CLIENT-VERSION", ref="#/components/headers/X-MINIMUM-CLIENT-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
|
|
|
{
|
2023-08-04 09:12:21 +02:00
|
|
|
/** @var \App\Models\User $user */
|
|
|
|
$user = auth()->user();
|
2024-01-14 05:05:00 +01:00
|
|
|
|
2023-08-04 09:12:21 +02:00
|
|
|
$quote = $this->quote_repo->save($request->all(), QuoteFactory::create($user->company()->id, $user->id));
|
2019-05-02 13:07:38 +02:00
|
|
|
|
2021-09-15 03:20:31 +02:00
|
|
|
$quote = $quote->service()
|
|
|
|
->fillDefaults()
|
|
|
|
->triggeredActions($request)
|
|
|
|
->save();
|
2020-11-04 07:02:15 +01:00
|
|
|
|
2023-08-04 09:12:21 +02:00
|
|
|
event(new QuoteWasCreated($quote, $quote->company, Ninja::eventVars($user->id)));
|
2020-11-03 11:19:32 +01:00
|
|
|
|
2019-05-02 13:07:38 +02:00
|
|
|
return $this->itemResponse($quote);
|
2019-04-02 08:36:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Display the specified resource.
|
|
|
|
*
|
2020-10-28 11:10:49 +01:00
|
|
|
* @param ShowQuoteRequest $request The request
|
|
|
|
* @param Quote $quote The quote
|
2019-05-02 13:07:38 +02:00
|
|
|
*
|
2020-10-28 11:10:49 +01:00
|
|
|
* @return 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",
|
2023-02-10 10:21:10 +01:00
|
|
|
* @OA\Parameter(ref="#/components/parameters/X-API-TOKEN"),
|
2019-10-07 06:29:16 +02:00
|
|
|
* @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",
|
2020-06-21 23:30:25 +02:00
|
|
|
* @OA\Header(header="X-MINIMUM-CLIENT-VERSION", ref="#/components/headers/X-MINIMUM-CLIENT-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.
|
|
|
|
*
|
2020-10-28 11:10:49 +01:00
|
|
|
* @param EditQuoteRequest $request The request
|
|
|
|
* @param Quote $quote The quote
|
2019-05-02 13:07:38 +02:00
|
|
|
*
|
2020-10-28 11:10:49 +01:00
|
|
|
* @return 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",
|
2023-02-10 10:21:10 +01:00
|
|
|
* @OA\Parameter(ref="#/components/parameters/X-API-TOKEN"),
|
2019-10-07 06:29:16 +02:00
|
|
|
* @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",
|
2020-06-21 23:30:25 +02:00
|
|
|
* @OA\Header(header="X-MINIMUM-CLIENT-VERSION", ref="#/components/headers/X-MINIMUM-CLIENT-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);
|
|
|
|
}
|
2020-09-06 11:38:10 +02:00
|
|
|
|
2019-04-02 08:36:49 +02:00
|
|
|
/**
|
|
|
|
* Update the specified resource in storage.
|
|
|
|
*
|
2020-10-28 11:10:49 +01:00
|
|
|
* @param UpdateQuoteRequest $request The request
|
|
|
|
* @param Quote $quote The quote
|
2019-05-02 13:07:38 +02:00
|
|
|
*
|
2020-10-28 11:10:49 +01:00
|
|
|
* @return 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",
|
2023-02-10 10:21:10 +01:00
|
|
|
* @OA\Parameter(ref="#/components/parameters/X-API-TOKEN"),
|
2019-10-07 06:29:16 +02:00
|
|
|
* @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",
|
2020-06-21 23:30:25 +02:00
|
|
|
* @OA\Header(header="X-MINIMUM-CLIENT-VERSION", ref="#/components/headers/X-MINIMUM-CLIENT-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
|
|
|
{
|
2020-03-21 06:37:30 +01:00
|
|
|
if ($request->entityIsDeleted($quote)) {
|
2019-12-30 22:59:12 +01:00
|
|
|
return $request->disallowUpdate();
|
2020-03-21 06:37:30 +01:00
|
|
|
}
|
2020-09-06 11:38:10 +02:00
|
|
|
|
2019-12-17 23:40:15 +01:00
|
|
|
$quote = $this->quote_repo->save($request->all(), $quote);
|
2019-05-02 13:07:38 +02:00
|
|
|
|
2021-09-27 00:29:18 +02:00
|
|
|
$quote->service()
|
2023-09-05 03:54:05 +02:00
|
|
|
->triggeredActions($request);
|
2024-02-13 05:25:18 +01:00
|
|
|
|
2021-05-06 23:12:07 +02:00
|
|
|
event(new QuoteWasUpdated($quote, $quote->company, Ninja::eventVars(auth()->user() ? auth()->user()->id : null)));
|
2020-11-03 11:19:32 +01:00
|
|
|
|
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.
|
|
|
|
*
|
2020-10-28 11:10:49 +01:00
|
|
|
* @param DestroyQuoteRequest $request
|
|
|
|
* @param Quote $quote
|
2019-05-02 13:07:38 +02:00
|
|
|
*
|
2020-10-28 11:10:49 +01:00
|
|
|
* @return Response
|
2019-10-07 06:29:16 +02:00
|
|
|
*
|
2019-12-30 22:59:12 +01:00
|
|
|
*
|
2020-10-28 11:10:49 +01:00
|
|
|
* @throws \Exception
|
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",
|
2023-02-10 10:21:10 +01:00
|
|
|
* @OA\Parameter(ref="#/components/parameters/X-API-TOKEN"),
|
2019-10-07 06:29:16 +02:00
|
|
|
* @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",
|
2020-06-21 23:30:25 +02:00
|
|
|
* @OA\Header(header="X-MINIMUM-CLIENT-VERSION", ref="#/components/headers/X-MINIMUM-CLIENT-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
|
|
|
{
|
2021-01-17 05:28:03 +01:00
|
|
|
$this->quote_repo->delete($quote);
|
2019-05-02 13:07:38 +02:00
|
|
|
|
2021-01-17 05:28:03 +01:00
|
|
|
return $this->itemResponse($quote->fresh());
|
2019-05-02 13:07:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-09-06 11:38:10 +02:00
|
|
|
* Perform bulk actions on the list view.
|
2019-12-30 22:59:12 +01:00
|
|
|
*
|
2023-07-26 04:59:36 +02:00
|
|
|
* @return \Illuminate\Support\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="",
|
2023-02-10 10:21:10 +01:00
|
|
|
* @OA\Parameter(ref="#/components/parameters/X-API-TOKEN"),
|
2019-10-07 06:29:16 +02:00
|
|
|
* @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",
|
2020-06-21 23:30:25 +02:00
|
|
|
* @OA\Header(header="X-MINIMUM-CLIENT-VERSION", ref="#/components/headers/X-MINIMUM-CLIENT-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
|
|
|
*/
|
2022-01-27 02:36:42 +01:00
|
|
|
public function bulk(BulkActionQuoteRequest $request)
|
2019-05-02 13:07:38 +02:00
|
|
|
{
|
2023-08-04 09:12:21 +02:00
|
|
|
/** @var \App\Models\User $user */
|
|
|
|
$user = auth()->user();
|
|
|
|
|
2023-11-18 08:45:26 +01:00
|
|
|
$action = $request->input('action');
|
2020-03-03 10:44:26 +01:00
|
|
|
|
2023-11-18 08:45:26 +01:00
|
|
|
$ids = $request->input('ids');
|
2019-05-02 13:07:38 +02:00
|
|
|
|
2023-08-04 10:13:26 +02:00
|
|
|
if (Ninja::isHosted() && (stripos($action, 'email') !== false) && !$user->account->account_sms_verified) {
|
2022-07-27 03:21:12 +02:00
|
|
|
return response(['message' => 'Please verify your account to send emails.'], 400);
|
2023-02-16 02:36:09 +01:00
|
|
|
}
|
2022-07-27 03:21:12 +02:00
|
|
|
|
2023-09-05 02:49:16 +02:00
|
|
|
$quotes = Quote::query()->with('invitations')->withTrashed()->whereIn('id', $this->transformKeys($ids))->company()->get();
|
2020-03-03 10:44:26 +01:00
|
|
|
|
2020-09-06 11:38:10 +02:00
|
|
|
if (! $quotes) {
|
2021-01-25 00:04:50 +01:00
|
|
|
return response()->json(['message' => ctrans('texts.quote_not_found')]);
|
2020-03-03 10:44:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2023-09-05 02:49:16 +02:00
|
|
|
* Download Quote/s
|
2020-03-03 10:44:26 +01:00
|
|
|
*/
|
2022-03-02 03:26:30 +01:00
|
|
|
if ($action == 'bulk_download' && $quotes->count() >= 1) {
|
2023-10-26 04:57:44 +02:00
|
|
|
$quotes->each(function ($quote) use ($user) {
|
2023-08-04 09:12:21 +02:00
|
|
|
if ($user->cannot('view', $quote)) {
|
2024-01-14 05:05:00 +01:00
|
|
|
return response()->json(['message' => ctrans('texts.access_denied')]);
|
2020-03-03 10:44:26 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2023-09-05 02:49:16 +02:00
|
|
|
ZipQuotes::dispatch($quotes->pluck('id')->toArray(), $quotes->first()->company, auth()->user());
|
2020-03-03 10:44:26 +01:00
|
|
|
|
2021-01-25 00:04:50 +01:00
|
|
|
return response()->json(['message' => ctrans('texts.sent_message')], 200);
|
2020-03-03 10:44:26 +01:00
|
|
|
}
|
2019-05-02 13:07:38 +02:00
|
|
|
|
2021-03-24 10:14:30 +01:00
|
|
|
if ($action == 'convert' || $action == 'convert_to_invoice') {
|
2020-05-28 13:22:25 +02:00
|
|
|
$this->entity_type = Quote::class;
|
|
|
|
$this->entity_transformer = QuoteTransformer::class;
|
2020-05-20 09:45:03 +02:00
|
|
|
|
2023-08-04 09:12:21 +02:00
|
|
|
$quotes->each(function ($quote, $key) use ($user) {
|
|
|
|
if ($user->can('edit', $quote) && $quote->service()->isConvertable()) {
|
2020-05-28 02:04:48 +02:00
|
|
|
$quote->service()->convertToInvoice();
|
2020-05-20 09:45:03 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2023-09-09 14:20:12 +02:00
|
|
|
return $this->listResponse(Quote::query()->withTrashed()->whereIn('id', $this->transformKeys($ids))->company());
|
2020-05-20 09:45:03 +02:00
|
|
|
}
|
|
|
|
|
2023-08-04 09:12:21 +02:00
|
|
|
if ($action == 'bulk_print' && $user->can('view', $quotes->first())) {
|
2023-02-16 02:36:09 +01:00
|
|
|
$paths = $quotes->map(function ($quote) {
|
2023-10-26 03:25:56 +02:00
|
|
|
return (new \App\Jobs\Entity\CreateRawPdf($quote->invitations->first()))->handle();
|
2022-10-30 21:50:29 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
$merge = (new PdfMerge($paths->toArray()))->run();
|
|
|
|
|
2023-02-16 02:36:09 +01:00
|
|
|
return response()->streamDownload(function () use ($merge) {
|
|
|
|
echo($merge);
|
|
|
|
}, 'print.pdf', ['Content-Type' => 'application/pdf']);
|
2022-10-30 21:50:29 +01:00
|
|
|
}
|
|
|
|
|
2022-08-15 05:49:47 +02:00
|
|
|
|
2023-02-16 02:36:09 +01:00
|
|
|
if ($action == 'convert_to_project') {
|
2023-08-04 09:12:21 +02:00
|
|
|
$quotes->each(function ($quote, $key) use ($user) {
|
|
|
|
if ($user->can('edit', $quote)) {
|
2023-09-11 23:29:00 +02:00
|
|
|
|
|
|
|
$quote->service()->convertToProject();
|
|
|
|
|
2022-08-15 05:49:47 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2023-09-09 14:20:12 +02:00
|
|
|
return $this->listResponse(Quote::query()->withTrashed()->whereIn('id', $this->transformKeys($ids))->company());
|
2022-08-15 05:49:47 +02:00
|
|
|
}
|
|
|
|
|
2023-11-18 02:46:03 +01:00
|
|
|
|
|
|
|
if($action == 'template' && $user->can('view', $quotes->first())) {
|
|
|
|
|
|
|
|
$hash_or_response = $request->boolean('send_email') ? 'email sent' : \Illuminate\Support\Str::uuid();
|
|
|
|
|
|
|
|
TemplateAction::dispatch(
|
|
|
|
$ids,
|
|
|
|
$request->template_id,
|
|
|
|
Quote::class,
|
|
|
|
$user->id,
|
|
|
|
$user->company(),
|
|
|
|
$user->company()->db,
|
|
|
|
$hash_or_response,
|
|
|
|
$request->boolean('send_email')
|
|
|
|
);
|
|
|
|
|
|
|
|
return response()->json(['message' => $hash_or_response], 200);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-03-03 10:44:26 +01:00
|
|
|
/*
|
|
|
|
* Send the other actions to the switch
|
|
|
|
*/
|
2023-08-04 09:12:21 +02:00
|
|
|
$quotes->each(function ($quote, $key) use ($action, $user) {
|
|
|
|
if ($user->can('edit', $quote)) {
|
2020-03-03 10:44:26 +01:00
|
|
|
$this->performAction($quote, $action, true);
|
2019-12-30 22:59:12 +01:00
|
|
|
}
|
2019-05-02 13:07:38 +02:00
|
|
|
});
|
|
|
|
|
2020-03-03 10:44:26 +01:00
|
|
|
/* Need to understand which permission are required for the given bulk action ie. view / edit */
|
|
|
|
|
|
|
|
return $this->listResponse(Quote::withTrashed()->whereIn('id', $this->transformKeys($ids))->company());
|
2019-05-02 13:07:38 +02:00
|
|
|
}
|
|
|
|
|
2019-10-07 06:29:16 +02:00
|
|
|
/**
|
2020-09-06 11:38:10 +02:00
|
|
|
* Quote Actions.
|
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}/{action}",
|
|
|
|
* operationId="actionQuote",
|
|
|
|
* tags={"quotes"},
|
|
|
|
* summary="Performs a custom action on an Quote",
|
|
|
|
* description="Performs a custom action on an Quote.
|
2023-08-04 09:12:21 +02:00
|
|
|
*
|
|
|
|
* The current range of actions are as follows
|
|
|
|
* - clone_to_quote
|
|
|
|
* - history
|
|
|
|
* - delivery_note
|
|
|
|
* - mark_paid
|
|
|
|
* - download
|
|
|
|
* - archive
|
|
|
|
* - delete
|
|
|
|
* - convert
|
|
|
|
* - convert_to_invoice
|
|
|
|
* - email",
|
2023-02-10 10:21:10 +01:00
|
|
|
* @OA\Parameter(ref="#/components/parameters/X-API-TOKEN"),
|
2019-10-07 06:29:16 +02:00
|
|
|
* @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",
|
2020-06-21 23:30:25 +02:00
|
|
|
* @OA\Header(header="X-MINIMUM-CLIENT-VERSION", ref="#/components/headers/X-MINIMUM-CLIENT-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"),
|
|
|
|
* ),
|
|
|
|
* )
|
2020-10-28 11:10:49 +01:00
|
|
|
* @param ActionQuoteRequest $request
|
|
|
|
* @param Quote $quote
|
|
|
|
* @param $action
|
|
|
|
* @return \Illuminate\Http\JsonResponse|Response|mixed|\Symfony\Component\HttpFoundation\StreamedResponse
|
2019-12-30 22:59:12 +01:00
|
|
|
*/
|
2020-03-21 06:37:30 +01:00
|
|
|
public function action(ActionQuoteRequest $request, Quote $quote, $action)
|
|
|
|
{
|
2020-03-03 10:44:26 +01:00
|
|
|
return $this->performAction($quote, $action);
|
|
|
|
}
|
|
|
|
|
|
|
|
private function performAction(Quote $quote, $action, $bulk = false)
|
2019-05-02 13:07:38 +02:00
|
|
|
{
|
|
|
|
switch ($action) {
|
2023-09-07 06:20:32 +02:00
|
|
|
case 'convert_to_project':
|
|
|
|
|
|
|
|
$this->entity_type = Project::class;
|
|
|
|
$this->entity_transformer = ProjectTransformer::class;
|
|
|
|
|
|
|
|
return $this->itemResponse($quote->service()->convertToProject());
|
|
|
|
|
2023-10-26 04:57:44 +02:00
|
|
|
case 'convert':
|
2021-03-26 09:07:43 +01:00
|
|
|
case 'convert_to_invoice':
|
|
|
|
|
|
|
|
$this->entity_type = Invoice::class;
|
|
|
|
$this->entity_transformer = InvoiceTransformer::class;
|
2022-06-21 11:57:17 +02:00
|
|
|
|
2021-03-26 09:07:43 +01:00
|
|
|
return $this->itemResponse($quote->service()->convertToInvoice());
|
|
|
|
|
2019-05-02 13:07:38 +02:00
|
|
|
case 'clone_to_invoice':
|
2020-02-19 21:44:12 +01:00
|
|
|
|
2020-05-09 00:35:49 +02:00
|
|
|
$this->entity_type = Invoice::class;
|
|
|
|
$this->entity_transformer = InvoiceTransformer::class;
|
2020-02-19 21:44:12 +01:00
|
|
|
|
|
|
|
$invoice = CloneQuoteToInvoiceFactory::create($quote, auth()->user()->id);
|
2020-09-06 11:38:10 +02:00
|
|
|
|
2020-02-19 21:44:12 +01:00
|
|
|
return $this->itemResponse($invoice);
|
2023-09-07 06:20:32 +02:00
|
|
|
|
2019-05-02 13:07:38 +02:00
|
|
|
case 'clone_to_quote':
|
2020-02-19 21:44:12 +01:00
|
|
|
$quote = CloneQuoteFactory::create($quote, auth()->user()->id);
|
2020-09-06 11:38:10 +02:00
|
|
|
|
2020-02-19 21:44:12 +01:00
|
|
|
return $this->itemResponse($quote);
|
2023-09-07 06:20:32 +02:00
|
|
|
|
2020-03-06 12:10:59 +01:00
|
|
|
case 'approve':
|
2022-06-21 11:57:17 +02:00
|
|
|
if (! in_array($quote->status_id, [Quote::STATUS_SENT, Quote::STATUS_DRAFT])) {
|
2021-01-25 00:04:50 +01:00
|
|
|
return response()->json(['message' => ctrans('texts.quote_unapprovable')], 400);
|
2020-03-21 06:37:30 +01:00
|
|
|
}
|
2020-09-06 11:38:10 +02:00
|
|
|
|
2022-03-17 03:41:46 +01:00
|
|
|
return $this->itemResponse($quote->service()->approveWithNoCoversion()->save());
|
2023-09-07 06:20:32 +02:00
|
|
|
|
2019-05-02 13:07:38 +02:00
|
|
|
case 'history':
|
2020-09-06 11:38:10 +02:00
|
|
|
// code...
|
2019-05-02 13:07:38 +02:00
|
|
|
break;
|
2019-11-25 10:38:55 +01:00
|
|
|
case 'download':
|
2021-05-15 04:19:36 +02:00
|
|
|
|
2023-11-16 01:47:57 +01:00
|
|
|
return response()->streamDownload(function () use ($quote) {
|
|
|
|
echo $quote->service()->getQuotePdf();
|
|
|
|
}, $quote->getFileName(), ['Content-Type' => 'application/pdf']);
|
2021-07-07 13:39:49 +02:00
|
|
|
|
2020-11-03 11:19:32 +01:00
|
|
|
case 'restore':
|
|
|
|
$this->quote_repo->restore($quote);
|
|
|
|
|
2022-06-21 11:57:17 +02:00
|
|
|
if (! $bulk) {
|
2022-08-18 06:08:50 +02:00
|
|
|
return $this->itemResponse($quote);
|
2020-11-25 15:19:52 +01:00
|
|
|
}
|
2020-11-03 11:19:32 +01:00
|
|
|
break;
|
2023-09-07 06:20:32 +02:00
|
|
|
|
2019-05-02 13:07:38 +02:00
|
|
|
case 'archive':
|
2020-08-23 03:08:18 +02:00
|
|
|
$this->quote_repo->archive($quote);
|
2020-09-06 11:38:10 +02:00
|
|
|
|
2022-06-21 11:57:17 +02:00
|
|
|
if (! $bulk) {
|
2022-08-18 06:08:50 +02:00
|
|
|
return $this->itemResponse($quote);
|
2020-11-25 15:19:52 +01:00
|
|
|
}
|
2020-11-03 11:19:32 +01:00
|
|
|
|
2019-05-02 13:07:38 +02:00
|
|
|
break;
|
|
|
|
case 'delete':
|
2019-11-25 10:38:55 +01:00
|
|
|
$this->quote_repo->delete($quote);
|
2020-09-06 11:38:10 +02:00
|
|
|
|
2022-06-21 11:57:17 +02:00
|
|
|
if (! $bulk) {
|
2022-08-18 06:08:50 +02:00
|
|
|
return $this->itemResponse($quote);
|
2020-11-25 15:19:52 +01:00
|
|
|
}
|
2020-11-03 11:19:32 +01:00
|
|
|
|
2019-05-02 13:07:38 +02:00
|
|
|
break;
|
|
|
|
case 'email':
|
2022-07-08 01:00:36 +02:00
|
|
|
case 'send_email':
|
2023-09-07 06:20:32 +02:00
|
|
|
|
2022-07-08 01:00:36 +02:00
|
|
|
$quote->service()->sendEmail();
|
|
|
|
|
2024-01-14 05:05:00 +01:00
|
|
|
return response()->json(['message' => ctrans('texts.sent_message')], 200);
|
2022-07-08 01:00:36 +02:00
|
|
|
|
2020-03-03 10:44:26 +01:00
|
|
|
case 'mark_sent':
|
|
|
|
$quote->service()->markSent()->save();
|
|
|
|
|
2020-09-06 11:38:10 +02:00
|
|
|
if (! $bulk) {
|
2020-03-03 10:44:26 +01:00
|
|
|
return $this->itemResponse($quote);
|
|
|
|
}
|
2020-11-03 11:19:32 +01:00
|
|
|
break;
|
2019-05-02 13:07:38 +02:00
|
|
|
default:
|
2022-06-21 11:57:17 +02:00
|
|
|
return response()->json(['message' => ctrans('texts.action_unavailable', ['action' => $action])], 400);
|
2019-05-02 13:07:38 +02:00
|
|
|
break;
|
|
|
|
}
|
2019-04-02 08:36:49 +02:00
|
|
|
}
|
2020-03-03 10:44:26 +01:00
|
|
|
|
2023-02-01 09:56:02 +01:00
|
|
|
/**
|
|
|
|
* @OA\Get(
|
|
|
|
* path="/api/v1/quote/{invitation_key}/download",
|
|
|
|
* operationId="downloadQuote",
|
|
|
|
* tags={"quotes"},
|
|
|
|
* summary="Download a specific quote by invitation key",
|
|
|
|
* description="Downloads a specific quote",
|
2023-02-10 10:21:10 +01:00
|
|
|
* @OA\Parameter(ref="#/components/parameters/X-API-TOKEN"),
|
2023-02-01 09:56:02 +01:00
|
|
|
* @OA\Parameter(ref="#/components/parameters/X-Requested-With"),
|
|
|
|
* @OA\Parameter(ref="#/components/parameters/include"),
|
|
|
|
* @OA\Parameter(
|
|
|
|
* name="invitation_key",
|
|
|
|
* in="path",
|
|
|
|
* description="The Quote Invitation Key",
|
|
|
|
* example="D2J234DFA",
|
|
|
|
* required=true,
|
|
|
|
* @OA\Schema(
|
|
|
|
* type="string",
|
|
|
|
* format="string",
|
|
|
|
* ),
|
|
|
|
* ),
|
|
|
|
* @OA\Response(
|
|
|
|
* response=200,
|
|
|
|
* description="Returns the quote pdf",
|
|
|
|
* @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\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"),
|
|
|
|
* ),
|
|
|
|
* )
|
|
|
|
* @param $invitation_key
|
|
|
|
* @return \Symfony\Component\HttpFoundation\BinaryFileResponse
|
|
|
|
*/
|
|
|
|
|
2020-03-21 06:37:30 +01:00
|
|
|
public function downloadPdf($invitation_key)
|
2020-03-06 14:41:15 +01:00
|
|
|
{
|
|
|
|
$invitation = $this->quote_repo->getInvitationByKey($invitation_key);
|
2024-01-14 05:05:00 +01:00
|
|
|
|
2023-02-01 09:52:38 +01:00
|
|
|
if (! $invitation) {
|
|
|
|
return response()->json(['message' => 'no record found'], 400);
|
|
|
|
}
|
|
|
|
|
2020-09-06 11:38:10 +02:00
|
|
|
$contact = $invitation->contact;
|
|
|
|
$quote = $invitation->quote;
|
2024-01-14 05:05:00 +01:00
|
|
|
|
2023-07-20 08:46:10 +02:00
|
|
|
App::setLocale($invitation->contact->preferredLocale());
|
2020-03-06 14:41:15 +01:00
|
|
|
|
2021-09-20 13:16:28 +02:00
|
|
|
$headers = ['Content-Type' => 'application/pdf'];
|
|
|
|
|
2022-06-21 11:57:17 +02:00
|
|
|
if (request()->input('inline') == 'true') {
|
2021-09-20 13:16:28 +02:00
|
|
|
$headers = array_merge($headers, ['Content-Disposition' => 'inline']);
|
2022-06-21 11:57:17 +02:00
|
|
|
}
|
2021-09-20 13:16:28 +02:00
|
|
|
|
2023-11-26 08:41:42 +01:00
|
|
|
return response()->streamDownload(function () use ($quote, $contact) {
|
2023-11-16 01:47:57 +01:00
|
|
|
echo $quote->service()->getQuotePdf($contact);
|
|
|
|
}, $quote->getFileName(), $headers);
|
2023-10-26 03:25:56 +02:00
|
|
|
|
2020-03-06 14:41:15 +01:00
|
|
|
}
|
2021-02-15 21:58:19 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Update the specified resource in storage.
|
|
|
|
*
|
|
|
|
* @param UploadQuoteRequest $request
|
|
|
|
* @param Quote $quote
|
|
|
|
* @return Response
|
|
|
|
*
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @OA\Put(
|
|
|
|
* path="/api/v1/quotes/{id}/upload",
|
|
|
|
* operationId="uploadQuote",
|
|
|
|
* tags={"quotes"},
|
|
|
|
* summary="Uploads a document to a quote",
|
|
|
|
* description="Handles the uploading of a document to a quote",
|
2023-02-10 10:21:10 +01:00
|
|
|
* @OA\Parameter(ref="#/components/parameters/X-API-TOKEN"),
|
2021-02-15 21:58:19 +01:00
|
|
|
* @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",
|
|
|
|
* @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/Quote"),
|
|
|
|
* ),
|
|
|
|
* @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(UploadQuoteRequest $request, Quote $quote)
|
|
|
|
{
|
2022-06-21 11:57:17 +02:00
|
|
|
if (! $this->checkFeature(Account::FEATURE_DOCUMENTS)) {
|
2021-03-07 22:32:38 +01:00
|
|
|
return $this->featureFailure();
|
2022-06-21 11:57:17 +02:00
|
|
|
}
|
2021-03-07 22:32:38 +01:00
|
|
|
|
2022-06-21 11:57:17 +02:00
|
|
|
if ($request->has('documents')) {
|
2023-08-20 06:05:26 +02:00
|
|
|
$this->saveDocuments($request->file('documents'), $quote, $request->input('is_public', true));
|
2022-06-21 11:57:17 +02:00
|
|
|
}
|
2021-02-15 21:58:19 +01:00
|
|
|
|
|
|
|
return $this->itemResponse($quote->fresh());
|
2022-06-21 11:57:17 +02:00
|
|
|
}
|
2019-12-30 22:59:12 +01:00
|
|
|
}
|