<?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="cont.CON1260.get_period_default" rootPath="sys_default_time"/>
        <a:model-query fetchAll="true" model="basic.hls_lease_channel_for_lov" rootPath="con1060_lease_list"/>
        <a:model-query defaultWhereClause="t1.business_type in (&apos;LEASE&apos;,&apos;LEASEBACK&apos;)" fetchAll="true" model="basic.hls_business_type_for_lov" rootPath="business_type_path"/>
    </a:init-procedure>
    <a:view>
        <script type="text/javascript"><![CDATA[
        function month_finance_query() {
            $('month_finance_grid_ds').query();
        }

        function month_finance_reset(){
            $('month_finance_form_ds').reset();
        }

        function month_finance_export() {
            $('source_to_grid')._export(null,'月别融资租赁现状');
        }

        function guarantor_sum_foot(data, name) {
            if (name == 'accessory_pattern') {
                return '<font color="red">合计:</font>';
            } else if (name == 'quantity') {
                return guarantor_colum_caculateTotal(data, name);
            } else if (name == 'lease_item_amount') {
                return guarantor_colum_caculateTotal(data, name);
            } else if (name == 'down_payment') {
                return guarantor_colum_caculateTotal(data, name);
            } else if (name == 'finance_amount') {
                return guarantor_colum_caculateTotal(data, name);
            } else if (name == 'tenant_service_charge') {
                return guarantor_colum_caculateTotal(data, name);
            } else if (name == 'agent_fee') {
                return guarantor_colum_caculateTotal(data, name);
            } else if (name == 'agent_bond') {
                return guarantor_colum_caculateTotal(data, name);
            } else if (name == 'tenant_bond') {
                return guarantor_colum_caculateTotal(data, name);
            } else if (name == 'insurance_method') {
                return guarantor_colum_caculateTotal(data, name);
            } else if (name == 'direct_agent_fee') {
                return guarantor_colum_caculateTotal(data, name);
            } else if (name == 'main_factory_price') {
                return guarantor_colum_caculateTotal(data, name);
            }
        }

        function guarantor_colum_caculateTotal(data, name) {
            var total = 0;
            var length = data.length;
            var value = 0;
            for (var i = 0;i < length;i++) {
                if (Ext.isEmpty(data[i].get(name))) {
                    value = 0;
                } else {
                    value = data[i].get(name);
                }
                total = plus(total, value);
            }
            if (name == 'quantity'){
                return '<font color=red>' + total + '</font>';
            }
            else {
                return '<font color=red>' + Leaf.formatMoney(total) + '</font>';
            }
        }

        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'] = 't.contract_id';

        }

        ]]></script>

        <a:dataSets>
            <a:dataSet id="contract_status_ds" lookupCode="CON500_CONTRACT_STATUS"/>
            <a:dataSet id="division_name_ds" loadData="true" model="cont.CON1260.hls_division"/>
            <a:dataSet id="business_type_ds">
                <a:datas dataSource="/model/business_type_path"/>
            </a:dataSet>
            <a:dataSet id="con1060_lease_channel_ds">
                <a:datas dataSource="/model/con1060_lease_list"/>
            </a:dataSet>
            <a:dataSet id="month_finance_form_ds">
                <a:fields>
                    <a:field name="contract_number" lovGridHeight="400" lovHeight="500" lovLabelWidth="100" lovService="cont.CON1260.con_receipts_contract" lovWidth="500"  title="合同编号">
                        <a:mapping>
                            <a:map from="contract_number" to="contract_number"/>
                        </a:mapping>
                    </a:field>
                    <a:field name="bp_agent_name" lovGridHeight="330" lovHeight="470" lovLabelWidth="120" lovService="cont.CON1260.con_bp_agent_query" lovWidth="700" title="代理商">
                        <a:mapping>
                            <a:map from="bp_agent_name" to="bp_agent_name"/>
                        </a:mapping>
                    </a:field>
                    <a:field name="period_name_from" lovGridHeight="300" lovHeight="500"
                             lovService="cont.CON1260.con_period_lov"
                             lovWidth="500"  title="GLD_PERIODS.PERIOD_NAME"
                             defaultValue="${/model/sys_default_time/record/@monthlist}">
                        <a:mapping>
                            <a:map from="monthlist" to="period_name_from"/>
                        </a:mapping>
                    </a:field>
                    <a:field name="period_name_to" lovGridHeight="300" lovHeight="500"
                             lovService="cont.CON1260.con_period_lov"
                             lovWidth="500"  title="GLD_PERIODS.PERIOD_NAME"
                             defaultValue="${/model/sys_default_time/record/@monthlist}">
                        <a:mapping>
                            <a:map from="monthlist" to="period_name_to"/>
                        </a:mapping>
                    </a:field>
                    <a:field name="lease_channel_desc" displayField="description" options="con1060_lease_channel_ds"
                             returnField="lease_channel" valueField="lease_channel"/>
                    <a:field name="business_type_n" displayField="description" options="business_type_ds" returnField="business_type" valueField="business_type"/>
                    <a:field name="division_n" displayField="description" options="division_name_ds"
                             returnField="division" valueField="division"/>
                    <a:field name="contract_status_n" displayField="code_value_name" options="contract_status_ds" returnField="contract_status" valueField="code_value"/>
                    <a:field name="__async__"  defaultValue="Y" prompt="异步导出"/>
                </a:fields>
            </a:dataSet>
            <a:dataSet id="month_finance_grid_ds" autoQuery="false"
                       model="cont.CON1260.con_month_finance_status"
                       queryDataSet="month_finance_form_ds" selectable="true" selectionModel="single" autoPageSize="false" pageSize="100">

                <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="month_finance_query" text="查询"/>
                <a:gridButton click="month_finance_reset" text="重置"/>
                <a:gridButton click="month_finance_export" text="导出"/>
            </a:screenTopToolbar>
            <a:form column="4" marginWidth="100" title="查询条件">
                <a:lov name="contract_number" bindTarget="month_finance_form_ds" prompt="合同编号" />
                <a:lov name="bp_agent_name" bindTarget="month_finance_form_ds" prompt="代理商名称" />
                <a:lov name="period_name_from" bindTarget="month_finance_form_ds" prompt="执行月份从" />
                <a:lov name="period_name_to" bindTarget="month_finance_form_ds" prompt="执行月份到" />
                <a:textField name="extra_nam" bindTarget="month_finance_form_ds" prompt="代理商简称" />
                <a:comboBox name="lease_channel_desc" bindTarget="month_finance_form_ds" prompt="商业模式"/>
                <a:comboBox name="business_type_n" bindTarget="month_finance_form_ds" prompt="业务类型"/>
                <a:textField name="bp_name" bindTarget="month_finance_form_ds" prompt="客户名称"  />
                <a:datePicker name="first_pay_date_from" bindTarget="month_finance_form_ds" prompt="首期还款日从"  />
                <a:datePicker name="first_pay_date_to" bindTarget="month_finance_form_ds" prompt="首期还款日到"  />
                <a:comboBox name="division_n" bindTarget="month_finance_form_ds" prompt="产品线"/>
                <a:comboBox name="contract_status_n" bindTarget="month_finance_form_ds" prompt="合同状态" />
                <a:datePicker name="retail_date_from" bindTarget="month_finance_form_ds" prompt="retail日从"  />
                <a:datePicker name="retail_date_to" bindTarget="month_finance_form_ds" prompt="retail日到"  />
                <a:textField name="pattern" bindTarget="month_finance_form_ds" prompt="主物件机型"  />
                <a:textField name="machine_number" bindTarget="month_finance_form_ds" prompt="主物件机号"  />
            </a:form>
            <a:grid id="source_to_grid" bindTarget="month_finance_grid_ds" navBar="true" marginHeight="200" marginWidth="100">
                <a:columns>
                    <a:column name="lease_execution_year" prompt="执行年月" width="120"/>
                    <a:column name="lease_channel_desc" prompt="商业模式" width="120"/>
                    <a:column name="business_type_n" prompt="业务类型" width="120"/>
                    <a:column name="large_area"  prompt="支社名称" width="100" />
                    <a:column name="bp_agent_name" prompt="代理商名称" />
                    <a:column name="extra_nam" prompt="代理商简称" />
                    <a:column name="submit_date" prompt="申请日期" width="80"/>
                    <a:column name="lease_execution_date"  prompt="执行日期" width="100"/>
                    <a:column name="contract_number"  prompt="合同编号" width="100" />
                    <a:column name="contract_status_n"  prompt="合同状态" width="100" />
                    <a:column name="bp_name"  prompt="客户名称" width="100" />
                    <a:column name="sys_level"  prompt="AS等级" width="100" />
                    <a:column name="score_level"  prompt="信审等级" width="100" />
                    <a:column name="division_n"  prompt="产品名称" width="100"/>
                    <a:column name="pattern"  prompt="主物件机型" width="100" />
                    <a:column name="accessory_pattern"  prompt="破碎器机型" width="100" footerRenderer="guarantor_sum_foot"/>
                    <a:column name="quantity"  prompt="台数" width="100" footerRenderer="guarantor_sum_foot"/>
                    <a:column name="first_pay_date"  prompt="首期还款日" width="100"/>
                    <a:column name="lease_term_month"  prompt="租赁个月" width="100"/>
                    <a:column name="int_rate"  prompt="适用利率（%）" width="100"/>
                    <a:column name="annual_pay_times_n"  prompt="支付方式" width="100"/>
                    <a:column name="deduct_bank_n"  prompt="收款方式" width="100"/>
                    <a:column name="machine_number"  prompt="主物件机号" width="100"/>
                    <a:column name="accessory_machine_number"  prompt="破碎器机号" width="100"/>
                    <a:column name="sales_method_n"  prompt="销售方式" width="100"/>
                    <a:column name="as_item_source"  prompt="AS 物件来源" width="100"/>
                    <a:column name="special_policy"  prompt="特殊政策" width="100"/>
                    <a:column name="product_name"  prompt="融资商品名1" width="100"/>
                    <a:column name="sub_price_list_name"  prompt="融资商品名2" width="100"/>
                    <a:column name="lease_item_amount"  prompt="购买价格" width="100" renderer="Leaf.formatMoney" footerRenderer="guarantor_sum_foot"/>
                    <a:column name="lease_item_amount2"  prompt="执行资产总计" width="100" renderer="Leaf.formatMoney"/>
                    <a:column name="down_payment_ratio"  prompt="首付率(%)" width="100"/>
                    <a:column name="down_payment"  prompt="首付款" width="100" renderer="Leaf.formatMoney" footerRenderer="guarantor_sum_foot"/>
                    <a:column name="finance_amount"  prompt="DCFL租赁本金" width="100" renderer="Leaf.formatMoney" footerRenderer="guarantor_sum_foot"/>
                    <a:column name="tenant_service_charge"  prompt="客户手续费" width="100" renderer="Leaf.formatMoney" footerRenderer="guarantor_sum_foot"/>
                    <a:column name="agent_fee"  prompt="代理商手续费" width="100" renderer="Leaf.formatMoney" footerRenderer="guarantor_sum_foot"/>
                    <a:column name="agent_bond"  prompt="代理商保证金" width="100" renderer="Leaf.formatMoney" footerRenderer="guarantor_sum_foot"/>
                    <a:column name="tenant_bond"  prompt="客户保证金" width="100" renderer="Leaf.formatMoney" footerRenderer="guarantor_sum_foot"/>
                    <a:column name="inception_of_lease"  prompt="日程交付日" width="100" align="center"/>
                    <a:column name="contract_inception_date"  prompt="合同交付日" width="100"/>
                    <a:column name="hd_user_col_v05_n"  prompt="是否打包产品" width="100"/>
                    <a:column name="wholesale_date"  prompt="WHOLESALE日期" width="100"/>
                    <a:column name="retail_date"  prompt="RETAIL日期" width="100"/>
                    <a:column name="insurance_fee"  prompt="保险费" width="100" renderer="Leaf.formatMoney" footerRenderer="guarantor_sum_foot"/>
                    <a:column name="direct_agent_fee"  prompt="直销手续费" width="100" renderer="Leaf.formatMoney" footerRenderer="guarantor_sum_foot"/>
                    <a:column name="main_factory_price"  prompt="主机出厂价" width="100" renderer="Leaf.formatMoney" footerRenderer="guarantor_sum_foot"/>
                    <a:column name="main_factory_sap_zaldt"  prompt="付款时间主机成本" width="120"/>
                    <a:column name="main_profit"  prompt="主机利润" width="100" renderer="Leaf.formatMoney"/>
                    <a:column name="main_profit_sap_zaldt"  prompt="付款时间主机利润" width="120"/>
                    <a:column name="accessory_factory_price"  prompt="破碎机出厂价" width="100" renderer="Leaf.formatMoney"/>
                    <a:column name="accessory_factory_sap_zaldt"  prompt="付款时间破碎器成本" width="120"/>
                    <a:column name="accessory_profit"  prompt="破碎机利润" width="100" renderer="Leaf.formatMoney"/>
                    <a:column name="accessory_profit_sap_zaldt"  prompt="付款时间破碎器利润" width="120"/>
                    <a:column name="cost_req_date"  prompt="付款申请时间（第一次付成本）" width="200" align="center"/>
                    <a:column name="profit_req_date"  prompt="付款申请时间（第一次付利润）" width="200" align="center"/>
                    <a:column name="max_cashflow_count"  prompt="历史最大逾期期数" width="100" align="center"/>
                    <a:column name="equipment_number"  prompt="装备号" width="100" align="center"/>
                </a:columns>
            </a:grid>
        </a:screenBody>
    </a:view>
</a:screen>
