<?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 http://axelor.com/xml/ns/domain-models/domain-models_5.2.xsd">

	<module name="contract" package="com.axelor.apps.contract.db" />

	<entity name="ContractVersion" repository="abstract">

		<integer name="statusSelect" title="Status" selection="contract.version.status.select" default="1" required="true" copy="false"/>
		<integer name="invoicingMomentSelect" selection="contract.version.invoicing.moment.select" title="Invoicing moment" default="1"/>
		<integer name="numberOfDays" title="Number of days"/>

		<string name="description" title="Description" multiline="true" large="true" />

		<boolean name="doNotRenew" title="Do not renew" default="false" />
		<boolean name="automaticInvoicing" title="Automatic invoicing" default="false"/>
		<boolean name="isPeriodicInvoicing" title="Periodic Invoicing" default="false"/>
		<boolean name="isProratedInvoice" title="Prorated Invoice" default="false"/>
		<boolean name="isProratedFirstInvoice" title="Prorated Starting periods" default="false"/>
		<boolean name="isProratedLastInvoice" title="Prorated finished periods" default="false"/>
		<boolean name="isTimeProratedInvoice" title="Prorated temporally" />
		<boolean name="isVersionProratedInvoice" title="Prorate from versions" />
		<boolean name="isTacitRenewal" title="Tacit renewal"/>
		<boolean name="isAutoEnableVersionOnRenew" title="Auto enable version on renew"/>
		<boolean name="isWithEngagement" title="With engagement"/>
		<boolean name="engagementStartFromVersion" title="Engagement start from version"/>
		<boolean name="isWithPriorNotice" title="With prior notice"/>
		<boolean name="isConsumptionBeforeEndDate" title="Only invoice consumption before Invoice period end Date" />
		<boolean name="isConsumptionManagement" title="Consumption management" default="false"/>

		<date name="supposedActivationDate" title="Supposed activation date" copy="false"/>
		<date name="activationDate" title="Activation date" copy="false"/>
		<date name="supposedEndDate" title="Supposed end date" copy="false"/>
		<date name="endDate" title="End date" copy="false"/>

		<many-to-one name="activatedByUser" ref="com.axelor.auth.db.User" title="Activated By" copy="false"/>
		<many-to-one name="paymentMode" ref="com.axelor.apps.account.db.PaymentMode" title="Payment mode"/>
		<many-to-one name="paymentCondition" ref="com.axelor.apps.account.db.PaymentCondition" title="Payment condition"/>
		<many-to-one name="invoicingDuration" ref="com.axelor.apps.base.db.Duration" title="Invoicing Frequency"/>
		<many-to-one name="contractHistory" ref="com.axelor.apps.contract.db.Contract" title="Contract" copy="false"/>
		<many-to-one name="renewalDuration" title="Renewal duration" ref="com.axelor.apps.base.db.Duration" />
		<many-to-one name="engagementDuration" title="Engagement duration" ref="com.axelor.apps.base.db.Duration" />
		<many-to-one name="priorNoticeDuration" title="Prior notice duration" ref="com.axelor.apps.base.db.Duration" />
		<many-to-one name="metaFile" ref="com.axelor.meta.db.MetaFile"/>

		<one-to-one name="contract" ref="com.axelor.apps.contract.db.Contract" title="Contract" mappedBy="currentContractVersion" copy="false"/>
		<one-to-one name="nextContract" ref="com.axelor.apps.contract.db.Contract" title="Contract" mappedBy="nextVersion" copy="false"/>

        <one-to-many name="contractLineList" ref="com.axelor.apps.contract.db.ContractLine" title="Invoicing content" mappedBy="contractVersion"/>

		<string name="fullName" namecolumn="true">
			<![CDATA[
	  		String fullName = "";
	  		if(contract != null && contract.getName() != null)  {
				fullName += contract.getName();
				if (contract.getVersionNumber() != null && contract.getVersionNumber() != 0){
					fullName += " " +  contract.getVersionNumber();
				}
			}
			
	  		return fullName;
	  	]]>
		</string>

		<extra-code><![CDATA[
            public static final int DRAFT_VERSION = 1;
            public static final int WAITING_VERSION = 2;
            public static final int ONGOING_VERSION = 3;
            public static final int TERMINATED_VERSION = 4;

            public static final int END_INVOICING_MOMENT = 1;
            public static final int BEGIN_INVOICING_MOMENT = 2;
            public static final int END_INVOICING_MOMENT_PLUS = 3;
            public static final int BEGIN_INVOICING_MOMENT_PLUS = 4;
		]]></extra-code>

	</entity>

</domain-models>
