Skip to content

Commit

Permalink
Merge pull request #327 from fiskaltrust/DailyClosings-Without-Action…
Browse files Browse the repository at this point in the history
…Journal

Read the dailyclosingNumber from the ftStateData property
  • Loading branch information
LeilaZarban authored Jul 22, 2024
2 parents 0b24014 + 683685f commit 02f0839
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 4 deletions.
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

0 comments on commit 02f0839

Please sign in to comment.