<?xml version="1.0" encoding="UTF-8"?>
<!--
    $Author: Feng  
    $Date: 2014-5-26 下午6:02:31  
    $Revision: 1.0  
    $Purpose: 
-->
<a:screen xmlns:a="http://www.leaf-framework.org/application" trace="true">
    <a:view>
        <a:link id="acp_invoice_delete_link_id" model="csh.CSH501.acp_invoice_update_query" modelaction="delete"/>
        <a:link id="acp_invoice_reverse_link_id" model="csh.CSH501.acp_invoice_reverse" modelaction="update"/>
        <script type="text/javascript"><![CDATA[
    	function acp512_invoice_close(){
    		$('acp_invoice_modify_window').close();
    	}
    	function acp512_invoice_save(){
    	    if('${/parameter/@invoice_status}' === 'NEW'){
    			$('acp512_invoice_hd_ds').submit();
    	    }else{
    	        Leaf.showErrorMessage('错误','当前发票状态非新建状态不能保存!');
    	    }
    	}
    	function acp512_invoice_delete(){
    	    if('${/parameter/@invoice_status}' === 'NEW'){
	    	    Leaf.showConfirm('提示','您确定删除这张已录入的发票?',function(){
	    	        Leaf.request({
	                	url: $('acp_invoice_delete_link_id').getUrl(),
	                	para: {
	                	    invoice_hd_id:${/parameter/@invoice_hd_id}
	                	},
	                 	success: function(){
	                 	    acp512_invoice_close();
	                 	},
	                	scope: this
	                });
	    	    });
    	    }else{
    	        Leaf.showErrorMessage('错误','当前发票状态非新建状态不能删除!');
    	    }
    	}
    	function acp512_invoice_reverse(){
    	    if('${/parameter/@invoice_status}' === 'CONFIRM'){
	    	    Leaf.showConfirm('提示','您确定删除这张已录入的发票?',function(){
	    	        Leaf.request({
	                	url: $('acp_invoice_reverse_link_id').getUrl(),
	                	para: {
	                	    invoice_hd_id:${/parameter/@invoice_hd_id}
	                	},
	                 	success: function(){
	                 	    acp512_invoice_close();
	                 	},
	                	scope: this
	                });
	    	    });
    	    }else{
    	        Leaf.showErrorMessage('错误','当前发票状态非确认状态不能反冲!');
    	    }
    	}
    ]]></script>
        <a:dataSets>
            <a:dataSet id="acp512_invoice_hd_ds" autoCreate="true" autoQuery="true" model="csh.CSH501.acp_invoice_hd_v" queryUrl="${/request/@context_path}/autocrud/csh.CSH501.acp_invoice_hd_v/query?invoice_hd_id=${/parameter/@invoice_hd_id}">
                <a:fields>
                    <a:field name="invoice_number"/>
                    <a:field name="invoice_date" required="true"/>
                    <a:field name="accounting_date" required="true"/>
                    <a:field name="description"/>
                </a:fields>
            </a:dataSet>
            <a:dataSet id="acp512_invoice_ln_ds" autoQuery="true" fetchAll="true" model="acp.ACP512.acp_invoice_ln" queryUrl="${/request/@context_path}/autocrud/acp.ACP512.acp_invoice_ln/query?invoice_hd_id=${/parameter/@invoice_hd_id}"/>
        </a:dataSets>
        <a:screenBody>
            <a:screenTopToolbar>
                <a:screenTitle/>
                <a:toolbarButton click="acp512_invoice_close" text="HLS.CLOSE"/>
                <a:toolbarButton id="acp512_invoice_save_id" click="acp512_invoice_save" text="HLS.SAVE"/>
                <a:toolbarButton id="acp512_invoice_delete_id" click="acp512_invoice_delete" text="HLS.REMOVE"/>
                <a:toolbarButton id="acp512_invoice_reverse_id" click="acp512_invoice_reverse" text="HLS.REVERSE"/>
            </a:screenTopToolbar>
            <a:form column="4" marginWidth="30" title="应付发票维护">
                <a:textField name="invoice_number" bindTarget="acp512_invoice_hd_ds" prompt="发票号"/>
                <a:datePicker name="invoice_date" bindTarget="acp512_invoice_hd_ds" prompt="发票日期"/>
                <a:datePicker name="accounting_date" bindTarget="acp512_invoice_hd_ds" prompt="记账日期"/>
                <a:textField name="description" bindTarget="acp512_invoice_hd_ds" prompt="备注"/>
                <a:textField name="document_number" bindTarget="acp512_invoice_hd_ds" prompt="单据编号" readOnly="true"/>
                <a:textField name="contract_number" bindTarget="acp512_invoice_hd_ds" prompt="合同编号" readOnly="true"/>
                <a:textField name="contract_name" bindTarget="acp512_invoice_hd_ds" prompt="合同名称" readOnly="true"/>
                <a:textField name="created_by_name" bindTarget="acp512_invoice_hd_ds" prompt="开票人" readOnly="true"/>
                <a:numberField name="total_amount" bindTarget="acp512_invoice_hd_ds" prompt="价税合计" readOnly="true"/>
                <a:numberField name="tax_amount" bindTarget="acp512_invoice_hd_ds" prompt="税额" readOnly="true"/>
                <a:textField name="invoice_status_desc" bindTarget="acp512_invoice_hd_ds" prompt="发票状态" readOnly="true"/>
                <a:textField name="invoice_title" bindTarget="acp512_invoice_hd_ds" prompt="发票抬头" readOnly="true"/>
            </a:form>
            <a:grid id="cashflowDs_grid" bindTarget="acp512_invoice_ln_ds" marginHeight="240" marginWidth="30" navBar="true">
                <a:columns>
                    <a:column name="times" align="right" lock="true" prompt="期数" width="60"/>
                    <a:column name="cf_item_desc" lock="true" prompt="应付项目" width="120"/>
                    <a:column name="due_date" prompt="到期日" renderer="Leaf.formatDate"/>
                    <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="billing_amount" align="right" prompt="总开票金额" renderer="Leaf.formatMoney"/>
                    <a:column name="last_received_date" prompt="付款日期" renderer="Leaf.formatDate"/>
                    <a:column name="total_amount" align="right" prompt="本次开票金额" renderer="Leaf.formatMoney"/>
                    <a:column name="tax_amount" align="right" prompt="本次开票税金" renderer="Leaf.formatMoney"/>
                </a:columns>
            </a:grid>
        </a:screenBody>
        <script type="text/javascript"><![CDATA[
        	function button_init(){
                        if('${/parameter/@invoice_status}' === 'NEW'){
                            $('acp512_invoice_save_id').enable();
                            $('acp512_invoice_delete_id').enable();
                            $('acp512_invoice_reverse_id').disable();
                        }else if('${/parameter/@invoice_status}' === 'CONFIRM'){
                            $('acp512_invoice_save_id').disable();
                            $('acp512_invoice_delete_id').disable();
                            $('acp512_invoice_reverse_id').enable();
                        }else{
                            $('acp512_invoice_save_id').disable();
                            $('acp512_invoice_delete_id').disable();
                            $('acp512_invoice_reverse_id').disable();
                        }
            }
            function view_init(){
                var ds = $('acp512_invoice_hd_ds');
                if('${/parameter/@invoice_status}' === 'NEW'){
                    ds.getField('invoice_number').setReadOnly(false);
                    ds.getField('invoice_date').setReadOnly(false);
                    ds.getField('accounting_date').setReadOnly(false);
                    ds.getField('description').setReadOnly(false);
                }else{
                    ds.getField('invoice_number').setReadOnly(true);
                    ds.getField('invoice_date').setReadOnly(true);
                    ds.getField('accounting_date').setReadOnly(true);
                    ds.getField('description').setReadOnly(true);
                }
            }
            function init() {
            	button_init();
            	view_init();
            }
            
            Leaf.onReady(init);
        ]]></script>
    </a:view>
</a:screen>