Skip to content

Commit

Permalink
Adjust reports API.
Browse files Browse the repository at this point in the history
  • Loading branch information
giorgos07 committed Feb 15, 2019
1 parent 5ffc697 commit d39b144
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 13 deletions.
5 changes: 3 additions & 2 deletions src/Incontrl.Sdk/Abstractions/IPastReportApi.cs
Expand Up @@ -17,11 +17,12 @@ public interface IPastReportApi
/// <summary>
/// Generates or updates a report for a subscription. This is a system call.
/// </summary>
/// <param name="frequency">The type of report to create or update.</param>
/// <param name="frequency">The frequency of the report to create.</param>
/// <param name="type">The type of report to create.</param>
/// <param name="month">The month of the past report to generate.</param>
/// <param name="year">The year of the past report to generate.</param>
/// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive notice of cancellation.</param>
/// <returns>Returns the task object representing the asynchronous operation.</returns>
Task<Report> CreateAsync(ReportingFrequency frequency, int month, int year, CancellationToken cancellationToken = default(CancellationToken));
Task<Report> CreateAsync(ReportingFrequency frequency, ReportType type, int month, int year, CancellationToken cancellationToken = default(CancellationToken));
}
}
5 changes: 3 additions & 2 deletions src/Incontrl.Sdk/Abstractions/IReportApi.cs
Expand Up @@ -17,10 +17,11 @@ public interface IReportApi
/// <summary>
/// Generates or updates a report for a subscription. This is a system call.
/// </summary>
/// <param name="frequency">The type of report to create or update.</param>
/// <param name="frequency">The frequency the of report to create or update.</param>
/// <param name="type">The type of the report.</param>
/// <param name="document">The document that was created and will be included in the report.</param>
/// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive notice of cancellation.</param>
/// <returns>Returns the task object representing the asynchronous operation.</returns>
Task<Report> CreateAsync(ReportingFrequency frequency, Document document, CancellationToken cancellationToken = default(CancellationToken));
Task<Report> UpsertAsync(ReportingFrequency frequency, ReportType type, Document document, CancellationToken cancellationToken = default(CancellationToken));
}
}
4 changes: 2 additions & 2 deletions src/Incontrl.Sdk/Incontrl.Sdk.csproj
Expand Up @@ -3,8 +3,8 @@
<Description>Incontrl.io .Net SDK</Description>
<Title>Incontrl.Net Class Library</Title>
<Copyright>Copyright (c) 2017 Indice</Copyright>
<VersionPrefix>2.8.19</VersionPrefix>
<!--<VersionSuffix>beta3</VersionSuffix>-->
<VersionPrefix>2.9.0</VersionPrefix>
<VersionSuffix>beta3</VersionSuffix>
<Authors>Constantinos Leftheris, Giorgos Manoltzas</Authors>
<TargetFrameworks>net452;netstandard1.4;netstandard2.0</TargetFrameworks>
<AssemblyTitle>Incontrl.Sdk</AssemblyTitle>
Expand Down
51 changes: 51 additions & 0 deletions src/Incontrl.Sdk/Models/Report.cs
Expand Up @@ -46,6 +46,11 @@ public class Report
/// A report for every record type.
/// </summary>
public ReportDetails[] PerRecordType { get; set; }

/// <summary>
/// The <see cref="DateTime"/> where the report was created.
/// </summary>
public DateTimeOffset? CreatedAt { get; set; }
}

/// <summary>
Expand Down Expand Up @@ -77,6 +82,31 @@ public class ReportDetails
/// The overall tax.
/// </summary>
public decimal? TotalTax { get; set; }

/// <summary>
///
/// </summary>
public decimal? Total { get; set; }

/// <summary>
///
/// </summary>
public decimal? TotalNet { get; set; }

/// <summary>
///
/// </summary>
public decimal? SubTotal { get; set; }

/// <summary>
///
/// </summary>
public decimal? TotalDiscount { get; set; }

/// <summary>
///
/// </summary>
public decimal? TotalPayable { get; set; }
}

/// <summary>
Expand Down Expand Up @@ -109,4 +139,25 @@ public enum ReportingFrequency : short
/// </summary>
Biyearly = 24
}

/// <summary>
/// The type of the report.
/// </summary>
public enum ReportType : short
{
/// <summary>
/// Issued
/// </summary>
Issued,

/// <summary>
/// Paid
/// </summary>
Paid,

/// <summary>
/// Due
/// </summary>
Due
}
}
3 changes: 2 additions & 1 deletion src/Incontrl.Sdk/Services/ClientBase.cs
Expand Up @@ -62,7 +62,8 @@ internal sealed class ClientBase

public async Task<TResponse> PostAsync<TRequest, TResponse>(string requestUri, TRequest model, CancellationToken cancellationToken = default(CancellationToken)) {
var response = default(JsonResponse<TResponse>);
var httpMessage = await _httpClient.PostAsync(requestUri, JsonRequest.For(model), cancellationToken).ConfigureAwait(false);
var uri = string.Format(requestUri);
var httpMessage = await _httpClient.PostAsync(uri, JsonRequest.For(model), cancellationToken).ConfigureAwait(false);
var content = await httpMessage.Content.ReadAsStringAsync().ConfigureAwait(false);

if (httpMessage.IsSuccessStatusCode) {
Expand Down
4 changes: 2 additions & 2 deletions src/Incontrl.Sdk/Services/PastReportApi.cs
Expand Up @@ -13,7 +13,7 @@ internal class PastReportApi : IPastReportApi

public string SubscriptionId { get; set; }

public Task<Report> CreateAsync(ReportingFrequency frequency, int month, int year, CancellationToken cancellationToken = default(CancellationToken)) =>
_clientBase.PostAsync<object, Report>($"subscriptions/{SubscriptionId}/past-reports/{frequency}?position={month}&year={year}", null, cancellationToken);
public Task<Report> CreateAsync(ReportingFrequency frequency, ReportType type, int month, int year, CancellationToken cancellationToken = default(CancellationToken)) =>
_clientBase.PostAsync<object, Report>($"subscriptions/{SubscriptionId}/past-reports?frequency={frequency}&position={month}&year={year}&type={type}", null, cancellationToken);
}
}
4 changes: 2 additions & 2 deletions src/Incontrl.Sdk/Services/ReportApi.cs
Expand Up @@ -13,7 +13,7 @@ internal class ReportApi : IReportApi

public string SubscriptionId { get; set; }

public Task<Report> CreateAsync(ReportingFrequency frequency, Document document, CancellationToken cancellationToken = default(CancellationToken)) =>
_clientBase.PostAsync<Document, Report>($"subscriptions/{SubscriptionId}/reports/{frequency}", document, cancellationToken);
public Task<Report> UpsertAsync(ReportingFrequency frequency, ReportType type, Document document, CancellationToken cancellationToken = default(CancellationToken)) =>
_clientBase.PostAsync<Document, Report>($"subscriptions/{SubscriptionId}/reports?frequency={frequency}&type={type}", document, cancellationToken);
}
}
4 changes: 2 additions & 2 deletions test/Incontrl.Sdk.Tests/FluentApiTests.cs
Expand Up @@ -489,8 +489,8 @@ await api.Subscriptions(subscriptionId)

#region Reports
var reports = await api.Subscriptions().Reports().ListAsync();
var generatedReport = await api.Subscriptions(subscriptionId).Reports().CreateAsync(ReportingFrequency.Monthly, new Document { });
var generatedPastReport = await api.Subscriptions(subscriptionId).PastReports().CreateAsync(ReportingFrequency.Monthly, 1, 2018);
var generatedReport = await api.Subscriptions(subscriptionId).Reports().UpsertAsync(ReportingFrequency.Semesterly, ReportType.Issued, new Document { });
var generatedPastReport = await api.Subscriptions(subscriptionId).PastReports().CreateAsync(ReportingFrequency.Monthly, ReportType.Paid, 1, 2018);
#endregion
}
}
Expand Down

0 comments on commit d39b144

Please sign in to comment.