Invoice-Settings in new Settingsformat

This commit is contained in:
1Day 2022-01-05 10:32:17 +01:00
parent 41d79186bd
commit 39177651a3
12 changed files with 110 additions and 134 deletions

View file

@ -2,9 +2,8 @@
namespace App\Classes\Settings;
use App\Models\InvoiceSettings;
use App\Models\Settings;
use Illuminate\Http\Request;
use ZipArchive;
class InvoiceSettingsC
{
@ -13,7 +12,7 @@ class InvoiceSettingsC
public function __construct()
{
$this->invoiceSettings = InvoiceSettings::first();
return;
}
@ -23,17 +22,30 @@ class InvoiceSettingsC
'logo' => 'nullable|max:10000|mimes:jpg,png,jpeg',
]);
InvoiceSettings::updateOrCreate([
'id' => "1"
], [
'company_name' => $request->get('company-name'),
'company_adress' => $request->get('company-address'),
'company_phone' => $request->get('company-phone'),
'company_mail' => $request->get('company-mail'),
'company_vat' => $request->get('company-vat'),
'company_web' => $request->get('company-web'),
'invoice_prefix' => $request->get('invoice-prefix'),
]);
$name = Settings::find("SETTINGS::INVOICE:COMPANY_NAME");
$address = Settings::find("SETTINGS::INVOICE:COMPANY_ADDRESS");
$phone = Settings::find("SETTINGS::INVOICE:COMPANY_PHONE");
$mail = Settings::find("SETTINGS::INVOICE:COMPANY_MAIL");
$vat = Settings::find("SETTINGS::INVOICE:COMPANY_VAT");
$web = Settings::find("SETTINGS::INVOICE:COMPANY_WEBSITE");
$prefix = Settings::find("SETTINGS::INVOICE:PREFIX");
$name->value=$request->get('company-name');
$address->value=$request->get('company-address');
$phone->value=$request->get('company-phone');
$mail->value=$request->get('company-mail');
$vat->value=$request->get('company-vat');
$web->value=$request->get('company-web');
$prefix->value=$request->get('invoice-prefix');
$name->save();
$address->save();
$phone->save();
$mail->save();
$vat->save();
$web->save();
$prefix->save();
if ($request->hasFile('logo')) {
$request->file('logo')->storeAs('public', 'logo.png');

View file

@ -16,7 +16,7 @@ class InvoiceController extends Controller
$zip = new ZipArchive;
$zip_safe_path = storage_path('invoices.zip');
$res = $zip->open($zip_safe_path, ZipArchive::CREATE | ZipArchive::OVERWRITE);
$result = $this::rglob(storage_path('app/invoice/*'));
$result = $dthis::rglob(storage_path('app/invoice/*'));
if ($res === TRUE) {
$zip->addFromString("1. Info.txt", __("Created at") . " " . now()->format("d.m.Y"));
foreach ($result as $file) {

View file

@ -495,17 +495,16 @@ class PaymentController extends Controller
//create invoice
$lastInvoiceID = \App\Models\Invoice::where("invoice_name", "like", "%" . now()->format('mY') . "%")->count("id");
$newInvoiceID = $lastInvoiceID + 1;
$InvoiceSettings = InvoiceSettings::query()->first();
$logoPath = storage_path('app/public/logo.png');
$seller = new Party([
'name' => $InvoiceSettings->company_name,
'phone' => $InvoiceSettings->company_phone,
'address' => $InvoiceSettings->company_adress,
'vat' => $InvoiceSettings->company_vat,
'name' => Settings::getValueByKey("SETTINGS::INVOICE:COMPANY_NAME"),
'phone' => Settings::getValueByKey("SETTINGS::INVOICE:COMPANY_PHONE"),
'address' => Settings::getValueByKey("SETTINGS::INVOICE:COMPANY_ADDRESS"),
'vat' => Settings::getValueByKey("SETTINGS::INVOICE:COMPANY_VAT"),
'custom_fields' => [
'E-Mail' => $InvoiceSettings->company_mail,
"Web" => $InvoiceSettings->company_web
'E-Mail' => Settings::getValueByKey("SETTINGS::INVOICE:COMPANY_MAIL"),
"Web" => Settings::getValueByKey("SETTINGS::INVOICE:COMPANY_WEBSITE")
],
]);
@ -540,7 +539,7 @@ class PaymentController extends Controller
->series(now()->format('mY'))
->delimiter("-")
->sequence($newInvoiceID)
->serialNumberFormat($InvoiceSettings->invoice_prefix . '{DELIMITER}{SERIES}{SEQUENCE}')
->serialNumberFormat(Settings::getValueByKey("SETTINGS::INVOICE:PREFIX") . '{DELIMITER}{SERIES}{SEQUENCE}')
->notes($notes);
if (file_exists($logoPath)) {

View file

@ -3,7 +3,6 @@
namespace App\Http\Controllers\Admin\SettingsControllers;
use App\Http\Controllers\Controller;
use App\Models\InvoiceSettings;
use App\Models\Settings;
use Illuminate\Contracts\Foundation\Application;
use Illuminate\Contracts\View\Factory;
@ -60,31 +59,7 @@ class SettingsController extends Controller
return redirect()->route('admin.settings.index')->with('success', __('Icons updated!'));
}
public function updateInvoiceSettings(Request $request)
{
$request->validate([
'logo' => 'nullable|max:10000|mimes:jpg,png,jpeg',
]);
InvoiceSettings::updateOrCreate([
'id' => "1"
], [
'company_name' => $request->get('company-name'),
'company_adress' => $request->get('company-address'),
'company_phone' => $request->get('company-phone'),
'company_mail' => $request->get('company-mail'),
'company_vat' => $request->get('company-vat'),
'company_web' => $request->get('company-web'),
'invoice_prefix' => $request->get('invoice-prefix'),
]);
if ($request->hasFile('logo')) {
$request->file('logo')->storeAs('public', 'logo.png');
}
return redirect()->route('admin.settings.index')->with('success', 'Invoice settings updated!');
}
public function updatevalue(Request $request)
{

View file

@ -1,23 +0,0 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class InvoiceSettings extends Model
{
use HasFactory;
protected $table = 'invoice_settings';
protected $fillable = [
'company_name',
'company_adress',
'company_phone',
'company_mail',
'company_vat',
'company_web',
'invoice_prefix'
];
}

View file

@ -10,6 +10,8 @@ class Settings extends Model
{
use HasFactory;
protected $table = 'settings';
public const CACHE_TAG = 'setting';
public $primaryKey = 'key';

View file

@ -1,48 +0,0 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;
class InvoiceSettings extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('invoice_settings', function (Blueprint $table) {
$table->id();
$table->string('company_name')->nullable();
$table->string('company_adress')->nullable();
$table->string('company_phone')->nullable();
$table->string('company_vat')->nullable();
$table->string('company_mail')->nullable();
$table->string('company_web')->nullable()->default(env("APP_URL",""));
$table->string('invoice_prefix')->nullable();
$table->timestamps();
});
DB::table('invoice_settings')->insert(
array(
'company_name' => env("APP_NAME","MyCompany"),
'company_web' => env("APP_URL",""),
'invoice_prefix' => "INV"
)
);
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('invoice_settings');
}
}

View file

@ -4,7 +4,7 @@ use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class Settings extends Migration
class CreateSettingsTable extends Migration
{
/**
* Run the migrations.
@ -16,7 +16,7 @@ class Settings extends Migration
Schema::create('settings', function (Blueprint $table) {
$table->id();
$table->string('key');
$table->string('value');
$table->string('value')->nullable();
$table->string('type');
$table->string('description');
$table->timestamps();

View file

@ -3,7 +3,6 @@
namespace Database\Seeders;
use Database\Seeders\Seeds\SettingsSeeder;
use Database\Seeders\Seeds\InvoiceSettingsSeeder;
use Illuminate\Database\Seeder;
class DatabaseSeeder extends Seeder

View file

@ -145,5 +145,65 @@ class SettingsSeeder extends Seeder
'description' => 'The %-value of tax that will be added to the product price on checkout'
]);
//Invoice company name
Settings::firstOrCreate([
'key' => 'SETTINGS::INVOICE:COMPANY_NAME',
], [
'value' => '',
'type' => 'string',
'description' => 'The name of the Company on the Invoices'
]);
//Invoice company address
Settings::firstOrCreate([
'key' => 'SETTINGS::INVOICE:COMPANY_ADDRESS',
], [
'value' => '',
'type' => 'string',
'description' => 'The address of the Company on the Invoices'
]);
//Invoice company phone
Settings::firstOrCreate([
'key' => 'SETTINGS::INVOICE:COMPANY_PHONE',
], [
'value' => '',
'type' => 'string',
'description' => 'The phone number of the Company on the Invoices'
]);
//Invoice company mail
Settings::firstOrCreate([
'key' => 'SETTINGS::INVOICE:COMPANY_MAIL',
], [
'value' => '',
'type' => 'string',
'description' => 'The email address of the Company on the Invoices'
]);
//Invoice VAT
Settings::firstOrCreate([
'key' => 'SETTINGS::INVOICE:COMPANY_VAT',
], [
'value' => '',
'type' => 'string',
'description' => 'The VAT-Number of the Company on the Invoices'
]);
//Invoice Website
Settings::firstOrCreate([
'key' => 'SETTINGS::INVOICE:COMPANY_WEBSITE',
], [
'value' => '',
'type' => 'string',
'description' => 'The Website of the Company on the Invoices'
]);
//Invoice Website
Settings::firstOrCreate([
'key' => 'SETTINGS::INVOICE:PREFIX',
], [
'value' => 'INV',
'type' => 'string',
'description' => 'The invoice prefix'
]);
}
}

View file

@ -1,4 +1,5 @@
@inject('Invoices', 'App\Classes\Settings\InvoiceSettingsC')
@inject('Settings', 'App\Models\Settings')
<div class="tab-pane mt-3" id="invoice">
<form method="POST" enctype="multipart/form-data" class="mb-3"
@ -12,8 +13,8 @@
<div class="form-group">
<div class="custom-control mb-3">
<label for="company-name">{{ __('Enter your companys name') }}</label>
<input x-model="company-name" id="company-name" name="company-name" type="text"
value="{{ $Invoices->invoiceSettings->company_name }}"
<input x-model="company-name" id="company-name" name="company-name" type="text" required
value="{{ App\Models\Settings::getValueByKey("SETTINGS::INVOICE:COMPANY_NAME") }}"
class="form-control @error('company-name') is-invalid @enderror">
</div>
</div>
@ -22,7 +23,7 @@
<div class="custom-control mb-3">
<label for="company-address">{{ __('Enter your companys address') }}</label>
<input x-model="company-address" id="company-address" name="company-address" type="text"
value="{{ $Invoices->invoiceSettings->company_address }}"
value="{{ App\Models\Settings::getValueByKey("SETTINGS::INVOICE:COMPANY_ADDRESS") }}"
class="form-control @error('company-address') is-invalid @enderror">
</div>
</div>
@ -31,7 +32,7 @@
<div class="custom-control mb-3">
<label for="company-phone">{{ __('Enter your companys phone number') }}</label>
<input x-model="company-phone" id="company-phone" name="company-phone" type="text"
value="{{ $Invoices->invoiceSettings->company_phone }}"
value="{{ App\Models\Settings::getValueByKey("SETTINGS::INVOICE:COMPANY_PHONE") }}"
class="form-control @error('company-phone') is-invalid @enderror">
</div>
</div>
@ -41,7 +42,7 @@
<div class="custom-control mb-3">
<label for="company-vat">{{ __('Enter your companys VAT id') }}</label>
<input x-model="company-vat" id="company-vat" name="company-vat" type="text"
value="{{ $Invoices->invoiceSettings->company_vat }}"
value="{{ App\Models\Settings::getValueByKey("SETTINGS::INVOICE:COMPANY_VAT") }}"
class="form-control @error('company-vat') is-invalid @enderror">
</div>
</div>
@ -52,7 +53,7 @@
<div class="custom-control mb-3">
<label for="company-mail">{{ __('Enter your companys email address') }}</label>
<input x-model="company-mail" id="company-mail" name="company-mail" type="text"
value="{{ $Invoices->invoiceSettings->company_mail }}"
value="{{ App\Models\Settings::getValueByKey("SETTINGS::INVOICE:COMPANY_MAIL") }}"
class="form-control @error('company-mail') is-invalid @enderror">
</div>
</div>
@ -61,17 +62,17 @@
<div class="custom-control mb-3">
<label for="company-web">{{ __('Enter your companys website') }}</label>
<input x-model="company-web" id="company-web" name="company-web" type="text"
value="{{ $Invoices->invoiceSettings->company_web }}"
value="{{ App\Models\Settings::getValueByKey("SETTINGS::INVOICE:COMPANY_WEBSITE") }}"
class="form-control @error('company-web') is-invalid @enderror">
</div>
</div>
<!-- website -->
<!-- prefix -->
<div class="form-group">
<div class="custom-control mb-3">
<label for="invoice-prefix">{{ __('Enter your custom invoice prefix') }}</label>
<input x-model="invoice-prefix" id="invoice-prefix" name="invoice-prefix" type="text"
value="{{ $Invoices->invoiceSettings->invoice_prefix }}"
<input x-model="invoice-prefix" id="invoice-prefix" name="invoice-prefix" type="text" required
value="{{ App\Models\Settings::getValueByKey("SETTINGS::INVOICE:PREFIX") }}"
class="form-control @error('invoice-prefix') is-invalid @enderror">
</div>
</div>
@ -89,7 +90,6 @@
</div>
@error('logo')
<span class="text-danger">
{{ $Invoices->invoiceSettings->message }}
</span>
@enderror
</div>

View file

@ -131,7 +131,7 @@ Route::middleware(['auth', 'checkSuspended'])->group(function () {
#settings
Route::patch('settings/update/icons', [SettingsController::class, 'updateIcons'])->name('settings.update.icons');
Route::patch('settings/update/invoice-settings', [SettingsController::class, 'updateInvoiceSettings'])->name('settings.update.invoicesettings');
Route::patch('settings/update/invoice-settings', [\App\Classes\Settings\InvoiceSettingsC::class, 'updateInvoiceSettings'])->name('settings.update.invoicesettings');
Route::patch('settings/update/lagnguage', [SettingsController::class, 'updateLanguageSettings'])->name('settings.update.languagesettings');
Route::resource('settings', SettingsController::class)->only('index');