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

<!-- These screens are for generating printed documents, such as invoices, bills, statements, etc. -->

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

    <!-- generate a PDF for the invoice. Sharing the same script file as the HTML page for viewing invoice -->
    <screen name="InvoicePDF">
         <section>
             <actions>
                <set field="defaultTemplateLocation" value="component://accounting/widget/AccountingPrintScreens.xml"/>
                <set field="defaultTemplateName" value="DefaultInvoicePDF"/>
                <script location="component://commonext/src/main/groovy/org/apache/ofbiz/commonext/template/DocTypeTemplate.groovy"/>
            </actions>
            <widgets>
                <include-screen name="${templateName}" location="${templateLocation}"/>
            </widgets>
        </section>
    </screen>

    <screen name="DefaultInvoicePDF">
        <section>
            <actions>
                <property-map resource="AccountingUiLabels" map-name="uiLabelMap" global="true"/>
                <property-map resource="ProductUiLabels" map-name="uiLabelMap" global="true"/>
                <property-map resource="PartyUiLabels" map-name="uiLabelMap" global="true"/>
                <property-map resource="OrderUiLabels" map-name="uiLabelMap" global="true"/>
                <property-map resource="CommonUiLabels" map-name="uiLabelMap" global="true"/>
                <set field="titleProperty" value="AccountingInvoice"/>
                <script location="component://accounting/src/main/groovy/org/apache/ofbiz/accounting/invoice/EditInvoice.groovy"/>
                <script location="component://party/src/main/groovy/org/apache/ofbiz/party/party/GetMyCompany.groovy"/>
            </actions>
            <widgets>
                <section>
                    <condition>
                        <or>
                            <if-service-permission service-name="acctgBasePermissionCheck" main-action="VIEW"/>
                            <!-- can always see own invoice -->
                            <if-compare field="invoice.partyIdFrom" operator="equals" value="${userLogin.partyId}"/>
                            <if-compare field="invoice.partyId" operator="equals" value="${userLogin.partyId}"/>
                            <!-- or is a contact of a company who owns the invoice-->
                            <if-compare field="invoice.partyIdFrom" operator="equals" value="${myCompanyId}"/>
                            <if-compare field="invoice.partyId" operator="equals" value="${myCompanyId}"/>
                        </or>
                    </condition>
                    <widgets>
                        <decorator-screen name="FoReportDecorator" location="component://common/widget/CommonScreens.xml">
                            <decorator-section name="topLeft">
                                <include-screen name="CompanyLogo" location="component://order/widget/ordermgr/OrderPrintScreens.xml"/>
                            </decorator-section>
                            <decorator-section name="topRight">
                               <platform-specific>
                                    <xsl-fo><html-template location="component://accounting/template/invoice/InvoiceReportHeaderInfo.fo.ftl"/></xsl-fo>
                                </platform-specific>
                            </decorator-section>
                            <decorator-section name="body">
                               <platform-specific>
                                   <xsl-fo><html-template location="component://accounting/template/invoice/InvoiceReportContactMechs.fo.ftl"/></xsl-fo>
                              </platform-specific>
                               <platform-specific>
                                   <xsl-fo><html-template location="component://accounting/template/invoice/InvoiceReportItems.fo.ftl"/></xsl-fo>
                               </platform-specific>
                            </decorator-section>
                        </decorator-screen>
                    </widgets>
                    <fail-widgets>
                        <decorator-screen name="FoReportDecorator" location="component://common/widget/CommonScreens.xml">
                            <decorator-section name="body">
                                <platform-specific>
                                    <xsl-fo><html-template location="component://accounting/template/invoice/NoAccountingView.fo.ftl"/></xsl-fo>
                                </platform-specific>
                            </decorator-section>
                        </decorator-screen>
                    </fail-widgets>
                </section>
            </widgets>
        </section>
    </screen>

    <screen name="PrintCheckPDF">
        <section>
            <condition>
                <if-service-permission service-name="acctgBasePermissionCheck" main-action="VIEW"/>
            </condition>
            <actions>
                <set field="titleProperty" value="AccountingPrintChecks"/>
            </actions>
            <widgets>
                <platform-specific>
                    <xsl-fo><html-template location="component://accounting/template/payment/printCheck.fo.ftl"/></xsl-fo>
                </platform-specific>
            </widgets>
            <fail-widgets>
                <label style="h3" text="${uiLabelMap.AccountingPrintChecksPermissionError}"/>
            </fail-widgets>
        </section>
    </screen>
    <screen name="PrintInvoices">
        <section>
            <actions>
                <property-map resource="AccountingUiLabels" map-name="uiLabelMap" global="true"/>
                <property-map resource="ProductUiLabels" map-name="uiLabelMap" global="true"/>
                <property-map resource="PartyUiLabels" map-name="uiLabelMap" global="true"/>
                <property-map resource="CommonUiLabels" map-name="uiLabelMap" global="true"/>
                <set field="invoiceIds" from-field="parameters.invoiceIds" type="List"/>
                <script location="component://accounting/src/main/groovy/org/apache/ofbiz/accounting/invoice/PrintInvoices.groovy"/>
            </actions>
            <widgets>
               <platform-specific>
                    <xsl-fo><html-template location="component://accounting/template/invoice/PrintInvoices.fo.ftl"/></xsl-fo>
                </platform-specific>
            </widgets>
        </section>
    </screen>
</screens>
