From d39b1442274ef96f16afa6dc85fdd091aeda697a Mon Sep 17 00:00:00 2001 From: Georgios Manoltzas Date: Fri, 15 Feb 2019 11:45:13 +0200 Subject: [PATCH] Adjust reports API. --- .../Abstractions/IPastReportApi.cs | 5 +- src/Incontrl.Sdk/Abstractions/IReportApi.cs | 5 +- src/Incontrl.Sdk/Incontrl.Sdk.csproj | 4 +- src/Incontrl.Sdk/Models/Report.cs | 51 +++++++++++++++++++ src/Incontrl.Sdk/Services/ClientBase.cs | 3 +- src/Incontrl.Sdk/Services/PastReportApi.cs | 4 +- src/Incontrl.Sdk/Services/ReportApi.cs | 4 +- test/Incontrl.Sdk.Tests/FluentApiTests.cs | 4 +- 8 files changed, 67 insertions(+), 13 deletions(-) diff --git a/src/Incontrl.Sdk/Abstractions/IPastReportApi.cs b/src/Incontrl.Sdk/Abstractions/IPastReportApi.cs index 5826287..d55bb78 100644 --- a/src/Incontrl.Sdk/Abstractions/IPastReportApi.cs +++ b/src/Incontrl.Sdk/Abstractions/IPastReportApi.cs @@ -17,11 +17,12 @@ public interface IPastReportApi /// /// Generates or updates a report for a subscription. This is a system call. /// - /// The type of report to create or update. + /// The frequency of the report to create. + /// The type of report to create. /// The month of the past report to generate. /// The year of the past report to generate. /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// Returns the task object representing the asynchronous operation. - Task CreateAsync(ReportingFrequency frequency, int month, int year, CancellationToken cancellationToken = default(CancellationToken)); + Task CreateAsync(ReportingFrequency frequency, ReportType type, int month, int year, CancellationToken cancellationToken = default(CancellationToken)); } } diff --git a/src/Incontrl.Sdk/Abstractions/IReportApi.cs b/src/Incontrl.Sdk/Abstractions/IReportApi.cs index d610008..5b0de86 100644 --- a/src/Incontrl.Sdk/Abstractions/IReportApi.cs +++ b/src/Incontrl.Sdk/Abstractions/IReportApi.cs @@ -17,10 +17,11 @@ public interface IReportApi /// /// Generates or updates a report for a subscription. This is a system call. /// - /// The type of report to create or update. + /// The frequency the of report to create or update. + /// The type of the report. /// The document that was created and will be included in the report. /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// Returns the task object representing the asynchronous operation. - Task CreateAsync(ReportingFrequency frequency, Document document, CancellationToken cancellationToken = default(CancellationToken)); + Task UpsertAsync(ReportingFrequency frequency, ReportType type, Document document, CancellationToken cancellationToken = default(CancellationToken)); } } diff --git a/src/Incontrl.Sdk/Incontrl.Sdk.csproj b/src/Incontrl.Sdk/Incontrl.Sdk.csproj index 627c5ae..f0321f0 100644 --- a/src/Incontrl.Sdk/Incontrl.Sdk.csproj +++ b/src/Incontrl.Sdk/Incontrl.Sdk.csproj @@ -3,8 +3,8 @@ Incontrl.io .Net SDK Incontrl.Net Class Library Copyright (c) 2017 Indice - 2.8.19 - + 2.9.0 + beta3 Constantinos Leftheris, Giorgos Manoltzas net452;netstandard1.4;netstandard2.0 Incontrl.Sdk diff --git a/src/Incontrl.Sdk/Models/Report.cs b/src/Incontrl.Sdk/Models/Report.cs index 608c77d..be7fc7c 100644 --- a/src/Incontrl.Sdk/Models/Report.cs +++ b/src/Incontrl.Sdk/Models/Report.cs @@ -46,6 +46,11 @@ public class Report /// A report for every record type. /// public ReportDetails[] PerRecordType { get; set; } + + /// + /// The where the report was created. + /// + public DateTimeOffset? CreatedAt { get; set; } } /// @@ -77,6 +82,31 @@ public class ReportDetails /// The overall tax. /// public decimal? TotalTax { get; set; } + + /// + /// + /// + public decimal? Total { get; set; } + + /// + /// + /// + public decimal? TotalNet { get; set; } + + /// + /// + /// + public decimal? SubTotal { get; set; } + + /// + /// + /// + public decimal? TotalDiscount { get; set; } + + /// + /// + /// + public decimal? TotalPayable { get; set; } } /// @@ -109,4 +139,25 @@ public enum ReportingFrequency : short /// Biyearly = 24 } + + /// + /// The type of the report. + /// + public enum ReportType : short + { + /// + /// Issued + /// + Issued, + + /// + /// Paid + /// + Paid, + + /// + /// Due + /// + Due + } } diff --git a/src/Incontrl.Sdk/Services/ClientBase.cs b/src/Incontrl.Sdk/Services/ClientBase.cs index 37d6dbb..fb2b783 100644 --- a/src/Incontrl.Sdk/Services/ClientBase.cs +++ b/src/Incontrl.Sdk/Services/ClientBase.cs @@ -62,7 +62,8 @@ internal sealed class ClientBase public async Task PostAsync(string requestUri, TRequest model, CancellationToken cancellationToken = default(CancellationToken)) { var response = default(JsonResponse); - 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) { diff --git a/src/Incontrl.Sdk/Services/PastReportApi.cs b/src/Incontrl.Sdk/Services/PastReportApi.cs index 98448ed..b48c20c 100644 --- a/src/Incontrl.Sdk/Services/PastReportApi.cs +++ b/src/Incontrl.Sdk/Services/PastReportApi.cs @@ -13,7 +13,7 @@ internal class PastReportApi : IPastReportApi public string SubscriptionId { get; set; } - public Task CreateAsync(ReportingFrequency frequency, int month, int year, CancellationToken cancellationToken = default(CancellationToken)) => - _clientBase.PostAsync($"subscriptions/{SubscriptionId}/past-reports/{frequency}?position={month}&year={year}", null, cancellationToken); + public Task CreateAsync(ReportingFrequency frequency, ReportType type, int month, int year, CancellationToken cancellationToken = default(CancellationToken)) => + _clientBase.PostAsync($"subscriptions/{SubscriptionId}/past-reports?frequency={frequency}&position={month}&year={year}&type={type}", null, cancellationToken); } } diff --git a/src/Incontrl.Sdk/Services/ReportApi.cs b/src/Incontrl.Sdk/Services/ReportApi.cs index 74286bf..35f2137 100644 --- a/src/Incontrl.Sdk/Services/ReportApi.cs +++ b/src/Incontrl.Sdk/Services/ReportApi.cs @@ -13,7 +13,7 @@ internal class ReportApi : IReportApi public string SubscriptionId { get; set; } - public Task CreateAsync(ReportingFrequency frequency, Document document, CancellationToken cancellationToken = default(CancellationToken)) => - _clientBase.PostAsync($"subscriptions/{SubscriptionId}/reports/{frequency}", document, cancellationToken); + public Task UpsertAsync(ReportingFrequency frequency, ReportType type, Document document, CancellationToken cancellationToken = default(CancellationToken)) => + _clientBase.PostAsync($"subscriptions/{SubscriptionId}/reports?frequency={frequency}&type={type}", document, cancellationToken); } } diff --git a/test/Incontrl.Sdk.Tests/FluentApiTests.cs b/test/Incontrl.Sdk.Tests/FluentApiTests.cs index 40758ab..0bce5fa 100644 --- a/test/Incontrl.Sdk.Tests/FluentApiTests.cs +++ b/test/Incontrl.Sdk.Tests/FluentApiTests.cs @@ -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 } }