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

  <entity name="BankDetails" lang="java">

    <many-to-one name="partner" ref="Partner" title="Partner"/>
    <string name="ownerName" title="Owner name" max="255"/>
    <many-to-one name="bank" title="BIC (Bank Identifier)" ref="com.axelor.apps.base.db.Bank" required="true"/>
    <many-to-one name="bankAddress" title="SWIFT address" ref="com.axelor.apps.base.db.BankAddress"/>
    <string name="iban" title="IBAN / BBAN" required="true"/>
    <many-to-one name="currency" ref="com.axelor.apps.base.db.Currency" title="Currency"/>
    <string name="bankCode" title="Bank Code" max="255"/>
    <string name="sortCode" title="Sort Code" max="255"/>
    <string name="accountNbr" title="Account Number" max="255" />
    <string name="bbanKey" title="BBan Key" max="255"/>
    <string name="ibanBic" title="IBAN / BBAN + BIC" max="255"/>
    <string name="label" title="Label"/>
    <boolean name="isDefault" title="Default" />
    <string name="fullName" title="Bank Details" search="ownerName" namecolumn="true">
        <![CDATA[
            String str = "";
            if (!(ownerName == null || ownerName.isEmpty())) {
                str = ownerName;
                if (!(ibanBic == null || ibanBic.isEmpty())) {
                    str = str.concat(" - ").concat(ibanBic);
                } else if (!(iban == null || iban.isEmpty())) {
                    str = str.concat(" - ").concat(iban);
                } else if (!(bankCode == null || bankCode.isEmpty())
                        && !(sortCode == null || sortCode.isEmpty())
                        && !(accountNbr == null || accountNbr.isEmpty())
                        && !(bbanKey == null || bbanKey.isEmpty())) {
                    str = str.concat(" - ").concat(bankCode)
                                           .concat(sortCode)
                                           .concat(accountNbr)
                                           .concat(bbanKey);
                }
                if (!(code == null || code.isEmpty())) {
                    str = str.concat(" - ").concat(code);
                }
            }
            return str;
        ]]>
    </string>
    <boolean name="active" title="Active" default="true"/>
    <string name="code" />

	<finder-method name="findDefaultByPartner" using="partner"
		filter="self.partner = :partner AND self.isDefault = TRUE" />
    <finder-method name="findActivesByPartner" using="partner,active" all="true"/>

  </entity>

</domain-models>
