<?xml version="1.0" encoding="UTF-8"?>
<a:screen xmlns:a="http://www.leaf-framework.org/application">
    <a:init-procedure><![CDATA[
	    
	]]></a:init-procedure>
    <a:view>
        <a:link id="csh_transaction_detail_link" url="${/request/@context_path}/modules/csh/CSH533/csh_receipt_write_off.lview"/>
        <a:link id="csh533_send_mail_link" model="csh.CSH531.csh_mail_send" modelaction="execute"/>
        <a:link id="csh533_check_write_off" model="csh.CSH531.csh_mail_send" modelaction="update"/>
        <a:link id="csh_write_off_upload_link" url="${/request/@context_path}/modules/csh/CSH533/csh_write_off_import.lview"/>
        <a:link id="csh_create_receipt_link" url="${/request/@context_path}/modules/csh/CSH533/csh_create_receipt_trx.lview"/>
        <a:link id="csh_calc_write_off_flag_link" model="csh.CSH531.csh_transaction_interface" modelaction="execute"/>
        <script type="text/javascript"><![CDATA[
        	var g_batch_id	=  ${/parameter/@batch_id};
        	
    	    function cshReceiptDetail(value, record, name){
    	        var batch_id = record.get('batch_id');
    	        var trx_interface_id = record.get('trx_interface_id');
    	        var csh_bank_slip_num = record.get('csh_bank_slip_num');
    	        var company_id = record.get('company_id');
    	        var csh_trx_date = Leaf.formatDate(record.get('csh_trx_date'));
    	        var csh_trx_period_name = record.get('csh_trx_period_name');
    	        var csh_trx_period_num = record.get('csh_trx_period_num');
    	        var csh_bp_bank_account_num = record.get('csh_bp_bank_account_num');
                return '<a href="javascript:csh_detail_fun('+batch_id+','+ trx_interface_id +',\''+ csh_bank_slip_num+'\','+company_id+',\''+csh_trx_date+'\',\''+csh_trx_period_name+'\','+csh_trx_period_num+',\'' + csh_bp_bank_account_num + '\')">${l:CSH533.WRITE_OFF_DETAIL}</a>';
    	    }
    	    
    	    function csh_detail_fun(batch_id,trx_interface_id,csh_bank_slip_num,company_id,csh_trx_date,csh_trx_period_name,csh_trx_period_num,csh_bp_bank_account_num){
    	        //
    	        var win =new Leaf.Window({
                    id: 'csh_transaction_detail_window',
                    url: $('csh_transaction_detail_link').getUrl(),
                    params:{batch_id:batch_id,
                    	    trx_interface_id:trx_interface_id,
                    	    batch_status:'${/parameter/@batch_status}',
                    	    csh_bank_slip_num:csh_bank_slip_num,
                    	    company_id:company_id,
                    	    csh_trx_date:csh_trx_date,
                    	    csh_trx_period_name:csh_trx_period_name,
                    	    csh_trx_period_num:csh_trx_period_num,
                    	    csh_bp_bank_account_num:csh_bp_bank_account_num},
                    title: '${l:CSH531.WRITE_OFF_DETAIL}',
                    width: 850,
                    height: 430
                });
                win.on('close',function(){
                    Leaf.request({
                        url:$('csh533_check_write_off').getUrl(),
                        para:{batch_id:g_batch_id},
                        success:function(){},
                        scope:this
                    });
                    $('csh_transaction_interface_ds').query();
                });
    	    }
    	    
    	    function csh_close_window(){
    	        // $('csh_receipt_detail_window').close();
    	        
    	        // if($('csh_receipt_detail_window')){
    	        	// $('csh_receipt_detail_window').close();
    	        // }else{
    	            location.href = $('csh_create_receipt_link').getUrl();
    	        // }
    	    }
    	    
    	    function csh533_receipt_save(){
    	        Leaf.request({
    	            url:$('csh_calc_write_off_flag_link').getUrl(),
    	            para:{batch_id:${/parameter/@batch_id}},
    	            success:function(){
    	            },
    	            scope:this
    	        });
    	        $('csh_transaction_interface_ds').submit();
    	    }
    	    
    	    function send_mail(){
    	        Leaf.request({
    	            url: $('csh533_send_mail_link').getUrl(),
    	            para: {batch_id:'${/parameter/@batch_id}'},
    	            success: function(){
    	                Leaf.showMessage('${l:PROMPT}','发送成功!');
    	            },
    	            scope:this
    	        });
    	    }
    	    
    	    function csh533_send_mail(){
    	        Leaf.showConfirm('${l:PROMPT}','是否将分配结果邮件发送到催款员?',function(){
    	            send_mail();
    	        },function(){});
    	    }
    	    
    	    function do_import(){
    	        new Leaf.Window({
                    id: 'csh_write_off_upload_window',
                    param :{winid :'csh_write_off_upload_window'},
                    url: $('csh_write_off_upload_link').getUrl() + '?batch_id=${/parameter/@batch_id}',
                    title: '${l:HLS.IMPORT}',
                    width: 420,
                    height: 275
                });
    	    }
    	    
    	    function csh533_import_write_off(){
    	        Leaf.showConfirm('${l:PROMPT}','导入分配将覆盖自动分配的数据,是否继续?',function(){
    	            do_import();
    	        },function(){});
    	    }
    	    
    	    function csh533_query(){
    	        $('csh_transaction_interface_ds').query();
    	    }
    	    
    	]]></script>
        <a:dataSets>
            <a:dataSet id="write_off_flag_ds" lookupCode="CSH531_CSH_INTERFACE_WRITE_OFF_FLAG"/>
            <a:dataSet id="lock_flag_ds" lookupCode="CSH531_LOCK_FLAG"/>
            <a:dataSet id="csh_receipt_detail_query" autoCreate="true">
                <a:fields>
                    <a:field name="csh_bank_slip_num"/>
                    <a:field name="csh_bank_account_num"/>
                    <a:field name="csh_trx_date"/>
                    <a:field name="csh_bp_bank_account_num"/>
                    <a:field name="csh_bp_bank_account_name"/>
                    <a:field name="batch_id" defaultValue="${/parameter/@batch_id}"/>
                    <a:field name="csh_description"/>
                </a:fields>
            </a:dataSet>
            <a:dataSet id="csh_transaction_interface_ds" autoPageSize="true" autoQuery="true" model="csh.CSH531.csh_transaction_interface" queryDataSet="csh_receipt_detail_query">
                <a:fields>
                    <a:field name="lock_flag"/>
                    <a:field name="lock_flag_desc" displayField="code_value_name" options="lock_flag_ds" returnField="lock_flag" valueField="code_value"/>
                    <a:field name="write_off_flag"/>
                    <a:field name="write_off_flag_desc" displayField="code_value_name" options="write_off_flag_ds" returnField="write_off_flag" valueField="code_value"/>
                </a:fields>
            </a:dataSet>
        </a:dataSets>
        <a:screenBody>
            <a:screenTopToolbar>
                <a:gridButton click="csh_close_window" text="HLS.RETURN"/>
                <a:gridButton click="csh533_import_write_off" text="CSH531.IMPORT_WRITE_OFF"/>
                <a:gridButton click="csh533_receipt_save" text="HLS.SAVE"/>
                <a:gridButton click="csh533_send_mail" text="邮件发送"/>
                <a:gridButton click="csh533_query" text="HLS.QUERY"/>
            </a:screenTopToolbar>
            <a:form column="2" title="查询条件">
                <a:textField name="csh_description" bindTarget="csh_receipt_detail_query" prompt="合同序号"/>
            </a:form>
            <a:grid bindTarget="csh_transaction_interface_ds" marginHeight="190" marginWidth="30" navBar="true">
                <a:columns>
                    <a:column name="csh_bank_account_num" prompt="CSH531.ACCOUNT_NUM" width="150"/>
                    <a:column name="csh_trx_date" prompt="CSH531.TRX_DATE" renderer="Leaf.formatDate" width="80"/>
                    <a:column name="csh_bp_bank_account_num" prompt="CSH531.BANK_ACCOUNT_NUM" width="150"/>
                    <a:column name="csh_bp_bank_account_name" prompt="CSH531.BANK_ACCOUNT_NAME"/>
                    <a:column name="csh_trx_amount" align="right" editor="csh533_receipt_grid_nf" prompt="CSH531.TRX_AMOUNT" renderer="Leaf.formatMoney"/>
                    <a:column name="csh_currency_code" align="center" prompt="CSH531.CURRENCY_CODE" width="60"/>
                    <a:column name="csh_description" prompt="CSH531.DESCRIPTION" width="200"/>
                    <!--    <a:column name="lock_flag_desc" editor="csh_transfer_grid_cb" prompt="CSH531.LOCK_FLAG" width="80"/>
                    <a:column name="post_flag" align="center" prompt="CSH531.POST_FLAG" width="60"/> -->
                    <a:column name="ebank_success_status" align="center" prompt="CSH5313.EBANK_SUCCESS_STATUS" width="55"/>
                    <a:column name="ebank_result_status_desc" prompt="CSH533.EBANK_RESULT_STATUS" width="55"/>
                    <a:column name="ebank_result_acc_balance" align="right" prompt="CSH533.EBANK_RESULT_ACC_BALANCE" renderer="Leaf.formatMoney"/>
                    <a:column name="ebank_result_success_amt" align="right" prompt="CSH533.EBANK_RESULT_SUCCESS_AMT" renderer="Leaf.formatMoney"/>
                    <a:column name="lock_flag_desc" editor="csh_transfer_grid_cb" prompt="CSH531.LOCK_FLAG" width="60"/>
                    <a:column name="write_off_flag_desc" align="center" prompt="CSH531.WRITE_OFF_FLAG" width="60"/>
                    <a:column align="center" prompt="CSH533.WRITE_OFF_DETAIL" renderer="cshReceiptDetail" width="60"/>
                </a:columns>
                <a:editors>
                    <a:comboBox id="csh_transfer_grid_cb"/>
                    <a:numberField id="csh533_receipt_grid_nf"/>
                </a:editors>
            </a:grid>
        </a:screenBody>
    </a:view>
</a:screen>