2018-08-31 06:03:11 +00:00
|
|
|
<?php
|
|
|
|
|
|
2018-10-11 14:25:59 +00:00
|
|
|
namespace Webkul\Tax\Http\Controllers;
|
2018-08-31 06:03:11 +00:00
|
|
|
|
|
|
|
|
use Illuminate\Http\Request;
|
|
|
|
|
use Illuminate\Http\Response;
|
2018-10-11 14:25:59 +00:00
|
|
|
use Webkul\Tax\Repositories\TaxRatesRepository as TaxRate;
|
2018-08-31 06:03:11 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Tax controller
|
|
|
|
|
*
|
|
|
|
|
* @author Prashant Singh <prashant.singh852@webkul.com>
|
|
|
|
|
* @copyright 2018 Webkul Software Pvt Ltd (http://www.webkul.com)
|
|
|
|
|
*/
|
|
|
|
|
class TaxRateController extends Controller
|
|
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
* Contains route related configuration
|
|
|
|
|
*
|
|
|
|
|
* @var array
|
|
|
|
|
*/
|
|
|
|
|
protected $_config;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Tax Rate Repository object
|
|
|
|
|
*
|
|
|
|
|
* @var array
|
|
|
|
|
*/
|
|
|
|
|
protected $taxRate;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Create a new controller instance.
|
|
|
|
|
*
|
2018-10-11 14:25:59 +00:00
|
|
|
* @param Webkul\Tax\Repositories\TaxRatesRepository $taxRate
|
2018-08-31 06:03:11 +00:00
|
|
|
* @return void
|
|
|
|
|
*/
|
|
|
|
|
public function __construct(TaxRate $taxRate)
|
|
|
|
|
{
|
|
|
|
|
$this->middleware('admin');
|
|
|
|
|
|
|
|
|
|
$this->taxRate = $taxRate;
|
|
|
|
|
|
|
|
|
|
$this->_config = request('_config');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2018-09-04 09:14:32 +00:00
|
|
|
* Display a listing
|
|
|
|
|
* resource for the
|
|
|
|
|
* available tax rates.
|
|
|
|
|
*
|
|
|
|
|
* @return mixed
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
public function index() {
|
|
|
|
|
return view($this->_config['view']);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Display a create
|
|
|
|
|
* form for tax rate
|
2018-08-31 06:03:11 +00:00
|
|
|
*
|
|
|
|
|
* @return view
|
|
|
|
|
*/
|
|
|
|
|
public function show()
|
|
|
|
|
{
|
|
|
|
|
return view($this->_config['view']);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Create the tax rate
|
|
|
|
|
*
|
|
|
|
|
* @return mixed
|
|
|
|
|
*/
|
|
|
|
|
public function create() {
|
2018-10-11 14:25:59 +00:00
|
|
|
// dd(request()->all());
|
2018-08-31 06:03:11 +00:00
|
|
|
|
|
|
|
|
$this->validate(request(), [
|
|
|
|
|
'identifier' => 'required|string|unique:tax_rates,identifier',
|
2018-10-11 14:25:59 +00:00
|
|
|
'is_zip' => 'sometimes',
|
2018-10-09 12:04:25 +00:00
|
|
|
'zip_code' => 'sometimes|required_without:is_zip',
|
2018-08-31 06:03:11 +00:00
|
|
|
'zip_from' => 'nullable|numeric|required_with:is_zip',
|
|
|
|
|
'zip_to' => 'nullable|numeric|required_with:is_zip,zip_from',
|
|
|
|
|
'state' => 'required|string',
|
|
|
|
|
'country' => 'required|string',
|
|
|
|
|
'tax_rate' => 'required|numeric'
|
|
|
|
|
]);
|
|
|
|
|
|
2018-10-11 14:25:59 +00:00
|
|
|
$data = request()->all();
|
|
|
|
|
// dd($data);
|
|
|
|
|
if(isset($data['is_zip'])) {
|
|
|
|
|
$data['is_zip'] = 1;
|
|
|
|
|
unset($data['zip_code']);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if($this->taxRate->create($data)) {
|
2018-08-31 06:03:11 +00:00
|
|
|
session()->flash('success', 'Tax Rate Created Successfully');
|
|
|
|
|
|
|
|
|
|
return redirect()->route($this->_config['redirect']);
|
|
|
|
|
} else {
|
|
|
|
|
session()->flash('error', 'Cannot Create Tax Rate');
|
|
|
|
|
|
|
|
|
|
return redirect()->back();
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-09 12:04:25 +00:00
|
|
|
Session()->flash('warning', 'System Cannot Identify the cause of this error, contact system administrator.');
|
|
|
|
|
|
2018-08-31 06:03:11 +00:00
|
|
|
return redirect()->back();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Show the edit form
|
|
|
|
|
* for the previously
|
|
|
|
|
* created tax rates.
|
|
|
|
|
*
|
|
|
|
|
* @return mixed
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
public function edit($id) {
|
|
|
|
|
|
|
|
|
|
$data = collect($this->taxRate->findOneByField('id', $id));
|
|
|
|
|
|
|
|
|
|
return view($this->_config['view'])->with('data', $data);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Edit the previous
|
|
|
|
|
* tax rate
|
|
|
|
|
*
|
|
|
|
|
* @return mixed
|
|
|
|
|
*/
|
|
|
|
|
public function update($id) {
|
|
|
|
|
|
|
|
|
|
$this->validate(request(), [
|
|
|
|
|
'identifier' => 'required|string|unique:tax_rates,identifier,'.$id,
|
2018-10-11 14:25:59 +00:00
|
|
|
'is_zip' => 'sometimes',
|
2018-08-31 06:03:11 +00:00
|
|
|
'zip_from' => 'nullable|numeric|required_with:is_zip',
|
|
|
|
|
'zip_to' => 'nullable|numeric|required_with:is_zip,zip_from',
|
|
|
|
|
'state' => 'required|string',
|
|
|
|
|
'country' => 'required|string',
|
|
|
|
|
'tax_rate' => 'required|numeric'
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
if($this->taxRate->update(request()->input(), $id)) {
|
|
|
|
|
session()->flash('success', 'Tax Rate Updated Successfully');
|
|
|
|
|
|
|
|
|
|
return redirect()->route($this->_config['redirect']);
|
|
|
|
|
} else {
|
|
|
|
|
session()->flash('error', 'Cannot Create Tax Rate');
|
|
|
|
|
|
|
|
|
|
return redirect()->back();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return redirect()->back();
|
|
|
|
|
}
|
|
|
|
|
}
|