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
@@ -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 => "الماس",
_ => "-"
};
}