mirror of
https://github.com/VueFileManager/vuefilemanager.git
synced 2026-05-19 11:45:01 +00:00
added invoice profile
This commit is contained in:
@@ -46,7 +46,7 @@ class InvoiceController extends Controller
|
||||
*/
|
||||
public function get_invoice(Invoice $invoice)
|
||||
{
|
||||
if (! Storage::exists(invoice_path($invoice))) {
|
||||
if (!Storage::exists(invoice_path($invoice))) {
|
||||
abort(404, 'Not Found');
|
||||
}
|
||||
|
||||
@@ -79,9 +79,10 @@ class InvoiceController extends Controller
|
||||
public function store(StoreInvoiceRequest $request)
|
||||
{
|
||||
$client = $this->getOrStoreClient($request);
|
||||
$user = $request->user();
|
||||
|
||||
$invoice = Invoice::create([
|
||||
'user_id' => $request->user()->id,
|
||||
'user_id' => $user->id,
|
||||
'client_id' => $client->id ?? null,
|
||||
'invoice_type' => $request->invoice_type,
|
||||
'invoice_number' => $request->invoice_number,
|
||||
@@ -90,6 +91,7 @@ class InvoiceController extends Controller
|
||||
'discount_type' => $request->discount_type ?? null,
|
||||
'discount_rate' => $request->discount_rate ?? null,
|
||||
'items' => $request->items,
|
||||
'user' => $user->invoiceProfile,
|
||||
'client' => [
|
||||
'email' => $client->email ?? $request->client_email,
|
||||
'name' => $client->name ?? $request->client_name,
|
||||
@@ -106,17 +108,17 @@ class InvoiceController extends Controller
|
||||
// Generate PDF
|
||||
\PDF::loadView('oasis.invoices.invoice', [
|
||||
'invoice' => Invoice::find($invoice->id),
|
||||
'user' => $request->user(),
|
||||
'user' => $user,
|
||||
])
|
||||
->setPaper('a4')
|
||||
->setOrientation('portrait')
|
||||
->save(
|
||||
storage_path("app/files/{$request->user()->id}/invoice-{$invoice->id}.pdf")
|
||||
storage_path("app/files/{$user->id}/invoice-{$invoice->id}.pdf")
|
||||
);
|
||||
|
||||
if ($request->send_invoice && $invoice->client['email']) {
|
||||
Notification::route('mail', $invoice->client['email'])->notify(
|
||||
new InvoiceDeliveryNotification($request->user(), $invoice)
|
||||
new InvoiceDeliveryNotification($user, $invoice)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -37,11 +37,6 @@ class Invoice extends Model
|
||||
return $this->hasOne(Client::class, 'id', 'user_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* Index file
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function toSearchableArray()
|
||||
{
|
||||
$array = $this->toArray();
|
||||
@@ -72,24 +67,6 @@ class Invoice extends Model
|
||||
$invoice->total_tax = invoice_total_tax($invoice);
|
||||
|
||||
$invoice->currency = 'CZK';
|
||||
|
||||
$user = Auth::user() ?? User::find($invoice->user_id);
|
||||
|
||||
$invoice->author_name = $user->settings->name ?? null;
|
||||
$invoice->author_stamp = ''; // TODO: doplnit
|
||||
|
||||
$invoice->user = [
|
||||
'name' => $user->settings->name ?? null,
|
||||
'address' => $user->settings->address ?? null,
|
||||
'state' => $user->settings->state ?? null,
|
||||
'city' => $user->settings->city ?? null,
|
||||
'postal_code' => $user->settings->postcode ?? null,
|
||||
'country' => $user->settings->country ?? null,
|
||||
'phone_number' => $user->settings->phoneNumber ?? null,
|
||||
'bank_name' => $user->settings->bank_name ?? null,
|
||||
'iban' => $user->settings->iban ?? null,
|
||||
'swift' => $user->settings->swift ?? null,
|
||||
];
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Oasis;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class InvoiceProfile extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
public $guarded = ['id'];
|
||||
|
||||
public $incrementing = false;
|
||||
|
||||
protected $keyType = 'string';
|
||||
|
||||
public function user()
|
||||
{
|
||||
return $this->hasOne(User::class, 'id', 'user_id');
|
||||
}
|
||||
|
||||
protected static function boot()
|
||||
{
|
||||
parent::boot();
|
||||
|
||||
static::creating(function ($invoice) {
|
||||
$invoice->id = (string) Str::uuid();
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -4,20 +4,21 @@ namespace App\Traits;
|
||||
|
||||
use App\Models\Oasis\Client;
|
||||
use App\Models\Oasis\Invoice;
|
||||
use App\Models\Oasis\InvoiceProfile;
|
||||
use App\Models\Oasis\SubscriptionRequest;
|
||||
|
||||
trait Oasis
|
||||
{
|
||||
/**
|
||||
* Get user subscription request
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function subscriptionRequest()
|
||||
{
|
||||
return $this->hasOne(SubscriptionRequest::class);
|
||||
}
|
||||
|
||||
public function invoiceProfile()
|
||||
{
|
||||
return $this->hasOne(InvoiceProfile::class);
|
||||
}
|
||||
|
||||
public function clients()
|
||||
{
|
||||
return $this->hasMany(Client::class, 'user_id', 'id');
|
||||
|
||||
Reference in New Issue
Block a user