WIP: office create order
This commit is contained in:
parent
3d4f463927
commit
1cbc87381d
3 changed files with 121 additions and 5 deletions
|
@ -54,7 +54,7 @@ public class CountryActivityRepository : ICountryActivityRepository
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="activityId"></param>
|
/// <param name="activityId"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public async Task<ActivityDto> GetActivity(string activityId)
|
public async Task<ActivityDto> RequestActivity(string activityId)
|
||||||
{
|
{
|
||||||
var activity = await _client
|
var activity = await _client
|
||||||
.GetFromJsonAsync<ActivityDto>($"{_api.CrmActivities}/{activityId}");
|
.GetFromJsonAsync<ActivityDto>($"{_api.CrmActivities}/{activityId}");
|
||||||
|
@ -76,4 +76,13 @@ public class CountryActivityRepository : ICountryActivityRepository
|
||||||
? new List<ReportItemView>()
|
? new List<ReportItemView>()
|
||||||
: JsonSerializer.Deserialize<List<ReportItemView>>(content, _options);
|
: JsonSerializer.Deserialize<List<ReportItemView>>(content, _options);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task<ApiResponseView> CreatePhoneOrder(string customerId, ActivityDto activity)
|
||||||
|
{
|
||||||
|
var response = await _client.PostAsJsonAsync($"{_api.OfficeCustomers}/{activity.CountryCode}/id/{customerId}/activities", activity);
|
||||||
|
var content = await response.Content.ReadAsStringAsync();
|
||||||
|
return string.IsNullOrWhiteSpace(content)
|
||||||
|
? new ApiResponseView { Code = 0, Id = "", IsSuccess = false, Message = "Ukendt fejl er opstået." }
|
||||||
|
: JsonSerializer.Deserialize<ApiResponseView>(content, _options);
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -29,7 +29,7 @@ public interface ICountryActivityRepository
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="activityId"></param>
|
/// <param name="activityId"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
Task<ActivityDto> GetActivity(string activityId);
|
Task<ActivityDto> RequestActivity(string activityId);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Get activities for customer Id
|
/// Get activities for customer Id
|
||||||
|
@ -37,4 +37,6 @@ public interface ICountryActivityRepository
|
||||||
/// <param name="customerId"></param>
|
/// <param name="customerId"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
Task<List<ReportItemView>> RequestActivityList(string customerId);
|
Task<List<ReportItemView>> RequestActivityList(string customerId);
|
||||||
|
|
||||||
|
Task<ApiResponseView> CreatePhoneOrder(string customerId, ActivityDto activity);
|
||||||
}
|
}
|
|
@ -16,13 +16,16 @@
|
||||||
|
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
|
using Blazored.Toast.Services;
|
||||||
using Microsoft.AspNetCore.Components;
|
using Microsoft.AspNetCore.Components;
|
||||||
using Microsoft.AspNetCore.Components.Forms;
|
using Microsoft.AspNetCore.Components.Forms;
|
||||||
|
using Wonky.Client.Helpers;
|
||||||
using Wonky.Client.HttpInterceptors;
|
using Wonky.Client.HttpInterceptors;
|
||||||
using Wonky.Client.HttpRepository;
|
using Wonky.Client.HttpRepository;
|
||||||
using Wonky.Client.Models;
|
using Wonky.Client.Models;
|
||||||
using Wonky.Client.OverlayOffice;
|
using Wonky.Client.OverlayOffice;
|
||||||
using Wonky.Client.OverlayOrderCreate;
|
using Wonky.Client.OverlayOrderCreate;
|
||||||
|
using Wonky.Client.Services;
|
||||||
using Wonky.Client.Shared;
|
using Wonky.Client.Shared;
|
||||||
using Wonky.Entity.DTO;
|
using Wonky.Entity.DTO;
|
||||||
using Wonky.Entity.Views;
|
using Wonky.Entity.Views;
|
||||||
|
@ -35,12 +38,15 @@ public partial class OfficeOrderCreatePage : IDisposable
|
||||||
// --------------------------------------------------------------------
|
// --------------------------------------------------------------------
|
||||||
// injected services
|
// injected services
|
||||||
[Inject] public ILogger<OfficeOrderCreatePage> Logger { get; set; }
|
[Inject] public ILogger<OfficeOrderCreatePage> Logger { get; set; }
|
||||||
|
[Inject] public IToastService Toaster { get; set; }
|
||||||
[Inject] public HttpInterceptorService Interceptor { get; set; }
|
[Inject] public HttpInterceptorService Interceptor { get; set; }
|
||||||
[Inject] public ICountryCatalogRepository Catalog { get; set; }
|
[Inject] public ICountryCatalogRepository Catalog { get; set; }
|
||||||
[Inject] public ICountryCustomerRepository CustomerRepo { get; set; }
|
[Inject] public ICountryCustomerRepository CustomerRepo { get; set; }
|
||||||
[Inject] public ICountryCustomerHistoryRepository HistoryRepo { get; set; }
|
[Inject] public ICountryCustomerHistoryRepository HistoryRepo { get; set; }
|
||||||
[Inject] public ICountryActivityRepository ActivityRepo { get; set; }
|
[Inject] public ICountryActivityRepository ActivityRepo { get; set; }
|
||||||
[Inject] public ISystemUserRepository UserRepo { get; set; }
|
[Inject] public ISystemUserRepository UserRepo { get; set; }
|
||||||
|
[Inject] public NavigationManager Navigator { get; set; }
|
||||||
|
[Inject] public IUserInfoService UserInfoService { get; set; }
|
||||||
|
|
||||||
// --------------------------------------------------------------------
|
// --------------------------------------------------------------------
|
||||||
// parameters
|
// parameters
|
||||||
|
@ -53,6 +59,7 @@ public partial class OfficeOrderCreatePage : IDisposable
|
||||||
private readonly JsonSerializerOptions _options = new() {PropertyNameCaseInsensitive = true};
|
private readonly JsonSerializerOptions _options = new() {PropertyNameCaseInsensitive = true};
|
||||||
// class objects
|
// class objects
|
||||||
private CompanyDto Company { get; set; } = new();
|
private CompanyDto Company { get; set; } = new();
|
||||||
|
private UserManagerEditView UserInfo { get; set; } = new();
|
||||||
private SalesItemView SelectedItem { get; set; } = new();
|
private SalesItemView SelectedItem { get; set; } = new();
|
||||||
private ActivityDto Activity { get; set; } = new();
|
private ActivityDto Activity { get; set; } = new();
|
||||||
private UserManagerEditView SalesRep { get; set; } = new();
|
private UserManagerEditView SalesRep { get; set; } = new();
|
||||||
|
@ -64,7 +71,7 @@ public partial class OfficeOrderCreatePage : IDisposable
|
||||||
private string Quantity { get; set; } = "1";
|
private string Quantity { get; set; } = "1";
|
||||||
private string Price { get; set; } = "0";
|
private string Price { get; set; } = "0";
|
||||||
private string Discount { get; set; } = "0";
|
private string Discount { get; set; } = "0";
|
||||||
private bool ReportClosed { get; set; }
|
// private bool ReportClosed { get; set; }
|
||||||
private bool PoFormInvalid { get; set; } = true;
|
private bool PoFormInvalid { get; set; } = true;
|
||||||
private bool Working { get; set; } = true;
|
private bool Working { get; set; } = true;
|
||||||
|
|
||||||
|
@ -87,6 +94,7 @@ public partial class OfficeOrderCreatePage : IDisposable
|
||||||
Interceptor.RegisterEvent();
|
Interceptor.RegisterEvent();
|
||||||
Interceptor.RegisterBeforeSendEvent();
|
Interceptor.RegisterBeforeSendEvent();
|
||||||
|
|
||||||
|
UserInfo = await UserInfoService.GetUserInfo();
|
||||||
// setup edit context
|
// setup edit context
|
||||||
ActivityContext = new EditContext(Activity);
|
ActivityContext = new EditContext(Activity);
|
||||||
ActivityContext.OnFieldChanged += HandleFieldChanged;
|
ActivityContext.OnFieldChanged += HandleFieldChanged;
|
||||||
|
@ -148,6 +156,7 @@ public partial class OfficeOrderCreatePage : IDisposable
|
||||||
Activity.VisitTypeEnum = "recall";
|
Activity.VisitTypeEnum = "recall";
|
||||||
Activity.ActivityTypeEnum = "phone";
|
Activity.ActivityTypeEnum = "phone";
|
||||||
Activity.ActivityStatusEnum = "order";
|
Activity.ActivityStatusEnum = "order";
|
||||||
|
Activity.OurRef = $"T:{UserInfo.FirstName}";
|
||||||
|
|
||||||
// Initialize date variable
|
// Initialize date variable
|
||||||
SelectedDate = DateTime.Now;
|
SelectedDate = DateTime.Now;
|
||||||
|
@ -220,8 +229,104 @@ public partial class OfficeOrderCreatePage : IDisposable
|
||||||
InventoryListOverlay.Show();
|
InventoryListOverlay.Show();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void CreateActivity()
|
private async Task CreateActivity()
|
||||||
{
|
{
|
||||||
|
// avoid duplication
|
||||||
|
if (Working)
|
||||||
|
return;
|
||||||
|
// validate customer address1
|
||||||
|
// - this is a required input
|
||||||
|
if (string.IsNullOrWhiteSpace(Activity.Address1))
|
||||||
|
{
|
||||||
|
Toaster.ShowError("Kunde adresse er ufuldstændig.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// validate org number
|
||||||
|
// - this is a required input
|
||||||
|
// - must validate according to country rules.
|
||||||
|
if (!VatUtils.ValidateFormat(Company.CountryCode, Activity.VatNumber))
|
||||||
|
{
|
||||||
|
Toaster.ShowError("Firma registreringsnummer er ikke korrekt.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// validate input according to status
|
||||||
|
switch (Activity.ActivityStatusEnum)
|
||||||
|
{
|
||||||
|
// don't accept order with no lines
|
||||||
|
case "order" when DraftProvider.Draft.Items.Count == 0:
|
||||||
|
Toaster.ShowError("Ved bestilling skal der være en eller flere linjer i kladden.");
|
||||||
|
return;
|
||||||
|
// phone number is required if first time customer
|
||||||
|
case "order" when Company.Account is "NY" or "" && string.IsNullOrWhiteSpace(Activity.Phone):
|
||||||
|
Toaster.ShowError("Ved bestilling til ny kunde skal telefon nummer angives.");
|
||||||
|
return;
|
||||||
|
// verify email address is a valid address
|
||||||
|
case "quote" when !Utils.IsValidEmail(Activity.Email):
|
||||||
|
Toaster.ShowError("Ved tilbud skal en gyldig email adresse angives.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// raise working flag
|
||||||
|
Working = true;
|
||||||
|
|
||||||
|
// reset selected item
|
||||||
|
SelectedItem = new SalesItemView();
|
||||||
|
// // check if phone number need to be updated
|
||||||
|
// if (OldPhone != Activity.Phone)
|
||||||
|
// {
|
||||||
|
// Company.Phone = Activity.Phone;
|
||||||
|
// Activity.OrderMessage = $"Telefonnr. opdateret.\n{Activity.OrderMessage}";
|
||||||
|
// await CompanyRepo.UpdateErpData(Company.CompanyId, Company);
|
||||||
|
// }
|
||||||
|
|
||||||
|
// begin assembling activity
|
||||||
|
Activity.ActivityDate = $"{SelectedDate:yyyy-MM-dd}";
|
||||||
|
if (Activity.Express)
|
||||||
|
Activity.OurRef = $"E{Activity.OurRef}";
|
||||||
|
// begin lines
|
||||||
|
Activity.Lines = new List<ActivityLineDto>();
|
||||||
|
var ln = 0;
|
||||||
|
if (DraftProvider.Draft.Items.Count != 0)
|
||||||
|
{
|
||||||
|
var lines = DraftProvider.Draft.Items.Select(item => new ActivityLineDto
|
||||||
|
{
|
||||||
|
Price = item.Price,
|
||||||
|
Discount = item.Discount,
|
||||||
|
LineAmount = item.LineTotal,
|
||||||
|
Qty = item.Quantity,
|
||||||
|
Sku = item.Item.Sku,
|
||||||
|
Text = item.Item.Name,
|
||||||
|
ShortName = item.Item.ShortName,
|
||||||
|
LineNumber = ++ln,
|
||||||
|
Sas = item.Sas,
|
||||||
|
Location = item.Item.Location
|
||||||
|
})
|
||||||
|
.ToList();
|
||||||
|
Activity.Lines = lines;
|
||||||
|
}
|
||||||
|
|
||||||
|
// debug logging
|
||||||
|
Logger.LogDebug("CrmNewActivityPage => \n {}", JsonSerializer.Serialize(Activity));
|
||||||
|
// post to api
|
||||||
|
var result = await ActivityRepo.CreatePhoneOrder(Company.CompanyId, Activity);
|
||||||
|
// debug logging
|
||||||
|
Logger.LogDebug("ApiResponseView => \n {}", JsonSerializer.Serialize(result));
|
||||||
|
// show result message
|
||||||
|
if (result.IsSuccess)
|
||||||
|
{
|
||||||
|
Toaster.ShowSuccess($"{result.Message}", "Telefon Ordre oprettet");
|
||||||
|
await DeleteDraft();
|
||||||
|
Navigator.NavigateTo($"/office/customers/{CompanyId}/orders/{result.Id}");
|
||||||
|
Working = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// lower working flag
|
||||||
|
Working = false;
|
||||||
|
// show error message
|
||||||
|
Toaster.ShowError(result.Message, "ORDRE FEJL");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue