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
|
|
|
|
*
|
|
|
|
* @copyright Copyright (c) 2019. Invoice Ninja LLC (https://invoiceninja.com)
|
|
|
|
*
|
|
|
|
* @license https://opensource.org/licenses/AAL
|
|
|
|
*/
|
2019-04-02 08:36:49 +02:00
|
|
|
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
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;
|
|
|
|
use App\Models\Quote;
|
|
|
|
use App\Repositories\QuoteRepository;
|
|
|
|
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-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-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-05-02 13:07:38 +02:00
|
|
|
public function store(StoreQuoteRequest $request)
|
2019-04-02 08:36:49 +02:00
|
|
|
{
|
2019-05-02 13:07:38 +02:00
|
|
|
|
|
|
|
$quote = $this->quote_repo->save($request, QuoteFactory::create(auth()->user()->company()->id, auth()->user()->id));
|
|
|
|
|
|
|
|
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-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-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-05-02 13:07:38 +02:00
|
|
|
public function update(UpdateQuoteRequest $request, Quote $quote)
|
2019-04-02 08:36:49 +02:00
|
|
|
{
|
2019-05-02 13:07:38 +02:00
|
|
|
|
|
|
|
$quote = $this->quote_repo->save(request(), $quote);
|
|
|
|
|
|
|
|
return $this->itemResponse($quote);
|
|
|
|
|
2019-04-02 08:36:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Remove the specified resource from storage.
|
|
|
|
*
|
2019-05-02 13:07:38 +02:00
|
|
|
* @param \App\Http\Requests\Quote\DestroyQuoteRequest $request
|
|
|
|
* @param \App\Models\Quote $quote
|
|
|
|
*
|
|
|
|
* @return \Illuminate\Http\Response
|
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
|
|
|
|
*
|
|
|
|
* @return Collection
|
|
|
|
*/
|
|
|
|
public function bulk()
|
|
|
|
{
|
|
|
|
|
|
|
|
$action = request()->input('action');
|
|
|
|
|
|
|
|
$ids = request()->input('ids');
|
|
|
|
|
|
|
|
$quotes = Quote::withTrashed()->find($ids);
|
|
|
|
|
|
|
|
$quotes->each(function ($quote, $key) use($action){
|
|
|
|
|
|
|
|
if(auth()->user()->can('edit', $quote))
|
|
|
|
$this->quote_repo->{$action}($quote);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
//todo need to return the updated dataset
|
|
|
|
return $this->listResponse(Quote::withTrashed()->whereIn('id', $ids));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public function action(ActionQuoteRequest $request, Quote $quote, $action)
|
|
|
|
{
|
|
|
|
|
|
|
|
switch ($action) {
|
|
|
|
case 'clone_to_invoice':
|
|
|
|
//$quote = CloneInvoiceFactory::create($quote, auth()->user()->id);
|
|
|
|
return $this->itemResponse($quote);
|
|
|
|
break;
|
|
|
|
case 'clone_to_quote':
|
|
|
|
//$quote = CloneInvoiceToQuoteFactory::create($quote, auth()->user()->id);
|
|
|
|
// todo build the quote transformer and return response here
|
|
|
|
break;
|
|
|
|
case 'history':
|
|
|
|
# code...
|
|
|
|
break;
|
|
|
|
case 'delivery_note':
|
|
|
|
# code...
|
|
|
|
break;
|
|
|
|
case 'mark_paid':
|
|
|
|
# code...
|
|
|
|
break;
|
|
|
|
case 'archive':
|
|
|
|
# code...
|
|
|
|
break;
|
|
|
|
case 'delete':
|
|
|
|
# code...
|
|
|
|
break;
|
|
|
|
case 'email':
|
|
|
|
//dispatch email to queue
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
# code...
|
|
|
|
break;
|
|
|
|
}
|
2019-04-02 08:36:49 +02:00
|
|
|
}
|
2019-05-02 13:07:38 +02:00
|
|
|
|
|
|
|
}
|