@{
    ViewData["MainNum"] = "4";
    ViewData["SubNum"] = "3";
    ViewData["Title"] = "電站發電收入";
}
@using SolarPower.Models.Role
@model RoleLayerEnum

<div class="container-fluid">
    <div class="row flex-nowrap wrapper">
        <div class="col-md-2 col-1 pl-0 pr-0 collapse width border-right sidebar vh-100 overflow-auto">

            <div class="list-group border-0 card text-center text-md-left" id="sidebar">

                <div class="border bg-light rounded-top">
                    <div class="form-group p-2 m-0 rounded-top">
                        <input type="text" class="form-control form-control-lg shadow-inset-2 m-0" id="js_list_accordion_filter" placeholder="">
                    </div>
                    <div id="js_list_accordion" class="accordion accordion-hover accordion-clean js-list-filter">
                        <div class="card border-top-left-radius-0 border-top-right-radius-0">
                            <div class="card-header">
                                <a href="javascript:void(0);" class="card-title collapsed" data-toggle="collapse" data-target="#js_list_accordion-a" aria-expanded="true" data-filter-tags="settings">
                                    <i class="fal fa-globe width-2 fs-xl"></i>
                                    新北市
                                    <span class="ml-auto">
                                        <span class="collapsed-reveal">
                                            <i class="fal fa-chevron-up fs-xl"></i>
                                        </span>
                                        <span class="collapsed-hidden">
                                            <i class="fal fa-chevron-down fs-xl"></i>
                                        </span>
                                    </span>
                                </a>
                            </div>
                            <div id="js_list_accordion-a" class="collapse" data-parent="#js_list_accordion" style="">
                                <div class="card-body">
                                    <ul class="list-group list-group-flush">
                                        <li class="list-group-item">
                                            <div class="d-flex justify-content-between">
                                                <h4 class="font-weight-bold"><i class="fal fa-charging-station"></i> 新竹交大站</h4>
                                                <div class="">
                                                    <input type="checkbox" class="" id="defaultUnchecked">
                                                </div>
                                            </div>
                                            <ul class="list-group list-group-flush">
                                                <li class="list-group-item pr-0 d-flex justify-content-between">
                                                    <a href="#"><i class="fal fa-tachometer-alt-slow"></i> 電錶 R001</a>
                                                    <div class="">
                                                        <input type="checkbox" class="" id="defaultUnchecked">
                                                    </div>
                                                </li>
                                                <li class="list-group-item pr-0 d-flex justify-content-between">
                                                    <a href="#"><i class="fal fa-sun"></i> 日照計 R002</a>
                                                    <div class="">
                                                        <input type="checkbox" class="" id="defaultUnchecked">
                                                    </div>
                                                </li>
                                                <li class="list-group-item pr-0 d-flex justify-content-between">
                                                    <a href="#"><i class="fal fa-thermometer-half"></i> 環境溫度計 R003</a>
                                                    <div class="">
                                                        <input type="checkbox" class="" id="defaultUnchecked">
                                                    </div>
                                                </li>
                                                <li class="list-group-item pr-0 d-flex justify-content-between">
                                                    <a href="#"><i class="fal fa-wind"></i> 風速計 R002</a>
                                                    <div class="">
                                                        <input type="checkbox" class="" id="defaultUnchecked">
                                                    </div>
                                                </li>
                                                <li class="list-group-item pr-0 d-flex justify-content-between">
                                                    <a href="#"><i class="fal fa-sun-dust"></i> 落塵計 R002</a>
                                                    <div class="">
                                                        <input type="checkbox" class="" id="defaultUnchecked">
                                                    </div>
                                                </li>
                                                <li class="list-group-item pr-0 d-flex justify-content-between">
                                                    <a href="#"><i class="fal fa-tint"></i> 濕度計 R002</a>
                                                    <div class="">
                                                        <input type="checkbox" class="" id="defaultUnchecked">
                                                    </div>
                                                </li>
                                                <li class="list-group-item pr-0 d-flex justify-content-between">
                                                    <a href="#"><i class="fal fa-server"></i> 逆變器 R002</a>
                                                    <div class="">
                                                        <input type="checkbox" class="" id="defaultUnchecked">
                                                    </div>
                                                </li>
                                            </ul>
                                        </li>
                                        <li class="list-group-item">
                                            <div class="d-flex justify-content-between">
                                                <h4 class="font-weight-bold"><i class="fal fa-charging-station"></i> 新竹動物園站</h4>
                                                <div class="">
                                                    <input type="checkbox" class="" id="defaultUnchecked">
                                                </div>
                                            </div>
                                        <li class="list-group-item">
                                            <div class="d-flex justify-content-between">
                                                <h4 class="font-weight-bold"><i class="fal fa-charging-station"></i> 新竹火車站</h4>
                                                <div class="">
                                                    <input type="checkbox" class="" id="defaultUnchecked">
                                                </div>
                                            </div>
                                    </ul>
                                </div>
                            </div>
                        </div>
                        <div class="card">
                            <div class="card-header">
                                <a href="javascript:void(0);" class="card-title collapsed" data-toggle="collapse" data-target="#js_list_accordion-b" aria-expanded="false" data-filter-tags="merge">
                                    <i class="fal fa-globe width-2 fs-xl"></i>
                                    台南市
                                    <span class="ml-auto">
                                        <span class="collapsed-reveal">
                                            <i class="fal fa-chevron-up fs-xl"></i>
                                        </span>
                                        <span class="collapsed-hidden">
                                            <i class="fal fa-chevron-down fs-xl"></i>
                                        </span>
                                    </span>
                                </a>
                            </div>
                            <div id="js_list_accordion-b" class="collapse" data-parent="#js_list_accordion">
                                <div class="card-body">
                                    放台南市list
                                </div>
                            </div>
                        </div>
                        <div class="card">
                            <div class="card-header">
                                <a href="javascript:void(0);" class="card-title collapsed" data-toggle="collapse" data-target="#js_list_accordion-c" aria-expanded="false" data-filter-tags="backup">
                                    <i class="fal fa-globe width-2 fs-xl"></i>
                                    屏東縣
                                    <span class="ml-auto">
                                        <span class="collapsed-reveal">
                                            <i class="fal fa-chevron-up fs-xl"></i>
                                        </span>
                                        <span class="collapsed-hidden">
                                            <i class="fal fa-chevron-down fs-xl"></i>
                                        </span>
                                    </span>
                                </a>
                            </div>
                            <div id="js_list_accordion-c" class="collapse" data-parent="#js_list_accordion">
                                <div class="card-body">
                                    <ul class="list-group">
                                        <li class="list-group-item">
                                            <span data-filter-tags="reports file">Reports</span>
                                        </li>
                                        <li class="list-group-item">
                                            <span data-filter-tags="analytics graphs">Analytics</span>
                                        </li>
                                        <li class="list-group-item">
                                            <span data-filter-tags="export download">Export</span>
                                        </li>
                                        <li class="list-group-item">
                                            <span data-filter-tags="storage">Storage</span>
                                        </li>
                                    </ul>
                                </div>
                            </div>
                        </div>
                    </div>
                    <span class="filter-message js-filter-message"></span>
                </div>
            </div>
        </div>
        <div class="col-auto px-0">
            <a href="javascript:;" id="collapse" data-target=".sidebar" data-toggle="collapse" class="btn btn-default btn-xs btn-icon waves-effect waves-themed" style="border-radius: 0;" aria-expanded="true">
                <span class="collapsed-reveal"><i class="fal fa-angle-left fa-lg py-3"></i></span>
                <span class="collapsed-hidden"><i class="fal fa-angle-right fa-lg py-3"></i></span>
            </a>
        </div>

        <main class="col px-5 pl-md-2 main">
            <div class="subheader">
                <h1 class="subheader-title">
                    <i class="subheader-icon fal fa-file-chart-line"></i> @ViewData["Title"]
                </h1>
            </div>


            <div class="row">
                <div class="col-xl-12">
                    <div id="panel-5" class="panel">
                        <div class="panel-container show">
                            <div class="panel-content">
                                <div class="mb-3 d-flex justify-content-start">
                                    <div class="pr-3">
                                        <div class="btn-group btn-group-md">
                                            <button type="button" class="btn btn-secondary waves-effect waves-themed btn-change-searchType" onclick="changeType(0, this)" id="firstclick">月</button>
                                            <button type="button" class="btn btn-secondary waves-effect waves-themed btn-change-searchType" onclick="changeType(1, this)">年</button>
                                        </div>
                                    </div>
                                    <div class="pr-3">
                                        <button type="button" class="btn btn-secondary waves-effect waves-themed btn-change-quickSearch1" onclick="quickSearch(0)">上月</button>
                                        <button type="button" class="btn btn-secondary waves-effect waves-themed btn-change-quickSearch2" onclick="quickSearch(1)">上上月</button>
                                    </div>
                                    <div class="pr-3">
                                        <div class="btn-group" id="js-demo-nesting" role="group" aria-label="Button group with nested dropdown">
                                            <input type="month" class="form-control" id="DateGet" />
                                        </div>
                                    </div>
                                    <div class="pr-3">
                                        <button type="button" class="btn btn-primary waves-effect waves-themed ml-1" onclick="Search()">查詢</button>
                                    </div>
                                </div>
                                <div class="mb-3 d-flex justify-content-start">
                                    <div class="pr-3">
                                        <button type="button" class="btn btn-primary waves-effect waves-themed" onclick="ExportExcel()"><span class="fal fa-file-excel mr-1"></span> 匯出</button>
                                    </div>
                                    <div class="row">
                                        <div class="pr-3" id="selectOneStation">
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

            <div id="panel-5" class="panel">
                <div class="panel-container show">
                    <div class="panel-content">
                        <div id="history-kWh-convas-div">
                            <canvas id="history-kWh"></canvas>
                        </div>
                        <div class="row mb-5">


                            <div class="col-md-12 d-flex overflow-auto justify-content-end">
                                <table class="table table-bordered text-center" style="width: 80.02%">
                                    <thead>
                                        <tr>
                                            <th class="bg-warning-100" colspan="3">預估值 CBA</th>
                                            <th class="bg-info-100" colspan="2">監控系統</th>
                                            <th class="bg-success-100" colspan="2">台電售電記錄</th>
                                            <th class="bg-primary-50" colspan="5">平均發電度數小計<br>(/kW)</th>
                                        </tr>
                                        <tr>
                                            <th style="width: 6.66%">建置容量(kW)</th>
                                            <th style="width: 6.66%">發電度數(kW/日)</th>
                                            <th style="width: 6.66%">售電單價(NT$/度)</th>
                                            <th style="width: 6.66%">建置容量(kW)</th>
                                            <th style="width: 6.66%">售電單價(NT$/度)</th>
                                            <th style="width: 6.66%">建置容量(kW)</th>
                                            <th style="width: 6.66%">售電單價(NT$/度)</th>
                                            <th style="width: 6.66%">CBA</th>
                                            <th style="width: 6.66%">監控系統</th>
                                            <th style="width: 6.66%">v.s CBA</th>
                                            <th style="width: 6.66%">Actual</th>
                                            <th style="width: 6.66%">v.s CBA</th>
                                        </tr>
                                    </thead>
                                    <tbody id="totalbody">
                                    </tbody>
                                </table>
                            </div>
                            <div class="col-md-12 overflow-auto">
                                <table class="table table-bordered text-center w-100">
                                    <thead>
                                        <tr>
                                            <th class="bg-primary-50" style="width: 6.66%">起日</th>
                                            <th class="bg-primary-50" style="width: 6.66%">起訖</th>
                                            <th class="bg-primary-50" style="width: 6.66%">天數</th>
                                            <th class="bg-warning-100" style="width: 6.66%">發電效能</th>
                                            <th class="bg-warning-100" style="width: 6.66%">總發電量(度數)</th>
                                            <th class="bg-warning-100" style="width: 6.66%">總售電收入(NT$)</th>
                                            <th class="bg-info-100" style="width: 6.66%">總發電量(度數)</th>
                                            <th class="bg-info-100" style="width: 6.66%">總售電收入(NT$)</th>
                                            <th class="bg-success-100" style="width: 6.66%">總發電量(度數)</th>
                                            <th class="bg-success-100" style="width: 6.66%">總售電收入(NT$)</th>
                                            <th class="bg-primary-50" style="width: 6.66%">CBA每KW平均發電度數</th>
                                            <th class="bg-primary-50" style="width: 6.66%">監控系統每KW平均發電度數</th>
                                            <th class="bg-primary-50" style="width: 6.66%">每KW平均發電度數比較(CBA vs 監控系統)</th>
                                            <th class="bg-primary-50" style="width: 6.66%">實際售電收入每KW品駿發電度數</th>
                                            <th class="bg-primary-50" style="width: 6.66%">每KW平均發電度數比較(CBA vs 實際售電收入)</th>
                                        </tr>
                                    </thead>
                                    <tbody id="asbody">
                                    </tbody>
                                </table>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

        </main>
    </div>
</div>
@section Scripts{
    <script>
        var nowpowerstation = null;//選擇電站
        var selecterd_powerstationId = [];
        var searchType; 
        var chart;
        $(function () {
            $('#collapse').trigger("click");
            $('#firstclick').trigger("click");
            //#region 載入左邊選單列表
            GetPowerStationCollapse("");
            //#endregion
        })
        //#region 顯示動態選取電站
        function AddButtonWithStation() {
            $('#selectOneStation').empty();
            var stri = '';
            $.each(selecterd_powerstationId, function (index, inverter) {
                if (inverter.value == nowpowerstation) {
                    stri += '<button type="button" class="btn btn-success waves-effect waves-themed ml-2 mb-2 btn-station" id="' + inverter.value + '" onclick="selectPowerStation(' + inverter.value + ',this) ">' + inverter.name + '</button>';
                }
                else {
                    stri += '<button type="button" class="btn btn-outline-success waves-effect waves-themed ml-2 mb-2 btn-station" id="' + inverter.value + '" onclick="selectPowerStation(' + inverter.value + ',this) ">' + inverter.name + '</button>';
                }
            })
            $('#selectOneStation').append(stri);
            if (nowpowerstation == null && selecterd_powerstationId.length > 0) {
                document.getElementById(selecterd_powerstationId[0].value).onclick();
            }
        }
        //#endregion

        //#region 選擇動態選取電站
        function selectPowerStation(a, e) {
            nowpowerstation = a;
            if ($('#selectOneStation').find('.btn-station').hasClass("btn-success")) {
                $('#selectOneStation').find('.btn-station').removeClass("btn-success").addClass("btn-outline-success");
            }
            $(e).removeClass("btn-outline-success").addClass("btn-success");
        }
        //#endregion

        //#region 左邊的搜索欄位
        $("#js_list_accordion_filter").change(function (e) {
            GetPowerStationCollapse($(this).val());
        });

        $('#js_list_accordion').on("change", 'input[name="selectedInverterLayer2[]"]', function (event) {
            var getstation =
            {
                name: $(this).attr('valuename'),
                value: this.value
            }

            if (this.checked) {
                selecterd_powerstationId.push(getstation);
            } else {
                var a = selecterd_powerstationId.filter(function (n, i) {

                    if (n.name === getstation.name && n.value === getstation.value) {
                        if (nowpowerstation == getstation.value) {
                            nowpowerstation = null;
                        }
                        selecterd_powerstationId.splice(i, 1);
                    }

                });
            }
            AddButtonWithStation();
        });


        function GetPowerStationCollapse(filter) {
            var url = "/StationReport/GetPowerStationNameListForGeneration"

            var send_data = {
                Filter: filter
            }

            $.post(url, send_data, function (rel) {
                if (rel.code != "0000") {
                    toast_error(rel.data.msg);
                    return;
                }

                var inverterCollapse = rel.data;



                $('#js_list_accordion').empty();

                if (inverterCollapse.length <= 0) {
                    $('#js_list_accordion').append("<div>查無結果</div>");
                }

                var str = "";

                Object.keys(inverterCollapse).map(function (key, index) {
                    str += '<div class="card border-top-left-radius-0 border-top-right-radius-0" id="templateCard">' +
                        '<div class="card-header">' +
                        '<a href="javascript:void(0);" class="card-title collapsed" data-toggle="collapse" data-target="#js_list_accordion-' + index + '" aria-expanded="false" data-filter-tags="settings">' +
                        '<i class="fal fa-globe width-2 fs-xl"></i>' +
                        '<span class="city-name">' + key + '</span>' +
                        '<span class="ml-auto">' +
                        '<span class="collapsed-reveal"><i class="fal fa-chevron-up fs-xl"></i></span>' +
                        '<span class="collapsed-hidden"><i class="fal fa-chevron-down fs-xl"></i></span>' +
                        '</span>' +
                        '</a>' +
                        '</div>' +
                        '<div id="js_list_accordion-' + index + '" class="collapse" data-parent="#js_list_accordion-' + index + '" style="">' +
                        '<div class="card-body">' +
                        '<ul class="list-group list-group-flush">';
                    $.each(inverterCollapse[key], function (index, inverter) {
                        var getstation =
                        {
                            name: inverter.powerStationName,
                            value: String(inverter.powerStationId)
                        }
                        var on = false;
                        var a = selecterd_powerstationId.find(function (n, i) {
                            if (n.name === getstation.name && n.value === getstation.value) {
                                on = true;
                            }
                        });
                        if (on == true) {
                            str += '<li class="list-group-item">' +
                                '<div class="d-flex justify-content-start">' +
                                '<div class="mr-2">' +
                                '<input type="checkbox" class="" name="selectedInverterLayer2[]" value="' + inverter.powerStationId + '" valueName ="' + inverter.powerStationName + '" checked>' +
                                '</div>' +
                                '<h5 class="font-weight-bold">' + inverter.powerStationName + '</h5>' +
                                '</div>' +
                                '</li>';
                        }
                        else {
                            str += '<li class="list-group-item">' +
                                '<div class="d-flex justify-content-start">' +
                                '<div class="mr-2">' +
                                '<input type="checkbox" class="" name="selectedInverterLayer2[]" value="' + inverter.powerStationId + '" valueName ="' + inverter.powerStationName + '">' +
                                '</div>' +
                                '<h5 class="font-weight-bold">' + inverter.powerStationName + '</h5>' +
                                '</div>' +
                                '</li>';
                        }
                    });

                    str += '</ul>';
                    str += '</div>';
                    str += '</div>';

                });

                $('#js_list_accordion').append(str);
                $('#js_list_accordion').find('.card').first().addClass(" border-top-left-radius-0 border-top-right-radius-0");

                $('input[name="selectedInverterLayer2[]"]').each(function () {
                    if ($.inArray(this.value, selecterd_powerstationId) > -1) {
                        $(this).prop('checked', true);
                    }
                });
                $("#js_list_accordion .collapse").collapse('show');


            }, 'json');
        }
        //#endregion

        //#region 更換搜尋條件(日,日區間,月,年)
        function changeType(type, e) {
            searchType = type;
            if ($(".btn-change-searchType").hasClass("btn-success")) {
                $(".btn-change-searchType").removeClass("btn-success").addClass("btn-secondary");
            }
            $(e).removeClass("btn-secondary").addClass("btn-success");
            switch (type) {
                case 0: $('#DateGet').prop({ 'type': 'month' });
                    $(".btn-change-quickSearch1").html("上月");
                    $(".btn-change-quickSearch2").html("上上月");
                    var dateLimit = new Date(new Date().setMonth(new Date().getMonth() - 1)).toISOString().substring(0, 7);
                    $('#DateGet').val(dateLimit);
                    break;
                case 1:
                    var year = new Date(new Date().setFullYear(new Date().getFullYear() - 1)).toISOString().substring(0, 4);
                    $('#DateGet').prop({ 'type': 'number', 'min': 1900, 'max': dateLimit, 'step': 1 });
                    $(".btn-change-quickSearch1").html("去年");
                    $(".btn-change-quickSearch2").html("前年");
                    $('#DateGet').val(year);
                    break;
            }

        }
        //#endregion

        //#region 快速填入條件(EX.今昨天)
        function quickSearch(day) {
            switch (searchType) {
                case 0:
                    if (day == 0) {
                        var dateLimit = new Date(new Date().setMonth(new Date().getMonth() - 1)).toISOString().substring(0, 7);
                        $('#DateGet').val(dateLimit).trigger('change');
                    } else {
                        var dateLimit = new Date(new Date().setMonth(new Date().getMonth() - 2)).toISOString().substring(0, 7);
                        $('#DateGet').val(dateLimit).trigger('change');
                    }
                    break;
                case 1:
                    if (day == 0) {
                        var dateLimit = new Date(new Date().setFullYear(new Date().getFullYear() - 1)).toISOString().substring(0, 4);
                        $('#DateGet').val(dateLimit).trigger('change');
                    } else {
                        var dateLimit = new Date(new Date().setFullYear(new Date().getFullYear() - 2)).toISOString().substring(0, 4);
                        $('#DateGet').val(dateLimit).trigger('change');
                    }
                    break;
            }
        }
        //#endregion


        function Search() {
            var url = "/PowerGeneration/GetGenerationList"
            var send_data = {
                PowerstationId: nowpowerstation,
                DateType: searchType,
                Date: $('#DateGet').val()
            }
            $.post(url, send_data, function (rel) {
                if (rel.code != "0000") {
                    toast_error(rel.msg);
                    return;
                }
                var str = "";
                var totaldays = 0;
                var capacity = 0;
                var rate = 0;
                var totalcbAkwh = 0;
                var totalactualkwh = 0;
                var totalrealKWH = 0;
                var cbAkwh = 0;
                var listday = new Array(0);
                var listcba = new Array(0);
                var listactual = new Array(0);
                var listreal = new Array(0);
                $('#totalbody').empty();
                $('#asbody').empty();


                if (rel.data.length == 0)
                {
                    str += "<tr>";
                    str += "<td colspan='15'>" + "查無資料" + "</td>";
                    str += "</tr>";
                }

                $.each(rel.data, function (index, val) {
                    var day1 = new Date(val.startAt);
                    var day2 = new Date(val.endAt);
                    var difference = Math.abs(day2 - day1);
                    var days = difference / (1000 * 3600 * 24) + 1;
                    totaldays += days;
                    capacity = val.capacity;
                    totalcbAkwh += val.cbAkwh * val.cbAeff * days * val.capacity * 0.01;
                    rate = val.rate;
                    totalactualkwh += val.actualkwh;
                    totalrealKWH += val.realKWH;
                    cbAkwh = val.cbAkwh;

                    listday.push(val.startAt);
                    listcba.push((val.cbAkwh * val.cbAeff * days * val.capacity * 0.01).toFixed(2));
                    listactual.push(val.actualkwh.toFixed(2));
                    listreal.push(val.realKWH.toFixed(2));

                    str += "<tr>";
                    str += "<td>" + val.startAt + "</td>";
                    str += "<td>" + val.endAt + "</td>";
                    str += "<td>" + days + "天" + "</td>";
                    str += "<td>" + val.cbAeff + "%" + "</td>";
                    str += "<td>" + (val.cbAkwh * val.cbAeff * days * val.capacity * 0.01).toFixed(2) + "</td>";
                    str += "<td>" + (val.rate * (val.cbAkwh * val.cbAeff * days * val.capacity * 0.01)).toFixed(2) + "</td>";
                    str += "<td>" + val.realKWH.toFixed(2) + "</td>";
                    str += "<td>" + val.realMoney.toFixed(2) + "</td>";
                    str += "<td>" + val.actualkwh.toFixed(2) + "</td>";
                    str += "<td>" + val.actualMoney.toFixed(2) + "</td>";
                    var cba = val.cbAkwh * val.cbAeff * days * val.capacity * 0.01 / days / val.capacity; 
                    str += "<td>" + cba.toFixed(2) + "</td>";
                    var real = val.realKWH / days / val.capacity;
                    str += "<td>" + real.toFixed(2) + "</td>";
                    str += "<td>" + ((cba == 0) ? 0 : ((real / cba - 1) * 100 ).toFixed(2)) + "%" + "</td>";
                    var act = val.actualkwh / days / val.capacity;
                    str += "<td>" + act.toFixed(2) + "</td>";
                    str += "<td>" + ((cba == 0) ? 0 : ((act / cba - 1) * 100 ).toFixed(2)) + "%" + "</td>";
                    str += "</tr>";
                })
                var checkvalue = false;
                if (totalcbAkwh == 0 || totaldays == 0 || capacity == 0)
                {
                    checkvalue = true;
                }
                var stra = "";
                stra += "<tr>";
                stra += "<td>" + capacity.toFixed(2) + "</td>";
                stra += "<td>" + cbAkwh.toFixed(2) + "</td>";
                stra += "<td>" + rate.toFixed(2) + "</td>";
                stra += "<td>" + capacity.toFixed(2) + "</td>";
                stra += "<td>" + rate.toFixed(2) + "</td>";
                stra += "<td>" + capacity.toFixed(2) + "</td>";
                stra += "<td>" + rate.toFixed(2) + "</td>";
                stra += "<td>" + (checkvalue ? 0 : (totalcbAkwh / totaldays / capacity).toFixed(2)) + "</td>";
                stra += "<td>" + ((totaldays == 0) ? 0 : (totalrealKWH / totaldays / capacity).toFixed(2)) + "</td>";
                stra += "<td>" + (checkvalue ? 0 : ((( (totalrealKWH / totaldays / capacity) / (totalcbAkwh / totaldays / capacity)) - 1) * 100).toFixed(2)  ) + "%" + "</td>";
                stra += "<td>" + ((totaldays == 0) ? 0 : (totalactualkwh / totaldays / capacity).toFixed(2)) + "</td>";
                stra += "<td>" + (checkvalue ? 0 : ( (((totalactualkwh / totaldays / capacity) / (totalcbAkwh / totaldays / capacity)) - 1) * 100).toFixed(2)  )  + "%" + "</td>";
                stra += "</tr>";
                $('#totalbody').append(stra);
                $('#asbody').append(str);

                $('#history-kWh-convas-div').empty();
                $('#history-kWh-convas-div').append('<canvas id="history-kWh"></canvas>');
                var ctx_history_kWh = document.getElementById('history-kWh').getContext('2d');
                var myhistorykwh = new Chart(ctx_history_kWh, {
                    type: 'bar',
                    data: {
                        labels: listday,
                        datasets: [
                            {
                                type: 'line',
                                label: 'CBA預估總發電量(度數)',
                                borderColor: 'rgb(0, 0, 0)',
                                pointBackgroundColor: 'rgb(0, 0, 0)',
                                pointBorderColor: 'rgb(0, 0, 0)',
                                pointBorderWidth: 1,
                                borderWidth: 1,
                                pointRadius: 1,
                                pointHoverRadius: 1,
                                fill: true,
                                backgroundColor: 'rgb(255, 192, 0)',
                                data: listcba
                            }, {
                                type: 'bar',
                                label: '監控系統總發電量(度數)',
                                backgroundColor: 'rgba(68, 114, 196)',
                                borderWidth: 1,
                                data: listreal
                            }, {
                                type: 'bar',
                                label: '台電售電量(度數)',
                                backgroundColor: 'rgba(165, 165, 165)',
                                borderWidth: 1,
                                data: listactual
                            }]
                    },
                    options: {
                        title: {
                            display: true,
                            text: '電量比較'
                        },
                        legend: {
                            display: true,
                            position: 'bottom'
                        },
                        scales: {
                            yAxes: [{
                                type: 'linear',
                                position: 'left',
                                ticks: {
                                    min: 0
                                },
                                scaleLabel: {
                                    display: true,
                                    labelString: '度數'
                                }
                            }]
                        }
                    }
                });



            });

        }

        function ExportExcel() {
            var send_data = {
                PowerStation: selecterd_powerstationId,
                DateType: searchType,
                Date: $('#DateGet').val()
            }
            if (send_data.PowerStation.length != 0) {
                window.location = "/PowerGeneration/ExportExcel?post=" + JSON.stringify(send_data);
            }
            else {
                toast_warning("請先選擇電站");
            }
        }
    </script>
}