<!---- 
    Author 	: Herpan /  18-08-2014	
    Author 	: Ferry /  03-01-2015	
-->

<div class="easyui-layout" data-options="fit:true,border:false">
    <form id="fm_edit_coa" name="fm_edit_coa" method="post" action="">
	<input type="hidden" name="AccountNumber" id="AccountNumber" value="<?php  echo $detail->AccountNumber ?>"/>

        <!-- 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"></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 Name</b></td>
                        <td>
                            <select class="easyui-combobox td_input" name="cmb_account_sub_type" id="cmb_account_sub_type" style="width:852px;height:20px;" editable="false" required="true" readonly
                                data-options="
                                    valueField:'AccountSubTypeID',
                                    textField:'AccountTypeName',
                                    url:'<?php echo base_url(); ?>custom/get_data/accountsubtype'
                                ">																			
                            </select>						

                            <!--<input type="checkbox" id="chk_suspended" name="chk_suspended" value="3" <?php if($detail->TransStatus==3) echo " checked"?> /> Suspended-->
                        </td>
                    </tr>

                    <tr>
                        <td><b>Sub Account Type Of</b></td>
                        <td>
                            <input type="hidden" name="account_parent_old" value="<?php  echo $detail->AccountParent ?>"/>
                            
                            <select class="easyui-combogrid td_input" name="cmb_account_parent" id="cmb_account_parent"  style="width:852px;height:20px;" required readonly
                                data-options="
                                    panelWidth:987,
                                    value:'<?php echo $detail->AccountParent ?>',
                                    idField:'AccountNumber',
                                    textField:'AccountName',
                                    url:'<?php echo base_url(); ?>list/coa/ajax_parent_branch',
                                    columns:[[
                                            {field:'AccountNumber',title:'Account Number',width:400},
                                            {field:'AccountName',title:'Account Name',width:583}
                                    ]]
                                ">											
                            </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 td_input" style="width:850px;" value="<?php echo $detail->AccountNumber ?>" readonly required />										
                        </td>
                    </tr>

                    <tr><td colspan="2"><hr/></td></tr>

                    <?php if($HaveBranch == 1){ ?>
                        <tr>
                            <td><b>Branch Name</b></td>
                            <td>
                                <select class="easyui-combogrid" name="cmb_branch_code" id="cmb_branch_code" style="width:852px;height:20px;" <?php if($view_type == 1){echo "disabled";}?>
                                    data-options="
                                        value:'<?php echo $detail->BranchCode ?>',
                                        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'}
                                        ]]
                                    " required="true" >
                                </select>
                            </td>									   
                        </tr>
                    <?php } ?>
                    
                    <tr>
                        <td><b>Bank Name</b></td>
                        <td>
                            <span>
                                <select class="easyui-combogrid" name="cmb_bank_id" id="cmb_bank_id" style="width:852px;height:20px;"
                                    data-options="
                                        value:'<?php echo $detail->BankID ?>',
                                        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'},
                                        ]]
                                    " required="true">
                                </select>
                            </span>
                        </td>									   
                    </tr>
						 
                    <tr>
                        <td><b>Account Name</b></td>
                        <td colspan="2">
                            <input type="hidden" name="account_name_old" value="<?php  echo $detail->AccountName ?>"/>
                            <input type="text" name="txt_account_name" id="txt_account_name" class="easyui-validatebox td_input" style="width:850px;"  data-options="required:true" value="<?php echo $detail->AccountName ?>" readonly/>
                        </td>
                    </tr>

<!--                    <tr>
                      <td class="td_label">Currency Name</td>
                      <td>
                        <select class="easyui-combobox td_input" name="cmb_currency_id" id="cmb_currency_id" style="width:987px;height:20px;" editable="false" data-options="valueField:'CurrencyCode',textField:'CurrencyName',url:'<?php echo base_url(); ?>custom/get_data/currency'" required ></select>
                      </td>
                    </tr>								-->					
                </table>
            </div>	

            <div style="width:99.5%;margin-top:5px;text-align:end;">
                <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-ok" <?php if((!in_array($this->session->userdata("jobtitle"), $app2)) || $detail->AppLevel2Status == 1){echo " disabled ";} ?> onclick="custom_data('<?php echo $menu_link?>/approval2','#fm_edit_coa');"> App. Dir</a> 								
                <a href="javascript:void(0)" class="easyui-linkbutton form-button" iconCls="icon-ok" <?php if((!in_array($this->session->userdata("jobtitle"), $app1)) || $detail->AppLevel1Status == 1){echo " disabled ";} ?> onclick="custom_data('<?php echo $menu_link?>/approval1','#fm_edit_coa');"> App. Mgr</a>
                <a href="javascript:void(0)" class="easyui-linkbutton form-button" iconCls="icon-save" <?php if($detail->AppLevel1Status == 1 || $detail->AppLevel2Status == 1){echo " disabled ";} ?> onclick="edit_data();" >Save</a>
                <a href="javascript:void(0)" class="easyui-linkbutton form-button" iconCls="icon-print">Preview & Print</a>   
                <a href="javascript:void(0)" class="easyui-linkbutton form-button" iconCls="icon-cancel">Cancel</a>	
            </div>	
        </div>
        <!-- end center view -->	
    </form>	
</div>

<!--script for coa form-->
<script>
    function edit_data(){
        edit_transaction('<?php echo $menu_link; ?>','#fm_edit_coa');
    }

    function edit_transaction(url,form_id) {
	url = base_url + url;	

        $(form_id).form('submit',{
            url: url + '/update_branch',
            onSubmit: function(){
                return $(this).form('validate');
            },
		
            success: function(result){
                var result = eval('('+result+')');

                if (result.status==true){
                    var edit_url=result.menu_link+"/edit_branch/"+result.number;
                    
                    $.messager.alert('Success',result.message,'info',function(){					
                        location.reload();								
                    });				
                } 
                else {
                    $.messager.show({
                        title: 'Unseccessfull',
                        msg: result.message,
                        showType:'show',
                        style:{
                                right:'',
                                bottom:''
                        }
                    });
                }
            },		
	
            statusCode: {
                404: function() {
                  alert("Page Not Found");
                }
            }
	});
    }

    $(document).ready(function(){
	$('#cmb_account_type').combobox('select',5);
	$('#cmb_account_sub_type').combobox('select','<?php echo $detail->AccountSubTypeID ?>');
	$('#cmb_currency_id').combobox('select','<?php echo $detail->CurrencyCode ?>');	
        form_coa();

        $('#cmb_bank_id').combogrid('grid').datagrid('load', {
           Branch_Code  : '<?php echo $detail->BranchCode ?>',
           Bank_Code    : '<?php echo $detail->BankID ?>'
        });
    });

    $('#cmb_branch_code').combogrid({
       onChange:function(){
           Branch_Code : '';
           $('#cmb_bank_id').combogrid('setValue', '');
           $('#txt_account_name').val('');    
       },

        onSelect:function(rowIndex, rowData){
           $('#cmb_bank_id').combogrid('grid').datagrid('load', {
              Branch_Code   : rowData.BranchCode
           });
       }               
    });

    $('#cmb_bank_id').combogrid({
        onSelect:function(rowIndex, rowData){
            var bank_code = rowData.BankCode;
            var bank_number = rowData.BankNumber;
            
            $('#txt_account_name').val(bank_code + ' (' + bank_number + ')');
        }
    });
</script>