2018-10-17 14:26:27 +02:00
|
|
|
<?php
|
2020-04-09 14:04:26 +02:00
|
|
|
|
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
|
|
|
|
*
|
2021-01-03 22:54:54 +01:00
|
|
|
* @copyright Copyright (c) 2021. Invoice Ninja LLC (https://invoiceninja.com)
|
2019-05-11 05:32:07 +02:00
|
|
|
*
|
|
|
|
* @license https://opensource.org/licenses/AAL
|
|
|
|
*/
|
2018-10-17 14:26:27 +02:00
|
|
|
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
2019-05-15 11:20:52 +02:00
|
|
|
use App\Events\Invoice\InvoiceWasCreated;
|
|
|
|
use App\Events\Invoice\InvoiceWasUpdated;
|
2019-04-23 06:16:41 +02:00
|
|
|
use App\Factory\CloneInvoiceFactory;
|
2019-04-23 15:17:49 +02:00
|
|
|
use App\Factory\CloneInvoiceToQuoteFactory;
|
2019-04-15 02:10:54 +02:00
|
|
|
use App\Factory\InvoiceFactory;
|
2019-04-17 02:58:23 +02:00
|
|
|
use App\Filters\InvoiceFilters;
|
2019-04-23 06:16:41 +02:00
|
|
|
use App\Http\Requests\Invoice\ActionInvoiceRequest;
|
2019-04-16 05:28:05 +02:00
|
|
|
use App\Http\Requests\Invoice\CreateInvoiceRequest;
|
2019-04-17 08:20:32 +02:00
|
|
|
use App\Http\Requests\Invoice\DestroyInvoiceRequest;
|
2019-04-16 05:28:05 +02:00
|
|
|
use App\Http\Requests\Invoice\EditInvoiceRequest;
|
|
|
|
use App\Http\Requests\Invoice\ShowInvoiceRequest;
|
|
|
|
use App\Http\Requests\Invoice\StoreInvoiceRequest;
|
|
|
|
use App\Http\Requests\Invoice\UpdateInvoiceRequest;
|
2021-02-15 12:34:05 +01:00
|
|
|
use App\Http\Requests\Invoice\UploadInvoiceRequest;
|
2020-10-28 07:58:15 +01:00
|
|
|
use App\Jobs\Entity\EmailEntity;
|
2019-05-09 07:29:31 +02:00
|
|
|
use App\Jobs\Invoice\StoreInvoice;
|
2020-02-15 10:06:30 +01:00
|
|
|
use App\Jobs\Invoice\ZipInvoices;
|
2020-09-30 11:10:02 +02:00
|
|
|
use App\Jobs\Util\UnlinkFile;
|
2021-03-07 11:14:53 +01:00
|
|
|
use App\Models\Account;
|
2020-02-26 11:06:08 +01:00
|
|
|
use App\Models\Client;
|
2019-04-02 07:16:39 +02:00
|
|
|
use App\Models\Invoice;
|
2020-11-11 01:13:39 +01:00
|
|
|
use App\Models\Quote;
|
2019-04-17 02:58:23 +02:00
|
|
|
use App\Repositories\InvoiceRepository;
|
2019-04-16 05:28:05 +02:00
|
|
|
use App\Transformers\InvoiceTransformer;
|
2020-11-11 01:13:39 +01:00
|
|
|
use App\Transformers\QuoteTransformer;
|
2020-07-08 14:02:16 +02:00
|
|
|
use App\Utils\Ninja;
|
2020-04-16 10:41:25 +02:00
|
|
|
use App\Utils\TempFile;
|
2019-04-02 08:36:49 +02:00
|
|
|
use App\Utils\Traits\MakesHash;
|
2021-02-15 12:34:05 +01:00
|
|
|
use App\Utils\Traits\SavesDocuments;
|
2018-10-17 14:26:27 +02:00
|
|
|
use Illuminate\Http\Request;
|
2020-10-28 11:10:49 +01:00
|
|
|
use Illuminate\Http\Response;
|
2020-02-12 01:41:17 +01:00
|
|
|
use Illuminate\Support\Facades\File;
|
|
|
|
use Illuminate\Support\Facades\Storage;
|
2018-10-17 14:26:27 +02:00
|
|
|
|
2019-04-04 11:28:53 +02:00
|
|
|
/**
|
2020-09-06 11:38:10 +02:00
|
|
|
* Class InvoiceController.
|
2019-04-04 11:28:53 +02:00
|
|
|
*/
|
2020-03-21 06:37:30 +01:00
|
|
|
class InvoiceController extends BaseController
|
|
|
|
{
|
|
|
|
use MakesHash;
|
2021-02-15 12:34:05 +01:00
|
|
|
use SavesDocuments;
|
|
|
|
|
2020-04-09 14:04:26 +02:00
|
|
|
protected $entity_type = Invoice::class;
|
2020-03-21 06:37:30 +01:00
|
|
|
|
2020-04-09 14:04:26 +02:00
|
|
|
protected $entity_transformer = InvoiceTransformer::class;
|
2020-03-21 06:37:30 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @var InvoiceRepository
|
|
|
|
*/
|
|
|
|
protected $invoice_repo;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* InvoiceController constructor.
|
|
|
|
*
|
2020-10-28 11:10:49 +01:00
|
|
|
* @param InvoiceRepository $invoice_repo The invoice repo
|
2020-03-21 06:37:30 +01:00
|
|
|
*/
|
|
|
|
public function __construct(InvoiceRepository $invoice_repo)
|
|
|
|
{
|
|
|
|
parent::__construct();
|
|
|
|
|
|
|
|
$this->invoice_repo = $invoice_repo;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-09-06 11:38:10 +02:00
|
|
|
* Show the list of Invoices.
|
2020-03-21 06:37:30 +01:00
|
|
|
*
|
2020-10-28 11:10:49 +01:00
|
|
|
* @param InvoiceFilters $filters The filters
|
2020-03-21 06:37:30 +01:00
|
|
|
*
|
2020-10-28 11:10:49 +01:00
|
|
|
* @return Response
|
2020-03-21 06:37:30 +01:00
|
|
|
*
|
|
|
|
* @OA\Get(
|
|
|
|
* path="/api/v1/invoices",
|
|
|
|
* operationId="getInvoices",
|
|
|
|
* tags={"invoices"},
|
|
|
|
* summary="Gets a list of invoices",
|
|
|
|
* description="Lists invoices, search and filters allow fine grained lists to be generated.
|
|
|
|
*
|
|
|
|
* Query parameters can be added to performed more fine grained filtering of the invoices, these are handled by the InvoiceFilters 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 invoices",
|
2020-06-21 23:30:25 +02:00
|
|
|
* @OA\Header(header="X-MINIMUM-CLIENT-VERSION", ref="#/components/headers/X-MINIMUM-CLIENT-VERSION"),
|
2020-03-21 06:37:30 +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/Invoice"),
|
|
|
|
* ),
|
|
|
|
* @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 index(InvoiceFilters $filters)
|
|
|
|
{
|
|
|
|
$invoices = Invoice::filter($filters);
|
|
|
|
|
|
|
|
return $this->listResponse($invoices);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Show the form for creating a new resource.
|
|
|
|
*
|
2020-10-28 11:10:49 +01:00
|
|
|
* @param CreateInvoiceRequest $request The request
|
2020-03-21 06:37:30 +01:00
|
|
|
*
|
2020-10-28 11:10:49 +01:00
|
|
|
* @return Response
|
2020-03-21 06:37:30 +01:00
|
|
|
*
|
|
|
|
*
|
|
|
|
* @OA\Get(
|
|
|
|
* path="/api/v1/invoices/create",
|
|
|
|
* operationId="getInvoicesCreate",
|
|
|
|
* tags={"invoices"},
|
|
|
|
* summary="Gets a new blank invoice 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 invoice object",
|
2020-06-21 23:30:25 +02:00
|
|
|
* @OA\Header(header="X-MINIMUM-CLIENT-VERSION", ref="#/components/headers/X-MINIMUM-CLIENT-VERSION"),
|
2020-03-21 06:37:30 +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/Invoice"),
|
|
|
|
* ),
|
|
|
|
* @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(CreateInvoiceRequest $request)
|
|
|
|
{
|
|
|
|
$invoice = InvoiceFactory::create(auth()->user()->company()->id, auth()->user()->id);
|
|
|
|
|
|
|
|
return $this->itemResponse($invoice);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Store a newly created resource in storage.
|
|
|
|
*
|
2020-10-28 11:10:49 +01:00
|
|
|
* @param StoreInvoiceRequest $request The request
|
2020-03-21 06:37:30 +01:00
|
|
|
*
|
2020-10-28 11:10:49 +01:00
|
|
|
* @return Response
|
2020-03-21 06:37:30 +01:00
|
|
|
*
|
|
|
|
*
|
|
|
|
* @OA\Post(
|
|
|
|
* path="/api/v1/invoices",
|
|
|
|
* operationId="storeInvoice",
|
|
|
|
* tags={"invoices"},
|
|
|
|
* summary="Adds a invoice",
|
|
|
|
* description="Adds an invoice 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 invoice object",
|
2020-06-21 23:30:25 +02:00
|
|
|
* @OA\Header(header="X-MINIMUM-CLIENT-VERSION", ref="#/components/headers/X-MINIMUM-CLIENT-VERSION"),
|
2020-03-21 06:37:30 +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/Invoice"),
|
|
|
|
* ),
|
|
|
|
* @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(StoreInvoiceRequest $request)
|
|
|
|
{
|
2021-02-11 22:00:42 +01:00
|
|
|
|
2020-03-21 06:37:30 +01:00
|
|
|
$client = Client::find($request->input('client_id'));
|
|
|
|
|
|
|
|
$invoice = $this->invoice_repo->save($request->all(), InvoiceFactory::create(auth()->user()->company()->id, auth()->user()->id));
|
|
|
|
|
2020-07-08 14:02:16 +02:00
|
|
|
event(new InvoiceWasCreated($invoice, $invoice->company, Ninja::eventVars()));
|
2020-03-21 06:37:30 +01:00
|
|
|
|
2020-11-04 09:43:20 +01:00
|
|
|
$invoice = $invoice->service()
|
|
|
|
->fillDefaults()
|
|
|
|
->triggeredActions($request)
|
|
|
|
->save();
|
2020-09-06 11:38:10 +02:00
|
|
|
|
2020-03-21 06:37:30 +01:00
|
|
|
return $this->itemResponse($invoice);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Display the specified resource.
|
|
|
|
*
|
2020-10-28 11:10:49 +01:00
|
|
|
* @param ShowInvoiceRequest $request The request
|
|
|
|
* @param Invoice $invoice The invoice
|
2020-03-21 06:37:30 +01:00
|
|
|
*
|
2020-10-28 11:10:49 +01:00
|
|
|
* @return Response
|
2020-03-21 06:37:30 +01:00
|
|
|
*
|
|
|
|
*
|
|
|
|
* @OA\Get(
|
|
|
|
* path="/api/v1/invoices/{id}",
|
|
|
|
* operationId="showInvoice",
|
|
|
|
* tags={"invoices"},
|
|
|
|
* summary="Shows an invoice",
|
|
|
|
* description="Displays an invoice 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 Invoice Hashed ID",
|
|
|
|
* example="D2J234DFA",
|
|
|
|
* required=true,
|
|
|
|
* @OA\Schema(
|
|
|
|
* type="string",
|
|
|
|
* format="string",
|
|
|
|
* ),
|
|
|
|
* ),
|
|
|
|
* @OA\Response(
|
|
|
|
* response=200,
|
|
|
|
* description="Returns the invoice object",
|
2020-06-21 23:30:25 +02:00
|
|
|
* @OA\Header(header="X-MINIMUM-CLIENT-VERSION", ref="#/components/headers/X-MINIMUM-CLIENT-VERSION"),
|
2020-03-21 06:37:30 +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/Invoice"),
|
|
|
|
* ),
|
|
|
|
* @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(ShowInvoiceRequest $request, Invoice $invoice)
|
|
|
|
{
|
|
|
|
return $this->itemResponse($invoice);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Show the form for editing the specified resource.
|
|
|
|
*
|
2020-10-28 11:10:49 +01:00
|
|
|
* @param EditInvoiceRequest $request The request
|
|
|
|
* @param Invoice $invoice The invoice
|
2020-03-21 06:37:30 +01:00
|
|
|
*
|
2020-10-28 11:10:49 +01:00
|
|
|
* @return Response
|
2020-03-21 06:37:30 +01:00
|
|
|
*
|
|
|
|
* @OA\Get(
|
|
|
|
* path="/api/v1/invoices/{id}/edit",
|
|
|
|
* operationId="editInvoice",
|
|
|
|
* tags={"invoices"},
|
|
|
|
* summary="Shows an invoice for editting",
|
|
|
|
* description="Displays an invoice 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 Invoice Hashed ID",
|
|
|
|
* example="D2J234DFA",
|
|
|
|
* required=true,
|
|
|
|
* @OA\Schema(
|
|
|
|
* type="string",
|
|
|
|
* format="string",
|
|
|
|
* ),
|
|
|
|
* ),
|
|
|
|
* @OA\Response(
|
|
|
|
* response=200,
|
|
|
|
* description="Returns the invoice object",
|
2020-06-21 23:30:25 +02:00
|
|
|
* @OA\Header(header="X-MINIMUM-CLIENT-VERSION", ref="#/components/headers/X-MINIMUM-CLIENT-VERSION"),
|
2020-03-21 06:37:30 +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/Invoice"),
|
|
|
|
* ),
|
|
|
|
* @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(EditInvoiceRequest $request, Invoice $invoice)
|
|
|
|
{
|
|
|
|
return $this->itemResponse($invoice);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Update the specified resource in storage.
|
|
|
|
*
|
2020-10-28 11:10:49 +01:00
|
|
|
* @param UpdateInvoiceRequest $request The request
|
|
|
|
* @param Invoice $invoice The invoice
|
2020-03-21 06:37:30 +01:00
|
|
|
*
|
2020-10-28 11:10:49 +01:00
|
|
|
* @return Response
|
2020-03-21 06:37:30 +01:00
|
|
|
*
|
|
|
|
*
|
|
|
|
* @OA\Put(
|
|
|
|
* path="/api/v1/invoices/{id}",
|
|
|
|
* operationId="updateInvoice",
|
|
|
|
* tags={"invoices"},
|
|
|
|
* summary="Updates an invoice",
|
|
|
|
* description="Handles the updating of an invoice 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 Invoice Hashed ID",
|
|
|
|
* example="D2J234DFA",
|
|
|
|
* required=true,
|
|
|
|
* @OA\Schema(
|
|
|
|
* type="string",
|
|
|
|
* format="string",
|
|
|
|
* ),
|
|
|
|
* ),
|
|
|
|
* @OA\Response(
|
|
|
|
* response=200,
|
|
|
|
* description="Returns the invoice object",
|
2020-06-21 23:30:25 +02:00
|
|
|
* @OA\Header(header="X-MINIMUM-CLIENT-VERSION", ref="#/components/headers/X-MINIMUM-CLIENT-VERSION"),
|
2020-03-21 06:37:30 +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/Invoice"),
|
|
|
|
* ),
|
|
|
|
* @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(UpdateInvoiceRequest $request, Invoice $invoice)
|
|
|
|
{
|
|
|
|
if ($request->entityIsDeleted($invoice)) {
|
|
|
|
return $request->disallowUpdate();
|
|
|
|
}
|
|
|
|
|
2020-09-06 11:38:10 +02:00
|
|
|
if ($invoice->isLocked()) {
|
2021-01-24 23:24:13 +01:00
|
|
|
return response()->json(['message' => ctrans('texts.locked_invoice')]);
|
2020-09-06 11:38:10 +02:00
|
|
|
}
|
2020-07-28 06:29:56 +02:00
|
|
|
|
2020-03-21 06:37:30 +01:00
|
|
|
$invoice = $this->invoice_repo->save($request->all(), $invoice);
|
|
|
|
|
2020-07-08 14:02:16 +02:00
|
|
|
event(new InvoiceWasUpdated($invoice, $invoice->company, Ninja::eventVars()));
|
2020-03-21 06:37:30 +01:00
|
|
|
|
|
|
|
return $this->itemResponse($invoice);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Remove the specified resource from storage.
|
|
|
|
*
|
2020-10-28 11:10:49 +01:00
|
|
|
* @param DestroyInvoiceRequest $request
|
|
|
|
* @param Invoice $invoice
|
2020-03-21 06:37:30 +01:00
|
|
|
*
|
2020-10-28 11:10:49 +01:00
|
|
|
* @return Response
|
2020-03-21 06:37:30 +01:00
|
|
|
*
|
2020-10-28 11:10:49 +01:00
|
|
|
* @throws \Exception
|
2020-03-21 06:37:30 +01:00
|
|
|
* @OA\Delete(
|
|
|
|
* path="/api/v1/invoices/{id}",
|
|
|
|
* operationId="deleteInvoice",
|
|
|
|
* tags={"invoices"},
|
|
|
|
* summary="Deletes a invoice",
|
|
|
|
* description="Handles the deletion of an invoice 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 Invoice 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-03-21 06:37:30 +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(DestroyInvoiceRequest $request, Invoice $invoice)
|
|
|
|
{
|
2021-01-17 05:28:03 +01:00
|
|
|
$this->invoice_repo->delete($invoice);
|
2020-03-21 06:37:30 +01:00
|
|
|
|
2021-01-17 05:28:03 +01:00
|
|
|
return $this->itemResponse($invoice->fresh());
|
2020-03-21 06:37:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-09-06 11:38:10 +02:00
|
|
|
* Perform bulk actions on the list view.
|
2020-03-21 06:37:30 +01:00
|
|
|
*
|
|
|
|
* @return Collection
|
|
|
|
*
|
|
|
|
* @OA\Post(
|
|
|
|
* path="/api/v1/invoices/bulk",
|
|
|
|
* operationId="bulkInvoices",
|
|
|
|
* tags={"invoices"},
|
|
|
|
* summary="Performs bulk actions on an array of invoices",
|
|
|
|
* 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 Bulk Action response",
|
2020-06-21 23:30:25 +02:00
|
|
|
* @OA\Header(header="X-MINIMUM-CLIENT-VERSION", ref="#/components/headers/X-MINIMUM-CLIENT-VERSION"),
|
2020-03-21 06:37:30 +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 bulk()
|
|
|
|
{
|
2021-01-07 23:03:29 +01:00
|
|
|
|
2020-03-21 06:37:30 +01:00
|
|
|
$action = request()->input('action');
|
|
|
|
|
|
|
|
$ids = request()->input('ids');
|
|
|
|
|
|
|
|
$invoices = Invoice::withTrashed()->whereIn('id', $this->transformKeys($ids))->company()->get();
|
|
|
|
|
2020-09-06 11:38:10 +02:00
|
|
|
if (! $invoices) {
|
2020-03-21 06:37:30 +01:00
|
|
|
return response()->json(['message' => 'No Invoices Found']);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Download Invoice/s
|
|
|
|
*/
|
|
|
|
|
|
|
|
if ($action == 'download' && $invoices->count() > 1) {
|
|
|
|
$invoices->each(function ($invoice) {
|
|
|
|
if (auth()->user()->cannot('view', $invoice)) {
|
2021-01-24 23:24:13 +01:00
|
|
|
return response()->json(['message' => ctrans('text.access_denied')]);
|
2020-03-21 06:37:30 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2021-02-18 00:30:31 +01:00
|
|
|
ZipInvoices::dispatch($invoices, $invoices->first()->company, auth()->user());
|
2020-03-21 06:37:30 +01:00
|
|
|
|
2021-01-24 23:24:13 +01:00
|
|
|
return response()->json(['message' => ctrans('texts.sent_message')], 200);
|
2020-03-21 06:37:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Send the other actions to the switch
|
|
|
|
*/
|
|
|
|
$invoices->each(function ($invoice, $key) use ($action) {
|
|
|
|
if (auth()->user()->can('edit', $invoice)) {
|
|
|
|
$this->performAction($invoice, $action, true);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
/* Need to understand which permission are required for the given bulk action ie. view / edit */
|
|
|
|
|
|
|
|
return $this->listResponse(Invoice::withTrashed()->whereIn('id', $this->transformKeys($ids))->company());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @OA\Get(
|
|
|
|
* path="/api/v1/invoices/{id}/{action}",
|
|
|
|
* operationId="actionInvoice",
|
|
|
|
* tags={"invoices"},
|
|
|
|
* summary="Performs a custom action on an invoice",
|
|
|
|
* description="Performs a custom action on an invoice.
|
|
|
|
*
|
2020-10-28 11:10:49 +01:00
|
|
|
* The current range of actions are as follows
|
|
|
|
* - clone_to_invoice
|
|
|
|
* - clone_to_quote
|
|
|
|
* - history
|
|
|
|
* - delivery_note
|
|
|
|
* - mark_paid
|
|
|
|
* - download
|
|
|
|
* - archive
|
|
|
|
* - delete
|
|
|
|
* - email",
|
2020-03-21 06:37:30 +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(
|
|
|
|
* name="id",
|
|
|
|
* in="path",
|
|
|
|
* description="The Invoice 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",
|
|
|
|
* ),
|
|
|
|
* ),
|
|
|
|
* @OA\Response(
|
|
|
|
* response=200,
|
|
|
|
* description="Returns the invoice object",
|
2020-06-21 23:30:25 +02:00
|
|
|
* @OA\Header(header="X-MINIMUM-CLIENT-VERSION", ref="#/components/headers/X-MINIMUM-CLIENT-VERSION"),
|
2020-03-21 06:37:30 +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/Invoice"),
|
|
|
|
* ),
|
|
|
|
* @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 ActionInvoiceRequest $request
|
|
|
|
* @param Invoice $invoice
|
|
|
|
* @param $action
|
|
|
|
* @return \App\Http\Controllers\Response|\Illuminate\Http\JsonResponse|Response|mixed|\Symfony\Component\HttpFoundation\StreamedResponse
|
2020-03-21 06:37:30 +01:00
|
|
|
*/
|
|
|
|
public function action(ActionInvoiceRequest $request, Invoice $invoice, $action)
|
|
|
|
{
|
|
|
|
return $this->performAction($invoice, $action);
|
|
|
|
}
|
|
|
|
|
|
|
|
private function performAction(Invoice $invoice, $action, $bulk = false)
|
|
|
|
{
|
|
|
|
/*If we are using bulk actions, we don't want to return anything */
|
|
|
|
switch ($action) {
|
|
|
|
case 'clone_to_invoice':
|
|
|
|
$invoice = CloneInvoiceFactory::create($invoice, auth()->user()->id);
|
2020-09-06 11:38:10 +02:00
|
|
|
|
2020-03-21 06:37:30 +01:00
|
|
|
return $this->itemResponse($invoice);
|
|
|
|
break;
|
|
|
|
case 'clone_to_quote':
|
|
|
|
$quote = CloneInvoiceToQuoteFactory::create($invoice, auth()->user()->id);
|
2020-11-11 01:13:39 +01:00
|
|
|
|
|
|
|
$this->entity_transformer = QuoteTransformer::class;
|
|
|
|
$this->entity_type = Quote::class;
|
|
|
|
|
|
|
|
return $this->itemResponse($quote);
|
|
|
|
|
2020-03-21 06:37:30 +01:00
|
|
|
break;
|
|
|
|
case 'history':
|
2020-09-06 11:38:10 +02:00
|
|
|
// code...
|
2020-03-21 06:37:30 +01:00
|
|
|
break;
|
|
|
|
case 'delivery_note':
|
2020-09-06 11:38:10 +02:00
|
|
|
// code...
|
2020-03-21 06:37:30 +01:00
|
|
|
break;
|
|
|
|
case 'mark_paid':
|
|
|
|
if ($invoice->balance < 0 || $invoice->status_id == Invoice::STATUS_PAID || $invoice->is_deleted === true) {
|
2021-01-24 23:24:13 +01:00
|
|
|
return $this->errorResponse(['message' => ctrans('texts.invoice_cannot_be_marked_paid')], 400);
|
2020-03-21 06:37:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
$invoice = $invoice->service()->markPaid();
|
|
|
|
|
2020-09-06 11:38:10 +02:00
|
|
|
if (! $bulk) {
|
2020-03-21 06:37:30 +01:00
|
|
|
return $this->itemResponse($invoice);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'mark_sent':
|
|
|
|
$invoice->service()->markSent()->save();
|
|
|
|
|
2020-09-06 11:38:10 +02:00
|
|
|
if (! $bulk) {
|
2020-03-21 06:37:30 +01:00
|
|
|
return $this->itemResponse($invoice);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'download':
|
2020-09-06 11:38:10 +02:00
|
|
|
return response()->streamDownload(function () use ($invoice) {
|
2020-06-24 10:59:56 +02:00
|
|
|
echo file_get_contents($invoice->pdf_file_path());
|
|
|
|
}, basename($invoice->pdf_file_path()));
|
|
|
|
//return response()->download(TempFile::path($invoice->pdf_file_path()), basename($invoice->pdf_file_path()));
|
2020-03-21 06:37:30 +01:00
|
|
|
break;
|
2020-06-08 23:43:46 +02:00
|
|
|
case 'restore':
|
|
|
|
$this->invoice_repo->restore($invoice);
|
|
|
|
|
2020-09-06 11:38:10 +02:00
|
|
|
if (! $bulk) {
|
2020-06-08 23:43:46 +02:00
|
|
|
return $this->listResponse($invoice);
|
|
|
|
}
|
|
|
|
break;
|
2020-03-21 06:37:30 +01:00
|
|
|
case 'archive':
|
|
|
|
$this->invoice_repo->archive($invoice);
|
|
|
|
|
2020-09-06 11:38:10 +02:00
|
|
|
if (! $bulk) {
|
2020-03-21 06:37:30 +01:00
|
|
|
return $this->listResponse($invoice);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'delete':
|
2021-01-24 23:24:13 +01:00
|
|
|
|
2020-03-21 06:37:30 +01:00
|
|
|
$this->invoice_repo->delete($invoice);
|
|
|
|
|
2020-09-06 11:38:10 +02:00
|
|
|
if (! $bulk) {
|
2020-03-21 06:37:30 +01:00
|
|
|
return $this->listResponse($invoice);
|
|
|
|
}
|
|
|
|
break;
|
2020-04-06 14:32:27 +02:00
|
|
|
case 'cancel':
|
2020-04-08 15:31:22 +02:00
|
|
|
$invoice = $invoice->service()->handleCancellation()->save();
|
|
|
|
|
2020-09-06 11:38:10 +02:00
|
|
|
if (! $bulk) {
|
2020-04-09 14:04:26 +02:00
|
|
|
$this->itemResponse($invoice);
|
|
|
|
}
|
2020-04-06 14:32:27 +02:00
|
|
|
break;
|
|
|
|
case 'reverse':
|
2020-04-08 12:48:31 +02:00
|
|
|
$invoice = $invoice->service()->handleReversal()->save();
|
|
|
|
|
2020-09-06 11:38:10 +02:00
|
|
|
if (! $bulk) {
|
2020-04-09 14:04:26 +02:00
|
|
|
$this->itemResponse($invoice);
|
|
|
|
}
|
2020-04-06 14:32:27 +02:00
|
|
|
break;
|
2020-03-21 06:37:30 +01:00
|
|
|
case 'email':
|
2020-09-21 08:27:02 +02:00
|
|
|
//check query parameter for email_type and set the template else use calculateTemplate
|
2021-01-20 02:59:39 +01:00
|
|
|
|
2020-09-06 11:38:10 +02:00
|
|
|
if (request()->has('email_type') && property_exists($invoice->company->settings, request()->input('email_type'))) {
|
2020-08-05 14:18:29 +02:00
|
|
|
$this->reminder_template = $invoice->client->getSetting(request()->input('email_type'));
|
2020-09-06 11:38:10 +02:00
|
|
|
} else {
|
2020-10-28 00:02:32 +01:00
|
|
|
$this->reminder_template = $invoice->calculateTemplate('invoice');
|
2020-09-06 11:38:10 +02:00
|
|
|
}
|
2020-03-21 06:37:30 +01:00
|
|
|
|
2020-09-02 03:11:01 +02:00
|
|
|
//touch reminder1,2,3_sent + last_sent here if the email is a reminder.
|
|
|
|
$invoice->service()->touchReminder($this->reminder_template)->save();
|
2020-04-19 12:29:58 +02:00
|
|
|
|
2020-09-06 11:38:10 +02:00
|
|
|
$invoice->invitations->load('contact.client.country', 'invoice.client.country', 'invoice.company')->each(function ($invitation) use ($invoice) {
|
2020-11-05 11:14:30 +01:00
|
|
|
EmailEntity::dispatch($invitation, $invoice->company, $this->reminder_template);
|
2020-03-21 06:37:30 +01:00
|
|
|
});
|
|
|
|
|
2020-12-16 12:52:40 +01:00
|
|
|
if ($invoice->invitations->count() >= 1) {
|
2021-01-20 02:59:39 +01:00
|
|
|
$invoice->entityEmailEvent($invoice->invitations->first(), 'invoice', $this->reminder_template);
|
2020-12-16 12:52:40 +01:00
|
|
|
}
|
2020-12-09 10:52:08 +01:00
|
|
|
|
2020-09-06 11:38:10 +02:00
|
|
|
if (! $bulk) {
|
2020-03-21 06:37:30 +01:00
|
|
|
return response()->json(['message' => 'email sent'], 200);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2021-01-24 23:24:13 +01:00
|
|
|
return response()->json(['message' => ctrans('texts.action_unavailable', ['action' => $action])], 400);
|
2020-04-09 14:04:26 +02:00
|
|
|
break;
|
2020-03-21 06:37:30 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @OA\Get(
|
|
|
|
* path="/api/v1/invoice/{invitation_key}/download",
|
|
|
|
* operationId="downloadInvoice",
|
|
|
|
* tags={"invoices"},
|
|
|
|
* summary="Download a specific invoice by invitation key",
|
|
|
|
* description="Downloads a specific invoice",
|
|
|
|
* @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="invitation_key",
|
|
|
|
* in="path",
|
|
|
|
* description="The Invoice Invitation Key",
|
|
|
|
* example="D2J234DFA",
|
|
|
|
* required=true,
|
|
|
|
* @OA\Schema(
|
|
|
|
* type="string",
|
|
|
|
* format="string",
|
|
|
|
* ),
|
|
|
|
* ),
|
|
|
|
* @OA\Response(
|
|
|
|
* response=200,
|
|
|
|
* description="Returns the invoice pdf",
|
2020-06-21 23:30:25 +02:00
|
|
|
* @OA\Header(header="X-MINIMUM-CLIENT-VERSION", ref="#/components/headers/X-MINIMUM-CLIENT-VERSION"),
|
2020-03-21 06:37:30 +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"),
|
|
|
|
* ),
|
|
|
|
* )
|
2020-10-28 11:10:49 +01:00
|
|
|
* @param $invitation_key
|
|
|
|
* @return \Symfony\Component\HttpFoundation\BinaryFileResponse
|
2020-03-21 06:37:30 +01:00
|
|
|
*/
|
|
|
|
public function downloadPdf($invitation_key)
|
|
|
|
{
|
|
|
|
$invitation = $this->invoice_repo->getInvitationByKey($invitation_key);
|
2020-09-06 11:38:10 +02:00
|
|
|
$contact = $invitation->contact;
|
|
|
|
$invoice = $invitation->invoice;
|
2020-03-21 06:37:30 +01:00
|
|
|
|
|
|
|
$file_path = $invoice->service()->getInvoicePdf($contact);
|
|
|
|
|
2020-04-15 02:30:52 +02:00
|
|
|
return response()->download($file_path, basename($file_path));
|
2020-03-21 06:37:30 +01:00
|
|
|
}
|
2020-11-04 02:27:07 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @OA\Get(
|
|
|
|
* path="/api/v1/invoices/{id}/delivery_note",
|
|
|
|
* operationId="deliveryNote",
|
|
|
|
* tags={"invoices"},
|
|
|
|
* summary="Download a specific invoice delivery notes",
|
|
|
|
* description="Downloads a specific invoice delivery notes",
|
|
|
|
* @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 Invoice Hahsed Id",
|
|
|
|
* example="D2J234DFA",
|
|
|
|
* required=true,
|
|
|
|
* @OA\Schema(
|
|
|
|
* type="string",
|
|
|
|
* format="string",
|
|
|
|
* ),
|
|
|
|
* ),
|
|
|
|
* @OA\Response(
|
|
|
|
* response=200,
|
|
|
|
* description="Returns the invoice delivery note 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 $invoice
|
|
|
|
* @return \Symfony\Component\HttpFoundation\BinaryFileResponse
|
|
|
|
*/
|
|
|
|
public function deliveryNote(ShowInvoiceRequest $request, Invoice $invoice)
|
|
|
|
{
|
2020-11-09 14:30:50 +01:00
|
|
|
$file_path = $invoice->service()->getInvoiceDeliveryNote($invoice, $invoice->invitations->first()->contact);
|
|
|
|
|
2020-12-08 13:10:27 +01:00
|
|
|
try {
|
2020-12-09 13:38:22 +01:00
|
|
|
$file = public_path("storage/{$file_path}");
|
2020-11-04 02:27:07 +01:00
|
|
|
|
|
|
|
|
2020-12-08 13:10:27 +01:00
|
|
|
return response()->download($file, basename($file));
|
2020-12-08 15:04:45 +01:00
|
|
|
} catch (\Exception $e) {
|
2020-12-08 13:10:27 +01:00
|
|
|
return response(['message' => 'Oops, something went wrong. Make sure you have symlink to storage/ in public/ directory.'], 500);
|
|
|
|
}
|
2020-11-04 02:27:07 +01:00
|
|
|
}
|
2021-02-15 12:34:05 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Update the specified resource in storage.
|
|
|
|
*
|
|
|
|
* @param UploadInvoiceRequest $request
|
|
|
|
* @param Invoice $invoice
|
|
|
|
* @return Response
|
|
|
|
*
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @OA\Put(
|
|
|
|
* path="/api/v1/invoices/{id}/upload",
|
|
|
|
* operationId="uploadInvoice",
|
|
|
|
* tags={"invoices"},
|
|
|
|
* summary="Uploads a document to a invoice",
|
|
|
|
* description="Handles the uploading of a document to a invoice",
|
|
|
|
* @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 Invoice Hashed ID",
|
|
|
|
* example="D2J234DFA",
|
|
|
|
* required=true,
|
|
|
|
* @OA\Schema(
|
|
|
|
* type="string",
|
|
|
|
* format="string",
|
|
|
|
* ),
|
|
|
|
* ),
|
|
|
|
* @OA\Response(
|
|
|
|
* response=200,
|
|
|
|
* description="Returns the Invoice 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/Invoice"),
|
|
|
|
* ),
|
|
|
|
* @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(UploadInvoiceRequest $request, Invoice $invoice)
|
|
|
|
{
|
2021-03-07 11:14:53 +01:00
|
|
|
if(!$this->checkFeature(Account::FEATURE_DOCUMENTS))
|
|
|
|
return $this->featureFailure();
|
|
|
|
|
2021-02-15 12:34:05 +01:00
|
|
|
if ($request->has('documents'))
|
|
|
|
$this->saveDocuments($request->file('documents'), $invoice);
|
|
|
|
|
|
|
|
return $this->itemResponse($invoice->fresh());
|
|
|
|
|
|
|
|
}
|
2018-10-17 14:26:27 +02:00
|
|
|
}
|