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

$idd = $_REQUEST['id'];
$id        = explode(",", $_REQUEST['id']);


$comid     = $id[0];
$vendorid  = $id[2];
$fcaid     = $id[1];
$cargoid   = $id[6];
$randomid  = $id[9];
$slaveids  = $id[10];
$name      = $_REQUEST['name'];
$page      = $_REQUEST['page'];
$invtype   = $_REQUEST['invtype'];
$currency = "USD";
$creatorsarr = $obj->getUsersWithAuthority('INI_FREIGHT_CHK_CRETR');
$approverarr1 = $obj->getUsersWithAuthority('INI_FREIGHT_CHK_APP_1');
$approverarr2 = $obj->getUsersWithAuthority('INI_FREIGHT_CHK_APP_2');

$creator = $obj->getUserAuthority($_SESSION['uid'], 'INI_FREIGHT_CHK_CRETR');
$approver1 = $obj->getUserAuthority($_SESSION['uid'], 'INI_FREIGHT_CHK_APP_1');
$approver2 = $obj->getUserAuthority($_SESSION['uid'], 'INI_FREIGHT_CHK_APP_2');


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

if (@$_REQUEST['action'] == 'submit') {
	$msg = $obj->insertFreightInvoiceDetails_in();
	$msg = explode(",", $msg);
	header('Location:./invoice_payment.php?msg=' . $msg[0] . '&comid=' . $msg[1] . '&page=' . $page . '&id=' . $_REQUEST['id'] . '&name=' . $_REQUEST['name'] . "&cargoid=" . $cargoid . "&invtype=" . $msg[2]);
}

if (@$_REQUEST['action2'] == 'submit1') {
	$msg = $obj->insertFreightPaymentReceivedDetails_in();
	$msg = explode("_", $msg);
	header('Location:./invoice_payment.php?msg=' . $msg[0] . '&comid=' . $msg[1] . '&page=' . $page . '&id=' . $_REQUEST['id'] . '&name=' . $_REQUEST['name'] . "&cargoid=" . $cargoid . "&invtype=" . $invtype);
}

if (@$_REQUEST['action1'] == 'submit2') {
	$msg = $obj->deletefreightInvoiceRecords_in();
	$msg = explode(",", $msg);
	header('Location:./invoice_payment.php?msg=' . $msg[0] . '&comid=' . $msg[1] . '&page=' . $page . '&id=' . $_REQUEST['id'] . '&name=' . $_REQUEST['name'] . "&cargoid=" . $cargoid . "&invtype=" . $invtype);
}



$fcaid = $obj->getLatestCostSheetIDForVcIn($comid);

// echo '<h1>'.$fcaid.'</h1>';
$obj->viewFreightCostEstimationTempleteRecordsNewForVcIn($fcaid);


// echo $

// echo '<h1>'.$comid.'</h1>';
// echo '<h1>'.$fcaid.'</h1>';

$arr = $obj->getLoadPortAndDischargePortArrBasedOnCommidAndProcessWithoutTBNForVcIn($comid, $fcaid);

// die('dfgkm') ;

// echo '<pre>';

// print_r($arr);
$lp_name = array();
$dp_name = array();

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




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

// echo $lp_name;

// die();



// $obj->viewFreightCostEstimationTempleteRecords_in($comid);
// $arr       = $obj->getLoadPortAndDischargePortArrBasedOnCommidAndProcessWithout_in($obj->getFun1());

// $lp_name = array(); 
// $dp_name = array();
// $discharge_port = "";




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


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

// echo $lp_name;

// die();
$pagename = basename($_SERVER['PHP_SELF']) . "?comid=" . $comid . "&name=" . $name . "&page=" . $page . "&id=" . $idd . "&cargoid=" . $cargoid . "&invtype=" . $invtype;

$uid	  = $_SESSION['uid'];
$moduleid = $_SESSION['moduleid'];
?>
<?php

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


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

	$sql_ufim = mysql_query("update freight_invoice_in_master set STATUS=0 where INVOICEID='" . $_POST['invoice_id'] . "'");
	echo true;
}

$query_in = "select * from freight_cost_estimete_in_master where COMID='" . $comid . "'";
$result_in = mysql_query($query_in) or die($query_in);
$rows_in = mysql_fetch_assoc($result_in);

//$sql = "SELECT * from freight_invoice_in_master where COMID='" . $comid . "' and MODULEID='" . $_SESSION['moduleid'] . "' and MCOMPANYID='" . $_SESSION['company'] . "' and VENDOR='" . $vendorid . "' and I_TYPE='" . $invtype . "' and STATUS < 5 LIMIT 1"; 

$sql = "SELECT * from freight_invoice_in_master where COMID='" . $comid . "' and MODULEID='" . $_SESSION['moduleid'] . "' and MCOMPANYID='" . $_SESSION['company'] . "' and VENDOR='" . $vendorid . "' and STATUS < 5 ORDER BY INVOICEID DESC LIMIT 1";

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

$invtype = ($rec) ? $rows['I_TYPE'] : $invtype;
?>
<!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(); ?>
	<!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
	<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
	<!--[if lt IE 9]>
  <script src="../js/html5shiv.js"></script>
  <script src="../js/respond.min.js"></script>
<![endif]-->
	<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() {
			$(".autosize").autosize({
				append: "\n"
			});
			$("#selApprovers").chosen();
			$("#frm1").validate({
				rules: {
					selFromOwner: {
						required: true
					},
					selIType: {
						required: true
					},
					txtDNote: {
						required: true
					},
					txtDate: {
						required: true
					},
					txtExchangeRate: {
						required: true
					},
					selExchangeCurrency: {
						required: true
					},
					txtPaymentTerms: {
						required: true
					},

					txtDesc: {
						required: true
					}
				},
				messages: {
					selIType: {
						required: "*"
					},
					txtDNote: {
						required: true
					},
					txtDate: {
						required: true
					},
					txtExchangeRate: {
						required: "*"
					},
					selExchangeCurrency: {
						required: "*"
					},
					txtPaymentTerms: {
						required: "*"
					},

				},
				submitHandler: function(form) {
					if ($('#txtStatus').val() == 0) {
						jAlert('<b style="font-size:25px;">Please wait . . .</b><br><br><img src="../../img/loading.gif"  />', 'Alert');
						$("#popup_container").css({
							"background": "rgba(255,255,255,0.1)",
							"border": "10px solid rgba(255,255,255,0.1)",
							"width": "100%"
						});
						$("#popup_content").css({
							"background": "none",
							"text-align": "center"
						});
						$("#popup_ok,#popup_title").hide();
						form.submit();
					} else {
						jConfirm('Are you sure you want to Submit ?', 'Confirmation', function(r) {
							if (r) {
								jAlert('<b style="font-size:25px;">Please wait . . .</b><br><br><img src="../../img/loading.gif"  />', 'Alert');
								$("#popup_container").css({
									"background": "rgba(255,255,255,0.1)",
									"border": "10px solid rgba(255,255,255,0.1)",
									"width": "100%"
								});
								$("#popup_content").css({
									"background": "none",
									"text-align": "center"
								});
								$("#popup_ok,#popup_title").hide();
								form.submit();
							}
						});
					}
				}
			});
			$("#txtTO,[id^=txtAddDesAmt_],[id^=txtSubDesAmt_],#txtAddComm,#txtExchangeRate,#txtBrokerage").numeric();
			$(".numeric").numeric();

			$('#txtRemarks').autosize({
				append: "\n"
			});

			$('#txtDate,#txtDueDate,#txtExchangeDate').datepicker({
				format: 'dd-mm-yyyy',
				autoclose: true
			});

			$('[id^=chkClubFreight_]').on('ifChecked', function() {
				var amount = parseFloat($("#txtClubFreight_" + $(this).val()).val());
				if (isNaN(amount)) {
					amount = 0;
				} else {
					amount = amount.toFixed(2);
				};
				var frtamt = parseFloat($("#txtGrossFreight").val());
				if (isNaN(frtamt)) {
					frtamt = 0;
				};
				var newamt = parseFloat(frtamt) + parseFloat(amount);
				$("#txtGrossFreight").val(newamt.toFixed(2));
				getAmountThereOff();
			});

			$('[id^=chkClubFreight_]').on('ifUnchecked', function() {
				var amount = parseFloat($("#txtClubFreight_" + $(this).val()).val());
				if (isNaN(amount)) {
					amount = 0;
				} else {
					amount = amount.toFixed(2);
				};
				var frtamt = parseFloat($("#txtGrossFreight").val());
				if (isNaN(frtamt)) {
					frtamt = 0;
				};
				var newamt = parseFloat(frtamt) - parseFloat(amount);
				$("#txtGrossFreight").val(newamt.toFixed(2));
				getAmountThereOff();
			});

			$('[id^=chkDemDis_]').on('ifChecked', function() {
				getAmountThereOff();
			});

			$('[id^=chkDemDis_]').on('ifUnchecked', function() {
				getAmountThereOff();
			});


			$('#rdoTaxApplicable1').on('ifChecked', function() {
				$(this).attr('checked', true);
				showhidetaxDiv();
			});

			$('#rdoTaxApplicable2').on('ifChecked', function() {
				$(this).attr('checked', true);
				showhidetaxDiv();
			});

			//-----------------------------------------------------------------
			$('#rdoGSTVAT1').on('ifChecked', function() {
				$(this).attr('checked', true);
				showhidetaxDiv();
			});

			$('#rdoGSTVAT2').on('ifChecked', function() {
				$(this).attr('checked', true);
				showhidetaxDiv();
			});


			$('#chkPrevInv_1').on('ifChecked', function() {
				$(this).attr('checked', true);
				getAmountThereOff();
			});

			$('#chkPrevInv_1').on('ifUnchecked', function() {
				$(this).attr('checked', false);
				getAmountThereOff();
			});



			// getFullcalCulation();
			readonlytextbox();
			showhidetaxDiv();
			getCalculateFreight();
			getBankingDetailsData();
			getAmountThereOff();
		});



		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);
			}
			getAmountThereOff();
		}

		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();
			}
			getAmountThereOff();
		}

		function getCalculateFreight() {
			var sum2 = parseFloat('<?php echo $id[3]; ?>');
			var sum1 = 0;
			for (var i = 1; i <= $("#hddnClubcount").val(); i++) {
				if ($("#chkClubFreight_" + i).is(":checked")) {
					var txtClubFreight = parseFloat($("#txtClubFreight_" + i).val());
					if (isNaN(txtClubFreight)) {
						txtClubFreight = 0;
					}
					sum1 = parseFloat(sum1.toFixed(2)) + parseFloat(txtClubFreight.toFixed(2));
				}
			}
			if (isNaN(sum1)) {
				sum1 = 0;
			}
			var sum3 = parseFloat(sum2.toFixed(2)) + parseFloat(sum1.toFixed(2));
			$("#txtGrossFreight").val(parseFloat(sum3.toFixed(2)));

		}


		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><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"  placeholder="Amount" autocomplete="off" value="" onKeyUp="getAmountThereOff();"/></td></tr>').appendTo("#tblAdd");
				$("#txtAddID").val(id);
				$("[id^=txtAddDesAmt_]").numeric();
			}
		}


		function removeAddRow(var1) {
			jConfirm('Are you sure you want to remove this entry permanently ?', 'Confirmation', function(r) {
				if (r) {
					$("#add_Row_" + var1).remove();
					getAmountThereOff();
				} 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><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"  placeholder="Amount" autocomplete="off" value="" onKeyUp="getAmountThereOff();"/></td></tr>').appendTo("#tblSub");
				$("#txtSubID").val(id);
				$("[id^=txtSubDesAmt_]").numeric();
			}
		}


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

		// function getBankingDetailsData()
		// {   
		//     var1 = $('#selNOB').val();
		// 	if($("#selNOB").val()!="")
		// 	{
		// 		$.post("options.php?id=43",{selNOB:""+$("#selNOB").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]);
		// 				$('#span_1_11').text(res[11]);
		// 			}
		// 		});
		// 	}
		// 	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("");
		// 		$('#span_1_11').text("");
		// 	}
		// }


		function getBankingDetailsData() {
			//var1 = $('#selNOB').val(); 

			var var1 = $('select[name="selNOB"]').val();
			var var2 = $('select[name="selNOB"]').attr('data-id');
			var id = (var2 == 1) ? 122 : 43;

			if (var1 != "") {
				$.post("options.php?id=" + id, {
					selNOB: "" + var1 + ""
				}, 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]);
						$('#span_1_11').text(res[11]);
					}
				});
			} 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("");
				$('#span_1_11').text("");
			}
		}





		function getAmountThereOff() {
			if ($('#txtFinlGrossFreight').val() == "" || isNaN($('#txtFinlGrossFreight').val())) {
				var final_freight = 0;
			} else {
				var final_freight = $("#txtFinlGrossFreight").val();
			}
			if ($('#txtGrossFreight').val() == "" || isNaN($('#txtGrossFreight').val())) {
				var final_freight1 = 0;
			} else {
				var final_freight1 = $("#txtGrossFreight").val();
			}


			if ($('#txtTO').val() == "" || isNaN($('#txtTO').val())) {
				var var1 = 0;
			} else {
				var var1 = $("#txtTO").val();
			}
			var var3 = (parseFloat(parseFloat(parseFloat(final_freight1) * parseFloat(var1)) / 100)).toFixed(2);
			if (isNaN(var3)) {
				var3 = 0;
			}

			$('#txtNet').val(parseFloat(var3).toFixed(2));

			var add1 = parseFloat($("[id^=txtAddDesAmt_]").sum());
			if (isNaN(add1)) {
				add1 = 0;
			}
			var sub1 = parseFloat($("[id^=txtSubDesAmt_]").sum());
			if (isNaN(sub1)) {
				sub1 = 0;
			}

			var addcomdem = 0;
			var brocommdem = 0;
			var addcom = parseFloat($("#txtAddComm").val());
			if (isNaN(addcom)) {
				addcom = 0;
			}
			var brocomm = parseFloat($("#txtBrokerage").val());
			if (isNaN(brocomm)) {
				brocomm = 0;
			}
			for (var i = 1; i <= $("#txtDemDisID").val(); i++) {
				if ($("#chkDemDis_" + i).is(":checked")) {
					var txtDemDisAmt = parseFloat($("#txtDemDisAmt_" + i).val());
					if (isNaN(txtDemDisAmt)) {
						txtDemDisAmt = 0.00;
					}
					add1 = parseFloat(add1) + parseFloat(txtDemDisAmt);

					if (txtDemDisAmt > 0) {
						var addcomdem1 = parseFloat(parseFloat(txtDemDisAmt) * parseFloat(addcom)) / 100;
						if (isNaN(addcomdem1)) {
							addcomdem1 = 0.00;
						}
						var brocommdem1 = parseFloat(parseFloat(txtDemDisAmt) * parseFloat(brocomm)) / 100;
						if (isNaN(brocommdem1)) {
							brocommdem1 = 0.00;
						}
						addcomdem = parseFloat(addcomdem) + parseFloat(addcomdem1);
						brocommdem = parseFloat(brocommdem) + parseFloat(brocommdem1);
					}
				}
			}

			if ($('#txtTO').val() > 0) {
				var brokerage = (parseFloat(parseFloat(parseFloat(final_freight1) * parseFloat(brocomm)) / 100)).toFixed(2);
				if (isNaN(brokerage)) {
					brokerage = 0;
				}

				if ($('#txtAddComm').val() == "" || isNaN($('#txtAddComm').val())) {
					var addcom = addcom_amt = 0;
				} else {
					var addcom = $("#txtAddComm").val();
					addcom_amt = parseFloat(parseFloat(final_freight1) * parseFloat(addcom)) / 100;
				}

			} else {
				var addcom_amt = 0;
				var brokerage = 0;
			}

			var brokerage_amt = parseFloat(brokerage) + parseFloat(brocommdem);
			$('#txtBrokerageAmt').val(parseFloat(brokerage_amt).toFixed(2));
			addcom_amt = parseFloat(parseFloat(addcom_amt) + parseFloat(addcomdem));
			$('#txtAddCommAmt').val(parseFloat(addcom_amt).toFixed(2));

			var var2 = parseFloat(var3) + parseFloat(add1) - parseFloat(sub1) - parseFloat(addcom_amt) - parseFloat(brokerage_amt);

			if (isNaN(var2)) {
				var2 = 0;
			}
			$('#txtNetAmtPayable').val(parseFloat(var2).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(var2) * parseFloat(txtSGST)) / 100;
			if (isNaN(txtSGST_Amount)) {
				txtSGST_Amount = 0;
			}
			var txtCGST_Amount = parseFloat(parseFloat(var2) * parseFloat(txtCGST)) / 100;
			if (isNaN(txtCGST_Amount)) {
				txtCGST_Amount = 0;
			}
			var txtIGST_Amount = parseFloat(parseFloat(var2) * parseFloat(txtIGST)) / 100;
			if (isNaN(txtIGST_Amount)) {
				txtIGST_Amount = 0;
			}
			var txtVAT_Amount = parseFloat(parseFloat(var2) * 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;
			}

			var2 = parseFloat(var2) - parseFloat(txtInvPAmt);

			var exRate = parseFloat($('#txtExchangeRate').val());

			var txtPreInvAmt = parseFloat($("#txtPrevInvAmt_1").val());
			if (isNaN(txtPreInvAmt)) {
				txtPreInvAmt = 0.00;
			}
			if ($("#chkPrevInv_1").is(":checked")) {
				// console.log('dpk');
				var txtInvAmt = parseFloat($("#txtNet").val());
				if (isNaN(txtInvAmt)) {
					txtInvAmt = 0.00;
				}

				var txtPreInvAmt = parseFloat($("#txtPrevInvAmt_1").val());
				if (isNaN(txtPreInvAmt)) {
					txtPreInvAmt = 0.00;
				}



				var txtAmtPayableWithTax = parseFloat($("#txtAmtPayableWithTax").val());
				if (isNaN(txtAmtPayableWithTax)) {
					txtAmtPayableWithTax = 0.00;
				}

				console.log(txtPreInvAmt);

				// console.log(txtInvAmt);

				// console.log(txtAmtPayableWithTax)


				var txtEOC = parseFloat($("#txtEOC").val());
				if (isNaN(txtEOC)) {
					txtEOC = 0.00;
				}

				txthddnAmt = parseFloat(txtInvAmt) - parseFloat(txtPreInvAmt);

				txthddnAmt1 = parseFloat(txtAmtPayableWithTax) - parseFloat(txtPreInvAmt);

				txthddnAmt2 = parseFloat(txtEOC) - parseFloat(txtPreInvAmt);

				console.log('---', txthddnAmt)

				$("#txtNetAmtPayable").val(txthddnAmt);
				$("#txtAmtPayableWithTax").val(txthddnAmt1);
				$("#txtEOC").val(txthddnAmt2);

				$("#txtPrevInvID_1").attr("disabled", false);
			} else {

				$("#txtPrevInvID_1").attr("disabled", true);

			}

			if ($("#rdoTaxApplicable1").is(":checked")) {
				if ($("#rdoGSTVAT1").is(":checked")) {
					var txtAmtPayableWithTax = parseFloat(var2) + parseFloat(txtSGST_Amount) + parseFloat(txtCGST_Amount) + parseFloat(txtIGST_Amount);

					if ($("#chkPrevInv_1").is(":checked")) {
						$('#txtAmtPayableWithTax').val(parseFloat(txtAmtPayableWithTax - txtPreInvAmt).toFixed(2));


						$('#txtEOC').val(parseFloat(txtAmtPayableWithTax * exRate - txtPreInvAmt).toFixed(2));
					} else {
						$('#txtAmtPayableWithTax').val(parseFloat(txtAmtPayableWithTax).toFixed(2));


						$('#txtEOC').val(parseFloat(txtAmtPayableWithTax * exRate).toFixed(2));
					}

				} else {
					var txtAmtPayableWithTax = parseFloat(var2) + parseFloat(txtVAT_Amount);
					$('#txtAmtPayableWithTax').val(parseFloat(txtAmtPayableWithTax).toFixed(2));

					$('#txtEOC').val(parseFloat(txtAmtPayableWithTax * exRate).toFixed(2));
				}
			} else {

				if ($("#chkPrevInv_1").is(":checked")) {
					$('#txtAmtPayableWithTax').val(parseFloat(var2 - txtPreInvAmt).toFixed(2));

					$('#txtEOC').val(parseFloat(var2 * exRate - txtPreInvAmt).toFixed(2));
				} else {
					$('#txtAmtPayableWithTax').val(parseFloat(var2).toFixed(2));

					$('#txtEOC').val(parseFloat(var2 * exRate).toFixed(2));

				}

			}

			var amtPayable = $('#txtAmtPayableWithTax').val();

			if (amtPayable < 0) {
				$('#bankingrow').hide();
				$('.fadeInBbnInvCom').css('display', 'block');
				$('.fadeInVenBank').css('display', 'none');

				$('.fadeInVenBank').attr('name', 'hidesel');
				$('.fadeInBbnInvCom').attr('name', 'selNOB');
			} else {
				$('.fadeInBbnInvCom').css('display', 'none');
				$('.fadeInVenBank').css('display', 'block');

				$('.fadeInVenBank').attr('name', 'selNOB');
				$('.fadeInBbnInvCom').attr('name', 'hidesel');
			}
		}


		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(var1) {
			jConfirm('Are you sure you want to Cancel this Entry?', 'Confirmation', function(r) {
				if (r) {
					$('#action1').val('submit2');
					$('#txtDEL_ID').val(var1);
					document.frm2.submit();
				} else {
					return false;
				}
			});
		}

		function openWin(var1) {
			$("#divPayment").empty();
			$("#divPayment").html('<div><img src="../../img/ajax-loader.gif" /><br><b>Loading...</b></div>');
			$.post("options.php?id=113", {
				invoiceid: "" + var1 + ""
			}, function(html) {
				$("#divPayment").empty();
				$("#divPayment").append(html);

				if ($('#txtP_PR').val() == "" || isNaN($('#txtP_PR').val())) {
					var txtP_PR = 0;
				} else {
					var txtP_PR = $("#txtP_PR").val();
				}
				txtP_PR = parseFloat(txtP_PR) + 100;
				if (txtP_PR > $("#txtP_Amt").val()) {
					$("#rcvdbtnhide").hide();
				}
				$(".numeric").numeric();
				$('#txtP_Remarks,[id^=txtP_Remarks_]').autosize({
					append: "\n"
				});
				$('[id^=txtP_Date_]').datepicker({
					format: 'dd-mm-yyyy',
					autoclose: true
				});

			});
		}

		function AddNewPaymentRow() {
			var id = $("#txtPaymentID").val();
			if ($("#txtP_Date_" + id).val() != "" && $("#txtP_PR_" + id).val() != "") {
				id = (id - 1) + 2;
				$('<tr id="trpaymentrow_' + id + '"><td><a href="#pr1" onClick="removePaymentRow(' + id + ');"><i class="fa fa-times" style="color:red;"></i></a></td><td><input type="text" name="txtP_Date_' + id + '" id="txtP_Date_' + id + '" class="form-control" value="" autocomplete="off"/></td><td><textarea name="txtP_Remarks_' + id + '" id="txtP_Remarks_' + id + '" class="form-control" cols="15" rows="2" placeholder="Remarks.."></textarea></td><td><input type="text" name="txtP_PR_' + id + '" id="txtP_PR_' + id + '" class="form-control numeric" autocomplete="off" placeholder="0.00" value=""  onkeyup="onkeyUp1();"/></td></tr>').appendTo("#paymenttbody");
				$('#txtP_Date_' + id).datepicker({
					format: 'dd-mm-yyyy',
					autoclose: true
				});
				$("#txtPaymentID").val(id);
				$('#txtP_Remarks_' + id).autosize({
					append: "\n"
				});
				$(".numeric").numeric();
				onkeyUp1();
			}
		}


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

		function onkeyUp1() {
			var txtInv = parseFloat($("[id^=txtP_PR_]").sum());
			if (isNaN(txtInv)) {
				txtInv = 0;
			}
			$('#txtP_PR').val(txtInv.toFixed(2));
		}


		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);
				return true;
			}
		}

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

		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;
				}
			});
		}
	</script>
	<style>
		.animated {
			vertical-align: top;
			transition: height 0.2s;
			-webkit-transition: height 0.2s;
			-moz-transition: height 0.2s;
		}

		form.cmxform label.error,
		label.error {
			/* remove the next line when you have trouble in IE6 with labels in list */
			font-family: Verdana, Arial, Helvetica, sans-serif;
			font-size: 10px;
			color: red;
			font-style: normal;
			font-weight: lighter;
			margin: 5px;
			vertical-align: top;
		}

		.span span {
			font-weight: bold;
		}
	</style>
</head>

<body class="skin-blue fixed">
	<!-- header logo: style can be found in header.less -->
	<?php $display->header_tag(); ?>
	<div class="wrapper row-offcanvas row-offcanvas-left">
		<?php $display->leftmenu($nav); ?>
		<aside class="right-side">
			<!-- Content Header (Page header) -->
			<section class="content-header">
				<h1>
					<i class="fa fa-book"></i>&nbsp;Ops <?php echo $subtitle; ?>&nbsp;&nbsp;&nbsp;&nbsp;<small>
						<div class="headline text-center" id="time" style="color:#000; font-weight:bold; font-size:12px;">( 20 Jul 2015 4:40:44 PM )</div>
					</small>
				</h1>
				<ol class="breadcrumb">
					<li><a href="../"><i class="fa fa-home"></i> Home</a></li>
					<li class="active">Ops <?php echo $subtitle; ?>&nbsp;&nbsp;&nbsp;&gt;&nbsp;&nbsp;&nbsp;<?php echo $page_bar; ?>&nbsp;&nbsp;&nbsp;</li>
				</ol>
			</section>

			<!-- Main content -->
			<section class="content invoice">
				<?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> invoice data added/updated successfully.
						</div>
				<?php }
				} ?>
				<!--   content put here..................-->
				<div align="right">

					<?php

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

				<div style="height:10px;">&nbsp;</div>

				<?php
				$status_query = "select * from freight_invoice_in_master where COMID='" . $comid . "' and MODULEID='" . $_SESSION['moduleid'] . "' and MCOMPANYID='" . $_SESSION['company'] . "' and VENDOR = '" . $vendorid . "' and STATUS>=5";

				$statusRes = mysql_query($status_query);

				$statusRow = mysql_fetch_assoc($statusRes);



				?>

				<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">
								FREIGHT PAYMENT CREATION
							</h2>
						</div><!-- /.col -->
					</div>

					<div class="row invoice-info">
						<div class="col-sm-4 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-4 invoice-col">
							<strong>To :</strong>
							<address>
								<?php if ($rec > 0) { ?>
									<?php echo $obj->getVendorListNewBasedOnID($rows['VENDOR']); ?><br>
									<?php echo stripslashes($obj->getVendorDataBasedOnID($rows['VENDOR'], 'STREET_1')); ?>
									<?php echo stripslashes($obj->getVendorDataBasedOnID($rows['VENDOR'], 'CITY')); ?>,
									<?php echo stripslashes($obj->getVendorDataBasedOnID($rows['VENDOR'], 'COUNTRY')); ?>,
									<?php echo stripslashes($obj->getVendorDataBasedOnID($rows['VENDOR'], 'CITY_POSTAL_CODE')); ?>
									<input type="hidden" name="txtVendor" id="txtVendor" value="<?php echo $rows['VENDOR']; ?>" />
									<input type="hidden" name="txtFCAID" id="txtFCAID" value="<?php echo $rows['FCAID']; ?>" />
								<?php } else { ?>
									<?php echo $obj->getVendorListNewBasedOnID($vendorid); ?><br>
									<?php echo stripslashes($obj->getVendorDataBasedOnID($vendorid, 'STREET_1')); ?>
									<?php echo stripslashes($obj->getVendorDataBasedOnID($vendorid, 'CITY')); ?>,
									<?php echo stripslashes($obj->getVendorDataBasedOnID($vendorid, 'COUNTRY')); ?>,
									<?php echo stripslashes($obj->getVendorDataBasedOnID($vendorid, 'CITY_POSTAL_CODE')); ?>
									<input type="hidden" name="txtVendor" id="txtVendor" value="<?php echo $vendorid; ?>" />
									<input type="hidden" name="txtFCAID" id="txtFCAID" value="<?php echo $obj->getFun1(); ?>" />
								<?php } ?>
							</address>
						</div><!-- /.col -->
						<div class="col-sm-4 invoice-col">
							<strong>Freight Details</strong>
							<address>
								Fixture Ref.: <?php echo $rows_in["VOYAGE_NO"]; ?><br />
								Vessel: <?php echo $obj->getVesselIMOData($rows_in["VESSEL_IMO_ID"], "VESSEL_NAME"); ?><br />
								CP Date: <?php echo date("d-m-Y", strtotime($obj->getFun3())); ?><br />
								<?php if ($cargoid != 0) { ?>
									Cargo: <?php echo $obj->getCargoNameListForMultipleNamemultiple($cargoid); ?><br />
								<?php } ?>
								Port of Loading: <?php echo $lp_name; ?><br />
								Port of Discharging: <?php echo $dp_name; ?>
							</address>
						</div><!-- /.col -->
					</div>
					<div class="row invoice-info">
						<div class="col-sm-4 invoice-col">
							Vendor (Manual)
							<address>
								<?php if ($rec > 0) { ?>
									<textarea class="form-control areasize" name="txtManualVendorName" id="txtManualVendorName" rows="3" placeholder="Vendor..."><?php echo $rows['MANUAL_VENDOR_NAME']; ?></textarea>
								<?php } else { ?>
									<textarea class="form-control areasize" name="txtManualVendorName" id="txtManualVendorName" rows="3" placeholder="Vendor..."><?php echo $obj->getVendorListNewBasedOnID($vendorid); ?> <?php echo stripslashes($obj->getVendorDataBasedOnID($vendorid, 'STREET_1'));



																																																							if (stripslashes($obj->getVendorDataBasedOnID($vendorid, 'CITY') != '')) {


																																																								echo stripslashes($obj->getVendorDataBasedOnID($vendorid, 'CITY'));
																																																							}
																																																							if (stripslashes($obj->getVendorDataBasedOnID($vendorid, 'COUNTRY') != '')) {


																																																								echo stripslashes($obj->getVendorDataBasedOnID($vendorid, 'COUNTRY'));
																																																							}
																																																							if (stripslashes($obj->getVendorDataBasedOnID($vendorid, 'CITY_POSTAL_CODE') != '')) {


																																																								echo stripslashes($obj->getVendorDataBasedOnID($vendorid, 'CITY_POSTAL_CODE'));
																																																							}


																																																							?></textarea>
								<?php } ?>
							</address>
						</div><!-- /.col -->
						<div class="col-sm-4 invoice-col">
							Port of Loading
							<address>
								<?php if ($rec > 0) { ?>
									<textarea class="form-control areasize" name="txtLoadPortName" id="txtLoadPortName" rows="2" placeholder="Port of Loading..."><?php echo $rows['LOAD_PORT_NAME']; ?></textarea>
								<?php } else { ?>
									<textarea class="form-control areasize" name="txtLoadPortName" id="txtLoadPortName" rows="2" placeholder="Port of Loading..."><?php echo $lp_name; ?></textarea>
								<?php } ?>
							</address>
						</div><!-- /.col -->
						<div class="col-sm-4 invoice-col">
							<strong>Port of Discharging</strong>
							<address>
								<?php if ($rec > 0) { ?>
									<textarea class="form-control areasize" name="txtDischargePortName" id="txtDischargePortName" rows="2" placeholder="Port of Discharging..."><?php echo $rows['DISCHARGE_PORT_NAME']; ?></textarea>
								<?php } else { ?>
									<textarea class="form-control areasize" name="txtDischargePortName" id="txtDischargePortName" rows="2" placeholder="Port of Discharging..."><?php echo $dp_name; ?></textarea>
								<?php } ?>
							</address>
						</div><!-- /.col -->
					</div>


					<div class="row invoice-info">
						<div class="col-sm-3 invoice-col">
							<strong>BL Date</strong>
							<address>

								<input type="text" name="txtBLDate" id="txtBLDate" autocomplete="off" class="form-control" value="<?php echo $rows['BL_DATE']; ?>" />
							</address>
						</div><!-- /.col -->
						<div class="col-sm-3 invoice-col">
							<strong>BL No.</strong>
							<address>
								<input type="text" name="txtBLNo" id="txtBLNo" autocomplete="off" class="form-control" value="<?php echo $rows['BL_NO']; ?>" />
							</address>
						</div><!-- /.col -->
						<div class="col-sm-3 invoice-col">
							<strong>Flag</strong>
							<address>
								<input type="text" name="txtFlag" id="txtFlag" autocomplete="off" class="form-control" value="<?php if ($rec == 0) {
																																	echo $obj->getCountryNameBasedOnID($obj->getVesselIMOData($rows_in["VESSEL_IMO_ID"], "FLAG"));
																																} else {
																																	echo $rows['FLAG'];
																																} ?>" />
							</address>
						</div><!-- /.col -->
						<div class="col-sm-3 invoice-col">
							<strong>IMO No.</strong>
							<address>
								<input type="text" name="txtIMONo" id="txtIMONo" autocomplete="off" class="form-control" value="<?php if ($rec == 0) {
																																	echo $obj->getVesselIMOData($rows_in["VESSEL_IMO_ID"], "IMO_NO");
																																} else {
																																	echo $rows['IMO_NO'];
																																} ?>" />
							</address>
						</div><!-- /.col -->
					</div>
					<?php

					$sqlForQtyNRate = 'select BL_QTY_FREIGHT,FREIGHT_GROSS from
										freight_cost_estimete_in_master where FCAID="' . $fcaid . '" and COMID="' . $comid . '" and MCOMPANYID="' . $_SESSION['company'] . '" and MODULEID="' . $_SESSION['moduleid'] . '"';

					$resForQtyNRate = mysql_query($sqlForQtyNRate) or die($sqlForQtyNRate);

					$rowForQtyNRate = mysql_fetch_assoc($resForQtyNRate);


					?>
					<div class="row invoice-info">
						<div class="col-sm-3 invoice-col">
							<strong>BL QUANTITY</strong>
							<address>

								<input type="text" name="txtBLQuantity" id="txtBLQuantity" autocomplete="off" class="form-control" value="<?php echo $rowForQtyNRate['BL_QTY_FREIGHT']; ?>" readonly />
							</address>
						</div><!-- /.col -->
						<div class="col-sm-3 invoice-col">
							<strong>FRIEGHT RATE</strong>


							<address>
								<input type="text" name="txtFrieghtRate" id="txtFrieghtRate" autocomplete="off" class="form-control" value="<?php echo $rowForQtyNRate['FREIGHT_GROSS'] . ' USD/MT'; ?>" readonly />
							</address>
						</div><!-- /.col -->

					</div>

					<div class="row invoice-info">
						<div class="col-sm-6 invoice-col">
							<div class="table-responsive">
								<table class="table">
									<tbody>
										<tr>
											<th style="width:50%;padding-top:15px;padding-bottom:15px;">Invoice Type :</th>
											<td><select name="selIType" class="select form-control" id="selIType"><?php $obj->getInvoiceTypeForInterimFinal($invtype); ?></select></td>
										</tr>
										<script>
											$("#selIType").val('<?php echo $rows['I_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>
												<?php if ($rec == 0) { ?>
													<input type="text" name="txtDNote" id="txtDNote" class="form-control" placeholder="Invoice No." value="" />
													<input type="hidden" name="txtDNote1" id="txtDNote1" value="" readonly />
												<?php } else { ?>
													<input type="text" name="txtDNote" id="txtDNote" class="form-control" placeholder="Invoice No." value="<?php echo $rows['MESSAGE']; ?>" />
													<input type="hidden" name="txtInvoiceid" id="txtInvoiceid" value="<?php echo $rows['INVOICEID']; ?>" readonly />
													<input type="hidden" name="txtDNote1" id="txtDNote1" value="<?php echo $rows['MESSAGE']; ?>" readonly />
												<?php } ?>
											</td>
										</tr>
										<?php
										$invdate = date('d-m-Y', strtotime($rows['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="txtDate" id="txtDate" autocomplete="off" class="form-control" 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']; ?>" /></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="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['REMARKS']; ?></textarea></td>
										</tr>
										<tr>
											<th style="padding-top:15px;padding-bottom:15px;">Banking Details :</th>
											<td>
												<select name="selNOB" data-id="1" class="select form-control fadeInVenBank" id="selNOB" onChange="getBankingDetailsData()"><?php $obj->getBankingDetailsDataWithJsonVendor($vendorid); ?></select>

												<select name="selNOB" data-id="2" class="select form-control fadeInBbnInvCom" id="selNOB" onChange="getBankingDetailsData()" style="display:none;">
													<?php
													$obj->getBankingDetails($rows['VENDOR_SLAVEID']);
													?>
												</select>
											</td>
											<script>
												<?php if ($rows['NET_PAYABLE_TAX'] < 0) { ?>
													$('.fadeInBbnInvCom').val('<?php echo $rows['NOB']; ?>');
												<?php } else { ?>
													$('.fadeInVenBank').val('<?php echo $rows['NOB']; ?>');
												<?php } ?>
											</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;"><input type="checkbox" class="c_bank_check" name="c_bank_check" value="Yes" <?= $rows['c_bank_check'] == 'Yes' ? 'checked' : '' ?>> 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>
										<tr>
											<td>IFSC</td>
											<td><span id="span_1_11"></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']); ?>
													<?php
													$j = 1;
													for ($i = 0; $i < sizeof($fileid); $i++) {
													?>
										<tr id="row_file_<?php echo $j; ?>">
											<td width="40%" align="left" class="input-text" valign="top"><a href="../../attachment/<?php echo $fileid[$i]; ?>" target="_blank" style="color:blue;" data-toggle="tooltip" data-original-title="<?php echo $filename[$i]; ?>"><i class="fa fa-external-link"></i>&nbsp;&nbsp;<?php echo $filename[$i]; ?></a>
												<input type="hidden" name="file_<?php echo $j; ?>" id="file_<?php echo $j; ?>" value="<?php echo $fileid[$i]; ?>" />
												<input type="hidden" name="name_<?php echo $j; ?>" id="name_<?php echo $j; ?>" value="<?php echo $filename[$i]; ?>" />
											</td>
											<td><a href="#1" onClick="Del_Upload(<?php echo $j; ?>);"><i class="fa fa-times " style="color:red;"></i></a></td>
										</tr>
									<?php $j++;
													} ?>
								<?php } ?>
								</td>
								</tr>
									</tbody>
								</table>
							</div>
						</div><!-- /.col -->
						<div class="col-sm-6 invoice-col">
							<div class="table-responsive">
								<table class="table">
									<tbody>
										<?php if ($obj->getFun71() > 0) { ?>
											<tr>
												<th style="width:50%;padding-top:15px;padding-bottom:15px;" colspan="2">Net Freight(<?php echo $currency; ?>) :</th>
												<td><input type="text" name="txtGrossFreightNet" id="txtGrossFreightNet" class="form-control" readonly value="<?php echo $obj->getFun66(); ?>"></td>
											</tr>
											<tr>
												<th style="width:50%;padding-top:15px;padding-bottom:15px;" colspan="2">Dead Freight(<?php echo $currency; ?>) :</th>
												<td><input type="text" name="txtGrossFreightDead" id="txtGrossFreightDead" class="form-control" readonly value="<?php echo $obj->getFun67(); ?>"></td>
											</tr>
										<?php } ?>

										<tr>
											<th style="width:50%;padding-top:15px;padding-bottom:15px;" colspan="2">Gross Freight(<?php echo $currency; ?>) :</th>
											<td><input type="text" name="txtGrossFreight" id="txtGrossFreight" class="form-control" readonly value="<?php echo $id[3]; ?>"><input type="hidden" name="hddnClubcount" id="hddnClubcount" value="<?php echo $jk; ?>"></td>
										</tr>

										<tr>
											<th style="width:50%;padding-top:15px;padding-bottom:15px;" colspan="2">% There Off :</th>
											<td><input type="text" name="txtTO" id="txtTO" class="form-control" value="<?php echo $rows['TO_1']; ?>" style="text-align:right;" onKeyUp="getAmountThereOff()" autocomplete="off" /><input type="hidden" name="txtFinlGrossFreight" id="txtFinlGrossFreight" class="form-control" readonly value="<?php echo $net_paid; ?>"></td>
										</tr>
										<tr>
											<th style="width:50%;padding-top:15px;padding-bottom:15px;" colspan="2"></th>
											<td><?php if ($rec == 0) { ?>
													<input type="text" name="txtNet" id="txtNet" class="form-control" readonly value="0" />
												<?php } else { ?>
													<input type="text" name="txtNet" id="txtNet" class="form-control" readonly value="<?php echo $rows['NET_AMOUNT']; ?>" />
												<?php } ?>
											</td>
										</tr>
										<!--<tr>
											<th style="width:50%;padding-top:15px;padding-bottom:15px;" colspan="2">Balance</th>
											<td><input type="text"  name="txtBalanceFreight" id="txtBalanceFreight" class="form-control" readonly value="" /></td>	
										</tr>-->



										<tr>
											<th style="width:50%;padding-top:15px;padding-bottom:15px;" colspan="3">Other Add <input type="hidden" name="txtDemDisID" id="txtDemDisID" value="<?= $i; ?>" /></th>
										</tr>
									</tbody>
									<?php $sql2 = "select * from freight_invoice_in_slave where INVOICEID='" . $rows['INVOICEID'] . "' 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 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><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="getAmountThereOff();" /></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><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="getAmountThereOff();" /></td>
											</tr>
										<?php } ?>
									</tbody>
									<tbody>
										<tr>
											<td align="left" colspan="3"><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 colspan="3">Other Less</th>
										</tr>
										<tr>
											<td style="width:25%;padding-top:15px;padding-bottom:15px;"><i>Brokerage (%)</i></td>
											<td style="width:40%;padding-top:15px;padding-bottom:15px;"><input type="text" name="txtBrokerage" id="txtBrokerage" class="form-control" onKeyUp="getAmountThereOff();" autocomplete="off" value="<?php echo $rows['BROKERAGE_PERCENT']; ?>"></td>
											<td><input type="text" name="txtBrokerageAmt" id="txtBrokerageAmt" class="form-control" readonly value="<?php echo $rows['BROKERAGE']; ?>"></td>
										</tr>
										<tr>
											<td style="width:25%;padding-top:15px;padding-bottom:15px;"><i>Less Addcom</i></td>
											<td style="width:40%;padding-top:15px;padding-bottom:15px;"><input type="text" name="txtAddComm" id="txtAddComm" class="form-control" placeholder="Addcom %" autocomplete="off" value="<?php if ($rec > 0) {
																																																										echo $rows['ADDCOM'];
																																																									} else {
																																																										echo $obj->getFun74();
																																																									} ?>" onKeyUp="getAmountThereOff();" /></td>
											<td><input type="text" name="txtAddCommAmt" id="txtAddCommAmt" class="form-control" placeholder="Amount" autocomplete="off" value="<?php echo $rows['ADDCOM_AMOUNT']; ?>" readonly /></td>
										</tr>

										<?php $sql2 = "select * from freight_invoice_in_slave where INVOICEID='" . $rows['INVOICEID'] . "' 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><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="getAmountThereOff();" /></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><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="getAmountThereOff();" /></td>
											</tr>
										<?php } ?>
									</tbody>
									<tbody>
										<tr>
											<td align="left" colspan="3"><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>


										<?php
										$sqlprev = "SELECT * from request_master where VENDOR='" . $vendorid . "' and MODULEID='" . $_SESSION['moduleid'] . "' and MCOMPANYID='" . $_SESSION['company'] . "' and STATUS=5  and P_AMT>0 ORDER BY REQ_ID DESC LIMIT 1";

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

										$resprev = mysql_query($sqlprev);
										$recprev = mysql_num_rows($resprev);
										$k = 0;
										$rowsprev = mysql_fetch_assoc($resprev);


										// $sql17 = "select * from request_master where REQ_ID='".."'";

										// $res17 = mysql_query($sql17) or die($sql17);

										// $rows17 = mysql_fetch_assoc($res17);

										if ($rowsprev['REQ_ID'] == $rows['preinv_id']) {
											$checkprev = 1;
										} else {
											$checkprev = 0;
										}
										?>
										<tr>
											<td colspan="2"><strong><input name="chkPrevInv_1" class="checkbox" id="chkPrevInv_1" type="checkbox" value="1" <?= ($checkprev == 1) ? 'checked="checked"' : '' ?> /><strong>&nbsp;&nbsp;1. <?php echo $rowsprev['PAYMENT_NO']; ?></strong><input type="hidden" name="txtPrevInvDays_1" id="txtPrevInvDays_1" value="<?php echo $rowsprev['HIRE_DAYS']; ?>" /><input type="hidden" name="txtPrevInvID_1" id="txtPrevInvID_1" value="<?php echo $rowsprev['REQ_ID']; ?>" /><input type="hidden" name="txtPrevInvIdentify_1" id="txtPrevInvIdentify_1" value="VC" /></td>
											<td><input type="text" name="txtPrevInvAmt_1" id="txtPrevInvAmt_1" class="form-control" placeholder="0.00" autocomplete="off" readonly value="<?php echo $rowsprev['P_AMT']; ?>" /></td>
										</tr>


										<tr>
											<td colspan="2"><strong>Amount Payable</strong></td>
											<td><input type="text" name="txtNetAmtPayable" id="txtNetAmtPayable" class="form-control" readonly value="<?php echo $rows['NET_PAYABLE']; ?>" /></td>
										</tr>


										<tr>
											<td><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><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();getAmountThereOff();" /></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><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();getAmountThereOff();" /></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><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();getAmountThereOff();" /></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><i>VAT (%)</i></td>
											<td><input type="text" name="txtVAT" id="txtVAT" class="form-control numeric" placeholder="%" autocomplete="off" value="<?= $rows['VAT_PERCENT']; ?>" onKeyUp="getAmountThereOff();" /></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 freight_invoice_in_master where COMID='" . $comid . "' and MODULEID='" . $_SESSION['moduleid'] . "' and MCOMPANYID='" . $_SESSION['company'] . "' and VENDOR = '" . $vendorid . "' and STATUS=5";
										$res1 = mysql_query($sql1);
										$i = 0;
										while ($rows1 = mysql_fetch_assoc($res1)) {
											$i++;
										?>
											<tr>
												<th style="width:50%;padding-top:15px;padding-bottom:15px;" colspan="2"><?php echo $rows1['I_TYPE'] . '(' . $rows1['MESSAGE'] . ')'; ?></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="2"><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>
											<td colspan="2"><strong>Exchange To Currency <?php

																							if ($rows['EXCHANGE_CURRENCY'] != ' ') {
																								echo '(' . $rows['EXCHANGE_CURRENCY'] . ')';
																							} else {
																								echo  '&nbsp';
																							}




																							?></strong></td>


											<td><input type="text" name="txtEOC" id="txtEOC" class="form-control" readonly value=" " /></td>

											<script>
												$("#txtExchangeRate").keyup(function() {


													var exchangeRate = $(this).val();

													if (exchangeRate.length >= 1) {
														var net_pay = $('#txtNetAmtPayable').val();

														$('#txtEOC').val(parseFloat(net_pay * exchangeRate).toFixed(2))

													}
												});

												$(function() {
													var exchangeRate = $('#txtExchangeRate').val();

													if (exchangeRate.length >= 1) {
														var net_pay = $('#txtAmtPayableWithTax').val();

														$('#txtEOC').val(parseFloat(net_pay * exchangeRate).toFixed(2))
													}
												});
											</script>
										</tr>
									</tbody>
								</table>
							</div>

							<div class="row invoice-info">
								<div class="col-sm-4 invoice-col">
									Level 1 Approver
								</div>
								<div class="col-sm-8 invoice-col">
									<?php
									if ($invtype == 'Interim') {
										$fieldname = 'INI_FREIGHT_CHK_APP_1';
									} else {
										$fieldname = 'FINL_FREIGHT_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" id="action" name="action" value="submit" />
						<input type="hidden" name="txtStatus" id="txtStatus" value="0" />
						<input type="hidden" name="txtCRMFILE" id="txtCRMFILE" value="" />
						<input type="hidden" name="txtCRMNAME" id="txtCRMNAME" value="" />
						<?php if (($rec == 0 && $creator == 1) || (($rows['STATUS'] == 0 || $rows['STATUS'] == 2) && $creator == 1)) {
							if (empty($approverarr1) && empty($approverarr2)) {
								$status = 5;
							} else if (empty($approverarr1) && !empty($approverarr2)) {
								$status = 4;
							} else {
								$status = 1;
							}
						?>
							<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="txtFreightAmtLocal" id="txtFreightAmtLocal" value="<?php echo $id[7]; ?>" />

					</div>
					<div class="box-footer" align="right">&nbsp;</div>
				</form>

				<form role="form" name="frm2" id="frm2" enctype="multipart/form-data" action="<?php echo $pagename; ?>" method="post">
					<div class="box">

						<div class="box-body no-padding">
							<table class="table table-striped">
								<thead>
									<tr>
										<th>Fixture Ref.</th>
										<th>Vessel</th>
										<th>Invoice Type</th>
										<th>Invoice No.</th>
										<th>Charterer</th>
										<th>Amount</th>
										<th>Invoice PDF</th>
										<th>Cancel Invoice</th>
										<th>Payment Paid</th>
										<th>Description</th>
										<?php
										if ($_SESSION['iutype'] == 'mgmt_user') {


										?>
											<th>Open</th>

										<?php
										}
										?>
									</tr>
								</thead>
								<tbody>
									<?php
									$sql = "select * from freight_invoice_in_master where COMID='" . $comid . "' and MODULEID='" . $_SESSION['moduleid'] . "' and MCOMPANYID='" . $_SESSION['company'] . "' and VENDOR = '" . $vendorid . "' and STATUS>=5";
									// echo $sql;

									// echo "<br>";
									$res = mysql_query($sql);
									$rec = mysql_num_rows($res);

									if ($rec == 0) {
									?>
										<tr>
											<td colspan="9" align="center" valign="middle" style="color:red;letter-spacing:1px;">SORRY CURRENTLY THERE ARE ZERO(0) RECORDS</td>
										</tr>
										<?php } else {
										// echo "<pre>";

										while ($rows = mysql_fetch_assoc($res)) {

										?>
											<tr data-status="<?= $rows['STATUS'] ?>" data-itype="<?= $obj->getInvoiceTypeName1($rows['I_TYPE']) ?>">
												<td align="left" valign="middle"><?php echo $rows_in["VOYAGE_NO"]; ?></td>
												<td align="left" valign="middle"><?php echo $obj->getVesselIMOData($obj->getCompareEstimateData($comid, "VESSEL_IMO_ID"), "VESSEL_NAME"); ?></td>
												<td align="left" valign="middle"><?php echo $obj->getInvoiceTypeName1($rows['I_TYPE']); ?></td>
												<td align="left" valign="middle"><?php echo $rows['MESSAGE']; ?></td>
												<td align="left" valign="middle"><?php echo $obj->getVendorListNewBasedOnID($rows['VENDOR']); ?></td>
												<td align="left" valign="middle"><?php echo $rows['NET_PAYABLE_TAX']; ?></td>
												<td align="center" valign="middle">
													<a href="#" title="Pdf" onClick="getPdf(<?php echo $rows['INVOICEID']; ?>);"><button class="btn btn-default" type="button" style="margin-right: 5px;"><i class="fa fa-download"></i> Generate PDF</button></a>
												</td>
												<td>
													<?php if ($rows['STATUS'] == 5) { ?>
														<a title="Cancel Link" href="#1" onClick="return getDelete(<?php echo $rows['INVOICEID']; ?>);">
															<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>
												<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']; ?>,<?php echo $rows['NET_AMOUNT']; ?>);">Payment Paid</a>
													<?php } ?>
												</td>
												<td align="left" valign="middle"><?php echo $rows['REMARKS']; ?></td>
												<?php
												if ($_SESSION['iutype'] == 'mgmt_user') {
												?>
													<td align="left" valign="middle"><button type="button" onclick="return openBtn('<?= $rows['INVOICEID'] ?>');" class="btn btn-danger btn-flat open_btn">Open</button></td>
												<?php
												}
												?>
											</tr>
									<?php }
									} ?>
								</tbody>
							</table>
						</div>
					</div>
					<input type="hidden" id="action1" name="action1" value="submit2" />
					<input type="hidden" name="txtDEL_ID" id="txtDEL_ID" value="0" />
				</form>
				<div class="modal fade" id="compose-modal" tabindex="-1" role="dialog" aria-hidden="true">
					<div class="modal-dialog" style="width:60%;">
						<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="frm3" id="frm3" 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="action2" name="action2" 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>
<script>
	let frm_table = $('#frm2 table ');




	let invoice_type = Array.from(frm_table.find("tr"));
	let invoice_result = invoice_type.filter(function(in_type) {
		return $(in_type).data('status') == 5 && $(in_type).data('itype') == 'Final';
	});

	// console.log(invoice_result);
	// console.log(invoice_result);

	if (invoice_result.length > 0) {
		$('#frm1').hide();
	}

	function openBtn(invoice_id) {
		$.post("", {
			invoice_id: invoice_id
		}, function(html) {
			if (html) {
				location.reload();
			}
		});
	}
</script>