mein-sterntours/app/Models/Customer.php
Phase-1-Rollback-Agent e3dc1afd8e WIP: Sicherheitsnetz vor Phase-1-R\u00fcckbau
Enth\u00e4lt gemischt: Laravel-10-Upgrade + Phase 1 (Contacts-Modul, Duplicats-Commands,
Soft-Delete+Merge-Fields) + Phase 2 Code-Umstellungen (inquiry_id, $table='contacts'/'inquiries')
+ Offers-Modul (Migrationen, Models, offer_id in Booking, offer-Disk in filesystems.php).

Phase 2 + Offers werden im folgenden Commit nach dev/backups/phase2-offers-2026-04-17/
verschoben, damit der Workspace auf Phase-1-only (= Test-System-Stand) reduziert ist
und direkt auf Live deploybar wird.

Tarball-Backup zus\u00e4tzlich unter: ../backups-safety/workspace-pre-phase1-rollback-2026-04-17.tar.gz

Made-with: Cursor
2026-04-17 13:40:31 +00:00

206 lines
7.2 KiB
PHP

<?php
/**
* Created by Reliese Model.
*/
namespace App\Models;
use App\Models\Sym\TravelCountry;
use Carbon\Carbon;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
/**
* Class Customer
*
* @property int $id
* @property int $salutation_id
* @property string $title
* @property string $name
* @property string $firstname
* @property Carbon $birthdate
* @property string $company
* @property string $street
* @property string $zip
* @property string $city
* @property string $email
* @property string $phone
* @property string $phonebusiness
* @property string $phonemobile
* @property string $fax
* @property string $bank
* @property string $bank_code
* @property string $bank_account_number
* @property int $credit_card_type_id
* @property string $credit_card_number
* @property Carbon $credit_card_expiration_date
* @property string $participants_remarks
* @property string $miscellaneous_remarks
* @property Carbon $created_at
* @property Carbon $updated_at
* @property int $country_id
* @property TravelCountry $travel_country
* @property CreditCardType $credit_card_type
* @property Salutation $salutation
* @property Collection|Booking[] $bookings
* @property Collection|Coupon[] $coupons
* @property Collection|Lead[] $leads
* @package App\Models
* @property-read int|null $bookings_count
* @property-read int|null $coupons_count
* @property-read int|null $leads_count
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Customer newModelQuery()
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Customer newQuery()
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Customer query()
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Customer whereBank($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Customer whereBankAccountNumber($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Customer whereBankCode($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Customer whereBirthdate($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Customer whereCity($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Customer whereCompany($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Customer whereCountryId($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Customer whereCreatedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Customer whereCreditCardExpirationDate($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Customer whereCreditCardNumber($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Customer whereCreditCardTypeId($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Customer whereEmail($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Customer whereFax($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Customer whereFirstname($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Customer whereId($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Customer whereMiscellaneousRemarks($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Customer whereName($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Customer whereParticipantsRemarks($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Customer wherePhone($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Customer wherePhonebusiness($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Customer wherePhonemobile($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Customer whereSalutationId($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Customer whereStreet($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Customer whereTitle($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Customer whereUpdatedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Customer whereZip($value)
* @mixin \Eloquent
*/
class Customer extends Model
{
use HasFactory;
protected $connection = 'mysql';
/**
* Modul 3 Phase 2: customer → contacts (RENAME TABLE).
* Der Model-Name bleibt aus Kompatibilität zum Legacy-Code bestehen;
* für die Neuimplementierung steht {@see Contact} bereit.
*/
protected $table = 'contacts';
protected $casts = [
'salutation_id' => 'int',
'credit_card_type_id' => 'int',
'country_id' => 'int',
'birthdate' => 'datetime',
'credit_card_expiration_date' => 'datetime',
];
protected $fillable = [
'salutation_id',
'title',
'name',
'firstname',
'birthdate',
'company',
'street',
'zip',
'city',
'email',
'phone',
'phonebusiness',
'phonemobile',
'fax',
'bank',
'bank_code',
'bank_account_number',
'credit_card_type_id',
'credit_card_number',
'credit_card_expiration_date',
'participants_remarks',
'miscellaneous_remarks',
'country_id',
];
public static $salutationType = [
1 => 'Herr',
2 => 'Frau',
3 => 'Divers/keine Anrede',
4 => 'Firma'
];
public static $salutationNameType = [
1 => 'Herr',
2 => 'Frau',
3 => '',
4 => 'Firma'
];
public static $salutationDearType = [
1 => 'geehrter',
2 => 'geehrte',
3 => 'geehrte:r',
4 => ''
];
public function travel_country()
{
return $this->belongsTo(TravelCountry::class, 'country_id');
}
public function credit_card_type()
{
return $this->belongsTo(CreditCardType::class);
}
public function salutation()
{
return $this->belongsTo(Salutation::class);
}
public function bookings()
{
return $this->hasMany(Booking::class, 'customer_id');
}
public function coupons()
{
return $this->hasMany(Coupon::class, 'customer_id');
}
public function leads()
{
return $this->hasMany(Lead::class, 'customer_id');
}
public function getSalutation(){
return isset(self::$salutationType[$this->salutation_id]) ? self::$salutationType[$this->salutation_id] : '';
}
public function getSalutationName(){
return isset(self::$salutationNameType[$this->salutation_id]) ? self::$salutationNameType[$this->salutation_id] : '';
}
public function getSalutationDear(){
return isset(self::$salutationDearType[$this->salutation_id]) ? self::$salutationDearType[$this->salutation_id] : '';
}
public function fullName()
{
if ($this->firstname) {
return $this->firstname . ' ' . $this->name;
}
return $this->name;
}
public static function getCustomerCountriesArray(){
return TravelCountry::where('is_customer_country', 1)->get()->pluck('name', 'id');
}
}