From 39177651a324a36b74cc80fe47657f66e0e9a3de Mon Sep 17 00:00:00 2001 From: 1Day Date: Wed, 5 Jan 2022 10:32:17 +0100 Subject: [PATCH] Invoice-Settings in new Settingsformat --- app/Classes/Settings/InvoiceSettingsC.php | 40 ++++++++----- .../Controllers/Admin/InvoiceController.php | 2 +- .../Controllers/Admin/PaymentController.php | 15 +++-- .../SettingsController.php | 25 -------- app/Models/InvoiceSettings.php | 23 ------- app/Models/Settings.php | 2 + .../2021_12_1_174440_invoice-settings.php | 48 --------------- ...22_01_05_071040_create_settings_table.php} | 4 +- database/seeders/DatabaseSeeder.php | 1 - database/seeders/Seeds/SettingsSeeder.php | 60 +++++++++++++++++++ .../admin/settings/tabs/invoice.blade.php | 22 +++---- routes/web.php | 2 +- 12 files changed, 110 insertions(+), 134 deletions(-) delete mode 100644 app/Models/InvoiceSettings.php delete mode 100644 database/migrations/2021_12_1_174440_invoice-settings.php rename database/migrations/{2022_01_05_071039_settings.php => 2022_01_05_071040_create_settings_table.php} (87%) diff --git a/app/Classes/Settings/InvoiceSettingsC.php b/app/Classes/Settings/InvoiceSettingsC.php index d4726e6a..1f43b745 100644 --- a/app/Classes/Settings/InvoiceSettingsC.php +++ b/app/Classes/Settings/InvoiceSettingsC.php @@ -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'); diff --git a/app/Http/Controllers/Admin/InvoiceController.php b/app/Http/Controllers/Admin/InvoiceController.php index bc20ef4c..381d7385 100644 --- a/app/Http/Controllers/Admin/InvoiceController.php +++ b/app/Http/Controllers/Admin/InvoiceController.php @@ -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) { diff --git a/app/Http/Controllers/Admin/PaymentController.php b/app/Http/Controllers/Admin/PaymentController.php index a08dddc7..7c0ed360 100644 --- a/app/Http/Controllers/Admin/PaymentController.php +++ b/app/Http/Controllers/Admin/PaymentController.php @@ -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)) { diff --git a/app/Http/Controllers/Admin/SettingsControllers/SettingsController.php b/app/Http/Controllers/Admin/SettingsControllers/SettingsController.php index 7fe6df3f..4dd493e5 100644 --- a/app/Http/Controllers/Admin/SettingsControllers/SettingsController.php +++ b/app/Http/Controllers/Admin/SettingsControllers/SettingsController.php @@ -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) { diff --git a/app/Models/InvoiceSettings.php b/app/Models/InvoiceSettings.php deleted file mode 100644 index c246f165..00000000 --- a/app/Models/InvoiceSettings.php +++ /dev/null @@ -1,23 +0,0 @@ -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'); - } -} diff --git a/database/migrations/2022_01_05_071039_settings.php b/database/migrations/2022_01_05_071040_create_settings_table.php similarity index 87% rename from database/migrations/2022_01_05_071039_settings.php rename to database/migrations/2022_01_05_071040_create_settings_table.php index d7c0a52a..92070000 100644 --- a/database/migrations/2022_01_05_071039_settings.php +++ b/database/migrations/2022_01_05_071040_create_settings_table.php @@ -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(); diff --git a/database/seeders/DatabaseSeeder.php b/database/seeders/DatabaseSeeder.php index 25db0f88..e759a595 100644 --- a/database/seeders/DatabaseSeeder.php +++ b/database/seeders/DatabaseSeeder.php @@ -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 diff --git a/database/seeders/Seeds/SettingsSeeder.php b/database/seeders/Seeds/SettingsSeeder.php index 6e57b1fc..499349f1 100644 --- a/database/seeders/Seeds/SettingsSeeder.php +++ b/database/seeders/Seeds/SettingsSeeder.php @@ -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' + ]); } } diff --git a/resources/views/admin/settings/tabs/invoice.blade.php b/resources/views/admin/settings/tabs/invoice.blade.php index eb9cdbf7..07e1f0cf 100644 --- a/resources/views/admin/settings/tabs/invoice.blade.php +++ b/resources/views/admin/settings/tabs/invoice.blade.php @@ -1,4 +1,5 @@ @inject('Invoices', 'App\Classes\Settings\InvoiceSettingsC') +@inject('Settings', 'App\Models\Settings')
-
@@ -22,7 +23,7 @@
@@ -31,7 +32,7 @@
@@ -41,7 +42,7 @@
@@ -52,7 +53,7 @@
@@ -61,17 +62,17 @@
- +
-
@@ -89,7 +90,6 @@ @error('logo') - {{ $Invoices->invoiceSettings->message }} @enderror diff --git a/routes/web.php b/routes/web.php index fa2a79af..14da9680 100644 --- a/routes/web.php +++ b/routes/web.php @@ -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');