<!---- 
    Author 	: Herpan / Tanggal : 18-08-2014	
    Revisi 	: Ferry / Tanggal : 13-01-2015    
-->

<div class="easyui-layout" data-options="fit:true,border:false">
    <!-- 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">
            <form id="fm_new_coa" name="fm_new_coa" method="post" action="">
            	<table width="100%" border="0" cellspacing="1" cellpadding="1">
                    <tr>
                        <td width="300"><b>Account Type Name</b></td>
                        <td>
                            <select class="easyui-combobox" name="cmb_account_sub_type" id="cmb_account_sub_type" style="width:852px;height:20px;" required="true" editable="false" readonly
                                data-options="
                                    valueField:'AccountSubTypeID',
                                    textField:'AccountTypeName',
                                    url:'<?php echo base_url(); ?>custom/get_data/accountsubtype'
                                ">																			
                            </select>
                        </td>
                    </tr>
                
                    <tr>
                        <td><b>Sub Account Type Of</b></td>
                        <td>
                            <select class="combo-grid" name="cmb_account_parent" id="cmb_account_parent" style="width:852px;height:20px;" required editable="true"
                                data-options="
                                    idField:'AccountNumber',
                                    textField:'AccountName',
                                    url:'<?php echo base_url(); ?>list/coa/ajax_parent_branch',
                                    method: 'post',
                                    fitColumns: true,
                                    columns:[[
                                        {field:'AccountNumber',title:'Account Number',width:200,halign:'center'},
                                        {field:'AccountName',title:'Account Name',width:630,halign:'center'}
                                    ]]
                                ">											
                            </select>
                        </td>
                    </tr>
                
                    <tr>
                        <td><b>Account No.</b></td>
                        <td>
                            <input type="text" name="txt_account_no" id="txt_account_no" class="easyui-validatebox" style="width:850px;" readonly required />
                        </td>
                    </tr>

                    <tr><td colspan="2"><hr/></td></tr>
                    
                    <tr>
                        <td><b>Branch Name</b></td>
                        <td>
                            <select class="combo-grid" name="cmb_branch_code" id="cmb_branch_code" style="width:852px;height:20px;" required="true" editable="true"
                                data-options="
                                    idField:'BranchCode',
                                    textField:'BranchName',
                                    url:'<?php echo base_url(); ?>custom/get_data/branch_by_company',
                                    columns:[[
                                        {field:'BranchCode',title:'Branch Code',width:200,halign:'center'},
                                        {field:'BranchName',title:'Branch Name',width:630,halign:'center'}
                                    ]]
                                ">
                            </select>
                        </td>
                    </tr>
                    
                    <tr>
                        <td><b>Bank Name</b></td>
                        <td>
                            <select class="combo-grid" name="cmb_bank_id" id="cmb_bank_id" style="width:852px;height:20px;" required="true" editable="true"
                                data-options="
                                    panelWidth:852,
                                    idField:'BankID',
                                    textField:'BankName',
                                    url:'<?php echo base_url(); ?>custom/get_data/bank_coa',
                                    columns:[[
                                        {field:'BranchName', title:'Branch Name', width:130, halign:'center'},
                                        {field:'BankCode', title:'Bank Code', width:130, halign:'center'},
                                        {field:'BankName', title:'Bank Name',width:307, halign:'center'},
                                        {field:'CityName', title:'Bank City', width:130, halign:'center'},
                                        {field:'BankNumber', title:'Bank Number',width:130, halign:'center', align:'center'}
                                    ]]
                                ">
                            </select>
                        </td>
                    </tr>
                
                    <tr>
                        <td><b>Account Name</b></td>
                        <td>
                            <input type="text" name="txt_account_name" id="txt_account_name" class="easyui-validatebox" style="width:850px;" data-options="required:true" readonly/>
                        </td>
                    </tr>
                
                    <tr>
                        <td><b>Currency Name</b></td>
                        <td>
                            <select class="easyui-combogrid" name="cmb_currency_id" id="cmb_currency_id" style="width:852px;height:20px;" required editable="false" readonly
                                data-options="
                                    idField:'CurrencyCode', 
                                    textField:'CurrencyName', 
                                    url:'<?php echo base_url(); ?>custom/get_data/currency',
                                    columns:[[
                                        {field:'CurrencyCode',title:'Currency Code',width:200,halign:'center'},
                                        {field:'CurrencyName',title:'Currency Name',width:630,halign:'center'}
                                    ]]
                                ">
                            </select>
                        </td>
                    </tr>
                </table>
            </form>
        </div>
    </div>
    
    <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();">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>
</div>

<script type="text/javascript">
    function insert_data(){
	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_branch',
            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('Gagal',result.message,'warning',function(){					
                        location.reload();							
                    });
                } 
            },
            statusCode: {
                404: function() {
                  alert("Page Not Found");
                }
            }
	});
    }	

    $(document).ready(function(){	
        form_coa();	
	$('#cmb_account_type').combobox('select', 5);
 	$('#cmb_account_sub_type').combobox('select', 7);
 	$('#cmb_account_parent').combobox('select', 7);
    });
    
    $('#cmb_branch_code').combogrid({
        onChange:function(){
            Branch_Code : '';
           
            $('#cmb_bank_id').combogrid('setValue', '');
            $('#txt_account_name').val('');           
            $('#cmb_currency_id').combogrid('setValue', '');
       },
               
       onSelect:function(rowIndex, rowData){
           $('#cmb_bank_id').combogrid('grid').datagrid('load', {
              Branch_Code   : rowData.BranchCode, 
              Bank_Code     : ''
           });
       }
    });
    
    $('#cmb_bank_id').combogrid({
        onSelect:function(rowIndex, rowData){
            var bank_code = rowData.BankCode;
            var bank_number = rowData.BankNumber;

            $('#txt_account_name').val(bank_code);
            $('#cmb_currency_id').combogrid('setValue', rowData.CurrencyCode);
        }
    });    
</script>