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

Read the dailyclosingNumber from the ftStateData property #327

Merged
merged 2 commits into from
Jul 22, 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 @@ -9,6 +9,7 @@
using fiskaltrust.Middleware.Contracts.Repositories;
using fiskaltrust.storage.V0;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;


namespace fiskaltrust.Middleware.Localization.QueueDE.Repositories
Expand All @@ -33,15 +34,26 @@ public async Task<List<DailyClosingReceipt>> GetAsync()

foreach (var aj in dailyClosings)
{
var closingNumber = JsonConvert.DeserializeAnonymousType(aj.DataJson, new { closingNumber = 0L }).closingNumber;

var queueItem = aj.ftQueueItemId == aj.ftQueueId
? await GetQueueItemOfMissingIdAsync(aj).ConfigureAwait(false)
: await _queueItemRepository.GetAsync(aj.ftQueueItemId).ConfigureAwait(false);

var closingNumber = JsonConvert.DeserializeAnonymousType(aj.DataJson, new JObject()).Property("closingNumber")?.Value.Value<long?>();
if(closingNumber == null)
{
var response = JsonConvert.DeserializeObject<ReceiptResponse>(queueItem.response);
var currentStateData = new JObject();
if (!string.IsNullOrEmpty(response.ftStateData))
{
currentStateData = (JObject) JsonConvert.DeserializeObject(response.ftStateData);
}

closingNumber = currentStateData.Property("DailyClosingNumber")?.Value.Value<long>() ?? 0L;
}

var dailyClosingReceipt = new DailyClosingReceipt
{
ZNumber = closingNumber,
ZNumber = (long)closingNumber,
};
if (queueItem != null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,11 @@ public async Task DailyClosingRepositoryTest_IncludeActionjWithNoQueueItemId_Val
closings[2].QueueRow.Should().Be(4);
closings[3].ZNumber.Should().Be(4);
closings[3].QueueRow.Should().Be(5);
closings[4].QueueRow.Should().Be(6);
closings[4].ZNumber.Should().Be(5);

}

private (IEnumerable<ftActionJournal>, IEnumerable<ftQueueItem>) GetDailyClosingData()
{
var queueId = Guid.NewGuid();
Expand All @@ -61,6 +63,10 @@ public async Task DailyClosingRepositoryTest_IncludeActionjWithNoQueueItemId_Val

var queueItem5_timestamp = DateTime.Now.Ticks;
var actionJournal5_timestamp = DateTime.Now.Ticks;
Task.Delay(1).Wait();

var queueItem6_timestamp = DateTime.Now.Ticks;
var actionJournal6_timestamp = DateTime.Now.Ticks;

var actionJournals = new List<ftActionJournal>() {
new() {
Expand Down Expand Up @@ -95,6 +101,14 @@ public async Task DailyClosingRepositoryTest_IncludeActionjWithNoQueueItemId_Val
Type = "4445000800000007",
DataJson = "{\"closingNumber\": 4, \"ftReceiptNumerator\": 5}"
},
new() {
ftQueueId = queueId,
ftActionJournalId = Guid.NewGuid(),
ftQueueItemId = queueId,
TimeStamp = actionJournal6_timestamp,
Type = "4445000800000007",
DataJson = "{\"ftReceiptNumerator\": 6}"
},
};

var queueItems = new List<ftQueueItem>()
Expand Down Expand Up @@ -134,6 +148,13 @@ public async Task DailyClosingRepositoryTest_IncludeActionjWithNoQueueItemId_Val
TimeStamp = queueItem5_timestamp,
response = JsonConvert.SerializeObject(new ReceiptResponse{ ftReceiptIdentification = "ft5#" })
},
new() {
ftQueueItemId = Guid.NewGuid(),
ftQueueRow = 6,
ftQueueId = queueId,
TimeStamp = queueItem6_timestamp,
response = JsonConvert.SerializeObject(new ReceiptResponse{ ftReceiptIdentification = "ft6#", ftStateData="{\"DailyClosingNumber\":5}" })
},
};

return (actionJournals, queueItems);
Expand Down
Loading