mein-sterntours/app/Models/BookingDocument.php
2025-04-01 10:40:14 +02:00

159 lines
4.7 KiB
PHP

<?php
/**
* Created by Reliese Model.
*/
namespace App\Models;
use Carbon\Carbon;
use Illuminate\Database\Eloquent\Model;
/**
* Class BookingDocument
*
* @property int $id
* @property int|null $booking_id
* @property int|null $customer_id
* @property int|null $lead_id
* @property string $identifier
* @property string $filename
* @property string $dir
* @property string $original_name
* @property string $ext
* @property string $mine
* @property int $size
* @property Carbon $date
* @property Carbon|null $created_at
* @property Carbon|null $updated_at
* @property Booking|null $booking
* @property Customer|null $customer
* @property Lead|null $lead
* @package App\Models
* @property \App\Models\Coupon|null $coupon_id
* @property int|null $booking_storno_id
* @property object|null $data
* @property int|null $status
* @property-read \App\Models\BookingStorno|null $booking_storno
* @method static \Illuminate\Database\Eloquent\Builder|BookingDocument newModelQuery()
* @method static \Illuminate\Database\Eloquent\Builder|BookingDocument newQuery()
* @method static \Illuminate\Database\Eloquent\Builder|BookingDocument query()
* @method static \Illuminate\Database\Eloquent\Builder|BookingDocument whereBookingId($value)
* @method static \Illuminate\Database\Eloquent\Builder|BookingDocument whereBookingStornoId($value)
* @method static \Illuminate\Database\Eloquent\Builder|BookingDocument whereCouponId($value)
* @method static \Illuminate\Database\Eloquent\Builder|BookingDocument whereCreatedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder|BookingDocument whereCustomerId($value)
* @method static \Illuminate\Database\Eloquent\Builder|BookingDocument whereData($value)
* @method static \Illuminate\Database\Eloquent\Builder|BookingDocument whereDate($value)
* @method static \Illuminate\Database\Eloquent\Builder|BookingDocument whereDir($value)
* @method static \Illuminate\Database\Eloquent\Builder|BookingDocument whereExt($value)
* @method static \Illuminate\Database\Eloquent\Builder|BookingDocument whereFilename($value)
* @method static \Illuminate\Database\Eloquent\Builder|BookingDocument whereId($value)
* @method static \Illuminate\Database\Eloquent\Builder|BookingDocument whereIdentifier($value)
* @method static \Illuminate\Database\Eloquent\Builder|BookingDocument whereLeadId($value)
* @method static \Illuminate\Database\Eloquent\Builder|BookingDocument whereMine($value)
* @method static \Illuminate\Database\Eloquent\Builder|BookingDocument whereOriginalName($value)
* @method static \Illuminate\Database\Eloquent\Builder|BookingDocument whereSize($value)
* @method static \Illuminate\Database\Eloquent\Builder|BookingDocument whereStatus($value)
* @method static \Illuminate\Database\Eloquent\Builder|BookingDocument whereUpdatedAt($value)
* @mixin \Eloquent
*/
class BookingDocument extends Model
{
protected $table = 'booking_documents';
protected $casts = [
'booking_id' => 'int',
'customer_id' => 'int',
'lead_id' => 'int',
'size' => 'int',
'data' => 'object',
'status' => 'int',
'booking_storno_id' => 'int',
'coupon_id' => 'int',
];
protected $dates = [
'date'
];
protected $fillable = [
'booking_id',
'customer_id',
'lead_id',
'coupon_id',
'booking_storno_id', //
'identifier',
'filename',
'dir',
'original_name',
'ext',
'mine',
'size',
'date',
'data',
'status'
];
/* Je nach identifier können verschiebene stati gesetzt werden
coupon 0 = nicht eingelöst 1 = eingelöst
*/
protected $status_type = [
0 => 'offen',
1 => 'erledigt',
];
public function booking()
{
return $this->belongsTo(Booking::class);
}
public function customer()
{
return $this->belongsTo(Customer::class);
}
public function lead()
{
return $this->belongsTo(Lead::class);
}
public function coupon_id()
{
return $this->belongsTo(Coupon::class);
}
public function booking_storno()
{
return $this->belongsTo(BookingStorno::class);
}
public function getURL($do=false){
return route('storage_file', [$this->id, 'booking_document', $do]);
}
public function getPath(){
return \Storage::disk('public')->path($this->dir.$this->filename);
}
public function deleteFile(){
if(\Storage::disk('public')->exists($this->dir.$this->filename)){
\Storage::disk('public')->delete($this->dir.$this->filename);
}
}
public function formatBytes($precision = 2)
{
$size = $this->size;
if ($size > 0) {
$size = (int) $size;
$base = log($size) / log(1024);
$suffixes = array(' bytes', ' KB', ' MB', ' GB', ' TB');
return round(pow(1024, $base - floor($base)), $precision) . $suffixes[floor($base)];
} else {
return $size;
}
}
}