mein-sterntours/app/Models/ServiceProviderEntry.php
2020-07-09 12:36:15 +02:00

138 lines
4.4 KiB
PHP

<?php
/**
* Created by Reliese Model.
*/
namespace App\Models;
use App\Services\Util;
use Carbon\Carbon;
use Illuminate\Database\Eloquent\Model;
/**
* Class ServiceProviderEntry
*
* @property int $id
* @property int $booking_id
* @property int $service_provider_id
* @property float $amount
* @property float $amount_eur
* @property float $factor
* @property Carbon $payment_date
* @property string $invoice_number
* @property bool $is_cleared
* @property Carbon $created_at
* @property Carbon $updated_at
* @property string $type
* @property Booking $booking
* @property ServiceProvider $service_provider
* @package App\Models
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\ServiceProviderEntry newModelQuery()
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\ServiceProviderEntry newQuery()
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\ServiceProviderEntry query()
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\ServiceProviderEntry whereAmount($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\ServiceProviderEntry whereAmountEur($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\ServiceProviderEntry whereBookingId($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\ServiceProviderEntry whereCreatedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\ServiceProviderEntry whereFactor($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\ServiceProviderEntry whereId($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\ServiceProviderEntry whereInvoiceNumber($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\ServiceProviderEntry whereIsCleared($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\ServiceProviderEntry wherePaymentDate($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\ServiceProviderEntry whereServiceProviderId($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\ServiceProviderEntry whereType($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\ServiceProviderEntry whereUpdatedAt($value)
* @mixin \Eloquent
*/
class ServiceProviderEntry extends Model
{
protected $table = 'service_provider_entry';
protected $casts = [
'booking_id' => 'int',
'service_provider_id' => 'int',
'amount' => 'float',
'amount_eur' => 'float',
'factor' => 'float',
'is_cleared' => 'bool'
];
protected $dates = [
'payment_date'
];
protected $fillable = [
'booking_id',
'service_provider_id',
'amount',
'amount_eur',
'factor',
'payment_date',
'invoice_number',
'is_cleared',
'type'
];
private static $counter = 0;
private static $bookingIds = array();
public function booking()
{
return $this->belongsTo(Booking::class);
}
public function service_provider()
{
return $this->belongsTo(ServiceProvider::class);
}
public function getCounter(){
if ($this->booking_id) {
if (!in_array($this->booking_id, self::$bookingIds)) {
self::$bookingIds[] = $this->booking_id;
self::$counter++;
}
return self::$counter;
}
}
public function getAmountAttribute()
{
return Util::_number_format($this->attributes['amount']);
}
public function getAmountRaw()
{
return $this->attributes['amount'];
}
public function getAmountEurAttribute()
{
return Util::_number_format($this->attributes['amount_eur']);
}
public function getAmountEurRaw()
{
return $this->attributes['amount_eur'];
}
public function getAmountFinalEur(){
$ret = $this->attributes['amount'];
if($this->attributes['amount_eur'] && $this->attributes['amount_eur'] > 0){
$ret = $this->attributes['amount_eur'];
}
return number_format($ret, 2, ',', '.');
}
public function getAmountFinalEurRaw(){
if($this->attributes['amount_eur'] && $this->attributes['amount_eur'] > 0){
return $this->attributes['amount_eur'];
}
return $this->attributes['amount'];
}
public function getPaymentDateFormat(){
if(!$this->attributes['payment_date']){ return ""; }
return Carbon::parse($this->attributes['payment_date'])->format(\Util::formatDateDB());
}
}