From 21b9d700355a329022e0c3f2c7937075bb2c9a2d Mon Sep 17 00:00:00 2001 From: 1day2die Date: Sat, 27 Nov 2021 02:47:36 +0100 Subject: [PATCH] invoice DB, counting up, format stuff --- .gitignore | 1 + .../Controllers/Admin/PaymentController.php | 24 ++++++-- app/Models/Invoice.php | 20 +++++++ app/Notifications/InvoiceNotification.php | 55 +++++++++++++++++++ .../2021_11_27_014226_create_invoices.php | 34 ++++++++++++ .../invoices/templates/default.blade.php | 1 + 6 files changed, 130 insertions(+), 5 deletions(-) create mode 100644 app/Models/Invoice.php create mode 100644 app/Notifications/InvoiceNotification.php create mode 100644 database/migrations/2021_11_27_014226_create_invoices.php diff --git a/.gitignore b/.gitignore index 9dd097b7..7639c9af 100644 --- a/.gitignore +++ b/.gitignore @@ -18,3 +18,4 @@ yarn-error.log .gitignore .env.dev .env.testing +public/vendor/invoices/logo.png diff --git a/app/Http/Controllers/Admin/PaymentController.php b/app/Http/Controllers/Admin/PaymentController.php index 826c8658..fb4d0526 100644 --- a/app/Http/Controllers/Admin/PaymentController.php +++ b/app/Http/Controllers/Admin/PaymentController.php @@ -10,6 +10,7 @@ use App\Models\PaypalProduct; use App\Models\Product; use App\Models\User; use App\Notifications\ConfirmPaymentNotification; +use App\Notifications\InvoiceNotification; use Exception; use Illuminate\Contracts\Foundation\Application; use Illuminate\Contracts\View\Factory; @@ -217,6 +218,9 @@ class PaymentController extends Controller ]); $item = (new InvoiceItem())->title($paypalProduct->description)->pricePerUnit($paypalProduct->price); + $lastInvoiceID = \App\Models\invoice::where("invoice_name","like","%".now()->format('M')."%")->max("id"); + $newInvoiceID = $lastInvoiceID + 1; + $invoice = Invoice::make() ->buyer($customer) ->seller($seller) @@ -224,19 +228,29 @@ class PaymentController extends Controller ->taxRate(floatval($paypalProduct->getTaxPercent())) ->shipping(0) ->addItem($item) - ->series('BIG') - ->status(__('invoices::invoice.paid')) - ->sequence(667) - ->serialNumberFormat('{SEQUENCE}/{SERIES}') + + ->series(now()->format('M')) + ->delimiter("-") + ->sequence($newInvoiceID) + ->serialNumberFormat('{SEQUENCE} - {SERIES}') + + ->logo(public_path('vendor/invoices/logo.png')) ->save('public'); + $user->notify(new InvoiceNotification($invoice)); + \App\Models\invoice::create([ + 'invoice_user' => $user->id, + 'invoice_name' => "invoice_".$invoice->series.$invoice->delimiter.$invoice->sequence, + 'payment_id' => $payment->payment_id, + ]); //redirect back to home - return redirect()->route('home')->with('success', 'Your credit balance has been increased! Invoice: '.$invoice->url()); + return redirect()->route('home')->with('success', 'Your credit balance has been increased! Find the invoice in your Notifications'); } + // If call returns body in response, you can get the deserialized version from the result attribute of the response if (env('APP_ENV') == 'local') { dd($response); diff --git a/app/Models/Invoice.php b/app/Models/Invoice.php new file mode 100644 index 00000000..e117b039 --- /dev/null +++ b/app/Models/Invoice.php @@ -0,0 +1,20 @@ +invoice = $invoice; + } + + /** + * Get the notification's delivery channels. + * + * @param mixed $notifiable + * @return array + */ + public function via($notifiable) + { + return ['database']; + } + + /** + * Get the array representation of the notification. + * + * @param mixed $notifiable + * @return array + */ + public function toArray($notifiable) + { + return [ + 'title' => "Invoice Created: Nr.".$this->invoice->sequence, + 'content' => " +

Find it here.

+ ", + ]; + } +} diff --git a/database/migrations/2021_11_27_014226_create_invoices.php b/database/migrations/2021_11_27_014226_create_invoices.php new file mode 100644 index 00000000..f2716c05 --- /dev/null +++ b/database/migrations/2021_11_27_014226_create_invoices.php @@ -0,0 +1,34 @@ +id(); + $table->string('invoice_name'); + $table->string('invoice_user'); + $table->string('payment_id'); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('invoices'); + } +} diff --git a/resources/views/vendor/invoices/templates/default.blade.php b/resources/views/vendor/invoices/templates/default.blade.php index 2c4ad699..c288a766 100644 --- a/resources/views/vendor/invoices/templates/default.blade.php +++ b/resources/views/vendor/invoices/templates/default.blade.php @@ -136,6 +136,7 @@ +