<!---- 
    Author 	: Wahyu
    Tanggal : 23-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" 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_piutang_no').val(),'<?=$menu_label;?>')" <?=(!in_array($detail->TransStatus,array(4,6))) ? 'disabled' : ''?> <?=($detail->TransStatus) == 3 ? 'checked':''?> <?= $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" plain="true" iconCls="icon-currency" onclick="app_payment()" <?=(in_array($detail->TransStatus,array(1)))?'':'disabled'?>>To Payment</a>
							<a href="#" class="easyui-linkbutton" iconCls="icon-journal" plain="true" onClick="parent.tab_edit('Journal Piutang Karyawan', '<?= $menu_link; ?>', 'icon-bank', 'to_journal',$('#txt_piutang_no').val())" <?= $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">
								<?= $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 elseif($detail->TransStatus==3): ?>
    	 <div class="blanket"></div>
         <div class="suspend-box"><b>Suspended</b></div>
	<?php elseif($detail->TransStatus == 1): ?>
         <div class="blanket"></div>
         <div class="cancel-box"><b>On Progress</b></div>
	<?php endif;?>
		<div id="form-wrapper" class="easyui-panel"  style="width:1180%;padding:5px;" fit="true">
			<form id="fm_piutang_karyawan" name="fm_piutang_karyawan" method="post" action="">
				<!-- Form Header -->
                <table width="100%" height="141" cellpadding="0" cellspacing="0">
                <tr>
                    <td width="50%" valign="top">
						 <table cellpadding="0" cellspacing="3" width="100%" height="100%" border="0">				   
							<tr>
								<td width="150">
									 <b><label>Transfer From</label></td>
								<td width="10">:</td>
								<td>
									<select editable="false" name="cmb_from_company" editable='false' class="combo-grid" id="cmb_from_company" required="required" style="width:200px;height:20px" <?=in_array($detail->TransStatus,array(1,2,3,4,5)) ? 'disabled':'';?> data-options="
										value:'<?= $detail->BranchCode; ?>', 
										panelWidth: 200,
										idField: 'BranchCode',
										textField: 'BranchName',
										url: '<?= base_url().$menu_link; ?>/get_company_edit/<?= $detail->BranchCode; ?>',            
										columns: [[
										{field:'BranchName',title:'Company Name',width:140}
										]],
										fitColumns: true,
										onSelect: function(rowIndex, rowData){	
											var ComCode = rowData.CompanyCode;
											$('#cmb_from_bank').combogrid({
												delay: 300,
												url: '<?= base_url().$menu_link; ?>/get_akun_bank/'+ComCode,
												idField: 'AccountNumber',
												textField: 'AccountName',
												columns: [[
													{field:'AccountName',title:'AccountName',width:400,sortable:true}
												]]
											});
											
											$('#cmb_karyawan').combogrid({
												delay: 300,
												url: '<?= base_url().$menu_link; ?>/get_karyawan/'+ComCode,
												idField: 'EmployeeCode',
												textField: 'EmployeeName',
												columns: [[
												    {field:'EmployeeCode',title:'NIK',width:50,sortable:true},
													{field:'EmployeeName',title:'Karayawan',width:180,sortable:true}
												]]
											});
										}
										">
									</select>
									<select name="cmb_from_bank" editable='true' class="combo-grid" id="cmb_from_bank" required="required" style="width:200px;height:20px;" <?=in_array($detail->TransStatus,array(1,2,3)) ? 'disabled':'';?>  data-options="
										value:'<?= $detail->BankTransfer; ?>',
										panelWidth: 300,
										idField: 'AccountNumber',
										textField: 'AccountName',
										url: '<?= base_url().$menu_link; ?>/get_akun_bank_edit/<?= $detail->BranchCode; ?>',               
										columns: [[
										{field:'AccountNumber',title:'Account Bank',width:110},
										{field:'AccountName',title:'Account Name',width:190}
										]],
										fitColumns: true,
										onSelect:function(){
			                               $('.app-button').linkbutton('disable');
			                              
			                            }
										">
										</select>
								</td>
							</tr>
							<tr>
								<td width="150">
									 <b><label>Transfer To</label></td>
								<td width="10">:</td>
								<td valign="top" align="left">
									<select name="cmb_karyawan" editable='true' class="combo-grid" id="cmb_karyawan" required="required" style="width:200px;height:20px;" <?=in_array($detail->TransStatus,array(1,2,3)) ? 'disabled':'';?>  data-options="
										value:'<?= $detail->EmplRecpCode; ?>',
										panelWidth: 300,
										idField: 'EmployeeCode',
										textField: 'EmployeeName',
										url: '<?= base_url().$menu_link; ?>/get_karyawan_edit/<?= $detail->BranchCode; ?>',               
										columns: [[
										{field:'EmployeeCode',title:'NIK',width:110},
										{field:'EmployeeName',title:'Karyawan',width:190}
										]],
										fitColumns: true,
										onSelect:function(){
			                               $('.app-button').linkbutton('disable');
			                              
			                            }
										">
										</select>
									<input name="txt_rekening_karyawan" id="txt_rekening_karyawan" class="easyui-validatebox" value="<?="$detail->BankReceipt"; ?>" <?=in_array($detail->TransStatus,array(1,2,3)) ? 'disabled':'';?> required="required" type="text" style="width:198px" placeholder="Rekening Karyawan" autocomplete="off" />
								</td>
								
							</tr>
							<tr>
								<td width="150">
									  <b><label>Cheque No</label>
							    </td>
								<td width="10">:</td>
								<td>
									<input name="txt_cheque_no" id="txt_cheque_no" type="text" value="<?= $detail->ChequeNumber;?>" <?=in_array($detail->TransStatus,array(1,2,3)) ? 'disabled':'';?> style="width:200px" />								
		                       </td>
								
							</tr>
							
							<tr>
								<td width="150">
									  <b><label>Description</label></td>
								<td width="10">:</td>
								<td>
									<textarea class="textbox" style="resize:none;" name="txa_description" id="txa_description" cols="55" rows="3" <?=in_array($detail->TransStatus,array(1,2,3)) ? 'disabled':'';?>><?="$detail->EDebtDesc"; ?></textarea></td>
								<td valign="top" align="left">&nbsp;</td>
							</tr>
							<tr>
							  <td width="150"><b><label>Amount</label></b></td>
							  <td width="10">:</td>
							  <td>
								<input name="txt_amount_rp" id="txt_amount_rp" type="text" value="<?="$detail->EDebtAmount"; ?>" class="easyui-numberbox" data-options="min:0.01,precision:2,decimalSeparator:',',groupSeparator:'.',prefix:''" style="width:403px;height:18px;text-align:right" required="required" />
								<input name="txt_amount" id="txt_amount" type="hidden" value="<?="$detail->EDebtAmount"; ?>" />
								<!--<a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-calculator',size:'small'" onClick="">-->
							  </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;">Piutang No.</td>
                            <td width="122" style="background:#333399;text-align:center;color:#FFF;">Piutang Date</td>
                        </tr>
                        <tr height="20">
                        	<td>&nbsp;</td>
                            <td><input type="text" name="txt_piutang_no" id="txt_piutang_no" value="<?="$detail->EDebtNumber";?>" class="easyui-validatebox" style="width:190px;height:18px;text-align:center;" required readonly  /></td>
                            <td><input type="text" name="txt_payment_date" id="txt_payment_date" class="easyui-datebox validBackward" style="width:122px;height:22px" required editable="false" value="<?= date("d-m-Y", strtotime($detail->EDebtDate));?>" 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>Availabel 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>
			</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" onclick="app_mgr()" <?= (($this->session->userdata("jobtitle_status") != 1 || !in_array($detail->TransStatus,array(4,6))) || (date('Y-m-d') < date('Y-m-d', strtotime($detail->EDebtDate))))?'disabled':''?>>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)))?'':'disabled'?> style="<?= $cek_autority_reverse;?>" >Reverse</a> 
                         <a href="javascript:void(0)" class="easyui-linkbutton form-button" iconCls="icon-save" onclick="save_data()" <?=(in_array($detail->TransStatus,array(0,1,2,3)))?'disabled':''?> <?= $cek_autority_save;?>>Save</a> 								
                         <a href="javascript:void(0)" class="easyui-linkbutton form-button" iconCls="icon-print" onclick="parent.tab_edit('Print Piutang Karyawan', '<?=$menu_link?>', 'icon-print', 'to_print_detail','<?= $detail->EDebtNumber;?>');" <?=(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,4)))?'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_cheque_date').datebox('setValue', '<?= date("d-m-Y", strtotime($detail->ChequeDate));?>');
    $('#txt_payment_date').datebox('setValue', '<?= date("d-m-Y", strtotime($detail->EDebtDate));?>');

    var AccountNumber	= '<?= $detail->BankTransfer; ?>';

    get_bank_balance(AccountNumber,'IDR'); 
});

function cek_amount(value){
	var total = toAngka(value);
	$("#txt_amount").val(total);
}

function save_data(){ 	

	var Amount = $('#txt_amount_rp').numberbox('getValue');
	$('#txt_amount').val(Amount);
	var total = $("#txt_amount").val();

	if(total < 1){
		$.messager.alert('Unseccessfull','Transaksi Belum Lengkap','error');
		return false;
	}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_piutang_no').val();
	    var status          = '<?= $detail->TransStatus;?>';

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

	    });
	}
}

function app_mgr(){

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

    checking_approval(no_transaksi,function(check){
        
        if(check.status == false){
             $('#code_appdir').val('5');
             approved_data('<?=$menu_link?>','#fm_piutang_karyawan');
        }else{
            $.messager.alert('Unseccessfull',check.message,'error',function(){
                location.reload();
            });
        }
    });
}

function app_reverse(){

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

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

function app_payment(){

    var isLock          = '<?=$detail->EdebtIsLock;?>';
    var no_transaksi    = $('#txt_piutang_no').val();

    if(isLock == 0){
       parent.tab_add('New Payment Karyawan','list/payment_karyawan','icon-add','add/'+no_transaksi);
    }else{
        $.messager.alert('Unseccessfull','Piutang Karyawan Lock. Tidak bisa melakukan transaksi payment.','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_piutang_no').val(), '<?=$menu_label;?>', url, created_by, login_as, job_title);
}

</script>