<!--
Author 	: Wahyu
Tanggal : 20-10-2014	
Revisi 	:
-->

<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-journal" plain="true" onClick="parent.tab_edit('Journal Deposit', '<?php echo $menu_link; ?>', 'icon-bank', 'to_journal','<?php echo $id = $detail->CDepNumber; ?>')">Journal</a>
                    <input type="checkbox" id="chk_status" name="chk_status" value="3" onClick="suspend(1)" style="margin-right:0px;margin-top:1px;<?=($detail->TransStatus==3)?'opacity:0.7;':''?>" 
						 <?php 
							if($detail->TransStatus == 2){echo "disabled";}
							if($detail->TransStatus == 3){echo "checked disabled";}
						?> 
                     />
                    <span style="<?=($detail->TransStatus==3)?'color:gray;':''?>">Suspend</span>
                </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">
    <?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%;height:526px;padding:5px;" fit="true">
        	<form id="fm_deposit" name="fm_deposit" method="post">
            <input type="hidden" name="currency_code" id="currency_code" value="<?php echo $detail->CurrencyCode;?>"/>
                <input type="hidden" name="currency_code_to" id="currency_code_to" value="<?php echo $detail->CurrencyCode_to;?>"/>
            	<!-- 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" editable="true" class="combo-grid" <?php if($detail->TransStatus == 3 || $detail->TransStatus == 2){ echo "disabled"; }?>
                                    id="cmb_bank_from" 
                                    style="width:252px;height:22px;" 
                                    data-options="
                                    	value:'<?php echo  $detail->BankPayment; ?>',
                                        panelWidth: 252,
                                        idField: 'AccountNumber',
                                        textField: 'AccountName',
                                        url: '<?php echo base_url(); ?><?php echo"activities/deposit"; ?>/get_petty_cash/<?php echo  $detail->BranchCode; ?>',               
                                        columns: [[
                                        {field:'AccountName',title:'Account Name',width:190}
                                        ]],
                                        fitColumns: true,
                                        onLoadSuccess:function(data){
                                            Vdata.data[0] = data.rows;  
                                        }
                                    " required 
                                >
                                </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" editable="true" class="combo-grid" <?php if($detail->TransStatus == 3 || $detail->TransStatus == 2){ echo "disabled"; }?>
                                    id="cmb_bank"  
                                    style="width:252px;height:22px;" 
                                    data-options="
                                    	value:'<?php echo  $detail->BankReceipt; ?>',
                                        panelWidth: 252,
                                        idField: 'AccountNumber',
                                        textField: 'AccountName',
                                        url: '<?php echo base_url(); ?><?php echo"activities/deposit"; ?>/get_akun_bank/<?php echo $detail->BranchCode; ?>/IDR/<?php echo $detail->CurrencyCode;?>',
                                        columns: [[
                                        {field:'AccountName',title:'Account Name',width:190}
                                        ]],
                                        fitColumns: true,
                                        onLoadSuccess:function(data){
                                            Vdata.data[1] = data.rows;  
                                        }
                                    " required 
                                >
                                </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;" <?php if($detail->TransStatus == 3 || $detail->TransStatus == 2){ echo "disabled"; }?>><?php echo  $detail->CDepDesc; ?></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="text" class="easyui-numberbox" style="width:110px;" data-options="min:0,precision:2,decimalSeparator:',',groupSeparator:'.',prefix:''" value="<?php echo $detail->CurrencyRate;?>"/> <strong>Currency :</strong> <span id="from_currency"></span> <span>TO</span> <span id="to_currency">
                            	
                            </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 type="text" name="txt_amount" id="txt_amount" class="easyui-numberbox"  data-options="min:0,precision:2,decimalSeparator:',',groupSeparator:'.',prefix:''" value="<?php echo  $detail->CDepTotalAmount; ?>" />
                            </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" value="<?php echo  $detail->CDepNumber; ?>" 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" style="width:122px;height:22px" required editable="false" readonly/></td>
                        </tr>
                        </table>
                    </td>
                </tr>
                </table>
                <!-- End of form header -->
            </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" 
                        <?php 
                            if($detail->TransStatus == 3 || date('Y-m-d') < date('Y-m-d', strtotime($detail->CDepDate))){ echo "disabled"; }
                            else if($this->session->userdata("jobtitle_status") == 1 &&  $detail->AppLevel1Status !=1){ echo " enabled "; } 
                            else { echo"disabled"; } 
                        ?> onclick="app_mgr()"> App. MGR</a>
                    <a href="javascript:void(0)" class="easyui-linkbutton form-button" iconCls="icon-save" id="" onclick="update_deposit()"
                        <?php 
                        
                            if(!empty($detail->AppLevel1Status)){ echo "disabled";}
                            else if($detail->TransStatus == 3 || $detail->TransStatus == 2){echo "disabled";}
                            else{ echo "enabled";}
                        ?>>Save</a> 								
                    <a href="javascript:void(0)" class="easyui-linkbutton form-button" iconCls="icon-print" onClick="link_print('<?php echo $menu_link; ?>/to_print/<?php echo $CDepNumber = str_replace("/",".", $detail->CDepNumber); ?>')">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">
var Vdata   = {id:['cmb_bank_from','cmb_bank'],data:[null,null]};
$(document).ready(function(){

    $(".combo-grid").combogrid().next().children(":text").blur(function(){
        var txtValue    = $(this).val();
        clearComboGrid(txtValue);
    });

	$('#txt_deposit_date').datebox('setValue','<?php echo  $detail->CDepDate; ?>');
	var from_currency = $('#currency_code').val();
	$('#cmb_bank').combogrid('readonly', true);
	var to_currency = $('#currency_code_to').val();
	
	$('#currency_amount').text('<?php echo $detail->CurrencyCode_to;?>');
	$('#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;?>');
	}
	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');
		}
	}
	
	$('#cmb_bank_from').combogrid({
		onSelect: function(rowIndex, rowData){
			if(rowData.CurrencyCode == 'IDR'){
			  $('#from_currency').text('USD');
			  $('#to_currency').text(rowData.CurrencyCode);
			  $('#txt_rate').numberbox('setValue', 0);
			   $('#currency_code').val(rowData.CurrencyCode);
			   
		   		$('#cmb_bank').combogrid({
					delay: 300,
					value:'',
					url: '<?php echo base_url(); ?><?php echo"activities/deposit"; ?>/get_akun_bank/<?php echo  $detail->BranchCode; ?>/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', 0);
			   $('#currency_code').val(rowData.CurrencyCode);
		   		$('#cmb_bank').combogrid({
					delay: 300,
					value:'',
					url: '<?php echo base_url(); ?><?php echo"activities/deposit"; ?>/get_akun_bank/<?php echo  $detail->BranchCode; ?>/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);
						}
						else{
							$('#currency_amount').text(rowData.CurrencyCode);
							$('#currency_code_to').val(rowData.CurrencyCode);
						}
					}
				});
		   }
		}
	
	});	
});

function app_mgr(){
	$.messager.confirm('Confirm','Setelah Di Approve Transaksi Akan Masuk Kedalam Coa, Silahkan Cek Kembali Transaksi Ini',function(r){
		if(r){
			custom_data('<?php echo"activities/deposit"; ?>/approval2','#fm_deposit');
		}
	});
}
function update_deposit(){
	var total_am = $("#txt_amount").numberbox('getValue');
	var txt_rate = $('#txt_rate').numberbox('getValue');
	
	if(total_am < 1){
		$.messager.show({
			title: 'Unseccessfull',
			msg: 'Amount Tidak Boleh Nol',
			style:{
					right:'',
					bottom:''
			}
		});
	} 
	else if(txt_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 Benar',function(r){
			if(r){
		  		edit_data('<?php echo"$menu_link"; ?>', '#fm_deposit');
		  	}
		});
	}
}

function suspend(type){
	suspend_data_new('F',type,'<?=$menu_link?>',$('#txt_deposit_no').val(),'Deposit');
}

/*function cek_amount(value){
	var total = toAngka(value);
	$("#txt_amount").numberbox('setValue', total);
}

function cek_rate(value){
	var total = toAngka(value);
	$("#txt_rate_hidden").numberbox('setValue', total);
}*/
</script>