<?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.
-->

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

    <form name="FindSalesOpportunity" type="single" target="FindSalesOpportunity"
        header-row-style="header-row" default-table-style="basic-table">
        <field name="salesOpportunityId" title="${uiLabelMap.SfaOpportunityId}"><text-find size="25"></text-find></field>
        <field name="opportunityName" title="${uiLabelMap.SfaOpportunityName}"><text-find size="25"></text-find></field>
        <field name="partyId" title="${uiLabelMap.SfaLead}"><lookup target-form-name="LookupLead"/></field>
        <field name="opportunityStageId" title="${uiLabelMap.SfaInitialStage}">
            <drop-down allow-empty="true">
                <entity-options entity-name="SalesOpportunityStage">
                    <entity-order-by field-name="sequenceNum"/>
                </entity-options>
            </drop-down>
        </field>
        <field name="typeEnumId" title="${uiLabelMap.SfaType}">
            <drop-down allow-empty="true">
                <entity-options key-field-name="enumId" entity-name="Enumeration">
                    <entity-constraint name="enumTypeId" operator="equals" value="SLSOPP_TYP_ENUM"/>
                    <entity-order-by field-name="description"/>
                </entity-options>
            </drop-down>
        </field>
        <field name="searchButton" title="${uiLabelMap.CommonFind}" widget-style="smallSubmit"><submit/></field>
    </form>

    <form name="ListSalesOpportunity" type="list" list-name="listIt" paginate-target="FindSalesOpportunity" view-size="20"
        odd-row-style="alternate-row" default-table-style="basic-table hover-bar" header-row-style="header-row-2">
        <actions>
            <set field="parameters.noConditionFind" value="Y"/>
            <set field="opportunityStageId" from-field="parameters.opportunityStageId"/>
            <set field="parameters.opportunityStageId" value="${groovy:opportunityStageId==null?'SOSTG_CLOSED':opportunityStageId}"/>
            <set field="parameters.opportunityStageId_op" value="${groovy:opportunityStageId==null?'notEqual':'equals'}"/>
            <set field="fieldList" value="${groovy:['partyId','salesOpportunityId','opportunityStageId','typeEnumId', 'roleTypeId', 'opportunityName']}" type="List"/>
            <set field="sortField" from-field="parameters.sortField" default-value="salesOpportunityId"/>
            <service service-name="performFind" result-map="result" result-map-list="listIt">
                <field-map field-name="inputFields" from-field="parameters"/>
                <field-map field-name="entityName" value="SalesOpportunityAndRole"/>
                <field-map field-name="orderBy" value="${sortField}"/>
                <field-map field-name="fieldList" from-field="fieldList"/>
                <field-map field-name="distinct" value="Y"/>
                <field-map field-name="viewIndex" from-field="viewIndex"/>
                <field-map field-name="viewSize" from-field="viewSize"/>
            </service>
        </actions>
        <row-actions>
            <entity-one entity-name="SalesOpportunity" value-field="salesOpportunity"/>
        </row-actions>
        <field name="salesOpportunityId"><hidden/></field>
        <field name="opportunityName" title="${uiLabelMap.SfaOpportunityName}">
            <hyperlink description="${opportunityName}[${salesOpportunityId}] ${roleTypeId}" target="EditSalesOpportunity">
                <parameter param-name="salesOpportunityId"/>
            </hyperlink>
        </field>
        <field name="opportunityStageId" title="${uiLabelMap.SfaInitialStage}"><display-entity entity-name="SalesOpportunityStage"/></field>
        <field name="partyId" title="${uiLabelMap.SfaLead}/${uiLabelMap.Account}">
            <display-entity entity-name="PartyNameView" description="${firstName} ${lastName} ${middleName} ${groupName}" key-field-name="partyId">
                <sub-hyperlink target="viewprofile" description=" [${partyId}]">
                    <parameter param-name="partyId" from-field="partyId"/>
                    <parameter param-name="roleTypeId" from-field="roleTypeId"/>
                </sub-hyperlink>
            </display-entity> 
        </field>
        <field name="roleTypeId"><display-entity entity-name="RoleType"/></field>
        <field name="nextStep"><display/></field>
        <field name="estimatedAmount" title="${uiLabelMap.SfaEstimatedAmount}"><display/></field>
        <field name="nextStepDate" position="1" title="${uiLabelMap.SfaNextStepDate}" sort-field="true"><display/></field>
        <field name="estimatedCloseDate" title="${uiLabelMap.SfaCloseDate}"><display/></field>
        <field name="editButton" title="${uiLabelMap.CommonClose}" use-when="estimatedCloseDate == void || estimatedCloseDate == null || org.apache.ofbiz.base.util.UtilValidate.isDateAfterNow(estimatedCloseDate) || opportunityStageId != &quot;SOSTG_CLOSED&quot;" widget-style="buttontext">
            <hyperlink description="${uiLabelMap.CommonClose}" target="closeSalesOpportunity">
                <parameter param-name="salesOpportunityId"/>
                <parameter param-name="opportunityStageId" value="SOSTG_CLOSED"/>
            </hyperlink>
        </field>
    </form>

    <form name="EditSalesOpportunity" type="single" target="updateSalesOpportunity" default-map-name="salesOpportunity" 
        header-row-style="header-row" default-table-style="basic-table" >
        <alt-target use-when="salesOpportunity==null" target="createSalesOpportunity"/>
        <field name="salesOpportunityId" use-when="salesOpportunity!=null"><display/></field>
        <field name="salesOpportunityId" use-when="salesOpportunity==null&amp;&amp;salesOpportunityId==null"><text/></field>
        <field name="salesOpportunityId" use-when="salesOpportunity==null&amp;&amp;salesOpportunityId!=null" tooltip="${uiLabelMap.CommonCannotBeFound}: [${salesOpportunityId}]"><display/></field>
        <field name="opportunityName" title="${uiLabelMap.SfaOpportunityName}"><text default-value="${communicationEvent.subject}" size="30"/></field>
        <field name="description" title="${uiLabelMap.MarketingSegmentGroupDescription}"><textarea default-value="${communicationEvent.content}"/></field>
        <field name="nextStep" title="${uiLabelMap.SfaNextStep}"><textarea/></field>
        <field name="estimatedAmount" position="1" title="${uiLabelMap.SfaEstimatedAmount}"><text size="25"/></field>
        <field name="estimatedProbability" position="2" title="${uiLabelMap.SfaProbability}"><text size="25"/></field>
        <field name="marketingCampaignId" position="1" title="${uiLabelMap.MarketingCampaign}">
            <drop-down allow-empty="true">
                <entity-options description="${campaignName}" entity-name="MarketingCampaign" key-field-name="marketingCampaignId">
                </entity-options>
            </drop-down>
        </field>
        <field name="currencyUomId" position="2" title="${uiLabelMap.CommonCurrency}">
            <drop-down allow-empty="true" no-current-selected-key="${defaultOrganizationPartyCurrencyUomId}">
                <entity-options key-field-name="uomId" description="${description} - ${abbreviation}" entity-name="Uom">
                    <entity-constraint name="uomTypeId" operator="equals" value="CURRENCY_MEASURE"/>
                    <entity-order-by field-name="description"/>
                </entity-options>
            </drop-down>
        </field>
        <field name="nextStepDate" position="1" title="${uiLabelMap.SfaNextStepDate}"><date-time/></field>
        <field name="estimatedCloseDate" position="2" title="${uiLabelMap.SfaCloseDate}"><date-time/></field>
        <field name="opportunityStageId" position="1" title="${uiLabelMap.SfaInitialStage}">
            <drop-down>
                <entity-options entity-name="SalesOpportunityStage">
                    <entity-order-by field-name="sequenceNum"/>
                </entity-options>
            </drop-down>
        </field>
        <field name="typeEnumId" position="2" title="${uiLabelMap.SfaType}">
            <drop-down allow-empty="true">
                <entity-options key-field-name="enumId" entity-name="Enumeration">
                    <entity-constraint name="enumTypeId" operator="equals" value="SLSOPP_TYP_ENUM"/>
                    <entity-order-by field-name="description"/>
                </entity-options>
            </drop-down>
        </field>
        <field name="dataSourceId" use-when="communicationEvent==null" position="1" title="${uiLabelMap.SfaDataSourceLabel}">
            <drop-down allow-empty="true">
                <entity-options key-field-name="dataSourceId" entity-name="DataSource">
                    <entity-constraint name="dataSourceTypeId" operator="equals" value="LEAD_SOURCE"/>
                    <entity-order-by field-name="description"/>
                </entity-options>
            </drop-down>
        </field>
        <field name="dataSourceId" use-when="communicationEvent!=null" position="1" title="${uiLabelMap.SfaDataSourceLabel}">
            <drop-down allow-empty="false" no-current-selected-key="EMAIL">
                <entity-options key-field-name="dataSourceId" entity-name="DataSource">
                    <entity-constraint name="dataSourceTypeId" operator="equals" value="LEAD_SOURCE"/>
                    <entity-order-by field-name="description"/>
                </entity-options>
            </drop-down>
        </field>
        <field name="accountPartyId" use-when="communicationEvent==null" title="${uiLabelMap.SfaInitialAccount}" ><lookup target-form-name="LookupAccount" default-value="${accountPartyId}"/></field>
        <field name="accountPartyId" use-when="communicationEvent!=null" title="${uiLabelMap.SfaInitialAccount}" ><lookup target-form-name="LookupAccount" default-value="${accountPartyId}"/></field>
        <field name="leadPartyId" use-when="communicationEvent==null" title="${uiLabelMap.SfaLead}"><lookup target-form-name="LookupLead" default-value="${leadPartyId}"/></field>
        <field name="leadPartyId" use-when="communicationEvent!=null" title="${uiLabelMap.SfaLead}"><lookup target-form-name="LookupLead" default-value="${communicationEvent.partyIdFrom}"/></field>
        <field name="submitButton" title="${uiLabelMap.CommonSave}" use-when="salesOpportunity==null"><submit button-type="button"/></field>
        <field name="submitButton" title="${uiLabelMap.CommonUpdate}" use-when="salesOpportunity!=null"><submit button-type="button"/></field>
    </form>

    <form name="ViewSalesOpportunity" type="single" default-map-name="salesOpportunity"
        header-row-style="header-row" default-table-style="basic-table">
        <field name="salesOpportunityId"><display/></field>
        <field name="opportunityName" position="1" title="${uiLabelMap.SfaOpportunityName}"><display/></field>
        <field name="accountPartyId" position="1" title="${uiLabelMap.SfaInitialAccount}" map-name="accountParty" field-name="partyId"><display-entity description="${firstName} ${lastName} ${groupName} [${partyId}]" entity-name="PartyNameView"/></field>
        <field name="leadPartyId" position="1" title="${uiLabelMap.SfaLead}" map-name="leadParty" field-name="partyId"><display-entity description="${firstName} ${lastName} ${groupName} [${partyId}]" entity-name="PartyNameView"/></field>
        <field name="estimatedAmount" position="1" title="${uiLabelMap.SfaEstimatedAmount} ${currencyUomId}"><display/></field>
        <field name="estimatedProbability" position="2" title="${uiLabelMap.SfaProbability}"><display/></field>
        <field name="nextStepDate" position="1" title="${uiLabelMap.SfaNextStepDate}"><display/></field>
        <field name="estimatedCloseDate" position="2" title="${uiLabelMap.SfaCloseDate}"><display/></field>
        <field name="opportunityStageId" position="1" title="${uiLabelMap.SfaInitialStage}">
            <display-entity entity-name="SalesOpportunityStage"/>
        </field>
        <field name="typeEnumId" position="2" title="${uiLabelMap.SfaType}"><display/></field>
        <field name="marketingCampaignId" position="1" title="${uiLabelMap.MarketingCampaign}"><display/></field>
        <field name="currencyUomId" position="2" title="${uiLabelMap.CommonCurrency}"><display/></field>
        <field name="dataSourceId" position="1" title="${uiLabelMap.SfaDataSourceLabel}"><display/></field>
        <field name="description" position="1" title="${uiLabelMap.MarketingSegmentGroupDescription}"><display/></field>
        <field name="nextStep" position="1" title="${uiLabelMap.SfaNextStep}"><display/></field>
    </form>
</forms>
