protected void afterOperationBody() { CustInvoiceJour custInvoiceJour; ISTDParameters parameters = ISTDParameters::find(); next afterOperationBody(); Set journalSet = Set::create(formletterOutputContract.parmAllJournalsPacked()); SetEnumerator se = journalSet.getEnumerator(); while (se.moveNext()) { custInvoiceJour = se.current(); if (ISTDParameters::isProduction() && !this.proforma() && custInvoiceJour && !formletterOutputContract.parmUpdateError()) { ISTDProcessInvoice processISTDInvoice = new ISTDProcessInvoice(); processISTDInvoice.parmCustInvoiceJour(custInvoiceJour); processISTDInvoice.run(); } } }
/// <summary> /// Contains the code that does the actual job of the class. /// </summary> private void processInvoice() { System.Net.HttpWebRequest request; System.Net.WebResponse response; System.IO.Stream responseStream, requestStream; System.IO.StreamReader streamReader; System.Text.Encoding utf8; System.Byte[] bytes; System.Exception ex; Notes requestJson, responseJson, errorMessage; System.Net.WebException webException; ISTDInvoiceStatus invoiceStatus; ISTDGenerateInvoiceXML generateInvoiceXML; ISTDGenerateCreditNoteInvoiceXML generateCreditNoteInvoiceXML; ISTDLogTable logTable; try { System.Net.WebHeaderCollection httpHeader = new System.Net.WebHeaderCollection(); new InteropPermission(InteropKind::ClrInterop).assert(); request = System.Net.WebRequest::Create(parameters.URL); utf8 = System.Text.Encoding::get_UTF8(); //fill log table logTable.clear(); logTable.ProcessedDateTime = DateTimeUtil::utcNow(); logTable.InvoiceId = custInvoiceJour.InvoiceId; logTable.InvoiceDate = custInvoiceJour.InvoiceDate; LogTable.custInvoiceJourRecId = custInvoiceJour.RecId; LogTable.InvoiceGUID = custInvoiceJour.ISTDGuid; if (custInvoiceJour.creditNote()) { generateCreditNoteInvoiceXML = new ISTDGenerateCreditNoteInvoiceXML(custInvoiceJour); requestJson = generateCreditNoteInvoiceXML.returnXML(); } else { generateInvoiceXML = new ISTDGenerateInvoiceXML(custInvoiceJour); requestJson = generateInvoiceXML.returnXML(); } //fill request logTable.Request = requestJson; bytes = utf8.GetBytes(requestJson); httpHeader = request.Headers; httpHeader.Add('Client-Id', parameters.ClientId); httpHeader.Add('Secret-Key', parameters.SecretKey); request.set_Method('POST'); request.set_Headers(httpHeader); request.ContentType = 'application/json'; request.set_ContentLength(bytes.get_Length()); requestStream = request.GetRequestStream(); requestStream.Write(bytes, 0, bytes.get_Length()); response = request.GetResponse(); responseStream = response.GetResponseStream(); streamReader = new System.IO.StreamReader(responseStream); responseJson = streamReader.ReadToEnd(); logTable.Response = responseJson; logTable.IsProcessed = NoYes::Yes; invoiceStatus = ISTDInvoiceStatus::Sent; info('Invoice was sent successfully.'); } catch (webException) { invoiceStatus = ISTDInvoiceStatus::Error; if (webException.get_Response() != null) { System.Net.HttpWebResponse httpWebResponse; Notes responseString; httpWebResponse = webException.get_Response() as System.Net.HttpWebResponse; responseStream = httpWebResponse.GetResponseStream(); streamReader = new System.IO.StreamReader(responseStream); responseString = streamReader.ReadToEnd(); logTable.Errors = responseString; logTable.IsProcessed = NoYes::No; streamReader.Close(); responseStream.Close(); httpWebResponse.Close(); warning(strFmt('invoice %1 was not sent. Please check the log form for errors and try again.', custInvoiceJour.InvoiceId)); } else { logTable.IsProcessed = NoYes::No; logTable.Errors = webException.get_Message(); } // if (!logTable.Errors) logTable.Errors = webException.get_Message() + ' - block 1'; } catch (Exception::Error) { logTable.IsProcessed = NoYes::No; logTable.Errors = con2Str(this.retreiveErrorsAndWarnings()); invoiceStatus = ISTDInvoiceStatus::Error; this.clearInfologErrorAndWarnings(); // if (!logTable.Errors) logTable.Errors = AifUtil::getClrErrorMessage() + ' - block 2'; } catch (Exception::CLRError) { logTable.IsProcessed = NoYes::No; logTable.Errors = AifUtil::getClrErrorMessage(); invoiceStatus = ISTDInvoiceStatus::Error; } catch { logTable.IsProcessed = NoYes::No; logTable.Errors = 'There was an unhandled error that occured. - ' + AifUtil::getClrErrorMessage(); invoiceStatus = ISTDInvoiceStatus::Error; } finally { if (invoiceStatus == ISTDInvoiceStatus::Sent) { if (!custInvoiceJour.creditNote()) { logTable.InvoiceAmount = generateInvoiceXML.parmInvoiceAmount(); } else if (custInvoiceJour.creditNote()) { logTable.InvoiceAmount = generateCreditNoteInvoiceXML.parmInvoiceAmount(); } } if (invoiceStatus == ISTDInvoiceStatus::Error && !custInvoiceJour.creditNote()) { ISTDLogLine logLine; delete_from logLine where logLine.custInvoiceJourRecId == custInvoiceJour.RecId; } ttsbegin; custInvoiceJour.selectForUpdate(true); custInvoiceJour.ISTDInvoiceStatus = invoiceStatus; custInvoiceJour.doUpdate(); ttscommit; logTable.insert(); } }
Under review
Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.
As AI tools become more common, we’re introducing a Responsible AI Use…
We are honored to recognize Andrés Arias as our Community Spotlight honoree for…
These are the community rock stars!
Stay up to date on forum activity by subscribing.
CA Neeraj Kumar 895
Sohaib Cheema 811 User Group Leader
André Arnaud de Cal... 787 Super User 2025 Season 2