<?xml version="1.0" encoding="UTF-8"?>
<!--
    $Author: hp  
    $Date: 2013-9-9 上午11:04:35  
    $Revision: 1.0  
    $Purpose: 
-->
<a:screen xmlns:a="http://www.leaf-framework.org/application">
    <a:init-procedure><![CDATA[
	]]></a:init-procedure>
    <a:view>
        <a:link id="save_invoice_link" model="acp.ACP600.save_acp_invoice" modelaction="update"/>
        <script type="text/javascript"><![CDATA[
            function press_CANCEL() {
            
               }
            
            function acp600_acp_invoice_query() {
                $('acp600_acp_invoice_ln_ds').query();
            }
            
            function acp600_acp_invoice_reset() {
                $('acp600_acp_invoice_hd_ds').reset();
            }
            function acp600_acp_invoice_save() {
            
                var ds = $('acp600_acp_invoice_ln_ds');
                var length = ds.getAll().length;
                var param;
                var record;
                for (var i = 0;i < length;i++) {
                    record = ds.getAt(i);
                    param = {
                        'invoice_hd_id': record.get('invoice_hd_id'),
                        'contract_id': record.get('contract_id'),
                        'project_id': record.get('project_id'),
                        'division': record.get('division'),
                        'bp_id': record.get('bp_id'),
                        'bp_name': record.get('bp_name'),
                        'owner_user_id': record.get('owner_user_id'),
                        'cashflow_id': record.get('cashflow_id'),
                        'cf_item': record.get('cf_item'),
                        'cf_type': record.get('cf_type'),
                        'invoice_number':record.get('invoice_number'),
                        'vat_invoice_code':record.get('vat_invoice_code'),
                        'tax_registry_num':record.get('tax_registry_num'),
                        'bp_tax_registry_num':record.get('bp_tax_registry_num'),
                        'total_amount':record.get('total_amount'),
                        'tax_amount':record.get('tax_amount'),
                        'invoice_date':record.get('invoice_date')
                    };
                    Leaf.request({
                        url: $('save_invoice_link').getUrl(),
                        para: param,
                        success: function success_callback(data) {
            				acp600_acp_invoice_query();
                           },
                        scope: this
                    });
                    Leaf.SideBar.show({
                        msg: '保存成功',
                        duration: 2000
                    });
                }
            }
            
            
            function acp600_acp_invoice_ln_ds_change_fun(dataset, record, name, value, oldvalue) {
                //var param;
                //var project_id;
                //var contract_id;
                //var division;
                //var owner_user_id;
                if (name == 'contract_number') {
                    //var contract_num = record.get('contract_number');
                    record.getMeta().getField('cashflow_des').setLovPara('contract_number',record.get('contract_number'));
                    
                    /* param = {
                     'contract_number': contract_num
                     };
                     Leaf.request({
                     url:'${/request/@context_path}/autocrud/acp.ACP600.get_cont_info/execute',
                     para:param,
                     success:function success_callback(data){
                     var result=data.result;
                     var lovField;
                     project_id=result.project_id;
                     contract_id=result.contract_id;
                     division=result.division;
                     owner_user_id=result.owner_user_id;
                     record.set('project_id',project_id);
                     record.set('contract_id',contract_id);
                     record.set('division',division);
                     record.set('owner_user_id',owner_user_id);
                     },
                     scope:this
                     });	 */
                }
            
            }
            
            function acp600_acp_invoice_add() {
                $('acp600_acp_invoice_ln_ds').create();
            }
            
            function acp_invoice_edit_function(record, name) {
                if (record.isNew) {
                    if(name=='contract_number' || name == 'cashflow_des')
                    {
                        return 'acp_input_invoice_lov_id' ;
                    }
                    if(name=='invoice_number' || name == 'vat_invoice_code' || name == 'tax_registry_num' || name == 'bp_tax_registry_num')
                    {
                        return 'acp_input_invoice_tf_id';
                    }
                    if(name=='total_amount' || name == 'tax_amount')
                    {
                        return 'acp_input_invoice_nf_id';
                    }
                    if(name == 'invoice_date')
                    {
                        return 'acp_input_invoice_dp_id';
                    }
                    return '' ;
                }
                return '' ;
            }

            
        ]]></script>
        <a:dataSets>
            <a:dataSet id="acp600_acp_invoice_hd_ds">
                <a:fields>
                    <a:field name="contract_number" lovGridHeight="320" lovHeight="480" lovService="acp.ACP600.con_contract_for_lov" lovWidth="500" title="合同编号">
                        <mapping>
                            <map from="contract_number" to="contract_number"/>
                            <map from="contract_id" to="contract_id"/>
                        </mapping>
                    </a:field>
                    <a:field name="contract_id"/>
                    <a:field name="invoice_number"/>
                    <a:field name="vat_invoice_code"/>
                    <a:field name="tax_registry_num"/>
                    <a:field name="bp_tax_registry_num"/>
                    <a:field name="invoice_date_from"/>
                    <a:field name="invoice_date_to"/>
                </a:fields>
            </a:dataSet>
            <a:dataSet id="acp600_acp_invoice_ln_ds" autoQuery="true" maxPageSize="15" model="acp.ACP600.acp_invoice_hd" queryDataSet="acp600_acp_invoice_hd_ds" selectable="true">
                <a:fields>
                    <a:field name="contract_number" lovGridHeight="320" lovHeight="480" lovService="acp.ACP600.con_contract_for_lov" lovWidth="500" required="true" title="合同编号">
                        <mapping>
                            <map from="contract_number" to="contract_number"/>
                            <map from="contract_id" to="contract_id"/>
                            <map from="bp_id_agent_level1" to="bp_id"/>
                            <map from="bp_id_agent_level1_n" to="bp_name"/>
                        </mapping>
                    </a:field>
                    <a:field name="cashflow_des" lovGridHeight="320" lovHeight="480" lovService="acp.ACP600.acp_get_cashflow_info" lovWidth="500" required="true" title="现金流项目">
                        <mapping>
                            <map from="cf_item_desc" to="cashflow_des"/>
                            <map from="cashflow_id" to="cashflow_id"/>
                            <map from="billing_amount" to="billing_amount"/>
                            <map from="cf_item" to="cf_item"/>
                            <map from="cf_type" to="cf_type"/>
                        </mapping>
                    </a:field>
                    <a:field name="contract_id"/>
                    <a:field name="invoice_number" required="true"/>
                    <a:field name="vat_invoice_code" required="true"/>
                    <a:field name="tax_registry_num" required="true"/>
                    <a:field name="bp_tax_registry_num" required="true"/>
                    <a:field name="tax_amount" required="true"/>
                    <a:field name="total_amount" required="true"/>
                    <a:field name="invoice_date" required="true"/>
                    <a:field name="invoice_date_from"/>
                    <a:field name="invoice_date_to"/>
                    <a:field name="division"/>
                    <a:field name="project_id"/>
                    <a:field name="contract_id"/>
                    <a:field name="owner_user_id"/>
                    <a:field name="cashflow_id"/>
                    <a:field name="billing_amount"/>
                    <a:field name="cf_item"/>
                    <a:field name="cf_type"/>
                    <a:field name="invoice_hd_id"/>
                </a:fields>
                <a:events>
                    <a:event name="update" handler="acp600_acp_invoice_ln_ds_change_fun"/>
                </a:events>
            </a:dataSet>
        </a:dataSets>
        <a:screenBody>
            <a:screenTopToolbar>
                <a:screenTitle/>
                <!--<a:toolbarButton click="acr100_acp_invoice_export" text="PROMPT.LOADDATA" width="80"/>-->
                <a:toolbarButton click="acp600_acp_invoice_query" text="HLS.QUERY" width="80"/>
                <a:toolbarButton click="acp600_acp_invoice_reset" text="HLS.RESET" width="80"/>
                <a:toolbarButton click="acp600_acp_invoice_add" text="新增" width="80"/>
                <a:toolbarButton click="acp600_acp_invoice_save" text="HLS.SAVE" width="80"/>
            </a:screenTopToolbar>
            <a:form column="4" marginWidth="30" title="查询界面">
                <a:lov name="contract_number" bindTarget="acp600_acp_invoice_hd_ds" prompt="合同号"/>
                <a:textField name="invoice_number" bindTarget="acp600_acp_invoice_hd_ds" prompt="发票号"/>
                <a:textField name="vat_invoice_code" bindTarget="acp600_acp_invoice_hd_ds" prompt="发票代码"/>
                <a:textField name="tax_registry_num" bindTarget="acp600_acp_invoice_hd_ds" prompt="购方识别号"/>
                <a:textField name="bp_tax_registry_num" bindTarget="acp600_acp_invoice_hd_ds" prompt="销方识别号"/>
                <a:datePicker name="invoice_date_from" bindTarget="acp600_acp_invoice_hd_ds" prompt="开票日期从"/>
                <a:datePicker name="invoice_date_to" bindTarget="acp600_acp_invoice_hd_ds" prompt="开票日期到"/>
            </a:form>
            <a:grid id="acr_input_invoice_export_grid" bindTarget="acp600_acp_invoice_ln_ds" height="450" marginWidth="30" maxPageCount="15" navBar="true">
                <a:columns>
                    <a:column name="contract_number" editorFunction="acp_invoice_edit_function" prompt="合同号" width="150"/>
                    <a:column name="cashflow_des" editorFunction="acp_invoice_edit_function" prompt="现金流项目" width="150"/>
                    <a:column name="invoice_number" editorFunction="acp_invoice_edit_function" prompt="发票号码"/>
                    <a:column name="vat_invoice_code" editorFunction="acp_invoice_edit_function" prompt="发票代码" width="150"/>
                    <a:column name="tax_registry_num" editorFunction="acp_invoice_edit_function" prompt="购方识别号" width="150"/>
                    <a:column name="bp_tax_registry_num" editorFunction="acp_invoice_edit_function" prompt="销方识别号" width="150"/>
                    <a:column name="total_amount" align="right" editorFunction="acp_invoice_edit_function" prompt="金额" renderer="Leaf.formatMoney"/>
                    <a:column name="tax_amount" align="right" editorFunction="acp_invoice_edit_function" prompt="税额" renderer="Leaf.formatMoney"/>
                    <a:column name="invoice_date" align="center" editorFunction="acp_invoice_edit_function" prompt="开票日期" renderer="Leaf.formatDate" width="150"/>
                </a:columns>
                <a:editors>
                    <a:lov id="acp_input_invoice_lov_id"/>
                    <a:textField id="acp_input_invoice_tf_id"/>
                    <a:datePicker id="acp_input_invoice_dp_id"/>
                    <a:numberField id="acp_input_invoice_nf_id"/>
                </a:editors>
            </a:grid>
        </a:screenBody>
    </a:view>
</a:screen>