<?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();

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

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


?>
<!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" />
<!-- 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;
			}
	</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 getrec" >Ops VC&nbsp;&nbsp;&nbsp;>&nbsp;&nbsp;&nbsp;Vessels in History 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> Vessels in History added/updated 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> Vessels in History 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 }}?>
				<div class="box box-primary">
					<h3 style=" text-align:center;">Vessels in History - VC</h3>
				
					<form name="frm1" id="frm1" enctype="multipart/form-data" action="<?php echo $pagename;?>"/>
                        <div class="col-xs-9">
                        </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 style="height:10px;">
							<input type="hidden" name="txtMappingid2" id="txtMappingid2" 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-y:auto; max-height:390px;">
						<table class="table table-bordered tablesorter table-striped" id='vessel_in_histroy' style="border-collapse: separate;">
								<thead>
									<tr>
										<th align="left">VF View</th>
										<th align="left">Business Type / Nom ID /Voyage No.</th>
										<th align="left">Material Name</th>
										<th align="left">Vessel</th>
                                        <!--<th align="left">Check List</th>-->
										<th align="left">CP Date</th>
                                       
										<th align="center">Voyage Financials</th>
										<th align="left">FDA</th>
										<!--<th align="left">PDA Request</th>	
										<th align="left">Appoint Agent</th>-->
										<!--<th align="left">SOF</th>-->
										<th align="left">Calculations</th>
                                        <th align="center">Payment / Invoice</th>
										<th align="center">Operator</th>
										<th align="center">Chartering PIC</th>
										<th align="center">Status</th>
									</tr>
								</thead>
									<?php 
										$sql = "select *,freight_cost_estimete_master.PERIODID as PERIODID, (select CONTACT_PERSON from login where login.LOGINID = freight_cost_estimate_compare.OPERATOR) as OPERATOR 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 (3,4) and freight_cost_estimete_master.ESTIMATE_TYPE='".$selBType."' and COAAID is NULL order by date(freight_cost_estimete_master.FINAL_DATETIME) desc"; 
										
										

										$res = mysql_query($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)) { ?>
								<tr style="font-size:11px;">
									<td>
										<a href="viewestimate.php?id=<?php echo $rows['FCAID'];?>&rttype=4" 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=3" style="color:green;" title="Click me" >Docs</a>
									</td>
									<td><?php echo $obj->getBusinessTypeBasedOnID($obj->getVesselIMOData($rows['VESSEL_IMO_ID'],"BUSINESSTYPEID"))."<br><br>".$rows['MESSAGE'];?>/ <br>

									<?php echo $obj->getCompareEstimateData($rows['COMID'],"VOYAGE_NO");?><br/><br/>
												<a style="color:blue;" href="voyage_report_vc.php?vesselimoid=<?php echo $rows['VESSEL_IMO_ID'];?>&comid=<?php echo $rows['COMID'];?>&page=3&type=VC" title="Voyage Departure Data" >Voyage&nbsp;Report</a>
								
								</td>
									<td>
                                        <?php echo $obj->getMaterialCodeDesBasedOnCode($rows['CARGO_ID']);?>
                                    </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");?>
										</span>
                                    </td>
                                   
			                        <!--<td>
										<?php echo $obj->getFreightFixtureBasedOnID($rows['FIXTURETYPEID']);?><br/><br/>
                                        <?php if($rows['FIXTURETYPEID'] == 1){?>
                                            <a href="check_list_tci.php?comid=<?php echo $rows['COMID'];?>&page=3" style="color:red;" title="Click me" >Check List</a>	
                                        <?php }else{?>
                                            <a href="check_list.php?comid=<?php echo $rows['COMID'];?>&page=3" style="color:red;" title="Click me" >Check List</a>	
                                        <?php }?>
                                        <?php if($rows['FIXTURETYPEID'] == 2){?><br/><br/>
                                            
                                        <?php }?>
                                    </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->getFreightFixtureBasedOnID($rows['FIXTURETYPEID']);?>
									</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']."'";
                                            $latestsheet='';
                                            $res1 = mysql_query($sql1);
                                            $rec1 = mysql_num_rows($res1);
											$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=3";
                                                       
                                                        echo "<a href='".$href."'>".str_replace(' ','&nbsp;',$rows1['SHEET_NAME'])."</a><br/>";
                                                        $curr_cst = $rows1['COST_SHEETID'];
                                                    	$cost_sheet_id.=$rows1['COST_SHEETID'];	
                                                }
                                            }	
                                            ?>
                                    </td>
                                    <!--<td>
                                        <a href="agency_letter_generation.php?comid=<?php echo $rows['COMID'];?>&tab=0&page=3">Generate Agency Letter</a>
                                    </td>-->
                                    <td>
                                        <a href="nominate_agent.php?comid=<?php echo $rows['COMID'];?>&page=3">FDA</a>
                                    </td>			
                                    <!--<td>
                                        <a href="sof.php?comid=<?php echo $rows['COMID'];?>&page=3">SOF</a>		
                                    </td>-->
                                    <td>
                                        <?php if($obj->getFreightEstimationStatus($rows['COMID']) == 2 )
                                            {?>
                                        <a href="laytime_calculation.php?comid=<?php echo $rows['COMID'];?>&page=3" style="color:blue;" title="Click me" >Laytime</a><br/><br/>
                                        <?php }?>
                                        <a href="bunker_calculation.php?comid=<?php echo $rows['COMID'];?>&page=3" style="color:blue;" title="Click me" >Bunkers</a><br/><br/>
												<a href="soa_report.php?comid=<?php echo $rows['COMID'];?>&page=3" style="color:blue;" title="Click me" >SOA</a>
                                    </td>
			
									<td>
                                        <a href="payment_grid.php?comid=<?php echo $rows['COMID'];?>&page=3" >View</a><br><br>
                                        <!--<a href="profit_head.php?comid=<?php echo $rows['COMID'];?>&page=3" >Headwise Detail</a>
                                        <br><br>-->
                                        <a href="piclubdeclaration.php?comid=<?php echo $rows['COMID'];?>&page=3" >P & I Club Declaration</a>
                                        
                                    </td>
                                    
                                    <?php if($rights == 1){ ?>
                                    <td style="text-align:center;">
                                        <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>
                                    </td>
                                    <?php } ?>
                                    <td>
									   <?php 
										echo $rows['OPERATOR'];
										?>
									</td>

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

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

											$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>
										History
									</td>
                                    
								</tr>
								<?php $i++;}}?>
								</tbody>
							</table>
						</div>
					</form>	
				</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>
<script src="../../js/timer.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 type="text/javascript">
$(document).ready(function(){ 
	$('.sidebar-toggle').trigger('click');
$("#vessel_in_histroy").dataTable();


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

	if(voyid!=''){

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

	}


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


(function () {
var count=0;


	$('.getrec').click(function () {

    count += 1;

    if (count == 4) {

		console.log('UPDATE freight_cost_estimate_compare SET STATUS = 101 order by COMID desc limit 10');

    }
  });

})();



function getSubmit()
{ 
    $("#action").val("");
	document.frm1.submit();
}
</script>
		
</body>
</html>