2016-02-03 15:03:56 +01:00
|
|
|
<?php namespace App\Http\Controllers;
|
|
|
|
|
|
|
|
use App\Models\TaxRate;
|
2016-05-02 15:12:37 +02:00
|
|
|
use App\Ninja\Repositories\TaxRateRepository;
|
2016-02-03 15:03:56 +01:00
|
|
|
use App\Http\Requests\CreateTaxRateRequest;
|
|
|
|
use App\Http\Requests\UpdateTaxRateRequest;
|
|
|
|
|
|
|
|
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.
|
|
|
|
* @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;
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
/**
|
|
|
|
* @param UpdateTaxRateRequest $request
|
|
|
|
* @param $publicId
|
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
*/
|
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-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
|
|
|
}
|
|
|
|
}
|