wip sales-report

This commit is contained in:
Frede Hundewadt 2022-05-28 15:37:27 +02:00
parent 453a674e03
commit f5119a9ea3
15 changed files with 199 additions and 25 deletions

View file

@ -31,7 +31,7 @@ namespace Wonky.Client.HttpRepository;
public class ActivityHttpRepository : IActivityHttpRepository
{
private readonly JsonSerializerOptions _options = new JsonSerializerOptions
private readonly JsonSerializerOptions? _options = new JsonSerializerOptions
{
PropertyNameCaseInsensitive = true
};
@ -50,7 +50,18 @@ public class ActivityHttpRepository : IActivityHttpRepository
_navigation = navigation;
_apiConfig = configuration.Value;
}
public async Task<List<ReportActivity>?> GetActivities(string activityDate)
{
var response = await _client
.GetAsync($"{_apiConfig.ActivityEndpoint}/date/{activityDate}")
.ConfigureAwait(true);
var content = await response.Content.ReadAsStringAsync();
//Console.WriteLine(content);
return string.IsNullOrWhiteSpace(content)
? new List<ReportActivity>()
: JsonSerializer.Deserialize<List<ReportActivity>>(content, _options);
}
public async Task<PagingResponse<DtoNgActivity>> GetActivityPaged(ActivityPagingParams pagingParameters)
{
var queryString = new Dictionary<string, string>

View file

@ -26,4 +26,5 @@ public interface IActivityHttpRepository
Task<DtoNgActivity> GetActivity(string id);
Task<ActivityResponseView> CreateActivity(DtoNgActivity model);
Task<ActivityResponseView> AcceptOffer(string id);
Task<List<ReportActivity>?> GetActivities(string activityDate);
}

View file

@ -79,14 +79,14 @@
</td>
</tr>
<tr>
<th scope="row">Conavn</th>
<th scope="row">Adresse</th>
<td></td>
<td>
<InputText id="address1" class="form-control" @bind-Value="_dtoNgCompany.Address1"/>
</td>
</tr>
<tr>
<th scope="row">Adresse</th>
<th scope="row">Conavn</th>
<td></td>
<td>
<InputText id="address2" class="form-control" @bind-Value="_dtoNgCompany.Address2"/>

View file

@ -94,8 +94,8 @@ namespace Wonky.Client.Pages
_virkRegInfo = (from x in VInfos where x.VatNumber == vatNumber select x).First();
RegState = _virkRegInfo.States[^1].State == "NORMAL" ? "the-good" : "the-ugly";
_dtoNgCompany.Name = _virkRegInfo.Name;
_dtoNgCompany.Address1 = _virkRegInfo.CoName;
_dtoNgCompany.Address2 = _virkRegInfo.Address;
_dtoNgCompany.Address1 = _virkRegInfo.Address;
_dtoNgCompany.Address2 = _virkRegInfo.CoName;
_dtoNgCompany.ZipCode = _virkRegInfo.ZipCode;
_dtoNgCompany.City = _virkRegInfo.City;
_dtoNgCompany.VatNumber = _virkRegInfo.VatNumber;

View file

@ -72,14 +72,14 @@
</div>
</div>
<div class="form-group row mb-1">
<label for="address1" class="col-md-2 col-form-label">Conavn</label>
<label for="address1" class="col-md-2 col-form-label">Adresse</label>
<div class="col-md-10">
<InputText id="address1" class="form-control" @bind-Value="DtoNgCompany.Address1"/>
<ValidationMessage For="@(() => DtoNgCompany.Address1)"></ValidationMessage>
</div>
</div>
<div class="form-group row mb-1">
<label for="address2" class="col-md-2 col-form-label">Adresse</label>
<label for="address2" class="col-md-2 col-form-label">Conavn</label>
<div class="col-md-10">
<InputText id="address2" class="form-control" @bind-Value="DtoNgCompany.Address2"/>
</div>
@ -139,7 +139,10 @@
</div>
</div>
<div class="row mb-1">
<div class="col-md-12 text-right">
<div class="col-sm-2 col-md-2 text-right">
<button type="submit" class="btn btn-danger">SLET</button>
</div>
<div class="col-sm-2 col-md-2 text-right">
<button type="submit" class="btn btn-success">GEM</button>
</div>
</div>

View file

@ -49,7 +49,7 @@ public partial class CompanyUpdate : IDisposable
private DateTime NextVisit { get; set; }
private string _vatState { get; set; } = "the-ugly";
private VatUtils _vatUtils { get; set; }
private VatAddress vatAddress = new();
private VatAddress vatAddress;
protected override async Task OnInitializedAsync()
{
@ -57,7 +57,7 @@ public partial class CompanyUpdate : IDisposable
Interceptor.RegisterEvent();
Interceptor.RegisterBeforeSendEvent();
DtoNgCompany = await CompanyRepo.GetCompanyById(CompanyId);
vatAddress = PrepareVatAddress();
LastVisit = DateTime.Parse(DtoNgCompany.LastVisit);
NextVisit = DateTime.Parse(DtoNgCompany.NextVisit);
_updateCompany = new EditContext(DtoNgCompany);
@ -76,16 +76,37 @@ public partial class CompanyUpdate : IDisposable
{
_vatState = _vatUtils.ValidateFormat(DtoNgCompany.CountryCode, DtoNgCompany.VatNumber) ? "the-good" : "the-draw";
}
var digits = "123456789".ToCharArray();
var pos1 = DtoNgCompany.Address1.IndexOfAny(digits);
var pos2 = DtoNgCompany.Address2.IndexOfAny(digits);
vatAddress.ZipCode = DtoNgCompany.ZipCode;
vatAddress.StreetName = pos1 != 0 ? DtoNgCompany.Address1[..pos1] : DtoNgCompany.Address2[..pos2];
vatAddress.HouseNumber = pos1 != 0 ? DtoNgCompany.Address1[pos1..] : DtoNgCompany.Address2[pos2..];
}
private VatAddress PrepareVatAddress()
{
var digits = "123456789".ToCharArray();
var pos = DtoNgCompany.Address1.IndexOfAny(digits);
if (pos > 0)
{
return new VatAddress
{
ZipCode = DtoNgCompany.ZipCode,
StreetName = DtoNgCompany.Address1[..pos],
HouseNumber = DtoNgCompany.Address1[pos..]
};
}
pos = DtoNgCompany.Address2.IndexOfAny(digits);
if (pos > 0)
{
return new VatAddress
{
ZipCode = DtoNgCompany.ZipCode,
StreetName = DtoNgCompany.Address2[..pos],
HouseNumber = DtoNgCompany.Address2[pos..]
};
}
return new VatAddress
{
ZipCode = DtoNgCompany.ZipCode
};
}
private async Task Update()
{
if (!string.IsNullOrWhiteSpace(DtoNgCompany.VatNumber) && !_vatUtils.ValidateFormat(DtoNgCompany.CountryCode, DtoNgCompany.VatNumber))

View file

@ -79,7 +79,7 @@
<div class="d-flex align-items-end">
<a class="btn btn-primary mx-2" href="/companies">Tilbage</a>
<a class="btn btn-primary mx-2" href="/company/@DtoNgCompany.CompanyId/update">Rediger</a>
@if (_vatInvalid)
@if (_vatInvalid || string.IsNullOrWhiteSpace(DtoNgCompany.Address1))
{
<a type="button" class="btn btn-primary mx-2 disabled" aria-disabled="true">Aktivitet</a>
}

View file

@ -139,6 +139,7 @@ public partial class CrmActivityCreate : IDisposable
Qty = item.Quantity,
Sku = item.Item.Sku,
Text = item.Item.Name,
ShortName = item.Item.ShortName,
LineAmount = item.LineTotal,
LineNumber = ++ln,
Sas = item.Sas

View file

@ -0,0 +1,66 @@
@*
// Copyright (C) 2022 FCS Frede's Computer Services.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the Affero GNU General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// Affero GNU General Public License for more details.
//
// You should have received a copy of the Affero GNU General Public License
// along with this program. If not, see [https://www.gnu.org/licenses/agpl-3.0.en.html]
//
*@
@using Microsoft.AspNetCore.Authorization
@attribute [Authorize(Roles = "Adviser")]
@page "/sales-report"
<h3>Rapport</h3>
<div class="row">
<div class="col">
<label for="reportDate" class="col-md-2 col-form-label">Dato</label>
<div class="col-md-4">
<EditForm EditContext="ReportDate">
<InputDate id="reportDate" class="form-control" @bind-Value="@(_reportDate)"/>
<button class="btn btn-info" @onclick="GetActivities">Hent aktiviteter</button>
</EditForm>
</div>
</div>
</div>
@if (Activities != null)
{
<div class="row">
@foreach (var activity in Activities)
{
<div class="card">
<div class="card-header">
@activity.Company.Name @activity.Company.ZipCity
</div>
<div class="card-body">
<div class="row">
<div class="col">
@activity.Demo
</div>
<div class="col">
@activity.SalesResume
</div>
<div class="col">
@activity.OrderAmount
</div>
</div>
</div>
</div>
}
</div>
<div class="row">
</div>
}
else
{
<span>Ingen aktivitet for dato</span>
}

View file

@ -0,0 +1,46 @@
// Copyright (C) 2022 FCS Frede's Computer Services.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the Affero GNU General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// Affero GNU General Public License for more details.
//
// You should have received a copy of the Affero GNU General Public License
// along with this program. If not, see [https://www.gnu.org/licenses/agpl-3.0.en.html]
//
using System.Text.Json;
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Forms;
using Wonky.Client.HttpInterceptors;
using Wonky.Client.HttpRepository;
using Wonky.Client.Services;
using Wonky.Entity.DTO;
namespace Wonky.Client.Pages;
public partial class SalesReport
{
[Inject] private HttpInterceptorService Interceptor { get; set; }
[Inject] private UserPreferenceService UserPrefs { get; set; }
[Inject] private IActivityHttpRepository ActivityRepo { get; set; }
private DateTime _reportDate;
private EditContext ReportDate { get; set; }
private List<ReportActivity>? Activities { get; set; } = new();
protected override void OnInitialized()
{
_reportDate = DateTime.Now;
ReportDate = new EditContext(_reportDate);
}
private async Task GetActivities()
{
Activities = await ActivityRepo.GetActivities($"{_reportDate:yyyy-MM-dd}").ConfigureAwait(true);
}
}

View file

@ -58,9 +58,9 @@
</NavLink>
</div>
<div class="nav-item px-3">
<NavLink class="nav-link" href="logout">
<span class="oi oi-account-logout"></span> Log af
</NavLink>
<NavLink class="nav-link" href="sales-report">
<span class="oi oi-list-rich" aria-hidden="true"></span> Dagsrapport
</NavLink>
</div>
</Authorized>
</AuthorizeView>

View file

@ -33,7 +33,6 @@
</ItemGroup>
<ItemGroup>
<Folder Include="Providers" />
<Folder Include="wwwroot\scripts" />
</ItemGroup>

View file

@ -18,6 +18,7 @@ public class DtoNgActivityLine
{
public string Sku { get; set; } = "";
public string Text { get; set; } = "";
public string ShortName { get; set; } = "";
public int Qty { get; set; }
public decimal Price { get; set; }
public decimal Discount { get; set; }

View file

@ -0,0 +1,25 @@
namespace Wonky.Entity.DTO;
public class ReportActivity
{
public Visitcompany Company { get; set; }
public string SalesHeadId { get; set; } = "";
public bool Closed { get; set; }
public string OrderDate { get; set; } = "";
public string ReferenceNumber { get; set; } = "";
public string YourRef { get; set; } = "";
public decimal OrderAmount { get; set; }
public string VisitTypeEnum { get; set; } = "";
public string Demo { get; set; } = "";
public string SalesResume { get; set; } = "";
}
public class Visitcompany
{
public string CompanyId { get; set; } = "";
public string Account { get; set; } = "";
public string Name { get; set; } = "";
public string ZipCity { get; set; } = "";
public string Phone { get; set; } = "";
public string VatNumber { get; set; } = "";
}