<?php 
session_start();
require_once("../../includes/display_internal_user_risk.inc.php");
require_once("../../includes/functions_internal_user_riskmangement.inc.php");

// echo '<pre>';


// print_r($_SESSION);

// die();

$obj = new data();
$connect = $obj->funConnect();
$display = new display();
$display->logout_iu();

if(@$_REQUEST['action'] == 'submit')
{
 	$id = $obj->createCalculatedRiskForVessel();
	header('Location:./riskcalculatorvessel.php?id='.$id);
}

$pagename = basename($_SERVER['PHP_SELF']);
?>
<!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" />
<!-- 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>
.table>thead>tr>th, .table>tbody>tr>th, .table>tfoot>tr>th, .table>thead>tr>td, .table>tbody>tr>td, .table>tfoot>tr>td
{
	padding:3px; 
}

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;
}

table{border-collapse:separate;}
select{height:19px;}
.select
{
    font-family: Verdana, Arial, Helvetica, sans-serif;
    font-size: 11px;
    font-weight: bold;
    color: #333333;
    /* color: #FBC763; */
    text-decoration: none;
    line-height: 13px;
	height:13px;
}

.input-text
{
	font-family: Verdana, Arial, Helvetica, sans-serif;
	font-size: 10px;
	font-weight: normal;
	color: #333333;
	text-decoration: none;
	/*text-transform:uppercase;
	line-height: 15px;*/
}

.input-textsmall
{
	font-family: Verdana, Arial, Helvetica, sans-serif;
	font-size: 9px;
	font-weight: normal;
	color: #333333;
	text-decoration:none;
	text-transform:uppercase;
}

.input 
{
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 10px;
font-weight: normal;
color: #333333;
text-decoration: none;
}
</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(5); ?>
			<aside class="right-side">                
                <!-- Content Header (Page header) -->
                <section class="content-header">
                    <h1>
                        <i class="fa fa-dollar"></i>&nbsp;CALCULATE RISK&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">CALCULATE RISK</li>
                    </ol>
                </section>
                <!-- Main content -->
                <section class="content">
				    <div align="right"><a href="riskcalculatorvessel.php"><button class="btn btn-info btn-flat">Back</button></a></div>
				    <div style="height:10px;">&nbsp;</div>
					<!--   content put here..................-->
					<div class="box box-primary">
						<h3 style=" text-align:center;">CALCULATE RISK</h3>
                        <form name="frm1" id="frm1" enctype="multipart/form-data" action="<?php echo $pagename;?>" method="post"/>
						<div class="row invoice-info" style="margin-left:7px;margin-right:7px;">
						    
                            
							<div class="col-xs-6">&nbsp;
							</div>
							<div class="col-sm-3">
								&nbsp;<address>
								
								</address>
							</div>
						</div>
						
						<div class="box-body table-responsive" style="overflow:auto;">
							<table id="vessel_list" class="table table-bordered table-striped" style="width:1500px;">
							    <thead>
								 
								<tr>
								    <th>Select</th>
									<th align="left" valign="top" width="5%">Contract ID</th>
									<th align="left" valign="top" width="8%">Contract No.</th>
									<th align="left" valign="top" width="8%">Contract Date</th>
									<th align="left" valign="top" width="8%">Vessel Name</th>
									<th align="left" valign="top" width="8%">Own Business Account</th>
									<th align="left" valign="top" width="8%">Working Currency</th>	
									<th align="left" valign="top" width="10%">Total Days</th>
									<th align="left" valign="top" width="10%">Initial Hire</th>	
									<th align="left" valign="top" width="10%">Projected Hire Rate/Day</th>
									<th align="left" valign="top" width="10%">Projected Hire</th>
									<th align="left" valign="top" width="10%">Difference</th>
									<!-- <th align="left" valign="top" width="12%">Nominate</th> -->
									
								</tr>
								</thead>
								
								<tbody id="tbody1">
									
								</tbody>
								
							</table>
						</div>
						
						
						<div class="row" style="padding-right:10px; padding-left:10px; margin-bottom:50px;">
							 <div class="col-xs-12" style="margin-bottom:30px; text-align:center;">
								<button type="submit" data-toggle="modal" data-target="#compose-modal" class="btn btn-primary" onClick="return getSelect();" >Submit</button>
								<input type="hidden" name="action" id="action" value="submit" />
							 </div>
						 </div>
						 <div class="row" style="padding-right:10px; padding-left:10px; margin-bottom:50px;">
						 <div class="col-xs-4" margin-bottom:30px;></div>
						 </div>
						</form>
					</div>
					<!--   content ends here..................-->
                </section><!-- /.content -->
            </aside><!-- /.right-side -->
        </div><!-- ./wrapper -->
<?php $display->footer(); ?>
<?php $display->js(); ?>
<link href="../../css/datatables/jquery.dataTables.min.css" rel="stylesheet" type="text/css" />
<script src='../../js/plugins/datatables/jquery.dataTables.min.js'></script>
<script src="../../js/timer.js" type="text/javascript"></script>
<link href="../../css/jquery.alerts.css" rel="stylesheet" type="text/css" />
<script language="JavaScript" type="text/javascript" src="../../js/jquery.numeric.js"></script>
<script language="JavaScript" type="text/javascript" src="../../js/jquery.alerts.js"></script>
<link href="../../css/datepicker/datepicker.css" rel="stylesheet" type="text/css" />
<script src="../../js/bootstrap-datepicker.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function(){
    $(".sidebar-toggle").click();
	$("#txtPaymentDate,#txtExchangeDate").datepicker({
		format: 'dd-mm-yyyy',
		autoclose: true
	});
	getData();
	$(".numeric").numeric();
	$("#frm1").validate({
		
			submitHandler: function(form)  {
				jConfirm('Are you sure you want to create RM?', 'Confirmation', function(r) {
				if(r){
					jAlert('<b style="font-size:25px;">Please wait . . .</b><br><br><img src="../../img/loading.gif"  />', 'Alert');
					$("#popup_container").css({"background": "rgba(255,255,255,0.1)","border": "10px solid rgba(255,255,255,0.1)","width": "100%"});
					$("#popup_content").css({"background":"none","text-align":"center"});
					$("#popup_ok,#popup_title").hide();  
					form.submit();
				}
				else{return false;}
				});
			}
	});
});

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

function getData()
{
	$('#tbody1').html("");
	$('#tbody1').html('<tr><td align="center" colspan="11"><img src="../../img/loading.gif" /></span></td></tr>');
	$.post("options.php?id=125",{selVendor:""+$("#selVendor").val()+""}, function(html) {
		$('#tbody1').html("");
		$('#tbody1').html(html);
		$("#selBankingDetails").html('');
		$("#selBankingDetails").html($("#txthddnBankingdetails").val());
		// $('[id^=txtInvoiceDate_]').datepicker({
		// 	format: 'dd-mm-yyyy',
		// 	autoclose: true
		// });
		
		$("[id^=chkSelect_]").iCheck({
			checkboxClass: 'icheckbox_minimal',
			radioClass: 'iradio_minimal'
		});
		
		$('[id^=chkSelect_]').on('ifChecked', function () { 
		   $(this).parents('tr').css( "background-color", "#c2dee5" );
		   $(this).parents('tr').find( "#txtPaymentNo_"+$(this).val() ).addClass('required');
		   $(this).parents('tr').find( "#txtActualAmt_"+$(this).val() ).addClass('required');
		   $(this).parents('tr').find( "#txtRemarks_"+$(this).val() ).addClass('required');
		   getExchangeAmountCal();
		});
		 
		$('[id^=chkSelect_]').on('ifUnchecked', function () { 
		   $(this).parents('tr').css( "background-color", "white" );
		   $(this).parents('tr').find( "#txtPaymentNo_"+$(this).val() ).removeClass("required").focus();
		   $(this).parents('tr').find( "#txtActualAmt_"+$(this).val() ).removeClass("required").focus();
		   $(this).parents('tr').find( "#txtRemarks_"+$(this).val() ).removeClass("required").focus();
		   $(this).focus();
		   getExchangeAmountCal();
		});
		
		getExchangeAmountCal();
		$(".numeric").numeric();
	});
}

function getExchangeAmountCal()
{

	// console.log('dpk is great');
    var resivedPl = 0;
	var actualtotal = 0;
	var actualexchangetotal = 0;
    // if($("#selExchangeCurrency").val()!='')
	// {
	    // $("#curr_span").text($("#selExchangeCurrency").val());
		// var exchangerate = parseFloat($("#txtExchangeRate").val());

		// var actualpl = 

		// var preHire = parseFloat($("#currentHire"+chkvalue).val());
				// if(isNaN(actualpl)){actualpl = 0;}

		
		// var preActual = parseFloat($("#currentBunker"+chkvalue).val());
				// if(isNaN(actualpl)){actualpl = 0;}
		// if(isNaN(exchangerate)){exchangerate = 1;}
		$('[id^=chkSelect_]').each(function() {
			if($(this).is(":checked")) {

				var chkvalue = $(this).val();
				var currentHire = parseFloat($("#pHireRate_"+chkvalue).val());
				if(isNaN(currentHire)){currentHire = 0;}

		


				var ttldays = parseFloat($("#TTLDAYS_"+chkvalue).val());
				if(isNaN(ttldays)){ttldays = 0;}

				var projectedHire = ttldays * currentHire;

				
	
				$('#pHire_'+chkvalue).val(projectedHire.toFixed(2))

			
				$('#diff_'+chkvalue).val(($('#HIRE_'+chkvalue).val()-$('#pHire_'+chkvalue).val()).toFixed(2))
				// $('#revisedPl_'+chkvalue).val(resivedPl.toFixed(2))
			}
		});
	// }
	// else
	// {
	// 	$("#curr_span").text('');
	// 	var exchangerate = 0;
	// 	$('[id^=chkSelect_]').each(function() {
	// 		if($(this).is(":checked")) {
	// 			var chkvalue = $(this).val();
				
	// 			var txtEstimatedAmt = parseFloat($("#txtEstimatedAmt_"+chkvalue).val());
	// 			if(isNaN(txtEstimatedAmt)){txtEstimatedAmt = 0;}
				
	// 			var txtActualAmt = parseFloat($("#txtActualAmt_"+chkvalue).val());
	// 			if(isNaN(txtActualAmt)){txtActualAmt = 0;}
				
	// 			var txtActualExchangeAmt = parseFloat(txtActualAmt)*parseFloat(exchangerate);
	// 			if(isNaN(txtActualExchangeAmt)){txtActualExchangeAmt = 0;}
	// 			$("#txtActualExchangeAmt_"+chkvalue).val(txtActualExchangeAmt.toFixed(2));
				
	// 			estimatedtotal = parseFloat(estimatedtotal) + parseFloat(txtEstimatedAmt);
	// 			actualtotal = parseFloat(actualtotal) + parseFloat(txtActualAmt);
	// 			actualexchangetotal = parseFloat(actualexchangetotal) + parseFloat(txtActualExchangeAmt);
	// 		}
	// 	});
		
	// }
	// $("#txtTotalEstAmount").val(estimatedtotal.toFixed(2));
	// $("#txtTotalAmount").val(actualtotal.toFixed(2));
	// $("#txtTotalExAmount").val(actualexchangetotal.toFixed(2));
}

function getSelect()
{

	var anyBoxesChecked = false;
	var chkArr = Array();
	var j = 0;
    $('[id^=chkSelect_]').each(function() {
        if ($(this).is(":checked")) {
			chkArr[j] = $(this).val();
            anyBoxesChecked = true;
			j = j + 1;
        }
    });
 
    if (anyBoxesChecked == false) {
       jAlert('Please select at least one record', 'alert');
      return false;
    } 
	else
	{  
	    var validationResponse = $('#frm1').valid();
	    if(validationResponse) {
		document.frm1.submit();
		} else {
		jAlert('Please Fill Required fields.', 'alert');
		return false;
	}
	}
}
 
</script>
		
</body>
</html>