<?php

class Timesheetday extends \Eloquent {

	use SoftDeletingTrait;

	protected $guarded		 = array();

	public function user() {
		return $this->belongsTo('User')->withTrashed()->remember(60);
	}

	public function timesheetdayFines() {
		return TimesheetdayFine::withTrashed()->whereDate($this->date)->whereUserId($this->user_id)->get();
	}

	public function setPaySalaryDayAttribute($value) {
		$value															 = str_replace(',', '.', $value);
		$value															 = str_replace(' ', '', $value);
		$this->attributes['pay_salary_day']	 = round($value * 100, 0);
	}

	public function getPaySalaryDayAttribute() {
		return round($this->attributes['pay_salary_day'] / 100, 2);
	}

	public function setPayPercentAllAttribute($value) {
		$value															 = str_replace(',', '.', $value);
		$value															 = str_replace(' ', '', $value);
		$this->attributes['pay_percent_all'] = round($value * 100, 0);
	}

	public function getPayPercentAllAttribute() {
		return round($this->attributes['pay_percent_all'] / 100, 2);
	}

	public function setPayPercentMarginAttribute($value) {
		$value																	 = str_replace(',', '.', $value);
		$value																	 = str_replace(' ', '', $value);
		$this->attributes['pay_percent_margin']	 = round($value * 100, 0);
	}

	public function getPayPercentMarginAttribute() {
		return round($this->attributes['pay_percent_margin'] / 100, 2);
	}

	public function setLateFeeAttribute($value) {
		$value												 = str_replace(',', '.', $value);
		$value												 = str_replace(' ', '', $value);
		$this->attributes['late_fee']	 = round($value * 100, 0);
	}

	public function getFinesAmountAttribute() {
		return round($this->attributes['fines_amount'] / 100, 2);
	}

	public function setFinesAmountAttribute($value) {
		$value												 = str_replace(',', '.', $value);
		$value												 = str_replace(' ', '', $value);
		$this->attributes['fines_amount']	 = round($value * 100, 0);
	}

	public function getLateFeeAttribute() {
		return round($this->attributes['late_fee'] / 100, 2);
	}

}
