<?xml version="1.0" encoding="UTF-8"?>

<a:screen xmlns:a="http://www.leaf-framework.org/application" trace="true">
    <a:init-procedure>
        <a:model-query fetchAll="true" model="basic.hls_lease_channel_for_lov" rootPath="acr510_lease_list"/>
    </a:init-procedure>
    <a:view>
        <a:link id="invoice_attachment_uploadFile_id" url="${/request/@context_path}/downloadFile.lview"/>
        <script type="text/javascript"><![CDATA[
        function et_document_return_query() {
            $('et_document_return_grid_ds').query();
        }

        function et_document_return_reset(){
            $('et_document_return_form_ds').reset();
        }

        function et_document_return_export() {
            $('source_to_grid')._export(null,'结清资料退还查询');
        }

        function aut_authority_list_validate_query(ds, qpara) {
            qpara['authority_flag'] = 'Y';
            qpara['contract_ref_content_flag'] = 'Y';
            qpara['trx_category'] = 'CONTRACT';
            qpara['trx_id'] = 't1.contract_id';
        }

        //pdf附件
        function downloadPdf(val, rec, name) {
            if (rec.get('ele_invoice_status') == 'DOWNLOAD') {
                return '<a href=javascript:detail_upload_window(' + rec.get('ele_invoice_hd_id') + ')>pdf附件</a>';
            }
        }

        function detail_upload_window(id) {
            var url = $('invoice_attachment_uploadFile_id').getUrl() + '?table_name=ACR_ELE_INVOICE_HD&header_id=' + id;
            var win = new Leaf.Window({
                url: url,
                title: '${l:HLS.SUPPORTING_DOCUMENT}',
                id: 'invoice_attachment_uploadFile_id_win',
                width: 850,
                height: 400
            });
            win.on('close', function () {
            });
        }

        function summaryRenderer(datas, name) {
                			var sum=0;

        	        		if(name=="total_amount"){
        	        			for(var i=0;i<datas.length;i++){
        		            		var record=datas[i];
        		            		var payment_amount_vl=record.get("total_amount");
        		            		var payment_amount=parseFloat(payment_amount_vl);
        		            		if(!isNaN(payment_amount)){
        		            			sum+=payment_amount;
        		            		}
                    			}
        		                return '<font color="red">' + Leaf.formatNumber(sum ,2)+ '</font>';
        	        		}
        }

        ]]></script>

        <a:dataSets>
            <a:dataSet id="acr515_lease_channel_ds">
                <a:datas dataSource="/model/acr510_lease_list"/>
            </a:dataSet>
            <a:dataSet id="business_type_ds" autoQuery="true" model="cont.CON1220.et_document_business_type"/>
            <a:dataSet id="send_object" autoQuery="true" model="cont.CON1220.send_object"/>
            <a:dataSet id="et_document_return_form_ds">
                <a:fields>
                    <a:field name="lease_channel" />
                    <a:field name="lease_channel_desc" displayField="description" options="acr515_lease_channel_ds"
                             returnField="lease_channel" valueField="lease_channel"/>
                    <a:field name="business_type"/>
                    <a:field name="business_type_n" displayField="code_value_name" options="business_type_ds" returnField="business_type" valueField="code_value"/>
                    <a:field name="send_object" displayField="send_object" options="send_object" returnField="send_object" valueField="send_object"/>
                    <a:field name="__async__"  defaultValue="Y" prompt="异步导出"/>
                </a:fields>
            </a:dataSet>
            <!--queryUrl="${/request/@context_path}/EtDocument/record/query"-->
            <a:dataSet id="et_document_return_grid_ds"
                       model="cont.CON1220.et_document_return_query"
                       queryDataSet="et_document_return_form_ds" selectable="true" selectionModel="single">
                <a:events>
                    <a:event  name="query" handler="aut_authority_list_validate_query"/>
                </a:events>
            </a:dataSet>
        </a:dataSets>

        <a:screenBody>
            <a:screenTopToolbar>
                <a:screenTitle/>
                <a:gridButton click="et_document_return_query" text="查询"/>
                <a:gridButton click="et_document_return_reset" text="重置"/>
                <a:gridButton click="et_document_return_export" text="导出"/>
            </a:screenTopToolbar>
            <a:form column="4" marginWidth="100" title="查询条件">
                <a:textField name="contract_number" bindTarget="et_document_return_form_ds" prompt="合同编号" />
                <a:textField name="bp_name" bindTarget="et_document_return_form_ds" prompt="客户名称" />
                <a:textField name="bp_agent_name" bindTarget="et_document_return_form_ds" prompt="代理商名称" />
                <a:datePicker name="et_date_from" bindTarget="et_document_return_form_ds" prompt="结清日期从"/>
                <a:datePicker name="et_date_to" bindTarget="et_document_return_form_ds" prompt="结清日期到"/>
                <a:datePicker name="send_date_from" bindTarget="et_document_return_form_ds" prompt="邮寄时间从"/>
                <a:datePicker name="send_date_to" bindTarget="et_document_return_form_ds" prompt="邮寄时间到"/>
                <a:comboBox name="send_object" bindTarget="et_document_return_form_ds" prompt="邮寄内容"/>
                <a:textField name="send_num" bindTarget="et_document_return_form_ds" prompt="快递单号"/>
                <a:textField name="pattern" bindTarget="et_document_return_form_ds" prompt="机型"/>
                <a:textField name="machine_number" bindTarget="et_document_return_form_ds" prompt="机号"/>

            </a:form>
            <a:grid id="source_to_grid" bindTarget="et_document_return_grid_ds" navBar="true" marginHeight="200" marginWidth="100">
                <a:columns>
                    <a:column name="contract_number" prompt="合同编号" width="120"/>
                    <a:column name="bp_code"  prompt="客户编号" width="120"/>
                    <a:column name="bp_name" prompt="客户名称" />
                    <a:column name="bp_agent_code" prompt="代理商编号"/>
                    <a:column name="bp_agent_name"  prompt="代理商名称" width="100" />
                    <a:column name="cf_item_n" prompt="现金流描述" width="200"/>
                    <a:column name="pattern"  prompt="机型" width="100"/>
                    <a:column name="machine_number"  prompt="机号" width="100"/>
                    <a:column name="et_date"  prompt="结清日期" width="100" renderer="Leaf.formatDate"/>
                    <a:column name="send_object"  prompt="邮寄内容" width="100"/>
                    <a:column name="send_date"  prompt="邮寄时间" width="100" renderer="Leaf.formatDate"/>
                    <a:column name="send_num"  prompt="快递单号" width="100"/>
                    <a:column name="recipients"  prompt="收件人" width="100"/>
                    <a:column name="invoice_number"  prompt="发票号码" width="100"/>
                    <a:column name="vat_invoice_code"  prompt="发票代码" width="100"/>
                    <a:column name="total_amount"  footerRenderer="summaryRenderer" prompt="发票金额" width="100" renderer="Leaf.formatMoney"/>
                    <a:column name="invoice_date"  prompt="开票时间" width="100" renderer="Leaf.formatDate"/>
                    <a:column name="download" prompt="电子发票下载" renderer="downloadPdf" align="center"/>
                    <a:column name="division"  prompt="产品线" width="100" />
                    <a:column name="lease_channel_desc"  prompt="商业模式" width="100" />
                    <a:column name="business_type_n"  prompt="租赁类型" width="100"/>
                    <a:column name="equipment_number"  prompt="装备号" width="100"/>
                </a:columns>
            </a:grid>
        </a:screenBody>
    </a:view>
</a:screen>
