Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,13 @@ codeunit 31118 "EET Management CZL"
EETEntryCZL.FieldError("Status");

PrepareEntryToSend(EETEntryCZL);
if not EETServiceManagementCZL.CheckEETEntry(EETEntryCZL) then begin
Comment thread
DavidHolusa marked this conversation as resolved.
Resolved
EETServiceManagementCZL.CopyErrorMessageToTemp(TempErrorMessage);
EETEntryCZL."Correction Allowed" := true;
EETEntryCZL.ChangeStatus(EETEntryCZL."Status"::Failure, EETServiceManagementCZL.GetResponseText(), TempErrorMessage);
exit;
end;

EETEntryCZL.ChangeStatus(EETEntryCZL."Status"::Sent);
if EETServiceManagementCZL.Send(EETEntryCZL) then begin
EETEntryCZL."Acknowledgement Code" := EETServiceManagementCZL.GetPOKControlCode();
Expand All @@ -74,6 +81,8 @@ codeunit 31118 "EET Management CZL"
end else begin
EETEntryCZL."Status" := EETEntryCZL."Status"::Failure;
EETEntryCZL."Failed Send Attempts" += 1;
// Correction permission is based on the latest failed registration attempt.
EETEntryCZL."Correction Allowed" := EETServiceManagementCZL.IsCorrectableFailure();
NewDescription := EETServiceManagementCZL.GetResponseText();
end;

Expand Down Expand Up @@ -112,8 +121,14 @@ codeunit 31118 "EET Management CZL"
EETEntryCZL.FieldError("Status");

PrepareEntryToSend(EETEntryCZL);
EETEntryCZL.ChangeStatus(EETEntryCZL."Status"::"Sent to Verification");
if not EETServiceManagementCZL.CheckEETEntry(EETEntryCZL) then begin
EETServiceManagementCZL.CopyErrorMessageToTemp(TempErrorMessage);
EETEntryCZL."Correction Allowed" := true;
EETEntryCZL.ChangeStatus(EETEntryCZL."Status"::Failure, EETServiceManagementCZL.GetResponseText(), TempErrorMessage);
exit;
end;

EETEntryCZL.ChangeStatus(EETEntryCZL."Status"::"Sent to Verification");
EETServiceManagementCZL.SetVerificationMode(true);
if EETServiceManagementCZL.Send(EETEntryCZL) then begin
EETEntryCZL."Status" := EETEntryCZL."Status"::Verified;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ codeunit 31116 "EET Service Management CZL"
ResponseContentErrorCode: Text;
VerificationMode: Boolean;
CommunicationFailed: Boolean;
SubmissionStarted: Boolean;
ResponseHeaderValid: Boolean;
EETNamespaceTxt: Label 'http://fs.gov.cz/eet/schema/v4', Locked = true;
SoapActionTxt: Label 'http://fs.gov.cz/eet/OdeslaniTrzby', Locked = true;
SoapNamespaceTxt: Label 'http://schemas.xmlsoap.org/soap/envelope/', Locked = true;
Expand Down Expand Up @@ -58,8 +60,6 @@ codeunit 31116 "EET Service Management CZL"
Initialize();

FindValidCertificate(EETEntryCZL.GetTaxpayerCertificateCode(), IsolatedCertificate);
if not CheckEETEntry(EETEntryCZL, IsolatedCertificate) then
Comment thread
DavidHolusa marked this conversation as resolved.
Resolved
Error('');

CreateXmlDocument(EETEntryCZL, RequestXmlDocument);
CreateSoapRequest(RequestXmlDocument, IsolatedCertificate, SoapXmlDocument);
Expand All @@ -78,8 +78,9 @@ codeunit 31116 "EET Service Management CZL"
Error('');
end;

local procedure CheckEETEntry(EETEntryCZL: Record "EET Entry CZL"; IsolatedCertificate: Record "Isolated Certificate"): Boolean
internal procedure CheckEETEntry(EETEntryCZL: Record "EET Entry CZL"): Boolean
var
IsolatedCertificate: Record "Isolated Certificate";
CertificateManagement: Codeunit "Certificate Management";
CertificateSimpleName: Text;
CertificateIssueErrorTxt: Label 'The certificate was issued to %1 but the Taxpayer ID of the EET entry is %2.', Comment = '%1=Taxpayer ID the certificate was issued to, %2=Taxpayer ID of EET Entry';
Expand All @@ -89,6 +90,7 @@ codeunit 31116 "EET Service Management CZL"
EmptyReceiptSerialNoTxt: Label 'Receipt Serial No. must not be empty.';
ReceiptSerialNoTooLongErr: Label 'Receipt Serial No. must not be longer than %1 characters. The EET service does not accept longer values.', Comment = '%1 = maximum number of characters';
begin
FindValidCertificate(EETEntryCZL.GetTaxpayerCertificateCode(), IsolatedCertificate);
Comment thread
DavidHolusa marked this conversation as resolved.
Resolved
Comment thread
DavidHolusa marked this conversation as resolved.
Resolved
CertificateSimpleName := CertificateManagement.GetCertSimpleName(IsolatedCertificate);
if EETEntryCZL."Taxpayer ID" <> CertificateSimpleName then
LogMessage(TempErrorMessage."Message Type"::Error, '',
Expand Down Expand Up @@ -293,6 +295,8 @@ codeunit 31116 "EET Service Management CZL"
Error(IncorrectUrlErr);
SOAPWSRequestManagementCZL.SetAction(SoapActionTxt);
SOAPWSRequestManagementCZL.SetTimeout(EETServiceSetupCZL."Limit Response Time");
// Once communication starts, a failure does not prove that the sale was not registered.
SubmissionStarted := true;
Comment thread
DavidHolusa marked this conversation as resolved.
Resolved
IsOk := SOAPWSRequestManagementCZL.SendRequestToWebService(EETServiceSetupCZL."Service URL", RequestContentXmlDocument);
GlobalHttpRequestMessage := SOAPWSRequestManagementCZL.GetHttpRequestMessage();
GlobalHttpResponseMessage := SOAPWSRequestManagementCZL.GetHttpResponseMessage();
Expand Down Expand Up @@ -333,7 +337,7 @@ codeunit 31116 "EET Service Management CZL"

ResponseContentError := ErrorXmlNode.AsXmlElement().InnerXml();
ResponseContentErrorCode := XMLDOMManagement.GetAttributeValue(ErrorXmlNode, 'kod');
if VerificationMode and (ResponseContentErrorCode = '0') then
if IsVerificationModeOK() then
exit;

LogMessage(TempErrorMessage."Message Type"::Error, ResponseContentErrorCode, ResponseContentError);
Expand Down Expand Up @@ -386,13 +390,17 @@ codeunit 31116 "EET Service Management CZL"
begin
if not XMLDOMManagement.FindNodeWithNamespace(
ResponseContentXmlDocument.AsXmlNode(), HeaderPathTxt, EETNamespacePrefixTxt, EETNamespaceTxt, HeaderXmlNode)
then
then begin
// Error responses may omit the original message UUID and header.
ResponseHeaderValid := ResponseContentErrorCode <> '';
exit;
end;

MessageUUID := XMLDOMManagement.GetAttributeValue(HeaderXmlNode, 'uuid_zpravy');
LogError := ResponseContentErrorCode = '' ?
(MessageUUID <> EETEntryCZL."Message UUID") :
(MessageUUID <> EETEntryCZL."Message UUID") and (MessageUUID <> '');
ResponseHeaderValid := not LogError;
if LogError then
LogMessage(TempErrorMessage."Message Type"::Error, '', MessageUUIDNotMatchErr);
end;
Expand All @@ -404,7 +412,8 @@ codeunit 31116 "EET Service Management CZL"
EETCertificateNotValidErr: Label 'Certificate of EET service is not valid.';
MissingResponseSignatureErr: Label 'The response from the EET service is not signed.';
begin
if VerificationMode then
// Documented error responses are unsigned; only acknowledgements require a certificate.
if VerificationMode or (ResponseContentErrorCode <> '') then
exit;
CertBase64Value := GetResponseCertificateAsBase64(ResponseXmlDocument);
if CertBase64Value = '' then begin
Expand Down Expand Up @@ -548,6 +557,8 @@ codeunit 31116 "EET Service Management CZL"
ResponseContentError := '';
ResponseContentErrorCode := '';
CommunicationFailed := false;
SubmissionStarted := false;
ResponseHeaderValid := false;
Clear(GlobalHttpRequestMessage);
Clear(GlobalHttpResponseMessage);

Expand Down Expand Up @@ -579,7 +590,7 @@ codeunit 31116 "EET Service Management CZL"

local procedure IsVerificationModeOK(): Boolean
begin
exit(VerificationMode and (ResponseContentErrorCode = '0'));
exit(VerificationMode and (GetResponseServiceError() = Enum::"EET Service Error CZL"::"Verification Succeeded"));
end;

local procedure LogMessage(MessageType: Option; MessageCode: Text; MessageText: Text)
Expand Down Expand Up @@ -629,13 +640,38 @@ codeunit 31116 "EET Service Management CZL"
exit(CopyStr(POKControlCode, 1, 39));
end;

procedure IsCorrectableFailure(): Boolean
Comment thread
DavidHolusa marked this conversation as resolved.
Resolved
Comment thread
DavidHolusa marked this conversation as resolved.
Resolved
var
ServiceError: Enum "EET Service Error CZL";
begin
// Call only after Send has returned false. This describes the last attempt, not the entry's complete history.
// Correctable means that the error allows editing selected entry data, not that the error can generally be resolved.
// Verification never registers a sale, and local failures before submission are safe to correct.
if VerificationMode or not SubmissionStarted then
exit(true);

ServiceError := GetResponseServiceError();
// Do not use IsRetryableFailure: subscribers may disable automatic retries without
// making changes to a potentially registered sale safe.
if CommunicationFailed or (ServiceError in [ServiceError::"Temporary Technical Error", ServiceError::"Technical or Data Error"]) then
exit(false);

// Only documented critical rejections with a matching (or legitimately omitted) UUID
// establish that this attempt did not register the sale. Unknown codes remain uncertain.
exit(ResponseHeaderValid and
(ServiceError in [ServiceError::"Invalid XML Encoding", ServiceError::"XML Schema Validation Failed",
ServiceError::"Invalid SOAP Signature", ServiceError::"Invalid Taxpayer ID Structure", ServiceError::"Message Too Large"]));
end;

procedure IsRetryableFailure() RetryableFailure: Boolean
var
EETManagement: Codeunit "EET Management CZL";
ServiceError: Enum "EET Service Error CZL";
begin
// The EET service recommends sending the message again only after the error codes -1 (temporary error) and 8.
// A failed communication is also temporary. Other errors, for example incorrect data or a missing certificate, are not solved by sending again.
RetryableFailure := CommunicationFailed or (ResponseContentErrorCode in [TemporaryTechnicalErrorCode(), TechnicalErrorCode()]);
ServiceError := GetResponseServiceError();
RetryableFailure := CommunicationFailed or (ServiceError in [ServiceError::"Temporary Technical Error", ServiceError::"Technical or Data Error"]);
EETManagement.OnIsRetryableFailure(CommunicationFailed, ResponseContentErrorCode, GlobalHttpResponseMessage, RetryableFailure);
end;

Expand Down Expand Up @@ -690,14 +726,29 @@ codeunit 31116 "EET Service Management CZL"
exit(12288);
end;

local procedure TemporaryTechnicalErrorCode(): Text
begin
exit('-1'); // Temporary technical error in processing - please re-send the data message later
end;

local procedure TechnicalErrorCode(): Text
begin
exit('8'); // The data message was not processed because of a technical error or a data error
local procedure GetResponseServiceError(): Enum "EET Service Error CZL"
begin
// Keep the wire codes at the conversion boundary; preserve the original text for logging and events.
case ResponseContentErrorCode of
'-1':
exit(Enum::"EET Service Error CZL"::"Temporary Technical Error");
'0':
exit(Enum::"EET Service Error CZL"::"Verification Succeeded");
'2':
exit(Enum::"EET Service Error CZL"::"Invalid XML Encoding");
'3':
exit(Enum::"EET Service Error CZL"::"XML Schema Validation Failed");
'4':
exit(Enum::"EET Service Error CZL"::"Invalid SOAP Signature");
'6':
exit(Enum::"EET Service Error CZL"::"Invalid Taxpayer ID Structure");
'7':
exit(Enum::"EET Service Error CZL"::"Message Too Large");
'8':
exit(Enum::"EET Service Error CZL"::"Technical or Data Error");
else
exit(Enum::"EET Service Error CZL"::Unknown);
end;
end;

[EventSubscriber(ObjectType::Table, Database::"Service Connection", OnRegisterServiceConnection, '', false, false)]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// ------------------------------------------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
// ------------------------------------------------------------------------------------------------
namespace Microsoft.Finance;

enum 11749 "EET Service Error CZL"
{
Access = Internal;
Extensible = false;

// Enum ordinals are internal identifiers, not the error codes of the service.
value(0; Unknown)
{
Caption = 'Unknown';
}
value(1; "Temporary Technical Error")
{
Caption = 'Temporary Technical Error';
}
value(2; "Verification Succeeded")
{
Caption = 'Verification Succeeded';
}
value(3; "Invalid XML Encoding")
{
Caption = 'Invalid XML Encoding';
}
value(4; "XML Schema Validation Failed")
{
Caption = 'XML Schema Validation Failed';
}
value(5; "Invalid SOAP Signature")
{
Caption = 'Invalid SOAP Signature';
}
value(6; "Invalid Taxpayer ID Structure")
{
Caption = 'Invalid Taxpayer ID Structure';
}
value(7; "Message Too Large")
{
Caption = 'Message Too Large';
}
value(8; "Technical or Data Error")
{
Caption = 'Technical or Data Error';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ using System.Security.User;
page 31146 "EET Entry Card CZL"
{
Caption = 'EET Entry Card';
Editable = false;
DeleteAllowed = false;
InsertAllowed = false;
PageType = Card;
SourceTable = "EET Entry CZL";
ApplicationArea = Basic, Suite;
Expand All @@ -36,15 +37,18 @@ page 31146 "EET Entry Card CZL"
}
field(Description; Rec.Description)
{
Editable = EntryEditable;
}
field("Document No."; Rec."Document No.")
{
}
field("Applied Document Type"; Rec."Applied Document Type")
{
Editable = EntryEditable;
}
field("Applied Document No."; Rec."Applied Document No.")
{
Editable = EntryEditable;
}
field("Receipt Serial No."; Rec."Receipt Serial No.")
{
Expand Down Expand Up @@ -72,12 +76,15 @@ page 31146 "EET Entry Card CZL"
Caption = 'Taxpayer and Authorization';
field("Taxpayer ID"; Rec."Taxpayer ID")
{
Editable = EntryEditable;
}
field("Authorizing Taxpayer ID"; Rec."Authorizing Taxpayer ID")
{
Editable = EntryEditable;
}
field("Multiple Taxpayer Auth."; Rec."Multiple Taxpayer Auth.")
{
Editable = EntryEditable;
}
}
group(Sale)
Expand Down Expand Up @@ -262,6 +269,7 @@ page 31146 "EET Entry Card CZL"
trigger OnAction()
begin
Rec.Verify();
CurrPage.Update(false);
end;
}
action(Cancel)
Expand All @@ -273,6 +281,7 @@ page 31146 "EET Entry Card CZL"
trigger OnAction()
begin
Rec.Cancel(true);
CurrPage.Update(false);
end;
}
}
Expand Down Expand Up @@ -313,12 +322,19 @@ page 31146 "EET Entry Card CZL"
trigger OnAfterGetRecord()
begin
SignatureCode := Rec.GetSignatureCode();
EntryEditable := Rec.IsEditable();
SetStatusStyle();
end;

trigger OnAfterGetCurrRecord()
begin
EntryEditable := Rec.IsEditable();
end;

var
SignatureCode: Text;
StatusStyleExpr: Text;
EntryEditable: Boolean;

local procedure SetStatusStyle()
begin
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ page 31137 "EET Simple Registration CZL"
Caption = 'General';
field("Business Premises Code"; Rec."Business Premises Code")
{
Editable = true;
ShowMandatory = true;

trigger OnLookup(var Text: Text): Boolean
Expand All @@ -48,6 +49,7 @@ page 31137 "EET Simple Registration CZL"
}
field("Cash Register Code"; Rec."Cash Register Code")
{
Editable = true;
ShowMandatory = true;

trigger OnLookup(var Text: Text): Boolean
Expand All @@ -62,6 +64,7 @@ page 31137 "EET Simple Registration CZL"
}
field("Document No."; Rec."Document No.")
{
Editable = true;
}
field(Description; Rec.Description)
{
Expand Down
Loading
Loading