Add initial Code
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Contact extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $fillable = [
|
||||
'customer_id',
|
||||
'first_name',
|
||||
'last_name',
|
||||
'email',
|
||||
'phone',
|
||||
'position',
|
||||
'is_primary',
|
||||
'avatar',
|
||||
];
|
||||
|
||||
public function customer()
|
||||
{
|
||||
return $this->belongsTo(Customer::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the URL to the contact's avatar.
|
||||
*/
|
||||
public function getAvatarUrlAttribute()
|
||||
{
|
||||
if ($this->avatar) {
|
||||
return asset('storage/' . $this->avatar);
|
||||
}
|
||||
|
||||
// Return null if no avatar is set
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Scope a query to order contacts with primary contacts first.
|
||||
*/
|
||||
public function scopePrimaryFirst($query)
|
||||
{
|
||||
return $query->orderBy('is_primary', 'desc');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Customer extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $casts = [
|
||||
'billing_address' => 'array'
|
||||
];
|
||||
|
||||
protected $fillable = [
|
||||
'type',
|
||||
'company_name',
|
||||
'vat_id',
|
||||
'tax_id', // Tax identification number
|
||||
'global_id', // Global Location Number (GLN) or other identification
|
||||
'legal_registration_id', // Legal registration ID
|
||||
'email',
|
||||
'phone',
|
||||
'billing_address',
|
||||
'payment_terms_id',
|
||||
'status',
|
||||
'notes',
|
||||
'logo',
|
||||
];
|
||||
|
||||
/**
|
||||
* Set the billing address attribute.
|
||||
*
|
||||
* @param array $value
|
||||
* @return void
|
||||
*/
|
||||
public function setBillingAddressAttribute($value)
|
||||
{
|
||||
if (is_string($value)) {
|
||||
$value = json_decode($value, true);
|
||||
}
|
||||
|
||||
$this->attributes['billing_address'] = json_encode([
|
||||
'line_one' => $value['line_one'] ?? '',
|
||||
'line_two' => $value['line_two'] ?? '',
|
||||
'city' => $value['city'] ?? '',
|
||||
'postal_code' => $value['postal_code'] ?? '',
|
||||
'country_code' => $value['country_code'] ?? 'DE', // Default to Germany
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the billing address attribute.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getBillingAddressAttribute()
|
||||
{
|
||||
return json_decode($this->attributes['billing_address'], true) ?? [
|
||||
'line_one' => '',
|
||||
'line_two' => '',
|
||||
'city' => '',
|
||||
'postal_code' => '',
|
||||
'country_code' => 'DE',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the URL to the customer's logo.
|
||||
*/
|
||||
public function getLogoUrlAttribute()
|
||||
{
|
||||
if ($this->logo) {
|
||||
return asset('storage/' . $this->logo);
|
||||
}
|
||||
|
||||
// Return null if no logo is set
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the contacts for the customer.
|
||||
*/
|
||||
public function contacts()
|
||||
{
|
||||
return $this->hasMany(Contact::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the payment term associated with the customer.
|
||||
*/
|
||||
public function paymentTerms()
|
||||
{
|
||||
return $this->belongsTo(PaymentTerms::class);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use App\Models\Customer;
|
||||
use App\Models\LineItem;
|
||||
|
||||
class Invoice extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $fillable = [
|
||||
'nr',
|
||||
'invoice_date',
|
||||
'due_date',
|
||||
'service_start_date',
|
||||
'service_end_date',
|
||||
'is_recurring',
|
||||
'is_partial_service',
|
||||
'customer_id',
|
||||
'billing_data',
|
||||
'payment_status',
|
||||
'total_amount',
|
||||
'title',
|
||||
'text',
|
||||
'items'
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'billing_data' => 'array', // JSON to Array
|
||||
];
|
||||
|
||||
public function customer()
|
||||
{
|
||||
return $this->belongsTo(Customer::class);
|
||||
}
|
||||
|
||||
public function items()
|
||||
{
|
||||
return $this->hasMany(LineItem::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the payment term for the invoice.
|
||||
*/
|
||||
public function getPaymentTermsAttribute()
|
||||
{
|
||||
return $this->customer->paymentTerms;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
|
||||
class LineItem extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $fillable = [
|
||||
'invoice_id',
|
||||
'position',
|
||||
'title',
|
||||
'description',
|
||||
'quantity',
|
||||
'unit',
|
||||
'price',
|
||||
];
|
||||
|
||||
public function invoice()
|
||||
{
|
||||
return $this->belongsTo(Invoice::class);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class PaymentTerms extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $fillable = [
|
||||
'name',
|
||||
'description',
|
||||
'is_fixed',
|
||||
'days'
|
||||
];
|
||||
|
||||
/**
|
||||
* Get the customers that use this payment term.
|
||||
*/
|
||||
public function customers()
|
||||
{
|
||||
return $this->hasMany(Customer::class);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Setting extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $fillable = [
|
||||
'invoice_number_format',
|
||||
'invoice_number_start',
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
// use Illuminate\Contracts\Auth\MustVerifyEmail;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Laravel\Sanctum\HasApiTokens;
|
||||
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||
use Illuminate\Notifications\Notifiable;
|
||||
use Laravel\Fortify\TwoFactorAuthenticatable;
|
||||
|
||||
class User extends Authenticatable
|
||||
{
|
||||
/** @use HasFactory<\Database\Factories\UserFactory> */
|
||||
use HasFactory, HasApiTokens, Notifiable, TwoFactorAuthenticatable;
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var list<string>
|
||||
*/
|
||||
protected $fillable = [
|
||||
'name',
|
||||
'email',
|
||||
'password',
|
||||
'avatar', // Add avatar field
|
||||
];
|
||||
|
||||
/**
|
||||
* The attributes that should be hidden for serialization.
|
||||
*
|
||||
* @var list<string>
|
||||
*/
|
||||
protected $hidden = [
|
||||
'password',
|
||||
'remember_token',
|
||||
];
|
||||
|
||||
/**
|
||||
* Get the attributes that should be cast.
|
||||
*
|
||||
* @return array<string, string>
|
||||
*/
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'email_verified_at' => 'datetime',
|
||||
'password' => 'hashed',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the URL to the user's avatar.
|
||||
*/
|
||||
public function getAvatarUrlAttribute()
|
||||
{
|
||||
if ($this->avatar) {
|
||||
return asset('storage/' . $this->avatar);
|
||||
}
|
||||
|
||||
// Return null if no avatar is set
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user