The following code calls the SalesConfirmationReport but instead of using its design, it uses bespoke design set in branding. This can allow you to call any report design that you want.
The contract class is nothing but parm methods for the journal recid and report name details for the dp class to fill in the write tmp tables. This is not a good design, so you dont have to follow it, but the below shows important methods that you need to override.
My biggest issue was overriding existing print management detail which can be done in the runPrintMgmt method.
/// <summary>
/// The <c>LSSalesConfirmController </c> class is the helper class for the associated SRS Report.
/// </summary>
public class LSSalesConfirmController extends TradeDocumentReportController implements BatchRetryable
{
FormletterJournalPrint formletterJournalPrint;
CustConfirmJour custConfirmJour;
/// <summary>
/// Gets the sales confirmation document title.
/// </summary>
/// <returns>
/// The document title.
/// </returns>
protected str documentTitle()
{
str documentTitle;
if (printCopyOriginal == PrintCopyOriginal::Copy)
{
if (custConfirmJour.isProforma())
{
documentTitle = literalStr("@SYS70793");
}
else
{
documentTitle = literalStr("@SYS24432");
}
}
else
{
if (custConfirmJour.isProforma())
{
documentTitle = literalStr("@SYS7845");
}
else
{
documentTitle = literalStr("@SYS12529");
}
}
return documentTitle;
}
[Wrappable(false)]
protected str documentIdentifier()
{
return custConfirmJour.ConfirmDocNum;
}
[Wrappable(false)]
protected TableId reportExceptionContextTableId()
{
return custConfirmJour.TableId;
}
[Wrappable(false)]
protected RecId reportExceptionContextRecordId()
{
return custConfirmJour.RecId;
}
protected boolean getFirstJournal()
{
return journalList.first(custConfirmJour);
}
protected boolean getNextJournal()
{
return journalList.next(custConfirmJour);
}
/// <summary>
/// Returns the record ID of the journal record to be passed to the contract.
/// </summary>
/// <returns>
/// The record ID of the journal record.
/// </returns>
protected RecId getRecordId()
{
return custConfirmJour.RecId;
}
/// <summary>
/// Initializes the report and sets the print management.
/// </summary>
protected void initFormLetterReport()
{
printCopyOriginal = this.parmArgs().parmEnum();
if (classIdGet(this.parmArgs().caller()) == classNum(SalesConfirmJournalPrint))
{
// Set the caller
formletterJournalPrint = this.parmArgs().caller();
}
if (this.parmArgs().record())
{
// Get journal list from the selected record/s
journalList = FormLetter::createJournalListCopy(this.parmArgs().record());
}
else
{
journalList = this.parmArgs().object();
}
formLetterReport = FormLetterReport::construct(PrintMgmtDocumentType::SalesOrderConfirmation);
formLetterReport.parmPrintType(printCopyOriginal);
if (formletterJournalPrint)
{
// Get the print settings
formLetterReport.parmDefaultCopyPrintJobSettings(new SRSPrintDestinationSettings(formletterJournalPrint.parmPrinterSettingsFormLetterCopy()));
formLetterReport.parmDefaultOriginalPrintJobSettings(new SRSPrintDestinationSettings(formletterJournalPrint.parmPrinterSettingsFormLetter()));
formLetterReport.parmUsePrintMgmtDestinations(formletterJournalPrint.parmUsePrintManagement());
}
else if (printCopyOriginal == PrintCopyOriginal::OriginalPrint)
{
// Always use the print mgmt destinations when reprinting for the OriginalPrint case.
formLetterReport.parmUsePrintMgmtDestinations(true);
}
super();
}
protected void runPrintMgmt()
{
//if you know there will not be any print management setup for your report, you can create a default one here. In my case, we were setting it up for emails but wanted a dynamic report design so it is commented out.
//SRSPrintDestinationSettings printSettings = new SRSPrintDestinationSettings(formLetterReport.parmReportRun().parmReportRunController().parmReportContract().parmPrintSettings().pack());
PrintMgmtPrintSettingDetail printSettingDetail;
journalList.first(custConfirmJour);
do
{
formLetterReport.loadPrintSettings(custConfirmJour, custConfirmJour.salesTable(), custConfirmJour.LanguageId);
if (formLetterReport.moveNextPrintSetting())
{
printSettingDetail = formLetterReport.getCurrentPrintSetting();
printSettingDetail.parmReportFormatName(this.getReportName(custConfirmJour));
//if you are creating the print settings value above, you need to pass it here.
//printSettingDetail.parmPrintJobSettings(printSettings);
formLetterReport.parmReportRun().loadSettingDetail(printSettingDetail);
}
CustLanguageId languageId = custConfirmJour.LanguageId;
this.parmReportContract().parmRdlContract().parmLabelLanguageId(languageId);
this.parmReportContract().parmRdlContract().parmLanguageId(languageId);
this.outputReports();
}
while (journalList.next(custConfirmJour) && !this.parmCancelRun());
}
/// <summary>
/// Sets the <c>SRSReportParameters</c> values in the report contract.
/// </summary>
protected void modifyContract()
{
LSOrderReportContract LSOrderConfcontract = this.parmReportContract().parmRdpContract() as LSOrderReportContract;
LSOrderConfcontract.parmTransactionRecId(custConfirmJour.RecId);
if (LSOrderConfcontract
&& !LSOrderConfcontract.parmLSReportName()
&& this.parmReportName())
{
container cReport = str2con(this.parmReportName(), '.');
str curReportName = any2Str(conPeek(cReport,1));
str curReportDesignName = any2Str(conPeek(cReport,2));
LSOrderConfcontract.parmLSReportName(curReportName);
LSOrderConfcontract.parmLSReportDesignName(curReportDesignName);
LSOrderConfcontract.parmCalledFromSO(true);
}
}
protected void output()
{
formLetterReport.loadPrintSettings(custConfirmJour, SalesTable::find(custConfirmJour.SalesId), custConfirmJour.LanguageId);
if (this.validateReportPrintJobSettingsEmailTo())
{
this.parmReportContract().parmRdlContract().parmLanguageId(custConfirmJour.LanguageId);
this.parmReportContract().parmRdlContract().parmLabelLanguageId(custConfirmJour.LanguageId);
super();
}
}
private boolean validateReportPrintJobSettingsEmailTo()
{
boolean ret = true;
PrintMgmtReportRun printMgmtReportRunLocal = formLetterReport.parmReportRun();
if (printMgmtReportRunLocal.next())
{
SRSPrintDestinationSettings printSettings = printMgmtReportRunLocal.settingDetail().parmPrintJobSettings();
if (printSettings.printMediumType() == SRSPrintMediumType::Email)
{
str emailTo = printSettings.emailTo();
if (!emailTo)
{
ret = checkFailed(strFmt("@SCM:SalesOrderEmailWasNotSent", custConfirmJour.SalesId));
}
else if (!SysEmailDistributor::validateEmail(emailTo))
{
ret = checkFailed(strFmt("@SCM:SalesOrderEmailWasNotSentInvalidEmail", custConfirmJour.SalesId, emailTo));
}
printSettings.fileName(strFmt("Order confirmation %1", custConfirmJour.SalesId));
}
printMgmtReportRunLocal.reset();
}
if(this.getFirstJournal())
{
this.parmReportName(this.getReportName(custConfirmJour));
}
return ret;
}
/// <summary>
/// Sets the values in the <c>CustConfirmJour</c> record.
/// </summary>
/// <param name="_common">
/// A <c>CustConfirmJour</c> record.
/// </param>
protected void setDataContractRecord(Common _common)
{
custConfirmJour = args.record();
}
public static LSSalesConfirmController construct()
{
return new LSSalesConfirmController();
}
/// <summary>
/// Initailzes the controller, sets the print management, assigns parameter values and runs the SRS report.
/// </summary>
/// <param name="_args">
/// The <c>Args</c> object.
/// </param>
public static void main(Args _args)
{
SrsReportRunController formLetterController = LSSalesConfirmController::construct();
LSSalesConfirmController controller = formLetterController;
if(_args.record())
{
CustConfirmJour ccj = _args.record();
controller.initArgs(_args, controller.getReportName(ccj));
}
if (classIdGet(_args.caller()) == classNum(SalesConfirmJournalPrint))
{
formLetterController.renderingCompleted += eventhandler(SalesConfirmJournalPrint::renderingCompleted);
}
SRSPrintDestinationSettings settings = controller.parmReportContract().parmPrintSettings();
settings.printMediumType(SRSPrintMediumType::Screen);
controller.parmReportContract().parmPrintSettings(settings);
formLetterController.startOperation();
}
/// <summary>
/// Specifies if the batch task is retryable for transient exceptions or not.
/// </summary>
/// <returns>
/// If true is returned, the batch task is retryable, otherwise it is not.
/// </returns>
[Hookable(false)]
final boolean isRetryable()
{
return true;
}
public PrintMgmtReportFormatName getReportName(CustConfirmJour _custConfirmJour)
{
RetailStoreTable retailStoreTable = RetailStoreTable::find(_custConfirmJour.salesTable().retailSalesTable().RetailStoreId);
CustTable custTable = CustTable::find(_custConfirmJour.OrderAccount);
SysDocuBrandDetails brandDetails;
str designType = custTable.custgroup == 'B2B' ?
strFmt('%1%2*', enum2Symbol(enumNum(LSSalesDocumentType), enum2int(LSSalesDocumentType::Confirmation)), 'B2B') :
strFmt('%1%2*', enum2Symbol(enumNum(LSSalesDocumentType), enum2int(LSSalesDocumentType::Confirmation)), 'B2C');
select firstonly brandDetails
where brandDetails.BrandId == retailStoreTable.LSBrandId
&& brandDetails.ReportName == 'LSOrderReport'
&& brandDetails.DesignName like designType;
if (!brandDetails.RecId)
{
throw error(strFmt('No report design found for BrandId: %1, CustGroupId: %2, DocumentType: %3',
retailStoreTable.LSBrandId,
custTable.custgroup,
enum2Symbol(enumNum(LSSalesDocumentType), enum2int(LSSalesDocumentType::Confirmation))));
}
return strFmt('%1.%2', brandDetails.ReportName, brandDetails.DesignName);
}
}
No comments:
Post a Comment