<?xml version="1.0" encoding="UTF-8"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements.  See the NOTICE file
distributed with this work for additional information
regarding copyright ownership.  The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License.  You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied.  See the License for the
specific language governing permissions and limitations
under the License.
-->

<screens xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns="http://ofbiz.apache.org/Widget-Screen" xsi:schemaLocation="http://ofbiz.apache.org/Widget-Screen http://ofbiz.apache.org/dtds/widget-screen.xsd">

    <screen name="GenericDecorator">
        <section>
            <actions>
                <set field="headerItem" value="chartofaccounts"/>
            </actions>
            <widgets>
                <!-- main defines the regions of the HTML page -->
                <decorator-screen name="main-decorator" location="${parameters.mainDecoratorLocation}">
                <!-- body is the primary display for this page and is called recursively -->
                    <decorator-section name="body">
                        <section>
                            <widgets>
                                <include-menu name="GlAccountTabBar" location="${parameters.mainMenuLocation}"/>

                                    <!-- label style="h1">List Accounts</label -->
                                    <label style="h1">${uiLabelMap[labelTitleProperty]}</label>

                                <!-- Now call the SimpleScreen form -->
                                <decorator-section-include name="body"/>
                            </widgets>
                            <!--
                            <fail-widgets>
                                <label style="h3">${uiLabelMap.XxxxViewPermissionError}</label>
                            </fail-widgets>
                            -->
                        </section>
                    </decorator-section>
                </decorator-screen>
            </widgets>
        </section>
    </screen>

    <screen name="CommonAccountDecorator">
        <section>
            <actions>
                <set field="glAccountId" from-field="parameters.glAccountId"/>
                <entity-one entity-name="GlAccount" value-field="glAccount"/>
            </actions>
            <widgets>
                <decorator-screen name="main-decorator" location="${parameters.mainDecoratorLocation}">
                    <decorator-section name="body">
                        <section>
                            <!-- do check for CATALOG, _VIEW permission -->
                            <!-- condition>
                                <if-has-permission permission="CATALOG" action="_VIEW"/>
                            </condition -->
                            <widgets>
                                <include-menu name="GlAccountTabBar" location="${parameters.mainMenuLocation}"/>
                                <label style="h1">${uiLabelMap[labelTitleProperty]} ${product.internalName} [${uiLabelMap.CommonId}:${productId}]</label>
                                <decorator-section-include name="body"/>
                            </widgets>
                            <!--
                            <fail-widgets>
                                <label style="h3">${uiLabelMap.XxxxViewPermissionError}</label>
                            </fail-widgets>
                            -->
                        </section>
                    </decorator-section>
                </decorator-screen>
            </widgets>
        </section>
    </screen>

    <screen name="AssignGlAccount">
        <section>
            <actions>
                <set field="titleProperty" value="AcctgAssignGlAccount"/>
                <set field="tabButtonItem" value="Chartofaccounts"/>
                <set field="tabButtonItem2" value="AssignGlAccount"/>
                <set field="helpAnchor" value="_help_for_assign_gl_account"/>
                <set field="labelTitleProperty" value="AcctgAssignGlAccount"/>

                <!-- <set field="accountId" from-field="parameters.accountId"/> -->
            </actions>
            <widgets>
                <decorator-screen name="GlobalGLSettingsDecorator" location="${parameters.mainDecoratorLocation}">
                    <decorator-section name="body">
                        <include-menu name="GlSettingTabBar" location="${parameters.mainMenuLocation}"/>
                        <screenlet title="${uiLabelMap.AcctgAssignGlAccount}">
                            <include-form name="AssignGlAccount" location="component://accounting/widget/GlobalGlAccountsForms.xml"/>
                        </screenlet>
                    </decorator-section>
                </decorator-screen>
            </widgets>
        </section>
    </screen>

    <screen name="GlAccountNavigate">
        <section>
            <actions>
                <set field="titleProperty" value="AcctgNavigateAccts"/>
                <set field="tabButtonItem" value="Chartofaccounts"/>
                <set field="tabButtonItem2" value="GlAccountNavigate"/>
                <set field="helpAnchor" value="_help_for_navigate_gl_accounts"/>
                <set field="labelTitleProperty" value="AcctgNavigateAccts"/>
                <!-- parameters includes requestAttributes and parameter map -->
                <!-- requestParameters is just the parameter map -->
                <set field="glAccountId" from-field="requestParameters.glAccountId"/>
                <set field="trail" from-field="requestParameters.trail"/>

                <entity-one entity-name="GlAccount" value-field="glAccount"/>
            </actions>
            <widgets>
                <decorator-screen name="GlobalGLSettingsDecorator" location="${parameters.mainDecoratorLocation}">
                    <decorator-section name="body">
                        <include-menu name="GlSettingTabBar" location="${parameters.mainMenuLocation}"/>
                        <screenlet title="${uiLabelMap.AcctgNavigateAccts}">
                            <include-tree name="GlAccountTree" location="component://accounting/widget/AccountingTrees.xml"/>
                        </screenlet>
                        <screenlet title="${uiLabelMap.PageTitleEditGlAccount}">
                            <include-form name="EditGlAccount" location="component://accounting/widget/GlobalGlAccountsForms.xml"/>
                        </screenlet>
                     </decorator-section>
                </decorator-screen>
            </widgets>
        </section>
    </screen>

    <!-- the next two screens list out the AcctgTransEntries, either from a GL Account or from an acctgTrans -->
    <screen name="ListGlAccountEntries">
        <section>
            <actions>
                <set field="titleProperty" value="PageTitleViewGlAccountEntries"/>
                <set field="tabButtonItem" value="ListGlAccountOrganization"/>
                <set field="glAccountId" from-field="requestParameters.glAccountId"/>
                <entity-and entity-name="AcctgTransEntry" list="entries">
                    <field-map field-name="glAccountId"/>
                </entity-and>
            </actions>
            <widgets>
                <decorator-screen name="main-decorator" location="${parameters.mainDecoratorLocation}">
                    <decorator-section name="body">
                        <screenlet title="${uiLabelMap.PageTitleViewGlAccountEntries}">
                            <include-tree name="ListGlAccountTree" location="component://accounting/widget/AccountingTrees.xml"/>
                        </screenlet>
                        <screenlet title="${uiLabelMap.PageTitleViewGlAccountEntries}">
                            <include-grid name="ListAcctgTransEntries" location="component://accounting/widget/GlobalGlAccountsForms.xml"/>
                        </screenlet>
                     </decorator-section>
                </decorator-screen>
            </widgets>
        </section>
    </screen>

    <screen name="ListAcctgTransEntries">
        <section>
            <actions>
                <set field="titleProperty" value="PageTitleViewAccountingTransaction"/>
                <set field="headerItem" value="chartofaccounts"/>
                <set field="acctgTransId" from-field="requestParameters.acctgTransId"/>
                <entity-and entity-name="AcctgTransEntry" list="entries">
                    <field-map field-name="acctgTransId"/>
                </entity-and>
            </actions>
            <widgets>
                <decorator-screen name="main-decorator" location="${parameters.mainDecoratorLocation}">
                    <decorator-section name="body">
                        <include-menu name="GlAccountTabBar" location="${parameters.mainMenuLocation}"/>
                        <screenlet title="${uiLabelMap.PageTitleViewAccountingTransaction}">
                            <include-tree name="ListGlAccountTree" location="component://accounting/widget/AccountingTrees.xml"/>
                        </screenlet>
                        <screenlet title="${uiLabelMap.PageTitleViewAccountingTransaction}">
                            <include-form name="ListAcctgTransEntries" location="component://accounting/widget/GlobalGlAccountsForms.xml"/>
                        </screenlet>
                     </decorator-section>
                </decorator-screen>
            </widgets>
        </section>
    </screen>

    <screen name="AddGlAccount">
        <section>
            <actions>
                <set field="titleProperty" value="PageTitleAddGlAccount"/>
                <set field="tabButtonItem" value=""/>
                <set field="labelTitleProperty" value=""/>
                <set field="glAccount" value=""/><!-- make sure glAccountId field is shown -->
            </actions>

            <widgets>
                <decorator-screen name="main-decorator" location="${parameters.mainDecoratorLocation}">
                    <decorator-section name="body">
                        <screenlet title="${uiLabelMap.PageTitleAddGlAccount}">
                            <include-form name="EditGlAccount" location="component://accounting/widget/GlobalGlAccountsForms.xml"/>
                        </screenlet>

                        <!-- include-screen screen-name="ListGlAccounts" name="ListGlAccounts" / -->

                        <!-- tree name="ListGlAccountTree" location="component://accounting/widget/AccountingTrees.xml"/ -->
                     </decorator-section>
                </decorator-screen>
            </widgets>
        </section>
    </screen>

    <screen name="ListGlAccounts">
        <section>
            <actions>
                <set field="titleProperty" value="PageTitleListAccounts"/>
                <set field="labelTitleProperty" value="PageTitleListAccounts"/>
                <set field="tabButtonItem" value="Chartofaccounts"/>
                <set field="helpAnchor" value="_help_find_global_gl_account"/>
                <!-- no longer works requies a fieldMap entity-and entity-name="GlAccount" list="entityList" use-cache="true" >
                    <limit-range start="0" size="20"/>
                </entity-and -->
                <set field="viewIndex" from-field="parameters.VIEW_INDEX" type="Integer" default-value="0"/>
                <set field="viewSizeDefaultValue" value="${groovy: modelTheme.getDefaultViewSize()}" type="Integer"/>
                <set field="viewSize" from-field="parameters.VIEW_SIZE" type="Integer" default-value="${viewSizeDefaultValue}"/>
            </actions>
            <widgets>
                <decorator-screen name="GlobalGLSettingsDecorator" location="${parameters.mainDecoratorLocation}">
                    <decorator-section name="body">
                        <include-menu name="GlSettingTabBar" location="${parameters.mainMenuLocation}"/>
                        <screenlet title="${uiLabelMap[labelTitleProperty]}">
                            <container style="button-bar">
                                <link target="ListGlAccountsReport" target-window="_blank" text="${uiLabelMap.CommonPrint}" style="buttontext"/>
                                <link target="ListGlAccountsExport" target-window="_blank" text="${uiLabelMap.CommonExport}" style="buttontext"/>
                            </container>
                            <include-grid name="ListGlAccount" location="component://accounting/widget/GlobalGlAccountsForms.xml"/>
                        </screenlet>
                    </decorator-section>
                </decorator-screen>
            </widgets>
        </section>
    </screen>
    <screen name="ListGlAccountsReport">
        <section>
            <actions>
                <property-map resource="AccountingUiLabels" map-name="uiLabelMap" global="true"/>
                <set field="titleProperty" value="PageTitleListAccounts"/>
                <set field="pageLayoutName" value="simple-landscape"/>
                <set field="paginate" value="false"/>
            </actions>
            <widgets>
                <decorator-screen name="SimpleDecorator" location="component://common/widget/CommonScreens.xml">
                    <decorator-section name="body">
                        <include-form name="ListGlAccountPdf" location="component://accounting/widget/GlobalGlAccountsForms.xml"/>
                    </decorator-section>
                </decorator-screen>
            </widgets>
        </section>
    </screen>
    <screen name="GlAccountDetail">
        <section>
            <actions>
                <entity-one entity-name="GlAccount" value-field="currentValue" use-cache="true">
                    <field-map field-name="glAccountId"/>
                </entity-one>
            </actions>
            <widgets>
                <label text="${uiLabelMap.FormFieldTitle_accountName}: ${currentValue.accountName}"/>
            </widgets>
        </section>
    </screen>

    <screen name="EditGlobalGlAccount">
        <section>
            <actions>
                <!-- <set field="title" value="Edit GlAccount"/>
                <set field="titleProperty" value=""/>
                <set field="tabButtonItem" value=""/>
                <set field="labelTitleProperty" value=""/> -->

                <set field="glAccountId" from-field="parameters.glAccountId"/>
                <entity-one entity-name="GlAccount" value-field="glAccount"/>
            </actions>
            <widgets>
                <decorator-screen name="CommonAccountDecorator">
                    <decorator-section name="body">
                        <include-form name="EditGlAccount" location="component://accounting/widget/GlobalGlAccountsForms.xml"/>
                    </decorator-section>
                </decorator-screen>
            </widgets>
        </section>
    </screen>
    <screen name="ViewRateAmounts">
        <section>
            <actions>
                <property-map resource="AccountingUiLabels" map-name="uiLabelMap" global="true"/>
                <set field="titleProperty" value="AccountingRateAmounts"/>
                <set field="labelTitleProperty" from-field="uiLabelMap.AccountingRateAmounts"/>
                <set field="tabButtonItem" value="ViewRateAmounts"/>
            </actions>
            <widgets>
                <decorator-screen name="GlobalGLSettingsDecorator" location="${parameters.mainDecoratorLocation}">
                    <decorator-section name="body">
                        <screenlet title="${uiLabelMap.AccountingUpdateRateAmount}" navigation-form-name="ListRateAmounts">
                            <include-form name="UpdateRateAmount" location="component://accounting/widget/GlobalGlAccountsForms.xml"/>
                        </screenlet>
                        <include-grid name="ListRateAmounts" location="component://accounting/widget/GlobalGlAccountsForms.xml"/>
                    </decorator-section>
                </decorator-screen>
            </widgets>
        </section>
    </screen>
    <!-- Screen to view and manage foreign exchange conversions -->
    <screen name="ViewFXConversions">
        <section>
            <actions>
                <property-map resource="AccountingUiLabels" map-name="uiLabelMap" global="true"/>
                <set field="titleProperty" value="AccountingFX"/>
                <set field="labelTitleProperty" from-field="uiLabelMap.AccountingFX"/>
                <set field="tabButtonItem" value="ViewFXConversions"/>
                <set field="helpAnchor" value="_help_for_view_foreign_exchange_rates"/>
                <property-to-field field="defaultCurrencyUomId" resource="general" property="currency.uom.id.default" default="USD"/>
                <!-- TODO: If UomConversionDated is ever used for another type of conversion besides currencies or if some currencies are
                    stored in UomConversion, we need to change the logic here -->
                <entity-condition entity-name="UomConversionDated" list="conversions">
                    <order-by field-name="uomId"/>
                    <order-by field-name="uomIdTo"/>
                    <order-by field-name="fromDate"/>
                </entity-condition>
            </actions>
            <widgets>
                <decorator-screen name="GlobalGLSettingsDecorator" location="${parameters.mainDecoratorLocation}">
                    <decorator-section name="body">
                        <screenlet id="FxConversionPanel" title="${uiLabelMap.AccountingUpdateFX}" collapsible="true">
                            <include-form name="UpdateFXConversion" location="component://accounting/widget/GlSetupForms.xml"/>
                        </screenlet>
                        <include-form name="ListConversions" location="component://accounting/widget/GlSetupForms.xml"/>
                    </decorator-section>
                </decorator-screen>
            </widgets>
        </section>
    </screen>

    <screen name="CostCenters">
        <section>
            <actions>
                <property-map resource="CommonUiLabels" map-name="uiLabelMap" global="true"/>
                <property-map resource="AccountingUiLabels" map-name="uiLabelMap" global="true"/>
                <set field="titleProperty" value="FormFieldTitle_costCenters"/>
                <set field="tabButtonItem" value="CostCenters"/>
                <set field="helpAnchor" value="_cost_centers"/>
            </actions>
            <widgets>
               <decorator-screen name="GlobalGLSettingsDecorator" location="${parameters.mainDecoratorLocation}">
                    <decorator-section name="body">
                        <section>
                            <actions>
                                <set field="organizationPartyId" from-field="parameters.organizationPartyId" default-value="${defaultOrganizationPartyId}"/>
                                <service service-name="getGlAcctgAndAmountPercentage" result-map="result">
                                    <field-map field-name="organizationPartyId"/>
                                </service>
                                <set field="glAcctgAndAmountPercentageList" from-field="result.glAcctgAndAmountPercentageList" type="List"/>
                                <set field="glAccountCategories" from-field="result.glAccountCategories" type="List"/>
                            </actions>
                            <widgets>
                                <screenlet title="${uiLabelMap.FormFieldTitle_costCenters}">
                                    <platform-specific>
                                        <html>
                                            <html-template location="component://accounting/template/ledger/CostCenters.ftl"/>
                                        </html>
                                    </platform-specific>
                                </screenlet>
                            </widgets>
                        </section>
                    </decorator-section>
                </decorator-screen>
            </widgets>
        </section>
    </screen>

</screens>
