<?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;
$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(); ?>
    <!-- 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>
  <re src="../js/respond.min.js"></re>
<![endif]-->
    <style>
        .outer {
            overflow-y: auto;
            height: 400px;
        }

        .outer {
            width: 100%;
            -layout: fixed;
        }

        .outer th {
            text-align: left;
            top: 0;
            position: sticky;

        }


        th {
            background: #eee;
        }

        hr.dashed {
            border-top: 3px dashed #bbb;
        }



        tr:nth-child(even) {
            background-color: #D6EEEE;
        }

        tr:hover {
            background-color: blanchedalmond;
        }

        tr {
            border-bottom: 1px solid #423030;
        }
    </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(1); ?>
        <aside class="right-side">
            <!-- Content Header (Page header) -->
            <section class="content-header">
                <h1>
                    <i class="fa fa-dashboard"></i>&nbsp;Dashboard&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">Dashboard</li>
                </ol>
            </section>

            <!-- Main content -->
            <section class="content">
                <!--   content put here..................-->

                <div class="row">

                    <div class="col-lg-4 col-xs-6">
                        <!-- small box -->
                        <div class="small-box bg-aqua">
                            <div class="inner">
                                <h4>
                                    Dummy
                                </h4>
                                <p>
                                    <br />


                                </p>
                            </div>
                            <div class="icon">
                                <i class="ionicons ion-pricetag"></i>
                            </div>
                            <a href="#" class="small-box-footer" onClick="getRelocate(2)">
                                Get in <i class="fa fa-arrow-circle-right"></i>
                            </a>
                        </div>
                    </div><!-- ./col -->

                    <div class="col-lg-4 col-xs-6">
                        <!-- small box -->
                        <div class="small-box bg-green">
                            <div class="inner">
                                <h4>
                                    Dummy
                                </h4>
                                <p>
                                    <br />




                                </p>
                            </div>
                            <div class="icon">
                                <i class="ionicons ion-share"></i>
                            </div>
                            <a href="#" class="small-box-footer" onClick="getRelocate(2)">
                                Get in <i class="fa fa-arrow-circle-right"></i>
                            </a>
                        </div>
                    </div><!-- ./col -->

                    <div class="col-lg-4 col-xs-6">
                        <!-- small box -->
                        <div class="small-box bg-blue">
                            <div class="inner">
                                <h4>
                                    Dummy
                                </h4>
                                <p>
                                    <br />

                                </p>
                            </div>
                            <div class="icon">
                                <i class="ionicons ion-bag"></i>
                            </div>
                            <a href="#" class="small-box-footer">
                                Get in <i class="fa fa-arrow-circle-right"></i>
                            </a>
                        </div>
                    </div><!-- ./col -->



                </div>


                <div></div>




                <input type="hidden" name="ttlforhedgepnl" id="ttlforhedgepnl" value="">
                <input type="hidden" name="ttlforhedm2m" id="ttlforhedm2m" value="">
                <input type="hidden" name="nOFD" id="nOFD" value="">




                <div class="modal fade" id="compose-modal" tabindex="-1" role="dialog" aria-hidden="true">
                    <div class="modal-dialog" style="width:70%">
                        <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;FFA DETAILS</h4>
                            </div>

                            <div class="modal-body" id="div_3" style="overflow:auto;">


                                <div class="box-body table-responsive" style="overflow:auto;">

                                    <div id="headingFfaDet"> </div>
                                    <hr style="height:2px;border-width:0;color:gray;background-color:gray">
                                    <table class="table table-bordered table-striped">
                                        <thead>
                                            <tr>
                                                <th align="left" width="15%">MONTH/YEAR

                                                </th>
                                                <th align="left" width="25%">CLOSED DAYS

                                                </th>
                                                <th align="left" width="40%">REALISED PNL

                                                </th>
                                                <th align="left" width="25%">OPEN DAYS</th>
                                                <th align="left" width="40%">M2M PNL</th>
                                                <th align="left" width="40%">TOTAL PNL</th>
                                            </tr>
                                        </thead>






                                        <tbody id="FfaDetailHedgeVsl">

                                        </tbody>
                                    </table>

                                </div>




                            </div>

                        </div>
                    </div>
                </div>






                <!--   content ends here..................-->
            </section><!-- /.content -->
        </aside><!-- /.right-side -->

    </div><!-- ./wrapper -->

</body>





<?php $display->footer(); ?>
<?php $display->js(); ?>
<script src="../../js/timer.js" type="text/javascript"></script>
<link href="../../css/jquery.alerts.css" rel="stylesheet" type="text/css" />
<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/jquery.autosize.js'></script>
<script language="JavaScript" type="text/javascript" src="../../js/jquery.alerts.js"></script>

<script>
    $(document).ready(function() {

        // getData();
        // getDataforspecs();
        // getDataForHedge();



    });

    function getData() {
        $('#reportdataDiv').html('<tr><td align="center" colspan="8"><img src="../../img/loading.gif" /></td></tr>');
        $.post("options.php?id=56", {
            txtFromDate: "" + $("#txtFromDate").val() + "",
            txtToDate: "" + $("#txtToDate").val() + "",
            selBType: "" + $("#selBType").val() + ""
        }, function(html) {
            $('#reportdataDiv,#freighttbody,#reportcompletedataDiv').empty();
            // $('').appendTo("#reportdataDiv");

            // console.log('check')
            $('<div class="box-body table-responsive"><table id="reportcomtable" class="table table-striped display" style="width:100%"><thead><tr><th align="left" width="15%">Vessels</th><th align="left" width="10%">Voyage No.</th><th align="left" width="10%">CP date</th><th align="left" width="40%">Voyage</th><th align="left" width="15%">Delivery - Re-Delivery</th></tr></thead><tbody id="reportcomtbody"></tbody></table></div>').appendTo("#reportcompletedataDiv");

            var jsondata = html.split('@@@');
            var jsondata1 = JSON.parse(jsondata[0]);
            let sumpnlrel = Number(0);
            let nOFD = Number(0);
            let m2mpl = Number(0);
            $.each(jsondata1, function(index, array) {
                if (array['pnl4rel'] == null) {
                    array['pnl4rel'] = 0;
                }
                if (array['NOFD'] == null) {
                    array['NOFD'] = 0;
                }
                if (array['m2mpl'] == null) {
                    array['m2mpl'] = 0;
                }
                if (array['vslForDet'] == null) {
                    array['vslForDet'] = ' ';
                }

                sumpnlrel += parseFloat(array['pnl4rel']);
                nOFD += parseFloat(array['NOFD']);
                if (array['m2mpl'] == '') {
                    array['m2mpl'] = 0
                }
                m2mpl += parseFloat(array['m2mpl']);

                $('<tr><td> <a href="#" class="column1link"  class="blue-border" style="display:block;" data-toggle="modal" data-target="#compose-modal" data-id="' + array['vslForDet'] + '" onclick="getDataForHedgeVsl(' + array['vslForDet'] + ');">' + array['vessel'] + '</a></td><td>' + array['pnl4rel'] + '</td><td>' + array['NOFD'] + '</td><td>' + array['m2mpl'] + '</td></tr>').appendTo("#reportdataDiv");

                // $('<tr><td>'+array['vessel']+'</td><td>'+array['voyageno']+'</td><td data-order="'+array['cpdatestr']+'">'+array['cpdate']+'</td><td>'+array['voyage']+'</td><td>'+array['delredeldate']+'</td></tr>').appendTo("#reportcomtbody");
            });
            // $('#reporttable').dataTable();




            $('#ttlforhedgepnl').val(parseFloat(sumpnlrel));
            $('#ttlforhedm2m').val(parseFloat(m2mpl));
            $('#nOFD').val(parseFloat(nOFD));


            $('<tr style="color:#ff5e00;"><td><strong>Total</strong></td><td><strong>' + sumpnlrel.toFixed(3) + '</strong></td><td><strong>' + nOFD.toFixed(3) + '</strong></td><td><strong>' + m2mpl.toFixed(3) + '</strong></td></tr>').appendTo("#reportdataDiv");


        });




    }


    function getDataForHedge() {
        $('#reportdataDivForCargo').html('<tr><td align="center" colspan="8"><img src="../../img/loading.gif" /></td></tr>');
        $.post("options.php?id=138", {
            txtFromDate: "" + $("#txtFromDate").val() + "",
            txtToDate: "" + $("#txtToDate").val() + "",
            selBType: "" + $("#selBType").val() + ""
        }, function(html) {

            $('#reportdataDivForCargo,#freighttbody,#reportcompletedataDiv').empty();


            var jsondata = html.split('@@@');
            var jsondata1 = JSON.parse(jsondata[0]);
            let sumpnlrel = Number(0);
            let nOFD = Number(0);
            let m2mpl = Number(0);
            $.each(jsondata1, function(index, array) {
                if (array['pnl4rel'] == null) {
                    array['pnl4rel'] = 0;
                }
                if (array['NOFD'] == null) {
                    array['NOFD'] = 0;
                }
                if (array['m2mpl'] == null) {
                    array['m2mpl'] = 0;
                }
                if (array['vslForDet'] == null) {
                    array['vslForDet'] = ' ';
                }

                sumpnlrel += parseFloat(array['pnl4rel']);
                nOFD += parseFloat(array['NOFD']);
                if (array['m2mpl'] == '') {
                    array['m2mpl'] = 0
                }
                m2mpl += parseFloat(array['m2mpl']);

                $('<tr ><td> <a href="#" class="column1link1_"  class="blue-border" style="display:block;" data-toggle="modal" data-target="#compose-modal" data-id="' + array['cargohedge'] + '" data-type="cargo"  data-fix="' + array['FIXTURE_NO'] + '">' + array['cargohedgename'] + '</a></td><td>' + array['pnl4rel'] + '</td><td>' + array['NOFD'] + '</td><td>' + array['m2mpl'] + '</td></tr>').appendTo("#reportdataDivForCargo");



                // $('<tr><td>'+array['vessel']+'</td><td>'+array['voyageno']+'</td><td data-order="'+array['cpdatestr']+'">'+array['cpdate']+'</td><td>'+array['voyage']+'</td><td>'+array['delredeldate']+'</td></tr>').appendTo("#reportcomtbody");
            });
            // $('#reporttable').dataTable();

            setTimeout(function() {
                $('#ttlforhedgepnl').val(parseFloat($('#ttlforhedgepnl').val()) + parseFloat(sumpnlrel));

                $('#ttlforhedm2m').val(parseFloat(m2mpl) + parseFloat($('#ttlforhedm2m').val()));

                $('#nOFD').val(parseFloat(parseFloat($('#nOFD').val()) + nOFD));
            }, 1500);

            $('<tr style="color:#ff5e00;"><td><strong>Total</strong></td><td><strong>' + sumpnlrel.toFixed(3) + '</strong></td><td><strong>' + nOFD.toFixed(3) + '</strong></td><td><strong>' + m2mpl.toFixed(3) + '</strong></td></tr>').appendTo("#reportdataDivForCargo");


        });




    }





    $(document).on("click", "a[href^=\'#\']", function(e) {

        if ($(this).data("type") == 'cargo') {

            $('#FfaDetailHedgeVsl').html('<tr><td align="center" colspan="8"><img src="../../img/loading.gif" /></td></tr>');
            $.post("options.php?id=139", {
                vslid: "" + $(this).data("id") + "",
                txtToDate: "" + $("#txtToDate").val() + "",
                txtFromDate: "" + $("#txtFromDate").val() + "",
                fixtureno: "" + $(this).data("fix") + ""
            }, function(html) {

                $('#FfaDetailHedgeVsl,#headingFfaDet').empty();

                $('<div class="box-body table-responsive"><table id="reportcomtable" class="table table-striped display" style="width:100%"><thead><tr><th align="left" width="15%">Vessels</th><th align="left" width="10%">Voyage No.</th><th align="left" width="10%">CP date</th><th align="left" width="40%">Voyage</th><th align="left" width="15%">Delivery - Re-Delivery</th></tr></thead><tbody id="reportcomtbody"></tbody></table></div>').appendTo("#reportcompletedataDiv");

                var jsondata = html.split('@@@');
                var jsondata1 = JSON.parse(jsondata[0]);
                let sumpnlrel = Number(0);
                let nOFD = Number(0);
                let m2mpl = Number(0);
                let closedDays = Number(0);
                let ttlpnl = Number(0);
                let ttlForTTlpnl = Number(0);
                let vsl = '';
                $.each(jsondata1, function(index, array) {

                    ttlpnl = 0;
                    if (array['PERIOD'] == null) {
                        array['PERIOD'] = 0;
                    }
                    if (array['pnl4rel'] == null) {
                        array['pnl4rel'] = 0;
                    }
                    if (array['NOFD'] == null) {
                        array['NOFD'] = 0;
                    }
                    if (array['m2mpl'] == null) {
                        array['m2mpl'] = 0;
                    }
                    if (array['closedDays'] == null) {
                        array['closedDays'] = ' ';
                    }
                    if (array['vessel'] == null) {
                        array['vessel'] = ' ';
                    }

                    sumpnlrel += parseFloat(array['pnl4rel']);
                    nOFD += parseFloat(array['NOFD']);
                    if (array['m2mpl'] == '') {
                        array['m2mpl'] = 0
                    }
                    m2mpl += parseFloat(array['m2mpl']);
                    closedDays += parseFloat(array['closedDays']);

                    ttlpnl = parseFloat(array['pnl4rel']) + parseFloat(array['m2mpl']);

                    ttlForTTlpnl += ttlpnl;
                    vsl = array['cargo'];

                    $('<tr><td>' + array['PERIOD'] + '</td><td>' + array['closedDays'] + '</td><td>' + array['pnl4rel'] + '</td><td>' + array['NOFD'] + '</td><td>' + array['m2mpl'] + '</td><td>' + ttlpnl.toFixed(2) + '</td></tr>').appendTo("#FfaDetailHedgeVsl");




                    // $('<tr><td>'+array['vessel']+'</td><td>'+array['voyageno']+'</td><td data-order="'+array['cpdatestr']+'">'+array['cpdate']+'</td><td>'+array['voyage']+'</td><td>'+array['delredeldate']+'</td></tr>').appendTo("#reportcomtbody");
                });
                // $('#reporttable').dataTable();

                $('<h3 align="center">' + vsl + '</h3>').appendTo("#headingFfaDet");
                $('#ttlforhedgepnl').val(parseFloat(sumpnlrel));
                $('#ttlforhedm2m').val(parseFloat(m2mpl));
                $('#nOFD').val(parseFloat(nOFD));


                $('<tr style="color:#ff5e00;"><td><strong>Total</strong></td><td><strong>' + closedDays.toFixed(3) + '</strong></td><td><strong>' + sumpnlrel.toFixed(3) + '</strong></td><td><strong>' + nOFD.toFixed(3) + '</strong></td><td><strong>' + m2mpl.toFixed(3) + '</strong></td><td><strong>' + ttlForTTlpnl.toFixed(3) + '</strong></td></tr>').appendTo("#FfaDetailHedgeVsl");


            });









        }
        e.preventDefault();
        return false;
    });


    function getDataForHedgeVsl(vslid) {

        $('#FfaDetailHedgeVsl').html('<tr><td align="center" colspan="8"><img src="../../img/loading.gif" /></td></tr>');
        $.post("options.php?id=137", {
            vslid: "" + vslid + "",
            txtToDate: "" + $("#txtToDate").val() + "",
            txtFromDate: "" + $("#txtFromDate").val() + ""
        }, function(html) {
            $('#FfaDetailHedgeVsl,#headingFfaDet').empty();
            // $('').appendTo("#reportdataDiv");

            // console.log('check')
            $('<div class="box-body table-responsive"><table id="reportcomtable" class="table table-striped display" style="width:100%"><thead><tr><th align="left" width="15%">Vessels</th><th align="left" width="10%">Voyage No.</th><th align="left" width="10%">CP date</th><th align="left" width="40%">Voyage</th><th align="left" width="15%">Delivery - Re-Delivery</th></tr></thead><tbody id="reportcomtbody"></tbody></table></div>').appendTo("#reportcompletedataDiv");

            var jsondata = html.split('@@@');
            var jsondata1 = JSON.parse(jsondata[0]);
            let sumpnlrel = Number(0);
            let nOFD = Number(0);
            let m2mpl = Number(0);
            let closedDays = Number(0);
            let ttlpnl = Number(0);
            let ttlForTTlpnl = Number(0);
            let vsl = '';
            $.each(jsondata1, function(index, array) {

                ttlpnl = 0;
                if (array['PERIOD'] == null) {
                    array['PERIOD'] = 0;
                }
                if (array['pnl4rel'] == null) {
                    array['pnl4rel'] = 0;
                }
                if (array['NOFD'] == null) {
                    array['NOFD'] = 0;
                }
                if (array['m2mpl'] == null) {
                    array['m2mpl'] = 0;
                }
                if (array['closedDays'] == null) {
                    array['closedDays'] = ' ';
                }
                if (array['vessel'] == null) {
                    array['vessel'] = ' ';
                }

                sumpnlrel += parseFloat(array['pnl4rel']);
                nOFD += parseFloat(array['NOFD']);
                if (array['m2mpl'] == '') {
                    array['m2mpl'] = 0
                }
                m2mpl += parseFloat(array['m2mpl']);
                closedDays += parseFloat(array['closedDays']);

                ttlpnl = parseFloat(array['pnl4rel']) + parseFloat(array['m2mpl']);

                ttlForTTlpnl += ttlpnl;
                vsl = array['vessel'];

                $('<tr><td>' + array['PERIOD'] + '</td><td>' + array['closedDays'] + '</td><td>' + array['pnl4rel'] + '</td><td>' + array['NOFD'] + '</td><td>' + array['m2mpl'] + '</td><td>' + ttlpnl.toFixed(2) + '</td></tr>').appendTo("#FfaDetailHedgeVsl");




                // $('<tr><td>'+array['vessel']+'</td><td>'+array['voyageno']+'</td><td data-order="'+array['cpdatestr']+'">'+array['cpdate']+'</td><td>'+array['voyage']+'</td><td>'+array['delredeldate']+'</td></tr>').appendTo("#reportcomtbody");
            });
            // $('#reporttable').dataTable();

            $('<h3 align="center">' + vsl + '</h3>').appendTo("#headingFfaDet");
            $('#ttlforhedgepnl').val(parseFloat(sumpnlrel));
            $('#ttlforhedm2m').val(parseFloat(m2mpl));
            $('#nOFD').val(parseFloat(nOFD));


            $('<tr style="color:#ff5e00;"><td><strong>Total</strong></td><td><strong>' + closedDays.toFixed(3) + '</strong></td><td><strong>' + sumpnlrel.toFixed(3) + '</strong></td><td><strong>' + nOFD.toFixed(3) + '</strong></td><td><strong>' + m2mpl.toFixed(3) + '</strong></td><td><strong>' + ttlForTTlpnl.toFixed(3) + '</strong></td></tr>').appendTo("#FfaDetailHedgeVsl");


        });



    }








    function getDataforspecs() {
        $('#reportdataDivforspecs,#reportdataDivttl').html('<tr><td align="center" colspan="8"><img src="../../img/loading.gif" /></td></tr>');
        $.post("options.php?id=136", {
            txtFromDate: "" + $("#txtFromDate").val() + "",
            txtToDate: "" + $("#txtToDate").val() + "",
            selBType: "" + $("#selBType").val() + ""
        }, function(html) {
            $('#reportdataDivforspecs,#freighttbody,#reportcompletedataDiv').empty();
            // $('').appendTo("#reportdataDiv");

            $('<div class="box-body table-responsive"><table id="reportcomtable" class="table table-striped display" style="width:100%"><thead><tr><th align="left" width="15%">Vessels</th><th align="left" width="10%">Voyage No.</th><th align="left" width="10%">CP date</th><th align="left" width="40%">Voyage</th><th align="left" width="15%">Delivery - Re-Delivery</th></tr></thead><tbody id="reportcomtbody"></tbody></table></div>').appendTo("#reportcompletedataDiv");

            var jsondata = html.split('@@@');
            var jsondata1 = JSON.parse(jsondata[0]);
            let sumpnlrel = Number(0);
            let nOFD = Number(0);
            let m2mpl = Number(0);
            $.each(jsondata1, function(index, array) {
                if (array['pnl4rel'] == null) {
                    array['pnl4rel'] = 0;
                }
                if (array['NOFD'] == null) {
                    array['NOFD'] = 0;
                }
                if (array['m2mpl'] == null) {
                    array['m2mpl'] = 0;
                }

                sumpnlrel += parseFloat(array['pnl4rel']);
                nOFD += parseFloat(array['NOFD']);
                if (array['m2mpl'] == '') {
                    array['m2mpl'] = 0
                }
                m2mpl += parseFloat(array['m2mpl']);
                $('<tr><td>' + array['vessel'] + '</td><td>' + array['pnl4rel'] + '</td><td>' + array['NOFD'] + '</td><td>' + array['m2mpl'] + '</td></tr>').appendTo("#reportdataDivforspecs");

                // $('<tr><td>'+array['vessel']+'</td><td>'+array['voyageno']+'</td><td data-order="'+array['cpdatestr']+'">'+array['cpdate']+'</td><td>'+array['voyage']+'</td><td>'+array['delredeldate']+'</td></tr>').appendTo("#reportcomtbody");
            });
            // $('#reporttable').dataTable();

            $('<tr style="color:#ff5e00;"><td><strong>Total</strong></td><td><strong>' + sumpnlrel.toFixed(3) + '</strong></td><td><strong>' + nOFD.toFixed(3) + '</strong></td><td><strong>' + m2mpl.toFixed(3) + '</strong></td></tr>').appendTo("#reportdataDivforspecs");

            // $('#reportdataDivttl').html('<tr><td align="center" colspan="8"><img src="../../img/loading.gif" /></td></tr>');
            setTimeout(function() {

                $('#reportdataDivttl').empty();
                $('<tr><td>SPECS</td><td>' + nOFD.toFixed(3) + '</td><td>' + m2mpl.toFixed(3) + '</td></tr>').appendTo("#reportdataDivttl");
                $('<tr><td>HEDGE</td><td>' + $('#nOFD').val() + '</td><td>' + $('#ttlforhedm2m').val() + '</td></tr>').appendTo("#reportdataDivttl");
                let ttlforriskdays = parseFloat(nOFD.toFixed(3)) + parseFloat($('#nOFD').val());
                let ttlforriskm2m = parseFloat(m2mpl.toFixed(3)) + parseFloat($('#ttlforhedm2m').val());
                $('<tr style="color:#ff5e00;"><td><strong>Total</strong></td><td><strong>' + ttlforriskdays.toFixed(3) + '</strong></td><td><strong>' + ttlforriskm2m.toFixed(3) + '</strong></td></tr>').appendTo("#reportdataDivttl");

            }, 2500);


        });




    }
</script>


</html>