2018-10-17 14:26:27 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
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-16 05:28:05 +02:00
|
|
|
use App\Http\Requests\Invoice\CreateInvoiceRequest;
|
|
|
|
use App\Http\Requests\Invoice\EditInvoiceRequest;
|
|
|
|
use App\Http\Requests\Invoice\ShowInvoiceRequest;
|
|
|
|
use App\Http\Requests\Invoice\StoreInvoiceRequest;
|
|
|
|
use App\Http\Requests\Invoice\UpdateInvoiceRequest;
|
2019-04-02 07:16:39 +02:00
|
|
|
use App\Models\Invoice;
|
2019-04-17 02:58:23 +02:00
|
|
|
use App\Repositories\InvoiceRepository;
|
2019-04-16 05:28:05 +02:00
|
|
|
use App\Transformers\InvoiceTransformer;
|
2019-04-02 08:36:49 +02:00
|
|
|
use App\Utils\Traits\MakesHash;
|
2018-10-17 14:26:27 +02:00
|
|
|
use Illuminate\Http\Request;
|
|
|
|
|
2019-04-04 11:28:53 +02:00
|
|
|
/**
|
|
|
|
* Class ClientController
|
|
|
|
* @package App\Http\Controllers
|
|
|
|
* @covers App\Http\Controllers\ClientController
|
|
|
|
*/
|
|
|
|
|
2019-03-28 22:34:58 +01:00
|
|
|
class InvoiceController extends BaseController
|
2018-10-17 14:26:27 +02:00
|
|
|
{
|
2019-03-28 22:34:58 +01:00
|
|
|
|
2019-04-02 07:16:39 +02:00
|
|
|
use MakesHash;
|
|
|
|
|
2019-04-04 01:17:15 +02:00
|
|
|
protected $entity_type = Invoice::class;
|
2019-04-02 07:16:39 +02:00
|
|
|
|
2019-04-04 01:17:15 +02:00
|
|
|
protected $entity_transformer = InvoiceTransformer::class;
|
2019-04-02 07:16:39 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @var ClientRepository
|
|
|
|
*/
|
2019-04-04 01:17:15 +02:00
|
|
|
protected $invoice_repo;
|
2019-04-02 07:16:39 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* ClientController constructor.
|
|
|
|
* @param ClientRepository $clientRepo
|
|
|
|
*/
|
2019-04-17 02:58:23 +02:00
|
|
|
public function __construct(InvoiceRepository $invoice_repo)
|
2019-03-28 22:34:58 +01:00
|
|
|
{
|
|
|
|
parent::__construct();
|
|
|
|
|
2019-04-04 01:17:15 +02:00
|
|
|
$this->invoice_repo = $invoice_repo;
|
2019-04-02 07:16:39 +02:00
|
|
|
|
2019-03-28 22:34:58 +01:00
|
|
|
}
|
2019-04-02 07:16:39 +02:00
|
|
|
|
2018-10-17 14:26:27 +02:00
|
|
|
/**
|
2019-04-02 07:16:39 +02:00
|
|
|
* @return \Illuminate\Contracts\View\Factory|\Illuminate\Http\JsonResponse|\Illuminate\View\View
|
2018-10-17 14:26:27 +02:00
|
|
|
*/
|
2019-04-17 02:58:23 +02:00
|
|
|
public function index(InvoiceFilters $filters)
|
2018-10-17 14:26:27 +02:00
|
|
|
{
|
2019-04-02 07:16:39 +02:00
|
|
|
|
2019-04-04 03:38:17 +02:00
|
|
|
$invoices = Invoice::filter($filters);
|
2019-04-02 08:36:49 +02:00
|
|
|
|
2019-04-04 03:38:17 +02:00
|
|
|
return $this->listResponse($invoices);
|
2019-04-02 07:16:39 +02:00
|
|
|
|
2018-10-17 14:26:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Show the form for creating a new resource.
|
|
|
|
*
|
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
*/
|
2019-04-16 05:28:05 +02:00
|
|
|
public function create(CreateInvoiceRequest $request)
|
2018-10-17 14:26:27 +02:00
|
|
|
{
|
2019-04-15 02:10:54 +02:00
|
|
|
$invoice = InvoiceFactory::create(auth()->user()->company()->id, auth()->user()->id);
|
|
|
|
|
|
|
|
return $this->itemResponse($invoice);
|
2018-10-17 14:26:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Store a newly created resource in storage.
|
|
|
|
*
|
|
|
|
* @param \Illuminate\Http\Request $request
|
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
*/
|
2019-04-16 05:28:05 +02:00
|
|
|
public function store(StoreInvoiceRequest $request)
|
2018-10-17 14:26:27 +02:00
|
|
|
{
|
2019-04-16 05:28:05 +02:00
|
|
|
|
2019-04-16 07:28:30 +02:00
|
|
|
$invoice = $this->invoice_repo->save($request, InvoiceFactory::create(auth()->user()->company()->id, auth()->user()->id));
|
|
|
|
|
2019-04-16 05:28:05 +02:00
|
|
|
return $this->itemResponse($invoice);
|
|
|
|
|
2018-10-17 14:26:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Display the specified resource.
|
|
|
|
*
|
|
|
|
* @param int $id
|
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
*/
|
2019-04-16 07:28:30 +02:00
|
|
|
public function show(ShowInvoiceRequest $request, Invoice $invoice)
|
2018-10-17 14:26:27 +02:00
|
|
|
{
|
2019-04-16 07:28:30 +02:00
|
|
|
|
|
|
|
return $this->itemResponse($invoice);
|
|
|
|
|
2018-10-17 14:26:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Show the form for editing the specified resource.
|
|
|
|
*
|
|
|
|
* @param int $id
|
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
*/
|
2019-04-17 02:58:23 +02:00
|
|
|
public function edit(EditInvoiceRequest $request, Invoice $invoice)
|
2018-10-17 14:26:27 +02:00
|
|
|
{
|
2019-04-16 07:28:30 +02:00
|
|
|
|
|
|
|
return $this->itemResponse($invoice);
|
|
|
|
|
2018-10-17 14:26:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Update the specified resource in storage.
|
|
|
|
*
|
|
|
|
* @param \Illuminate\Http\Request $request
|
|
|
|
* @param int $id
|
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
*/
|
2019-04-16 07:28:30 +02:00
|
|
|
public function update(UpdateInvoiceRequest $request, Invoice $invoice)
|
2018-10-17 14:26:27 +02:00
|
|
|
{
|
2019-04-16 07:28:30 +02:00
|
|
|
|
|
|
|
$invoice = $this->invoice_repo->save($request, $invoice);
|
|
|
|
|
|
|
|
return $this->itemResponse($invoice);
|
|
|
|
|
2018-10-17 14:26:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Remove the specified resource from storage.
|
|
|
|
*
|
|
|
|
* @param int $id
|
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
*/
|
2019-04-16 05:28:05 +02:00
|
|
|
public function destroy(DestroyInvoiceRequest $request, Invoice $invoice)
|
2018-10-17 14:26:27 +02:00
|
|
|
{
|
2019-04-16 07:28:30 +02:00
|
|
|
|
|
|
|
$invoice->delete();
|
|
|
|
|
|
|
|
return response()->json([], 200);
|
2019-04-17 02:58:23 +02:00
|
|
|
|
2018-10-17 14:26:27 +02:00
|
|
|
}
|
|
|
|
}
|