This commit is contained in:
Kevin Adametz 2024-08-05 11:58:09 +02:00
parent c1c613a4b9
commit 881fc84207
384 changed files with 50679 additions and 990 deletions

View file

@ -7,8 +7,9 @@
namespace App\Models;
use Carbon\Carbon;
use Illuminate\Database\Eloquent\Collection;
use App\Services\Util;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Collection;
/**
* Class Coupon
@ -78,6 +79,32 @@ class Coupon extends Model
'text'
];
/**
* The "booted" method of the model.
*
* @return void
*/
protected static function boot()
{
parent::boot();
static::created(function ($model) {
$model->number = sprintf(
'%02u-%05u-%05u-%02u%02u',
date('y'),
$model->customer_id,
$model->id,
date('H'),
date('i')
);
$model->save();
});
}
public function create($product)
{
logger($product->id);
}
public function booking()
{
return $this->belongsTo(Booking::class);
@ -88,6 +115,12 @@ class Coupon extends Model
return $this->belongsTo(Customer::class);
}
public function booking_document()
{
return $this->hasOne(BookingDocument::class, 'coupon_id', 'id');
}
public function bookings()
{
return $this->hasMany(Booking::class);
@ -95,6 +128,67 @@ class Coupon extends Model
public function isLegal(){
//TODO
// return strtotime(date('Y-m-d')) <= strtotime($this->getValidDate());
return false;
}
public function getValueFormatted()
{
return Util::_number_format($this->attributes['value']);
}
public function getValueRaw()
{
return $this->attributes['value'];
}
public function setValueAttribute($value)
{
$this->attributes['value'] = Util::_clean_float($value);
}
public function getIssueDateFormatted()
{
return isset($this->attributes['issue_date']) ? Carbon::parse($this->attributes['issue_date'])->format('d.m.Y') : '';
}
public function setIssueDateAttribute($value)
{
if (!$value) {
$this->attributes['issue_date'] = null;
} else {
$this->attributes['issue_date'] = Carbon::parse($value)->format('Y-m-d');
}
}
public function getValidDateFormatted()
{
return isset($this->attributes['valid_date']) ? Carbon::parse($this->attributes['valid_date'])->format('d.m.Y') : '';
}
public function setValidDateAttribute($value)
{
if (!$value) {
$this->attributes['valid_date'] = null;
} else {
$this->attributes['valid_date'] = Carbon::parse($value)->format('Y-m-d');
}
}
public function getRedeemDateFormatted()
{
return isset($this->attributes['redeem_date']) ? Carbon::parse($this->attributes['redeem_date'])->format('d.m.Y') : '';
}
public function setRedeemDateAttribute($value)
{
if (!$value) {
$this->attributes['redeem_date'] = null;
} else {
$this->attributes['redeem_date'] = Carbon::parse($value)->format('Y-m-d');
}
}
}