Skip to content
Open
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 @@ -41,6 +41,7 @@ public void Should_build_filter_with_non_dependent_fields()
.WithOkud(Okud.Parse("1234567"))
.WithRegNumberOfPfrDocflow(PfrRegNumber.Parse("123-456-789012"))
.WithTypes(DocflowType.Fns534Report, DocflowType.Fns534Letter)
.WithSuccessStates(DocflowState.Successful, DocflowState.Warning)
.WithFormName("the form")
.WithCreatedFrom(createdFrom)
.WithCreatedTo(createdTo)
Expand Down Expand Up @@ -69,7 +70,9 @@ public void Should_build_filter_with_non_dependent_fields()
("periodFrom", "2021-07-08T00:00:00.0000000"),
("periodTo", "2021-07-18T00:00:00.0000000"),
("type", "fns534-report"),
("type", "fns534-letter")
("type", "fns534-letter"),
("successState", "successful"),
("successState", "warning")
);
}

Expand Down Expand Up @@ -144,6 +147,31 @@ public void Should_create_correct_filter_with_existing_docflow_type(DocflowType
ShouldHaveExpectedQueryParameters(filter, ("type", type.ToUrn()!.Nss));
}

[Test]
public void Should_create_correct_filter_with_success_states()
{
var filter = new DocflowFilterBuilder()
.WithSuccessStates(DocflowState.Successful, DocflowState.Warning)
.CreateFilter();

ShouldHaveExpectedQueryParameters(
filter,
("successState", "successful"),
("successState", "warning"));
}

[Test]
public void Should_create_correct_filter_with_non_existing_state_in_sdk()
{
var filter = new DocflowFilterBuilder()
.WithSuccessStates(new DocflowState("urn:docflow-state:unknown-state"))
.CreateFilter();

ShouldHaveExpectedQueryParameters(
filter,
("successState", "unknown-state"));
}

private static readonly DocflowType[] TypeCases =
{
DocflowType.PfrAncillary,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using JetBrains.Annotations;
using Kontur.Extern.Api.Client.Models.Common;
using Kontur.Extern.Api.Client.Common.Time;
using Kontur.Extern.Api.Client.Models.Common;
using Kontur.Extern.Api.Client.Models.Common.Enums;
using Kontur.Extern.Api.Client.Models.Docflows.Enums;

Expand Down Expand Up @@ -78,6 +78,12 @@ public class DocflowFilter
/// </summary>
public void SetTypes(DocflowType[] value) => queryParameters.Set(value);

/// <summary>
/// Состояния документооборотов
/// </summary>
/// <param name="value"></param>
public void SetSuccessStates(DocflowState[] value) => queryParameters.Set(value);

/// <summary>
/// КНД – код налоговой декларации. Задается по маске XXXXXXX, где Х - это цифра от 0 до 9
/// </summary>
Expand Down Expand Up @@ -154,6 +160,7 @@ private class QueryParameters
public const string createdFrom = nameof(createdFrom);
public const string createdTo = nameof(createdTo);
public const string type = nameof(type);
public const string successState = nameof(successState);
public const string knd = nameof(knd);
public const string okud = nameof(okud);
public const string okpo = nameof(okpo);
Expand All @@ -171,7 +178,8 @@ private class QueryParameters
private readonly Dictionary<string, string> queryParameters = new();
private readonly List<string> types = new(0);
private readonly List<string> pfrLetterTypes = new(0);

private readonly List<string> successStates = new(0);

public IEnumerable<(string name, string value)> GetParameters()
{
foreach (var pair in queryParameters)
Expand All @@ -188,6 +196,11 @@ private class QueryParameters
{
yield return (pfrLetterCategory, category);
}

foreach (var state in successStates)
{
yield return (successState, state);
}
}

public void Set(string parameterName, bool? value) =>
Expand Down Expand Up @@ -245,6 +258,23 @@ public void Set(PfrLetterType[]? letterTypes)
}
}

public void Set(DocflowState[]? states)
{
if (states is null)
{
successStates.Clear();
}
else
{
foreach (var state in states)
{
var urn = state.ToUrn();
if (!successStates.Contains(urn.Nss))
successStates.Add(urn.Nss);
}
}
}

public void Set(string parameterName, string? value) =>
SetValue(parameterName, value);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
using System.Diagnostics.CodeAnalysis;
using JetBrains.Annotations;
using Kontur.Extern.Api.Client.ApiLevel.Models.Requests.Docflows;
using Kontur.Extern.Api.Client.Common.Time;
using Kontur.Extern.Api.Client.Exceptions;
using Kontur.Extern.Api.Client.Models.Common.Enums;
using Kontur.Extern.Api.Client.Models.Docflows.Enums;
using Kontur.Extern.Api.Client.Models.Numbers;
using Kontur.Extern.Api.Client.Common.Time;
using Kontur.Extern.Api.Client.Models.Common.Enums;

namespace Kontur.Extern.Api.Client.Model.DocflowFiltering
{
Expand Down Expand Up @@ -138,6 +138,12 @@ public DocflowFilterBuilder WithTypes(params DocflowType[] types)
return this;
}

public DocflowFilterBuilder WithSuccessStates(params DocflowState[] states)
{
filter.SetSuccessStates(states);
return this;
}

/// <summary>
/// КНД – код налоговой декларации.
/// </summary>
Expand Down