<!---- 
    Author 	: Herpan \ Tanggal : 18-08-2014	
    Revisi 	: Ferry \ Tanggal  : 28-12-2012
-->
<?php
//---------Untuk privellege jika dia ada tombol save----------
	if($group_user->SavePrivillage == 1){
		$cek_autority_save  = "";
	}
	else{
		$cek_autority_save 	= "disabled";
	}
//-------------end----------------------------
?>
<div class="easyui-layout" data-options="fit:true,border:false">
    <form id="fm_new_coa" name="fm_new_coa" method="post" action="">
	<input type="hidden" name="chk_company" id="chk_company"/>
		
        <!-- top view-->
        <div id="form-header" data-options="region:'north',border:false" >	
            <div id="form-header-wrapper">
            
                <table cellpadding="0" cellspacing="0" width="100%" height="100%" border="0">
                    <tr>
                        <td align="left" valign="middle"><a href="#" class="easyui-linkbutton" data-options="plain:true,iconCls:'icon-reload'" onclick="location.reload();">Refresh</a></td>							
                        <td height="25" align="right" valign="middle">								
                            <span class="form-title">
                                <?php echo $menu_label; ?>
                            </span>
                        </td>
                    </tr>
                </table>		     	
            </div>			
        </div>
        <!-- end top view -->
	
        <!-- center view -->
        <div id="form-body-grey" data-options="region:'center',border:false">
            <div id="form-wrapper" class="easyui-panel" style="padding:10px;" fit="true">
                <table>
                    <tr>
                        <td width="300"><b>Account Type</b></td>
                        <td>
                            <select class="" name="cmb_account_sub_type" id="cmb_account_sub_type" style="width:852px;height:22px;" required editable="true"
                                data-options="
                                    panelWidth:852,
                                    idField: 'AccountSubTypeID',
                                    textField: 'AccountTypeName',
                                    url: '<?=base_url()?>list/coa/ajax_account_subtype',
                                    method: 'get',
                                    columns: [[
                                        {field:'AccountTypeName',title:'Account Type Name',width:832,halign:'center'}
                                    ]],
                                    fitColumns: true
                                ">
                            </select>
                        </td>
                    </tr>

                    <tr style="height:30px">
                        <td><b>Sub Account of</b></td>
                        
                        <td>
                            <div id="cmb_sub_account_wrapper" >                                
                                <select class="combo-grid" name="cmb_account_parent" id="cmb_account_parent" style="width:852px;height:22px;" required editable="true"
                                    data-options="
                                        panelWidth:852,
                                        idField: 'AccountNumber',
                                        textField: 'AccountName',
                                        url: '<?=base_url()?>list/coa/account_gl_for_new/',
                                        method: 'get',
                                        columns: [[
                                            {field:'AccountNumber',title:'Account Number',width:200,halign:'center'},
                                            {field:'AccountName',title:'Account Name',width:630,halign:'center'}
                                        ]],
                                        fitColumns: true
                                    ">
                                </select>
                             </div>
                        </td>
                    </tr>     
                    
                    <tr>
                        <td><b>Account No.</b></td>
                        <td>
                            <input type="text" name="txt_account_no" id="txt_account_no" class="easyui-validatebox td_input" style="width:850px;" readonly value="<?php echo $AccountNumber ?>" />										
                        </td>
                    </tr>

                    <tr>
                        <td><b>Account Name</b></td>
                        <td colspan="2"><input type="text" name="txt_account_name" class="easyui-validatebox td_input" style="width:850px;" data-options="required:true" /></td>
                    </tr>

                    <tr>
                        <td><b>Currency Name</b></td>
                        <td>
                            <select class="combo-grid td_input" name="cbg_currency" id="cbg_currency" style="width:852px;height:20px;" editable="true" required 
                                data-options = "
                                    idField:'CurrencyCode',
                                    textField:'CurrencyName',
                                    url:'<?php echo base_url(); ?>custom/get_data/currency_new',
                                    columns:[[
                                        {field:'CurrencyCode',title:'Currency Code',width:200,halign:'center'},
                                        {field:'CurrencyName',title:'Currency Name',width:630,halign:'center'},
                                    ]]
                                ">                                
                            </select>
                        </td>
                    </tr>

                    <tr>
                        <td valign="top" style="padding-top:4px"><b>Company Name</b></td>
                        <td>
                            <table id="dtg_company" idField="CompanyCode" class="easyui-datagrid" style="width:852px" required
                                url="<?php echo base_url()?>custom/get_data/company_branch"
                                data-options="singleSelect:true"
                                >

                                <thead>
                                    <tr>
                                        <th field="ck" checkbox="true"></th>
                                        <th width="150" align="left" halign="center" field="CompanyCode">Company Code</th>
                                        <th width="150" align="left" halign="center" field="BranchCode">Branch Code</th>
                                        <th width="500" align="left" halign="center" field="CompanyName">Company Name</th>                                            										
                                    </tr>
                                </thead>
                            </table>
                        </td>
                    </tr>
                </table>
            </div>	
        </div>
        <!-- end center view -->
        
        <div id="form-footer" data-options="region:'south',border:false">
            <table width="100%" cellpadding="0" cellspacing="0">
                <tr>
                    <td align="right">
                        <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-help" onclick="" plain="true">Help</a>
                        <a href="javascript:void(0)" class="easyui-linkbutton form-button" iconCls="icon-save" onclick="insert_data();" <?php echo $cek_autority_save;?>>Save</a> 								
                        <a href="javascript:void(0)" class="easyui-linkbutton form-button" iconCls="icon-cancel" onclick="parent.tab_close('tt')">Cancel</a>	
                    </td>
                </tr>
            </table>
        </div>
    </form>	
</div>

<!--script for coa form-->
<script>
var SavePrivillage 	= '<?php echo $group_user->SavePrivillage;?>';
    $(document).ready(function(){
        $('#cmb_account_sub_type').combogrid({
            onSelect:function(rowIndex, rowData){
				$('#cmb_account_parent').combogrid('setValue', '');
				
				/*========================cek jika auto number======================*/
				$('#cbg_currency').combogrid({
					url:'<?php echo base_url(); ?>custom/get_data/currency_new/'+rowData.AccountAutoStatus,
					idField:'CurrencyCode',
					textField:'CurrencyName',
					columns:[[
						{field:'CurrencyCode',title:'Currency Code',width:200,halign:'center'},
						{field:'CurrencyName',title:'Currency Name',width:630,halign:'center'},
					]]
				});
				/*=========================end=======================================*/
				
                $('#cmb_account_parent').combogrid('grid').datagrid('load',{
                    AccountParentID : rowData.AccountSubTypeID
                });
            }
        });
	form_coa();	
		
    });
    
    function insert_data(){
        var company         = $('#dtg_company').datagrid('getChecked');
        var checked_company = JSON.stringify(company);

        $("#chk_company").val(checked_company);
	
        save_transaction('<?php echo $menu_link; ?>','#fm_new_coa');
    }
    
    function save_transaction(url, form_id) {
	url = base_url + url;

        $(form_id).form('submit',{
            url: url + '/insert',
            onSubmit: function(){
                return $(this).form('validate');
            },
            success: function(result){
                var result = eval('('+result+')');
                
                if (result.status==true){
                    $.messager.alert('Success',result.message,'info',function(){					
                        location.reload();							
                    });			   			
                } 
                else {
                    $.messager.alert('Error',result.message,'error',function(){					
                        //location.reload();							
                    });
                } 
            },
	
            statusCode: {
                404: function() {
                  alert("Page Not Found");
                }
            }
	});
    }	
</script>