WIP - B2B restock

This commit is contained in:
Frede Hundewadt 2023-09-29 08:09:45 +02:00
parent 11340a95fb
commit d5b0b29cb1
2 changed files with 135 additions and 85 deletions

View file

@ -19,79 +19,100 @@
@attribute [Authorize(Roles = "EShop")] @attribute [Authorize(Roles = "EShop")]
@page "/b2b/{countryCode}/{companyId}" @page "/b2b/{countryCode}/{companyId}"
<div class="row"> <div class="row g-2 mb-2">
<div class="col-sm-12 col-md-6"> <div class="card col-md-4">
@if (!string.IsNullOrWhiteSpace(_businessInfo.Name)) <div class="card-body">
{ <h5 class="card-title">
<div class="card"> @_businessInfo.Name
<div class="card-body"> </h5>
<h5 class="card-title"> <p class="card-text">
@_businessInfo.Name <i class="bi-card-heading"></i> @_businessInfo.Account<br/>
</h5> <i class="bi-phone"></i> @_businessInfo.Phone<br/>
<p class="card-text"> <i class="bi-at"></i> @_businessInfo.Email<br/>
@_businessInfo.Address1<br/> </p>
@_businessInfo.Address2<br/> </div>
@_businessInfo.ZipCode @_businessInfo.City<br/> </div>
</p> <div class="card col-md-4">
<p class="card-text"> <div class="card-body">
<i class="bi-card-heading"></i> @_businessInfo.Account<br/> <h5 class="card-title">
<i class="bi-phone"></i> @_businessInfo.Phone<br/> Leveringsadresse
<i class="bi-at"></i> @_businessInfo.Email<br/> </h5>
</p> <p class="card-text">
</div> @_businessInfo.Address1<br/>
</div> @_businessInfo.Address2<br/>
} @_businessInfo.ZipCode @_businessInfo.City<br/>
</p>
</div>
</div>
<div class="card col-md-4">
<div class="card-body">
<h5 class="card-title">
@_advisorInfo.Name
</h5>
<p class="card-text">
<i class="bi-phone"></i> @_advisorInfo.Phone<br/>
<i class="bi-at"></i> @_advisorInfo.Email<br/>
</p>
</div>
</div> </div>
<div class="col-sm-12 col-md-6">
@if (!string.IsNullOrWhiteSpace(_advisorInfo.Name))
{
<div class="card">
<div class="card-body">
<h5 class="card-title">
@_advisorInfo.Name
</h5>
<p class="card-text">
<i class="bi-phone"></i> @_advisorInfo.Phone<br/>
<i class="bi-at"></i> @_advisorInfo.Email<br/>
</p>
</div>
</div>
}
</div>
</div> </div>
<div> @if (_productInventory.Any())
@if (_productInventory.Any()) {
{ <div class="row row-cols-1 row-cols-md-2 g-2">
<table class="table"> @foreach (var product in _productInventory)
<thead> {
<tr> <div class="card col-md-6 col-xl-4">
<th>Produkter</th> <div class="row g-0">
</tr> <div class="col-sm-3">
</thead> <img class="img-fluid rounded-start" src="@(product.PictureLink)?height=125" alt="@product.Description"
<tbody>
@foreach (var product in _productInventory)
{
<tr>
<td>
<img src="@(product.PictureLink)?height=100" alt="@product.Description"
onerror="this.onerror=null;this.src='@(_config.AssetUrl)/images/no-image.png?height=100'"/> onerror="this.onerror=null;this.src='@(_config.AssetUrl)/images/no-image.png?height=100'"/>
</td> </div>
<td>@product.LastInvoiceDate</td> <div class="col-md-9">
<td>@product.Description</td> <div class="card-body">
<td>@product.Quantity</td> <h5 class="card-title">
<td> @product.Description
<button type="button" class="btn btn-primary">Genbestil</button> </h5>
</td> <table class="table table-sm">
</tr> <thead>
} <tr>
</tbody> <th scope="col">Sidste køb</th>
</table> <th scope="col">Forbrug</th>
<B2BProductHistoryOverlay CompanyId="@CompanyId" ItemSku="" /> <th></th>
} </tr>
else </thead>
{ <tbody>
<WorkingThreeDots/> <tr>
} <td>
</div> @product.LastInvoiceDate
</td>
<td>
@product.Quantity
</td>
<td>
<a role="button" class="btn-link" @onclick="() => ShowProductHistoryOverlay(product.Sku)">
Historik
</a>
</td>
</tr>
</tbody>
</table>
<div class="mt-3 d-grid align-content-end">
<button type="button" class="btn btn-primary btn-sm"
@onclick="() => ShowProductHistoryOverlay(product.Sku)">
Genbestil
</button>
</div>
</div>
</div>
</div>
</div>
}
</div>
<B2BProductPriceHistoryOverlay CompanyId="@CompanyId" Sku="@_sku" @ref="PriceHistoryOverlay"/>
}
else
{
<WorkingThreeDots/>
}

View file

@ -3,6 +3,7 @@ using Microsoft.AspNetCore.Components;
using Microsoft.Extensions.Options; using Microsoft.Extensions.Options;
using Wonky.Client.HttpInterceptors; using Wonky.Client.HttpInterceptors;
using Wonky.Client.HttpRepository; using Wonky.Client.HttpRepository;
using Wonky.Client.Models;
using Wonky.Client.OverlayB2B; using Wonky.Client.OverlayB2B;
using Wonky.Client.Shared; using Wonky.Client.Shared;
using Wonky.Entity.Configuration; using Wonky.Entity.Configuration;
@ -18,6 +19,9 @@ public partial class BusinessCustomerLandingPage : IDisposable
// ############################################################## // ##############################################################
[Inject] public HttpInterceptorService Interceptor { get; set; } [Inject] public HttpInterceptorService Interceptor { get; set; }
[Inject] public IB2BRepository B2BRepo { get; set; } [Inject] public IB2BRepository B2BRepo { get; set; }
[Inject]
public ICountryCatalogRepository Catalog { get; set; }
[Inject] private IOptions<ApiConfig> Config { get; set; } [Inject] private IOptions<ApiConfig> Config { get; set; }
// ############################################################## // ##############################################################
@ -32,8 +36,11 @@ public partial class BusinessCustomerLandingPage : IDisposable
private List<ProductHistoryView> _productHistory = new(); private List<ProductHistoryView> _productHistory = new();
private List<ProductInventoryItemView> _productInventory = new(); private List<ProductInventoryItemView> _productInventory = new();
private ApiConfig _config = new(); private ApiConfig _config = new();
private B2BProductHistoryOverlay PriceOverlay { get; set; } private B2BProductPriceHistoryOverlay PriceHistoryOverlay { get; set; }
private string Price { get; set; } = "0"; private string _price = "0";
private string _quantity = "1";
private ItemSelect _selectedItem = new();
private string _sku = "";
protected override async Task OnInitializedAsync() protected override async Task OnInitializedAsync()
@ -47,15 +54,37 @@ public partial class BusinessCustomerLandingPage : IDisposable
if (_productInventory.Any()) if (_productInventory.Any())
{ {
_productInventory = _productInventory _productInventory = _productInventory
.OrderByDescending(x => x.LastInvoiceDate) .OrderByDescending(x => x.Quantity)
.ToList(); .ToList();
} }
} }
private void ShowPriceHistoryOverlay() private async Task AddItemToOrder(string sku)
{ {
PriceOverlay.Show(); var item = await Catalog.GetSalesItemSku(CountryCode, sku);
var history = await B2BRepo.GetCustomerProductHistory(CompanyId, sku);
var line = history
.OrderByDescending(x => x.DeliveryDate)
.Where(x => x.Price != 0).Take(1).ToList()[0];
DraftProvider.Draft.DraftId = CompanyId;
DraftProvider.Draft.Items.Add(
new DraftItem()
{
Price = line.Price,
Quantity = line.Quantity,
Discount = 0,
Sas = false,
Item = item
});
await DraftProvider.SaveChangesAsync();
}
private void ShowProductHistoryOverlay(string sku)
{
_sku = sku;
PriceHistoryOverlay.Show();
} }
@ -80,12 +109,12 @@ public partial class BusinessCustomerLandingPage : IDisposable
{ {
return; return;
} }
Price = price.ToString("N2", CultureInfo.InvariantCulture);
_price = price.ToString("N2", CultureInfo.InvariantCulture);
StateHasChanged(); StateHasChanged();
} }
public void Dispose() public void Dispose()
{ {
Interceptor.DisposeEvent(); Interceptor.DisposeEvent();