<?xml version="1.0" ?>
<domain-models xmlns="http://axelor.com/xml/ns/domain-models"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://axelor.com/xml/ns/domain-models http://axelor.com/xml/ns/domain-models/domain-models_5.2.xsd">

  <module name="human-resource" package="com.axelor.apps.hr.db"/>

  <entity name="Timesheet" cacheable="true">

      <date name="sentDate" title="Sent Date" readonly="true"/>
      <integer name="statusSelect" title="Status" selection="hrs.timesheet.status.select" default="1" readonly="true"/>
      <many-to-one name="user" ref="com.axelor.auth.db.User" title="User" column="user_id" required="true" readonly="true"/>
      <one-to-many name="timesheetLineList" ref="com.axelor.apps.hr.db.TimesheetLine" title="Timesheet Lines" mappedBy="timesheet" orphanRemoval="true"/>
      <date name="fromDate"/>
      <date name="toDate"/>
      <many-to-one name="company" ref="com.axelor.apps.base.db.Company"/>
      <many-to-one name="validatedBy" ref="com.axelor.auth.db.User" title="Validated by" readonly="true"/>
      <many-to-one name="refusedBy" ref="com.axelor.auth.db.User" title="Refused By" readonly="true"/>
      <date name="validationDate" title="Validation Date" readonly="true"  />
      <date name="refusalDate" title="Refusal Date" readonly="true" />
      <string name="groundForRefusal" title="Ground For Refusal" large="true"/>
	  <decimal name="periodTotal" title="Total on period (hours)"/>
	  <boolean name="showEditor" title="Show editor" />
      <string name="timeLoggingPreferenceSelect" title="Time logging preference" selection="hr.time.logging.preference.select"/>

      <string name="fullName" namecolumn="true" readonly="true">
      <![CDATA[
      		if(this.getUser() != null && this.getCreatedOn() != null){
      			return this.getUser().getFullName()+" "+this.getCreatedOn().getDayOfMonth()+"/"+this.getCreatedOn().getMonthValue()
	  				+"/"+this.getCreatedOn().getYear()+"  "+this.getCreatedOn().getHour()+":"+this.getCreatedOn().getMinute();
      		}
	  		else if (this.getUser() != null){
	  			return this.getUser().getFullName()+" N°"+this.getId();
	  		}
	  		else{
	  			return "N°"+this.getId();
	  		}
	  ]]>
      </string>
      
      <finder-method name="findByUserAndStatus" using="user,statusSelect"/>
      
      <extra-code>
      	<![CDATA[
	  		public static final int STATUS_DRAFT = 1;
	  		public static final int STATUS_CONFIRMED = 2;
	  		public static final int STATUS_VALIDATED = 3;
	  		public static final int STATUS_REFUSED = 4;
	  		public static final int STATUS_CANCELED = 5;
	  ]]>
      </extra-code>
      <track>
          <field name="statusSelect"/>
      </track>
  </entity>
  
</domain-models>
