2d833605b4
Build and Deploy / build (push) Successful in 2m18s
- Added InventoryMainPage for managing inventory items with filtering options. - Created LowStockPage to display low stock items with filtering capabilities. - Developed MovementsPage to track inventory movements with detailed filtering. - Introduced WarehousesPage for managing warehouses, including creation and viewing inventory. - Enhanced backend integration with InventoryBFFContract for data retrieval. - Implemented user-friendly UI components using MudBlazor for better user experience. - Added necessary dialog components for adding stock, adjusting inventory, and viewing movements.
121 lines
3.4 KiB
C#
121 lines
3.4 KiB
C#
using Microsoft.AspNetCore.Components;
|
|
using MudBlazor;
|
|
using Foursat.BackOffice.BFF.Inventory.Protos;
|
|
using BackOffice.Pages.Inventory.Components;
|
|
using BackOffice.Common.Utilities;
|
|
|
|
namespace BackOffice.Pages.Inventory;
|
|
|
|
public partial class LowStockPage
|
|
{
|
|
[Inject] public InventoryBFFContract.InventoryBFFContractClient InventoryContract { get; set; } = default!;
|
|
|
|
private List<LowStockItemDto> _items = new();
|
|
private List<WarehouseDto> _warehouses = new();
|
|
private bool _isLoading = true;
|
|
|
|
// Filter fields
|
|
private long? _filterWarehouseId;
|
|
private ProductType _filterProductType = ProductType.Unspecified;
|
|
|
|
protected override async Task OnInitializedAsync()
|
|
{
|
|
await LoadWarehouses();
|
|
await LoadData();
|
|
}
|
|
|
|
private async Task LoadWarehouses()
|
|
{
|
|
try
|
|
{
|
|
var response = await InventoryContract.GetAllWarehousesAsync(new GetAllWarehousesRequest
|
|
{
|
|
ActiveOnly = true
|
|
});
|
|
_warehouses = response.Warehouses.ToList();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Snackbar.Add($"خطا در بارگذاری انبارها: {ex.Message}", Severity.Error);
|
|
}
|
|
}
|
|
|
|
private async Task LoadData()
|
|
{
|
|
_isLoading = true;
|
|
StateHasChanged();
|
|
|
|
try
|
|
{
|
|
var request = new GetLowStockItemsRequest
|
|
{
|
|
Count = 200, // Get up to 200 low stock items
|
|
ProductType = _filterProductType
|
|
};
|
|
|
|
if (_filterWarehouseId.HasValue)
|
|
{
|
|
request.WarehouseId = _filterWarehouseId.Value;
|
|
}
|
|
|
|
var response = await InventoryContract.GetLowStockItemsAsync(request);
|
|
_items = response.Items.ToList();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Snackbar.Add($"خطا در بارگذاری دادهها: {ex.Message}", Severity.Error);
|
|
_items = new();
|
|
}
|
|
finally
|
|
{
|
|
_isLoading = false;
|
|
StateHasChanged();
|
|
}
|
|
}
|
|
|
|
private string GetProductTypeLabel(ProductType type)
|
|
{
|
|
return type switch
|
|
{
|
|
ProductType.Regular => "محصول عادی",
|
|
ProductType.Discount => "محصول تخفیفی",
|
|
_ => "نامشخص"
|
|
};
|
|
}
|
|
|
|
private async Task OpenAddStockDialog(LowStockItemDto item)
|
|
{
|
|
var productId = item.ProductType == ProductType.Regular
|
|
? (item.ProductId ?? 0)
|
|
: (item.DiscountProductId ?? 0);
|
|
|
|
var parameters = new DialogParameters
|
|
{
|
|
["Warehouses"] = _warehouses,
|
|
["ProductIdParam"] = productId,
|
|
["ProductTypeParam"] = item.ProductType,
|
|
["ProductName"] = item.ProductName,
|
|
["WarehouseIdParam"] = item.WarehouseId
|
|
};
|
|
|
|
var dialog = await DialogService.ShowAsync<AddStockDialog>($"ورود کالا - {item.ProductName}", parameters, new DialogOptions
|
|
{
|
|
CloseButton = true,
|
|
MaxWidth = MaxWidth.Medium,
|
|
FullWidth = true
|
|
});
|
|
|
|
var result = await dialog.Result;
|
|
if (!result!.Canceled)
|
|
{
|
|
Snackbar.Add("موجودی با موفقیت اضافه شد", Severity.Success);
|
|
await LoadData();
|
|
}
|
|
}
|
|
|
|
private void GoBack()
|
|
{
|
|
Navigation.NavigateTo(RouteConstance.Inventory);
|
|
}
|
|
}
|