Lots of solutions being offered. Customers are in rush to get it done ASAP as dead line is approaching.
Mostly solution are opted by customer:
- API : Plain Text
- API : With Encryption & Decryption
- SFTP file transfer (Excel/CSV/JSON)
- GSP's own schema
- Government Compatible
- Generate IRN
- Export Json File
- Import Json File
Note: You may add/modify filed as per GSP details. Create a corresponding page for this table.
Note: Above fields are for example only. You may add/modify as per your need. Create a corresponding page for this table.
Step 4: Modify e-Invoice Management codeunit's methos "ExportAsJson(DocumentNo);" to call API & process response. Get the e-Invoice Setup and check if Integration is enabled then Call API otherwise leave the original code to save the JSON file.
Define the below variables in function "ExportAsJson":
Update "ExportAsJson" function as below:
LOCAL PROCEDURE ExportAsJson@1500012(DocumentNo@1500000 : Code[20]);
VAR
NewStream@1055602 : InStream;
HttpWebRequestMgt@1170000000 : Codeunit 1297;
TempBlob@1170000003 : Record 99008535;
HTTPStatusCode@1170000002 : DotNet "'System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.Net.HttpStatusCode";
ResponseHeader@1170000001 : DotNet "'System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.Collections.Specialized.NameObjectCollectionBase";
InStr@1170000004 : InStream;
Json@1170000005 : Text;
JSONManagement@1170000006 : Codeunit 5459;
WasSuccess@1170000007 : Boolean;
ErrorText@1170000008 : Text;
TrnsIdentifier@1170000009 : Text[250];
AckNumber@1170000014 : Text[30];
AckDateText@1170000015 : Text[30];
IRNText@1170000010 : Text[250];
SignedQR@1170000011 : Text;
SignedInv@1170000012 : Text;
eInvoiceEntry@1170000016 : Record 50051;
OStream@1170000017 : OutStream;
RequestText@1170000018 : Text;
QRPayload@1000000001 : Text;
IRNStatus@1000000002 : Text;
eInvoiceSetup@1000 : Record 50050;
AuthToken@1004 : Text[250];
SuccessText@1000000004 : Text[10];
QRCodeFileName@1000000005 : Text;
FileMgmt@1000000006 : Codeunit 419;
JObject@1000000008 : DotNet "'Newtonsoft.Json'.Newtonsoft.Json.Linq.JObject";
JSONArray@1000000007 : DotNet "'Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed'.Newtonsoft.Json.Linq.JArray";
RequestResponse@1000000010 : BigText;
BEGIN
eInvoiceSetup.GET();
HttpWebRequestMgt.Initialize(eInvoiceSetup."Base URL" + eInvoiceSetup."Generate E-Invoice URL");HttpWebRequestMgt.DisableUI();HttpWebRequestMgt.SetMethod('POST');
HttpWebRequestMgt.AddHeader('Bearer', AuthToken);HttpWebRequestMgt.SetContentType('application/json');HttpWebRequestMgt.SetReturnType('application/json');
HttpWebRequestMgt.AddBodyAsText(RequestText);WasSuccess := FALSE;ErrorText := '';IRNText := '';SignedQR := '';SignedInv := '';AckNumber := '';QRPayload := '';IRNStatus := '';TempBlob.INIT;TempBlob.Blob.CREATEINSTREAM(InStr);IF HttpWebRequestMgt.GetResponse(InStr,HTTPStatusCode,ResponseHeader) THEN BEGINIF FORMAT(HTTPStatusCode.ToString) IN ['OK','Ok','ok'] THENWasSuccess := TRUE;Json := TempBlob.ReadAsText('',TEXTENCODING::UTF8);JSONManagement.InitializeFromString(Json);SuccessText := JSONManagement.GetValue('Success');IF UPPERCASE(SuccessText) = 'Y' THEN BEGINAckNumber := JSONManagement.GetValue('AckNo');AckDateText := JSONManagement.GetValue('AckDt');IRNText := JSONManagement.GetValue('Irn');SignedInv := JSONManagement.GetValue('SignedInvoice');SignedQR := JSONManagement.GetValue('SignedQRCode');IRNStatus := JSONManagement.GetValue('Status');END ELSE BEGINJObject := JObject.JObject();JSONManagement.GetJSONObject(JObject);ArrayString := JObject.SelectToken('ErrorDetails').ToString;CLEAR(JSONManagement);CLEAR(JObject);JObject := JObject.JObject();JSONArray := JSONArray.JArray();JSONManagement.InitializeCollection(ArrayString);JSONManagement.GetJsonArray(JSONArray);FOREACH JObject IN JSONArray DO BEGINErrorText := JObject.GetValue('error_message').ToString;ENDEND;END ELSESuccessText := 'N';
//Create EntryeInvoiceEntry.INIT;IF IsInvoice THENeInvoiceEntry."Document Type" := eInvoiceEntry."Document Type"::InvoiceELSEeInvoiceEntry."Document Type" := eInvoiceEntry."Document Type"::CrMemo;eInvoiceEntry."Document No." := DocumentNo;CLEAR(RequestResponse);RequestResponse.ADDTEXT(RequestText);eInvoiceEntry."Request JSON".CREATEOUTSTREAM(OStream);RequestResponse.WRITE(OStream);
CLEAR(RequestResponse);RequestResponse.ADDTEXT(Json);eInvoiceEntry."Response JSON".CREATEOUTSTREAM(OStream);RequestResponse.WRITE(OStream);
IF NOT eInvoiceEntry.INSERT THENeInvoiceEntry.MODIFY;
IF UPPERCASE(SuccessText) = 'Y' THEN BEGINQRCodeFileName := GetQRCode(SignedQR);QRCodeFileName := MoveToMagicPath(QRCodeFileName); // To avoid confirmation dialogue on RTCCLEAR(TempBlob);FileMgmt.BLOBImport(TempBlob,QRCodeFileName);IF TempBlob.Blob.HASVALUE THEN BEGINeInvoiceEntry."QR Code Image" := TempBlob.Blob;END;eInvoiceEntry.Status := eInvoiceEntry.Status::Generated;eInvoiceEntry."Acknowledgment No." := AckNumber;eInvoiceEntry."Acknowledgment Date" := AckDateText;eInvoiceEntry.IRN := IRNText;eInvoiceEntry."IRN Status" := IRNStatus;eInvoiceEntry.SignedQRWriteAsText(SignedQR,TEXTENCODING::UTF8);eInvoiceEntry.SignedInvWriteAsText(SignedInv,TEXTENCODING::UTF8);eInvoiceEntry."QR Code".CREATEOUTSTREAM(OStream,TEXTENCODING::UTF8);OStream.WRITETEXT(QRPayload,STRLEN(QRPayload));END ELSE BEGINeInvoiceEntry.Status := eInvoiceEntry.Status::Fail;eInvoiceEntry."Error Message" := COPYSTR(ErrorText,1,250);END;eInvoiceEntry.RequestWriteAsText(RequestText,TEXTENCODING::UTF8);eInvoiceEntry.ResponseWriteAsText(Json,TEXTENCODING::UTF8);eInvoiceEntry."Created By" := USERID;eInvoiceEntry."Created Date Time" := CURRENTDATETIME;eInvoiceEntryMODIFY;
END ELSE BEGIN
FileManagement.DownloadToFile(ServerFile,LocalFile);
END;
END;
Note: This code might not run directly, you need to change/update accordingly. Codeunit: Http Web Request Mgt., JSON Management, & File Management are sufficient to call API & easily parse response using few supporting .net variables.
Step 5: Similarly need to write code for cancel IRN. Give a button at e-Invoice Entries page.
Step 6: Finalize your solution by putting required validations to avoid errors. Check the link for validation.
Happy to help you, pleas comment & give feedback. Or, you may contact us for further detailed information.
Home-Based Medical Billing Businesses vary significantly from one to the next in experience Small Practices Medical Billing Services, ability and services offered. Many are small start up businesses with only one or two employees. Some offer extensive experience from previous employment in a doctor's office, others may have only one or two clients.
ReplyDelete