<?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="forecast-recap-grid" title="Forecast Recaps" model="com.axelor.apps.cash.management.db.ForecastRecap">
		<field name="company" if="__config__.app.getApp('base').getEnableMultiCompany()"/>
		<field name="bankDetails" if="__config__.app.getApp('base').getManageMultiBanks()"/>
		<field name="fromDate"/>
		<field name="toDate"/>
	</grid>
 
	 <form name="forecast-recap-form" title="Forecast Recap" model="com.axelor.apps.cash.management.db.ForecastRecap"
	 	onNew="action-forecast-recap-record-default-on-new" width="large">
	 	<toolbar>
			<button name="printBtn" title="Print" icon="fa-print" onClick="save,action-forecast-recap-view-reports-wizard"/>
	 	</toolbar>
	 	<panel name="mainPanel" >
	 	   <panel name="seqPanel" colSpan="12">
                       <field name="forecastRecapSeq" showTitle="false" colSpan="12" css="label-bold bold large"/>
                   </panel>
		   <field name="company" canEdit="false" onChange="action-forecast-record-bank, action-forecast-recap-record-currency"/>
	       	   <field name="bankDetails" onSelect="action-accounting-batch-attrs-bank-details-domain" if="__config__.app.getApp('base').getManageMultiBanks()"/>
	       	   <field name="fromDate" onChange="action-forecast-recap-validate-dates"/>
       		   <field name="toDate" onChange="action-forecast-recap-validate-dates"/>
       		   <field name="opportunitiesTypeSelect"/>
       		   <field name="startingBalance"/>
       		   <button name="populateRecapBtn" title="Populate" onClick="action-forecast-recap-validate-dates-before-populate,save,action-forecast-recap-method-populate"/>
       		   <panel-dashlet name="forecastRecapLineListPanel" showIf="id" height="500" action="action-forecast-recap-view-show-forecast-recap-line-list" colSpan="12"/>
       		   <field name="endingBalance" readonly="true" colSpan="4"/>
       		   <field name="currency" readonly="true" colSpan="4"/>
       		   <field name="calculationDate" colSpan="4"/>
       		   <field name="isReport" hidden="true"/>
	 	</panel>
	 </form>
	 
	 <form model="com.axelor.apps.base.db.Wizard" title="Reports" name="forecast-recap-print-wizard-form">
		<panel name="mainPanel">
			<field name="$reportTypeSelect" title="Format" selection="forecast.recap.report.type.select" colSpan="3" type="string"/>
			<button name="printBtn" title="Print" onClick="action-forecast-recap-method-print" readonlyIf="$reportTypeSelect == null" colSpan="3"/>
		</panel>
	</form>

	 <grid name="forecast-report-grid" title="Forecast Reports" model="com.axelor.apps.cash.management.db.ForecastRecap">
       <field name="company"/>
       <field name="bankDetails" if="__config__.app.getApp('base').getManageMultiBanks()"/>
       <field name="fromDate"/>
       <field name="toDate"/>
    </grid>
 
	 <form name="forecast-report-form" title="Forecast Report" model="com.axelor.apps.cash.management.db.ForecastRecap"
	 	onNew="action-forecast-report-record-default-on-new">
	 	<panel name="mainPanel" >
			<field name="company" canEdit="false" onChange="action-forecast-record-bank, action-forecast-recap-record-currency" colSpan="4" required="true"/>
	       	<field name="bankDetails" onSelect="action-accounting-batch-attrs-bank-details-domain" if="__config__.app.getApp('base').getManageMultiBanks()" colSpan="4"/>
	       	<field name="salesMan" canNew="false" canEdit="false" canView="false" colSpan="4"/>
	       	<field name="fromDate" onChange="action-forecast-recap-validate-dates" required="true"/>
       		<field name="toDate" onChange="action-forecast-recap-validate-dates" required="true"/>
       		<field name="opportunitiesTypeSelect" colSpan="12" width="50%"/>
       		<field name="displayTypeSelect"/>
       		<button name="updateBtn" title="Update" onClick="save, action-forecast-report-refresh"/>
       		<panel-dashlet name="reportDashletSalesPanel" action="forecast.report.sales.dashlet" colSpan="12" hideIf="displayTypeSelect == 2"/>
       		<panel-dashlet name="reportDashletSpendingPanel" action="forecast.report.spending.dashlet" colSpan="12" hideIf="displayTypeSelect == 1"/>
       		<panel-dashlet name="reportDashletMargesPanel" action="forecast.report.marges.dashlet" colSpan="12" hideIf="displayTypeSelect != 3"/>
       		<field name="isReport" hidden="true"/>
	 	</panel>
	 </form>
	 
	 <action-view title="Sales" name="forecast.report.sales.dashlet">
	  <view type="chart" name="chart.forecast.report.sales"/>
	  <context name="_id" expr="eval: id" />
	</action-view>
	
	<action-view title="Spending" name="forecast.report.spending.dashlet">
	  <view type="chart" name="chart.forecast.report.spending"/>
	  <context name="_id" expr="eval: id" />
	</action-view>
	
	<action-view title="Marges" name="forecast.report.marges.dashlet">
	  <view type="chart" name="chart.forecast.report.marges"/>
	  <context name="_id" expr="eval: id" />
	</action-view>
	
	<action-view name="action-forecast-recap-view-show-forecast-recap-line-list" title="Details" model="com.axelor.apps.cash.management.db.ForecastRecapLine">
		<view type="grid" name="forecast-recap-line-grid"/>
		<view type="form" name="forecast-recap-line-form"/>
		<view-param name="limit" value="100"/>
		<domain>self.forecastRecap.id = :forecastRecap</domain>
		<context name="forecastRecap" expr="eval: __self__?.id"/>
	</action-view>
	 
	 <action-attrs name="action-forecast-report-refresh">
	  <attribute for="reportDashlet" name="refresh" expr="true"/>
	</action-attrs>
	 
	 <action-record name="action-forecast-recap-record-currency" model="com.axelor.apps.cash.management.db.ForecastRecap">
	 	<field name="currency" expr="company?.currency"/>
	 </action-record>
	 
	 <action-record name="action-forecast-recap-record-default-on-new" model="com.axelor.apps.cash.management.db.ForecastRecap">
	 	<field name="company" expr="eval: __user__.activeCompany"/>
	 	<field name="currency" expr="eval: __user__.activeCompany?.currency"/>
	 	<field name="isReport" expr="eval: false"/>
	 </action-record>
	 
	 <action-record name="action-forecast-report-record-default-on-new" model="com.axelor.apps.cash.management.db.ForecastRecap">
	 	<field name="company" expr="eval: __user__.activeCompany"/>
	 	<field name="currency" expr="eval: __user__.activeCompany?.currency"/>
	 	<field name="isReport" expr="eval: true"/>
	 </action-record>
	 
	 <action-validate name="action-forecast-recap-validate-dates">
		<error message="Invalid dates" if="toDate != null &amp;&amp; fromDate != null &amp;&amp; toDate &lt; fromDate" action="action-forecast-recap-null-toDate"/>
	</action-validate>
	
	<action-record name="action-forecast-recap-null-toDate" model="com.axelor.apps.cash.management.db.ForecastRecap">
		<field name="toDate" expr="eval: null"/>
	</action-record>
	
	<action-validate name="action-forecast-recap-validate-dates-before-populate">
		<error message="Invalid dates" if="toDate == null || fromDate == null"/>
	</action-validate>
	
	<action-method name="action-forecast-recap-method-populate">
		<call class="com.axelor.apps.cash.management.web.ForecastRecapController" method="populate"/>
	</action-method>
	
	<action-view name="action-forecast-recap-view-reports-wizard" title="Reports"
		model="com.axelor.apps.cash.management.db.ForecastRecap" >
		<view type="form" name="forecast-recap-print-wizard-form" />
		<view-param name="popup" value="true"/>
		<view-param name="show-toolbar" value="false"/>
		<view-param name="show-confirm" value="false" />
		<view-param name="popup-save" value="false"/>
		<context name="_forecastRecapId" expr="eval: id"/>
	</action-view>

    <action-method name="action-forecast-recap-method-print">
		<call class="com.axelor.apps.cash.management.web.ForecastRecapController" method="print"/>
    </action-method>

</object-views>
