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


include_once("../../includes/fpdf.php");
$obj = new data();
$connect = $obj->funConnect();
$display = new display();
$display->logout_iu();
$id = $_REQUEST['id'];

// echo $id;

// die();



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


// if (@$_REQUEST['action1'] == 'submit')
//  {
//  	$msg = $obj->submitFinalFCARecordCompare();
// 	header('Location:./riskcalculator.php?msg=3');
//  }



$obj->viewCombinedSOAPayableData($id);
$creatorsarr = $obj->getUsersWithAuthority('SOA_CHK_CRETR');
$approverarr1 = $obj->getUsersWithAuthority('SOA_CHK_APP_1');
$approverarr2 = $obj->getUsersWithAuthority('SOA_CHK_APP_2');

$creator = $obj->getUserAuthority($_SESSION['uid'], 'SOA_CHK_CRETR');
$approver1 = $obj->getUserAuthority($_SESSION['uid'], 'SOA_CHK_APP_1');
$approver2 = $obj->getUserAuthority($_SESSION['uid'], 'SOA_CHK_APP_2');
$approver2 = $obj->getUserAuthority($_SESSION['uid'], 'SOA_CHK_APP_2');
$accounts = $obj->getUserAuthority($_SESSION['uid'], 'SOA_CHK_ACC');
$pagename = basename($_SERVER['PHP_SELF']).'?id='.$id;
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title><?php $display->title(); ?></title>
<?php $display->favicon(); ?>
<meta content='width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no' name='viewport'>
<?php $display->css(); ?>
<?php $display->js(); ?>
<link href="../../css/jquery.alerts.css" rel="stylesheet" type="text/css" />
<script src='../../js/jquery.autosize.js'></script>
<script language="JavaScript" type="text/javascript" src="../../js/jquery.alerts.js"></script>
<script src="../../js/timer.js" type="text/javascript"></script>
<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>
<!-- 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;
}

#vertical-2 thead,#vertical-2 tbody{
                display:inline-block;
            }
</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" id="print_pdf">
						<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-12">
							   
                            <!-- <a href="#" onClick="getListToCompare();" style="float:right;"><button type="button" data-toggle="modal" data-target="#compose-modal" class="btn btn-warning" onClick="getListToCompare();" >Create Decision Chart</button></a> -->
                               
							</div>
							<div class="col-xs-6">&nbsp;
								
							</div>
							<div class="col-sm-3">
								&nbsp;<address>
									
								<!-- <a href="allPdf.php?id=90&csp=<?=$id?>" title="Pdf"><button type="button" class="btn btn-default" style="margin-right: 5px;"><i class="fa fa-download"></i> Generate PDF</button></a> -->
									
								</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 align="left" valign="top" width="8%">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="8%">Total Days</th>
									<th align="left" valign="top" width="8%">Initial Hire</th>	
									<th align="left" valign="top" width="8%">Projected Hire Rate/Day</th>
									<th align="left" valign="top" width="8%">Projected Hire</th>
									<th align="left" valign="top" width="8%">Difference</th>

									
									
								</tr>
								</thead>
								
								<tbody id="tbody1">
							<?php $sql = "select * from period_rm_slave where RM_ID='".$id."'";

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

							// die();

								  $result = mysql_query($sql);
								  $sno = 0;
								  while($rows = mysql_fetch_assoc($result))

								//   echo '<pre>';

								//   print_r($rows);

								//   die();


								  {$sno++;

								


									echo '<tr>';
									echo '<td>'.$rows['CONTRACT_ID'].'</td>';
									echo '<td>'.$rows['CONTRACT_NO'].'</td>';
									echo '<td>'.$rows['CONTRACT_DATE'].'</td>';
									echo '<td>'.$rows['VESSEL_IMO_ID'].'<input type="hidden" id="RM_ID_'.$sno.'" name="RM_ID_'.$sno.'" value="'.$rows['RM_SLAVE_ID'].'"/></td>';
									echo '<td>'.$rows['OWN_BUSINESS_ACCOUNT'].'</td>';
									$invoicedate = date('d-m-Y',strtotime($rows['INVOICE_DATE']));if($invoicedate=='01-01-1970'){$invoicedate = '';}
									echo '<td>'.$rows['WORKING_CURRENCY'].'</td>';

									echo '<td>'.$rows['TTLDAYS'].'</td>';

									echo '<td>'.$rows['HIRE'].'</td>';
									echo '<td><input type="text" name="pHireRate_'.$sno.'" id="pHireRate_'.$sno.'" class="form-control" autocomplete="off" value="'.$rows['pHireRate'].'" placeholder=""  onKeyUp="getExchangeAmountCal();"/></td>';


									echo '<td><input type="text" name="pHire_'.$sno.'" id="pHire_'.$sno.'" class="form-control" readonly="true" autocomplete="off" value="'.$rows['pHire'].'"  placeholder=""  onKeyUp="getExchangeAmountCal(); /><input type="hidden" id="NAME_ID_'.$sno.'" name="NAME_ID_'.$sno.'" value="2"/><input type="hidden" id="HIRE_'.$sno.'" name="HIRE_'.$sno.'" value="'.$rows['HIRE'].'"/><input type="hidden" id="finalhireage_'.$sno.'" name="finalhireage_'.$sno.'" value="'.$rows['FINAL_HIERAGE_AMOUNT'].'"/><input type="hidden" id="TRANS_DATE_'.$sno.'" name="TRANS_DATE_'.$sno.'" value="'.$rows['TRANS_DATE'].'"/><input type="hidden" id="TTLDAYS_'.$sno.'" name="TTLDAYS_'.$sno.'" value="'.$rows['TTLDAYS'].'"/><input type="hidden" id="FREIGHTGROSS_'.$sno.'" name="FREIGHTGROSS_'.$sno.'" value="'.$rows['FREIGHT_GROSS'].'"/><input type="hidden" id="FCAID_'.$sno.'" name="FCAID_'.$sno.'" value="'.$rows['FCAID'].'"</td>';
									echo '<td><input type="text" name="diff_'.$sno.'" id="diff_'.$sno.'" class="form-control" readonly="true" autocomplete="off" value="'.$rows['diff'].'" /></td>';
									// echo '<td><input type="text" name="revisedPl_'.$sno.'" id="revisedPl_'.$sno.'" class="form-control" readonly="true" autocomplete="off" value="'.$rows['REVISED_PL'].'" /></td>';
									// echo '<td><input type="checkbox" name="chkFCA[]" id="chkFCA_'.$sno.'" value="'.$rows['FCAID'].'" class="checkbox"/></td>';

									}?>

												



								
						
								</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="getValidate()">Submit</button> -->

									<button type="submit"  class="btn btn-primary" onclick="getValidate()">Submit</button>
		
					
								<input type="hidden" name="action" id="action" value="submit" />
								   
									<input type="hidden" name="txtCRMFILE" id="txtCRMFILE" value="" />
									 <input type="hidden" name="txtCRMNAME" id="txtCRMNAME" value="" />

									 <input type="hidden" name="txtCRMFILEGrid" id="txtCRMFILEGrid" value="" />
									 <input type="hidden" name="txtCRMNAMEGrid" id="txtCRMNAMEGrid" value="" />

									<input type="hidden" name="txtrowcount" id="txtrowcount" value="<?=$sno;?>" /> 
							 </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>


					<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" 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(); ?>
<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/datetimepicker/bootstrap-datetimepicker.css" rel="stylesheet" type="text/css" />
<script src="../../js/plugins/datetimepicker/bootstrap-datetimepicker.min.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>
<script src="https://rawgit.com/eKoopmans/html2pdf/master/dist/html2pdf.bundle.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
    $(".sidebar-toggle").click();
	$("#txtPaymentDate,#txtExchangeDate").datepicker({
		format: 'dd-mm-yyyy',
		autoclose: true
	});
	$("#selVendor").val('<?php echo $obj->getFun15();?>');
	$("#selExchangeCurrency").val('<?php echo $obj->getFun11();?>');
	$(".numeric").numeric();
	$("#selApprovers").chosen();
	$(".areasize").autosize({append: "\n"});

	
	$('[id^=txtInvoiceDate_]').datepicker({
		format: 'dd-mm-yyyy',
		autoclose: true
	});
	getExchangeAmountCal();
});

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


function getExchangeAmountCal()
{


    var resivedPl = 0;
	var actualtotal = 0;
	var actualexchangetotal = 0;

	var txtrowcount = $("#txtrowcount").val();
		for(var chkvalue=1;chkvalue <=txtrowcount;chkvalue++)
		{

				
				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))

				console.log($('#pHire_'+chkvalue).val());
				
			
				$('#diff_'+chkvalue).val(	(parseFloat($('#HIRE_'+chkvalue).val())-parseFloat($('#pHire_'+chkvalue).val())).toFixed(2))
				// $('#revisedPl_'+chkvalue).val(resivedPl.toFixed(2))
		}
	

}


function getValidate(var1)
{

console.log('dpk');

return false;

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

function Del_UploadOfGrid(elx)
{

	jConfirm('Are you sure you want to remove this attachment permanently ?', 'Confirmation', function(r) {
	if(r){
			$(elx).parent().parent().remove();	
			$(elx).parent().parent().prev().val(parseInt($(elx).parent().parent().prev().val())-parseInt(1))
		 }
	else{return false;}
	});
}



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
	{  
	    $("#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:""+chkArr+""}, 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();
	}
}







</script>
	
</body>
</html>