using System.Net; using System.IO;
using System.Configuration;
using System.Collections.Specialized;
internal final class FinReporting
{ /// <summary>
/// Class entry point. The system will call this method when a designated menu
///is selected or when execution starts and this class is set as the startup class.
/// </summary>
/// <param name = "_args">The specified arguments.</param>
public static void main(Args _args)
{
financialReportVersion financialReportVersion;
FinancialReports financialReports;
PeriodEnd periodEndDate;
str reportName;
str fileContent;
const str fileName = 'FinancialReport.xml';
Map saveResults = new Map(Types::Guid, Types::Class);
reportName = "12 Month Rolling Single Column Income Statement - Default";
periodEndDate = mkDate(31,12,2023);
//FiscalCalendarYear::findYearByCalendarDate( //Ledger::fiscalCalendar(CompanyInfo::find().RecId), systemDateGet()).EndDate;
guid _resultKey = emptyGuid();
str _extension = ".pdf";
select firstonly financialReportVersion
order by recid desc
join financialReports
where financialReports.DesignId==financialReportVersion.DesignId
&& financialReports.reportName == reportName;
FinancialReportingIReportExport reportExporter = new FinancialReportingReportExport(); System.Text.Encoding encodingGB18030 = System.Text.Encoding::GetEncoding("utf-8");
if (!financialReports.DesignId)
{
throw error(strfmt("Design not found for Report %1", reportName));
}
System.IO.Stream stream = reportExporter.GenerateAndExportReport( financialReports.DesignId,
curExt(),
mkDate(28,02,2024),
FinancialReportingReportExportFormat::Xml,
encodingGB18030);
if (stream == null)
{
throw error(strfmt("Stream is empty for Report %1 period %2",
reportName, periodEndDate));
}
System.IO.StreamReader sReader = new System.IO.StreamReader(stream);
fileContent = sReader.ReadToEnd();
// File::SendStringAsFileToUser(fileContent, fileName);
DocuFileSaveResult result;
if(financialReports)
{
// result = DocuFileSave::promptForSaveLocation(financialReports.ReportName, _extension); result = DocuFileSaveResult::construct();
str sharePointHost = OfficeSharePoint::getDefaultServer();
DocuFileSaveOptions options = DocuFileSaveOptions::construct(sharePointHost, reportName, ".pdf", " ");
result.parmAction(DocuFileSaveAction::Download); result.parmFilename(options.getCompleteFileName()); result.parmStorageLocation(options.parmStorageLocation());
}
_resultKey = newGuid();
saveResults.insert(_resultKey, result);
str _fileUrl = strFmt("%1%2%3","https://usnconeboxax1aos.cloud.onebox.dynamics.com/FinancialReporting/Report.svc/report/printFile/",financialReportVersion.ReportId,"/financial/0");
str _queryString ="printOptions={\"UseFinancialDetail\":true,\"UseAccountDetail\":false,\"UseTransactionDetail\":false,\"IncludeAllUnits\":false,\"FitToPageWidth\":false,\"IsLandscape\":false,\"PaperKind\":9,\"MarginTop\":\"0.25\",\"MarginBottom\":\"0.25\",\"MarginLeft\":\"0.50\",\"MarginRight\":\"0.50\"}&resources_lcid=en-us&format_lcid=en-US&format=5";
DocuFileSaveResult saveResult;
if(_resultKey && saveResults.exists(_resultKey))
{ saveResult = saveResults.lookup(_resultKey);
saveResults.remove(_resultKey);
}
if (saveResult != null)
{
FinancialReportingReportExport reportExporterloc = new FinancialReportingReportExport(); Stream s = reportExporterloc.getExportedReport(_fileUrl, _queryString); DocuFileSave::processSaveResult(s, saveResult); // File::SendFileToUser(stream, saveResult.parmFilename());
}
}
}
No comments:
Post a Comment