Monday, 13 August 2018

Modify PrintMgmt Report format table

/// <summary>
/// Allows for the population of the PrintMgmtReportFormat table used for print management.
/// </summary>
/// <remarks>
/// This is a framework class. Customizing this class may cause problems with future upgrades to the software.
/// </remarks>
class CITPrintMgmtReportFormatSubscriber
{
    /// <summary>
    /// Event handler for populating the PrintMgmtReportFormat table.
    /// </summary>
    [SubscribesTo(classstr(PrintMgmtReportFormatPublisher), delegatestr(PrintMgmtReportFormatPublisher, notifyPopulate))]
    public static void notifyPopulate()
    {
        UMAPrintMgmtReportFormatSubscriber::populate();
    }

    /// <summary>
    /// Adds records to the <c>PrintMgmtReportFormat</c> table.
    /// </summary>
    /// <remarks>
    /// New report formats are manually added in this method by a developer.  The method is called before
    /// the <c>PrintMgmtSetupUIMain</c> form opens to ensure the list of available reports is updated.
    /// </remarks>
    public static void populate()
    {
        #PrintMgmtSetup
        #ISOCountryRegionCodes
        int reports = 0;
        int added = 0;
        LogisticsAddressCountryRegionISOCode isoCountryCode = SysCountryRegionCode::countryInfo();
        LogisticsAddressCountryRegionId countryRegionId = SysCountryRegionCode::getCountryRegionIdByIsoCode(isoCountryCode);
        #RusReportFormats


        ttsbegin;
       
       
        UMAPrintMgmtReportFormatSubscriber::add(PrintMgmtDocumentType::SalesOrderPackingSlip, ssrsReportStr(UmaPackingSlip, Wayfair), ssrsReportStr(UmaPackingSlip, Wayfair), countryRegionId, NoYes::Yes, PrintMgmtSSRS::SSRS);
        UMAPrintMgmtReportFormatSubscriber::add(PrintMgmtDocumentType::SalesOrderPackingSlip, ssrsReportStr(UmaPackingSlip, Amazon), ssrsReportStr(UmaPackingSlip, Amazon), countryRegionId, NoYes::Yes, PrintMgmtSSRS::SSRS);

        ttscommit;
    }

    private static boolean add(
            PrintMgmtDocumentType _type,
            PrintMgmtReportFormatName _name,
            PrintMgmtReportFormatDescription _description,
            PrintMgmtReportFormatCountryRegionId _countryRegionId,
            PrintMgmtReportFormatSystem _system
            , PrintMgmtSSRS _ssrs = PrintMgmtSSRS::SSRS
            )
    {
        PrintMgmtReportFormat printMgmtReportFormat;
        boolean isDuplicateFound;
        boolean isSystemFormatWithDifferentDescriptionFound;

        #PrintMgmtSetup

        isSystemFormatWithDifferentDescriptionFound = _system && (select firstOnly RecId from printMgmtReportFormat
            where printMgmtReportFormat.DocumentType == _type
                && printMgmtReportFormat.Description != _description
                && printMgmtReportFormat.System == true).RecId != 0;

        // If the format no longer matches up with the existing system formats, change them all to
        // non-system formats. This ensure existing links / setup will not be broken, but also provides
        // a way for the user to fix the formats.
        if (isSystemFormatWithDifferentDescriptionFound)
        {
            update_recordSet printMgmtReportFormat
                setting System = false
                where printMgmtReportFormat.DocumentType == _type
                    && printMgmtReportFormat.Description != _description
                    && printMgmtReportFormat.System == true;
        }

        isDuplicateFound = (select RecId from printMgmtReportFormat
            where printMgmtReportFormat.DocumentType == _type
                && printMgmtReportFormat.Description == _description
                && printMgmtReportFormat.CountryRegionId == _countryRegionId).RecId != 0;

        if (isDuplicateFound)
        {
            if (isSystemFormatWithDifferentDescriptionFound)
            {
                // We must ensure that the system report always matches the country context
                // of the company. If the the country context has been chagned multiple times
                // such that the report format already exists, we must change it back to system.
                update_recordSet printMgmtReportFormat
                    setting System = true
                    where printMgmtReportFormat.DocumentType == _type
                        && printMgmtReportFormat.Description == _description
                        && printMgmtReportFormat.CountryRegionId == _countryRegionId;
            }
            else
            {
                return false;
            }
        }
        else
        {
            // Add the new format
            printMgmtReportFormat.clear();
            printMgmtReportFormat.DocumentType = _type;
            printMgmtReportFormat.Name = _name;
            printMgmtReportFormat.Description = _description;
            printMgmtReportFormat.CountryRegionId = _countryRegionId;
            printMgmtReportFormat.System = _system;
            printMgmtReportFormat.ssrs = _ssrs;
            printMgmtReportFormat.insert();
        }

        return true;
    }

}

No comments:

Post a Comment