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

View file

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