<?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="Expense" cacheable="true">

      <string name="expenseSeq"  title="Expense N°" readonly="true"/>

      <date name="sentDate" title="Sent Date" readonly="true"  />
      <many-to-one name="period" ref="com.axelor.apps.base.db.Period" title="Period"/>
      <integer name="statusSelect" title="Status" selection="hrs.expenses.status.select" default="1" readonly="true"/>
      <many-to-one name="user" ref="com.axelor.auth.db.User" title="User" column="user_id" readonly="true"/>

      <one-to-many name="generalExpenseLineList" ref="com.axelor.apps.hr.db.ExpenseLine" title="General expense lines" mappedBy="generalExpense"/>
      <one-to-many name="kilometricExpenseLineList" ref="com.axelor.apps.hr.db.ExpenseLine" title="Kilometric lines" mappedBy="kilometricExpense"/>

      <decimal name="exTaxTotal" title="Total W.T." scale="2" precision="20" readonly="true"/>
   	  <decimal name="taxTotal" title="Total tax" scale="2" precision="20" readonly="true"/>
      <decimal name="inTaxTotal" title="Total A.T.I." scale="2" precision="20" readonly="true"/>
      <many-to-one name="company" ref="com.axelor.apps.base.db.Company"/>
      <date name="moveDate" title="Move Date"/>
      <many-to-one name="move" ref="com.axelor.apps.account.db.Move"/>
      <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"/>
      <boolean name="ventilated"/>
      <integer name="companyCbSelect" title="Expense paid with company's credit card" selection="hr.expense.company.cb.payment" default="1"/>
      <many-to-one name="payrollPreparation" ref="com.axelor.apps.hr.db.PayrollPreparation"/>
      <boolean name="multipleUsers" title="Multiple users" default="false"/>
      <one-to-many name="employeeAdvanceUsageList" ref="com.axelor.apps.hr.db.EmployeeAdvanceUsage" mappedBy="expense" title="Employee advances" readonly="true" orphanRemoval="false"/>
      <decimal name="advanceAmount" title="Advance" />
      <decimal name="withdrawnCash" title="Withdrawn cash" />
      <decimal name="personalExpenseAmount" title="Personal expense amount" hidden="true" />
      
      <!-- Payment -->
      <date name="paymentDate" title="Payment Date" readonly="true"/>
  	  <many-to-one name="paymentMode" ref="com.axelor.apps.account.db.PaymentMode" title="Payment mode"/>
  	  <many-to-one name="bankOrder" ref="com.axelor.apps.bankpayment.db.BankOrder" readonly="true" title="Bank Order"/>
  	  <decimal name="paymentAmount" title="Payment amount" readonly="true" />
  	  <integer name="paymentStatusSelect" title="Payment Status" selection="invoice.payment.status.select" readonly="true" default="0"/>
      <many-to-one name="paymentMove" ref="com.axelor.apps.account.db.Move"/>

      <string name="fullName" namecolumn="true" readonly="true">
      <![CDATA[
      String fullName = "";
      if(this.getUser() != null)  {
      	 fullName = this.getUser().getFullName();
      }
      if(this.getCreatedOn() != null){
      	fullName = fullName.concat(" ").concat(this.getCreatedOn().format(java.time.format.DateTimeFormatter.ofPattern("yyyyMMdd HH:mm")));
      }
      return fullName;
	  ]]>
      </string>

      <many-to-one name="bankDetails" ref="com.axelor.apps.base.db.BankDetails" title="Bank"/>
      
      <unique-constraint columns="expenseSeq,company"/>
	
      <extra-code>
      	<![CDATA[
      		//STATUS SELECT
	  		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_REIMBURSED = 4;
	  		public static final int STATUS_REFUSED = 5;
	  		public static final int STATUS_CANCELED = 6;

            public static final int COMPANY_CB_PAYMENT_NO = 1;
            public static final int COMPANY_CB_PAYMENT_COMPANYS_CREDIT_CARD = 2;
	  ]]>
      </extra-code>
  </entity>
  
</domain-models>
