-
-
@_workDate.ToLongDateString()
-
-
-
+
-
@_activity.Name - @_activity.Account
+ @Activity.Name - @Activity.Account
-@if (_reportClosed)
+@if (ReportClosed)
{
-
Der kan ikke oprettes besøg når der findes rapport for @_workDate.ToShortDateString()
+
Der kan ikke oprettes besøg når der findes rapport for @SelectedDate.ToShortDateString()
}
else
{
-
+
-
+
-
+
-
-
- @if (!string.IsNullOrEmpty(_activity.VatNumber) && !string.IsNullOrWhiteSpace(_activity.Address1) && _company.HasFolded == 0)
+
+
+ @if (!string.IsNullOrEmpty(Activity.VatNumber) && !string.IsNullOrWhiteSpace(Activity.Address1) && Company.HasFolded == 0)
{
-
+ @if (DraftStateProvider.Draft.Items.Any())
+ {
+
+ }
+ else
+ {
+
+ }
}
-
- @if (_activity.ActivityStatusEnum == "order")
+
+ @if (Activity.ActivityStatusEnum == "order")
{
-
+
}
@@ -83,63 +83,178 @@ else
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
+
-
-
+
+
-
-
+
+
-
+
+ @* Order lines -----------------------------------------------------*@
+
+ @* draft line ----------------------------------------------------- *@
+
+
+ @if (!string.IsNullOrWhiteSpace(SelectedItem.Name) && ShowItem)
+ {
+
+ }
+
+
+
- @* Order lines *@
-
+ @*
+ $1$ Order lines #1#
+
+ *@
@* Delivery address *@
-
-
+
}
-
\ No newline at end of file
+
+
+
+
\ No newline at end of file
diff --git a/Wonky.Client/Pages/CrmActivityNewPage.razor.cs b/Wonky.Client/Pages/CrmActivityNewPage.razor.cs
index d229a01e..949659b6 100644
--- a/Wonky.Client/Pages/CrmActivityNewPage.razor.cs
+++ b/Wonky.Client/Pages/CrmActivityNewPage.razor.cs
@@ -38,7 +38,7 @@ public partial class CrmActivityNewPage : IDisposable
// Services
[Inject] public ILogger
Logger { get; set; }
[Inject] public HttpInterceptorService Interceptor { get; set; }
- [Inject] public PreferenceService PreferenceService { get; set; }
+ [Inject] public PreferenceService Prefs { get; set; }
[Inject] public IToastService Toast { get; set; }
[Inject] public NavigationManager Navigator { get; set; }
[Inject] public ILocalStorageService Storage { get; set; }
@@ -47,13 +47,13 @@ public partial class CrmActivityNewPage : IDisposable
[Inject] public ICrmActivityHttpRepository CrmActivityRepo { get; set; }
[Inject] public ICrmReportHttpRepository CrmReportRepo { get; set; }
// variables
- private readonly JsonSerializerOptions? _options = new JsonSerializerOptions{PropertyNameCaseInsensitive = true};
- private SalesItemView _selectedItem { get; set; } = new();
- private Preferences _prefs { get; set; } = new();
- private ActivityDto _activity { get; set; } = new();
- private CompanyDto _company = new();
- private EditContext _editContext { get; set; }
- private bool _poFormInvalid { get; set; } = true;
+ private readonly JsonSerializerOptions? _options = new() {PropertyNameCaseInsensitive = true};
+ private SalesItemView SelectedItem { get; set; } = new();
+ private Preferences UserPrefs { get; set; } = new();
+ private ActivityDto Activity { get; set; } = new();
+ private CompanyDto Company = new();
+ private EditContext ActivityContext { get; set; }
+ private bool PoFormInvalid { get; set; } = true;
private bool ShowItem { get; set; }
private string Quantity = "1";
private string Price = "0";
@@ -64,129 +64,131 @@ public partial class CrmActivityNewPage : IDisposable
private bool InvalidActivity = true;
private bool InvalidCanvas = true;
private bool NoHistory = true;
- private bool _reportClosed { get; set; }
- private UserInfoView _ux { get; set; } = new();
- private DateTime _workDate { get; set; } = DateTime.Now;
- private string _selectedDate { get; set; } = "";
- private string _phone { get; set; } = "";
- private string _confirmDatePrompt { get; set; }
+ private bool ReportClosed { get; set; }
+ private UserInfoView ThisUserInfo { get; set; } = new();
+ private DateTime SelectedDate { get; set; }
+ private string OldPhone { get; set; } = "";
+ private string PromptDateConfirm { get; set; }
// MODAL DIALOGS
private PriceListModal PriceListModal { get; set; }
private ProductHistoryModal HistoryModal { get; set; }
private ProductPriceHistoryModal PriceHistoryModal { get; set; }
- private ConfirmationModal ConfirmWorkDate { get; set; } = new();
+ private ConfirmWorkDateModal ConfirmWorkDate { get; set; } = new();
- protected override async Task OnParametersSetAsync()
- {
- Interceptor.RegisterEvent();
- Interceptor.RegisterBeforeSendEvent();
-
- _prefs = await PreferenceService.GetPreferences();
-
- if (!string.IsNullOrWhiteSpace(_prefs.WorkDate))
- _workDate = DateTime.Parse(_prefs.WorkDate);
- _selectedDate = $"{_workDate:yyyy-MM-dd}";
-
- // raise flag if report is closed
- _reportClosed = await CrmReportRepo.ReportExist(_selectedDate);
- }
-
protected override async Task OnInitializedAsync()
{
- _editContext = new EditContext(_activity);
- _editContext.OnFieldChanged += HandleFieldChanged;
- _editContext.OnValidationStateChanged += ValidationChanged;
-
- _activity.ActivityDate = $"{_workDate:yyyy-MM-dd}" ;
-
- _ux = await Storage.GetItemAsync("_xu");
-
- // get company
- _company = await CompanyRepo.GetCompanyById(CompanyId);
-
+ ActivityContext = new EditContext(Activity);
+ ActivityContext.OnFieldChanged += HandleFieldChanged;
+ ActivityContext.OnValidationStateChanged += ValidationChanged;
+
+ Interceptor.RegisterEvent();
+ Interceptor.RegisterBeforeSendEvent();
+ // User Preferences
+ UserPrefs = await Prefs.GetPreferences();
+ // User Info
+ ThisUserInfo = await Storage.GetItemAsync("_xu");
+ // Fetch Customer from http
+ Company = await CompanyRepo.GetCompanyById(CompanyId);
+ if (Company.HasFolded == 1)
+ // Company has shutdown activities
+ Activity.OrderMessage = "BEMÆRK: CVR nummer er ophørt.";
// variable to validate if customer needs phone number update
- _phone = _company.Phone;
- if (string.IsNullOrWhiteSpace(_company.Phone)
- && !string.IsNullOrWhiteSpace(_company.Account)
- && _company.Account != "NY" && _company.Account.Length > 7)
+ OldPhone = Company.Phone;
+ if (string.IsNullOrWhiteSpace(Company.Phone)
+ && !string.IsNullOrWhiteSpace(Company.Account)
+ && Company.Account != "NY" && Company.Account.Length > 7)
{
- _company.Phone = _company.Account[..8];
+ Company.Phone = Company.Account[..8];
}
-
- _activity.BcId = _company.BcId;
- _activity.ActivityStatusEnum = "noSale";
- _activity.VisitTypeEnum = _company.Account is "" or "NY" ? "new" : "recall";
-
- if (_company.HasFolded == 1)
- _activity.OrderMessage = "Virksomheden er ophørt.";
-
- // permanent identifications
- _activity.CompanyId = _company.CompanyId;
- _activity.SalesRepId = _ux.Id;
- _activity.SalesRep = _ux.Advisor;
- _activity.CountryCode = _ux.CountryCode;
-
- _activity.Account = _company.Account;
- _activity.VatNumber = _company.VatNumber;
- _activity.Email = _company.Email;
- _activity.Phone = _company.Phone;
- _activity.Mobile = _company.Mobile;
-
- _activity.Name = _company.Name;
- _activity.Address1 = _company.Address1;
- _activity.Address2 = _company.Address2;
- _activity.ZipCode = _company.ZipCode;
- _activity.City = _company.City;
-
- _activity.DlvName = _company.Name;
- _activity.DlvAddress1 = _company.Address1;
- _activity.DlvAddress2 = _company.Address2;
- _activity.DlvZipCode = _company.ZipCode;
- _activity.DlvCity = _company.City;
+ // Populate base activity information
+ Activity.BcId = Company.BcId;
+ Activity.ActivityStatusEnum = "noSale";
+ Activity.VisitTypeEnum = Company.Account is "" or "NY" ? "new" : "recall";
+ Activity.CompanyId = Company.CompanyId;
+ Activity.SalesRepId = ThisUserInfo.Id;
+ Activity.SalesRep = ThisUserInfo.Advisor;
+ Activity.CountryCode = ThisUserInfo.CountryCode;
+ Activity.Account = Company.Account;
+ Activity.VatNumber = Company.VatNumber;
+ Activity.Email = Company.Email;
+ Activity.Phone = Company.Phone;
+ Activity.Mobile = Company.Mobile;
+ Activity.Name = Company.Name;
+ Activity.Address1 = Company.Address1;
+ Activity.Address2 = Company.Address2;
+ Activity.ZipCode = Company.ZipCode;
+ Activity.City = Company.City;
+ Activity.DlvName = Company.Name;
+ Activity.DlvAddress1 = Company.Address1;
+ Activity.DlvAddress2 = Company.Address2;
+ Activity.DlvZipCode = Company.ZipCode;
+ Activity.DlvCity = Company.City;
+ // Initialize date variable
+ SelectedDate = string.IsNullOrWhiteSpace(UserPrefs.WorkDate) ? DateTime.Now : DateTime.Parse(UserPrefs.WorkDate);
+ // raise flag if report is closed
+ ReportClosed = await CrmReportRepo.ReportExist($"{SelectedDate:yyyy-MM-dd}");
+ // Ask for confirmation of date
+ Logger.LogDebug("Preferences.DateConfirmed => {}", UserPrefs.DateConfirmed);
+ if (!UserPrefs.DateConfirmed)
+ {
+ PromptDateConfirm = $"Aktiviteter oprettes med dato {SelectedDate.ToShortDateString()}. Er dette OK?";
+ ConfirmWorkDate.Show();
+ }
+ // Lines may already have been added from the company inventory page
+ if (DraftStateProvider.Draft.Items.Any())
+ {
+ // set dropdown selection accordingly
+ Activity.ActivityTypeEnum = "onSite";
+ Activity.ActivityStatusEnum = "order";
+ }
+ StateHasChanged();
}
-
+ ///
+ /// Work Date confirm callback
+ ///
+ private async Task WorkDateConfirmCallback()
+ {
+ await Prefs.SetDateConfirmed(true);
+ ConfirmWorkDate.Hide();
+ StateHasChanged();
+ }
+ ///
+ /// Show Price list modal
+ ///
private void CallPriceListModal()
{
PriceListModal.Show();
}
-
- private void VerifyWorkDateConfirmed()
- {
- Logger.LogDebug("Preferences.DateConfirmed => {}", _prefs.DateConfirmed);
-
- if (_prefs.DateConfirmed) return;
-
- _confirmDatePrompt = $"Dato {_activity.ActivityDate}?";
- ConfirmWorkDate.Show();
- }
-
- private async Task WorkDateConfirmed()
- {
- await PreferenceService.SetDateConfirmed(true);
- ConfirmWorkDate.Hide();
- }
-
- private async Task SelectSku(SelectedSku sku)
+ ///
+ /// Price List modal callback
+ ///
+ ///
+ private async Task PriceListCallback(SelectedSku sku)
{
// get selected item
if (string.IsNullOrWhiteSpace(sku.ItemId))
return;
- _selectedItem = await Catalog.GetSalesItemId(sku.ItemId);
+ SelectedItem = await Catalog.GetSalesItemId(sku.ItemId);
ShowItem = true;
Price = sku.Rate;
Quantity = sku.Quantity;
StateHasChanged();
}
-
+ ///
+ /// Show Price History modal
+ ///
private void CallPriceHistoryModal()
{
if(ShowItem)
PriceHistoryModal.Show();
}
-
- private void SelectPrice(decimal price)
+ ///
+ /// Price History modal callback
+ ///
+ ///
+ private void PriceHistoryCallback(decimal price)
{
if (price == 0)
return;
@@ -194,31 +196,30 @@ public partial class CrmActivityNewPage : IDisposable
Price = price.ToString("N2", CultureInfo.InvariantCulture);
StateHasChanged();
}
-
- private async Task SetWorkDate(string workDate)
+
+ ///
+ /// Work Date component callback
+ ///
+ ///
+ private async Task WorkDateComponentCallback(string workDate)
{
- _selectedDate = workDate;
- _workDate = DateTime.Parse(_selectedDate);
- _activity.ActivityDate = _selectedDate;
- _reportClosed = await CrmReportRepo.ReportExist(_selectedDate);
+ ReportClosed = await CrmReportRepo.ReportExist(workDate);
+ SelectedDate = DateTime.Parse(workDate);
+ Activity.ActivityDate = workDate;
}
-
+ ///
+ /// Validate and Create Activity
+ ///
private async Task CreateActivity()
{
-
- // if (!_prefs.DateConfirmed)
- // {
- // _confirmDatePrompt = $"Er arbejdsdato {_selectedDate} korrekt?";
- // CallConfirmWorkDate();
- // }
-
- if (string.IsNullOrWhiteSpace(_activity.Address1))
+
+ if (string.IsNullOrWhiteSpace(Activity.Address1))
{
Toast.ShowError("Kunde adresse er ufuldstændig.");
return;
}
- if (_activity.ActivityStatusEnum == "order")
+ if (Activity.ActivityStatusEnum == "order")
{
if (DraftStateProvider.Draft.Items.Count == 0)
{
@@ -226,27 +227,36 @@ public partial class CrmActivityNewPage : IDisposable
return;
}
- if (string.IsNullOrWhiteSpace(_activity.Phone))
+ if (string.IsNullOrWhiteSpace(Activity.Phone))
{
Toast.ShowError("Ved bestilling til ny kunde skal telefon nummer angives.");
return;
-
}
}
- _poFormInvalid = true;
-
- _activity.ActivityDate = $"{_workDate:yyyy-MM-dd}";
- _activity.OurRef = _activity.ActivityTypeEnum switch
+ PoFormInvalid = true;
+ // reset selected item
+ SelectedItem = new SalesItemView();
+ // check if phone number need to be updated
+ if (OldPhone != Activity.Phone)
{
- "phone" => $"T:{_ux.FullName.Split(" ")[0]}",
- "onSite" => $"B:{_ux.FullName.Split(" ")[0]}",
+ Company.Phone = Activity.Phone;
+ // update company phone record
+ Logger.LogDebug("CrmNewActivityPage => \n New Phone Number \n {}", Activity.Phone);
+ await CompanyRepo.UpdateCompany(Company.CompanyId, Company);
+ }
+ // begin assembling activity
+ Activity.ActivityDate = $"{SelectedDate:yyyy-MM-dd}";
+ Activity.OurRef = Activity.ActivityTypeEnum switch
+ {
+ "phone" => $"T:{ThisUserInfo.FullName.Split(" ")[0]}",
+ "onSite" => $"B:{ThisUserInfo.FullName.Split(" ")[0]}",
_ => ""
};
- if (_activity.Express)
- _activity.OurRef = $"E{_activity.OurRef}";
-
- _activity.Lines = new List();
+ if (Activity.Express)
+ Activity.OurRef = $"E{Activity.OurRef}";
+ // begin lines
+ Activity.Lines = new List();
var ln = 0;
if (DraftStateProvider.Draft.Items.Count != 0)
{
@@ -264,22 +274,12 @@ public partial class CrmActivityNewPage : IDisposable
Location = item.Item.Location
})
.ToList();
- _activity.Lines = lines;
+ Activity.Lines = lines;
}
- if (_phone != _activity.Phone)
- {
- _company.Phone = _activity.Phone;
- // update company phone record
- await CompanyRepo.UpdateCompany(_company.CompanyId, _company);
- }
-
- Logger.LogDebug("CrmNewActivityPage => \n {}", JsonSerializer.Serialize(_activity));
-
+ Logger.LogDebug("CrmNewActivityPage => \n {}", JsonSerializer.Serialize(Activity));
// post to api
- var result = await CrmActivityRepo.CreateActivity(_activity);
-
+ var result = await CrmActivityRepo.CreateActivity(Activity);
Logger.LogDebug("ApiResponseView => \n {}", JsonSerializer.Serialize(result));
-
// show result message
if (result.IsSuccess)
{
@@ -289,21 +289,20 @@ public partial class CrmActivityNewPage : IDisposable
return;
}
- _poFormInvalid = false;
+ PoFormInvalid = false;
Toast.ShowError(result.Message, "ORDRE FEJL");
- _selectedItem = new SalesItemView();
}
-
- private void CheckActivity()
- {
- InvalidActivityType = string.IsNullOrWhiteSpace(_activity.ActivityTypeEnum);
- }
-
+ ///
+ /// Delete current draft
+ ///
private async Task DeleteDraft()
{
await DraftStateProvider.DeleteDraftAsync();
}
-
+ ///
+ /// Add item to draft
+ ///
+ ///
private async Task AddItem(SalesItemView salesItem)
{
ShowItem = false;
@@ -326,6 +325,10 @@ public partial class CrmActivityNewPage : IDisposable
// save the item using the CartStateProvider's save method
await DraftStateProvider.SaveChangesAsync();
}
+ ///
+ /// Remove item from draft
+ ///
+ ///
private async Task RemoveItem(DraftItem item)
{
// remove item
@@ -333,53 +336,57 @@ public partial class CrmActivityNewPage : IDisposable
// save the remaining draft
await DraftStateProvider.SaveChangesAsync();
}
-
+ ///
+ /// Edit Context handle field change
+ ///
+ ///
+ ///
private void HandleFieldChanged(object sender, FieldChangedEventArgs e)
{
// InvalidCanvas = InvalidActivityType;
InvalidActivity = InvalidActivityType
- || _poFormInvalid
+ || PoFormInvalid
|| DraftStateProvider.Draft.Items.Count == 0
- || (_activity.ActivityStatusEnum == "offer" && string.IsNullOrWhiteSpace(_activity.Email));
- if (_activity.YourRef.Length > 35 || _activity.ReferenceNumber.Length > 20)
+ || (Activity.ActivityStatusEnum == "offer" && string.IsNullOrWhiteSpace(Activity.Email));
+ if (Activity.YourRef.Length > 35 || Activity.ReferenceNumber.Length > 20)
{
- _poFormInvalid = true;
+ PoFormInvalid = true;
return;
}
-
if (InvalidActivity)
{
- _poFormInvalid = true;
+ PoFormInvalid = true;
return;
}
-
- _poFormInvalid = !_editContext.Validate();
+ PoFormInvalid = !ActivityContext.Validate();
StateHasChanged();
}
+ ///
+ /// Edit Context handle validation change
+ ///
+ ///
+ ///
private void ValidationChanged(object sender, ValidationStateChangedEventArgs e)
{
- if (string.IsNullOrEmpty(_activity.ActivityTypeEnum) && !_reportClosed)
+ if (string.IsNullOrEmpty(Activity.ActivityTypeEnum) && !ReportClosed)
{
Toast.ShowWarning("Aktivitet type kan ikke være tom");
return;
}
-
- _poFormInvalid = false;
-
- _editContext.OnFieldChanged -= HandleFieldChanged;
- _editContext.OnValidationStateChanged -= ValidationChanged;
- _editContext = new EditContext(_activity);
- _editContext.OnFieldChanged += HandleFieldChanged;
- _editContext.OnValidationStateChanged += ValidationChanged;
-
- VerifyWorkDateConfirmed();
+ PoFormInvalid = false;
+ ActivityContext.OnFieldChanged -= HandleFieldChanged;
+ ActivityContext.OnValidationStateChanged -= ValidationChanged;
+ ActivityContext = new EditContext(Activity);
+ ActivityContext.OnFieldChanged += HandleFieldChanged;
+ ActivityContext.OnValidationStateChanged += ValidationChanged;
}
-
+ ///
+ /// Implement Dispose from IDisposable
+ ///
public void Dispose()
{
Interceptor.DisposeEvent();
- _editContext.OnFieldChanged -= HandleFieldChanged;
- _editContext.OnValidationStateChanged -= ValidationChanged;
+ ActivityContext.OnFieldChanged -= HandleFieldChanged;
+ ActivityContext.OnValidationStateChanged -= ValidationChanged;
}
-
}
\ No newline at end of file
diff --git a/Wonky.Client/Pages/CrmActivityTodayPage.razor b/Wonky.Client/Pages/CrmActivityTodayPage.razor
index c83ae66f..3b9f8067 100644
--- a/Wonky.Client/Pages/CrmActivityTodayPage.razor
+++ b/Wonky.Client/Pages/CrmActivityTodayPage.razor
@@ -20,12 +20,9 @@
@attribute [Authorize(Roles = "Advisor")]
@page "/activity-today"
-
-
-
@(string.IsNullOrWhiteSpace(_workDate) ? "" : $"{DateTime.Parse(_workDate).ToLongDateString()}")
-
-
-
+
+
+
@@ -33,7 +30,7 @@
@if (_reportExist)
{
-
RAPPORT
+
RAPPORT
}
else
{
diff --git a/Wonky.Client/Pages/CrmActivityTodayPage.razor.cs b/Wonky.Client/Pages/CrmActivityTodayPage.razor.cs
index e2f79cd4..10d55cf0 100644
--- a/Wonky.Client/Pages/CrmActivityTodayPage.razor.cs
+++ b/Wonky.Client/Pages/CrmActivityTodayPage.razor.cs
@@ -36,30 +36,28 @@ public partial class CrmActivityTodayPage : IDisposable
[Inject] public IToastService _toast { get; set; }
private ReportStatusView? ReportStatusView { get; set; } = new();
private Preferences _prefs { get; set; } = new();
- private string _workDate { get; set; } = $"{DateTime.Now:yyyy-MM-dd}";
+ private DateTime SelectedDate { get; set; }
private bool _reportExist = false;
private bool Loading { get; set; } = true;
protected override async Task OnInitializedAsync()
{
_prefs = await _preferenceService.GetPreferences();
- if(!string.IsNullOrWhiteSpace(_prefs.WorkDate))
- _workDate = _prefs.WorkDate;
+ SelectedDate = string.IsNullOrWhiteSpace(_prefs.WorkDate) ? DateTime.Now : DateTime.Parse(_prefs.WorkDate);
_interceptor.RegisterEvent();
_interceptor.RegisterBeforeSendEvent();
- _reportExist = await CrmReportRepo.ReportExist(_workDate);
-
- await GetActivities(_workDate);
+ _reportExist = await CrmReportRepo.ReportExist($"{SelectedDate:yyyy-MM-dd}");
+ await GetActivities($"{SelectedDate:yyyy-MM-dd}");
}
private async Task GetActivities(string workDate)
{
_toast.ShowInfo("Vent nogle sekunder for data");
- _workDate = workDate;
+ SelectedDate = DateTime.Parse(workDate);
ReportStatusView = new ReportStatusView();
- ReportStatusView = await CrmActivityRepo.GetActivities(workDate);
+ ReportStatusView = await CrmActivityRepo.GetActivities($"{SelectedDate:yyyy-MM-dd}");
_logger.LogDebug("Activities => {}", JsonSerializer.Serialize(ReportStatusView));
Loading = false;
}
diff --git a/Wonky.Client/Pages/CrmCompanyInventoryPage.razor b/Wonky.Client/Pages/CrmCompanyInventoryPage.razor
index 65a79c0c..e03fd8d4 100644
--- a/Wonky.Client/Pages/CrmCompanyInventoryPage.razor
+++ b/Wonky.Client/Pages/CrmCompanyInventoryPage.razor
@@ -19,23 +19,21 @@
@using Microsoft.AspNetCore.Authorization
@page "/companies/{CompanyId}/h/i"
@attribute [Authorize(Roles = "Advisor")]
-
-
-