2015-03-17 02:30:56 +01:00
|
|
|
<?php namespace App\Http\Controllers;
|
2015-03-16 22:45:25 +01:00
|
|
|
|
2015-11-27 13:55:28 +01:00
|
|
|
use Auth;
|
|
|
|
use Input;
|
2015-03-17 02:30:56 +01:00
|
|
|
use Utils;
|
2015-04-08 20:19:58 +02:00
|
|
|
use Response;
|
|
|
|
use App\Models\Invoice;
|
2015-03-24 09:21:12 +01:00
|
|
|
use App\Ninja\Repositories\InvoiceRepository;
|
2015-11-27 13:55:28 +01:00
|
|
|
use App\Http\Controllers\BaseAPIController;
|
|
|
|
use App\Ninja\Transformers\QuoteTransformer;
|
2015-03-16 22:45:25 +01:00
|
|
|
|
2015-11-27 13:55:28 +01:00
|
|
|
class QuoteApiController extends BaseAPIController
|
2015-03-16 22:45:25 +01:00
|
|
|
{
|
|
|
|
protected $invoiceRepo;
|
|
|
|
|
|
|
|
public function __construct(InvoiceRepository $invoiceRepo)
|
|
|
|
{
|
2015-11-27 13:55:28 +01:00
|
|
|
parent::__construct();
|
|
|
|
|
2015-03-16 22:45:25 +01:00
|
|
|
$this->invoiceRepo = $invoiceRepo;
|
|
|
|
}
|
|
|
|
|
2015-11-08 22:53:13 +01:00
|
|
|
/**
|
|
|
|
* @SWG\Get(
|
|
|
|
* path="/quotes",
|
|
|
|
* tags={"quote"},
|
|
|
|
* summary="List of quotes",
|
|
|
|
* @SWG\Response(
|
|
|
|
* response=200,
|
|
|
|
* description="A list with quotes",
|
|
|
|
* @SWG\Schema(type="array", @SWG\Items(ref="#/definitions/Invoice"))
|
|
|
|
* ),
|
|
|
|
* @SWG\Response(
|
|
|
|
* response="default",
|
|
|
|
* description="an ""unexpected"" error"
|
|
|
|
* )
|
|
|
|
* )
|
|
|
|
*/
|
2015-11-27 13:55:28 +01:00
|
|
|
public function index()
|
2015-03-16 22:45:25 +01:00
|
|
|
{
|
2015-11-27 13:55:28 +01:00
|
|
|
$paginator = Invoice::scope();
|
2015-07-30 19:48:59 +02:00
|
|
|
$invoices = Invoice::scope()
|
2015-11-27 13:55:28 +01:00
|
|
|
->with('client', 'invitations', 'user', 'invoice_items')
|
2015-09-07 11:07:55 +02:00
|
|
|
->where('invoices.is_quote', '=', true);
|
|
|
|
|
2015-11-27 13:55:28 +01:00
|
|
|
if ($clientPublicId = Input::get('client_id')) {
|
|
|
|
$filter = function($query) use ($clientPublicId) {
|
2015-09-07 11:07:55 +02:00
|
|
|
$query->where('public_id', '=', $clientPublicId);
|
2015-11-27 13:55:28 +01:00
|
|
|
};
|
|
|
|
$invoices->whereHas('client', $filter);
|
|
|
|
$paginator->whereHas('client', $filter);
|
2015-09-07 11:07:55 +02:00
|
|
|
}
|
|
|
|
|
2015-11-27 13:55:28 +01:00
|
|
|
$invoices = $invoices->orderBy('created_at', 'desc')->paginate();
|
|
|
|
|
|
|
|
$transformer = new QuoteTransformer(\Auth::user()->account, Input::get('serializer'));
|
|
|
|
$paginator = $paginator->paginate();
|
2015-03-16 22:45:25 +01:00
|
|
|
|
2015-11-27 13:55:28 +01:00
|
|
|
$data = $this->createCollection($invoices, $transformer, 'quotes', $paginator);
|
2015-03-16 22:45:25 +01:00
|
|
|
|
2015-11-27 13:55:28 +01:00
|
|
|
return $this->response($data);
|
2015-03-16 22:45:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
public function store()
|
|
|
|
{
|
|
|
|
$data = Input::all();
|
|
|
|
$invoice = $this->invoiceRepo->save(false, $data, false);
|
|
|
|
|
|
|
|
$response = json_encode($invoice, JSON_PRETTY_PRINT);
|
|
|
|
$headers = Utils::getApiHeaders();
|
|
|
|
return Response::make($response, 200, $headers);
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
}
|