<?xml version="1.0" encoding="UTF-8"?>
<!--
	&author:DJ
	$date:2013/05/08
	$purpose:发票创建
-->
<a:screen xmlns:a="http://www.leaf-framework.org/application" trace="true">
    <a:init-procedure>
        <a:model-query model="basic.sys_session_info" rootPath="default_value_record"/>
<!--        <a:model-query model="acr.ACR510.acr_invoice_group_billing_method" rootPath="group_billing_method_list"/>-->
    </a:init-procedure>
    <a:view>
        <a:link id="svcLink_create_invoice" url="${/request/@context_path}/modules/acr/ACR510/acr_invoice_create.lsc"/>
        <!-- <a:screen-include screen="modules/hls/hls_common_javascript.lview"/>-->
        <script type="text/javascript"><![CDATA[

        function createScreen_close() {
            var win = $('acr_invoice_create_invoice');
            win.close();
        }

        function createScreen_create() {
            var win = $('acr_invoice_create_invoice');

            winMask(win);

            var ds = $('headDs');
            if (!ds.validate(true)) {
                f_hls.winNoMask(win);
                return;
            }
            debugger
            var datas = ds.getJsonData();

            winNoMask(win);

            Leaf.showConfirm('${l:HLS.PROMPT}', '是否确认开票?', function () {
                winMask(win);
                Leaf.request({
                    url: $('svcLink_create_invoice').getUrl(),
                    para: datas,
                    success: function (res) {
                        winNoMask(win);
                        createScreen_close();
                        contractDs_grid_query();
                    },
                    failure: function () {
                        winNoMask(win);
                    },
                    error: function () {
                        winNoMask(win);
                    },
                    scope: this
                });
            }, function () {
                winNoMask(win);
            });

        }

        function unSelect_selectedDs(ds, record) {
            record.dirty = false;
        }

        function onSelect_selectedDs(ds, record) {
            record.dirty = true;
        }

        function onLoad_selectedDs(ds) {
            ds.selectAll.defer(5, ds);
            var records = ds.getAll();
            for (var i = 0; i < records.length; i++) {
                if ( records[i].get('cf_item') && records[i].get('cf_item') == '51') {
                    records[i].set('product_name', '保证金');
                    records[i].set('invoice_kind', 'RECEIPT');
                    records[i].set('invoice_kind_desc', '收据');
                }

            }
        }


        function winNoMask() {
            Leaf.Masker.unmask(Ext.getBody());

        }

        function winMask() {
            Leaf.Masker.mask(Ext.getBody(), '${l:HLS.EXECUTING}');
        }
        ]]></script>
        <style><![CDATA[
			.item-radio-option {
            margin-right: 50px;
        }
        ]]></style>
        <a:dataSets>
            <a:dataSet id="invoiceKindDs" lookupCode="ACR510_INVOICE_KIND"/>
            <a:dataSet id="headDs" autoCreate="true">
                <a:fields>
                    <a:field name="company_id" defaultValue="${/parameter/@company_id}"/>
                    <a:field name="group_billing_method" defaultValue="GROUP_BY_CONTRACT"/>
                    <a:field name="accounting_date" defaultValue="${/model/default_value_record/record/@today}"
                             required="true"/>
                    <a:field name="invoice_date" defaultValue="${/model/default_value_record/record/@today}"
                             required="true"/>
                </a:fields>
            </a:dataSet>
            <a:dataSet id="selectedDs" autoQuery="true" bindName="line_info" bindTarget="headDs" fetchAll="true"
                       model="acr.ACR510.acr_invoice_create" selectable="true">
                <a:fields>
                    <a:field name="product_name" lovGridHeight="360" lovHeight="540" lovService="acr.ACR510.acr_invoice_create_lov" lovWidth="680" required="true" title="货物及应税劳务名称">
                        <a:mapping>
                            <a:map from="code_value_name" to="product_name"/>
                        </a:mapping>
                    </a:field>
                    <a:field name="billing_amount" required="true"/>
                    <a:field name="invoice_kind"/>
                    <a:field name="invoice_kind_desc" displayField="code_value_name" options="invoiceKindDs"
                             required="true" returnField="invoice_kind" valueField="code_value"/>
                    <a:field name="billing_object"/>
                    <a:field name="invoice_bp_tax_registry_num" prompt="纳税人识别号"/>
                </a:fields>
                <a:events>
                    <a:event name="load" handler="onLoad_selectedDs"/>
                    <a:event name="select" handler="onSelect_selectedDs"/>
                    <a:event name="unselect" handler="unSelect_selectedDs"/>
                </a:events>
            </a:dataSet>
        </a:dataSets>
        <a:screenBody>
            <a:screenTopToolbar>
                <a:gridButton click="createScreen_close" text="HLS.CLOSE"/>
                <a:gridButton click="createScreen_create" text="HLS.CREATE"/>
            </a:screenTopToolbar>
            <a:form column="3">
                <a:datePicker name="invoice_date" bindTarget="headDs" prompt="ACR.INVOICE_DATE"/>
                <a:datePicker name="accounting_date" bindTarget="headDs" prompt="HLS.ACCOUNT_DATE"/>
            </a:form>
            <a:tabPanel marginHeight="220" marginWidth="30">
                <a:tabs>
                    <a:tab prompt="ACR510.TAB.BILLING_INFO" width="100">
                        <a:grid id="selectedDs_grid" bindTarget="selectedDs" marginHeight="270" marginWidth="60">
                            <a:columns>
                                <a:column name="contract_number" lock="true" width="150" prompt="合同编号" readOnly="true"/>
                                <a:column name="contract_name" lock="true" width="150" prompt="合同名称" readOnly="true"/>
                                <a:column name="bp_name" prompt="承租人名称" readOnly="true"/>
                                <a:column name="times" align="right" lock="true" width="40" prompt="期数" readOnly="true"/>
                                <a:column name="cf_item_desc" prompt="应收项目" readOnly="true"/>
                                <a:column name="product_name" width="150" prompt="货物及应税劳务名称" editor="acr_invoice_create_lov"/>
                                <a:column name="invoice_kind_desc" prompt="发票类型" editor="selectedDs_grid_editor_comb"/>
                                <a:column name="currency" prompt="币种" readOnly="true"/>
                                <a:column name="due_amount" align="right" renderer="Leaf.formatMoney" prompt="应收金额" readOnly="true"/>
                                <a:column name="received_amount" align="right" renderer="Leaf.formatMoney" prompt="已收金额" readOnly="true"/>
                                <a:column name="cf_billing_amount" align="right" renderer="Leaf.formatMoney" prompt="已开票金额" readOnly="true"/>
                                <a:column name="billing_amount" align="right" prompt="本次开票金额" renderer="Leaf.formatMoney"
                                          editor="selectedDs_grid_editor_tf"/>
                            </a:columns>
                            <a:editors>
                                <a:comboBox id="selectedDs_grid_editor_comb"/>
                                <a:textField id="selectedDs_grid_editor_tf"/>
                                <a:lov id="acr_invoice_create_lov"/>
                            </a:editors>
                        </a:grid>
                    </a:tab>
                    <a:tab prompt="ACR510.TAB.ASSIST_INFO" width="100">
                        <a:grid id="selectedDs_grid_2" bindTarget="selectedDs" marginHeight="270" marginWidth="60">
                            <a:columns>
                                <a:column name="contract_number" lock="true" width="150" prompt="合同编号" readOnly="true"/>
                                <a:column name="contract_name" lock="true" width="150" prompt="合同名称" readOnly="true"/>
                                <a:column name="bp_name" prompt="承租人名称" readOnly="true"/>
                                <a:column name="times" align="right" lock="true" width="40" prompt="期数" readOnly="true"/>
                                <a:column name="billing_method" prompt="开票规则" readOnly="true"/>
                                <a:column name="billing_way_n" prompt="开票方式" width="80" readOnly="true"/>
                                <a:column name="billing_frequency_n" prompt="开票频率" width="80" readOnly="true"/>
                                <a:column name="billing_object_name" prompt="开票对象" autoAdjust="false"
                                          showTitle="true" width="200" readOnly="true"/>
                                <a:column name="invoice_title" prompt="发票抬头" autoAdjust="false" editor=""
                                          showTitle="true" width="200" readOnly="true"/>
                                <a:column name="object_taxpayer_type" prompt="纳税人类型" readOnly="true"/>
                                <a:column name="invoice_bp_tax_registry_num" prompt="纳税人识别号" width="150" readOnly="true"/>
                                <a:column name="invoice_bp_address_phone_num" prompt="开票地址电话" autoAdjust="false"
                                          showTitle="true" width="200" readOnly="true"/>
                                <a:column name="invoice_bp_bank_account" prompt="开户行及账号" autoAdjust="false"
                                          showTitle="true" width="150" readOnly="true"/>
                            </a:columns>
                        </a:grid>
                    </a:tab>
                </a:tabs>
            </a:tabPanel>
<!--            <a:fieldSet title="ACR.GROUP_BILLING_METHOD">-->
<!--                <a:radio name="group_billing_method" bindTarget="headDs" labelField="code_value_name"-->
<!--                         options="/model/group_billing_method_list" prompt="" radioSeparator="" valueField="code_value"-->
<!--                         width="600"/>-->
<!--            </a:fieldSet>-->
        </a:screenBody>
    </a:view>
</a:screen>