<!---- 
    Author 	: Fachri
    Tanggal : 17-04-2015	
    Revisi 	:
-->
<?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">
                    <a href="#" class="easyui-linkbutton" iconCls="icon-document" plain="true" onclick="parent.tab_add('New Inter Bank Transfer','<?=$menu_link?>','icon-add','add')">New</a>
                	<a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-reload" plain="true" onclick="location.reload()">Refresh</a>
                </td>
                <td height="25" align="right" valign="middle">
                    <span class="form-title" style="margin-left:7px;">
                        <?=$menu_label?>
                    </span>
                </td>
            </tr>
            </table>		     	
        </div>			
    </div>
    <!-- End of top view -->
	<!-- center view -->
	<div id="form-body-grey" data-options="region:'center',border:false">
		<div id="form-wrapper" class="easyui-panel"  style="width:1180%;padding:5px;" fit="true">
			<form id="fm_ibank_transfer" name="fm_ibank_transfer" method="post">
	            <input type="hidden" name="currency_code" id="currency_code" readonly="readonly" />
	            <input type="hidden" name="currency_code_to" id="currency_code_to" readonly="readonly" />
	            <input type="hidden" name="branch_trans" id="branch_trans" readonly="readonly" />
	            <table width="100%" height="141" cellpadding="0" cellspacing="0">
	                <tr>
	                    <td width="50%" valign="top">
							<table cellpadding="0" cellspacing="1" width="100%" height="100%" border="0">
								<tr>
									 <td valign="middle" height="24" align="left"><b><label>Transfer From</label></b></td>
									 <td valign="middle" align="left">
									 <select name="cmb_bank_from" editable='true' class="combo-grid" id="cmb_bank_from" required="required" style="width:259px; height:20px;" data-options="
											panelWidth: 259,
											idField: 'AccountNumber',
											textField: 'AccountName',
											url: '<?=base_url().$menu_link; ?>/get_akun_bank_from_add',                   
											columns: [[
												{field:'AccountName',title:'Account Name',width:190},
			                                	{field:'BranchName',title:'Branch Name',width:190}
											]],
											fitColumns: true,
											onSelect: function(rowIndex, rowData){

												get_master_rate(rowData.CurrencyCode);
                                           		get_bank_balance(rowData.AccountNumber,rowData.CurrencyCode); 

												if(rowData.CurrencyCode == 'IDR'){
													$('#currency_code').val(rowData.CurrencyCode);
													
													
													$('#cmb_bank_to').combogrid({
														delay: 300,
														url: '<?= base_url().$menu_link; ?>/get_akun_bank_to_add/<?= $this->session->userdata('company');?>/IDR/'+rowData.CurrencyCode,
														idField: 'AccountNumber',
														textField: 'AccountName',
														columns: [[
															{field:'AccountName',title:'AccountName',width:400,sortable:true},
															{field:'BranchName',title:'Branch Name',width:400,sortable:true}
														]],
														onSelect: function(rowIndex, rowData){
															if(rowData.CurrencyCode == 'IDR'){
																$('#currency_amount').text(rowData.CurrencyCode);
																$('#currency_code_to').val(rowData.CurrencyCode);
																
																$('#from_currency').text('IDR');
																$('#to_currency').text(rowData.CurrencyCode);

																$('#txt_rate').prop('readonly',true);
															}
															else{
																$('#currency_amount').text(rowData.CurrencyCode);
																$('#currency_code_to').val(rowData.CurrencyCode);
																
																$('#from_currency').text(rowData.CurrencyCode);
																$('#to_currency').text('IDR');

																$('#txt_rate').prop('readonly',false);
															}

															$('#branch_trans').val(rowData.BranchName);
															$('#branch_to').html(rowData.BranchName);
														}
													});
												}
												else{
													$('#from_currency').text(rowData.CurrencyCode);
													$('#to_currency').text('IDR');
												
													$('#currency_code').val(rowData.CurrencyCode);
													
													$('#cmb_bank_to').combogrid({
														delay: 300,
														url: '<?= base_url().$menu_link; ?>/get_akun_bank_to_add/<?= $this->session->userdata('company');?>/IDR/'+rowData.CurrencyCode,
														idField: 'AccountNumber',
														textField: 'AccountName',
														columns: [[
															{field:'AccountName',title:'AccountName',width:200,sortable:true},
								                            {field:'BranchName',title:'Branch Name',width:190}
														]],
														onSelect: function(rowIndex, rowData){
															if(rowData.CurrencyCode == 'IDR'){
																$('#currency_amount').text(rowData.CurrencyCode);
																$('#currency_code_to').val(rowData.CurrencyCode);
																$('#txt_rate').prop('readonly',false);
															}
															else{
																$('#currency_amount').text(rowData.CurrencyCode);
																$('#currency_code_to').val(rowData.CurrencyCode);
																$('#txt_rate').prop('readonly',false);
															}

															$('#branch_trans').val(rowData.BranchName);
															$('#branch_to').html(rowData.BranchName);
														}
													});
												}

												$('#branch_from').html(rowData.BranchName);
											}
											">
											</select>	
											<span id="branch_from"></span>
									 </td>
							   </tr>
								<tr>
									<td valign="top" height="24" width="80" align="left">
										<b><label>Transfer To</label></td></b>
									<td valign="top" width="998" align="left">
										<select name="cmb_bank_to" editable='true' class="combo-grid" id="cmb_bank_to" required="required" style="width:259px; height:20px;" data-options="
										panelWidth: 300,
										idField: 'AccountNumber',
										textField: 'AccountName',
										             
										columns: [[
										{field:'AccountName',title:'Account Name',width:190}
			                            
										]],
										fitColumns: true
										">
										</select>	
										<span id="branch_to"></span>
									</td>
								</tr>
								<tr>
									<td valign="top" height="26" align="left">
										<b><label>Rate</label></b>
									</td>
									<td valign="top" align="left">
										<input name="txt_rate" id="txt_rate" editable='false' type="text" class="easyui-numberbox" data-options="min:0.01,precision:2,decimalSeparator:',',groupSeparator:'.',prefix:''" style="width:80px;" required="required" /> <strong>Currency :</strong> <span id="from_currency"></span> <span>TO</span> <span id="to_currency"></span>
								  </td>
								</tr>
								<tr>
		                            <td valign="top" align="left" height="26"><b><?php echo label_grid('check_no');?></b></td>
		                            <td>
		                                <input type="text" name="cheque_number" id="cheque_number" style="width:255px">
		                            </td>
		                        </tr>
								<tr>
									<td valign="top" height="37" align="left">
										<b><label>Memo</label></b>
									</td>
									<td height="37" valign="top" align="left">
										<textarea class="textbox" style="resize:none;" name="txa_memo" id="txa_memo" cols="34" rows="3"></textarea>
									</td>
								</tr>
								<tr>
								  <td valign="middle" height="23" align="left"><b><label>Amount (<span id="currency_amount"></span>)</label></b></td>
								  <td valign="top" align="left">
									<!--<input name="txt_amount_rp" id="txt_amount_rp" type="text" class="easyui-numberbox" data-options="min:0,precision:2,decimalSeparator:',',groupSeparator:'.',prefix:''" style="width:258px;height:18px" required="required" />-->
									<!--<a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-calculator',size:'small'" onClick="">-->
									<input name="txt_amount" id="txt_amount" type="text" class="easyui-numberbox" data-options="min:0.01,precision:2,decimalSeparator:',',groupSeparator:'.',prefix:''" required="required" style="width:255px;text-align:right"/>
								  </td>
								</tr>
								
								<tr>
									<td colspan="2" align="left" valign="top">&nbsp;</td>
								</tr>
							</table>
						</td>
						<td width="50%" valign="top">
	                        <table width="100%" cellpadding="0" cellspacing="1" style="margin-top:4px;">
	                        <tr height="20">
	                            <td rowspan="7" valign="top">&nbsp;</td>
	                            <td width="122">&nbsp;</td>
	                            <td width="190" style="background:#333399;text-align:center;color:#FFF;"><b>Available Balance (<span class='bank_balance_currency'></span>)</b></td>
	                            <td width="122" style="background:#333399;text-align:center;color:#FFF;">Date</td>
	                        </tr>
	                        <tr height="20">
	                        	<td>&nbsp;</td>
	                            <td><input name="txt_bank_balance" id="txt_bank_balance" type="text" class="easyui-numberbox" data-options="precision:2,decimalSeparator:',',groupSeparator:'.',prefix:''" style="text-align:right;width:255px" readonly /></td>
	                            <td><input type="text" name="txt_date" id="txt_date" class="easyui-datebox validBackward" style="width:122px;height:22px" required editable="false" value="<?php echo $date_now;?>"/></td>
	                        </tr>
	                        </table>
                    	</td>
					</tr>
				</table>				  
			</form>
		</div>

	</div>
    <div id="form-footer" data-options="region:'south',border:false">
			<table cellpadding="0" cellspacing="0" width="100%" height="100%" border="0">
				 <tr>
				   <td align="left">
				   </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 save-button" iconCls="icon-save" onclick="save();" <?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>
</div>

<script type="text/javascript">	

var SavePrivillage 	= '<?=$group_user->SavePrivillage;?>';

function save(){
	var total = $("#txt_amount").numberbox('getValue');
	var txt_rate = $('#txt_rate').numberbox('getValue');
	if(total <= 0){
		$.messager.alert('Unseccessfull','Amount tidak boleh kurang dari sama dengan nol','warning');
	}
	else if(txt_rate <= 0){
			$.messager.alert('Unseccessfull','Rate tidak boleh kurang dari sama dengan nol','warning');
		}
	 else {
	   
		save_transaction('<?php echo"$menu_link"; ?>', '#fm_ibank_transfer');
		  
	}
}
</script>