<?php
session_start();
require_once("../../includes/display_internal_user_sopf.inc.php");
require_once("../../includes/functions_internal_user_sopf.inc.php");
$obj = new data();
$connect = $obj->funConnect();
$display = new display();
$display->logout_iu();

$_SESSION['moduleid'] = 6;
$_SESSION['selBType'] = (isset($_SESSION['selBType'])) ? $_SESSION['selBType'] : 2;

$ids = $_REQUEST['ids'];
if (@$_REQUEST['action'] == 'submit') {
	$msg = $obj->deleteFCETempleteRecordsNew();
	header('Location:./estimate_list.php?msg=' . $msg);
}

if (@$_REQUEST['action'] == 'submit1') {
	$msg = $obj->submitFinalFCARecordCompare();
	header('Location:./estimate_list.php?msg=4');
}

if (@$_REQUEST['action1'] == 'submit') {
	$msg = $obj->submitFinalFCARecordCompare();
	header('Location:./decisionchart_list.php?msg=1');
}
unset($_SESSION["final"]);

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

$pagename = basename($_SERVER['PHP_SELF']);
$msg = NULL;
?>

<!DOCTYPE html>
<html>

<head>
	<meta charset="UTF-8">
	<title><?php $display->title(); ?></title>
	<?php $display->favicon(); ?>
	<meta content='width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no' name='viewport'>
	<?php $display->css(); ?>
	<link href="../../css/datatables/dataTables.bootstrap.css" rel="stylesheet" type="text/css" />
	<?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]-->
	<style>
		.benchclass {
			background-color: #f39c12;
			color: #ffffff;
		}
	</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(9); ?>
		<aside class="right-side">
			<!-- Content Header (Page header) -->
			<section class="content-header">
				<h1>
					<i class="fa fa-leaf"></i>&nbsp;VC Out Estimates&nbsp;&nbsp;&nbsp;&nbsp;<small>
						<div class="headline text-center" id="time" style="color:#000; font-weight:bold; font-size:12px;"></div>
					</small>
				</h1>
				<ol class="breadcrumb">
					<li><a href="../"><i class="fa fa-home"></i> Home</a></li>
					<li class="active">VC Out Estimates : Estimate</li>
				</ol>
			</section>

			<!-- Main content -->
			<section class="content">
				<!--   content put here..................-->
				<?php if (isset($_REQUEST['msg'])) {
					$msg = $_REQUEST['msg'];
					if ($msg == 0) { ?>
						<div class="alert alert-success alert-dismissable">
							<i class="fa fa-check"></i>
							<button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
							<b>Congratulations!</b> VC Estimates added/updated successfully.
						</div>
					<?php } ?>
					<?php if ($msg == 1) { ?>
						<div class="alert alert-danger alert-dismissable">
							<i class="fa fa-ban"></i>
							<button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
							<b>Sorry!</b> there was an error while adding/updating VC Estimates.
						</div>
					<?php } ?>
					<?php if ($msg == 2) { ?>
						<div class="alert alert-success alert-dismissable">
							<i class="fa fa-check"></i>
							<button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
							<b>Congratulations!</b> VC Estimates delete successfully.
						</div>
					<?php }
					if ($msg == 3) { ?>
						<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> Final VC Estimates added successfully.
						</div>
					<?php }
					if ($msg == 4) { ?>
						<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> Fixture sent to ops successfully.
						</div>
				<?php }
				} ?>
				<div class="box box-primary">
					<h3 style=" text-align:center;">VC Out Estimates : Estimate List</h3>
					<form name="frm1" id="frm1" enctype="multipart/form-data" action="<?php echo $pagename; ?>">
						<div class="row" style="padding-right:10px; padding-left:10px; margin-bottom:5px;">
							<div class="col-xs-6">&nbsp;</div>

							<div class="col-xs-2" style="float: right; <?php echo (count($businessType) > 1) ? '' : 'display: none;' ?>">
								<select name="selBType" id="selBType" class="form-control" onChange="getSubmit();">
									<option value="">---Select Business Type---</option>
									<?php echo $obj->getBusinessTypeList1($selBType, $businessType); ?>
								</select>
							</div>

							<div class="<?php echo (count($businessType) > 1) ? 'col-xs-4' : 'col-xs-6' ?>">
								<a href="addestimate.php?estimatetype=<?= $estimatetype; ?>" title="Add" id="addnew" style="float: right;"><button type="button" class="btn btn-info btn-flat">Add New</button></a>
								<a href="#" onClick="getListToCompare();" style="float: right; padding-right: 30px;"><button type="button" class="btn btn-warning" onClick="getListToCompare();">Sensitivity Analysis</button></a>
							</div>

						</div>

						<div>
							<input name="txttblid" id="txttblid" type="hidden" value="" />
							<input name="txttblstatus" id="txttblstatus" type="hidden" value="" />
							<input name="delId" id="delId" type="hidden" value="" />
							<input type="hidden" name="action" id="action" value="submit" />
						</div>
						<?php $obj->displayFCETempleteListNew($selBType); ?>
						<div style="clear:both;"></div>
					</form>
				</div>

				<div class="modal fade" id="compose-modal" tabindex="-1" role="dialog" aria-hidden="true">
					<div class="modal-dialog" style="width:95%">
						<div class="modal-content">
							<div class="modal-header">
								<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
								<h4 class="modal-title">
									<!-- <i class="fa fa-file-text-o"></i>&nbsp;&nbsp;Decision Chart -->
								</h4>
							</div>
							<form name="frm2" id="frm2" enctype="multipart/form-data" action="<?php echo $pagename; ?>" />
							<div class="modal-body text-center" id="div_3" style="overflow:auto;">
							</div>
							<input type="hidden" name="action1" value="submit" />
							</form>
						</div>
					</div>
				</div>
				<!--   content ends here..................-->
			</section><!-- /.content -->
		</aside><!-- /.right-side -->

	</div><!-- ./wrapper -->
	<?php $display->footer(); ?>
	<script src='../../js/jquery.autosize.js'></script>
	<script src="../../js/plugins/datatables/jquery.dataTables.js" type="text/javascript"></script>
	<script src="../../js/plugins/datatables/dataTables.bootstrap.js" type="text/javascript"></script>
	<script src="../../js/timer.js" type="text/javascript"></script>
	<link href="../../css/jquery.alerts.css" rel="stylesheet" type="text/css" />
	<link href="../../css/datepicker/datepicker.css" rel="stylesheet" type="text/css" />
	<script src="../../js/plugins/datepicker/bootstrap-datepicker.js" type="text/javascript"></script>
	<script language="JavaScript" type="text/javascript" src="../../js/jquery.alerts.js"></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>
	<!-- <script src="https://cdnjs.cloudflare.com/ajax/libs/html2pdf.js/0.10.1/html2pdf.bundle.min.js"></script> -->
	<script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/2.5.1/jspdf.umd.min.js"></script>
	<script src="https://cdnjs.cloudflare.com/ajax/libs/html2canvas/1.4.1/html2canvas.min.js"></script>
	<script type="text/javascript">
		$(document).ready(function() {
			<?php if (isset($_REQUEST['ids']) && $_REQUEST['ids'] != "") { ?>
				//getListToCompare1("<?php echo $_REQUEST['ids']; ?>");
			<?php } ?>
			$('#estimatetype1').on('ifChecked', function() {
				//$("#addprev").attr("href", "addprevestimate.php?estimatetype="+$(this).val());
				$("#addnew").attr("href", "addestimate.php?estimatetype=" + $(this).val());
			});

			$('#estimatetype1').on('ifUnchecked', function() {
				//$("#addprev").attr("href", "");
				$("#addnew").attr("href", "");
			});
			$('#estimatetype2').on('ifChecked', function() {
				// $("#addprev").attr("href", "addprevestimate.php?estimatetype="+$(this).val());
				$("#addnew").attr("href", "addestimate.php?estimatetype=" + $(this).val());
			});

			$('#estimatetype2').on('ifUnchecked', function() {
				//$("#addprev").attr("href", "");
				$("#addnew").attr("href", "");
			});
			$('#estimatetype3').on('ifChecked', function() {
				//$("#addprev").attr("href", "addprevestimate.php?estimatetype="+$(this).val());
				$("#addnew").attr("href", "addestimate.php?estimatetype=" + $(this).val());
			});

			$('#estimatetype3').on('ifUnchecked', function() {
				//$("#addprev").attr("href", "");
				$("#addnew").attr("href", "");
			});
			$('#chkAll').on('ifChecked', function() {
				$('[id^=chkFCA_]').attr("checked", true);
				$('[id^=chkFCA_]').iCheck({
					checkboxClass: 'icheckbox_minimal',
					radioClass: 'iradio_minimal'
				});
			});

			$('#chkAll').on('ifUnchecked', function() {
				$('[id^=chkFCA_]').attr("checked", false);
				$('[id^=chkFCA_]').iCheck({
					checkboxClass: 'icheckbox_minimal',
					radioClass: 'iradio_minimal'
				});
			});

		});
		$(function() {
			$("#fce_list").dataTable();

		});

		function getDelete(var1) {
			jConfirm('Are you sure you want to delete this entry permanently?', 'Confirmation', function(r) {
				if (r) {
					$("#delId").val(var1);
					document.frm1.submit();
				} else {
					return false;
				}
			});
		}

		function getData() {
			$("#tbody").html("");
			$("#tbody").html('<tr><td height="100" colspan="8" align="center" ><img src="../../img/loading.gif" /></td></tr>');
			$.post("options.php?id=31", {
				selVName: "" + $("#selVName").val() + "",
				selSheetName: "" + $("#selSheetName").val() + ""
			}, function(html) {
				$("#tbody").html("");
				$("#tbody").html(html);
				$("#fce_list").dataTable();
				$('[id^=txtDesc_]').autosize({
					append: "\n"
				});
			});
		}

		function getCheckAllCHeckbox() {
			if ($("#chkAll").attr('checked')) {
				$('[id^=chkFCA_]').attr("checked", true);
				$('[id^=chkFCA_]').iCheck({
					checkboxClass: 'icheckbox_minimal',
					radioClass: 'iradio_minimal'
				});
			} else {
				$('[id^=chkFCA_]').attr("checked", false);
				$('[id^=chkFCA_]').iCheck({
					checkboxClass: 'icheckbox_minimal',
					radioClass: 'iradio_minimal'
				});
			}
		}

		function getListToCompare() {
			var anyBoxesChecked = false;
			var chkArr = Array();
			var j = 0;
			$('[id^=chkFCA_]').each(function() {
				if ($(this).is(":checked")) {
					chkArr[j] = $(this).val();
					anyBoxesChecked = true;
					j = j + 1;
				}
			});

			if (anyBoxesChecked == false) {
				jAlert('Please select at least one checkbox', 'alert');
				return false;
			} else {
				$("#compose-modal").modal('show');
				$("#div_3").html('<b style="font-size:25px;">Please wait . . .</b><br><br><img src="../../img/loading.gif"  />');
				$.post("options.php?id=131", {
					chkArr: "" + chkArr + ""
				}, function(html) {
					$("#div_3").html("");
					$("#div_3").html(html);

					$("[id^=txtFreight_], [id^=txtQty_], [id^=txtLP_], [id^=txtDP_], [id^=txtTP_], [id^=txtBP_], [id^=txtHire_], [id^=txtBunkerGrade_], [id^=txtMinQty_], [id^=txtMinFlatRate_], [id^=txtMinWSRate_], [id^=txtOverageQty_], [id^=txtOverageFlatRate_], [id^=txtOverageWSRate_]").numeric();

					/*$("#download").click(function() {
						var element = document.getElementById("compareDiv");
						html2pdf().from(element).save("compare.pdf");
					});*/
				});
			}
		}

		async function generatePDF() {
			jAlert('<b style="font-size:25px;">Please wait . . .</b><br><br><img src="../../img/loading.gif"  />', 'Alert');

			$("#popup_ok").remove();

			const element = document.getElementById("compareDiv");

			$("#popup_container").css({
				"border": "10px solid rgba(255,255,255,0.1)",
				"width": "100%"
			});
			$("#popup_content").css({
				"background": "none",
				"text-align": "center"
			});

			/*element.querySelectorAll("tr.sensitivity_analysis").forEach(tr => {
				tr.style.display = "none";
			});*/

			const canvas = await html2canvas(element, {
				scale: 2
			});

			/*element.querySelectorAll("tr.sensitivity_analysis").forEach(tr => {
				tr.style.display = "";
			});*/

			const imgData = canvas.toDataURL("image/png");

			// Get canvas size
			const imgWidth = canvas.width;
			const imgHeight = canvas.height;

			const margin = 20; // margin in points (1pt ≈ 1/72 inch)

			// PDF size (A4 = 210x297mm = ~595x842 pt in jsPDF)
			const pdf = new jspdf.jsPDF("p", "pt", "a4");
			const pageWidth = pdf.internal.pageSize.getWidth();
			const pageHeight = pdf.internal.pageSize.getHeight();

			// Adjust width and height to fit within the margin
			const availableWidth = pageWidth - margin * 2;
			const availableHeight = pageHeight - margin * 2;

			// Scale image to fit the page
			const ratio = Math.min(availableWidth / imgWidth, availableHeight / imgHeight);
			const newWidth = imgWidth * ratio;
			const newHeight = imgHeight * ratio;

			// X and Y positions to center the image within the margins
			const x = margin + (availableWidth - newWidth) / 2;
			const y = 20;

			pdf.addImage(imgData, "PNG", x, y, newWidth, newHeight);
			pdf.save("sensitivity_analysis.pdf");

			$("#popup_overlay, #popup_container").hide();
		}


		function getListToCompare1(ids) {

			$("#buttonPop1").click();
			$("#div_3").html('<b style="font-size:25px;">Please wait . . .</b><br><br><img src="../../img/loading.gif"  />');
			$.post("options.php?id=36", {
				chkArr: "" + ids + ""
			}, function(html) {
				$("#div_3").html("");
				$("#div_3").html(html);
				$("input[type='radio']").iCheck({
					checkboxClass: 'icheckbox_minimal',
					radioClass: 'iradio_minimal'
				});
				$('[id^=txtDesc_]').autosize({
					append: "\n"
				});
			});

		}



		function SubmitToCompare() {
			var anyBoxesChecked = false;
			var chkArr = Array();
			var j = 0;
			$('[id^=rdoFCA_]').each(function() {
				if ($(this).is(":checked")) {
					chkArr[j] = $(this).val();
					var rowid = this.id;
					var lasrvar1 = rowid.split("_")[1];
					if ($("#txtDesc_" + lasrvar1).val() != "") {
						anyBoxesChecked = true;
						j = j + 1;
					}

				}
			});

			if (anyBoxesChecked == false) {
				jAlert('Please select one Fixture and fill remarks', 'alert');
				return false;
			} else {
				document.frm2.submit();
			}
		}


		function getSubmit() {
			$("#action").val("ss");
			document.frm1.submit();
		}

		function getCalculateRates(id, num, flag) {
			var minFlatRate = parseFloat($("#txtMinFlatRate_" + id + "_" + num).val()) || 0;
			var minWSRate = parseFloat($("#txtMinWSRate_" + id + "_" + num).val()) || 0;

			if (flag == 1) {
				$("#txtOverageFlatRate_" + id + "_" + num).val(parseFloat(minFlatRate / 2).toFixed(2));
			}

			if (flag == 2) {
				$("#txtOverageWSRate_" + id + "_" + num).val(minWSRate.toFixed(2));
			}

			getCalculate(id);
		}

		function getCalculate(id, bunkerGrade = '') {
			var freight = parseFloat($("#txtFreight_" + id).val()) || 0;
			var qty = parseFloat($("#txtQty_" + id).val()) || 0;
			var lumpsum = parseFloat($("#txtLumpSum_" + id).val()) || 0;
			var brokeragePer = parseFloat($("#brokerage_" + id).attr('data-per')) || 0;
			var addCommPer = parseFloat($("#addComm_" + id).attr('data-per')) || 0;
			var otherIncome = parseFloat($("#otherIncome_" + id).text()) || 0;

			if (lumpsum) {
				var grossFreight = lumpsum.toFixed(2);
			} else {
				var grossFreight = (freight * qty).toFixed(2);
			}

			if ($("#txtMinQty_" + id + "_1").length) {
				var totalAmt = 0;

				$('[id^=txtMinQty_' + id + '_]').each(function() {
					var num = $(this).attr('data-id');

					var minCargoQty = parseFloat($("#txtMinQty_" + id + "_" + num).val()) || 0;
					var minFlatRate = parseFloat($("#txtMinFlatRate_" + id + "_" + num).val()) || 0;
					var minWSRate = parseFloat($("#txtMinWSRate_" + id + "_" + num).val()) || 0;

					var minAmt = parseFloat(parseFloat(minCargoQty) * parseFloat(minFlatRate) * parseFloat(minWSRate)) / 100;

					$("#txtMinAmt_" + id + "_" + num).val(minAmt.toFixed(2));

					var overageQty = parseFloat($("#txtOverageQty_" + id + "_" + num).val()) || 0;
					var overageFlatRate = parseFloat($("#txtOverageFlatRate_" + id + "_" + num).val()) || 0;
					var overageWSRate = parseFloat($("#txtOverageWSRate_" + id + "_" + num).val()) || 0;

					var overageAmt = parseFloat(parseFloat(overageQty) * parseFloat(overageFlatRate) * parseFloat(overageWSRate)) / 100;

					$("#txtOverageAmt_" + id + "_" + num).val(overageAmt.toFixed(2));

					totalAmt = parseFloat(totalAmt) + parseFloat(minAmt.toFixed(2)) + parseFloat(overageAmt.toFixed(2));
				});

				grossFreight = totalAmt.toFixed(2);
			}

			$("#grossFreight_" + id).text(grossFreight);

			var brokerage = ((grossFreight * brokeragePer) / 100).toFixed(2);

			$("#brokerage_" + id).text(brokerage);

			var addComm = ((grossFreight * addCommPer) / 100).toFixed(2);

			if (parseFloat(addComm) != 0) {
				$("#addComm_" + id).html(addCommPer + '%&nbsp&nbsp(-)' + addComm);
			}

			var netReceivable = ((parseFloat(grossFreight) + parseFloat(otherIncome)) - (parseFloat(brokerage) + parseFloat(addComm))).toFixed(2);

			$("#netReceivable_" + id).text(netReceivable);

			var loadPortCost = parseFloat($("[id^=txtLP_" + id + "_").sum()) || 0;
			var dischargePortCost = parseFloat($("[id^=txtDP_" + id + "_").sum()) || 0;
			var transitPortCost = parseFloat($("[id^=txtTP_" + id + "_").sum()) || 0;
			var bunkeringPortCost = parseFloat($("[id^=txtBP_" + id + "_").sum()) || 0;
			var operationalCost = parseFloat($("#operationalCost_" + id).text()) || 0;

			$("#loadPortCost_" + id).text(loadPortCost);
			$("#discPortCost_" + id).text(dischargePortCost);
			$("#transitPortCost_" + id).text(transitPortCost);
			$("#bunkeringPortCost_" + id).text(bunkeringPortCost);

			var totalCargoExpense = parseFloat(loadPortCost) + parseFloat(dischargePortCost) + parseFloat(transitPortCost) + parseFloat(bunkeringPortCost) + parseFloat(operationalCost);

			$("#totalExpense_" + id).text(totalCargoExpense);

			var hirePerDay = parseFloat($("#txtHire_" + id).val()) || 0;
			var ballastBonus = parseFloat($("#txtHire_" + id).attr('data-ballast-bonus')) || 0;
			var hierageAddCommPercent = parseFloat($("#txtHire_" + id).attr('data-hierage-addcomm-percent')) || 0;
			var hierageBrokeragePercent = parseFloat($("#txtHire_" + id).attr('data-hierage-brokerage-percent')) || 0;
			var cvePerMonth = parseFloat($("#txtHire_" + id).attr('data-cve-per-month')) || 0;
			var totalDays = parseFloat($("#txtHire_" + id).attr('data-ttl-days')) || 0;
			var ilohcCost = parseFloat($("#txtHire_" + id).attr('data-ilohc-cost')) || 0;

			var hireAmt = parseFloat(hirePerDay) * (totalDays);
			var GrossHierageAmt = parseFloat(hireAmt) + parseFloat(ballastBonus);
			var hierageAddCommAmt = (parseFloat(GrossHierageAmt) * parseFloat(hierageAddCommPercent)) / 100;
			var hierageBrokerageAmt = (parseFloat(hireAmt) * parseFloat(hierageBrokeragePercent)) / 100;
			var hierageAmt = parseFloat(GrossHierageAmt) - parseFloat(hierageAddCommAmt) - parseFloat(hierageBrokerageAmt);
			var hierageCVEAmt = ((parseFloat(cvePerMonth) * 12) / 365) * parseFloat(totalDays);

			var netHierageAmt = (parseFloat(hierageAmt) + parseFloat(hierageCVEAmt)).toFixed(2);

			$("#estimatedHire_" + id).text(netHierageAmt);

			if (bunkerGrade) {
				var price = parseFloat($("#txtBunkerGrade_" + id + "_" + bunkerGrade).val()) || 0;
				var mt = parseFloat($("#est_mt_" + id + "_" + bunkerGrade).text()) || 0;

				var cost = (parseFloat(mt) * parseFloat(price)).toFixed(2);

				$("#est_price_" + id + "_" + bunkerGrade).text(price);
				$("#est_cost_" + id + "_" + bunkerGrade).text(cost);

				var amount = 0;

				$("[id^=est_cost_" + id + "_]").each(function(index, element) {
					amount = parseFloat(amount) + parseFloat($(this).text());
				});

				$("#totalBunkerExpense_" + id).text(amount.toFixed(2));
			}

			var totalBunkerExpense = $("#totalBunkerExpense_" + id).text();

			var profitloss = parseFloat(netReceivable) + parseFloat(ilohcCost) - parseFloat(totalCargoExpense) - parseFloat(totalBunkerExpense) - parseFloat(netHierageAmt);

			$("#profitLoss_" + id).text(profitloss.toFixed(2));

			var dailyProfit = (totalDays != 0) ? (parseFloat(profitloss) / parseFloat(totalDays)) : 0;

			$("#nettDailyProfit_" + id).text(dailyProfit.toFixed(2));
		}

		function updateEstimate(id) {
			$("#btn_" + id).prop("disabled", true);

			var freight = parseFloat($("#txtFreight_" + id).val()) || 0;
			var qty = parseFloat($("#txtQty_" + id).val()) || 0;
			var hirePerDay = parseFloat($("#txtHire_" + id).val()) || 0;
			var lumpsum = parseFloat($("#txtLumpSum_" + id).val()) || 0;

			localStorage.setItem("freight", freight);
			localStorage.setItem("qty", qty);
			localStorage.setItem("hirePerDay", hirePerDay);
			localStorage.setItem("lumpsum", lumpsum);

			$("[id^=txtBunkerGrade_" + id + "_]").each(function(index, element) {
				var arr = ($(this).attr('id')).split('_');

				localStorage.setItem(arr[2], $(this).val());
			});

			$("[id^=txtLP_" + id + "_]").each(function(index, element) {
				var arr = ($(this).attr('id')).split('_');

				localStorage.setItem('txtPCosts_' + arr[2], $(this).val());
			});

			$("[id^=txtDP_" + id + "_]").each(function(index, element) {
				var arr = ($(this).attr('id')).split('_');

				localStorage.setItem('txtDCosts_' + arr[2], $(this).val());
			});

			$("[id^=txtTP_" + id + "_]").each(function(index, element) {
				var arr = ($(this).attr('id')).split('_');

				localStorage.setItem('txtTCosts_' + arr[2], $(this).val());
			});

			$("[id^=txtBP_" + id + "_]").each(function(index, element) {
				var arr = ($(this).attr('id')).split('_');

				localStorage.setItem('txtBCosts_' + arr[2], $(this).val());
			});

			$("[id^=txtMinQty_" + id + "_]").each(function(index, element) {
				var arr = ($(this).attr('id')).split('_');

				localStorage.setItem('txtMinCargoQty_' + arr[2], $(this).val());
			});

			$("[id^=txtMinFlatRate_" + id + "_]").each(function(index, element) {
				var arr = ($(this).attr('id')).split('_');

				localStorage.setItem('txtMinFlatRateQty_' + arr[2], $(this).val());
			});

			$("[id^=txtMinWSRate_" + id + "_]").each(function(index, element) {
				var arr = ($(this).attr('id')).split('_');

				localStorage.setItem('txtMinWSQty_' + arr[2], $(this).val());
			});

			$("[id^=txtMinAmt_" + id + "_]").each(function(index, element) {
				var arr = ($(this).attr('id')).split('_');

				localStorage.setItem('txtMinAmount_' + arr[2], $(this).val());
			});

			$("[id^=txtOverageQty_" + id + "_]").each(function(index, element) {
				var arr = ($(this).attr('id')).split('_');

				localStorage.setItem('txtOveCargoQty_' + arr[2], $(this).val());
			});

			$("[id^=txtOverageFlatRate_" + id + "_]").each(function(index, element) {
				var arr = ($(this).attr('id')).split('_');

				localStorage.setItem('txtOveFlatRateQty_' + arr[2], $(this).val());
			});

			$("[id^=txtOverageWSRate_" + id + "_]").each(function(index, element) {
				var arr = ($(this).attr('id')).split('_');

				localStorage.setItem('txtOveWSQty_' + arr[2], $(this).val());
			});

			$("[id^=txtOverageAmt_" + id + "_]").each(function(index, element) {
				var arr = ($(this).attr('id')).split('_');

				localStorage.setItem('txtOveAmount_' + arr[2], $(this).val());
			});

			window.open("updateestimate.php?id=" + id, "_blank");

			setTimeout(function() {
				jAlert('<b>Congratulations!</b> VC Estimate updated successfully.', 'Alert');
				$("#btn_" + id).prop("disabled", false);

				$('#compose-modal').on('hidden.bs.modal', function() {
					location.reload();
				});
			}, 3500);
		}

		function sentToOps(fcaId) {
			jConfirm('Are you sure you want to Send to Ops?', 'Confirmation', function(r) {
				if (r) {
					$("#txttblid").val(fcaId);
					$("#action").val('submit1');
					document.frm1.submit();
				} else {
					return false;
				}
			});
		}
	</script>

</body>

</html>