<?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->insertActualCostSheetNametc();
		}
		else
		{
			$msg = $obj->deleteInOpsEntrytc($_REQUEST['txtComid2']);
		}
		header('Location:./in_ops_tc.php?msg=3');
	}
	else if($_REQUEST['txtStatus'] == "1")
	{
		$msg = $obj->convertToPostOpstc($_REQUEST['txtComid2']);
	}
	else if($_REQUEST['txtStatus'] == "2")
	{
		
	}
	
	header('Location:./in_ops_tc.php?msg=3');
 }
 


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 = '';
}

// echo $selBType;

// die();




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


	$change_op_query=mysql_query("UPDATE chartering_estimate_tc_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]-->
</head>
    <body class="skin-blue fixed">
        <!-- header logo: style can be found in header.less -->
        <?php $display->header_tag(); ?>
		<div class="wrapper row-offcanvas row-offcanvas-left">
            <?php $display->leftmenu(21); ?>
			<aside class="right-side">                
                <!-- Content Header (Page header) -->
                <section class="content-header">
                    <h1>
                        <i class="fa fa-book"></i>&nbsp;Ops TC&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 TC&nbsp;&nbsp;&nbsp;>&nbsp;&nbsp;&nbsp;In Ops at a glance TC</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 - TC</h3>
							
					<form name="frm1" id="frm1" enctype="multipart/form-data" action="<?php echo $pagename;?>"/>
					<div class="col-xs-6">
                            </div>
                            <div class="col-xs-3">
                                 <select name="selBType" id="selBType" class="form-control" onChange="getSubmit();">
                                 <option value="">---Select Business Type---</option>
								   <?php echo $obj->getBusinessTypeList1($selBType);?>
                                  </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"/>
						</div>
                
						<div class="box-body table-responsive" style="overflow:auto;">
							<table class="table table-bordered table-striped" id='in_ops_at_glance'>
								<thead>
									<tr valign="top">
										<th align="left">Final TC Est/Docs</th>
										<th align="left">Nom ID/TC No.</th>
										<th align="left">Business Type</th>
                                        <th align="left">Vessel</th>
										<th align="left">Charterer</th>
                                        <th align="left">CP Date</th>
										<th align="left">Port Del/Port Re-Del</th>
                                        <th align="left">Checklist</th>
										<th align="left">TC days/ Fixture Note</th>
										<th align="left">TC Financials</th>
										<th align="left">Agency Letters</th>
                                        <th align="left">Payment/Invoices</th>
										<th align="left">De-activate/Compare</th>
										<th align="left">Operator</th>
                                        <th align="left">Re-Del Date</th>
                                        <th align="left">Chatering Team</th>
										
                                        <th align="left">Change TC Status</th>	
									</tr>
								</thead>
									<?php


					
									$sql = "select chartering_estimate_tc_compare.COMID as COMID,chartering_estimate_tc_compare.OPERATOR as OPERATOR,(select CONTACT_PERSON from login where login.LOGINID = chartering_estimate_tc_compare.OPERATOR) as OPERATORForNon,(select NAME from vendor_master where vendor_master.CODE = chartering_estimate_tc_master.SEL_CHARTERER) as SEL_CHARTERER,chartering_estimate_tc_master.PERIODID  as  PERIODID , chartering_estimate_tc_master.VESSEL_IMO_ID as VESSEL_IMO_ID, chartering_estimate_tc_master.TCOUTID as TCOUTID, chartering_estimate_tc_master.TC_NO as TC_NO, chartering_estimate_tc_compare.MESSAGE as MESSAGE, chartering_estimate_tc_master.FIXTURE_TYPE as FIXTURE_TYPE, chartering_estimate_tc_master.RE_DEL_DATE as RE_DEL_DATE,(select SUM(UTILISATION_DAY_EST) as UTILISATION_DAY_EST from chartering_tc_estimate_slave1 where chartering_tc_estimate_slave1.TCOUTID= (select TCOUTID from chartering_estimate_tc_master where chartering_estimate_tc_master.COMID=chartering_estimate_tc_compare.COMID order by TCOUTID desc limit 0,1)) as UTILISATION_DAY_EST, chartering_estimate_tc_master.TC_NO as VOYAGE_NAME 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='".$_SESSION['selBType']."' and chartering_estimate_tc_compare.STATUS=1 and year(chartering_estimate_tc_master.UPDATE_ON_DATE)='".$selYear."' order by date(chartering_estimate_tc_master.FINAL_DATETIME) desc"; 
									// echo $sql;
                                    $res = mysql_query($sql) or die($sql);
									$rec = mysql_num_rows($res);
									$i=1;
									$submit = 0;
										if($rec == 0)
										{
											echo '<tbody>';
									
											echo '</tbody>';
										}else{
									?>
								<tbody>
									<?php
										while($rows = mysql_fetch_assoc($res))
										{

											$ESTIMATE_TYPE = $obj->getCharteringEstimateTCData($rows['COMID'],"ESTIMATE_TYPE");											
											$sql2 = "select TCOUTID, CP_DATE1 from chartering_estimate_tc_master where COMID='".$rows['COMID']."' order by TCOUTID asc";
											$res2 = mysql_query($sql2);
											$row2 = mysql_fetch_assoc($res2);
										?>						
										<tr id="in_row_<?php echo $i;?>" style="font-size:11px;">
											<td>
												<a href="viewtcestimate.php?id=<?php echo $row2['TCOUTID'];?>&rttype=1" style="color:green;" title="Click me" >TC</a><br/><br/>
												<a href="documents_tc.php?comid=<?php echo $rows['COMID'];?>&page=1" style="color:green;" title="Click me" >Docs</a>
											</td>
                                           <td><?php echo $rows['MESSAGE']."<br/><br/><span style='color:red;'>".$rows['TC_NO'];?></span></td>
											<td><?php echo $obj->getEstimateList($ESTIMATE_TYPE);?></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->getCharteringEstimateTCData($rows['COMID'],"VESSEL_TYPE");?></span></td>
											<td><?php echo $rows['SEL_CHARTERER']?></td>
                                            <td><?php if($row2['CP_DATE1']=="" || $row2['CP_DATE1']=="0000-00-00"){$CP_DATE1 = "";}else{$CP_DATE1 = date('d-m-Y',strtotime($row2['CP_DATE1']));} echo $CP_DATE1;?></td>
                                            <td><?php echo $obj->getCharteringEstimateTCData($rows['COMID'],"DEL_RANGE_PORT");?>/<?php echo $obj->getCharteringEstimateTCData($rows['COMID'],"RE_DEL_RANGE"); ?></td>
                                            <td><a href="tc_check_list.php?comid=<?php echo $rows['COMID'];?>&page=1" style="color:red;" title="Check List" >Check List</a><br/><br/></td>


											<?php 
											
											$tcdays=0;
											$sql11 = "SELECT * from invoice_tchire_master where COMID='" . $rows['COMID'] . "' order by INVOICEID desc";
											$res11 = mysql_query($sql11);
											$rec11 = mysql_num_rows($res11);

											$rows11 = mysql_fetch_assoc($res11);


													// echo $sql11;
													
											if ($rows11['HIRE_DAYS']==0 || $rows11['HIRE_DAYS']=='') {
												
											
												

												$sql_invslave1 = "select sum(HIRE_DAYS) as HIRE_DAYS from invoice_tchire_hire_salve where INV_ID='".$rows11['INVOICEID']."'";

												// echo $sql_invslave1;
			
												
												$res_invslave1 = mysql_query($sql_invslave1);
												$result_invslave1 = mysql_fetch_assoc($res_invslave1);
			
												
			
												
												$tcdays= $result_invslave1['HIRE_DAYS'];
									


			
											}else{
												

												$tcdays= $rows11['HIRE_DAYS'];
												


											}



											
											
											?>


                                            <td><?php echo $tcdays?> <br/><br/><a href="viewtcfixturenote.php?comid=<?php echo $rows['COMID'];?>&page=1" style="color:green;" title="Click me" >Fixture Note</a></td>
                                            <td style="text-align:center;">
											<?php
													$sql1 = "select * from cost_sheettc_name_master where COMID='".$rows['COMID']."' and MODULEID='".$_SESSION['moduleid']."' and MCOMPANYID='".$_SESSION['company']."'";

													// echo '<h1>'.$sql1;

													
													$res1 = mysql_query($sql1);

													$rec1 = mysql_num_rows($res1);

													
													if($rec1 > 0)
													{

														// echo '<h1>dpk';
														while($rows1 = mysql_fetch_assoc($res1))
														{
															if($rows1['PROCESS'] != "EST")
															{
																$href = "./cost_sheet_tc.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'];
															}
															else
															{
																$curr_cst = $obj->getCostSheetFixtureID($rows['COMID'],"SHEET_NO");
															}
														}
													}	
											      
												   $fcaid = $obj->getLatestCostSheetIDTC($rows['COMID']);	
												   $lastsheet = $obj->getLatestSheetIDTC($rows['COMID']);	
												   if($lastsheet==0)
												   {?>
                                                   <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'];?>);">A</button>
                                                   <?php }else{
											       if($obj->getEstimateDatatc($fcaid,$lastsheet)==1)
													{
													?>
													<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'];?>);">A</button>
													<?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_inops_tc.php?comid=<?php echo $rows['COMID'];?>&tab=1&page=1">Generate Agency Letter</a></td>
                                            <td>
											<i class="glyphicon glyphicon-list-alt"></i>&nbsp;&nbsp;<a href="payment_grid_tc.php?comid=<?php echo $rows['COMID'];?>&tab=0&page=1" style="color:#005A86;"><strong>View</strong></i></a><br/>
											</td>
											<td><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 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</button>
											<?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['OPERATOR'] ?>')  }, 100);</script>
										<?php } else{?>
											<td>
										   <?php 
											echo $rows['OPERATORForNon'];
											?>
										</td>

											<?php } ?>


											<td><?php if($rows['RE_DEL_DATE']=="" || $rows['RE_DEL_DATE']=="0000-00-00"){$RE_DEL_DATE = "";}else{$RE_DEL_DATE = date('d-m-Y',strtotime($rows['RE_DEL_DATE']));} echo $RE_DEL_DATE;?></td>
                                            
											<td>

												<?php
												// ldj

										


												$t_id = $obj->getLatestCostSheetIDTC($rows['COMID']);
												$obj->viewTCEstimationTempleteRecordsNew($t_id);

												

															// $obj->viewTCEstimationTempleteRecordsNew($rows['FCAID']);
															// $pic_user_query=mysql_query("SELECT * FROM login WHERE STATUS=1 and USER_TYPE in ('internal_user','mgmt_user') and LOGINID=".$obj->getFun147()."");
															// echo mysql_fetch_assoc($pic_user_query)['CONTACT_PERSON'];


															echo $obj->getCountryName($obj->getFun147());
												?>
											</td>
											
											<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'];?>);">Post Ops</button>
											</td>
										</tr>	                                        
									<?php $i = $i + 1; } }?>
								</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 class="col-sm-12 invoice-col">
														<strong style="text-align:center;text-decoration:underline;display:block;">INSTRUCTIONS FOR CREATING 1ST TC SHEET</strong>
														<p style="padding:2%;">In the Ops side, the user should click A and enter any desired TC Sheet Name. This is then also possible after every "Submit to Close"</p>
													</div>
												</div>
												
												<div class="row invoice-info" style="padding:2%">
													<div class="col-sm-12 invoice-col">
														TC Sheet Name
														<address>
															<input type="text" name="txtFile" id="txtFile" class="form-control" autocomplete="off" value="<?php echo $obj->getNomDetailsData($comid,"FREIGHT_RATE");?>" placeholder="TC Sheet Name" />
															<input type="hidden" name="txtComid1" id="txtComid1" />
														</address>
													</div><!-- /.col -->
												</div>
												
												<?php if($rights == 1){ ?>
												<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>
												<?php } ?>
											</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 type="text/javascript">
$(document).ready(function(){
	$("#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": "100%"});
			$("#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": "100%"});
		$("#popup_content").css({"background":"none","text-align":"center"});
		$("#popup_ok,#popup_title").hide();  
		form.submit();
	}
});
	//sortDateFormat();
	$("#in_ops_at_glance").dataTable({

		"iDisplayLength": 100, 
		bStateSave: true, 
		stateDuration: -1
		
    });

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


	if(voyid!=''){

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

	}




	
	
//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)
{
	$('#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 TC Sheet 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 getValidate3(var1) {


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

	// console.log(res);

	const obj = JSON.parse(res);

	// console.log(obj.DTCVENDORID)

	var selESTtcVendor, TC_FINAL_HIERAGE_VENDOR, TC_outDelRedel, TC_outHireRate, TC_outDelivery, TC_outReDelivery, TC_InDeliveryReDel, TC_RATE;
	if (obj.selESTtcVendor == 1) {

		selESTtcVendor = '&#9989;';

	} else {
		selESTtcVendor = '&#10060;';
	}
	if (obj.TC_FINAL_HIERAGE_VENDOR == 1) {

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

		TC_FINAL_HIERAGE_VENDOR = '&#10060;';
	}
	if (obj.TC_outDelRedel == 1) {

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

		TC_outDelRedel = '&#10060;';
	}
	if (obj.TC_outHireRate == 1) {

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

		TC_outHireRate = '&#10060;';
	}

	if (obj.TC_outDelivery == 1) {

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

		TC_outDelivery = '&#10060;';
	}

	if (obj.TC_outReDelivery == 1) {

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

		TC_outReDelivery = '&#10060;';
	}

	
	if (obj.TC_InDeliveryReDel == 1) {

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

		TC_InDeliveryReDel = '&#10060;';
	}


	if (obj.TC_RATE == 1) {

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

		TC_RATE = '&#10060;';
	}


	var selESTtcVendor, TC_FINAL_HIERAGE_VENDOR, TC_outDelRedel, TC_outHireRate, TC_outDelivery, TC_outReDelivery, TC_InDeliveryReDel, TC_RATE;



	if (obj.selESTtcVendor == 0 || obj.TC_FINAL_HIERAGE_VENDOR == 0 || obj.TC_outDelRedel == 0 || 	obj.TC_outHireRate == 0 || obj.TC_outDelivery == 0 || obj.TC_outReDelivery == 0 || obj.TC_InDeliveryReDel == 0 || obj.TC_RATE == 0) {

		jConfirm('Please check all mandatory fields are filled<br>' + selESTtcVendor + ' Tc Out Vendor<br>' + TC_FINAL_HIERAGE_VENDOR + ' Tc In Vendor<br>' + TC_outDelRedel + ' Tc Out Del/ReDel Date<br>' + TC_outHireRate + ' Tc Out Hire Rate<br>' + TC_outDelivery + ' Tc Out Bunker Del<br>' + TC_outReDelivery + ' Tc Out Bunker ReDel<br>' + TC_InDeliveryReDel + ' Tc In Del/ReDel Date<br>' + TC_RATE + ' Tc In Rate', 'Alert', function(r) {
			if (r) {

				return false;

			} else {
				return false;
			}
		});

	} else {
		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);

			$('#checkForCheck').val(23);


			$("#txtFileName").val(file_name);
			document.frm1.submit();

		}
		else{return false;}
		});	
}

function getSubmit()
{ 
    $("#action").val("");
	document.frm1.submit();
}


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


		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" );
			}
		}

		
	});
}


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 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-Tc.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>