<?php
//entrada dos parametro via GET (moedid/perid)
$moedid = filter_input(INPUT_GET, 'moedid', FILTER_DEFAULT);
$perid = filter_input(INPUT_GET, 'perid', FILTER_VALIDATE_INT);

//montando as datas de acordo com o periodo
$data_fim = date("Y-m-d");
$data_ini = date('Y-m-d', strtotime("-{$perid} month", strtotime($data_fim)));
?>
<ul class="page-breadcrumb breadcrumb">
    <li>
        <span>Indice</span>
    </li>
</ul>
<br>
<div class="row">
    <div class="col-md-12">
        <form method="POST" action="javascript:filtro();" class="form-inline margin-bottom-40" role="form">
            <div class="form-group form-md-line-input">
                <select class="form-control" name="moedid" id="campo_moeda">
                    <option value="">Selecione a moeda</option>
                    <?php
                    $Read = new Read;
                    $Read->ExeRead("tp_moedas");
                    if ($Read->getResult()):
                        foreach ($Read->getResult() as $moedas):
                            extract($moedas);
                            $sel = '';
                            if (isset($moedid) && $moedid == $moeda_codigo) {
                                $sel = 'selected';
                            }
                            ?>

                            <option <?= $sel; ?> value="<?= $moeda_codigo; ?>"><?= $moeda_nome; ?></option>

                            <?php
                        endforeach;
                    endif;
                    ?>
                </select>
                <div class="form-control-focus"> </div>
            </div>
            <div class="form-group form-md-line-input has-success">
                <select class="form-control" name="perid" id="campo_periodo">
                    <option value="">Selecione o periodo</option>
                    <?php
                    $Read = new Read;
                    $Read->ExeRead("tp_periodos", "ORDER BY periodo_meses ASC");
                    if ($Read->getResult()):
                        foreach ($Read->getResult() as $periodos):
                            extract($periodos);
                            $sel = '';
                            if (isset($perid) && $perid == $periodo_meses) {
                                $sel = 'selected';
                            }
                            ?>

                            <option <?= $sel; ?> value="<?= $periodo_meses; ?>"><?= $periodo_nome; ?></option>

                            <?php
                        endforeach;
                    endif;
                    ?>
                </select>
                <div class="form-control-focus"> </div>
            </div>
            <button type="button" onclick="filtro()" class="btn btn-sm btn-success table-group-action-submit"> <i class="fa fa-check"></i> Carregar</button>

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

<?php
if ($moedid == '' || $perid == ''):
    WSErro("Selecione a moeda e o periodo para consulta!", WS_INFOR);
else:

    $Query = "SELECT ";
    $Query .= "indice_data, ";
    $Query .= "CFTC_Contract_Market_Code, ";
    $Query .= "NonComm_Positions_Long_All, ";
    $Query .= "NonComm_Positions_Short_All, ";
    $Query .= "Comm_Positions_Long_All, ";
    $Query .= "Comm_Positions_Short_All, ";
    $Query .= "Open_Interest_All, ";
    $Query .= "Open_Interest_Old, ";
    $Query .= "NonComm_Postions_Spread_All, ";

    $Query .= "NonComm_Positions_Long_All, ";
    $Query .= "Comm_Positions_Long_All, ";
    $Query .= "NonRept_Positions_Long_All, ";
    $Query .= "NonRept_Positions_Short_All, ";

    $Query .= "Pct_of_OI_NonComm_Long_All, ";
    $Query .= "Pct_of_OI_NonComm_Short_All ";
    $Query .= "FROM ";
    $Query .= "tp_indice ";
    $Query .= "WHERE ";
    $Query .= "CFTC_Contract_Market_Code = :codigo ";
    $Query .= "AND indice_data BETWEEN :data_ini AND :data_fim ";
    $Query .= "ORDER BY indice_data DESC";


    $Read = new Read;
    $Read->FullRead($Query, "codigo={$moedid}&data_ini={$data_ini}&data_fim={$data_fim}");

    foreach ($Read->getResult() as $rs):
        extract($rs);

        if ($moedid == '095741' || $moedid == '092741' || $moedid == '090741' || $moedid == '097741'):

            $Dados['NetNonComm'][] = $NonComm_Positions_Short_All - $NonComm_Positions_Long_All;
            $Dados['NetComm'][] = $Comm_Positions_Short_All - $Comm_Positions_Long_All;
            $Dados['Flip'][] = $Pct_of_OI_NonComm_Short_All - $Pct_of_OI_NonComm_Long_All;
            $Dados['Cover'][] = ($NonComm_Positions_Short_All - $NonComm_Positions_Long_All) / ($Open_Interest_All - $NonComm_Postions_Spread_All);

        else:

            $Dados['NetNonComm'][] = $NonComm_Positions_Long_All - $NonComm_Positions_Short_All;
            $Dados['NetComm'][] = $Comm_Positions_Long_All - $Comm_Positions_Short_All;
            $Dados['Flip'][] = $Pct_of_OI_NonComm_Long_All - $Pct_of_OI_NonComm_Short_All;
            $Dados['Cover'][] = ($NonComm_Positions_Long_All - $NonComm_Positions_Short_All) / ($Open_Interest_All - $NonComm_Postions_Spread_All);

        endif;

//        $Dados['indice_data'][] = $indice_data;
        $Dados['indice_data'][] = "'" . date("d/m/Y", strtotime($indice_data)) . "'";
        $Dados['ind_data'][] = date("d/m/Y", strtotime($indice_data));
        $Dados['CFTC_Contract_Market_Code'][] = $CFTC_Contract_Market_Code;
        $Dados['NonComm_Positions_Long_All'][] = $NonComm_Positions_Long_All;
        $Dados['NonComm_Positions_Short_All'][] = $NonComm_Positions_Short_All;
        $Dados['Comm_Positions_Long_All'][] = $Comm_Positions_Long_All;
        $Dados['Comm_Positions_Short_All'][] = $Comm_Positions_Short_All;
        $Dados['Open_Interest_All'][] = $Open_Interest_All;
        $Dados['Open_Interest_Old'][] = $Open_Interest_Old;
        $Dados['NonComm_Postions_Spread_All'][] = $NonComm_Postions_Spread_All;
        $Dados['NonRept_Positions_Long_All'][] = $NonRept_Positions_Long_All;
        $Dados['NonRept_Positions_Short_All'][] = $NonRept_Positions_Short_All;

        $Dados['Long_All'][] = $NonComm_Positions_Long_All;
        $Dados['Short_All'][] = $NonComm_Positions_Short_All;
        $Dados['Pct_of_OI_NonComm_Long_All'][] = $Pct_of_OI_NonComm_Long_All;
        $Dados['Pct_of_OI_NonComm_Short_All'][] = $Pct_of_OI_NonComm_Short_All;

        $Dados['Aberto'][] = $NonComm_Positions_Long_All + $NonComm_Postions_Spread_All + $Comm_Positions_Long_All + $NonRept_Positions_Long_All;
        $Dados['Volume'][] = $NonComm_Positions_Long_All + $NonComm_Positions_Short_All;

    endforeach;
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////Dolar USD//////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
    $moedaBase = '098662';
    $Read = new Read;
    $Read->FullRead($Query, "codigo={$moedaBase}&data_ini={$data_ini}&data_fim={$data_fim}");

    foreach ($Read->getResult() as $rs):
        extract($rs);

        if ($moedid == '095741' || $moedid == '092741' || $moedid == '090741' || $moedid == '097741'):

            $Usd['NetNonComm'][] = $NonComm_Positions_Short_All - $NonComm_Positions_Long_All;
            $Usd['NetComm'][] = $Comm_Positions_Short_All - $Comm_Positions_Long_All;
            $Usd['Flip'][] = $Pct_of_OI_NonComm_Short_All - $Pct_of_OI_NonComm_Long_All;
            $Usd['Cover'][] = $NonComm_Positions_Short_All - $NonComm_Positions_Long_All / ($Open_Interest_All - $NonComm_Postions_Spread_All);

        else:

            $Usd['NetNonComm'][] = $NonComm_Positions_Long_All - $NonComm_Positions_Short_All;
            $Usd['NetComm'][] = $Comm_Positions_Long_All - $Comm_Positions_Short_All;
            $Usd['Flip'][] = $Pct_of_OI_NonComm_Long_All - $Pct_of_OI_NonComm_Short_All;
            $Usd['Cover'][] = $NonComm_Positions_Long_All - $NonComm_Positions_Short_All / ($Open_Interest_All - $NonComm_Postions_Spread_All);

        endif;

        $Usd['indice_data'][] = $indice_data;
        $Usd['CFTC_Contract_Market_Code'][] = $CFTC_Contract_Market_Code;
        $Usd['NonComm_Positions_Long_All'][] = $NonComm_Positions_Long_All;
        $Usd['NonComm_Positions_Short_All'][] = $NonComm_Positions_Short_All;
        $Usd['Comm_Positions_Long_All'][] = $Comm_Positions_Long_All;
        $Usd['Comm_Positions_Short_All'][] = $Comm_Positions_Short_All;
        $Usd['Open_Interest_All'][] = $Open_Interest_All;
        $Usd['NonComm_Postions_Spread_All'][] = $NonComm_Postions_Spread_All;

    endforeach;
///////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////End Dolar USD//////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////Maximo e Minimo///////////////
////Sinal
    for ($i = 0; $i < count($Dados['indice_data']); $i++) {
        ///Moeda
        if ($moedid == '095741' || $moedid == '092741' || $moedid == '090741' || $moedid == '097741'):
            $Dados['Sinal'][] = $Dados['NetNonComm'][$i] - $Usd['NetNonComm'][$i];
        elseif ($moedid == '098662' || $moedid == '067651'):
            $Dados['Sinal'][] = $Dados['NetNonComm'][$i];
        else:
            $Dados['Sinal'][] = $Dados['NetNonComm'][$i] - $Usd['NetNonComm'][$i];
        endif;
    }
////End Sinal

    $maxNetNC = max($Dados['NetNonComm']);
    $minNetNC = min($Dados['NetNonComm']);
    $maxNetCC = max($Dados['NetComm']);
    $minNetCC = min($Dados['NetComm']);
    $maxCover = max($Dados['Cover']);
    $minCover = min($Dados['Cover']);
    $maxFlip = max($Dados['Flip']);
    $minFlip = min($Dados['Flip']);
    $maxSinal = max($Dados['Sinal']);
    $minSinal = min($Dados['Sinal']);
/////////////END MAX MIN////////////////
/////////////////////////////////////////////////////////////////////////////////////////
//////////////////Montando array dos gráfico ////////////////////////
////////////////////////////////////////////////////////////////////////////////////////
    $indice = count($Usd['indice_data']);
    for ($i = 0; $i < count($Usd['indice_data']); $i++) {
        if ($moedid == '095741' || $moedid == '092741' || $moedid == '090741' || $moedid == '097741'):
            ///Diferença
            $Array['Dif'][] = $Dados['NetNonComm'][$i] - $Usd['NetNonComm'][$i];
        elseif ($moedid == '098662' || $moedid == '067651'):
            ///Diferença
            $Array['Dif'][] = $Dados['NetNonComm'][$i];
        else:
            ///Diferença
            $Array['Dif'][] = $Dados['NetNonComm'][$i] - $Usd['NetNonComm'][$i];
        endif;
        ///Liquidez 
        $NetNC = ($Dados['NetNonComm'][$i] - $minNetNC) / ($maxNetNC - $minNetNC) * 100;
        $Array['NetNC'][] = number_format($NetNC, 2);
        $NetCC = ($Dados['NetComm'][$i] - $minNetCC) / ($maxNetCC - $minNetCC) * 100;
        $Array['NetCC'][] = number_format($NetCC, 2);

        ///Moviment index
        $Moviment = ($Dados['Cover'][$i] - $minCover) / ($maxCover - $minCover) * 100;

        $diferenca = $indice - $i;
        if ($diferenca < 7):
            $p = $diferenca - 1;
        else:
            $p = 6;
        endif;

        $pi = $i + $p;
        $Index = ($Dados['Cover'][$pi] - $minCover) / ($maxCover - $minCover) * 100;
        $MovimentIndex = $Moviment - $Index;
        $Array['MovimentIndex'][] = number_format($MovimentIndex, 2);

        ///Flip
        $FlipNC = ($Dados['Flip'][$i] - $minFlip) / ($maxFlip - $minFlip) * 100;
        $Array['FlipNC'][] = number_format($FlipNC, 2);

        ///Moeda
        $Sinal = ($Dados['Sinal'][$i] - $minSinal) / ($maxSinal - $minSinal) * 100;
        $Array['Sinal'][] = number_format($Sinal, 2);
    }
//////////End array dos gráficos
////////////////////////////////////////////////////////////////////

    $ind = count($Array['Dif']);
    $arr = array();
    for ($i = 0; $i < count($Array['Dif']); $i++) {
        $entre = $ind - $i;
        if ($entre < 12):
            $p = $entre - 1;
        else:
            $p = 12;
        endif;
        //testar se o multiplo esta zera e inserir 1
        if ($p < 1) {
            $p = 1;
        }
        ///////

        $b = $i + $p;
        for ($a = $i; $a < $b; $a++) {
            $arr['mNet'][] = $Dados['NonComm_Positions_Long_All'][$a] - $Dados['NonComm_Positions_Short_All'][$a];
            $arr['mNetU'][] = $Usd['NonComm_Positions_Long_All'][$a] - $Usd['NonComm_Positions_Short_All'][$a];
            $arr['mDif'][] = $Array['Dif'][$a];
        }
        $NetMedia = array_sum($arr['mNet']) / $p;
        $NetUMedia = array_sum($arr['mNetU']) / $p;
        $DifMedia = array_sum($arr['mDif']) / $p;
        $Array['NetMedia'][] = round($NetMedia);
        $Array['NetUMedia'][] = round($NetUMedia);
        $Array['DifMedia'][] = round($DifMedia);
        unset($arr);
    }


////////////////////////////////////////////////////////////////////////////////////////
//////////////////End Array do gráfico//////////////////
///////////////////////////////////////////////////////////////////////////////////////
/////////Grafico 1 DIF ////////////
    $difDat = implode(', ', array_reverse($Dados['indice_data']));
    $DifStr = implode(', ', array_reverse($Array['Dif']));
    $DifMediaStr = implode(', ', array_reverse($Array['DifMedia']));

/////////Grafico 2 NET ////////////
    $NetNonCommStr = implode(', ', array_reverse($Array['NetNC']));
    $NetCommStr = implode(', ', array_reverse($Array['NetCC']));

////////Grafico 3 Moviment Index ////////////
    $IndexStr = implode(', ', array_reverse($Array['MovimentIndex']));

////////Grafico 4 Flip ////////////
    $FlipStr = implode(', ', array_reverse($Array['FlipNC']));

////////Grafico 5 Sinal ///////////
    $SinalStr = implode(', ', array_reverse($Array['Sinal']));

////////Grafico 6 Volume ///////////
    $AbertoStr = implode(', ', array_reverse($Dados['Aberto']));
    $VolumeStr = implode(', ', array_reverse($Dados['Volume']));

////////Grafico 7 Long Short ///////////
    $LongStr = implode(', ', array_reverse($Dados['Long_All']));
    $ShortStr = implode(', ', array_reverse($Dados['Short_All']));


/////////////// Table //////////////////
////
    for ($i = 0; $i < 20; $i++) {
        $Table[$i]['Data'] = $Dados['ind_data'][$i];
        $Table[$i]['LongNC'] = $Dados['NonComm_Positions_Long_All'][$i];
        $Table[$i]['ShortNC'] = $Dados['NonComm_Positions_Short_All'][$i];
        $TotalNC = $Dados['NonComm_Positions_Long_All'][$i] + $Dados['NonComm_Positions_Short_All'][$i];
        $Table[$i]['TotalNC'] = $TotalNC;

        $Table[$i]['PercLongNC'] = number_format(($Dados['NonComm_Positions_Long_All'][$i] * 100) / $TotalNC);
        $Table[$i]['PercShortNC'] = number_format(($Dados['NonComm_Positions_Short_All'][$i] * 100) / $TotalNC);

        $TableNetNC = $Dados['NonComm_Positions_Long_All'][$i] - $Dados['NonComm_Positions_Short_All'][$i];
        $Table[$i]['NetNC'] = $Dados['NonComm_Positions_Long_All'][$i] - $Dados['NonComm_Positions_Short_All'][$i];
        $Table[$i]['DivLongNC'] = number_format($Dados['NonComm_Positions_Long_All'][$i] / $Dados['NonComm_Positions_Short_All'][$i], 1, ',', '.') . ':1';
        $Table[$i]['DivShortNC'] = number_format($Dados['NonComm_Positions_Short_All'][$i] / $Dados['NonComm_Positions_Long_All'][$i], 1, ',', '.') . ':1';

        ////USD
        $Table[$i]['UsdLongNC'] = $Usd['NonComm_Positions_Long_All'][$i];
        $Table[$i]['UsdShortNC'] = $Usd['NonComm_Positions_Short_All'][$i];
        $UsdTotalNC = $Usd['NonComm_Positions_Long_All'][$i] + $Usd['NonComm_Positions_Short_All'][$i];
        $Table[$i]['UsdTotalNC'] = $UsdTotalNC;

        $Table[$i]['UsdPercLongNC'] = number_format(($Usd['NonComm_Positions_Long_All'][$i] * 100) / $UsdTotalNC);
        $Table[$i]['UsdPercShortNC'] = number_format(($Usd['NonComm_Positions_Short_All'][$i] * 100) / $UsdTotalNC);

        $TableUsdNetNC = $Usd['NonComm_Positions_Long_All'][$i] - $Usd['NonComm_Positions_Short_All'][$i];
        $Table[$i]['UsdNetNC'] = $Usd['NonComm_Positions_Long_All'][$i] - $Usd['NonComm_Positions_Short_All'][$i];
        if ($moedid == '095741' || $moedid == '092741' || $moedid == '090741' || $moedid == '097741'):
            ///Diferença
            $Table[$i]['Diferenca'] = $TableUsdNetNC - $TableNetNC;
        elseif ($moedid == '098662' || $moedid == '067651'):
            $Table[$i]['Diferenca'] = $TableNetNC;
        else:
            $Table[$i]['Diferenca'] = $TableNetNC - $TableUsdNetNC;
        endif;

        $Table[$i]['NetMedia'] = $Array['NetMedia'][$i];
        $Table[$i]['NetUMedia'] = $Array['NetUMedia'][$i];
        $Table[$i]['DifMedia'] = $Array['DifMedia'][$i];
    }
////End Table
/////////////// Array Média Table //////////////////
////
    for ($i = 0; $i < 12; $i++) {
        $MTable['LongNC'][$i] = $Dados['NonComm_Positions_Long_All'][$i];
        $MTable['ShortNC'][$i] = $Dados['NonComm_Positions_Short_All'][$i];
        $TotalNC = $Dados['NonComm_Positions_Long_All'][$i] + $Dados['NonComm_Positions_Short_All'][$i];
        $MTable['TotalNC'][$i] = $TotalNC;

        $TableNetNC = $Dados['NonComm_Positions_Long_All'][$i] - $Dados['NonComm_Positions_Short_All'][$i];
        $MTable['NetNC'][$i] = $Dados['NonComm_Positions_Long_All'][$i] - $Dados['NonComm_Positions_Short_All'][$i];

        ////USD
        $MTable['UsdLongNC'][$i] = $Usd['NonComm_Positions_Long_All'][$i];
        $MTable['UsdShortNC'][$i] = $Usd['NonComm_Positions_Short_All'][$i];
        $UsdTotalNC = $Usd['NonComm_Positions_Long_All'][$i] + $Usd['NonComm_Positions_Short_All'][$i];
        $MTable['UsdTotalNC'][$i] = $UsdTotalNC;

        $TableUsdNetNC = $Usd['NonComm_Positions_Long_All'][$i] - $Usd['NonComm_Positions_Short_All'][$i];
        $MTable['UsdNetNC'][$i] = $Usd['NonComm_Positions_Long_All'][$i] - $Usd['NonComm_Positions_Short_All'][$i];
        if ($moedid == '095741' || $moedid == '092741' || $moedid == '090741' || $moedid == '097741'):
            ///Diferença
            $MTable['Diferenca'][$i] = $TableUsdNetNC - $TableNetNC;
        elseif ($moedid == '098662' || $moedid == '067651'):
            $MTable['Diferenca'][$i] = $TableNetNC;
        else:
            $MTable['Diferenca'][$i] = $TableNetNC - $TableUsdNetNC;
        endif;
    }
////End Array Média Table
/////////////// Tirando Média Table ///////
    $MTableLong = round(array_sum($MTable['LongNC']) / 12);
    $MTableShort = round(array_sum($MTable['ShortNC']) / 12);
    $MTableTotal = round(array_sum($MTable['TotalNC']) / 12);
    $MTableNet = round(array_sum($MTable['NetNC']) / 12);
    $MTableLongUsd = round(array_sum($MTable['UsdLongNC']) / 12);
    $MTableShortUsd = round(array_sum($MTable['UsdShortNC']) / 12);
    $MTableTotalUsd = round(array_sum($MTable['UsdTotalNC']) / 12);
    $MTableNetUsd = round(array_sum($MTable['UsdNetNC']) / 12);
    $MTableDif = round(array_sum($MTable['Diferenca']) / 12);
//////////End Media Table//////////////////
/////////////contrato em aberto////////
    $CANCLong = $Dados['NonComm_Positions_Long_All'][0];
    $CANCShort = $Dados['NonComm_Positions_Short_All'][0];
    $CANCSpread = $Dados['NonComm_Postions_Spread_All'][0];
    $CACCLong = $Dados['Comm_Positions_Long_All'][0];
    $CACCShort = $Dados['Comm_Positions_Short_All'][0];
    $CAVVLong = $Dados['NonRept_Positions_Long_All'][0];
    $CAVVShort = $Dados['NonRept_Positions_Short_All'][0];
    $CATOTAL = $CANCLong + $CANCSpread + $CACCLong + $CAVVLong;

//echo "<pre>";
//print_r($Table);
//echo "</pre>";
    /////////////// Table Resume //////////////////
////
    for ($i = 0; $i < 10; $i++) {

        $mtable[$i]['i_data'] = $Dados['indice_data'][$i];
        $mtable[$i]['Open'] = $Dados['Open_Interest_Old'][$i];
        $mtable[$i]['OpenPc'] = (($Dados['Open_Interest_Old'][$i] / $Dados['Open_Interest_Old'][$i + 1]) - 1) * 100;

        ///NC////////////////////////////////////////////////////////////
        $mtable[$i]['LongNC'] = $Dados['NonComm_Positions_Long_All'][$i];
        $mtable[$i]['ShortNC'] = $Dados['NonComm_Positions_Short_All'][$i];
        $mtable[$i]['SpreadNC'] = $Dados['NonComm_Postions_Spread_All'][$i];
        $mtbNetNC = $Dados['NonComm_Positions_Long_All'][$i] - $Dados['NonComm_Positions_Short_All'][$i];
        $mtable[$i]['NetNC'] = $mtbNetNC;

        $mtable[$i]['LongNCPc'] = (($Dados['NonComm_Positions_Long_All'][$i] / $Dados['NonComm_Positions_Long_All'][$i + 1]) - 1) * 100;
        $mtable[$i]['ShortNCPc'] = (($Dados['NonComm_Positions_Short_All'][$i] / $Dados['NonComm_Positions_Short_All'][$i + 1]) - 1) * 100;
        $mtable[$i]['SpreadNCPc'] = (($Dados['NonComm_Postions_Spread_All'][$i] / $Dados['NonComm_Postions_Spread_All'][$i + 1]) - 1) * 100;
        $mtbNetNCPc = $Dados['NonComm_Positions_Long_All'][$i + 1] - $Dados['NonComm_Positions_Short_All'][$i + 1];
        $mtable[$i]['NetNCPc'] = (($mtbNetNC / $mtbNetNCPc) - 1) * 100;

        ///CC//////////////////////////////////////////////////////////
        $mtable[$i]['LongCC'] = $Dados['Comm_Positions_Long_All'][$i];
        $mtable[$i]['ShortCC'] = $Dados['Comm_Positions_Short_All'][$i];
        $mtbNetCC = $Dados['Comm_Positions_Long_All'][$i] - $Dados['Comm_Positions_Short_All'][$i];
        $mtable[$i]['NetCC'] = $mtbNetCC;

        $mtable[$i]['LongCCPc'] = (($Dados['Comm_Positions_Long_All'][$i] / $Dados['Comm_Positions_Long_All'][$i + 1]) - 1) * 100;
        $mtable[$i]['ShortCCPc'] = (($Dados['Comm_Positions_Short_All'][$i] / $Dados['Comm_Positions_Short_All'][$i + 1]) - 1) * 100;
        $mtbNetCCPc = $Dados['Comm_Positions_Long_All'][$i + 1] - $Dados['Comm_Positions_Short_All'][$i + 1];
        $mtable[$i]['NetCCPc'] = (($mtbNetCC / $mtbNetCCPc) - 1) * 100;

        ///NO Report///////////////////////////////////////////////////
        $mtable[$i]['LongNR'] = $Dados['NonRept_Positions_Long_All'][$i];
        $mtable[$i]['ShortNR'] = $Dados['NonRept_Positions_Short_All'][$i];
        $mtbNetNR = $Dados['NonRept_Positions_Long_All'][$i] - $Dados['NonRept_Positions_Short_All'][$i];
        $mtable[$i]['NetNR'] = $mtbNetNR;

        $mtable[$i]['LongNRPc'] = (($Dados['NonRept_Positions_Long_All'][$i] / $Dados['NonRept_Positions_Long_All'][$i + 1]) - 1) * 100;
        $mtable[$i]['ShortNRPc'] = (($Dados['NonRept_Positions_Short_All'][$i] / $Dados['NonRept_Positions_Short_All'][$i + 1]) - 1) * 100;
        $mtbNetNRPc = $Dados['NonRept_Positions_Long_All'][$i + 1] - $Dados['NonRept_Positions_Short_All'][$i + 1];
        $mtable[$i]['NetNRPc'] = (($mtbNetNR / $mtbNetNRPc) - 1) * 100;

        ///Flip///////////////////////////////////////////////////
        $mtable[$i]['LongFL'] = $Dados['Pct_of_OI_NonComm_Long_All'][$i];
        $mtable[$i]['ShortFL'] = $Dados['Pct_of_OI_NonComm_Short_All'][$i];
        $mtbNetFL = $Dados['Pct_of_OI_NonComm_Long_All'][$i] - $Dados['Pct_of_OI_NonComm_Short_All'][$i];
        $mtable[$i]['NetFL'] = $mtbNetFL;

        $mtable[$i]['LongFLPc'] = (($Dados['Pct_of_OI_NonComm_Long_All'][$i] / $Dados['Pct_of_OI_NonComm_Long_All'][$i + 1]) - 1) * 100;
        $mtable[$i]['ShortFLPc'] = (($Dados['Pct_of_OI_NonComm_Short_All'][$i] / $Dados['Pct_of_OI_NonComm_Short_All'][$i + 1]) - 1) * 100;
        $mtbNetFLPc = $Dados['Pct_of_OI_NonComm_Long_All'][$i + 1] - $Dados['Pct_of_OI_NonComm_Short_All'][$i + 1];
        $mtable[$i]['NetFLPc'] = (($mtbNetFL / $mtbNetFLPc) - 1) * 100;

        ///Razão///////////////////////////////////////////////////
        $LongRA = $Dados['NonComm_Positions_Long_All'][$i] / $Dados['NonComm_Positions_Short_All'][$i];
        $ShortRA = $Dados['NonComm_Positions_Short_All'][$i] / $Dados['NonComm_Positions_Long_All'][$i];
        $mtable[$i]['LongRA'] = $LongRA;
        $mtable[$i]['ShortRA'] = $ShortRA;

        $LongRAPc = $Dados['NonComm_Positions_Long_All'][$i + 1] / $Dados['NonComm_Positions_Short_All'][$i + 1];
        $ShortRAPc = $Dados['NonComm_Positions_Short_All'][$i + 1] / $Dados['NonComm_Positions_Long_All'][$i + 1];
        $mtable[$i]['LongRAPc'] = (($LongRA / $LongRAPc) - 1) * 100;
        $mtable[$i]['ShortRAPc'] = (($ShortRA / $ShortRAPc) - 1) * 100;
    }
////End Table Resume
    ?>

    <!-- titulos aberto -->
    <div class="row">
        <div class="col-md-7">
            <div class="table-scrollable">
                <table class="table table-bordered table-hover">
                    <thead>
                        <tr>
                            <th class="active" colspan="5"> Contratos em Aberto </th>
                            <th class="active"> Total </th>
                            <th class="active"> <?= $CATOTAL; ?> </th>
                        </tr>
                    </thead>
                    <tbody>
                        <tr>
                            <td class="success"> NC Long </td>
                            <td class="success"> NC Short </td>
                            <td class="success"> Spread </td>
                            <td class="success"> CC Long </td>
                            <td class="success"> CC Short </td>
                            <td class="success"> VV Long </td>
                            <td class="success"> VV Short </td>
                        </tr>
                        <tr>
                            <td class="active"> <?= $CANCLong; ?> </td>
                            <td class="active"> <?= $CANCShort; ?> </td>
                            <td class="active"> <?= $CANCSpread; ?> </td>
                            <td class="active"> <?= $CACCLong; ?> </td>
                            <td class="active"> <?= $CACCShort; ?> </td>
                            <td class="active"> <?= $CAVVLong; ?> </td>
                            <td class="active"> <?= $CAVVShort; ?> </td>
                        </tr>
                        <tr>
                            <td class="active"> <?= number_format(($CANCLong * 100) / $CATOTAL, 2, ',', '.'); ?>% </td>
                            <td class="active"> <?= number_format(($CANCShort * 100) / $CATOTAL, 2, ',', '.'); ?>% </td>
                            <td class="active"> <?= number_format(($CANCSpread * 100) / $CATOTAL, 2, ',', '.'); ?>% </td>
                            <td class="active"> <?= number_format(($CACCLong * 100) / $CATOTAL, 2, ',', '.'); ?>% </td>
                            <td class="active"> <?= number_format(($CACCShort * 100) / $CATOTAL, 2, ',', '.'); ?>% </td>
                            <td class="active"> <?= number_format(($CAVVLong * 100) / $CATOTAL, 2, ',', '.'); ?>% </td>
                            <td class="active"> <?= number_format(($CAVVShort * 100) / $CATOTAL, 2, ',', '.'); ?>% </td>
                        </tr>
                    </tbody>
                </table>
            </div>
        </div>
        <div class="col-md-5">
            <div class="table-scrollable">
                <table class="table table-bordered table-hover">
                    <thead>
                        <tr>
                            <th class="success" style="text-align:center"> Preço </th>
                            <th class="success" style="text-align:center"> Volume </th>
                            <th class="success" style="text-align:center"> OI </th>
                            <th class="success" style="text-align:center"> Trader </th>
                            <th class="success"> Tendência  </th>
                        </tr>
                    </thead>
                    <tbody>
                        <tr>
                            <td class="active" style="text-align:center"> <i class="fa fa-arrow-up font-green-jungle"></i> </td>
                            <td class="active" style="text-align:center"> <i class="fa fa-arrow-up font-green-jungle"></i> </td>
                            <td class="active" style="text-align:center"> <i class="fa fa-arrow-up font-green-jungle"></i> </td>
                            <td class="active" style="text-align:center"> <i class="fa fa-arrow-up font-green-jungle"></i> </td>
                            <td class="active font-green-jungle"> <b>FORTE</b> </td>
                        </tr>
                        <tr>
                            <td class="active" style="text-align:center"> <i class="fa fa-arrow-down font-red-thunderbird"></i> </td>
                            <td class="active" style="text-align:center"> <i class="fa fa-arrow-up font-green-jungle"></i> </td>
                            <td class="bg-yellow-crusta" style="text-align:center"> <i class="fa fa-arrow-up font-green-jungle"></i> <i class="fa fa-arrow-down font-red-thunderbird"></i> </td>
                            <td class="active" style="text-align:center"> <i class="fa fa-arrow-down font-red-thunderbird"></i> </td>
                            <td class="active font-green-jungle"> <b>FORTE</b> </td>
                        </tr>
                        <tr>
                            <td class="active" style="text-align:center"> <i class="fa fa-arrow-up font-green-jungle"></i> </td>
                            <td class="active" style="text-align:center"> <i class="fa fa-arrow-down font-red-thunderbird"></i> </td>
                            <td class="active" style="text-align:center"> <i class="fa fa-arrow-down font-red-thunderbird"></i> </td>
                            <td class="active" style="text-align:center"> <i class="fa fa-arrow-up font-green-jungle"></i> </td>
                            <td class="active font-red-thunderbird"> <b>FRACA</b> </td>
                        </tr>
                        <tr>
                            <td class="active" style="text-align:center"> <i class="fa fa-arrow-down font-red-thunderbird"></i> </td>
                            <td class="active" style="text-align:center"> <i class="fa fa-arrow-down font-red-thunderbird"></i> </td>
                            <td class="active" style="text-align:center"> <i class="fa fa-arrow-down font-red-thunderbird"></i> </td>
                            <td class="active" style="text-align:center"> <i class="fa fa-arrow-down font-red-thunderbird"></i> </td>
                            <td class="active font-red-thunderbird"> <b>FRACA</b> </td>
                        </tr>
                    </tbody>
                </table>
            </div>
        </div>
    </div>
    <!-- END titulos aberto -->
    <style>
        .table-bordered>tbody>tr>td.bordernone{
            border: 0px;
            border-right: 1px solid #979ca0;
        }
        
        .table-bordered>thead>tr>th{
            border: 0px;
            border-right: 1px solid #979ca0;
        }
        
        .table-scrollable{
            border: 0px;
        }
        
        .table-scrollable>.table{
            background-color: initial;
        }
    </style>
    <div class="portlet ">
        <div class="portlet-title tabbable-line">

            <ul class="nav nav-tabs">
                <li class="active">
                    <a href="#tab_1_1" data-toggle="tab">Resumo</a>
                </li>
                <li>
                    <a href="#tab_1_2" data-toggle="tab">Detalhes</a>
                </li>
            </ul>
        </div>
        <div class="portlet-body">
            <div class="tab-content">
                <!-- PERSONAL INFO TAB -->
                <div class="tab-pane active" id="tab_1_1">
                    <!-- tabela indice -->
                    <div class="row">
                        <?php
                        $ind = 0;
                        foreach ($mtable as $tables):
                            extract($tables);
                            if ($ind < 8):
                                ?>
                                <div class="col-md-6">
                                    <div class="table-scrollable">
                                        <table class="table table-bordered table-hover text-center">
                                            <thead>
                                                <tr>
                                                    <!-- função para ascrecentar meses a data -->
                                                    <th class="bordernone" colspan="9"></th>
                                                    <th class="bg-dark bg-font-dark" colspan="2"> <?= number_format($OpenPc, 2); ?>% </th>
                                                </tr>
                                                <tr>
                                                    <th class="bordernone">  </th>
                                                    <th class="bg-dark bg-font-dark" colspan="6"> Resumo Cot Somente Futuros <?= $i_data; ?> </th>
                                                    <th class="bg-dark bg-font-dark"> Total OI: </th>
                                                    <th class="bg-dark bg-font-dark">   
                                                        <?php
                                                        if ($OpenPc > 0):
                                                            echo '<i class="fa fa-caret-up font-green-jungle"></i>';
                                                        else:
                                                            echo '<i class="fa fa-caret-down font-red-thunderbird"></i>';
                                                        endif;
                                                        ?>
                                                    </th>
                                                    <th class="bg-dark bg-font-dark"> <?= $Open; ?> </th>
                                                    <th class="bg-dark bg-font-dark">  </th>
                                                </tr>
                                                <tr>
                                                    <th class="bordernone">  </th>
                                                    <th class="bg-yellow-crusta text-center" colspan="2"> NC </th>
                                                    <th class="bg-blue text-center" colspan="2"> CC </th>
                                                    <th class="success text-center" colspan="2"> NO Report </th>
                                                    <th class="bg-green-meadow text-center" colspan="2"> Flip </th>
                                                    <th class="warning text-center" colspan="2"> Razão </th>
                                                </tr>
                                            </thead>
                                            <tbody>
                                                <tr>
                                                    <td class="bordernone"> LONG </td>
                                                    <td class="active"> <?= $LongNC; ?><br><?= number_format($LongNCPc, 2); ?>% </td>
                                                    <td class="active">
                                                        <?php
                                                        if ($LongNCPc > 0):
                                                            echo '<i class="fa fa-caret-up font-green-jungle"></i>';
                                                        else:
                                                            echo '<i class="fa fa-caret-down font-red-thunderbird"></i>';
                                                        endif;
                                                        ?> 
                                                    </td>
                                                    <td class="active"> <?= $LongCC; ?><br><?= number_format($LongCCPc, 2); ?>% </td>
                                                    <td class="active">
                                                        <?php
                                                        if ($LongCCPc > 0):
                                                            echo '<i class="fa fa-caret-up font-green-jungle"></i>';
                                                        else:
                                                            echo '<i class="fa fa-caret-down font-red-thunderbird"></i>';
                                                        endif;
                                                        ?> 
                                                    </td>
                                                    <td class="active"> <?= $LongNR; ?><br><?= number_format($LongNRPc, 2); ?>% </td>
                                                    <td class="active">
                                                        <?php
                                                        if ($LongNRPc > 0):
                                                            echo '<i class="fa fa-caret-up font-green-jungle"></i>';
                                                        else:
                                                            echo '<i class="fa fa-caret-down font-red-thunderbird"></i>';
                                                        endif;
                                                        ?>  
                                                    </td>
                                                    <td class="active"> <?= number_format($LongFL, 1); ?><br><?= number_format($LongFLPc, 2); ?>% </td>
                                                    <td class="active"> 
                                                        <?php
                                                        if ($LongFLPc > 0):
                                                            echo '<i class="fa fa-caret-up font-green-jungle"></i>';
                                                        else:
                                                            echo '<i class="fa fa-caret-down font-red-thunderbird"></i>';
                                                        endif;
                                                        ?> 
                                                    </td>
                                                    <td class="active"> Long/Short<br><?= number_format($LongRA, 1); ?>:1 </td>
                                                    <td class="active"> 
                                                        <?php
                                                        if ($LongRAPc > 0):
                                                            echo '<i class="fa fa-caret-up font-green-jungle"></i>';
                                                        else:
                                                            echo '<i class="fa fa-caret-down font-red-thunderbird"></i>';
                                                        endif;
                                                        ?> 
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td class="bordernone"> SHORT </td>
                                                    <td class="active"> <?= $ShortNC; ?><br><?= number_format($ShortNCPc, 2); ?>% </td>
                                                    <td class="active">
                                                        <?php
                                                        if ($ShortNCPc > 0):
                                                            echo '<i class="fa fa-caret-up font-green-jungle"></i>';
                                                        else:
                                                            echo '<i class="fa fa-caret-down font-red-thunderbird"></i>';
                                                        endif;
                                                        ?> 
                                                    </td>
                                                    <td class="active"> <?= $ShortCC; ?><br><?= number_format($ShortCCPc, 2); ?>% </td>
                                                    <td class="active"> 
                                                        <?php
                                                        if ($ShortCCPc > 0):
                                                            echo '<i class="fa fa-caret-up font-green-jungle"></i>';
                                                        else:
                                                            echo '<i class="fa fa-caret-down font-red-thunderbird"></i>';
                                                        endif;
                                                        ?> 
                                                    </td>
                                                    <td class="active"> <?= $ShortNR; ?><br><?= number_format($ShortNRPc, 2); ?>% </td>
                                                    <td class="active">  
                                                        <?php
                                                        if ($ShortNRPc > 0):
                                                            echo '<i class="fa fa-caret-up font-green-jungle"></i>';
                                                        else:
                                                            echo '<i class="fa fa-caret-down font-red-thunderbird"></i>';
                                                        endif;
                                                        ?> 
                                                    </td>
                                                    <td class="active"> <?= number_format($ShortFL, 1); ?><br><?= number_format($ShortFLPc, 2); ?>% </td>
                                                    <td class="active">  
                                                        <?php
                                                        if ($ShortFLPc > 0):
                                                            echo '<i class="fa fa-caret-up font-green-jungle"></i>';
                                                        else:
                                                            echo '<i class="fa fa-caret-down font-red-thunderbird"></i>';
                                                        endif;
                                                        ?> 
                                                    </td>
                                                    <td class="active"> Short/Long<br><?= number_format($ShortRA, 1); ?>:1</td>
                                                    <td class="active">  
                                                        <?php
                                                        if ($ShortRAPc > 0):
                                                            echo '<i class="fa fa-caret-up font-green-jungle"></i>';
                                                        else:
                                                            echo '<i class="fa fa-caret-down font-red-thunderbird"></i>';
                                                        endif;
                                                        ?> 
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td class="bordernone"> SPREAD </td>
                                                    <td class="active"> <?= $SpreadNC; ?><br><?= number_format($SpreadNCPc, 2); ?>% </td>
                                                    <td class="active"> 
                                                        <?php
                                                        if ($SpreadNCPc > 0):
                                                            echo '<i class="fa fa-caret-up font-green-jungle"></i>';
                                                        else:
                                                            echo '<i class="fa fa-caret-down font-red-thunderbird"></i>';
                                                        endif;
                                                        ?>
                                                    </td>
                                                    <td class="active"> </td>
                                                    <td class="active"> </td>
                                                    <td class="active"> </td>
                                                    <td class="active"> </td>
                                                    <td class="active"> </td>
                                                    <td class="active"> </td>
                                                    <td class="active"> </td>
                                                    <td class="active"> </td>
                                                </tr>
                                                <tr>
                                                    <td class="bordernone"> POSIÇÃO<BR>LIQUIDA </td>
                                                    <td class="active"> <?= $NetNC; ?><br><?= number_format($NetNCPc, 2); ?>% </td>
                                                    <td class="active">  
                                                        <?php
                                                        if ($NetNCPc > 0):
                                                            echo '<i class="fa fa-caret-up font-green-jungle"></i>';
                                                        else:
                                                            echo '<i class="fa fa-caret-down font-red-thunderbird"></i>';
                                                        endif;
                                                        ?>
                                                    </td>
                                                    <td class="active"> <?= $NetCC; ?><br><?= number_format($NetCCPc, 2); ?>% </td>
                                                    <td class="active">  
                                                        <?php
                                                        if ($NetCCPc > 0):
                                                            echo '<i class="fa fa-caret-up font-green-jungle"></i>';
                                                        else:
                                                            echo '<i class="fa fa-caret-down font-red-thunderbird"></i>';
                                                        endif;
                                                        ?>
                                                    </td>
                                                    <td class="active"> <?= $NetNR; ?><br><?= number_format($NetNRPc, 2); ?>% </td>
                                                    <td class="active">   
                                                        <?php
                                                        if ($NetNRPc > 0):
                                                            echo '<i class="fa fa-caret-up font-green-jungle"></i>';
                                                        else:
                                                            echo '<i class="fa fa-caret-down font-red-thunderbird"></i>';
                                                        endif;
                                                        ?>
                                                    </td>
                                                    <td class="active"> <?= number_format($NetFL, 1); ?><br><?= number_format($NetFLPc, 2); ?>% </td>
                                                    <td class="active">   
                                                        <?php
                                                        if ($NetFLPc > 0):
                                                            echo '<i class="fa fa-caret-up font-green-jungle"></i>';
                                                        else:
                                                            echo '<i class="fa fa-caret-down font-red-thunderbird"></i>';
                                                        endif;
                                                        ?>
                                                    </td>
                                                    <td class="active">  </td>
                                                    <td class="active">  </td>
                                                </tr>
                                            </tbody>
                                        </table>
                                    </div>
                                </div>
                                <?php
                                $ind++;
                            endif;
                        endforeach;
                        ?>
                    </div>
                    <!-- END tabela indice -->
                </div>
                <!-- END PERSONAL INFO TAB -->
                <!-- CHANGE AVATAR TAB -->
                <div class="tab-pane" id="tab_1_2">
                    <!-- tabela indice -->
                    <div class="row">
                        <div class="col-md-12">
                            <div class="table-scrollable">
                                <table class="table table-bordered table-hover">
                                    <thead>
                                        <tr>
                                            <!-- função para ascrecentar meses a data -->
                                            <?php $dataN = date('Y-m-d', strtotime("+4 month", strtotime("2018/09/15"))); ?>
                                            <th class="warning"></th>
                                            <th class="warning"> <?= $MTableLong; ?> </th>
                                            <th class="warning"> <?= $MTableShort; ?> </th>
                                            <th class="warning"> <?= $MTableTotal; ?> </th>
                                            <th class="warning" colspan="2"> Não Comercial </th>
                                            <th class="warning"> <?= $MTableNet; ?> </th>
                                            <th class="warning" rowspan="2"> Long </th>
                                            <th class="warning" rowspan="2"> Short </th>
                                            <th rowspan="2">  </th>
                                            <th class="warning"> <?= $MTableLongUsd; ?> </th>
                                            <th class="warning"> <?= $MTableShortUsd; ?> </th>
                                            <th class="warning"> <?= $MTableTotalUsd; ?> </th>
                                            <th class="warning" colspan="2"> Comercial </th>
                                            <th class="warning"> <?= $MTableNetUsd; ?> </th>
                                            <th class="warning"> <?= $MTableDif; ?> </th>
                                        </tr>
                                        <tr>
                                            <th class="success"> Data </th>
                                            <th class="success"> Long </th>
                                            <th class="success"> Short </th>
                                            <th class="success"> Total </th>
                                            <th class="success"> % Long </th>
                                            <th class="success"> % Short </th>
                                            <th class="success"> Net Pos. </th>

                                            <th class="success"> Long </th>
                                            <th class="success"> Short </th>
                                            <th class="success"> Total </th>
                                            <th class="success"> % Long </th>
                                            <th class="success"> % Short </th>
                                            <th class="success"> Net Pos. </th>
                                            <th class="success"> Sinal </th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                        <?php
                                        foreach ($Table as $DATA):
                                            extract($DATA);

                                            //////////////////////////////////////////////////////////
                                            //formatação condicional do NonComm
                                            //LONG
                                            $class_NonLong = '';
                                            if ($PercLongNC >= 50 && $PercLongNC < 60):
                                                $class_NonLong = 'bg-yellow-saffron';
                                            elseif ($PercLongNC >= 60 && $PercLongNC < 70):
                                                $class_NonLong = 'bg-yellow-crusta';
                                            elseif ($PercLongNC >= 70 && $PercLongNC < 80):
                                                $class_NonLong = 'bg-green-turquoise';
                                            elseif ($PercLongNC >= 80):
                                                $class_NonLong = 'bg-green-jungle';
                                            endif;

                                            //Short
                                            $class_NonShort = '';
                                            if ($PercShortNC >= 50 && $PercShortNC < 60):
                                                $class_NonShort = 'bg-yellow-saffron';
                                            elseif ($PercShortNC >= 60 && $PercShortNC < 70):
                                                $class_NonShort = 'bg-yellow-crusta';
                                            elseif ($PercShortNC >= 70 && $PercShortNC < 80):
                                                $class_NonShort = 'bg-green-turquoise';
                                            elseif ($PercShortNC >= 80):
                                                $class_NonShort = 'bg-green-jungle';
                                            endif;

                                            //NET
                                            $class_NonNet = '';
                                            if ($NetNC >= $NetMedia):
                                                $class_NonNet = 'bg-green-jungle';
                                            else:
                                                $class_NonNet = 'bg-red';
                                            endif;
                                            // end da formatação condicional NonComm
                                            ///////////////////////////////////////////////////////////////////////////
                                            ////////////////////////////////////////////////////////////
                                            //formatação condicional do NonComm USD
                                            //LONG
                                            $class_Long = '';
                                            if ($UsdPercLongNC >= 50 && $UsdPercLongNC < 60):
                                                $class_Long = 'bg-yellow-saffron';
                                            elseif ($UsdPercLongNC >= 60 && $UsdPercLongNC < 70):
                                                $class_Long = 'bg-yellow-crusta';
                                            elseif ($UsdPercLongNC >= 70 && $UsdPercLongNC < 80):
                                                $class_Long = 'bg-green-turquoise';
                                            elseif ($UsdPercLongNC >= 80):
                                                $class_Long = 'bg-green-jungle';
                                            endif;

                                            //Short
                                            $class_Short = '';
                                            if ($UsdPercShortNC >= 50 && $UsdPercShortNC < 60):
                                                $class_Short = 'bg-yellow-saffron';
                                            elseif ($UsdPercShortNC >= 60 && $UsdPercShortNC < 70):
                                                $class_Short = 'bg-yellow-crusta';
                                            elseif ($UsdPercShortNC >= 70 && $UsdPercShortNC < 80):
                                                $class_Short = 'bg-green-turquoise';
                                            elseif ($UsdPercShortNC >= 80):
                                                $class_Short = 'bg-green-jungle';
                                            endif;

                                            //NET
                                            $class_Net = '';
                                            if ($UsdNetNC >= $NetUMedia):
                                                $class_cNet = 'bg-green-jungle';
                                            else:
                                                $class_cNet = 'bg-red';
                                            endif;

                                            //Dif
                                            $class_Dif = '';
                                            if ($Diferenca >= $DifMedia):
                                                $class_cDif = 'bg-green-jungle';
                                            else:
                                                $class_cDif = 'bg-red';
                                            endif;
                                            // end da formatação condicional NonComm USD
                                            ///////////////////////////////////////////////////////////////////////////
                                            ?>
                                            <tr>
                                                <td> <?= $Data; ?> </td>
                                                <td> <?= $LongNC; ?> </td>
                                                <td> <?= $ShortNC; ?> </td>
                                                <td> <?= $TotalNC; ?> </td>
                                                <td class="<?= $class_NonLong; ?>"> <?= $PercLongNC ?>% </td>
                                                <td class="<?= $class_NonShort; ?>"> <?= $PercShortNC ?>% </td> </td>
                                                <td class="<?= $class_NonNet; ?>"> <?= $NetNC; ?> </td>
                                                <td> <?= $DivLongNC; ?> </td>
                                                <td> <?= $DivShortNC; ?> </td>
                                                <td>  </td>
                                                <td> <?= $UsdLongNC; ?> </td>
                                                <td> <?= $UsdShortNC; ?> </td>
                                                <td> <?= $UsdTotalNC; ?> </td>
                                                <td class="<?= $class_Long; ?>"> <?= $UsdPercLongNC ?>% </td>
                                                <td class="<?= $class_Short; ?>"> <?= $UsdPercShortNC ?>% </td> </td>
                                                <td class="<?= $class_cNet; ?>"> <?= $UsdNetNC; ?> </td>
                                                <td class="<?= $class_cDif; ?>"> <?= $Diferenca; ?> </td>
                                            </tr>
                                            <?php
                                        endforeach;
                                        ?>
                                    </tbody>
                                </table>
                            </div>
                        </div>
                    </div>
                    <!-- END tabela indice -->
                </div>
                <!-- END CHANGE AVATAR TAB -->
            </div>
        </div>
    </div>


    <hr>
    <div class="row">
        <div class="col-md-12">
            <div class="embed-container">
                <iframe id="widgetMataf" style="border: none; overflow:hidden; background-color: transparent;" src="https://www.mataf.net/pt/widget/currencyindex"></iframe> 
            </div>
        </div>
    </div>
    <hr>
    <div class="row">
        <div class="col-md-12">
            <div id="dif"></div>
        </div>
    </div>
    <hr>
    <div class="row">
        <div class="col-md-12">
            <div id="normalizado"></div>
        </div>
    </div>
    <hr>
    <div class="row">
        <div class="col-md-12">
            <div id="index"></div>
        </div>
    </div>
    <hr>
    <div class="row">
        <div class="col-md-12">
            <div id="flip"></div>
        </div>
    </div>
    <hr>
    <div class="row">
        <div class="col-md-12">
            <div id="moedas"></div>
        </div>
    </div>
    <hr>
    <div class="row">
        <div class="col-md-12">
            <div id="volume"></div>
        </div>
    </div>
    <hr>
    <div class="row">
        <div class="col-md-12">
            <div id="LongShort"></div>
        </div>
    </div>

    <script src="__jsc/highcharts/code/highcharts.js"></script>
    <script src="__jsc/highcharts/code/modules/data.js"></script>
    <script src="__jsc/highcharts/code/modules/series-label.js"></script>
    <script src="__jsc/highcharts/code/modules/exporting.js"></script>
    <script src="__jsc/highcharts/code/modules/export-data.js"></script>

    <script type="text/javascript">

                    Highcharts.setOptions({
                        colors: ['#3faba4', '#c49f47', '#ED561B', '#DDDF00', '#24CBE5', '#64E572', '#FF9655', '#FFF263']
                    });

                    Highcharts.chart('dif', {
                        chart: {
                            backgroundColor: '#00000'
                        },
                        title: {
                            text: 'Distância da média em função contrato',
                            style: {
                                color: '#FFF',
                                fontWeight: 'bold'
                            }
                        },

                        credits: {
                            enabled: false
                        },

                        xAxis: {
                            categories: [<?= $difDat; ?>],
                            tickmarkPlacement: 'on',
                            labels: {
                                style: {
                                    color: '#FFF'
                                }
                            },
                            title: {
                                enabled: false
                            }
                        },
                        yAxis: {
                            gridLineWidth: 0,
                            minorGridLineWidth: 0,
                            title: {
                                enabled: false,
                                style: {
                                    color: "#FFF"
                                }
                            },
                            labels: {
                                style: {
                                    color: '#FFF'
                                }
                            }
                        },

                        legend: {
                            enabled: false
                        },

                        tooltip: {
                            shared: true,
                            crosshairs: true
                        },

                        series: [{
                                name: 'Diferença',
                                data: [<?= $DifStr; ?>]
                            }, {
                                name: 'Média',
                                data: [<?= $DifMediaStr; ?>]
                            }]
                    });

                    Highcharts.chart('normalizado', {
                        chart: {
                            backgroundColor: '#000000'
                        },
                        title: {
                            text: 'Net Position Normalizado',
                            style: {
                                color: '#FFF',
                                fontWeight: 'bold'
                            }
                        },

                        credits: {
                            enabled: false
                        },

                        xAxis: {
                            categories: [<?= $difDat; ?>],
                            tickmarkPlacement: 'on',
                            labels: {
                                style: {
                                    color: '#FFF'
                                }
                            },
                            title: {
                                enabled: false
                            }
                        },
                        yAxis: {
                            gridLineWidth: 0,
                            minorGridLineWidth: 0,
                            labels: {
                                format: '{value}%',
                                style: {
                                    color: '#FFF'
                                }
                            },
                            title: {
                                text: ''
                            }
                        },

                        legend: {
                            enabled: false
                        },

                        tooltip: {
                            shared: true,
                            crosshairs: true
                        },

                        series: [{
                                name: 'Net_Posi_NC',
                                data: [<?= $NetNonCommStr; ?>],
                                tooltip: {
                                    valueSuffix: '%'
                                }
                            }, {
                                name: 'Net_posi_CC',
                                data: [<?= $NetCommStr; ?>],
                                tooltip: {
                                    valueSuffix: '%'
                                }
                            }]
                    });

                    Highcharts.chart('index', {
                        chart: {
                            backgroundColor: '#000000',
                            type: 'column'
                        },
                        title: {
                            text: 'Moviment Index',
                            style: {
                                color: '#FFF',
                                fontWeight: 'bold'
                            }
                        },
                        xAxis: {
                            categories: [<?= $difDat; ?>],
                            labels: {
                                style: {
                                    color: '#FFF'
                                }
                            },
                        },
                        yAxis: {
                            gridLineWidth: 0,
                            minorGridLineWidth: 0,
                            labels: {
                                format: '{value}%',
                                style: {
                                    color: '#FFF'
                                }
                            },
                            title: {
                                text: ''
                            }
                        },
                        legend: {
                            enabled: false
                        },
                        credits: {
                            enabled: false
                        },
                        series: [{
                                name: 'Moviment',
                                data: [<?= $IndexStr; ?>],
                                tooltip: {
                                    valueSuffix: '%'
                                }
                            }]
                    });

                    Highcharts.chart('flip', {
                        chart: {
                            backgroundColor: '#000000'
                        },
                        title: {
                            text: '% Contratos Abertos NC',
                            style: {
                                color: '#FFF',
                                fontWeight: 'bold'
                            }
                        },

                        credits: {
                            enabled: false
                        },

                        xAxis: {
                            categories: [<?= $difDat; ?>],
                            tickmarkPlacement: 'on',
                            labels: {
                                style: {
                                    color: '#FFF'
                                }
                            },
                            title: {
                                enabled: false
                            }
                        },
                        yAxis: {
                            gridLineWidth: 0,
                            minorGridLineWidth: 0,
                            labels: {
                                format: '{value}%',
                                style: {
                                    color: '#FFF'
                                }
                            },
                            title: {
                                text: '',
                                style: {
                                    color: '#FFF'
                                }
                            }
                        },

                        legend: {
                            enabled: false
                        },

                        tooltip: {
                            shared: true,
                            crosshairs: true
                        },

                        series: [{
                                name: 'Flip NC',
                                data: [<?= $FlipStr; ?>],
                                tooltip: {
                                    valueSuffix: '%'
                                }
                            }]
                    });

                    Highcharts.chart('moedas', {
                        chart: {
                            backgroundColor: '#000000'
                        },
                        title: {
                            text: 'Relação Base Cotação Normalizado',
                            style: {
                                color: '#FFF',
                                fontWeight: 'bold'
                            }
                        },

                        credits: {
                            enabled: false
                        },

                        xAxis: {
                            categories: [<?= $difDat; ?>],
                            tickmarkPlacement: 'on',
                            labels: {
                                style: {
                                    color: '#FFF'
                                }
                            },
                            title: {
                                enabled: false
                            }
                        },
                        yAxis: [{// Primary yAxis
                                gridLineWidth: 0,
                                minorGridLineWidth: 0,
                                labels: {
                                    format: '{value}%',
                                    style: {
                                        color: '#fff'
                                    }
                                },
                                title: {
                                    text: 'Normalizado',
                                    style: {
                                        color: '#fff'
                                    }
                                }
                            }],

                        legend: {
                            enabled: false
                        },

                        tooltip: {
                            shared: true,
                            crosshairs: true
                        },

                        series: [{
                                name: 'Normarlizado',
                                type: 'spline',
                                data: [<?= $SinalStr; ?>],
                                tooltip: {
                                    valueSuffix: '%'
                                }
                            }]
                    });

                    Highcharts.setOptions({
                        colors: ['#3faba4', '#3faba4']
                    });

                    Highcharts.chart('volume', {
                        chart: {
                            backgroundColor: '#000000'
                        },
                        title: {
                            text: 'Contratos em abertos em função volume',
                            style: {
                                color: '#FFF',
                                fontWeight: 'bold'
                            }
                        },

                        credits: {
                            enabled: false
                        },

                        xAxis: {
                            categories: [<?= $difDat; ?>],
                            tickmarkPlacement: 'on',
                            labels: {
                                style: {
                                    color: '#FFF'
                                }
                            },
                            title: {
                                enabled: false
                            }
                        },
                        yAxis: [{// Primary yAxis
                                gridLineWidth: 0,
                                minorGridLineWidth: 0,
                                labels: {
                                    format: '{value}',
                                    style: {
                                        color: '#FFF'
                                    }
                                },
                                title: {
                                    text: 'Abertos',
                                    style: {
                                        color: '#FFF'
                                    }
                                }
                            }],

                        legend: {
                            enabled: false
                        },

                        tooltip: {
                            shared: true,
                            crosshairs: true
                        },

                        series: [{
                                name: 'Volumes',
                                type: 'column',
                                data: [<?= $VolumeStr; ?>],
                                tooltip: {
                                    valueSuffix: ' '
                                }
                            },
                            {
                                name: 'Abertos',
                                type: 'spline',
                                data: [<?= $AbertoStr; ?>],
                                tooltip: {
                                    valueSuffix: ' '
                                }
                            }]
                    });

                    Highcharts.setOptions({
                        colors: ['#3faba4', '#c49f47', '#ED561B', '#DDDF00', '#24CBE5', '#64E572', '#FF9655', '#FFF263']
                    });

                    Highcharts.chart('LongShort', {
                        chart: {
                            backgroundColor: '#00000'
                        },
                        title: {
                            text: 'Position Long Short',
                            style: {
                                color: '#FFF',
                                fontWeight: 'bold'
                            }
                        },

                        credits: {
                            enabled: false
                        },

                        xAxis: {
                            categories: [<?= $difDat; ?>],
                            tickmarkPlacement: 'on',
                            labels: {
                                style: {
                                    color: '#FFF'
                                }
                            },
                            title: {
                                enabled: false
                            }
                        },
                        yAxis: {
                            gridLineWidth: 0,
                            minorGridLineWidth: 0,
                            title: {
                                enabled: false,
                                style: {
                                    color: "#FFF"
                                }
                            },
                            labels: {
                                style: {
                                    color: '#FFF'
                                }
                            }
                        },

                        legend: {
                            enabled: false
                        },

                        tooltip: {
                            shared: true,
                            crosshairs: true
                        },

                        series: [{
                                name: 'Long',
                                data: [<?= $LongStr; ?>]
                            }, {
                                name: 'Short',
                                data: [<?= $ShortStr; ?>]
                            }]
                    });

    </script>
<?php
endif;
?>
<script>
    function filtro() {
        var moeda = $("#campo_moeda").val();
        var periodo = $("#campo_periodo").val();



        if (moeda == '') {
            console.log('moeda vazia');
        } else if (periodo == '') {
            console.log('periodo vazia');
        } else {
            window.location.href = "painel.php?exe=indice/index&moedid=" + moeda + "&perid=" + periodo;
        }
    }
</script>