<?php
session_start();
include_once("../../includes/functions_internal_user_dryout.inc.php");
include_once("../../includes/functions_internal_user_mailinbox.inc.php");
@$i = $_REQUEST['id'];
switch ($i)
{
   
	case 1:
        $ret = checkDuplicateVendorName();
				break;
	case 2:
        $ret = checkDuplicateVendorCode();
				break;
	case 3:
        $ret = checkDuplicateVendorShortName();
				break;
	case 4:
        $ret = checkPortStatus();
				break;
	case 5:
        $ret = getCOAData();
				break;
    case 6:
        $ret = checkDuplicateOpenCargo();
				break;
	case 7:
       	$ret = checkRate();
			 	break;
	case 8:
        $ret = getAddReferencesData();
				break;
	case 9:
        $ret = getSpotFixtureReport();
				break;
				
	case 10:
        $ret = checkDistance();
				break;
				
	case 11:
        $ret = checkDuplicateNomID();
				break;
				
	case 12:
        $ret = getAgencyLetterData();
				break;
				
	case 13:
        $ret = getZoneData();
				break;
	
	case 14:
        $ret = getAgentListCPDateWiseReport();
				break;
	
	case 15:
        $ret = getDeadFreightSummaryReport();
				break;
				
	case 16:
        $ret = getCOAReportData();
				break;
				
	case 17:
        $ret = getDailyLogRecord();
				break;
	case 18:
        $ret = getOwner_brokerWiseFreightReport();
				break;
	case 19:
        $ret = getSpoyFixtureReport();
				break;
	case 20:
        $ret = getDemmurageSummaryReport();
				break;	
	case 21:
        $ret = getPortPerformanceReport();
				break;
	case 22:
        $ret = getPNIClubReport();
				break;
	case 23:
        $ret = getAgingPayableReport();
				break;
	case 24:
        $ret = getAgingReceivablesReport();
				break;
	case 25:
        $ret = getProfitabilityReport();
				break;
	case 26:
			$ret = getProjectedCashFlowRecord();
			break;
	case 27:
			$ret = getShipmentRegisterRecord();
			break;
			
	case 30:
			$ret = redirectURLLaytimeLoadPort();
			break;
	case 31:
        $ret = getVoyageEstimatesData();
				break;
	case 32:
       $ret = getVesselRelatedData();
				break;
	case 33:
       	$ret = getVoyageFinancialsEstimatesComparisonData();
			 	break;
	case 34:
       	$ret = getVoyageFinancialsComparisonData();
			 	break;
	case 35:
        $ret = getProfitabilityHeadWiseReport();
				break;
	case 36:
        $ret = getCompareEstimatesList();
				break;
	case 37:
        $ret = getDecisionChartListList();
				break;
	case 38:
        $ret = getPaymentRequestYesOrNo();
				break;
	case 39:		
        $ret = checkDuplicateVessel();
				break;
	case 40:		
        $ret = checkDuplicateIMONo();
				break;
	case 41:
        $ret = getGenerateAgencyLetterDataJson();
				break;
    case 42:
        $ret = getVesselDetails();
				break;
	case 43:
        $ret = getBankingDetails();
				break;
	case 44:
        $ret = getFreightInvoicePaymentDetails();
				break;
	case 45:
        $ret = getHireInvoicePaymentDetails();
				break;
	case 46:
        $ret = getDumerageInvoicePaymentDetails();
				break;
	case 47:
        $ret = getPaymentInvoicePaymentDetails();
				break;
	case 48:
        $ret = getVesselDataToCompare();
				break;
	case 49:
        $ret = getCompareSheetData();
				break;
	case 50:
        $ret = getCharteringRegisterData();
				break;
	case 51:
        $ret = getCharteringRegisterDataDetailed();
				break;
	case 52:
        $ret = getTCCompareEstimatesList();
				break;
	case 53:
        $ret = getTCDecisionChartList();
				break;
	case 54:
        $ret = getTCHireInvoicePaymentDetails();
				break;
	case 55:
        $ret = getCompareSheetDataTC();
				break;
	case 56:
        $ret = getDashBoardData();
				break;
	case 57:
        $ret = getDailyPositionReport();
				break;
	case 58:
        $ret = getmaildata();
				break;
	case 59:
        $ret = getvendordata();
				break;
	case 60:
        $ret = getAgencyLetterTCDataDelete();
				break;
    case 61:
        $ret = getDeleteTCHireInvoice();
				break;
	case 62:
        $ret = getTCHireInvoicePaymentDetails();
				break;
	case 63:
        $ret = getTCOthersInvoicePaymentDetails();
				break;
	case 64:
        $ret = getvendorname();
		break;
	case 65:
		$ret = getShipOwnerdetail();
		break;
    case 66:
        $ret = getDashBoardData1();
				break;
	case 67:
        $ret = getCharteringRegisterDataTC();
				break;
	case 68:
        $ret = getCOAVCEstimates();
				break;
	case 69:
        $ret = getCOAListjson();
				break;
	case 70:
        $ret = getCOAVCEstimatesDashboard();
				break;
	case 71:
        $ret = getHireInvoicePaymentDetailsTC();
				break;
	case 72:
        $ret = getCargoPlanningDetailsCP();
				break;
	case 73:
        $ret = getCargoPlanningjson();
				break;
	case 74:
        $ret = getCargoTonnageBookReport();
				break;
	case 75:
        $ret = getOtherReletInvoicePaymentDetails();
				break;
	case 76:
        $ret = getPaymentReletInvoicePaymentDetails();
				break;
	case 77:
        $ret = getCargoPlanningListDetails();
				break;
	case 78:
        $ret = getVesselOpenPositionReport();
				break;
	case 79:
        $ret = getTCOthersPaymentPaidDetails();
				break;
	default:
		    $ret = "";
				break; 				
}


function getTCOthersPaymentPaidDetails()
{
	$obj 		= new data();
	$connect	= $obj->funConnect();
	$invoiceid 	= $_REQUEST['invoiceid'];
	
	$sql 		= "select * from payment_tcother_master where PAYMENTID='".$invoiceid."' ";
	$res 	 	=  mysql_query($sql) or die($sql);
	$rows 		= mysql_fetch_assoc($res);
	if($rows['P_DATE']!="" && $rows['P_DATE']!="1970-01-01")
	{
		$idate = date('d-m-Y',strtotime($rows['P_DATE']));
	}
	else
	{
		$idate = date('d-m-Y',time());
	}
	echo '<div class="row invoice-info">
			 <div class="col-sm-4 invoice-col">
				 Amount
				<address>
					<input type="text" name="txtP_Amt" id="txtP_Amt" class="form-control" readonly value="'.$rows['FINAL_AMOUNT'].'" autocomplete="off"/>
					<input type="hidden" name="txtP_ID" id="txtP_ID" readonly value="'.$invoiceid.'" />	
				</address>
			 </div><!-- /.col -->
			 <div class="col-sm-4 invoice-col">
				Date
				<address>
					<input type="text" name="txtP_Date" id="txtP_Date" class="form-control" value="'.$idate.'" autocomplete="off"/>
				</address>
			 </div><!-- /.col -->
		</div>
		<div class="row invoice-info">
			 <div class="col-sm-12 invoice-col">
				Remarks
				<address>
					<textarea name="txtP_Remarks" id="txtP_Remarks" class="form-control" cols="15" rows="1" placeholder="Remarks..">'.$rows['P_REMARKS'].'</textarea>
				</address>
			 </div><!-- /.col -->
		</div>
		<div class="row invoice-info">
			<div class="col-sm-4 invoice-col">
			Payment Paid
			   <address>
				   <input type="text" name="txtP_PR" id="txtP_PR" class="form-control" autocomplete="off" placeholder="0.00" value="'.$rows['P_AMT'].'"  onkeyup="onkeyUp1();"/>
			   </address>
			</div><!-- /.col -->
			<div class="col-sm-8 invoice-col">
			 Attachments 
		        <address>
				   <div class="btn btn-success btn-file btn-flat" data-toggle="tooltip" data-original-title="Add Attachments">
						<i class="fa fa-paperclip"></i> Attachment
						<input type="file" class="form-control" multiple name="mul_file[]" id="mul_file" title="" data-widget="Add Attachment" data-toggle="tooltip" data-original-title="Add Attachment"/>
				   </div>';
				   if($rows['ATTACHMENTS'] != '')
					{ 
						$file = explode(",",$rows['ATTACHMENTS']); 
						$name = explode(",",$rows['ATTACHMENTS_NAME']);									
				   echo '<address>
							<table cellpadding="1" cellspacing="1" border="0" width="100%" align="left">';
							$j =1;
							for($i=0;$i<sizeof($file);$i++)
							{
							echo '<tr height="20" id="row_file1_'.$j.'">
								<td width="80%" align="left" class="input-text"  valign="top"><a href="../../attachment/'.$file[$i].'" target="_blank" style="color:blue;" data-toggle="tooltip" data-original-title="'.$name[$i].'"><i class="fa fa-external-link"></i>&nbsp;&nbsp;'.$name[$i].'</a>
								<input type="hidden" name="file1_'.$j.'" id="file1_'.$j.'" value="'.$file[$i].'" />
								<input type="hidden" name="name1_'.$j.'" id="name1_'.$j.'" value="'.$name[$i].'" />
								</td>
								<td width="20%" align="left" class="input-text"  valign="top"><a href="#1" onClick="Del_Upload1('.$j.');"><i class="fa fa-times " style="color:red;"></i></a></td>
							</tr>';
							$j++;}
						echo '</table>
						</address>';
					}
			echo '</address>
			</div><!-- /.col -->
		</div>';
}

function getVesselOpenPositionReport()
{
	$obj 			= new data();
	$connect		= $obj->funConnect();
	$selBType       =  $_REQUEST['selBType'];
	
	$sql = "select VESSEL_IMO_ID, VESSEL_NAME, BUSINESSTYPEID, (select VesselType from vessel_type_master where vessel_type_master.VesselTypeId = vessel_imo_master.VESSEL_TYPE) as VESSEL_TYPE from vessel_imo_master where BUSINESSTYPEID='".$selBType."' and MCOMPANYID='".$_SESSION['company']."'";
	$i = 0;
	$result = mysql_query($sql) or die($sql);
	while($rows   = mysql_fetch_assoc($result))
	{
		$sql1 = "select COMID, FCAID, OPEN_CARGOID, (select TO_PORT from freight_cost_estimete_slave1 where freight_cost_estimete_slave1.FCAID=freight_cost_estimete_master.FCAID and DISC_PORT_QTY>0 order by FCA_SLAVEID DESC LIMIT 1) as LAST_DIS_PORT, (select RANDOMID from freight_cost_estimete_slave1 where freight_cost_estimete_slave1.FCAID=freight_cost_estimete_master.FCAID and DISC_PORT_QTY>0 order by FCA_SLAVEID DESC LIMIT 1) as LAST_RANDOMID, (select DISC_PORT_QTY from freight_cost_estimete_slave1 where freight_cost_estimete_slave1.FCAID=freight_cost_estimete_master.FCAID and DISC_PORT_QTY>0 order by FCA_SLAVEID DESC LIMIT 1) as LAST_DISC_PORT_QTY from freight_cost_estimete_master where VESSEL_IMO_ID='".$rows['VESSEL_IMO_ID']."' and MCOMPANYID='".$_SESSION['company']."' order by FCAID DESC";
		$result1 = mysql_query($sql1) or die($sql1);
		$num1 = mysql_num_rows($result1);
		$rows1 = mysql_fetch_assoc($result1);
		$checklistid      = $obj->getCheckListRecordsDataBasedOnComID($rows1['COMID'],"CHECKLIST_ID");
		$vesselsailed_VC1  = $obj->getCheckListPortDataRecordsRecBasedOnComID($rows1['COMID'],$checklistid,"DP",$rows1['LAST_DIS_PORT'],$rows1['LAST_RANDOMID'],"VESSEL SAILED");
		$vesselsailed_VC1  = ($vesselsailed_VC1 == '')?$obj->getCheckListPortDataRecordsRecBasedOnComID($rows1['COMID'],$checklistid,"DP",$rows1['LAST_DIS_PORT'],$rows1['LAST_RANDOMID'],"ETC/D"):$vesselsailed_VC1;
		$vesselsailed_VC  = date('d-m-Y',strtotime($vesselsailed_VC1));
		if($vesselsailed_VC == '01-01-1970'){$vesselsailed_VC = '';}else{$vesselsailed_VC  = date('d-m-Y',strtotime($vesselsailed_VC1));}
		
		$sql2 = "select COMID, TCOUTID, RE_DEL_RANGE, (select REDEL_DATE_EST from chartering_tc_estimate_slave1 where chartering_tc_estimate_slave1.TCOUTID=chartering_estimate_tc_master.TCOUTID order by TC_SLAVE1ID DESC LIMIT 1) as LAST_REDEL_DATE_EST, (select REDEL_DATE_EST from chartering_tc_estimate_slave1 where chartering_tc_estimate_slave1.TCOUTID=chartering_estimate_tc_master.TCOUTID order by TC_SLAVE1ID DESC LIMIT 1) as LAST_REDEL_DATE_EST1, (select RANDOMID from chartering_tc_estimate_slave1 where chartering_tc_estimate_slave1.TCOUTID=chartering_estimate_tc_master.TCOUTID order by TC_SLAVE1ID DESC LIMIT 1) as LAST_RANDOMID from chartering_estimate_tc_master where VESSEL_IMO_ID='".$rows['VESSEL_IMO_ID']."' and MCOMPANYID='".$_SESSION['company']."' order by TCOUTID DESC";
		
		$result2 = mysql_query($sql2) or die($sql2);
		$num2 = mysql_num_rows($result2);
		$rows2 = mysql_fetch_assoc($result2);
		$vesselsailed_TC1  = $rows2['LAST_REDEL_DATE_EST'];
		$vesselsailed_TC  = date('d-m-Y',strtotime($vesselsailed_TC1));
		if($vesselsailed_TC == '01-01-1970'){$vesselsailed_TC = '';}else{$vesselsailed_TC  = date('d-m-Y',strtotime($vesselsailed_TC1));}
		
		if($vesselsailed_VC !='' || $vesselsailed_TC !='')
		{   
			  
			$dischargeport = $cargo_name = $cargoqty = $bysseness = $opendate = '';
			if(($vesselsailed_TC !='' && $vesselsailed_VC !='' && strtotime($vesselsailed_TC) < strtotime($vesselsailed_VC)))
			{$dischargeport = $obj->getPortNameBasedOnID($rows1['LAST_DIS_PORT']);$cargo_name = $obj->getCargoNameListForMultipleNamemultiple($obj->getOpenCargoPositionData($rows1['OPEN_CARGOID'],'CARGO'));$cargoqty = $rows1['LAST_DISC_PORT_QTY']." MT";$bysseness = 'Voyage';$opendate = $vesselsailed_VC;}
			elseif($vesselsailed_TC =='' && $vesselsailed_VC !='')
			{$dischargeport = $obj->getPortNameBasedOnID($rows1['LAST_DIS_PORT']);$cargo_name = $obj->getCargoNameListForMultipleNamemultiple($obj->getOpenCargoPositionData($rows1['OPEN_CARGOID'],'CARGO'));$cargoqty = $rows1['LAST_DISC_PORT_QTY']." MT";$bysseness = 'Voyage';$opendate = $vesselsailed_VC;}
			elseif($vesselsailed_VC =='' && $vesselsailed_TC !='')
			{$dischargeport = '';$cargo_name = '';$cargoqty = '';$bysseness = 'TC';$dischargeport = $rows2['RE_DEL_RANGE'];$opendate = $vesselsailed_TC;}
			else{$dischargeport = '';$cargo_name = '';$cargoqty = '';$bysseness = 'TC';$dischargeport = $rows2['RE_DEL_RANGE'];$opendate = $vesselsailed_TC;}
			$i++;
			echo '<tr>';
				echo '<td>'.$i.'</td>';
				echo '<td>'.$rows['VESSEL_NAME'].'</td>';
				echo '<td>'.$rows['VESSEL_TYPE'].'</td>';
				echo '<td>'.$bysseness.'</td>';
				echo '<td>'.$dischargeport.'</td>';
				echo '<td>'.$opendate.'</td>';
				echo '<td>'.$cargo_name.'</td>';
				echo '<td>'.$cargoqty.'</td>';
			echo '</tr>';
		}
	}
	
}

function getCargoPlanningListDetails()
{
	$obj 			= new data();
	$connect		= $obj->funConnect();
	$txtLaycanSDate     =  $_REQUEST['txtLaycanSDate'];
	$txtLaycanEDate     =  $_REQUEST['txtLaycanEDate'];
	$selCargoPlan       =  $_REQUEST['selCargoPlan'];
	$txtFromCargoSize   =  $_REQUEST['txtFromCargoSize'];
	$txtToCargoSize     =  $_REQUEST['txtToCargoSize'];
	$coaspot            =  $_REQUEST['coaspot'];
	$relet              =  $_REQUEST['relet'];
	
	$sql = "select OPEN_CARGOID, CPID, MODULEID, MCOMPANYID, COA_DATE, (select MATERIAL_CODE_DESC from cargo_master where cargo_master.MATERIALID = open_cargo_master.CARGO) as CARGONAME, (select NAME from basein_master where basein_master.BASEINID = open_cargo_master.BASINID) as BASINAME, (select PortName from port_master where port_master.PortId = open_cargo_master.LOAD_PORT) as LOADPORT, (select PortName from port_master where port_master.PortId = open_cargo_master.DISCHARGE_PORT) as DISPORT, (select NAME from vendor_master where vendor_master.CODE = open_cargo_master.CHARTERER) as CHARTERERNAME, (select NAME from vendor_master where vendor_master.CODE = open_cargo_master.OWNER) as OWNERNAME, CARGOSTEAMSIZE, LAYCAN_SDATE, LAYCAN_EDATE, BASE_FREIGHT, UPDATE_STATUS, VESSEL_TYPE, (select VesselType from vessel_type_master where vessel_type_master.VesselTypeId = open_cargo_master.VESSEL_TYPE) as VESSEL_TYPE1, RDO_WS_TYPE, WS_LUMPSUM_AMOUNT, (case when (RDO_WS_TYPE = 1) THEN 'WS' ELSE 'Lumpsum' END) as WS_RDO_TEXT, (case when (RDO_WS_TYPE = 1) THEN 'Base Freight' ELSE 'Lumpsum' END) as WS_RDO_TEXT1, CARGO_RELET, COA_SPOT from open_cargo_master where BUSINESSTYPEID='".$_SESSION['selBType']."' and UPDATE_STATUS=2 and MCOMPANYID='".$_SESSION['company']."' and COA_SPOT='".$coaspot."' and CARGO_RELET='".$relet."' and (select count(DISTINCT(freight_cost_estimete_master.COMID)) from freight_cost_estimete_master where freight_cost_estimete_master.OPEN_CARGOID=open_cargo_master.OPEN_CARGOID and SHEET_NO and COAID is NULL) =0 and (select count(DISTINCT(freight_cost_estimete_master.COMID)) from freight_cost_estimete_master where freight_cost_estimete_master.OPEN_CARGOID=open_cargo_master.OPEN_CARGOID and SHEET_NO is not NULL and COAID is not NULL)=0 and (select count(DISTINCT(cargo_relet_estimate_masster.COMID)) from cargo_relet_estimate_masster where cargo_relet_estimate_masster.OPEN_CARGOID=open_cargo_master.OPEN_CARGOID and SHEET_NO is not NULL and COAID is NOT NULL) = 0";
	if($txtLaycanSDate!='')
	{
		$sql.=" and LAYCAN_SDATE>='".date('Y-m-d',strtotime($txtLaycanSDate))."'";
	}
	if($txtLaycanEDate!='')
	{
		$sql.=" and LAYCAN_SDATE<='".date('Y-m-d',strtotime($txtLaycanEDate))."'";
	}
	if($selCargoPlan!='')
	{
		$sql.=" and CARGO='".$selCargoPlan."'";
	}
	if($txtFromCargoSize!='')
	{
		$sql.=" and CARGOSTEAMSIZE>='".$txtFromCargoSize."'";
	}
	if($txtToCargoSize!='')
	{
		$sql.=" and CARGOSTEAMSIZE<='".$txtToCargoSize."'";
	}
	//echo $sql;
	$result = mysql_query($sql) or die($sql);
	$cargodata = array();
	while($rows   = mysql_fetch_assoc($result))
	{
		$freightdata = '';
		if($_SESSION['selBType']==1)
		{
			 $freightdata = $rows['WS_RDO_TEXT1']." ".$rows['WS_LUMPSUM_AMOUNT'];
			 if($rows['RDO_WS_TYPE'] ==1)
		 	 {
		     	$value1= "CPID:".$rows['CPID'].', Laycan Start:'.date('d-m-Y',strtotime($rows['LAYCAN_SDATE'])).', Cargo:'.$rows['CARGONAME'].', Qty:'.$rows['CARGOSTEAMSIZE'].' MT, Base Freight(USD): '.$rows['WS_LUMPSUM_AMOUNT'].' ';
			 }else{
				$value1= "CPID:".$rows['CPID'].', Laycan Start:'.date('d-m-Y',strtotime($rows['LAYCAN_SDATE'])).', Cargo:'.$rows['CARGONAME'].', Qty:'.$rows['CARGOSTEAMSIZE'].' MT/Lumpsum (USD):'.$rows['WS_LUMPSUM_AMOUNT'] ;
			 }
		}
		if($_SESSION['selBType']==2)
		{
			 $freightdata = $rows['WS_RDO_TEXT']." ".$rows['WS_LUMPSUM_AMOUNT'];
			 if($rows['RDO_WS_TYPE'] ==1)
		 	 {
		     	$value1= "CPID:".$rows['CPID'].', Laycan Start:'.date('d-m-Y',strtotime($rows['LAYCAN_SDATE'])).', Cargo:'.$rows['CARGONAME'].', Qty:'.$rows['CARGOSTEAMSIZE'].' MT, WS:'.$rows['WS_LUMPSUM_AMOUNT'].' ';
			 }else{
				$value1= "CPID:".$rows['CPID'].', Laycan Start:'.date('d-m-Y',strtotime($rows['LAYCAN_SDATE'])).', Cargo:'.$rows['CARGONAME'].', Qty:'.$rows['CARGOSTEAMSIZE'].' MT, Lumpsum (USD):'.$rows['WS_LUMPSUM_AMOUNT'] ;
			 }
		}
		if($_SESSION['selBType']==3)
		{
			$freightdata = $rows['BASE_FREIGHT'];
			$value1= "CPID:".$rows['CPID'].', Laycan Start:'.date('d-m-Y',strtotime($rows['LAYCAN_SDATE'])).', Cargo:'.$rows['CARGONAME'].', Qty:'.$rows['CARGOSTEAMSIZE'].' MT, Freight (USD):'.$rows['BASE_FREIGHT'].' ';
		}
	    $cargodata[] = array('CPID'=>$rows['CPID'],'OPEN_CARGOID'=>$rows['OPEN_CARGOID'],'CHARTERER'=>$rows['CHARTERERNAME'],'OWNER'=>$rows['OWNERNAME'],'CARGO'=>$rows['CARGONAME'],'CARGOSTEAMSIZE'=>$rows['CARGOSTEAMSIZE'],'VESSELTYPE'=>$rows['VESSEL_TYPE1'],'BASE_FREIGHT'=>$freightdata,'COA_DATE'=>date('d-m-Y',strtotime($rows['COA_DATE'])),'BASINID'=>$rows['BASINAME'],'LOAD_PORT'=>$rows['LOADPORT'],'DISCHARGE_PORT'=>$rows['DISPORT'],'LAYCAN_SDATE'=>date('d-m-Y',strtotime($rows['LAYCAN_SDATE'])),'LAYCAN_EDATE'=>date('d-m-Y',strtotime($rows['LAYCAN_EDATE'])),'TEXTTOSHOW'=>$value1);
	}
	echo json_encode($cargodata);
}

function getPaymentReletInvoicePaymentDetails()
{
	$obj 		= new data();
	$connect	= $obj->funConnect();
	$invoiceid 	= $_REQUEST['invoiceid'];
	
	$sql 		= "select * from request_relet_master where REQ_ID='".$invoiceid."' ";
	$res 	 	=  mysql_query($sql) or die($sql);
	$rows 		= mysql_fetch_assoc($res);
	if($rows['P_DATE']!="")
	{
		$idate = date('d-m-Y',strtotime($rows['P_DATE']));
	}
	else
	{
		$idate = date('d-m-Y',time());
	}
	echo '<div class="row invoice-info">
			 <div class="col-sm-4 invoice-col">
				 Amount To Pay
				<address>
					<input type="text" name="txtP_Amt" id="txtP_Amt" class="form-control" readonly value="'.$rows['NET_AMT'].'" autocomplete="off"/>
					<input type="hidden" name="txtP_ID" id="txtP_ID" readonly value="'.$invoiceid.'" />	
				</address>
			 </div><!-- /.col -->
			 <div class="col-sm-4 invoice-col">
				Date
				<address>
					<input type="text" name="txtP_Date" id="txtP_Date" class="form-control" value="'.$idate.'" autocomplete="off"/>
				</address>
			 </div><!-- /.col -->
		</div>
		<div class="row invoice-info">
			 <div class="col-sm-12 invoice-col">
				Remarks
				<address>
					<textarea name="txtP_Remarks" id="txtP_Remarks" class="form-control" cols="15" rows="1" placeholder="Remarks..">'.$rows['P_REMARKS'].'</textarea>
				</address>
			 </div><!-- /.col -->
		</div>
		<div class="row invoice-info">
			<div class="col-sm-4 invoice-col">
			Amount Paid
			   <address>
				   <input type="text" name="txtP_PR" id="txtP_PR" class="form-control" autocomplete="off" placeholder="0.00" value="'.$rows['P_AMT'].'"  onkeyup="onkeyUp1();"/>
			   </address>
			</div><!-- /.col -->
			<div class="col-sm-8 invoice-col">
			 Attachments 
		        <address>
				   <div class="btn btn-success btn-file btn-flat" data-toggle="tooltip" data-original-title="Add Attachments">
						<i class="fa fa-paperclip"></i> Attachment
						<input type="file" class="form-control" multiple name="mul_file[]" id="mul_file" title="" data-widget="Add Attachment" data-toggle="tooltip" data-original-title="Add Attachment"/>
				   </div>';
				   if($rows['ATTACHMENTS'] != '')
					{ 
						$file = explode(",",$rows['ATTACHMENTS']); 
						$name = explode(",",$rows['ATTACHMENTS_NAME']);									
				   echo '<address>
							<table cellpadding="1" cellspacing="1" border="0" width="100%" align="left">';
							$j =1;
							for($i=0;$i<sizeof($file);$i++)
							{
							echo '<tr height="20" id="row_file1_'.$j.'">
								<td width="80%" align="left" class="input-text"  valign="top"><a href="../../attachment/'.$file[$i].'" target="_blank" style="color:blue;" data-toggle="tooltip" data-original-title="'.$name[$i].'"><i class="fa fa-external-link"></i>&nbsp;&nbsp;'.$name[$i].'</a>
								<input type="hidden" name="file1_'.$j.'" id="file1_'.$j.'" value="'.$file[$i].'" />
								<input type="hidden" name="name1_'.$j.'" id="name1_'.$j.'" value="'.$name[$i].'" />
								</td>
								<td width="20%" align="left" class="input-text"  valign="top"><a href="#1" onClick="Del_Upload1('.$j.');"><i class="fa fa-times " style="color:red;"></i></a></td>
							</tr>';
							$j++;}
						echo '</table>
						</address>';
					}
			echo '</address>
			</div><!-- /.col -->
		</div>';
}

function getOtherReletInvoicePaymentDetails()
{
	$obj 		= new data();
	$connect	= $obj->funConnect();
	$invoiceid 	= $_REQUEST['invoiceid'];
	
	$sql 		= "select * from other_relet_invoice_master where INVOICEID='".$invoiceid."' ";
	$res 	 	=  mysql_query($sql) or die($sql);
	$rows 		= mysql_fetch_assoc($res);
	if($rows['P_DATE']!="")
	{
		$idate = date('d-m-Y',strtotime($rows['P_DATE']));
	}
	else
	{
		$idate = date('d-m-Y',time());
	}
	echo '<div class="row invoice-info">
			 <div class="col-sm-4 invoice-col">
				 Amount
				<address>
					<input type="text" name="txtP_Amt" id="txtP_Amt" class="form-control" readonly value="'.$rows['NET_PAYABLE'].'" autocomplete="off"/>
					<input type="hidden" name="txtP_ID" id="txtP_ID" readonly value="'.$invoiceid.'" />	
				</address>
			 </div><!-- /.col -->
			 <div class="col-sm-4 invoice-col">
				Date
				<address>
					<input type="text" name="txtP_Date" id="txtP_Date" class="form-control" value="'.$idate.'" autocomplete="off"/>
				</address>
			 </div><!-- /.col -->
		</div>
		<div class="row invoice-info">
			 <div class="col-sm-12 invoice-col">
				Remarks
				<address>
					<textarea name="txtP_Remarks" id="txtP_Remarks" class="form-control" cols="15" rows="1" placeholder="Remarks..">'.$rows['P_REMARKS'].'</textarea>
				</address>
			 </div><!-- /.col -->
		</div>
		<div class="row invoice-info">
			<div class="col-sm-4 invoice-col">
			Payment Received
			   <address>
				   <input type="text" name="txtP_PR" id="txtP_PR" class="form-control" autocomplete="off" placeholder="0.00" value="'.$rows['P_AMT'].'"  onkeyup="onkeyUp1();"/>
			   </address>
			</div><!-- /.col -->
			<div class="col-sm-8 invoice-col">
			 Attachments 
		        <address>
				   <div class="btn btn-success btn-file btn-flat" data-toggle="tooltip" data-original-title="Add Attachments">
						<i class="fa fa-paperclip"></i> Attachment
						<input type="file" class="form-control" multiple name="mul_file[]" id="mul_file" title="" data-widget="Add Attachment" data-toggle="tooltip" data-original-title="Add Attachment"/>
				   </div>';
				   if($rows['ATTACHMENTS'] != '')
					{ 
						$file = explode(",",$rows['ATTACHMENTS']); 
						$name = explode(",",$rows['ATTACHMENTS_NAME']);									
				   echo '<address>
							<table cellpadding="1" cellspacing="1" border="0" width="100%" align="left">';
							$j =1;
							for($i=0;$i<sizeof($file);$i++)
							{
							echo '<tr height="20" id="row_file1_'.$j.'">
								<td width="80%" align="left" class="input-text"  valign="top"><a href="../../attachment/'.$file[$i].'" target="_blank" style="color:blue;" data-toggle="tooltip" data-original-title="'.$name[$i].'"><i class="fa fa-external-link"></i>&nbsp;&nbsp;'.$name[$i].'</a>
								<input type="hidden" name="file1_'.$j.'" id="file1_'.$j.'" value="'.$file[$i].'" />
								<input type="hidden" name="name1_'.$j.'" id="name1_'.$j.'" value="'.$name[$i].'" />
								</td>
								<td width="20%" align="left" class="input-text"  valign="top"><a href="#1" onClick="Del_Upload1('.$j.');"><i class="fa fa-times " style="color:red;"></i></a></td>
							</tr>';
							$j++;}
						echo '</table>
						</address>';
					}
			echo '</address>
			</div><!-- /.col -->
		</div>';
}


function getCargoTonnageBookReport()
{
	$obj = new data();
	$connect=$obj->funConnect();
	$txtFrom_Date = $_REQUEST['txtFrom_Date'];
	$txtTo_Date   = $_REQUEST['txtTo_Date'];
	$selMonth     = $_REQUEST['selMonth'];
	$selYear      = $_REQUEST['selYear'];
	$selQtr       = $_REQUEST['selQtr'];
	$selStatus    = $_REQUEST['selStatus'];
	$selQtr       = $_REQUEST['selQtr'];
	$selBType     = $_REQUEST['selBType'];
	$fromdate = $todate = '';
	if($selQtr==1 && $selYear!=''){$fromdate = $selYear.'-01-01';$todate = $selYear.'-03-31';}
	if($selQtr==2 && $selYear!=''){$fromdate = $selYear.'-04-01';$todate = $selYear.'-06-30';}
	if($selQtr==3 && $selYear!=''){$fromdate = $selYear.'-07-01';$todate = $selYear.'-09-30';}
	if($selQtr==4 && $selYear!=''){$fromdate = $selYear.'-10-01';$todate = $selYear.'-12-31';}
	
	$sQuery = "SELECT OPEN_CARGOID, CPID, MODULEID, MCOMPANYID, COA_DATE, (select count(DISTINCT(freight_cost_estimete_master.COMID)) from freight_cost_estimete_master where freight_cost_estimete_master.OPEN_CARGOID=open_cargo_master.OPEN_CARGOID and SHEET_NO and COAID is NULL) as VOYAGEBOOk, (select count(DISTINCT(freight_cost_estimete_master.COMID)) from freight_cost_estimete_master where freight_cost_estimete_master.OPEN_CARGOID=open_cargo_master.OPEN_CARGOID and SHEET_NO is not NULL and COAID is not NULL) as COABOOk, (select count(DISTINCT(cargo_relet_estimate_masster.COMID)) from cargo_relet_estimate_masster where cargo_relet_estimate_masster.OPEN_CARGOID=open_cargo_master.OPEN_CARGOID and SHEET_NO is not NULL and COAID is NOT NULL) as COARELETBOOk, (select MATERIAL_TYPE from cargo_master where cargo_master.MATERIALID = open_cargo_master.CARGO) as CARGONAME, (select NAME from basein_master where basein_master.BASEINID = open_cargo_master.BASINID) as BASINAME, (select PortName from port_master where port_master.PortId = open_cargo_master.LOAD_PORT) as LOADPORT, (select PortName from port_master where port_master.PortId = open_cargo_master.DISCHARGE_PORT) as DISPORT, (select NAME from vendor_master where vendor_master.CODE = open_cargo_master.CHARTERER and vendor_master.MCOMPANYID='".$_SESSION['company']."') as CHARTERERNAME, (select NAME from vendor_master where vendor_master.CODE = open_cargo_master.OWNER and vendor_master.MCOMPANYID='".$_SESSION['company']."') as OWNERNAME, COA_SPOT, (case when (COA_SPOT = 1) THEN 'SPOT' ELSE 'COA' END) as COASPOT, CARGOSTEAMSIZE, LAYCAN_SDATE, LAYCAN_EDATE, BASE_FREIGHT, BUNKER_HEDGE, CARGO_RELET, TOLERANCE, (case when (CARGO_RELET = 1) THEN 'Cargo Relet' ELSE 'Voyage' END) as CARGORELET, (case when (BUNKER_HEDGE = 1) THEN 'Yes' ELSE 'No' END) as BUNKER_HEDGE1, UPDATE_STATUS, VESSEL_TYPE, (select VesselType from vessel_type_master where vessel_type_master.VesselTypeId = open_cargo_master.VESSEL_TYPE) as VESSEL_TYPE1, REMARKS FROM open_cargo_master where UPDATE_STATUS=2 and MCOMPANYID='".$_SESSION['company']."' and BUSINESSTYPEID='".$selBType."'";
	
	if($txtFrom_Date!='' && $txtTo_Date!='')
	{
		$sQuery.= " and LAYCAN_SDATE >='".date('Y-m-d',strtotime($txtFrom_Date))."' and LAYCAN_SDATE <='".date('Y-m-d',strtotime($txtTo_Date))."'";
	}
	if($selMonth)
	{
		$sQuery.= " and month(LAYCAN_SDATE) ='".$selMonth."'";
	}
	if($selYear && $fromdate=='' && $todate=='')
	{
		$sQuery.= " and year(LAYCAN_SDATE) ='".$selYear."'";
	}
	if($selYear!='' && $fromdate!='' && $todate!='')
	{
		$sQuery.= " and LAYCAN_SDATE >='".$fromdate."' and LAYCAN_SDATE <='".$todate."'";
	}
	
	$i = 1;
	$rResult = mysql_query($sQuery) or die($sQuery);
	while($rows = mysql_fetch_array($rResult))
	{
	    if($rows['VOYAGEBOOk']>0 || $rows['COABOOk']>0 || $rows['COARELETBOOk']>0){$status = '<span class="label label-warning">Booked</span>';}else{$status = '<span class="label label-success">Open</span>';}
		if($selStatus == 2 && $status == '<span class="label label-warning">Booked</span>')
		{
			echo '<tr>';
			echo '<td align="center" valign="middle" class="input-text">'.$i.'.</td>';
			echo '<td align="left" valign="middle" class="input-text">'.$rows['CHARTERERNAME'].'</td>';
			echo '<td align="left" valign="middle" class="input-text">'.$rows['OWNERNAME'].'</td>';
			echo '<td align="left" valign="middle" class="input-text">'.$rows['BASINAME'].'</td>';
			echo '<td align="left" valign="middle" class="input-text">'.$rows['COASPOT'].'</td>';
			/*if($rows['COASPOT']=='SPOT')
			{
				$sql4 = "select DISTINCT(COMID) from freight_cost_estimate_compare inner join freight_cost_estimete_master on freight_cost_estimete_master.COMID = freight_cost_estimate_compare.COMID where freight_cost_estimete_master.OPEN_CARGOID='".$rows['OPEN_CARGOID']."'";
				$resul4 = mysql_query($sql4);
				$rows4 = mysql_fetch_assoc($resul4);
				$shipment1 =1;
				$shipment2 =$rows4['LEGS'];
				echo '<td align="left" valign="middle" class="input-text">'.$shipment1.'</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$shipment2.'</td>';
			}
			else
			{
				$coaids = array();
				$sql2 = "select DISTINCT(COAID) from freight_cost_estimate_compare inner join freight_cost_estimete_master on freight_cost_estimete_master.COMID = freight_cost_estimate_compare.COMID where freight_cost_estimete_master.OPEN_CARGOID='".$rows['OPEN_CARGOID']."'";
				$resul2 = mysql_query($sql2) or die($sql2);
				while($rows2 = mysql_fetch_assoc($resul2))
				{
					$coaids[] = $rows2['COAID'];
				}
				
				$sql3 = "select DISTINCT(COAID) from cargo_relet_estimate_compare inner join cargo_relet_estimate_masster on cargo_relet_estimate_masster.COMID = cargo_relet_estimate_compare.COMID where cargo_relet_estimate_masster.OPEN_CARGOID='".$rows['OPEN_CARGOID']."'";
				$resul3 = mysql_query($sql3) or die($sql3);
				while($rows3 = mysql_fetch_assoc($resul3))
				{
					$coaids[] = $rows3['COAID'];
				}
				
				$sql4 = "select TOTAL_SHIPMENTS, (select COUNT(COMID) as LEGS from freight_cost_estimate_compare where freight_cost_estimate_compare.COAAID=coa_master.COAID) as LEGS from coa_master where COAID in (".implode(',',$coaids).")";
				$resul4 = mysql_query($sql4);
				$rows4 = mysql_fetch_assoc($resul4);
				echo '<td align="left" valign="middle" class="input-text">'.$rows4['TOTAL_SHIPMENTS'].'</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows4['LEGS'].'</td>';
			}*/
			echo '<td align="left" valign="right" class="input-text">'.date('d-m-Y',strtotime($rows['LAYCAN_SDATE'])).'</td>';
			echo '<td align="left" valign="right" class="input-text">'.date('d-m-Y',strtotime($rows['LAYCAN_EDATE'])).'</td>';
			echo '<td align="left" valign="right" class="input-text">'.$rows['LOADPORT'].'</td>';
			echo '<td align="left" valign="right" class="input-text">'.$rows['DISPORT'].'</td>';
			echo '<td align="left" valign="right" class="input-text">'.$rows['CARGONAME'].'</td>';
			echo '<td align="left" valign="right" class="input-text">'.$rows['CARGOSTEAMSIZE'].'</td>';
			echo '<td align="left" valign="right" class="input-text">'.$rows['TOLERANCE'].'</td>';
			echo '<td align="left" valign="right" class="input-text">'.$rows['BUNKER_HEDGE1'].'</td>';
			echo '<td align="left" valign="right" class="input-text">'.$rows['CARGORELET'].'</td>';
			echo '<td align="left" valign="right" class="input-text">'.$rows['VESSEL_TYPE1'].'</td>';
			echo '<td align="left" valign="right" class="input-text">'.$rows['REMARKS'].'</td>';
			
			echo '<td align="left" valign="right" class="input-text">'.$status.'</td>';
			echo '</tr>';
			$i++;
		}
		if($selStatus == 1 && $status == '<span class="label label-success">Open</span>')
		{
			echo '<tr>';
			echo '<td align="center" valign="middle" class="input-text">'.$i.'.</td>';
			echo '<td align="left" valign="middle" class="input-text">'.$rows['CHARTERERNAME'].'</td>';
			echo '<td align="left" valign="middle" class="input-text">'.$rows['OWNERNAME'].'</td>';
			echo '<td align="left" valign="middle" class="input-text">'.$rows['BASINAME'].'</td>';
			echo '<td align="left" valign="middle" class="input-text">'.$rows['COASPOT'].'</td>';
			/*if($rows['COASPOT']=='SPOT')
			{
				$sql4 = "select DISTINCT(COMID) from freight_cost_estimate_compare inner join freight_cost_estimete_master on freight_cost_estimete_master.COMID = freight_cost_estimate_compare.COMID where freight_cost_estimete_master.OPEN_CARGOID='".$rows['OPEN_CARGOID']."'";
				$resul4 = mysql_query($sql4);
				$rows4 = mysql_fetch_assoc($resul4);
				$shipment1 =1;
				$shipment2 =$rows4['LEGS'];
				echo '<td align="left" valign="middle" class="input-text">'.$shipment1.'</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$shipment2.'</td>';
			}
			else
			{
				$coaids = array();
				$sql2 = "select DISTINCT(COAID) from freight_cost_estimate_compare inner join freight_cost_estimete_master on freight_cost_estimete_master.COMID = freight_cost_estimate_compare.COMID where freight_cost_estimete_master.OPEN_CARGOID='".$rows['OPEN_CARGOID']."'";
				$resul2 = mysql_query($sql2) or die($sql2);
				while($rows2 = mysql_fetch_assoc($resul2))
				{
					$coaids[] = $rows2['COAID'];
				}
				
				$sql3 = "select DISTINCT(COAID) from cargo_relet_estimate_compare inner join cargo_relet_estimate_masster on cargo_relet_estimate_masster.COMID = cargo_relet_estimate_compare.COMID where cargo_relet_estimate_masster.OPEN_CARGOID='".$rows['OPEN_CARGOID']."'";
				$resul3 = mysql_query($sql3) or die($sql3);
				while($rows3 = mysql_fetch_assoc($resul3))
				{
					$coaids[] = $rows3['COAID'];
				}
				
				$sql4 = "select TOTAL_SHIPMENTS, (select COUNT(COMID) as LEGS from freight_cost_estimate_compare where freight_cost_estimate_compare.COAAID=coa_master.COAID) as LEGS from coa_master where COAID in (".implode(',',$coaids).")";
				$resul4 = mysql_query($sql4);
				$rows4 = mysql_fetch_assoc($resul4);
				echo '<td align="left" valign="middle" class="input-text">'.$rows4['TOTAL_SHIPMENTS'].'</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows4['LEGS'].'</td>';
			}*/
			echo '<td align="left" valign="right" class="input-text">'.date('d-m-Y',strtotime($rows['LAYCAN_SDATE'])).'</td>';
			echo '<td align="left" valign="right" class="input-text">'.date('d-m-Y',strtotime($rows['LAYCAN_EDATE'])).'</td>';
			echo '<td align="left" valign="right" class="input-text">'.$rows['LOADPORT'].'</td>';
			echo '<td align="left" valign="right" class="input-text">'.$rows['DISPORT'].'</td>';
			echo '<td align="left" valign="right" class="input-text">'.$rows['CARGONAME'].'</td>';
			echo '<td align="left" valign="right" class="input-text">'.$rows['CARGOSTEAMSIZE'].'</td>';
			echo '<td align="left" valign="right" class="input-text">'.$rows['TOLERANCE'].'</td>';
			echo '<td align="left" valign="right" class="input-text">'.$rows['BUNKER_HEDGE1'].'</td>';
			echo '<td align="left" valign="right" class="input-text">'.$rows['CARGORELET'].'</td>';
			echo '<td align="left" valign="right" class="input-text">'.$rows['VESSEL_TYPE1'].'</td>';
			echo '<td align="left" valign="right" class="input-text">'.$rows['REMARKS'].'</td>';
			
			echo '<td align="left" valign="right" class="input-text">'.$status.'</td>';
			echo '</tr>';
			$i++;
		}
		
		if($selStatus == 0)
		{
			echo '<tr>';
			echo '<td align="center" valign="middle" class="input-text">'.$i.'.</td>';
			echo '<td align="left" valign="middle" class="input-text">'.$rows['CHARTERERNAME'].'</td>';
			echo '<td align="left" valign="middle" class="input-text">'.$rows['OWNERNAME'].'</td>';
			echo '<td align="left" valign="middle" class="input-text">'.$rows['BASINAME'].'</td>';
			echo '<td align="left" valign="middle" class="input-text">'.$rows['COASPOT'].'</td>';
			/*if($rows['COASPOT']=='SPOT')
			{
				$sql4 = "select DISTINCT(COMID) from freight_cost_estimate_compare inner join freight_cost_estimete_master on freight_cost_estimete_master.COMID = freight_cost_estimate_compare.COMID where freight_cost_estimete_master.OPEN_CARGOID='".$rows['OPEN_CARGOID']."'";
				$resul4 = mysql_query($sql4);
				$rows4 = mysql_fetch_assoc($resul4);
				$shipment1 =1;
				$shipment2 =$rows4['LEGS'];
				echo '<td align="left" valign="middle" class="input-text">'.$shipment1.'</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$shipment2.'</td>';
			}
			else
			{
				$coaids = array();
				$sql2 = "select DISTINCT(COAID) from freight_cost_estimate_compare inner join freight_cost_estimete_master on freight_cost_estimete_master.COMID = freight_cost_estimate_compare.COMID where freight_cost_estimete_master.OPEN_CARGOID='".$rows['OPEN_CARGOID']."'";
				$resul2 = mysql_query($sql2) or die($sql2);
				while($rows2 = mysql_fetch_assoc($resul2))
				{
					$coaids[] = $rows2['COAID'];
				}
				
				$sql3 = "select DISTINCT(COAID) from cargo_relet_estimate_compare inner join cargo_relet_estimate_masster on cargo_relet_estimate_masster.COMID = cargo_relet_estimate_compare.COMID where cargo_relet_estimate_masster.OPEN_CARGOID='".$rows['OPEN_CARGOID']."'";
				$resul3 = mysql_query($sql3) or die($sql3);
				while($rows3 = mysql_fetch_assoc($resul3))
				{
					$coaids[] = $rows3['COAID'];
				}
				
				$sql4 = "select TOTAL_SHIPMENTS, (select COUNT(COMID) as LEGS from freight_cost_estimate_compare where freight_cost_estimate_compare.COAAID=coa_master.COAID) as LEGS from coa_master where COAID in (".implode(',',$coaids).")";
				$resul4 = mysql_query($sql4);
				$rows4 = mysql_fetch_assoc($resul4);
				echo '<td align="left" valign="middle" class="input-text">'.$rows4['TOTAL_SHIPMENTS'].'</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows4['LEGS'].'</td>';
			}*/
			echo '<td align="left" valign="right" class="input-text">'.date('d-m-Y',strtotime($rows['LAYCAN_SDATE'])).'</td>';
			echo '<td align="left" valign="right" class="input-text">'.date('d-m-Y',strtotime($rows['LAYCAN_EDATE'])).'</td>';
			echo '<td align="left" valign="right" class="input-text">'.$rows['LOADPORT'].'</td>';
			echo '<td align="left" valign="right" class="input-text">'.$rows['DISPORT'].'</td>';
			echo '<td align="left" valign="right" class="input-text">'.$rows['CARGONAME'].'</td>';
			echo '<td align="left" valign="right" class="input-text">'.$rows['CARGOSTEAMSIZE'].'</td>';
			echo '<td align="left" valign="right" class="input-text">'.$rows['TOLERANCE'].'</td>';
			echo '<td align="left" valign="right" class="input-text">'.$rows['BUNKER_HEDGE1'].'</td>';
			echo '<td align="left" valign="right" class="input-text">'.$rows['CARGORELET'].'</td>';
			echo '<td align="left" valign="right" class="input-text">'.$rows['VESSEL_TYPE1'].'</td>';
			echo '<td align="left" valign="right" class="input-text">'.$rows['REMARKS'].'</td>';
			
			echo '<td align="left" valign="right" class="input-text">'.$status.'</td>';
			echo '</tr>';
			$i++;
		}	
	}
}


function getCargoPlanningjson()
{
	$obj = new data();
	$connect=$obj->funConnect();
	$_SESSION['selBType'] = $_POST['businesstype'];
	$rigts    = explode(',',$obj->getUserRights($_SESSION['uid'],$_SESSION['moduleid'],18));
	
	if($_POST['businesstype']==1)
	{
		$aColumns = array("CPID", "COA_DATE", "CARGONAME", "CARGOSTEAMSIZE", "LOADPORT", "DISPORT", "WS_RDO_TEXT1", "CHARTERERNAME", "OWNERNAME", "COASPOT", "CARGORELET");
	}
	if($_POST['businesstype']==2)
	{
		$aColumns = array("CPID", "COA_DATE", "CARGONAME", "CARGOSTEAMSIZE", "LOADPORT", "DISPORT", "WS_RDO_TEXT", "CHARTERERNAME", "OWNERNAME", "COASPOT", "CARGORELET");
	}
	if($_POST['businesstype']==3)
	{
		$aColumns = array("CPID", "COA_DATE", "CARGONAME", "CARGOSTEAMSIZE", "LOADPORT", "DISPORT", "BASE_FREIGHT", "CHARTERERNAME", "OWNERNAME", "COASPOT", "CARGORELET");
	}
	$sIndexColumn = "OPEN_CARGOID";
	
	$sTable = "open_cargo_master";
	
	if(!empty($_POST['order'][0]['column']))
	{
		$sOrder = "ORDER BY  ".$aColumns[intval($_POST['order'][0]['column'])]." ".$_POST['order'][0]['dir'];
	}
	else
	{
		$sOrder = "ORDER BY CPID";
	}
	
	$sWhere = "";$where1 = '';
	
	if ($_POST['search']['value']!= "")
	{
		if($_POST['businesstype']==1)
		{
			$sWhere = " where (CPID='".$_POST['search']['value']."' or COA_DATE LIKE '%".$_POST['search']['value']."%' or CARGONAME LIKE '%".$_POST['search']['value']."%' or LOADPORT LIKE '%".$_POST['search']['value']."%' or DISPORT LIKE '%".$_POST['search']['value']."%' or WS_RDO_TEXT1 LIKE '%".$_POST['search']['value']."%' or CARGOSTEAMSIZE LIKE '%".$_POST['search']['value']."%' or CHARTERERNAME LIKE '%".$_POST['search']['value']."%' or OWNERNAME LIKE '%".$_POST['search']['value']."%' or COASPOT LIKE '%".$_POST['search']['value']."%' or UPDATESTATUS LIKE '%".$_POST['search']['value']."%' or CARGORELET LIKE '%".$_POST['search']['value']."%')";
		}
		if($_POST['businesstype']==2)
		{
			$sWhere = " where (CPID='".$_POST['search']['value']."' or COA_DATE LIKE '%".$_POST['search']['value']."%' or CARGONAME LIKE '%".$_POST['search']['value']."%' or LOADPORT LIKE '%".$_POST['search']['value']."%' or DISPORT LIKE '%".$_POST['search']['value']."%' or WS_RDO_TEXT LIKE '%".$_POST['search']['value']."%' or CARGOSTEAMSIZE LIKE '%".$_POST['search']['value']."%' or CHARTERERNAME LIKE '%".$_POST['search']['value']."%' or OWNERNAME LIKE '%".$_POST['search']['value']."%' or COASPOT LIKE '%".$_POST['search']['value']."%' or UPDATESTATUS LIKE '%".$_POST['search']['value']."%' or CARGORELET LIKE '%".$_POST['search']['value']."%')";
		}
		if($_POST['businesstype']==3)
		{
			$sWhere = " where (CPID='".$_POST['search']['value']."' or COA_DATE LIKE '%".$_POST['search']['value']."%' or CARGONAME LIKE '%".$_POST['search']['value']."%' or LOADPORT LIKE '%".$_POST['search']['value']."%' or DISPORT LIKE '%".$_POST['search']['value']."%' or BASE_FREIGHT LIKE '%".$_POST['search']['value']."%' or CARGOSTEAMSIZE LIKE '%".$_POST['search']['value']."%' or CHARTERERNAME LIKE '%".$_POST['search']['value']."%' or OWNERNAME LIKE '%".$_POST['search']['value']."%' or COASPOT LIKE '%".$_POST['search']['value']."%' or UPDATESTATUS LIKE '%".$_POST['search']['value']."%' or CARGORELET LIKE '%".$_POST['search']['value']."%')";
		}
	}
	
	if ($_POST['businesstype']!= "")
	{
	    if($sWhere!=''){
	        $sWhere.= " and BUSINESSTYPEID='".$_POST['businesstype']."'";
		}else{
			$sWhere.= " where BUSINESSTYPEID='".$_POST['businesstype']."'";
		}
	}
	
	$sQuery = "SELECT * FROM (select OPEN_CARGOID, CPID, MODULEID, MCOMPANYID, BUSINESSTYPEID, COA_DATE, (select MATERIAL_TYPE from cargo_master where cargo_master.MATERIALID = open_cargo_master.CARGO) as CARGONAME, (select PortName from port_master where port_master.PortId = open_cargo_master.LOAD_PORT) as LOADPORT, (select PortName from port_master where port_master.PortId = open_cargo_master.DISCHARGE_PORT) as DISPORT, (select NAME from vendor_master where vendor_master.CODE = open_cargo_master.CHARTERER) as CHARTERERNAME, (select NAME from vendor_master where vendor_master.CODE = open_cargo_master.OWNER) as OWNERNAME, COA_SPOT, (case when (COA_SPOT = 1) THEN 'SPOT' ELSE 'COA' END) as COASPOT, CARGOSTEAMSIZE, LAYCAN_SDATE, LAYCAN_EDATE, BASE_FREIGHT, CARGO_RELET, (case when (CARGO_RELET = 1) THEN 'Cargo Relet' ELSE 'Voyage' END) as CARGORELET, UPDATE_STATUS, (case when (UPDATE_STATUS = 2) THEN 'Approved' ELSE CASE WHEN (UPDATE_STATUS = 1) THEN 'Approval Awaited' ELSE 'Pending' END END) as UPDATESTATUS, RDO_WS_TYPE, (case when (RDO_WS_TYPE = 1) THEN 'WS' ELSE 'Lumpsum' END) as WS_RDO_TEXT, (case when (RDO_WS_TYPE = 1) THEN 'Base Freight' ELSE 'Lumpsum' END) as WS_RDO_TEXT1, WS_LUMPSUM_AMOUNT from open_cargo_master) as innerTable $sWhere $sOrder LIMIT ".$_POST['start'].", ".$_POST['length']."";
	
	$rResult = mysql_query($sQuery) or die($sQuery);
	
	$sQuery = "	SELECT COUNT(".$sIndexColumn.") FROM (select * from open_cargo_master) as innerTable $sWhere";
	
	$rResultFilterTotal = mysql_query($sQuery);
	$aResultFilterTotal = mysql_fetch_array($rResultFilterTotal);
	$totalFiltered = $aResultFilterTotal[0];
	
	$sQuery = " SELECT COUNT(".$sIndexColumn.") FROM $sTable";
	$rResultTotal = mysql_query($sQuery);
	$aResultTotal = mysql_fetch_array($rResultTotal);
	$totalFiltered = $totalData = $aResultTotal[0];
	
	$aaData = array();
	$i = $_POST['start'];
	while ( $aRow = mysql_fetch_array( $rResult ) )
	{
		$row = array(); $i = $i+1;
		
		$details = $status = '';
		
	    if($aRow['UPDATESTATUS'] == 'Approved')
		{
			$status = '<b><span class="label label-success">Approved</span></b>';
		}
		else if($aRow['UPDATESTATUS'] == 'Approval Awaited')
		{
			$status = '<b><span class="label label-warning">Approval Awaited</span></b>';
		}
		else
		{
			$status = '<b><span class="label label-danger">Pending</span></b>';
		}
		
		if($_SESSION['company'] == $aRow['MCOMPANYID'])
		{
			$details='<a href="updatecargoplanning.php?id='.$aRow['OPEN_CARGOID'].'" title="Edit Details" ><i class="fa fa-edit "></i></a>';
			if($aRow['UPDATE_STATUS'] <=1){$details.='&nbsp;&nbsp;|&nbsp;&nbsp;<a href="#Remove" title="Remove Details" onclick="getDelete('.$aRow['OPEN_CARGOID'].');" ><i class="fa fa-times" style="color:red;"></i></a>';}
		}
		else
		{
			$details = '<strong><a href="updatecargoplanning.php?id='.$rows['OPEN_CARGOID'].'" title="View Details" ><i class="fa fa-file-text-o"></i></a></strong>';
		}
		
		if($_POST['businesstype']==1)
		{
			$freightdata = $aRow['WS_RDO_TEXT1']." ".$aRow['WS_LUMPSUM_AMOUNT'];
		}
		if($_POST['businesstype']==2)
		{
			$freightdata = $aRow['WS_RDO_TEXT']." ".$aRow['WS_LUMPSUM_AMOUNT'];
		}
		if($_POST['businesstype']==3)
		{
			$freightdata = $aRow['BASE_FREIGHT'];
		}
		$aaData[] = array('col1'=>$aRow['CPID'], 'col2'=>date('d-m-Y',strtotime($aRow['COA_DATE'])), 'col3'=>$aRow['CARGONAME'], 'col4'=>$aRow['CARGOSTEAMSIZE'], 'col5'=>$aRow['LOADPORT'], 'col6'=>$aRow['DISPORT'], 'col7'=>$freightdata, 'col8'=>$aRow['CHARTERERNAME'], 'col9'=>$aRow['OWNERNAME'], 'col10'=>$aRow['COASPOT'], 'col11'=>$aRow['CARGORELET'], 'col12'=>date('d-m-Y',strtotime($aRow['LAYCAN_SDATE'])).'<br/>To<br/>'.date('d-m-Y',strtotime($aRow['LAYCAN_EDATE'])), 'col13'=>$status, 'col14'=>$details);
	}
	
	echo json_encode(array("draw"=>intval($_POST['draw']),"recordsTotal"=>$totalData,"recordsFiltered"=>$totalFiltered,"records" => $aaData));
}



function getCargoPlanningDetailsCP()
{
	$obj 			= new data();
	$connect		= $obj->funConnect();
	$selCargoPlanning   =  $_REQUEST['selCargoPlanning'];
	$resultcoa = mysql_query("select * from open_cargo_master where OPEN_CARGOID='".$selCargoPlanning."'") or die;
	$rowscoa   = mysql_fetch_assoc($resultcoa);
	echo json_encode(array('CPID'=>$rowscoa['CPID'],'SHIPPER'=>$rowscoa['SHIPPER'],'CHARTERER'=>$rowscoa['CHARTERER'],'OWNER'=>$rowscoa['OWNER'],'RECEAVER'=>$rowscoa['RECEAVER'],'CARGO'=>$rowscoa['CARGO'],'CARGOSTEAMSIZE'=>$rowscoa['CARGOSTEAMSIZE'],'TOLERANCE'=>$rowscoa['TOLERANCE'],'BASE_FREIGHT'=>$rowscoa['BASE_FREIGHT'],'COA_SPOT'=>$rowscoa['COA_SPOT'],'COA_DATE'=>date('d-m-Y',strtotime($rowscoa['COA_DATE'])),'BASINID'=>$rowscoa['BASINID'],'BUNKER_HEDGE'=>$rowscoa['BUNKER_HEDGE'],'LOAD_PORT'=>$rowscoa['LOAD_PORT'],'DISCHARGE_PORT'=>$rowscoa['DISCHARGE_PORT'],'LAYCAN_SDATE'=>date('d-m-Y',strtotime($rowscoa['LAYCAN_SDATE'])),'LAYCAN_EDATE'=>date('d-m-Y',strtotime($rowscoa['LAYCAN_EDATE'])),'CARGO_RELET'=>$rowscoa['CARGO_RELET'],'NOMCLAUSE'=>$rowscoa['NOMCLAUSE'],'REMARKS'=>$rowscoa['REMARKS'],'RDO_WS_TYPE'=>$rowscoa['RDO_WS_TYPE'],'WS_LUMPSUM_AMOUNT'=>$rowscoa['WS_LUMPSUM_AMOUNT']));
}

function getCOAVCEstimatesDashboard()
{
	$obj 			= new data();
	$connect		= $obj->funConnect();
	$coaid   =  $_REQUEST['coaid'];
	$resultcoa = mysql_query("select * from coa_master where COAID='".$coaid."'") or die;
	$rowscoa   = mysql_fetch_assoc($resultcoa);
	$currencttoshow = $rowscoa['CURRENCY'];
	echo '<div class="row invoice-info">
	            <div class="col-sm-12 invoice-col">
				<strong style="Color:#3c8dbc;">Voyage</strong>
				</div>
          </div>
		  <div class="row invoice-info">
	            <div class="col-sm-12 invoice-col">
				<strong>&nbsp;</strong>
				</div>
          </div>
		  <div class="box-body table-responsive" style="overflow:auto;">';
	echo '<table id="fce_list" class="table table-bordered table-striped">';
	echo '<thead>';
	echo '<tr>';
	echo '<th align="center" valign="middle" width="5%">#</th>';
	echo '<th align="left" valign="middle" width="5%">Nom Date</th>';
	echo '<th align="left" valign="middle" width="5%">COA&nbsp;ID/<br/>Voy&nbsp;No</th>';
	echo '<th align="left" valign="middle" width="5%">Voy Starts</th>';
	echo '<th align="left" valign="middle" width="5%">Voy Ends</th>';
	echo '<th align="left" valign="middle" width="5%">LP/DP</th>';
	echo '<th align="left" valign="middle" width="5%">Cargo(CBM)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</th>';
	echo '<th align="left" valign="middle" width="5%">Cargo(MT)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</th>';
	echo '<th align="left" valign="middle" width="5%">Freight('.$currencttoshow.')&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</th>';
	echo '<th align="left" valign="middle" width="5%">Freight Overage('.$currencttoshow.')&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</th>';
	echo '<th align="left" valign="middle" width="5%">Dem('.$currencttoshow.')&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</th>';
	echo '<th align="left" valign="middle" width="5%">Dead Freight('.$currencttoshow.')</th>';
	echo '<th align="left" valign="middle" width="5%">Bunker Costs ('.$currencttoshow.')</th>';
	echo '<th align="left" valign="middle" width="5%">Port Costs('.$currencttoshow.')</th>';
	echo '<th align="left" valign="middle" width="5%">Total Other Costs('.$currencttoshow.')</th>';
	echo '<th align="left" valign="middle" width="5%">Other Income('.$currencttoshow.')</th>';
	echo '<th align="left" valign="middle" width="5%">Total Rev('.$currencttoshow.')</th>';
	echo '<th align="left" valign="middle" width="5%">Total Costs('.$currencttoshow.')</th>';
	echo '<th align="left" valign="middle" width="5%">Voy Earnings('.$currencttoshow.')</th>';
	echo '</tr>';
	echo '</thead>';
	echo '<tbody id="tbody">';
	$sql = "select freight_cost_estimate_compare.COMID as COMID, COAAID, (select CARGO from coa_master where coa_master.COAID=freight_cost_estimate_compare.COAAID) as CARGOIDD, freight_cost_estimate_compare.FCAID as FCAID, freight_cost_estimete_master.VESSEL_IMO_ID as VESSEL_IMO_ID, freight_cost_estimate_compare.MESSAGE as MESSAGE, freight_cost_estimete_master.COA_SPOT as COA_SPOT, freight_cost_estimete_master.FIXTURETYPEID as FIXTURETYPEID from freight_cost_estimate_compare inner join freight_cost_estimete_master on freight_cost_estimete_master.FCAID= freight_cost_estimate_compare.FCAID WHERE freight_cost_estimate_compare.FINAL_ID!='' and freight_cost_estimete_master.FIXED=1 and COAAID is not NULL and COAAID = '".$coaid."' order by date(freight_cost_estimete_master.TRANS_DATE) desc";
	
	$res = mysql_query($sql) or die($sql);
	$rec = mysql_num_rows($res);
	$i = 1;
	if($rec == 0)
	{
		
	}
	else{
		while($rows = mysql_fetch_assoc($res))
		{			
			$arr_load = $arr_discharge = array();
			$fcaid = $obj->getCompareEstimateData($rows['COMID'],"FCAID");
			$sql1 = "select FROM_PORT, TO_PORT, LOAD_PORT_COST, LOAD_PORT_QTY, DISC_PORT_COST, DISC_PORT_QTY, DDCLP_NETCOST, DDCDP_NETCOST from freight_cost_estimete_slave1 where FCAID='".$fcaid."'";
			$res1 = mysql_query($sql1);
			$demmurage = 0;
			while($row1 = mysql_fetch_assoc($res1))
			{
				if($row1['LOAD_PORT_QTY']>0)
				{
					$arr_load[] = $obj->getPortNameBasedOnID($row1['FROM_PORT']);
				}
				if($row1['DISC_PORT_QTY']>0)
				{
					$arr_discharge[] = $obj->getPortNameBasedOnID($row1['TO_PORT']);
				}
				$demmurage = $demmurage + $row1['DDCLP_NETCOST'] + $row1['DDCDP_NETCOST'];
			}
			
			$sql12 = "select SUM(CARGO_CBM) as SUM, SUM(CARGO_MT) as SUM1 from freight_cost_estimete_slave10 where FCAID='".$fcaid."' and STATUS!=3";
			$res12 = mysql_query($sql12);
			$row12 = mysql_fetch_assoc($res12);
				
			$sql16 = "select SUM(AMOUNT_USD) as SUM from freight_cost_estimete_slave10 where FCAID='".$fcaid."' and STATUS=1";
			$res16 = mysql_query($sql16);
			$row16 = mysql_fetch_assoc($res16);
			
			$sql13 = "select SUM(AMOUNT_USD) as SUM from freight_cost_estimete_slave10 where FCAID='".$fcaid."' and STATUS=2";
			$res13 = mysql_query($sql13);
			$row13 = mysql_fetch_assoc($res13);
			
			$sql14 = "select SUM(AMOUNT_USD) as SUM from freight_cost_estimete_slave10 where FCAID='".$fcaid."' and STATUS=3";
			$res14 = mysql_query($sql14);
			$row14 = mysql_fetch_assoc($res14);
			
			$lk = 0;
			$sql15 = "select RAW_AMOUNT, IDENTY_ID from freight_cost_estimete_slave3 where FCAID='".$fcaid."' and IDENTIFY='OTHERINCOME' and RAW_AMOUNT>0";
			$res15 = mysql_query($sql15);$otherincome = 0;$otherincometext = array();
			while($row15 = mysql_fetch_assoc($res15))
			{$lk++;
				$otherincome = $otherincome + $row15['RAW_AMOUNT'];
				$otherincometext[] = $lk.'.&nbsp;'.$row15['IDENTY_ID'].'&nbsp;-&nbsp;'.$row15['RAW_AMOUNT'];
			}
			
			$sql17 = "select FCAID, SHIPPER_CHARTER, CARGO_CBM, CARGO_MT, STATUS, DEM_AMT, AMOUNT_USD from freight_cost_estimete_slave10 where FCAID='".$fcaid."'";
			$res17 = mysql_query($sql17);
			$demmuragetext = $cargocbm = $cargomt = $freightmtmain = $freightmtoverage = $freightmtdeadfrt = array();$j = 0;$k =0;$l =0;$m=0;
			while($row17 = mysql_fetch_assoc($res17))
			{$j++;if($row17['STATUS']==1){$stat = 'Main&nbsp;Cargo';}if($row17['STATUS']==2){$stat = 'Overage';} if($row17['STATUS']==3){$stat = 'Dead&nbsp;Freight';} 
			    if($row17['STATUS']==1 || $row17['STATUS']==2)
				{
					if($row17['DEM_AMT'] >0)
					{
						$demmuragetext[] = $j.'.&nbsp;'.$obj->getVendorListNewBasedOnID($row17['SHIPPER_CHARTER']).'&nbsp;-&nbsp;'.$stat.'-'.$row17['CARGO_MT'].'&nbsp;-&nbsp;'.$row17['DEM_AMT'];
					}
					$cargocbm[] = $j.'.&nbsp;'.$obj->getVendorListNewBasedOnID($row17['SHIPPER_CHARTER']).'&nbsp;-&nbsp;'.$stat.'-'.$row17['CARGO_CBM'];
					$cargomt[] = $j.'.&nbsp;'.$obj->getVendorListNewBasedOnID($row17['SHIPPER_CHARTER']).'&nbsp;-&nbsp;'.$stat.'-'.$row17['CARGO_MT'];
					if($row17['STATUS']==1)
					{$k++;
						$freightmtmain[] = $k.'.&nbsp;'.$obj->getVendorListNewBasedOnID($row17['SHIPPER_CHARTER']).'&nbsp;-&nbsp;'.$stat.'-'.$row17['CARGO_MT'].'&nbsp;-&nbsp;'.$row17['AMOUNT_USD'];
					}
					if($row17['STATUS']==2)
					{$l++;
						$freightmtoverage[] = $l.'.&nbsp;'.$obj->getVendorListNewBasedOnID($row17['SHIPPER_CHARTER']).'&nbsp;-&nbsp;'.$stat.'-'.$row17['CARGO_MT'].'&nbsp;-&nbsp;'.$row17['AMOUNT_USD'];
					}
				}
				if($row17['STATUS']==3)
				{$m++;
					$freightmtdeadfrt[] = $m.'.&nbsp;'.$obj->getVendorListNewBasedOnID($row17['SHIPPER_CHARTER']).'&nbsp;-&nbsp;'.$stat.'-'.$row17['CARGO_MT'].'&nbsp;-&nbsp;'.$row17['AMOUNT_USD'];
				}
			}
			
			$completiondate = $obj->getReDelDate($rows['COMID']);
			if($completiondate!="" && $completiondate!="1970-01-01")
			{
				$completiondate = date('d-m-Y',strtotime($completiondate));
			}
			
			echo '<tr>';
			echo '<td align="center" valign="middle" class="input-text">'.$i.'.</td>';
			echo '<td align="left" valign="middle" class="input-text">'.date('d-m-Y',strtotime($obj->getCompareEstimateData($rows['COMID'],"TRANS_DATE"))).'</td>';
			echo '<td align="left" valign="middle" class="input-text">'.$rowscoa['COA_ID'].'<br/>'.$obj->getCompareEstimateData($rows['COMID'],"VOYAGE_NO").'</td>';
			echo '<td align="left" valign="middle" class="input-text">'.date('d-m-Y',strtotime($obj->getCompareEstimateData($rows['COMID'],"TRANS_DATE"))).'</td>';
			
			echo '<td align="left" valign="middle" class="input-text">'.$completiondate.'</td>';
			echo '<td align="left" valign="middle" class="input-text">'.implode(', ',$arr_load).'/ '.implode(', ',$arr_discharge).'</td>';
			echo '<td align="left" valign="right" class="input-text">'.$row12['SUM'].'<br/>'.implode('<br/>',$cargocbm).'</td>';
			echo '<td align="left" valign="right" class="input-text">'.$row12['SUM1'].'<br/>'.implode('<br/>',$cargomt).'</td>';
			echo '<td align="left" valign="right" class="input-text">'.$row16['SUM'].'<br/>'.implode('<br/>',$freightmtmain).'</td>';
			echo '<td align="left" valign="right" class="input-text">'.$row13['SUM'].'<br/>'.implode('<br/>',$freightmtoverage).'</td>';
			echo '<td align="left" valign="right" class="input-text">'.$demmurage.'<br/>'.implode('<br/>',$demmuragetext).'</td>';
			echo '<td align="left" valign="right" class="input-text">'.$row14['SUM'].'<br/>'.implode('<br/>',$freightmtdeadfrt).'</td>';
			echo '<td align="left" valign="right" class="input-text">'.$obj->getCompareEstimateData($rows['COMID'],"BUNKER_EXPENSES").'</td>';
			echo '<td align="left" valign="right" class="input-text">'.$obj->getCompareEstimateData($rows['COMID'],"PORT_EXPENSES").'</td>';
			echo '<td align="left" valign="right" class="input-text">0.00</td>';
			echo '<td align="left" valign="right" class="input-text">'.number_format($otherincome,2,'.','').'<br/>'.implode('<br/>',$otherincometext).'</td>';
			echo '<td align="left" valign="right" class="input-text">'.number_format(($row16['SUM'] + $row13['SUM'] + $row14['SUM'] + $demmurage),2,'.','').'</td>';
			echo '<td align="left" valign="right" class="input-text">'.number_format(($obj->getCompareEstimateData($rows['COMID'],"BUNKER_EXPENSES") + $obj->getCompareEstimateData($rows['COMID'],"PORT_EXPENSES") + $row15['SUM']),2,'.','').'</td>';
			echo '<td align="left" valign="right" class="input-text">'.$obj->getCompareEstimateData($rows['COMID'],"VOYAGE_EARNING").'</td>';
			echo '</tr>';
			$i++;
		}
	
	}
	echo '</tbody>';
	echo '</table></div>';
	
	echo '<div class="row invoice-info">
	            <div class="col-sm-12 invoice-col">
				<strong>&nbsp;</strong>
				</div>
          </div>
		  <div class="row invoice-info">
	            <div class="col-sm-12 invoice-col">
				<strong style="Color:#3c8dbc;">Cargo Relets</strong>
				</div>
          </div>
		  <div class="row invoice-info">
	            <div class="col-sm-12 invoice-col">
				<strong>&nbsp;</strong>
				</div>
          </div>';
	echo '<div class="box-body table-responsive" style="overflow:auto;">';
	echo '<table id="relet_list" class="table table-bordered table-striped">';
	echo '<thead>';
	echo '<tr>';
	echo '<th align="center" valign="middle" width="5%">#</th>';
	echo '<th align="left" valign="middle" width="12%">COA ID / No.</th>';
	echo '<th align="left" valign="middle" width="10%">Relet No.</th>';
	echo '<th align="left" valign="middle" width="10%">COA Date</th>';
	echo '<th align="left" valign="middle" width="10%">Cargo Quantity(MT)</th>';
	echo '<th align="left" valign="middle" width="10%">LP/DP</th>';
	echo '<th align="left" valign="middle" width="6%">Frt-IN ('.$currencttoshow.'/MT)</th>';
	echo '<th align="left" valign="middle" width="10%">Frt-IN ('.$currencttoshow.')</th>';
	echo '<th align="left" valign="middle" width="10%">FO Surcharge('.$currencttoshow.')</th>';
	echo '<th align="left" valign="middle" width="5%">Frt-OUT ('.$currencttoshow.'/MT)</th>';
	echo '<th align="left" valign="middle" width="5%">Frt-OUT ('.$currencttoshow.')</th>';
	echo '<th align="left" valign="middle" width="5%">Proﬁt('.$currencttoshow.')</th>';
	echo '</tr>';
	echo '</thead>';
	echo '<tbody id="tbody1">';
	
	$sql = "select FCAID, VESSEL_IMO_ID, COAID, CARGO_RELET_NO, CARGO_QMT_MT, FREIGHT_USD, FREIGHT_AMT, BUNKER_SURCHARGE_AMT, TOTAL_AMT, PROFIT, FREIGHT_USD_OUT, FREIGHT_AMT_OUT, BUSINESSTYPEID, FIXED, COMID from cargo_relet_estimate_masster WHERE MODULEID='".$_SESSION['moduleid']."' AND MCOMPANYID='".$_SESSION['company']."' and BUSINESSTYPEID='".$_SESSION['selBType']."' and SHEET_NO is NULL and COAID='".$coaid."' order by FCAID desc";
	
	$res = mysql_query($sql) or die($sql);
	$rec = mysql_num_rows($res);
	$i = 1;
	if($rec == 0)
	{
		
	}
	else{
		while($rows = mysql_fetch_assoc($res))
		{
			$arr_load = $arr_discharge = array();
			$sql1 = "select * from cargo_relet_estimate_slave2 where FCAID='".$rows['FCAID']."' and IDENTIFY='IN'";
			$res1 = mysql_query($sql1);
			while($row1 = mysql_fetch_assoc($res1))
			{
				if($row1['PORT_TYPE']=='LP')
				{
					$arr_load[] = $obj->getPortNameBasedOnID($row1['PORTID']);
				}
				if($row1['PORT_TYPE']=='DP')
				{
					$arr_discharge[] = $obj->getPortNameBasedOnID($row1['PORTID']);
				}
			}
				
			
			echo '<tr>';
			echo '<td align="center" valign="middle" class="input-text">'.$i.'.</td>';
			echo '<td align="left" valign="middle" class="input-text">'.$obj->getCOANumberDataBasedOnID($rows['COAID'],'COA_ID').'/ '.$obj->getCOANumberDataBasedOnID($rows['COAID'],'COA_NO').'</td>';
			echo '<td align="left" valign="middle" class="input-text">'.$rows['CARGO_RELET_NO'].'</td>';
			$coadate = $obj->getCOANumberDataBasedOnID($rows['COAID'],'COA_DATE');
			if($coadate=="" || $coadate=="1970-01-01"){$coadate = "";}else{$coadate = date('d-m-Y',strtotime($coadate));}
			echo '<td align="left" valign="middle" class="input-text">'.$coadate.'</td>';
			echo '<td align="left" valign="middle" class="input-text">'.$rows['CARGO_QMT_MT'].'</td>';
			echo '<td align="left" valign="middle" class="input-text">'.implode(', ',$arr_load).'/ '.implode(', ',$arr_discharge).'</td>';
			echo '<td align="left" valign="middle" class="input-text">'.$rows['FREIGHT_USD'].'</td>';
			echo '<td align="left" valign="middle" class="input-text">'.$rows['FREIGHT_AMT'].'</td>';
			echo '<td align="left" valign="middle" class="input-text">'.$rows['BUNKER_SURCHARGE_AMT'].'</td>';
			echo '<td align="left" valign="middle" class="input-text">'.$rows['FREIGHT_USD_OUT'].'</td>';
			echo '<td align="left" valign="middle" class="input-text">'.$rows['FREIGHT_AMT_OUT'].'</td>';
			echo '<td align="left" valign="middle" class="input-text">'.$rows['PROFIT'].'</td>';
			
			
			echo '</tr>';
			$i++;
		}
	
	}
	echo '</tbody>';
	echo '</table></div>';
}


function getCOAListjson()
{
	$obj = new data();
	$connect=$obj->funConnect();
	$_SESSION['selBType'] = $_POST['businesstype'];
	$aColumns = array("COAID", "COA_ROUTE", "COA_ID", "COA_NO", "COA_DATE", "VESSEL_TYPE", "CHARTERER", "CARGO", "MIN_GUARANTEED_QTY", "COA_DURATION", "TOTAL_SHIPMENTS", "LEGS");
	
	$sIndexColumn = "COAID";
	
	$sTable = "coa_master";
	
	if(!empty($_POST['order'][0]['column']))
	{
		$sOrder = "ORDER BY  ".$aColumns[intval($_POST['order'][0]['column'])]." ".$_POST['order'][0]['dir'];
	}
	else
	{
		$sOrder = "ORDER BY COAID";
	}
	
	$sWhere = "";
	
	if ($_POST['search']['value']!= "")
	{
		$sWhere = " and BUSINESSTYPEID='".$_POST['search']['value']."' (COA_ROUTE LIKE '%".$_POST['search']['value']."%' or COA_ID LIKE '%".$_POST['search']['value']."%' or COA_NO LIKE '%".$_POST['search']['value']."%' or COA_DATE LIKE '%".$_POST['search']['value']."%' or VESSEL_TYPE LIKE '%".$_POST['search']['value']."%' or CHARTERER LIKE '%".$_POST['search']['value']."%' or CARGO LIKE '%".$_POST['search']['value']."%' or MIN_GUARANTEED_QTY LIKE '%".$_POST['search']['value']."%' or TOTAL_SHIPMENTS LIKE '%".$_POST['search']['value']."%' or LEGS LIKE '%".$_POST['search']['value']."%') ";
	}else{$sWhere = " and BUSINESSTYPEID='".$_POST['businesstype']."' ";}
	
	if($_POST['txtFromDate']!='' && $_POST['txtToDate']!='')
	{
		$sWhere = $sWhere." and COA_DATE >='".date('Y-m-d',strtotime($_POST['txtFromDate']))."' and COA_DATE <='".date('Y-m-d',strtotime($_POST['txtToDate']))."' ";
	}
	
	$sQuery = "SELECT * FROM (select COAID, MODULEID, MCOMPANYID, (select COAROUTE_NAME from coaroute_master where coaroute_master.COAROUTEID = coa_master.COA_ROUTE) as COA_ROUTE, COA_ID, COA_NO, COA_DATE, (select VesselType from vessel_type_master where vessel_type_master.VesselTypeId=coa_master.VESSEL_TYPE) as VESSEL_TYPE, COA_DURATION, (select CONCAT(NAME, '(',CODE,')') as CHARTERER from vendor_master where vendor_master.CODE=coa_master.CHARTERER) as CHARTERER, BUSINESSTYPEID, UPDATE_STATUS, (select GROUP_CONCAT(COMID) as COMID from freight_cost_estimate_compare where freight_cost_estimate_compare.COAAID=coa_master.COAID) as COMID, (select GROUP_CONCAT(COMID) as COMID from cargo_relet_estimate_compare where cargo_relet_estimate_compare.COAAID=coa_master.COAID) as COMID1, (select CONCAT(MATERIAL_CODE_DESC, '(' ,MATERIAL_CODE,')') as CARGO from cargo_master where cargo_master.MATERIALID=coa_master.CARGO) as CARGO, MIN_GUARANTEED_QTY, TOTAL_SHIPMENTS, (select COUNT(*) as LEGS from freight_cost_estimate_compare where freight_cost_estimate_compare.COAAID=coa_master.COAID) as LEGS, (select COUNT(*) as LEGS from cargo_relet_estimate_compare where cargo_relet_estimate_compare.COAAID=coa_master.COAID) as LEGS1 from coa_master) as innerTable where MCOMPANYID='".$_SESSION['company']."' $sWhere $sOrder LIMIT ".$_POST['start'].", ".$_POST['length']."";
	$rResult = mysql_query($sQuery) or die($sQuery);
	
	$sQuery = "	SELECT COUNT(".$sIndexColumn.") FROM (select * from coa_master) as innerTable $sWhere";
	
	$rResultFilterTotal = mysql_query($sQuery);
	$aResultFilterTotal = mysql_fetch_array($rResultFilterTotal);
	$totalFiltered = $aResultFilterTotal[0];
	
	$sQuery = " SELECT COUNT(".$sIndexColumn.") FROM $sTable";
	$rResultTotal = mysql_query($sQuery);
	$aResultTotal = mysql_fetch_array($rResultTotal);
	$totalFiltered = $totalData = $aResultTotal[0];
	
	$aaData = array();
	$i = $_POST['start'];
	while ( $aRow = mysql_fetch_array( $rResult ) )
	{
		$row = array(); $i = $i+1;
		$cargomt = 0;
		
		if($aRow['COMID']!='')
		{   
		    $comids = explode(',',$aRow['COMID']);
			for($lk = 0;$lk <count($comids);$lk++)
			{
				$sql1 = "select SUM(CARGO_MT) as SUM from freight_cost_estimete_slave10 where FCAID='".$obj->getCompareEstimateData($comids[$lk],"FCAID")."' and STATUS!=3";
				$res1 = mysql_query($sql1) or die($sql1);
				$rows1 = mysql_fetch_assoc($res1);
				$cargomt = $cargomt + $rows1['SUM'];
			}
		}
		if($aRow['COMID1']!='')
		{
			$comids1 = explode(',',$aRow['COMID1']);
			for($lk = 0;$lk <count($comids1);$lk++)
			{  
				$sql1 = "select SUM(CARGO_QMT_MT) as SUM from cargo_relet_estimate_masster where FCAID='".$obj->getCompareCargoReletData($comids1[$lk],"FCAID")."'";
				$res1 = mysql_query($sql1) or die($sql1);
				$rows1 = mysql_fetch_assoc($res1);
				$cargomt = $cargomt + $rows1['SUM'];
			}
		}
		//echo $cargomt;
		$details = $details1 = '';
		if($_POST['gridtype']==1)
		{
			$details = '<strong><a href="#" title="View Details" data-toggle="modal" data-target="#compose-modal" onclick="getListOFEstimate('.$aRow['COAID'].','.$i.');"><button type="button" class="btn btn-warning btn-flat">Details</button></a></strong>';
			
		}
		else
		{
			$details = '<strong><a href="#" title="View Details" data-toggle="modal" data-target="#compose-modal" onclick="getListOFEstimate('.$aRow['COAID'].','.$i.');"><button type="button" class="btn btn-warning btn-flat">Nominate</button></a></strong>';
			if($obj->getPerformedVesselRec($aRow['COAID']) == 0 && $aRow['UPDATE_STATUS']<=1)
			{
				$details1 ='<a href="cancel_coa.php?id='.$aRow['COAID'].'" title="Cancel COA" ><i class="fa fa-times" style="color:red;"></i></a>&nbsp;&nbsp;|&nbsp;';
			}
			$details1.='&nbsp;<a href="updatecoa.php?id='.$aRow['COAID'].'" title="Edit Details" ><i class="fa fa-edit "></i></a>';
		}
		
		$aaData[] = array('col1'=>$i.'.', 'col2'=>$aRow['COA_ROUTE'], 'col3'=>'<span id="coaid_'.$i.'">'.$aRow['COA_ID'].'</span>', 'col4'=>$aRow['COA_NO'], 'col5'=>date('d-m-Y',strtotime($aRow['COA_DATE'])), 'col6'=>$aRow['VESSEL_TYPE'], 'col7'=>$aRow['CHARTERER'], 'col8'=>$aRow['CARGO'], 'col9'=>$aRow['MIN_GUARANTEED_QTY'], 'col10'=>$aRow['COA_DURATION'], 'col11'=>$aRow['TOTAL_SHIPMENTS'], 'col12'=>$aRow['LEGS'] + $aRow['LEGS1'], 'col13'=>number_format(($aRow['MIN_GUARANTEED_QTY'] - $cargomt),2,'.',''), 'col14'=>$details, 'col15'=>$details1);
		
	}
	
	echo json_encode(array("draw"=>intval($_POST['draw']),"recordsTotal"=>$totalData,"recordsFiltered"=>$totalFiltered,"records" => $aaData));
}


function getCOAVCEstimates()
{
	$obj 			= new data();
	$connect		= $obj->funConnect();
	$rigtscoa       = explode(',',$obj->getUserRights($_SESSION['uid'],$_SESSION['moduleid'],14));
	$coaid   =  $_REQUEST['coaid'];
	$result = mysql_query("select * from coa_master where COAID='".$coaid."'") or die;
	$rows   = mysql_fetch_assoc($result);
	$currencttoshow = $rows['CURRENCY'];
	echo '<div class="row invoice-info" id="addnewbutton">
	            <div class="col-sm-6 invoice-col">
				<strong>Voyages</strong>
				</div>
				<div class="col-sm-6 invoice-col" style="text-align:right;">
					<address>';
					if(in_array(2, $rigtscoarelet) || in_array(3, $rigtscoa)){
	                    echo '<a href="addcoacargorelet.php?coaid='.$coaid.'&page=1"><button type="button" class="btn btn-warning btn-flat" >Add New Cargo Relet</button></a>&nbsp;&nbsp;&nbsp;&nbsp;';
	                }
					if(in_array(2, $rigtscoarelet) || in_array(3, $rigtscoa)){
					   echo '&nbsp;&nbsp;&nbsp;&nbsp;<a href="addcoaestimates.php?coaid='.$coaid.'&page=1"><button type="button" class="btn btn-info btn-flat" >Add New Voyage</button></a>';
					}
			echo '</address>
				</div>
            </div>';
	echo '<div class="box-body table-responsive" style="overflow:auto;">';
	echo '<table id="fce_list" class="table table-bordered table-striped">';
	echo '<thead>';
	echo '<tr>';
	echo '<th align="center" valign="middle" width="5%">#</th>';
	echo '<th align="left" valign="middle" width="12%">Vessel Name/Type</th>';
	echo '<th align="left" valign="middle" width="10%">COA ID/NO</th>';
	echo '<th align="left" valign="middle" width="10%">Voyage No.</th>';
	echo '<th align="left" valign="middle" width="10%">COA Date</th>';
	echo '<th align="left" valign="middle" width="10%">DWT</th>';
	echo '<th align="left" valign="middle" width="6%">LP/DP</th>';
	echo '<th align="left" valign="middle" width="10%">Duration</th>';
	echo '<th align="left" valign="middle" width="10%">Cargo Quantity</th>';
	echo '<th align="left" valign="middle" width="5%">TCE</th>';
	echo '<th align="left" valign="middle" width="5%">Daily Time Charter <span style="font-size:10px; font-style:italic;">('.$currencttoshow.'/Day)</span></th>';
	echo '<th align="left" valign="middle" width="5%">P/L</th>';
	echo '<th align="center" valign="middle" width="7%">Details</th>';
	echo '</tr>';
	echo '</thead>';
	echo '<tbody id="tbody">';
	$sql = "select FCAID, VESSEL_IMO_ID, COAID, VOYAGE_NO, VESSEL_TYPE, FREIGHT_GROSS, TOTAL_DAYS, DAILY_EARNING, DAILY_VESSEL_OPERATION_EXP, PROFIT_LOSS, ESTIMATE_TYPE, FIXED, COMID from freight_cost_estimete_master WHERE MODULEID='".$_SESSION['moduleid']."' AND MCOMPANYID='".$_SESSION['company']."' and ESTIMATE_TYPE='".$_SESSION['selBType']."' and SHEET_NO is NULL and COAID='".$coaid."' order by FCAID desc";
	
	$res = mysql_query($sql) or die($sql);
	$rec = mysql_num_rows($res);
	$i = 1;
	if($rec == 0)
	{
		
	}
	else{
		while($rows = mysql_fetch_assoc($res))
		{
			$arr_load = $arr_discharge = array();
			$sql1 = "select FROM_PORT, TO_PORT, LOAD_PORT_COST, LOAD_PORT_QTY, DISC_PORT_COST, DISC_PORT_QTY from freight_cost_estimete_slave1 where FCAID='".$rows['FCAID']."'";
			$res1 = mysql_query($sql1);
			while($row1 = mysql_fetch_assoc($res1))
			{
				if($row1['LOAD_PORT_QTY']>0)
				{
					$arr_load[] = $obj->getPortNameBasedOnID($row1['FROM_PORT']);
				}
				if($row1['DISC_PORT_QTY']>0)
				{
					$arr_discharge[] = $obj->getPortNameBasedOnID($row1['TO_PORT']);
				}
			}
			
			$quantity = 0;
			
			$sql12 = "select sum(CARGO_MT) as sum from freight_cost_estimete_slave10 where FCAID='".$rows['FCAID']."' and STATUS!=3";
			$res12 = mysql_query($sql12);
			$row12 = mysql_fetch_assoc($res12);
			$quantity = $row12['sum'];
				
			
			echo '<tr>';
			echo '<td align="center" valign="middle" class="input-text">'.$i.'.</td>';
			echo '<td align="left" valign="middle" class="input-text">'.$obj->getVesselIMOData($rows['VESSEL_IMO_ID'],"VESSEL_NAME").'/ '.$rows['VESSEL_TYPE'].'</td>';
			echo '<td align="left" valign="middle" class="input-text">'.$obj->getCOANumberDataBasedOnID($rows['COAID'],'COA_ID').'<br/>'.$obj->getCOANumberDataBasedOnID($rows['COAID'],'COA_NO').'</td>';
			echo '<td align="left" valign="middle" class="input-text">'.$rows['VOYAGE_NO'].'</td>';
			$coadate = $obj->getCOANumberDataBasedOnID($rows['COAID'],'COA_DATE');
			if($coadate=="" || $coadate=="1970-01-01"){$coadate = "";}else{$coadate = date('d-m-Y',strtotime($coadate));}
			echo '<td align="left" valign="middle" class="input-text">'.$coadate.'</td>';
			echo '<td align="left" valign="middle" class="input-text">'.$obj->getVesselIMOData($rows['VESSEL_IMO_ID'],"DWT").'</td>';
			echo '<td align="left" valign="middle" class="input-text">'.implode(', ',$arr_load).'/ '.implode(', ',$arr_discharge).'</td>';
			echo '<td align="left" valign="middle" class="input-text">'.$rows['TOTAL_DAYS'].'</td>';
			echo '<td align="left" valign="middle" class="input-text">'.$quantity.'</td>';
			echo '<td align="left" valign="middle" class="input-text">'.$rows['DAILY_EARNING'].'</td>';
			echo '<td align="left" valign="middle" class="input-text">'.$rows['DAILY_VESSEL_OPERATION_EXP'].'</td>';
			echo '<td align="left" valign="middle" class="input-text">'.$rows['PROFIT_LOSS'].'</td>';
			
			if($rows['COMID']=="" || $rows['COMID']==0)
			{
				echo '<td align="center" valign="middle" class="input-text"><a href="updatecoaestimates.php?id='.$rows['FCAID'].'&coaid='.$rows['COAID'].'" title="Edit Details" ><i class="fa fa-edit "></i></a>&nbsp;|&nbsp;<a title="Delete Link" href="#Delete" onclick="return getDelete('.$rows['FCAID'].');" ><i class="fa fa-times" style="color:red;"></i></td>';
			}
			else
			{
				echo '<td align="center" valign="middle"><a href="viewcoaestimates.php?id='.$rows['FCAID'].'&coaid='.$rows['COAID'].'&page=1" title="Edit Details" style="font-size:16px; font-weight:bold;"><i class="fa fa-file-text-o" aria-hidden="true"></i></a></td>';
			}
			echo '</tr>';
			$i++;
		}
	
	}
	echo '</tbody>';
	echo '</table></div>';
	
	echo '<div class="row invoice-info">
	            <div class="col-sm-12 invoice-col">
				<strong>&nbsp;</strong>
				</div>
          </div>
		  <div class="row invoice-info">
	            <div class="col-sm-12 invoice-col">
				<strong>Cargo Relets</strong>
				</div>
          </div>
		  <div class="row invoice-info">
	            <div class="col-sm-12 invoice-col">
				<strong>&nbsp;</strong>
				</div>
          </div>';
	echo '<div class="box-body table-responsive" style="overflow:auto;">';
	echo '<table id="relet_list" class="table table-bordered table-striped">';
	echo '<thead>';
	echo '<tr>';
	echo '<th align="center" valign="middle" width="5%">#</th>';
	echo '<th align="left" valign="middle" width="12%">COA ID / No.</th>';
	echo '<th align="left" valign="middle" width="10%">Relet No.</th>';
	echo '<th align="left" valign="middle" width="10%">COA Date</th>';
	echo '<th align="left" valign="middle" width="10%">Cargo Quantity(MT)</th>';
	echo '<th align="left" valign="middle" width="10%">LP/DP</th>';
	echo '<th align="left" valign="middle" width="6%">Frt-IN ('.$currencttoshow.'/MT)</th>';
	echo '<th align="left" valign="middle" width="10%">Frt-IN ('.$currencttoshow.')</th>';
	echo '<th align="left" valign="middle" width="10%">FO Surcharge('.$currencttoshow.')</th>';
	echo '<th align="left" valign="middle" width="5%">Frt-OUT ('.$currencttoshow.'/MT)</th>';
	echo '<th align="left" valign="middle" width="5%">Frt-OUT ('.$currencttoshow.')</th>';
	echo '<th align="left" valign="middle" width="5%">Proﬁt('.$currencttoshow.')</th>';
	echo '<th align="center" valign="middle" width="7%">Details</th>';
	echo '</tr>';
	echo '</thead>';
	echo '<tbody id="tbody1">';
	
	$sql = "select FCAID, VESSEL_IMO_ID, COAID, CARGO_RELET_NO, CARGO_QMT_MT, FREIGHT_USD, FREIGHT_AMT, BUNKER_SURCHARGE_AMT, TOTAL_AMT, PROFIT, FREIGHT_USD_OUT, FREIGHT_AMT_OUT, BUSINESSTYPEID, FIXED, COMID from cargo_relet_estimate_masster WHERE MODULEID='".$_SESSION['moduleid']."' AND MCOMPANYID='".$_SESSION['company']."' and BUSINESSTYPEID='".$_SESSION['selBType']."' and SHEET_NO is NULL and COAID='".$coaid."' order by FCAID desc";
	
	$res = mysql_query($sql) or die($sql);
	$rec = mysql_num_rows($res);
	$i = 1;
	if($rec == 0)
	{
		
	}
	else{
		while($rows = mysql_fetch_assoc($res))
		{
			$arr_load = $arr_discharge = array();
			$sql1 = "select * from cargo_relet_estimate_slave2 where FCAID='".$rows['FCAID']."' and IDENTIFY='IN'";
			$res1 = mysql_query($sql1);
			while($row1 = mysql_fetch_assoc($res1))
			{
				if($row1['PORT_TYPE']=='LP')
				{
					$arr_load[] = $obj->getPortNameBasedOnID($row1['PORTID']);
				}
				if($row1['PORT_TYPE']=='DP')
				{
					$arr_discharge[] = $obj->getPortNameBasedOnID($row1['PORTID']);
				}
			}
				
			
			echo '<tr>';
			echo '<td align="center" valign="middle" class="input-text">'.$i.'.</td>';
			echo '<td align="left" valign="middle" class="input-text">'.$obj->getCOANumberDataBasedOnID($rows['COAID'],'COA_ID').'/ '.$obj->getCOANumberDataBasedOnID($rows['COAID'],'COA_NO').'</td>';
			echo '<td align="left" valign="middle" class="input-text">'.$rows['CARGO_RELET_NO'].'</td>';
			$coadate = $obj->getCOANumberDataBasedOnID($rows['COAID'],'COA_DATE');
			if($coadate=="" || $coadate=="1970-01-01"){$coadate = "";}else{$coadate = date('d-m-Y',strtotime($coadate));}
			echo '<td align="left" valign="middle" class="input-text">'.$coadate.'</td>';
			echo '<td align="left" valign="middle" class="input-text">'.$rows['CARGO_QMT_MT'].'</td>';
			echo '<td align="left" valign="middle" class="input-text">'.implode(', ',$arr_load).'/ '.implode(', ',$arr_discharge).'</td>';
			echo '<td align="left" valign="middle" class="input-text">'.$rows['FREIGHT_USD'].'</td>';
			echo '<td align="left" valign="middle" class="input-text">'.$rows['FREIGHT_AMT'].'</td>';
			echo '<td align="left" valign="middle" class="input-text">'.$rows['BUNKER_SURCHARGE_AMT'].'</td>';
			echo '<td align="left" valign="middle" class="input-text">'.$rows['FREIGHT_USD_OUT'].'</td>';
			echo '<td align="left" valign="middle" class="input-text">'.$rows['FREIGHT_AMT_OUT'].'</td>';
			echo '<td align="left" valign="middle" class="input-text">'.$rows['PROFIT'].'</td>';
			
			if($rows['COMID']=="")
			{
				echo '<td align="center" valign="middle" class="input-text"><a href="updatecoacargorelet.php?id='.$rows['FCAID'].'&coaid='.$rows['COAID'].'" title="Edit Details" ><i class="fa fa-edit "></i></a>&nbsp;|&nbsp;<a title="Delete Link" href="#Delete" onclick="return getDelete1('.$rows['FCAID'].');" ><i class="fa fa-times" style="color:red;"></i></td>';
			}
			else
			{
				echo '<td align="center" valign="middle"><a href="viewcoacargorelet.php?id='.$rows['FCAID'].'&coaid='.$rows['COAID'].'&page=1" title="Edit Details" style="font-size:16px; font-weight:bold;"><i class="fa fa-file-text-o" aria-hidden="true"></i></a></td>';
			}
			echo '</tr>';
			$i++;
		}
	
	}
	echo '</tbody>';
	echo '</table></div>';
}


function getCharteringRegisterDataTC()
{
	$obj 		  = new data();
	$connect	  = $obj->funConnect();
	
	$txtFrom_Date = date('Y-m-d',strtotime($_REQUEST['txtFrom_Date']));
	$txtTo_Date   =  date('Y-m-d',strtotime($_REQUEST['txtTo_Date']));
	$selBType     = $_REQUEST['selBType'];
	
	$sql = "select chartering_estimate_tc_compare.COMID as COMID, chartering_estimate_tc_master.VESSEL_IMO_ID as VESSEL_IMO_ID, chartering_estimate_tc_compare.MESSAGE as MESSAGE, chartering_estimate_tc_master.CP_DATE1 as CP_DATE, chartering_estimate_tc_master.SUMMER_DWT, chartering_estimate_tc_master.TCOUTID as TCOUTID, chartering_estimate_tc_master.TC_NO as TC_NO from chartering_estimate_tc_compare inner join chartering_estimate_tc_master on chartering_estimate_tc_master.TCOUTID= chartering_estimate_tc_compare.TCOUTID WHERE chartering_estimate_tc_compare.MODULEID='".$_SESSION['moduleid']."' AND chartering_estimate_tc_compare.MCOMPANYID='".$_SESSION['company']."' and chartering_estimate_tc_compare.FINAL_ID!='' and chartering_estimate_tc_master.FIXED=1 and chartering_estimate_tc_compare.STATUS in (1,2,4) and chartering_estimate_tc_master.TC_DATE>='".$txtFrom_Date."' and chartering_estimate_tc_master.TC_DATE<='".$txtTo_Date."'  and chartering_estimate_tc_master.ESTIMATE_TYPE='".$selBType."' and chartering_estimate_tc_master.SHEET_NO is NULL and chartering_estimate_tc_compare.COMID>0"; 
	$res 		  = mysql_query($sql) or die($sql);
	$rec     	  = mysql_num_rows($res);
	$j=1;
	$cost_sheet_id = "";
	$arr = array();
	
	echo '<table id="sf_list" class="table table-bordered table-striped dataTable">
		<thead>
			<tr>
				<th rowspan="2" align="left" valign="top" width="10%">Sr.&nbsp;No.</th>
				<th rowspan="2" align="left" valign="top" width="10%">Nom&nbsp;ID</th>
				<th rowspan="2" align="left" valign="top" width="10%">TC No.</th>
				<th rowspan="2" align="left" valign="top" width="10%">Vessel&nbsp;Name</th>	
				<th rowspan="2" align="left" valign="top" width="10%">DWT(MT)</th>	
				<th rowspan="2" align="left" valign="top" width="10%">CP&nbsp;Date</th>
				<th rowspan="2" align="left" valign="top" width="10%" style="min-width:100px;">Charterer</th>
				<th rowspan="2" align="left" valign="top" width="10%" style="min-width:100px;">Port Del/ Port Re-Del</th>
				<th rowspan="2" align="left" valign="top" width="18%" style="min-width:100px;">Del/Re-Del Dates</th>
				<th colspan="6" align="left" valign="top" width="10%">Initial&nbsp;P&nbsp;&&nbsp;L</th>
				<th colspan="6" align="left" valign="top" width="10%">Final&nbsp;P&nbsp;&&nbsp;L</th>
			</tr>
			<tr>
				<th align="left" valign="top" width="10%">Total Rev(USD)</th>
				<th align="left" valign="top" width="10%" style="min-width:120px;">Other Expenses(USD)</th>
				<th align="left" valign="top" width="10%">TC In-Hire Expense(USD)</th>
				<th align="left" valign="top" width="10%">Total Exp(USD)</th>
				<th align="left" valign="top" width="10%">TC Earnings</th>
				<th align="left" valign="top" width="10%">Profit/ Day (USD)</th>
				
				<th align="left" valign="top" width="10%">Total Rev(USD)</th>
				<th align="left" valign="top" width="10%" style="min-width:120px;">Other Expenses(USD)</th>
				<th align="left" valign="top" width="10%">TC In-Hire Expense(USD)</th>
				<th align="left" valign="top" width="10%">Total Exp(USD)</th>
				<th align="left" valign="top" width="10%">TC Earnings</th>
				<th align="left" valign="top" width="10%">Profit/ Day (USD)</th>
			</tr>
		</thead>
	<tbody>';
	
	if($rec == 0)
	{
		
	}else{
	
		while($rows = mysql_fetch_assoc($res))
		{
			$sqldel = "select DEL_DATE_EST from chartering_tc_estimate_slave1 where TCOUTID=".$rows['TCOUTID']." order by TC_SLAVE1ID ASC";
			$resultdel = mysql_query($sqldel);
			$rowsdel = mysql_fetch_assoc($resultdel);
			$sqlredel = "select REDEL_DATE_EST from chartering_tc_estimate_slave1 where TCOUTID=".$rows['TCOUTID']." order by TC_SLAVE1ID DESC";
			$resultredel = mysql_query($sqlredel);
			$rowsredel = mysql_fetch_assoc($resultredel);
			
			$l_cost_sheet_id = $obj->getLatestCostSheetIDTC($rows['COMID']);
			$cpdate = $obj->getCharteringEstimateTCData($rows['COMID'],"CP_DATE1");
			if($cpdate!="0000-00-00" && $cpdate!=""){$cpdate = date('d-m-Y',strtotime($cpdate));}else{$cpdate = "";}
			echo '<tr>';
			echo '<td align="center" valign="middle">'.$j.'</td>';
			echo '<td align="left" valign="middle">'.$rows['MESSAGE'].'</td>';
			echo '<td align="left" valign="middle">'.$rows['TC_NO'].'</td>';
			echo '<td align="left" valign="middle">'.$obj->getVesselIMOData($rows['VESSEL_IMO_ID'],"VESSEL_NAME").'</td>';
			echo '<td align="left" valign="middle">'.$rows['SUMMER_DWT'].'</td>';
			echo '<td align="left" valign="middle">'.$cpdate.'</td>';
			echo '<td align="left" valign="middle">'.$obj->getVendorListNewBasedOnID($obj->getCharteringEstimateTCData($rows['COMID'],"SEL_CHARTERER")).'</td>';
			echo '<td align="left" valign="middle">'.$obj->getCharteringEstimateTCData($rows['COMID'],"DEL_RANGE_PORT").' <br/><br/>'.$obj->getCharteringEstimateTCData($rows['COMID'],"RE_DEL_RANGE").'</td>';
			echo '<td align="left" valign="middle">'.date('d-m-Y H:i',strtotime($rowsdel['DEL_DATE_EST'])).' <br/>'.date('d-m-Y H:i',strtotime($rowsredel['REDEL_DATE_EST'])).'</td>';
			
			$revenue = $otherexpense = $totalexpense = $tchirein = $earning = $hiredays = 0;
			$othertext = array();
			$sqlfirst = "select TCOUTID from chartering_estimate_tc_master where COMID=".$rows['COMID']." and SHEET_NO is NULL";
			$resulfirst = mysql_query($sqlfirst);$i = 0;
			while($rowsfirst = mysql_fetch_assoc($resulfirst))
			{$i++;
			    if($i==1)
				{
					$sqlfrst1 = "select TOTAL_REV_EST, NET_HIREAGE, TOTAL_EXP_EST, VOYAGE_EARN_EST, UTILISATION_DAY_EST, TC_SLAVE1ID from chartering_tc_estimate_slave1 where TCOUTID=".$rowsfirst['TCOUTID']."";
					$resulfrst1 = mysql_query($sqlfrst1);
					while($rowsfrst1 = mysql_fetch_assoc($resulfrst1))
					{
						$revenue           = $revenue + $rowsfrst1['TOTAL_REV_EST'];
						$tchirein          = $tchirein + $rowsfrst1['NET_HIREAGE'];
						$totalexpense      = $totalexpense + $rowsfrst1['TOTAL_EXP_EST'];
						$earning           = $earning + $rowsfrst1['VOYAGE_EARN_EST'];
						$hiredays          = $hiredays + $rowsfrst1['UTILISATION_DAY_EST'];
						$sqlfrst2 = "select * from chartering_estimate_tc_slave2 where TC_SLAVE1ID=".$rowsfrst1['TC_SLAVE1ID']." and STATUS=2 and CHK_ADDTTL=1";
						$resulfrst2 = mysql_query($sqlfrst2);
						while($rowsfrst2 = mysql_fetch_assoc($resulfrst2))
						{
							$otherexpense      = $otherexpense + $rowsfrst2['OTHER_AMT'];
							$othertext[] = $obj->getExpenseTypeNameBasedOnID($rowsfrst2['EXPENSETYPEID'])." (".$rowsfrst2['DESCRIPTION'].") - ".$rowsfrst2['OTHER_AMT'];
						}
					}
				}
			}
			
			echo '<td align="left" valign="middle">'.$revenue.'</td>';
			echo '<td align="left" valign="middle">'.$otherexpense.'<br/>'.implode('<br/>',$othertext).'</td>';
			echo '<td align="left" valign="middle">'.$tchirein.'</td>';
			echo '<td align="left" valign="middle">'.$totalexpense.'</td>';
			echo '<td align="left" valign="middle">'.$earning.'</td>';
			echo '<td align="left" valign="middle">'.number_format($earning/$hiredays,2,'.','').'</td>';
			
			$revenue = $otherexpense = $totalexpense = $tchirein = $earning = $hiredays = 0;
			$othertext = array();$i = 0;
			$sqllast = "select TCOUTID from chartering_estimate_tc_master where COMID=".$rows['COMID']." and SHEET_NO is not NULL order by TCOUTID desc";
			$resullast = mysql_query($sqllast);
			while($rowslast = mysql_fetch_assoc($resullast))
			{$i++;
			    if($i==1)
				{
					$sqllast1 = "select TOTAL_REV_EST, NET_HIREAGE, TOTAL_EXP_EST, VOYAGE_EARN_EST, UTILISATION_DAY_EST, TC_SLAVE1ID from chartering_tc_estimate_slave1 where TCOUTID=".$rowslast['TCOUTID']."";
					$resullast1 = mysql_query($sqllast1);
					while($rowslast1 = mysql_fetch_assoc($resullast1))
					{
						$revenue           = $revenue + $rowslast1['TOTAL_REV_EST'];
						$tchirein          = $tchirein + $rowslast1['NET_HIREAGE'];
						$totalexpense      = $totalexpense + $rowslast1['TOTAL_EXP_EST'];
						$earning           = $earning + $rowslast1['VOYAGE_EARN_EST'];
						$hiredays          = $hiredays + $rowslast1['UTILISATION_DAY_EST'];
						$sqllast2 = "select * from chartering_estimate_tc_slave2 where TC_SLAVE1ID=".$rowslast1['TC_SLAVE1ID']." and STATUS=2 and CHK_ADDTTL=1";
						$resullast2 = mysql_query($sqllast2);
						while($rowslast2 = mysql_fetch_assoc($resullast2))
						{
							$otherexpense      = $otherexpense + $rowslast2['OTHER_AMT'];
							$othertext[] = $obj->getExpenseTypeNameBasedOnID($rowslast2['EXPENSETYPEID'])." (".$rowslast2['DESCRIPTION'].") - ".$rowslast2['OTHER_AMT'];
						}
					}
				}
			}
			
			echo '<td align="left" valign="middle">'.$revenue.'</td>';
			echo '<td align="left" valign="middle">'.$otherexpense.'<br/>'.implode('<br/>',$othertext).'</td>';
			echo '<td align="left" valign="middle">'.$tchirein.'</td>';
			echo '<td align="left" valign="middle">'.$totalexpense.'</td>';
			echo '<td align="left" valign="middle">'.$earning.'</td>';
			echo '<td align="left" valign="middle">'.number_format($earning/$hiredays,2,'.','').'</td>';
			echo '</tr>';
			$j++;
		}
	}
	echo '</tbody>';
	echo '</table>';		
}

function getDashBoardData1()
{
	$obj 			= new data();
	$connect		= $obj->funConnect();
	$txtFromDate    =  $_REQUEST['txtFromDate'];
	$txtToDate      =  $_REQUEST['txtToDate'];
	$selBType       =  $_REQUEST['selBType'];
	if($txtFromDate!='' && $txtToDate!='')
	{
		$sql = "select chartering_estimate_tc_compare.COMID as COMID, chartering_estimate_tc_master.VESSEL_IMO_ID as VESSEL_IMO_ID, chartering_estimate_tc_master.TC_NO as TC_NO, chartering_estimate_tc_compare.MESSAGE as MESSAGE from chartering_estimate_tc_compare inner join chartering_estimate_tc_master on chartering_estimate_tc_master.TCOUTID= chartering_estimate_tc_compare.TCOUTID WHERE chartering_estimate_tc_compare.MODULEID='".$_SESSION['moduleid']."' AND chartering_estimate_tc_compare.MCOMPANYID='".$_SESSION['company']."' and chartering_estimate_tc_compare.FINAL_ID!='' and chartering_estimate_tc_master.FIXED=1 and date(chartering_estimate_tc_master.FINAL_DATETIME)>='".date('Y-m-d',strtotime($txtFromDate))."' and date(chartering_estimate_tc_master.FINAL_DATETIME)<='".date('Y-m-d',strtotime($txtToDate))."' and chartering_estimate_tc_master.ESTIMATE_TYPE='".$selBType."' and chartering_estimate_tc_compare.STATUS in(1,2,4) order by date(chartering_estimate_tc_master.FINAL_DATETIME) desc";
		//echo $sql; 
	}
	else
	{
		$txtToDate      =  date('Y-m-d',time());
		$txtFromDate    =  date('Y-m-d', strtotime('-3 month'));
	    
		$sql = "select chartering_estimate_tc_compare.COMID as COMID, chartering_estimate_tc_master.VESSEL_IMO_ID as VESSEL_IMO_ID, chartering_estimate_tc_master.TC_NO as TC_NO, chartering_estimate_tc_compare.MESSAGE as MESSAGE from chartering_estimate_tc_compare inner join chartering_estimate_tc_master on chartering_estimate_tc_master.TCOUTID= chartering_estimate_tc_compare.TCOUTID WHERE chartering_estimate_tc_compare.MODULEID='".$_SESSION['moduleid']."' AND chartering_estimate_tc_compare.MCOMPANYID='".$_SESSION['company']."' and chartering_estimate_tc_compare.FINAL_ID!='' and chartering_estimate_tc_master.FIXED=1 and date(chartering_estimate_tc_master.FINAL_DATETIME)>='".date('Y-m-d',strtotime($txtFromDate))."' and date(chartering_estimate_tc_master.FINAL_DATETIME)<='".date('Y-m-d',strtotime($txtToDate))."' and chartering_estimate_tc_master.ESTIMATE_TYPE='".$selBType."' and chartering_estimate_tc_compare.STATUS in(1,2,4) order by date(chartering_estimate_tc_master.FINAL_DATETIME) desc"; 
	}
	$res = mysql_query($sql) or die($sql);
	$rec = mysql_num_rows($res);
	$arr_data = array();
	$arr_other = array();
	$sumother = $sumotherAmt = $sumhire = $sumhireAmt = 0;
	$arr_hire = array();
	while($rows = mysql_fetch_assoc($res))
	{
		$sql1 = "select (select sum(VOYAGE_EARN_EST) as EARNING from chartering_tc_estimate_slave1 where chartering_tc_estimate_slave1.TCOUTID=chartering_estimate_tc_master.TCOUTID) as EARNING from  chartering_estimate_tc_master where COMID='".$rows['COMID']."' and SHEET_NO is NULL order by TCOUTID asc";
		$result1 = mysql_query($sql1) or die($sql1);
		$rows1 = mysql_fetch_assoc($result1);
		if($rows1['EARNING']!=NULL){$freightgross = $rows1['EARNING']/1000;}else{$freightgross = '';}
		
		$sql2 = "select (select sum(VOYAGE_EARN_EST) as EARNING from chartering_tc_estimate_slave1 where chartering_tc_estimate_slave1.TCOUTID=chartering_estimate_tc_master.TCOUTID) as EARNING from  chartering_estimate_tc_master where COMID='".$rows['COMID']."' and SHEET_NO is not NULL and FINAL_STATUS=1";
		$result2 = mysql_query($sql2) or die($sql2);
		$rows2 = mysql_fetch_assoc($result2);
		if($rows2['EARNING']!=NULL){$interim = $rows2['EARNING']/1000;}else{$interim = '';}
		
		$sql3 = "select (select sum(VOYAGE_EARN_EST) as EARNING from chartering_tc_estimate_slave1 where chartering_tc_estimate_slave1.TCOUTID=chartering_estimate_tc_master.TCOUTID) as EARNING, (select sum(NET_HIRE_AMT) as NET_HIRE_AMT from chartering_tc_estimate_slave1 where chartering_tc_estimate_slave1.TCOUTID=chartering_estimate_tc_master.TCOUTID) as NET_HIRE_AMT, (select sum(UTILISATION_DAY_EST) as UTILISATION_DAY_EST from chartering_tc_estimate_slave1 where chartering_tc_estimate_slave1.TCOUTID=chartering_estimate_tc_master.TCOUTID) as UTILISATION_DAY_EST from  chartering_estimate_tc_master where COMID='".$rows['COMID']."' and SHEET_NO is not NULL order by TCOUTID desc";
		$result3 = mysql_query($sql3) or die($sql3);
		$rows3 = mysql_fetch_assoc($result3);
		$remainingtcdays = $rows3['UTILISATION_DAY_EST'];
		$sql4 = "select sum(P_AMT) as SUM from invoice_tchire_master where COMID='".$rows['COMID']."' ";
		$result4 = mysql_query($sql4) or die($sql4);
		$rows4 = mysql_fetch_assoc($result4);
		if($rows4['SUM'] == $rows3['NET_HIRE_AMT'])
		{
			if($rows3['EARNING']!=NULL){$completion = $rows3['EARNING']/1000;}else{$completion = '';}	
		}
		else
		{
			$completion = '';
		}
		
		
		$sql_dem = "select P_AMT as SUM, FINAL_AMOUNT as SUM2, INV_IDENTITY, SHORT_DESC from invoice_tcother_master where COMID='".$rows['COMID']."' and STATUS=1";
		$result_dem = mysql_query($sql_dem) or die($sql_dem);
		while($rows_dem = mysql_fetch_assoc($result_dem))
		{
			$otherinv =  $rows_dem['SUM2'] - $rows_dem['SUM'];
			if($otherinv >0)
			{
				$sumotherAmt = $sumotherAmt + number_format($otherinv,2,'.','');
				$arr_other[] = array('TCno'=>$rows['TC_NO'], 'shortdesc'=>$rows_dem['SHORT_DESC'], 'vessel'=>$obj->getVesselIMOData($rows['VESSEL_IMO_ID'],"VESSEL_NAME").'('.$rows['MESSAGE'].')','amount'=>number_format($otherinv,2,'.',''));
			}
		}
		
		$sql5 = "select P_AMT as SUM, FINAL_AMOUNT as SUM2, RANDOMID, HIRE_DAYS, OLD_EXCHANGE_RATE from invoice_tchire_master where COMID='".$rows['COMID']."' and STATUS=1";
		$result5 = mysql_query($sql5) or die($sql5);
		while($rows5 = mysql_fetch_assoc($result5))
		{
			if($rows5['OLD_EXCHANGE_RATE']>0 || $rows5['OLD_EXCHANGE_RATE']<0)
			{$exchangerate = $rows5['OLD_EXCHANGE_RATE'];}else{$exchangerate = 1;}
			$hiretamt = ($exchangerate*$rows5['SUM2']) - ($exchangerate*$rows5['SUM']);
			$remainingtcdays = $remainingtcdays - $rows5['HIRE_DAYS'];
			if($hiretamt>0)
			{
				$sumhireAmt = $sumhireAmt + $hiretamt;
				$sqlven = "select TTL_REV_VENDOR from chartering_tc_estimate_slave1 where TCOUTID='".$obj->getLatestCostSheetIDTC($rows['COMID'])."' and RANDOMID='".$rows5['RANDOMID']."' order by TCOUTID desc";
				//echo $sqlven;
				$resultven = mysql_query($sqlven) or die($sqlven);
				$rowsven = mysql_fetch_assoc($resultven);
				$arr_hire[] = array('TCno'=>$rows['TC_NO'],'customer'=>$obj->getVendorListNewBasedOnID($rowsven['TTL_REV_VENDOR']), 'vessel'=>$obj->getVesselIMOData($rows['VESSEL_IMO_ID'],"VESSEL_NAME").'('.$rows['MESSAGE'].')','amount'=>number_format($hiretamt,2,'.',''));
			}
		}
		
		
		
		$arr_data[] = array('TCno'=>$rows['TC_NO'], 'vessel'=>$obj->getVesselIMOData($rows['VESSEL_IMO_ID'],"VESSEL_NAME").'('.$rows['MESSAGE'].')','fixture'=>number_format($freightgross,2,'.',''),'Interim'=>number_format($interim,2,'.',''),'completion'=>number_format($completion,2,'.',''),'fixcolor'=>'#86a948','intrimgrey'=>'#999898','completeblue'=>'#367fa9');
	}
	echo json_encode($arr_data)."@@@".$rec."@@@".json_encode($arr_other)."@@@".$sumother."@@@".json_encode($arr_hire)."@@@".number_format($sumhire,2,'.','')."@@@".number_format($sumotherAmt,2,'.','')."@@@".number_format($sumhireAmt,2,'.','');
}

function getvendorname()
{
	$obj 			   = new data();
	$connect		   = $obj->funConnect();
	$selAList  		   = $_REQUEST['selAList'];
	
	$sql = "select * from vendor_master where CODE = '".$selAList."' ";
	$res  = mysql_query($sql) or die($sql);
	$rows = mysql_fetch_assoc($res); 
	echo $rows['NAME']." /att. ".$rows['STREET_2']." (".$rows['EMAILID'].")";
}

function getShipOwnerdetail()
{
	$obj 			   = new data();
	$connect		   = $obj->funConnect();
	$selShipOwner  		   = $_REQUEST['selShipOwner'];
	
	$sql = "select * from vendor_master where CODE = '".$selShipOwner."' ";
	$res  = mysql_query($sql) or die($sql);
	$rows = mysql_fetch_assoc($res); 
	echo $rows['NAME'].", ".$rows['STREET_1'];
}


function getTCOthersInvoicePaymentDetails()
{
	$obj 		= new data();
	$connect	= $obj->funConnect();
	$invoiceid 	= $_REQUEST['invoiceid'];
	
	$sql 		= "select * from invoice_tcother_master where INVOICEID='".$invoiceid."' ";
	$res 	 	=  mysql_query($sql) or die($sql);
	$rows 		= mysql_fetch_assoc($res);
	if($rows['P_DATE']!="" && $rows['P_DATE']!="1970-01-01")
	{
		$idate = date('d-m-Y',strtotime($rows['P_DATE']));
	}
	else
	{
		$idate = date('d-m-Y',time());
	}
	echo '<div class="row invoice-info">
			 <div class="col-sm-4 invoice-col">
				 Amount
				<address>
					<input type="text" name="txtP_Amt" id="txtP_Amt" class="form-control" readonly value="'.$rows['FINAL_AMOUNT'].'" autocomplete="off"/>
					<input type="hidden" name="txtP_ID" id="txtP_ID" readonly value="'.$invoiceid.'" />	
				</address>
			 </div><!-- /.col -->
			 <div class="col-sm-4 invoice-col">
				Date
				<address>
					<input type="text" name="txtP_Date" id="txtP_Date" class="form-control" value="'.$idate.'" autocomplete="off"/>
				</address>
			 </div><!-- /.col -->
		</div>
		<div class="row invoice-info">
			 <div class="col-sm-12 invoice-col">
				Remarks
				<address>
					<textarea name="txtP_Remarks" id="txtP_Remarks" class="form-control" cols="15" rows="1" placeholder="Remarks..">'.$rows['P_REMARKS'].'</textarea>
				</address>
			 </div><!-- /.col -->
		</div>
		<div class="row invoice-info">
			<div class="col-sm-4 invoice-col">
			Payment Received
			   <address>
				   <input type="text" name="txtP_PR" id="txtP_PR" class="form-control" autocomplete="off" placeholder="0.00" value="'.$rows['P_AMT'].'"  onkeyup="onkeyUp1();"/>
			   </address>
			</div><!-- /.col -->
			<div class="col-sm-8 invoice-col">
			 Attachments 
		        <address>
				   <div class="btn btn-success btn-file btn-flat" data-toggle="tooltip" data-original-title="Add Attachments">
						<i class="fa fa-paperclip"></i> Attachment
						<input type="file" class="form-control" multiple name="mul_file[]" id="mul_file" title="" data-widget="Add Attachment" data-toggle="tooltip" data-original-title="Add Attachment"/>
				   </div>';
				   if($rows['ATTACHMENTS'] != '')
					{ 
						$file = explode(",",$rows['ATTACHMENTS']); 
						$name = explode(",",$rows['ATTACHMENTS_NAME']);									
				   echo '<address>
							<table cellpadding="1" cellspacing="1" border="0" width="100%" align="left">';
							$j =1;
							for($i=0;$i<sizeof($file);$i++)
							{
							echo '<tr height="20" id="row_file1_'.$j.'">
								<td width="80%" align="left" class="input-text"  valign="top"><a href="../../attachment/'.$file[$i].'" target="_blank" style="color:blue;" data-toggle="tooltip" data-original-title="'.$name[$i].'"><i class="fa fa-external-link"></i>&nbsp;&nbsp;'.$name[$i].'</a>
								<input type="hidden" name="file1_'.$j.'" id="file1_'.$j.'" value="'.$file[$i].'" />
								<input type="hidden" name="name1_'.$j.'" id="name1_'.$j.'" value="'.$name[$i].'" />
								</td>
								<td width="20%" align="left" class="input-text"  valign="top"><a href="#1" onClick="Del_Upload1('.$j.');"><i class="fa fa-times " style="color:red;"></i></a></td>
							</tr>';
							$j++;}
						echo '</table>
						</address>';
					}
			echo '</address>
			</div><!-- /.col -->
		</div>';
}

function getTCHireInvoicePaymentDetails()
{
	$obj 		= new data();
	$connect	= $obj->funConnect();
	$invoiceid 	= $_REQUEST['invoiceid'];
	
	$sql 		= "select * from invoice_tchire_master where INVOICEID='".$invoiceid."' ";
	$res 	 	=  mysql_query($sql) or die($sql);
	$rows 		= mysql_fetch_assoc($res);
	if($rows['P_DATE']!="" && $rows['P_DATE']!="1970-01-01")
	{
		$idate = date('d-m-Y',strtotime($rows['P_DATE']));
	}
	else
	{
		$idate = date('d-m-Y',time());
	}
	echo '<div class="row invoice-info">
			 <div class="col-sm-4 invoice-col">
				 Amount
				<address>
					<input type="text" name="txtP_Amt" id="txtP_Amt" class="form-control" readonly value="'.$rows['FINAL_AMOUNT'].'" autocomplete="off"/>
					<input type="hidden" name="txtP_ID" id="txtP_ID" readonly value="'.$invoiceid.'" />	
				</address>
			 </div><!-- /.col -->
			 <div class="col-sm-4 invoice-col">
				Date
				<address>
					<input type="text" name="txtP_Date" id="txtP_Date" class="form-control" value="'.$idate.'" autocomplete="off"/>
				</address>
			 </div><!-- /.col -->
		</div>
		<div class="row invoice-info">
			 <div class="col-sm-12 invoice-col">
				Remarks
				<address>
					<textarea name="txtP_Remarks" id="txtP_Remarks" class="form-control" cols="15" rows="1" placeholder="Remarks..">'.$rows['P_REMARKS'].'</textarea>
				</address>
			 </div><!-- /.col -->
		</div>
		<div class="row invoice-info">
			<div class="col-sm-4 invoice-col">
			Payment Received
			   <address>
				   <input type="text" name="txtP_PR" id="txtP_PR" class="form-control" autocomplete="off" placeholder="0.00" value="'.$rows['P_AMT'].'"  onkeyup="onkeyUp1();"/>
			   </address>
			</div><!-- /.col -->
			<div class="col-sm-8 invoice-col">
			 Attachments 
		        <address>
				   <div class="btn btn-success btn-file btn-flat" data-toggle="tooltip" data-original-title="Add Attachments">
						<i class="fa fa-paperclip"></i> Attachment
						<input type="file" class="form-control" multiple name="mul_file[]" id="mul_file" title="" data-widget="Add Attachment" data-toggle="tooltip" data-original-title="Add Attachment"/>
				   </div>';
				   if($rows['ATTACHMENTS'] != '')
					{ 
						$file = explode(",",$rows['ATTACHMENTS']); 
						$name = explode(",",$rows['ATTACHMENTS_NAME']);									
				   echo '<address>
							<table cellpadding="1" cellspacing="1" border="0" width="100%" align="left">';
							$j =1;
							for($i=0;$i<sizeof($file);$i++)
							{
							echo '<tr height="20" id="row_file1_'.$j.'">
								<td width="80%" align="left" class="input-text"  valign="top"><a href="../../attachment/'.$file[$i].'" target="_blank" style="color:blue;" data-toggle="tooltip" data-original-title="'.$name[$i].'"><i class="fa fa-external-link"></i>&nbsp;&nbsp;'.$name[$i].'</a>
								<input type="hidden" name="file1_'.$j.'" id="file1_'.$j.'" value="'.$file[$i].'" />
								<input type="hidden" name="name1_'.$j.'" id="name1_'.$j.'" value="'.$name[$i].'" />
								</td>
								<td width="20%" align="left" class="input-text"  valign="top"><a href="#1" onClick="Del_Upload1('.$j.');"><i class="fa fa-times " style="color:red;"></i></a></td>
							</tr>';
							$j++;}
						echo '</table>
						</address>';
					}
			echo '</address>
			</div><!-- /.col -->
		</div>';
}

function getDeleteTCHireInvoice()
{
	$obj 		= new data();
	$connect	= $obj->funConnect();
	$invoiceid = $_REQUEST['invoiceid'];		
	$delquery 	= "delete from invoice_tchire_master where INVOICEID='".$invoiceid."'";
	$delquery1 	= "delete from invoice_tchire_slave1 where INVOICEID='".$invoiceid."'";
	mysql_query($delquery);
	mysql_query($delquery1);
	echo 1;
}


function getAgencyLetterTCDataDelete()
{
	$obj 		= new data();
	$connect	= $obj->funConnect();
	$agencytcid = $_REQUEST['agencytcid'];		
	$delquery 	= "delete from generate_agency_letter_tc where GEN_AGENCY_TC_ID='".$agencytcid."'";
	mysql_query($delquery);
	echo 1;
}

function getvendordata()
{
	$obj 			   = new data();
	$connect		   = $obj->funConnect();
	$selCharOperation  = $_REQUEST['selCharOperation'];
	
	$sql = "select * from vendor_master where CODE = '".$selCharOperation."' ";
	$res  = mysql_query($sql) or die($sql);
	$rows = mysql_fetch_assoc($res); 
	echo $rows['STREET_1'].' '.$rows['STREET_2'].' '.$rows['STREET_3'].' '.$rows['STREET_4'].' '.$rows['STREET_5'].' '.$rows['CITY'].' '.$rows['CITY_POSTAL_CODE'].', Phone-'.$rows['PHONE'].', Email-'.$rows['EMAILID'].', PIC-'.$rows['STREET_2'];
}

function getmaildata()
{
	$mailtype  = $_REQUEST['mailtype'];
	$obj 	   = new emaildata();
	$emaildata = $obj->getMails($mailtype,$_REQUEST['start'],$_REQUEST['val'],$_REQUEST['itemperpage']);
	
	echo json_encode($emaildata['mailheader'])."@@@@@@".$emaildata['count']."@@@@@@".$emaildata['start'];
}



function getDailyPositionReport()
{
	$obj 			= new data();
	$connect		= $obj->funConnect();
	$selBType  = $_REQUEST['selBType'];
	$selVoyageType = $_REQUEST['selVoyageType'];
	
	
	 echo '<h3 style="text-align:center;">'.date("d M Y",time()).' - DAILY POSITION REPORT - VC & COA</h3>';
	 echo '<div style="overflow:auto;">';	
	 echo '<div class="box-body table-responsive">';	
	 echo '<table cellspacing="0" id="GridView1" class="table table-bordered table-striped" style="width:100%;border-collapse:collapse;">';
	 if($selVoyageType=='VC'){
	 	$sql1 =" and COAAID is NULL"; 
	 }
	 if($selVoyageType=='COA'){
	 	$sql1 =" and COAAID is not NULL";
	 }
	 $sql = "select *, (select CONTACT_PERSON from login where login.LOGINID=freight_cost_estimate_compare.OPERATOR) as OPERATOR1, (select LAYCAN_SDATE from open_cargo_master where open_cargo_master.OPEN_CARGOID = freight_cost_estimete_master.OPEN_CARGOID) as LAYCAN_SDATE, (select LAYCAN_EDATE from open_cargo_master where open_cargo_master.OPEN_CARGOID = freight_cost_estimete_master.OPEN_CARGOID) as LAYCAN_EDATE, (select CARGO from open_cargo_master where open_cargo_master.OPEN_CARGOID = freight_cost_estimete_master.OPEN_CARGOID) as CARGOIDS, (select CHARTERER from open_cargo_master where open_cargo_master.OPEN_CARGOID = freight_cost_estimete_master.OPEN_CARGOID) as CHARTERER1, (select OWNER from open_cargo_master where open_cargo_master.OPEN_CARGOID = freight_cost_estimete_master.OPEN_CARGOID) as OWNER1, (select SHIPPER from open_cargo_master where open_cargo_master.OPEN_CARGOID = freight_cost_estimete_master.OPEN_CARGOID) as SHIPPER1 from freight_cost_estimate_compare inner join freight_cost_estimete_master on freight_cost_estimete_master.FCAID= freight_cost_estimate_compare.FCAID WHERE freight_cost_estimate_compare.MODULEID='".$_SESSION['moduleid']."' AND freight_cost_estimate_compare.MCOMPANYID='".$_SESSION['company']."' and freight_cost_estimate_compare.FINAL_ID!='' and freight_cost_estimete_master.FIXED=1 and freight_cost_estimate_compare.STATUS in (1,2) and freight_cost_estimete_master.ESTIMATE_TYPE='".$selBType."' ".$sql1." group by freight_cost_estimete_master.FCAID order by freight_cost_estimate_compare.COMID desc ";
	 
	 $res  = mysql_query($sql) or die($sql);
	 $res1 = mysql_query($sql);
	 $res2 = mysql_query($sql);
	 $res3 = mysql_query($sql);
	 $rec  = mysql_num_rows($res);
	 $operator_arr = array();
	 if($rec == 0)
	 {
		 echo '<tr>';
		 echo '<td align="center" colspan="18" valign="middle" style="color:#ff0000;letter-spacing:1px;">'.strtoupper("Sorry Currently there are zero(0) records").'</td>';
		 echo '</tr>';
	 }
	 else
	 {
		    echo '<thead>';
	 		//............................for TOWARDS LOAD PORT - AT SEA .........................................................
	 	 	echo '<tr class="GridviewScrollHeader" style="font-size:12px;color:#fff; background-color:#1E85BE;">';
		 	echo '<td align="left" valign="top" colspan="17">TOWARDS LOAD PORT</td>';
			
			echo '</tr>';
		   echo '</thead>';
			echo '<tr class="GridviewScrollHeader" style="font-size:12px; background-color:#eee;">';
			echo '<td align="center" valign="top">S. No.</td>';
			echo '<td align="center" valign="top">Vessel</td>';
			echo '<td align="center" valign="top">Nom ID/Voyage ID</td>';
			echo '<td align="center" valign="top">Operator Name</td>';
			echo '<td align="center" valign="top">Charterer</td>';
			echo '<td align="center" valign="top">Shipper</td>';
			echo '<td align="center" valign="top">Owner</td>';
			echo '<td align="center" valign="top">Port</td>';
			echo '<td align="center" valign="top">ETA</td>';
			echo '<td align="center" valign="top">Cargo</td>';
			echo '<td align="center" valign="top">Qty(MT)</td>';
			echo '<td align="center" valign="top">Laycan</td>';
			echo '<td align="center" valign="top">Agent</td>';
			echo '<td align="center" valign="top">Broker</td>';
			echo '<td align="center" valign="top">Dem. Rate(USD/Day)</td>';
			echo '<td align="center" valign="top">Dis Port(s)</td>';
			echo '<td align="center" valign="top">Remarks</td>';
			echo '</tr>';
			$j=1;
		 while($rows = mysql_fetch_assoc($res))
		  {
			    $port_arr_lp  = $obj->getLoadPortArrBasedOnIDComidAndProcessWithoutTBN($rows['COMID']);
			 	for($i=0;$i<count($port_arr_lp);$i++)
				{
					if($obj->getCheckListRecordsRecBasedOnComID($rows['COMID']) > 0)
					{
						$arr_loadport  = explode('###',$port_arr_lp[$i]);
						$checklistid   = $obj->getCheckListRecordsDataBasedOnComID($rows['COMID'],"CHECKLIST_ID");
						$eta30days     = $obj->getCheckListPortDataRecordsRecBasedOnComID($rows['COMID'],$checklistid,"LP",$arr_loadport[0],$arr_loadport[1],"ETA 30 DAYS");
						$eta25days     = $obj->getCheckListPortDataRecordsRecBasedOnComID($rows['COMID'],$checklistid,"LP",$arr_loadport[0],$arr_loadport[1],"ETA 25 DAYS");
						$eta20days     = $obj->getCheckListPortDataRecordsRecBasedOnComID($rows['COMID'],$checklistid,"LP",$arr_loadport[0],$arr_loadport[1],"ETA 20 DAYS");
						$eta15days     = $obj->getCheckListPortDataRecordsRecBasedOnComID($rows['COMID'],$checklistid,"LP",$arr_loadport[0],$arr_loadport[1],"ETA 15 DAYS");
						$eta10days     = $obj->getCheckListPortDataRecordsRecBasedOnComID($rows['COMID'],$checklistid,"LP",$arr_loadport[0],$arr_loadport[1],"ETA 10 DAYS");
						$eta7days      = $obj->getCheckListPortDataRecordsRecBasedOnComID($rows['COMID'],$checklistid,"LP",$arr_loadport[0],$arr_loadport[1],"ETA 7 DAYS");
						$eta5days      = $obj->getCheckListPortDataRecordsRecBasedOnComID($rows['COMID'],$checklistid,"LP",$arr_loadport[0],$arr_loadport[1],"ETA 5 DAYS");
						$eta3days      = $obj->getCheckListPortDataRecordsRecBasedOnComID($rows['COMID'],$checklistid,"LP",$arr_loadport[0],$arr_loadport[1],"ETA 3 DAYS");
						$eta2days      = $obj->getCheckListPortDataRecordsRecBasedOnComID($rows['COMID'],$checklistid,"LP",$arr_loadport[0],$arr_loadport[1],"ETA 2 DAYS");
						$eta1days      = $obj->getCheckListPortDataRecordsRecBasedOnComID($rows['COMID'],$checklistid,"LP",$arr_loadport[0],$arr_loadport[1],"ETA 1 DAY");
						$actualarrival = $obj->getCheckListPortDataRecordsRecBasedOnComID($rows['COMID'],$checklistid,"LP",$arr_loadport[0],$arr_loadport[1],"ACTUAL ARRIVAL");
						
						if(($eta30days!='' && $actualarrival=="") || ($eta25days!='' && $actualarrival=="") || ($eta20days!='' && $actualarrival=="") || ($eta15days!='' && $actualarrival=="") || ($eta10days!='' && $actualarrival=="") || ($eta7days!='' && $actualarrival=="") || ($eta5days!='' && $actualarrival=="") || ($eta3days!='' && $actualarrival=="") || ($eta2days!='' && $actualarrival=="") || ($eta1days!='' && $actualarrival==""))
						{
							$operator_arr[$rows['OPERATOR']][] = 1;
							$count_arr_lp1[] = $j;
							$cargos = $obj->getCargoNameListForMultipleNamemultiple($rows['CARGOIDS']);
							$broker_arr = array();
							$fcaid = $obj->getLatestCostSheetID($rows['COMID']);
							$sql_brok = "select VENDORID from freight_cost_estimete_slave4 where FCAID='".$fcaid."'";
							$res_brok = mysql_query($sql_brok);
							while($rows_brok = mysql_fetch_assoc($res_brok))
							{
								$broker_arr[] = $obj->getVendorListNewBasedOnID($rows_brok['VENDORID']);
							}
							
							$sql_qty = "select LOAD_PORT_QTY from freight_cost_estimete_slave1 where FROM_PORT='".$arr_loadport[0]."' and RANDOMID='".$arr_loadport[1]."' and FCAID='".$fcaid."'";
							$res_qty = mysql_query($sql_qty) or die($sql_qty);
							$rows_qty = mysql_fetch_assoc($res_qty);
							$quantity = $rows_qty['LOAD_PORT_QTY'];
							
							echo '<tr class="GridviewScrollItem">';
							echo '<td align="center" valign="top">'.$j.'.</td>';
							echo '<td align="left" valign="top">'.$obj->getVesselIMOData($obj->getCompareEstimateData($rows['COMID'],"VESSEL_IMO_ID"),"VESSEL_NAME").'</td>';
							echo '<td align="left" valign="top">'.$obj->getCompareTableData($rows['COMID'],"MESSAGE").'/'.$rows['VOYAGE_NO'].'</td>';
							echo '<td align="left" valign="top">'.$rows['OPERATOR1'].'</td>';
							echo '<td align="left" valign="top">'.$obj->getVendorListNewBasedOnID($rows['CHARTERER1']).'</td>';
							echo '<td align="left" valign="top">'.$obj->getVendorListNewBasedOnID($rows['SHIPPER1']).'</td>';
							echo '<td align="left" valign="top">'.$obj->getVendorListNewBasedOnID($rows['OWNER1']).'</td>';
							echo '<td align="left" valign="top">'.$obj->getPortNameBasedOnID($arr_loadport[0]).'</td>';
							echo '<td align="left" valign="top">'.$obj->getMaxETADate($rows['COMID'],"LP",$arr_loadport[0],$arr_loadport[1]).'</td>';
							echo '<td align="left" valign="top">'.$cargos.'</td>';
							
							echo '<td align="left" valign="top">'.$quantity.'</td>';
							
							echo '<td align="left" valign="top">'.date('d-m-Y',strtotime($rows['LAYCAN_EDATE'])).'/'.date('d-m-Y',strtotime($rows['LAYCAN_EDATE'])).'</td>';
							echo '<td align="left" valign="top">'.$obj->getCheckListPortDataRecordsRecBasedOnComID($rows['COMID'],$checklistid,"LP",$arr_loadport[0],$arr_loadport[1],"AGENT").'</td>';
							echo '<td align="left" valign="top">'.implode(', ',$broker_arr).'</td>';
							echo '<td align="left" valign="top">'.$obj->getCheckListPortDataRecordsRecBasedOnComID($rows['COMID'],$checklistid,"LP",$arr_loadport[0],$arr_loadport[1],"DEMURRAGE RATE(USD/DAY)").'</td>';
							echo '<td align="left" valign="top">'.implode(" , ",$obj->getDisPortNameArrBasedOnIDComidAndProcessWithoutTBN($rows['COMID'])).'</td>';
							echo '<td align="left" valign="top">'.$obj->getCheckListPortDataRecordsRecBasedOnComID($rows['COMID'],$checklistid,"LP",$arr_loadport[0],$arr_loadport[1],"REMARKS TOWARDS LOAD PORT").'</td>';
							
							echo '</tr>';
							 $j++;
						}
					}
			   }
			}//die;
			if(!is_array($count_arr_lp1))
			{
				echo '<tr class="GridviewScrollItem">';
				echo '<td align="center" valign="top">-</td>';
				echo '<td align="center" valign="top">-</td>';
				echo '<td align="center" valign="top">-</td>';
				echo '<td align="center" valign="top">-</td>';
				echo '<td align="center" valign="top">-</td>';
				echo '<td align="center" valign="top">-</td>';
				echo '<td align="center" valign="top">-</td>';
				echo '<td align="center" valign="top">-</td>';
				echo '<td align="center" valign="top">-</td>';
				echo '<td align="center" valign="top">-</td>';
				echo '<td align="center" valign="top">-</td>';
				echo '<td align="center" valign="top">-</td>';
				echo '<td align="center" valign="top">-</td>';
				echo '<td align="center" valign="top">-</td>';
				echo '<td align="center" valign="top">-</td>';
				echo '<td align="center" valign="top">-</td>';
				echo '<td align="center" valign="top">-</td>';
				echo '</tr>';
			}
		  //....................................ends here................................................................
		  
		  //............................for AT LOAD PORT  .........................................................
		  echo '<thead>';
	 	 	echo '<tr class="GridviewScrollHeader" style="font-size:12px;color:#fff; background-color:#1E85BE;">';
		 	echo '<td align="left" valign="top" colspan="18">AT LOAD PORT</td>';
			echo '</tr>';
		 echo '</thead>';
			echo '<tr class="GridviewScrollHeader" style="font-size:12px; background-color:#eee;">';
			echo '<td align="center" valign="top">S. No.</td>';
			echo '<td align="center" valign="top">Vessel</td>';
			echo '<td align="center" valign="top">Nom ID/Voyage ID</td>';
			echo '<td align="center" valign="top">Operator Name</td>';
			echo '<td align="center" valign="top">Charterer</td>';
			echo '<td align="center" valign="top">Shipper</td>';
			echo '<td align="center" valign="top">Owner</td>';
			echo '<td align="center" valign="top">Port</td>';
			echo '<td align="center" valign="top">ARRVD/ETC</td>';
			echo '<td align="center" valign="top">Cargo</td>';
			echo '<td align="center" valign="top">Qty(MT)</td>';
			echo '<td align="center" valign="top">Laycan</td>';
			echo '<td align="center" valign="top">Agent</td>';
			echo '<td align="center" valign="top">Broker</td>';
			echo '<td align="center" valign="top">Dem. Rate(USD/Day)</td>';
			echo '<td align="center" valign="top">Dis Port(s)</td>';
			echo '<td align="center" valign="top">Remarks</td>';
			echo '</tr>';
			$j=1;
			
		 	while($rows1 = mysql_fetch_assoc($res1))
		  	{
			    $port_arr_lp       = $obj->getLoadPortArrBasedOnIDComidAndProcessWithoutTBN($rows1['COMID']);
			 	for($i=0;$i<count($port_arr_lp);$i++)
				{
				if($obj->getCheckListRecordsRecBasedOnComID($rows1['COMID']) > 0)
				{
					$arr_loadport      = explode('###',$port_arr_lp[$i]);
					$checklistid       = $obj->getCheckListRecordsDataBasedOnComID($rows1['COMID'],"CHECKLIST_ID");
					$actualarrival     = $obj->getCheckListPortDataRecordsRecBasedOnComID($rows1['COMID'],$checklistid,"LP",$arr_loadport[0],$arr_loadport[1],"ACTUAL ARRIVAL");
					$vesselsailed      = $obj->getCheckListPortDataRecordsRecBasedOnComID($rows1['COMID'],$checklistid,"LP",$arr_loadport[0],$arr_loadport[1],"VESSEL SAILED");
					if($actualarrival!='' && $vesselsailed=="")
					{
						$count_arr_lp2[] = $j;
						$operator_arr[$rows1['OPERATOR']][] = 1;
						$cargos = $obj->getCargoNameListForMultipleNamemultiple($rows1['CARGOIDS']);
						
						$broker_arr = array();
						$fcaid = $obj->getLatestCostSheetID($rows1['COMID']);
						$sql_brok = "select VENDORID from freight_cost_estimete_slave4 where FCAID='".$fcaid."'";
						$res_brok = mysql_query($sql_brok);
						while($rows_brok = mysql_fetch_assoc($res_brok))
						{
							$broker_arr[] = $obj->getVendorListNewBasedOnID($rows_brok['VENDORID']);
						}
						$sql_qty = "select LOAD_PORT_QTY from freight_cost_estimete_slave1 where FROM_PORT='".$arr_loadport[0]."' and RANDOMID='".$arr_loadport[1]."' and FCAID='".$fcaid."'";
						$res_qty = mysql_query($sql_qty) or die($sql_qty);
						$rows_qty = mysql_fetch_assoc($res_qty);
						$quantity = $rows_qty['LOAD_PORT_QTY'];
						
						echo '<tr class="GridviewScrollItem">';
						echo '<td align="center" valign="top">'.$j.'.</td>';
						echo '<td align="left" valign="top">'.$obj->getVesselIMOData($obj->getCompareEstimateData($rows1['COMID'],"VESSEL_IMO_ID"),"VESSEL_NAME").'</td>';
						echo '<td align="left" valign="top">'.$obj->getCompareTableData($rows1['COMID'],"MESSAGE").'/'.$rows1['VOYAGE_NO'].'</td>';
						echo '<td align="left" valign="top">'.$rows1['OPERATOR1'].'</td>';
						echo '<td align="left" valign="top">'.$obj->getVendorListNewBasedOnID($rows1['CHARTERER1']).'</td>';
						echo '<td align="left" valign="top">'.$obj->getVendorListNewBasedOnID($rows1['SHIPPER1']).'</td>';
						echo '<td align="left" valign="top">'.$obj->getVendorListNewBasedOnID($rows1['OWNER1']).'</td>';
						echo '<td align="left" valign="top">'.$obj->getPortNameBasedOnID($arr_loadport[0]).'</td>';
						$arrival_date = $obj->getCheckListPortDataRecordsRecBasedOnComID($rows1['COMID'],$checklistid,"LP",$arr_loadport[0],$arr_loadport[1],"ACTUAL ARRIVAL");
						$etcd_date = $obj->getCheckListPortDataRecordsRecBasedOnComID($rows1['COMID'],$checklistid,"LP",$arr_loadport[0],$arr_loadport[1],"ETC/D");
						if(date("d-m-Y",strtotime($arrival_date))!='01-01-1970'){$arrival_date =date("d-M-Y H:i",strtotime($arrival_date)); }
						if(date("d-m-Y",strtotime($etcd_date))!='01-01-1970'){$etcd_date = $arrival_date.'/'.date("d-M-Y H:i",strtotime($etcd_date)); }else{$etcd_date = $arrival_date;}
						echo '<td align="left"  valign="top">'.$etcd_date.'</td>';
						
						echo '<td align="left" valign="top">'.$cargos.'</td>';
						echo '<td align="left" valign="top">'.$quantity.'</td>';
						echo '<td align="left" valign="top">'.date('d-m-Y',strtotime($rows1['LAYCAN_EDATE'])).'/'.date('d-m-Y',strtotime($rows1['LAYCAN_EDATE'])).'</td>';
						echo '<td align="left" valign="top">'.$obj->getCheckListPortDataRecordsRecBasedOnComID($rows1['COMID'],$checklistid,"LP",$arr_loadport[0],$arr_loadport[1],"AGENT").'</td>';
						echo '<td align="left" valign="top">'.implode(', ',$broker_arr).'</td>';
						echo '<td align="left" valign="top">'.$obj->getCheckListPortDataRecordsRecBasedOnComID($rows1['COMID'],$checklistid,"LP",$arr_loadport[0],$arr_loadport[1],"DEMURRAGE RATE(USD/DAY)").'</td>';
						echo '<td align="left" valign="top">'.implode(" , ",$obj->getDisPortNameArrBasedOnIDComidAndProcessWithoutTBN($rows1['COMID'])).'</td>';
						echo '<td align="left" valign="top">'.$obj->getCheckListPortDataRecordsRecBasedOnComID($rows1['COMID'],$checklistid,"LP",$arr_loadport[0],$arr_loadport[1],"REMARKS AT LOAD PORT").'</td>';
						echo '</tr>';
						$j++;
					}
				}
			   }
			}
			if(!is_array($count_arr_lp2))
			{
				echo '<tr class="GridviewScrollItem">';
				echo '<td align="center" valign="top">-</td>';
				echo '<td align="center" valign="top">-</td>';
				echo '<td align="center" valign="top">-</td>';
				echo '<td align="center" valign="top">-</td>';
				echo '<td align="center" valign="top">-</td>';
				echo '<td align="center" valign="top">-</td>';
				echo '<td align="center" valign="top">-</td>';
				echo '<td align="center" valign="top">-</td>';
				echo '<td align="center" valign="top">-</td>';
				echo '<td align="center" valign="top">-</td>';
				echo '<td align="center" valign="top">-</td>';
				echo '<td align="center" valign="top">-</td>';
				echo '<td align="center" valign="top">-</td>';
				echo '<td align="center" valign="top"></td>';
				echo '<td align="center" valign="top">-</td>';
				echo '<td align="center" valign="top">-</td>';
				echo '<td align="center" valign="top">-</td>';
				echo '</tr>';
			}
		  //....................................ends here................................................................
	   	  //............................for TOWARDS DISCHARGE PORT - AT SEA .........................................................
		  echo '<thead>';
	 	 	echo '<tr class="GridviewScrollHeader" style="font-size:12px;color:#fff; background-color:#1E85BE;">';
		 	echo '<td align="left" valign="top" colspan="18">TOWARDS DISCHARGE PORT</td>';
			echo '</tr>';
		 echo '</thead>';
			echo '<tr class="GridviewScrollHeader" style="font-size:12px; background-color:#eee;">';
			echo '<td align="center" valign="top">S. No.</td>';
			echo '<td align="center" valign="top">Vessel</td>';
			echo '<td align="center" valign="top">Nom ID/Voyage ID</td>';
			echo '<td align="center" valign="top">Operator Name</td>';
			echo '<td align="center" valign="top">Charterer</td>';
			echo '<td align="center" valign="top">Shipper</td>';
			echo '<td align="center" valign="top">Owner</td>';
			echo '<td align="center" valign="top">Port</td>';
			echo '<td align="center" valign="top">ETA</td>';
			echo '<td align="center" valign="top">Cargo</td>';
			echo '<td align="center" valign="top">Qty(MT)</td>';
			echo '<td align="center" valign="top">Laycan</td>';
			echo '<td align="center" valign="top">Agent</td>';
			echo '<td align="center" valign="top">Broker</td>';
			echo '<td align="center" valign="top">Dem. Rate(USD/Day)</td>';
			echo '<td align="center" valign="top">Dis Port(s)</td>';
			echo '<td align="center" valign="top">Remarks</td>';
			echo '</tr>';
			$j=1;
		 	while($rows2 = mysql_fetch_assoc($res2))
		  	{
			    $port_arr_dp       = $obj->getDisPortArrBasedOnIDComidAndProcessWithoutTBN($rows2['COMID']);
			 	for($i=0;$i<count($port_arr_dp);$i++)
				{
				if($obj->getCheckListRecordsRecBasedOnComID($rows2['COMID']) > 0)
				{
					$arr_dischargeport = explode('###',$port_arr_dp[$i]);
					$checklistid   = $obj->getCheckListRecordsDataBasedOnComID($rows2['COMID'],"CHECKLIST_ID");
					$eta30days     = $obj->getCheckListPortDataRecordsRecBasedOnComID($rows2['COMID'],$checklistid,"DP",$arr_dischargeport[0],$arr_dischargeport[1],"ETA 30 DAYS");
					$eta25days     = $obj->getCheckListPortDataRecordsRecBasedOnComID($rows2['COMID'],$checklistid,"DP",$arr_dischargeport[0],$arr_dischargeport[1],"ETA 25 DAYS");
					$eta20days     = $obj->getCheckListPortDataRecordsRecBasedOnComID($rows2['COMID'],$checklistid,"DP",$arr_dischargeport[0],$arr_dischargeport[1],"ETA 20 DAYS");
					$eta15days     = $obj->getCheckListPortDataRecordsRecBasedOnComID($rows2['COMID'],$checklistid,"DP",$arr_dischargeport[0],$arr_dischargeport[1],"ETA 15 DAYS");
					$eta10days     = $obj->getCheckListPortDataRecordsRecBasedOnComID($rows2['COMID'],$checklistid,"DP",$arr_dischargeport[0],$arr_dischargeport[1],"ETA 10 DAYS");
					$eta7days      = $obj->getCheckListPortDataRecordsRecBasedOnComID($rows2['COMID'],$checklistid,"DP",$arr_dischargeport[0],$arr_dischargeport[1],"ETA 7 DAYS");
					$eta5days      = $obj->getCheckListPortDataRecordsRecBasedOnComID($rows2['COMID'],$checklistid,"DP",$arr_dischargeport[0],$arr_dischargeport[1],"ETA 5 DAYS");
					$eta3days      = $obj->getCheckListPortDataRecordsRecBasedOnComID($rows2['COMID'],$checklistid,"DP",$arr_dischargeport[0],$arr_dischargeport[1],"ETA 3 DAYS");
					$eta2days      = $obj->getCheckListPortDataRecordsRecBasedOnComID($rows2['COMID'],$checklistid,"DP",$arr_dischargeport[0],$arr_dischargeport[1],"ETA 2 DAYS");
					$eta1days      = $obj->getCheckListPortDataRecordsRecBasedOnComID($rows2['COMID'],$checklistid,"DP",$arr_dischargeport[0],$arr_dischargeport[1],"ETA 1 DAY");
					$actualarrival   = $obj->getCheckListPortDataRecordsRecBasedOnComID($rows2['COMID'],$checklistid,"DP",$arr_dischargeport[0],$arr_dischargeport[1],"ACTUAL ARRIVAL");
					if(($eta30days!='' && $actualarrival=="") || ($eta25days!='' && $actualarrival=="") || ($eta20days!='' && $actualarrival=="") || ($eta15days!='' && $actualarrival=="") || ($eta10days!='' && $actualarrival=="") || ($eta7days!='' && $actualarrival=="") || ($eta5days!='' && $actualarrival=="") || ($eta3days!='' && $actualarrival=="") || ($eta2days!='' && $actualarrival=="") || ($eta1days!='' && $actualarrival==""))
					{
						$operator_arr[$rows2['OPERATOR']][] = 1;
						$count_arr_dp1[] = $j;
						$cargos = $obj->getCargoNameListForMultipleNamemultiple($rows2['CARGOIDS']);
						$quantity = $rows2['CARGO_LOADABLE_MT'];
						
						$broker_arr = array();
						$fcaid = $obj->getLatestCostSheetID($rows2['COMID']);
						$sql_brok = "select VENDORID from freight_cost_estimete_slave4 where FCAID='".$fcaid."'";
						$res_brok = mysql_query($sql_brok);
						while($rows_brok = mysql_fetch_assoc($res_brok))
						{
							$broker_arr[] = $obj->getVendorListNewBasedOnID($rows_brok['VENDORID']);
						}
						$sql_qty = "select DISC_PORT_QTY from freight_cost_estimete_slave1 where TO_PORT='".$arr_dischargeport[0]."' and RANDOMID='".$arr_dischargeport[1]."' and FCAID='".$fcaid."'";
						$res_qty = mysql_query($sql_qty) or die($sql_qty);
						$rows_qty = mysql_fetch_assoc($res_qty);
						$quantity = $rows_qty['DISC_PORT_QTY'];
						
						echo '<tr class="GridviewScrollItem">';
						echo '<td align="center" valign="top">'.$j.'.</td>';
						echo '<td align="left" valign="top">'.$obj->getVesselIMOData($obj->getCompareEstimateData($rows2['COMID'],"VESSEL_IMO_ID"),"VESSEL_NAME").'</td>';
						echo '<td align="left" valign="top">'.$obj->getCompareTableData($rows2['COMID'],"MESSAGE").'/'.$rows2['VOYAGE_NO'].'</td>';
						echo '<td align="left" valign="top">'.$rows2['OPERATOR1'].'</td>';
						echo '<td align="left" valign="top">'.$obj->getVendorListNewBasedOnID($rows2['CHARTERER1']).'</td>';
						echo '<td align="left" valign="top">'.$obj->getVendorListNewBasedOnID($rows2['SHIPPER1']).'</td>';
						echo '<td align="left" valign="top">'.$obj->getVendorListNewBasedOnID($rows2['OWNER1']).'</td>';
						echo '<td align="left" valign="top">'.$obj->getPortNameBasedOnID($arr_dischargeport[0]).'</td>';
						echo '<td>'.$obj->getMaxETADate($rows2['COMID'],"DP",$arr_dischargeport[0],$arr_dischargeport[1]).'</td>';
						echo '<td align="left" valign="top">'.$cargos.'</td>';
						echo '<td align="left" valign="top">'.$quantity.'</td>';
						echo '<td align="left" valign="top">'.date('d-m-Y',strtotime($rows2['LAYCAN_EDATE'])).'/'.date('d-m-Y',strtotime($rows2['LAYCAN_EDATE'])).'</td>';
						echo '<td align="left" valign="top">'.$obj->getCheckListPortDataRecordsRecBasedOnComID($rows2['COMID'],$checklistid,"DP",$arr_dischargeport[0],$arr_dischargeport[1],"AGENT").'</td>';
						echo '<td align="left" valign="top">'.implode(', ',$broker_arr).'</td>';
						echo '<td align="left" valign="top">'.$obj->getCheckListPortDataRecordsRecBasedOnComID($rows2['COMID'],$checklistid,"DP",$arr_dischargeport[0],$arr_dischargeport[1],"DEMURRAGE RATE(USD/DAY)").'</td>';
						echo '<td align="left" valign="top">'.implode(" , ",$obj->getDisPortNameArrBasedOnIDComidAndProcessWithoutTBN($rows2['COMID'])).'</td>';
						echo '<td align="left" valign="top">'.$obj->getCheckListPortDataRecordsRecBasedOnComID($rows2['COMID'],$checklistid,"DP",$arr_dischargeport[0],$arr_dischargeport[1],"REMARKS TOWARDS DISCHARGE PORT").'</td>';
						echo '</tr>';
						$j++;
					}
				}
			   }
		  	}
			if(!is_array($count_arr_dp1))
			{
				echo '<tr class="GridviewScrollItem">';
				echo '<td align="center" valign="top">-</td>';
				echo '<td align="center" valign="top">-</td>';
				echo '<td align="center" valign="top">-</td>';
				echo '<td align="center" valign="top">-</td>';
				echo '<td align="center" valign="top">-</td>';
				echo '<td align="center" valign="top">-</td>';
				echo '<td align="center" valign="top">-</td>';
				echo '<td align="center" valign="top">-</td>';
				echo '<td align="center" valign="top">-</td>';
				echo '<td align="center" valign="top">-</td>';
				echo '<td align="center" valign="top">-</td>';
				echo '<td align="center" valign="top">-</td>';
				echo '<td align="center" valign="top">-</td>';
				echo '<td align="center" valign="top">-</td>';
				echo '<td align="center" valign="top"></td>';
				echo '<td align="center" valign="top">-</td>';
				echo '<td align="center" valign="top">-</td>';
				echo '</tr>';
			}
		  	//....................................ends here................................................................
		  	//............................for AT DISCHARGE PORT  .........................................................
			echo '<thead>';
	 	 	echo '<tr class="GridviewScrollHeader" style="font-size:12px;color:#fff; background-color:#1E85BE;">';
		 	echo '<td align="left" valign="top" colspan="18">AT DISCHARGE PORT</td>';
			echo '</tr>';
			echo '</thead>';
		 
			echo '<tr class="GridviewScrollHeader" style="font-size:12px; background-color:#eee;">';
			echo '<td align="center" valign="top">S. No.</td>';
			echo '<td align="center" valign="top">Vessel</td>';
			echo '<td align="center" valign="top">Nom ID/Voyage ID</td>';
			echo '<td align="center" valign="top">Operator Name</td>';
			echo '<td align="center" valign="top">Charterer</td>';
			echo '<td align="center" valign="top">Shipper</td>';
			echo '<td align="center" valign="top">Owner</td>';
			echo '<td align="center" valign="top">Port</td>';
			echo '<td align="center" valign="top">ARRVD/ETC</td>';
			echo '<td align="center" valign="top">Cargo</td>';
			echo '<td align="center" valign="top">Qty(MT)</td>';
			echo '<td align="center" valign="top">Laycan</td>';
			echo '<td align="center" valign="top">Agent</td>';
			echo '<td align="center" valign="top">Broker</td>';
			echo '<td align="center" valign="top">Dem. Rate(USD/Day)</td>';
			echo '<td align="center" valign="top">Dis Port(s)</td>';
			echo '<td align="center" valign="top">Remarks</td>';
			echo '</tr>';
			$j=1;
			while($rows3 = mysql_fetch_assoc($res3))
			{
				$port_arr_dp   = $obj->getDisPortArrBasedOnIDComidAndProcessWithoutTBN($rows3['COMID']);
				for($i=0;$i<count($port_arr_dp);$i++)
				{
				if($obj->getCheckListRecordsRecBasedOnComID($rows3['COMID']) > 0)
				{
					$arr_dischargeport = explode('###',$port_arr_dp[$i]);
					$checklistid       = $obj->getCheckListRecordsDataBasedOnComID($rows3['COMID'],"CHECKLIST_ID");
					$actualarrival       = $obj->getCheckListPortDataRecordsRecBasedOnComID($rows3['COMID'],$checklistid,"DP",$arr_dischargeport[0],$arr_dischargeport[1],"ACTUAL ARRIVAL");
					$vesselsailed      = $obj->getCheckListPortDataRecordsRecBasedOnComID($rows3['COMID'],$checklistid,"DP",$arr_dischargeport[0],$arr_dischargeport[1],"VESSEL SAILED");
					if($actualarrival!= "" && $vesselsailed=="")
					{
						$count_arr_dp2[] = $j;
						$operator_arr[$rows3['OPERATOR']][] = 1;
						
						$cargos = $obj->getCargoNameListForMultipleNamemultiple($rows3['CARGOIDS']);
						
						$broker_arr = array();
						$fcaid = $obj->getLatestCostSheetID($rows3['COMID']);
						$sql_brok = "select VENDORID from freight_cost_estimete_slave4 where FCAID='".$fcaid."'";
						$res_brok = mysql_query($sql_brok);
						while($rows_brok = mysql_fetch_assoc($res_brok))
						{
							$broker_arr[] = $obj->getVendorListNewBasedOnID($rows_brok['VENDORID']);
						}
						$sql_qty = "select DISC_PORT_QTY from freight_cost_estimete_slave1 where TO_PORT='".$arr_dischargeport[0]."' and RANDOMID='".$arr_dischargeport[1]."' and FCAID='".$fcaid."'";
						$res_qty = mysql_query($sql_qty) or die($sql_qty);
						$rows_qty = mysql_fetch_assoc($res_qty);
						$quantity = $rows_qty['DISC_PORT_QTY'];
						
						echo '<tr class="GridviewScrollItem">';
						echo '<td align="center" valign="top">'.$j.'.</td>';
						echo '<td align="left" valign="top">'.$obj->getVesselIMOData($obj->getCompareEstimateData($rows3['COMID'],"VESSEL_IMO_ID"),"VESSEL_NAME").'</td>';
						echo '<td align="left" valign="top">'.$obj->getCompareTableData($rows3['COMID'],"MESSAGE").'/'.$rows3['VOYAGE_NO'].'</td>';
						echo '<td align="left" valign="top">'.$rows3['OPERATOR1'].'</td>';
						echo '<td align="left" valign="top">'.$obj->getVendorListNewBasedOnID($rows3['CHARTERER1']).'</td>';
						echo '<td align="left" valign="top">'.$obj->getVendorListNewBasedOnID($rows3['SHIPPER1']).'</td>';
						echo '<td align="left" valign="top">'.$obj->getVendorListNewBasedOnID($rows3['OWNER1']).'</td>';
						echo '<td align="left" valign="top">'.$obj->getPortNameBasedOnID($arr_dischargeport[0]).'</td>';
						$arrival_date = $obj->getCheckListPortDataRecordsRecBasedOnComID($rows3['COMID'],$checklistid,"DP",$arr_dischargeport[0],$arr_dischargeport[1],"ACTUAL ARRIVAL");
						$etcd_date = $obj->getCheckListPortDataRecordsRecBasedOnComID($rows3['COMID'],$checklistid,"DP",$arr_dischargeport[0],$arr_dischargeport[1],"ETC/D");
						if(date("d-m-Y",strtotime($arrival_date))!='01-01-1970'){$arrival_date =date("d-M-Y H:i",strtotime($arrival_date)); }
						if(date("d-m-Y",strtotime($etcd_date))!='01-01-1970'){$etcd_date = $arrival_date.'/'.date("d-M-Y H:i",strtotime($etcd_date)); }else{$etcd_date = $arrival_date;}
						echo '<td align="left"  valign="top">'.$etcd_date.'</td>';
						
						echo '<td align="left" valign="top">'.$cargos.'</td>';
						echo '<td align="left" valign="top">'.$quantity.'</td>';
						echo '<td align="left" valign="top">'.date('d-m-Y',strtotime($rows3['LAYCAN_EDATE'])).'/'.date('d-m-Y',strtotime($rows3['LAYCAN_EDATE'])).'</td>';
						echo '<td align="left" valign="top">'.$obj->getCheckListPortDataRecordsRecBasedOnComID($rows3['COMID'],$checklistid,"DP",$arr_dischargeport[0],$arr_dischargeport[1],"AGENT").'</td>';
						echo '<td align="left" valign="top">'.implode(', ',$broker_arr).'</td>';
						echo '<td align="left" valign="top">'.$obj->getCheckListPortDataRecordsRecBasedOnComID($rows3['COMID'],$checklistid,"DP",$arr_dischargeport[0],$arr_dischargeport[1],"DEMURRAGE RATE(USD/DAY)").'</td>';
						echo '<td align="left" valign="top">'.implode(" , ",$obj->getDisPortNameArrBasedOnIDComidAndProcessWithoutTBN($rows3['COMID'])).'</td>';
						echo '<td align="left" valign="top">'.$obj->getCheckListPortDataRecordsRecBasedOnComID($rows3['COMID'],$checklistid,"DP",$arr_dischargeport[0],$arr_dischargeport[1],"REMARKS AT DISCHARGE PORT").'</td>';
						echo '</tr>';
						 $j++;
					}
				}
			   }
			}


			if(!is_array($count_arr_dp2))
			{
				echo '<tr class="GridviewScrollItem">';
				echo '<td align="center" valign="top" >-</td>';
				echo '<td align="center" valign="top" >-</td>';
				echo '<td align="center" valign="top" >-</td>';
				echo '<td align="center" valign="top" >-</td>';
				echo '<td align="center" valign="top" >-</td>';
				echo '<td align="center" valign="top" >-</td>';
				echo '<td align="center" valign="top" >-</td>';
				echo '<td align="center" valign="top" >-</td>';
				echo '<td align="center" valign="top" >-</td>';
				echo '<td align="center" valign="top" >-</td>';
				echo '<td align="center" valign="top" >-</td>';
				echo '<td align="center" valign="top" >-</td>';
				echo '<td align="center" valign="top" >-</td>';
				echo '<td align="center" valign="top" ></td>';
				echo '<td align="center" valign="top" >-</td>';
				echo '<td align="center" valign="top" >-</td>';
				echo '<td align="center" valign="top" >-</td>';
				echo '</tr>';
			}
		  //....................................ends here................................................................
	  }
	
	echo '</table>';
	echo '</div>';
	echo '<div class="box-body table-responsive">';	
	    echo '<table cellspacing="0" id="GridView2" class="table table-bordered table-striped" style="width:50%;border-collapse:collapse;">';
		    echo '<tr class="GridviewScrollHeader" style="font-size:14px;color:#fff; background-color:#1E85BE;">';
				echo '<th colspan="2">NO. OF VESSELS PER OPERATOR</th>';
			echo '</tr>';
			echo '<tr class="GridviewScrollHeader" style="font-size:14px; background-color:#eee;">';
				echo '<th>Operator</th>';
				echo '<th>No. Of Vessels</th>';
			echo '</tr>';
			$sql4 = "select LOGINID, CONTACT_PERSON from login where STATUS=1 and USER_TYPE='internal_user'";
			$res4 = mysql_query($sql4);$sum = 0;
			while($rows4 = mysql_fetch_assoc($res4))
			{
				echo '<tr>';
					echo '<td>'.$rows4['CONTACT_PERSON'].'</td>';
					echo '<td>'.count($operator_arr[$rows4['LOGINID']]).'</td>';
				echo '</tr>';
				$sum = $sum + count($operator_arr[$rows4['LOGINID']]);
			}
			echo '<tr class="GridviewScrollHeader" style="font-size:14px; background-color:#eee;">';
					echo '<td><strong>Total</strong></td>';
					echo '<td><strong>'.$sum.'</strong></td>';
			echo '</tr>';
		echo '</table>';
	echo '</div>';	
	echo '</div>';
}


function getDashBoardData()
{
	$obj 			= new data();
	$connect		= $obj->funConnect();
	$txtFromDate    =  $_REQUEST['txtFromDate'];
	$txtToDate      =  $_REQUEST['txtToDate'];
	$selBType       =  $_REQUEST['selBType'];
	if($txtFromDate!='' && $txtToDate!='')
	{
		$sql = "select freight_cost_estimate_compare.COMID as COMID, freight_cost_estimete_master.VESSEL_IMO_ID as VESSEL_IMO_ID, freight_cost_estimate_compare.MESSAGE as MESSAGE, freight_cost_estimete_master.FIXTURETYPEID as FIXTURETYPEID from freight_cost_estimate_compare inner join freight_cost_estimete_master on freight_cost_estimete_master.FCAID= freight_cost_estimate_compare.FCAID WHERE freight_cost_estimate_compare.MODULEID='".$_SESSION['moduleid']."' AND freight_cost_estimate_compare.MCOMPANYID='".$_SESSION['company']."' and freight_cost_estimate_compare.FINAL_ID!='' and freight_cost_estimete_master.FIXED=1 and freight_cost_estimate_compare.STATUS in (1,2,4) and date(freight_cost_estimete_master.ADD_ON_DATE)>='".date('Y-m-d',strtotime($txtFromDate))."' and date(freight_cost_estimete_master.ADD_ON_DATE)<='".date('Y-m-d',strtotime($txtToDate))."' and freight_cost_estimete_master.ESTIMATE_TYPE='".$selBType."' order by date(freight_cost_estimete_master.FINAL_DATETIME) desc"; 
	}
	else
	{
		$txtToDate      =  date('Y-m-d',time());
		$txtFromDate    =  date('Y-m-d', strtotime('-3 month'));
	    
		$sql = "select freight_cost_estimate_compare.COMID as COMID, freight_cost_estimete_master.VESSEL_IMO_ID as VESSEL_IMO_ID, freight_cost_estimate_compare.MESSAGE as MESSAGE, freight_cost_estimete_master.FIXTURETYPEID as FIXTURETYPEID from freight_cost_estimate_compare inner join freight_cost_estimete_master on freight_cost_estimete_master.FCAID= freight_cost_estimate_compare.FCAID WHERE freight_cost_estimate_compare.MODULEID='".$_SESSION['moduleid']."' AND freight_cost_estimate_compare.MCOMPANYID='".$_SESSION['company']."' and freight_cost_estimate_compare.FINAL_ID!='' and freight_cost_estimete_master.FIXED=1 and freight_cost_estimate_compare.STATUS in (1,2,4) and date(freight_cost_estimete_master.ADD_ON_DATE)>='".date('Y-m-d',strtotime($txtFromDate))."' and date(freight_cost_estimete_master.ADD_ON_DATE)<='".date('Y-m-d',strtotime($txtToDate))."' and freight_cost_estimete_master.ESTIMATE_TYPE='".$selBType."' order by date(freight_cost_estimete_master.FINAL_DATETIME) desc"; 
	}
	$res = mysql_query($sql) or die($sql);
	$rec = mysql_num_rows($res);
	$arr_data = array();
	$arr_dumm = array();
	$sumdum = $sumdumAmt = $sumfreight = $sumfreightAmt = 0;
	$arr_freight = array();
	while($rows = mysql_fetch_assoc($res))
	{
		$sql_dem = "select sum(P_AMT) as sum1, sum(NET_PAYABLE) as sum2 from other_invoice_master where P_TYPE like 'Demurrage/Dispatch Invoice%' and COMID='".$rows['COMID']."'";
		//echo $sql_dem;
		$result_dem = mysql_query($sql_dem) or die($sql_dem);
		$rows_dem = mysql_fetch_assoc($result_dem);
		$dummerage =  $rows_dem['sum2'] - $rows_dem['sum1'];
		if($dummerage!=0)
		{
			$sumdum = $sumdum + 1;
			$sumdumAmt = $sumdumAmt + number_format($dummerage,2,'.','');
			$arr_dumm[] = array('vessel'=>$obj->getVesselIMOData($rows['VESSEL_IMO_ID'],"VESSEL_NAME").'('.$rows['MESSAGE'].')','dummerage'=>number_format($dummerage,2,'.',''));
		}
		
		$sql1 = "select PROFIT_LOSS from freight_cost_estimete_master where COMID='".$rows['COMID']."' and SHEET_NO is not NULL order by FCAID asc";
		$result1 = mysql_query($sql1) or die($sql1);
		$rows1 = mysql_fetch_assoc($result1);
		if($rows1['PROFIT_LOSS']!=NULL){$freightgross = $rows1['PROFIT_LOSS']/1000;}else{$freightgross = '';}
		
		$sql2 = "select PROFIT_LOSS from freight_cost_estimete_master where COMID='".$rows['COMID']."' and SHEET_NO is not NULL order by FCAID asc LIMIT 3 OFFSET 1";
		$result2 = mysql_query($sql2) or die($sql2);
		$rows2 = mysql_fetch_assoc($result2);
		if($rows2['PROFIT_LOSS']!=NULL){$interim = $rows2['PROFIT_LOSS']/1000;}else{$interim = '';}
		
		$sql3 = "select TOTAL_PREIGHT_ADJ, PROFIT_LOSS from freight_cost_estimete_master where COMID='".$rows['COMID']."' and SHEET_NO is not NULL order by FCAID desc";
		$result3 = mysql_query($sql3) or die($sql3);
		$rows3 = mysql_fetch_assoc($result3);
		
		$sql4 = "select sum(P_AMT) as SUM from freight_invoice_master where COMID='".$rows['COMID']."' order by COMID desc";
		$result4 = mysql_query($sql4) or die($sql4);
		$rows4 = mysql_fetch_assoc($result4);
		
		if($rows4['SUM']>0)
		{
			if($rows3['PROFIT_LOSS']!=NULL){$completion = $rows3['PROFIT_LOSS']/1000;}else{$completion = '';}
			
		}else
		{
			$completion = '';
		}
		
		$sql5 = "select sum(P_AMT) as SUM, sum(NET_PAYABLE) as SUM2 from freight_invoice_master where COMID='".$rows['COMID']."' order by COMID desc";
		$result5 = mysql_query($sql5) or die($sql5);
		$rows5 = mysql_fetch_assoc($result5);
		$freightamt = $rows5['SUM2'] - $rows5['SUM'];
		if($freightamt>0)
		{
			$sumfreight = $sumfreight + 1;
			$sumfreightAmt = $sumfreightAmt + $freightamt;
			$arr_freight[] = array('vessel'=>$obj->getVesselIMOData($rows['VESSEL_IMO_ID'],"VESSEL_NAME").'('.$rows['MESSAGE'].')','freight'=>number_format($freightamt,2,'.',''));
		}
		
		
		$arr_data[] = array('vessel'=>$obj->getVesselIMOData($rows['VESSEL_IMO_ID'],"VESSEL_NAME").'('.$rows['MESSAGE'].')','fixture'=>number_format($freightgross,2,'.',''),'Interim'=>number_format($interim,2,'.',''),'completion'=>number_format($completion,2,'.',''),'fixcolor'=>'#86a948','intrimgrey'=>'#999898','completeblue'=>'#367fa9');
	}
	
	echo json_encode($arr_data)."@@@".$rec."@@@".json_encode($arr_dumm)."@@@".$sumdum."@@@".json_encode($arr_freight)."@@@".number_format($sumfreight,0,'.','')."@@@".number_format($sumdumAmt,2,'.','')."@@@".number_format($sumfreightAmt,2,'.','');
}


function getCompareSheetDataTC()
{
	$obj 			= new data();
	$connect		= $obj->funConnect();
	$comid          =  $_REQUEST['comid'];
    $sql11 = "select chartering_estimate_tc_compare.COMID as COMID, TC_DATE, TC_NO, CP_DATE1 as CP_DATE, SUMMER_DWT, VESSEL_IMO_ID, VESSEL_TYPE from chartering_estimate_tc_compare inner join chartering_estimate_tc_master on chartering_estimate_tc_master.COMID=chartering_estimate_tc_compare.COMID where chartering_estimate_tc_master.COMID='".$comid."' order by chartering_estimate_tc_master.TCOUTID desc";
	$result11 = mysql_query($sql11) or die($sql11);
	$rows11 = mysql_fetch_assoc($result11);
	echo '<div class="row">
			<div class="col-xs-6">
				<h2 class="page-header">
				 Main Particulars
				</h2>                            
			</div><!-- /.col -->
			<div class="col-xs-6">
				<h2 class="page-header">
				 <a href="allExcel.php?id=27&comid='.$comid.'" title="Pdf"><button class="btn btn-default" type="button" style="margin-left: 115px; margin-top:-19px;"><i class="fa fa-download"></i> Generate Excel</button></a>
				</h2>                            
			</div><!-- /.col -->
		</div>
			
		<div class="row invoice-info">
			<div class="col-sm-4 invoice-col">
				 Vessel Name
				<address>
				'.$obj->getVesselIMOData($rows11['VESSEL_IMO_ID'],"VESSEL_NAME").'
			</div><!-- /.col -->
			 <div class="col-sm-4 invoice-col">
				 Vessel Type
				<address>
					'.$rows11['VESSEL_TYPE'].'
				</address>
			</div><!-- /.col -->
			<div class="col-sm-4 invoice-col">
				 DWT Summer
				<address>
					'.$rows11['SUMMER_DWT'].'
				</address>
			</div><!-- /.col -->
		</div>
			
		<div class="row invoice-info">
			<div class="col-sm-4 invoice-col">
			   Fixture Date
				<address>
				'.date('d-m-Y',strtotime($rows11['TC_DATE'])).'
				</address>
			</div><!-- /.col -->
			<div class="col-sm-4 invoice-col">
			   CP Date
				<address>
				'.date('d-m-Y',strtotime($rows11['CP_DATE'])).'
				</address>
			</div><!-- /.col -->
			<div class="col-sm-4 invoice-col">
				TC No
				<address>
					'.$rows11['TC_NO'].'
				</address>
			</div><!-- /.col -->
		</div>';
		 
		
	
	echo '<div class="box-body table-responsive">';
	echo '<table class="table table-bordered table-striped">';
	echo '<thead>';
	echo '<tr>';
	$sql = "SELECT * FROM chartering_estimate_tc_master where COMID='".$comid."' order by TCOUTID asc";
	$result = mysql_query($sql) ;
	$num = mysql_num_rows($result);
	$width = 90/$num;
	echo '<th align="center" valign="middle" width="10%">Sheet Name/Parameters</th>';
	$result = mysql_query($sql);
	while($rows= mysql_fetch_assoc($result))
	{
		$sql1 = "select SHEET_NAME from cost_sheettc_name_master where COST_SHEETID='".$rows['SHEET_NO']."' order by COST_SHEETID ";
		$res1 = mysql_query($sql1);
		$rows1 = mysql_fetch_assoc($res1);
		if(isset($rows1['SHEET_NAME']))
		{
		    echo '<th align="center" valign="middle" width="'.$width.'%">'.$rows1['SHEET_NAME'].'</th>';
		}
		else
		{
			echo '<th align="center" valign="middle" width="'.$width.'%">Fixture TC</th>';
		}
	}
	echo '</tr>';
	
	$array_revenue = array();
	echo '<tr>';
	echo '<td align="left" colspan="'.(1+$num).'"><span style="font-size:16px;"><strong>REVENUE</strong></span></td>';
	echo '</tr>';
	
	echo '<tr>';
	echo '<td align="center" valign="middle" width="10%">Daily Gross Hire(USD/Day)</td>';
	$result = mysql_query($sql);
	while($rows= mysql_fetch_assoc($result))
	{
		$arr_t = array();
		$sql2 = "select DAILY_GROSS_HIRE_EST from chartering_tc_estimate_slave1 where TCOUTID='".$rows['TCOUTID']."'";
		$result2 = mysql_query($sql2);
		while($rows2= mysql_fetch_assoc($result2))
		{
			$arr_t[] = $rows2['DAILY_GROSS_HIRE_EST'];
		}
		echo '<td align="center" valign="middle" width="'.$width.'%">'.implode('/',$arr_t).'</td>';
	}
	echo '</tr>';
	
	echo '<tr>';
	echo '<td align="center" valign="middle" width="10%">Add Comm(USD)</td>';
	$result = mysql_query($sql);
	while($rows= mysql_fetch_assoc($result))
	{
		$arr_t = array();
		$sql2 = "select ADD_COMM_CAL_EST from chartering_tc_estimate_slave1 where TCOUTID='".$rows['TCOUTID']."'";
		$result2 = mysql_query($sql2);
		while($rows2= mysql_fetch_assoc($result2))
		{
			$arr_t[] = $rows2['ADD_COMM_CAL_EST'];
		}
		echo '<td align="center" valign="middle" width="'.$width.'%">'.implode('/',$arr_t).'</td>';
	}
	echo '</tr>';
	
	echo '<tr>';
	echo '<td align="center" valign="middle" width="10%">Broker’s Comm(USD)</td>';
	$result = mysql_query($sql);
	while($rows= mysql_fetch_assoc($result))
	{
		$arr_t = array();
		$sql2 = "select BROKER_COMM_CAL_EST from chartering_tc_estimate_slave1 where TCOUTID='".$rows['TCOUTID']."'";
		$result2 = mysql_query($sql2);
		while($rows2= mysql_fetch_assoc($result2))
		{
			$arr_t[] = $rows2['BROKER_COMM_CAL_EST'];
		}
		echo '<td align="center" valign="middle" width="'.$width.'%">'.implode('/',$arr_t).'</td>';
	}
	echo '</tr>';
	
	echo '<tr>';
	echo '<td align="center" valign="middle" width="10%">Nett Hire(USD/day)</td>';
	$result = mysql_query($sql);
	while($rows= mysql_fetch_assoc($result))
	{
		$arr_t = array();
		$sql2 = "select NETT_HIRE_EST from chartering_tc_estimate_slave1 where TCOUTID='".$rows['TCOUTID']."'";
		$result2 = mysql_query($sql2);
		while($rows2= mysql_fetch_assoc($result2))
		{
			$arr_t[] = $rows2['NETT_HIRE_EST'];
		}
		echo '<td align="center" valign="middle" width="'.$width.'%">'.implode('/',$arr_t).'</td>';
	}
	echo '</tr>';
	
	echo '<tr>';
	echo '<td align="center" valign="middle" width="10%">Nett Rev(USD)</td>';
	$result = mysql_query($sql);
	while($rows= mysql_fetch_assoc($result))
	{
		$arr_t = array();
		$sql2 = "select TOTAL_REV_EST from chartering_tc_estimate_slave1 where TCOUTID='".$rows['TCOUTID']."'";
		$result2 = mysql_query($sql2);
		while($rows2= mysql_fetch_assoc($result2))
		{
			$arr_t[] = $rows2['TOTAL_REV_EST'];
		}
		echo '<td align="center" valign="middle" width="'.$width.'%">'.implode('/',$arr_t).'</td>';
	}
	echo '</tr>';
	
	echo '<tr>';
	echo '<td align="center" valign="middle" width="10%">Less Off Hire(USD)</td>';
	$result = mysql_query($sql);
	while($rows= mysql_fetch_assoc($result))
	{
		$arr_t = array();
		$sql2 = "select LESS_OFF_HIRE_EST from chartering_tc_estimate_slave1 where TCOUTID='".$rows['TCOUTID']."'";
		$result2 = mysql_query($sql2);
		while($rows2= mysql_fetch_assoc($result2))
		{
			$arr_t[] = $rows2['LESS_OFF_HIRE_EST'];
		}
		echo '<td align="center" valign="middle" width="'.$width.'%">'.implode('/',$arr_t).'</td>';
	}
	echo '</tr>';
	
	echo '<tr>';
	echo '<td align="center" valign="middle" width="10%">CVE(USD)</td>';
	$result = mysql_query($sql);
	while($rows= mysql_fetch_assoc($result))
	{
		$arr_t = array();
		$sql2 = "select CVE_EST from chartering_tc_estimate_slave1 where TCOUTID='".$rows['TCOUTID']."'";
		$result2 = mysql_query($sql2);
		while($rows2= mysql_fetch_assoc($result2))
		{
			$arr_t[] = $rows2['CVE_EST'];
		}
		echo '<td align="center" valign="middle" width="'.$width.'%">'.implode('/',$arr_t).'</td>';
	}
	echo '</tr>';
	
	echo '<tr>';
	echo '<td align="center" valign="middle" width="10%">Nett Hire to invoice(USD)</td>';
	$result = mysql_query($sql);
	while($rows= mysql_fetch_assoc($result))
	{
		$arr_t = array();
		$sql2 = "select NET_HIRE_AMT from chartering_tc_estimate_slave1 where TCOUTID='".$rows['TCOUTID']."'";
		$result2 = mysql_query($sql2);
		while($rows2= mysql_fetch_assoc($result2))
		{
			$arr_t[] = $rows2['NET_HIRE_AMT'];
		}
		echo '<td align="center" valign="middle" width="'.$width.'%">'.implode('/',$arr_t).'</td>';
	}
	echo '</tr>';
	
	echo '<tr>';
	echo '<td align="center" valign="middle" width="10%">Other Income(USD)</td>';
	$result = mysql_query($sql);
	while($rows= mysql_fetch_assoc($result))
	{
		$arr_t = array();
		$sql2 = "select NET_HIRE_AMT from chartering_tc_estimate_slave1 where TCOUTID='".$rows['TCOUTID']."'";
		$result2 = mysql_query($sql2);
		while($rows2= mysql_fetch_assoc($result2))
		{
			$arr_tt = array();
			$sql3 = "select OTHER_AMT from chartering_estimate_tc_slave2 where STATUS=1 and TC_SLAVE1ID='".$rows2['TC_SLAVE1ID']."'";
			$result3 = mysql_query($sql3);
			while($rows3 = mysql_fetch_assoc($result3))
			{
			    $arr_tt[] = $rows3['OTHER_AMT'];
			}
			$arr_t[] = array_sum($arr_tt);
		}
		echo '<td align="center" valign="middle" width="'.$width.'%">'.implode('/',$arr_t).'</td>';
	}
	echo '</tr>';
	
	echo '<tr>';
	echo '<td align="center" valign="middle" width="10%"><strong>Total Revenue(USD)</strong></td>';
	$result = mysql_query($sql);
	while($rows= mysql_fetch_assoc($result))
	{
		$arr_t = array();
		$sql2 = "select NET_HIRE_AMT from chartering_tc_estimate_slave1 where TCOUTID='".$rows['TCOUTID']."'";
		$result2 = mysql_query($sql2);
		while($rows2= mysql_fetch_assoc($result2))
		{
			$arr_t[] = $rows2['NET_HIRE_AMT'];
		}
		echo '<td align="center" valign="middle" width="'.$width.'%">'.implode('/',$arr_t).'</td>';
	}
	echo '</tr>';
	
	$array_expense = array();
	echo '<tr>';
	echo '<td align="left" colspan="'.(1+$num).'"><span style="font-size:16px;"><strong>EXPENSES </strong></span></td>';
	echo '</tr>';
	
	echo '<tr>';
	echo '<td align="center" valign="middle" width="10%">Other expenses(USD)</td>';
	$result = mysql_query($sql);
	while($rows= mysql_fetch_assoc($result))
	{
		$arr_t = array();
		$sql2 = "select NET_HIRE_AMT from chartering_tc_estimate_slave1 where TCOUTID='".$rows['TCOUTID']."'";
		$result2 = mysql_query($sql2);
		while($rows2= mysql_fetch_assoc($result2))
		{
			$arr_tt = array();
			$sql3 = "select OTHER_AMT from chartering_estimate_tc_slave2 where STATUS=2 and TC_SLAVE1ID='".$rows2['TC_SLAVE1ID']."'";
			$result3 = mysql_query($sql3);
			while($rows3 = mysql_fetch_assoc($result3))
			{
			    $arr_tt[] = $rows3['OTHER_AMT'];
			}
			$arr_t[] = array_sum($arr_tt);
		}
		echo '<td align="center" valign="middle" width="'.$width.'%">'.implode('/',$arr_t).'</td>';
	}
	echo '</tr>';
	
	echo '<tr>';
	echo '<td align="center" valign="middle" width="10%"><strong>Total Expenses(USD)</strong></td>';
	$result = mysql_query($sql);
	while($rows= mysql_fetch_assoc($result))
	{
		$arr_t = array();
		$sql2 = "select TC_SLAVE1ID from chartering_tc_estimate_slave1 where TCOUTID='".$rows['TCOUTID']."'";
		$result2 = mysql_query($sql2);
		while($rows2= mysql_fetch_assoc($result2))
		{
			$arr_tt = array();
			$sql3 = "select OTHER_AMT from chartering_estimate_tc_slave2 where STATUS=2 and TC_SLAVE1ID='".$rows2['TC_SLAVE1ID']."'";
			$result3 = mysql_query($sql3);
			while($rows3 = mysql_fetch_assoc($result3))
			{
			    $arr_tt[] = $rows3['OTHER_AMT'];
			}
			$arr_t[] = array_sum($arr_tt);
		}
		echo '<td align="center" valign="middle" width="'.$width.'%">'.array_sum($arr_t).'</td>';
	}
	echo '</tr>';
	
	echo '<tr>';
	echo '<td align="left" colspan="'.(1+$num).'"><span style="font-size:16px;"><strong>RESULTS </strong></span></td>';
	echo '</tr>';
	
	echo '<tr>';
	echo '<td align="center" valign="middle" width="10%"><strong>TC Earnings(USD)</strong></td>';
	$result = mysql_query($sql);
	while($rows= mysql_fetch_assoc($result))
	{
		$arr_t = array();
		$sql2 = "select VOYAGE_EARN_EST from chartering_tc_estimate_slave1 where TCOUTID='".$rows['TCOUTID']."'";
		$result2 = mysql_query($sql2);
		while($rows2= mysql_fetch_assoc($result2))
		{
			$arr_t[] = $rows2['VOYAGE_EARN_EST'];
		}
		echo '<td align="center" valign="middle" width="'.$width.'%">'.implode('/',$arr_t).'</td>';
	}
	echo '</tr>';
	
	
	
	echo '<tr>';
	echo '<td align="center" valign="middle" width="10%"><strong>Profit/Day(USD)</strong></td>';
	$result = mysql_query($sql);
	while($rows= mysql_fetch_assoc($result))
	{
		$arr_t = array();
		$sql2 = "select PROFIT_PER_DAY_EST from chartering_tc_estimate_slave1 where TCOUTID='".$rows['TCOUTID']."'";
		$result2 = mysql_query($sql2);
		while($rows2= mysql_fetch_assoc($result2))
		{
			$arr_t[] = $rows2['PROFIT_PER_DAY_EST'];
		}
		echo '<td align="center" valign="middle" width="'.$width.'%">'.implode('/',$arr_t).'</td>';
	}
	echo '</tr>';
	
	
	
	echo '</tbody>';
	echo '</table>';
	echo '</div>';
}


function getTCDecisionChartList()
{
	$obj 			= new data();
	$connect		= $obj->funConnect();
	$val   =  $_REQUEST['val'];
	$val1  =  $_REQUEST['val2'];
	if(strlen($val1) ==1){$val1 = "00".$val1;}
	if(strlen($val1) ==2){$val1 = "0".$val1;}
	if(strlen($val1) >2){$val1 = $val1;}
	$sql1 = "select * from chartering_estimate_tc_compare WHERE MODULEID='".$_SESSION['moduleid']."' AND MCOMPANYID='".$_SESSION['company']."' and MESSAGE ='".$val."-".$val1."' ";
	$res1 = mysql_query($sql1);
	$arr = array();
	while($row1 = mysql_fetch_assoc($res1))
	{
		$arr[] = $row1['TCOUTID'];
	}
	$arr1 = implode(',',$arr);
	echo '<div class="box-body table-responsive">
	<div align="right" style="margin-bottom:10px; margin-top:-10px;"><a href="allPdf.php?id=58&val='.$val.'&val2='.$val1.'" title="Pdf"><button class="btn btn-default" style="margin-right: 5px;"><i class="fa fa-download"></i> Generate PDF</button></a></div>';
	echo '<table id="fce1_list" class="table table-bordered table-striped">';
	echo '<thead>';
	echo '<tr>';
	echo '<th align="center" valign="middle" width="5%">#</th>';
	echo '<th align="left" valign="middle" width="12%">Vessel</th>';
	echo '<th align="left" valign="middle" width="10%">Vessel Type</th>';
	echo '<th align="left" valign="middle" width="10%">TC No.</th>';
	echo '<th align="left" valign="middle" width="10%">CP Date</th>';
	echo '<th align="left" valign="middle" width="10%">DWT</th>';
	echo '<th align="left" valign="middle" width="10%">Del Port</th>';
	echo '<th align="left" valign="middle" width="6%">Re Del Port</th>';
	echo '<th align="left" valign="middle" width="10%">TC Days</th>';
	echo '<th align="left" valign="middle" width="5%">Daily Gross Hire(USD)</th>';
	echo '<th align="left" valign="middle" width="5%">Total Rev(USD)</th>';
	echo '<th align="left" valign="middle" width="5%">Status</th>';
	echo '<th align="left" valign="middle" width="25%">Remarks<br/><div style="min-width:150px;"></div></th>';
	echo '<th align="center" valign="middle" width="5%">Select</th>';
	echo '<th align="center" valign="middle" width="5%">View</th>';
	echo '</tr>';
	echo '</thead>';
	echo '<tbody id="tbody">';
	
	$sql = "SELECT TCOUTID, vessel_imo_master.VESSEL_NAME, chartering_estimate_tc_master.VESSEL_TYPE, chartering_estimate_tc_master.EXCHANGE_RATE, (select SUM(TC_DAYS_EST) as SUM from chartering_tc_estimate_slave1 where chartering_tc_estimate_slave1.TCOUTID= chartering_estimate_tc_master.TCOUTID) as TC_DAYS_EST, (select SUM(TOTAL_REV_EST) as SUM from chartering_tc_estimate_slave1 where chartering_tc_estimate_slave1.TCOUTID= chartering_estimate_tc_master.TCOUTID) as TOTAL_REV_EST, vessel_imo_master.VESSEL_IMO_ID, TC_NO, SEL_CP_TYPE, CP_DATE1, FUEL_SPECS, MASTERS_NAME, DWT_SUMMER_CP, DEL_RANGE_PORT, RE_DEL_RANGE, HIRE_FIX_PER FROM chartering_estimate_tc_master inner JOIN vessel_imo_master ON vessel_imo_master.VESSEL_IMO_ID=chartering_estimate_tc_master.VESSEL_IMO_ID WHERE MODULEID='".$_SESSION['moduleid']."' AND chartering_estimate_tc_master.MCOMPANYID='".$_SESSION['company']."' and TCOUTID in (".$arr1.") order by TCOUTID desc";
	$res = mysql_query($sql) or die($sql);
	$rec = mysql_num_rows($res);
	$i = 1;
	if($rec == 0)
	{
		
	}
	else{
		while($rows = mysql_fetch_assoc($res))
		{
			$sql2 = "select * from chartering_estimate_tc_compare WHERE MESSAGE ='".$val."-".$val1."' and TCOUTID='".$rows['TCOUTID']."' ";
			$res2 = mysql_query($sql2);
			$row2 = mysql_fetch_assoc($res2);
			if($rows['FIXED']==1){$fixed = "Finalised";}else{$fixed = "Not Fixed";}
			if($row2['TCOUTID']==$row2['FINAL_ID']){$checked = "checked";}else{$checked = "";}
			
			if($rows['EXCHANGE_RATE']>0 || $rows['EXCHANGE_RATE']<0){$exchangerate = $rows['EXCHANGE_RATE'];}else{$exchangerate = 1;}
			echo '<tr>';
			echo '<td align="center" valign="middle" class="input-text">'.$i.'.</td>';
			echo '<td align="left" valign="middle" class="input-text">'.$rows['VESSEL_NAME'].'</td>';
			echo '<td align="left" valign="middle" class="input-text">'.$rows['VESSEL_TYPE'].'</td>';
			echo '<td align="left" valign="middle" class="input-text">'.$rows['TC_NO'].'</td>';
			if($rows['CP_DATE1']=="" || $rows['CP_DATE1']=="1970-01-01"){$CP_DATE1 = "";}else{$CP_DATE1 = date('d-m-Y',strtotime($rows['CP_DATE1']));}
			echo '<td align="left" valign="middle" class="input-text">'.$CP_DATE1.'</td>';
			echo '<td align="left" valign="middle" class="input-text">'.$rows['DWT_SUMMER_CP'].'</td>';
			echo '<td align="left" valign="middle" class="input-text">'.$rows['DEL_RANGE_PORT'].'</td>';
			echo '<td align="left" valign="middle" class="input-text">'.$rows['RE_DEL_RANGE'].'</td>';
			echo '<td align="left" valign="middle" class="input-text">'.$rows['TC_DAYS_EST'].'</td>';
			echo '<td align="left" valign="middle" class="input-text">'.number_format(($rows['HIRE_FIX_PER']*$exchangerate),2,'.','').'</td>';
			echo '<td align="left" valign="middle" class="input-text">'.$rows['TOTAL_REV_EST'].'</td>';
			echo '<td align="left" valign="middle" class="input-text">'.$fixed.'</td>';
			echo '<td align="left" valign="middle" class="input-text">'.$row2['REMARKS'].'</td>';
			echo '<td align="center" valign="middle" class="input-text"><b><input type="radio" name="rdoFCA" id="rdoFCA_'.$i.'" value="'.$rows['TCOUTID'].'" class="checkbox"  '.$checked.'/></b><input type="hidden" name="hiddnFca_'.$i.'" id="hiddnFca_'.$i.'" value="'.$rows['TCOUTID'].'"/></td>';
			echo '<td align="center" valign="middle" class="input-text"><a href="viewtcestimate.php?id='.$rows['TCOUTID'].'&rttype=4" title="View Details"><strong><i class="fa fa-file"></i></strong></a></td>';
			echo '</tr>';
			$i++;
		}
	}echo '</tbody>';
	echo '</table></div>';
}



function getTCCompareEstimatesList()
{
	$obj 			= new data();
	$connect		= $obj->funConnect();
	$chkArr   =  $_REQUEST['chkArr'];
	echo '<div class="box-body table-responsive">';
	echo '<table id="fce1_list" class="table table-bordered table-striped">';
	echo '<thead>';
	echo '<tr>';
	echo '<th align="center" valign="middle" width="5%">#</th>';
	echo '<th align="left" valign="middle" width="12%">Vessel</th>';
	echo '<th align="left" valign="middle" width="10%">Vessel Type</th>';
	echo '<th align="left" valign="middle" width="10%">TC No.</th>';
	echo '<th align="left" valign="middle" width="10%">CP Date</th>';
	echo '<th align="left" valign="middle" width="10%">DWT</th>';
	echo '<th align="left" valign="middle" width="10%">Del Port</th>';
	echo '<th align="left" valign="middle" width="6%">Re Del Port</th>';
	echo '<th align="left" valign="middle" width="10%">TC Days</th>';
	echo '<th align="left" valign="middle" width="5%">Daily Gross Hire(USD)</th>';
	echo '<th align="left" valign="middle" width="5%">Total Rev(USD)</th>';
	echo '<th align="left" valign="middle" width="25%">Remarks<br/><div style="min-width:150px;"></div></th>';
	echo '<th align="center" valign="middle" width="5%">Select</th>';
	echo '<th align="center" valign="middle" width="2%">Edit</th>';
	echo '</tr>';
	echo '</thead>';
	echo '<tbody id="tbody">';
	
	$sql = "SELECT TCOUTID, vessel_imo_master.VESSEL_NAME, chartering_estimate_tc_master.VESSEL_TYPE, chartering_estimate_tc_master.EXCHANGE_RATE, (select SUM(TC_DAYS_EST) as SUM from chartering_tc_estimate_slave1 where chartering_tc_estimate_slave1.TCOUTID= chartering_estimate_tc_master.TCOUTID) as TC_DAYS_EST, (select SUM(TOTAL_REV_EST) as SUM from chartering_tc_estimate_slave1 where chartering_tc_estimate_slave1.TCOUTID= chartering_estimate_tc_master.TCOUTID) as TOTAL_REV_EST, vessel_imo_master.VESSEL_IMO_ID, TC_NO, SEL_CP_TYPE, CP_DATE1, FUEL_SPECS, MASTERS_NAME, DWT_SUMMER_CP, DEL_RANGE_PORT, RE_DEL_RANGE, HIRE_FIX_PER FROM chartering_estimate_tc_master inner JOIN vessel_imo_master ON vessel_imo_master.VESSEL_IMO_ID=chartering_estimate_tc_master.VESSEL_IMO_ID WHERE MODULEID='".$_SESSION['moduleid']."' AND chartering_estimate_tc_master.MCOMPANYID='".$_SESSION['company']."' and TCOUTID in (".$chkArr.") order by TCOUTID desc";
	
	$res = mysql_query($sql) or die($sql);
	$rec = mysql_num_rows($res);
	$i = 1;
	if($rec == 0)
	{
		
	}
	else{
		while($rows = mysql_fetch_assoc($res))
		{
			if($rows['EXCHANGE_RATE']>0 || $rows['EXCHANGE_RATE']<0){$exchangerate = $rows['EXCHANGE_RATE'];}else{$exchangerate = 1;}
			echo '<tr>';
			echo '<td align="center" valign="middle" class="input-text">'.$i.'.</td>';
			echo '<td align="left" valign="middle" class="input-text">'.$rows['VESSEL_NAME'].'</td>';
			echo '<td align="left" valign="middle" class="input-text">'.$rows['VESSEL_TYPE'].'</td>';
			echo '<td align="left" valign="middle" class="input-text">'.$rows['TC_NO'].'</td>';
			if($rows['CP_DATE1']=="" || $rows['CP_DATE1']=="1970-01-01"){$CP_DATE1 = "";}else{$CP_DATE1 = date('d-m-Y',strtotime($rows['CP_DATE1']));}
			echo '<td align="left" valign="middle" class="input-text">'.$CP_DATE1.'</td>';
			echo '<td align="left" valign="middle" class="input-text">'.$rows['DWT_SUMMER_CP'].'</td>';
			echo '<td align="left" valign="middle" class="input-text">'.$rows['DEL_RANGE_PORT'].'</td>';
			echo '<td align="left" valign="middle" class="input-text">'.$rows['RE_DEL_RANGE'].'</td>';
			echo '<td align="left" valign="middle" class="input-text">'.$rows['TC_DAYS_EST'].'</td>';
			echo '<td align="left" valign="middle" class="input-text">'.number_format(($rows['HIRE_FIX_PER']*$exchangerate),2,'.','').'</td>';
			echo '<td align="left" valign="middle" class="input-text">'.$rows['TOTAL_REV_EST'].'</td>';
			echo '<td align="left" valign="middle" class="input-text"><textarea class="form-control areasize" name="txtDesc_'.$i.'" id="txtDesc_'.$i.'" rows="3" placeholder="Remarks ..." ></textarea></td>';
			echo '<td align="center" valign="middle" class="input-text"><input type="radio" name="rdoFCA" id="rdoFCA_'.$i.'" value="'.$rows['TCOUTID'].'" class="checkbox"/><input type="hidden" name="hiddnFca_'.$i.'" id="hiddnFca_'.$i.'" value="'.$rows['TCOUTID'].'"/></td>';
			echo '<td align="center" valign="middle" class="input-text"><a href="updatetcestimate.php?id='.$rows['TCOUTID'].'&ids='.$chkArr.'" title="Edit Details" ><i class="fa fa-edit "></i></a></td>';	
			echo '</tr>';
			$i++;
		}
	}
	echo '</tbody>';
	echo '</table></div>
	
	       <div class="row invoice-info" >
				<div class="col-sm-12 invoice-col" style="text-align:right;">
					<address>
					   <button type="button" class="btn btn-info btn-flat" onclick="SubmitToCompare();">Submit</button>
					   <input type="hidden" name="hddnCount" id="hddnCount" value="'.$rec.'" />
					</address>
				</div>
            </div>';
}



function getCharteringRegisterDataDetailed()
{
	$obj 		  = new data();
	$connect	  = $obj->funConnect();
	
	$txtFrom_Date = date('Y-m-d',strtotime($_REQUEST['txtFrom_Date']));
	$txtTo_Date   =  date('Y-m-d',strtotime($_REQUEST['txtTo_Date']));
	$selBType     = $_REQUEST['selBType'];
	$selCOASpot   = $_REQUEST['selCOASpot'];
	
	if($selCOASpot == 2){$subquery = " and freight_cost_estimate_compare.COAAID is not NULL";}else{$subquery = " and freight_cost_estimate_compare.COAAID is NULL";}
	
	
	$sql = "select freight_cost_estimate_compare.COMID as COMID, freight_cost_estimate_compare.COAAID as COAAID, (select CONTACT_PERSON from login where login.LOGINID=freight_cost_estimate_compare.USERID) as CHARTERINGUSER, (select CONTACT_PERSON from login where login.LOGINID=freight_cost_estimate_compare.OPERATOR) as OPSUSER, freight_cost_estimete_master.VESSEL_IMO_ID as VESSEL_IMO_ID, freight_cost_estimate_compare.MESSAGE as MESSAGE, freight_cost_estimete_master.CP_DATE as CP_DATE, freight_cost_estimete_master.DWT_SUMMER as DWT_SUMMER, freight_cost_estimete_master.DWT_TOPICAL as DWT_TOPICAL, freight_cost_estimete_master.QTY_TYPE_RADIO as QTY_TYPE_RADIO, freight_cost_estimete_master.TRANS_DATE as TRANS_DATE, freight_cost_estimete_master.FCAID as FCAID, freight_cost_estimete_master.VOYAGE_NO as VOYAGE_NO, freight_cost_estimete_master.VOYAGE_NAME as VOYAGE_NAME from freight_cost_estimate_compare inner join freight_cost_estimete_master on freight_cost_estimete_master.FCAID= freight_cost_estimate_compare.FCAID WHERE freight_cost_estimate_compare.MODULEID='".$_SESSION['moduleid']."' AND freight_cost_estimate_compare.MCOMPANYID='".$_SESSION['company']."' and freight_cost_estimate_compare.FINAL_ID!='' and freight_cost_estimete_master.FIXED=1 and freight_cost_estimate_compare.STATUS in (1,2) and freight_cost_estimete_master.TRANS_DATE>='".$txtFrom_Date."' and freight_cost_estimete_master.TRANS_DATE<='".$txtTo_Date."'  and freight_cost_estimete_master.ESTIMATE_TYPE='".$selBType."' ".$subquery." group by freight_cost_estimate_compare.COMID "; 
	$res 		  = mysql_query($sql);
	$rec     	  = mysql_num_rows($res);
	$j=1;
	$cost_sheet_id = "";
	$arr = array();
	
	echo '<table id="sf_list" class="table table-bordered table-striped dataTable">
		<thead>
			<tr>
				<th rowspan="2" align="left" valign="top" width="10%">Sr.&nbsp;No.</th>
				<th rowspan="2" align="left" valign="top" width="10%">Nom&nbsp;ID</th>';
				if($selCOASpot == 2){
					echo '<th rowspan="2" align="left" valign="top" width="10%">Voyage&nbsp;No./COA ID</th>';
				}else{
					echo '<th rowspan="2" align="left" valign="top" width="10%">Voyage&nbsp;No./Voyage Name</th>';
				}
				echo '<th rowspan="2" align="left" valign="top" width="10%">Vessel&nbsp;Name</th>	
				<th rowspan="2" align="left" valign="top" width="10%">CPIC</th>
				<th rowspan="2" align="left" valign="top" width="10%">OPS PIC</th>
				<th rowspan="2" align="left" valign="top" width="10%">&nbsp;&nbsp;DWT&nbsp;&nbsp;</th>
				<th rowspan="2" valign="top" width="10%">Cargo&nbsp;Name</th>
				<th rowspan="2" align="left" valign="top" width="10%">CP&nbsp;Date</th>
				<th rowspan="2" align="left" valign="top" width="10%">Owner&nbsp;Name (TC Hire In)</th>
				<th rowspan="2" align="left" valign="top" width="10%">&nbsp;&nbsp;Charterer&nbsp;&nbsp;</th>
				<th rowspan="2" align="left" valign="top" width="10%">Fixture&nbsp;Date</th>
				<th colspan="8" align="left" valign="top" width="10%">Initial&nbsp;P&nbsp;&&nbsp;L</th>
				<th colspan="8" align="left" valign="top" width="10%">Final&nbsp;P&nbsp;&&nbsp;L</th>
				<th rowspan="2" align="left" valign="top" width="10%">Remarks</th>
			</tr>
			<tr>
				<th align="left" valign="top" width="10%">&nbsp;P&nbsp;&&nbsp;L&nbsp;</th>
				<th align="left" valign="top" width="10%">Revenue</th>
				<th align="left" valign="top" width="10%">Demurrage /Dispatch</th>
				<th align="left" valign="top" width="10%">Operational Expenses</th>
				<th align="left" valign="top" width="10%">Port Expenses</th>
				<th align="left" valign="top" width="10%">Bunker Expenses</th>
				<th align="left" valign="top" width="10%">Hire Due</th>
				<th align="left" valign="top" width="10%">Hire Paid</th>
				
				<th align="left" valign="top" width="10%">&nbsp;P&nbsp;&&nbsp;L&nbsp;</th>
				<th align="left" valign="top" width="10%">Revenue</th>
				<th align="left" valign="top" width="10%">Demurrage /Dispatch</th>
				<th align="left" valign="top" width="10%">Operational Expenses</th>
				<th align="left" valign="top" width="10%">Port Expenses</th>
				<th align="left" valign="top" width="10%">Bunker Expenses</th>
				<th align="left" valign="top" width="10%">Hire Due</th>
				<th align="left" valign="top" width="10%">Hire Paid</th>
			</tr>
		</thead>
	<tbody>';
	
	if($rec == 0)
	{
		
	}else{
	
		while($rows = mysql_fetch_assoc($res))
		{
			$l_cost_sheet_id = $obj->getLatestCostSheetID($rows['COMID']);
			$cpdate = $obj->getCompareEstimateData($rows['COMID'],"CP_DATE");
			if($cpdate!="0000-00-00" && $cpdate!=""){$cpdate = date('d-m-Y',strtotime($cpdate));}else{$cpdate = "";}
			$fixturedate = date('d-m-Y',strtotime($obj->getCompareEstimateData($rows['COMID'],"TRANS_DATE")));
			echo '<tr>';
			echo '<td align="center" valign="middle">'.$j.'</td>';
			echo '<td align="left" valign="middle">'.$rows['MESSAGE'].'</td>';
			if($selCOASpot == 2){
			echo '<td align="left" valign="middle">'.$obj->getCompareEstimateData($rows['COMID'],"VOYAGE_NO").'/'.$obj->getCoaData($rows['COAAID'],"COA_ID").'</td>';
			}else{
			echo '<td align="left" valign="middle">'.$obj->getCompareEstimateData($rows['COMID'],"VOYAGE_NO").'/'.$obj->getCompareEstimateData($rows['COMID'],"VOYAGE_NAME").'</td>';
			}
			echo '<td align="left" valign="middle">'.$obj->getVesselIMOData($rows['VESSEL_IMO_ID'],"VESSEL_NAME").'</td>';
			echo '<td align="left" valign="middle">'.$rows['CHARTERINGUSER'].'</td>';
			echo '<td align="left" valign="middle">'.$rows['OPSUSER'].'</td>';
			echo '<td align="left" valign="middle">'.$obj->getCompareEstimateData($rows['COMID'],"DWT_SUMMER").'</td>';
			echo '<td align="left" valign="middle">'.$obj->getMaterialCodeDesBasedOnId($obj->getOpenCargoPositionData($obj->getCompareEstimateData($rows['COMID'],"OPEN_CARGOID"),"CARGO")).'</td>';
			echo '<td align="left" valign="middle">'.$cpdate.'</td>';
			echo '<td align="left" valign="middle">'.$obj->getVendorListNewBasedOnID($obj->getOpenCargoPositionData($obj->getCompareEstimateData($rows['COMID'],"OPEN_CARGOID"),"OWNER")).'</td>';
			echo '<td align="left" valign="middle">'.$obj->getVendorListNewBasedOnID($obj->getOpenCargoPositionData($obj->getCompareEstimateData($rows['COMID'],"OPEN_CARGOID"),"CHARTERER")).'</td>';
			echo '<td align="left" valign="middle">'.$fixturedate.'</td>';
			
			$res14 = mysql_query("select FCAID, PROFIT_LOSS, REVENUES_FREIGHT, TOTAL_ORC_EXP_AMT, PORT_EXPENSES, BUNKER_EXPENSES, HIDDEN_HIRAGE from freight_cost_estimete_master where COMID='".$rows['COMID']."' and SHEET_NO!='' order by FCAID asc");
			$i =0;
			$first_pl = $last_pl = $first_revenue = $last_revenue = $first_demudes = $last_demudes = $first_operation = $last_operation = $first_port = $last_port = $first_bunker = $last_bunker = $first_hiredue = $last_hiredue = $first_hirepaid = $last_hirepaid = '';
			$num14 = mysql_num_rows($res14);
			while($row14 = mysql_fetch_assoc($res14))
			{
				if($i==0)
				{
					$first_pl = $row14['PROFIT_LOSS'];
					$first_revenue = $row14['REVENUES_FREIGHT'];
					$sql15 = "select sum(DDCLP_NETCOST + DDCDP_NETCOST) as sum from freight_cost_estimete_slave1 where FCAID='".$row14['FCAID']."'";
					$result15 = mysql_query($sql15) or die($sql15);
					$row15 = mysql_fetch_assoc($result15);
					$first_demudes = $row15['sum'];
					$first_operation = $row14['TOTAL_ORC_EXP_AMT'];
					$first_port = $row14['PORT_EXPENSES'];
					$first_bunker = $row14['BUNKER_EXPENSES'];
					$sqlsavedinvoic = "select * from freight_cost_estimete_slave11 where FCAID='".$row14['FCAID']."'";
					$ressavedinvoice = mysql_query($sqlsavedinvoic);
					$sum1 = $valueinv = 0;
					$hirage = $row14['HIDDEN_HIRAGE'];
					while($rowssavedinvoice = mysql_fetch_assoc($ressavedinvoice))
					{
						$sqlinvoice = "select FINAL_AMT, P_AMT, INVOICE_TYPE from invoice_hire_master WHERE INVOICEID='".$rowssavedinvoice['INVOICEID']."'";
						$resinvoice = mysql_query($sqlinvoice);
						$numinvoice = mysql_num_rows($resinvoice);
						
						while($rowsinvoice = mysql_fetch_assoc($resinvoice))
						{
							$sum1 = $sum1 + $rowsinvoice['P_AMT'];
							$hirage = $hirage - $rowsinvoice['P_AMT'];
						    if($rowsinvoice['INVOICE_TYPE']=="Final"){$valueinv = 1;}
						}
					}
					if($valueinv == 1){$hirage=0;}
					$first_hiredue = $hirage;
					$first_hirepaid = $sum1;
					
				}
				elseif($num14 == ($i+1))
				{
					$last_pl = $row14['PROFIT_LOSS'];
					$last_revenue = $row14['REVENUES_FREIGHT'];
					
					$sql15 = "select sum(TTL_DEMURRAGE) as sum1, sum(TTL_DESPATCH) as sum2 from laytime_master where COMID='".$rows['COMID']."' ";
					$res15 = mysql_query($sql15);
					$rec15 = mysql_num_rows($res15);
					$row15 = mysql_fetch_assoc($res15);
					$last_demudes = number_format($row15['sum1'],2,'.','') - number_format($row15['sum2'],2,'.','');
					$last_operation = $row14['TOTAL_ORC_EXP_AMT'];
					$last_port = $row14['PORT_EXPENSES'];
					$last_bunker = $row14['BUNKER_EXPENSES'];
					$sqlsavedinvoic = "select * from freight_cost_estimete_slave11 where FCAID='".$row14['FCAID']."'";
					
					$ressavedinvoice = mysql_query($sqlsavedinvoic);
					$sum1 = $valueinv = 0;
					$hirage = $row14['HIDDEN_HIRAGE'];
					while($rowssavedinvoice = mysql_fetch_assoc($ressavedinvoice))
					{
						$sqlinvoice = "select FINAL_AMT, P_AMT, INVOICE_TYPE from invoice_hire_master WHERE INVOICEID='".$rowssavedinvoice['INVOICEID']."'";
						
						$resinvoice = mysql_query($sqlinvoice);
						$numinvoice = mysql_num_rows($resinvoice);
						
						while($rowsinvoice = mysql_fetch_assoc($resinvoice))
						{
							$sum1 = $sum1 + $rowsinvoice['P_AMT'];
							$hirage = $hirage - $rowsinvoice['P_AMT'];
						    if($rowsinvoice['INVOICE_TYPE']=="Final"){$valueinv = 1;}
						}
					}
					if($valueinv == 1){$hirage=0;}
					$last_hiredue = $hirage;
					$last_hirepaid = $sum1;//echo $sum1;
				}
				$i = $i + 1;
			}
			echo '<td align="left" valign="middle">'.$first_pl.'</td>';
			echo '<td align="left" valign="middle">'.$first_revenue.'</td>';
			echo '<td align="left" valign="middle">'.$first_demudes.'</td>';
			echo '<td align="left" valign="middle">'.$first_operation.'</td>';
			echo '<td align="left" valign="middle">'.$first_port.'</td>';
			echo '<td align="left" valign="middle">'.$first_bunker.'</td>';
			echo '<td align="left" valign="middle">'.$first_hiredue.'</td>';
			echo '<td align="left" valign="middle">'.$first_hirepaid.'</td>';
			
			echo '<td align="left" valign="middle">'.$last_pl.'</td>';
			echo '<td align="left" valign="middle">'.$last_revenue.'</td>';
			echo '<td align="left" valign="middle">'.$last_demudes.'</td>';
			echo '<td align="left" valign="middle">'.$last_operation.'</td>';
			echo '<td align="left" valign="middle">'.$last_port.'</td>';
			echo '<td align="left" valign="middle">'.$last_bunker.'</td>';
			echo '<td align="left" valign="middle">'.$last_hiredue.'</td>';
			echo '<td align="left" valign="middle">'.$last_hirepaid.'</td>';
			echo '<td align="left" valign="middle"></td>';
			echo '</tr>';
			$j++;
		}
	}
	echo '</tbody>';
	echo '</table>';		
}


function getCharteringRegisterData()
{
	$obj 		  = new data();
	$connect	  = $obj->funConnect();
	
	$txtFrom_Date = date('Y-m-d',strtotime($_REQUEST['txtFrom_Date']));
	$txtTo_Date   =  date('Y-m-d',strtotime($_REQUEST['txtTo_Date']));
	$selBType     = $_REQUEST['selBType'];
	$selCOASpot   = $_REQUEST['selCOASpot'];
	
	if($selCOASpot == 2){$subquery = " and freight_cost_estimate_compare.COAAID is not NULL";}else{$subquery = " and freight_cost_estimate_compare.COAAID is NULL";}
	
	$sql = "select freight_cost_estimate_compare.COMID as COMID, freight_cost_estimate_compare.COAAID, (select CONTACT_PERSON from login where login.LOGINID=freight_cost_estimate_compare.USERID) as CHARTERINGUSER, (select CONTACT_PERSON from login where login.LOGINID=freight_cost_estimate_compare.OPERATOR) as OPSUSER, freight_cost_estimate_compare.COAAID as COAAID, freight_cost_estimete_master.VESSEL_IMO_ID as VESSEL_IMO_ID, freight_cost_estimete_master.ESTIMATE_TYPE as ESTIMATE_TYPE, freight_cost_estimate_compare.MESSAGE as MESSAGE, freight_cost_estimete_master.CP_DATE as CP_DATE, freight_cost_estimete_master.DWT_SUMMER as DWT_SUMMER, freight_cost_estimete_master.DWT_TOPICAL as DWT_TOPICAL, freight_cost_estimete_master.QTY_TYPE_RADIO as QTY_TYPE_RADIO, freight_cost_estimete_master.TRANS_DATE as TRANS_DATE, freight_cost_estimete_master.FCAID as FCAID, freight_cost_estimete_master.VOYAGE_NO as VOYAGE_NO, freight_cost_estimete_master.VOYAGE_NAME as VOYAGE_NAME from freight_cost_estimate_compare inner join freight_cost_estimete_master on freight_cost_estimete_master.FCAID= freight_cost_estimate_compare.FCAID WHERE freight_cost_estimate_compare.MODULEID='".$_SESSION['moduleid']."' AND freight_cost_estimate_compare.MCOMPANYID='".$_SESSION['company']."' and freight_cost_estimate_compare.FINAL_ID!='' and freight_cost_estimete_master.FIXED=1 and freight_cost_estimate_compare.STATUS in (1,2) and freight_cost_estimete_master.TRANS_DATE>='".$txtFrom_Date."' and freight_cost_estimete_master.TRANS_DATE<='".$txtTo_Date."' and freight_cost_estimete_master.ESTIMATE_TYPE='".$selBType."' ".$subquery." group by freight_cost_estimate_compare.COMID "; 
	
	$res 		  = mysql_query($sql) or die($sql);
	$rec     	  = mysql_num_rows($res);
	$j=1;
	$cost_sheet_id = "";
	$arr = array();
	
	echo '<table id="sf_list" class="table table-bordered table-striped dataTable">
		<thead>
			<tr>
			<th align="left" valign="top" width="5%">Sr.&nbsp;No.</th>
			<th align="left" valign="top" width="10%">Nom&nbsp;ID</th>';
			if($selCOASpot == 2){
			echo '<th align="left" valign="top" width="10%">Voyage&nbsp;No./ COA ID</th>';
			}else{
			echo '<th align="left" valign="top" width="10%">Voyage&nbsp;No./ Voyage Name</th>';}
			echo '<th align="left" valign="top" width="10%">Vessel&nbsp;Name</th>	
			<th align="left" valign="top" width="10%">CPIC</th>
			<th align="left" valign="top" width="10%">OPS PIC</th>
			<th align="left" valign="top" width="10%">DWT</th>
			<th align="left" valign="top" width="10%">Cargo Name</th>
			<th align="left" valign="top" width="10%">&nbsp;&nbsp;&nbsp;&nbsp;CP&nbsp;Date&nbsp;&nbsp;&nbsp;&nbsp;</th>
			<th align="left" valign="top" width="10%">Owner&nbsp;Name (TC Hire In)</th>
			<th align="left" valign="top" width="10%">&nbsp;&nbsp;Charterer&nbsp;&nbsp;</th>
			<th align="left" valign="top" width="10%">Fixture&nbsp;Date</th>
			<th align="left" valign="top" width="10%">&nbsp;Revenue&nbsp;</th>
			<th align="left" valign="top" width="10%">Initial&nbsp;P&nbsp;&&nbsp;L</th>
			<th align="left" valign="top" width="10%">Final&nbsp;P&nbsp;&&nbsp;L</th>
			<th align="left" valign="top" width="10%">Remarks</th>
			</tr>
		</thead>
	<tbody>';
	
	if($rec == 0)
	{
		
	}else{
	
		while($rows = mysql_fetch_assoc($res))
		{
			$l_cost_sheet_id = $obj->getLatestCostSheetID($rows['COMID']);
			$cpdate = $obj->getCompareEstimateData($rows['COMID'],"CP_DATE");
			if($cpdate!="0000-00-00" && $cpdate!=""){$cpdate = date('d-m-Y',strtotime($cpdate));}else{$cpdate = "";}
			$fixturedate = date('d-m-Y',strtotime($obj->getCompareEstimateData($rows['COMID'],"TRANS_DATE")));
			echo '<tr>';
			echo '<td align="center" valign="middle">'.$j.'</td>';
			echo '<td align="left" valign="middle">'.$rows['MESSAGE'].'</td>';
			if($selCOASpot == 2){
			echo '<td align="left" valign="middle">'.$obj->getCompareEstimateData($rows['COMID'],"VOYAGE_NO").'/'.$obj->getCoaData($rows['COAAID'],"COA_ID").'</td>';
			}else{
			echo '<td align="left" valign="middle">'.$obj->getCompareEstimateData($rows['COMID'],"VOYAGE_NO").'/'.$obj->getCompareEstimateData($rows['COMID'],"VOYAGE_NAME").'</td>';
			}
			echo '<td align="left" valign="middle">'.$obj->getVesselIMOData($rows['VESSEL_IMO_ID'],"VESSEL_NAME").'</td>';
			echo '<td align="left" valign="middle">'.$rows['CHARTERINGUSER'].'</td>';
			echo '<td align="left" valign="middle">'.$rows['OPSUSER'].'</td>';
			echo '<td align="left" valign="middle">'.$obj->getCompareEstimateData($rows['COMID'],"DWT_SUMMER").'</td>';
			echo '<td align="left" valign="middle">'.$obj->getMaterialCodeDesBasedOnId($obj->getOpenCargoPositionData($obj->getCompareEstimateData($rows['COMID'],"OPEN_CARGOID"),"CARGO")).'</td>';
			echo '<td align="left" valign="middle">'.$cpdate.'</td>';
			echo '<td align="left" valign="middle">'.$obj->getVendorListNewBasedOnID($obj->getOpenCargoPositionData($obj->getCompareEstimateData($rows['COMID'],"OPEN_CARGOID"),"OWNER")).'</td>';
			echo '<td align="left" valign="middle">'.$obj->getVendorListNewBasedOnID($obj->getOpenCargoPositionData($obj->getCompareEstimateData($rows['COMID'],"OPEN_CARGOID"),"CHARTERER")).'</td>';
			echo '<td align="left" valign="middle">'.$fixturedate.'</td>';
			echo '<td align="left" valign="middle">'.$obj->getCompareEstimateData($rows['COMID'],"REVENUES_FREIGHT").'</td>';
			$res14 = mysql_query("select PROFIT_LOSS from freight_cost_estimete_master where COMID='".$rows['COMID']."' and SHEET_NO!='' order by SHEET_NO asc");
			$i =0;
			$first = $last = '';
			while($row14 = mysql_fetch_assoc($res14))
			{
				if($i==0)
				{
					$first = $row14['PROFIT_LOSS'];
				}
				else
				{
					$last = $row14['PROFIT_LOSS'];
				}
				$i = $i + 1;
			}
			echo '<td align="left" valign="middle">'.$first.'</td>';
			echo '<td align="left" valign="middle">'.$last.'</td>';
			echo '<td align="left" valign="middle"></td>';
			echo '</tr>';
			$j++;
		}
	}
	echo '</tbody>';
	echo '</table>';		
}


function getCompareSheetData()
{
	$obj 			= new data();
	$connect		= $obj->funConnect();
	$comid          =  $_REQUEST['comid'];

	echo '<div class="row">
			<div class="col-xs-6">
				<h2 class="page-header">
				 Main Particulars
				</h2>                            
			</div><!-- /.col -->
			<div class="col-xs-6">
				<h2 class="page-header">
				 <a href="allExcel.php?id=23&comid='.$comid.'" title="Pdf"><button class="btn btn-default" type="button" style="margin-left: 115px; margin-top:-19px;"><i class="fa fa-download"></i> Generate Excel</button></a>
				</h2>                            
			</div><!-- /.col -->
		</div>
			
		<div class="row invoice-info">
			<div class="col-sm-4 invoice-col">
				 Vessel Name
				<address>
				'.$obj->getVesselIMOData($obj->getCompareEstimateData($comid,"VESSEL_IMO_ID"),"VESSEL_NAME").'
			</div><!-- /.col -->
			 <div class="col-sm-4 invoice-col">
				 Vessel Type
				<address>
					'.$obj->getVesselTypeBasedOnID($obj->getVesselIMOData($obj->getCompareEstimateData($comid,"VESSEL_IMO_ID"),"VESSEL_TYPE")).'
				</address>
			</div><!-- /.col -->
			<div class="col-sm-4 invoice-col">
				 Flag
				<address>
					'.$obj->getCompareEstimateData($comid,"FLAG").'
				</address>
			</div><!-- /.col -->
		</div>
			
		<div class="row invoice-info">
			<div class="col-sm-4 invoice-col">
			   Fixture Date
				<address>
				'.date('d-m-Y',strtotime($obj->getCompareEstimateData($comid,"TRANS_DATE"))).'
				</address>
			</div><!-- /.col -->
			
			<div class="col-sm-4 invoice-col">
				Voyage No. / Coa / Spot
				<address>
					'.$obj->getCompareEstimateData($comid,"VOYAGE_NO").'
				</address>
			</div><!-- /.col -->
			
			<div class="col-sm-4 invoice-col">
				 Voyage Financials Name
				<address>
					'.$obj->getCompareEstimateData($comid,"VOYAGE_NAME").'
				</address>
			</div><!-- /.col -->
		</div>
		 
		<div class="row invoice-info">
			<div class="col-sm-4 invoice-col">
				DWT<span style="font-size:10px; font-style:italic;">(Summer)</span>
				<address>
				'.$obj->getCompareEstimateData($comid,"DWT_SUMMER").'
				</address>
			</div><!-- /.col -->
			
			<div class="col-sm-4 invoice-col">
				DWT<span style="font-size:10px; font-style:italic;">(Tropical)</span>
				<address>
				'.$obj->getCompareEstimateData($comid,"DWT_TOPICAL").'
				</address>
			</div><!-- /.col -->
		</div>';
	
	
	echo '<div class="box-body table-responsive">';
	echo '<table class="table table-bordered table-striped">';
	echo '<thead>';
	echo '<tr>';
	$sql = "SELECT * FROM freight_cost_estimete_master where COMID='".$comid."'";
	$result = mysql_query($sql);
	$num = mysql_num_rows($result);
	$width = 90/$num;
	echo '<th align="center" valign="middle" width="10%">Sheet Name/Parameters</th>';
	$result = mysql_query($sql);
	while($rows= mysql_fetch_assoc($result))
	{
		$sql1 = "select SHEET_NAME from cost_sheet_name_master where COST_SHEETID='".$rows['SHEET_NO']."'";
		$res1 = mysql_query($sql1);
		$rows1 = mysql_fetch_assoc($res1);
		if($rows1['SHEET_NAME']!='')
		{
		    echo '<th align="center" valign="middle" width="'.$width.'%">'.$rows1['SHEET_NAME'].'</th>';
		}
		else
		{
			echo '<th align="center" valign="middle" width="'.$width.'%">FVF</th>';
		}
	}
	echo '</tr>';
	
	
	echo '<tr>';
	echo '<td align="left" colspan="'.(1+$num).'"><span style="font-size:16px;"><strong>Cargo Type</strong></span></td>';
	echo '</tr>';
	
	echo '<tr>';
	echo '<td align="center" valign="middle" width="10%"></td>';
	
	$result = mysql_query($sql);
	while($rows= mysql_fetch_assoc($result))
	{
		echo '<td align="center" valign="middle" width="'.$width.'%">'.$obj->getEstimateList($rows['ESTIMATE_TYPE']).'</td>';
	}
	echo '</tr>';
	
	
	
	$array_revenue = array();
	echo '<tr>';
	echo '<td align="left" colspan="'.(1+$num).'"><span style="font-size:16px;"><strong>Revenue</strong></span></td>';
	echo '</tr>';
	
	echo '<tr>';
	echo '<td align="center" valign="middle" width="10%">Demurrage</td>';
	$result = mysql_query($sql);
	while($rows= mysql_fetch_assoc($result))
	{
		$arr_sum = array();
		$sql1 = "select DDCLP_NETCOST from freight_cost_estimete_slave1 where FCAID='".$rows['FCAID']."'";
		$res1 = mysql_query($sql1);
		while($rows1 = mysql_fetch_assoc($res1))
		{
			if($rows1['DDCLP_NETCOST']>0)
			{
				$arr_sum[] = $rows1['DDCLP_NETCOST'];
			}
		}
		
		$sql2 = "select DDCDP_NETCOST from freight_cost_estimete_slave1 where FCAID='".$rows['FCAID']."'";
		$res2 = mysql_query($sql2);
		while($rows2 = mysql_fetch_assoc($res2))
		{
			if($rows2['DDCDP_NETCOST']>0)
			{
				$arr_sum[] = $rows2['DDCDP_NETCOST'];
			}
		}
		$array_revenue[$rows['FCAID']][] = array_sum($arr_sum);
		echo '<td align="center" valign="middle" width="'.$width.'%">'.array_sum($arr_sum).'</td>';
	}
	echo '</tr>';
	
	echo '<tr>';
	echo '<td align="center" valign="middle" width="10%">Dispatch</td>';
	$result = mysql_query($sql);
	while($rows= mysql_fetch_assoc($result))
	{
		$arr_sum = array();
		$sql1 = "select DDCLP_NETCOST from freight_cost_estimete_slave1 where FCAID='".$rows['FCAID']."'";
		$res1 = mysql_query($sql1);
		while($rows1 = mysql_fetch_assoc($res1))
		{
			if($rows1['DDCLP_NETCOST']<0)
			{
				$arr_sum[] = $rows1['DDCLP_NETCOST'];
			}
		}
		
		$sql2 = "select DDCDP_NETCOST from freight_cost_estimete_slave1 where FCAID='".$rows['FCAID']."'";
		$res2 = mysql_query($sql2);
		while($rows2 = mysql_fetch_assoc($res2))
		{
			if($rows2['DDCDP_NETCOST']< 0)
			{
				$arr_sum[] = $rows2['DDCDP_NETCOST'];
			}
		}
		$array_revenue[$rows['FCAID']][] = array_sum($arr_sum);
		echo '<td align="center" valign="middle" width="'.$width.'%">'.array_sum($arr_sum).'</td>';
	}
	echo '</tr>';
	
	echo '<tr>';
	echo '<td align="center" valign="middle" width="10%">Final Nett Freight</td>';
	$result = mysql_query($sql);
	while($rows= mysql_fetch_assoc($result))
	{
		$array_revenue[$rows['FCAID']][] = $rows['REVENUES_FREIGHT'];
		echo '<td align="center" valign="middle" width="'.$width.'%">'.$rows['REVENUES_FREIGHT'].'</td>';
	}
	echo '</tr>';
	
	echo '<tr>';
	echo '<td align="center" valign="middle" width="10%"><strong>Total Revenue</strong></td>';
	$result = mysql_query($sql);
	while($rows= mysql_fetch_assoc($result))
	{
		echo '<td align="center" valign="middle" width="'.$width.'%"><strong>'.array_sum($array_revenue[$rows['FCAID']]).'</strong></td>';
	}
	echo '</tr>';
	
	
	$array_expense = array();
	echo '<tr>';
	echo '<td align="left" colspan="'.(1+$num).'"><span style="font-size:16px;"><strong>Expenses- Cargo </strong></span></td>';
	echo '</tr>';
	
	echo '<tr>';
	echo '<td align="center" valign="middle" width="10%">Loading Port</td>';
	$result = mysql_query($sql);
	while($rows= mysql_fetch_assoc($result))
	{
		$arr_sum = array();
		$sql1 = "select sum(LOAD_PORT_COST) as sum from freight_cost_estimete_slave1 where FCAID='".$rows['FCAID']."'";
		$res1 = mysql_query($sql1);
		$rows1 = mysql_fetch_assoc($res1);
		$array_expense[$rows['FCAID']][] = $rows1['sum'];
		echo '<td align="center" valign="middle" width="'.$width.'%">'.$rows1['sum'].'</td>';
	}
	echo '</tr>';
	
	echo '<tr>';
	echo '<td align="center" valign="middle" width="10%">Discharge Port</td>';
	$result = mysql_query($sql);
	while($rows= mysql_fetch_assoc($result))
	{
		$arr_sum = array();
		$sql1 = "select sum(DISC_PORT_COST) as sum from freight_cost_estimete_slave1 where FCAID='".$rows['FCAID']."'";
		$res1 = mysql_query($sql1);
		$rows1 = mysql_fetch_assoc($res1);
		$array_expense[$rows['FCAID']][] = $rows1['sum'];
		echo '<td align="center" valign="middle" width="'.$width.'%">'.$rows1['sum'].'</td>';
	}
	echo '</tr>';
	
	echo '<tr>';
	echo '<td align="center" valign="middle" width="10%">Bunker Port</td>';
	$result = mysql_query($sql);
	while($rows= mysql_fetch_assoc($result))
	{
		$arr_sum = array();
		$sql1 = "select sum(TRANSIT_PORT_COST) as sum from freight_cost_estimete_slave1 where FCAID='".$rows['FCAID']."'";
		$res1 = mysql_query($sql1);
		$rows1 = mysql_fetch_assoc($res1);
		$array_expense[$rows['FCAID']][] = $rows1['sum'];
		echo '<td align="center" valign="middle" width="'.$width.'%">'.$rows1['sum'].'</td>';
	}
	echo '</tr>';
	
	
	$sqlop = "SELECT owner_related_cost_master.OWNER_RCOSTID, owner_related_cost_master.NAME FROM owner_related_cost_master inner join freight_cost_estimete_slave3 on freight_cost_estimete_slave3.IDENTY_ID=owner_related_cost_master.OWNER_RCOSTID inner join freight_cost_estimete_master on freight_cost_estimete_master.FCAID =freight_cost_estimete_slave3.FCAID  where owner_related_cost_master.STATUS=1 and freight_cost_estimete_master.COMID='".$comid."' and freight_cost_estimete_slave3.RAW_AMOUNT > 0 group by freight_cost_estimete_slave3.IDENTY_ID";
    $resop = mysql_query($sqlop);
    $numop = mysql_num_rows($resop);
    while($rowsop = mysql_fetch_assoc($resop))
    {
		echo '<tr>';
		echo '<td align="center" valign="middle" width="10%">'.$rowsop['NAME'].'</td>';
		$result = mysql_query($sql);
		while($rows= mysql_fetch_assoc($result))
		{
			$sql1 = "select sum(RAW_AMOUNT) as sum from freight_cost_estimete_slave3 where FCAID='".$rows['FCAID']."' and IDENTIFY='ORC' and IDENTY_ID='".$rowsop['OWNER_RCOSTID']."'";
			$res1 = mysql_query($sql1);
			$rows1 = mysql_fetch_assoc($res1);
			$array_expense[$rows['FCAID']][] = $rows1['sum'];
			echo '<td align="center" valign="middle" width="'.$width.'%">'.$rows1['sum'].'</td>';
		}
		echo '</tr>';
	}

	echo '<tr>';
	echo '<td align="center" valign="middle" width="10%">CVE</td>';
	$result = mysql_query($sql);
	while($rows= mysql_fetch_assoc($result))
	{
		$array_expense[$rows['FCAID']][] = $rows['CVE_AMT'];
		echo '<td align="center" valign="middle" width="'.$width.'%">'.$rows['CVE_AMT'].'</td>';
	}
	echo '</tr>';
	
	echo '<tr>';
	echo '<td align="center" valign="middle" width="10%">ILOHC</td>';
	$result = mysql_query($sql);
	while($rows= mysql_fetch_assoc($result))
	{
		$array_expense[$rows['FCAID']][] = $rows['ILOHC_AMT'];
		echo '<td align="center" valign="middle" width="'.$width.'%">'.$rows['ILOHC_AMT'].'</td>';
	}
	echo '</tr>';
	
	echo '<tr>';
	echo '<td align="center" valign="middle" width="10%">Address Commission</td>';
	$result = mysql_query($sql);
	while($rows= mysql_fetch_assoc($result))
	{
		$array_expense[$rows['FCAID']][] = $rows['ILOHC_AMT'];
		echo '<td align="center" valign="middle" width="'.$width.'%">'.$rows['ADDRESS_COMMISSION_AMT'].'</td>';
	}
	echo '</tr>';
	
	echo '<tr>';
	echo '<td align="center" valign="middle" width="10%">Brokerage Commission</td>';
	$result = mysql_query($sql);
	while($rows= mysql_fetch_assoc($result))
	{
		$sql1 = "select sum(BROKAGE_AMT) as sum from freight_cost_estimete_slave4 where FCAID='".$rows['FCAID']."' ";
		$res1 = mysql_query($sql1);
		$rows1 = mysql_fetch_assoc($res1);
		$array_expense[$rows['FCAID']][] = $rows1['sum'];
		echo '<td align="center" valign="middle" width="'.$width.'%">'.$rows1['sum'].'</td>';
	}
	echo '</tr>';
	
	echo '<tr>';
	echo '<td align="center" valign="middle" width="10%"><strong>Total Expense-Cargo</strong></td>';
	$result = mysql_query($sql);
	while($rows= mysql_fetch_assoc($result))
	{
		echo '<td align="center" valign="middle" width="'.$width.'%"><strong>'.array_sum($array_expense[$rows['FCAID']]).'</strong></td>';
	}
	echo '</tr>';
	
	
	echo '<tr>';
	echo '<td align="left" valign="middle" colspan="'.(1+$num).'"><span style="font-size:16px;"><strong>Totals</strong></span> (Distance/Days/Consp.)</td>';
	echo '</tr>';
	
	
	echo '<tr>';
	echo '<td align="center" valign="middle" width="10%">Laden Dist</td>';
	$result = mysql_query($sql);
	while($rows= mysql_fetch_assoc($result))
	{
		echo '<td align="center" valign="middle" width="'.$width.'%">'.$rows['LADEN_DIST'].'</td>';
	}
	echo '</tr>';
	
	echo '<tr>';
	echo '<td align="center" valign="middle" width="10%">Ballast Dist</td>';
	$result = mysql_query($sql);
	while($rows= mysql_fetch_assoc($result))
	{
		echo '<td align="center" valign="middle" width="'.$width.'%">'.$rows['BALLAST_DIST'].'</td>';
	}
	echo '</tr>';
	
	echo '<tr>';
	echo '<td align="center" valign="middle" width="10%">Total Dist</td>';
	$result = mysql_query($sql);
	while($rows= mysql_fetch_assoc($result))
	{
		echo '<td align="center" valign="middle" width="'.$width.'%">'.$rows['TOTAL_DISTANCE'].'</td>';
	}
	echo '</tr>';
	
	echo '<tr>';
	echo '<td align="center" valign="middle" width="10%">Laden Days</td>';
	$result = mysql_query($sql);
	while($rows= mysql_fetch_assoc($result))
	{
		echo '<td align="center" valign="middle" width="'.$width.'%">'.$rows['LADEN_DAYS'].'</td>';
	}
	echo '</tr>';
	
	
	echo '<tr>';
	echo '<td align="center" valign="middle" width="10%">Ballast Days</td>';
	$result = mysql_query($sql);
	while($rows= mysql_fetch_assoc($result))
	{
		echo '<td align="center" valign="middle" width="'.$width.'%">'.$rows['BALLAST_DAYS'].'</td>';
	}
	echo '</tr>';
	
	echo '<tr>';
	echo '<td align="center" valign="middle" width="10%">Total Sea Days</td>';
	$result = mysql_query($sql);
	while($rows= mysql_fetch_assoc($result))
	{
		echo '<td align="center" valign="middle" width="'.$width.'%">'.$rows['TOTAL_PASSAGE_DAYS'].'</td>';
	}
	echo '</tr>';
	
	echo '<tr>';
	echo '<td align="center" valign="middle" width="10%">Ttl Port Idle Days</td>';
	$result = mysql_query($sql);
	while($rows= mysql_fetch_assoc($result))
	{
		echo '<td align="center" valign="middle" width="'.$width.'%">'.$rows['IDEAL_DAYS'].'</td>';
	}
	echo '</tr>';
	
	echo '<tr>';
	echo '<td align="center" valign="middle" width="10%">Ttl Port Work Days</td>';
	$result = mysql_query($sql);
	while($rows= mysql_fetch_assoc($result))
	{
		echo '<td align="center" valign="middle" width="'.$width.'%">'.$rows['WORKING_DAYS'].'</td>';
	}
	echo '</tr>';
	
	echo '<tr>';
	echo '<td align="center" valign="middle" width="10%">Total Days</td>';
	$result = mysql_query($sql);
	while($rows= mysql_fetch_assoc($result))
	{
		echo '<td align="center" valign="middle" width="'.$width.'%">'.$rows['TOTAL_DAYS'].'</td>';
	}
	echo '</tr>';
	
	echo '<tr>';
	echo '<td align="center" valign="middle" width="10%">Ttl FO Consp MT</td>';
	$result = mysql_query($sql);
	while($rows= mysql_fetch_assoc($result))
	{
		echo '<td align="center" valign="middle" width="'.$width.'%">'.$rows['FO_CONSP'].'</td>';
	}
	echo '</tr>';
	
	echo '<tr>';
	echo '<td align="center" valign="middle" width="10%">Ttl DO Consp MT</td>';
	$result = mysql_query($sql);
	while($rows= mysql_fetch_assoc($result))
	{
		echo '<td align="center" valign="middle" width="'.$width.'%">'.$rows['DO_CONSP'].'</td>';
	}
	echo '</tr>';
	
	
	
	$bunker_expense = array();
	echo '<tr>';
	echo '<td align="left" valign="middle" colspan="'.(1+$num).'"><span style="font-size:16px;"><strong>Bunker Expenses</strong></span> (Qty / Price / Amount)</td>';
	echo '</tr>';
	
	$sql2 = "SELECT bunker_grade_master.BUNKERGRADEID, bunker_grade_master.NAME FROM bunker_grade_master inner join freight_cost_estimete_slave2 on freight_cost_estimete_slave2.BUNKERGRADEID=bunker_grade_master.BUNKERGRADEID inner join freight_cost_estimete_master on freight_cost_estimete_master.FCAID =freight_cost_estimete_slave2.FCAID  where bunker_grade_master.MODULEID='".$_SESSION['moduleid']."' AND bunker_grade_master.MCOMPANYID='".$_SESSION['company']."' and bunker_grade_master.STATUS=1 and freight_cost_estimete_master.COMID='".$comid."' and (freight_cost_estimete_slave2.EST_COST > 0 or freight_cost_estimete_slave2.ACTUAL_COST>0) group by freight_cost_estimete_slave2.BUNKERGRADEID";
	$res2 = mysql_query($sql2);
	$rec2 = mysql_num_rows($res2);
	$m=0; 
	while($rows2 = mysql_fetch_assoc($res2))
	{
		echo '</tr>';
		echo '<tr>';
		echo '<td align="center" valign="middle" width="10%" style="overflow:auto;">'.$rows2['NAME'].'</td>';
		$result = mysql_query($sql);
		while($rows= mysql_fetch_assoc($result))
		{   $sql1 = "select * from freight_cost_estimete_slave2 where FCAID='".$rows['FCAID']."' and BUNKERGRADEID='".$rows2['BUNKERGRADEID']."'";
			$res1 = mysql_query($sql1);
			$rows1 = mysql_fetch_assoc($res1);
			$qty = $price = $amount = 0;
			if($rows1['ACTUAL_COST']>0)
			{
				$qty    = $rows1['ACTUAL_MT'];
				$price  = $rows1['ACTUAL_PRICE'];
				$amount = $rows1['ACTUAL_COST'];
			}
			else
			{
				$qty    = $rows1['EST_MT'];
				$price  = $rows1['EST_PRICE'];
				$amount = $rows1['EST_COST'];
			}
			$bunker_expense[$rows['FCAID']][] =  $amount;
			echo '<td align="center" valign="middle" width="'.$width.'%">'.$qty.' / '.$price.' / '.$amount.'</td>';
		}
		echo '</tr>';
	}
	
	echo '<tr>';
	echo '<td align="center" valign="middle" width="10%"><strong>Total Bunker Expense</strong></td>';
	$result = mysql_query($sql);
	while($rows= mysql_fetch_assoc($result))
	{
		echo '<td align="center" valign="middle" width="'.$width.'%"><strong>'.array_sum($bunker_expense[$rows['FCAID']]).'</strong></td>';
	}
	echo '</tr>';
	
	

	echo '<tr>';
	echo '<td align="center" valign="middle" width="10%"><span style="font-size:16px;"><strong>Navigation Expenses</strong></span></td>';
	$result = mysql_query($sql);
	while($rows= mysql_fetch_assoc($result))
	{
		echo '<td align="center" valign="middle" width="'.$width.'%"><strong>'.(array_sum($array_expense[$rows['FCAID']]) + array_sum($bunker_expense[$rows['FCAID']])).'</strong></td>';
	}
	echo '</tr>';
	
	
	echo '<tr>';
	echo '<td align="left" valign="middle" colspan="'.(1+$num).'"><span style="font-size:16px;"><strong>Expense - Ship</strong></span></td>';
	echo '</tr>';
	
	echo '<tr>';
	echo '<td align="center" valign="middle" width="10%">Hire</td>';
	$result = mysql_query($sql);
	while($rows= mysql_fetch_assoc($result))
	{
		echo '<td align="center" valign="middle" width="'.$width.'%"><strong>'.$rows['DAILY_VESSEL_OPERATION_EXP'].'</strong></td>';
	}
	echo '</tr>';
	
	echo '<tr>';
	echo '<td align="center" valign="middle" width="10%">Hireage</td>';
	$result = mysql_query($sql);
	while($rows= mysql_fetch_assoc($result))
	{
		$hirage = $rows['DAILY_VESSEL_OPERATION_EXP']*$rows['TOTAL_DAYS'];
		$sqlinvoice = "select INVOICE_TYPE, INVOICE_NO, BALANCE_TO_OWNER from invoice_hire_master WHERE MODULEID='".$_SESSION['moduleid']."' AND MCOMPANYID='".$_SESSION['company']."' and COMID='".$comid."' and STATUS=2 order by INVOICEID";
		$resinvoice = mysql_query($sqlinvoice);
		$numinvoice = mysql_num_rows($resinvoice);
		$hierage_sign = 0;
		while($rowsinvoice = mysql_fetch_assoc($resinvoice))
		{
		   $hirage = $hirage - $rowsinvoice['BALANCE_TO_OWNER'];
		   if($rowsinvoice['INVOICE_TYPE']=="Final"){$hierage_sign = 1;}
		}
		if($hierage_sign == 1 ){$hirage = $rows['DAILY_VESSEL_OPERATION_EXP']*$rows['TOTAL_DAYS'];}
		echo '<td align="center" valign="middle" width="'.$width.'%"><strong>'.$hirage.'</strong></td>';
	}
	echo '</tr>';
	
	echo '<tr>';
	echo '<td align="center" valign="middle" width="10%">Ballast Bonus</td>';
	$result = mysql_query($sql);
	while($rows= mysql_fetch_assoc($result))
	{
		echo '<td align="center" valign="middle" width="'.$width.'%"><strong>'.$rows['BALLAST_BONUS'].'</strong></td>';
	}
	echo '</tr>';
	
	echo '<tr>';
	echo '<td align="center" valign="middle" width="10%">Add Comm (%/Amt)</td>';
	$result = mysql_query($sql);
	while($rows= mysql_fetch_assoc($result))
	{
		$hirage = $rows['DAILY_VESSEL_OPERATION_EXP']*$rows['TOTAL_DAYS'];
		$sqlinvoice = "select INVOICE_TYPE, INVOICE_NO, BALANCE_TO_OWNER from invoice_hire_master WHERE MODULEID='".$_SESSION['moduleid']."' AND MCOMPANYID='".$_SESSION['company']."' and COMID='".$comid."' and STATUS=2 order by INVOICEID";
		$resinvoice = mysql_query($sqlinvoice);
		$numinvoice = mysql_num_rows($resinvoice);
		$hierage_sign = 0;
		while($rowsinvoice = mysql_fetch_assoc($resinvoice))
		{
		   $hirage = $hirage - $rowsinvoice['BALANCE_TO_OWNER'];
		   if($rowsinvoice['INVOICE_TYPE']=="Final"){$hierage_sign = 1;}
		}
		if($hierage_sign == 1 ){$hirage = $rows['DAILY_VESSEL_OPERATION_EXP']*$rows['TOTAL_DAYS'];}
		echo '<td align="center" valign="middle" width="'.$width.'%"><strong>'.$rows['HIREAGE_PERCENT'].' / '.(($hirage*$rows['HIREAGE_PERCENT'])/100).'</strong></td>';
	}
	echo '</tr>';
	
	echo '<tr>';
	echo '<td align="center" valign="middle" width="10%"><strong>Nett Hireage<strong></td>';
	$result = mysql_query($sql);
	while($rows= mysql_fetch_assoc($result))
	{
		$hirage = $rows['DAILY_VESSEL_OPERATION_EXP']*$rows['TOTAL_DAYS'];
		$sqlinvoice = "select INVOICE_TYPE, INVOICE_NO, BALANCE_TO_OWNER from invoice_hire_master WHERE MODULEID='".$_SESSION['moduleid']."' AND MCOMPANYID='".$_SESSION['company']."' and COMID='".$comid."' and STATUS=2 order by INVOICEID";
		$resinvoice = mysql_query($sqlinvoice);
		$numinvoice = mysql_num_rows($resinvoice);
		$hierage_sign = 0;
		while($rowsinvoice = mysql_fetch_assoc($resinvoice))
		{
		   $hirage = $hirage - $rowsinvoice['BALANCE_TO_OWNER'];
		   if($rowsinvoice['INVOICE_TYPE']=="Final"){$hierage_sign = 1;}
		}
		if($hierage_sign == 1 ){$hirage = $rows['DAILY_VESSEL_OPERATION_EXP']*$rows['TOTAL_DAYS'];}
		echo '<td align="center" valign="middle" width="'.$width.'%"><strong>'.($hirage - (($hirage*$rows['HIREAGE_PERCENT'])/100) + $rows['BALLAST_BONUS']).'</strong></td>';
	}
	echo '</tr>';
	
	echo '<tr>';
	echo '<td align="center" valign="middle" width="10%"><span style="font-size:16px;"><strong>Daily Earnings / TCE</strong></span></td>';
	$result = mysql_query($sql);
	while($rows= mysql_fetch_assoc($result))
	{
		echo '<td align="center" valign="middle" width="'.$width.'%">'.$rows['DAILY_EARNING'].'</td>';
	}
	echo '</tr>';
	
	echo '<tr>';
	echo '<td align="center" valign="middle" width="10%"><span style="font-size:16px;"><strong>Nett Daily Profit</strong></span></td>';
	$result = mysql_query($sql);
	while($rows= mysql_fetch_assoc($result))
	{
		echo '<td align="center" valign="middle" width="'.$width.'%">'.$rows['NET_DAILY_PROFIT'].'</td>';
	}
	echo '</tr>';
	
	
	echo '<tr>';
	echo '<td align="center" valign="middle" width="10%"><span style="font-size:16px;"><strong>P/L</strong></span></td>';
	$result = mysql_query($sql);
	while($rows= mysql_fetch_assoc($result))
	{
		echo '<td align="center" valign="middle" width="'.$width.'%">'.$rows['PROFIT_LOSS'].'</td>';
	}
	echo '</tr>';
	
	echo '</tbody>';
	echo '</table>';
	echo '</div>';
}


function getVesselDataToCompare()
{
	$obj 			= new data();
	$connect		= $obj->funConnect();
	$chkArr1   =  explode(',',$_REQUEST['chkArr']);
	echo '<div align="right"><a href="allPdf.php?id=56&chkValue='.$_REQUEST['chkArr'].'" title="Pdf"><button class="btn btn-default" type="button" style="margin-right: 5px;"><i class="fa fa-download"></i> Generate PDF</button></a></div><br/>';
	echo '<div class="box-body table-responsive">';
	echo '<table class="table table-bordered table-striped">';
	echo '<thead>';
	echo '<tr>';
	echo '<th align="center" valign="middle" width="10%">Vessel Name/Commercial Parameters</th>';
	$width = 90/count($chkArr1);
	for($i=0;$i<count($chkArr1);$i++)
	{
		echo '<th align="center" valign="middle" width="'.$width.'%">'.$obj->getVesselIMOData($chkArr1[$i],"VESSEL_NAME").'</th>';
	}
	echo '</tr>';
	echo '</thead>';
	echo '<tbody>';
	
	echo '<tr>';
	echo '<td align="center">Vessel Type</td>';
	for($i=0;$i<count($chkArr1);$i++)
	{
		echo '<td align="center">'.$obj->getVesselTypeBasedOnID($obj->getVesselIMOData($chkArr1[$i],"VESSEL_TYPE")).'</td>';
	}
	echo '</tr>';
	
	echo '<tr>';
	echo '<td align="center">DWT <span style="font-size:11px; font-style:italic;">(Summer)</span></td>';
	for($i=0;$i<count($chkArr1);$i++)
	{
		echo '<td align="center">'.$obj->getVesselIMOData($chkArr1[$i],"DWT").'</td>';
	}
	echo '</tr>';
	
	echo '<tr>';
	echo '<td align="center">Draft <span style="font-size:10px; font-style:italic;">(Summer)</td>';
	for($i=0;$i<count($chkArr1);$i++)
	{
		echo '<td align="center">'.$obj->getVesselIMOData($chkArr1[$i],"DRAFTM").'</td>';
	}
	echo '</tr>';
	
	echo '<tr>';
	echo '<td align="center">TPC</td>';
	for($i=0;$i<count($chkArr1);$i++)
	{
		echo '<td align="center">'.$obj->getVesselParticularData('SUMMER_3','vessel_master_1',$chkArr1[$i]).'</td>';
	}
	echo '</tr>';
	
	echo '<tr>';
	echo '<td align="center" colspan="'.(count($chkArr1) + 1).'">SPEED DATA</td>';
	echo '</tr>';
	
	echo '<tr>';
	echo '<td align="center">Ballast Speed - Full Speed <span style="font-size:10px; font-style:italic;">(Knots)</span></td>';
	for($i=0;$i<count($chkArr1);$i++)
	{
		echo '<td align="center">'.$obj->getVesselParameterData($chkArr1[$i],"B_FULL_SPEED",$user).'</td>';
	}
	echo '</tr>';
	
	echo '<tr>';
	echo '<td align="center">Ballast Speed - Service Speed <span style="font-size:10px; font-style:italic;">(Knots)</span></td>';
	for($i=0;$i<count($chkArr1);$i++)
	{
		echo '<td align="center">'.$obj->getVesselParameterData($chkArr1[$i],"B_ECO_SPEED1",$user).'</td>';
	}
	echo '</tr>';
	
	echo '<tr>';
	echo '<td align="center">Ballast Speed - Most Eco Speed <span style="font-size:10px; font-style:italic;">(Knots)</span></td>';
	for($i=0;$i<count($chkArr1);$i++)
	{
		echo '<td align="center">'.$obj->getVesselParameterData($chkArr1[$i],"B_ECO_SPEED2",$user).'</td>';
	}
	echo '</tr>';
	
	echo '<tr>';
	echo '<td align="center">Laden Speed - Full Speed <span style="font-size:10px; font-style:italic;">(Knots)</span></td>';
	for($i=0;$i<count($chkArr1);$i++)
	{
		echo '<td align="center">'.$obj->getVesselParameterData($chkArr1[$i],"L_FULL_SPEED",$user).'</td>';
	}
	echo '</tr>';
	
	echo '<tr>';
	echo '<td align="center">Laden Speed - Service Speed <span style="font-size:10px; font-style:italic;">(Knots)</span></td>';
	for($i=0;$i<count($chkArr1);$i++)
	{
		echo '<td align="center">'.$obj->getVesselParameterData($chkArr1[$i],"L_ECO_SPEED1",$user).'</td>';
	}
	echo '</tr>';
	
	echo '<tr>';
	echo '<td align="center">Laden Speed - Most Eco Speed <span style="font-size:10px; font-style:italic;">(Knots)</span></td>';
	for($i=0;$i<count($chkArr1);$i++)
	{
		echo '<td align="center">'.$obj->getVesselParameterData($chkArr1[$i],"L_ECO_SPEED2",$user).'</td>';
	}
	echo '</tr>';
	
	echo '<tr>';
	echo '<td align="center" colspan="'.(count($chkArr1) + 1).'">FO Consumption MT/Day</td>';
	echo '</tr>';
	
	echo '<tr>';
	echo '<td align="center">Ballast Passage - Full Speed</td>';
	for($i=0;$i<count($chkArr1);$i++)
	{
		echo '<td align="center">'.$obj->getVesselParameterData($chkArr1[$i],"BP_FO_FULL_SPEED",$user).'</td>';
	}
	echo '</tr>';
	
	echo '<tr>';
	echo '<td align="center">Ballast Passage - Service Speed</td>';
	for($i=0;$i<count($chkArr1);$i++)
	{
		echo '<td align="center">'.$obj->getVesselParameterData($chkArr1[$i],"BP_FO_ECO_SPEED1",$user).'</td>';
	}
	echo '</tr>';
	
	echo '<tr>';
	echo '<td align="center">Ballast Passage - Most Eco Speed</td>';
	for($i=0;$i<count($chkArr1);$i++)
	{
		echo '<td align="center">'.$obj->getVesselParameterData($chkArr1[$i],"BP_FO_ECO_SPEED2",$user).'</td>';
	}
	
	
	echo '<tr>';
	echo '<td align="center">Laden Passage - Full Speed</td>';
	for($i=0;$i<count($chkArr1);$i++)
	{
		echo '<td align="center">'.$obj->getVesselParameterData($chkArr1[$i],"LP_FO_FULL_SPEED",$user).'</td>';
	}
	echo '</tr>';
	
	echo '<tr>';
	echo '<td align="center">Laden Passage - Service Speed</td>';
	for($i=0;$i<count($chkArr1);$i++)
	{
		echo '<td align="center">'.$obj->getVesselParameterData($chkArr1[$i],"LP_FO_ECO_SPEED1",$user).'</td>';
	}
	echo '</tr>';
	
	echo '<tr>';
	echo '<td align="center">Laden Passage - Most Eco Speed</td>';
	for($i=0;$i<count($chkArr1);$i++)
	{
		echo '<td align="center">'.$obj->getVesselParameterData($chkArr1[$i],"LP_FO_ECO_SPEED2",$user).'</td>';
	}
	echo '</tr>';
	
	echo '<tr>';
	echo '<td align="center">In Port - Idle</td>';
	for($i=0;$i<count($chkArr1);$i++)
	{
		echo '<td align="center">'.$obj->getVesselParameterData($chkArr1[$i],"PI_FO_FULL_SPEED",$user).'</td>';
	}
	echo '</tr>';
	
	echo '<tr>';
	echo '<td align="center">In Port - Working</td>';
	for($i=0;$i<count($chkArr1);$i++)
	{
		echo '<td align="center">'.$obj->getVesselParameterData($chkArr1[$i],"PW_FO_FULL_SPEED",$user).'</td>';
	}
	echo '</tr>';
	
	echo '<tr>';
	echo '<td align="center">Others </td>';
	for($i=0;$i<count($chkArr1);$i++)
	{
		echo '<td align="center">'.$obj->getVesselParameterData($chkArr1[$i],"OTH_FO_FULL_SPEED",$user).'</td>';
	}
	echo '</tr>';
	
	echo '<tr>';
	echo '<td align="center" colspan="'.(count($chkArr1) + 1).'">DO Consumption per MT/Day</td>';
	echo '</tr>';
	
	echo '<tr>';
	echo '<td align="center">Ballast Passage - Full Speed</td>';
	for($i=0;$i<count($chkArr1);$i++)
	{
		echo '<td align="center">'.$obj->getVesselParameterData($chkArr1[$i],"BP_DO_FULL_SPEED",$user).'</td>';
	}
	echo '</tr>';
	
	echo '<tr>';
	echo '<td align="center">Ballast Passage - Service Speed</td>';
	for($i=0;$i<count($chkArr1);$i++)
	{
		echo '<td align="center">'.$obj->getVesselParameterData($chkArr1[$i],"BP_DO_ECO_SPEED1",$user).'</td>';
	}
	echo '</tr>';
	
	echo '<tr>';
	echo '<td align="center">Ballast Passage - Most Eco Speed</td>';
	for($i=0;$i<count($chkArr1);$i++)
	{
		echo '<td align="center">'.$obj->getVesselParameterData($chkArr1[$i],"BP_DO_ECO_SPEED2",$user).'</td>';
	}
	
	echo '<tr>';
	echo '<td align="center">Laden Passage - Full Speed</td>';
	for($i=0;$i<count($chkArr1);$i++)
	{
		echo '<td align="center">'.$obj->getVesselParameterData($chkArr1[$i],"LP_DO_FULL_SPEED",$user).'</td>';
	}
	echo '</tr>';
	
	echo '<tr>';
	echo '<td align="center">Laden Passage - Service Speed</td>';
	for($i=0;$i<count($chkArr1);$i++)
	{
		echo '<td align="center">'.$obj->getVesselParameterData($chkArr1[$i],"LP_DO_ECO_SPEED1",$user).'</td>';
	}
	echo '</tr>';
	
	echo '<tr>';
	echo '<td align="center">Laden Passage - Most Eco Speed</td>';
	for($i=0;$i<count($chkArr1);$i++)
	{
		echo '<td align="center">'.$obj->getVesselParameterData($chkArr1[$i],"LP_DO_ECO_SPEED2",$user).'</td>';
	}
	echo '</tr>';
	
	echo '<tr>';
	echo '<td align="center">In Port - Idle</td>';
	for($i=0;$i<count($chkArr1);$i++)
	{
		echo '<td align="center">'.$obj->getVesselParameterData($chkArr1[$i],"PI_DO_FULL_SPEED",$user).'</td>';
	}
	echo '</tr>';
	
	echo '<tr>';
	echo '<td align="center">In Port - Working</td>';
	for($i=0;$i<count($chkArr1);$i++)
	{
		echo '<td align="center">'.$obj->getVesselParameterData($chkArr1[$i],"PW_DO_FULL_SPEED",$user).'</td>';
	}
	echo '</tr>';
	
	echo '<tr>';
	echo '<td align="center">Others </td>';
	for($i=0;$i<count($chkArr1);$i++)
	{
		echo '<td align="center">'.$obj->getVesselParameterData($chkArr1[$i],"OTH_DO_FULL_SPEED",$user).'</td>';
	}
	echo '</tr>';
	
	echo '</body>';
	echo '</table></div>';
	
}

function getPaymentInvoicePaymentDetails()
{
	$obj 		= new data();
	$connect	= $obj->funConnect();
	$invoiceid 	= $_REQUEST['invoiceid'];
	
	$sql 		= "select * from request_master where REQ_ID='".$invoiceid."' ";
	$res 	 	=  mysql_query($sql) or die($sql);
	$rows 		= mysql_fetch_assoc($res);
	if($rows['P_DATE']!="")
	{
		$idate = date('d-m-Y',strtotime($rows['P_DATE']));
	}
	else
	{
		$idate = date('d-m-Y',time());
	}
	echo '<div class="row invoice-info">
			 <div class="col-sm-4 invoice-col">
				 Amount To Pay
				<address>
					<input type="text" name="txtP_Amt" id="txtP_Amt" class="form-control" readonly value="'.$rows['REQ_TO_PAY'].'" autocomplete="off"/>
					<input type="hidden" name="txtP_ID" id="txtP_ID" readonly value="'.$invoiceid.'" />	
				</address>
			 </div><!-- /.col -->
			 <div class="col-sm-4 invoice-col">
				Date
				<address>
					<input type="text" name="txtP_Date" id="txtP_Date" class="form-control" value="'.$idate.'" autocomplete="off"/>
				</address>
			 </div><!-- /.col -->
		</div>
		<div class="row invoice-info">
			 <div class="col-sm-12 invoice-col">
				Remarks
				<address>
					<textarea name="txtP_Remarks" id="txtP_Remarks" class="form-control" cols="15" rows="1" placeholder="Remarks..">'.$rows['P_REMARKS'].'</textarea>
				</address>
			 </div><!-- /.col -->
		</div>
		<div class="row invoice-info">
			<div class="col-sm-4 invoice-col">
			Amount Paid
			   <address>
				   <input type="text" name="txtP_PR" id="txtP_PR" class="form-control" autocomplete="off" placeholder="0.00" value="'.$rows['P_AMT'].'"  onkeyup="onkeyUp1();"/>
			   </address>
			</div><!-- /.col -->
			<div class="col-sm-8 invoice-col">
			 Attachments 
		        <address>
				   <div class="btn btn-success btn-file btn-flat" data-toggle="tooltip" data-original-title="Add Attachments">
						<i class="fa fa-paperclip"></i> Attachment
						<input type="file" class="form-control" multiple name="mul_file[]" id="mul_file" title="" data-widget="Add Attachment" data-toggle="tooltip" data-original-title="Add Attachment"/>
				   </div>';
				   if($rows['ATTACHMENTS'] != '')
					{ 
						$file = explode(",",$rows['ATTACHMENTS']); 
						$name = explode(",",$rows['ATTACHMENTS_NAME']);									
				   echo '<address>
							<table cellpadding="1" cellspacing="1" border="0" width="100%" align="left">';
							$j =1;
							for($i=0;$i<sizeof($file);$i++)
							{
							echo '<tr height="20" id="row_file1_'.$j.'">
								<td width="80%" align="left" class="input-text"  valign="top"><a href="../../attachment/'.$file[$i].'" target="_blank" style="color:blue;" data-toggle="tooltip" data-original-title="'.$name[$i].'"><i class="fa fa-external-link"></i>&nbsp;&nbsp;'.$name[$i].'</a>
								<input type="hidden" name="file1_'.$j.'" id="file1_'.$j.'" value="'.$file[$i].'" />
								<input type="hidden" name="name1_'.$j.'" id="name1_'.$j.'" value="'.$name[$i].'" />
								</td>
								<td width="20%" align="left" class="input-text"  valign="top"><a href="#1" onClick="Del_Upload1('.$j.');"><i class="fa fa-times " style="color:red;"></i></a></td>
							</tr>';
							$j++;}
						echo '</table>
						</address>';
					}
			echo '</address>
			</div><!-- /.col -->
		</div>';
}

function getDumerageInvoicePaymentDetails()
{
	$obj 		= new data();
	$connect	= $obj->funConnect();
	$invoiceid 	= $_REQUEST['invoiceid'];
	
	$sql 		= "select * from other_invoice_master where INVOICEID='".$invoiceid."' ";
	$res 	 	=  mysql_query($sql) or die($sql);
	$rows 		= mysql_fetch_assoc($res);
	if($rows['P_DATE']!="")
	{
		$idate = date('d-m-Y',strtotime($rows['P_DATE']));
	}
	else
	{
		$idate = date('d-m-Y',time());
	}
	echo '<div class="row invoice-info">
			 <div class="col-sm-4 invoice-col">
				 Amount
				<address>
					<input type="text" name="txtP_Amt" id="txtP_Amt" class="form-control" readonly value="'.$rows['NET_PAYABLE'].'" autocomplete="off"/>
					<input type="hidden" name="txtP_ID" id="txtP_ID" readonly value="'.$invoiceid.'" />	
				</address>
			 </div><!-- /.col -->
			 <div class="col-sm-4 invoice-col">
				Date
				<address>
					<input type="text" name="txtP_Date" id="txtP_Date" class="form-control" value="'.$idate.'" autocomplete="off"/>
				</address>
			 </div><!-- /.col -->
		</div>
		<div class="row invoice-info">
			 <div class="col-sm-12 invoice-col">
				Remarks
				<address>
					<textarea name="txtP_Remarks" id="txtP_Remarks" class="form-control" cols="15" rows="1" placeholder="Remarks..">'.$rows['P_REMARKS'].'</textarea>
				</address>
			 </div><!-- /.col -->
		</div>
		<div class="row invoice-info">
			<div class="col-sm-4 invoice-col">
			Payment Received
			   <address>
				   <input type="text" name="txtP_PR" id="txtP_PR" class="form-control" autocomplete="off" placeholder="0.00" value="'.$rows['P_AMT'].'"  onkeyup="onkeyUp1();"/>
			   </address>
			</div><!-- /.col -->
			<div class="col-sm-8 invoice-col">
			 Attachments 
		        <address>
				   <div class="btn btn-success btn-file btn-flat" data-toggle="tooltip" data-original-title="Add Attachments">
						<i class="fa fa-paperclip"></i> Attachment
						<input type="file" class="form-control" multiple name="mul_file[]" id="mul_file" title="" data-widget="Add Attachment" data-toggle="tooltip" data-original-title="Add Attachment"/>
				   </div>';
				   if($rows['ATTACHMENTS'] != '')
					{ 
						$file = explode(",",$rows['ATTACHMENTS']); 
						$name = explode(",",$rows['ATTACHMENTS_NAME']);									
				   echo '<address>
							<table cellpadding="1" cellspacing="1" border="0" width="100%" align="left">';
							$j =1;
							for($i=0;$i<sizeof($file);$i++)
							{
							echo '<tr height="20" id="row_file1_'.$j.'">
								<td width="80%" align="left" class="input-text"  valign="top"><a href="../../attachment/'.$file[$i].'" target="_blank" style="color:blue;" data-toggle="tooltip" data-original-title="'.$name[$i].'"><i class="fa fa-external-link"></i>&nbsp;&nbsp;'.$name[$i].'</a>
								<input type="hidden" name="file1_'.$j.'" id="file1_'.$j.'" value="'.$file[$i].'" />
								<input type="hidden" name="name1_'.$j.'" id="name1_'.$j.'" value="'.$name[$i].'" />
								</td>
								<td width="20%" align="left" class="input-text"  valign="top"><a href="#1" onClick="Del_Upload1('.$j.');"><i class="fa fa-times " style="color:red;"></i></a></td>
							</tr>';
							$j++;}
						echo '</table>
						</address>';
					}
			echo '</address>
			</div><!-- /.col -->
		</div>';
}


function getHireInvoicePaymentDetails()
{
	$obj 		= new data();
	$connect	= $obj->funConnect();
	$invoiceid 	= $_REQUEST['invoiceid'];
	
	$sql 		= "select * from invoice_hire_master where INVOICEID='".$invoiceid."' ";
	$res 	 	=  mysql_query($sql) or die($sql);
	$rows 		= mysql_fetch_assoc($res);
	if($rows['P_DATE']!="")
	{
		$idate = date('d-m-Y',strtotime($rows['P_DATE']));
	}
	else
	{
		$idate = date('d-m-Y',time());
	}
	echo '<div class="row invoice-info">
			 <div class="col-sm-4 invoice-col">
				 Amount To Pay
				<address>
					<input type="text" name="txtP_Amt" id="txtP_Amt" class="form-control" readonly value="'.$rows['FINAL_AMT'].'" autocomplete="off"/>
					<input type="hidden" name="txtP_ID" id="txtP_ID" readonly value="'.$invoiceid.'" />	
				</address>
			 </div><!-- /.col -->
			 <div class="col-sm-4 invoice-col">
				Date
				<address>
					<input type="text" name="txtP_Date" id="txtP_Date" class="form-control" value="'.$idate.'" autocomplete="off"/>
				</address>
			 </div><!-- /.col -->
		</div>
		<div class="row invoice-info">
			 <div class="col-sm-12 invoice-col">
				Remarks
				<address>
					<textarea name="txtP_Remarks" id="txtP_Remarks" class="form-control" cols="15" rows="1" placeholder="Remarks..">'.$rows['P_REMARKS'].'</textarea>
				</address>
			 </div><!-- /.col -->
		</div>
		<div class="row invoice-info">
			<div class="col-sm-4 invoice-col">
			Amount Paid
			   <address>
				   <input type="text" name="txtP_PR" id="txtP_PR" class="form-control" autocomplete="off" placeholder="0.00" value="'.$rows['P_AMT'].'"  onkeyup="onkeyUp1();"/>
			   </address>
			</div><!-- /.col -->
			<div class="col-sm-8 invoice-col">
			 Attachments 
		        <address>
				   <div class="btn btn-success btn-file btn-flat" data-toggle="tooltip" data-original-title="Add Attachments">
						<i class="fa fa-paperclip"></i> Attachment
						<input type="file" class="form-control" multiple name="mul_file[]" id="mul_file" title="" data-widget="Add Attachment" data-toggle="tooltip" data-original-title="Add Attachment"/>
				   </div>';
				   if($rows['ATTACHMENTS'] != '')
					{ 
						$file = explode(",",$rows['ATTACHMENTS']); 
						$name = explode(",",$rows['ATTACHMENTS_NAME']);									
				   echo '<address>
							<table cellpadding="1" cellspacing="1" border="0" width="100%" align="left">';
							$j =1;
							for($i=0;$i<sizeof($file);$i++)
							{
							echo '<tr height="20" id="row_file1_'.$j.'">
								<td width="80%" align="left" class="input-text"  valign="top"><a href="../../attachment/'.$file[$i].'" target="_blank" style="color:blue;" data-toggle="tooltip" data-original-title="'.$name[$i].'"><i class="fa fa-external-link"></i>&nbsp;&nbsp;'.$name[$i].'</a>
								<input type="hidden" name="file1_'.$j.'" id="file1_'.$j.'" value="'.$file[$i].'" />
								<input type="hidden" name="name1_'.$j.'" id="name1_'.$j.'" value="'.$name[$i].'" />
								</td>
								<td width="20%" align="left" class="input-text"  valign="top"><a href="#1" onClick="Del_Upload1('.$j.');"><i class="fa fa-times " style="color:red;"></i></a></td>
							</tr>';
							$j++;}
						echo '</table>
						</address>';
					}
			echo '</address>
			</div><!-- /.col -->
		</div>';
}


function getHireInvoicePaymentDetailsTC()
{
	$obj 		= new data();
	$connect	= $obj->funConnect();
	$invoiceid 	= $_REQUEST['invoiceid'];
	
	$sql 		= "select * from invoice_hiretc_master where INVOICEID='".$invoiceid."' ";
	$res 	 	=  mysql_query($sql) or die($sql);
	$rows 		= mysql_fetch_assoc($res);
	if($rows['P_DATE']!="")
	{
		$idate = date('d-m-Y',strtotime($rows['P_DATE']));
	}
	else
	{
		$idate = date('d-m-Y',time());
	}
	echo '<div class="row invoice-info">
			 <div class="col-sm-4 invoice-col">
				 Amount To Pay
				<address>
					<input type="text" name="txtP_Amt" id="txtP_Amt" class="form-control" readonly value="'.$rows['FINAL_AMT'].'" autocomplete="off"/>
					<input type="hidden" name="txtP_ID" id="txtP_ID" readonly value="'.$invoiceid.'" />	
				</address>
			 </div><!-- /.col -->
			 <div class="col-sm-4 invoice-col">
				Date
				<address>
					<input type="text" name="txtP_Date" id="txtP_Date" class="form-control" value="'.$idate.'" autocomplete="off"/>
				</address>
			 </div><!-- /.col -->
		</div>
		<div class="row invoice-info">
			 <div class="col-sm-12 invoice-col">
				Remarks
				<address>
					<textarea name="txtP_Remarks" id="txtP_Remarks" class="form-control" cols="15" rows="1" placeholder="Remarks..">'.$rows['P_REMARKS'].'</textarea>
				</address>
			 </div><!-- /.col -->
		</div>
		<div class="row invoice-info">
			<div class="col-sm-4 invoice-col">
			Amount Paid
			   <address>
				   <input type="text" name="txtP_PR" id="txtP_PR" class="form-control" autocomplete="off" placeholder="0.00" value="'.$rows['P_AMT'].'"  onkeyup="onkeyUp1();"/>
			   </address>
			</div><!-- /.col -->
			<div class="col-sm-8 invoice-col">
			 Attachments 
		        <address>
				   <div class="btn btn-success btn-file btn-flat" data-toggle="tooltip" data-original-title="Add Attachments">
						<i class="fa fa-paperclip"></i> Attachment
						<input type="file" class="form-control" multiple name="mul_file[]" id="mul_file" title="" data-widget="Add Attachment" data-toggle="tooltip" data-original-title="Add Attachment"/>
				   </div>';
				   if($rows['ATTACHMENTS'] != '')
					{ 
						$file = explode(",",$rows['ATTACHMENTS']); 
						$name = explode(",",$rows['ATTACHMENTS_NAME']);									
				   echo '<address>
							<table cellpadding="1" cellspacing="1" border="0" width="100%" align="left">';
							$j =1;
							for($i=0;$i<sizeof($file);$i++)
							{
							echo '<tr height="20" id="row_file1_'.$j.'">
								<td width="80%" align="left" class="input-text"  valign="top"><a href="../../attachment/'.$file[$i].'" target="_blank" style="color:blue;" data-toggle="tooltip" data-original-title="'.$name[$i].'"><i class="fa fa-external-link"></i>&nbsp;&nbsp;'.$name[$i].'</a>
								<input type="hidden" name="file1_'.$j.'" id="file1_'.$j.'" value="'.$file[$i].'" />
								<input type="hidden" name="name1_'.$j.'" id="name1_'.$j.'" value="'.$name[$i].'" />
								</td>
								<td width="20%" align="left" class="input-text"  valign="top"><a href="#1" onClick="Del_Upload1('.$j.');"><i class="fa fa-times " style="color:red;"></i></a></td>
							</tr>';
							$j++;}
						echo '</table>
						</address>';
					}
			echo '</address>
			</div><!-- /.col -->
		</div>';
}



function getFreightInvoicePaymentDetails()
{
	$obj 		= new data();
	$connect	= $obj->funConnect();
	$invoiceid 	= $_REQUEST['invoiceid'];
	
	$sql 		= "select * from freight_invoice_master where INVOICEID='".$invoiceid."' ";
	$res 	 	=  mysql_query($sql) or die($sql);
	$rows 		= mysql_fetch_assoc($res);
	if($rows['P_DATE']!="")
	{
		$idate = date('d-m-Y',strtotime($rows['P_DATE']));
	}
	else
	{
		$idate = date('d-m-Y',time());
	}
	echo '<div class="row invoice-info">
			 <div class="col-sm-4 invoice-col">
				 Amount
				<address>
					<input type="text" name="txtP_Amt" id="txtP_Amt" class="form-control" readonly value="'.$rows['NET_PAYABLE'].'" autocomplete="off"/>
					<input type="hidden" name="txtP_ID" id="txtP_ID" readonly value="'.$invoiceid.'" />	
				</address>
			 </div><!-- /.col -->
			 <div class="col-sm-4 invoice-col">
				Date
				<address>
					<input type="text" name="txtP_Date" id="txtP_Date" class="form-control" value="'.$idate.'" autocomplete="off"/>
				</address>
			 </div><!-- /.col -->
		</div>
		<div class="row invoice-info">
			 <div class="col-sm-12 invoice-col">
				Remarks
				<address>
					<textarea name="txtP_Remarks" id="txtP_Remarks" class="form-control" cols="15" rows="1" placeholder="Remarks..">'.$rows['P_REMARKS'].'</textarea>
				</address>
			 </div><!-- /.col -->
		</div>
		<div class="row invoice-info">
			<div class="col-sm-4 invoice-col">
			Payment Received
			   <address>
				   <input type="text" name="txtP_PR" id="txtP_PR" class="form-control" autocomplete="off" placeholder="0.00" value="'.$rows['P_AMT'].'"  onkeyup="onkeyUp1();"/>
			   </address>
			</div><!-- /.col -->
			<div class="col-sm-8 invoice-col">
			 Attachments 
		        <address>
				   <div class="btn btn-success btn-file btn-flat" data-toggle="tooltip" data-original-title="Add Attachments">
						<i class="fa fa-paperclip"></i> Attachment
						<input type="file" class="form-control" multiple name="mul_file[]" id="mul_file" title="" data-widget="Add Attachment" data-toggle="tooltip" data-original-title="Add Attachment"/>
				   </div>';
				   if($rows['ATTACHMENTS'] != '')
					{ 
						$file = explode(",",$rows['ATTACHMENTS']); 
						$name = explode(",",$rows['ATTACHMENTS_NAME']);									
				   echo '<address>
							<table cellpadding="1" cellspacing="1" border="0" width="100%" align="left">';
							$j =1;
							for($i=0;$i<sizeof($file);$i++)
							{
							echo '<tr height="20" id="row_file1_'.$j.'">
								<td width="80%" align="left" class="input-text"  valign="top"><a href="../../attachment/'.$file[$i].'" target="_blank" style="color:blue;" data-toggle="tooltip" data-original-title="'.$name[$i].'"><i class="fa fa-external-link"></i>&nbsp;&nbsp;'.$name[$i].'</a>
								<input type="hidden" name="file1_'.$j.'" id="file1_'.$j.'" value="'.$file[$i].'" />
								<input type="hidden" name="name1_'.$j.'" id="name1_'.$j.'" value="'.$name[$i].'" />
								</td>
								<td width="20%" align="left" class="input-text"  valign="top"><a href="#1" onClick="Del_Upload1('.$j.');"><i class="fa fa-times " style="color:red;"></i></a></td>
							</tr>';
							$j++;}
						echo '</table>
						</address>';
					}
			echo '</address><br/><br/>
			</div><!-- /.col -->
		</div>';
}


function getBankingDetails()
{
	$obj = new data();
	$connect=$obj->funConnect();
	$selNOB = $_REQUEST['selNOB'];	
	$query   = mysql_query("select * from banking_details where BD_ID='".$selNOB."'");
	while($row = mysql_fetch_assoc($query))
	{
		$details = addslashes($row['ADDRESS'])." @@@@".addslashes($row['AC_NO'])." @@@@".addslashes($row['BANK'])." @@@@".addslashes($row['B_ADDRESS'])." @@@@".$row['BANK_SWIFT_CODE']." @@@@".$row['IBAN_NO']." @@@@".$row['FED_ABA']." @@@@".$row['C_BANK_NAME']." @@@@".$row['C_SWIFT_CODE']." @@@@".$row['CORRES_ADDRESS']." @@@@".$row['B_ACNO'];
	}
	echo $details;
}


function getVesselDetails()
{
    $obj 		= new data();
	$connect	= $obj->funConnect();
	$vessel1d = $_REQUEST['vessel1d'];	
	$query = "select * from vessel_commercial_parameters where VESSEL_IMO_ID='".$vessel1d."'";
	$res = mysql_query($query);
	$rec = mysql_num_rows($res);
	
	if($obj->getVesselIMOData($vessel1d,"DWT") == ""){$dwt_sum = "0.0";}else{$dwt_sum = $obj->getVesselIMOData($vessel1d,"DWT");}
	if($obj->getVesselParticularData('TROPICAL_1','vessel_master_1',$vessel1d) == ""){$dwt_trop = "0.0";}else{$dwt_trop = $obj->getVesselParticularData('TROPICAL_1','vessel_master_1',$vessel1d);}
	if($obj->getVesselIMOData($vessel1d,"GRAIN") == ""){$grain = "0.0";}else{$grain = $obj->getVesselIMOData($vessel1d,"GRAIN");}
	if($obj->getVesselIMOData($vessel1d,"BALE") == ""){$bale = "0.0";}else{$bale = $obj->getVesselIMOData($vessel1d,"BALE");}
	
	if(is_null($rows1["EXTERNAL_VESSEL_ID"]))
	{
		$vesselid = $vessel1d;
		$user = "";
	}
	else
	{
		$vesselid = $rows1['EXTERNAL_VESSEL_ID'];
		$user = "EXTERNAL_USER";
	}
	
	
	$btype = $obj->getVesselIMOData($vessel1d,"BUSINESSTYPEID");
	$btypename = $obj->getBusinessTypeBasedOnID1($obj->getVesselIMOData($vessel1d,"BUSINESSTYPEID"));
	$b_full_speed = $obj->getVesselParameterData($vesselid,"B_FULL_SPEED",$user);
	if($b_full_speed == "" ){$bfs = 0;}else{$bfs = $b_full_speed;}
	$b_ech_speed1 = $obj->getVesselParameterData($vesselid,"B_ECO_SPEED1",$user);
	if($b_ech_speed1 == "" ){$bes1 = 0;}else{$bes1 = $b_ech_speed1;}
	$b_ech_speed2 = $obj->getVesselParameterData($vesselid,"B_ECO_SPEED2",$user);
	if($b_ech_speed2 == "" ){$bes2 = 0;}else{$bes2 = $b_ech_speed2;}
	$fo_b_full_speed = $obj->getVesselParameterData($vesselid,"BP_FO_FULL_SPEED",$user);
	if($fo_b_full_speed == ""){$fo_bfs = 0;}else{$fo_bfs = $fo_b_full_speed;}
	$fo_b_ech_speed1 = $obj->getVesselParameterData($vesselid,"BP_FO_ECO_SPEED1",$user);
	if($fo_b_ech_speed1 == ""){$fo_bes1 = 0;}else{$fo_bes1 = $fo_b_ech_speed1;}
	$fo_b_ech_speed2 = $obj->getVesselParameterData($vesselid,"BP_FO_ECO_SPEED2",$user);
	if($fo_b_ech_speed2 == ""){$fo_bes2 = 0;}else{$fo_bes2 = $fo_b_ech_speed2;}
	$do_b_full_speed = $obj->getVesselParameterData($vesselid,"BP_DO_FULL_SPEED",$user);
	if($do_b_full_speed == ""){$do_bfs = 0;}else{$do_bfs = $do_b_full_speed;}
	$do_b_ech_speed1 = $obj->getVesselParameterData($vesselid,"BP_DO_ECO_SPEED1",$user);
	if($do_b_ech_speed1 == ""){$do_bes1 = 0;}else{$do_bes1 = $do_b_ech_speed1;}
	$do_b_ech_speed2 = $obj->getVesselParameterData($vesselid,"BP_DO_ECO_SPEED2",$user);
	if($do_b_ech_speed2 == ""){$do_bes2 = 0;}else{$do_bes2 = $do_b_ech_speed2;}
	
	$l_full_speed = $obj->getVesselParameterData($vesselid,"L_FULL_SPEED",$user);
	if($l_full_speed == "" ){$lfs = 0;}else{$lfs = $l_full_speed;}
	$l_ech_speed1 = $obj->getVesselParameterData($vesselid,"L_ECO_SPEED1",$user);
	if($l_ech_speed1 == "" ){$les1 = 0;}else{$les1 = $l_ech_speed1;}
	$l_ech_speed2 = $obj->getVesselParameterData($vesselid,"L_ECO_SPEED2",$user);
	if($l_ech_speed2 == "" ){$les2 = 0;}else{$les2 = $l_ech_speed2;}
	$fo_l_full_speed = $obj->getVesselParameterData($vesselid,"LP_FO_FULL_SPEED",$user);
	if($fo_l_full_speed == ""){$fo_lfs = 0;}else{$fo_lfs = $fo_l_full_speed;}
	$fo_l_ech_speed1 = $obj->getVesselParameterData($vesselid,"LP_FO_ECO_SPEED1",$user);
	if($fo_l_ech_speed1 == ""){$fo_les1 = 0;}else{$fo_les1 = $fo_l_ech_speed1;}
	$fo_l_ech_speed2 = $obj->getVesselParameterData($vesselid,"LP_FO_ECO_SPEED2",$user);
	if($fo_l_ech_speed2 == ""){$fo_les2 = 0;}else{$fo_les2 = $fo_l_ech_speed2;}
	$do_l_full_speed = $obj->getVesselParameterData($vesselid,"LP_DO_FULL_SPEED",$user);
	if($do_l_full_speed == ""){$do_lfs = 0;}else{$do_lfs = $do_l_full_speed;}
	$do_l_ech_speed1 = $obj->getVesselParameterData($vesselid,"LP_DO_ECO_SPEED1",$user);
	if($do_l_ech_speed1 == ""){$do_les1 = 0;}else{$do_les1 = $do_l_ech_speed1;}
	$do_l_ech_speed2 = $obj->getVesselParameterData($vesselid,"LP_DO_ECO_SPEED2",$user);
	if($do_l_ech_speed2 == ""){$do_les2 = 0;}else{$do_les2 = $do_l_ech_speed2;}
	
	$fo_inport_idle = $obj->getVesselParameterData($vesselid,"PI_FO_FULL_SPEED",$user);
	if($fo_inport_idle == ""){$foidle = 0;}else{$foidle = $fo_inport_idle;}
	$fo_inport_wrking = $obj->getVesselParameterData($vesselid,"PW_FO_FULL_SPEED",$user);
	if($fo_inport_wrking == ""){$fowrking = 0;}else{$fowrking = $fo_inport_wrking;}
	
	$do_inport_idle = $obj->getVesselParameterData($vesselid,"PI_DO_FULL_SPEED",$user);
	if($do_inport_idle == ""){$doidle = 0;}else{$doidle = $do_inport_idle;}
	$do_inport_wrking = $obj->getVesselParameterData($vesselid,"PW_DO_FULL_SPEED",$user);
	if($do_inport_wrking == ""){$dowrking = 0;}else{$dowrking = $do_inport_wrking;}
	
	$flag = $obj->getCountryNameOnId($obj->getVesselIMOData($vessel1d,"FLAG"));
	if($flag == ""){$flag = 0;}else{$flag = $flag;}
	
	if($rec == 0){$vesselrecord = 0;}else{$vesselrecord = $rec;}
	
	$txtOwnerPandI = $obj->getVendorNameBasedOnID($obj->getVesselIMOData($vessel1d,"P_I"));
	
	 if($_SESSION['selBType'] == 3)
	 {
		 $txtCallSign = $obj->getVesselParticularData('CALL_SIGN','vessel_master_6',$vessel1d);
		 $txtInmarsatTel = $obj->getVesselParticularData('TELEX_NUMBER','vessel_master_6',$vessel1d);
		 $txtInmarsatEmail = $obj->getVesselParticularData('EMAIL_ADDRESS','vessel_master_6',$vessel1d);
		 $BuildYard	= $obj->getVesselParticularData('YARD_NAME','vessel_master_1',$vessel1d);
		 $txtPortOfRegis = $obj->getPortName($obj->getVesselParticularData('PORT_ID','vessel_master_1',$vessel1d));
		 $txtLastSpSurvey = $obj->checkVesselDate('DATE_LAST_1','vessel_master_2',$vessel1d);
		 $tpc = $obj->getVesselParticularData('SUMMER_3','vessel_master_1',$vessel1d);
		 $KeelTopMast = $obj->getVesselParticularData('DISTANCE_KEEL','vessel_master_1',$vessel1d);
		 $GrossTon    = $obj->getVesselIMOData($vessel1d,"GRT_NRT");
		 $NetTonnage  = $obj->getVesselIMOData($vessel1d,"NRT");
		 $ballastCondition = $obj->getVesselParticularData('NOH_1','vessel_master_1',$vessel1d);
		 $heavyBlastCondition = $obj->getVesselParticularData('NOH_2','vessel_master_1',$vessel1d);
		 if($ballastCondition == ""){$ballastCondition = $heavyBlastCondition;}
		 elseif($heavyBlastCondition == ""){$ballastCondition = $ballastCondition;}
		 elseif($ballastCondition == "" && $heavyBlastCondition != ""){$ballastCondition = $heavyBlastCondition;}
		 elseif($ballastCondition != "" && $heavyBlastCondition == ""){$ballastCondition = $ballastCondition;}
		 elseif($ballastCondition != "" && $heavyBlastCondition != ""){$ballastCondition = $heavyBlastCondition;}
		 
		 if($txtLastSpSurvey == "0000-00-00" || $txtLastSpSurvey == "1970-01-01"  || $txtLastSpSurvey == ""){ $txtLastSpSurvey = ""; }else{ $txtLastSpSurvey = date("d-m-Y",strtotime($txtLastSpSurvey));}
		 $txtLastDD = $obj->checkVesselDate('DATE_DRYDOCK','vessel_master_2',$vessel1d);
		 if($txtLastDD == "0000-00-00" || $txtLastDD == "1970-01-01"  || $txtLastDD == ""){ $txtLastDD = ""; }else{ $txtLastDD = date("d-m-Y",strtotime($txtLastDD));}
	 }
	 elseif($_SESSION['selBType'] == 2)
	 {
		 $txtCallSign = $obj->getVesselParticularData('CALL_SIGN','vessel_master_tankers',$vessel1d);
		 $txtInmarsatTel = $obj->getVesselParticularData('PHONE_NO','vessel_master_tankers',$vessel1d);
		 $txtInmarsatEmail = $obj->getVesselParticularData('EMAIL_ADDRESS','vessel_master_tankers',$vessel1d);
		 $BuildYard	= $obj->getVesselParticularData('BUILDER','vessel_master_tankers',$vessel1d);
		 $txtPortOfRegis = $obj->getPortName($obj->getVesselParticularData('REGISTRY_PORT','vessel_master_tankers',$vessel1d));
		 $txtLastSpSurvey = $obj->checkVesselDate('SURVEY_DATE','vessel_master_tankers',$vessel1d);
		 $tpc = $obj->getVesselParticularData('TPC_SUMMER','vessel_master_tankers',$vessel1d);
		 $CTankNoOfGrades = $obj->getVesselIMOData($vessel1d,"NO_OF_GRADE");
	     $CPumpCap         =  $obj->getVesselIMOData($vessel1d,"TANKER_PUMP_MAINCAP");
		 $KeelTopMast = $obj->getVesselParticularData('KEEL_KTM','vessel_master_tankers',$vessel1d);
		 $GrossTon    = $obj->getVesselParticularData('GROSS_TONNAGE','vessel_master_tankers',$vessel1d);
		 $NetTonnage  = $obj->getVesselParticularData('NET_TONNAGE','vessel_master_tankers',$vessel1d);
		 $ballastCondition = $obj->getVesselParticularData('FULL_MAST_2','vessel_master_tankers',$vessel1d);
		 $heavyBlastCondition = $obj->getVesselParticularData('COLLAPSED_MAST_2','vessel_master_tankers',$vessel1d);
		 if($ballastCondition == ""){$ballastCondition = $heavyBlastCondition;}
		 elseif($heavyBlastCondition == ""){$ballastCondition = $ballastCondition;}
		 elseif($ballastCondition == "" && $heavyBlastCondition != ""){$ballastCondition = $heavyBlastCondition;}
		 elseif($ballastCondition != "" && $heavyBlastCondition == ""){$ballastCondition = $ballastCondition;}
		 elseif($ballastCondition != "" && $heavyBlastCondition != ""){$ballastCondition = $heavyBlastCondition;}
		 
		 if($txtLastSpSurvey == "0000-00-00" || $txtLastSpSurvey == "1970-01-01"  || $txtLastSpSurvey == ""){ $txtLastSpSurvey = ""; }else{ $txtLastSpSurvey = date("d-m-Y",strtotime($txtLastSpSurvey));}
		 $txtLastDD = $obj->checkVesselDate('DRY_DOCK_DATE','vessel_master_tankers',$vessel1d);
		 if($txtLastDD == "0000-00-00" || $txtLastDD == "1970-01-01"  || $txtLastDD == ""){ $txtLastDD = ""; }else{ $txtLastDD = date("d-m-Y",strtotime($txtLastDD));}
	 }
    
	$txtSummerDraft = $obj->getVesselIMOData($vessel1d,"DRAFTM");
	$txtClassID = $obj->getClaSocNameOnId($obj->getVesselIMOData($vessel1d,"CLA_SOC_ID"));
	$txtSuezGRT = $obj->getVesselParticularData('GT_SUEZ','vessel_master_1',$vessel1d);
	$txtSuezGRT1 = explode('/', $txtSuezGRT);
	$suezGRT = $txtSuezGRT1[0]; $suezNRT = $txtSuezGRT1[1];
	$txtPanamaNRT = $obj->getVesselParticularData('GT_PANAMA','vessel_master_1',$vessel1d);
	$txtPanamaNRT1 = explode('/', $txtPanamaNRT);
	$panamaGRT = $txtPanamaNRT1[0]; $panamaNRT = $txtPanamaNRT1[1];
	
	$a[$vessel1d][] = array('type' => $obj->getVesselTypeBasedOnID($obj->getVesselIMOData($vessel1d,"VESSEL_TYPE")) , 'dwtsum' => $dwt_sum, 'dwttrop' => $dwt_trop, 'grain' => $grain, 'bale' => $bale, 'bfs' => $bfs, 'bes1' => $bes1, 'bes2' => $bes2, 'fobfs' => $fo_bfs, 'fobes1' => $fo_bes1, 'fobes2' => $fo_bes2, 'dobfs' => $do_bfs, 'dobes1' => $do_bes1, 'dobes2' => $do_bes2, 'lfs' => $lfs, 'les1' => $les1, 'les2' => $les2, 'folfs' => $fo_lfs, 'foles1' => $fo_les1, 'foles2' => $fo_les2, 'dolfs' => $do_lfs, 'doles1' => $do_les1, 'doles2' => $do_les2, 'foidle' => $foidle, 'fwking' => $fowrking, 'ddle' => $doidle, 'dwking' => $dowrking, 'num' => $rec, 'flag' => $flag, 'year' => $obj->getVesselIMOData($vessel1d,"YEARBUILT"), 'gnrt' => $obj->getVesselIMOData($vessel1d,"GRT_NRT"), 'gear' => $obj->getVesselIMOData($vessel1d,"CARGO_GEAR"), 'loa' => $obj->getVesselIMOData($vessel1d,"LOA"), 'beam' => $obj->getVesselIMOData($vessel1d,"EXT_BREADTH"), 'tpc' => $tpc, 'BuildYard' => $BuildYard, 'txtPortOfRegis' => $txtPortOfRegis, 'txtIMOnum' => $obj->getVesselIMOData($vessel1d,"IMO_NO"), 'txtOwnerPandI' => $txtOwnerPandI, 'txtCallSign' => $txtCallSign, 'txtInmarsatTel' => $txtInmarsatTel, 'txtInmarsatEmail' => $txtInmarsatEmail, 'txtSummerDraft' => $txtSummerDraft, 'txtClassID' => $txtClassID, 'txtLastSpSurvey' => $txtLastSpSurvey, 'txtLastDD' => $txtLastDD, 'GrossTonnage' => $GrossTon, 'NetTonnage' => $NetTonnage, 'CTankCap' => $obj->getVesselIMOData($vessel1d,"TANKER_CAPACITY"), 'CTankNoOfGrades' => $CTankNoOfGrades, 'CPumpCap' => $CPumpCap, 'CTotalSBTCap' => $obj->getVesselIMOData($vessel1d,"TANKER_SBT_CAPACITY"), 'txtSuezGRT' => $suezGRT, 'txtSuezNRT' => $suezNRT, 'PanamaNRT' => $panamaNRT, 'txtGrainCap' => $obj->getVesselIMOData($vessel1d,"GRAIN"), 'txtBaleCap' => $obj->getVesselIMOData($vessel1d,"BALE"), 'txtCranes' => $obj->getVesselIMOData($vessel1d,"CRANESIZE"), 'txtGrabs' => $obj->getVesselIMOData($vessel1d,"GRABSIZE"), 'KeelTopMast' => $KeelTopMast, 'WaterlineTopMast' => $ballastCondition, 'btypename'=>$btypename  , 'SDWTMT'=>$obj->getVesselIMOData($vessel1d,"DWT"), 'SDWTLT'=>$obj->getVesselParticularData('DWT_LT','vessel_master_1',$vessel1d), 'SDraftM'=>$obj->getVesselIMOData($vessel1d,"DRAFTM"), 'SDraftFT'=>$obj->getVesselParticularData('DRAFT_FT','vessel_master_1',$vessel1d), 'TPIMT'=>$obj->getVesselParticularData('TPI_MT','vessel_master_1',$vessel1d), 'TPILT'=>$obj->getVesselParticularData('TPI_LT','vessel_master_1',$vessel1d), 'TPCMT'=>$obj->getVesselParticularData('TPC_MT','vessel_master_1',$vessel1d), 'TPCLT'=>$obj->getVesselParticularData('TPC_LT','vessel_master_1',$vessel1d), 'ConstantsMT'=>$obj->getVesselParticularData('CONSTANTMT','vessel_master_1',$vessel1d), 'ConstantsLT'=>$obj->getVesselParticularData('CONSTANTLT','vessel_master_1',$vessel1d), 'GrainCapCBM'=>$obj->getVesselIMOData($vessel1d,"GRAIN"), 'GrainCapCFT'=>number_format($obj->getVesselIMOData($vessel1d,"GRAIN")*35.3147,0,'.',''));
	echo json_encode($a);
}

function getGenerateAgencyLetterDataJson() 
{
	
	$obj 		= new data();
	$connect	= $obj->funConnect();
	$agencyid 	= $_REQUEST['agencyid'];
	$comid    	= $_REQUEST['comid'];
	$port 		= $_REQUEST['port'];
	$portid 	= $_REQUEST['portid'];
	$tabid 		= $_REQUEST['tabid'];
	$serialno   = $_REQUEST['serialno'];
	
	$sql 		= "select * from generate_agency_letter where COMID='".$comid."' and MODULEID='".$_SESSION['moduleid']."' AND MCOMPANYID='".$_SESSION['company']."' and PORT='".$port."' and PORTID='".$portid."' and RANDOMID='".$serialno."'";
	
	$res 	 	=  mysql_query($sql) or die($sql);
	$rows 		= mysql_fetch_assoc($res);
	
	$genDataJson = array('GEN_AGENCY_ID' => $rows['GEN_AGENCY_ID'],'COMID' => $rows['COMID'],'MODULEID' => $rows['MODULEID'],'MCOMPANYID' => $rows['MCOMPANYID'],'PORT' => $rows['PORT'],'PORTID' => $rows['PORTID'],'DATE' => date("d-m-Y",strtotime($rows['DATE'])),'KIND_ATTN_TO' => $rows['KIND_ATTN_TO'],'USERNAME' => $rows['USERNAME'],'PASSWORD' => $rows['PASSWORD'],'PASSWORD' => $rows['PASSWORD'],'EMAIL_ADDRESS_1' => $rows['EMAIL_ADDRESS_1'],'EMAIL_ADDRESS_2' => $rows['EMAIL_ADDRESS_2'],'EMAIL_CHARTER_1' => $rows['EMAIL_CHARTER_1'],'EMAIL_CHARTER_2' => $rows['EMAIL_CHARTER_2'],'EMAIL_CHARTER_3' => $rows['EMAIL_CHARTER_3'],'EMAIL_CHARTER_4' => $rows['EMAIL_CHARTER_4'],'EMAIL_CHARTER_5' => $rows['EMAIL_CHARTER_5'],'PAD_INI_PAY_PERSENT' => $rows['PAD_INI_PAY_PERSENT'],'PAD_FIN_PAY_PERSENT' => $rows['PAD_FIN_PAY_PERSENT'],'BS_FUEL_GR_SP' => $rows['BS_FUEL_GR_SP'],'BS_SUPPLIER' => $rows['BS_SUPPLIER'],'BS_PHYSICAL' => $rows['BS_PHYSICAL'],'BS_QUANTITY' => $rows['BS_QUANTITY'],'BS_BUNKERING_PORT' => $rows['BS_BUNKERING_PORT'],'TERMO_OF_TOLERANCE' => $rows['TERMO_OF_TOLERANCE'],'CARGO_PACKING_DESC' => $rows['CARGO_PACKING_DESC'],'TOLERANCE_SUB' => $rows['TOLERANCE_SUB'],'TOLERANCE_PERCENT_SUB' => $rows['TOLERANCE_PERCENT_SUB'],'TOLERANCE_ADD' => $rows['TOLERANCE_ADD'],'TOLERANCE_PERCENT_ADD' => $rows['TOLERANCE_PERCENT_ADD'],'QTY' => $rows['QTY']);
	echo json_encode($genDataJson);die();
	
}

function checkDuplicateIMONo()
{
	$obj = new data();
	$connect=$obj->funConnect();
	$txtIMONo = trim(ereg_replace(' +',' ',$_REQUEST['txtIMONo']));
	$query = mysql_query("select * from vessel_imo_master where MCOMPANYID='".$_SESSION['company']."' and IMO_NO='".$txtIMONo."' ");
	$num=mysql_num_rows($query);
		if($num > 0)
		{
			echo 'false';
		}
		else
		{
			echo 'true';
		}
}

function checkDuplicateVessel()
{
	$obj = new data();
	$connect=$obj->funConnect();
	$vessel_name = trim(ereg_replace(' +',' ',$_REQUEST['txtVName']));
	$query = mysql_query("select * from vessel_imo_master where MCOMPANYID='".$_SESSION['company']."' and VESSEL_NAME='".$vessel_name."' ");
	$num=mysql_num_rows($query);
		if($num > 0)
		{
			echo 'false';
		}
		else
		{
			echo 'true';
		}
}

function getPaymentRequestYesOrNo()
{
	$obj 			= new data();
	$connect		= $obj->funConnect();
	
	$port_id = $_REQUEST['port_id'];
	$port = $_REQUEST['port'];
	$mappingid = $_REQUEST['mappingid'];
	$sql = "select * from request_master where MAPPINGID='".$mappingid."' and MODULEID='".$_SESSION['moduleid']."'  AND MCOMPANYID='".$_SESSION['company']."' and NAME='Port Costs' and GRADEID='".$port_id."' and PORT='".$port."'";
	$res = mysql_query($sql);
	$rec = mysql_num_rows($res);
	echo $rec;	
}

function getDecisionChartListList()
{
	$obj 			= new data();
	$connect		= $obj->funConnect();
	$val   =  $_REQUEST['val'];
	$val1  =  $_REQUEST['val2'];
	if(strlen($val1) ==1){$val1 = "00".$val1;}
	if(strlen($val1) ==2){$val1 = "0".$val1;}
	if(strlen($val1) >2){$val1 = $val1;}
	$sql1 = "select * from freight_cost_estimate_compare WHERE MODULEID='".$_SESSION['moduleid']."' AND MCOMPANYID='".$_SESSION['company']."' and MESSAGE ='".$val."-".$val1."' ";
	$res1 = mysql_query($sql1);
	$arr = array();
	while($row1 = mysql_fetch_assoc($res1))
	{
		$arr[] = $row1['FCAID'];
	}
	$arr1 = implode(',',$arr);
	echo '<div class="box-body table-responsive">
	<div align="right" style="margin-bottom:10px; margin-top:-10px;"><a href="allPdf.php?id=54&val='.$val.'&val2='.$val1.'" title="Pdf"><button class="btn btn-default" style="margin-right: 5px;"><i class="fa fa-download"></i> Generate PDF</button></a></div>';
	echo '<table id="fce1_list" class="table table-bordered table-striped">';
	echo '<thead>';
	echo '<tr>';
	echo '<th align="center" valign="middle" width="5%">#</th>';
	echo '<th align="left" valign="middle" width="10%">Vessel Name</th>';
	echo '<th align="left" valign="middle" width="10%">Sheet Name</th>';
	echo '<th align="left" valign="middle" width="10%">DWT</th>';
	if($_SESSION['selBType']==1)
	{
	echo '<th align="left" valign="middle" width="10%">Base Freight <span style="font-size:10px; font-style:italic;">(USD/MT)</span> / Lumpsum <span style="font-size:10px; font-style:italic;">(USD)</span></th>';
	}
	if($_SESSION['selBType']==3)
	{
	echo '<th align="left" valign="middle" width="10%">Freight <span style="font-size:10px; font-style:italic;">(USD/MT)</th>';
	}
	if($_SESSION['selBType']==2)
	{
	echo '<th align="left" valign="middle" width="10%">WS/<br/>Lumpsum <span style="font-size:10px; font-style:italic;">(USD/MT)</th>';
	}
	echo '<th align="left" valign="middle" width="6%">Delivery Port</th>';
	echo '<th align="left" valign="middle" width="6%">LP/DP</th>';
	echo '<th align="left" valign="middle" width="5%">Duration</th>';
	echo '<th align="left" valign="middle" width="5%">Cargo Quantity</th>';
	echo '<th align="left" valign="middle" width="5%">TCE</th>';
	echo '<th align="left" valign="middle" width="5%">Daily Time Charter <span style="font-size:10px; font-style:italic;">(USD/Day)</span></th>';
	echo '<th align="left" valign="middle" width="5%">P/L</th>';
	echo '<th align="left" valign="middle" width="5%">Status</th>';
	echo '<th align="left" valign="middle" width="25%">Remarks</th>';
	echo '<th align="center" valign="middle" width="5%">Select</th>';
	echo '<th align="center" valign="middle" width="5%">View</th>';
	echo '</tr>';
	echo '</thead>';
	echo '<tbody id="tbody">';
	$sql = "select * from freight_cost_estimete_master WHERE MODULEID='".$_SESSION['moduleid']."' AND MCOMPANYID='".$_SESSION['company']."' and FCAID in (".$arr1.") order by FCAID desc";
	$res = mysql_query($sql);
	$rec = mysql_num_rows($res);
	$i = 1;
	if($rec == 0)
	{
		
	}
	else{
	
		while($rows = mysql_fetch_assoc($res))
		{
			$arr_ballast = $arr_load = $arr_discharge = array();
			$sql1 = "select * from freight_cost_estimete_slave1 where FCAID='".$rows['FCAID']."'";
            $res1 = mysql_query($sql1);
			while($rows1 = mysql_fetch_assoc($res1))
			{
				if($rows1['PASSAGE_TYPE'] == 2)
				{
				  $arr_load[] = $obj->getPortNameBasedOnID($rows1['FROM_PORT']);
				  $arr_discharge[] = $obj->getPortNameBasedOnID($rows1['TO_PORT']);
				}
				if($rows1['PASSAGE_TYPE'] == 1)
				{
					$arr_ballast[] = $obj->getPortNameBasedOnID($rows1['FROM_PORT']);
				}
			}
			
			$sql2 = "select * from freight_cost_estimate_compare WHERE MESSAGE ='".$val."-".$val1."' and FCAID='".$rows['FCAID']."' ";
			$res2 = mysql_query($sql2);
			$row2 = mysql_fetch_assoc($res2);
			if($rows['FIXED']==1){$fixed = "Finalised";}else{$fixed = "Not Fixed";}
			if($row2['FCAID']==$row2['FINAL_ID']){$checked = "checked";}else{$checked = "";}
			
			$quantity = 0;$freight = 0;
			if($rows['ESTIMATE_TYPE']==1)
			{
				$quantity = $rows['GAS_QUANTITY'];
				if($rows['GAS_MARKET']==1){$freight = 'Base Freight '.$rows['GAS_BASE_RATE'];}else{$freight = 'Lumpsum '.$rows['GAS_LUMSUM'];}
			}
			else if($rows['ESTIMATE_TYPE']==2)
			{
				$quantity = $rows['TANK_QUANTITY'];
				$sql21 = "select MIN_WS from freight_cost_estimete_slave12 where FCAID='".$rows['FCAID']."' ";
				$res21 = mysql_query($sql21);
				$row21 = mysql_fetch_assoc($res21);
				if($rows['CHK_LUMPSUM']==1){$freight = 'Lumpsum '.$rows['LUMPSUMAMT'];}else{$freight = 'WS '.$row21['MIN_WS'];}
			}
			else
			{
				if($rows['QTY_TYPE_RADIO'] == 1)
				{
					$quantity = $rows['QUANTITY'];
					$freight = $rows['FREIGHT_GROSS'];
				}
				else
				{
					$sql12 = "select sum(QUANTITY) as sum, sum(GROSS_FREIGHT) as sum1 from freight_cost_estimete_slave7 where FCAID='".$rows['FCAID']."'";
					$res12 = mysql_query($sql12);
					$row12 = mysql_fetch_assoc($res12);
					$quantity = $row12['sum'];
					$freight = $row12['sum1'];
				}
			}
			
			echo '<tr>';
			echo '<td align="center" valign="middle" class="input-text">'.$i.'.</td>';
			echo '<td align="left" valign="middle" class="input-text">'.$obj->getVesselIMOData($rows['VESSEL_IMO_ID'],"VESSEL_NAME").'</td>';
			echo '<td align="left" valign="middle" class="input-text">'.$rows['VOYAGE_NAME'].'</td>';
			echo '<td align="left" valign="middle" class="input-text">'.$obj->getVesselIMOData($rows['VESSEL_IMO_ID'],"DWT").'</td>';
			echo '<td align="left" valign="middle" class="input-text">'.$freight.'</td>';
			echo '<td align="left" valign="middle" class="input-text">'.implode(', ',$arr_ballast).'</td>';
			echo '<td align="left" valign="middle" class="input-text">'.implode(', ',$arr_load).'/ '.implode(', ',$arr_discharge).'</td>';
			echo '<td align="left" valign="middle" class="input-text">'.$rows['TOTAL_DAYS'].'</td>';
			echo '<td align="left" valign="middle" class="input-text">'.$quantity.'</td>';
			echo '<td align="left" valign="middle" class="input-text">'.$rows['DAILY_EARNING'].'</td>';
			echo '<td align="left" valign="middle" class="input-text">'.$rows['DAILY_VESSEL_OPERATION_EXP'].'</td>';
			echo '<td align="left" valign="middle" class="input-text">'.$rows['PROFIT_LOSS'].'</td>';
			echo '<td align="left" valign="middle" class="input-text">'.$fixed.'</td>';
			echo '<td align="left" valign="middle" class="input-text">'.$row2['REMARKS'].'</td>';
			echo '<td align="center" valign="middle" class="input-text"><b><input type="radio" name="rdoFCA" id="rdoFCA_'.$i.'" value="'.$rows['FCAID'].'" class="checkbox"  '.$checked.'/></b><input type="hidden" name="hiddnFca_'.$i.'" id="hiddnFca_'.$i.'" value="'.$rows['FCAID'].'"/></td>';
			echo '<td align="center" valign="middle" class="input-text"><a href="viewestimate.php?id='.$rows['FCAID'].'&rttype=2" title="View Details"><strong><i class="fa fa-file"></i></strong></a></td>';
			echo '</tr>';
			$i++;
		}
	
	}echo '</tbody>';
	echo '</table></div>';
}



function getCompareEstimatesList()
{
	$obj 			= new data();
	$connect		= $obj->funConnect();
	$chkArr   =  $_REQUEST['chkArr'];
	echo '<div class="box-body table-responsive">';
	echo '<table id="fce1_list" class="table table-bordered table-striped">';
	echo '<thead>';
	echo '<tr>';
	echo '<th align="center" valign="middle" width="5%">#</th>';
	echo '<th align="left" valign="middle" width="10%">Vessel Name</th>';
	echo '<th align="left" valign="middle" width="10%">Sheet Name</th>';
	echo '<th align="left" valign="middle" width="5%">DWT</th>';
	if($_SESSION['selBType'] == 1)
	{
	echo '<th align="left" valign="middle" width="10%">Base Freight <span style="font-size:10px; font-style:italic;">(USD/MT)</span>/ Lumpsum <span style="font-size:10px; font-style:italic;">(USD)</span></th>';
	}
	if($_SESSION['selBType'] == 2)
	{
	echo '<th align="left" valign="middle" width="10%">WS/Lump-sum<span style="font-size:10px; font-style:italic;">(USD)</span></th>';
	}
	if($_SESSION['selBType'] == 3)
	{
	echo '<th align="left" valign="middle" width="10%">Freight <span style="font-size:10px; font-style:italic;">(USD/MT)</span></th>';
	}
	echo '<th align="left" valign="middle" width="6%">Delivery Port</th>';
	echo '<th align="left" valign="middle" width="6%">LP/DP</th>';
	echo '<th align="left" valign="middle" width="5%">Duration</th>';
	echo '<th align="left" valign="middle" width="5%">Cargo Quantity</th>';
	echo '<th align="left" valign="middle" width="5%">TCE</th>';
	echo '<th align="left" valign="middle" width="5%">Daily Time Charter <span style="font-size:10px; font-style:italic;">(USD/Day)</span></th>';
	echo '<th align="left" valign="middle" width="5%">P/L</th>';
	echo '<th align="left" valign="middle" width="25%">Remarks<br/><div style="min-width:150px;"></div></th>';
	echo '<th align="center" valign="middle" width="5%">Select</th>';
	echo '<th align="center" valign="middle" width="2%">Edit</th>';
	echo '</tr>';
	echo '</thead>';
	echo '<tbody id="tbody">';
	$sql = "select * from freight_cost_estimete_master WHERE MODULEID='".$_SESSION['moduleid']."' AND MCOMPANYID='".$_SESSION['company']."' and FCAID in (".$chkArr.") order by FCAID desc";
	$res = mysql_query($sql);
	$rec = mysql_num_rows($res);
	$i = 1;
	if($rec == 0)
	{
		
	}
	else{
	
		while($rows = mysql_fetch_assoc($res))
		{
			
			
			$arr_ballast = $arr_load = $arr_discharge = array();
			$sql2 = "select * from freight_cost_estimete_slave1 where FCAID='".$rows['FCAID']."'";
            $res2 = mysql_query($sql2);
			while($rows2 = mysql_fetch_assoc($res2))
			{
				  $arr_load[] = $obj->getPortNameBasedOnID($rows2['FROM_PORT']);
				  $arr_discharge[] = $obj->getPortNameBasedOnID($rows2['TO_PORT']);
				
				if($rows2['PASSAGE_TYPE'] == 1)
				{
					$arr_ballast[] = $obj->getPortNameBasedOnID($rows2['FROM_PORT']);
				}
			}
			
			$quantity = $freight = 0;
			if($rows['ESTIMATE_TYPE']==1)
			{
				$quantity = $rows['GAS_QUANTITY'];
				if($rows['GAS_MARKET']==1){$freight = 'Base Freight '.$rows['GAS_BASE_RATE'];}else{$freight = 'Lumpsum '.$rows['GAS_LUMSUM'];}
			}
			else if($rows['ESTIMATE_TYPE']==2)
			{
				$quantity = $rows['TANK_QUANTITY'];
				$sql21 = "select MIN_WS from freight_cost_estimete_slave12 where FCAID='".$rows['FCAID']."' ";
				$res21 = mysql_query($sql21);
				$row21 = mysql_fetch_assoc($res21);
				if($rows['CHK_LUMPSUM']==1){$freight = 'Lumpsum '.$rows['LUMPSUMAMT'];}else{$freight = 'WS '.$row21['MIN_WS'];}
			}
			else
			{
				if($rows['QTY_TYPE_RADIO'] == 1)
				{
					$quantity = $rows['QUANTITY'];
					$freight = $rows['FREIGHT_GROSS'];
				}
				else
				{
					$sql12 = "select sum(QUANTITY) as sum, sum(GROSS_FREIGHT) as sum1 from freight_cost_estimete_slave7 where FCAID='".$rows['FCAID']."'";
					$res12 = mysql_query($sql12);
					$row12 = mysql_fetch_assoc($res12);
					$quantity = $row12['sum'];
					$freight = $row12['sum1'];
				}
			}
			echo '<tr>';
			echo '<td align="center" valign="middle" class="input-text">'.$i.'.</td>';
			echo '<td align="left" valign="middle" class="input-text">'.$obj->getVesselIMOData($rows['VESSEL_IMO_ID'],"VESSEL_NAME").'</td>';
			echo '<td align="left" valign="middle" class="input-text">'.$rows['VOYAGE_NAME'].'</td>';
			echo '<td align="left" valign="middle" class="input-text">'.$obj->getVesselIMOData($rows['VESSEL_IMO_ID'],"DWT").'</td>';
			echo '<td align="left" valign="middle" class="input-text">'.$freight.'</td>';
			echo '<td align="left" valign="middle" class="input-text">'.implode(', ',$arr_ballast).'</td>';
			echo '<td align="left" valign="middle" class="input-text">'.implode(', ',$arr_load).'/ '.implode(', ',$arr_discharge).'</td>';
			echo '<td align="left" valign="middle" class="input-text">'.$rows['TOTAL_DAYS'].'</td>';
			echo '<td align="left" valign="middle" class="input-text">'.$quantity.'</td>';
			
			echo '<td align="left" valign="middle" class="input-text">'.$rows['DAILY_EARNING'].'</td>';
			echo '<td align="left" valign="middle" class="input-text">'.$rows['DAILY_VESSEL_OPERATION_EXP'].'</td>';
			echo '<td align="left" valign="middle" class="input-text">'.$rows['PROFIT_LOSS'].'</td>';
			echo '<td align="left" valign="middle" class="input-text"><textarea class="form-control areasize" name="txtDesc_'.$i.'" id="txtDesc_'.$i.'" rows="3" placeholder="Remarks ..." ></textarea></td>';
			echo '<td align="center" valign="middle" class="input-text"><input type="radio" name="rdoFCA" id="rdoFCA_'.$i.'" value="'.$rows['FCAID'].'" class="checkbox"/><input type="hidden" name="hiddnFca_'.$i.'" id="hiddnFca_'.$i.'" value="'.$rows['FCAID'].'"/></td>';
			echo '<td align="center" valign="middle" class="input-text"><a href="updateestimate.php?id='.$rows['FCAID'].'&ids='.$chkArr.'" title="Edit Details" ><i class="fa fa-edit "></i></a></td>';	
			echo '</tr>';
			$i++;
		}
	
	}echo '</tbody>';
	echo '</table></div>
	       <div class="row invoice-info" >
				<div class="col-sm-12 invoice-col" style="text-align:right;">
					<address>
					   <button type="button" class="btn btn-info btn-flat" onclick="SubmitToCompare();">Submit</button>
					   <input type="hidden" name="hddnCount" id="hddnCount" value="'.$rec.'" />
					</address>
				</div>
            </div>';
}






function getProfitabilityHeadWiseReport()
{
	$obj 			= new data();
	$connect		= $obj->funConnect();
	
	$txtFrom_Date 	= date('Y-m-d',strtotime($_REQUEST['txtFrom_Date']));
	$txtTo_Date 	= date('Y-m-d',strtotime($_REQUEST['txtTo_Date']));
	
	$sql = "select * from freight_cost_analysis_master inner join mapping_master on mapping_master.MAPPINGID = freight_cost_analysis_master.MAPPINGID where TRANS_DATE >='".date('Y-m-d',strtotime($_REQUEST['txtFrom_Date']))."' and TRANS_DATE <='".date('Y-m-d',strtotime($_REQUEST['txtTo_Date']))."' and freight_cost_analysis_master.MODULEID='".$_SESSION['moduleid']."' AND freight_cost_analysis_master.MCOMPANYID='".$_SESSION['company']."' group by freight_cost_analysis_master.MAPPINGID ";
	$res = mysql_query($sql);
	$rec = mysql_num_rows($res);
	$i = 1;
	if($rec == 0)
	{
		echo '<tr>';
		echo '<td align="center" valign="middle" colspan="9" style="color:red;letter-spacing:1px;">SORRY CURRENTLY THERE ARE ZERO(0) RECORDS.</td>';
		echo '</tr>';
	}
	else
	{   $arr_sumin = $arr_sumout = array();
		while($rows = mysql_fetch_assoc($res))
		{
		    $sheetNo = $obj->getLatestCostSheetID($rows['MAPPINGID']);
			$cpdate = date('Y-m-d',strtotime($rows['TRANS_DATE']));
			$sel2 = "select sum(COSTIN) as sum1, sum(COSTOUT) as sum2 from profit_head_master where MODULEID='".$_SESSION['moduleid']."' and MCOMPANYID='".$_SESSION['company']."' and MAPPINGID='".$rows['MAPPINGID']."' and SHEET_NO='".$sheetNo."' and (COSTIN >0 or COSTOUT>0) and VENDORID!=''";
			$result2 = mysql_query($sel2) or die($sel2);
			$rows2  = mysql_fetch_assoc($result2);
			
			$sel = "select * from profit_head_master where MODULEID='".$_SESSION['moduleid']."' and MCOMPANYID='".$_SESSION['company']."' and MAPPINGID='".$rows['MAPPINGID']."' and SHEET_NO='".$sheetNo."' and (COSTIN >0 or COSTOUT>0) and VENDORID!=''";
			$result = mysql_query($sel) or die($sel);
			$num1   = mysql_num_rows($result);
			if($num1>0){$colspan = $num1+ 2;}else{$colspan = 1;}
			
			if($num1>0)
			{
			    $arr_sumin1 = $arr_sumout1 = array();
			    echo '<tr>';
				echo '<td align="left" rowspan="'.$colspan.'" valign="middle"><strong>'.$i.'</strong></td>';
				echo '<td align="left" rowspan="'.$colspan.'" valign="middle"><strong>'.$obj->getMappingData($rows['MAPPINGID'],"NOM_NAME").'</strong></td>';
				echo '<td align="left" rowspan="'.$colspan.'" valign="middle"><strong>'.$obj->getVesselIMOData($obj->getVesselOpenEntryDeta($rows['OPEN_VESSEL_ID'],'VESSEL_IMO_ID'),"VESSEL_NAME").'</strong></td>';
				echo '<td align="left" rowspan="'.$colspan.'" valign="middle"><strong>'.date('d-m-Y',strtotime($cpdate)).'</strong></td>';
				echo '<td align="left" valign="middle"><strong>'.$rows['CARGO_QTY'].'</strong></td>';
				echo '<td align="left" valign="middle"></td>';
				echo '<td align="left" valign="middle"><strong>'.$rows2['sum1'].'</strong></td>';
				echo '<td align="left" valign="middle"><strong>'.$rows2['sum2'].'</strong></td>';
				echo '<td align="left" valign="middle"><strong>'.($rows2['sum1'] - $rows2['sum2']).'</strong></td>';
				echo '</tr>';
				while($rows1  = mysql_fetch_assoc($result))
				{
				    $text = "";
					$arr_sumin1[] = $rows1['COSTIN']; $arr_sumout1[]=$rows1['COSTOUT'];
				    if($rows1['IDENTIFY']=="FREIGHT")
					{$text = "Final Nett Freight";}
					else if($rows1['IDENTIFY']=="BROKERAGE")
					{$text = "Total Brokerage Commission (%)";}
					else if($rows1['IDENTIFY']=="BROKERAGE")
					{$text = "Total Brokerage Commission (%)";}
					else if($rows1['IDENTIFY']=="BUNKERNETT")
					{$text = "Total Brokerage Commission (%)";}
					else if($rows1['IDENTIFY']=="OWNERRELATED")
					{$text = "Owner Related Costs (".$obj->getOwnerRelatedCostNameBasedOnID($rows1['IDENTIFY_ID']).")";}
					else if($rows1['IDENTIFY']=="CHARTERER")
					{$text = "Charterers' Costs (".$obj->getChartererCostNameBasedOnID($rows1['IDENTIFY_ID']).")";}
					else if($rows1['IDENTIFY']=="LPCOST")
					{$text = "Port Cost (Load Port  ".$obj->getPortNameBasedOnID($rows1['IDENTIFY_ID']).")";}
					
					else if($rows1['IDENTIFY']=="DPCOST")
					{$text = "Port Cost (Discharge Port ".$obj->getPortNameBasedOnID($rows1['IDENTIFY_ID']).")";}
					else if($rows1['IDENTIFY']=="TPCOST")
					{$text = "Port Cost (Transit Port ".$obj->getPortNameBasedOnID($rows1['IDENTIFY_ID']).")";}
					else if($rows1['IDENTIFY']=="DLPCOST")
					{$text = "Demurrage (Load Port  ".$obj->getPortNameBasedOnID($rows1['IDENTIFY_ID']).")";}
					else if($rows1['IDENTIFY']=="DDPCOST")
					{$text = "Demurrage (Discharge Port  ".$obj->getPortNameBasedOnID($rows1['IDENTIFY_ID']).")";}
					else if($rows1['IDENTIFY']=="OTHERMISC")
					{$text = "Other Misc. Income (".$obj->getOtherMiscCostNameBasedOnID($rows1['IDENTIFY_ID']).")";}
				    echo '<tr>';
					echo '<td align="left" valign="middle">'.$text.'</td>';
					echo '<td align="left" valign="middle">'.$obj->getVendorListNewBasedOnID($rows1['VENDORID']).'</td>';
					echo '<td align="left" valign="middle">'.$rows1['COSTIN'].'</td>';
					echo '<td align="left" valign="middle">'.$rows1['COSTOUT'].'</td>';
					echo '<td align="left" valign="middle">'.($rows1['COSTIN'] - $rows1['COSTOUT']).'</td>';
					echo '</tr>';
				}
				echo '<tr>';
				echo '<td align="left" colspan="2" valign="middle"><strong>Total</strong></td>';
				echo '<td align="left" valign="middle">'.array_sum($arr_sumin1).'</td>';
				echo '<td align="left" valign="middle">'.array_sum($arr_sumout1).'</td>';
				echo '<td align="left" valign="middle">'.(array_sum($arr_sumin1) - array_sum($arr_sumout1)).'</td>';
				echo '</tr>';$i++;
			}
		    
		}
	}
}

/******************************Cost sheet compair********************************/

function getVoyageFinancialsComparisonData()
{
	$obj 			= new data();
	$connect		= $obj->funConnect();
	$selVFEstimate 	= $_REQUEST['selVFEstimate'];
	$mappingid 		= $_REQUEST['mappingid'];
	$arr 			= explode(",",$selVFEstimate);
	
	echo '<div align="right"><a href="#Pdf" title="Pdf" onclick="getPdf();" class="btn btn-default" style="margin:5px;"><i class="fa fa-download"></i> Generate PDF</a></div>';
	echo '<table cellspacing="0" class="table table-bordered table-striped dataTable" id="GridView1" style="width:100%;border-collapse:collapse;overflow:scroll;">';
	echo '<tr class="GridviewScrollHeader">';
	echo '<td align="left" valign="middle" style="color:#fff; background-color:#1E85BE" >VOYAGE ESTIMATES</td>';
	for($i=0;$i<count($arr);$i++)
	{
		echo '<td align="left" width="37%" valign="middle" style="color:#fff;background-color:#1E85BE;" >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'.$obj->getFreightCostEstimationData($arr[$i],"ESTIMATION_NO").'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>';
	}	
	echo '</tr>';
	
	echo '<tr class="GridviewScrollItem" >';
	echo '<td align="left" valign="top" style="color:#1b77a6;font-weight:bold;">Vessel Name</td>';
	for($i=0;$i<count($arr);$i++)
	{
		echo '<td align="center" width="37%" valign="top">'.$obj->getVesselIMOData($obj->getVesselOpenEntryDeta($obj->getMappingData($mappingid,"OPEN_VESSEL_ID"),"VESSEL_IMO_ID"),"VESSEL_NAME").'</td>';
	}
	echo '</tr>';
	
	echo '<tr class="GridviewScrollItem" >';
	echo '<td align="left" valign="top" style="color:#1b77a6;font-weight:bold;">Date</td>';
	for($i=0;$i<count($arr);$i++)
	{
		echo '<td align="center" width="37%" valign="top" style="font-size:12px;">'.date("d M Y",strtotime($obj->getFreightCostEstimationData($arr[$i],"TRANS_DATE"))).'</td>';
	}
	echo '</tr>';
	
	echo '<tr class="GridviewScrollItem" >';
	echo '<td align="left" valign="top" style="font-size:12px;color:#1b77a6;font-weight:bold;">Voy No.</td>';
	for($i=0;$i<count($arr);$i++)
	{
		echo '<td align="center" width="37%" valign="top">'.$obj->getFreightCostEstimationData($arr[$i],"VOYAGE_NO").'</td>';
	}
	echo '</tr>';
	
	/*echo '<tr class="GridviewScrollItem" >';
	echo '<td align="left" valign="top" style="color:#1b77a6;font-weight:bold;">DWT <span style="font-size:10px; font-style:italic;">(Summer)</span></td>';
	for($i=0;$i<count($arr);$i++)
	{
		echo '<td align="center" width="37%" valign="top">'.$obj->getFreightCostEstimationData($arr[$i],"SUMMER_DWT").'</td>';
	}
	echo '</tr>';*/
	
	echo '<tr class="GridviewScrollItem" >';
	echo '<td align="left" valign="top" style="color:#1b77a6;font-weight:bold;">Cargo Type / Cargo Name</td>';
	for($i=0;$i<count($arr);$i++)
	{
		echo '<td align="center" width="37%" valign="top">'.$obj->getCargoTypeNameBasedOnID($obj->getFreightCostEstimationData($arr[$i],"CARGO_TYPEID")).' / '.$obj->getCargoContarctForMapping($obj->getMappingData($mappingid,"CARGO_IDS"),$obj->getMappingData($mappingid,"CARGO_POSITION")).'</td>';
	}
	echo '</tr>';
	
	echo '<tr class="GridviewScrollItem" >';
	echo '<td align="left" valign="top" style="color:#1b77a6;font-weight:bold;">Cargo Qty <span style="font-size:10px; font-style:italic;">(MT)</span></td>';
	for($i=0;$i<count($arr);$i++)
	{
		echo '<td align="center" width="37%" valign="top">'.$obj->getFreightCostEstimationData($arr[$i],"CARGO_QTY").'</td>';
	}
	echo '</tr>';
	
		
	echo '<tr class="GridviewScrollItem" >';
	echo '<td align="left" valign="top" style="background-color:#DDDDDD;color:#1b77a6;font-weight:bold;">&nbsp;</td>';
	for($i=0;$i<count($arr);$i++)
	{
		echo '<td align="center" width="37%" valign="top" style="background-color:#DDDDDD;">&nbsp;</td>';
	}
	echo '</tr>';
	
	echo '<tr class="GridviewScrollItem" >';
	echo '<td align="left" valign="top" style="color:#1b77a6;font-weight:bold;">Load Port</td>';
	for($i=0;$i<count($arr);$i++)
	{
		echo '<td align="center" width="37%" valign="top">'.$obj->getFCECostSheetPortNameBasedOnID($arr[$i],"fca_tci_load_port","LOADPORTID").'</td>';
	}
	echo '</tr>';
	
	echo '<tr class="GridviewScrollItem" >';
	echo '<td align="left" valign="top" style="color:#1b77a6;font-weight:bold;">Load Rate <span style="font-size:10px; font-style:italic;">(MT/Day)</span></td>';
	for($i=0;$i<count($arr);$i++)
	{
		echo '<td align="center" width="37%" valign="top">'.$obj->getFCECostSheetPortDataBasedOnID($arr[$i],"fca_tci_load_port","RATE").'</td>';
	}
	echo '</tr>';
	
	echo '<tr class="GridviewScrollItem" >';
	echo '<td align="left" valign="top" style="color:#1b77a6;font-weight:bold;">Load Port Cost</td>';
	for($i=0;$i<count($arr);$i++)
	{
		echo '<td align="center" width="37%" valign="top">'.$obj->getFCECostSheetPortDataBasedOnID($arr[$i],"fca_tci_load_port","PORT_COST").'</td>';
	}
	echo '</tr>';
	
	
	echo '<tr class="GridviewScrollItem" >';
	echo '<td align="left" valign="top" style="background-color:#DDDDDD;color:#1b77a6;font-weight:bold;">&nbsp;</td>';
	for($i=0;$i<count($arr);$i++)
	{
		echo '<td align="center" width="37%" valign="top" style="background-color:#DDDDDD;">&nbsp;</td>';
	}
	echo '</tr>';
	
	echo '<tr class="GridviewScrollItem" >';
	echo '<td align="left" valign="top" style="color:#1b77a6;font-weight:bold;">Discharge Port</td>';
	for($i=0;$i<count($arr);$i++)
	{
		echo '<td align="center" width="37%" valign="top">'.$obj->getFCECostSheetPortNameBasedOnID($arr[$i],"fca_tci_disch_port","DIS_PORT_ID").'</td>';
	}
	echo '</tr>';
	
	echo '<tr class="GridviewScrollItem" >';
	echo '<td align="left" valign="top" style="color:#1b77a6;font-weight:bold;">Discharge Rate <span style="font-size:10px; font-style:italic;">(MT/Day)</span></td>';
	for($i=0;$i<count($arr);$i++)
	{
		echo '<td align="center" width="37%" valign="top">'.$obj->getFCECostSheetPortDataBasedOnID($arr[$i],"fca_tci_disch_port","RATE").'</td>';
	}
	echo '</tr>';
	
	echo '<tr class="GridviewScrollItem" >';
	echo '<td align="left" valign="top" style="color:#1b77a6;font-weight:bold;">Discharge Port Cost</td>';
	for($i=0;$i<count($arr);$i++)
	{
		echo '<td align="center" width="37%" valign="top">'.$obj->getFCECostSheetPortDataBasedOnID($arr[$i],"fca_tci_disch_port","PORT_COST").'</td>';
	}
	echo '</tr>';
	
	echo '<tr class="GridviewScrollItem" >';
	echo '<td align="left" valign="top" style="background-color:#DDDDDD;color:#1b77a6;font-weight:bold;">&nbsp;</td>';
	for($i=0;$i<count($arr);$i++)
	{
		echo '<td align="center" width="37%" valign="top" style="background-color:#DDDDDD;">&nbsp;</td>';
	}
	echo '</tr>';
	
	echo '<tr class="GridviewScrollItem" >';
	echo '<td align="left" valign="top" style="color:#1b77a6;font-weight:bold;">Transit Port</td>';
	for($i=0;$i<count($arr);$i++)
	{
		echo '<td align="center" width="37%" valign="top">'.$obj->getFCECostSheetPortNameBasedOnID($arr[$i],"fca_tci_transit_port","LOAD_PORTID").'</td>';
	}
	echo '</tr>';
		
	echo '<tr class="GridviewScrollItem" >';
	echo '<td align="left" valign="top" style="color:#1b77a6;font-weight:bold;">Transit Port Cost</td>';
	for($i=0;$i<count($arr);$i++)
	{
		echo '<td align="center" width="37%" valign="top">'.$obj->getFCECostSheetPortDataBasedOnID($arr[$i],"fca_tci_transit_port","PORT_COST").'</td>';
	}
	echo '</tr>';
	
	
	echo '<tr class="GridviewScrollItem" >';
	echo '<td align="left" valign="top" style="background-color:#DDDDDD;color:#1b77a6;font-weight:bold;">&nbsp;</td>';
	for($i=0;$i<count($arr);$i++)
	{
		echo '<td align="center" width="37%" valign="top" style="background-color:#DDDDDD;">&nbsp;</td>';
	}
	echo '</tr>';
	
	
	echo '<tr class="GridviewScrollItem" >';
	echo '<td align="left" valign="top" style="color:#1b77a6;font-weight:bold;">TOTAL DAYS</td>';
	for($i=0;$i<count($arr);$i++)
	{
		echo '<td align="center" width="37%" valign="top">'.$obj->getFreightEstimationTotalRecords($arr[$i],"TTL_DAYS").'</td>';
	}
	echo '</tr>';
	
	echo '<tr class="GridviewScrollItem" >';
	echo '<td align="left" valign="top" style="color:#1b77a6;font-weight:bold;">Sea Days</td>';
	for($i=0;$i<count($arr);$i++)
	{
		echo '<td align="center" width="37%" valign="top">'.$obj->getFreightEstimationTotalRecords($arr[$i],"TTL_SEA_DAYS").'</td>';
	}
	echo '</tr>';
	
	echo '<tr class="GridviewScrollItem" >';
	echo '<td align="left" valign="top" style="color:#1b77a6;font-weight:bold;">Port Idle</td>';
	for($i=0;$i<count($arr);$i++)
	{
		echo '<td align="center" width="37%" valign="top">'.$obj->getFreightEstimationTotalRecords($arr[$i],"TTL_PORT_IDLE_DAYS").'</td>';
	}
	echo '</tr>';
	
	echo '<tr class="GridviewScrollItem" >';
	echo '<td align="left" valign="top" style="color:#1b77a6;font-weight:bold;">Port Working</td>';
	for($i=0;$i<count($arr);$i++)
	{
		echo '<td align="center" width="37%" valign="top">'.$obj->getFreightEstimationTotalRecords($arr[$i],"TTL_PORT_WORK_DAYS").'</td>';
	}
	echo '</tr>';
	
	echo '<tr class="GridviewScrollItem" >';
	echo '<td align="left" valign="top" style="background-color:#DDDDDD;color:#1b77a6;font-weight:bold;">&nbsp;</td>';
	for($i=0;$i<count($arr);$i++)
	{
		echo '<td align="center" width="37%" valign="top" style="background-color:#DDDDDD;">&nbsp;</td>';
	}
	echo '</tr>';
	
	
	echo '<tr class="GridviewScrollItem" >';
	echo '<td align="left" valign="top" style="color:#1b77a6;font-weight:bold;">FUEL DETAILS</td>';
	for($i=0;$i<count($arr);$i++)
	{
		echo '<td align="center" width="37%" valign="top">&nbsp;</td>';
	}
	echo '</tr>';
	
	echo '<tr class="GridviewScrollItem" >';
	echo '<td align="left" valign="top" style="color:#1b77a6;font-weight:bold;">FO Consp <span style="font-size:10px; font-style:italic;">(MT)</span></td>';
	for($i=0;$i<count($arr);$i++)
	{
		echo '<td align="center" width="37%" valign="top">'.$obj->getFreightEstimationTotalRecords($arr[$i],"TTL_FO_CONSP_MT").'</td>';
	}
	echo '</tr>';
	
	echo '<tr class="GridviewScrollItem" >';
	echo '<td align="left" valign="top" style="color:#1b77a6;font-weight:bold;">DO Consp <span style="font-size:10px; font-style:italic;">(MT)</span></td>';
	for($i=0;$i<count($arr);$i++)
	{
		echo '<td align="center" width="37%" valign="top">'.$obj->getFreightEstimationTotalRecords($arr[$i],"TTL_DO_CONSP_MT").'</td>';
	}
	echo '</tr>';
	
	echo '<tr class="GridviewScrollItem" >';
	echo '<td align="left" valign="top" style="color:#1b77a6;font-weight:bold;">FO Price <span style="font-size:10px; font-style:italic;">(USD/MT)</span></td>';
	for($i=0;$i<count($arr);$i++)
	{
		echo '<td align="center" width="37%" valign="top">'.$obj->getFoConspCostSheetDataBasedOnID($arr[$i],"EST_PRICE").'</td>';
	}
	echo '</tr>';
	
	echo '<tr class="GridviewScrollItem" >';
	echo '<td align="left" valign="top" style="color:#1b77a6;font-weight:bold;">DO Price <span style="font-size:10px; font-style:italic;">(USD/MT)</span></td>';
	for($i=0;$i<count($arr);$i++)
	{
		echo '<td align="center" width="37%" valign="top">'.$obj->getDoConspCostSheetDataBasedOnID($arr[$i],"EST_PRICE").'</td>';
	}
	echo '</tr>';
	
	echo '<tr class="GridviewScrollItem" >';
	echo '<td align="left" valign="top" style="color:#1b77a6;font-weight:bold;">Total Fuel Cost <span style="font-size:10px; font-style:italic;">(USD)</span></td>';
	for($i=0;$i<count($arr);$i++)
	{
		$ttl_fuel_cost = ($obj->getFoConspCostSheetDataBasedOnID($arr[$i],"EST_MT") * $obj->getFoConspCostSheetDataBasedOnID($arr[$i],"EST_PRICE")) + ($obj->getDoConspCostSheetDataBasedOnID($arr[$i],"EST_MT") * $obj->getDoConspCostSheetDataBasedOnID($arr[$i],"EST_PRICE"));
		echo '<td align="center" width="37%" valign="top">'.$ttl_fuel_cost.'</td>';
	}
	echo '</tr>';
	
	echo '<tr class="GridviewScrollItem" >';
	echo '<td align="left" valign="top" style="color:#1b77a6;font-weight:bold;">Total Related Cost <span style="font-size:10px; font-style:italic;">(USD)</span></td>';
	for($i=0;$i<count($arr);$i++)
	{
		echo '<td align="center" width="37%" valign="top">'.$obj->getFreightEstimationTotalRecords($arr[$i],"TTL_SHIPOWNER_EXP").'</td>';
	}
	echo '</tr>';
	
	echo '<tr class="GridviewScrollItem" >';
	echo '<td align="left" valign="top" style="color:#1b77a6;font-weight:bold;">Total Other Miscellaneous Cost <span style="font-size:10px; font-style:italic;">(USD)</span></td>';
	for($i=0;$i<count($arr);$i++)
	{
		echo '<td align="center" width="37%" valign="top">'.$obj->getOMCSumCostSheet($arr[$i]).'</td>';
	}
	echo '</tr>';
	
	echo '<tr class="GridviewScrollItem" >';
	echo '<td align="left" valign="top" style="background-color:#DDDDDD;color:#1b77a6;font-weight:bold;">&nbsp;</td>';
	for($i=0;$i<count($arr);$i++)
	{
		echo '<td align="center" width="37%" valign="top" style="background-color:#DDDDDD;">&nbsp;</td>';
	}
	echo '</tr>';
	
	
	echo '<tr class="GridviewScrollItem" >';
	echo '<td align="left" valign="top" style="color:#dc631e;font-weight:bold;">RESULTS</td>';
	for($i=0;$i<count($arr);$i++)
	{
		echo '<td align="center" width="37%" valign="top">&nbsp;</td>';
	}
	echo '</tr>';
	
	echo '<tr class="GridviewScrollItem" >';
	echo '<td align="left" valign="top" style="color:#1b77a6;font-weight:bold;">Revenue <span style="font-size:10px; font-style:italic;">(Final Nett Freight)</span></td>';
	for($i=0;$i<count($arr);$i++)
	{
		echo '<td align="center" width="37%" valign="top">'.$obj->getFreightEstimationTotalRecords($arr[$i],"REVENUE").'</td>';
	}
	echo '</tr>';
	
	
	
	echo '<tr class="GridviewScrollItem" >';
	echo '<td align="left" valign="top" style="color:#1b77a6;font-weight:bold;">Total Owners Expenses</td>';
	for($i=0;$i<count($arr);$i++)
	{
		echo '<td align="center" width="37%" valign="top">'.$obj->getFreightEstimationTotalRecords($arr[$i],"TTL_OWNER_EXP").'</td>';
	}
	echo '</tr>';
	
	echo '<tr class="GridviewScrollItem" >';
	echo '<td align="left" valign="top" style="color:#1b77a6;font-weight:bold;">Total Charterers &rsquo; Expenses</td>';
	for($i=0;$i<count($arr);$i++)
	{
		echo '<td align="center" width="37%" valign="top">'.$obj->getFreightEstimationTotalRecords($arr[$i],"TTL_CHARTERER_EXP").'</td>';
	}
	echo '</tr>';
	
	echo '<tr class="GridviewScrollItem" >';
	echo '<td align="left" valign="top" style="color:#1b77a6;font-weight:bold;">Voyage Earnings</td>';
	for($i=0;$i<count($arr);$i++)
	{
		echo '<td align="center" width="37%" valign="top">'.$obj->getFreightEstimationTotalRecords($arr[$i],"VOYAGE_EARNING").'</td>';
	}
	echo '</tr>';
	
	echo '<tr class="GridviewScrollItem" >';
	echo '<td align="left" valign="top" style="color:#dc631e;font-weight:bold;">Daily Earnings / TCE</td>';
	for($i=0;$i<count($arr);$i++)
	{
		echo '<td align="center" width="37%" valign="top">'.$obj->getFreightEstimationTotalRecords($arr[$i],"DAILY_EARNING").'</td>';
	}
	echo '</tr>';
	
	echo '<tr class="GridviewScrollItem" >';
	echo '<td align="left" valign="top" style="color:#1b77a6;font-weight:bold;">Daily Time Charter<span style="font-size:10px; font-style:italic;">(USD/Day)</span></td>';
	for($i=0;$i<count($arr);$i++)
	{
		echo '<td align="center" width="37%" valign="top">'.$obj->getFreightEstimationTotalRecords($arr[$i],"DAILY_VO_EXP").'</td>';
	}
	echo '</tr>';
	
	echo '<tr class="GridviewScrollItem" >';
	echo '<td align="left" valign="top" style="color:#1b77a6;font-weight:bold;">Hireage</td>';
	for($i=0;$i<count($arr);$i++)
	{
		echo '<td align="center" width="37%" valign="top">'.$obj->getFreightEstimationTotalRecords($arr[$i],"HIREAGE_AMT").'</td>';
	}
	echo '</tr>';
		
	echo '<tr class="GridviewScrollItem" >';
	echo '<td align="left" valign="top" style="color:#1b77a6;font-weight:bold;">Add Comm<span style="font-size:10px; font-style:italic;">(%)</span></td>';
	for($i=0;$i<count($arr);$i++)
	{
		echo '<td align="center" width="37%" valign="top">'.$obj->getFreightEstimationTotalRecords($arr[$i],"HIREAGE_PERCENT").'&nbsp;&nbsp;-&nbsp;&nbsp;'.$obj->getFreightEstimationTotalRecords($arr[$i],"HIREAGE_PER_AMT").'</td>';
	}
	echo '</tr>';
	
	echo '<tr class="GridviewScrollItem" >';
	echo '<td align="left" valign="top" style="color:#dc631e;font-weight:bold;">G Total Voyage Earnings <span style="font-size:10px; font-style:italic;">(Voyage Earnings + Demurrage)</span></td>';
	for($i=0;$i<count($arr);$i++)
	{
		echo '<td align="center" width="37%" valign="top">'.$obj->getFreightEstimationTotalRecords($arr[$i],"GRAND_TTL_VOYAGE_EARNING").'</td>';
	}
	echo '</tr>';
	
	echo '<tr class="GridviewScrollItem" >';
	echo '<td align="left" valign="top" style="color:#1b77a6;font-weight:bold;">Nett Hireage</td>';
	for($i=0;$i<count($arr);$i++)
	{
		echo '<td align="center" width="37%" valign="top">'.$obj->getFreightEstimationTotalRecords($arr[$i],"HIREAGE_NETT_AMT").'</td>';
	}
	echo '</tr>';
	
	echo '<tr class="GridviewScrollItem" >';
	echo '<td align="left" valign="top" style="color:#dc631e;font-weight:bold;">Nett Daily Earnings </td>';
	for($i=0;$i<count($arr);$i++)
	{
		echo '<td align="center" width="37%" valign="top">'.$obj->getFreightEstimationTotalRecords($arr[$i],"NETT_DAILY_EARNING").'</td>';
	}
	echo '</tr>';
	
		
	echo '<tr class="GridviewScrollItem" >';
	echo '<td align="left" valign="top" style="color:#dc631e;font-weight:bold;">Nett Daily Profit </td>';
	for($i=0;$i<count($arr);$i++)
	{
		echo '<td align="center" width="37%" valign="top">'.$obj->getFreightEstimationTotalRecords($arr[$i],"NETT_DAILY_PROFIT").'</td>';
	}
	echo '</tr>';
	
	echo '<tr class="GridviewScrollItem" >';
	echo '<td align="left" valign="top" style="color:#dc631e;font-weight:bold;">P / L </td>';
	for($i=0;$i<count($arr);$i++)
	{
		$pl = $obj->getFreightEstimationTotalRecords($arr[$i],"NETT_DAILY_PROFIT") * $obj->getFreightEstimationTotalRecords($arr[$i],"TTL_DAYS");
		echo '<td align="center" width="37%" valign="top">'.round($pl,2).'</td>';
	}
	echo '</tr>';
	
	echo '</table>';
}


/******************************End cost sheet compair pdf********************************/


function getVoyageFinancialsEstimatesComparisonData()
{
	$obj = new data();
	$connect=$obj->funConnect();
	$selVFEstimate = $_REQUEST['selVFEstimate'];
	$arr = explode(",",$selVFEstimate);
	
	echo '<a href="#Pdf" title="Pdf" onclick="getPdf();"><img src="../../img/pdf_button.png" width="25" height="25" /></a><br><br>';
	echo '<table cellspacing="0" class="table table-bordered table-striped dataTable" id="GridView1" style="width:100%;border-collapse:collapse;overflow:scroll;">';
	echo '<tr class="GridviewScrollHeader">';
	echo '<td align="left" valign="middle" class="input-text" style="font-size:12px; color:#fff; background-color:#1E85BE" >VOYAGE ESTIMATES</td>';
	for($i=0;$i<count($arr);$i++)
	{
		echo '<td align="left" width="37%" valign="middle" class="input-text" style="font-size:12px; color:#fff;background-color:#1E85BE;" >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'.$obj->getFreightCostEstimationTempleteData($arr[$i],"ESTIMATION_NO").' ('.$obj->getVesselIMOData($obj->getFreightCostEstimationTempleteData($arr[$i],"VESSEL_IMO_ID"),"VESSEL_NAME").')&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>';
	}	
	echo '</tr>';
	
	echo '<tr class="GridviewScrollItem" >';
	echo '<td align="left" valign="top" class="input-text" style="font-size:12px;color:#1b77a6;font-weight:bold;">Vessel Type</td>';
	for($i=0;$i<count($arr);$i++)
	{
		echo '<td align="center" width="37%" valign="top" class="input-text" style="font-size:12px;">'.$obj->getVesselTypeBasedOnID($obj->getVesselIMOData($obj->getFreightCostEstimationTempleteData($arr[$i],"VESSEL_IMO_ID"),"VESSEL_TYPE")).'</td>';
	}
	echo '</tr>';
	
	echo '<tr class="GridviewScrollItem" >';
	echo '<td align="left" valign="top" class="input-text" style="font-size:12px;color:#1b77a6;font-weight:bold;">Vessel Name</td>';
	for($i=0;$i<count($arr);$i++)
	{
		echo '<td align="center" width="37%" valign="top" class="input-text" style="font-size:12px;">'.$obj->getVesselIMOData($obj->getFreightCostEstimationTempleteData($arr[$i],"VESSEL_IMO_ID"),"VESSEL_NAME").'</td>';
	}
	echo '</tr>';
	
	echo '<tr class="GridviewScrollItem" >';
	echo '<td align="left" valign="top" class="input-text" style="font-size:12px;color:#1b77a6;font-weight:bold;">Date</td>';
	for($i=0;$i<count($arr);$i++)
	{
		echo '<td align="center" width="37%" valign="top" class="input-text" style="font-size:12px;">'.date("d M Y",strtotime($obj->getFreightCostEstimationTempleteData($arr[$i],"TRANS_DATE"))).'</td>';
	}
	echo '</tr>';
	
	echo '<tr class="GridviewScrollItem" >';
	echo '<td align="left" valign="top" class="input-text" style="font-size:12px;color:#1b77a6;font-weight:bold;">Voy No.</td>';
	for($i=0;$i<count($arr);$i++)
	{
		echo '<td align="center" width="37%" valign="top" class="input-text" style="font-size:12px;">'.$obj->getFreightCostEstimationTempleteData($arr[$i],"VOYAGE_NO").'</td>';
	}
	echo '</tr>';
	
	echo '<tr class="GridviewScrollItem" >';
	echo '<td align="left" valign="top" class="input-text" style="font-size:12px;color:#1b77a6;font-weight:bold;">DWT <span style="font-size:10px; font-style:italic;">(Summer)</span></td>';
	for($i=0;$i<count($arr);$i++)
	{
		echo '<td align="center" width="37%" valign="top" class="input-text" style="font-size:12px;">'.$obj->getVesselMaster1Data($obj->getFreightCostEstimationTempleteData($arr[$i],"VESSEL_IMO_ID"),"SUMMER_1").'</td>';
	}
	echo '</tr>';
	
	echo '<tr class="GridviewScrollItem" >';
	echo '<td align="left" valign="top" class="input-text" style="font-size:12px;color:#1b77a6;font-weight:bold;">Cargo Type / Cargo Name</td>';
	for($i=0;$i<count($arr);$i++)
	{
		echo '<td align="center" width="37%" valign="top" class="input-text" style="font-size:12px;">'.$obj->getCargoTypeNameBasedOnID($obj->getFreightCostEstimationTempleteData($arr[$i],"CARGO_TYPEID")).' / '.$obj->getMaterialCodeDesBasedOnId($obj->getFreightCostEstimationTempleteData($arr[$i],"MATERIALID")).'</td>';
	}
	echo '</tr>';
	
	echo '<tr class="GridviewScrollItem" >';
	echo '<td align="left" valign="top" class="input-text" style="font-size:12px;color:#1b77a6;font-weight:bold;">Cargo Qty <span style="font-size:10px; font-style:italic;">(MT)</span></td>';
	for($i=0;$i<count($arr);$i++)
	{
		echo '<td align="center" width="37%" valign="top" class="input-text" style="font-size:12px;">'.$obj->getFreightCostEstimationTempleteData($arr[$i],"CARGO_QTY").'</td>';
	}
	echo '</tr>';
	
		
	echo '<tr class="GridviewScrollItem" >';
	echo '<td align="left" valign="top" class="input-text" style="font-size:12px;color:#1b77a6;font-weight:bold;">&nbsp;</td>';
	for($i=0;$i<count($arr);$i++)
	{
		echo '<td align="center" width="37%" valign="top" class="input-text" style="font-size:12px;">&nbsp;</td>';
	}
	echo '</tr>';
	
	echo '<tr class="GridviewScrollItem" >';
	echo '<td align="left" valign="top" class="input-text" style="font-size:12px;color:#1b77a6;font-weight:bold;">Load Port</td>';
	for($i=0;$i<count($arr);$i++)
	{
		echo '<td align="center" width="37%" valign="top" class="input-text" style="font-size:12px;">'.$obj->getFCEPortNameBasedOnID($arr[$i],"fca_tci_tmp_load_port","LOADPORTID").'</td>';
	}
	echo '</tr>';
	
	echo '<tr class="GridviewScrollItem" >';
	echo '<td align="left" valign="top" class="input-text" style="font-size:12px;color:#1b77a6;font-weight:bold;">Load Rate <span style="font-size:10px; font-style:italic;">(MT/Day)</span></td>';
	for($i=0;$i<count($arr);$i++)
	{
		echo '<td align="center" width="37%" valign="top" class="input-text" style="font-size:12px;">'.$obj->getFCEPortDataBasedOnID($arr[$i],"fca_tci_tmp_load_port","RATE").'</td>';
	}
	echo '</tr>';
	
	echo '<tr class="GridviewScrollItem" >';
	echo '<td align="left" valign="top" class="input-text" style="font-size:12px;color:#1b77a6;font-weight:bold;">Load Port Cost</td>';
	for($i=0;$i<count($arr);$i++)
	{
		echo '<td align="center" width="37%" valign="top" class="input-text" style="font-size:12px;">'.$obj->getFCEPortDataBasedOnID($arr[$i],"fca_tci_tmp_load_port","PORT_COST").'</td>';
	}
	echo '</tr>';
	
	
	echo '<tr class="GridviewScrollItem" >';
	echo '<td align="left" valign="top" class="input-text" style="font-size:12px;color:#1b77a6;font-weight:bold;">&nbsp;</td>';
	for($i=0;$i<count($arr);$i++)
	{
		echo '<td align="center" width="37%" valign="top" class="input-text" style="font-size:12px;">&nbsp;</td>';
	}
	echo '</tr>';
	
	echo '<tr class="GridviewScrollItem" >';
	echo '<td align="left" valign="top" class="input-text" style="font-size:12px;color:#1b77a6;font-weight:bold;">Discharge Port</td>';
	for($i=0;$i<count($arr);$i++)
	{
		echo '<td align="center" width="37%" valign="top" class="input-text" style="font-size:12px;">'.$obj->getFCEPortNameBasedOnID($arr[$i],"fca_tci_tmp_disch_port","DIS_PORT_ID").'</td>';
	}
	echo '</tr>';
	
	echo '<tr class="GridviewScrollItem" >';
	echo '<td align="left" valign="top" class="input-text" style="font-size:12px;color:#1b77a6;font-weight:bold;">Discharge Rate <span style="font-size:10px; font-style:italic;">(MT/Day)</span></td>';
	for($i=0;$i<count($arr);$i++)
	{
		echo '<td align="center" width="37%" valign="top" class="input-text" style="font-size:12px;">'.$obj->getFCEPortDataBasedOnID($arr[$i],"fca_tci_tmp_disch_port","RATE").'</td>';
	}
	echo '</tr>';
	
	echo '<tr class="GridviewScrollItem" >';
	echo '<td align="left" valign="top" class="input-text" style="font-size:12px;color:#1b77a6;font-weight:bold;">Discharge Port Cost</td>';
	for($i=0;$i<count($arr);$i++)
	{
		echo '<td align="center" width="37%" valign="top" class="input-text" style="font-size:12px;">'.$obj->getFCEPortDataBasedOnID($arr[$i],"fca_tci_tmp_disch_port","PORT_COST").'</td>';
	}
	echo '</tr>';
	
	echo '<tr class="GridviewScrollItem" >';
	echo '<td align="left" valign="top" class="input-text" style="font-size:12px;color:#1b77a6;font-weight:bold;">&nbsp;</td>';
	for($i=0;$i<count($arr);$i++)
	{
		echo '<td align="center" width="37%" valign="top" class="input-text" style="font-size:12px;">&nbsp;</td>';
	}
	echo '</tr>';
	
	echo '<tr class="GridviewScrollItem" >';
	echo '<td align="left" valign="top" class="input-text" style="font-size:12px;color:#1b77a6;font-weight:bold;">Transit Port</td>';
	for($i=0;$i<count($arr);$i++)
	{
		echo '<td align="center" width="37%" valign="top" class="input-text" style="font-size:12px;">'.$obj->getFCEPortNameBasedOnID($arr[$i],"fca_tci_tmp_transit_port","LOAD_PORTID").'</td>';
	}
	echo '</tr>';
		
	echo '<tr class="GridviewScrollItem" >';
	echo '<td align="left" valign="top" class="input-text" style="font-size:12px;color:#1b77a6;font-weight:bold;">Transit Port Cost</td>';
	for($i=0;$i<count($arr);$i++)
	{
		echo '<td align="center" width="37%" valign="top" class="input-text" style="font-size:12px;">'.$obj->getFCEPortDataBasedOnID($arr[$i],"fca_tci_tmp_transit_port","PORT_COST").'</td>';
	}
	echo '</tr>';
	
	
	echo '<tr class="GridviewScrollItem" >';
	echo '<td align="left" valign="top" class="input-text" style="font-size:12px;color:#1b77a6;font-weight:bold;">&nbsp;</td>';
	for($i=0;$i<count($arr);$i++)
	{
		echo '<td align="center" width="37%" valign="top" class="input-text" style="font-size:12px;">&nbsp;</td>';
	}
	echo '</tr>';
	
	
	echo '<tr class="GridviewScrollItem" >';
	echo '<td align="left" valign="top" class="input-text" style="font-size:12px;color:#1b77a6;font-weight:bold;">TOTAL DAYS</td>';
	for($i=0;$i<count($arr);$i++)
	{
		echo '<td align="center" width="37%" valign="top" class="input-text" style="font-size:12px;">'.$obj->getFreightCostEstimationTempleteTotalRecords($arr[$i],"TTL_DAYS").'</td>';
	}
	echo '</tr>';
	
	echo '<tr class="GridviewScrollItem" >';
	echo '<td align="left" valign="top" class="input-text" style="font-size:12px;color:#1b77a6;font-weight:bold;">Sea Days</td>';
	for($i=0;$i<count($arr);$i++)
	{
		echo '<td align="center" width="37%" valign="top" class="input-text" style="font-size:12px;">'.$obj->getFreightCostEstimationTempleteTotalRecords($arr[$i],"TTL_SEA_DAYS").'</td>';
	}
	echo '</tr>';
	
	echo '<tr class="GridviewScrollItem" >';
	echo '<td align="left" valign="top" class="input-text" style="font-size:12px;color:#1b77a6;font-weight:bold;">Port Idle</td>';
	for($i=0;$i<count($arr);$i++)
	{
		echo '<td align="center" width="37%" valign="top" class="input-text" style="font-size:12px;">'.$obj->getFreightCostEstimationTempleteTotalRecords($arr[$i],"TTL_PORT_IDLE_DAYS").'</td>';
	}
	echo '</tr>';
	
	echo '<tr class="GridviewScrollItem" >';
	echo '<td align="left" valign="top" class="input-text" style="font-size:12px;color:#1b77a6;font-weight:bold;">Port Working</td>';
	for($i=0;$i<count($arr);$i++)
	{
		echo '<td align="center" width="37%" valign="top" class="input-text" style="font-size:12px;">'.$obj->getFreightCostEstimationTempleteTotalRecords($arr[$i],"TTL_PORT_WORK_DAYS").'</td>';
	}
	echo '</tr>';
	
	echo '<tr class="GridviewScrollItem" >';
	echo '<td align="left" valign="top" class="input-text" style="font-size:12px;color:#1b77a6;font-weight:bold;">&nbsp;</td>';
	for($i=0;$i<count($arr);$i++)
	{
		echo '<td align="center" width="37%" valign="top" class="input-text" style="font-size:12px;">&nbsp;</td>';
	}
	echo '</tr>';
	
	
	echo '<tr class="GridviewScrollItem" >';
	echo '<td align="left" valign="top" class="input-text" style="font-size:14px;color:#1b77a6;font-weight:bold;">FUEL DETAILS</td>';
	for($i=0;$i<count($arr);$i++)
	{
		echo '<td align="center" width="37%" valign="top" class="input-text" style="font-size:12px;">&nbsp;</td>';
	}
	echo '</tr>';
	
	echo '<tr class="GridviewScrollItem" >';
	echo '<td align="left" valign="top" class="input-text" style="font-size:12px;color:#1b77a6;font-weight:bold;">FO Consp <span style="font-size:10px; font-style:italic;">(MT)</span></td>';
	for($i=0;$i<count($arr);$i++)
	{
		echo '<td align="center" width="37%" valign="top" class="input-text" style="font-size:12px;">'.$obj->getFreightCostEstimationTempleteTotalRecords($arr[$i],"TTL_FO_CONSP_MT").'</td>';
	}
	echo '</tr>';
	
	echo '<tr class="GridviewScrollItem" >';
	echo '<td align="left" valign="top" class="input-text" style="font-size:12px;color:#1b77a6;font-weight:bold;">DO Consp <span style="font-size:10px; font-style:italic;">(MT)</span></td>';
	for($i=0;$i<count($arr);$i++)
	{
		echo '<td align="center" width="37%" valign="top" class="input-text" style="font-size:12px;">'.$obj->getFreightCostEstimationTempleteTotalRecords($arr[$i],"TTL_DO_CONSP_MT").'</td>';
	}
	echo '</tr>';
	
	echo '<tr class="GridviewScrollItem" >';
	echo '<td align="left" valign="top" class="input-text" style="font-size:12px;color:#1b77a6;font-weight:bold;">FO Price <span style="font-size:10px; font-style:italic;">(USD/MT)</span></td>';
	for($i=0;$i<count($arr);$i++)
	{
		echo '<td align="center" width="37%" valign="top" class="input-text" style="font-size:12px;">'.$obj->getFoConspDataBasedOnID($arr[$i],"EST_PRICE").'</td>';
	}
	echo '</tr>';
	
	echo '<tr class="GridviewScrollItem" >';
	echo '<td align="left" valign="top" class="input-text" style="font-size:12px;color:#1b77a6;font-weight:bold;">DO Price <span style="font-size:10px; font-style:italic;">(USD/MT)</span></td>';
	for($i=0;$i<count($arr);$i++)
	{
		echo '<td align="center" width="37%" valign="top" class="input-text" style="font-size:12px;">'.$obj->getDoConspDataBasedOnID($arr[$i],"EST_PRICE").'</td>';
	}
	echo '</tr>';
	
	echo '<tr class="GridviewScrollItem" >';
	echo '<td align="left" valign="top" class="input-text" style="font-size:12px;color:#1b77a6;font-weight:bold;">Total Fuel Cost <span style="font-size:10px; font-style:italic;">(USD)</span></td>';
	for($i=0;$i<count($arr);$i++)
	{
		$ttl_fuel_cost = ($obj->getFoConspDataBasedOnID($arr[$i],"EST_MT") * $obj->getFoConspDataBasedOnID($arr[$i],"EST_PRICE")) + ($obj->getDoConspDataBasedOnID($arr[$i],"EST_MT") * $obj->getDoConspDataBasedOnID($arr[$i],"EST_PRICE"));
		echo '<td align="center" width="37%" valign="top" class="input-text" style="font-size:12px;">'.$ttl_fuel_cost.'</td>';
	}
	echo '</tr>';
	
	echo '<tr class="GridviewScrollItem" >';
	echo '<td align="left" valign="top" class="input-text" style="font-size:12px;color:#1b77a6;font-weight:bold;">Total Owner Related Cost <span style="font-size:10px; font-style:italic;">(USD)</span></td>';
	for($i=0;$i<count($arr);$i++)
	{
		echo '<td align="center" width="37%" valign="top" class="input-text" style="font-size:12px;">'.$obj->getFreightCostEstimationTempleteTotalRecords($arr[$i],"TTL_SHIPOWNER_EXP").'</td>';
	}
	echo '</tr>';
	
	echo '<tr class="GridviewScrollItem" >';
	echo '<td align="left" valign="top" class="input-text" style="font-size:12px;color:#1b77a6;font-weight:bold;">Total Other Shipping Cost <span style="font-size:10px; font-style:italic;">(USD)</span></td>';
	for($i=0;$i<count($arr);$i++)
	{
		echo '<td align="center" width="37%" valign="top" class="input-text" style="font-size:12px;">'.$obj->getOSCSumTMP($arr[$i]).'</td>';
	}
	echo '</tr>';
	
	echo '<tr class="GridviewScrollItem" >';
	echo '<td align="left" valign="top" class="input-text" style="font-size:12px;color:#1b77a6;font-weight:bold;">Total Other Miscellaneous Cost <span style="font-size:10px; font-style:italic;">(USD)</span></td>';
	for($i=0;$i<count($arr);$i++)
	{
		echo '<td align="center" width="37%" valign="top" class="input-text" style="font-size:12px;">'.$obj->getOMCSumTMP($arr[$i]).'</td>';
	}
	echo '</tr>';
	
	echo '<tr class="GridviewScrollItem" >';
	echo '<td align="left" valign="top" class="input-text" style="font-size:12px;color:#1b77a6;font-weight:bold;">&nbsp;</td>';
	for($i=0;$i<count($arr);$i++)
	{
		echo '<td align="center" width="37%" valign="top" class="input-text" style="font-size:12px;">&nbsp;</td>';
	}
	echo '</tr>';
	
	
	echo '<tr class="GridviewScrollItem" >';
	echo '<td align="left" valign="top" class="input-text" style="font-size:14px;color:#dc631e;font-weight:bold;">RESULTS</td>';
	for($i=0;$i<count($arr);$i++)
	{
		echo '<td align="center" width="37%" valign="top" class="input-text" style="font-size:12px;">&nbsp;</td>';
	}
	echo '</tr>';
	
	echo '<tr class="GridviewScrollItem" >';
	echo '<td align="left" valign="top" class="input-text" style="font-size:12px;color:#888;font-weight:bold;">Revenue <span style="font-size:10px; font-style:italic;">(Final Nett Freight)</span></td>';
	for($i=0;$i<count($arr);$i++)
	{
		echo '<td align="center" width="37%" valign="top" class="input-text" style="font-size:12px;">'.$obj->getFreightCostEstimationTempleteTotalRecords($arr[$i],"REVENUE").'</td>';
	}
	echo '</tr>';
	
	
	
	echo '<tr class="GridviewScrollItem" >';
	echo '<td align="left" valign="top" class="input-text" style="font-size:12px;color:#888;font-weight:bold;">Total Owners Expenses</td>';
	for($i=0;$i<count($arr);$i++)
	{
		echo '<td align="center" width="37%" valign="top" class="input-text" style="font-size:12px;">'.$obj->getFreightCostEstimationTempleteTotalRecords($arr[$i],"TTL_OWNER_EXP").'</td>';
	}
	echo '</tr>';
	
	echo '<tr class="GridviewScrollItem" >';
	echo '<td align="left" valign="top" class="input-text" style="font-size:12px;color:#888;font-weight:bold;">Total Charterers &rsquo; Expenses</td>';
	for($i=0;$i<count($arr);$i++)
	{
		echo '<td align="center" width="37%" valign="top" class="input-text" style="font-size:12px;">'.$obj->getFreightCostEstimationTempleteTotalRecords($arr[$i],"TTL_CHARTERER_EXP").'</td>';
	}
	echo '</tr>';
	
	echo '<tr class="GridviewScrollItem" >';
	echo '<td align="left" valign="top" class="input-text" style="font-size:12px;color:#888;font-weight:bold;">Voyage Earnings</td>';
	for($i=0;$i<count($arr);$i++)
	{
		echo '<td align="center" width="37%" valign="top" class="input-text" style="font-size:12px;">'.$obj->getFreightCostEstimationTempleteTotalRecords($arr[$i],"VOYAGE_EARNING").'</td>';
	}
	echo '</tr>';
	
	echo '<tr class="GridviewScrollItem" >';
	echo '<td align="left" valign="top" class="input-text" style="font-size:12px;color:#dc631e;font-weight:bold;">Daily Earnings / TCE</td>';
	for($i=0;$i<count($arr);$i++)
	{
		echo '<td align="center" width="37%" valign="top" class="input-text" style="font-size:12px;">'.$obj->getFreightCostEstimationTempleteTotalRecords($arr[$i],"DAILY_EARNING").'</td>';
	}
	echo '</tr>';
	
	echo '<tr class="GridviewScrollItem" >';
	echo '<td align="left" valign="top" class="input-text" style="font-size:12px;color:#888;font-weight:bold;">Daily Time Charter<span style="font-size:10px; font-style:italic;">(USD/Day)</span></td>';
	for($i=0;$i<count($arr);$i++)
	{
		echo '<td align="center" width="37%" valign="top" class="input-text" style="font-size:12px;">'.$obj->getFreightCostEstimationTempleteTotalRecords($arr[$i],"DAILY_VO_EXP").'</td>';
	}
	echo '</tr>';
	
	echo '<tr class="GridviewScrollItem" >';
	echo '<td align="left" valign="top" class="input-text" style="font-size:12px;color:#dc631e;font-weight:bold;">G Total Voyage Earnings <span style="font-size:10px; font-style:italic;">(Voyage Earnings + Demurrage)</span></td>';
	for($i=0;$i<count($arr);$i++)
	{
		echo '<td align="center" width="37%" valign="top" class="input-text" style="font-size:12px;">'.$obj->getFreightCostEstimationTempleteTotalRecords($arr[$i],"GRAND_TTL_VOYAGE_EARNING").'</td>';
	}
	echo '</tr>';
	
	echo '<tr class="GridviewScrollItem" >';
	echo '<td align="left" valign="top" class="input-text" style="font-size:12px;color:#dc631e;font-weight:bold;">Nett Daily Earnings </td>';
	for($i=0;$i<count($arr);$i++)
	{
		echo '<td align="center" width="37%" valign="top" class="input-text" style="font-size:12px;">'.$obj->getFreightCostEstimationTempleteTotalRecords($arr[$i],"NETT_DAILY_EARNING").'</td>';
	}
	echo '</tr>';
	
	echo '<tr class="GridviewScrollItem" >';
	echo '<td align="left" valign="top" class="input-text" style="font-size:12px;color:#dc631e;font-weight:bold;">Nett Daily Profit </td>';
	for($i=0;$i<count($arr);$i++)
	{
		echo '<td align="center" width="37%" valign="top" class="input-text" style="font-size:12px;">'.$obj->getFreightCostEstimationTempleteTotalRecords($arr[$i],"NETT_DAILY_PROFIT").'</td>';
	}
	echo '</tr>';
	
	echo '<tr class="GridviewScrollItem" >';
	echo '<td align="left" valign="top" class="input-text" style="font-size:12px;color:#dc631e;font-weight:bold;">P / L </td>';
	for($i=0;$i<count($arr);$i++)
	{
		echo '<td align="center" width="37%" valign="top" class="input-text" style="font-size:12px;">'.$obj->getFreightCostEstimationTempleteTotalRecords($arr[$i],"PL").'</td>';
	}
	echo '</tr>';
	
	echo '</table>';
	
}

function getVesselRelatedData()
{
	$obj = new data();
	$connect=$obj->funConnect();
	$selVName = $_REQUEST['selVName'];
	
	$query = "select * from vessel_commercial_parameters where VESSEL_IMO_ID='".$selVName."' and MODULEID='".$_SESSION['moduleid']."'";
	$res = mysql_query($query);
	$rec = mysql_num_rows($res);
	
	
	if($obj->getVesselMaster1Data($selVName,"SUMMER_1") == ""){$dwt_sum = "0.0";}else{$dwt_sum = $obj->getVesselMaster1Data($selVName,"SUMMER_1");}
	if($obj->getVesselMaster1Data($selVName,"TROPICAL_1") == ""){$dwt_trop = "0.0";}else{$dwt_trop = $obj->getVesselMaster1Data($selVName,"TROPICAL_1");}
	if($obj->getVesselMaster8Data($selVName,"GRAIN") == ""){$grain = "0.0";}else{$grain = $obj->getVesselMaster8Data($selVName,"GRAIN");}
	if($obj->getVesselMaster8Data($selVName,"BALE") == ""){$bale = "0.0";}else{$bale = $obj->getVesselMaster8Data($selVName,"BALE");}
	
	if(is_null($obj->getVesselIMOData($selVName,"EXTERNAL_VESSEL_ID")))
	{
		$vesselid = $selVName;
		$user = "";
	}
	else
	{
		$vesselid = $obj->getVesselIMOData($selVName,"EXTERNAL_VESSEL_ID");
		$user = "EXTERNAL_USER";
	}
	
	
	$b_full_speed = $obj->getVesselParameterData($vesselid,"B_FULL_SPEED",$user);
	if($b_full_speed == "" ){$bfs = 0;}else{$bfs = $b_full_speed;}
	$b_ech_speed1 = $obj->getVesselParameterData($vesselid,"B_ECO_SPEED1",$user);
	if($b_ech_speed1 == "" ){$bes1 = 0;}else{$bes1 = $b_ech_speed1;}
	$b_ech_speed2 = $obj->getVesselParameterData($vesselid,"B_ECO_SPEED2",$user);
	if($b_ech_speed2 == "" ){$bes2 = 0;}else{$bes2 = $b_ech_speed2;}
	$fo_b_full_speed = $obj->getVesselParameterData($vesselid,"BP_FO_FULL_SPEED",$user);
	if($fo_b_full_speed == ""){$fo_bfs = 0;}else{$fo_bfs = $fo_b_full_speed;}
	$fo_b_ech_speed1 = $obj->getVesselParameterData($vesselid,"BP_FO_ECO_SPEED1",$user);
	if($fo_b_ech_speed1 == ""){$fo_bes1 = 0;}else{$fo_bes1 = $fo_b_ech_speed1;}
	$fo_b_ech_speed2 = $obj->getVesselParameterData($vesselid,"BP_FO_ECO_SPEED2",$user);
	if($fo_b_ech_speed2 == ""){$fo_bes2 = 0;}else{$fo_bes2 = $fo_b_ech_speed2;}
	$do_b_full_speed = $obj->getVesselParameterData($vesselid,"BP_DO_FULL_SPEED",$user);
	if($do_b_full_speed == ""){$do_bfs = 0;}else{$do_bfs = $do_b_full_speed;}
	$do_b_ech_speed1 = $obj->getVesselParameterData($vesselid,"BP_DO_ECO_SPEED1",$user);
	if($do_b_ech_speed1 == ""){$do_bes1 = 0;}else{$do_bes1 = $do_b_ech_speed1;}
	$do_b_ech_speed2 = $obj->getVesselParameterData($vesselid,"BP_DO_ECO_SPEED2",$user);
	if($do_b_ech_speed2 == ""){$do_bes2 = 0;}else{$do_bes2 = $do_b_ech_speed2;}
	
	$l_full_speed = $obj->getVesselParameterData($vesselid,"L_FULL_SPEED",$user);
	if($l_full_speed == "" ){$lfs = 0;}else{$lfs = $l_full_speed;}
	$l_ech_speed1 = $obj->getVesselParameterData($vesselid,"L_ECO_SPEED1",$user);
	if($l_ech_speed1 == "" ){$les1 = 0;}else{$les1 = $l_ech_speed1;}
	$l_ech_speed2 = $obj->getVesselParameterData($vesselid,"L_ECO_SPEED2",$user);
	if($l_ech_speed2 == "" ){$les2 = 0;}else{$les2 = $l_ech_speed2;}
	$fo_l_full_speed = $obj->getVesselParameterData($vesselid,"LP_FO_FULL_SPEED",$user);
	if($fo_l_full_speed == ""){$fo_lfs = 0;}else{$fo_lfs = $fo_l_full_speed;}
	$fo_l_ech_speed1 = $obj->getVesselParameterData($vesselid,"LP_FO_ECO_SPEED1",$user);
	if($fo_l_ech_speed1 == ""){$fo_les1 = 0;}else{$fo_les1 = $fo_l_ech_speed1;}
	$fo_l_ech_speed2 = $obj->getVesselParameterData($vesselid,"LP_FO_ECO_SPEED2",$user);
	if($fo_l_ech_speed2 == ""){$fo_les2 = 0;}else{$fo_les2 = $fo_l_ech_speed2;}
	$do_l_full_speed = $obj->getVesselParameterData($vesselid,"LP_DO_FULL_SPEED",$user);
	if($do_l_full_speed == ""){$do_lfs = 0;}else{$do_lfs = $do_l_full_speed;}
	$do_l_ech_speed1 = $obj->getVesselParameterData($vesselid,"LP_DO_ECO_SPEED1",$user);
	if($do_l_ech_speed1 == ""){$do_les1 = 0;}else{$do_les1 = $do_l_ech_speed1;}
	$do_l_ech_speed2 = $obj->getVesselParameterData($vesselid,"LP_DO_ECO_SPEED2",$user);
	if($do_l_ech_speed2 == ""){$do_les2 = 0;}else{$do_les2 = $do_l_ech_speed2;}
	
	$fo_inport_idle = $obj->getVesselParameterData($vesselid,"PI_FO_FULL_SPEED",$user);
	if($fo_inport_idle == ""){$foidle = 0;}else{$foidle = $fo_inport_idle;}
	$fo_inport_wrking = $obj->getVesselParameterData($vesselid,"PW_FO_FULL_SPEED",$user);
	if($fo_inport_wrking == ""){$fowrking = 0;}else{$fowrking = $fo_inport_wrking;}
	
	$do_inport_idle = $obj->getVesselParameterData($vesselid,"PI_DO_FULL_SPEED",$user);
	if($do_inport_idle == ""){$doidle = 0;}else{$doidle = $do_inport_idle;}
	$do_inport_wrking = $obj->getVesselParameterData($vesselid,"PW_DO_FULL_SPEED",$user);
	if($do_inport_wrking == ""){$dowrking = 0;}else{$dowrking = $do_inport_wrking;}
	
	if($rec == 0){$vesselrecord = 0;}else{$vesselrecord = $rec;}
	
	echo $obj->getVesselTypeBasedOnID($obj->getVesselIMOData($selVName,"VESSEL_TYPE"))."#".$dwt_sum."#".$dwt_trop."#".$grain."#".$bale."#".$bfs."#".$bes1."#".$bes2."#".$fo_bfs."#".$fo_bes1."#".$fo_bes2."#".$do_bfs."#".$do_bes1."#".$do_bes2."#".$lfs."#".$les1."#".$les2."#".$fo_lfs."#".$fo_les1."#".$fo_les2."#".$do_lfs."#".$do_les1."#".$do_les2."#".$foidle."#".$fowrking."#".$doidle."#".$dowrking."#".$vesselrecord;
}


function getVoyageEstimatesData()
{
	$obj = new data();
	$connect=$obj->funConnect();
	$selVName = $_REQUEST['selVName'];
	$selSheetName = $_REQUEST['selSheetName'];
	
	$sql = "select * from freight_cost_analysis_tmp_master WHERE MODULEID='".$_SESSION['moduleid']."' AND MCOMPANYID='".$_SESSION['company']."' ";
	if($selVName != "")
	{
		$sql.= " and VESSEL_IMO_ID = '".$selVName."'  ";
	}
	if($selSheetName != "")
	{
		$sql.= " and FCATMPID = '".$selSheetName."'  ";
	}
	$sql.= "order by FCATMPID desc";
	
	$res = mysql_query($sql);
	$rec = mysql_num_rows($res);
	$i = 1;
	if($rec == 0)
	{
		echo '<tr>';
		echo '<td align="center" colspan="6" valign="middle" style="color:#ff0000;letter-spacing:1px;">'.strtoupper("Sorry Currently there are zero(0) records").'</td>';
		echo '</tr>';
	}
	else{ 
		while($rows = mysql_fetch_assoc($res))
			{
				echo '<tr>';
				echo '<td align="center" valign="middle" class="input-text">'.$i.'.</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['ESTIMATION_NO'].'</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$obj->getVesselIMOData($rows['VESSEL_IMO_ID'],"VESSEL_NAME").'</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$obj->getFreightFixtureBasedOnID($rows['FIXTURETYPEID']).'</td>';
				echo '<td align="center" valign="middle" class="input-text"><a href="sensitivity_analysis_tmp.php?id='.$rows['FCATMPID'].'" title="Sensitivity Analysis" >SA</a></td>';
				echo '<td align="center" valign="middle" class="input-text"><a href="allPdf.php?id=13&fca_tmpid='.$rows['FCATMPID'].'" title="Pdf Details" ><img src="../../img/pdf_button.png" width="14" height="14" /></a>&nbsp;|&nbsp;<a href="updatefce.php?id='.$rows['FCATMPID'].'" title="Edit Details" ><i class="fa fa-edit "></i></a>&nbsp;|&nbsp;<a title="Delete Link" href="#Delete" onclick="return getDelete('.$rows['FCATMPID'].');" ><i class="fa fa-times" style="color:red;"></i></a></td>';	
				echo '</tr>';
				$i++;
		}
	}
}

function redirectURLLaytimeLoadPort()
{
	$obj 			= new data();
	$connect		= $obj->funConnect();
	$laytime_lp_id 	= $_REQUEST['laytime_lp_id'];
	
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
	$msg = 0;
	
	$delquery1 = "delete from laytime_loadport_master where LAYTIME_LP_ID='".$laytime_lp_id."'";
	$delquery2 = "delete from laytime_loadport_slave where LAYTIME_LP_ID='".$laytime_lp_id."'";
	mysql_query($delquery1);
	mysql_query($delquery2);
	mysql_query("commit");
	
	echo $msg;
}





function getAgingReceivablesReport()
{
	$obj 			= new data();
	$connect		= $obj->funConnect();
	
	$selVendor      = $_REQUEST['selVendor'];
	$selBType    	= $_REQUEST['selBType'];
	$selDate_Type 	= $_REQUEST['selDate_Type'];
	
	$var = '';
	if($selDate_Type == 1)
	{
	    $var = 1;
	}
	else if($selDate_Type == 2)
	{
	    $from_date = date('Y-m-d',strtotime('-30 days'));
	    $to_date = date('Y-m-d',time());
		$var = 2;
	}
	else if($selDate_Type == 3)
	{
        $from_date = date('Y-m-d',strtotime('-60 days'));
	    $to_date = date('Y-m-d',strtotime('-30 days'));	
		$var = 2;
	}
	else if($selDate_Type == 4)
	{
	    $from_date = date('Y-m-d',strtotime('-90 days'));
	    $to_date = date('Y-m-d',strtotime('-60 days'));	
		$var = 2;
	}
	else if($selDate_Type == 5)
	{
	    $from_date = date('Y-m-d',strtotime('-90 days'));
		$var = 3;
	}
	
	
	echo '<table id="aging_report_list" class="table table-bordered table-striped dataTable" >
			<thead>
				<tr>
					<th align="left" width="5%">Sr. No.</th>
					<th align="left" width="10%">Vendor</th>
					<th align="left" width="10%">Nom Id</th>
					<th align="left" width="9%">Vessel</th>
					<th align="left" width="9%">CP Date</th>									
					<th align="left" width="9%">Cost Type</th>
					<th align="left" width="9%">Bill Date</th>
					<th align="left" width="10%">Amount Billed</th>
					<th align="left" width="10%">Amount Received</th>
					<th align="left" width="10%">Difference</th>
					<th align="left" width="9">Delay (Days)</th>
				</tr>
			</thead>
			<tbody>';
	$sql = "select * from freight_cost_estimate_compare inner join freight_cost_estimete_master on freight_cost_estimete_master.FCAID= freight_cost_estimate_compare.FCAID WHERE freight_cost_estimate_compare.MODULEID='".$_SESSION['moduleid']."' AND freight_cost_estimate_compare.MCOMPANYID='".$_SESSION['company']."' and freight_cost_estimate_compare.FINAL_ID!='' and freight_cost_estimete_master.FIXED=1 and freight_cost_estimate_compare.STATUS in (1,2) and freight_cost_estimete_master.ESTIMATE_TYPE='".$selBType."' order by freight_cost_estimate_compare.COMID desc";
	$res = mysql_query($sql);
	$rec = mysql_num_rows($res);
	$i = 1;
	if($rec == 0)
	{
		
	}
	else
	{	
		while($rows = mysql_fetch_assoc($res))
		{		
		    $fcaid = $obj->getLatestCostSheetID($rows['COMID']);
			$obj->viewFreightCostEstimationTempleteRecordsNew($fcaid);
			if($var == 1)
			{
				$sql1 = "select * from dumerage_invoice_master where ".(($_REQUEST['selVendor']!='')?"VENDOR='".$selVendor."' and ":"")." COMID='".$rows['COMID']."'";
			}
			else if($var == 2)
			{
				$sql1 = "select * from dumerage_invoice_master where ".(($_REQUEST['selVendor']!='')?"VENDOR='".$selVendor."' and ":"")." (DATE BETWEEN '".date("Y-m-d",strtotime($from_date))."' and '".date("Y-m-d",strtotime($to_date))."')  and COMID='".$rows['COMID']."' ";
			}
			else if($var == 3)
			{
				$sql1 = "select * from dumerage_invoice_master where ".(($_REQUEST['selVendor']!='')?"VENDOR='".$selVendor."' and ":"")." DATE<'".date("Y-m-d",strtotime($from_date))."'  and COMID='".$rows['COMID']."' ";
			}
			$res1 = mysql_query($sql1) or die($sql1);
			while ($rows1 = mysql_fetch_assoc($res1))
			{
				$invoice_amt= $rows1['NET_AMT'];
				$amt_paid = $rows1['P_AMT'];
				$diff = $invoice_amt - $amt_paid;
				$cost_type = 'Demurrage Dispatch Ship Owner - '.$obj->getPortNameBasedOnID($rows1['PORTID']).' ('.$rows1['PORT_TYPE'].')';
				$start = strtotime($rows1['DATE']);
				$end = strtotime(date('Y-m-d',time()));
				$delay_days = ceil(abs($end - $start) / 86400);
				if($rows1['VENDOR']!="")
				{
					echo '<tr>';
					echo '<td align="left" valign="middle">'.$i.'.</td>';
					echo '<td align="left" valign="middle">'.$obj->getVendorListNewBasedOnID($rows1['VENDOR']).'</td>';
					echo '<td align="left" valign="middle">'.$obj->getCompareTableData($rows['COMID'],"MESSAGE").'</td>';
					echo '<td align="left" valign="middle">'.$obj->getVesselIMOData($obj->getCompareEstimateData($rows['COMID'],"VESSEL_IMO_ID"),"VESSEL_NAME").'</td>';
					echo '<td align="left" valign="middle">'.(($obj->getFun112()=='' || $obj->getFun112()=='0000-00-00' || $obj->getFun112()=='1970-01-01')?'':date("d-m-Y",strtotime($obj->getFun112()))).'</td>';
					echo '<td align="left" valign="middle">'.$cost_type.'</td>';
					echo '<td align="left" valign="middle">'.date("d-m-Y",strtotime($rows1['DATE'])).'</td>';
					echo '<td align="left" valign="middle">'.$obj->getNumberFormat($invoice_amt).'</td>';
					echo '<td align="left" valign="middle">'.$obj->getNumberFormat($amt_paid).'</td>';
					echo '<td align="left" valign="middle">'.$obj->getNumberFormat($diff).'</td>';
					echo '<td align="left" valign="middle">'.$delay_days.'</td>';
					echo '</tr>';
					$i++;
				}
				
				
			}
			if($var == 1)
			{
				$sql1 = "select * from freight_invoice_master where COMID='".$rows['COMID']."' ";
			}
			else if($var == 2)
			{
				$sql1 = "select * from freight_invoice_master where (DATE BETWEEN '".date("Y-m-d",strtotime($from_date))."' and '".date("Y-m-d",strtotime($to_date))."')  and COMID='".$rows['COMID']."'";
			}
			else if($var == 3)
			{
				$sql1 = "select * from freight_invoice_master where DATE<'".date("Y-m-d",strtotime($from_date))."'  and COMID='".$rows['COMID']."' ";
			}
			$res1 = mysql_query($sql1) or die($sql1);
			while($rows1 = mysql_fetch_assoc($res1))
			{
				if($rows1['VENDOR']!="")
				{
					$cost_type = 'Final Nett Freight';
					$invoice_amt= $rows1['NET_PAYABLE'];
					$amt_paid = $rows1['P_AMT'];
					$diff = $invoice_amt - $amt_paid;
					$start = strtotime($rows1['DATE']);
					$end = strtotime(date('Y-m-d',time()));
					$delay_days = ceil(abs($end - $start) / 86400);
					echo '<tr>';
					echo '<td align="left" valign="middle">'.$i.'.</td>';
					echo '<td align="left" valign="middle">'.$obj->getVendorListNewBasedOnID($rows1['VENDOR']).'</td>';
					echo '<td align="left" valign="middle">'.$obj->getCompareTableData($rows['COMID'],"MESSAGE").'</td>';
					echo '<td align="left" valign="middle">'.$obj->getVesselIMOData($obj->getCompareEstimateData($rows['COMID'],"VESSEL_IMO_ID"),"VESSEL_NAME").'</td>';
					echo '<td align="left" valign="middle">'.(($obj->getFun112()=='' || $obj->getFun112()=='0000-00-00' || $obj->getFun112()=='1970-01-01')?'':date("d-m-Y",strtotime($obj->getFun112()))).'</td>';
					echo '<td align="left" valign="middle">'.$cost_type.'</td>';
					echo '<td align="left" valign="middle">'.date("d-m-Y",strtotime($rows1['DATE'])).'</td>';
					echo '<td align="left" valign="middle">'.$obj->getNumberFormat($invoice_amt).'</td>';
					echo '<td align="left" valign="middle">'.$obj->getNumberFormat($amt_paid).'</td>';
					echo '<td align="left" valign="middle">'.$obj->getNumberFormat($diff).'</td>';
					echo '<td align="left" valign="middle">'.$delay_days.'</td>';
					echo '</tr>';
				$i++;
				}
			}
		}
	}

	echo '</tbody>
	</table>
	';
}

function getAgingPayableReport()
{
	$obj 			= new data();
	$connect		= $obj->funConnect();
	
	$selVendor      = $_REQUEST['selVendor'];
	$selDate_Type 	= $_REQUEST['selDate_Type'];
	$selBType       = $_REQUEST['selBType'];
	
	if($selDate_Type == 1)
	{
	    $var = 1;
	}
	else if($selDate_Type == 2)
	{
	    $from_date = date('Y-m-d',strtotime('-30 days'));
	    $to_date = date('Y-m-d',time());
		$var = 2;
	}
	else if($selDate_Type == 3)
	{
        $from_date = date('Y-m-d',strtotime('-60 days'));
	    $to_date = date('Y-m-d',strtotime('-30 days'));	
		$var = 2;
	}
	else if($selDate_Type == 4)
	{
	    $from_date = date('Y-m-d',strtotime('-90 days'));
	    $to_date = date('Y-m-d',strtotime('-60 days'));	
		$var = 2;
	}
	else if($selDate_Type == 5)
	{
	    $from_date = date('Y-m-d',strtotime('-90 days'));
		$var = 3;
	}
	
	
	echo '<table id="aging_report_list" class="table table-bordered table-striped dataTable" >
			<thead>
				<tr>
					<th align="left" width="5%">Sr. No.</th>
					<th align="left" width="10%">Vendor</th>
					<th align="left" width="10%">Nom Id</th>
					<th align="left" width="9%">Vessel</th>
					<th align="left" width="9%">CP Date</th>									
					<th align="left" width="9%">Cost Type</th>
					<th align="left" width="9%">Bill Date</th>
					<th align="left" width="10%">Amount Billed</th>
					<th align="left" width="10%">Amount Paid</th>
					<th align="left" width="10%">Difference</th>
					<th align="left" width="9">Delay (Days)</th>
				</tr>
			</thead>
			<tbody>';
	$sql = "select * from freight_cost_estimate_compare inner join freight_cost_estimete_master on freight_cost_estimete_master.FCAID= freight_cost_estimate_compare.FCAID WHERE freight_cost_estimate_compare.MODULEID='".$_SESSION['moduleid']."' AND freight_cost_estimate_compare.MCOMPANYID='".$_SESSION['company']."' and freight_cost_estimate_compare.FINAL_ID!='' and freight_cost_estimete_master.FIXED=1 and freight_cost_estimate_compare.STATUS in (1,2) and freight_cost_estimete_master.ESTIMATE_TYPE='".$selBType."' group by freight_cost_estimate_compare.COMID";
	$res = mysql_query($sql) or die($sql);
	$rec = mysql_num_rows($res);
	$i = 1;
	if($rec == 0)
	{
		
	}
	else
	{	
		while($rows = mysql_fetch_assoc($res))
		{		
		    $fcaid = $obj->getLatestCostSheetID($rows['COMID']);
			$obj->viewFreightCostEstimationTempleteRecordsNew($fcaid);
			if($var = 1)
			{
				$sql1 = "select * from request_master where ".(($_REQUEST['selVendor']!='')?"VENDOR='".$selVendor."' and ":"")." COMID='".$rows['COMID']."'";
			}
			else if($var = 2)
			{
				$sql1 = "select * from request_master where ".(($_REQUEST['selVendor']!='')?"VENDOR='".$selVendor."' and ":"")."  (INVOICE_DATE BETWEEN '".date("Y-m-d",strtotime($from_date))."' and '".date("Y-m-d",strtotime($to_date))."')  and COMID='".$rows['COMID']."' ";
			}
			else if($var = 3)
			{
				$sql1 = "select * from request_master where ".(($_REQUEST['selVendor']!='')?"VENDOR='".$selVendor."' and ":"")."  INVOICE_DATE<'".date("Y-m-d",strtotime($from_date))."'  and COMID='".$rows['COMID']."' ";
			}
			$res1 = mysql_query($sql1);
			while ($rows1 = mysql_fetch_assoc($res1))
			{
				if($rows1['NAME_ID'] == 2)
				{
					$cost_type = 'Bunkers Nett Supply - '.$obj->getBunkerGradeBasedOnID($rows1['GRADEID']);
				}
				else if($rows1['NAME_ID'] == 3)
				{
					if($rows1['GRADEID']==0)
					{
						$cost_type = 'Operational Costs (Others) - Brokerage Commission (%)';
					}
					else
					{
						$cost_type = 'Operational Costs (Others) - '.$obj->getOwnerRelatedCostNameBasedOnID($rows1['GRADEID']);
					}
				}
				else if($rows1['NAME_ID'] == 4)
				{
					$cost_type = 'Charterers Costs';
				}
				else if($rows1['NAME_ID'] == 5)
				{
					if($rows1['PORT'] == 'Load')
					{
						$cost_type = 'Port Costs - '.$obj->getPortNameBasedOnID($rows1['GRADEID']).' (LP)';
					}
					else if($rows1['PORT'] == 'Discharge')
					{
						$cost_type = 'Port Costs - '.$obj->getPortNameBasedOnID($rows1['GRADEID']).' (DP)';
					}
					else if($rows1['PORT'] == 'Transit')
					{
						$cost_type = 'Port Costs - '.$obj->getPortNameBasedOnID($rows1['GRADEID']).' (TP)';
					}
				}
				else if($rows1['NAME_ID'] == 7)
				{
					$cost_type[$j] = 'Other Miscellaneous Costs';
				}
				else if($rows1['NAME_ID'] == 8)
				{
				    $cost_type[$j] = $rows1['NAME'];	
				}
				$invoice_amt= $rows1['NET_AMT'];
				$amt_paid = $rows1['P_AMT'];
				$diff = $invoice_amt - $amt_paid;
				
				$start = strtotime($rows1['INVOICE_DATE']);
				$end = strtotime(date('Y-m-d',time()));
				$delay_days = ceil(abs($end - $start) / 86400);
					
				if($rows1['VENDOR']!="")
				{
					echo '<tr>';
					echo '<td align="left" valign="middle">'.$i.'.</td>';
					echo '<td align="left" valign="middle">'.$obj->getVendorListNewBasedOnID($rows1['VENDOR']).'</td>';
					echo '<td align="left" valign="middle">'.$obj->getCompareTableData($rows['COMID'],"MESSAGE").'</td>';
					echo '<td align="left" valign="middle">'.$obj->getVesselIMOData($obj->getCompareEstimateData($rows['COMID'],"VESSEL_IMO_ID"),"VESSEL_NAME").'</td>';
					echo '<td align="left" valign="middle">'.(($obj->getFun112()=='' || $obj->getFun112()=='0000-00-00' || $obj->getFun112()=='1970-01-01')?'':date("d-m-Y",strtotime($obj->getFun112()))).'</td>';
					echo '<td align="left" valign="middle">'.$cost_type.'</td>';
					echo '<td align="left" valign="middle">'.date("d-m-Y",strtotime($rows1['INVOICE_DATE'])).'</td>';
					echo '<td align="left" valign="middle">'.$obj->getNumberFormat($invoice_amt).'</td>';
					echo '<td align="left" valign="middle">'.$obj->getNumberFormat($amt_paid).'</td>';
					echo '<td align="left" valign="middle">'.$obj->getNumberFormat($diff).'</td>';
					echo '<td align="left" valign="middle">'.$delay_days.'</td>';
					echo '</tr>';
					$i++;
				}
				
				
			}
			if($var = 1)
			{
				$sql1 = "select * from invoice_hire_master where COMID='".$rows['COMID']."' ";
			}
			else if($var = 2)
			{
				$sql1 = "select * from invoice_hire_master where (INVOICE_DATE BETWEEN '".date("Y-m-d",strtotime($from_date))."' and '".date("Y-m-d",strtotime($to_date))."')  and COMID='".$rows['COMID']."'";
			}
			else if($var = 3)
			{
				$sql1 = "select * from invoice_hire_master where INVOICE_DATE<'".date("Y-m-d",strtotime($from_date))."'  and COMID='".$rows['COMID']."' ";
			}
			$res1 = mysql_query($sql1);
			while($rows1 = mysql_fetch_assoc($res1))
			{
				if($rows1['VENDORID']!="")
				{
					$cost_type = 'Daily Time Charter';
					$invoice_amt= $rows1['BALANCE_TO_OWNER'];
					$amt_paid = $rows1['P_AMT'];
					$diff = $invoice_amt - $amt_paid;
					
					$start = strtotime($rows1['INVOICE_DATE']);
					$end = strtotime(date('Y-m-d',time()));
					$delay_days = ceil(abs($end - $start) / 86400);
					
					echo '<tr>';
					echo '<td align="left" valign="middle">'.$i.'.</td>';
					echo '<td align="left" valign="middle">'.$obj->getVendorListNewBasedOnID($rows1['VENDORID']).'</td>';
					echo '<td align="left" valign="middle">'.$obj->getCompareTableData($rows['COMID'],"MESSAGE").'</td>';
					echo '<td align="left" valign="middle">'.$obj->getVesselIMOData($obj->getCompareEstimateData($rows['COMID'],"VESSEL_IMO_ID"),"VESSEL_NAME").'</td>';
					echo '<td align="left" valign="middle">'.(($obj->getFun112()=='' || $obj->getFun112()=='0000-00-00' || $obj->getFun112()=='1970-01-01')?'':date("d-m-Y",strtotime($obj->getFun112()))).'</td>';
					echo '<td align="left" valign="middle">'.$cost_type.'</td>';
					echo '<td align="left" valign="middle">'.date("d-m-Y",strtotime($rows1['INVOICE_DATE'])).'</td>';
					echo '<td align="left" valign="middle">'.$obj->getNumberFormat($invoice_amt).'</td>';
					echo '<td align="left" valign="middle">'.$obj->getNumberFormat($amt_paid).'</td>';
					echo '<td align="left" valign="middle">'.$obj->getNumberFormat($diff).'</td>';
					echo '<td align="left" valign="middle">'.$delay_days.'</td>';
					echo '</tr>';
				$i++;
				}
			}
		}
	}

	echo '</tbody>
	</table>
	';
}


function getPNIClubReport()
{
	
	$obj 			= new data();
	$connect		= $obj->funConnect();
	
	$txtFrom_Date 	= strtotime($_REQUEST['txtFrom_Date']);
	$txtTo_Date 	= strtotime($_REQUEST['txtTo_Date']);
	
	$chk			= $_REQUEST['chk'];
	
	$sql = "select * from mapping_master where MODULEID='".$_SESSION['moduleid']."'  AND MCOMPANYID='".$_SESSION['company']."' and STATUS in (2,5) order by MAPPINGID";
	$res = mysql_query($sql);
	$rec = mysql_num_rows($res);
	$i=1;
	$cost_sheet_id = "";
	$arr = array();
	if($rec == 0)
	{
		echo '<tr>';
		echo '<td align="center" valign="middle" colspan="11" style="color:red;letter-spacing:1px;">SORRY CURRENTLY THERE ARE ZERO(0) RECORDS.</td>';
		echo '</tr>';
	}else{
		while($rows = mysql_fetch_assoc($res))
		{
			$l_cost_sheet_id = $obj->getLatestCostSheetID($rows['MAPPINGID']);
			$obj->viewFreightEstimationRecords($rows['MAPPINGID'],$l_cost_sheet_id);
			//$cpdate = strtotime($obj->getVesselOpenEntryDeta($obj->getMappingData($rows['MAPPINGID'],"OPEN_VESSEL_ID"),"CP_DATE"));
			$cpdate = strtotime($obj->getFun3());
			
			if($txtFrom_Date <= $cpdate && $cpdate <= $txtTo_Date)
			{
					if($chk == 1)
					{
						if($obj->getOtherMiscDetailsBasedOnMappingid($rows['MAPPINGID'],$obj->getFun1(),'3',"AMOUNT") != 0)
						{
							echo '<tr>';
							echo '<td align="center" valign="middle">'.$i.'.</td>';
							echo '<td align="left" valign="middle">'.$obj->getMappingData($rows['MAPPINGID'],"NOM_NAME").'</td>';
							echo '<td align="left" valign="middle">'.$obj->getVesselIMOData($obj->getVesselOpenEntryDeta($rows['OPEN_VESSEL_ID'],'VESSEL_IMO_ID'),"VESSEL_NAME").'</td>';
							if(date("d-M-Y",strtotime($obj->getVesselOpenEntryDeta($obj->getMappingData($rows['MAPPINGID'],"OPEN_VESSEL_ID"),"CP_DATE"))) == "01-Jan-1970")
							{
								echo '<td align="left" valign="middle"></td>';
							}
							else
							{
								echo '<td align="left" valign="middle">'.date("d M Y",strtotime($obj->getVesselOpenEntryDeta($obj->getMappingData($rows['MAPPINGID'],"OPEN_VESSEL_ID"),"CP_DATE"))).'</td>';
							}
							echo '<td align="left" valign="middle">'.$obj->getCargoContarctForMapping($obj->getMappingData($rows['MAPPINGID'],"CARGO_IDS"),$obj->getMappingData($rows['MAPPINGID'],"CARGO_POSITION")).'</td>';
							echo '<td align="left" valign="middle">'.$obj->getVendorListNewBasedOnID($obj->getOtherMiscDetailsBasedOnMappingid($rows['MAPPINGID'],$obj->getFun1(),'3',"VENDORID")).'</td>';
							echo '<td align="right" valign="middle">'.number_format($obj->getOtherMiscDetailsBasedOnMappingid($rows['MAPPINGID'],$obj->getFun1(),'3',"AMOUNT"),2,'.',',').'</td>';
							if($obj->getOtherMiscDetailsBasedOnMappingid($rows['MAPPINGID'],$obj->getFun1(),'3',"VENDORID") != "")
							{
								$paid = $obj->getPaidRequestAmount($rows['MAPPINGID'],'6','3');
								echo '<td align="right" valign="middle">'.number_format($paid,2,'.',',').'</td>';
							}
							else
							{
								$paid = 0.00;
								echo '<td align="right" valign="middle">'.$paid.'</td>';
							}
							echo '<td align="right" valign="middle">'.number_format(($obj->getOtherMiscDetailsBasedOnMappingid($rows['MAPPINGID'],$obj->getFun1(),'3',"AMOUNT") - $paid),2,'.',',').'</td>';
							echo '</tr>';
							$i++;
						}
					}
					else
					{
						echo '<tr>';
						echo '<td align="center" valign="middle">'.$i.'.</td>';
						echo '<td align="left" valign="middle">'.$obj->getMappingData($rows['MAPPINGID'],"NOM_NAME").'</td>';
						echo '<td align="left" valign="middle">'.$obj->getVesselIMOData($obj->getVesselOpenEntryDeta($rows['OPEN_VESSEL_ID'],'VESSEL_IMO_ID'),"VESSEL_NAME").'</td>';
						if(date("d-M-Y",strtotime($obj->getVesselOpenEntryDeta($obj->getMappingData($rows['MAPPINGID'],"OPEN_VESSEL_ID"),"CP_DATE"))) == "01-Jan-1970")
						{
							echo '<td align="left" valign="middle"></td>';
						}
						else
						{
							echo '<td align="left" valign="middle">'.date("d M Y",strtotime($obj->getVesselOpenEntryDeta($obj->getMappingData($rows['MAPPINGID'],"OPEN_VESSEL_ID"),"CP_DATE"))).'</td>';
						}
						echo '<td align="left" valign="middle">'.$obj->getCargoContarctForMapping($obj->getMappingData($rows['MAPPINGID'],"CARGO_IDS"),$obj->getMappingData($rows['MAPPINGID'],"CARGO_POSITION")).'</td>';
						echo '<td align="left" valign="middle">'.$obj->getVendorListNewBasedOnID($obj->getOtherMiscDetailsBasedOnMappingid($rows['MAPPINGID'],$obj->getFun1(),'3',"VENDORID")).'</td>';
						echo '<td align="right" valign="middle">'.number_format($obj->getOtherMiscDetailsBasedOnMappingid($rows['MAPPINGID'],$obj->getFun1(),'3',"AMOUNT"),2,'.',',').'</td>';
						if($obj->getOtherMiscDetailsBasedOnMappingid($rows['MAPPINGID'],$obj->getFun1(),'3',"VENDORID") != "")
						{
							$paid = $obj->getPaidRequestAmount($rows['MAPPINGID'],'6','3');
							echo '<td align="right" valign="middle">'.number_format($paid,2,'.',',').'</td>';
						}
						else
						{
							$paid = 0.00;
							echo '<td align="right" valign="middle">'.$paid.'</td>';
						}
						echo '<td align="right" valign="middle">'.number_format(($obj->getOtherMiscDetailsBasedOnMappingid($rows['MAPPINGID'],$obj->getFun1(),'3',"AMOUNT") - $paid),2,'.',',').'</td>';
						echo '</tr>';
						$i++;
					}
			}
		}
	}
}


function getProjectedCashFlowRecord()
{
	$obj 			= new data();
	$connect		= $obj->funConnect();
	
	$selDate_Type 	= $_REQUEST['selDate_Type'];
	$txtFrom_Date 	= $_REQUEST['txtFrom_Date'];
	$txtTo_Date 	= $_REQUEST['txtTo_Date'];
	$txtDays 		= $_REQUEST['txtDays'];
	
	$selBType 		= $_REQUEST['selBType'];
	
	$arr_eta 		= array("ETA 1 DAY","ETA 2 DAYS","ETA 3 DAYS","ETA 5 DAYS","ETA 7 DAYS");
	echo '<table id="projected_cash_flw_report" class="table table-bordered table-striped dataTable" >
			<thead>
				<tr>
					<th align="left">Sr. No.</th>
					<th align="left">Nom ID</th>
					<th align="left">Material Name</th>
					<th align="left">Vessel</th>
					<th align="left">Total Outstanding (USD)</th>
					<th align="left">Payments (USD)</th>
					<th align="left">Balance Outstanding (USD)</th>
					<th align="left">LP <span id="th_span_1"></span> Date</th>
					<th align="left">Due Date</th>
				</tr>
			</thead>
			<tbody>';
	$sql = "select * from check_list where MODULEID='".$_SESSION['moduleid']."' AND MCOMPANYID='".$_SESSION['company']."'";
	$res = mysql_query($sql);
	$rec = mysql_num_rows($res);
	$k = 1;
	if($rec == 0)
	{
	}
	else
	{
		while($rows = mysql_fetch_assoc($res))
		{
			$fcaid = $obj->getLatestCostSheetID($rows['COMID']);
			$obj->viewFreightCostEstimationTempleteRecordsNew($fcaid);
			if($obj->getFun158() == $selBType)
			{
				$arr  = $obj->getLoadPortAndDischargePortArrBasedOnCommidAndProcessWithoutTBN($rows['COMID'],$fcaid);
				
				$rec1 = 0;
				
				for($i=0;$i<count($arr);$i++)
				{
					$arr_portval = explode('@@',$arr[$i]);
					if($arr_portval[0] == 'LP')
					{
						if($selDate_Type == 1)
						{
							for($j=0;$j<sizeof($arr_eta);$j++)
							{
								$sql1 = "select * from checklist_loadport where PORT='LP' and PORTID='".$arr_portval[1]."' and ENTITY_NAME ='".$arr_eta[$j]."' and CHECKLIST_ID='".$rows['CHECKLIST_ID']."' and RANDOMID='".$arr_portval[2]."' and ENTITY_VALUE!=''";
								
								$res1 = mysql_query($sql1);
								$res11 = mysql_query($sql1);
								$rec1 = mysql_num_rows($res1);
								$rows1 = mysql_fetch_assoc($res1);
								$date2 = $rows1['ENTITY_VALUE'];
								$vall = 0;
								if($date2!="")
								{
									$date3 = strtotime($date2);
									if(strtotime($date2)>=strtotime($txtFrom_Date) && strtotime($date2)<=strtotime($txtTo_Date))
									{
									   $vall = 1;
									}
									else{$vall = 0;}
									
								}else{$vall = 0;}
								if($vall > 0){break;}
							}
						}
						else
						{
							$sql1 = "select * from checklist_loadport where PORT='LP' and PORTID='".$arr_portval[1]."' and ENTITY_NAME ='ETC/D' and CHECKLIST_ID='".$rows['CHECKLIST_ID']."' and RANDOMID='".$arr_portval[2]."'";
							$res1 = mysql_query($sql1);
							$res11 = mysql_query($sql1);
							$rec1 = mysql_num_rows($res1);
							$rows1 = mysql_fetch_assoc($res1);
							$date2 = $rows1['ENTITY_VALUE'];
							$vall = 0;
							if($date2!="")
							{
								$date3 = strtotime($date2);
								if(strtotime($date2)>=strtotime($txtFrom_Date) && strtotime($date2)<=strtotime($txtTo_Date))
								{
								   $vall = 1;
								}
								else{$vall = 0;}
								
							}else{$vall = 0;}
							if($vall > 0){break;}
						}
					}
					
					if($vall > 0){break;}
				}
				
				if($vall > 0)
				{
					$rows1 = mysql_fetch_assoc($res11);
					$cost = 0; $bal_cost = 0;
					
					$sql3 = "select * from request_master where COMID='".$rows['COMID']."' and MODULEID='".$_SESSION['moduleid']."'  AND MCOMPANYID='".$_SESSION['company']."'";
					$res3 = mysql_query($sql3);
					while($rows3 = mysql_fetch_assoc($res3))
					{
						$cost = $cost + $rows3['REQ_TO_PAY'];
					}
					
					echo '<tr>';
					echo '<td align="left" valign="middle">'.$k.'.</td>';
					echo '<td align="left" valign="middle">'.$obj->getCompareTableData($rows['COMID'],"MESSAGE").'</td>';
					echo '<td align="left" valign="middle">'.$obj->getMaterialCodeDesBasedOnId($obj->getFun52()).'</td>';
					echo '<td align="left" valign="middle">'.$obj->getVesselIMOData($obj->getFun5(),"VESSEL_NAME").'</td>';
					$bal_cost = $obj->getFun84() + $obj->getFun153() + $obj->getFun152() + $obj->getFun131() - $cost;
					$ttl_cost = $ttl_cost + $obj->getFun84() + $obj->getFun153() + $obj->getFun152() + $obj->getFun131();
					$ttl_bal_cost = $ttl_bal_cost + $bal_cost;
					echo '<td align="left" valign="middle">'.$obj->getNumberFormat(($obj->getFun84() + $obj->getFun153() + $obj->getFun152() + $obj->getFun131())).'</td>';
					echo '<td align="left" valign="middle">'.$obj->getNumberFormat($cost).'</td>';
					echo '<td align="left" valign="middle">'.$obj->getNumberFormat($bal_cost).'</td>';
					echo '<td align="left" valign="middle">'.date("d-M-Y",strtotime($rows1['ENTITY_VALUE'])).'</td>';
					echo '<td align="left" valign="middle">'.date("d-M-Y , D",strtotime($rows1['ENTITY_VALUE']. ' + '.$txtDays.' days')).'</td>';
					echo '</tr>';
					
					$k++;
				}
			}	
		}
	}
	
	if($k > 1)
	{
		echo '<tfoot>';
		echo '<tr valign="top">';
		echo '<th align="right" colspan="4">Totals</th>';
		echo '<th align="left">'.$obj->getNumberFormat($ttl_cost).'</th>';
		echo '<th align="left"></th>';
		echo '<th align="left">'.$obj->getNumberFormat($ttl_bal_cost).'</th>';
		echo '<th align="left" colspan="2"></th>';
		echo '</tr>';
		echo '</tfoot>';
	}
	echo '</tbody></table>';
}





function getShipmentRegisterRecord()
{

	$obj 			= new data();
	$connect		= $obj->funConnect();
	
	$txtFrom_Date 	= $_REQUEST['txtFrom_Date'];
	$txtTo_Date  	= $_REQUEST['txtTo_Date'];
	$selDate_Type 	= $_REQUEST['selDate_Type'];
	$selBType 	    = $_REQUEST['selBType'];
	echo '<table id="shipment_registor" class="table table-bordered table-striped dataTable">
			<thead>
				<tr>
					<th valign="top">Nom ID</th>
					<th valign="top">Vessel</th>
					<th valign="top">CP Date</th>
					<th valign="top">Owner</th>
					<th valign="top">Broker</th>
					<th valign="top">Material Desc</th>
					<th valign="top">Last Updated Freight</th>
					<th valign="top">From Port</th>
					<th valign="top">To Port</th>
					<th valign="top">BL Date</th>
					<th valign="top">Qty</th>
					<th valign="top">Operational Expenses</th>
					<th valign="top">Port Expenses</th>
					<th valign="top">Bunker Expenses</th>
					<th valign="top">Voyage Earnings</th>
					<th valign="top">Daily Earnings / TCE</th>
					<th valign="top">Voyage Earnings + Demurrage</th>
					<th valign="top">Nett Daily Profit</th>
					<th valign="top">P/L</th>
				</tr>
			</thead>
			<tbody>';
	$sql = "select * from freight_cost_estimate_compare inner join freight_cost_estimete_master on freight_cost_estimete_master.FCAID= freight_cost_estimate_compare.FCAID WHERE freight_cost_estimate_compare.MODULEID='".$_SESSION['moduleid']."' AND freight_cost_estimate_compare.MCOMPANYID='".$_SESSION['company']."' and freight_cost_estimate_compare.FINAL_ID!='' and freight_cost_estimete_master.FIXED=1 and freight_cost_estimete_master.ESTIMATE_TYPE='".$selBType."' and freight_cost_estimate_compare.STATUS in (1,2) order by freight_cost_estimate_compare.COMID desc";
	$res = mysql_query($sql) or die($sql);
	$rec = mysql_num_rows($res); $j = 0;
	if($rec == 0)
	{
	}
	else
	{
		while($rows = mysql_fetch_assoc($res))
		{
			$fcaid = $obj->getLatestCostSheetID($rows['COMID']);
			$obj->viewFreightCostEstimationTempleteRecordsNew($fcaid);
			
			$quantity = $freight = 0;
			if($obj->getCompareEstimateData($rows['COMID'],"ESTIMATE_TYPE")==1)
			{
				$quantity = $obj->getCompareEstimateData($rows['COMID'],"GAS_QUANTITY");
				if($obj->getCompareEstimateData($rows['COMID'],"GAS_MARKET"))
				{
					$freight = $obj->getCompareEstimateData($rows['COMID'],"GAS_QUANTITY");
				}
				else
				{
					$freight = number_format(($obj->getCompareEstimateData($rows['COMID'],"GAS_BALTIC") + $obj->getCompareEstimateData($rows['COMID'],"ADDNL_PRENIUM"))*$obj->getCompareEstimateData($rows['COMID'],"GAS_QUANTITY"), 2, '.', '');
				}
			}
			else if($obj->getCompareEstimateData($rows['COMID'],"ESTIMATE_TYPE")==2)
			{
				$quantity = $obj->getCompareEstimateData($rows['COMID'],"TANK_QUANTITY");
				$sql12 = "select sum(TOTAL_AMOUNT) as sum1 from freight_cost_estimete_slave12 where FCAID='".$obj->getCompareEstimateData($rows['COMID'],"FCAID")."'";
				$res12 = mysql_query($sql12);
				$row12 = mysql_fetch_assoc($res12);
				$freight  = $row12['sum1'];
			}
			else
			{
				if($obj->getCompareEstimateData($rows['COMID'],"QTY_TYPE_RADIO")== 1)
				{
					$quantity = $obj->getCompareEstimateData($rows['COMID'],"QUANTITY");
					$freight  = $obj->getCompareEstimateData($rows['COMID'],"NET_PAYABLE");
				}
				else
				{
					$sql12 = "select sum(QUANTITY) as sum, sum(NET_FREIGHT) as sum2 from freight_cost_estimete_slave7 where FCAID='".$obj->getCompareEstimateData($rows['COMID'],"FCAID")."'";
					$res12 = mysql_query($sql12);
					$row12 = mysql_fetch_assoc($res12);
					$quantity = $row12['sum'];
					$freight  = number_format($row12['sum2'], 2, '.', '');
				}
			}
			
			$addn_qty = $obj->getFun54();
			$dead_freight_qty = $obj->getFun53();				
			$arr  = $obj->getLoadPortAndDischargePortArrBasedOnCommidAndProcessWithoutTBN($rows['COMID'],$fcaid);
			
			$lp_name = ''; $dp_name = '';
			for($i=0;$i<count($arr);$i++)
			{
				$arr_portval = explode('@@',$arr[$i]);
				if($arr_portval[0] == "LP"){$lp_name .= $obj->getPortNameBasedOnID($arr_portval[1]).',</br>';}
				else{$dp_name .= $obj->getPortNameBasedOnID($arr_portval[1]).',</br>';}
			}
			
			$lp_name = substr($lp_name,0,-6);
			$dp_name = substr($dp_name,0,-6);
			$bl_date_arr = array();
			$bl_qty = 0;
			if($selDate_Type == 1)
			{
				$sql1 = "select * from sof_master where (BL_DATE BETWEEN '".date("Y-m-d",strtotime($txtFrom_Date))."' and '".date("Y-m-d",strtotime($txtTo_Date))."') and MODULEID='".$_SESSION['moduleid']."' AND MCOMPANYID='".$_SESSION['company']."' and COMID='".$rows['COMID']."' and LOGIN = 'INTERNAL_USER'";
				$res1 = mysql_query($sql1);
				$res11 = mysql_query($sql1);
			    $rec1 = mysql_num_rows($res1);
				$bl_date_arr = array();
			    while($rows1 = mysql_fetch_assoc($res1))
				{
					for($i=0;$i<count($arr);$i++)
			        {
						$arr_portval = explode('@@',$arr[$i]);
						$sql2 = "select * from sof_master where SOFID='".$rows1['SOFID']."' and PORT='".$arr_portval[0]."' and PORTID='".$arr_portval[1]."' and RANDOMID='".$arr_portval[2]."'";
						$res2 = mysql_query($sql2);
						$rec2 = mysql_num_rows($res2);
						while($rows2 = mysql_fetch_assoc($res2))
						{
							$bl_date = date("d-M-Y",strtotime($rows2['BL_DATE']));
							$bl_date_arr[] = $arr_portval[0]."-".$obj->getPortNameBasedOnID($arr_portval[1])."-".$bl_date;
							$bl_qty = $bl_qty + $rows2['BL_QTY_LOADED'];
						}
					}
				}
			}
			else
			{
				$sql1 = "select * from freight_cost_estimete_master where (TRANS_DATE BETWEEN '".date("Y-m-d",strtotime($txtFrom_Date))."' and '".date("Y-m-d",strtotime($txtTo_Date))."') and MODULEID='".$_SESSION['moduleid']."' AND MCOMPANYID='".$_SESSION['company']."' and COMID='".$rows['COMID']."' and FCAID='".$fcaid."' order by FCAID";
				$res1 = mysql_query($sql1);
				$res11 = mysql_query($sql1);
			    $rec1 = mysql_num_rows($res1);
			    $rows1 = mysql_fetch_assoc($res1);
				
				$bl_date_arr = array();
				for($i=0;$i<count($arr);$i++)
				{
					$arr_portval = explode('@@',$arr[$i]);
					$sql2 = "select * from sof_master where COMID='".$rows1['COMID']."' and PORT='".$arr_portval[0]."' and PORTID='".$arr_portval[1]."' and RANDOMID='".$arr_portval[2]."' and LOGIN = 'INTERNAL_USER'";
					$res2 = mysql_query($sql2) or die($sql2);
					$rec2 = mysql_num_rows($res2);
					while($rows2 = mysql_fetch_assoc($res2))
					{
						if($rows2['BL_DATE']!='' && $rows2['BL_DATE']!='0000-00-00' && $rows2['BL_DATE']!='1970-01-01' && $rows2['BL_DATE']!='01-01-1970')
						{
						   $bl_date = date("d-M-Y",strtotime($rows2['BL_DATE']));
						}
						else
						{
							$bl_date = '';
						}
						$bl_date_arr[] = $arr_portval[0]."-".$obj->getPortNameBasedOnID($arr_portval[1])."-".$bl_date;
						$bl_qty = $bl_qty + $rows2['BL_QTY_LOADED'];
					}
				}
			}
			
			
			if($rec1>0)
			{
			    echo '<tr class="GridviewScrollItem">';
				echo '<td align="left" valign="top" >'.$obj->getCompareTableData($rows['COMID'],"MESSAGE").'</td>';
				echo '<td align="left"  valign="top" >'.$obj->getVesselIMOData($obj->getFun5(),"VESSEL_NAME").'</td>';
				echo '<td align="left" valign="top" >'.(($obj->getFun112()=='' || $obj->getFun112()=='0000-00-00' || $obj->getFun112()=='1970-01-01')?'':date("d-m-Y",strtotime($obj->getFun112()))).'</td>';
				$sql7 = "select * from freight_cost_estimete_slave4 where FCAID='".$obj->getFun1()."' ";
				$res7 = mysql_query($sql7);
				$rec7 = mysql_num_rows($res7);
				$arrvendor = array();
				while($rows7 = mysql_fetch_assoc($res7))
				{
					$arrvendor[] = $obj->getVendorListNewBasedOnID($rows7['VENDORID']);
				}
				echo '<td align="left" valign="top" >'.$obj->getVendorListNewBasedOnID($obj->getFun140()).'</td>';
				echo '<td align="left" valign="top" >'.implode(', ',$arrvendor).'</td>';
				echo '<td align="left" valign="top" >'.$obj->getMaterialCodeDesBasedOnCode($obj->getFun52()).'</td>';
				echo '<td align="left" valign="top" >'.$freight.'</td>';
				echo '<td align="left" valign="top" >'.$lp_name.'</td>'; 
				echo '<td align="left" valign="top" >'.$dp_name.'</td>';
				echo '<td align="left" valign="top" >'.implode('<br/>',$bl_date_arr).'</td>';
				echo '<td align="left" valign="top" >'.$obj->getNumberFormat($quantity).'</td>';
				echo '<td align="left" valign="top" >'.$obj->getNumberFormat($obj->getFun84()).'</td>';
				echo '<td align="left" valign="top" >'.$obj->getNumberFormat($obj->getFun153()).'</td>';
				echo '<td align="left" valign="top" >'.$obj->getNumberFormat($obj->getFun152()).'</td>';
				echo '<td align="left" valign="top" >'.$obj->getNumberFormat($obj->getFun89()).'</td>';
				echo '<td align="left" valign="top" >'.$obj->getNumberFormat($obj->getFun90()).'</td>';
				echo '<td align="left" valign="top" >'.$obj->getNumberFormat($obj->getFun92()).'</td>';
				echo '<td align="left" valign="top" >'.$obj->getNumberFormat($obj->getFun93()).'</td>';
				echo '<td align="left" valign="top" >'.$obj->getNumberFormat($obj->getFun95()).'</td>';
				echo '</tr>';
				$j++;
			}
		}
	}
	echo '</body></table>';
	
}




function getProfitabilityReport()
{
	$obj 			= new data();
	$connect		= $obj->funConnect();
	
	$txtFrom_Date 	= strtotime($_REQUEST['txtFrom_Date']);
	$txtTo_Date 	= strtotime($_REQUEST['txtTo_Date']);
	$selBType 	    = $_REQUEST['selBType'];
	
	
	echo '<table id="profittability_report" class="table table-bordered table-striped dataTable" >
			<thead>
				<tr>
					<th align="left" width="5%">Sr. No.</th>
					<th align="left" width="10%">Nom Id</th>
					<th align="left" width="10%">Vessel</th>
					<th align="left" width="15%">CP Date</th>
					<th align="center" width="5%">Status</th>
					<th align="left" width="15%">Total Qty. (MT)</th>
					<th align="left" width="15%">Earnings (Including Demurrage)</th>
					<th align="left" width="15%">Expense</th>
					<th align="left" width="15%">Net Earnings</th>
				</tr>
			</thead>
			<tbody id="tableBody">';
	$sql = "select * from freight_cost_estimate_compare inner join freight_cost_estimete_master on freight_cost_estimete_master.FCAID= freight_cost_estimate_compare.FCAID WHERE freight_cost_estimate_compare.MODULEID='".$_SESSION['moduleid']."' AND freight_cost_estimate_compare.MCOMPANYID='".$_SESSION['company']."' and freight_cost_estimate_compare.FINAL_ID!='' and freight_cost_estimete_master.FIXED=1 and freight_cost_estimate_compare.STATUS in (1,2) and freight_cost_estimete_master.ESTIMATE_TYPE='".$selBType."' order by freight_cost_estimate_compare.COMID desc";
	$res = mysql_query($sql) or die($sql);
	$rec = mysql_num_rows($res);
	$i = 1;
	if($rec == 0)
	{
		
	}
	else
	{
		while($rows = mysql_fetch_assoc($res))
		{
			$var  = 0; 
			$fcaid = $obj->getLatestCostSheetID($rows['COMID']);
			$obj->viewFreightCostEstimationTempleteRecordsNew($fcaid);
			
			
			$quantity = 0;
			if($obj->getCompareEstimateData($rows['COMID'],"ESTIMATE_TYPE")==1)
			{
				$quantity = $obj->getCompareEstimateData($rows['COMID'],"GAS_QUANTITY");
			}
			else if($obj->getCompareEstimateData($rows['COMID'],"ESTIMATE_TYPE")==2)
			{
				$quantity = $obj->getCompareEstimateData($rows['COMID'],"TANK_QUANTITY");
			}
			else
			{
				if($obj->getCompareEstimateData($rows['COMID'],"QTY_TYPE_RADIO")== 1)
				{
					$quantity = $obj->getCompareEstimateData($rows['COMID'],"QUANTITY");
				}
				else
				{
					$sql12 = "select sum(QUANTITY) as sum from freight_cost_estimete_slave7 where FCAID='".$fcaid."'";
					$res12 = mysql_query($sql12);
					$row12 = mysql_fetch_assoc($res12);
					$quantity = $row12['sum'];
				}
			}
			
			$cpdate = strtotime($obj->getFun112());
			
			if($rows['STATUS'] == '1'){$status = 'In Ops';}else{$status = 'Post Ops';}
			
			$mysql2 = "select sum(DDCDP_NETCOST) as sum2, sum(DDCLP_NETCOST) as sum3 from freight_cost_estimete_slave1 where FCAID='".$fcaid."'";
			$myres2 = mysql_query($mysql2) or die($mysql2);
			$myrows2 = mysql_fetch_assoc($myres2);
			
			$profit = $obj->getFun86() + $myrows2['sum2'] + $myrows2['sum3'];
			
			$expense = $obj->getFun84() + $obj->getFun153() + $obj->getFun152() + $obj->getFun131();
			
			$diff = $profit - $expense;
			
			if($txtFrom_Date <= $cpdate && $cpdate <= $txtTo_Date)
			{
				echo '<tr>';
				echo '<td align="left" valign="middle">'.$i.'.</td>';
				echo '<td align="left" valign="middle">'.$obj->getCompareTableData($rows['COMID'],"MESSAGE").'</td>';
				echo '<td align="left" valign="middle">'.$obj->getVesselIMOData($obj->getFun5(),"VESSEL_NAME").'</td>';
				echo '<td align="left" valign="middle">'.(($obj->getFun112()=='' || $obj->getFun112()=='0000-00-00' || $obj->getFun112()=='1970-01-01')?'':date("d-m-Y",strtotime($obj->getFun112()))).'</td>';
				echo '<td align="center" valign="middle">'.$status.'</td>';
				echo '<td align="left" valign="middle">'.$quantity.'</td>';
				echo '<td align="left" valign="middle">'.$profit.'</td>';
				echo '<td align="left" valign="middle">'.$expense.'</td>';
				echo '<td align="left" valign="middle">'.$diff.'</td>';
				echo '</tr>';
				
				$i++;
			}
		}
	}
	echo '</tbody>
	   </table>';
}


function getPortPerformanceReport()
{
	$obj 		= new data();
	$connect	= $obj->funConnect();
	$selPort 	= $_REQUEST['selPort'];	
	$selBType 	= $_REQUEST['selBType'];
	$sql = "select * from freight_cost_estimate_compare inner join freight_cost_estimete_master on freight_cost_estimete_master.FCAID= freight_cost_estimate_compare.FCAID WHERE freight_cost_estimate_compare.MODULEID='".$_SESSION['moduleid']."' AND freight_cost_estimate_compare.MCOMPANYID='".$_SESSION['company']."' and freight_cost_estimate_compare.FINAL_ID!='' and freight_cost_estimete_master.FIXED=1 and freight_cost_estimate_compare.STATUS in (1,2) and freight_cost_estimete_master.ESTIMATE_TYPE='".$selBType."' order by freight_cost_estimate_compare.COMID desc";
	$res = mysql_query($sql);
	$rec = mysql_num_rows($res);
	$j = 1;
	
	echo '<table id="port_performance_list" class="table table-bordered table-striped dataTable">
		<thead>
			<tr valign="top">
				<th align="left" width="5%">Sr. No.</th>
				<th align="left" width="10%">Port</th>
				<th align="left" width="10%">Vessel Name</th>
				<th align="left" width="10%">Nom Id</th>
				<th align="center" width="10%">Quantity</th>
				<th align="left" width="10%">Pre Berthing Delays (DAYS)</th>
				<th align="left" width="15%">Cargo Working Time (DAYS)</th>
				<th align="left" width="15%">Actual Load / Disg Rate (MT/DAYS)</th>
				<th align="left" width="15%">Demmurage / Despatch Amt (USD)</th>
			</tr>
		</thead>
		<tbody>';
	
	if($rec == 0)
	{
		echo '<tr>';
		echo '<td align="center" valign="middle" colspan="11" style="color:red;letter-spacing:1px;">SORRY CURRENTLY THERE ARE ZERO(0) RECORDS.</td>';
		echo '</tr>';
	}
	else
	{
		while($rows = mysql_fetch_assoc($res))
		{
			$quantity = 0;
			if($obj->getCompareEstimateData($rows['COMID'],"ESTIMATE_TYPE")==1)
			{
				$quantity = $obj->getCompareEstimateData($rows['COMID'],"GAS_QUANTITY");
			}
			else if($obj->getCompareEstimateData($rows['COMID'],"ESTIMATE_TYPE")==2)
			{
				$quantity = $obj->getCompareEstimateData($rows['COMID'],"TANK_QUANTITY");
			}
			else
			{
				if($obj->getCompareEstimateData($rows['COMID'],"QTY_TYPE_RADIO")== 1)
				{
					$quantity = $obj->getCompareEstimateData($rows['COMID'],"QUANTITY");
				}
				else
				{
					$sql12 = "select sum(QUANTITY) as sum from freight_cost_estimete_slave7 where FCAID='".$fcaid."'";
					$res12 = mysql_query($sql12);
					$row12 = mysql_fetch_assoc($res12);
					$quantity = $row12['sum'];
				}
			}
			$fcaid = $obj->getLatestCostSheetID($rows['COMID']);
            $obj->viewFreightCostEstimationTempleteRecordsNew($fcaid);
			$arr       = $obj->getLoadPortAndDischargePortArrBasedOnCommidAndProcessWithoutTBN($comid,$fcaid);
			for($i=0;$i<count($arr);$i++)
			{
				$arr_portval = explode('@@',$arr[$i]);
				if($selPort== $arr_portval[1])
				{
					$sql1 = "select * from sof_master where COMID='".$rows['COMID']."' and LOGIN='INTERNAL_USER' and MODULEID='".$_SESSION['moduleid']."'  AND MCOMPANYID='".$_SESSION['company']."' and PORT='".$arr_portval[0]."' and PORTID='".$selPort."' and RANDOMID='".$arr_portval[2]."'";
					$res1 = mysql_query($sql1);
					$rec1 = mysql_num_rows($res1);
					if($rec1 > 0)
					{
						$rows1 = mysql_fetch_assoc($res1);
						
						if($rows1['NT_1'] != '' && $rows1['PBFB_1'] != '')
						{ 
							$start = strtotime($rows1['NT_1']); 
							$end   = strtotime($rows1['PBFB_1']);
							$days_pre_berthing = ($end - $start) / 86400;
						}
						else if($rows1['NT_1'] != '' && $rows1['LC'] != '')
						{ 
							$start = strtotime($rows1['NT_1']); 
							$end   = strtotime($rows1['LC']);
							$days_pre_berthing = ($end - $start) / 86400;
						}
						else
						{ 
							$start = 0; $end = 0;
							$days_pre_berthing = 0;
						} 
						
						
						$start = strtotime($rows1['LC']); 
						$end   = strtotime($rows1['LC1']);
						
						$days_cargo_wrk = ($end - $start) / 86400;
						
						$actual_rate = $quantity/$days_cargo_wrk;
						
						if($arr_portval[0] == "LP")
						{
							$sql1  = "select * from laytime_master where COMID='".$rows['COMID']."' and LOGIN='INTERNAL_USER' and PORT='LP' and PORTID='".$selPort."' and RANDOMID='".$arr_portval[2]."'";
							$res1  = mysql_query($sql1) or die($sql1);
							$rows1 = mysql_fetch_assoc($res1);
							
							if($rows1['TTL_DEMURRAGE'] == 0 && $rows1['TTL_DESPATCH'] == 0){$value = 0;}
							if($rows1['TTL_DEMURRAGE'] == 0){$value = "-".$rows1['TTL_DESPATCH'];}
							if($rows1['TTL_DESPATCH'] == 0){$value = $rows1['TTL_DEMURRAGE'];}
						}
						else
						{
							$sql1  = "select * from laytime_master where COMID='".$rows['COMID']."' and LOGIN='INTERNAL_USER' and PORT='DP' and PORTID='".$selPort."' and RANDOMID='".$arr_portval[2]."'";
							$res1  = mysql_query($sql1) or die($sql1);
							$rec1  = mysql_num_rows($res1);
							$rows1 = mysql_fetch_assoc($res1);
							
							if($rows1['TTL_DEMURRAGE'] == 0 && $rows1['TTL_DESPATCH'] == 0){$value = 0;}
							if($rows1['TTL_DEMURRAGE'] == 0){$value = "-".$rows1['TTL_DESPATCH'];}
							if($rows1['TTL_DESPATCH'] == 0){$value = $rows1['TTL_DEMURRAGE'];}
						}
						
						
						
						echo '<tr>';
						echo '<td align="left" valign="middle">'.$j.'.</td>';
						echo '<td align="left" valign="middle">'.$obj->getPortNameBasedOnID($selPort).'</td>';
						echo '<td align="left" valign="middle">'.$obj->getVesselIMOData($obj->getFun5(),"VESSEL_NAME").'</td>';
						echo '<td align="left" valign="middle">'.$obj->getCompareTableData($rows['COMID'],"MESSAGE").'</td>';
						echo '<td align="center" valign="middle">'.$obj->getNumberFormat($quantity).'</td>';
						echo '<td align="center" valign="middle">'.$obj->getNumberFormat($days_pre_berthing).'</td>';
						echo '<td align="center" valign="middle">'.$obj->getNumberFormat($days_cargo_wrk).'</td>';
						echo '<td align="center" valign="middle">'.$obj->getNumberFormat($actual_rate).'</td>';
						echo '<td align="center" valign="middle">'.$obj->getNumberFormat($value).'</td>';
						echo '</tr>';
						
						$j++;
					}
				}
			}
		}
	}
	echo '</tbody>
		</table>';
}

function getDeadFreightSummaryReport()
{
	$obj 			= new data();
	$connect		= $obj->funConnect();	
	$txtFrom_Date 	= strtotime($_REQUEST['txtFrom_Date']);
	$txtTo_Date 	= strtotime($_REQUEST['txtTo_Date']);
	$selBType       = $_REQUEST['selBType'];
	
	$chk = $_REQUEST['chk'];
	
	$sql = "select * from freight_cost_estimate_compare inner join freight_cost_estimete_master on freight_cost_estimete_master.FCAID= freight_cost_estimate_compare.FCAID WHERE freight_cost_estimate_compare.MODULEID='".$_SESSION['moduleid']."' AND freight_cost_estimate_compare.MCOMPANYID='".$_SESSION['company']."' and freight_cost_estimate_compare.FINAL_ID!='' and freight_cost_estimete_master.FIXED=1 and freight_cost_estimate_compare.STATUS in (1,2) AND freight_cost_estimete_master.ESTIMATE_TYPE='".$selBType."' order by freight_cost_estimate_compare.COMID desc";
	$res = mysql_query($sql) or die($sql);
	$rec = mysql_num_rows($res);
	$i=1;
	$arr = array();
	
	echo '<table id="df_list"  class="table table-bordered table-striped" >
			<thead>
			<tr>
				<th align="left" valign="top" width="9%">Sr. No</th>
				<th align="left" valign="top" width="9%">Nom ID</th>
				<th align="left" valign="top" width="9%">Voyage No.</th>
				<th align="left" valign="top" width="9%">Vessel Name</th>
				<th align="left" valign="top" width="9%">COA/Spot</th>
				<th align="left" valign="top" width="9%">CP Date</th>	
				<th align="left" valign="top" width="9%">Shipper</th>
				<th align="left" valign="top" width="9%">Charterer</th>
				<th align="left" valign="top" width="9%">Load Port</th>
				<th align="left" valign="top" width="9%">Discharge Port</th>
				<th align="left" valign="top" width="9%">Contract Qty (MT)</th>
				<th align="left" valign="top" width="9%">Dead freight Qty (MT)</th>	
				<th align="left" valign="top" width="10%">Dead freight Amount (USD)</th>
			</tr>
			</thead>
			<tbody>';
	
	if($rec == 0)
	{
		
	}else{
	
		while($rows = mysql_fetch_assoc($res))
		{
			$fcaid = $obj->getLatestCostSheetID($rows['COMID']);
            $obj->viewFreightCostEstimationTempleteRecordsNew($fcaid);
			
			$cpdate = strtotime($obj->getFun112());
			
			if($txtFrom_Date <= $cpdate && $cpdate <= $txtTo_Date)
			{
				if($obj->getFun2() == 2)
				{
					if($chk == 1)
					{
						if($obj->getFun67()!= 0)
						{
							echo '<tr>';
							echo '<td align="center" valign="middle">'.$i.'.</td>';
							echo '<td align="left" valign="middle">'.$obj->getCompareTableData($rows['COMID'],"MESSAGE").'</td>';
							echo '<td align="left" valign="middle">'.$obj->getFun8().'</td>';
							echo '<td align="left" valign="middle">'.$obj->getVesselIMOData($obj->getFun5(),"VESSEL_NAME").'</td>';
							$quantity = $dfqty = $dfamt = 0;$coa_spot = '';
							if($obj->getFun175()!='')
							{   $coa_spot = 'COA'; 
								$sql12 = "select sum(CARGO_MT) as sum1, sum(CARGO_CBM) as sum2 from freight_cost_estimete_slave10 where FCAID='".$fcaid."' and STATUS=1";
								$res12 = mysql_query($sql12);
								$row12 = mysql_fetch_assoc($res12);
								if($obj->getCompareEstimateData($rows['COMID'],"ESTIMATE_TYPE")==1)
								{
									$quantity = $row12['sum2'];
								}
								else if($obj->getCompareEstimateData($rows['COMID'],"ESTIMATE_TYPE")==2)
								{
									$quantity = $row12['sum2'];
								}
								else
								{
								   $quantity = $row12['sum1'];
								}
								$sql12 = "select sum(CARGO_MT) as sum1, sum(CARGO_CBM) as sum2, sum(AMOUNT_USD) as sum3 from freight_cost_estimete_slave10 where FCAID='".$fcaid."' and STATUS=3";
								$res12 = mysql_query($sql12);
								$row12 = mysql_fetch_assoc($res12);
								if($obj->getCompareEstimateData($rows['COMID'],"ESTIMATE_TYPE")==1)
								{
									$dfqty = $row12['sum2'];
								}
								else if($obj->getCompareEstimateData($rows['COMID'],"ESTIMATE_TYPE")==2)
								{
									$dfqty = $row12['sum2'];
								}
								else
								{
								   $dfqty = $row12['sum1'];
								}
								
								$dfamt = $row12['sum3'];
							}
							else
							{
								$coa_spot = 'SPOT';
								if($obj->getCompareEstimateData($rows['COMID'],"ESTIMATE_TYPE")==1)
								{
									$quantity = $obj->getCompareEstimateData($rows['COMID'],"GAS_QUANTITY");
								}
								else if($obj->getCompareEstimateData($rows['COMID'],"ESTIMATE_TYPE")==2)
								{
									$quantity = $obj->getCompareEstimateData($rows['COMID'],"TANK_QUANTITY");
								}
								else
								{
									if($obj->getCompareEstimateData($rows['COMID'],"QTY_TYPE_RADIO")== 1)
									{
										$quantity = $obj->getCompareEstimateData($rows['COMID'],"QUANTITY");
									}
									else
									{
										$sql12 = "select sum(QUANTITY) as sum from freight_cost_estimete_slave7 where FCAID='".$fcaid."'";
										$res12 = mysql_query($sql12);
										$row12 = mysql_fetch_assoc($res12);
										$quantity = $row12['sum'];
									}
									$dfqty = $obj->getFun53();
									$dfamt = $obj->getFun67();
								}
								
							}
							echo '<td align="left" valign="middle">'.$coa_spot.'</td>';
							if(date("d-M-Y",strtotime($obj->getFun112())) == "01-Jan-1970")
							{
								echo '<td align="left" valign="middle"></td>';
							}
							else
							{
								echo '<td align="left" valign="middle">'.date("d-m-Y",strtotime($obj->getFun112())).'</td>';
							}
							
							echo '<td align="left" valign="middle">'.$obj->getVendorListNewBasedOnID($obj->getOpenCargoPositionData($obj->getFun206(),'SHIPPER')).'</td>';
							echo '<td align="left" valign="middle">'.$obj->getVendorListNewBasedOnID($obj->getOpenCargoPositionData($obj->getFun206(),'CHARTERER')).'</td>';
							echo '<td align="left" valign="middle">'.implode(" , ",$obj->getLoadPortNameArrBasedOnIDComidAndProcessWithoutTBN($rows['COMID'])).'</td>';
							echo '<td align="left" valign="middle">'.implode(" , ",$obj->getDisPortNameArrBasedOnIDComidAndProcessWithoutTBN($rows['COMID'])).'</td>';
							
							echo '<td align="left" valign="middle">'.$quantity.'</td>';
							
							echo '<td align="left" valign="middle">'.$dfqty.'</td>';
							echo '<td align="left" valign="middle">'.$dfamt.'</td>';
							echo '</tr>';
							$i++;
						}
					}
					else
					{
						echo '<tr>';
						echo '<td align="center" valign="middle">'.$i.'.</td>';
						echo '<td align="left" valign="middle">'.$obj->getCompareTableData($rows['COMID'],"MESSAGE").'</td>';
						echo '<td align="left" valign="middle">'.$obj->getFun8().'</td>';
						echo '<td align="left" valign="middle">'.$obj->getVesselIMOData($obj->getFun5(),"VESSEL_NAME").'</td>';
						$quantity = $dfqty = $dfamt = 0;$coa_spot = '';
						if($obj->getFun175()!='')
						{   $coa_spot = 'COA'; 
							$sql12 = "select sum(CARGO_MT) as sum1, sum(CARGO_CBM) as sum2 from freight_cost_estimete_slave10 where FCAID='".$fcaid."' and STATUS=1";
							$res12 = mysql_query($sql12);
							$row12 = mysql_fetch_assoc($res12);
							if($obj->getCompareEstimateData($rows['COMID'],"ESTIMATE_TYPE")==1)
							{
								$quantity = $row12['sum2'];
							}
							else if($obj->getCompareEstimateData($rows['COMID'],"ESTIMATE_TYPE")==2)
							{
								$quantity = $row12['sum2'];
							}
							else
							{
							   $quantity = $row12['sum1'];
							}
							$sql12 = "select sum(CARGO_MT) as sum1, sum(CARGO_CBM) as sum2, sum(AMOUNT_USD) as sum3 from freight_cost_estimete_slave10 where FCAID='".$fcaid."' and STATUS=3";
							$res12 = mysql_query($sql12);
							$row12 = mysql_fetch_assoc($res12);
							if($obj->getCompareEstimateData($rows['COMID'],"ESTIMATE_TYPE")==1)
							{
								$dfqty = $row12['sum2'];
							}
							else if($obj->getCompareEstimateData($rows['COMID'],"ESTIMATE_TYPE")==2)
							{
								$dfqty = $row12['sum2'];
							}
							else
							{
							   $dfqty = $row12['sum1'];
							}
							
							$dfamt = $row12['sum3'];
						}
						else
						{
							$coa_spot = 'SPOT';
							if($obj->getCompareEstimateData($rows['COMID'],"ESTIMATE_TYPE")==1)
							{
								$quantity = $obj->getCompareEstimateData($rows['COMID'],"GAS_QUANTITY");
							}
							else if($obj->getCompareEstimateData($rows['COMID'],"ESTIMATE_TYPE")==2)
							{
								$quantity = $obj->getCompareEstimateData($rows['COMID'],"TANK_QUANTITY");
							}
							else
							{
								if($obj->getCompareEstimateData($rows['COMID'],"QTY_TYPE_RADIO")== 1)
								{
									$quantity = $obj->getCompareEstimateData($rows['COMID'],"QUANTITY");
								}
								else
								{
									$sql12 = "select sum(QUANTITY) as sum from freight_cost_estimete_slave7 where FCAID='".$fcaid."'";
									$res12 = mysql_query($sql12);
									$row12 = mysql_fetch_assoc($res12);
									$quantity = $row12['sum'];
								}
								$dfqty = $obj->getFun53();
								$dfamt = $obj->getFun67();
							}
							
						}
						echo '<td align="left" valign="middle">'.$coa_spot.'</td>';
						if(date("d-M-Y",strtotime($obj->getFun112())) == "01-Jan-1970")
						{
							echo '<td align="left" valign="middle"></td>';
						}
						else
						{
							echo '<td align="left" valign="middle">'.date("d-m-Y",strtotime($obj->getFun112())).'</td>';
						}
						

						echo '<td align="left" valign="middle">'.$obj->getVendorListNewBasedOnID($obj->getOpenCargoPositionData($obj->getFun206(),'SHIPPER')).'</td>';
						echo '<td align="left" valign="middle">'.$obj->getVendorListNewBasedOnID($obj->getOpenCargoPositionData($obj->getFun206(),'CHARTERER')).'</td>';
						echo '<td align="left" valign="middle">'.implode(" , ",$obj->getLoadPortNameArrBasedOnIDComidAndProcessWithoutTBN($rows['COMID'])).'</td>';
						echo '<td align="left" valign="middle">'.implode(" , ",$obj->getDisPortNameArrBasedOnIDComidAndProcessWithoutTBN($rows['COMID'])).'</td>';
						echo '<td align="left" valign="middle">'.$quantity.'</td>';
						echo '<td align="left" valign="middle">'.$dfqty.'</td>';
						echo '<td align="left" valign="middle">'.$dfamt.'</td>';
						echo '</tr>';
						$i++;
					}
				}
			}
		}
	}
	echo '</tbody>
		</table>';
}



function getDemmurageSummaryReport()
{
	$obj 			= new data();
	$connect		= $obj->funConnect();
	
	$txtFrom_Date 	= strtotime($_REQUEST['txtFrom_Date']);
	$txtTo_Date 	= strtotime($_REQUEST['txtTo_Date']);
	$chk 			= $_REQUEST['chk'];
	$selBType       = $_REQUEST['selBType'];
	if($selBType == 3){$hrdays = 'Days';}else{$hrdays = 'Hrs';}
	$selCOASpot     = $_REQUEST['selCOASpot'];
	
	echo 
	'<table id="demm_summ_list" class="table table-bordered table-striped" >
	<thead>
		<tr valign="top">
			<th align="left">Sr. No.</th>
			<th align="left">Nom Id</th>
			<th align="left">Voyage No.</th>
			<th align="left">Vessel Name</th>
			<th align="left">COA/Spot</th>
			<th align="left">CP Date</th>
			<th align="left">Total Qty.(MT)</th>
			<th align="left">Port</th>
			<th align="left">Turn Time (Hrs)</th>
			<th align="left">TT terms</th>
			<th align="left">Load/Dis Port Rate (MT/Day)</th>
			<th align="left">Laytime Allowed('.$hrdays.')</th>
			<th align="left">Actual Laytime('.$hrdays.')</th>
			<th align="left">Time to demurrage/despatch('.$hrdays.')</th>
			<th align="left">Demurrage /Dispatch (USD)</th>
			<th align="center">Total Demurrage /Dispatch (USD)</th>
			<th align="center">Net Freight Effect (USD/MT)</th>
		</tr>
	</thead>
	<tbody>';
	if($selCOASpot == 2){$subquery = " and freight_cost_estimate_compare.COAAID is not NULL";}else{$subquery = " and freight_cost_estimate_compare.COAAID is NULL";}

	$sql = "select * from freight_cost_estimate_compare inner join freight_cost_estimete_master on freight_cost_estimete_master.FCAID= freight_cost_estimate_compare.FCAID WHERE freight_cost_estimate_compare.MODULEID='".$_SESSION['moduleid']."' AND freight_cost_estimate_compare.MCOMPANYID='".$_SESSION['company']."' and freight_cost_estimate_compare.FINAL_ID!='' and freight_cost_estimete_master.FIXED=1 and freight_cost_estimate_compare.STATUS in (1,2) AND freight_cost_estimete_master.ESTIMATE_TYPE='".$selBType."' ".$subquery." order by freight_cost_estimate_compare.COMID desc";
	//echo $sql;
	$res = mysql_query($sql);
	$rec = mysql_num_rows($res);
	$j = 1;
	if($rec == 0)
	{
		
	}
	else
	{	
		while($rows = mysql_fetch_assoc($res))
		{
			$fcaid = $obj->getLatestCostSheetID($rows['COMID']);
            $obj->viewFreightCostEstimationTempleteRecordsNew($fcaid);
			$cpdate = strtotime($obj->getFun112());
			if($txtFrom_Date <= $cpdate && $cpdate <= $txtTo_Date)
			{
				$arr       = $obj->getLoadPortAndDischargePortArrBasedOnCommidAndProcessWithoutTBN($comid,$fcaid);
				$port_arr  = $obj->getLoadPortAndDischargePortArrBasedOnCommidAndProcessWithoutTBN($comid,$fcaid);
				
				$lp_name = array(); $dp_name =array(); $lp_name_1 = array(); $dp_name_1 = array(); $totals = 0;
				$lp_turnTime = array();$dp_turnTime = array();$lp_ttterms = array();$dp_ttterms = array();$lp_loadRate = array();$dp_loadRate = array();
				$lp_laytime = array();$dp_laytime = array();$lp_Alaytime = array();$dp_Alaytime = array();$lp_timetodum = array();$dp_timetodum = array();
				for($i=0;$i<count($arr);$i++)
				{
					$arr_portval = explode('@@',$arr[$i]);
					if($arr_portval[0] == "LP" && $arr_explode[8]=='')
					{
						$sql1 = "select * from laytime_master where COMID='".$rows['COMID']."' and LOGIN='INTERNAL_USER' and PORT='LP' and PORTID='".$arr_portval[1]."' and RANDOMID='".$arr_portval[2]."'";
						$res1 = mysql_query($sql1);
						$rec1 = mysql_num_rows($res1);
						$rows1 = mysql_fetch_assoc($res1);
						
						if($rows1['TTL_DEMURRAGE'] == 0 && $rows1['TTL_DESPATCH'] == 0){$value = 0;}
						if($rows1['TTL_DEMURRAGE'] == 0){$value = "-".$rows1['TTL_DESPATCH'];}
						if($rows1['TTL_DESPATCH'] == 0){$value = $rows1['TTL_DEMURRAGE'];}
						
						if($rec1 > 0){$lp_name_1[]= 'LP- '.$obj->getPortNameBasedOnID($arr_portval[1]).'- '.$obj->getNumberFormat($value); $totals = $totals+$value;}
						$lp_name[]= 'LP-'.$obj->getPortNameBasedOnID($arr_portval[1]);
						$lp_turnTime[]= 'LP- '.$obj->getPortNameBasedOnID($arr_portval[1]).'- '.$obj->getNumberFormat($rows1['TURN_TIME']);
						$lp_ttterms[]= 'LP- '.$obj->getPortNameBasedOnID($arr_portval[1]).'- '.$rows1['TT_TERMS'];
						$lp_loadRate[]= 'LP- '.$obj->getPortNameBasedOnID($arr_portval[1]).'- '.$rows1['LOADED_RATE'];
						$lp_laytime[]= 'LP- '.$obj->getPortNameBasedOnID($arr_portval[1]).'- '.$rows1['LAYTIME_ALLOWED'];
						$lp_Alaytime[]= 'LP- '.$obj->getPortNameBasedOnID($arr_portval[1]).'- '.$rows1['ACTUAL_LAYTIME'];
						if($rows1['TIME_TO_DEMURRAGE'] >0)
						{$lp_timetodum[]= 'LP- '.$obj->getPortNameBasedOnID($arr_portval[1]).'- DEM- '.$rows1['TIME_TO_DEMURRAGE'];}
						else
						{$lp_timetodum[]= 'LP- '.$obj->getPortNameBasedOnID($arr_portval[1]).'- DES- '.$rows1['TIME_TO_DESPATCH'];}
					}
					if($arr_portval[0] == "DP" && $arr_explode[8]=='')
					{
						$sql1 = "select * from laytime_master where COMID='".$rows['COMID']."' and LOGIN='INTERNAL_USER' and PORT='DP' and PORTID='".$arr_portval[1]."' and RANDOMID='".$arr_portval[2]."'";
						$res1 = mysql_query($sql1);
						$rec1 = mysql_num_rows($res1);
						$rows1 = mysql_fetch_assoc($res1);
						
						if($rows1['TTL_DEMURRAGE'] == 0 && $rows1['TTL_DESPATCH'] == 0){$value = 0;}
						if($rows1['TTL_DEMURRAGE'] == 0){$value = "-".$rows1['TTL_DESPATCH'];}
						if($rows1['TTL_DESPATCH'] == 0){$value = $rows1['TTL_DEMURRAGE'];}
						
						if($rec1 > 0){$dp_name_1[]= 'DP-'.$obj->getPortNameBasedOnID($arr_portval[1]).'-'.$obj->getNumberFormat($value); $totals = $totals+$value;}
						$dp_name[]= 'DP-'.$obj->getPortNameBasedOnID($arr_portval[1]);
						$dp_turnTime[]= 'DP-'.$obj->getPortNameBasedOnID($arr_portval[1]).'-'.$obj->getNumberFormat($rows1['TURN_TIME']);
						$dp_ttterms[]= 'DP-'.$obj->getPortNameBasedOnID($arr_portval[1]).'- '.$rows1['TT_TERMS'];
						$dp_loadRate[]= 'DP-'.$obj->getPortNameBasedOnID($arr_portval[1]).'- '.$rows1['LOADED_RATE'];
						$dp_laytime[]= 'DP-'.$obj->getPortNameBasedOnID($arr_portval[1]).'- '.$rows1['LAYTIME_ALLOWED'];
						$dp_Alaytime[]= 'DP-'.$obj->getPortNameBasedOnID($arr_portval[1]).'- '.$rows1['ACTUAL_LAYTIME'];
						if($rows1['TIME_TO_DEMURRAGE'] >0)
						{$dp_timetodum[]= 'DP- '.$obj->getPortNameBasedOnID($arr_portval[1]).'- DEM- '.$rows1['TIME_TO_DEMURRAGE'];}
						else
						{$dp_timetodum[]= 'DP- '.$obj->getPortNameBasedOnID($arr_portval[1]).'- DES- '.$rows1['TIME_TO_DESPATCH'];}
					}
				}
				
				if(count($lp_name) >0 && count($dp_name) >0)
				{$portsdata = implode(',<br/>',$lp_name).'<br/><br/>'.implode(',<br/>',$dp_name);}
				if(count($lp_name)==0)
				{$portsdata = implode(',<br/>',$dp_name);}
				if(count($dp_name)==0)
				{$portsdata = implode(',<br/>',$lp_name);}
				
				if(count($lp_name_1) >0 && count($dp_name_1) >0)
				{$portsdata_1 = implode(',<br/>',$lp_name_1).'<br/><br/>'.implode(',<br/>',$dp_name_1);}
				if(count($lp_name_1)==0)
				{$portsdata_1 = implode(',<br/>',$dp_name_1);}
				if(count($dp_name_1)==0)
				{$portsdata_1 = implode(',<br/>',$lp_name_1);}
				
				if(count($lp_turnTime) >0 && count($dp_turnTime) >0)
				{$portsdata_2 = implode(',<br/>',$lp_turnTime).'<br/><br/>'.implode(',<br/>',$dp_turnTime);}
				if(count($lp_turnTime)==0)
				{$portsdata_2 = implode(',<br/>',$dp_turnTime);}
				if(count($dp_turnTime)==0)
				{$portsdata_2 = implode(',<br/>',$lp_turnTime);}
				
				if(count($lp_ttterms) >0 && count($dp_ttterms) >0)
				{$portsdata_3 = implode(',<br/>',$lp_ttterms).'<br/><br/>'.implode(',<br/>',$dp_ttterms);}
				if(count($lp_ttterms)==0)
				{$portsdata_3 = implode(',<br/>',$dp_ttterms);}
				if(count($dp_ttterms)==0)
				{$portsdata_3 = implode(',<br/>',$lp_ttterms);}
				
				if(count($lp_loadRate) >0 && count($dp_loadRate) >0)
				{$portsdata_4 = implode(',<br/>',$lp_loadRate).'<br/><br/>'.implode(',<br/>',$dp_loadRate);}
				if(count($lp_loadRate)==0)
				{$portsdata_4 = implode(',<br/>',$dp_loadRate);}
				if(count($dp_loadRate)==0)
				{$portsdata_4 = implode(',<br/>',$lp_loadRate);}
				
				if(count($lp_laytime) >0 && count($dp_laytime) >0)
				{$portsdata_5 = implode(',<br/>',$lp_laytime).'<br/><br/>'.implode(',<br/>',$dp_laytime);}
				if(count($lp_laytime)==0)
				{$portsdata_5 = implode(',<br/>',$dp_laytime);}
				if(count($dp_laytime)==0)
				{$portsdata_5 = implode(',<br/>',$lp_laytime);}
				
				if(count($lp_Alaytime) >0 && count($dp_Alaytime) >0)
				{$portsdata_6 = implode(',<br/>',$lp_Alaytime).'<br/><br/>'.implode(',<br/>',$dp_Alaytime);}
				if(count($lp_Alaytime)==0)
				{$portsdata_6 = implode(',<br/>',$dp_Alaytime);}
				if(count($dp_Alaytime)==0)
				{$portsdata_6 = implode(',<br/>',$lp_Alaytime);}
				
				if(count($lp_timetodum) >0 && count($dp_timetodum) >0)
				{$portsdata_7 = implode(',<br/>',$lp_timetodum).'<br/><br/>'.implode(',<br/>',$dp_timetodum);}
				if(count($lp_timetodum)==0)
				{$portsdata_7 = implode(',<br/>',$dp_timetodum);}
				if(count($dp_timetodum)==0)
				{$portsdata_7 = implode(',<br/>',$lp_timetodum);}
				
				
				if($chk == 1){if($totals == 0){$var = 0;}else{$var = 1;}}
				else{$var = 1;}
				$quantity = 0;
				
				
				$quantity = 0;$coa_spot = '';
				if($obj->getFun175()!='')
				{   
				    $coa_spot = 'COA'; 
					$sql12 = "select sum(CARGO_MT) as sum1, sum(CARGO_CBM) as sum2 from freight_cost_estimete_slave10 where FCAID='".$fcaid."' and STATUS=1";
					$res12 = mysql_query($sql12);
					$row12 = mysql_fetch_assoc($res12);
					if($obj->getCompareEstimateData($rows['COMID'],"ESTIMATE_TYPE")==1)
					{
						$quantity = $row12['sum2'];
					}
					else if($obj->getCompareEstimateData($rows['COMID'],"ESTIMATE_TYPE")==2)
					{
						$quantity = $row12['sum2'];
					}
					else
					{
					   $quantity = $row12['sum1'];
					}
					
				}
				else
				{
					$coa_spot = 'SPOT';
					if($obj->getCompareEstimateData($rows['COMID'],"ESTIMATE_TYPE")==1)
					{
						$quantity = $obj->getCompareEstimateData($rows['COMID'],"GAS_QUANTITY");
					}
					else if($obj->getCompareEstimateData($rows['COMID'],"ESTIMATE_TYPE")==2)
					{
						$quantity = $obj->getCompareEstimateData($rows['COMID'],"TANK_QUANTITY");
					}
					else
					{
						if($obj->getCompareEstimateData($rows['COMID'],"QTY_TYPE_RADIO")== 1)
						{
							$quantity = $obj->getCompareEstimateData($rows['COMID'],"QUANTITY");
						}
						else
						{
							$sql12 = "select sum(QUANTITY) as sum from freight_cost_estimete_slave7 where FCAID='".$fcaid."'";
							$res12 = mysql_query($sql12);
							$row12 = mysql_fetch_assoc($res12);
							$quantity = $row12['sum'];
						}
					}
					
				}
				
				if($var == 1)
				{
					echo '<tr>';
					echo '<td align="left" valign="middle" >'.$j.'.</td>';
					echo '<td align="left" valign="middle">'.$obj->getCompareTableData($rows['COMID'],"MESSAGE").'</td>';
					echo '<td align="left" valign="middle">'.$obj->getFun8().'</td>';
					echo '<td align="left" valign="middle">'.$obj->getVesselIMOData($obj->getFun5(),"VESSEL_NAME").'</td>';
					echo '<td align="left" valign="middle">'.$coa_spot.'</td>';
					echo '<td align="left" valign="middle">'.date("d-m-Y",strtotime($obj->getFun112())).'</td>';
					echo '<td align="left" valign="middle">'.$quantity.'</td>';
					echo '<td align="left" valign="middle">'.$portsdata.'</td>';
					
					echo '<td align="left" valign="middle">'.$portsdata_2.'</td>';
					echo '<td align="left" valign="middle">'.$portsdata_3.'</td>';
					echo '<td align="left" valign="middle">'.$portsdata_4.'</td>';
					echo '<td align="left" valign="middle">'.$portsdata_5.'</td>';
					echo '<td align="left" valign="middle">'.$portsdata_6.'</td>';
					echo '<td align="left" valign="middle">'.$portsdata_7.'</td>';
					
					echo '<td align="left" valign="middle">'.$portsdata_1.'</td>';
					echo '<td align="center" valign="middle">'.$obj->getNumberFormat($totals).'</td>';
					
					$net_effect = $totals/$obj->getFun50();
					echo '<td align="center" valign="middle">'.$obj->getNumberFormat($net_effect).'</td>';
					echo '</tr>';
					
					$j++;
				}
			}
		}
	}
	
	echo '</tbody>';
	echo '</table>';
}


function getSpoyFixtureReport()
{
	$obj 		  = new data();
	$connect	  = $obj->funConnect();
	
	$txtFrom_Date = strtotime($_REQUEST['txtFrom_Date']);
	$txtTo_Date   = strtotime($_REQUEST['txtTo_Date']);
	$selBType     = $_REQUEST['selBType'];
	
	
	$sql = "select freight_cost_estimate_compare.COMID as COMID, freight_cost_estimete_master.VESSEL_IMO_ID as VESSEL_IMO_ID, freight_cost_estimate_compare.MESSAGE as MESSAGE, freight_cost_estimete_master.COA_SPOT as COA_SPOT, freight_cost_estimete_master.FIXTURETYPEID as FIXTURETYPEID from freight_cost_estimate_compare inner join freight_cost_estimete_master on freight_cost_estimete_master.FCAID= freight_cost_estimate_compare.FCAID WHERE freight_cost_estimate_compare.MODULEID='".$_SESSION['moduleid']."' AND freight_cost_estimate_compare.MCOMPANYID='".$_SESSION['company']."' and freight_cost_estimate_compare.FINAL_ID!='' and freight_cost_estimete_master.FIXED=1 and freight_cost_estimate_compare.STATUS=1 and (freight_cost_estimete_master.CP_DATE!='0000-00-00' or freight_cost_estimete_master.CP_DATE is not NULL) and freight_cost_estimete_master.ESTIMATE_TYPE='".$selBType."' order by freight_cost_estimete_master.FCAID desc"; 
	$res 		  = mysql_query($sql) or die($sql);
	$rec     	  = mysql_num_rows($res);
	$i=1;
	$cost_sheet_id = "";
	$arr = array();
	
	if($rec == 0)
	{
		
	}else{
	
		while($rows = mysql_fetch_assoc($res))
		{
			$cp_date = $obj->getCompareEstimateData($rows['COMID'],"CP_DATE");
			$cpdate = strtotime($cp_date);
			
			if($txtFrom_Date <= $cpdate && $cpdate <= $txtTo_Date)
			{
				if($rows['COA_SPOT'] == 1)
				{
					$arr_load = $arr_discharge = array();
					$sql1 = "select FROM_PORT, TO_PORT, LOAD_PORT_COST, LOAD_PORT_QTY, DISC_PORT_COST, DISC_PORT_QTY from freight_cost_estimete_slave1 where FCAID='".$obj->getCompareEstimateData($rows['COMID'],"FCAID")."'";
					$res1 = mysql_query($sql1);
					while($row1 = mysql_fetch_assoc($res1))
					{
						if($row1['LOAD_PORT_QTY']>0)
						{
							$arr_load[] = $obj->getPortNameBasedOnID($row1['FROM_PORT']);
						}
						if($row1['DISC_PORT_QTY']>0)
						{
							$arr_discharge[] = $obj->getPortNameBasedOnID($row1['TO_PORT']);
						}
					}
					
					echo '<tr>';
					echo '<td align="center" valign="middle">'.$i.'.</td>';
					echo '<td align="left" valign="middle">'.$obj->getCompareEstimateData($rows['COMID'],"VOYAGE_NAME").'</td>';
					echo '<td align="left" valign="middle">'.$obj->getVesselIMOData($obj->getCompareEstimateData($rows['COMID'],"VESSEL_IMO_ID"),"VESSEL_NAME").'</td>';
					if(date("d-M-Y",strtotime($cp_date)) == "01-Jan-1970")
					{
						echo '<td align="left" valign="middle"></td>';
					}
					else
					{
						echo '<td align="left" valign="middle">'.date("d-m-Y",strtotime($cp_date)).'</td>';
					}
					
					$sql2 = "select * from freight_cost_estimete_slave4 where FCAID='".$obj->getCompareEstimateData($rows['COMID'],"FCAID")."'";
					$res2 = mysql_query($sql2);
					$rec2 = mysql_num_rows($res2);
					$vendorid = array();
					while($rows2 = mysql_fetch_assoc($res2))
					{
						$vendorid[] = $obj->getVendorListNewBasedOnID($rows2['VENDORID']);
					}
					
					echo '<td align="left" valign="middle">'.$obj->getVendorListNewBasedOnID($obj->getCompareEstimateData($rows['COMID'],"DTCVENDORID")).'</td>';
					echo '<td align="left" valign="middle">'.implode(', ',$vendorid).'</td>';
					echo '<td align="left" valign="middle">'.$obj->getCompareEstimateData($rows['COMID'],"VESSEL_TYPE").'</td>';
					
					$quantity = $freight = 0;
					if($obj->getCompareEstimateData($rows['COMID'],"ESTIMATE_TYPE")==1)
					{
						$quantity = $obj->getCompareEstimateData($rows['COMID'],"GAS_QUANTITY");
						if($obj->getCompareEstimateData($rows['COMID'],"GAS_MARKET"))
						{
							$freight = $obj->getCompareEstimateData($rows['COMID'],"GAS_QUANTITY");
						}
						else
						{
							$freight = number_format(($obj->getCompareEstimateData($rows['COMID'],"GAS_BALTIC") + $obj->getCompareEstimateData($rows['COMID'],"ADDNL_PRENIUM"))*$obj->getCompareEstimateData($rows['COMID'],"GAS_QUANTITY"), 2, '.', '');
						}
					}
					else if($obj->getCompareEstimateData($rows['COMID'],"ESTIMATE_TYPE")==2)
					{
						$quantity = $obj->getCompareEstimateData($rows['COMID'],"TANK_QUANTITY");
						$sql12 = "select sum(TOTAL_AMOUNT) as sum1 from freight_cost_estimete_slave12 where FCAID='".$obj->getCompareEstimateData($rows['COMID'],"FCAID")."'";
						$res12 = mysql_query($sql12);
						$row12 = mysql_fetch_assoc($res12);
						$freight  = $row12['sum1'];
					}
					else
					{
						if($obj->getCompareEstimateData($rows['COMID'],"QTY_TYPE_RADIO")== 1)
						{
							$quantity = $obj->getCompareEstimateData($rows['COMID'],"QUANTITY");
							$freight  = $obj->getCompareEstimateData($rows['COMID'],"NET_PAYABLE");
						}
						else
						{
							$sql12 = "select sum(QUANTITY) as sum, sum(NET_FREIGHT) as sum2 from freight_cost_estimete_slave7 where FCAID='".$obj->getCompareEstimateData($rows['COMID'],"FCAID")."'";
							$res12 = mysql_query($sql12);
							$row12 = mysql_fetch_assoc($res12);
							$quantity = $row12['sum'];
							$freight  = number_format($row12['sum2'], 2, '.', '');
						}
					}
					echo '<td align="left" valign="middle">'.$quantity.'</td>';
					echo '<td align="left" valign="middle">'.implode(', ',$arr_load).'</td>';
					echo '<td align="left" valign="middle">'.implode(', ',$arr_discharge).'</td>';
					
					echo '<td align="left" valign="middle">'.$freight.'</td>';
					echo '</tr>';
					$i++;
				}
			}
		}
	}		
}


function getOwner_brokerWiseFreightReport()
{
	$obj 		= new data();
	$connect	= $obj->funConnect();
	
	$selVendor = $_REQUEST['selVendor'];
	$selBOwner = $_REQUEST['selBOwner'];
	$selBType  = $_REQUEST['selBType'];
	
	if($selBOwner == 11){$label = "Owner";$label1 = "Broker";}else if($selBOwner == 12){$label = "Broker";$label1 = "Owner";}
	
	echo '<table id="Owner_broker_wise_fixture_report" class="table table-bordered table-striped dataTable">';
	echo '<thead>';
	echo '<tr>';
	echo '<th align="left" valign="top" width="10%">Sr. No</th>';
	echo '<th align="left" valign="top" width="10%">'.$label.'</th>';
	echo '<th align="left" valign="top" width="10%">Vessel&nbsp;Type</th>';
	echo '<th align="left" valign="top" width="10%">Voyage Financials Name</th>';
	echo '<th align="left" valign="top" width="10%">Vessel Name</th>';
	echo '<th align="left" valign="top" width="10%">CP Date</th>';
	echo '<th align="left" valign="top" width="10%">Contract Qty</th>';
	echo '<th align="left" valign="top" width="10%">Business Type</th>';
	echo '<th align="left" valign="top" width="10%">'.$label1.'</th>';
	echo '</tr>';
	echo '</thead>';
	echo '<tbody>';
	$sql1 = "select * from vessel_type_master where STATUS=1 and BusinessType='".$selBType."' order by VesselType";
	$res1 = mysql_query($sql1);
	
	while($rows1 = mysql_fetch_assoc($res1))
	{
		$sql = "select freight_cost_estimate_compare.COMID, freight_cost_estimete_master.FCAID from freight_cost_estimate_compare inner join freight_cost_estimete_master on freight_cost_estimete_master.FCAID= freight_cost_estimate_compare.FCAID WHERE freight_cost_estimate_compare.MODULEID='".$_SESSION['moduleid']."' AND freight_cost_estimate_compare.MCOMPANYID='".$_SESSION['company']."' and freight_cost_estimate_compare.FINAL_ID!='' and freight_cost_estimete_master.FIXED=1 and freight_cost_estimate_compare.STATUS=1 and freight_cost_estimete_master.VESSEL_TYPE='".$rows1['VesselType']."' and freight_cost_estimete_master.ESTIMATE_TYPE='".$selBType."'  order by freight_cost_estimete_master.FCAID desc"; 
		//echo $sql."##";
		$res = mysql_query($sql) or die($sql);
		$rec = mysql_num_rows($res1);
		$i=1;
		$cost_sheet_id = "";
		$arr = array();
		while($rows = mysql_fetch_assoc($res))
		{       
		        $fcaid = $obj->getCompareEstimateData($rows['COMID'],"FCAID");
				$obj->viewFreightCostEstimationTempleteRecordsNew($fcaid);

				if($selBOwner == 11)
				{
					if($selVendor == $obj->getCompareEstimateData($rows['COMID'],"DTCVENDORID"))
					{
						echo '<tr>';
						echo '<td align="center" valign="middle">'.$i.'.</td>';
						echo '<td align="left" valign="middle">'.$obj->getVendorListNewBasedOnID($obj->getCompareEstimateData($rows['COMID'],"DTCVENDORID")).'</td>';
						echo '<td align="left" valign="middle">'.$obj->getCompareEstimateData($rows['COMID'],"VESSEL_TYPE").'</td>';
						echo '<td align="left" valign="middle">'.$obj->getCompareEstimateData($rows['COMID'],"VOYAGE_NAME").'</td>';
						echo '<td align="left" valign="middle">'.$obj->getVesselIMOData($obj->getCompareEstimateData($rows['COMID'],"VESSEL_IMO_ID"),"VESSEL_NAME").'</td>';
						$cpdate = $obj->getCompareEstimateData($rows['COMID'],"CP_DATE");
						if(date("d-M-Y",strtotime($cpdate)) == "01-Jan-1970")
						{
							echo '<td align="left" valign="middle"></td>';
						}
						else
						{
							echo '<td align="left" valign="middle">'.date("d-m-Y",strtotime($cpdate)).'</td>';
						}
						$quantity = 0;
						if($obj->getCompareEstimateData($rows['COMID'],"ESTIMATE_TYPE")==1)
						{
							$quantity = $obj->getCompareEstimateData($rows['COMID'],"GAS_QUANTITY");
						}
						else if($obj->getCompareEstimateData($rows['COMID'],"ESTIMATE_TYPE")==2)
						{
							$quantity = $obj->getCompareEstimateData($rows['COMID'],"TANK_QUANTITY");
						}
						else
						{
							if($obj->getCompareEstimateData($rows['COMID'],"QTY_TYPE_RADIO")== 1)
							{
								$quantity = $obj->getCompareEstimateData($rows['COMID'],"QUANTITY");
							}
							else
							{
								$sql12 = "select sum(QUANTITY) as sum from freight_cost_estimete_slave7 where FCAID='".$fcaid."'";
								$res12 = mysql_query($sql12);
								$row12 = mysql_fetch_assoc($res12);
								$quantity = $row12['sum'];
							}
						}
						echo '<td align="left" valign="middle">'.$quantity.'</td>';
						echo '<td align="left" valign="middle">'.$obj->getBusinessTypeBasedOnID1($obj->getCompareEstimateData($rows['COMID'],"ESTIMATE_TYPE")).'</td>';
						$sql2 = "select * from freight_cost_estimete_slave4 where FCAID='".$obj->getFun1()."'";
						$res2 = mysql_query($sql2);
						$rec2 = mysql_num_rows($res2);
						$vendorid = array();
						while($rows2 = mysql_fetch_assoc($res2))
						{
							$vendorid[] = $obj->getVendorListNewBasedOnID($rows2['VENDORID']);
						}
						echo '<td align="left" valign="middle" >'.implode(', ',$vendorid).'</td>';
						echo '</tr>';
						$i++;
					}
				}
				else if($selBOwner == 12)
				{
					$sql2 = "select * from freight_cost_estimete_slave4 where FCAID='".$obj->getFun1()."'";
					$res2 = mysql_query($sql2);
					$rec2 = mysql_num_rows($res2);
					$vendorid = array();
					while($rows2 = mysql_fetch_assoc($res2))
					{
						if($selVendor == $rows2['VENDORID'])
						{  
							echo '<tr>';
							echo '<td align="center" valign="middle">'.$i.'.</td>';
							echo '<td align="left" valign="middle">'.$obj->getVendorListNewBasedOnID($rows2['VENDORID']).'</td>';
							echo '<td align="left" valign="middle">'.$obj->getCompareEstimateData($rows['COMID'],"VESSEL_TYPE").'</td>';
							echo '<td align="left" valign="middle">'.$obj->getCompareEstimateData($rows['COMID'],"VOYAGE_NAME").'</td>';
							echo '<td align="left" valign="middle">'.$obj->getVesselIMOData($obj->getCompareEstimateData($rows['COMID'],"VESSEL_IMO_ID"),"VESSEL_NAME").'</td>';
							$cpdate = $obj->getCompareEstimateData($rows['COMID'],"CP_DATE");
							if(date("d-M-Y",strtotime($cpdate)) == "01-Jan-1970")
							{
								echo '<td align="left" valign="middle"></td>';
							}
							else
							{
								echo '<td align="left" valign="middle">'.date("d-m-Y",strtotime($cpdate)).'</td>';
							}
							$quantity = 0;
							if($obj->getCompareEstimateData($rows['COMID'],"ESTIMATE_TYPE")==1)
							{
								$quantity = $obj->getCompareEstimateData($rows['COMID'],"GAS_QUANTITY");
							}
							else if($obj->getCompareEstimateData($rows['COMID'],"ESTIMATE_TYPE")==2)
							{
								$quantity = $obj->getCompareEstimateData($rows['COMID'],"TANK_QUANTITY");
							}
							else
							{
								if($obj->getCompareEstimateData($rows['COMID'],"QTY_TYPE_RADIO")== 1)
								{
									$quantity = $obj->getCompareEstimateData($rows['COMID'],"QUANTITY");
								}
								else
								{
									$sql12 = "select sum(QUANTITY) as sum from freight_cost_estimete_slave7 where FCAID='".$fcaid."'";
									$res12 = mysql_query($sql12);
									$row12 = mysql_fetch_assoc($res12);
									$quantity = $row12['sum'];
								}
							}
							echo '<td align="left" valign="middle">'.$quantity.'</td>';
							echo '<td align="left" valign="middle">'.$obj->getFreightFixtureBasedOnID($obj->getCompareEstimateData($rows['COMID'],"FIXTURETYPEID")).'</td>';
							echo '<td align="left" valign="middle" >'.$obj->getVendorListNewBasedOnID($obj->getFun140()).'</td>';
							echo '</tr>';
							$i++;
						}
					}
				}		
		}
		if($i > 1)
		{
			echo '<tr>';
			echo '<td align="left" valign="middle" colspan="2">Total '.$rows1['VesselType'].'</td>';	
			echo '<td align="left" valign="middle" colspan="9">'.($i-1).'</td>';
			echo '</tr>';
		}
	}
	echo '</tbody>';
	echo '</table>';	
}


function getDailyLogRecord()
{
	$obj = new data();
	$connect=$obj->funConnect();
	
	$txtDate 		= $_REQUEST['txtDate'];
	
	$obj->insertLastDateDailyLogData(date("Y-m-d",strtotime($txtDate)));
	
	echo '<tr height="10"><td align="right" colspan="5"><a title="Generate PDF" href="#Pdf" onclick="getPdf();" ><img src="../../images/pdf_button.png" border="0" height="20" width="20" /></a>&nbsp;&nbsp;<a href="#?" title="Excel" onclick="getExcel();"><img src="../../images/excel.gif"  /></a></td></tr>';
	echo '<tr height="10"><td align="right" colspan="5"></td></tr>';
	
	echo '<tr height="10"><td align="center" colspan="5">';
	echo '<table cellpadding="1" cellspacing="1" border="0" width="100%" class="tablesorter" style="background-color:#808080;">';
	echo '<thead>';
	echo '<tr valign="top" style="font-size:10px; color:#fff;">';
	echo '<th align="left">Vessel</th>';
	echo '<th align="left">Material Description</th>';
	echo '<th align="left">Fixture Type</th>';
	echo '<th align="left">Load Port(s)</th>';
	echo '<th align="left">Discharge Port(s)</th>';
	echo '<th align="left">Load / Disch (In Last 24 Hrs)</th>';
	echo '<th align="left">Total Load / Disch</th>';
	echo '<th align="left">Balance To Load / Disch</th>';
	echo '<th align="left">Port Status</th>';
	echo '<th align="left">Edit</th>';
	echo '</tr>';
	echo '</thead>';
	echo '<tbody>';
	
	$sql = "select * from mapping_master where MODULEID='".$_SESSION['moduleid']."'  AND MCOMPANYID='".$_SESSION['company']."' and STATUS=2 order by MAPPINGID";
	$res = mysql_query($sql);
	$rec = mysql_num_rows($res);
	if($rec == 0)
	{
		echo '<tr>';
		echo '<td align="center" valign="middle" colspan="8" style="color:red;letter-spacing:1px;">SORRY CURRENTLY THERE ARE ZERO(0) RECORDS.</td>';
		echo '</tr>';
	}
	else
	{
		$j = 1;
		while($rows = mysql_fetch_assoc($res))
		{
			$cost_sheet_id = $obj->getLatestCostSheetID($rows['MAPPINGID']);
			$arr  = $obj->getLoadPortAndDischargePortArrBasedOnMappingidAndProcessWithoutTBN($rows['MAPPINGID'],$cost_sheet_id);
			$port_arr  = $obj->getLoadPortAndDischargePortArrBasedOnIDMappingidAndProcessWithoutTBN($rows['MAPPINGID'],$cost_sheet_id);
			
			$lp_name = ''; $dp_name = '';
			$obj->viewFreightEstimationRecords($rows['MAPPINGID'],$cost_sheet_id);
			for($i=0;$i<count($arr);$i++)
			{
				$sql3 = "select COUNTRY_NAME from PORT_MASTER where PortId='".$port_arr[$i]."'";
				$res3 = mysql_query($sql3);
				$rows3 = mysql_fetch_assoc($res3);
				
				if(substr($arr[$i],0,2) == "LP"){$lp_name .= substr($arr[$i],5).' ('.$obj->getCountryNameOnId($rows3['COUNTRY_NAME']).'),</br>';}
				else{$dp_name .= substr($arr[$i],5).',</br>';}
			}
			
			$lp_name = substr($lp_name,0,-6);
			$dp_name = substr($dp_name,0,-6);
			
			$sql1 = "select * from daily_log where MAPPINGID='".$rows['MAPPINGID']."' and TRANS_DATE='".date("Y-m-d",strtotime($txtDate))."'";
			$res1 = mysql_query($sql1);
			$rec1 = mysql_num_rows($res1);
			$rows1 = mysql_fetch_assoc($res1);
			
			echo '<tr id="row_1_'.$j.'" style="font-size:11px;">';
			echo '<td align="left" valign="middle">'.$obj->getVesselIMOData($obj->getVesselOpenEntryDeta($obj->getMappingData($rows['MAPPINGID'],"OPEN_VESSEL_ID"),"VESSEL_IMO_ID"),"VESSEL_NAME").'</td>';
			echo '<td align="left" valign="middle">'.$obj->getCargoContarctForMapping($obj->getMappingData($rows['MAPPINGID'],"CARGO_IDS"),$obj->getMappingData($rows['MAPPINGID'],"CARGO_POSITION"),$obj->getMappingData($rows['MAPPINGID'],"SHIPPING_STAGE")).'</td>';
			echo '<td align="left" valign="middle">'.$obj->getFreightFixtureBasedOnID($obj->getFun2()).'</td>';
			echo '<td align="left" valign="middle">'.$lp_name.'</td>';
			echo '<td align="left" valign="middle">'.$dp_name.'</td>';
			echo '<td align="left" valign="middle">'.$rows1['DAILY_CARGO_QTY'].'</td>';
			echo '<td align="left" valign="middle">'.$rows1['TTL_CARGO_QTY'].'</td>';
			echo '<td align="left" valign="middle">'.$rows1['BAL_QTY'].'</td>';
			echo '<td align="left" valign="middle">'.$rows1['PORT_STATUS'].'</td>';
			echo '<td align="left" valign="middle"><button class="ox-button" id="inner-login-button" type="button" onclick="getView('.$j.')"><b><span id="d27e53" style="color:#000000;">Edit</span></b></button></td>';
			echo '</tr>';
			
			$j++;
			
			if($rec1 == 0)
			{
				$sql2 = "select max(TRANS_DATE) as max from daily_log where MAPPINGID='".$rows['MAPPINGID']."' and TRANS_DATE<'".date("Y-m-d",strtotime($txtDate))."'";
				$res2 = mysql_query($sql2);
				$rows2 = mysql_fetch_assoc($res2);
				
				$sql1 = "select * from daily_log where MAPPINGID='".$rows['MAPPINGID']."' and TRANS_DATE='".date("Y-m-d",strtotime($rows2['max']))."'";
				$res1 = mysql_query($sql1);
				$rows1 = mysql_fetch_assoc($res1);
			}
			
			echo '<tr id="row_2_'.$j.'" style="display:none;">';
			echo '<td align="left" valign="middle" colspan="10">';
			echo '<table cellpadding="1" cellspacing="1" border="0" width="100%">';
			echo '<tr style="font-size:11px;">';
			echo '<td align="left" valign="middle">Load / Disch (In Last 24 Hrs)</td>';
			echo '<td align="left" valign="middle">:</td>';
			echo '<td align="left" valign="middle"><textarea class="animated" name="txtLCLdd_'.$j.'" id="txtLCLdd_'.$j.'" cols="14" rows="1">'.$rows1['DAILY_CARGO_QTY'].'</textarea></td>';
			echo '<td align="left" valign="middle">Total Load / Disch</td>';
			echo '<td align="left" valign="middle">:</td>';
			echo '<td align="left" valign="middle"><textarea class="animated" name="txtTtlCLdd_'.$j.'" id="txtTtlCLdd_'.$j.'" cols="14" rows="1">'.$rows1['TTL_CARGO_QTY'].'</textarea></td>';
			echo '</tr>';
			echo '<tr style="font-size:11px;">';
			echo '<td align="left" valign="middle">Balance To Load / Disch</td>';
			echo '<td align="left" valign="middle">:</td>';
			echo '<td align="left" valign="middle"><textarea class="animated" name="txtBTLd_'.$j.'" id="txtBTLd_'.$j.'" cols="14" rows="1">'.$rows1['BAL_QTY'].'</textarea></td>';
			echo '<td align="left" valign="middle">Port Status</td>';
			echo '<td align="left" valign="middle">:</td>';
			echo '<td align="left" valign="middle"><textarea class="animated" name="txtPortStatus_'.$j.'" id="txtPortStatus_'.$j.'" cols="14" rows="1">'.$rows1['PORT_STATUS'].'</textarea><input type="hidden" name="txtMappingid_'.$j.'" id="txtMappingid_'.$j.'" size="10" readonly="true" value="'.$rows['MAPPINGID'].'"/></td>';
			echo '</tr>';
			echo '<tr>';
			echo '<td align="right" valign="middle" colspan="6"><button class="ox-button" id="inner-login-button" type="submit" onclick="return getSubmit('.$j.');" ><b><span id="d27e53" >Submit</span></b></button></td>';
			echo '</tr>';
			echo '</table>';
			echo '</td>';
			echo '</tr>';
			
			$j++;
		}
	}
	echo '</tbody>';
	echo '</table>';
	echo '</td><tr>';
}


function getCOAReportData()
{
	$obj = new data();
	$connect=$obj->funConnect();
	
	$curr_fyear = $_REQUEST['selFYear'];
	
	//$year = date("Y",time());
	//if(date("m",time()) < '04'){$curr_fyear = ($year-1)."-".$year;$curr_year = ($year-1);}
	//else{$curr_fyear = $year."-".($year+1);$curr_year = $year;}
	
	$curr_fyear_arr = explode("-",$curr_fyear);
	echo '<h3 style=" text-align:center;">'.$curr_fyear.' COA Status Sheet</h3>';	
	echo '<div id="bunker_adj" class="box-body table-responsive"  style="width:100%;overflow-y: hidden;overflow-x:scroll;">';
	echo '<table cellspacing="0" class="table table-bordered table-striped dataTable" id="cargo_open" style="width:100%;border-collapse:collapse;overflow:scroll;">';
	echo '<thead>';
	echo '<tr class="GridviewScrollHeader" >';
	echo '<th align="left" valign="top" >Owner</th>';
	echo '<th align="center" valign="top">COA CP Date</th>';
	echo '<th align="center" colspan="2" valign="top">Total</th>';
	echo '<th align="center" colspan="2" valign="top">Performed / Nominated</th>';
	echo '<th align="center" colspan="2" valign="top" >Balance</th>';
	echo '<th align="center" valign="top">Apr-'.$curr_fyear_arr[0].'</th>';
	echo '<th align="center" valign="top">May-'.$curr_fyear_arr[0].'</th>';
	echo '<th align="center" valign="top">Jun-'.$curr_fyear_arr[0].'</th>';
	echo '<th align="center" valign="top">July-'.$curr_fyear_arr[0].'</th>';
	echo '<th align="center" valign="top">Aug-'.$curr_fyear_arr[0].'</th>';
	echo '<th align="center" valign="top">Sep-'.$curr_fyear_arr[0].'</th>';
	echo '<th align="center" valign="top">Oct-'.$curr_fyear_arr[0].'</th>';
	echo '<th align="center" valign="top">Nov-'.$curr_fyear_arr[0].'</th>';
	echo '<th align="center" valign="top">Dec-'.$curr_fyear_arr[0].'</th>';
	echo '<th align="center" valign="top">Jan-'.($curr_fyear_arr[0]+1).'</th>';
	echo '<th align="center" valign="top">Feb-'.($curr_fyear_arr[0]+1).'</th>';
	echo '<th align="center" valign="top">Mar-'.($curr_fyear_arr[0]+1).'</th>';
	echo '<th align="center" valign="top">Notice(d)</th>';
	echo '<th align="center" valign="top">Dem</th>';
	echo '</thead>';
	
	echo '<tbody>';
	
	echo '<tr class="GridviewScrollHeader" style="font-size:12px; background-color:#eee;">';
	echo '<td>&nbsp;</td>';
	echo '<td align="center" valign="top"></td>';
	echo '<td align="center" valign="top">Vol. MT</td>';
	echo '<td align="center" valign="top">Shpmt No</td>';
	echo '<td align="center" valign="top">Vol. MT</td>';
	echo '<td align="center" valign="top">Shpmt No</td>';
	echo '<td align="center" valign="top">Vol. MT</td>';
	echo '<td align="center" valign="top">Shpmt No</td>';
	echo '<td align="center" valign="top"></td>';
	echo '<td align="center" valign="top"></td>';
	echo '<td align="center" valign="top"></td>';
	echo '<td align="center" valign="top"></td>';
	echo '<td align="center" valign="top"></td>';
	echo '<td align="center" valign="top"></td>';
	echo '<td align="center" valign="top"></td>';
	echo '<td align="center" valign="top"></td>';
	echo '<td align="center" valign="top"></td>';
	echo '<td align="center" valign="top"></td>';
	echo '<td align="center" valign="top"></td>';
	echo '<td align="center" valign="top"></td>';
	echo '<td align="center" valign="top"></td>';
	echo '<td align="center" valign="top"></td>';
	echo '</tr>';
	
	$ttl_vol_mt = $ttl_shpmt = $ttl_perf = $ttl_perf_shpmt = $blnce_vol_mt = $blnce_shpmt = 0;
		
	$sql = "select * from vessel_category_master where STATUS=1 order by NAME";
	$res  = mysql_query($sql);
	while($rows = mysql_fetch_assoc($res))
	{
		echo '<tr class="GridviewScrollItem" style="font-size:12px;color:#1E85BE; font-weight:bold;">';
		echo '<td align="left" valign="top">'.strtoupper($rows['NAME']).'</td>';
		echo '<td align="center" valign="top"></td>';
		echo '<td align="center" valign="top"></td>';
		echo '<td align="center" valign="top"></td>';
		echo '<td align="center" valign="top"></td>';
		echo '<td align="center" valign="top"></td>';
		echo '<td align="center" valign="top"></td>';
		echo '<td align="center" valign="top"></td>';
		echo '<td align="center" valign="top"></td>';
		echo '<td align="center" valign="top"></td>';
		echo '<td align="center" valign="top"></td>';
		echo '<td align="center" valign="top"></td>';
		echo '<td align="center" valign="top"></td>';
		echo '<td align="center" valign="top"></td>';
		echo '<td align="center" valign="top"></td>';
		echo '<td align="center" valign="top"></td>';
		echo '<td align="center" valign="top"></td>';
		echo '<td align="center" valign="top"></td>';
		echo '<td align="center" valign="top"></td>';
		echo '<td align="center" valign="top"></td>';
		echo '<td align="center" valign="top"></td>';
		echo '<td align="center" valign="top"></td>';
		echo '</tr>';
		
		$sql1 = "select * from coa_master where MODULEID='".$_SESSION['moduleid']."' and MCOMPANYID='".$_SESSION['company']."' and VESSEL_CATEGORY_ID='".$rows['VESSEL_CATEGORY_ID']."' and START_DATE between '".$curr_fyear_arr[0]."-04-01' and '".$curr_fyear_arr[1]."-03-31'";
		$res1 = mysql_query($sql1);
		$rec1 = mysql_num_rows($res1);
		if($rec1 == 0)
		{
			echo '<tr class="GridviewScrollItem" style="font-size:12px;color:#1E85BE; font-weight:bold;">';
			echo '<td align="center" valign="top">&nbsp;</td>';
			echo '<td align="center" valign="top"></td>';
			echo '<td align="center" valign="top"></td>';
			echo '<td align="center" valign="top"></td>';
			echo '<td align="center" valign="top"></td>';
			echo '<td align="center" valign="top"></td>';
			echo '<td align="center" valign="top"></td>';
			echo '<td align="center" valign="top"></td>';
			echo '<td align="center" valign="top"></td>';
			echo '<td align="center" valign="top"></td>';
			echo '<td align="center" valign="top"></td>';
			echo '<td align="center" valign="top"></td>';
			echo '<td align="center" valign="top"></td>';
			echo '<td align="center" valign="top"></td>';
			echo '<td align="center" valign="top"></td>';
			echo '<td align="center" valign="top"></td>';
			echo '<td align="center" valign="top"></td>';
			echo '<td align="center" valign="top"></td>';
			echo '<td align="center" valign="top"></td>';
			echo '<td align="center" valign="top"></td>';
			echo '<td align="center" valign="top"></td>';
			echo '<td align="center" valign="top"></td>';
			echo '</tr>';
		}
		else
		{
			$ttl_vol_mt_l = $ttl_shpmt_l = $ttl_perf_l = $ttl_perf_shpmt_l = $blnce_vol_mt_l = $blnce_shpmt_l = 0;
			while($rows1 = mysql_fetch_assoc($res1))
			{
				echo '<tr class="GridviewScrollItem">';
				echo '<td align="left" valign="top" >'.$obj->getVendorListNewBasedOnID($rows1['OWNER']).'</td>';
				echo '<td align="center" valign="top" >'.date("d M Y",strtotime($rows1['COA_DATE'])).'</td>';
				echo '<td align="center" valign="top" >'.$obj->getNumberFormat(($rows1['NO_OF_SHIPMENT'] * $rows['SIZE']) / 1000000).'</td>';
				echo '<td align="center" valign="top" >'.$rows1['NO_OF_SHIPMENT'].'</td>';
				
				if($obj->getPerformedVesselRec($rows1['COAID']) == 0){$perf_qty = "0.00";}else{$perf_qty = ($obj->getPerformedVesselRec($rows1['COAID']) * $rows['SIZE']) / 1000000;}
				echo '<td align="center" valign="top" >'.$obj->getNumberFormat($perf_qty).'</td>';
				echo '<td align="center" valign="top" >'.$obj->getPerformedVesselRec($rows1['COAID']).'</td>';
				
				echo '<td align="center" valign="top" >'.$obj->getNumberFormat((($rows1['NO_OF_SHIPMENT'] * $rows['SIZE']) / 1000000) - $perf_qty).'</td>';
				echo '<td align="center" valign="top" >'.($rows1['NO_OF_SHIPMENT'] - $obj->getPerformedVesselRec($rows1['COAID'])).'</td>';
				if($rows1['STATUS'] == 2)
				{
					echo '<td align="left" valign="top" colspan="12" style="color:#fff; background-color:#dc631e;">'.$rows1['CANCEL_REMARKS'].'</td>';
				}
				else
				{
					echo '<td align="left" valign="top" >'.$obj->getAttachedVesselWithCOABasedOnFinancialYear($rows1['COAID'],$curr_fyear_arr[0],"04").'</td>';
					echo '<td align="left" valign="top" >'.$obj->getAttachedVesselWithCOABasedOnFinancialYear($rows1['COAID'],$curr_fyear_arr[0],"05").'</td>';
					echo '<td align="left" valign="top" >'.$obj->getAttachedVesselWithCOABasedOnFinancialYear($rows1['COAID'],$curr_fyear_arr[0],"06").'</td>';
					echo '<td align="left" valign="top" >'.$obj->getAttachedVesselWithCOABasedOnFinancialYear($rows1['COAID'],$curr_fyear_arr[0],"07").'</td>';
					echo '<td align="left" valign="top" >'.$obj->getAttachedVesselWithCOABasedOnFinancialYear($rows1['COAID'],$curr_fyear_arr[0],"08").'</td>';
					echo '<td align="left" valign="top" >'.$obj->getAttachedVesselWithCOABasedOnFinancialYear($rows1['COAID'],$curr_fyear_arr[0],"09").'</td>';
					echo '<td align="left" valign="top" >'.$obj->getAttachedVesselWithCOABasedOnFinancialYear($rows1['COAID'],$curr_fyear_arr[0],"10").'</td>';
					echo '<td align="left" valign="top" >'.$obj->getAttachedVesselWithCOABasedOnFinancialYear($rows1['COAID'],$curr_fyear_arr[0],"11").'</td>';
					echo '<td align="left" valign="top" >'.$obj->getAttachedVesselWithCOABasedOnFinancialYear($rows1['COAID'],$curr_fyear_arr[0],"12").'</td>';
					echo '<td align="left" valign="top" >'.$obj->getAttachedVesselWithCOABasedOnFinancialYear($rows1['COAID'],$curr_fyear_arr[0],"01").'</td>';
					echo '<td align="left" valign="top" >'.$obj->getAttachedVesselWithCOABasedOnFinancialYear($rows1['COAID'],$curr_fyear_arr[0],"02").'</td>';
					echo '<td align="left" valign="top" >'.$obj->getAttachedVesselWithCOABasedOnFinancialYear($rows1['COAID'],$curr_fyear_arr[0],"03").'</td>';	
				}
				echo '<td align="center" valign="top" >'.$rows1['NOTICE_DAYS'].' (d)</td>';
				echo '<td align="center" valign="top" >'.$obj->getNumberFormat($rows1['DEMURRAGE_RATE']).'</td>';			
				echo '</tr>';
				
				$ttl_vol_mt += $obj->getNumberFormat(($rows1['NO_OF_SHIPMENT'] * $rows['SIZE']) / 1000000);
				$ttl_shpmt += $rows1['NO_OF_SHIPMENT'];
				$ttl_perf += $perf_qty;
				$ttl_perf_shpmt += $obj->getPerformedVesselRec($rows1['COAID']);
				$blnce_vol_mt += $obj->getNumberFormat((($rows1['NO_OF_SHIPMENT'] * $rows['SIZE']) / 1000000) - $perf_qty);
				$blnce_shpmt += ($rows1['NO_OF_SHIPMENT'] - $obj->getPerformedVesselRec($rows1['COAID']));
				
				$ttl_vol_mt_l += $obj->getNumberFormat(($rows1['NO_OF_SHIPMENT'] * $rows['SIZE']) / 1000000);
				$ttl_shpmt_l += $rows1['NO_OF_SHIPMENT'];
				$ttl_perf_l += $perf_qty;
				$ttl_perf_shpmt_l += $obj->getPerformedVesselRec($rows1['COAID']);
				$blnce_vol_mt_l += $obj->getNumberFormat((($rows1['NO_OF_SHIPMENT'] * $rows['SIZE']) / 1000000) - $perf_qty);
				$blnce_shpmt_l += ($rows1['NO_OF_SHIPMENT'] - $obj->getPerformedVesselRec($rows1['COAID']));
			}
				echo '<tr class="GridviewScrollItem" style="font-size:12px;color:#dc631e; font-weight:bold;">';
				echo '<td align="left" valign="top">Totals '.strtoupper($rows['NAME']).'</td>';
				echo '<td align="center" valign="top" ></td>';
				echo '<td align="center" valign="top">'.$ttl_vol_mt_l.'</td>';
				echo '<td align="center" valign="top">'.$ttl_shpmt_l.'</td>';
				echo '<td align="center" valign="top">'.$obj->getNumberFormat($ttl_perf_l).'</td>';
				echo '<td align="center" valign="top">'.$ttl_perf_shpmt_l.'</td>';
				
				echo '<td align="center" valign="top">'.$blnce_vol_mt_l.'</td>';
				echo '<td align="center" valign="top">'.$blnce_shpmt_l.'</td>';
				echo '<td align="left" valign="top"></td>';
				echo '<td align="left" valign="top"></td>';
				echo '<td align="left" valign="top"></td>';
				echo '<td align="left" valign="top"></td>';
				echo '<td align="left" valign="top"></td>';
				echo '<td align="left" valign="top"></td>';
				echo '<td align="left" valign="top"></td>';
				echo '<td align="left" valign="top"></td>';
				echo '<td align="left" valign="top"></td>';
				echo '<td align="left" valign="top"></td>';
				echo '<td align="left" valign="top"></td>';
				echo '<td align="left" valign="top"></td>';	
				echo '<td align="center" valign="top"></td>';
				echo '<td align="center" valign="top"></td>';			
				echo '</tr>';
		}
	}
	echo '<tr class="GridviewScrollItem" style="font-size:12px;color:#dc631e; font-weight:bold;">';
	echo '<td align="left" valign="top">GRAND TOTALS</td>';
	echo '<td align="center" valign="top" ></td>';
	echo '<td align="center" valign="top">'.$ttl_vol_mt.'</td>';
	echo '<td align="center" valign="top">'.$ttl_shpmt.'</td>';
	echo '<td align="center" valign="top">'.$obj->getNumberFormat($ttl_perf).'</td>';
	echo '<td align="center" valign="top">'.$ttl_perf_shpmt.'</td>';
	echo '<td align="center" valign="top">'.$blnce_vol_mt.'</td>';
	echo '<td align="center" valign="top">'.$blnce_shpmt.'</td>';
	echo '<td align="left" valign="top" ></td>';
	echo '<td align="left" valign="top" ></td>';
	echo '<td align="left" valign="top" ></td>';
	echo '<td align="left" valign="top" ></td>';
	echo '<td align="left" valign="top" ></td>';
	echo '<td align="left" valign="top" ></td>';
	echo '<td align="left" valign="top" ></td>';
	echo '<td align="left" valign="top" ></td>';
	echo '<td align="left" valign="top" ></td>';
	echo '<td align="left" valign="top" ></td>';
	echo '<td align="left" valign="top" ></td>';
	echo '<td align="left" valign="top" ></td>';	
	echo '<td align="center" valign="top" ></td>';
	echo '<td align="center" valign="top" ></td>';			
	echo '</tr>';	
	echo '</tbody>';
	echo '</table>';
	echo '</div>';	
	
}






function getZoneData()
{
	$obj 		= new data();
	$connect	= $obj->funConnect();
	$selPort 	= $_REQUEST['selPort'];
	$sql 		= "select ZoneId from port_master where PortCode=".$selPort;
	$res 		= mysql_query($sql);
	$rows 		= mysql_fetch_assoc($res);
	echo $rows['ZoneId'];	
}


function getAgentListCPDateWiseReport()
{
	$obj 		= new data();
	$connect	= $obj->funConnect();	
	$selPort 	= $_REQUEST['selPort'];
	
	$sql = "select * from freight_cost_estimate_compare inner join freight_cost_estimete_master on freight_cost_estimete_master.FCAID= freight_cost_estimate_compare.FCAID WHERE freight_cost_estimate_compare.MODULEID='".$_SESSION['moduleid']."' AND freight_cost_estimate_compare.MCOMPANYID='".$_SESSION['company']."' and freight_cost_estimate_compare.FINAL_ID!='' and freight_cost_estimete_master.FIXED=1 and freight_cost_estimate_compare.STATUS in (1,2) order by freight_cost_estimate_compare.COMID desc";
	$res = mysql_query($sql) or die($sql);
	$rec = mysql_num_rows($res);
	$i=1;
	$cost_sheet_id = "";
	$arr = array();
	
	if($rec == 0)
	{
		echo '<tr>';
		echo '<td align="center" valign="middle" colspan="11" style="color:red;letter-spacing:1px;">SORRY CURRENTLY THERE ARE ZERO(0) RECORDS.</td>';
		echo '</tr>';
	}else{
		while($rows = mysql_fetch_assoc($res))
		{
			$l_cost_sheet_id = $obj->getLatestCostSheetID($rows['COMID']);
	    	$arr = $obj->getLoadPortAndDischargePortArrBasedOnCommidAndProcessWithoutTBN($rows['COMID'],$l_cost_sheet_id);
			for($j=0;$j<count($arr);$j++)
			{
				$arr_portval = explode('@@',$arr[$j]);
				if($selPort == $arr_portval[1])
				{
					echo '<tr>';
					echo '<td align="center" valign="middle">'.$i.'.</td>';
					echo '<td align="left" valign="middle">'.$rows['VOYAGE_NAME'].'</td>';
					if(date("d-M-Y",strtotime($rows['CP_DATE'])) == "01-Jan-1970")
					{
						echo '<td></td>';
					}
					else
					{
						echo '<td>'.date("d-m-Y",strtotime($rows['CP_DATE'])).'</td>';
					}
					echo '<td align="left" valign="middle">'.$obj->getVesselIMOData($rows['VESSEL_IMO_ID'],"VESSEL_NAME").'</td>';
					echo '<td align="left" valign="middle">'.$obj->getPortName($arr_portval[1]).'</td>';
					echo '<td align="left" valign="middle">'.$obj->getCargoNameListForMultipleName($rows['CARGO_ID']).'</td>';
					
					$mysql = "select * from generate_agency_letter where COMID='".$rows['COMID']."' and MODULEID='".$_SESSION['moduleid']."' AND MCOMPANYID='".$_SESSION['company']."' and PORT='".$arr_portval[0]."' and PORTID='".$arr_portval[1]."' and RANDOMID='".$arr_portval[2]."' and STATUS=2";
					$myres = mysql_query($mysql);
					$myrec = mysql_num_rows($myres);
					if($myrec == 1)
					{
						$myrows  = mysql_fetch_assoc($myres);
						echo '<td align="left" valign="middle">'.$obj->getVendorListNewBasedOnID($myrows['VENDORID']).'</td>';
					}
					else
					{
						echo '<td align="left" valign="middle"></td>';
					}
					
					echo '<td align="left" valign="middle">'.$obj->getVendorListNewBasedOnID($obj->getCompareEstimateData($rows['COMID'],"SHIPPER")).'</td>';
					echo '</tr>';
					$i++;
				}
				else if($selPort == "")
				{
					echo '<tr>';
					echo '<td align="center" valign="middle">'.$i.'.</td>';
					echo '<td align="left" valign="middle">'.$rows['VOYAGE_NAME'].'</td>';
					if(date("d-M-Y",strtotime($rows['CP_DATE'])) == "01-Jan-1970")
					{
						echo '<td></td>';
					}
					else
					{
						echo '<td>'.date("d-m-Y",strtotime($rows['CP_DATE'])).'</td>';
					}
					echo '<td align="left" valign="middle">'.$obj->getVesselIMOData($rows['VESSEL_IMO_ID'],"VESSEL_NAME").'</td>';
					echo '<td align="left" valign="middle">'.$obj->getPortName($arr[$j]).'</td>';
					echo '<td align="left" valign="middle">'.$obj->getCargoNameListForMultipleName($rows['CARGO_ID']).'</td>';
					
					$mysql = "select * from generate_agency_letter where COMID='".$rows['COMID']."' and MODULEID='".$_SESSION['moduleid']."' AND MCOMPANYID='".$_SESSION['company']."' and PORT='".$arr_portval[0]."' and PORTID='".$arr_portval[1]."' and RANDOMID='".$arr_portval[2]."' and STATUS=2";
					$myres = mysql_query($mysql);
					$myrec = mysql_num_rows($myres);
					if($myrec == 1)
					{
						$myrows  = mysql_fetch_assoc($myres);
						echo '<td align="left" valign="middle">'.$obj->getVendorListNewBasedOnID($myrows['VENDORID']).'</td>';
					}
					else
					{
						echo '<td align="left" valign="middle"></td>';
					}
					echo '<td align="left" valign="middle">'.$obj->getVendorListNewBasedOnID($obj->getCompareEstimateData($rows['COMID'],"SHIPPER")).'</td>';
					echo '</tr>';
					$i++;
				}
			}
		}
	}		
}


function getAgencyLetterData()
{
	$obj 		= new data();
	$connect	= $obj->funConnect();
	$agencyid 	= $_REQUEST['agencyid'];
	$comid 	= $_REQUEST['comid'];
	$port 		= $_REQUEST['port'];
	$portid 	= $_REQUEST['portid'];
	$tabid 		= $_REQUEST['tabid'];
	
	$lp_costid	= $obj->getLoadPortCostData($agencyid,"LP_COST_ID");	
	$delquery1 	= "delete from generate_agency_letter where GEN_AGENCY_ID='".$agencyid."'";
	$delquery2 	= "delete from loadport_cost_master where LP_COST_ID='".$lp_costid."'";
	$delquery3 	= "delete from loadport_cost_slave where LP_COST_ID='".$lp_costid."'";
	mysql_query($delquery1);
	mysql_query($delquery2);
	mysql_query($delquery3);
	echo 1;
}


function checkDuplicateNomID()
{
	$sug 		= new clsSettings();
	$con 		= $sug->funConnect();
	$nomid 		= $_REQUEST['txtNomID'];
	$query 		= mysql_query("select * from mapping_master where NOM_NAME= '".$nomid."'");
	$num		= mysql_num_rows($query);
	if($num > 0)
	{
		echo 'false';
	}
	else
	{
		echo 'true';
	}
}


function checkDistance()
{
	$obj = new data();
	$connect=$obj->funConnect();
	
	$selFPort = $_REQUEST['selFPort'];
	$selTPort = $_REQUEST['selTPort'];
	$selDType = $_REQUEST['selDType'];
	
	if($selDType == 1){$field = "SHORT_DIS";}
	if($selDType == 2){$field = "NM250_DIS";}
	if($selDType == 3){$field = "NM600_DIS";}
	if($selDType == 4){$field = "LONG_DIS";}
	
	$sql = "select ".$field." from distance_master where FROMPORTID=".$selFPort." and TOPORTID=".$selTPort." and ".$field.">0 ";
	$result = mysql_query($sql);
	$rec = mysql_num_rows($result);
	if($rec == 0)
	{
		$sql1 = "select ".$field." from distance_master where FROMPORTID=".$selTPort." and TOPORTID=".$selFPort." and ".$field.">0 ";
		$result1 = mysql_query($sql1);
		$rec1 	 = mysql_num_rows($result1);
		if($rec1 == 0)
		{
			echo '';
		}
		else
		{
			$rows1 = mysql_fetch_assoc($result1);
			echo $rows1[$field];
		}
	}
	else
	{
		$rows = mysql_fetch_assoc($result);
		echo $rows[$field];
	}
}


function getSpotFixtureReport()
{
	$obj = new data();
	$connect=$obj->funConnect();
	
	$txtFrom_Date = strtotime($_REQUEST['txtFrom_Date']);
	$txtTo_Date = strtotime($_REQUEST['txtTo_Date']);
	
	$sql = "select * from mapping_master where MODULEID='".$_SESSION['moduleid']."'  AND MCOMPANYID='".$_SESSION['company']."' and STATUS in (2,5) order by MAPPINGID";
	$res = mysql_query($sql);
	$rec = mysql_num_rows($res);
	$i=1;
	$cost_sheet_id = "";
	$arr = array();
	while($rows = mysql_fetch_assoc($res))
	{
		$l_cost_sheet_id = $obj->getLatestCostSheetID($rows['MAPPINGID']);
		$obj->viewFreightEstimationRecords($rows['MAPPINGID'],$l_cost_sheet_id);
		//$cpdate = strtotime($obj->getVesselOpenEntryDeta($obj->getMappingData($rows['MAPPINGID'],"OPEN_VESSEL_ID"),"CP_DATE"));
		$cpdate = strtotime($obj->getFun3());
		
		if($txtFrom_Date <= $cpdate && $cpdate <= $txtTo_Date)
		{   echo"heheheheheh";
			if($obj->getVesselOpenEntryDeta($obj->getMappingData($rows['MAPPINGID'],"OPEN_VESSEL_ID"),"COA_SPOT") == 1)
			{
				echo '<tr>';
				echo '<td align="center" valign="middle" >'.$i.'.</td>';
				echo '<td align="left" valign="middle" >'.$obj->getMappingData($rows['MAPPINGID'],"NOM_NAME").'</td>';
				echo '<td align="left" valign="middle" >'.$obj->getVesselIMOData($obj->getVesselOpenEntryDeta($rows['OPEN_VESSEL_ID'],'VESSEL_IMO_ID'),"VESSEL_NAME").'</td>';
				if(date("d-M-Y",strtotime($obj->getVesselOpenEntryDeta($obj->getMappingData($rows['MAPPINGID'],"OPEN_VESSEL_ID"),"CP_DATE"))) == "01-Jan-1970")
				{
					echo '<td align="left" valign="middle" "></td>';
				}
				else
				{
					echo '<td align="left" valign="middle" >'.date("d M Y",strtotime($obj->getVesselOpenEntryDeta($obj->getMappingData($rows['MAPPINGID'],"OPEN_VESSEL_ID"),"CP_DATE"))).'</td>';
				}
				echo '<td align="left" valign="middle" >'.$obj->getVendorListNewBasedOnID($obj->getVesselOpenEntryDeta($obj->getMappingData($rows['MAPPINGID'],"OPEN_VESSEL_ID"),"OWNER")).'</td>';
				echo '<td align="left" valign="middle" >'.$obj->getVendorListNewBasedOnID($obj->getVesselOpenEntryDeta($obj->getMappingData($rows['MAPPINGID'],"OPEN_VESSEL_ID"),"BROKER")).'</td>';
				echo '<td align="left" valign="middle" >'.$obj->getVesselCategoryTypeBasedOnId($obj->getOpenCargoMasterDataBasedOnContractID($obj->getMappingData($rows['MAPPINGID'],"CARGO_IDS"),'VESSEL_CATEGORY')).'</td>';
				echo '<td align="left" valign="middle" >'.$obj->getFun15().'</td>';
				echo '<td align="left" valign="middle" >'.implode(" , ",$obj->getLoadPortNameArrBasedOnIDMappingidAndProcessWithoutTBN($rows['MAPPINGID'],$l_cost_sheet_id)).'</td>';
				echo '<td align="left" valign="middle" >'.implode(" , ",$obj->getDisPortNameArrBasedOnIDMappingidAndProcessWithoutTBN($rows['MAPPINGID'],$l_cost_sheet_id)).'</td>';
				echo '<td align="left" valign="middle" >'.$obj->getFun13().'</td>';
				echo '</tr>';
				$i++;
			}
		}
	}	
}

function getAddReferencesData()
{
	
	$obj = new data();
	$connect=$obj->funConnect();
	$selCategory = $_REQUEST['selCategory'];
	$selRefType = $_REQUEST['selRefType'];
	$txtName = $_REQUEST['txtName'];
	
	//echo $txtName;
	$sql = "select * from elibrary where MODULEID='".$_SESSION['moduleid']."' AND MCOMPANYID='".$_SESSION['company']."' ";
	if($selCategory != "")
	{
		$sql.= " and CATEGORY = '".$selCategory."'  ";
	}
	if($selRefType != "")
	{
		$sql.= " and REFERENCE = '".$selRefType."'  ";
	}
	if($txtName != "")
	{
		$sql.= " and NAME = '".$txtName."'  ";
	}
	//echo $sql; 
	$res = mysql_query($sql);
	$rec = mysql_num_rows($res);
	$i = 1;
	if($rec == 0)
	{
		//echo '<tbody>';
		echo '<tr>';
		echo '<td align="center" colspan="8" valign="middle" style="color:#ff0000;letter-spacing:1px;">'.strtoupper("Sorry Currently there are zero(0) records").'</td>';
		echo '</tr>';
		//echo '</tbody>';
	}
	else{
		while($rows = mysql_fetch_assoc($res))
			{	
				echo '<tr>';
				echo '<td align="left" valign="middle">'.$obj->viewCategoryDetails($rows['CATEGORY'],"NAME").'</td>';
				echo '<td align="left" valign="middle">'.$obj->viewReferenceTypeDetails($rows['REFERENCE'],"NAME").'</td>';
				echo '<td align="left" valign="middle">'.date("d M Y",strtotime($rows['DATE'])).'</td>';
				echo '<td align="left" valign="middle">'.$rows['NAME'].'</td>';
				echo '<td align="left" valign="middle">'.$rows['DESCRIPTION'].'</td>';
				echo '<td align="left" valign="middle">'.$rows['SOURCE'].'</td>';
				if($rows['UPLOAD'] != "")
				{
					$attachments = explode(",",$rows['UPLOAD']);
					echo '<td align="center" valign="middle">';
					for($m=0;$m<count($attachments);$m++)
					{
						if(trim($attachments[$m]) != "")
						{
							echo '&nbsp;&nbsp;<a href="../../ElibraryImages/'.$attachments[$m].'" target="_blank" title="View"><i class="fa fa-external-link"></i></a>';
						}
					}
					echo '</td>';
				}
				echo '<td align="center" valign="middle"><a href="updateReferences.php?id='.$rows['ELIBREF_ID'].'" title="Edit Details" ><i class="fa fa-edit "></i></a>&nbsp;|&nbsp;<a title="Delete Link" href="#'.$i.'" onclick="return getDelete('.$rows['ELIBREF_ID'].');"  ><i class="fa fa-times" style="color:red;"></i></a></td>';
				echo '</tr>';
				$i++;
		}
	}
}


function checkRate()
{
	$obj = new data();
	$connect=$obj->funConnect();
	$selFPort = $_REQUEST['selFPort'];
	$selTPort = $_REQUEST['selTPort'];
	$sql = "select * from wspc_master where FROM_PORT='".$selFPort."' and TO_PORT='".$selTPort."' and MCOMPANYID='".$_SESSION['company']."' and MODULEID='".$_SESSION['moduleid']."'";
	$result = mysql_query($sql);
	$rec = mysql_num_rows($result);
	if($rec == 0)
	{
		$sql1 = "select * from wspc_master where FROM_PORT='".$selTPort."' and TO_PORT='".$selFPort."' and MCOMPANYID='".$_SESSION['company']."' and MODULEID='".$_SESSION['moduleid']."'";
		$result1 = mysql_query($sql1);
		$rec1 = mysql_num_rows($result1);
		if($rec1 == 0)
		{
			echo '0# # #0';
		}
		else
		{
			$rows1 = mysql_fetch_assoc($result1);
			echo $rows1['WS_F_RATE'].'#'.$rows1['STATUS'].'#'.$rows1['REMARKS'].'#'.$rows1['FIXED_DIFF'];
		}
	}
	else
	{
		$rows = mysql_fetch_assoc($result);
		echo $rows['WS_F_RATE'].'#'.$rows['STATUS'].'#'.$rows['REMARKS'].'#'.$rows['FIXED_DIFF'];
		//echo $rows['Unit'];
	}
}

function checkDuplicateOpenCargo()
{
$sug = new clsSettings();
$sug->funConnect();
$contract_id = $_REQUEST['txtCID'];
$query = mysql_query("select * from open_cargo_master where MODULEID='".$_SESSION['moduleid']."' AND MCOMPANYID='".$_SESSION['company']."' and CONTRACTID= '".$contract_id."'");
$num=mysql_num_rows($query);
	if($num > 0)
	{
	echo 'false';
	}
	else
	{
	echo 'true';
	}
}

function getCOAData()
{
	$obj = new data();
	$connect=$obj->funConnect();
	$selActive1 = $_REQUEST['selActive'];
	$txtCOADate = $_REQUEST['txtCOADate'];
	$selOwner = $_REQUEST['selOwner'];
	
	if($_REQUEST['selActive'] == 3){$selActive = 1;}else{$selActive = $_REQUEST['selActive'];}
	
	//$sql = "select * from coa_master WHERE MODULEID='".$_SESSION['moduleid']."' AND MCOMPANYID='".$_SESSION['company']."' and STATUS='".$selActive."' order by COA_DATE desc";
	$sql = "SELECT * from coa_master where MODULEID='".$_SESSION['moduleid']."' AND MCOMPANYID='".$_SESSION['company']."' and STATUS='".$selActive."' ";
	if($_REQUEST['txtCOADate'] != "")
	{
	$sql.= " and COA_DATE = '".date("Y-m-d",strtotime($_REQUEST['txtCOADate']))."'  ";
	}
	if($_REQUEST['selOwner'] != "")
	{
	$sql.= " and OWNER = '".$_REQUEST['selOwner']."'  ";
	}
	$sql.="order by COA_DATE desc";
	$res = mysql_query($sql);
	$rec = mysql_num_rows($res);
	$i = 1;
	if($rec == 0)
	{
		//echo '<tbody>';
		echo '<tr>';
		echo '<td align="center" colspan="8" valign="middle" style="color:#ff0000;letter-spacing:1px;">'.strtoupper("Sorry Currently there are zero(0) records").'</td>';
		echo '</tr>';
		//echo '</tbody>';
	}
	else{
		while($rows = mysql_fetch_assoc($res))
			{
				if($selActive1 == 3)
				{
					if((int)$rows['NO_OF_SHIPMENT'] == (int)$obj->getPerformedVesselRec($rows['COAID']))
					{
						echo '<tr>';
						echo '<td align="left" valign="middle">'.date("d-m-Y",strtotime($rows['COA_DATE'])).'</td>';
						echo '<td align="left" valign="middle">'.$rows['COA_NO'].'</td>';
						echo '<td align="left" valign="middle">'.$obj->getCargoNameBasedOnId($rows['CARGOTYPEID']).'</td>';
						echo '<td align="left" valign="middle">'.$obj->getVesselCategoryTypeBasedOnId($rows['VESSEL_CATEGORY_ID']).'</td>';
						echo '<td align="center" valign="middle">'.$rows['NO_OF_SHIPMENT'].'</td>';
						echo '<td align="center" valign="middle">'.$obj->getPerformedVesselRec($rows['COAID']).'</td>';
						echo '<td align="left" valign="middle">'.$obj->getVendorListNewBasedOnID($rows['OWNER']).' ('.$rows['OWNER'].')</td>';
						if($rows['STATUS'] == 1)
						{
							echo '<td align="right" valign="middle">';
							if($obj->getPerformedVesselRec($rows['COAID']) == 0)
							{
								echo '<a href="cancel_coa.php?id='.$rows['COAID'].'" title="Cancel COA" ><img src="../../img/icon_delete.gif" width="14" height="14" /></a>&nbsp;|&nbsp;';
							}
							echo '<a href="monthly_coa_remarks.php?id='.$rows['COAID'].'" title="Monthly Remarks" ><img src="../../img/edit.png" width="14" height="14" /></a>&nbsp;|&nbsp;<a href="updatecoa.php?id='.$rows['COAID'].'" title="Edit Details" ><img src="../../img/edit.png" width="14" height="14" /></a></td>';	
						}
						else
						{
							echo '<td align="left" valign="middle">';
							echo $rows['CANCEL_REMARKS'];
							echo '</td>';	
						}
						echo '</tr>';
						$i++;
					}
				}
				else
				{
					if((int)$rows['NO_OF_SHIPMENT'] != (int)$obj->getPerformedVesselRec($rows['COAID']))
					{
						echo '<tr>';
						echo '<td align="left" valign="middle">'.date("d-m-Y",strtotime($rows['COA_DATE'])).'</td>';
						echo '<td align="left" valign="middle">'.$rows['COA_NO'].'</td>';
						echo '<td align="left" valign="middle">'.$obj->getCargoNameBasedOnId($rows['CARGOTYPEID']).'</td>';
						echo '<td align="left" valign="middle">'.$obj->getVesselCategoryTypeBasedOnId($rows['VESSEL_CATEGORY_ID']).'</td>';
						echo '<td align="center" valign="middle">'.$rows['NO_OF_SHIPMENT'].'</td>';
						echo '<td align="center" valign="middle">'.$obj->getPerformedVesselRec($rows['COAID']).'</td>';
						echo '<td align="left" valign="middle">'.$obj->getVendorListNewBasedOnID($rows['OWNER']).' ('.$rows['OWNER'].')</td>';
						if($rows['STATUS'] == 1)
						{
							echo '<td align="right" valign="middle">';
							if($obj->getPerformedVesselRec($rows['COAID']) == 0)
							{
								echo '<a href="cancel_coa.php?id='.$rows['COAID'].'" title="Cancel COA" ><img src="../../img/icon_delete.gif" width="14" height="14" /></a>&nbsp;|&nbsp;';
							}
							echo '<a href="monthly_coa_remarks.php?id='.$rows['COAID'].'" title="Monthly Remarks" ><img src="../../img/edit.png" width="14" height="14" /></a>&nbsp;|&nbsp;<a href="updatecoa.php?id='.$rows['COAID'].'" title="Edit Details" ><img src="../../img/edit.png" width="14" height="14" /></a></td>';	
						}
						else
						{
							echo '<td align="left" valign="middle">';
							echo $rows['CANCEL_REMARKS'];
							echo '</td>';	
						}
						echo '</tr>';
						$i++;
					}
				}
		}
	}
}



function checkPortStatus()
{
	$obj			= new data();
	$connect		= $obj->funConnect();
	$selTerminal 	= $_REQUEST['selTerminal'];
	$selCargo 		= explode(",",$_REQUEST['selCargo']);
	
	$query = "select * from port_information_master where PORTID='".$selCargo[1]."' and CARGOID='".$selCargo[0]."' and TERMINALID='".$selTerminal."' AND MODULEID='".$_SESSION['moduleid']."' AND MCOMPANYID='".$_SESSION['company']."' AND STATUS=1";
	$result = mysql_query($query) ;
	$num 	= mysql_num_rows($result);
	
		if($num > 0)
		{
		echo 'false';
		}
		else
		{
		echo 'true';
		}
	
}

function checkDuplicateVendorShortName()
{
	$sug 		= new clsSettings();
	$sug->funConnect();
	$s_name 	= trim(ereg_replace(' +',' ',$_REQUEST['txtVSName']));
	$query 		= mysql_query("select * from vendor_master where STATUS=1 and SHORT_NAME= '".$s_name."'");
	$num		= mysql_num_rows($query);
	if($num > 0)
	{
		echo 'false';
	}
	else
	{
		echo 'true';
	}
}

function checkDuplicateVendorCode()
{
	$sug 		= new clsSettings();
	$sug->funConnect();
	$code 		= trim(ereg_replace(' +',' ',$_REQUEST['txtVCode'])); 
	$query 		= mysql_query("select * from vendor_master where STATUS=1 and CODE= '".$code."'");
	$num		= mysql_num_rows($query);
	if($num > 0)
	{
		echo 'false';
	}
	else
	{
		echo 'true';
	}
}

function checkDuplicateVendorName()
{
	$sug 		= new clsSettings();
				$sug->funConnect();
	$name 		= trim(ereg_replace(' +',' ',$_REQUEST['txtVName']));
	$query 		= mysql_query("select * from vendor_master where STATUS=1 and NAME= '".$name."'");
	$num		= mysql_num_rows($query);
	if($num > 0)
	{
		echo 'false';
	}
	else
	{
		echo 'true';
	}
}


?>