e6a75bf16b
Used standard DATEV format(10000 – 69999) Fixes #31
99 lines
2.3 KiB
PHP
99 lines
2.3 KiB
PHP
<?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',
|
|
'customer_nr',
|
|
'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);
|
|
}
|
|
}
|