<?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'];
$page  = $_REQUEST['page'];

if($page == 1){$page_link = "payment_grid.php"; $page_bar="In Ops at a glance";$nav=5;$subtitle = 'VC';}else if($page == 2){$page_link = "payment_grid.php"; $page_bar="Vessels in Post Ops";$nav=5;$subtitle = 'VC';}else if($page == 3){$page_link = "payment_grid.php"; $page_bar="Vessels in History";$nav=5;$subtitle = 'VC';}else if($page == 4){$page_link = "payment_gridcoa.php"; $page_bar="In Ops at a glance - COA";$nav=16;$subtitle = 'COA';}else if($page == 5){$page_link = "payment_gridcoa.php"; $page_bar="In Post Ops at a glance - COA";$nav=16;$subtitle = 'COA';}else if($page == 6){$page_link = "payment_gridcoa.php"; $page_bar="Vessels in History - COA";$nav=16;$subtitle = 'COA';}else{$page_link = "payment_grid.php"; $page_bar="Historical Data - VC";$nav=23;$subtitle = 'VC';}

if(@$_REQUEST['action'] == 'submit')
{
	$msg = $obj->insertInvoiceHireDetails();
	$msg = explode(",",$msg);
	header('Location:./invoice_hire.php?msg='.$msg[0].'&comid='.$comid.'&page='.$page);
}
if(@$_REQUEST['action2'] == 'submit1')
{
	$msg = $obj->insertHirePaymentReceivedDetails();
	$msg = explode("_",$msg);
	header('Location:./invoice_hire.php?msg='.$msg[0].'&comid='.$comid.'&page='.$page);
}
if(@$_REQUEST['action11'] == 'submit2')
{
	$msg = $obj->deleteHireInvoiceRecords();
	$msg = explode(",",$msg);
	header('Location:./invoice_hire.php?msg='.$msg[0].'&comid='.$comid.'&page='.$page);
}

if (isset($_POST['invoice_id'])) {


	mysql_query("update alert_master set SHOW_STATUS=0 where IDENTIFYID='".$_POST['invoice_id']."'");

	$sql_ufim = mysql_query("update invoice_hire_master set STATUS=0,SYNC_STATUS=0 where INVOICEID='".$_POST['invoice_id']."'");

	echo true;
	
}


$creatorsarr = $obj->getUsersWithAuthority('HIRE_STSTMENT_CHK_CRETR');
$approverarr1 = $obj->getUsersWithAuthority('HIRE_STSTMENT_CHK_APP_1');
$approverarr2 = $obj->getUsersWithAuthority('HIRE_STSTMENT_CHK_APP_2');

$creator = $obj->getUserAuthority($_SESSION['uid'], 'HIRE_STSTMENT_CHK_CRETR');
$approver1 = $obj->getUserAuthority($_SESSION['uid'], 'HIRE_STSTMENT_CHK_APP_1');
$approver2 = $obj->getUserAuthority($_SESSION['uid'], 'HIRE_STSTMENT_CHK_APP_2');

$id = $obj->getLatestCostSheetID($comid);

// echo '<h1>'.$id;
$obj->viewFreightCostEstimationTempleteRecordsNew($id);
$arr  = $obj->getLoadPortAndDischargePortArrBasedOnCommidAndProcessWithoutTBN($comid,$id);
$vendorid = $obj->getFun140();


$arrayrandomidtc = $arrayrandomidvc = array();
if($obj->getFun241()==NULL || $obj->getFun241()=='' || $obj->getFun241()==0)
{
    $arrayrandomidvc[] = $comid;
	$arrayfcaid[] = $obj->getCompareEstimateData($comid,"FCAID");
}else
{
    $arrayrandomidvc = $arrayfcaid = array();
    $sql_fcem = "select COMID from freight_cost_estimete_master where PERIODID='".$obj->getFun241()."' and COMID is not NULL GROUP BY COMID";
	$result_fcem = mysql_query($sql_fcem) or die($sql_fcem);
	while($rows_fcem = mysql_fetch_assoc($result_fcem))
	{
	    $arrayrandomidvc[] = $rows_fcem['COMID'];
		$arrayfcaid[] = $obj->getCompareEstimateData($rows_fcem['COMID'],"FCAID");
	}
	
	$arrayrandomidtc = $arraytcoutid = array();
    $sql_cetm = "select COMID from chartering_estimate_tc_master where PERIODID='".$obj->getFun241()."' and COMID is not NULL GROUP BY COMID";
	$result__cetm = mysql_query($sql_cetm) or die($sql_cetm);
	while($rows_cetm = mysql_fetch_assoc($result__cetm))
	{
	    $arrayrandomidtc[] = $rows_cetm['COMID'];
		$arraytcoutid[] = $obj->getCharteringEstimateTCData($rows_cetm['COMID'],"TCOUTID");
	}
	
}

$lp_name = array(); 
$dp_name = array();

for($j=0;$j<count($arr);$j++)
{   $arr_explode = explode('@@',$arr[$j]);
    
    if($arr_explode[0] == "LP" && $arr_explode[8]==''){$lp_name[]= $obj->getPortNameBasedOnID($arr_explode[1]);}
	if($arr_explode[0] == "DP" && $arr_explode[8]==''){$dp_name[]= $obj->getPortNameBasedOnID($arr_explode[1]);}
}

$lp_name  = implode(', ',$lp_name);
$dp_name  = implode(', ',$dp_name);

if($obj->getFun175()!='')
{
	$sqlcoa = "select * from coa_master where COAID='".$obj->getFun175()."'";
	$resultcoa = mysql_query($sqlcoa) or die($sqlcoa);
	$rowscoa   = mysql_fetch_assoc($resultcoa);
	$currency = $rowscoa['CURRENCY'];
}else
{
	$currency = 'USD';
}

$bunkergrade = array( 1 =>1 , 2 =>2, 3 =>3 , 4 =>4);
$bunkergrade1= array( 1 =>'HSFO' , 2 =>'LSFO', 3 =>'HSDO' , 4 =>'LSDO');
$pagename = basename($_SERVER['PHP_SELF'])."?comid=".$_REQUEST['comid'].'&page='.$_REQUEST['page'];
?>
<!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/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>
<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>

<script type="text/javascript">
$(document).ready(function(){ 
    $(".sidebar-toggle").click();
	$(".autosize").autosize({append: "\n"});
	$("#selApprovers").chosen();
	$("#frm1").validate({
		rules: {
		selFromOwner: {required: true},
		selIType: {required: true},
		txtInvNo: {required: true},
		txtInvDate: {required: true},
		txtExchangeRate:{required: true},
		selExchangeCurrency:{required: true},
		txtPaymentTerms:{required: true},
		selBankingDetails:{required: true},
		txtHireFrom:{required: true},
		txtHireTo:{required: true},
		txtAttenName:{required: true},
		txtExchangeDate:{required: true}
		},
	messages: {
		selIType: {required: "*"},
		txtInvNo: {required: true},
		txtInvDate: {required: true},
		txtExchangeRate:{required: "*"},
		selExchangeCurrency:{required: "*"},
		txtPaymentTerms:{required: "*"},
		selBankingDetails:{required: "*"},
		txtHireFrom:{required: "*"},
		txtHireTo:{required: "*"},
		txtAttenName:{required: "*"},
		txtExchangeDate:{required: "*"}
		},
	submitHandler: function(form)  {



		if($('#txtCORCIDFORLESSADJ_1').val() != "" && 	($('#txtLessADJAmt_1').val() != "" || $('#txtLessADJAmt_1').val() >0.00)  ||  $('#txtFixNoForLESSADJ_1').val()!=""){

		if($('#txtCORCIDFORLESSADJ_1').val() == "" || $('#txtFixNoForLESSADJ_1').val() == "" || $('#txtVesselFORLESSADJ_1').val() == "" || $('#txtLessADJAmt_1').val() == ""){
			jAlert('Please select all the fields in Adjustment');
			return false;
		}else{

			jConfirm('Are you sure you want to save this data ?', 'Confirmation', function(r) {
			if(r){
				jAlert('<b style="font-size:25px;">Please wait . . .</b><br><br><img src="../../img/loading.gif"  />', 'Alert');
				$("#popup_container").css({"background": "rgba(255,255,255,0.1)","border": "10px solid rgba(255,255,255,0.1)","width": "100%"});
				$("#popup_content").css({"background":"none","text-align":"center"});
				$("#popup_ok,#popup_title").hide();  
				form.submit();
			}
			else{return false;}
			});

		}
		}


		if($('#txtCORCIDFORADDADJ_1').val() != "" && 	($('#txtAddADJAmt_1').val() != "" || $('#txtAddADJAmt_1').val() > 0.00) || $('#txtFixNoForADDADJ_1').val()!="" ||  $('#txtFixNoForADDADJ_1').val()!=""){


		 if($('#txtCORCIDFORADDADJ_1').val() == "" || $('#txtFixNoForADDADJ_1').val() == "" || $('#txtVesselFORADDADJ_1').val() == "" || $('#txtAddADJAmt_1').val() == ""){
			jAlert('Please select all the fields in Adjustment');
			return false;
		}else{

			jConfirm('Are you sure you want to save this data ?', 'Confirmation', function(r) {
			if(r){
				jAlert('<b style="font-size:25px;">Please wait . . .</b><br><br><img src="../../img/loading.gif"  />', 'Alert');
				$("#popup_container").css({"background": "rgba(255,255,255,0.1)","border": "10px solid rgba(255,255,255,0.1)","width": "100%"});
				$("#popup_content").css({"background":"none","text-align":"center"});
				$("#popup_ok,#popup_title").hide();  
				form.submit();
			}
			else{return false;}
			});

		}





		}

		if($('#txtAddDes_1').val() != "" && 	($('#txtAddDesAmt_1').val() != "" || $('#txtAddDesAmt_1').val() >0.00)  || 	$('#txtSubDes_1').val() != "" && 	($('#txtSubDesAmt_1').val() != "" || $('#txtSubDesAmt_1').val() > 0.00)){
			
			// console.log('dpk1');
	

			// console.log('dpk1213');
		if($('#txtCORCIDFOROTHERADD_1').val() == "" && $('#txtAddDesAmt_1').val() >0.00){
			console.log('dpk');
		// console.log($('#txtCORCIDFOROTHERADD_1').val());

		jAlert('<b style="font-size:20px;">Please Select Cost Type</b>','Alert');

		return false;
		}

		else if($('#txtCORCIDFOROTHERLESS_1').val() == "" && $('#txtSubDesAmt_1').val() >0.00){

		// console.log($('#txtCORCIDFOROTHERLESS_1').val());

		jAlert('<b style="font-size:20px;">Please Select Cost Type</b>','Alert');

		return false;
		}else{
			jConfirm('Are you sure you want to save this data ?', 'Confirmation', function(r) {
			if(r){
				jAlert('<b style="font-size:25px;">Please wait . . .</b><br><br><img src="../../img/loading.gif"  />', 'Alert');
				$("#popup_container").css({"background": "rgba(255,255,255,0.1)","border": "10px solid rgba(255,255,255,0.1)","width": "100%"});
				$("#popup_content").css({"background":"none","text-align":"center"});
				$("#popup_ok,#popup_title").hide();  
				form.submit();
			}
			else{return false;}
			});

		}



	
		


		}else{



		    jConfirm('Are you sure you want to save this data ?', 'Confirmation', function(r) {
			if(r){
				jAlert('<b style="font-size:25px;">Please wait . . .</b><br><br><img src="../../img/loading.gif"  />', 'Alert');
				$("#popup_container").css({"background": "rgba(255,255,255,0.1)","border": "10px solid rgba(255,255,255,0.1)","width": "100%"});
				$("#popup_content").css({"background":"none","text-align":"center"});
				$("#popup_ok,#popup_title").hide();  
				form.submit();
			}
			else{return false;}
			});

		}
		}
	});

	$(".numeric").numeric();
	$('.datepicker').datepicker({
		format: 'dd-mm-yyyy',
		autoclose:true
	});
	
	$('#txtHireFrom,#txtHireTo, [id^=txtOffHireFrom_],[id^=txtOffHireTo_],[id^=txtHireFrom_],[id^=txtHireTo_]').datetimepicker({
		
		format: 'dd-mm-yyyy hh:ii',
		autoclose: true,
		todayBtn: true,
		minuteStep: 1
		}).on('changeDate', function(){
		getFullClaculation();
	});
	$('[id^=txtHireTo_]').rules("add", "required");
	$('#ChkBallastBonus').on('ifChecked', function () { 
	   $("#spanBallastBonus").show();
	   getFullClaculation();
	});
	 
	$('#ChkBallastBonus').on('ifUnchecked', function () { 
	   $("#spanBallastBonus").hide();
	   getFullClaculation();
	});
	
	$('#ChkShowOffHire').on('ifChecked', function () { 
	   $("#offhiretable").show();
	   getFullClaculation();
	});
	 
	$('#ChkShowOffHire').on('ifUnchecked', function () { 
	   $("#offhiretable").hide();
	   getFullClaculation();
	});
	
	$("#ChkOverConspBunker").on('ifChecked', function () { 
	   $("[id^=DivBunkerOverConsp_]").show();
	   getFullClaculation();
	});
	
	$("#ChkOverConspBunker").on('ifUnchecked', function () { 
	   $("[id^=DivBunkerOverConsp_]").hide();
	   getFullClaculation();
	});
	
	
	$("#ChkDeliveryBunker").on('ifChecked', function () { 
	   $("[id^=DivBunkerDelivery_]").show();
	   getFullClaculation();
	});
	
	$("#ChkDeliveryBunker").on('ifUnchecked', function () { 
	   $("[id^=DivBunkerDelivery_]").hide();
	   getFullClaculation();
	});
	
	$("#ChkReDeliveryBunker").on('ifChecked', function () { 
	   $("[id^=DivBunkerReDelivery_]").show();
	   getFullClaculation();
	});
	
	$("#ChkReDeliveryBunker").on('ifUnchecked', function () { 
	   $("[id^=DivBunkerReDelivery_]").hide();
	   getFullClaculation();
	});
	
	$("[id^=chkORC_]").on('ifChecked', function () { 
	   $(this).attr('checked', true);
	   getFullClaculation();
	});
	
	$("[id^=chkORC_]").on('ifUnchecked', function () {
	   $(this).attr('checked', false); 
	   getFullClaculation();
	});
	
	
	$("[id^=chkPrevInv_]").on('ifChecked', function () { 
	   $(this).attr('checked', true);
	   getFullClaculation();
	});
	
	$("[id^=chkPrevInv_]").on('ifUnchecked', function () { 
	   $(this).attr('checked', false);
	   getFullClaculation();
	});
	
	$('[id^=Chk_Owner_Account_]').on('ifChecked', function () { 
		   $(this).attr('checked', true);
		   getFullClaculation();
		});
		 
		$('[id^=Chk_Owner_Account_]').on('ifUnchecked', function () { 
		   $(this).attr('checked', false);
		   getFullClaculation();
		});
	
	getBankingDetailsData();
	getFullClaculation();
	
});


function getTimeDiff(date2,date1)
{	
	if(date1 != '' &&  date2 != '')
	{
		end_actual_time  	 =  getDateWithSpecificFormat(date2);
		start_actual_time    =  getDateWithSpecificFormat(date1);
		
		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 days			= (diff) / 86400000;
		return days.toFixed(5);	
	}
}

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 AddNewAddRow()
{
	var id = $("#txtAddID").val();
	if($("#txtAddDes_"+id).val() != "" && $("#txtAddDesAmt_"+id).val() != "")
	{
		id = (id - 1) + 2;
		$('<tr id="add_Row_'+id+'"><td align="center"><a href="#pr1" onClick="removeAddRow(1);"><i class="fa fa-times" style="color:red;"></i></a><select class="form-control" name="txtCORCIDFOROTHERADD_'+id+'" id="txtCORCIDFOROTHERADD_'+id+'" style="width:100px;" required><?php $obj->getOwnerRelatedCostListForTallyInvoice();?></select></td><td colspan="2"><textarea class="form-control areasize" name="txtAddDes_'+id+'" id="txtAddDes_'+id+'" rows="2" placeholder="Description..."></textarea></td><td><input type="text" name="txtAddDesAmt_'+id+'" id="txtAddDesAmt_'+id+'" class="form-control numeric"  placeholder="Amount" autocomplete="off" value="" onKeyUp="getFullClaculation();"/></td></tr>').appendTo("#tblAdd");
		$("#txtAddID").val(id);
		$(".numeric").numeric();	
	}
}


function removeAddRow(var1)
{
		jConfirm('Are you sure you want to remove this entry permanently ?', 'Confirmation', function(r) {
			if(r){
					$("#add_Row_"+var1).remove();
					getFullClaculation();
				 }
			else{return false;}
			});
}



function SubNewSubRow()
{
	var id = $("#txtSubID").val();
	if($("#txtSubDes_"+id).val() != "" && $("#txtSubDesAmt_"+id).val() != "")
	{
		id = (id - 1) + 2;
		$('<tr id="Sub_Row_'+id+'"><td align="center"><a href="#pr1" onClick="removeSubRow(1);"><i class="fa fa-times" style="color:red;"></i></a><select class="form-control" name="txtCORCIDFOROTHERLESS_'+id+'" id="txtCORCIDFOROTHERLESS_'+id+'" style="width:100px;" required><?php $obj->getOwnerRelatedCostListForTallyInvoice();?></select></td><td colspan="2"><textarea class="form-control areasize" name="txtSubDes_'+id+'" id="txtSubDes_'+id+'" rows="2" placeholder="Description..."></textarea></td><td><input type="text" name="txtSubDesAmt_'+id+'" id="txtSubDesAmt_'+id+'" class="form-control numeric"  placeholder="Amount" autocomplete="off" value="" onKeyUp="getFullClaculation();"/></td></tr>').appendTo("#tblSub");
		$("#txtSubID").val(id);
		$(".numeric").numeric();
	}
}


function removeSubRow(var1)
{
	jConfirm('Are you sure you want to remove this entry permanently ?', 'Confirmation', function(r) {
		if(r){
				$("#Sub_Row_"+var1).remove();
				getFullClaculation();
			 }
		else{return false;}
		});
}



function SubNewHoldRow()
{
	var id = $("#txtHoldID").val();
	if($("#txtHoldDes_"+id).val() != "" && $("#txtHoldDesAmt_"+id).val() != "")
	{
		id = (id - 1) + 2;
		$('<tr id="Hold_Row_'+id+'"><td align="center"><a href="#pr1" onClick="removeHoldRow(1);"><i class="fa fa-times" style="color:red;"></i></a></td><td colspan="2"><textarea class="form-control areasize" name="txtHoldDes_'+id+'" id="txtHoldDes_'+id+'" rows="2" placeholder="Description..."></textarea></td><td><input type="text" name="txtHoldDesAmt_'+id+'" id="txtHoldDesAmt_'+id+'" class="form-control numeric"  placeholder="Amount" autocomplete="off" value="" onKeyUp="getFullClaculation();"/></td></tr>').appendTo("#tblHold");
		$("#txtHoldID").val(id);
		$(".numeric").numeric();
	}
}


function removeHoldRow(var1)
{
	jConfirm('Are you sure you want to remove this entry permanently ?', 'Confirmation', function(r) {
		if(r){
				$("#Hold_Row_"+var1).remove();
				getFullClaculation();
			 }
		else{return false;}
		});
}


function SubNewHireSurveyRow()
{
	var id = $("#txtHireSurveyID").val();
	if($("#txtHireSurveyDes_"+id).val() != "" && $("#txtHireSurveyDesAmt_"+id).val() != "")
	{
		id = (id - 1) + 2;
		$('<tr id="HireSurvey_Row_'+id+'"><td align="center"><a href="#pr1" onClick="removeHireSurveyRow(1);"><i class="fa fa-times" style="color:red;"></i></a></td><td><textarea class="form-control areasize" name="txtHireSurveyDes_'+id+'" id="txtHireSurveyDes_'+id+'" rows="2" placeholder="Description..."></textarea></td><td align="left"><input name="Chk_Owner_Account_'+id+'" class="checkbox" id="Chk_Owner_Account_'+id+'" type="checkbox" value="1"/>&nbsp;&nbsp;On Owner\'s Account</td><td><input type="text" name="txtHireSurveyDesAmt_'+id+'" id="txtHireSurveyDesAmt_'+id+'" class="form-control numeric"  placeholder="Amount" autocomplete="off" value="" onKeyUp="getFullClaculation();"/></td></tr>').appendTo("#tblHireSurvey");
		$("#txtHireSurveyID").val(id);
		$(".numeric").numeric();
		
		$('#Chk_Owner_Account_'+id).iCheck({
		checkboxClass: 'icheckbox_minimal',
		radioClass: 'iradio_minimal'
		});
		
		$('[id^=Chk_Owner_Account_]').on('ifChecked', function () { 
		   $(this).attr('checked', true);
		   getFullClaculation();
		});
		 
		$('[id^=Chk_Owner_Account_]').on('ifUnchecked', function () { 
		   $(this).attr('checked', false);
		   getFullClaculation();
		});
	}
}


function removeHireSurveyRow(var1)
{
	jConfirm('Are you sure you want to remove this entry permanently ?', 'Confirmation', function(r) {
		if(r){
				$("#HireSurvey_Row_"+var1).remove();
				getFullClaculation();
			 }
		else{return false;}
		});
}



function getFullClaculation()
{

	
    for(var i = 1;i<=$("#txtAddDELID").val();i++)
	{
		if($("#selDELBunker_"+i).val()!='')
		{
			if($("#txtDelBunkerQty_"+i).val() == ""){var txtDelBunkerQty = 0;}else{var txtDelBunkerQty = $("#txtDelBunkerQty_"+i).val();}
			if($("#txtDelBunkerPrice_"+i).val() == ""){var txtDelBunkerPrice = 0;}else{var txtDelBunkerPrice = $("#txtDelBunkerPrice_"+i).val();}
			var txtDelBunkerAmt = parseFloat(txtDelBunkerQty)*parseFloat(txtDelBunkerPrice);if(isNaN(txtDelBunkerAmt)){txtDelBunkerAmt = 0.00;}
			$("#txtDelBunkerAmt_"+i).val(parseFloat(txtDelBunkerAmt).toFixed(2));
		}
		else
		{
			$("#txtDelBunkerQty_"+i).val('');
			$("#txtDelBunkerPrice_"+i).val('');
			$("#txtDelBunkerAmt_"+i).val('')
		}
	}
	
	for(var i = 1;i<=$("#txtAddREDELID").val();i++)
	{
		if($("#selReDELBunker_"+i).val()!='')
		{
			if($("#txtReDelBunkerQty_"+i).val() == ""){var txtReDelBunkerQty = 0;}else{var txtReDelBunkerQty = $("#txtReDelBunkerQty_"+i).val();}
			if($("#txtReDelBunkerPrice_"+i).val() == ""){var txtReDelBunkerPrice = 0;}else{var txtReDelBunkerPrice = $("#txtReDelBunkerPrice_"+i).val();}
			var txtReDelBunkerAmt = parseFloat(txtReDelBunkerQty)*parseFloat(txtReDelBunkerPrice);if(isNaN(txtReDelBunkerAmt)){txtReDelBunkerAmt = 0.00;}
			$("#txtReDelBunkerAmt_"+i).val(parseFloat(txtReDelBunkerAmt).toFixed(2));
		}
		else
		{
			$("#txtReDelBunkerQty_"+i).val('');
			$("#txtReDelBunkerPrice_"+i).val('');
			$("#txtReDelBunkerAmt_"+i).val('')
		}
	}
    
	
	for(var i = 1;i<=$("#txtAddOVERCONPID").val();i++)
	{
		if($("#selOverConspBunker_"+i).val()!='')
		{
			if($("#txtOverConspBunkerQty_"+i).val() == ""){var txtOverConspBunkerQty = 0;}else{var txtOverConspBunkerQty = $("#txtOverConspBunkerQty_"+i).val();}
			if($("#txtOverConspBunkerPrice_"+i).val() == ""){var txtOverConspBunkerPrice = 0;}else{var txtOverConspBunkerPrice = $("#txtOverConspBunkerPrice_"+i).val();}
			var txtOverConspBunkerAmt = parseFloat(txtOverConspBunkerQty)*parseFloat(txtOverConspBunkerPrice);if(isNaN(txtOverConspBunkerAmt)){txtOverConspBunkerAmt = 0.00;}
			$("#txtOverConspBunkerAmt_"+i).val(parseFloat(txtOverConspBunkerAmt).toFixed(2));
		}
		else
		{
			$("#txtOverConspBunkerQty_"+i).val('');
			$("#txtOverConspBunkerPrice_"+i).val('');
			$("#txtOverConspBunkerAmt_"+i).val('')
		}
	}
	
	
	var ownersbunkercal = 0;var offhiredays = 0;
	if($("#ChkShowOffHire").is(":checked"))
	{
	    var numoff = $("#txtOFFID").val();
		
		for(var i =1;i <=numoff;i++)
		{
			if(typeof($("#txtOffHireFrom_"+i).val())!='undefined')
			{
				
				if($("#txtOffHireTo_"+i).val()!='' && $("#txtOffHireFrom_"+i).val()!='')
				{
					// return false;

					var timediff = parseFloat(getTimeDiff($("#txtOffHireTo_"+i).val(),$("#txtOffHireFrom_"+i).val()));
					if(isNaN(timediff)){timediff = 0.00;}
					
					var txtOffHirePercent = parseFloat($("#txtOffHirePercent_"+i).val());if(isNaN(txtOffHirePercent)){txtOffHirePercent = 0;}
					var txtOffHireDays = parseFloat(parseFloat(timediff)*parseFloat(txtOffHirePercent))/100;if(isNaN(txtOffHireDays) || txtOffHireDays==''){txtOffHireDays = 0;}
					$("#txtOffHireDays_"+i).val(parseFloat(txtOffHireDays).toFixed(5));
					timediff = txtOffHireDays;
				}else{
				    var txtOffHirePercent = parseFloat($("#txtOffHirePercent_"+i).val());if(isNaN(txtOffHirePercent)){txtOffHirePercent = 0;}
					var timediff = $("#txtOffHireDays_"+i).val();
					if(timediff=="" || isNaN(timediff)){timediff =0;}
					var txtOffHireDays = parseFloat(parseFloat(timediff)*parseFloat(txtOffHirePercent))/100;if(isNaN(txtOffHireDays) || txtOffHireDays==''){txtOffHireDays = 0;}
					var timediff = txtOffHireDays;
				}
				
				var offrate  = parseFloat($("#selOffHirePerDay_"+i).val());if(isNaN(offrate) || offrate==''){offrate = 0;}
				offhiredays =   parseFloat(parseFloat(offhiredays) + parseFloat(timediff));
				$("#txtOffHireAmt_"+i).val(parseFloat(parseFloat(timediff)*parseFloat(offrate)).toFixed(2));
				
				var numoffbunker = $("#txtTCConBunkerCount_"+i).val();
				for(var j =1;j <=numoffbunker;j++)
				{
					if(typeof($("#selTCConBunker_"+i+"_"+j).val())!='undefined')
					{
						var txtTCConBunkerQty = parseFloat($("#txtTCConBunkerQty_"+i+"_"+j).val());
						if(isNaN(txtTCConBunkerQty)){txtTCConBunkerQty = 0.00;}
						var txtTCConBunkerPrice = parseFloat($("#txtTCConBunkerPrice_"+i+"_"+j).val());
						if(isNaN(txtTCConBunkerPrice)){txtTCConBunkerPrice = 0.00;}
						var txtTCConBunkerAmt = parseFloat(parseFloat(txtTCConBunkerQty)*parseFloat(txtTCConBunkerPrice));
						console.log(txtTCConBunkerAmt)

						// console.log('-------------')
						$("#txtTCConBunkerAmt_"+i+"_"+j).val(parseFloat(txtTCConBunkerAmt).toFixed(2));
						ownersbunkercal = parseFloat(ownersbunkercal) + parseFloat(txtTCConBunkerAmt);
					}
				}
			}
		}
	}
	
	
	for(var i =1;i<=$("#totalDaysTows").val();i++)
	{
	    var delDays1 = parseFloat(getTimeDiff($("#txtHireTo_"+i).val(),$("#txtHireFrom_"+i).val()));
		if(isNaN(delDays1)){delDays1 = 0.00000;}
		var txtHireTo=$("#txtHireTo_"+i).val();

		var txtHireFrom=$("#txtHireFrom_"+i).val();
		var dateFrom = getString1(txtHireFrom);
		var dateTo = getString1(txtHireTo);

		var txtHireperDay = parseFloat($("#txtHireperDay_"+i).val());if(isNaN(txtHireperDay)){txtHireperDay = 0.00;}
		
		if($("#ChkShowOffHire").is(":checked"))
		{

			var numoff = $("#txtOFFID").val();
			for(var jj =1;jj <=numoff;jj++)
			{
				var dateCheck = getString1($("#txtOffHireFrom_"+jj).val());

			     if(txtHireperDay == $("#selOffHirePerDay_"+jj).val() && $("#txtOffHireDays_"+jj).val() > 0)
				 {
				     if($("#txtOffHireTo_"+jj).val()!='' && $("#txtOffHireFrom_"+jj).val()!='')
				     {
						//if(dateCheck >= dateFrom &&  dateCheck <= dateTo){
						 var txtOffHireDays = parseFloat($("#txtOffHireDays_"+jj).val());if(isNaN(txtOffHireDays)){txtOffHireDays = 0.00000;}
						 delDays1 = parseFloat(delDays1) - parseFloat(txtOffHireDays);
						//}
					 }
					 else
					 {  
					     var txtOffHirePercent = parseFloat($("#txtOffHirePercent_"+jj).val());if(isNaN(txtOffHirePercent)){txtOffHirePercent = 0;}
						 var timediff = $("#txtOffHireDays_"+jj).val();
						 if(timediff=="" || isNaN(timediff)){timediff =0;}
						 var txtOffHireDays = parseFloat(parseFloat(timediff)*parseFloat(txtOffHirePercent))/100;if(isNaN(txtOffHireDays) || txtOffHireDays==''){txtOffHireDays = 0;}
						 delDays1 = parseFloat(delDays1) - parseFloat(txtOffHireDays);
					 }
				 }
			}
		}

		var checkHireDays = parseFloat($('#txtEstHireDays').val());


			
			$("#txtInvDay_"+i).val(parseFloat(delDays1).toFixed(5));

			var nettHire = parseFloat(txtHireperDay) * parseFloat(delDays1);
			if(isNaN(nettHire)){nettHire = 0.00;}
			$("#txtInvHire_"+i).val(parseFloat(nettHire).toFixed(2));

		
		

}

	function checkdate(_input, _start, _end) {
    function parseDate(x) {
        if (typeof x === 'string') {
            var parts = x.split(/[-: ]/g).map(Number);
            x = new Date(parts[0], parts[1]-1, parts[2], parts[3], parts[4], parts[5]);
        }
        return x;
    }

    _input = parseDate(_input);
    _start = parseDate(_start);
    _end   = parseDate(_end);

    return _input > _start && _input < _end;
}

function getString1(var1)
{
	var var2 = var1.split(' ');
	var var3 = var2[0].split('-');	 
	return var3[2]+'/'+var3[1]+'/'+var3[0]+' '+var2[1]; 
}
	
    var delDays1 = parseFloat($("[id^=txtInvDay_]").sum()).toFixed(5);
	if(isNaN(delDays1)){delDays1 = 0.00000;}
	delDays1 = parseFloat(delDays1).toFixed(5);
	
	var nettHire = parseFloat($("[id^=txtInvHire_]").sum()).toFixed(2);
	if(isNaN(nettHire)){nettHire = 0.00;}
	var nettHire1 = nettHire;
	$("#txtTotalHire").val(parseFloat(nettHire).toFixed(2));
	
	if($("#txtCVEMonth").val() == ""){var txtCVEMonth = 0;}else{var txtCVEMonth = $("#txtCVEMonth").val();}
	var txtCVE_Amt = parseFloat(parseFloat(parseFloat(parseFloat(txtCVEMonth)*12)/365)*parseFloat(delDays1));if(isNaN(txtCVE_Amt)){txtCVE_Amt = 0.00;}
	$("#txtCVE_Amt").val(parseFloat(txtCVE_Amt).toFixed(2));
	

	if($("#ChkBallastBonus").is(":checked"))
	{
	    var txtBallastBonus = parseFloat($("#txtBallastBonus").val());if(isNaN(txtBallastBonus)){txtBallastBonus = 0.00;}
		nettHire = parseFloat(nettHire) + parseFloat(txtBallastBonus.toFixed(4));
	}
	
	if($("#txtAddrCommPer").val() == ""){var txtAddrCommPer = 0;}else{var txtAddrCommPer = $("#txtAddrCommPer").val();}
	var txtAddrCommAmt = parseFloat(parseFloat(parseFloat(nettHire)*parseFloat(txtAddrCommPer))/100);if(isNaN(txtAddrCommAmt)){txtAddrCommAmt = 0.00;}
	$("#txtAddrCommAmt").val(parseFloat(txtAddrCommAmt).toFixed(2));
	
	if($("#txtBroCommPer").val() == ""){var txtBroCommPer = 0;}else{var txtBroCommPer = $("#txtBroCommPer").val();}
	var txtBroCommAmt = parseFloat(parseFloat(parseFloat(nettHire)*parseFloat(txtBroCommPer))/100);if(isNaN(txtBroCommAmt)){txtBroCommAmt = 0.00;}
	$("#txtBroCommAmt").val(parseFloat(txtBroCommAmt).toFixed(2));		
	
	var txthddnAmt = 0;
	
	for(var i = 1;i<=$("#hddnprevinvid").val();i++)
	{
		if($("#chkPrevInv_"+i).is(":checked"))
		{
			var txtPrevInvAmt = parseFloat($("#txtPrevInvAmt_"+i).val());if(isNaN(txtPrevInvAmt)){txtPrevInvAmt = 0.00;}
			txthddnAmt = parseFloat(txthddnAmt) + parseFloat(txtPrevInvAmt);
		}
	}
	
	
	var otheradd = parseFloat($("[id^=txtAddDesAmt_]").sum()).toFixed(2);if(isNaN(otheradd)){otheradd = 0.00;}
	var addadj = parseFloat($("[id^=txtAddADJAmt_]").sum()).toFixed(2);if(isNaN(addadj)){addadj = 0.00;}
	otheradd = parseFloat(otheradd) + parseFloat(txtCVE_Amt);if(isNaN(otheradd)){otheradd = 0.00;}
	var otherless = parseFloat($("[id^=txtSubDesAmt_]").sum()).toFixed(2);
	var lessadj = parseFloat($("[id^=txtLessADJAmt_]").sum()).toFixed(2);
	var otherhold = parseFloat($("[id^=txtHoldDesAmt_]").sum()).toFixed(2);
	
	for(var i = 1;i<=$("#txtHireSurveyID").val();i++)
	{
	    var txtHireSurveyDesAmt = parseFloat($("#txtHireSurveyDesAmt_"+i).val());if(isNaN(txtHireSurveyDesAmt)){txtHireSurveyDesAmt = 0;}
		if($("#Chk_Owner_Account_"+i).is(":checked"))
		{
			otheradd = parseFloat(otheradd) + parseFloat(txtHireSurveyDesAmt);
		}
		else
		{
			otherless = parseFloat(otherless) + parseFloat(txtHireSurveyDesAmt);
		}
	}
	
	otheradd = parseFloat(otheradd) + parseFloat(otherhold);
	
	$("#txtAddrCommAmt").val(parseFloat(txtAddrCommAmt).toFixed(2));
	$("#txtBroCommAmt").val(parseFloat(txtBroCommAmt).toFixed(2));	
	
	if($("#ChkDeliveryBunker").is(":checked"))
	{
		otheradd = parseFloat(otheradd) + parseFloat($("[id^=txtDelBunkerAmt_]").sum());
	}
	
	
	if($("#ChkReDeliveryBunker").is(":checked"))
	{
		otherless = parseFloat(otherless) + parseFloat($("[id^=txtReDelBunkerAmt_]").sum());
	}
	
	
	if($("#ChkOverConspBunker").is(":checked"))
	{
		otherless = parseFloat(otherless) + parseFloat($("[id^=txtOverConspBunkerAmt_]").sum());
	}
	
	console.log(ownersbunkercal)
	// console.log(otheradd);

	// console.log(ownersbunkercal);
	// console.log(otherless);
	otherless = parseFloat(otherless) + parseFloat(txtAddrCommAmt);

	otherless = parseFloat(otherless) + parseFloat(txtBroCommAmt);
	
	var finalamt = roundToTwo(nettHire) + roundToTwo(otheradd) + roundToTwo(addadj) - roundToTwo(otherless) - roundToTwo(ownersbunkercal)- roundToTwo(lessadj);
	
	console.log(finalamt ,roundToTwo(finalamt)	);
	// Number(1.345).toFixed(2)
	$("#txtFinalAmt").val(roundToTwo(finalamt));
	
	
	for(var i = 1;i<=$("#txtORCID").val();i++)
	{
		if($("#chkORC_"+i).is(":checked"))
		{
			var txtORCAmt = parseFloat($("#txtORCAmt_"+i).val());if(isNaN(txtORCAmt)){txtORCAmt = 0.00;}
			txthddnAmt = parseFloat(txthddnAmt) + parseFloat(txtORCAmt);
		}
	}
	
	
	var txtBalanceShipOwner = parseFloat(finalamt) - parseFloat(txthddnAmt);

	console.log(txtBalanceShipOwner);

	$("#txtBalanceShipOwner").val(roundToTwo(txtBalanceShipOwner));
	
	if(txtBalanceShipOwner >=0)
	{
	    $("#selBankingID").show();
		<?php if($banking_details_c > 0)
		{?>
			$("#selBankingID").rules('add', {required:true});
	<?php }?>

		$("#selBankingID1").hide();
	}
	else
	{
		$("#selBankingID1").show();
		$("#selBankingID").hide();
	}
	
	var txthddnHireDays = parseFloat($("[id^=txtPrevInvDays_]").sum());
	var txtEstHireDays = parseFloat($("#txtEstHireDays").val());
	if(isNaN(txtEstHireDays)){txtEstHireDays = 0.00;}
	var txtRemainingDays = parseFloat(txtEstHireDays) - parseFloat(delDays1);
	if(isNaN(txtRemainingDays)){txtRemainingDays = 0.00;}
	$("#txtRemainingDays").val(parseFloat(txtRemainingDays).toFixed(5));
}

function calc(numConverted) {
    var num = numConverted,rounded
    var with2Decimals = num.toString().match(/^-?\d+(?:\.\d{0,2})?/)[0]
    rounded = with2Decimals
	return rounded
}

function roundToTwo(num) {
    return +(Math.round(num + "e+2")  + "e-2");
}

function getDelete(invoiceid,var1)
{ 
    jConfirm('Are you sure you want to delete this statement permanently ?', 'Confirmation', function(r) {
		if(r){ 
			$("#action11").val('submit2');
			
			$("#txtDEL_ID").val(invoiceid);
			document.frm3.submit();
	    }
		else{return false;}
		});
}



function removeLessAdjRow(var1)
{
		jConfirm('Are you sure you want to remove this entry permanently ?', 'Confirmation', function(r) {
			if(r){
					$("#lessadj_Row_"+var1).remove();
					getFullClaculation();
				 }
			else{return false;}
			});
}



function getBankingDetailsData()
{   
	var1 = $('#selBankingDetails').val();
	if($("#selBankingDetails").val()!="")
	{
		$.post("options.php?id=43",{selNOB:""+$("#selBankingDetails").val()+""}, function(html) {
			if(html!="")
			{
				$("#bankingrow").show();
				var res = html.split("@@@@");
				$('#span_1_0').text(res[0]);
				$('#span_1_1').text(res[1]);
				$('#span_1_2').text(res[2]);
				$('#span_1_3').text(res[3]);
				$('#span_1_4').text(res[4]);
				$('#span_1_5').text(res[5]);
				$('#span_1_6').text(res[6]);
				$('#span_1_7').text(res[7]);
				$('#span_1_8').text(res[8]);
				$('#span_1_9').text(res[9]);
				$('#span_1_10').text(res[10]);
			}
		});
	}
	else

	{
	    $("#bankingrow").hide();	
		$('#span_1_0').text("");
	    $('#span_1_1').text("");
		$('#span_1_2').text("");
		$('#span_1_3').text("");
		$('#span_1_4').text("");
		$('#span_1_5').text("");
		$('#span_1_6').text("");
		$('#span_1_7').text("");
		$('#span_1_8').text("");
		$('#span_1_9').text("");
		$('#span_1_10').text("");
	}
}

function getValid()
{
	if($('#txtP_PR').val() == '' || $('#txtP_Date').val() =='' || $('#txtP_Remarks').val()=='')
	{
		jAlert('Please fill the Payment Received & Date & Remarks', 'Alert');
		return false;
	}
	else
	{
		var file_temp_name = $("[id^=file1_]").map(function () {return this.value;}).get().join(",");
	    $('#txtCRMFILE1').val(file_temp_name);
	    var file_actual_name = $("[id^=name1_]").map(function () {return this.value;}).get().join(",");
	    $('#txtCRMNAME1').val(file_actual_name);
		document.frm2.submit();
		return true;
	}
}


function openWin(var1)
{
	$("#divPayment").empty();
	$("#divPayment").html('<div><img src="../../img/ajax-loader.gif" /><br><b>Loading...</b></div>'); 
	$.post("options.php?id=45",{invoiceid:""+var1+""}, function(html) {
		$("#divPayment").empty();
		$("#divPayment").append(html);
		// if($("#txtP_PR").val() > 0)
		// {
			// $("#btnhide").hide();	
		// }
		$("#txtP_PR").numeric();
        $('#txtP_Remarks').autosize({append: "\n"});
		$('#txtP_Date').datepicker({
			format: 'dd-mm-yyyy',
			autoclose:true
		});
	});
}

function Del_Upload1(var2)
{
	jConfirm('Are you sure you want to delete this upload permanently ?', 'Confirmation', function(r) {
	if(r){ 
		$('#row_file1_'+var2).remove();
	}
	});
}

function getDatesFinal()
{
    if($("#selIType").val() == 'Final')
	{
		if($("#txtFirstDate").val()!='')
		{
			$("#txtHireFrom").val($("#txtFirstDate").val());
		}
		
		if($("#txtLastDate").val()!='')
		{
			$("#txtHireTo").val($("#txtLastDate").val());
		}
	}
	else
	{
		$("#txtHireTo").val('');
		$("#txtHireFrom").val('');
	}
	
	getFullClaculation();
}


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


function AddNewOffHire()
{
	var id = $("#txtOFFID").val();
	if($("#txtOffHireReason_"+id).val() != "" && (($("#txtOffHireFrom_"+id).val() != "" && $("#txtOffHireTo_"+id).val() != "") || $("#txtOffHireDays_"+id).val() != ""))
	{
		id = (id - 1) + 2;
		$('<tr id="row_offhire_'+id+'"><td><a href="#pr'+id+'" onclick="removeOffHire('+id+');"><i class="fa fa-times" style="color:red;"></i></a></td><td valign="top"><textarea class="form-control areasize" name="txtOffHireReason_'+id+'" id="txtOffHireReason_'+id+'" rows="3" placeholder="Off Hire Reason..."></textarea></td><td valign="top"><input type="text" name="txtOffHireFrom_'+id+'" id="txtOffHireFrom_'+id+'" class="form-control" placeholder="dd-mm-yyyy HH:MM" autocomplete="off" value=""></td><td valign="top"><input type="text" name="txtOffHireTo_'+id+'" id="txtOffHireTo_'+id+'" class="form-control" placeholder="dd-mm-yyyy HH:MM" autocomplete="off" value=""></td><td valign="top"><input type="text" name="txtOffHirePercent_'+id+'" id="txtOffHirePercent_'+id+'" class="form-control" placeholder="%" autocomplete="off" value="" onKeyUp="getFullClaculation();"/></td><td valign="top"><input type="text" name="txtOffHireDays_'+id+'" id="txtOffHireDays_'+id+'" class="form-control numeric" placeholder="Off Hire Days" autocomplete="off" value="" onKeyUp="getFullClaculation();"/></td><td width="15%"><select name="selOffHirePerDay_'+id+'" id="selOffHirePerDay_'+id+'" class="form-control" onChange="getFullClaculation();"></select></td><td valign="top"><input type="text" name="txtOffHireAmt_'+id+'" id="txtOffHireAmt_'+id+'" class="form-control" placeholder="Off Hire(USD)" autocomplete="off" value=""/></td></tr><tr id="row_offhireBunker_'+id+'"><td></td><td colspan="6"><table width="100%" class="tablesorter"><tr><td></td><td>Bunker Grade</td><td>Qty(MT)</td><td>Price(USD)</td><td>Amount(USD)</td></tr><tbody id="TCConbunkerTBody_'+id+'"><tr id="DivTCConBunkeractual_'+id+'_1"><td><a href="#tb1" onClick="removeTCConBunkerRows('+id+',1);" ><i class="fa fa-times" style="color:red;"></i></a></td><td><select name="selTCConBunker_'+id+'_1" id="selTCConBunker_'+id+'_1" class="form-control"><?php $obj->getBunkerList();?></select></td><td><input type="text" name="txtTCConBunkerQty_'+id+'_1" id="txtTCConBunkerQty_'+id+'_1" class="form-control numeric" onKeyUp="getFullClaculation();" placeholder="0.00" autocomplete="off" value=""/></td><td><input type="text" name="txtTCConBunkerPrice_'+id+'_1" id="txtTCConBunkerPrice_'+id+'_1" class="form-control numeric" onKeyUp="getFullClaculation();" placeholder="0.00" autocomplete="off" value=""/></td><td><input type="text" name="txtTCConBunkerAmt_'+id+'_1" id="txtTCConBunkerAmt_'+id+'_1" class="form-control"  placeholder="0.00" readonly autocomplete="off" value=""/></td></tr></tbody><tr><td colspan="6"><button type="button" class="btn btn-primary" onClick="addTCConBunkerRow('+id+',1)">Add Bunkers</button><input type="hidden" name="txtTCConBunkerCount_'+id+'" id="txtTCConBunkerCount_'+id+'" value="1"/></td></tr></table></td></tr>').appendTo("#offhirebody");
		$("#txtOFFID").val(id);
		$("[id^=txtOffHirePercent_]").numeric();	
		$(".numeric").numeric();
		$(".areasize").autosize({append: "\n"});
		
		$("#selOffHirePerDay_"+id).html($("#hirearraycell").html());
		
		$('#txtOffHireFrom_'+id+',#txtOffHireTo_'+id).datetimepicker({
		format: 'dd-mm-yyyy hh:ii',
	    autoclose: true,
        todayBtn: true,
        minuteStep: 1
		}).on('changeDate', function(){  getFullClaculation(); });
	}
}


function removeOffHire(var1)
{
		jConfirm('Are you sure you want to remove this entry permanently ?', 'Confirmation', function(r) {
		if(r){
				$("#row_offhire_"+var1).remove();
				$("#row_offhireBunker_"+var1).remove()
				getFullClaculation();
			 }
		else{return false;}
		});
}


function addTCConBunkerRow(val)
{
	var id = $("#txtTCConBunkerCount_"+val).val();
	if($("#txtTCConBunkerQty_"+val+"_"+id).val() != "" && $("#selTCConBunker_"+val+"_"+id).val() != "" && $("#txtTCConBunkerPrice_"+val+"_"+id).val() != "")
	{
		id = (id - 1) + 2;
		$('<tr id="DivTCConBunkeractual_'+val+'_'+id+'"><td><a href="#tbb'+id+'" onclick="removeTCConBunkerRows('+val+','+id+');"><i class="fa fa-times" style="color:red;"></i></a></td><td><select name="selTCConBunker_'+val+'_'+id+'" id="selTCConBunker_'+val+'_'+id+'" class="form-control"><?php $obj->getBunkerList();?></select></td><td><input type="text" name="txtTCConBunkerQty_'+val+'_'+id+'" id="txtTCConBunkerQty_'+val+'_'+id+'" class="form-control numeric" onkeyup="getFullClaculation();" placeholder="0.00" autocomplete="off" value=""></td><td><input type="text" name="txtTCConBunkerPrice_'+val+'_'+id+'" id="txtTCConBunkerPrice_'+val+'_'+id+'" class="form-control numeric" onkeyup="getFullClaculation();" placeholder="0.00" autocomplete="off" value=""></td><td><input type="text" name="txtTCConBunkerAmt_'+val+'_'+id+'" id="txtTCConBunkerAmt_'+val+'_'+id+'" class="form-control" placeholder="0.00" readonly="" autocomplete="off" value=""></td></tr>').appendTo("#TCConbunkerTBody_"+val);
		$("#txtTCConBunkerCount_"+val).val(id);
		$(".numeric").numeric();	
	}
	else
	{
		jAlert('Please fill previous data', 'Alert');
		return false;
	}
}

function removeTCConBunkerRows(val,var1)
{
	jConfirm('Are you sure you want to remove this entry permanently ?', 'Confirmation', function(r) {
		if(r){
				$("#DivTCConBunkeractual_"+val+"_"+var1).remove();
				getFullClaculation();			
			 }
		else{return false;}
		});
}


function AddNewOverConspRow()
{
	var id = $("#txtAddOVERCONPID").val();
	if($("#selOverConspBunker_"+id).val() != "" && $("#txtOverConspBunkerQty_"+id).val() != "" && $("#txtOverConspBunkerPrice_"+id).val() != "")
	{
		id = (id - 1) + 2;
		$('<tr id="DivBunkerOverConsp_'+id+'"><td><select name="selOverConspBunker_'+id+'" class="form-control" id="selOverConspBunker_'+id+'"><?php $obj->getBunkerList();?></select></td><td><input type="text" name="txtOverConspBunkerQty_'+id+'" id="txtOverConspBunkerQty_'+id+'" class="form-control numeric" value="" placeholder="0.00" onKeyUp="getFullClaculation();" autocomplete="off" /></td><td><input type="text" name="txtOverConspBunkerPrice_'+id+'" id="txtOverConspBunkerPrice_'+id+'" class="form-control numeric" value="" placeholder="0.00" onKeyUp="getFullClaculation();" autocomplete="off" /></td><td><input type="text" name="txtOverConspBunkerAmt_'+id+'" id="txtOverConspBunkerAmt_'+id+'" class="form-control numeric" value="" placeholder="0.00" readonly="true" autocomplete="off"/></td></tr>').appendTo("#bunkerOverConspbody");
		$("#txtAddOVERCONPID").val(id);
		$(".numeric").numeric();
	}
	else
	{
		jAlert('Please fill previous data', 'Alert');
		return false;
	}
}
</script>
<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;
}
.span span{
	font-weight:bold;
}
</style>
</head>
    <body class="skin-blue fixed">
        <!-- header logo: style can be found in header.less -->
        <?php $display->header_tag(); ?>
		<div class="wrapper row-offcanvas row-offcanvas-left">
            <?php $display->leftmenu($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;">( 20 Jul 2015 4:40:44 PM )</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;&gt;&nbsp;&nbsp;&nbsp;<?php echo $page_bar;?>&nbsp;&nbsp;&nbsp;</li>
                    </ol>
                </section>

                <!-- Main content -->
                <section class="content">
                        <?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> Hire Statement 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> Hire Statement can not be created.
								</div>
								<?php }?>
								<?php if($msg == 2){?>
								<div class="alert alert-success alert-dismissable">
									<i class="fa fa-ban"></i>
									<button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
									<b>Congratulations!</b> Hire Statement deleted successfully.
								</div>
								<?php }?>
                                <?php if($msg == 3){?>
								<div class="alert alert-success alert-dismissable">
									<i class="fa fa-ban"></i>
									<button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
									<b>Congratulations!</b> Payment paid details saved successfully.
								</div>
								<?php }?>
						<?php }?>
				<!--   content put here..................-->
                <?php
				$sql = "SELECT *,(select CONTACT_PERSON from login where login.LOGINID = invoice_hire_master.L_UPDATED_BY) as LUPNAME from invoice_hire_master where COMID='".$comid."' and MODULEID='".$_SESSION['moduleid']."' and MCOMPANYID='".$_SESSION['company']."' and STATUS < 5";

				// echo '<pre>';

			// echo '<h1>'.$sql;
		
				$res 	= mysql_query($sql);
				$rec 	= mysql_num_rows($res);
				$rows 	= mysql_fetch_assoc($res);
			

				$sql_rep = "SELECT * from invoice_hire_master where COMID='".$comid."' and MODULEID='".$_SESSION['moduleid']."' and MCOMPANYID='".$_SESSION['company']."' ORDER BY INVOICEID DESC LIMIT 1;
				";
			
			
				$res_rep 	= mysql_query($sql_rep);
				$rec_rep 	= mysql_num_rows($res_rep);
				$rows_rep 	= mysql_fetch_assoc($res_rep);
				
				$sql3 = "SELECT SUM(OFF_HIRE) as SUM, SUM(OFF_DAYS) as SUM1 from freight_cost_estimete_slave14 where FCAID='".$id."'";
				$res3 	= mysql_query($sql3);
				$rec3 	= mysql_num_rows($res3);
				$rows3 = mysql_fetch_assoc($res3);
				
				$sql31 = "SELECT SUM(BUNKERAMT) as SUM2 from freight_cost_estimete_slave15 where FCAID='".$id."'";
				$res31 	= mysql_query($sql31);
				$rec31 	= mysql_num_rows($res31);
				$rows31 = mysql_fetch_assoc($res31);
				
				$sql_all = "SELECT * from invoice_hire_master where COMID='".$comid."' and MODULEID='".$_SESSION['moduleid']."' and MCOMPANYID='".$_SESSION['company']."' and STATUS = 5 order by INVOICEID desc";
				$res_all 	= mysql_query($sql_all);
				
				$rec_all 	= mysql_num_rows($res_all);
				$offhiredays = $offhireamount = 0;
				$ifballastbonus = 0;$ifdelivery = 0; $ifredelivery = 0;
				$lasthiredate = '';$totalinvdays = 0;
				$i = 0;
				$previnvoiceid = '';
				while($rows_all	= mysql_fetch_assoc($res_all))
				{$i++; if($i==1){$previnvoiceid = $rows_all['INVOICEID'];}
				    if($rows_all['CHK_BALLAST_BONUS']==1){$ifballastbonus = 1;}
					if($rows_all['CHK_DELIVERY']==1){$ifdelivery = 1;}
					if($rows_all['CHK_REDELIVERY']==1){$ifredelivery = 1;}
					if($rows_all['CHK_OFFHIRE']==1){$offhiredays = $offhiredays + $rows_all['OFFHIRE_DAYS'];}
					if($rows_all['CHK_OFFHIRE']==1){$offhireamount = $offhireamount + $rows_all['OFFHIRE_AMT'];}
					
					$lasthirelastdate = $rows_all['HIRE_TO'];
					$totalinvdays = $totalinvdays + $rows_all['HIRE_DAYS'];
				} 
				
				if($rec_all>0){
					$remainingdays = $obj->getFun62() - $totalinvdays;
					
					$strtodays = number_format(($remainingdays * (60 * 60 * 24)),0,'.','');
					$laststrtotime = strtotime($lasthirelastdate) + $strtodays;
					$lastdate = date('d-m-Y H:i',$laststrtotime);
				}

				
				?>	



					<?php if($rec>0){?>
											
						<div align="left">
												<strong>
												<div class="col-xs-12" style="">
														(LAST UPDATED BY/TIME)
										</div>
													<div class="col-xs-12" style="">
													<?php
																		echo $rows['LUPNAME'] . '-' . $rows['L_UP_TIME'];
																		?>

					</div>
											</strong>
					
											</div>
						<?php } ?>




				<div align="right"><?php if($rec>0){?><a href="allPdf.php?id=46&comid=<?php echo $comid; ?>&invoiceid=<?php echo $rows_rep['INVOICEID']; ?>" title="Pdf"><button class="btn btn-default" style="margin-right: 5px;"><i class="fa fa-download"></i> Generate PDF</button></a><?php }?><a href="<?php echo $page_link;?>?comid=<?php echo $comid;?>&page=<?php echo $page;?>"><button class="btn btn-info btn-flat" type="button" >Back</button></a>


			
			</div>
				
				<div style="height:10px;">&nbsp;</div>
					<form role="form" name="frm1" id="frm1" enctype="multipart/form-data" action="<?php echo $pagename;?>" method="post">			
						<div class="row">
							<div class="col-xs-12" style="text-align:center;">
								<h2 class="page-header">
								HIRE STATEMENT CREATION 

                                <input type="hidden" name="txtInID" id="txtInID" value="<?php echo $rows['INVOICEID'];?>"/>
                                <input type="hidden" name="txtFCAID" id="txtFCAID" value="<?php echo $obj->getFun1();?>"/>
								<input type="hidden" name="txtFirstDate" id="txtFirstDate" value="<?php if(date('d-m-Y',strtotime($lasthirelastdate))!='01-01-1970'){echo date('d-m-Y H:i',strtotime($lasthirelastdate));}?>"/>
                                <input type="hidden" name="txtLastDate" id="txtLastDate" value="<?php if(date('d-m-Y',strtotime($lastdate))!='01-01-1970'){echo date('d-m-Y H:i',strtotime($lastdate));}?>"/>
								</h2>                            
							</div><!-- /.col -->
						</div>
					
						<div class="row invoice-info">
							<div class="col-sm-3 invoice-col">
							   <strong>Creating Company :</strong>
								<address>
                                     <select  name="selFromOwner" class="select form-control" id="selFromOwner">
										<?php $obj->getVendorListNewForCOA(11);?>
									</select>
									<script>$('#selFromOwner').val('<?php echo $rows_rep['SHIP_OWNER'];?>');</script>
								</address>
							</div><!-- /.col -->
                            
							<div class="col-sm-3 invoice-col">
							   <strong>To :</strong>
								<address>
									<?php echo $obj->getVendorListNewBasedOnID($vendorid,"NAME");?><br/>
                                    <?php echo $obj->getVendorListNewData($vendorid,"STREET_1");?><br/>
                                    <?php if($obj->getVendorListNewData($vendorid,"STREET_2")!=''){echo $obj->getVendorListNewData($vendorid,"STREET_2").'<br/>';}?>
                                     <?php echo $obj->getVendorListNewData($vendorid,"CITY");?> <?php echo $obj->getVendorListNewData($vendorid,"COUNTRY");?> <?php echo $obj->getVendorListNewData($vendorid,"CITY_POSTAL_CODE");?>
								</address>
							</div><!-- /.col -->
							
						
							
							<div class="col-sm-3 invoice-col " >
							   <strong>Banking Details:</strong>
								<address>

								<?php
										$banking_details_c 		= mysql_num_rows(mysql_query("select vendor_master_slave.RANDOMID, vendor_master_slave.SLAVEID, vendor_master_slave.NAME, vendor_master_slave.ADDRESS, vendor_master_slave.ACCOUNTNO, vendor_master_slave.IBAN_NO, vendor_master_slave.IBAN_REMARKS, vendor_master_slave.BANK_NAME, vendor_master_slave.BANK_ADDRESS, vendor_master_slave.SWIFT_CODE, vendor_master_slave.US_CORRES_BANK from vendor_master_slave inner join vendor_master on vendor_master.VENDORID=vendor_master_slave.VENDORID where vendor_master.CODE='".$vendorid."'"));


										if($banking_details_c == 0){
											$vendor_id=mysql_fetch_assoc(mysql_query("SELECT * FROM vendor_master WHERE  CODE ='".$vendorid."' "))['VENDORID'];
											?>
												<span id="selBankingID" style="display:none;">
													<a href="updatevendor.php?id=<?=$vendor_id?>"><button class="btn btn-warning btn-flat" type="button">Create Banking Details </button></a>
												</span>

										<?php
										}else{
											
											?>
											<select name="selBankingID" class="select form-control" id="selBankingID"  style="display:none;">
											<?php 
											
												$obj->getBankingDetailsDataWithJsonVendor($vendorid,$rows_rep['VENDOR_SLAVEID']);
											
											?>
											</select>
											<?php
										}

										
								?>

									
									<select name="selBankingID1" class="select form-control" style="display:none;" id="selBankingID1">
									<?php $obj->getBankingDetails();?>
									</select>
									<script>$('#selBankingID1').val('<?php echo $rows_rep['BANKINGDETAILID'];?>');</script>
								</address>
							</div><!-- /.col -->
                            
							<div class="col-sm-3 invoice-col">
								<strong>Hire Details :</strong>
								<address>
								    Nom ID :- <?php echo $obj->getCompareTableData($comid,"MESSAGE");?><br/>
                                    Vessel :- <?php echo $obj->getVesselIMOData($obj->getCompareEstimateData($comid,"VESSEL_IMO_ID"),"VESSEL_NAME");?><br/>
                                    CP Date :- <?php echo date("d-m-Y",strtotime($obj->getFun240()));?><br/>
									TC No. :- <?php echo $obj->getFun229();?><br/>
                                    Loading Port :- <?php echo $lp_name;?><br/>
                                    Discharging Port :- <?php echo $dp_name;?>
								</address>
							</div><!-- /.col -->
						</div>
						<br/>
						<div class="row invoice-info">
						   <div class="col-sm-4 invoice-col">
                               <div class="table-responsive">
                                    <table class="table" >
                                        <tbody>
                                        <tr>
                                            <th width="47%" style="width:50%;padding-top:15px;padding-bottom:15px;">Statement Type :</th>
                                            <td width="53%"><select  name="selIType" class="select form-control" id="selIType" onChange="getDatesFinal();"><?php $obj->getInvoiceType();?></select></td>
                                        </tr>
                                        <script>$("#selIType").val('<?php echo $rows_rep['INVOICE_TYPE'];?>');</script>
                                        
                                        <tr>
                                            <th style="padding-top:15px;padding-bottom:15px;">Hire Statement Number    :</th>
                                            <td><input type="text" name="txtInvNo" id="txtInvNo" class="form-control"  placeholder="Hire Number" autocomplete="off" value="<?php echo $rows['INVOICE_NO'] == ''?$obj->getFun229():$rows['INVOICE_NO'];?>"/></td>
                                        </tr>
                                        <?php
										$invdate = date('d-m-Y',strtotime($rows_rep['INVOICE_DATE']));
										if($invdate=='01-01-1970'){$invdate = '';}
										$duedate = date('d-m-Y',strtotime($rows_rep['DUE_DATE']));
										if($duedate=='01-01-1970'){$duedate = '';}
										$exchangeDate = date('d-m-Y',strtotime($rows_rep['EXCHANGE_DATE']));
										if($exchangeDate=='01-01-1970'){$exchangeDate = '';}
										?>
                                        <tr>
                                            <th style="padding-top:15px;padding-bottom:15px;">Hire Statement Date :</th>
                                            <td><input type="text" name="txtInvDate" id="txtInvDate" class="form-control datepicker"  placeholder="dd-mm-yyyy" autocomplete="off" value="<?php echo $invdate;?>"/></td>
                                        </tr>
                                        
                                        <tr>
                                            <th style="padding-top:15px;padding-bottom:15px;">Exchange Rate :</th>
                                            <td><input type="text" name="txtExchangeRate" id="txtExchangeRate" class="form-control numeric"  placeholder="Exchange Rate" autocomplete="off" value="<?php echo $rows_rep['EXCHANGE_RATE'];?>"/></td>
                                        </tr>
                                        <tr>
                                            <th style="padding-top:15px;padding-bottom:15px;">Exchange Date :</th>
                                            <td><input type="text" name="txtExchangeDate" id="txtExchangeDate" class="form-control datepicker"  placeholder="dd-mm-yyyy" autocomplete="off" value="<?php echo $exchangeDate;?>"/></td>
                                        </tr>
                                        <tr>
                                            <th style="width:50%;padding-top:15px;padding-bottom:15px;">Exchange To Currency :</th>
                                            <td><select  name="selExchangeCurrency" class="select form-control" id="selExchangeCurrency"><?php $obj->getCurrencyList();?></select></td>
                                        </tr>
                                        <script>$("#selExchangeCurrency").val('<?php echo $rows_rep['CURRENCY'];?>');</script>
                                        <tr>
                                            <th style="width:50%;padding-top:15px;padding-bottom:15px;">Remaining Days to Statement :</th>
                                            <td><input type="text" name="txtRemainingDays" id="txtRemainingDays" class="form-control" readonly style="background-color:#eee;"  placeholder="Remaining Days to Statement" autocomplete="off" value=""/></td>
                                        </tr>
                                        <tr>
                                            <th style="padding-top:15px;padding-bottom:15px;">Payment Terms :</th>
                                            <td><input type="text" name="txtPaymentTerms" id="txtPaymentTerms" class="form-control"  placeholder="Payment Terms" autocomplete="off" value="<?php echo $rows_rep['PAYMENT_TERMS'];?>"/></td>
                                        </tr>
                                        <tr>
                                            <th style="padding-top:15px;padding-bottom:15px;">Description :</th>
                                            <td><textarea name="txtDesc" id="txtDesc" class="form-control autosize" rows="3" placeholder="Description"><?php echo $rows_rep['DESCRIPTION'];?></textarea></td>
                                        </tr>
										<?php if($obj->getFun245()=='0000-00-00 00:00:00' || $obj->getFun245()=='1970-01-01 08:00:00'){$offfrom = '';}else{$offfrom = date('d-m-Y H:i',strtotime($obj->getFun245()));}?>
                                        <?php if($obj->getFun246()=='0000-00-00 00:00:00' || $obj->getFun246()=='1970-01-01 08:00:00'){$offto = '';}else{$offto = date('d-m-Y H:i',strtotime($obj->getFun246()));}?>
										<tr>
                                            <th style="padding-top:15px;padding-bottom:15px;">Delivery Port/Date :</th>
                                            <td><?=$obj->getFun247();?> / <?php echo $offfrom;?></td>
                                        </tr>
										
										<tr>
                                            <th style="padding-top:15px;padding-bottom:15px;">Re Delivery Port/Date :</th>
                                            <td><?=$obj->getFun248();?> / <?php echo $offto;?></td>
                                        </tr>
                                        
                                     </tbody>
                                     <tbody>
									    <tr>
											<td><strong>Documents</strong></td>
											<td>
											<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[]" id="attach_file" title="" data-widget="Attachment" data-toggle="tooltip" data-original-title="Attachment"/>
											</div>
											<br/>
											<?php if($rows_rep['UPLOAD'] != '')
											{ 
												$file = explode(",",$rows_rep['UPLOAD']); 
												$name = explode(",",$rows_rep['UPLOAD_NAME']); ?>	
											   <?php
												$j =1;
												for($i=0;$i<sizeof($file);$i++)
												{
												?>
												<tr id="row_file_<?php echo $j;?>">
													<td width="40%" align="left" valign="top"><a href="../../attachment/<?php echo $file[$i]; ?>" 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[$i];?></a>
													<input type="hidden" name="file_<?php echo $j;?>" id="file_<?php echo $j;?>" value="<?php echo $file[$i]; ?>" />
													<input type="hidden" name="name_<?php echo $j;?>" id="name_<?php echo $j;?>" value="<?php echo $name[$i]; ?>" />
													</td>
													<td ><a href="#1" onClick="Del_Upload(<?php echo $j;?>);"><i class="fa fa-times " style="color:red;"></i></a></td>
												</tr>
											   <?php $j++;}?>
									   <?php }?>
											</td>
										</tr>
									 </tbody>
                                   </table>
                               </div>
						   </div><!-- /.col -->
						   <div class="col-sm-8 invoice-col">
							   <div class="table-responsive">
                                    <table class="table">
                                        <tbody>
										<tr>
                                            <th style="padding-top:15px;padding-bottom:15px;" colspan="3">Final Hire-age(<?php echo $currency;?>):</th>
                                            <td width="30%"><input type="text" name="txtFinalHireage" id="txtFinalHireage" class="form-control" readonly style="background-color:#eee;"  placeholder="Hire Days" autocomplete="off" value="<?php echo $obj->getFun236();?>"/>
                                        </tr>
                                        <tr>
                                            <th style="padding-top:15px;padding-bottom:15px;" colspan="3">Total Voyage Days(Sea & Port):</th>
                                            <td width="30%"><input type="text" name="txtEstHireDays" id="txtEstHireDays" class="form-control" readonly style="background-color:#eee;"  placeholder="Hire Days" autocomplete="off" value="<?php echo $obj->getFun239();?>"/>
                                        </tr>
                                        
                                        <tr>
										<td colspan="4">
										<table width="100%">
										<thead>
										<tr>
                                            <th>TTL days</th>
											<th>Bal Days</th>
											<th>Hire(USD/Day)</th>
											<th width="16%">Hire From</th>
											<th width="16%">Hire To</th>
											<th>Hire Day</th>
                                            <td><strong>Hire(USD)</strong></td>
                                        </tr>
										</thead>
										<?php $hirearray_cell = array();
							        $sql_2 = "select * from freight_cost_estimete_slave17 where FCAID='".$id."' ";	

									// echo '<h1>'.$sql_2;
									$validateHireTo='';
									$result_2 = mysql_query($sql_2);$i = 0;
									$num_2 = mysql_num_rows($result_2);
									while($rows_2 = mysql_fetch_assoc($result_2))
									{$i++;$hirearray_cell[$rows_2['HIRE_RATE']] = $rows_2['HIRE_RATE'];
									$sql_invslave = "select sum(UTILISED_DAYS) as DAYS from invoice_hire_slave8 inner join invoice_hire_master on invoice_hire_master.INVOICEID=invoice_hire_slave8.INVOICEID where invoice_hire_master.COMID='".$comid."' and MODULEID='".$_SESSION['moduleid']."' and MCOMPANYID='".$_SESSION['company']."' and STATUS=5 and invoice_hire_slave8.RANDOMID='".$rows_2['RANDOMID']."'";
									$res_invslave = mysql_query($sql_invslave);
									$result_invslave = mysql_fetch_assoc($res_invslave);
									
									$validateHireTo = $rows_2['HIRE_TO'];

									$sql_invslave1 = "select invoice_hire_slave8.UTILISED_DAYS, invoice_hire_slave8.HIRE_AMT, invoice_hire_slave8.HIRE_FROM, invoice_hire_slave8.HIRE_TO from invoice_hire_slave8 inner join invoice_hire_master on invoice_hire_master.INVOICEID=invoice_hire_slave8.INVOICEID where invoice_hire_master.COMID='".$comid."' and MODULEID='".$_SESSION['moduleid']."' and MCOMPANYID='".$_SESSION['company']."' and STATUS<5 and invoice_hire_slave8.RANDOMID='".$rows_2['RANDOMID']."'";
									$res_invslave1 = mysql_query($sql_invslave1);
									$result_invslave1 = mysql_fetch_assoc($res_invslave1);
									?>
                                        <tr>
                                            <td>
											<input type="text" name="txtTotalDay_<?=$i?>" id="txtTotalDay_<?=$i?>" class="form-control"  readonly style="background-color:#eee;" placeholder="Daily Hire(USD/Day)" autocomplete="off" value="<?php echo $rows_2['HIRE_DAYS'];?>"/><input type="hidden" name="txtTotalInvoicedDay_<?=$i?>" id="txtTotalInvoicedDay_<?=$i?>" value="<?php echo $result_invslave['DAYS'];?>"/></td>
											<td><input type="text" name="txtRemainingDay_<?=$i?>" id="txtRemainingDay_<?=$i?>" class="form-control"  readonly style="background-color:#eee;" placeholder="Daily Hire(USD/Day)" autocomplete="off" value="<?php echo number_format($rows_2['HIRE_DAYS'],5,'.',',');?>"/></td>
											<td><input type="text" name="txtHireperDay_<?=$i?>" id="txtHireperDay_<?=$i?>" class="form-control"  readonly style="background-color:#eee;" placeholder="Daily Hire(USD/Day)" autocomplete="off" value="<?php echo $rows_2['HIRE_RATE'];?>"/></td>
											<?php
											$txtHireFrom = date('d-m-Y H:i',strtotime($result_invslave1['HIRE_FROM']));
											if($txtHireFrom=='01-01-1970 00:00' || $txtHireFrom=='01-01-1970 08:00' || $txtHireFrom=='01-01-1970 01:00'){$txtHireFrom = '';}
											$txtHireTo = date('d-m-Y H:i',strtotime($result_invslave1['HIRE_TO']));
											if($txtHireTo=='01-01-1970 00:00' || $txtHireTo=='01-01-1970 08:00' || $txtHireTo=='01-01-1970 01:00'){$txtHireTo = '';}
											
											if($rec==0)
										    {$txtHireFrom = date('d-m-Y H:i',strtotime($rows_2['HIRE_FROM']));}
											?>
											<td><input type="text" name="txtHireFrom_<?=$i?>" id="txtHireFrom_<?=$i?>" class="form-control" onKeyUp="getFullClaculation();"  placeholder="dd-mm-yyyy hh:mm" autocomplete="off" value="<?php echo $txtHireFrom;?>"/></td>
                                            <td><input type="text" name="txtHireTo_<?=$i?>" id="txtHireTo_<?=$i?>" class="form-control" onKeyUp="getFullClaculation();" placeholder="dd-mm-yyyy hh:mm" autocomplete="off" value="<?php echo $txtHireTo;?>"/></td>
											<td><input type="text" name="txtInvDay_<?=$i?>" id="txtInvDay_<?=$i?>" class="form-control numeric" placeholder="0.00" autocomplete="off" value="<?php echo $result_invslave1['UTILISED_DAYS'];?>" readonly="true"/></td>
                                            
											<td><input type="text" name="txtInvHire_<?=$i?>" id="txtInvHire_<?=$i?>" class="form-control" readonly style="background-color:#eee;"  placeholder="Total Hire" autocomplete="off" value="<?php echo $result_invslave1['HIRE_AMT'];?>"/><input type="hidden" name="txtRandom_<?=$i?>" id="txtRandom_<?=$i?>" value="<?php echo $rows_2['RANDOMID'];?>"/></td>
                                        </tr>
								<?php }?>
								<input type = "hidden" value="<?= date('d-m-Y H:i',strtotime($validateHireTo));?>" name="validateHireToDate" id="validateHireToDate">  
								       </table>
									     </td>
                                        </tr>
                                        
                                        <tr>
                                            <th style="padding-top:15px;padding-bottom:15px;" colspan="3">Gross Hire for this Invoice :</th>
                                            <td><input type="text" name="txtTotalHire" id="txtTotalHire" class="form-control" readonly style="background-color:#eee;"  placeholder="Total Hire" autocomplete="off" value="<?php echo $rows_rep['HIRE_INV_AMT'];?>"/><input type="hidden" name="totalDaysTows" id="totalDaysTows" value="<?=$i?>"/></td>
                                        </tr>
                                        


										<tr>
                                            <th style="width:50%;padding-top:15px;padding-bottom:15px;" colspan="3">Add Adjustment</th>
                                        </tr>
										<td colspan="4">
										<table width="100%">
										<thead>
										<tr>
											<th></th>
                                            <th>Cost type</th>
											<th>Fixture no</th>
											<th>Vessel</th>
											<th width="16%">Description</th>
											<th width="16%">Amount</th>
									
									
                                        </tr>
										</thead>


										
										<?php $sql2 = "select * from invoice_hire_adj where INVOICEID='".$rows_rep['INVOICEID']."' and IDENTIFY='ADD'";

									//  ECHO '<H1>'.$sql2;
										$res2 = mysql_query($sql2);
										$num211 = mysql_num_rows($res2);
										if($num211 >0){$num2111 = $num211;}else{$num2111 = 1;}
										?>
									<tbody id="tblAddADJ">
									<?php if($num211 >0)
										{$i = 0;
										while($rows2 = mysql_fetch_assoc($res2))
										{$i++;

											// print_r($rows2);
										?>



										<tr id="addadj_Row_<?php echo $i;?>">
										<td align="center"><a href="#pr<?= $i?>" onClick="removeAddAdjRow(<?= $i?>);"><i class="fa fa-times" style="color:red;"></i></a></td>

                                            <td>
											<select class="form-control" name="txtCORCIDFORADDADJ_<?= $i?>" id="txtCORCIDFORADDADJ_<?= $i?>" style="width:100px;">
                                   			     <?php $obj->getOwnerRelatedCostListForTallyInvoice($rows2['ORC_ID']);?>
                                      			  </select></td>
											<td><select class="form-control" name="txtFixNoForADDADJ_<?= $i?>" id="txtFixNoForADDADJ_<?= $i?>" style="width:100px;" onchange="getVessel(this)">
                                   			     <?php $obj->getFixtureNoForTallyInvoice($rows2['FIXTURE_NO']);?>
                                      			  </select></td>
											<td><select class="form-control check" name="txtVesselFORADDADJ_<?= $i?>" id="txtVesselFORADDADJ_<?= $i?>" data-check="io" style="width:100px;" readonly>

											<?php $obj->getVesselNameForTally($rows2['VESSEL']);?>
											
                                      			  </select></td>
											
											<td><textarea class="form-control areasize" name="txtAddDesADJ_<?= $i?>" id="txtAddDesADJ_<?= $i?>" rows="2" placeholder="Description..."><?= $rows2['DESCRIPTION']?></textarea></td>
                                            <td><input type="text" name="txtAddADJAmt_<?= $i?>" id="txtAddADJAmt_<?= $i?>" class="form-control numeric"  placeholder="Amount" autocomplete="off" value="<?= $rows2['AMOUNT']?>" onKeyUp="getFullClaculation();"/></td>
												
										
                                        </tr>












											<?php }}else{?>
                                        <tr id="addadj_Row_1">

										<td align="center"><a href="#pr1" onClick="removeAddAdjRow(1);"><i class="fa fa-times" style="color:red;"></i></a></td>
                                            <td >
											<select class="form-control" name="txtCORCIDFORADDADJ_1" id="txtCORCIDFORADDADJ_1" style="width:100px;">
                                   			     <?php $obj->getOwnerRelatedCostListForTallyInvoice();?>
                                      			  </select></td>
											<td><select class="form-control" name="txtFixNoForADDADJ_1" id="txtFixNoForADDADJ_1" style="width:100px;" onchange="getVessel(this)">
                                   			     <?php $obj->getFixtureNoForTallyInvoice();?>
                                      			  </select></td>
											<td id="checForCheck"><select class="form-control check" name="txtVesselFORADDADJ_1" id="txtVesselFORADDADJ_1" style="width:100px;" readonly>
                                   			  
                                      			  </select></td>
											
											<td><textarea class="form-control areasize" name="txtAddDesADJ_1" id="txtAddDesADJ_1" rows="2" placeholder="Description..."></textarea></td>
                                            <td><input type="text" name="txtAddADJAmt_1" id="txtAddADJAmt_1" class="form-control numeric"  placeholder="Amount" autocomplete="off" value="" onKeyUp="getFullClaculation();"/></td>
												
										
                                        </tr>

							
										<?php }?>
										</tbody>

								       </table>
									     </td>
                                        </tr>
												<tbody>
										<tr>
                                               <td align="left" colspan="3"><button type="button" class="btn btn-primary btn-flat" onClick="AddNewAddADJRow();">Add</button><input type="hidden" name="txtAddADJID" id="txtAddADJID" value="<?php echo $num2111;?>"/></td>
                                           </tr>
                                        <tr>
                                            <th style="padding-top:15px;padding-bottom:15px;" colspan="4">Other Add</th>
                                        </tr>
                                       
										   <tr>
                                               <th align="left" colspan="3"><input name="ChkBallastBonus" class="checkbox" id="ChkBallastBonus" type="checkbox" value="1" <?php if($rows_rep['CHK_BALLAST_BONUS']==1){echo 'checked';}?>/>&nbsp;&nbsp;Ballast Bonus(<?php echo $currency;?>)</th>
                                               <?php if($rows_rep['CHK_BALLAST_BONUS']==1){$ballastdisplay = '';}else{$ballastdisplay = 'none';}?>
                                               <td><span id="spanBallastBonus" style="display:<?php echo $ballastdisplay;?>"><input type="text" name="txtBallastBonus" id="txtBallastBonus" class="form-control"  placeholder="0.00" readonly autocomplete="off" value="<?php echo $obj->getFun145();?>"/></span></td>
                                            </tr>
										
                                        <tr>
                                            <td colspan="2" style="font-size:13px;"><strong>&nbsp;&nbsp;&nbsp;<i>CVE(<?php echo $currency;?>)</strong></i></td>
                                            <td width="25%"><input type="text" name="txtCVEMonth" id="txtCVEMonth" class="form-control numeric"  placeholder="CVE" autocomplete="off" value="<?php echo $obj->getFun231();?>" onKeyUp="getFullClaculation();" readonly="true"/></td>
                                            <td><input type="text" name="txtCVE_Amt" id="txtCVE_Amt" class="form-control numeric" readonly  placeholder="CVE Amount" autocomplete="off" value="<?php echo $rows_rep['CVE_AMT'];?>"/></td>
                                        </tr>
										
                                     </tbody>
                                     <?php 
									    if($rec>0)
										{
											$sql2 = "select * from invoice_hire_slave1 where INVOICEID='".$rows_rep['INVOICEID']."' and IDENTIFY='ADD'";
										}else{
										    $sql2 = "select * from invoice_hire_slave1 where INVOICEID='".$previnvoiceid."' and IDENTIFY='ADD'";
										}
										   $res2 = mysql_query($sql2);
										   $num2 = mysql_num_rows($res2);
										   if($num2 >0){$num21 = $num2;}else{$num21 = 1;}
									       ?>
                                      <tbody id="tblAdd">
                                  <?php if($num2 >0)
									    {$i = 0;
										  while($rows2 = mysql_fetch_assoc($res2))
										  {$i++;
										  ?>
										    <tr id="add_Row_<?php echo $i;?>">
										  	    <td width="25%" align="center"><a href="#pr<?php echo $i;?>" onClick="removeAddRow(<?php echo $i;?>);"><i class="fa fa-times" style="color:red;"></i></a>

												  <select class="form-control" name="txtCORCIDFOROTHERADD_<?php echo $i;?>" id="txtCORCIDFOROTHERADD_<?php echo $i;?>" style="width:100px;">
												<?php $obj->getOwnerRelatedCostListForTallyInvoice($rows2['ORC_ID']);?>
												</select>


											
											</td>
										     	<td colspan="2"><textarea class="form-control areasize" name="txtAddDes_<?php echo $i;?>" id="txtAddDes_<?php echo $i;?>" rows="2" placeholder="Description..."><?php echo $rows2['DESCRIPTION'];?></textarea></td>
										   	    <td><input type="text" name="txtAddDesAmt_<?php echo $i;?>" id="txtAddDesAmt_<?php echo $i;?>" class="form-control numeric"  placeholder="Amount" autocomplete="off" value="<?php echo $rows2['AMOUNT'];?>" onKeyUp="getFullClaculation();"/></td>
										    </tr>
											
										<?php }}else{?>
										   <tr id="add_Row_1">

										  
										       <td align="center"><a href="#pr1" onClick="removeAddRow(1);"><i class="fa fa-times" style="color:red;"></i></a>
											   <select class="form-control" name="txtCORCIDFOROTHERADD_1" id="txtCORCIDFOROTHERADD_1" style="width:100px;">
												<?php $obj->getOwnerRelatedCostListForTallyInvoice();?>
												</select>
											</td>
										       <td colspan="2"><textarea class="form-control areasize" name="txtAddDes_1" id="txtAddDes_1" rows="2" placeholder="Description..."></textarea></td>
										       <td><input type="text" name="txtAddDesAmt_1" id="txtAddDesAmt_1" class="form-control numeric"  placeholder="Amount" autocomplete="off" value="" onKeyUp="getFullClaculation();"/></td>
										   </tr>
								   <?php }?>
                                       </tbody>
                                       <tbody>
                                           <tr>
                                               <td align="left" colspan="4"><button type="button" class="btn btn-primary btn-flat" onClick="AddNewAddRow();">Add</button><input type="hidden" name="txtAddID" id="txtAddID" value="<?php echo $num21;?>"/></td>
                                           </tr>

										</tbody>


										   <tr>
                                            <th style="width:50%;padding-top:15px;padding-bottom:15px;" colspan="3">Less Adjustment</th>
                                        </tr>
										<td colspan="4">
										<table width="100%">
										<thead>
										<tr>
											<th></th>
                                            <th>Cost type</th>
											<th>Fixture no</th>
											<th>Vessel</th>
											<th width="16%">Description</th>
											<th width="16%">Amount</th>
									
									
                                        </tr>
										</thead>


										
									<?php $sql2 = "select * from invoice_hire_adj where INVOICEID='".$rows_rep['INVOICEID']."' and IDENTIFY='SUB'";

									//  ECHO '<H1>'.$sql2;
										$res2 = mysql_query($sql2);
										$num2 = mysql_num_rows($res2);
										if($num2 >0){$num21 = $num2;}else{$num21 = 1;}
										?>
									<tbody id="tblLessADJ">
									<?php if($num2 >0)
										{$i = 0;
										while($rows2 = mysql_fetch_assoc($res2))
										{$i++;

											// print_r($rows2);
										?>



										<tr id="lessadj_Row_<?php echo $i;?>">
										<td align="center"><a href="#pr<?= $i?>" onClick="removeLessAdjRow(<?= $i?>);"><i class="fa fa-times" style="color:red;"></i></a></td>

                                            <td>
											<select class="form-control" name="txtCORCIDFORLESSADJ_<?= $i?>" id="txtCORCIDFORLESSADJ_<?= $i?>" style="width:100px;">
                                   			     <?php $obj->getOwnerRelatedCostListForTallyInvoice($rows2['ORC_ID']);?>
                                      			  </select></td>
											<td><select class="form-control" name="txtFixNoForLESSADJ_<?= $i?>" id="txtFixNoForLESSADJ_<?= $i?>" style="width:100px;"onchange="getVessel(this)" >
                                   			     <?php $obj->getFixtureNoForTallyInvoice($rows2['FIXTURE_NO']);?>
                                      			  </select></td>
											<td><select class="form-control check" name="txtVesselFORLESSADJ_<?= $i?>" id="txtVesselFORLESSADJ_<?= $i?>" style="width:100px;" readonly>
                                   			       <?php $obj->getVesselNameForTally($rows2['VESSEL']);?>
                                      			  </select></td>
											
											<td><textarea class="form-control areasize" name="txtLessDesADJ_<?= $i?>" id="txtLessDesADJ_<?= $i?>" rows="2" placeholder="Description..."><?= $rows2['DESCRIPTION']?></textarea></td>
                                            <td><input type="text" name="txtLessADJAmt_<?= $i?>" id="txtLessADJAmt_<?= $i?>" class="form-control numeric"  placeholder="Amount" autocomplete="off" value="<?= $rows2['AMOUNT']?>" onKeyUp="getFullClaculation();"/></td>
												
										
                                        </tr>
											<?php }}else{?>
                                        <tr id="lessadj_Row_1">

										<td align="center"><a href="#pr1" onClick="removeLessAdjRow(1);"><i class="fa fa-times" style="color:red;"></i></a></td>
                                            <td >
											<select class="form-control" name="txtCORCIDFORLESSADJ_1" id="txtCORCIDFORLESSADJ_1" style="width:100px;">
                                   			     <?php $obj->getOwnerRelatedCostListForTallyInvoice();?>
                                      			  </select></td>
											<td><select class="form-control" name="txtFixNoForLESSADJ_1" id="txtFixNoForLESSADJ_1" style="width:100px;" onchange="getVessel(this)">
                                   			     <?php $obj->getFixtureNoForTallyInvoice();?>
                                      			  </select></td>
											<td><select class="form-control check"  name="txtVesselFORLESSADJ_1" id="txtVesselFORLESSADJ_1" style="width:100px;" readonly>
                                   			   
                                      			  </select></td>
											
											<td><textarea class="form-control areasize" name="txtLessDesADJ_1" id="txtLessDesADJ_1" rows="2" placeholder="Description..."></textarea></td>
                                            <td><input type="text" name="txtLessADJAmt_1" id="txtLessADJAmt_1" class="form-control numeric"  placeholder="Amount" autocomplete="off" value="" onKeyUp="getFullClaculation();"/></td>
												
										
                                        </tr>

							
										<?php }?>
										</tbody>

								       </table>
									     </td>
                                        </tr>

										<tbody>

										<tr>
                                               <td align="left" colspan="3"><button type="button" class="btn btn-primary btn-flat" onClick="AddNewLESSADJRow();">Add</button><input type="hidden" name="txtLESSADJID" id="txtLESSADJID" value="<?php echo $num21;?>"/></td>
                                           </tr>
											</tbody>



                                           <tr>
                                               <th style="padding-top:15px;padding-bottom:15px;" colspan="4">Other Less</th>
                                           </tr>
										   
                                           <tr>
                                               <td colspan="2" style="font-size:13px;"><strong>&nbsp;&nbsp;&nbsp;<i>Address Commission(%)</i></strong></td>
                                               <td><input type="text" name="txtAddrCommPer" id="txtAddrCommPer" class="form-control numeric"  placeholder="Address Commission" autocomplete="off" value="<?php echo $obj->getFun129();?>" onKeyUp="getFullClaculation();" readonly="true"/></td>
                                               <td><input type="text" name="txtAddrCommAmt" id="txtAddrCommAmt" class="form-control numeric" readonly  placeholder="Amount" autocomplete="off" value="<?php echo $rows_rep['ADD_COMM_AMT'];?>"/></td>
                                           </tr>
                                           <tr>
                                               <td colspan="2" style="font-size:13px;"><strong>&nbsp;&nbsp;&nbsp;<i>Broker Commission(%)</i></strong></td>
                                               <td><input type="text" name="txtBroCommPer" id="txtBroCommPer" class="form-control numeric"  placeholder="Broker Commission" autocomplete="off" value="<?php echo $obj->getFun237();?>" onKeyUp="getFullClaculation();" readonly="true"/></td>
                                               <td><input type="text" name="txtBroCommAmt" id="txtBroCommAmt" class="form-control numeric" readonly  placeholder="Amount" autocomplete="off" value="<?php echo $rows_rep['BRO_COMM_AMT'];?>"/></td>
                                           </tr>
                                      <?php 
										if($rec>0)
										{
											$sql2 = "select * from invoice_hire_slave1 where INVOICEID='".$rows_rep['INVOICEID']."' and IDENTIFY='SUB'";
										}else{
										    $sql2 = "select * from invoice_hire_slave1 where INVOICEID='".$previnvoiceid."' and IDENTIFY='SUB'";
										}
											$res2 = mysql_query($sql2);
											$num2 = mysql_num_rows($res2);
											if($num2 >0){$num21 = $num2;}else{$num21 = 1;}?>
                                       </tbody>
                                       <tbody id="tblSub">
                                     <?php if($num2 >0)
										   {$i = 0;
											while($rows2 = mysql_fetch_assoc($res2))
											{$i++;
											?>
											<tr id="Sub_Row_<?php echo $i;?>">
											   <td align="center"><a href="#pr<?php echo $i;?>" onClick="removeSubRow(<?php echo $i;?>);"><i class="fa fa-times" style="color:red;"></i></a>
												
											   <select class="form-control" name="txtCORCIDFOROTHERLESS_<?php echo $i;?>" id="txtCORCIDFOROTHERLESS_<?php echo $i;?>" style="width:100px;">
										<?php $obj->getOwnerRelatedCostListForTallyInvoice($rows2['ORC_ID']);?>
										</select>

											
											</td>
											   <td colspan="2"><textarea class="form-control areasize" name="txtSubDes_<?php echo $i;?>" id="txtSubDes_<?php echo $i;?>" rows="2" placeholder="Description..."><?php echo $rows2['DESCRIPTION'];?></textarea></td>
											   <td><input type="text" name="txtSubDesAmt_<?php echo $i;?>" id="txtSubDesAmt_<?php echo $i;?>" class="form-control numeric"  placeholder="Amount" autocomplete="off" value="<?php echo $rows2['AMOUNT'];?>" onKeyUp="getFullClaculation();"/></td>
											</tr>
											<?php }}else{?>
											<tr id="Sub_Row_1">
											   <td align="center"><a href="#pr1" onClick="removeSubRow(1);"><i class="fa fa-times" style="color:red;"></i></a>
												
											   <select class="form-control" name="txtCORCIDFOROTHERLESS_1" id="txtCORCIDFOROTHERLESS_1" style="width:100px;">
										<?php $obj->getOwnerRelatedCostListForTallyInvoice();?>
										</select>

											</td>
											   <td colspan="2"><textarea class="form-control areasize" name="txtSubDes_1" id="txtSubDes_1" rows="2" placeholder="Description..."></textarea></td>
											   <td><input type="text" name="txtSubDesAmt_1" id="txtSubDesAmt_1" class="form-control numeric"  placeholder="Amount" autocomplete="off" value="" onKeyUp="getFullClaculation();"/></td>
											</tr>
									<?php }?>
                                       </tbody>
                                       <tbody>
                                           <tr>
                                               <td align="left" colspan="4"><button type="button" class="btn btn-primary btn-flat" onClick="SubNewSubRow();">Add</button><input type="hidden" name="txtSubID" id="txtSubID" value="<?php echo $num21;?>"/></td>
                                           </tr>
										   
                                            
											<tr>
                                               <th align="left" colspan="4"><input name="ChkDeliveryBunker" class="checkbox" id="ChkDeliveryBunker" type="checkbox" value="1" <?php if($rows_rep['CHK_DELIVERY']==1){echo 'checked';}?> />&nbsp;&nbsp;Delivery Bunkers</th>
                                            </tr>
											<?php if($rows_rep['CHK_DELIVERY']==1){$deliverydisplay = '';}else{$deliverydisplay = 'none';}?>
                                            <tr id="DivBunkerDelivery_0" style="display:<?php echo $deliverydisplay;?>;">
                                            <td>Bunker Grade</td>
                                            <td>Qty(MT)</td>
                                            <td>Price(<?php echo $currency;?>)</td>
                                            <td>Amount(<?php echo $currency;?>)</td>
                                            </tr>
                                            <tbody id="bunkerDeliverybody">
									<?php   
										if($rec==0 && $previnvoiceid=='')
										{
											$sqltc4 = "SELECT BUNKERID, AMOUNT, QTY, PRICE, IDENTITY from freight_cost_estimete_slave13 where FCAID='".$id."' and IDENTITY='DEL'";
											$restc4 	= mysql_query($sqltc4);
											$rectc4 	= mysql_num_rows($restc4);$del = 0;
											while($rows4 = mysql_fetch_assoc($restc4))
											{$del++;?>
											<tr id="DivBunkerDelivery_<?php echo $del;?>" style="display:<?php echo $deliverydisplay;?>;">
                                            <td><select name="selDELBunker_<?php echo $del;?>" id="selDELBunker_<?php echo $del;?>" class="select form-control" onChange="getFullClaculation();"><?php $obj->getBunkerList();?></select></td>
                                            <td><input type="text" name="txtDelBunkerQty_<?php echo $del;?>" id="txtDelBunkerQty_<?php echo $del;?>" onKeyUp="getFullClaculation();" class="form-control numeric"  placeholder="0.00" autocomplete="off" value="<?php echo $rows4['QTY'];?>"/></td>
                                            <td><input type="text" name="txtDelBunkerPrice_<?php echo $del;?>" id="txtDelBunkerPrice_<?php echo $del;?>" onKeyUp="getFullClaculation();" class="form-control numeric"  placeholder="0.00" autocomplete="off" value="<?php echo $rows4['PRICE'];?>"/></td>
                                            <td><input type="text" name="txtDelBunkerAmt_<?php echo $del;?>" id="txtDelBunkerAmt_<?php echo $del;?>" class="form-control"  placeholder="0.00" readonly autocomplete="off" value="<?php echo $rows4['AMOUNT'];?>"/></td>
										    </tr>
                                            <script>$("#selDELBunker_<?php echo $del;?>").val(<?php echo $rows4['BUNKERID'];?>);</script>  
									<?php   }
										}else{
										    if($rec>0)
										    {
                                            	$sql_inv2 = "select * from invoice_hire_slave2 where INVOICEID='".$rows_rep['INVOICEID']."' and IDENTIFY='DEL'";
											}
											else
											{
											    $sql_inv2 = "select * from invoice_hire_slave2 where INVOICEID='".$previnvoiceid."' and IDENTIFY='DEL'"; 
											} 
											$res_inv2 = mysql_query($sql_inv2);
											$num_inv2 = mysql_num_rows($res_inv2);	
											$del = 0;
											while($rows_inv2 = mysql_fetch_assoc($res_inv2))
											{$del++;
											?>
                                            <tr id="DivBunkerDelivery_<?php echo $del;?>" style="display:<?php echo $deliverydisplay;?>;">
                                            <td><select name="selDELBunker_<?php echo $del;?>" id="selDELBunker_<?php echo $del;?>" class="select form-control" onChange="getFullClaculation();"><?php $obj->getBunkerList();?></select></td>
                                            <td><input type="text" name="txtDelBunkerQty_<?php echo $del;?>" id="txtDelBunkerQty_<?php echo $del;?>" onKeyUp="getFullClaculation();" class="form-control numeric"  placeholder="0.00" autocomplete="off" value="<?php echo $rows_inv2['BUNKER_QTY'];?>"/></td>
                                            <td><input type="text" name="txtDelBunkerPrice_<?php echo $del;?>" id="txtDelBunkerPrice_<?php echo $del;?>" onKeyUp="getFullClaculation();" class="form-control numeric"  placeholder="0.00" autocomplete="off" value="<?php echo $rows_inv2['BUNKER_PRICE'];?>"/></td>
                                            <td><input type="text" name="txtDelBunkerAmt_<?php echo $del;?>" id="txtDelBunkerAmt_<?php echo $del;?>" class="form-control"  placeholder="0.00" readonly autocomplete="off" value="<?php echo $rows_inv2['BUNKER_AMT'];?>"/></td>
										    </tr>
                                            <script>$("#selDELBunker_<?php echo $del;?>").val(<?php echo $rows_inv2['BUNKERID'];?>);</script>  
                                      <?php }?>
								  <?php }?> 
                                            </tbody>   
											<tr style="display:none;">
											   <td align="left" colspan="4"><input type="hidden" name="txtAddDELID" id="txtAddDELID" value="<?php echo $del;?>"/></td>
											</tr>
										<?php if($rows_rep['CHK_REDELIVERY']==1){$redeliverydisplay = '';}else{$redeliverydisplay = 'none';}?>
											<tr>
                                               <th align="left" colspan="4"><input name="ChkReDeliveryBunker" class="checkbox" id="ChkReDeliveryBunker" type="checkbox" value="1" <?php if($rows_rep['CHK_REDELIVERY']==1){echo 'checked';}?> />&nbsp;&nbsp;Re-Delivery Bunkers</th>
                                            </tr>
									        <tr id="DivBunkerReDelivery_0" style="display:<?php echo $redeliverydisplay;?>;">
                                            <td>Bunker Grade</td>
                                            <td>Qty(MT)</td>
                                            <td>Price(<?php echo $currency;?>)</td>
                                            <td>Amount(<?php echo $currency;?>)</td>
                                            </tr>
                                            <tbody id="bunkerReDeliverybody">
									<?php   
										if($rec==0)
										{
											$sqltc4 = "SELECT BUNKERID, AMOUNT, QTY, PRICE, IDENTITY from freight_cost_estimete_slave13 where FCAID='".$id."' and IDENTITY='REDEL'";
											$restc4 	= mysql_query($sqltc4);
											$rectc4 	= mysql_num_rows($restc4);$redel = 0;
											while($rows4 = mysql_fetch_assoc($restc4))
											{$redel++;?>
											<tr id="DivBunkerReDelivery_<?php echo $redel;?>" style="display:<?php echo $redeliverydisplay;?>;">
                                            <td><select name="selReDELBunker_<?php echo $redel;?>" id="selReDELBunker_<?php echo $redel;?>" class="select form-control" onChange="getFullClaculation();"><?php $obj->getBunkerList();?></select></td>
                                            <td><input type="text" name="txtReDelBunkerQty_<?php echo $redel;?>" id="txtReDelBunkerQty_<?php echo $redel;?>" onKeyUp="getFullClaculation();" class="form-control numeric"  placeholder="0.00" autocomplete="off" value="<?php echo $rows4['QTY'];?>"/></td>
                                            <td><input type="text" name="txtReDelBunkerPrice_<?php echo $redel;?>" id="txtReDelBunkerPrice_<?php echo $redel;?>" onKeyUp="getFullClaculation();" class="form-control numeric"  placeholder="0.00" autocomplete="off" value="<?php echo $rows4['PRICE'];?>"/></td>
                                            <td><input type="text" name="txtReDelBunkerAmt_<?php echo $redel;?>" id="txtReDelBunkerAmt_<?php echo $redel;?>" class="form-control"  placeholder="0.00" readonly autocomplete="off" value="<?php echo $rows4['AMOUNT'];?>"/></td>
										    </tr>
                                            <script>$("#selReDELBunker_<?php echo $redel;?>").val(<?php echo $rows4['BUNKERID'];?>);</script>   
									<?php   }
										}else{
										    if($rec>0)
										    {
                                            	$sql_inv2 = "select * from invoice_hire_slave2 where INVOICEID='".$rows_rep['INVOICEID']."' and IDENTIFY='REDEL'";
											}
											else
											{
											    $sql_inv2 = "select * from invoice_hire_slave2 where INVOICEID='".$previnvoiceid."' and IDENTIFY='REDEL'"; 
											} 
											$res_inv2 = mysql_query($sql_inv2);$redel = 0;
											$num_inv2 = mysql_num_rows($res_inv2);	
											while($rows_inv2 = mysql_fetch_assoc($res_inv2))
											{$redel++;
											?>
                                            <tr id="DivBunkerReDelivery_<?php echo $redel;?>" style="display:<?php echo $redeliverydisplay;?>;">
                                            <td><select name="selReDELBunker_<?php echo $redel;?>" id="selReDELBunker_<?php echo $redel;?>" class="select form-control" onChange="getFullClaculation();"><?php $obj->getBunkerList();?></select></td>
                                            <td><input type="text" name="txtReDelBunkerQty_<?php echo $redel;?>" id="txtReDelBunkerQty_<?php echo $redel;?>" onKeyUp="getFullClaculation();" class="form-control numeric"  placeholder="0.00" autocomplete="off" value="<?php echo $rows_inv2['BUNKER_QTY'];?>"/></td>
                                            <td><input type="text" name="txtReDelBunkerPrice_<?php echo $redel;?>" id="txtReDelBunkerPrice_<?php echo $redel;?>" onKeyUp="getFullClaculation();" class="form-control numeric"  placeholder="0.00" autocomplete="off" value="<?php echo $rows_inv2['BUNKER_PRICE'];?>"/></td>
                                            <td><input type="text" name="txtReDelBunkerAmt_<?php echo $redel;?>" id="txtReDelBunkerAmt_<?php echo $redel;?>" class="form-control"  placeholder="0.00" readonly autocomplete="off" value="<?php echo $rows_inv2['BUNKER_AMT'];?>"/></td>
										    </tr>
                                            <script>$("#selReDELBunker_<?php echo $redel;?>").val(<?php echo $rows_inv2['BUNKERID'];?>);</script>  
                                            <?php }
										}?> 
                                            </tbody>   
											<tr style="display:none;">
											   <td align="left" colspan="4"><button type="button" class="btn btn-primary btn-flat" onClick="AddNewREDELRow();">Add</button><input type="hidden" name="txtAddREDELID" id="txtAddREDELID" value="<?php echo $redel;?>"/></td>
											</tr>

											<tr>
                                               <th align="left" colspan="3"><input name="ChkShowOffHire" class="checkbox" id="ChkShowOffHire" type="checkbox" value="1" <?php if($rows_rep['CHK_OFFHIRE']==1){echo 'checked';}?>/>&nbsp;&nbsp;Off-hire(<?php echo $currency;?>)
											   <select style="display:none;" name="hirearraycell" id="hirearraycell">
											   <?php
											   while ($array_cell = each($hirearray_cell)) 
												{
													$value = $array_cell['value'];
													$key = $array_cell['key'];
													echo "<option value='$key'>".$value."</option>";
												}
											   ?>
											   </select>
											   </th>
                                               <?php if($rows_rep['CHK_OFFHIRE']==1){$offhiredisplay = '';}else{$offhiredisplay = 'none';}?>
                                               <td></td>
                                            </tr>
											<?php if($rows_rep['CHK_OFFHIRE']==1){$deliverydisplay = '';}else{$deliverydisplay = 'none';}?>
											<tr>
												<td colspan="4">
												<table class="table" id="offhiretable" style="display:<?php echo $deliverydisplay;?>;">
													<tbody id="offhirebody">
													 <?php 

													//  if($rec==0 && !empty($obj->getFun241())){

													// 	$sql3 = "select * from freight_cost_estimete_slave14 where FCAID='".$obj->getFun1()."'";

													//  }

													 if($rec==0 && !empty($obj->getFun241())){

														
														if($previnvoiceid!=''){
															$sql3 = "select * from invoice_hire_slave6 where INVOICEID='".$previnvoiceid."'";
															// echo '<h1>'.$previnvoiceid;
														}else{
															$sql3 = "select * from period_contract_master_slave2 where PERIODID='".$obj->getFun241()."'";
															// echo '<h1>'.$previnvoiceid;
														}
														
													 }
													 else if($rec==0 && $previnvoiceid=='')
												 	 {
														// echo '<h1>jp';
														 $sql3 = "select * from freight_cost_estimete_slave14 where FCAID='".$obj->getFun1()."'";

														//  echo '<h1>'.$sql3;
													 }
													

													 else if($rec>0)
													 {
														 $sql3 = "select * from invoice_hire_slave6 where INVOICEID='".$rows_rep['INVOICEID']."'";
														//  echo '<h1>'.$sql3;
													 }else{
														// echo '<h1>dsfs';
														 $sql3 = "select * from invoice_hire_slave6 where INVOICEID='".$previnvoiceid."'";
														//  echo '<h1>'.$sql3;
													 }
													 $result3 = mysql_query($sql3);
													 $num3 = mysql_num_rows($result3);$k = 0;
													 if($num3==0){$k++;?>
														<tr id="row_offhire_<?php echo $k;?>">
															<td><a href="#tb1" onClick="removeOffHire(<?php echo $k;?>);" ><i class="fa fa-times" style="color:red;"></i></a></td>
															<td valign="top" width="18%"><textarea class="form-control areasize" name="txtOffHireReason_<?php echo $k;?>"  id="txtOffHireReason_<?php echo $k;?>" rows="3" placeholder="Off Hire Reason..."></textarea></td>
															<td valign="top" width="15%"><input autocomplete="off" type="text" name="txtOffHireFrom_<?php echo $k;?>" id="txtOffHireFrom_<?php echo $k;?>" class="form-control" value="" placeholder="dd-mm-yyyy HH:MM" /></td>
															<td valign="top" width="15%"><input autocomplete="off" type="text" name="txtOffHireTo_<?php echo $k;?>" id="txtOffHireTo_<?php echo $k;?>" class="form-control" value="" placeholder="dd-mm-yyyy HH:MM" /></td>
															<td valign="top" width="10%"><input autocomplete="off" type="text" name="txtOffHirePercent_<?php echo $k;?>" id="txtOffHirePercent_<?php echo $k;?>" class="form-control numeric" placeholder="%" value="" onKeyUp="getFullClaculation();"></td>
															<td valign="top" width="10%"><input autocomplete="off" type="text" name="txtOffHireDays_<?php echo $k;?>" id="txtOffHireDays_<?php echo $k;?>" class="form-control numeric" placeholder="Off Hire Days" value="" onKeyUp="getFullClaculation();"></td>
															<td width="15%"><select name="selOffHirePerDay_<?php echo $k;?>" id="selOffHirePerDay_<?php echo $k;?>" class="form-control" onChange="getFullClaculation();"></select></td>
															<script>$("#selOffHirePerDay_<?php echo $k;?>").html($("#hirearraycell").html());</script>
															<td valign="top" width="12%"><input autocomplete="off" type="text" name="txtOffHireAmt_<?php echo $k;?>" id="txtOffHireAmt_<?php echo $k;?>" class="form-control" placeholder="Off Hire(USD)" readonly value="" ></td>
														   
														</tr>
														<tr id="row_offhireBunker_<?php echo $k;?>">
															<td></td>
															<td colspan="7">
																<table width="100%" class='tablesorter'>
																  <tr>
																	<td></td>
																	<td>Bunker Grade</td>
																	<td>Qty(MT)</td>
																	<td>Price(USD)</td>
																	<td>Amount(USD)</td>
																  </tr>
																  <tbody id="TCConbunkerTBody_<?php echo $k;?>">
																  <tr id="DivTCConBunkeractual_<?php echo $k;?>_1">
																	<td><a href="#tb1'" onClick="removeTCConBunkerRows(<?php echo $k;?>,1);" ><i class="fa fa-times" style="color:red;"></i></a></td>
																	<td><select name="selTCConBunker_<?php echo $k;?>_1" id="selTCConBunker_<?php echo $k;?>_1" class="form-control"><?php $obj->getBunkerList();?></select></td>
																	<td><input type="text" name="txtTCConBunkerQty_<?php echo $k;?>_1" id="txtTCConBunkerQty_<?php echo $k;?>_1" class="form-control numeric" onKeyUp="getFullClaculation();" placeholder="0.00" autocomplete="off" value=""/></td>
																	<td><input type="text" name="txtTCConBunkerPrice_<?php echo $k;?>_1" id="txtTCConBunkerPrice_<?php echo $k;?>_1" class="form-control numeric" onKeyUp="getFullClaculation();" placeholder="0.00" autocomplete="off" value=""/></td>
																	<td><input type="text" name="txtTCConBunkerAmt_<?php echo $k;?>_1" id="txtTCConBunkerAmt_<?php echo $k;?>_1" class="form-control"  placeholder="0.00" readonly autocomplete="off" value=""/></td>
																  </tr>
																</tbody>
																  <tr>
																	<td colspan="5"><button type="button" class="btn btn-primary" onClick="addTCConBunkerRow(<?php echo $k;?>)">Add Bunkers</button><input type="hidden" name="txtTCConBunkerCount_<?php echo $k;?>" id="txtTCConBunkerCount_<?php echo $k;?>" value="<?php echo $k;?>"/></td>
																  </tr>
																</table>
															</td>
														</tr>
													<?php }else{
													   while($rows3 = mysql_fetch_assoc($result3))
													   {$k++;								   
													   ?>
														 <tr id="row_offhire_<?php echo $k;?>">
															<td><a href="#tb1" onClick="removeOffHire(<?php echo $k;?>);" ><i class="fa fa-times" style="color:red;"></i></a></td>
															<td valign="top" width="18%"><textarea class="form-control areasize" name="txtOffHireReason_<?php echo $k;?>"  id="txtOffHireReason_<?php echo $k;?>" rows="2" placeholder="Off Hire Reason..." ><?php echo $rows3['OFF_REASON'];?></textarea></td>
															<?php if($rows3['OFF_FROM']=='0000-00-00 00:00:00' || $rows3['OFF_FROM']=='1970-01-01 08:00:00'){$offfrom = '';}else{$offfrom = date('d-m-Y H:i',strtotime($rows3['OFF_FROM']));}?>
															<?php if($rows3['OFF_TO']=='0000-00-00 00:00:00' || $rows3['OFF_TO']=='1970-01-01 08:00:00'){$offto = '';}else{$offto = date('d-m-Y H:i',strtotime($rows3['OFF_TO']));}?>
															<td valign="top" width="15%"><input autocomplete="off" type="text" name="txtOffHireFrom_<?php echo $k;?>" id="txtOffHireFrom_<?php echo $k;?>" class="form-control" value="<?php echo $offfrom;?>" placeholder="dd-mm-yyyy HH:MM" /></td>
															<td valign="top" width="15%"><input autocomplete="off" type="text" name="txtOffHireTo_<?php echo $k;?>" id="txtOffHireTo_<?php echo $k;?>" class="form-control" value="<?php echo $offto;?>" placeholder="dd-mm-yyyy HH:MM" /></td>
															<td valign="top" width="10%"><input autocomplete="off" type="text" name="txtOffHirePercent_<?php echo $k;?>" id="txtOffHirePercent_<?php echo $k;?>" class="form-control numeric" placeholder="%" value="<?php echo $rows3['OFF_HIRE_PERCENT'];?>" onKeyUp="getFullClaculation();"></td>
															<td valign="top" width="10%"><input autocomplete="off" type="text" name="txtOffHireDays_<?php echo $k;?>" id="txtOffHireDays_<?php echo $k;?>" class="form-control numeric" placeholder="Off Hire Days" value="<?php echo $rows3['OFF_DAYS'];?>" onKeyUp="getFullClaculation();"></td>
															<td width="15%"><select name="selOffHirePerDay_<?php echo $k;?>" id="selOffHirePerDay_<?php echo $k;?>" class="form-control" onChange="getFullClaculation();"></select></td>
															<script>$("#selOffHirePerDay_<?php echo $k;?>").html($("#hirearraycell").html());$("#selOffHirePerDay_<?php echo $k;?>").val('<?php echo $rows3['HIRE_RATE'];?>');</script>
															<td valign="top" width="12%"><input autocomplete="off" type="text" name="txtOffHireAmt_<?php echo $k;?>" id="txtOffHireAmt_<?php echo $k;?>" class="form-control" placeholder="Off Hire(USD)" readonly value="<?php echo $rows3['OFF_HIRE'];?>" ></td>
														   
														</tr>
														<tr id="row_offhireBunker_<?php echo $k;?>">
															<td></td>
															<td colspan="7">
																<table width="100%" class='tablesorter'>
																  <tr>
																	<td></td>
																	<td>Bunker Grade</td>
																	<td>Qty(MT)</td>
																	<td>Price(USD)</td>
																	<td>Amount(USD)</td>
																  </tr>
																  <tbody id="TCConbunkerTBody_<?php echo $k;?>">
																 <?php 

																if($rec==0 && !empty($obj->getFun241())){

																	if($previnvoiceid!=''){

																		$sql4 = "select * from invoice_hire_slave61 where INVOICEID='".$previnvoiceid."' and INVOICE_SLAVE6ID='".$rows3['INVOICE_SLAVE6ID']."'";

																		
																	}else{
																		$sql4 = "select * from period_contract_master_slave21 where PERIODID='".$obj->getFun241()."' and PERIOD_SLAVEID='".$rows3['PERIOD_SLAVEID']."'";
																	}
																	
																	// echo '<h1>'.$sql3;
																}
																
																 else if($rec==0 && $previnvoiceid=='')
																 {
																	 $sql4 = "select * from freight_cost_estimete_slave15 where FCAID='".$obj->getFun1()."' and FCA_SLAVE14ID='".$rows3['FCA_SLAVE14ID']."'";
																 }
														
																 else if($rec>0)
																 {
																	 $sql4 = "select * from invoice_hire_slave61 where INVOICEID='".$rows_rep['INVOICEID']."' and INVOICE_SLAVE6ID='".$rows3['INVOICE_SLAVE6ID']."'";
																 }else{
																	 $sql4 = "select * from invoice_hire_slave61 where INVOICEID='".$previnvoiceid."' and INVOICE_SLAVE6ID='".$rows3['INVOICE_SLAVE6ID']."'";
																 }
																 $result4 = mysql_query($sql4);
																 $num4 = mysql_num_rows($result4);$m = 0;
																 if($num4==0){$m++;?>
																  <tr id="DivTCConBunkeractual_<?php echo $k;?>_1">
																	<td><a href="#tb1'" onClick="removeTCConBunkerRows(<?php echo $k;?>,1);" ><i class="fa fa-times" style="color:red;"></i></a></td>
																	<td><select name="selTCConBunker_<?php echo $k;?>_1" id="selTCConBunker_<?php echo $k;?>_1" class="form-control"><?php $obj->getBunkerList();?></select></td>
																	<td><input type="text" name="txtTCConBunkerQty_<?php echo $k;?>_1" id="txtTCConBunkerQty_<?php echo $k;?>_1" class="form-control numeric" onKeyUp="getFullClaculation();" placeholder="0.00" autocomplete="off" value="" /></td>
																	<td><input type="text" name="txtTCConBunkerPrice_<?php echo $k;?>_1" id="txtTCConBunkerPrice_<?php echo $k;?>_1" class="form-control numeric" onKeyUp="getFullClaculation();" placeholder="0.00" autocomplete="off" value="" /></td>
																	<td><input type="text" name="txtTCConBunkerAmt_<?php echo $k;?>_1" id="txtTCConBunkerAmt_<?php echo $k;?>_1" class="form-control"  placeholder="0.00" readonly autocomplete="off" value=""/></td>
																  </tr>
																 <?php }else{
																   while($rows4 = mysql_fetch_assoc($result4))
																   {$m++; //echo '<pre>';print_r($rows4);?>
																   <tr id="DivTCConBunkeractual_<?php echo $k;?>_<?=$m;?>">
																	<td><a href="#tb1'" onClick="removeTCConBunkerRows(<?php echo $k;?>,<?=$m;?>);" ><i class="fa fa-times" style="color:red;"></i></a></td>
																	<td><select name="selTCConBunker_<?php echo $k;?>_<?=$m;?>" id="selTCConBunker_<?php echo $k;?>_<?=$m;?>" class="form-control" ><?php $obj->getBunkerList();?></select></td>
																	<td><input type="text" name="txtTCConBunkerQty_<?php echo $k;?>_<?=$m;?>" id="txtTCConBunkerQty_<?php echo $k;?>_<?=$m;?>" class="form-control numeric" onKeyUp="getFullClaculation();" placeholder="0.00" autocomplete="off" value="<?=$rows4['BUNKERQTY'];?>" /></td>
																	<td><input type="text" name="txtTCConBunkerPrice_<?php echo $k;?>_<?=$m;?>" id="txtTCConBunkerPrice_<?php echo $k;?>_<?=$m;?>" class="form-control numeric" onKeyUp="getFullClaculation();" placeholder="0.00" autocomplete="off" value="<?=$rows4['BUNKERPRICE'];?>" /></td>
																	<td><input type="text" name="txtTCConBunkerAmt_<?php echo $k;?>_<?=$m;?>" id="txtTCConBunkerAmt_<?php echo $k;?>_<?=$m;?>" class="form-control"  placeholder="0.00" readonly autocomplete="off" value="<?=$rows4['BUNKERAMT'];?>"/></td>
																  </tr>
																  <script>$("#selTCConBunker_<?php echo $k;?>_<?=$m;?>").val(<?=$rows4['BUNKERID'];?>);</script>
																  <?php }}?>
																</tbody>
																  <tr>
																	<td colspan="5"><?php if($invoicedval==0){?><button type="button" class="btn btn-primary" onClick="addTCConBunkerRow(<?php echo $k;?>)">Add Bunkers</button><?php }?><input type="hidden" name="txtTCConBunkerCount_<?php echo $k;?>" id="txtTCConBunkerCount_<?php echo $k;?>" value="<?=$m;?>"/></td>
																  </tr>
																</table>
															</td>
														</tr>
													<?php }}?>
												   </tbody> 
											   
													<tbody>		
														<tr>
															<td colspan="6"><button type="button" class="btn btn-primary" onClick="AddNewOffHire();">Add Off-Hire</button><input type="hidden" name="txtOFFID" id="txtOFFID" value="<?php echo $k;?>"/></td>
														</tr>
													</tbody>
									           </table> 
									           </td> 
										    </tr>
									       
										   
										   <?php if($rows_rep['CHK_OVERCONSP']==1){$OverConspdisplay = '';}else{$OverConspdisplay = 'none';}?>
										   <tr>
                                               <th align="left" colspan="4"><input name="ChkOverConspBunker" class="checkbox" id="ChkOverConspBunker" type="checkbox" value="1" <?php if($rows_rep['CHK_OVERCONSP']==1){echo 'checked';}?> />&nbsp;&nbsp;Bunker Over Consumption as per Weather Routing</th>
                                            </tr>
									        <tr id="DivBunkerOverConsp_0" style="display:<?php echo $OverConspdisplay;?>;">
                                            <td>Bunker Grade</td>
                                            <td>Qty(MT)</td>
                                            <td>Price(<?php echo $currency;?>)</td>
                                            <td>Amount(<?php echo $currency;?>)</td>
                                            </tr>
                                            <tbody id="bunkerOverConspbody">
									<?php   if($rec>0)
											{
												$sql2 = "select * from invoice_hire_slave2 where INVOICEID='".$rows_rep['INVOICEID']."' and IDENTIFY='OVERCONSP'";
											}else{
												$sql2 = "select * from invoice_hire_slave2 where INVOICEID='".$previnvoiceid."' and IDENTIFY='OVERCONSP'";
											}
											$res2 = mysql_query($sql2);
											$num2 = mysql_num_rows($res2);
											if($num2 >0){$num21 = $num2;}else{$num21 = 1;}
										if($num2 >0)
									    {$i = 0;
										  while($rows2 = mysql_fetch_assoc($res2))
										  {$i++;?>
											<tr id="DivBunkerOverConsp_<?php echo $i;?>" style="display:<?php echo $OverConspdisplay;?>;">
                                            <td><select name="selOverConspBunker_<?php echo $i;?>" id="selOverConspBunker_<?php echo $i;?>" class="select form-control" onChange="getFullClaculation();"><?php $obj->getBunkerList();?></select></td>
                                            <td><input type="text" name="txtOverConspBunkerQty_<?php echo $i;?>" id="txtOverConspBunkerQty_<?php echo $i;?>" onKeyUp="getFullClaculation();" class="form-control numeric"  placeholder="0.00" autocomplete="off" value="<?php echo $rows2['BUNKER_QTY'];?>"/></td>
                                            <td><input type="text" name="txtOverConspBunkerPrice_<?php echo $i;?>" id="txtOverConspBunkerPrice_<?php echo $i;?>" onKeyUp="getFullClaculation();" class="form-control numeric"  placeholder="0.00" autocomplete="off" value="<?php echo $rows2['BUNKER_PRICE'];?>"/></td>
                                            <td><input type="text" name="txtOverConspBunkerAmt_<?php echo $i;?>" id="txtOverConspBunkerAmt_<?php echo $i;?>" class="form-control"  placeholder="0.00" readonly autocomplete="off" value="<?php echo $rows2['BUNKER_AMT'];?>"/></td>
										    </tr>
                                            <script>$("#selOverConspBunker_<?php echo $i;?>").val(<?php echo $rows2['BUNKERID'];?>);</script>   
									<?php   }
										}else{$i=1;
											?>
                                            <tr id="DivBunkerOverConsp_<?php echo $i;?>" style="display:<?php echo $OverConspdisplay;?>;">
                                            <td><select name="selOverConspBunker_<?php echo $i;?>" id="selOverConspBunker_<?php echo $i;?>" class="select form-control" onChange="getFullClaculation();"><?php $obj->getBunkerList();?></select></td>
                                            <td><input type="text" name="txtOverConspBunkerQty_<?php echo $i;?>" id="txtOverConspBunkerQty_<?php echo $i;?>" onKeyUp="getFullClaculation();" class="form-control numeric"  placeholder="0.00" autocomplete="off" value=""/></td>
                                            <td><input type="text" name="txtOverConspBunkerPrice_<?php echo $i;?>" id="txtOverConspBunkerPrice_<?php echo $i;?>" onKeyUp="getFullClaculation();" class="form-control numeric"  placeholder="0.00" autocomplete="off" value=""/></td>
                                            <td><input type="text" name="txtOverConspBunkerAmt_<?php echo $i;?>" id="txtOverConspBunkerAmt_<?php echo $i;?>" class="form-control"  placeholder="0.00" readonly autocomplete="off" value=""/></td>
										    </tr>  
                                            <?php
										}?> 
                                            </tbody>   
											<tr id="DivBunkerOverConsp_01" style="display:<?php echo $OverConspdisplay;?>;">
											   <td align="left" colspan="4"><button type="button" class="btn btn-primary btn-flat" onClick="AddNewOverConspRow();">Add</button><input type="hidden" name="txtAddOVERCONPID" id="txtAddOVERCONPID" value="<?php echo $num21;?>"/></td>
											</tr>
										   
										   
										   <tr>
                                               <th style="padding-top:15px;padding-bottom:15px;" colspan="4">Hold Cleaning</th>
                                           </tr>
                                      <?php 
										if($rec>0)
										{
											$sql2 = "select * from invoice_hire_slave1 where INVOICEID='".$rows_rep['INVOICEID']."' and IDENTIFY='HOLD_CLEANING'";
										}else{
										    $sql2 = "select * from invoice_hire_slave1 where INVOICEID='".$previnvoiceid."' and IDENTIFY='HOLD_CLEANING'";
										}
											$res2 = mysql_query($sql2);
											$num2 = mysql_num_rows($res2);
											if($num2 >0){$num21 = $num2;}else{$num21 = 1;}?>
                                       </tbody>
                                       <tbody id="tblHold">
                                     <?php if($num2 >0)
										   {$i = 0;


											while($rows2 = mysql_fetch_assoc($res2))
											{$i++;
											?>
											<tr id="Hold_Row_<?php echo $i;?>">
											   <td align="center"><a href="#pr<?php echo $i;?>" onClick="removeHoldRow(<?php echo $i;?>);"><i class="fa fa-times" style="color:red;"></i></a></td>
											   <td colspan="2"><textarea class="form-control areasize" name="txtHoldDes_<?php echo $i;?>" id="txtHoldDes_<?php echo $i;?>" rows="2" placeholder="Description..."><?php echo $rows2['DESCRIPTION'];?></textarea></td>
											   <td><input type="text" name="txtHoldDesAmt_<?php echo $i;?>" id="txtHoldDesAmt_<?php echo $i;?>" class="form-control numeric"  placeholder="Amount" autocomplete="off" value="<?php echo $rows2['AMOUNT'];?>" onKeyUp="getFullClaculation();"/></td>
											</tr>
											<?php }}else{?>

												<?php
												
							
												$sql1 = "select RAW_AMOUNT from freight_cost_estimete_slave3 where FCAID='" . $id . "' and IDENTIFY='ORC' and IDENTY_ID=12";
												$res1 = mysql_query($sql1) or die($sql1);

												
												// echo '<h1>'.$sql1;
												$rows1 = mysql_fetch_assoc($res1);
													
													
													
													?>
											<tr id="Hold_Row_1">
											   <td align="center"><a href="#pr1" onClick="removeHoldRow(1);"><i class="fa fa-times" style="color:red;"></i></a>
												

											</td>
											   <td colspan="2"><textarea class="form-control areasize" name="txtHoldDes_1" id="txtHoldDes_1" rows="2" placeholder="Description...">ILOHC</textarea></td>
											   <td><input type="text" name="txtHoldDesAmt_1" id="txtHoldDesAmt_1" class="form-control numeric"  placeholder="Amount" autocomplete="off" value="<?= $rows1['RAW_AMOUNT']?>" onKeyUp="getFullClaculation();"/></td>
											</tr>
									<?php }?>
                                       </tbody>
										   <tbody>		
											<tr>
												<td colspan="4"><button type="button" class="btn btn-primary" onClick="SubNewHoldRow();">Add New</button><input type="hidden" name="txtHoldID" id="txtHoldID" value="<?php echo $num21;?>"/></td>
											</tr>
										</tbody>
										
										
										<tr>
                                               <th style="padding-top:15px;padding-bottom:15px;" colspan="4">On/Off hire survey</th>
                                           </tr>
                                      <?php 
										if($rec>0)
										{
											$sql2 = "select * from invoice_hire_slave1 where INVOICEID='".$rows_rep['INVOICEID']."' and IDENTIFY='HIRE_SURVEY'";
										}else{
										    $sql2 = "select * from invoice_hire_slave1 where INVOICEID='".$previnvoiceid."' and IDENTIFY='HIRE_SURVEY'";
										}
											$res2 = mysql_query($sql2);
											$num2 = mysql_num_rows($res2);
											if($num2 >0){$num21 = $num2;}else{$num21 = 2;}?>
                                       </tbody>
                                       <tbody id="tblHireSurvey">
                                     <?php if($num2 >0)
										   {$i = 0;
											while($rows2 = mysql_fetch_assoc($res2))
											{$i++;
											?>
											<tr id="HireSurvey_Row_<?php echo $i;?>">
											   <td align="center"><a href="#pr<?php echo $i;?>" onClick="removeHireSurveyRow(<?php echo $i;?>);"><i class="fa fa-times" style="color:red;"></i></a></td>
											   <td><textarea class="form-control areasize" name="txtHireSurveyDes_<?php echo $i;?>" id="txtHireSurveyDes_<?php echo $i;?>" rows="2" placeholder="Description..."><?php echo $rows2['DESCRIPTION'];?></textarea></td>
											   <td align="left"><input name="Chk_Owner_Account_<?php echo $i;?>" class="checkbox" id="Chk_Owner_Account_<?php echo $i;?>" type="checkbox" value="1" <?php if($rows2['CHK_OWNER_ACC']==1){echo 'checked';}?> />&nbsp;&nbsp;On Owner's Account</td>
											   <td><input type="text" name="txtHireSurveyDesAmt_<?php echo $i;?>" id="txtHireSurveyDesAmt_<?php echo $i;?>" class="form-control numeric"  placeholder="Amount" autocomplete="off" value="<?php echo $rows2['AMOUNT'];?>" onKeyUp="getFullClaculation();"/></td>
											</tr>
											<?php }}else{?>
											<tr id="HireSurvey_Row_1">
											   <td align="center"><a href="#pr1" onClick="removeHireSurveyRow(1);"><i class="fa fa-times" style="color:red;"></i></a></td>
											   <td><textarea class="form-control areasize" name="txtHireSurveyDes_1" id="txtHireSurveyDes_1" rows="2" placeholder="Description...">Joint On-Hire Survey</textarea></td>
											   <td align="left"><input name="Chk_Owner_Account_1" class="checkbox" id="Chk_Owner_Account_1" type="checkbox" value="1"/>&nbsp;&nbsp;On Owner's Account</td>
											   <td><input type="text" name="txtHireSurveyDesAmt_1" id="txtHireSurveyDesAmt_1" class="form-control numeric"  placeholder="Amount" autocomplete="off" value="" onKeyUp="getFullClaculation();"/></td>
											</tr>
											<tr id="HireSurvey_Row_2">
											   <td align="center"><a href="#pr1" onClick="removeHireSurveyRow(2);"><i class="fa fa-times" style="color:red;"></i></a></td>
											   <td><textarea class="form-control areasize" name="txtHireSurveyDes_2" id="txtHireSurveyDes_2" rows="2" placeholder="Description...">Joint Off-Hire Survey</textarea></td>
											   <td align="left"><input name="Chk_Owner_Account_2" class="checkbox" id="Chk_Owner_Account_2" type="checkbox" value="1"/>&nbsp;&nbsp;On Owner's Account</td>
											   <td><input type="text" name="txtHireSurveyDesAmt_2" id="txtHireSurveyDesAmt_2" class="form-control numeric"  placeholder="Amount" autocomplete="off" value="" onKeyUp="getFullClaculation();"/></td>
											</tr>
									<?php }?>
                                       </tbody>
										   <tbody>		
											<tr>
												<td colspan="4"><button type="button" class="btn btn-primary" onClick="SubNewHireSurveyRow();">Add New</button><input type="hidden" name="txtHireSurveyID" id="txtHireSurveyID" value="<?php echo $num21;?>"/></td>
											</tr>
										</tbody>
										   
									       <tr>
                                                <td colspan="3"><strong>Total Hire for this Inv (<?php echo $currency;?>)</strong></td>
                                                
                                                <td><input type="text" name="txtFinalAmt" id="txtFinalAmt" class="form-control"  placeholder="0.00" autocomplete="off" readonly value="<?php echo $rows_rep['FINAL_AMT'];?>"/></td>
                                            </tr> 
											
											
											<?php $m = 0;
											$sql121    = "select * from freight_cost_estimete_slave3 where FCAID in (".implode(',',$arrayfcaid).") and VENDORID='".$vendorid."' and IDENTIFY='ORC' and RAW_AMOUNT>0";
											$result    = mysql_query($sql121);
											$record    = mysql_num_rows($result);
											while($rows11 = mysql_fetch_array($result))
											{
												$m++;
												$sql12 = "select count(*) as count from invoice_hire_slave5 where INVOICEID='".$rows_rep['INVOICEID']."' and VENDORID='".$vendorid."' and RANDOMID='".$rows11['RANDOMID']."' ";
												$res12 = mysql_query($sql12) or die($sql12);
												$rows12 = mysql_fetch_assoc($res12);
												
												$sql13 = "select count(*) as count from invoice_hire_slave5 inner join invoice_hire_master on invoice_hire_master.INVOICEID=invoice_hire_slave5.INVOICEID where invoice_hire_slave5.VENDORID='".$vendorid."' and invoice_hire_master.COMID in (".$comid.") and invoice_hire_slave5.RANDOMID='".$rows11['RANDOMID']."'";
												$res13 = mysql_query($sql13) or die($sql13);
												$rows13 = mysql_fetch_assoc($res13);
												
												if($rows12['count']>0){$checkdem = 1;}else if($rows13['count']>0 && $rec == 0){$checkdem = 1;}else{$checkdem = 0;}
											?>
												<tr>


												<?php
			
			$checked=strpos($obj->getOwnerRelatedCostNameBasedOnID($rows11['IDENTY_ID']), "Test") !==false?'checked':'';
			
			if($checkdem==1){
				$checked="checked";
			}

												?>
													<td colspan="3"><input name="chkORC_<?=$m;?>" class="checkbox" id="chkORC_<?=$m;?>" type="checkbox" value="1" <?=$checked?>/><strong>&nbsp;&nbsp;<?php echo $m;?>. <?php echo $obj->getOwnerRelatedCostNameBasedOnID($rows11['IDENTY_ID']);?></strong>
													<input type="hidden" name="txtORCRandomid_<?=$m;?>" id="txtORCRandomid_<?=$m;?>" value="<?=$rows11['RANDOMID'];?>" />
													<input type="hidden" name="txtORCVendorid_<?=$m;?>" id="txtORCVendorid_<?=$m;?>" value="<?=$rows11['VENDORID'];?>" />
													<input type="hidden" name="txtORCIdentify_<?=$m;?>" id="txtORCIdentify_<?=$m;?>" value="<?=$rows11['IDENTY_ID'];?>" />
													</td>
													<td><input type="text"  name="txtORCAmt_<?=$m;?>" id="txtORCAmt_<?=$m;?>" class="form-control" readonly value="<?=$rows11['RAW_AMOUNT'];?>" /></td>
												</tr>
										  <?php }?>
											<tr> 
											   <td colspan="4"><input type="hidden" name="txtORCID" id="txtORCID" value="<?=$m;?>" /></td>
											</tr>
											
											<?php 
											$sqlprev = "SELECT * from invoice_hire_master where COMID in (".implode(',',$arrayrandomidvc).") and MODULEID='".$_SESSION['moduleid']."' and MCOMPANYID='".$_SESSION['company']."' and STATUS=5";
											$resprev = mysql_query($sqlprev);
											$recprev = mysql_num_rows($resprev);$k = 0;
											while($rowsprev = mysql_fetch_assoc($resprev))
											{$m++;$k++;
											
											    $sql17 = "select count(*) as count from invoice_hire_slave7 where INVOICEID='".$rows_rep['INVOICEID']."' and PINVOICEID='".$rowsprev['INVOICEID']."' and IDENTIFY='VC'";
												$res17 = mysql_query($sql17) or die($sql17);
												$rows17 = mysql_fetch_assoc($res17);


												if($rec>0){

													if($rows17['count']>0){$checkprev = 1;}else{$checkprev = 0;}

												}else{

													if($rows17['count']>0 || $rowsprev['INVOICE_TYPE']=='FHS2' || $rowsprev['INVOICE_TYPE']=='Final'){$checkprev = 1;}else{$checkprev = 0;}

												}
												
											?>
                                            <tr>
                                                <td colspan="3"><strong><input name="chkPrevInv_<?=$k;?>" class="checkbox" id="chkPrevInv_<?=$k;?>" type="checkbox" value="1" <?=($checkprev==1)?'checked="checked"':''?>/><strong>&nbsp;&nbsp;<?php echo $m;?>. <?php echo $rowsprev['INVOICE_NO'];?></strong><input type="hidden" name="txtPrevInvDays_<?php echo $k;?>" id="txtPrevInvDays_<?php echo $k;?>" value="<?php echo $rowsprev['HIRE_DAYS'];?>"/><input type="hidden" name="txtPrevInvID_<?php echo $k;?>" id="txtPrevInvID_<?php echo $k;?>" value="<?php echo $rowsprev['INVOICEID'];?>"/><input type="hidden" name="txtPrevInvIdentify_<?php echo $k;?>" id="txtPrevInvIdentify_<?php echo $k;?>" value="VC"/></td>
                                                <td><input type="text" name="txtPrevInvAmt_<?php echo $k;?>" id="txtPrevInvAmt_<?php echo $k;?>" class="form-control"  placeholder="0.00" autocomplete="off" readonly value="<?php echo $rowsprev['P_AMT'];?>"/></td>
                                            </tr>
                                        <?php }?>
										
										<?php 
											$sqlprev = "SELECT * from invoice_hiretc_master where COMID in (".implode(',',$arrayrandomidtc).") and MODULEID='".$_SESSION['moduleid']."' and MCOMPANYID='".$_SESSION['company']."' and STATUS=5";
											$resprev = mysql_query($sqlprev);
											$recprev = mysql_num_rows($resprev);
											while($rowsprev = mysql_fetch_assoc($resprev))
											{$m++;$k++;
											
											    $sql17 = "select count(*) as count from invoice_hire_slave7 where INVOICEID='".$rows_rep['INVOICEID']."' and PINVOICEID='".$rowsprev['INVOICEID']."' and IDENTIFY='TC'";
												$res17 = mysql_query($sql17) or die($sql17);
												$rows17 = mysql_fetch_assoc($res17);
												
												if($rows17['count']>0){$checkprev = 1;}else{$checkprev = 0;}
											?>
                                            <tr>
                                                <td colspan="3"><strong><input name="chkPrevInv_<?=$k;?>" class="checkbox" id="chkPrevInv_<?=$k;?>" type="checkbox" value="1" <?=($checkprev==1)?'checked="checked"':''?>/><strong>&nbsp;&nbsp;<?php echo $m;?>. <?php echo $rowsprev['INVOICE_NO'];?></strong><input type="hidden" name="txtPrevInvDays_<?php echo $k;?>" id="txtPrevInvDays_<?php echo $k;?>" value="<?php echo $rowsprev['HIRE_DAYS'];?>"/><input type="hidden" name="txtPrevInvID_<?php echo $k;?>" id="txtPrevInvID_<?php echo $k;?>" value="<?php echo $rowsprev['INVOICEID'];?>"/><input type="hidden" name="txtPrevInvIdentify_<?php echo $k;?>" id="txtPrevInvIdentify_<?php echo $k;?>" value="TC"/></td>
                                                <td><input type="text" name="txtPrevInvAmt_<?php echo $k;?>" id="txtPrevInvAmt_<?php echo $k;?>" class="form-control"  placeholder="0.00" autocomplete="off" readonly value="<?php echo $rowsprev['P_AMT'];?>"/></td>
                                            </tr>
                                        <?php }?>
										
										    <tr style="">
                                            <th style="padding-top:15px;padding-bottom:15px;" colspan="3">Balance(<?php echo $currency;?>) :<input type="hidden" name="hddnprevinvid" id="hddnprevinvid" value="<?=$k;?>"/></th>
                                            <td><input type="text" name="txtBalanceShipOwner" id="txtBalanceShipOwner" class="form-control" readonly style="background-color:#eee;"  placeholder="Balance to Shipowner" autocomplete="off" value="<?php echo $rows_rep['BALANCE_TO_OWNER'];?>"/></td>
                                        </tr>
                                        
                                       </tbody>
                                   </table>

								
                               </div>
							 
							   <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 = 'HIRE_STSTMENT_CHK_APP_1';
								   ?>
								    
									<select data-placeholder="Choose Approver..." class="input-text chzn-select" style="width:300px;" multiple name="selApprovers[]" id="selApprovers"><?php $obj->getApproverListBasedOnApprovalMatrix($fieldname, $rows_rep['APPROVERS']);?></select>
								   </div>
							   </div>
							  
									


									<h4>
									<?php if($approver2==1){ ?>
										<hr>
									
										<legend><h3 style="padding: 0 0 0 10px">Payment</h3></legend>

										<?php if($rows_rep['PAYMENT_STATUS']=='payment_hold'){?>
										<label style="padding: 0 0 0 11px;">Payment Hold</label><input checked type="radio" id="delivery" name="payment_status" value="payment_hold" />
										<?php }else{?>
											<label style="padding: 0 0 0 11px;">Payment Hold</label><input type="radio" id="delivery" name="payment_status" value="payment_hold" />

											<?php }if($rows_rep['PAYMENT_STATUS']=='payment_payable'){?>
										<label style="padding: 0 0 0 11px;">Payment Payable</label><input checked type="radio" id="delivery" name="payment_status" value="payment_payable" />
										<?php }else{?>
											<label style="padding: 0 0 0 11px;">Payment Payable</label><input type="radio" id="delivery" name="payment_status" value="payment_payable" />
											<?php } ?>
								
									<?php } ?>
										</h4>
							   <div class="row invoice-info">
							       <div class="col-sm-12 invoice-col">&nbsp;</div>
							   </div>
						   </div><!-- /.col -->
						</div>
                      
                       <div class="box-footer" align="right">
							<input type="hidden" name="txtStatus" id="txtStatus" value="" />
							
							<?php if(($rec==0 && $creator==1) || (($rows['STATUS']==0 || $rows['STATUS']==2) && $creator==1)){
									   if(empty($approverarr1) && empty($approverarr2)){$status = 5;}
									   else if(empty($approverarr1) && !empty($approverarr2)){$status = 4;}
									   else{$status = 1;}

									    if(in_array("2",$obj->getUserRightsForViewCheckerMaker($_SESSION['uid'],5,5))){
							  ?>
									<button type="submit" class="btn btn-primary btn-flat" onClick="return getValidate(0);">Submit to edit</button>
									<?php } ?>&nbsp;&nbsp;

									<?php if(in_array("3",$obj->getUserRightsForViewCheckerMaker($_SESSION['uid'],5,5))){?>
									<button type="submit" class="btn btn-warning btn-flat" onClick="return getValidate(<?=$status;?>);">Send for Approval</button>
									<?php } ?>
							  <?php }else if($rec>0 && ($rows['STATUS']==1 || $rows['STATUS']==4) && $approver1 == 1){
										 if(empty($approverarr2)){$status = 5;}
										 else{$status = 3;}


										 if(in_array("2",$obj->getUserRightsForViewCheckerMaker($_SESSION['uid'],5,5))){


								   ?>
									<button type="submit" class="btn btn-primary btn-flat" onClick="return getValidate(2);">Send for Review</button>
									<?php } ?>&nbsp;&nbsp;
									<?php if(in_array("3",$obj->getUserRightsForViewCheckerMaker($_SESSION['uid'],5,5))){?>
									<button type="submit" class="btn btn-warning btn-flat" onClick="return getValidate(<?=$status;?>);">Submit & Approve</button>

									<?php } ?>


							  <?php }else if($rec>0 && $rows['STATUS']==3 && $approver2 == 1){
									   if(empty($approverarr1)){$status = 2;}
									   else{$status = 4;}

									   if(in_array("2",$obj->getUserRightsForViewCheckerMaker($_SESSION['uid'],5,5))){
									  ?>
									<button type="submit" class="btn btn-primary btn-flat" onClick="return getValidate(<?=$status;?>);">Send for Review</button>
									<?php } ?>
									&nbsp;&nbsp;
									<?php if(in_array("3",$obj->getUserRightsForViewCheckerMaker($_SESSION['uid'],5,5))){?>
									<button type="submit" class="btn btn-warning btn-flat" onClick="return getValidate(5);">Submit & Approve</button>
									<?php } ?>
							  <?php }?>
										
							
							
							<!--<button class="btn btn-primary btn-flat" type="submit" onClick="return getValidate(0);">Submit to Edit</button>
							<button class="btn btn-primary btn-flat" type="submit" onClick="return getValidate(1);">Submit to Close</button>-->
							<input type="hidden" name="action" id="action" value="submit" />
                           
						    <input type="hidden" name="txtCRMFILE" id="txtCRMFILE" value="" />
					         <input type="hidden" name="txtCRMNAME" id="txtCRMNAME" value="" />
				        </div>
                         </form> 
					
						
						<form role="form" name="frm3" id="frm3" enctype="multipart/form-data" action="<?php echo $pagename;?>" method="post">
                        <div class="box-body no-padding" style="overflow:auto;">
                            <table class="table table-striped" id="i_h_listing_table">
                                <thead>
                                    <tr>
                                        <th width="3%"># <input type="hidden" name="action11" id="action11" value="" /><input type="hidden" name="txtDEL_ID" id="txtDEL_ID" value="0"/></th>
                                        <th width="10%">Fixture No</th>
                                        <th width="10%">Hire Statement Date</th>
                                        <th width="10%">Hire Statement No.</th>
										<th width="10%">Hire From - To</th>
                                        <th width="10%">Hire Days</th>
                                        <th width="10%">Amount</th>
                                        <th width="10%">Generate PDF/JSON</th>
                                        <th width="10%">Payment Actioned</th>
										<th width="10%">Attachment</th>
										<?php

										if ($_SESSION['iutype'] == 'mgmt_user') {
											?>
 												<th width="3%">Delete</th>
												 <th width="3%">Open</th>
											<?php
										}
										?>
                                       	<th width="10%">LAST UPDATED BY/TIME</th>
                                    </tr>
                                </thead>
                                <tbody id="tbl_txtID">
                                <?php 
                                $sql_ihm = "SELECT *,(select CONTACT_PERSON from login where login.LOGINID = invoice_hire_master.L_UPDATED_BY) as LUPNAME from invoice_hire_master where COMID in (".implode(',',$arrayrandomidvc).") and MODULEID='".$_SESSION['moduleid']."' and MCOMPANYID='".$_SESSION['company']."' and STATUS=5 ORDER BY INVOICE_DATE ASC";

								// echo '<h2>'.$sql_ihm;
								
                                $res_ihm = mysql_query($sql_ihm);
                                $rec_ihm = mysql_num_rows($res_ihm);

								
								$sqlForCheck = "SELECT * from invoice_hire_master where COMID in (".implode(',',$arrayrandomidvc).") and MODULEID='".$_SESSION['moduleid']."' and MCOMPANYID='".$_SESSION['company']."' and (STATUS=0 || STATUS=1 || STATUS=3)";

								$resForCheck = mysql_query($sqlForCheck);
                                $recForCheck = mysql_num_rows($resForCheck);


								if($recForCheck > 0){

									$displayBtn = 'display: none;';

								}else{

									$displayBtn = '';
								}

								$sql_ihmForCount = "SELECT COUNT(*) AS LOG_COUNT from invoice_hire_master where COMID in (".implode(',',$arrayrandomidvc).") and MODULEID='".$_SESSION['moduleid']."' and MCOMPANYID='".$_SESSION['company']."' and STATUS=5 ORDER BY INVOICE_DATE ASC";
								// $res_ihm = mysql_query($sql_ihm);
                                $res_ihmForCount = mysql_query($sql_ihmForCount);
								$rows_ihmForCount = mysql_fetch_assoc($res_ihmForCount);
                                if($rec_ihm == 0){
                                ?>
                                <tr id="tpRow"><td valign="top" align="center" colspan="9" style="color:red;">Sorry , currently zero(0) records added.</td></tr>
                                <?php }else{
                                $m=1;
                                while($rows_ihm = mysql_fetch_assoc($res_ihm))
                                {
                                ?>
                                <tr id="tpRow_<?php echo $m;?>">
                                <td align="center"><?php echo $m.".";?></td>
                                <td align="center">

									<?php echo $obj->getCompareEstimateData($comid,"VOYAGE_NO");?>
									
								</td>
                                <td align="left"><?php echo date("d-M-Y",strtotime($rows_ihm['INVOICE_DATE']));?></td>
                                <td align="left"><?php echo $rows_ihm["INVOICE_NO"];?></td>
								
								<?php 
								$fcaid = $obj->getCompareEstimateData($rows_ihm['COMID'],"FCAID");

								$sql_invslave = "select sum(UTILISED_DAYS) as DAYS from invoice_hire_slave8 where INVOICEID='".$rows_ihm['INVOICEID']."'";
									$res_invslave = mysql_query($sql_invslave) or die($sql_invslave);
									$result_invslave = mysql_fetch_assoc($res_invslave);?>
                                
								<?php 
								$sql_2 = "select HIRE_RATE, RANDOMID from freight_cost_estimete_slave17 where FCAID='".$fcaid."' ";
								// echo '<h1>'.$sql_2;	
								$result_2 = mysql_query($sql_2) or die($sql_2);$i = 0;
								$num_2 = mysql_num_rows($result_2);

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

								// $hireDayForCheck[]='';
								while($rows_ihm_2 = mysql_fetch_assoc($result_2))
								{
									$fromdate = '';$todate = '';
									$sql_invslave1 = "select HIRE_FROM, HIRE_TO, UTILISED_DAYS from invoice_hire_slave8 where INVOICEID='".$rows_ihm['INVOICEID']."' and RANDOMID='".$rows_ihm_2['RANDOMID']."'";
									$res_invslave1 = mysql_query($sql_invslave1) or die($sql_invslave1);

									// echo '------------';
									// echo '<h1>'.$sql_invslave1;	
									$num_invslave1 = mysql_num_rows($res_invslave1);
									$ik = 1;
									while($result_invslave1 = mysql_fetch_assoc($res_invslave1))
									{
										$uitiliseddays = $uitiliseddays + $result_invslave1['UTILISED_DAYS'];
										$fromdate = $result_invslave1['HIRE_FROM'];
										$todate = $result_invslave1['HIRE_TO'];
									
										if(date('d-m-Y',strtotime($fromdate))!='01-01-1970' && date('d-m-Y',strtotime($todate))!='01-01-1970')
										{
											 echo "<td align='left' data-tdate='".date('d-m-Y H:i',strtotime($todate))."'>".$rows_ihm_2['HIRE_RATE']."(".date('d-m-Y H:i',strtotime($fromdate))." - ".date('d-m-Y H:i',strtotime($todate)).")<br/>";
										}
									}
								}?>
								
								<?php if($num_2==0){?>
									<td  align="left">
								<?php 
								if(date('d-m-Y',strtotime($rows_ihm['HIRE_FROM']))!='01-01-1970' && date('d-m-Y',strtotime($rows_ihm['HIRE_TO']))!='01-01-1970')
								{
								echo date('d-m-Y H:i',strtotime($rows_ihm['HIRE_FROM']));?> - <?php echo date('d-m-Y H:i',strtotime($rows_ihm['HIRE_TO']));
								}?>
								<?php } ?>

								<?php 
										if ($m == $rows_ihmForCount['LOG_COUNT']){

											$hireDayForCheck += $result_invslave['DAYS'];
											$hireDayForCheck += $rows_ihm['HIRE_DAYS'] > 0?$rows_ihm['HIRE_DAYS']:'';
									}
								?>
								</td>
                                <td align="left"><?php echo $result_invslave['DAYS'];?><?=($rows_ihm['HIRE_DAYS'] > 0)?$rows_ihm['HIRE_DAYS']:'';?></td>
                                <td align="left"><?php echo $rows_ihm['BALANCE_TO_OWNER'];?><input type="hidden" name="txthddnAmt_<?php echo $m;?>" id="txthddnAmt_<?php echo $m;?>" value="<?php echo $rows_ihm['BALANCE_TO_OWNER'];?>"/><input type="hidden" name="txthddnUsdAmt_<?php echo $m;?>" id="txthddnUsdAmt_<?php echo $m;?>" value="<?php echo number_format(($rows_ihm['BALANCE_TO_OWNER']*$rows_ihm['EXCHANGE_RATE']),2,'.','');?>"/><input type="hidden" name="txthddnID_<?php echo $m;?>" id="txthddnID_<?php echo $m;?>" value="<?php echo $rows_ihm['INVOICEID'];?>"/><input type="hidden" id="tblid1" name="tblid1" value=""/></td>
                                <td align="left"><p>
                                <a href="allPdf.php?id=46&comid=<?php echo $rows_ihm["COMID"]; ?>&invoiceid=<?php echo $rows_ihm['INVOICEID']; ?>" title="Pdf"><button type="button" class="btn btn-default" style="margin-right: 5px;"><i class="fa fa-download"></i> Generate PDF</button></a></p>
									
								<hr style="margin-bottom:7px;margin-top:7px;">
											<a href="#jsondownload" title="Pdf" id="jsondownload" onClick="getDownloadJson(<?php echo $rows_ihm['INVOICEID'];?>,<?php echo $rows_ihm['COMID'];?>);"><button class="btn btn-primary" type="button" style="margin-right: 5px;"><i class="fa fa-download"></i> Generate Json</button></a>


							
							</td>
                                <td align="left" valign="middle">
								<a href="#Payment" title="Payment Received" class="btn btn-default btn-sm" data-toggle="modal" data-target="#compose-modal" onClick="openWin(<?php echo $rows_ihm['INVOICEID'];?>);">Payment Actioned</a>
                                </td>
								<td width="40%" >
								<?php							
								$attached_files=explode(',',$rows_ihm['UPLOAD']);
								$attached_file_name=explode(',',$rows_ihm['UPLOAD_NAME']);

									$files=array_combine($attached_files,$attached_file_name);


								foreach($files as $key=>$single_file){

									if($single_file!=''){


									
									?>

									
								<a href="../../attachment/<?=$key?>" target="_blank"><i class="fa fa-external-link"></i><?=$single_file?></a>
									<?php
									echo "<br>";

									}
								}
								?>
							</td>


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

											?>
							 					<td align="center">
                              				  <a href="#?" title="Delete Entry" onClick="getDelete(<?php echo $rows_ihm['INVOICEID'];?>,<?php echo $m;?>);"><i class="fa fa-times" style="color:red;"></i></a></td> 

												<td align="left" valign="middle"><button style="<?= $displayBtn; ?>" type="button" onclick="return openBtn('<?=$rows_ihm['INVOICEID']?>');" class="btn btn-danger btn-flat open_btn">Open</button></td>

										<?php

										}
								?>

									<td>

									<?php if($rows_ihm['LUPNAME']) {echo $rows_ihm['LUPNAME'] . '-' . $rows_ihm['L_UP_TIME'];}?>
									</td>
                                </tr>
                                <?php $m++;}}?>

								<input type="hidden" name="hireDaysForCheck" id="hireDaysForCheck" value="<?= $hireDayForCheck; ?>">
                                </tbody>
                                
                            </table>
                         </div>
												
					</form>
                    <div class="modal fade" id="compose-modal" tabindex="-1" role="dialog" aria-hidden="true">
						<div class="modal-dialog">
							<div class="modal-content">
								<div class="modal-header">
									<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
								</div>
								<div class="modal-body">
									<form name="frm2" id="frm2" enctype="multipart/form-data" action="<?php echo $pagename;?>" method="post"/>
                                        <div id="divPayment">
                                            
                                        </div>
                                        <div class="box-footer" align="right">
                                            <button type="submit" id="btnhide" class="btn btn-primary btn-flat" onClick="return getValid();" >Submit</button>
                                            <input type="hidden" id="action2" name="action2" value="submit1" />
                                            <input type="hidden" name="txtCRMFILE1" id="txtCRMFILE1" value="" />
                                            <input type="hidden" name="txtCRMNAME1" id="txtCRMNAME1" value="" />
                                            <input type="hidden" id="tblid" name="tblid" value=""/>
                                        </div>
									</form>
								</div>
							</div><!-- /.modal-content -->
						</div><!-- /.modal-dialog -->
					</div>
				<!--   content ends here..................-->
                </section><!-- /.content -->
            </aside><!-- /.right-side -->
			
        </div><!-- ./wrapper -->
<?php $display->footer(); ?>

    </body>
</html>

<script>


function getDownloadJson(invid,comid)
{
	$.post("options.php?id=135",{invoiceid:""+invid+"",comid:""+comid+""}, function(json_data) {
		
		var json_data = JSON.parse(json_data);
		var data = json_data.jsondata;
		var  filename = 'Hirepayment-'+json_data.inv_no+'.json';

		if(typeof data === "object"){
			data = JSON.stringify(data, undefined, 4)
		}

		var blob = new Blob([data], {type: 'text/json'}),
			e    = document.createEvent('MouseEvents'),
			a    = document.createElement('a')

		a.download = filename
		a.href = window.URL.createObjectURL(blob)
		a.dataset.downloadurl =  ['text/json', a.download, a.href].join(':')
		e.initMouseEvent('click', true, false, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null)
		a.dispatchEvent(e);
	});
}





function openBtn(invoice_id)
{

	jConfirm('Are you sure you want to open this record ?', 'Confirmation', function(r) {
			if(r){
				jAlert('<b style="font-size:25px;">Please wait . . .</b><br><br><img src="../../img/loading.gif"  />', 'Alert');
				$("#popup_container").css({"background": "rgba(255,255,255,0.1)","border": "10px solid rgba(255,255,255,0.1)","width": "100%"});
				$("#popup_content").css({"background":"none","text-align":"center"});
				$("#popup_ok,#popup_title").hide();  	
				$.post("",{invoice_id:invoice_id}, function(html) {
					if(html){
						location.reload();
					}
				});
			}
			else{return false;}
			});
}


function getValidate(var1)
{
	
	$("#txtStatus").val(var1);
		
	// let redel_date=new Date(getDateWithSpecificFormat($('[id^=txtHireTo_]').val()));
	// 	let latest_to_date = new Date(getDateWithSpecificFormat($('#i_h_listing_table tr:last td:nth-child(5)').data('tdate')));
		// if(redel_date <=  latest_to_date){
		// 	jAlert('Hire already created for these dates.', 'Alert');

		// 	$('[id^=txtHireTo_]').css({'background-color':'#ffdedec7','color':'red'});
		// 	return false;
		// }
		

	var file_temp_name = $("[id^=file_]").map(function () {return this.value;}).get().join(",");
	$('#txtCRMFILE').val(file_temp_name);
	var file_actual_name = $("[id^=name_]").map(function () {return this.value;}).get().join(",");
	$('#txtCRMNAME').val(file_actual_name);
	
	if($('#txtStatus').val()==1)
	{   
	    if($('#selApprovers').val()==null || $('#selApprovers').val()=='')
		{
		    jAlert('Please select Level 1 Approvers first.', 'Alert');
			return false;
		}
		else
		{
		    return true;
		}
	}

	if($('#txtStatus').val()==5){


			var exRate = '<?php echo $rows_rep['EXCHANGE_RATE']?>';

			var currency = '<?php echo $rows_rep['CURRENCY']?>';

			var invId = '<?php echo $rows_rep['INVOICEID']?>';

			var amt = '<?php echo $rows_rep['BALANCE_TO_OWNER']?>';

			if((exRate)=='' || (currency)==''){

				var url = 'allPdf.php?id=46&comid='+<?php echo $comid; ?>+'&preview_pdf=true&invoiceid='+invId+'&txtBalanceShipOwner='+amt+'&txtExchangeRate=0&selExchangeCurrency=null';
					

			}else{

				var url = 'allPdf.php?id=46&comid='+<?php echo $comid; ?>+'&preview_pdf=true&invoiceid='+invId+'&txtBalanceShipOwner='+amt+'&txtExchangeRate='+exRate+'&selExchangeCurrency='+currency;

			}
	
			$.ajax({

				url: url,

				cache:false,

				success:function(res){
					// console.log(res);
				},

				error:function(){

				}

			});


	}
	
}

function getVessel(elx){

$.post("options.php?id=140",{fixtureNo:""+$(elx).val()+""}, function(data){

	$(elx).closest('td').next().find('select.check').html(data)

});
}


function AddNewAddADJRow()
{

	// console.log('dpkAddadj');
	var id = $("#txtAddADJID").val();

	// console.log('')
	if($("#txtAddADJAmt_"+id).val() != "" && $("#txtAddDesADJ_"+id).val() != "" && $("#txtCORCIDFORADDADJ_"+id).val() != "")
	{
		id = (id - 1) + 2;
		$('<tr id="addadj_Row_'+id+'"><td align="center"><a href="#pr'+id+'" onClick="removeAddAdjRow('+id+');"><i class="fa fa-times" style="color:red;"></i></a></td><td><select class="form-control" name="txtCORCIDFORADDADJ_'+id+'" id="txtCORCIDFORADDADJ_'+id+'" style="width:100px;" required><?php $obj->getOwnerRelatedCostListForTallyInvoice();?></select></td><td><select class="form-control" name="txtFixNoForADDADJ_'+id+'" id="txtFixNoForADDADJ_'+id+'" style="width:100px;" onchange="getVessel(this)" required><?php $obj->getFixtureNoForTallyInvoice();?></select></td><td><select class="form-control check" name="txtVesselFORADDADJ_'+id+'" id="txtVesselFORADDADJ_'+id+'" style="width:100px;" readonly></select></td><td><textarea class="form-control areasize" name="txtAddDesADJ_'+id+'" id="txtAddDesADJ_'+id+'" rows="2" placeholder="Description..." required></textarea></td><td><input type="text" name="txtAddADJAmt_'+id+'" id="txtAddADJAmt_'+id+'" class="form-control"  placeholder="Amount" autocomplete="off" value="" onKeyUp="getFullClaculation();" required/></td></tr>').appendTo("#tblAddADJ");
		$("#txtAddADJID").val(id);
		$("[id^=txtAddADJAmt_]").numeric();	
	}
}



function AddNewLESSADJRow()
{

	// console.log('dpkAddadj');
	var id = $("#txtLESSADJID").val();

	// console.log('')
	if($("#txtLessADJAmt_"+id).val() != "" && $("#txtLessDesADJ_"+id).val() != "" && $("#txtCORCIDFORLESSADJ_"+id).val() != "")
	{
		id = (id - 1) + 2;
		$('<tr id="lessadj_Row_'+id+'"><td align="center"><a href="#pr'+id+'" onClick="removeLessAdjRow('+id+');"><i class="fa fa-times" style="color:red;"></i></a></td><td><select class="form-control" name="txtCORCIDFORLESSADJ_'+id+'" id="txtCORCIDFORLESSADJ_'+id+'" style="width:100px;" required><?php $obj->getOwnerRelatedCostListForTallyInvoice();?></select></td><td><select class="form-control" name="txtFixNoForLESSADJ_'+id+'" id="txtFixNoForLESSADJ_'+id+'" style="width:100px;" onchange="getVessel(this)" required><?php $obj->getFixtureNoForTallyInvoice();?></select></td><td><select class="form-control check" name="txtVesselFORLESSADJ_'+id+'" id="txtVesselFORLESSADJ_'+id+'" style="width:100px;" readonly></select></td><td><textarea class="form-control areasize" name="txtLessDesADJ_'+id+'" id="txtLessDesADJ_'+id+'" rows="2" placeholder="Description..." required></textarea></td><td><input type="text" name="txtLessADJAmt_'+id+'" id="txtLessADJAmt_'+id+'" class="form-control"  placeholder="Amount" autocomplete="off" value="" onKeyUp="getFullClaculation();" required/></td></tr>').appendTo("#tblLessADJ");
		$("#txtLESSADJID").val(id);
		$("[id^=txtLessADJAmt_]").numeric();	
	}
}




function removeAddAdjRow(var1)
{
		jConfirm('Are you sure you want to remove this entry permanently ?', 'Confirmation', function(r) {
			if(r){
					$("#addadj_Row_"+var1).remove();
					getFullClaculation();
				 }
			else{return false;}
			});
}






if($('[id^=txtHireTo_]').val() == '')
{

	
	// $('[id^=txtHireTo_]').val($('#i_h_listing_table tr:last td:nth-child(5)').data('tdate'));

}

</script>