diff --git a/.DS_Store b/.DS_Store
new file mode 100644
index 000000000..7f9929bc6
Binary files /dev/null and b/.DS_Store differ
diff --git a/azure-pipelines/fiskaltrust.Middleware.Queue-Release.yml b/azure-pipelines/fiskaltrust.Middleware.Queue-Release.yml
index e0f8d0baf..2ccba5316 100644
--- a/azure-pipelines/fiskaltrust.Middleware.Queue-Release.yml
+++ b/azure-pipelines/fiskaltrust.Middleware.Queue-Release.yml
@@ -35,3 +35,53 @@ stages:
environment: production
storage: stprodwesteuropepackages
serviceConnection: rg-prod-westeurope-packages
+
+ - template: templates/release-legacy.yml
+ parameters:
+ type: fiskaltrust.Middleware.Queue
+ artifact: build
+ projects:
+ - InMemory
+ - SQLite
+ - EF
+ - MySQL
+ - PostgreSQL
+ stages:
+ - stage: Release_Sandbox_Legacy
+ dependsOn: []
+ templateContext:
+ environment: sandbox-legacy
+ storage: fiskaltrustsandbox
+ serviceConnection: sandbox-legacy-packages
+
+ - stage: Release_Production_Legacy
+ templateContext:
+ dependsOnPrefix: Release_Sandbox_Legacy
+ environment: production-legacy
+ storage: fiskaltrustcommonwe1
+ serviceConnection: production-legacy-packages
+
+ - template: templates/release-legacy-nuget.yml
+ parameters:
+ type: fiskaltrust.Middleware.Queue
+ artifact: build
+ projects:
+ - InMemory
+ - SQLite
+ - EF
+ - MySQL
+ - PostgreSQL
+ stages:
+ - stage: Release_Sandbox_Legacy_Nuget
+ dependsOn: []
+ templateContext:
+ environment: sandbox-legacy-nuget
+ feed: dev
+ serviceConnection: sandbox-legacy-packages
+
+ - stage: Release_Production_Legacy_Nuget
+ templateContext:
+ dependsOnPrefix: Release_Sandbox_Legacy_Nuget
+ environment: production-legacy-nuget
+ feed: middleware
+ serviceConnection: production-legacy-packages
\ No newline at end of file
diff --git a/azure-pipelines/fiskaltrust.Middleware.SCU.DE-Release.yml b/azure-pipelines/fiskaltrust.Middleware.SCU.DE-Release.yml
index 6b27516f0..0f23774c9 100644
--- a/azure-pipelines/fiskaltrust.Middleware.SCU.DE-Release.yml
+++ b/azure-pipelines/fiskaltrust.Middleware.SCU.DE-Release.yml
@@ -38,3 +38,59 @@ stages:
environment: production
storage: stprodwesteuropepackages
serviceConnection: rg-prod-westeurope-packages
+
+ - template: templates/release-legacy.yml
+ parameters:
+ type: fiskaltrust.Middleware.SCU.DE
+ artifact: build
+ projects:
+ - CryptoVision
+ - DieboldNixdorf
+ - Epson
+ - FiskalyCertified
+ - Swissbit
+ - DeutscheFiskal
+ - SwissbitCloud
+ - InMemory
+ stages:
+ - stage: Release_Sandbox_Legacy
+ dependsOn: []
+ templateContext:
+ environment: sandbox-legacy
+ storage: fiskaltrustsandbox
+ serviceConnection: sandbox-legacy-packages
+
+ - stage: Release_Production_Legacy
+ templateContext:
+ dependsOnPrefix: Release_Sandbox_Legacy
+ environment: production-legacy
+ storage: fiskaltrustcommonwe1
+ serviceConnection: production-legacy-packages
+
+ - template: templates/release-legacy-nuget.yml
+ parameters:
+ type: fiskaltrust.Middleware.SCU.DE
+ artifact: build
+ projects:
+ - CryptoVision
+ - DieboldNixdorf
+ - Epson
+ - FiskalyCertified
+ - Swissbit
+ - DeutscheFiskal
+ - SwissbitCloud
+ - InMemory
+ stages:
+ - stage: Release_Sandbox_Legacy_Nuget
+ dependsOn: []
+ templateContext:
+ environment: sandbox-legacy-nuget
+ feed: dev
+ serviceConnection: sandbox-legacy-packages
+
+ - stage: Release_Production_Legacy_Nuget
+ templateContext:
+ dependsOnPrefix: Release_Sandbox_Legacy_Nuget
+ environment: production-legacy-nuget
+ feed: middleware
+ serviceConnection: production-legacy-packages
\ No newline at end of file
diff --git a/azure-pipelines/fiskaltrust.Middleware.SCU.IT-Release.yml b/azure-pipelines/fiskaltrust.Middleware.SCU.IT-Release.yml
index d6b3dcf92..be8c33167 100644
--- a/azure-pipelines/fiskaltrust.Middleware.SCU.IT-Release.yml
+++ b/azure-pipelines/fiskaltrust.Middleware.SCU.IT-Release.yml
@@ -16,7 +16,9 @@ stages:
type: fiskaltrust.Middleware.SCU.IT
artifact: build
projects:
- - Epson
+ - EpsonRTPrinter
+ - CustomRTPrinter
+ - CustomRTServer
stages:
- stage: Release_Sandbox
dependsOn: []
@@ -25,9 +27,32 @@ stages:
storage: stdevwesteuropepackages
serviceConnection: rg-dev-westeurope-packages
- # - stage: Release_Production
- # templateContext:
- # environment: production
- # storage: stprodwesteuropepackages
- # serviceConnection: rg-prod-westeurope-packages
- # dependsOnPrefix: Release_Sandbox
+ - stage: Release_Production
+ templateContext:
+ environment: production
+ storage: stprodwesteuropepackages
+ serviceConnection: rg-prod-westeurope-packages
+ dependsOnPrefix: Release_Sandbox
+
+ - template: templates/release-legacy.yml
+ parameters:
+ type: fiskaltrust.Middleware.SCU.IT
+ artifact: build
+ projects:
+ - EpsonRTPrinter
+ - CustomRTPrinter
+ - CustomRTServer
+ stages:
+ - stage: Release_Sandbox_Legacy
+ dependsOn: []
+ templateContext:
+ environment: sandbox-legacy
+ storage: fiskaltrustsandbox
+ serviceConnection: sandbox-legacy-packages
+
+ - stage: Release_Production_Legacy
+ templateContext:
+ dependsOnPrefix: Release_Sandbox_Legacy
+ environment: production-legacy
+ storage: fiskaltrustcommonwe1
+ serviceConnection: production-legacy-packages
\ No newline at end of file
diff --git a/azure-pipelines/fiskaltrust.Middleware.SCU.IT.yml b/azure-pipelines/fiskaltrust.Middleware.SCU.IT.yml
index 061d1f3ab..7d365e282 100644
--- a/azure-pipelines/fiskaltrust.Middleware.SCU.IT.yml
+++ b/azure-pipelines/fiskaltrust.Middleware.SCU.IT.yml
@@ -62,4 +62,6 @@ stages:
parameters:
workingDirectory: scu-it
projects:
- - fiskaltrust.Middleware.SCU.IT.Epson
+ - fiskaltrust.Middleware.SCU.IT.EpsonRTPrinter
+ - fiskaltrust.Middleware.SCU.IT.CustomRTServer
+ - fiskaltrust.Middleware.SCU.IT.CustomRTPrinter
diff --git a/azure-pipelines/templates/release-legacy-nuget.yml b/azure-pipelines/templates/release-legacy-nuget.yml
new file mode 100644
index 000000000..dc576bc64
--- /dev/null
+++ b/azure-pipelines/templates/release-legacy-nuget.yml
@@ -0,0 +1,55 @@
+parameters:
+- name: stages
+ type: stageList
+
+- name: type
+ type: string
+
+- name: artifact
+ type: string
+ default: current
+
+- name: projects
+ type: object
+
+stages:
+- ${{ each project in parameters.projects }}:
+ - ${{ each stage in parameters.stages }}:
+ - ${{ each pair in stage }}:
+ ${{ if eq(pair.key, 'stage') }}:
+ stage: ${{ pair.value }}_${{ project }}
+ ${{ else }}:
+ ${{ pair.key }}: ${{ pair.value }}
+
+ displayName: ${{ stage.templateContext.environment }} ${{ project }}
+
+ ${{ if ne(stage.templateContext.dependsOnPrefix, '') }}:
+ dependsOn: ${{ stage.templateContext.dependsOnPrefix }}_${{ replace(project, '.', '_') }}
+
+ ${{ if eq(stage.templateContext.environment, 'production-legacy-nuget') }}:
+ condition: and(startsWith(variables['Build.SourceBranch'], 'refs/tags/'), contains(variables['Build.SourceBranch'], lower('/${{ project }}/v')))
+ ${{ else }}:
+ condition: or(not(startsWith(variables['Build.SourceBranch'], 'refs/tags/')), and(startsWith(variables['Build.SourceBranch'], 'refs/tags/'), contains(variables['Build.SourceBranch'], lower('/${{ project }}/v'))))
+
+ jobs:
+ - deployment: Release
+
+ pool:
+ vmImage: windows-latest
+
+ environment: ${{ stage.templateContext.serviceConnection }}
+
+ strategy:
+ runOnce:
+ deploy:
+ steps:
+ - download: ${{ parameters.artifact }}
+ artifact: packages-v1
+ displayName: "Download artifact"
+
+ - task: NuGetCommand@2
+ displayName: 'NuGet push'
+ inputs:
+ command: push
+ packagesToPush: '${{ parameters.type }}.${{ project }}.*.nupkg'
+ publishVstsFeed: '${{ stage.templateContext.feed }}'
\ No newline at end of file
diff --git a/azure-pipelines/templates/release-legacy.yml b/azure-pipelines/templates/release-legacy.yml
new file mode 100644
index 000000000..3cb5e1a0d
--- /dev/null
+++ b/azure-pipelines/templates/release-legacy.yml
@@ -0,0 +1,57 @@
+parameters:
+- name: stages
+ type: stageList
+
+- name: type
+ type: string
+
+- name: artifact
+ type: string
+ default: current
+
+- name: projects
+ type: object
+
+stages:
+- ${{ each project in parameters.projects }}:
+ - ${{ each stage in parameters.stages }}:
+ - ${{ each pair in stage }}:
+ ${{ if eq(pair.key, 'stage') }}:
+ stage: ${{ pair.value }}_${{ project }}
+ ${{ else }}:
+ ${{ pair.key }}: ${{ pair.value }}
+
+ displayName: ${{ stage.templateContext.environment }} ${{ project }}
+
+ ${{ if ne(stage.templateContext.dependsOnPrefix, '') }}:
+ dependsOn: ${{ stage.templateContext.dependsOnPrefix }}_${{ replace(project, '.', '_') }}
+
+ ${{ if eq(stage.templateContext.environment, 'production-legacy') }}:
+ condition: and(startsWith(variables['Build.SourceBranch'], 'refs/tags/'), contains(variables['Build.SourceBranch'], lower('/${{ project }}/v')))
+ ${{ else }}:
+ condition: or(not(startsWith(variables['Build.SourceBranch'], 'refs/tags/')), and(startsWith(variables['Build.SourceBranch'], 'refs/tags/'), contains(variables['Build.SourceBranch'], lower('/${{ project }}/v'))))
+
+ jobs:
+ - deployment: Release
+
+ pool:
+ vmImage: windows-latest
+
+ environment: ${{ stage.templateContext.serviceConnection }}
+
+ strategy:
+ runOnce:
+ deploy:
+ steps:
+ - download: ${{ parameters.artifact }}
+ artifact: packages-v1
+ displayName: "Download artifact"
+
+ - task: AzureCLI@2
+ displayName: "Publish to blob storage"
+ inputs:
+ azureSubscription: ${{ stage.templateContext.serviceConnection }}
+ scriptType: ps
+ scriptLocation: inlineScript
+ inlineScript: |
+ az storage blob upload-batch --account-name ${{ stage.templateContext.storage }} -d "packages" -s "$(Pipeline.Workspace)/${{ parameters.artifact }}/packages-v1/" --pattern "${{ parameters.type }}.${{ project }}.*.nupkg"
\ No newline at end of file
diff --git a/azure-pipelines/templates/scu-it/build-nuget.template.yml b/azure-pipelines/templates/scu-it/build-nuget.template.yml
index b1277e634..b51843755 100644
--- a/azure-pipelines/templates/scu-it/build-nuget.template.yml
+++ b/azure-pipelines/templates/scu-it/build-nuget.template.yml
@@ -43,8 +43,16 @@ steps:
$(WorkingDirectory)/src/**/*fiskaltrust*.exe
- script: dotnet pack --output $(Build.ArtifactStagingDirectory) --no-restore --configuration $(buildConfiguration)
- displayName: 'dotnet pack fiskaltrust.Middleware.SCU.IT.Epson'
- workingDirectory: '$(WorkingDirectory)/src/fiskaltrust.Middleware.SCU.IT.Epson'
+ displayName: 'dotnet pack fiskaltrust.Middleware.SCU.IT.EpsonRTPrinter'
+ workingDirectory: '$(WorkingDirectory)/src/fiskaltrust.Middleware.SCU.IT.EpsonRTPrinter'
+
+- script: dotnet pack --output $(Build.ArtifactStagingDirectory) --no-restore --configuration $(buildConfiguration)
+ displayName: 'dotnet pack fiskaltrust.Middleware.SCU.IT.CustomRTServer'
+ workingDirectory: '$(WorkingDirectory)/src/fiskaltrust.Middleware.SCU.IT.CustomRTServer'
+
+- script: dotnet pack --output $(Build.ArtifactStagingDirectory) --no-restore --configuration $(buildConfiguration)
+ displayName: 'dotnet pack fiskaltrust.Middleware.SCU.IT.CustomRTPrinter'
+ workingDirectory: '$(WorkingDirectory)/src/fiskaltrust.Middleware.SCU.IT.CustomRTPrinter'
- task: PublishBuildArtifacts@1
displayName: 'Publish Artifact: drop'
diff --git a/nuget.config b/nuget.config
index 0892f6b55..9abfa3796 100644
--- a/nuget.config
+++ b/nuget.config
@@ -6,6 +6,8 @@
-
+
+
\ No newline at end of file
diff --git a/queue/fiskaltrust.Middleware.sln b/queue/fiskaltrust.Middleware.sln
index 49a6d21aa..b686d7b64 100644
--- a/queue/fiskaltrust.Middleware.sln
+++ b/queue/fiskaltrust.Middleware.sln
@@ -127,13 +127,13 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "fiskaltrust.Middleware.Loca
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "fiskaltrust.Middleware.Localization.QueueIT", "src\fiskaltrust.Middleware.Localization.QueueIT\fiskaltrust.Middleware.Localization.QueueIT.csproj", "{65633C3A-65AA-4E05-8E56-7A348872CCC3}"
EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "fiskaltrust.Middleware.Localization.QueueIT.UnitTest", "test\fiskaltrust.Middleware.Localization.QueueIT.UnitTest\fiskaltrust.Middleware.Localization.QueueIT.UnitTest.csproj", "{5FAB9D88-4B90-4DF0-B1B7-1F50DF7CFCA4}"
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "fiskaltrust.Middleware.Localization.QueueIT.UnitTest", "test\fiskaltrust.Middleware.Localization.QueueIT.UnitTest\fiskaltrust.Middleware.Localization.QueueIT.UnitTest.csproj", "{5FAB9D88-4B90-4DF0-B1B7-1F50DF7CFCA4}"
EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "fiskaltrust.Middleware.Localization.QueueDEFAULT", "src\fiskaltrust.Middleware.Localization.QueueDEFAULT\fiskaltrust.Middleware.Localization.QueueDEFAULT.csproj", "{3C0310D9-EC55-4115-A2D5-0DC8C1246645}"
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "fiskaltrust.Middleware.Localization.QueueDEFAULT", "src\fiskaltrust.Middleware.Localization.QueueDEFAULT\fiskaltrust.Middleware.Localization.QueueDEFAULT.csproj", "{3C0310D9-EC55-4115-A2D5-0DC8C1246645}"
EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "fiskaltrust.Middleware.Localization.QueueDEFAULT.UnitTest", "test\fiskaltrust.Middleware.Localization.QueueDEFAULT.UnitTest\fiskaltrust.Middleware.Localization.QueueDEFAULT.UnitTest.csproj", "{04B32BB6-2E1D-400F-B7B2-2638483B0825}"
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "fiskaltrust.Middleware.Localization.QueueDEFAULT.UnitTest", "test\fiskaltrust.Middleware.Localization.QueueDEFAULT.UnitTest\fiskaltrust.Middleware.Localization.QueueDEFAULT.UnitTest.csproj", "{04B32BB6-2E1D-400F-B7B2-2638483B0825}"
EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "fiskaltrust.Middleware.Localization.QueueFR.IntegrationTest", "test\fiskaltrust.Middleware.Localization.QueueFR.IntegrationTest\fiskaltrust.Middleware.Localization.QueueFR.IntegrationTest.csproj", "{7F52D143-9179-4FCF-9DC7-B5F1681BD22A}"
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "fiskaltrust.Middleware.Localization.QueueFR.IntegrationTest", "test\fiskaltrust.Middleware.Localization.QueueFR.IntegrationTest\fiskaltrust.Middleware.Localization.QueueFR.IntegrationTest.csproj", "{7F52D143-9179-4FCF-9DC7-B5F1681BD22A}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
diff --git a/queue/src/Directory.Build.props b/queue/src/Directory.Build.props
index 396315fff..f6b2fd8d0 100644
--- a/queue/src/Directory.Build.props
+++ b/queue/src/Directory.Build.props
@@ -3,10 +3,11 @@
netstandard2.0;netstandard2.1;net461;net6
+ NU1901;NU1902;NU1903;NU1904
-
+
NU1605
diff --git a/queue/src/fiskaltrust.Middleware.Contracts/Extensions/ReceiptRequestExtensions.cs b/queue/src/fiskaltrust.Middleware.Contracts/Extensions/ReceiptRequestExtensions.cs
deleted file mode 100644
index 233ce6d12..000000000
--- a/queue/src/fiskaltrust.Middleware.Contracts/Extensions/ReceiptRequestExtensions.cs
+++ /dev/null
@@ -1,14 +0,0 @@
-using fiskaltrust.ifPOS.v1;
-
-namespace fiskaltrust.Middleware.Contracts.Extensions
-{
- public static class ReceiptRequestExtensions
- {
- public static bool IsVoid(this ReceiptRequest receiptRequest)
- {
- return (receiptRequest.ftReceiptCase & 0x0000_0000_0004_0000) > 0x0000;
- }
-
- public static bool IsFailedReceipt(this ReceiptRequest receiptRequest) => (receiptRequest.ftReceiptCase & 0x0000_0000_0001_0000) != 0;
- }
-}
diff --git a/queue/src/fiskaltrust.Middleware.Localization.QueueDE/Extensions/ReceiptRequestExtensions.cs b/queue/src/fiskaltrust.Middleware.Localization.QueueDE/Extensions/ReceiptRequestExtensions.cs
index 228971e1c..523e39c38 100644
--- a/queue/src/fiskaltrust.Middleware.Localization.QueueDE/Extensions/ReceiptRequestExtensions.cs
+++ b/queue/src/fiskaltrust.Middleware.Localization.QueueDE/Extensions/ReceiptRequestExtensions.cs
@@ -109,6 +109,11 @@ public static bool IsFailTransactionReceipt(this ReceiptRequest receiptRequest)
{
return ((receiptRequest.ftReceiptCase & 0x0000_0000_0000_FFFF) == 0x0000_0000_0000_000B);
}
+
+ public static bool IsVoid(this ReceiptRequest receiptRequest)
+ {
+ return (receiptRequest.ftReceiptCase & 0x0000_0000_0004_0000) > 0x0000;
+ }
public static string GetReceiptIdentification(this ReceiptRequest receiptRequest, long receiptNumerator, ulong? transactionNumber)
{
@@ -368,7 +373,7 @@ public static string GetReceiptTaxes(this ReceiptRequest request)
special_2 += item.Amount * GetSignForAmount(item.Quantity, item.Amount);
break;
default:
- zero += item.Amount * GetSignForAmount(item.Quantity, item.Amount);
+ zero += item.Amount * GetSignForAmount(item.Quantity, item.Amount);
break;
}
@@ -393,7 +398,7 @@ public static string GetReceiptTaxes(this ReceiptRequest request)
case 0x0015:
case 0x0016:
case 0x0017:
- item.Amount = item.Amount*GetSignForAmount(item.Quantity, item.Amount);
+ item.Amount = item.Amount * GetSignForAmount(item.Quantity, item.Amount);
zero += item.Amount * -1;
break;
default:
@@ -402,8 +407,8 @@ public static string GetReceiptTaxes(this ReceiptRequest request)
}
//TODO check rounding problesm: round sum(results) towards receipt.totalamount if given
- return FormatAmount(normal) + "_" + FormatAmount(discounted_1) + "_" + FormatAmount( special_1) +
- "_" + FormatAmount(special_2) + "_" + FormatAmount( zero);
+ return FormatAmount(normal) + "_" + FormatAmount(discounted_1) + "_" + FormatAmount(special_1) +
+ "_" + FormatAmount(special_2) + "_" + FormatAmount(zero);
}
private static string FormatAmount(decimal value)
{
@@ -424,10 +429,10 @@ DateTime GetMinDateTime(IEnumerable dts)
request.cbReceiptMoment
}).Min();
}
- private static decimal GetSignForAmount(decimal quantity, decimal amount) => quantity < 0 && amount >= 0 ? -1 : 1;
+ private static decimal GetSignForAmount(decimal quantity, decimal amount) => quantity < 0 && amount >= 0 ? -1 : 1;
public static void CheckForEqualSumChargePayItems(this ReceiptRequest request, ILogger logger)
{
- var chargeAmount = request.cbChargeItems != null ? request.cbChargeItems.Sum( x => x.Amount != null ? x.Amount * GetSignForAmount(x.Quantity, x.Amount) : 0) : 0;
+ var chargeAmount = request.cbChargeItems != null ? request.cbChargeItems.Sum(x => x.Amount != null ? x.Amount * GetSignForAmount(x.Quantity, x.Amount) : 0) : 0;
var payAmount = request.cbPayItems != null ? request.cbPayItems.Sum(x => x.Amount != null ? x.Amount * GetSignForAmount(x.Quantity, x.Amount) : 0) : 0;
if (chargeAmount != payAmount)
{
diff --git a/queue/src/fiskaltrust.Middleware.Localization.QueueDE/MasterData/MasterDataService.cs b/queue/src/fiskaltrust.Middleware.Localization.QueueDE/MasterData/MasterDataService.cs
index 71592b657..59e3ae5d3 100644
--- a/queue/src/fiskaltrust.Middleware.Localization.QueueDE/MasterData/MasterDataService.cs
+++ b/queue/src/fiskaltrust.Middleware.Localization.QueueDE/MasterData/MasterDataService.cs
@@ -1,6 +1,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
+using fiskaltrust.ifPOS.v1.it;
using fiskaltrust.Middleware.Contracts.Models;
using fiskaltrust.Middleware.Contracts.Repositories;
using fiskaltrust.storage.V0.MasterData;
@@ -93,4 +94,4 @@ public async Task PersistConfigurationAsync()
}
}
}
-}
+}
\ No newline at end of file
diff --git a/queue/src/fiskaltrust.Middleware.Localization.QueueIT/Constants/Cases.cs b/queue/src/fiskaltrust.Middleware.Localization.QueueIT/Constants/Cases.cs
index de9582897..dc8e13df7 100644
--- a/queue/src/fiskaltrust.Middleware.Localization.QueueIT/Constants/Cases.cs
+++ b/queue/src/fiskaltrust.Middleware.Localization.QueueIT/Constants/Cases.cs
@@ -1,7 +1,16 @@
+using System.Globalization;
+
namespace fiskaltrust.Middleware.Localization.QueueIT.Constants
{
public class Cases
{
- public const long BASE_STATE = 0x4954000000000000;
+ public const long BASE_STATE = 0x4954_2000_0000_0000;
+
+ public static NumberFormatInfo CurrencyFormatter = new()
+ {
+ NumberDecimalSeparator = ",",
+ NumberGroupSeparator = "",
+ CurrencyDecimalDigits = 2
+ };
}
}
\ No newline at end of file
diff --git a/queue/src/fiskaltrust.Middleware.Localization.QueueIT/Constants/CountrySpecificSettings.cs b/queue/src/fiskaltrust.Middleware.Localization.QueueIT/Constants/CountrySpecificSettings.cs
deleted file mode 100644
index 8dba553c3..000000000
--- a/queue/src/fiskaltrust.Middleware.Localization.QueueIT/Constants/CountrySpecificSettings.cs
+++ /dev/null
@@ -1,22 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Text;
-using fiskaltrust.Middleware.Contracts.Constants;
-using fiskaltrust.Middleware.Contracts.Repositories;
-
-namespace fiskaltrust.Middleware.Localization.QueueIT.Constants
-{
- public class CountrySpecificSettings : ICountrySpecificSettings
- {
- public long CountryBaseState => Cases.BASE_STATE;
-
- public bool ResendFailedReceipts => true;
-
- public ICountrySpecificQueueRepository CountrySpecificQueueRepository { get; private set; }
-
- public CountrySpecificSettings(ICountrySpecificQueueRepository countrySpecificQueueRepository)
- {
- CountrySpecificQueueRepository = countrySpecificQueueRepository;
- }
- }
-}
diff --git a/queue/src/fiskaltrust.Middleware.Localization.QueueIT/Constants/SignatureTypesIT.cs b/queue/src/fiskaltrust.Middleware.Localization.QueueIT/Constants/SignatureTypesIT.cs
new file mode 100644
index 000000000..f7fabee48
--- /dev/null
+++ b/queue/src/fiskaltrust.Middleware.Localization.QueueIT/Constants/SignatureTypesIT.cs
@@ -0,0 +1,21 @@
+namespace fiskaltrust.Middleware.Localization.QueueIT.Constants
+{
+ public enum SignatureTypesIT
+ {
+ PosReceiptPrimarySignature = 0x01,
+ PosReceiptSecondarySignature = 0x02,
+ RTSerialNumber = 0x010,
+ RTZNumber = 0x11,
+ RTDocumentNumber = 0x12,
+ RTDocumentMoment = 0x13,
+ RTDocumentType = 0x14,
+ RTLotteryID = 0x15,
+ RTCustomerID = 0x16,
+ RTServerShaMetadata = 0x17,
+ RTAmount = 0x18,
+
+ RTReferenceZNumber = 0x20,
+ RTReferenceDocumentNumber = 0x21,
+ RTReferenceDocumentMoment = 0x22
+ }
+}
diff --git a/queue/src/fiskaltrust.Middleware.Localization.QueueIT/Constants/States.cs b/queue/src/fiskaltrust.Middleware.Localization.QueueIT/Constants/States.cs
deleted file mode 100644
index df0636bc3..000000000
--- a/queue/src/fiskaltrust.Middleware.Localization.QueueIT/Constants/States.cs
+++ /dev/null
@@ -1,12 +0,0 @@
-namespace fiskaltrust.Middleware.Localization.QueueIT.Constants
-{
- public class States
- {
- public const long ToOldForLateSigning = Cases.BASE_STATE + 0x03;
- }
-
- public class StateFlags
- {
- public const long ReceiptsNeedManualUpload = 0x0000_0000_0001_0000;
- }
-}
\ No newline at end of file
diff --git a/queue/src/fiskaltrust.Middleware.Localization.QueueIT/Exceptions/CbReferenceExistsException.cs b/queue/src/fiskaltrust.Middleware.Localization.QueueIT/Exceptions/CbReferenceExistsException.cs
deleted file mode 100644
index 320a87feb..000000000
--- a/queue/src/fiskaltrust.Middleware.Localization.QueueIT/Exceptions/CbReferenceExistsException.cs
+++ /dev/null
@@ -1,16 +0,0 @@
-using System;
-using System.Runtime.Serialization;
-
-namespace fiskaltrust.Middleware.Localization.QueueIT.Exceptions
-{
- [Serializable]
- public class CbReferenceExistsException : ArgumentException
- {
- public static readonly string _message = "CbReference {0} from Request already exists in the database, use an unique cbReference for each transaction.";
- public CbReferenceExistsException() { }
-
- public CbReferenceExistsException(string reference) : base(string.Format(_message, reference)) { }
- public CbReferenceExistsException(string reference, Exception inner) : base(string.Format(_message, reference), inner) { }
- protected CbReferenceExistsException(SerializationInfo info, StreamingContext context) : base(info, context) { }
- }
-}
diff --git a/queue/src/fiskaltrust.Middleware.Localization.QueueIT/Exceptions/ItemPaymentInequalityException.cs b/queue/src/fiskaltrust.Middleware.Localization.QueueIT/Exceptions/ItemPaymentInequalityException.cs
deleted file mode 100644
index 07e0e1bf9..000000000
--- a/queue/src/fiskaltrust.Middleware.Localization.QueueIT/Exceptions/ItemPaymentInequalityException.cs
+++ /dev/null
@@ -1,16 +0,0 @@
-using System;
-using System.Runtime.Serialization;
-
-namespace fiskaltrust.Middleware.Localization.QueueIT.Exceptions
-{
- [Serializable]
- public class ItemPaymentInequalityException : Exception
- {
- public static readonly string _message = "Pament sum of {0} is inequal to chargeitem sum {1}.";
- public ItemPaymentInequalityException() { }
-
- public ItemPaymentInequalityException(decimal paymentSum, decimal chargeItemSum) : base(string.Format(_message, paymentSum, chargeItemSum)) { }
- public ItemPaymentInequalityException(decimal paymentSum, decimal chargeItemSum, Exception inner) : base(string.Format(_message, paymentSum, chargeItemSum), inner) { }
- protected ItemPaymentInequalityException(SerializationInfo info, StreamingContext context) : base(info, context) { }
- }
-}
diff --git a/queue/src/fiskaltrust.Middleware.Localization.QueueIT/Exceptions/MultiUseVoucherNoSaleException.cs b/queue/src/fiskaltrust.Middleware.Localization.QueueIT/Exceptions/MultiUseVoucherNoSaleException.cs
deleted file mode 100644
index 4cefd41a0..000000000
--- a/queue/src/fiskaltrust.Middleware.Localization.QueueIT/Exceptions/MultiUseVoucherNoSaleException.cs
+++ /dev/null
@@ -1,15 +0,0 @@
-using System;
-using System.Runtime.Serialization;
-
-namespace fiskaltrust.Middleware.Localization.QueueIT.Exceptions
-{
- [Serializable]
- public class MultiUseVoucherNoSaleException : ArgumentException
- {
- public static readonly string _message = "In a multi use Voucher sale no other chargeitems can be sold!";
-
- public MultiUseVoucherNoSaleException() : base(_message) { }
- public MultiUseVoucherNoSaleException(Exception inner) : base(_message, inner) { }
- protected MultiUseVoucherNoSaleException(SerializationInfo info, StreamingContext context) : base(info, context) { }
- }
-}
diff --git a/queue/src/fiskaltrust.Middleware.Localization.QueueIT/Exceptions/RefundException.cs b/queue/src/fiskaltrust.Middleware.Localization.QueueIT/Exceptions/RefundException.cs
deleted file mode 100644
index 342de521b..000000000
--- a/queue/src/fiskaltrust.Middleware.Localization.QueueIT/Exceptions/RefundException.cs
+++ /dev/null
@@ -1,14 +0,0 @@
-using System;
-using System.Runtime.Serialization;
-
-namespace fiskaltrust.Middleware.Localization.QueueIT.Exceptions
-{
- [Serializable]
- public class RefundException : ArgumentException
- {
- public RefundException() { }
- public RefundException(string message) : base(message) { }
- public RefundException(string message, Exception inner) : base(message, inner) { }
- protected RefundException(SerializationInfo info, StreamingContext context) : base(info, context) { }
- }
-}
diff --git a/queue/src/fiskaltrust.Middleware.Localization.QueueIT/Extensions/ChargeItemExtensions.cs b/queue/src/fiskaltrust.Middleware.Localization.QueueIT/Extensions/ChargeItemExtensions.cs
deleted file mode 100644
index 3e528e29a..000000000
--- a/queue/src/fiskaltrust.Middleware.Localization.QueueIT/Extensions/ChargeItemExtensions.cs
+++ /dev/null
@@ -1,117 +0,0 @@
-using fiskaltrust.ifPOS.v1;
-using fiskaltrust.ifPOS.v1.it;
-using fiskaltrust.Middleware.Contracts.Exceptions;
-
-namespace fiskaltrust.Middleware.Localization.QueueIT.Extensions
-{
- public static class ChargeItemExtensions
- {
-
- // TODO: check VAT rate table on printer at the moment according to xml example
- private static readonly int _vatRateBasic = 1;
- private static readonly int _vatRateDeduction1 = 2;
- private static readonly int _vatRateDeduction2 = 3;
- private static readonly int _vatRateDeduction3 = 4;
- private static readonly int _vatRateZero = 0;
-
- public static PaymentAdjustmentType? GetPaymentAdjustmentType(this ChargeItem chargeItem)
- {
- return (chargeItem.ftChargeItemCase & 0xFFFF) switch
- {
- long i when i >= 0x0023 && i <= 0x0027 => PaymentAdjustmentType.Adjustment,
- long i when i >= 0x0028 && i <= 0x002C => PaymentAdjustmentType.SingleUseVoucher,
- _ => null,
- };
- }
-
- public static bool IsPaymentAdjustment(this ChargeItem chargeItem)
- {
- return (chargeItem.ftChargeItemCase & 0xFFFF) switch
- {
- long i when i >= 0x0023 && i <= 0x0027 => true,
- long i when i >= 0x0028 && i <= 0x002D && chargeItem.GetAmount() < 0 => true,
- _ => false,
- };
- }
-
- public static bool IsMultiUseVoucherRedeem(this ChargeItem chargeItem)
- {
- return (chargeItem.ftChargeItemCase & 0xFFFF) switch
- {
- 0x002D => true && chargeItem.GetAmount() < 0,
- _ => false,
- };
- }
-
- public static bool IsMultiUseVoucherSale(this ChargeItem chargeItem)
- {
- return (chargeItem.ftChargeItemCase & 0xFFFF) switch
- {
- 0x002D => true && chargeItem.GetAmount() > 0,
- _ => false,
- };
- }
-
- public static int GetVatGroup(this ChargeItem chargeItem)
- {
- // TODO: check VAT rate table on printer at the moment according to xml example
- switch (chargeItem.ftChargeItemCase & 0xFFFF)
- {
- //0
- case 0x0005:
- case 0x000C:
- case 0x0011:
- case 0x0016:
- case 0x001B:
- case 0x0020:
- case 0x0027:
- case 0x002C:
- case 0x002D:
- return _vatRateZero;
- //22
- case 0x0001:
- case 0x0008:
- case 0x000D:
- case 0x0012:
- case 0x0017:
- case 0x001C:
- case 0x0023:
- case 0x0028:
- return _vatRateBasic;
- //10
- case 0x0002:
- case 0x0009:
- case 0x000E:
- case 0x0013:
- case 0x0018:
- case 0x001D:
- case 0x0024:
- case 0x0029:
- return _vatRateDeduction1;
- //5
- case 0x0003:
- case 0x000A:
- case 0x000F:
- case 0x0014:
- case 0x0019:
- case 0x001E:
- case 0x0025:
- case 0x002A:
- return _vatRateDeduction2;
- //4
- case 0x0004:
- case 0x000B:
- case 0x0010:
- case 0x0015:
- case 0x001A:
- case 0x001F:
- case 0x0026:
- case 0x002B:
- return _vatRateDeduction3;
- default:
- throw new UnknownChargeItemException(chargeItem.ftChargeItemCase);
- }
- }
- public static decimal GetAmount(this ChargeItem chargeItem) => chargeItem.Quantity < 0 && chargeItem.Amount >= 0 ? chargeItem.Amount*(-1) : chargeItem.Amount;
- }
-}
diff --git a/queue/src/fiskaltrust.Middleware.Localization.QueueIT/Extensions/PayItemExtensions.cs b/queue/src/fiskaltrust.Middleware.Localization.QueueIT/Extensions/PayItemExtensions.cs
deleted file mode 100644
index 65f6bd2f9..000000000
--- a/queue/src/fiskaltrust.Middleware.Localization.QueueIT/Extensions/PayItemExtensions.cs
+++ /dev/null
@@ -1,57 +0,0 @@
-using System;
-using fiskaltrust.ifPOS.v1;
-using fiskaltrust.ifPOS.v1.it;
-using fiskaltrust.Middleware.Contracts.Exceptions;
-
-namespace fiskaltrust.Middleware.Localization.QueueIT.Extensions
-{
- public static class PayItemExtensions
- {
- public static PaymentType GetPaymentType(this PayItem payItem)
- {
- switch (payItem.ftPayItemCase & 0xFFFF)
- {
- case 0x0000:
- case 0x0001:
- return PaymentType.Cash;
- case 0x0003:
- return PaymentType.Cheque;
- case 0x0004:
- case 0x0005:
- case 0x0009:
- case 0x000A:
- return PaymentType.CreditCard;
- case 0x0006:
- return PaymentType.Voucher;
- case 0x0002: //TODO foreign currencies
- case 0x0007: //TODO Online payment
- case 0x0008: //TODO Customer card payment
- case 0x000C: //TODO SEPA transfer
- case 0x000D: //TODO Other transfer
- case 0x000E: //TODO Cash book expense
- case 0x000F: //TODO Cash book contribution
- case 0x0010: //TODO Levy
- case 0x0011: //TODO Internal/ material consumption Can be used for bill
- case 0x0012: //TODO 0x4954000000000012 Change tip cash
- throw new NotImplementedException();
- case 0x000B:
- return PaymentType.NotPaid;
- default:
- throw new UnknownPayItemException(payItem.ftPayItemCase);
- }
- }
-
- public static bool IsVoucherRedeem(this PayItem payItem)
- {
- return payItem.GetPaymentType() == PaymentType.Voucher && payItem.GetAmount() > 0;
- }
-
- public static bool IsVoucherSale(this PayItem payItem)
- {
- return payItem.GetPaymentType() == PaymentType.Voucher && payItem.GetAmount() < 0;
- }
-
- public static decimal GetAmount(this PayItem payItem) => payItem.Quantity < 0 && payItem.Amount >= 0 ? payItem.Amount * (-1) : payItem.Amount;
-
- }
-}
diff --git a/queue/src/fiskaltrust.Middleware.Localization.QueueIT/Extensions/ReceiptRequestExtensions.cs b/queue/src/fiskaltrust.Middleware.Localization.QueueIT/Extensions/ReceiptRequestExtensions.cs
index 6c5f693a0..d825fd0b6 100644
--- a/queue/src/fiskaltrust.Middleware.Localization.QueueIT/Extensions/ReceiptRequestExtensions.cs
+++ b/queue/src/fiskaltrust.Middleware.Localization.QueueIT/Extensions/ReceiptRequestExtensions.cs
@@ -1,123 +1,23 @@
-using System;
-using System.Collections.Generic;
-using System.Diagnostics.CodeAnalysis;
-using System.Linq;
-using System.Net.Http.Headers;
-using fiskaltrust.ifPOS.v1;
-using fiskaltrust.ifPOS.v1.it;
-using fiskaltrust.Middleware.Localization.QueueIT.Exceptions;
+using fiskaltrust.ifPOS.v1;
namespace fiskaltrust.Middleware.Localization.QueueIT.Extensions
{
public static class ReceiptRequestExtensions
{
- public static bool IsMultiUseVoucherSale(this ReceiptRequest receiptRequest)
- {
- var hasChargeItemVoucher = receiptRequest?.cbChargeItems?.Any(x => x.IsMultiUseVoucherSale()) ?? false;
- var hasPayItemVoucher = receiptRequest?.cbPayItems?.Any(x => x.IsVoucherSale()) ?? false;
+ public static bool IsVoid(this ReceiptRequest receiptRequest) => (receiptRequest.ftReceiptCase & 0x0000_0000_000F_0000) == 0x0000_0000_0004_0000;
- if(hasChargeItemVoucher || hasPayItemVoucher)
- {
- if(receiptRequest?.cbChargeItems?.Any(x => !x.IsPaymentAdjustment() && !x.IsMultiUseVoucherSale()) ?? false)
- {
- throw new MultiUseVoucherNoSaleException();
- }
- return true;
- }
- return false;
- }
+ public static bool IsRefund(this ReceiptRequest receiptRequest) => (receiptRequest.ftReceiptCase & 0x0000_0000_0F00_0000) == 0x0000_0000_0100_0000;
- public static List GetPaymentAdjustments(this ReceiptRequest receiptRequest)
- {
- var paymentAdjustments = new List();
+ public static bool IsInitialOperation(this ReceiptRequest receiptRequest) => (receiptRequest.ftReceiptCase & 0x0000_0000_0000_FFFF) == 0x4001;
- if (receiptRequest.cbChargeItems != null)
- {
- foreach (var item in receiptRequest.cbChargeItems)
- {
- if (item.IsPaymentAdjustment() && !item.IsMultiUseVoucherRedeem())
- {
- paymentAdjustments.Add(new PaymentAdjustment
- {
- Amount = item.GetAmount(),
- Description = item.Description,
- VatGroup = item.GetVatGroup(),
- PaymentAdjustmentType = (PaymentAdjustmentType) item.GetPaymentAdjustmentType(),
- AdditionalInformation = item.ftChargeItemCaseData
- });
- }
- }
- }
- return paymentAdjustments;
- }
+ public static bool IsReceiptOperation(this ReceiptRequest receiptRequest) => (receiptRequest.ftReceiptCase & 0x0000_0000_0000_F000) == 0x0000;
- public static List GetPayments(this ReceiptRequest receiptRequest)
- {
- var sumChargeItems = receiptRequest.cbChargeItems?.Sum(x => x.GetAmount()) ?? 0;
- var sumPayItems = receiptRequest.cbPayItems?.Sum(x => x.GetAmount()) ?? 0;
+ public static bool IsInvoiceOperation(this ReceiptRequest receiptRequest) => (receiptRequest.ftReceiptCase & 0x0000_0000_0000_F000) == 0x1000;
- if ((sumPayItems - sumChargeItems) != 0)
- {
- throw new ItemPaymentInequalityException(sumPayItems, sumChargeItems);
- }
- var payment = receiptRequest.GetPaymentFullyRedeemedByVouchers();
+ public static bool IsDailyOperation(this ReceiptRequest receiptRequest) => (receiptRequest.ftReceiptCase & 0x0000_0000_0000_F000) == 0x2000;
- if (payment.Any())
- {
- return payment;
- }
- var payments = receiptRequest.cbPayItems?.Select(p => new Payment
- {
- Amount = p.Amount,
- Description = p.Description,
- PaymentType = p.GetPaymentType(),
- AdditionalInformation = p.ftPayItemCaseData
- }).ToList() ?? new List();
- var vouchersFromChargeItms = receiptRequest.cbChargeItems.Where(x => x.IsMultiUseVoucherRedeem()).Select(ch =>
- new Payment
- {
- Amount = Math.Abs(ch.Amount),
- Description = ch.Description,
- PaymentType = PaymentType.Voucher,
- AdditionalInformation = ch.ftChargeItemCaseData
- }).ToList();
- payments.AddRange(vouchersFromChargeItms);
- return payments;
- }
+ public static bool IsProtocolOperation(this ReceiptRequest receiptRequest) => (receiptRequest.ftReceiptCase & 0x0000_0000_0000_F000) == 0x3000;
- private static List GetPaymentFullyRedeemedByVouchers(this ReceiptRequest receiptRequest)
- {
- var sumChargeItemsNoVoucher = receiptRequest.cbChargeItems?.Where(x => !x.IsPaymentAdjustment()).Sum(x => x.GetAmount()) ?? 0;
-
- var payments = new List();
- if ((receiptRequest.cbPayItems != null && receiptRequest.cbPayItems.Any(x => x.IsVoucherRedeem())) ||
- (receiptRequest.cbChargeItems != null && receiptRequest.cbChargeItems.Any(x => x.IsMultiUseVoucherRedeem())))
- {
- var sumVoucher = receiptRequest.cbPayItems.Where(x => x.IsVoucherRedeem()).Sum(x => x.GetAmount()) +
- receiptRequest.cbChargeItems.Where(x => x.IsMultiUseVoucherRedeem()).Sum(x => Math.Abs(x.Amount));
- if (sumVoucher > sumChargeItemsNoVoucher)
- {
- var dscrPay = receiptRequest.cbPayItems.Where(x => x.IsVoucherRedeem()).Select(x => x.Description).ToList();
- var dscrCharge = receiptRequest.cbChargeItems.Where(x => x.IsMultiUseVoucherRedeem()).Select(x => x.Description).ToList();
- dscrPay.AddRange(dscrCharge);
-
- var addiPay = receiptRequest.cbPayItems.Where(x => x.IsVoucherRedeem()).Select(x => x.ftPayItemCaseData).ToList();
- var addiCharge = receiptRequest.cbChargeItems.Where(x => x.IsMultiUseVoucherRedeem()).Select(x => x.ftChargeItemCaseData).ToList();
- addiPay.AddRange(addiCharge);
-
- payments.Add(
- new Payment
- {
- Amount = sumChargeItemsNoVoucher,
- Description = string.Join(" ", dscrPay),
- PaymentType = PaymentType.Voucher,
- AdditionalInformation = string.Join(" ", addiPay),
- });
- };
- }
- return payments;
- }
-
+ public static bool IsLifeCycleOperation(this ReceiptRequest receiptRequest) => (receiptRequest.ftReceiptCase & 0x0000_0000_0000_F000) == 0x4000;
}
}
-
diff --git a/queue/src/fiskaltrust.Middleware.Localization.QueueIT/Extensions/ServiceCollectionExtensions.cs b/queue/src/fiskaltrust.Middleware.Localization.QueueIT/Extensions/ServiceCollectionExtensions.cs
deleted file mode 100644
index 879e2df78..000000000
--- a/queue/src/fiskaltrust.Middleware.Localization.QueueIT/Extensions/ServiceCollectionExtensions.cs
+++ /dev/null
@@ -1,20 +0,0 @@
-using fiskaltrust.Middleware.Localization.QueueIT.RequestCommands;
-using Microsoft.Extensions.DependencyInjection;
-
-namespace fiskaltrust.Middleware.Localization.QueueIT.Extensions
-{
- public static class ServiceCollectionExtensions
- {
- public static IServiceCollection ConfigureReceiptCommands(this IServiceCollection services)
- {
- services.AddSingleton();
- services.AddSingleton();
- services.AddSingleton();
- services.AddSingleton();
- services.AddSingleton();
- services.AddSingleton();
- services.AddSingleton();
- return services;
- }
- }
-}
diff --git a/queue/src/fiskaltrust.Middleware.Localization.QueueIT/Extensions/ftJournalITExtensions.cs b/queue/src/fiskaltrust.Middleware.Localization.QueueIT/Extensions/ftJournalITExtensions.cs
deleted file mode 100644
index 38e3b2fc7..000000000
--- a/queue/src/fiskaltrust.Middleware.Localization.QueueIT/Extensions/ftJournalITExtensions.cs
+++ /dev/null
@@ -1,32 +0,0 @@
-using System;
-using fiskaltrust.storage.V0;
-
-namespace fiskaltrust.Middleware.Localization.QueueIT.Extensions
-{
- public struct ScuResponse
- {
- public long ftReceiptCase { get; set; }
- public DateTime ReceiptDateTime { get; set; }
- public long ReceiptNumber { get; set; }
- public long ZRepNumber { get; set; }
- public string DataJson { get; set; }
- }
- public static class ftJournalITExtensions
- {
- public static ftJournalIT FromResponse(this ftJournalIT ftJournalIT, ICountrySpecificQueue queueIt, ftQueueItem queueItem, ScuResponse scuResponse)
- {
- ftJournalIT.ftJournalITId = Guid.NewGuid();
- ftJournalIT.ftQueueId = queueIt.ftQueueId;
- ftJournalIT.ftQueueItemId = queueItem.ftQueueItemId;
- ftJournalIT.cbReceiptReference = queueItem.cbReceiptReference;
- ftJournalIT.ftSignaturCreationUnitITId = queueIt.ftSignaturCreationUnitId.Value;
- ftJournalIT.JournalType = scuResponse.ftReceiptCase & 0xFFFF;
- ftJournalIT.ReceiptDateTime = scuResponse.ReceiptDateTime;
- ftJournalIT.ReceiptNumber = scuResponse.ReceiptNumber;
- ftJournalIT.ZRepNumber = scuResponse.ZRepNumber;
- ftJournalIT.DataJson = scuResponse.DataJson;
- ftJournalIT.TimeStamp = DateTime.UtcNow.Ticks;
- return ftJournalIT;
- }
- }
-}
diff --git a/queue/src/fiskaltrust.Middleware.Localization.QueueIT/Factories/SignaturItemFactory.cs b/queue/src/fiskaltrust.Middleware.Localization.QueueIT/Factories/SignaturItemFactory.cs
new file mode 100644
index 000000000..a6b35c9c3
--- /dev/null
+++ b/queue/src/fiskaltrust.Middleware.Localization.QueueIT/Factories/SignaturItemFactory.cs
@@ -0,0 +1,147 @@
+using System.Collections.Generic;
+using System.Text;
+using System;
+using fiskaltrust.ifPOS.v1;
+using fiskaltrust.ifPOS.v1.it;
+using fiskaltrust.Middleware.Localization.QueueIT.Helpers;
+using fiskaltrust.storage.V0;
+using fiskaltrust.Middleware.Localization.QueueIT.Constants;
+namespace fiskaltrust.Middleware.Localization.QueueIT.Factories
+{
+ public static class SignaturItemFactory
+ {
+ public static SignaturItem CreateInitialOperationSignature(ftQueueIT queueIT, RTInfo rtInfo)
+ {
+ return new SignaturItem()
+ {
+ ftSignatureType = Cases.BASE_STATE | 0x1_1001,
+ ftSignatureFormat = (long) SignaturItem.Formats.Text,
+ Caption = $"Initial-operation receipt",
+ Data = $"Queue-ID: {queueIT.ftQueueITId} Serial-Nr: {rtInfo.SerialNumber}"
+ };
+ }
+
+ public static SignaturItem CreateOutOfOperationSignature(ftQueueIT queueIT)
+ {
+ return new SignaturItem()
+ {
+ ftSignatureType = Cases.BASE_STATE | 0x1_1002,
+ ftSignatureFormat = (long) SignaturItem.Formats.Text,
+ Caption = $"Out-of-operation receipt",
+ Data = $"Queue-ID: {queueIT.ftQueueITId}"
+ };
+ }
+
+ public static List CreatePOSReceiptFormatSignatures(ReceiptResponse response)
+ {
+ return new List
+ {
+ new SignaturItem
+ {
+ Caption = "[www.fiskaltrust.it]",
+ Data = CreateFooter(response).ToString(),
+ ftSignatureFormat = (long) SignaturItem.Formats.Text,
+ ftSignatureType = Cases.BASE_STATE | (long) SignatureTypesIT.PosReceiptPrimarySignature
+ },
+ new SignaturItem
+ {
+ Caption = "DOCUMENTO COMMERCIALE",
+ Data = CreateHeader(response).ToString(),
+ ftSignatureFormat = (long) SignaturItem.Formats.Text,
+ ftSignatureType = Cases.BASE_STATE | (long) SignatureTypesIT.PosReceiptSecondarySignature
+ }
+ };
+ }
+
+ private static StringBuilder CreateFooter(ReceiptResponse receiptResponse)
+ {
+ var receiptNumber = long.Parse(receiptResponse.GetSignaturItem(SignatureTypesIT.RTDocumentNumber)?.Data);
+ var zRepNumber = long.Parse(receiptResponse.GetSignaturItem(SignatureTypesIT.RTZNumber)?.Data);
+ var rtDocumentMoment = DateTime.Parse(receiptResponse.GetSignaturItem(SignatureTypesIT.RTDocumentMoment)?.Data);
+ var codiceLotteria = receiptResponse.GetSignaturItem(SignatureTypesIT.RTLotteryID)?.Data;
+ var customerIdentification = receiptResponse.GetSignaturItem(SignatureTypesIT.RTCustomerID)?.Data;
+ var shaMetadata = receiptResponse.GetSignaturItem(SignatureTypesIT.RTServerShaMetadata)?.Data;
+ var rtServerSerialNumber = receiptResponse.GetSignaturItem(SignatureTypesIT.RTSerialNumber)?.Data;
+
+ var stringBuilder = new StringBuilder();
+ stringBuilder.AppendLine($"{rtDocumentMoment.ToString("dd-MM-yyyy HH:mm")}");
+ stringBuilder.AppendLine($"DOCUMENTO N. {zRepNumber.ToString().PadLeft(4, '0')}-{receiptNumber.ToString().PadLeft(4, '0')}");
+ if (!string.IsNullOrEmpty(codiceLotteria))
+ {
+ stringBuilder.AppendLine($"Codice Lotteria: {codiceLotteria}");
+ stringBuilder.AppendLine();
+ }
+ if (!string.IsNullOrEmpty(customerIdentification))
+ {
+ stringBuilder.AppendLine($"Codice Fiscale: {customerIdentification}");
+ }
+ if (!string.IsNullOrEmpty(shaMetadata))
+ {
+ stringBuilder.AppendLine($"Server RT {rtServerSerialNumber}");
+ }
+ stringBuilder.AppendLine($"Cassa {receiptResponse.ftCashBoxIdentification}");
+ if (!string.IsNullOrEmpty(shaMetadata))
+ {
+ stringBuilder.AppendLine($"-----FIRMA ELETTRONICA-----");
+ stringBuilder.AppendLine(shaMetadata);
+ stringBuilder.AppendLine("---------------------------");
+ }
+ return stringBuilder;
+ }
+
+ private static StringBuilder CreateHeader(ReceiptResponse receiptResponse, string referencedRT = null, string referencedPrinterRT = null)
+ {
+ var docType = receiptResponse.GetSignaturItem(SignatureTypesIT.RTDocumentType)?.Data;
+ if (docType.ToUpper() == "POSRECEIPT")
+ {
+ return new StringBuilder("di vendita o prestazione");
+ }
+
+ var referenceZNumberString = receiptResponse.GetSignaturItem(SignatureTypesIT.RTReferenceZNumber)?.Data;
+ var referenceDocNumberString = receiptResponse.GetSignaturItem(SignatureTypesIT.RTReferenceDocumentNumber)?.Data;
+ var referenceDateTimeString = receiptResponse.GetSignaturItem(SignatureTypesIT.RTReferenceDocumentMoment)?.Data;
+ var stringBuilder = new StringBuilder();
+ if (docType.ToUpper() == "REFUND")
+ {
+ stringBuilder.AppendLine("emesso per RESO MERCE");
+ if (string.IsNullOrEmpty(referenceZNumberString) || string.IsNullOrEmpty(referenceDocNumberString))
+ {
+ stringBuilder.AppendLine($"ND del {DateTime.Parse(referenceDateTimeString).ToString("dd-MM-yyyy")}");
+ }
+ else
+ {
+ stringBuilder.AppendLine($"N. {long.Parse(referenceZNumberString).ToString().PadLeft(4, '0')}-{long.Parse(referenceDocNumberString).ToString().PadLeft(4, '0')} del {DateTime.Parse(referenceDateTimeString).ToString("dd-MM-yyyy")}");
+ }
+ if (!string.IsNullOrEmpty(referencedRT))
+ {
+ stringBuilder.AppendLine($"Server RT {referencedRT}");
+ }
+ if (!string.IsNullOrEmpty(referencedPrinterRT))
+ {
+ stringBuilder.AppendLine($"RT {referencedRT}");
+ }
+ }
+ else if (docType.ToUpper() == "VOID")
+ {
+ stringBuilder.AppendLine("emesso per ANNULLAMENTO");
+ if (string.IsNullOrEmpty(referenceZNumberString) || string.IsNullOrEmpty(referenceDocNumberString))
+ {
+ stringBuilder.AppendLine($"ND del {DateTime.Parse(referenceDateTimeString).ToString("dd-MM-yyyy")}");
+ }
+ else
+ {
+ stringBuilder.AppendLine($"N. {long.Parse(referenceZNumberString).ToString().PadLeft(4, '0')}-{long.Parse(referenceDocNumberString).ToString().PadLeft(4, '0')} del {DateTime.Parse(referenceDateTimeString).ToString("dd-MM-yyyy")}");
+ }
+ if (!string.IsNullOrEmpty(referencedRT))
+ {
+ stringBuilder.AppendLine($"Server RT {referencedRT}");
+ }
+ if (!string.IsNullOrEmpty(referencedPrinterRT))
+ {
+ stringBuilder.AppendLine($"RT {referencedRT}");
+ }
+ }
+ return stringBuilder;
+ }
+ }
+}
diff --git a/queue/src/fiskaltrust.Middleware.Localization.QueueIT/Factories/SignatureItemFactoryIT.cs b/queue/src/fiskaltrust.Middleware.Localization.QueueIT/Factories/SignatureItemFactoryIT.cs
deleted file mode 100644
index 53f725f5c..000000000
--- a/queue/src/fiskaltrust.Middleware.Localization.QueueIT/Factories/SignatureItemFactoryIT.cs
+++ /dev/null
@@ -1,118 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Globalization;
-using fiskaltrust.ifPOS.v1;
-using fiskaltrust.ifPOS.v1.it;
-using fiskaltrust.Middleware.Contracts.Factories;
-
-
-namespace fiskaltrust.Middleware.Localization.QueueIT.Factories
-{
- public class SignatureItemFactoryIT : SignatureItemFactory
- {
- public override long CountryBaseState => 0x4954000000000000;
-
- public SignatureItemFactoryIT() {
- }
-
- protected static NumberFormatInfo CurrencyFormatter = new ()
- {
- NumberDecimalSeparator = ",",
- NumberGroupSeparator = "",
- CurrencyDecimalDigits = 2
- };
-
- public SignaturItem[] CreatePosReceiptSignatures(DailyClosingResponse dailyClosingResponse)
- {
- return new SignaturItem[]
- {
- new SignaturItem
- {
- Caption = "",
- Data = dailyClosingResponse.ZRepNumber.ToString(),
- ftSignatureFormat = (long) SignaturItem.Formats.Text,
- ftSignatureType = CountryBaseState & (long) SignatureTypesIT.ZNumber
- },
- new SignaturItem
- {
- Caption = "",
- Data = dailyClosingResponse.DailyAmount.ToString(CurrencyFormatter),
- ftSignatureFormat = (long) SignaturItem.Formats.Text,
- ftSignatureType = CountryBaseState & (long) SignatureTypesIT.ReceiptAmount
- }
- };
- }
-
- public SignaturItem[] CreateVoucherSignatures(NonFiscalRequest nonFiscalRequest)
- {
-
- var signs = new List();
- var cnt = nonFiscalRequest.NonFiscalPrints.Count;
- for (var i = 0; i < cnt; i ++ )
- {
- var dat = nonFiscalRequest.NonFiscalPrints[i].Data;
- if ( dat == "***Voucher***")
- {
- var dat2 = i + 1 < cnt ? nonFiscalRequest.NonFiscalPrints[i + 1].Data : null;
- var isAmount = decimal.TryParse(dat2, NumberStyles.Number, new CultureInfo("it-It", false), out var amnt);
- if (!isAmount)
- {
- dat2 = i + 2 < cnt ? nonFiscalRequest.NonFiscalPrints[i + 2].Data : null;
- isAmount = decimal.TryParse(dat2, NumberStyles.Number, new CultureInfo("it-It", false), out amnt);
- }
- if (isAmount)
- {
- signs.Add(new SignaturItem
- {
- Caption = "",
- Data = Math.Abs(amnt).ToString(new NumberFormatInfo
- {
- NumberDecimalSeparator = ",",
- NumberGroupSeparator = "",
- CurrencyDecimalDigits = 2
- }),
- ftSignatureFormat = (long) SignaturItem.Formats.Text,
- ftSignatureType = CountryBaseState & (long) SignatureTypesIT.ReceiptAmount
- });
- }
- }
- }
- return signs.ToArray();
- }
-
- public SignaturItem [] CreatePosReceiptSignatures(FiscalReceiptResponse fiscalReceiptResponse)
- {
- return new SignaturItem[]
- {
- new SignaturItem
- {
- Caption = "",
- Data = fiscalReceiptResponse.ReceiptNumber.ToString(),
- ftSignatureFormat = (long) SignaturItem.Formats.Text,
- ftSignatureType = CountryBaseState & (long) SignatureTypesIT.ReceiptNumber
- },
- new SignaturItem
- {
- Caption = "",
- Data = fiscalReceiptResponse.ZRepNumber.ToString(),
- ftSignatureFormat = (long) SignaturItem.Formats.Text,
- ftSignatureType = CountryBaseState & (long) SignatureTypesIT.ZNumber
- },
- new SignaturItem
- {
- Caption = "",
- Data = fiscalReceiptResponse.Amount.ToString(CurrencyFormatter),
- ftSignatureFormat = (long) SignaturItem.Formats.Text,
- ftSignatureType = CountryBaseState & (long) SignatureTypesIT.ReceiptAmount
- },
- new SignaturItem
- {
- Caption = "",
- Data = fiscalReceiptResponse.ReceiptDateTime.ToString("yyyy-MM-dd HH:mm:ss"),
- ftSignatureFormat = (long) SignaturItem.Formats.Text,
- ftSignatureType = CountryBaseState & (long) SignatureTypesIT.ReceiptTimestamp
- }
- };
- }
- }
-}
diff --git a/queue/src/fiskaltrust.Middleware.Localization.QueueIT/Factories/ftActionJournalFactory.cs b/queue/src/fiskaltrust.Middleware.Localization.QueueIT/Factories/ftActionJournalFactory.cs
new file mode 100644
index 000000000..7b1115752
--- /dev/null
+++ b/queue/src/fiskaltrust.Middleware.Localization.QueueIT/Factories/ftActionJournalFactory.cs
@@ -0,0 +1,88 @@
+using System;
+using fiskaltrust.ifPOS.v1;
+using fiskaltrust.Middleware.Contracts.Extensions;
+using fiskaltrust.storage.serialization.DE.V0;
+using fiskaltrust.storage.V0;
+using Newtonsoft.Json;
+
+namespace fiskaltrust.Middleware.Localization.QueueIT.Factories
+{
+ public static class ftActionJournalFactory
+
+ {
+ public static ftActionJournal CreateDailyClosingActionJournal(ftQueue queue, ftQueueItem queueItem, ReceiptRequest request)
+ {
+ var ftReceiptCaseHex = request.ftReceiptCase.ToString("X");
+ return CreateActionJournal(queue.ftQueueId, ftReceiptCaseHex, queueItem.ftQueueItemId, $"Daily-Closing receipt was processed.", JsonConvert.SerializeObject(new { ftReceiptNumerator = queue.ftReceiptNumerator + 1 }));
+ }
+
+ public static ftActionJournal CreateMonthlyClosingActionJournal(ftQueue queue, ftQueueItem queueItem, ReceiptRequest request)
+ {
+ var ftReceiptCaseHex = request.ftReceiptCase.ToString("X");
+ return CreateActionJournal(queue.ftQueueId, ftReceiptCaseHex, queueItem.ftQueueItemId, $"Monthly-Closing receipt was processed.", JsonConvert.SerializeObject(new { ftReceiptNumerator = queue.ftReceiptNumerator + 1 }));
+ }
+
+ public static ftActionJournal CreateInitialOperationActionJournal(ftQueue queue, ftQueueItem queueItem, ftQueueIT queueIT, ReceiptRequest request)
+ {
+ var notification = new ActivateQueueSCU
+ {
+ CashBoxId = Guid.Parse(request.ftCashBoxID),
+ QueueId = queueItem.ftQueueId,
+ Moment = DateTime.UtcNow,
+ SCUId = queueIT.ftSignaturCreationUnitITId.GetValueOrDefault(),
+ IsStartReceipt = true,
+ Version = "V0",
+ };
+ return CreateActionJournal(queue.ftQueueId, $"{request.ftReceiptCase:X}-{nameof(ActivateQueueSCU)}", queueItem.ftQueueItemId, $"Initial-Operation receipt. Queue-ID: {queue.ftQueueId}", JsonConvert.SerializeObject(notification));
+ }
+
+ public static ftActionJournal CreateWrongStateForInitialOperationActionJournal(ftQueue queue, ftQueueItem queueItem, ReceiptRequest request)
+ {
+ return CreateActionJournal(queue.ftQueueId, $"{request.ftReceiptCase:X}",
+ queueItem.ftQueueItemId, queue.IsDeactivated()
+ ? $"Queue {queue.ftQueueId} is de-activated, initial-operations-receipt can not be executed."
+ : $"Queue {queue.ftQueueId} is already activated, initial-operations-receipt can not be executed.", "");
+ }
+
+ public static ftActionJournal CreateOutOfOperationActionJournal(ftQueue queue, ftQueueItem queueItem, ftQueueIT queueIT, ReceiptRequest request)
+ {
+ var notification = new DeactivateQueueSCU
+ {
+ CashBoxId = Guid.Parse(request.ftCashBoxID),
+ QueueId = queueItem.ftQueueId,
+ Moment = DateTime.UtcNow,
+ SCUId = queueIT.ftSignaturCreationUnitITId.GetValueOrDefault(),
+ IsStopReceipt = true,
+ Version = "V0"
+ };
+ return CreateActionJournal(queue.ftQueueId, $"{request.ftReceiptCase:X}-{nameof(DeactivateQueueSCU)}", queueItem.ftQueueItemId, $"Out-of-Operation receipt. Queue-ID: {queue.ftQueueId}", JsonConvert.SerializeObject(notification));
+ }
+
+ public static ftActionJournal CreateAlreadyOutOfOperationActionJournal(ftQueue queue, ftQueueItem queueItem, ReceiptRequest request)
+ {
+ return CreateActionJournal(queue.ftQueueId, $"{request.ftReceiptCase:X}-Queue-already-deactivated",
+ queueItem.ftQueueItemId, $"Out-of-Operation receipt. Queue-ID: {queue.ftQueueId}", $"Queue was already deactivated on the {queue.StopMoment.Value.ToString("yyyy-MM-dd hh:mm:ss")}");
+ }
+
+ public static ftActionJournal CreateYearlyClosingClosingActionJournal(ftQueue queue, ftQueueItem queueItem, ReceiptRequest request)
+ {
+ var ftReceiptCaseHex = request.ftReceiptCase.ToString("X");
+ return CreateActionJournal(queue.ftQueueId, ftReceiptCaseHex, queueItem.ftQueueItemId, $"Yearly-Closing receipt was processed.", JsonConvert.SerializeObject(new { ftReceiptNumerator = queue.ftReceiptNumerator + 1 }));
+ }
+
+ private static ftActionJournal CreateActionJournal(Guid queueId, string type, Guid queueItemId, string message, string data, int priority = -1)
+ {
+ return new ftActionJournal
+ {
+ ftActionJournalId = Guid.NewGuid(),
+ ftQueueId = queueId,
+ ftQueueItemId = queueItemId,
+ Type = type,
+ Moment = DateTime.UtcNow,
+ Message = message,
+ Priority = priority,
+ DataJson = data
+ };
+ }
+ }
+}
diff --git a/queue/src/fiskaltrust.Middleware.Localization.QueueIT/Factories/ftJournalITFactory.cs b/queue/src/fiskaltrust.Middleware.Localization.QueueIT/Factories/ftJournalITFactory.cs
new file mode 100644
index 000000000..2c3c61d9a
--- /dev/null
+++ b/queue/src/fiskaltrust.Middleware.Localization.QueueIT/Factories/ftJournalITFactory.cs
@@ -0,0 +1,28 @@
+using System;
+using fiskaltrust.Middleware.Localization.QueueIT.Models;
+using fiskaltrust.storage.V0;
+
+namespace fiskaltrust.Middleware.Localization.QueueIT.Factories
+{
+ public static class ftJournalITFactory
+ {
+ public static ftJournalIT CreateFrom(ftQueueItem queueItem, ftQueueIT queueIT, ScuResponse scuResponse)
+ {
+ var ftJournalIT = new ftJournalIT
+ {
+ ftJournalITId = Guid.NewGuid(),
+ ftQueueId = queueIT.ftQueueId,
+ ftQueueItemId = queueItem.ftQueueItemId,
+ cbReceiptReference = queueItem.cbReceiptReference,
+ ftSignaturCreationUnitITId = queueIT.ftSignaturCreationUnitId.Value,
+ JournalType = scuResponse.ftReceiptCase & 0xFFFF,
+ ReceiptDateTime = scuResponse.ReceiptDateTime,
+ ReceiptNumber = scuResponse.ReceiptNumber,
+ ZRepNumber = scuResponse.ZRepNumber,
+ DataJson = scuResponse.DataJson,
+ TimeStamp = DateTime.UtcNow.Ticks
+ };
+ return ftJournalIT;
+ }
+ }
+}
diff --git a/queue/src/fiskaltrust.Middleware.Localization.QueueIT/Helpers/IsExternalInit.cs b/queue/src/fiskaltrust.Middleware.Localization.QueueIT/Helpers/IsExternalInit.cs
new file mode 100644
index 000000000..be6567575
--- /dev/null
+++ b/queue/src/fiskaltrust.Middleware.Localization.QueueIT/Helpers/IsExternalInit.cs
@@ -0,0 +1,15 @@
+using System.ComponentModel;
+
+namespace System.Runtime.CompilerServices
+{
+ ///
+ /// Reserved to be used by the compiler for tracking metadata.
+ /// This class should not be used by developers in source code.
+ /// This dummy class is required to compile records when targeting .NET Standard
+ /// https://developercommunity.visualstudio.com/t/error-cs0518-predefined-type-systemruntimecompiler/1244809
+ ///
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public static class IsExternalInit
+ {
+ }
+}
\ No newline at end of file
diff --git a/queue/src/fiskaltrust.Middleware.Localization.QueueIT/Helpers/ReceiptResponseHelper.cs b/queue/src/fiskaltrust.Middleware.Localization.QueueIT/Helpers/ReceiptResponseHelper.cs
new file mode 100644
index 000000000..d4f6bc7ca
--- /dev/null
+++ b/queue/src/fiskaltrust.Middleware.Localization.QueueIT/Helpers/ReceiptResponseHelper.cs
@@ -0,0 +1,41 @@
+using System.Collections.Generic;
+using System.Linq;
+using fiskaltrust.ifPOS.v1;
+using fiskaltrust.Middleware.Localization.QueueIT.Constants;
+
+namespace fiskaltrust.Middleware.Localization.QueueIT.Helpers
+{
+ public static class ReceiptResponseHelper
+ {
+ public static void SetReceiptResponseError(this ReceiptResponse receiptResponse, string errorMessage)
+ {
+ receiptResponse.ftState |= 0xEEEE_EEEE;
+ receiptResponse.ftSignatures = new List().ToArray();
+ receiptResponse.AddSignatureItem(new SignaturItem
+ {
+ Caption = "FAILURE",
+ Data = errorMessage,
+ ftSignatureFormat = (long) SignaturItem.Formats.Text,
+ ftSignatureType = 0x4954_2000_0000_3000
+ });
+ }
+
+ public static void InsertSignatureItems(this ReceiptResponse receiptResponse, List signaturItems)
+ {
+ var data = receiptResponse.ftSignatures.ToList();
+ data.InsertRange(0, signaturItems);
+ receiptResponse.ftSignatures = data.ToArray();
+ }
+
+ public static void AddSignatureItem(this ReceiptResponse receiptResponse, SignaturItem signaturItem)
+ {
+ var data = receiptResponse.ftSignatures.ToList();
+ data.Add(signaturItem);
+ receiptResponse.ftSignatures = data.ToArray();
+ }
+
+ public static bool HasFailed(this ReceiptResponse receiptRespons) => (receiptRespons.ftState & 0xFFFF_FFFF) == 0xEEEE_EEEE;
+
+ public static SignaturItem GetSignaturItem(this ReceiptResponse receiptResponse, SignatureTypesIT signatureTypesIT) => receiptResponse.ftSignatures.FirstOrDefault(x => (x.ftSignatureType & 0xFF) == (long) signatureTypesIT);
+ }
+}
diff --git a/queue/src/fiskaltrust.Middleware.Localization.QueueIT/IITSSCDProvider.cs b/queue/src/fiskaltrust.Middleware.Localization.QueueIT/IITSSCDProvider.cs
new file mode 100644
index 000000000..39b287494
--- /dev/null
+++ b/queue/src/fiskaltrust.Middleware.Localization.QueueIT/IITSSCDProvider.cs
@@ -0,0 +1,12 @@
+using System.Threading.Tasks;
+using fiskaltrust.ifPOS.v1.it;
+
+namespace fiskaltrust.Middleware.Localization.QueueIT
+{
+ public interface IITSSCDProvider
+ {
+ Task ProcessReceiptAsync(ProcessRequest request);
+
+ Task GetRTInfoAsync();
+ }
+}
diff --git a/queue/src/fiskaltrust.Middleware.Localization.QueueIT/IReceiptTypeProcessor.cs b/queue/src/fiskaltrust.Middleware.Localization.QueueIT/IReceiptTypeProcessor.cs
new file mode 100644
index 000000000..d8c2c31d5
--- /dev/null
+++ b/queue/src/fiskaltrust.Middleware.Localization.QueueIT/IReceiptTypeProcessor.cs
@@ -0,0 +1,15 @@
+using System.Collections.Generic;
+using System.Threading.Tasks;
+using fiskaltrust.ifPOS.v1;
+using fiskaltrust.Middleware.Localization.QueueIT.v2;
+using fiskaltrust.storage.V0;
+
+namespace fiskaltrust.Middleware.Localization.QueueIT
+{
+ public interface IReceiptTypeProcessor
+ {
+ public ReceiptCases ReceiptCase { get; }
+
+ Task<(ReceiptResponse receiptResponse, List actionJournals)> ExecuteAsync(ftQueue queue, ftQueueIT queueIt, ReceiptRequest request, ReceiptResponse receiptResponse, ftQueueItem queueItem);
+ }
+}
diff --git a/queue/src/fiskaltrust.Middleware.Localization.QueueIT/ITSSCDProvider.cs b/queue/src/fiskaltrust.Middleware.Localization.QueueIT/ITSSCDProvider.cs
new file mode 100644
index 000000000..c9aa9388b
--- /dev/null
+++ b/queue/src/fiskaltrust.Middleware.Localization.QueueIT/ITSSCDProvider.cs
@@ -0,0 +1,128 @@
+using System;
+using System.Linq;
+using System.Threading;
+using System.Threading.Tasks;
+using fiskaltrust.ifPOS.v1.it;
+using fiskaltrust.Middleware.Abstractions;
+using fiskaltrust.Middleware.Contracts.Models;
+using fiskaltrust.storage.V0;
+using Microsoft.Extensions.Logging;
+using Newtonsoft.Json;
+
+namespace fiskaltrust.Middleware.Localization.QueueIT
+{
+ public class ITSSCDProvider : IITSSCDProvider
+ {
+ private readonly ILogger _logger;
+ private readonly IClientFactory _clientFactory;
+ private readonly IConfigurationRepository _configurationRepository;
+ private readonly MiddlewareConfiguration _middlewareConfiguration;
+ private readonly QueueITConfiguration _queueConfiguration;
+
+ private readonly SemaphoreSlim _semaphoreInstance = new SemaphoreSlim(1, 1);
+ private readonly SemaphoreSlim _semaphoreRegister = new SemaphoreSlim(1, 1);
+
+ private IITSSCD _instance;
+
+ public IITSSCD Instance
+ {
+ get
+ {
+ try
+ {
+ _semaphoreInstance.Wait();
+ if (_instance == null)
+ {
+ RegisterCurrentScuAsync().Wait();
+ }
+ return _instance;
+ }
+ finally
+ {
+ _semaphoreInstance.Release();
+ }
+ }
+ }
+
+ public ITSSCDProvider(ILogger logger, IClientFactory clientFactory, IConfigurationRepository configurationRepository, MiddlewareConfiguration middlewareConfiguration, QueueITConfiguration queueConfiguration)
+ {
+ _logger = logger;
+ _clientFactory = clientFactory;
+ _configurationRepository = configurationRepository;
+ _middlewareConfiguration = middlewareConfiguration;
+ _queueConfiguration = queueConfiguration;
+ }
+
+ public async Task RegisterCurrentScuAsync()
+ {
+ try
+ {
+ await _semaphoreRegister.WaitAsync().ConfigureAwait(false);
+ var queueIT = await _configurationRepository.GetQueueITAsync(_middlewareConfiguration.QueueId).ConfigureAwait(false);
+
+ if (!queueIT.ftSignaturCreationUnitITId.HasValue)
+ {
+ _instance = null;
+ return;
+ }
+
+ var signaturCreationUnitIT = await _configurationRepository.GetSignaturCreationUnitITAsync(queueIT.ftSignaturCreationUnitITId.Value).ConfigureAwait(false);
+ var uri = GetUriForSignaturCreationUnit(signaturCreationUnitIT);
+ var config = new ClientConfiguration
+ {
+ Url = uri.ToString(),
+ UrlType = uri.Scheme
+ };
+
+ if (_queueConfiguration.ScuTimeoutMs.HasValue)
+ {
+ config.Timeout = TimeSpan.FromMilliseconds(_queueConfiguration.ScuTimeoutMs.Value);
+ }
+ if (_queueConfiguration.ScuMaxRetries.HasValue)
+ {
+ config.RetryCount = _queueConfiguration.ScuMaxRetries.Value;
+ }
+
+ _instance = _clientFactory.CreateClient(config);
+ try
+ {
+ var tseInfo = await _instance.GetRTInfoAsync().ConfigureAwait(false);
+ signaturCreationUnitIT.InfoJson = JsonConvert.SerializeObject(tseInfo);
+ await _configurationRepository.InsertOrUpdateSignaturCreationUnitITAsync(signaturCreationUnitIT).ConfigureAwait(false);
+ }
+ catch (Exception ex)
+ {
+ _logger.LogWarning(ex, "Failed to updated status of SCU (Url: {ScuUrl}, Id: {ScuId}). Will try again later...", config.Url, queueIT.ftSignaturCreationUnitITId.Value);
+ }
+ }
+ finally
+ {
+ _semaphoreRegister.Release();
+ }
+ }
+
+ public async Task ProcessReceiptAsync(ProcessRequest request)
+ {
+ return await Instance.ProcessReceiptAsync(request);
+ }
+
+
+ public async Task GetRTInfoAsync()
+ {
+ return await Instance.GetRTInfoAsync();
+ }
+
+ private static Uri GetUriForSignaturCreationUnit(ftSignaturCreationUnitIT signaturCreationUnit)
+ {
+ var url = signaturCreationUnit.Url;
+ try
+ {
+ var urls = JsonConvert.DeserializeObject(url);
+ var grpcUrl = urls.FirstOrDefault(x => x.StartsWith("grpc://"));
+ url = grpcUrl ?? urls.First();
+ }
+ catch { }
+ return new Uri(url);
+ }
+ }
+}
diff --git a/queue/src/fiskaltrust.Middleware.Localization.QueueIT/JournalProcessorIT.cs b/queue/src/fiskaltrust.Middleware.Localization.QueueIT/JournalProcessorIT.cs
index 8ceb0ee1f..073a6d908 100644
--- a/queue/src/fiskaltrust.Middleware.Localization.QueueIT/JournalProcessorIT.cs
+++ b/queue/src/fiskaltrust.Middleware.Localization.QueueIT/JournalProcessorIT.cs
@@ -8,14 +8,6 @@ namespace fiskaltrust.Middleware.Localization.QueueIT
{
public class JournalProcessorIT : IMarketSpecificJournalProcessor
{
- private readonly ILogger _logger;
-
- public JournalProcessorIT(
- ILogger logger)
- {
- _logger = logger;
- }
-
public IAsyncEnumerable ProcessAsync(JournalRequest request)
{
throw new NotImplementedException();
diff --git a/queue/src/fiskaltrust.Middleware.Localization.QueueIT/Models/ScuResponse.cs b/queue/src/fiskaltrust.Middleware.Localization.QueueIT/Models/ScuResponse.cs
new file mode 100644
index 000000000..c59d4cefc
--- /dev/null
+++ b/queue/src/fiskaltrust.Middleware.Localization.QueueIT/Models/ScuResponse.cs
@@ -0,0 +1,13 @@
+using System;
+
+namespace fiskaltrust.Middleware.Localization.QueueIT.Models
+{
+ public struct ScuResponse
+ {
+ public long ftReceiptCase { get; set; }
+ public DateTime ReceiptDateTime { get; set; }
+ public long ReceiptNumber { get; set; }
+ public long ZRepNumber { get; set; }
+ public string DataJson { get; set; }
+ }
+}
diff --git a/queue/src/fiskaltrust.Middleware.Localization.QueueIT/QueueITBootstrapper.cs b/queue/src/fiskaltrust.Middleware.Localization.QueueIT/QueueITBootstrapper.cs
index a93ed4bbb..b858bcae7 100644
--- a/queue/src/fiskaltrust.Middleware.Localization.QueueIT/QueueITBootstrapper.cs
+++ b/queue/src/fiskaltrust.Middleware.Localization.QueueIT/QueueITBootstrapper.cs
@@ -1,16 +1,7 @@
-using fiskaltrust.ifPOS.v1.it;
-using fiskaltrust.Middleware.Abstractions;
-using fiskaltrust.Middleware.Contracts.Constants;
-using fiskaltrust.Middleware.Contracts.Interfaces;
+using fiskaltrust.Middleware.Contracts.Interfaces;
using fiskaltrust.Middleware.Contracts.Models;
-using fiskaltrust.Middleware.Contracts.Repositories;
-using fiskaltrust.Middleware.Contracts.RequestCommands.Factories;
-using fiskaltrust.Middleware.Localization.QueueIT.Constants;
-using fiskaltrust.Middleware.Localization.QueueIT.Extensions;
-using fiskaltrust.Middleware.Localization.QueueIT.Factories;
-using fiskaltrust.Middleware.Localization.QueueIT.Repositories;
-using fiskaltrust.Middleware.Localization.QueueIT.RequestCommands.Factories;
-using fiskaltrust.Middleware.Localization.QueueIT.Services;
+using fiskaltrust.Middleware.Localization.QueueIT.v2;
+using fiskaltrust.storage.V0;
using Microsoft.Extensions.DependencyInjection;
namespace fiskaltrust.Middleware.Localization.QueueIT
@@ -20,23 +11,16 @@ public class QueueITBootstrapper : ILocalizedQueueBootstrapper
public void ConfigureServices(IServiceCollection services)
{
var _ = services
- .AddScoped()
- .AddScoped()
+ .AddScoped()
+ .AddScoped(x => new SignProcessor(x.GetRequiredService(), x.GetRequiredService()))
.AddScoped()
- .AddScoped()
- .AddScoped()
- .AddScoped()
+ .AddScoped()
+ .AddScoped()
+ .AddScoped()
+ .AddScoped()
+ .AddScoped()
.AddSingleton(sp => QueueITConfiguration.FromMiddlewareConfiguration(sp.GetRequiredService()))
- .AddSingleton(sp =>
- {
- var sscdProvider = new ITSSCDProvider(
- sp.GetRequiredService>(),
- sp.GetRequiredService());
- sscdProvider.RegisterCurrentScuAsync().Wait();
- return sscdProvider;
- })
- .AddSingleton()
- .ConfigureReceiptCommands();
+ .AddSingleton();
}
}
}
diff --git a/queue/src/fiskaltrust.Middleware.Localization.QueueIT/QueueITConfiguration.cs b/queue/src/fiskaltrust.Middleware.Localization.QueueIT/QueueITConfiguration.cs
index ad0c8fa31..2797ecc29 100644
--- a/queue/src/fiskaltrust.Middleware.Localization.QueueIT/QueueITConfiguration.cs
+++ b/queue/src/fiskaltrust.Middleware.Localization.QueueIT/QueueITConfiguration.cs
@@ -6,6 +6,16 @@ namespace fiskaltrust.Middleware.Localization.QueueIT
public class QueueITConfiguration
{
public bool Sandbox { get; set; } = false;
+
+
+ [JsonProperty("scu-timeout-ms")]
+ public long? ScuTimeoutMs { get; set; }
+
+ [JsonProperty("scu-max-retries")]
+ public int? ScuMaxRetries { get; set; } = 1;
+ // SKE => currently we don't perform any retries, we'll have to think about how we can handle this differently in the future, probably letting one of either component decide
+ // also this thing has to be 1 since we are considering the first try also as retry.
+
public static QueueITConfiguration FromMiddlewareConfiguration(MiddlewareConfiguration middlewareConfiguration) => JsonConvert.DeserializeObject(JsonConvert.SerializeObject(middlewareConfiguration.Configuration));
}
}
\ No newline at end of file
diff --git a/queue/src/fiskaltrust.Middleware.Localization.QueueIT/Repositories/CountrySpecificQueueRepository.cs b/queue/src/fiskaltrust.Middleware.Localization.QueueIT/Repositories/CountrySpecificQueueRepository.cs
deleted file mode 100644
index 441b9ad67..000000000
--- a/queue/src/fiskaltrust.Middleware.Localization.QueueIT/Repositories/CountrySpecificQueueRepository.cs
+++ /dev/null
@@ -1,20 +0,0 @@
-using System;
-using System.Threading.Tasks;
-using fiskaltrust.Middleware.Contracts.Repositories;
-using fiskaltrust.storage.V0;
-
-namespace fiskaltrust.Middleware.Localization.QueueIT.Repositories
-{
- public class CountrySpecificQueueRepository : ICountrySpecificQueueRepository
- {
- private readonly IConfigurationRepository _configurationRepository;
-
- public CountrySpecificQueueRepository(IConfigurationRepository configurationRepository)
- {
- _configurationRepository = configurationRepository;
- }
-
- public async Task GetQueueAsync(Guid queueId) => await _configurationRepository.GetQueueITAsync(queueId).ConfigureAwait(false);
- public async Task InsertOrUpdateQueueAsync(ICountrySpecificQueue queue) => await _configurationRepository.InsertOrUpdateQueueITAsync((ftQueueIT) queue).ConfigureAwait(false);
- }
-}
diff --git a/queue/src/fiskaltrust.Middleware.Localization.QueueIT/RequestCommands/DailyClosingReceiptCommand.cs b/queue/src/fiskaltrust.Middleware.Localization.QueueIT/RequestCommands/DailyClosingReceiptCommand.cs
deleted file mode 100644
index 20f041fa8..000000000
--- a/queue/src/fiskaltrust.Middleware.Localization.QueueIT/RequestCommands/DailyClosingReceiptCommand.cs
+++ /dev/null
@@ -1,81 +0,0 @@
-using System;
-using System.Threading.Tasks;
-using fiskaltrust.ifPOS.v1;
-using fiskaltrust.ifPOS.v1.errors;
-using fiskaltrust.ifPOS.v1.it;
-using fiskaltrust.Middleware.Contracts.Constants;
-using fiskaltrust.Middleware.Contracts.Interfaces;
-using fiskaltrust.Middleware.Contracts.Repositories;
-using fiskaltrust.Middleware.Contracts.RequestCommands;
-using fiskaltrust.Middleware.Localization.QueueIT.Extensions;
-using fiskaltrust.Middleware.Localization.QueueIT.Factories;
-using fiskaltrust.Middleware.Localization.QueueIT.Services;
-using fiskaltrust.storage.V0;
-using Microsoft.Extensions.Logging;
-
-namespace fiskaltrust.Middleware.Localization.QueueIT.RequestCommands
-{
- public class DailyClosingReceiptCommand : Contracts.RequestCommands.DailyClosingReceiptCommand
- {
- private readonly long _countryBaseState;
- protected override long CountryBaseState => _countryBaseState;
- private readonly ICountrySpecificSettings _countryspecificSettings;
- private readonly ICountrySpecificQueueRepository _countrySpecificQueueRepository;
- private readonly SignatureItemFactoryIT _signatureItemFactoryIT;
- private readonly IMiddlewareJournalITRepository _journalITRepository;
- private readonly IITSSCD _client;
- private readonly ISSCD _signingDevice;
- private readonly ILogger _logger;
-
- public DailyClosingReceiptCommand(ISSCD signingDevice, ILogger logger, SignatureItemFactoryIT signatureItemFactoryIT, ICountrySpecificSettings countrySpecificSettings, IITSSCDProvider itIsscdProvider, IMiddlewareJournalITRepository journalITRepository)
- {
- _countrySpecificQueueRepository = countrySpecificSettings.CountrySpecificQueueRepository;
- _client = itIsscdProvider.Instance;
- _journalITRepository = journalITRepository;
- _signatureItemFactoryIT = signatureItemFactoryIT;
- _countryspecificSettings = countrySpecificSettings;
- _countryBaseState = countrySpecificSettings.CountryBaseState;
- _signingDevice = signingDevice;
- _logger = logger;
- }
-
- protected override async Task GetCashboxIdentificationAsync(Guid ftQueueId)
- {
- var queueIt = await _countrySpecificQueueRepository.GetQueueAsync(ftQueueId).ConfigureAwait(false);
- return queueIt.CashBoxIdentification;
- }
-
- public override Task ReceiptNeedsReprocessing(ftQueue queue, ReceiptRequest request, ftQueueItem queueItem) => Task.FromResult(false);
-
- protected override async Task SpecializeAsync(RequestCommandResponse requestCommandResponse, ftQueue queue, ReceiptRequest request, ftQueueItem queueItem)
- {
- var response = await _client.ExecuteDailyClosingAsync(new DailyClosingRequest() ).ConfigureAwait(false);
-
- if (!response.Success)
- {
- if (response.SSCDErrorInfo.Type == SSCDErrorType.Connection)
- {
- return await ProcessFailedReceiptRequest(_signingDevice, _logger, _countryspecificSettings, queue, queueItem, request).ConfigureAwait(false);
- }
- else
- {
- throw new SSCDErrorException(response.SSCDErrorInfo.Type, response.SSCDErrorInfo.Info);
- }
- }
- else
- {
- requestCommandResponse.ReceiptResponse.ftReceiptIdentification += $"Z{response.ZRepNumber}";
- requestCommandResponse.ReceiptResponse.ftSignatures = _signatureItemFactoryIT.CreatePosReceiptSignatures(response);
- var queueIt = await _countrySpecificQueueRepository.GetQueueAsync(queue.ftQueueId).ConfigureAwait(false);
- var journalIT = new ftJournalIT().FromResponse(queueIt, queueItem, new ScuResponse()
- {
- DataJson = response.ReportDataJson,
- ftReceiptCase = request.ftReceiptCase,
- ZRepNumber = response.ZRepNumber
- });
- await _journalITRepository.InsertAsync(journalIT).ConfigureAwait(false);
- return requestCommandResponse;
- }
- }
- }
-}
diff --git a/queue/src/fiskaltrust.Middleware.Localization.QueueIT/RequestCommands/Factories/RequestCommandFactory.cs b/queue/src/fiskaltrust.Middleware.Localization.QueueIT/RequestCommands/Factories/RequestCommandFactory.cs
deleted file mode 100644
index 1d7b82c6b..000000000
--- a/queue/src/fiskaltrust.Middleware.Localization.QueueIT/RequestCommands/Factories/RequestCommandFactory.cs
+++ /dev/null
@@ -1,34 +0,0 @@
-using System;
-using fiskaltrust.ifPOS.v1;
-using fiskaltrust.Middleware.Contracts.Exceptions;
-using fiskaltrust.Middleware.Contracts.RequestCommands;
-using fiskaltrust.Middleware.Contracts.RequestCommands.Factories;
-using Microsoft.Extensions.DependencyInjection;
-
-namespace fiskaltrust.Middleware.Localization.QueueIT.RequestCommands.Factories
-{
- public class RequestCommandFactory : IRequestCommandFactory
- {
- private readonly IServiceProvider _serviceProvider;
-
- public RequestCommandFactory(IServiceProvider serviceCollection) => _serviceProvider = serviceCollection;
-
- public RequestCommand Create(ReceiptRequest request)
- {
- RequestCommand command = (request.ftReceiptCase & 0xFFFF) switch
- {
- 0x0000 => _serviceProvider.GetService(),
- 0x0001 => _serviceProvider.GetService(),
- 0x0003 => _serviceProvider.GetService(),
- 0x0004 => _serviceProvider.GetService(),
- 0x0007 => _serviceProvider.GetService(),
- 0x0005 => _serviceProvider.GetService(),
- 0x0006 => _serviceProvider.GetService(),
- 0x0002 => _serviceProvider.GetService(),
- _ => throw new UnknownReceiptCaseException(request.ftReceiptCase)
- };
-
- return command;
- }
- }
-}
\ No newline at end of file
diff --git a/queue/src/fiskaltrust.Middleware.Localization.QueueIT/RequestCommands/InitialOperationReceiptCommand.cs b/queue/src/fiskaltrust.Middleware.Localization.QueueIT/RequestCommands/InitialOperationReceiptCommand.cs
deleted file mode 100644
index 00077bf0a..000000000
--- a/queue/src/fiskaltrust.Middleware.Localization.QueueIT/RequestCommands/InitialOperationReceiptCommand.cs
+++ /dev/null
@@ -1,61 +0,0 @@
-using System;
-using System.Threading.Tasks;
-using fiskaltrust.storage.V0;
-using Microsoft.Extensions.Logging;
-using Newtonsoft.Json;
-using fiskaltrust.ifPOS.v1;
-using fiskaltrust.storage.serialization.DE.V0;
-using fiskaltrust.Middleware.Localization.QueueIT.Factories;
-using fiskaltrust.Middleware.Localization.QueueIT.Services;
-using fiskaltrust.ifPOS.v1.it;
-using fiskaltrust.Middleware.Contracts.Repositories;
-using fiskaltrust.Middleware.Contracts.Constants;
-
-namespace fiskaltrust.Middleware.Localization.QueueIT.RequestCommands
-{
- public class InitialOperationReceiptCommand : Contracts.RequestCommands.InitialOperationReceiptCommand
- {
- private readonly ICountrySpecificQueueRepository _countrySpecificQueueRepository;
-
- private readonly IConfigurationRepository _configurationRepository;
- private readonly SignatureItemFactoryIT _signatureItemFactoryIT;
- private readonly IITSSCD _client;
-
- public InitialOperationReceiptCommand(ICountrySpecificSettings countrySpecificQueueSettings, IITSSCDProvider itIsscdProvider, ILogger logger, IConfigurationRepository configurationRepository, SignatureItemFactoryIT signatureItemFactoryIT) : base(countrySpecificQueueSettings, logger, configurationRepository)
- {
- _client = itIsscdProvider.Instance;
- _configurationRepository = configurationRepository;
- _signatureItemFactoryIT = signatureItemFactoryIT;
- _countrySpecificQueueRepository = countrySpecificQueueSettings.CountrySpecificQueueRepository;
-
- }
-
- protected override async Task<(ftActionJournal, SignaturItem)> InitializeSCUAsync(ftQueue queue, ReceiptRequest request, ftQueueItem queueItem)
- {
- var queueIt = await _configurationRepository.GetQueueITAsync(queue.ftQueueId);
- var scu = await _configurationRepository.GetSignaturCreationUnitITAsync(queueIt.ftSignaturCreationUnitITId.Value).ConfigureAwait(false);
- var deviceInfo = await _client.GetDeviceInfoAsync().ConfigureAwait(false);
- if (string.IsNullOrEmpty(scu.InfoJson ))
- {
- scu.InfoJson = JsonConvert.SerializeObject(deviceInfo);
- await _configurationRepository.InsertOrUpdateSignaturCreationUnitITAsync(scu).ConfigureAwait(false);
- }
- var signatureItem = _signatureItemFactoryIT.CreateInitialOperationSignature($"Queue-ID: {queue.ftQueueId} Serial-Nr: {deviceInfo.SerialNumber}");
- var notification = new ActivateQueueSCU
- {
- CashBoxId = Guid.Parse(request.ftCashBoxID),
- QueueId = queueItem.ftQueueId,
- Moment = DateTime.UtcNow,
- SCUId = queueIt.ftSignaturCreationUnitITId.GetValueOrDefault(),
- IsStartReceipt = true,
- Version = "V0",
- };
- var actionJournal = CreateActionJournal(queue.ftQueueId, $"{request.ftReceiptCase:X}-{nameof(ActivateQueueSCU)}",
- queueItem.ftQueueItemId, $"Initial-Operation receipt. Queue-ID: {queue.ftQueueId}", JsonConvert.SerializeObject(notification));
-
- return (actionJournal, signatureItem);
- }
-
- public override Task ReceiptNeedsReprocessing(ftQueue queue, ReceiptRequest request, ftQueueItem queueItem) => Task.FromResult(false);
- }
-}
diff --git a/queue/src/fiskaltrust.Middleware.Localization.QueueIT/RequestCommands/MonthlyClosingReceiptCommand.cs b/queue/src/fiskaltrust.Middleware.Localization.QueueIT/RequestCommands/MonthlyClosingReceiptCommand.cs
deleted file mode 100644
index e991df28f..000000000
--- a/queue/src/fiskaltrust.Middleware.Localization.QueueIT/RequestCommands/MonthlyClosingReceiptCommand.cs
+++ /dev/null
@@ -1,31 +0,0 @@
-using System.Threading.Tasks;
-using System;
-using fiskaltrust.storage.V0;
-using fiskaltrust.ifPOS.v1;
-using fiskaltrust.Middleware.Contracts.Repositories;
-using fiskaltrust.Middleware.Contracts.Constants;
-
-namespace fiskaltrust.Middleware.Localization.QueueIT.RequestCommands
-{
- public class MonthlyClosingReceiptCommand : Contracts.RequestCommands.MonthlyClosingReceiptCommand
- {
- private readonly ICountrySpecificQueueRepository _countrySpecificQueueRepository;
-
- private readonly long _countryBaseState;
- protected override long CountryBaseState => _countryBaseState;
-
- public MonthlyClosingReceiptCommand(ICountrySpecificSettings countrySpecificSettings)
- {
- _countrySpecificQueueRepository = countrySpecificSettings.CountrySpecificQueueRepository;
- _countryBaseState = countrySpecificSettings.CountryBaseState;
- }
-
- protected override async Task GetCashboxIdentificationAsync(Guid ftQueueId)
- {
- var queueIt = await _countrySpecificQueueRepository.GetQueueAsync(ftQueueId).ConfigureAwait(false);
- return queueIt.CashBoxIdentification;
- }
-
- public override Task ReceiptNeedsReprocessing(ftQueue queue, ReceiptRequest request, ftQueueItem queueItem) => Task.FromResult(false);
- }
-}
diff --git a/queue/src/fiskaltrust.Middleware.Localization.QueueIT/RequestCommands/OutOfOperationReceiptCommand.cs b/queue/src/fiskaltrust.Middleware.Localization.QueueIT/RequestCommands/OutOfOperationReceiptCommand.cs
deleted file mode 100644
index ae0df2fa4..000000000
--- a/queue/src/fiskaltrust.Middleware.Localization.QueueIT/RequestCommands/OutOfOperationReceiptCommand.cs
+++ /dev/null
@@ -1,56 +0,0 @@
-using System;
-using System.Threading.Tasks;
-using fiskaltrust.storage.V0;
-using fiskaltrust.ifPOS.v1;
-using fiskaltrust.storage.serialization.DE.V0;
-using Newtonsoft.Json;
-using fiskaltrust.Middleware.Localization.QueueIT.Factories;
-using fiskaltrust.Middleware.Contracts.Repositories;
-using fiskaltrust.Middleware.Contracts.Constants;
-
-namespace fiskaltrust.Middleware.Localization.QueueIT.RequestCommands
-{
- public class OutOfOperationReceiptCommand : Contracts.RequestCommands.OutOfOperationReceiptCommand
- {
- protected override long CountryBaseState => _countryBaseState;
- private readonly long _countryBaseState;
- private readonly SignatureItemFactoryIT _signatureItemFactoryIT;
- private readonly ftQueueIT _queueIt;
- private readonly ICountrySpecificQueueRepository _countrySpecificQueueRepository;
-
- public OutOfOperationReceiptCommand(SignatureItemFactoryIT signatureItemFactoryIT, ftQueueIT queueIt, ICountrySpecificSettings countrySpecificSettings)
- {
- _signatureItemFactoryIT = signatureItemFactoryIT;
- _queueIt = queueIt;
- _countrySpecificQueueRepository = countrySpecificSettings.CountrySpecificQueueRepository;
- _countryBaseState = countrySpecificSettings.CountryBaseState;
- }
-
- public override Task ReceiptNeedsReprocessing(ftQueue queue, ReceiptRequest request, ftQueueItem queueItem) => Task.FromResult(false);
-
- protected override Task<(ftActionJournal, SignaturItem)> DeactivateSCUAsync(ftQueue queue, ReceiptRequest request, ftQueueItem queueItem)
- {
- var signatureItem = _signatureItemFactoryIT.CreateOutOfOperationSignature($"Queue-ID: {queue.ftQueueId}");
- var notification = new DeactivateQueueSCU
- {
- CashBoxId = Guid.Parse(request.ftCashBoxID),
- QueueId = queueItem.ftQueueId,
- Moment = DateTime.UtcNow,
- SCUId = _queueIt.ftSignaturCreationUnitITId.GetValueOrDefault(),
- IsStopReceipt = true,
- Version = "V0"
- };
-
- var actionJournal = CreateActionJournal(queue.ftQueueId, $"{request.ftReceiptCase:X}-{nameof(DeactivateQueueSCU)}",
- queueItem.ftQueueItemId, $"Out-of-Operation receipt. Queue-ID: {queue.ftQueueId}", JsonConvert.SerializeObject(notification));
-
- return Task.FromResult((actionJournal, signatureItem));
- }
-
- protected override async Task GetCashboxIdentificationAsync(Guid ftQueueId)
- {
- var queueIt = await _countrySpecificQueueRepository.GetQueueAsync(ftQueueId).ConfigureAwait(false);
- return queueIt.CashBoxIdentification;
- }
- }
-}
diff --git a/queue/src/fiskaltrust.Middleware.Localization.QueueIT/RequestCommands/PosReceiptCommand.cs b/queue/src/fiskaltrust.Middleware.Localization.QueueIT/RequestCommands/PosReceiptCommand.cs
deleted file mode 100644
index 3f364267e..000000000
--- a/queue/src/fiskaltrust.Middleware.Localization.QueueIT/RequestCommands/PosReceiptCommand.cs
+++ /dev/null
@@ -1,257 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Threading.Tasks;
-using fiskaltrust.ifPOS.v1;
-using fiskaltrust.storage.V0;
-using fiskaltrust.Middleware.Contracts.RequestCommands;
-using fiskaltrust.ifPOS.v1.it;
-using System.Linq;
-using fiskaltrust.Middleware.Localization.QueueIT.Extensions;
-using fiskaltrust.Middleware.Localization.QueueIT.Factories;
-using fiskaltrust.Middleware.Localization.QueueIT.Services;
-using fiskaltrust.Middleware.Contracts.Extensions;
-using fiskaltrust.Middleware.Localization.QueueIT.Exceptions;
-using Newtonsoft.Json;
-using fiskaltrust.Middleware.Contracts.Repositories;
-using fiskaltrust.ifPOS.v1.errors;
-using fiskaltrust.Middleware.Contracts.Constants;
-using System.Globalization;
-using Microsoft.Extensions.Logging;
-using fiskaltrust.Middleware.Contracts.Interfaces;
-
-namespace fiskaltrust.Middleware.Localization.QueueIT.RequestCommands
-{
- public struct RefundDetails
- {
- public string Serialnumber { get; set; }
- public long ZRepNumber { get; set; }
- public long ReceiptNumber { get; set; }
- public DateTime ReceiptDateTime { get; set; }
- }
-
- public class PosReceiptCommand : RequestCommand
- {
- private readonly long _countryBaseState;
- private readonly ICountrySpecificQueueRepository _countrySpecificQueueRepository;
- private readonly ICountrySpecificSettings _countryspecificSettings;
- private readonly IConfigurationRepository _configurationRepository;
- private readonly SignatureItemFactoryIT _signatureItemFactoryIT;
- private readonly IMiddlewareJournalITRepository _journalITRepository;
- private readonly IITSSCD _client;
- private readonly ISSCD _signingDevice;
- private readonly ILogger _logger;
-
- public PosReceiptCommand(ISSCD signingDevice, ILogger logger, IITSSCDProvider itIsscdProvider, SignatureItemFactoryIT signatureItemFactoryIT, IMiddlewareJournalITRepository journalITRepository, IConfigurationRepository configurationRepository, ICountrySpecificSettings countrySpecificSettings)
- {
- _client = itIsscdProvider.Instance;
- _signatureItemFactoryIT = signatureItemFactoryIT;
- _journalITRepository = journalITRepository;
- _countryspecificSettings = countrySpecificSettings;
- _countrySpecificQueueRepository = countrySpecificSettings.CountrySpecificQueueRepository;
- _countryBaseState = countrySpecificSettings.CountryBaseState;
- _configurationRepository = configurationRepository;
- _signingDevice = signingDevice;
- _logger = logger;
- }
-
- public override async Task ExecuteAsync(ftQueue queue, ReceiptRequest request, ftQueueItem queueItem, bool isBeingResent = false)
- {
- var journals = await _journalITRepository.GetAsync().ConfigureAwait(false);
- if (journals.Where(x => x.cbReceiptReference.Equals(request.cbReceiptReference)).Any())
- {
- throw new CbReferenceExistsException(request.cbReceiptReference);
- }
-
- var queueIt = await _countrySpecificQueueRepository.GetQueueAsync(queue.ftQueueId).ConfigureAwait(false);
-
- var receiptResponse = CreateReceiptResponse(queue, request, queueItem, queueIt.CashBoxIdentification, _countryBaseState);
-
- if (request.IsMultiUseVoucherSale())
- {
- return await CreateNonFiscalRequestAsync(queueIt, queueItem, receiptResponse, request).ConfigureAwait(false);
- }
-
- FiscalReceiptResponse response;
- if (request.IsVoid())
- {
- var fiscalReceiptRefund = await CreateRefundAsync(request).ConfigureAwait(false);
- response = await _client.FiscalReceiptRefundAsync(fiscalReceiptRefund).ConfigureAwait(false);
- }
- else
- {
- var fiscalReceiptinvoice = CreateInvoice(request);
- response = await _client.FiscalReceiptInvoiceAsync(fiscalReceiptinvoice).ConfigureAwait(false);
- }
- if (!response.Success)
- {
- if (response.SSCDErrorInfo.Type == SSCDErrorType.Connection && !isBeingResent)
- {
- return await ProcessFailedReceiptRequest(_signingDevice, _logger, _countryspecificSettings, queue, queueItem, request).ConfigureAwait(false);
- }
- else
- {
- throw new SSCDErrorException(response.SSCDErrorInfo.Type, response.SSCDErrorInfo.Info);
- }
- }
- else
- {
- receiptResponse.ftReceiptIdentification += $"{response.ReceiptNumber}";
- receiptResponse.ftSignatures = _signatureItemFactoryIT.CreatePosReceiptSignatures(response);
- var journalIT = new ftJournalIT().FromResponse(queueIt, queueItem, new ScuResponse()
- {
- DataJson = response.ReceiptDataJson,
- ftReceiptCase = request.ftReceiptCase,
- ReceiptDateTime = response.ReceiptDateTime,
- ReceiptNumber = response.ReceiptNumber,
- ZRepNumber = response.ZRepNumber
- });
- await _journalITRepository.InsertAsync(journalIT).ConfigureAwait(false);
- }
-
- return new RequestCommandResponse
- {
- ReceiptResponse = receiptResponse,
- ActionJournals = new List()
- };
- }
-
- private async Task CreateNonFiscalRequestAsync(ICountrySpecificQueue queue, ftQueueItem queueItem, ReceiptResponse receiptResponse, ReceiptRequest request)
- {
- var nonFiscalRequest = new NonFiscalRequest
- {
- NonFiscalPrints = new List()
- };
- if (request.cbChargeItems != null)
- {
- foreach (var chargeItem in request.cbChargeItems.Where(x => x.IsMultiUseVoucherSale()))
- {
- AddVoucherNonFiscalPrints(nonFiscalRequest.NonFiscalPrints, chargeItem.Amount, chargeItem.ftChargeItemCaseData);
- }
- }
- if (request.cbPayItems != null)
- {
- foreach (var payItem in request.cbPayItems.Where(x => x.IsVoucherSale()))
- {
- AddVoucherNonFiscalPrints(nonFiscalRequest.NonFiscalPrints, payItem.Amount, payItem.ftPayItemCaseData);
- }
- }
- var response = await _client.NonFiscalReceiptAsync(nonFiscalRequest);
-
- if (response.Success)
- {
- receiptResponse.ftSignatures = _signatureItemFactoryIT.CreateVoucherSignatures(nonFiscalRequest);
- }
- var journalIT = new ftJournalIT
- {
- ftJournalITId = Guid.NewGuid(),
- ftQueueId = queue.ftQueueId,
- ftQueueItemId = queueItem.ftQueueItemId,
- cbReceiptReference = queueItem.cbReceiptReference,
- ftSignaturCreationUnitITId = queue.ftSignaturCreationUnitId.Value,
- JournalType = request.ftReceiptCase & 0xFFFF,
- ReceiptDateTime = queueItem.cbReceiptMoment,
- ReceiptNumber = -1,
- ZRepNumber = -1,
- DataJson = JsonConvert.SerializeObject(nonFiscalRequest),
- TimeStamp = DateTime.UtcNow.Ticks
- };
- await _journalITRepository.InsertAsync(journalIT).ConfigureAwait(false);
-
- return new RequestCommandResponse
- {
- ReceiptResponse = receiptResponse,
- ActionJournals = new List()
- };
- }
-
- private static void AddVoucherNonFiscalPrints(List nonFiscalPrints, decimal amount, string info)
- {
- nonFiscalPrints.Add(new NonFiscalPrint() { Data = "***Voucher***", Font = 2 });
- if (!string.IsNullOrEmpty(info))
- {
- nonFiscalPrints.Add(new NonFiscalPrint() { Data = info, Font = 2 });
- }
- nonFiscalPrints.Add(new NonFiscalPrint()
- {
- Data = Math.Abs(amount).ToString(new NumberFormatInfo
- {
- NumberDecimalSeparator = ",",
- NumberGroupSeparator = "",
- CurrencyDecimalDigits = 2
- }),
- Font = 2
- });
- }
-
- private static FiscalReceiptInvoice CreateInvoice(ReceiptRequest request)
- {
- var fiscalReceiptRequest = new FiscalReceiptInvoice()
- {
- //Barcode = ChargeItem.ProductBarcode,
- //TODO DisplayText = "Message on customer display",
- Operator = request.cbUser,
- Items = request.cbChargeItems.Where(x => !x.IsPaymentAdjustment()).Select(p => new Item
- {
- Description = p.Description,
- Quantity = p.Quantity,
- UnitPrice = p.UnitPrice ?? p.Amount / p.Quantity,
- Amount = p.Amount,
- VatGroup = p.GetVatGroup(),
- AdditionalInformation = p.ftChargeItemCaseData
- }).ToList(),
- PaymentAdjustments = request.GetPaymentAdjustments(),
- Payments = request.GetPayments()
- };
- return fiscalReceiptRequest;
- }
-
- private async Task CreateRefundAsync(ReceiptRequest request)
- {
- var refundDetails = await GetRefundDetailsAsync(request).ConfigureAwait(false);
- var fiscalReceiptRequest = new FiscalReceiptRefund()
- {
- //TODO Barcode = "0123456789"
- Operator = request.cbUser,
- DisplayText = $"REFUND {refundDetails.ZRepNumber:D4} {refundDetails.ReceiptNumber:D4} {refundDetails.ReceiptDateTime:ddMMyyyy} {refundDetails.Serialnumber}",
- Refunds = request.cbChargeItems?.Select(p => new Refund
- {
- Description = p.Description,
- Quantity = Math.Abs(p.Quantity),
- UnitPrice = p.UnitPrice ?? 0,
- Amount = Math.Abs(p.Amount),
- VatGroup = p.GetVatGroup()
- }).ToList(),
- PaymentAdjustments = request.GetPaymentAdjustments(),
- Payments = request.cbPayItems?.Select(p => new Payment
- {
- Amount = p.Amount,
- Description = p.Description,
- PaymentType = p.GetPaymentType(),
- }).ToList()
- };
-
- return fiscalReceiptRequest;
- }
-
- private async Task GetRefundDetailsAsync(ReceiptRequest request)
- {
- var journalIt = await _journalITRepository.GetAsync().ConfigureAwait(false);
- var receipt = journalIt.Where(x => x.cbReceiptReference.Equals(request.cbPreviousReceiptReference)).FirstOrDefault() ?? throw new RefundException($"Receipt {request.cbPreviousReceiptReference} was not found!");
- var scu = await _configurationRepository.GetSignaturCreationUnitITAsync(receipt.ftSignaturCreationUnitITId).ConfigureAwait(false);
- var deviceInfo = JsonConvert.DeserializeObject(scu.InfoJson);
- return new RefundDetails()
- {
- ReceiptNumber = receipt.ReceiptNumber,
- ZRepNumber = receipt.ZRepNumber,
- ReceiptDateTime = receipt.ReceiptDateTime,
- Serialnumber = deviceInfo.SerialNumber
- };
- }
-
- public override async Task ReceiptNeedsReprocessing(ftQueue queue, ReceiptRequest request, ftQueueItem queueItem)
- {
- var journalIt = await _journalITRepository.GetByQueueItemId(queueItem.ftQueueItemId).ConfigureAwait(false);
- return journalIt == null;
- }
- }
-}
diff --git a/queue/src/fiskaltrust.Middleware.Localization.QueueIT/RequestCommands/YearlyClosingReceiptCommand.cs b/queue/src/fiskaltrust.Middleware.Localization.QueueIT/RequestCommands/YearlyClosingReceiptCommand.cs
deleted file mode 100644
index baa24ee42..000000000
--- a/queue/src/fiskaltrust.Middleware.Localization.QueueIT/RequestCommands/YearlyClosingReceiptCommand.cs
+++ /dev/null
@@ -1,30 +0,0 @@
-using System;
-using System.Threading.Tasks;
-using fiskaltrust.ifPOS.v1;
-using fiskaltrust.Middleware.Contracts.Constants;
-using fiskaltrust.Middleware.Contracts.Repositories;
-using fiskaltrust.storage.V0;
-
-namespace fiskaltrust.Middleware.Localization.QueueIT.RequestCommands
-{
- public class YearlyClosingReceiptCommand : Contracts.RequestCommands.YearlyClosingReceiptCommand
- {
- private readonly long _countryBaseState;
- protected override long CountryBaseState => _countryBaseState;
- private readonly ICountrySpecificQueueRepository _countrySpecificQueueRepository;
-
- public YearlyClosingReceiptCommand(ICountrySpecificSettings countryspecificSettings)
- {
- _countrySpecificQueueRepository = countryspecificSettings.CountrySpecificQueueRepository;
- _countryBaseState = countryspecificSettings.CountryBaseState;
- }
-
- protected override async Task GetCashboxIdentificationAsync(Guid ftQueueId)
- {
- var queueIt = await _countrySpecificQueueRepository.GetQueueAsync(ftQueueId).ConfigureAwait(false);
- return queueIt.CashBoxIdentification;
- }
-
- public override Task ReceiptNeedsReprocessing(ftQueue queue, ReceiptRequest request, ftQueueItem queueItem) => Task.FromResult(false);
- }
-}
diff --git a/queue/src/fiskaltrust.Middleware.Localization.QueueIT/RequestCommands/ZeroReceiptCommandIT.cs b/queue/src/fiskaltrust.Middleware.Localization.QueueIT/RequestCommands/ZeroReceiptCommandIT.cs
deleted file mode 100644
index 2f841f854..000000000
--- a/queue/src/fiskaltrust.Middleware.Localization.QueueIT/RequestCommands/ZeroReceiptCommandIT.cs
+++ /dev/null
@@ -1,18 +0,0 @@
-using fiskaltrust.storage.V0;
-using Microsoft.Extensions.Logging;
-using fiskaltrust.Middleware.Contracts.RequestCommands;
-using fiskaltrust.Middleware.Contracts.Repositories;
-using fiskaltrust.Middleware.Contracts.RequestCommands.Factories;
-using fiskaltrust.Middleware.Contracts.Constants;
-using fiskaltrust.Middleware.Contracts.Interfaces;
-
-namespace fiskaltrust.Middleware.Localization.QueueIT.RequestCommands
-{
- public class ZeroReceiptCommandIT : ZeroReceiptCommand
- {
- public ZeroReceiptCommandIT(ISSCD signingDevice, ICountrySpecificSettings countryspecificSettings, IMiddlewareQueueItemRepository queueItemRepository, IRequestCommandFactory requestCommandFactory, ILogger logger, IActionJournalRepository actionJournalRepository) :
- base(signingDevice, countryspecificSettings, queueItemRepository, requestCommandFactory, logger, actionJournalRepository)
- {
- }
- }
-}
diff --git a/queue/src/fiskaltrust.Middleware.Localization.QueueIT/Services/IITSSCDProvider.cs b/queue/src/fiskaltrust.Middleware.Localization.QueueIT/Services/IITSSCDProvider.cs
deleted file mode 100644
index c90574db4..000000000
--- a/queue/src/fiskaltrust.Middleware.Localization.QueueIT/Services/IITSSCDProvider.cs
+++ /dev/null
@@ -1,12 +0,0 @@
-using System.Threading.Tasks;
-using fiskaltrust.ifPOS.v1.it;
-
-namespace fiskaltrust.Middleware.Localization.QueueIT.Services
-{
- public interface IITSSCDProvider
- {
- IITSSCD Instance { get; }
-
- Task RegisterCurrentScuAsync();
- }
-}
diff --git a/queue/src/fiskaltrust.Middleware.Localization.QueueIT/Services/ITSSCDProvider.cs b/queue/src/fiskaltrust.Middleware.Localization.QueueIT/Services/ITSSCDProvider.cs
deleted file mode 100644
index d950e874f..000000000
--- a/queue/src/fiskaltrust.Middleware.Localization.QueueIT/Services/ITSSCDProvider.cs
+++ /dev/null
@@ -1,90 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Threading;
-using System.Threading.Tasks;
-using fiskaltrust.ifPOS.v1.it;
-using fiskaltrust.Middleware.Abstractions;
-using fiskaltrust.Middleware.Contracts.Models;
-using fiskaltrust.storage.V0;
-using Newtonsoft.Json;
-
-namespace fiskaltrust.Middleware.Localization.QueueIT.Services
-{
- public class ITSSCDProvider : IITSSCDProvider
- {
-
- private readonly IClientFactory _clientFactory;
- private readonly MiddlewareConfiguration _middlewareConfiguration;
-
- private readonly SemaphoreSlim _semaphoreInstance = new SemaphoreSlim(1, 1);
- private readonly SemaphoreSlim _semaphoreRegister = new SemaphoreSlim(1, 1);
-
- private IITSSCD _instance;
-
- public IITSSCD Instance
- {
- get
- {
- try
- {
- _semaphoreInstance.Wait();
- if (_instance == null)
- {
- RegisterCurrentScuAsync().Wait();
- }
-
- return _instance;
- }
- finally
- {
- _semaphoreInstance.Release();
- }
- }
- }
-
- public ITSSCDProvider(IClientFactory clientFactory, MiddlewareConfiguration middlewareConfiguration)
- {
- _clientFactory = clientFactory;
- _middlewareConfiguration = middlewareConfiguration;
- }
-
- public async Task RegisterCurrentScuAsync()
- {
- try
- {
- await _semaphoreRegister.WaitAsync().ConfigureAwait(false);
- var ftSignaturCreationUnitIT = JsonConvert.DeserializeObject>(_middlewareConfiguration.Configuration["init_ftSignaturCreationUnitIT"].ToString());
-
- var uri = GetUriForSignaturCreationUnit(ftSignaturCreationUnitIT.FirstOrDefault().Url);
- var config = new ClientConfiguration
- {
- Url = uri.ToString(),
- UrlType = uri.Scheme
- };
-
- _instance = _clientFactory.CreateClient(config);
- }
- finally
- {
- _semaphoreRegister.Release();
- }
- }
-
- private static Uri GetUriForSignaturCreationUnit(string url)
- {
-
- try
- {
- var urls = JsonConvert.DeserializeObject(url);
- var grpcUrl = urls.FirstOrDefault(x => x.StartsWith("grpc://"));
- url = grpcUrl ?? urls.First();
- }
- catch { }
-
- return new Uri(url);
- }
-
- }
-
-}
diff --git a/queue/src/fiskaltrust.Middleware.Localization.QueueIT/Services/SscdIT.cs b/queue/src/fiskaltrust.Middleware.Localization.QueueIT/Services/SscdIT.cs
deleted file mode 100644
index 1cc0b7f17..000000000
--- a/queue/src/fiskaltrust.Middleware.Localization.QueueIT/Services/SscdIT.cs
+++ /dev/null
@@ -1,35 +0,0 @@
-using System;
-using System.Threading.Tasks;
-using Microsoft.Extensions.Logging;
-using fiskaltrust.ifPOS.v1.it;
-using Newtonsoft.Json;
-using fiskaltrust.Middleware.Contracts.Interfaces;
-
-namespace fiskaltrust.Middleware.Localization.QueueIT.Services
-{
- public class SscdIT : ISSCD
- {
- private readonly IITSSCD _client;
- private readonly ILogger _logger;
-
-
- public SscdIT(IITSSCDProvider itIsscdProvider, ILogger logger)
- {
- _client = itIsscdProvider.Instance;
- _logger = logger;
- }
-
- public async Task IsSSCDAvailable()
- {
- try
- {
- var deviceInfo = await _client.GetDeviceInfoAsync().ConfigureAwait(false);
- _logger.LogDebug(JsonConvert.SerializeObject(deviceInfo));
- return true;
- }catch (Exception ex) {
- _logger.LogError(ex, "Error on DeviceInfo Request.");
- return false;
- }
- }
- }
-}
diff --git a/queue/src/fiskaltrust.Middleware.Localization.QueueIT/SignProcessor.cs b/queue/src/fiskaltrust.Middleware.Localization.QueueIT/SignProcessor.cs
new file mode 100644
index 000000000..e09228481
--- /dev/null
+++ b/queue/src/fiskaltrust.Middleware.Localization.QueueIT/SignProcessor.cs
@@ -0,0 +1,97 @@
+using System;
+using System.Collections.Generic;
+using System.Threading.Tasks;
+using fiskaltrust.ifPOS.v1;
+using fiskaltrust.Middleware.Contracts.Extensions;
+using fiskaltrust.Middleware.Contracts.Interfaces;
+using fiskaltrust.Middleware.Localization.QueueIT.Constants;
+using fiskaltrust.Middleware.Localization.QueueIT.Extensions;
+using fiskaltrust.Middleware.Localization.QueueIT.Helpers;
+using fiskaltrust.storage.V0;
+
+namespace fiskaltrust.Middleware.Localization.QueueIT
+{
+ public class SignProcessor : IMarketSpecificSignProcessor
+ {
+ protected readonly IConfigurationRepository _configurationRepository;
+ private readonly SignProcessorIT _signProcessorIT;
+
+ public SignProcessor(IConfigurationRepository configurationRepository, SignProcessorIT signProcessorIT)
+ {
+ _configurationRepository = configurationRepository;
+ _signProcessorIT = signProcessorIT;
+ }
+
+ public async Task<(ReceiptResponse receiptResponse, List actionJournals)> ProcessAsync(ReceiptRequest request, ftQueue queue, ftQueueItem queueItem)
+ {
+
+ var receiptIdentification = $"ft{queue.ftReceiptNumerator:X}#";
+ var receiptResponse = new ReceiptResponse
+ {
+ ftCashBoxID = request.ftCashBoxID,
+ ftQueueID = queueItem.ftQueueId.ToString(),
+ ftQueueItemID = queueItem.ftQueueItemId.ToString(),
+ ftQueueRow = queueItem.ftQueueRow,
+ cbTerminalID = request.cbTerminalID,
+ cbReceiptReference = request.cbReceiptReference,
+ ftReceiptMoment = DateTime.UtcNow,
+ ftState = Cases.BASE_STATE,
+ ftReceiptIdentification = receiptIdentification
+ };
+
+ if (queue.IsDeactivated())
+ {
+ return ReturnWithQueueIsDisabled(queue, receiptResponse, queueItem);
+ }
+
+ if (request.IsInitialOperation() && !queue.IsNew())
+ {
+ receiptResponse.SetReceiptResponseError("The queue is already operational. It is not allowed to send another InitOperation Receipt");
+ return (receiptResponse, new List());
+ }
+
+ if (!request.IsInitialOperation() && queue.IsNew())
+ {
+ return ReturnWithQueueIsNotActive(queue, receiptResponse, queueItem);
+ }
+
+ return await _signProcessorIT.ProcessAsync(request, receiptResponse, queue, queueItem).ConfigureAwait(false);
+ }
+
+ public (ReceiptResponse receiptResponse, List actionJournals) ReturnWithQueueIsNotActive(ftQueue queue, ReceiptResponse receiptResponse, ftQueueItem queueItem)
+ {
+ var actionJournals = new List
+ {
+ new ftActionJournal
+ {
+ ftActionJournalId = Guid.NewGuid(),
+ ftQueueId = queueItem.ftQueueId,
+ ftQueueItemId = queueItem.ftQueueItemId,
+ Moment = DateTime.UtcNow,
+ Message = $"QueueId {queueItem.ftQueueId} has not been activated yet."
+ }
+ };
+ receiptResponse.ftState += ftStatesFlags.SECURITY_MECHAMISN_DEACTIVATED;
+ receiptResponse.ftReceiptIdentification = $"ft{queue.ftReceiptNumerator:X}#";
+ return (receiptResponse, actionJournals);
+ }
+
+ public (ReceiptResponse receiptResponse, List actionJournals) ReturnWithQueueIsDisabled(ftQueue queue, ReceiptResponse receiptResponse, ftQueueItem queueItem)
+ {
+ var actionJournals = new List
+ {
+ new ftActionJournal
+ {
+ ftActionJournalId = Guid.NewGuid(),
+ ftQueueId = queueItem.ftQueueId,
+ ftQueueItemId = queueItem.ftQueueItemId,
+ Moment = DateTime.UtcNow,
+ Message = $"QueueId {queueItem.ftQueueId} has been disabled."
+ }
+ };
+ receiptResponse.ftState += ftStatesFlags.SECURITY_MECHAMISN_DEACTIVATED;
+ receiptResponse.ftReceiptIdentification = $"ft{queue.ftReceiptNumerator:X}#";
+ return (receiptResponse, actionJournals);
+ }
+ }
+}
diff --git a/queue/src/fiskaltrust.Middleware.Localization.QueueIT/SignProcessorIT.cs b/queue/src/fiskaltrust.Middleware.Localization.QueueIT/SignProcessorIT.cs
index 93e327d23..5d986728e 100644
--- a/queue/src/fiskaltrust.Middleware.Localization.QueueIT/SignProcessorIT.cs
+++ b/queue/src/fiskaltrust.Middleware.Localization.QueueIT/SignProcessorIT.cs
@@ -2,56 +2,82 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using fiskaltrust.ifPOS.v1;
+using fiskaltrust.Middleware.Localization.QueueIT.Extensions;
+using fiskaltrust.Middleware.Localization.QueueIT.Helpers;
+using fiskaltrust.Middleware.Localization.QueueIT.v2;
using fiskaltrust.storage.V0;
-using System.Linq;
-using fiskaltrust.Middleware.Contracts.Exceptions;
-using fiskaltrust.Middleware.Localization.QueueIT.RequestCommands;
-using fiskaltrust.Middleware.Contracts.RequestCommands.Factories;
-using fiskaltrust.Middleware.Contracts.Constants;
-using fiskaltrust.Middleware.Contracts.Interfaces;
using Microsoft.Extensions.Logging;
namespace fiskaltrust.Middleware.Localization.QueueIT
{
- public class SignProcessorIT : IMarketSpecificSignProcessor
+ public class SignProcessorIT
{
- private readonly ICountrySpecificSettings _countrySpecificSettings;
- private readonly IRequestCommandFactory _requestCommandFactory;
protected readonly IConfigurationRepository _configurationRepository;
- private readonly ISSCD _signingDevice;
- private readonly ILogger _logger;
+ private readonly LifecyclCommandProcessorIT _lifecyclCommandProcessorIT;
+ private readonly ReceiptCommandProcessorIT _receiptCommandProcessorIT;
+ private readonly DailyOperationsCommandProcessorIT _dailyOperationsCommandProcessorIT;
+ private readonly InvoiceCommandProcessorIT _invoiceCommandProcessorIT;
+ private readonly ProtocolCommandProcessorIT _protocolCommandProcessorIT;
+ private readonly ILogger _logger;
- public SignProcessorIT(ISSCD signingDevice, ILogger logger, ICountrySpecificSettings countrySpecificSettings, IRequestCommandFactory requestCommandFactory, IConfigurationRepository configurationRepository)
+ public SignProcessorIT(ILogger logger, IConfigurationRepository configurationRepository, LifecyclCommandProcessorIT lifecyclCommandProcessorIT, ReceiptCommandProcessorIT receiptCommandProcessorIT, DailyOperationsCommandProcessorIT dailyOperationsCommandProcessorIT, InvoiceCommandProcessorIT invoiceCommandProcessorIT, ProtocolCommandProcessorIT protocolCommandProcessorIT)
{
- _requestCommandFactory = requestCommandFactory;
_configurationRepository = configurationRepository;
- _countrySpecificSettings = countrySpecificSettings;
- _signingDevice = signingDevice;
+ _lifecyclCommandProcessorIT = lifecyclCommandProcessorIT;
+ _receiptCommandProcessorIT = receiptCommandProcessorIT;
+ _dailyOperationsCommandProcessorIT = dailyOperationsCommandProcessorIT;
+ _invoiceCommandProcessorIT = invoiceCommandProcessorIT;
+ _protocolCommandProcessorIT = protocolCommandProcessorIT;
_logger = logger;
}
- public async Task<(ReceiptResponse receiptResponse, List actionJournals)> ProcessAsync(ReceiptRequest request, ftQueue queue, ftQueueItem queueItem)
+ public async Task<(ReceiptResponse receiptResponse, List actionJournals)> ProcessAsync(ReceiptRequest request, ReceiptResponse receiptResponse, ftQueue queue, ftQueueItem queueItem)
{
var queueIT = await _configurationRepository.GetQueueITAsync(queue.ftQueueId).ConfigureAwait(false);
- if (!queueIT.ftSignaturCreationUnitITId.HasValue)
- {
- throw new NullReferenceException(nameof(queueIT.ftSignaturCreationUnitITId));
- }
- var requestCommand = _requestCommandFactory.Create(request);
+ receiptResponse.ftCashBoxIdentification = queueIT.CashBoxIdentification;
- var scu = await _configurationRepository.GetSignaturCreationUnitITAsync(queueIT.ftSignaturCreationUnitITId.Value);
- if (string.IsNullOrEmpty(scu.InfoJson) && requestCommand is not InitialOperationReceiptCommand)
+ try
{
- throw new MissiningInitialOpException();
- }
- if (queueIT.SSCDFailCount > 0 && requestCommand is not ZeroReceiptCommandIT)
+ if (request.IsDailyOperation())
+ {
+ (var response, var actionJournals) = await _dailyOperationsCommandProcessorIT.ProcessReceiptAsync(new ProcessCommandRequest(queue, queueIT, request, receiptResponse, queueItem)).ConfigureAwait(false);
+ return (response, actionJournals);
+ }
+
+ if (request.IsLifeCycleOperation())
+ {
+ (var response, var actionJournals) = await _lifecyclCommandProcessorIT.ProcessReceiptAsync(new ProcessCommandRequest(queue, queueIT, request, receiptResponse, queueItem)).ConfigureAwait(false);
+ return (response, actionJournals);
+ }
+
+ if (request.IsReceiptOperation())
+ {
+ var (response, actionJournals) = await _receiptCommandProcessorIT.ProcessReceiptAsync(new ProcessCommandRequest(queue, queueIT, request, receiptResponse, queueItem)).ConfigureAwait(false);
+ return (response, actionJournals);
+ }
+
+ if (request.IsProtocolOperation())
+ {
+ var (response, actionJournals) = await _protocolCommandProcessorIT.ProcessReceiptAsync(new ProcessCommandRequest(queue, queueIT, request, receiptResponse, queueItem)).ConfigureAwait(false);
+ return (response, actionJournals);
+ }
+
+ if (request.IsInvoiceOperation())
+ {
+ var (response, actionJournals) = await _invoiceCommandProcessorIT.ProcessReceiptAsync(new ProcessCommandRequest(queue, queueIT, request, receiptResponse, queueItem)).ConfigureAwait(false);
+ return (response, actionJournals);
+ }
+
+ receiptResponse.SetReceiptResponseError($"The given ftReceiptCase 0x{request.ftReceiptCase:x} is not supported. Please refer to docs.fiskaltrust.cloud for supported cases.");
+ return (receiptResponse, new List());
+ }
+ catch (Exception ex)
{
- var requestCommandResponse = await requestCommand.ProcessFailedReceiptRequest(_signingDevice, _logger, _countrySpecificSettings, queue, queueItem, request).ConfigureAwait(false);
- return (requestCommandResponse.ReceiptResponse, requestCommandResponse.ActionJournals.ToList());
+ _logger.LogError(ex, "Failed to process receiptcase 0x{receiptcase}", request.ftReceiptCase.ToString("X"));
+ receiptResponse.SetReceiptResponseError($"Failed to process receiptcase 0x{request.ftReceiptCase.ToString("X")}. with the following exception message: " + ex.Message);
+ return (receiptResponse, new List());
}
- var response = await requestCommand.ExecuteAsync(queue, request, queueItem).ConfigureAwait(false);
- return (response.ReceiptResponse, response.ActionJournals.ToList());
}
}
}
diff --git a/queue/src/fiskaltrust.Middleware.Localization.QueueIT/SignatureTypesIT.cs b/queue/src/fiskaltrust.Middleware.Localization.QueueIT/SignatureTypesIT.cs
deleted file mode 100644
index 457236bd8..000000000
--- a/queue/src/fiskaltrust.Middleware.Localization.QueueIT/SignatureTypesIT.cs
+++ /dev/null
@@ -1,10 +0,0 @@
-namespace fiskaltrust.Middleware.Localization.QueueIT
-{
- public enum SignatureTypesIT
- {
- ReceiptNumber = 0x01,
- ZNumber = 0x02,
- ReceiptAmount = 0x03,
- ReceiptTimestamp = 0x04
- }
-}
diff --git a/queue/src/fiskaltrust.Middleware.Localization.QueueIT/v2/DailyOperationsCommandProcessorIT.cs b/queue/src/fiskaltrust.Middleware.Localization.QueueIT/v2/DailyOperationsCommandProcessorIT.cs
new file mode 100644
index 000000000..f4f46b0d2
--- /dev/null
+++ b/queue/src/fiskaltrust.Middleware.Localization.QueueIT/v2/DailyOperationsCommandProcessorIT.cs
@@ -0,0 +1,176 @@
+using System.Collections.Generic;
+using System.Threading.Tasks;
+using fiskaltrust.ifPOS.v1.it;
+using fiskaltrust.Middleware.Localization.QueueIT.Constants;
+using fiskaltrust.Middleware.Localization.QueueIT.Factories;
+using fiskaltrust.Middleware.Localization.QueueIT.Helpers;
+using fiskaltrust.Middleware.Localization.QueueIT.Models;
+using fiskaltrust.storage.V0;
+
+#pragma warning disable
+
+namespace fiskaltrust.Middleware.Localization.QueueIT.v2
+{
+ public class DailyOperationsCommandProcessorIT
+ {
+ private readonly IJournalITRepository _journalITRepository;
+ private readonly IConfigurationRepository _configurationRepository;
+ private readonly IITSSCDProvider _itSSCDProvider;
+
+ public DailyOperationsCommandProcessorIT(IITSSCDProvider itSSCDProvider, IJournalITRepository journalITRepository, IConfigurationRepository configurationRepository)
+ {
+ _itSSCDProvider = itSSCDProvider;
+ _journalITRepository = journalITRepository;
+ _configurationRepository = configurationRepository;
+ }
+
+ public async Task ProcessReceiptAsync(ProcessCommandRequest request)
+ {
+ var receiptCase = (request.ReceiptRequest.ftReceiptCase & 0xFFFF);
+ if (receiptCase == (int) ReceiptCases.ZeroReceipt0x2000)
+ return await ZeroReceipt0x2000Async(request);
+
+ if (receiptCase == (int) ReceiptCases.OneReceipt0x2001)
+ return await OneReceipt0x2001Async(request);
+
+ if (receiptCase == (int) ReceiptCases.ShiftClosing0x2010)
+ return await ShiftClosing0x2010Async(request);
+
+ if (receiptCase == (int) ReceiptCases.DailyClosing0x2011)
+ return await DailyClosing0x2011Async(request);
+
+ if (receiptCase == (int) ReceiptCases.MonthlyClosing0x2012)
+ return await MonthlyClosing0x2012Async(request);
+
+ if (receiptCase == (int) ReceiptCases.YearlyClosing0x2013)
+ return await YearlyClosing0x2013Async(request);
+
+ request.ReceiptResponse.SetReceiptResponseError($"The given ReceiptCase 0x{request.ReceiptRequest.ftReceiptCase:x} is not supported. Please refer to docs.fiskaltrust.cloud for supported cases.");
+ return new ProcessCommandResponse(request.ReceiptResponse, new List());
+ }
+
+ public async Task ZeroReceipt0x2000Async(ProcessCommandRequest request)
+ {
+ var (queue, queueIT, receiptRequest, receiptResponse, queueItem) = request;
+ if (queueIT.SSCDFailCount != 0)
+ {
+ queueIT.SSCDFailCount = 0;
+ queueIT.SSCDFailMoment = null;
+ queueIT.SSCDFailQueueItemId = null;
+ await _configurationRepository.InsertOrUpdateQueueITAsync(queueIT).ConfigureAwait(false);
+ }
+
+ var establishConnection = await _itSSCDProvider.ProcessReceiptAsync(new ProcessRequest
+ {
+ ReceiptRequest = receiptRequest,
+ ReceiptResponse = receiptResponse
+ });
+ if (establishConnection.ReceiptResponse.HasFailed())
+ {
+ return new ProcessCommandResponse(establishConnection.ReceiptResponse, new List());
+ }
+
+ if (establishConnection.ReceiptResponse.ftState == 0x4954_2001_0000_0000)
+ {
+ return new ProcessCommandResponse(establishConnection.ReceiptResponse, new List());
+ }
+ return new ProcessCommandResponse(establishConnection.ReceiptResponse, new List());
+ }
+
+ public async Task OneReceipt0x2001Async(ProcessCommandRequest request) => await Task.FromResult(new ProcessCommandResponse(request.ReceiptResponse, new List()));
+
+ public async Task ShiftClosing0x2010Async(ProcessCommandRequest request) => await Task.FromResult(new ProcessCommandResponse(request.ReceiptResponse, new List()));
+
+ public async Task DailyClosing0x2011Async(ProcessCommandRequest request)
+ {
+ var (queue, queueIt, receiptRequest, receiptResponse, queueItem) = request;
+ var actionJournalEntry = ftActionJournalFactory.CreateDailyClosingActionJournal(queue, queueItem, receiptRequest);
+ var result = await _itSSCDProvider.ProcessReceiptAsync(new ProcessRequest
+ {
+ ReceiptRequest = receiptRequest,
+ ReceiptResponse = receiptResponse
+ });
+ if (result.ReceiptResponse.HasFailed())
+ {
+ return new ProcessCommandResponse(result.ReceiptResponse, new List());
+ }
+
+ var zNumber = result.ReceiptResponse.GetSignaturItem(SignatureTypesIT.RTZNumber).Data;
+ receiptResponse.ftReceiptIdentification += $"Z{zNumber.PadLeft(4, '0')}";
+ receiptResponse.ftSignatures = result.ReceiptResponse.ftSignatures;
+
+ var journalIT = ftJournalITFactory.CreateFrom(queueItem, queueIt, new ScuResponse()
+ {
+ ftReceiptCase = receiptRequest.ftReceiptCase,
+ ZRepNumber = long.Parse(zNumber)
+ });
+ await _journalITRepository.InsertAsync(journalIT).ConfigureAwait(false);
+
+ return new ProcessCommandResponse(receiptResponse, new List
+ {
+ actionJournalEntry
+ });
+ }
+
+ public async Task MonthlyClosing0x2012Async(ProcessCommandRequest request)
+ {
+ var (queue, queueIt, receiptRequest, receiptResponse, queueItem) = request;
+ var actionJournalEntry = ftActionJournalFactory.CreateMonthlyClosingActionJournal(queue, queueItem, receiptRequest);
+ var result = await _itSSCDProvider.ProcessReceiptAsync(new ProcessRequest
+ {
+ ReceiptRequest = receiptRequest,
+ ReceiptResponse = receiptResponse
+ });
+ if (result.ReceiptResponse.HasFailed())
+ {
+ return new ProcessCommandResponse(result.ReceiptResponse, new List());
+ }
+
+ var zNumber = result.ReceiptResponse.GetSignaturItem(SignatureTypesIT.RTZNumber).Data;
+ receiptResponse.ftReceiptIdentification += $"Z{zNumber.PadLeft(4, '0')}";
+ receiptResponse.ftSignatures = result.ReceiptResponse.ftSignatures;
+
+ var journalIT = ftJournalITFactory.CreateFrom(queueItem, queueIt, new ScuResponse()
+ {
+ ftReceiptCase = receiptRequest.ftReceiptCase,
+ ZRepNumber = long.Parse(zNumber)
+ });
+ await _journalITRepository.InsertAsync(journalIT).ConfigureAwait(false);
+
+ return new ProcessCommandResponse(receiptResponse, new List
+ {
+ actionJournalEntry
+ });
+ }
+
+ public async Task YearlyClosing0x2013Async(ProcessCommandRequest request)
+ {
+ var (queue, queueIt, receiptRequest, receiptResponse, queueItem) = request;
+
+ var actionJournalEntry = ftActionJournalFactory.CreateYearlyClosingClosingActionJournal(queue, queueItem, receiptRequest);
+ var result = await _itSSCDProvider.ProcessReceiptAsync(new ProcessRequest
+ {
+ ReceiptRequest = receiptRequest,
+ ReceiptResponse = receiptResponse
+ });
+ if (result.ReceiptResponse.HasFailed())
+ {
+ return new ProcessCommandResponse(result.ReceiptResponse, new List());
+ }
+
+ var zNumber = result.ReceiptResponse.GetSignaturItem(SignatureTypesIT.RTZNumber).Data;
+ receiptResponse.ftReceiptIdentification += $"Z{zNumber.PadLeft(4, '0')}";
+ receiptResponse.ftSignatures = result.ReceiptResponse.ftSignatures;
+ var journalIT = ftJournalITFactory.CreateFrom(queueItem, queueIt, new ScuResponse()
+ {
+ ftReceiptCase = receiptRequest.ftReceiptCase,
+ ZRepNumber = long.Parse(zNumber)
+ });
+ await _journalITRepository.InsertAsync(journalIT).ConfigureAwait(false);
+ return new ProcessCommandResponse(receiptResponse, new List
+ {
+ actionJournalEntry
+ });
+ }
+ }
+}
\ No newline at end of file
diff --git a/queue/src/fiskaltrust.Middleware.Localization.QueueIT/v2/InvoiceCommandProcessorIT.cs b/queue/src/fiskaltrust.Middleware.Localization.QueueIT/v2/InvoiceCommandProcessorIT.cs
new file mode 100644
index 000000000..08208f45d
--- /dev/null
+++ b/queue/src/fiskaltrust.Middleware.Localization.QueueIT/v2/InvoiceCommandProcessorIT.cs
@@ -0,0 +1,39 @@
+using System.Collections.Generic;
+using System.Threading.Tasks;
+using fiskaltrust.Middleware.Localization.QueueIT.Helpers;
+using fiskaltrust.storage.V0;
+
+#pragma warning disable
+
+namespace fiskaltrust.Middleware.Localization.QueueIT.v2
+{
+ public class InvoiceCommandProcessorIT
+ {
+ public async Task ProcessReceiptAsync(ProcessCommandRequest request)
+ {
+ var receiptCase = (request.ReceiptRequest.ftReceiptCase & 0xFFFF);
+ if (receiptCase == (int)ReceiptCases.InvoiceUnknown0x1000)
+ return await InvoiceUnknown0x1000Async(request);
+
+ if (receiptCase == (int)ReceiptCases.InvoiceB2C0x1001)
+ return await InvoiceB2C0x1001Async(request);
+
+ if (receiptCase == (int)ReceiptCases.InvoiceB2B0x1002)
+ return await InvoiceB2B0x1002Async(request);
+
+ if (receiptCase == (int)ReceiptCases.InvoiceB2G0x1003)
+ return await InvoiceB2G0x1003Async(request);
+
+ request.ReceiptResponse.SetReceiptResponseError($"The given ftReceiptCase 0x{request.ReceiptRequest.ftReceiptCase:x} is not supported. Please refer to docs.fiskaltrust.cloud for supported cases.");
+ return new ProcessCommandResponse(request.ReceiptResponse, new List());
+ }
+
+ public async Task InvoiceUnknown0x1000Async(ProcessCommandRequest request) => await Task.FromResult(new ProcessCommandResponse(request.ReceiptResponse, new List())).ConfigureAwait(false);
+
+ public async Task InvoiceB2C0x1001Async(ProcessCommandRequest request) => await Task.FromResult(new ProcessCommandResponse(request.ReceiptResponse, new List())).ConfigureAwait(false);
+
+ public async Task InvoiceB2B0x1002Async(ProcessCommandRequest request) => await Task.FromResult(new ProcessCommandResponse(request.ReceiptResponse, new List())).ConfigureAwait(false);
+
+ public async Task InvoiceB2G0x1003Async(ProcessCommandRequest request) => await Task.FromResult(new ProcessCommandResponse(request.ReceiptResponse, new List())).ConfigureAwait(false);
+ }
+}
\ No newline at end of file
diff --git a/queue/src/fiskaltrust.Middleware.Localization.QueueIT/v2/LifecyclCommandProcessorIT.cs b/queue/src/fiskaltrust.Middleware.Localization.QueueIT/v2/LifecyclCommandProcessorIT.cs
new file mode 100644
index 000000000..dc2047132
--- /dev/null
+++ b/queue/src/fiskaltrust.Middleware.Localization.QueueIT/v2/LifecyclCommandProcessorIT.cs
@@ -0,0 +1,130 @@
+using System;
+using System.Collections.Generic;
+using System.Threading.Tasks;
+using fiskaltrust.ifPOS.v1;
+using fiskaltrust.ifPOS.v1.it;
+using fiskaltrust.Middleware.Localization.QueueIT.Factories;
+using fiskaltrust.Middleware.Localization.QueueIT.Helpers;
+using fiskaltrust.storage.V0;
+using Newtonsoft.Json;
+
+#pragma warning disable
+
+namespace fiskaltrust.Middleware.Localization.QueueIT.v2
+{
+ public class LifecyclCommandProcessorIT
+ {
+ private readonly IITSSCDProvider _itSSCDProvider;
+ private readonly IJournalITRepository _journalITRepository;
+ private readonly IConfigurationRepository _configurationRepository;
+
+ public LifecyclCommandProcessorIT(IITSSCDProvider itSSCDProvider, IJournalITRepository journalITRepository, IConfigurationRepository configurationRepository)
+ {
+ _itSSCDProvider = itSSCDProvider;
+ _journalITRepository = journalITRepository;
+ _configurationRepository = configurationRepository;
+ }
+
+ public async Task ProcessReceiptAsync(ProcessCommandRequest request)
+ {
+ var receiptCase = (request.ReceiptRequest.ftReceiptCase & 0xFFFF);
+ if (receiptCase == (int) ReceiptCases.InitialOperationReceipt0x4001)
+ return await InitialOperationReceipt0x4001Async(request);
+
+ if (receiptCase == (int) ReceiptCases.OutOfOperationReceipt0x4002)
+ return await OutOfOperationReceipt0x4002Async(request);
+
+ if (receiptCase == (int) ReceiptCases.InitSCUSwitch0x4011)
+ return await InitSCUSwitch0x4011Async(request);
+
+ if (receiptCase == (int) ReceiptCases.FinishSCUSwitch0x4012)
+ return await FinishSCUSwitch0x4012Async(request);
+
+ request.ReceiptResponse.SetReceiptResponseError($"The given ReceiptCase 0x{request.ReceiptRequest.ftReceiptCase:x} is not supported. Please refer to docs.fiskaltrust.cloud for supported cases.");
+ return new ProcessCommandResponse(request.ReceiptResponse, new List());
+ }
+
+ public async Task InitialOperationReceipt0x4001Async(ProcessCommandRequest request)
+ {
+ // TODO SKE => We need to figure a way to retry this functionality in case we fail to do something. There are a few states that
+ // we need to take care of:
+ // - SCU is not rechable => initial operation fails with EEEE_EEEE and needs to be retried by the caller
+ // - SCU is reachable but fails internall => initial operation fails with EEEE_EEEE and needs to be retried by the caller
+ // - SCU succeeds, but the Queue fails to receive / store the result for whatever reason => initial operation fails with EEEE_EEEE and needs to be retried by the caller but the SCU should be capable of handling that
+ //
+ // A few more points regarding the activation
+ // - If we fail to receive the result the point of activation doesn't match with the one given in the QueueItem.
+ // -
+ var (queue, queueIt, receiptRequest, receiptResponse, queueItem) = request;
+ var scu = await _configurationRepository.GetSignaturCreationUnitITAsync(queueIt.ftSignaturCreationUnitITId.Value).ConfigureAwait(false);
+ var deviceInfo = await _itSSCDProvider.GetRTInfoAsync().ConfigureAwait(false);
+ if (string.IsNullOrEmpty(scu.InfoJson))
+ {
+ scu.InfoJson = JsonConvert.SerializeObject(deviceInfo);
+ await _configurationRepository.InsertOrUpdateSignaturCreationUnitITAsync(scu).ConfigureAwait(false);
+ }
+
+ var signature = SignaturItemFactory.CreateInitialOperationSignature(queueIt, deviceInfo);
+ var actionJournal = ftActionJournalFactory.CreateInitialOperationActionJournal(queue, queueItem, queueIt, receiptRequest);
+
+ var result = await _itSSCDProvider.ProcessReceiptAsync(new ProcessRequest
+ {
+ ReceiptRequest = receiptRequest,
+ ReceiptResponse = receiptResponse,
+ });
+ if (result.ReceiptResponse.HasFailed())
+ {
+ return new ProcessCommandResponse(receiptResponse, new List());
+ }
+
+ var signatures = new List
+ {
+ signature
+ };
+ queue.StartMoment = DateTime.UtcNow;
+ await _configurationRepository.InsertOrUpdateQueueAsync(queue).ConfigureAwait(false);
+ signatures.AddRange(result.ReceiptResponse.ftSignatures);
+ receiptResponse.ftSignatures = signatures.ToArray();
+
+ return new ProcessCommandResponse(receiptResponse, new List
+ {
+ actionJournal
+ });
+ }
+
+ public async Task OutOfOperationReceipt0x4002Async(ProcessCommandRequest request)
+ {
+ var (queue, queueIt, receiptRequest, receiptResponse, queueItem) = request;
+
+ var result = await _itSSCDProvider.ProcessReceiptAsync(new ProcessRequest
+ {
+ ReceiptRequest = receiptRequest,
+ ReceiptResponse = receiptResponse,
+ });
+ if (result.ReceiptResponse.HasFailed())
+ {
+ return new ProcessCommandResponse(receiptResponse, new List());
+ }
+
+ queue.StopMoment = DateTime.UtcNow;
+ await _configurationRepository.InsertOrUpdateQueueAsync(queue);
+
+ var signatureItem = SignaturItemFactory.CreateOutOfOperationSignature(queueIt);
+ var actionJournal = ftActionJournalFactory.CreateOutOfOperationActionJournal(queue, queueItem, queueIt, receiptRequest);
+ var signatures = new List
+ {
+ signatureItem
+ };
+ signatures.AddRange(result.ReceiptResponse.ftSignatures);
+ receiptResponse.ftSignatures = signatures.ToArray();
+ return new ProcessCommandResponse(receiptResponse, new List
+ {
+ actionJournal
+ });
+ }
+
+ public async Task InitSCUSwitch0x4011Async(ProcessCommandRequest request) => await Task.FromResult(new ProcessCommandResponse(request.ReceiptResponse, new List())).ConfigureAwait(false);
+
+ public async Task FinishSCUSwitch0x4012Async(ProcessCommandRequest request) => await Task.FromResult(new ProcessCommandResponse(request.ReceiptResponse, new List())).ConfigureAwait(false);
+ }
+}
\ No newline at end of file
diff --git a/queue/src/fiskaltrust.Middleware.Localization.QueueIT/v2/Models/ProcessCommandRequest.cs b/queue/src/fiskaltrust.Middleware.Localization.QueueIT/v2/Models/ProcessCommandRequest.cs
new file mode 100644
index 000000000..ef2fee048
--- /dev/null
+++ b/queue/src/fiskaltrust.Middleware.Localization.QueueIT/v2/Models/ProcessCommandRequest.cs
@@ -0,0 +1,12 @@
+using System;
+using System.Collections.Generic;
+using System.Threading.Tasks;
+using fiskaltrust.ifPOS.v1;
+using fiskaltrust.storage.V0;
+
+#pragma warning disable
+
+namespace fiskaltrust.Middleware.Localization.QueueIT.v2
+{
+ public record ProcessCommandRequest(ftQueue Queue, ftQueueIT QueueIt, ReceiptRequest ReceiptRequest, ReceiptResponse ReceiptResponse, ftQueueItem QueueItem);
+}
diff --git a/queue/src/fiskaltrust.Middleware.Localization.QueueIT/v2/Models/ProcessCommandResponse.cs b/queue/src/fiskaltrust.Middleware.Localization.QueueIT/v2/Models/ProcessCommandResponse.cs
new file mode 100644
index 000000000..01203a4b2
--- /dev/null
+++ b/queue/src/fiskaltrust.Middleware.Localization.QueueIT/v2/Models/ProcessCommandResponse.cs
@@ -0,0 +1,10 @@
+using System.Collections.Generic;
+using fiskaltrust.ifPOS.v1;
+using fiskaltrust.storage.V0;
+
+#pragma warning disable
+
+namespace fiskaltrust.Middleware.Localization.QueueIT.v2
+{
+ public record ProcessCommandResponse(ReceiptResponse receiptResponse, List actionJournals);
+}
diff --git a/queue/src/fiskaltrust.Middleware.Localization.QueueIT/v2/ProtocolCommandProcessorIT.cs b/queue/src/fiskaltrust.Middleware.Localization.QueueIT/v2/ProtocolCommandProcessorIT.cs
new file mode 100644
index 000000000..e595ed613
--- /dev/null
+++ b/queue/src/fiskaltrust.Middleware.Localization.QueueIT/v2/ProtocolCommandProcessorIT.cs
@@ -0,0 +1,132 @@
+using System;
+using System.Collections.Generic;
+using System.Threading.Tasks;
+using fiskaltrust.ifPOS.v1;
+using fiskaltrust.ifPOS.v1.it;
+using fiskaltrust.Middleware.Contracts.Repositories;
+using fiskaltrust.Middleware.Localization.QueueIT.Constants;
+using fiskaltrust.Middleware.Localization.QueueIT.Helpers;
+using fiskaltrust.storage.V0;
+using Microsoft.Extensions.Logging;
+using Newtonsoft.Json;
+
+#pragma warning disable
+
+namespace fiskaltrust.Middleware.Localization.QueueIT.v2
+{
+ public class ProtocolCommandProcessorIT
+ {
+ private readonly IITSSCDProvider _itSSCDProvider;
+ private readonly IJournalITRepository _journalITRepository;
+ private readonly IMiddlewareQueueItemRepository _queueItemRepository;
+ private readonly ILogger _logger;
+
+ public ProtocolCommandProcessorIT(IITSSCDProvider itSSCDProvider, IJournalITRepository journalITRepository, IMiddlewareQueueItemRepository queueItemRepository, ILogger logger)
+ {
+ _itSSCDProvider = itSSCDProvider;
+ _journalITRepository = journalITRepository;
+ _queueItemRepository = queueItemRepository;
+ _logger = logger;
+ }
+
+ public async Task ProcessReceiptAsync(ProcessCommandRequest request)
+ {
+ var receiptCase = (request.ReceiptRequest.ftReceiptCase & 0xFFFF);
+ if (receiptCase == (int) ReceiptCases.ProtocolUnspecified0x3000)
+ return await ProtocolUnspecified0x3000Async(request);
+
+ if (receiptCase == (int) ReceiptCases.ProtocolTechnicalEvent0x3001)
+ return await ProtocolTechnicalEvent0x3001Async(request);
+
+ if (receiptCase == (int) ReceiptCases.ProtocolAccountingEvent0x3002)
+ return await ProtocolAccountingEvent0x3002Async(request);
+
+ if (receiptCase == (int) ReceiptCases.InternalUsageMaterialConsumption0x3003)
+ return await InternalUsageMaterialConsumption0x3003Async(request);
+
+ if (receiptCase == (int) ReceiptCases.Order0x3004)
+ return await Order0x3004Async(request);
+
+ if (receiptCase == (int) ReceiptCases.CopyReceiptPrintExistingReceipt0x3010)
+ return await CopyReceiptPrintExistingReceipt0x3010Async(request);
+
+ request.ReceiptResponse.SetReceiptResponseError($"The given ftReceiptCase 0x{request.ReceiptRequest.ftReceiptCase:x} is not supported. Please refer to docs.fiskaltrust.cloud for supported cases.");
+ return new ProcessCommandResponse(request.ReceiptResponse, new List());
+ }
+
+ public async Task ProtocolUnspecified0x3000Async(ProcessCommandRequest request) => await Task.FromResult(new ProcessCommandResponse(request.ReceiptResponse, new List())).ConfigureAwait(false);
+
+ public async Task ProtocolTechnicalEvent0x3001Async(ProcessCommandRequest request) => await Task.FromResult(new ProcessCommandResponse(request.ReceiptResponse, new List())).ConfigureAwait(false);
+
+ public async Task ProtocolAccountingEvent0x3002Async(ProcessCommandRequest request) => await Task.FromResult(new ProcessCommandResponse(request.ReceiptResponse, new List())).ConfigureAwait(false);
+
+ public async Task InternalUsageMaterialConsumption0x3003Async(ProcessCommandRequest request) => await Task.FromResult(new ProcessCommandResponse(request.ReceiptResponse, new List())).ConfigureAwait(false);
+
+ public async Task Order0x3004Async(ProcessCommandRequest request) => await Task.FromResult(new ProcessCommandResponse(request.ReceiptResponse, new List())).ConfigureAwait(false);
+
+ public async Task CopyReceiptPrintExistingReceipt0x3010Async(ProcessCommandRequest request)
+ {
+ var (queue, queueIT, receiptRequest, receiptResponse, queueItem) = request;
+ await LoadReceiptReferencesToResponse(receiptRequest, queueItem, receiptResponse);
+ try
+ {
+ var result = await _itSSCDProvider.ProcessReceiptAsync(new ProcessRequest
+ {
+ ReceiptRequest = receiptRequest,
+ ReceiptResponse = receiptResponse
+ });
+ if (result.ReceiptResponse.HasFailed())
+ {
+ return new ProcessCommandResponse(result.ReceiptResponse, new List());
+ }
+ return new ProcessCommandResponse(result.ReceiptResponse, new List());
+ }
+ catch (Exception ex)
+ {
+ receiptResponse.SetReceiptResponseError(ex.Message);
+ return new ProcessCommandResponse(receiptResponse, new List());
+ }
+ }
+
+ private async Task LoadReceiptReferencesToResponse(ReceiptRequest request, ftQueueItem queueItem, ReceiptResponse receiptResponse)
+ {
+ var queueItems = _queueItemRepository.GetByReceiptReferenceAsync(request.cbPreviousReceiptReference, request.cbTerminalID);
+ await foreach (var existingQueueItem in queueItems)
+ {
+ var referencedResponse = JsonConvert.DeserializeObject(existingQueueItem.response);
+ var documentNumber = referencedResponse.GetSignaturItem(SignatureTypesIT.RTDocumentNumber).Data;
+ var zNumber = referencedResponse.GetSignaturItem(SignatureTypesIT.RTZNumber).Data;
+ var documentMoment = referencedResponse.GetSignaturItem(SignatureTypesIT.RTDocumentMoment)?.Data;
+ documentMoment ??= queueItem.cbReceiptMoment.ToString("yyyy-MM-dd");
+ var signatures = new List();
+ signatures.AddRange(receiptResponse.ftSignatures);
+ signatures.AddRange(new List
+ {
+ new SignaturItem
+ {
+ Caption = "",
+ Data = zNumber.ToString(),
+ ftSignatureFormat = (long) SignaturItem.Formats.Text,
+ ftSignatureType = Cases.BASE_STATE | (long) SignatureTypesIT.RTReferenceZNumber
+ },
+ new SignaturItem
+ {
+ Caption = "",
+ Data = documentNumber.ToString(),
+ ftSignatureFormat = (long) SignaturItem.Formats.Text,
+ ftSignatureType = Cases.BASE_STATE | (long) SignatureTypesIT.RTReferenceDocumentNumber
+ },
+ new SignaturItem
+ {
+ Caption = "",
+ Data = documentMoment,
+ ftSignatureFormat = (long) SignaturItem.Formats.Text,
+ ftSignatureType = Cases.BASE_STATE | (long) SignatureTypesIT.RTReferenceDocumentMoment
+ },
+ });
+ receiptResponse.ftSignatures = signatures.ToArray();
+ break;
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/queue/src/fiskaltrust.Middleware.Localization.QueueIT/v2/ReceiptCommandProcessorIT.cs b/queue/src/fiskaltrust.Middleware.Localization.QueueIT/v2/ReceiptCommandProcessorIT.cs
new file mode 100644
index 000000000..690111cda
--- /dev/null
+++ b/queue/src/fiskaltrust.Middleware.Localization.QueueIT/v2/ReceiptCommandProcessorIT.cs
@@ -0,0 +1,142 @@
+using System.Collections.Generic;
+using System.Threading.Tasks;
+using fiskaltrust.ifPOS.v1;
+using fiskaltrust.ifPOS.v1.it;
+using fiskaltrust.Middleware.Contracts.Repositories;
+using fiskaltrust.Middleware.Localization.QueueIT.Constants;
+using fiskaltrust.Middleware.Localization.QueueIT.Extensions;
+using fiskaltrust.Middleware.Localization.QueueIT.Factories;
+using fiskaltrust.Middleware.Localization.QueueIT.Helpers;
+using fiskaltrust.Middleware.Localization.QueueIT.Models;
+using fiskaltrust.storage.V0;
+using Newtonsoft.Json;
+
+#pragma warning disable
+
+namespace fiskaltrust.Middleware.Localization.QueueIT.v2
+{
+ public class ReceiptCommandProcessorIT
+ {
+ private readonly IITSSCDProvider _itSSCDProvider;
+ private readonly IJournalITRepository _journalITRepository;
+ private readonly IMiddlewareQueueItemRepository _queueItemRepository;
+
+ public ReceiptCommandProcessorIT(IITSSCDProvider itSSCDProvider, IJournalITRepository journalITRepository, IMiddlewareQueueItemRepository queueItemRepository)
+ {
+ _itSSCDProvider = itSSCDProvider;
+ _journalITRepository = journalITRepository;
+ _queueItemRepository = queueItemRepository;
+ }
+
+ public async Task ProcessReceiptAsync(ProcessCommandRequest request)
+ {
+ var receiptCase = (request.ReceiptRequest.ftReceiptCase & 0xFFFF);
+ if (receiptCase == (int) ReceiptCases.UnknownReceipt0x0000)
+ return await UnknownReceipt0x0000Async(request);
+
+ if (receiptCase == (int) ReceiptCases.PointOfSaleReceipt0x0001)
+ return await PointOfSaleReceipt0x0001Async(request);
+
+ if (receiptCase == (int) ReceiptCases.PaymentTransfer0x0002)
+ return await PaymentTransfer0x0002Async(request);
+
+ if (receiptCase == (int) ReceiptCases.PointOfSaleReceiptWithoutObligation0x0003)
+ return await PointOfSaleReceiptWithoutObligation0x0003Async(request);
+
+ if (receiptCase == (int) ReceiptCases.ECommerce0x0004)
+ return await ECommerce0x0004Async(request);
+
+ if (receiptCase == (int) ReceiptCases.Protocol0x0005)
+ return await Protocol0x0005Async(request);
+
+ request.ReceiptResponse.SetReceiptResponseError($"The given ftReceiptCase 0x{request.ReceiptRequest.ftReceiptCase:x} is not supported. Please refer to docs.fiskaltrust.cloud for supported cases.");
+ return new ProcessCommandResponse(request.ReceiptResponse, new List());
+ }
+
+ public async Task UnknownReceipt0x0000Async(ProcessCommandRequest request) => await PointOfSaleReceipt0x0001Async(request);
+
+ public async Task PointOfSaleReceipt0x0001Async(ProcessCommandRequest request)
+ {
+ if (request.ReceiptRequest.IsVoid() || request.ReceiptRequest.IsRefund())
+ {
+ await LoadReceiptReferencesToResponse(request.ReceiptRequest, request.QueueItem, request.ReceiptResponse);
+ }
+
+ var (queue, queueIt, receiptRequest, receiptResponse, queueItem) = request;
+
+ var result = await _itSSCDProvider.ProcessReceiptAsync(new ProcessRequest
+ {
+ ReceiptRequest = receiptRequest,
+ ReceiptResponse = receiptResponse,
+ });
+ if (result.ReceiptResponse.HasFailed())
+ {
+ return new ProcessCommandResponse(result.ReceiptResponse, new List());
+ }
+
+ var documentNumber = result.ReceiptResponse.GetSignaturItem(SignatureTypesIT.RTDocumentNumber);
+ var zNumber = result.ReceiptResponse.GetSignaturItem(SignatureTypesIT.RTZNumber);
+ receiptResponse.ftReceiptIdentification += $"{zNumber.Data.PadLeft(4, '0')}-{documentNumber.Data.PadLeft(4, '0')}";
+ receiptResponse.ftSignatures = result.ReceiptResponse.ftSignatures;
+ receiptResponse.InsertSignatureItems(SignaturItemFactory.CreatePOSReceiptFormatSignatures(receiptResponse));
+ var journalIT = ftJournalITFactory.CreateFrom(queueItem, queueIt, new ScuResponse()
+ {
+ ftReceiptCase = receiptRequest.ftReceiptCase,
+ ReceiptNumber = long.Parse(documentNumber.Data),
+ ZRepNumber = long.Parse(zNumber.Data)
+ });
+ await _journalITRepository.InsertAsync(journalIT).ConfigureAwait(false);
+ return new ProcessCommandResponse(receiptResponse, new List());
+ }
+
+ public async Task PaymentTransfer0x0002Async(ProcessCommandRequest request) => await Task.FromResult(new ProcessCommandResponse(request.ReceiptResponse, new List())).ConfigureAwait(false);
+
+ public async Task PointOfSaleReceiptWithoutObligation0x0003Async(ProcessCommandRequest request) => await Task.FromResult(new ProcessCommandResponse(request.ReceiptResponse, new List())).ConfigureAwait(false);
+
+ public async Task ECommerce0x0004Async(ProcessCommandRequest request) => await Task.FromResult(new ProcessCommandResponse(request.ReceiptResponse, new List())).ConfigureAwait(false);
+
+ public async Task Protocol0x0005Async(ProcessCommandRequest request) => await PointOfSaleReceipt0x0001Async(request);
+
+ private async Task LoadReceiptReferencesToResponse(ReceiptRequest request, ftQueueItem queueItem, ReceiptResponse receiptResponse)
+ {
+ var queueItems = _queueItemRepository.GetByReceiptReferenceAsync(request.cbPreviousReceiptReference, request.cbTerminalID);
+ // What should we do in this case? Cannot really proceed with the storno but we
+ await foreach (var existingQueueItem in queueItems)
+ {
+ var referencedResponse = JsonConvert.DeserializeObject(existingQueueItem.response);
+ var documentNumber = referencedResponse.GetSignaturItem(SignatureTypesIT.RTDocumentNumber).Data;
+ var zNumber = referencedResponse.GetSignaturItem(SignatureTypesIT.RTZNumber).Data;
+ var documentMoment = referencedResponse.GetSignaturItem(SignatureTypesIT.RTDocumentMoment)?.Data;
+ documentMoment ??= queueItem.cbReceiptMoment.ToString("yyyy-MM-dd");
+ var signatures = new List();
+ signatures.AddRange(receiptResponse.ftSignatures);
+ signatures.AddRange(new List
+ {
+ new SignaturItem
+ {
+ Caption = "",
+ Data = zNumber.ToString(),
+ ftSignatureFormat = (long) SignaturItem.Formats.Text,
+ ftSignatureType = Cases.BASE_STATE | (long) SignatureTypesIT.RTReferenceZNumber
+ },
+ new SignaturItem
+ {
+ Caption = "",
+ Data = documentNumber.ToString(),
+ ftSignatureFormat = (long) SignaturItem.Formats.Text,
+ ftSignatureType = Cases.BASE_STATE | (long) SignatureTypesIT.RTReferenceDocumentNumber
+ },
+ new SignaturItem
+ {
+ Caption = "",
+ Data = documentMoment,
+ ftSignatureFormat = (long) SignaturItem.Formats.Text,
+ ftSignatureType = Cases.BASE_STATE | (long) SignatureTypesIT.RTReferenceDocumentMoment
+ },
+ });
+ receiptResponse.ftSignatures = signatures.ToArray();
+ break;
+ }
+ }
+ }
+}
diff --git a/queue/src/fiskaltrust.Middleware.Localization.QueueIT/v2/Tagging/ITReceiptCases.cs b/queue/src/fiskaltrust.Middleware.Localization.QueueIT/v2/Tagging/ITReceiptCases.cs
new file mode 100644
index 000000000..83da13716
--- /dev/null
+++ b/queue/src/fiskaltrust.Middleware.Localization.QueueIT/v2/Tagging/ITReceiptCases.cs
@@ -0,0 +1,36 @@
+namespace fiskaltrust.Middleware.Localization.QueueIT.v2
+{
+ public enum ReceiptCases : long
+ {
+ UnknownReceipt0x0000 = 0x0000,
+ PointOfSaleReceipt0x0001 = 0x0001,
+ PaymentTransfer0x0002 = 0x0002,
+ PointOfSaleReceiptWithoutObligation0x0003 = 0x0003,
+ ECommerce0x0004 = 0x0004,
+ Protocol0x0005 = 0x0005,
+
+ InvoiceUnknown0x1000 = 0x1000,
+ InvoiceB2C0x1001 = 0x1001,
+ InvoiceB2B0x1002 = 0x1002,
+ InvoiceB2G0x1003 = 0x1003,
+
+ ZeroReceipt0x2000 = 0x2000,
+ OneReceipt0x2001 = 0x2001,
+ ShiftClosing0x2010 = 0x2010,
+ DailyClosing0x2011 = 0x2011,
+ MonthlyClosing0x2012 = 0x2012,
+ YearlyClosing0x2013 = 0x2013,
+
+ ProtocolUnspecified0x3000 = 0x3000,
+ ProtocolTechnicalEvent0x3001 = 0x3001,
+ ProtocolAccountingEvent0x3002 = 0x3002,
+ InternalUsageMaterialConsumption0x3003 = 0x3003,
+ Order0x3004 = 0x3004,
+ CopyReceiptPrintExistingReceipt0x3010 = 0x3010,
+
+ InitialOperationReceipt0x4001 = 0x4001,
+ OutOfOperationReceipt0x4002 = 0x4002,
+ InitSCUSwitch0x4011 = 0x4011,
+ FinishSCUSwitch0x4012 = 0x4012,
+ }
+}
\ No newline at end of file
diff --git a/queue/src/fiskaltrust.Middleware.Localization.QueueIT/v2/Tagging/ftStatesFlags.cs b/queue/src/fiskaltrust.Middleware.Localization.QueueIT/v2/Tagging/ftStatesFlags.cs
new file mode 100644
index 000000000..703bd7b36
--- /dev/null
+++ b/queue/src/fiskaltrust.Middleware.Localization.QueueIT/v2/Tagging/ftStatesFlags.cs
@@ -0,0 +1,19 @@
+namespace fiskaltrust.Middleware.Localization.QueueIT.Constants
+{
+ public static class ftStatesFlags
+ {
+ public const long SECURITY_MECHAMISN_DEACTIVATED = 0x0000_0000_0000_0001;
+
+ public const long SCU_TEMPORARY_OUT_OF_SERVICE = 0x0000_0000_0000_0002;
+
+ public const long LATESIGNINGMODE_ISACTIVE = 0x0000_0000_0000_0008;
+
+ public const long MESSAGE_IS_PENDING = 0x0000_0000_0000_0040;
+
+ public const long DAILY_CLOSING_IS_DUE = 0x0000_0000_0000_0100;
+
+ public const long ERROR = 0x0000_0000_EEEE_EEEE;
+
+ public const long FAIIL = 0x0000_0000_FFFF_FFFF;
+ }
+}
\ No newline at end of file
diff --git a/queue/src/fiskaltrust.Middleware.Queue.AzureTableStorage/version.json b/queue/src/fiskaltrust.Middleware.Queue.AzureTableStorage/version.json
index 5b52c5c85..6b2ce375c 100644
--- a/queue/src/fiskaltrust.Middleware.Queue.AzureTableStorage/version.json
+++ b/queue/src/fiskaltrust.Middleware.Queue.AzureTableStorage/version.json
@@ -1,5 +1,5 @@
{
- "version": "1.3.49",
+ "version": "1.3.50-rc1",
"releaseBranches": [
"^refs/tags/queue/azuretablestorage/v\\d+(?:\\.\\d+)*(?:-.*)?$"
]
diff --git a/queue/src/fiskaltrust.Middleware.Queue.EF/version.json b/queue/src/fiskaltrust.Middleware.Queue.EF/version.json
index dcc6ca445..bac787247 100644
--- a/queue/src/fiskaltrust.Middleware.Queue.EF/version.json
+++ b/queue/src/fiskaltrust.Middleware.Queue.EF/version.json
@@ -1,5 +1,5 @@
{
- "version": "1.3.49",
+ "version": "1.3.50-rc1",
"releaseBranches": [
"^refs/tags/queue/ef/v\\d+(?:\\.\\d+)*(?:-.*)?$"
]
diff --git a/queue/src/fiskaltrust.Middleware.Queue.InMemory/version.json b/queue/src/fiskaltrust.Middleware.Queue.InMemory/version.json
index 80184f6a3..03c3e3d7d 100644
--- a/queue/src/fiskaltrust.Middleware.Queue.InMemory/version.json
+++ b/queue/src/fiskaltrust.Middleware.Queue.InMemory/version.json
@@ -1,5 +1,5 @@
{
- "version": "1.3.49",
+ "version": "1.3.50-rc1",
"releaseBranches": [
"^refs/tags/queue/inmemory/v\\d+(?:\\.\\d+)*(?:-.*)?$"
]
diff --git a/queue/src/fiskaltrust.Middleware.Queue.MySQL/version.json b/queue/src/fiskaltrust.Middleware.Queue.MySQL/version.json
index e3a253e60..7780c640e 100644
--- a/queue/src/fiskaltrust.Middleware.Queue.MySQL/version.json
+++ b/queue/src/fiskaltrust.Middleware.Queue.MySQL/version.json
@@ -1,5 +1,5 @@
{
- "version": "1.3.49",
+ "version": "1.3.50-rc1",
"releaseBranches": [
"^refs/tags/queue/mysql/v\\d+(?:\\.\\d+)*(?:-.*)?$"
]
diff --git a/queue/src/fiskaltrust.Middleware.Queue.PostgreSQL/version.json b/queue/src/fiskaltrust.Middleware.Queue.PostgreSQL/version.json
index 571a678ff..adbee9504 100644
--- a/queue/src/fiskaltrust.Middleware.Queue.PostgreSQL/version.json
+++ b/queue/src/fiskaltrust.Middleware.Queue.PostgreSQL/version.json
@@ -1,5 +1,5 @@
{
- "version": "1.3.49",
+ "version": "1.3.50-rc1",
"releaseBranches": [
"^refs/tags/queue/postgresql/v\\d+(?:\\.\\d+)*(?:-.*)?$"
]
diff --git a/queue/src/fiskaltrust.Middleware.Queue.SQLite/.nuspec b/queue/src/fiskaltrust.Middleware.Queue.SQLite/.nuspec
index a924d2f16..c3efb67d4 100644
--- a/queue/src/fiskaltrust.Middleware.Queue.SQLite/.nuspec
+++ b/queue/src/fiskaltrust.Middleware.Queue.SQLite/.nuspec
@@ -19,7 +19,7 @@
-
+
diff --git a/queue/src/fiskaltrust.Middleware.Queue.SQLite/version.json b/queue/src/fiskaltrust.Middleware.Queue.SQLite/version.json
index 7cdf36b5f..8f85e51b4 100644
--- a/queue/src/fiskaltrust.Middleware.Queue.SQLite/version.json
+++ b/queue/src/fiskaltrust.Middleware.Queue.SQLite/version.json
@@ -1,5 +1,5 @@
{
- "version": "1.3.49",
+ "version": "1.3.50-rc1",
"releaseBranches": [
"^refs/tags/queue/sqlite/v\\d+(?:\\.\\d+)*(?:-.*)?$"
]
diff --git a/queue/src/fiskaltrust.Middleware.Queue/SignProcessor.cs b/queue/src/fiskaltrust.Middleware.Queue/SignProcessor.cs
index 03477893c..3cc6399f3 100644
--- a/queue/src/fiskaltrust.Middleware.Queue/SignProcessor.cs
+++ b/queue/src/fiskaltrust.Middleware.Queue/SignProcessor.cs
@@ -169,9 +169,21 @@ private async Task InternalSign(ftQueue queue, ReceiptRequest d
await _queueItemRepository.InsertOrUpdateAsync(queueItem).ConfigureAwait(false);
_logger.LogTrace("SignProcessor.InternalSign: Updating Queue in database.");
await _configurationRepository.InsertOrUpdateQueueAsync(queue).ConfigureAwait(false);
- _logger.LogTrace("SignProcessor.InternalSign: Adding ReceiptJournal to database.");
- receiptJournal = await CreateReceiptJournalAsync(queue, queueItem, data).ConfigureAwait(false);
+ if ((receiptResponse.ftState & 0xFFFF_FFFF) == 0xEEEE_EEEE)
+ {
+ // TODO: This state indicates that something went wrong while processing the receipt request.
+ // While we will probably introduce a parameter for this we are right now just returning
+ // the receipt response as it is.
+ // Another thing that needs to be considered is if and when we put things into the security
+ // mechanism. Since there might be cases where we still need to store it though.
+ return receiptResponse;
+ }
+ else
+ {
+ _logger.LogTrace("SignProcessor.InternalSign: Adding ReceiptJournal to database.");
+ receiptJournal = await CreateReceiptJournalAsync(queue, queueItem, data).ConfigureAwait(false);
+ }
return receiptResponse;
}
finally
diff --git a/queue/src/fiskaltrust.Middleware.Storage.Base/BaseStorageBootStrapper.cs b/queue/src/fiskaltrust.Middleware.Storage.Base/BaseStorageBootStrapper.cs
index 53ef7d470..3c2fb0af5 100644
--- a/queue/src/fiskaltrust.Middleware.Storage.Base/BaseStorageBootStrapper.cs
+++ b/queue/src/fiskaltrust.Middleware.Storage.Base/BaseStorageBootStrapper.cs
@@ -113,7 +113,7 @@ public async Task PersistConfigurationAsync(StorageBaseInitConfiguration config,
await InitSignaturCreationUnitFRAsync(config.SignaturCreationUnitsFR, configurationRepository).ConfigureAwait(false);
await InitSignaturCreationUnitDEAsync(config.SignaturCreationUnitsDE, configurationRepository, enforceUpdateUserDefinedConfig).ConfigureAwait(false);
await InitSignaturCreationUnitMEAsync(config.SignaturCreationUnitsME, configurationRepository).ConfigureAwait(false);
- await InitSignaturCreationUnitITAsync(config.SignaturCreationUnitsIT, configurationRepository).ConfigureAwait(false);
+ await InitSignaturCreationUnitITAsync(config.SignaturCreationUnitsIT, configurationRepository, enforceUpdateUserDefinedConfig).ConfigureAwait(false);
}
private T ParseParameter(Dictionary config, string key) where T : new()
@@ -405,15 +405,30 @@ private async Task InitSignaturCreationUnitMEAsync(List signaturCreationUnitsIT, IConfigurationRepository configurationRepository)
+ private async Task InitSignaturCreationUnitITAsync(List signaturCreationUnitsIT, IConfigurationRepository configurationRepository, bool enforceUpdateUserDefinedConfig)
{
foreach (var item in signaturCreationUnitsIT)
{
- var scu = await configurationRepository.GetSignaturCreationUnitITAsync(item.ftSignaturCreationUnitITId).ConfigureAwait(false);
- if (scu == null)
+ var db_scu = await configurationRepository.GetSignaturCreationUnitITAsync(item.ftSignaturCreationUnitITId).ConfigureAwait(false);
+ if (db_scu == null)
{
await configurationRepository.InsertOrUpdateSignaturCreationUnitITAsync(item).ConfigureAwait(false);
}
+ else if (db_scu.TimeStamp < item.TimeStamp || enforceUpdateUserDefinedConfig)
+ {
+ var changed = false;
+ if (!string.IsNullOrEmpty(item.Url) && db_scu.Url != item.Url)
+ {
+ changed = true;
+ db_scu.Url = item.Url;
+ }
+
+ if (changed)
+ {
+ db_scu.TimeStamp = item.TimeStamp;
+ await configurationRepository.InsertOrUpdateSignaturCreationUnitITAsync(db_scu).ConfigureAwait(false);
+ }
+ }
}
}
}
diff --git a/queue/test/Directory.Build.props b/queue/test/Directory.Build.props
index 1f5b36f51..1441fbeab 100644
--- a/queue/test/Directory.Build.props
+++ b/queue/test/Directory.Build.props
@@ -1,20 +1,24 @@
-
-
-
-
-
-
-
-
-
-
- all
- runtime; build; native; contentfiles; analyzers
-
-
-
-
+
+ NU1901;NU1902;NU1903;NU1904
+
+
+
+
+
+
+
+
+
+
+
+
+ all
+ runtime; build; native; contentfiles; analyzers
+
+
+
+
diff --git a/queue/test/Manual/fiskaltrust.Middleware.Queue.Test.Launcher/fiskaltrust.Middleware.Queue.Test.Launcher.csproj b/queue/test/Manual/fiskaltrust.Middleware.Queue.Test.Launcher/fiskaltrust.Middleware.Queue.Test.Launcher.csproj
index 7d13d6b26..ad2c224ba 100644
--- a/queue/test/Manual/fiskaltrust.Middleware.Queue.Test.Launcher/fiskaltrust.Middleware.Queue.Test.Launcher.csproj
+++ b/queue/test/Manual/fiskaltrust.Middleware.Queue.Test.Launcher/fiskaltrust.Middleware.Queue.Test.Launcher.csproj
@@ -13,9 +13,9 @@
-
-
-
+
+
+
diff --git a/queue/test/fiskaltrust.Middleware.Localization.QueueIT.UnitTest/Extensions.cs b/queue/test/fiskaltrust.Middleware.Localization.QueueIT.UnitTest/Extensions.cs
deleted file mode 100644
index 6d9ee4bec..000000000
--- a/queue/test/fiskaltrust.Middleware.Localization.QueueIT.UnitTest/Extensions.cs
+++ /dev/null
@@ -1,60 +0,0 @@
-using System;
-using System.Collections.Generic;
-using Microsoft.Extensions.DependencyInjection;
-using Microsoft.Extensions.Logging;
-
-namespace fiskaltrust.Middleware.Localization.QueueIT.UnitTest
-{
- public static class Extensions
- {
- public static void SetGlobalLogger(LogLevel verbosity = LogLevel.Debug)
- {
- var configuration = new Serilog.LoggerConfiguration()
- .Enrich.FromLogContext();
- switch (verbosity)
- {
- case LogLevel.Trace:
- configuration = configuration.MinimumLevel.Verbose();
- break;
- case LogLevel.Debug:
- configuration = configuration.MinimumLevel.Debug();
- break;
- case LogLevel.Information:
- configuration = configuration.MinimumLevel.Information();
- break;
- case LogLevel.Warning:
- configuration = configuration.MinimumLevel.Warning();
- break;
- case LogLevel.Error:
- configuration = configuration.MinimumLevel.Error();
- break;
- case LogLevel.Critical:
- configuration = configuration.MinimumLevel.Fatal();
- break;
- case LogLevel.None:
- break;
- default:
- configuration = configuration.MinimumLevel.Information();
- break;
- }
- }
-
- public static IServiceCollection AddStandardLoggers(this IServiceCollection services, LogLevel verbosity)
- {
- SetGlobalLogger(verbosity);
-
- services.AddLogging(builder => builder.SetMinimumLevel(verbosity));
- return services;
- }
-
- public static IEnumerable Flatten(this Exception exception)
- {
- yield return exception;
- while (exception.InnerException != null)
- {
- yield return exception.InnerException;
- exception = exception.InnerException;
- }
- }
- }
-}
diff --git a/queue/test/fiskaltrust.Middleware.Localization.QueueIT.UnitTest/InMemoryTestScu.cs b/queue/test/fiskaltrust.Middleware.Localization.QueueIT.UnitTest/InMemoryTestScu.cs
deleted file mode 100644
index 0fa86c3f1..000000000
--- a/queue/test/fiskaltrust.Middleware.Localization.QueueIT.UnitTest/InMemoryTestScu.cs
+++ /dev/null
@@ -1,27 +0,0 @@
-using System;
-using System.Threading.Tasks;
-using fiskaltrust.ifPOS.v1.it;
-
-namespace fiskaltrust.Middleware.Localization.QueueIT.UnitTest
-{
- internal class InMemoryTestScu : IITSSCD
- {
- public Task EchoAsync(ScuItEchoRequest request) => throw new NotImplementedException();
- public Task ExecuteDailyClosingAsync(DailyClosingRequest request) => throw new NotImplementedException();
-
- public Task FiscalReceiptInvoiceAsync(FiscalReceiptInvoice request)
- {
- return Task.FromResult(new FiscalReceiptResponse()
- {
- Amount = 9909.98m,
- ReceiptNumber = 245,
- ReceiptDateTime = new DateTime(1999, 1, 1, 0, 0, 1),
- Success = true,
-
- });
- }
- public Task FiscalReceiptRefundAsync(FiscalReceiptRefund request) => throw new NotImplementedException();
- public Task GetDeviceInfoAsync() => throw new NotImplementedException();
- public Task NonFiscalReceiptAsync(NonFiscalRequest request) => throw new NotImplementedException();
- }
-}
diff --git a/queue/test/fiskaltrust.Middleware.Localization.QueueIT.UnitTest/POSReceiptSignatureData.cs b/queue/test/fiskaltrust.Middleware.Localization.QueueIT.UnitTest/POSReceiptSignatureData.cs
new file mode 100644
index 000000000..e9a7a451b
--- /dev/null
+++ b/queue/test/fiskaltrust.Middleware.Localization.QueueIT.UnitTest/POSReceiptSignatureData.cs
@@ -0,0 +1,124 @@
+using System;
+using System.Collections.Generic;
+using fiskaltrust.ifPOS.v1;
+using fiskaltrust.Middleware.Localization.QueueIT.Constants;
+
+namespace fiskaltrust.Middleware.Localization.QueueIT.UnitTest
+{
+ public class POSReceiptSignatureData
+ {
+ public string RTSerialNumber { get; set; } = string.Empty;
+ public long RTZNumber { get; set; }
+ public long RTDocNumber { get; set; }
+ public DateTime RTDocMoment { get; set; }
+ public string RTDocType { get; set; } = string.Empty;
+ public string RTCodiceLotteria { get; set; }
+ public string RTCustomerID { get; set; }
+ public string RTServerSHAMetadata { get; set; }
+
+ public long? RTReferenceZNumber { get; set; }
+ public long? RTReferenceDocNumber { get; set; }
+ public DateTime? RTReferenceDocMoment { get; set; }
+
+ public static List CreateDocumentoCommercialeSignatures(POSReceiptSignatureData data)
+ {
+ var signatureItems = new List()
+ {
+ new SignaturItem
+ {
+ Caption = "",
+ Data = data.RTSerialNumber,
+ ftSignatureFormat = (long) SignaturItem.Formats.Text,
+ ftSignatureType = Cases.BASE_STATE |(long) SignatureTypesIT.RTSerialNumber
+ },
+ new SignaturItem
+ {
+ Caption = "",
+ Data = data.RTZNumber.ToString().PadLeft(4, '0'),
+ ftSignatureFormat = (long) SignaturItem.Formats.Text,
+ ftSignatureType = Cases.BASE_STATE | (long) SignatureTypesIT.RTZNumber
+ },
+ new SignaturItem
+ {
+ Caption = "",
+ Data = data.RTDocNumber.ToString().PadLeft(4, '0'),
+ ftSignatureFormat = (long) SignaturItem.Formats.Text,
+ ftSignatureType = Cases.BASE_STATE |(long) SignatureTypesIT.RTDocumentNumber
+ },
+ new SignaturItem
+ {
+ Caption = "",
+ Data = data.RTDocMoment.ToString("yyyy-MM-dd HH:mm:ss"),
+ ftSignatureFormat = (long) SignaturItem.Formats.Text,
+ ftSignatureType = Cases.BASE_STATE |(long) SignatureTypesIT.RTDocumentMoment
+ },
+ new SignaturItem
+ {
+ Caption = "",
+ Data = data.RTDocType, // TODO CoNVert
+ ftSignatureFormat = (long) SignaturItem.Formats.Text,
+ ftSignatureType = Cases.BASE_STATE |(long) SignatureTypesIT.RTDocumentType
+ }
+ };
+
+ if (!string.IsNullOrEmpty(data.RTServerSHAMetadata))
+ {
+ signatureItems.Add(new SignaturItem
+ {
+ Caption = "",
+ Data = data.RTServerSHAMetadata,
+ ftSignatureFormat = (long) SignaturItem.Formats.Text,
+ ftSignatureType = Cases.BASE_STATE | (long) SignatureTypesIT.RTServerShaMetadata
+ });
+ }
+
+ if (!string.IsNullOrEmpty(data.RTCodiceLotteria))
+ {
+ signatureItems.Add(new SignaturItem
+ {
+ Caption = "",
+ Data = data.RTCodiceLotteria,
+ ftSignatureFormat = (long) SignaturItem.Formats.Text,
+ ftSignatureType = Cases.BASE_STATE | (long) SignatureTypesIT.RTLotteryID
+ });
+ }
+
+ if (!string.IsNullOrEmpty(data.RTCustomerID))
+ {
+ signatureItems.Add(new SignaturItem
+ {
+ Caption = "",
+ Data = data.RTCustomerID,
+ ftSignatureFormat = (long) SignaturItem.Formats.Text,
+ ftSignatureType = Cases.BASE_STATE | (long) SignatureTypesIT.RTCustomerID
+ });
+ }
+
+ if (data.RTReferenceZNumber.HasValue && data.RTReferenceDocNumber.HasValue && data.RTReferenceDocMoment.HasValue) // TODO WE NEED TO CHECK THAT
+ {
+ signatureItems.Add(new SignaturItem
+ {
+ Caption = "",
+ Data = data.RTReferenceZNumber.Value.ToString().PadLeft(4, '0'),
+ ftSignatureFormat = (long) SignaturItem.Formats.Text,
+ ftSignatureType = Cases.BASE_STATE | (long) SignatureTypesIT.RTReferenceZNumber
+ });
+ signatureItems.Add(new SignaturItem
+ {
+ Caption = "",
+ Data = data.RTReferenceDocNumber.Value.ToString().PadLeft(4, '0'),
+ ftSignatureFormat = (long) SignaturItem.Formats.Text,
+ ftSignatureType = Cases.BASE_STATE | (long) SignatureTypesIT.RTReferenceDocumentNumber
+ });
+ signatureItems.Add(new SignaturItem
+ {
+ Caption = "",
+ Data = data.RTReferenceDocMoment.Value.ToString("yyyy-MM-dd"),
+ ftSignatureFormat = (long) SignaturItem.Formats.Text,
+ ftSignatureType = Cases.BASE_STATE | (long) SignatureTypesIT.RTReferenceDocumentMoment
+ });
+ }
+ return signatureItems;
+ }
+ }
+}
diff --git a/queue/test/fiskaltrust.Middleware.Localization.QueueIT.UnitTest/QueueITBootstrapperTests.cs b/queue/test/fiskaltrust.Middleware.Localization.QueueIT.UnitTest/QueueITBootstrapperTests.cs
new file mode 100644
index 000000000..8288d7fed
--- /dev/null
+++ b/queue/test/fiskaltrust.Middleware.Localization.QueueIT.UnitTest/QueueITBootstrapperTests.cs
@@ -0,0 +1,50 @@
+using Xunit;
+using Microsoft.Extensions.DependencyInjection;
+using fiskaltrust.Middleware.Contracts.Interfaces;
+using Moq;
+using fiskaltrust.storage.V0;
+using fiskaltrust.Middleware.Abstractions;
+using fiskaltrust.ifPOS.v1.it;
+using fiskaltrust.Middleware.Contracts.Models;
+using fiskaltrust.Middleware.Contracts.Repositories;
+
+namespace fiskaltrust.Middleware.Localization.QueueIT.UnitTest
+{
+
+
+ public class ReceiptTypeProcessorFactoryTests
+ {
+ [Fact]
+ public void CreateWithWrongReceiptCase_ShouldThrow()
+ {
+
+ }
+ }
+
+ public class QueueITBootstrapperTests
+ {
+ [Fact]
+ public void TryToConstructSignProcessorIT()
+ {
+ var serviceCollection = new ServiceCollection();
+ serviceCollection.AddLogging();
+ serviceCollection.AddSingleton(Mock.Of());
+ serviceCollection.AddSingleton(Mock.Of());
+ serviceCollection.AddSingleton(Mock.Of());
+ serviceCollection.AddSingleton(Mock.Of>());
+ serviceCollection.AddSingleton(new MiddlewareConfiguration
+ {
+ Configuration = new System.Collections.Generic.Dictionary
+ {
+ { "init_ftSignaturCreationUnitIT", "[{\"Url\":\"https://faker\"}]" }
+ }
+ });
+
+ var bootstrapper = new QueueITBootstrapper();
+ bootstrapper.ConfigureServices(serviceCollection);
+
+ serviceCollection.BuildServiceProvider().GetRequiredService();
+ }
+ }
+
+}
diff --git a/queue/test/fiskaltrust.Middleware.Localization.QueueIT.UnitTest/QueueITStateTests.cs b/queue/test/fiskaltrust.Middleware.Localization.QueueIT.UnitTest/QueueITStateTests.cs
new file mode 100644
index 000000000..b79a03592
--- /dev/null
+++ b/queue/test/fiskaltrust.Middleware.Localization.QueueIT.UnitTest/QueueITStateTests.cs
@@ -0,0 +1,164 @@
+using System;
+using System.Collections.Generic;
+using System.Threading.Tasks;
+using fiskaltrust.ifPOS.v1;
+using fiskaltrust.ifPOS.v1.it;
+using fiskaltrust.Middleware.Abstractions;
+using fiskaltrust.Middleware.Contracts.Interfaces;
+using fiskaltrust.Middleware.Contracts.Models;
+using fiskaltrust.Middleware.Contracts.Repositories;
+using fiskaltrust.Middleware.Localization.QueueIT.v2;
+using fiskaltrust.storage.V0;
+using FluentAssertions;
+using Microsoft.Extensions.DependencyInjection;
+using Moq;
+using Newtonsoft.Json;
+using Xunit;
+
+namespace fiskaltrust.Middleware.Localization.QueueIT.UnitTest
+{
+ public class QueueITStateTests
+ {
+ private static readonly Guid _queueID = new Guid();
+
+ private readonly ftQueue _queue = new ftQueue
+ {
+ ftQueueId = _queueID,
+ };
+
+ private readonly ftQueue _queueStarted = new ftQueue
+ {
+ ftQueueId = _queueID,
+ StartMoment = DateTime.UtcNow,
+ ftReceiptNumerator = 1
+ };
+
+ private readonly ftQueue _queueStopped = new ftQueue
+ {
+ ftQueueId = _queueID,
+ StartMoment = DateTime.UtcNow,
+ StopMoment = DateTime.UtcNow
+ };
+
+ private IMarketSpecificSignProcessor GetSUT()
+ {
+ var serviceCollection = new ServiceCollection();
+ serviceCollection.AddLogging();
+ serviceCollection.AddSingleton(Mock.Of(MockBehavior.Strict));
+ serviceCollection.AddSingleton(Mock.Of());
+ serviceCollection.AddSingleton(Mock.Of>(MockBehavior.Strict));
+ serviceCollection.AddSingleton(Mock.Of(MockBehavior.Strict));
+ serviceCollection.AddSingleton(new MiddlewareConfiguration());
+
+ var bootstrapper = new QueueITBootstrapper();
+ bootstrapper.ConfigureServices(serviceCollection);
+
+ return serviceCollection.BuildServiceProvider().GetRequiredService();
+ }
+
+ public static IEnumerable