Tax Module completed
This commit is contained in:
parent
4cf6ab5f00
commit
888dfc6b0f
|
|
@ -188,7 +188,11 @@ return [
|
|||
'name' => 'Name',
|
||||
'code' => 'Code',
|
||||
'description' => 'Description',
|
||||
'select-taxrates' => 'Select Tax Rates'
|
||||
'select-taxrates' => 'Select Tax Rates',
|
||||
'edit' => [
|
||||
'title' => 'Edit Tax Rule',
|
||||
'edit-button-title' => 'Edit Rule'
|
||||
]
|
||||
],
|
||||
'taxrate' => [
|
||||
'title' => 'Add Tax Rate',
|
||||
|
|
|
|||
|
|
@ -70,7 +70,7 @@
|
|||
|
||||
<select multiple="multiple" v-validate="'required'" class="control" id="taxrates" name="taxrates[]" value="{{ old('taxrates') }}">
|
||||
@foreach($taxRates as $taxRate)
|
||||
<option value="{{$taxRate['id']}}">{{$taxRate['identifier']}}</option>
|
||||
<option value="{{ $taxRate['id'] }}">{{ $taxRate['identifier'] }}</option>
|
||||
@endforeach
|
||||
</select>
|
||||
|
||||
|
|
|
|||
|
|
@ -6,16 +6,15 @@
|
|||
|
||||
@section('content')
|
||||
<div class="content">
|
||||
{{-- {{ dd($data[0][0]) }} --}}
|
||||
<form method="POST" action="{{ route('admin.taxrule.update', $data[0][0]['id']) }}" @submit.prevent="onSubmit">
|
||||
<div class="page-header">
|
||||
<div class="page-title">
|
||||
<h1>{{ __('admin::app.configuration.taxrate.edit.title') }}</h1>
|
||||
<h1>{{ __('admin::app.configuration.taxrule.edit.title') }}</h1>
|
||||
</div>
|
||||
|
||||
<div class="page-action">
|
||||
<button type="submit" class="btn btn-lg btn-primary">
|
||||
{{ __('admin::app.configuration.taxrate.edit.edit-button-title') }}
|
||||
{{ __('admin::app.configuration.taxrule.edit.edit-button-title') }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -186,6 +186,12 @@ class Core
|
|||
return TaxCategory::findOrFail($id)->tax_rates;
|
||||
}
|
||||
|
||||
/**
|
||||
* To fetch all
|
||||
* tax rates.
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
public function getAllTaxRates() {
|
||||
return TaxRate::all();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -90,19 +90,7 @@ class TaxCategoryController extends Controller
|
|||
if($currentTaxRule = $this->taxRule->create(request()->input())) {
|
||||
$allTaxRules = $data['taxrates'];
|
||||
|
||||
foreach ($allTaxRules as $index => $taxRuleId) {
|
||||
$taxMap['tax_category_id'] = $currentTaxRule->id;
|
||||
|
||||
$taxMap['tax_rate_id'] = $taxRuleId;
|
||||
|
||||
if ($this->taxMap->create($taxMap)) {
|
||||
continue;
|
||||
} else {
|
||||
return redirect()->action('TaxCategoryController@performRollback',[
|
||||
'taxRuleId' => $taxRuleId
|
||||
]);
|
||||
}
|
||||
}
|
||||
$this->taxRule->onlyAttach($currentTaxRule->id, $allTaxRules);
|
||||
|
||||
session()->flash('success', 'New Tax Rule Created');
|
||||
|
||||
|
|
@ -160,24 +148,16 @@ class TaxCategoryController extends Controller
|
|||
$data['description'] = request()->input('description');
|
||||
|
||||
if($this->taxRate->update($data, $id)) {
|
||||
if($this->taxRate->sync(request()->input('taxrates'))) {
|
||||
session()->flash('success', 'Tax Category is successfully edited.');
|
||||
return redirect()->route($this->_config['redirect']);
|
||||
} else {
|
||||
session()->flash('error', 'Tax Rates cannot be synced.');
|
||||
return redirect()->back();
|
||||
}
|
||||
$this->taxRule->syncAndDetach($id, request()->input('taxrates'));
|
||||
|
||||
session()->flash('success', 'Tax Category is successfully edited.');
|
||||
|
||||
return redirect()->route($this->_config['redirect']);
|
||||
} else {
|
||||
session()->flash('error', 'Tax Category Cannot be Updated Successfully.');
|
||||
|
||||
return redirect()->back();
|
||||
}
|
||||
|
||||
// $taxRuleData = $this->taxRule->findOneByField('id', $id);
|
||||
|
||||
// $taxMapData = $this->taxMap->findByField('tax_rule_id', $id);
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -22,6 +22,6 @@ class TaxCategory extends Model
|
|||
|
||||
//for joining the two way pivot table
|
||||
public function tax_rates() {
|
||||
return $this->belongsToMany(TaxRate::class, 'tax_categories_tax_rates', 'tax_category_id');
|
||||
return $this->belongsToMany(TaxRate::class, 'tax_categories_tax_rates', 'tax_category_id')->withPivot('id');
|
||||
}
|
||||
}
|
||||
|
|
@ -37,6 +37,7 @@ class TaxCategoriesRepository extends Repository
|
|||
* @param array $data
|
||||
* @param $id
|
||||
* @param string $attribute
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function update(array $data, $id, $attribute = "id")
|
||||
|
|
@ -47,4 +48,35 @@ class TaxCategoriesRepository extends Repository
|
|||
|
||||
return $taxmap;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to attach
|
||||
* associations
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function onlyAttach($id, $taxRates) {
|
||||
|
||||
foreach($taxRates as $key => $value) {
|
||||
|
||||
$this->model->findOrFail($id)->tax_rates()->attach($id, ['tax_category_id' => $id, 'tax_rate_id' => $value]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Method to detach
|
||||
* and attach the
|
||||
* associations
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function syncAndDetach($id, $taxRates) {
|
||||
$this->model->findOrFail($id)->tax_rates()->detach();
|
||||
|
||||
foreach($taxRates as $key => $value) {
|
||||
$this->model->findOrFail($id)->tax_rates()->attach($id, ['tax_category_id' => $id, 'tax_rate_id' => $value]);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -121,7 +121,7 @@ class Product extends Model
|
|||
{
|
||||
return $this->belongsToMany(self::class, 'product_cross_sells');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param string $key
|
||||
*
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@ Route::group(['middleware' => ['web']], function () {
|
|||
|
||||
Route::view('/product', 'shop::store.product.details.home.index')->name('customer.product');
|
||||
|
||||
Route::view('/product/{slug}/review', 'shop::store.product.review.index')->name('customer.product.review');
|
||||
Route::view('/product/review', 'shop::store.product.review.index')->name('customer.product.review');
|
||||
|
||||
//customer account
|
||||
Route::prefix('account')->group(function () {
|
||||
|
|
|
|||
Loading…
Reference in New Issue