invoice DB, counting up, format stuff
This commit is contained in:
parent
bf848f0bcb
commit
21b9d70035
6 changed files with 130 additions and 5 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -18,3 +18,4 @@ yarn-error.log
|
||||||
.gitignore
|
.gitignore
|
||||||
.env.dev
|
.env.dev
|
||||||
.env.testing
|
.env.testing
|
||||||
|
public/vendor/invoices/logo.png
|
||||||
|
|
|
@ -10,6 +10,7 @@ use App\Models\PaypalProduct;
|
||||||
use App\Models\Product;
|
use App\Models\Product;
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
use App\Notifications\ConfirmPaymentNotification;
|
use App\Notifications\ConfirmPaymentNotification;
|
||||||
|
use App\Notifications\InvoiceNotification;
|
||||||
use Exception;
|
use Exception;
|
||||||
use Illuminate\Contracts\Foundation\Application;
|
use Illuminate\Contracts\Foundation\Application;
|
||||||
use Illuminate\Contracts\View\Factory;
|
use Illuminate\Contracts\View\Factory;
|
||||||
|
@ -217,6 +218,9 @@ class PaymentController extends Controller
|
||||||
]);
|
]);
|
||||||
$item = (new InvoiceItem())->title($paypalProduct->description)->pricePerUnit($paypalProduct->price);
|
$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()
|
$invoice = Invoice::make()
|
||||||
->buyer($customer)
|
->buyer($customer)
|
||||||
->seller($seller)
|
->seller($seller)
|
||||||
|
@ -224,19 +228,29 @@ class PaymentController extends Controller
|
||||||
->taxRate(floatval($paypalProduct->getTaxPercent()))
|
->taxRate(floatval($paypalProduct->getTaxPercent()))
|
||||||
->shipping(0)
|
->shipping(0)
|
||||||
->addItem($item)
|
->addItem($item)
|
||||||
->series('BIG')
|
|
||||||
|
|
||||||
->status(__('invoices::invoice.paid'))
|
->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');
|
->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
|
//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 call returns body in response, you can get the deserialized version from the result attribute of the response
|
||||||
if (env('APP_ENV') == 'local') {
|
if (env('APP_ENV') == 'local') {
|
||||||
dd($response);
|
dd($response);
|
||||||
|
|
20
app/Models/Invoice.php
Normal file
20
app/Models/Invoice.php
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models;
|
||||||
|
|
||||||
|
use Hidehalo\Nanoid\Client;
|
||||||
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||||
|
|
||||||
|
class invoice extends Model
|
||||||
|
{
|
||||||
|
use HasFactory;
|
||||||
|
|
||||||
|
protected $fillable = [
|
||||||
|
'invoice_name',
|
||||||
|
'invoice_user',
|
||||||
|
'payment_id'
|
||||||
|
];
|
||||||
|
|
||||||
|
}
|
55
app/Notifications/InvoiceNotification.php
Normal file
55
app/Notifications/InvoiceNotification.php
Normal file
|
@ -0,0 +1,55 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Notifications;
|
||||||
|
|
||||||
|
use App\Models\Server;
|
||||||
|
use Illuminate\Bus\Queueable;
|
||||||
|
use Illuminate\Notifications\Notification;
|
||||||
|
use LaravelDaily\Invoices\Invoice;
|
||||||
|
|
||||||
|
class InvoiceNotification extends Notification
|
||||||
|
|
||||||
|
{
|
||||||
|
use Queueable;
|
||||||
|
/**
|
||||||
|
* @var invoice
|
||||||
|
*/
|
||||||
|
private $invoice;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new notification instance.
|
||||||
|
*
|
||||||
|
* @param Invoice $invoice
|
||||||
|
*/
|
||||||
|
public function __construct(Invoice $invoice)
|
||||||
|
{
|
||||||
|
$this->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' => "
|
||||||
|
<p>Find it <a href='".$this->invoice->url()."'>here</a>.</p>
|
||||||
|
",
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
34
database/migrations/2021_11_27_014226_create_invoices.php
Normal file
34
database/migrations/2021_11_27_014226_create_invoices.php
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
class CreateInvoices extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function up()
|
||||||
|
{
|
||||||
|
Schema::create('invoices', function (Blueprint $table) {
|
||||||
|
$table->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');
|
||||||
|
}
|
||||||
|
}
|
|
@ -136,6 +136,7 @@
|
||||||
|
|
||||||
<table class="table mt-5">
|
<table class="table mt-5">
|
||||||
<tbody>
|
<tbody>
|
||||||
|
<tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td class="border-0 pl-0" width="70%">
|
<td class="border-0 pl-0" width="70%">
|
||||||
<h4 class="text-uppercase">
|
<h4 class="text-uppercase">
|
||||||
|
|
Loading…
Reference in a new issue