Files
FA_WEB/OrdersManagement/Components/Pages/Warehouse.razor

138 lines
6.0 KiB
Plaintext

@page "/Warehouse"
@using Syncfusion.Blazor.Cards
@using Syncfusion.Blazor.Grids
@using SytelineSaAppEfDataModel.Dtos
@using Syncfusion.Blazor.DropDowns
@using FilterType = Syncfusion.Blazor.Grids.FilterType
@using SelectionMode = Syncfusion.Blazor.Grids.SelectionMode
@using Syncfusion.Blazor.Navigations
@inject WarehouseService WarehouseService
@inject NavigationManager NavigationManager
<div class="h-100 d-flex justify-content-center align-items-start">
<SfCard CssClass="shadow" style="width: 100%; max-width: 1200px;">
<CardHeader>
<h3 class="text-primary">Dokumenty WZ na Magazynie</h3>
</CardHeader>
<CardContent>
<h5 class="text-primary mb-3">Klient</h5>
<SfDropDownList TValue="Guid?" TItem="WzClientDto" DataSource="@_clients" Placeholder="Wybierz Klienta">
<DropDownListFieldSettings Value="ID" Text="Name"/>
<DropDownListEvents TValue="Guid?" TItem="WzClientDto" ValueChange="OnValueChange"/>
</SfDropDownList>
@if (_isVisible)
{
<h5 class="text-primary mb-3">Dokumenty WZ</h5>
<SfGrid @ref="_grid"
AllowFiltering="true"
AllowPaging="true"
AllowSorting="true"
AllowSelection="true"
TValue="MaterialTransactionDto"
DataSource="@_dataSource"
EnableAdaptiveUI="true">
<GridColumns>
<GridColumn Field=@nameof(MaterialTransactionDto.MTGroupNum) HeaderText="Numer WZ" TextAlign="TextAlign.Center" Width="110"></GridColumn>
<GridColumn Field=@nameof(MaterialTransactionDto.CreateDate) HeaderText="Data utworzenia" TextAlign="TextAlign.Center" Width="100"></GridColumn>
<GridColumn Field=@nameof(MaterialTransactionDto.RefNum) HeaderText="Numer zamówienia" TextAlign="TextAlign.Center" Width="110"></GridColumn>
</GridColumns>
<SfToolbar>
<ToolbarItems>
<ToolbarItem Type="ItemType.Button" Text="Utwórz Packing List" Id="CreatePackingList"
PrefixIcon="e-icons e-save" OnClick="CreatePackingList"/>
</ToolbarItems>
</SfToolbar>
<GridFilterSettings Type="FilterType.Excel"/>
<GridPageSettings PageSize="10" PageSizes="@(new[] { 10, 20, 50, 100 })"/>
<GridSelectionSettings Mode="SelectionMode.Row" Type="SelectionType.Multiple"/>
</SfGrid>
}
</CardContent>
<CardFooter>
<small class="text-muted">FA Krosno Manager © @(DateTime.Now.Year)</small>
</CardFooter>
</SfCard>
</div>
@code {
private SfGrid<MaterialTransactionDto> _grid;
private IEnumerable<WzClientDto> _clients = new List<WzClientDto>();
private IEnumerable<MaterialTransactionDto> _materialTransactions = new List<MaterialTransactionDto>();
private IEnumerable<MaterialTransactionDto> _dataSource = new List<MaterialTransactionDto>();
private WzClientDto? _selectedClient;
bool _isVisible = false;
protected override async Task OnAfterRenderAsync(bool firstRender)
{
if (firstRender)
{
_clients = await WarehouseService.GetAllClientsAsync();
StateHasChanged();
}
}
private async Task OnValueChange(ChangeEventArgs<Guid?, WzClientDto> args)
{
if (args.Value.HasValue)
{
_selectedClient = args.ItemData;
_isVisible = true;
_materialTransactions = await WarehouseService.GetAllClientWzsAsync(_selectedClient.CustomerNumber, _selectedClient.CustomerSequence ?? 0);
_dataSource = _materialTransactions.GroupBy(x => x.MTGroupNum).Select(x => x.First()).ToList();
}
else
{
_selectedClient = null;
_isVisible = false;
}
StateHasChanged();
}
private async Task CreatePackingList()
{
var selectedRecords = await _grid.GetSelectedRecordsAsync();
if (selectedRecords.Any())
{
WzHeaderDto wzHeader = new WzHeaderDto
{
ID = Guid.NewGuid(),
FK_Client = _selectedClient?.ID
};
await WarehouseService.CreateWzHeaderAsync(wzHeader);
switch (_selectedClient?.Name.ToUpper())
{
case "MEYLE":
IList<WzRowMeyleDto> rows = new List<WzRowMeyleDto>();
IList<MaterialTransactionDto> materialTransactions = _materialTransactions.Where(x => selectedRecords.Any(y => y.MTGroupNum == x.MTGroupNum)).ToList();
foreach (MaterialTransactionDto materialTransactionDto in materialTransactions)
{
CustomerOrderDto customerOrder = await WarehouseService.GetCustomerOrder(materialTransactionDto.RefNum ?? string.Empty);
ItemCustDto item = await WarehouseService.GetItem(materialTransactionDto.Item ?? string.Empty, customerOrder.CustNum);
rows.Add(new WzRowMeyleDto
{
ID = Guid.NewGuid(),
Quantity = Math.Abs((int?)materialTransactionDto.Qty ?? 0),
ItemNumber = item.CustItem,
OrderNumber = customerOrder.CustPo,
WzNumber = materialTransactionDto.MTGroupNum ?? string.Empty,
FK_Header = wzHeader.ID
});
}
await WarehouseService.CreateWzRowsMeyleAsync(rows);
break;
}
NavigationManager.NavigateTo("/Warehouse/PackList/" + wzHeader.ID);
}
}
}