<?xml version="1.0" encoding="UTF-8"?>
<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
  https://axelor.com/xml/ns/domain-models/domain-models_6.0.xsd">

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

  <entity name="Absence">
    <many-to-one name="employee" ref="com.axelor.apps.hr.db.Employee"/>
    <integer name="absenceType" title="Type Absence" selection="hr.type.absence.selection"/>

    <datetime name="startDate" title="Date Début"/>
    <datetime name="endDate" title="Date Fin"/>
    <decimal name="totalAbsenceHours" precision="20" scale="2"/>
    <one-to-many name="dailyReport" ref="com.axelor.apps.hr.db.DailyReport"/>

    <many-to-many name="dailyReportSet" ref="com.axelor.apps.hr.db.DailyReport"/>
    
    <string name="fullName" namecolumn="true">
          <![CDATA[
            String fullName = "";
            if (employee != null && employee.getContactPartner() != null && employee.getContactPartner().getFullName() != null) {
              fullName += employee.getContactPartner().getFullName();
            }
            if (absenceType != null) {
              fullName += " - " + absenceType;
            } 
            if (startDate != null && endDate != null) {
              java.time.format.DateTimeFormatter formatter = java.time.format.DateTimeFormatter.ofPattern("dd/MM/yyyy HH:mm");
              fullName += " (from " + startDate.format(formatter) + " to " + endDate.format(formatter) + ")";
            }
            return fullName;
          ]]>
    </string> 
    
    <extra-code><![CDATA[
    
      // PERIOD ABSENCE TYPE
      public static final int PERIOD_ABSENCE_TYPE_PARTIAL_DAY = 0;
      public static final int PERIOD_ABSENCE_TYPE_FULL_DAY = 1;
      public static final int PERIOD_ABSENCE_TYPE_MULTIPLE_DAYS = 2;

    ]]></extra-code>  

    <track>
      <field name="employee"/>
      <field name="absenceType"/>
      <field name="startDate"/>
      <field name="endDate"/>
    </track>

    <!--<string name="fullName" namecolumn="true">
          <![CDATA[
            String fullName = "";
            if (employee != null && employee.getContactPartner() != null && employee.getContactPartner().getFullName() != null) {
              fullName += employee.getContactPartner().getFullName();
            }
            if (absenceType != null) {
              fullName += " - " + absenceType;
            }
            if (periodAbsenceType != null){
              if(periodAbsenceType == 0){
                if (startDate != null && endDate != null){
                  java.time.format.DateTimeFormatter formatter = java.time.format.DateTimeFormatter.ofPattern("HH:mm");
                  fullName += " (from " + startDate.format(formatter) + " to " + endDate.format(formatter) + ")";
                }
              } else if(periodAbsenceType == 1){
                if(startDate != null){
                  java.time.format.DateTimeFormatter formatter = java.time.format.DateTimeFormatter.ofPattern("dd/MM/yyyy");
                  fullName += " - " + startDate.format(formatter);
                }
              }else{
                if (startDate != null && endDate != null){
                  java.time.format.DateTimeFormatter formatter = java.time.format.DateTimeFormatter.ofPattern("dd/MM/yyyy");
                  fullName += " (from " + startDate.format(formatter) + " to " + endDate.format(formatter) + ")";
                }
              }
            }
            else{ 
              if (startDate != null && endDate != null) {
                java.time.format.DateTimeFormatter formatter = java.time.format.DateTimeFormatter.ofPattern("dd/MM/yyyy HH:mm");
                fullName += " (from " + startDate.format(formatter) + " to " + endDate.format(formatter) + ")";
              }
            }
            return fullName;
          ]]>
    </string> -->

  </entity>

</domain-models>