<!---- 
    Author 	: Herpan
    Tanggal : 12-08-2014	
    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----------------------------
	foreach($transaksi_antar_kas as $row):
?>
<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;?>',$('#trans_to_petty_cash_no').val(),'<?=$menu_label;?>')" <?=(!in_array($row->TransCashStatus,array(4,6))) ? 'disabled' : ''?> <?=(in_array($row->TransCashStatus,array(3,9))) ? 'checked' : ''?><?php echo $cek_autority_delete;?>/>
                            <span style="display:inline-block;margin-top:2px;<?=(($row->TransCashStatus==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($row->TransCashStatus == 4){
			                    echo get_status_approval_header($row->TransCashStatus);
			                }
			                ?>
			                </span>
			            </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">
		<?php if($row->TransCashStatus == 2){ ?>
            <div class="blanket"></div>
            <div class="finished-box"><b>Finished</b></div>
		<?php }else if($row->TransCashStatus ==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_transaksi_antar_kas" name="fm_transaksi_antar_kas" method="post">
				
				<input type="hidden" id="id" name="id" value="<?=$row->TCashNumber;?>" />
				<input type="hidden" id="branch_code_hidden" name="branch_code_hidden" value="<?=$row->BranchTCash;?>" />
				<?php foreach($id_journal as $row_idjournal){?>
				<input type="hidden" name="id_journnal[]" value="<?=$row_idjournal->TCashJournalID;?>" />
				<?php } ?>
				<input type="hidden" name="code_appmgrspv" id="code_appmgrspv" />
				<input type="hidden" name="copy_suspend" id="copy_suspend" />
                <input type="hidden" name="currency_code" id="currency_code" value="<?=$row->CurrencyCode;?>"/>
                <input type="hidden" name="currency_code_to" id="currency_code_to" value="<?=$row->CurrencyCode_to;?>"/>
                <!-- Form Header -->
                <table width="100%" height="141" cellpadding="0" cellspacing="0">
	                <tr>
	                    <td width="50%" valign="top">
							<table cellpadding="0" cellspacing="1" width="100%" height="36%" 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:250px;height:20px" <?php if($row->TransCashStatus == 3 || $row->TransCashStatus == 2 || $row->TransCashStatus == 1){echo "disabled";}?>
											required data-options="
												panelWidth: 250,
												value:'<?=$row->BankTransfer;?>',
												idField: 'AccountNumber',
												textField: 'AccountName',
												url: '<?= base_url().$menu_link; ?>/get_bank_bycompany/<?=$row->BranchTCash;?>',
												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;
												   $('.app-button').linkbutton('disable');

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

												   if(rowData.CurrencyCode == 'IDR'){
														$('#currency_code').val(rowData.CurrencyCode);
														
														var currency_array = ['IDR'];
														
														$('#cmb_bank_accountto').combogrid({
															delay: 300,
															value:'', 
															url: '<?=base_url().$menu_link; ?>/get_petty_cash_bycompany/<?= $row->BranchTCash;?>/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){
																$('.app-button').linkbutton('disable');
																$('#cmb_bank_accountto').combogrid('readonly', false);
																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,
															value:'', 
															url: '<?= base_url().$menu_link; ?>/get_petty_cash_bycompany/<?= $row->BranchTCash;?>/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){
																$('#cmb_bank_accountto').combogrid('readonly', false);
																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);
																	
																}
															}
														});
												   }
												}
											">
										</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:250px;height:20px" <?php if($row->TransCashStatus == 3 || $row->TransCashStatus == 2 || $row->TransCashStatus == 1){echo "disabled";}?>
									required data-options="
										panelWidth: 250,
										value:'<?=$row->BankReceipt;?>',
										idField: 'AccountNumber',
										textField: 'AccountName',
										url: '<?=base_url().$menu_link; ?>/get_petty_cash_bycompany/<?=$row->BranchTCash;?>/IDR/<?= $row->CurrencyCode;?>',
										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" value="<?=$row->ChequeNumber;?>" <?=in_array($row->TransCashStatus, array(1,2,3))?'disabled':'';?>>
		                            </td>
		                        </tr>
								<tr>
									<td valign="top" height="54" align="left">
										<b><label>Memo</label></b>
									</td>
									<td height="54" valign="top" align="left">
										<textarea class="textbox" style="resize:none;" name="txa_memo" id="txa_memo" cols="33" rows="3" <?php if($row->TransCashStatus == 3 || $row->TransCashStatus == 2 || $row->TransCashStatus == 1){echo "disabled";}?>><?= $row->TCashDesc;?></textarea>
								  </td>
							  </tr>
			                    <tr>
									<td valign="top" height="31" 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" style="width:110px;" data-options="min:0.01,precision:2,decimalSeparator:',',groupSeparator:'.',prefix:''" value="<?= $row->CurrencyRate;?>"/> <strong>Currency :</strong> <span id="from_currency"></span> <span>TO</span> <span id="to_currency"></span>
			                        </td>
								</tr>
								<tr>
								  <td valign="top" height="23" 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:''" value="<?= $row->TransAmount;?>" style="width:250px;text-align:right;" required="required"
											autoComplete="off" <?php if($row->TransCashStatus == 3 || $row->TransCashStatus == 2 || $row->TransCashStatus == 1){echo "disabled";}?>/>
									
								  </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="190" style="background:#333399;text-align:center;color:#FFF;">Transfer Cash No.</td>
		                            <td width="122" style="background:#333399;text-align:center;color:#FFF;">Date</td>
		                        </tr>
		                        <tr height="20">
		                        	<td>&nbsp;</td>
		                            <td><input type="text" name="trans_to_petty_cash_no" value="<?=$row->TCashNumber;?>" id="trans_to_petty_cash_no" class="easyui-validatebox"  style="width:190px;height:18px;text-align:center;" required readonly  /></td>
		                            <td><input type="text" name="txt_jv_date" id="txt_jv_date" value="<?= date("d-m-Y", strtotime($row->TCashDate));?>" class="easyui-datebox" style="width:122px;height:22px" required editable="false" 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>
	<?php endforeach;?>
    <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" onclick="btn_appmgrspv()" <?= (($this->session->userdata("jobtitle_status") != 1 || !in_array($row->TransCashStatus, array(4,6))) || (date('Y-m-d') < date('Y-m-d', strtotime($row->TCashDate))))?'disabled':'' ?>>App. Mgr</a>
                     <a href="javascript:void(0)" class="easyui-linkbutton form-button app-button" iconCls="icon-ok" onclick="app_reverse()" <?=(!in_array($row->TransCashStatus, array(1,2,9))) || (date('Y-m-d') < date('Y-m-d', strtotime($row->TCashDate)))?'disabled':'' ?> style="<?= $cek_autority_reverse;?>" >Reverse</a>
                     <a href="javascript:void(0)" class="easyui-linkbutton form-button save-button" iconCls="icon-save" onclick="save_data();" <?=(in_array($row->TransCashStatus,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="" id="prevandviewbyno">Preview & Print</a>   
                     <a href="javascript:void(0)" class="easyui-linkbutton form-button" iconCls="icon-cancel" onclick="parent.tab_close('tt')">Cancel</a> -->
                     <a href="javascript:void(0)" class="easyui-linkbutton form-button" iconCls="icon-print" onclick="parent.tab_edit('Print Transfer To Petty Cash', '<?=$menu_link?>', 'icon-print', 'to_print_detail','<?php echo $row->TCashNumber;?>');" <?=(in_array($row->TransCashStatus,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($row->TransCashStatus,array(0,4,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(){
    			    
	var from_currency = $('#currency_code').val();
	var to_currency = $('#currency_code_to').val();
	
	$('#currency_amount').text('<?php echo $row->CurrencyCode_to;?>');
	$('#cmb_bank_accountto').combogrid('readonly', true);
	
	if(from_currency == 'IDR' && to_currency == "IDR"){
		$('#from_currency').text('IDR');
		$('#to_currency').text('<?php echo $row->CurrencyCode_to;?>');
		$('#txt_rate').prop('readonly', true);
	}
	else{
		if(to_currency != "IDR"){
			$('#from_currency').text('<?php echo $row->CurrencyCode_to;?>');
			$('#to_currency').text('IDR');
		}
		else{
			$('#from_currency').text('<?php echo $row->CurrencyCode;?>');
			$('#to_currency').text('IDR');
		}
	}

	var AccountNumber = '<?= $row->BankTransfer;?>';
	
    get_bank_balance(AccountNumber,from_currency);
	
});
</script>
<script type="text/javascript">
	
	function save_data(){
		var total_am = $("#txt_amount").numberbox('getValue');
		var txt_rate = $('#txt_rate').numberbox('getValue');
		
		if(total_am < 1){
			$.messager.alert('Unseccessfull','Amount tidak boleh kurang dari sama dengan nol','warning');
		} 
		else if(txt_rate < 1){
			$.messager.alert('Unseccessfull','Rate tidak boleh kurang dari sama dengan nol','warning');
		}
		else{
			var login_as        = "<?= $this->session->userdata('username');?>";
	        var created_by      = "<?= $row->CreatedBy;?>";
	        var depart_by       = "<?= $row->DepartmentCode;?>";
			var depart_ses      = "<?= $this->session->userdata('department');?>";
			var jobtitle_status = "<?= $this->session->userdata('jobtitle_status');?>";

	        var no_transaksi    = $('#trans_to_petty_cash_no').val();
	        var status          = '<?= $row->TransCashStatus;?>';
	        

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

	        });

		}
	}
	
	$('#chk_suspend').click(function(){
		if($(this).is(':checked')){
			$('#copy_suspend').val('1');
		}
		else{
			$('#copy_suspend').val('');
		}
	});
	
	function app_reverse(){
		var no_transaksi    = $('#trans_to_petty_cash_no').val();
	    

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

	    checking_approval(no_transaksi,function(check){
	        
	        if(check.status == false){
	        	$('#code_appmgrspv').val('4');
	           	approved_data('<?=$menu_link?>','#fm_transaksi_antar_kas');
	        }else{
	            $.messager.alert('Unseccessfull',check.message,'error',function(){
	                location.reload();
	            });
	        }
	    });	
			
	}
	
	function to_journal(){
		var idtojournal	= $('#id').val();
		parent.tab_edit('Journal Transfer To Petty Cash', '<?=$menu_link?>', 'icon-journal', 'to_journal', idtojournal);
	}
	
	
	$('#prevandviewbyno').click(function(){
		var trans_no		= $('#id').val();
		parent.tab_edit('Print Transfer To Petty Cash', '<?=$menu_link?>', 'icon-print', 'to_previewbyno', trans_no);
	});

	function suspend(type){
	    var created_by      = '<?php echo $row->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?>', $('#trans_to_petty_cash_no').val(), '<?=$menu_label;?>', url, created_by, login_as, job_title);
	}
</script>