<?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="bank-payment" package="com.axelor.apps.bankpayment.db"/>

  <entity name="BankOrder" lang="java" sequential="true">
  
  	<integer name="orderTypeSelect" title="Order Type" selection="bankpayment.bank.order.type.select"/>
  	<integer name="rejectStatusSelect" title="Rejection Status" selection="bankpayment.bank.order.reject.status.select"/>
  	<string name="bankOrderSeq" title="Sequence" namecolumn="true" readonly="true"/>
  	<integer name="partnerTypeSelect" title="Partner Type" selection="bankpayment.bank.order.partner.type.select" required="true"/>
  	<integer name="statusSelect" title="Status" default="1" readonly="true" selection="bankpayment.bank.order.status.select"/>
	<date name="bankOrderDate" title="Bank order due Date"/>
	<many-to-one name="paymentMode" ref="com.axelor.apps.account.db.PaymentMode" title="Payment Mode"/>
	<many-to-one name="bankOrderFileFormat" ref="com.axelor.apps.bankpayment.db.BankOrderFileFormat" title="File format" required="true"/>
	<datetime name="confirmationDateTime" title="Confirmation date"/>
	<datetime name="validationDateTime" title="Validation date"/>
	<datetime name="fileGenerationDateTime" title="File generation date"/>
	<datetime name="sendingDateTime" title="Sending date"/>
	<many-to-one name="bankOrderCurrency" ref="com.axelor.apps.base.db.Currency" title="Currency"/>
	<many-to-one name="companyCurrency" ref="com.axelor.apps.base.db.Currency" title="Company currency"/>
	<boolean name="isMultiDate" title="Multidate"/>
	<boolean name="isMultiCurrency" title="Multicurrency"/>
	<decimal name="arithmeticTotal" title="Arithmetic total" readonly="true"/>
	<boolean name="testMode" title="Test mode"/>
    <many-to-one name="batch" ref="com.axelor.apps.base.db.Batch" title="Batch" />
    <integer name="technicalOriginSelect" title="Technical Origin" selection="bankpayment.bank.order.technical.origin.select" default="0"/>

	<!-- Sender -->
	<many-to-one name="senderCompany" ref="com.axelor.apps.base.db.Company" title="Company"/>
	<many-to-one name="senderBankDetails" ref="com.axelor.apps.base.db.BankDetails" title="Bank Account"/>
	<decimal name="bankOrderTotalAmount" title="Total amount"/>
	<decimal name="companyCurrencyTotalAmount" title="Total amount in company currency" readonly="true"/>
	<string name="senderReference" title="Reference"/>
	<string name="senderLabel" title="Label"/>
	<integer name="nbOfLines" title="Number of lines"/>
	
	<!-- Receiver -->
	<one-to-many name="bankOrderLineList" ref="BankOrderLine" mappedBy="bankOrder" title="Bank Order Lines" orderBy="counter"/>
	
	<many-to-one name="signatoryUser" ref="com.axelor.auth.db.User" title="Signatory"/>
	<many-to-one name="signatoryEbicsUser" ref="com.axelor.apps.bankpayment.db.EbicsUser" title="Signatory"/>
	<many-to-one name="generatedMetaFile" ref="com.axelor.meta.db.MetaFile" title="Generated file" />
	<many-to-one name="signedMetaFile" ref="com.axelor.meta.db.MetaFile" title="Signed file" />

	<unique-constraint columns="bankOrderSeq,senderCompany"/>
	
	<extra-code><![CDATA[
	
	   	// BANK ORDER TYPE SELECT
		public static final int ORDER_TYPE_SEPA_CREDIT_TRANSFER = 1;
		public static final int ORDER_TYPE_SEPA_DIRECT_DEBIT = 2;
		public static final int ORDER_TYPE_INTERNATIONAL_CREDIT_TRANSFER = 3;
		public static final int ORDER_TYPE_INTERNATIONAL_DIRECT_DEBIT = 4;
		public static final int ORDER_TYPE_NATIONAL_TREASURY_TRANSFER = 5;
		public static final int ORDER_TYPE_INTERNATIONAL_TREASURY_TRANSFER = 6;
		public static final int ORDER_TYPE_SEND_BANK_ORDER = 7;
	
	   	// STATUS SELECT
		public static final int STATUS_DRAFT = 1;
		public static final int STATUS_AWAITING_SIGNATURE = 2;
		public static final int STATUS_VALIDATED = 3;
		public static final int STATUS_CARRIED_OUT = 4;
		public static final int STATUS_REJECTED = 5;
		public static final int STATUS_CANCELED = 6;

		
		// PARTNER TYPE SELECT
		public static final int PARTNER_TYPE_SUPPLIER = 1;
		public static final int PARTNER_TYPE_EMPLOYEE = 2;
		public static final int PARTNER_TYPE_CUSTOMER = 3;
		public static final int PARTNER_TYPE_COMPANY = 4;
		
		
		// REJECT STATUS SELECT
		public static final int REJECT_STATUS_NOT_REJECTED = 0;
		public static final int REJECT_STATUS_PARTIALLY_REJECTED = 1;
		public static final int REJECT_STATUS_TOTALLY_REJECTED = 2;
		
		//TECHNICAL ORIGIN SELECT
		public static final int TECHNICAL_ORIGIN_ENTRY = 0;
		public static final int TECHNICAL_ORIGIN_AUTOMATIC = 1;
		public static final int TECHNICAL_ORIGIN_IMPORT = 2;
	
	]]></extra-code>

	  <track>
		  <field name="bankOrderDate" on="UPDATE" if="statusSelect &gt; 1"/>
		  <field name="signatoryEbicsUser" on="UPDATE" if="statusSelect &gt; 1"/>
		  <field name="senderCompany" on="UPDATE" if="statusSelect &gt; 1"/>
		  <field name="senderBankDetails" on="UPDATE" if="statusSelect &gt; 1"/>
		  <field name="bankOrderTotalAmount" on="UPDATE" if="statusSelect &gt; 1"/>
		  <field name="bankOrderCurrency" on="UPDATE" if="statusSelect &gt; 1"/>
		  <field name="senderReference" on="UPDATE" if="statusSelect &gt; 1"/>
		  <field name="statusSelect" on="UPDATE" if="statusSelect &gt; 1"/>
		  <message if="statusSelect == 2" tag="info">Awaiting signature</message>
	  </track>

  </entity>

</domain-models>
