<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<window xmlns="http://schemas.haulmont.com/cuba/window.xsd"
        caption="msg://screen.editorCaption.order"
        class="ru.cs_consult.simpledoc.web.order.OrderEdit"
        datasource="orderDs"
        messagesPack="ru.cs_consult.simpledoc.web.order">
    <dsContext>
        <datasource id="orderDs"
                    class="ru.cs_consult.simpledoc.entity.Order"
                    view="order-full-view">
            <collectionDatasource id="specificationDs"
                                  property="specification"/>
            <collectionDatasource id="fileTableDs"
                                  property="fileTable"/>
            <collectionDatasource id="chatDs"
                                  property="chat"/>
            <collectionDatasource id="customerContactsDs"
                                  property="customerContacts"/>
            <datasource id="customerDs"
                        property="customer"/>
        </datasource>
        <collectionDatasource id="supplierDs"
                              class="ru.cs_consult.simpledoc.entity.Organizations"
                              view="_minimal">
            <query>
                <![CDATA[select e from simpledoc$Organizations e where e.myGroup=true]]>
            </query>
        </collectionDatasource>
        <collectionDatasource id="salesDocGroupsDs"
                              class="ru.cs_consult.simpledoc.entity.SalesDocGroup"
                              view="salesDocGroup-view">
            <query>
                <![CDATA[select e from simpledoc$SalesDocGroup e where e.salesDocKind = @enum(ru.cs_consult.simpledoc.entity.SalesDocKind.Orders)
or e.salesDocKind = @enum(ru.cs_consult.simpledoc.entity.SalesDocKind.Proposal)]]>
            </query>
        </collectionDatasource>
        <collectionDatasource id="vATsDs"
                              class="ru.cs_consult.simpledoc.entity.VAT"
                              view="vAT-view">
            <query>
                <![CDATA[select e from simpledoc$VAT e]]>
            </query>
        </collectionDatasource>
        <collectionDatasource id="docStatusesDs"
                              class="ru.cs_consult.simpledoc.entity.DocStatus"
                              view="_local">
            <query>
                <![CDATA[select e from simpledoc$DocStatus e]]>
            </query>
        </collectionDatasource>
        <collectionDatasource id="departmentsDs"
                              class="ru.cs_consult.simpledoc.entity.Department"
                              view="department-TreeView">
            <query>
                <![CDATA[select e from simpledoc$Department e where 
e.isPost = true]]>
            </query>
        </collectionDatasource>
        <collectionDatasource id="currenciesDs"
                              class="ru.cs_consult.simpledoc.entity.Currency"
                              view="_local">
            <query>
                <![CDATA[select e from simpledoc$Currency e]]>
            </query>
        </collectionDatasource>
        <collectionDatasource id="linkedInvoicesDs"
                              class="ru.cs_consult.simpledoc.entity.Invoice"
                              view="invoice-full-view">
            <query>
                <![CDATA[select e from simpledoc$Invoice e where e.order.id = :ds$orderDs]]>
            </query>
        </collectionDatasource>
        <collectionDatasource id="tasksDs"
                              allowCommit="false"
                              class="ru.cs_consult.simpledoc.entity.Tasks"
                              view="tasks-browser-view">
            <query>
                <![CDATA[select e from simpledoc$Tasks e where e.order.id = :ds$orderDs]]>
            </query>
        </collectionDatasource>
        <collectionDatasource id="customerOrganizationsDs"
                              class="ru.cs_consult.simpledoc.entity.Organizations"
                              view="_local">
            <query>
                <![CDATA[select e from simpledoc$Organizations e where e.isFolder = false]]>
            </query>
        </collectionDatasource>
        <collectionDatasource id="contactsDs"
                              class="ru.cs_consult.simpledoc.entity.Contacts"
                              view="contacts-view">
            <query>
                <![CDATA[select e from simpledoc$Contacts e where e.organizations.id = :ds$customerDs]]>
            </query>
        </collectionDatasource>
        <collectionDatasource id="linkedСontractsDs"
                              class="ru.cs_consult.simpledoc.entity.Contract"
                              view="contract-full-view">
            <query>
                <![CDATA[select e from simpledoc$Contract e where e.order.id = :ds$orderDs]]>
            </query>
        </collectionDatasource>
    </dsContext>
    <dialogMode forceDialog="true"
                height="800"
                width="760"/>
    <layout expand="scrollBox"
            spacing="true">
        <scrollBox id="scrollBox"
                   spacing="true">
            <grid id="topGrid"
                  spacing="true"
                  width="100%">
                <columns count="2"/>
                <rows>
                    <row>
                        <lookupPickerField id="salesDocGroupLookupPickerField"
                                           caption="msg://lookupPickerField.salesDocGroupLookupPickerField.caption"
                                           datasource="orderDs"
                                           optionsDatasource="salesDocGroupsDs"
                                           property="salesDocGroup"
                                           width="300px">
                            <actions>
                                <action id="open"/>
                            </actions>
                        </lookupPickerField>
                        <hbox id="fullNumberHbox"
                              enable="false"
                              expand="fullNumberTextField"
                              spacing="true">
                            <textField id="fullNumberTextField"
                                       caption="msg://textField.fullNumberTextField.caption"
                                       datasource="orderDs"
                                       property="fullNumber"
                                       width="140px"/>
                            <dateField id="dateField"
                                       caption="msg://dateField.dateField.caption"
                                       datasource="orderDs"
                                       property="date"
                                       width="140px"/>
                        </hbox>
                    </row>
                    <row>
                        <dateField id="endDatePlanDateField"
                                   caption="msg://dateField.endDatePlanDateField.caption"
                                   datasource="orderDs"
                                   enable="false"
                                   property="endDatePlan"
                                   width="300px"/>
                        <lookupField id="statusLookupField"
                                     caption="msg://lookupField.statusLookupField.caption"
                                     datasource="orderDs"
                                     enable="false"
                                     optionsDatasource="docStatusesDs"
                                     property="status"
                                     width="300px"/>
                    </row>
                    <row>
                        <hbox id="validityHbox"
                              enable="false"
                              spacing="true">
                            <textField id="validityInDaysTextField"
                                       caption="msg://textField.validityInDaysTextField.caption"
                                       datasource="orderDs"
                                       property="validityInDays"
                                       width="145px"/>
                            <dateField id="validityUnitDateField"
                                       caption="msg://dateField.validityUnitDateField.caption"
                                       datasource="orderDs"
                                       property="validUnit"
                                       width="145px"/>
                        </hbox>
                        <buttonsPanel id="buttonsPanel"
                                      align="BOTTOM_LEFT"
                                      enable="false">
                            <button id="ctreateInvoiceButton"
                                    caption="msg://button.createInvoiceButton.caption"
                                    invoke="onButtonAddInvoiceClick"/>
                            <button id="createContractButton"
                                    caption="msg://button.createContractButton.caption"
                                    invoke="onButtonAddContractClick"/>
                            <popupButton id="popupButtonLinkedItem"
                                         icon="CHAIN"
                                         popupOpenDirection="BOTTOM_LEFT"
                                         responsive="true"
                                         stylename="borderless">
                                <popup>
                                    <vbox margin="true"
                                          spacing="true"
                                          width="350px">
                                        <table id="invoiceTable"
                                               align="MIDDLE_CENTER"
                                               caption="msg://table.invoiceTable.caption"
                                               columnControlVisible="false"
                                               columnHeaderVisible="false"
                                               contextMenuEnabled="false"
                                               reorderingAllowed="false"
                                               settingsEnabled="false"
                                               showSelection="false"
                                               sortable="false"
                                               stylename="borderless no-horizontal-lines no-stripes no-vertical-lines">
                                            <columns>
                                                <column id="instanceName"
                                                        generator="onInstanceNameColumnInvoiceTable"
                                                        link="true"
                                                        linkScreenOpenType="DIALOG"/>
                                                <column id="dataNumberInvoice"
                                                        generator="dataNumberInvoice"
                                                        sortable="false"/>
                                            </columns>
                                            <rows datasource="linkedInvoicesDs"/>
                                        </table>
                                        <table id="contractTable"
                                               align="MIDDLE_CENTER"
                                               caption="msg://table.contractTable.caption"
                                               columnControlVisible="false"
                                               columnHeaderVisible="false"
                                               contextMenuEnabled="false"
                                               reorderingAllowed="false"
                                               settingsEnabled="false"
                                               showSelection="false"
                                               sortable="false"
                                               stylename="borderless no-horizontal-lines no-stripes no-vertical-lines">
                                            <columns>
                                                <column id="instanceName"
                                                        generator="onInstanceNameColumnContractTable"
                                                        link="true"
                                                        linkScreenOpenType="DIALOG"/>
                                                <column id="dateNumberContract"
                                                        generator="dateNumberContract"
                                                        link="true"
                                                        linkScreenOpenType="DIALOG"
                                                        sortable="false"/>
                                            </columns>
                                            <rows datasource="linkedСontractsDs"/>
                                        </table>
                                    </vbox>
                                </popup>
                            </popupButton>
                        </buttonsPanel>
                    </row>
                </rows>
            </grid>
            <tabSheet id="menuTabSheet"
                      enable="false">
                <tab id="basicTab"
                     caption="msg://tab.basicTab.caption"
                     margin="true,false,false,false"
                     spacing="true">
                    <vbox id="basicVbox"
                          spacing="true">
                        <hbox id="createdHbox"
                              expand="creatorHbox"
                              spacing="true"
                              width="100%">
                            <hbox id="creatorHbox"
                                  expand="creatorTextLabel"
                                  spacing="true">
                                <label id="creatorLabel"
                                       value="msg://label.creatorLabel.value"/>
                                <label id="creatorTextLabel"
                                       datasource="orderDs"
                                       property="creator"/>
                            </hbox>
                            <label id="dateCreatedLabel"
                                   datasource="orderDs"
                                   property="createTs"/>
                        </hbox>
                        <lookupField id="supplierLookupField"
                                     caption="msg://lookupField.supplierLookupField.caption"
                                     datasource="orderDs"
                                     optionsDatasource="supplierDs"
                                     property="supplier"
                                     width="100%"/>
                        <lookupPickerField id="managerLookupPickerField"
                                           caption="msg://lookupPickerField.managerLookupPickerField.caption"
                                           datasource="orderDs"
                                           optionsDatasource="departmentsDs"
                                           property="manager"
                                           width="100%">
                            <actions>
                                <action id="lookup"/>
                            </actions>
                        </lookupPickerField>
                        <split height="1px"
                               orientation="vertical"
                               responsive="true"
                               width="100%"/>
                        <vbox id="customerVbox"
                              spacing="true">
                            <hbox id="customerHbox"
                                  spacing="true"
                                  width="100%">
                                <lookupPickerField id="customerLookupPickerField"
                                                   caption="msg://lookupPickerField.customerLookupPickerField.caption"
                                                   datasource="orderDs"
                                                   optionsDatasource="customerOrganizationsDs"
                                                   property="customer"
                                                   width="100%">
                                    <actions>
                                        <action id="edit"
                                                icon="EXTERNAL_LINK_SQUARE"
                                                invoke="onEditCustomer"/>
                                        <action id="lookup"
                                                icon="EXTERNAL_LINK_SQUARE"/>
                                    </actions>
                                </lookupPickerField>
                            </hbox>
                            <label id="customerInformationLabel"/>
                            <vbox id="customerContactVbox"
                                  align="TOP_CENTER"
                                  spacing="true"
                                  width="80%">
                                <hbox id="customerContactHbox"
                                      align="TOP_CENTER"
                                      spacing="true"
                                      width="100%">
                                    <lookupField id="customerContactLookupField"
                                                 caption="msg://lookupField.customerContactLookupField.caption"
                                                 captionProperty="displayName"
                                                 optionsDatasource="contactsDs"
                                                 width="100%"/>
                                </hbox>
                                <table id="customerContactTable"
                                       columnControlVisible="false"
                                       columnHeaderVisible="false"
                                       height="70px"
                                       multiselect="true"
                                       responsive="true"
                                       stylename="borderless no-horizontal-lines no-stripes no-vertical-lines"
                                       width="100%">
                                    <actions>
                                        <action id="remove"/>
                                        <action id="edit"/>
                                    </actions>
                                    <columns>
                                        <column id="informationNameNumb"/>
                                    </columns>
                                    <rows datasource="customerContactsDs"/>
                                </table>
                            </vbox>
                        </vbox>
                        <textArea id="subjectTextArea"
                                  datasource="orderDs"
                                  property="subject"
                                  width="100%"/>
                        <hbox id="forSumHbox"
                              spacing="true"
                              width="100%">
                            <textField id="sumTextField"
                                       caption="msg://textField.sumTextField.caption"
                                       datasource="orderDs"
                                       property="sum"
                                       width="100%"/>
                            <lookupField id="vatLookupField"
                                         caption="msg://lookupField.vatLookupField.caption"
                                         datasource="orderDs"
                                         optionsDatasource="vATsDs"
                                         property="vat"
                                         width="100%"/>
                            <textField id="VATSummTextField"
                                       caption="msg://textField.VATSummTextField.caption"
                                       datasource="orderDs"
                                       editable="false"
                                       enable="false"
                                       property="vatSum"
                                       width="100%"/>
                        </hbox>
                        <groupBox id="payPrePayGroupBox"
                                  caption="msg://groupBox.payPrePaymentGroupBox.caption"
                                  collapsable="true"
                                  spacing="true"
                                  stylename="light">
                            <grid id="paymentPrePaymentGrid"
                                  spacing="true"
                                  width="100%">
                                <columns count="2"/>
                                <rows>
                                    <row>
                                        <lookupField id="paymentSchemeLookupField"
                                                     caption="msg://lookupField.paymentSchemeLookupField.caption"
                                                     datasource="orderDs"
                                                     optionsEnum="ru.cs_consult.simpledoc.entity.PaymentScheme"
                                                     property="paymentScheme"
                                                     width="100%"/>
                                        <hbox id="prePaymentProcentHbox"
                                              spacing="true"
                                              width="100%">
                                            <lookupField id="prePaymentProcentLookupField"
                                                         caption="msg://lookupField.prePaymentProcentLookupField.caption"
                                                         datasource="orderDs"
                                                         optionsEnum="ru.cs_consult.simpledoc.entity.PrepaymentProcent"
                                                         property="prePaymentProcents"
                                                         width="100%"/>
                                            <textField id="prePaymentProcentTextField"
                                                       align="BOTTOM_LEFT"
                                                       datasource="orderDs"
                                                       maxLength="3"
                                                       property="prePaymentProcent"
                                                       width="100%"/>
                                        </hbox>
                                    </row>
                                    <row>
                                        <hbox id="ppSumHbox"
                                              colspan="2"
                                              spacing="true">
                                            <textField id="ppaySumTextField"
                                                       caption="msg://textField.ppaySumTextField.caption"
                                                       datasource="orderDs"
                                                       property="prePaymentSum"/>
                                            <textField id="paySumTextField"
                                                       caption="msg://textField.paySumTextField.caption"
                                                       datasource="orderDs"
                                                       property="paymentSum"/>
                                        </hbox>
                                    </row>
                                    <row>
                                        <split colspan="2"
                                               height="1px"
                                               orientation="vertical"
                                               responsive="true"
                                               width="100%"/>
                                    </row>
                                    <row>
                                        <groupBox id="prePaymentGroupBox"
                                                  caption="msg://groupBox.prePaymentGroupBox.caption"
                                                  enable="false"
                                                  spacing="true"
                                                  visible="false">
                                            <grid id="prePaymentGrid"
                                                  spacing="true"
                                                  width="100%">
                                                <columns>
                                                    <column flex="0.0"/>
                                                    <column flex="0.0"/>
                                                </columns>
                                                <rows>
                                                    <row>
                                                        <textField id="prePaymentSumTextField"
                                                                   caption="msg://textField.prePaymentSumTextField.caption"
                                                                   datasource="orderDs"
                                                                   property="prePaymentSum"
                                                                   width="100%"/>
                                                        <dateField id="prePaymentDatePlanDateField"
                                                                   caption="msg://dateField.prePaymentDatePlanDateField.caption"
                                                                   datasource="orderDs"
                                                                   property="prePaymentDatePlan"
                                                                   width="100%"/>
                                                    </row>
                                                    <row>
                                                        <textField id="prePaymentDurationTextField"
                                                                   caption="msg://textField.prePaymentDurationTextField.caption"
                                                                   datasource="orderDs"
                                                                   property="prePaymentDuration"
                                                                   width="100%"/>
                                                        <hbox id="prePaymentDurationInWorkDaysHbox"
                                                              align="BOTTOM_LEFT"
                                                              expand="prePaymentDurationInWorkDaysOptionsGroup"
                                                              spacing="true"
                                                              width="100%">
                                                            <checkBox id="prePaymentDurationInWorkDaysCheckBox"
                                                                      datasource="orderDs"
                                                                      property="prePaymentDurationInWorkDays"
                                                                      visible="false"/>
                                                            <optionsGroup id="prePaymentDurationInWorkDaysOptionsGroup"
                                                                          enable="false"
                                                                          orientation="horizontal"/>
                                                        </hbox>
                                                    </row>
                                                    <row>
                                                        <checkBox id="isPrePayedCheckBox"
                                                                  align="MIDDLE_LEFT"
                                                                  caption="msg://checkBox.isPrePayedCheckBox.caption"
                                                                  datasource="orderDs"
                                                                  property="isPrePayed"
                                                                  width="100%"/>
                                                        <dateField id="prePaymentDateFactDateField"
                                                                   datasource="orderDs"
                                                                   property="prePaymentDateFact"
                                                                   width="100%"/>
                                                    </row>
                                                </rows>
                                            </grid>
                                        </groupBox>
                                        <groupBox id="paymentGroupBox"
                                                  caption="msg://groupBox.paymentGroupBox.caption"
                                                  enable="false"
                                                  spacing="true"
                                                  visible="false">
                                            <grid id="paymentGrid"
                                                  spacing="true"
                                                  width="100%">
                                                <columns count="2"/>
                                                <rows>
                                                    <row>
                                                        <textField id="paymentSumTextField"
                                                                   caption="msg://textField.paymentSumTextField.caption"
                                                                   datasource="orderDs"
                                                                   property="paymentSum"
                                                                   width="100%"/>
                                                        <dateField id="paymentDatePlanDateField"
                                                                   caption="msg://dateField.paymentDatePlanDateField.caption"
                                                                   datasource="orderDs"
                                                                   property="paymentDatePlan"
                                                                   width="100%"/>
                                                    </row>
                                                    <row>
                                                        <textField id="paymentDurationTextField"
                                                                   caption="msg://textField.paymentDurationTextField.caption"
                                                                   datasource="orderDs"
                                                                   property="paymentDuration"
                                                                   width="100%"/>
                                                        <hbox id="paymentDurationInWorkDaysHbox"
                                                              align="BOTTOM_LEFT"
                                                              expand="paymentDurationInWorkDaysOptionsGroup"
                                                              spacing="true"
                                                              width="100%">
                                                            <checkBox id="paymentDurationInWorkDaysCheckBox"
                                                                      datasource="orderDs"
                                                                      property="paymentDurationInWorkDays"
                                                                      visible="false"/>
                                                            <optionsGroup id="paymentDurationInWorkDaysOptionsGroup"
                                                                          enable="false"
                                                                          orientation="horizontal"/>
                                                        </hbox>
                                                    </row>
                                                    <row>
                                                        <checkBox id="isPayedCheckBox"
                                                                  align="MIDDLE_LEFT"
                                                                  caption="msg://checkBox.isPayedCheckBox.caption"
                                                                  datasource="orderDs"
                                                                  property="isPayed"
                                                                  width="100%"/>
                                                        <dateField id="paymentDateFactDateField"
                                                                   datasource="orderDs"
                                                                   property="paymentDateFact"
                                                                   width="100%"/>
                                                    </row>
                                                </rows>
                                            </grid>
                                        </groupBox>
                                    </row>
                                </rows>
                            </grid>
                        </groupBox>
                        <groupBox id="periodOfExecutionGroupBox"
                                  caption="msg://groupBox.periodOfExecutionGroupBox.caption"
                                  spacing="true"
                                  stylename="light">
                            <hbox id="periodOfExecutionHbox"
                                  spacing="true"
                                  width="100%">
                                <hbox id="durationHbox"
                                      spacing="true"
                                      width="100%">
                                    <textField id="durationTextField"
                                               caption="msg://textField.durationTextField.caption"
                                               datasource="orderDs"
                                               property="duration"
                                               width="100%"/>
                                </hbox>
                                <hbox id="durationInWorkDaysHbox"
                                      align="BOTTOM_CENTER"
                                      expand="durationInWorkDaysOptionsGroup"
                                      spacing="true"
                                      width="100%">
                                    <checkBox id="durationInWorkDaysCheckBox"
                                              datasource="orderDs"
                                              property="durationInWorkDays"
                                              visible="false"/>
                                    <optionsGroup id="durationInWorkDaysOptionsGroup"
                                                  align="BOTTOM_CENTER"
                                                  datasource="orderDs"
                                                  orientation="horizontal"
                                                  property="durationInWorkDays"/>
                                </hbox>
                                <hbox id="endDatePlanHbox2"
                                      spacing="true"
                                      width="100%">
                                    <dateField id="endDatePlanDateField2"
                                               caption="msg://ateField.endDatePlanDateField2.caption"
                                               datasource="orderDs"
                                               property="endDatePlan"
                                               width="100%"/>
                                </hbox>
                            </hbox>
                        </groupBox>
                    </vbox>
                </tab>
                <tab id="specificationTab"
                     caption="msg://tab.specificationTab.caption"
                     lazy="true"
                     margin="true,false,false,false"
                     spacing="true">
                    <groupBox id="specificationBox"
                              caption="msg://.groupBox.specificationBox.caption">
                        <table id="specificationTable"
                               columnControlVisible="false"
                               height="200px"
                               width="100%">
                            <actions>
                                <action id="create"/>
                                <action id="edit"/>
                                <action id="remove"/>
                            </actions>
                            <columns>
                                <column id="itemName"/>
                                <column id="price"/>
                                <column id="vat"/>
                                <column id="count"/>
                                <column id="discount"/>
                                <column id="itemSum"/>
                            </columns>
                            <rows datasource="specificationDs"/>
                            <buttonsPanel>
                                <button id="createSpButton"
                                        action="specificationTable.create"/>
                                <button id="editSpButton"
                                        action="specificationTable.edit"/>
                                <button id="removeSpButton"
                                        action="specificationTable.remove"/>
                            </buttonsPanel>
                        </table>
                    </groupBox>
                </tab>
                <tab id="fileTab"
                     caption="msg://tab.fileTab.caption"
                     margin="true,false,false,false"
                     spacing="true">
                    <frame id="frameFiles"
                           screen="fileTable_frame"/>
                </tab>
                <tab id="tasksTab"
                     caption="msg://tab.tasksTab.caption"
                     spacing="true">
                    <frame id="frameTasks"
                           height="100%"
                           responsive="true"
                           screen="tasks_frame"/>
                </tab>
                <tab id="linksTab"
                     caption="msg://linksTab"
                     margin="true,false,false,false"
                     spacing="true">
                    <vbox id="linksTabVbox"
                          height="100%"
                          spacing="true">
                        <frame id="frameFreeLinks"
                               height="100%"
                               screen="freeEntityLinks_frame"/>
                    </vbox>
                </tab>
                <tab id="discussionTab"
                     caption="msg://tab.discussionTab.caption"
                     margin="true,false,false,false"
                     spacing="true">
                    <frame id="discussionFrame"
                           screen="discussion_frame"/>
                </tab>
            </tabSheet>
        </scrollBox>
        <hbox spacing="true">
            <frame id="windowActions"
                   screen="editWindowActions"/>
            <button id="saveButton"
                    caption="msg://button.saveButton.caption"
                    invoke="onSaveButton"/>
        </hbox>
    </layout>
</window>
