@page
@model Manage.IndexModel
@using Microsoft.AspNetCore.Http
@using JtkMainServer.Managers
@{
    ViewData["Title"] = "관리자 페이지";
    ViewData["LoggedInUserId"] = HttpContext.Session.GetString("LoggedInUserId");
    ViewData["LoggedIn"] = ViewData["LoggedInUserId"] != null;
    ViewData["ActivatedTabIndex"] = 0;

    var toDate = DateTime.Today;
    var fromDate = DateTime.Parse($"{toDate.Year}-{toDate.Month}-01");

    var days = Math.Round((toDate - fromDate).TotalDays) + 1;

    var monthIncome = DbManager.GetSalesUserChargeIncome(fromDate, toDate);
    var monthExpense = DbManager.GetSalesPlacePaymentExpense(fromDate, toDate);
    var monthUsersCount = DbManager.GetUsersCount(fromDate, toDate);
    var monthPlacesCount = DbManager.GetPlacesCount(fromDate, toDate);

    var income = DbManager.GetSalesUserChargeIncome();
    var expense = DbManager.GetSalesPlacePaymentExpense();
    var usersCount = DbManager.GetUsersCount();
    var placesCount = DbManager.GetPlacesCount();
}

<style type="text/css">
    .table-stats {
        width: 100%;
    }
    .table-stats th {
        font-weight: normal;
        font-size: large;
        padding: 8px 4px 8px 4px;
    }

    .table-stats td {
        text-align: right;
    }
</style>
<div class="row" style="margin-top:20px">
    <div class="col-md-6">
        @Html.Partial("~/Views/ManageTabs.cshtml")
        <h3>@(DateTime.Now.Month)월 통계<span style="font-size: small"> @(days)일간</span></h3>
        <table class="table-stats">
            <tr>
                <th>수입액</th>
                <td>￦@monthIncome.ToString("N0")</td>
            </tr>
            <tr>
                <th>지출액</th>
                <td>￦@monthExpense.ToString("N0")</td>
            </tr>
            <tr>
                <th>등록 회원수</th>
                <td>@(monthUsersCount.ToString("N0"))명</td>
            </tr>
            <tr>
                <th>등록 가맹점수</th>
                <td>@(monthPlacesCount.ToString("N0"))개소</td>
            </tr>
        </table>
        <hr />
        <h3>전체 통계</h3>
        <table class="table-stats">
            <tr>
                <th>수입액</th>
                <td>￦@income.ToString("N0")</td>
            </tr>
            <tr>
                <th>지출액</th>
                <td>￦@expense.ToString("N0")</td>
            </tr>
            <tr>
                <th>회원수</th>
                <td>@(usersCount.ToString("N0"))명</td>
            </tr>
            <tr>
                <th>가맹점수</th>
                <td>@(placesCount.ToString("N0"))개소</td>
            </tr>
        </table>
        <hr />
    </div>
</div>

<div>
    <a asp-page="Index">홈으로 이동</a>
</div>