FIX customer didn't load correct - not possible to create visit

This commit is contained in:
Frede Hundewadt 2023-06-16 11:20:12 +02:00
parent fece4d93e5
commit 80fa4e2c09
2 changed files with 202 additions and 242 deletions

View file

@ -21,7 +21,7 @@
@attribute [Authorize(Roles = "Advisor")]
@page "/advisor/customers/{CompanyId}/activities/new"
<PageTitle>Ny aktivitet - @Company.Name</PageTitle>
<PageTitle>Ny aktivitet - @_company.Name</PageTitle>
<div class="row bg-dark text-white rounded-2 mb-2 py-2 align-items-center">
<div class="col">
@ -29,15 +29,15 @@
</div>
</div>
@if (!string.IsNullOrWhiteSpace(Company.Blocked))
@if (!string.IsNullOrWhiteSpace(_company.Blocked))
{
<div class="alert alert-danger">
<h4>Ring til kontoret. Denne konto er spærret med kode '@Company.Blocked'</h4>
<h4>Ring til kontoret. Denne konto er spærret med kode '@_company.Blocked'</h4>
</div>
}
<div class="row mb-2 bg-dark text-white rounded-3 p-3">
<div class="col">
<span class="h3">@Activity.Name</span> <span>(@Activity.Account)</span>
<span class="h3">@_activity.Name</span> <span>(@_activity.Account)</span>
</div>
</div>
@ -51,12 +51,12 @@
}
else
{
<EditForm EditContext="ActivityContext">
<EditForm EditContext="_formContext">
<DataAnnotationsValidator/>
<div class="row mb-3 g-2">
<label for="activityType" class="col-sm-2 col-form-label-sm">Ordre Type</label>
<div class="col-sm-4">
<InputSelect id="activityType" class="form-select bg-primary text-bg-primary" @bind-Value="@Activity.ActivityTypeEnum">
<InputSelect id="activityType" class="form-select bg-primary text-bg-primary" @bind-Value="@_activity.ActivityTypeEnum">
@if (_kanvas)
{
<option value="canvas" selected>Kanvas</option>
@ -68,21 +68,21 @@ else
<option value="phone">Telefon</option>
}
</InputSelect>
<ValidationMessage For="@(() => Activity.ActivityTypeEnum)"></ValidationMessage>
<ValidationMessage For="@(() => _activity.ActivityTypeEnum)"></ValidationMessage>
</div>
<label for="statusType" class="col-sm-2 col-form-label-sm">Status</label>
<div class="col-sm-4">
<InputSelect id="statusType" class="form-select bg-primary text-bg-primary" @bind-Value="@Activity.ActivityStatusEnum">
<InputSelect id="statusType" class="form-select bg-primary text-bg-primary" @bind-Value="@_activity.ActivityStatusEnum">
@if (_kanvas)
{
<option value="canvas" selected>Kanvas</option>
<option selected value="canvas">Kanvas</option>
}
else
{
<option value="noSale">Ingen salg</option>
/*@if (!string.IsNullOrEmpty(Activity.VatNumber) && !string.IsNullOrWhiteSpace(Activity.Address1) && Company.HasFolded == 0)*/
@if (!string.IsNullOrEmpty(Activity.VatNumber) && !string.IsNullOrWhiteSpace(Activity.Address1))
<option selected value="noSale">Ingen salg</option>
/*@if (!string.IsNullOrEmpty(_activity.VatNumber) && !string.IsNullOrWhiteSpace(_activity.Address1) && _company.HasFolded == 0)*/
@if (!string.IsNullOrWhiteSpace(_activity.VatNumber) && !string.IsNullOrWhiteSpace(_activity.Address1) && _company.HasFolded == 0)
{
@if (DraftProvider.Draft.DraftType == "order")
{
@ -93,7 +93,7 @@ else
<option value="order">Bestilling</option>
}
@if (DraftProvider.Draft.DraftType == "offer")
@if (DraftProvider.Draft.DraftType == "quote")
{
<option selected value="quote">Tilbud</option>
}
@ -104,11 +104,11 @@ else
}
}
</InputSelect>
<ValidationMessage For="@(() => Activity.ActivityStatusEnum)"></ValidationMessage>
@if (Activity.ActivityStatusEnum == "order")
<ValidationMessage For="@(() => _activity.ActivityStatusEnum)"></ValidationMessage>
@if (_activity.ActivityStatusEnum == "order")
{
<div class="form-check">
<InputCheckbox id="express" class="form-check-input" @bind-Value="@Activity.Express"/>
<InputCheckbox id="express" class="form-check-input" @bind-Value="@_activity.Express"/>
<label class="form-check-label" for="express">Express</label>
</div>
}
@ -118,79 +118,79 @@ else
{
<label for="demo" class="col-sm-2 col-form-label-sm">Demo</label>
<div class="col-sm-10">
<InputText id="demo" class="form-control" @bind-Value="Activity.Demo"/>
<ValidationMessage For="@(() => Activity.Demo)"></ValidationMessage>
<InputText id="demo" class="form-control" @bind-Value="_activity.Demo"/>
<ValidationMessage For="@(() => _activity.Demo)"></ValidationMessage>
</div>
<label for="orderMessage" class="col-sm-2 col-form-label-sm">Note /Kontor</label>
<div class="col-sm-10">
<InputTextArea id="orderMessage" class="form-control" @bind-Value="Activity.OrderMessage"/>
<ValidationMessage For="@(() => Activity.OrderMessage)"></ValidationMessage>
<InputTextArea id="orderMessage" class="form-control" @bind-Value="_activity.OrderMessage"/>
<ValidationMessage For="@(() => _activity.OrderMessage)"></ValidationMessage>
</div>
<label for="crmNote" class="col-sm-2 col-form-label-sm">Note /Selv</label>
<div class="col-sm-10">
<InputTextArea id="crmNote" class="form-control" @bind-Value="Activity.CrmNote"/>
<ValidationMessage For="@(() => Activity.CrmNote)"></ValidationMessage>
<InputTextArea id="crmNote" class="form-control" @bind-Value="_activity.CrmNote"/>
<ValidationMessage For="@(() => _activity.CrmNote)"></ValidationMessage>
</div>
}
else
{
<label for="demo" class="col-sm-2 col-form-label-sm">Demo</label>
<div class="col-sm-4">
<InputText id="demo" class="form-control" @bind-Value="Activity.Demo"/>
<ValidationMessage For="@(() => Activity.Demo)"></ValidationMessage>
<InputText id="demo" class="form-control" @bind-Value="_activity.Demo"/>
<ValidationMessage For="@(() => _activity.Demo)"></ValidationMessage>
</div>
<label for="email" class="col-sm-2 col-form-label-sm">Epost</label>
<div class="col-sm-4">
<InputText id="email" class="form-control" @bind-Value="Activity.Email"/>
<ValidationMessage For="@(() => Activity.Email)"></ValidationMessage>
<InputText id="email" class="form-control" @bind-Value="_activity.Email"/>
<ValidationMessage For="@(() => _activity.Email)"></ValidationMessage>
</div>
<label for="referenceNumber" class="col-sm-2 col-form-label-sm">Rekvisition</label>
<div class="col-sm-4">
<InputText id="referenceNumber" class="form-control" @bind-Value="Activity.ReferenceNumber"/>
<ValidationMessage For="@(() => Activity.ReferenceNumber)"></ValidationMessage>
<InputText id="referenceNumber" class="form-control" @bind-Value="_activity.ReferenceNumber"/>
<ValidationMessage For="@(() => _activity.ReferenceNumber)"></ValidationMessage>
</div>
<label for="yourRef" class="col-sm-2 col-form-label-sm">Indkøber</label>
<div class="col-sm-4">
<InputText id="yourRef" class="form-control" @bind-Value="Activity.YourRef"/>
<ValidationMessage For="@(() => Activity.YourRef)"></ValidationMessage>
<InputText id="yourRef" class="form-control" @bind-Value="_activity.YourRef"/>
<ValidationMessage For="@(() => _activity.YourRef)"></ValidationMessage>
</div>
<label for="attention" class="col-sm-2 col-form-label-sm">Att.</label>
<div class="col-sm-4">
<InputText id="attention" class="form-control" @bind-Value="Activity.Attention"/>
<ValidationMessage For="@(() => Activity.Attention)"></ValidationMessage>
<InputText id="attention" class="form-control" @bind-Value="_activity.Attention"/>
<ValidationMessage For="@(() => _activity.Attention)"></ValidationMessage>
</div>
<label for="phone" class="col-sm-2 col-form-label-sm">Tlf.</label>
<div class="col-sm-4">
<InputText id="phone" class="form-control" @bind-Value="Activity.Phone"/>
<ValidationMessage For="@(() => Activity.Phone)"></ValidationMessage>
<InputText id="phone" class="form-control" @bind-Value="_activity.Phone"/>
<ValidationMessage For="@(() => _activity.Phone)"></ValidationMessage>
</div>
<div class="col-sm-6"></div>
<label for="vatNumber" class="col-sm-2 col-form-label-sm">Cvr/Org nr.</label>
<div class="col-sm-2">
<InputText id="vatNumber" class="form-control" @bind-Value="Activity.VatNumber"/>
<ValidationMessage For="@(() => Activity.VatNumber)"/>
<InputText id="vatNumber" class="form-control" @bind-Value="_activity.VatNumber"/>
<ValidationMessage For="@(() => _activity.VatNumber)"/>
</div>
<div class="col-sm-2">
@if (Activity.CountryCode.ToLower() == "se")
@if (_activity.CountryCode.ToLower() == "se")
{
<button type="button" class="btn btn-warning" @onclick="@TestOrgNumber">ORG Nr.</button>
}
</div>
<label for="orderMessage" class="col-sm-2 col-form-label-sm">Note /Kontor</label>
<div class="col-sm-4">
<InputTextArea id="orderMessage" class="form-control" @bind-Value="Activity.OrderMessage"/>
<ValidationMessage For="@(() => Activity.OrderMessage)"></ValidationMessage>
<InputTextArea id="orderMessage" class="form-control" @bind-Value="_activity.OrderMessage"/>
<ValidationMessage For="@(() => _activity.OrderMessage)"></ValidationMessage>
</div>
<label for="crmNote" class="col-sm-2 col-form-label-sm">Note /Selv</label>
<div class="col-sm-4">
<InputTextArea id="crmNote" class="form-control" @bind-Value="Activity.CrmNote"/>
<ValidationMessage For="@(() => Activity.CrmNote)"></ValidationMessage>
<InputTextArea id="crmNote" class="form-control" @bind-Value="_activity.CrmNote"/>
<ValidationMessage For="@(() => _activity.CrmNote)"></ValidationMessage>
</div>
}
</div>
@ -202,23 +202,23 @@ else
@*
***************** Invoice history overlay *****************************
*@
<button class="btn btn-danger" disabled="@string.IsNullOrWhiteSpace(Activity.ActivityTypeEnum)" @onclick="@ShowInvoiceOverlay">Faktura</button>
<button class="btn btn-danger" disabled="@string.IsNullOrWhiteSpace(_activity.ActivityTypeEnum)" @onclick="@ShowInvoiceOverlay">Faktura</button>
</div>
<div class="col-sm-3 d-grid mx-auto">
@*
***************** Visit hisotry overlay *****************************
*@
<button class="btn btn-warning" disabled="@string.IsNullOrWhiteSpace(Activity.ActivityTypeEnum)" @onclick="@ShowActivitiesOverlay">Tidl. besøg</button>
<button class="btn btn-warning" disabled="@string.IsNullOrWhiteSpace(_activity.ActivityTypeEnum)" @onclick="@ShowActivitiesOverlay">Tidl. besøg</button>
</div>
<div class="col-sm-3 d-grid mx-auto">
@*
***************** Product Inventory overlay *****************************
*@
<button class="btn btn-success" disabled="@string.IsNullOrWhiteSpace(Activity.ActivityTypeEnum)" @onclick="@ShowInventoryOverlay">Produkter</button>
<button class="btn btn-success" disabled="@string.IsNullOrWhiteSpace(_activity.ActivityTypeEnum)" @onclick="@ShowInventoryOverlay">Produkter</button>
</div>
</div>
<div id="this-draft" class="@(Activity.ActivityStatusEnum is "order" or "quote" ? "inno-display" : "inno-hidden")">
<div id="this-draft" class="@(_activity.ActivityStatusEnum is "order" or "quote" ? "inno-display" : "inno-hidden")">
@* Draft lines in draft -----------------------------------------------------*@
<div class="row">
<div class="col">
@ -291,7 +291,7 @@ else
@* Create Draft line ----------------------------------------------------- *@
<div class="row">
<div class="col">
@if (!string.IsNullOrWhiteSpace(SelectedItem.Name) && ShowItem)
@if (!string.IsNullOrWhiteSpace(_selectedItem.Name) && ShowItem)
{
<table id="draft-line" class="table table-bordered">
<thead>
@ -329,12 +329,12 @@ else
<td class="align-middle align-content-center justify-content-center">
<input type="checkbox" class="form-check" @bind-value="Sas"/>
</td>
<td class="align-middle">@SelectedItem.Sku</td>
<td class="align-middle">@_selectedItem.Sku</td>
<td class="align-middle">
@*
***************** Add item button *****************************
*@
<button type="button" class="btn btn-primary d-block text-sm-center" @onclick="@(() => AddItem(SelectedItem))">@Quantity stk. @SelectedItem.Name</button>
<button type="button" class="btn btn-primary d-block text-sm-center" @onclick="@(() => AddItem(_selectedItem))">@Quantity stk. @_selectedItem.Name</button>
</td>
</tr>
</tbody>
@ -344,9 +344,9 @@ else
</div>
@* end draft line ------------------------------------------------- *@
</div>
@* <div class="card" id="crmActivity"> *@
@* <div class="card" id="crm_activity"> *@
@* Delivery address *@
<div class="card mb-3 @(Activity.ActivityStatusEnum == "order" ? "inno-display" : "inno-hidden")">
<div class="card mb-3 @(_activity.ActivityStatusEnum == "order" ? "inno-display" : "inno-hidden")">
<div class="card-header text-end">
<button class="btn btn-secondary" type="button" @onclick="@(ToggleDeliveryAddress)">
Leveringsadresse
@ -357,31 +357,31 @@ else
<div class="row mb-1">
<label for="dlvName" class="col-sm-2 col-form-label-sm">Lev. Navn</label>
<div class="col-md-10">
<InputText id="dlvName" class="form-control" @bind-Value="Activity.DlvName"/>
<InputText id="dlvName" class="form-control" @bind-Value="_activity.DlvName"/>
</div>
</div>
<div class="row mb-1">
<label for="dlvAddress1" class="col-sm-2 col-form-label-sm">Lev. Adresse</label>
<div class="col-md-10">
<InputText id="dlvAddress1" class="form-control" @bind-Value="Activity.DlvAddress1"/>
<InputText id="dlvAddress1" class="form-control" @bind-Value="_activity.DlvAddress1"/>
</div>
</div>
<div class="row mb-1">
<label for="dlvAddress2" class="col-sm-2 col-form-label-sm">Lev. Adresse</label>
<div class="col-md-10">
<InputText id="dlvAddress2" class="form-control" @bind-Value="Activity.DlvAddress2"/>
<InputText id="dlvAddress2" class="form-control" @bind-Value="_activity.DlvAddress2"/>
</div>
</div>
<div class="row mb-1">
<label for="dlvZipCode" class="col-sm-2 col-form-label-sm">Lev. Postnr</label>
<div class="col-md-10">
<InputText id="dlvZipCode" class="form-control" @bind-Value="Activity.DlvZipCode"/>
<InputText id="dlvZipCode" class="form-control" @bind-Value="_activity.DlvZipCode"/>
</div>
</div>
<div class="row mb-1">
<label for="dlvCity" class="col-sm-2 col-form-label-sm">Lev. Bynavn</label>
<div class="col-md-10">
<InputText id="dlvCity" class="form-control" @bind-Value="Activity.DlvCity"/>
<InputText id="dlvCity" class="form-control" @bind-Value="_activity.DlvCity"/>
</div>
</div>
</div>
@ -392,14 +392,14 @@ else
<div class="row mb-2">
<div class="col-sm-6">
<a class="btn btn-warning" href="/advisor/customers/@Company.CompanyId"><i class="bi-chevron-left"></i> Stamkort</a>
<a class="btn btn-warning" href="/advisor/customers/@_company.CompanyId"><i class="bi-chevron-left"></i> Stamkort</a>
</div>
<div class="col-sm-4 text-end">
@*
***************** Confirm product check overlay button *****************************
***************** Continue by submitton order to erp *****************************
*@
<button type="button" class="btn btn-warning" @onclick="@ShowProductCheckOverlay" disabled="@(PoFormInvalid || Working)">
<button type="button" class="btn btn-warning" @onclick="@ShowProductCheckOverlay" disabled="@(_formInvalid || Working)">
<i class="bi-cloud-arrow-up"></i> @ButtonText
</button>
</div>
@ -409,25 +409,25 @@ else
<ConfirmWorkDateOverlay BodyMessage="@PromptDateConfirm"
OnOkClicked="WorkDateOverlayCallback" @ref="WorkDateOverlay"/>
<ProductHistoryOverlay CompanyId="@CompanyId" ItemSku="@SelectedItem.Sku" @ref="ProductOverlay"/>
<ProductHistoryOverlay CompanyId="@CompanyId" ItemSku="@_selectedItem.Sku" @ref="ProductOverlay"/>
<CatalogPagedOverlay CountryCode="@Company.CountryCode.ToLower()"
<CatalogPagedOverlay CountryCode="@_company.CountryCode.ToLower()"
OnSelected="PriceCatalogOverlayCallback" @ref="CatalogOverlay"/>
<ProductPriceHistoryOverlay CompanyId="@CompanyId" Sku="@SelectedItem.Sku"
<ProductPriceHistoryOverlay CompanyId="@CompanyId" Sku="@_selectedItem.Sku"
OnSelected="PriceHistoryOverlayCallback" @ref="PriceOverlay"/>
<ConfirmCheckOverlay BodyMessage="" CompanyId="@CompanyId"
Products="_inventoryDrawer.Content"
OnOkClicked="ProductCheckOverlayCallback" @ref="ProductCheckOverlay"/>
<CustomerActivityListOverlay CompanyName="@Company.Name"
<CustomerActivityListOverlay CompanyName="@_company.Name"
Activities="_activityDrawer.Content" @ref="ActivityListOverlay"/>
<CustomerInventoryListOverlay CompanyName="@Company.Name" CompanyId="@CompanyId" CountryCode="@Company.CountryCode"
<CustomerInventoryListOverlay CompanyName="@_company.Name" CompanyId="@CompanyId" CountryCode="@_company.CountryCode"
Inventory="_inventoryDrawer.Content"
OnSelected="InventoryOverlayCallback" @ref="InventoryListOverlay"/>
<CustomerInvoiceListOverlay Company="Company"
<CustomerInvoiceListOverlay Company="_company"
Invoices="_invoiceDrawer.Content" @ref="InvoiceListOverlay"/>

View file

@ -59,12 +59,6 @@ public partial class AdvisorActivityCreatePage : IDisposable
// #############################################################
private readonly JsonSerializerOptions _options = new() { PropertyNameCaseInsensitive = true };
private SalesItemView SelectedItem { get; set; } = new();
private UserPreference UserPreference { get; set; } = new();
private ActivityDto Activity { get; set; } = new();
private CompanyDto Company { get; set; } = new();
private EditContext? ActivityContext { get; set; }
private bool PoFormInvalid { get; set; } = true;
private bool ShowItem { get; set; }
private string Quantity { get; set; } = "1";
private string Price { get; set; } = "0";
@ -74,12 +68,11 @@ public partial class AdvisorActivityCreatePage : IDisposable
private bool InvalidActivity { get; set; } = true;
private bool ReportClosed { get; set; }
private bool Working { get; set; } = true;
private UserManagerEditView SalesRep { get; set; } = new();
private DateTime SelectedDate { get; set; }
private string PromptDateConfirm { get; set; } = "";
private string ButtonText { get; set; } = "Gem besøg";
private bool OrgWarning { get; set; }
private const string PromptDemoForgotten = "Har du glemt demo?";
// private bool OrgWarning { get; set; }
// private const string PromptDemoForgotten = "Har du glemt demo?";
private CatalogPagedOverlay CatalogOverlay { get; set; } = new();
private ProductHistoryOverlay ProductOverlay { get; set; } = new();
private ProductPriceHistoryOverlay PriceOverlay { get; set; } = new();
@ -88,60 +81,69 @@ public partial class AdvisorActivityCreatePage : IDisposable
private CustomerInvoiceListOverlay InvoiceListOverlay { get; set; } = new();
private CustomerInventoryListOverlay InventoryListOverlay { get; set; } = new();
private CustomerActivityListOverlay ActivityListOverlay { get; set; } = new();
private CompanyDto _company = new();
private bool _kanvas;
private bool _hideDeliveryAddress = true;
private InfoDrawer _infoDrawer = new();
private ActivityDrawer _activityDrawer = new();
private InventoryDrawer _inventoryDrawer = new();
private InvoiceDrawer _invoiceDrawer = new();
private SalesItemView _selectedItem = new();
private UserPreference _userPref = new();
private ActivityDto _activity = new();
private EditContext _formContext;
private UserManagerEditView _salesRep = new();
private bool _formInvalid = true;
/// <summary>
/// Page initialization
/// </summary>
protected override async Task OnInitializedAsync()
{
ActivityContext = new EditContext(Activity);
ActivityContext.OnFieldChanged += ContextHandleFieldChanged;
ActivityContext.OnValidationStateChanged += ContextValidationChanged;
_formContext = new EditContext(_activity);
_formContext.OnFieldChanged += ContextHandleFieldChanged!;
_formContext.OnValidationStateChanged += ContextValidationChanged!;
Interceptor.RegisterEvent();
Interceptor.RegisterBeforeSendEvent();
// User Preferences
UserPreference = await PreferenceService.GetProfile();
// User Info
SalesRep = await UserInfo.GetUserInfo();
_userPref = await PreferenceService.GetProfile();
_salesRep = await UserInfo.GetUserInfo();
_infoDrawer = await DrawerService.GetInfoDrawerAsync(CompanyId);
_activityDrawer = await DrawerService.GetActivityDrawerAsync(CompanyId);
_inventoryDrawer = await DrawerService.GetInventoryDrawerAsync(CompanyId);
_invoiceDrawer = await DrawerService.GetInvoiceDrawerAsync(CompanyId);
_company = await CompanyRepo.GetCompanyById(CompanyId);
Company = _infoDrawer.Content;
if (!_company.Account.StartsWith("NY"))
{
_inventoryDrawer = await DrawerService.GetInventoryDrawerAsync(CompanyId, true);
_invoiceDrawer = await DrawerService.GetInvoiceDrawerAsync(CompanyId, true);
}
if (Company.Account.StartsWith("KANVAS"))
_infoDrawer.Content = _company;
_infoDrawer.LastDateModified = DateTime.Today;
await DrawerService.StoreInfoDrawerAsync(CompanyId, _infoDrawer);
_activityDrawer = await DrawerService.GetActivityDrawerAsync(CompanyId, true);
if (_company.Account.StartsWith("KANVAS"))
{
_kanvas = true;
Activity.ActivityStatusEnum = "canvas";
Activity.ActivityTypeEnum = "canvas";
Activity.ActivityVisitEnum = "new";
PoFormInvalid = false;
_activity.ActivityStatusEnum = "canvas";
_activity.ActivityTypeEnum = "canvas";
_activity.ActivityVisitEnum = "new";
_formInvalid = false;
}
else
{
if (Company.HasFolded == 1)
if (_company.HasFolded == 1)
{
// Company has shut down
Activity.OrderMessage = "BEMÆRK: CVR nummer er ophørt.";
// _company has shut down
_activity.OrderMessage = "BEMÆRK: CVR nummer er ophørt.";
}
Activity.ActivityStatusEnum = "noSale";
_activity.ActivityStatusEnum = "noSale";
// decide if new or recall
Activity.ActivityVisitEnum = Company.Account.StartsWith("NY")
_activity.ActivityVisitEnum = _company.Account.StartsWith("NY")
? "new"
: "recall";
// if (string.IsNullOrWhiteSpace(Company.Segment) && SalesRep.CountryCode.ToLower() == "dk")
// if (string.IsNullOrWhiteSpace(_company.Segment) && _salesRep.CountryCode.ToLower() == "dk")
// {
// Toaster.ShowError("Der mangler information om Segment. Ret kunde segment, gem erp data og prøv igen.");
// // Navigator.NavigateTo($"/advisor/customers/{CompanyId}");
@ -149,48 +151,48 @@ public partial class AdvisorActivityCreatePage : IDisposable
}
// Populate base activity information
Activity.BcId = Company.BcId;
Activity.CompanyId = Company.CompanyId;
Activity.SalesRepId = SalesRep.UserId;
Activity.SalesRep = SalesRep.SalesRep;
Activity.CountryCode = SalesRep.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;
Activity.Segment = Company.Segment;
Activity.EanNumber = Company.EanNumber;
_activity.Account = _company.Account;
_activity.Address1 = _company.Address1;
_activity.Address2 = _company.Address2;
_activity.BcId = _company.BcId;
_activity.City = _company.City;
_activity.CompanyId = _company.CompanyId;
_activity.CountryCode = _salesRep.CountryCode;
_activity.DlvCity = _company.City;
_activity.DlvAddress1 = _company.Address1;
_activity.DlvAddress2 = _company.Address2;
_activity.DlvName = _company.Name;
_activity.DlvZipCode = _company.ZipCode;
_activity.EanNumber = _company.EanNumber;
_activity.Email = _company.Email;
_activity.Mobile = _company.Mobile;
_activity.Name = _company.Name;
_activity.Phone = _company.Phone;
_activity.VatNumber = _company.VatNumber;
_activity.SalesRep = _salesRep.SalesRep;
_activity.SalesRepId = _salesRep.UserId;
_activity.Segment = _company.Segment;
_activity.ZipCode = _company.ZipCode;
/*
* debug loggin
*/
// Logger.LogDebug("company.segment = {}", Company.Segment);
// Logger.LogDebug("activity.segment = {}", Activity.Segment);
// Logger.LogDebug("AdvisorActivityCreatePage => DateTime parser => {}", UserPreference.WorkDate);
// Logger.LogDebug("company.segment = {}", _company.Segment);
// Logger.LogDebug("activity.segment = {}", _activity.Segment);
// Logger.LogDebug("AdvisorActivityCreatePage => DateTime parser => {}", _userPref.WorkDate);
/*
* set selected date
*/
SelectedDate = string.IsNullOrWhiteSpace(UserPreference.WorkDate)
SelectedDate = string.IsNullOrWhiteSpace(_userPref.WorkDate)
? DateTime.Now
: DateTime.Parse(UserPreference.WorkDate);
: DateTime.Parse(_userPref.WorkDate);
// raise flag if report is closed
ReportClosed = await ReportRepo.ReportExist($"{SelectedDate:yyyy-MM-dd}");
// Ask for confirmation of date
// Logger.LogDebug("Preferences.DateConfirmed => {}", UserPreference.DateConfirmed);
if (!UserPreference.DateConfirmed)
// Logger.LogDebug("Preferences.DateConfirmed => {}", _userPref.DateConfirmed);
if (!_userPref.DateConfirmed)
{
PromptDateConfirm = $"Aktiviteter oprettes med dato {SelectedDate.ToShortDateString()}. Er dette OK?";
WorkDateOverlay.Show();
@ -200,38 +202,38 @@ public partial class AdvisorActivityCreatePage : IDisposable
if (DraftProvider.Draft.DraftType == "order")
{
// set dropdown selection accordingly
if (Activity.ActivityTypeEnum != "phone")
if (_activity.ActivityTypeEnum != "phone")
{
Activity.ActivityTypeEnum = "onSite";
_activity.ActivityTypeEnum = "onSite";
}
Activity.ActivityStatusEnum = "order";
PoFormInvalid = false;
_activity.ActivityStatusEnum = "order";
_formInvalid = false;
}
if (SalesRep.CountryCode.ToLower() == "se")
if (_salesRep.CountryCode.ToLower() == "se")
{
await TestOrgNumber();
}
Working = false;
StateHasChanged();
// StateHasChanged();
}
private async Task TestOrgNumber()
{
var result = await OrgService.GetPersonalOrgNumber(Activity.Name);
var result = await OrgService.GetPersonalOrgNumber(_activity.Name);
if (!string.IsNullOrWhiteSpace(result.PersonalId))
{
// Toaster.ShowSuccess($"PersonId for {result.CompanyName} er fundet til at være {result.PersonalId}");
Activity.VatNumber = result.PersonalId;
_activity.VatNumber = result.PersonalId;
}
}
/// <summary>
/// Show Activity Overlay
/// Show _activity Overlay
/// </summary>
private void ShowActivitiesOverlay()
{
@ -263,10 +265,10 @@ public partial class AdvisorActivityCreatePage : IDisposable
private async Task ShowProductCheckOverlay()
{
// check if new account
if (string.IsNullOrWhiteSpace(Company.Account)
|| Company.Account.StartsWith("NY")
|| Activity.ActivityStatusEnum.ToLower() == "quote"
|| Activity.ActivityStatusEnum.ToLower() == "canvas")
if (string.IsNullOrWhiteSpace(_company.Account)
|| _company.Account.StartsWith("NY")
|| _activity.ActivityStatusEnum.ToLower() == "quote"
|| _activity.ActivityStatusEnum.ToLower() == "canvas")
{
// proceed to create activity - as there is no product check to be done
await CreateActivity();
@ -309,19 +311,14 @@ public partial class AdvisorActivityCreatePage : IDisposable
{
return;
}
SelectedItem = await CatalogRepo.GetSalesItemId(SalesRep.CountryCode.ToLower(), sku.ItemId);
_selectedItem = await CatalogRepo.GetSalesItemId(_salesRep.CountryCode.ToLower(), sku.ItemId);
ShowItem = true;
Price = sku.Rate;
Quantity = sku.Quantity;
StateHasChanged();
}
/// <summary>
/// Product Price History Overlay Callback
/// </summary>
/// <param name="price"></param>
private void PriceHistoryOverlayCallback(decimal price)
{
if (price == 0)
@ -334,22 +331,15 @@ public partial class AdvisorActivityCreatePage : IDisposable
}
/// <summary>
/// Inventory Overlay Callback
/// </summary>
/// <param name="item"></param>
private void InventoryOverlayCallback(DraftItem item)
{
Activity.ActivityStatusEnum = "order";
_activity.ActivityStatusEnum = "order";
DraftProvider.Draft.DraftType = "order";
DraftProvider.Draft.Items.Add(item);
StateHasChanged();
}
/// <summary>
/// Product Check Overlay Callback
/// </summary>
private async Task ProductCheckOverlayCallback()
{
ProductCheckOverlay.Hide();
@ -362,33 +352,24 @@ public partial class AdvisorActivityCreatePage : IDisposable
await CreateActivity();
}
/// <summary>
/// Workdate Overlay Callback
/// </summary>
private async Task WorkDateOverlayCallback()
{
await PreferenceService.SetDateConfirmed(true);
Activity.ActivityDate = $"{SelectedDate:yyyy-MM-dd}";
_activity.ActivityDate = $"{SelectedDate:yyyy-MM-dd}";
WorkDateOverlay.Hide();
StateHasChanged();
}
/// <summary>
/// Workdate Changed Callback
/// </summary>
/// <param name="workDate"></param>
private async Task WorkDateChangedCallback(string workDate)
{
ReportClosed = await ReportRepo.ReportExist(workDate);
SelectedDate = DateTime.Parse(workDate);
Activity.ActivityDate = workDate;
_activity.ActivityDate = workDate;
}
/// <summary>
/// Create Activity
/// </summary>
private async Task CreateActivity()
{
if (Working)
@ -402,20 +383,20 @@ public partial class AdvisorActivityCreatePage : IDisposable
switch (_kanvas)
{
/*
* validate customer address1 is required when Activity is order or quote
* validate customer address1 is required when _activity is order or quote
*/
case false when string.IsNullOrWhiteSpace(Activity.Address1) && Activity.ActivityStatusEnum is "order" or "quote":
case false when string.IsNullOrWhiteSpace(_activity.Address1) && _activity.ActivityStatusEnum is "order" or "quote":
Toaster.ShowError("Kunde adresse er ufuldstændig.");
return;
/*
* valid OrganisationNumber is required when Activity is order or quote
* valid OrganisationNumber is required when _activity is order or quote
*/
case false when !VatUtils.ValidateFormat(Company.CountryCode, Activity.VatNumber) && Activity.ActivityStatusEnum is "order" or "quote":
case false when !VatUtils.ValidateFormat(_company.CountryCode, _activity.VatNumber) && _activity.ActivityStatusEnum is "order" or "quote":
Toaster.ShowError("Firma registreringsnummer er ikke korrekt.");
return;
}
switch (Activity.ActivityStatusEnum)
switch (_activity.ActivityStatusEnum)
{
/*
* don't accept Draft with no Items
@ -426,13 +407,13 @@ public partial class AdvisorActivityCreatePage : IDisposable
/*
* phone number is required if first time customer
*/
case "order" when Company.Account.StartsWith("NY") && string.IsNullOrWhiteSpace(Activity.Phone):
case "order" when _company.Account.StartsWith("NY") && 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):
case "quote" when !Utils.IsValidEmail(_activity.Email):
Toaster.ShowError("Ved tilbud skal en gyldig email adresse angives.");
return;
}
@ -440,34 +421,35 @@ public partial class AdvisorActivityCreatePage : IDisposable
* set Workgin flag (prevents other actions while working)
*/
Working = true;
Toaster.ShowWarning("Arbejder på det... Vent venligst...");
/*
* reset local variable
*/
SelectedItem = new SalesItemView();
_selectedItem = new SalesItemView();
/*
* ensure date is SelectedDate
*/
Activity.ActivityDate = $"{SelectedDate:yyyy-MM-dd}";
_activity.ActivityDate = $"{SelectedDate:yyyy-MM-dd}";
/*
* Generate OurRef from activity type and user FirstName
*/
Activity.OurRef = Activity.ActivityTypeEnum switch
_activity.OurRef = _activity.ActivityTypeEnum switch
{
"phone" => $"T:{SalesRep.FirstName}",
"onSite" => $"B:{SalesRep.FirstName}",
"phone" => $"T:{_salesRep.FirstName}",
"onSite" => $"B:{_salesRep.FirstName}",
_ => ""
};
if (Activity.Express)
if (_activity.Express)
{
/*
* add `E` to indicate express
*/
Activity.OurRef = $"E{Activity.OurRef}";
_activity.OurRef = $"E{_activity.OurRef}";
}
/*
* generate lines from draft
*/
Activity.Lines = new List<ActivityLineDto>();
_activity.Lines = new List<ActivityLineDto>();
var ln = 0;
if (DraftProvider.Draft.Items.Count != 0)
{
@ -485,12 +467,12 @@ public partial class AdvisorActivityCreatePage : IDisposable
Location = item.Item.Location
})
.ToList();
Activity.Lines = lines;
_activity.Lines = lines;
}
/*
* send reqeust
*/
var result = await ActivityRepo.CreateActivity(Activity);
var result = await ActivityRepo.CreateActivity(_activity);
if (result.IsSuccess)
{
/*
@ -535,16 +517,16 @@ public partial class AdvisorActivityCreatePage : IDisposable
// // return;
// // }
// // OrgWarning = true;
// if (Company.CountryCode.ToLower() == "se"
// && Utils.StringToDigits(Activity.VatNumber).Length < 10
// && Activity.ActivityStatusEnum == "order")
// if (_company.CountryCode.ToLower() == "se"
// && Utils.StringToDigits(_activity.VatNumber).Length < 10
// && _activity.ActivityStatusEnum == "order")
// {
// // Toaster.ShowWarning("Org nummer er ufuldstændig. Skal opdateres før bestilling kan sendes.");
// // Toaster.ShowInfo("Vent mens vi soger at finde de manglende cifre ...");
// var result = await OrgService.GetPersonalOrgNumber(Activity.Name);
// var result = await OrgService.GetPersonalOrgNumber(_activity.Name);
// if (!string.IsNullOrWhiteSpace(result.PersonalId))
// {
// Activity.VatNumber = result.PersonalId;
// _activity.VatNumber = result.PersonalId;
// Toaster.ShowSuccess($"Org nummer for {result.CompanyName} er fundet at være {result.PersonalId}.");
// }
// }
@ -552,24 +534,16 @@ public partial class AdvisorActivityCreatePage : IDisposable
// }
/// <summary>
/// Remove Current Draft
/// </summary>
private async Task DeleteDraft()
{
await DraftProvider.DeleteDraftAsync();
Activity.ActivityStatusEnum = "noSale";
_activity.ActivityStatusEnum = "noSale";
}
/// <summary>
/// Add Item To Draft
/// </summary>
/// <param name="salesItem"></param>
private async Task AddItem(SalesItemView salesItem)
{
ShowItem = false;
// create a new cart item
var item = new DraftItem
{
Item = salesItem,
@ -578,27 +552,19 @@ public partial class AdvisorActivityCreatePage : IDisposable
Discount = Convert.ToDecimal(Discount, CultureInfo.InvariantCulture),
Sas = Sas
};
// reset internals to initial state
Sas = false;
Quantity = "1";
Price = "0";
Discount = "0";
// add it to the cart
DraftProvider.Draft.Items.Add(item);
if (Activity.ActivityStatusEnum != "quote")
if (_activity.ActivityStatusEnum != "quote")
{
Activity.ActivityStatusEnum = "order";
_activity.ActivityStatusEnum = "order";
}
// save the item using the CartStateProvider's save method
await DraftProvider.SaveChangesAsync();
}
/// <summary>
/// Remove Item From Draft
/// </summary>
/// <param name="item"></param>
private async Task RemoveItem(DraftItem item)
{
// remove item
@ -607,29 +573,22 @@ public partial class AdvisorActivityCreatePage : IDisposable
await DraftProvider.SaveChangesAsync();
if (!DraftProvider.Draft.Items.Any())
{
Activity.ActivityStatusEnum = "noSale";
_activity.ActivityStatusEnum = "noSale";
}
}
/// <summary>
/// EditContext Field Changed Callback
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
/// <exception cref="ArgumentOutOfRangeException"></exception>
private void ContextHandleFieldChanged(object sender, FieldChangedEventArgs e)
{
Logger.LogDebug("ActivityNewPage => ContextHandleFieldChanged => ActivityStatusEnum <= '{}'",
Activity.ActivityStatusEnum);
DraftProvider.Draft.DraftType = Activity.ActivityStatusEnum;
if (Activity.ActivityStatusEnum == "noSale")
Logger.LogDebug("ActivityNewPage => FieldChanged => ActivityStatusEnum <= '{}'", _activity.ActivityStatusEnum);
DraftProvider.Draft.DraftType = _activity.ActivityStatusEnum;
if (_activity.ActivityStatusEnum == "noSale")
{
Logger.LogDebug("ActivityNewPage => ActivityStatusEnum == 'noSale' <= remove items");
DraftProvider.Draft.Items = new List<DraftItem>();
}
ButtonText = Activity.ActivityStatusEnum.ToLower() switch
ButtonText = _activity.ActivityStatusEnum.ToLower() switch
{
"nosale" => "Gem Besøg",
"order" => "Send Bestilling",
@ -639,19 +598,20 @@ public partial class AdvisorActivityCreatePage : IDisposable
// InvalidCanvas = InvalidActivityType;
InvalidActivity = InvalidActivityType
|| PoFormInvalid
|| _formInvalid
|| DraftProvider.Draft.Items.Count == 0
|| (Activity.ActivityStatusEnum == "offer"
&& string.IsNullOrWhiteSpace(Activity.Email));
if (Activity.YourRef.Length > 35
|| Activity.ReferenceNumber.Length > 20
|| (_activity.ActivityStatusEnum == "quote"
&& string.IsNullOrWhiteSpace(_activity.Email));
if (_activity.YourRef.Length > 35
|| _activity.ReferenceNumber.Length > 20
|| InvalidActivity)
{
PoFormInvalid = true;
_formInvalid = true;
return;
}
PoFormInvalid = !ActivityContext.Validate();
_formInvalid = !_formContext.Validate();
StateHasChanged();
}
@ -663,28 +623,28 @@ public partial class AdvisorActivityCreatePage : IDisposable
/// <param name="e"></param>
private void ContextValidationChanged(object sender, ValidationStateChangedEventArgs e)
{
if (string.IsNullOrEmpty(Activity.ActivityTypeEnum) && !ReportClosed)
if (string.IsNullOrEmpty(_activity.ActivityTypeEnum) && !ReportClosed)
{
Toaster.ShowWarning("Aktivitet type kan ikke være tom");
PoFormInvalid = true;
_formInvalid = true;
return;
}
if (Activity.ActivityStatusEnum.ToLower() is "order" or "quote"
&& Company.CountryCode.ToLower() == "se"
&& Utils.StringToDigits(Activity.VatNumber).Length < 10)
if (_activity.ActivityStatusEnum.ToLower() is "order" or "quote"
&& _company.CountryCode.ToLower() == "se"
&& Utils.StringToDigits(_activity.VatNumber).Length < 10)
{
Toaster.ShowError("Org nummer er ufuldstændig ...");
// ShowOrgWarning();
// return;
}
PoFormInvalid = false;
ActivityContext.OnFieldChanged -= ContextHandleFieldChanged;
ActivityContext.OnValidationStateChanged -= ContextValidationChanged;
ActivityContext = new EditContext(Activity);
ActivityContext.OnFieldChanged += ContextHandleFieldChanged;
ActivityContext.OnValidationStateChanged += ContextValidationChanged;
_formInvalid = false;
_formContext.OnFieldChanged -= ContextHandleFieldChanged;
_formContext.OnValidationStateChanged -= ContextValidationChanged;
_formContext = new EditContext(_activity);
_formContext.OnFieldChanged += ContextHandleFieldChanged;
_formContext.OnValidationStateChanged += ContextValidationChanged;
}
@ -694,7 +654,7 @@ public partial class AdvisorActivityCreatePage : IDisposable
public void Dispose()
{
Interceptor.DisposeEvent();
ActivityContext.OnFieldChanged -= ContextHandleFieldChanged;
ActivityContext.OnValidationStateChanged -= ContextValidationChanged;
_formContext.OnFieldChanged -= ContextHandleFieldChanged;
_formContext.OnValidationStateChanged -= ContextValidationChanged;
}
}