<?php
session_start();
require_once("../../includes/display_internal_user_dryout.inc.php");
require_once("../../includes/functions_internal_user_dryout.inc.php");
$obj = new data();
$connect = $obj->funConnect();
$display = new display();
$display->logout_iu();



if (@$_REQUEST['action'] == 'submit') {
	if ($_REQUEST['txtStatus'] == "") {
		if ($_REQUEST['txtComid2'] == "") {
			$msg = $obj->insertActualCostSheetName();
		} else {
			$msg = $obj->deleteInOpsEntry($_REQUEST['txtComid2']);
		}
		header('Location:./in_ops_at_glance.php?msg=3');
	} else if ($_REQUEST['txtStatus'] == "1") {
		$msg = $obj->convertToPostOps($_REQUEST['txtComid2'], $_REQUEST['txtPostfixPIC']);
	} else if ($_REQUEST['txtStatus'] == "2") {
	}

	header('Location:./in_ops_at_glance.php?msg=3');
}

if (@$_REQUEST['action1'] == 'submit1') {
	if (@$_REQUEST['txtuid'] == 1) {
		$msg = $obj->insertPerfAtSeaUploadDetails();
		header('Location:./in_ops_at_glance.php?msg=' . $msg);
	} else if (@$_REQUEST['txtuid'] == 2) {
		$msg = $obj->insertPerfAtPortUploadDetails();
		header('Location:./in_ops_at_glance.php?msg=' . $msg);
	}
}

if (isset($_REQUEST['selYear']) && $_REQUEST['selYear'] != "") {
	$selYear = $_REQUEST['selYear'];
	$_SESSION['selYear'] = $selYear;
} else {
	$selYear = $_SESSION['selYear'];
}

if (isset($_REQUEST['selBType']) && $_REQUEST['selBType'] != "") {
	$selBType = $_SESSION['selBType'] = $_REQUEST['selBType'];
} else if (isset($_SESSION['selBType'])) {
	$selBType = $_SESSION['selBType'];
} else {
	unset($_SESSION['selBType']);
	$selBType = '';
}

if (isset($_POST['op']) && isset($_POST['id'])) {


	$change_op_query = mysql_query("UPDATE freight_cost_estimate_compare SET OPERATOR='" . $_POST['op'] . "'  WHERE  COMID = '" . $_POST['id'] . "'");


	if ($change_op_query) {
		echo true;
		return;
	}

	echo false;
	return;
}


$pagename = basename($_SERVER['PHP_SELF']);

$uid	  = $_SESSION['uid'];
$moduleid = $_SESSION['moduleid'];
$rights = $obj->getUserRights($uid, $moduleid, 4);

?>
<!DOCTYPE html>
<html>

<head>
	<meta charset="UTF-8">
	<title><?php $display->title(); ?></title>
	<?php $display->favicon(); ?>
	<meta content='width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no' name='viewport'>
	<?php $display->css(); ?>
	<link href="../../css/datatables/dataTables.bootstrap.css" rel="stylesheet" type="text/css" />

	<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
	<script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/1.3.3/jspdf.min.js"></script>
	<script src="https://html2canvas.hertzen.com/dist/html2canvas.js"></script>


	<!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
	<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
	<!--[if lt IE 9]>
  <script src="../js/html5shiv.js"></script>
  <script src="../js/respond.min.js"></script>
<![endif]-->

	<style>
		.tablesorter th {
			position: -webkit-sticky;
			background-color: white !important;
			position: sticky;
			top: -10px;
			border-top: #ddd 1px solid !important;
			z-index: 999 !important;
		}

		.tooltip-inner {
			background-color: #eee;
			color: #000;
			font-weight: bold;
			width: 500px;
			/* Fixed width */
			max-width: none;
			/* Disable Bootstrap's default limit */
			white-space: normal;
			/* Allow multiline text */
		}

		.tooltip.top .tooltip-arrow {
			border-top-color: #eee;
		}

		.tooltip.right .tooltip-arrow {
			border-right-color: #eee;
		}

		.tooltip.bottom .tooltip-arrow {
			border-bottom-color: #eee;
		}

		.tooltip.left .tooltip-arrow {
			border-left-color: #eee;
		}
	</style>
</head>

<body class="skin-blue fixed">
	<!-- header logo: style can be found in header.less -->
	<?php $display->header_tag(); ?>
	<div class="wrapper row-offcanvas row-offcanvas-left">
		<?php $display->leftmenu(5); ?>
		<aside class="right-side">
			<!-- Content Header (Page header) -->
			<section class="content-header">
				<h1>
					<i class="fa fa-leaf"></i>&nbsp;Ops VC&nbsp;&nbsp;&nbsp;&nbsp;<small>
						<div class="headline text-center" id="time" style="color:#000; font-weight:bold; font-size:12px;"></div>
					</small>
				</h1>
				<ol class="breadcrumb">
					<li><a href="../"><i class="fa fa-home"></i> Home</a></li>
					<li class="active">Ops VC&nbsp;&nbsp;&nbsp;>&nbsp;&nbsp;&nbsp;In Ops at a glance VC</li>
				</ol>
			</section>

			<!-- Main content -->
			<section class="content">
				<!--   content put here..................-->
				<?php if (isset($_REQUEST['msg'])) {
					$msg = $_REQUEST['msg'];
					if ($msg == 0) { ?>
						<div class="alert alert-success alert-dismissable">
							<i class="fa fa-check"></i>
							<button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
							<b>Congratulations!</b> In Ops at a glance added/updated successfully.
						</div>
					<?php } ?>
					<?php if ($msg == 4) { ?>
						<div class="alert alert-success alert-dismissable">
							<i class="fa fa-ban"></i>
							<button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
							<b>Congratulations!</b> new sheet added successfully.
						</div>
					<?php } ?>
					<?php if ($msg == 1) { ?>
						<div class="alert alert-success alert-dismissable">
							<i class="fa fa-ban"></i>
							<button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
							<b>Congratulations!</b> In Ops at a glance sheet successfully create.
						</div>
					<?php } ?>
					<?php if ($msg == 2) { ?>
						<div class="alert alert-success alert-dismissable">
							<i class="fa fa-check"></i>
							<button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
							<b>Congratulations!</b> Status changed successfully.
						</div>
					<?php } ?>
					<?php if ($msg == 6) { ?>
						<div class="alert alert-success alert-dismissable">
							<i class="fa fa-check"></i>
							<button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
							<b>Congratulations!</b> Nomination sent to "Post Ops".
						</div>
				<?php }
				} ?>
				<div class="box box-primary">
					<h3 style=" text-align:center;">In Ops at a glance - VC</h3>

					<form name="frm1" id="frm1" enctype="multipart/form-data" action="<?php echo $pagename; ?>" data-postfixpic="" />
					<div class="col-xs-6">
					</div>

					<div class="col-xs-3">
						<select name="selBType" id="selBType" class="form-control" onChange="getSubmit();" style="<?php echo (count($businessType) > 1) ? '' : 'display: none;' ?>">
							<option value="">---Select Business Type---</option>
							<?php echo $obj->getBusinessTypeList1($selBType, $businessType); ?>
						</select>
					</div><!-- /.col -->

					<div class="col-xs-3">
						<select name="selYear" id="selYear" class="form-control" onChange="getSubmit();">
							<?php echo $obj->getYearList($selYear); ?>
						</select>
					</div><!-- /.col -->
					<div style="height:10px;">
						<input type="hidden" name="txtComid2" id="txtComid2" value="" />
						<input type="hidden" name="txtStatus" id="txtStatus" value="" />
						<input type="hidden" name="txtFileName" id="txtFileName" value="" />
						<input type="hidden" name="action" id="action" value="submit" />
						<input type="hidden" name="txtPostfixPIC" id="txtPostfixPIC" value="" />
					</div>





					<div class="box-body table-responsive" style="overflow-y:auto; max-height:390px;">
						<table class="table table-bordered tablesorter table-striped" id='in_ops_at_glance' style="border-collapse: separate;">
							<thead>
								<tr valign="top">
									<th align="left">FVF/ Voyage Docs</th>
									<th align="left">Nom ID / Voyage No.</th>
									<th align="left">Business Type</th>
									<th align="left">Material Name</th>
									<th align="left">Vessel</th>
									<th align="left">Charterer</th>
									<th align="left">CP Date</th>

									<!--<th align="left">Check List</th>-->
									<th align="left">Voyage Financials</th>
									<th>PDA Request</th>
									<th align="left">PDA/FDA</th>
									<!--<th align="left">Appoint Agent</th>-->
									<!--<th align="left">SOF</th>-->
									<th align="left">Calculations</th>
									<th align="center">Payment / Invoice</th>
									<?php if ($rights == 1) { ?>
										<th align="center">Deactivate / Alerts</th>
									<?php } else { ?>
										<th align="center">Alerts</th>
									<?php } ?>
									<th align="center">Operator</th>
									<th align="center">Chartering Team</th>
									<th align="center">Last Updated By/Time</th>

									<?php if ($rights == 1) { ?>
										<th align="center">Complete</th>
									<?php } else { ?>

									<?php } ?>
								</tr>
							</thead>
							<tbody>
								<?php
								if ($selBType != '') {
									$sql = "select freight_cost_estimate_compare.COMID as COMID, (select CONTACT_PERSON from login where login.LOGINID = freight_cost_estimate_compare.OPERATOR) as OPERATOR, freight_cost_estimate_compare.OPERATOR as toChangeOp ,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.QTY_TYPE_RADIO as QTY_TYPE_RADIO,(select NAME from vendor_master where vendor_master.CODE = freight_cost_estimete_master.FGFF_VENDORID) as FGFF_VENDORID,(select NAME from vendor_master where vendor_master.CODE = freight_cost_estimete_master.LUMP_VENDOR) as LUMP_VENDOR,freight_cost_estimete_master.L_UPDATED_BY as LASTUPDATEDBY, 
									(SELECT a.SEL_BUSI_TYPE FROM freight_cost_estimete_master a WHERE a.COMID = freight_cost_estimate_compare.COMID ORDER BY a.FCAID DESC LIMIT 1) as SEL_BUSI_TYPE,freight_cost_estimete_master.L_UP_TIME as LASTUPDATEDTIME,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_estimate_compare.STATUS=1 and year(freight_cost_estimete_master.ADD_ON_DATE)='" . $selYear . "' 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";

									// echo $sql;
									$res = mysql_query($sql);
									$rec = mysql_num_rows($res);
									$i = 1;
									$submit = 0;
									if ($rec == 0) {
										echo '<tbody>';

										echo '</tbody>';
									} else {
								?>

										<?php
										while ($rows = mysql_fetch_assoc($res)) {
											$materialid = $obj->getCompareEstimateData($rows['COMID'], "CARGO_ID");
											$ESTIMATE_TYPE = $obj->getCompareEstimateData($rows['COMID'], "ESTIMATE_TYPE");
										?>
											<tr id="in_row_<?php echo $i; ?>" style="font-size:11px;">
												<td>
													<a href="viewestimate.php?id=<?php echo $rows['FCAID']; ?>&rttype=1" style="color:green;" title="Click me">FVF</a>&nbsp;&nbsp;|&nbsp;&nbsp;<a href="allPdf.php?id=77&fcaid=<?php echo $rows['FCAID']; ?>" style="color:green;" title="Click me"><span class="glyphicon glyphicon-download-alt"></span></a><br /><br />
													<a href="documents.php?comid=<?php echo $rows['COMID']; ?>&page=1" style="color:green;" title="Click me">Docs</a>

												</td>


												<td>
													<?php echo $rows['MESSAGE']; ?> / <br>
													<?php echo $obj->getCompareEstimateData($rows['COMID'], "VOYAGE_NO"); ?><br /><br />
													<a style="color:blue;" href="voyage_report_vc.php?vesselimono=<?php echo $obj->getVesselIMOData($rows['VESSEL_IMO_ID'], "IMO_NO"); ?>&comid=<?php echo $rows['COMID']; ?>&page=1&type=VC" title="Voyage Departure Data">Voyage&nbsp;Report</a>
												</td>
												<td>
													<?php echo $obj->getEstimateList($ESTIMATE_TYPE); ?>
												</td>
												<td>
													<?php echo $obj->getCargoNameListForMultipleNamemultiple($materialid); ?>
												</td>

												<td>


													<?php
													if ($rows['PERIODID'] > 0) {
													?>
														<span style="color:red">
														<?php
													}
														?>
														<span>
															<?php echo $obj->getVesselIMOData($rows['VESSEL_IMO_ID'], "VESSEL_NAME"); ?>/<br /> <?php echo $obj->getCompareEstimateData($rows['COMID'], "VESSEL_TYPE"); ?>
															<!-- <input type="hidden" name="vesselImoId" id=> -->
														</span>
												</td>





												<td>
													<?php


													$sql1 = "select TANKER_RADIO_SINGLE_DIS, QTY_TYPE_RADIO,(select NAME from vendor_master where vendor_master.CODE = freight_cost_estimete_master.FGFF_VENDORID) as FGFF_VENDORID,(select NAME from vendor_master where vendor_master.CODE = freight_cost_estimete_master.LUMP_VENDOR) as LUMP_VENDOR,FCAID from freight_cost_estimete_master where COMID='" . $rows['COMID'] . "' and SHEET_NO is not null";


													$res1 = mysql_query($sql1);



													$rows1 = mysql_fetch_assoc($res1);


													$ven = '';

													if ($rows1['TANKER_RADIO_SINGLE_DIS'] == 2) {

														$shipperCharter = [];

														$sql12 = "select (select NAME from vendor_master where vendor_master.CODE = freight_cost_estimete_slave10.SHIPPER_CHARTER) as VENDORNAME from freight_cost_estimete_slave10 where FCAID='" . $rows1['FCAID'] . "'";
														//echo $sql12;
														$res12 = mysql_query($sql12);
														$rec12 = mysql_num_rows($res12);

														while ($rows2 = mysql_fetch_assoc($res12)) {
															$shipperCharter[] = $rows2['VENDORNAME'];
														}

														$ven = implode(',<br>', $shipperCharter);
														echo $ven;
													} else {

														if ($_SESSION['selBType'] == 2) {

															if ($rows1['QTY_TYPE_RADIO'] == 1 && $rows1['LUMP_VENDOR']) {
																echo $rows1['LUMP_VENDOR'];

																// echo 'dpk';
															} else {

																$sql12 = "select (select NAME from vendor_master where vendor_master.CODE = freight_cost_estimete_slave12.CUSTOMER) as CUSTOMERNAME from freight_cost_estimete_slave12 where FCAID='" . $rows1['FCAID'] . "'";
																$res12 = mysql_query($sql12);
																$rec12 = mysql_num_rows($res12);

																$customer = [];

																while ($rows12 = mysql_fetch_assoc($res12)) {
																	$customer[] = $rows12['CUSTOMERNAME'];
																}

																$ven = implode(',<br>', $customer);
																echo $ven;
															}
														} else {

															if ($rows1['QTY_TYPE_RADIO'] == 1) {

																echo $rows1['FGFF_VENDORID'];
															} else {

																$qtyVendor = [];

																$sql12 = "select (select NAME from vendor_master where vendor_master.CODE = freight_cost_estimete_slave7.QTY_VENDORID) as QTY_VENDORID from freight_cost_estimete_slave7 where FCAID='" . $rows1['FCAID'] . "'";
																//echo $sql12;
																$res12 = mysql_query($sql12);
																$rec12 = mysql_num_rows($res12);

																while ($rows2 = mysql_fetch_assoc($res12)) {
																	$qtyVendor[] = $rows2['QTY_VENDORID'];
																}

																$ven = implode(',<br>', $qtyVendor);
																echo $ven;
															}
														}
													}


													?>
												</td>
												<?php
												$fixture_date = $obj->getCompareEstimateData($rows['COMID'], "TRANS_DATE");
												if ($fixture_date != "0000-00-00" && $fixture_date != "") {
													$fixture_date = date('d-m-Y', strtotime($fixture_date));
												} else {
													$fixture_date = "";
												} ?>
												<td>
													<?php echo $fixture_date; ?><br /><br />
													<?php echo $obj->getBusiNameAcToid($rows['SEL_BUSI_TYPE']); ?>
												</td>


												<!--<td>
												
													<a href="check_list.php?comid=<?php echo $rows['COMID']; ?>&page=1" style="color:red;" title="Click me" >Check List</a>	
											</td>-->

												<td style="text-align:center;">
													<?php
													$sql1 = "select * from cost_sheet_name_master where COMID='" . $rows['COMID'] . "' and MODULEID='" . $_SESSION['moduleid'] . "' and MCOMPANYID='" . $_SESSION['company'] . "'";

													$res1 = mysql_query($sql1);
													$rec1 = mysql_num_rows($res1);
													$latestsheet = '';
													$cost_sheet_id = '';
													if ($rec1 > 0) {
														while ($rows1 = mysql_fetch_assoc($res1)) {
															$latestsheet = $rows1['COST_SHEETID'];
															$href = "./cost_sheet_tci.php?comid=" . $rows['COMID'] . "&cost_sheet_id=" . $rows1['COST_SHEETID'] . "&page=1";


															echo "<a href='" . $href . "'>" . str_replace(' ', '&nbsp;', $rows1['SHEET_NAME']) . "</a><br/>";
															$curr_cst = $rows1['COST_SHEETID'];
															$cost_sheet_id .= $rows1['COST_SHEETID'];
														}
													}
													$fcaid = $obj->getLatestCostSheetID($rows['COMID']);
													if ($obj->getEstimateData($fcaid, "FINAL_STATUS") == 1 && ($latestsheet == '' || $obj->getTCICostSheetRecDetails($rows['COMID'], $latestsheet) > 0)) {
													?>
														<br /><button class="btn btn-primary btn-flat" data-toggle="modal" data-target="#compose-modal1" type="button" title="Add New CS" onClick="openWin1(<?php echo $rows['COMID']; ?>,<?= $rows['VESSEL_IMO_ID'] ?>,<?= $fcaid ?>);">A</button><input type="hidden" name="sdsdsd" value="<?= $obj->getTCICostSheetRecDetails($rows['COMID'], $latestsheet); ?>" />
													<?php } else { ?>
														<br /><button class="btn btn-primary btn-flat" type="button" title="Add New CS" onClick="msg();">A</button>
													<?php } ?>
												</td>
												<td>
													<a href="agency_letter_generation.php?comid=<?php echo $rows['COMID']; ?>&tab=1&page=1">Generate Port Related Letters</a>
												</td>
												<td>
													<a href="nominate_agent.php?comid=<?php echo $rows['COMID']; ?>&page=1">PDA/FDA</a>
												</td>
												<td>
													<a href="sof.php?comid=<?php echo $rows['COMID']; ?>&page=1" style="color:blue;" title="Click me">SOF</a><br /><br />
													<a href="laytime_calculation.php?comid=<?php echo $rows['COMID']; ?>&page=1&workbookid=2&iden=CHART" style="color:blue;">Laytime</a><br /><br />
													<a href="bunker_calculation.php?comid=<?php echo $rows['COMID']; ?>&page=1" style="color:blue;" title="Click me">Bunkers</a><br /><br />
													<a href="soa_report.php?comid=<?php echo $rows['COMID']; ?>&page=1" style="color:blue;" title="Click me">SOA</a>
												</td>
												<td>

													<a href="payment_grid.php?comid=<?php echo $rows['COMID']; ?>&page=1&voyage_no=<?= $obj->getCompareEstimateData($rows['COMID'], "VOYAGE_NO") ?>">View</a><br><br>
													<!--<br>
												<a href="piclubdeclaration.php?comid=<?php echo $rows['COMID']; ?>&page=1" >P & I Club Declaration</a>-->

												</td>

												<td style="text-align:center;">
													<?php if ($rights == 1) { ?>
														<a href="#A" title="Deactivate entry" onClick="getValidate2(<?php echo $rows['COMID']; ?>,<?php echo $i; ?>);">
															<i class="fa fa-times" style="color:red;"></i>
														</a><br />
													<?php } ?>
													<?php if ($_SESSION['COM_SH'] == 1) { ?>
														<button class="btn btn-primary btn-flat" data-toggle="modal" data-target="#compose-modal2" type="button" title="Compare Sheets" onClick="getCompareSheetData(<?php echo $rows['COMID']; ?>);">Compare Sheets</button>

													<?php } ?>

													<?php
													$freightsql = "select * from freight_invoice_master WHERE (COMID='" . $rows['COMID'] . "' and P_AMT is NULL) or (COMID='" . $rows['COMID'] . "' and P_AMT=0)";
													$freightres = mysql_query($freightsql);
													$freightrec = mysql_num_rows($freightres);
													if ($freightrec > 0) { ?>
														<span style="color:red; font-weight:bold;">Payment not Received</span><br /><br />
													<?php } ?>

													<?php
													$hiresql = "select * from invoice_hire_master WHERE (COMID='" . $rows['COMID'] . "' and P_AMT is NULL) or (COMID='" . $rows['COMID'] . "' and P_AMT=0)";
													$hireres = mysql_query($hiresql);
													$hirerec = mysql_num_rows($hireres);
													if ($hirerec > 0) { ?>
														<span style="color:red; font-weight:bold;">Payment not Paid</span>
													<?php }
													?>
												</td>

												<?php if ($_SESSION['iutype'] == 'mgmt_user') { ?>


													<td align="center" valign="middle" class="input-text"><select name="selUser_<?php echo $i; ?>" id="selUser_<?php echo $i; ?>" class="form-control" onchange="changeOperator('<?= $rows['COMID'] ?>',this)"><?php echo $obj->getUserListForOp(); ?></select></td>
													<script>
														setTimeout(function() {
															$('#selUser_<?php echo $i ?>').val('<?php echo $rows['toChangeOp'] ?>')
														}, 100);
													</script>
												<?php } else { ?>
													<td>
														<?php
														echo $rows['OPERATOR'];
														?>
													</td>

												<?php } ?>







												<?php
												$sql11 = "select L_UP_TIME,(select CONTACT_PERSON from login where login.LOGINID = freight_cost_estimete_master.L_UPDATED_BY) as LUPNAME from freight_cost_estimete_master where COMID='" . $rows['COMID'] . "' and SHEET_NO is not null";

												$res11 = mysql_query($sql11);
												$rows11 = mysql_fetch_assoc($res11);

												// print_r($rows11);
												// echo $sql11;
												?>


												<td>
													<?php
													// $test_id = $obj->getTCICostSheetID($rows['COMID'],$cost_sheet_id);

													// print_r($test_id);
													// $obj->viewFreightCostEstimationTempleteRecordsNew($test_id);
													$s_id = $obj->getLatestCostSheetID($rows['COMID']);
													$obj->viewFreightCostEstimationTempleteRecordsNew($s_id);

													// $id = $obj->getTCICostSheetID($comid,$cost_sheet_id);
													// $s_id = $obj->getTCICostSheetID($rows['COMID'],$cost_sheet_id);

													// echo "<h1>LDJ ".$rows['COMID']."  ".$cost_sheet_id. "</h1>";
													// $obj->viewFreightCostEstimationTempleteRecordsNew($rows['FCAID']);	


													echo $obj->getCountryName($obj->getFun261());

													// die();


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

													// echo mysql_fetch_assoc($pic_user_query)['CONTACT_PERSON'];

													?>
												</td>



												<td>
													<?php
													if ($rows11['LUPNAME']) {
														echo $rows11['LUPNAME'];
													}

													if ($rows11['L_UP_TIME']) {
														echo '<br>' . date('d-m-Y H:i', strtotime($rows11['L_UP_TIME']));
													}
													?>
												</td>



												<?php if ($rights == 1) { ?>
													<td>
														<button class="btn btn-primary btn-flat" id="inner-login-button" type="button" title="Push to Post Ops" onClick="getValidate3(<?php echo $rows['COMID']; ?>,'<?= $href ?>');">Post Ops</button>
													</td>

												<?php } else { ?>

												<?php } ?>
											</tr>

									<?php $i = $i + 1;
										}
									}
								} else { ?>

								<?php } ?>
							</tbody>
						</table>
					</div>
					</form>

				</div>



	</div>


	<div class="modal fade" id="compose-modal1" tabindex="-1" role="dialog" aria-hidden="true">
		<div class="modal-dialog">
			<div class="modal-content">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
				</div>
				<div class="modal-body">
					<div class="box box-primary">
						<div class="box-body no-padding">
							<form name="frm2" id="frm2" method="post" enctype="multipart/form-data" action="<?php echo $pagename; ?>">
								<div class="row invoice-info">

								</div>

								<div class="row invoice-info" style="padding:2%">
									<div class="col-sm-12 invoice-col">
										Please enter Voyage Financials Name and Submit
										<address>
											<input type="text" name="txtFile" id="txtFile" class="form-control" autocomplete="off" value="<?php echo $obj->getNomDetailsData($comid, "FREIGHT_RATE"); ?>" placeholder="Voyage Financials Name" />
											<input type="hidden" name="txtComid1" id="txtComid1" />
										</address>
									</div><!-- /.col -->
								</div>


								<div class="row invoice-info">
									<div class="col-sm-12 invoice-col" style="text-align:center;">
										<button type="submit" class="btn btn-primary btn-flat" onClick="return getValidate();">Submit</button>
										<input type="hidden" name="action" id="action" value="submit" />
									</div><!-- /.col -->
								</div>

							</form>
						</div><!-- /.box-body -->
					</div>
				</div>
			</div><!-- /.modal-content -->
		</div><!-- /.modal-dialog -->
	</div>


	<div class="modal fade" id="compose-modal2" tabindex="-1" role="dialog" aria-hidden="true">
		<div class="modal-dialog" style="width:98%">
			<div class="modal-content">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
					<h4 class="modal-title"><i class="fa fa-file-text-o"></i>&nbsp;&nbsp;Compare Sheets</h4>
				</div>
				<form name="frm2" id="frm2" enctype="multipart/form-data" action="<?php echo $pagename; ?>" />
				<div class="modal-body" id="div_3" style="overflow:auto;">
				</div>

				</form>
			</div>
		</div><!-- /.modal-dialog -->
	</div>
	<!--   content ends here..................-->
	</section><!-- /.content -->
	</aside><!-- /.right-side -->
	</div><!-- ./wrapper -->
	<?php $display->footer(); ?>
	<?php $display->js(); ?>

	<script src="../../js/plugins/datatables/jquery.dataTables.js" type="text/javascript"></script>
	<script src="../../js/plugins/datatables/dataTables.bootstrap.js" type="text/javascript"></script>
	<link href="../../css/jquery.alerts.css" rel="stylesheet" type="text/css" />
	<script language="JavaScript" type="text/javascript" src="../../js/jquery.alerts.js"></script>
	<script language="JavaScript" type="text/javascript" src="../../js/jquery.validate.js"></script>
	<script src="../../js/timer.js" type="text/javascript"></script>

	<script src='../../js/jquery.autosize.js'></script>



	<script type="text/javascript">
		$(document).ready(function() {
			$('.sidebar-toggle').trigger('click');

			// console.log($("#selusers").html());

			// $('#selUser').html($("#selusers").html());
			$("#in_ops_at_glance").dataTable({
				// "iDisplayLength": 50,

				"pageLength": 50,
				bStateSave: true,
				stateDuration: -1

			});


			var voyid = '<?= $_REQUEST['voy_no'] ?>';


			if (voyid != '') {

				$('.dataTables_filter').find('input').val(voyid).keyup();

			}


			$("#frm1").validate({
				rules: {

				},
				messages: {

				},
				submitHandler: function(form) {
					jAlert('<b style="font-size:25px;">Please wait . . .</b><br><br><img src="../../img/loading.gif"  />', 'Alert');
					$("#popup_container").css({
						"background": "rgba(255,255,255,0.1)",
						"border": "10px solid rgba(255,255,255,0.1)",
						"width": "110%"
					});
					$("#popup_content").css({
						"background": "none",
						"text-align": "center"
					});
					$("#popup_ok,#popup_title").hide();
					form.submit();
				}
			});
			$("#frm2").validate({
				rules: {

				},
				messages: {

				},
				submitHandler: function(form) {
					jAlert('<b style="font-size:25px;">Please wait . . .</b><br><br><img src="../../img/loading.gif"  />', 'Alert');
					$("#popup_container").css({
						"background": "rgba(255,255,255,0.1)",
						"border": "10px solid rgba(255,255,255,0.1)",
						"width": "110%"
					});
					$("#popup_content").css({
						"background": "none",
						"text-align": "center"
					});
					$("#popup_ok,#popup_title").hide();
					form.submit();
				}
			});
			//sortDateFormat();


			//for uploading........
			$('#photoimg').live('change', function() {
				$("#cpDiv_" + $("#txtVar").val()).append("<span id='labelDiv_" + $("#txtVar").val() + "_" + $("#txtID_" + $("#txtVar").val()).val() + "'>abc</span>");
				$("#labelDiv_" + $("#txtVar").val() + "_" + $("#txtID_" + $("#txtVar").val()).val()).html('<img src="../../images/loader.gif" alt="Uploading...." width="20" height="10"  />');
				$("#imageform").ajaxForm({
					target: '#labelDiv_' + $("#txtVar").val() + '_' + $("#txtID_" + $("#txtVar").val()).val()
				}).submit();
				var id = $("#txtID_" + $("#txtVar").val()).val();
				id = (id - 1) + 2;
				$("#txtID_" + $("#txtVar").val()).val(id);
				$.modal.close();
			});
			//....................
		});

		function getData() {
			$("#in_ops_at_glance tbody").empty();
			$("#in_ops_at_glance tbody").html('<tr><td height="200" colspan="17" align="center" ><img src="../../img/loading.gif" /></td></tr>');
			$.post("options.php?id=42", {
				selVName: "" + $("#selVName").val() + ""
			}, function(html) {
				$("#in_ops_at_glance tbody").empty();
				$("#in_ops_at_glance tbody").append(html);
			});
		}

		function openWin1(comid, vesselimoid, fcaid) {

			$('#basic-modal-content').modal();
			$("#txtComid1").val(comid);
			$("#simplemodal-container").css({
				"height": "200px"
			});

		}

		function getValidate() {
			if ($("#txtFile").val() != "") {
				document.frm2.submit();
			} else {
				jAlert('Please fill the file name', 'Alert');
				return false;
			}
		}

		function msg() {
			jAlert('Please make sure the last Voyage Financials is Submit to Close', 'Alert');
		}

		function openWin2(var1, mappinid) {
			$('#basic-modal-content1').modal();
			$("#txtVar").val(var1);
			$("#txtComid").val(comid);
			$("#simplemodal-container").css({
				"width": "300px",
				"height": "50px"
			});
		}

		function openWin(comid, vesselid, id) {
			$('#basic-modal').modal();
			$("#txtComid").val(comid);
			$("#txtVesselid").val(vesselid);
			$("#txtuid").val(id);
			$("#simplemodal-container").css({
				"width": "300px",
				"height": "50px"
			});
		}

		function getValid() {
			if ($('#txtfile').val() == '') {
				jAlert('Please choose the file', 'Alert');
				return false;
			} else {
				var name = $('#txtfile').val();
				name = name.split('.');
				if (name[1] == 'txt') {
					return true;
				} else {
					jAlert('Please choose only .txt file', 'Alert');
					$('#txtfile').val('');
					return false;
				}
			}
		}

		function getPdfForSea(comid, vesselid) {
			location.href = 'allPdf.php?id=12&comid=' + comid + '&vesselid=' + vesselid;
		}

		function getValidate2(var1, rowid) {
			$("#in_row_" + rowid + " td").css({
				"background-color": "red"
			});
			jConfirm('Are you sure to de-activate this Nom ID ?', 'Confirmation', function(r) {
				if (r) {
					$("#txtComid2").val(var1);
					document.frm1.submit();
				} else {
					$("#in_row_" + rowid + " td").css({
						"background-color": ""
					});
					return false;
				}
			});
		}

		function getValidate3(var1, $href) {

			var userType = '<?= $_SESSION['iutype'] ?>'

			$.post("options.php?id=127", {
				comid: "" + var1 + ""
			}, function(res) {

				console.log(res);

				const obj = JSON.parse(res);

				// console.log(obj.DTCVENDORID);

				var blQuantity, LPDPTPVEN_1, LPDPTPVEN_2, LPDPTPVEN_3, BROK_VENDOR, DTCVENDORID, FGFF_VENDORID, FHSFINAL;
				if (obj.BL_QTY_FREIGHT == 1) {

					blQuantity = '&#9989;';

				} else {
					blQuantity = '&#10060;';
				}
				if (obj.Hire_Stmt == 1) {

					FHSFINAL = '&#9989;';

				} else {
					FHSFINAL = '&#10060;';

				}
				if (obj.LPDPTPVEN_1 == 1) {

					LPDPTPVEN_1 = '&#9989;';
				} else {

					LPDPTPVEN_1 = '&#10060;';
				}
				if (obj.DTCVENDORID == 1) {

					DTCVENDORID = '&#9989;';
				} else {

					DTCVENDORID = '&#10060;';
				}
				if (obj.FGFF_VENDORID == 1) {

					FGFF_VENDORID = '&#9989;';
				} else {

					FGFF_VENDORID = '&#10060;';
				}

				if (obj.BROK_VENDOR == 1) {

					BROK_VENDOR = '&#9989;';
				} else {

					BROK_VENDOR = '&#10060;';
				}

				if (obj.FREIGHT_GROSS == 1) {

					FREIGHT_GROSS = '&#9989;';
				} else {

					FREIGHT_GROSS = '&#10060;';
				}


				if (obj.HIRE_RATE == 1) {

					HIRE_RATE = '&#9989;';
				} else {

					HIRE_RATE = '&#10060;';
				}



				if (userType == 'mgmt_user') {

					jConfirm("<label>Postfix PIC</label><select name='selPostfixPIC' id='selPostfixPIC' class='form-control'><?php echo $obj->getUserList(1); ?></select><br><b>Are you sure to send this Nom ID to post ops ?</b>", 'Confirmation', function(r) {
						if (r) {

							$("#txtPostfixPIC").val($("#frm1").attr('data-postfixpic'));
							$("#frm1").attr('data-postfixpic', '');

							if ($("#txtPostfixPIC").val()) {
								$("#txtComid2").val(var1);
								$("#txtStatus").val(1);

								document.frm1.submit();
							} else {
								jAlert("Please select a Postfix PIC before proceeding.", "Alert");
							}
						} else {
							return false;
						}
					});


					$('#selPostfixPIC').change(function() {
						$("#frm1").attr('data-postfixpic', $(this).val());
					});

				} else {

					if (obj.DTCVENDORID == 0 || obj.LPDPTPVEN_1 == 0 || obj.FGFF_VENDORID == 0 || obj.blQuantity ==
						1 || obj.BROK_VENDOR == 0 || obj.Hire_Stmt == 0 || obj.Ops_Cost == 0) {
						jConfirm('Please check all mandatory fields are filled<br>' + FGFF_VENDORID + ' FREIGHT VENDOR<br>' + DTCVENDORID + ' HIRE VENDOR<br>' + LPDPTPVEN_1 + ' PORT COST VENDOR<br>' + blQuantity + ' BL QUANTITY<br>' + BROK_VENDOR + ' BROKERAGE VENDOR<br>' + FREIGHT_GROSS + ' FREIGHT RATE<br>' + HIRE_RATE + ' HIRE RATE<br>' + FHSFINAL + 'FHS/FINAL', 'Alert', function(r) {
							if (r) {


								window.location = "" + $href + ""



							} else {
								return false;
							}
						});

					} else {

						$.alerts.okButton = "Ok";
						$.alerts.cancelButton = "Done";


						jConfirm('<b>Request to kindly review the operational costs and check/uncheck accordingly</b>', 'Alert', function(r) {

							if (r) {
								return false;
							} else {

								$.alerts.cancelButton = "Cancel";

								jConfirm("<label>Postfix PIC</label><select name='selPostfixPIC' id='selPostfixPIC' class='form-control'><?php echo $obj->getUserList(1); ?></select><br><b>Are you sure to send this Nom ID to post ops ?</b>", 'Confirmation', function(r) {
									if (r) {

										$("#txtPostfixPIC").val($("#frm1").attr('data-postfixpic'));
										$("#frm1").attr('data-postfixpic', '');

										if ($("#txtPostfixPIC").val()) {
											$("#txtComid2").val(var1);
											$("#txtStatus").val(1);

											document.frm1.submit();
										} else {
											jAlert("Please select a Postfix PIC before proceeding.", "Alert");
										}
									} else {
										return false;
									}
								});

							}


							$('#selPostfixPIC').change(function() {
								$("#frm1").attr('data-postfixpic', $(this).val());
							});

						});

						/*jConfirm('Are you sure to send this Nom ID to post ops ?', 'Confirmation', function(r) {
							if (r) {
								$("#txtComid2").val(var1);
								$("#txtStatus").val(1);

								document.frm1.submit();
							} else {
								return false;
							}
						});*/

					}




				}



			});



		}

		function getValidate4(var1, file_name) {
			jConfirm('Are you sure to remove this document permanently ?', 'Confirmation', function(r) {
				if (r) {
					$("#txtComid2").val(var1);
					$("#txtStatus").val(2);
					$("#txtFileName").val(file_name);
					document.frm1.submit();
				} else {
					return false;
				}
			});
		}

		function getSubmit() {
			$("#action").val("");

			document.frm1.submit();
		}


		function getCompareSheetData(comid) {
			$("#div_3").empty();
			$("#txtCOMID").val('');
			$("#div_3").html('<div style="height:200px;text-align:center;"><img src="../../img/loading.gif" /></div>');
			$.post("options.php?id=131", {
				comid: "" + comid + "",
				page: '1'
			}, function(html) {
				$("#div_3").empty();
				$("#div_3").html(html);
				$("#txtCOMID").val(comid);
				$(".autosize").autosize({
					append: "\n"
				});

				for (var i = 1; i <= $("#txtRowCount").val(); i++) {
					var amount = parseFloat($("#txtDifference_" + i).val());
					if (isNaN(amount)) {
						amount = 0;
					}
					if (amount < 0) {
						$("#txtDifference_" + i).css("color", "red");
					} else {
						$("#txtDifference_" + i).css("color", "green");
					}
				}

				for (var i = 1; i <= $("#txtIdentity8ID").val(); i++) {
					var amount = parseFloat($("#txtDifference_8_" + i).val());
					if (isNaN(amount)) {
						amount = 0;
					}
					if (amount < 0) {
						$("#txtDifference_8_" + i).css("color", "red");
					} else {
						$("#txtDifference_8_" + i).css("color", "green");
					}
				}

				$('[data-toggle="tooltip"]').tooltip();

			});
		}




		function getjsPDF() {

			var HTML_Width = $(".canvas_div_pdf").width();
			var HTML_Height = $(".canvas_div_pdf").height();
			var top_left_margin = 15;
			var PDF_Width = HTML_Width + (top_left_margin * 2);
			var PDF_Height = (PDF_Width * 1.5) + (top_left_margin * 2);
			var canvas_image_width = HTML_Width;
			var canvas_image_height = HTML_Height;

			var totalPDFPages = Math.ceil(HTML_Height / PDF_Height) - 1;


			html2canvas($(".canvas_div_pdf")[0], {
				allowTaint: true
			}).then(function(canvas) {
				canvas.getContext('2d');

				console.log(canvas.height + "  " + canvas.width);


				var imgData = canvas.toDataURL("image/jpeg", 1.0);
				var pdf = new jsPDF('p', 'pt', [PDF_Width, PDF_Height]);
				pdf.addImage(imgData, 'JPG', top_left_margin, top_left_margin, canvas_image_width, canvas_image_height);


				for (var i = 1; i <= totalPDFPages; i++) {
					pdf.addPage(PDF_Width, PDF_Height);
					pdf.addImage(imgData, 'JPG', top_left_margin, -(PDF_Height * i) + (top_left_margin * 4), canvas_image_width, canvas_image_height);
				}

				pdf.save("Compare-Sheet-Vc.pdf");
			});
		};


		function changeOperator(table_id, clx) {

			let op = $(clx).val()

			$.ajax({

				type: "POST",
				data: {
					id: table_id,
					op: op
				},
				dataType: "json",

				success: function(result) {
					// when call is sucessfull
					if (result) {
						location.reload();
					}
				},
				error: function(err) {
					// check the err for error details

				}
			});

		}
	</script>

</body>

</html>