Introduce option model for storing necessary configuration data.

This commit is contained in:
2025-01-04 18:37:29 +01:00
parent 3b51ab109d
commit fa085b7384
10 changed files with 412 additions and 2 deletions

View File

@@ -0,0 +1,33 @@
<?php
namespace App\Http\Controllers\Api;
use App\Http\Controllers\Controller;
use App\Models\Option;
use Illuminate\Http\Request;
use Illuminate\Http\JsonResponse;
class OptionController extends Controller
{
/**
* Display a listing of the resource.
*/
public function index(): JsonResponse
{
return response()->json(Option::all(['name', 'value']));
}
/**
* Store a newly created resource in storage.
*/
public function store(Request $request): JsonResponse
{
foreach ($request->all() as $key => $value) {
$option = Option::firstOrNew(['name' => $key]);
$option->value = $value;
$option->save();
}
return response()->json($request->all());
}
}

View File

@@ -0,0 +1,16 @@
<?php
namespace App\Http\Controllers;
use Illuminate\Contracts\View\View;
class OptionController extends Controller
{
/**
* Display a listing of the resource.
*/
public function index(): View
{
return view('option.index');
}
}

19
app/Models/Option.php Normal file
View File

@@ -0,0 +1,19 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class Option extends Model
{
/**
* The attributes that are mass assignable.
*
* @var array<int, string>
*/
protected $fillable = [
'name',
'value',
];
}

View File

@@ -0,0 +1,29 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('options', function (Blueprint $table) {
$table->id();
$table->string('name')->unique();
$table->longText('value')->nullable();
$table->timestamps();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('options');
}
};

View File

@@ -4,10 +4,10 @@ return [
/*
|------------------------------------------------- -------------------------
| Übersetzungen der Einstellungen
| Übersetzungen Konfigurationen
|------------------------------------------------- -------------------------
|
| Die folgenden Sprachzeilen werden für die Einstellungen verwendet.
| Die folgenden Sprachzeilen werden für allgemeine Einstellungen verwendet.
|
*/
@@ -23,5 +23,25 @@ return [
'Are you sure you want to delete this taxrate?' => 'Sicher, dass der Steuersatz gelöscht werden soll?',
'Once the taxrate is deleted, all of its resources and data will be permanently deleted.' => 'Sobald der Steuersatz gelöscht wird, werden alle Ressourcen und Daten dauerhaft gelöscht.',
'Enter your taxrate\'s information.' => 'Gib die Informationen des Steuersatzes ein.',
'Options' => 'Einstellungen',
'Company details' => 'Firmendaten',
'Company name' => 'Firmenname',
'Company additional' => 'Firmenzusatz',
'Representative' => 'gesetzlicher Vertreter',
'Address' => 'Adresse',
'Zip' => 'Postleitzahl',
'City' => 'Stadt',
'Phone' => 'Telefon',
'Email' => 'E-Mail',
'Website' => 'Webseite',
'Tax number' => 'Steuernummer',
'Jurisdiction' => 'Gerichtsstand',
'Bank details' => 'Bankverbindung',
'Institute' => 'Institut',
'BIC' => 'BIC',
'IBAN' => 'IBAN',
'Correspondence' => 'Schriftverkehr',
'Color' => 'Farbe',
'Company logo' => 'Firmenlogo',
];

View File

@@ -15,6 +15,7 @@ return [
'Edit' => 'Bearbeiten',
'Delete' => 'Löschen',
'Save' => 'Speichern',
'Change' => 'Ändern',
'SaveAndContinue' => 'Speichern und Weiter',
'Saved' => 'Gespeichert',
'Cancel' => 'Abbrechen',

View File

@@ -27,6 +27,10 @@
:active="\Illuminate\Support\Str::startsWith(request()->route()->getName(), 'taxrate.')">
{{ __('configuration.Taxrates') }}
</x-nav-link>
<x-nav-link :href="route('option.index')"
:active="\Illuminate\Support\Str::startsWith(request()->route()->getName(), 'option.')">
{{ __('configuration.Options') }}
</x-nav-link>
</div>
</div>

View File

@@ -0,0 +1,283 @@
<x-app-layout>
<x-slot name="header">
<h2 class="font-semibold text-xl text-gray-800 dark:text-gray-200 leading-tight">
{{ __('configuration.Options') }}
</h2>
</x-slot>
<div class="py-12" x-data="optionForm">
<div class="max-w-7xl mx-auto sm:px-6 lg:px-8 space-y-6">
<!-- Company details -->
<div class="p-4 sm:p-8 bg-white dark:bg-gray-800 shadow sm:rounded-lg">
<div class="max-w">
<section>
<details>
<summary class="text-lg font-medium text-gray-900 dark:text-gray-100 cursor-pointer">
{{ __('configuration.Company details') }}
</summary>
<form class="mt-6 space-y-2" @submit.prevent="">
<p class="text-red-600 font-bold" x-text="message" x-show="error"></p>
<div class="flex flex-row items-start">
<x-input-label class="w-1/4" for="company_logo"
:value="__('configuration.Company logo')"/>
<x-text-input id="company_logo" name="company_logo" type="file"
class="mt-1 block w-full"
x-show="options.company_logo == null"
@change="updatePreview()"/>
<div class="w-full flex flex-row" x-show="options.company_logo != null">
<img class="w-1/4" :src="options.company_logo"/>
<div class="ml-12">
<x-primary-button class=""
@click="clearPreview()">{{ __('form.Change') }}</x-primary-button>
</div>
</div>
</div>
<div class="flex flex-row items-center">
<x-input-label class="w-1/4" for="company_name"
:value="__('configuration.Company name')"/>
<x-text-input id="company_name" name="company_name" type="text"
class="mt-1 block w-full"
:value="old('company_name')" required autofocus
autocomplete="company_name"
x-model="options.company_name"/>
</div>
<div class="flex flex-row items-center">
<x-input-label class="w-1/4" for="company_additional"
:value="__('configuration.Company additional')"/>
<x-text-input id="company_additional" name="company_additional" type="text"
class="mt-1 block w-full"
:value="old('company_additional')" autofocus
autocomplete="company_additional"
x-model="options.company_additional"/>
</div>
<div class="flex flex-row items-center">
<x-input-label class="w-1/4" for="representative"
:value="__('configuration.Representative')"/>
<x-text-input id="representative" name="representative" type="text"
class="mt-1 block w-full"
:value="old('representative')" required autofocus
autocomplete="representative"
x-model="options.representative"/>
</div>
<div class="flex flex-row items-center">
<x-input-label class="w-1/4" for="address" :value="__('configuration.Address')"/>
<x-text-input id="address" name="address" type="text" class="mt-1 block w-full"
:value="old('address')" required autofocus autocomplete="address"
x-model="options.address"/>
</div>
<div class="flex flex-row items-center">
<x-input-label class="w-1/4" for="zip" :value="__('configuration.Zip')"/>
<x-text-input id="zip" name="zip" type="text" class="mt-1 block w-full"
:value="old('zip')" required autofocus autocomplete="zip"
x-model="options.zip"/>
</div>
<div class="flex flex-row items-center">
<x-input-label class="w-1/4" for="city" :value="__('configuration.City')"/>
<x-text-input id="city" name="city" type="text" class="mt-1 block w-full"
:value="old('city')" required autofocus autocomplete="city"
x-model="options.city"/>
</div>
<div class="flex flex-row items-center">
<x-input-label class="w-1/4" for="phone" :value="__('configuration.Phone')"/>
<x-text-input id="phone" name="phone" type="text" class="mt-1 block w-full"
:value="old('phone')" autofocus autocomplete="phone"
x-model="options.phone"/>
</div>
<div class="flex flex-row items-center">
<x-input-label class="w-1/4" for="email" :value="__('configuration.Email')"/>
<x-text-input id="email" name="email" type="email" class="mt-1 block w-full"
:value="old('email')" required autofocus autocomplete="email"
x-model="options.email"/>
</div>
<div class="flex flex-row items-center">
<x-input-label class="w-1/4" for="website" :value="__('configuration.Website')"/>
<x-text-input id="website" name="website" type="url" class="mt-1 block w-full"
:value="old('website')" autofocus autocomplete="website"
x-model="options.website"/>
</div>
<div class="flex flex-row items-center">
<x-input-label class="w-1/4" for="tax_number"
:value="__('configuration.Tax number')"/>
<x-text-input id="tax_number" name="tax_number" type="text"
class="mt-1 block w-full"
:value="old('tax_number')" required autofocus
autocomplete="tax_number"
x-model="options.tax_number"/>
</div>
<div class="flex flex-row items-center">
<x-input-label class="w-1/4" for="jurisdiction"
:value="__('configuration.Jurisdiction')"/>
<x-text-input id="jurisdiction" name="jurisdiction" type="text"
class="mt-1 block w-full"
:value="old('jurisdiction')" required autofocus
autocomplete="jurisdiction"
x-model="options.jurisdiction"/>
</div>
</form>
</details>
</section>
</div>
</div>
<!-- Bank details -->
<div class="p-4 sm:p-8 bg-white dark:bg-gray-800 shadow sm:rounded-lg">
<div class="max-w">
<section>
<details>
<summary class="text-lg font-medium text-gray-900 dark:text-gray-100 cursor-pointer">
{{ __('configuration.Bank details') }}
</summary>
<form class="mt-6 space-y-2" @submit.prevent="">
<div class="flex flex-row items-center">
<x-input-label class="w-1/4" for="institute_1"
:value="__('configuration.Institute'). ' 1'"/>
<x-text-input id="institute_1" name="institute_1" type="text"
class="mt-1 block w-full"
:value="old('institute_1')" required autofocus
autocomplete="institute_1"
x-model="options.institute_1"/>
</div>
<div class="flex flex-row items-center">
<x-input-label class="w-1/4" for="bic_1"
:value="__('configuration.BIC'). ' 1'"/>
<x-text-input id="bic_1" name="bic_1" type="text"
class="mt-1 block w-full"
:value="old('bic_1')" required autofocus
autocomplete="bic_1"
x-model="options.bic_1"/>
</div>
<div class="flex flex-row items-center">
<x-input-label class="w-1/4" for="iban_1"
:value="__('configuration.IBAN'). ' 1'"/>
<x-text-input id="iban_1" name="iban_1" type="text"
class="mt-1 block w-full"
:value="old('iban_1')" required autofocus
autocomplete="iban_1"
x-model="options.iban_1"/>
</div>
<div class="flex flex-row items-center">
<x-input-label class="w-1/4" for="institute_2"
:value="__('configuration.Institute'). ' 2'"/>
<x-text-input id="institute_2" name="institute_2" type="text"
class="mt-1 block w-full"
:value="old('institute_2')" required autofocus
autocomplete="institute_2"
x-model="options.institute_2"/>
</div>
<div class="flex flex-row items-center">
<x-input-label class="w-1/4" for="bic_2"
:value="__('configuration.BIC'). ' 2'"/>
<x-text-input id="bic_2" name="bic_2" type="text"
class="mt-1 block w-full"
:value="old('bic_2')" required autofocus
autocomplete="bic_2"
x-model="options.bic_2"/>
</div>
<div class="flex flex-row items-center">
<x-input-label class="w-1/4" for="iban_2"
:value="__('configuration.IBAN'). ' 2'"/>
<x-text-input id="iban_2" name="iban_2" type="text"
class="mt-1 block w-full"
:value="old('iban_2')" required autofocus
autocomplete="iban_2"
x-model="options.iban_2"/>
</div>
</form>
</details>
</section>
</div>
</div>
<!-- correspondence -->
<div class="p-4 sm:p-8 bg-white dark:bg-gray-800 shadow sm:rounded-lg">
<div class="max-w">
<section>
<details>
<summary class="text-lg font-medium text-gray-900 dark:text-gray-100 cursor-pointer">
{{ __('configuration.Correspondence') }}
</summary>
<form class="mt-6 space-y-2" @submit.prevent="">
<div class="flex flex-row items-center">
<x-input-label class="w-1/4" for="color_1"
:value="__('configuration.Color'). ' 1'"/>
<x-text-input id="color_1" name="color_1" type="color"
class="mt-1 block"
:value="old('color_1')" required autofocus
autocomplete="color_1"
x-model="options.color_1"/>
</div>
<div class="flex flex-row items-center">
<x-input-label class="w-1/4" for="color_2"
:value="__('configuration.Color'). ' 2'"/>
<x-text-input id="color_2" name="color_2" type="color"
class="mt-1 block"
:value="old('color_2')" required autofocus
autocomplete="color_2"
x-model="options.color_2"/>
</div>
</form>
</details>
</section>
</div>
</div>
<div class="flex items-center gap-4">
<x-primary-button @click="submit">{{ __('form.Save') }}</x-primary-button>
</div>
</div>
</div>
</x-app-layout>
<script>
function optionForm() {
return {
options: {},
error: false,
message: '',
init() {
let vm = this;
axios.get('/option')
.then(function (response) {
response.data.forEach((value) => {
vm.options[value.name] = value.value;
});
})
},
updatePreview() {
let reader, files = document.getElementById('company_logo').files;
reader = new FileReader();
reader.onload = e => {
this.options.company_logo = e.target.result;
console.log(e.target.result);
};
reader.readAsDataURL(files[0]);
},
clearPreview() {
this.options.company_logo = null;
},
submit() {
let vm = this;
console.log(vm.options);
axios.post('/option', vm.options)
.then(function (response) {
console.log(response.data);
})
.catch(function (error) {
console.log(error);
})
}
}
}
</script>

View File

@@ -5,6 +5,7 @@ use App\Http\Controllers\Api\AuthController;
use App\Http\Controllers\Api\CustomerController;
use App\Http\Controllers\Api\InvoiceController;
use App\Http\Controllers\Api\InvoiceitemController;
use App\Http\Controllers\Api\OptionController;
use App\Http\Controllers\Api\TaxrateController;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Route;
@@ -26,6 +27,8 @@ Route::group(['as' => 'api.'], function () {
Route::apiResource('/taxrate', TaxRateController::class)->except(['show']);
Route::get('/invoice/{start?}/{end?}', [InvoiceController::class, 'index'])->name('invoice.index');
Route::apiResource('/invoice.item', InvoiceItemController::class)->shallow();
Route::get('/option', [OptionController::class, 'index'])->name('option.index');
Route::post('/option', [OptionController::class, 'store'])->name('option.store');
});
});

View File

@@ -2,6 +2,7 @@
use App\Http\Controllers\CustomerController;
use App\Http\Controllers\InvoiceController;
use App\Http\Controllers\OptionController;
use App\Http\Controllers\ProfileController;
use App\Http\Controllers\TaxrateController;
use Illuminate\Support\Facades\Route;
@@ -22,6 +23,7 @@ Route::middleware('auth')->group(function () {
Route::resource('/customer', CustomerController::class)->only(['index', 'create', 'edit']);
Route::resource('/taxrate', TaxrateController::class)->only(['index', 'create', 'edit']);
Route::resource('/invoice', InvoiceController::class)->only(['index', 'create', 'show', 'edit']);
Route::get('/option', [OptionController::class, 'index'])->name('option.index');
});
require __DIR__.'/auth.php';