<?xml version="1.0" encoding="UTF-8"?>
<!--
    $Author: qwm  
    $Date: 2013-6-24 下午1:28:49  
    $Revision: 1.0  
    $Purpose: 
-->
<a:screen xmlns:a="http://www.leaf-framework.org/application">
    <a:init-procedure><![CDATA[
    ]]></a:init-procedure>
    <a:view package="leaf.ui.std" template="default">
        <a:link id="con_contract_et_heads_save_link" modelaction="insert" url="${/request/@context_path}/autocrud/cont.CON701.con_contract_et_heads/batch_update"/>
        <a:link id="con_contract_et_lines_save_link" modelaction="insert" url="${/request/@context_path}/autocrud/cont.CON701.con_contract_et_lines/batch_update"/>
        <a:link id="con_contract_et_calculate_link" url="${/request/@context_path}/modules/cont/CON610/con_contract_et_calculate.lsc"/>
        <a:link id="con_contract_et_save_link" model="cont.CON610.con_contract_et_save" modelaction="execute"/>
        <a:link id="con_contract_et_submit_link" model="cont.CON610.con_contract_et_submit" modelaction="execute"/>
        <a:link id="con_contract_termination_date_check_link" model="cont.CON701.con_contract_termination_date_check" modelaction="execute"/>
        <a:link id="attachment_downloadFile_link" url="${/request/@context_path}/downloadFile.lview"/>
        <div/>
        <script type="text/javascript"><![CDATA[
            function Screen_forward() {
                history.go(1);
            }
            
            function Screen_back() {
                history.go(-1);
            }
            
            function Screen_exit() {
                $('${/parameter/@winId}').close();
            }
            
            function contractCreateScreen_calculate() {
            
                var ds = $('contract_et_Screen_mainDs'),
                    et_ds = $('early_terminationDs'),
                    et_record = et_ds.getAt(0),
                    record = ds.getCurrentRecord();
                var et_agreement_id;
                if (record.validateRecord(true)) {
                    var termination_date = Leaf.formatDate(record.get('termination_date'));
                    var contract_id = record.get('contract_id');
                    var et_type = record.get('et_type');
                    var et_profile = record.get('et_profile');
                    var et_ratio = record.get('et_ratio');
                    if (et_record) {
                        et_agreement_id = et_record.get('et_agreement_id');
                    }
                    Leaf.Masker.mask(Ext.getBody(), '正在加载..');
                    Leaf.request({
                        url: $('con_contract_et_calculate_link').getUrl(),
                        para: {
                            termination_date: termination_date,
                            contract_id: contract_id,
                            et_type: et_type,
                            et_agreement_id: et_agreement_id,
                            et_profile: et_profile,
                            et_ratio: et_ratio
                        },
                        success: function(args) { //
                            var et_agreement_id = args.result.et_agreement_id;
                            et_ds.setQueryParameter('et_agreement_id', et_agreement_id);
                            et_ds.query();
            
                            $('unreceivedAmountDs').setQueryParameter('contract_id', record.get('contract_id'));
                            $('unreceivedAmountDs').setQueryParameter('et_agreement_id', et_agreement_id);
                            $('unreceivedAmountDs').query();
            
                            $('receivedAmountDs').setQueryParameter('contract_id', record.get('contract_id'));
                            $('receivedAmountDs').query();
                            document.getElementById("detail_flag_id").style.display = "";
                            Leaf.Masker.unmask(Ext.getBody());
                        },
                        failure: function() {
                            Leaf.Masker.unmask(Ext.getBody());
                        },
                        error: function() {
                            Leaf.Masker.unmask(Ext.getBody());
                        },
                        scope: this
                    });
                    Leaf.Masker.unmask(Ext.getBody());
                }
            
            }
            
            function et_save(value) {
                var et_ds = $('early_terminationDs'),
                    et_record = et_ds.getAt(0);
                if (et_record) {
                    var et_agreement_id = et_record.get('et_agreement_id'),
                        penalty = et_record.get('penalty'),
                        et_fee = et_record.get('et_fee');
                    et_total_amount = et_record.get('et_total_amount');
                    Leaf.request({
                        url: $('con_contract_et_save_link').getUrl(),
                        para: {
                            et_agreement_id: et_agreement_id,
                            penalty: penalty,
                            et_fee: et_fee,
                            et_total_amount: et_total_amount
                        },
                        success: function(args) { //
                            if (value == 'sub') {
                                et_submit();
            
                            } else {
                                Leaf.SideBar.show({
                                    msg: '${l:HLS.SUBMIT_SUCCESS}',
                                    duration: 2000
                                });
                            }
                        },
                        scope: this
                    });
                } else {
                    Leaf.showMessage('提示', '请先测算！');
                }
            
            }
            
            function et_submit() {
                var et_ds = $('early_terminationDs'),
                    et_record = et_ds.getAt(0);
                if (et_record) {
                    var et_agreement_id = et_record.get('et_agreement_id');
                    Leaf.showConfirm('${l:HLS.PROMPT}', '确定要提交？', function() {
                        Leaf.request({
                            url: $('con_contract_et_submit_link').getUrl(),
                            para: {
                                et_agreement_id: et_agreement_id
                            },
                            success: function(args) { //
                                Leaf.SideBar.show({
                                    msg: '${l:HLS.SUBMIT_SUCCESS}',
                                    duration: 2000
                                });
                                $('con_contract_adv_settle_create_window').close();
                                $('contract_et_Screen_mainDs').query();
                            },
                            scope: this
                        });
                    });
                } else {
                    Leaf.showMessage('提示', '请先测算！');
                }
            
            }
            
            function et_submit_entrance() {
                et_save('sub');
            }
            
            function onUpdate(ds, record, name, value) {
                if (name == 'et_fee' || name == 'penalty') {
                    var et_fee = record.get('et_fee');
                    var penalty = record.get('penalty');
                    var residual_value = record.get('residual_value');
                    var overdue_amount = record.get('overdue_amount');
                    var undue_principal = record.get('undue_principal');
                    var et_interest = record.get('et_interest');
                    var rentals_payable = record.get('rentals_payable');
                    if (!et_fee) {
                        et_fee = 0;
                    }
                    if (!penalty) {
                        penalty = 0;
                    }
                    record.set('et_total_amount', et_fee + penalty + residual_value + overdue_amount + undue_principal + et_interest + rentals_payable);
                }
            }
            
            function open_attachment_window(){
                    var val = $('early_terminationDs').getAt(0).get('et_agreement_id');
	        	    var url = $('attachment_downloadFile_link').getUrl() + '?table_name=CON_CONTRACT_ET_HD&header_id=' + val;
	                var win = new Leaf.Window({
	                    url: url,
	                    title: '附件查看',
	                    id: 'approve_downloadFile_id',
	                    width: 850,
	                    height: 400
	                });
	                win.on('close', function() {
	                });    
        	}
        ]]></script>
        <a:dataSets>
            <a:dataSet id="contract_et_Screen_mainDs2" model="cont.CON360.con_contract_et_hd_maintain_query"><![CDATA[
        	]]></a:dataSet>
            <a:dataSet id="early_terminationDs" model="cont.CON610.con_contract_et_hd">
                <!-- <a:fields>
                    <a:field name="overdue_amount" required="true" />
                    <a:field name="rentals_payable" required="true" />
                    <a:field name="undue_principal" required="true" />
                    <a:field name="et_interest" required="true" />
                    <a:field name="et_fee" required="true" />
                    <a:field name="residual_value" required="true" />
                    <a:field name="et_rate" required="true" />
                    
                </a:fields> -->
                <a:events>
                    <a:event name="update" handler="onUpdate"/>
                </a:events>
            </a:dataSet>
            <!-- <a:dataSet id="rentPaymentDs" model="cont.CON701.con_ren_payment_status_query" submitUrl="${/request/@context_path}/autocrud/cont.CON701.con_contract_et_lines/batch_update"><![CDATA[
            
            ]]></a:dataSet> -->
            <a:dataSet id="receivedAmountDs" model="cont.CON610.con_contract_received_amount"/>
            <a:dataSet id="unreceivedAmountDs" model="cont.CON610.con_contract_unreceived_amount"/>
        </a:dataSets>
        <a:screenBody>
            <!--<a:screenTopToolbar>-->
            <!--<a:gridButton click="Screen_back" text="HLS.BACK"/>
                <a:gridButton click="Screen_forward" text="HLS.FORWARD"/>-->
            <!--<a:gridButton click="Screen_exit" text="关闭"/>
                <a:gridButton click="contractCreateScreen_calculate" text="测算"/>
                <a:gridButton click="et_save" text="HLS.SAVE"/>
                <a:gridButton click="et_submit_entrance" text="提交"/>-->
            <!--</a:screenTopToolbar>-->
            <a:gridButton click="open_attachment_window" text="附件查看"/>
            <a:form column="4" labelWidth="110" marginWidth="30" title="HLS.QUERY_TITLE">
                <a:textField name="et_agreement_number" bindTarget="contract_et_Screen_mainDs2" prompt="资产处置编号" readOnly="true"/>
                <a:textField name="contract_number" bindTarget="contract_et_Screen_mainDs2" prompt="合同编码" readOnly="true"/>
                <a:textField name="contract_name" bindTarget="contract_et_Screen_mainDs2" prompt="合同名称" readOnly="true"/>
                <a:textField name="document_type_desc" bindTarget="contract_et_Screen_mainDs2" prompt="合同类型" readOnly="true"/>
                <a:textField name="document_category_desc" bindTarget="contract_et_Screen_mainDs2" prompt="合同类别" readOnly="true"/>
                <a:textField name="bp_name" bindTarget="contract_et_Screen_mainDs2" prompt="承租人名称" readOnly="true"/>
                <!-- <a:textField name="project_name" bindTarget="contract_et_Screen_mainDs2" prompt="案件申请名称" readOnly="true"/> -->
                <a:textField name="contract_status_desc" bindTarget="contract_et_Screen_mainDs2" prompt="合同状态" readOnly="true"/>
                <a:textField name="inception_of_lease" bindTarget="contract_et_Screen_mainDs2" prompt="起租日期" readOnly="true"/>
                <!-- <a:textField name="employee_name" bindTarget="contract_et_Screen_mainDs2" prompt="客户经理" readOnly="true"/> -->
                <!--<a:textField name="overdue_status" bindTarget="contractQueryScreen_mainDs" prompt="是否逾期"/>-->
                <!--<a:comboBox name="et_profile_desc" bindTarget="contractQueryScreen_mainDs" prompt="结清方式"/>-->
                <a:lov name="et_type_desc" bindTarget="contract_et_Screen_mainDs2" prompt="资产处置类型" readOnly="true"/>
                <a:percentField name="et_ratio" bindTarget="contract_et_Screen_mainDs2" prompt="资产处置手续费率" readOnly="true"/>
                <a:datePicker name="termination_date" bindTarget="contract_et_Screen_mainDs2" prompt="资产处置日" readOnly="true" renderer="Leaf.formatDate">
                    <!-- <a:events>
                        <a:event name="change" handler="termination_date_handler"/>
                    </a:events> --><![CDATA[
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                ]]></a:datePicker>
            </a:form>
            <div id="detail_flag_id">
                <a:form title="资产处置信息">
                    <h3 style="color:black; text-align:left;font-weight:bold;font-size:10px;"><![CDATA[资产处置手续费=(逾期租金+逾期罚金+未到期本金+留购金+多退少补金额)*资产处置手续费率]]></h3>
                    <h3 style="color:black; text-align:left;font-weight:bold;font-size:10px;"><![CDATA[资产处置费用=逾期租金+逾期罚金+未到期本金+资产处置手续费+留购金+多退少补金额]]></h3>
                    <a:form column="4" labelWidth="110" marginWidth="38">
                        <a:numberField name="overdue_amount" allowDecimals="true" allowFormat="true" bindTarget="early_terminationDs" decimalPrecision="2" prompt="逾期租金" readOnly="true"/>
                        <a:numberField name="penalty" allowDecimals="true" allowFormat="true" bindTarget="early_terminationDs" decimalPrecision="2" prompt="逾期罚金" readOnly="true"/>
                        <!--<a:numberField name="rentals_payable" allowDecimals="true" allowFormat="true" bindTarget="early_terminationDs" decimalPrecision="2" prompt="应付租金" readOnly="true"/> -->
                        <a:numberField name="undue_principal" allowDecimals="true" allowFormat="true" bindTarget="early_terminationDs" decimalPrecision="2" prompt="未到期本金" readOnly="true"/>
                        <a:numberField name="et_interest" allowDecimals="true" allowFormat="true" bindTarget="early_terminationDs" decimalPrecision="2" prompt="资产处置手续费" readOnly="true"/>
                        <!--<a:numberField name="mgt_fee_after_discount" allowDecimals="true" allowFormat="true" bindTarget="early_terminationDs" decimalPrecision="2" prompt="管理费贴现值"/>-->
                        <a:numberField name="residual_value" allowDecimals="true" allowFormat="true" bindTarget="early_terminationDs" decimalPrecision="2" prompt="留购金" readOnly="true"/>
                        <!--<a:numberField name="ref_n02" allowDecimals="true" allowFormat="true" bindTarget="early_terminationDs" decimalPrecision="2" prompt="其他款项" readOnly="true"/>-->
                        <a:numberField name="et_fee" allowDecimals="true" allowFormat="true" bindTarget="early_terminationDs" decimalPrecision="2" prompt="多退少补金额" readOnly="true"/>
                        <!--<a:numberField name="et_rate" allowDecimals="true" allowFormat="true" bindTarget="early_terminationDs" decimalPrecision="2" prompt="贴现利率" readOnly="true"/>-->
                        <a:numberField name="et_total_amount" allowDecimals="true" allowFormat="true" bindTarget="early_terminationDs" decimalPrecision="2" prompt="资产处置费用合计" readOnly="true"/>
                        <a:numberField name="ref_n05" allowDecimals="true" allowFormat="true" bindTarget="early_terminationDs" decimalPrecision="2" prompt="退还保证金" readOnly="true"/>
                    </a:form>
                    <!-- <h3 style="color:black; text-align:left;font-weight:bold;font-size:14px;"><![CDATA[未到期金额贴现]]></h3> -->
                    <a:tabPanel marginHeight="350" marginWidth="30">
                        <a:tabs>
                            <a:tab prompt="未收金额" width="110">
                                <a:grid bindTarget="unreceivedAmountDs" marginHeight="380" marginWidth="60" navBar="true">
                                    <a:columns>
                                        <a:column name="times" prompt="期数"/>
                                        <a:column name="cf_type_dis" prompt="类型"/>
                                        <a:column name="due_amount" align="right" prompt="应收金额" renderer="Leaf.formatMoney"/>
                                        <a:column name="received_amount" align="right" prompt="已收金额" renderer="Leaf.formatMoney"/>
                                        <a:column name="due_date" prompt="预定支付日期"/>
                                        <a:column name="principal" align="right" prompt="本金" renderer="Leaf.formatMoney"/>
                                        <a:column name="interest" align="right" prompt="利息" renderer="Leaf.formatMoney"/>
                                        <!--<a:column name="termination_date" prompt="结清日"/>-->
                                        <a:column name="cf_status_dis" prompt="现金流状态"/>
                                    </a:columns>
                                </a:grid>
                            </a:tab>
                            <a:tab prompt="已收金额" width="110">
                                <a:grid bindTarget="receivedAmountDs" marginHeight="380" marginWidth="60" navBar="true">
                                    <a:columns>
                                        <a:column name="times" prompt="期数"/>
                                        <a:column name="cf_type_dis" prompt="类型"/>
                                        <a:column name="due_amount" align="right" prompt="应收金额" renderer="Leaf.formatMoney"/>
                                        <a:column name="received_amount" align="right" prompt="未收金额" renderer="Leaf.formatMoney"/>
                                        <a:column name="due_date" prompt="预定支付日期"/>
                                        <a:column name="received_principal" align="right" prompt="已收本金" renderer="Leaf.formatMoney"/>
                                        <a:column name="received_interest" align="right" prompt="已收利息" renderer="Leaf.formatMoney"/>
                                        <!--<a:column name="termination_date" prompt="结清日"/>-->
                                        <a:column name="cf_status_dis" prompt="现金流状态"/>
                                    </a:columns>
                                </a:grid>
                            </a:tab>
                        </a:tabs>
                    </a:tabPanel>
                </a:form>
            </div>
        </a:screenBody>
        <script type="text/javascript"><![CDATA[
            Leaf.onReady(init);
            function init() {
                $('contract_et_Screen_mainDs2').setQueryParameter('et_agreement_id', '${/parameter/@et_agreement_id}');
                $('contract_et_Screen_mainDs2').query();
                $('early_terminationDs').setQueryParameter('et_agreement_id', '${/parameter/@et_agreement_id}');
                $('early_terminationDs').query();
                $('unreceivedAmountDs').setQueryParameter('et_agreement_id', '${/parameter/@et_agreement_id}');
                $('unreceivedAmountDs').query();
                $('receivedAmountDs').setQueryParameter('et_agreement_id', '${/parameter/@et_agreement_id}');
                $('receivedAmountDs').query();
            }
        ]]></script>
    </a:view>
</a:screen>
