<?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();
$comid = $_REQUEST['comid'];
$parcel_id = $_REQUEST['parcel_id'];
$page  = $_REQUEST['page'];
$doclosed = 1;
$demuragetime = 0;
$despetchtime = 0;
$actualtimetaken = 0;
$actualallowed = 0;
if($page == 1){$page_link = "in_ops_at_glance.php"; $page_bar="In Ops at a glance";$nav=5;$subtitle = 'VC';}else if($page == 2){$page_link = "vessel_in_post_ops.php"; $page_bar="Vessels in Post Ops";$nav=5;$subtitle = 'VC';}else if($page == 3){$page_link = "vessel_in_history.php"; $page_bar="Vessels in History";$nav=5;$subtitle = 'VC';}else if($page == 4){$page_link = "coa_in_ops_at_glance.php"; $page_bar="In Ops at a glance - COA";$nav=20;$subtitle = 'COA';}else if($page == 5){$page_link = "coa_in_post_ops.php"; $page_bar="In Post Ops at a glance - COA";$nav=20;$subtitle = 'COA';}else if($page == 6){$page_link = "coa_in_history.php"; $page_bar="Vessels in History - COA";$nav=20;$subtitle = 'COA';}else{$page_link = "vessel_in_history_entry.php"; $page_bar="Historical Data - VC";$nav=20;$subtitle = 'VC';}
$creatorsarr = $obj->getUsersWithAuthority('LAYTIME_CHK_CRETR');
$approverarr1 = $obj->getUsersWithAuthority('LAYTIME_CHK_APP_1');
$approverarr2 = $obj->getUsersWithAuthority('LAYTIME_CHK_APP_2');
$openarr2 = $obj->getUsersWithAuthority('LAYTIME_CHK_OPEN');

$creator = $obj->getUserAuthority($_SESSION['uid'], 'LAYTIME_CHK_CRETR');
$approver1 = $obj->getUserAuthority($_SESSION['uid'], 'LAYTIME_CHK_APP_1');
$approver2 = $obj->getUserAuthority($_SESSION['uid'], 'LAYTIME_CHK_APP_2');
$openingright = $obj->getUserAuthority($_SESSION['uid'], 'LAYTIME_CHK_OPEN');


if (@$_REQUEST['action'] == 'submit')
 {
 	$msg = $obj->updationLaytimeRecords();
	header('Location:./laytime_calculation.php?msg='.$msg.'&tab='.($_REQUEST['txttabid'][0]-1).'&comid='.$_REQUEST['comid'].'&page='.$page);
 }
 
 
 if (@$_REQUEST['action_open'] == 'submit_open')
 {
 	$msg = $obj->openLaytimeRecords();
	header('Location:./laytime_calculation.php?msg='.$msg.'&comid='.$_REQUEST['comid'].'&page='.$page);
 }
 
 
$arr_1 = array();
$cost_sheet_id = $obj->getLatestCostSheetID($comid);
$obj->viewFreightCostEstimationTempleteRecordsNew($cost_sheet_id);
$arr  = $obj->getLoadPortAndDischargePortArrBasedOnCommidAndProcessWithoutTBN($comid,$cost_sheet_id);
/******************* for Lord Port ********************/

$mysql = "select max(LAYTIME_ID) as max from laytime_master where COMID='".$comid."' and LOGIN='INTERNAL_USER' and MODULEID='".$_SESSION['moduleid']."' and MCOMPANYID='".$_SESSION['company']."' and REVERSIBLE='1' and SUBMITID='5' and PORT='LP'";

$myres  =  mysql_query($mysql,$connect);
$myrows = mysql_fetch_assoc($myres);
$maxidlp = $myrows['max'];

$sql_LP = "select * from laytime_master where LAYTIME_ID='".$maxidlp."'";
$res_LP = mysql_query($sql_LP);
$rowsLP = mysql_fetch_assoc($res_LP);
 

/******************* for Discharge Port ********************/

$mysql = "select max(LAYTIME_ID) as max from laytime_master where COMID='".$comid."' and LOGIN='INTERNAL_USER' and MODULEID='".$_SESSION['moduleid']."' and MCOMPANYID='".$_SESSION['company']."' and REVERSIBLE='1' and SUBMITID='5' and PORT='DP'";

$myres  =  mysql_query($mysql,$connect);
$myrows = mysql_fetch_assoc($myres);
$maxidDP = $myrows['max'];

$sql_DP = "select * from laytime_master where LAYTIME_ID='".$maxidDP."'";
$res_DP = mysql_query($sql_DP);
$rowsDP = mysql_fetch_assoc($res_DP);

$uid	  = $_SESSION['uid'];
$moduleid = $_SESSION['moduleid'];
if($page == 1)
{
	$linkid = 4;
}
else
{
	$linkid = 5;
}
$rights = $obj->getUserRights($uid,$moduleid,$linkid);

$pagename = basename($_SERVER['PHP_SELF'])."?comid=".$comid."&page=".$page;
$msg = NULL;
if(empty($_REQUEST['tab']))
{
   $_REQUEST['tab'] = 0;
}

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");
	$owner = $obj->getVendorListNewData($rowscoa['OWNER'],"NAME");
	$broker  = $obj->getVendorListNewData($rowscoa['BROKER'],"NAME");
	$cargoids = $rowscoa['CARGO'];
	$currency = $rowscoa['CURRENCY'];
}
else
{
	$arrvendor = array();
	if($obj->getFun158()==2)
	{
	    if($obj->getFun228()==1)
        {
		    if($obj->getCompareEstimateData($comid,"CHK_LUMPSUM") == 1)
			{
				$arrvendor[] = $obj->getVendorListNewBasedOnID($obj->getCompareEstimateData($comid,"LUMP_VENDOR"));
			}
			else
			{
				$res11 = mysql_query("select * from freight_cost_estimete_slave12 where FCAID='".$obj->getFun1()."' and CUSTOMER!='' ");
				$num11 = mysql_num_rows($res11);
				while($rows11 = mysql_fetch_assoc($res11))
				{
				   $arrvendor[] = $obj->getVendorListNewData($rows11['CUSTOMER'],"NAME");
				}
			}
		}
		else
		{
			$sql12 = "select SHIPPER_CHARTER, STATUS from freight_cost_estimete_slave10 where FCAID='".$obj->getCompareEstimateData($comid,"FCAID")."' group by SHIPPER_CHARTER";
			$res12 = mysql_query($sql12);
			while($row12 = mysql_fetch_assoc($res12))
			{
				if($row12['STATUS']==1 || $row12['STATUS']==2)
				{
					$arrvendor[]  = $obj->getVendorListNewBasedOnID($row12['SHIPPER_CHARTER']);
				}
			}
		}
	}
	else
	{
		$arrvendor[] = $obj->getVendorListNewData($obj->getCompareEstimateData($comid,"FGFF_VENDORID"),"NAME");
	}
	$charterer = implode(',', $arrvendor);
	$owner = $obj->getVendorListNewData($obj->getCompareEstimateData($comid,"OWNER"),"NAME");
	$broker  = $obj->getVendorListNewData($obj->getCompareEstimateData($comid,"BROKER"),"NAME");
	$cargoids = $obj->getCompareEstimateData($comid,"CARGO_ID");
	$currency = 'USD';
}
?>
<!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(); ?>
<?php $display->js(); ?>
<link href="../../css/jquery.alerts.css" rel="stylesheet" type="text/css" />
<script src='../../js/jquery.autosize.js'></script>
<script language="JavaScript" type="text/javascript" src="../../js/jquery.alerts.js"></script>
<script src="../../js/timer.js" type="text/javascript"></script>
<link href="../../css/datetimepicker/bootstrap-datetimepicker.css" rel="stylesheet" type="text/css" />
<script src="../../js/plugins/datetimepicker/bootstrap-datetimepicker.min.js" type="text/javascript"></script>
<link href="../../css/datepicker/datepicker.css" rel="stylesheet" type="text/css" />
<script src="../../js/bootstrap-datepicker.js" type="text/javascript"></script>
<script language="JavaScript" type="text/javascript" src="../../js/jquery.numeric.js"></script>
<script language="JavaScript" type="text/javascript" src="../../js/jquery.calculation-min.js"></script>
<link type="text/css" href="../../css/chosen.css" rel="stylesheet" />
<script src="../../js/chosen.jquery.js" type="text/javascript"></script>
<script type="text/javascript">

$(function() {
    $("#loader").fadeOut(2000, function() {
        $("#DivOwnerPL").fadeIn(1000);        
    });
});


$(document).ready(function(){  

	// getFinalCalculation();
   $(".chzn-select").chosen();
	$('[id^=txtLPNotes_]').css({"height": "30px"});
	$('[id^=txtLPNotes_],[id^=txtRemarks_],[id^=txtLPTTTerms_]').autosize({append: "\n"});
	$('[id^=txtLPLTparcel_],[id^=txtDPLTparcel_],[id^=txtLPLoadedQty_],[id^=txtLPLoadedRate_],[id^=txtLPDRate_],[id^=txtLPDespatchRate_],[id^=txtLPActualLaytimeInsert_],[id^=txtLPLDeductionTparcent_]').numeric();
	
	$("[id^=txtNor_Tendered_],[id^=txtPilot_onBoard_],[id^=txtDIS_LOD_Commenced_],[id^=txtDIS_LOD_Completed_],[id^=txtNOR_Accepted_],[id^=txtStart_Counting_]").datetimepicker({
		format: 'dd-mm-yyyy hh:ii', 
		autoclose: true,
		todayBtn: true,
		minuteStep: 1	
	});
	
	$('[id^=txtVessel_Arrived_],[id^=txtVessel_Sailed_]').datetimepicker({
		format: 'dd-mm-yyyy hh:ii',
		autoclose: true,
		todayBtn: true,
		minuteStep: 1
		}).on('changeDate', function(){
		var id = this.id.split('_');
		getFinalCalculation(id[2]);
	});

	$("[id^=txtNS_]").datetimepicker({
		format: 'dd-mm-yyyy hh:ii', 
		autoclose: true,
		todayBtn: true,
		minuteStep: 1	
	});
	
	$("[id^=txtLPDStart_],[id^=txtLPDEnd_]").datetimepicker({
		format: 'dd-mm-yyyy hh:ii', 
		autoclose: true,
		todayBtn: true,
		minuteStep: 1	
	}).on('changeDate', function(){
		var id = this.id.split('_');
		getFinalCalculation(id[1]);	
    });
	
	$("[id^=txtLPDDeductionStart_],[id^=txtLPDDeductionEnd_]").datetimepicker({
		format: 'dd-mm-yyyy hh:ii', 
		autoclose: true,
		todayBtn: true,
		minuteStep: 1	
	}).on('changeDate', function(){
		var id = this.id.split('_');
		getFinalCalculation(id[1]);	
	});
	
	
	$('[id^=checkLPLTCounts_]').on('ifChecked', function () { 
		var id = this.id.split('_');
	   $("#checkLPLTNoCounts_"+id[1]+"_"+id[2]).iCheck('uncheck');
		$("#txtLPLTparcel_"+id[1]+"_"+id[2]).removeAttr("readonly");
		if($("#txtLPLTparcel_"+id[1]+"_"+id[2]).val()=='' || $("#txtLPLTparcel_"+id[1]+"_"+id[2]).val()==0)
		{
			$("#txtLPLTparcel_"+id[1]+"_"+id[2]).val("100");
		}
		$("#txtLPLTparcel_"+id[1]+"_"+id[2]).focus();
		getFinalCalculation(id[1]);	   
	});
	$('[id^=checkLPLTNoCounts_]').on('ifChecked', function () { 
		var id = this.id.split('_');
	    $("#checkLPLTCounts_"+id[1]+"_"+id[2]).iCheck('uncheck');
		$("#txtLPLTparcel_"+id[1]+"_"+id[2]).attr("readonly",true);
		if($("#txtLPLTparcel_"+id[1]+"_"+id[2]).val()=='')
		{
			$("#txtLPLTparcel_"+id[1]+"_"+id[2]).val("0");
		}
		$("#txtLPLTparcel_"+id[1]+"_"+id[2]).focus();
		getFinalCalculation(id[1]);
	});
	
	$('[id^=checkLPLTCounts_]').on('ifUnchecked', function () { 
	    var id = this.id.split('_');
		
		$("#txtLPLTparcel_"+id[1]+"_"+id[2]).attr("readonly",true);
		$("#txtLPLTparcel_"+id[1]+"_"+id[2]).val("0");
		$('#txtCummulative_'+id[1]+'_'+id[2]).html("00.00");
		$('#txtCummulative1_'+id[1]+'_'+id[2]).val("00.00");
		getFinalCalculation(id[1]);		
	});
	$('[id^=checkLPLTNoCounts_]').on('ifUnchecked', function () { 
		var id = this.id.split('_');
		$("#txtLPLTparcel_"+id[1]+"_"+id[2]).removeAttr("readonly");
		$("#txtLPLTparcel_"+id[1]+"_"+id[2]).val("100");
		$('#txtCummulative_'+id[1]+'_'+id[2]).html("00.00");
		$('#txtCummulative1_'+id[1]+'_'+id[2]).val("00.00");
		getFinalCalculation(id[1]);
	});
	<?php for($i=0;$i<count($arr);$i++){
		$arr_explode = explode('@@',$arr[$i]);$port_name = $obj->shortPortNameWithCountry($obj->getPortNameBasedOnID($arr_explode[1]));
		if($arr_explode[0]!='TP'){?>
		getLaytime_Allowed(<?php echo $i+1;?>);
	<?php }}?>
});


function getString(var1)
{
	 var var2 = var1.split(' ');
	 var var3 = var2[0].split('-');
	 
	 return var3[2]+'/'+var3[1]+'/'+var3[0]+' '+var2[1];
}

function getDateWithSpecificFormat(sep)
{
	var dateSplit1  = sep.split(' ');
	var dateSplit   = dateSplit1[0].split('-');
	var currentDate = dateSplit[2] + '-' + dateSplit[1] + '-' + dateSplit[0]+' '+dateSplit1[1];
	return currentDate;
}

function getFinalCalculation(val)
{	


	// alert();

	


    if($('#txtVessel_Arrived_'+val).val()!='' && $('#txtVessel_Sailed_'+val).val()!='')
	{ 

		
		var vessel_arrived  =  getString($('#txtVessel_Arrived_'+val).val()); 
		var vessel_sailed    =  getString($('#txtVessel_Sailed_'+val).val());
		
		vessel_arrived  	 =  getDateWithSpecificFormat(vessel_arrived);
		vessel_sailed    =  getDateWithSpecificFormat(vessel_sailed);
		
		start_actual_time 	= new Date(vessel_arrived);
		end_actual_time 	= new Date(vessel_sailed);
	
		var diff 			= end_actual_time - start_actual_time;
		var days			= (diff) / 86400000;
		var days = days.toFixed(4);
		
		if(isNaN(days) || days==''){days = '0.00'}
		$('#txtLPDaysAtPort_'+val).val(days);
	}
	else
	{
	    $('#txtLPDaysAtPort_'+val).val('0.00');
	}

    for(i = 1;i<=$("#txtTBODYID_"+val).val();i++)
	{

	
	    if(typeof($('#txtLPDDeductionStart_'+val+'_'+i).val())!='undefined')
		{
			if($('#txtLPDDeductionStart_'+val+'_'+i).val() != '' &&  $('#txtLPDDeductionEnd_'+val+'_'+i).val() != '')
			{
				var end_actual_time  =  getString($('#txtLPDDeductionEnd_'+val+'_'+i).val()); 
				var start_actual_time    =  getString($('#txtLPDDeductionStart_'+val+'_'+i).val());
				
				start_actual_time = new Date(start_actual_time);
				end_actual_time = new Date(end_actual_time);
			
				var diff = end_actual_time - start_actual_time;
			
				var diffSeconds = diff/1000;
				var HH = Math.floor(diffSeconds/3600);
				
				var MM = Math.floor(diffSeconds%3600)/60/60;
				var HH = parseFloat(HH)+parseFloat(MM);
				var HH = HH.toFixed(4);
				
				$('#txtLPDeductionDiff_'+val+'_'+i).val(HH);
			}
			else
			{
				$('#txtLPDeductionDiff_'+val+'_'+i).val("0.0");
			}
			
			var lp_diff1		 = parseFloat($("#txtLPDeductionDiff_"+val+"_"+i).val());if(isNaN(lp_diff1) || lp_diff1==''){lp_diff1 = 0;}
			var lp_diff = (parseFloat(lp_diff1) * parseFloat($("#txtLPLDeductionTparcent_"+val+"_"+i).val())) / 100;
			if(isNaN(lp_diff)){lp_diff = 0;}
			$("#txtLPDeductionDiff1_"+val+"_"+i).val(parseFloat(lp_diff.toFixed(4)));
		}
	}
	$("#txtLPTotalDeduction_"+val).val($("[id^=txtLPDeductionDiff_"+val+"_]").sum().toFixed(4));
	$("#txtLPTotalDeduction1_"+val).val($("[id^=txtLPDeductionDiff1_"+val+"_]").sum().toFixed(4));

	var crmid = $("#txtCRM_"+val).val();

	// if($('#turn_time_to_add_'+val).val() != ''){



		
	// 	let turn_time_to_add=Number($('#turn_time_to_add_'+val).val());
		
		

	// 	let newlaytime_allowed=Number($("#txtLPLaytimeAllowed_"+val).val())+turn_time_to_add;

		
	// 	$("#txtLPLaytimeAllowed_"+val).val(newlaytime_allowed.toFixed(2));




	// }

	

	var laytime_allowed1 = parseFloat($("#txtLPLaytimeAllowed_"+val).val());

	

	

	if(laytime_allowed1 == ""){var laytime_allowed = 0;}
	else{
	var laytime_allowed = laytime_allowed1;
	}
	var sum = 0;
	var i =1;
	<?php if($obj->getFun158()==1 || $obj->getFun158()==2){?>var divider = 1;<?php }else{?>var divider = 24;<?php }?>
	
	for(i = 1;i<=crmid;i++)
	{
		if($('#txtLPDEnd_'+val+'_'+i).val() != '' &&  $('#txtLPDStart_'+val+'_'+i).val() != '')
		{
			var end_actual_time  =  getString($('#txtLPDEnd_'+val+'_'+i).val()); 
			var start_actual_time    =  getString($('#txtLPDStart_'+val+'_'+i).val());
			
			start_actual_time = new Date(start_actual_time);
			end_actual_time = new Date(end_actual_time);
		
			var diff = end_actual_time - start_actual_time;
		
			var diffSeconds = diff/1000;
			var HH = Math.floor(diffSeconds/3600);
			
			var MM = Math.floor(diffSeconds%3600)/60/60;
			var HH = parseFloat(HH)+parseFloat(MM);
			var HH = HH.toFixed(4);
			
			$('#txtLPDiff_'+val+'_'+i).html(HH);
			$('#txtLPDiff1_'+val+'_'+i).val(HH);
		}
		else
		{
			$('#txtLPDiff_'+val+'_'+i).html("0.0");
			$('#txtLPDiff1_'+val+'_'+i).val("0.0");
		}
		
		var lp_diff1		 = $("#txtLPDiff1_"+val+"_"+i).val();
		var lp_diff = (parseFloat(lp_diff1) * parseFloat($("#txtLPLTparcel_"+val+"_"+i).val())) / 100;
		$("#txtLPVal_"+val+"_"+i).val(parseFloat(lp_diff));
		
		if($("#checkLPLTCounts_"+val+"_"+i).attr('checked'))
		{
			sum = parseFloat(sum) + parseFloat($("#txtLPVal_"+val+"_"+i).val());
			var sum2 = parseFloat(sum)/parseFloat(divider);
			var ttl = parseFloat(laytime_allowed) - parseFloat(sum2);		
			var hh = parseFloat(ttl).toFixed(4);
			$('#txtCummulative_'+val+'_'+i).html(hh);
			$('#txtCummulative1_'+val+'_'+i).val(hh);
		}
		else
		{
		    $('#txtCummulative_'+val+'_'+i).html('0.00');
			$('#txtCummulative1_'+val+'_'+i).val('0.00');	
		}
	}
	
	var actual_time11     = parseFloat($("#txtLPActualLaytime1_"+val).val());if(isNaN(actual_time11)){actual_time11 = 0;}
	var txtLPActualLaytime =  parseFloat(parseFloat(sum)/parseFloat(divider)).toFixed(4);if(isNaN(txtLPActualLaytime)){txtLPActualLaytime = 0;}
	txtLPActualLaytime = parseFloat(txtLPActualLaytime) + parseFloat(actual_time11);
	$("#txtLPActualLaytime_"+val).val(parseFloat(txtLPActualLaytime).toFixed(4));
	


	var actual_time1     = parseFloat($("#txtLPActualLaytime_"+val).val());
	
	var laytime_allowed1 = parseFloat($("#txtLPLaytimeAllowed_"+val).val());
	//alert(actual_time1);
	if(actual_time1 != "" && laytime_allowed1 != "")
	{ 
		if(actual_time1 > laytime_allowed1)
		{ 
		    var deductions = parseFloat($("[id^=txtLPDeductionDiff1_"+val+"_]").sum().toFixed(4));
		    var deductions2 = parseFloat(deductions)/parseFloat(divider);
			var diff = parseFloat(actual_time1) - parseFloat(laytime_allowed1) - parseFloat(deductions2.toFixed(4));
			var hrs = parseFloat(diff).toFixed(4);
			$("#txtLPTimetodemurrage_"+val).val(hrs);
			$("#txtLPTimetodespatch_"+val).val("00.00");
		}
		else if(laytime_allowed1 > actual_time1)
		{ 
			var diff = parseFloat(laytime_allowed1) - parseFloat(actual_time1);
			var hrs = parseFloat(diff).toFixed(4);
			$("#txtLPTimetodespatch_"+val).val(hrs);
			$("#txtLPTimetodemurrage_"+val).val("00.00");
		}
		else
		{ 
			$("#txtLPTimetodemurrage_"+val).val("00.00");
			$("#txtLPTimetodespatch_"+val).val("00.00");
		}
	}
	else
	{
		$("#txtLPTimetodemurrage_"+val).val("00.00");
		$("#txtLPTimetodespatch_"+val).val("00.00");
	}
	
	if(crmid == 0 || crmid == '')
	{
		if(laytime_allowed1 > 0)
		{ 
			$("#txtLPTimetodemurrage_"+val).val("00.00");
			$("#txtLPTimetodespatch_"+val).val(laytime_allowed1);
		}
		else if(laytime_allowed1 < 0)
		{ 
			$("#txtLPTimetodemurrage_"+val).val();
			$("#txtLPTimetodespatch_"+val).val("00.00");
		}
		else
		{ 
			$("#txtLPTimetodemurrage_"+val).val("00.00");
			$("#txtLPTimetodespatch_"+val).val("00.00");
		}
	}
	
	<?php if($obj->getFun158()==1 || $obj->getFun158()==2){?>var divider1 = 24;<?php }else{?>var divider1 = 1;<?php }?>
	if($("#txtLPTimetodemurrage_"+val).val() == ""){var dem = 0;}else{var dem = $("#txtLPTimetodemurrage_"+val).val();}
	if($("#txtLPDRate_"+val).val() == ""){var dem_rate = 0;}else{var dem_rate = $("#txtLPDRate_"+val).val();}
	var days = parseFloat(dem) / parseFloat(divider1);
	var usd = parseFloat(days) * parseFloat(dem_rate);
	$("#txtLPTTLDemurrage_"+val).val(usd.toFixed(2));
	
	if($("#txtLPTimetodespatch_"+val).val() == ""){var despatch = 0;}else{var despatch = $("#txtLPTimetodespatch_"+val).val();}
	if($("#txtLPDespatchRate_"+val).val() == ""){var despatch_rate = 0;}else{var despatch_rate = $("#txtLPDespatchRate_"+val).val();}
	var days = parseFloat(despatch) / parseFloat(divider1);
	var usd = parseFloat(days) * parseFloat(despatch_rate);
	$("#txtLPTTLDespatch_"+val).val(usd.toFixed(2));

	if($("#txtLPActualLaytime_"+val).val()==parseFloat(0.0000)){


		// var totalForDemurrage = $("#txtLPLaytimeAllowed_"+val).val()*$("#txtLPDRate_"+val).val()
		// $("#txtLPTTLDemurrage_"+val).val(totalForDemurrage.toFixed(2));

		var totalForDespatch = $("#txtLPLaytimeAllowed_"+val).val()*$("#txtLPDespatchRate_"+val).val()
		$("#txtLPTTLDespatch_"+val).val(totalForDespatch);

	}


	
}




function getLaytime_Allowed(var1)
{	<?php if($obj->getFun158()!=2){?>
	if($('#txtLPLoadedQty_'+var1).val() != "" && $('#txtLPLoadedRate_'+var1).val() != 0)
	{
		
		<?php if($obj->getFun158()==1){?>
		var getval1 = parseFloat((($('#txtLPLoadedQty_'+var1).val()) / $('#txtLPLoadedRate_'+var1).val())).toFixed(4);	
		<?php }else if($obj->getFun158()==3){?>
		var getval1 = parseFloat((($('#txtLPLoadedQty_'+var1).val()) / $('#txtLPLoadedRate_'+var1).val())).toFixed(4);
		<?php }else{?>
		var getval1 = parseFloat((($('#txtLPLoadedQty_'+var1).val()) / $('#txtLPLoadedRate_'+var1).val()) * 24).toFixed(4);
		<?php }?>
		
		var new_val = parseFloat($('#txtLPAndDPLaytimeAllowed_'+var1).val());if(isNaN(new_val)){ new_val = 0;}if(isNaN(getval1)){ getval1 = 0;}
		if(new_val==""){ var new_lpdpval = 0; } else { var new_lpdpval = new_val; }

		if($('#turn_time_to_add_'+var1).val() != ''){
			getval1= Number(getval1) + (Number($('#turn_time_to_add_'+var1).val())/24);
			
		}
		var getval = parseFloat(parseFloat(getval1)+parseFloat(new_lpdpval)).toFixed(4);

		// if($('#turn_time_to_add_'+var1).val() != ''){

			
		// 	getval= getval + Number($('#turn_time_to_add_'+var1).val());

			
		// }
		$('#txtLPLaytimeAllowed_'+var1).val(getval);
		getFinalCalculation(var1);
	}
	<?php }else{

		?>
		let laytime_allowed =$('#txtLPLaytimeAllowed_'+var1).val() == ''?0:Number($('#txtLPLaytimeAllowed_'+var1).val());

		if($('#turn_time_to_add_'+var1).val() != ''){


			laytime_allowed=Number(laytime_allowed) + (Number($('#turn_time_to_add_'+var1).val())/24) ;

			$('#txtLPLaytimeAllowed_'+var1).val(laytime_allowed);
			
		}else{
			$('#txtLPLaytimeAllowed_'+var1).val(laytime_allowed);
		}

		<?php
	}
	
	
	?>
}

function getSubmit(tabid,submitid,port,portid,serialno)
{
	$("[id^=txttabid_],[id^=txtsubmitid_],[id^=txtport_],[id^=txtportid_],[id^=txtSerialNo_]").val("");
	$("#txttabid_"+tabid).val(tabid);
	$("#txtsubmitid_"+tabid).val(submitid);
	$("#txtport_"+tabid).val(port);
	$("#txtportid_"+tabid).val(portid);
	$("#txtSerialNo_"+tabid).val(serialno);
	
	var var3 = $("[id^=file_"+tabid+"_]").map(function () {return this.value;}).get().join(",");
	$('#txtCRMFILE_'+tabid).val(var3);
	var var2 = $("[id^=name_"+tabid+"_]").map(function () {return this.value;}).get().join(",");
	$('#txtCRMNAME_'+tabid).val(var2);
	

	// console.log( $('#txtLPLoadedQty_'+tabid).val() <= 0)

	// return false;

	var isTanker = '<?= $_SESSION['selBType']?>';

	if(isTanker!=2){



	if($('#txtLPLoadedQty_'+tabid).val().length == 0  ||  $('#txtLPLoadedRate_'+tabid).val().length == 0 || $('#txtLPLoadedQty_'+tabid).val()<= 0 || $('#txtLPLoadedRate_'+tabid).val() <= 0){

		jAlert('Please Check Load Rate Or Quantity', 'Alert');
		return false;

	}
	
	
	else{

	if(submitid==1)
	{   
	    if($('#selApprovers_'+tabid).val()==null || $('#selApprovers_'+tabid).val()=='')
		{
		    jAlert('Please select Level 1 Approvers first.', 'Alert');
			return false;
		}
		else
		{
		    jConfirm('Are you sure you want to Submit?', 'Confirmation', function(r) {
				if(r)
				{
					document.getElementById("frm"+tabid).submit();
				}
				else
				{
					return false;
				}
			});
		}
	}
	else
	{
	    if(submitid >1)
		{
			jConfirm('Are you sure you want to Submit?', 'Confirmation', function(r) {
				if(r)
				{
					document.getElementById("frm"+tabid).submit();
				}
				else
				{
					return false;
				}
			});
		}else{
			document.getElementById("frm"+tabid).submit();
		}
	}
	}

	}else{


		if(submitid==1)
	{   
	    if($('#selApprovers_'+tabid).val()==null || $('#selApprovers_'+tabid).val()=='')
		{
		    jAlert('Please select Level 1 Approvers first.', 'Alert');
			return false;
		}
		else
		{
		    jConfirm('Are you sure you want to Submit?', 'Confirmation', function(r) {
				if(r)
				{
					document.getElementById("frm"+tabid).submit();
				}
				else
				{
					return false;
				}
			});
		}
	}
	else
	{
	    if(submitid >1)
		{
			jConfirm('Are you sure you want to Submit?', 'Confirmation', function(r) {
				if(r)
				{
					document.getElementById("frm"+tabid).submit();
				}
				else
				{
					return false;
				}
			});
		}else{
			document.getElementById("frm"+tabid).submit();
		}
	}
	

	}
}


function getShow(id)
{	
	if($('#selApp_'+id).val() == 1)
	{
		$('#row_'+id).show();
	}
	else
	{
		$('#row_'+id).hide();
	}
}

function getPdf(var1)
{
	location.href='allPdf.php?id=16&laytimeid='+var1;
}

function getExcel(var1)
{
	location.href='allExcel.php?id=6&laytimeid='+var1;
}

function addUI_Row(var1,var3)
{
	
	
	var var2 = $("#txtID_"+var1+"_"+var3).val();
	var id = parseInt(var2)+parseInt(1);
	
	var var4 = $('#txtCRM_'+var1).val();
	var i;
	for(i=id; i<=var4; i++)
	{
		var j = parseInt(i)+parseInt(1);
		
		$('#txtActivity_'+var1+'_'+i).attr('name','txtActivity_r_'+var1+'_'+j);
		$('#txtActivity_'+var1+'_'+i).attr('id','txtActivity_r_'+var1+'_'+j);
		
		$('#txtLPDStart_'+var1+'_'+i).attr('name','txtLPDStart_r_'+var1+'_'+j);
		$('#txtLPDStart_'+var1+'_'+i).attr('id','txtLPDStart_r_'+var1+'_'+j);
		
		$('#txtLPDEnd_'+var1+'_'+i).attr('name','txtLPDEnd_r_'+var1+'_'+j);
		$('#txtLPDEnd_'+var1+'_'+i).attr('id','txtLPDEnd_r_'+var1+'_'+j);
		
		$('#txtLPDiff_'+var1+'_'+i).attr('name','txtLPDiff_r_'+var1+'_'+j);
		$('#txtLPDiff_'+var1+'_'+i).attr('id','txtLPDiff_r_'+var1+'_'+j);
		
		$('#txtLPDiff1_'+var1+'_'+i).attr('name','txtLPDiff1_r_'+var1+'_'+j);
		$('#txtLPDiff1_'+var1+'_'+i).attr('id','txtLPDiff1_r_'+var1+'_'+j);
		
		$('#checkLPLTCounts_'+var1+'_'+i).attr('name','checkLPLTCounts_r_'+var1+'_'+j);
		$('#checkLPLTCounts_'+var1+'_'+i).attr('id','checkLPLTCounts_r_'+var1+'_'+j);
		
		$('#labelLPLTCounts_'+var1+'_'+i).attr('for','checkLPLTCounts_'+var1+'_'+j);
		$('#labelLPLTCounts_'+var1+'_'+i).attr('id','labelLPLTCounts_r_'+var1+'_'+j);
		
		$('#checkLPLTNoCounts_'+var1+'_'+i).attr('name','checkLPLTNoCounts_r_'+var1+'_'+j);
		$('#checkLPLTNoCounts_'+var1+'_'+i).attr('id','checkLPLTNoCounts_r_'+var1+'_'+j);
		
		$('#labelLPLTNoCounts_'+var1+'_'+i).attr('for','checkLPLTNoCounts_'+var1+'_'+j);
		$('#labelLPLTNoCounts_'+var1+'_'+i).attr('id','labelLPLTNoCounts_r_'+var1+'_'+j);
		
		$('#txtLPLTparcel_'+var1+'_'+i).attr('name','txtLPLTparcel_r_'+var1+'_'+j);
		$('#txtLPLTparcel_'+var1+'_'+i).attr('id','txtLPLTparcel_r_'+var1+'_'+j);
		
		$('#txtLPVal_'+var1+'_'+i).attr('name','txtLPVal_r_'+var1+'_'+j);
		$('#txtLPVal_'+var1+'_'+i).attr('id','txtLPVal_r_'+var1+'_'+j);
		
		$('#txtCummulative_'+var1+'_'+i).attr('name','txtCummulative_r_'+var1+'_'+j);
		$('#txtCummulative_'+var1+'_'+i).attr('id','txtCummulative_r_'+var1+'_'+j);
		
		$('#txtCummulative1_'+var1+'_'+i).attr('name','txtCummulative1_r_'+var1+'_'+j);
		$('#txtCummulative1_'+var1+'_'+i).attr('id','txtCummulative1_r_'+var1+'_'+j);
		
		$('#txtLPNotes_'+var1+'_'+i).attr('name','txtLPNotes_r_'+var1+'_'+j);
		$('#txtLPNotes_'+var1+'_'+i).attr('id','txtLPNotes_r_'+var1+'_'+j);
		
		$('#chk_checkLPLTCounts_'+var1+'_'+i).attr('id','chk_checkLPLTCounts_r_'+var1+'_'+j);
		$('#chk_checkLPLTNoCounts_'+var1+'_'+i).attr('id','chk_checkLPLTNoCounts_r_'+var1+'_'+j);
		
		//$('#txtAnch_'+var1+'_'+i).attr('href','javascript:addUI_Row('+var1+','+j+');');
		$('#txtAnch_'+var1+'_'+i).attr('onClick','addUI_Row('+var1+','+j+')');
		$('#txtAnch_'+var1+'_'+i).attr('id','txtAnch_r_'+var1+'_'+j);
		
		$('#txtAnchDel_'+var1+'_'+i).attr('href','javascript:Del_Row('+var1+','+j+');');
		$('#txtAnchDel_'+var1+'_'+i).attr('id','txtAnchDel_r_'+var1+'_'+j);
		
		$("#txtID_"+var1+"_"+i).attr('id','txtID_r_'+var1+'_'+j);
		
		$("#row_"+var1+"_"+i).attr('id','row_r_'+var1+'_'+j);
	}
	
	var4 = parseInt(var4)+1;
	$('#txtCRM_'+var1).val(var4);
	$('#txtTBID_'+var1).val(var4);
	
	var id1 = parseInt(id)+parseInt(1);
	for(i=id1; i<=var4; i++)
	{
		$('#txtActivity_r_'+var1+'_'+i).attr('name','txtActivity_'+var1+'_'+i);
		$('#txtActivity_r_'+var1+'_'+i).attr('id','txtActivity_'+var1+'_'+i);
		
		$('#txtLPDStart_r_'+var1+'_'+i).attr('name','txtLPDStart_'+var1+'_'+i);
		$('#txtLPDStart_r_'+var1+'_'+i).attr('id','txtLPDStart_'+var1+'_'+i);
		
		$('#txtLPDEnd_r_'+var1+'_'+i).attr('name','txtLPDEnd_'+var1+'_'+i);
		$('#txtLPDEnd_r_'+var1+'_'+i).attr('id','txtLPDEnd_'+var1+'_'+i);
		
		$('#txtLPDiff_r_'+var1+'_'+i).attr('name','txtLPDiff_'+var1+'_'+i);
		$('#txtLPDiff_r_'+var1+'_'+i).attr('id','txtLPDiff_'+var1+'_'+i);
		
		$('#txtLPDiff1_r_'+var1+'_'+i).attr('name','txtLPDiff1_'+var1+'_'+i);
		$('#txtLPDiff1_r_'+var1+'_'+i).attr('id','txtLPDiff1_'+var1+'_'+i);
		
		$('#checkLPLTCounts_r_'+var1+'_'+i).attr('name','checkLPLTCounts_'+var1+'_'+i);
		$('#checkLPLTCounts_r_'+var1+'_'+i).attr('id','checkLPLTCounts_'+var1+'_'+i);
		
		$('#labelLPLTCounts_r_'+var1+'_'+i).attr('id','labelLPLTCounts_'+var1+'_'+i);
		
		
		$('#checkLPLTNoCounts_r_'+var1+'_'+i).attr('name','checkLPLTNoCounts_'+var1+'_'+i);
		$('#checkLPLTNoCounts_r_'+var1+'_'+i).attr('id','checkLPLTNoCounts_'+var1+'_'+i);
		
		$('#labelLPLTNoCounts_r_'+var1+'_'+i).attr('id','labelLPLTNoCounts_'+var1+'_'+i);
		
		
		$('#txtLPLTparcel_r_'+var1+'_'+i).attr('name','txtLPLTparcel_'+var1+'_'+i);
		$('#txtLPLTparcel_r_'+var1+'_'+i).attr('id','txtLPLTparcel_'+var1+'_'+i);
		
		$('#txtLPLTparcel_'+var1+'_'+i).attr('onKeyup','getFinalCalculation('+var1+')');
		
		$('#txtLPVal_r_'+var1+'_'+i).attr('name','txtLPVal_'+var1+'_'+i);
		$('#txtLPVal_r_'+var1+'_'+i).attr('id','txtLPVal_'+var1+'_'+i);
		
		$('#txtCummulative_r_'+var1+'_'+i).attr('name','txtCummulative_'+var1+'_'+i);
		$('#txtCummulative_r_'+var1+'_'+i).attr('id','txtCummulative_'+var1+'_'+i);
		
		$('#txtCummulative1_r_'+var1+'_'+i).attr('name','txtCummulative1_'+var1+'_'+i);
		$('#txtCummulative1_r_'+var1+'_'+i).attr('id','txtCummulative1_'+var1+'_'+i);
		
		$('#txtLPNotes_r_'+var1+'_'+i).attr('name','txtLPNotes_'+var1+'_'+i);
		$('#txtLPNotes_r_'+var1+'_'+i).attr('id','txtLPNotes_'+var1+'_'+i);
		
		$('#chk_checkLPLTCounts_r_'+var1+'_'+i).attr('id','chk_checkLPLTCounts_'+var1+'_'+j);
		
		$('#chk_checkLPLTNoCounts_r_'+var1+'_'+i).attr('id','chk_checkLPLTNoCounts_'+var1+'_'+j);
		
		$('#txtAnch_'+var1+'_'+i).attr('onClick','addUI_Row('+var1+','+i+')');
		
		$('#txtAnch_r_'+var1+'_'+i).attr('id','txtAnch_'+var1+'_'+i);
		
		$('#txtAnchDel_r_'+var1+'_'+i).attr('id','txtAnchDel_'+var1+'_'+i);
		
		$("#txtID_r_"+var1+"_"+i).attr('id','txtID_'+var1+'_'+i);
		$('#txtID_'+var1+'_'+i).val(i);
		
		$("#row_r_"+var1+"_"+i).attr('id','row_'+var1+'_'+i);
	}
	
	
	if($("#txtActivity_"+var1+"_"+var2).val() != "" && ($("#txtLPDStart_"+var1+"_"+var2).val() != "" || $("#txtLPDEnd_"+var1+"_"+var2).val() != ""))
	{
	    var val5 = var2;
		var2  = (var2 - 1 )+ 2;	
		
        $("#row_"+var1+"_"+val5).after('<tr id="row_'+var1+'_'+var2+'"><td align="left" valign="middle"><input type="text" class="form-control" name="txtActivity_'+var1+'_'+var2+'" id="txtActivity_'+var1+'_'+var2+'"  value="" autocomplete="off"/ style="width:150px;"></td><td align="left" valign="middle"><input type="text" class="form-control" name="txtLPDStart_'+var1+'_'+var2+'" id="txtLPDStart_'+var1+'_'+var2+'" value="" style="width:135px;" autocomplete="off"/></td><td align="left" valign="middle"><input type="text" class="form-control" name="txtLPDEnd_'+var1+'_'+var2+'" id="txtLPDEnd_'+var1+'_'+var2+'" value="" style="width:135px;" autocomplete="off"/></td><td align="left" valign="middle"><span id="txtLPDiff_'+var1+'_'+var2+'"></span><input type="hidden" class="form-control" name="txtLPDiff1_'+var1+'_'+var2+'" id="txtLPDiff1_'+var1+'_'+var2+'" readonly="true" value="" /></td><td align="left" valign="middle" ><input type="checkbox" name="checkLPLTCounts_'+var1+'_'+var2+'" id="checkLPLTCounts_'+var1+'_'+var2+'" class="form-control" value="1"></td><td align="left" valign="middle"><input type="checkbox" name="checkLPLTNoCounts_'+var1+'_'+var2+'" id="checkLPLTNoCounts_'+var1+'_'+var2+'" class="form-control" value="1"></td><td align="center" valign="middle"><input type="text" class="form-control" name="txtLPLTparcel_'+var1+'_'+var2+'" id="txtLPLTparcel_'+var1+'_'+var2+'" onkeyup="getFinalCalculation('+var1+');" autocomplete="off" value="0" style="width:100px;"/><input type="hidden" class="form-control" name="txtLPVal_'+var1+'_'+var2+'" id="txtLPVal_'+var1+'_'+var2+'" autocomplete="off" value="0" /></td><td align="left" valign="middle"><div style="width:50px;"><span id="txtCummulative_'+var1+'_'+var2+'"></span></div><input type="hidden" class="form-control" name="txtCummulative1_'+var1+'_'+var2+'" id="txtCummulative1_'+var1+'_'+var2+'" readonly="true" value="" /></td><td align="left" valign="middle"><textarea class="form-control" name="txtLPNotes_'+var1+'_'+var2+'" id="txtLPNotes_'+var1+'_'+var2+'" style="width:150px;"></textarea></td><td align="left" valign="middle"><button type="button" id="txtAnch_'+var1+'_'+var2+'" onClick="addUI_Row('+var1+','+var2+');" class="btn btn-primary btn-flat">Add</button><input type="hidden" class="input" name="txtID_'+var1+'_'+var2+'" id="txtID_'+var1+'_'+var2+'" value="'+var2+'" /></td><td align="left" valign="middle" ><a id="txtAnchDel_'+var1+'_'+var2+'" onclick="return Del_Row('+var1+','+var2+');" href="javascript:Del_Row('+var1+','+var2+');"><i class="fa fa-times " style="color:red;"></i></a></td></tr>');
		
		$('#checkLPLTCounts_'+var1+'_'+var2).iCheck({checkboxClass:'icheckbox_minimal'});
		$('#checkLPLTNoCounts_'+var1+'_'+var2).iCheck({checkboxClass:'icheckbox_minimal'});
		
		$("#txtLPDStart_"+var1+"_"+var2).val($("#txtLPDEnd_"+var1+"_"+val5).val());
		
		$('[id^=txtLPNotes_]').autosize({append: "\n"});
		
		$("[id^=txtLPDStart_],[id^=txtLPDEnd_]").datetimepicker({
			format: 'dd-mm-yyyy hh:ii', 
			autoclose: true,
			todayBtn: true,
			minuteStep: 1	
		}).on('changeDate', function(){
			var id = this.id.split('_');
			getFinalCalculation(id[1]);	
		});
	}
	else
	{
			jAlert('Please fill the above entries.', 'Alert');
	}
	
	$('[id^=checkLPLTCounts_]').on('ifChecked', function () { 
		var id = this.id.split('_');
	   $("#checkLPLTNoCounts_"+id[1]+"_"+id[2]).iCheck('uncheck');
		$("#txtLPLTparcel_"+id[1]+"_"+id[2]).removeAttr("readonly");
		if($("#txtLPLTparcel_"+id[1]+"_"+id[2]).val()=='' || $("#txtLPLTparcel_"+id[1]+"_"+id[2]).val()==0)
		{
			$("#txtLPLTparcel_"+id[1]+"_"+id[2]).val("100");
		}
		$("#txtLPLTparcel_"+id[1]+"_"+id[2]).focus();
		getFinalCalculation(id[1]);	   
	});
	$('[id^=checkLPLTNoCounts_]').on('ifChecked', function () { 
		var id = this.id.split('_');
	    $("#checkLPLTCounts_"+id[1]+"_"+id[2]).iCheck('uncheck');
		$("#txtLPLTparcel_"+id[1]+"_"+id[2]).attr("readonly",true);
		if($("#txtLPLTparcel_"+id[1]+"_"+id[2]).val()=='')
		{
			$("#txtLPLTparcel_"+id[1]+"_"+id[2]).val("0");
		}
		$("#txtLPLTparcel_"+id[1]+"_"+id[2]).focus();
		getFinalCalculation(id[1]);
	});
	
	$('[id^=checkLPLTCounts_]').on('ifUnchecked', function () { 
	    var id = this.id.split('_');
		$("#txtLPLTparcel_"+id[1]+"_"+id[2]).attr("readonly",true);
		$("#txtLPLTparcel_"+id[1]+"_"+id[2]).val("0");
		$('#txtCummulative_'+id[1]+'_'+id[2]).html("00.00");
		$('#txtCummulative1_'+id[1]+'_'+id[2]).val("00.00");
		getFinalCalculation(id[1]);		
	});
	$('[id^=checkLPLTNoCounts_]').on('ifUnchecked', function () { 
		var id = this.id.split('_');
		$("#txtLPLTparcel_"+id[1]+"_"+id[2]).removeAttr("readonly");
		$("#txtLPLTparcel_"+id[1]+"_"+id[2]).val("100");
		$('#txtCummulative_'+id[1]+'_'+id[2]).html("00.00");
		$('#txtCummulative1_'+id[1]+'_'+id[2]).val("00.00");
		getFinalCalculation(id[1]);
	});
}

function Del_Row(var1,var2)
{
	jConfirm('Are you sure you want to Delete this entry?', 'Confirmation', function(r) {
	if(r){
	
		$('#row_'+var1+'_'+var2).remove();
		var var12 = var2 - 1;
		$('#txtAnch_'+var1+'_'+var12).css("display","block");
		$('#txtAnchDel_'+var1+'_'+var12).css("display","block");
		
		var var4 = $('#txtCRM_'+var1).val();
		var i;
		for(i=var4; i>var2; i--)
		{
			j = parseInt(i)-parseInt(1);
			
			$('#txtActivity_'+var1+'_'+i).attr('name','txtActivity_r_'+var1+'_'+j);
			$('#txtActivity_'+var1+'_'+i).attr('id','txtActivity_r_'+var1+'_'+j);
			
			$('#txtLPDStart_'+var1+'_'+i).attr('name','txtLPDStart_r_'+var1+'_'+j);
			$('#txtLPDStart_'+var1+'_'+i).attr('id','txtLPDStart_r_'+var1+'_'+j);
			
			$('#txtLPDEnd_'+var1+'_'+i).attr('name','txtLPDEnd_r_'+var1+'_'+j);
			$('#txtLPDEnd_'+var1+'_'+i).attr('id','txtLPDEnd_r_'+var1+'_'+j);
			
			$('#txtLPDiff_'+var1+'_'+i).attr('name','txtLPDiff_r_'+var1+'_'+j);
			$('#txtLPDiff_'+var1+'_'+i).attr('id','txtLPDiff_r_'+var1+'_'+j);
			
			$('#txtLPDiff1_'+var1+'_'+i).attr('name','txtLPDiff1_r_'+var1+'_'+j);
			$('#txtLPDiff1_'+var1+'_'+i).attr('id','txtLPDiff1_r_'+var1+'_'+j);
			
			$('#checkLPLTCounts_'+var1+'_'+i).attr('name','checkLPLTCounts_r_'+var1+'_'+j);
			$('#checkLPLTCounts_'+var1+'_'+i).attr('id','checkLPLTCounts_r_'+var1+'_'+j);
			
			$('#labelLPLTCounts_'+var1+'_'+i).attr('for','checkLPLTCounts_'+var1+'_'+j);
			$('#labelLPLTCounts_'+var1+'_'+i).attr('id','labelLPLTCounts_r_'+var1+'_'+j);
			
			$('#checkLPLTNoCounts_'+var1+'_'+i).attr('name','checkLPLTNoCounts_r_'+var1+'_'+j);
			$('#checkLPLTNoCounts_'+var1+'_'+i).attr('id','checkLPLTNoCounts_r_'+var1+'_'+j);
			
			$('#labelLPLTNoCounts_'+var1+'_'+i).attr('for','checkLPLTNoCounts_'+var1+'_'+j);
			$('#labelLPLTNoCounts_'+var1+'_'+i).attr('id','labelLPLTNoCounts_r_'+var1+'_'+j);
			
			$('#txtLPLTparcel_'+var1+'_'+i).attr('name','txtLPLTparcel_r_'+var1+'_'+j);
			$('#txtLPLTparcel_'+var1+'_'+i).attr('id','txtLPLTparcel_r_'+var1+'_'+j);
			
			$('#txtLPVal_'+var1+'_'+i).attr('name','txtLPVal_r_'+var1+'_'+j);
			$('#txtLPVal_'+var1+'_'+i).attr('id','txtLPVal_r_'+var1+'_'+j);
			
			$('#txtCummulative_'+var1+'_'+i).attr('name','txtCummulative_r_'+var1+'_'+j);
			$('#txtCummulative_'+var1+'_'+i).attr('id','txtCummulative_r_'+var1+'_'+j);
			
			$('#txtCummulative1_'+var1+'_'+i).attr('name','txtCummulative1_r_'+var1+'_'+j);
			$('#txtCummulative1_'+var1+'_'+i).attr('id','txtCummulative1_r_'+var1+'_'+j);
			
			$('#txtLPNotes_'+var1+'_'+i).attr('name','txtLPNotes_r_'+var1+'_'+j);
			$('#txtLPNotes_'+var1+'_'+i).attr('id','txtLPNotes_r_'+var1+'_'+j);
			
			$('#chk_checkLPLTCounts_'+var1+'_'+i).attr('id','chk_checkLPLTCounts_r_'+var1+'_'+j);
			$('#chk_checkLPLTNoCounts_'+var1+'_'+i).attr('id','chk_checkLPLTNoCounts_r_'+var1+'_'+j);
			
			$('#txtAnch_'+var1+'_'+i).attr('onClick','addUI_Row('+var1+','+j+')');
			
			$('#txtAnch_'+var1+'_'+i).attr('href','javascript:addUI_Row('+var1+','+j+');');
			
			$('#txtAnchDel_'+var1+'_'+i).attr('href','javascript:Del_Row('+var1+','+j+');');
			
			
			$("#txtID_"+var1+"_"+i).attr('id','txtID_r_'+var1+'_'+j);
			
			$("#row_"+var1+"_"+i).attr('id','row_r_'+var1+'_'+j);
		}
		
		var4 = parseInt(var4)-parseInt(1);
		$('#txtCRM_'+var1).val(var4);
		$('#txtTBID_'+var1).val(var4);
		
		for(i=var4; i>=var2; i--)
		{
			$('#txtActivity_r_'+var1+'_'+i).attr('name','txtActivity_'+var1+'_'+i);
			$('#txtActivity_r_'+var1+'_'+i).attr('id','txtActivity_'+var1+'_'+i);
			
			$('#txtLPDStart_r_'+var1+'_'+i).attr('name','txtLPDStart_'+var1+'_'+i);
			$('#txtLPDStart_r_'+var1+'_'+i).attr('id','txtLPDStart_'+var1+'_'+i);
			
			$('#txtLPDEnd_r_'+var1+'_'+i).attr('name','txtLPDEnd_'+var1+'_'+i);
			$('#txtLPDEnd_r_'+var1+'_'+i).attr('id','txtLPDEnd_'+var1+'_'+i);
			
			$('#txtLPDiff_r_'+var1+'_'+i).attr('name','txtLPDiff_'+var1+'_'+i);
			$('#txtLPDiff_r_'+var1+'_'+i).attr('id','txtLPDiff_'+var1+'_'+i);
			
			$('#txtLPDiff1_r_'+var1+'_'+i).attr('name','txtLPDiff1_'+var1+'_'+i);
			$('#txtLPDiff1_r_'+var1+'_'+i).attr('id','txtLPDiff1_'+var1+'_'+i);
			
			$('#checkLPLTCounts_r_'+var1+'_'+i).attr('name','checkLPLTCounts_'+var1+'_'+i);
			$('#checkLPLTCounts_r_'+var1+'_'+i).attr('id','checkLPLTCounts_'+var1+'_'+i);
			
			$('#labelLPLTCounts_r_'+var1+'_'+i).attr('id','labelLPLTCounts_'+var1+'_'+i);
			
			
			$('#checkLPLTNoCounts_r_'+var1+'_'+i).attr('name','checkLPLTNoCounts_'+var1+'_'+i);
			$('#checkLPLTNoCounts_r_'+var1+'_'+i).attr('id','checkLPLTNoCounts_'+var1+'_'+i);
			
			$('#labelLPLTNoCounts_r_'+var1+'_'+i).attr('id','labelLPLTNoCounts_'+var1+'_'+i);
			
			$('#txtLPLTparcel_r_'+var1+'_'+i).attr('name','txtLPLTparcel_'+var1+'_'+i);
			$('#txtLPLTparcel_r_'+var1+'_'+i).attr('id','txtLPLTparcel_'+var1+'_'+i);
			
			$('#txtLPLTparcel_'+var1+'_'+i).attr('onKeyup','getFinalCalculation('+var1+')');
			
			$('#txtLPVal_r_'+var1+'_'+i).attr('name','txtLPVal_'+var1+'_'+i);
			$('#txtLPVal_r_'+var1+'_'+i).attr('id','txtLPVal_'+var1+'_'+i);
			
			$('#txtCummulative_r_'+var1+'_'+i).attr('name','txtCummulative_'+var1+'_'+i);
			$('#txtCummulative_r_'+var1+'_'+i).attr('id','txtCummulative_'+var1+'_'+i);
			
			$('#txtCummulative1_r_'+var1+'_'+i).attr('name','txtCummulative1_'+var1+'_'+i);
			$('#txtCummulative1_r_'+var1+'_'+i).attr('id','txtCummulative1_'+var1+'_'+i);
			
			$('#txtLPNotes_r_'+var1+'_'+i).attr('name','txtLPNotes_'+var1+'_'+i);
			$('#txtLPNotes_r_'+var1+'_'+i).attr('id','txtLPNotes_'+var1+'_'+i);
			
			$('#chk_checkLPLTCounts_r_'+var1+'_'+i).attr('id','chk_checkLPLTCounts_'+var1+'_'+j);
			
			$('#chk_checkLPLTNoCounts_r_'+var1+'_'+i).attr('id','chk_checkLPLTNoCounts_'+var1+'_'+j);
			
			$('#txtAnch_'+var1+'_'+i).attr('onClick','addUI_Row('+var1+','+i+')');
			
			$('#txtAnch_r_'+var1+'_'+i).attr('id','txtAnch_'+var1+'_'+i);
			
			$('#txtAnchDel_r_'+var1+'_'+i).attr('id','txtAnchDel_'+var1+'_'+i);
			
			$("#txtID_r_"+var1+"_"+i).attr('id','txtID_'+var1+'_'+i);
			$('#txtID_'+var1+'_'+i).val(i);
			
			$("#row_r_"+var1+"_"+i).attr('id','row_'+var1+'_'+i);
		}
		
		getFinalCalculation(var1);
	
	}
	else
	{
		return false;
	}
	});
}


function addUIDeduction_Row(var1)
{
	var var2 = $("#txtTBODYID_"+var1).val();
	var var5 = var2;
	if($("#txtDeductionActivity_"+var1+"_"+var2).val() != "" && ($("#txtLPDDeductionStart_"+var1+"_"+var2).val() != "" || $("#txtLPDDeductionEnd_"+var1+"_"+var2).val() != ""))
	{
		var2  = parseInt(var2) + 1;	
		
		$('<tr id="rowdeduction_'+var1+'_'+var2+'"><td align="left" valign="middle"><input class="form-control" name="txtDeductionActivity_'+var1+'_'+var2+'" id="txtDeductionActivity_'+var1+'_'+var2+'" value="" style="width:150px;" /></td><td align="left" valign="middle"><input type="text" class="form-control" name="txtLPDDeductionStart_'+var1+'_'+var2+'" id="txtLPDDeductionStart_'+var1+'_'+var2+'" value="" style="width:135px;" autocomplete="off"/></td><td align="left" valign="middle" ><input type="text" class="form-control" name="txtLPDDeductionEnd_'+var1+'_'+var2+'" id="txtLPDDeductionEnd_'+var1+'_'+var2+'" value="" style="width:135px;" autocomplete="off"/></td><td align="left" valign="middle" ><input type="text" class="form-control" name="txtLPDeductionDiff_'+var1+'_'+var2+'" id="txtLPDeductionDiff_'+var1+'_'+var2+'" readonly value=""/></td><td align="left" valign="middle" ><input type="text" class="form-control" name="txtLPLDeductionTparcent_'+var1+'_'+var2+'" id="txtLPLDeductionTparcent_'+var1+'_'+var2+'" onKeyUp="getFinalCalculation('+var1+');" autocomplete="off" value="" style="width:100px;"/></td><td align="left" valign="middle" ><input type="text" class="form-control" name="txtLPDeductionDiff1_'+var1+'_'+var2+'" id="txtLPDeductionDiff1_'+var1+'_'+var2+'" readonly value="" /></td><td align="left" valign="middle" ><textarea class="form-control animated" name="txtLPDeductionNotes_'+var1+'_'+var2+'" id="txtLPDeductionNotes_'+var1+'_'+var2+'" style="width:150px;" ></textarea></td><td><a onClick="DelDeduction_Row('+var1+','+var2+');"><i class="fa fa-times" style="color:red;"></i></a></td></tr></tr>').appendTo("#dudectiontbody_"+var1);
		
		$("#txtLPDDeductionStart_"+var1+"_"+var2).val($("#txtLPDDeductionEnd_"+var1+"_"+var5).val());
		$('[id^=txtLPDeductionNotes_]').autosize({append: "\n"});
		$('[id^=txtLPLDeductionTparcent_]').numeric();
		$("#txtTBODYID_"+var1).val(var2);
		$("[id^=txtLPDDeductionStart_],[id^=txtLPDDeductionEnd_]").datetimepicker({
			format: 'dd-mm-yyyy hh:ii', 
			autoclose: true,
			todayBtn: true,
			minuteStep: 1	
		}).on('changeDate', function(){
			var id = this.id.split('_');
			getFinalCalculation(id[1]);	
		});
	}
	else
	{
			jAlert('Please fill the above entries.', 'Alert');
	}
}

function DelDeduction_Row(var1,var2)
{
	jConfirm('Are you sure you want to Delete this entry?', 'Confirmation', function(r) {
	if(r){
	
		$('#rowdeduction_'+var1+'_'+var2).remove();
		
		
		getFinalCalculation(var1);
	
	}
	else
	{
		return false;
	}
	});
}


function addUI_Row_2(var1)
{
	var id = $("#txtCID_"+var1).val();
	var id1 = $("#txtCID1_"+var1).val();
	
	if(id == 0)
	{

		// console.log(id)

		// console.log(id1)
		// console.log('dpk');
		id  = (id - 1 )+ 2;
		id1  = (id1 - 1 )+ 4;
		
		$('<tr><td width="2%" align="left" valign="top">'+id1+'.</td><td width="48%" align="left" valign="top"><input type="text" name="txtAV_Name_'+var1+'_'+id+'" id="txtAV_Name_'+var1+'_'+id+'" class="form-control" autocomplete="off" value="" /></td><td width="50%" align="left" valign="top"><input type="text" name="txtAV_Value_'+var1+'_'+id+'" id="txtAV_Value_'+var1+'_'+id+'" class="form-control" autocomplete="off" value="" /></td></tr>').appendTo("#sort1_"+var1);
		$("#txtCID_"+var1).val(id);
		$("#txtCID1_"+var1).val(id1);
		
		for(i=0;i<18;i++)
		{ id1  = (id1 - 1 )+ 2; $('#id_'+i).text(id1+'.');}
	}
	else
	{

		// console.log('ldj');

		if($("#txtAV_Name_"+var1+"_"+id).val() != "" && $("#txtAV_Value_"+var1+"_"+id).val() != "")
		{
			id  = (id - 1 )+ 2;
			id1  = (id1 - 1 )+ 2;
			
			$('<tr><td width="2%" align="left" valign="top">'+id1+'.</td><td width="48%" align="left" valign="top"><input type="text" name="txtAV_Name_'+var1+'_'+id+'" id="txtAV_Name_'+var1+'_'+id+'" class="form-control" autocomplete="off" value="" /></td><td width="50%" align="left" valign="top"><input type="text" name="txtAV_Value_'+var1+'_'+id+'" id="txtAV_Value_'+var1+'_'+id+'" class="form-control" autocomplete="off" value="" /></td></tr>').appendTo("#sort1_"+var1);
			$("#txtCID_"+var1).val(id);
			$("#txtCID1_"+var1).val(id1);
			
			for(i=0;i<18;i++)
			{ id1  = (id1 - 1 )+ 2; $('#id_'+i).text(id1+'.');}
		}
		else
		{
			jAlert('Please fill the above entries.', 'Alert');
		}
	}	
}

function Del_Upload(var1, val2)
{
	jConfirm('Are you sure you want to remove this attachment permanently ?', 'Confirmation', function(r) {
	if(r){
			$("#row_file1_"+var1+"_"+val2).remove();	
		 }
	else{return false;}
	});
}


function getSubmit1()
{

	let nav_id = $('.nav-tabs').find('li.active').attr('data-num');

	let laytime_id=$('#tabs_'+nav_id).find('.laytime_id').val();

	$('#frm_open').append("<input type='hidden' name='laytime_id' value='"+laytime_id+"'/>");
    jConfirm('Are you sure you want to open Laytime?. After submit laytime for all below ports will open.', 'Confirmation', function(r) {
	if(r){
			document.getElementById("frm_open").submit();
		 }
	else{return false;}
	});
}

</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>
.animated {
	vertical-align: top; 
	transition: height 0.2s;
	-webkit-transition: height 0.2s; 
	-moz-transition: height 0.2s; 
}
form.cmxform label.error, label.error {
	/* remove the next line when you have trouble in IE6 with labels in list */
	font-family:Verdana, Arial, Helvetica, sans-serif;
	font-size:10px;
	color: red;
	font-style:normal;
	font-weight:lighter;
	margin:5px;
	vertical-align:top;
}
</style>
</head>
    <body class="skin-blue fixed">

	<div  id="loader"  class="box-body table-responsive" style="position: fixed;top: 0px;left: 0px; width: 100%;height: 100%;z-index: 9999; background: url('../../img/loading.gif') 
              50% 50% no-repeat rgb(249,249,249);">
						
					</div> 
        <!-- header logo: style can be found in header.less -->
        <?php $display->header_tag(); ?>
		<div class="wrapper row-offcanvas row-offcanvas-left">
            <?php $display->leftmenu($nav); ?>
			<aside class="right-side">                
                <!-- Content Header (Page header) -->
                 <section class="content-header">
                    <h1>
                        <i class="fa fa-book"></i>&nbsp;Ops <?php echo $subtitle;?>&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 <?php echo $subtitle;?>&nbsp;&nbsp;&nbsp;>&nbsp;&nbsp;&nbsp;<?php echo $page_bar;?></li>
                    </ol>
                </section>
                <!-- Main content -->
                <section class="content invoice">
					<!--   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> Laytime 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>Sorry!</b> this Laytime is already exists for this port.
								</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> Laytime opened successfully.
									</div>
								<?php }?>
						<?php }?>
						<?php $psqone = "select * from laytime_master where COMID='".$comid."' and SUBMITID=5";
								$presone = mysql_query($psqone);
								$precone = mysql_num_rows($presone);?>
					    <form name="frm_open" id="frm_open" enctype="multipart/form-data" action="<?php echo $pagename;?>" method="post"/>
							<div align="right">
							<input type="hidden" name="action_open" id="action_open" value="submit_open" />
							<?php if($precone>0 && $openingright==1){?><button type="button" onClick="return getSubmit1();" class="btn btn-danger btn-flat open_btn">Open</button>
								
								
								<?php }?>&nbsp;&nbsp;&nbsp;&nbsp;<a href="<?php echo $page_link;?>"><button type="button" class="btn btn-info btn-flat">Back</button></a></div>
						</form>
						<div style="height:10px;">&nbsp;</div>
						<div class="row">
							<div class="col-xs-12">
								<h2 class="page-header" style="text-align:center;">
							<?php echo strtoupper($obj->getEstimateList($_SESSION['selBType']));?> LAYTIME CALCULATIONS
								</h2>                            
							</div><!-- /.col -->
						</div>			
						<div class="row invoice-info">
							<div class="col-md-12">
								<!-- Custom Tabs -->
								<div id="tabs" class="nav-tabs-custom">
									<ul class="nav nav-tabs">
									<?php $i = 0;for($ln=0;$ln<count($arr);$ln++){
										$arr_explode = explode('@@',$arr[$ln]);
										
										$port_name = $obj->shortPortNameWithCountry($obj->getPortNameBasedOnID($arr_explode[1]));
										if($arr_explode[0]!='TP'){?>


										<li data-num="<?=$i+1?>"  data-seltype="<?=$_SESSION['selBType']?>" class="<?php if($_REQUEST['tab'] == $i){ echo 'active';} ?>"><a href="#tabs_<?php echo $i+1;?>" data-toggle="tab"><?php echo $arr_explode[0]."-".$port_name;?></a></li>
									<?php $i++;}}?>
									</ul>
									<div class="tab-content">
									
									<!----------------------------------------------- Start 1------------------------------------------------->
									<?php
									$LPReverssible = 0;$i = 0; 
									for($ln=0;$ln<count($arr);$ln++){$arr_explode = explode('@@',$arr[$ln]);$port_name = $obj->shortPortNameWithCountry($obj->getPortNameBasedOnID($arr_explode[1])); 
									 if($arr_explode[0]!='TP'){?>
									<div id="tabs_<?php echo $i+1;?>" class="tab-pane <?php if($_REQUEST['tab'] == $i){ echo 'active';} ?>">
									<form name="frm<?php echo $i+1;?>" id="frm<?php echo $i+1;?>" enctype="multipart/form-data" action="<?php echo $pagename;?>" method="post"/>
									<?php
									
									$psql = "select * from laytime_master where COMID='".$comid."' and LOGIN='INTERNAL_USER' and MODULEID='".$_SESSION['moduleid']."' and MCOMPANYID='".$_SESSION['company']."' and PORT='".$arr_explode[0]."' and PORTID='".$arr_explode[1]."' and RANDOMID='".$arr_explode[2]."'";

										
										
									$pres = mysql_query($psql);
									$prec = mysql_num_rows($pres);
									$prows = mysql_fetch_assoc($pres);

									echo "<input type='hidden' name='laytime_id_specific' class='laytime_id' id='laytime_id_".($i+1)."' value='".$prows['LAYTIME_ID']."' />";
									echo "<input type='hidden'   class='submit_id'  value='".$prows['SUBMITID']."' />";

									// echo "<pre>";

									// print_r($prows);

								

									
									if($prec != 0 && $prows['APPLICABLE_STATUS'] == 1){
									?>
									
									<?php }?>
									<div>
									<input type="hidden" value="0" name="txtShow_<?php echo $i+1;?>" id="txtShow_<?php echo $i+1;?>"/>
									<input type="hidden" name="txttabid[]" id="txttabid_<?php echo $i+1;?>" class="form-control" size="10" readonly value="" />
									<input type="hidden" name="txtsubmitid_<?php echo $i+1;?>" id="txtsubmitid_<?php echo $i+1;?>" class="form-control" size="10" readonly value="" />
									<input type="hidden" name="txtport_<?php echo $i+1;?>" id="txtport_<?php echo $i+1;?>" class="form-control" size="10" readonly value="" />
									<input type="hidden" name="txtportid_<?php echo $i+1;?>" id="txtportid_<?php echo $i+1;?>" class="form-control" size="10" readonly value="" />
                                    <input type="hidden" name="txtSerialNo_<?php echo $i+1;?>" id="txtSerialNo_<?php echo $i+1;?>" class="form-control" readonly value="" />
									
									<input type="hidden" name="txtCRMFILE_<?php echo $i+1;?>" id="txtCRMFILE_<?php echo $i+1;?>" value="" />
					                        <input type="hidden" name="txtCRMNAME_<?php echo $i+1;?>" id="txtCRMNAME_<?php echo $i+1;?>" value="" />
									</div>
									<?php
									$sql = "select * from sof_master where COMID='".$comid."'";
									$res = mysql_query($sql);
									$rows = mysql_fetch_assoc($res);
									
									$mysql2 = "select * from laytime_master where COMID='".$comid."' and LOGIN='INTERNAL_USER' and MODULEID='".$_SESSION['moduleid']."' and MCOMPANYID='".$_SESSION['company']."' and REVERSIBLE='1' and SUBMITID='5' and PORT='".$arr_explode[0]."' and PORTID='".$arr_explode[1]."' and RANDOMID='".$arr_explode[2]."'";
									$myres2  =  mysql_query($mysql2,$connect);
									$myrows2 = mysql_fetch_assoc($myres2);
									
									if(substr($arr[$ln],0,2)=='LP'){
										if($myrows2['TIME_TO_DEMURRAGE']==00.00){ 
											$arr_1[0][$i] = $myrows2['TIME_TO_DESPATCH'];
										}
										else{ 
											$arr_1[0][$i] = '-'.$myrows2['TIME_TO_DEMURRAGE'];
										}
									}
									else{
										if($myrows2['TIME_TO_DEMURRAGE']==00.00){ 
											$arr_1[1][$i] = $myrows2['TIME_TO_DESPATCH'];
										}
										else{ 
											$arr_1[1][$i] = '-'.$myrows2['TIME_TO_DEMURRAGE'];
										}
									}
									
									$query = "select * from laytime_master where COMID='".$comid."' and LOGIN='INTERNAL_USER' and MODULEID='".$_SESSION['moduleid']."' and MCOMPANYID='".$_SESSION['company']."' and PORT='".substr($arr[$ln],0,2)."' and PORT='".$arr_explode[0]."' and PORTID='".$arr_explode[1]."' and RANDOMID='".$arr_explode[2]."'";
									$qres5 = mysql_query($query);
									$qrec5 = mysql_num_rows($qres5);
									$qrows5 = mysql_fetch_assoc($qres5);
									
									$style = ''; $style1 = '';
									if($qrec5 != 0)
									{
										if($qrows5['APPLICABLE_STATUS'] == 0){$style = 'selected="selected"'; $style1 = 'style="display:none;"';}else{$style = ''; $style1 = '';}
									}
									?>
									<script>$(document).ready(function(){  getFinalCalculation(<?php echo $i+1;?>);});</script>
									<div class="row invoice-info">
                                    <?php if($qrec5>0)
									{?>
                                        <div class="col-sm-6 invoice-col" style="text-align:left;">
                                            <a href="allPdf.php?id=85&laytimeid=<?php echo $qrows5['LAYTIME_ID'];?>&comid=<?php echo $comid;?>&port=<?=$arr_explode[0]?>&portid=<?=$arr_explode[1]?>&ramdomid=<?=$arr_explode[2]?>" title="Pdf" ><button class="btn btn-default" style="margin-right: 5px;" type="button"><i class="fa fa-download"></i> Download  Laytime Report / Port</button></a><br/><br/>
                                        </div>
                                        <div class="col-sm-6 invoice-col" style="text-align:right;">
                                            <a href="allPdf.php?id=85&laytimeid=<?php echo $qrows5['LAYTIME_ID'];?>&comid=<?php echo $comid;?>" title="Pdf" ><button class="btn btn-default" style="margin-right: 5px;" type="button"><i class="fa fa-download"></i> Download Consolidated Laytime Report</button></a><br/><br/>
                                        </div>
                                    <?php }?>
                                    </div>
									<?php
									$sql1 = "select * from laytime_master where COMID='".$comid."' and LOGIN='INTERNAL_USER' and MODULEID='".$_SESSION['moduleid']."' and MCOMPANYID='".$_SESSION['company']."' and PORT='".$arr_explode[0]."' and PORTID='".$arr_explode[1]."' and RANDOMID='".$arr_explode[2]."' and SOF_LOADPORTID='".$rows['SOFID']."'";
									$res1 = mysql_query($sql1);
									$rows1 = mysql_fetch_assoc($res1);

									
									$rec1 = mysql_num_rows($res1);?>
									
									<div class="box-body table-responsive">
									<div>
									<table class="table table-bordered dataTable">
									<tbody id="sort1_<?php echo $i+1;?>"> 
									<tr>
										<td width="2%" align="left" valign="top">1.</td>
										<td width="48%" align="left" valign="top">NAME OF VESSEL</td>
										<td width="50%" align="left" valign="top"><?php echo $obj->getVesselIMOData($obj->getCompareEstimateData($comid,"VESSEL_IMO_ID"),"VESSEL_NAME");?><input type="hidden" name="txtportSerialid_<?php echo $i+1;?>" id="txtportSerialid_<?php echo $i+1;?>" class="form-control" readonly value="<?php echo $i+1;?>" /></td>
									</tr>
									<tr>
									<td width="2%" align="left" valign="top">2.</td>
									<td width="48%" align="left" valign="top">BUILT</td>
									<td width="50%" align="left" valign="top"><input type="text" name="txtVAPS_<?php echo $i+1;?>" id="txtVAPS_<?php echo $i+1;?>" class="form-control" autocomplete="off" value="<?php echo $obj->getVesselIMOData($obj->getCompareEstimateData($comid,"VESSEL_IMO_ID"),"YEARBUILT");?>" readonly/></td>
									</tr>
									
									<tr>
										<td width="2%" align="left" valign="top">3.</td>
										<td width="48%" align="left" valign="top">GRT/NRT</td>
										<td width="50%" align="left" valign="top"><input type="text" name="txtVA_<?php echo $i+1;?>" id="txtVA_<?php echo $i+1;?>" class="form-control" autocomplete="off" value="<?php echo $obj->getVesselIMOData($obj->getCompareEstimateData($comid,"VESSEL_IMO_ID"),"GRT_NRT").'/'.$obj->getVesselIMOData($obj->getCompareEstimateData($comid,"VESSEL_IMO_ID"),"NRT");?>" readonly/></td>
									</tr>
									
									
									<?php if($obj->getCompareEstimateData($comid,"ESTIMATE_TYPE")!=2){?>
                                    <tr>
                                        <td width="2%" align="left" valign="top">4.</td>
                                        <td width="48%" align="left" valign="top">GEAR/GRABS</td>
                                        <td width="50%" align="left" valign="top"><input type="text" name="txtAA_<?php echo $i+1;?>" id="txtAA_<?php echo $i+1;?>" class="form-control" autocomplete="off" value="<?php echo $obj->getVesselIMOData($obj->getCompareEstimateData($comid,"VESSEL_IMO_ID"),"CARGO_GEAR");?>" readonly/></td>
                                    </tr>
                                    <tr>
                                        <td width="2%" align="left" valign="top">5.</td>
                                        <td width="48%" align="left" valign="top">HATCH/HOLD</td>
                                        <td width="50%" align="left" valign="top"><input type="text" name="txtPBFB_<?php echo $i+1;?>" id="txtPBFB_<?php echo $i+1;?>" class="form-control" autocomplete="off" value="<?php echo $obj->getVesselIMOData($obj->getCompareEstimateData($comid,"VESSEL_IMO_ID"),"HATCH_SIZE");?>" readonly/></td>
                                    </tr>
                                    <?php }else{?>
                                    <tr>
                                        <td width="2%" align="left" valign="top">4.</td>
                                        <td width="48%" align="left" valign="top">NO. OF CARGO PUMP(Main)</td>
                                        <td width="50%" align="left" valign="top"><input type="text" name="txtAA_<?php echo $i+1;?>" id="txtAA_<?php echo $i+1;?>" class="form-control" autocomplete="off" value="<?php echo $obj->getVesselIMOData($obj->getCompareEstimateData($comid,"VESSEL_IMO_ID"),"TANKER_CARGO_PUMP");?>" readonly/></td>
                                    </tr>
                                    <tr>
                                        <td width="2%" align="left" valign="top">5.</td>
                                        <td width="48%" align="left" valign="top">CARGO PUMP MAIN CAP(CBM/Hr)</td>
                                        <td width="50%" align="left" valign="top"><input type="text" name="txtPBFB_<?php echo $i+1;?>" id="txtPBFB_<?php echo $i+1;?>" class="form-control" autocomplete="off" value="<?php echo $obj->getVesselIMOData($obj->getCompareEstimateData($comid,"VESSEL_IMO_ID"),"TANKER_PUMP_MAINCAP");?>" readonly/></td>
                                    </tr>	
                                   <?php }?>	
									
									<tr>
										<td width="2%" height="20" align="left" valign="top" colspan="3"></td>
									</tr>
									
									<tr>
										<td width="2%" align="left" valign="top">6.</td>
										<td width="48%" align="left" valign="top">PORT/TERMINAL/BERTH/ANCHORAGE</td>
										<td width="50%" align="left" valign="top"><input type="text" name="txtTerminal_<?php echo $i+1;?>" id="txtTerminal_<?php echo $i+1;?>" class="form-control" autocomplete="off" value="<?php echo $rows1['TERMINAL'];?>" /></td>
									</tr>
									
									<tr>
										<td width="2%" height="20" align="left" valign="top" colspan="3"></td>
									</tr>
									
									<tr>
										<td width="2%" align="left" valign="top">7.</td>
										<td width="48%" align="left" valign="top">STOWAGE PLAN QUANTITY (MT)</td>
										<td width="50%" align="left" valign="top"><input type="text" name="txtStowageQty_<?php echo $i+1;?>" id="txtStowageQty_<?php echo $i+1;?>" class="form-control" autocomplete="off" value="<?php echo $rows1['STOWAGE_QTY'];?>" /></td>
									</tr>
									
									<tr>
										<td width="2%" align="left" valign="top">8.</td>
										<td width="48%" align="left" valign="top">VESSEL ARRIVED</td>
										<td width="50%" align="left" valign="top"><input type="text" name="txtVessel_Arrived_<?php echo $i+1;?>" id="txtVessel_Arrived_<?php echo $i+1;?>" class="form-control" autocomplete="off" value="<?php echo $rows1['VESSEL_ARRIVED'];?>"  /></td>
									</tr>
									
									<tr>
										<td width="2%" align="left" valign="top">9.</td>
										<td width="48%" align="left" valign="top">NOR TENDERED</td>
										<td width="50%" align="left" valign="top"><input type="text" name="txtNor_Tendered_<?php echo $i+1;?>" id="txtNor_Tendered_<?php echo $i+1;?>" class="form-control" autocomplete="off" value="<?php echo $rows1['NOR_TENDERED'];?>"  /></td>
									</tr>
									
									<tr>
										<td width="2%" align="left" valign="top">10.</td>
										<td width="48%" align="left" valign="top">NOR ACCEPTED / VALIDATED</td>
										<td width="50%" align="left" valign="top"><input type="text" name="txtNOR_Accepted_<?php echo $i+1;?>" id="txtNOR_Accepted_<?php echo $i+1;?>" class="form-control" autocomplete="off" value="<?php echo $rows1['NOR_ACCEPTED'];?>" /></td>
									</tr>
									<tr>
										<td width="2%" align="left" valign="top">11.</td>
										<td width="48%" align="left" valign="top">LAYTIME TO START COUNTING </td>
										<td width="50%" align="left" valign="top"><input type="text" name="txtStart_Counting_<?php echo $i+1;?>" id="txtStart_Counting_<?php echo $i+1;?>" class="form-control" autocomplete="off" value="<?php echo $rows1['START_COUNTING'];?>" /></td>
									</tr>
									
									<tr>
										<td width="2%" align="left" valign="top">12.</td>
										<td width="48%" align="left" valign="top">SAILING TIME</td>
										<td width="50%" align="left" valign="top"><input type="text" name="txtPilot_onBoard_<?php echo $i+1;?>" id="txtPilot_onBoard_<?php echo $i+1;?>" class="form-control" autocomplete="off" value="<?php echo $rows1['PILOT_ON_BOARD'];?>"  /></td>
									</tr>
									
									<tr>
										<td width="2%" align="left" valign="top">13.</td>
										<td width="48%" align="left" valign="top">LOAD/DISCH COMMENCED</td>
										<td width="50%" align="left" valign="top"><input type="text" name="txtDIS_LOD_Commenced_<?php echo $i+1;?>" id="txtDIS_LOD_Commenced_<?php echo $i+1;?>" class="form-control" autocomplete="off" value="<?php echo $rows1['LOAD_DIS_COMMENCED'];?>" /></td>
									</tr>
									
									<tr>
										<td width="2%" align="left" valign="top">14.</td>
										<td width="48%" align="left" valign="top">LOAD/DISCH COMPLETED</td>
										<td width="50%" align="left" valign="top"><input type="text" name="txtDIS_LOD_Completed_<?php echo $i+1;?>" id="txtDIS_LOD_Completed_<?php echo $i+1;?>" class="form-control" autocomplete="off" value="<?php echo $rows1['LOAD_DIS_COMPLETED'];?>" /></td>
									</tr>
									
									<tr>
										<td width="2%" align="left" valign="top">15.</td>
										<td width="48%" align="left" valign="top">VESSEL SAILED</td>
										<td width="50%" align="left" valign="top"><input type="text" name="txtVessel_Sailed_<?php echo $i+1;?>" id="txtVessel_Sailed_<?php echo $i+1;?>" class="form-control" autocomplete="off" value="<?php echo $rows1['VESSEL_SAILED'];?>"/></td>
									</tr>
									
									<?php
									$k = 13; $j = 0;
									$sql_1 = "select * from laytime_slave2 where LAYTIME_ID='".$rows1['LAYTIME_ID']."'";
									$res_1 = mysql_query($sql_1);
									$rec_1 = mysql_num_rows($res_1);
									if($rec_1 > 0)
									{ 
										while($rows_1 = mysql_fetch_assoc($res_1))
										{ $k = $k+1; $j = $j+1;
									?>
									<tr>
									<td width="2%" align="left" valign="top"><?php echo $k;?>.</td>
									<td width="48%" align="left" valign="top"><input type="text" name="txtAV_Name_<?php echo $i+1;?>_<?php echo $j;?>" id="txtAV_Name_<?php echo $i+1;?>_<?php echo $j;?>" class="form-control" autocomplete="off" value="<?php echo $rows_1['ENTITY_NAME']; ?>" /></td>
									<td width="50%" align="left" valign="top"><input type="text" name="txtAV_Value_<?php echo $i+1;?>_<?php echo $j;?>" id="txtAV_Value_<?php echo $i+1;?>_<?php echo $j;?>" class="form-control" autocomplete="off" value="<?php echo $rows_1['ENTITY_VALUE']; ?>" /></td>
									</tr>
									<?php }}else{$k = 13; $j = 0;}?>
									
									</tbody>
									
									<tr>
										<td colspan="6" align="left" valign="middle"><button type="button" onClick="addUI_Row_2(<?php echo $i+1;?>);" class="btn btn-primary btn-flat">Add</button><input type="hidden" class="form-control" name="txtCID_<?php echo $i+1;?>" id="txtCID_<?php echo $i+1;?>" value="<?php echo $j;?>" size="5" /><input type="hidden" class="form-control" name="txtCID1_<?php echo $i+1;?>" id="txtCID1_<?php echo $i+1;?>" value="<?php echo $k;?>" size="5" /></td>
									</tr>
									
									</table>
									</div>
									</div>
									
									
									<div class="row invoice-info">
										<div class="col-sm-3 invoice-col">
											Laytime Applicable
											<address>
												<select  name="selApp_<?php echo $i+1;?>" class="form-control" id="selApp_<?php echo $i+1;?>" onChange="getShow(<?php echo $i+1;?>)">
												<option value="1" >Yes</option>
												<option value="0" <?php echo $style;?>>No</option>
												</select>
											</address>
										</div>

									

										<div class="col-sm-3 invoice-col">
											Port Name (Manual) 
											<address>
											<!-- <input  class="form-control port_name_manual" name="port_name_manual" value="<?php // echo  $prows['port_name_manual']; ?>" >			 -->
											<?php
												
											
												if($prows['port_name_manual'] !='' ){

											
											?>
											<textarea class="form-control port_name_manual" name="port_name_manual_<?php echo $i+1;?>">
												<?=  preg_replace('/\s+/', ' ', $prows['port_name_manual'])?>
											</textarea>
<?php
	}else{
		?>

<textarea class="form-control port_name_manual" name="port_name_manual_<?php echo $i+1;?>">
											
											</textarea>
<?php
	}
?>									
										</address>

										</div> 
										<div class="col-sm-3 invoice-col">
											Detention
											<address>
												<input type="checkbox" name="detention_<?php echo $i+1;?>" id="detention_<?php echo $i+1;?>"  <?=$rows1['DETENTION']=='1'?'checked':''?>   class="form-control detention" value="<?=$rows1['DETENTION']=='1'?'1':'0'?>"  />

												<label id="detention_<?php echo $i+1;?>" for="detention_<?php echo $i+1;?>"></label>		
											</address>

											<?php
													if(is_null($rows1['DETENTION'])){
															echo "<input type='hidden' class='dynamic_detention'  name='detention_".($i+1)."' value='0'/>" ;
													}
											?>
												<!--------------------- For REVERSIBLE after submit and close --------------------->
										</div>
                                        <?php if($i+1 < count($arr)){?>
										<div class="col-sm-3 invoice-col">
											Reversible
											<address>
												<!--------------------- For REVERSIBLE after submit and close --------------------->
											<?php 
											if(substr($arr[$ln],0,2)=='LP'){ 
												if($rowsLP['SUBMITID']==5 && $rowsLP['REVERSIABLE']==1){
											?>	
											<input type="checkbox" name="checkLPReverssible_<?php echo $i+1;?>" id="checkLPReverssible_<?php echo $i+1;?>" class="form-control" checked="checked" value="1" /><label id="labelLPReverssible_<?php echo $i+1;?>" for="checkLPReverssible_<?php echo $i+1;?>"></label>
											<?php } 
											else if($qrows5['REVERSIBLE']!=1) { ?>
											<input type="checkbox" name="checkLPReverssible_<?php echo $i+1;?>" id="checkLPReverssible_<?php echo $i+1;?>" class="form-control" value="1" /><label id="labelLPReverssible_<?php echo $i+1;?>" for="checkLPReverssible_<?php echo $i+1;?>"></label>
											<?php } 
											else { ?>
											<input type="checkbox" name="checkLPReverssible_<?php echo $i+1;?>" id="checkLPReverssible_<?php echo $i+1;?>" class="form-control" checked="checked" value="1" /><label id="labelLPReverssible_<?php echo $i+1;?>" for="checkLPReverssible_<?php echo $i+1;?>"></label>
											<?php }} ?>
											
											<?php 
											if(substr($arr[$ln],0,2)=='DP'){ 
												if($rowsDP['SUBMITID']==5){
											?>	
											<input type="checkbox" name="checkLPReverssible_<?php echo $i+1;?>" id="checkLPReverssible_<?php echo $i+1;?>" class="form-control" checked="checked" value="1" /><label id="labelLPReverssible_<?php echo $i+1;?>" for="checkLPReverssible_<?php echo $i+1;?>"></label>
											<?php } 
											else if($qrows5['REVERSIBLE']==0) { ?>
											<input type="checkbox" name="checkLPReverssible_<?php echo $i+1;?>" id="checkLPReverssible_<?php echo $i+1;?>" class="form-control" value="1" /><label id="labelLPReverssible_<?php echo $i+1;?>" for="checkLPReverssible_<?php echo $i+1;?>"></label>
											<?php } 
											else { ?>
											<input type="checkbox" name="checkLPReverssible_<?php echo $i+1;?>" id="checkLPReverssible_<?php echo $i+1;?>" class="form-control" checked="checked" value="1" /><label id="labelLPReverssible_<?php echo $i+1;?>" for="checkLPReverssible_<?php echo $i+1;?>"></label>
											<?php }} ?>
                                            <?php 
											if(substr($arr[$ln],0,2)=='TP'){ 
												if($rowsDP['SUBMITID']==5){
											?>	
											<input type="checkbox" name="checkLPReverssible_<?php echo $i+1;?>" id="checkLPReverssible_<?php echo $i+1;?>" class="form-control" checked="checked" value="1" /><label id="labelLPReverssible_<?php echo $i+1;?>" for="checkLPReverssible_<?php echo $i+1;?>"></label>
											<?php } 
											else if($qrows5['REVERSIBLE']==0) { ?>
											<input type="checkbox" name="checkLPReverssible_<?php echo $i+1;?>" id="checkLPReverssible_<?php echo $i+1;?>" class="form-control" value="1" /><label id="labelLPReverssible_<?php echo $i+1;?>" for="checkLPReverssible_<?php echo $i+1;?>"></label>
											<?php } 
											else { ?>
											<input type="checkbox" name="checkLPReverssible_<?php echo $i+1;?>" id="checkLPReverssible_<?php echo $i+1;?>" class="form-control" checked="checked" value="1" /><label id="labelLPReverssible_<?php echo $i+1;?>" for="checkLPReverssible_<?php echo $i+1;?>"></label>
											<?php }} ?>
											</address>
										</div>
                                        <?php }?>
									</div>
									
									<div id="row_<?php echo $i+1;?>" <?php echo $style1;?>>
									
									<div class="row invoice-info">
										<div class="col-sm-4 invoice-col">
											Entity
											<address>
											<?php
											$sql1 = "select * from laytime_master where COMID='".$comid."' and LOGIN='INTERNAL_USER' and MODULEID='".$_SESSION['moduleid']."' and MCOMPANYID='".$_SESSION['company']."' and PORT='".$arr_explode[0]."' and PORTID='".$arr_explode[1]."' and RANDOMID='".$arr_explode[2]."' and SOF_LOADPORTID='".$rows['SOFID']."'";
											$res1 = mysql_query($sql1);
											$rows1 = mysql_fetch_assoc($res1);
											$rec1 = mysql_num_rows($res1);
											if($rec1 == 0)
											{
											?>
											Ship Owner
											<?php }else{?>
											Ship Owner
											<?php }?>
											</address>
										</div>
										<div class="col-sm-4 invoice-col">
											Charterer
											<address>
											    <input type="hidden" name="selVendor_<?php echo $i+1;?>" id="selVendor_<?php echo $i+1;?>" value="<?php echo $arr_explode[4];?>" />
                                                <?php 
												echo $charterer;
												
												?>
												
											</address>
										</div>
										<div class="col-sm-4 invoice-col">
                                            Cargo
                                            <address>
                                            <?php echo $obj->getCargoNameListForMultipleNamemultiple($cargoids);?>
                                            </address>
                                        </div>
									</div>
									
									<div class="row invoice-info">
										<div class="col-sm-4 invoice-col">
											Nomination ID
											<address>
												<input type="text" name="txtLPNomID_<?php echo $i+1;?>" id="txtLPNomID_<?php echo $i+1;?>" class="form-control"  readonly="true" value="<?php echo $obj->getCompareTableData($comid,"MESSAGE");?>" />
											</address>
										</div>
										
									
									
							 <?php //if($_SESSION['selBType'] != 2){ ?> 
										<div class="col-sm-4 invoice-col">
										<?php if(substr($arr[$ln],0,2) == "LP"){ $name = 'Load'; } else { $name = 'Discharge';}?>
												<?php echo $name;?> Qty (MT)
												<address>
													<?php if(substr($arr[$ln],0,2) == "LP"){ $name_1 = 'BL_QTY_LOADED'; } else { $name_1 = 'BL_QTY_LOADED';}?>
													<?php if($rec1 == 0){?>
													<input type="text" name="txtLPLoadedQty_<?php echo $i+1;?>" id="txtLPLoadedQty_<?php echo $i+1;?>" class="form-control" value="<?php echo $arr_explode[3];?>" onKeyUp="getLaytime_Allowed(<?php echo $i+1;?>)" autocomplete="off"/>
													<?php }else{?>
													<input type="text" name="txtLPLoadedQty_<?php echo $i+1;?>" id="txtLPLoadedQty_<?php echo $i+1;?>" class="form-control" value="<?php echo $rows1['LOADED_QTY'];?>"  onkeyup="getLaytime_Allowed(<?php echo $i+1;?>);" autocomplete="off"/>
													<?php }?>
												</address>
										</div>
										<div class="col-sm-4 invoice-col">
											<?php echo $name;?> Rate <?php if($obj->getFun158()==1){echo '(CBM/Hr)';}if($obj->getFun158()==2){echo '(MT/Hr)';}if($obj->getFun158()==3){echo '(MT/Day)';}?>
											<address>
                                            <?php if($rec1 == 0){?>
												<input type="text" name="txtLPLoadedRate_<?php echo $i+1;?>" id="txtLPLoadedRate_<?php echo $i+1;?>" class="form-control" value="<?php echo $arr_explode[6];?>"  onkeyup="getLaytime_Allowed(<?php echo $i+1;?>)" autocomplete="off"/>
                                            <?php }else{?>
													<input type="text" name="txtLPLoadedRate_<?php echo $i+1;?>" id="txtLPLoadedRate_<?php echo $i+1;?>" class="form-control" value="<?php echo $rows1['LOADED_RATE'];?>"  onkeyup="getLaytime_Allowed(<?php echo $i+1;?>)" autocomplete="off"/>
											<?php }?>
											</address>
										</div> 
							<?php // } ?> 
									</div>
									
									<?php if($obj->getFun158()==1 || $obj->getFun158()==2){$title1 = "Hrs";	}else{$title1 = "Days";	}?>
							   
								  
									
									<?php 
									$j = $i-1;
									
									//print_r($arr_1);
									if(substr($arr[$ln],0,2) == "LP"){ $value = $arr_1[0][$j]; } else{ $value = $arr_1[1][$j]; }
									?>
									<?php 
									if(!isset($rows1['LAYTIME_ALLOWED']))
									{
										$saveddemurrage = $despetchtime - $demuragetime;
									}else{if($LPReverssible==1){$saveddemurrage = $despetchtime - $demuragetime;}else{$saveddemurrage = $rows1['LAYTIME_ALLOWED'];}}
									//echo $saveddemurrage;
									?>
									<div class="row invoice-info">

									<div class="col-sm-3 invoice-col">
											Turn Time (To Add) Hours <br> &nbsp;
											<address>
												<input type="text" data-tm="<?=$rows1['TURN_TIME_TO_ADD']?>" name="turn_time_to_add_<?php echo $i+1;?>" id="turn_time_to_add_<?php echo $i+1;?>" placeholder="Add Hours" class="form-control" onkeyup="getLaytime_Allowed(<?php echo $i+1;?>)" value="<?PHP echo $rows1['TURN_TIME_TO_ADD'];?>"/>

											</address>
										</div>
										<div class="col-sm-3 invoice-col">
											Laytime Allowed <?=$rows1['REVERSIABLE']?> (<?php echo $title1;?>) <br> &nbsp;
											<address>
												

											<!-- If previous tab is reversible selected on tanker condition -->
											<!-- ldjgrt -->
											<!-- $rows1['REVERSIABLE'] -->
											
											<input type="text"  name="txtLPLaytimeAllowed_<?php echo $i+1;?>" id="txtLPLaytimeAllowed_<?php echo $i+1;?>" class="form-control" onKeyUp="getFinalCalculation(<?php echo $i+1;?>)" <?php if($rows1['LAYTIME_ALLOWED'] != ' '){?> value="<?php echo $rows1['LAYTIME_ALLOWED']; ?>"<?php } else{?> value=" " <?php }?> <?php if($_SESSION['selBType'] == 2){ ?> <?php }else{?> readonly <?php }?> />
										
											<input type="hidden" name="txtLPAndDPLaytimeAllowed_<?php echo $i+1;?>" id="txtLPAndDPLaytimeAllowed_<?php echo $i+1;?>" class="form-control" onKeyUp="getFinalCalculation(<?php echo $i+1;?>)"  value="<?php echo $actualallowed;?>" />
											<?php //echo ($demuragetime - $despetchtime);?>
											</address>
										</div>
										<div class="col-sm-3 invoice-col">
											Actual Laytime As Per Below Entry(<?php echo $title1;?>)
											<br> &nbsp;
											<address>
												<input type="text" name="txtLPActualLaytime_<?php echo $i+1;?>" id="txtLPActualLaytime_<?php echo $i+1;?>" class="form-control txtLPActualLaytime" value="<?PHP echo $rows1['ACTUAL_LAYTIME'];?>" readonly />
												<input type="hidden" name="txtLPActualLaytime1_<?php echo $i+1;?>" id="txtLPActualLaytime1_<?php echo $i+1;?>" class="form-control" onKeyUp="getFinalCalculation(<?php echo $i+1;?>)"  value="<?php echo $actualtimetaken;?>" />
											</address>
										</div>
										<div class="col-sm-3 invoice-col">
											Turn Time <br> &nbsp;
											<address>
												<input type="text" name="txtLPTurnTime_<?php echo $i+1;?>" id="txtLPTurnTime_<?php echo $i+1;?>" class="form-control" value="<?PHP echo $rows1['TURN_TIME'];?>"/>
											</address>
										</div>
									</div>
									
									<div class="row invoice-info">
									    <div class="col-sm-3 invoice-col">
											Time to demurrage(<?php echo $title1;?>)
											<address>
                                            <input type="hidden" name="txthiddnDemuragetime_<?php echo $i+1;?>" id="txthiddnDemuragetime_<?php echo $i+1;?>" value="<?=$demuragetime;?>"/>
                                            <input type="hidden" name="txthiddnDespatchtime_<?php echo $i+1;?>" id="txthiddnDespatchtime_<?php echo $i+1;?>" value="<?=$despetchtime;?>"/>
											<input type="text" name="txtLPTimetodemurrage_<?php echo $i+1;?>" id="txtLPTimetodemurrage_<?php echo $i+1;?>" class="form-control" value="<?PHP echo $rows1['TIME_TO_DEMURRAGE'];?>" readonly />
                                            <?php if($rows1['REVERSIBLE']==1){$demuragetime = $rows1['TIME_TO_DEMURRAGE'];$despetchtime = $rows1['TIME_TO_DESPATCH'];$actualtimetaken = $rows1['ACTUAL_LAYTIME'];$actualallowed = $rows1['LAYTIME_ALLOWED'];}else{$demuragetime = 0;$despetchtime = 0;$actualtimetaken = 0;$actualallowed = 0;}
											//echo $demuragetime;echo $despetchtime;
											?>
											</address>
										</div>
										<div class="col-sm-3 invoice-col">
										<span class="dem_rate_text">Demurrage </span> Rate (<?php echo $currency;?>/Day)
											<address>
											<?php
											if($rec1 == 0){
												?>
													<input type="text" name="txtLPDRate_<?php echo $i+1;?>" id="txtLPDRate_<?php echo $i+1;?>" class="form-control demurrage_rate"   value="<?php echo $arr_explode[9];?>" onKeyUp="getFinalCalculation(<?php echo $i+1;?>);" autocomplete="off"/>
												<?php
											}else{
												?>
													<input type="text" name="txtLPDRate_<?php echo $i+1;?>" id="txtLPDRate_<?php echo $i+1;?>" class="form-control demurrage_rate"  value="<?php echo $rows1['DEMURRAGE_RATE'];?>"   onKeyUp="getFinalCalculation(<?php echo $i+1;?>);" autocomplete="off"/>
												<?php
											}

											?>
											</address>
										</div>
										<div class="col-sm-3 invoice-col dem_div">
										<span class="dem_rate_text">Demurrage</span>(<?php echo $currency;?>)
											<address>
											
											<input type="text" name="txtLPTTLDemurrage_<?php echo $i+1;?>"  data-dem="<?=$rows1['DETENTION']=='1'?$rows1['TTL_DEMURRAGE']:''?>" id="txtLPTTLDemurrage_<?php echo $i+1;?>" class="form-control txtLPTTLDemurrage" value="<?php echo $rows1['TTL_DEMURRAGE'];?>"  autocomplete="off"/>


											</address>
										</div>
										<div class="col-sm-3 invoice-col ">
										<span class="man_dem_rate_text">Manual Demurrage</span>(<?php echo $currency;?>)
											<address>
												<!-- dpknik -->
												<input type="text" name="TTL_DEMURRAGE_MANUAL_<?php echo $i+1;?>"   id="TTL_DEMURRAGE_MANUAL_<?php echo $i+1;?>" class="form-control TTL_DEMURRAGE_MANUAL" value="<?PHP echo $rows1['TTL_DEMURRAGE_MANUAL'];?>" onchange="MannualDemOrDes(this)"  autocomplete="off"/>
											</address>
										</div>
									</div>
									
									<div class="row invoice-info">
										<div class="col-sm-3 invoice-col">
											Time to despatch(<?php echo $title1;?>)
											<address>

											<input type="text" name="txtLPTimetodespatch_<?php echo $i+1;?>" id="txtLPTimetodespatch_<?php echo $i+1;?>" class="form-control" value="<?PHP echo $rows1['TIME_TO_DESPATCH'];?>"  />

											
											</address>
										</div>
										<div class="col-sm-3 invoice-col despatch_rate_div">
											Despatch Rate (<?php echo $currency;?>/Day)
											<address>


											<?php
											if($rec1 == 0){
												?>
													

													<input type="text" name="txtLPDespatchRate_<?php echo $i+1;?>" id="txtLPDespatchRate_<?php echo $i+1;?>" class="form-control despatch_rate" value="<?php echo $arr_explode[10];?>" onKeyUp="getFinalCalculation(<?php echo $i+1;?>);"  autocomplete="off"/>
												<?php
											}else{
												?>
													<input type="text" name="txtLPDespatchRate_<?php echo $i+1;?>" id="txtLPDespatchRate_<?php echo $i+1;?>" class="form-control despatch_rate"   value="<?php echo $rows1['DESPATCH_RATE'];?>" onKeyUp="getFinalCalculation(<?php echo $i+1;?>);"  autocomplete="off"/>
												<?php
											}

											?>
												
												
												<input type="hidden" name="txtSofLoadPortID_<?php echo $i+1;?>" id="txtSofLoadPortID_<?php echo $i+1;?>" class="form-control" data-sof="<?=$rows['SOFID']?>" value="<?php echo $rows['SOFID'];?>"   />
											</address>
										</div>
										<div class="col-sm-3 invoice-col despatch_div">
											Despatch(<?php echo $currency;?>)
											<address>
												<input type="text" name="txtLPTTLDespatch_<?php echo $i+1;?>" id="txtLPTTLDespatch_<?php echo $i+1;?>" class="form-control despatch" value="<?php echo $rows1['TTL_DESPATCH'];?>" style="color:red;"  autocomplete="off"/>
											</address>
										</div>
										<div class="col-sm-3 invoice-col man_despatch_div">
											Manual Despatch(<?php echo $currency;?>)
											<address>
												<input type="text" name="TTL_DESPATCH_MANUAL_<?php echo $i+1;?>" id="TTL_DESPATCH_MANUAL_<?php echo $i+1;?>" class="form-control TTL_DESPATCH_MANUAL" value="<?PHP echo $rows1['TTL_DESPATCH_MANUAL'];?>" style="color:red;" onchange="MannualDemOrDes(this)" autocomplete="off"/>
											</address>
										</div>
									</div>
									
									<div class="row invoice-info">
										<div class="col-sm-4 invoice-col">
											Total Days At Port
											<address>
											<input type="text" name="txtLPDaysAtPort_<?php echo $i+1;?>" id="txtLPDaysAtPort_<?php echo $i+1;?>" class="form-control" value="<?PHP echo $rows1['TOTAL_DAYS_AT_PORT'];?>" readonly />
											</address>
										</div>
										<div class="col-sm-4 invoice-col">
											Terms
											<address>
											<input type="text" name="txtLPTerms_<?php echo $i+1;?>" id="txtLPTerms_<?php echo $i+1;?>" class="form-control" value="<?PHP echo $rows1['LOADED_TERMS'];?>"/>
											</address>
										</div>
									</div>
									
									</div>
									
									<?php 
									$sql2 = "select * from laytime_slave where LAYTIME_ID='".$rows1['LAYTIME_ID']."'";
									$res2 = mysql_query($sql2) or die($sql2);
									$rec2 = mysql_num_rows($res2);
									?>
									<div class="box-body table-responsive">
									<div style="overflow:auto;">
									<table class="table table-bordered table-striped" id="laytimetable_<?php echo $i+1;?>">
									<thead>
										<tr>
										<th align="left" valign="middle" style="background-color:#3c8dbc;font-size:12px; color:#fff;" >Activity in Port</th>
										<th align="left" valign="middle" style="background-color:#3c8dbc;font-size:12px; color:#fff;" >Date / Time - Start</th>
										<th align="left" valign="middle" style="background-color:#3c8dbc;font-size:12px; color:#fff;" >Date / Time - Finish</th>
										<th align="left" valign="middle" style="background-color:#3c8dbc;font-size:12px; color:#fff;" >Duration (Hrs)</th> 
										<th align="left" valign="middle" style="background-color:#3c8dbc;font-size:12px; color:#fff;" >LT (C)</th>
										<th align="left" valign="middle" style="background-color:#3c8dbc;font-size:12px; color:#fff;" >LT (NC)</th>
										<th align="left" valign="middle" style="background-color:#3c8dbc;font-size:12px; color:#fff;" >LT (Partial %)</th>
										<th align="left" valign="middle" style="background-color:#3c8dbc;font-size:12px; color:#fff;" >Cummulative Time</th>
										<th align="left" valign="middle" style="background-color:#3c8dbc;font-size:12px; color:#fff;" >Notes</th>
										<th align="left" valign="middle" style="background-color:#3c8dbc;font-size:12px; color:#fff;" ></th>
										<th align="left" valign="middle" style="background-color:#3c8dbc;font-size:12px; color:#fff;" ></th>
										</tr>
									</thead>
									<tbody>
								
									<?php  $m=1;
									if($rec2>0)
									{
									while($rows2 = mysql_fetch_assoc($res2))
									{
										if(date("d-m-Y",strtotime($rows2['START_DATETIME'])) == '01-01-1970') {$s_date = "";} else {$s_date = date("d-m-Y H:i",strtotime($rows2['START_DATETIME']));}
								        if(date("d-m-Y",strtotime($rows2['FINISH_DATETIME'])) == '01-01-1970') {$f_date = "";} else {$f_date = date("d-m-Y H:i",strtotime($rows2['FINISH_DATETIME']));}
									?>
										<tr id="row_<?php echo $i+1;?>_<?php echo $m;?>">
											<td align="left" valign="middle"><input class="form-control" name="txtActivity_<?php echo $i+1;?>_<?php echo $m;?>" id="txtActivity_<?php echo $i+1;?>_<?php echo $m;?>" value="<?php echo $rows2['ACTIVITYID'];?>" style="width:150px;" /></td>
											<td align="left" valign="middle"><input type="text" class="form-control" name="txtLPDStart_<?php echo $i+1;?>_<?php echo $m;?>" id="txtLPDStart_<?php echo $i+1;?>_<?php echo $m;?>" value="<?php echo $s_date;?>" style="width:135px;" autocomplete="off"/></td>
											<td align="left" valign="middle" ><input type="text" class="form-control" name="txtLPDEnd_<?php echo $i+1;?>_<?php echo $m;?>" id="txtLPDEnd_<?php echo $i+1;?>_<?php echo $m;?>" value="<?php echo $f_date;?>" style="width:135px;" autocomplete="off"/></td>
											<td align="left" valign="middle" ><div style="width:50px;"><span id="txtLPDiff_<?php echo $i+1;?>_<?php echo $m;?>"><?php echo $rows2['DURATION'];?></span></div><input type="hidden" class="form-control" name="txtLPDiff1_<?php echo $i+1;?>_<?php echo $m;?>" id="txtLPDiff1_<?php echo $i+1;?>_<?php echo $m;?>" readonly value="<?php echo $rows2['DURATION'];?>" /></td>
											<?php if($rows2['LT_C'] == 0){?>
											<td align="left" valign="middle" ><input type="checkbox" name="checkLPLTCounts_<?php echo $i+1;?>_<?php echo $m;?>" id="checkLPLTCounts_<?php echo $i+1;?>_<?php echo $m;?>" class="regular-checkbox big-checkbox" value="1"  /><label id="labelLPLTCounts_<?php echo $i+1;?>_<?php echo $m;?>" for="checkLPLTCounts_<?php echo $i+1;?>_<?php echo $m;?>"></label></td>
											<?php }else{$duration = explode(".",$rows2['DURATION']);$lp_val = (int)(($duration[0]/**60*/)+$duration[1]);?>
											<td align="left" valign="middle"><input type="checkbox" checked="checked" name="checkLPLTCounts_<?php echo $i+1;?>_<?php echo $m;?>" id="checkLPLTCounts_<?php echo $i+1;?>_<?php echo $m;?>" class="regular-checkbox big-checkbox" value="1" /><label id="labelLPLTCounts_<?php echo $i+1;?>_<?php echo $m;?>" for="checkLPLTCounts_<?php echo $i+1;?>_<?php echo $m;?>"></label></td>
											<?php }?>
                                            <?php if($rows2['LT_C']==1){$readonly = '';}else{$readonly = 'readonly';}?>
											<?php if($rows2['LT_NC'] == 0){?>
											<td align="left" valign="middle" >
                                            
									<input type="checkbox" name="checkLPLTNoCounts_<?php echo $i+1;?>_<?php echo $m;?>" id="checkLPLTNoCounts_<?php echo $i+1;?>_<?php echo $m;?>" class="regular-checkbox big-checkbox"  value="1" /><label id="labelLPLTNoCounts_<?php echo $i+1;?>_<?php echo $m;?>" for="checkLPLTNoCounts_<?php echo $i+1;?>_<?php echo $m;?>"></label></td>
											<?php }else{$lp_val = 0;?>
											<td align="left" valign="middle">
									<input type="checkbox" checked="checked" name="checkLPLTNoCounts_<?php echo $i+1;?>_<?php echo $m;?>" id="checkLPLTNoCounts_<?php echo $i+1;?>_<?php echo $m;?>" class="regular-checkbox big-checkbox" value="1" /><label id="labelLPLTNoCounts_<?php echo $i+1;?>_<?php echo $m;?>" for="checkLPLTNoCounts_<?php echo $i+1;?>_<?php echo $m;?>"></label></td>
											<?php }?>
											<td align="left" valign="middle" >
									<input type="text" class="form-control" <?=$readonly;?> name="txtLPLTparcel_<?php echo $i+1;?>_<?php echo $m;?>" id="txtLPLTparcel_<?php echo $i+1;?>_<?php echo $m;?>" onKeyUp="getFinalCalculation(<?php echo $i+1;?>);" autocomplete="off" value="<?php echo $rows2['LT_PARTIAL']; ?>" style="width:100px;"/>
									<?php if($rows2['LT_C'] == 0 && $rows2['LT_NC'] == 0){$lp_val = 0;}?>
									<input type="hidden" class="form-control" name="txtLPVal_<?php echo $i+1;?>_<?php echo $m;?>" id="txtLPVal_<?php echo $i+1;?>_<?php echo $m;?>" size="4" autocomplete="off" value="<?php echo $lp_val;?>" />
											</td>
											<td align="left" valign="middle" ><div style="width:50px;"><span id="txtCummulative_<?php echo $i+1;?>_<?php echo $m;?>"><?php echo $rows2['CUMMULATIVE_TIME']; ?></span></div><input type="hidden" class="form-control" name="txtCummulative1_<?php echo $i+1;?>_<?php echo $m;?>" id="txtCummulative1_<?php echo $i+1;?>_<?php echo $m;?>" readonly value="<?php echo $rows2['CUMMULATIVE_TIME']; ?>" /></td>
											<td align="left" valign="middle" >
									<textarea class="form-control animated" name="txtLPNotes_<?php echo $i+1;?>_<?php echo $m;?>" id="txtLPNotes_<?php echo $i+1;?>_<?php echo $m;?>" style="width:150px;" ><?php echo $rows2['NOTES']; ?></textarea></td>
											<td align="left" valign="middle"><button type="button" id="txtAnch_<?php echo $i+1;?>_<?php echo $m;?>" onClick="addUI_Row(<?php echo $i+1;?>,<?php echo $m;?>);" class="btn btn-primary btn-flat">Add</button><input type="hidden" class="input" name="txtID_<?php echo $i+1;?>_<?php echo $m;?>" id="txtID_<?php echo $i+1;?>_<?php echo $m;?>" value="<?php echo $m; ?>"/></td>
											<td align="left" valign="middle"><a id="txtAnchDel_<?php echo $i+1;?>_<?php echo $m;?>" onClick="return Del_Row(<?php echo $i+1;?>,<?php echo $m;?>);"><i class="fa fa-times " style="color:red;"></i></a></td>
										</tr>
										
									<?php $m++;}}else{?>
									    <tr id="row_<?php echo $i+1;?>_<?php echo $m;?>">
											<td align="left" valign="middle"><input class="form-control" name="txtActivity_<?php echo $i+1;?>_<?php echo $m;?>" id="txtActivity_<?php echo $i+1;?>_<?php echo $m;?>" value="" style="width:150px;" /></td>
											<td align="left" valign="middle"><input type="text" class="form-control" name="txtLPDStart_<?php echo $i+1;?>_<?php echo $m;?>" id="txtLPDStart_<?php echo $i+1;?>_<?php echo $m;?>" value="" style="width:135px;" autocomplete="off"/></td>
											<td align="left" valign="middle" ><input type="text" class="form-control" name="txtLPDEnd_<?php echo $i+1;?>_<?php echo $m;?>" id="txtLPDEnd_<?php echo $i+1;?>_<?php echo $m;?>" value="" style="width:135px;" autocomplete="off"/></td>
											<td align="left" valign="middle" ><div style="width:50px;"><span id="txtLPDiff_<?php echo $i+1;?>_<?php echo $m;?>"></span></div><input type="hidden" class="form-control" name="txtLPDiff1_<?php echo $i+1;?>_<?php echo $m;?>" id="txtLPDiff1_<?php echo $i+1;?>_<?php echo $m;?>" readonly value="" /></td>
											<td align="left" valign="middle" ><input type="checkbox" name="checkLPLTCounts_<?php echo $i+1;?>_<?php echo $m;?>" id="checkLPLTCounts_<?php echo $i+1;?>_<?php echo $m;?>" class="regular-checkbox big-checkbox" value="1"  /><label id="labelLPLTCounts_<?php echo $i+1;?>_<?php echo $m;?>" for="checkLPLTCounts_<?php echo $i+1;?>_<?php echo $m;?>"></label></td>
                                            <td align="left" valign="middle" >
                                            <input type="checkbox" name="checkLPLTNoCounts_<?php echo $i+1;?>_<?php echo $m;?>" id="checkLPLTNoCounts_<?php echo $i+1;?>_<?php echo $m;?>" class="regular-checkbox big-checkbox"  value="1" /><label id="labelLPLTNoCounts_<?php echo $i+1;?>_<?php echo $m;?>" for="checkLPLTNoCounts_<?php echo $i+1;?>_<?php echo $m;?>"></label></td>
											<td align="left" valign="middle" >
									           <input type="text" class="form-control" name="txtLPLTparcel_<?php echo $i+1;?>_<?php echo $m;?>" id="txtLPLTparcel_<?php echo $i+1;?>_<?php echo $m;?>" onKeyUp="getFinalCalculation(<?php echo $i+1;?>);" autocomplete="off" value="" style="width:100px;"/>
									
									             <input type="hidden" class="form-control" name="txtLPVal_<?php echo $i+1;?>_<?php echo $m;?>" id="txtLPVal_<?php echo $i+1;?>_<?php echo $m;?>" size="4" autocomplete="off" value="" />
											</td>
											<td align="left" valign="middle" ><div style="width:50px;"><span id="txtCummulative_<?php echo $i+1;?>_<?php echo $m;?>"></span></div><input type="hidden" class="form-control" name="txtCummulative1_<?php echo $i+1;?>_<?php echo $m;?>" id="txtCummulative1_<?php echo $i+1;?>_<?php echo $m;?>" readonly value="" /></td>
											<td align="left" valign="middle" >
									          <textarea class="form-control animated" name="txtLPNotes_<?php echo $i+1;?>_<?php echo $m;?>" id="txtLPNotes_<?php echo $i+1;?>_<?php echo $m;?>" style="width:150px;" ></textarea></td>
											<td align="left" valign="middle"><button type="button" id="txtAnch_<?php echo $i+1;?>_<?php echo $m;?>" onClick="addUI_Row(<?php echo $i+1;?>,<?php echo $m;?>);" class="btn btn-primary btn-flat">Add</button><input type="hidden" class="input" name="txtID_<?php echo $i+1;?>_<?php echo $m;?>" id="txtID_<?php echo $i+1;?>_<?php echo $m;?>" value="<?php echo $m; ?>"/></td>
											<td align="left" valign="middle"><a id="txtAnchDel_<?php echo $i+1;?>_<?php echo $m;?>" onClick="return Del_Row(<?php echo $i+1;?>,<?php echo $m;?>);"><i class="fa fa-times " style="color:red;"></i></a></td>
										</tr>
									<?php $m++;}?>
									</tbody>
									</table>
									</div>
									</div>
									
									<div class="row invoice-info"><input type="hidden" class="form-control" name="txtTBID_<?php echo $i+1;?>" id="txtTBID_<?php echo $i+1;?>" value="<?php $m = $m - 1; echo $m; ?>" /><input id="txtCRM_<?php echo $i+1;?>" name="txtCRM_<?php echo $i+1;?>" value="<?php echo $m; ?>" type="hidden" /></div>
									<fieldset>
									<legend>Deductions</legend>
									</fieldset>
									
									<div class="box-body table-responsive">
										<div style="overflow:auto;">
										<table class="table table-bordered table-striped" id="laytimedeductiontable_<?php echo $i+1;?>">
										<thead>
											<tr>
											<th align="left" valign="middle" style="background-color:#3c8dbc;font-size:12px; color:#fff;" >Activity in Port</th>
											<th align="left" valign="middle" style="background-color:#3c8dbc;font-size:12px; color:#fff;" >Date / Time - Start</th>
											<th align="left" valign="middle" style="background-color:#3c8dbc;font-size:12px; color:#fff;" >Date / Time - Finish</th>
											<th align="left" valign="middle" style="background-color:#3c8dbc;font-size:12px; color:#fff;" >Duration (Hrs)</th> 
											<th align="left" valign="middle" style="background-color:#3c8dbc;font-size:12px; color:#fff;" >LT (Partial %)</th>
											<th align="left" valign="middle" style="background-color:#3c8dbc;font-size:12px; color:#fff;" >Duration (Hrs)</th> 
											<th align="left" valign="middle" style="background-color:#3c8dbc;font-size:12px; color:#fff;" width="20%">Notes</th>
											<th align="left" valign="middle" style="background-color:#3c8dbc;font-size:12px; color:#fff;" ></th>
											</tr>
										</thead>
										<tbody id="dudectiontbody_<?php echo $i+1;?>">
										<?php
										$sql3 = "select * from laytime_slave1 where LAYTIME_ID='".$rows1['LAYTIME_ID']."' ";
										$res3 = mysql_query($sql3);
										$rec3 = mysql_num_rows($res3);
										$m=0;
										if($rec3>0 && $rec1>0)
										{
											while($rows3 = mysql_fetch_assoc($res3))
											{$m++;
											if(date("d-m-Y",strtotime($rows3['START_DATETIME'])) == '01-01-1970') {$s_date = "";} else {$s_date = date("d-m-Y H:i",strtotime($rows3['START_DATETIME']));}
											if(date("d-m-Y",strtotime($rows3['FINISH_DATETIME'])) == '01-01-1970') {$f_date = "";} else {$f_date = date("d-m-Y H:i",strtotime($rows3['FINISH_DATETIME']));}
											?>
												<tr id="rowdeduction_<?php echo $i+1;?>_<?php echo $m;?>">
												<td align="left" valign="middle"><input class="form-control" name="txtDeductionActivity_<?php echo $i+1;?>_<?php echo $m;?>" id="txtDeductionActivity_<?php echo $i+1;?>_<?php echo $m;?>" value="<?php echo $rows3['ACTIVITYID'];?>" style="width:150px;" autocomplete="off"/></td>
												<td align="left" valign="middle"><input type="text" class="form-control" name="txtLPDDeductionStart_<?php echo $i+1;?>_<?php echo $m;?>" id="txtLPDDeductionStart_<?php echo $i+1;?>_<?php echo $m;?>" value="<?php echo $s_date;?>" style="width:135px;"  autocomplete="off" autocomplete="off"/></td>
												<td align="left" valign="middle" ><input type="text" class="form-control" name="txtLPDDeductionEnd_<?php echo $i+1;?>_<?php echo $m;?>" id="txtLPDDeductionEnd_<?php echo $i+1;?>_<?php echo $m;?>" value="<?php echo $f_date;?>" style="width:135px;"  autocomplete="off" autocomplete="off"/></td>
												<td align="left" valign="middle" ><input type="text" class="form-control" name="txtLPDeductionDiff_<?php echo $i+1;?>_<?php echo $m;?>" id="txtLPDeductionDiff_<?php echo $i+1;?>_<?php echo $m;?>" readonly value="<?php echo $rows3['DURATION'];?>" /></td>
												<td align="left" valign="middle" ><input type="text" class="form-control" name="txtLPLDeductionTparcent_<?php echo $i+1;?>_<?php echo $m;?>" id="txtLPLDeductionTparcent_<?php echo $i+1;?>_<?php echo $m;?>" onKeyUp="getFinalCalculation(<?php echo $i+1;?>);" autocomplete="off" value="<?php echo $rows3['LT_PARTIAL']; ?>" style="width:100px;"  autocomplete="off"/>
										        </td>
												<td align="left" valign="middle" ><input type="text" class="form-control" name="txtLPDeductionDiff1_<?php echo $i+1;?>_<?php echo $m;?>" id="txtLPDeductionDiff1_<?php echo $i+1;?>_<?php echo $m;?>" readonly value="<?php echo $rows3['CUMMULATIVE_TIME'];?>" /></td>
												<td align="left" valign="middle" ><textarea class="form-control animated" name="txtLPDeductionNotes_<?php echo $i+1;?>_<?php echo $m;?>" id="txtLPDeductionNotes_<?php echo $i+1;?>_<?php echo $m;?>" style="width:150px;" ><?php echo $rows3['NOTES']; ?></textarea></td>
												<td><a onClick="DelDeduction_Row(<?php echo $i+1;?>,<?php echo $m;?>);"><i class="fa fa-times" style="color:red;"></i></a></td>
											    </tr>
										<?php }}else{$m++;?>
										        <tr id="rowdeduction_<?php echo $i+1;?>_<?php echo $m;?>">
												<td align="left" valign="middle"><input class="form-control" name="txtDeductionActivity_<?php echo $i+1;?>_<?php echo $m;?>" id="txtDeductionActivity_<?php echo $i+1;?>_<?php echo $m;?>" value="" style="width:150px;"  autocomplete="off"/></td>
												<td align="left" valign="middle"><input type="text" class="form-control" name="txtLPDDeductionStart_<?php echo $i+1;?>_<?php echo $m;?>" id="txtLPDDeductionStart_<?php echo $i+1;?>_<?php echo $m;?>" value="" style="width:135px;"  autocomplete="off" autocomplete="off"/></td>
												<td align="left" valign="middle" ><input type="text" class="form-control" name="txtLPDDeductionEnd_<?php echo $i+1;?>_<?php echo $m;?>" id="txtLPDDeductionEnd_<?php echo $i+1;?>_<?php echo $m;?>" value="" style="width:135px;"  autocomplete="off" autocomplete="off"/></td>
												<td align="left" valign="middle" ><input type="text" class="form-control" name="txtLPDeductionDiff_<?php echo $i+1;?>_<?php echo $m;?>" id="txtLPDeductionDiff_<?php echo $i+1;?>_<?php echo $m;?>" readonly value="" /></td>
												<td align="left" valign="middle" ><input type="text" class="form-control" name="txtLPLDeductionTparcent_<?php echo $i+1;?>_<?php echo $m;?>" id="txtLPLDeductionTparcent_<?php echo $i+1;?>_<?php echo $m;?>" onKeyUp="getFinalCalculation(<?php echo $i+1;?>);" autocomplete="off" value="" style="width:100px;"  autocomplete="off"/>
										        </td>
												<td align="left" valign="middle" ><input type="text" class="form-control" name="txtLPDeductionDiff1_<?php echo $i+1;?>_<?php echo $m;?>" id="txtLPDeductionDiff1_<?php echo $i+1;?>_<?php echo $m;?>" readonly value="" /></td>
												<td align="left" valign="middle" ><textarea class="form-control animated" name="txtLPDeductionNotes_<?php echo $i+1;?>_<?php echo $m;?>" id="txtLPDeductionNotes_<?php echo $i+1;?>_<?php echo $m;?>" style="width:150px;" ></textarea></td>
												<td><a onClick="DelDeduction_Row(<?php echo $i+1;?>,<?php echo $m;?>);"><i class="fa fa-times" style="color:red;"></i></a></td>
												</tr>
										<?php }?>
										</tbody>
										<tfoot>
										    <tr>
											   <td colspan="3"><button type="button" onClick="addUIDeduction_Row(<?php echo $i+1;?>);" class="btn btn-primary btn-flat">Add</button><input type="hidden" name="txtTBODYID_<?php echo $i+1;?>" id="txtTBODYID_<?php echo $i+1;?>" value="<?php echo $m;?>"/></td>
											   <td><input type="text" class="form-control" readonly="true" name="txtLPTotalDeduction_<?php echo $i+1;?>" id="txtLPTotalDeduction_<?php echo $i+1;?>" autocomplete="off" value=""/></td>
											   <td></td>
											   <td><input type="text" class="form-control" readonly="true" name="txtLPTotalDeduction1_<?php echo $i+1;?>" id="txtLPTotalDeduction1_<?php echo $i+1;?>" autocomplete="off" value=""/></td>
											   <td colspan="2"></td>
											</tr>
										</tfoot>
										</table>
										</div>
									</div>
									
									
									
									
									<div class="row invoice-info">
										<div class="col-sm-6 invoice-col">
											Remarks
											<address>
											<textarea class="form-control" name="txtRemarks_<?php echo $i+1;?>" id="txtRemarks_<?php echo $i+1;?>"  rows="3"><?PHP echo $rows1['REMARKS'];?></textarea>
											</address>
										</div>
										<div class="col-sm-6 invoice-col">
										   Attachments
											<address>
												<div class="btn btn-success btn-file btn-flat" data-toggle="tooltip">
													<i class="fa fa-paperclip"></i> Attachment
													<input type="file" class="form-control" multiple name="attach_file_<?php echo $i+1;?>[]" id="attach_file_<?php echo $i+1;?>" title="" data-widget="Attachment" data-toggle="tooltip" data-original-title="Attachment"/>
												</div>
												<br/>
												<table width="100%">
												<?php if($rows1['ATTACHMENTS'] != '')
												{ 
													$file = explode(",",$rows1['ATTACHMENTS']); 
													$name = explode(",",$rows1['ATTACHMENTS_NAME']); ?>										
												<tr>
													<td colspan="2">
												  Previous Attachments
													</td>
												</tr>
								   
													<?php
													for($j=0;$j<sizeof($file);$j++)
													{
													?>
													<tr id="row_file1_<?php echo $i+1;?>_<?php echo ($j+1);?>">
														<td width="40%" align="left" class="input-text"  valign="top"><a href="../../attachment/<?php echo $file[$j]; ?>" target="_blank" style="color:blue;" data-toggle="tooltip" data-original-title="<?php echo $name[$i];?>"><i class="fa fa-external-link"></i>&nbsp;&nbsp;<?php echo $name[$j];?></a>
														<input type="hidden" name="file_<?php echo $i+1;?>_<?php echo $j+1;?>" id="file_<?php echo $i+1;?>_<?php echo $j+1;?>" value="<?php echo $file[$j]; ?>" />
														<input type="hidden" name="name_<?php echo $i+1;?>_<?php echo $j+1;?>" id="name_<?php echo $i+1;?>_<?php echo $j+1;?>" value="<?php echo $name[$j]; ?>" />
														</td>
														<td ><a href="#1" onClick="Del_Upload(<?php echo $i+1;?>,<?php echo $j+1;?>);"><i class="fa fa-times " style="color:red;"></i></a></td>
													</tr>
													<?php }?>
												<?php }?>
											   </table>
											</address>
										</div>
									</div>
							  <?php $sql1 = "select * from laytime_master where COMID='".$comid."' and LOGIN='INTERNAL_USER' and MODULEID='".$_SESSION['moduleid']."' and MCOMPANYID='".$_SESSION['company']."' and PORT='".$arr_explode[0]."' and PORTID='".$arr_explode[1]."' and SOF_LOADPORTID='".$rows['SOFID']."' and RANDOMID='".$arr_explode[2]."'";
									$res1 = mysql_query($sql1);
									$rec1 = mysql_num_rows($res1);
									$rows1 = mysql_fetch_assoc($res1);?>
									
									<div class="row invoice-info">
									   <div class="col-sm-4 invoice-col">
										   Level 1 Approver
									   </div>
									   <div class="col-sm-8 invoice-col">
									   <?php
									  $fieldname = 'LAYTIME_CHK_APP_1';
									   ?>
										
										<select data-placeholder="Choose Approver..." class="input-text chzn-select" style="width:300px;" multiple name="selApprovers_<?php echo $i+1;?>[]" id="selApprovers_<?php echo $i+1;?>"><?php $obj->getApproverListBasedOnApprovalMatrix($fieldname, $rows1['APPROVERS']);?></select>
									   </div>
								   </div>
								   <div class="row invoice-info">
									   <div class="col-sm-12 invoice-col">&nbsp;</div>
								   </div>
									
									<div class="box-footer" align="right">
									<?php 
									$status = '';
									if($rows1['SUBMITID'] != 5 )
									{
										if(($rec1==0 && $creator==1) || (($rows1['SUBMITID']==0 || $rows1['SUBMITID']==2) && $creator==1)){
										   if(empty($approverarr1) && empty($approverarr2)){$status = 5;}
										   else if(empty($approverarr1) && !empty($approverarr2)){$status = 4;}
										   else{$status = 1;} ?>
										<button type="button" class="btn btn-primary btn-flat" onClick="getSubmit(<?php echo $i+1;?>,0,'<?php echo $arr_explode[0];?>',<?php echo $arr_explode[1];?>,<?php echo $arr_explode[2];?>);">Submit to edit</button>&nbsp;&nbsp;
										
										<?php if($doclosed == 1 && $status==5)
										{?>
										    <button type="button" class="btn btn-warning btn-flat" onClick="getSubmit(<?php echo $i+1;?>,<?=$status;?>,'<?php echo $arr_explode[0];?>',<?php echo $arr_explode[1];?>,<?php echo $arr_explode[2];?>);">Send for Approval</button>
								  <?php }else if($status<5){?>
										    <button type="button" class="btn btn-warning btn-flat" onClick="getSubmit(<?php echo $i+1;?>,<?=$status;?>,'<?php echo $arr_explode[0];?>',<?php echo $arr_explode[1];?>,<?php echo $arr_explode[2];?>);">Send for Approval</button>
								  <?php }?>
								  
								  <?php }else if($rec1>0 && ($rows1['SUBMITID']==1 || $rows1['SUBMITID']==4) && $approver1 == 1){
											 if(empty($approverarr2)){$status = 5;}
											 else{$status = 3;}
									   ?>
										<button type="button" class="btn btn-primary btn-flat" onClick="getSubmit(<?php echo $i+1;?>,2,'<?php echo $arr_explode[0];?>',<?php echo $arr_explode[1];?>,<?php echo $arr_explode[2];?>);">Send for Review</button>&nbsp;&nbsp;
										
										<?php if($doclosed == 1 && $status==5)
										{?>
										     <button type="button" class="btn btn-warning btn-flat" onClick="getSubmit(<?php echo $i+1;?>,<?=$status;?>,'<?php echo $arr_explode[0];?>',<?php echo $arr_explode[1];?>,<?php echo $arr_explode[2];?>);">Submit & Approve</button>
								  <?php }else if($status<5){?>
										    <button type="button" class="btn btn-warning btn-flat" onClick="getSubmit(<?php echo $i+1;?>,<?=$status;?>,'<?php echo $arr_explode[0];?>',<?php echo $arr_explode[1];?>,<?php echo $arr_explode[2];?>);">Submit & Approve</button>
								  <?php }?>
								  
								  <?php }else if($rec1>0 && $rows1['SUBMITID']==3 && $approver2 == 1){
										   if(empty($approverarr1)){$status = 2;}
										   else{$status = 4;}
								  ?>
										<button type="button" class="btn btn-primary btn-flat" onClick="getSubmit(<?php echo $i+1;?>,<?=$status;?>,'<?php echo $arr_explode[0];?>',<?php echo $arr_explode[1];?>,<?php echo $arr_explode[2];?>);">Send for Review</button>&nbsp;&nbsp;
										<?php if($doclosed == 1){?><button type="button" class="btn btn-warning btn-flat" onClick="getSubmit(<?php echo $i+1;?>,5,'<?php echo $arr_explode[0];?>',<?php echo $arr_explode[1];?>,<?php echo $arr_explode[2];?>);">Submit & Approve</button><?php }?>
								  <?php }?>
                               <?php }?>
							         <input type="hidden" name="action" id="action" value="submit" />
								</div>	
							 
									
									</form>
									</div>
									<?php 
									$LPReverssible = ($rows1['REVERSIBLE']==1)?1:0;
									if($rows1['REVERSIBLE']==1 && $rows1['SUBMITID'] == 5)
									{
									   $doclosed = 1;
									}
									if(($rows1['REVERSIBLE']==0 || $rows1['REVERSIBLE']!=1) && $rows1['SUBMITID'] == 5)
									{
									   $doclosed = 1;
									}
									
									if($rows1['REVERSIBLE']==1 && $rows1['SUBMITID'] < 5)
									{
									   $doclosed = 0;	
									}
									
									
									$i++;}} ?>
									
									<!-- /.tab_1-pane -->
									
									</div><!-- /.tab-content -->
								</div><!-- nav-tabs-custom -->
							</div>
						</div>
					<!--   content ends here..................-->
                </section><!-- /.content -->
            </aside><!-- /.right-side -->
        </div><!-- ./wrapper -->
<?php $display->footer(); ?>
    </body>
</html>

<script>
// $('#element').parents().eq(2);  // "Great-grandfather".


	// $('.port_name_manual').text($('.port_name_manual').parents().eq(11).find('.nav-tabs li.active a').text());

// console.log($('.port_name_manual').parents().eq(11).find('.nav-tabs li.active'));

$('.port_name_manuall').text($('.nav-tabs li.active a').text());
// console.log($('.port_name_manual').parents().eq(11).find('.nav-tabs li.active a').text());
	// console.log($('.port_name_manual').parents().eq(11).find('.nav-tabs li.active a').text());

	$('.invoice-info .nav-tabs li').on('click', function(){

	 	 let prev_text=	Number($(this).data('num'))-1;
		 let seltype= Number($(this).data('seltype'));
		 if(seltype==2 && prev_text>0){			
				if($('#checkLPReverssible_'+prev_text).is(':checked')){

					// let hrs=(Number($('#txtLPTimetodemurrage_'+prev_text).val())>0)?-Number($('#txtLPTimetodemurrage_'+prev_text).val()):Number($('#txtLPTimetodespatch_'+prev_text).val());
					let new_laytime_val=Number($('#txtLPLaytimeAllowed_'+prev_text).val());
					
					
					
					// (Number($('#txtLPLaytimeAllowed_'+prev_text).val())+hrs).toFixed(2);
					$('#txtLPLaytimeAllowed_'+(prev_text+1)).val(new_laytime_val).keyup();	
					
					
				}
		 }		
		
		$('.port_name_manuall').text($(this).find('a').text());
	});


	function MannualDemOrDes(elx)
				{
					// let form= $(elx).parents().eq(3);
					// console.log(form);
					let current_div=$(elx).parents().eq(1);

					let actual_des_dem_amount=$(current_div).prev().find('input').val();
					console.log(actual_des_dem_amount);
					if(Number(actual_des_dem_amount) == 0){
						jAlert('Dem/Des should be greater than zero', 'Alert');

						$(elx).val('');
						return ;
					}

					let dem_des_diff=Math.abs(Number($(elx).val())-Number(actual_des_dem_amount));

					if(dem_des_diff>1000){
						jAlert('Dem/Des difference should not exceed 1000 USD', 'Alert');

						$(elx).val('');
						return ;
					}

					

					// console.log(current_div);


					
					// if(Number($(current_div).find('.form-control txtLPTTLDemurrage').val())==0){
					// 	jAlert('Amount Dem/Des amount should be greater than zero', 'Alert');
					// }
					
				}
</script>

<script>
let nav_id = $('.nav-tabs').find('li.active').attr('data-num');

let submit_id=$('#tabs_'+nav_id).find('.submit_id').val();

// alert(laytime_id);




if(submit_id == 5){
	$('.open_btn').show();
}else{
	$('.open_btn').hide();
}

$('.nav-tabs li').click(function(){
	
	let nav_id_t=$(this).attr('data-num');

	let submit_id_t=$('#tabs_'+nav_id_t).find('.submit_id').val();

	 if(submit_id_t == 5){
		$('.open_btn').show();
	}else{
		$('.open_btn').hide();
	}

})
$('a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
			

			// let active_num=$(e.target).parent().data('num');


			
			let prev_num=active_num-1;



			if(active_num>1){
					if($('#checkLPReverssible_'+prev_num).is(':checked')){							
							

								let prev_count_table=parseInt($('#laytimetable_'+prev_num).find('.sr_no').last().text())+1;
								$('#laytimetable_'+active_num).attr('data-total',prev_count_table);										   
								   $.each($('#laytimetable_'+active_num).find('.sr_no'),(k,v)=>{											
									$(v).text(k+prev_count_table);
							});
							
							// }
							// else{

							// $.each($('#laytimetable_'+active_num).find('.sr_no'),(k,v)=>{											
							// 		$(v).text(k+data_total+1);
							// });
				
											
					}else{

						// $('#laytimetable_'+prev_num).attr('data-total',0);

						$.each($('#laytimetable_'+active_num).find('.sr_no'),(k,v)=>{
									$(v).text(k+1);
							})

					}
			}
			let active_num = $('#tabs').find('ul li.active').data('num');



		if($('#tabs_'+active_num).find('.detention').is(':checked')){
		   let frm =$('#frm'+active_num);


		//    $(frm).find('.demurrage_rate').prop('readonly',false);
				   $(frm).find('.dem_rate_text').text('Detention');
				   $(frm).find('.man_dem_rate_text').text('Manual Detention');
				$(frm).find('.despatch_rate').prop('disabled',true);
				$(frm).find('.despatch').prop('disabled',true);
				$(frm).find('.despatch_rate_div').fadeOut();
				$(frm).find('.despatch_div').fadeOut();
		}


		

		});
		// if($('.detention').is(':checked')){
		// 		let frm =$('.detention').parents().eq(4);
		// 		$(frm).find('.dem_rate_text').text('Detention');
		// 		$(frm).find('.despatch_rate').prop('disabled',true);
		// 		$(frm).find('.despatch').prop('disabled',true);
		// 		$(frm).find('.despatch_rate_div').fadeOut();
		// 		$(frm).find('.despatch_div').fadeOut();	
		// }


		// tabs_1

		let tab_num = $('#tabs').find('ul li.active').data('num');
		let frm =$('#frm'+tab_num);
			
		if($('#tabs_'+tab_num).find('.detention').is(':checked')){



				let actual_laytime=Number($(frm).find('.txtLPActualLaytime').val());
				let demurrage_rate=Number($(frm).find('.demurrage_rate').val());

				// $(frm).find('.demurrage_rate').prop('readonly',false);
				$(frm).find('.checkLPReverssible').attr('disabled',true);
				$(frm).find('.txtLPTTLDemurrage').val((actual_laytime*demurrage_rate).toFixed(2));
				   $(frm).find('.dem_rate_text').text('Detention');
				   $(frm).find('.man_dem_rate_text').text('Manual Detention');
				$(frm).find('.despatch_rate').prop('disabled',true);
				$(frm).find('.despatch').prop('disabled',true);
				$(frm).find('.despatch_rate_div').fadeOut();
				$(frm).find('.despatch_div').fadeOut();
				$(frm).find('.dynamic_detention').val(1);						
				
			}
		// 	else{
		// 	$(frm).find('.dynamic_detention').val(0);						

		// }
	
		
		

		$('.detention').on('ifChanged', function(e) {



			let current_elm = e.target;	
			
		
			let frm = $(current_elm).parents().eq(4);
			if($(current_elm).is(':checked')){


				


				let actual_laytime=Number($(frm).find('.txtLPActualLaytime').val());
				let demurrage_rate=Number($(frm).find('.demurrage_rate').val());
				$(frm).find('.checkLPReverssible').attr('disabled',true);

				$(frm).find('.txtLPTTLDemurrage').val((actual_laytime*demurrage_rate).toFixed(2));

				// $(frm).find('.demurrage_rate').prop('readonly',false);
				$(frm).find('.dem_rate_text').text('Detention');
				$(frm).find('.man_dem_rate_text').text('Manual Detention');
				$(frm).find('.despatch_rate').prop('disabled',true);
				$(frm).find('.despatch').prop('disabled',true);
				$(frm).find('.despatch_rate_div').fadeOut();
				$(frm).find('.despatch_div').fadeOut();	
				$(frm).find('.dynamic_detention').val(1);						
				$(current_elm).val(1);
			}
			else{
				// $(frm).find('.demurrage_rate').prop('readonly',true);
				$(frm).find('.checkLPReverssible').attr('disabled',false);

				let days= Number($(frm).find('.txtLPActualLaytime').val()) - Number($(frm).find('.txtLPLaytimeAllowed').val()); 
				let demurrage_rate=Number($(frm).find('.demurrage_rate').val());

				if(days>0){

					$(frm).find('.txtLPTTLDemurrage').val((days*demurrage_rate).toFixed(2));
				}else{
					$(frm).find('.txtLPTTLDemurrage').val((0).toFixed(2));
				}

				

				$(frm).find('.dem_rate_text').text('Demurrage');
				$(frm).find('.despatch_rate').prop('disabled',false);
				$(frm).find('.despatch').prop('disabled',false);
				$(frm).find('.despatch_rate_div').fadeIn();
				$(frm).find('.despatch_div').fadeIn();
				$(frm).find('.dynamic_detention').val(0);						
				$(current_elm).val(0);
				
			} 	
	  });

	</script>