<?php 
session_start();
require_once("../../includes/display_internal_user_dryout.inc.php");
require_once("../../includes/functions_internal_user_dryout.inc.php");
$obj = new data();
$connect = $obj->funConnect();
$display = new display();
$display->logout_iu();
if (@$_REQUEST['action'] == 'submit')
 {
 	$msg = $obj->insertGenericFinancesDetails();
	header('Location:./generic_finances_list.php?msg='.$msg);
 }
$pagename = basename($_SERVER['PHP_SELF']);


if(isset($_POST['vendorid'])){

	$vendor_id=$_POST['vendorid'];
	// $change_year_query=mysql_query("UPDATE freight_cost_estimete_master SET F_YEAR='".$_POST['f_year']."'  WHERE  FCAID = '".$_POST['id']."'");
	$banking_detail_query=mysql_query("SELECT * from vendor_master_slave WHERE VENDORID='".$vendor_id."'");

	$banking_data=[];
	while ($b_row=mysql_fetch_assoc($banking_detail_query)) {
		array_push($banking_data,$b_row);
	}

	echo json_encode($banking_data);
	
	return;
}


	$creatorsarr = $obj->getUsersWithAuthority('GEN_CHK_CRETR');
	$approverarr1 = $obj->getUsersWithAuthority('GEN_CHK_APP_1');
	$approverarr2 = $obj->getUsersWithAuthority('GEN_CHK_APP_2');
	
	$creator = $obj->getUserAuthority($_SESSION['uid'], 'GEN_CHK_CRETR');
	$approver1 = $obj->getUserAuthority($_SESSION['uid'], 'GEN_CHK_APP_1');
	$approver2 = $obj->getUserAuthority($_SESSION['uid'], 'GEN_CHK_APP_2');

?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title><?php $display->title(); ?></title>
<?php $display->favicon(); ?>
<meta content='width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no' name='viewport'>
<?php $display->css(); ?>
<!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
  <script src="../js/html5shiv.js"></script>
  <script src="../js/respond.min.js"></script>
<![endif]-->
<style>
.animated {
				vertical-align: top; 
				transition: height 0.2s;
				-webkit-transition: height 0.2s; 
				-moz-transition: height 0.2s; 
			}

form.cmxform label.error, label.error {
		/* remove the next line when you have trouble in IE6 with labels in list */
		font-family:Verdana, Arial, Helvetica, sans-serif;
		font-size:10px;
		color: red;
		font-style:normal;
		font-weight:lighter;
		margin:5px;
		vertical-align:top;
		}
</style>
</head>
    <body class="skin-blue fixed">
        <!-- header logo: style can be found in header.less -->
        <?php $display->header_tag(); ?>
		<div class="wrapper row-offcanvas row-offcanvas-left">
            <?php $display->leftmenu(21); ?>
			<aside class="right-side">                
                <!-- Content Header (Page header) -->
                 <section class="content-header">
                    <h1>
                        <i class="fa fa-book"></i>&nbsp;Generic Finances&nbsp;&nbsp;&nbsp;&nbsp;<small><div class="headline text-center" id="time" style="color:#000; font-weight:bold; font-size:12px;"></div></small>
                    </h1>
                    <ol class="breadcrumb">
                        <li><a href="../"><i class="fa fa-home"></i> Home</a></li>
                        <li class="active">Generic Finances</li>
                    </ol>
                </section>

                <!-- Main content -->
                <section class="content invoice">
				<!--   content put here..................-->
				<div align="right"><a href="generic_finances_list.php"><button class="btn btn-info btn-flat">Back</button></a></div>
				<div style="height:10px;">&nbsp;</div>
				<form role="form" name="frm1" id="frm1" enctype="multipart/form-data" action="<?php echo $pagename;?>" method="post">			
				<div class="row type_detail">
							<div class="col-sm-3 ">

							<strong>Type  :</strong>
								<address>
								   <select  name="type" class="select form-control" id="type" >
											<option value="">Select Type</option>
											<option value="invoice">Invoice</option>
											<option value="payment">Payment</option>
											
									</select>
								</address>
							</div>
				</div>
					<div class="row invoice-info">
							<div class="col-sm-3 invoice-col">
								<strong>Invoicing Company  :</strong>
								<address>
								   <select  name="selFromOwner" class="select form-control" id="selFromOwner">
										<?php 
										$obj->getVendorListNewForCOA(11);
										?>
									</select>
								</address>
							</div><!-- /.col -->   
							<div class="col-sm-3 invoice-col">
								 <strong>Contract Type :</strong>
								<address>
								   <select  name="selContractType" class="select form-control" id="selContractType">
										<?php 
										$obj->getCOASpotTCList();
										?>
									</select>
								</address>
							</div><!-- /.col -->                  
							<div class="col-sm-3 invoice-col">
								 <strong>To :</strong>
								<address>
								   <select  name="selVendor" class="select form-control" id="selVendor" onchange="BankingDetails(this)">
										<?php 
										// $obj->getVendorListNewForCOA('7,11,10');


										$sql = "select CODE, NAME,VENDORID from vendor_master where STATUS=1  and MCOMPANYID='".$_SESSION['company']."' order by NAME ";


										$result 		= mysql_query($sql) or die($sql);
										echo '<option value = "" >---Select from list---</option>';
										@$selVendor = @$_REQUEST['selVendor'];
										while($rows = mysql_fetch_assoc($result))
											{
											$key = $rows['CODE'];
											$vendorid = $rows['VENDORID'];
											$value = addslashes($rows['NAME'])." ( ".$rows['CODE']." )";
											echo '<option value="'.$key.'" data-vendorid="'.$vendorid.'"';
										
											if($key == @$selVendor){ echo ' selected';}
											echo '>'.$value.'</option>';
											}
										?>
									</select>
								</address>
							</div><!-- /.col -->
							<div class="col-sm-3 invoice-col">
								<strong>Contract Details</strong>
								<address>
								   <textarea name="txtContractDetails" id="txtContractDetails" class="form-control areasize" rows="3" placeholder="Description"></textarea>
								</address>
							</div><!-- /.col -->
						</div>
					    
                        <div class="row invoice-info">
						   <div class="col-sm-6 invoice-col">
                               <div class="table-responsive">
                                    <table class="table">
                                        <tbody>
										<tr>
                                            <th style="width:50%;padding-top:15px;padding-bottom:15px;">Business Type :</th>
                                            <td><select  name="selBType" class="form-control" id="selBType"><?php $obj->getBusinessTypeList1($selBType);?></select></td>
                                        </tr>
                                        <tr>
                                            <th style="width:50%;padding-top:15px;padding-bottom:15px;">Invoice Type :</th>
                                            <td><select  name="selIType" class="select form-control" id="selIType"><?php $obj->getInvoiceType();?></select></td>
                                        </tr>
                                        <tr>
                                            <th style="width:50%;padding-top:15px;padding-bottom:15px;">Attn :</th>
                                            <td><input type="text" name="txtAttenName" id="txtAttenName" class="form-control"  placeholder="Attn" autocomplete="off" value=""/></td>
                                        </tr>
                                        <tr>
                                            <th style="padding-top:15px;padding-bottom:15px;">Invoice Number :</th>
                                            <td>
											
                                            <input type="text" name="txtInvoiceNo" id="txtInvoiceNo" class="form-control" placeholder="Invoice No." value=""/>
                                        </tr>
                                        <tr>
                                            <th style="padding-top:15px;padding-bottom:15px;">Invoice Date :</th>
                                            <td><input type="text" name="txtInvoiceDate" id="txtInvoiceDate"  autocomplete="off" placeholder="dd-mm-yyyy" class="form-control" value=""/></td>
                                        </tr>
                                        <tr>
                                            <th style="padding-top:15px;padding-bottom:15px;">Due Date :</th>
                                            <td><input type="text" name="txtDueDate" id="txtDueDate" class="form-control datepicker"  placeholder="dd-mm-yyyy" autocomplete="off" value=""/></td>
                                        </tr>
                                       
                                        <tr>
                                            <th style="width:50%;padding-top:15px;padding-bottom:15px;">Working Currency :</th>
                                            <td><select  name="selExchangeCurrency" class="select form-control" id="selExchangeCurrency"><?php $obj->getCurrencyList();?></select></td>
                                        </tr>
                                        <tr>
                                            <th style="padding-top:15px;padding-bottom:15px;">Payment Terms :</th>
                                            <td><input type="text" name="txtPaymentTerms" id="txtPaymentTerms" class="form-control"  placeholder="Payment Terms" autocomplete="off" value=""/></td>
                                        </tr>
                                        <tr>
                                            <th style="padding-top:15px;padding-bottom:15px;">Description :</th>
                                            <td><textarea name="txtDesc" id="txtDesc" class="form-control areasize" rows="3" placeholder="Description"></textarea></td>
                                        </tr>
                                        <tr>
                                            <th style="padding-top:15px;padding-bottom:15px;">Banking Details :</th>
                                            <td><select  name="selNOB" class="select form-control" id="selNOB" onChange="getBankingDetailsData()"><?php $obj->getBankingDetails();?></select></td>
                                       
                                        </tr>



										<tr>
											<td><strong>Documents:</strong></td>
											<td>
											<div class="btn btn-success btn-file btn-flat" data-toggle="tooltip">
											<i class="fa fa-paperclip"></i> Attachment
											<input type="file" class="form-control" multiple name="attach_file[]" id="attach_file" title="" data-widget="Attachment" data-toggle="tooltip" data-original-title="Attachment"/>
											</div>
											<br/>
											<?php if($rows['UPLOAD'] != '')
											{ 
												$fileid = explode(",",$rows['UPLOAD']); 
												$filename = explode(",",$rows['UPLOAD_NAME']); ?>	
											   <?php
												$j =1;
												for($i=0;$i<sizeof($fileid);$i++)
												{
												?>
												<tr id="row_file_<?php echo $j;?>">
													<td width="40%" align="left" class="input-text"  valign="top"><a href="../../attachment/<?php echo $fileid[$i]; ?>" target="_blank" style="color:blue;" data-toggle="tooltip" data-original-title="<?php echo $filename[$i];?>"><i class="fa fa-external-link"></i>&nbsp;&nbsp;<?php echo $filename[$i];?></a>
													<input type="hidden" name="file_<?php echo $j;?>" id="file_<?php echo $j;?>" value="<?php echo $fileid[$i]; ?>" />
													<input type="hidden" name="name_<?php echo $j;?>" id="name_<?php echo $j;?>" value="<?php echo $filename[$i]; ?>" />
													</td>
													<td ><a href="#1" onClick="Del_Upload(<?php echo $j;?>);"><i class="fa fa-times " style="color:red;"></i></a></td>
												</tr>
											   <?php $j++;}?>
									   <?php }?>
											</td>
										</tr>
                                     </tbody>
                                     <tbody id="bankingrow" style="display:none;">
                                        <tr>
											<td>Address</td>
											<td><span id="span_1_0"></span></td>
										</tr>
										<tr>
											<td>Beneficiary A/C No.</td>
											<td><span id="span_1_1"></span></td>
										</tr>
										<tr>
											<td>Beneficiary Bank</td>
											<td><span id="span_1_2"></span></td>
										</tr>
										<tr>
											<td>Beneficiary Bank Address</td>
											<td><span id="span_1_3"></span></td>
										</tr>
										<tr>
											<td>Beneficiary Bank Swift Code</td>
											<td><span id="span_1_4"></span></td>
										</tr>
										<tr>
											<td>IBAN No.</td>
											<td><span id="span_1_5"></span></td>
										</tr>
										<tr>
											<td>FED ABA</td>
											<td><span id="span_1_6"></span></td>
										</tr>
										<tr>
											<td colspan="4" style="background-color:grey; color:white;">CORRESPONDENT DETAILS</td>
										</tr>
										<tr>
											<td>Correspondent Bank Name</td>
											<td><span id="span_1_7"></span></td>
										</tr>
										
                                        <tr>
                                            <td>Correspondent Bank Address</td>
											<td><span id="span_1_9"></span></td>
										</tr>
                                        <tr>
											<td>Account Number</td>
											<td><span id="span_1_10"></span></td>
										</tr>
                                        <tr>
											<td>Swift Code</td>
											<td><span id="span_1_8"></span></td>
										</tr>
                                     </tbody>
                                   </table>
                               </div>
						   </div><!-- /.col -->
						   <div class="col-sm-6 invoice-col">
							   <div class="table-responsive">
                                    <table class="table">
                                        <tbody>
                                        
                                        <tr>
                                            <th>Description</th>
											<td><textarea name="txtAmountDesc" id="txtAmountDesc" class="form-control areasize" rows="3" placeholder="Description"></textarea></td>
                                            <td><input type="text" name="txtMainAmount" id="txtMainAmount" class="form-control numeric" onKeyUp="getAmountThereOff();"/ autocomplete="off" value=""></td>
                                        </tr>
                                        
                                        
                                        <tr>
                                            <th style="width:50%;padding-top:15px;padding-bottom:15px;" colspan="3">Other Add</th>
                                        </tr>
                                     </tbody>
									 <tbody id="tblAdd">
                                           <tr id="add_Row_1">
										       <td align="center"><a href="#pr1" onClick="removeAddRow(1);"><i class="fa fa-times" style="color:red;"></i></a></td>
										       <td><textarea class="form-control areasize" name="txtAddDes_1" id="txtAddDes_1" rows="2" placeholder="Description..."></textarea></td>
										       <td><input type="text" name="txtAddDesAmt_1" id="txtAddDesAmt_1" class="form-control numeric"  placeholder="Amount" autocomplete="off" value="" onKeyUp="getAmountThereOff();"/></td>
										   </tr>
                                       </tbody>
                                       <tbody>
                                           <tr>
                                               <td align="left" colspan="3"><button type="button" class="btn btn-primary btn-flat" onClick="AddNewAddRow();">Add</button><input type="hidden" name="txtAddID" id="txtAddID" value="1"/></td>
                                           </tr>
                                           
                                           <tr>
                                               <th colspan="3">Other Less</th>
                                           </tr>
                                       </tbody>
                                       <tbody id="tblSub">
											<tr id="Sub_Row_1">
											   <td align="center"><a href="#pr1" onClick="removeSubRow(1);"><i class="fa fa-times" style="color:red;"></i></a></td>
											   <td><textarea class="form-control areasize" name="txtSubDes_1" id="txtSubDes_1" rows="2" placeholder="Description..."></textarea></td>
											   <td><input type="text" name="txtSubDesAmt_1" id="txtSubDesAmt_1" class="form-control numeric"  placeholder="Amount" autocomplete="off" value="" onKeyUp="getAmountThereOff();"/></td>
											</tr>
                                       </tbody>
                                       <tbody>
                                           <tr>
                                               <td align="left" colspan="3"><button type="button" class="btn btn-primary btn-flat" onClick="SubNewSubRow();">Add</button><input type="hidden" name="txtSubID" id="txtSubID" value="1"/></td>
                                           </tr>
                                           <tr>
                                                <td colspan="2"><strong>Total Amount Invoiced</strong></td>
                                                
                                                <td><input type="text"  name="txtNetAmtPayable" id="txtNetAmtPayable" class="form-control" readonly value="" /></td>
                                            </tr>
                                            
                                       </tbody>
                                   </table>
                               </div>
						   </div><!-- /.col -->
						</div>



						<div class="row" style="padding-right:10px; padding-left:10px; margin-bottom:10px;">
							 <div class="col-xs-12" margin-bottom:30px;>
							      <h4>
								
									
									<legend><h3 style="padding: 0 0 0 10px">Invoice</h3></legend>

									<?php if($obj->getFun25()=='payment_hold'){?>
									<label style="padding: 0 0 0 11px;">Invoice Hold</label>&nbsp;&nbsp;<input checked type="radio" id="delivery" name="payment_status" value="payment_hold" />
									<?php }else{?>
										<label style="padding: 0 0 0 11px;">Invoice Hold</label>&nbsp;&nbsp;<input type="radio" id="delivery" name="payment_status" value="payment_hold" />

										<?php }if($obj->getFun25()=='payment_payable'){?>
									<label style="padding: 0 0 0 11px;">Invoice Payable</label>&nbsp;&nbsp;<input checked type="radio" id="delivery" name="payment_status" value="payment_payable" />
									<?php }else{?>
										<label style="padding: 0 0 0 11px;">Invoice Payable</label>&nbsp;&nbsp;&nbsp;<input type="radio" id="delivery" name="payment_status" value="payment_payable" />
										<?php } ?>
										<hr>
								
									</h4>
							 </div>

						</div>

						

						<div class="row invoice-info">
							       <div class="col-sm-4 invoice-col">
								       Level 1 Approver
								   </div>
								   <div class="col-sm-8 invoice-col">
								   <?php
								  
									
										$fieldname = 'GEN_CHK_APP_1';
									?>
								    
									<select data-placeholder="Choose Approver..." class="input-text chzn-select" style="width:300px;" multiple name="selApprovers[]" id="selApprovers"><?php $obj->getApproverListBasedOnApprovalMatrix($fieldname, $rows['APPROVERS']);?></select>
								   </div>
							   </div>


							   <input type="hidden" name="txtCRMFILE" id="txtCRMFILE" value="" />
					        <input type="hidden" name="txtCRMNAME" id="txtCRMNAME" value="" />


                    



                    
				
				        <div class="box-footer" align="right">
                            <input type="hidden" id="action" name="action" value="submit" />
                            <input type="hidden" name="txtStatus" id="txtStatus" value="0"/>
							<?php if(($rec==0 && $creator==1) || (($rows['STATUS']==0 || $rows['STATUS']==2) && $creator==1)){
					           if(empty($approverarr1) && empty($approverarr2)){$status = 5;}
							   else if(empty($approverarr1) && !empty($approverarr2)){$status = 4;}
							   else{$status = 1;}	
					  ?>	
							<button type="submit" class="btn btn-primary btn-flat" onClick="return getValidate(0);">Submit to edit</button>&nbsp;&nbsp;
							<button type="submit" class="btn btn-warning btn-flat" onClick="return getValidate(<?=$status;?>);">Send for Approval</button>
                      <?php }else if($rec>0 && ($rows['STATUS']==1 || $rows['STATUS']==4) && $approver1 == 1){
					             if(empty($approverarr2)){$status = 5;}
							     else{$status = 3;}
						   ?>
						    <button type="submit" class="btn btn-primary btn-flat" onClick="return getValidate(2);">Send for Review</button>&nbsp;&nbsp;
							<button type="submit" class="btn btn-warning btn-flat" onClick="return getValidate(<?=$status;?>);">Submit & Approve</button>
					  <?php }else if($rec>0 && $rows['STATUS']==3 && $approver2 == 1){
					           if(empty($approverarr1)){$status = 2;}
							   else{$status = 4;} 
					  ?>
					        <button type="submit" class="btn btn-primary btn-flat" onClick="return getValidate(<?=$status;?>);">Send for Review</button>&nbsp;&nbsp;
					        <button type="submit" class="btn btn-warning btn-flat" onClick="return getValidate(5);">Submit & Approve</button>
					  <?php }?>
                            
						</div>
				</form>
				
				<!--   content ends here..................-->
                </section><!-- /.content -->
            </aside><!-- /.right-side -->
			
        </div><!-- ./wrapper -->
<?php $display->footer(); ?>
<?php $display->js(); ?>
<link href="../../css/jquery.alerts.css" rel="stylesheet" type="text/css" />
<script src='../../js/jquery.autosize.js'></script>
<script language="JavaScript" type="text/javascript" src="../../js/jquery.alerts.js"></script>
<script src="../../js/timer.js" type="text/javascript"></script>
<link href="../../css/datepicker/datepicker.css" rel="stylesheet" type="text/css" />

<link type="text/css" href="../../css/chosen.css" rel="stylesheet" />
<script src="../../js/chosen.jquery.js" type="text/javascript"></script>

<script src="../../js/bootstrap-datepicker.js" type="text/javascript"></script>
<script language="JavaScript" type="text/javascript" src="../../js/jquery.numeric.js"></script>
<script language="JavaScript" type="text/javascript" src="../../js/jquery.calculation-min.js"></script>
<link href="../../css/datetimepicker/bootstrap-datetimepicker.css" rel="stylesheet" type="text/css" />
<script src="../../js/plugins/datetimepicker/bootstrap-datetimepicker.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function(){ 

	$("#selApprovers").chosen();


$('#txtDate').datepicker({
    format: 'dd-mm-yyyy'
});
$(".numeric").numeric();
$(".areasize").autosize({append: "\n"});
$("#selBType").val(<?=$_SESSION['selBType'];?>);
$('#txtInvoiceDate,#txtDueDate,#txtExchangeDate').datepicker({
	format: 'dd-mm-yyyy',
	autoclose:true
});

$("#frm1").validate({
	rules: {
	selFromOwner: {required: true},
	selVendor: {required: true},
	txtContractDetails: {required: true},
	txtAmountDesc: {required: true},
	txtMainAmount: {required: true},
	txtInvoiceDate: {required: true},
	selIType: {required: true},
	txtInvoiceNo: {required: true},
	txtDate: {required: true},
	txtDueDate:{required: true},
	txtExchangeRate:{required: true},
	selExchangeCurrency:{required: true},
	txtPaymentTerms:{required: true},
	selNOB:{required: true},
	txtDesc:{required: true}
	},
messages: {
	selIType: {required: "*"},
	txtInvoiceNo: {required: true},
	txtDate: {required: true},
	txtDueDate:{required: "*"},
	txtExchangeRate:{required: "*"},
	selExchangeCurrency:{required: "*"},
	txtPaymentTerms:{required: "*"},
	selNOB:{required: "*"}
	},
submitHandler: function(form)  {
		if($('#txtStatus').val() == 0)
		{
			jAlert('<b style="font-size:25px;">Please wait . . .</b><br><br><img src="../../img/loading.gif"  />', 'Alert');
			$("#popup_container").css({"background": "rgba(255,255,255,0.1)","border": "10px solid rgba(255,255,255,0.1)","width": "100%"});
			$("#popup_content").css({"background":"none","text-align":"center"});
			$("#popup_ok,#popup_title").hide();  
			form.submit();
		}
		else
		{
			jConfirm('Are you sure you want to Submit?', 'Confirmation', function(r) {
				if(r)
				{
					jAlert('<b style="font-size:25px;">Please wait . . .</b><br><br><img src="../../img/loading.gif"  />', 'Alert');
					$("#popup_container").css({"background": "rgba(255,255,255,0.1)","border": "10px solid rgba(255,255,255,0.1)","width": "100%"});
					$("#popup_content").css({"background":"none","text-align":"center"});
					$("#popup_ok,#popup_title").hide();  
					form.submit();
				}
			});
		}
	}
});

});

function AddNewAddRow()
{
	var id = $("#txtAddID").val();
	if($("#txtAddDes_"+id).val() != "" && $("#txtAddDesAmt_"+id).val() != "")
	{
		id = (id - 1) + 2;
		$('<tr id="add_Row_'+id+'"><td align="center"><a href="#pr1" onClick="removeAddRow(1);"><i class="fa fa-times" style="color:red;"></i></a></td><td><textarea class="form-control areasize" name="txtAddDes_'+id+'" id="txtAddDes_'+id+'" rows="2" placeholder="Description..."></textarea></td><td><input type="text" name="txtAddDesAmt_'+id+'" id="txtAddDesAmt_'+id+'" class="form-control"  placeholder="Amount" autocomplete="off" value="" onKeyUp="getAmountThereOff();"/></td></tr>').appendTo("#tblAdd");
		$("#txtAddID").val(id);
		$("[id^=txtAddDesAmt_]").numeric();	
	}
}


function removeAddRow(var1)
{
		jConfirm('Are you sure you want to remove this entry permanently ?', 'Confirmation', function(r) {
			if(r){
					$("#add_Row_"+var1).remove();
					getAmountThereOff();
				 }
			else{return false;}
			});
}



function SubNewSubRow()
{
	var id = $("#txtSubID").val();
	if($("#txtSubDes_"+id).val() != "" && $("#txtSubDesAmt_"+id).val() != "")
	{
		id = (id - 1) + 2;
		$('<tr id="Sub_Row_'+id+'"><td align="center"><a href="#pr1" onClick="removeSubRow(1);"><i class="fa fa-times" style="color:red;"></i></a></td><td><textarea class="form-control areasize" name="txtSubDes_'+id+'" id="txtSubDes_'+id+'" rows="2" placeholder="Description..."></textarea></td><td><input type="text" name="txtSubDesAmt_'+id+'" id="txtSubDesAmt_'+id+'" class="form-control"  placeholder="Amount" autocomplete="off" value="" onKeyUp="getAmountThereOff();"/></td></tr>').appendTo("#tblSub");
		$("#txtSubID").val(id);
		$("[id^=txtSubDesAmt_]").numeric();	
	}
}


function removeSubRow(var1)
{
	jConfirm('Are you sure you want to remove this entry permanently ?', 'Confirmation', function(r) {
		if(r){
				$("#Sub_Row_"+var1).remove();
				getAmountThereOff();
			 }
		else{return false;}
		});
}

function getBankingDetailsData()
{   
    var1 = $('#selNOB').val();
	if($("#selNOB").val()!="")
	{
		$.post("options.php?id=43",{selNOB:""+$("#selNOB").val()+""}, function(html) {
			if(html!="")
			{
				$("#bankingrow").show();
				var res = html.split("@@@@");
				$('#span_1_0').text(res[0]);
				$('#span_1_1').text(res[1]);
				$('#span_1_2').text(res[2]);
				$('#span_1_3').text(res[3]);
				$('#span_1_4').text(res[4]);
				$('#span_1_5').text(res[5]);
				$('#span_1_6').text(res[6]);
				$('#span_1_7').text(res[7]);
				$('#span_1_8').text(res[8]);
				$('#span_1_9').text(res[9]);
				$('#span_1_10').text(res[10]);
			}
		});
	}
	else
	{
	    $("#bankingrow").hide();	
		$('#span_1_0').text("");
	    $('#span_1_1').text("");
		$('#span_1_2').text("");
		$('#span_1_3').text("");
		$('#span_1_4').text("");
		$('#span_1_5').text("");
		$('#span_1_6').text("");
		$('#span_1_7').text("");
		$('#span_1_8').text("");
		$('#span_1_9').text("");
		$('#span_1_10').text("");
	}
}



function getAmountThereOff()
{ 
    if($('#txtMainAmount').val()=="" || isNaN($('#txtMainAmount').val())){var final_freight = 0;}else{var final_freight = $("#txtMainAmount").val();}
	
    var add1 = parseFloat($("[id^=txtAddDesAmt_]").sum());
	if(isNaN(add1)){add1 = 0;}
	var sub1 = parseFloat($("[id^=txtSubDesAmt_]").sum());
	if(isNaN(sub1)){sub1 = 0;}	
	
	var var2 = parseFloat(final_freight) + parseFloat(add1) - parseFloat(sub1);
	
	if(isNaN(var2)){var2 = 0;}
	$('#txtNetAmtPayable').val(parseFloat(var2).toFixed(2));
	
}

function getValidate(var1)
{
	$('#txtStatus').val(var1);



	
					var file_temp_name = $("[id^=file_]").map(function () {return this.value;}).get().join(",");
					$('#txtCRMFILE').val(file_temp_name);
					var file_actual_name = $("[id^=name_]").map(function () {return this.value;}).get().join(",");
					$('#txtCRMNAME').val(file_actual_name);



	if($('#txtStatus').val()==1)
	{   
	    if($('#selApprovers').val()==null || $('#selApprovers').val()=='')
		{
		    jAlert('Please select Level 1 Approvers first.', 'Alert');
			return false;
		}
		else
		{
		    return true;
		}
	}

}

function BankingDetails(elx)
{
	if($('#type').val()=='payment'){


		let vendorid=$(elx).find(':selected').data('vendorid');
						$.ajax({
                       
					   type: "POST",
					   data: { vendorid: vendorid },
					   dataType: "json",
					   
					   success: function (result) {
						   // when call is sucessfull

							// if(result.length>0){
								$('#selNOB').empty();

								$('#selNOB').attr('onchange','getVendorBankingDetail(this)');

								$.each(result, function(k,v){

									console.log(v);

									$('#selNOB').html('<option value="">Select Bank</option><option data-name="'+v.NAME+'" data-accno="'+v.ACCOUNTNO+'" data-address="'+v.ADDRESS+'" data-bankadd="'+v.BANK_ADDRESS+'" data-swiftcode="'+v.SWIFT_CODE+'" value="'+v.SLAVEID+'">'+v.BANK_NAME+'</option>')
								});

								// <option value="2">BAINBRIDGE NAVIGATION DMCC - EMIRATES NBD - USD ACCOUNT</option>
							// }

						
							//   if(result){
							//    $(clx).parent().prev().text(f_year);
							//   }
						   },
						   error: function (err) {
						   // check the err for error details
						  
							   
						   }
				   });
		
		
	}
}

// <tbody id="bankingrow" style="">
//                                         <tr>
// 											<td>Address</td>
// 											<td><span id="span_1_0">OFFICE NO: 405, LEVEL 4, GOLDCREST EXECUTIVE TOWER,  CLUSTER C, JUMEIRAH LAKE TOWERS, DUBAI, UAE. P.O . BOX 238605 </span></td>
// 										</tr>
// 										<tr>
// 											<td>Beneficiary A/C No.</td>
// 											<td><span id="span_1_1"> </span></td>
// 										</tr>
// 										<tr>
// 											<td>Beneficiary Bank</td>
// 											<td><span id="span_1_2">EMIRATES NBD - USD ACCOUNT </span></td>
// 										</tr>
// 										<tr>
// 											<td>Beneficiary Bank Address</td>
// 											<td><span id="span_1_3">GROUND FLOOR, SAEED TOWER, SHEIKH ZAYED RD, DUBAI P.O. Box - 777 </span></td>
// 										</tr>
// 										<tr>
// 											<td>Beneficiary Bank Swift Code</td>
// 											<td><span id="span_1_4">EBILAEADXXX </span></td>
// 										</tr>
// 										<tr>
// 											<td>IBAN No.</td>
// 											<td><span id="span_1_5">AE950260001025624994102 </span></td>
// 										</tr>
// 										<tr>
// 											<td>FED ABA</td>
// 											<td><span id="span_1_6"> </span></td>
// 										</tr>
// 										<tr>
// 											<td colspan="4" style="background-color:grey; color:white;">CORRESPONDENT DETAILS</td>
// 										</tr>
// 										<tr>
// 											<td>Correspondent Bank Name</td>
// 											<td><span id="span_1_7"> </span></td>
// 										</tr>
										
//                                         <tr>
//                                             <td>Correspondent Bank Address</td>
// 											<td><span id="span_1_9"> </span></td>
// 										</tr>
//                                         <tr>
// 											<td>Account Number</td>
// 											<td><span id="span_1_10"> </span></td>
// 										</tr>
//                                         <tr>
// 											<td>Swift Code</td>
// 											<td><span id="span_1_8"> </span></td>
// 										</tr>
//                                      </tbody>
function getVendorBankingDetail(elx)
{
	let selected_bank=$(elx).find(':selected');
	
				$('#span_1_0').text($(selected_bank).data('address'));
				$('#span_1_1').text($(selected_bank).data('accno'));
				$('#span_1_2').text($(selected_bank).text());
				$('#span_1_3').text($(selected_bank).data('bankadd'));
				$('#span_1_4').text($(selected_bank).data('swiftcode'));
			
				$('#bankingrow').show();


}
// <option data-name="ABU DHABI MARINE OPERATIONS AND SERVICES COMPANY LLC" data-accno="1011003993215021" data-address="PO Box 61, Abu Dhabi, U.A.E" data-bankadd="KHALIFA STREET, ABU DHABI"  data-swiftcode="NBADAEAA" value="FIRST ABU DHABI BANK">FIRST ABU DHABI BANK</option>
</script>
    </body>
</html>