2017-01-30 20:40:43 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers;
|
2016-02-03 15:03:56 +01:00
|
|
|
|
2017-03-08 17:03:35 +01:00
|
|
|
use App\Http\Requests\TaxRateRequest;
|
2016-02-03 15:03:56 +01:00
|
|
|
use App\Http\Requests\CreateTaxRateRequest;
|
|
|
|
use App\Http\Requests\UpdateTaxRateRequest;
|
2017-01-30 20:40:43 +01:00
|
|
|
use App\Models\TaxRate;
|
|
|
|
use App\Ninja\Repositories\TaxRateRepository;
|
2016-02-03 15:03:56 +01:00
|
|
|
|
|
|
|
class TaxRateApiController extends BaseAPIController
|
|
|
|
{
|
2016-07-03 18:11:58 +02:00
|
|
|
/**
|
|
|
|
* @var TaxRateRepository
|
|
|
|
*/
|
2016-02-03 15:03:56 +01:00
|
|
|
protected $taxRateRepo;
|
2016-07-03 18:11:58 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @var string
|
|
|
|
*/
|
2016-05-01 22:55:13 +02:00
|
|
|
protected $entityType = ENTITY_TAX_RATE;
|
|
|
|
|
2016-07-03 18:11:58 +02:00
|
|
|
/**
|
|
|
|
* TaxRateApiController constructor.
|
2017-01-30 20:40:43 +01:00
|
|
|
*
|
2016-07-03 18:11:58 +02:00
|
|
|
* @param TaxRateRepository $taxRateRepo
|
|
|
|
*/
|
2016-05-02 15:12:37 +02:00
|
|
|
public function __construct(TaxRateRepository $taxRateRepo)
|
2016-02-03 15:03:56 +01:00
|
|
|
{
|
2016-03-02 15:36:46 +01:00
|
|
|
parent::__construct();
|
2016-02-03 15:03:56 +01:00
|
|
|
|
|
|
|
$this->taxRateRepo = $taxRateRepo;
|
|
|
|
}
|
|
|
|
|
2016-12-29 17:17:17 +01:00
|
|
|
/**
|
|
|
|
* @SWG\Get(
|
|
|
|
* path="/tax_rates",
|
2017-03-09 17:22:37 +01:00
|
|
|
* summary="List tax rates",
|
|
|
|
* operationId="listTaxRates",
|
2016-12-29 17:17:17 +01:00
|
|
|
* tags={"tax_rate"},
|
|
|
|
* @SWG\Response(
|
|
|
|
* response=200,
|
2017-03-08 17:03:35 +01:00
|
|
|
* description="A list of tax rates",
|
2016-12-29 17:17:17 +01:00
|
|
|
* @SWG\Schema(type="array", @SWG\Items(ref="#/definitions/TaxRate"))
|
|
|
|
* ),
|
|
|
|
* @SWG\Response(
|
|
|
|
* response="default",
|
|
|
|
* description="an ""unexpected"" error"
|
|
|
|
* )
|
|
|
|
* )
|
|
|
|
*/
|
2016-02-03 15:03:56 +01:00
|
|
|
public function index()
|
|
|
|
{
|
2016-05-01 22:55:13 +02:00
|
|
|
$taxRates = TaxRate::scope()
|
|
|
|
->withTrashed()
|
|
|
|
->orderBy('created_at', 'desc');
|
2016-05-02 15:12:37 +02:00
|
|
|
|
2016-05-02 10:38:01 +02:00
|
|
|
return $this->listResponse($taxRates);
|
2016-02-03 15:03:56 +01:00
|
|
|
}
|
|
|
|
|
2017-03-08 17:03:35 +01:00
|
|
|
/**
|
|
|
|
* @SWG\Get(
|
|
|
|
* path="/tax_rates/{tax_rate_id}",
|
|
|
|
* summary="Retrieve a tax rate",
|
2017-03-09 17:22:37 +01:00
|
|
|
* operationId="getTaxRate",
|
|
|
|
* tags={"tax_rate"},
|
2017-03-08 17:03:35 +01:00
|
|
|
* @SWG\Parameter(
|
|
|
|
* in="path",
|
|
|
|
* name="tax_rate_id",
|
|
|
|
* type="integer",
|
2017-03-09 11:11:45 +01:00
|
|
|
* required=true
|
2017-03-08 17:03:35 +01:00
|
|
|
* ),
|
|
|
|
* @SWG\Response(
|
|
|
|
* response=200,
|
|
|
|
* description="A single tax rate",
|
|
|
|
* @SWG\Schema(type="object", @SWG\Items(ref="#/definitions/TaxRate"))
|
|
|
|
* ),
|
|
|
|
* @SWG\Response(
|
|
|
|
* response="default",
|
|
|
|
* description="an ""unexpected"" error"
|
|
|
|
* )
|
|
|
|
* )
|
|
|
|
*/
|
|
|
|
public function show(TaxRateRequest $request)
|
|
|
|
{
|
|
|
|
return $this->itemResponse($request->entity());
|
|
|
|
}
|
|
|
|
|
2016-12-29 17:17:17 +01:00
|
|
|
/**
|
|
|
|
* @SWG\Post(
|
|
|
|
* path="/tax_rates",
|
|
|
|
* summary="Create a tax rate",
|
2017-03-09 17:22:37 +01:00
|
|
|
* operationId="createTaxRate",
|
|
|
|
* tags={"tax_rate"},
|
2016-12-29 17:17:17 +01:00
|
|
|
* @SWG\Parameter(
|
|
|
|
* in="body",
|
2017-03-08 17:03:35 +01:00
|
|
|
* name="tax_rate",
|
2016-12-29 17:17:17 +01:00
|
|
|
* @SWG\Schema(ref="#/definitions/TaxRate")
|
|
|
|
* ),
|
|
|
|
* @SWG\Response(
|
|
|
|
* response=200,
|
|
|
|
* description="New tax rate",
|
|
|
|
* @SWG\Schema(type="object", @SWG\Items(ref="#/definitions/TaxRate"))
|
|
|
|
* ),
|
|
|
|
* @SWG\Response(
|
|
|
|
* response="default",
|
|
|
|
* description="an ""unexpected"" error"
|
|
|
|
* )
|
|
|
|
* )
|
|
|
|
*/
|
2016-02-03 15:03:56 +01:00
|
|
|
public function store(CreateTaxRateRequest $request)
|
|
|
|
{
|
2016-05-02 15:12:37 +02:00
|
|
|
$taxRate = $this->taxRateRepo->save($request->input());
|
|
|
|
|
|
|
|
return $this->itemResponse($taxRate);
|
2016-02-03 15:03:56 +01:00
|
|
|
}
|
|
|
|
|
2016-07-03 18:11:58 +02:00
|
|
|
/**
|
2016-12-29 17:17:17 +01:00
|
|
|
* @SWG\Put(
|
|
|
|
* path="/tax_rates/{tax_rate_id}",
|
|
|
|
* summary="Update a tax rate",
|
2017-03-09 17:22:37 +01:00
|
|
|
* operationId="updateTaxRate",
|
|
|
|
* tags={"tax_rate"},
|
2016-12-29 17:17:17 +01:00
|
|
|
* @SWG\Parameter(
|
2017-03-08 17:03:35 +01:00
|
|
|
* in="path",
|
|
|
|
* name="tax_rate_id",
|
|
|
|
* type="integer",
|
2017-03-09 11:11:45 +01:00
|
|
|
* required=true
|
2017-03-08 17:03:35 +01:00
|
|
|
* ),
|
|
|
|
* @SWG\Parameter(
|
2016-12-29 17:17:17 +01:00
|
|
|
* in="body",
|
2017-03-08 17:03:35 +01:00
|
|
|
* name="tax_rate",
|
2016-12-29 17:17:17 +01:00
|
|
|
* @SWG\Schema(ref="#/definitions/TaxRate")
|
|
|
|
* ),
|
|
|
|
* @SWG\Response(
|
|
|
|
* response=200,
|
2017-03-08 17:03:35 +01:00
|
|
|
* description="Updated tax rate",
|
2016-12-29 17:17:17 +01:00
|
|
|
* @SWG\Schema(type="object", @SWG\Items(ref="#/definitions/TaxRate"))
|
|
|
|
* ),
|
|
|
|
* @SWG\Response(
|
|
|
|
* response="default",
|
|
|
|
* description="an ""unexpected"" error"
|
|
|
|
* )
|
|
|
|
* )
|
2017-01-30 20:54:09 +01:00
|
|
|
*
|
2017-01-30 20:49:42 +01:00
|
|
|
* @param mixed $publicId
|
2016-07-03 18:11:58 +02:00
|
|
|
*/
|
2016-05-02 15:12:37 +02:00
|
|
|
public function update(UpdateTaxRateRequest $request, $publicId)
|
2016-02-03 15:03:56 +01:00
|
|
|
{
|
2016-05-02 15:12:37 +02:00
|
|
|
if ($request->action) {
|
|
|
|
return $this->handleAction($request);
|
2016-02-03 15:03:56 +01:00
|
|
|
}
|
2016-12-29 17:17:17 +01:00
|
|
|
|
2016-05-02 15:12:37 +02:00
|
|
|
$data = $request->input();
|
|
|
|
$data['public_id'] = $publicId;
|
2016-05-02 19:42:13 +02:00
|
|
|
$taxRate = $this->taxRateRepo->save($data, $request->entity());
|
2016-05-02 15:12:37 +02:00
|
|
|
|
|
|
|
return $this->itemResponse($taxRate);
|
2016-02-03 15:03:56 +01:00
|
|
|
}
|
2017-03-08 17:03:35 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @SWG\Delete(
|
|
|
|
* path="/tax_rates/{tax_rate_id}",
|
|
|
|
* summary="Delete a tax rate",
|
2017-03-09 17:22:37 +01:00
|
|
|
* operationId="deleteTaxRate",
|
|
|
|
* tags={"tax_rate"},
|
2017-03-08 17:03:35 +01:00
|
|
|
* @SWG\Parameter(
|
|
|
|
* in="path",
|
|
|
|
* name="tax_rate_id",
|
|
|
|
* type="integer",
|
2017-03-09 11:11:45 +01:00
|
|
|
* required=true
|
2017-03-08 17:03:35 +01:00
|
|
|
* ),
|
|
|
|
* @SWG\Response(
|
|
|
|
* response=200,
|
|
|
|
* description="Deleted tax rate",
|
|
|
|
* @SWG\Schema(type="object", @SWG\Items(ref="#/definitions/TaxRate"))
|
|
|
|
* ),
|
|
|
|
* @SWG\Response(
|
|
|
|
* response="default",
|
|
|
|
* description="an ""unexpected"" error"
|
|
|
|
* )
|
|
|
|
* )
|
|
|
|
*/
|
2017-03-09 11:11:45 +01:00
|
|
|
public function destroy(UpdateTaxRateRequest $request)
|
2017-03-08 17:03:35 +01:00
|
|
|
{
|
|
|
|
$entity = $request->entity();
|
|
|
|
|
|
|
|
$this->taxRateRepo->delete($entity);
|
|
|
|
|
|
|
|
return $this->itemResponse($entity);
|
|
|
|
}
|
2016-02-03 15:03:56 +01:00
|
|
|
}
|