function insertRequestDetails()
{

	$connect 			= $this->funConnect();	
	$id 				= explode(",",$_REQUEST['id']);
	$comid 			    = $id['4'];
	//print_r($id);
	$selAType 			= addslashes(trim($_REQUEST['selAType']));
	$txtAccNO	 		= addslashes(trim($_REQUEST['txtAccNO']));
	$txtDate	 		= date("Y-m-d",strtotime($_REQUEST['txtDate']));
	$txtCP_Date	 		= date("Y-m-d",strtotime($_REQUEST['txtCP_Date']));
	$txtRemarks	 		= addslashes(trim($_REQUEST['txtRemarks']));
	
	$txtTtl_Outs	 	= addslashes(trim($_REQUEST['txtTtl_Outs']));
	$txtBal_Outs	 	= addslashes(trim($_REQUEST['txtBal_Outs']));
	
	$txtROP	 			= addslashes(trim($_REQUEST['txtROP_3']));
	
	$txtROP_1	 		= addslashes(trim($_REQUEST['txtROP_1']));
	
	$txtPaymentID	 	= addslashes(trim($_REQUEST['txtPaymentID']));
	$txtStatus	 		= addslashes(trim($_REQUEST['txtStatus']));
	$txtVendor	 		= addslashes(trim($_REQUEST['txtVendor']));
	$txtCID	 			= addslashes(trim($_REQUEST['txtCID']));
	$txtV_I_Amt	 		= addslashes(trim($_REQUEST['txtV_I_Amt']));
	
	$txtExchangeRate	= addslashes(trim($_REQUEST['txtExchangeRate']));
	$txtExchangeDate	= date("Y-m-d",strtotime($_REQUEST['txtExchangeDate']));
	$selExchangeCurrency= addslashes(trim($_REQUEST['selExchangeCurrency']));
	
	$selBankingID       = addslashes(trim($_REQUEST['selBankingID']));
	
	$txtI_Date	 		= date("Y-m-d",strtotime($_REQUEST['txtI_Date']));
	$txtNET             = $_REQUEST['txtNET'];
	
	
	$txtCRMFILE			= addslashes(trim($_REQUEST['txtCRMFILE']));
	$txtCRMNAME			= addslashes(trim($_REQUEST['txtCRMNAME']));
	
	$upload = $this->getUpload($_FILES['attach_file']);
	$name = $this->getUploadName($_FILES['attach_file']);
	$upload = implode(',',$upload);
	$name = implode(',',$name);
	if($txtCRMFILE != '' && $upload != ''){ $upload1 = $txtCRMFILE.','.$upload;}
	else if($txtCRMFILE == '' && $upload != ''){ $upload1 = $upload;}
	else if($txtCRMFILE != '' && $upload == ''){ $upload1 = $txtCRMFILE;}
	
	if($txtCRMNAME != '' && $name != ''){ $name1 = $txtCRMNAME.','.$name;}
	else if($txtCRMNAME == '' && $name != ''){ $name1 = $name;}
	else if($txtCRMNAME != '' && $name == ''){ $name1 = $txtCRMNAME;}
	
	
	$msg = 0;
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
	
	
	$selApprovers             = $_REQUEST['selApprovers'];
	$invoiceidd = '';$creatorloginid = '';
	
	if($txtPaymentID=='')
	{
		$sql = "insert into request_master (COMID, MODULEID, MCOMPANYID, LOGIN, NAME, NAME_ID, GRADEID, VENDOR, PORT, ACCOUNT_TYPE, PAYMENT_NO, DATE, REMARKS, TTL_OUTSTANDINGS, BAL_OUTSTANDINGS, REQ_TO_PAY, STATUS, CP_DATE, REQUESTED, VESSELID, R_TYPE, P_TYPE, INVOICE_AMT, INVOICE_DATE, NET_AMT, UPLOAD, UPLOAD_NAME, APPROVERS, CREATOR, EXCHANGE_RATE, EXCHANGE_DATE, EXCHANGE_CURRENCY, BANKING_DETAILS,VENDOR_SLAVEID,PAYMENT_STATUS) values ('".$comid."', '".$_SESSION['moduleid']."', '".$_SESSION['company']."', 'INTERNAL_USER', '".$id[1]."', '".$id[0]."', '".$_REQUEST['grade_id_test']."', '".$txtVendor."', '".$id[6]."', '".$selAType."', '".$txtAccNO."', '".$txtDate."', '".$txtRemarks."', '".$this->getCheckNullVal($txtTtl_Outs)."', '".$this->getCheckNullVal($txtBal_Outs)."', '".$this->getCheckNullVal($txtROP)."', '".$txtStatus."', '".$txtCP_Date."', '0', '".$this->getCompareEstimateData($comid,"VESSEL_IMO_ID")."', '".$this->getCheckNullVal($_REQUEST['rdoQty'])."', '".$this->getCheckNullVal($txtROP_1)."', '".$this->getCheckNullVal($txtV_I_Amt)."', '".$txtI_Date."', '".$this->getCheckNullVal($txtNET)."', '".$upload1."', '".$name1."', '".implode(',',$_REQUEST['selApprovers'])."', '".$_SESSION['uid']."', '".$this->getCheckNullVal($txtExchangeRate)."', '".$txtExchangeDate."', '".$selExchangeCurrency."', '".addslashes(trim($this->getVendorListNewData($txtVendor,"BANKING_DETAILS")))."', '".$selBankingID."', '".$_REQUEST['payment_status']."')";
		
		mysql_query($sql) or die($sql);
		mysql_query("commit");
		
		$sql1  = "select max(REQ_ID) as max from request_master";
		$res1  = mysql_query($sql1);
		$rows1 = mysql_fetch_assoc($res1);
		$invoiceidd = $rows1['max'];
		$creatorloginid =  $_SESSION['uid'];
		
		$txtAddID  = $_REQUEST['txtAddID'];
		for($i=1;$i<=$txtAddID;$i++)
		{
			$txtAddDes	 	  = addslashes(trim($_REQUEST['txtAddDes_'.$i]));
			$txtAddDesAmt	  = $this->getCheckNullVal($_REQUEST['txtAddDesAmt_'.$i]);
			$sql2 = "insert into request_master_slave (REQ_ID, DESCRIPTION, AMOUNT, IDENTIFY) values ('".$rows1['max']."', '".$txtAddDes."', '".$txtAddDesAmt."', 'ADD')";
			mysql_query($sql2);
		}
		
		$txtSubID  = $_REQUEST['txtSubID'];
		for($i=1;$i<=$txtSubID;$i++)
		{
			$txtSubDes	 	  = addslashes(trim($_REQUEST['txtSubDes_'.$i]));
			$txtSubDesAmt	  = $this->getCheckNullVal($_REQUEST['txtSubDesAmt_'.$i]);
			$sql2 = "insert into request_master_slave (REQ_ID, DESCRIPTION, AMOUNT, IDENTIFY) values ('".$rows1['max']."', '".$txtSubDes."', '".$txtSubDesAmt."', 'SUB')";
			mysql_query($sql2);
		}
		
		$this->saveRecentWork($selAType." ".$_REQUEST['name']."  Payment (".$txtAccNO.") Created Successfully.");

	}else
	{
	    $invoiceidd = $txtPaymentID;
		
		$sql_sel = "select APPROVERS, CREATOR from request_master where REQ_ID='".$txtPaymentID."'";
		$res_sel = mysql_query($sql_sel) or die($sql_sel);
		$rows_sel = mysql_fetch_assoc($res_sel);
		
		if($txtStatus ==0 || $txtStatus ==1)
		{
		    $approversel = implode(',',$_REQUEST['selApprovers']);
		}else
		{
		    $approversel = $rows_sel['APPROVERS'];
		}
		$creatorloginid = $rows_sel['CREATOR'];
		

		


		$sql = "update request_master set NAME='".$id[1]."', NAME_ID='".$id[0]."', GRADEID='".$_REQUEST['grade_id_test']."', VENDOR='".$txtVendor."', PORT='".$id[6]."', ACCOUNT_TYPE='".$selAType."', PAYMENT_NO='".$txtAccNO."', DATE='".$txtDate."', REMARKS='".$txtRemarks."', TTL_OUTSTANDINGS='".$this->getCheckNullVal($txtTtl_Outs)."', BAL_OUTSTANDINGS='".$this->getCheckNullVal($txtBal_Outs)."', REQ_TO_PAY='".$this->getCheckNullVal($txtROP)."', STATUS= '".$txtStatus."', CP_DATE='".$txtCP_Date."', REQUESTED='0', VESSELID='".$this->getCompareEstimateData($comid,"VESSEL_IMO_ID")."', R_TYPE='".$this->getCheckNullVal($_REQUEST['rdoQty'])."', P_TYPE='".$this->getCheckNullVal($txtROP_1)."', INVOICE_AMT='".$this->getCheckNullVal($txtV_I_Amt)."', INVOICE_DATE='".$txtI_Date."', NET_AMT='".$this->getCheckNullVal($txtNET)."', UPLOAD='".$upload1."', UPLOAD_NAME='".$name1."', APPROVERS='".$approversel."', EXCHANGE_RATE='".$this->getCheckNullVal($txtExchangeRate)."', EXCHANGE_DATE='".$txtExchangeDate."', EXCHANGE_CURRENCY='".$selExchangeCurrency."', BANKING_DETAILS='".addslashes(trim($this->getVendorListNewData($txtVendor,"BANKING_DETAILS")))."', VENDOR_SLAVEID='".$selBankingID."', PAYMENT_STATUS='".$_REQUEST['payment_status']."' where REQ_ID='".$txtPaymentID."'";
		mysql_query($sql) or die($sql);
		mysql_query("commit");
		
		$sql5 = "delete from request_master_slave where REQ_ID='".$txtPaymentID."'";
		mysql_query($sql5) or die($sql5);
		mysql_query("commit");
		
		
		$txtAddID  = $_REQUEST['txtAddID'];
		for($i=1;$i<=$txtAddID;$i++)
		{
			$txtAddDes	 	  = addslashes(trim($_REQUEST['txtAddDes_'.$i]));
			$txtAddDesAmt	  = $this->getCheckNullVal($_REQUEST['txtAddDesAmt_'.$i]);
			$sql2 = "insert into request_master_slave (REQ_ID, DESCRIPTION, AMOUNT, IDENTIFY) values ('".$txtPaymentID."', '".$txtAddDes."', '".$txtAddDesAmt."', 'ADD')";
			mysql_query($sql2);
		}
		
		$txtSubID  = $_REQUEST['txtSubID'];
		for($i=1;$i<=$txtSubID;$i++)
		{
			$txtSubDes	 	  = addslashes(trim($_REQUEST['txtSubDes_'.$i]));
			$txtSubDesAmt	  = $this->getCheckNullVal($_REQUEST['txtSubDesAmt_'.$i]);
			$sql2 = "insert into request_master_slave (REQ_ID, DESCRIPTION, AMOUNT, IDENTIFY) values ('".$txtPaymentID."', '".$txtSubDes."', '".$txtSubDesAmt."', 'SUB')";
			mysql_query($sql2);
		}
		
		$this->saveRecentWork($selAType." ".$_REQUEST['name']." Payment (".$txtAccNO.") Added/Updated Successfully.");
	}
	$this->inactiveUserAlerts('PAYMENT', $_SESSION['uid'], $invoiceidd);
	
	$creatorsarr =  ($creatorloginid!='' && $creatorloginid!=NULL)?array($creatorloginid):array();
	$approverarr1 = $_REQUEST['selApprovers'];
	
	if($id[1] == 'Load Port Costs' || $id[1] == 'Discharge Port Costs' || $id[1] == 'Transit Port Costs')
	{
		$portcost = 0;
		if($id[1] == 'Load Port Costs')
		{
			$portcost = $this->getFDA($comid,'LP',$id[2],$id['7']);
		}
		if($id[1] == 'Discharge Port Costs')
		{
			$portcost = $this->getFDA($comid,'DP',$id[2],$id['7']);
		}
		if($id[1] == 'Transit Port Costs')
		{
			$portcost = $this->getFDA($comid,'TP',$id[2],$id['7']);
		}
		if($portcost >0)
		{
			$approverarr2 = $this->getUsersWithAuthority('FDA_CHK_APP_2');
			$appaccountarr   = $this->getUsersWithAuthority('FDA_CHK_ACC');
		}else
		{
			$approverarr2 = $this->getUsersWithAuthority('PDA_CHK_APP_2');
			$appaccountarr   = $this->getUsersWithAuthority('PDA_CHK_ACC');
		}
	}
	else
	{
		$approverarr2 = $this->getUsersWithAuthority('OTHER_PAYMENT_CHK_APP_2');
		$appaccountarr   = $this->getUsersWithAuthority('OTHER_PAYMENT_CHK_ACC');
	}
	
	$approverarraccount2 = $this->getUsersWithAuthority('HIRE_STSTMENT_CHK_ACC');
	
	$url = './request_port_cost.php?id='.$_REQUEST['id'].'&page='.$_REQUEST['page'].'&name='.$_REQUEST['name'];
	$currentusername = $this->getUserDetailBaseOnId($_SESSION['uid'], 'CONTACT_PERSON');
	$invtitleType = 'PAYMENT';
	
	$vesselname = $this->getVesselIMOData($this->getCompareEstimateData($comid,"VESSEL_IMO_ID"),"VESSEL_NAME");
	
	if($invoiceidd != '' && $txtStatus >= 1)
	{
	    $userarray = array();
	    if($txtStatus == 1)
		{  
		     if(!empty($approverarr1))
			 {
			 	 $userarray = $approverarr1;
			 }
		     else if(empty($approverarr1) && !empty($approverarr2))
			 {
			     $userarray = $approverarr2;
			 }
			 if(!empty($userarray))
			 {
			      foreach($userarray as $userarray1)
				  {
				       $this->saveUserAlerts($_SESSION['uid'], $userarray1, $url, $invtitleType, $currentusername.' sent '.$_REQUEST['name'].' '.$invtitleType.' ('.$vesselname.' - '.$txtAccNO.') for Level 1 Approval', $invoiceidd);				  
				  }
			 }
		}
		
		if($txtStatus == 2)
		{  
		     $userarray = $creatorsarr;
			 
			 if(!empty($userarray))
			 {
			      foreach($userarray as $userarray1)
				  {
				       $this->saveUserAlerts($_SESSION['uid'], $userarray1, $url, $invtitleType, $currentusername.' sent '.$_REQUEST['name'].' '.$invtitleType.' ('.$vesselname.' - '.$txtAccNO.') for Review', $invoiceidd);				  
				  }
			 }
		}
		
		if($txtStatus == 4)
		{  
		     $userarray = $approverarr1;
			 
			 if(!empty($userarray))
			 {
			      foreach($userarray as $userarray1)
				  {
				       $this->saveUserAlerts($_SESSION['uid'], $userarray1, $url, $invtitleType, $currentusername.' sent '.$_REQUEST['name'].' '.$invtitleType.' ('.$vesselname.' - '.$txtAccNO.') for Review', $invoiceidd);				  
				  }
			 }
		}
		
		if($txtStatus == 3)
		{
		     if(!empty($approverarr2))
			 {
			     $userarray = $approverarr2;
			 }
			 if(!empty($userarray))
			 {
			      foreach($userarray as $userarray1)
				  {
				       $this->saveUserAlerts($_SESSION['uid'], $userarray1, $url, $invtitleType, $currentusername.' sent '.$_REQUEST['name'].' '.$invtitleType.' ('.$vesselname.' - '.$txtAccNO.') for Level 2 Approval', $invoiceidd);				  
				  }
			 }
		}
		
		if($txtStatus == 5)
		{	

			$sql_com   = "update request_master set SYNC_STATUS=1 where REQ_ID='".$invoiceidd."'"; 
			mysql_query($sql_com) or ($sql_com);
			
		     if(!empty($appaccountarr))
			 {
			     $userarray = $appaccountarr;
			 }
			 if(!empty($userarray))
			 {
			      foreach($userarray as $userarray1)
				  {
				       $this->saveUserAlerts($_SESSION['uid'], $userarray1, $url, $invtitleType, $currentusername.' Approved '.$_REQUEST['name'].' '.$invtitleType.' ('.$vesselname.' - '.$txtAccNO.').', $invoiceidd);				  
				  }
			 }
		}
	}
	
	mysql_query("commit");
	return $msg; 
}