<!---- 
Author  : Herpan / Tanggal : 12/08/2014
Revisi  : Ferry / Tanggal : 13/01/2015
Revisi  : Fachri / Tanggal : 27/08/2015
-->
<?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">
    <!-- 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" iconCls="icon-document" plain="true" onclick="parent.tab_add('New Bank','<?=$menu_link?>','icon-add','add');">New</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_bank" name="fm_bank" method="post">
            	<input type="hidden" name="txt_branch_code" id="txt_branch_code" class="easyui-validatebox" />
                <table width="100%" border="0" cellspacing="1" cellpadding="1">
                    <tr>
                        <td width="300px"><b>Branch Name</b></td>
                        <td>
                            <select class="combo-grid" name="cmb_branch_code" id="cmb_branch_code" style="width:852px;height:20px;" required editable="true"
                                data-options="
                                    panelWidth:852,
                                    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>Initial Bank</b></td>
                        <td> 
                            <input type="text" name="txt_initial_bank" id="txt_initial_bank" class="easyui-validatebox" style="width:850px;text-transform:uppercase;" required maxlength="3" onKeyup="initial_bank();"/>
                        </td>
                    </tr>
                    <tr>
                        <td><b>Bank Code</b></td>
                        <td>
                            <input type="text" name="txt_bank_code" id="txt_bank_code" class="easyui-validatebox" required style="width:850px;text-transform:uppercase;" readonly/>										
                        </td>
                    </tr>
                
                    <tr>
                        <td><b>Bank Name</b></td>
                        <td> 
                            <input type="text" name="txt_bank_name" id="txt_bank_name" class="easyui-validatebox" style="width:850px;" data-options="required:true" />
                        </td>
                    </tr>

                    <tr>
                        <td valign="top"><b>Description</b></td>
                        <td>
                            <textarea name="txt_bank_description" id="txt_bank_description" class="easyui-validatebox" style="width:846px" rows="4"></textarea>
                        </td>
                    </tr>
                    
                    <tr>
                        <td><b>Bank Number</b></td>
                        <td>
                            <input type="text" name="txt_bank_number" id="txt_bank_number" class="easyui-validatebox easyui-numberbox" maxlength="4" style="width:852px;" data-options="required:true" onKeyup="initial_bank();"/>
                        </td>
                    </tr>
                    
                    <tr>
                        <td><b>Bank In Code</b></td>
                        <td>
                            <input type="text" name="txt_bank_in_code" id="txt_bank_in_code" class="easyui-validatebox" style="width:850px;text-transform:uppercase;" readonly/>
                        </td>
                    </tr>
                    
                    <tr>
                        <td><b>Bank Out Code</b></td>
                        <td>
                            <input type="text" name="txt_bank_out_code" id="txt_bank_out_code" class="easyui-validatebox" style="width:850px;text-transform:uppercase;" readonly/>
                        </td>
                    </tr>
                    
                    <tr>
                        <td valign="top"><b>Bank Address</b></td>
                        <td>
                            <textarea name="txt_bank_address" id="txt_bank_address" class="easyui-validatebox" data-options="required:true" style="width:846px" rows="4"></textarea>
                        </td>
                    </tr>
                    
                    <tr>
                        <td><b>City/State/Country</b></td>
                        <td>
                            <select name="cmb_city" id="cmb_city" class="combo-grid" style="width:282px;height:20px" required="true" editable="true"
                                data-options="
                                    idField:'CityCode',
                                    textField:'CityName',
                                    url:'<?php echo base_url(); ?>custom/get_data/city',
                                    method: 'get',
                                    columns: [[
                                        {field:'CityCode',title:'City Code',width:100,halign:'center',align:'left'},
                                        {field:'CityName',title:'City Name',width:161,halign:'center',align:'left'}
                                    ]]
                                ">
                            </select>
                            
                            <select name="cmb_state" id="cmb_state" class="easyui-combogrid" style="width:282px;height:20px" required="true" editable="false" readonly
                                data-options="
                                    idField:'StateCode',
                                    textField:'StateName',
                                    url:'<?php echo base_url(); ?>custom/get_data/state',
                                    method: 'get',
                                    columns: [[
                                        {field:'StateCode',title:'State Code',width:100,halign:'center',align:'left'},
                                        {field:'StateName',title:'State Name',width:161,halign:'center',align:'left'}
                                    ]]
                                ">
                            </select>
                            
                            <select name="cmb_country" id="cmb_country" class="easyui-combogrid" style="width:280px;height:20px" required="true" editable="false" readonly
                                data-options="
                                    idField:'CountryCode',
                                    textField:'CountryName',
                                    url:'<?php echo base_url(); ?>custom/get_data/country',
                                    method: 'get',
                                    columns: [[
                                        {field:'CountryCode',title:'Country Code',width:100,halign:'center',align:'left'},
                                        {field:'CountryName',title:'Country Name',width:161,halign:'center',align:'left'}
                                    ]]
                                ">
                            </select>
                        </td>
                    </tr>
                    
                    <tr>
                        <td><b>Currency</b></td>
                        <td>
                            <select name="cmb_currency" id="cmb_currency" class="combo-grid" editable="true" style="width:852px;height:20px;" required="true"
                                data-options="
                                    idField:'CurrencyCode',
                                    textField:'CurrencyName',
                                    url:'<?php echo base_url(); ?>custom/get_data/currency_new',
                                    method:'get',
                                    columns: [[
                                        {field:'CurrencyCode',title:'Code',width:100,halign:'center',align:'left'},
                                        {field:'CurrencyName',title:'Name',width:165,halign:'center',align:'left'},
                                        {field:'CurrencyDesc',title:'Description',width:200,halign:'center',align:'left'},
                                        {field:'CountryName',title:'Country',width:150,halign:'center',align:'center'},
                                        {field:'CurrencyRate',title:'Rate',width:110,halign:'center',align:'right'},
                                        {field:'CurrencySymbol',title:'Symbol',width:100,halign:'center',align:'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>&nbsp;</td>
                <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="save_data('<?php echo $menu_link?>','#fm_bank',1);" <?php echo $cek_autority_save;?>>Save</a>
                    <a href="javascript:void(0)" class="easyui-linkbutton form-button" iconCls="icon-cancel" onclick="$('#fm_bank').form('clear');">Cancel</a>	
                </td>
            </tr>
        </table>
    </div>    
</div>

<script>
    function create_bank_inout_code(){
	var bank_code 		= $('#txt_bank_code').val();
	var bank_name 		= $('#txt_bank_code').val();
	var bank_number 	= $('#txt_bank_number').val();
	var sub_code		= bank_code.substr(0,2);
	var bank_in_code	= bank_code+'M-';
	var bank_out_code	= bank_code+'K-';
        
	$('#txt_bank_in_code').val(bank_in_code);
	$('#txt_bank_out_code').val(bank_out_code);	
    }
	
	function initial_bank(currency, branch_code){
		var bank_initial 	= $('#txt_initial_bank').val();
		var bank_number 	= $('#txt_bank_number').val();
		var cmb_currency 	= $('#cmb_currency').val(currency);
		var txt_branch_code = $('#txt_branch_code').val();
		
		if(branch_code === undefined){branch_code = ""}
		if(currency === undefined){currency = ""}
		
		var set_bank_code 	= txt_branch_code+'/'+bank_initial+'/'+bank_number+'/'+currency;
		var bank_code 		= $('#txt_bank_code').val(set_bank_code);
		
		var set_in_bank_code 	= bank_initial+'/'+bank_number+'/'+currency+'/M';
		var set_out_bank_code 	= bank_initial+'/'+bank_number+'/'+currency+'/K';
		
		var sub_code		= bank_initial.substr(0,2);
		var bank_in_code	= sub_code+'M-'+bank_number;
		var bank_out_code	= sub_code+'K-'+bank_number;
	
		$('#txt_bank_in_code').val(bank_in_code);
		$('#txt_bank_out_code').val(bank_out_code);	
	}
    
    $(document).ready(function(){
	$('#cmb_branch_code').combogrid('setValues', ['<?php echo $branch_code ?>']);
        
		$('#cmb_branch_code').combogrid({
            onSelect:function(rowIndex, rowData){
                $('#txt_branch_code').val('');
				
				initial_bank(rowData.BranchCode);
				$('#txt_branch_code').val(rowData.BranchCode);
            }
        });
		
		$('#cmb_currency').combogrid({
            onSelect:function(rowIndex, rowData){
                initial_bank(rowData.CurrencyCode);
            }
        });
		
        $('#cmb_city').combogrid({
            onSelect:function(rowIndex, rowData){
                $('#cmb_state').combogrid('setValue', rowData.StateCode);
            }
        });

        $('#cmb_state').combogrid({
            onSelect:function(rowIndex, rowData){
                $('#cmb_country').combogrid('setValue', rowData.CountryCode);
            }
        });        
    });
</script>