Build everything to deal with tax rates.
This commit is contained in:
61
app/Http/Controllers/Api/TaxrateController.php
Normal file
61
app/Http/Controllers/Api/TaxrateController.php
Normal file
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Taxrate;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class TaxrateController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
return response()->json(Taxrate::all());
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
$taxData = $request->validate([
|
||||
'name' => 'required|string',
|
||||
'rate' => 'required|numeric',
|
||||
'active' => 'required|boolean'
|
||||
]);
|
||||
|
||||
$tax = new Taxrate($taxData);
|
||||
$tax->save();
|
||||
|
||||
return response()->json($tax);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*/
|
||||
public function update(Request $request, Taxrate $taxrate)
|
||||
{
|
||||
$taxData = $request->validate([
|
||||
'name' => 'required|string',
|
||||
'rate' => 'required|numeric',
|
||||
'active' => 'required|boolean'
|
||||
]);
|
||||
|
||||
$taxrate->update($taxData);
|
||||
|
||||
return response()->json($taxrate);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*/
|
||||
public function destroy(Taxrate $taxrate)
|
||||
{
|
||||
$taxrate->delete();
|
||||
|
||||
return response()->json();
|
||||
}
|
||||
}
|
||||
32
app/Http/Controllers/TaxrateController.php
Normal file
32
app/Http/Controllers/TaxrateController.php
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\Taxrate;
|
||||
|
||||
class TaxrateController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
return view('taxrate.index');
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
return view('taxrate.create');
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*/
|
||||
public function edit(Taxrate $taxrate)
|
||||
{
|
||||
return view('taxrate.edit', ['taxrate' => $taxrate]);
|
||||
}
|
||||
}
|
||||
@@ -4,8 +4,28 @@ namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
use Illuminate\Support\Number;
|
||||
|
||||
class Taxrate extends Model
|
||||
{
|
||||
use SoftDeletes;
|
||||
|
||||
protected $fillable = [
|
||||
'name',
|
||||
'rate',
|
||||
'active',
|
||||
];
|
||||
|
||||
/**
|
||||
* The attributes that are appended with attribute getters.
|
||||
*
|
||||
* @var string[]
|
||||
*/
|
||||
protected $appends = [
|
||||
'rate_percentage',
|
||||
];
|
||||
public function getRatePercentageAttribute()
|
||||
{
|
||||
return Number::percentage($this->rate, 2, 8, 'de');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user