<!---- 
    Author 	: Wahyu
    Tanggal : 23-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" valign="middle">							
							<a href="#" class="easyui-linkbutton" iconCls="icon-document" plain="true" onclick="location.reload()" />New</a>
							<a href="#" class="easyui-linkbutton" iconCls="icon-journal" plain="true" onClick="parent.tab_edit('Journal Piutang Karyawan', '<?php echo $menu_link; ?>', 'icon-bank', 'to_journal',$('#txt_piutang_no').val())" />Journal</a>
						</td>							
						<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_piutang_karyawan" name="fm_piutang_karyawan" method="post" action="<?php echo base_url(); ?><?php echo"activities/piutang_karyawan/update"; ?>">
				 <table cellpadding="0" cellspacing="3 width="100%" height="100%" border="0">
				    
					<tr>
						<td valign="top" height="22" width="75" align="left">
							 <label>Dari</label></td>
						<td valign="top" align="left"  width="760">
							<select editable="false" name="cmb_from_company" class="easyui-combogrid" id="cmb_from_company" required="required" style="width:200px;height:20px" <?php if($detail->TransStatus == 3 || $detail->TransStatus == 2 || $detail->TransStatus == 1 || $detail->TransStatus == 4 || $detail->TransStatus == 5){ echo " disabled "; }?> data-options="
								value:'<?php echo  $detail->BranchCode; ?>', 
								panelWidth: 200,
								idField: 'BranchCode',
								textField: 'BranchName',
								url: '<?php echo base_url(); ?><?php echo"activities/piutang_karyawan"; ?>/get_company_edit/<?php echo  $detail->BranchCode; ?>',            
								columns: [[
								{field:'BranchName',title:'Company Name',width:140}
								]],
								fitColumns: true
								">
							</select>
					
							<select editable="false" name="cmb_from_bank" class="easyui-combogrid" id="cmb_from_bank" required="required" style="width:200px;height:20px;" <?php if($detail->TransStatus == 3 || $detail->TransStatus == 2 || $detail->TransStatus == 1 || $detail->TransStatus == 4 || $detail->TransStatus == 5){ echo " disabled "; }?>  data-options="
							value:'<?php echo  $detail->BankTransfer; ?>',
							panelWidth: 300,
							idField: 'AccountNumber',
							textField: 'AccountName',
							url: '<?php echo base_url(); ?><?php echo"activities/piutang_karyawan"; ?>/get_akun_bank_edit/<?php echo  $detail->BranchCode; ?>',               
							columns: [[
							{field:'AccountNumber',title:'Account Bank',width:110},
							{field:'AccountName',title:'Account Name',width:190}
							]],
							fitColumns: true
							">
							</select>	
						</td>
                        <td width="139" height="22" align="left" valign="top">Employee Debt No</td>
						<td width="164" align="left" valign="top">
							<input type="text" name="txt_piutang_no" value="<?php echo"$detail->EDebtNumber"; ?>" id="txt_piutang_no" class="easyui-validatebox" style="width:170px;" readonly  required="required" />								
                       </td>
                       
                       

						
				   </tr>
					<tr>
						<td valign="top" height="22" align="left">
							 Kepada</td>
						<td valign="top" align="left">
							<select name="cmb_karyawan" editable="false" class="easyui-combogrid" id="cmb_karyawan" required="required" style="width:200px;height:20px;" <?php if($detail->TransStatus == 3 || $detail->TransStatus == 2 || $detail->TransStatus == 1 || $detail->TransStatus == 4 || $detail->TransStatus == 5){ echo " disabled "; }?>  data-options="
							value:'<?php echo  $detail->EmplRecpCode; ?>',
							panelWidth: 300,
							idField: 'EmployeeCode',
							textField: 'EmployeeName',
							url: '<?php echo base_url(); ?><?php echo"activities/piutang_karyawan"; ?>/get_karyawan_edit/<?php echo  $detail->BranchCode; ?>',               
							columns: [[
							{field:'EmployeeCode',title:'NIK',width:110},
							{field:'EmployeeName',title:'Karyawan',width:190}
							]],
							fitColumns: true
							">
							</select>		
							<input name="txt_rekening_karyawan" id="txt_rekening_karyawan" value="<?php echo"$detail->BankReceipt"; ?>" type="text" style="width:198px" <?php if($detail->TransStatus == 3 || $detail->TransStatus == 2 || $detail->TransStatus == 1 || $detail->TransStatus == 4 || $detail->TransStatus == 5){ echo " disabled "; }?> />
						</td>
						<td valign="top" align="left">Piutang Date</td>
                        <td valign="top" align="left"><input type="text" editable="false" name="txt_payment_date" value="<?php echo date("d-m-Y", strtotime($detail->EDebtDate));?>" id="txt_payment_date" class="easyui-datebox validBackward" style="width:120px;" required="required" readonly /></td>	
					</tr>
					<tr>
						<td valign="top" height="22" align="left">
							  Cheque No
					    </td>
						<td valign="top" align="left">
							<input name="txt_cheque_no" id="txt_cheque_no" type="text" style="width:100px" value="<?php echo $detail->ChequeNumber;?>" <?php if($detail->TransStatus == 3 || $detail->TransStatus == 2 || $detail->TransStatus == 1 || $detail->TransStatus == 4 || $detail->TransStatus == 5){ echo " disabled "; }?> />								
                       </td>
						<td valign="top" align="left">&nbsp;</td>
					</tr>
					<!--<tr>
						<td valign="top" height="22" align="left">
							 Date
					    </td>
						<td valign="top" align="left">
							<input editable="false" name="txt_cheque_date" id="txt_cheque_date" type="text" class="easyui-datebox" style="width:100px;height:20px;" value="<?php echo date("d-m-Y", strtotime($detail->ChequeDate));?>" <?php if($detail->TransStatus == 3 || $detail->TransStatus == 2 || $detail->TransStatus == 1 || $detail->TransStatus == 4 || $detail->TransStatus == 5){ echo " disabled "; }?> />
                        </td>
						<td valign="top" align="left">&nbsp;</td>
					</tr>-->
					<tr>
						<td valign="top" height="51" align="left">
							  Description</td>
						<td valign="top" align="left"><textarea class="textbox" style="resize:none;" name="txa_description" id="txa_description" cols="48" rows="3" <?php if($detail->TransStatus == 3 || $detail->TransStatus == 2 || $detail->TransStatus == 1 || $detail->TransStatus == 4 || $detail->TransStatus == 5){ echo " disabled "; }?> ><?php echo"$detail->EDebtDesc"; ?></textarea></td>
						<td valign="top" align="left">&nbsp;</td>
					</tr>
					<tr>
					  <td height="22" valign="top" align="left">Amount</td>
					  <td valign="top" height="22" align="left">
						<input name="txt_amount_rp" id="txt_amount_rp" type="text" 
                        
                         class="easyui-numberbox" data-options="min:0,precision:2,decimalSeparator:',',groupSeparator:'.',prefix:''" onkeyup="cek_amount(this.value)" value="<?php echo"$detail->EDebtAmount"; ?>" style="width:100px;height:18px" required="required" <?php if($detail->TransStatus == 3 || $detail->TransStatus == 2 || $detail->TransStatus == 1 || $detail->TransStatus == 4 || $detail->TransStatus == 5){ echo " disabled "; }?> />
						<input name="txt_amount" id="txt_amount" value="<?php echo"$detail->EDebtAmount"; ?>" type="hidden" />
						<!--<a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-calculator',size:'small'" onClick="">-->
					  </td>
					  <td valign="top" align="left">&nbsp;</td>
				    </tr>
                    <tr>
						<td valign="middle" height="21" align="left">
							<label>Suspended</label>
						</td>
						<td align="left" valign="middle">
							<input type="checkbox" name="chk_suspended" id="chk_suspended" onClick="suspend(1)" class="easyui-validatebox" value="<?php if($detail->TransStatus != 3){ echo"3"; }?>"  <?php if($detail->TransStatus == 3){ echo"checked='checked' disabled"; } else if($detail->TransStatus == 1 || $detail->TransStatus == 2 || $detail->TransStatus == 4 || $detail->TransStatus == 5){echo "disabled";} ?> /> 
						</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" 
						 <?php 
						 	if(date('Y-m-d') < date('Y-m-d', strtotime($detail->EDebtDate)) || $detail->TransStatus == 3 || $detail->TransStatus == 2 || $detail->TransStatus == 1){ 
								echo " disabled "; 
							} 
							else if($this->session->userdata("jobtitle_status") == 0 &&  $detail->AppLevel2Status !=1){ 
								echo " enabled "; 
							} 
							else { 
								echo"disabled"; 
							} 
						 ?> 
                         onclick="custom_data('<?php echo"activities/piutang_karyawan"; ?>/approval1','#fm_piutang_karyawan');"> App. Dir</a>
                         <a href="javascript:void(0)" class="easyui-linkbutton form-button app-button" iconCls="icon-ok" 
						 <?php 
						 	if(date('Y-m-d') < date('Y-m-d', strtotime($detail->EDebtDate)) || $detail->TransStatus == 3 || $detail->TransStatus == 2 || $detail->TransStatus == 1){ 
								echo " disabled "; 
							} 
							else if($this->session->userdata("jobtitle_status") == 1 &&  $detail->AppLevel1Status !=1){ 
								echo " enabled "; 
							} 
							else{ 
								echo"disabled"; 
							} 
						?> onclick="custom_data('<?php echo"activities/piutang_karyawan"; ?>/approval2','#fm_piutang_karyawan');"> App. Mgr</a>			 
                         <a href="javascript:void(0)" class="easyui-linkbutton form-button" iconCls="icon-save" onclick="save_data()" <?php if($detail->TransStatus == 3 || $detail->TransStatus == 2 || $detail->TransStatus == 1){ echo " disabled "; } else if($detail->AppLevel2Status == 1 ||  $detail->AppLevel1Status == 1){ echo " disabled "; } else { echo"enabled"; } ?>  >Save</a> 								
                         <a href="javascript:void(0)" class="easyui-linkbutton form-button" iconCls="icon-print" onclick="parent.tab_add('Print <?php echo"Piutang Karyawan"; ?>', '<?php echo"list/piutang_karyawan"; ?>', 'icon-bank', 'to_preview')">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(3,9)) || $detail->AppLevel2Status==1)?'disabled':''?>>Cancel</a>		
		
					</td>
				 </tr>
			</table>				
		</div>
</div>

<script type="text/javascript">	
$(document).ready(function(){
        $('#txt_cheque_date').datebox('setValue', '<?php echo date("d-m-Y", strtotime($detail->ChequeDate));?>');
        $('#txt_payment_date').datebox('setValue', '<?php echo date("d-m-Y", strtotime($detail->EDebtDate));?>');
});
    
$('#cmb_from_company').combogrid({
	onSelect: function(rowIndex, rowData){	
		var ComCode = rowData.CompanyCode;
		$('#cmb_from_bank').combogrid({
			delay: 300,
			url: '<?php echo base_url(); ?><?php echo"$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: '<?php echo base_url(); ?><?php echo"$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}
			]]
		});
	}
});

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

function save_data(){ 	
	var total = $("#txt_amount").val();
	if(total < 1){
		$.messager.show({
			title: 'Unseccessfull',
			msg: 'Amount Tidak Boleh Nol',
			style:{
					right:'',
					bottom:''
			}
		});
	} else {
	    //$("#fm_piutang_karyawan").submit();
	    edit_data('<?php echo"$menu_link"; ?>', '#fm_piutang_karyawan');
	}
} 
function suspend(type){
	suspend_data_new('F',type,'<?=$menu_link?>',$('#txt_piutang_no').val(),'Piutang Karyawan');
}
</script>