<?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;
	case 80:
        $ret = getBunkerConsumptionReport();
				break;	
	case 81:
        $ret = getGenericInvoicePaymentDetails();
				break;
	case 82:
        $ret = getDistanceFromSeaMatrixDetails();
				break;
	case 83:
        $ret = getPortAPIDetails();
				break;
	case 84:
        $ret = getLocalPortAPIDetails();
				break;
	case 85:
        $ret = getInitiateSession();
				break;
	case 86:
        $ret = getDaysAfterDate();
				break;
	case 87:
        $ret = getContractListjson();
				break;
	case 88:
        $ret = getContractNominationList();
				break;
	case 89:
        $ret = getTCEarningReport();
				break;
	case 90:
        $ret = getCombinedSOAData();
				break;
	case 91:
        $ret = getCombinedSOAListJson();
				break;
	case 92:
        $ret = getComparisionVCReport();
				break;
	case 93:
        $ret = getComparisionSheetsReport();
				break;
	case 94:
        $ret = getComparisionSheetsReport1();
				break;
	case 95:
        $ret = getDecignChartJsonList();
				break;
	case 96:
        $ret = getDecignChartTCJsonList();
				break;
	case 97:
        $ret = getVCVessel_HistoryList();
				break;
	case 98:
        $ret = getAgingReceivablesPayableReport();
				break;
	case 99:
        $ret = getTCVessel_HistoryList();
				break;
	case 100:
        $ret = getFleetListJson();
				break;
	case 101:
        $ret = getVendorListJson();
				break;
	case 102:
        $ret = getHeadwiseSummReports();
				break;
	case 103:
        $ret = getPeriodDetails();
				break;
	case 104:
		$ret=getContractListJsonForDash();
		break;
	case 105:
		$ret = testingLdj();
				break;	
	case 106:
	$ret = getPandLDetailedReg();
	break;	 

	case 107:
	$ret = unHoldPayments();
	break;
	case 108:
	$ret = getDataRecordForPayPayable();
	break;

	case 109:
		$ret = getDataRecordForPayHold();
		break;
				
	default:
		    $ret = "";
				break; 				
}



function getDataRecordForPayHold(){

	$obj = new data();
	$connect=$obj->funConnect();

	$totalFiltered = 0;
	
	$totalData = 0;
	

	$sqlForApp = 'select PAYMENT_UNLOCK from approval_matrix where LOGINID='.$_SESSION['uid'].'';

	$resultForApp = mysql_query($sqlForApp);
	$rowsForApp = mysql_fetch_assoc($resultForApp);

	$sel = "select * from alert_master where SHOW_STATUS=1 and SENDTO='".$_SESSION['uid']."' order by ADDONDATE DESC";

		
	$aaData = array();


	$result = mysql_query($sel);
	while($rows = mysql_fetch_assoc($result))
	{
		$voyagename = '';$voyageno = '';$status = '';$comid='';$vendorname = '';$invoiceno = '';$formname = '';
		
		
	
		
		if($rows['IDENTIFY']=='HIRE STATEMENT')
		{
			$sql1 = "select COMID, INVOICEID, INVOICE_NO,PAYMENT_STATUS,STATUS from invoice_hire_master where INVOICEID='".$rows['IDENTIFYID']."'";
			$result1 = mysql_query($sql1) or die($sql1);
			$rows1 = mysql_fetch_assoc($result1);

			if($_REQUEST['accountType']=='Singapore'){
			if(substr( $obj->getCompareEstimateData($rows1['COMID'],"VOYAGE_NO"), 0, 1)=='S' || substr( $obj->getCompareEstimateData($rows1['COMID'],"VOYAGE_NO"), 0, 2)=='TS'){
			if($rows1['PAYMENT_STATUS']=='payment_hold'){
				
			$comid = $rows1['COMID'];
			$voyageno = $obj->getCompareEstimateData($rows1['COMID'],"VOYAGE_NO");
			$voyagename = $obj->getVesselIMOData($obj->getCompareEstimateData($rows1['COMID'],"VESSEL_IMO_ID"),"VESSEL_NAME");
			$status = $rows1['STATUS'];
			$vendorname = $obj->getVendorListNewBasedOnID($obj->getCompareEstimateData($rows1['COMID'],"DTCVENDORID"));
			$invoiceno  = $rows1['INVOICE_NO'];
			$formname = 'Hire Statement';
			$paytype = 'HOLD';
			}
		}
		}

		if($_REQUEST['accountType']=='Dubai'){
			if(substr( $obj->getCompareEstimateData($rows1['COMID'],"VOYAGE_NO"), 0, 1)=='U' || substr( $obj->getCompareEstimateData($rows1['COMID'],"VOYAGE_NO"), 0, 2)=='TU'){
			if($rows1['PAYMENT_STATUS']=='payment_hold'){
				
			$comid = $rows1['COMID'];
			$voyageno = $obj->getCompareEstimateData($rows1['COMID'],"VOYAGE_NO");
			$voyagename = $obj->getVesselIMOData($obj->getCompareEstimateData($rows1['COMID'],"VESSEL_IMO_ID"),"VESSEL_NAME");
			$status = $rows1['STATUS'];
			$vendorname = $obj->getVendorListNewBasedOnID($obj->getCompareEstimateData($rows1['COMID'],"DTCVENDORID"));
			$invoiceno  = $rows1['INVOICE_NO'];
			$formname = 'Hire Statement';
			$paytype = 'HOLD';
			}
		}
		}
		}
		
		if($rows['IDENTIFY']=='PAYMENT')
		{
			$sql1 = "select COMID, REQ_ID, PAYMENT_NO, VENDOR, STATUS, NAME,PAYMENT_STATUS from request_master where REQ_ID='".$rows['IDENTIFYID']."'";
			$result1 = mysql_query($sql1) or die($sql1);
			$rows1 = mysql_fetch_assoc($result1);

			if($_REQUEST['accountType']=='Singapore'){
			if(substr( $obj->getCompareEstimateData($rows1['COMID'],"VOYAGE_NO"), 0, 1)=='S' || substr( $obj->getCompareEstimateData($rows1['COMID'],"VOYAGE_NO"), 0, 2)=='TS'){
			if($rows1['PAYMENT_STATUS']=='payment_hold' ){
				
			$comid = $rows1['COMID'];
			$voyageno = $obj->getCompareEstimateData($rows1['COMID'],"VOYAGE_NO");
			$voyagename = $obj->getVesselIMOData($obj->getCompareEstimateData($rows1['COMID'],"VESSEL_IMO_ID"),"VESSEL_NAME");
			$status = $rows1['STATUS'];
			$vendorname = $obj->getVendorListNewBasedOnID($rows1['VENDOR']);
			$invoiceno  = $rows1['PAYMENT_NO'];
			$formname = $rows1['NAME'];
			$paytype = 'HOLD';
			}
		}
		}
		if($_REQUEST['accountType']=='Dubai'){
			if(substr( $obj->getCompareEstimateData($rows1['COMID'],"VOYAGE_NO"), 0, 1)=='U' || substr( $obj->getCompareEstimateData($rows1['COMID'],"VOYAGE_NO"), 0, 2)=='TU'){
			if($rows1['PAYMENT_STATUS']=='payment_hold'  ){
				
			$comid = $rows1['COMID'];
			$voyageno = $obj->getCompareEstimateData($rows1['COMID'],"VOYAGE_NO");
			$voyagename = $obj->getVesselIMOData($obj->getCompareEstimateData($rows1['COMID'],"VESSEL_IMO_ID"),"VESSEL_NAME");
			$status = $rows1['STATUS'];
			$vendorname = $obj->getVendorListNewBasedOnID($rows1['VENDOR']);
			$invoiceno  = $rows1['PAYMENT_NO'];
			$formname = $rows1['NAME'];
			$paytype = 'HOLD';
			}
		}
		}
		}
	
		
		
		if($rows['IDENTIFY']=='TC HIRE STATEMENT')
		{
			$sql1 = "select COMID, INVOICEID, INVOICE_NO, RANDOMID, STATUS, INVOICE_TYPE,PAYMENT_STATUS from invoice_hiretc_master where INVOICEID='".$rows['IDENTIFYID']."'";
			$result1 = mysql_query($sql1) or die($sql1);
			$rows1 = mysql_fetch_assoc($result1);

			if($_REQUEST['accountType']=='Singapore'){
			if(substr( $obj->getCompareEstimateData($rows1['COMID'],"VOYAGE_NO"), 0, 1)=='S' || substr( $obj->getCompareEstimateData($rows1['COMID'],"VOYAGE_NO"), 0, 2)=='TS'){
			if($rows1['PAYMENT_STATUS']=='payment_hold' ){
			
			$comid = $rows1['COMID'];
			$voyageno = $obj->getCharteringEstimateTCData($rows1['COMID'],"TC_NO");
			$voyagename = $obj->getVesselIMOData($obj->getCharteringEstimateTCData($rows1['COMID'],"VESSEL_IMO_ID"),"VESSEL_NAME");
			$status = $rows1['STATUS'];
			$invoiceno  = $rows1['INVOICE_NO'];
			
			$sqltc = "SELECT * from chartering_tc_estimate_slave1 where TCOUTID='".$obj->getCharteringEstimateTCData($rows1['COMID'],"TCOUTID")."' and RANDOMID='".$rows1['RANDOMID']."'";
			$restc 	= mysql_query($sqltc);
			$rectc 	= mysql_num_rows($restc);
			$rowstc = mysql_fetch_assoc($restc);
			$vendorname = $obj->getVendorListNewBasedOnID($rowstc['TC_FINAL_HIERAGE_VENDOR']);
			$formname =  $rows['INVOICE_TYPE'].' TC Hire Statement';
			$paytype = 'HOLD';
			}
		}
		}
		if($_REQUEST['accountType']=='Dubai'){
			if(substr( $obj->getCompareEstimateData($rows1['COMID'],"VOYAGE_NO"), 0, 1)=='U' || substr( $obj->getCompareEstimateData($rows1['COMID'],"VOYAGE_NO"), 0, 2)=='TU'){
			if($rows1['PAYMENT_STATUS']=='payment_hold'  ){
			
			$comid = $rows1['COMID'];
			$voyageno = $obj->getCharteringEstimateTCData($rows1['COMID'],"TC_NO");
			$voyagename = $obj->getVesselIMOData($obj->getCharteringEstimateTCData($rows1['COMID'],"VESSEL_IMO_ID"),"VESSEL_NAME");
			$status = $rows1['STATUS'];
			$invoiceno  = $rows1['INVOICE_NO'];
			
			$sqltc = "SELECT * from chartering_tc_estimate_slave1 where TCOUTID='".$obj->getCharteringEstimateTCData($rows1['COMID'],"TCOUTID")."' and RANDOMID='".$rows1['RANDOMID']."'";
			$restc 	= mysql_query($sqltc);
			$rectc 	= mysql_num_rows($restc);
			$rowstc = mysql_fetch_assoc($restc);
			$vendorname = $obj->getVendorListNewBasedOnID($rowstc['TC_FINAL_HIERAGE_VENDOR']);
			$formname =  $rows['INVOICE_TYPE'].' TC Hire Statement';
			$paytype = 'HOLD';
			}
		}
		}
		}
		
	
		
		if($_REQUEST['accountType']=='Singapore'){
		if(substr( $obj->getCompareEstimateData($rows1['COMID'],"VOYAGE_NO"), 0, 1)=='S' || substr( $obj->getCompareEstimateData($rows1['COMID'],"VOYAGE_NO"), 0, 2)=='TS'){
	  if($rows1['PAYMENT_STATUS']=='payment_hold'  ){ $i++;
	
	 	
		if($status==0){
			  $subMit =  '<span class="label label-primary">Submit to Edit</span>';
		}
			  else if($status==1){
			 $subMit =  '<span class="label label-danger">Level 1 Approval Pending Since '.$obj->getDaysDifference($rows['ADDONDATE'],date('Y-m-d',time())).' Days</span>';
		 }
			  else if($status==2){
			 $subMit=  '<span class="label label-warning">Sent for Review To Creator Since '.$obj->getDaysDifference($rows1['ADDONDATE'],date('Y-m-d',time())).' Days</span>';
		 } 
			  else if($status==3){
			  $subMit= '<span class="label label-danger">Level 2 Approval Pending Since '.$obj->getDaysDifference($rows['ADDONDATE'],date('Y-m-d',time())).' Days</span>';
		 }
			  else if($status==4){
			  $subMit =  '<span class="label label-danger">Sent for Review To Approver 1 Since '.$obj->getDaysDifference($rows1['ADDONDATE'],date('Y-m-d',time())).' Days</span>';
		 }
			  else{
			  $subMit =  '<span class="label label-warning">Payment Received/Paid Pending Since '.$obj->getDaysDifference($rows['ADDONDATE'],date('Y-m-d',time())).' Days</span>';
		 }
	
		$date = date('d-m-Y',strtotime($rows['ADDONDATE']));
		$docLink =  '<a href="documents.php?comid='.$comid.'&amp;page=1" style="color:green;" target="_blank" title="Click me">Docs</a>';
		
	if($rows['REDIRECTTO']!=''){
		$reDirectLink =  '<a href="'.$rows['REDIRECTTO'].'&alertid='.$rows['ALERTID'].' target="_blank"><i class="fa fa-edit "></i> View</a>';
	  }else{
	$reDirectLink=  '<a href="payment_grid.php?comid='.$comid.'&page='.$obj->getCompareTableData($comid, 'STATUS').'&alertid='.$rows['ALERTID'].'" target="_blank"><i class="fa fa-edit "></i> View</a>';
	   
		
  
	} 

	if($rowsForApp['PAYMENT_UNLOCK']==1){
	$paymentUnlock = '	<button type="button" class="btn btn-primary" onClick="unholdPayment('.$rows['IDENTIFY'].','.$rows['IDENTIFYID'].')" >Unhold</button>';
	}else{	
		$paymentUnlock=' ';
	}
	$aaData[] = array('col1'=>$i.'.', 'col2'=>$voyagename, 'col3'=>$voyageno, 'col4'=>$formname, 'col5'=>$invoiceno, 'col6'=>$paytype, 'col7'=>$vendorname, 'col8'=>$subMit, 'col9'=>$date, 'col10'=>$docLink, 'col11'=>$reDirectLink,'col12'=>$paymentUnlock);
}

}

}


if($_REQUEST['accountType']=='Dubai'){
	if(substr( $obj->getCompareEstimateData($rows1['COMID'],"VOYAGE_NO"), 0, 1)=='U' || substr( $obj->getCompareEstimateData($rows1['COMID'],"VOYAGE_NO"), 0, 2)=='TU' ){
  if($rows1['PAYMENT_STATUS']=='payment_hold' ){ $j++;

	 
	if($status==0){
		  $subMit =  '<span class="label label-primary">Submit to Edit</span>';
	}
		  else if($status==1){
		 $subMit =  '<span class="label label-danger">Level 1 Approval Pending Since '.$obj->getDaysDifference($rows['ADDONDATE'],date('Y-m-d',time())).' Days</span>';
	 }
		  else if($status==2){
		 $subMit=  '<span class="label label-warning">Sent for Review To Creator Since '.$obj->getDaysDifference($rows1['ADDONDATE'],date('Y-m-d',time())).' Days</span>';
	 } 
		  else if($status==3){
		  $subMit= '<span class="label label-danger">Level 2 Approval Pending Since '.$obj->getDaysDifference($rows['ADDONDATE'],date('Y-m-d',time())).' Days</span>';
	 }
		  else if($status==4){
		  $subMit =  '<span class="label label-danger">Sent for Review To Approver 1 Since '.$obj->getDaysDifference($rows1['ADDONDATE'],date('Y-m-d',time())).' Days</span>';
	 }
		  else{
		  $subMit =  '<span class="label label-warning">Payment Received/Paid Pending Since '.$obj->getDaysDifference($rows['ADDONDATE'],date('Y-m-d',time())).' Days</span>';
	 }

	$date = date('d-m-Y',strtotime($rows['ADDONDATE']));
	$docLink =  '<a href="documents.php?comid='.$comid.'&amp;page=1" style="color:green;" target="_blank" title="Click me">Docs</a>';
	
if($rows['REDIRECTTO']!=''){
	$reDirectLink =  '<a href="'.$rows['REDIRECTTO'].'&alertid='.$rows['ALERTID'].' target="_blank"><i class="fa fa-edit "></i> View</a>';
  }else{
$reDirectLink=  '<a href="payment_grid.php?comid='.$comid.'&page='.$obj->getCompareTableData($comid, 'STATUS').'&alertid='.$rows['ALERTID'].'" target="_blank"><i class="fa fa-edit "></i> View</a>';
   
	if($rowsForApp['PAYMENT_UNLOCK']==1){
	$paymentUnlock = '	<button type="button" class="btn btn-primary" onClick="unholdPayment('.$rows['IDENTIFY'].','.$rows['IDENTIFYID'].')" >Unhold</button>';
	}else{	
		$paymentUnlock=' ';
	}

} 
$aaData[] = array('col1'=>$j.'.', 'col2'=>$voyagename, 'col3'=>$voyageno, 'col4'=>$formname, 'col5'=>$invoiceno, 'col6'=>$paytype, 'col7'=>$vendorname, 'col8'=>$subMit, 'col9'=>$date, 'col10'=>$docLink, 'col11'=>$reDirectLink,'col12'=>$paymentUnlock);
}


}


}


}

// echo count($aaData);

echo json_encode(array("draw"=>intval($_POST['draw']),"recordsTotal"=>' ',"recordsFiltered"=>' ',"records" => $aaData));



}


function getDataRecordForPayPayable(){

	$obj = new data();
	$connect=$obj->funConnect();

	$totalFiltered = 0;
	
	$totalData = 0;
	

	$sel = "select * from alert_master where SHOW_STATUS=1 and SENDTO='".$_SESSION['uid']."' order by ADDONDATE DESC";

		
	$aaData = array();
	$i=$_POST['start'];
	$j=$_POST['start'];

	// $totalFiltered = $totalData = $aResultTotal[0];

	$result = mysql_query($sel);
	while($rows = mysql_fetch_assoc($result))
	{
		$voyagename = '';$voyageno = '';$status = '';$comid='';$vendorname = '';$invoiceno = '';$formname = '';
		if($rows['IDENTIFY']=='FREIGHT INVOICE')
		{
			$sql1 = "select COMID, INVOICEID, MESSAGE, VENDOR, STATUS, I_TYPE from freight_invoice_master where INVOICEID='".$rows['IDENTIFYID']."'";
			$result1 = mysql_query($sql1) or die($sql1);
			$rows1 = mysql_fetch_assoc($result1);
		
			
				if($_REQUEST['accountType']=='Singapore'){
				if(substr( $obj->getCompareEstimateData($rows1['COMID'],"VOYAGE_NO"), 0, 1)=='S' || substr( $obj->getCompareEstimateData($rows1['COMID'],"VOYAGE_NO"), 0, 2)=='TS'){
				$comid = $rows1['COMID'];
				$voyageno = $obj->getCompareEstimateData($rows1['COMID'],"VOYAGE_NO");
				$voyagename = $obj->getVesselIMOData($obj->getCompareEstimateData($rows1['COMID'],"VESSEL_IMO_ID"),"VESSEL_NAME");
				$status = $rows1['STATUS'];
				$vendorname = $obj->getVendorListNewBasedOnID($rows1['VENDOR']);
				$invoiceno  = $rows1['MESSAGE'];
				$formname = $rows['I_TYPE'].' Freight Invoice';
				$paytype = 'Receivable';
				}
			}

			if($_REQUEST['accountType']=='Dubai'){

				if(substr( $obj->getCompareEstimateData($rows1['COMID'],"VOYAGE_NO"), 0, 1)=='U'  || substr( $obj->getCompareEstimateData($rows1['COMID'],"VOYAGE_NO"), 0, 1)=='TU'){
				$comid = $rows1['COMID'];
				$voyageno = $obj->getCompareEstimateData($rows1['COMID'],"VOYAGE_NO");
				$voyagename = $obj->getVesselIMOData($obj->getCompareEstimateData($rows1['COMID'],"VESSEL_IMO_ID"),"VESSEL_NAME");
				$status = $rows1['STATUS'];
				$vendorname = $obj->getVendorListNewBasedOnID($rows1['VENDOR']);
				$invoiceno  = $rows1['MESSAGE'];
				$formname = $rows['I_TYPE'].' Freight Invoice';
				$paytype = 'Receivable';
				}
			}
		}
		
		if($rows['IDENTIFY']=='OTHER INVOICE')
		{
			$sql1 = "select COMID, INVOICEID, MESSAGE, VENDOR, STATUS, P_TYPE from other_invoice_master where INVOICEID='".$rows['IDENTIFYID']."'";
			$result1 = mysql_query($sql1) or die($sql1);
			$rows1 = mysql_fetch_assoc($result1);

			if($_REQUEST['accountType']=='Singapore'){
			if(substr( $obj->getCompareEstimateData($rows1['COMID'],"VOYAGE_NO"), 0, 1)=='S' || substr( $obj->getCompareEstimateData($rows1['COMID'],"VOYAGE_NO"), 0, 2)=='TS'){
			$comid = $rows1['COMID'];
			$voyageno = $obj->getCompareEstimateData($rows1['COMID'],"VOYAGE_NO");
			$voyagename = $obj->getVesselIMOData($obj->getCompareEstimateData($rows1['COMID'],"VESSEL_IMO_ID"),"VESSEL_NAME");
			$status = $rows1['STATUS'];
			$vendorname = $obj->getVendorListNewBasedOnID($rows1['VENDOR']);
			$invoiceno  = $rows1['MESSAGE'];
			$formname = $rows['P_TYPE'];
			$paytype = 'Receivable';
			}
		}

			if($_REQUEST['accountType']=='Dubai'){
				if(substr( $obj->getCompareEstimateData($rows1['COMID'],"VOYAGE_NO"), 0, 1)=='U'  || substr( $obj->getCompareEstimateData($rows1['COMID'],"VOYAGE_NO"), 0, 1)=='TU'){
				$comid = $rows1['COMID'];
				$voyageno = $obj->getCompareEstimateData($rows1['COMID'],"VOYAGE_NO");
				$voyagename = $obj->getVesselIMOData($obj->getCompareEstimateData($rows1['COMID'],"VESSEL_IMO_ID"),"VESSEL_NAME");
				$status = $rows1['STATUS'];
				$vendorname = $obj->getVendorListNewBasedOnID($rows1['VENDOR']);
				$invoiceno  = $rows1['MESSAGE'];
				$formname = $rows['P_TYPE'];
				$paytype = 'Receivable';
				}
		}

		
		}
		
		if($rows['IDENTIFY']=='HIRE STATEMENT')
		{
			$sql1 = "select COMID, INVOICEID, INVOICE_NO,PAYMENT_STATUS,STATUS from invoice_hire_master where INVOICEID='".$rows['IDENTIFYID']."'";
			$result1 = mysql_query($sql1) or die($sql1);
			$rows1 = mysql_fetch_assoc($result1);

			if($_REQUEST['accountType']=='Singapore'){
			if(substr( $obj->getCompareEstimateData($rows1['COMID'],"VOYAGE_NO"), 0, 1)=='S' || substr( $obj->getCompareEstimateData($rows1['COMID'],"VOYAGE_NO"), 0, 2)=='TS'){
			if($rows1['PAYMENT_STATUS']=='payment_payable' || $rows1['PAYMENT_STATUS']==NULL ){
				
			$comid = $rows1['COMID'];
			$voyageno = $obj->getCompareEstimateData($rows1['COMID'],"VOYAGE_NO");
			$voyagename = $obj->getVesselIMOData($obj->getCompareEstimateData($rows1['COMID'],"VESSEL_IMO_ID"),"VESSEL_NAME");
			$status = $rows1['STATUS'];
			$vendorname = $obj->getVendorListNewBasedOnID($obj->getCompareEstimateData($rows1['COMID'],"DTCVENDORID"));
			$invoiceno  = $rows1['INVOICE_NO'];
			$formname = 'Hire Statement';
			$paytype = 'Payable';
			}
		}
		}

		if($_REQUEST['accountType']=='Dubai'){
			if(substr( $obj->getCompareEstimateData($rows1['COMID'],"VOYAGE_NO"), 0, 1)=='U'  || substr( $obj->getCompareEstimateData($rows1['COMID'],"VOYAGE_NO"), 0, 2)=='TU'){
			if($rows1['PAYMENT_STATUS']=='payment_payable' || $rows1['PAYMENT_STATUS']==NULL ){
				
			$comid = $rows1['COMID'];
			$voyageno = $obj->getCompareEstimateData($rows1['COMID'],"VOYAGE_NO");
			$voyagename = $obj->getVesselIMOData($obj->getCompareEstimateData($rows1['COMID'],"VESSEL_IMO_ID"),"VESSEL_NAME");
			$status = $rows1['STATUS'];
			$vendorname = $obj->getVendorListNewBasedOnID($obj->getCompareEstimateData($rows1['COMID'],"DTCVENDORID"));
			$invoiceno  = $rows1['INVOICE_NO'];
			$formname = 'Hire Statement';
			$paytype = 'Payable';
			}
		}
		}
		}
		
		if($rows['IDENTIFY']=='PAYMENT')
		{
			$sql1 = "select COMID, REQ_ID, PAYMENT_NO, VENDOR, STATUS, NAME,PAYMENT_STATUS from request_master where REQ_ID='".$rows['IDENTIFYID']."'";
			$result1 = mysql_query($sql1) or die($sql1);
			$rows1 = mysql_fetch_assoc($result1);

			if($_REQUEST['accountType']=='Singapore'){
			if(substr( $obj->getCompareEstimateData($rows1['COMID'],"VOYAGE_NO"), 0, 1)=='S' || substr( $obj->getCompareEstimateData($rows1['COMID'],"VOYAGE_NO"), 0, 2)=='TS'){
			if($rows1['PAYMENT_STATUS']=='payment_payable' || $rows1['PAYMENT_STATUS']==NULL ){
				
			$comid = $rows1['COMID'];
			$voyageno = $obj->getCompareEstimateData($rows1['COMID'],"VOYAGE_NO");
			$voyagename = $obj->getVesselIMOData($obj->getCompareEstimateData($rows1['COMID'],"VESSEL_IMO_ID"),"VESSEL_NAME");
			$status = $rows1['STATUS'];
			$vendorname = $obj->getVendorListNewBasedOnID($rows1['VENDOR']);
			$invoiceno  = $rows1['PAYMENT_NO'];
			$formname = $rows1['NAME'];
			$paytype = 'PAYABLE';
			}
		}
		}
		if($_REQUEST['accountType']=='Dubai'){
			if(substr( $obj->getCompareEstimateData($rows1['COMID'],"VOYAGE_NO"), 0, 1)=='U'  || substr( $obj->getCompareEstimateData($rows1['COMID'],"VOYAGE_NO"), 0, 2)=='TU'){
			if($rows1['PAYMENT_STATUS']=='payment_payable' || $rows1['PAYMENT_STATUS']==NULL ){
				
			$comid = $rows1['COMID'];
			$voyageno = $obj->getCompareEstimateData($rows1['COMID'],"VOYAGE_NO");
			$voyagename = $obj->getVesselIMOData($obj->getCompareEstimateData($rows1['COMID'],"VESSEL_IMO_ID"),"VESSEL_NAME");
			$status = $rows1['STATUS'];
			$vendorname = $obj->getVendorListNewBasedOnID($rows1['VENDOR']);
			$invoiceno  = $rows1['PAYMENT_NO'];
			$formname = $rows1['NAME'];
			$paytype = 'PAYABLE';
			}
		}
		}
		}
		
		
		if($rows['IDENTIFY']=='LAYTIME')
		{
			$sql1 = "select COMID, LAYTIME_ID, SUBMITID, PORT, PORTID, VENDOR from laytime_master where LAYTIME_ID='".$rows['IDENTIFYID']."'";
			$result1 = mysql_query($sql1) or die($sql1);
			$rows1 = mysql_fetch_assoc($result1);
			if($_REQUEST['accountType']=='Singapore'){
			if(substr( $obj->getCompareEstimateData($rows1['COMID'],"VOYAGE_NO"), 0, 1)=='S' || substr( $obj->getCompareEstimateData($rows1['COMID'],"VOYAGE_NO"), 0, 2)=='TS'){
			$comid = $rows1['COMID'];
			$voyageno = $obj->getCompareEstimateData($rows1['COMID'],"VOYAGE_NO");
			$voyagename = $obj->getVesselIMOData($obj->getCompareEstimateData($rows1['COMID'],"VESSEL_IMO_ID"),"VESSEL_NAME");
			$status = $rows1['SUBMITID'];
			$vendorname = $obj->getVendorListNewBasedOnID($rows1['VENDOR']);
			$invoiceno  = $rows1['PORT'].' - '.$obj->getPortNameBasedOnID($rows1['PORTID']);
			$formname = 'LAYTIME';
			$paytype = 'Receivable';
			}
		}
		if($_REQUEST['accountType']=='Dubai'){
			if(substr( $obj->getCompareEstimateData($rows1['COMID'],"VOYAGE_NO"), 0, 1)=='U'  || substr( $obj->getCompareEstimateData($rows1['COMID'],"VOYAGE_NO"), 0, 2)=='TU'){
			$comid = $rows1['COMID'];
			$voyageno = $obj->getCompareEstimateData($rows1['COMID'],"VOYAGE_NO");
			$voyagename = $obj->getVesselIMOData($obj->getCompareEstimateData($rows1['COMID'],"VESSEL_IMO_ID"),"VESSEL_NAME");
			$status = $rows1['SUBMITID'];
			$vendorname = $obj->getVendorListNewBasedOnID($rows1['VENDOR']);
			$invoiceno  = $rows1['PORT'].' - '.$obj->getPortNameBasedOnID($rows1['PORTID']);
			$formname = 'LAYTIME';
			$paytype = 'Receivable';
			}
		}

		}
		
		if($rows['IDENTIFY']=='FDA')
		{
			$sql1 = "select COMID, LP_COST_ID, SUBMITID, PORT, PORTID, RANDOMID from loadport_cost_master where LP_COST_ID='".$rows['IDENTIFYID']."'";
			$result1 = mysql_query($sql1) or die($sql1);
			$rows1 = mysql_fetch_assoc($result1);
			if($_REQUEST['accountType']=='Singapore'){
			if(substr( $obj->getCompareEstimateData($rows1['COMID'],"VOYAGE_NO"), 0, 1)=='S' || substr( $obj->getCompareEstimateData($rows1['COMID'],"VOYAGE_NO"), 0, 2)=='TS'){
			$comid = $rows1['COMID'];
			$voyageno = $obj->getCompareEstimateData($rows1['COMID'],"VOYAGE_NO");
			$voyagename = $obj->getVesselIMOData($obj->getCompareEstimateData($rows1['COMID'],"VESSEL_IMO_ID"),"VESSEL_NAME");
			$status = $rows1['SUBMITID'];
			$invoiceno  = $rows1['PORT'].' - '.$obj->getPortNameBasedOnID($rows1['PORTID']);
			
			$sqltc = "SELECT PORT_COSTLP_VENDOR, PORT_COSTDP_VENDOR, PORT_COSTTP_VENDOR from freight_cost_estimete_slave1 where FCAID='".$obj->getCompareEstimateData($rows1['COMID'],"FCAID")."' and RANDOMID='".$rows1['RANDOMID']."'";
			$restc 	= mysql_query($sqltc);
			$rectc 	= mysql_num_rows($restc);
			$rowstc = mysql_fetch_assoc($restc);
			if($rows1['PORT'] == 'LP')
			{
				  $vendorname = $obj->getVendorListNewBasedOnID($rowstc['PORT_COSTLP_VENDOR']);
			}
			if($rows1['PORT'] == 'DP')
			{
				  $vendorname = $obj->getVendorListNewBasedOnID($rowstc['PORT_COSTDP_VENDOR']);
			}
			if($rows1['PORT'] == 'TP')
			{
				  $vendorname = $obj->getVendorListNewBasedOnID($rowstc['PORT_COSTTP_VENDOR']);
			}
			
			$formname = 'FDA';
			$paytype = 'Payable';
		}
	}

	if($_REQUEST['accountType']=='Dubai'){
		if(substr( $obj->getCompareEstimateData($rows1['COMID'],"VOYAGE_NO"), 0, 1)=='U'  || substr( $obj->getCompareEstimateData($rows1['COMID'],"VOYAGE_NO"), 0, 2)=='TU'){
		$comid = $rows1['COMID'];
		$voyageno = $obj->getCompareEstimateData($rows1['COMID'],"VOYAGE_NO");
		$voyagename = $obj->getVesselIMOData($obj->getCompareEstimateData($rows1['COMID'],"VESSEL_IMO_ID"),"VESSEL_NAME");
		$status = $rows1['SUBMITID'];
		$invoiceno  = $rows1['PORT'].' - '.$obj->getPortNameBasedOnID($rows1['PORTID']);
		
		$sqltc = "SELECT PORT_COSTLP_VENDOR, PORT_COSTDP_VENDOR, PORT_COSTTP_VENDOR from freight_cost_estimete_slave1 where FCAID='".$obj->getCompareEstimateData($rows1['COMID'],"FCAID")."' and RANDOMID='".$rows1['RANDOMID']."'";
		$restc 	= mysql_query($sqltc);
		$rectc 	= mysql_num_rows($restc);
		$rowstc = mysql_fetch_assoc($restc);
		if($rows1['PORT'] == 'LP')
		{
			  $vendorname = $obj->getVendorListNewBasedOnID($rowstc['PORT_COSTLP_VENDOR']);
		}
		if($rows1['PORT'] == 'DP')
		{
			  $vendorname = $obj->getVendorListNewBasedOnID($rowstc['PORT_COSTDP_VENDOR']);
		}
		if($rows1['PORT'] == 'TP')
		{
			  $vendorname = $obj->getVendorListNewBasedOnID($rowstc['PORT_COSTTP_VENDOR']);
		}
		
		$formname = 'FDA';
		$paytype = 'Payable';
	}
}
		}
		
		
		if($rows['IDENTIFY']=='HIRE INVOICE')
		{
			$sql1 = "select COMID, INVOICEID, INVOICE_NO, RANDOMID, STATUS, INVOICE_TYPE from invoice_tchire_master where INVOICEID='".$rows['IDENTIFYID']."'";
			$result1 = mysql_query($sql1) or die($sql1);
			$rows1 = mysql_fetch_assoc($result1);

			if($_REQUEST['accountType']=='Singapore'){
			if(substr( $obj->getCompareEstimateData($rows1['COMID'],"VOYAGE_NO"), 0, 1)=='S' || substr( $obj->getCompareEstimateData($rows1['COMID'],"VOYAGE_NO"), 0, 2)=='TS'){
			$comid = $rows1['COMID'];
			$voyageno = $obj->getCharteringEstimateTCData($rows1['COMID'],"TC_NO");
			$voyagename = $obj->getVesselIMOData($obj->getCharteringEstimateTCData($rows1['COMID'],"VESSEL_IMO_ID"),"VESSEL_NAME");
			$status = $rows1['STATUS'];
			$invoiceno  = $rows1['INVOICE_NO'];
			
			$sqltc = "SELECT * from chartering_tc_estimate_slave1 where TCOUTID='".$obj->getCharteringEstimateTCData($rows1['COMID'],"TCOUTID")."' and RANDOMID='".$rows1['RANDOMID']."'";
			$restc 	= mysql_query($sqltc);
			$rectc 	= mysql_num_rows($restc);
			$rowstc = mysql_fetch_assoc($restc);
			$vendorname = $obj->getVendorListNewBasedOnID($rowstc['TTL_REV_VENDOR']);
			$formname = ucwords($rows['INVOICE_TYPE']).' TC Hire Invoice';
			$paytype = 'Receivable';
			}
		}
		if($_REQUEST['accountType']=='Dubai'){
			if(substr( $obj->getCompareEstimateData($rows1['COMID'],"VOYAGE_NO"), 0, 1)=='U' || substr( $obj->getCompareEstimateData($rows1['COMID'],"VOYAGE_NO"), 0, 2)=='TU'){
			$comid = $rows1['COMID'];
			$voyageno = $obj->getCharteringEstimateTCData($rows1['COMID'],"TC_NO");
			$voyagename = $obj->getVesselIMOData($obj->getCharteringEstimateTCData($rows1['COMID'],"VESSEL_IMO_ID"),"VESSEL_NAME");
			$status = $rows1['STATUS'];
			$invoiceno  = $rows1['INVOICE_NO'];
			
			$sqltc = "SELECT * from chartering_tc_estimate_slave1 where TCOUTID='".$obj->getCharteringEstimateTCData($rows1['COMID'],"TCOUTID")."' and RANDOMID='".$rows1['RANDOMID']."'";
			$restc 	= mysql_query($sqltc);
			$rectc 	= mysql_num_rows($restc);
			$rowstc = mysql_fetch_assoc($restc);
			$vendorname = $obj->getVendorListNewBasedOnID($rowstc['TTL_REV_VENDOR']);
			$formname = ucwords($rows['INVOICE_TYPE']).' TC Hire Invoice';
			$paytype = 'Receivable';
			}
		}
		}
		
		if($rows['IDENTIFY']=='TC HIRE STATEMENT')
		{
			$sql1 = "select COMID, INVOICEID, INVOICE_NO, RANDOMID, STATUS, INVOICE_TYPE,PAYMENT_STATUS from invoice_hiretc_master where INVOICEID='".$rows['IDENTIFYID']."'";
			$result1 = mysql_query($sql1) or die($sql1);
			$rows1 = mysql_fetch_assoc($result1);

			if($_REQUEST['accountType']=='Singapore'){
			if(substr( $obj->getCompareEstimateData($rows1['COMID'],"VOYAGE_NO"), 0, 1)=='S' || substr( $obj->getCompareEstimateData($rows1['COMID'],"VOYAGE_NO"), 0, 2)=='TS'){
			if($rows1['PAYMENT_STATUS']=='payment_payable' || $rows1['PAYMENT_STATUS']==NULL ){
			
			$comid = $rows1['COMID'];
			$voyageno = $obj->getCharteringEstimateTCData($rows1['COMID'],"TC_NO");
			$voyagename = $obj->getVesselIMOData($obj->getCharteringEstimateTCData($rows1['COMID'],"VESSEL_IMO_ID"),"VESSEL_NAME");
			$status = $rows1['STATUS'];
			$invoiceno  = $rows1['INVOICE_NO'];
			
			$sqltc = "SELECT * from chartering_tc_estimate_slave1 where TCOUTID='".$obj->getCharteringEstimateTCData($rows1['COMID'],"TCOUTID")."' and RANDOMID='".$rows1['RANDOMID']."'";
			$restc 	= mysql_query($sqltc);
			$rectc 	= mysql_num_rows($restc);
			$rowstc = mysql_fetch_assoc($restc);
			$vendorname = $obj->getVendorListNewBasedOnID($rowstc['TC_FINAL_HIERAGE_VENDOR']);
			$formname =  $rows['INVOICE_TYPE'].' TC Hire Statement';
			$paytype = 'Payable';
			}
		}
		}
		if($_REQUEST['accountType']=='Dubai'){
			if(substr( $obj->getCompareEstimateData($rows1['COMID'],"VOYAGE_NO"), 0, 1)=='U' || substr( $obj->getCompareEstimateData($rows1['COMID'],"VOYAGE_NO"), 0, 2)=='TU'){
			if($rows1['PAYMENT_STATUS']=='payment_payable' || $rows1['PAYMENT_STATUS']==NULL ){
			
			$comid = $rows1['COMID'];
			$voyageno = $obj->getCharteringEstimateTCData($rows1['COMID'],"TC_NO");
			$voyagename = $obj->getVesselIMOData($obj->getCharteringEstimateTCData($rows1['COMID'],"VESSEL_IMO_ID"),"VESSEL_NAME");
			$status = $rows1['STATUS'];
			$invoiceno  = $rows1['INVOICE_NO'];
			
			$sqltc = "SELECT * from chartering_tc_estimate_slave1 where TCOUTID='".$obj->getCharteringEstimateTCData($rows1['COMID'],"TCOUTID")."' and RANDOMID='".$rows1['RANDOMID']."'";
			$restc 	= mysql_query($sqltc);
			$rectc 	= mysql_num_rows($restc);
			$rowstc = mysql_fetch_assoc($restc);
			$vendorname = $obj->getVendorListNewBasedOnID($rowstc['TC_FINAL_HIERAGE_VENDOR']);
			$formname =  $rows['INVOICE_TYPE'].' TC Hire Statement';
			$paytype = 'Payable';
			}
		}
		}
		}
		
		if($rows['IDENTIFY']=='OTHER TC INVOICE')
		{
			$sql1 = "select COMID, INVOICEID, INVOICE_NO, RANDOMID, STATUS, VENDOR, SHORT_DESC from invoice_tcother_master where INVOICEID='".$rows['IDENTIFYID']."'";
			$result1 = mysql_query($sql1) or die($sql1);
			$rows1 = mysql_fetch_assoc($result1);
			if($_REQUEST['accountType']=='Singapore'){
			if(substr( $obj->getCompareEstimateData($rows1['COMID'],"VOYAGE_NO"), 0, 1)=='S' || substr( $obj->getCompareEstimateData($rows1['COMID'],"VOYAGE_NO"), 0, 2)=='TS'){
			$comid = $rows1['COMID'];
			$voyageno = $obj->getCharteringEstimateTCData($rows1['COMID'],"TC_NO");
			$voyagename = $obj->getVesselIMOData($obj->getCharteringEstimateTCData($rows1['COMID'],"VESSEL_IMO_ID"),"VESSEL_NAME");
			$status = $rows1['STATUS'];
			$invoiceno  = $rows1['INVOICE_NO'];
			$vendorname = $obj->getVendorListNewBasedOnID($rows1['VENDOR']);
			$formname =  $rows['SHORT_DESC'];
			$paytype = 'Receivable';
			}
		}
		if($_REQUEST['accountType']=='Dubai'){
			if(substr( $obj->getCompareEstimateData($rows1['COMID'],"VOYAGE_NO"), 0, 1)=='U' || substr( $obj->getCompareEstimateData($rows1['COMID'],"VOYAGE_NO"), 0, 2)=='TU'){
			$comid = $rows1['COMID'];
			$voyageno = $obj->getCharteringEstimateTCData($rows1['COMID'],"TC_NO");
			$voyagename = $obj->getVesselIMOData($obj->getCharteringEstimateTCData($rows1['COMID'],"VESSEL_IMO_ID"),"VESSEL_NAME");
			$status = $rows1['STATUS'];
			$invoiceno  = $rows1['INVOICE_NO'];
			$vendorname = $obj->getVendorListNewBasedOnID($rows1['VENDOR']);
			$formname =  $rows['SHORT_DESC'];
			$paytype = 'Receivable';
			}
		}
		}
		
		if($rows['IDENTIFY']=='OTHER TC PAYMENT')
		{
			$sql1 = "select PAYMENTID, COMID, INVOICE_NO, RANDOMID, STATUS, VENDOR, SHORT_DESC from payment_tcother_master where PAYMENTID='".$rows['IDENTIFYID']."'";
			$result1 = mysql_query($sql1) or die($sql1);
			$rows1 = mysql_fetch_assoc($result1);
			if($_REQUEST['accountType']=='Singapore'){
			if(substr( $obj->getCompareEstimateData($rows1['COMID'],"VOYAGE_NO"), 0, 1)=='S' || substr( $obj->getCompareEstimateData($rows1['COMID'],"VOYAGE_NO"), 0, 2)=='TS'){
			$comid = $rows1['COMID'];
			$voyageno = $obj->getCharteringEstimateTCData($rows1['COMID'],"TC_NO");
			$voyagename = $obj->getVesselIMOData($obj->getCharteringEstimateTCData($rows1['COMID'],"VESSEL_IMO_ID"),"VESSEL_NAME");
			$status = $rows1['STATUS'];
			$invoiceno  = $rows1['INVOICE_NO'];
			$vendorname = $obj->getVendorListNewBasedOnID($rows1['VENDOR']);
			$formname =  "Other TC Payment";
			$paytype = 'Payable';
			}
		}
		if($_REQUEST['accountType']=='Dubai'){
			if(substr( $obj->getCompareEstimateData($rows1['COMID'],"VOYAGE_NO"), 0, 1)=='U' || substr( $obj->getCompareEstimateData($rows1['COMID'],"VOYAGE_NO"), 0, 2)=='TU'){
			$comid = $rows1['COMID'];
			$voyageno = $obj->getCharteringEstimateTCData($rows1['COMID'],"TC_NO");
			$voyagename = $obj->getVesselIMOData($obj->getCharteringEstimateTCData($rows1['COMID'],"VESSEL_IMO_ID"),"VESSEL_NAME");
			$status = $rows1['STATUS'];
			$invoiceno  = $rows1['INVOICE_NO'];
			$vendorname = $obj->getVendorListNewBasedOnID($rows1['VENDOR']);
			$formname =  "Other TC Payment";
			$paytype = 'Payable';
			}
		}
		}
		
		if($_REQUEST['accountType']=='Singapore'){
		if(substr( $obj->getCompareEstimateData($rows1['COMID'],"VOYAGE_NO"), 0, 1)=='S' || substr( $obj->getCompareEstimateData($rows1['COMID'],"VOYAGE_NO"), 0, 2)=='TS'){
	  if($rows1['PAYMENT_STATUS']=='payment_payable' || $rows1['PAYMENT_STATUS']==NULL ){ $i++;
	
	 	
		if($status==0){
			  $subMit =  '<span class="label label-primary">Submit to Edit</span>';
		}
			  else if($status==1){
			 $subMit =  '<span class="label label-danger">Level 1 Approval Pending Since '.$obj->getDaysDifference($rows['ADDONDATE'],date('Y-m-d',time())).' Days</span>';
		 }
			  else if($status==2){
			 $subMit=  '<span class="label label-warning">Sent for Review To Creator Since '.$obj->getDaysDifference($rows1['ADDONDATE'],date('Y-m-d',time())).' Days</span>';
		 } 
			  else if($status==3){
			  $subMit= '<span class="label label-danger">Level 2 Approval Pending Since '.$obj->getDaysDifference($rows['ADDONDATE'],date('Y-m-d',time())).' Days</span>';
		 }
			  else if($status==4){
			  $subMit =  '<span class="label label-danger">Sent for Review To Approver 1 Since '.$obj->getDaysDifference($rows1['ADDONDATE'],date('Y-m-d',time())).' Days</span>';
		 }
			  else{
			  $subMit =  '<span class="label label-warning">Payment Received/Paid Pending Since '.$obj->getDaysDifference($rows['ADDONDATE'],date('Y-m-d',time())).' Days</span>';
		 }
	
		$date = date('d-m-Y',strtotime($rows['ADDONDATE']));
		$docLink =  '<a href="documents.php?comid='.$comid.'&amp;page=1" style="color:green;" target="_blank" title="Click me">Docs</a>';
		
	if($rows['REDIRECTTO']!=''){
		$reDirectLink =  '<a href="'.$rows['REDIRECTTO'].'&alertid='.$rows['ALERTID'].' target="_blank"><i class="fa fa-edit "></i> View</a>';
	  }else{
	$reDirectLink=  '<a href="payment_grid.php?comid='.$comid.'&page='.$obj->getCompareTableData($comid, 'STATUS').'&alertid='.$rows['ALERTID'].'" target="_blank"><i class="fa fa-edit "></i> View</a>';
	   
		
  
	} 
}
$aaData[] = array('col1'=>$i.'.', 'col2'=>$voyagename, 'col3'=>$voyageno, 'col4'=>$formname, 'col5'=>$invoiceno, 'col6'=>$paytype, 'col7'=>$vendorname, 'col8'=>$subMit, 'col9'=>$date, 'col10'=>$docLink, 'col11'=>$reDirectLink);
}

	

	

}


if($_REQUEST['accountType']=='Dubai'){
	if(substr( $obj->getCompareEstimateData($rows1['COMID'],"VOYAGE_NO"), 0, 1)=='U' || substr( $obj->getCompareEstimateData($rows1['COMID'],"VOYAGE_NO"), 0, 2)=='TU'){
  if($rows1['PAYMENT_STATUS']=='payment_payable' || $rows1['PAYMENT_STATUS']==NULL ){ $j++;

	 
	if($status==0){
		  $subMit =  '<span class="label label-primary">Submit to Edit</span>';
	}
		  else if($status==1){
		 $subMit =  '<span class="label label-danger">Level 1 Approval Pending Since '.$obj->getDaysDifference($rows['ADDONDATE'],date('Y-m-d',time())).' Days</span>';
	 }
		  else if($status==2){
		 $subMit=  '<span class="label label-warning">Sent for Review To Creator Since '.$obj->getDaysDifference($rows1['ADDONDATE'],date('Y-m-d',time())).' Days</span>';
	 } 
		  else if($status==3){
		  $subMit= '<span class="label label-danger">Level 2 Approval Pending Since '.$obj->getDaysDifference($rows['ADDONDATE'],date('Y-m-d',time())).' Days</span>';
	 }
		  else if($status==4){
		  $subMit =  '<span class="label label-danger">Sent for Review To Approver 1 Since '.$obj->getDaysDifference($rows1['ADDONDATE'],date('Y-m-d',time())).' Days</span>';
	 }
		  else{
		  $subMit =  '<span class="label label-warning">Payment Received/Paid Pending Since '.$obj->getDaysDifference($rows['ADDONDATE'],date('Y-m-d',time())).' Days</span>';
	 }

	$date = date('d-m-Y',strtotime($rows['ADDONDATE']));
	$docLink =  '<a href="documents.php?comid='.$comid.'&amp;page=1" style="color:green;" target="_blank" title="Click me">Docs</a>';
	
if($rows['REDIRECTTO']!=''){
	$reDirectLink =  '<a href="'.$rows['REDIRECTTO'].'&alertid='.$rows['ALERTID'].' target="_blank"><i class="fa fa-edit "></i> View</a>';
  }else{
$reDirectLink=  '<a href="payment_grid.php?comid='.$comid.'&page='.$obj->getCompareTableData($comid, 'STATUS').'&alertid='.$rows['ALERTID'].'" target="_blank"><i class="fa fa-edit "></i> View</a>';
   
	

} 
}
$aaData[] = array('col1'=>$j.'.', 'col2'=>$voyagename, 'col3'=>$voyageno, 'col4'=>$formname, 'col5'=>$invoiceno, 'col6'=>$paytype, 'col7'=>$vendorname, 'col8'=>$subMit, 'col9'=>$date, 'col10'=>$docLink, 'col11'=>$reDirectLink);

}


}


}

// echo count($aaData);

echo json_encode(array("draw"=>intval($_POST['draw']),"recordsTotal"=>count($aaData),"recordsFiltered"=>count($aaData),"records" => $aaData));

}


function unHoldPayments(){

	 $obj 		= new data();

	 $connect	= $obj->funConnect();

	 if($_REQUEST['idenType']=='HIRE STATEMENT'){
		
		$sqlForunHold = "update invoice_hire_master set PAYMENT_STATUS='payment_payable' where INVOICEID='".$_REQUEST['idenId']."'";

		mysql_query($sqlForunHold);

		echo true;

	 }elseif($_REQUEST['idenType']=='PAYMENT'){


		mysql_query("update request_master set PAYMENT_STATUS='payment_payable' where REQ_ID='".$_REQUEST['idenId']."'");

		echo true;

	 }elseif($_REQUEST['idenType']=='TC HIRE STATEMENT'){

		$sqlForunHold = "update invoice_hiretc_master set PAYMENT_STATUS='payment_payable' where INVOICEID='".$_REQUEST['idenId']."'";

		mysql_query($sqlForunHold);

		echo true;

	 }
}
function getPeriodDetails()
{
    $obj 		= new data();
	$connect	= $obj->funConnect();
	$periodid = $_REQUEST['periodid'];	
	
	$querymain = "select * from period_contract_master where PERIODID='".$periodid."'";
	$resmain = mysql_query($querymain);
	$rowsmain = mysql_fetch_assoc($resmain);
	
	$period_hire_details = array();
	$query = "select * from period_contract_master_slave4 where PERIODID='".$periodid."'";
	$res = mysql_query($query);
	$hirenum = mysql_num_rows($res);
	while($rows = mysql_fetch_assoc($res))
	{
	    if($rows['HIRE_FROM']=='0000-00-00 00:00:00' || $rows['HIRE_FROM']=='1970-01-01 08:00:00'){$hirefrom = '';}else{$hirefrom = date('d-m-Y H:i',strtotime($rows['HIRE_FROM']));}
        if($rows['HIRE_TO']=='0000-00-00 00:00:00' || $rows['HIRE_TO']=='1970-01-01 08:00:00'){$hireto = '';}else{$hireto = date('d-m-Y H:i',strtotime($rows['HIRE_TO']));}
		
	    $period_hire_details[] = array('HIRE_FROM'=>$hirefrom, 'HIRE_TO'=>$hireto, 'HIRE_RATE'=>$rows['HIRE_RATE'], 'HIRE_DAYS'=>$rows['HIRE_DAYS']);
	}
	
	
	$period_bunker_details = array();
	$query = "select * from period_contract_master_slave1 where PERIODID='".$periodid."'";
	$res = mysql_query($query);
	$bunkernum = mysql_num_rows($res);
	while($rows = mysql_fetch_assoc($res))
	{
	    if($rows['BUNKER_DATE']=='0000-00-00' || $rows['BUNKER_DATE']=='1970-01-01'){$bunkerdate = '';}else{$bunkerdate = date('d-m-Y',strtotime($rows['BUNKER_DATE']));}
		
	    $period_bunker_details[] = array('BUNKERGRADEID'=>$rows['BUNKERGRADEID'], 'BUNKER_DATE'=>$bunkerdate, 'BUNKER_QTY'=>$rows['BUNKER_QTY'], 'BUNKER_AMT'=>$rows['BUNKER_AMT'], 'BUNKER_RATE'=>$rows['BUNKER_PRICE'], 'IDENTITY'=>$rows['IDENTITY']);
	}
	
	
	$period_offhire_details = array();
	$query = "select * from period_contract_master_slave2 where PERIODID='".$periodid."'";
	$res = mysql_query($query);
	$offhirenum = mysql_num_rows($res);
	while($rows = mysql_fetch_assoc($res))
	{
	    if($rows['OFF_HIRE_FROM']=='0000-00-00 00:00:00' || $rows['OFF_HIRE_FROM']=='1970-01-01 08:00:00'){$offhirefrom = '';}else{$offhirefrom = date('d-m-Y H:i',strtotime($rows['OFF_HIRE_FROM']));}
        if($rows['OFF_HIRE_TO']=='0000-00-00 00:00:00' || $rows['OFF_HIRE_TO']=='1970-01-01 08:00:00'){$offhireto = '';}else{$offhireto = date('d-m-Y H:i',strtotime($rows['OFF_HIRE_TO']));}
		
		$OFF_HIRE_BUNKER = array();
		$query1 = "select * from period_contract_master_slave21 where PERIODID='".$periodid."' and PERIOD_SLAVEID='".$rows['PERIOD_SLAVEID']."'";
		$res1 = mysql_query($query1);
		$rec1 = mysql_num_rows($res1);
		while($rows1 = mysql_fetch_assoc($res1))
		{
			$OFF_HIRE_BUNKER[] = array('BUNKERGRADEID'=>$rows1['BUNKERGRADEID'], 'BUNKER_QTY'=>$rows1['BUNKER_QTY'], 'BUNKER_PRICE'=>$rows1['BUNKER_PRICE'], 'BUNKER_AMT'=>$rows1['BUNKER_AMT'], 'CHK_OWNER_ACCOUNT'=>$rows1['CHK_OWNER_ACCOUNT']);
		}
	    $period_offhire_details[] = array('OFF_HIRE_REASON'=>$rows['OFF_HIRE_REASON'], 'OFF_HIRE_FROM'=>$offhirefrom, 'OFF_HIRE_TO'=>$offhireto, 'OFF_HIRE_DAYS'=>$rows['OFF_HIRE_DAYS'], 'OFF_HIRE_RATE'=>$rows['OFF_HIRE_RATE'], 'OFF_HIRE_AMT'=>$rows['OFF_HIRE_AMT'], 'OFF_HIRE_BUNKER'=>$OFF_HIRE_BUNKER);
	}
	
	echo json_encode(array('vesselimoid'=>$rowsmain['VESSEL_IMO_ID'], 'period_hire_details' => $period_hire_details, 'period_bunker_details'=>$period_bunker_details, 'period_offhire_details'=>$period_offhire_details, 'hirenum' => $hirenum, 'bunkernum' => $bunkernum, 'offhirenum'=>$offhirenum));
}

function getHeadwiseSummReports()
{
	$obj 			= new data();
	$connect		= $obj->funConnect();
	$txtFrom_Date 	= strtotime($_REQUEST['txtFrom_Date']);
	$txtTo_Date 	= strtotime($_REQUEST['txtTo_Date']);
	$selVendor 		= $_REQUEST['selVendor'];
	$selBType       = $_REQUEST['selBType'];
	$selCOASpot     = $_REQUEST['selCOASpot'];

	echo 
	'<table id="headwise_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>';
			$querymisc = mysql_query("select NAME, OWNER_RCOSTID from owner_related_cost_master where STATUS=1 order by NAME");
		    while($rowsmisc = mysql_fetch_assoc($querymisc))
			{
				echo '<th align="left">'.$rowsmisc['NAME'].'</th>';
			}			
	echo '</tr>
	</thead>
	<tbody>';
	if($selCOASpot == 2){$subquery = " and freight_cost_estimate_compare.COAAID is not NULL";$coa_spot='COA';}else{$subquery = " and freight_cost_estimate_compare.COAAID is NULL";$coa_spot='Spot';}

	$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." and date(freight_cost_estimete_master.TRANS_DATE)>='".date('Y-m-d',$txtFrom_Date)."' and date(freight_cost_estimete_master.TRANS_DATE)<='".date('Y-m-d',$txtTo_Date)."' order by freight_cost_estimate_compare.COMID desc";
	
	$res = mysql_query($sql) or die($sql);
	$rec = mysql_num_rows($res);
	$j = 1;
	if($rec == 0)
	{
	
	}
	else
	{	
		while($rows = mysql_fetch_assoc($res))
		{
            $fcaid= $obj->getCompareEstimateData($rows['COMID'],"FCAID");
			if($selVendor!='')
			{
				$sql1 = "select RAW_AMOUNT from freight_cost_estimete_slave3 where FCAID='".$fcaid."' and VENDORID='".$selVendor."' and IDENTIFY='ORC' and RAW_AMOUNT>0";
			}
		   else
			{
				$sql1 = "select RAW_AMOUNT from freight_cost_estimete_slave3 where FCAID='".$fcaid."' and IDENTIFY='ORC' and RAW_AMOUNT>0";
			}
			$res1 = mysql_query($sql1) or die($sql1);
			$num1 = mysql_num_rows($res1);
			if($num1>0)
			{
				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->getCompareEstimateData($rows['COMID'],"VOYAGE_NO").'</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">'.$coa_spot.'</td>';
				$querymisc = mysql_query("select NAME, OWNER_RCOSTID from owner_related_cost_master where STATUS=1 order by NAME");
				while($rowsmisc = mysql_fetch_assoc($querymisc))
				{
				   if($selVendor!='')
					{
						$sql1 = "select RAW_AMOUNT from freight_cost_estimete_slave3 where FCAID='".$fcaid."' and VENDORID='".$selVendor."' and IDENTY_ID='".$rowsmisc['OWNER_RCOSTID']."' and IDENTIFY='ORC' and RAW_AMOUNT>0";
					}
				   else
					{
						$sql1 = "select RAW_AMOUNT from freight_cost_estimete_slave3 where FCAID='".$fcaid."' and IDENTY_ID='".$rowsmisc['OWNER_RCOSTID']."' and IDENTIFY='ORC' and RAW_AMOUNT>0";
					}
				   $res1 = mysql_query($sql1) or die($sql1);
				   $rows1 = mysql_fetch_assoc($res1);
				   echo '<td align="left">'.$rows1['RAW_AMOUNT'].'</td>';
				}
				echo '</tr>';
				$j++;
			}
		}
	}
	echo '</tbody>';
	echo '</table>';
}


function getVendorListJson()
{
	$obj 			= new data();
	$connect		= $obj->funConnect();
	
	$aColumns = array("VENDORID", "VENDOR_TYPE", "NAME", "SHORT_NAME", "CODE");
	
	$sIndexColumn = "VENDORID";
	
	$sTable = "vendor_master";
	
	if(!empty($_POST['order'][0]['column']))
	{
		$sOrder = "ORDER BY  ".$aColumns[intval($_POST['order'][0]['column'])]." ".$_POST['order'][0]['dir'];
	}
	else
	{
		$sOrder = "ORDER BY VENDORID";
	}
	
	$sWhere = "";
	
	if ($_POST['search']['value']!= "")
	{
		$sWhere = " MCOMPANYID='".$_SESSION['company']."' and (NAME LIKE '%".$_POST['search']['value']."%' or VENDOR_TYPE LIKE '%".$_POST['search']['value']."%' or SHORT_NAME LIKE '%".$_POST['search']['value']."%' or CODE LIKE '%".$_POST['search']['value']."%')";
	}else{$sWhere = " MCOMPANYID='".$_SESSION['company']."'";}
	
	$sQuery = "SELECT * FROM (select VENDORID, VENDOR_TYPEID, (select NAME from vendor_type_master where vendor_type_master.VENDOR_TYPEID=vendor_master.VENDOR_TYPEID) as VENDOR_TYPE, SHORT_NAME, CODE, NAME, MCOMPANYID, STATUS from vendor_master ) as innerTable where $sWhere $sOrder LIMIT ".$_POST['start'].", ".$_POST['length']."";
	
	$rResult = mysql_query($sQuery) or die($sQuery);
	
	$sQuery = "	SELECT COUNT(".$sIndexColumn.") FROM (select * from vendor_master ) as innerTable $sWhere";
	
	$rResultFilterTotal = mysql_query($sQuery);
	$aResultFilterTotal = mysql_fetch_array($rResultFilterTotal);
	$totalFiltered = $aResultFilterTotal[0];
	
	$sQuery = " SELECT COUNT(".$sIndexColumn.") FROM $sTable where MCOMPANYID='".$_SESSION['company']."'";
	$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;
		
		$details1 = '<a href="updatevendor.php?id='.$aRow['VENDORID'].'" title="Edit Details" ><i class="fa fa-edit "></i></a>';
		
		if($aRow['STATUS'] == 1)
		{
			$status = '<div class="onoffswitch">
			<input type="text" name="onoffswitch_'.$i.'" class="onoffswitch-checkbox" id="myonoffswitch_'.$i.'" checked="checked" onclick="return getChangeStatus('.$aRow['VENDORID'].','.$aRow['STATUS'].','.$i.');" value="'.$i.'">
			<label class="onoffswitch-label" for="myonoffswitch_'.$i.'">
				<div class="onoffswitch-inner"></div>
				<div class="onoffswitch-switch"></div>
			</label>
			</div>';
		}
		else
		{
			$status = '<div class="onoffswitch">
			<input type="text" name="onoffswitch_'.$i.'" class="onoffswitch-checkbox" id="myonoffswitch_'.$i.'" unchecked onclick="return getChangeStatus('.$aRow['VENDORID'].','.$aRow['STATUS'].','.$i.');" value="'.$i.'">
			<label class="onoffswitch-label" for="myonoffswitch_'.$i.'">
				<div class="onoffswitch-inner"></div>
				<div class="onoffswitch-switch"></div>
			</label>
			</div>';
		}
		
		$aaData[] = array('col1'=>$i, 'col2'=>$aRow['VENDOR_TYPE'], 'col3'=>$aRow['NAME'], 'col4'=>$aRow['SHORT_NAME'], 'col5'=>$aRow['CODE'], 'col6'=>$status, 'col7'=>$details1);
		
	}
	
	echo json_encode(array("draw"=>intval($_POST['draw']),"recordsTotal"=>$totalData,"recordsFiltered"=>$totalFiltered,"records" => $aaData));
}


function getFleetListJson()
{
	$obj 			= new data();
	$connect		= $obj->funConnect();
	$_SESSION['selBType'] = $_POST['selBType'];
	
	
	$aColumns = array("VESSEL_IMO_ID", "VESSEL_TYPE", "VESSEL_NAME", "BUSINESS_TYPE", "IMO_NO", "DWT", "YEARBUILT");
	
	$sIndexColumn = "VESSEL_IMO_ID";
	
	$sTable = "vessel_imo_master";
	
	if(!empty($_POST['order'][0]['column']))
	{
		$sOrder = "ORDER BY  ".$aColumns[intval($_POST['order'][0]['column'])]." ".$_POST['order'][0]['dir'];
	}
	else
	{
		$sOrder = "ORDER BY VESSEL_IMO_ID";
	}
	
	$sWhere = "";
	
	if ($_POST['search']['value']!= "")
	{
		$sWhere = " BUSINESSTYPEID='".$_SESSION['selBType']."' and MCOMPANYID='".$_SESSION['company']."' and (VESSEL_NAME LIKE '%".$_POST['search']['value']."%' or BUSINESS_TYPE LIKE '%".$_POST['search']['value']."%' or VESSEL_TYPE LIKE '%".$_POST['search']['value']."%' or IMO_NO LIKE '%".$_POST['search']['value']."%' or DWT LIKE '%".$_POST['search']['value']."%' or YEARBUILT LIKE '%".$_POST['search']['value']."%' )";
	}else{$sWhere = " BUSINESSTYPEID='".$_SESSION['selBType']."' and MCOMPANYID='".$_SESSION['company']."'";}
	
	$sQuery = "SELECT * FROM (select VESSEL_IMO_ID, (select VESSELTYPE from vessel_type_master where VESSELTYPEID=vessel_imo_master.VESSEL_TYPE) as VESSEL_TYPE, IMO_NO, DWT, YEARBUILT, VESSEL_NAME, BUSINESSTYPEID, (case when (BUSINESSTYPEID = 1) THEN 'Gas' when (BUSINESSTYPEID = 2) THEN 'Tanker' ELSE 'Dry Cargo' END) as BUSINESS_TYPE, MCOMPANYID from vessel_imo_master ) as innerTable where $sWhere $sOrder LIMIT ".$_POST['start'].", ".$_POST['length']."";
	
	$rResult = mysql_query($sQuery) or die($sQuery);
	
	$sQuery = "	SELECT COUNT(".$sIndexColumn.") FROM (select * from vessel_imo_master ) as innerTable $sWhere";
	
	$rResultFilterTotal = mysql_query($sQuery);
	$aResultFilterTotal = mysql_fetch_array($rResultFilterTotal);
	$totalFiltered = $aResultFilterTotal[0];
	
	$sQuery = " SELECT COUNT(".$sIndexColumn.") FROM $sTable where BUSINESSTYPEID='".$_SESSION['selBType']."' and MCOMPANYID='".$_SESSION['company']."'";
	$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;
		
		$details1 = '<a href="updatevessel.php?id='.$aRow['VESSEL_IMO_ID'].'" title="Edit Details" ><i class="fa fa-edit "></i></a>';
		if($aRow['BUSINESSTYPEID'] == 3)
			{
			$details2 = '<td align="center" valign="middle" class="input-text"><a class="fa fa-file-text-o" href="view_vessel.php?id='.$aRow['VESSEL_IMO_ID'].'" title="View Vessel Particulars" ></a>&nbsp; | &nbsp;<a class="fa fa-edit" href="update_vessel.php?id='.$aRow['VESSEL_IMO_ID'].'" title="Edit Vessel Particulars" ></td>';
			}else{
			$details2 = '<td align="center" valign="middle" class="input-text"><a class="fa fa-file-text-o" href="view_vessel_tankers.php?id='.$aRow['VESSEL_IMO_ID'].'" title="View Vessel Particulars" ></a>&nbsp; | &nbsp;<a class="fa fa-edit" href="update_vessel_tankers.php?id='.$aRow['VESSEL_IMO_ID'].'" title="Edit Vessel Particulars" ></td>';	
			}
		$details3 = '<a class="fa fa-edit" href="commercial_parameter.php?id='.$aRow['VESSEL_IMO_ID'].'" title="Commercial Parameters" >';
		$details4 = '<input type="checkbox" name="chkVSL[]" id="chkVSL_'.$i.'" value="'.$aRow['VESSEL_IMO_ID'].'" class="checkbox"/>';
		
		$aaData[] = array('col1'=>$i, 'col2'=>$aRow['VESSEL_TYPE'], 'col3'=>$aRow['VESSEL_NAME'], 'col4'=>$aRow['BUSINESS_TYPE'], 'col5'=>$aRow['IMO_NO'], 'col6'=>$aRow['DWT'], 'col7'=>$aRow['YEARBUILT'], 'col8'=>$details1, 'col9'=>$details2, 'col10'=>$details3, 'col11'=>$details4);
		
	}
	
	echo json_encode(array("draw"=>intval($_POST['draw']),"recordsTotal"=>$totalData,"recordsFiltered"=>$totalFiltered,"records" => $aaData));
}

function getTCVessel_HistoryList()
{
   //echo 1;die;
	$obj 			= new data();
	$connect		= $obj->funConnect();
	$_SESSION['selBType'] = $_POST['selBType'];
	
	$aColumns = array("BUSINESS_TYPE", "MESSAGE", "VESSEL_NAME", "CP_DATE1", "TC_NO", "CONTACT_PERSON");
	
	$sIndexColumn = "COMID";
	
	$sTable = "chartering_estimate_tc_compare";
	
	if(!empty($_POST['order'][0]['column']))
	{
		$sOrder = "ORDER BY  ".$aColumns[intval($_POST['order'][0]['column'])]." ".$_POST['order'][0]['dir'];
	}
	else
	{
		$sOrder = "ORDER BY COMID";
	}
	
	$sWhere = "";
	
	if ($_POST['search']['value']!= "")
	{
		$sWhere = " FINAL_ID!='' and STATUS=5 and (select ESTIMATE_TYPE from chartering_estimate_tc_master where chartering_estimate_tc_master.TCOUTID=TCOUTIDD)='".$_SESSION['selBType']."' and (select FIXED from chartering_estimate_tc_master where chartering_estimate_tc_master.TCOUTID=TCOUTIDD)=1 and MODULEID='".$_SESSION['moduleid']."' AND MCOMPANYID='".$_SESSION['company']."' and (VESSEL_NAME LIKE '%".$_POST['search']['value']."%' or MESSAGE LIKE '%".$_POST['search']['value']."%' or BUSINESS_TYPE LIKE '%".$_POST['search']['value']."%' or TC_NO LIKE '%".$_POST['search']['value']."%' or (select CP_DATE1 from chartering_estimate_tc_master where chartering_estimate_tc_master.TCOUTID=TCOUTIDD) LIKE '%".$_POST['search']['value']."%' or (select CONTACT_PERSON from login where login.LOGINID=USERID) LIKE '%".$_POST['search']['value']."%' )";
	}else{$sWhere = " FINAL_ID!='' and STATUS=5 and (select ESTIMATE_TYPE from chartering_estimate_tc_master where chartering_estimate_tc_master.TCOUTID=TCOUTIDD)='".$_SESSION['selBType']."' and (select FIXED from chartering_estimate_tc_master where chartering_estimate_tc_master.TCOUTID=TCOUTIDD)=1 and MODULEID='".$_SESSION['moduleid']."' AND MCOMPANYID='".$_SESSION['company']."'";}
	
	$sQuery = "SELECT * FROM (select COMID, MESSAGE, STATUS, USERID, TCOUTID as TCOUTIDD, (select (case when (ESTIMATE_TYPE = 1) THEN 'Gas' when (ESTIMATE_TYPE = 2) THEN 'Tanker' ELSE 'Dry Cargo' END) as ESTIMATE_TYPE from chartering_estimate_tc_master where chartering_estimate_tc_master.TCOUTID=TCOUTIDD) as BUSINESS_TYPE, MCOMPANYID, MODULEID, (select CONTACT_PERSON from login where login.LOGINID=chartering_estimate_tc_compare.USERID) as CONTACT_PERSON, FINAL_ID, (select TC_NO from chartering_estimate_tc_master where chartering_estimate_tc_master.TCOUTID=TCOUTIDD) as TC_NO, (select CP_DATE1 from chartering_estimate_tc_master where chartering_estimate_tc_master.TCOUTID=TCOUTIDD) as CP_DATE1, (select VESSEL_NAME from vessel_imo_master where vessel_imo_master.VESSEL_IMO_ID=(select VESSEL_IMO_ID from chartering_estimate_tc_master where chartering_estimate_tc_master.TCOUTID=TCOUTIDD)) as VESSEL_NAME from chartering_estimate_tc_compare) as innerTable where $sWhere $sOrder LIMIT ".$_POST['start'].", ".$_POST['length']."";
	
	$rResult = mysql_query($sQuery) or die($sQuery);
	
	$sQuery = "	SELECT COUNT(".$sIndexColumn.") FROM (select * from chartering_estimate_tc_compare) 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;
		
		$financila_link = '';
		$sql1 = "select * from cost_sheettc_name_master where COMID='".$aRow['COMID']."'";
		$latestsheet='';
		$res1 = mysql_query($sql1);
		$rec1 = mysql_num_rows($res1);
		if($rec1 > 0)
		{
			while($rows1 = mysql_fetch_assoc($res1))
			{
			   $latestsheet = $rows1['COST_SHEETID'];
			   $href = "./addhistoricaldatatc.php?comid=".$aRow['COMID']."&cost_sheet_id=".$rows1['COST_SHEETID']."&page=7";
				   
					$financila_link = "<a href='".$href."'>".str_replace(' ','&nbsp;',$rows1['SHEET_NAME'])."</a><br/>";				
			}
		}	
		
		//$paymentgrid = '<a href="payment_grid.php?comid='.$aRow['COMID'].'&page=7" >View</a><br><br><a href="piclubdeclaration.php?comid='.$aRow['COMID'].'&page=7" >P & I Club Declaration</a>';
		
		$aaData[] = array('col1'=>$aRow['BUSINESS_TYPE'], 'col2'=>$aRow['MESSAGE'], 'col3'=>$aRow['VESSEL_NAME'], 'col4'=>date('d-m-Y',strtotime($aRow['CP_DATE1'])), 'col5'=>$aRow['TC_NO'], 'col6'=>$aRow['CONTACT_PERSON'], 'col7'=>$financila_link, 'col8'=>'History');
		
	}
	
	echo json_encode(array("draw"=>intval($_POST['draw']),"recordsTotal"=>$totalData,"recordsFiltered"=>$totalFiltered,"records" => $aaData));
}


function getAgingReceivablesPayableReport()
{
	$obj 			= new data();
	$connect		= $obj->funConnect();
	
	$selVendor      = $_REQUEST['selVendor'];
	$selBType    	= $_REQUEST['selBType'];
	$selSpotCOA 	= $_REQUEST['selSpotCOA'];
	$selVoyageNo 	= $_REQUEST['selVoyageNo'];
	$selTCNo 	    = $_REQUEST['selTCNo'];
	
	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="9%">Client</th>
					<th align="left" width="9%">Spot/COA/TC</th>
					<th align="left" width="9%">Nom Id/Voyage No.</th>
					<th align="left" width="9%">Vessel</th>
					<th align="left" width="9%">Amount Invoiced</th>
					<th align="left" width="9%">Amount Received</th>
					<th align="left" width="9%">Difference</th>
					<th align="left" width="9%">Payment Advice Created</th>
					<th align="left" width="9%">Amount Paid</th>
					<th align="left" width="9%">Difference</th>
				</tr>
			</thead>
			<tbody>';
	if($selSpotCOA == 3)
	{
	    $selCOASpot1 = 'TC';
		$subquery = ($selTCNo!='null')?' and chartering_estimate_tc_compare.COMID in ('.$selTCNo.') ':'';
		$sql = "select * 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) ".$subquery." and chartering_estimate_tc_master.ESTIMATE_TYPE='".$selBType."' order by chartering_estimate_tc_compare.COMID desc";
	}
	else
	{
		if($selSpotCOA == 2){$subquery = " and freight_cost_estimete_master.COAID is not NULL";$selCOASpot1='COA';}else{$subquery = " and freight_cost_estimete_master.COAID is NULL";$selCOASpot1='Spot';}
		$subquery.= ($selVoyageNo!='null')?' and freight_cost_estimate_compare.COMID in ('.$selVoyageNo.') ':'';
		$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";
	}
	$res = mysql_query($sql);
	$rec = mysql_num_rows($res);
	$i = 1;
	if($rec == 0)
	{
		
	}
	else
	{	
		while($rows = mysql_fetch_assoc($res))
		{		
		    $invoicedamount = $receivedamount = 0;
			$paymentamount = $paidamount = 0;  
		    if($selSpotCOA == 3)
        	{
				$tcoutid = $obj->getLatestCostSheetIDTC($rows['COMID']);
				$obj->viewTCEstimationTempleteRecordsNew($tcoutid);
				$sqltc = "SELECT * from chartering_tc_estimate_slave1 where TCOUTID='".$obj->getFun1()."'";
				$restc 	= mysql_query($sqltc);
				$rectc 	= mysql_num_rows($restc);
				while($rowstc = mysql_fetch_assoc($restc))
				{
					if(($_REQUEST['selVendor']!='' && $_REQUEST['selVendor']==$rowstc['TTL_REV_VENDOR']) || $_REQUEST['selVendor'] =='')
					{
						$sql1 = "select NET_PAYABLE_TAX, P_AMT from invoice_tchire_master where COMID='".$rows['COMID']."' and RANDOMID='".$rowstc['RANDOMID']."' and STATUS<=5";
						$res1 = mysql_query($sql1) or die($sql1);
						while ($rows1 = mysql_fetch_assoc($res1))
						{
							$diff = $rows1['NET_PAYABLE_TAX'] - $rows1['P_AMT'];
							if($diff > 1000)
							{
								$invoicedamount = $invoicedamount + $rows1['NET_PAYABLE_TAX'];
								$receivedamount = $receivedamount + $rows1['P_AMT'];
							}
							
						}
					}
					
					if(($_REQUEST['selVendor']!='' && $_REQUEST['selVendor']==$rowstc['TC_FINAL_HIERAGE_VENDOR']) || $_REQUEST['selVendor'] =='')
					{
						$sql1 = "select BALANCE_TO_OWNER, P_AMT from invoice_hiretc_master where COMID='".$rows['COMID']."' and RANDOMID='".$rowstc['RANDOMID']."'";
						$res1 = mysql_query($sql1) or die($sql1);
						while ($rows1 = mysql_fetch_assoc($res1))
						{
						    $diff = $rows1['BALANCE_TO_OWNER'] - $rows1['P_AMT'];
							if($diff > 1000)
							{
								$paymentamount = $paymentamount + $rows1['BALANCE_TO_OWNER'];
								$paidamount = $paidamount + $rows1['P_AMT'];
							}
						}
					}
					
					$sql1 = "select NET_PAYABLE_TAX, P_AMT from invoice_tcother_master where ".(($_REQUEST['selVendor']!='')?"VENDOR='".$selVendor."' and ":"")." COMID='".$rows['COMID']."' and RANDOMID='".$rowstc['RANDOMID']."'";
					$res1 = mysql_query($sql1) or die($sql1);
					while($rows1 = mysql_fetch_assoc($res1))
					{
						if($rows1['VENDOR']!="")
						{
						    $diff = $rows1['NET_PAYABLE_TAX'] - $rows1['P_AMT'];
							if($diff > 1000)
							{
								$invoicedamount = $invoicedamount + $rows1['NET_PAYABLE_TAX'];
								$receivedamount = $receivedamount + $rows1['P_AMT'];
							}
						}
					}
					
					$sql1 = "select FINAL_AMOUNT, P_AMT from payment_tcother_master where ".(($_REQUEST['selVendor']!='')?"VENDOR='".$selVendor."' and ":"")." COMID='".$rows['COMID']."' and RANDOMID='".$rowstc['RANDOMID']."'";
					$res1 = mysql_query($sql1) or die($sql1);
					while($rows1 = mysql_fetch_assoc($res1))
					{
						if($rows1['VENDOR']!="")
						{
						    $diff = $rows1['FINAL_AMOUNT'] - $rows1['P_AMT'];
							if($diff > 1000)
							{
								$paymentamount = $paymentamount + $rows1['FINAL_AMOUNT'];
								$paidamount = $paidamount + $rows1['P_AMT'];
							}	
						}
					}
				}
				
				if($invoicedamount > 0 || $invoicedamount < 0 || $paymentamount > 0 || $paymentamount < 0 )
				{
				echo '<tr>
				        <td>'.$i.'</td>
						<td>'.$obj->getVendorListNewData($selVendor,"NAME").'</td>
						<td>TC</td>
						<td>'.$obj->getCompareTableDataTC($rows['COMID'],"MESSAGE").'/'.$obj->getFun7().'</td>
						<td>'.$obj->getVesselIMOData($obj->getFun3(),"VESSEL_NAME").'</td>
						<td  align="right" style="background-color: #bcf4cc;">'.$obj->getNumberFormat1($invoicedamount).'<input type="hidden" id="hddninvoicedamt_'.$i.'" value="'.$obj->getNumberFormat1($invoicedamount).'"/></td>
						<td align="right" style="background-color: #bcf4cc;">'.$obj->getNumberFormat1($receivedamount).'<input type="hidden" id="hddnreceivedamt_'.$i.'" value="'.$obj->getNumberFormat1($receivedamount).'"/></td>
						<td align="right" style="background-color: #bcf4cc;">'.$obj->getNumberFormat1(($invoicedamount - $receivedamount)).'<input type="hidden" id="hddninvdiffamt_'.$i.'" value="'.$obj->getNumberFormat1(($invoicedamount - $receivedamount)).'"/></td>
						<td align="right" style="background-color: #f4dcbc;">'.$obj->getNumberFormat1($paymentamount).'<input type="hidden" id="hddnpaymentamt_'.$i.'" value="'.$obj->getNumberFormat1($paymentamount).'"/></td>
						<td align="right" style="background-color: #f4dcbc;">'.$obj->getNumberFormat1($paidamount).'<input type="hidden" id="hddnpaidamt_'.$i.'" value="'.$obj->getNumberFormat1($paidamount).'"/></td>
						<td align="right" style="background-color: #f4dcbc;">'.$obj->getNumberFormat1(($paymentamount - $paidamount)).'<input type="hidden" id="hddnipaymentdiffamt_'.$i.'" value="'.$obj->getNumberFormat1(($paymentamount - $paidamount)).'"/></td>
				     </tr>';
					 $i++;
				}
			}
			else
			{
				$fcaid = $obj->getLatestCostSheetID($rows['COMID']);
				$obj->viewFreightCostEstimationTempleteRecordsNew($fcaid);
				$identity = '';
				if($obj->getFun175()!='')
				{
					$sqlcoa = "select * from coa_master where COAID='".$obj->getFun175()."'";
					$resultcoa = mysql_query($sqlcoa) or die($sqlcoa);
					$rowscoa   = mysql_fetch_assoc($resultcoa);
					$charterer = $obj->getVendorListNewData($rowscoa['CHARTERER'],"NAME");
					$currency = $rowscoa['CURRENCY'];
					$identity = 'COA';
				}
				else
				{
					$currency = $obj->getFun206();
					$identity = 'VC';
				}
				
				$sql1 = "select NET_PAYABLE_TAX, P_AMT from other_invoice_master where ".(($_REQUEST['selVendor']!='')?"VENDOR='".$selVendor."' and ":"")." COMID='".$rows['COMID']."'";
				$res1 = mysql_query($sql1) or die($sql1);
				while ($rows1 = mysql_fetch_assoc($res1))
				{
				    $diff = $rows1['NET_PAYABLE_TAX'] - $rows1['P_AMT'];
					if($diff > 1000)
					{
						$invoicedamount = $invoicedamount + $rows1['NET_PAYABLE_TAX'];
						$receivedamount = $receivedamount + $rows1['P_AMT'];
					}
				}
				
				$sql1 = "select * from freight_invoice_master where ".(($_REQUEST['selVendor']!='')?"VENDOR='".$selVendor."' and ":"")." COMID='".$rows['COMID']."' ";
				$res1 = mysql_query($sql1) or die($sql1);
				while($rows1 = mysql_fetch_assoc($res1))
				{
					if($rows1['VENDOR']!="")
					{
					    $diff = $rows1['NET_PAYABLE_TAX'] - $rows1['P_AMT'];
						if($diff > 1000)
						{
							$invoicedamount = $invoicedamount + $rows1['NET_PAYABLE_TAX'];
							$receivedamount = $receivedamount + $rows1['P_AMT'];
						}
					}
				}
				
				if(($_REQUEST['selVendor']!='' && $_REQUEST['selVendor']==$obj->getFun140()) || $_REQUEST['selVendor'] =='')
				{
					$sql1 = "select BALANCE_TO_OWNER, P_AMT from invoice_hire_master where COMID='".$rows['COMID']."'";
					$res1 = mysql_query($sql1) or die($sql1);
					while ($rows1 = mysql_fetch_assoc($res1))
					{
					
					    $diff = $rows1['BALANCE_TO_OWNER'] - $rows1['P_AMT'];
						if($diff > 1000)
						{
							$paymentamount = $paymentamount + $rows1['BALANCE_TO_OWNER'];
							$paidamount = $paidamount + $rows1['P_AMT'];
						}
					}
				}
				
				$sql1 = "select REQ_TO_PAY, P_AMT from request_master where ".(($_REQUEST['selVendor']!='')?"VENDOR='".$selVendor."' and ":"")." COMID='".$rows['COMID']."'";
				$res1 = mysql_query($sql1) or die($sql1);
				while ($rows1 = mysql_fetch_assoc($res1))
				{
				    $diff = $rows1['REQ_TO_PAY'] - $rows1['P_AMT'];
					if($diff > 1000)
					{
						$paymentamount = $paymentamount + $rows1['REQ_TO_PAY'];
						$paidamount = $paidamount + $rows1['P_AMT'];
					}
				}
				
				if($invoicedamount > 0 || $invoicedamount < 0 || $paymentamount > 0 || $paymentamount < 0 )
				{
				echo '<tr>
				        <td>'.$i.'</td>
						<td>'.$obj->getVendorListNewData($selVendor,"NAME").'</td>
						<td>'.$identity.'</td>
						<td>'.$obj->getFun8().'</td>
						<td>'.$obj->getVesselIMOData($obj->getFun5(),"VESSEL_NAME").'</td>
						<td align="right" style="background-color: #bcf4cc;">'.$obj->getNumberFormat1($invoicedamount).'<input type="hidden" id="hddninvoicedamt_'.$i.'" value="'.$obj->getNumberFormat1($invoicedamount).'"/></td>
						<td align="right" style="background-color: #bcf4cc;">'.$obj->getNumberFormat1($receivedamount).'<input type="hidden" id="hddnreceivedamt_'.$i.'" value="'.$obj->getNumberFormat1($receivedamount).'"/></td>
						<td align="right" style="background-color: #bcf4cc;">'.$obj->getNumberFormat1(($invoicedamount - $receivedamount)).'<input type="hidden" id="hddninvdiffamt_'.$i.'" value="'.$obj->getNumberFormat1(($invoicedamount - $receivedamount)).'"/></td>
						<td align="right" style="background-color: #f4dcbc;">'.$obj->getNumberFormat1($paymentamount).'<input type="hidden" id="hddnpaymentamt_'.$i.'" value="'.$obj->getNumberFormat1($paymentamount).'"/></td>
						<td align="right" style="background-color: #f4dcbc;">'.$obj->getNumberFormat1($paidamount).'<input type="hidden" id="hddnpaidamt_'.$i.'" value="'.$obj->getNumberFormat1($paidamount).'"/></td>
						<td align="right" style="background-color: #f4dcbc;">'.$obj->getNumberFormat1(($paymentamount - $paidamount)).'<input type="hidden" id="hddnipaymentdiffamt_'.$i.'" value="'.$obj->getNumberFormat1(($paymentamount - $paidamount)).'"/></td>
				     </tr>';
					 $i++;
				}
			    
			}
		}
	}
	
	
	echo '</tbody>';
	echo '<tfoot>
	       <tr>
			<td colspan="5"><strong>Total</strong></td>
			<td style="background-color: #bcf4cc;"><input type="text" name="txtInvoicedAmt" id="txtInvoicedAmt" class="form-control" autocomplete="off" value="" readonly/></td>
			<td style="background-color: #bcf4cc;"><input type="text" name="txtReceivedAmt" id="txtReceivedAmt" class="form-control" autocomplete="off" value="" readonly/></td>
			<td style="background-color: #bcf4cc;"><input type="text" name="txtInvDiffAmt" id="txtInvDiffAmt" class="form-control" autocomplete="off" value="" readonly/></td>
			<td style="background-color: #f4dcbc;"><input type="text" name="txtPaymentAmt" id="txtPaymentAmt" class="form-control" autocomplete="off" value="" readonly/></td>
			<td style="background-color: #f4dcbc;"><input type="text" name="txtPaidAmt" id="txtPaidAmt" class="form-control" autocomplete="off" value="" readonly/></td>
			<td style="background-color: #f4dcbc;"><input type="text" name="txtPayDiffAmt" id="txtPayDiffAmt" class="form-control" autocomplete="off" value="" readonly/></td>
		 </tr>
		 <tr>
			<td colspan="5"><strong>Net Balance</strong></td>
			<td><input type="text" name="txtBalanceAmt" id="txtBalanceAmt" class="form-control" autocomplete="off" value="" readonly/></td>
		 </tr>
	   </tfoot>'; 
	echo '</table>';
}



function getVCVessel_HistoryList()
{
   //echo 1;die;
	$obj 			= new data();
	$connect		= $obj->funConnect();
	$_SESSION['selBType'] = $_POST['selBType'];
	
	$aColumns = array("BUSINESS_TYPE", "MESSAGE", "CARGONAME", "VESSEL_NAME", "VOYAGE_NO", "CP_DATE");
	
	$sIndexColumn = "COMID";
	
	$sTable = "freight_cost_estimate_compare";
	
	if(!empty($_POST['order'][0]['column']))
	{
		$sOrder = "ORDER BY  ".$aColumns[intval($_POST['order'][0]['column'])]." ".$_POST['order'][0]['dir'];
	}
	else
	{
		$sOrder = "ORDER BY COMID";
	}
	
	$sWhere = "";
	
	if ($_POST['search']['value']!= "")
	{
		$sWhere = " FINAL_ID!='' and STATUS=5 and (select ESTIMATE_TYPE from freight_cost_estimete_master where freight_cost_estimete_master.FCAID=FCAIDD)='".$_SESSION['selBType']."' and (select FIXED from freight_cost_estimete_master where freight_cost_estimete_master.FCAID=FCAIDD)=1 and MODULEID='".$_SESSION['moduleid']."' AND MCOMPANYID='".$_SESSION['company']."' and (VESSEL_NAME LIKE '%".$_POST['search']['value']."%' or MESSAGE LIKE '%".$_POST['search']['value']."%' or BUSINESS_TYPE LIKE '%".$_POST['search']['value']."%' or VOYAGE_NO LIKE '%".$_POST['search']['value']."%' or CARGONAME LIKE '%".$_POST['search']['value']."%' or ADD_ON_DATE LIKE '%".$_POST['search']['value']."%')";
	}else{$sWhere = " FINAL_ID!='' and STATUS=5 and (select ESTIMATE_TYPE from freight_cost_estimete_master where freight_cost_estimete_master.FCAID=FCAIDD)='".$_SESSION['selBType']."' and (select FIXED from freight_cost_estimete_master where freight_cost_estimete_master.FCAID=FCAIDD)=1 and MODULEID='".$_SESSION['moduleid']."' AND MCOMPANYID='".$_SESSION['company']."'";}
	
	$sQuery = "SELECT * FROM (select COMID, MESSAGE, STATUS, USERID, ADD_ON_DATE, FCAID as FCAIDD, (select MATERIAL_CODE_DESC from cargo_master where cargo_master.MATERIALID = (select CARGO_ID from freight_cost_estimete_master where freight_cost_estimete_master.FCAID=FCAIDD)) as CARGONAME, (select (case when (ESTIMATE_TYPE = 1) THEN 'Gas' when (ESTIMATE_TYPE = 2) THEN 'Tanker' ELSE 'Dry Cargo' END) as ESTIMATE_TYPE from freight_cost_estimete_master where freight_cost_estimete_master.FCAID=FCAIDD) as BUSINESS_TYPE, MCOMPANYID, MODULEID, (select CONTACT_PERSON from login where login.LOGINID=freight_cost_estimate_compare.USERID) as CONTACT_PERSON, FINAL_ID, (select VOYAGE_NO from freight_cost_estimete_master where freight_cost_estimete_master.FCAID=FCAIDD) as VOYAGE_NO, (select TRANS_DATE from freight_cost_estimete_master where freight_cost_estimete_master.FCAID=FCAIDD) as TRANS_DATE, (select VESSEL_NAME from vessel_imo_master where vessel_imo_master.VESSEL_IMO_ID=(select VESSEL_IMO_ID from freight_cost_estimete_master where freight_cost_estimete_master.FCAID=FCAIDD)) as VESSEL_NAME from freight_cost_estimate_compare) as innerTable where $sWhere $sOrder LIMIT ".$_POST['start'].", ".$_POST['length']."";
	
	$rResult = mysql_query($sQuery) or die($sQuery);
	
	$sQuery = "	SELECT COUNT(".$sIndexColumn.") FROM (select * from freight_cost_estimate_compare) 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;
		
		$financila_link = '';
		$sql1 = "select * from cost_sheet_name_master where COMID='".$aRow['COMID']."'";
		$latestsheet='';
		$res1 = mysql_query($sql1);
		$rec1 = mysql_num_rows($res1);
		if($rec1 > 0)
		{
			while($rows1 = mysql_fetch_assoc($res1))
			{
			   $latestsheet = $rows1['COST_SHEETID'];
			   $href = "./addhistoricaldata.php?comid=".$aRow['COMID']."&cost_sheet_id=".$rows1['COST_SHEETID']."&page=7";
				   
					$financila_link = "<a href='".$href."'>".str_replace(' ','&nbsp;',$rows1['SHEET_NAME'])."</a><br/>";				
			}
		}	
		
		$fdalink = '<a href="nominate_agent.php?comid='.$aRow['COMID'].'&page=7">FDA</a>';
		
		$calculations = '<a href="laytime_calculation.php?comid='.$aRow['COMID'].'&page=7" style="color:blue;" title="Click me" >Laytime</a><br/><br/>
                                        <a href="bunker_calculation.php?comid='.$aRow['COMID'].'&page=7" style="color:blue;" title="Click me" >Bunkers</a><br/><br/>
												<a href="soa_report.php?comid='.$aRow['COMID'].'&page=7" style="color:blue;" title="Click me" >SOA</a>';
		
		$paymentgrid = '<a href="payment_grid.php?comid='.$aRow['COMID'].'&page=7" >View</a><br><br><a href="piclubdeclaration.php?comid='.$aRow['COMID'].'&page=7" >P & I Club Declaration</a>';
		
		$aaData[] = array('col1'=>$aRow['BUSINESS_TYPE'], 'col2'=>$aRow['MESSAGE'], 'col3'=>$aRow['CARGONAME'], 'col4'=>$aRow['VESSEL_NAME'], 'col5'=>date('d-m-Y',strtotime($aRow['TRANS_DATE'])), 'col6'=>$aRow['VOYAGE_NO'], 'col7'=>$financila_link, 'col8'=>$fdalink, 'col9'=>$calculations, 'col10'=>$paymentgrid, 'col11'=>$aRow['CONTACT_PERSON'], 'col12'=>'History');
		
	}
	
	echo json_encode(array("draw"=>intval($_POST['draw']),"recordsTotal"=>$totalData,"recordsFiltered"=>$totalFiltered,"records" => $aaData));
}


function getDecignChartTCJsonList()
{
   //echo 1;die;
	$obj 			= new data();
	$connect		= $obj->funConnect();
	
	$aColumns = array("COMID", "MESSAGE", "MESSAGE_NO", "VOYAGE_NO", "VESSEL_NAME", "DEL_RANGE_PORT", "ADD_ON_DATE", "CONTACT_PERSON");
	
	$sIndexColumn = "COMID";
	
	$sTable = "chartering_estimate_tc_compare";
	
	if(!empty($_POST['order'][0]['column']))
	{
		$sOrder = "ORDER BY  ".$aColumns[intval($_POST['order'][0]['column'])]." ".$_POST['order'][0]['dir'];
	}
	else
	{
		$sOrder = "ORDER BY COMID";
	}
	
	$sWhere = "";
	
	if ($_POST['search']['value']!= "")
	{
		$sWhere = " FINAL_ID!='' and MODULEID='".$_SESSION['moduleid']."' AND MCOMPANYID='".$_SESSION['company']."' and (VESSEL_NAME LIKE '%".$_POST['search']['value']."%' or MESSAGE LIKE '%".$_POST['search']['value']."%' or MESSAGE_NO LIKE '%".$_POST['search']['value']."%' or TC_NO LIKE '%".$_POST['search']['value']."%' or CONTACT_PERSON LIKE '%".$_POST['search']['value']."%' or ADD_ON_DATE LIKE '%".$_POST['search']['value']."%' or DEL_RANGE_PORT LIKE '%".$_POST['search']['value']."%')";
	}else{$sWhere = " FINAL_ID!='' and MODULEID='".$_SESSION['moduleid']."' AND MCOMPANYID='".$_SESSION['company']."'";}
	
	$sQuery = "SELECT * FROM (select COMID, MESSAGE, MESSAGE_NO, USERID, ADD_ON_DATE, TCOUTID as TCOUTIDD, MCOMPANYID, MODULEID, (select CONTACT_PERSON from login where login.LOGINID=chartering_estimate_tc_compare.USERID) as CONTACT_PERSON, (select CONCAT(DEL_RANGE_PORT,' / ', RE_DEL_RANGE) as DEL_RANGE from chartering_estimate_tc_master where chartering_estimate_tc_master.TCOUTID=TCOUTIDD) as DEL_RANGE_PORT, FINAL_ID, (select TC_NO from chartering_estimate_tc_master where chartering_estimate_tc_master.TCOUTID=TCOUTIDD) as TC_NO, (select VESSEL_NAME from vessel_imo_master where vessel_imo_master.VESSEL_IMO_ID=(select VESSEL_IMO_ID from chartering_estimate_tc_master where chartering_estimate_tc_master.TCOUTID=TCOUTIDD)) as VESSEL_NAME from chartering_estimate_tc_compare) as innerTable where $sWhere $sOrder LIMIT ".$_POST['start'].", ".$_POST['length']."";
	
	$rResult = mysql_query($sQuery) or die($sQuery);
	
	$sQuery = "	SELECT COUNT(".$sIndexColumn.") FROM (select * from chartering_estimate_tc_compare) 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;
		
		$loadports = $obj->getLoadPortNameArrBasedOnIDComidAndProcessWithoutTBN($aRow['COMID']);
		$disports = $obj->getDisPortNameArrBasedOnIDComidAndProcessWithoutTBN($aRow['COMID']);
		
		$details = '<a href="#" title="View Details" data-toggle="modal" data-target="#compose-modal" onclick="getListToCompare('.explode('-',$aRow['MESSAGE'])[0].','.$aRow['MESSAGE_NO'].');" ><i class="fa fa-file"></i></a>';
		
		$aaData[] = array('col1'=>$i.'.', 'col2'=>$aRow['MESSAGE'], 'col3'=>$aRow['MESSAGE_NO'], 'col4'=>$aRow['TC_NO'], 'col5'=>$aRow['VESSEL_NAME'], 'col6'=>$aRow['DEL_RANGE_PORT'], 'col7'=>date('d-m-Y',strtotime($aRow['ADD_ON_DATE'])), 'col8'=>$aRow['CONTACT_PERSON'], 'col9'=>$details);
		
	}
	
	echo json_encode(array("draw"=>intval($_POST['draw']),"recordsTotal"=>$totalData,"recordsFiltered"=>$totalFiltered,"records" => $aaData));
}


function getDecignChartJsonList()
{
   //echo 1;die;
	$obj 			= new data();
	$connect		= $obj->funConnect();
	$_SESSION['selBType'] = $_POST['selBType'];
	
	$aColumns = array("COMID", "MESSAGE", "MESSAGE_NO", "VOYAGE_NO", "VESSEL_NAME", "ADD_ON_DATE", "CONTACT_PERSON");
	
	$sIndexColumn = "COMID";
	
	$sTable = "freight_cost_estimate_compare";
	
	if(!empty($_POST['order'][0]['column']))
	{
		$sOrder = "ORDER BY  ".$aColumns[intval($_POST['order'][0]['column'])]." ".$_POST['order'][0]['dir'];
	}
	else
	{
		$sOrder = "ORDER BY COMID";
	}
	
	$sWhere = "";
	
	if ($_POST['search']['value']!= "")
	{
		$sWhere = " FINAL_ID!='' and (select ESTIMATE_TYPE from freight_cost_estimete_master where freight_cost_estimete_master.FCAID=FCAIDD)='".$_SESSION['selBType']."' and MODULEID='".$_SESSION['moduleid']."' AND MCOMPANYID='".$_SESSION['company']."' and (VESSEL_NAME LIKE '%".$_POST['search']['value']."%' or MESSAGE LIKE '%".$_POST['search']['value']."%' or MESSAGE_NO LIKE '%".$_POST['search']['value']."%' or VOYAGE_NO LIKE '%".$_POST['search']['value']."%' or CONTACT_PERSON LIKE '%".$_POST['search']['value']."%' or ADD_ON_DATE LIKE '%".$_POST['search']['value']."%')";
	}else{$sWhere = " FINAL_ID!='' and (select ESTIMATE_TYPE from freight_cost_estimete_master where freight_cost_estimete_master.FCAID=FCAIDD)='".$_SESSION['selBType']."' and MODULEID='".$_SESSION['moduleid']."' AND MCOMPANYID='".$_SESSION['company']."'";}
	
	$sQuery = "SELECT * FROM (select COMID, MESSAGE, MESSAGE_NO, USERID, ADD_ON_DATE, FCAID as FCAIDD, MCOMPANYID, MODULEID, (select CONTACT_PERSON from login where login.LOGINID=freight_cost_estimate_compare.USERID) as CONTACT_PERSON, FINAL_ID, (select VOYAGE_NO from freight_cost_estimete_master where freight_cost_estimete_master.FCAID=FCAIDD) as VOYAGE_NO, (select VESSEL_NAME from vessel_imo_master where vessel_imo_master.VESSEL_IMO_ID=(select VESSEL_IMO_ID from freight_cost_estimete_master where freight_cost_estimete_master.FCAID=FCAIDD)) as VESSEL_NAME from freight_cost_estimate_compare) as innerTable where $sWhere $sOrder LIMIT ".$_POST['start'].", ".$_POST['length']."";
	
	$rResult = mysql_query($sQuery) or die($sQuery);
	
	$sQuery = "	SELECT COUNT(".$sIndexColumn.") FROM (select * from freight_cost_estimate_compare) 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;
		
		$loadports = $obj->getLoadPortNameArrBasedOnIDComidAndProcessWithoutTBN($aRow['COMID']);
		$disports = $obj->getDisPortNameArrBasedOnIDComidAndProcessWithoutTBN($aRow['COMID']);
		
		$details = '<a href="#" title="View Details" data-toggle="modal" data-target="#compose-modal" onclick="getListToCompare('.explode('-',$aRow['MESSAGE'])[0].','.$aRow['MESSAGE_NO'].');" ><i class="fa fa-file"></i></a>';
		
		$aaData[] = array('col1'=>$i.'.', 'col2'=>$aRow['MESSAGE'], 'col3'=>$aRow['MESSAGE_NO'], 'col4'=>$aRow['VOYAGE_NO'], 'col5'=>$aRow['VESSEL_NAME'], 'col6'=>date('d-m-Y',strtotime($aRow['ADD_ON_DATE'])), 'col7'=>$aRow['CONTACT_PERSON'], 'col8'=>implode(',',$loadports).' / '.implode(',',$disports), 'col9'=>$details);
		
	}
	
	echo json_encode(array("draw"=>intval($_POST['draw']),"recordsTotal"=>$totalData,"recordsFiltered"=>$totalFiltered,"records" => $aaData));
}

function getComparisionSheetsReport1()
{
	$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."' order by FCAID ASC";
	$result = mysql_query($sql);
	$num = mysql_num_rows($result);
	$width = 70/$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 '<th align="center" valign="middle" width="10%"></th>';
	echo '</tr>';
	
	
	echo '<tr>';
	echo '<td align="left" colspan="'.(2+$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 '<th align="center" valign="middle" width="10%">Diff.</th>';
	echo '</tr>';
	
	
	
	$array_revenue = array();
	echo '<tr>';
	echo '<td align="left" colspan="'.(2+$num).'"><span style="font-size:16px;"><strong>Revenue</strong></span></td>';
	echo '</tr>';
	
	$line = 0;
	$line=1;
	echo '<tr id="trRow_'.$line.'">';
	echo '<td align="center" valign="middle" width="10%">Demurrage<input type="hidden" id="txtIdentity_'.$line.'" name="txtIdentity_'.$line.'" value="Demurrage"/></td>';
	$result = mysql_query($sql);$initialamt = $finalamt = $difference = 0;
	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);
		$finalamt = array_sum($arr_sum);
		$difference = $finalamt - $initialamt;
		$initialamt = array_sum($arr_sum);
		echo '<td align="center" valign="middle" width="'.$width.'%">'.array_sum($arr_sum).'</td>';
	}
	
	echo '<td align="center" valign="middle""><input type="text" class="form-control" readonly="true" name="txtDifference_'.$line.'" id="txtDifference_'.$line.'" value="'.number_format($difference,2,'.','').'"></td>';
	echo '</tr>';
	
	$line = 2;
	echo '<tr id="trRow_'.$line.'">';
	echo '<td align="center" valign="middle" width="10%">Dispatch <input type="hidden" id="txtIdentity_'.$line.'" name="txtIdentity_'.$line.'" value="Dispatch"/></td>';
	$result = mysql_query($sql);$initialamt = $finalamt = $difference = 0;
	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);
		
		$finalamt = array_sum($arr_sum);
		$difference = $finalamt - $initialamt;
		$initialamt = array_sum($arr_sum);
		echo '<td align="center" valign="middle" width="'.$width.'%">'.array_sum($arr_sum).'</td>';
	}
	echo '<td align="center" valign="middle""><input type="text" class="form-control" readonly="true" name="txtDifference_'.$line.'" id="txtDifference_'.$line.'" value="'.number_format($difference,2,'.','').'"></td>';

	echo '</tr>';
	
	$line = 3;
	echo '<tr id="trRow_'.$line.'">';
	echo '<td align="center" valign="middle" width="10%">Final Nett Freight <input type="hidden" id="txtIdentity_'.$line.'" name="txtIdentity_'.$line.'" value="Final Nett Freight"/></td>';
	$result = mysql_query($sql);$initialamt = $finalamt = $difference = 0;
	while($rows= mysql_fetch_assoc($result))
	{
		$array_revenue[$rows['FCAID']][] = $rows['REVENUES_FREIGHT'];
		$finalamt = array_sum($arr_sum);
		$difference = $finalamt - $initialamt;
		$initialamt = array_sum($arr_sum);

		echo '<td align="center" valign="middle" width="'.$width.'%">'.$rows['REVENUES_FREIGHT'].'</td>';
	}
	echo '<td align="center" valign="middle""><input type="text" class="form-control" readonly="true" name="txtDifference_'.$line.'" id="txtDifference_'.$line.'" value="'.number_format($difference,2,'.','').'"></td>';
	echo '</tr>';
	
	$line = 4;
	echo '<tr id="trRow_'.$line.'">';
	echo '<td align="center" valign="middle" width="10%"><strong>Total Revenue</strong> <input type="hidden" id="txtIdentity_'.$line.'" name="txtIdentity_'.$line.'" value="Total Revenue"/></td>';
	$result = mysql_query($sql);$initialamt = $finalamt = $difference = 0;
	while($rows= mysql_fetch_assoc($result))
	{
	    $finalamt = array_sum($array_revenue[$rows['FCAID']]);
		$difference = $finalamt - $initialamt;
		$initialamt = array_sum($array_revenue[$rows['FCAID']]);
		echo '<td align="center" valign="middle" width="'.$width.'%"><strong>'.array_sum($array_revenue[$rows['FCAID']]).'</strong></td>';
	}
	echo '<td align="center" valign="middle""><input type="text" class="form-control" readonly="true" name="txtDifference_'.$line.'" id="txtDifference_'.$line.'" value="'.number_format($difference,2,'.','').'"></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>';
	
	$line = 5;
	echo '<tr id="trRow_'.$line.'">';
	echo '<td align="center" valign="middle" width="10%">Loading Port <input type="hidden" id="txtIdentity_'.$line.'" name="txtIdentity_'.$line.'" value="Loading Port"/></td>';
	$result = mysql_query($sql);$initialamt = $finalamt = $difference = 0;
	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'];
		$finalamt = $rows1['sum'];
		$difference = $finalamt - $initialamt;
		$initialamt = $rows1['sum'];
		echo '<td align="center" valign="middle" width="'.$width.'%">'.$rows1['sum'].'</td>';
	}
	echo '<td align="center" valign="middle""><input type="text" class="form-control" readonly="true" name="txtDifference_'.$line.'" id="txtDifference_'.$line.'" value="'.number_format($difference,2,'.','').'"></td>';
	echo '</tr>';
	
	$line = 6;
	echo '<tr id="trRow_'.$line.'">';
	echo '<td align="center" valign="middle" width="10%">Discharge Port<input type="hidden" id="txtIdentity_'.$line.'" name="txtIdentity_'.$line.'" value="Discharge Port"/></td>';
	$result = mysql_query($sql);$initialamt = $finalamt = $difference = 0;
	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'];
		$finalamt = $rows1['sum'];
		$difference = $finalamt - $initialamt;
		$initialamt = $rows1['sum'];
		echo '<td align="center" valign="middle" width="'.$width.'%">'.$rows1['sum'].'</td>';
	}
	echo '<td align="center" valign="middle""><input type="text" class="form-control" readonly="true" name="txtDifference_'.$line.'" id="txtDifference_'.$line.'" value="'.number_format($difference,2,'.','').'"></td>';
	echo '</tr>';
	
	$line = 7;
	echo '<tr id="trRow_'.$line.'">';
	echo '<td align="center" valign="middle" width="10%">Bunker Port<input type="hidden" id="txtIdentity_'.$line.'" name="txtIdentity_'.$line.'" value="Bunker Port"/></td>';
	$result = mysql_query($sql);$initialamt = $finalamt = $difference = 0;
	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'];
		$finalamt = $rows1['sum'];
		$difference = $finalamt - $initialamt;
		$initialamt = $rows1['sum'];
		echo '<td align="center" valign="middle" width="'.$width.'%">'.$rows1['sum'].'</td>';
	}
	echo '<td align="center" valign="middle""><input type="text" class="form-control" readonly="true" name="txtDifference_'.$line.'" id="txtDifference_'.$line.'" value="'.number_format($difference,2,'.','').'"></td>';
	echo '</tr>';
	
	$line = 8;
	$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);
	$i = 0;
    while($rowsop = mysql_fetch_assoc($resop))
    {$i++;
		echo '<tr id="trRow_'.$line.'_'.$i.'">';
		echo '<td align="center" valign="middle" width="10%">'.$rowsop['NAME'].'<input type="hidden" name="txtIdentity_'.$line.'_'.$i.'" id="txtIdentity_'.$line.'_'.$i.'" value="'.$rowsop['NAME'].'"/></td>';
		$result = mysql_query($sql);$initialamt = $finalamt = $difference = 0;
		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'];
			
			$finalamt = $rows1['sum'];
			$difference = $finalamt - $initialamt;
			$initialamt = $rows1['sum'];
			echo '<td align="center" valign="middle" width="'.$width.'%">'.$rows1['sum'].'</td>';
		}
		echo '<td align="center" valign="middle""><input type="text" class="form-control" readonly="true" name="txtDifference_'.$line.'_'.$i.'" id="txtDifference_'.$line.'_'.$i.'" value="'.number_format($difference,2,'.','').'"></td>';
		echo '</tr>';
	}

    $line = 9;
	echo '<tr id="trRow_'.$line.'">';
	echo '<td align="center" valign="middle" width="10%">CVE <input type="hidden" id="txtIdentity_'.$line.'" name="txtIdentity_'.$line.'" value="CVE"/><input type="hidden" name="txtIdentity8ID" name="txtIdentity8ID" valye="'.$numop.'"/></td>';
	$result = mysql_query($sql);$initialamt = $finalamt = $difference = 0;
	while($rows= mysql_fetch_assoc($result))
	{
		$array_expense[$rows['FCAID']][] = $rows['CVE_AMT'];
		$finalamt = $rows['CVE_AMT'];
		$difference = $finalamt - $initialamt;
		$initialamt = $rows['CVE_AMT'];
		echo '<td align="center" valign="middle" width="'.$width.'%">'.$rows['CVE_AMT'].'</td>';
	}
	echo '<td align="center" valign="middle""><input type="text" class="form-control" readonly="true" name="txtDifference_'.$line.'" id="txtDifference_'.$line.'" value="'.number_format($difference,2,'.','').'"></td>';
	echo '</tr>';
	
	$line = 10;	
	echo '<tr id="trRow_'.$line.'">';
	echo '<td align="center" valign="middle" width="10%">Address Commission <input type="hidden" id="txtIdentity_'.$line.'" name="txtIdentity_'.$line.'" value="Address Commission"/></td>';
	$result = mysql_query($sql);$initialamt = $finalamt = $difference = 0;
	while($rows= mysql_fetch_assoc($result))
	{
		$array_expense[$rows['FCAID']][] = $rows['ADDRESS_COMMISSION_AMT'];
		$finalamt = $rows['ADDRESS_COMMISSION_AMT'];
		$difference = $finalamt - $initialamt;
		$initialamt = $rows['ADDRESS_COMMISSION_AMT'];
		echo '<td align="center" valign="middle" width="'.$width.'%">'.$rows['ADDRESS_COMMISSION_AMT'].'</td>';
	}
	echo '<td align="center" valign="middle""><input type="text" class="form-control" readonly="true" name="txtDifference_'.$line.'" id="txtDifference_'.$line.'" value="'.number_format($difference,2,'.','').'"></td>';
	echo '</tr>';
	
	$line = 11;
	echo '<tr id="trRow_'.$line.'">';
	echo '<td align="center" valign="middle" width="10%">Brokerage Commission <input type="hidden" id="txtIdentity_'.$line.'" name="txtIdentity_'.$line.'" value="Brokerage Commission"/></td>';
	$result = mysql_query($sql);$initialamt = $finalamt = $difference = 0;
	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'];
		$finalamt = $rows1['sum'];
		$difference = $finalamt - $initialamt;
		$initialamt = $rows1['sum'];
		echo '<td align="center" valign="middle" width="'.$width.'%">'.$rows1['sum'].'</td>';
	}
	echo '<td align="center" valign="middle""><input type="text" class="form-control" readonly="true" name="txtDifference_'.$line.'" id="txtDifference_'.$line.'" value="'.number_format($difference,2,'.','').'"></td>';
	echo '</tr>';
	
	$line = 12;
	echo '<tr id="trRow_'.$line.'">';
	echo '<td align="center" valign="middle" width="10%"><strong>Total Expense-Cargo</strong> <input type="hidden" id="txtIdentity_'.$line.'" name="txtIdentity_'.$line.'" value="Total Expense-Cargo"/></td>';
	$result = mysql_query($sql);$initialamt = $finalamt = $difference = 0;
	while($rows= mysql_fetch_assoc($result))
	{
	    $finalamt = array_sum($array_expense[$rows['FCAID']]);
		$difference = $finalamt - $initialamt;
		$initialamt = array_sum($array_expense[$rows['FCAID']]);
		echo '<td align="center" valign="middle" width="'.$width.'%"><strong>'.array_sum($array_expense[$rows['FCAID']]).'</strong></td>';
	}
	echo '<td align="center" valign="middle""><input type="text" class="form-control" readonly="true" name="txtDifference_'.$line.'" id="txtDifference_'.$line.'" value="'.number_format($difference,2,'.','').'"></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>';
	
	$line = 14;
	echo '<tr id="trRow_'.$line.'">';
	echo '<td align="center" valign="middle" width="10%">Laden Dist <input type="hidden" id="txtIdentity_'.$line.'" name="txtIdentity_'.$line.'" value="Laden Dist"/></td>';
	$result = mysql_query($sql);$initialamt = $finalamt = $difference = 0;
	while($rows= mysql_fetch_assoc($result))
	{
	    $finalamt = $rows['LADEN_DIST'];
		$difference = $finalamt - $initialamt;
		$initialamt = $rows['LADEN_DIST'];
		echo '<td align="center" valign="middle" width="'.$width.'%">'.$rows['LADEN_DIST'].'</td>';
	}
	echo '<td align="center" valign="middle""><input type="text" class="form-control" readonly="true" name="txtDifference_'.$line.'" id="txtDifference_'.$line.'" value="'.number_format($difference,2,'.','').'"></td>';
	echo '</tr>';
	
	$line = 15;
	echo '<tr id="trRow_'.$line.'">';
	echo '<td align="center" valign="middle" width="10%">Ballast Dist <input type="hidden" id="txtIdentity_'.$line.'" name="txtIdentity_'.$line.'" value="Ballast Dist"/></td>';
	$result = mysql_query($sql);$initialamt = $finalamt = $difference = 0;
	while($rows= mysql_fetch_assoc($result))
	{
	    $finalamt = $rows['BALLAST_DIST'];
		$difference = $finalamt - $initialamt;
		$initialamt = $rows['BALLAST_DIST'];
		echo '<td align="center" valign="middle" width="'.$width.'%">'.$rows['BALLAST_DIST'].'</td>';
	}
	echo '<td align="center" valign="middle""><input type="text" class="form-control" readonly="true" name="txtDifference_'.$line.'" id="txtDifference_'.$line.'" value="'.number_format($difference,2,'.','').'"></td>';
	echo '</tr>';
	
	$line = 16;
	echo '<tr id="trRow_'.$line.'">';
	echo '<td align="center" valign="middle" width="10%">Total Dist <input type="hidden" id="txtIdentity_'.$line.'" name="txtIdentity_'.$line.'" value="Total Dist"/></td>';
	$result = mysql_query($sql);$initialamt = $finalamt = $difference = 0;
	while($rows= mysql_fetch_assoc($result))
	{
	    $finalamt = $rows['TOTAL_DISTANCE'];
		$difference = $finalamt - $initialamt;
		$initialamt = $rows['TOTAL_DISTANCE'];
		echo '<td align="center" valign="middle" width="'.$width.'%">'.$rows['TOTAL_DISTANCE'].'</td>';
	}
	echo '<td align="center" valign="middle""><input type="text" class="form-control" readonly="true" name="txtDifference_'.$line.'" id="txtDifference_'.$line.'" value="'.number_format($difference,2,'.','').'"></td>';
	echo '</tr>';
	
	$line = 17;
	echo '<tr id="trRow_'.$line.'">';
	echo '<td align="center" valign="middle" width="10%">Laden Days <input type="hidden" id="txtIdentity_'.$line.'" name="txtIdentity_'.$line.'" value="Laden Days"/></td>';
	$result = mysql_query($sql);$initialamt = $finalamt = $difference = 0;
	while($rows= mysql_fetch_assoc($result))
	{
	    $finalamt = $rows['LADEN_DAYS'];
		$difference = $finalamt - $initialamt;
		$initialamt = $rows['LADEN_DAYS'];
		echo '<td align="center" valign="middle" width="'.$width.'%">'.$rows['LADEN_DAYS'].'</td>';
	}
	echo '<td align="center" valign="middle""><input type="text" class="form-control" readonly="true" name="txtDifference_'.$line.'" id="txtDifference_'.$line.'" value="'.number_format($difference,2,'.','').'"></td>';
	echo '</tr>';
	
	$line = 18;
	echo '<tr id="trRow_'.$line.'">';
	echo '<td align="center" valign="middle" width="10%">Ballast Days <input type="hidden" id="txtIdentity_'.$line.'" name="txtIdentity_'.$line.'" value="Ballast Days"/></td>';
	$result = mysql_query($sql);$initialamt = $finalamt = $difference = 0;
	while($rows= mysql_fetch_assoc($result))
	{
	    $finalamt = $rows['BALLAST_DAYS'];
		$difference = $finalamt - $initialamt;
		$initialamt = $rows['BALLAST_DAYS'];
		echo '<td align="center" valign="middle" width="'.$width.'%">'.$rows['BALLAST_DAYS'].'</td>';
	}
	echo '<td align="center" valign="middle""><input type="text" class="form-control" readonly="true" name="txtDifference_'.$line.'" id="txtDifference_'.$line.'" value="'.number_format($difference,2,'.','').'"></td>';
	echo '</tr>';
	
	$line = 19;
	echo '<tr id="trRow_'.$line.'">';
	echo '<td align="center" valign="middle" width="10%">Total Sea Days <input type="hidden" id="txtIdentity_'.$line.'" name="txtIdentity_'.$line.'" value="Total Sea Days"/></td>';
	$result = mysql_query($sql);$initialamt = $finalamt = $difference = 0;
	while($rows= mysql_fetch_assoc($result))
	{
	    $finalamt = $rows['TOTAL_PASSAGE_DAYS'];
		$difference = $finalamt - $initialamt;
		$initialamt = $rows['TOTAL_PASSAGE_DAYS'];
		echo '<td align="center" valign="middle" width="'.$width.'%">'.$rows['TOTAL_PASSAGE_DAYS'].'</td>';
	}
	echo '<td align="center" valign="middle""><input type="text" class="form-control" readonly="true" name="txtDifference_'.$line.'" id="txtDifference_'.$line.'" value="'.number_format($difference,2,'.','').'"></td>';
	echo '</tr>';
	
	$line = 20;
	echo '<tr id="trRow_'.$line.'">';
	echo '<td align="center" valign="middle" width="10%">Ttl Port Idle Days <input type="hidden" id="txtIdentity_'.$line.'" name="txtIdentity_'.$line.'" value="Ttl Port Idle Days"/></td>';
	$result = mysql_query($sql);$initialamt = $finalamt = $difference = 0;
	while($rows= mysql_fetch_assoc($result))
	{
	    $finalamt = $rows['IDEAL_DAYS'];
		$difference = $finalamt - $initialamt;
		$initialamt = $rows['IDEAL_DAYS'];
		echo '<td align="center" valign="middle" width="'.$width.'%">'.$rows['IDEAL_DAYS'].'</td>';
	}
	echo '<td align="center" valign="middle""><input type="text" class="form-control" readonly="true" name="txtDifference_'.$line.'" id="txtDifference_'.$line.'" value="'.number_format($difference,2,'.','').'"></td>';
	echo '</tr>';
	
	$line = 21;
	echo '<tr id="trRow_'.$line.'">';
	echo '<td align="center" valign="middle" width="10%">Ttl Port Work Days <input type="hidden" id="txtIdentity_'.$line.'" name="txtIdentity_'.$line.'" value="Loading Port"/></td>';
	$result = mysql_query($sql);$initialamt = $finalamt = $difference = 0;
	while($rows= mysql_fetch_assoc($result))
	{
	    $finalamt = $rows['WORKING_DAYS'];
		$difference = $finalamt - $initialamt;
		$initialamt = $rows['WORKING_DAYS'];
		echo '<td align="center" valign="middle" width="'.$width.'%">'.$rows['WORKING_DAYS'].'</td>';
	}
	echo '<td align="center" valign="middle""><input type="text" class="form-control" readonly="true" name="txtDifference_'.$line.'" id="txtDifference_'.$line.'" value="'.number_format($difference,2,'.','').'"></td>';
	echo '</tr>';
	
	$line = 22;
	echo '<tr id="trRow_'.$line.'">';
	echo '<td align="center" valign="middle" width="10%">Total Days <input type="hidden" id="txtIdentity_'.$line.'" name="txtIdentity_'.$line.'" value="Total Days"/></td>';
	$result = mysql_query($sql);$initialamt = $finalamt = $difference = 0;
	while($rows= mysql_fetch_assoc($result))
	{
	    $finalamt = $rows['TOTAL_DAYS'];
		$difference = $finalamt - $initialamt;
		$initialamt = $rows['TOTAL_DAYS'];
		echo '<td align="center" valign="middle" width="'.$width.'%">'.$rows['TOTAL_DAYS'].'</td>';
	}
	echo '<td align="center" valign="middle""><input type="text" class="form-control" readonly="true" name="txtDifference_'.$line.'" id="txtDifference_'.$line.'" value="'.number_format($difference,2,'.','').'"></td>';
	echo '</tr>';
	
	$line = 23;
	echo '<tr id="trRow_'.$line.'">';
	echo '<td align="center" valign="middle" width="10%">Ttl FO Consp MT <input type="hidden" id="txtIdentity_'.$line.'" name="txtIdentity_'.$line.'" value="Ttl FO Consp MT"/></td>';
	$result = mysql_query($sql);$initialamt = $finalamt = $difference = 0;
	while($rows= mysql_fetch_assoc($result))
	{
	    $finalamt = $rows['FO_CONSP'];
		$difference = $finalamt - $initialamt;
		$initialamt = $rows['FO_CONSP'];
		echo '<td align="center" valign="middle" width="'.$width.'%">'.$rows['FO_CONSP'].'</td>';
	}
	echo '<td align="center" valign="middle""><input type="text" class="form-control" readonly="true" name="txtDifference_'.$line.'" id="txtDifference_'.$line.'" value="'.number_format($difference,2,'.','').'"></td>';
	echo '</tr>';
	
	
	$line = 24;
	echo '<tr id="trRow_'.$line.'">';
	echo '<td align="center" valign="middle" width="10%">Ttl DO Consp MT <input type="hidden" id="txtIdentity_'.$line.'" name="txtIdentity_'.$line.'" value="Ttl DO Consp MT"/></td>';
	$result = mysql_query($sql);$initialamt = $finalamt = $difference = 0;
	while($rows= mysql_fetch_assoc($result))
	{
	    $finalamt = $rows['DO_CONSP'];
		$difference = $finalamt - $initialamt;
		$initialamt = $rows['DO_CONSP'];
		echo '<td align="center" valign="middle" width="'.$width.'%">'.$rows['DO_CONSP'].'</td>';
	}
	echo '<td align="center" valign="middle""><input type="text" class="form-control" readonly="true" name="txtDifference_'.$line.'" id="txtDifference_'.$line.'" value="'.number_format($difference,2,'.','').'"></td>';
	echo '</tr>';
	
	
	$line = 25;
	$bunker_expense = array();
	echo '<tr id="trRow_'.$line.'">';
	echo '<td align="left" valign="middle" colspan="'.(2+$num).'"><span style="font-size:16px;"><strong>Bunker Expenses</strong></span> (Qty / Price / Amount) <input type="hidden" id="txtIdentity_'.$line.'" name="txtIdentity_'.$line.'" value="Bunker Expenses"/></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 '<td align="center" valign="middle" width="10%" style="overflow:auto;"></td>';
		echo '</tr>';
	}
	
	$line = 26;
	echo '<tr id="trRow_'.$line.'">';
	echo '<td align="center" valign="middle" width="10%"><strong>Total Bunker Expense</strong> <input type="hidden" id="txtIdentity_'.$line.'" name="txtIdentity_'.$line.'" value="Total Bunker Expense"/></td>';
	$result = mysql_query($sql);$initialamt = $finalamt = $difference = 0;
	while($rows= mysql_fetch_assoc($result))
	{
	    $finalamt = array_sum($bunker_expense[$rows['FCAID']]);
		$difference = $finalamt - $initialamt;
		$initialamt = array_sum($bunker_expense[$rows['FCAID']]);
		echo '<td align="center" valign="middle" width="'.$width.'%"><strong>'.array_sum($bunker_expense[$rows['FCAID']]).'</strong></td>';
	}
	echo '<td align="center" valign="middle""><input type="text" class="form-control" readonly="true" name="txtDifference_'.$line.'" id="txtDifference_'.$line.'" value="'.number_format($difference,2,'.','').'"></td>';
	echo '</tr>';
	
	
    $line = 27;
	echo '<tr id="trRow_'.$line.'">';
	echo '<td align="center" valign="middle" width="10%"><span style="font-size:16px;"><strong>Navigation Expenses</strong></span> <input type="hidden" id="txtIdentity_'.$line.'" name="txtIdentity_'.$line.'" value="Navigation Expenses"/></td>';
	$result = mysql_query($sql);$initialamt = $finalamt = $difference = 0;
	while($rows= mysql_fetch_assoc($result))
	{
	    $finalamt = (array_sum($array_expense[$rows['FCAID']]) + array_sum($bunker_expense[$rows['FCAID']]));
		$difference = $finalamt - $initialamt;
		$initialamt = (array_sum($array_expense[$rows['FCAID']]) + array_sum($bunker_expense[$rows['FCAID']]));
		echo '<td align="center" valign="middle" width="'.$width.'%"><strong>'.(array_sum($array_expense[$rows['FCAID']]) + array_sum($bunker_expense[$rows['FCAID']])).'</strong></td>';
	}
	echo '<td align="center" valign="middle""><input type="text" class="form-control" readonly="true" name="txtDifference_'.$line.'" id="txtDifference_'.$line.'" value="'.number_format($difference,2,'.','').'"></td>';
	echo '</tr>';
	
	
	
	$line = 28;
	echo '<tr id="trRow_'.$line.'">';
	echo '<td align="center" valign="middle" width="10%">Hireage <input type="hidden" id="txtIdentity_'.$line.'" name="txtIdentity_'.$line.'" value="Hireage"/></td>';
	$result = mysql_query($sql);$initialamt = $finalamt = $difference = 0;
	while($rows= mysql_fetch_assoc($result))
	{
		$hirage = $rows['DAILY_VESSEL_OPERATION_EXP']*$rows['TOTAL_DAYS'];
		$sqlinvoice = "select SUM(HIRE_AMT) as SUM from freight_cost_estimete_slave17 WHERE FCAID='".$rows['FCAID']."'";
		$resinvoice = mysql_query($sqlinvoice);
		$numinvoice = mysql_num_rows($resinvoice);
		$rowsinvoice = mysql_fetch_assoc($resinvoice);
		if($numinvoice > 0)
		{
		    $hirage = $rowsinvoice['SUM'];
		}
		else
		{
			$hirage = $rows['DAILY_VESSEL_OPERATION_EXP']*$rows['TOTAL_DAYS'];
		}
		
		$finalamt = $hirage;
		$difference = $finalamt - $initialamt;
		$initialamt = $hirage;
		
		echo '<td align="center" valign="middle" width="'.$width.'%"><strong>'.$hirage.'</strong></td>';
	}
	echo '<td align="center" valign="middle""><input type="text" class="form-control" readonly="true" name="txtDifference_'.$line.'" id="txtDifference_'.$line.'" value="'.number_format($difference,2,'.','').'"></td>';
	echo '</tr>';
	
	$line = 30;
	echo '<tr id="trRow_'.$line.'">';
	echo '<td align="center" valign="middle" width="10%">Ballast Bonus <input type="hidden" id="txtIdentity_'.$line.'" name="txtIdentity_'.$line.'" value="Ballast Bonus"/></td>';
	$result = mysql_query($sql);$initialamt = $finalamt = $difference = 0;
	while($rows= mysql_fetch_assoc($result))
	{
	    $finalamt = array_sum($arr_sum);
		$difference = $finalamt - $initialamt;
		$initialamt = array_sum($arr_sum);
		echo '<td align="center" valign="middle" width="'.$width.'%"><strong>'.$rows['BALLAST_BONUS'].'</strong></td>';
	}
	echo '<td align="center" valign="middle""><input type="text" class="form-control" readonly="true" name="txtDifference_'.$line.'" id="txtDifference_'.$line.'" value="'.number_format($difference,2,'.','').'"></td>';
	echo '</tr>';
	
	$line = 31;
	echo '<tr id="trRow_'.$line.'">';
	echo '<td align="center" valign="middle" width="10%">Add Comm (%/Amt) <input type="hidden" id="txtIdentity_'.$line.'" name="txtIdentity_'.$line.'" value="Add Comm (%/Amt)"/></td>';
	$result = mysql_query($sql);$initialamt = $finalamt = $difference = 0;
	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'];}
		
		$finalamt = ($hirage*$rows['HIREAGE_PERCENT'])/100;
		$difference = $finalamt - $initialamt;
		$initialamt = ($hirage*$rows['HIREAGE_PERCENT'])/100;
		echo '<td align="center" valign="middle" width="'.$width.'%"><strong>'.$rows['HIREAGE_PERCENT'].' / '.(($hirage*$rows['HIREAGE_PERCENT'])/100).'</strong></td>';
	}
	echo '<td align="center" valign="middle""><input type="text" class="form-control" readonly="true" name="txtDifference_'.$line.'" id="txtDifference_'.$line.'" value="'.number_format($difference,2,'.','').'"></td>';
	echo '</tr>';
	
	$line = 32;
	echo '<tr id="trRow_'.$line.'">';
	echo '<td align="center" valign="middle" width="10%"><strong>Nett Hireage<strong> <input type="hidden" id="txtIdentity_'.$line.'" name="txtIdentity_'.$line.'" value="Nett Hireage"/></td>';
	$result = mysql_query($sql);$initialamt = $finalamt = $difference = 0;
	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'];}
		$finalamt = ($hirage - (($hirage*$rows['HIREAGE_PERCENT'])/100) + $rows['BALLAST_BONUS']);
		$difference = $finalamt - $initialamt;
		$initialamt = ($hirage - (($hirage*$rows['HIREAGE_PERCENT'])/100) + $rows['BALLAST_BONUS']);
		echo '<td align="center" valign="middle" width="'.$width.'%"><strong>'.($hirage - (($hirage*$rows['HIREAGE_PERCENT'])/100) + $rows['BALLAST_BONUS']).'</strong></td>';
	}
	echo '<td align="center" valign="middle""><input type="text" class="form-control" readonly="true" name="txtDifference_'.$line.'" id="txtDifference_'.$line.'" value="'.number_format($difference,2,'.','').'"></td>';
	echo '</tr>';
	
	$line = 33;
	echo '<tr id="trRow_'.$line.'">';
	echo '<td align="center" valign="middle" width="10%"><span style="font-size:16px;"><strong>Daily Earnings / TCE</strong></span> <input type="hidden" id="txtIdentity_'.$line.'" name="txtIdentity_'.$line.'" value="Daily Earnings / TCE"/></td>';
	$result = mysql_query($sql);$initialamt = $finalamt = $difference = 0;
	while($rows= mysql_fetch_assoc($result))
	{
	    $finalamt = $rows['DAILY_EARNING'];
		$difference = $finalamt - $initialamt;
		$initialamt = $rows['DAILY_EARNING'];
		echo '<td align="center" valign="middle" width="'.$width.'%">'.$rows['DAILY_EARNING'].'</td>';
	}
	echo '<td align="center" valign="middle""><input type="text" class="form-control" readonly="true" name="txtDifference_'.$line.'" id="txtDifference_'.$line.'" value="'.number_format($difference,2,'.','').'"></td>';
	echo '</tr>';
	
	$line = 34;
	echo '<tr id="trRow_'.$line.'">';
	echo '<td align="center" valign="middle" width="10%"><span style="font-size:16px;"><strong>Nett Daily Profit</strong></span> <input type="hidden" id="txtIdentity_'.$line.'" name="txtIdentity_'.$line.'" value="Nett Daily Profit"/></td>';
	$result = mysql_query($sql);$initialamt = $finalamt = $difference = 0;
	while($rows= mysql_fetch_assoc($result))
	{
	    $finalamt = $rows['NET_DAILY_PROFIT'];
		$difference = $finalamt - $initialamt;
		$initialamt = $rows['NET_DAILY_PROFIT'];
		echo '<td align="center" valign="middle" width="'.$width.'%">'.$rows['NET_DAILY_PROFIT'].'</td>';
	}
	echo '<td align="center" valign="middle""><input type="text" class="form-control" readonly="true" name="txtDifference_'.$line.'" id="txtDifference_'.$line.'" value="'.number_format($difference,2,'.','').'"></td>';
	echo '</tr>';
	
	$line = 35;
	echo '<tr id="trRow_'.$line.'">';
	echo '<td align="center" valign="middle" width="10%"><span style="font-size:16px;"><strong>P/L</strong></span> <input type="hidden" id="txtIdentity_'.$line.'" name="txtIdentity_'.$line.'" value="P/L"/><input type="hidden" name="txtRowCount" id="txtRowCount" value="35"/></td>';
	$result = mysql_query($sql);$initialamt = $finalamt = $difference = 0;
	while($rows= mysql_fetch_assoc($result))
	{
	    $finalamt = $rows['PROFIT_LOSS'];
		$difference = $finalamt - $initialamt;
		$initialamt = $rows['PROFIT_LOSS'];
		echo '<td align="center" valign="middle" width="'.$width.'%">'.$rows['PROFIT_LOSS'].'</td>';
	}
	echo '<td align="center" valign="middle""><input type="text" class="form-control" readonly="true" name="txtDifference_'.$line.'" id="txtDifference_'.$line.'" value="'.number_format($difference,2,'.','').'"></td>';
	echo '</tr>';
	echo '<tr>';
	echo '<td align="left" colspan="'.$num.'"><span style="font-size:16px;"><strong>P/L Difference</strong></span></td>';
	echo '<td align="center" valign="middle""><input type="text" class="form-control numeric" autocomplete="off" name="txtPLDifference" id="txtPLDifference" value="'.number_format($obj->getCompareEstimateData($comid,"PL_DIFF"),2,'.','').'" onKeyUp="calculete();"><input type="hidden" name="txtCalPL" id="txtCalPL" value="'.number_format($obj->getCompareEstimateData($comid,"PROFIT_LOSS"),2,'.','').'"></td>';
	echo '</tr>';
	echo '<tr>';
	echo '<td align="left" colspan="'.$num.'"><span style="font-size:16px;"><strong>Actual P/L (Calculated - Difference)</strong></span></td>';
	echo '<td align="center" valign="middle""><input type="text" class="form-control numeric" readonly="true" name="txtActualPL" id="txtActualPL" value="'.number_format($obj->getCompareEstimateData($comid,"ACTUAL_PL"),2,'.','').'"></td>';
	echo '</tr>';
	echo '</tbody>';
	echo '</table>';
	echo '</div>';
}

function getComparisionSheetsReport()
{
	$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."' order by FCAID ASC";
	$result = mysql_query($sql);
	$num = mysql_num_rows($result);
	$width = 65/$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 '<th align="center" valign="middle" width="10%"></th>';
	echo '<th align="center" valign="middle" width="15%"></th>';
	echo '</tr>';
	
	
	echo '<tr>';
	echo '<td align="left" colspan="'.(3+$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 '<th align="center" valign="middle" width="10%">Diff.</th>';
	echo '<th align="center" valign="middle" width="15%">Remarks</th>';
	echo '</tr>';
	
	
	
	$array_revenue = array();
	echo '<tr>';
	echo '<td align="left" colspan="'.(3+$num).'"><span style="font-size:16px;"><strong>Revenue</strong></span></td>';
	echo '</tr>';
	
	$line = 0;
	$line=1;
	echo '<tr id="trRow_'.$line.'">';
	echo '<td align="center" valign="middle" width="10%">Demurrage<input type="hidden" id="txtIdentity_'.$line.'" name="txtIdentity_'.$line.'" value="Demurrage"/></td>';
	$result = mysql_query($sql);$initialamt = $finalamt = $difference = 0;
	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);
		$finalamt = array_sum($arr_sum);
		$difference = $finalamt - $initialamt;
		$initialamt = array_sum($arr_sum);
		echo '<td align="center" valign="middle" width="'.$width.'%">'.array_sum($arr_sum).'</td>';
	}
	
	echo '<td align="center" valign="middle""><input type="text" class="form-control" readonly="true" name="txtDifference_'.$line.'" id="txtDifference_'.$line.'" value="'.number_format($difference,2,'.','').'"></td>';
	echo '<td align="center" valign="middle""><textarea class="form-control areasize" cols="30" rows="2" name="txtRemarks_'.$line.'" id="txtRemarks_'.$line.'" placeholder="Remarks...">'.$obj->getRemarksFromCompTable($comid, $line).'</textarea></td>';
	echo '</tr>';
	
	$line = 2;
	echo '<tr id="trRow_'.$line.'">';
	echo '<td align="center" valign="middle" width="10%">Dispatch <input type="hidden" id="txtIdentity_'.$line.'" name="txtIdentity_'.$line.'" value="Dispatch"/></td>';
	$result = mysql_query($sql);$initialamt = $finalamt = $difference = 0;
	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);
		
		$finalamt = array_sum($arr_sum);
		$difference = $finalamt - $initialamt;
		$initialamt = array_sum($arr_sum);
		echo '<td align="center" valign="middle" width="'.$width.'%">'.array_sum($arr_sum).'</td>';
	}
	echo '<td align="center" valign="middle""><input type="text" class="form-control" readonly="true" name="txtDifference_'.$line.'" id="txtDifference_'.$line.'" value="'.number_format($difference,2,'.','').'"></td>';
	echo '<td align="center" valign="middle""><textarea class="form-control areasize" cols="30" rows="2" name="txtRemarks_'.$line.'" id="txtRemarks_'.$line.'" placeholder="Remarks...">'.$obj->getRemarksFromCompTable($comid, $line).'</textarea></td>';
	echo '</tr>';
	
	$line = 3;
	echo '<tr id="trRow_'.$line.'">';
	echo '<td align="center" valign="middle" width="10%">Final Nett Freight <input type="hidden" id="txtIdentity_'.$line.'" name="txtIdentity_'.$line.'" value="Final Nett Freight"/></td>';
	$result = mysql_query($sql);$initialamt = $finalamt = $difference = 0;
	while($rows= mysql_fetch_assoc($result))
	{
		$array_revenue[$rows['FCAID']][] = $rows['REVENUES_FREIGHT'];
		$finalamt = array_sum($arr_sum);
		$difference = $finalamt - $initialamt;
		$initialamt = array_sum($arr_sum);
		echo '<td align="center" valign="middle" width="'.$width.'%">'.$rows['REVENUES_FREIGHT'].'</td>';
	}
	echo '<td align="center" valign="middle""><input type="text" class="form-control" readonly="true" name="txtDifference_'.$line.'" id="txtDifference_'.$line.'" value="'.number_format($difference,2,'.','').'"></td>';
	echo '<td align="center" valign="middle""><textarea class="form-control areasize" cols="30" rows="2" name="txtRemarks_'.$line.'" id="txtRemarks_'.$line.'" placeholder="Remarks...">'.$obj->getRemarksFromCompTable($comid, $line).'</textarea></td>';
	echo '</tr>';
	
	$line = 4;
	echo '<tr id="trRow_'.$line.'">';
	echo '<td align="center" valign="middle" width="10%"><strong>Total Revenue</strong> <input type="hidden" id="txtIdentity_'.$line.'" name="txtIdentity_'.$line.'" value="Total Revenue"/></td>';
	$result = mysql_query($sql);$initialamt = $finalamt = $difference = 0;
	while($rows= mysql_fetch_assoc($result))
	{
	    $finalamt = array_sum($array_revenue[$rows['FCAID']]);
		$difference = $finalamt - $initialamt;
		$initialamt = array_sum($array_revenue[$rows['FCAID']]);
		echo '<td align="center" valign="middle" width="'.$width.'%"><strong>'.array_sum($array_revenue[$rows['FCAID']]).'</strong></td>';
	}
	echo '<td align="center" valign="middle""><input type="text" class="form-control" readonly="true" name="txtDifference_'.$line.'" id="txtDifference_'.$line.'" value="'.number_format($difference,2,'.','').'"></td>';
	echo '<td align="center" valign="middle""><textarea class="form-control areasize" cols="30" rows="2" name="txtRemarks_'.$line.'" id="txtRemarks_'.$line.'" placeholder="Remarks...">'.$obj->getRemarksFromCompTable($comid, $line).'</textarea></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>';
	
	$line = 5;
	echo '<tr id="trRow_'.$line.'">';
	echo '<td align="center" valign="middle" width="10%">Loading Port <input type="hidden" id="txtIdentity_'.$line.'" name="txtIdentity_'.$line.'" value="Loading Port"/></td>';
	$result = mysql_query($sql);$initialamt = $finalamt = $difference = 0;
	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'];
		$finalamt = $rows1['sum'];
		$difference = $finalamt - $initialamt;
		$initialamt = $rows1['sum'];
		echo '<td align="center" valign="middle" width="'.$width.'%">'.$rows1['sum'].'</td>';
	}
	echo '<td align="center" valign="middle""><input type="text" class="form-control" readonly="true" name="txtDifference_'.$line.'" id="txtDifference_'.$line.'" value="'.number_format($difference,2,'.','').'"></td>';
	echo '<td align="center" valign="middle""><textarea class="form-control areasize" cols="30" rows="2" name="txtRemarks_'.$line.'" id="txtRemarks_'.$line.'" placeholder="Remarks...">'.$obj->getRemarksFromCompTable($comid, $line).'</textarea></td>';
	echo '</tr>';
	
	$line = 6;
	echo '<tr id="trRow_'.$line.'">';
	echo '<td align="center" valign="middle" width="10%">Discharge Port<input type="hidden" id="txtIdentity_'.$line.'" name="txtIdentity_'.$line.'" value="Discharge Port"/></td>';
	$result = mysql_query($sql);$initialamt = $finalamt = $difference = 0;
	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'];
		$finalamt = $rows1['sum'];
		$difference = $finalamt - $initialamt;
		$initialamt = $rows1['sum'];
		echo '<td align="center" valign="middle" width="'.$width.'%">'.$rows1['sum'].'</td>';
	}
	echo '<td align="center" valign="middle""><input type="text" class="form-control" readonly="true" name="txtDifference_'.$line.'" id="txtDifference_'.$line.'" value="'.number_format($difference,2,'.','').'"></td>';
	echo '<td align="center" valign="middle""><textarea class="form-control areasize" cols="30" rows="2" name="txtRemarks_'.$line.'" id="txtRemarks_'.$line.'" placeholder="Remarks...">'.$obj->getRemarksFromCompTable($comid, $line).'</textarea></td>';
	echo '</tr>';
	
	$line = 7;
	echo '<tr id="trRow_'.$line.'">';
	echo '<td align="center" valign="middle" width="10%">Bunker Port<input type="hidden" id="txtIdentity_'.$line.'" name="txtIdentity_'.$line.'" value="Bunker Port"/></td>';
	$result = mysql_query($sql);$initialamt = $finalamt = $difference = 0;
	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'];
		$finalamt = $rows1['sum'];
		$difference = $finalamt - $initialamt;
		$initialamt = $rows1['sum'];
		echo '<td align="center" valign="middle" width="'.$width.'%">'.$rows1['sum'].'</td>';
	}
	echo '<td align="center" valign="middle""><input type="text" class="form-control" readonly="true" name="txtDifference_'.$line.'" id="txtDifference_'.$line.'" value="'.number_format($difference,2,'.','').'"></td>';
	echo '<td align="center" valign="middle""><textarea class="form-control areasize" cols="30" rows="2" name="txtRemarks_'.$line.'" id="txtRemarks_'.$line.'" placeholder="Remarks...">'.$obj->getRemarksFromCompTable($comid, $line).'</textarea></td>';
	echo '</tr>';
	
	$line = 8;
	$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);
	$i = 0;
    while($rowsop = mysql_fetch_assoc($resop))
    {$i++;
		echo '<tr id="trRow_'.$line.'_'.$i.'">';
		echo '<td align="center" valign="middle" width="10%">'.$rowsop['NAME'].'<input type="hidden" name="txtIdentity_'.$line.'_'.$i.'" id="txtIdentity_'.$line.'_'.$i.'" value="'.$rowsop['NAME'].'"/></td>';
		$result = mysql_query($sql);$initialamt = $finalamt = $difference = 0;
		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'];
			
			$finalamt = $rows1['sum'];
			$difference = $finalamt - $initialamt;
			$initialamt = $rows1['sum'];
			echo '<td align="center" valign="middle" width="'.$width.'%">'.$rows1['sum'].'</td>';
		}
		echo '<td align="center" valign="middle""><input type="text" class="form-control" readonly="true" name="txtDifference_'.$line.'_'.$i.'" id="txtDifference_'.$line.'_'.$i.'" value="'.number_format($difference,2,'.','').'"></td>';
		echo '<td align="center" valign="middle""><textarea class="form-control areasize" cols="30" rows="2" name="txtRemarks_'.$line.'_'.$i.'" id="txtRemarks_'.$line.'_'.$i.'" placeholder="Remarks...">'.$obj->getRemarksFromCompTable($comid, $line).''.$obj->getRemarksFromCompTableSlave($comid, 8, $rowsop['NAME']).'</textarea></td>';
		echo '</tr>';
	}

    $line = 9;
	echo '<tr id="trRow_'.$line.'">';
	echo '<td align="center" valign="middle" width="10%">CVE <input type="hidden" id="txtIdentity_'.$line.'" name="txtIdentity_'.$line.'" value="CVE"/><input type="hidden" name="txtIdentity8ID" name="txtIdentity8ID" valye="'.$numop.'"/></td>';
	$result = mysql_query($sql);$initialamt = $finalamt = $difference = 0;
	while($rows= mysql_fetch_assoc($result))
	{
		$array_expense[$rows['FCAID']][] = $rows['CVE_AMT'];
		$finalamt = $rows['CVE_AMT'];
		$difference = $finalamt - $initialamt;
		$initialamt = $rows['CVE_AMT'];
		echo '<td align="center" valign="middle" width="'.$width.'%">'.$rows['CVE_AMT'].'</td>';
	}
	echo '<td align="center" valign="middle""><input type="text" class="form-control" readonly="true" name="txtDifference_'.$line.'" id="txtDifference_'.$line.'" value="'.number_format($difference,2,'.','').'"></td>';
	echo '<td align="center" valign="middle""><textarea class="form-control areasize" cols="30" rows="2" name="txtRemarks_'.$line.'" id="txtRemarks_'.$line.'" placeholder="Remarks...">'.$obj->getRemarksFromCompTable($comid, $line).'</textarea></td>';
	echo '</tr>';
	
	$line = 10;	
	echo '<tr id="trRow_'.$line.'">';
	echo '<td align="center" valign="middle" width="10%">Address Commission <input type="hidden" id="txtIdentity_'.$line.'" name="txtIdentity_'.$line.'" value="Address Commission"/></td>';
	$result = mysql_query($sql);$initialamt = $finalamt = $difference = 0;
	while($rows= mysql_fetch_assoc($result))
	{
		$array_expense[$rows['FCAID']][] = $rows['ADDRESS_COMMISSION_AMT'];
		$finalamt = $rows['ADDRESS_COMMISSION_AMT'];
		$difference = $finalamt - $initialamt;
		$initialamt = $rows['ADDRESS_COMMISSION_AMT'];
		echo '<td align="center" valign="middle" width="'.$width.'%">'.$rows['ADDRESS_COMMISSION_AMT'].'</td>';
	}
	echo '<td align="center" valign="middle""><input type="text" class="form-control" readonly="true" name="txtDifference_'.$line.'" id="txtDifference_'.$line.'" value="'.number_format($difference,2,'.','').'"></td>';
	echo '<td align="center" valign="middle""><textarea class="form-control areasize" cols="30" rows="2" name="txtRemarks_'.$line.'" id="txtRemarks_'.$line.'" placeholder="Remarks...">'.$obj->getRemarksFromCompTable($comid, $line).'</textarea></td>';
	echo '</tr>';
	
	$line = 11;
	echo '<tr id="trRow_'.$line.'">';
	echo '<td align="center" valign="middle" width="10%">Brokerage Commission <input type="hidden" id="txtIdentity_'.$line.'" name="txtIdentity_'.$line.'" value="Brokerage Commission"/></td>';
	$result = mysql_query($sql);$initialamt = $finalamt = $difference = 0;
	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'];
		$finalamt = $rows1['sum'];
		$difference = $finalamt - $initialamt;
		$initialamt = $rows1['sum'];
		echo '<td align="center" valign="middle" width="'.$width.'%">'.$rows1['sum'].'</td>';
	}
	echo '<td align="center" valign="middle""><input type="text" class="form-control" readonly="true" name="txtDifference_'.$line.'" id="txtDifference_'.$line.'" value="'.number_format($difference,2,'.','').'"></td>';
	echo '<td align="center" valign="middle""><textarea class="form-control areasize" cols="30" rows="2" name="txtRemarks_'.$line.'" id="txtRemarks_'.$line.'" placeholder="Remarks...">'.$obj->getRemarksFromCompTable($comid, $line).'</textarea></td>';
	echo '</tr>';
	
	$line = 12;
	echo '<tr id="trRow_'.$line.'">';
	echo '<td align="center" valign="middle" width="10%"><strong>Total Expense-Cargo</strong> <input type="hidden" id="txtIdentity_'.$line.'" name="txtIdentity_'.$line.'" value="Total Expense-Cargo"/></td>';
	$result = mysql_query($sql);$initialamt = $finalamt = $difference = 0;
	while($rows= mysql_fetch_assoc($result))
	{
	    $finalamt = array_sum($array_expense[$rows['FCAID']]);
		$difference = $finalamt - $initialamt;
		$initialamt = array_sum($array_expense[$rows['FCAID']]);
		echo '<td align="center" valign="middle" width="'.$width.'%"><strong>'.array_sum($array_expense[$rows['FCAID']]).'</strong></td>';
	}
	echo '<td align="center" valign="middle""><input type="text" class="form-control" readonly="true" name="txtDifference_'.$line.'" id="txtDifference_'.$line.'" value="'.number_format($difference,2,'.','').'"></td>';
	echo '<td align="center" valign="middle""><textarea class="form-control areasize" cols="30" rows="2" name="txtRemarks_'.$line.'" id="txtRemarks_'.$line.'" placeholder="Remarks...">'.$obj->getRemarksFromCompTable($comid, $line).'</textarea></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>';
	
	$line = 14;
	echo '<tr id="trRow_'.$line.'">';
	echo '<td align="center" valign="middle" width="10%">Laden Dist <input type="hidden" id="txtIdentity_'.$line.'" name="txtIdentity_'.$line.'" value="Laden Dist"/></td>';
	$result = mysql_query($sql);$initialamt = $finalamt = $difference = 0;
	while($rows= mysql_fetch_assoc($result))
	{
	    $finalamt = $rows['LADEN_DIST'];
		$difference = $finalamt - $initialamt;
		$initialamt = $rows['LADEN_DIST'];
		echo '<td align="center" valign="middle" width="'.$width.'%">'.$rows['LADEN_DIST'].'</td>';
	}
	echo '<td align="center" valign="middle""><input type="text" class="form-control" readonly="true" name="txtDifference_'.$line.'" id="txtDifference_'.$line.'" value="'.number_format($difference,2,'.','').'"></td>';
	echo '<td align="center" valign="middle""><textarea class="form-control areasize" cols="30" rows="2" name="txtRemarks_'.$line.'" id="txtRemarks_'.$line.'" placeholder="Remarks...">'.$obj->getRemarksFromCompTable($comid, $line).'</textarea></td>';
	echo '</tr>';
	
	$line = 15;
	echo '<tr id="trRow_'.$line.'">';
	echo '<td align="center" valign="middle" width="10%">Ballast Dist <input type="hidden" id="txtIdentity_'.$line.'" name="txtIdentity_'.$line.'" value="Ballast Dist"/></td>';
	$result = mysql_query($sql);$initialamt = $finalamt = $difference = 0;
	while($rows= mysql_fetch_assoc($result))
	{
	    $finalamt = $rows['BALLAST_DIST'];
		$difference = $finalamt - $initialamt;
		$initialamt = $rows['BALLAST_DIST'];
		echo '<td align="center" valign="middle" width="'.$width.'%">'.$rows['BALLAST_DIST'].'</td>';
	}
	echo '<td align="center" valign="middle""><input type="text" class="form-control" readonly="true" name="txtDifference_'.$line.'" id="txtDifference_'.$line.'" value="'.number_format($difference,2,'.','').'"></td>';
	echo '<td align="center" valign="middle""><textarea class="form-control areasize" cols="30" rows="2" name="txtRemarks_'.$line.'" id="txtRemarks_'.$line.'" placeholder="Remarks...">'.$obj->getRemarksFromCompTable($comid, $line).'</textarea></td>';
	echo '</tr>';
	
	$line = 16;
	echo '<tr id="trRow_'.$line.'">';
	echo '<td align="center" valign="middle" width="10%">Total Dist <input type="hidden" id="txtIdentity_'.$line.'" name="txtIdentity_'.$line.'" value="Total Dist"/></td>';
	$result = mysql_query($sql);$initialamt = $finalamt = $difference = 0;
	while($rows= mysql_fetch_assoc($result))
	{
	    $finalamt = $rows['TOTAL_DISTANCE'];
		$difference = $finalamt - $initialamt;
		$initialamt = $rows['TOTAL_DISTANCE'];
		echo '<td align="center" valign="middle" width="'.$width.'%">'.$rows['TOTAL_DISTANCE'].'</td>';
	}
	echo '<td align="center" valign="middle""><input type="text" class="form-control" readonly="true" name="txtDifference_'.$line.'" id="txtDifference_'.$line.'" value="'.number_format($difference,2,'.','').'"></td>';
	echo '<td align="center" valign="middle""><textarea class="form-control areasize" cols="30" rows="2" name="txtRemarks_'.$line.'" id="txtRemarks_'.$line.'" placeholder="Remarks...">'.$obj->getRemarksFromCompTable($comid, $line).'</textarea></td>';
	echo '</tr>';
	
	$line = 17;
	echo '<tr id="trRow_'.$line.'">';
	echo '<td align="center" valign="middle" width="10%">Laden Days <input type="hidden" id="txtIdentity_'.$line.'" name="txtIdentity_'.$line.'" value="Laden Days"/></td>';
	$result = mysql_query($sql);$initialamt = $finalamt = $difference = 0;
	while($rows= mysql_fetch_assoc($result))
	{
	    $finalamt = $rows['LADEN_DAYS'];
		$difference = $finalamt - $initialamt;
		$initialamt = $rows['LADEN_DAYS'];
		echo '<td align="center" valign="middle" width="'.$width.'%">'.$rows['LADEN_DAYS'].'</td>';
	}
	echo '<td align="center" valign="middle""><input type="text" class="form-control" readonly="true" name="txtDifference_'.$line.'" id="txtDifference_'.$line.'" value="'.number_format($difference,2,'.','').'"></td>';
	echo '<td align="center" valign="middle""><textarea class="form-control areasize" cols="30" rows="2" name="txtRemarks_'.$line.'" id="txtRemarks_'.$line.'" placeholder="Remarks...">'.$obj->getRemarksFromCompTable($comid, $line).'</textarea></td>';
	echo '</tr>';
	
	$line = 18;
	echo '<tr id="trRow_'.$line.'">';
	echo '<td align="center" valign="middle" width="10%">Ballast Days <input type="hidden" id="txtIdentity_'.$line.'" name="txtIdentity_'.$line.'" value="Ballast Days"/></td>';
	$result = mysql_query($sql);$initialamt = $finalamt = $difference = 0;
	while($rows= mysql_fetch_assoc($result))
	{
	    $finalamt = $rows['BALLAST_DAYS'];
		$difference = $finalamt - $initialamt;
		$initialamt = $rows['BALLAST_DAYS'];
		echo '<td align="center" valign="middle" width="'.$width.'%">'.$rows['BALLAST_DAYS'].'</td>';
	}
	echo '<td align="center" valign="middle""><input type="text" class="form-control" readonly="true" name="txtDifference_'.$line.'" id="txtDifference_'.$line.'" value="'.number_format($difference,2,'.','').'"></td>';
	echo '<td align="center" valign="middle""><textarea class="form-control areasize" cols="30" rows="2" name="txtRemarks_'.$line.'" id="txtRemarks_'.$line.'" placeholder="Remarks...">'.$obj->getRemarksFromCompTable($comid, $line).'</textarea></td>';
	echo '</tr>';
	
	$line = 19;
	echo '<tr id="trRow_'.$line.'">';
	echo '<td align="center" valign="middle" width="10%">Total Sea Days <input type="hidden" id="txtIdentity_'.$line.'" name="txtIdentity_'.$line.'" value="Total Sea Days"/></td>';
	$result = mysql_query($sql);$initialamt = $finalamt = $difference = 0;
	while($rows= mysql_fetch_assoc($result))
	{
	    $finalamt = $rows['TOTAL_PASSAGE_DAYS'];
		$difference = $finalamt - $initialamt;
		$initialamt = $rows['TOTAL_PASSAGE_DAYS'];
		echo '<td align="center" valign="middle" width="'.$width.'%">'.$rows['TOTAL_PASSAGE_DAYS'].'</td>';
	}
	echo '<td align="center" valign="middle""><input type="text" class="form-control" readonly="true" name="txtDifference_'.$line.'" id="txtDifference_'.$line.'" value="'.number_format($difference,2,'.','').'"></td>';
	echo '<td align="center" valign="middle""><textarea class="form-control areasize" cols="30" rows="2" name="txtRemarks_'.$line.'" id="txtRemarks_'.$line.'" placeholder="Remarks...">'.$obj->getRemarksFromCompTable($comid, $line).'</textarea></td>';
	echo '</tr>';
	
	$line = 20;
	echo '<tr id="trRow_'.$line.'">';
	echo '<td align="center" valign="middle" width="10%">Ttl Port Idle Days <input type="hidden" id="txtIdentity_'.$line.'" name="txtIdentity_'.$line.'" value="Ttl Port Idle Days"/></td>';
	$result = mysql_query($sql);$initialamt = $finalamt = $difference = 0;
	while($rows= mysql_fetch_assoc($result))
	{
	    $finalamt = $rows['IDEAL_DAYS'];
		$difference = $finalamt - $initialamt;
		$initialamt = $rows['IDEAL_DAYS'];
		echo '<td align="center" valign="middle" width="'.$width.'%">'.$rows['IDEAL_DAYS'].'</td>';
	}
	echo '<td align="center" valign="middle""><input type="text" class="form-control" readonly="true" name="txtDifference_'.$line.'" id="txtDifference_'.$line.'" value="'.number_format($difference,2,'.','').'"></td>';
	echo '<td align="center" valign="middle""><textarea class="form-control areasize" cols="30" rows="2" name="txtRemarks_'.$line.'" id="txtRemarks_'.$line.'" placeholder="Remarks...">'.$obj->getRemarksFromCompTable($comid, $line).'</textarea></td>';
	echo '</tr>';
	
	$line = 21;
	echo '<tr id="trRow_'.$line.'">';
	echo '<td align="center" valign="middle" width="10%">Ttl Port Work Days <input type="hidden" id="txtIdentity_'.$line.'" name="txtIdentity_'.$line.'" value="Loading Port"/></td>';
	$result = mysql_query($sql);$initialamt = $finalamt = $difference = 0;
	while($rows= mysql_fetch_assoc($result))
	{
	    $finalamt = $rows['WORKING_DAYS'];
		$difference = $finalamt - $initialamt;
		$initialamt = $rows['WORKING_DAYS'];
		echo '<td align="center" valign="middle" width="'.$width.'%">'.$rows['WORKING_DAYS'].'</td>';
	}
	echo '<td align="center" valign="middle""><input type="text" class="form-control" readonly="true" name="txtDifference_'.$line.'" id="txtDifference_'.$line.'" value="'.number_format($difference,2,'.','').'"></td>';
	echo '<td align="center" valign="middle""><textarea class="form-control areasize" cols="30" rows="2" name="txtRemarks_'.$line.'" id="txtRemarks_'.$line.'" placeholder="Remarks...">'.$obj->getRemarksFromCompTable($comid, $line).'</textarea></td>';
	echo '</tr>';
	
	$line = 22;
	echo '<tr id="trRow_'.$line.'">';
	echo '<td align="center" valign="middle" width="10%">Total Days <input type="hidden" id="txtIdentity_'.$line.'" name="txtIdentity_'.$line.'" value="Total Days"/></td>';
	$result = mysql_query($sql);$initialamt = $finalamt = $difference = 0;
	while($rows= mysql_fetch_assoc($result))
	{
	    $finalamt = $rows['TOTAL_DAYS'];
		$difference = $finalamt - $initialamt;
		$initialamt = $rows['TOTAL_DAYS'];
		echo '<td align="center" valign="middle" width="'.$width.'%">'.$rows['TOTAL_DAYS'].'</td>';
	}
	echo '<td align="center" valign="middle""><input type="text" class="form-control" readonly="true" name="txtDifference_'.$line.'" id="txtDifference_'.$line.'" value="'.number_format($difference,2,'.','').'"></td>';
	echo '<td align="center" valign="middle""><textarea class="form-control areasize" cols="30" rows="2" name="txtRemarks_'.$line.'" id="txtRemarks_'.$line.'" placeholder="Remarks...">'.$obj->getRemarksFromCompTable($comid, $line).'</textarea></td>';
	echo '</tr>';
	
	$line = 23;
	echo '<tr id="trRow_'.$line.'">';
	echo '<td align="center" valign="middle" width="10%">Ttl FO Consp MT <input type="hidden" id="txtIdentity_'.$line.'" name="txtIdentity_'.$line.'" value="Ttl FO Consp MT"/></td>';
	$result = mysql_query($sql);$initialamt = $finalamt = $difference = 0;
	while($rows= mysql_fetch_assoc($result))
	{
	    $finalamt = $rows['FO_CONSP'];
		$difference = $finalamt - $initialamt;
		$initialamt = $rows['FO_CONSP'];
		echo '<td align="center" valign="middle" width="'.$width.'%">'.$rows['FO_CONSP'].'</td>';
	}
	echo '<td align="center" valign="middle""><input type="text" class="form-control" readonly="true" name="txtDifference_'.$line.'" id="txtDifference_'.$line.'" value="'.number_format($difference,2,'.','').'"></td>';
	echo '<td align="center" valign="middle""><textarea class="form-control areasize" cols="30" rows="2" name="txtRemarks_'.$line.'" id="txtRemarks_'.$line.'" placeholder="Remarks...">'.$obj->getRemarksFromCompTable($comid, $line).'</textarea></td>';
	echo '</tr>';
	
	
	$line = 24;
	echo '<tr id="trRow_'.$line.'">';
	echo '<td align="center" valign="middle" width="10%">Ttl DO Consp MT <input type="hidden" id="txtIdentity_'.$line.'" name="txtIdentity_'.$line.'" value="Ttl DO Consp MT"/></td>';
	$result = mysql_query($sql);$initialamt = $finalamt = $difference = 0;
	while($rows= mysql_fetch_assoc($result))
	{
	    $finalamt = $rows['DO_CONSP'];
		$difference = $finalamt - $initialamt;
		$initialamt = $rows['DO_CONSP'];
		echo '<td align="center" valign="middle" width="'.$width.'%">'.$rows['DO_CONSP'].'</td>';
	}
	echo '<td align="center" valign="middle""><input type="text" class="form-control" readonly="true" name="txtDifference_'.$line.'" id="txtDifference_'.$line.'" value="'.number_format($difference,2,'.','').'"></td>';
	echo '<td align="center" valign="middle""><textarea class="form-control areasize" cols="30" rows="2" name="txtRemarks_'.$line.'" id="txtRemarks_'.$line.'" placeholder="Remarks...">'.$obj->getRemarksFromCompTable($comid, $line).'</textarea></td>';
	echo '</tr>';
	
	
	$line = 25;
	$bunker_expense = array();
	echo '<tr id="trRow_'.$line.'">';
	echo '<td align="left" valign="middle" colspan="'.(2+$num).'"><span style="font-size:16px;"><strong>Bunker Expenses</strong></span> (Qty / Price / Amount) <input type="hidden" id="txtIdentity_'.$line.'" name="txtIdentity_'.$line.'" value="Bunker Expenses"/></td>';
	echo '<td align="center" valign="middle""><textarea class="form-control areasize" cols="30" rows="2" name="txtRemarks_'.$line.'" id="txtRemarks_'.$line.'" placeholder="Remarks...">'.$obj->getRemarksFromCompTable($comid, $line).'</textarea></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 '<td align="center" valign="middle" width="10%" style="overflow:auto;"></td>';
		echo '</tr>';
	}
	
	$line = 26;
	echo '<tr id="trRow_'.$line.'">';
	echo '<td align="center" valign="middle" width="10%"><strong>Total Bunker Expense</strong> <input type="hidden" id="txtIdentity_'.$line.'" name="txtIdentity_'.$line.'" value="Total Bunker Expense"/></td>';
	$result = mysql_query($sql);$initialamt = $finalamt = $difference = 0;
	while($rows= mysql_fetch_assoc($result))
	{
	    $finalamt = array_sum($bunker_expense[$rows['FCAID']]);
		$difference = $finalamt - $initialamt;
		$initialamt = array_sum($bunker_expense[$rows['FCAID']]);
		echo '<td align="center" valign="middle" width="'.$width.'%"><strong>'.array_sum($bunker_expense[$rows['FCAID']]).'</strong></td>';
	}
	echo '<td align="center" valign="middle""><input type="text" class="form-control" readonly="true" name="txtDifference_'.$line.'" id="txtDifference_'.$line.'" value="'.number_format($difference,2,'.','').'"></td>';
	echo '<td align="center" valign="middle""><textarea class="form-control areasize" cols="30" rows="2" name="txtRemarks_'.$line.'" id="txtRemarks_'.$line.'" placeholder="Remarks...">'.$obj->getRemarksFromCompTable($comid, $line).'</textarea></td>';
	echo '</tr>';
	
	
    $line = 27;
	echo '<tr id="trRow_'.$line.'">';
	echo '<td align="center" valign="middle" width="10%"><span style="font-size:16px;"><strong>Navigation Expenses</strong></span> <input type="hidden" id="txtIdentity_'.$line.'" name="txtIdentity_'.$line.'" value="Navigation Expenses"/></td>';
	$result = mysql_query($sql);$initialamt = $finalamt = $difference = 0;
	while($rows= mysql_fetch_assoc($result))
	{
	    $finalamt = (array_sum($array_expense[$rows['FCAID']]) + array_sum($bunker_expense[$rows['FCAID']]));
		$difference = $finalamt - $initialamt;
		$initialamt = (array_sum($array_expense[$rows['FCAID']]) + array_sum($bunker_expense[$rows['FCAID']]));
		echo '<td align="center" valign="middle" width="'.$width.'%"><strong>'.(array_sum($array_expense[$rows['FCAID']]) + array_sum($bunker_expense[$rows['FCAID']])).'</strong></td>';
	}
	echo '<td align="center" valign="middle""><input type="text" class="form-control" readonly="true" name="txtDifference_'.$line.'" id="txtDifference_'.$line.'" value="'.number_format($difference,2,'.','').'"></td>';
	echo '<td align="center" valign="middle""><textarea class="form-control areasize" cols="30" rows="2" name="txtRemarks_'.$line.'" id="txtRemarks_'.$line.'" placeholder="Remarks...">'.$obj->getRemarksFromCompTable($comid, $line).'</textarea></td>';
	echo '</tr>';
	
	
	
	$line = 28;
	echo '<tr id="trRow_'.$line.'">';
	echo '<td align="center" valign="middle" width="10%">Hireage <input type="hidden" id="txtIdentity_'.$line.'" name="txtIdentity_'.$line.'" value="Hireage"/></td>';
	$result = mysql_query($sql);$initialamt = $finalamt = $difference = 0;
	while($rows= mysql_fetch_assoc($result))
	{
		$hirage = $rows['DAILY_VESSEL_OPERATION_EXP']*$rows['TOTAL_DAYS'];
		$sqlinvoice = "select SUM(HIRE_AMT) as SUM from freight_cost_estimete_slave17 WHERE FCAID='".$rows['FCAID']."'";
		$resinvoice = mysql_query($sqlinvoice);
		$numinvoice = mysql_num_rows($resinvoice);
		$rowsinvoice = mysql_fetch_assoc($resinvoice);
		if($numinvoice > 0)
		{
		    $hirage = $rowsinvoice['SUM'];
		}
		else
		{
			$hirage = $rows['DAILY_VESSEL_OPERATION_EXP']*$rows['TOTAL_DAYS'];
		}
		
		$finalamt = $hirage;
		$difference = $finalamt - $initialamt;
		$initialamt = $hirage;
		
		echo '<td align="center" valign="middle" width="'.$width.'%"><strong>'.$hirage.'</strong></td>';
	}
	echo '<td align="center" valign="middle""><input type="text" class="form-control" readonly="true" name="txtDifference_'.$line.'" id="txtDifference_'.$line.'" value="'.number_format($difference,2,'.','').'"></td>';
	echo '<td align="center" valign="middle""><textarea class="form-control areasize" cols="30" rows="2" name="txtRemarks_'.$line.'" id="txtRemarks_'.$line.'" placeholder="Remarks...">'.$obj->getRemarksFromCompTable($comid, $line).'</textarea></td>';
	echo '</tr>';
	
	$line = 30;
	echo '<tr id="trRow_'.$line.'">';
	echo '<td align="center" valign="middle" width="10%">Ballast Bonus <input type="hidden" id="txtIdentity_'.$line.'" name="txtIdentity_'.$line.'" value="Ballast Bonus"/></td>';
	$result = mysql_query($sql);$initialamt = $finalamt = $difference = 0;
	while($rows= mysql_fetch_assoc($result))
	{
	    $finalamt = array_sum($arr_sum);
		$difference = $finalamt - $initialamt;
		$initialamt = array_sum($arr_sum);
		echo '<td align="center" valign="middle" width="'.$width.'%"><strong>'.$rows['BALLAST_BONUS'].'</strong></td>';
	}
	echo '<td align="center" valign="middle""><input type="text" class="form-control" readonly="true" name="txtDifference_'.$line.'" id="txtDifference_'.$line.'" value="'.number_format($difference,2,'.','').'"></td>';
	echo '<td align="center" valign="middle""><textarea class="form-control areasize" cols="30" rows="2" name="txtRemarks_'.$line.'" id="txtRemarks_'.$line.'" placeholder="Remarks...">'.$obj->getRemarksFromCompTable($comid, $line).'</textarea></td>';
	echo '</tr>';
	
	$line = 31;
	echo '<tr id="trRow_'.$line.'">';
	echo '<td align="center" valign="middle" width="10%">Add Comm (%/Amt) <input type="hidden" id="txtIdentity_'.$line.'" name="txtIdentity_'.$line.'" value="Add Comm (%/Amt)"/></td>';
	$result = mysql_query($sql);$initialamt = $finalamt = $difference = 0;
	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'];}
		
		$finalamt = ($hirage*$rows['HIREAGE_PERCENT'])/100;
		$difference = $finalamt - $initialamt;
		$initialamt = ($hirage*$rows['HIREAGE_PERCENT'])/100;
		echo '<td align="center" valign="middle" width="'.$width.'%"><strong>'.$rows['HIREAGE_PERCENT'].' / '.(($hirage*$rows['HIREAGE_PERCENT'])/100).'</strong></td>';
	}
	echo '<td align="center" valign="middle""><input type="text" class="form-control" readonly="true" name="txtDifference_'.$line.'" id="txtDifference_'.$line.'" value="'.number_format($difference,2,'.','').'"></td>';
	echo '<td align="center" valign="middle""><textarea class="form-control areasize" cols="30" rows="2" name="txtRemarks_'.$line.'" id="txtRemarks_'.$line.'" placeholder="Remarks...">'.$obj->getRemarksFromCompTable($comid, $line).'</textarea></td>';
	echo '</tr>';
	
	$line = 32;
	echo '<tr id="trRow_'.$line.'">';
	echo '<td align="center" valign="middle" width="10%"><strong>Nett Hireage<strong> <input type="hidden" id="txtIdentity_'.$line.'" name="txtIdentity_'.$line.'" value="Nett Hireage"/></td>';
	$result = mysql_query($sql);$initialamt = $finalamt = $difference = 0;
	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'];}
		$finalamt = ($hirage - (($hirage*$rows['HIREAGE_PERCENT'])/100) + $rows['BALLAST_BONUS']);
		$difference = $finalamt - $initialamt;
		$initialamt = ($hirage - (($hirage*$rows['HIREAGE_PERCENT'])/100) + $rows['BALLAST_BONUS']);
		echo '<td align="center" valign="middle" width="'.$width.'%"><strong>'.($hirage - (($hirage*$rows['HIREAGE_PERCENT'])/100) + $rows['BALLAST_BONUS']).'</strong></td>';
	}
	echo '<td align="center" valign="middle""><input type="text" class="form-control" readonly="true" name="txtDifference_'.$line.'" id="txtDifference_'.$line.'" value="'.number_format($difference,2,'.','').'"></td>';
	echo '<td align="center" valign="middle""><textarea class="form-control areasize" cols="30" rows="2" name="txtRemarks_'.$line.'" id="txtRemarks_'.$line.'" placeholder="Remarks...">'.$obj->getRemarksFromCompTable($comid, $line).'</textarea></td>';
	echo '</tr>';
	
	$line = 33;
	echo '<tr id="trRow_'.$line.'">';
	echo '<td align="center" valign="middle" width="10%"><span style="font-size:16px;"><strong>Daily Earnings / TCE</strong></span> <input type="hidden" id="txtIdentity_'.$line.'" name="txtIdentity_'.$line.'" value="Daily Earnings / TCE"/></td>';
	$result = mysql_query($sql);$initialamt = $finalamt = $difference = 0;
	while($rows= mysql_fetch_assoc($result))
	{
	    $finalamt = $rows['DAILY_EARNING'];
		$difference = $finalamt - $initialamt;
		$initialamt = $rows['DAILY_EARNING'];
		echo '<td align="center" valign="middle" width="'.$width.'%">'.$rows['DAILY_EARNING'].'</td>';
	}
	echo '<td align="center" valign="middle""><input type="text" class="form-control" readonly="true" name="txtDifference_'.$line.'" id="txtDifference_'.$line.'" value="'.number_format($difference,2,'.','').'"></td>';
	echo '<td align="center" valign="middle""><textarea class="form-control areasize" cols="30" rows="2" name="txtRemarks_'.$line.'" id="txtRemarks_'.$line.'" placeholder="Remarks...">'.$obj->getRemarksFromCompTable($comid, $line).'</textarea></td>';
	echo '</tr>';
	
	$line = 34;
	echo '<tr id="trRow_'.$line.'">';
	echo '<td align="center" valign="middle" width="10%"><span style="font-size:16px;"><strong>Nett Daily Profit</strong></span> <input type="hidden" id="txtIdentity_'.$line.'" name="txtIdentity_'.$line.'" value="Nett Daily Profit"/></td>';
	$result = mysql_query($sql);$initialamt = $finalamt = $difference = 0;
	while($rows= mysql_fetch_assoc($result))
	{
	    $finalamt = $rows['NET_DAILY_PROFIT'];
		$difference = $finalamt - $initialamt;
		$initialamt = $rows['NET_DAILY_PROFIT'];
		echo '<td align="center" valign="middle" width="'.$width.'%">'.$rows['NET_DAILY_PROFIT'].'</td>';
	}
	echo '<td align="center" valign="middle""><input type="text" class="form-control" readonly="true" name="txtDifference_'.$line.'" id="txtDifference_'.$line.'" value="'.number_format($difference,2,'.','').'"></td>';
	echo '<td align="center" valign="middle""><textarea class="form-control areasize" cols="30" rows="2" name="txtRemarks_'.$line.'" id="txtRemarks_'.$line.'" placeholder="Remarks...">'.$obj->getRemarksFromCompTable($comid, $line).'</textarea></td>';
	echo '</tr>';
	
	$line = 35;
	echo '<tr id="trRow_'.$line.'">';
	echo '<td align="center" valign="middle" width="10%"><span style="font-size:16px;"><strong>P/L</strong></span> <input type="hidden" id="txtIdentity_'.$line.'" name="txtIdentity_'.$line.'" value="P/L"/><input type="hidden" name="txtRowCount" id="txtRowCount" value="35"/></td>';
	$result = mysql_query($sql);$initialamt = $finalamt = $difference = 0;
	while($rows= mysql_fetch_assoc($result))
	{
	    $finalamt = $rows['ACTUAL_PL'];
		$difference = $finalamt - $initialamt;
		$initialamt = $rows['ACTUAL_PL'];
		echo '<td align="center" valign="middle" width="'.$width.'%">'.$rows['ACTUAL_PL'].'</td>';
	}
	echo '<td align="center" valign="middle""><input type="text" class="form-control" readonly="true" name="txtDifference_'.$line.'" id="txtDifference_'.$line.'" value="'.number_format($difference,2,'.','').'"></td>';
	echo '<td align="center" valign="middle""><textarea class="form-control areasize" cols="30" name="txtRemarks_'.$line.'" id="txtRemarks_'.$line.'" rows="2" placeholder="Remarks...">'.$obj->getRemarksFromCompTable($comid, $line).'</textarea></td>';
	echo '</tr>';
	
	echo '</tbody>';
	echo '</table>';
	echo '</div>';
}


function getComparisionVCReport()
{
	$obj 		  = new data();
	$connect	  = $obj->funConnect();
	
	$selYear = addslashes($_REQUEST['selYear']);
	
	$sql = "select freight_cost_estimate_compare.COMID as COMID 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,3) and year(freight_cost_estimete_master.ADD_ON_DATE)='".$selYear."' and COAAID is NULL and FINAL_ID!='' order by date(freight_cost_estimete_master.FINAL_DATETIME) desc";
	
	$res 		  = mysql_query($sql) or die($sql);
	$rec     	  = mysql_num_rows($res);
	$j=1;
	$arr = array();
	echo '<table id="voyage_list" class="table table-bordered table-striped dataTable">
			<thead>
			<tr>
				<th align="left" valign="top" width="5%">S.No.</th>
				<th align="left" valign="top" width="10%">CP Date</th>
				<th align="left" valign="top" width="10%">Voyage No.</th>
				<th align="left" valign="top" width="10%">Vessel Name</th>	
				<th align="left" valign="top" width="10%">Cargo Qty. (MT)</th>
				<th align="left" valign="top" width="10%">TC Earning (USD)</th>
				<th align="left" valign="top" width="10%">P&L (USD)</th>
				<th align="left" valign="top" width="10%">Comparision</th>
			</tr>
			</thead>
			<tbody>';
	while($rows = mysql_fetch_assoc($res))
	{
		$cpdate = $obj->getCompareEstimateData($rows['COMID'],"TRANS_DATE");
		if($cpdate!="0000-00-00" && $cpdate!=""){$cpdate = date('d-m-Y',strtotime($cpdate));}else{$cpdate = "";}
		$vesselname = $obj->getVesselIMOData($obj->getCompareEstimateData($rows['COMID'],"VESSEL_IMO_ID"),"VESSEL_NAME");
		$voyageno = $obj->getCompareEstimateData($rows['COMID'],"VOYAGE_NO");
        
		$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='".$obj->getCompareEstimateData($rows['COMID'],"FCAID")."'";
				$res12 = mysql_query($sql12);
				$row12 = mysql_fetch_assoc($res12);
				$quantity = $row12['sum'];
			}
		}
		
  		echo '<tr>';
		echo '<td align="center" valign="middle">'.$j.'</td>';
		echo '<td align="left" valign="middle">'.$cpdate.'</td>';
		echo '<td align="left" valign="middle">'.$voyageno.'</td>';
		echo '<td align="left" valign="middle">'.$vesselname.'</td>';
		echo '<td align="left" valign="middle">'.$quantity.'</td>';
		echo '<td align="left" valign="middle">'.$obj->getCompareEstimateData($rows['COMID'],"DAILY_EARNING").'</td>';
		echo '<td align="left" valign="middle">'.$obj->getCompareEstimateData($rows['COMID'],"ACTUAL_PL").'</td>';
		echo '<td align="left" valign="middle"><button class="btn btn-primary btn-flat" data-toggle="modal" data-target="#compose-modal2" type="button" title="Compare Sheets" onClick="getCompareSheetData('.$rows['COMID'].');">Compare Sheets</button></td>';
		echo '</tr>';
		$j++;
	}

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


function getCombinedSOAListJson()
{
	$obj = new data();
	$connect=$obj->funConnect();
	
	$aColumns = array("SOAID", "SOA_NO", "SOA_DATE", "CREATORNAME", "UPDATE_STATUS");
	
	$sIndexColumn = "SOAID";
	
	$sTable = "combined_soa_master";
	
	if(!empty($_POST['order'][0]['column']))
	{
		$sOrder = "ORDER BY  ".$aColumns[intval($_POST['order'][0]['column'])]." ".$_POST['order'][0]['dir'];
	}
	else
	{
		$sOrder = "ORDER BY SOAID";
	}
	
	$sWhere = "";
	
	if ($_POST['search']['value']!= "")
	{
		$sWhere = " (SOA_NO LIKE '%".$_POST['search']['value']."%' or SOA_DATE LIKE '%".$_POST['search']['value']."%'  or CREATORNAME LIKE '%".$_POST['search']['value']."%' or UPDATE_STATUS LIKE '%".$_POST['search']['value']."%') ";
	}else{$sWhere = " 1=1";}
	
	$sQuery = "SELECT * FROM (select SOAID, SOA_NO, SOA_DATE, STATUS, CREATOR, (CASE when (STATUS = 0) THEN 'Submit to Edit' when (STATUS = 1) THEN 'Level 1 Approval Pending'  when (STATUS = 2) THEN 'Sent for Review To Creator' when (STATUS = 3) THEN 'Level 2 Approval Pending' when (STATUS = 4) THEN 'Sent for Review To Approver 1' when (STATUS = 5) THEN 'Pending for Payment' ELSE 'Paid' END) as UPDATE_STATUS, (select CONTACT_PERSON from login where login.LOGINID = combined_soa_master.CREATOR) as CREATORNAME from combined_soa_master) as innerTable where $sWhere $sOrder LIMIT ".$_POST['start'].", ".$_POST['length']."";
	$rResult = mysql_query($sQuery) or die($sQuery);
	$sQuery = "	SELECT COUNT(".$sIndexColumn.") FROM (select * from combined_soa_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 ) )
	{$i++;
	    
		$details = '<a href="updatecombinedsoa.php?id='.$aRow['SOAID'].'" title="Edit Details" ><i class="fa fa-edit "></i></a>';
		
		
		if($aRow['UPDATE_STATUS'] == 'Submit to Edit')
		{
			$status = '<b><span class="label label-danger">Submit to Edit</span></b>';
		}
		else if($aRow['UPDATE_STATUS'] == 'Level 1 Approval Pending')
		{
			$status = '<b><span class="label label-warning">Level 1 Approval Pending</span></b>';
		}
		else if($aRow['UPDATE_STATUS'] == 'Sent for Review To Creator')
		{
			$status = '<b><span class="label label-danger">Sent for Review To Creator</span></b>';
		}
		else if($aRow['UPDATE_STATUS'] == 'Level 2 Approval Pending')
		{
			$status = '<b><span class="label label-warning">Level 2 Approval Pending</span></b>';
		}
		else if($aRow['UPDATE_STATUS'] == 'Sent for Review To Approver 1')
		{
			$status = '<b><span class="label label-danger">Sent for Review To Approver 1</span></b>';
		}
		else if($aRow['UPDATE_STATUS'] == 'Pending for Payment')
		{
			$status = '<b><span class="label label-danger">Pending for Payment</span></b>';
		}
		else
		{
			$status = '<b><span class="label label-success">Paid</span></b>';
		}
		
		$aaData[] = array('col1'=>$i.'.', 'col2'=>$aRow['SOA_NO'], 'col3'=>date('d-m-Y',strtotime($aRow['SOA_DATE'])), 'col4'=>$aRow['CREATORNAME'], 'col5'=>$status, 'col6'=>$details);
		
	}
	
	echo json_encode(array("draw"=>intval($_POST['draw']),"recordsTotal"=>$totalData,"recordsFiltered"=>$totalFiltered,"records" => $aaData));
}


function getCombinedSOAData()
{
	$obj 		  = new data();
	$connect	  = $obj->funConnect();
	
	$vendor = addslashes($_REQUEST['selVendor']);
	
	$sql = "select invoice_hire_master.INVOICE_NO, invoice_hire_master.INVOICE_DATE, invoice_hire_master.BALANCE_TO_OWNER, invoice_hire_master.INVOICEID, invoice_hire_master.COMID from invoice_hire_master inner join freight_cost_estimete_master on freight_cost_estimete_master.COMID=invoice_hire_master.COMID where invoice_hire_master.STATUS=5 and freight_cost_estimete_master.DTCVENDORID='".$vendor."' and (invoice_hire_master.P_AMT is NULL or invoice_hire_master.P_AMT='') and (select COUNT(*) as COUNT from combined_soa_slave where combined_soa_slave.INVOICEID=invoice_hire_master.INVOICEID and combined_soa_slave.INVOICE_TYPE='HIRE STATEMENT')=0"; 
	
	$res 		  = mysql_query($sql) or die($sql);
	$rec     	  = mysql_num_rows($res);
	$j=1;
	$arr = array();
	
	
	if($rec == 0)
	{
		//echo '<tr><td colspan="7">Sorr</td></tr>';
	}else{
	
		while($rows = mysql_fetch_assoc($res))
		{
			$cpdate = $obj->getCompareEstimateData($rows['COMID'],"TRANS_DATE");
			if($cpdate!="0000-00-00" && $cpdate!=""){$cpdate = date('d-m-Y',strtotime($cpdate));}else{$cpdate = "";}
			$vesselname = $obj->getVesselIMOData($obj->getCompareEstimateData($rows['COMID'],"VESSEL_IMO_ID"),"VESSEL_NAME");
			$vendorname = $obj->getVendorListNewData($obj->getCompareEstimateData($rows['COMID'],"DTCVENDORID"),"NAME");
			$voyageno = $obj->getCompareEstimateData($rows['COMID'],"VOYAGE_NO");
			
			echo '<tr>';
			echo '<td align="center" valign="middle"><input name="chkSelect[]" class="checkbox" id="chkSelect_'.$j.'" type="checkbox" value="'.$j.'"/><input type="hidden" name="txtInvoiceID_'.$j.'" id="txtInvoiceID_'.$j.'" value="'.$rows['INVOICEID'].'"/><input type="hidden" name="txtInvoiceType_'.$j.'" id="txtInvoiceType_'.$j.'" value="HIRE STATEMENT"/></td>';
			echo '<td align="left" valign="middle">'.$vesselname.'</td>';
			echo '<td align="left" valign="middle">'.$voyageno.'</td>';
			echo '<td align="left" valign="middle">'.$cpdate.'</td>';
			echo '<td align="left" valign="middle">Hire Statement</td>';
			echo '<td align="left" valign="middle">'.$rows['INVOICE_NO'].'</td>';
			echo '<td align="left" valign="middle">'.date('d-m-Y',strtotime($rows['INVOICE_DATE'])).'</td>';
			echo '<td align="left" valign="middle">'.$vendorname.'</td>';
			echo '<td align="left" valign="right">'.$rows['BALANCE_TO_OWNER'].'<input type="hidden" name="txtBalance_'.$j.'" id="txtBalance_'.$j.'" value="'.$rows['BALANCE_TO_OWNER'].'"/></td>';
			echo '<td align="left" valign="middle"><input type="text" name="txtAmountPaid_'.$j.'" id="txtAmountPaid_'.$j.'" readonly="true" class="form-control numeric" placeholder="0.00" autocomplete="off" value=""/></td>';
			echo '<td align="left" valign="middle"><textarea name="txtRemarks_'.$j.'" id="txtRemarks_'.$j.'" class="form-control autosize" readonly="true" rows="3" placeholder="Description"></textarea></td>';
			echo '</tr>';
			$j++;
		}
	}
	
	
	$sql = "select COMID, PAYMENT_NO, DATE, REQ_TO_PAY, REQ_ID, NAME, VENDOR from request_master where STATUS=5 and (P_AMT is NULL or P_AMT='') and (select COUNT(*) as COUNT from combined_soa_slave where combined_soa_slave.INVOICEID=request_master.REQ_ID and combined_soa_slave.INVOICE_TYPE='PAYMENT')=0 and VENDOR='".$vendor."'"; 
	
	$res 		  = mysql_query($sql) or die($sql);
	$rec     	  = mysql_num_rows($res);
	$arr = array();
	
	
	if($rec == 0)
	{
		
	}else{
	
		while($rows = mysql_fetch_assoc($res))
		{
			$cpdate = $obj->getCompareEstimateData($rows['COMID'],"TRANS_DATE");
			if($cpdate!="0000-00-00" && $cpdate!=""){$cpdate = date('d-m-Y',strtotime($cpdate));}else{$cpdate = "";}
			$vesselname = $obj->getVesselIMOData($obj->getCompareEstimateData($rows['COMID'],"VESSEL_IMO_ID"),"VESSEL_NAME");
			$vendorname = $obj->getVendorListNewData($rows['VENDOR'],"NAME");
			$voyageno = $obj->getCompareEstimateData($rows['COMID'],"VOYAGE_NO");
			
			echo '<tr>';
			echo '<td align="center" valign="middle"><input name="chkSelect[]" class="checkbox" id="chkSelect_'.$j.'" type="checkbox" value="'.$j.'"/><input type="hidden" name="txtInvoiceID_'.$j.'" id="txtInvoiceID_'.$j.'" value="'.$rows['REQ_ID'].'"/><input type="hidden" name="txtInvoiceType_'.$j.'" id="txtInvoiceType_'.$j.'" value="PAYMENT"/></td>';
			echo '<td align="left" valign="middle">'.$vesselname.'</td>';
			echo '<td align="left" valign="middle">'.$voyageno.'</td>';
			echo '<td align="left" valign="middle">'.$cpdate.'</td>';
			echo '<td align="left" valign="middle">'.$rows['NAME'].'</td>';
			echo '<td align="left" valign="middle">'.$rows['PAYMENT_NO'].'</td>';
			echo '<td align="left" valign="middle">'.date('d-m-Y',strtotime($rows['DATE'])).'</td>';
			echo '<td align="left" valign="middle">'.$vendorname.'</td>';
			echo '<td align="left" valign="right">'.$rows['REQ_TO_PAY'].'<input type="hidden" name="txtBalance_'.$j.'" id="txtBalance_'.$j.'" value="'.$rows['REQ_TO_PAY'].'"/></td>';
			echo '<td align="left" valign="middle"><input type="text" name="txtAmountPaid_'.$j.'" id="txtAmountPaid_'.$j.'" readonly="true" class="form-control numeric" placeholder="0.00" autocomplete="off" value=""/></td>';
			echo '<td align="left" valign="middle"><textarea name="txtRemarks_'.$j.'" id="txtRemarks_'.$j.'" class="form-control autosize" readonly="true" rows="3" placeholder="Description"></textarea></td>';
			echo '</tr>';
			$j++;
		}
	}
	
	
	$sql = "select INVOICE_NO, INVOICE_DATE, BALANCE_TO_OWNER, INVOICEID, RANDOMID, COMID from invoice_hiretc_master where STATUS=5 and (select TC_FINAL_HIERAGE_VENDOR from chartering_tc_estimate_slave1 where chartering_tc_estimate_slave1.TCOUTID=(select TCOUTID from chartering_estimate_tc_master where chartering_estimate_tc_master.COMID=invoice_hiretc_master.COMID order by TCOUTID DESC LIMIT 0,1) and chartering_tc_estimate_slave1.RANDOMID=invoice_hiretc_master.RANDOMID)='".$vendor."' and (invoice_hiretc_master.P_AMT is NULL or invoice_hiretc_master.P_AMT='') and (select COUNT(*) as COUNT from combined_soa_slave where combined_soa_slave.INVOICEID=invoice_hiretc_master.INVOICEID and combined_soa_slave.INVOICE_TYPE='TC HIRE STATEMENT')=0"; 
	$res 		  = mysql_query($sql) or die($sql);
	$rec     	  = mysql_num_rows($res);
	
	$arr = array();
	
	
	if($rec == 0)
	{
		
	}else{
	
		while($rows = mysql_fetch_assoc($res))
		{
		    $tcoutid = $obj->getCharteringEstimateTCData($rows['COMID'],"TCOUTID");
		    $sqltc = "SELECT TC_CP_DATE, TC_FINAL_HIERAGE_VENDOR from chartering_tc_estimate_slave1 where TCOUTID='".$tcoutid."' and RANDOMID='".$rows['RANDOMID']."'";
			$restc 	= mysql_query($sqltc);
			$rectc 	= mysql_num_rows($restc);
			$rowstc = mysql_fetch_assoc($restc);
			
			$cpdate = $rowstc['TC_CP_DATE'];
			if($cpdate!="0000-00-00" && $cpdate!=""){$cpdate = date('d-m-Y',strtotime($cpdate));}else{$cpdate = "";}
			$vesselname = $obj->getVesselIMOData($obj->getCharteringEstimateTCData($rows['COMID'],"VESSEL_IMO_ID"),"VESSEL_NAME");
			$vendorname = $obj->getVendorListNewData($rowstc['TC_FINAL_HIERAGE_VENDOR'],"NAME");
			$voyageno = $obj->getCharteringEstimateTCData($rows['COMID'],"TC_NO");
			
			echo '<tr>';
			echo '<td align="center" valign="middle"><input name="chkSelect[]" class="checkbox" id="chkSelect_'.$j.'" type="checkbox" value="'.$j.'"/><input type="hidden" name="txtInvoiceID_'.$j.'" id="txtInvoiceID_'.$j.'" value="'.$rows['INVOICEID'].'"/><input type="hidden" name="txtInvoiceType_'.$j.'" id="txtInvoiceType_'.$j.'" value="TC HIRE STATEMENT"/></td>';
			echo '<td align="left" valign="middle">'.$vesselname.'</td>';
			echo '<td align="left" valign="middle">'.$voyageno.'</td>';
			echo '<td align="left" valign="middle">'.$cpdate.'</td>';
			echo '<td align="left" valign="middle">TC Hire Statement</td>';
			echo '<td align="left" valign="middle">'.$rows['INVOICE_NO'].'</td>';
			echo '<td align="left" valign="middle">'.date('d-m-Y',strtotime($rows['INVOICE_DATE'])).'</td>';
			echo '<td align="left" valign="middle">'.$vendorname.'</td>';
			echo '<td align="left" valign="right">'.$rows['BALANCE_TO_OWNER'].'<input type="hidden" name="txtBalance_'.$j.'" id="txtBalance_'.$j.'" value="'.$rows['BALANCE_TO_OWNER'].'"/></td>';
			echo '<td align="left" valign="middle"><input type="text" name="txtAmountPaid_'.$j.'" id="txtAmountPaid_'.$j.'" readonly="true" class="form-control numeric" placeholder="0.00" autocomplete="off" value=""/></td>';
			echo '<td align="left" valign="middle"><textarea name="txtRemarks_'.$j.'" id="txtRemarks_'.$j.'" class="form-control autosize" readonly="true" rows="3" placeholder="Description"></textarea></td>';
			echo '</tr>';
			$j++;
		}
	}
	
	$sql = "select INVOICE_NO, SHORT_DESC, INVOICE_DATE, PAYMENTID, RANDOMID, COMID, FINAL_AMOUNT, VENDOR from payment_tcother_master where STATUS=5 and VENDOR='".$vendor."' and (payment_tcother_master.P_AMT is NULL or payment_tcother_master.P_AMT='') and (select COUNT(*) as COUNT from combined_soa_slave where combined_soa_slave.INVOICEID=payment_tcother_master.PAYMENTID and combined_soa_slave.INVOICE_TYPE='TC PAYMENT')=0"; 
	$res 		  = mysql_query($sql) or die($sql);
	$rec     	  = mysql_num_rows($res);
	
	$arr = array();
	
	
	if($rec == 0)
	{
		
	}else{
	
		while($rows = mysql_fetch_assoc($res))
		{
		    $tcoutid = $obj->getCharteringEstimateTCData($rows['COMID'],"TCOUTID");
		    $sqltc = "SELECT TC_CP_DATE, TC_FINAL_HIERAGE_VENDOR from chartering_tc_estimate_slave1 where TCOUTID='".$tcoutid."' and RANDOMID='".$rows['RANDOMID']."'";
			$restc 	= mysql_query($sqltc);
			$rectc 	= mysql_num_rows($restc);
			$rowstc = mysql_fetch_assoc($restc);
			
			$cpdate = $rowstc['TC_CP_DATE'];
			if($cpdate!="0000-00-00" && $cpdate!=""){$cpdate = date('d-m-Y',strtotime($cpdate));}else{$cpdate = "";}
			$vesselname = $obj->getVesselIMOData($obj->getCharteringEstimateTCData($rows['COMID'],"VESSEL_IMO_ID"),"VESSEL_NAME");
			$vendorname = $obj->getVendorListNewData($rows['VENDOR'],"NAME");
			$voyageno = $obj->getCharteringEstimateTCData($rows['COMID'],"TC_NO");
			
			echo '<tr>';
			echo '<td align="center" valign="middle"><input name="chkSelect[]" class="checkbox" id="chkSelect_'.$j.'" type="checkbox" value="'.$j.'"/><input type="hidden" name="txtInvoiceID_'.$j.'" id="txtInvoiceID_'.$j.'" value="'.$rows['PAYMENTID'].'"/><input type="hidden" name="txtInvoiceType_'.$j.'" id="txtInvoiceType_'.$j.'" value="TC PAYMENT"/></td>';
			echo '<td align="left" valign="middle">'.$vesselname.'</td>';
			echo '<td align="left" valign="middle">'.$voyageno.'</td>';
			echo '<td align="left" valign="middle">'.$cpdate.'</td>';
			echo '<td align="left" valign="middle">'.$rows['SHORT_DESC'].'</td>';
			echo '<td align="left" valign="middle">'.$rows['INVOICE_NO'].'</td>';
			echo '<td align="left" valign="middle">'.date('d-m-Y',strtotime($rows['INVOICE_DATE'])).'</td>';
			echo '<td align="left" valign="middle">'.$vendorname.'</td>';
			echo '<td align="left" valign="right">'.$rows['FINAL_AMOUNT'].'<input type="hidden" name="txtBalance_'.$j.'" id="txtBalance_'.$j.'" value="'.$rows['FINAL_AMOUNT'].'"/></td>';
			echo '<td align="left" valign="middle"><input type="text" name="txtAmountPaid_'.$j.'" id="txtAmountPaid_'.$j.'" readonly="true" class="form-control numeric" placeholder="0.00" autocomplete="off" value=""/></td>';
			echo '<td align="left" valign="middle"><textarea name="txtRemarks_'.$j.'" id="txtRemarks_'.$j.'" class="form-control autosize" readonly="true" rows="3" placeholder="Description"></textarea></td>';
			echo '</tr>';
			$j++;
		}
	}
	
	echo '</tbody>';
	echo '</table>';		
}

function getTCEarningReport()
{
	$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 freight_cost_estimate_compare.COMID as COMID, freight_cost_estimete_master.VOYAGE_NO, freight_cost_estimete_master.TRANS_DATE as TRANS_DATE, freight_cost_estimete_master.VESSEL_IMO_ID as VESSEL_IMO_ID, freight_cost_estimete_master.ESTIMATE_TYPE as ESTIMATE_TYPE, freight_cost_estimete_master.CP_DATE as CP_DATE, freight_cost_estimete_master.FCAID as 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 in (1,2,3,4,5,6) 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."' 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%">S.No.</th>
			<th align="left" valign="top" width="10%">CP Date</th>
			<th align="left" valign="top" width="10%">Voyage No.</th>
			<th align="left" valign="top" width="10%">Vessel Name</th>	
			<th align="left" valign="top" width="10%">TC Days</th>
			<th align="left" valign="top" width="10%">P&L (USD)</th>
			<th align="left" valign="top" width="10%">Hire/Day (USD)</th>
			<th align="left" valign="top" width="10%">TC Earning (USD)</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'],"TRANS_DATE");
			if($cpdate!="0000-00-00" && $cpdate!=""){$cpdate = date('d-m-Y',strtotime($cpdate));}else{$cpdate = "";}
			$tchiredays = $obj->getCompareEstimateData($rows['COMID'],"TC_HIRE_DAYS");
			
			$tcearning = $obj->getCompareEstimateData($rows['COMID'],"DAILY_VESSEL_OPERATION_EXP") + ($obj->getCompareEstimateData($rows['COMID'],'PROFIT_LOSS'))/$tchiredays;
			echo '<tr>';
			echo '<td align="center" valign="middle">'.$j.'</td>';
			echo '<td align="left" valign="middle">'.$cpdate.'</td>';
			echo '<td align="left" valign="middle">'.$obj->getCompareEstimateData($rows['COMID'],"VOYAGE_NO").'</td>';
			echo '<td align="left" valign="middle">'.$obj->getVesselIMOData($rows['VESSEL_IMO_ID'],"VESSEL_NAME").'</td>';
			echo '<td align="left" valign="middle">'.$tchiredays.'</td>';
			echo '<td align="left" valign="middle">'.$obj->getCompareEstimateData($rows['COMID'],'PROFIT_LOSS').'</td>';
			echo '<td align="left" valign="middle">'.$obj->getCompareEstimateData($rows['COMID'],"DAILY_VESSEL_OPERATION_EXP").'</td>';
			echo '<td align="left" valign="middle">'.number_format($tcearning,2,'.','').'</td>';
			echo '</tr>';
			$j++;
		}
	}
	echo '</tbody>';
	echo '</table>';		
}

function getContractNominationList()
{
	$obj 			= new data();
	$connect		= $obj->funConnect();
	$rigtscoa       = explode(',',$obj->getUserRights($_SESSION['uid'],$_SESSION['moduleid'],14));
	$contractid   =  $_REQUEST['contractid'];
	$result = mysql_query("select * from period_contract_master where PERIODID='".$contractid."'") or die;
	$rows   = mysql_fetch_assoc($result);
	$currencttoshow = $rows['WORKING_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="addestimate.php?periodid='.$contractid.'&page=1&estimatetype='.$_SESSION['selBType'].'"><button type="button" class="btn btn-warning btn-flat" >Add New Voyage Estimate</button></a>&nbsp;&nbsp;&nbsp;&nbsp;';
	               // }
					//if(in_array(2, $rigtscoarelet) || in_array(3, $rigtscoa)){
					   echo '&nbsp;&nbsp;&nbsp;&nbsp;<a href="addtcestimate.php?periodid='.$contractid.'&page=1&estimatetype='.$_SESSION['selBType'].'"><button type="button" class="btn btn-info btn-flat" >Add New TC Estimate</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</th>';
	echo '<th align="left" valign="middle" width="10%">Voyage 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="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="center" valign="middle" width="7%">Details</th>';
	echo '</tr>';
	echo '</thead>';
	echo '<tbody id="tbody">';
	$sql = "select freight_cost_estimete_master.FCAID, freight_cost_estimete_master.VESSEL_IMO_ID, freight_cost_estimete_master.PERIODID, freight_cost_estimete_master.VOYAGE_NO, freight_cost_estimete_master.COMID, freight_cost_estimete_master.ESTIMATE_TYPE, freight_cost_estimete_master.FIXED, freight_cost_estimete_master.COMID, freight_cost_estimete_master.QUANTITY, freight_cost_estimete_master.TRANS_DATE 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='".$_SESSION['selBType']."' and PERIODID='".$contractid."' and FINAL_ID!='' order by date(freight_cost_estimete_master.FINAL_DATETIME) 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(QUANTITY) as sum from freight_cost_estimete_slave7 where FCAID='".$rows['FCAID']."'";
			$res12 = mysql_query($sql12);
			$row12 = mysql_fetch_assoc($res12);
			$quantity = $row12['sum'] + $rows['QUANTITY'];
				
			
			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_NO'].'</td>';
			$coadate = $obj->getCompareEstimateData($rows['COMID'],"TRANS_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">'.$obj->getCompareEstimateData($rows['COMID'],"TOTAL_DAYS").'</td>';
			echo '<td align="left" valign="middle" class="input-text">'.$quantity.'</td>';
			echo '<td align="left" valign="middle" class="input-text">'.$obj->getCompareEstimateData($rows['COMID'],"DAILY_EARNING").'</td>';
			echo '<td align="left" valign="middle" class="input-text">'.$obj->getCompareEstimateData($rows['COMID'],"DAILY_VESSEL_OPERATION_EXP").'</td>';
			
			if($rows['COMID']=="" || $rows['COMID']==0)
			{
				echo '<td align="center" valign="middle" class="input-text"><a href="updateestimate.php?id='.$rows['FCAID'].'" 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="viewestimate.php?id='.$rows['FCAID'].'&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>TC Estimates</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="left" valign="middle" width="10%">S.No.</th>';
	echo '<th align="left" valign="middle" width="10%">Vessel</th>';
	echo '<th align="left" valign="middle" width="7%">TC No.</th>';
	echo '<th align="left" valign="middle" width="11%">CP Date</th>';
	echo '<th align="left" valign="middle" width="9%">DWT</th>';
	echo '<th align="left" valign="middle" width="9%">Del Port</th>';
	echo '<th align="left" valign="middle" width="9%">Re Del Port</th>';
	echo '<th align="left" valign="middle" width="7%">TC Days</th>';
	echo '<th align="left" valign="middle" width="9%">Daily Gross Hire('.$currencttoshow.')</th>';
	echo '<th align="left" valign="middle" width="9%">Hire Rate/Day('.$currencttoshow.')</th>';
	echo '<th align="center" valign="middle" width="10%">Fixture Note</th>';
	echo '<th align="left" valign="middle" width="5%">Estimate</th>';
	echo '</tr>';
	echo '</thead>';
	echo '<tbody id="tbody1">';
	
	$sql = "SELECT chartering_estimate_tc_master.TCOUTID, (select TC_RATE from chartering_tc_estimate_slave2 where chartering_tc_estimate_slave2.TC_SLAVE1ID=(select TC_SLAVE1ID from chartering_tc_estimate_slave1 where chartering_tc_estimate_slave1.TCOUTID= chartering_estimate_tc_master.TCOUTID LIMIT 1) LIMIT 1) as TC_RATE, chartering_estimate_tc_master.EXCHANGE_RATE, chartering_estimate_tc_master.COMID, (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, chartering_estimate_tc_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_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 PERIODID='".$contractid."' order by date(chartering_estimate_tc_master.FINAL_DATETIME) 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 (select TC_RATE from chartering_tc_estimate_slave2 where chartering_tc_estimate_slave2.TC_SLAVE1ID=(select TC_SLAVE1ID from chartering_tc_estimate_slave1 where chartering_tc_estimate_slave1.TCOUTID= chartering_estimate_tc_master.TCOUTID LIMIT 1) LIMIT 1) as TC_RATE, chartering_estimate_tc_master.EXCHANGE_RATE, chartering_estimate_tc_master.COMID, (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, chartering_estimate_tc_master.VESSEL_IMO_ID from chartering_estimate_tc_master where TCOUTID='".$obj->getCharteringEstimateTCData($rows['COMID'], 'TCOUTID')."'";
			$res2 = mysql_query($sql2) or die($sql2);
			$rows2 = mysql_fetch_assoc($res2);
			
			
			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['TC_NO'].'</td>';
			
			if($obj->getCharteringEstimateTCData($rows['COMID'], 'CP_DATE1')=="" || $obj->getCharteringEstimateTCData($rows['COMID'], 'CP_DATE1')=="1970-01-01"){$CP_DATE1 = "";}else{$CP_DATE1 = date('d-m-Y',strtotime($obj->getCharteringEstimateTCData($rows['COMID'], '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">'.$rows2['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">'.$rows2['TC_RATE'].'</td>';
			
			if($rows['COMID']=="")
			{
				echo '<td align="center" valign="middle" class="input-text"><a href="updatetcestimate.php?id='.$rows['TCOUTID'].'" title="Edit Details"><i class="fa fa-edit"></i></a></td>';
				echo '<td align="center" valign="middle" class="input-text"><a href="updatetcestimatecal.php?id='.$rows['TCOUTID'].'" title="Edit TC Estimate"><i class="fa fa-edit"></i></a></td>';
			}
			else
			{
				echo '<td align="center" valign="middle" class="input-text"><a href="updatetcestimate.php?id='.$rows['TCOUTID'].'" title="Edit Details"><i class="fa fa-edit"></i></a></td>';
				echo '<td align="center" valign="middle" class="input-text"><a href="viewtcestimate.php?id='.$rows['TCOUTID'].'&rttype=" title="Edit Details" ><i class="fa fa-file "></i></a></td>';
			}
			echo '</tr>';
			$i++;
		}
	
	}
	echo '</tbody>';
	echo '</table></div>';
}

function getContractListjson()
{
	$obj = new data();
	$connect=$obj->funConnect();
	$_SESSION['selBType'] = $_POST['businesstype'];
	$aColumns = array("PERIODID", "CONTRACT_ID", "CONTRACT_NO", "CONTRACT_DATE", "OWN_BUSINESS_ACCOUNT", "VESSEL_IMO_ID", "WORKING_CURRENCY", "UPDATESTATUS");
	
	$sIndexColumn = "PERIODID";
	
	$sTable = "period_contract_master";
	
	if(!empty($_POST['order'][0]['column']))
	{
		$sOrder = "ORDER BY  ".$aColumns[intval($_POST['order'][0]['column'])]." ".$_POST['order'][0]['dir'];
	}
	else
	{
		$sOrder = "ORDER BY PERIODID";
	}
	
	$sWhere = "";
	
	if ($_POST['search']['value']!= "")
	{
		$sWhere = " and BUSINESSTYPE='".$_POST['businesstype']."' and (CONTRACT_ID LIKE '%".$_POST['search']['value']."%' or CONTRACT_NO LIKE '%".$_POST['search']['value']."%' or CONTRACT_DATE LIKE '%".$_POST['search']['value']."%' or OWN_BUSINESS_ACCOUNT LIKE '%".$_POST['search']['value']."%' or VESSEL_IMO_ID LIKE '%".$_POST['search']['value']."%' or UPDATE_STATUS LIKE '%".$_POST['search']['value']."%') ";
	}else{$sWhere = " and BUSINESSTYPE='".$_POST['businesstype']."' ";}
	
	$sQuery = "SELECT * FROM (select PERIODID, MODULEID, MCOMPANYID, CONTRACT_ID, CONTRACT_NO, WORKING_CURRENCY, CONTRACT_DATE, DELIVERY_DATE, RE_DEL_MAX_DATE, (select VESSEL_NAME from vessel_imo_master where vessel_imo_master.VESSEL_IMO_ID=period_contract_master.VESSEL_IMO_ID) as VESSEL_IMO_ID, (select CONCAT(NAME, '(',CODE,')') as OWN_BUSINESS_ACCOUNT from vendor_master where vendor_master.CODE=period_contract_master.OWN_BUSINESS_ACCOUNT) as OWN_BUSINESS_ACCOUNT, BUSINESSTYPE, (case when (UPDATE_STATUS = 1) THEN 'Save as Draft' ELSE 'Submit to Closed' END) as UPDATE_STATUS from period_contract_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 period_contract_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 ) )
	{
	    $totaldays = (strtotime($aRow['RE_DEL_MAX_DATE']) - strtotime($aRow['DELIVERY_DATE'])) / (60 * 60 * 24);
		$row = array(); $i = $i+1;
		$bunkerarray = $closingarray = array();
		$resultload = mysql_query("select BUNKERGRADEID, BUNKER_QTY from period_contract_master_slave1 where IDENTITY='DEL' and PERIODID='".$aRow['PERIODID']."'");
	    while($rowsload   = mysql_fetch_assoc($resultload))
		{
		    $bunkerarray[] = $obj->getBunkerGradeBasedOnID($rowsload['BUNKERGRADEID']).' - '.$rowsload['BUNKER_QTY'].' MT';
			 
			$remainingbunker = 0;
			$resultbunker = mysql_query("select (select TCOUTID from chartering_estimate_tc_master where chartering_estimate_tc_master.COMID=chartering_estimate_tc_compare.COMID order by chartering_estimate_tc_master.TCOUTID DESC LIMIT 1) as TCOUTID 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.PERIODID=".$aRow['PERIODID']." and chartering_estimate_tc_compare.FINAL_ID!='' and chartering_estimate_tc_master.FIXED=1 GROUP BY chartering_estimate_tc_master.COMID");
			while($rowsbunker   = mysql_fetch_assoc($resultbunker))
			{
				$resultbunker1 = mysql_query("select TC_SLAVE1ID from chartering_tc_estimate_slave1 where TCOUTID=".$rowsbunker['TCOUTID']."");
				while($rowsbunker1   = mysql_fetch_assoc($resultbunker1))
				{
					$resultbunker2 = mysql_query("select QTY from chartering_estimate_tc_slave5 where TC_SLAVE1ID='".$rowsbunker1['TC_SLAVE1ID']."' and IDENTITY='DEL' and BUNKERID='".$rowsload['BUNKERGRADEID']."'");
					$rowsbunker2 = mysql_fetch_assoc($resultbunker2);
					
					$resultbunker3 = mysql_query("select QTY from chartering_estimate_tc_slave5 where TC_SLAVE1ID='".$rowsbunker1['TC_SLAVE1ID']."' and IDENTITY='REDEL' and BUNKERID='".$rowsload['BUNKERGRADEID']."'");
					$rowsbunker3 = mysql_fetch_assoc($resultbunker3);
					$remainingbunker = number_format(($rowsbunker2['QTY'] - $rowsbunker3['QTY']),4,'.','');
				}
			}
			
			$resultbunker = mysql_query("select (select FCAID from freight_cost_estimete_master where freight_cost_estimete_master.COMID=freight_cost_estimate_compare.COMID order by freight_cost_estimete_master.FCAID DESC LIMIT 1) as TOTAL_DAYS 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.PERIODID=".$aRow['PERIODID']." and freight_cost_estimate_compare.FINAL_ID!='' and freight_cost_estimete_master.FIXED=1 GROUP BY freight_cost_estimete_master.COMID");
			while($rowsbunker   = mysql_fetch_assoc($resultbunker))
			{
				$resultbunker1 = mysql_query("select * from freight_cost_estimete_slave8 where IDENTIFY='CONSUMPTION' and FCAID=".$rowsbunker['FCAID']." and BUNKERID=".$rowsload['BUNKERGRADEID']);
				$rowsbunker1   = mysql_fetch_assoc($resultbunker1);
				
				$resultbunker2 = mysql_query("select * from freight_cost_estimete_slave8 where IDENTIFY='SUPPLY' and FCAID=".$rowsbunker['FCAID']." and BUNKERID=".$rowsload['BUNKERGRADEID']);
				$rowsbunker2   = mysql_fetch_assoc($resultbunker2);
				
				$remainingbunker = $remainingbunker + number_format(($rowsbunker2['QTY'] - $rowsbunker1['QTY']),4,'.','');
			}
			
			$closingarray[] = $obj->getBunkerGradeBasedOnID($rowsload['BUNKERGRADEID']).' - '.number_format(($rowsload['BUNKER_QTY'] - $remainingbunker),4,'.','').' MT';
		}
		
		$performeddays = 0;
		$sqltcdays = "select (select TCOUTID from chartering_estimate_tc_master where chartering_estimate_tc_master.COMID=chartering_estimate_tc_compare.COMID order by chartering_estimate_tc_master.TCOUTID DESC LIMIT 1) as TCOUTID 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.PERIODID=".$aRow['PERIODID']." and chartering_estimate_tc_compare.FINAL_ID!='' and chartering_estimate_tc_master.FIXED=1 GROUP BY chartering_estimate_tc_master.COMID";
		$resulttcdays = mysql_query($sqltcdays) or die($sqltcdays);
	    while($rowstcdays   = mysql_fetch_assoc($resulttcdays))
		{
		    $resulttcdays1 = mysql_query("select SUM(TC_DAYS_EST) as SUM from chartering_tc_estimate_slave1 where TCOUTID=".$rowstcdays['TCOUTID']."");
			while($rowstcdays1   = mysql_fetch_assoc($resulttcdays1))
			{
			    $performeddays = $performeddays + $rowstcdays1['SUM'];
			}
		}
		
		$sqltcdays = "select (select TOTAL_DAYS from freight_cost_estimete_master where freight_cost_estimete_master.COMID=freight_cost_estimate_compare.COMID order by freight_cost_estimete_master.FCAID DESC LIMIT 1) as TOTAL_DAYS 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.PERIODID=".$aRow['PERIODID']." and freight_cost_estimate_compare.FINAL_ID!='' and freight_cost_estimete_master.FIXED=1 GROUP BY freight_cost_estimete_master.COMID";
		$resulttcdays = mysql_query($sqltcdays) or die($sqltcdays);
	    while($rowstcdays   = mysql_fetch_assoc($resulttcdays))
		{
		    $performeddays = $performeddays + $rowstcdays['TOTAL_DAYS'];
		}
		
		$details = $details1 = '';
		
		$details = '<strong><a href="#" title="View Details" data-toggle="modal" data-target="#compose-modal" onclick="getListOFEstimate('.$aRow['PERIODID'].','.$i.');"><button type="button" class="btn btn-warning btn-flat">Nominate</button></a></strong>';
		
		$details1 = '<a href="updateperiod_contract.php?id='.$aRow['PERIODID'].'" title="Edit Details" ><i class="fa fa-edit "></i></a>';
		
		if($aRow['UPDATE_STATUS'] == 'Save as Draft')
		{
			$status = '<b><span class="label label-primary">Save as Draft</span></b>';
		}
		else
		{
			$status = '<b><span class="label label-success">Submit to Closed</span></b>';
		}
		
		$aaData[] = array('col1'=>$i.'.', 'col2'=>$aRow['CONTRACT_ID'], 'col3'=>$aRow['CONTRACT_NO'], 'col4'=>date('d-m-Y',strtotime($aRow['CONTRACT_DATE'])), 'col5'=>$aRow['VESSEL_IMO_ID'], 'col6'=>$aRow['OWN_BUSINESS_ACCOUNT'], 'col7'=>$aRow['WORKING_CURRENCY'], 'col8'=>$status, 'col9'=>$details, 'col10'=>$details1, 'col11'=>implode('<br/>',$bunkerarray), 'col12'=>number_format($totaldays,5,'.','').'/<br/>'.$performeddays.'/<br/>'.number_format(($totaldays - $performeddays),5,'.',''), 'col13'=>implode('<br/>',$closingarray));
		
	}
	
	echo json_encode(array("draw"=>intval($_POST['draw']),"recordsTotal"=>$totalData,"recordsFiltered"=>$totalFiltered,"records" => $aaData));
}

function getDaysAfterDate()
{
    $startdate = $_REQUEST['startdate'];
	$txtPeriodMin = $_REQUEST['txtPeriodMin'];
	$txtPeriodMax = $_REQUEST['txtPeriodMax'];
	$monthdaystext = $_REQUEST['monthdaystext'];
	$plusdays = ($_REQUEST['plusdays']=='')?0:$_REQUEST['plusdays'];
	$a = array();
	if($startdate!='' && $txtPeriodMin!='')
	{
	    $redelmindate = date('d-m-Y', strtotime('+'.$txtPeriodMin.' '.$monthdaystext, strtotime($startdate)));
	    if($monthdaystext == "Months")
		{
	    $redelmindate = date('d-m-Y', strtotime('-1 days', strtotime($redelmindate)));
		}
		$redelmindate1 = date('d-m-Y', strtotime('+'.$plusdays.' days', strtotime($redelmindate)));
	    $a['redelmindate'] = $redelmindate;
		$a['redelmindate1'] = $redelmindate1;
	}
	else
	{  
	    $redelmindate = $redelmindate1 = '';
	    $a['redelmindate']= $redelmindate;
		$a['redelmindate1']= $redelmindate1;
	}
	
	if($startdate!='' && $txtPeriodMax!='')
	{
	    $redelmaxdate = date('d-m-Y', strtotime('+'.$txtPeriodMax.' '.$monthdaystext, strtotime($startdate)));
		if($monthdaystext == "Months")
		{
	    $redelmaxdate = date('d-m-Y', strtotime('-1 days', strtotime($redelmaxdate)));
		}
		$redelmaxdate1 = date('d-m-Y', strtotime('+'.$plusdays.' days', strtotime($redelmaxdate)));
	    $a['redelmaxdate'] = $redelmaxdate;
		$a['redelmaxdate1'] = $redelmaxdate1;
	}
	else
	{  
	    $redelmaxdate = $redelmaxdate1 = '';
	    $a['redelmaxdate']= $redelmaxdate;
		$a['redelmaxdate1']= $redelmaxdate1;
	}
	
	echo json_encode($a);
}

function getInitiateSession()
{
session_start();
echo 1;
}

function getLocalPortAPIDetails()
{
    $porttext = $_REQUEST['q'];
    
    $obj 		= new data();
	$connect	= $obj->funConnect();
	
	$json_data = array();
    $query = "select PortId, PortName, PortCode, COUNTRY_KEY, COUNTRY_KEY from port_master where (PortName like '".$porttext."%' or PortCode like '".$porttext."%')";
	$result = mysql_query($query);
	while($rows = mysql_fetch_assoc($result))
	{
	    $json_data[] = array('id' =>$rows['PortId'],	'name' => $rows['PortName'].' ('.$rows['COUNTRY_KEY'].')');
	}
	echo json_encode($json_data);
	
}

function getPortAPIDetails()
{
    $porttext = $_REQUEST['q'];
    
    $obj 		= new data();
	$connect	= $obj->funConnectMysqli();
	
    $url = "https://api-stolt.seametrix.net/api/GetPorts?AccessKey=7oc3y5h2w2f&inText=".str_replace(" ","%20",$porttext);
	
	$opts = array(
	  'http'=>array(
		'method'=>"GET",
		'header'=>"Connection: close\r\n"
	  )
	);
	
	$context = stream_context_create($opts);
	
	$data = file_get_contents($url, false, $context);
	
	
	//echo $data;die;
	//$header = array();
	//$header[] = 'Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5';
	/*$header[] = 'Cache-Control: max-age=0';
	$header[] = 'Connection: keep-alive';
	$header[] = 'Keep-Alive: 300';
	$header[] = 'Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7';
	$header[] = 'Accept-Language: en-us,en;q=0.5';
	$header[] = 'Pragma: ';
	$ch = curl_init(); 
	curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.0.11) Gecko/2009060215 Firefox/3.0.11 (.NET CLR 3.5.30729)');
	curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
	curl_setopt($ch, CURLOPT_AUTOREFERER, true); 
	curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4 );
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
	curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
	curl_setopt($ch, CURLOPT_ENCODING, '');
	curl_setopt($ch, CURLOPT_TIMEOUT, 30);
	curl_setopt($ch, CURLOPT_URL, $url);
	$data = curl_exec($ch);
	curl_close ($ch);*/
    
	$json_data = array();
	$resultdata = json_decode($data, true);
	if($resultdata['resultText']=='Success')
	{
	    foreach($resultdata['ports'] as $resultdata1)
		{
		    $query = "select PortId from port_master where PortName='".$resultdata1['portName']."' and PortCode='".$resultdata1['portCode']."'";
			$result = mysqli_query($connect, $query);
			$num = mysqli_num_rows($result);
			if($num == 0)
			{
		        $sql3 = "insert into port_master (PortName, COUNTRY_KEY, PortCode, STATUS) values ('".$resultdata1['portName']."', '".$resultdata1['country']."', '".$resultdata1['portCode']."', 1)";
				mysqli_query($connect, $sql3) or die($sql3);
				mysqli_query("commit");
				
				$sql1  = "select max(PortId) as max from port_master";
				$res1  = mysqli_query($connect, $sql1) or die($sql1);
				$rows1 = mysqli_fetch_assoc($res1);
				$maxid    = $rows1['max'];
				$json_data[] = array('id' => $maxid,	'name' => $resultdata1['portName'].'('.$resultdata1['country'].')');
				
			}else{
			    $rows = mysqli_fetch_assoc($result);
				$json_data[] = array('id' => $rows['PortId'],	'name' => $resultdata1['portName'].'('.$resultdata1['country'].')');
			}
		}
	}
	echo json_encode($json_data);
	
}

function getDistanceFromSeaMatrixDetails()
{           
    $url = "https://apipro.seametrix.net/api/GetRoutes?AccessKey=7oc3y5h2w2f";
    $obj 		= new data();
    $allowedarea = explode(',',$_REQUEST['AllowedAreas']);
	$allowedarea1 = array();
	for($i=0;$i<count($allowedarea);$i++)
	{
	    $allowedarea1[] = (int)$allowedarea[$i];
	}

	$curl = curl_init($url);
	curl_setopt($curl, CURLOPT_URL, $url);
	curl_setopt($curl, CURLOPT_POST, true);
	curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
	
	$headers = array("Content-Type: application/json");
	curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
	
	$data_arr = array("StartLon" => (int)$_REQUEST['StartLon'],
	"StartLat" => (int)$_REQUEST['StartLat'],     
	"StartPortCode" => $obj->getPortCodeBasedOnID($_REQUEST['StartPortID']),
	"EndLon" => (int)$_REQUEST['EndLon'],
	"EndLat" => (int)$_REQUEST['EndLat'],
	"EndPortCode" => $obj->getPortCodeBasedOnID($_REQUEST['EndPortID']),
	"GreatCircleInterval" => (int)$_REQUEST['GreatCircleInterval'],               
	"AllowedAreas" => $allowedarea1,
	"SecaAvoidance" => (int)$_REQUEST['SecaAvoidance'],          
	"AslCompliance" => (int)$_REQUEST['AslCompliance']);
	
	
	$data = "[".json_encode($data_arr)."]";
	
	curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
	curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
	curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
	
	$resp = curl_exec($curl);
	curl_close($curl);
	echo $resp;
	
}

function getGenericInvoicePaymentDetails()
{
	$obj 		= new data();
	$connect	= $obj->funConnect();
	$invoiceid 	= $_REQUEST['invoiceid'];
	
	$sql 		= "select * from generic_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 getBunkerConsumptionReport()
{
	$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'];
	$selVessel      = $_REQUEST['selVessel'];
	$currency       = 'USD';
	
	echo 
	'<table id="bunker_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">Bunker Data(SOSP)</th>
			<th align="left">Bunker Data(SOSP)</th>
			<th align="left">Consumed(Charterer’s)</th>
			<th align="left">Consumed(Owner’s)</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";}
	if($selVessel!= ''){$subquery1 = " and freight_cost_estimete_master.VESSEL_IMO_ID ='".$selVessel."'";}else{$subquery1 = " ";}

	$sql = "select freight_cost_estimate_compare.COMID, freight_cost_estimete_master.TRANS_DATE, freight_cost_estimate_compare.COAAID 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." ".$subquery1." and date(freight_cost_estimete_master.TRANS_DATE) BETWEEN '".$txtFrom_Date."' and '".$txtTo_Date."' order by freight_cost_estimate_compare.COMID desc";
	
	$res = mysql_query($sql) or die($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->getFun3());
			$coa_spot = '';
			if($obj->getFun175()!='')
			{   
				$coa_spot = 'COA'; 
			}
			else
			{
				$coa_spot = 'Spot'; 
			}
			
			$query11 = "select * from freight_cost_estimate_compare_slave where COMID='".$rows['COMID']."'";
			$res11  = mysql_query($query11);
			$num11 = mysql_num_rows($res11);
			if($num11 > 0)
			{
				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().'<br/><br/><a target="_blank" href="bunker_calculation.php?comid='.$rows['COMID'].'&page=1"><b><i class="fa fa-edit"></i>&nbsp;Bunker Details</B></a></td>';
				echo '<td align="left" valign="middle">'.$obj->getVesselIMOData($obj->getFun5(),"VESSEL_NAME").'</td>';
				echo '<td align="left" valign="middle">'.$coa_spot.'</td>';
				
				$sql2 = "select * from freight_cost_estimete_slave1 where FCAID='".$obj->getFun1()."'";
				$result2 = mysql_query($sql2);$arr_ports = array();
				$num2 = mysql_num_rows($result2);$k = 0;
				while($rows2 = mysql_fetch_assoc($result2))
				{$k++;
					$arr_ports[] = array('portid'=>$rows2['FROM_PORT'],'randomid'=>$rows2['RANDOMID']);
					if($k == $num2)
					{
						$arr_ports[] = array('portid'=>$rows2['TO_PORT'],'randomid'=>$rows2['RANDOMID']);
					}
				}
			  
				$i = 0;$contentprev = $contentlast = '';
				foreach($arr_ports as $arr_ports1)
				{$i++;
				    if($i==1)
					{
						$query1 = "select * from freight_cost_estimate_compare_slave where PORTID='".$arr_ports1['portid']."' and RANDOMID='".$arr_ports1['randomid']."' and COMID='".$rows['COMID']."'";
						$res1  = mysql_query($query1);
						$row1 = mysql_fetch_assoc($res1);
						if(date('d-m-Y', strtotime($row1['ROB_DATE']))=='01-01-1970'){$rob_date = '';}else{$rob_date = date('d-m-Y H:i', strtotime($row1['ROB_DATE']));}
						$contentprev.= '<strong>Date : </strong>'.$rob_date.'<br/>';
						$contentprev.= '<strong>Port : </strong>'.$obj->getPortNameBasedOnID($arr_ports1['portid']).'<br/>';
						
						$query2 = "select * from freight_cost_estimate_compare_slave5 where COMID='".$rows['COMID']."' and ROB_SOSP>0";
						$res2 = mysql_query($query2);
						while($row2 = mysql_fetch_assoc($res2))
						{
							$contentprev.= '<strong>'.$obj->getBunkerGradeBasedOnID($row2['BUNKERID']).' - </strong>MT '.$row2['ROB_SOSP'].', '.$currency.' '.$row2['BUNKER_PRICE'].'<br/>';
						}
					}
					
					if($i == count($arr_ports) && $i>1)
					{
						$query1 = "select * from freight_cost_estimate_compare_slave where PORTID='".$arr_ports1['portid']."' and RANDOMID='".$arr_ports1['randomid']."' and COMID='".$rows['COMID']."'";
						$res1  = mysql_query($query1);
						$row1 = mysql_fetch_assoc($res1);
						if(date('d-m-Y', strtotime($row1['ROB_DATE']))=='01-01-1970'){$rob_date = '';}else{$rob_date = date('d-m-Y H:i', strtotime($row1['ROB_DATE']));}
						$contentlast.= '<strong>Date : </strong>'.$rob_date.'<br/>';
						$contentlast.= '<strong>Port : </strong>'.$obj->getPortNameBasedOnID($arr_ports1['portid']).'<br/>';
						
						$query2 = "select * from freight_cost_estimate_compare_slave2 where COMID='".$rows['COMID']."' and COM_SLAVEID='".$row1['COM_SLAVEID']."' and ROB_SOSP>0";
						$res2 = mysql_query($query2);
						while($row2 = mysql_fetch_assoc($res2))
						{
							$query3 = "select * from freight_cost_estimate_compare_slave3 where COMID='".$rows['COMID']."' and BUNKERID='".$row2['BUNKERID']."'";
							$res3 = mysql_query($query3);
							$row3 = mysql_fetch_assoc($res3);
							$contentlast.= '<strong>'.$obj->getBunkerGradeBasedOnID($row2['BUNKERID']).' - </strong>MT '.$row2['ROB_SOSP'].', '.$currency.' '.$row3['SOSP_VALUE'].'<br/>';
						}
					}
				}
				echo '<td align="left" valign="middle">'.$contentprev.'</td>';
				echo '<td align="left" valign="middle">'.$contentlast.'</td>';
				$content1 = '';
				$query4 = "select * from freight_cost_estimate_compare_slave4 where COMID='".$rows['COMID']."' and CONSUMEDON='CHARTERER'";
				$res4 = mysql_query($query4);
				$num4 = mysql_num_rows($res4);
				while($row4 = mysql_fetch_assoc($res4))
				{
					$content1.= '<strong>'.$obj->getBunkerGradeBasedOnID($row4['BUNKERID']).' - </strong>MT '.$row4['QTY_USER'].', '.$currency.' '.$row4['USED_AMT'].'<br/>';
				}
				echo '<td align="left" valign="middle">'.$content1.'</td>';
				$content2 = '';
				$query4 = "select * from freight_cost_estimate_compare_slave4 where COMID='".$rows['COMID']."' and CONSUMEDON='OWNER'";
				$res4 = mysql_query($query4);
				$num4 = mysql_num_rows($res4);
				while($row4 = mysql_fetch_assoc($res4))
				{
					$content2.= '<strong>'.$obj->getBunkerGradeBasedOnID($row4['BUNKERID']).' - </strong>MT '.$row4['QTY_USER'].', '.$currency.' '.$row4['USED_AMT'].'<br/>';
				}
				echo '<td align="left" valign="middle">'.$content2.'</td>';
				echo '</tr>';
						
				$j++;
			}
			
		}
	}
	
	echo '</tbody>';
	echo '</table>';
}


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, LOAD_PORT, DISCHARGE_PORT, (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 = '';
		
		$resultload = mysql_query("select GROUP_CONCAT(PortName) as PORTNAME from port_master where PortId in (".$rows['LOAD_PORT'].")");
	    $rowsload   = mysql_fetch_assoc($resultload);
		
		$resultdis = mysql_query("select GROUP_CONCAT(PortName) as PORTNAME from port_master where PortId in (".$rows['DISCHARGE_PORT'].")");
	    $rowsdis   = mysql_fetch_assoc($resultdis);
		
		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'=>$rowsload['PORTNAME'],'DISCHARGE_PORT'=>$rowsdis['PORTNAME'],'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, LOAD_PORT, DISCHARGE_PORT, (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))
	{
	    $sqlload = "select GROUP_CONCAT(PortName) as PORTNAME from port_master where PortId in (".$rows['LOAD_PORT'].")";
	    $resultload = mysql_query($sqlload) or die($sqlload);
	    $rowsload   = mysql_fetch_assoc($resultload);
		
		$sqldis = "select GROUP_CONCAT(PortName) as PORTNAME from port_master where PortId in (".$rows['DISCHARGE_PORT'].")";
		$resultdis = mysql_query($sqldis) or die($sqldis);
	    $rowsdis   = mysql_fetch_assoc($resultdis);
		
	    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>';
			
			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">'.$rowsload['PORTNAME'].'</td>';
			echo '<td align="left" valign="right" class="input-text">'.$rowsdis['PORTNAME'].'</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>';
			
			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">'.$rowsload['PORTNAME'].'</td>';
			echo '<td align="left" valign="right" class="input-text">'.$rowsdis['PORTNAME'].'</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>';
			
			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">'.$rowsload['PORTNAME'].'</td>';
			echo '<td align="left" valign="right" class="input-text">'.$rowsdis['PORTNAME'].'</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", "WS_RDO_TEXT1", "CHARTERERNAME", "OWNERNAME", "COASPOT", "CARGORELET");
	}
	if($_POST['businesstype']==2)
	{
		$aColumns = array("CPID", "COA_DATE", "CARGONAME", "CARGOSTEAMSIZE", "WS_RDO_TEXT", "CHARTERERNAME", "OWNERNAME", "COASPOT", "CARGORELET");
	}
	if($_POST['businesstype']==3)
	{
		$aColumns = array("CPID", "COA_DATE", "CARGONAME", "CARGOSTEAMSIZE", "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 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 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 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']."' and MCOMPANYID='".$_SESSION['company']."'";
		}else{
			$sWhere.= " where BUSINESSTYPEID='".$_POST['businesstype']."' and MCOMPANYID='".$_SESSION['company']."'";
		}
	}
	
	$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, LOAD_PORT, DISCHARGE_PORT, (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 where  MCOMPANYID='".$_SESSION['company']."'";
	$rResultTotal = mysql_query($sQuery);
	$aResultTotal = mysql_fetch_array($rResultTotal);
	$totalFiltered = $totalData = $aResultTotal[0];
	
	$aaData = array();
	$i = $_POST['start'];
	while ( $aRow = mysql_fetch_array( $rResult ) )
	{
	    $resultload = mysql_query("select GROUP_CONCAT(PortName) as PORTNAME from port_master where PortId in (".$aRow['LOAD_PORT'].")");
	    $rowsload   = mysql_fetch_assoc($resultload);
		
		$resultdis = mysql_query("select GROUP_CONCAT(PortName) as PORTNAME from port_master where PortId in (".$aRow['DISCHARGE_PORT'].")");
	    $rowsdis   = mysql_fetch_assoc($resultdis);
		
		$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'=>$rowsload['PORTNAME'], 'col6'=>$rowsdis['PORTNAME'], '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);
	
	$loadportjson = $disportjson = array();
	$resultload = mysql_query("select PortName, PortId from port_master where PortId in (".$rowscoa['LOAD_PORT'].")");
	while($rowsload   = mysql_fetch_assoc($resultload))
	{
		$loadportjson[] = array('id'=>$rowsload['PortId'], 'name'=>$rowsload['PortName']);
	}
	
	$resultdis = mysql_query("select PortName, PortId from port_master where PortId in (".$rowscoa['DISCHARGE_PORT'].")");
	while($rowsdis   = mysql_fetch_assoc($resultdis))
	{
		$disportjson[] = array('id'=>$rowsdis['PortId'], 'name'=>$rowsdis['PortName']);
	}
	
	
	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'],'LOAD_PORT_TEXT'=>$loadportjson,'DISCHARGE_PORT_TEXT'=>$disportjson));
}

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'];
	
	if($_SESSION['iutype']=='mgmt_user'){$styledisplay = '';$colspan=6;}else{$styledisplay = 'display:none;';$colspan=5;}
	
	$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="'.$colspan.'" align="left" valign="top" width="10%">Initial&nbsp;P&nbsp;&&nbsp;L</th>
				<th colspan="'.$colspan.'" 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%" style="'.$styledisplay.'">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%" style="'.$styledisplay.'">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" style="'.$styledisplay.'">'.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" style="'.$styledisplay.'">'.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=='')
	{
		$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.DEL_DATE as DEL_DATE, chartering_estimate_tc_master.RE_DEL_DATE as RE_DEL_DATE, chartering_estimate_tc_master.CP_DATE1, 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 chartering_estimate_tc_master.ESTIMATE_TYPE='".$selBType."' and chartering_estimate_tc_compare.STATUS in(1) 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']."' and date(INVOICE_DATE)>='".date('Y-m-d',strtotime($txtFromDate))."' and date(INVOICE_DATE)<='".date('Y-m-d',strtotime($txtToDate))."' and STATUS<=5 ";
		$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<=5 and date(INVOICE_DATE)>='".date('Y-m-d',strtotime($txtFromDate))."' and date(INVOICE_DATE)<='".date('Y-m-d',strtotime($txtToDate))."'";
		$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 >1000)
			{
				$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, NET_PAYABLE_TAX as SUM2, RANDOMID, HIRE_DAYS, OLD_EXCHANGE_RATE from invoice_tchire_master where COMID='".$rows['COMID']."' and STATUS<=5 and date(INVOICE_DATE)>='".date('Y-m-d',strtotime($txtFromDate))."' and date(INVOICE_DATE)<='".date('Y-m-d',strtotime($txtToDate))."'";
		$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>100)
			{
				$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['TC_NO'].')','amount'=>number_format($hiretamt,2,'.',''));
			}
		}
		
		if(date('d-m-Y',strtotime($rows['DEL_DATE']))!='01-01-1970'){$deliverydate = date('d-m-Y',strtotime($rows['DEL_DATE']));}else{$deliverydate = '';}
		if(date('d-m-Y',strtotime($rows['RE_DEL_DATE']))!='01-01-1970'){$redeliverydate = date('d-m-Y',strtotime($rows['RE_DEL_DATE']));}else{$redeliverydate = '';}
		
		$sqlhire = "select count(*) as count from invoice_hiretc_master where COMID='".$rows['COMID']."' and INVOICE_TYPE ='Final'";
		$resulthire = mysql_query($sqlhire) or die($sqlhire);
		$rowshire = mysql_fetch_assoc($resulthire);
		
		if($rowshire['count']==0)
		{
			$arr_data[] = array('TCno'=>$rows['TC_NO'], 'vessel'=>$obj->getVesselIMOData($rows['VESSEL_IMO_ID'],"VESSEL_NAME"),'fixture'=>number_format($freightgross,2,'.',''),'Interim'=>number_format($interim,2,'.',''),'completion'=>number_format($completion,2,'.',''),'fixcolor'=>'#86a948','intrimgrey'=>'#999898','completeblue'=>'#367fa9', 'delredeldate'=>$deliverydate.' - '.$redeliverydate, 'cp_date'=>date('d-m-Y',strtotime($rows['CP_DATE1'])),'cpdatestr'=>strtotime($rows['CP_DATE1']));
		}
	}
	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'];	
	
	$sql = "select * from invoice_tchire_master where INVOICEID='".$invoiceid."'";
	$result = mysql_query($sql);
	while($rows = mysql_fetch_assoc($result))
	{
	
	    $obj->saveRecentWork($rows['INVOICE_TYPE']." Hire Invoice (".$rows['INVOICE_NO'].") Cancelled Successfully.");
		
		$sql_insert = "insert into invoice_tchire_master(COMID, MODULEID, MCOMPANYID, INVOICE_DATE, INVOICE_TYPE, INVOICE_NO, EXCHANGE_RATE, EXCHANGE_CURRENCY, PAYMENT_TERMS, DESCRIPTION, BANKINGID, DUE_DATE, HIRE_FROM_DATE, HIRE_TO_DATE, HIRE_DAYS, HIRE_INV_AMT, BALANCE_TO_OWNER, FINAL_AMOUNT, STATUS, SHIP_OWNER, ATTEN, RANDOMID, EXCHANGE_DATE, P_DATE, P_AMT, P_REMARKS, ATTACHMENTS, ATTACHMENTS_NAME, OLD_EXCHANGE_RATE, OLD_EXCHANGE_CURRENCY, OLD_DAILY_HIRE_RATE, CVE_MONTH, CVE_AMOUNT, ADDRESS_COMMISSION, ADDRESS_COMMISSION_AMOUNT, BROKER_COMMISSION, BROKER_COMMISSION_AMOUNT, IS_OFFHIRE, CVE_OFFHIRE_MONTH, CVE_OFFHIRE_AMOUNT, IS_DELIVERYBUNKERS, IS_REDELIVERYBUNKERS, RDOTAXAPPLICABLE, RDOVATGST, SGST_PERCENT, CGST_PERCENT, IGST_PERCENT, VAT_PERCENT, NET_PAYABLE_TAX, SGST_PERCENT_AMOUNT, CGST_PERCENT_AMOUNT, IGST_PERCENT_AMOUNT, VAT_PERCENT_AMOUNT, APPROVERS, CREATOR, UPLOAD, UPLOAD_NAME, CHK_BALLAST_BONUS, CHK_OVERCONSP) value('".$rows['COMID']."', '".$rows['MODULEID']."', '".$rows['MCOMPANYID']."', '".$rows['INVOICE_DATE']."', 'Credit', '".$rows['INVOICE_NO']."', '".$rows['EXCHANGE_RATE']."', '".$rows['EXCHANGE_CURRENCY']."', '".addslashes($rows['PAYMENT_TERMS'])."', '".addslashes($rows['DESCRIPTION'])."', '".$rows['BANKINGID']."', '".$rows['DUE_DATE']."', '".$rows['HIRE_FROM_DATE']."', '".$rows['HIRE_TO_DATE']."', '".$rows['HIRE_DAYS']."', '".$rows['HIRE_INV_AMT']."', '".$rows['BALANCE_TO_OWNER']."', '".$rows['FINAL_AMOUNT']."', '8', '".$rows['SHIP_OWNER']."', '".addslashes($rows['ATTEN'])."', '".$rows['RANDOMID']."', '".$rows['EXCHANGE_DATE']."', '".$rows['P_DATE']."', '".$rows['P_AMT']."', '".addslashes($rows['P_REMARKS'])."', '".addslashes($rows['ATTACHMENTS'])."', '".addslashes($rows['ATTACHMENTS_NAME'])."', '".$rows['OLD_EXCHANGE_RATE']."', '".$rows['OLD_EXCHANGE_CURRENCY']."', '".$rows['OLD_DAILY_HIRE_RATE']."', '".$rows['CVE_MONTH']."', '".$rows['CVE_AMOUNT']."', '".$rows['ADDRESS_COMMISSION']."', '".$rows['ADDRESS_COMMISSION_AMOUNT']."', '".$rows['BROKER_COMMISSION']."', '".$rows['BROKER_COMMISSION_AMOUNT']."', '".$rows['IS_OFFHIRE']."', '".$rows['CVE_OFFHIRE_MONTH']."', '".$rows['CVE_OFFHIRE_AMOUNT']."', '".$rows['IS_DELIVERYBUNKERS']."', '".$rows['IS_REDELIVERYBUNKERS']."', '".$rows['RDOTAXAPPLICABLE']."', '".$rows['RDOVATGST']."', '".$rows['SGST_PERCENT']."', '".$rows['CGST_PERCENT']."', '".$rows['IGST_PERCENT']."', '".$rows['VAT_PERCENT']."', '".$rows['NET_PAYABLE_TAX']."', '".$rows['SGST_PERCENT_AMOUNT']."', '".$rows['CGST_PERCENT_AMOUNT']."', '".$rows['IGST_PERCENT_AMOUNT']."', '".$rows['VAT_PERCENT_AMOUNT']."', '".$rows['APPROVERS']."', '".$rows['CREATOR']."', '".$rows['UPLOAD']."', '".$rows['UPLOAD_NAME']."', '".$rows['CHK_BALLAST_BONUS']."', '".$rows['CHK_OVERCONSP']."')";
		mysql_query($sql_insert) or die($sql_insert);
		
		$sql_max = "select max(INVOICEID) as max from invoice_tchire_master";
		$res_max = mysql_query($sql_max);
		$rows_max = mysql_fetch_assoc($res_max);
		
		$sql1 = "select * from invoice_tchire_slave1 where INVOICEID='".$invoiceid."'";
		$result1 = mysql_query($sql1);
		while($rows1 = mysql_fetch_assoc($result1))
		{
		    $sql_isert2 = "insert into invoice_tchire_slave1 (INVOICEID, DESCRIPTION, AMOUNT, IDENTIFY) value ('".$rows_max['max']."', '".addslashes($rows1['DESCRIPTION'])."', '".$rows1['AMOUNT']."', '".$rows1['IDENTIFY']."')";
			mysql_query($sql_isert2);
		}
		
		$sql1 = "select * from invoice_tchire_slave2 where INVOICEID='".$invoiceid."'";
		$result1 = mysql_query($sql1);
		while($rows1 = mysql_fetch_assoc($result1))
		{
		    $sql_isert2 = "insert into invoice_tchire_slave2 (INVOICEID, BUNKERID, BUNKER_QTY, BUNKER_PRICE, BUNKER_PER, BUNKER_AMT, IDENTIFY, BUNKER_PER_AMT) value ('".$rows_max['max']."', '".$rows1['BUNKERID']."', '".$rows1['BUNKER_QTY']."', '".$rows1['BUNKER_PRICE']."', '".$rows1['BUNKER_PER']."', '".$rows1['BUNKER_AMT']."', '".$rows1['IDENTIFY']."', '".$rows1['BUNKER_PER_AMT']."')";
			mysql_query($sql_isert2);
		}
		
		$sql1 = "select * from invoice_tchire_slave3 where INVOICEID='".$invoiceid."'";
		$result1 = mysql_query($sql1);
		while($rows1 = mysql_fetch_assoc($result1))
		{
		    $sql_isert2 = "insert into invoice_tchire_slave3 (INVOICEID, INVOICEID, OFFHIRE_REASON, FROM_OFF_DATE, TO_OFF_DATE, OFFHIRE_DAYS) value ('".$rows_max['max']."', '".addslashes($rows1['OFFHIRE_REASON'])."', '".$rows1['FROM_OFF_DATE']."', '".$rows1['TO_OFF_DATE']."', '".$rows1['OFFHIRE_DAYS']."')";
			mysql_query($sql_isert2);
		}
		
		
		$sql1 = "select * from invoice_tchire_slave4 where INVOICEID='".$invoiceid."'";
		$result1 = mysql_query($sql1);
		while($rows1 = mysql_fetch_assoc($result1))
		{
		    $sql_isert2 = "insert into invoice_tchire_slave4 (INVOICEID, OFF_REASON, OFF_FROM, OFF_TO, OFF_HIRE_PERCENT, OFF_DAYS, OFF_HIRE) value ('".$rows_max['max']."', '".addslashes($rows1['OFF_REASON'])."', '".$rows1['OFF_FROM']."', '".$rows1['OFF_TO']."', '".$rows1['OFF_HIRE_PERCENT']."', '".$rows1['OFF_DAYS']."', '".$rows1['OFF_HIRE']."')";
			mysql_query($sql_isert2);
			
			
			$sql_maxslave = "select max(INVOICE_SLAVE4ID) as max from invoice_tchire_slave4";
			$res_maxslave = mysql_query($sql_maxslave);
			$rows_maxslave = mysql_fetch_assoc($res_maxslave);
			
			$sql3 = "select * from invoice_tchire_slave41 where INVOICEID='".$invoiceid."' and INVOICE_SLAVE4ID='".$rows1['INVOICE_SLAVE4ID']."'";
			$result3 = mysql_query($sql3);
			while($rows3 = mysql_fetch_assoc($result3))
			{
				$sql_isert4 = "insert into invoice_tchire_slave41 (INVOICE_SLAVE4ID, INVOICEID, BUNKERID, BUNKER_QTY, BUNKER_PRICE, BUNKER_AMT) value ('".$rows_maxslave['max']."', '".$rows_max['max']."', '".addslashes($rows3['BUNKERID'])."', '".$rows3['BUNKER_QTY']."', '".$rows3['BUNKER_PRICE']."', '".$rows3['BUNKER_AMT']."')";
				mysql_query($sql_isert4);
			}
		}
		
		$sql2 = "update invoice_tchire_master set STATUS=8 where INVOICEID='".$invoiceid."'";
	    mysql_query($sql2);
	}
	
	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=='')
	{
		$txtToDate      =  date('Y-m-d',time());
		$txtFromDate    =  date('Y-m-d', strtotime('-3 months'));
	}
	
	$sql = "select freight_cost_estimate_compare.COMID as COMID, freight_cost_estimete_master.VESSEL_IMO_ID as VESSEL_IMO_ID, freight_cost_estimete_master.VESSEL_IMO_ID as VESSEL_IMO_ID, freight_cost_estimete_master.VOYAGE_NO as VOYAGE_NO, freight_cost_estimete_master.TRANS_DATE as TRANS_DATE, freight_cost_estimete_master.FIXTURETYPEID as FIXTURETYPEID, freight_cost_estimete_master.PERIODID as PERIODID 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) 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 = $sumfreightAmt1 = 0;
	$arr_freight = array();
	while($rows = mysql_fetch_assoc($res))
	{
		$sql_dem = "select (select SUM(DEM_AMT) from freight_invoice_slave3 where freight_invoice_slave3.INVOICEID=freight_invoice_master.INVOICEID) as DEM_AMT, freight_invoice_master.VENDOR as VENDOR from freight_invoice_master where COMID='".$rows['COMID']."' and date(DATE)>='".date('Y-m-d',strtotime($txtFromDate))."' and date(DATE)<='".date('Y-m-d',strtotime($txtToDate))."' and (P_AMT is NULL or P_AMT='') and (select count(*) from freight_invoice_slave3 where freight_invoice_slave3.INVOICEID=freight_invoice_master.INVOICEID)>0 and STATUS=5";
		
		$result_dem = mysql_query($sql_dem) or die($sql_dem);
		$rows_dem = mysql_fetch_assoc($result_dem);
		
		/*$sql_dem1 = "select (select SUM(DEM_AMT) from freight_invoice_slave3 where freight_invoice_slave3.INVOICEID=freight_invoice_master.INVOICEID) as DEM_AMT from freight_invoice_master where COMID='".$rows['COMID']."' and date(DATE)>='".date('Y-m-d',strtotime($txtFromDate))."' and date(DATE)<='".date('Y-m-d',strtotime($txtToDate))."' and (P_AMT is NULL or P_AMT='') and (select count(*) from freight_invoice_slave3 where freight_invoice_slave3.INVOICEID=freight_invoice_master.INVOICEID)>0 and STATUS=5";
		
		$result_dem1 = mysql_query($sql_dem) or die($sql_dem1);
		$rows_dem1 = mysql_fetch_assoc($result_dem1);*/
		
		if($rows_dem['DEM_AMT']>0)
		{
			$sumdum = $sumdum + 1;
			$sumdumAmt = $sumdumAmt + number_format($rows_dem['DEM_AMT'],2,'.','');
			
			$vendorarr = $obj->getVendorListNewBasedOnID($rows_dem['VENDOR']);
				
			
			$arr_dumm[] = array('vessel'=>$obj->getVesselIMOData($rows['VESSEL_IMO_ID'],"VESSEL_NAME"),'voyage'=>$rows['VOYAGE_NO'],'charterer'=>$vendorarr,'dummerage'=>number_format($rows_dem['DEM_AMT'],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, FCAID 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']."' and date(DATE)>='".date('Y-m-d',strtotime($txtFromDate))."' and date(DATE)<='".date('Y-m-d',strtotime($txtToDate))."' and STATUS<=5 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_TAX) as SUM2 from freight_invoice_master where COMID='".$rows['COMID']."' and date(DATE)>='".date('Y-m-d',strtotime($txtFromDate))."' and date(DATE)<='".date('Y-m-d',strtotime($txtToDate))."' and STATUS=5 and I_TYPE='Interim' order by COMID desc";
		$result5 = mysql_query($sql5) or die($sql5);
		$rows5 = mysql_fetch_assoc($result5);
		
		$freightamt = $rows5['SUM2'] - $rows5['SUM'];
		
		$sql51 = "select sum(P_AMT) as SUM, sum(NET_PAYABLE_TAX) as SUM2 from freight_invoice_master where COMID='".$rows['COMID']."' and date(DATE)>='".date('Y-m-d',strtotime($txtFromDate))."' and date(DATE)<='".date('Y-m-d',strtotime($txtToDate))."' and STATUS=5 and I_TYPE='Final' order by COMID desc";
		$result51 = mysql_query($sql51) or die($sql51);
		$rows51 = mysql_fetch_assoc($result51);
		
		$freightamt = $rows5['SUM2'] - $rows5['SUM'];
		$freightamt1 = $rows51['SUM2'] - $rows51['SUM'];
		
		if($freightamt>1000 || $freightamt1>1000)
		{
			$sumfreight = $sumfreight + 1;
			$sumfreightAmt = $sumfreightAmt + $freightamt;
			
			$sumfreightAmt1 = $sumfreightAmt1 + $freightamt1;
			
			$vendorarr = array();
			$sql6 = "select DISTINCT VENDOR from freight_invoice_master where COMID='".$rows['COMID']."' and date(DATE)>='".date('Y-m-d',strtotime($txtFromDate))."' and date(DATE)<='".date('Y-m-d',strtotime($txtToDate))."' and STATUS=5 and (I_TYPE='Interim' or I_TYPE='Final') order by COMID desc";
			$result6 = mysql_query($sql6) or die($sql6);
			while($rows6 = mysql_fetch_assoc($result6))
			{
			    $vendorarr[] = $obj->getVendorListNewBasedOnID($rows6['VENDOR']);
			}			
			
			$arr_freight[] = array('vessel'=>$obj->getVesselIMOData($rows['VESSEL_IMO_ID'],"VESSEL_NAME"),'voyage'=>$rows['VOYAGE_NO'],'charterer'=>implode(', ',$vendorarr),'freight'=>number_format($freightamt,2,'.',''),'freight1'=>number_format($freightamt1,2,'.',''));
		}
		
		$queryperiod = "SELECT * FROM period_contract_master where PERIODID='".$rows['PERIODID']."'"; 
	    $resultperiod = mysql_query($queryperiod);
	    $rowsperiod = mysql_fetch_assoc($resultperiod);
		if(date('d-m-Y',strtotime($rowsperiod['DELIVERY_DATE']))!='01-01-1970'){$deliverydate = date('d-m-Y',strtotime($rowsperiod['DELIVERY_DATE']));}else{$deliverydate = '';}
		if(date('d-m-Y',strtotime($rowsperiod['RE_DEL_MAX_DATE']))!='01-01-1970'){$redeliverydate = date('d-m-Y',strtotime($rowsperiod['RE_DEL_MAX_DATE']));}else{$redeliverydate = '';}
		
		$sqlhire = "select count(*) as count from invoice_hire_master where COMID='".$rows['COMID']."' and INVOICE_TYPE ='Final'";
		$resulthire = mysql_query($sqlhire) or die($sqlhire);
		$rowshire = mysql_fetch_assoc($resulthire);
		
		if($rowshire['count']==0)
		{
		    $arrports  = $obj->getLoadPortAndDischargePortArrBasedOnCommidAndProcessWithoutTBN($rows['COMID'],$rows3['FCAID']);
			$lp_name = array(); 
			$dp_name = array();
			$discharge_port = "";
			
			for($j=0;$j<count($arrports);$j++)
			{   
				$arr_explode = explode('@@',$arrports[$j]);
				if($arr_explode[0] == "LP"){$lp_name[]= explode('/',$obj->getPortNameBasedOnID($arr_explode[1]))[0];}
				if($arr_explode[0] == "DP"){$dp_name[]= explode('/',$obj->getPortNameBasedOnID($arr_explode[1]))[0];}
			}
			
			$lp_name  = implode(', ',$lp_name);
			$dp_name  = implode(', ',$dp_name);
		
			$arr_data[] = array('vessel'=>$obj->getVesselIMOData($rows['VESSEL_IMO_ID'],"VESSEL_NAME"),'fixture'=>number_format($freightgross,2,'.',''),'Interim'=>number_format($interim,2,'.',''),'completion'=>number_format($completion,2,'.',''),'fixcolor'=>'#86a948','intrimgrey'=>'#999898','completeblue'=>'#367fa9','voyageno'=>$rows['VOYAGE_NO'],'cpdate'=>date('d-m-Y',strtotime($rows['TRANS_DATE'])),'cpdatestr'=>strtotime($rows['TRANS_DATE']),'voyage'=>strtoupper($lp_name).' / '.strtoupper($dp_name), 'delredeldate'=>$deliverydate.' - '.$redeliverydate);
		}
	}
	
	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,'.','')."@@@".number_format($sumfreightAmt1,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>';
	
	if($_SESSION['iutype']=='mgmt_user')
	{
	
		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']));
	
	if($_SESSION['iutype']=='mgmt_user'){$styledisplay = '';$colspan=8;}else{$styledisplay = 'display:none;';$colspan=7;}
	
	$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_estimete_master.CARGO_ID, freight_cost_estimete_master.TANKER_RADIO_SINGLE_DIS, 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="'.$colspan.'" align="left" valign="top" width="10%">Initial&nbsp;P&nbsp;&&nbsp;L</th>
				<th colspan="'.$colspan.'" 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%" style="'.$styledisplay.'">&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%" style="'.$styledisplay.'">&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'],"TRANS_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($rows['CARGO_ID']).'</td>';
			echo '<td align="left" valign="middle">'.$cpdate.'</td>';
			echo '<td align="left" valign="middle">'.$obj->getCompanyNameBasedOnID($_SESSION['company'],"COMPANY_NAME").'</td>';
			$charterers = '';
			if($obj->getCompareEstimateData($rows['COMID'],"ESTIMATE_TYPE")==3 && $obj->getCompareEstimateData($rows['COMID'],"QTY_TYPE_RADIO") == 2)
			{
				$vendor_arr = array();
				$sql12 = "select QTY_VENDORID from freight_cost_estimete_slave7 where FCAID='".$obj->getCompareEstimateData($rows['COMID'],"FCAID")."' group by QTY_VENDORID";
				$res12 = mysql_query($sql12);
				while($row12 = mysql_fetch_assoc($res12))
				{
					$vendor_arr[]  = $obj->getVendorListNewBasedOnID($row12['QTY_VENDORID']);
				}
				$charterers = implode(',', $vendor_arr);
			}
			else
			{
				$charterers = $obj->getVendorListNewBasedOnID($obj->getCompareEstimateData($rows['COMID'],"FGFF_VENDORID"));
			}
			echo '<td align="left" valign="middle">'.$charterers.'</td>';
			echo '<td align="left" valign="middle">'.$fixturedate.'</td>';
			
			$res14 = mysql_query("select FCAID, PROFIT_LOSS, ACTUAL_PL, 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['ACTUAL_PL'];
					$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['ACTUAL_PL'];
					$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" style="'.$styledisplay.'">'.$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" style="'.$styledisplay.'">'.$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']));
	
	if($_SESSION['iutype']=='mgmt_user'){$styledisplay = '';$colspan=8;}else{$styledisplay = 'display:none;';$colspan=7;}
	
	$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_estimete_master.CARGO_ID, freight_cost_estimete_master.TANKER_RADIO_SINGLE_DIS, 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%" style="'.$styledisplay.'">Initial&nbsp;P&nbsp;&&nbsp;L</th>
			<th align="left" valign="top" width="10%" style="'.$styledisplay.'">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'],"TRANS_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($rows['CARGO_ID']).'</td>';
			echo '<td align="left" valign="middle">'.$cpdate.'</td>';
			echo '<td align="left" valign="middle">'.$obj->getCompanyNameBasedOnID($_SESSION['company'],"COMPANY_NAME").'</td>';
			
			$charterers = '';
			if($obj->getCompareEstimateData($rows['COMID'],"ESTIMATE_TYPE")==3 && $obj->getCompareEstimateData($rows['COMID'],"QTY_TYPE_RADIO") == 2)
			{
				$vendor_arr = array();
				$sql12 = "select QTY_VENDORID from freight_cost_estimete_slave7 where FCAID='".$obj->getCompareEstimateData($rows['COMID'],"FCAID")."' group by QTY_VENDORID";
				$res12 = mysql_query($sql12);
				while($row12 = mysql_fetch_assoc($res12))
				{
					$vendor_arr[]  = $obj->getVendorListNewBasedOnID($row12['QTY_VENDORID']);
				}
				$charterers = implode(',', $vendor_arr);
			}
			else
			{
				$charterers = $obj->getVendorListNewBasedOnID($obj->getCompareEstimateData($rows['COMID'],"FGFF_VENDORID"));
			}
			
			echo '<td align="left" valign="middle">'.$charterers.'</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, ACTUAL_PL 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['ACTUAL_PL'];
				}
				else
				{
					$last = $row14['ACTUAL_PL'];
				}
				$i = $i + 1;
			}
			echo '<td align="left" valign="middle" style="'.$styledisplay.'">'.$first.'</td>';
			echo '<td align="left" valign="middle" style="'.$styledisplay.'">'.$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><th align="center" valign="middle" width="50%">ESTIMATED</th><th colspan="2" align="center" valign="middle" width="50%">ACTUAL</th></tr>';
	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>';
	
	if($_SESSION['iutype']=='mgmt_user')
	{
		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).'"><strong>SPEED DATA</strong></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).'"><strong>FO Consp/day(MT) - At Sea</strong></td>';
	echo '</tr>';
	
	$arr_level = array('SECA (Ballast) - Full Speed', 'SECA (Laden) - Full Speed', 'NON-SECA (Ballast) - Full Speed', 'NON-SECA (Laden) - Full Speed', 'SECA (Ballast) - Service Speed', 'SECA (Laden) - Service Speed', 'NON-SECA (Ballast) - Service Speed', 'NON-SECA (Laden) - Service Speed', 'SECA (Ballast) - Most Eco Speed', 'SECA (Laden) - Most Eco Speed', 'NON-SECA (Ballast) - Most Eco Speed', 'NON-SECA (Laden) - Most Eco Speed');
	$arr_fields = array('FO_BALAST_ATSEA_SECA_CONSP_FS', 'FO_LADEN_ATSEA_SECA_CONSP_FS', 'FO_BALAST_ATSEA_NONSECA_CONSP_FS', 'FO_LADEN_ATSEA_NONSECA_CONSP_FS', 'FO_BALAST_ATSEA_SECA_CONSP_SS', 'FO_LADEN_ATSEA_SECA_CONSP_SS', 'FO_BALAST_ATSEA_NONSECA_CONSP_SS', 'FO_LADEN_ATSEA_NONSECA_CONSP_SS', 'FO_BALAST_ATSEA_SECA_CONSP_MES', 'FO_LADEN_ATSEA_SECA_CONSP_MES', 'FO_BALAST_ATSEA_NONSECA_CONSP_MES', 'FO_LADEN_ATSEA_NONSECA_CONSP_MES');
	
	for($j=0;$j<count($arr_level);$j++)
	{
		echo '<tr>';
		echo '<td align="center">'.$arr_level[$j].'</td>';
		for($i=0;$i<count($chkArr1);$i++)
		{
		    $sql = "select ".$arr_fields[$j].", BUNKERID from vessel_commercial_parameters_slave1 where IDENTIFY='FO' and COMMERCIAL_PARAMETERID=".$obj->getVesselParameterData($chkArr1[$i],"COMMERCIAL_PARAMETERID");
		    $result = mysql_query($sql);
		    $bunker_consp = array();
			while($rows = mysql_fetch_assoc($result))
			{
			    $bunker_consp[] = $obj->getBunkerGradeBasedOnID($rows['BUNKERID']).' - '.$rows[$arr_fields[$j]];
			}
			echo '<td align="center">'.implode(', ',$bunker_consp).'</td>';
		}
		echo '</tr>';
	}
	
	
	echo '<tr>';
	echo '<td align="center" colspan="'.(count($chkArr1) + 1).'"><strong>DO Consp/day(MT) - At Sea</strong></td>';
	echo '</tr>';
	
	$arr_level = array('SECA (Ballast) - Full Speed', 'SECA (Laden) - Full Speed', 'NON-SECA (Ballast) - Full Speed', 'NON-SECA (Laden) - Full Speed', 'SECA (Ballast) - Service Speed', 'SECA (Laden) - Service Speed', 'NON-SECA (Ballast) - Service Speed', 'NON-SECA (Laden) - Service Speed', 'SECA (Ballast) - Most Eco Speed', 'SECA (Laden) - Most Eco Speed', 'NON-SECA (Ballast) - Most Eco Speed', 'NON-SECA (Laden) - Most Eco Speed');
	$arr_fields = array('FO_BALAST_ATSEA_SECA_CONSP_FS', 'FO_LADEN_ATSEA_SECA_CONSP_FS', 'FO_BALAST_ATSEA_NONSECA_CONSP_FS', 'FO_LADEN_ATSEA_NONSECA_CONSP_FS', 'FO_BALAST_ATSEA_SECA_CONSP_SS', 'FO_LADEN_ATSEA_SECA_CONSP_SS', 'FO_BALAST_ATSEA_NONSECA_CONSP_SS', 'FO_LADEN_ATSEA_NONSECA_CONSP_SS', 'FO_BALAST_ATSEA_SECA_CONSP_MES', 'FO_LADEN_ATSEA_SECA_CONSP_MES', 'FO_BALAST_ATSEA_NONSECA_CONSP_MES', 'FO_LADEN_ATSEA_NONSECA_CONSP_MES');
	
	for($j=0;$j<count($arr_level);$j++)
	{
		echo '<tr>';
		echo '<td align="center">'.$arr_level[$j].'</td>';
		for($i=0;$i<count($chkArr1);$i++)
		{
		    $sql = "select ".$arr_fields[$j].", BUNKERID from vessel_commercial_parameters_slave1 where IDENTIFY='DO' and COMMERCIAL_PARAMETERID=".$obj->getVesselParameterData($chkArr1[$i],"COMMERCIAL_PARAMETERID");
		    $result = mysql_query($sql);
		    $bunker_consp = array();
			while($rows = mysql_fetch_assoc($result))
			{
			    $bunker_consp[] = $obj->getBunkerGradeBasedOnID($rows['BUNKERID']).' - '.$rows[$arr_fields[$j]];
			}
			echo '<td align="center">'.implode(', ',$bunker_consp).'</td>';
		}
		echo '</tr>';
	}
	
	
	
	
	
	echo '<tr>';
	echo '<td align="center" colspan="'.(count($chkArr1) + 1).'"><strong>FO Consp/day(MT)- In Port</strong></td>';
	echo '</tr>';
	
	$arr_level = array('SECA - Working', 'NON-SECA - Working', 'SECA - Idle', 'NON-SECA - Idle', 'SECA - Others', 'NON-SECA - Others');
	$arr_fields = array('FO_INPORT_SECA_CONSP_WORKING', 'FO_INPORT_NONSECA_CONSP_WORKING', 'FO_INPORT_SECA_CONSP_IDLE', 'FO_INPORT_NONSECA_CONSP_IDLE', 'FO_INPORT_SECA_CONSP_OTHER', 'FO_INPORT_NONSECA_CONSP_OTHER');
	
	for($j=0;$j<count($arr_level);$j++)
	{
		echo '<tr>';
		echo '<td align="center">'.$arr_level[$j].'</td>';
		for($i=0;$i<count($chkArr1);$i++)
		{
		    $sql = "select ".$arr_fields[$j].", BUNKERID from vessel_commercial_parameters_slave1 where IDENTIFY='FO' and COMMERCIAL_PARAMETERID=".$obj->getVesselParameterData($chkArr1[$i],"COMMERCIAL_PARAMETERID");
		    $result = mysql_query($sql);
		    $bunker_consp = array();
			while($rows = mysql_fetch_assoc($result))
			{
			    $bunker_consp[] = $obj->getBunkerGradeBasedOnID($rows['BUNKERID']).' - '.$rows[$arr_fields[$j]];
			}
			echo '<td align="center">'.implode(', ',$bunker_consp).'</td>';
		}
		echo '</tr>';
	}
	
	
	echo '<tr>';
	echo '<td align="center" colspan="'.(count($chkArr1) + 1).'"><strong>DO Consp/day(MT)- In Port</strong></td>';
	echo '</tr>';
	
	$arr_level = array('SECA - Working', 'NON-SECA - Working', 'SECA - Idle', 'NON-SECA - Idle', 'SECA - Others', 'NON-SECA - Others');
	$arr_fields = array('FO_INPORT_SECA_CONSP_WORKING', 'FO_INPORT_NONSECA_CONSP_WORKING', 'FO_INPORT_SECA_CONSP_IDLE', 'FO_INPORT_NONSECA_CONSP_IDLE', 'FO_INPORT_SECA_CONSP_OTHER', 'FO_INPORT_NONSECA_CONSP_OTHER');
	
	for($j=0;$j<count($arr_level);$j++)
	{
		echo '<tr>';
		echo '<td align="center">'.$arr_level[$j].'</td>';
		for($i=0;$i<count($chkArr1);$i++)
		{
		    $sql = "select ".$arr_fields[$j].", BUNKERID from vessel_commercial_parameters_slave1 where IDENTIFY='DO' and COMMERCIAL_PARAMETERID=".$obj->getVesselParameterData($chkArr1[$i],"COMMERCIAL_PARAMETERID");
		    $result = mysql_query($sql);
		    $bunker_consp = array();
			while($rows = mysql_fetch_assoc($result))
			{
			    $bunker_consp[] = $obj->getBunkerGradeBasedOnID($rows['BUNKERID']).' - '.$rows[$arr_fields[$j]];
			}
			echo '<td align="center">'.implode(', ',$bunker_consp).'</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['BALANCE_TO_OWNER'].'" 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['BALANCE_TO_OWNER'].'" 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">
				 Invoice Amount
				<address>
					<input type="text" name="txtP_Amt" id="txtP_Amt" class="form-control" readonly value="'.$rows['NET_PAYABLE_TAX'].'" autocomplete="off"/>
					<input type="hidden" name="txtP_ID" id="txtP_ID" readonly value="'.$invoiceid.'" />	
				</address>
			 </div><!-- /.col -->
			 
			 <div class="col-sm-8 invoice-col">
				Main 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>';
		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="5%">#</th>';
		echo '<th align="left" valign="middle" width="20%">Payment Date</th>';
		echo '<th align="left" valign="middle" width="40%">Payment Remarks</th>';
		echo '<th align="left" valign="middle" width="20%">Payment Received</th>';
		echo '</tr>';
		echo '</thead>';
		echo '<tbody id="paymenttbody">';
		$sqlslave 		= "select * from freight_invoice_slave2 where INVOICEID='".$invoiceid."' ";
		$resslave 	 	=  mysql_query($sqlslave) or die($sqlslave);
		$numslave       =  mysql_num_rows($resslave);
		$i = 0;
		if($numslave==0)
		{$i++;
		    echo '<tr id="trpaymentrow_'.$i.'">';
			echo '<td><a href="#pr1" onClick="removePaymentRow('.$i.');"><i class="fa fa-times" style="color:red;"></i></a></td>';
			echo '<td><input type="text" name="txtP_Date_'.$i.'" id="txtP_Date_'.$i.'" class="form-control" value="" autocomplete="off"/></td>';
			echo '<td><textarea name="txtP_Remarks_'.$i.'" id="txtP_Remarks_'.$i.'" class="form-control" cols="15" rows="2" placeholder="Remarks.."></textarea></td>';
			echo '<td><input type="text" name="txtP_PR_'.$i.'" id="txtP_PR_'.$i.'" class="form-control numeric" autocomplete="off" placeholder="0.00" value=""  onkeyup="onkeyUp1();"/></td>';
			echo '</tr>';
		}else
		{
			while($rowsslave = mysql_fetch_assoc($resslave))
			{$i++;
			
			if(date('d-m-Y',strtotime($rowsslave['RECVD_DATE']))!="01-01-1970")
			{
				$idate = date('d-m-Y',strtotime($rowsslave['RECVD_DATE']));
			}
			else
			{
				$idate = date('d-m-Y',time());
			}
				echo '<tr id="trpaymentrow_'.$i.'">';
				echo '<td><a href="#pr1" onClick="removePaymentRow('.$i.');"><i class="fa fa-times" style="color:red;"></i></a></td>';
				echo '<td><input type="text" name="txtP_Date_'.$i.'" id="txtP_Date_'.$i.'" class="form-control" value="'.$idate.'" autocomplete="off"/></td>';
				echo '<td><textarea name="txtP_Remarks_'.$i.'" id="txtP_Remarks_'.$i.'" class="form-control" cols="15" rows="2" placeholder="Remarks..">'.$rowsslave['RECVD_REMARKS'].'</textarea></td>';
				echo '<td><input type="text" name="txtP_PR_'.$i.'" id="txtP_PR_'.$i.'" class="form-control numeric" autocomplete="off" placeholder="0.00" value="'.$rowsslave['RECVD_AMOUNT'].'"  onkeyup="onkeyUp1();"/></td>';
				echo '</tr>';
			}
		}
		echo '</tbody">';
		echo '<tfoot>';
		echo '<tr>';
		echo '<td><button type="button" class="btn btn-primary btn-flat" onClick="AddNewPaymentRow();">Add</button><input type="hidden" name="txtPaymentID" id="txtPaymentID" value="'.$i.'"/></td>';
		echo '<td colspan="2">Total Payment Received</td>';
		echo '<td><input type="text" name="txtP_PR" id="txtP_PR" class="form-control" autocomplete="off" placeholder="0.00" value="'.$rows['P_AMT'].'" readonly="true" onkeyup="onkeyUp1();"/></td>';
		echo '</tr>';
		echo '</tfoot">';
		echo '</table>';
		echo '</div">';
		
		echo '<div class="row invoice-info">
			<div class="col-sm-12 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']." @@@@".$row['IFSC'];
	}
	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);
	
	$laden_balast_consp = array();
	$sql_lb = "select * from vessel_commercial_parameters_slave1 where COMMERCIAL_PARAMETERID=".$obj->getVesselParameterData($vessel1d,"COMMERCIAL_PARAMETERID");
	$result_lb = mysql_query($sql_lb);$i = 0;
	$num_lb = mysql_num_rows($result_lb);
	while($rows_lb = mysql_fetch_assoc($result_lb))
	{
	    $laden_balast_consp[] = array('BUNKERID'=>$rows_lb['BUNKERID'], 'BUNKER_NAME'=>$obj->getBunkerGradeBasedOnID($rows_lb['BUNKERID']), 'IDENTIFY'=>$rows_lb['IDENTIFY'], 'FO_BALAST_ATSEA_SECA_CONSP_FS'=>$rows_lb['FO_BALAST_ATSEA_SECA_CONSP_FS'], 'FO_LADEN_ATSEA_SECA_CONSP_FS'=>$rows_lb['FO_LADEN_ATSEA_SECA_CONSP_FS'], 'FO_BALAST_ATSEA_NONSECA_CONSP_FS'=>$rows_lb['FO_BALAST_ATSEA_NONSECA_CONSP_FS'], 'FO_LADEN_ATSEA_NONSECA_CONSP_FS'=>$rows_lb['FO_LADEN_ATSEA_NONSECA_CONSP_FS'], 'FO_BALAST_ATSEA_SECA_CONSP_SS'=>$rows_lb['FO_BALAST_ATSEA_SECA_CONSP_SS'], 'FO_LADEN_ATSEA_SECA_CONSP_SS'=>$rows_lb['FO_LADEN_ATSEA_SECA_CONSP_SS'], 'FO_BALAST_ATSEA_NONSECA_CONSP_SS'=>$rows_lb['FO_BALAST_ATSEA_NONSECA_CONSP_SS'], 'FO_LADEN_ATSEA_NONSECA_CONSP_SS'=>$rows_lb['FO_LADEN_ATSEA_NONSECA_CONSP_SS'], 'FO_BALAST_ATSEA_SECA_CONSP_MES'=>$rows_lb['FO_BALAST_ATSEA_SECA_CONSP_MES'], 'FO_LADEN_ATSEA_SECA_CONSP_MES'=>$rows_lb['FO_LADEN_ATSEA_SECA_CONSP_MES'], 'FO_BALAST_ATSEA_NONSECA_CONSP_MES'=>$rows_lb['FO_BALAST_ATSEA_NONSECA_CONSP_MES'], 'FO_LADEN_ATSEA_NONSECA_CONSP_MES'=>$rows_lb['FO_LADEN_ATSEA_NONSECA_CONSP_MES']);
	}
	
	$working_idle_consp = array();
	$sql_wl = "select * from vessel_commercial_parameters_slave1 where COMMERCIAL_PARAMETERID=".$obj->getVesselParameterData($vessel1d,"COMMERCIAL_PARAMETERID");
	$result_wl = mysql_query($sql_wl);$i = 0;
	$num_wl = mysql_num_rows($result_wl);
	while($rows_wl = mysql_fetch_assoc($result_wl))
	{
	    $working_idle_consp[] = array('BUNKERID'=>$rows_wl['BUNKERID'], 'BUNKER_NAME'=>$obj->getBunkerGradeBasedOnID($rows_wl['BUNKERID']), 'IDENTIFY'=>$rows_wl['IDENTIFY'], 'FO_INPORT_SECA_CONSP_WORKING'=>$rows_wl['FO_INPORT_SECA_CONSP_WORKING'], 'FO_INPORT_NONSECA_CONSP_WORKING'=>$rows_wl['FO_INPORT_NONSECA_CONSP_WORKING'], 'FO_INPORT_SECA_CONSP_IDLE'=>$rows_wl['FO_INPORT_SECA_CONSP_IDLE'], 'FO_INPORT_NONSECA_CONSP_IDLE'=>$rows_wl['FO_INPORT_NONSECA_CONSP_IDLE'], 'FO_INPORT_SECA_CONSP_OTHER'=>$rows_wl['FO_INPORT_SECA_CONSP_OTHER'], 'FO_INPORT_NONSECA_CONSP_OTHER'=>$rows_wl['FO_INPORT_NONSECA_CONSP_OTHER']       , 'FO_INPORT_SECA_CONSP_IDLE_BALLAST'=>$rows_wl['FO_INPORT_SECA_CONSP_IDLE_BALLAST'], 'FO_INPORT_NONSECA_CONSP_IDLE_BALLAST'=>$rows_wl['FO_INPORT_NONSECA_CONSP_IDLE_BALLAST'], 'FO_INPORT_SECA_CONSP_IDLE_LADEN'=>$rows_wl['FO_INPORT_SECA_CONSP_IDLE_LADEN'], 'FO_INPORT_NONSECA_CONSP_IDLE_LADEN'=>$rows_wl['FO_INPORT_NONSECA_CONSP_IDLE_LADEN'], 'FO_INPORT_SECA_CONSP_WORKING_LP'=>$rows_wl['FO_INPORT_SECA_CONSP_WORKING_LP'], 'FO_INPORT_NONSECA_CONSP_WORKING_LP'=>$rows_wl['FO_INPORT_NONSECA_CONSP_WORKING_LP'], 'FO_INPORT_SECA_CONSP_WORKING_DP'=>$rows_wl['FO_INPORT_SECA_CONSP_WORKING_DP'], 'FO_INPORT_NONSECA_CONSP_WORKING_DP'=>$rows_wl['FO_INPORT_NONSECA_CONSP_WORKING_DP'], 'FO_OTHER_SECA_CONSP_TK'=>$rows_wl['FO_OTHER_SECA_CONSP_TK'], 'FO_OTHER_NONSECA_CONSP_TK'=>$rows_wl['FO_OTHER_NONSECA_CONSP_TK'], 'FO_OTHER_SECA_CONSP_INERT'=>$rows_wl['FO_OTHER_SECA_CONSP_INERT'], 'FO_OTHER_NONSECA_CONSP_INERT'=>$rows_wl['FO_OTHER_NONSECA_CONSP_INERT'], 'FO_OTHER_SECA_CONSP_GF'=>$rows_wl['FO_OTHER_SECA_CONSP_GF'], 'FO_OTHER_NONSECA_CONSP_GF'=>$rows_wl['FO_OTHER_NONSECA_CONSP_GF'], 'FO_OTHER_SECA_CONSP_HEAT'=>$rows_wl['FO_OTHER_SECA_CONSP_HEAT'], 'FO_OTHER_NONSECA_CONSP_HEAT'=>$rows_wl['FO_OTHER_NONSECA_CONSP_HEAT'], 'FO_OTHER_SECA_CONSP_HEAT_1'=>$rows_wl['FO_OTHER_SECA_CONSP_HEAT_1'], 'FO_OTHER_NONSECA_CONSP_HEAT_1'=>$rows_wl['FO_OTHER_NONSECA_CONSP_HEAT_1']);
		
		
		//, FO_OTHER_SECA_CONSP_TK, , , , , , , , FO_OTHER_SECA_CONSP_HEAT_1, FO_OTHER_NONSECA_CONSP_HEAT_1
	}
	
	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;}
	
	
	$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;}
	
	$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);
		 $TPCMT = $obj->getVesselParticularData('TPC_MT','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);
		 $TPCMT = $obj->getVesselParticularData('TPC_SUMMER','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, 'lfs' => $lfs, 'les1' => $les1, 'les2' => $les2, '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'=>$TPCMT, '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,'.',''), 'laden_balast_consp'=>$laden_balast_consp, 'working_idle_consp'=>$working_idle_consp);
	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['LOAD_PORT_QTY']>0)
				{
				  	$arr_load[] = $obj->getPortNameBasedOnID($rows1['FROM_PORT']);
				}
				if($rows1['DISC_PORT_QTY']>0)
				{
				 	 $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'];
			    if($rows['TANKER_RADIO_SINGLE_DIS']==1)
				{
					$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
				{
				    $sql12 = "select sum(AMOUNT_USD) as sum1 from freight_cost_estimete_slave10 where FCAID='".$rows['FCAID']."'";
					$res12 = mysql_query($sql12);
					$row12 = mysql_fetch_assoc($res12);
					$freight = 'Lumpsum '.$row12['sum1'];
				}
			}
			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))
			{
			      if($rows2['LOAD_PORT_QTY']>0)
				  {
				  	$arr_load[] = $obj->getPortNameBasedOnID($rows2['FROM_PORT']);
				  }
				  if($rows2['DISC_PORT_QTY']>0)
				  {
				 	 $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'];
				if($rows['TANKER_RADIO_SINGLE_DIS']==1)
				{
					$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
				{
					$sql12 = "select sum(AMOUNT_USD) as sum1 from freight_cost_estimete_slave10 where FCAID='".$rows['FCAID']."'";
					$res12 = mysql_query($sql12);
					$row12 = mysql_fetch_assoc($res12);
					$freight = 'Lumpsum '.$row12['sum1'];
				}
			}
			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'];
	$selSpotCOA 	= $_REQUEST['selSpotCOA'];
	
	$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="9%">Spot/COA/TC</th>
					<th align="left" width="10%">Nom Id/Voyage No.</th>
					<th align="left" width="9%">Vessel</th>
					<th align="left" width="9%">CP Date</th>									
					<th align="left" width="9%">Invoice Type</th>
					<th align="left" width="9%">Invoice No.</th>
					<th align="left" width="9%">Invoice Date</th>
					<th align="left" width="10%">Amount Invoiced</th>
					<th align="left" width="10%">Amount Received</th>
					<th align="left" width="10%">Difference</th>
					<th align="left" width="5%">Delay (Days)</th>
					<th align="left" width="5%">Open/Closed</th>
				</tr>
			</thead>
			<tbody>';
	if($selSpotCOA == 3)
	{
	    $selCOASpot1 = 'TC';
		$sql = "select * 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) and chartering_estimate_tc_master.ESTIMATE_TYPE='".$selBType."' order by chartering_estimate_tc_compare.COMID desc";
	}
	else
	{
		if($selSpotCOA == 2){$subquery = " and freight_cost_estimete_master.COAID is not NULL";$selCOASpot1='COA';}else{$subquery = " and freight_cost_estimete_master.COAID is NULL";$selCOASpot1='Spot';}
		$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";
	}
	$res = mysql_query($sql);
	$rec = mysql_num_rows($res);
	$i = 1;
	if($rec == 0)
	{
		
	}
	else
	{	
		while($rows = mysql_fetch_assoc($res))
		{		
		    if($selSpotCOA == 3)
        	{
				$tcoutid = $obj->getLatestCostSheetIDTC($rows['COMID']);
				$obj->viewTCEstimationTempleteRecordsNew($tcoutid);
				$sqltc = "SELECT * from chartering_tc_estimate_slave1 where TCOUTID='".$obj->getFun1()."'";
				$restc 	= mysql_query($sqltc);
				$rectc 	= mysql_num_rows($restc);
				while($rowstc = mysql_fetch_assoc($restc))
				{
					$currency = $rowstc['EXCHANGE_CURRENCY'];
					if(($_REQUEST['selVendor']!='' && $_REQUEST['selVendor']==$rowstc['TTL_REV_VENDOR']) || $_REQUEST['selVendor'] =='')
					{
						if($var == 1)
						{
							$sql1 = "select * from invoice_tchire_master where COMID='".$rows['COMID']."' and RANDOMID='".$rowstc['RANDOMID']."'";
						}
						else if($var == 2)
						{
							$sql1 = "select * from invoice_tchire_master where (INVOICE_DATE BETWEEN '".date("Y-m-d",strtotime($from_date))."' and '".date("Y-m-d",strtotime($to_date))."')  and COMID='".$rows['COMID']."' and RANDOMID='".$rowstc['RANDOMID']."'";
						}
						else if($var == 3)
						{
							$sql1 = "select * from invoice_tchire_master where INVOICE_DATE<'".date("Y-m-d",strtotime($from_date))."'  and COMID='".$rows['COMID']."' and RANDOMID='".$rowstc['RANDOMID']."'";
						}
						$res1 = mysql_query($sql1) or die($sql1);
						while ($rows1 = mysql_fetch_assoc($res1))
						{
						    $cost_type = 'Hire Invoice';
							$invoice_amt= $rows1['FINAL_AMOUNT'];
							$amt_paid = $rows1['P_AMT'];
							$diff = $invoice_amt - $amt_paid;
							$start = strtotime($rows1['INVOICE_DATE']);
							if($rows1['P_DATE'] == NULL || date('d-m-Y',strtotime($rows1['P_DATE'])) == '01-01-1970' || $rows1['P_DATE'] == '')
							{
								$end = strtotime(date('Y-m-d',time()));
							}
							else
							{
								$end = strtotime(date('Y-m-d',strtotime($rows1['P_DATE'])));
							}
							$delay_days = ceil(abs($end - $start) / 86400);
							if($rowstc['TTL_REV_VENDOR']!="")
							{
								echo '<tr>';
								echo '<td align="left" valign="middle">'.$i.'.</td>';
								echo '<td align="left" valign="middle">'.$obj->getVendorListNewBasedOnID($rowstc['TTL_REV_VENDOR']).'</td>';
								echo '<td align="left" valign="middle">'.$selCOASpot1.'</td>';
								echo '<td align="left" valign="middle">'.$obj->getCompareTableDataTC($rows['COMID'],"MESSAGE").'/<br/>'.$obj->getFun7().'</td>';
								echo '<td align="left" valign="middle">'.$obj->getVesselIMOData($obj->getFun3(),"VESSEL_NAME").'</td>';
								echo '<td align="left" valign="middle">'.(($obj->getFun9()=='' || $obj->getFun9()=='0000-00-00' || $obj->getFun9()=='1970-01-01')?'':date("d-m-Y",strtotime($obj->getFun9()))).'</td>';
								echo '<td align="left" valign="middle">'.$cost_type.'</td>';
								echo '<td align="left" valign="middle">'.$rows1['INVOICE_NO'].'</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>';
								if($rows1['STATUS']==0){$status = '<span class="label label-warning">Open</span>';}else if($rows1['STATUS']==1){$status = '<span class="label label-success">Closed</span>';}else{$status = '<span class="label label-danger">Cancelled</span>';}
								echo '<td align="left" valign="middle">'.$status.'</td>';
								echo '</tr>';
								$i++;
							}
						}
					}
					
					if($var == 1)
					{
						$sql1 = "select * from invoice_tcother_master where ".(($_REQUEST['selVendor']!='')?"VENDOR='".$selVendor."' and ":"")." COMID='".$rows['COMID']."' and RANDOMID='".$rowstc['RANDOMID']."'";
					}
					else if($var == 2)
					{
						$sql1 = "select * from invoice_tcother_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']."' and RANDOMID='".$rowstc['RANDOMID']."'";
					}
					else if($var == 3)
					{
						$sql1 = "select * from invoice_tcother_master where ".(($_REQUEST['selVendor']!='')?"VENDOR='".$selVendor."' and ":"")." INVOICE_DATE<'".date("Y-m-d",strtotime($from_date))."'  and COMID='".$rows['COMID']."' and RANDOMID='".$rowstc['RANDOMID']."'";
					}
					$res1 = mysql_query($sql1) or die($sql1);
					while($rows1 = mysql_fetch_assoc($res1))
					{
						if($rows1['VENDOR']!="")
						{
							$cost_type = $rows1['INV_IDENTITY'].' '.$rows1['SHORT_DESC'];
							$invoice_amt= $rows1['FINAL_AMOUNT'];
							$amt_paid = $rows1['P_AMT'];
							$diff = $invoice_amt - $amt_paid;
							$start = strtotime($rows1['INVOICE_DATE']);
							if($rows1['P_DATE'] == NULL || date('d-m-Y',strtotime($rows1['P_DATE'])) == '01-01-1970' || $rows1['P_DATE'] == '')
							{
								$end = strtotime(date('Y-m-d',time()));
							}
							else
							{
								$end = strtotime(date('Y-m-d',strtotime($rows1['P_DATE'])));
							}
							$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">'.$selCOASpot1.'</td>';
							echo '<td align="left" valign="middle">'.$obj->getCompareTableData($rows['COMID'],"MESSAGE").'/<br/>'.$obj->getFun7().'</td>';
							echo '<td align="left" valign="middle">'.$obj->getVesselIMOData($obj->getFun3(),"VESSEL_NAME").'</td>';
							echo '<td align="left" valign="middle">'.(($obj->getFun9()=='' || $obj->getFun9()=='0000-00-00' || $obj->getFun9()=='1970-01-01')?'':date("d-m-Y",strtotime($obj->getFun9()))).'</td>';
							echo '<td align="left" valign="middle">'.$cost_type.'</td>';
							echo '<td align="left" valign="middle">'.$rows1['INVOICE_NO'].'</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>';
							if($rows1['STATUS']==0){$status = '<span class="label label-warning">Open</span>';}else if($rows1['STATUS']==1){$status = '<span class="label label-success">Closed</span>';}else{$status = '<span class="label label-danger">Cancelled</span>';}
							echo '<td align="left" valign="middle">'.$status.'</td>';
							echo '</tr>';
						$i++;
						}
					}
				}
			}
			else
			{
				$fcaid = $obj->getLatestCostSheetID($rows['COMID']);
				$obj->viewFreightCostEstimationTempleteRecordsNew($fcaid);
				if($obj->getFun175()!='')
				{
					$sqlcoa = "select * from coa_master where COAID='".$obj->getFun175()."'";
					$resultcoa = mysql_query($sqlcoa) or die($sqlcoa);
					$rowscoa   = mysql_fetch_assoc($resultcoa);
					$charterer = $obj->getVendorListNewData($rowscoa['CHARTERER'],"NAME");
					$currency = $rowscoa['CURRENCY'];
				}
				else
				{
					$currency = $obj->getFun206();
					
				}
				if($var == 1)
				{
					$sql1 = "select * from other_invoice_master where ".(($_REQUEST['selVendor']!='')?"VENDOR='".$selVendor."' and ":"")." COMID='".$rows['COMID']."'";
				}
				else if($var == 2)
				{
					$sql1 = "select * from other_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 other_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_PAYABLE'];
					$amt_paid = $rows1['P_AMT'];
					$diff = $invoice_amt - $amt_paid;
					$cost_type = $rows1['P_TYPE'];
					$start = strtotime($rows1['DATE']);
					if($rows1['P_DATE'] == NULL || date('d-m-Y',strtotime($rows1['P_DATE'])) == '01-01-1970' || $rows1['P_DATE'] == '')
					{
						$end = strtotime(date('Y-m-d',time()));
					}
					else
					{
						$end = strtotime(date('Y-m-d',strtotime($rows1['P_DATE'])));
					}
					$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">'.$selCOASpot1.'</td>';
						echo '<td align="left" valign="middle">'.$obj->getCompareTableData($rows['COMID'],"MESSAGE").'/<br/>'.$obj->getFun8().'</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->getFun3()=='' || $obj->getFun3()=='0000-00-00' || $obj->getFun3()=='1970-01-01')?'':date("d-m-Y",strtotime($obj->getFun3()))).'</td>';
						echo '<td align="left" valign="middle">'.$cost_type.'</td>';
						echo '<td align="left" valign="middle">'.$rows1['MESSAGE'].'</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>';
						if($rows1['STATUS']==0){$status = '<span class="label label-warning">Open</span>';}else if($rows1['STATUS']==1){$status = '<span class="label label-success">Closed</span>';}else{$status = '<span class="label label-danger">Cancelled</span>';}
						echo '<td align="left" valign="middle">'.$status.'</td>';
						echo '</tr>';
						$i++;
					}
					
					
				}
				if($var == 1)
				{
					$sql1 = "select * from freight_invoice_master where ".(($_REQUEST['selVendor']!='')?"VENDOR='".$selVendor."' and ":"")." COMID='".$rows['COMID']."' ";
				}
				else if($var == 2)
				{
					$sql1 = "select * from freight_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 freight_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))
				{
					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']);
						if($rows1['P_DATE'] == NULL || date('d-m-Y',strtotime($rows1['P_DATE'])) == '01-01-1970' || $rows1['P_DATE'] == '')
						{
							$end = strtotime(date('Y-m-d',time()));
						}
						else
						{
							$end = strtotime(date('Y-m-d',strtotime($rows1['P_DATE'])));
						}
						$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">'.$selCOASpot1.'</td>';
						echo '<td align="left" valign="middle">'.$obj->getCompareTableData($rows['COMID'],"MESSAGE").'/<br/>'.$obj->getFun8().'</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->getFun3()=='' || $obj->getFun3()=='0000-00-00' || $obj->getFun3()=='1970-01-01')?'':date("d-m-Y",strtotime($obj->getFun3()))).'</td>';
						echo '<td align="left" valign="middle">'.$cost_type.'</td>';
						echo '<td align="left" valign="middle">'.$rows1['MESSAGE'].'</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>';
						if($rows1['STATUS']==0){$status = '<span class="label label-warning">Open</span>';}else if($rows1['STATUS']==1){$status = '<span class="label label-success">Closed</span>';}else{$status = '<span class="label label-danger">Cancelled</span>';}
						echo '<td align="left" valign="middle">'.$status.'</td>';
						echo '</tr>';
					$i++;
					}
				}
			}
		}
	}
	
	$currency = 'USD';
	if($var == 1)
	{
		$sql1 = "select * from generic_invoice_master where ".(($_REQUEST['selVendor']!='')?"VENDOR='".$selVendor."' and ":"")." CONTRACT_TYPE='".$selSpotCOA."' and BUSINESSTYPEID='".$selBType."' ";
	}
	else if($var == 2)
	{
		$sql1 = "select * from generic_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 CONTRACT_TYPE='".$selSpotCOA."' and BUSINESSTYPEID='".$selBType."'";
	}
	else if($var == 3)
	{
		$sql1 = "select * from generic_invoice_master where ".(($_REQUEST['selVendor']!='')?"VENDOR='".$selVendor."' and ":"")." DATE<'".date("Y-m-d",strtotime($from_date))."' and CONTRACT_TYPE='".$selSpotCOA."' and BUSINESSTYPEID='".$selBType."'";
	}
	
	$res1 = mysql_query($sql1) or die($sql1);
	while($rows1 = mysql_fetch_assoc($res1))
	{
		if($rows1['VENDOR']!="")
		{
			$cost_type = $rows1['AMOUNT_DESC'];
			$invoice_amt= $rows1['NET_PAYABLE'];
			$amt_paid = $rows1['P_AMT'];
			$diff = $invoice_amt - $amt_paid;
			$start = strtotime($rows1['INVOICE_DATE']);
			if($rows1['P_DATE'] == NULL || date('d-m-Y',strtotime($rows1['P_DATE'])) == '01-01-1970' || $rows1['P_DATE'] == '0000-00-00' || $rows1['P_DATE'] == '')
			{
				$end = strtotime(date('Y-m-d',time()));
			}
			else
			{
				$end = strtotime(date('Y-m-d',strtotime($rows1['P_DATE'])));
			}
			$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->getCOA_SPOTBasedOnID($selSpotCOA).'</td>';
			echo '<td align="left" valign="middle">Generic Finances</td>';
			echo '<td align="left" valign="middle"></td>';
			echo '<td align="left" valign="middle"></td>';
			echo '<td align="left" valign="middle">'.$cost_type.'</td>';
			echo '<td align="left" valign="middle">'.$rows1['INVOICE_NO'].'</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).' '.$currency.'</td>';
			echo '<td align="left" valign="middle">'.$obj->getNumberFormat($amt_paid).' '.$currency.'</td>';
			echo '<td align="left" valign="middle">'.$obj->getNumberFormat($diff).' '.$currency.'</td>';
			echo '<td align="left" valign="middle">'.$delay_days.'</td>';
			if($rows1['STATUS']==0){$status = '<span class="label label-warning">Open</span>';}else if($rows1['STATUS']==1){$status = '<span class="label label-success">Closed</span>';}else{$status = '<span class="label label-danger">Cancelled</span>';}
			echo '<td align="left" valign="middle">'.$status.'</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'];
	$selCOASpot     = $_REQUEST['selCOASpot'];
	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="9%">Vendor</th>
					<th align="left" width="9%">COA/Spot</th>
					<th align="left" width="9%">Nom Id/Voyage No.</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%">Payment No.</th>
					<th align="left" width="9%">Invoice Date</th>
					<th align="left" width="9%">Payment Date</th>
					<th align="left" width="9%">Amount Invoiced</th>
					<th align="left" width="9%">Amount Paid</th>
					<th align="left" width="9%">Difference</th>
					<th align="left" width="9">Delay (Days)</th>
				</tr>
			</thead>
			<tbody>';
	if($selCOASpot == 2){$subquery = " and freight_cost_estimete_master.COAID is not NULL";$selCOASpot1='COA';}else{$subquery = " and freight_cost_estimete_master.COAID is NULL";$selCOASpot1='Spot';}
	$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." 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']."' ";
			}//echo $sql1;
			$res1 = mysql_query($sql1) or die($sql1);
			while ($rows1 = mysql_fetch_assoc($res1))
			{
				if($rows1['NAME_ID'] == 2)
				{
					$cost_type = $rows1['NAME'].' - '.$obj->getBunkerGradeBasedOnID($rows1['GRADEID']);
				}
				else if($rows1['NAME_ID'] == 3)
				{
					if($rows1['GRADEID']==0)
					{
						$cost_type = $rows1['NAME'].' - Brokerage Commission (%)';
					}
					else
					{
					    $sql4 = "select * from freight_cost_estimete_slave3 where FCAID='".$obj->getFun1()."'  and IDENTIFY='ORC'";
						$res4 = mysql_query($sql4);
						$rec4 = mysql_num_rows($res4);$j=0;
						while($rows4 = mysql_fetch_assoc($res4))
						{$j++;
							if($j==$rows1['GRADEID'])
							{
								$cost_type = $rows1['NAME'].' - '.$obj->getOwnerRelatedCostNameBasedOnID($rows4['IDENTY_ID']);
							}
						}
					}
				}
				
				else if($rows1['NAME_ID'] == 5)
				{
					$cost_type = $rows1['NAME'].' - '.$obj->getPortNameBasedOnID($rows1['GRADEID']);
				}
				
				$invoice_amt= $rows1['NET_AMT'];
				$amt_paid = $rows1['P_AMT'];
				$diff = $invoice_amt - $amt_paid;
				
				$start = strtotime($rows1['INVOICE_DATE']);
				if($rows1['P_DATE'] == NULL || date('d-m-Y',strtotime($rows1['P_DATE'])) == '01-01-1970' || $rows1['P_DATE'] == '')
				{
					$end = strtotime(date('Y-m-d',time()));
				}
				else
				{
				    $end = strtotime(date('Y-m-d',strtotime($rows1['P_DATE'])));
				}
				$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">'.$selCOASpot1.'</td>';
					echo '<td align="left" valign="middle">'.$obj->getCompareTableData($rows['COMID'],"MESSAGE").'/'.$obj->getFun8().'</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->getFun3()=='' || $obj->getFun3()=='0000-00-00' || $obj->getFun3()=='1970-01-01')?'':date("d-m-Y",strtotime($obj->getFun3()))).'</td>';
					echo '<td align="left" valign="middle">'.$cost_type.'</td>';
					echo '<td align="left" valign="middle">'.$rows1['PAYMENT_NO'].'</td>';
					echo '<td align="left" valign="middle">'.date("d-m-Y",strtotime($rows1['INVOICE_DATE'])).'</td>';
					echo '<td align="left" valign="middle">'.(($rows1['P_DATE']=='' || $rows1['P_DATE']=='0000-00-00' || $rows1['P_DATE']=='1970-01-01')?'':date("d-m-Y",strtotime($rows1['P_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(($obj->getCompareEstimateData($rows['COMID'],"DTCVENDORID")!="") && ($_REQUEST['selVendor']=='' || $selVendor == $obj->getCompareEstimateData($rows['COMID'],"DTCVENDORID")))
				{
					$cost_type = 'Daily Time Charter';
					$invoice_amt= $rows1['FINAL_AMT'];
					$amt_paid = $rows1['P_AMT'];
					$diff = $invoice_amt - $amt_paid;
					
					$start = strtotime($rows1['INVOICE_DATE']);
					if($rows1['P_DATE'] == NULL || date('d-m-Y',strtotime($rows1['P_DATE'])) == '01-01-1970' || $rows1['P_DATE'] == '')
					{
						$end = strtotime(date('Y-m-d',time()));
					}
					else
					{
						$end = strtotime(date('Y-m-d',strtotime($rows1['P_DATE'])));
					}
					$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($obj->getCompareEstimateData($rows['COMID'],"DTCVENDORID")).'</td>';
					echo '<td align="left" valign="middle">'.$selCOASpot1.'</td>';
					echo '<td align="left" valign="middle">'.$obj->getCompareTableData($rows['COMID'],"MESSAGE").'/'.$obj->getFun8().'</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->getFun3()=='' || $obj->getFun3()=='0000-00-00' || $obj->getFun3()=='1970-01-01')?'':date("d-m-Y",strtotime($obj->getFun3()))).'</td>';
					echo '<td align="left" valign="middle">'.$cost_type.'</td>';
					echo '<td align="left" valign="middle">'.$rows1['INVOICE_NO'].'</td>';
					echo '<td align="left" valign="middle">'.date("d-m-Y",strtotime($rows1['INVOICE_DATE'])).'</td>';
					echo '<td align="left" valign="middle">'.(($rows1['P_DATE']=='' || $rows1['P_DATE']=='0000-00-00' || $rows1['P_DATE']=='1970-01-01')?'':date("d-m-Y",strtotime($rows1['P_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");
				if($obj->getFun228()==1)
				{
					if($obj->getCompareEstimateData($comid,"CHK_LUMPSUM") == 1)
					{
						$freight = $obj->getCompareEstimateData($comid,"LUMPSUMAMT");
					}
					else
					{
						$res11 = mysql_query("select sum(TOTAL_AMOUNT) as sum1 from freight_cost_estimete_slave12 where FCAID='".$obj->getCompareEstimateData($rows['COMID'],"FCAID")."' and CUSTOMER!='' ");
						$num11 = mysql_num_rows($res11);
						$rows11 = mysql_fetch_assoc($res11);
						$freight = $rows11['sum1'];
					}
				}
				else
				{
					$sql12 = "select sum(AMOUNT_USD) as sum1 from freight_cost_estimete_slave10 where FCAID='".$obj->getCompareEstimateData($rows['COMID'],"FCAID")."' group by SHIPPER_CHARTER";
					$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->getFun3()=='' || $obj->getFun3()=='0000-00-00' || $obj->getFun3()=='1970-01-01')?'':date("d-m-Y",strtotime($obj->getFun3()))).'</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->getCompanyNameBasedOnID($_SESSION['company'],"COMPANY_NAME").'</td>';
				echo '<td align="left" valign="top" >'.implode(', ',$arrvendor).'</td>';
				echo '<td align="left" valign="top" >'.$obj->getMaterialCodeDesBasedOnId($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->getFun249()).'</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'];
	$selCOASpot	    = $_REQUEST['selCOASpot'];
	
	
	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/Voyage No.</th>
					<th align="left" width="10%">Vessel</th>
					<th align="left" width="10%">(COA/Spot)/Voyage No.</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">';
	if($selCOASpot == 2){$subquery = " and freight_cost_estimete_master.COAID is not NULL";}else{$subquery = " and freight_cost_estimete_master.COAID 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";
	$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>';
				if($selCOASpot == 2){
				echo '<td align="left" valign="middle">COA/'.$obj->getCompareEstimateData($rows['COMID'],"VOYAGE_NO").'</td>';
				}else{
				echo '<td align="left" valign="middle">Spot/'.$obj->getCompareEstimateData($rows['COMID'],"VOYAGE_NO").'</td>';
				}
				echo '<td align="left" valign="middle">'.(($obj->getFun3()=='' || $obj->getFun3()=='0000-00-00' || $obj->getFun3()=='1970-01-01')?'':date("d-m-Y",strtotime($obj->getFun3()))).'</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->getFun3())) == "01-Jan-1970")
							{
								echo '<td align="left" valign="middle"></td>';
							}
							else
							{
								echo '<td align="left" valign="middle">'.date("d-m-Y",strtotime($obj->getFun3())).'</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->getFun3())) == "01-Jan-1970")
						{
							echo '<td align="left" valign="middle"></td>';
						}
						else
						{
							echo '<td align="left" valign="middle">'.date("d-m-Y",strtotime($obj->getFun3())).'</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->getFun3())).'</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.TRANS_DATE!='0000-00-00' or freight_cost_estimete_master.TRANS_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'],"TRANS_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->getCompanyNameBasedOnID($_SESSION['company'],"COMPANY_NAME").'</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");
					    if($obj->getCompareEstimateData($rows['COMID'],"TANKER_RADIO_SINGLE_DIS")==1)
						{
						    if($obj->getCompareEstimateData($rows['COMID'],"CHK_LUMPSUM") == 1)
							{

								$freight = $obj->getCompareEstimateData($rows['COMID'],"LUMPSUMAMT");
							}
							else
							{
								$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
						{
							$sql12 = "select sum(AMOUNT_USD) as sum1 from freight_cost_estimete_slave10 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['TRANS_DATE'])) == "01-Jan-1970")
					{
						echo '<td></td>';
					}
					else
					{
						echo '<td>'.date("d-m-Y",strtotime($rows['TRANS_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->getMaterialCodeDesBasedOnId($obj->getCompareEstimateData($rows['COMID'],"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['TRANS_DATE'])) == "01-Jan-1970")
					{
						echo '<td></td>';
					}
					else
					{
						echo '<td>'.date("d-m-Y",strtotime($rows['TRANS_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->getMaterialCodeDesBasedOnId($obj->getCompareEstimateData($rows['COMID'],"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';
	}
}
function getContractListJsonForDash(){
	$obj = new data();
	$connect=$obj->funConnect();
	$_SESSION['selBType'] = $_POST['businesstype'];
	$aColumns = array("PERIODID", "CONTRACT_ID", "CONTRACT_NO", "CONTRACT_DATE", "OWN_BUSINESS_ACCOUNT", "VESSEL_IMO_ID", "WORKING_CURRENCY", "UPDATESTATUS");
	
	$sIndexColumn = "PERIODID";
	
	$sTable = "period_contract_master";
	
	if(!empty($_POST['order'][0]['column']))
	{
		$sOrder = "ORDER BY  ".$aColumns[intval($_POST['order'][0]['column'])]." ".$_POST['order'][0]['dir'];
	}
	else
	{
		$sOrder = "ORDER BY PERIODID";
	}
	
	$sWhere = "";
	
	if ($_POST['search']['value']!= "")
	{
		$sWhere = " and BUSINESSTYPE='".$_POST['businesstype']."' and (CONTRACT_ID LIKE '%".$_POST['search']['value']."%' or CONTRACT_NO LIKE '%".$_POST['search']['value']."%' or CONTRACT_DATE LIKE '%".$_POST['search']['value']."%' or OWN_BUSINESS_ACCOUNT LIKE '%".$_POST['search']['value']."%' or VESSEL_IMO_ID LIKE '%".$_POST['search']['value']."%' or UPDATE_STATUS LIKE '%".$_POST['search']['value']."%') ";
	}else{$sWhere = " and BUSINESSTYPE='".$_POST['businesstype']."' ";}
	
	$sQuery = "SELECT * FROM (select PERIODID, MODULEID, MCOMPANYID, CONTRACT_ID, CONTRACT_NO, WORKING_CURRENCY, CONTRACT_DATE, DELIVERY_DATE, RE_DEL_MAX_DATE, (select VESSEL_NAME from vessel_imo_master where vessel_imo_master.VESSEL_IMO_ID=period_contract_master.VESSEL_IMO_ID) as VESSEL_IMO_ID, (select CONCAT(NAME, '(',CODE,')') as OWN_BUSINESS_ACCOUNT from vendor_master where vendor_master.CODE=period_contract_master.OWN_BUSINESS_ACCOUNT) as OWN_BUSINESS_ACCOUNT, BUSINESSTYPE, (case when (UPDATE_STATUS = 1) THEN 'Save as Draft' ELSE 'Submit to Closed' END) as UPDATE_STATUS from period_contract_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 period_contract_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 ) )
	{
	    $totaldays = (strtotime($aRow['RE_DEL_MAX_DATE']) - strtotime($aRow['DELIVERY_DATE'])) / (60 * 60 * 24);
		$row = array(); $i = $i+1;
		$bunkerarray = $closingarray = array();
		$resultload = mysql_query("select BUNKERGRADEID, BUNKER_QTY from period_contract_master_slave1 where IDENTITY='DEL' and PERIODID='".$aRow['PERIODID']."'");
	    while($rowsload   = mysql_fetch_assoc($resultload))
		{
		    $bunkerarray[] = $obj->getBunkerGradeBasedOnID($rowsload['BUNKERGRADEID']).' - '.$rowsload['BUNKER_QTY'].' MT';
			 
			$remainingbunker = 0;
			$resultbunker = mysql_query("select (select TCOUTID from chartering_estimate_tc_master where chartering_estimate_tc_master.COMID=chartering_estimate_tc_compare.COMID order by chartering_estimate_tc_master.TCOUTID DESC LIMIT 1) as TCOUTID 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.PERIODID=".$aRow['PERIODID']." and chartering_estimate_tc_compare.FINAL_ID!='' and chartering_estimate_tc_master.FIXED=1 GROUP BY chartering_estimate_tc_master.COMID");
			while($rowsbunker   = mysql_fetch_assoc($resultbunker))
			{
				$resultbunker1 = mysql_query("select TC_SLAVE1ID from chartering_tc_estimate_slave1 where TCOUTID=".$rowsbunker['TCOUTID']."");
				while($rowsbunker1   = mysql_fetch_assoc($resultbunker1))
				{
					$resultbunker2 = mysql_query("select QTY from chartering_estimate_tc_slave5 where TC_SLAVE1ID='".$rowsbunker1['TC_SLAVE1ID']."' and IDENTITY='DEL' and BUNKERID='".$rowsload['BUNKERGRADEID']."'");
					$rowsbunker2 = mysql_fetch_assoc($resultbunker2);
					
					$resultbunker3 = mysql_query("select QTY from chartering_estimate_tc_slave5 where TC_SLAVE1ID='".$rowsbunker1['TC_SLAVE1ID']."' and IDENTITY='REDEL' and BUNKERID='".$rowsload['BUNKERGRADEID']."'");
					$rowsbunker3 = mysql_fetch_assoc($resultbunker3);
					$remainingbunker = number_format(($rowsbunker2['QTY'] - $rowsbunker3['QTY']),4,'.','');
				}
			}
			
			$resultbunker = mysql_query("select (select FCAID from freight_cost_estimete_master where freight_cost_estimete_master.COMID=freight_cost_estimate_compare.COMID order by freight_cost_estimete_master.FCAID DESC LIMIT 1) as TOTAL_DAYS 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.PERIODID=".$aRow['PERIODID']." and freight_cost_estimate_compare.FINAL_ID!='' and freight_cost_estimete_master.FIXED=1 GROUP BY freight_cost_estimete_master.COMID");
			while($rowsbunker   = mysql_fetch_assoc($resultbunker))
			{
				$resultbunker1 = mysql_query("select * from freight_cost_estimete_slave8 where IDENTIFY='CONSUMPTION' and FCAID=".$rowsbunker['FCAID']." and BUNKERID=".$rowsload['BUNKERGRADEID']);
				$rowsbunker1   = mysql_fetch_assoc($resultbunker1);
				
				$resultbunker2 = mysql_query("select * from freight_cost_estimete_slave8 where IDENTIFY='SUPPLY' and FCAID=".$rowsbunker['FCAID']." and BUNKERID=".$rowsload['BUNKERGRADEID']);
				$rowsbunker2   = mysql_fetch_assoc($resultbunker2);
				
				$remainingbunker = $remainingbunker + number_format(($rowsbunker2['QTY'] - $rowsbunker1['QTY']),4,'.','');
			}
			
			$closingarray[] = $obj->getBunkerGradeBasedOnID($rowsload['BUNKERGRADEID']).' - '.number_format(($rowsload['BUNKER_QTY'] - $remainingbunker),4,'.','').' MT';
		}
		
		$performeddays = 0;
		$sqltcdays = "select (select TCOUTID from chartering_estimate_tc_master where chartering_estimate_tc_master.COMID=chartering_estimate_tc_compare.COMID order by chartering_estimate_tc_master.TCOUTID DESC LIMIT 1) as TCOUTID 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.PERIODID=".$aRow['PERIODID']." and chartering_estimate_tc_compare.FINAL_ID!='' and chartering_estimate_tc_master.FIXED=1 GROUP BY chartering_estimate_tc_master.COMID";
		$resulttcdays = mysql_query($sqltcdays) or die($sqltcdays);
	    while($rowstcdays   = mysql_fetch_assoc($resulttcdays))
		{
		    $resulttcdays1 = mysql_query("select SUM(TC_DAYS_EST) as SUM from chartering_tc_estimate_slave1 where TCOUTID=".$rowstcdays['TCOUTID']."");
			while($rowstcdays1   = mysql_fetch_assoc($resulttcdays1))
			{
			    $performeddays = $performeddays + $rowstcdays1['SUM'];
			}
		}
		
		$sqltcdays = "select (select TOTAL_DAYS from freight_cost_estimete_master where freight_cost_estimete_master.COMID=freight_cost_estimate_compare.COMID order by freight_cost_estimete_master.FCAID DESC LIMIT 1) as TOTAL_DAYS 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.PERIODID=".$aRow['PERIODID']." and freight_cost_estimate_compare.FINAL_ID!='' and freight_cost_estimete_master.FIXED=1 GROUP BY freight_cost_estimete_master.COMID";
		$resulttcdays = mysql_query($sqltcdays) or die($sqltcdays);
	    while($rowstcdays   = mysql_fetch_assoc($resulttcdays))
		{
		    $performeddays = $performeddays + $rowstcdays['TOTAL_DAYS'];
		}
			$details = $details1 = '';

		$sqlForTotalShipForVc = "select freight_cost_estimete_master.FCAID, freight_cost_estimete_master.VESSEL_IMO_ID, freight_cost_estimete_master.PERIODID, freight_cost_estimete_master.VOYAGE_NO, freight_cost_estimete_master.COMID, freight_cost_estimete_master.ESTIMATE_TYPE, freight_cost_estimete_master.FIXED, freight_cost_estimete_master.COMID, freight_cost_estimete_master.QUANTITY, freight_cost_estimete_master.TRANS_DATE 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='".$_SESSION['selBType']."' and PERIODID='".$aRow['PERIODID']."' and FINAL_ID!='' order by date(freight_cost_estimete_master.FINAL_DATETIME) DESC";
		
		$resForTotalShipmentVc = mysql_query($sqlForTotalShipForVc) or die($sqlForTotalShipForVc);

		$recForTotalShipmentVc = mysql_num_rows($resForTotalShipmentVc);

		$details = $recForTotalShipmentVc;

		$sqlForTotalShipForTc="SELECT chartering_estimate_tc_master.TCOUTID, (select TC_RATE from chartering_tc_estimate_slave2 where chartering_tc_estimate_slave2.TC_SLAVE1ID=(select TC_SLAVE1ID from chartering_tc_estimate_slave1 where chartering_tc_estimate_slave1.TCOUTID= chartering_estimate_tc_master.TCOUTID LIMIT 1) LIMIT 1) as TC_RATE, chartering_estimate_tc_master.EXCHANGE_RATE, chartering_estimate_tc_master.COMID, (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, chartering_estimate_tc_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_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 PERIODID='".$aRow['PERIODID']."' order by date(chartering_estimate_tc_master.FINAL_DATETIME) DESC";

		$resForTotalShipmentTc = mysql_query($sqlForTotalShipForTc) or die($sqlForTotalShipForTc);

		$recForTotalShipmentTc = mysql_num_rows($resForTotalShipmentTc);

		$details1 = $recForTotalShipmentTc;
			
		$aaData[] = array('col1'=>$i.'.', 'col2'=>$aRow['CONTRACT_ID'], 'col3'=>$aRow['CONTRACT_NO'], 'col4'=>date('d-m-Y',strtotime($aRow['CONTRACT_DATE'])), 'col5'=>$aRow['VESSEL_IMO_ID'], 'col6'=>$aRow['OWN_BUSINESS_ACCOUNT'], 'col7'=>$aRow['WORKING_CURRENCY'], 'col8'=>$status, 'col9'=>$details, 'col10'=>$details1, 'col11'=>implode('<br/>',$bunkerarray), 'col12'=>number_format($totaldays,5,'.','').'/<br/>'.$performeddays.'/<br/>'.number_format(($totaldays - $performeddays),5,'.',''), 'col13'=>implode('<br/>',$closingarray));
		
	}
	
	echo json_encode(array("draw"=>intval($_POST['draw']),"recordsTotal"=>$totalData,"recordsFiltered"=>$totalFiltered,"records" => $aaData));
}

function testingLdj()
{



	$obj 		= new data();
	 $connect	= $obj->funConnect();	
	$from_date=date('Y-m-d', strtotime($_REQUEST["txtFrom_Date"]));
	$to_date=date('Y-m-d', strtotime($_REQUEST["txtTo_Date"])) ;    
	$selBType=$_REQUEST["selBType"] ;    
 	$fetch_data=[];

	//  $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." group by freight_cost_estimate_compare.COMID";
	
	$sql="SELECT *  FROM `request_master` INNER JOIN freight_cost_estimete_master on freight_cost_estimete_master.COMID= request_master.COMID  WHERE  freight_cost_estimete_master.ESTIMATE_TYPE='".$selBType."' AND    request_master.P_DATE BETWEEN '".$from_date."' AND '".$to_date."' GROUP BY request_master.REQ_ID";	



	$res = mysql_query($sql) or die($sql);
	$rec = mysql_num_rows($res);
	if($rec>0){
		while($rows = mysql_fetch_assoc($res))
		{
			$rows["table_name"]="request_master";
				array_push($fetch_data,$rows);	
		}
	}


	$sql2="SELECT * FROM `request_mastertc` INNER JOIN freight_cost_estimete_master on freight_cost_estimete_master.COMID= request_mastertc.COMID  WHERE  freight_cost_estimete_master.ESTIMATE_TYPE='".$selBType."' AND     request_mastertc.P_DATE BETWEEN '".$from_date."' AND '".$to_date."' GROUP BY request_mastertc.REQ_ID";	
	$res2 = mysql_query($sql2) or die($sql2);
	$rec2 = mysql_num_rows($res2);
	if($rec2>0){
		while($rows2 = mysql_fetch_assoc($res2))
		{
			$rows2["table_name"]="request_mastertc";
			
				array_push($fetch_data,$rows2);	
		}
	}

	
	$sql3="SELECT * FROM `invoice_hire_master` INNER JOIN freight_cost_estimete_master on freight_cost_estimete_master.COMID= invoice_hire_master.COMID  WHERE  freight_cost_estimete_master.ESTIMATE_TYPE='".$selBType."' AND    invoice_hire_master.P_DATE BETWEEN '".$from_date."' AND '".$to_date."' GROUP BY invoice_hire_master.INVOICEID";	
	$res3 = mysql_query($sql3) or die($sql3);
	$rec3 = mysql_num_rows($res3);
	if($rec3>0){
		while($rows3 = mysql_fetch_assoc($res3))
		{
			$rows3["table_name"]="invoice_hire_master";
			
				array_push($fetch_data,$rows3);	
		}
	}


	$sql4=" SELECT * FROM `invoice_hiretc_master` INNER JOIN freight_cost_estimete_master on freight_cost_estimete_master.COMID= invoice_hiretc_master.COMID  WHERE  freight_cost_estimete_master.ESTIMATE_TYPE='".$selBType."' AND    invoice_hiretc_master.P_DATE BETWEEN '".$from_date."' AND '".$to_date."' GROUP BY invoice_hiretc_master.INVOICEID";	
	$res4 = mysql_query($sql4) or die($sql4);
	$rec4 = mysql_num_rows($res4);
	if($rec4>0){
		while($rows4 = mysql_fetch_assoc($res4))
		{		
			$rows4["table_name"]="invoice_hiretc_master";
		
				array_push($fetch_data,$rows4);	
		}
	}
		


	echo 
	'<table id="df_list" class="table table-bordered table-striped" >
	<thead>
		<tr valign="top">
				<th align="left" valign="top" width="9%">Sr. No</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%">Vendor Name</th>
				<th align="left" valign="top" width="9%">Payment Type</th>
				<th align="left" valign="top" width="9%">Payment Date</th>
				<th align="left" valign="top" width="9%">Amount</th>			
					
				</thead>	';



				// $voyage_no_query = mysql_query("SELECT VOYAGE_NO FROM freight_cost_estimete_master WHERE COMID = '".$rows['COMID']."'");
			
			
				
	array_multisort(array_map('strtotime',array_column($fetch_data,'P_DATE')),
					SORT_DESC, 
					$fetch_data); 


				$ldj_query = mysql_query("SELECT DTCVENDORID FROM freight_cost_estimete_master WHERE DTCVENDORID  != NULL");
			$vendor_id= mysql_fetch_row($ldj_query)[0];
		
	
		$sel_type_query= mysql_query("SELECT ESTIMATE_TYPE FROM freight_cost_estimete_master WHERE ESTIMATE_TYPE ='".$selBType."' ");

	$sel_type_value= mysql_fetch_row($sel_type_query)[0];


	if($sel_type_value!=''){



		foreach($fetch_data as $key=>$rows):
			if ($rows['P_AMT']!=null) {	



				
if($rows['table_name'] == 'invoice_hire_master' )	{

		// $ldj_query = mysql_query("SELECT DTCVENDORID FROM freight_cost_estimete_master WHERE DTCVENDORID !=NULL AND COMID  = '".$rows['COMID']."'");
		$vendor_fetch_query = mysql_query("SELECT DTCVENDORID FROM freight_cost_estimete_master WHERE COMID = '".$rows['COMID']."' AND DTCVENDORID IS NOT NULL
		");
		$vendor_id= mysql_fetch_row($vendor_fetch_query)[0];

		$vendor_name = $obj->getVendorListNewBasedOnID($vendor_id);
		// $vendor_name = $obj->getVendorListNewBasedOnID($rows['SHIP_OWNER']);
	

		
	}	

	else if($rows['table_name'] == 'invoice_hiretc_master'){
		$tcout_query = mysql_query("SELECT TCOUTID FROM chartering_estimate_tc_master WHERE COMID = '".$rows['COMID']."' AND TCOUTID IS NOT NULL
		");
		$tcout= mysql_fetch_row($tcout_query)[0];
		/* echo "<br>";
		
		echo "<h1>".$tcout."";
		exit; */
		$vendor_fetch_query = mysql_query("SELECT TC_FINAL_HIERAGE_VENDOR FROM chartering_tc_estimate_slave1 WHERE TCOUTID='".$tcout."' ");
		$vendor_id= mysql_fetch_row($vendor_fetch_query)[0];		

		$vendor_name = $obj->getVendorListNewBasedOnID($vendor_id);
	}
	else{
		
		$vendor_name = $obj->getVendorListNewBasedOnID($rows['VENDOR']);
	}	
// $voyage_no =$obj->getFun8();

		if($rows['table_name']=='invoice_hiretc_master'){
	$voyage_no_query = mysql_query("SELECT TC_NO FROM chartering_estimate_tc_master WHERE COMID = '".$rows['COMID']."'");
		$voyage_no= mysql_fetch_row($voyage_no_query)[0];

		$imo_no_query = mysql_query("SELECT VESSEL_IMO_ID FROM chartering_estimate_tc_master WHERE COMID = '".$rows['COMID']."'");
		$imo_no= mysql_fetch_row($imo_no_query)[0];

}
else{
	$voyage_no_query = mysql_query("SELECT VOYAGE_NO FROM freight_cost_estimete_master WHERE COMID = '".$rows['COMID']."'");
	$voyage_no= mysql_fetch_row($voyage_no_query)[0];

	$imo_no_query = mysql_query("SELECT VESSEL_IMO_ID FROM freight_cost_estimete_master WHERE COMID = '".$rows['COMID']."'");
	$imo_no= mysql_fetch_row($imo_no_query)[0];
}



		$vessel_name_query = mysql_query("SELECT VESSEL_NAME FROM vessel_imo_master WHERE VESSEL_IMO_ID='".$imo_no."'");
		$vessal_name= mysql_fetch_row($vessel_name_query)[0];

		$payment_type=($rows['NAME']=='')?'HIRE':$rows['NAME'];
		echo '<tr>
				<td align="left" valign="top" width="9%">'.($key+1).'</td>	
				<td align="left" valign="top" width="9%">'.$voyage_no.'</td>
				<td align="left" valign="top" width="9%">'.$vessal_name.'</td>			    
				<td align="left" valign="top" width="9%">'.$vendor_name.'</td>
				<td align="left" valign="top" width="9%">'.$payment_type.'</td>
				<td align="left" valign="top" width="9%">'.$rows['P_DATE'].'</td>
				<td align="left" valign="top" width="9%">'.$rows['P_AMT'].'</td>			    
								
			</tr>';
			}
	endforeach;	

	}
	echo '</tr>
	</thead>
	<tbody>';	
// 		$d_t= '<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%">Voy No</th>	   
// 	</tr>
// 	</thead>
// 	<tbody>';

// 	echo $d_t;

// foreach($fetch_data as $key=>$single_data):
 

//  echo $d_t.`<tr>
//  		<td align="left" valign="top" width="9%">Sr. No</td>
// 		<td align="left" valign="top" width="9%">Nom ID</td>
// 		<td align="left" valign="top" width="9%">Voyage No.</td>
// 		<td align="left" valign="top" width="9%">Vessel Name</td>
// 		<td align="left" valign="top" width="9%">COA/Spot</td>
// 		<td align="left" valign="top" width="9%">Voy No</td>	    
// </tr>`;
// endforeach;
// echo $d_t."</tbody></table>";
// 	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%">Voy No</th>	
// 		<th align="left" valign="top" width="9%">Vessel Name</th>	
// 		<th align="left" valign="top" width="9%">Vendor</th>	
// 		<th align="left" valign="top" width="9%">Payment Type</th>	
// 		<th align="left" valign="top" width="9%">Payment Date</th>	
// 		<th align="left" valign="top" width="9%">Amount</th>	
			
	   
// 	</tr>
// 	</thead>';
	
	// if($rec4>0){
	// 	while($rows4 = mysql_fetch_assoc($res4))
	// 	{

		
	// 			array_push($fetch_data,$rows4);
	
	// 	}


	// }
// echo "<pre>";	
// foreach($fetch_data as $key=>$single_data):
//   print_r($single_data);
// endforeach;
// exit;
		
	// $obj 		= new data();
	// $connect	= $obj->funConnect();	
	// $selPort 	= $_REQUEST['selPort'];
	
	// $sql = "SELECT * From request_master ORDER BY  ";
}
function getPandLDetailedReg()
{
			$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']));
			
			if($_SESSION['iutype']=='mgmt_user'){$styledisplay = '';$colspan=8;}else{$styledisplay = 'display:none;';$colspan=7;}
			
			$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";}




			// 26 may 2022
			

			// end 26 May 2022

		// 	$sql = "select freight_cost_estimate_compare.COMID as COMID,freight_cost_estimete_master.BL_QTY_FREIGHT as cargo_qty, freight_cost_estimete_master.CARGO_ID, freight_cost_estimete_master.TANKER_RADIO_SINGLE_DIS, 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.LAYCAN_START_DATE  as LAYCAN_START_DATE , 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_estimate_compare.FCAID as FCAID,cost_sheet_name_master.COST_SHEETID as SHEET_NO,freight_cost_estimete_master.VOYAGE_NO as VOYAGE_NO, freight_cost_estimete_master.VOYAGE_NAME as VOYAGE_NAME,freight_cost_estimete_slave17.HIRE_DAYS as hire_days, freight_cost_estimete_slave17.HIRE_RATE as hire_rate ,freight_cost_estimete_master.FINAL_HIERAGE_AMOUNT as hire_amt ,freight_cost_estimete_master.FREIGHT_GROSS as FREIGHT_GROSS , freight_invoice_master.NET_AMOUNT as NET_AMT,vessel_imo_master.DWT as DWT ,(select CONTACT_PERSON from login where login.LOGINID = freight_cost_estimate_compare.OPERATOR) as OPERATOR ,(SELECT PortName from port_master WHERE PortId = freight_cost_estimete_slave1.FROM_PORT
		// 	) as FROM_PORT ,freight_cost_estimete_slave1.FCAID as FCAIDT ,(SELECT PortName from port_master WHERE PortId = freight_cost_estimete_slave1.TO_PORT ) as TO_PORT,freight_cost_estimete_master.FCAID ,
		// 	freight_cost_estimete_slave1.FROM_PORT as FROM_PORTIDD, 
		// 	freight_cost_estimete_master.REVENUES_FREIGHT	
			
		// 	from freight_cost_estimete_master 	
		// 	inner join freight_cost_estimate_compare on freight_cost_estimate_compare.FCAID= freight_cost_estimete_master.FCAID 	
		// 	inner join freight_cost_estimete_slave17 on freight_cost_estimete_slave17.FCAID = freight_cost_estimete_master.FCAID 	
		// 	inner join freight_invoice_master   on freight_invoice_master.COMID= freight_cost_estimete_master.COMID 
		// 	inner join vessel_imo_master on vessel_imo_master.VESSEL_IMO_ID= freight_cost_estimete_master.VESSEL_IMO_ID 
		// 	inner join freight_cost_estimete_slave1 on freight_cost_estimete_slave1.FCAID= freight_cost_estimate_compare.FCAID 
		// 	inner join cost_sheet_name_master  on cost_sheet_name_master.COMID= freight_cost_estimete_master.COMID 

			
			
		// WHERE
		
		
		// freight_cost_estimate_compare.MODULEID='".$_SESSION['moduleid']."'  
		// AND     cost_sheet_name_master.COST_SHEETID != '0.00'
		// AND      freight_cost_estimate_compare.MCOMPANYID='".$_SESSION['company']."' 
		// and		freight_cost_estimate_compare.FINAL_ID!='' 
		// 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_estimete_master.COMID ";
		// freight_cost_estimate_compare.STATUS=1 and
		$sql = "select freight_cost_estimate_compare.COMID as COMID,freight_cost_estimete_master.FCAID, (select CONTACT_PERSON from login where login.LOGINID=freight_cost_estimate_compare.OPERATOR) as OPSUSER, freight_cost_estimate_compare.COAAID as COAAID, freight_cost_estimate_compare.FCAID as FCAID, freight_cost_estimete_master.VESSEL_IMO_ID as VESSEL_IMO_ID,freight_cost_estimete_master.PERIODID as PERIODID, 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_estimete_master.TRANS_DATE>='".$txtFrom_Date."' and  freight_cost_estimete_master.TRANS_DATE<='".$txtTo_Date."' and freight_cost_estimete_master.ESTIMATE_TYPE='".$_SESSION['selBType']."' and COAAID is NULL and FINAL_ID!='' order by date(freight_cost_estimete_master.FINAL_DATETIME) desc";







	
		// $sql = "select * from freight_cost_estimete_master WHERE freight_cost_estimete_master.TRANS_DATE>='".$txtFrom_Date."' and freight_cost_estimete_master.TRANS_DATE<='".$txtTo_Date."' group by freight_cost_estimete_master.COMID";



	

	

			$res 		  = mysql_query($sql);
			$rec     	  = mysql_num_rows($res);
			$j=1;
			$cost_sheet_id = "";
			$arr = array();

			// <th  align="left"  valign="top" width="10%">LP Dem/DES</th>
			
			echo '<table id="sf_list" class="table table-bordered table-striped dataTable">
				<thead>
					<tr>
						<th  align="left" valign="top" width="10%">Sr.&nbsp;No.</th>
						<th  align="left" valign="top" width="10%">Type</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>';
						}

						// if($_SESSION['iutype']=='mgmt_user'){$styledisplay = '';}else{$styledisplay = 'display:none;';}

						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%">&nbsp;&nbsp;DWT&nbsp;&nbsp;</th>
						<th  valign="top" width="10%">Cargo&nbsp;Name</th>
						<th  valign="top" width="10%">Cargo Qty</th>
						
						<th  align="left" valign="top" width="10%">CP&nbsp;Date</th>
						<th  align="left" valign="top" width="10%">Voyage Laycan Commencement</th>
						<th  align="left" valign="top" width="10%">Owner&nbsp;Name (TC Hire In)</th>
						<th  align="left" valign="top" width="10%">Hire Days</th>
						<th  align="left" valign="top" width="10%">Hire Rate</th>
						<th  align="left" valign="top" width="10%">Hire Amount</th>
						<th  align="left" valign="top" width="10%">Freight Rate / MT</th>
						<th  align="left" valign="top" width="10%">Total Freight / MT</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%">Operator</th>
						<th  align="left"  valign="top" width="10%">From Port</th>
						<th  align="left"  valign="top" width="10%">LP FDA</th>
						<th  align="left"  valign="top" width="10%">LP Dem/Des</th>
						
						<th  align="left"  valign="top" width="10%">To Port</th>
						<th  align="left"  valign="top" width="10%">DP FDA</th>
						<th  align="left"  valign="top" width="10%">DP Dem/Des</th>
						<th  align="left"  valign="top" width="10%">Amt Paid to WRC</th>
						<th  align="left"  valign="top" width="10%">WRC</th>
						<th  align="left"  valign="top" width="10%">P & I Survey Vendor</th>
						<th  align="left"  valign="top" width="10%">P & I Survey</th>
						<th  align="left"  valign="top" width="10%">P & I  Vendor</th>
						<th  align="left"  valign="top" width="10%">P & I Cost</th>
						<th  align="left"  valign="top" width="10%">CP Services Vendor</th>
						<th  align="left"  valign="top" width="10%">CP Services</th>
						<th  align="left"  valign="top" width="10%">CP Review Vendor</th>
						<th  align="left"  valign="top" width="10%">CP Review</th>
						<th  align="left"  valign="top" width="10%">Survey BP Vendor</th>
						<th  align="left"  valign="top" width="10%">Survey BP</th>
						<th  align="left"  valign="top" width="10%">Survey Del Port Vendor</th>
						<th  align="left"  valign="top" width="10%">Survey Del Port</th>
						<th  align="left"  valign="top" width="10%">Survey Re Del Port Vendor</th>
						<th  align="left"  valign="top" width="10%">Survey Re Del Port</th>
						<th  align="left"  valign="top" width="10%">Misc Vendor</th>
						<th  align="left"  valign="top" width="10%">Misc</th>
						<th  align="left"  valign="top" width="10%">Owner Brokerage Vendor</th>
						<th  align="left"  valign="top" width="10%">Owner Brokerage</th>
						<th  align="left"  valign="top" width="10%">Charterers Brokerage Vendor</th>
						<th  align="left"  valign="top" width="10%">Charterers Brokerage</th>
						
						
						
						<th  align="left"  valign="top" width="10%"> IFO Bunker Supplier</th>
						<th  align="left"  valign="top" width="10%">IFO Grade</th>
						<th  align="left"  valign="top" width="10%">IFO Qty</th>
						<th  align="left"  valign="top" width="10%">IFO Price</th>
						<th  align="left"  valign="top" width="10%">IFO Cost</th>


						<th  align="left"  valign="top" width="10%">MDO Bunker Supplier</th>
						<th  align="left"  valign="top" width="10%">MDO Grade</th>
						<th  align="left"  valign="top" width="10%">MDO Qty</th>
						<th  align="left"  valign="top" width="10%">MDO Price</th>
						<th  align="left"  valign="top" width="10%">MDO Cost</th>


						<th  align="left"  valign="top" width="10%">Total Voyage Earning</th>
						<th  align="left"  valign="top" width="10%">Expense</th>';
						
						if($_SESSION['iutype']=='mgmt_user'){
							echo '<th  align="left"  valign="top" width="10%">P & L</th>'; 
						}
						
						
						


						 echo'</tr>
					
				</thead>
			<tbody>';
			
			if($rec == 0)
			{
				
			}else{

				while($rows = mysql_fetch_assoc($res))
				{




				$s_id = $obj->getTCICostSheetID($rows['COMID'],$rows['SHEET_NO']);
				$obj->viewFreightCostEstimationTempleteRecordsNew($s_id);


				$lpc_query=mysql_query("SELECT LOAD_PORT_COST from freight_cost_estimete_slave1 WHERE FCAID = '".$obj->getFun1()."'  AND LOAD_PORT_COST > 0");
				$lpc= mysql_fetch_row($lpc_query)[0];


				$dpc_query=mysql_query("SELECT DISC_PORT_COST from freight_cost_estimete_slave1 WHERE FCAID = '".$obj->getFun1()."'  AND DISC_PORT_COST > 0");
				$dpc=mysql_fetch_row($dpc_query)[0];



			// $total_qty_query=mysql_query("select SUM(QUANTITY) from freight_cost_estimete_slave7 where FCAID='".$rows['FCAID']."'");

			
			// $total_qty= mysql_fetch_row($total_qty_query)[0];

			// $cargo_qty=($rows['cargo_qty']=='0.000')?$total_qty:$rows['cargo_qty'];


			


			$cost_sheet_id_query = mysql_query("select * from cost_sheet_name_master where COMID='".$rows['COMID']."' and MODULEID='".$_SESSION['moduleid']."' and MCOMPANYID='".$_SESSION['company']."'");

			$cost_sheet_id=mysql_fetch_assoc($cost_sheet_id_query)['COST_SHEETID'];

			

			$com_id_for_cargo = $obj->getTCICostSheetID($rows['COMID'],$cost_sheet_id);
			$obj->viewFreightCostEstimationTempleteRecordsNew($com_id_for_cargo);
				$cargo_qty=$obj->getFun244();



				
				$hire_days_query=mysql_query("select * from freight_cost_estimete_slave17 where FCAID='".$obj->getFun1()."'");
			$hire_data=	mysql_fetch_assoc($hire_days_query);		
			$hire_days=	$hire_data['HIRE_DAYS'];
			$hire_rate=	$hire_data['HIRE_RATE'];
			$hire_amt=	$hire_data['HIRE_AMT'];

		


			if($obj->getFun109()=="" || $obj->getFun109()=="0000-00-00" || $obj->getFun109()=="1970-01-01"){$voyage_laycan_commencement = "";}else{$voyage_laycan_commencement = date('d-m-Y',strtotime($obj->getFun109()));}

			

			$wrc_query=mysql_query("select * from freight_cost_estimete_slave3 where FCAID='".$obj->getFun1()."' and IDENTIFY='ORC' and RAW_AMOUNT>0 AND IDENTY_ID ='27'");
			$wrc=mysql_fetch_assoc($wrc_query);
			$wrc_vendor_name_query  = mysql_query("select * from vendor_master where CODE='".$wrc['VENDORID']."' and MCOMPANYID='".$_SESSION['company']."'");
			$wrc_vendor_name = mysql_fetch_assoc($wrc_vendor_name_query)['NAME'];
			$wrc_amt=$wrc['RAW_AMOUNT'];


			$pi_query=mysql_query("select * from freight_cost_estimete_slave3 where FCAID='".$obj->getFun1()."' and IDENTIFY='ORC' and RAW_AMOUNT>0 AND IDENTY_ID ='3'");
			$pi_assoc=mysql_fetch_assoc($pi_query);
			$pi_vendor_name_query  = mysql_query("select * from vendor_master where CODE='".$pi_assoc['VENDORID']."' and MCOMPANYID='".$_SESSION['company']."'");
			$pi_vendor_name = mysql_fetch_assoc($pi_vendor_name_query)['NAME'];
			$pi_amt=$pi_assoc['RAW_AMOUNT'];



			$pi_c_query=mysql_query("select * from freight_cost_estimete_slave3 where FCAID='".$obj->getFun1()."' and IDENTIFY='ORC' and RAW_AMOUNT>0 AND IDENTY_ID ='7'");
			$pi_c_assoc=mysql_fetch_assoc($pi_c_query);
			$pi_c_vendor_name_query  = mysql_query("select * from vendor_master where CODE='".$pi_c_assoc['VENDORID']."' and MCOMPANYID='".$_SESSION['company']."'");
			$pi_c_vendor_name = mysql_fetch_assoc($pi_c_vendor_name_query)['NAME'];
			$pi_c_amt=$pi_c_assoc['RAW_AMOUNT'];


			$cp_services_e_query=mysql_query("select * from freight_cost_estimete_slave3 where FCAID='".$obj->getFun1()."' and IDENTIFY='ORC' and RAW_AMOUNT>0 AND IDENTY_ID ='28'");
			$cp_service_assoc=mysql_fetch_assoc($cp_services_e_query);
			$cp_services_query  = mysql_query("select * from vendor_master where CODE='".$cp_service_assoc['VENDORID']."' and MCOMPANYID='".$_SESSION['company']."'");
			$cp_services_vendor_name = mysql_fetch_assoc($cp_services_query)['NAME'];
			$cp_service_amt=$cp_service_assoc['RAW_AMOUNT'];


			$cp_review_e_query=mysql_query("select * from freight_cost_estimete_slave3 where FCAID='".$obj->getFun1()."' and IDENTIFY='ORC' and RAW_AMOUNT>0 AND IDENTY_ID ='29'");
			$cp_review_assoc=mysql_fetch_assoc($cp_review_e_query);
			$cp_review_query  = mysql_query("select * from vendor_master where CODE='".$cp_review_assoc['VENDORID']."' and MCOMPANYID='".$_SESSION['company']."'");
			$cp_review_vendor_name = mysql_fetch_assoc($cp_review_query)['NAME'];
			$cp_review_amt=$cp_review_assoc['RAW_AMOUNT'];


			$servey_bp_e_query=mysql_query("select * from freight_cost_estimete_slave3 where FCAID='".$obj->getFun1()."' and IDENTIFY='ORC' and RAW_AMOUNT>0 AND IDENTY_ID ='32'");
			$servey_bp_assoc=mysql_fetch_assoc($servey_bp_e_query);
			$servey_bp_query  = mysql_query("select * from vendor_master where CODE='".$servey_bp_assoc['VENDORID']."' and MCOMPANYID='".$_SESSION['company']."'");
			$servey_bp_vendor_name = mysql_fetch_assoc($servey_bp_query)['NAME'];
			$servey_bp_amt=$servey_bp_assoc['RAW_AMOUNT'];



			$servey_del_port_e_query=mysql_query("select * from freight_cost_estimete_slave3 where FCAID='".$obj->getFun1()."' and IDENTIFY='ORC' and RAW_AMOUNT>0 AND IDENTY_ID ='30'");
			$servey_del_port_assoc=mysql_fetch_assoc($servey_del_port_e_query);
			$servey_del_port_query  = mysql_query("select * from vendor_master where CODE='".$servey_del_port_assoc['VENDORID']."' and MCOMPANYID='".$_SESSION['company']."'");
			$servey_del_port_vendor_name = mysql_fetch_assoc($servey_del_port_query)['NAME'];
			$servey_del_port_amt=$servey_del_port_assoc['RAW_AMOUNT'];


			$servey_redel_e_query=mysql_query("select * from freight_cost_estimete_slave3 where FCAID='".$obj->getFun1()."' and IDENTIFY='ORC' and RAW_AMOUNT>0 AND IDENTY_ID ='31'");
			$servey_redel_assoc=mysql_fetch_assoc($servey_redel_e_query);
			$servey_redel_query  = mysql_query("select * from vendor_master where CODE='".$servey_redel_assoc['VENDORID']."' and MCOMPANYID='".$_SESSION['company']."'");
			$servey_redel_vendor_name = mysql_fetch_assoc($servey_redel_query)['NAME'];
			$servey_redel_amt=$servey_redel_assoc['RAW_AMOUNT'];



			$misc_e_query=mysql_query("select * from freight_cost_estimete_slave3 where FCAID='".$obj->getFun1()."' and IDENTIFY='ORC' and RAW_AMOUNT>0 AND IDENTY_ID ='5'");
			$misc_assoc=mysql_fetch_assoc($misc_e_query);
			$misc_query  = mysql_query("select * from vendor_master where CODE='".$misc_assoc['VENDORID']."' and MCOMPANYID='".$_SESSION['company']."'");
			$misc_vendor_name = mysql_fetch_assoc($misc_query)['NAME'];
			$misc_amt=$misc_assoc['RAW_AMOUNT'];



			$owner_brokerage_e_query=mysql_query("select * from freight_cost_estimete_slave3 where FCAID='".$obj->getFun1()."' and IDENTIFY='ORC' and RAW_AMOUNT>0 AND IDENTY_ID ='35'");
			$owner_brokerage_assoc=mysql_fetch_assoc($owner_brokerage_e_query);
			$owner_brokerage_query  = mysql_query("select * from vendor_master where CODE='".$owner_brokerage_assoc['VENDORID']."' and MCOMPANYID='".$_SESSION['company']."'");
			$owner_brokerage_vendor_name = mysql_fetch_assoc($owner_brokerage_query)['NAME'];
			$owner_brokerage_amt=$owner_brokerage_assoc['RAW_AMOUNT'];

			$charterers_brokerage_e_query=mysql_query("select * from freight_cost_estimete_slave3 where FCAID='".$obj->getFun1()."' and IDENTIFY='ORC' and RAW_AMOUNT>0 AND IDENTY_ID ='34'");
			$charterers_brokerage_assoc=mysql_fetch_assoc($charterers_brokerage_e_query);
			$charterers_brokerage_query  = mysql_query("select * from vendor_master where CODE='".$charterers_brokerage_assoc['VENDORID']."' and MCOMPANYID='".$_SESSION['company']."'");
			$charterers_brokerage_vendor_name = mysql_fetch_assoc($charterers_brokerage_query)['NAME'];
			$charterers_brokerage_amt=$charterers_brokerage_assoc['RAW_AMOUNT'];



			$owner_name_code_query=mysql_query("select DTCVENDORID from freight_cost_estimete_master where FCAID='".$obj->getFun1()."' and MCOMPANYID='".$_SESSION['company']."'");

			$owner_name_query=mysql_query("select NAME from vendor_master where CODE='".mysql_fetch_assoc($owner_name_code_query)['DTCVENDORID']."' and MCOMPANYID='".$_SESSION['company']."'");

			$owner_name=mysql_fetch_assoc($owner_name_query)['NAME'];





			$ifo_fdo_query=mysql_query("select 
					freight_cost_estimete_slave8.FCA_SLAVE8ID,
					freight_cost_estimete_slave8.FCAID,
					freight_cost_estimete_slave8.BUNKERGRADEID,
					freight_cost_estimete_slave8.COST,
					freight_cost_estimete_slave8.VENDORID,
					freight_cost_estimete_slave8.COST_MT,
					freight_cost_estimete_slave8.QTY,
					freight_cost_estimete_slave8.PRICE,
					freight_cost_estimete_slave8.PORT ,
					bunker_grade_master.BUNKERTYPE,
					bunker_grade_master.NAME 
				from freight_cost_estimete_slave8 
				inner join bunker_grade_master   on bunker_grade_master.BUNKERGRADEID = freight_cost_estimete_slave8.BUNKERGRADEID   
				where freight_cost_estimete_slave8.FCAID='".$obj->getFun1()."' and freight_cost_estimete_slave8.IDENTIFY='SUPPLY' ORDER BY bunker_grade_master.BUNKERTYPE ");

				$bunker_vendor_name_ifo="";
				$bunker_grade_ifo="";
				$bunker_qty_ifo="";
				$bunker_price_ifo="";
				$bunker_cost_ifo="";
				
				
				
				$bunker_vendor_name_mdo="";
				$bunker_grade_mdo="";
				$bunker_qty_mdo="";
				$bunker_price_mdo="";
				$bunker_cost_mdo="";

	

			if(mysql_num_rows($ifo_fdo_query)>0){
				
				while($ifo_fdo=mysql_fetch_assoc($ifo_fdo_query)){
					$ven_n_query  = mysql_query("select NAME from vendor_master where CODE='".$ifo_fdo['VENDORID']."'");
					$ven_name=mysql_fetch_assoc($ven_n_query)['NAME'];
					if($ifo_fdo['BUNKERTYPE']=='IFO'){

						
						$bunker_vendor_name_ifo.=$ven_name.",";
						$bunker_grade_ifo.=$ifo_fdo['NAME'].",";
						$bunker_qty_ifo.=$ifo_fdo['QTY'].",";
						$bunker_price_ifo.=$ifo_fdo['PRICE'].",";
						$bunker_cost_ifo.=$ifo_fdo['QTY']*$ifo_fdo['PRICE'].",";
					}else{
				
						$bunker_vendor_name_mdo.=$ven_name.",";
						$bunker_grade_mdo.=$ifo_fdo['NAME'].",";
						$bunker_qty_mdo.=$ifo_fdo['QTY'].",";
						$bunker_price_mdo.=$ifo_fdo['PRICE'].",";
						$bunker_cost_mdo.=$ifo_fdo['QTY']*$ifo_fdo['PRICE'].",";
					}
				}
			}					


				$bunker_vendor_name_ifo=rtrim($bunker_vendor_name_ifo,",");
				$bunker_grade_ifo=rtrim($bunker_grade_ifo,",");
				$bunker_qty_ifo=rtrim($bunker_qty_ifo,",");
				$bunker_price_ifo=rtrim($bunker_price_ifo,",");
				$bunker_cost_ifo=rtrim($bunker_cost_ifo,",");

				$bunker_vendor_name_mdo=rtrim($bunker_vendor_name_mdo,",");
				$bunker_grade_mdo=rtrim($bunker_grade_mdo,",");
				$bunker_qty_mdo=rtrim($bunker_qty_mdo,",");
				$bunker_price_mdo=rtrim($bunker_price_mdo,",");
				$bunker_cost_mdo=rtrim($bunker_cost_mdo,",");




				$t_voy_earning_q=mysql_query("select TOTAL_VOYAGE_EARNING,TOTAL_ORC_EXP_AMT,BUNKER_EXPENSES,PORT_EXPENSES from freight_cost_estimete_master where FCAID='".$obj->getFun1()."'");

				$revenues_freight_data=mysql_fetch_assoc($t_voy_earning_q);
				$total_voyage_earnings=$revenues_freight_data['TOTAL_VOYAGE_EARNING'];

				$expenses = $revenues_freight_data['TOTAL_ORC_EXP_AMT'] +$revenues_freight_data['BUNKER_EXPENSES'] +$revenues_freight_data['PORT_EXPENSES'];
			
			$lp_dem_des_query= mysql_query("select DDCLP_REALCOST FROM  freight_cost_estimete_slave1 where FCAID='".$obj->getFun1()."' AND DDCLP_REALCOST !=0 ");

			$lp_dem_des=mysql_fetch_assoc($lp_dem_des_query)['DDCLP_REALCOST'];

			$dp_dem_des_query= mysql_query("select DDCDP_REALCOST FROM  freight_cost_estimete_slave1 where FCAID='".$obj->getFun1()."' AND DDCDP_REALCOST !=0 ");

			$dp_dem_des=mysql_fetch_assoc($dp_dem_des_query)['DDCDP_REALCOST'];


			$freight_rate_query=mysql_query("select FREIGHT_GROSS FROM  freight_cost_estimete_master where FCAID='".$obj->getFun1()."' ");
			$freight_rate=mysql_fetch_assoc($freight_rate_query)['FREIGHT_GROSS'];


			$total_freight_rate_query=mysql_query("select TOTAL_PREIGHT_ADJ FROM  freight_cost_estimete_master where FCAID='".$obj->getFun1()."' ");
			$total_freight=mysql_fetch_assoc($total_freight_rate_query)['TOTAL_PREIGHT_ADJ'];





			// from port
			$from_port_query=mysql_query("SELECT FROM_PORT, LOAD_PORT_COST from freight_cost_estimete_slave1 where FCAID='".$obj->getFun1()."' AND LOAD_PORT_COST !=0  ");

			$from_port="";
			$lp_fda="";

			while($from_port_data=mysql_fetch_assoc($from_port_query)){


				$from_port.=$obj->getPortNameBasedOnID($from_port_data['FROM_PORT']).",";
				$lp_fda.=$from_port_data['LOAD_PORT_COST'].",";

			}


			$from_port=rtrim($from_port,",");
			$lp_fda=rtrim($lp_fda,",");


			$to_port_query=mysql_query("SELECT TO_PORT, DISC_PORT_COST from freight_cost_estimete_slave1 where FCAID='".$obj->getFun1()."' AND DISC_PORT_COST !=0  ");

			$to_port="";
			$dp_fda="";

			while($to_port_data=mysql_fetch_assoc($to_port_query)){


				$to_port.=$obj->getPortNameBasedOnID($to_port_data['TO_PORT']).",";
				$dp_fda.=$to_port_data['DISC_PORT_COST'].",";

			}


				$to_port=rtrim($to_port,",");
				$dp_fda=rtrim($dp_fda,",");

 

	$obj->viewFreightCostEstimationTempleteRecordsNew($rows['FCAID']);

	$materialid = $obj->getCompareEstimateData($rows['COMID'],"CARGO_ID");											 

		$pic_user_query=mysql_query("SELECT * FROM login WHERE STATUS=1 and USER_TYPE in ('internal_user','mgmt_user') and LOGINID=".$obj->getFun261()."");

														$pic_user= mysql_fetch_assoc($pic_user_query)['CONTACT_PERSON'];
					


			$l_cost_sheet_id = $obj->getLatestCostSheetID($rows['COMID']);
			$cpdate = $obj->getCompareEstimateData($rows['COMID'],"TRANS_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">VC Out</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">'.$pic_user.'</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->getCargoNameListForMultipleNamemultiple($materialid).'</td>';

			
			echo '<td align="left" valign="middle">'.$cargo_qty.'</td>';
			echo '<td align="left" valign="middle">'.$cpdate.'</td>';

			
			echo '<td align="left" valign="middle">'.$voyage_laycan_commencement.'</td>';

			
			// echo '<td align="left" valign="middle">'.$obj->getVendorNameBasedOnID($rows['DTCVENDORID']).'</td>';
			echo '<td align="left" valign="middle">'.$owner_name.'</td>';

		
			echo '<td align="left" valign="middle">'.$hire_days.'</td>';
			echo '<td align="left" valign="middle">'.$hire_rate.'</td>';
			echo '<td align="left" valign="middle">'.$hire_amt.'</td>';
			echo '<td align="left" valign="middle">'.$freight_rate.'</td>';

		
			echo '<td align="left" valign="middle">'.$total_freight.'</td>';
			$charterers = '';
			if($obj->getCompareEstimateData($rows['COMID'],"ESTIMATE_TYPE")==3 && $obj->getCompareEstimateData($rows['COMID'],"QTY_TYPE_RADIO") == 2)
			{
				$vendor_arr = array();
				$sql12 = "select QTY_VENDORID from freight_cost_estimete_slave7 where FCAID='".$obj->getCompareEstimateData($rows['COMID'],"FCAID")."' group by QTY_VENDORID";
				$res12 = mysql_query($sql12);
				while($row12 = mysql_fetch_assoc($res12))
				{
					$vendor_arr[]  = $obj->getVendorListNewBasedOnID($row12['QTY_VENDORID']);
				}
				$charterers = implode(',', $vendor_arr);
			}
			else
			{
				$charterers = $obj->getVendorListNewBasedOnID($obj->getCompareEstimateData($rows['COMID'],"FGFF_VENDORID"))."";
			}
			echo '<td align="left" valign="middle">'.$charterers.'</td>';
		
			echo '<td align="left" valign="middle">'.$fixturedate.'</td>';
		
			echo '<td align="left" valign="middle">'.$rows['OPSUSER'].'</td>';
			echo '<td align="left" valign="middle">'.$from_port.'</td>';
			echo '<td align="left" valign="middle">'.$lp_fda.'</td>';
			echo '<td align="left" valign="middle">'.$lp_dem_des.'</td>';
			
			// echo '<td align="left" valign="middle">LOKENDRA</td>';
			echo '<td align="left" valign="middle">'.$to_port.'</td>';
			echo '<td align="left" valign="middle">'.$dp_fda.'</td>';
			echo '<td align="left" valign="middle">'.$dp_dem_des.'</td>';
			
			$res14 = mysql_query("select ACTUAL_PL from freight_cost_estimete_master where COMID='".$rows['COMID']."' and SHEET_NO!='' order by FCAID asc");

		
			
			$pl=	mysql_fetch_row($res14);
			
			if($_SESSION['iutype']=='mgmt_user'){$styledisplay = '';}else{$styledisplay = 'display:none;';}
			echo '<td align="left" valign="middle">'.$wrc_vendor_name.'</td>';
			echo '<td align="left" valign="middle">'.$wrc_amt.'</td>';
			echo '<td align="left" valign="middle">'.$pi_vendor_name.'</td>';
			echo '<td align="left" valign="middle">'.$pi_amt.'</td>';
			echo '<td align="left" valign="middle">'.$pi_c_vendor_name.'</td>';
			echo '<td align="left" valign="middle">'.$pi_c_amt.'</td>';
			echo '<td align="left" valign="middle">'.$cp_services_vendor_name.'</td>';
			echo '<td align="left" valign="middle">'.$cp_service_amt.'</td>';
			echo '<td align="left" valign="middle">'.$cp_review_vendor_name.'</td>';
			echo '<td align="left" valign="middle">'.$cp_review_amt.'</td>';
			echo '<td align="left" valign="middle">'.$servey_bp_vendor_name.'</td>';
			echo '<td align="left" valign="middle">'.$servey_bp_amt.'</td>';
			echo '<td align="left" valign="middle">'.$servey_del_port_vendor_name.'</td>';
			echo '<td align="left" valign="middle">'.$servey_del_port_amt.'</td>';
			echo '<td align="left" valign="middle">'.$servey_redel_vendor_name.'</td>';
			echo '<td align="left" valign="middle">'.$servey_redel_amt.'</td>';
			echo '<td align="left" valign="middle">'.$misc_vendor_name.'</td>';
			echo '<td align="left" valign="middle">'.$misc_amt.'</td>';
			echo '<td align="left" valign="middle">'.$owner_brokerage_vendor_name.'</td>';
			echo '<td align="left" valign="middle">'.$owner_brokerage_amt.'</td>';
			echo '<td align="left" valign="middle">'.$charterers_brokerage_vendor_name.'</td>';
			echo '<td align="left" valign="middle">'.$charterers_brokerage_amt.'</td>';
				echo '<td align="left" valign="middle">'.$bunker_vendor_name_ifo.'</td>';
				echo '<td align="left" valign="middle">'.$bunker_grade_ifo.'</td>';
				echo '<td align="left" valign="middle">'.$bunker_qty_ifo.'</td>';
				echo '<td align="left" valign="middle">'.$bunker_price_ifo.'</td>';
				echo '<td align="left" valign="middle">'.$bunker_cost_ifo.'</td>';
				echo '<td align="left" valign="middle">'.$bunker_vendor_name_mdo.'</td>';
				echo '<td align="left" valign="middle">'.$bunker_grade_mdo.'</td>';
				echo '<td align="left" valign="middle">'.$bunker_qty_mdo.'</td>';
				echo '<td align="left" valign="middle">'.$bunker_price_mdo.'</td>';
				echo '<td align="left" valign="middle">'.$bunker_cost_mdo.'</td>';
				echo '<td align="left" valign="middle">'.$total_voyage_earnings.'</td>';
				echo '<td align="left" valign="middle">'.$expenses.'</td>';
		
		
		if($_SESSION['iutype']=='mgmt_user'){
			echo '<td align="left"  valign="middle">'.$pl[0].'</td>';
			}

					echo '</tr>';



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


?>