<?xml version="1.0" encoding="UTF-8"?>
<a:screen xmlns:a="http://www.leaf-framework.org/application" customizationEnabled="true"
          trace="true">
    <a:init-procedure/>
    <a:view>

        <a:link id="con_contract_get_layout_code_link_id" model="cont.CON500.con_contract_get_layout_code"
                modelaction="update"/>
        <a:link id="${/parameter/@layout_code}con_contract_query_link"
                url="${/request/@context_path}/modules/cont/CON505/con_contract_modify.lview"/>
        <script type="text/javascript"><![CDATA[

        // window['${/parameter/@layout_code}_user_button1_layout_dynamic_click'] = function() {
        //     var lnds = get_dsid_by_tabcode_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'G_CONTRACT_RESULT', 'hls_journal_detail');
        //      $(lnds).query();
        //      debugger
        //     var ds_id = get_dsid_by_tabcode_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'G_CONTRACT_AGENT', 'hls_journal_detail');
        //     $(ds_id).setQueryUrl('${/request/@context_path}/autocrud/cont.CON3400.contract_sales_report_query/query');
        //     $(ds_id).query();
        //
        // }

       /* window['${/parameter/@bp_seq}${/parameter/@layout_code}_on_layout_dynamic_grid_query'] = function(ds, qpara, bp_seq) {
            console.log(ds.id)
            var lnds = get_dsid_by_tabcode_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'G_CONTRACT_RESULT', 'hls_journal_detail');
            var lndss = get_dsid_by_tabcode_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'G_CONTRACT_RESULT_COPY', 'hls_journal_detail');
            if(lndss==ds.id){
               var ds_id = get_dsid_by_tabcode_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'G_CONTRACT_AGENT', 'hls_journal_detail');
               $(ds_id).setQueryUrl('${/request/@context_path}/autocrud/cont.CON3400.contract_sales_report_query/query');
               $(ds_id).query();
                $(lnds).setQueryUrl('${/request/@context_path}/autocrud/cont.CON3400.contract_sales_report_query_lns/query');
                $(lnds).query();
           }

        };
         var division=''; var division_descrption=''; var bp_id_agent_level1_id=''; var bp_id_agent_level1_desc='';
        //更新时调用
        window['${/parameter/@bp_seq}${/parameter/@layout_code}_on_layout_dynamic_update'] = function (ds, record, name, value, old_value, bp_seq) {
            debugger;
            if(ds.id=='CONTRACT_SALES_ENTRANCE_AC_F_QUERY__ds'){
                if(name=='division'){
                    division=division+','+value;
                    record.data.division_s=division;
                }
                if(name=='division_n'){
                    division_descrption=division_descrption+value+',';
                    record.data.division_descrption=division_descrption;
                    $jq('[name="division_descrption"]').val(division_descrption)
                }
                if(name=='bp_id_agent_level1'){
                    if(bp_id_agent_level1_id==''){
                        bp_id_agent_level1_id=value;
                    }else {
                        bp_id_agent_level1_id=bp_id_agent_level1_id+','+value;
                    }
                    record.data.bp_id_agent_level1_id=bp_id_agent_level1_id;
                }
                if(name=='bp_id_agent_level1_n'){
                    bp_id_agent_level1_desc=bp_id_agent_level1_desc+value+',';
                    record.data.bp_id_agent_level1_desc=bp_id_agent_level1_desc;
                    $jq('[name="bp_id_agent_level1_desc"]').val(bp_id_agent_level1_desc);
                }
            }
        }
        window['${/parameter/@bp_seq}${/parameter/@layout_code}_RESET_LAYOUT_DYNAMIC_CLICK']=function(){
            for(var i=0;i<window['${/parameter/@bp_seq}${/parameter/@layout_code}_layoutDataSetList'].length;i++){
                if(!$(window['${/parameter/@bp_seq}${/parameter/@layout_code}_layoutDataSetList'][i]).queryurl){
                    $(window['${/parameter/@bp_seq}${/parameter/@layout_code}_layoutDataSetList'][i]).reset();
                    division=''; division_descrption=''; bp_id_agent_level1_id='';  bp_id_agent_level1_desc='';
                    $jq('[name="division_descrption"]').val(division_descrption);
                    $jq('[name="division_s"]').val(division);
                    $jq('[name="bp_id_agent_level1_id"]').val(bp_id_agent_level1_id);
                    $jq('[name="bp_id_agent_level1_desc"]').val(bp_id_agent_level1_desc);
                }
            }
        };
        Leaf.onReady(function(){
           var table= document.getElementById('CONTRACT_SALES_ENTRANCE_AC_G_CONTRACT_RESULT_COPY_hls_journal_detail_layout_grid_id_wrap');
            table.style.display ="none";
        });*/

        function con_contract_query() {
                var headers_ds = $('contract_sales_report_ds');
                var record = headers_ds.getAt(0);
                record.data.division='';
                if(record.data.lease_name10=='Y'){
                    record.data.division=',10';
                }
                if(record.data.lease_name20=='Y'){
                    record.data.division=record.data.division+',20';
                }
                if(record.data.lease_name30=='Y'){
                    record.data.division=record.data.division+',30';
                }
                if(record.data.lease_name40=='Y'){
                    record.data.division=record.data.division+',40';
                }
                if(record.data.lease_name50=='Y'){
                    record.data.division=record.data.division+',50';
                }
                if(record.data.lease_name60=='Y'){
                    record.data.division=record.data.division+',60';
                }
                if(record.data.lease_name70=='Y'){
                    record.data.division=record.data.division+',70';
                };
            if(record.data.lease_name80=='Y'){
                record.data.division=record.data.division+',80';
            };
            if(record.data.lease_name90=='Y'){
                record.data.division=record.data.division+',90';
            };
            if(record.data.lease_name91=='Y'){//addby xsh35973 20221011 I-12357新增产品线
                record.data.division=record.data.division+',91';
            };
            if(record.data.lease_name92=='Y'){//add by gzj
                record.data.division=record.data.division+',92';
            };
                record.data.division=record.data.division.substr(1,record.data.division.length);
            $('contract_sales_result_ds').query();
            $('contract_sales_agent_result_ds').query();
        }

        function con_contract_reset() {
            $('contract_sales_report_ds').reset();
        }
        function formatDate(value, record, name, config_record) {
            if (name == 'journal_date') {
                return /\d{4}-\d{1,2}-\d{1,2}/g.exec(value);
            }
        }
        ]]></script>
        <a:dataSets>
            <a:dataSet id="business_type_n_ds">
                <a:datas>
                    <a:record code_value="LEASE" code_value_name="直租"/>
                    <a:record code_value="LEASEBACK" code_value_name="售后回租"/>
                </a:datas>
            </a:dataSet>
            <a:dataSet id="contract_sales_report_ds"  autoPageSize="true">
                <a:fields>
                    <a:field name="bp_agent_name"/>
                    <a:field name="journal_num"/>
                    <a:field name="journal_date"/>
                    <a:field name="journal_date_from"/>
                    <a:field name="journal_date_to"/>
                    <a:field name="division"/>
                    <a:field name="division_n"/>
                    <a:field name="contract_number"/>
                    <a:field name="business_type"/>
                    <a:field name="business_type_n" displayField="code_value_name" options="business_type_n_ds"
                             returnField="business_type" valueField="code_value"/>
                    <a:field name="extra_nam" lovGridHeight="350" lovHeight="500" lovService="cont.CON3400.hls_bp_master_for_lov?bp_category=AGENT" lovWidth="800" displayField="bp_name" valueField="bp_id">
                        <a:mapping>
                            <a:map from="bp_id" to="bp_id"/>
                            <a:map from="extra_nam" to="extra_nam"/>
                            <a:map from="bp_name" to="bp_name"/>
                        </a:mapping>
                    </a:field>
                    <a:field name="bp_id"/>
                    <a:field name="bp_name"/>
                    <a:field name="bp_tenant_code"/>
                    <a:field name="bp_tenant_name"/>
                    <a:field name="modelcd"/>
                    <a:field name="pattern"/>
                    <a:field name="machine_number"/>
                    <a:field name="sale_amount"/>
                    <a:field name="sale_penalty"/>
                    <a:field name="sale_other"/>

                    <a:field name="agent_name"/>
                    <a:field name="vender_name"/>
                    <a:field name="sale_amount"/>
                    <a:field name="sale_penalty"/>
                    <a:field name="sale_other"/>
                    <a:field name="sum_total"/>

                    <a:field name="brand_value"/>
                    <a:field name="using_hour"/>
                </a:fields>
            </a:dataSet>
            <a:dataSet id="contract_sales_result_ds" model="cont.CON3400.contract_sales_report_query_lns" autoPageSize="true" queryDataSet="contract_sales_report_ds" autoQuery="true"/>
            <a:dataSet id="contract_sales_agent_result_ds" model="cont.CON3400.contract_sales_report_query"  autoPageSize="true" queryDataSet="contract_sales_report_ds" autoQuery="true"/>

        </a:dataSets>

        <a:screenBody>
            <a:screenTopToolbar>
                <a:gridButton click="con_contract_query" text="HLS.QUERY"/>
                <a:gridButton click="con_contract_reset" text="HLS.RESET"/>
            </a:screenTopToolbar>

            <a:form bindTarget="contract_sales_report_ds" column="4" title="销售收入查询" marginWidth="40">
                <a:datePicker name="journal_date_from" bindTarget="contract_sales_report_ds" prompt="记账日期从"/>
                <a:datePicker name="journal_date_to" bindTarget="contract_sales_report_ds" prompt="记账日期到"/>
                <a:comboBox name="business_type_n" bindTarget="contract_sales_report_ds" prompt="业务类型"/>
                <a:multiLov name="extra_nam" displayField="extra_nam" valueField="bp_id"
                            bindTarget="contract_sales_report_ds"  prompt="代理店"
                            lovWidth="300" lovHeight="300" lovGridHeight="300" title="代理店lov"  width="400"/>
                <a:checkBox name="lease_name10" bindTarget="contract_sales_report_ds" prompt="国产挖机"/>
                <a:checkBox name="lease_name20" bindTarget="contract_sales_report_ds" prompt="进口挖机"/>
                <a:checkBox name="lease_name30" bindTarget="contract_sales_report_ds" prompt="高空作业车"/>
                <a:checkBox name="lease_name50" bindTarget="contract_sales_report_ds" prompt="星邦高空作业车"/>
                <a:checkBox name="lease_name60" bindTarget="contract_sales_report_ds" prompt="新业务"/>
                <a:checkBox name="lease_name70" bindTarget="contract_sales_report_ds" prompt="铁甲业务"/>
                <a:checkBox name="lease_name80" bindTarget="contract_sales_report_ds" prompt="叉车"/>
                <a:checkBox name="lease_name90" bindTarget="contract_sales_report_ds" prompt="租赁二手机"/>
                <a:checkBox name="lease_name40" bindTarget="contract_sales_report_ds" prompt="其它"/>
                <a:checkBox name="lease_name91" bindTarget="contract_sales_report_ds" prompt="神钢建机"/>//addby xsh35973 20221011 I-12357新增产品线
                <a:checkBox name="lease_name92" bindTarget="contract_sales_report_ds" prompt="北京卡家"/>
            </a:form>

            <a:grid id="contract_sales_result_ds_grid" bindTarget="contract_sales_result_ds" marginHeight="150" navBar="true" marginWidth="40">
                <a:columns>
                    <a:column name="bp_agent_name"  prompt="代理店"  align="center" width="220"/>
                    <a:column name="journal_num"  prompt="凭证编号"  align="center" width="220"/>
                    <a:column name="journal_date"  prompt="记账日期"  align="center" width="220" renderer="formatDate"/>
                    <a:column name="division_n"  prompt="租赁物"  align="center" width="220"/>
                    <a:column name="contract_number"  prompt="合同编号"  align="center" width="220"/>
                    <a:column name="business_type_n"  prompt="业务类型"  align="center" width="220"/>
                    <a:column name="bp_tenant_code"  prompt="承租人编号"  align="center" width="220"/>
                    <a:column name="bp_tenant_name"  prompt="承租人名称"  align="center" width="220"/>
                    <a:column name="modelcd"  prompt="机型"  align="center" width="220"/>
                    <a:column name="pattern"  prompt="型号"  align="center" width="220"/>
                    <a:column name="machine_number"  prompt="机号"  align="center" width="220"/>
                    <a:column name="brand_value"  prompt="品牌"  align="center" width="220"/>
                    <a:column name="using_hour"  prompt="使用小时数"  align="center" width="220" renderer="Leaf.formatMoney"/>
                    <a:column name="sale_amount"  prompt="销售收入"  align="center" width="220"/>
                    <a:column name="sale_penalty"  prompt="逾期利息收入"  align="center" width="220"/>
                    <a:column name="sale_other"  prompt="其他收入"  align="center" width="220"/>
                </a:columns>
            </a:grid>

            <a:grid id="contract_sales_agent_result_ds_grid" bindTarget="contract_sales_agent_result_ds" marginHeight="150" navBar="true" marginWidth="40">
                <a:columns>
                    <a:column name="agent_name"  prompt="代理店"  align="center" width="220"/>
                    <a:column name="vender_name"  prompt="厂商"  align="center" width="220"/>
                    <a:column name="sale_amount"  prompt="销售收入"  align="center" width="220"/>
                    <a:column name="sale_penalty"  prompt="逾期利息收入"  align="center" width="220"/>
                    <a:column name="sale_other"  prompt="其他收入"  align="center" width="220"/>
                    <a:column name="sum_total"  prompt="合计"  align="center" width="220"/>
                </a:columns>
            </a:grid>
        </a:screenBody>

        <!--<a:screen-include screen="modules/cont/CON500/con_contract_get_layout_code.lview"/>-->
    </a:view>
</a:screen>
