<!--
Author 	: Wahyu
Tanggal : 20-10-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----------------------------
?>
<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">
                    <input type="checkbox" id="chk_suspended" name="chk_suspended" value="3" onclick="suspend_transaction(1,'<?= $menu_link;?>',$('#txt_deposit_no').val(),'<?=$menu_label;?>')" style="margin-right:0px;margin-top:1px;<?=($detail->TransStatus==3)?'opacity:0.7;':''?>" <?=(!in_array($detail->TransStatus,array(4,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="parent.tab_edit('Journal Deposit', '<?php echo $menu_link; ?>', 'icon-bank', 'to_journal','<?php echo $id = $detail->CDepNumber; ?>')" <?php echo $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 == 4){
                    echo get_status_approval_header($detail->TransStatus);
                }
                ?>
                </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" class="combo-grid" editable="true" <?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: '<?= base_url().$menu_link; ?>/get_petty_cash/<?= $detail->BranchCode; ?>',               
                                        columns: [[
                                            {field:'AccountNumber',title:'Account Number',width:100},
                                            {field:'AccountName',title:'Account Name',width:190},
                                            {field:'CurrencyCode',title:'Currency Code',width:150}
                                        ]],
                                        fitColumns: true,
                                        onChange:function(){
                                            $('.app-button').linkbutton('disable');
                                        },
                                        onSelect: function(rowIndex, rowData){
                                            
                                            get_bank_balance(rowData.AccountNumber,rowData.CurrencyCode);  

                                            if(rowData.CurrencyCode == 'IDR'){
                                                $('#from_currency').text('USD');
                                                $('#to_currency').text(rowData.CurrencyCode);
                                                $('#txt_rate').numberbox('setValue', 1);
                                                $('#currency_code').val(rowData.CurrencyCode);
                                                $('#txt_rate').prop('readonly',false);
                                          
                                                $('#cmb_bank').combogrid({
                                                    delay: 300,
                                                    value:'',
                                                    url: '<?= base_url().$menu_link; ?>/get_akun_bank/<?= $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);
                                                            $('#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');
                                                $('#txt_rate').numberbox('setValue', 1);
                                                $('#currency_code').val(rowData.CurrencyCode);
                                                $('#txt_rate').prop('readonly',false);

                                                $('#cmb_bank').combogrid({
                                                    delay: 300,
                                                    value:'',
                                                    url: '<?= base_url().$menu_link; ?>/get_akun_bank/<?= $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);
                                                            $('#txt_rate').prop('readonly',false);
                                                        }
                                                    }
                                                });
                                            }
                                        }
                                    " required 
                                >
                                </select>
                            </td>
                        </tr>
                        <tr height="20">
                        	<td width="150"><b>Deposit To</b></td>
                            <td width="10"><b>:</b></td>
                            <td>
                            	<select name="cmb_bank" class="combo-grid" editable="true" <?php if($detail->TransStatus == 3 || $detail->TransStatus == 2){ echo "disabled"; }?>
                                    id="cmb_bank"  
                                    style="width:252px;height:22px;" 
                                    data-options="
                                    	value:'<?= $detail->BankReceipt; ?>',
                                        panelWidth: 252,
                                        idField: 'AccountNumber',
                                        textField: 'AccountName',
                                        url: '<?= base_url().$menu_link; ?>/get_akun_bank/<?= $detail->BranchCode; ?>/IDR/<?= $detail->CurrencyCode;?>',
                                        columns: [[
                                        {field:'AccountName',title:'Account Name',width:190}
                                        ]],
                                        fitColumns: true,
                                        onSelect:function(record){
                                           $('.app-button').linkbutton('disable');
                                          
                                        }
                                    " required 
                                >
                                </select>
                                
                            </td>
                        </tr>
                         <tr height="20">
                            <td width="150" valign="top" style="padding-top:4px;"><b><?php echo label_grid('check_no');?></b></td>
                            <td width="10" valign="top" style="padding-top:4px;"><b>:</b></td>
                            <td>
                                <input type="text" name="cheque_number" id="cheque_number" style="width:250px" value="<?=$detail->ChequeNumber;?>" <?=in_array($detail->TransStatus, array(1,2,3)) ? 'disabled':'';?>>
                            </td>
                        </tr>
                        <tr height="20">
                        	<td width="150" 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="150"><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.01,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="150"><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.01,precision:2,decimalSeparator:',',groupSeparator:'.',prefix:''" value="<?php echo  $detail->CDepTotalAmount; ?>" style="text-align:right;width:250px" />
                            </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>
                        <table width="100%" cellpadding="0" cellspacing="0" style="margin-top:1px;">
                        <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;"><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;height:18px;width:316px" 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" <?= (($this->session->userdata("jobtitle_status") != 1 || !in_array($detail->TransStatus,array(4,6))) || (date('Y-m-d') < date('Y-m-d', strtotime($detail->CDepDate))))?'disabled':''?> onclick="app_mgr()"> App. Mgr</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" id="" onclick="update_deposit()" <?=(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="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-print" onclick="parent.tab_edit('Print Deposit', '<?=$menu_link?>', 'icon-print', 'to_print_detail','<?php echo $detail->CDepNumber;?>');" <?=(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="parent.tab_close('tt')">Cancel</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,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(){

	$('#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);

    var bank_payment = '<?= $detail->BankPayment; ?>';
    
    get_bank_balance(bank_payment,from_currency);
	
	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');
		}
	}
	
});

function app_mgr(){
	
    var no_transaksi    = $('#txt_deposit_no').val();

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

function cancel_transaction(){
	if(confirm("Apakah Anda yakin ?")==true){
		custom_data('<?php echo"list/deposit"; ?>/cancel_transaction','#fm_deposit');
	}
		
}

function app_reverse(){
    var no_transaksi    = $('#txt_deposit_no').val();

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

function update_deposit(){
	var total_am = $("#txt_amount").numberbox('getValue');
	var txt_rate = $('#txt_rate').numberbox('getValue');
	
	if(total_am <= 0){
		$.messager.alert('Unseccessfull','Amount tidak boleh kosong','warning');
	} 
	else if(txt_rate <= 0){
		$.messager.alert('Unseccessfull','Rate tidak boleh kosong','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_deposit_no').val();
        var status          = '<?= $detail->TransStatus;?>';
        

        checking_update(no_transaksi,status,function(check){
        
            if(check.status == true){
                edit_data('<?=$menu_link?>','#fm_deposit',created_by,login_as,depart_by,depart_ses,jobtitle_status);
            }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_deposit_no').val(), '<?=$menu_label;?>', url, created_by, login_as, job_title);
}

</script>