feat: add withdrawal requests feature and update VAT loading mechanism
Build and Deploy / build (push) Successful in 1m25s

This commit is contained in:
masoodafar-web
2025-12-20 04:03:11 +03:30
parent 9ee464b8b4
commit 025e8d3c3e
24 changed files with 961 additions and 398 deletions
@@ -58,7 +58,7 @@
</HeaderContent>
<RowTemplate>
<MudTd>
<MudChip T="string" Color="Color.Default" Size="Size.Small">@context.WeekLabel</MudChip>
<MudChip T="string" Color="Color.Default" Size="Size.Small">@context.WeekDisplayName</MudChip>
</MudTd>
<MudTd>@context.BalancesEarned</MudTd>
<MudTd>
@@ -75,7 +75,7 @@
Variant="Variant.Text"
Color="Color.Info"
StartIcon="@Icons.Material.Filled.Info"
Href="@($"{RouteConstants.Commission.WeeklyBalance}?week={context.WeekNumber}")">
Href="@($"{RouteConstants.Commission.WeeklyBalance}?week={context.WeekDefinitionId}")">
جزئیات
</MudButton>
</MudTd>
@@ -90,7 +90,7 @@
<MudPaper Class="pa-3 rounded-lg" Outlined="true">
<MudStack Spacing="1">
<MudStack Row="true" Justify="Justify.SpaceBetween" AlignItems="AlignItems.Center">
<MudChip T="string" Color="Color.Default" Size="Size.Small">@payout.WeekLabel</MudChip>
<MudChip T="string" Color="Color.Default" Size="Size.Small">@payout.WeekDisplayName</MudChip>
<MudChip T="string" Color="@GetStatusColor(payout.StatusBadgeColor)" Size="Size.Small" Variant="Variant.Outlined">
@payout.Status
</MudChip>
@@ -103,7 +103,7 @@
Color="Color.Info"
FullWidth="true"
StartIcon="@Icons.Material.Filled.Info"
Href="@($"{RouteConstants.Commission.WeeklyBalance}?week={payout.WeekNumber}")">
Href="@($"{RouteConstants.Commission.WeeklyBalance}?week={payout.WeekDefinitionId}")">
مشاهده جزئیات هفته
</MudButton>
</MudStack>
@@ -52,7 +52,7 @@
</HeaderContent>
<RowTemplate>
<MudTd DataLabel="هفته">
<MudChip T="string" Color="Color.Primary" Size="Size.Small" Variant="Variant.Outlined">@context.WeekLabel</MudChip>
<MudChip T="string" Color="Color.Primary" Size="Size.Small" Variant="Variant.Outlined">@context.WeekDisplayName</MudChip>
</MudTd>
<MudTd DataLabel="تعادل‌ها">
<MudText>@context.BalancesEarned</MudText>
@@ -73,7 +73,7 @@
Variant="Variant.Text"
Color="Color.Info"
StartIcon="@Icons.Material.Filled.Visibility"
Href="@($"{RouteConstants.Commission.WeeklyBalance}?week={context.WeekNumber}")">
Href="@($"{RouteConstants.Commission.WeeklyBalance}?week={context.WeekDefinitionId}")">
مشاهده
</MudButton>
</MudTd>
@@ -1,5 +1,6 @@
@attribute [Route(RouteConstants.Commission.WeeklyBalance)]
@using FrontOffice.Main.Utilities
@using FrontOffice.Main.Shared
@using MudBlazor
<PageTitle>تعادل هفتگی</PageTitle>
@@ -13,20 +14,38 @@
<!-- انتخاب هفته -->
<MudPaper Elevation="2" Class="pa-3 rounded-lg">
<MudStack Row="true" Spacing="2" AlignItems="AlignItems.End">
<MudNumericField @bind-Value="_selectedWeekNumber"
Label="شماره هفته"
Variant="Variant.Outlined"
Min="1"
HelperText="هفته مورد نظر را انتخاب کنید (خالی = هفته جاری)"
Style="max-width: 200px;" />
<MudButton Variant="Variant.Filled" Color="Color.Primary" OnClick="LoadWeeklyBalanceAsync" StartIcon="@Icons.Material.Filled.Search">
مشاهده
</MudButton>
<MudButton Variant="Variant.Outlined" OnClick="LoadCurrentWeekAsync" StartIcon="@Icons.Material.Filled.Today">
هفته جاری
</MudButton>
</MudStack>
<MudGrid Spacing="2">
<MudItem xs="8" sm="6" md="6">
<WeekSelector @ref="_weekSelector"
@bind-Value="_selectedWeekDefinition"
Label="انتخاب هفته"
Placeholder="هفته را جستجو یا انتخاب کنید"
Variant="Variant.Outlined"
Dense="false"
OnlyActive="true" />
</MudItem>
@* <MudItem xs="4" sm="3" md="3"> *@
@* <MudButton Variant="Variant.Outlined" *@
@* OnClick="LoadCurrentWeekAsync" *@
@* StartIcon="@Icons.Material.Filled.Today" *@
@* FullWidth="true" *@
@* Style="height: 56px;"> *@
@* هفته جاری *@
@* </MudButton> *@
@* </MudItem> *@
<MudItem xs="4" sm="3" md="3" Class="pt-6">
<MudButton Variant="Variant.Filled"
Color="Color.Primary"
OnClick="LoadWeeklyBalanceAsync"
StartIcon="@Icons.Material.Filled.Search"
Disabled="@(_selectedWeekDefinition == null)"
FullWidth="true"
Style="height: 50px;">
جستجو
</MudButton>
</MudItem>
</MudGrid>
</MudPaper>
@if (_isLoading)
@@ -35,113 +54,89 @@
}
else if (_weeklyBalance is not null)
{
<!-- اطلاعات هفته -->
<MudPaper Elevation="2" Class="pa-4 rounded-lg">
<MudStack Spacing="2">
<MudText Typo="Typo.h6">هفته @_weeklyBalance.WeekNumber - @_weeklyBalance.WeekLabel</MudText>
<MudDivider />
<MudGrid Spacing="2">
<MudItem xs="12" sm="6">
<MudText Typo="Typo.subtitle2" Class="mud-text-secondary">تاریخ شروع:</MudText>
<MudText Typo="Typo.body1"><strong>@_weeklyBalance.StartDatePersian</strong></MudText>
</MudItem>
<MudItem xs="12" sm="6">
<MudText Typo="Typo.subtitle2" Class="mud-text-secondary">تاریخ پایان:</MudText>
<MudText Typo="Typo.body1"><strong>@_weeklyBalance.EndDatePersian</strong></MudText>
</MudItem>
</MudGrid>
</MudStack>
<!-- اطلاعات هفته - کامپکت -->
<MudPaper Elevation="2" Class="pa-3 rounded-lg">
<MudGrid Spacing="1">
<MudItem xs="12" sm="4">
<MudStack Row="true" AlignItems="AlignItems.Center" Spacing="1">
<MudIcon Icon="@Icons.Material.Filled.DateRange" Size="Size.Small" Color="Color.Primary" />
<MudText Typo="Typo.body2"><strong>@_weeklyBalance.WeekDisplayName</strong></MudText>
</MudStack>
</MudItem>
<MudItem xs="6" sm="4">
<MudText Typo="Typo.caption" Class="mud-text-secondary">شروع: <strong>@_weeklyBalance.StartDatePersian</strong></MudText>
</MudItem>
<MudItem xs="6" sm="4">
<MudText Typo="Typo.caption" Class="mud-text-secondary">پایان: <strong>@_weeklyBalance.EndDatePersian</strong></MudText>
</MudItem>
</MudGrid>
</MudPaper>
<!-- تعادل چپ و راست -->
<!-- تعادل چپ و راست - کارت‌های بزرگ -->
<MudGrid Spacing="2">
<MudItem xs="12" md="6">
<MudPaper Elevation="2" Class="pa-4 rounded-lg" Style="height: 100%;">
<MudStack Spacing="2">
<MudStack Row="true" AlignItems="AlignItems.Center" Spacing="2">
<MudIcon Icon="@Icons.Material.Filled.ChevronLeft" Color="Color.Info" Size="Size.Large" />
<MudText Typo="Typo.h6" Color="Color.Info">شاخه چپ</MudText>
</MudStack>
<MudText Typo="Typo.h4" Color="Color.Info">@_weeklyBalance.LeftBalanceFormatted</MudText>
<MudItem xs="6">
<MudPaper Elevation="3" Class="pa-4 rounded-lg text-center" Style="background: linear-gradient(135deg, #e3f2fd 0%, #bbdefb 100%);">
<MudStack Spacing="1" AlignItems="AlignItems.Center">
<MudIcon Icon="@Icons.Material.Filled.ChevronLeft" Color="Color.Info" Size="Size.Large" />
<MudText Typo="Typo.subtitle2" Color="Color.Info">شاخه چپ</MudText>
<MudText Typo="Typo.h5" Color="Color.Info" Style="font-weight: bold;">@_weeklyBalance.LeftBalanceFormatted</MudText>
<MudProgressLinear Color="Color.Info"
Value="@GetLeftPercentage()"
Size="Size.Large"
Class="rounded-lg" />
Size="Size.Medium"
Class="rounded-lg mt-2"
Style="width: 100%;" />
<MudText Typo="Typo.caption" Class="mud-text-secondary">
@GetLeftPercentage().ToString("F1")% از کل تعادل
@GetLeftPercentage().ToString("F1")% از کل
</MudText>
</MudStack>
</MudPaper>
</MudItem>
<MudItem xs="12" md="6">
<MudPaper Elevation="2" Class="pa-4 rounded-lg" Style="height: 100%;">
<MudStack Spacing="2">
<MudStack Row="true" AlignItems="AlignItems.Center" Spacing="2">
<MudIcon Icon="@Icons.Material.Filled.ChevronRight" Color="Color.Success" Size="Size.Large" />
<MudText Typo="Typo.h6" Color="Color.Success">شاخه راست</MudText>
</MudStack>
<MudText Typo="Typo.h4" Color="Color.Success">@_weeklyBalance.RightBalanceFormatted</MudText>
<MudItem xs="6">
<MudPaper Elevation="3" Class="pa-4 rounded-lg text-center" Style="background: linear-gradient(135deg, #e8f5e9 0%, #c8e6c9 100%);">
<MudStack Spacing="1" AlignItems="AlignItems.Center">
<MudIcon Icon="@Icons.Material.Filled.ChevronRight" Color="Color.Success" Size="Size.Large" />
<MudText Typo="Typo.subtitle2" Color="Color.Success">شاخه راست</MudText>
<MudText Typo="Typo.h5" Color="Color.Success" Style="font-weight: bold;">@_weeklyBalance.RightBalanceFormatted</MudText>
<MudProgressLinear Color="Color.Success"
Value="@GetRightPercentage()"
Size="Size.Large"
Class="rounded-lg" />
Size="Size.Medium"
Class="rounded-lg mt-2"
Style="width: 100%;" />
<MudText Typo="Typo.caption" Class="mud-text-secondary">
@GetRightPercentage().ToString("F1")% از کل تعادل
@GetRightPercentage().ToString("F1")% از کل
</MudText>
</MudStack>
</MudPaper>
</MudItem>
</MudGrid>
<!-- محاسبات کمیسیون -->
<!-- محاسبات کمیسیون - فشرده‌تر -->
<MudPaper Elevation="2" Class="pa-4 rounded-lg">
<MudText Typo="Typo.h6" Class="mb-3">محاسبات کمیسیون</MudText>
<MudStack Spacing="2">
<MudStack Row="true" Justify="Justify.SpaceBetween" AlignItems="AlignItems.Center">
<MudText Typo="Typo.body1">تعادل چپ:</MudText>
<MudText Typo="Typo.body1" Color="Color.Info"><strong>@_weeklyBalance.LeftBalanceFormatted</strong></MudText>
</MudStack>
<MudStack Row="true" Justify="Justify.SpaceBetween" AlignItems="AlignItems.Center">
<MudText Typo="Typo.body1">تعادل راست:</MudText>
<MudText Typo="Typo.body1" Color="Color.Success"><strong>@_weeklyBalance.RightBalanceFormatted</strong></MudText>
</MudStack>
<MudDivider />
<MudStack Row="true" Justify="Justify.SpaceBetween" AlignItems="AlignItems.Center">
<MudText Typo="Typo.body1">حداقل تعادل (پایه کمیسیون):</MudText>
<MudText Typo="Typo.h6" Color="Color.Warning"><strong>@_weeklyBalance.MinBalanceFormatted</strong></MudText>
</MudStack>
<MudStack Row="true" Justify="Justify.SpaceBetween" AlignItems="AlignItems.Center">
<MudText Typo="Typo.body1">تعداد تعادل (دفعات):</MudText>
<MudText Typo="Typo.h6" Color="Color.Secondary"><strong>@_weeklyBalance.BalanceCount</strong></MudText>
</MudStack>
<MudDivider />
<MudStack Row="true" Justify="Justify.SpaceBetween" AlignItems="AlignItems.Center">
<MudText Typo="Typo.h6">کمیسیون محاسبه شده:</MudText>
<MudText Typo="Typo.h5" Color="Color.Primary"><strong>@_weeklyBalance.CalculatedCommissionFormatted</strong></MudText>
</MudStack>
<MudText Typo="Typo.subtitle1" Class="mb-2" Style="font-weight: bold;">محاسبات کمیسیون</MudText>
<MudSimpleTable Dense="true" Hover="true" Style="background: transparent;">
<tbody>
<tr>
<td><MudText Typo="Typo.body2">حداقل تعادل (پایه کمیسیون):</MudText></td>
<td class="text-end"><MudText Typo="Typo.body1" Color="Color.Warning"><strong>@_weeklyBalance.MinBalanceFormatted</strong></MudText></td>
</tr>
<tr>
<td><MudText Typo="Typo.body2">تعداد تعادل (دفعات):</MudText></td>
<td class="text-end"><MudText Typo="Typo.body1" Color="Color.Secondary"><strong>@_weeklyBalance.BalanceCount</strong></MudText></td>
</tr>
<tr style="background-color: var(--mud-palette-primary-lighten);">
<td><MudText Typo="Typo.subtitle1"><strong>کمیسیون محاسبه شده:</strong></MudText></td>
<td class="text-end"><MudText Typo="Typo.h6" Color="Color.Primary"><strong>@_weeklyBalance.CalculatedCommissionFormatted</strong></MudText></td>
</tr>
</tbody>
</MudSimpleTable>
@if (_weeklyBalance.LeftCarryover > 0 || _weeklyBalance.RightCarryover > 0)
{
<MudAlert Severity="Severity.Info" Variant="Variant.Outlined">
<MudText Typo="Typo.body2">
<strong>Carryover (انتقال به هفته بعد):</strong><br />
چپ: @_weeklyBalance.LeftCarryoverFormatted | راست: @_weeklyBalance.RightCarryoverFormatted
</MudText>
</MudAlert>
}
</MudStack>
</MudPaper>
<!-- نمودار مقایسه -->
<MudPaper Elevation="2" Class="pa-4 rounded-lg">
<MudText Typo="Typo.h6" Class="mb-3">نمودار مقایسه</MudText>
<MudChart ChartType="ChartType.Bar"
Width="100%"
Height="300px"
InputData="@(new double[] { _weeklyBalance.LeftBalance, _weeklyBalance.RightBalance, _weeklyBalance.MinBalance })"
InputLabels="@(new[] { "چپ", "راست", "حداقل" })"
ChartOptions="@_chartOptions" />
@if (_weeklyBalance.LeftCarryover > 0 || _weeklyBalance.RightCarryover > 0)
{
<MudAlert Severity="Severity.Info" Variant="Variant.Text" Dense="true" Class="mt-2">
<strong>انتقال به هفته بعد:</strong> چپ: @_weeklyBalance.LeftCarryoverFormatted | راست: @_weeklyBalance.RightCarryoverFormatted
</MudAlert>
}
</MudPaper>
}
else if (_hasError)
@@ -1,4 +1,5 @@
using FrontOffice.Main.Utilities;
using FrontOffice.Main.Shared;
using Microsoft.AspNetCore.Components;
using MudBlazor;
@@ -7,13 +8,15 @@ namespace FrontOffice.Main.Pages.Commission;
public partial class WeeklyBalancePage : ComponentBase
{
[Inject] private CommissionService CommissionService { get; set; } = default!;
[Inject] private ISnackbar SnackbarService { get; set; } = default!;
[Parameter]
[SupplyParameterFromQuery(Name = "week")]
public int? QueryWeekNumber { get; set; }
public string? QueryWeekNumber { get; set; }
private WeekSelector? _weekSelector;
private WeekDefinitionDto? _selectedWeekDefinition;
private WeeklyBalanceDto? _weeklyBalance;
private int? _selectedWeekNumber;
private bool _isLoading = true;
private bool _hasError = false;
@@ -27,12 +30,44 @@ public partial class WeeklyBalancePage : ComponentBase
}
};
protected override async Task OnInitializedAsync()
protected override async Task OnAfterRenderAsync(bool firstRender)
{
if (QueryWeekNumber.HasValue)
_selectedWeekNumber = QueryWeekNumber;
if (firstRender)
{
// Wait for WeekSelector to initialize and load its cached weeks
if (_weekSelector != null)
{
await _weekSelector.EnsureLoadedAsync();
// Handle query parameter ?week=46 (WeekOrder) or ?week=123 (Id)
if (!string.IsNullOrEmpty(QueryWeekNumber))
{
// Try to parse as integer (first try as WeekOrder, then as Id)
if (int.TryParse(QueryWeekNumber, out int weekOrder))
{
_selectedWeekDefinition = _weekSelector.FindByWeekOrder(weekOrder);
if (_selectedWeekDefinition == null && long.TryParse(QueryWeekNumber, out long id))
{
_selectedWeekDefinition = _weekSelector.FindById(id);
}
}
}
// If no week selected and no query param, select current week
if (_selectedWeekDefinition == null)
{
_selectedWeekDefinition = _weekSelector.GetCurrentWeek();
}
StateHasChanged();
await LoadWeeklyBalanceAsync();
}
}
}
await LoadWeeklyBalanceAsync();
protected override void OnInitialized()
{
_isLoading = true;
}
private async Task LoadWeeklyBalanceAsync()
@@ -41,12 +76,27 @@ public partial class WeeklyBalancePage : ComponentBase
{
_isLoading = true;
_hasError = false;
_weeklyBalance = await CommissionService.GetMyWeeklyBalanceAsync(_selectedWeekNumber);
long? weekDefinitionId = _selectedWeekDefinition?.Id;
_weeklyBalance = await CommissionService.GetMyWeeklyBalanceAsync(weekDefinitionId);
// Update week display name from selected definition if available
if (_selectedWeekDefinition != null && _weeklyBalance != null)
{
_weeklyBalance.WeekDisplayName = _selectedWeekDefinition.DisplayName;
return;
}
_weeklyBalance = new WeeklyBalanceDto()
{
};
}
catch (Exception ex)
{
_hasError = true;
Snackbar.Add($"خطا در دریافت تعادل: {ex.Message}", Severity.Error);
SnackbarService.Add($"خطا در دریافت تعادل: {ex.Message}", Severity.Error);
}
finally
{
@@ -56,7 +106,11 @@ public partial class WeeklyBalancePage : ComponentBase
private async Task LoadCurrentWeekAsync()
{
_selectedWeekNumber = null;
if (_weekSelector != null)
{
await _weekSelector.SelectCurrentWeekAsync();
}
_selectedWeekDefinition = _weekSelector?.GetCurrentWeek();
await LoadWeeklyBalanceAsync();
}
@@ -192,6 +192,17 @@
</MudCard>
</MudLink>
</MudItem>
<MudItem xs="6" sm="6" md="3">
<MudLink Href="@RouteConstants.Profile.WithdrawalRequests" Underline="Underline.None" Class="tile-link">
<MudCard Elevation="1" Class="rounded-lg profile-tile">
<MudCardContent Class="d-flex flex-column align-center pa-4">
<MudIcon Icon="@Icons.Material.Filled.RequestPage" Size="Size.Large" Color="Color.Warning" />
<MudText Typo="Typo.subtitle1" Class="mt-2">درخواست برداشت</MudText>
<MudText Typo="Typo.caption" Class="mud-text-secondary">ثبت و پیگیری برداشت</MudText>
</MudCardContent>
</MudCard>
</MudLink>
</MudItem>
<MudItem xs="6" sm="6" md="3">
<MudLink Href="@RouteConstants.Club.Membership" Underline="Underline.None" Class="tile-link">
<MudCard Elevation="1" Class="rounded-lg profile-tile">
+38 -103
View File
@@ -17,14 +17,9 @@
</MudPaper>
</MudItem>
<MudItem xs="12" sm="6" md="4">
<MudPaper Elevation="2" Class="pa-4 rounded-lg" Style="background-color: var(--mud-palette-warning-lighten);">
<MudStack Row="true" AlignItems="AlignItems.Center" Spacing="2">
<MudIcon Icon="@Icons.Material.Filled.Discount" Color="Color.Warning" Size="Size.Large" />
<MudStack Spacing="0">
<MudText Typo="Typo.subtitle2" Style="color: var(--mud-palette-warning-darken);">موجودی تخفیف باشگاه</MudText>
<MudText Typo="Typo.h4" Style="color: var(--mud-palette-warning-darken);"><strong>@_balances.Discount</strong></MudText>
</MudStack>
</MudStack>
<MudPaper Elevation="2" Class="pa-4 rounded-lg">
<MudText Typo="Typo.subtitle2" Class="mud-text-secondary">موجودی فروشگاه تخفیفی</MudText>
<MudText Typo="Typo.h4" Color="Color.Warning">@_balances.Discount</MudText>
</MudPaper>
</MudItem>
<MudItem xs="12" sm="6" md="4">
@@ -35,61 +30,45 @@
</MudItem>
</MudGrid>
<MudPaper Elevation="2" Class="pa-4 rounded-lg">
<MudText Typo="Typo.h6" Class="mb-2">درخواست برداشت از موجودی شبکه</MudText>
<MudStack Spacing="2">
<MudTextField @bind-Value="_withdrawPayoutId"
Label="شناسه واریز (PayoutId)"
Variant="Variant.Outlined"
Type="MudBlazor.InputType.Number"
Required="true" />
<MudRadioGroup T="WithdrawalMethodClient" @bind-SelectedOption="_withdrawMethod" Row="true">
<MudRadio T="WithdrawalMethodClient" Option="@WithdrawalMethodClient.Cash" Label="برداشت نقدی (نیاز به شبا)" />
<MudRadio T="WithdrawalMethodClient" Option="@WithdrawalMethodClient.Diamond" Label="الماس/غیرنقدی" />
</MudRadioGroup>
<MudTextField @bind-Value="_withdrawIban"
Label="شماره شبا"
Variant="Variant.Outlined"
Disabled="_withdrawMethod == WithdrawalMethodClient.Diamond"
Placeholder="IRxxxxxxxxxxxx"
Adornment="Adornment.Start"
AdornmentText="IR" />
<MudText Typo="Typo.caption" Class="mud-text-secondary">
حداقل مبلغ برداشت: @FormatPrice(_minWithdrawalAmount)
</MudText>
<MudButton Disabled="_isSubmittingWithdrawal"
Variant="Variant.Filled"
Color="Color.Primary"
StartIcon="@Icons.Material.Filled.Outbound"
OnClick="SubmitWithdrawal">
@(_isSubmittingWithdrawal ? "در حال ثبت..." : "ثبت درخواست برداشت")
</MudButton>
</MudStack>
</MudPaper>
<!-- دکمه دسترسی سریع به درخواست برداشت -->
<MudButton Variant="Variant.Filled"
Color="Color.Warning"
Size="Size.Large"
FullWidth="true"
StartIcon="@Icons.Material.Filled.RequestPage"
Href="@RouteConstants.Profile.WithdrawalRequests"
Class="rounded-lg">
درخواست‌های برداشت
</MudButton>
<MudPaper Elevation="2" Class="pa-4 rounded-lg">
<MudText Typo="Typo.h6" Class="mb-2">تراکنش‌ها و مسیرهای شارژ</MudText>
<MudStack Row="true" Spacing="2" Class="mb-3" AlignItems="AlignItems.End">
<MudTextField @bind-Value="_filterReferenceId"
Label="شناسه ارجاع"
Variant="Variant.Outlined"
Adornment="Adornment.Start"
AdornmentIcon="@Icons.Material.Filled.Search" />
<MudSelect T="string" @bind-Value="_filterType" Label="نوع تراکنش" Variant="Variant.Outlined">
<MudSelectItem T="string" Value="@("all")">همه</MudSelectItem>
<MudSelectItem T="string" Value="@("in")">ورودی (شارژ)</MudSelectItem>
<MudSelectItem T="string" Value="@("out")">خروجی (برداشت/خرید)</MudSelectItem>
</MudSelect>
<MudSelect T="string" @bind-Value="_withdrawStatusFilter" Label="وضعیت برداشت" Variant="Variant.Outlined">
<MudSelectItem T="string" Value="@("all")">همه</MudSelectItem>
<MudSelectItem T="string" Value="@("pending")">Pending</MudSelectItem>
<MudSelectItem T="string" Value="@("requested")">Requested</MudSelectItem>
<MudSelectItem T="string" Value="@("withdrawn")">Withdrawn</MudSelectItem>
<MudSelectItem T="string" Value="@("cancelled")">Cancelled</MudSelectItem>
</MudSelect>
<MudButton Variant="Variant.Outlined" OnClick="ApplyFilters" StartIcon="@Icons.Material.Filled.FilterList">اعمال فیلتر</MudButton>
</MudStack>
<MudGrid Spacing="2" Class="mb-3">
<MudItem xs="6" md="4">
<MudTextField @bind-Value="_filterReferenceId"
Label="شناسه ارجاع"
Variant="Variant.Outlined"
Adornment="Adornment.Start"
AdornmentIcon="@Icons.Material.Filled.Search"
FullWidth="true" />
</MudItem>
<MudItem xs="6" md="4">
<MudSelect T="string" @bind-Value="_filterType" Label="نوع تراکنش" Variant="Variant.Outlined" FullWidth="true">
<MudSelectItem T="string" Value="@("all")">همه</MudSelectItem>
<MudSelectItem T="string" Value="@("in")">ورودی (شارژ)</MudSelectItem>
<MudSelectItem T="string" Value="@("out")">خروجی (برداشت/خرید)</MudSelectItem>
</MudSelect>
</MudItem>
<MudItem xs="12" md="4" Class="d-flex align-end">
<MudButton Variant="Variant.Outlined"
OnClick="ApplyFilters"
StartIcon="@Icons.Material.Filled.FilterList"
FullWidth="true">
اعمال فیلتر
</MudButton>
</MudItem>
</MudGrid>
<MudHidden Breakpoint="Breakpoint.MdAndUp" Invert="true">
<MudTable Items="_txs" Dense="true">
@@ -126,49 +105,5 @@
</MudStack>
</MudHidden>
</MudPaper>
<MudPaper Elevation="2" Class="pa-4 rounded-lg">
<MudText Typo="Typo.h6" Class="mb-2">درخواست‌های برداشت ثبت‌شده</MudText>
<MudHidden Breakpoint="Breakpoint.MdAndUp" Invert="true">
<MudTable Items="_withdrawals" Dense="true">
<HeaderContent>
<MudTh>هفته</MudTh>
<MudTh>مبلغ</MudTh>
<MudTh>وضعیت</MudTh>
<MudTh>روش</MudTh>
<MudTh>تاریخ</MudTh>
</HeaderContent>
<RowTemplate>
<MudTd>@context.WeekNumber</MudTd>
<MudTd>@FormatPrice(context.Amount)</MudTd>
<MudTd>
<MudChip T="string" Color="@(ResolveStatusColor(context.Status))" Variant="Variant.Outlined" Size="Size.Small">
@ResolveStatusText(context.Status)
</MudChip>
</MudTd>
<MudTd>@ResolveMethodText(context.Method)</MudTd>
<MudTd>@context.Created</MudTd>
</RowTemplate>
</MudTable>
</MudHidden>
<MudHidden Breakpoint="Breakpoint.MdAndUp">
<MudStack Spacing="2">
@foreach (var wd in _withdrawals)
{
<MudPaper Class="pa-3 rounded-lg" Outlined="true">
<MudStack Spacing="1">
<MudStack Row="true" Justify="Justify.SpaceBetween" AlignItems="AlignItems.Center">
<MudText>@wd.WeekNumber</MudText>
<MudText Color="Color.Primary">@FormatPrice(wd.Amount)</MudText>
</MudStack>
<MudText Typo="Typo.caption" Class="mud-text-secondary">وضعیت: @ResolveStatusText(wd.Status) | روش: @ResolveMethodText(wd.Method)</MudText>
<MudText Typo="Typo.caption" Class="mud-text-secondary">@wd.Created</MudText>
</MudStack>
</MudPaper>
}
</MudStack>
</MudHidden>
</MudPaper>
</MudStack>
</MudContainer>
@@ -6,71 +6,20 @@ namespace FrontOffice.Main.Pages.Profile;
public partial class Wallet : ComponentBase
{
private long _minWithdrawalAmount = 1_000_000; // مقدار پیش‌فرض، از CMS خوانده می‌شود
private (string Credit, string Discount, string Network) _balances = ("-", "-", "-");
private List<WalletTransaction> _txs = new();
private List<WalletWithdrawal> _withdrawals = new();
private string? _filterReferenceId;
private string _filterType = "all";
private string _withdrawStatusFilter = "all";
private bool _isSubmittingWithdrawal;
private long _withdrawPayoutId;
private WithdrawalMethodClient _withdrawMethod = WithdrawalMethodClient.Cash;
private string? _withdrawIban;
protected override async Task OnInitializedAsync()
{
var b = await WalletService.GetBalancesAsync();
_balances = (FormatPrice(b.CreditBalance), FormatPrice(b.DiscountBalance), FormatPrice(b.NetworkBalance));
_txs = await WalletService.GetTransactionsAsync();
_withdrawals = await WalletService.GetWithdrawalsAsync();
var settings = await WalletService.GetWithdrawalSettingsAsync();
if (settings.MinWithdrawalAmount > 0)
_minWithdrawalAmount = settings.MinWithdrawalAmount;
}
private static string FormatPrice(long price) => string.Format("{0:N0} تومان", price);
private async Task SubmitWithdrawal()
{
var target = _withdrawals.FirstOrDefault(x => x.Id == _withdrawPayoutId);
if (target is null)
{
_withdrawals = await WalletService.GetWithdrawalsAsync();
target = _withdrawals.FirstOrDefault(x => x.Id == _withdrawPayoutId);
}
if (target != null && target.Amount < _minWithdrawalAmount)
{
Snackbar.Add($"مبلغ این واریز کمتر از حداقل برداشت ({_minWithdrawalAmount:N0} تومان) است.", Severity.Warning);
return;
}
if (_withdrawPayoutId <= 0)
{
Snackbar.Add("شناسه واریز (PayoutId) الزامی است.", Severity.Warning);
return;
}
if (_withdrawMethod == WithdrawalMethodClient.Cash && string.IsNullOrWhiteSpace(_withdrawIban))
{
Snackbar.Add("برای برداشت نقدی، شماره شبا لازم است.", Severity.Warning);
return;
}
try
{
_isSubmittingWithdrawal = true;
await WalletService.RequestWithdrawalAsync(_withdrawPayoutId, _withdrawMethod, _withdrawIban);
Snackbar.Add("درخواست برداشت ثبت شد.", Severity.Success);
}
catch (Exception ex)
{
Snackbar.Add($"خطا در ثبت برداشت: {ex.Message}", Severity.Error);
}
finally
{
_isSubmittingWithdrawal = false;
}
}
private async Task ApplyFilters()
{
long? refId = null;
@@ -85,39 +34,5 @@ public partial class Wallet : ComponentBase
_ => null
};
_txs = await WalletService.GetTransactionsAsync(refId, isIncrease);
int? status = _withdrawStatusFilter switch
{
"pending" => 1,
"requested" => 2,
"withdrawn" => 3,
"cancelled" => 4,
_ => null
};
_withdrawals = await WalletService.GetWithdrawalsAsync(status);
}
private static string ResolveStatusText(int status) => status switch
{
0 => "ایجاد شده",
1 => "پرداخت شده",
2 => "درخواست برداشت",
3 => "برداشت شده",
4 => "لغو شده",
_ => status.ToString()
};
private static Color ResolveStatusColor(int status) => status switch
{
2 => Color.Warning,
3 => Color.Success,
4 => Color.Error,
_ => Color.Info
};
private static string ResolveMethodText(int? method) => method switch
{
0 => "نقدی",
1 => "الماس",
_ => "-"
};
}
@@ -0,0 +1,125 @@
@attribute [Route(RouteConstants.Profile.WithdrawalRequests)]
<PageTitle>درخواست‌های برداشت</PageTitle>
<MudContainer MaxWidth="MaxWidth.Large" Class="py-6">
<MudStack Spacing="3">
<MudStack Row="true" Justify="Justify.SpaceBetween" AlignItems="AlignItems.Center">
<MudText Typo="Typo.h5">درخواست‌های برداشت</MudText>
<MudButton Variant="Variant.Text" StartIcon="@Icons.Material.Filled.ArrowBack" Href="@RouteConstants.Profile.Wallet">بازگشت به کیف پول</MudButton>
</MudStack>
<!-- فرم درخواست برداشت جدید -->
<MudPaper Elevation="2" Class="pa-4 rounded-lg">
<MudText Typo="Typo.h6" Class="mb-2">ثبت درخواست برداشت جدید</MudText>
<MudStack Spacing="2">
<MudTextField @bind-Value="_withdrawPayoutId"
Label="شناسه واریز (PayoutId)"
Variant="Variant.Outlined"
Type="MudBlazor.InputType.Number"
Required="true" />
<MudRadioGroup T="WithdrawalMethodClient" @bind-Value="_withdrawMethod" Row="true">
<MudRadio T="WithdrawalMethodClient" Option="@WithdrawalMethodClient.Cash" Color="Color.Primary">برداشت نقدی (نیاز به شبا)</MudRadio>
<MudRadio T="WithdrawalMethodClient" Option="@WithdrawalMethodClient.Diamond" Color="Color.Secondary">الماس/غیرنقدی</MudRadio>
</MudRadioGroup>
<MudTextField @bind-Value="_withdrawIban"
Label="شماره شبا"
Variant="Variant.Outlined"
Disabled="_withdrawMethod == WithdrawalMethodClient.Diamond"
Placeholder="IRxxxxxxxxxxxx"
Adornment="Adornment.Start"
AdornmentText="IR" />
<MudText Typo="Typo.caption" Class="mud-text-secondary">
حداقل مبلغ برداشت: @FormatPrice(_minWithdrawalAmount)
</MudText>
<MudButton Disabled="_isSubmittingWithdrawal"
Variant="Variant.Filled"
Color="Color.Primary"
StartIcon="@Icons.Material.Filled.Outbound"
OnClick="SubmitWithdrawal">
@(_isSubmittingWithdrawal ? "در حال ثبت..." : "ثبت درخواست برداشت")
</MudButton>
</MudStack>
</MudPaper>
<!-- فیلتر وضعیت -->
<MudPaper Elevation="2" Class="pa-4 rounded-lg">
<MudStack Row="true" Spacing="2" AlignItems="AlignItems.End">
<MudSelect T="string" @bind-Value="_statusFilter" Label="فیلتر وضعیت" Variant="Variant.Outlined" Style="min-width: 180px;">
<MudSelectItem T="string" Value="@("all")">همه</MudSelectItem>
<MudSelectItem T="string" Value="@("pending")">در انتظار</MudSelectItem>
<MudSelectItem T="string" Value="@("requested")">درخواست شده</MudSelectItem>
<MudSelectItem T="string" Value="@("withdrawn")">برداشت شده</MudSelectItem>
<MudSelectItem T="string" Value="@("cancelled")">لغو شده</MudSelectItem>
</MudSelect>
<MudButton Variant="Variant.Outlined" OnClick="ApplyFilter" StartIcon="@Icons.Material.Filled.FilterList">اعمال فیلتر</MudButton>
</MudStack>
</MudPaper>
<!-- لیست درخواست‌های برداشت -->
<MudPaper Elevation="2" Class="pa-4 rounded-lg">
<MudText Typo="Typo.h6" Class="mb-3">لیست درخواست‌ها</MudText>
@if (_isLoading)
{
<MudProgressLinear Color="Color.Primary" Indeterminate="true" />
}
else if (!_withdrawals.Any())
{
<MudAlert Severity="Severity.Info" Variant="Variant.Outlined">
هنوز درخواست برداشتی ثبت نشده است.
</MudAlert>
}
else
{
<!-- نمایش دسکتاپ -->
<MudHidden Breakpoint="Breakpoint.MdAndUp" Invert="true">
<MudTable Items="_withdrawals" Dense="true" Hover="true" Striped="true">
<HeaderContent>
<MudTh>هفته</MudTh>
<MudTh>مبلغ</MudTh>
<MudTh>وضعیت</MudTh>
<MudTh>روش برداشت</MudTh>
<MudTh>تاریخ ثبت</MudTh>
</HeaderContent>
<RowTemplate>
<MudTd DataLabel="هفته">@context.WeekDisplayName</MudTd>
<MudTd DataLabel="مبلغ">@FormatPrice(context.Amount)</MudTd>
<MudTd DataLabel="وضعیت">
<MudChip T="string" Color="@(ResolveStatusColor(context.Status))" Variant="Variant.Filled" Size="Size.Small">
@ResolveStatusText(context.Status)
</MudChip>
</MudTd>
<MudTd DataLabel="روش">@ResolveMethodText(context.Method)</MudTd>
<MudTd DataLabel="تاریخ">@context.Created</MudTd>
</RowTemplate>
</MudTable>
</MudHidden>
<!-- نمایش موبایل -->
<MudHidden Breakpoint="Breakpoint.MdAndUp">
<MudStack Spacing="2">
@foreach (var wd in _withdrawals)
{
<MudPaper Class="pa-3 rounded-lg" Outlined="true">
<MudStack Spacing="1">
<MudStack Row="true" Justify="Justify.SpaceBetween" AlignItems="AlignItems.Center">
<MudText Typo="Typo.subtitle2">@wd.WeekDisplayName</MudText>
<MudChip T="string" Color="@(ResolveStatusColor(wd.Status))" Variant="Variant.Filled" Size="Size.Small">
@ResolveStatusText(wd.Status)
</MudChip>
</MudStack>
<MudStack Row="true" Justify="Justify.SpaceBetween" AlignItems="AlignItems.Center">
<MudText Typo="Typo.h6" Color="Color.Primary">@FormatPrice(wd.Amount)</MudText>
<MudText Typo="Typo.caption" Class="mud-text-secondary">@ResolveMethodText(wd.Method)</MudText>
</MudStack>
<MudText Typo="Typo.caption" Class="mud-text-secondary">@wd.Created</MudText>
</MudStack>
</MudPaper>
}
</MudStack>
</MudHidden>
}
</MudPaper>
</MudStack>
</MudContainer>
@@ -0,0 +1,123 @@
using FrontOffice.Main.Utilities;
using Microsoft.AspNetCore.Components;
using MudBlazor;
namespace FrontOffice.Main.Pages.Profile;
public partial class WithdrawalRequests : ComponentBase
{
private long _minWithdrawalAmount = 1_000_000;
private List<WalletWithdrawal> _withdrawals = new();
private string _statusFilter = "all";
private bool _isLoading = true;
private bool _isSubmittingWithdrawal;
private long _withdrawPayoutId;
private WithdrawalMethodClient _withdrawMethod = WithdrawalMethodClient.Cash;
private string? _withdrawIban;
protected override async Task OnInitializedAsync()
{
await LoadData();
}
private async Task LoadData()
{
_isLoading = true;
try
{
_withdrawals = await WalletService.GetWithdrawalsAsync();
var settings = await WalletService.GetWithdrawalSettingsAsync();
if (settings.MinWithdrawalAmount > 0)
_minWithdrawalAmount = settings.MinWithdrawalAmount;
}
finally
{
_isLoading = false;
}
}
private static string FormatPrice(long price) => string.Format("{0:N0} تومان", price);
private async Task SubmitWithdrawal()
{
if (_withdrawPayoutId <= 0)
{
Snackbar.Add("شناسه واریز (PayoutId) الزامی است.", Severity.Warning);
return;
}
if (_withdrawMethod == WithdrawalMethodClient.Cash && string.IsNullOrWhiteSpace(_withdrawIban))
{
Snackbar.Add("برای برداشت نقدی، شماره شبا لازم است.", Severity.Warning);
return;
}
try
{
_isSubmittingWithdrawal = true;
await WalletService.RequestWithdrawalAsync(_withdrawPayoutId, _withdrawMethod, _withdrawIban);
Snackbar.Add("درخواست برداشت ثبت شد.", Severity.Success);
// بروزرسانی لیست
await LoadData();
// ریست فرم
_withdrawPayoutId = 0;
_withdrawIban = null;
}
catch (Exception ex)
{
Snackbar.Add($"خطا در ثبت برداشت: {ex.Message}", Severity.Error);
}
finally
{
_isSubmittingWithdrawal = false;
}
}
private async Task ApplyFilter()
{
_isLoading = true;
try
{
int? status = _statusFilter switch
{
"pending" => 1,
"requested" => 2,
"withdrawn" => 3,
"cancelled" => 4,
_ => null
};
_withdrawals = await WalletService.GetWithdrawalsAsync(status);
}
finally
{
_isLoading = false;
}
}
private static string ResolveStatusText(int status) => status switch
{
0 => "ایجاد شده",
1 => "در انتظار پرداخت",
2 => "درخواست برداشت",
3 => "برداشت شده",
4 => "لغو شده",
_ => status.ToString()
};
private static Color ResolveStatusColor(int status) => status switch
{
1 => Color.Info,
2 => Color.Warning,
3 => Color.Success,
4 => Color.Error,
_ => Color.Default
};
private static string ResolveMethodText(int? method) => method switch
{
0 => "نقدی (شبا)",
1 => "الماس",
_ => "-"
};
}
+10 -1
View File
@@ -16,7 +16,16 @@ public partial class Cart : ComponentBase, IDisposable
// لود سبد خرید (فقط اگر کاربر لاگین کرده باشد)
await CartService.EnsureInitializedAsync();
CartService.OnChange += StateHasChanged;
await VAT.LoadAsync();
}
protected override async Task OnAfterRenderAsync(bool firstRender)
{
if (firstRender)
{
// بارگذاری نرخ VAT
await VAT.LoadAsync();
}
await base.OnAfterRenderAsync(firstRender);
}
private async Task IncrementQty(long productId)
@@ -30,7 +30,16 @@ public partial class CheckoutSummary : ComponentBase
await Cart.EnsureInitializedAsync();
await LoadAddresses();
await LoadWalletBalance();
await VAT.LoadAsync();
}
protected override async Task OnAfterRenderAsync(bool firstRender)
{
if (firstRender)
{
// بارگذاری نرخ VAT
await VAT.LoadAsync();
}
await base.OnAfterRenderAsync(firstRender);
}
private async Task LoadWalletBalance()
@@ -79,7 +88,7 @@ public partial class CheckoutSummary : ComponentBase
{
var request = new SubmitShopBuyOrderRequest
{
TotalAmount = Cart.Total
TotalAmount = VAT.AddVAT(Cart.Total)
};
var response = await UserOrderContract.SubmitShopBuyOrderAsync(request);
@@ -19,7 +19,6 @@ public partial class Orders : ComponentBase
_loading = true;
try
{
await VAT.LoadAsync();
_orders = await OrderService.GetOrdersAsync();
}
catch (Exception ex)
@@ -33,6 +32,16 @@ public partial class Orders : ComponentBase
}
}
protected override async Task OnAfterRenderAsync(bool firstRender)
{
if (firstRender)
{
// بارگذاری نرخ VAT
await VAT.LoadAsync();
}
await base.OnAfterRenderAsync(firstRender);
}
private static string FormatPrice(long price) => string.Format("{0:N0} تومان", price);
@@ -30,7 +30,7 @@ public partial class ProductDetail : ComponentBase, IDisposable
private IReadOnlyList<ProductCategoryPathInfo> _categoryPaths = Array.Empty<ProductCategoryPathInfo>();
private ProductGalleryImage? _selectedGalleryImage;
private readonly List<BreadcrumbItem> _breadcrumbItems = new();
private long TotalPrice => VAT.AddVAT((_product?.Price ?? 0) * _qty);
private long TotalPrice => (_product?.Price ?? 0) * _qty;
private bool HasDiscount => _product is { Discount: > 0 and < 100 };
private long? OriginalPrice => HasDiscount && _product is not null
@@ -55,8 +55,7 @@ public partial class ProductDetail : ComponentBase, IDisposable
await Cart.EnsureInitializedAsync();
Cart.OnChange += HandleCartChanged;
// بارگذاری نرخ VAT
await VAT.LoadAsync();
_loading = true;
_product = await ProductService.GetByIdAsync(id);
@@ -80,7 +79,15 @@ public partial class ProductDetail : ComponentBase, IDisposable
await base.OnInitializedAsync();
}
protected override async Task OnAfterRenderAsync(bool firstRender)
{
await base.OnAfterRenderAsync(firstRender);
if (firstRender)
{
// بارگذاری نرخ VAT
await VAT.LoadAsync();
}
}
private async Task AddToCart()
{
@@ -26,10 +26,19 @@ public partial class Products : ComponentBase, IDisposable
await Cart.EnsureInitializedAsync();
Cart.OnChange += StateHasChanged;
Navigation.LocationChanged += HandleLocationChanged;
await VAT.LoadAsync();
await Load();
}
protected override async Task OnAfterRenderAsync(bool firstRender)
{
if (firstRender)
{
// بارگذاری نرخ VAT
await VAT.LoadAsync();
}
await base.OnAfterRenderAsync(firstRender);
}
private async Task Load()
{
_loading = true;