#129 expenses UI
This commit is contained in:
parent
d6644fcaf5
commit
045ef6f405
@ -85,7 +85,7 @@
|
||||
<td>@donation.DonorName</td>
|
||||
<td>
|
||||
<a role="button" href="/Admin/DonationEdit/?id=@donation.Id" class="actionlink" title="ویرایش">✎</a>
|
||||
<a role="button" onclick="deleteDonation(@donation.Id)" class="actionlink" title="حذف">🗑</a>
|
||||
<a role="button" onclick="deleteItem(@donation.Id, 'کمک')" class="actionlink" title="حذف">🗑</a>
|
||||
</td>
|
||||
</tr>
|
||||
}
|
||||
|
||||
88
GanjooRazor/Areas/Admin/Pages/Expenses.cshtml
Normal file
88
GanjooRazor/Areas/Admin/Pages/Expenses.cshtml
Normal file
@ -0,0 +1,88 @@
|
||||
@page
|
||||
@model GanjooRazor.Areas.Admin.Pages.ExpensesModel
|
||||
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
|
||||
@{
|
||||
Layout = "_AdminLayout";
|
||||
ViewData["Title"] = "هزینهها";
|
||||
}
|
||||
|
||||
<h1>@ViewData["Title"]</h1>
|
||||
|
||||
<p>@Model.LastMessage</p>
|
||||
|
||||
<form method="post">
|
||||
<table>
|
||||
<tr>
|
||||
<td>
|
||||
تاریخ:
|
||||
</td>
|
||||
<td>
|
||||
<input type="date" asp-for="Expense.ExpenseDate" />
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
مبلغ:
|
||||
</td>
|
||||
<td>
|
||||
<input type="number" asp-for="Expense.Amount" />
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
واحد:
|
||||
</td>
|
||||
<td>
|
||||
<input asp-for="Expense.Unit" />
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
شرح:
|
||||
</td>
|
||||
<td>
|
||||
<input size="50" asp-for="Expense.Description" />
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td colspan="2">
|
||||
<input type="submit" value="ثبت هزینهٔ جدید" />
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
</table>
|
||||
|
||||
</form>
|
||||
|
||||
<p><a href="/donate" target="_blank">مشاهدهٔ صفحه</a></p>
|
||||
<p>@Model.ShowAccountInfo</p>
|
||||
<p><a role="button" onclick="rebuildDonationsPage()" class="actionlink" title="بازسازی صفحهٔ کمکها">بازسازی صفحهٔ کمکها</a></p>
|
||||
|
||||
@if (Model.Expenses != null)
|
||||
{
|
||||
<table>
|
||||
<tr>
|
||||
<th>تاریخ</th>
|
||||
<th>مبلغ</th>
|
||||
<th>شرح</th>
|
||||
<th>
|
||||
#
|
||||
</th>
|
||||
</tr>
|
||||
@foreach (var expense in Model.Expenses)
|
||||
{
|
||||
<tr id="tr-@expense.Id">
|
||||
<td>@RMuseum.Services.Implementation.DonationService.FormatDate(expense.ExpenseDate)</td>
|
||||
<td>@RMuseum.Services.Implementation.DonationService.FormatMoney(expense.Amount)</td>
|
||||
<td>@expense.Description</td>
|
||||
<td>
|
||||
<a role="button" href="/Admin/ExpenseEdit/?id=@expense.Id" class="actionlink" title="ویرایش">✎</a>
|
||||
<a role="button" onclick="deleteItem(@expense.Id, 'هزینه')" class="actionlink" title="حذف">🗑</a>
|
||||
</td>
|
||||
</tr>
|
||||
}
|
||||
</table>
|
||||
|
||||
|
||||
}
|
||||
142
GanjooRazor/Areas/Admin/Pages/Expenses.cshtml.cs
Normal file
142
GanjooRazor/Areas/Admin/Pages/Expenses.cshtml.cs
Normal file
@ -0,0 +1,142 @@
|
||||
using System;
|
||||
using System.Net.Http;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using GanjooRazor.Utils;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||
using Newtonsoft.Json;
|
||||
using RMuseum.Models.Accounting;
|
||||
|
||||
namespace GanjooRazor.Areas.Admin.Pages
|
||||
{
|
||||
[IgnoreAntiforgeryToken(Order = 1001)]
|
||||
public class ExpensesModel : PageModel
|
||||
{
|
||||
/// <summary>
|
||||
/// HttpClient instance
|
||||
/// </summary>
|
||||
private readonly HttpClient _httpClient;
|
||||
|
||||
/// <summary>
|
||||
/// constructor
|
||||
/// </summary>
|
||||
/// <param name="httpClient"></param>
|
||||
public ExpensesModel(HttpClient httpClient)
|
||||
{
|
||||
_httpClient = httpClient;
|
||||
}
|
||||
/// <summary>
|
||||
/// last message
|
||||
/// </summary>
|
||||
public string LastMessage { get; set; }
|
||||
[BindProperty]
|
||||
public GanjoorExpense Expense { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// donations
|
||||
/// </summary>
|
||||
public GanjoorExpense[] Expenses { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// show account info
|
||||
/// </summary>
|
||||
public string ShowAccountInfo { get; set; }
|
||||
|
||||
private async Task ReadExpenses()
|
||||
{
|
||||
var response = await _httpClient.GetAsync($"{APIRoot.Url}/api/donations/expense");
|
||||
if (!response.IsSuccessStatusCode)
|
||||
{
|
||||
LastMessage = await response.Content.ReadAsStringAsync();
|
||||
}
|
||||
|
||||
response.EnsureSuccessStatusCode();
|
||||
|
||||
Expenses = JsonConvert.DeserializeObject<GanjoorExpense[]>(await response.Content.ReadAsStringAsync());
|
||||
|
||||
using (HttpClient secureClient = new HttpClient())
|
||||
{
|
||||
if (await GanjoorSessionChecker.PrepareClient(secureClient, Request, Response))
|
||||
{
|
||||
HttpResponseMessage resAccountInfo = await secureClient.GetAsync($"{APIRoot.Url}/api/donations/accountinfo/visible");
|
||||
if (!resAccountInfo.IsSuccessStatusCode)
|
||||
{
|
||||
LastMessage = await resAccountInfo.Content.ReadAsStringAsync();
|
||||
}
|
||||
|
||||
resAccountInfo.EnsureSuccessStatusCode();
|
||||
|
||||
ShowAccountInfo = JsonConvert.DeserializeObject<bool>(await resAccountInfo.Content.ReadAsStringAsync()) ? "نمایش حساب فعال است." : "نمایش حساب غیرفعال است.";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<IActionResult> OnGetAsync()
|
||||
{
|
||||
LastMessage = "";
|
||||
|
||||
Expense = new GanjoorExpense()
|
||||
{
|
||||
ExpenseDate = DateTime.Now.Date,
|
||||
Unit = "تومان",
|
||||
};
|
||||
|
||||
await ReadExpenses();
|
||||
|
||||
return Page();
|
||||
}
|
||||
|
||||
public async Task<IActionResult> OnPostAsync(GanjoorExpense Expense)
|
||||
{
|
||||
LastMessage = "";
|
||||
using (HttpClient secureClient = new HttpClient())
|
||||
{
|
||||
if (await GanjoorSessionChecker.PrepareClient(secureClient, Request, Response))
|
||||
{
|
||||
|
||||
HttpResponseMessage response = await secureClient.PostAsync($"{APIRoot.Url}/api/donations/expense", new StringContent(JsonConvert.SerializeObject(Expense), Encoding.UTF8, "application/json"));
|
||||
if (!response.IsSuccessStatusCode)
|
||||
{
|
||||
LastMessage = await response.Content.ReadAsStringAsync();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
LastMessage = "لطفا از گنجور خارج و مجددا به آن وارد شوید.";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return Page();
|
||||
}
|
||||
|
||||
public async Task<IActionResult> OnPostRebuildPageAsync()
|
||||
{
|
||||
using (HttpClient secureClient = new HttpClient())
|
||||
{
|
||||
if (await GanjoorSessionChecker.PrepareClient(secureClient, Request, Response))
|
||||
{
|
||||
HttpResponseMessage response = await secureClient.PutAsync($"{APIRoot.Url}/api/donations/page", null);
|
||||
response.EnsureSuccessStatusCode();
|
||||
return new OkObjectResult(true);
|
||||
}
|
||||
}
|
||||
return new OkObjectResult(false);
|
||||
}
|
||||
|
||||
public async Task<IActionResult> OnDeleteAsync(int id)
|
||||
{
|
||||
using (HttpClient secureClient = new HttpClient())
|
||||
{
|
||||
if (await GanjoorSessionChecker.PrepareClient(secureClient, Request, Response))
|
||||
{
|
||||
var response = await secureClient.DeleteAsync($"{APIRoot.Url}/api/donations/expense/{id}");
|
||||
response.EnsureSuccessStatusCode();
|
||||
return new OkObjectResult(true);
|
||||
}
|
||||
}
|
||||
return new OkObjectResult(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -76,9 +76,9 @@
|
||||
});
|
||||
}
|
||||
|
||||
function deleteDonation(donationId) {
|
||||
function deleteItem(itemId, itemName) {
|
||||
|
||||
if (!confirm('آیا از حذف این کمک اطمینان دارید؟'))
|
||||
if (!confirm('آیا از حذف این ' + itemName+' اطمینان دارید؟'))
|
||||
return;
|
||||
|
||||
|
||||
@ -86,7 +86,7 @@
|
||||
type: "DELETE",
|
||||
url: '',
|
||||
data: {
|
||||
id: donationId
|
||||
id: itemId
|
||||
},
|
||||
error: function () {
|
||||
alert('خطا رخ داد.');
|
||||
@ -127,6 +127,14 @@
|
||||
|
||||
</ul>
|
||||
</div>
|
||||
<div class="navbar-collapse collapse d-sm-inline-flex justify-content-between">
|
||||
<ul class="navbar-nav flex-grow-1">
|
||||
<li class="nav-item">
|
||||
<a class="nav-link text-dark" asp-area="Admin" asp-page="Expenses">هزینهها</a>
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</nav>
|
||||
</header>
|
||||
|
||||
@ -8194,6 +8194,20 @@
|
||||
Show Donating Information (temporary switch off/on)
|
||||
</summary>
|
||||
</member>
|
||||
<member name="M:RMuseum.Services.Implementation.DonationService.FormatMoney(System.Decimal)">
|
||||
<summary>
|
||||
format money
|
||||
</summary>
|
||||
<param name="amount"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:RMuseum.Services.Implementation.DonationService.FormatDate(System.DateTime)">
|
||||
<summary>
|
||||
format datetime
|
||||
</summary>
|
||||
<param name="dateTime"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="F:RMuseum.Services.Implementation.DonationService._context">
|
||||
<summary>
|
||||
Database Context
|
||||
|
||||
@ -828,12 +828,23 @@ namespace RMuseum.Services.Implementation
|
||||
}
|
||||
}
|
||||
|
||||
private static string FormatMoney(decimal amount)
|
||||
/// <summary>
|
||||
/// format money
|
||||
/// </summary>
|
||||
/// <param name="amount"></param>
|
||||
/// <returns></returns>
|
||||
|
||||
public static string FormatMoney(decimal amount)
|
||||
{
|
||||
return amount.ToString("N0", new CultureInfo("fa-IR")).ToPersianNumbers();
|
||||
}
|
||||
|
||||
private static string FormatDate(DateTime dateTime)
|
||||
/// <summary>
|
||||
/// format datetime
|
||||
/// </summary>
|
||||
/// <param name="dateTime"></param>
|
||||
/// <returns></returns>
|
||||
public static string FormatDate(DateTime dateTime)
|
||||
{
|
||||
return $"{dateTime.ToPersianYearMonthDay().Day.ToPersianNumbers()}م {PersianCulture.GetPersianMonthName(dateTime.ToPersianYearMonthDay().Month)} {dateTime.ToPersianYearMonthDay().Year.ToPersianNumbers()}";
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user