2025-10-20 08:57:51 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Models;
|
|
|
|
|
|
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
2026-02-17 10:35:03 +01:00
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
2025-10-20 08:57:51 +02:00
|
|
|
|
|
|
|
|
class Customer extends Model
|
|
|
|
|
{
|
|
|
|
|
use HasFactory;
|
|
|
|
|
|
|
|
|
|
protected $casts = [
|
|
|
|
|
'billing_address' => 'array'
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
protected $fillable = [
|
|
|
|
|
'type',
|
|
|
|
|
'company_name',
|
2025-10-21 17:12:50 +02:00
|
|
|
'customer_nr',
|
2025-10-20 08:57:51 +02:00
|
|
|
'vat_id',
|
|
|
|
|
'tax_id', // Tax identification number
|
|
|
|
|
'global_id', // Global Location Number (GLN) or other identification
|
|
|
|
|
'legal_registration_id', // Legal registration ID
|
2025-11-04 13:51:31 +01:00
|
|
|
'url',
|
2025-10-20 08:57:51 +02:00
|
|
|
'email',
|
|
|
|
|
'phone',
|
|
|
|
|
'billing_address',
|
|
|
|
|
'payment_terms_id',
|
|
|
|
|
'status',
|
2025-11-28 09:18:39 +01:00
|
|
|
'description',
|
2025-10-20 08:57:51 +02:00
|
|
|
'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);
|
|
|
|
|
}
|
2025-11-21 13:23:13 +01:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get the notes for the customer
|
|
|
|
|
*/
|
|
|
|
|
public function notes()
|
|
|
|
|
{
|
|
|
|
|
return $this->morphMany(Note::class, 'notable');
|
|
|
|
|
}
|
2025-10-20 08:57:51 +02:00
|
|
|
}
|