<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<object-views xmlns="http://axelor.com/xml/ns/object-views"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://axelor.com/xml/ns/object-views http://axelor.com/xml/ns/object-views/object-views_5.2.xsd">

	<grid name="accounting-batch-grid" title="Accounting batches" model="com.axelor.apps.account.db.AccountingBatch">
		<field name="actionSelect" />
		<field name="code" x-bind="{{code|unaccent|uppercase}}" />
		<field name="company" form-view="company-form" grid-view="company-grid" if="__config__.app.getApp('base').getEnableMultiCompany()"/>
		<field name="createdOn"/>
		<field name="createdBy" form-view="user-form" grid-view="user-grid"/>
	</grid>
 
<form  onNew="action-accounting-batch-record-on-new" name="accounting-batch-form" title="Accounting Batch" model="com.axelor.apps.account.db.AccountingBatch">
	<panel name="mainPanel" >
		<field name="actionSelect" onChange="action-accounting-batch-record-default-currency"/>
		<field name="code" x-bind="{{code|unaccent|uppercase}}" onChange="action-base-batch-condition-check-unique-code"/>
		<field name="company" canEdit="false" widget="SuggestBox" form-view="company-form" grid-view="company-grid" onChange="action-accounting-batch-attrs-set-empty-year-and-accountset-value"/>
		<field name="bankDetails" hideIf="actionSelect &amp;&amp; ([14,15,16,17,18,21].indexOf(actionSelect) &gt; -1 || (actionSelect == 11 &amp;&amp; reimbursementTypeSelect == 2) || (actionSelect == 12 &amp;&amp; directDebitDataTypeSelect == 2))" widget="SuggestBox" onSelect="action-accounting-batch-attrs-bank-details-domain" form-view="bank-details-form" grid-view="bank-details-grid"/>
		<field name="archived" title="Archived"/>
	</panel>
	<panel-tabs name="mainPanelTab">
		<panel name="reimbursementPagePanel" title="Reimbursement configuration" hideIf="actionSelect != 11">
			<field name="reimbursementTypeSelect"/>
			<field name="reimbursementExportTypeSelect" hideIf="reimbursementTypeSelect != 1"/>
			<field name="currency" canEdit="false" readonly="true" grid-view="currency-grid" form-view="currency-form"/>
		</panel>
		<panel name="directDebitPagePanel" title="Direct debit configuration" hideIf="actionSelect != 12">
			<field name="directDebitDataTypeSelect" />
			<field name="paymentMode"
				domain="self.typeSelect = 2 AND self.inOutSelect = 1 AND self.generateBankOrder = TRUE"
				grid-view="payment-mode-grid" form-view="payment-mode-form" />
			<field name="dueDate" />
			<field name="currency" />
			<field name="includeOtherBankAccounts" if="__config__.app.getApp('base').getManageMultiBanks()" />
		</panel>
		<panel name="creditTransferPagePanel" title="Credit Transfer configuration" hideIf="actionSelect != 19">
			<field name="creditTransferTypeSelect"/>
			<field name="customerReimbursementTypeSelect" showIf="$contains([3], creditTransferTypeSelect)" />
			<field name="paymentMode" domain="self.typeSelect in (2,9)" grid-view="payment-mode-grid" form-view="payment-mode-form"/>
			<field name="period" showIf="$contains([1], creditTransferTypeSelect)" form-view="period-form" grid-view="period-grid" canEdit="false" canView="false"/>
			<field name="dueDate" showIf="$contains([2, 3], creditTransferTypeSelect)" />
			<field name="currency" showIf="$contains([2, 3], creditTransferTypeSelect)" />
			<field name="includeOtherBankAccounts" showIf="$contains([1, 2, 3], creditTransferTypeSelect)" if="__config__.app.getApp('base').getManageMultiBanks()" />
		</panel>

		<panel name="debtRecoveryPagePanel" title="Debt recovery configuration" hideIf="actionSelect != 14"  >
			<field name="debtRecoveryTypeSelect"/>
		</panel>

		<panel name="accountCustomerPagePanel" title="Account calculation configuration" hideIf="actionSelect != 17">
			 <field name="updateCustAccountOk"/>
			 <field name="updateDueCustAccountOk"/>
			 <field name="updateDueDebtRecoveryCustAccountOk"/>
		</panel>
		<panel name="moveLineExportPagePanel" title="Move Lines Export Config" hideIf="actionSelect != 18">
			<field name="moveLineExportTypeSelect"/>
			<field name="startDate"/>
			<field name="endDate"/>
		</panel>
		<panel name="yearOpeningOrClosureAccountsPagePanel" title="Close/open the accounts" hideIf="actionSelect != 21">
<!-- 		TODO FILTER ON STATUS -->
			<field name="closeYear"/>
			<field name="openYear"/>
			<field name="year" domain="self.typeSelect = 1 AND self.company = :company AND (self.statusSelect = 1 OR :closeYear is false)" canEdit="false"/>		
			<field name="allocatePerPartner"/>
    		<field name="year.toDate" showIf="closeYear" hidden="true"/>
    		<field name="year.reportedBalanceDate" showIf="openYear" hidden="true"/>
    		<field name="moveDescription"/>
			<field name="accountSet" colSpan="12" form-view="account-form" grid-view="account-grid" widget="TagSelect" canNew="false" canEdit="false" domain="self.company = :company"/> 
<!-- 			<field name="journalSet" colSpan="12" form-view="journal-form" grid-view="journal-grid" widget="TagSelect" canNew="false" domain="self.company = :company"/> -->
		</panel>
		<panel name="informationPanel" title="Information"  >
			<field name="createdOn" title="Created on"/>
			<field name="createdBy" title="Created by" form-view="user-form" grid-view="user-grid"/>
			<field name="description" showTitle="false"  />
	      	<panel-related name="batchListPanel" field="batchList" colSpan="12" form-view="batch-form" grid-view="batch-grid" readonly="true"/>
		</panel>
	</panel-tabs>
	<panel name="actionsPanel" sidebar="true" title="Actions">
	    <button name="reimbursementBatchBtn" title="Reimbursement Batch" showIf="actionSelect == 11"  onClick="save,action-accounting-batch-method-action-reimbursement" colSpan="12"/>
	    <button name="directDebitBatchBtn" title="Direct Debit Batch" showIf="actionSelect == 12"  onClick="save,action-accounting-batch-method-action-direct-debit" colSpan="12"/>
	    <button name="debtRecoveryBatchBtn" title="Debt recovery Batch" showIf="actionSelect == 14" onClick="save,action-accounting-batch-method-action-debt-recovery" colSpan="12"/>
	    <button name="doubtfulCustomerBatchBtn" title="Doubtful Customer Batch" showIf="actionSelect == 16" onClick="save,action-accounting-batch-method-action-doubtful-customer" colSpan="12"/>
	    <button name="accountCustomerBatchBtn" title="Start" showIf="actionSelect == 17"  onClick="save,action-accounting-batch-method-action-account-customer" colSpan="12"/>
	    <button name="moveLineExportBatchBtn" title="Start" showIf="actionSelect == 18"  onClick="save,action-accounting-batch-method-action-move-line-export" colSpan="12"/>
	    <button name="creditTransferBatchBtn" title="Credit Transfer Batch" showIf="actionSelect == 19" onClick="save,action-accounting-batch-method-action-credit-transfer" colSpan="12"/>
	    <button name="realizeFixedAssetLinesBatchBtn" title="Realize Fixed asset lines Batch" showIf="actionSelect == 20" onClick="save,action-accounting-batch-method-action-fixed-asset-lines-realize" colSpan="12"/>
	    <button name="closeAnnualAccountsBatchBtn" title="Start" showIf="actionSelect == 21" onClick="save,action-accounting-batch-group-close-annual-accounts" colSpan="12"/>
	</panel>
</form>

    <!-- ACTION GROUP -->
	<action-group name="action-accounting-batch-group-close-annual-accounts">
		<action name="action-accounting-batch-validate-batchlist-not-empty"/>
		<action name="action-accounting-batch-method-action-close-annual-accounts"/>
	</action-group>
    
    
    <!-- ACTION RECORD -->
    <action-record name="action-accounting-batch-record-on-new" model="com.axelor.apps.account.db.AccountingBatch">
		<field name="createdOn" expr="eval: __config__.app.getTodayDate()"/>
		<field name="createdBy" expr="eval:__user__"/>
		<field name="company"  expr="eval:__user__.activeCompany" if="__user__.activeCompany != null"/>
    	<field name="company"  expr="eval:__repo__(Company).all().fetchOne()" if="__user__.activeCompany == null &amp;&amp; __repo__(Company).all().fetch().size == 1"/>
	</action-record>
    
    <action-record name="action-accounting-batch-record-default-currency" model="com.axelor.apps.account.db.AccountingBatch">
    	<field name="currency" expr="eval: company?.currency" if="[11, 12, 15, 19].indexOf(actionSelect) >= 0"/>
    </action-record>
    
    <!-- ACTION METHOD -->
	<action-method name="action-accounting-batch-method-action-reimbursement">
		<call class="com.axelor.apps.account.web.AccountingBatchController" method="actionReimbursement"/>
	</action-method>
	
	<action-method name="action-accounting-batch-method-action-direct-debit">
		<call class="com.axelor.apps.account.web.AccountingBatchController" method="actionDirectDebit"/>
	</action-method>
	
	<action-method name="action-accounting-batch-method-action-debt-recovery">
		<call class="com.axelor.apps.account.web.AccountingBatchController" method="actionDebtRecovery"/>
	</action-method>
	
	<action-method name="action-accounting-batch-method-action-doubtful-customer">
		<call class="com.axelor.apps.account.web.AccountingBatchController" method="actionDoubtfulCustomer"/>
	</action-method>
	
	<action-method name="action-accounting-batch-method-action-account-customer">
		<call class="com.axelor.apps.account.web.AccountingBatchController" method="actionAccountingCustomer"/>
	</action-method>
	
	<action-method name="action-accounting-batch-method-action-move-line-export">
		<call class="com.axelor.apps.account.web.AccountingBatchController" method="actionMoveLineExport"/>
	</action-method>
	
	<action-method name="action-accounting-batch-method-action-credit-transfer">
		<call class="com.axelor.apps.account.web.AccountingBatchController" method="actionCreditTransfer"/>
	</action-method>
	
	<action-method name="action-accounting-batch-method-action-fixed-asset-lines-realize">
		<call class="com.axelor.apps.account.web.AccountingBatchController" method="actionRealizeFixedAssetLines"/>
	</action-method>
	
	<action-method name="action-accounting-batch-method-action-close-annual-accounts">
		<call class="com.axelor.apps.account.web.AccountingBatchController" method="actionCloseAnnualAccounts"/>
	</action-method>
	
	<!-- ACTION VALIDATE -->
	<action-validate name="action-accounting-batch-validate-batchlist-not-empty">
   		<alert message="The batch to close the annual accounts has already ran. Are you sure you want to continue ?" if="eval: batchList &amp;&amp; !batchList?.empty" />
   	</action-validate>

    <!-- ACTION ATTRS -->
    
    <action-attrs name="action-accounting-batch-attrs-bank-details-domain">
        <attribute name="domain" expr="eval: &quot;self.id IN (${company?.bankDetailsSet?.collect{it.id}.join(',')},${company?.defaultBankDetails?.id}) AND self.active = true&quot;" for="bankDetails"
        	if="!company.bankDetailsSet.isEmpty()"/>
       	<attribute name="domain" expr="eval: &quot;self.id = ${company?.defaultBankDetails?.id} AND self.active = true&quot;" for="bankDetails"
        	if="company.bankDetailsSet.isEmpty()"/>
    </action-attrs>
    
    <action-attrs name="action-accounting-batch-attrs-set-empty-year-and-accountset-value">
    	<attribute name="value" expr="eval: null" for="year,accountSet"/>
    </action-attrs>

</object-views>
