<!---- 
    Author 	: Fachri
    Tanggal : 	
    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="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-reload" plain="true" onclick="location.reload()">Refresh</a>
							<a href="#" class="easyui-linkbutton" iconCls="icon-document" plain="true" onclick="location.reload()">New</a>
						</td>							
						<td height="25" align="right" valign="middle">								
							<span class="form-title"><?=$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_transaksi_antar_kas" name="fm_transaksi_antar_kas" 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="currency_code_from" id="currency_code_to" 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="top" height="24" width="88" align="left">
										<b><label>Transfer From</label></b>
									</td>
									<td valign="top" width="990" align="left">
										<select name="cmb_bank_accountfrom" editable='true' class="combo-grid" id="cmb_bank_accountfrom" style="width:252px;height:22px;"  required="required"
											data-options="
												panelWidth: 252,
												idField: 'AccountNumber',
												textField: 'AccountName',
												url: '<?= base_url().$menu_link; ?>/get_bank_bycompany/<?= $this->session->userdata('branch');?>',
												method: 'get',
												columns: [[
													{field:'AccountNumber',title:'AccountNumber',width:100},
													{field:'AccountName',title:'Account Name',width:190},
													{field:'CurrencyCode',title:'Currency Code',width:80}
												]],
			                                    
												fitColumns: true,
												onSelect: function(rowIndex, rowData){
												   var currency_code = rowData.CurrencyCode;
												   
												   get_master_rate(rowData.CurrencyCode);
                                           		   get_bank_balance(rowData.AccountNumber,rowData.CurrencyCode); 

												   if(rowData.CurrencyCode == 'IDR'){
														//$('#txt_rate').prop('readonly', true);
														$('#currency_code').val(rowData.CurrencyCode);
														
														var currency_array = ['IDR'];
														
														$('#cmb_bank_accountto').combogrid({
															delay: 300,
															url: '<?= base_url().$menu_link; ?>/get_petty_cash_bycompany/<?= $this->session->userdata('branch');?>/IDR/'+rowData.CurrencyCode,
															idField: 'AccountNumber',
															textField: 'AccountName',
															columns: [[
																{field:'AccountNumber',title:'AccountNumber',width:100},
																{field:'AccountName',title:'Account Name',width:190},
																{field:'CurrencyCode',title:'Currency Code',width:80}
															]],
															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);
																}
															}
														});
												   }
												   else{
														$('#from_currency').text(rowData.CurrencyCode);
														$('#to_currency').text('IDR');
														
														$('#currency_code').val(rowData.CurrencyCode);
														
														var currency_array = ['IDR'];
														
														$('#cmb_bank_accountto').combogrid({
															delay: 300,
															url: '<?= base_url().$menu_link; ?>/get_petty_cash_bycompany/<?= $this->session->userdata('branch');?>/IDR/'+rowData.CurrencyCode,
															idField: 'AccountNumber',
															textField: 'AccountName',
															columns: [[
																{field:'AccountNumber',title:'AccountNumber',width:100},
																{field:'AccountName',title:'Account Name',width:190},
																{field:'CurrencyCode',title:'Currency Code',width:80}
															]],
															onSelect: function(rowIndex, rowData){
																if(rowData.CurrencyCode == 'IDR'){
																	$('#currency_amount').text(rowData.CurrencyCode);
																	$('#currency_code_to').val(rowData.CurrencyCode);
																	$('#txt_rate').prop('readonly', false);
																	/*$('#txt_rate').prop('readonly', true);
																	$('#txt_rate').val(1);*/
																}
																else{
																	$('#currency_amount').text(rowData.CurrencyCode);
																	$('#currency_code_to').val(rowData.CurrencyCode);
																	$('#txt_rate').prop('readonly', false);
																	/*$('#txt_rate').prop('readonly', false);
																	$('#txt_rate').val(0);*/
																}
															}
														});
												   }  
												}
											">
										</select>
									</td>
			                        
								</tr>
								<tr>
									<td valign="top" height="24" align="left">
										<b><label>Transfer To</label></b>
									</td>
									<td valign="top" width="990" align="left">
										<select name="cmb_bank_accountto" editable='true' class="combo-grid" id="cmb_bank_accountto" style="width:252px;height:22px" required="required"
										data-options="
										panelWidth: 252,
										idField: 'AccountNumber',
										textField: 'AccountName',
										method: 'get',
										columns: [[
											{field:'AccountNumber',title:'AccountNumber',width:100},
											{field:'AccountName',title:'Account Name',width:190},
											{field:'CurrencyCode',title:'Currency Code',width:80}
										]],
										fitColumns: true
										">
									</select></td>
									
								</tr>
								<tr>
		                            <td valign="top" align="left"><b><?php echo label_grid('check_no');?></b></td>
		                            <td>
		                                <input type="text" name="cheque_number" id="cheque_number" style="width:250px">
		                            </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="33" rows="3"></textarea>
									</td>
								</tr>
								 <tr>
									<td valign="top" height="24" align="left">
										<b><label>Rate</label></b>
									</td>
									<td valign="top" width="990" align="left">
									<input name="txt_rate" id="txt_rate" type="text" class="easyui-numberbox" data-options="min:0.01,precision:2,decimalSeparator:',',groupSeparator:'.',prefix:''" style="width:110px;" /> <strong>Currency :</strong> <span id="from_currency"></span> <span>TO</span> <span id="to_currency">
			                        </td>
								</tr>
								<tr>
								  <td valign="middle" height="35" align="left"><b><label>Amount (<span id="currency_amount"></span>)</label></b></td>
								  <td valign="top" align="left">
									<input name="txt_amount" id="txt_amount" type="text" class="easyui-numberbox" data-options="min:0.01,precision:2,decimalSeparator:',',groupSeparator:'.',prefix:''"  style="width:250px; margin-top:4px;text-align:right;" required="required"
											autoComplete="off"/>
									
								  </td>
								</tr>
								
								<tr>
									<td colspan="2" align="left" valign="top">&nbsp;</td>
								</tr>
							</table>
						</td>
						<td width="50%" valign="top" align="right">
							<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="122" 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:250px" readonly /></td>
		                            <td><input type="text" name="txt_jv_date" id="txt_jv_date" class="easyui-datebox validBackward" style="width:122px;height:22px" editable="false" value="<?php echo $date_now;?>" required="required"/></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>

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

$(document).ready(function(){

    $('#txt_jv_date').datebox({
        onChange:function(){
            url             = base_url + '<?= $menu_link;?>/get_transaksi_number';                
            var Patycash_date   = $('#txt_jv_date').datebox('getValue');
            
            $.post(url, {Patycash_date:Patycash_date}, function(result){
                if (result.status === true){
                    $('#trans_to_petty_cash_no').val(result.number);
                } 
            },'json');
        }
    });        
});
	
	function save(){
		var total_am = $("#txt_amount").numberbox('getValue');
		var txt_rate = $('#txt_rate').numberbox('getValue');
		
		if($('#cmb_bank_accountfrom').combobox('getValue') == $('#cmb_bank_accountto').combobox('getValue')){
			$.messager.alert('Info','Transfer from dan transfer to tidak boleh sama');
			return false;
		}
		else if(total_am <= 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('<?=$menu_link?>','#fm_transaksi_antar_kas');
		}
	}
</script>