checking - HTTP repositories

This commit is contained in:
Frede Hundewadt 2023-11-16 18:28:42 +01:00
parent e13c08937e
commit 6776b3ca6d
10 changed files with 205 additions and 172 deletions

View file

@ -53,7 +53,7 @@
</div> </div>
<div class="col-sm-3"> <div class="col-sm-3">
<button type="button" class="btn btn-outline-dark me-2" @onclick="@(() => SetQuote(quote.ESalesNumber, QuoteStatus.Lose))"> <button type="button" class="btn btn-outline-dark me-2" @onclick="@(() => SetQuote(quote.ESalesNumber, QuoteStatus.Lose))">
<i class="bi-trash-fill"></i> <i class="bi-trash-2-fill"></i>
</button> </button>
<button type="button" class="btn btn-outline-dark me-2" @onclick="@(() => SetQuote(quote.ESalesNumber, QuoteStatus.Archive))"> <button type="button" class="btn btn-outline-dark me-2" @onclick="@(() => SetQuote(quote.ESalesNumber, QuoteStatus.Archive))">
<i class="bi-archive-fill"></i> <i class="bi-archive-fill"></i>
@ -75,7 +75,9 @@
<i class="bi-question-circle-fill" style="font-size: 1.2rem"></i> <i class="bi-question-circle-fill" style="font-size: 1.2rem"></i>
break; break;
case "Lose": case "Lose":
<i class="bi-trash-fill" style="font-size: 1.2rem"></i> <button type="button" class="btn btn-outline-danger me-2" @onclick="@(() => SetQuote(quote.ESalesNumber, QuoteStatus.Trash))">
<i class="bi-trash-fill" style="font-size: 1.2rem"></i>
</button>
break; break;
case "Note": case "Note":
<i class="bi-tag-fill" style="font-size: 1.2rem"></i> <i class="bi-tag-fill" style="font-size: 1.2rem"></i>

View file

@ -21,8 +21,20 @@ public enum QuoteStatus
None, None,
Order, Order,
Lose, Lose,
Archive,
Note, Note,
Archive,
Trash,
All, All,
NoteOpen NoteOpen
} }
// public enum QuoteStatus
// {
// None,
// Order,
// Lose,
// Archive,
// Note,
// All,
// NoteOpen
// }

View file

@ -62,7 +62,6 @@ public class AdvisorActivityRepository : IAdvisorActivityRepository
{ {
return new List<ReportItemView>(); return new List<ReportItemView>();
} }
return JsonSerializer.Deserialize<List<ReportItemView>>(content, _options) ?? new List<ReportItemView>(); return JsonSerializer.Deserialize<List<ReportItemView>>(content, _options) ?? new List<ReportItemView>();
} }
@ -73,7 +72,7 @@ public class AdvisorActivityRepository : IAdvisorActivityRepository
/// <returns></returns> /// <returns></returns>
public async Task<ApiResponseView> UpdateQuoteStatus(ReportItemView activity) public async Task<ApiResponseView> UpdateQuoteStatus(ReportItemView activity)
{ {
var resp = new ApiResponseView var responseView = new ApiResponseView
{ {
Code = 404, Code = 404,
IsSuccess = false, IsSuccess = false,
@ -85,11 +84,10 @@ public class AdvisorActivityRepository : IAdvisorActivityRepository
var content = await response.Content.ReadAsStringAsync(); var content = await response.Content.ReadAsStringAsync();
if (string.IsNullOrWhiteSpace(content)) if (string.IsNullOrWhiteSpace(content))
{ {
return resp; return responseView;
} }
_logger.LogDebug("UpdateQuote Response Content <= {}", content); _logger.LogDebug("UpdateQuote Response Content <= {}", content);
return JsonSerializer.Deserialize<ApiResponseView>(content, _options) ?? resp; return JsonSerializer.Deserialize<ApiResponseView>(content, _options) ?? responseView;
} }
/// <summary> /// <summary>
@ -124,12 +122,10 @@ public class AdvisorActivityRepository : IAdvisorActivityRepository
{ {
var response = await _client var response = await _client
.GetAsync($"{_api.CrmActivities}/date/{activityDate}"); .GetAsync($"{_api.CrmActivities}/date/{activityDate}");
if (!response.IsSuccessStatusCode)
return new ReportStatusView();
var content = await response.Content.ReadAsStringAsync(); var content = await response.Content.ReadAsStringAsync();
return string.IsNullOrWhiteSpace(content) if (!response.IsSuccessStatusCode || string.IsNullOrWhiteSpace(content))
? new ReportStatusView() return new ReportStatusView();
: JsonSerializer.Deserialize<ReportStatusView>(content, _options); return JsonSerializer.Deserialize<ReportStatusView>(content, _options) ?? new ReportStatusView();
} }
/// <summary> /// <summary>
@ -153,11 +149,9 @@ public class AdvisorActivityRepository : IAdvisorActivityRepository
{ {
var response = await _client.GetAsync($"{_api.CrmActivities}/company/{customerId}"); var response = await _client.GetAsync($"{_api.CrmActivities}/company/{customerId}");
var content = await response.Content.ReadAsStringAsync(); var content = await response.Content.ReadAsStringAsync();
if (!response.IsSuccessStatusCode) if (!response.IsSuccessStatusCode || string.IsNullOrWhiteSpace(content))
return new List<ReportItemView>(); return new List<ReportItemView>();
return string.IsNullOrWhiteSpace(content) return JsonSerializer.Deserialize<List<ReportItemView>>(content, _options) ?? new List<ReportItemView>();
? new List<ReportItemView>()
: JsonSerializer.Deserialize<List<ReportItemView>>(content, _options);
} }
/// <summary> /// <summary>

View file

@ -60,7 +60,7 @@ public class AdvisorCustomerHistoryRepository : IAdvisorCustomerHistoryRepositor
public async Task<InvoiceListView> GetInvoiceListHeader(string companyId) public async Task<InvoiceListView> GetInvoiceListHeader(string companyId)
{ {
var response = await _client.GetAsync($"{_api.CrmCustomers}/{companyId}/invoices"); var response = await _client.GetAsync($"{_api.CrmCustomers}/{companyId}/invoices/head");
var content = await response.Content.ReadAsStringAsync(); var content = await response.Content.ReadAsStringAsync();
if (!response.IsSuccessStatusCode || string.IsNullOrWhiteSpace(content)) if (!response.IsSuccessStatusCode || string.IsNullOrWhiteSpace(content))
{ {

View file

@ -36,12 +36,12 @@ public class CabinetDrawerService : ICabinetDrawerService
} }
public async Task<ActivityDrawer> GetActivityDrawerAsync(string companyId, bool force = false) public async Task<ActivityDrawer> GetActivityDrawerAsync(string companyId, bool forceBackend = false)
{ {
var drawer = await _asyncStorageService var drawer = await _asyncStorageService
.GetItemAsync<ActivityDrawer>($"{companyId}.{ActivityDrawer.Label}"); .GetItemAsync<ActivityDrawer>($"{companyId}.{ActivityDrawer.Label}");
if (drawer == null) force = true; if (drawer == null) forceBackend = true;
if (!force) return drawer ?? new ActivityDrawer(); if (!forceBackend) return drawer ?? new ActivityDrawer();
var result = await _activityRepo.GetCustomerActivities(companyId); var result = await _activityRepo.GetCustomerActivities(companyId);
drawer = new ActivityDrawer drawer = new ActivityDrawer
{ {
@ -53,13 +53,13 @@ public class CabinetDrawerService : ICabinetDrawerService
} }
public async Task<CatalogDrawer> GetCatalogDrawerAsync(string countryCode, bool force = false) public async Task<CatalogDrawer> GetCatalogDrawerAsync(string countryCode, bool forceBackend = false)
{ {
var drawer = await _asyncStorageService var drawer = await _asyncStorageService
.GetItemAsync<CatalogDrawer>($"{countryCode}.{CatalogDrawer.Label}"); .GetItemAsync<CatalogDrawer>($"{countryCode}.{CatalogDrawer.Label}");
if (drawer == null) force = true; if (drawer == null) forceBackend = true;
if (!force) return drawer ?? new CatalogDrawer(); if (!forceBackend) return drawer ?? new CatalogDrawer();
var result = await _priceCatalogRepo.GetPriceList(countryCode); var result = await _priceCatalogRepo.GetPriceList(countryCode);
drawer = new CatalogDrawer drawer = new CatalogDrawer
{ {
@ -71,13 +71,13 @@ public class CabinetDrawerService : ICabinetDrawerService
} }
public async Task<InfoDrawer> GetInfoDrawerAsync(string companyId, bool force = false) public async Task<InfoDrawer> GetInfoDrawerAsync(string companyId, bool forceBackend = false)
{ {
var drawer = await _asyncStorageService var drawer = await _asyncStorageService
.GetItemAsync<InfoDrawer>($"{companyId}.{InfoDrawer.Label}"); .GetItemAsync<InfoDrawer>($"{companyId}.{InfoDrawer.Label}");
if (drawer == null) force = true; if (drawer == null) forceBackend = true;
if (!force) return drawer ?? new InfoDrawer(); if (!forceBackend) return drawer ?? new InfoDrawer();
var result = await _customerRepo.GetCompanyById(companyId); var result = await _customerRepo.GetCompanyById(companyId);
drawer = new InfoDrawer drawer = new InfoDrawer
{ {
@ -85,17 +85,17 @@ public class CabinetDrawerService : ICabinetDrawerService
Content = result Content = result
}; };
await StoreInfoDrawerAsync(companyId, drawer); await StoreInfoDrawerAsync(companyId, drawer);
return drawer ?? new InfoDrawer(); return drawer;
} }
public async Task<InventoryDrawer> GetInventoryDrawerAsync(string companyId, bool force = false) public async Task<InventoryDrawer> GetInventoryDrawerAsync(string companyId, bool forceBackend = false)
{ {
var drawer = await _asyncStorageService var drawer = await _asyncStorageService
.GetItemAsync<InventoryDrawer>($"{companyId}.{InventoryDrawer.Label}"); .GetItemAsync<InventoryDrawer>($"{companyId}.{InventoryDrawer.Label}");
if (drawer == null) force = true; if (drawer == null) forceBackend = true;
if (!force) return drawer ?? new InventoryDrawer(); if (!forceBackend) return drawer ?? new InventoryDrawer();
var result = await _historyRepo.GetInventory(companyId); var result = await _historyRepo.GetInventory(companyId);
drawer = new InventoryDrawer drawer = new InventoryDrawer
{ {
@ -107,12 +107,12 @@ public class CabinetDrawerService : ICabinetDrawerService
} }
public async Task<InvoiceDrawer> GetInvoiceDrawerAsync(string companyId, bool force = false) public async Task<InvoiceDrawer> GetInvoiceDrawerAsync(string companyId, bool forceBackend = false)
{ {
var drawer = await _asyncStorageService var drawer = await _asyncStorageService
.GetItemAsync<InvoiceDrawer>($"{companyId}.{InvoiceDrawer.Label}"); .GetItemAsync<InvoiceDrawer>($"{companyId}.{InvoiceDrawer.Label}");
if (drawer == null) force = true; if (drawer == null) forceBackend = true;
if (!force) return drawer ?? new InvoiceDrawer(); if (!forceBackend) return drawer ?? new InvoiceDrawer();
var result = await _historyRepo.GetInvoiceList(companyId); var result = await _historyRepo.GetInvoiceList(companyId);
drawer = new InvoiceDrawer drawer = new InvoiceDrawer
{ {
@ -120,17 +120,17 @@ public class CabinetDrawerService : ICabinetDrawerService
Content = result Content = result
}; };
await StoreInvoiceDrawerAsync(companyId, drawer); await StoreInvoiceDrawerAsync(companyId, drawer);
return drawer ?? new InvoiceDrawer(); return drawer;
} }
public async Task<StatisticDrawer> GetStatisticDrawerAsync(string companyId, bool force = false) public async Task<StatisticDrawer> GetStatisticDrawerAsync(string companyId, bool forceBackend = false)
{ {
var drawer = await _asyncStorageService var drawer = await _asyncStorageService
.GetItemAsync<StatisticDrawer>($"{companyId}.{StatisticDrawer.Label}"); .GetItemAsync<StatisticDrawer>($"{companyId}.{StatisticDrawer.Label}");
if (drawer == null) force = true; if (drawer == null) forceBackend = true;
if (!force) return drawer ?? new StatisticDrawer(); if (!forceBackend) return drawer ?? new StatisticDrawer();
var result = await _historyRepo.GetProductInvoiceLines(companyId); var result = await _historyRepo.GetProductInvoiceLines(companyId);
var content = result.Select(x => new InventoryItem var content = result.Select(x => new InventoryItem
{ {
@ -153,7 +153,7 @@ public class CabinetDrawerService : ICabinetDrawerService
public async Task StoreActivityDrawerAsync(string companyId, ActivityDrawer drawer) public async Task StoreActivityDrawerAsync(string companyId, ActivityDrawer drawer)
{ {
if (drawer.Content.Any()) if (drawer.Content.Count != 0)
{ {
drawer.Content = drawer.Content.OrderByDescending(x => x.OrderDate).ToList(); drawer.Content = drawer.Content.OrderByDescending(x => x.OrderDate).ToList();
} }
@ -176,7 +176,7 @@ public class CabinetDrawerService : ICabinetDrawerService
public async Task StoreInventoryDrawerAsync(string companyId, InventoryDrawer drawer) public async Task StoreInventoryDrawerAsync(string companyId, InventoryDrawer drawer)
{ {
if (drawer.Content.Any()) if (drawer.Content.Count != 0)
{ {
drawer.Content = drawer.Content.OrderByDescending(x => x.LastInvoiceDate).ToList(); drawer.Content = drawer.Content.OrderByDescending(x => x.LastInvoiceDate).ToList();
} }
@ -187,7 +187,7 @@ public class CabinetDrawerService : ICabinetDrawerService
public async Task StoreInvoiceDrawerAsync(string companyId, InvoiceDrawer drawer) public async Task StoreInvoiceDrawerAsync(string companyId, InvoiceDrawer drawer)
{ {
if (drawer.Content.Any()) if (drawer.Content.Count != 0)
{ {
drawer.Content = drawer.Content.OrderByDescending(x => x.DocumentDate).ToList(); drawer.Content = drawer.Content.OrderByDescending(x => x.DocumentDate).ToList();
} }
@ -198,7 +198,7 @@ public class CabinetDrawerService : ICabinetDrawerService
public async Task StoreStatisticDrawerAsync(string companyId, StatisticDrawer drawer) public async Task StoreStatisticDrawerAsync(string companyId, StatisticDrawer drawer)
{ {
if (drawer.Content.Any()) if (drawer.Content.Count != 0)
{ {
drawer.Content = drawer.Content.OrderByDescending(x => x.DeliveryDate).ToList(); drawer.Content = drawer.Content.OrderByDescending(x => x.DeliveryDate).ToList();
} }

View file

@ -6,12 +6,12 @@ namespace Wonky.Client.Local.Services;
public interface ICabinetDrawerService public interface ICabinetDrawerService
{ {
Task<ActivityDrawer> GetActivityDrawerAsync(string companyId, bool force = false); Task<ActivityDrawer> GetActivityDrawerAsync(string companyId, bool forceBackend = false);
Task<CatalogDrawer> GetCatalogDrawerAsync(string countryCode, bool force = false); Task<CatalogDrawer> GetCatalogDrawerAsync(string countryCode, bool forceBackend = false);
Task<InfoDrawer> GetInfoDrawerAsync(string companyId, bool force = false); Task<InfoDrawer> GetInfoDrawerAsync(string companyId, bool forceBackend = false);
Task<InventoryDrawer> GetInventoryDrawerAsync(string companyId, bool force = false); Task<InventoryDrawer> GetInventoryDrawerAsync(string companyId, bool forceBackend = false);
Task<InvoiceDrawer> GetInvoiceDrawerAsync(string companyId, bool force = false); Task<InvoiceDrawer> GetInvoiceDrawerAsync(string companyId, bool forceBackend = false);
Task<StatisticDrawer> GetStatisticDrawerAsync(string companyId, bool force = false); Task<StatisticDrawer> GetStatisticDrawerAsync(string companyId, bool forceBackend = false);
Task StoreActivityDrawerAsync(string companyId, ActivityDrawer drawer); Task StoreActivityDrawerAsync(string companyId, ActivityDrawer drawer);
Task StoreCatalogDrawerAsync(string countryCode, CatalogDrawer drawer); Task StoreCatalogDrawerAsync(string countryCode, CatalogDrawer drawer);

View file

@ -64,7 +64,7 @@ public partial class AdvisorCustomerCreatePage : IDisposable
CompanyContext.OnValidationStateChanged += ValidationChanged; CompanyContext.OnValidationStateChanged += ValidationChanged;
UserInfo = await UserInfoService.GetUserInfo(); UserInfo = await UserInfoService.GetUserInfo();
Dk = UserInfo.CountryCode.ToLower() == "dk"; Dk = UserInfo.CountryCode.Equals("dk", StringComparison.CurrentCultureIgnoreCase);
Company.SalesRepId = UserInfo.UserId; Company.SalesRepId = UserInfo.UserId;
Company.CountryCode = UserInfo.CountryCode.ToLower(); Company.CountryCode = UserInfo.CountryCode.ToLower();
@ -95,7 +95,7 @@ public partial class AdvisorCustomerCreatePage : IDisposable
Logger.LogDebug("CrmCompanyView => SelectCompanyCallback => {}", JsonSerializer.Serialize(regInfo)); Logger.LogDebug("CrmCompanyView => SelectCompanyCallback => {}", JsonSerializer.Serialize(regInfo));
// this can be removed in favor of the new data returned from updating the VatNumber // this can be removed in favor of the new data returned from updating the VatNumber
RegState = regInfo.States[0].State.ToLower() == "normal" ? "the-good" : "the-dead"; RegState = regInfo.States[0].State.Equals("normal", StringComparison.CurrentCultureIgnoreCase) ? "the-good" : "the-dead";
if (regInfo.SyncAll) if (regInfo.SyncAll)
{ {
Company.Name = regInfo.Name; Company.Name = regInfo.Name;

View file

@ -55,7 +55,7 @@ public partial class AdvisorCustomerViewEditPage : IDisposable
// ########################################################################### // ###########################################################################
[Parameter] public string CompanyId { get; set; } = ""; [Parameter] public string CompanyId { get; set; } = "";
// ########################################################################### // ###########################################################################
private EditContext _erpFormContext; private EditContext _erpFormContext;
private DateTime _lastVisit; private DateTime _lastVisit;
@ -67,7 +67,9 @@ public partial class AdvisorCustomerViewEditPage : IDisposable
private VatLookupDkModal _vatLookupPopup = new(); private VatLookupDkModal _vatLookupPopup = new();
private List<ContactDto> _contacts = new(); private List<ContactDto> _contacts = new();
private string VatState { get; set; } = "the-ugly"; private string VatState { get; set; } = "the-ugly";
private bool _validVat; private bool _validVat;
// private bool _hasFolded; // private bool _hasFolded;
// private string _currentVat = ""; // private string _currentVat = "";
private string _countryCode = "dk"; private string _countryCode = "dk";
@ -82,7 +84,9 @@ public partial class AdvisorCustomerViewEditPage : IDisposable
private string _activitiesLink = ""; private string _activitiesLink = "";
private string _invoiceLink = ""; private string _invoiceLink = "";
private string _newActivityLink = ""; private string _newActivityLink = "";
private int _enableLink = 1; private int _enableLink = 1;
// private ActivityDrawer _activityDrawer = new(); // private ActivityDrawer _activityDrawer = new();
// private InventoryDrawer _inventoryDrawer = new(); // private InventoryDrawer _inventoryDrawer = new();
// private InvoiceDrawer _invoiceDrawer = new(); // private InvoiceDrawer _invoiceDrawer = new();
@ -92,7 +96,7 @@ public partial class AdvisorCustomerViewEditPage : IDisposable
private CompanyDto _company = new(); private CompanyDto _company = new();
// private string _companyId = ""; // private string _companyId = "";
protected override async Task OnInitializedAsync() protected override async Task OnInitializedAsync()
{ {
/* /*
@ -128,15 +132,15 @@ public partial class AdvisorCustomerViewEditPage : IDisposable
{ {
Navigator.NavigateTo($"/advisor/customers/{CompanyId}/activities/new"); Navigator.NavigateTo($"/advisor/customers/{CompanyId}/activities/new");
} }
/* /*
* fetch user info from local storage * fetch user info from local storage
*/ */
_userInfo = await UserInfoService.GetUserInfo(); _userInfo = await UserInfoService.GetUserInfo();
_countryCode = _userInfo.CountryCode.ToLower(); _countryCode = _userInfo.CountryCode.ToLower();
_countryIsDk = _countryCode == "dk"; _countryIsDk = _countryCode == "dk";
_infoDrawer = await DrawerService.GetInfoDrawerAsync(CompanyId); _infoDrawer = await DrawerService.GetInfoDrawerAsync(CompanyId, forceBackend: true);
_infoDrawer.Content = _company;
await DrawerService.StoreInfoDrawerAsync(CompanyId, _infoDrawer);
/* /*
* internal _enableActivity flag * internal _enableActivity flag
*/ */
@ -149,86 +153,91 @@ public partial class AdvisorCustomerViewEditPage : IDisposable
{ {
_enableActivity = 1; _enableActivity = 1;
} }
/* /*
* only execute if the InfoDrawer.Company is not KANVAS * only execute if the InfoDrawer.Company is not KANVAS
*/ */
Logger.LogDebug("_company => {}", JsonSerializer.Serialize(_company)); Logger.LogDebug("_company => {}", JsonSerializer.Serialize(_company));
/* /*
* toggle view button text * toggle view button text
*/ */
_toggleButtonText = _company.IsHidden == 0 ? "Udelad kunde i oversigt" : "Brug Normal Visning"; _toggleButtonText = _company.IsHidden == 0 ? "Udelad kunde i oversigt" : "Brug Normal Visning";
// _currentVat = _company.VatNumber; // _currentVat = _company.VatNumber;
_company.CountryCode = _userInfo.CountryCode.ToLower(); _company.CountryCode = _userInfo.CountryCode.ToLower();
/* /*
* visit interval init * visit interval init
*/ */
if (_company.Interval == 0) if (_company.Interval == 0)
{ {
_company.Interval = 8; _company.Interval = 8;
} }
/*
* visit date init
*/
_lastVisit = DateTime.Parse(_company.LastVisit);
_nextVisit = DateTime.Parse(_company.NextVisit);
/*
* if no previous visit is registered - force last visit date to 2020
*/
if (_lastVisit.Year < 2020)
{
_lastVisit = DateTime.Parse("2020-01-01");
}
/*
* set next visit according to last visit and interval
*/
if (!_company.ValidDateSpan())
{
_nextVisit = _lastVisit.AddDays(_company.Interval * 7);
}
/*
* display urgency of next visit
*/
_visitStateCss = Mapper.MapVisitState($"{_nextVisit:yyyy-MM-dd}");
/*
* handle InfoDrawer.Company out of business case
*/
if (_company.HasFolded == 1)
{
/*
* this is only used if user has selected to show closed companies
*/
// _hasFolded = true;
VatState = "the-dead";
_visitStateCss = "the-dead";
}
else
{
/*
* vat validation flags
*/
_company.ValidVat = VatUtils.ValidateFormat(_company.CountryCode, _company.VatNumber) ? 1 : 0;
_validVat = _company.ValidVat == 1; // true/false flag set if InfoDrawer.Company has a valid vatNumber
VatState = _company.ValidVat == 1 ? "the-good" : "no-vat"; // assign css class
}
if (_countryIsDk) /*
{ * visit date init
_companyVatAddress = PrepareVatAddress(_company); */
} _lastVisit = DateTime.Parse(_company.LastVisit);
// await GetContacts(CompanyId); _nextVisit = DateTime.Parse(_company.NextVisit);
/*
* if no previous visit is registered - force last visit date to 2020
*/
if (_lastVisit.Year < 2020)
{
_lastVisit = DateTime.Parse("2020-01-01");
}
/*
* set next visit according to last visit and interval
*/
if (!_company.ValidDateSpan())
{
_nextVisit = _lastVisit.AddDays(_company.Interval * 7);
}
/*
* display urgency of next visit
*/
_visitStateCss = Mapper.MapVisitState($"{_nextVisit:yyyy-MM-dd}");
/*
* handle InfoDrawer.Company out of business case
*/
if (_company.HasFolded == 1)
{
/*
* this is only used if user has selected to show closed companies
*/
// _hasFolded = true;
VatState = "the-dead";
_visitStateCss = "the-dead";
}
else
{
/*
* vat validation flags
*/
_company.ValidVat = VatUtils.ValidateFormat(_company.CountryCode, _company.VatNumber) ? 1 : 0;
_validVat = _company.ValidVat == 1; // true/false flag set if InfoDrawer.Company has a valid vatNumber
VatState = _company.ValidVat == 1 ? "the-good" : "no-vat"; // assign css class
}
if (_countryIsDk)
{
_companyVatAddress = PrepareVatAddress(_company);
}
// await GetContacts(CompanyId);
/* /*
* remove loading image * remove loading image
*/ */
_working = false; _working = false;
} }
protected override async Task OnAfterRenderAsync(bool firstRender) protected override async Task OnAfterRenderAsync(bool firstRender)
{ {
if (firstRender) if (firstRender)
{ {
await GetContacts(CompanyId); await GetContacts(CompanyId);
_ = await DrawerService.GetActivityDrawerAsync(CompanyId, force:true); await DrawerService.GetActivityDrawerAsync(CompanyId, forceBackend: true);
if (!_company.Account.StartsWith("NY")) if (!_company.Account.StartsWith("NY"))
{ {
await ReloadHistory(); await ReloadHistory();
@ -236,45 +245,50 @@ public partial class AdvisorCustomerViewEditPage : IDisposable
} }
} }
private async Task ReloadHistory(bool force = false) private async Task ReloadHistory(bool forceBackend = false)
{ {
if (force) if (forceBackend)
{ {
Toaster.ShowInfo("Afventer svar fra tjenester ..."); Toaster.ShowInfo("Afventer svar fra tjenester ...");
} }
_enableLink = 0; _enableLink = 0;
_enableActivity = 0; _enableActivity = 0;
var newSync = await CustomerHistoryRepo.RequestErpSync(CompanyId, _company.HistorySync, force); var newSync = await CustomerHistoryRepo.RequestErpSync(CompanyId, _company.HistorySync, forceBackend);
await Task.Delay(500); await Task.Delay(500);
if (!string.IsNullOrWhiteSpace(newSync)) if (!string.IsNullOrWhiteSpace(newSync))
{ {
Toaster.ShowSuccess($"{forceBackend} {newSync} ERP hitorik synkroniseret til CRM.");
_company.HistorySync = newSync; _company.HistorySync = newSync;
if (!_company.Account.StartsWith("NY")) if (!_company.Account.StartsWith("NY"))
{ {
_ = await DrawerService.GetInvoiceDrawerAsync(CompanyId, force); await DrawerService.GetInvoiceDrawerAsync(CompanyId, forceBackend);
_ = await DrawerService.GetInventoryDrawerAsync(CompanyId, force); await DrawerService.GetInventoryDrawerAsync(CompanyId, forceBackend);
_ = await DrawerService.GetStatisticDrawerAsync(CompanyId, force); await DrawerService.GetStatisticDrawerAsync(CompanyId, forceBackend);
} }
_ = await DrawerService.GetActivityDrawerAsync(CompanyId, force); await DrawerService.GetActivityDrawerAsync(CompanyId, forceBackend);
} }
_enableLink = 1; _enableLink = 1;
_enableActivity = _company.ValidVat; _enableActivity = _company.ValidVat;
StateHasChanged(); StateHasChanged();
if (force) if (forceBackend)
{ {
Toaster.ShowSuccess("Alle tjenester har svaret."); Toaster.ShowSuccess("Alle tjenester har svaret.");
} }
} }
private void ToggleErpEdit() private void ToggleErpEdit()
{ {
_erpEditDisabled = !_erpEditDisabled; _erpEditDisabled = !_erpEditDisabled;
} }
private void ToggleVatEdit() private void ToggleVatEdit()
{ {
_vatEditDisabled = !_vatEditDisabled; _vatEditDisabled = !_vatEditDisabled;
@ -294,7 +308,7 @@ public partial class AdvisorCustomerViewEditPage : IDisposable
await AdvisorCustomerRepo.UpdateCrmData(CompanyId, _company); await AdvisorCustomerRepo.UpdateCrmData(CompanyId, _company);
} }
/* /*
* Request contacts for company * Request contacts for company
*/ */
@ -319,7 +333,7 @@ public partial class AdvisorCustomerViewEditPage : IDisposable
_vatLookupPopup.Show(); _vatLookupPopup.Show();
} }
/* /*
* Callback from vat lookup overlay with registration infomration * Callback from vat lookup overlay with registration infomration
*/ */
@ -340,6 +354,7 @@ public partial class AdvisorCustomerViewEditPage : IDisposable
_company.ZipCode = regInfo.ZipCode; _company.ZipCode = regInfo.ZipCode;
_company.City = regInfo.City; _company.City = regInfo.City;
} }
_company.VatNumber = regInfo.VatNumber; _company.VatNumber = regInfo.VatNumber;
} }
@ -386,6 +401,7 @@ public partial class AdvisorCustomerViewEditPage : IDisposable
*/ */
await ContactRepo.PutContact(contact); await ContactRepo.PutContact(contact);
} }
/* /*
* reset default contact * reset default contact
*/ */
@ -400,7 +416,7 @@ public partial class AdvisorCustomerViewEditPage : IDisposable
/* /*
* Delete contact callback * Delete contact callback
*/ */
private async Task DeleteContactCallback(string contactId) private async Task DeleteContactCallback(string contactId)
{ {
if (_working) if (_working)
@ -408,7 +424,7 @@ public partial class AdvisorCustomerViewEditPage : IDisposable
_working = true; _working = true;
/* /*
* send delete request to backend * send delete request to backend
*/ */
await ContactRepo.DeleteContact(CompanyId, contactId); await ContactRepo.DeleteContact(CompanyId, contactId);
/* /*
* reset default contact * reset default contact
@ -421,7 +437,7 @@ public partial class AdvisorCustomerViewEditPage : IDisposable
_working = false; _working = false;
} }
/* /*
* Execute post requset - updating CRM data (non ERP related) * Execute post requset - updating CRM data (non ERP related)
*/ */
@ -440,6 +456,7 @@ public partial class AdvisorCustomerViewEditPage : IDisposable
_infoDrawer = await DrawerService.GetInfoDrawerAsync(CompanyId, true); _infoDrawer = await DrawerService.GetInfoDrawerAsync(CompanyId, true);
_company = _infoDrawer.Content; _company = _infoDrawer.Content;
} }
StateHasChanged(); StateHasChanged();
_working = false; _working = false;
Toaster.ShowSuccess("Dine CRM data er opdateret."); Toaster.ShowSuccess("Dine CRM data er opdateret.");
@ -462,6 +479,7 @@ public partial class AdvisorCustomerViewEditPage : IDisposable
_infoDrawer = await DrawerService.GetInfoDrawerAsync(CompanyId, true); _infoDrawer = await DrawerService.GetInfoDrawerAsync(CompanyId, true);
_company = _infoDrawer.Content; _company = _infoDrawer.Content;
} }
StateHasChanged(); StateHasChanged();
_working = false; _working = false;
Toaster.ShowSuccess(_company.Account.StartsWith("NY") Toaster.ShowSuccess(_company.Account.StartsWith("NY")
@ -484,12 +502,13 @@ public partial class AdvisorCustomerViewEditPage : IDisposable
return; return;
/* /*
* VAT format validation * VAT format validation
*/ */
if (!VatUtils.ValidateFormat(_company.CountryCode, _company.VatNumber)) if (!VatUtils.ValidateFormat(_company.CountryCode, _company.VatNumber))
{ {
Toaster.ShowError($"Moms Nummer ugyldigt"); Toaster.ShowError($"Moms Nummer ugyldigt");
return; return;
} }
_working = true; _working = true;
_vatEditDisabled = true; _vatEditDisabled = true;
Toaster.ShowInfo("Vent venligst ..."); Toaster.ShowInfo("Vent venligst ...");
@ -499,6 +518,7 @@ public partial class AdvisorCustomerViewEditPage : IDisposable
_infoDrawer = await DrawerService.GetInfoDrawerAsync(CompanyId, true); _infoDrawer = await DrawerService.GetInfoDrawerAsync(CompanyId, true);
_company = _infoDrawer.Content; _company = _infoDrawer.Content;
} }
StateHasChanged(); StateHasChanged();
_working = false; _working = false;
// if (_company.HasFolded == 1) // if (_company.HasFolded == 1)
@ -508,7 +528,7 @@ public partial class AdvisorCustomerViewEditPage : IDisposable
Toaster.ShowSuccess("Moms Nr. er opdateret."); Toaster.ShowSuccess("Moms Nr. er opdateret.");
} }
/* /*
* Prepare vat address * Prepare vat address
* used to lookup danish company * used to lookup danish company
@ -529,6 +549,7 @@ public partial class AdvisorCustomerViewEditPage : IDisposable
HouseNumber = company.Address1.Split(' ')[1].Split('-')[0] HouseNumber = company.Address1.Split(' ')[1].Split('-')[0]
}; };
} }
/* /*
* process address2 * process address2
*/ */
@ -542,13 +563,14 @@ public partial class AdvisorCustomerViewEditPage : IDisposable
HouseNumber = company.Address2.Split(' ')[1].Split('-')[0] HouseNumber = company.Address2.Split(' ')[1].Split('-')[0]
}; };
} }
/* /*
* return empty model * return empty model
*/ */
return new VatAddress(); return new VatAddress();
} }
/* /*
* Force enable activioty - even if company has turned keys and shut down * Force enable activioty - even if company has turned keys and shut down
*/ */
@ -563,7 +585,6 @@ public partial class AdvisorCustomerViewEditPage : IDisposable
*/ */
private void HandleFieldChanged(object? sender, FieldChangedEventArgs? e) private void HandleFieldChanged(object? sender, FieldChangedEventArgs? e)
{ {
_nextVisit = _lastVisit.AddDays(_company.Interval * 7); _nextVisit = _lastVisit.AddDays(_company.Interval * 7);
/* /*
* avoid nesting if by assuming _validVat is false * avoid nesting if by assuming _validVat is false
@ -571,7 +592,7 @@ public partial class AdvisorCustomerViewEditPage : IDisposable
_validVat = false; _validVat = false;
/* /*
* set _validVat true if validation succeed * set _validVat true if validation succeed
*/ */
if (VatUtils.ValidateFormat(_company.CountryCode, _company.VatNumber)) if (VatUtils.ValidateFormat(_company.CountryCode, _company.VatNumber))
{ {
_validVat = true; _validVat = true;

View file

@ -26,33 +26,31 @@
</div> </div>
<div class="col-sm-4 text-end"> <div class="col-sm-4 text-end">
<div class="btn-group btn-group" role="group" aria-label="Filter tilbud"> <div class="btn-group btn-group" role="group" aria-label="Filter tilbud">
@* all quotes (list) *@
<input type="radio" class="btn-check" name="btn-filter" id="btn-filter4" autocomplete="off" @onchange="() => FilterQuotes(QuoteStatus.All)"/> <input type="radio" class="btn-check" name="btn-filter" id="btn-filter4" autocomplete="off"
<label class="btn btn-dark" for="btn-filter4"><i class="bi-list"style="font-size: 1.3rem"></i></label> @onchange="() => FilterQuotes(QuoteStatus.All)"/>
<label class="btn btn-dark" for="btn-filter4"><i class="bi-list" style="font-size: 1.3rem"></i></label>
<input type="radio" class="btn-check" name="btn-filter" id="btn-filter1" autocomplete="off" @onchange="() => FilterQuotes(QuoteStatus.Lose)"/> @* lost quotes (trash) *@
<label class="btn btn-dark" for="btn-filter1"><i class="bi-trash-fill"style="font-size: 1.3rem"></i></label> <input type="radio" class="btn-check" name="btn-filter" id="btn-filter1" autocomplete="off"
@onchange="() => FilterQuotes(QuoteStatus.Lose)"/>
<input type="radio" class="btn-check" name="btn-filter" id="btn-filter2" autocomplete="off" @onchange="() => FilterQuotes(QuoteStatus.Archive)"/> <label class="btn btn-dark" for="btn-filter1"><i class="bi-trash-2" style="font-size: 1.3rem"></i></label>
<label class="btn btn-dark" for="btn-filter2"><i class="bi-archive-fill"style="font-size: 1.3rem"></i></label> @* archived quotes (archive) *@
<input type="radio" class="btn-check" name="btn-filter" id="btn-filter2" autocomplete="off"
<input type="radio" class="btn-check" name="btn-filter" id="btn-filter5" autocomplete="off" @onchange="() => FilterQuotes(QuoteStatus.None)"/> @onchange="() => FilterQuotes(QuoteStatus.Archive)"/>
<label class="btn btn-dark" for="btn-filter5"><i class="bi-question-circle-fill"style="font-size: 1.3rem"></i></label> <label class="btn btn-dark" for="btn-filter2"><i class="bi-archive-fill" style="font-size: 1.3rem"></i></label>
@* open/undecided quotes (question) *@
<input type="radio" class="btn-check" name="btn-filter" id="btn-filter3" autocomplete="off" @onchange="() => FilterQuotes(QuoteStatus.Note)"/> <input type="radio" class="btn-check" name="btn-filter" id="btn-filter5" autocomplete="off"
<label class="btn btn-dark" for="btn-filter3"><i class="bi-tag-fill"style="font-size: 1.3rem"></i></label> @onchange="() => FilterQuotes(QuoteStatus.None)"/>
<label class="btn btn-dark" for="btn-filter5"><i class="bi-question-circle-fill" style="font-size: 1.3rem"></i></label>
<input type="radio" class="btn-check" name="btn-filter" id="btn-filter6" autocomplete="off" @onchange="() => FilterQuotes(QuoteStatus.NoteOpen)" checked/> @* quotes tagged as notes (tag) *@
<label class="btn btn-dark" for="btn-filter6"><i class="bi-activity"style="font-size: 1.3rem"></i></label> <input type="radio" class="btn-check" name="btn-filter" id="btn-filter3" autocomplete="off"
@onchange="() => FilterQuotes(QuoteStatus.Note)"/>
<label class="btn btn-dark" for="btn-filter3"><i class="bi-tag-fill" style="font-size: 1.3rem"></i></label>
@* quotes - either tagged or open (activity) *@
<input type="radio" class="btn-check" name="btn-filter" id="btn-filter6" autocomplete="off"
@onchange="() => FilterQuotes(QuoteStatus.NoteOpen)" checked/>
<label class="btn btn-dark" for="btn-filter6"><i class="bi-activity" style="font-size: 1.3rem"></i></label>
</div> </div>
@*
<div class="form-check">
<input class="form-check-input" type="checkbox" id="showAll"
@bind-Value="Filtered" @bind-Value:event="onchange" @onclick="@FilterQuotes" disabled="@(!Quotes.Any())"/>
<label for="showAll" class="form-check-label">Vis alle</label>
</div>
*@
</div> </div>
</div> </div>

View file

@ -48,7 +48,7 @@ public partial class AdvisorQuoteListPage : IDisposable
await Storage.SetItemAsync("quotes", QuoteList.OrderBy(x => x.Company.Name)); await Storage.SetItemAsync("quotes", QuoteList.OrderBy(x => x.Company.Name));
Working = false; Working = false;
// filter quotes - if any - default to QStatus.NoteOpen // filter quotes - if any - default to QStatus.NoteOpen
if (QuoteList.Any()) if (QuoteList.Count != 0)
await FilterQuotes(QuoteFilter); await FilterQuotes(QuoteFilter);
} }
@ -62,6 +62,7 @@ public partial class AdvisorQuoteListPage : IDisposable
QuoteStatus.Lose => QuoteList.Where(x => x.QuoteStatusEnum is "Lose").ToList(), QuoteStatus.Lose => QuoteList.Where(x => x.QuoteStatusEnum is "Lose").ToList(),
QuoteStatus.Archive => QuoteList.Where(x => x.QuoteStatusEnum is "Archive").ToList(), QuoteStatus.Archive => QuoteList.Where(x => x.QuoteStatusEnum is "Archive").ToList(),
QuoteStatus.Note => QuoteList.Where(x => x.QuoteStatusEnum is "Note").ToList(), QuoteStatus.Note => QuoteList.Where(x => x.QuoteStatusEnum is "Note").ToList(),
QuoteStatus.Trash => QuoteList.Where(x => x.QuoteStatusEnum is "Trash").ToList(),
QuoteStatus.NoteOpen => QuoteList.Where(x => x.QuoteStatusEnum is "Note" or "None").ToList(), QuoteStatus.NoteOpen => QuoteList.Where(x => x.QuoteStatusEnum is "Note" or "None").ToList(),
_ => QuoteList.ToList() _ => QuoteList.ToList()
}; };
@ -75,19 +76,24 @@ public partial class AdvisorQuoteListPage : IDisposable
if (args.Status == QuoteStatus.Order) if (args.Status == QuoteStatus.Order)
quote.OrderDate = $"{DateTime.Now:yyyy-MM-dd}"; quote.OrderDate = $"{DateTime.Now:yyyy-MM-dd}";
quote.QuoteStatusEnum = Utils.EnumToString(args.Status); quote.QuoteStatusEnum = Utils.EnumToString(args.Status);
// send update request to backend // send update request to backend
var response = await AdvisorActivityRepo.UpdateQuoteStatus(quote); var response = await AdvisorActivityRepo.UpdateQuoteStatus(quote);
Toaster.ShowInfo($"{response.Message}"); Toaster.ShowInfo($"{response.Message}");
// clear and reload quotes // clear and reload quotes
QuoteList = new List<ReportItemView>(); QuoteList = new List<ReportItemView>();
await Storage.RemoveItemAsync("quotes"); await Storage.RemoveItemAsync("quotes");
QuoteList = await AdvisorActivityRepo.GetQuotes(); QuoteList = await AdvisorActivityRepo.GetQuotes();
// store quotes in local storage // store quotes in local storage
await Storage.SetItemAsync("quotes", QuoteList.OrderBy(x => x.Company.Name)); await Storage.SetItemAsync("quotes", QuoteList.OrderBy(x => x.Company.Name));
// filter quotes - if any - based on active filter // filter quotes - if any - based on active filter
if(QuoteList.Count != 0) if(QuoteList.Count != 0)
await FilterQuotes(QuoteFilter); await FilterQuotes(QuoteFilter);
Working = false; Working = false;
// signal page state changed // signal page state changed
StateHasChanged(); StateHasChanged();
} }