<!---- 
    Author 	: Fachri
    Tanggal : 17-04-2015	
    Revisi 	:
-->
<?php
//---------Untuk privellege jika dia ada tombol save,suspen,jurnal----------
	if($group_user->SavePrivillage == 1){
		$cek_autority_save  = "";
	}
	else{
		$cek_autority_save 	= "disabled";
	}
	
	if($group_user->JournalPrivillage == 1){
		$cek_autority_journal  = "";
	}
	else{
		$cek_autority_journal 	= "disabled";
	}
	
	if($group_user->DeletePrivillage == 1){
		$cek_autority_delete  = "";
	}
	else{
		$cek_autority_delete 	= "disabled";
	}

	 if($group_user->ReversePrivillage == 1){
        $cek_autority_reverse  = "";
    }
    else{
        $cek_autority_reverse    = "display:none";
    }
//-------------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">
							<input type="checkbox" class="easyui-checkbox" name="chk_suspended" id="chk_suspended" style="margin-top:0px;margin-right:1px;" onclick="suspend_transaction(1,'<?= $menu_link;?>',$('#txt_ibank_no').val(),'<?=$menu_label;?>')" <?=(!in_array($detail->TransStatus,array(5,6))) ? 'disabled' : ''?> <?=(in_array($detail->TransStatus,array(3,9))) ? 'checked' : ''?>  <?php echo $cek_autority_delete;?>/>
                            <span style="display:inline-block;margin-top:2px;<?=(($detail->TransStatus==3)?'color:gray;':'color:black')?>">Suspend</span>
							<a href="#" class="easyui-linkbutton" iconCls="icon-journal" plain="true" onclick="to_journal()" id="to_journal" <?= $cek_autority_journal;?>>Journal</a>
							<a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-reload" plain="true" onclick="location.reload()">Refresh</a>
							
						</td>
						<td align="center" width="40%"><span id="approval_information">
		                <?php
		                if($detail->TransStatus == 5){
		                    echo get_status_approval_header($detail->TransStatus);
		                }
		                ?>						
						<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">
    <?php if($detail->TransStatus==2){ ?>
        <div class="blanket"></div>
        <div class="paid-box"><b>Paid</b></div>
    <?php }else if($detail->TransStatus==3){ ?>
    	 <div class="blanket"></div>
         <div class="suspend-box"><b>Suspended</b></div>
	<?php
	}
	?>
		<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" value="<?= $detail->CurrencyCode;?>"/>
	            <input type="hidden" name="currency_code_to" id="currency_code_to" value="<?= $detail->CurrencyCode_to;?>"/>
	            <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,
			                                value:'<?= $detail->BankTransfer; ?>', 
											idField: 'AccountNumber',
											textField: 'AccountName',
											url: '<?= base_url().$menu_link; ?>/get_akun_bank_from_edit/<?= $detail->BranchCode; ?>',                   
											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);
													
													$('.app-button').linkbutton('disable');

													//taro function clear data row ke 2
													$('#cmb_bank_to').combogrid({
														delay: 300,
														value:'', 
														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:'Account Name',width:200,sortable:true},
															{field:'BranchName',title:'Branch Name',width:200,sortable:true}
														]],
														onSelect: function(rowIndex, rowData){
															$('#cmb_bank_accountto').combogrid('readonly', false);
															$('.app-button').linkbutton('disable');
															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{
																$('#from_currency').text(rowData.CurrencyCode);
																$('#to_currency').text('IDR');
																$('#currency_amount').text(rowData.CurrencyCode);
																$('#txt_rate').prop('readonly',false);
																
															}

															$('#branch_to').html(rowData.BranchName);
														}
													});
												}
												else{
													$('#from_currency').text(rowData.CurrencyCode);
													$('#to_currency').text('IDR');
													$('#currency_code').val(rowData.CurrencyCode);
													
													$('.app-button').linkbutton('disable');
													//taro function clear data row ke 2
													
													$('#cmb_bank_to').combogrid({
														delay: 300,
														value:'', 
														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:'Account Name',width:200,sortable:true},
															{field:'BranchName',title:'Branch Name',width:200,sortable:true}
														]],
														onSelect: function(rowIndex, rowData){
															$('#cmb_bank_accountto').combogrid('readonly', false);
															$('.app-button').linkbutton('disable');
															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_to').html(rowData.BranchName);
														}
													});
												}

												$('#branch_from').html(rowData.BranchName);
											}
											">
											</select>
											<span id="branch_from"><?=$detail->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="
										value:'<?= $detail->BankReceipt; ?>', 
			                            panelWidth: 300,
										idField: 'AccountNumber',
										textField: 'AccountName',
										url: '<?= base_url().$menu_link; ?>/get_akun_bank_to_add/<?= $company_code;?>/IDR/<?= $detail->CurrencyCode;?>',             
										columns: [[
										{field:'AccountName',title:'Account Name',width:190}
										]],
										fitColumns: true
										">
										</select>
										<span id="branch_to"><?=$detail->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" style="width:80px;" data-options="min:0.01,precision:2,decimalSeparator:',',groupSeparator:'.',prefix:''" required="required" value="<?= $detail->CurrencyRate;?>" /> <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" value="<?=$detail->ChequeNumber;?>" <?=in_array($detail->TransStatus, array(1,2,3,9))?'disabled':'';?>>
		                            </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"><?= $detail->IBankDesc;?></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" onkeyup="cek_amount(this.value)" class="easyui-numberbox" data-options="min:0.01,precision:2,decimalSeparator:',',groupSeparator:'.',prefix:''" style="width:258px;text-align:right;" value="<?= $detail->IBankAmount;?>" required="required" autocomplete="off" />
									<!--<a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-calculator',size:'small'" onClick="">-->
									<input name="txt_amount" id="txt_amount" type="hidden" value="<?= $detail->IBankAmount;?>"/>
								  </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;">InterBank Transfer 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_ibank_no" id="txt_ibank_no" class="easyui-validatebox" value="<?= $detail->IBankNumber; ?>" style="width:190px;height:18px;text-align:center;" required readonly  /></td>
	                            <td><input type="text" name="txt_date" id="txt_date" class="easyui-datebox" style="width:122px;height:22px" required editable="false" value="<?= $detail->IBankDate; ?>" readonly/></td>
	                        </tr>
	                        </table>
	                        <table width="100%" cellpadding="0" cellspacing="1" style="margin-top:0px;">
	                        <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>
	                        </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:315px" readonly /></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 app-button" iconCls="icon-ok" <?= (($this->session->userdata("jobtitle_status") != 0 || !in_array($detail->TransStatus, array(5,6))) || (date('Y-m-d') < date('Y-m-d', strtotime($detail->IBankDate))))?'disabled':'' ?> onclick="app_dir()"> App. Dir</a>
                         <a href="javascript:void(0)" class="easyui-linkbutton form-button app-button" iconCls="icon-reload" onclick="app_reverse()" <?=(in_array($detail->TransStatus,array(1,2,9)))?'':'disabled'?> style="<?= $cek_autority_reverse;?>" >Reverse</a>
                         <a href="javascript:void(0)" class="easyui-linkbutton form-button save-button" iconCls="icon-save" onclick="save();" <?=(in_array($detail->TransStatus,array(0,1,2,3)))?'disabled':''?><?php echo $cek_autority_save;?>>Save</a> 								
                         <a href="javascript:void(0)" class="easyui-linkbutton form-button" iconCls="icon-print" onclick="parent.tab_edit('Print IBank Transfer', '<?=$menu_link?>', 'icon-print', 'to_print_detail','<?php echo $detail->IBankNumber;?>');" <?=(in_array($detail->TransStatus,array(4,5,6,1,2,3,9)))?'':'disabled'?>>Preview & Print</a>  
                         <a href="javascript:void(0)" class="easyui-linkbutton form-button" iconCls="icon-cancel" onclick="<?=($this->session->userdata('jobtitle_status')==0)?'suspend(2)':'parent.tab_close(\'tt\')'?>" <?=(!in_array($detail->TransStatus,array(0,5,6)))?'disabled':''?>><?=($this->session->userdata('jobtitle_status')==0)?'Cancel':'Close'?></a>
					</td>
				 </tr>
			</table>				
		</div>
</div>

<script type="text/javascript">	

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

$(document).ready(function(){
        
	$('#cmb_bank_to').combogrid('readonly', true);
	var from_currency = $('#currency_code').val();
	$('#currency_amount').text('<?php echo $detail->CurrencyCode_to;?>');
	var to_currency = $('#currency_code_to').val();
	//$('#cmb_bank_accountto').combogrid('readonly', true);
	
	if(from_currency == 'IDR' && to_currency == "IDR"){
		$('#from_currency').text('IDR');
		$('#to_currency').text('<?php echo $detail->CurrencyCode_to;?>');
		$("#txt_rate").prop('readonly',true);
	}
	else{
		if(to_currency != "IDR"){
			$('#from_currency').text('<?php echo $detail->CurrencyCode_to;?>');
			$('#to_currency').text('IDR');
		}
		else{
			$('#from_currency').text('<?php echo $detail->CurrencyCode;?>');
			$('#to_currency').text('IDR');
		}
	}

	var bank_payment = '<?= $detail->BankTransfer; ?>';
    
    get_bank_balance(bank_payment,from_currency);

}); 

function save(){
	
	var total = $("#txt_amount").val();
	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 {
	   	
	   	var login_as        = "<?= $this->session->userdata('username');?>";
        var created_by      = "<?= $detail->CreatedBy;?>";

        var depart_by       = "<?= $detail->DepartmentCode;?>";
		var depart_ses      = "<?= $this->session->userdata('department');?>";
		var jobtitle_status = "<?= $this->session->userdata('jobtitle_status');?>";

        var no_transaksi    = $('#txt_ibank_no').val();
        var status          = '<?= $detail->TransStatus;?>';

        checking_update(no_transaksi,status,function(check){
        
            if(check.status == true){
                edit_data('<?=$menu_link?>','#fm_ibank_transfer',created_by,login_as,depart_by,depart_ses,jobtitle_status);
            }else{
                $.messager.alert('Unseccessfull',check.message,'error',function(){
                    location.reload();
                });
            }

        });
		
		 
	}
}

function to_journal(){
	var idtojournal	= $('#txt_ibank_no').val();
	parent.tab_edit('Journal Inter Bank Transfer', '<?=$menu_link?>', 'icon-journal', 'to_journal', idtojournal);
}
	
function cek_amount(value){
	var total = toAngka(value);
	$("#txt_amount").val(total);
}

function app_dir(){

	var no_transaksi    = $('#txt_ibank_no').val();

    checking_approval(no_transaksi,function(check){
        
        if(check.status == false){
           	custom_data('<?=$menu_link?>/approval2','#fm_ibank_transfer');
        }else{
            $.messager.alert('Unseccessfull',check.message,'error',function(){
                location.reload();
            });
        }
    });
}

function app_reverse(){

	var no_transaksi    = $('#txt_ibank_no').val();
    
    checking_reverse(no_transaksi,function(check){
        
        if(check.status == true){
            reversed_data('F','<?=$menu_link?>', no_transaksi, 'IBank Transfer');
        }else{
           $.messager.alert('Unseccessfull',check.message,'error',function(){
                location.reload();
            });
        }
    });
}

function suspend(type){
    var created_by      = '<?php echo $detail->CreatedBy;?>';
    var login_as        = '<?php echo$this->session->userdata('username');?>';
    var job_title       = '<?php echo $this->session->userdata('jobtitle_status');?>';
    var url             = '<?= base_url();?>custom/custom/checking_suspend';
    
    suspend_check_trans('F', type, '<?=$menu_link?>', $('#txt_ibank_no').val(), '<?=$menu_label;?>', url, created_by, login_as, job_title);
}

</script>