<?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'];
$randomid  = $_REQUEST['randomid'];
if(@$_REQUEST['action'] == 'submit')
{
	$msg = $obj->insertTCInvoiceHireDetails();
	header('Location:./hireinvoicetc.php?msg='.$msg.'&comid='.$comid.'&page='.$page.'&randomid='.$randomid);
}
if (@$_REQUEST['action1'] == 'submit1')
{
	$msg = $obj->inserttcHirePaymentReceivedDetails();
	header('Location:./hireinvoicetc.php?msg='.$msg.'&comid='.$comid.'&page='.$page.'&randomid='.$randomid);
}

$id = $obj->getLatestCostSheetIDTC($comid);
$obj->viewTCEstimationTempleteRecordsNew($id);

$creatorsarr = $obj->getUsersWithAuthority('HIRE_INVOICE_CHK_CRETR');
$approverarr1 = $obj->getUsersWithAuthority('HIRE_INVOICE_CHK_APP_1');
$approverarr2 = $obj->getUsersWithAuthority('HIRE_INVOICE_CHK_APP_2');

$creator = $obj->getUserAuthority($_SESSION['uid'], 'HIRE_INVOICE_CHK_CRETR');
$approver1 = $obj->getUserAuthority($_SESSION['uid'], 'HIRE_INVOICE_CHK_APP_1');
$approver2 = $obj->getUserAuthority($_SESSION['uid'], 'HIRE_INVOICE_CHK_APP_2');


$pagename = basename($_SERVER['PHP_SELF'])."?comid=".$_REQUEST['comid'].'&page='.$_REQUEST['page']."&randomid=".$_REQUEST['randomid'];
?>
<!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},
		txtDueDate:{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},
		txtDueDate:{required: "*"},
		txtExchangeRate:{required: "*"},
		selExchangeCurrency:{required: "*"},
		txtPaymentTerms:{required: "*"},
		selBankingDetails:{required: "*"},
		txtHireFrom:{required: "*"},
		txtHireTo:{required: "*"},
		txtAttenName:{required: "*"},
		txtExchangeDate:{required: "*"}
		},
	submitHandler: function(form)  {
			jAlert('<b style="font-size:25px;">Please wait . . .</b><br><br><img src="../../img/loading.gif"  />', 'Alert');
			$("#popup_container").css({"background": "rgba(255,255,255,0.1)","border": "10px solid rgba(255,255,255,0.1)","width": "100%"});
			$("#popup_content").css({"background":"none","text-align":"center"});
			$("#popup_ok,#popup_title").hide();  
			form.submit();
		}
	});

	$(".numeric").numeric();
	$('.datepicker').datepicker({
		format: 'dd-mm-yyyy',
		autoclose:true
	});
	
	$('[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();
	});
	
	$('#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();
	});
	
	$('#rdoTaxApplicable1').on('ifChecked', function () { 
		$(this).attr('checked', true);showhidetaxDiv();
	});
	
	$('#rdoTaxApplicable2').on('ifChecked', function () { 
	   $(this).attr('checked', true);showhidetaxDiv();
	});
	
	
	$('[id^=Chk_Owner_Account_]').on('ifChecked', function () { 
	   $(this).attr('checked', true);
	   getFullClaculation();
	});
	 
	$('[id^=Chk_Owner_Account_]').on('ifUnchecked', function () { 
	   $(this).attr('checked', false);
	   getFullClaculation();
	});
	
	//-----------------------------------------------------------------
	$('#rdoGSTVAT1').on('ifChecked', function () { 
	   $(this).attr('checked', true);showhidetaxDiv();
	});
	
	$('#rdoGSTVAT2').on('ifChecked', function () { 
	   $(this).attr('checked', true);showhidetaxDiv();
	});
	
	readonlytextbox();
	showhidetaxDiv();
	
	getBankingDetailsData();
	getFullClaculation();
	
});


function readonlytextbox()
{
    if($("#txtIGST").val()>0)
	{
	    $("#txtSGST,#txtCGST").attr('readonly',true);
		$("#txtSGST,#txtCGST").val(0);
	}
	else
	{
	    $("#txtSGST,#txtCGST").attr('readonly',false);
	}
	
	if($("#txtSGST").val()>0 || $("#txtCGST").val()>0)
	{
	    $("#txtIGST").attr('readonly',true);
		$("#txtIGST").val(0);
	}
	else
	{
	    $("#txtIGST").attr('readonly',false);
	}
	getFullClaculation();
}

function showhidetaxDiv()
{
    if($("#rdoTaxApplicable1").is(":checked"))
	{
	    $("#taxRadioDiv,#taxtDiv_1,#taxtDiv_2,#taxtDiv_3,#taxtDiv_4").show();
		if($("#rdoGSTVAT1").is(":checked"))
	    {
			$("#taxtDiv_1,#taxtDiv_2,#taxtDiv_3").show();
            $("#taxtDiv_4").hide();
		}
		else
		{
		    $("#taxtDiv_1,#taxtDiv_2,#taxtDiv_3").hide();
            $("#taxtDiv_4").show();
		}
	}
	else
	{
	    $("#taxRadioDiv,#taxtDiv_1,#taxtDiv_2,#taxtDiv_3,#taxtDiv_4").hide();
	}
	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></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></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 getFullClaculation()
{
	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()!='')
				{
					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 = 0;}
				$("#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));
						$("#txtTCConBunkerAmt_"+i+"_"+j).val(parseFloat(txtTCConBunkerAmt).toFixed(2));
						ownersbunkercal = parseFloat(ownersbunkercal) + parseFloat(txtTCConBunkerAmt);
					}
				}
			}
		}
	}
	
    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('')
		}
	}
	
	for(var i =1;i<=$("#totalDaysTows").val();i++)
	{
	    var delDays1 = parseFloat(getTimeDiff($("#txtHireTo_"+i).val(),$("#txtHireFrom_"+i).val()));
		if(isNaN(delDays1)){delDays1 = 0.00000;}
		if(parseFloat(delDays1) > parseFloat($("#txtRemainingDay_"+i).val())){delDays1 = 0.00000;jAlert('Hire Days can\'t be more than Balance days.', 'Alert');}
		
		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++)
			{
			     if(txtHireperDay == $("#selOffHirePerDay_"+jj).val() && $("#txtOffHireDays_"+jj).val() > 0)
				 {
				     if($("#txtOffHireTo_"+jj).val()!='' && $("#txtOffHireFrom_"+jj).val()!='')
				     {
						 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);
					 }
				 }
			}
		}
		
		$("#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));
	}

	var delDays1 = parseFloat($("[id^=txtInvDay_]").sum()).toFixed(5);
	if(isNaN(delDays1)){delDays1 = 0.00;}
	
	var nettHire = parseFloat($("[id^=txtInvHire_]").sum()).toFixed(2);
	if(isNaN(nettHire)){nettHire = 0.00;}
	$("#txtTotalHire").val(parseFloat(nettHire).toFixed(2));
	
	
	

    var delDays1 = parseFloat(getTimeDiff($("#txtHireTo").val(),$("#txtHireFrom").val()));
	if(isNaN(delDays1)){delDays1 = 0.0000;}
	
	delDays1 = parseFloat(delDays1) - parseFloat(offhiredays);
	$("#txtHireDays").val(parseFloat(delDays1).toFixed(5));

	
	var nettHire = parseFloat(txtHireperDay) * parseFloat(delDays1);
	if(isNaN(nettHire)){nettHire = 0.00;}
	$("#txtTotalHire").val(parseFloat(nettHire).toFixed(2));
	
	if($("#ChkBallastBonus").is(":checked"))
	{
	    var txtBallastBonus = parseFloat($("#txtBallastBonus").val());if(isNaN(txtBallastBonus)){txtBallastBonus = 0.00;}
		nettHire = parseFloat(nettHire) + parseFloat(txtBallastBonus.toFixed(2));
	}
	
	var txtNetHire = parseFloat($("#txtTotalTCHire").val());
	if(isNaN(txtNetHire)){txtNetHire = 0.00;}
	

	if($("#txtCVEMonth").val() == ""){var txtCVEMonth = 0;}else{var txtCVEMonth = $("#txtCVEMonth").val();}
	var txtCVE_Amt = parseFloat(parseFloat(parseFloat(txtCVEMonth)/30)*parseFloat(delDays1));if(isNaN(txtCVE_Amt)){txtCVE_Amt = 0.00;}
	$("#txtCVE_Amt").val(parseFloat(txtCVE_Amt).toFixed(2));
	
	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 = parseFloat($("[id^=txthddnUsdAmt_]").sum()).toFixed(2);
	var otheradd = parseFloat($("[id^=txtAddDesAmt_]").sum()).toFixed(2);
	otheradd = parseFloat(otheradd) + parseFloat(txtCVE_Amt);
	var otherless = parseFloat($("[id^=txtSubDesAmt_]").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);
	
	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());
	}
	
	otherless = parseFloat(otherless) + parseFloat(txtAddrCommAmt);
	otherless = parseFloat(otherless) + parseFloat(txtBroCommAmt);
	
	var finalamt = parseFloat(nettHire) + parseFloat(otheradd) - parseFloat(otherless)  - parseFloat(ownersbunkercal);
	$("#txtFinalAmt").val(parseFloat(finalamt).toFixed(2));
	
	var txtBalanceShipOwner = parseFloat(txtNetHire) - parseFloat(finalamt) - parseFloat(txthddnAmt);
	$("#txtBalanceShipOwner").val(parseFloat(txtBalanceShipOwner).toFixed(2));
	//------------
	var txtSGST = parseFloat($("#txtSGST").val());if(isNaN(txtSGST)){txtSGST = 0;}
	var txtCGST = parseFloat($("#txtCGST").val());if(isNaN(txtCGST)){txtCGST = 0;}
	var txtIGST = parseFloat($("#txtIGST").val());if(isNaN(txtIGST)){txtIGST = 0;}
	var txtVAT = parseFloat($("#txtVAT").val());if(isNaN(txtVAT)){txtVAT = 0;}
	
	var txtSGST_Amount = parseFloat(parseFloat(finalamt)*parseFloat(txtSGST))/100;if(isNaN(txtSGST_Amount)){txtSGST_Amount = 0;}
	var txtCGST_Amount = parseFloat(parseFloat(finalamt)*parseFloat(txtCGST))/100;if(isNaN(txtCGST_Amount)){txtCGST_Amount = 0;}
	var txtIGST_Amount = parseFloat(parseFloat(finalamt)*parseFloat(txtIGST))/100;if(isNaN(txtIGST_Amount)){txtIGST_Amount = 0;}
	var txtVAT_Amount = parseFloat(parseFloat(finalamt)*parseFloat(txtVAT))/100;if(isNaN(txtVAT_Amount)){txtVAT_Amount = 0;}
	
	$("#txtSGST_Amount").val(parseFloat(txtSGST_Amount).toFixed(2));
	$("#txtCGST_Amount").val(parseFloat(txtCGST_Amount).toFixed(2));
	$("#txtIGST_Amount").val(parseFloat(txtIGST_Amount).toFixed(2));
	$("#txtVAT_Amount").val(parseFloat(txtVAT_Amount).toFixed(2));
	
	var txtInvPAmt = parseFloat($("[id^=txtInvPAmt_]").sum());
	if(isNaN(txtInvPAmt)){txtInvPAmt = 0;}
	
	finalamt = parseFloat(finalamt) - parseFloat(txtInvPAmt);
	
	if($("#rdoTaxApplicable1").is(":checked"))
	{
		if($("#rdoGSTVAT1").is(":checked"))
	    {
			var txtAmtPayableWithTax = parseFloat(finalamt) + parseFloat(txtSGST_Amount) + parseFloat(txtCGST_Amount) + parseFloat(txtIGST_Amount);
			$('#txtAmtPayableWithTax').val(parseFloat(txtAmtPayableWithTax).toFixed(2));
		}else{
			var txtAmtPayableWithTax = parseFloat(finalamt) + parseFloat(txtVAT_Amount);
			$('#txtAmtPayableWithTax').val(parseFloat(txtAmtPayableWithTax).toFixed(2));
		}
	}else{
		$('#txtAmtPayableWithTax').val(parseFloat(finalamt).toFixed(2));
	}
	
} */

function getFullClaculation()
{

	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()!='')
				{
					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 = 0;}
				$("#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));
						$("#txtTCConBunkerAmt_"+i+"_"+j).val(parseFloat(txtTCConBunkerAmt).toFixed(2));
						ownersbunkercal = parseFloat(ownersbunkercal) + parseFloat(txtTCConBunkerAmt);
					}
				}
			}
		}
	}

    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('')
		}
	}
    

	for(var i =1;i<=$("#totalDaysTows").val();i++)
	{
	    var delDays1 = parseFloat(getTimeDiff($("#txtHireTo_"+i).val(),$("#txtHireFrom_"+i).val()));
		if(isNaN(delDays1)){delDays1 = 0.00000;}
		if(parseFloat(delDays1) > parseFloat($("#txtRemainingDay_"+i).val())){delDays1 = 0.00000;jAlert('Hire Days can\'t be more than Balance days.', 'Alert');}
		
		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++)
			{
			     if(txtHireperDay == $("#selOffHirePerDay_"+jj).val() && $("#txtOffHireDays_"+jj).val() > 0)
				 {
				     if($("#txtOffHireTo_"+jj).val()!='' && $("#txtOffHireFrom_"+jj).val()!='')
				     {
						 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);
					 }
				 }
			}
		}
		
		$("#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));
	}

	var delDays1 = parseFloat($("[id^=txtInvDay_]").sum()).toFixed(5);
	if(isNaN(delDays1)){delDays1 = 0.00;}
	
	var nettHire = parseFloat($("[id^=txtInvHire_]").sum()).toFixed(2);
	if(isNaN(nettHire)){nettHire = 0.00;}
	$("#txtTotalHire").val(parseFloat(nettHire).toFixed(2));
	
	if($("#ChkBallastBonus").is(":checked"))
	{
	    var txtBallastBonus = parseFloat($("#txtBallastBonus").val());if(isNaN(txtBallastBonus)){txtBallastBonus = 0.00;}
		nettHire = parseFloat(nettHire) + parseFloat(txtBallastBonus.toFixed(2));
	}
	
	var txtNetHire = parseFloat($("#txtTotalTCHire").val());
	if(isNaN(txtNetHire)){txtNetHire = 0.00;}
	

	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($("#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 = parseFloat($("[id^=txthddnUsdAmt_]").sum()).toFixed(2);
	var otheradd = parseFloat($("[id^=txtAddDesAmt_]").sum()).toFixed(2);
	otheradd = parseFloat(otheradd) + parseFloat(txtCVE_Amt);
	var otherless = parseFloat($("[id^=txtSubDesAmt_]").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);
	
	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());
	}
	
	otherless = parseFloat(otherless) + parseFloat(txtAddrCommAmt);
	otherless = parseFloat(otherless) + parseFloat(txtBroCommAmt);
	
	var finalamt = parseFloat(nettHire) + parseFloat(otheradd) - parseFloat(otherless)  - parseFloat(ownersbunkercal);
	$("#txtFinalAmt").val(parseFloat(finalamt).toFixed(2));
	
	var txtBalanceShipOwner = parseFloat(txtNetHire) - parseFloat(finalamt) - parseFloat(txthddnAmt);
	$("#txtBalanceShipOwner").val(parseFloat(txtBalanceShipOwner).toFixed(2));
	//------------
	var txtSGST = parseFloat($("#txtSGST").val());if(isNaN(txtSGST)){txtSGST = 0;}
	var txtCGST = parseFloat($("#txtCGST").val());if(isNaN(txtCGST)){txtCGST = 0;}
	var txtIGST = parseFloat($("#txtIGST").val());if(isNaN(txtIGST)){txtIGST = 0;}
	var txtGST = parseFloat($("#txtGST").val());if(isNaN(txtGST)){txtGST = 0;}
	var txtVAT = parseFloat($("#txtVAT").val());if(isNaN(txtVAT)){txtVAT = 0;}
	
	var txtSGST_Amount = parseFloat(parseFloat(finalamt)*parseFloat(txtSGST))/100;if(isNaN(txtSGST_Amount)){txtSGST_Amount = 0;}
	var txtCGST_Amount = parseFloat(parseFloat(finalamt)*parseFloat(txtCGST))/100;if(isNaN(txtCGST_Amount)){txtCGST_Amount = 0;}
	var txtIGST_Amount = parseFloat(parseFloat(finalamt)*parseFloat(txtIGST))/100;if(isNaN(txtIGST_Amount)){txtIGST_Amount = 0;}
	var txtGST_Amount = parseFloat(parseFloat(finalamt)*parseFloat(txtGST))/100;if(isNaN(txtGST_Amount)){txtGST_Amount = 0;}
	var txtVAT_Amount = parseFloat(parseFloat(finalamt)*parseFloat(txtVAT))/100;if(isNaN(txtVAT_Amount)){txtVAT_Amount = 0;}
	
	$("#txtSGST_Amount").val(parseFloat(txtSGST_Amount).toFixed(2));
	$("#txtCGST_Amount").val(parseFloat(txtCGST_Amount).toFixed(2));
	$("#txtIGST_Amount").val(parseFloat(txtIGST_Amount).toFixed(2));
	$("#txtGST_Amount").val(parseFloat(txtGST_Amount).toFixed(2));
	$("#txtVAT_Amount").val(parseFloat(txtVAT_Amount).toFixed(2));
	
	var txtInvPAmt = parseFloat($("[id^=txtInvPAmt_]").sum());
	if(isNaN(txtInvPAmt)){txtInvPAmt = 0;}
	
	finalamt = parseFloat(finalamt) - parseFloat(txtInvPAmt);
	
	if($("#rdoTaxApplicable1").is(":checked"))
	{
		if($("#rdoGSTVAT1").is(":checked"))
	    {
			var txtAmtPayableWithTax = parseFloat(finalamt) + parseFloat(txtSGST_Amount) + parseFloat(txtCGST_Amount) + parseFloat(txtIGST_Amount);
			$('#txtAmtPayableWithTax').val(parseFloat(txtAmtPayableWithTax).toFixed(2));
		}else{
			var txtAmtPayableWithTax = parseFloat(finalamt) + parseFloat(txtVAT_Amount);
			$('#txtAmtPayableWithTax').val(parseFloat(txtAmtPayableWithTax).toFixed(2));
		}
	}else{
		$('#txtAmtPayableWithTax').val(parseFloat(finalamt).toFixed(2));
	}
	
	
	var txtAmtPayableWithTax = parseFloat($("#txtAmtPayableWithTax").val());
	if(isNaN(txtAmtPayableWithTax)){txtAmtPayableWithTax = 0;}
	
	var txtExchangeRate = parseFloat($("#txtExchangeRate").val());
	if(isNaN(txtExchangeRate)){txtExchangeRate = 0;}
	var othercurrencyamt = parseFloat(parseFloat(txtAmtPayableWithTax)*parseFloat(txtExchangeRate));
	if(isNaN(othercurrencyamt)){othercurrencyamt = 0;}
	$("#spanothercurrencyamt").text(othercurrencyamt.toFixed(2));
	if($("#selExchangeCurrency").val()!='')
	{
	    $("#spanothercurrency").text($("#selExchangeCurrency option:selected").text());
	}else
	{
	    $("#spanothercurrency").text('');
	}
	
}

function getValidate(var1)
{
	$('#txtStatus').val(var1);
	
	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;
		}
	}
	
}

function getDelete(invoiceid,comid,var1)
{ 
	jConfirm('Are you sure you want to cancel this entry permanently ?', 'Confirmation', function(r) {
	if(r){
			$.post("options.php?id=61",{invoiceid:""+invoiceid+"",comid:""+comid+""}, function(html) {
				if(html==1)
				{
					window.location.replace("hireinvoicetc.php?msg=2&comid=<?php echo $comid;?>&page=<?php echo $page;?>&randomid=<?php echo $randomid;?>");
				}
			});
		}
		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=62",{invoiceid:""+var1+""}, function(html) {
		$("#divPayment").empty();
		$("#divPayment").append(html);
		
		if($("#txtP_PR").val() > 0)
		{
			$("#rcvdbtnhide").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 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 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 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;
	}
}






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 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^=txtOffHireRate_]").numeric();	
		$(".numeric").numeric();
		$(".areasize").autosize({append: "\n"});
		$('#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;}
		});
}

</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(21); ?>
			<aside class="right-side">                
                <!-- Content Header (Page header) -->
                 <section class="content-header">
                    <h1>
                        <i class="fa fa-book"></i>&nbsp;Ops TC&nbsp;&nbsp;&nbsp;&nbsp;<small><div class="headline text-center" id="time" style="color:#000; font-weight:bold; font-size:12px;">( 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 TC&nbsp;&nbsp;&nbsp;&gt;&nbsp;&nbsp;&nbsp;In Ops at a glance TC&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 Invoice 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 Invoice 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 Invoice cancelled 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 received details saved successfully.
								</div>
								<?php }?>
						<?php }?>
				<!--   content put here..................-->
                <?php
				$sqltc = "SELECT * from chartering_tc_estimate_slave1 where TCOUTID='".$obj->getFun1()."' and RANDOMID='".$randomid."'";
				$restc 	= mysql_query($sqltc);
				$rectc 	= mysql_num_rows($restc);
				$rowstc = mysql_fetch_assoc($restc);
				
				$sqltc3 = "SELECT SUM(OFF_HIRE) as SUM, SUM(OFF_DAYS) as SUM1 from chartering_estimate_tc_slave3 where TC_SLAVE1ID='".$rowstc['TC_SLAVE1ID']."'";
				$restc3 	= mysql_query($sqltc3);
				$rectc3 	= mysql_num_rows($restc3);
				$rowstc3 = mysql_fetch_assoc($restc3);
				
				$sql = "SELECT * from invoice_tchire_master where COMID='".$comid."' and MODULEID='".$_SESSION['moduleid']."' and MCOMPANYID='".$_SESSION['company']."' and RANDOMID='".$randomid."' and STATUS <5 LIMIT 1";
				$res 	= mysql_query($sql);
				$rec 	= mysql_num_rows($res);
				$rows 	= mysql_fetch_assoc($res);
				
				$sql_all = "SELECT * from invoice_tchire_master where COMID='".$comid."' and MODULEID='".$_SESSION['moduleid']."' and MCOMPANYID='".$_SESSION['company']."' and RANDOMID='".$randomid."' and STATUS = 5 order by INVOICEID desc";
				$res_all 	= mysql_query($sql_all);
				$rec_all 	= mysql_num_rows($res_all);
				$ifballastbonus = 0;$ifdelivery = 0; $ifredelivery = 0;$ifoffhire = 0;$ifoverbunkerconsp = 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['IS_DELIVERYBUNKERS']==1){$ifdelivery = 1;}
					if($rows_all['IS_REDELIVERYBUNKERS']==1){$ifredelivery = 1;}
					if($rows_all['IS_OFFHIRE']==1){$ifoffhire = 1;}
					if($rows_all['CHK_OVERCONSP']==1){$ifoverbunkerconsp = 1;}				
				} 
				
				?>	
				<div align="right"><?php if($rec>0){?><a href="allPdf.php?id=67&comid=<?php echo $comid; ?>&invoiceid=<?php echo $rows['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="payment_grid_tc.php?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">
								TC HIRE INVOICE CREATION
                                <input type="hidden" name="txtInID" id="txtInID" value="<?php echo $rows['INVOICEID'];?>"/>
								</h2>                            
							</div><!-- /.col -->
						</div>
					
						<div class="row invoice-info">
							<div class="col-sm-3 invoice-col">
							   <strong>Invoicing Company :</strong>
								<address>
                                
									<select  name="selFromOwner" class="select form-control" id="selFromOwner">
										<?php 
										$obj->getVendorListNewForCOA(11);
										?>
									</select>
									<script>$('#selFromOwner').val('<?php echo $rows['SHIP_OWNER'];?>');</script>
								</address>
							</div><!-- /.col -->
                            
							<div class="col-sm-3 invoice-col">
							   <strong>To :</strong>
								<address>
									<?php echo $obj->getVendorListNewData($rowstc['TTL_REV_VENDOR'],"NAME");?><br/>
                                    <?php echo $obj->getVendorListNewData($rowstc['TTL_REV_VENDOR'],"STREET_1");?><br/>
                                    <?php if($obj->getVendorListNewData($rowstc['TTL_REV_VENDOR'],"STREET_2")!=''){echo $obj->getVendorListNewData($rowstc['TTL_REV_VENDOR'],"STREET_2").'<br/>';}?>
                                     <?php echo $obj->getVendorListNewData($rowstc['TTL_REV_VENDOR'],"CITY");?> <?php echo $obj->getVendorListNewData($rowstc['TTL_REV_VENDOR'],"COUNTRY");?> <?php echo $obj->getVendorListNewData($rowstc['TTL_REV_VENDOR'],"CITY_POSTAL_CODE");?>
								</address>
							</div><!-- /.col -->
                            <div class="col-sm-3 invoice-col">
								<strong>Vendor (Manual):</strong>
								<address>
								<?php if($rec > 0){?>
								   <textarea class="form-control areasize" name="txtManualVendorName" id="txtManualVendorName" rows="4" placeholder="Vendor..."><?php echo $rows['MANUAL_VENDOR_NAME'];?></textarea>
								<?php }else{?>
								   <textarea data-test="" class="form-control areasize" name="txtManualVendorName" id="txtManualVendorName" rows="4" placeholder="Vendor..."><?php echo $obj->getVendorListNewBasedOnID($rowstc['TTL_REV_VENDOR']);?> <?php echo stripslashes($obj->getVendorDataBasedOnID($rowstc['TTL_REV_VENDOR'],'STREET_1'));?>
								   
                                    <?php 
									if ($obj->getVendorDataBasedOnID($rowstc['TTL_REV_VENDOR'],'CITY') != '') {

										
										echo stripslashes($obj->getVendorDataBasedOnID($rowstc['TTL_REV_VENDOR'],'CITY'));
									}

									if ($obj->getVendorDataBasedOnID($rowstc['TTL_REV_VENDOR'],'COUNTRY') != '') {
										
										echo stripslashes($obj->getVendorDataBasedOnID($rowstc['TTL_REV_VENDOR'],'COUNTRY'));
									}
									if ($obj->getVendorDataBasedOnID($rowstc['TTL_REV_VENDOR'],'CITY_POSTAL_CODE') != '') {
										
										echo stripslashes($obj->getVendorDataBasedOnID($rowstc['TTL_REV_VENDOR'],'CITY_POSTAL_CODE'));
									}								
									?>                                  
                                    </textarea>
								<?php }?>
								</address>
							</div><!-- /.col --> 
							<div class="col-sm-3 invoice-col">
								<strong>Hire Details :</strong>
								<address>
								    TC NO :- <?php echo $obj->getFun7();?><br/>
                                    Vessel :- <?php echo $obj->getVesselIMOData($obj->getFun3(),"VESSEL_NAME");?><br/>
                                    CP Date :- <?php echo date('d-m-Y',strtotime($obj->getFun9()));?><br/>
                                    DEL :- <?php echo $obj->getFun44();?><br/>
                                    RE DEL :- <?php echo $obj->getFun53();?>
								</address>
							</div><!-- /.col -->
						</div>
						
						<br/>
						<div class="row invoice-info">
						   <div class="col-sm-5 invoice-col">
                               <div class="table-responsive">
                                    <table class="table">
                                        <tbody>
                                        <tr>
                                            <th width="47%" style="width:50%;padding-top:15px;padding-bottom:15px;">Invoice Type :</th>
                                            <td width="53%"><select  name="selIType" class="select form-control" id="selIType"><?php $obj->getInvoiceType();?></select></td>
                                        </tr>
                                        <script>$("#selIType").val('<?php echo $rows['INVOICE_TYPE'];?>');</script>
                                        <tr>
                                            <th style="width:50%;padding-top:15px;padding-bottom:15px;">Attn :</th>
                                            <td><input type="text" name="txtAttenName" id="txtAttenName" class="form-control"  placeholder="Attn" autocomplete="off" value="<?php echo $rows['ATTEN'];?>"/></td>
                                        </tr>
                                        <tr>
                                            <th style="padding-top:15px;padding-bottom:15px;">Invoice Number :</th>
                                            <td><input type="text" name="txtInvNo" id="txtInvNo" class="form-control"  placeholder="Invoice Number" autocomplete="off" value="<?php echo $rows['INVOICE_NO'];?>"/></td>
                                        </tr>
                                        <?php
										$invdate = date('d-m-Y',strtotime($rows['INVOICE_DATE']));
										if($invdate=='01-01-1970'){$invdate = '';}
										$duedate = date('d-m-Y',strtotime($rows['DUE_DATE']));
										if($duedate=='01-01-1970'){$duedate = '';}
										$exchangeDate = date('d-m-Y',strtotime($rows['EXCHANGE_DATE']));
										if($exchangeDate=='01-01-1970'){$exchangeDate = '';}
										?>
                                        <tr>
                                            <th style="padding-top:15px;padding-bottom:15px;">Invoice 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;">Due Date :</th>
                                            <td><input type="text" name="txtDueDate" id="txtDueDate" class="form-control datepicker"  placeholder="dd-mm-yyyy" autocomplete="off" value="<?php echo $duedate;?>"/></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['EXCHANGE_RATE'];?>"/><input type="hidden" name="txtOldExchangeRate" id="txtOldExchangeRate" value="<?php echo $rowstc['EXCHANGE_RATE'];?>"/><input type="hidden" name="txtOldExchangeCurrency" id="txtOldExchangeCurrency" value="<?php echo $rowstc['EXCHANGE_CURRENCY'];?>"/><input type="hidden" name="txtOldHireRate" id="txtOldHireRate" value="<?php echo $rowstc['DAILY_GROSS_HIRE_EST'];?>"/></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['EXCHANGE_CURRENCY'];?>');</script>
                                        <tr>
                                            <th style="width:50%;padding-top:15px;padding-bottom:15px;">Delivery Date :</th>
                                            <td><input type="text" name="txtDelDate" id="txtDelDate" class="form-control" readonly style="background-color:#eee;"  placeholder="dd-mm-yyyy" autocomplete="off" value="<?php echo date('d-m-Y',strtotime($rowstc['DEL_DATE_EST']));?>"/></td>
                                        </tr>
                                        <tr>
                                            <th style="width:50%;padding-top:15px;padding-bottom:15px;">Re Delivery Date :</th>
                                            <td><input type="text" name="txtReDelDate" id="txtReDelDate" class="form-control" readonly style="background-color:#eee;" placeholder="dd-mm-yyyy" autocomplete="off" value="<?php echo date('d-m-Y',strtotime($rowstc['REDEL_DATE_EST']));?>"/></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['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['DESCRIPTION'];?></textarea></td>
                                        </tr>
                                        <tr>
                                            <th style="padding-top:15px;padding-bottom:15px;">Banking Details :</th>
                                            <td><select  name="selBankingDetails" class="select form-control" id="selBankingDetails" onChange="getBankingDetailsData()"><?php $obj->getBankingDetails();?></select></td>
                                            <script>$('#selBankingDetails').val('<?php echo $rows['BANKINGID'];?>');</script>
                                        </tr>
                                     </tbody>
                                     <tbody id="bankingrow" style="display:none;">
                                        <tr>
											<td>Address</td>
											<td><span id="span_1_0"></span></td>
										</tr>
										<tr>
											<td>Beneficiary A/C No.</td>
											<td><span id="span_1_1"></span></td>
										</tr>
										<tr>
											<td>Beneficiary Bank</td>
											<td><span id="span_1_2"></span></td>
										</tr>
										<tr>
											<td>Beneficiary Bank Address</td>
											<td><span id="span_1_3"></span></td>
										</tr>
										<tr>
											<td>Beneficiary Bank Swift Code</td>
											<td><span id="span_1_4"></span></td>
										</tr>
										<tr>
											<td>IBAN No.</td>
											<td><span id="span_1_5"></span></td>
										</tr>
										<tr>
											<td>FED ABA</td>
											<td><span id="span_1_6"></span></td>
										</tr>
										<tr>
											<td colspan="4" style="background-color:grey; color:white;">CORRESPONDENT DETAILS</td>
										</tr>
										<tr>
											<td>Correspondent Bank Name</td>
											<td><span id="span_1_7"></span></td>
										</tr>
										
                                        <tr>
                                            <td>Correspondent Bank Address</td>
											<td><span id="span_1_9"></span></td>
										</tr>
                                        <tr>
											<td>Account Number</td>
											<td><span id="span_1_10"></span></td>
										</tr>
                                        <tr>
											<td>Swift Code</td>
											<td><span id="span_1_8"></span></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['UPLOAD'] != '')
											{ 
												$fileid = explode(",",$rows['UPLOAD']); 
												$filename = explode(",",$rows['UPLOAD_NAME']); ?>	


												<tr>
													<td colspan="2">
												  Previous Attachments:
													</td>
												</tr>

											   <?php
												// $j =1;
												for($j=0;$j<sizeof($fileid);$j++)
												{
												?>
											
												<tr id="row_file_<?php echo ($j+1);?>">

														<td width="90%" align="left" class="input-text"  valign="top"><a href="../../attachment/<?php echo $fileid[$j]; ?>" target="_blank" style="color:blue;" data-toggle="tooltip" data-original-title="<?php echo $filename[$j];?>"><i class="fa fa-external-link"></i>&nbsp;&nbsp;<?php echo $filename[$j];?></a>
														<input type="hidden" name="file_<?php echo $j+1;?>" id="file_<?php echo $j+1;?>" value="<?php echo $fileid[$j]; ?>" />
														<input type="hidden" name="name_<?php echo $j+1;?>" id="name_<?php echo $j+1;?>" value="<?php echo $filename[$j]; ?>" />
														</td>
														<td ><a href="#1" onClick="Del_Upload(<?php echo $j+1;?>);"><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-7 invoice-col">
							   <div class="table-responsive">
                                    <table class="table">
                                        <tbody>
                                        <tr>
										<td colspan="4">
										<table class="table">
											<tbody>
											<tr>
												<td style="padding-top:15px;padding-bottom:15px;" colspan="3">TC Days:</td>
										<?php $sql_2 = "select SUM(HIRE_DAYS) as TOTAL_DAYS from chartering_estimate_tc_slave8 where TC_SLAVE1ID='".$rowstc['TC_SLAVE1ID']."'";	
										$result_2 = mysql_query($sql_2);
										$rows_2 = mysql_fetch_assoc($result_2);?>
												<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 $rows_2['TOTAL_DAYS'];?>"/>
											</tr>
											</tbody>
										</table>
										<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 
							  $ballastbonus = 0;$hirearray_cell = array();
							  $sql_2 = "select chartering_estimate_tc_slave8.RANDOMID, chartering_estimate_tc_slave8.DEL_DATE, chartering_estimate_tc_slave8.RE_DEL_DATE, chartering_estimate_tc_slave8.HIRE_RATE, chartering_estimate_tc_slave8.HIRE_DAYS, chartering_estimate_tc_slave8.HIRE_AMT from chartering_estimate_tc_slave8 where chartering_estimate_tc_slave8.TC_SLAVE1ID='".$rowstc['TC_SLAVE1ID']."' ";	
									$result_2 = mysql_query($sql_2);$i = 0;
									$num_2 = mysql_num_rows($result_2);
									while($rows_2 = mysql_fetch_assoc($result_2))
									{$i++;
									$ballastbonus = $ballastbonus + $rows_2['BALLAST_BONUS'];
									$sql_invslave = "select sum(UTILISED_DAYS) as DAYS from invoice_tchire_slave5 inner join invoice_tchire_master on invoice_tchire_master.INVOICEID=invoice_tchire_slave5.INVOICEID where invoice_tchire_master.COMID='".$comid."' and MODULEID='".$_SESSION['moduleid']."' and MCOMPANYID='".$_SESSION['company']."' and STATUS=5 and invoice_tchire_slave5.RANDOMID='".$rows_2['RANDOMID']."'";
									$res_invslave = mysql_query($sql_invslave);
									$result_invslave = mysql_fetch_assoc($res_invslave);
									
									$sql_invslave1 = "select invoice_tchire_slave5.UTILISED_DAYS, invoice_tchire_slave5.HIRE_AMT, invoice_tchire_slave5.HIRE_RATE, invoice_tchire_slave5.HIRE_FROM, invoice_tchire_slave5.HIRE_TO from invoice_tchire_slave5 inner join invoice_tchire_master on invoice_tchire_master.INVOICEID=invoice_tchire_slave5.INVOICEID where invoice_tchire_master.COMID='".$comid."' and MODULEID='".$_SESSION['moduleid']."' and MCOMPANYID='".$_SESSION['company']."' and STATUS<5 and invoice_tchire_slave5.RANDOMID='".$rows_2['RANDOMID']."'";


									$res_invslave1 = mysql_query($sql_invslave1);
									$result_invslave1 = mysql_fetch_assoc($res_invslave1);
									?>
                                        <tr data-sql="<?=$sql_invslave1?>">
											<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


											$hirearray_cell[$rows_2['HIRE_RATE']] = $rows_2['HIRE_RATE'];
											$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['DEL_DATE']));}
											?>
											<td><input type="text" readonly style="pointer-events:none !important"  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>
											<th><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"/></th>
                                            
											<th><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'];?>"/>
											</th>
											
											<input type="hidden" name="txtRandom_<?=$i?>" id="txtRandom_<?=$i?>" value="<?php echo $rows_2['RANDOMID'];?>"/>
											</td>
                                        </tr>
								<?php }?>
								       </table>

										</td>	
										</tr>
                                        <tr>
                                            <th style="padding-top:15px;padding-bottom:15px;" colspan="3">Total 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['HIRE_INV_AMT'];?>"/><input type="hidden" name="totalDaysTows" id="totalDaysTows" value="<?=$i?>"/></td>
                                        </tr>
                                        
                                        <tr>
                                            <th style="padding-top:15px;padding-bottom:15px;" colspan="4">Other Add</th>
                                        </tr>
                                        <tr>
                                            <th style="padding-top:15px;padding-bottom:15px;" colspan="3"><input name="ChkBallastBonus" class="checkbox" id="ChkBallastBonus" type="checkbox" value="1" <?php if($rows['CHK_BALLAST_BONUS']==1){echo 'checked';}?>/>&nbsp;&nbsp;Ballast Bonus :</th>
											<?php if($rows['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" readonly style="background-color:#eee;"  placeholder="Ballast Bonus" autocomplete="off" value="<?php echo $rowstc['BALLAST_BONUS_AMT'];?>"/></span></td>
                                        </tr>
                                        <tr>
                                            <td colspan="2" style="font-size:13px;"><strong>&nbsp;&nbsp;&nbsp;<i>CVE(<?php echo $rowstc['EXCHANGE_CURRENCY'];?>)</strong></i></td>
                                            <td width="30%"><input type="text" name="txtCVEMonth" id="txtCVEMonth" class="form-control numeric"  placeholder="CVE" autocomplete="off" value="<?php echo $rows['CVE_MONTH'];?>" onKeyUp="getFullClaculation();"/></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['CVE_AMOUNT'];?>"/></td>
                                        </tr>
										
                                     </tbody>
                                     <?php 
									    if($rec>0)
										{
											$sql2 = "select * from invoice_tchire_slave1 where INVOICEID='".$rows['INVOICEID']."' and IDENTIFY='ADD'";
										}else{
										    $sql2 = "select * from invoice_tchire_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="15%" align="center"><a href="#pr<?php echo $i;?>" onClick="removeAddRow(<?php echo $i;?>);"><i class="fa fa-times" style="color:red;"></i></a></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></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>
                                           <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 $rows['ADDRESS_COMMISSION'];?>" onKeyUp="getFullClaculation();"/></td>
                                               <td><input type="text" name="txtAddrCommAmt" id="txtAddrCommAmt" class="form-control numeric" readonly  placeholder="Amount" autocomplete="off" value="<?php echo $rows['ADDRESS_COMMISSION_AMOUNT'];?>"/></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 $rows['BROKER_COMMISSION'];?>" onKeyUp="getFullClaculation();"/></td>
                                               <td><input type="text" name="txtBroCommAmt" id="txtBroCommAmt" class="form-control numeric" readonly  placeholder="Amount" autocomplete="off" value="<?php echo $rows['BROKER_COMMISSION_AMOUNT'];?>"/></td>
                                           </tr>
                                      <?php 
									    if($rec>0)
										{
											$sql2 = "select * from invoice_tchire_slave1 where INVOICEID='".$rows['INVOICEID']."' and IDENTIFY='SUB'";
										}else{
										    $sql2 = "select * from invoice_tchire_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></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></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="3"><input name="ChkShowOffHire" class="checkbox" id="ChkShowOffHire" type="checkbox" value="1" <?php if($rows['IS_OFFHIRE']==1){echo 'checked';}?>/>&nbsp;&nbsp;Off-hire(<?php echo $rowstc['EXCHANGE_CURRENCY'];?>)</th>
                                               <?php if($rows['IS_OFFHIRE']==1){$offhiredisplay = '';}else{$offhiredisplay = 'none';}?>
                                               <td><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></td>
                                            </tr>
											<?php if($rows['IS_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 && $previnvoiceid=='')
												 	 {
														 $sql3 = "select * from chartering_estimate_tc_slave3 where TC_SLAVE1ID='".$rowstc['TC_SLAVE1ID']."'";
													 }
													 else if($rec>0)
													 {
														 $sql3 = "select * from invoice_tchire_slave4 where INVOICEID='".$rows['INVOICEID']."'";
													 }else{
														 $sql3 = "select * from invoice_tchire_slave4 where INVOICEID='".$previnvoiceid."'";
													 }
													 $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="17%"><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="16%"><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="16%"><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><select name="selOffHirePerDay_<?php echo $k;?>" id="selOffHirePerDay_<?php echo $k;?>" class="form-control"></select></td>
															<script>$("#selOffHirePerDay_<?php echo $k;?>").html($("#hirearraycell").html());</script>
															<td valign="top" width="13%"><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="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_<?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="17%"><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="16%"><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="16%"><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="10%"><select name="selOffHirePerDay_<?php echo $k;?>" id="selOffHirePerDay_<?php echo $k;?>" class="form-control"></select></td>
															<script>$("#selOffHirePerDay_<?php echo $k;?>").html($("#hirearraycell").html());$("#selOffHirePerDay_<?php echo $k;?>").val(<?php echo $rows3['OFF_HIRE_RATE'];?>);</>
															<td valign="top" width="13%"><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="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_<?php echo $k;?>">
																 <?php 
																 if($rec==0 && $previnvoiceid=='')
																 {
																	 $sql4 = "select * from chartering_estimate_tc_slave7 where TC_SLAVE1ID='".$rowstc['TC_SLAVE1ID']."' and TC_SLAVE3ID='".$rows3['TC_SLAVE3ID']."'";
																 }
																 else if($rec>0)
																 {
																	 $sql4 = "select * from invoice_tchire_slave41 where INVOICEID='".$rows['INVOICEID']."' and INVOICE_SLAVE4ID='".$rows3['INVOICE_SLAVE4ID']."'";
																 }else{
																	 $sql4 = "select * from invoice_tchire_slave41 where INVOICEID='".$previnvoiceid."' and INVOICE_SLAVE4ID='".$rows3['INVOICE_SLAVE4ID']."'";
																 }
																 $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++;?>
																   <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['BUNKER_QTY'];?>" /></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['BUNKER_PRICE'];?>" /></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['BUNKER_AMT'];?>"/></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>
                                            <tr>
                                               <th align="left" colspan="4"><input name="ChkDeliveryBunker" class="checkbox" id="ChkDeliveryBunker" type="checkbox" value="1" <?php if($rows['IS_DELIVERYBUNKERS']==1){echo 'checked';}?> />&nbsp;&nbsp;Delivery Bunkers</th>
                                            </tr>
                                            <?php if($rows['IS_DELIVERYBUNKERS']==1){$deliverydisplay = '';}else{$deliverydisplay = 'none';}?>
											
											
											<tr id="DivBunkerDelivery_0" style="display:<?php echo $deliverydisplay;?>;">
                                            <td>Bunker Grade</td>
                                            <td>Qty(MT)</td>
                                            <td>Price(USD)</td>
                                            <td>Amount(USD)</td>
                                            </tr>
                                            <tbody id="bunkerDeliverybody">
									<?php 
									    if($rec==0 && $previnvoiceid == '')
										{
											$sqltc4 = "SELECT BUNKERID, AMOUNT, QTY, PRICE, IDENTITY from chartering_estimate_tc_slave5 where TC_SLAVE1ID='".$rowstc['TC_SLAVE1ID']."'and IDENTITY='DEL'";
											$restc4 	= mysql_query($sqltc4) or die($sqltc4);
											$rectc4 	= mysql_num_rows($restc4);$del = 0;
											while($rowstc4 = 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 $rowstc4['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 $rowstc4['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 $rowstc4['AMOUNT'];?>"/></td>
										    </tr>
											<script>$("#selDELBunker_<?php echo $del;?>").val(<?php echo $rowstc4['BUNKERID'];?>);</script> 
									<?php   }
										}
										else
										{	
										    if($rec>0)
										    {
                                            	$sql_inv2 = "select BUNKERID, BUNKER_QTY, BUNKER_PRICE, BUNKER_PER, BUNKER_AMT, IDENTIFY, BUNKER_PER_AMT from invoice_tchire_slave2 where INVOICEID='".$rows['INVOICEID']."' and IDENTIFY='DEL'"; 
											}else
											{
											    $sql_inv2 = "select BUNKERID, BUNKER_QTY, BUNKER_PRICE, BUNKER_PER, BUNKER_AMT, IDENTIFY, BUNKER_PER_AMT from invoice_tchire_slave2 where INVOICEID='".$previnvoiceid."' and IDENTIFY='DEL'"; 
											}
											$res_inv2 = mysql_query($sql_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 }?>
                                            <tr style="display:none;">
											   <td align="left" colspan="4"><input type="hidden" name="txtAddDELID" id="txtAddDELID" value="<?php echo $del;?>"/></td>
											</tr>

										
                                            <tr>
                                               <th align="left" colspan="4"><input name="ChkReDeliveryBunker" class="checkbox" id="ChkReDeliveryBunker" type="checkbox" value="1" <?php if($rows['IS_REDELIVERYBUNKERS']==1){echo 'checked';}?> />&nbsp;&nbsp;Re-Delivery Bunkers</th>
                                            </tr>
                                            <?php if($rows['IS_REDELIVERYBUNKERS']==1){$redeliverydisplay = '';}else{$redeliverydisplay = 'none';}?>
											
											
											<tr id="DivBunkerReDelivery_0" style="display:<?php echo $redeliverydisplay;?>;">
                                            <td>Bunker Grade</td>
                                            <td>Qty(MT)</td>
                                            <td>Price(USD)</td>
                                            <td>Amount(USD)</td>
                                            </tr>
									<?php 
									    if($rec==0 && $previnvoiceid == '')
										{
											$sqltc4 = "SELECT BUNKERID, AMOUNT, QTY, PRICE, IDENTITY from chartering_estimate_tc_slave5 where TC_SLAVE1ID='".$rowstc['TC_SLAVE1ID']."'and IDENTITY='REDEL'";
											$restc4 	= mysql_query($sqltc4) or die($sqltc4);
											$rectc4 	= mysql_num_rows($restc4);$redel = 0;
											while($rowstc4 = 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 $rowstc4['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 $rowstc4['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 $rowstc4['AMOUNT'];?>"/></td>
										    </tr>
                                            <script>$("#selReDELBunker_<?php echo $redel;?>").val(<?php echo $rowstc4['BUNKERID'];?>);</script>   
									<?php   }
										}
										else
										{		
											if($rec>0)
										    {
                                            	$sql_inv2 = "select BUNKERID, BUNKER_QTY, BUNKER_PRICE, BUNKER_PER, BUNKER_AMT, IDENTIFY, BUNKER_PER_AMT from invoice_tchire_slave2 where INVOICEID='".$rows['INVOICEID']."' and IDENTIFY='REDEL'"; 
											}else
											{
											    $sql_inv2 = "select BUNKERID, BUNKER_QTY, BUNKER_PRICE, BUNKER_PER, BUNKER_AMT, IDENTIFY, BUNKER_PER_AMT from invoice_tchire_slave2 where INVOICEID='".$previnvoiceid."' and IDENTIFY='REDEL'"; 
											}
											$res_inv2 = mysql_query($sql_inv2);$redel = 0;
											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 }
									   }?>
									        <tr style="display:none;">
											   <td align="left" colspan="4"><input type="hidden" name="txtAddREDELID" id="txtAddREDELID" value="<?php echo $redel;?>"/></td>
											</tr>
											
										   
										   
										   
										   
										   
										   <?php if($rows['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['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(USD)</td>
                                            <td>Amount(USD)</td>
                                            </tr>
                                            <tbody id="bunkerOverConspbody">
									<?php   if($rec>0)
											{
												$sql2 = "select * from invoice_tchire_slave2 where INVOICEID='".$rows['INVOICEID']."' and IDENTIFY='OVERCONSP'";
											}else{
												$sql2 = "select * from invoice_tchire_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_tchire_slave1 where INVOICEID='".$rows['INVOICEID']."' and IDENTIFY='HOLD_CLEANING'";
										}else{
										    $sql2 = "select * from invoice_tchire_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{?>
											<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="" 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_tchire_slave1 where INVOICEID='".$rows['INVOICEID']."' and IDENTIFY='HIRE_SURVEY'";
										}else{
										    $sql2 = "select * from invoice_tchire_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>Final Amount (<?php echo $rowstc['EXCHANGE_CURRENCY'];?>) to invoice</strong></td>
                                                
                                                <td><input type="text" name="txtFinalAmt" id="txtFinalAmt" class="form-control"  placeholder="0.00" autocomplete="off" readonly value="<?php echo $rows['FINAL_AMOUNT'];?>"/></td>
                                            </tr>
											
											<tr>
                                                <td colspan="2"><strong>GST/VAT Applicable</strong></td>
                                                <td><input name="rdoTaxApplicable" class="checkbox" id="rdoTaxApplicable1" type="radio" value="1" <?php if($rows['RDOTAXAPPLICABLE'] == 1) echo "checked"; ?> <?php if($rec == 0){?>checked<?php }?>/>&nbsp;&nbsp;Yes&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input name="rdoTaxApplicable" class="checkbox" id="rdoTaxApplicable2" type="radio" value="2" <?php if($rows['RDOTAXAPPLICABLE'] == 2) echo "checked"; ?>/>&nbsp;&nbsp;No</td>
												<td><span id="taxRadioDiv"><input name="rdoGSTVAT" class="checkbox" id="rdoGSTVAT1" type="radio" value="1" <?php if($rows['RDOVATGST'] == 1) echo "checked"; ?> <?php if($rec == 0){?>checked<?php }?>/>&nbsp;&nbsp;GST&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input name="rdoGSTVAT" class="checkbox" id="rdoGSTVAT2" type="radio" value="2" <?php if($rows['RDOVATGST'] == 2) echo "checked"; ?>/>&nbsp;&nbsp;VAT</span></td>
                                           </tr>
										   <tr id="taxtDiv_1">
                                                <td colspan="2"><i>SGST (%)</i></td>
                                                <td><input type="text" name="txtSGST" id="txtSGST" class="form-control numeric"  placeholder="%" autocomplete="off" value="<?=$rows['SGST_PERCENT'];?>" onKeyUp="readonlytextbox();getFullClaculation();"/></td>
												<td><input type="text" name="txtSGST_Amount" id="txtSGST_Amount" class="form-control numeric"  placeholder="%" autocomplete="off" readonly="true" value="<?=$rows['SGST_PERCENT_AMOUNT'];?>"/></td>
                                           </tr>
										   <tr id="taxtDiv_2">
                                                <td colspan="2"><i>CGST (%)</i></td>
                                                <td><input type="text" name="txtCGST" id="txtCGST" class="form-control numeric"  placeholder="%" autocomplete="off" value="<?=$rows['CGST_PERCENT'];?>" onKeyUp="readonlytextbox();getFullClaculation();"/></td>
												<td><input type="text" name="txtCGST_Amount" id="txtCGST_Amount" class="form-control numeric"  placeholder="%" autocomplete="off" readonly="true" value="<?=$rows['CGST_PERCENT_AMOUNT'];?>"/></td>
                                           </tr>
										   <tr id="taxtDiv_3">
                                                <td colspan="2"><i>IGST (%)</i></td>
                                                <td><input type="text" name="txtIGST" id="txtIGST" class="form-control numeric"  placeholder="%" autocomplete="off" value="<?=$rows['IGST_PERCENT'];?>" onKeyUp="readonlytextbox();getFullClaculation();"/></td>
												<td><input type="text" name="txtIGST_Amount" id="txtIGST_Amount" class="form-control numeric"  placeholder="%" autocomplete="off" readonly="true" value="<?=$rows['IGST_PERCENT_AMOUNT'];?>"/></td>
                                           </tr>
										   <tr id="taxtDiv_4">
                                                <td colspan="2"><i>VAT (%)</i></td>
                                                <td><input type="text" name="txtVAT" id="txtVAT" class="form-control numeric"  placeholder="%" autocomplete="off" value="<?=$rows['VAT_PERCENT'];?>" onKeyUp="getFullClaculation();"/></td>
												<td><input type="text" name="txtVAT_Amount" id="txtVAT_Amount" class="form-control numeric"  placeholder="%" autocomplete="off" readonly="true" value="<?=$rows['VAT_PERCENT_AMOUNT'];?>"/></td>
                                           </tr>
										   
										   <?php   $sql1 = "SELECT * from invoice_tchire_master where COMID='".$comid."' and MODULEID='".$_SESSION['moduleid']."' and MCOMPANYID='".$_SESSION['company']."' and RANDOMID='".$randomid."' and STATUS>=5 order by INVOICEID";
											$res1 = mysql_query($sql1);
											$i =0;
											while($rows1 = mysql_fetch_assoc($res1))
											{ $i++;
											?>
											<tr>
												<th style="padding-top:15px;padding-bottom:15px;" colspan="3"><?php echo $rows1['I_TYPE'].'('.$rows1['INVOICE_NO'].')';?></th>
												<td><input type="text"  name="txtInvPAmt_<?php echo $i;?>" id="txtInvPAmt_<?php echo $i;?>" class="form-control" readonly value="<?php echo $rows1['P_AMT'];?>" /></td>	
											</tr>
										<?php }?>
										   
										   <tr>
                                                <td colspan="3"><strong>Amount Payable (After TAX)</strong></td>
                                                <td><input type="text"  name="txtAmtPayableWithTax" id="txtAmtPayableWithTax" class="form-control" readonly value="<?php echo $rows['NET_PAYABLE_TAX'];?>" /></td>
                                           </tr>
                                            <tr style="display:none;">
                                            <th style="padding-top:15px;padding-bottom:15px;" colspan="3">Balance to Shipowner(<?php echo $rowstc['EXCHANGE_CURRENCY'];?>) :</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['BALANCE_TO_OWNER'];?>"/></td>
                                        </tr>
                                        
                                       </tbody>
                                   </table>
                               </div>
							   
							   <?php //if(($rec == 0 && !empty($approverarr1)) || ($rec > 0 )){?>
							   <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_INVOICE_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['APPROVERS']);?></select>
								   </div>
							   </div>
							   <div class="row invoice-info">
							       <div class="col-sm-12 invoice-col">&nbsp;</div>
							   </div>
						<?php //}?>
							   
						   </div><!-- /.col -->
						</div>
                        
					
						
						
                       <div class="box-footer" align="right">
							<input type="hidden" name="txtStatus" id="txtStatus" value="" />
							<!--<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="action" id="action" value="submit" />
						    <input type="hidden" name="txtDEL_ID" id="txtDEL_ID" value="0"/>
							
						<?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;}
						  ?>
								<button type="submit" class="btn btn-primary btn-flat" onClick="return getValidate(0);">Submit to edit</button>&nbsp;&nbsp;
								<button type="submit" class="btn btn-warning btn-flat" onClick="return getValidate(<?=$status;?>);">Send for Approval</button>
						  <?php }else if($rec>0 && ($rows['STATUS']==1 || $rows['STATUS']==4) && $approver1 == 1){
									 if(empty($approverarr2)){$status = 5;}
									 else{$status = 3;}
							   ?>
								<button type="submit" class="btn btn-primary btn-flat" onClick="return getValidate(2);">Send for Review</button>&nbsp;&nbsp;
								<button type="submit" class="btn btn-warning btn-flat" onClick="return getValidate(<?=$status;?>);">Submit & Approve</button>
						  <?php }else if($rec>0 && $rows['STATUS']==3 && $approver2 == 1){
								   if(empty($approverarr1)){$status = 2;}
								   else{$status = 4;}
						  ?>
								<button type="submit" class="btn btn-primary btn-flat" onClick="return getValidate(<?=$status;?>);">Send for Review</button>&nbsp;&nbsp;
								<button type="submit" class="btn btn-warning btn-flat" onClick="return getValidate(5);">Submit & Approve</button>
						  <?php }?>
							<input type="hidden" name="txtCRMFILE" id="txtCRMFILE" value="" />
					        <input type="hidden" name="txtCRMNAME" id="txtCRMNAME" value="" />
				        </div>
                        
                        <br/><br/>
                        <div class="box-body no-padding" style="overflow:auto;">
                            <table class="table table-striped">
                                <thead>
                                    <tr>
                                        <th width="3%">#</th>
                                        <th width="3%">TC No</th>
                                        <th width="10%">Invoice Date</th>
										<th width="10%">Invoice Type</th>
                                        <th width="10%">Due Date</th>
                                        <th width="10%">Invoice No.</th>
                                        <th width="10%">Hire Days</th>
                                        <th width="10%">Invoice Amount</th>
                                        <th width="10%">Generate PDF</th>
                                        <th width="10%">Payment Received</th>
                                        <th width="3%">Cancel</th>
                                    </tr>
                                </thead>
                                <tbody id="tbl_txtID">
                                <?php 
                                $sql = "SELECT * from invoice_tchire_master where COMID='".$comid."' and MODULEID='".$_SESSION['moduleid']."' and MCOMPANYID='".$_SESSION['company']."' and RANDOMID='".$randomid."' and STATUS>=5 order by INVOICE_DATE";
                                $res = mysql_query($sql);
                                $rec = mysql_num_rows($res);
                                if($rec == 0){
                                ?>
                                <tr id="tpRow"><td valign="top" align="center" colspan="10" style="color:red;">Sorry , currently zero(0) records added.</td></tr>
                                <?php }else{
                                $m=1;
                                while($rows = mysql_fetch_assoc($res))
                                {
                                ?>
                                <tr id="tpRow_<?php echo $m;?>">
                                <td align="center"><?php echo $m.".";?></td>
                                <td align="center"><?=$obj->getFun7()?></td>
                                <td align="left"><?php echo date("d-M-Y",strtotime($rows['INVOICE_DATE']));?></td>
								<td align="left" valign="middle"><?php echo $obj->getInvoiceTypeName1($rows['INVOICE_TYPE']);?></td>
                                <td align="left"><?php echo date("d-M-Y",strtotime($rows['DUE_DATE']));?></td>
                                <td align="left"><?php echo $rows["INVOICE_NO"];?></td>
                                <td align="left"><?php echo $rows['HIRE_DAYS'];?></td>
                                <td align="left"><?php echo $rows['NET_PAYABLE_TAX'];?><input type="hidden" name="txthddnAmt_<?php echo $m;?>" id="txthddnAmt_<?php echo $m;?>" value="<?php echo $rows['NET_PAYABLE_TAX'];?>"/><input type="hidden" name="txthddnUsdAmt_<?php echo $m;?>" id="txthddnUsdAmt_<?php echo $m;?>" value="<?php echo number_format(($rows['NET_PAYABLE_TAX']*$rows['EXCHANGE_RATE']),2,'.','');?>"/></td>
                                <td align="left"><p>
                                <a href="allPdf.php?id=67&comid=<?php echo $comid; ?>&invoiceid=<?php echo $rows['INVOICEID']; ?>" title="Pdf" ><button class="btn btn-default" style="margin-right: 5px;" type="button"><i class="fa fa-download"></i> Generate PDF</button></a></p></td>
                                <td align="left" valign="middle">
								<?php if($rows['STATUS']==5){?>
								<a href="#Payment" title="Payment Received" class="btn btn-default btn-sm" data-toggle="modal" data-target="#compose-modal" onClick="openWin(<?php echo $rows['INVOICEID'];?>);">Payment Received</a>
								<?php }?>
                                </td>
                                <td align="center">
								<?php if($rows['STATUS']==5){?>
                                <a href="#?" title="Cancel Entry" onClick="getDelete(<?php echo $rows['INVOICEID'];?>,<?php echo $comid;?>,<?php echo $m;?>);"><button class="btn btn-danger" type="button"><i class="fa fa-times"></i> Cancel</button></a>
								<?php }else{?>
								<span class="label label-danger">Cancelled</span>
								<?php }?>
								</td>
                                </tr>
                                <?php $m++;}}?>
                                </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="rcvdbtnhide" class="btn btn-primary btn-flat" onClick="return getValid();" >Submit</button>
                                            <input type="hidden" id="action1" name="action1" value="submit1" />
                                            <input type="hidden" name="txtCRMFILE1" id="txtCRMFILE1" value="" />
                                            <input type="hidden" name="txtCRMNAME1" id="txtCRMNAME1" 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>