From c8071b64d9a4a0b371fa34198ba68d03ac8ad295 Mon Sep 17 00:00:00 2001 From: IceToast Date: Sat, 15 Jan 2022 17:52:19 +0100 Subject: [PATCH] =?UTF-8?q?feat:=20=E2=9C=A8=20Added=20Enable/Disable=20In?= =?UTF-8?q?voices?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Classes/Settings/Invoices.php | 3 ++- .../Controllers/Admin/PaymentController.php | 25 ++++++++++++++----- database/seeders/Seeds/SettingsSeeder.php | 8 +++++- .../admin/settings/tabs/invoices.blade.php | 9 +++++++ 4 files changed, 37 insertions(+), 8 deletions(-) diff --git a/app/Classes/Settings/Invoices.php b/app/Classes/Settings/Invoices.php index b19bb6e3..425af60c 100644 --- a/app/Classes/Settings/Invoices.php +++ b/app/Classes/Settings/Invoices.php @@ -28,7 +28,8 @@ class Invoices "SETTINGS::INVOICE:COMPANY_MAIL" => "company-mail", "SETTINGS::INVOICE:COMPANY_VAT" => "company-vat", "SETTINGS::INVOICE:COMPANY_WEBSITE" => "company-web", - "SETTINGS::INVOICE:PREFIX" => "invoice-prefix" + "SETTINGS::INVOICE:PREFIX" => "invoice-prefix", + "SETTINGS::INVOICE:ENABLED" => "enable-invoices", ]; foreach ($values as $key => $value) { diff --git a/app/Http/Controllers/Admin/PaymentController.php b/app/Http/Controllers/Admin/PaymentController.php index 7efaaa35..9a65aa4b 100644 --- a/app/Http/Controllers/Admin/PaymentController.php +++ b/app/Http/Controllers/Admin/PaymentController.php @@ -197,7 +197,11 @@ class PaymentController extends Controller event(new UserUpdateCreditsEvent($user)); - $this->createInvoice($user, $payment, 'paid'); + //only create invoice if SETTINGS::INVOICE:ENABLE is true + if (config('SETTINGS::INVOICE:ENABLE') == 'true') { + $this->createInvoice($user, $payment, 'paid'); + } + //redirect back to home return redirect()->route('home')->with('success', __('Your credit balance has been increased!')); @@ -336,7 +340,10 @@ class PaymentController extends Controller event(new UserUpdateCreditsEvent($user)); - $this->createInvoice($user, $payment, 'paid'); + //only create invoice if SETTINGS::INVOICE:ENABLE is true + if (config('SETTINGS::INVOICE:ENABLE') == 'true') { + $this->createInvoice($user, $payment, 'paid'); + } //redirect back to home return redirect()->route('home')->with('success', __('Your credit balance has been increased!')); @@ -359,7 +366,10 @@ class PaymentController extends Controller 'credit_product_id' => $creditProduct->id, ]); - $this->createInvoice($user, $payment, 'processing'); + //only create invoice if SETTINGS::INVOICE:ENABLE is true + if (config('SETTINGS::INVOICE:ENABLE') == 'true') { + $this->createInvoice($user, $payment, 'paid'); + } //redirect back to home return redirect()->route('home')->with('success', __('Your payment is being processed!')); @@ -416,7 +426,10 @@ class PaymentController extends Controller $user->notify(new ConfirmPaymentNotification($payment)); event(new UserUpdateCreditsEvent($user)); - $this->createInvoice($user, $payment, 'paid'); + //only create invoice if SETTINGS::INVOICE:ENABLE is true + if (config('SETTINGS::INVOICE:ENABLE') == 'true') { + $this->createInvoice($user, $payment, 'paid'); + } } } catch (HttpException $ex) { abort(422); @@ -521,7 +534,7 @@ class PaymentController extends Controller ->pricePerUnit($creditProduct->price); $notes = [ - __("Payment method") .": ". $payment->payment_method, + __("Payment method") . ": " . $payment->payment_method, ]; $notes = implode("
", $notes); @@ -591,7 +604,7 @@ class PaymentController extends Controller return $payment->created_at ? $payment->created_at->diffForHumans() : ''; }) ->addColumn('actions', function (Payment $payment) { - return ' + return ' '; }) ->rawColumns(['actions']) diff --git a/database/seeders/Seeds/SettingsSeeder.php b/database/seeders/Seeds/SettingsSeeder.php index 4b3fc001..b41462d6 100644 --- a/database/seeders/Seeds/SettingsSeeder.php +++ b/database/seeders/Seeds/SettingsSeeder.php @@ -144,7 +144,13 @@ class SettingsSeeder extends Seeder 'type' => 'integer', 'description' => 'The %-value of tax that will be added to the product price on checkout' ]); - + //Invoices enabled + Settings::firstOrCreate([ + 'key' => 'SETTINGS::INVOICE:ENABLED', + ], [ + 'value' => 'false', + 'type' => 'boolean', + ]); //Invoice company name Settings::firstOrCreate([ 'key' => 'SETTINGS::INVOICE:COMPANY_NAME', diff --git a/resources/views/admin/settings/tabs/invoices.blade.php b/resources/views/admin/settings/tabs/invoices.blade.php index f594ea04..27faef7c 100644 --- a/resources/views/admin/settings/tabs/invoices.blade.php +++ b/resources/views/admin/settings/tabs/invoices.blade.php @@ -76,6 +76,15 @@
+
+
+
+ + +
+
+