<!---- 
    Author 	: Wahyu
    Tanggal : 23-10-2014	
    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" valign="middle">							
							<a href="#" class="easyui-linkbutton" iconCls="icon-document" plain="true" onclick="location.reload()" />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">
								<?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="width:1180%;padding:5px;" fit="true">
			<form id="fm_loan_funding" name="fm_loan_funding" method="post" action="">
				<!-- Form Header -->
                <table width="100%" height="141" cellpadding="0" cellspacing="0">
                <tr>
                    <td width="50%" valign="top">
						 <table cellpadding="0" cellspacing="3" width="100%" height="100%" border="0">				   
							<tr>
								<td width="150">
									 <b><label>Loan Account</label></td>
								<td width="10">:</td>
								<td>
									<select editable="true" name="cmb_loan_account" class="combo-grid" id="cmb_loan_account" required="required" style="width:369px;height:20px" data-options="
										panelWidth: 380,
										idField: 'AccountNumber',
										textField: 'AccountName',
										url: '<?= base_url().$menu_link; ?>/get_loan_account',            
										columns: [[
											{field:'AccountNumber',title:'Account Code',width:150,'hidden':true},
											{field:'AccountName',title:'Account Name',width:250},
											{field:'CurrencyCode',title:'Currency Code',width:100}
										]],
										fitColumns: false,
										onSelect:function(IndexRow,rowData){

											$('#currency_code').val(rowData.CurrencyCode);
											$('#from_currency').html(rowData.CurrencyCode);
											$('#amount_currency').html(rowData.CurrencyCode);
											var to_currency = $('#to_currency').html();
											if(to_currency == 'IDR' && rowData.CurrencyCode == 'IDR'){
                                            	$('#txt_rate').numberbox('setValue', 1);
										   		$('#txt_rate').prop('readonly',true);
                                            }else{
                                            	get_master_rate(rowData.CurrencyCode);  
                                            	$('#txt_rate').prop('readonly',false);
                                            }

                                            $('#cmb_receipt_account').combogrid('setValue','');
                                            $('#cmb_receipt_account').combogrid('grid').datagrid('load',{
							            		CurrencyCode:rowData.CurrencyCode
							            	});
										   	
										}
										
										">
									</select>
									
								</td>
							</tr>
							<tr>
								<td width="150"><b><label>Transfer To</label></td>
								<td width="10">:</td>
								<td valign="top" align="left">
									<select editable="true" name="cmb_receipt_account" class="combo-grid" id="cmb_receipt_account" required="required" style="width:369px;height:20px" data-options="
										panelWidth: 380,
										idField: 'AccountNumber',
										textField: 'AccountName',
										url: '<?= base_url().$menu_link; ?>/get_receipt_account',            
										columns: [[
											{field:'AccountNumber',title:'Account Code',width:150,'hidden':true},
											{field:'AccountName',title:'Account Name',width:250},
											{field:'CurrencyCode',title:'Currency Code',width:100}
										]],
										fitColumns: false,
										onSelect: function(rowIndex, rowData){
                                            get_bank_balance(rowData.AccountNumber,rowData.CurrencyCode);

                                            var from_currency = $('#currency_code').val();

                                            if(from_currency == 'IDR' && rowData.CurrencyCode == 'IDR'){
                                            	
										   		$('#txt_rate').prop('readonly',true);
										   		$('#to_currency').html(rowData.CurrencyCode);
                                            }else{
                                            	
                                            	$('#txt_rate').prop('readonly',false);
                                            	$('#to_currency').html('IDR');
                                            }
                                        }
										">
									</select>
								</td>
								
							</tr>
							<tr>
								<td width="150">
									  <b><label>Rate</label>
							    </td>
								<td width="10">:</td>
								<td>
                            		<input name="txt_rate" id="txt_rate" type="numberbox" class="easyui-numberbox" style="width:200px;" data-options=" min:0.01,precision:2,decimalSeparator:',',groupSeparator:'.'" formatter="formatRp" /> <strong>Currency :</strong> <span id="from_currency"></span> <span>TO</span> <span id="to_currency"></span>
                            	</td>
								
							</tr>
							 <tr>
	                            <td width="150"><b><?php echo label_grid('check_no');?></b></td>
	                            <td width="10"><b>:</b></td>
	                            <td>
	                                 <input type="text" name="cheque_number" id="cheque_number" style="width:369px">
	                            </td>
	                        </tr>
							<tr>
								<td width="150">
									  <b><label>Description</label></td>
								<td width="10">:</td>
								<td>
									<textarea class="textbox" style="resize:none;" name="txa_description" id="txa_description" cols="50" rows="3"></textarea></td>
								<td valign="top" align="left">&nbsp;</td>
							</tr>
							<tr>
							  <td width="150"><b><label>Amount (<span id="amount_currency"></span>)</label></b></td>
							  <td width="10">:</td>
							  <td>
								<input name="txt_amount" id="txt_amount" type="numberbox" class="easyui-numberbox" data-options="min:0.01,precision:2,decimalSeparator:',',groupSeparator:'.',prefix:''" style="width:369px;height:20px;text-align:right" required="required" />
								<input type="hidden" name="currency_code" id="currency_code">
								<!--<a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-calculator',size:'small'" onClick="">-->
							  </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="150" 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;">Loan Date</td>
                        </tr>
                        <tr height="20">
                        	<td>&nbsp;</td>
                            <td><input name="txt_bank_balance" id="txt_bank_balance" class="easyui-numberbox" data-options="precision:2,decimalSeparator:',',groupSeparator:'.',prefix:''" style="text-align:right;width:180px;height:20px" readonly /></td>
                            <td><input type="text" name="txt_loan_date" id="txt_loan_date" class="easyui-datebox validBackward" style="width:122px;height:22px" required editable="false" value="<?= $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_data()"; <?php echo $cek_autority_save;?>>Save</a> 
                         <a href="javascript:void(0)" class="easyui-linkbutton form-button" iconCls="icon-cancel" onclick="location.reload()">Cancel</a>	
		
					</td>
				 </tr>
			</table>				
		</div>
</div>

<script type="text/javascript">	

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

function cek_amount(value){
	var total = toAngka(value);
	$("#txt_amount").val(total);
}

function save_data(){
	var total = parseFloat($("#txt_amount").numberbox('getValue'));	
	if(total < 0.01){
		$.messager.alert('Unseccessfull','Transaksi Belum Lengkap','error');
		return false;
	}
	else {
		save_transaction('<?=$menu_link;?>', '#fm_loan_funding','1');
	}
} 
</script>