2015-10-21 13:11:08 +02:00
|
|
|
<?php namespace App\Http\Controllers;
|
|
|
|
|
|
|
|
use Auth;
|
|
|
|
use Str;
|
|
|
|
use DB;
|
|
|
|
use Datatable;
|
|
|
|
use Utils;
|
|
|
|
use URL;
|
|
|
|
use View;
|
|
|
|
use Input;
|
|
|
|
use Session;
|
|
|
|
use Redirect;
|
|
|
|
|
|
|
|
use App\Models\TaxRate;
|
2015-11-05 23:37:04 +01:00
|
|
|
use App\Services\TaxRateService;
|
2015-10-21 13:11:08 +02:00
|
|
|
|
|
|
|
class TaxRateController extends BaseController
|
|
|
|
{
|
2015-11-05 23:37:04 +01:00
|
|
|
protected $taxRateService;
|
|
|
|
|
|
|
|
public function __construct(TaxRateService $taxRateService)
|
|
|
|
{
|
|
|
|
parent::__construct();
|
|
|
|
|
|
|
|
$this->taxRateService = $taxRateService;
|
|
|
|
}
|
|
|
|
|
2015-10-21 13:11:08 +02:00
|
|
|
public function index()
|
|
|
|
{
|
|
|
|
return Redirect::to('settings/' . ACCOUNT_TAX_RATES);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getDatatable()
|
|
|
|
{
|
2015-11-05 23:37:04 +01:00
|
|
|
return $this->taxRateService->getDatatable(Auth::user()->account_id);
|
2015-10-21 13:11:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function edit($publicId)
|
|
|
|
{
|
|
|
|
$data = [
|
|
|
|
'taxRate' => TaxRate::scope($publicId)->firstOrFail(),
|
|
|
|
'method' => 'PUT',
|
|
|
|
'url' => 'tax_rates/'.$publicId,
|
|
|
|
'title' => trans('texts.edit_tax_rate'),
|
|
|
|
];
|
|
|
|
|
|
|
|
return View::make('accounts.tax_rate', $data);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function create()
|
|
|
|
{
|
|
|
|
$data = [
|
|
|
|
'taxRate' => null,
|
|
|
|
'method' => 'POST',
|
|
|
|
'url' => 'tax_rates',
|
|
|
|
'title' => trans('texts.create_tax_rate'),
|
|
|
|
];
|
|
|
|
|
|
|
|
return View::make('accounts.tax_rate', $data);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function store()
|
|
|
|
{
|
|
|
|
return $this->save();
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
return Redirect::to('settings/' . ACCOUNT_TAX_RATES);
|
|
|
|
}
|
|
|
|
|
2015-11-05 23:37:04 +01:00
|
|
|
public function bulk()
|
2015-10-21 13:11:08 +02:00
|
|
|
{
|
2015-11-05 23:37:04 +01:00
|
|
|
$action = Input::get('bulk_action');
|
|
|
|
$ids = Input::get('bulk_public_id');
|
|
|
|
$count = $this->taxRateService->bulk($ids, $action);
|
2015-10-21 13:11:08 +02:00
|
|
|
|
|
|
|
Session::flash('message', trans('texts.archived_tax_rate'));
|
|
|
|
|
|
|
|
return Redirect::to('settings/' . ACCOUNT_TAX_RATES);
|
|
|
|
}
|
|
|
|
}
|