'int', 'service_provider_id' => 'int', 'amount' => 'float', 'amount_eur' => 'float', 'factor' => 'float', 'is_cleared' => 'bool', 'payment_date' => 'datetime', ]; 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 setFactorAttribute($value) { $this->attributes['factor'] = floatval(preg_replace("/[^0-9.-]/", "", str_replace(',', '.', $value))); } public function getFactorAttribute() { return Util::_number_format($this->attributes['factor'], 4); } public function getFactortRaw() { return $this->attributes['factor']; } public function setAmountAttribute($value) { $this->attributes['amount'] = Util::_clean_float($value); } public function getAmountAttribute() { return Util::_number_format($this->attributes['amount']); } public function getAmountRaw() { return $this->attributes['amount']; } public function setAmountEurAttribute($value) { $this->attributes['amount_eur'] = Util::_clean_float($value); } 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()); } }