feat: implement VAT management service and integrate VAT calculations across components
This commit is contained in:
@@ -11,6 +11,7 @@ public partial class ProductDetail : ComponentBase, IDisposable
|
||||
{
|
||||
[Inject] private ProductService ProductService { get; set; } = default!;
|
||||
[Inject] private CartService Cart { get; set; } = default!;
|
||||
[Inject] private VATService VAT { get; set; } = default!;
|
||||
|
||||
[Parameter] public long id { get; set; }
|
||||
|
||||
@@ -18,12 +19,18 @@ public partial class ProductDetail : ComponentBase, IDisposable
|
||||
private bool _loading;
|
||||
private int _qty = 1;
|
||||
private const int MinQty = 1;
|
||||
private const int MaxQty = 20;
|
||||
|
||||
// حداکثر تعداد قابل خرید بر اساس موجودی انبار
|
||||
private int MaxQty => _product?.RemainingCount > 0 ? _product.RemainingCount : 0;
|
||||
|
||||
// آیا محصول موجود است
|
||||
private bool IsInStock => _product is not null && _product.RemainingCount > 0;
|
||||
|
||||
private IReadOnlyList<ProductGalleryImage> _galleryItems = Array.Empty<ProductGalleryImage>();
|
||||
private IReadOnlyList<ProductCategoryPathInfo> _categoryPaths = Array.Empty<ProductCategoryPathInfo>();
|
||||
private ProductGalleryImage? _selectedGalleryImage;
|
||||
private readonly List<BreadcrumbItem> _breadcrumbItems = new();
|
||||
private long TotalPrice => (_product?.Price ?? 0) * _qty;
|
||||
private long TotalPrice => VAT.AddVAT((_product?.Price ?? 0) * _qty);
|
||||
private bool HasDiscount => _product is { Discount: > 0 and < 100 };
|
||||
|
||||
private long? OriginalPrice => HasDiscount && _product is not null
|
||||
@@ -44,8 +51,13 @@ public partial class ProductDetail : ComponentBase, IDisposable
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
// لود سبد خرید (فقط اگر کاربر لاگین کرده باشد)
|
||||
await Cart.EnsureInitializedAsync();
|
||||
Cart.OnChange += HandleCartChanged;
|
||||
|
||||
// بارگذاری نرخ VAT
|
||||
await VAT.LoadAsync();
|
||||
|
||||
_loading = true;
|
||||
_product = await ProductService.GetByIdAsync(id);
|
||||
_loading = false;
|
||||
@@ -127,7 +139,9 @@ public partial class ProductDetail : ComponentBase, IDisposable
|
||||
Cart.OnChange -= HandleCartChanged;
|
||||
}
|
||||
|
||||
private static string FormatPrice(long price) => string.Format("{0:N0} تومان", price);
|
||||
private string FormatPrice(long price) => $"{VAT.AddVAT(price):N0} تومان";
|
||||
|
||||
private string FormatPriceWithoutVAT(long price) => $"{price:N0} تومان";
|
||||
|
||||
private static IReadOnlyList<ProductGalleryImage> BuildGalleryItems(Product product)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user