WIP: quotes - refactor express call to use get instead of put
This commit is contained in:
parent
6e882db6f5
commit
0b0be1a247
7 changed files with 63 additions and 52 deletions
|
@ -20,6 +20,12 @@ namespace Wonky.Client.HttpInterfaces;
|
|||
|
||||
public interface ICrmActivityHttpRepository
|
||||
{
|
||||
/// <summary>
|
||||
/// Get a list of open quotes
|
||||
/// </summary>
|
||||
/// <returns>List of Activities with ActivityStatus == Quote</returns>
|
||||
Task<List<ActivityDto>> GetQuotes();
|
||||
|
||||
/// <summary>
|
||||
/// Convert quote to sale
|
||||
/// </summary>
|
||||
|
@ -67,7 +73,7 @@ public interface ICrmActivityHttpRepository
|
|||
/// </summary>
|
||||
/// <param name="activityId"></param>
|
||||
/// <returns>ApiResponseView</returns>
|
||||
Task<ApiResponseView> SetProcessStateExpress(string activityId);
|
||||
Task<ApiResponseView> GetExpressState(string activityId);
|
||||
|
||||
/// <summary>
|
||||
/// Update office note for activity
|
||||
|
|
|
@ -46,6 +46,16 @@ public class CrmActivityHttpRepository : ICrmActivityHttpRepository
|
|||
_api = configuration.Value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get a list of quotes
|
||||
/// </summary>
|
||||
/// <returns>List of activities with Quote status </returns>
|
||||
public async Task<List<ActivityDto>> GetQuotes()
|
||||
{
|
||||
var result = await _client.GetFromJsonAsync<List<ActivityDto>>($"{_api.CrmActivities}/quotes", _options);
|
||||
return result ?? new List<ActivityDto>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Convert quote to sale
|
||||
/// </summary>
|
||||
|
@ -55,7 +65,7 @@ public class CrmActivityHttpRepository : ICrmActivityHttpRepository
|
|||
{
|
||||
var response = await _client.PutAsJsonAsync(
|
||||
$"{_api.CrmActivities}/{activity.SalesHeadId}/accept", activity, _options);
|
||||
|
||||
|
||||
var content = await response.Content.ReadAsStringAsync();
|
||||
var result = JsonSerializer.Deserialize<ApiResponseView>(content);
|
||||
return result!;
|
||||
|
@ -89,8 +99,8 @@ public class CrmActivityHttpRepository : ICrmActivityHttpRepository
|
|||
if (!response.IsSuccessStatusCode)
|
||||
return new ReportStatusView();
|
||||
var content = await response.Content.ReadAsStringAsync();
|
||||
return string.IsNullOrWhiteSpace(content)
|
||||
? new ReportStatusView()
|
||||
return string.IsNullOrWhiteSpace(content)
|
||||
? new ReportStatusView()
|
||||
: JsonSerializer.Deserialize<ReportStatusView>(content, _options);
|
||||
}
|
||||
|
||||
|
@ -115,12 +125,11 @@ public class CrmActivityHttpRepository : ICrmActivityHttpRepository
|
|||
{
|
||||
var response = await _client.GetAsync($"{_api.CrmActivities}/company/{customerId}");
|
||||
var content = await response.Content.ReadAsStringAsync();
|
||||
if(!response.IsSuccessStatusCode)
|
||||
if (!response.IsSuccessStatusCode)
|
||||
return new List<ReportItemView>();
|
||||
return string.IsNullOrWhiteSpace(content)
|
||||
? new List<ReportItemView>()
|
||||
: JsonSerializer.Deserialize<List<ReportItemView>>(content, _options);
|
||||
|
||||
: JsonSerializer.Deserialize<List<ReportItemView>>(content, _options);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -135,24 +144,21 @@ public class CrmActivityHttpRepository : ICrmActivityHttpRepository
|
|||
return salesItem ?? new ReportItemView();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set backend process state to express
|
||||
/// </summary>
|
||||
/// <param name="activityId"></param>
|
||||
/// <returns>ApiResponseView</returns>
|
||||
public async Task<ApiResponseView> SetProcessStateExpress(string activityId)
|
||||
public async Task<ApiResponseView> GetExpressState(string activityId)
|
||||
{
|
||||
var response = await _client.PutAsync(
|
||||
$"{_api.CrmActivities}/express/{activityId}?status=Express", null);
|
||||
var content = await response.Content.ReadAsStringAsync();
|
||||
return string.IsNullOrWhiteSpace(content)
|
||||
? new ApiResponseView
|
||||
{
|
||||
Code = (int)response.StatusCode,
|
||||
Id = activityId,
|
||||
Message = "Resoursen returnerede fejl",
|
||||
IsSuccess = false
|
||||
}
|
||||
: JsonSerializer.Deserialize<ApiResponseView>(content);
|
||||
var response = await _client.GetFromJsonAsync<ApiResponseView>($"{_api.CrmActivities}/express/{activityId}?status=Express", _options);
|
||||
return response ?? new ApiResponseView
|
||||
{
|
||||
Code = 404,
|
||||
IsSuccess = false,
|
||||
Message = "Uventet svare fra server",
|
||||
Id = ""
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
@page "/companies/{CompanyId}/quotes"
|
||||
@page "/open-quotes"
|
||||
@using Wonky.Client.HttpInterfaces
|
||||
<div class="row">
|
||||
<h3>Åbne tilbud</h3>
|
|
@ -26,14 +26,14 @@
|
|||
<div class="col">
|
||||
<div class="text-center">
|
||||
<img class="grumpy-coder mb-2" src="@_app?.Image" alt="Wonky Logo"/>
|
||||
<h5><AppVersion></AppVersion></h5>
|
||||
<h5><AppVersion /></h5>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row mb-2">
|
||||
<div class="col">
|
||||
<h2 class="text-center">Piktogrammer</h2>
|
||||
<ColorCodingComponent></ColorCodingComponent>
|
||||
<ColorCodingComponent />
|
||||
</div>
|
||||
</div>
|
||||
<div class="row mb-2">
|
||||
|
@ -56,13 +56,12 @@
|
|||
<a class="list-group-item list-group-item-action" href="https://dotnet.microsoft.com/en-us/apps/aspnet/web-apps/blazor/" target="_blank">Blazor WebAssembly</a>
|
||||
<a class="list-group-item list-group-item-action" href="https://getbootstrap.com/" target="_blank">Bootstrap</a>
|
||||
<a class="list-group-item list-group-item-action" href="https://github.com/SamHerbert/SVG-Loaders" target="_blank">SVG-Loaders</a>
|
||||
<a class="list-group-item list-group-item-action" href="https://codeberg.org/wonky/Wonky.Client" target="_blank">Wonky Client</a>
|
||||
<a class="list-group-item list-group-item-action" href="https://codeberg.org/wonky/fcs-azure" target="_blank">FCS Azure</a>
|
||||
<a class="list-group-item list-group-item-action" href="https://codeberg.org/wonky/fcs-brreg" target="_blank">FCS BrReg</a>
|
||||
<a class="list-group-item list-group-item-action" href="https://codeberg.org/wonky/fcs-common" target="_blank">FCS Common</a>
|
||||
<a class="list-group-item list-group-item-action" href="https://codeberg.org/wonky/fcs-utils" target="_blank">FCS Utils</a>
|
||||
<a class="list-group-item list-group-item-action" href="https://codeberg.org/wonky/fcs-vies" target="_blank">FCS Vies</a>
|
||||
<a class="list-group-item list-group-item-action" href="https://codeberg.org/wonky/fcs-virk" target="_blank">FCS Virk</a>
|
||||
<a class="list-group-item list-group-item-action" href="https://github.com/FCS-TECH/fcs-azure" target="_blank">FCS Azure</a>
|
||||
<a class="list-group-item list-group-item-action" href="https://github.com/FCS-TECH/fcs-brreg" target="_blank">FCS BrReg</a>
|
||||
<a class="list-group-item list-group-item-action" href="https://github.com/FCS-TECH/fcs-common" target="_blank">FCS Common</a>
|
||||
<a class="list-group-item list-group-item-action" href="https://github.com/FCS-TECH/fcs-utils" target="_blank">FCS Utils</a>
|
||||
<a class="list-group-item list-group-item-action" href="https://github.com/FCS-TECH/fcs-vies" target="_blank">FCS Vies</a>
|
||||
<a class="list-group-item list-group-item-action" href="https://github.com/FCS-TECH/fcs-virk" target="_blank">FCS Virk</a>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -35,9 +35,11 @@
|
|||
<Authorized>
|
||||
<div class="d-print-none">
|
||||
<div class="row">
|
||||
<div class="col text-end">
|
||||
<div class="col-sm-1">
|
||||
<button type="button" class="btn btn-warning d-block" onclick="window.print();">PRINT</button>
|
||||
<button type="button" class="btn btn-warning d-block" @onclick="SetExpressState" disabled="@_isNotified">SÆT I GANG</button>
|
||||
</div>
|
||||
<div class="col-sm-5">
|
||||
<button type="button" class="btn btn-warning d-block" @onclick="SetExpressState" disabled="@_isNotified">Kvitter for modtagelse</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -45,7 +45,7 @@ public partial class OfficeOrderViewPage : IDisposable
|
|||
private bool _isNotified { get; set; }
|
||||
private bool Working { get; set; } = true;
|
||||
|
||||
private readonly JsonSerializerOptions? _options = new JsonSerializerOptions
|
||||
private readonly JsonSerializerOptions _options = new JsonSerializerOptions
|
||||
{
|
||||
PropertyNameCaseInsensitive = true
|
||||
};
|
||||
|
@ -54,6 +54,7 @@ public partial class OfficeOrderViewPage : IDisposable
|
|||
{
|
||||
Interceptor.RegisterEvent();
|
||||
Interceptor.RegisterBeforeSendEvent();
|
||||
// fetch order from backend
|
||||
_reportItem = await ActivityRepo.GetReportItem(OrderId);
|
||||
Logger.LogDebug("ReportItem => \n {}", JsonSerializer.Serialize(_reportItem, _options));
|
||||
Working = false;
|
||||
|
@ -64,25 +65,20 @@ public partial class OfficeOrderViewPage : IDisposable
|
|||
/// </summary>
|
||||
private async Task SetExpressState()
|
||||
{
|
||||
// disable doubled actions
|
||||
if (Working)
|
||||
return;
|
||||
Working = true;
|
||||
Logger.LogDebug("SetExpressState => \n {}", JsonSerializer.Serialize(_reportItem, _options));
|
||||
var responseView = await ActivityRepo.SetProcessStateExpress(_reportItem.ActivityId);
|
||||
Logger.LogDebug("SetExpressState => \n {}", responseView.Message );
|
||||
|
||||
if (!responseView.IsSuccess)
|
||||
{
|
||||
Toast.ShowError(responseView.Message);
|
||||
Working = false;
|
||||
return;
|
||||
}
|
||||
|
||||
Logger.LogDebug("GetExpressState => {}", JsonSerializer.Serialize(_reportItem, _options));
|
||||
// send request to backend
|
||||
var responseView = await ActivityRepo.GetExpressState(_reportItem.ActivityId);
|
||||
Logger.LogDebug("SetExpressState => responseView <= {} ", JsonSerializer.Serialize(responseView));
|
||||
// get user info from storage
|
||||
var user = await Storage.GetItemAsync<UserInfoView>("_xu");
|
||||
// fetch sales rep from response
|
||||
var salesRep = await UserRepo.GetAdvisorInfo(responseView.Id);
|
||||
|
||||
Logger.LogDebug("SetExpressState => salesRep => \n {}", JsonSerializer.Serialize(salesRep));
|
||||
|
||||
Logger.LogDebug("SetExpressState => salesRep => {}", JsonSerializer.Serialize(salesRep));
|
||||
// create email notification body
|
||||
var body = new StringBuilder();
|
||||
body.AppendLine($"Kvittering for modtagelse af hasteordre {_reportItem.ESalesNumber}");
|
||||
body.AppendLine($"Konto : {_reportItem.Company.Account}");
|
||||
|
@ -93,7 +89,7 @@ public partial class OfficeOrderViewPage : IDisposable
|
|||
body.AppendLine("Med venlig hilsen");
|
||||
body.AppendLine($"{user.FullName}");
|
||||
body.AppendLine($"{user.PhoneNumber}");
|
||||
|
||||
// create a list of mail addresses
|
||||
var sendTo = new List<EmailContact>
|
||||
{
|
||||
new()
|
||||
|
@ -102,7 +98,7 @@ public partial class OfficeOrderViewPage : IDisposable
|
|||
Name = $"{salesRep.FirstName} {salesRep.LastName}"
|
||||
}
|
||||
};
|
||||
|
||||
// create an email
|
||||
var msg = new EmailMessage
|
||||
{
|
||||
Body = body.ToString(),
|
||||
|
@ -111,7 +107,9 @@ public partial class OfficeOrderViewPage : IDisposable
|
|||
IsBodyHtml = false
|
||||
};
|
||||
Logger.LogDebug("SetExpressState Notification => \n {}", JsonSerializer.Serialize(msg));
|
||||
// send a system generated email
|
||||
var sendMail = await MailService.SendMail("System", msg);
|
||||
// result notification
|
||||
if (sendMail.IsSuccess)
|
||||
{
|
||||
Toast
|
||||
|
@ -124,7 +122,7 @@ public partial class OfficeOrderViewPage : IDisposable
|
|||
.ShowWarning(
|
||||
$"Notifikation til {salesRep.FirstName} kunne ikke sendes. {sendMail.Message}", "ADVARSEL");
|
||||
}
|
||||
|
||||
// disable further notifications
|
||||
_isNotified = true;
|
||||
Working = false;
|
||||
}
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
{
|
||||
"appInfo": {
|
||||
"name": "Wonky Client",
|
||||
"version": "0.83.3",
|
||||
"version": "0.84.1",
|
||||
"rc": true,
|
||||
"sandBox": false,
|
||||
"image": "grumpy-coder.png"
|
||||
},
|
||||
"apiConfig": {
|
||||
"baseUrl": "https://zeta.innotec.dk",
|
||||
"baseUrl": "https://eta.innotec.dk",
|
||||
"catalog": "api/v2/catalog",
|
||||
"crmCustomers": "api/v2/crm/companies",
|
||||
"crmInventoryExt": "history/inventory",
|
||||
|
|
Loading…
Reference in a new issue