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

    <grid name="ListBillingAccounts" list-name="listIt" paginate-target="FindBillingAccount" default-entity-name="BillingAccount"
        odd-row-style="alternate-row" default-table-style="basic-table hover-bar">
        <actions>
            <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="BillingAccount"/>
                <field-map field-name="orderBy" value="billingAccountId"/>
            </service>
        </actions>
        <field name="billingAccountId" widget-style="buttontext">
            <hyperlink description="${billingAccountId}" target="EditBillingAccount">
                <parameter param-name="billingAccountId"/>
            </hyperlink>
        </field>
        <field name="accountLimit">
            <display type="currency" currency="${accountCurrencyUomId}"/>
        </field>
        <field name="description"><display/></field>
        <field name="fromDate"><display/></field>
        <field name="thruDate"><display/></field>
    </grid>
    <grid name="ListBillingAccountsByParty" list-name="billingAccounts" paginate-target="FindBillingAccount"
        odd-row-style="alternate-row" default-table-style="basic-table hover-bar">
        <field name="billingAccountId" widget-style="buttontext">
            <hyperlink description="${billingAccountId}" target="EditBillingAccount">
                <parameter param-name="billingAccountId"/>
            </hyperlink>
        </field>
        <field name="accountLimit">
            <display type="currency" currency="${billingAccount.accountCurrencyUomId}"/>
        </field>
        <field name="accountBalance"><display type="currency"/></field>
        <field name="description"><display/></field>
        <field name="fromDate"><display/></field>
        <field name="thruDate"><display/></field>
        <field name="partyId" title="${uiLabelMap.PartyPartyId}"><display description="${parameters.partyId}"/></field>
        <field name="roleTypeId" title="${uiLabelMap.AccountingRoleType}"><display-entity entity-name="RoleType"/></field>
    </grid>
    <grid name="ListBillingAccountInvoices" list-name="billingAccountInvoices" paginate-target="BillingAccountInvoices" default-entity-name="Invoice"
        odd-row-style="alternate-row"  header-row-style="header-row-2" default-table-style="basic-table hover-bar">
        <actions>
            <entity-condition entity-name="Invoice" list="billingAccountInvoices">
                <condition-list>
                    <condition-expr field-name="billingAccountId" from-field="billingAccountId"/>
                    <condition-expr field-name="statusId" from-field="parameters.statusId" ignore-if-empty="true"/>
                </condition-list>
            </entity-condition>
        </actions>
        <row-actions>
            <service service-name="getPartyNameForDate" result-map="partyNameResultFrom">
                <field-map field-name="partyId" from-field="partyIdFrom"/>
                <field-map field-name="compareDate" from-field="invoiceDate"/>
                <field-map field-name="lastNameFirst" value="Y"/>
            </service>
            <service service-name="getPartyNameForDate" result-map="partyNameResultTo">
                <field-map field-name="partyId" from-field="partyId"/>
                <field-map field-name="compareDate" from-field="invoiceDate"/>
                <field-map field-name="lastNameFirst" value="Y"/>
            </service>
            <script location="component://accounting/src/main/groovy/org/apache/ofbiz/accounting/invoice/DisplayInvoiceAmounts.groovy"/>
        </row-actions>
        <field name="billingAccountId"><hidden/></field>
        <field name="invoiceId" widget-style="buttontext">
            <hyperlink description="${invoiceId}" target="viewInvoice">
                <parameter param-name="invoiceId"/>
            </hyperlink>
        </field>
        <field name="invoiceTypeId"><display-entity entity-name="InvoiceType"/></field>
        <field name="invoiceDate"><display/></field>
        <field name="statusId" title="${uiLabelMap.CommonStatus}"><display-entity entity-name="StatusItem"/></field>
        <field name="description"><display/></field>
        <field name="partyIdFrom"><display description="${partyNameResultFrom.fullName} [${partyIdFrom}]"/></field>
        <field name="partyIdTo" parameter-name="partyId"><display description="${partyNameResultTo.fullName} [${partyId}]"/></field>
        <field name="invoiceDate"><display description="${groovy:invoiceDate.toString().substring(0,10)}"/></field>
        <field name="total" widget-area-style="align-text"><display type="currency" currency="${currencyUomId}"/></field>
        <field name="amountToApply" widget-area-style="align-text"><display type="currency" currency="${currencyUomId}"/></field>
        <field name="capture" use-when="${groovy:!paidInvoice}" widget-style="buttontext">
            <hyperlink description="${uiLabelMap.AccountingCapture}" target="capturePaymentsByInvoice">
                <parameter param-name="invoiceId"/>
                <parameter param-name="billingAccountId"/>
            </hyperlink>
        </field>
        <field name="capture" use-when="${groovy:paidInvoice}"><display/></field>
    </grid>
    <form name="BillingAccount" type="single"
        header-row-style="header-row" default-table-style="basic-table">
        <actions>
            <set field="availableBalance" value="${groovy:billingAccount != null ? org.apache.ofbiz.order.order.OrderReadHelper.getBillingAccountBalance(billingAccount) : 0}" type="BigDecimal"/>
        </actions>
        <auto-fields-service service-name="updateBillingAccount" map-name="billingAccount"/>
        <field name="billingAccountId"><display/></field>
        <field name="accountCurrencyUomId" title="${uiLabelMap.CommonCurrency}" position="2"><display/></field>
        <field name="externalAccountId"><display/></field>
        <field name="partyId" title="${uiLabelMap.CommonParty}"><display/></field>
        <field name="contactMechId" title="${uiLabelMap.PartyContactInfo}" position="2">
            <display-entity entity-name="PostalAddress" description="${toName}, ${attnName}, ${address1}, ${stateProvinceGeoId} ${postalCode}">
            </display-entity>
        </field>
        <field name="accountLimit"><display type="currency" currency="${billingAccount.accountCurrencyUomId}"/></field>
        <field name="description" title="${uiLabelMap.CommonDescription}"><display/></field>
        <field name="availableBalance" title="${uiLabelMap.AccountingBillingAvailableBalance}">
            <display type="currency" currency="${billingAccount.accountCurrencyUomId}"/>
        </field>
        <field name="netBalance" title="${uiLabelMap.AccountingBillingNetBalance}" position="2">
            <display description="${groovy:org.apache.ofbiz.accounting.payment.BillingAccountWorker.getBillingAccountNetBalance(delegator, billingAccountId)}" type="currency" currency="${billingAccount.accountCurrencyUomId}"/>
        </field>
        <field name="fromDate" title="${uiLabelMap.CommonFrom}"><display type="date-time"/></field>
        <field name="thruDate" title="${uiLabelMap.CommonThru}" position="2"><display type="date-time"/></field>
    </form>
    <form name="EditBillingAccount" type="single" target="updateBillingAccount"
        header-row-style="header-row" default-table-style="basic-table">
        <actions>
            <set field="availableBalance" value="${groovy:billingAccount != null ? org.apache.ofbiz.order.order.OrderReadHelper.getBillingAccountBalance(billingAccount) : 0}" type="BigDecimal"/>
        </actions>
        <alt-target use-when="billingAccount==null" target="createBillingAccountAndRole"/>
        <auto-fields-service service-name="updateBillingAccount" map-name="billingAccount"/>
        <field name="description"><text size="60"/></field>
        <field use-when="billingAccount==null" name="billingAccountId"><hidden/></field>
        <field use-when="billingAccount!=null" name="billingAccountId"><display/></field>
        <field name="partyId" use-when="billingAccount != null" ><display/></field>
        <field name="partyId" use-when="billingAccount == null" title="${uiLabelMap.AccountingPartyBilledTo}" required-field="true"><lookup target-form-name="LookupPartyName"/></field>
        <field name="roleTypeId" use-when="billingAccount == null"><hidden value="BILL_TO_CUSTOMER"/></field>
        <field name="roleTypeId" use-when="billingAccount != null"><hidden/></field>
        <field name="accountCurrencyUomId">
            <drop-down allow-empty="false" no-current-selected-key="${defaultOrganizationPartyCurrencyUomId}">
                <entity-options key-field-name="uomId" description="${abbreviation} - ${description}" 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="contactMechId" tooltip="${uiLabelMap.AccountingBillingContactMechIdMessage}" use-when="billingAccount != null">
            <drop-down no-current-selected-key="${billingAccount.contactMechId}">
                <entity-options entity-name="BillingAccountRoleAndAddress" key-field-name="contactMechId" description="[${partyId}][${contactMechId}] ${toName}, ${attnName}, ${address1}, ${stateProvinceGeoId} ${postalCode}" filter-by-date="true">
                    <entity-constraint name="billingAccountId" env-name="billingAccountId"/>
                    <entity-order-by field-name="partyId"/>
                    <entity-order-by field-name="contactMechId"/>
                </entity-options>
            </drop-down>
        </field>
        <field name="availableBalance" title="${uiLabelMap.AccountingBillingAvailableBalance}" tooltip="${uiLabelMap.AccountingBillingAvailableBalanceMessage}">
            <display type="currency" currency="${billingAccount.accountCurrencyUomId}"/>
        </field>
        <field name="fromDate"><date-time default-value="${nowTimestamp}"/></field>
        <field name="submitButton" title="${uiLabelMap.CommonCreate}" use-when="billingAccount == null" widget-style="smallSubmit"><submit button-type="button"/></field>
        <field name="submitButton" title="${uiLabelMap.CommonUpdate}" use-when="billingAccount!=null" widget-style="smallSubmit"><submit button-type="button"/></field>
    </form>
    <grid name="ListBillingAccountRoles" list-name="billingAccountRoleList" target="updateBillingAccountRole"
        odd-row-style="alternate-row" header-row-style="header-row-2" default-table-style="basic-table hover-bar"
        paginate-target="EditBillingAccountRoles" separate-columns="true">
        <actions>
            <entity-condition entity-name="BillingAccountRole" list="billingAccountRoleList">
                <condition-expr field-name="billingAccountId" from-field="billingAccountId"/>
                <order-by field-name="roleTypeId"/>
            </entity-condition>
        </actions>
        <auto-fields-service service-name="updateBillingAccountRole" default-field-type="edit"/>
        <field name="billingAccountId"><hidden/></field>
        <field name="partyId" title="${uiLabelMap.CommonParty}">
            <display-entity entity-name="PartyNameView" description="${firstName} ${middleName} ${lastName} ${groupName}">
                <sub-hyperlink description="${partyId}" target="/partymgr/control/viewprofile" target-type="inter-app" link-style="buttontext">
                    <parameter param-name="partyId"/>
                </sub-hyperlink>
            </display-entity>
        </field>
        <field name="roleTypeId" title="${uiLabelMap.CommonRole}">
            <display-entity entity-name="RoleType"/>
        </field>
        <field name="fromDate" title="${uiLabelMap.CommonFrom}"><display type="date-time"/></field>
        <field name="thruDate" title="${uiLabelMap.CommonThru}"><date-time/></field>
        <field name="submitButton" title="${uiLabelMap.CommonUpdate}" widget-style="smallSubmit"><submit button-type="button"/></field>
        <field name="deleteLink" title=" " widget-style="buttontext">
            <hyperlink description="${uiLabelMap.CommonDelete}" target="deleteBillingAccountRole" also-hidden="false">
                <parameter param-name="billingAccountId"/>
                <parameter param-name="roleTypeId"/>
                <parameter param-name="partyId"/>
                <parameter param-name="fromDate"/>
            </hyperlink>
        </field>
    </grid>
    <grid name="BillingAccountRoles" list-name="billingAccountRoleList"
        odd-row-style="alternate-row" header-row-style="header-row-2" default-table-style="basic-table hover-bar"
        paginate-target="EditBillingAccountRoles" separate-columns="true">
        <actions>
            <entity-condition entity-name="BillingAccountRole" list="billingAccountRoleList">
                <condition-expr field-name="billingAccountId" from-field="billingAccountId"/>
                <order-by field-name="roleTypeId"/>
            </entity-condition>
        </actions>
        <field name="billingAccountId"><hidden/></field>
        <field name="partyId" title="${uiLabelMap.CommonParty}">
            <display-entity entity-name="PartyNameView" description="${firstName} ${middleName} ${lastName} ${groupName}">
                <sub-hyperlink description="${partyId}" target="/partymgr/control/viewprofile" target-type="inter-app" link-style="buttontext">
                    <parameter param-name="partyId"/>
                </sub-hyperlink>
            </display-entity>
        </field>
        <field name="roleTypeId" title="${uiLabelMap.CommonRole}">
            <display-entity entity-name="RoleType"/>
        </field>
        <field name="fromDate" title="${uiLabelMap.CommonFrom}"><display type="date-time"/></field>
        <field name="thruDate" title="${uiLabelMap.CommonThru}"><display type="date-time"/></field>
    </grid>
    <form name="AddBillingAccountRole" type="single" target="createBillingAccountRole" default-map-name="billingAccountRole"
        header-row-style="header-row" default-table-style="basic-table">
        <auto-fields-service service-name="createBillingAccountRole"/>
        <field name="billingAccountId"><hidden/></field>
        <field name="roleTypeId" title="${uiLabelMap.CommonRole}">
            <drop-down allow-empty="false" no-current-selected-key="BILL_TO_CUSTOMER">
                <entity-options entity-name="RoleType">
                    <entity-order-by field-name="description"/>
                </entity-options>
            </drop-down>
        </field>
        <field name="fromDate" title="${uiLabelMap.CommonFrom}"><date-time default-value="${nowTimestamp}"/></field>
        <field name="thruDate" title="${uiLabelMap.CommonThru}"><date-time/></field>
        <field name="partyId" title="${uiLabelMap.CommonParty}" required-field="true"><lookup target-form-name="LookupPartyName"/></field>
        <field name="submitButton" title="${uiLabelMap.CommonAdd}" widget-style="smallSubmit"><submit button-type="button"/></field>
    </form>
    <grid name="ListBillingAccountTerms" list-name="billingAccountTermsList" default-entity-name="BillingAccountTerm" paginate-target="EditBillingAccountTerms"
        odd-row-style="alternate-row" default-table-style="basic-table hover-bar">
        <actions>
            <entity-condition entity-name="BillingAccountTerm" list="billingAccountTermsList">
                <condition-expr field-name="billingAccountId" from-field="billingAccountId"/>
            </entity-condition>
        </actions>
        <field name="billingAccountId"><hidden/></field>
        <field name="termTypeId" title="${uiLabelMap.PartyTermType}">
            <display-entity entity-name="TermType"/>
        </field>
        <field name="termValue" title="${uiLabelMap.CommonValue}"><display/></field>
        <field name="uomId" title="${uiLabelMap.CommonUom}">
            <display-entity entity-name="Uom"/>
        </field>
        <field name="billingAccountTermId" title=" " widget-style="buttontext">
            <hyperlink description="${uiLabelMap.CommonEdit}" target="EditBillingAccountTerms">
                <parameter param-name="billingAccountId"/>
                <parameter param-name="billingAccountTermId"/>
            </hyperlink>
        </field>
        <field name="deleteLink" title=" " widget-style="buttontext">
            <hyperlink description="${uiLabelMap.CommonDelete}" target="removeBillingAccountTerm">
                <parameter param-name="billingAccountId"/>
                <parameter param-name="billingAccountTermId"/>
            </hyperlink>
        </field>
    </grid>
    <form name="EditBillingAccountTerms" type="single" target="updateBillingAccountTerm" default-map-name="billingAccountTerm"
        header-row-style="header-row" default-table-style="basic-table">
        <alt-target use-when="billingAccountTermId==null" target="createBillingAccountTerm"/>
        <field name="billingAccountId"><hidden/></field>
        <field use-when="billingAccountTermId!=null" name="billingAccountTermId"><hidden/></field>
        <field name="termTypeId" title="${uiLabelMap.PartyTermType}">
            <drop-down>
                <entity-options entity-name="TermType">
                    <entity-constraint name="parentTypeId" value="FINANCIAL_TERM"/>
                    <entity-order-by field-name="description"/>
                </entity-options>
            </drop-down>
        </field>
        <field name="uomId" title="${uiLabelMap.CommonUom}">
            <drop-down allow-empty="true">
                <entity-options entity-name="Uom">
                    <entity-order-by field-name="description"/>
                </entity-options>
            </drop-down>
        </field>
        <field name="termValue" title="${uiLabelMap.PartyTermValue}"><text size="10"/></field>
        <field name="submitButton" title="${uiLabelMap.CommonSave}" widget-style="smallSubmit"><submit button-type="button"/></field>
    </form>
    <grid name="ListBillingAccountPayments" list-name="payments" paginate-target="BillingAccountPayments"
        odd-row-style="alternate-row" header-row-style="header-row-2" default-table-style="basic-table hover-bar">
        <actions>
            <entity-condition entity-name="PaymentAndApplication" list="payments">
                <condition-expr field-name="billingAccountId" from-field="billingAccountId"/>
            </entity-condition>
        </actions>
        <field name="paymentId" widget-style="buttontext">
            <hyperlink description="${paymentId}" target="paymentOverview">
                <parameter param-name="paymentId"/>
            </hyperlink>
        </field>
        <field name="paymentMethodTypeId" title="${uiLabelMap.CommonType}">
            <display-entity entity-name="PaymentMethodType"/>
        </field>
        <field name="invoiceId"><display/></field>
        <field name="invoiceItemSeqId"><display/></field>
        <field name="effectiveDate"><display/></field>
        <field name="amountApplied">
            <display type="currency" currency="${currencyUomId}"/>
        </field>
        <field name="amount">
            <display type="currency" currency="${currencyUomId}"/>
        </field>
    </grid>
    <form name="CreateIncomingBillingAccountPayment" type="single" target="createPaymentAndAssociateToBillingAccount"
        header-row-style="header-row" default-table-style="basic-table">
        <actions>
            <set field="partyIdFrom" from-field="billToCustomer.partyId"/>
        </actions>
        <field name="billingAccountId"><hidden/></field>
        <field name="currencyUomId"><hidden value="${billingAccount.accountCurrencyUomId}"/></field>
        <field name="statusId"><hidden value="PMNT_NOT_PAID"/></field>
        <field name="partyIdFrom"><lookup target-form-name="LookupPartyName"/></field>
        <field name="organizationPartyId" parameter-name="partyIdTo">
            <drop-down allow-empty="false">
                <entity-options description="${partyId}" entity-name="PartyRole" key-field-name="partyId">
                    <entity-constraint name="roleTypeId" value="INTERNAL_ORGANIZATIO"/>
                    <entity-order-by field-name="partyId"/>
                </entity-options>
            </drop-down>
        </field>
        <field name="paymentTypeId" title="${uiLabelMap.AccountingPaymentType}">
            <drop-down allow-empty="false" no-current-selected-key="CUSTOMER_DEPOSIT">
                <entity-options entity-name="PaymentType">
                    <entity-order-by field-name="description"/>
                </entity-options>
            </drop-down>
        </field>
        <field name="paymentMethodTypeId">
            <drop-down allow-empty="false">
                <entity-options entity-name="PaymentMethodType">
                    <entity-order-by field-name="description"/>
                </entity-options>
            </drop-down>
        </field>
        <field name="amount"><text/></field>
        <field name="createButton">
            <submit button-type="button"/>
        </field>
    </form>
    <grid name="ListBillingAccountOrders" list-name="orderPaymentPreferencesList" paginate-target="BillingAccountOrders"
        odd-row-style="alternate-row" default-table-style="basic-table hover-bar">
        <field name="billingAccountId"><hidden/></field>
        <field name="orderId" widget-style="buttontext">
            <hyperlink description="${orderId}" target="/ordermgr/control/orderview" target-type="inter-app" also-hidden="false">
                <parameter param-name="orderId"/>
            </hyperlink>
        </field>
        <field name="orderDate"><display/></field>
        <field name="paymentMethodTypeId">
            <display-entity entity-name="PaymentMethodType" key-field-name="paymentMethodTypeId"/>
        </field>
        <field name="paymentStatusId" title="${uiLabelMap.CommonStatus}">
            <display-entity entity-name="StatusItem" key-field-name="statusId"/>
        </field>
        <field name="maxAmount">
            <display type="currency" currency="${currencyUomId}"/>
        </field>
    </grid>
    <form name="FindBillingAccounts" type="single" target="FindBillingAccount"
        header-row-style="header-row" default-table-style="basic-table">
        <field name="billingAccountId"><text-find ignore-case="true"/></field>
        <field name="description"><text-find ignore-case="true"/></field>
        <field name="accountLimit"><text/></field>
        <field name="fromDate"><date-time/></field>
        <field name="thruDate"><date-time/></field>
        <field name="noConditionFind"><hidden value="Y"/><!-- if this isn't there then with all fields empty no query will be done --></field>
        <field name="searchButton" title="${uiLabelMap.CommonFind}" widget-style="smallSubmit"><submit button-type="button"/></field>
    </form>
</forms>
