Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Send invoice without usage. #1030

Merged
merged 1 commit into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ public TUsageInvoicingActionController(FoxIDsControlSettings settings, Telemetry

var mUsed = await tenantDataRepository.GetAsync<Used>(await Used.IdFormatAsync(action.TenantName, action.PeriodBeginDate.Year, action.PeriodBeginDate.Month));

if (action.DoInvoicingAgain)
if (action.DoInvoicing)
{
await DoInvoicingAgain(mUsed);
await DoInvoicing(mUsed);
}
else if (action.DoSendInvoiceAgain)
{
Expand Down Expand Up @@ -99,17 +99,37 @@ public TUsageInvoicingActionController(FoxIDsControlSettings settings, Telemetry
}
}

private async Task DoInvoicingAgain(Used mUsed)
private async Task DoInvoicing(Used mUsed)
{
if ((mUsed.IsUsageCalculated || mUsed.Items?.Count() > 0) && !mUsed.IsDone)
var mTenant = await tenantDataRepository.GetAsync<Tenant>(await Tenant.IdFormatAsync(mUsed.TenantName));

if (mTenant.EnableUsage)
{
var mTenant = await tenantDataRepository.GetAsync<Tenant>(await Tenant.IdFormatAsync(mUsed.TenantName));
using var cancellationTokenSource = new CancellationTokenSource();
await usageInvoicingLogic.DoInvoicingAsync(mTenant, mUsed, cancellationTokenSource.Token);
if ((mUsed.IsUsageCalculated || mUsed.Items?.Count() > 0) && !mUsed.IsDone)
{
using var cancellationTokenSource = new CancellationTokenSource();
await usageInvoicingLogic.DoInvoicingAsync(mTenant, mUsed, cancellationTokenSource.Token);
}
else
{
throw new Exception("The usage is not calculated or no items exits or it is already done and can not be invoiced.");
}
}
else
{
throw new Exception("The usage is not calculated or already done and can not be invoiced again.");
if(mUsed.IsDone)
{
throw new Exception("The usage is already done and can not be invoiced.");
}
else if (mUsed.Items?.Count() > 0)
{
using var cancellationTokenSource = new CancellationTokenSource();
await usageInvoicingLogic.DoInvoicingAsync(mTenant, mUsed, cancellationTokenSource.Token, doInvoicing: true);
}
else
{
logger.Event($"Usage, no items to invoice for tenant '{mUsed.TenantName}'.");
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/FoxIDs.Control/FoxIDs.Control.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<Version>1.11.16</Version>
<Version>1.11.17</Version>
<RootNamespace>FoxIDs</RootNamespace>
<Authors>Anders Revsgaard</Authors>
<Company>ITfoxtec</Company>
Expand Down
10 changes: 3 additions & 7 deletions src/FoxIDs.Control/Logic/Usage/UsageInvoicingLogic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ public UsageInvoicingLogic(FoxIDsControlSettings settings, TelemetryScopedLogger
this.usageMolliePaymentLogic = usageMolliePaymentLogic;
}

public async Task<bool> DoInvoicingAsync(Tenant tenant, Used used, CancellationToken stoppingToken)
public async Task<bool> DoInvoicingAsync(Tenant tenant, Used used, CancellationToken stoppingToken, bool doInvoicing = false)
{
if(!tenant.EnableUsage)
if(!doInvoicing && !tenant.EnableUsage)
{
logger.Event($"Usage, invoicing for tenant '{used.TenantName}' not enabled.");
return false;
Expand Down Expand Up @@ -251,14 +251,10 @@ private async Task<Invoice> CreateInvoiceAsync(Tenant tenant, Used used, bool is
};

var usageSettings = await GetUsageSettingsAsync();
var plan = tenant.PlanName.IsNullOrEmpty() ? null : await masterDataRepository.GetAsync<Plan>(await Plan.IdFormatAsync(tenant.PlanName));
var plan = tenant.EnableUsage && !tenant.PlanName.IsNullOrEmpty() ? await masterDataRepository.GetAsync<Plan>(await Plan.IdFormatAsync(tenant.PlanName)) : null;

stoppingToken.ThrowIfCancellationRequested();
CalculateInvoice(used, plan, invoice, tenant.IncludeVat, GetExchangesRate(invoice.Currency, usageSettings.CurrencyExchanges));
if(invoice.Price <= 0)
{
return null;
}

invoice.InvoiceNumber = await GetInvoiceNumberAsync(usageSettings);

Expand Down
2 changes: 1 addition & 1 deletion src/FoxIDs.ControlClient/FoxIDs.ControlClient.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<Version>1.11.16</Version>
<Version>1.11.17</Version>
<RootNamespace>FoxIDs.Client</RootNamespace>
<Authors>Anders Revsgaard</Authors>
<Company>ITfoxtec</Company>
Expand Down
6 changes: 3 additions & 3 deletions src/FoxIDs.ControlClient/Pages/Usage/Usage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ private void ShowCreateUsage()
usedList.Add(used);
}

public bool ShowDoInvoicingAgainButton(GeneralUsedViewModel used) => (used.IsUsageCalculated || used.HasItems) && !used.IsDone;
public bool ShowDoInvoicingButton(GeneralUsedViewModel used) => (used.IsUsageCalculated || used.HasItems) && !used.IsDone;

public bool ShowSendInvoiceAgainButton(GeneralUsedViewModel used) => used.IsInvoiceReady && (used.Invoices?.LastOrDefault()?.IsCardPayment != true || used.PaymentStatus == UsagePaymentStatus.Paid);

Expand Down Expand Up @@ -285,12 +285,12 @@ private async Task DeleteUsedAsync(GeneralUsedViewModel generalUsed)
}
}

private async Task DoInvoicingAgainAsync(GeneralUsedViewModel generalUsed)
private async Task DoInvoicingAsync(GeneralUsedViewModel generalUsed)
{
generalUsed.InvoicingActionButtonDisabled = true;
try
{
var usedResult = await TenantService.UsageInvoicingActionAsync(new UsageInvoicingAction { TenantName = generalUsed.TenantName, PeriodBeginDate = generalUsed.PeriodBeginDate, PeriodEndDate = generalUsed.PeriodEndDate, DoInvoicingAgain = true });
var usedResult = await TenantService.UsageInvoicingActionAsync(new UsageInvoicingAction { TenantName = generalUsed.TenantName, PeriodBeginDate = generalUsed.PeriodBeginDate, PeriodEndDate = generalUsed.PeriodEndDate, DoInvoicing = true });
UpdateGeneralModel(generalUsed, usedResult);
}
catch (TokenUnavailableException)
Expand Down
16 changes: 8 additions & 8 deletions src/FoxIDs.ControlClient/Pages/Usage/Usage.razor
Original file line number Diff line number Diff line change
Expand Up @@ -195,18 +195,18 @@
</div>
}
<div class="modal-footer">
@if (ShowDoInvoicingAgainButton(used))
@if (ShowDoInvoicingButton(used))
{
@if (!used.InvoicingActionButtonDisabled)
{
<button type="button" class="btn btn-outline-dark mr-2" @onclick="@(async () => await DoInvoicingAgainAsync(used))">
Do invoicing again
<button type="button" class="btn btn-outline-dark mr-2" @onclick="@(async () => await DoInvoicingAsync(used))">
Do invoicing
</button>
}
else
{
<button type="button" class="btn btn-outline-dark mr-2" disabled="disabled">
Do invoicing again
Do invoicing
</button>
}
}
Expand Down Expand Up @@ -285,18 +285,18 @@
@UsageInfoText(used)
</button>

@if (ShowDoInvoicingAgainButton(used))
@if (ShowDoInvoicingButton(used))
{
@if (!used.InvoicingActionButtonDisabled)
{
<button type="button" class="btn btn-sm btn-outline-dark mr-2" @onclick="@(async () => await DoInvoicingAgainAsync(used))">
Do invoicing again
<button type="button" class="btn btn-sm btn-outline-dark mr-2" @onclick="@(async () => await DoInvoicingAsync(used))">
Do invoicing
</button>
}
else
{
<button type="button" class="btn btn-sm btn-outline-dark mr-2" disabled="disabled">
Do invoicing again
Do invoicing
</button>
}
}
Expand Down
16 changes: 0 additions & 16 deletions src/FoxIDs.ControlClient/Pages/Usage/UsageTenants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -165,14 +165,6 @@ private async Task OnEditTenantValidSubmitAsync(GeneralTenantViewModel generalTe
afterMap.AdministratorEmail = afterMap.Customer.InvoiceEmails.First();
afterMap.AdministratorPassword = Util.SecretGenerator.GenerateNewPassword();
afterMap.ControlClientBaseUri = RouteBindingLogic.GetBaseUri();

if (afterMap.Customer != null)
{
if (!afterMap.EnableUsage && !(afterMap.Customer.InvoiceEmails?.Count() > 0) && afterMap.Customer.Name.IsNullOrEmpty())
{
afterMap.Customer = null;
}
}
}));
generalTenant.Form.UpdateModel(tenantResult.Map<TenantViewModel>());
generalTenant.CreateMode = false;
Expand All @@ -183,14 +175,6 @@ private async Task OnEditTenantValidSubmitAsync(GeneralTenantViewModel generalTe
var tenantResult = await TenantService.UpdateTenantAsync(generalTenant.Form.Model.Map<TenantRequest>(afterMap: afterMap =>
{
afterMap.ForUsage = true;

if (afterMap.Customer != null)
{
if (!afterMap.EnableUsage && !(afterMap.Customer.InvoiceEmails?.Count() > 0) && afterMap.Customer.Name.IsNullOrEmpty())
{
afterMap.Customer = null;
}
}
}));
generalTenant.Form.UpdateModel(tenantResult.Map<TenantViewModel>());
toastService.ShowSuccess("Usage tenant updated.");
Expand Down
1 change: 0 additions & 1 deletion src/FoxIDs.ControlClient/Pages/Usage/UsageTenants.razor
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@
<div class="active-group active">
<div class="card">
<div class="card-body mt-2">
<FInputToggle @bind-Value="tenant.Form.Model.EnableUsage" For="@(() => tenant.Form.Model.EnableUsage)" TextType="y.n" />
<FInputSelect @bind-Value="tenant.Form.Model.Currency" For="@(() => tenant.Form.Model.Currency)">
<option value="@string.Empty"></option>
<option value="@Constants.Models.Currency.Eur">@Constants.Models.Currency.Eur</option>
Expand Down
2 changes: 1 addition & 1 deletion src/FoxIDs.ControlShared/FoxIDs.ControlShared.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<Version>1.11.16</Version>
<Version>1.11.17</Version>
<RootNamespace>FoxIDs</RootNamespace>
<Authors>Anders Revsgaard</Authors>
<Company>ITfoxtec</Company>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{
public class UsageInvoicingAction : UsageRequest
{
public bool DoInvoicingAgain { get; set; }
public bool DoInvoicing { get; set; }

public bool DoSendInvoiceAgain { get; set; }

Expand Down
2 changes: 1 addition & 1 deletion src/FoxIDs.Shared/FoxIDs.Shared.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<Version>1.11.16</Version>
<Version>1.11.17</Version>
<RootNamespace>FoxIDs</RootNamespace>
<Authors>Anders Revsgaard</Authors>
<Company>ITfoxtec</Company>
Expand Down
2 changes: 1 addition & 1 deletion src/FoxIDs.SharedBase/FoxIDs.SharedBase.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<Version>1.11.16</Version>
<Version>1.11.17</Version>
<RootNamespace>FoxIDs</RootNamespace>
<Authors>Anders Revsgaard</Authors>
<Company>ITfoxtec</Company>
Expand Down
2 changes: 1 addition & 1 deletion src/FoxIDs/FoxIDs.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<Version>1.11.16</Version>
<Version>1.11.17</Version>
<RootNamespace>FoxIDs</RootNamespace>
<Authors>Anders Revsgaard</Authors>
<Company>ITfoxtec</Company>
Expand Down