<?xml version="1.0" encoding="UTF-8"?>
<!--
    $Author: zhangxing5129  
    $Date: 2013-12-20 下午03:30:10  
    $Revision: 1.0  
    $Purpose: 
-->
<a:screen xmlns:a="http://www.leaf-framework.org/application" customizationEnabled="true" trace="true">
    <a:init-procedure>
        <a:model-query fetchAll="true" model="basic.hls_sys_time_default_value" rootPath="sysdate_rp"/>
    </a:init-procedure>
    <a:view>
        <a:link id="penatly_link" url="${/request/@context_path}/modules/cont/CON747/con_contract_penatly_submit.lsc"/>
        <script type="text/javascript"><![CDATA[
            function req_detail_close() {
                $('con_contract_penatly_change_req_detail_id').close();
            }
            
            function req_detail_approve() {
                Leaf.showConfirm('${l:HLS.PROMPT}', '${l:HLS.ARE_YOU_SURE_TO_SUBMIT}', req_detail_approve_confirm, function() {
                    return;
                });
            }
            
            function req_detail_approve_confirm() {
                var line_selected_records = $('con_change_req_line_ds').getSelected();
                if (line_selected_records.length == 0) {
                    Leaf.showMessage('${HLS.PROMPTS}', '${l:CON747.CHOOSE_CHANGE_RECORD_MSG}');
                    return;
                }
                for (i = 0;i < line_selected_records.length;i++) {
                    if (!Ext.isEmpty(line_selected_records[0].get('change_penalty_amount')) || line_selected_records[0].get('change_penalty_amount') === 0) {
                        var ds = $('con_contract_penatly_change_req_detail_header_ds');
                        var datas = ds.getJsonData(false);
                        Leaf.Masker.mask($('con_contract_penatly_change_req_detail_id').wrap, '${HLS.EXECUTING}');
                        Leaf.request({
                            url: $('penatly_link').getUrl(),
                            para: datas,
                            success: function() {
                                Leaf.Masker.unmask($('con_contract_penatly_change_req_detail_id').wrap);
                                $('con_change_req_line_ds').query();
                                Leaf.showMessage('${l:HLS.PROMPT}', '${l:CON747.SUBMIT_SUCCESS}');
                            },
                            failure: function() {
                                Leaf.Masker.unmask($('con_contract_penatly_change_req_detail_id').wrap);
                            },
                            error: function() {
                                Leaf.Masker.unmask($('con_contract_penatly_change_req_detail_id').wrap);
                            }
            
                        });
                    } else {
                        Leaf.showMessage('${HLS.PROMPTS}', '${l:CON747.ENTER_CHANGE_AMOUNT_MSG}');
                        return;
                    }
                }
            
            }
            
            function on_change_req_line_query(ds, qpara) {
                var bp_id = '${/parameter/@bp_id}';
                if (bp_id) {
                    qpara['bp_id'] = bp_id;
                }
            }
            
            function con_change_req_line_ds_update(ds, record, name, value, oldvalue) {
                if (name == 'change_penalty_amount') {
                    if (!Ext.isEmpty(value) || value === 0) {
                        if (value - record.get('due_amount') > 0) {
                            Leaf.showConfirm('${l:HLS.PROMPT}', '${l:CON747.CONFIRM_CHANGE_MSG}', function() {
                                $('con_change_req_line_ds').select(record);
                                return;
                            }, function() {
                                record.set('change_penalty_amount', '');
                                $('con_change_req_line_ds').unSelect(record);
                                return;
                            });
                        } else {
                            $('con_change_req_line_ds').select(record);
                        }
                    } else {
                        $('con_change_req_line_ds').unSelect(record);
                    }
                }
            }
        ]]></script>
        <a:dataSets>
            <a:dataSet id="con_contract_penatly_change_req_detail_header_ds" autoCreate="true" submitUrl="${/request/@context_path}/modules/cont/CON747/con_contract_penatly_submit.lsc">
                <a:fields>
                    <a:field name="bp_id" defaultValue="${/parameter/@bp_id}"/>
                    <a:field name="bp_code" defaultValue="${/parameter/@bp_code}"/>
                    <a:field name="bp_name" defaultValue="${/parameter/@bp_name}"/>
                    <a:field name="con_req_number"/>
                    <a:field name="project_id" defaultValue="${/parameter/@project_id}"/>
                    <a:field name="project_number" defaultValue="${/parameter/@project_number}"/>
                    <a:field name="project_name" defaultValue="${/parameter/@project_name}"/>
                    <a:field name="contract_id" defaultValue="${/parameter/@contract_id}"/>
                    <a:field name="last_calc_date" defaultValue="${/model/sysdate_rp/record/@now_time}" required="true"/>
                    <a:field name="change_reason"/>
                </a:fields>
            </a:dataSet>
            <a:dataSet id="con_change_req_line_ds" autoQuery="true" bindName="line_result" bindTarget="con_contract_penatly_change_req_detail_header_ds" fetchAll="true" model="cont.CON747.con_contract_penatly_change_req_detail_line" queryDataSet="con_contract_penatly_change_req_header_ds" selectable="true">
                <a:fields>
                    <a:field name="cashflow_id"/>
                    <a:field name="change_penalty_amount"/>
                </a:fields>
                <a:events>
                    <a:event name="update" handler="con_change_req_line_ds_update"/>
                </a:events>
            </a:dataSet>
        </a:dataSets>
        <a:screenBody>
            <a:screenTopToolbar>
                <a:gridButton click="req_detail_close" text="HLS.BACK"/>
                <a:gridButton click="req_detail_approve" text="HLS.SUBMIT"/>
            </a:screenTopToolbar>
            <a:form column="1" title="CON747.PENALTY_CHANGE_REQ">
                <a:box column="3" labelWidth="100">
                    <a:textField name="bp_code" bindTarget="con_contract_penatly_change_req_detail_header_ds" prompt="CON305.BP_ID_TENANT" readOnly="true" width="150"/>
                    <a:textField name="bp_name" bindTarget="con_contract_penatly_change_req_detail_header_ds" prompt="HLS.TENANT_NAME" readOnly="true" width="150"/>
                    <a:textField name="con_req_number" bindTarget="con_contract_penatly_change_req_detail_header_ds" prompt="CON747.CON_REQ_NUMBER" readOnly="true" width="150"/>
                    <a:textField name="project_number" bindTarget="con_contract_penatly_change_req_detail_header_ds" prompt="HLS.PROJECT_NUMBER" readOnly="true" width="150"/>
                    <a:textField name="project_name" bindTarget="con_contract_penatly_change_req_detail_header_ds" prompt="HLS.PROJECT_NAME" readOnly="true" width="150"/>
                    <a:datePicker name="last_calc_date" bindTarget="con_contract_penatly_change_req_detail_header_ds" prompt="CON747.LAST_CALC_DATE" readOnly="true" width="150"/>
                </a:box>
                <a:box column="3" labelWidth="100">
                    <a:textArea name="change_reason" bindTarget="con_contract_penatly_change_req_detail_header_ds" colspan="3" prompt="CON747.CHANGE_REASON" width="666"/>
                </a:box>
            </a:form>
            <a:grid bindTarget="con_change_req_line_ds" marginHeight="270" marginWidth="30" navBar="true">
                <a:columns>
                    <a:column name="contract_number" prompt="HLS.CONTRACT_NUMBER" width="150"/>
                    <a:column name="contract_name" prompt="HLS.CONTRACT_NAME" width="200"/>
                    <a:column name="times" prompt="HLS.TIMES" width="50"/>
                    <a:column name="cf_item_desc" prompt="HLS.CF_ITEM_DESC" width="80"/>
                    <a:column name="rental_amount" align="right" prompt="CON305.ACC_AMOUNT" renderer="Leaf.formatMoney" width="100"/>
                    <a:column name="due_date" prompt="HLS.DUE_DATE" renderer="Leaf.formatDate" width="100"/>
                    <a:column name="overdue_max_days" align="right" prompt="CON747.OVERDUE_MAX_DAYS" width="100"/>
                    <a:column name="due_amount" align="right" prompt="CON747.DUE_AMOUNT" renderer="Leaf.formatMoney" width="100"/>
                    <a:column name="received_amount" align="right" prompt="CON747.RECEIVED_AMOUNT" renderer="Leaf.formatMoney" width="100"/>
                    <a:column name="unreceived_amount" align="right" prompt="CON747.UNRECEIVED_AMOUNT" renderer="Leaf.formatMoney" width="100"/>
                    <a:column name="change_penalty_amount" align="right" editor="line_nf" prompt="CON747.CHANGE_PENALTY_AMOUNT" renderer="Leaf.formatMoney" width="100"/>
                </a:columns>
                <a:editors>
                    <a:numberField id="line_nf" allowDecimals="true" allowFormat="true" allowNegative="false"/>
                </a:editors>
            </a:grid>
        </a:screenBody>
    </a:view>
</a:screen>
