<?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="lunch-voucher-advance-grid" title="Lunch voucher advances" model="com.axelor.apps.hr.db.LunchVoucherAdvance" onNew="action-lunch-voucher-advance-record-default" orderBy="-distributionDate">
        <field name="distributionDate"/>
        <field name="nbrLunchVouchers" aggregate="sum"/>
        <field name="lunchVoucherWageShare"/>
        <field name="lunchVoucherEmployersShare"/>
        <field name="comments"/>
        <button name="printLunchVoucherAdvanceBtn" title="Print" icon="fa-print" onClick="action-lunch-voucher-advance-print"/>
    </grid>

	<form name="lunch-voucher-advance-form" title="Lunch voucher advance" model="com.axelor.apps.hr.db.LunchVoucherAdvance" onNew="action-lunch-voucher-advance-record-default" width="large">
		<panel name="mainPanel">
			<field name="distributionDate"/>
	        <field name="nbrLunchVouchers"/>
	        <field name="lunchVoucherWageShare"/>
	        <field name="lunchVoucherEmployersShare"/>
		</panel>
		<panel name="commentPanel" title="Comment">
			<field name="comments" colSpan="12" showTitle="false" widget="Text"/>
		</panel>
	</form>
	
	<action-record name="action-lunch-voucher-advance-record-default" model="com.axelor.apps.hr.db.LunchVoucherAdvance">
		<field name="distributionDate" expr="eval: __date__"/>
		<field name="lunchVoucherWageShare" expr="eval: __user__.activeCompany?.hrConfig?.lunchVoucherWageShare"/>
		<field name="lunchVoucherEmployersShare" expr="eval: __user__.activeCompany?.hrConfig?.lunchVoucherEmployersShare"/>
	</action-record>
	
	<!-- Create a new lunch voucher advance from an employee -->
	
	<action-view name="action-lunch-voucher-advance-new" title="Lunch voucher advance" model="com.axelor.apps.hr.db.LunchVoucherAdvance">
		<view type="form" name="lunch-voucher-advance-new-form"/>
		<view-param name="popup" value="reload"/>
		<view-param name="show-toolbar" value="false"/>
    	<view-param name="show-confirm" value="false" />
    	<view-param name="popup-save" value="false"/>
		<context name="_xEmployeeId" expr="eval: __this__.id"/>
	</action-view>
	
	<form name="lunch-voucher-advance-new-form" title="Lunch voucher advance" model="com.axelor.apps.hr.db.LunchVoucherAdvance" onNew="action-lunch-voucher-advance-new-record-default" width="large">
		<panel name="mainPanel">
			<field name="distributionDate"/>
	        <field name="nbrLunchVouchers"/>
	        <field name="lunchVoucherWageShare"/>
	        <field name="lunchVoucherEmployersShare"/>
		</panel>
		<panel name="commentPanel" title="Comment">
			<field name="comments" colSpan="12" showTitle="false" widget="Text"/>
		</panel>
		<panel name="otherDetailPanel">
			<button name="createNewAdvanceBtn" title="Validate the advance" onClick="action-lunch-voucher-advance-group-onNewAdvance"/>
			<field name="employee" hidden="true" canNew="false" canEdit="false" canView="false"/>
		</panel>
	</form>
	
	<action-record name="action-lunch-voucher-advance-new-record-default" model="com.axelor.apps.hr.db.LunchVoucherAdvance">
		<field name="distributionDate" expr="eval: __date__"/>
		<field name="lunchVoucherWageShare" expr="eval: __user__.activeCompany?.hrConfig?.lunchVoucherWageShare"/>
		<field name="lunchVoucherEmployersShare" expr="eval: __user__.activeCompany?.hrConfig?.lunchVoucherEmployersShare"/>
		<field name="employee" expr="eval: __repo__(Employee).find(_xEmployeeId)" if="_xEmployeeId != null"/>
	</action-record>
	
	<action-group name="action-lunch-voucher-advance-group-onNewAdvance">
		<action name="action-lunch-voucher-advance-checkNewAdvance"/>
		<action name="action-lunch-voucher-advance-onNewAdvance"/>
	</action-group>
	
	<action-method name="action-lunch-voucher-advance-onNewAdvance">
		<call class="com.axelor.apps.hr.web.lunch.voucher.LunchVoucherAdvanceController" method="onNewAdvance"/>
	</action-method>
	
	<action-method name="action-lunch-voucher-advance-checkNewAdvance">
		<call class="com.axelor.apps.hr.web.lunch.voucher.LunchVoucherAdvanceController" method="checkOnNewAdvance"/>
	</action-method>

	<action-method name="action-lunch-voucher-advance-print">
		<call class="com.axelor.apps.hr.web.lunch.voucher.LunchVoucherAdvanceController" method="print"/>
	</action-method>
	
</object-views>
