<?php
//---------Untuk privellege jika dia ada tombol save----------
	if($group_user->SavePrivillage == 1){
		$cek_autority_save  = "";
	}
	else{
		$cek_autority_save 	= "disabled";
	}
	echo $group_user->SavePrivillage;
//-------------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 Deposit','<?=$menu_link?>','icon-add','add')">New</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 -->
    
    <div id="form-body" data-options="region:'center',border:false">
    	<div id="form-wrapper" class="easyui-panel" style="width:1180%;height:526px;padding:5px;" fit="true">
        	<form id="fm_deposit" name="fm_deposit" 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" />
            	<!-- Form Header -->
                <table width="100%" height="141" cellpadding="0" cellspacing="0">
                <tr>
                    <td width="50%" valign="top">
                    	<table width="100%" cellpadding="0" cellspacing="1" style="margin-top:4px;">
                        <tr height="20">
                        	<td width="120"><b>Deposit From</b></td>
                            <td width="10"><b>:</b></td>
                            <td>
                            	<select name="cmb_bank_from" class="easyui-combogrid" 
                                    id="cmb_bank_from" 
                                    style="width:252px;height:22px;" 
                                    data-options="
                                        panelWidth: 252,
                                        idField: 'AccountNumber',
                                        textField: 'AccountName',
                                        url: '<?php echo base_url(); ?><?php echo"activities/deposit"; ?>/get_petty_cash_add',               
                                        columns: [[
                                        {field:'AccountName',title:'Account Name',width:190}
                                        ]],
                                        fitColumns: true
                                    " required editable="false"
                                >
                                </select>
                            </td>
                        </tr>
                        <tr height="20">
                        	<td width="120"><b>Deposit To</b></td>
                            <td width="10"><b>:</b></td>
                            <td>
                            	<select name="cmb_bank" class="easyui-combogrid" 
                                    id="cmb_bank"  
                                    style="width:252px;height:22px;" 
                                    data-options="
                                        panelWidth: 252,
                                        idField: 'AccountNumber',
                                        textField: 'AccountName',
                                                      
                                        columns: [[
                                        {field:'AccountName',title:'Account Name',width:190}
                                        ]],
                                        fitColumns: true
                                    " required editable="false"
                                >
                                </select>
                            </td>
                        </tr>
                        <tr height="20">
                        	<td width="120" valign="top" style="padding-top:4px;"><b>Description</b></td>
                            <td width="10" valign="top" style="padding-top:4px;"><b>:</b></td>
                            <td>
                            	<textarea class="textbox" name="txa_memo" id="txa_memo" rows="4" style="width:250px;resize:none;white-space:normal;"></textarea>
                            </td>
                        </tr>
                        
                    	<tr height="20">
                        	<td width="120"><b>Rate</b></td>
                            <td width="10"><b>:</b></td>
                            <td>
                            	<input name="txt_rate" id="txt_rate" type="numberbox" class="easyui-numberbox" style="width:110px;" /> <strong>Currency :</strong> <span id="from_currency"></span> <span>TO</span> <span id="to_currency"></span>
                            </td>
                        </tr>
                        <tr height="20">
                        	<td width="120"><b>Amount (<span id="currency_amount"></span>)</b></td>
                            <td width="10"><b>:</b></td>
                            <td>
                                <!--<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,precision:2,decimalSeparator:',',groupSeparator:'.',prefix:''"/>
                            </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;">Deposit No.</td>
                            <td width="122" style="background:#333399;text-align:center;color:#FFF;">Deposit Date</td>
                        </tr>
                        <tr height="20">
                        	<td>&nbsp;</td>
                            <td><input type="text" name="txt_deposit_no" id="txt_deposit_no" class="easyui-validatebox" style="width:190px;height:18px;text-align:center;" required readonly  /></td>
                            <td><input type="text" name="txt_deposit_date" id="txt_deposit_date" class="easyui-datebox validBackward" style="width:122px;height:22px" required editable="false" value="<?php echo $date_now;?>"/></td>
                        </tr>
                        </table>
                    </td>
                </tr>
                </table>
                <!-- End of form header -->
            </form>
    	</div>
        
        <div id="form-footer">
            
		</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" 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-print" onclick="" disabled>Preview & Print</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">	
$(document).ready(function(){
	$('#txt_deposit_no').val('<?php echo $dep_number; ?>');
	$('#txt_deposit_date').datebox({
		onChange:function(){
			url             = base_url + 'activities/deposit/get_dep_number';                
			var Dep_date   = $('#txt_deposit_date').datebox('getValue');
			
			$.post(url, {Dep_date:Dep_date}, function(result){
				if (result.status === true){
					$('#txt_deposit_no').val(result.number);
				} 
			},'json');
		}
	});        
	
	$('#cmb_bank_from').combogrid({
		onSelect: function(rowIndex, rowData){
		   var currency_code = rowData.CurrencyCode;
		   if(rowData.CurrencyCode == 'IDR'){
				
			   $('#currency_code').val(rowData.CurrencyCode);
			   $('#txt_rate').numberbox('setValue', 1);
			   
		   		$('#cmb_bank').combogrid({
					delay: 300,
					url: '<?php echo base_url(); ?><?php echo"activities/deposit"; ?>/get_akun_bank_add/<?php echo  $this->session->userdata('branch');?>/IDR/'+rowData.CurrencyCode,
					idField: 'AccountNumber',
					textField: 'AccountName',
					columns: [[
						{field:'AccountName',title:'AccountName',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);
						}
						else{
							$('#currency_amount').text(rowData.CurrencyCode);
							$('#currency_code_to').val(rowData.CurrencyCode);
							
							$('#from_currency').text(rowData.CurrencyCode);
							$('#to_currency').text('IDR');
						}
					}
				});
		   }
		   else{
			   $('#from_currency').text(rowData.CurrencyCode);
				$('#to_currency').text('IDR');
				$('#txt_rate').numberbox('setValue', 1);
			   $('#currency_code').val(rowData.CurrencyCode);
		   		$('#cmb_bank').combogrid({
					delay: 300,
					url: '<?php echo base_url(); ?><?php echo"activities/deposit"; ?>/get_akun_bank_add/<?php echo  $this->session->userdata('branch');?>/IDR/'+rowData.CurrencyCode,
					idField: 'AccountNumber',
					textField: 'AccountName',
					columns: [[
						{field:'AccountName',title:'AccountName',width:400,sortable:true}
					]],
					onSelect: function(rowIndex, rowData){
						if(rowData.CurrencyCode == 'IDR'){
							$('#currency_amount').text(rowData.CurrencyCode);
							$('#currency_code_to').val(rowData.CurrencyCode);
							//$('#to_currency').text(rowData.CurrencyCode);
							/*$('#txt_rate').prop('readonly', true);
							$('#txt_rate').val(1);*/
						}
						else{
							$('#currency_amount').text(rowData.CurrencyCode);
							$('#currency_code_to').val(rowData.CurrencyCode);
							//$('#to_currency').text(rowData.CurrencyCode);
							/*$('#txt_rate').prop('readonly', false);
							$('#txt_rate').val(0);*/
						}
					}
				});
		   }
		}
	});
	
	function save_data(){
		 
        var total_am = $("#txt_amount").numberbox('getValue');
		var total_rate = $("#txt_rate").numberbox('getValue');
		
		if(total_am < 1){
			$.messager.show({
				title: 'Unseccessfull',
				msg: 'Amount Tidak Boleh Nol',
				style:{
						right:'',
						bottom:''
				}
			});
		}
		else if(total_rate < 1){
			$.messager.show({
				title: 'Unseccessfull',
				msg: 'Rate Tidak Boleh Kosong',
				style:{
						right:'',
						bottom:''
				}
			});
		} else {	
			//$("#fm_deposit").submit();
			$.messager.confirm('Confirm','Pastikan Semua Data Transaksi Sudah Terisi Dengan Benar',function(r){
				if(r){
					save_transaction('<?php echo"$menu_link"; ?>', '#fm_deposit');
				}
			});
	    }
	}
});
</script>