Tuesday 21 May 2019

AX 7 Override Sales Invoice report form controller

/// <summary>
///     The <c>SalesInvoiceController</c> class is the helper class for the associated SRS Report.
/// </summary>
public class SalesInvoiceControllerEEMC extends GiroPrintMgmtFormLetterController
{
    PrintCopyOriginal printCopyOriginal;
    RecordSortedList journalList;
    SalesInvoiceJournalPrint salesInvoiceJournalPrint;
    CustInvoiceJour custInvoiceJour;
    SalesInvoiceContract salesInvoiceContract;
    RecId ledgerJournalTransRecId;

    ItemType taxInvoiceItemType;
    boolean isTaxInvoice;
    // <GTH>
    boolean runOnBlockMode_TH;
    // </GTH>

    #ISOCountryRegionCodes
    // <GBR>
    #NFPrinting_BR
    FiscalDocumentContract_BR fiscalDocumentContract;
    FiscalDocument_BR fiscalDocument;
    // </GBR>

    // <GTE>
    boolean isGSTInvoice;
    GSTInvoiceContract_IN gstInvoiceContract;
    SRSCatalogItemName preReportName;
    // </GTE>

    protected void dialogShow()
    {
        if (useReportViewerForm && runOnBlockMode_TH)
        {
            if (dialog is SysOperationDialog)
            {
                SysOperationDialog sysOperationDialog = dialog as SysOperationDialog;
                sysOperationDialog.run();
            }
            else
            {
                FormRun formRun = dialog as formRun;
                formRun.run();
            }

            this.dialogPostRun();
            dialog.wait();
        }
        else
        {
            super();
        }
    }

private CustLanguageId getCustLanguageId()
{
CustLanguageId custLanguageId;

if (strLen(custInvoiceJour.InvoiceAccount) != 0)
{
custLanguageId = CustTable::find(custInvoiceJour.InvoiceAccount).languageId();
}
         else
         {
             custLanguageId = custInvoiceJour.LanguageId;
         }
       
return custLanguageId;
}

    /// <summary>
    ///     Retrieves the report header title.
    /// </summary>
    /// <returns>
    ///     The report header title.
    /// </returns>
    protected str documentTitle()
    {
        str documentTitle;
        boolean isCreditNote;
        CustLanguageId languageId;
        CustParameters custParameters = CustParameters::find();
        CompanyInfo companyInfo = CompanyInfo::find();
        // <GEEU>
        LogisticsAddressCountryRegionISOCode isoCountryCode = SysCountryRegionCode::countryInfo();
        // </GEEU>
        // <GEELV>
        boolean isInvoiceNumberUsed = ((isoCountryCode == #isoLV));
        // </GEELV>
        boolean printCorrInvoiceLabel_DE = isoCountryCode == #isoDE && companyInfo.PrintCorrInvoiceLabel_DE && custInvoiceJour.InvoiceDate >= companyInfo.PrintCorrInvoiceLabelEffDate_DE;

        languageId = this.getCustLanguageId();

        if (isoCountryCode == #isoLV)
        {
            GlobalizationInstrumentationHelper::featureRun(GlobalizationConstants::FeatureReferenceLV00010, funcName());
        }

        // <GEEU>
        switch (isoCountryCode)
        {
            case #isoEE, #isoLT, #isoHU, #isoLV, #isoPL:
                isCreditNote = custInvoiceJour.returnLinesExist_W();
                break;
            case #isoCZ:
                return SalesInvoiceControllerEEMC::documentTitle_CZ(custInvoiceJour,
                                                                salesInvoiceContract.parmPrintCopyOriginal(),
                                                                salesInvoiceContract.parmIsTaxInvoice());
            // <GMY>
            case #isoMY:
                return SalesInvoiceControllerEEMC::documentTitle_MY(
                    custInvoiceJour,
                    salesInvoiceContract.parmPrintCopyOriginal(),
                    salesInvoiceContract.parmIsTaxInvoice());
            // </GMY>
            default:
                // </GEEU>
                isCreditNote = custInvoiceJour.InvoiceAmount < 0 || (custInvoiceJour.InvoiceAmount == 0 && custInvoiceJour.Qty < 0);
            // <GEEU>
        }
        // </GEEU>

        if (!isCreditNote)
        {
            if (salesInvoiceContract.parmPrintCopyOriginal() == PrintCopyOriginal::Copy)
            {
                if (custInvoiceJour.isProforma())
                {
                    if (custInvoiceJour.Prepayment)
                    {
                        documentTitle = SysLabel::labelId2String(literalStr("@SYS87980"), languageId);
                    }
                    else
                    {
                        // <GEELV>
                        if (isInvoiceNumberUsed)
                        {
                            documentTitle = SysLabel::labelId2String(literalStr("@GLS222535"), languageId);
                        }
                        else
                        {
                            // </GEELV>
                            documentTitle = SysLabel::labelId2String(literalStr("@SYS70789"), languageId);
                            // <GEELV>
                        }
                        // </GEELV>
                    }
                }
                else
                {
                    if (salesInvoiceContract.parmIsTaxInvoice())
                    {
                        documentTitle = SysLabel::labelId2String(literalStr("@SYS121364"), languageId);
                    }
                    else if (isoCountryCode == #isoAE)
                    {
                        // Always print "Copy Tax invoice" if country is UAE
                        documentTitle = SysLabel::labelId2String(literalStr("@UAE_VAT:UAE_VAT_CopyTaxInvoice"), custInvoiceJour.LanguageId);
                    }
                    else
                    {
                        // <GEELV>
                        if (isInvoiceNumberUsed)
                        {
                            documentTitle = SysLabel::labelId2String(literalStr("@GLS222536"), languageId);
                        }
                        else
                        {
                            // </GEELV>
                            if (!SysCountryRegionCode::isLegalEntityInCountryRegion([#isoLT]))
                            {
                                documentTitle = SysLabel::labelId2String(literalStr("@SYS24428"), languageId);
                            }
                            else
                            {
                                documentTitle = SysLabel::labelId2String(literalStr("@SYS12128"), languageId);
                            }
                            // <GEELV>
                        }
                        // </GEELV>
                    }
                }
            }
            else
            {
                if (custInvoiceJour.isProforma())
                {
                    if (custInvoiceJour.Prepayment)
                    {
                        documentTitle = SysLabel::labelId2String(literalStr("@SYS87979"), languageId);
                    }
                    else
                    {
                        if (salesInvoiceContract.parmIsTaxInvoice())
                        {
                            documentTitle = SysLabel::labelId2String(literalStr("@SYS121362"), languageId);
                        }
                        else
                        {
                            // <GEELV>
                            if (isInvoiceNumberUsed)
                            {
                                documentTitle = SysLabel::labelId2String(literalStr("@GLS222537"), languageId);
                            }
                            else
                            {
                                // </GEELV>
                                documentTitle = SysLabel::labelId2String(literalStr("@SYS4701"), languageId);
                                // <GEELV>
                            }
                            // </GEELV>
                        }
                    }
                }
                else
                {
                    if (salesInvoiceContract.parmIsTaxInvoice())
                    {
                        documentTitle = SysLabel::labelId2String(literalStr("@SYS115505"), languageId);
                    }
                    else
                    {
                        // <GEELV>
                        if (isInvoiceNumberUsed)
                        {
                            documentTitle = SysLabel::labelId2String(literalStr("@GLS222538"), languageId);
                        }
                        else if (isoCountryCode == #isoAE)
                        {
                            // Always print "Tax invoice" if country is UAE
                            documentTitle = SysLabel::labelId2String(literalStr("@SYS115505"), custInvoiceJour.LanguageId);
                        }
                        else
                        {
                            // </GEELV>
                            documentTitle = SysLabel::labelId2String(literalStr("@SYS12128"), languageId);
                            // <GEELV>
                        }
                        // </GEELV>
                    }
                }
            }
        }
        else
        {
            if (salesInvoiceContract.parmPrintCopyOriginal() == PrintCopyOriginal::Copy)
            {
                if (custInvoiceJour.isProforma())
                {
                    if (custInvoiceJour.Prepayment)
                    {
                        documentTitle = printCorrInvoiceLabel_DE ? SysLabel::labelId2String(literalStr("@SYS4004214"), languageId):
                                                                   SysLabel::labelId2String(literalStr("@SYS87981"), languageId);
                    }
                    else
                    {
                        if (custParameters.CreditInvoicingReport)
                        {
                            documentTitle = printCorrInvoiceLabel_DE ? SysLabel::labelId2String(literalStr("@SYS4004215"), languageId) :
                                                                       SysLabel::labelId2String(literalStr("@SYS99741"), languageId);
                        }
                        else
                        {
                            documentTitle = printCorrInvoiceLabel_DE ? SysLabel::labelId2String(literalStr("@SYS4004215"), languageId) :
                                                                       SysLabel::labelId2String(literalStr("@SYS70790"), languageId);
                        }
                    }
                }
                else
                {
                    // <GEEHU>
                    if (isoCountryCode == #isoHU)
                    {
                        GlobalizationInstrumentationHelper::featureRun(GlobalizationConstants::FeatureReferenceHU00005, funcName());

                        // Always print "Invoice credit note" if country is Hungary
                        documentTitle = SysLabel::labelId2String(literalStr("@SYS4081405"), languageId);
                    }
                    else if (isoCountryCode == #isoAE)
                    {
                        // Always print "Copy Tax credit note" if country is UAE
                        documentTitle = SysLabel::labelId2String(literalStr("@UAE_VAT:UAE_VAT_CopyTaxCreditNote"), custInvoiceJour.LanguageId);
                    }
                    else
                    // </GEEHU>
                    if (custParameters.CreditInvoicingReport)
                    {
                        documentTitle = printCorrInvoiceLabel_DE ? SysLabel::labelId2String(literalStr("@SYS4004216"), languageId) :
                                                                   SysLabel::labelId2String(literalStr("@SYS99733"), languageId);
                    }
                    else
                    {
                        documentTitle = printCorrInvoiceLabel_DE ? SysLabel::labelId2String(literalStr("@SYS4004216"), languageId) :
                                                                   SysLabel::labelId2String(literalStr("@SYS24607"), languageId);
                    }
                }
            }
            else
            {
                if (custInvoiceJour.isProforma())
                {
                    if (custInvoiceJour.Prepayment)
                    {
                        documentTitle = printCorrInvoiceLabel_DE ? SysLabel::labelId2String(literalStr("@SYS4004214"), languageId) :
                                                                   SysLabel::labelId2String(literalStr("@SYS87981"), languageId);
                    }
                    else
                    {
                        if (custParameters.CreditInvoicingReport)
                        {
                            documentTitle = printCorrInvoiceLabel_DE ? SysLabel::labelId2String(literalStr("@SYS4004217"), languageId) :
                                                                       SysLabel::labelId2String(literalStr("@SYS99735"), languageId);
                        }
                        else
                        {
                            documentTitle = printCorrInvoiceLabel_DE ? SysLabel::labelId2String(literalStr("@SYS4004217"), languageId) :
                                                                       SysLabel::labelId2String(literalStr("@SYS24608"), languageId);
                        }
                    }
                }
                else
                {
                    // <GEEHU>
                    if (isoCountryCode == #isoHU)
                    {
                        // Always print "Invoice credit note" if country is Hungary
                        documentTitle = SysLabel::labelId2String(literalStr("@SYS4081405"), languageId);
                    }
                    else if (isoCountryCode == #isoAE)
                    {
                        // Always print "Tax credit note" if country is UAE
                        documentTitle = SysLabel::labelId2String(literalStr("@UAE_VAT:UAE_VAT_TaxCreditNote"), custInvoiceJour.LanguageId);
                    }
                    else
                    // </GEEHU>
                    if (custParameters.CreditInvoicingReport)
                    {
                        documentTitle = printCorrInvoiceLabel_DE ? SysLabel::labelId2String(literalStr("@SYS4004218"), languageId) :
                                                                   SysLabel::labelId2String(literalStr("@SYS99734"), languageId);
                    }
                    else
                    {
                        documentTitle = printCorrInvoiceLabel_DE ? SysLabel::labelId2String(literalStr("@SYS4004218"), languageId) :
                                                                   SysLabel::labelId2String(literalStr("@SYS8125"), languageId);
                    }
                }
            }
        }
        return documentTitle;
    }

    public PaymentStub getGiroType()
    {
        return custInvoiceJour.GiroType;
    }

    /// <summary>
    ///     Initializes the report and sets the print management.
    /// </summary>
    protected void initFormLetterReport()
    {
        printCopyOriginal = this.parmArgs().parmEnum();

        if (classIdGet(this.parmArgs().caller()) == classNum(SalesInvoiceJournalPrint))
        {
            // Set the caller
            salesInvoiceJournalPrint = this.parmArgs().caller();
        }
        if (this.parmArgs().dataset() == tableNum(WMSShipment))
        {
            WMSShipment wmsShipment = args.record();
            journalList = FormLetter::createJournalListCopy(ShipCarrierShipmentInvoice::custInvoiceJour(wmsShipment.ShipmentId));
        }
        else
        {
            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(this.printMgmtDocumentType());

        formLetterReport.parmPrintType(printCopyOriginal);

        if (salesInvoiceJournalPrint)
        {
            // Get the print settings
            formLetterReport.parmDefaultCopyPrintJobSettings(new SRSPrintDestinationSettings(salesInvoiceJournalPrint.parmPrinterSettingsFormLetterCopy()));
            formLetterReport.parmDefaultOriginalPrintJobSettings(new SRSPrintDestinationSettings(salesInvoiceJournalPrint.parmPrinterSettingsFormLetter()));
            formLetterReport.parmUsePrintMgmtDestinations(salesInvoiceJournalPrint.parmUsePrintManagement());
            formLetterReport.parmUseUserDefinedDestinations(salesInvoiceJournalPrint.parmUseUserDefinedDestinations());

            this.initInvoiceForPrint(salesInvoiceJournalPrint, journalList);
        }
        else if (printCopyOriginal == PrintCopyOriginal::OriginalPrint)
        {
            // Always use the print mgmt destinations when reprinting for the OriginalPrint case.
            formLetterReport.parmUsePrintMgmtDestinations(true);
        }
        else
        {
            FormLetterServiceController formLetterServiceController = args.caller() as FormLetterServiceController;
            if (formLetterServiceController)
            {
                FormLetterContract contract = formLetterServiceController.getContract();
                if (contract)
                {
                    formLetterReport.parmDefaultOriginalPrintJobSettings(new SRSPrintDestinationSettings(SysOperationHelper::base64Decode(contract.parmPrintersettingsFormletter())));
                    formLetterReport.parmDefaultCopyPrintJobSettings(new SRSPrintDestinationSettings(SysOperationHelper::base64Decode(contract.parmPrintersettingsFormletterCopy())));
                    formLetterReport.parmUsePrintMgmtDestinations(contract.parmUsePrintManagement());
                    formLetterReport.parmUseUserDefinedDestinations(contract.parmUseUserDefinedDestinations());
                }
            }
        }

        super();
    }

    /// <summary>
    /// Retrieves the <c>PrintMgmtDocumentType</c>.
    /// </summary>
    /// <returns>
    /// The <c>PrintMgmtDocumentType</c> instance.
    /// </returns>
    public PrintMgmtDocumentType printMgmtDocumentType()
    {
        return PrintMgmtDocumentType::SalesOrderInvoice;
    }

    /// <summary>
    ///     Executes the report for the print management setting that is currently loaded.
    /// </summary>
    /// <remarks>
    /// The <c>outReports</c> method iterates over print management settings and calls this method for each
    /// print management setting that is loaded. Override this method to modify parameters for each print
    /// settings if you want to provide different footer text for each print settings loaded for a given
    /// report.
    /// </remarks>
    /// <exception cref="M:Exception::Error">
    ///     The print management object has not been initialized.
    /// </exception>
    #ISOCountryRegionCodes
    protected void outputReport()
    {
        PrintMgmtPrintSettingDetail detail = formLetterReport.getCurrentPrintSetting();

        // <GEELT>
        CompanyInfo companyInfo = CompanyInfo::find();
        // </GEELT>
        // <GEEHU>
        // </GEEHU>

        // <GTE><GIN>
        if (SysCountryRegionCode::isLegalEntityInCountryRegion([#isoIN]))
        {
            if (formLetterReport.parmPrintType() != PrintCopyOriginal::OriginalPrint || TaxSolutionScopeIntegrationUtil::isCompanyEnabled())
            {
                this.initReportName_IN();
            }

            if (TaxSolutionScopeIntegrationUtil::isCompanyEnabled() && this.parmIsGSTInvoice_IN())
            {
                this.outputReport_IN();
                super();
                return;
            }
            detail.parmReportFormatName(ssrsReportStr(SalesInvoiceCopy, Report));
        }
        // </GTE></GIN>

        // <GBR>
        if (!BrazilParameters::isEnabled())
        {
            // </GBR>
            salesInvoiceContract.parmInstanceType(detail.parmType());
            salesInvoiceContract.parmIdentificationText(detail.parmIdentificationText());

            switch (formLetterReport.getCurrentPrintSetting().parmType())
            {
                case PrintMgmtDocInstanceType::Copy : printCopyOriginal = PrintCopyOriginal::Copy;
                    break;

                case PrintMgmtDocInstanceType::Original : printCopyOriginal = PrintCopyOriginal::OriginalPrint;
                    break;
            }

            salesInvoiceContract.parmPrintCopyOriginal(printCopyOriginal);
            String255 documentTitle = this.documentTitle();

            // <GEELT>
            if (SysCountryRegionCode::isLegalEntityInCountryRegion([#isoLT]))
            {
                if (strLRTrim(companyInfo.getPrimaryRegistrationNumber(TaxRegistrationTypesList::TAXID, custInvoiceJour.InvoiceDate)))
                {
                    // Adds the "VAT" keyword to the begining of the invoice text if the company is a VAT payer
                    documentTitle = strFmt("@SYS76498", SysLabel::labelId2String(literalStr("@GLS107406"), custInvoiceJour.LanguageId), documentTitle);
                }
                // Adds "Sequel" word to the end of the invoice text to be shown on each page except the first one.
                String255 documentTitleSequel = SysLabel::labelId2String(literalStr("@GLS221084"));

                salesInvoiceContract.parmDocumentTitleSequel(documentTitleSequel);
            }
            // </GEELT>

            salesInvoiceContract.parmDocumentTitle(documentTitle);

            // <GEEHU>
            if (SysCountryRegionCode::isLegalEntityInCountryRegion([#isoHU]) && !custInvoiceJour.isProforma())
            {
                SRSPrintDestinationSettings srsPrintDestinationSettings = formLetterReport.getCurrentPrintSetting().parmPrintJobSettings();
                SRSPrintMediumType srsPrintMediumType = srsPrintDestinationSettings.printMediumType();

                if (srsPrintDestinationSettings.printMediumType() == SRSPrintMediumType::Printer)
                {
                    CustInvoiceJourPrint custInvoiceJourPrint = CustInvoiceJourPrint::findFromCustInvoiceJour(custInvoiceJour.RecId);
                    int copyNumber = CustInvoiceJourPrint::createInvoiceCopySequence(custInvoiceJour.RecId, printCopyOriginal);

                    if (printCopyOriginal == PrintCopyOriginal::Copy)
                    {
                        salesInvoiceContract.parmInvoiceInstanceText(strFmt("%1 %2", int2str(copyNumber), SysLabel::labelId2String(literalStr("@GLS107722"), custInvoiceJour.LanguageId)));
                    }
                    else
                    {
                        if (custInvoiceJourPrint.HasOriginalBeenPrinted)
                        {
                            // Don't allow to print the original document more than once.
                            error(strFmt("@GLS223085", custInvoiceJour.InvoiceId, custInvoiceJour.InvoiceDate));
                            return;
                        }
                        salesInvoiceContract.parmInvoiceInstanceText(strFmt("%1 %2", int2str(0), SysLabel::labelId2String(literalStr("@GLS107723"), custInvoiceJour.LanguageId)));
                    }
                }
                else
                {
                    salesInvoiceContract.parmInvoiceInstanceText(strFmt("%1%2%3", SysLabel::labelId2String(literalStr("@GLS107724"), custInvoiceJour.LanguageId), "\n", SysLabel::labelId2String(literalStr("@GLS107725"), custInvoiceJour.LanguageId)));
                }
            }
            // </GEEHU>

            if (SysCountryRegionCode::isLegalEntityInCountryRegion([#isoIS]))
            {
                GiroPrintMgmtFormLetterControllerHelper_IS::updateInvoiceJourPrintedOriginal(this.custInvoiceJour, this.printCopyOriginal, detail);
            }

            // <GTH>
            if (   TaxThaiGovCertificationFeatureChecker::isSubstitutionAdjustmentEnabled()
                && !salesInvoiceContract.parmMiscText()) // we are not in the process of 'document set' printing
            {
                CustInvoiceJourAdjustment::markInvoiceAsPrinted(custInvoiceJour.RecId, salesInvoiceContract.parmAdjustmentRecId_TH());
            }
            // </GTH>

            // <GBR>
        }
        // </GBR>

        try
        {
            super();

            this.outputReportPostProcess();
        }
        catch (Exception::Error)
        {
            SysInfoLogStr errorMessage = SrsReportRunController::getErrorMessage();

            if (detail.parmPrintJobSettings().printMediumType() == SRSPrintMediumType::Email &&
                (strCmp(errorMessage, strfmt("@SYS134596", "@SYS101250")) == 0 ||
                strCmp(errorMessage, strfmt("@SYS134596", "@SYS80078")) == 0))
            {
                // If printing via email log info about the invalid email and continue processing remaining invoices
                error(strFmt("@AccountsReceivable:CustInvoiceInvalidEmail", custInvoiceJour.InvoiceAccount, custInvoiceJour.InvoiceId));
            }
            else
            {
                error(strFmt("@AccountsReceivable:CustInvoicePrintManagementIssue", custInvoiceJour.InvoiceAccount, custInvoiceJour.InvoiceId));
            }
        }
    }

    /// <summary>
    /// The method handles any processing that needs to happen at the end of the outputReport() method, but within the execution scope of the
    /// try/catch block.
    /// </summary>
    /// <remarks>This method has been provided for extensibility purposes and is designed to be wrapped using the chain of command pattern.</remarks>
    protected void outputReportPostProcess()
    {
    }

    [Hookable(false)]
    public boolean parmRunOnBlockMode_TH(boolean _runOnBlockMode_TH = runOnBlockMode_TH)
    {
        runOnBlockMode_TH = _runOnBlockMode_TH;
        return runOnBlockMode_TH;
    }

    /// <summary>
    ///     Sets the <c>SRSReportParameters</c> values to the report contract.
    /// </summary>
    protected void preRunModifyContract()
    {
        SRSTmpDataStore srsTmpDataStore;
        SalesInvoiceHeaderFooterTmp salesInvoiceHeaderFooterTmp;

        // <GTH>
        // </GTH>
        // <GBR>
        FiscalEstablishment_BR fiscalEstablishment;
        // </GBR>

        // <GTE><GIN>
        if (SysCountryRegionCode::isLegalEntityInCountryRegion([#isoIN])
            && TaxSolutionScopeIntegrationUtil::isCompanyEnabled()
            && this.parmIsGSTInvoice_IN())
        {
            this.preRunModifyContract_IN();
            super();
            return;
        }
        // </GTE></GIN>

        // <GBR>
        if (BrazilParameters::isEnabled())
        {
            fiscalDocumentContract = this.parmReportContract().parmRdpContract();

            select firstonly fiscalDocument
                where fiscalDocument.RefRecId == custInvoiceJour.RecId
                    && fiscalDocument.RefTableId == custInvoiceJour.TableId
                join EFDocPrePrintedSecurityForm, EFDocEnvironment from fiscalEstablishment
                    where fiscalEstablishment.FiscalEstablishmentId == fiscalDocument.FiscalEstablishment;

            fiscalDocumentContract.parmRecordId(fiscalDocument.RecId);
            fiscalDocumentContract.parmPrePrintedSecurityForm(fiscalEstablishment.EFDocPrePrintedSecurityForm);
            fiscalDocumentContract.parmMaxDescSizeAdditionaInfFirstPage(#MaxDescSizeAdditionaInfFirstPage);
            fiscalDocumentContract.parmProForma(custInvoiceJour.isProforma());

            if (fiscalDocument.isElectronic())
            {
                fiscalDocumentContract.parmMaxDescSizeAdditionalInformation(#MaxDescSizeAdditionalInformation);
            }
            else
            {
                fiscalDocumentContract.parmMaxDescSizeAdditionalInformation(#MaxNFMemoLines * #MaxNFMemoDescriptionSize);
            }

            if (fiscalEstablishment.EFDocEnvironment == EFDocEnvironment_BR::Testing)
            {
                fiscalDocumentContract.parmEFDocEnvironment(true);
            }
            else
            {
                fiscalDocumentContract.parmEFDocEnvironment(false);
            }

            if (salesInvoiceJournalPrint)
            {
                // Pack the class and insert into the temporary store.
                srsTmpDataStore.Value = salesInvoiceJournalPrint.pack();
                srsTmpDataStore.insert();

                // Set the rec id to contract parameter
                fiscalDocumentContract.parmFormLetterRecordId(srsTmpDataStore.RecId);
            }
        }
        else
        {
            // </GBR>
            if (!salesInvoiceContract)
            {
                salesInvoiceContract = this.parmReportContract().parmRdpContract();
            }

            salesInvoiceContract.parmPrintCopyOriginal(printCopyOriginal);

            salesInvoiceContract.parmRecordId(custInvoiceJour.RecId);
            salesInvoiceContract.parmledgerJournalTransRecordId(ledgerJournalTransRecId);
            salesInvoiceContract.parmTaxInvoiceItemType(taxInvoiceItemType);

            // <GTH>
            if (TaxThaiGovCertificationFeatureChecker::isUnrealizedVATEnabled())
            {
                TaxAgent taxAgent = TaxAgent::find(custInvoiceJour.custInvoiceJourExtensionTH().TaxAgent);
                salesInvoiceContract.parmIsUnrealizedVATEnabled(true);
                salesInvoiceContract.parmAgentId(taxAgent.AgentId);
                salesInvoiceContract.parmAgentName(taxAgent.name());
                salesInvoiceContract.parmAgentAddress(taxAgent.address());
                salesInvoiceContract.parmTaxBranchCode(TaxBranchType::getTBDisplayValueByDefaultDimension(custInvoiceJour.DefaultDimension));
                salesInvoiceContract.parmTaxBranchName(TaxBranch::getReportTaxBranchStr(salesInvoiceContract.parmTaxBranchCode()));
                salesInvoiceContract.parmAdjustmentRecId_TH(CustInvoiceJourAdjustment::findLatestByCustInvoiceJour(
                                                            custInvoiceJour.RecId,
                                                            CustInvoiceJourAdjustment::getAdjustmentTypeFromArgs(this.parmArgs())).RecId);
                isTaxInvoice = custInvoiceJour.isRealizedVAT();
                //print document set
                if (salesInvoiceJournalPrint && salesInvoiceJournalPrint.parmDocuSetCode())
                {
                    salesInvoiceContract.parmProdType(salesInvoiceJournalPrint.parmProdType());
                    salesInvoiceContract.parmPrintHeader(salesInvoiceJournalPrint.parmPrintHeader());
                    salesInvoiceContract.parmLocation(salesInvoiceJournalPrint.parmLocation());
                    salesInvoiceContract.parmMiscText(salesInvoiceJournalPrint.parmMiscText());
                }
            }
            // </GTH>

            salesInvoiceContract.parmIsTaxInvoice(isTaxInvoice);
            // <GEEPL>
            if (SysCountryRegionCode::isLegalEntityInCountryRegion([#isoPL]))
            {
                salesInvoiceContract.parmCustInvoiceDuplicateRecId(this.parmDuplicateInvoiceRecId());
                salesInvoiceContract.parmUserName(SysReportRun::userName());
            }
            // </GEEPL>
            this.parmReportContract().parmRdlContract().parmLabelLanguageId(this.getCustLanguageId());
            this.parmReportContract().parmRdlContract().parmLanguageId(custInvoiceJour.LanguageId);

            if (salesInvoiceJournalPrint)
            {
                // Pack the class and insert into the temporary store.
                srsTmpDataStore.Value = salesInvoiceJournalPrint.pack();
                srsTmpDataStore.insert();

                // Set the rec id to contract parameter
                salesInvoiceContract.parmFormLetterRecordId(srsTmpDataStore.RecId);
            }

            // To Capture the createdTransactionId.
            select firstonly salesInvoiceHeaderFooterTmp
                where salesInvoiceHeaderFooterTmp.JournalRecId == custInvoiceJour.RecId;

            salesInvoiceContract.parmCreatedTransactionId(salesInvoiceHeaderFooterTmp.createdTransactionId);
           
            salesInvoiceContract.parmCountryRegionISOCode(SysCountryRegionCode::countryInfo());
           
            // <GSA>
            if (SysCountryRegionCode::isLegalEntityInCountryRegion([#isoSA, #isoAE]))
            {
                salesInvoiceContract.parmLanguageId(custInvoiceJour.LanguageId);
            }
            // </GSA>
            // <GBR>
        }
        // </GBR>
        this.preRunModifyContractExtension(this, salesInvoiceContract);

        super();
    }

    /// <summary>
    /// Extends the contract modification before run.
    /// </summary>
    /// <param name = "_controller">The controller object.</param>
    /// <param name = "_contract">The contract object.</param>
    delegate void preRunModifyContractExtension(SalesInvoiceControllerEEMC _controller, SalesInvoiceContract _contract)
    {
    }

    private void resetReportDataContract()
    {
        contractsInitialized = false;
        this.parmReportRun(null);
        this.parmReportContract(null);

        // <GTE><GIN>
        if (SysCountryRegionCode::isLegalEntityInCountryRegion([#isoIN])
            && TaxSolutionScopeIntegrationUtil::isCompanyEnabled())
        {
            gstInvoiceContract = null;
            salesInvoiceContract = null;
        }
        // </GTE></GIN>
    }

    /// <summary>
    /// Creates the print setting detail.
    /// </summary>
    /// <returns>The print setting detail.</returns>
    [Replaceable]
    protected PrintMgmtPrintSettingDetail printSettingDetail()
    {
        PrintMgmtPrintSettingDetail printSettingDetail;

        if (BrazilParameters::isEnabled()
            && formLetterReport.moveNextPrintSetting())
        {
            printSettingDetail = formLetterReport.getCurrentPrintSetting();

            if (printSettingDetail.parmReportFormatName() == PrintMgmtDocType::construct(this.printMgmtDocumentType()).getDefaultReportFormat())
            {
                fiscalDocument = custInvoiceJour.fiscalDocument_BR();

                // Retrieves the appropiate SSRS Report name to show an invoice (FiscalDocument_BR, EFDocDANFE_BR, RPS_BR)
                this.parmReportName(fiscalDocument.getReportName());

                // Change the default report to Brazilian Format
                printSettingDetail.parmReportFormatName(this.parmReportName());
            }
            else
            {
                // Uses the SSRS Report name configured by user on Print Management
                this.parmReportName(printSettingDetail.parmReportFormatName());
            }

            this.resetReportDataContract();
        }
        else if (SysCountryRegionCode::isLegalEntityInCountryRegion([#isoAE]) && formLetterReport.moveNextPrintSetting())
        {
            printSettingDetail = formLetterReport.getCurrentPrintSetting();

            if (printSettingDetail.parmReportFormatName() == PrintMgmtDocType::construct(this.printMgmtDocumentType()).getDefaultReportFormat())
            {
                this.parmReportName(ssrsReportStr(SalesInvoiceCopy, Report));
            }

            printSettingDetail.parmReportFormatName(this.parmReportName());
        }

        return printSettingDetail;
    }

    /// <summary>
    ///     Runs the print report.
    /// </summary>
    protected void runPrintMgmt()
    {
        Common printMgmtReferencedTable;
        // <GSA>
        LanguageId originalLanguageId;
        // </GSA>
        LanguageId originalLanguageId_AE;

        if (!journalList)
        {
            throw error("@SYS26348");
        }

        journalList.first(custInvoiceJour);

        do
        {
            if (!custInvoiceJour)
            {
                throw error("@SYS26348");
            }
            // <GMY>
            if (custInvoiceJour.custInvoiceJour_W().InvoiceType_MY == InvoiceType_MY::GST
                && !TaxGSTHelper_MY::getGSTRegistrationNumber(custInvoiceJour.InvoiceDate))
            {
                throw error("@SYP4860820");
            }
            // </GMY>

            // Determine where to start looking for Print Mgmt settings
            if (SalesParameters::find().DeleteHeading == NoYes::Yes)
            {
                // The original SalesTable record no longer exists, so skip that Print Mgmt level
                // and start with the customer instead.
                printMgmtReferencedTable = custInvoiceJour.custTable_InvoiceAccount();

                if (printMgmtReferencedTable == null)
                {
                    printMgmtReferencedTable = custInvoiceJour.custTable_OrderAccount();
                }
            }
            else
            {
                printMgmtReferencedTable = custInvoiceJour.salesTable();
            }

            formLetterReport.loadPrintSettings(custInvoiceJour, printMgmtReferencedTable, custInvoiceJour.LanguageId);
           
            PrintMgmtPrintSettingDetail printSettingDetail = this.printSettingDetail();
            if (printSettingDetail)
            {
                formLetterReport.parmReportRun().loadSettingDetail(printSettingDetail);
            }
            if(formLetterReport.moveNextPrintSetting())
            {
                printSettingDetail = formLetterReport.getCurrentPrintSetting();

                if(printSettingDetail.parmReportFormatName() == PrintMgmtDocType::construct(PrintMgmtDocumentType::SalesOrderInvoice).getDefaultReportFormat())
                {
                    this.parmReportName(ssrsReportStr(SalesInvoiceCopy, Report));
                   
                }
                printSettingDetail.parmReportFormatName(this.parmReportName());
                this.resetReportDataContract();
                formLetterReport.parmReportRun().loadSettingDetail(printSettingDetail);
            }

            this.outputReports();

            DocumentAttachment documentAttachment = DocumentAttachment::construct(PrintMgmtDocumentType::SalesOrderInvoice);
            documentAttachment.parmJournal(custInvoiceJour);
            documentAttachment.parmInnerReportDataContract(reportContract);
            documentAttachment.parmPrintCopyOriginal(formLetterReport.parmPrintType());
            documentAttachment.run();
            // <GEEPL>
            // <GSA>
            if (CustVendInvoiceJour::needToPrintInCompanyLanguage_SA(custInvoiceJour))
            {
                originalLanguageId = custInvoiceJour.LanguageId;
                CustVendInvoiceJour::setLanguage_SA(custInvoiceJour, CompanyInfo::languageId());
            }
            else
            if (originalLanguageId)
            {
                if (! custInvoiceJour.Proforma)
                {
                    CustVendInvoiceJour::setLanguage_SA(custInvoiceJour, originalLanguageId);
                }
                originalLanguageId = '';
            }
            // </GSA>

            if (CustVendInvoiceJour::needToPrintInCompanyLanguage_AE(custInvoiceJour))
            {
                originalLanguageId_AE = custInvoiceJour.LanguageId;
                CustVendInvoiceJour::setLanguage_AE(custInvoiceJour, CompanyInfo::languageId());
            }
            else if (originalLanguageId_AE)
            {
                CustVendInvoiceJour::setLanguage_AE(custInvoiceJour, originalLanguageId_AE);
                originalLanguageId_AE = '';
            }
        }
        while (this.parmArgs().dataset() != tableNum(CustInvoiceDuplicateTable_W)
            && (originalLanguageId || journalList.next(custInvoiceJour)
                || (originalLanguageId_AE))
            && !this.parmCancelRun());
        // </GEEPL>
    }

    /// <summary>
    ///     Gets the report header title for the Czech Republic
    /// </summary>
    /// <param name="_custInvoiceJour">
    ///     The <c>CustInvoiceJour</c> Record for which we look for title
    /// </param>
    /// <param name="_printCopyOriginal">
    ///     Printing type: Copy or Original
    /// </param>
    /// <param name="_isTaxInvoice">
    ///     The boolean sign which shows the it is a tax invoice or not (different titles)
    /// </param>
    /// <returns>
    ///     The report header title
    /// </returns>
    static str documentTitle_CZ(
        custInvoiceJour _custInvoiceJour,
        PrintCopyOriginal _printCopyOriginal,
        boolean _isTaxInvoice = false)
    {
        str documentTitle;
        boolean isCreditNote = _custInvoiceJour.creditNote();

        void setDocumentTitle(str _label)
        {
            documentTitle = SysLabel::labelId2String(_label);
        }

        if (!isCreditNote)
        {
            if (_printCopyOriginal == PrintCopyOriginal::Copy)
            {
                if (_custInvoiceJour.isProforma())
                {
                    if (_custInvoiceJour.Prepayment)
                    {
                        setDocumentTitle(literalStr("@SYS87980"));
                    }
                    else
                    {
                        setDocumentTitle(literalStr("@SYS70789"));
                    }
                }
                else
                {
                    if (_isTaxInvoice)
                    {
                        setDocumentTitle(literalStr("@SYS121364"));
                    }
                    else
                    {
                        setDocumentTitle(literalStr("@SYS24428"));
                    }
                }
            }
            else
            {
                if (_custInvoiceJour.isProforma())
                {
                    if (_custInvoiceJour.Prepayment)
                    {
                        setDocumentTitle(literalStr("@SYS87979"));
                    }
                    else
                    {
                        if (_isTaxInvoice)
                        {
                            setDocumentTitle(literalStr("@SYS121362"));
                        }
                        else
                        {
                            setDocumentTitle(literalStr("@SYS4701"));
                        }
                    }
                }
                else
                {
                    if (_isTaxInvoice)
                    {
                        setDocumentTitle(literalStr("@SYS115505"));
                    }
                    else
                    {
                        setDocumentTitle(literalStr("@SYS12128"));
                    }
                }
            }
        }
        else
        {
            if (_printCopyOriginal == PrintCopyOriginal::Copy)
            {
                if (_custInvoiceJour.isProforma())
                {
                    if (_custInvoiceJour.Prepayment)
                    {
                        setDocumentTitle(literalStr("@SYS4002413"));
                    }
                    else
                    {
                        setDocumentTitle(literalStr("@SYS4002415"));
                    }
                }
                else
                {
                    setDocumentTitle(literalStr("@SYS4002422"));
                }
            }
            else
            {
                if (_custInvoiceJour.isProforma())
                {
                    if (_custInvoiceJour.Prepayment)
                    {
                        setDocumentTitle(literalStr("@SYS4002414"));
                    }
                    else
                    {
                        setDocumentTitle(literalStr("@SYS4002424"));
                    }
                }
                else
                {
                    setDocumentTitle(literalStr("@SYS4002423"));
                }
            }
        }
        return documentTitle;
    }

    /// <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)
    {
        //<GEEPL>
        #ISOCountryRegionCodes
        RecordSortedList journalList;
        CustInvoiceJour custInvoiceJour;
        str txt="";
        //</GEEPL>
        // <GTE><GIN>
        Common common;
        // </GTE></GIN>

        GiroPrintMgmtFormLetterController formLetterController = SalesInvoiceControllerEEMC::construct();

        // <GEERU>
        if (SysCountryRegionCode::isLegalEntityInCountryRegion([#isoRU]))
        {
            if (!NonSSRSPrintMgmtAdapter::runPrintMgmtNonSSRS(PrintMgmtDocumentType::SalesOrderInvoice, _args))
            {
                return;
            }
        }
        // </GEERU>

        // <GEEPL>
        if (SysCountryRegionCode::isLegalEntityInCountryRegion([#isoPL]))
        {
            if (_args.dataset() == tableNum(CustInvoiceDuplicateTable_W))
            {
                CustInvoiceDuplicateTable_W custInvoiceDuplicateTable = _args.record();
                _args.record(custInvoiceDuplicateTable.custInvoiceJour());
                formLetterController.parmDuplicateInvoiceRecId(custInvoiceDuplicateTable.RecId);
            }
           
            journalList = _args.record() ? FormLetter::createJournalListCopy(_args.record()) : _args.object();
            journalList.first(custInvoiceJour);

            switch (custInvoiceJour.custInvoiceJour_PL().FiscalDocState_PL)
            {
                case PlFiscalDocState::FiscalDocument:
                    try
                    {
                        PlFiscalPrinterHandling::generateFiscalDoc(custInvoiceJour);
                        return;
                    }
                    catch
                    {
                        // Allow execution to continue of PlFiscalPrinterHandling throws an error
                        return;
                    }
                case PlFiscalDocState::PrintedFiscalDocument:
                    info("@GLS110142");
                    return;
                default:
                    break;
            }
        }
        // </GEEPL>
        formLetterController.parmArgs(_args);
        // <GIN>
        if (SysCountryRegionCode::isLegalEntityInCountryRegion([#isoIN]))
        {
            journalList = _args.record() ? FormLetter::createJournalListCopy(_args.record()) : _args.object();
            journalList.first(custInvoiceJour);
            if (custInvoiceJour.isProforma())
            {
                common = SalesParmTable::findSalesId(custInvoiceJour.SalesId, custInvoiceJour.ParmId);
            }
            else
            {
                common = custInvoiceJour;
            }

            SalesInvoiceControllerEEMC salesInvoiceController = formLetterController;

            // <GTE><GIN>
            if (TaxGSTInvoiceHelper_IN::isGSTInvoice(common)
               && !custInvoiceJour.salesTable().CustomsExportOrder_IN)
            {
                salesInvoiceController.parmIsGSTInvoice_IN(true);
                formLetterController.parmReportName(ssrsReportStr(SalesInvoiceCopy, Report));
            }
            // </GIN></GTE>
            else
            {
                formLetterController.parmReportName(ssrsReportStr(SalesInvoiceCopy, Report));
            }
        }
        else if (SysCountryRegionCode::isLegalEntityInCountryRegion([#isoAE]))
        {
            formLetterController.parmReportName(ssrsReportStr(SalesInvoiceCopy, Report));
        }
        else
        {
            // </GIN>
            // <GTH>
            if (!CustInvoiceJourExtensionTH::canInvoiceBePrinted(_args))
            {
                return;
            }

            // print Thailand report
            if (TaxThaiGovCertificationFeatureChecker::isUnrealizedVATEnabled() && _args.parmEnum() != PrintCopyOriginal::OriginalPrint)
            {
                SalesInvoiceControllerEEMC::printDocumentSet(_args);
                return;
            }
            else
            {
                // </GTH>
               // formLetterController.parmReportName(PrintMgmtDocType::construct(PrintMgmtDocumentType::SalesOrderInvoice).getDefaultReportFormat());
                // <GTH>
                formLetterController.parmReportName(ssrsReportStr(SalesInvoiceCopy, Report));
            }
            // </GTH>
            // <GIN>
        }
        // </GIN>
        txt = formLetterController.parmReportName();
        formLetterController.parmReportName(ssrsReportStr(SalesInvoiceCopy, Report));
        formLetterController.parmShowDialog(false);
        formLetterController.parmDialogCaption("@SYS22766");
        formLetterController.startOperation();
    }

    /// <summary>
    ///     This method prints document set.
    /// </summary>
    /// <param name="_args">
    ///     The given args.
    /// </param>
    public static void printDocumentSet(Args _args)
    {
        GlobalizationInstrumentationHelper::featureRun(GlobalizationConstants::FeatureReferenceTH00004, funcName());

        // <GTH>
        SalesInvoiceControllerEEMC formLetterController = new SalesInvoiceControllerEEMC();
        SalesInvoiceJournalPrint salesInvoiceJournalPrintLocal;
        TaxUnrealizedDocuSetLine docuSetLineLocal;
        TaxUnrealizedDocuSetTable docuSetTableLocal;
        boolean firstSet = true;
        TaxUnrealizedDocuId docuCode;
        boolean printDocuSet = true;

        SRSCatalogItemName reportName = ssrsReportStr(SalesInvoiceCopy, Report);

        // true if print report in invoice posting, false if print report via invoice journal form.
        if (classIdGet(_args.caller()) == classNum(SalesInvoiceJournalPrint))
        {
            salesInvoiceJournalPrintLocal = _args.caller();
            docuCode = salesInvoiceJournalPrintLocal.parmDocuSetCode();
        }
        else
        {
            SalesDocumentSetSelector docuSetSelector = new SalesDocumentSetSelector();
            printDocuSet = docuSetSelector.run();
            if (printDocuSet && (docuSetSelector.getDocuCode()))
            {
                docuCode = docuSetSelector.getDocuCode();
                salesInvoiceJournalPrintLocal = SalesInvoiceJournalPrint::construct();
                salesInvoiceJournalPrintLocal.parmDocuSetCode(docuCode);
            }
        }

        if (printDocuSet)
        {
            formLetterController.parmArgs(_args);
            formLetterController.parmReportName(reportName);
            formLetterController.parmShowDialog(false);
            formLetterController.parmRunOnBlockMode_TH(true);
            formLetterController.startOperation();
        }

        // true to print document set.
        if (docuCode != '')
        {
            while select PrintHeader from docuSetLineLocal
                order by docuSetLineLocal.RecId
                join ProdType, Location, MiscText from docuSetTableLocal
                    where docuSetLineLocal.TaxUnrealizedDocuSetTable == docuSetTableLocal.RecId
                        && docuSetTableLocal.Code == docuCode
            {
                if (firstSet)
                {
                    salesInvoiceJournalPrintLocal.parmProdType(docuSetTableLocal.ProdType);
                    salesInvoiceJournalPrintLocal.parmLocation(docuSetTableLocal.Location);
                    salesInvoiceJournalPrintLocal.parmMiscText(docuSetTableLocal.MiscText);
                    firstSet = false;
                }
                salesInvoiceJournalPrintLocal.parmPrintHeader(docuSetLineLocal.PrintHeader);
                _args.caller(salesInvoiceJournalPrintLocal);
                formLetterController = new SalesInvoiceControllerEEMC();
                formLetterController.parmArgs(_args);
                formLetterController.parmReportName(reportName);
                formLetterController.parmShowDialog(false);
                formLetterController.startOperation();
            }
        }
        // </GTH>
    }

    /// <summary>
    ///     Gets the report header title for Malaysian.
    /// </summary>
    /// <param name="_custInvoiceJour">
    ///     The <c>CustInvoiceJour</c> Record for which we look for title.
    /// </param>
    /// <param name="_printCopyOriginal">
    ///     Printing type: Copy or Original
    /// </param>
    /// <param name="_isTaxInvoice">
    ///     The boolean sign which shows the it is a tax invoice or not (different titles)
    /// </param>
    /// <returns>
    ///     The report header title
    /// </returns>
    static str documentTitle_MY(
        custInvoiceJour _custInvoiceJour,
        PrintCopyOriginal _printCopyOriginal,
        boolean _isTaxInvoice = false)
    {
        str documentTitle;
        CustInvoiceJour_W custInvoiceJour_W = _custInvoiceJour.custInvoiceJour_W();

        NoteType_MY noteTypeLocal = custInvoiceJour_W.NoteType_MY;

        if (noteTypeLocal == NoteType_MY::Blank
            && _custInvoiceJour.InvoiceAmount < 0)
        {
            // When NoteType_MY is Blank and invoice amount < 0, will follow sys logic to print "Credit note".
            noteTypeLocal = NoteType_MY::CreditNote;
        }

        switch (noteTypeLocal)
        {
            case NoteType_MY::Blank:
                if (custInvoiceJour_W.InvoiceType_MY == InvoiceType_MY::Invoice || custInvoiceJour_W.InvoiceType_MY == InvoiceType_MY::ServiceInvoice)
                {
                    if (_printCopyOriginal == PrintCopyOriginal::Copy)
                    {
                        if (_custInvoiceJour.isProforma())
                        {
                            if (_custInvoiceJour.Prepayment)
                            {
                                documentTitle = SysLabel::labelId2String(literalStr("@SYS87980"), _custInvoiceJour.LanguageId);
                            }
                            else
                            {
                                documentTitle = SysLabel::labelId2String(literalStr("@SYS70789"), _custInvoiceJour.LanguageId);
                            }
                        }
                        else
                        {
                            if (_isTaxInvoice)
                            {
                                documentTitle = SysLabel::labelId2String(literalStr("@SYS121364"), _custInvoiceJour.LanguageId);
                            }
                            else
                            {
                                documentTitle = SysLabel::labelId2String(literalStr("@SYS24428"), _custInvoiceJour.LanguageId);
                            }
                        }
                    }
                    else
                    {
                        if (_custInvoiceJour.isProforma())
                        {
                            if (_custInvoiceJour.Prepayment)
                            {
                                documentTitle = SysLabel::labelId2String(literalStr("@SYS87979"), _custInvoiceJour.LanguageId);
                            }
                            else
                            {
                                if (_isTaxInvoice)
                                {
                                    documentTitle = SysLabel::labelId2String(literalStr("@SYS121362"), _custInvoiceJour.LanguageId);
                                }
                                else
                                {
                                    documentTitle = SysLabel::labelId2String(literalStr("@SYS4701"), _custInvoiceJour.LanguageId);
                                }
                            }
                        }
                        else
                        {
                            if (_isTaxInvoice)
                            {
                                documentTitle = SysLabel::labelId2String(literalStr("@SYS115505"), _custInvoiceJour.LanguageId);
                            }
                            else
                            {
                                documentTitle = SysLabel::labelId2String(literalStr("@SYS12128"), _custInvoiceJour.LanguageId);
                            }
                        }
                    }
                }
                else if (custInvoiceJour_W.InvoiceType_MY == InvoiceType_MY::GST)
                {
                    if (_printCopyOriginal == PrintCopyOriginal::Copy)
                    {
                        if (_custInvoiceJour.isProforma())
                        {
                            if (_custInvoiceJour.Prepayment)
                            {
                                documentTitle = SysLabel::labelId2String(literalStr("@SYS87980"), _custInvoiceJour.LanguageId);
                            }
                            else
                            {
                                documentTitle = SysLabel::labelId2String(literalStr("@SYS121363"), _custInvoiceJour.LanguageId);
                            }
                        }
                        else
                        {
                            documentTitle = SysLabel::labelId2String(literalStr("@SYS121364"), _custInvoiceJour.LanguageId);
                        }
                    }
                    else
                    {
                        if (_custInvoiceJour.isProforma())
                        {
                            if (_custInvoiceJour.Prepayment)
                            {
                                documentTitle = SysLabel::labelId2String(literalStr("@SYS87979"), _custInvoiceJour.LanguageId);
                            }
                            else
                            {
                                documentTitle = SysLabel::labelId2String(literalStr("@SYS121362"), _custInvoiceJour.LanguageId);
                            }
                        }
                        else
                        {
                            documentTitle = SysLabel::labelId2String(literalStr("@SYS115505"), _custInvoiceJour.LanguageId);
                        }
                    }
                }
                break;
            case NoteType_MY::CreditNote:
                if (_printCopyOriginal == PrintCopyOriginal::Copy)
                {
                    if (_custInvoiceJour.isProforma())
                    {
                        if (_custInvoiceJour.Prepayment)
                        {
                            documentTitle = SysLabel::labelId2String(literalStr("@SYS87981"), _custInvoiceJour.LanguageId);
                        }
                        else
                        {
                            documentTitle = SysLabel::labelId2String(literalStr("@SYS70790"), _custInvoiceJour.LanguageId);
                        }
                    }
                    else
                    {
                        documentTitle = SysLabel::labelId2String(literalStr("@SYS24607"), _custInvoiceJour.LanguageId);
                    }
                }
                else
                {
                    if (_custInvoiceJour.isProforma())
                    {
                        if (_custInvoiceJour.Prepayment)
                        {
                            documentTitle = SysLabel::labelId2String(literalStr("@SYS87981"), _custInvoiceJour.LanguageId);
                        }
                        else
                        {
                            documentTitle = SysLabel::labelId2String(literalStr("@SYS24608"), _custInvoiceJour.LanguageId);
                        }
                    }
                    else
                    {
                        documentTitle = SysLabel::labelId2String(literalStr("@SYS8125"), _custInvoiceJour.LanguageId);
                    }
                }
                break;
            case NoteType_MY::DebitNote:
                if (_printCopyOriginal == PrintCopyOriginal::Copy)
                {
                    if (_custInvoiceJour.isProforma())
                    {
                        if (_custInvoiceJour.Prepayment)
                        {
                            documentTitle = SysLabel::labelId2String(literalStr("@SYP4860810"), _custInvoiceJour.LanguageId);
                        }
                        else
                        {
                            documentTitle = SysLabel::labelId2String(literalStr("@SYP4860812"), _custInvoiceJour.LanguageId);
                        }
                    }
                    else
                    {
                        documentTitle = SysLabel::labelId2String(literalStr("@SYP4860807"), _custInvoiceJour.LanguageId);
                    }
                }
                else
                {
                    if (_custInvoiceJour.isProforma())
                    {
                        if (_custInvoiceJour.Prepayment)
                        {
                            documentTitle = SysLabel::labelId2String(literalStr("@SYP4860809"), _custInvoiceJour.LanguageId);
                        }
                        else
                        {
                            documentTitle = SysLabel::labelId2String(literalStr("@SYP4860811"), _custInvoiceJour.LanguageId);
                        }
                    }
                    else
                    {
                        documentTitle = SysLabel::labelId2String(literalStr("@SYP4860805"), _custInvoiceJour.LanguageId);
                    }
                }
                break;
        }

        return documentTitle;
    }

    /// <summary>
    /// Executes the report for the print management setting that is currently loaded.
    /// </summary>
    protected void outputReport_IN()
    {
        ITaxDocument taxDocument;
        TaxDocumentExtension_IN taxDocumentExtension;

        taxDocument = TaxBusinessService::getTaxDocumentBySource(custInvoiceJour.TableId, custInvoiceJour.RecId);
        if (taxDocument)
        {
            if (taxDocument.getGUID())
            {
               // taxDocumentExtension = taxDocumentExtension_in::findByTaxDocument(taxDocument.getGUID());
            }
        }

        GSTInvoiceDPBase_IN gstInvoiceDPBaseImp = new TaxGSTSalesOrderInvoiceDP_IN();
        PrintMgmtPrintSettingDetail detail = formLetterReport.getCurrentPrintSetting();

        gstInvoiceContract.parmInstanceType(detail.parmType());
        gstInvoiceContract.parmIdentificationText(detail.parmIdentificationText());

        switch (formLetterReport.getCurrentPrintSetting().parmType())
        {
            case PrintMgmtDocInstanceType::Copy : printCopyOriginal = PrintCopyOriginal::Copy;
                break;

            case PrintMgmtDocInstanceType::Original : printCopyOriginal = PrintCopyOriginal::OriginalPrint;
                break;
        }

        gstInvoiceContract.parmPrintCopyOriginal(printCopyOriginal);
        gstInvoiceContract.parmDocumentTitle(gstInvoiceDPBaseImp.documentTitle(
            custInvoiceJour.isProforma(),
            taxDocumentExtension,
            printCopyOriginal,
            ModuleType_IN::AccountsReceivable));
    }

    /// <summary>
    /// Sets the <c>SRSReportParameters</c> values to the report contract.
    /// </summary>
    protected void preRunModifyContract_IN()
    {
        SRSTmpDataStore srsTmpDataStore;
        GSTInvoiceHeaderFooterTmp_IN gstInvoiceHeaderFooterTmp_IN;

        if (!gstInvoiceContract)
        {
            gstInvoiceContract = this.parmReportContract().parmRdpContract();
        }

        gstInvoiceContract.parmPrintCopyOriginal(printCopyOriginal);

        gstInvoiceContract.parmRecordId(custInvoiceJour.RecId);
        gstInvoiceContract.parmledgerJournalTransRecordId(ledgerJournalTransRecId);
        gstInvoiceContract.parmGSTInvoiceControllerName(classId2Name(classIdGet(this)));
        this.parmReportContract().parmRdlContract().parmLanguageId(custInvoiceJour.LanguageId);

        if (salesInvoiceJournalPrint)
        {
            // Pack the class and insert into the temporary store.
            srsTmpDataStore.Value = salesInvoiceJournalPrint.pack();
            srsTmpDataStore.insert();

            // Set the rec id to contract parameter
            gstInvoiceContract.parmFormLetterRecordId(srsTmpDataStore.RecId);

            // To Capture the createdTransactionId.
            select firstonly JournalRecId, CreatedTransactionId from gstInvoiceHeaderFooterTmp_IN
                where gstInvoiceHeaderFooterTmp_IN.JournalRecId == custInvoiceJour.RecId;

            gstInvoiceContract.parmCreatedTransactionId(gstInvoiceHeaderFooterTmp_IN.createdTransactionId);
        }
    }

    public boolean parmIsGSTInvoice_IN(boolean _isGSTInvoice = isGSTInvoice)
    {
        // <GTE><GIN>
        isGSTInvoice = _isGSTInvoice;
        return isGSTInvoice;
        // </GTE></GIN>
    }

    private void initReportName_IN()
    {
        // <GTE><GIN>
        PrintMgmtPrintSettingDetail printSettingDetail;
        // </GTE></GIN>

        // <GIN>
        printSettingDetail = formLetterReport.getCurrentPrintSetting();

        if (printSettingDetail.parmReportFormatName() == PrintMgmtDocType::construct(PrintMgmtDocumentType::SalesOrderInvoice).getDefaultReportFormat())
        {
            // <GTE>
            if (printCopyOriginal == printCopyOriginal::Copy)
            {
                this.parmIsGSTInvoice_IN(
                    TaxGSTInvoiceHelper_IN::isGSTInvoice(custInvoiceJour)
                    && !custInvoiceJour.salesTable().CustomsExportOrder_IN);
                           
            }

            if (TaxSolutionScopeIntegrationUtil::isCompanyEnabled() && this.parmIsGSTInvoice_IN())
            {
                this.parmReportName(ssrsReportStr(SalesInvoiceCopy, Report));
            }
            else
            {
                // </GTE>
                this.parmReportName(ssrsReportStr(SalesInvoiceCopy, Report));
                // <GTE>
            }
        }
        else
        {
            this.parmReportName(ssrsReportStr(SalesInvoiceCopy, Report));
        }

        if (printCopyOriginal == printCopyOriginal::Copy)
        {
            if (preReportName && preReportName != this.parmReportName())
            {
                this.resetReportDataContract();
            }
            preReportName = this.parmReportName();
        }

        // </GTE>
        printSettingDetail.parmReportFormatName(this.parmReportName());
        // </GIN>
    }

    protected void new()
    {
        super();
    }

    public static SalesInvoiceControllerEEMC construct()
    {
        SalesInvoiceControllerEEMC controller = new SalesInvoiceControllerEEMC();

        return controller;
    }

    /// <summary>
    /// Adds extensibility to initialize the invoices for print.
    /// </summary>
    /// <param name="_salesInvoiceJournalPrint">
    /// The <c>SalesInvoiceJournalPrint</c> class.
    /// </param>
    /// <param name="_journalList">
    /// The <c>RecordSortedList</c> with invoice records.
    /// </param>
    [Hookable]
    public void initInvoiceForPrint(SalesInvoiceJournalPrint _salesInvoiceJournalPrint, RecordSortedList _journalList)
    {
    }

}