mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-09 03:14:30 -04:00
Added tax rates and localization to the API
This commit is contained in:
parent
021f195c45
commit
e9cacf2fdf
68
app/Http/Controllers/TaxRateApiController.php
Normal file
68
app/Http/Controllers/TaxRateApiController.php
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
<?php namespace App\Http\Controllers;
|
||||||
|
|
||||||
|
use App\Services\TaxRateService;
|
||||||
|
use App\Ninja\Repositories\TaxRateRepository;
|
||||||
|
use App\Ninja\Transformers\TaxRateTransformer;
|
||||||
|
use Auth;
|
||||||
|
use App\Models\TaxRate;
|
||||||
|
|
||||||
|
use App\Http\Requests\CreateTaxRateRequest;
|
||||||
|
use App\Http\Requests\UpdateTaxRateRequest;
|
||||||
|
|
||||||
|
class TaxRateApiController extends BaseAPIController
|
||||||
|
{
|
||||||
|
protected $taxRateService;
|
||||||
|
protected $taxRateRepo;
|
||||||
|
|
||||||
|
public function __construct(TaxRateService $taxRateService, TaxRateRepository $taxRateRepo)
|
||||||
|
{
|
||||||
|
parent::__construct();
|
||||||
|
|
||||||
|
$this->taxRateService = $taxRateService;
|
||||||
|
$this->taxRateRepo = $taxRateRepo;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function index()
|
||||||
|
{
|
||||||
|
$taxRates = TaxRate::scope()->withTrashed();
|
||||||
|
$taxRates = $taxRates->paginate();
|
||||||
|
|
||||||
|
$paginator = TaxRate::scope()->withTrashed()->paginate();
|
||||||
|
|
||||||
|
$transformer = new TaxRateTransformer(Auth::user()->account, $this->serializer);
|
||||||
|
$data = $this->createCollection($taxRates, $transformer, 'tax_rates', $paginator);
|
||||||
|
|
||||||
|
return $this->response($data);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function store(CreateTaxRateRequest $request)
|
||||||
|
{
|
||||||
|
return $this->save($request);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function update(UpdateTaxRateRequest $request, $taxRatePublicId)
|
||||||
|
{
|
||||||
|
$taxRate = TaxRate::scope($taxRatePublicId)->firstOrFail();
|
||||||
|
|
||||||
|
if ($request->action == ACTION_ARCHIVE) {
|
||||||
|
$this->taxRateRepo->archive($taxRate);
|
||||||
|
|
||||||
|
$transformer = new TaxRateTransformer(Auth::user()->account, $request->serializer);
|
||||||
|
$data = $this->createItem($taxRate, $transformer, 'tax_rates');
|
||||||
|
|
||||||
|
return $this->response($data);
|
||||||
|
} else {
|
||||||
|
return $this->save($request, $taxRate);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private function save($request, $taxRate = false)
|
||||||
|
{
|
||||||
|
$taxRate = $this->taxRateRepo->save($request->input(), $taxRate);
|
||||||
|
|
||||||
|
$transformer = new TaxRateTransformer(\Auth::user()->account, $request->serializer);
|
||||||
|
$data = $this->createItem($taxRate, $transformer, 'tax_rates');
|
||||||
|
|
||||||
|
return $this->response($data);
|
||||||
|
}
|
||||||
|
}
|
@ -13,16 +13,22 @@ use Redirect;
|
|||||||
|
|
||||||
use App\Models\TaxRate;
|
use App\Models\TaxRate;
|
||||||
use App\Services\TaxRateService;
|
use App\Services\TaxRateService;
|
||||||
|
use App\Ninja\Repositories\TaxRateRepository;
|
||||||
|
|
||||||
|
use App\Http\Requests\CreateTaxRateRequest;
|
||||||
|
use App\Http\Requests\UpdateTaxRateRequest;
|
||||||
|
|
||||||
class TaxRateController extends BaseController
|
class TaxRateController extends BaseController
|
||||||
{
|
{
|
||||||
protected $taxRateService;
|
protected $taxRateService;
|
||||||
|
protected $taxRateRepo;
|
||||||
|
|
||||||
public function __construct(TaxRateService $taxRateService)
|
public function __construct(TaxRateService $taxRateService, TaxRateRepository $taxRateRepo)
|
||||||
{
|
{
|
||||||
parent::__construct();
|
parent::__construct();
|
||||||
|
|
||||||
$this->taxRateService = $taxRateService;
|
$this->taxRateService = $taxRateService;
|
||||||
|
$this->taxRateRepo = $taxRateRepo;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function index()
|
public function index()
|
||||||
@ -59,34 +65,25 @@ class TaxRateController extends BaseController
|
|||||||
return View::make('accounts.tax_rate', $data);
|
return View::make('accounts.tax_rate', $data);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function store()
|
public function store(CreateTaxRateRequest $request)
|
||||||
{
|
{
|
||||||
return $this->save();
|
$this->taxRateRepo->save($request->input());
|
||||||
}
|
|
||||||
|
|
||||||
public function update($publicId)
|
|
||||||
{
|
|
||||||
return $this->save($publicId);
|
|
||||||
}
|
|
||||||
|
|
||||||
private function save($publicId = false)
|
|
||||||
{
|
|
||||||
if ($publicId) {
|
|
||||||
$taxRate = TaxRate::scope($publicId)->firstOrFail();
|
|
||||||
} else {
|
|
||||||
$taxRate = TaxRate::createNew();
|
|
||||||
}
|
|
||||||
|
|
||||||
$taxRate->name = trim(Input::get('name'));
|
|
||||||
$taxRate->rate = Utils::parseFloat(Input::get('rate'));
|
|
||||||
$taxRate->save();
|
|
||||||
|
|
||||||
$message = $publicId ? trans('texts.updated_tax_rate') : trans('texts.created_tax_rate');
|
|
||||||
Session::flash('message', $message);
|
|
||||||
|
|
||||||
|
Session::flash('message', trans('texts.created_tax_rate'));
|
||||||
return Redirect::to('settings/' . ACCOUNT_TAX_RATES);
|
return Redirect::to('settings/' . ACCOUNT_TAX_RATES);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function update(UpdateTaxRateRequest $request, $publicId)
|
||||||
|
{
|
||||||
|
$taxRate = TaxRate::scope($publicId)->firstOrFail();
|
||||||
|
|
||||||
|
$this->taxRateRepo->save($request->input(), $taxRate);
|
||||||
|
|
||||||
|
Session::flash('message', trans('texts.updated_tax_rate'));
|
||||||
|
return Redirect::to('settings/' . ACCOUNT_TAX_RATES);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public function bulk()
|
public function bulk()
|
||||||
{
|
{
|
||||||
$action = Input::get('bulk_action');
|
$action = Input::get('bulk_action');
|
||||||
|
31
app/Http/Requests/CreateTaxRateRequest.php
Normal file
31
app/Http/Requests/CreateTaxRateRequest.php
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
<?php namespace app\Http\Requests;
|
||||||
|
|
||||||
|
use App\Http\Requests\Request;
|
||||||
|
use Illuminate\Validation\Factory;
|
||||||
|
|
||||||
|
class CreateTaxRateRequest extends Request
|
||||||
|
{
|
||||||
|
// Expenses
|
||||||
|
/**
|
||||||
|
* Determine if the user is authorized to make this request.
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function authorize()
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the validation rules that apply to the request.
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function rules()
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'name' => 'required',
|
||||||
|
'rate' => 'required',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
31
app/Http/Requests/UpdateTaxRateRequest.php
Normal file
31
app/Http/Requests/UpdateTaxRateRequest.php
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
<?php namespace app\Http\Requests;
|
||||||
|
|
||||||
|
use App\Http\Requests\Request;
|
||||||
|
use Illuminate\Validation\Factory;
|
||||||
|
|
||||||
|
class UpdateTaxRateRequest extends Request
|
||||||
|
{
|
||||||
|
// Expenses
|
||||||
|
/**
|
||||||
|
* Determine if the user is authorized to make this request.
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function authorize()
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the validation rules that apply to the request.
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function rules()
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'name' => 'required',
|
||||||
|
'rate' => 'required',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
@ -232,9 +232,9 @@ Route::group(['middleware' => 'api', 'prefix' => 'api/v1'], function()
|
|||||||
Route::resource('tasks', 'TaskApiController');
|
Route::resource('tasks', 'TaskApiController');
|
||||||
Route::post('hooks', 'IntegrationController@subscribe');
|
Route::post('hooks', 'IntegrationController@subscribe');
|
||||||
Route::post('email_invoice', 'InvoiceApiController@emailInvoice');
|
Route::post('email_invoice', 'InvoiceApiController@emailInvoice');
|
||||||
Route::post('email_invoicev2', 'InvoiceApiController@emailInvoicev2');
|
|
||||||
Route::get('user_accounts', 'AccountApiController@getUserAccounts');
|
Route::get('user_accounts', 'AccountApiController@getUserAccounts');
|
||||||
Route::resource('products', 'ProductApiController');
|
Route::resource('products', 'ProductApiController');
|
||||||
|
Route::resource('tax_rates', 'TaxRateApiController');
|
||||||
|
|
||||||
// Vendor
|
// Vendor
|
||||||
Route::resource('vendors', 'VendorApiController');
|
Route::resource('vendors', 'VendorApiController');
|
||||||
|
@ -37,6 +37,12 @@ class Account extends Eloquent
|
|||||||
'size_id',
|
'size_id',
|
||||||
'industry_id',
|
'industry_id',
|
||||||
'email_footer',
|
'email_footer',
|
||||||
|
'timezone_id',
|
||||||
|
'date_format_id',
|
||||||
|
'datetime_format_id',
|
||||||
|
'currency_id',
|
||||||
|
'language_id',
|
||||||
|
'military_time',
|
||||||
];
|
];
|
||||||
|
|
||||||
public static $basicSettings = [
|
public static $basicSettings = [
|
||||||
|
@ -7,6 +7,11 @@ class TaxRate extends EntityModel
|
|||||||
use SoftDeletes;
|
use SoftDeletes;
|
||||||
protected $dates = ['deleted_at'];
|
protected $dates = ['deleted_at'];
|
||||||
|
|
||||||
|
protected $fillable = [
|
||||||
|
'name',
|
||||||
|
'rate'
|
||||||
|
];
|
||||||
|
|
||||||
public function getEntityType()
|
public function getEntityType()
|
||||||
{
|
{
|
||||||
return ENTITY_TAX_RATE;
|
return ENTITY_TAX_RATE;
|
||||||
|
@ -20,6 +20,22 @@ class TaxRateRepository extends BaseRepository
|
|||||||
->select('tax_rates.public_id', 'tax_rates.name', 'tax_rates.rate', 'tax_rates.deleted_at');
|
->select('tax_rates.public_id', 'tax_rates.name', 'tax_rates.rate', 'tax_rates.deleted_at');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function save($data, $taxRate = false)
|
||||||
|
{
|
||||||
|
if ( ! $taxRate) {
|
||||||
|
if (isset($data['public_id'])) {
|
||||||
|
$taxRate = TaxRate::scope($data['public_id'])->firstOrFail();
|
||||||
|
} else {
|
||||||
|
$taxRate = TaxRate::createNew();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$taxRate->fill($data);
|
||||||
|
$taxRate->save();
|
||||||
|
|
||||||
|
return $taxRate;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
public function save($taxRates)
|
public function save($taxRates)
|
||||||
{
|
{
|
||||||
|
@ -64,6 +64,12 @@ class APICest
|
|||||||
$this->createEntity('payment', $data);
|
$this->createEntity('payment', $data);
|
||||||
$this->listEntities('payment');
|
$this->listEntities('payment');
|
||||||
|
|
||||||
|
$data = new stdClass;
|
||||||
|
$data->name = $this->faker->word;
|
||||||
|
$data->rate = $this->faker->numberBetween(1, 10);
|
||||||
|
$this->createEntity('tax_rate', $data);
|
||||||
|
$this->listEntities('tax_rate');
|
||||||
|
|
||||||
$this->listEntities('account');
|
$this->listEntities('account');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user