<!---- 
    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="" disabled />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">
		<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/insert"; ?>">
				 <table cellpadding="0" cellspacing="3" width="100%" height="100%" border="0">				   
					<tr>
						<td valign="top" height="22" width="70" align="left">
							 <label>Transfer From</label></td>
						<td valign="top" align="left"  width="800">
							<select editable="false" name="cmb_from_company" class="easyui-combogrid" id="cmb_from_company" required="required" style="width:200px;height:20px" data-options="
								panelWidth: 200,
								idField: 'BranchCode',
								textField: 'BranchName',
								url: '<?php echo base_url(); ?><?php echo"activities/piutang_karyawan"; ?>/get_company',            
								columns: [[
								{field:'BranchName',title:'Company Name',width:140}
								]],
								fitColumns: true
								">
							</select>
							<select editable="false" name="cmb_from_bank" id="cmb_from_bank" class="easyui-combobox" required="required" style="width:200px;height:20px;">
								
							</select>
						</td>
						<td valign="middle" height="22" width="120" align="left">Employee Debt No</td>
						<td valign="top" align="left">
							<input type="text" name="txt_piutang_no" id="txt_piutang_no" class="easyui-validatebox" style="width:200px;" readonly  required="required" />								
                       </td>
					</tr>
					<tr>
						<td valign="top" height="22" align="left">
							 Transfer To</td>
						<td valign="top" align="left">
							<select editable="false" name="cmb_karyawan" class="easyui-combogrid" required="required" id="cmb_karyawan" style="width:200px;height:20px">
							
							</select>
							<input name="txt_rekening_karyawan" id="txt_rekening_karyawan" class="easyui-validatebox" required="required" type="text" style="width:198px" placeholder="Rekening Karyawan" autocomplete="off" />
						</td>
						<td valign="midlle" height="22" align="left">
							 Piutang Date
					    </td>
						<td valign="top" align="left">
							<input editable="false" name="txt_payment_date" id="txt_payment_date" type="text" value="<?php echo $date_now;?>" class="easyui-datebox validBackward" required="required" style="width:100px;height:20px;" />
                        </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" />								
                       </td>
						<td valign="top" align="left">&nbsp;</td>
					</tr>
					<!--<tr>
						<td valign="top" height="22" align="left">
							Cheque Date
					    </td>
						<td valign="top" align="left">
							<input required="required" name="txt_cheque_date" id="txt_cheque_date" type="text" class="easyui-datebox" style="width:100px;height:20px;" />
                        </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"></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" onkeyup="cek_amount(this.value)" class="easyui-validatebox currency" style="width:100px;height:18px" required="required" />
						<input name="txt_amount" id="txt_amount" type="hidden" />
						<!--<a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-calculator',size:'small'" onClick="">-->
					  </td>
					  <td valign="top" align="left">&nbsp;</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" iconCls="icon-save" id="save_data">Save</a> 								
                         <a href="javascript:void(0)" class="easyui-linkbutton form-button" iconCls="icon-print" onclick="" disabled>Preview & Print</a>   
                         <a href="javascript:void(0)" class="easyui-linkbutton form-button" iconCls="icon-cancel" onclick="location.reload()">Cancel</a>	
		
					</td>
				 </tr>
			</table>				
		</div>
</div>

<script type="text/javascript">	
$(document).ready(function(){
        $('#txt_piutang_no').val('<?php echo $piutang_karyawan; ?>');
        $('#txt_payment_date').datebox({
            onChange:function(){
                url             = base_url + 'activities/piutang_karyawan/get_piutang_karyawan_number';                
                var Piutang_karyawan_date   = $('#txt_payment_date').datebox('getValue');
                
                $.post(url, {Piutang_karyawan_date:Piutang_karyawan_date}, function(result){
                    if (result.status === true){
                        $('#txt_piutang_no').val(result.number);
                    } 
                },'json');
            }
        });        
    });
	
$('#cmb_from_company').combogrid({
	onSelect: function(rowIndex, rowData){	
		var ComCode = rowData.BranchCode;
		$('#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}
			]],
			onSelect: function(){
				$('#txt_rekening_karyawan').val('');
			}
		});
	}
});

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

$("#save_data").click(function() { 
	var total = $("#txt_amount").val();	
	
	if(total < 1){
		$.messager.alert('Unseccessfull','Transaksi Belum Lengkap','error');
		return false;
	}
	else {
	    //$("#fm_payment_karyawan").submit();
		//$('#dtg_payment_history').edatagrid('reload');
		//save_payment('<?php echo"$menu_link"; ?>', '#fm_payment_karyawan','','#dtg_payment_history');
		save_transaction('<?php echo"$menu_link"; ?>', '#fm_piutang_karyawan','1');
		
	}
}); 
 
</script>