Concur import for General Ledger post by Pipe delimited

Contract Class
[DataContractAttribute,SysOperationContractProcessingAttribute(classstr(KGSPMIManualFileReadCSVUIBuilder))]
class KGSPMIManualFileReadCSVContract
{
//This code is not used
/// <summary>
/// Gets or sets the value of the datacontract parameter File.
/// </summary>
/// <param name="_fileName">
/// The new value of the datacontract parameter filename; optional.
/// </param>
/// <returns>
/// The current value of datacontract parameter filename
/// </returns>
private System.IO.Stream stream;
private Filename filename;
private boolean readDataFromBlob;
public System.IO.Stream parmStream(System.IO.Stream _stream = stream)
{
stream = _stream;
return stream;
}
public Filename parmFilename(Filename _fileName = fileName)
{
fileName = _fileName;
return fileName;
}
}

UIBuilderClass

class KGSPMIManualFileReadCSVUIBuilder extends SysOperationAutomaticUIBuilder
{
private const str fileUploadName = "Upload";


private const str okButtonName = "OK";

DialogGroup dialogGroup;

FormBuildControl formBuildControl;

FileUploadBuild dialogFileUpload;

   
public void build() {
 

super();

dialogGroup = dialog.addGroup("@SYS319541");
formBuildControl = dialog.formBuildDesign().control(dialogGroup.name());

dialogFileUpload = formBuildControl.addControlEx(classstr(FileUpload), FileUploadName);

dialogFileUpload.style(FileUploadStyle::MinimalWithFilename);

dialogFileUpload.baseFileUploadStrategyClassName(classstr(FileUploadTemporaryStorageStrategy));

dialogFileUpload.fileTypesAccepted(".csv");

dialogFileUpload.fileNameLabel("@SYS308842");
}

 

protected void setDialogOkButtonEnabled(FormRun _formRun, boolean _isEnabled)
{
FormControl okButtonControl = _formRun.control(_formRun.controlId(OkButtonName));
if (okButtonControl)
{
okButtonControl.enabled(_isEnabled);
}

}

 

private void uploadStarted()
{
var formRun = this.dialog().dialogForm().formRun();
this.setDialogOkButtonEnabled(formRun, false);
}

 

/// <summary>

/// Notify file upload status.

/// </summary>

protected void uploadCompleted()
{
var formRun = this.dialog().dialogForm().formRun();
FileUpload fileUpload = formRun.control(formRun.controlId(FileUploadName));

this.dataContractObject().parmStream(fileUpload.getUploadedFile(true));

this.dataContractObject().parmFilename(fileUpload.fileName());

fileUpload.notifyUploadCompleted -= eventhandler(this.UploadCompleted);

this.setDialogOkButtonEnabled(formRun, true);
}

 

/// <summary>

// Disables the dialog Ok button until the file upload is complete.

/// </summary>

public void postRun()
{
super();
var formRun = this.dialog().dialogForm().formRun();

FileUpload fileUpload = formRun.control(formRun.controlId(FileUploadName));

fileUpload.notifyUploadCompleted += eventhandler(this.uploadCompleted);

this.setDialogOkButtonEnabled(formRun, false);

}

}

Service Class

/// <summary>
///    The <c>KGSPMIConcurExpenseManualService</c> class acts as the service for the
///    <c>ConcurExpenseManual</c> class.
/// </summary>
class KGSPMIConcurExpenseManualService extends SysOperationServiceBase
{
    container                               conRecord;
    KGSPMIIntegrationParameters             integrationParameters;
    int                                     journalLinescnt;
    LedgerJournalName                       ledgerJournalName;
    LedgerJournalTable                      ledgerJournalTableLoc, ledgerJournalTablePost;
    KGSPMIPostConcur                        postConcur;
    LedgerJournalCheckPost                  ledgerJournalCheckPost;
    MainAccount                             mainAccount;
    LedgerJournalTrans_Project              ledgerJournalTrans_Project;
    ProjId                                  projId;
    KGSPMIConcurExpenseParameterCredit      concurExpenseParameterCredit;
    str          glDescription;
    LedgerJournalEngine      ledgerJournalEngine =  new LedgerJournalEngine();
   
    #Define.ReportCustom14(55)
    #Define.ReportCustom15(56)
    #Define.ReportID(19)
    #Define.BatchID(2)
    #Define.AmountDueEmployee(319)
    #Define.AmountDueCompanyCard(320)
    #Define.JournalAccountCode(167)
    #Define.JournalDebitorCredit(168)
    #Define.NetTaxAmount(247)
    #Define.ReimbursementCurrencyAlphaISE(22)
    #Define.EmployeeFirstName(7)
    #Define.ReportPaymentProcessingDate(26)
    #Define.ReportOrgUnit2(36)
    #Define.ReportOrgUnit3(37)
    #Define.ReportOrgUnit4(38)
    #Define.ReportEntryDescription(69)
    #Define.EmployeeID(5)
    #Define.CreditCardTransactionReferenceNumber(133)
    #Define.MiddleInitial(8)
    #Define.EmployeeLastName(6)
    /// <summary>
    ///    The <c>initiateProcess</c> Method acts as the Contract method for the
    ///    <c>ConcurExpenseManual</c> class.
    /// </summary>
    public void initiateProcess(KGSPMIManualFileReadCSVContract _contract)
    {
        System.IO.StreamReader          streamReader;
        str                             strRecord, firstRecord;
        LedgerJournalTrans              ledgerJournalTransReportID;
        integrationParameters = KGSPMIIntegrationParameters::find();
        delete_from postConcur;
        conRecord       = conNull();
        streamReader    = new System.IO.StreamReader(_contract.parmStream());
        firstRecord     = streamReader.ReadLine();//Skip first record header
        try
        {
            ttsbegin;
            if(!integrationParameters.ConcurExpensePerfectLedgerJournalNameId)//Checking the parameter field
            {
                throw Error("@KGSPMI:KGSPMIConcurExpenseParamValidationTxt");
            }
            strRecord           = streamReader.ReadLine();
            ledgerJournalName   =   LedgerJournalName::find(integrationParameters.ConcurExpensePerfectLedgerJournalNameId);
            while(!System.String::IsNullOrEmpty(strRecord))
            {
                conRecord = str2con(strRecord,'|');
                if (conRecord)
                {
                    if(conPeek(conRecord, #EmployeeFirstName))
                    {
                        glDescription = strFmt("%1", conPeek(conRecord, #EmployeeFirstName));
                    }
                    if(conPeek(conRecord, #MiddleInitial))
                    {
                        glDescription += strFmt(" %1", conPeek(conRecord, #MiddleInitial));
                    }
                    if(conPeek(conRecord, #EmployeeLastName))
                    {
                        glDescription += strFmt(" %1", conPeek(conRecord, #EmployeeLastName));
                    }
                   
     select count(RecId) from ledgerJournalTransReportID
      where ledgerJournalTransReportID.Invoice == conPeek(conRecord, #ReportID); //find the existing invoice
                    if(ledgerJournalTransReportID.RecId == 0)
                    {
                        if(conPeek(conRecord, #ReportCustom14))//Finding ProjectID
                        {
                            if(this.validateProjID(conPeek(conRecord, #ReportCustom14)))
                            {
                                this.createLedgerJournalHeader(ledgerJournalName);
                                this.createLedgerJournalLines(ledgerJournalName, ledgerJournalTableLoc.JournalNum);
                                postConcur = KGSPMIPostConcur::find(ledgerJournalTableLoc.JournalNum);
                                if(!postConcur)
                                {
                                    postConcur.JournalNum   =   ledgerJournalTableLoc.JournalNum;
                                    postConcur.insert();
                                }
                            }
       else
                            {
                                throw Error(strFmt("@KGSPMI:KGSPMIProjectIDValidate", conPeek(conRecord, #ReportCustom14)));
                            }
                        }
      else
                        {
                            this.createLedgerJournalHeader(ledgerJournalName);
                            this.createLedgerJournalLines(ledgerJournalName, ledgerJournalTableLoc.JournalNum);
                            postConcur = KGSPMIPostConcur::find(ledgerJournalTableLoc.JournalNum);
                            if(!postConcur)
                            {
                                postConcur.JournalNum   =   ledgerJournalTableLoc.JournalNum;
                                postConcur.insert();
                            }
                        }
                    }
                    else
                    {
                        select firstonly ledgerJournalTransReportID
       where ledgerJournalTransReportID.Invoice == conPeek(conRecord, #ReportID);
                        this.createLedgerJournalLines(ledgerJournalName, ledgerJournalTransReportID.JournalNum);
                    }
                }
                strRecord = streamReader.ReadLine();
            }
            ttscommit;
            while select JournalNum from postConcur
            {
                ledgerJournalTablePost  =   LedgerJournalTable::find(postConcur.JournalNum);
                ledgerJournalCheckPost  =   LedgerJournalCheckPost::newLedgerJournalTable(ledgerJournalTablePost, NoYes::Yes);
                ledgerJournalCheckPost.runOperation();
            }
            info(strFmt("@KGSPMI:KGSPMINumberOfJouLinesInserted", journalLinescnt));
        }
        catch
        {
            error(strFmt("@KGSPMI:KGSPMIConcurExpenseCreationErrorTxt", ledgerJournalTableLoc.JournalNum));
        }
    }
    /// <summary>
    /// Validates the Project Table record for ProjectID.
    /// </summary>
    /// <param name="_ProjID">
    /// The Project Table record which is to be validated.
    /// </param>
    /// <returns>
    /// true if the Project Table record is valid; otherwise, false.
    /// </returns>
    Public boolean validateProjID(str  _ProjID)
    {
        boolean  ret = true;
        ProjTable projTableLoc;
        select firstonly projTableLoc
   where projTableLoc.ProjId == _ProjID;
        if(projTableLoc)
        {
            ret = true;
        }
  else
        {
            ret = false;
        }
        return ret;
    }
 //Validate Project Status
    //Public boolean validateProjStatus(container  _con)
    //{
    //    boolean  ret = true;
    //    ProjTable projTableLoc;
    //    select firstonly projTableLoc where projTableLoc.ProjId == conPeek(_con, #ReportCustom14);
    //    if(projTableLoc.Status != ProjStatus::Completed)
    //        ret = true;
    //    else
    //        ret = false;
    //    return ret;
    //}
    /// <summary>
    /// Validates the VendTable record for Vendor On Hold.
    /// </summary>
    /// <param name="_vendID">
    /// The VendTable record which is to be validated.
    /// </param>
    /// <returns>
    /// true if the VendTable record is valid; otherwise, false.
    /// </returns>
    Public boolean validateVendorOnHold(str  _vendID)
    {
        boolean  ret = true;
        VendTable vendTable;
        select firstonly vendTable
   where vendTable.AccountNum == _vendID;
        if(vendTable.Blocked == CustVendorBlocked::No)
        {
            ret = true;
        }
        else
        {
            ret = false;
        }
        return ret;
    }
    /// <summary>
    /// Validates the VendTable record for VendorID.
    /// </summary>
    /// <param name="_vendID">
    /// The VendTable record which is to be validated.
    /// </param>
    /// <returns>
    /// true if the VendTable record is valid; otherwise, false.
    /// </returns>
    Public boolean validateVendorID(str _vendID)
    {
        boolean  ret = true;
        VendTable vendTable;
        select firstonly vendTable
   where vendTable.AccountNum == _vendID;
        if(vendTable)
        {
            ret = true;
        }
        else
        {
            ret = false;
        }
        return ret;
    }
    /// <summary>
    /// Creates LedgerJournalHeader records in <c>ledgerJournalTable</c>.
    /// </summary>
    /// <param name="_ledgerJournalName">
    /// The <c>LedgerJournalName</c> record.
    /// </param>
    public void createLedgerJournalHeader(LedgerJournalName   _ledgerJournalName)
    {
        ledgerJournalTableLoc.clear();
        ledgerJournalTableLoc.initValue();
        ledgerJournalTableLoc.initFromLedgerJournalName(_ledgerJournalName.JournalName);
        ledgerJournalTableLoc.JournalName   =   _ledgerJournalName.JournalName;
        ledgerJournalTableLoc.Name          =   strFmt("%1-%2-%3",conPeek(conRecord, #ReportID), conPeek(conRecord, #BatchID), glDescription);
        ledgerJournalTableLoc.JournalNum    =   NumberSeq::newGetNum(LedgerParameters::numRefJournalNum()).num();
        if(ledgerJournalTableLoc.validateWrite())
        {
            ledgerJournalTableLoc.insert();
        }
        else
        {
            Throw Exception::Error;
        }
    }
    /// <summary>
    /// Creates LedgerJournalTrans_Project records in <c>LedgerJournalTrans_Project</c>.
    /// </summary>
    /// <param name="_ledgerJournalTrans">
    /// The <c>LedgerJournalTrans</c> record.
    /// </param>
    /// /// <param name="_projCategoryID">
    /// The <c>str</c> record.
    /// </param>
    /// /// <param name="_projID">
    /// The <c>ProjId</c> record.
    /// </param>
    public  void createLedgerJournalTrans_Project(LedgerJournalTrans  _ledgerJournalTrans, str  _projCategoryID, ProjId  _projID)
    {
        DimensionAttributeValueCombination          dimensionAttributeValueCombination;
        TrvCostType                                 costType;
        CategoryTable                               categoryTable;
        ProjLineProperty       projLineProperty;
        ProjTable         projTableLoc;
        select firstonly LinePropertyId from projLineProperty;
        select firstonly projTableLoc
   where projTableLoc.ProjId == _projID;
        select firstonly ledgerJournalTrans_Project
   where ledgerJournalTrans_Project.RefRecId == _ledgerJournalTrans.RecId;
        if(!ledgerJournalTrans_Project)
        {
            select firstonly mainAccount
    where mainAccount.MainAccountId == _projCategoryID;
            if(mainAccount)
            {
                select firstonly dimensionAttributeValueCombination
     where dimensionAttributeValueCombination.DisplayValue == mainAccount.MainAccountId;
                if(dimensionAttributeValueCombination)
                {
                    select firstonly costType
      where costType.LedgerDimension      == dimensionAttributeValueCombination.RecId;
                    select firstonly categoryTable
      where categoryTable.CategoryId == costType.CostType;
                }
            }
            // Set the project specific journal fields.
            ledgerJournalTrans_Project.clear();
            ledgerJournalTrans_Project.RefRecId      = _ledgerJournalTrans.RecId;
            ledgerJournalTrans_Project.ProjId      = _ledgerJournalTrans.parmAccount();
            ledgerJournalTrans_Project.CategoryId     = categoryTable.CategoryId;
            ledgerJournalTrans_Project.Module      =   ModuleAxapta::Project;
            ledgerJournalTrans_Project.LinePropertyId    = projLineProperty.LinePropertyId;
            ledgerJournalTrans_Project.SalesCurrencyId    = ProjInvoiceTable::find(projTableLoc.ProjInvoiceProjId).CurrencyId;
            ledgerJournalTrans_Project.ProjTransDate    = _ledgerJournalTrans.TransDate;
            ledgerJournalTrans_Project.Qty       = 1;
            if (!ledgerJournalTrans_Project.SalesCurrencyId)
            {
                if (projTableLoc.CustAccount)
                {
                    ledgerJournalTrans_Project.SalesCurrencyId  = CustTable::find(projTableLoc.CustAccount).Currency;
                }
                else
                {
                    ledgerJournalTrans_Project.SalesCurrencyId  = CompanyInfoHelper::standardCurrency();
                }
            }
            ledgerJournalTrans_Project.CostPrice     = _ledgerJournalTrans.AmountCurDebit;
            ledgerJournalTrans_Project.TaxGroupSales    = _ledgerJournalTrans.TaxGroup;
            ledgerJournalTrans_Project.TaxItemGroupSales   = _ledgerJournalTrans.TaxItemGroup;
            ledgerJournalTrans_Project.insert();
        }
    }
    /// <summary>
    /// Creates LedgerJournalTrans lines records in <c>LedgerJournalTrans</c>.
    /// </summary>
    /// <param name="_ledgerJournalName">
    /// The <c>LedgerJournalName</c> record.
    /// </param>
    /// /// <param name="_ledgerJournalId">
    /// The <c>LedgerJournalId</c> record.
    /// </param>
    public void createLedgerJournalLines(LedgerJournalName   _ledgerJournalName, LedgerJournalId   _ledgerJournalId)
    {
        LedgerJournalTrans      ledgerJournalTrans;
        NumberSeq               numberSeq;
        NumberSequenceTable     numberSeqTable;
        Voucher                 voucher;
        container               acctPattern, acctPatternOffset;
        ProjTable               projTable;
        str                     defaultDimensionDisplayValue, projCategoryID, creditCardReferenceValue, mainAccountName;
        str                     creditCardReference = conPeek(conRecord, #CreditCardTransactionReferenceNumber);
        VendTable    vendTable;
        str      offsetDepartment, offsetAmex, offsetPcard;
        str      AirfareCaptial = 'Airfare';
        str      airfareSmall = 'airfare';
        str      amex   = 'Amex';
        str      debitValue  = 'DR';
        str      offsetDepartmentValue = '0000';
        //Lines
        projCategoryID    =   conPeek(conRecord, #ReportCustom15);
        creditCardReferenceValue    =   subStr(creditCardReference, strLen(creditCardReference) -3, 4);
        vendTable     = VendTable::find(conPeek(conRecord, #EmployeeID));
        if(conPeek(conRecord, #JournalAccountCode))
        {
            defaultDimensionDisplayValue     =   strFmt("%1", conPeek(conRecord, #JournalAccountCode));
        }
        if (conPeek(conRecord, #ReportOrgUnit2) != 0)
        {
            defaultDimensionDisplayValue += strFmt("-%1", conPeek(conRecord, #ReportOrgUnit2));
        }
        if (conPeek(conRecord, #ReportOrgUnit3) != 0)
        {
            defaultDimensionDisplayValue += strFmt("-%1", conPeek(conRecord, #ReportOrgUnit3));
        }
        if (conPeek(conRecord, #ReportOrgUnit4) != 0)
        {
            defaultDimensionDisplayValue += strFmt("-%1", conPeek(conRecord, #ReportOrgUnit4));
        }
        if (conPeek(conRecord, #ReportOrgUnit2) != 0)
        {
            offsetDepartment = strFmt("%1", conPeek(conRecord, #ReportOrgUnit2));
        }
  else
        {
            offsetDepartment = offsetDepartmentValue;
        }
        //checking projectID based on ReportCustom14
        select firstonly projTable
   where projTable.ProjId == conPeek(conRecord, #ReportCustom14);
        if(projTable)
        {
            //Checking CorporateCard
            if(conPeek(conRecord, #AmountDueCompanyCard))
            {
                //Checking AmexCard
                mainAccount = MainAccount::findByMainAccountId(conPeek(conRecord, #JournalAccountCode));
                mainAccountName = mainAccount.Name;
                if(strScan(mainAccountName, AirfareCaptial, 1, strLen(mainAccountName)) || strScan(mainAccountName, airfareSmall, 1, strLen(mainAccountName)))
                {
                    ledgerJournalTrans.clear();
                    ledgerJournalTrans.initValue();
                    ledgerJournalTrans.JournalNum               =   _ledgerJournalId;
                    ledgerJournalTrans.TransDate                =   str2Date(conPeek(conRecord, #ReportPaymentProcessingDate), 213);
                    select firstonly numberSeqTable
      where numberSeqTable.RecId == _ledgerJournalName.NumberSequenceTable;
                    if(numberSeqTable && !voucher)
                    {
                        numberSeq   =   NumberSeq::newGetVoucherFromCode(numberSeqTable.NumberSequence);
                        voucher     =   numberSeq.voucher();
                    }
                    ledgerJournalTrans.Voucher                  =   voucher;
                    ledgerJournalTrans.AccountType              =   LedgerJournalACType::Ledger;
                    acctPattern                                 =   KGSPMIDimensionUtility::getLedgerDimContainerFromLedgerFormat(defaultDimensionDisplayValue);
                    ledgerJournalTrans.LedgerDimension          =   KGSPMIDimensionUtility::generateLedgerDimension(acctPattern);
                   
     if(creditCardReferenceValue)
                    {
                        ledgerJournalTrans.Txt                  =   strFmt("@KGSPMI:KGSPMIAmexString", conPeek(conRecord, #ReportID), glDescription, creditCardReferenceValue);
                    }
                    else
                    {
                        ledgerJournalTrans.Txt                  =   strFmt("%1-%2", conPeek(conRecord, #ReportID), glDescription);
                    }
                    if(conPeek(conRecord, #JournalDebitorCredit) == debitValue)
                    {
                        ledgerJournalTrans.AmountCurDebit       =   conPeek(conRecord, #NetTaxAmount);
                        ledgerJournalTrans.AmountCurCredit      =   0;
                    }
                    else
                    {
                        ledgerJournalTrans.AmountCurDebit       =   0;
                        ledgerJournalTrans.AmountCurCredit      =   conPeek(conRecord, #NetTaxAmount);
                    }
                    ledgerJournalTrans.OffsetAccountType        =   LedgerJournalACType::Ledger;
                    select firstonly concurExpenseParameterCredit
                        where concurExpenseParameterCredit.PaymentMode == amex;
                    offsetAmex         = strFmt("%1-%2", concurExpenseParameterCredit.AccountNumber, offsetDepartment);
                    acctPatternOffset                           =   KGSPMIDimensionUtility::getLedgerDimContainerFromLedgerFormat(offsetAmex);
                    ledgerJournalTrans.OffsetLedgerDimension    =   KGSPMIDimensionUtility::generateLedgerDimension(acctPatternOffset);
                    ledgerJournalTrans.CurrencyCode             =   conPeek(conRecord,#ReimbursementCurrencyAlphaISE);
                    ledgerJournalEngine.accountNumModified(ledgerJournalTrans);
                    ledgerJournalEngine.accountModified(ledgerJournalTrans);
                    ledgerJournalTrans.Invoice                  =   conPeek(conRecord, #ReportID);
                    ledgerJournalTrans.Due      = str2Date(conPeek(conRecord, #ReportPaymentProcessingDate), 213);
                    ledgerJournalTrans.TransactionType   = LedgerTransType::GeneralJournal;
                    if(ledgerJournalTrans.validateWrite())
                    {
                        ledgerJournalTrans.insert();
                        journalLinescnt++;
                    }
                    else
                    {
                        Throw Exception::Error;
                    }
                }
                //Pcard
                else
                {
                    ledgerJournalTrans.clear();
                    ledgerJournalTrans.initValue();
                    ledgerJournalTrans.JournalNum               =   _ledgerJournalId;
                    ledgerJournalTrans.TransDate                =   str2Date(conPeek(conRecord, #ReportPaymentProcessingDate), 213);
                    select firstonly numberSeqTable
      where numberSeqTable.RecId == _ledgerJournalName.NumberSequenceTable;
                    if(numberSeqTable && !voucher)
                    {
                        numberSeq   =   NumberSeq::newGetVoucherFromCode(numberSeqTable.NumberSequence);
                        voucher     =   numberSeq.voucher();
                    }
                    ledgerJournalTrans.Voucher                  =   voucher;
                    ledgerJournalTrans.AccountType              =   LedgerJournalACType::Ledger;
                    acctPattern                                 =   KGSPMIDimensionUtility::getLedgerDimContainerFromLedgerFormat(defaultDimensionDisplayValue);
                    ledgerJournalTrans.LedgerDimension          =   KGSPMIDimensionUtility::generateLedgerDimension(acctPattern);
                    if(creditCardReferenceValue)
                    {
                        ledgerJournalTrans.Txt                  =   strFmt("@KGSPMI:KGSPMIPCardString", conPeek(conRecord, #ReportID), glDescription, creditCardReferenceValue);
                    }
                    else
                    {
                        ledgerJournalTrans.Txt                  =   strFmt("%1-%2", conPeek(conRecord, #ReportID), glDescription);
                    }
                    if(conPeek(conRecord, #JournalDebitorCredit) == debitValue)
                    {
                        ledgerJournalTrans.AmountCurDebit       =   conPeek(conRecord, #NetTaxAmount);
                        ledgerJournalTrans.AmountCurCredit      =   0;
                    }
                    else
                    {
                        ledgerJournalTrans.AmountCurDebit       =   0;
                        ledgerJournalTrans.AmountCurCredit      =   conPeek(conRecord, #NetTaxAmount);
                    }
                    ledgerJournalTrans.OffsetAccountType        =   LedgerJournalACType::Ledger;
                    select firstonly concurExpenseParameterCredit
                        where concurExpenseParameterCredit.PaymentMode != amex;
                    offsetPcard         = strFmt("%1-%2", concurExpenseParameterCredit.AccountNumber, offsetDepartment);
                    acctPatternOffset                           =   KGSPMIDimensionUtility::getLedgerDimContainerFromLedgerFormat(offsetPcard);
                    ledgerJournalTrans.OffsetLedgerDimension    =   KGSPMIDimensionUtility::generateLedgerDimension(acctPatternOffset);
                    ledgerJournalTrans.CurrencyCode             =   conPeek(conRecord,#ReimbursementCurrencyAlphaISE);
                    ledgerJournalEngine.accountNumModified(ledgerJournalTrans);
                    ledgerJournalEngine.accountModified(ledgerJournalTrans);
                    ledgerJournalTrans.Invoice                  =   conPeek(conRecord, #ReportID);
                    ledgerJournalTrans.Due      = str2Date(conPeek(conRecord, #ReportPaymentProcessingDate), 213);
                    ledgerJournalTrans.TransactionType   = LedgerTransType::GeneralJournal;
                    if(ledgerJournalTrans.validateWrite())
                    {
                        ledgerJournalTrans.insert();
                        journalLinescnt++;
                    }
                    else
                    {
                        Throw Exception::Error;
                    }
                }
            }
            //Vendor
            else
            {
                if(this.validateVendorID(conPeek(conRecord, #EmployeeID)))
                {
                    if(this.validateVendorOnHold(conPeek(conRecord, #EmployeeID)))
                    {
                        ledgerJournalTrans.clear();
                        ledgerJournalTrans.initValue();
                        ledgerJournalTrans.JournalNum                   =   _ledgerJournalId;
                        ledgerJournalTrans.TransDate                    =   str2Date(conPeek(conRecord, #ReportPaymentProcessingDate), 213);
                        select firstonly numberSeqTable
                            where numberSeqTable.RecId == _ledgerJournalName.NumberSequenceTable;
                        if(numberSeqTable && !voucher)
                        {
                            numberSeq   =   NumberSeq::newGetVoucherFromCode(numberSeqTable.NumberSequence);
                            voucher     =   numberSeq.voucher();
                        }
                        ledgerJournalTrans.Voucher                      =   voucher;
                        ledgerJournalTrans.AccountType                  =   LedgerJournalACType::Project;
                        projId                                          =   conPeek(conRecord, #ReportCustom14);
                        ledgerJournalTrans.LedgerDimension              =   KGSPMIDimensionUtility::generateDynamicAccount(LedgerJournalACType::Project, projId);
                        ledgerJournalTrans.DefaultDimension             =   projTable.DefaultDimension;
                        if(creditCardReferenceValue)
                        {
                            ledgerJournalTrans.Txt      =   strFmt("%1-%2-%3", conPeek(conRecord, #ReportID), glDescription, creditCardReferenceValue);
                        }
                        else
                        {
                            ledgerJournalTrans.Txt      =   strFmt("%1-%2", conPeek(conRecord, #ReportID), glDescription);
                        }
                        if(conPeek(conRecord, #JournalDebitorCredit) == debitValue)
                        {
                            ledgerJournalTrans.AmountCurDebit           =   conPeek(conRecord, #NetTaxAmount);
                            ledgerJournalTrans.AmountCurCredit          =   0;
                        }
                        else
                        {
                            ledgerJournalTrans.AmountCurDebit           =   0;
                            ledgerJournalTrans.AmountCurCredit          =   conPeek(conRecord, #NetTaxAmount);
                        }
                        ledgerJournalTrans.OffsetAccountType            =   LedgerJournalACType::Vend;
                        ledgerJournalTrans.OffsetLedgerDimension        =   KGSPMIDimensionUtility::generateDynamicAccount(LedgerJournalACType::Vend, vendTable.AccountNum);
                        ledgerJournalTrans.OffsetDefaultDimension  = vendTable.DefaultDimension;
                        ledgerJournalTrans.CurrencyCode                 =   conPeek(conRecord,#ReimbursementCurrencyAlphaISE);
                        ledgerJournalEngine.accountNumModified(ledgerJournalTrans);
                        ledgerJournalEngine.accountModified(ledgerJournalTrans);
                        ledgerJournalTrans.TaxGroup      = vendTable.TaxGroup;
                        ledgerJournalTrans.PaymMode      = vendTable.PaymMode;
                        ledgerJournalTrans.Invoice                      =   conPeek(conRecord, #ReportID);
                        ledgerJournalTrans.Due       = str2Date(conPeek(conRecord, #ReportPaymentProcessingDate), 213);
                        ledgerJournalTrans.TransactionType    = LedgerTransType::GeneralJournal;
                        ledgerJournalTrans.Approved      = NoYes::Yes;
                        if(ledgerJournalTrans.validateWrite())
                        {
                            ledgerJournalTrans.insert();
                            this.createLedgerJournalTrans_Project(ledgerJournalTrans, projCategoryID,projId);
                            journalLinescnt++;
                        }
                        else
                        {
                            Throw Exception::Error;
                        }
                    }
     else
                    {
                        throw Error(strFmt("@KGSPMI:KGSPMIVendorIDonHold",conPeek(conRecord, #EmployeeID)));
                    }
                }
    else
                {
                    throw Error(strFmt("@KGSPMI:KGSPMIVendorIDValidate",conPeek(conRecord, #EmployeeID)));
                }
            }
        }
        //Not a ProjectID
        else
        {
            //Checking CorporateCard
            if(conPeek(conRecord, #AmountDueCompanyCard))
            {
                mainAccount =   MainAccount::findByMainAccountId(conPeek(conRecord, #JournalAccountCode));
                mainAccountName = mainAccount.Name;
                if(strScan(mainAccountName, AirfareCaptial, 1, strLen(mainAccountName)) || strScan(mainAccountName, airfareSmall, 1, strLen(mainAccountName)))
                {
                    ledgerJournalTrans.clear();
                    ledgerJournalTrans.initValue();
                    ledgerJournalTrans.JournalNum               =   _ledgerJournalId;
                    ledgerJournalTrans.TransDate                =   str2Date(conPeek(conRecord, #ReportPaymentProcessingDate), 213);
                    select firstonly numberSeqTable
      where numberSeqTable.RecId == _ledgerJournalName.NumberSequenceTable;
                    if(numberSeqTable && !voucher)
                    {
                        numberSeq   =   NumberSeq::newGetVoucherFromCode(numberSeqTable.NumberSequence);
                        voucher     =   numberSeq.voucher();
                    }
                    ledgerJournalTrans.Voucher                  =   voucher;
                    ledgerJournalTrans.AccountType              =   LedgerJournalACType::Ledger;
                    acctPattern                                 =   KGSPMIDimensionUtility::getLedgerDimContainerFromLedgerFormat(defaultDimensionDisplayValue);
                    ledgerJournalTrans.LedgerDimension          =   KGSPMIDimensionUtility::generateLedgerDimension(acctPattern);
                    if(creditCardReferenceValue)
                    {
                        ledgerJournalTrans.Txt                  =   strFmt("@KGSPMI:KGSPMIAmexString", conPeek(conRecord, #ReportID), glDescription, creditCardReferenceValue);
                    }
                    else
                    {
                        ledgerJournalTrans.Txt                  =   strFmt("%1-%2", conPeek(conRecord, #ReportID), glDescription);
                    }
                    if(conPeek(conRecord, #JournalDebitorCredit) == debitValue)
                    {
                        ledgerJournalTrans.AmountCurDebit       =   conPeek(conRecord, #NetTaxAmount);
                        ledgerJournalTrans.AmountCurCredit      =   0;
                    }
                    else
                    {
                        ledgerJournalTrans.AmountCurDebit       =   0;
                        ledgerJournalTrans.AmountCurCredit      =   conPeek(conRecord, #NetTaxAmount);
                    }
                    ledgerJournalTrans.OffsetAccountType        =   LedgerJournalACType::Ledger;
                    select firstonly concurExpenseParameterCredit
                        where concurExpenseParameterCredit.PaymentMode == amex;
                    offsetAmex                                 = strFmt("%1-%2", concurExpenseParameterCredit.AccountNumber, offsetDepartment);
                    acctPatternOffset                           =   KGSPMIDimensionUtility::getLedgerDimContainerFromLedgerFormat(offsetAmex);
                    ledgerJournalTrans.OffsetLedgerDimension    =   KGSPMIDimensionUtility::generateLedgerDimension(acctPatternOffset);
                    ledgerJournalTrans.CurrencyCode             =   conPeek(conRecord,#ReimbursementCurrencyAlphaISE);
                    ledgerJournalEngine.accountNumModified(ledgerJournalTrans);
                    ledgerJournalEngine.accountModified(ledgerJournalTrans);
                    ledgerJournalTrans.Invoice                  =   conPeek(conRecord, #ReportID);
                    ledgerJournalTrans.Due      = str2Date(conPeek(conRecord, #ReportPaymentProcessingDate), 213);
                    ledgerJournalTrans.TransactionType   = LedgerTransType::GeneralJournal;
                    if(ledgerJournalTrans.validateWrite())
                    {
                        ledgerJournalTrans.insert();
                        journalLinescnt++;
                    }
                    else
                    {
                        Throw Exception::Error;
                    }
                }
                //Pcard
                else
                {
                    ledgerJournalTrans.clear();
                    ledgerJournalTrans.initValue();
                    ledgerJournalTrans.JournalNum               =   _ledgerJournalId;
                    ledgerJournalTrans.TransDate                =   str2Date(conPeek(conRecord, #ReportPaymentProcessingDate), 213);
                    select firstonly numberSeqTable
      where numberSeqTable.RecId == _ledgerJournalName.NumberSequenceTable;
                    if(numberSeqTable && !voucher)
                    {
                        numberSeq   =   NumberSeq::newGetVoucherFromCode(numberSeqTable.NumberSequence);
                        voucher     =   numberSeq.voucher();
                    }
                    ledgerJournalTrans.Voucher                  =   voucher;
                    ledgerJournalTrans.AccountType              =   LedgerJournalACType::Ledger;
                    acctPattern                                 =   KGSPMIDimensionUtility::getLedgerDimContainerFromLedgerFormat(defaultDimensionDisplayValue);
                    ledgerJournalTrans.LedgerDimension          =   KGSPMIDimensionUtility::generateLedgerDimension(acctPattern);
                    if(creditCardReferenceValue)
                    {
                        ledgerJournalTrans.Txt                  =   strFmt("@KGSPMI:KGSPMIPCardString", conPeek(conRecord, #ReportID), glDescription, creditCardReferenceValue);
                    }
                    else
                    {
                        ledgerJournalTrans.Txt                  =   strFmt("%1-%2", conPeek(conRecord, #ReportID), glDescription);
                    }
                    if(conPeek(conRecord, #JournalDebitorCredit) == debitValue)
                    {
                        ledgerJournalTrans.AmountCurDebit       =   conPeek(conRecord, #NetTaxAmount);
                        ledgerJournalTrans.AmountCurCredit      =   0;
                    }
                    else
                    {
                        ledgerJournalTrans.AmountCurDebit       =   0;
                        ledgerJournalTrans.AmountCurCredit      =   conPeek(conRecord, #NetTaxAmount);
                    }
                    ledgerJournalTrans.OffsetAccountType        =   LedgerJournalACType::Ledger;
                    select firstonly concurExpenseParameterCredit
                        where concurExpenseParameterCredit.PaymentMode != amex;
                    offsetPcard         = strFmt("%1-%2", concurExpenseParameterCredit.AccountNumber, offsetDepartment);
                    acctPatternOffset                           =   KGSPMIDimensionUtility::getLedgerDimContainerFromLedgerFormat(offsetPcard);
                    ledgerJournalTrans.OffsetLedgerDimension    =   KGSPMIDimensionUtility::generateLedgerDimension(acctPatternOffset);
                    ledgerJournalTrans.CurrencyCode             =   conPeek(conRecord,#ReimbursementCurrencyAlphaISE);
                    ledgerJournalEngine.accountNumModified(ledgerJournalTrans);
                    ledgerJournalEngine.accountModified(ledgerJournalTrans);
                    ledgerJournalTrans.Invoice                  =   conPeek(conRecord, #ReportID);
                    ledgerJournalTrans.Due      = str2Date(conPeek(conRecord, #ReportPaymentProcessingDate), 213);
                    ledgerJournalTrans.TransactionType   = LedgerTransType::GeneralJournal;
                    if(ledgerJournalTrans.validateWrite())
                    {
                        ledgerJournalTrans.insert();
                        journalLinescnt++;
                    }
                    else
                    {
                        Throw Exception::Error;
                    }
                }
            }
            //Vendor
            else
            {
                if(this.validateVendorID(conPeek(conRecord, #EmployeeID)))
                {
                    if(this.validateVendorOnHold(conPeek(conRecord, #EmployeeID)))
                    {
                        ledgerJournalTrans.clear();
                        ledgerJournalTrans.initValue();
                        ledgerJournalTrans.JournalNum                   =   _ledgerJournalId;
                        ledgerJournalTrans.TransDate                    =   str2Date(conPeek(conRecord, #ReportPaymentProcessingDate), 213);
                        select firstonly numberSeqTable
       where numberSeqTable.RecId == _ledgerJournalName.NumberSequenceTable;
                        if(numberSeqTable && !voucher)
                        {
                            numberSeq   =   NumberSeq::newGetVoucherFromCode(numberSeqTable.NumberSequence);
                            voucher     =   numberSeq.voucher();
                        }
                        ledgerJournalTrans.Voucher                      =   voucher;
                        ledgerJournalTrans.AccountType                  =   LedgerJournalACType::Ledger;
                        acctPattern          =   KGSPMIDimensionUtility::getLedgerDimContainerFromLedgerFormat(defaultDimensionDisplayValue);
                        ledgerJournalTrans.LedgerDimension    =   KGSPMIDimensionUtility::generateLedgerDimension(acctPattern);
                        if(creditCardReferenceValue)
                        {
                            ledgerJournalTrans.Txt      =   strFmt("%1-%2-%3", conPeek(conRecord, #ReportID), glDescription, creditCardReferenceValue);
                        }
                        else
                        {
                            ledgerJournalTrans.Txt      =   strFmt("%1-%2", conPeek(conRecord, #ReportID), glDescription);
                        }
                        if(conPeek(conRecord, #JournalDebitorCredit) == debitValue)
                        {
                            ledgerJournalTrans.AmountCurDebit           =   conPeek(conRecord, #NetTaxAmount);
                            ledgerJournalTrans.AmountCurCredit          =   0;
                        }
                        else
                        {
                            ledgerJournalTrans.AmountCurDebit           =   0;
                            ledgerJournalTrans.AmountCurCredit          =   conPeek(conRecord, #NetTaxAmount);
                        }
                        ledgerJournalTrans.OffsetAccountType            =   LedgerJournalACType::Vend;
                        vendTable          = VendTable::find(conPeek(conRecord, #EmployeeID));
                        ledgerJournalTrans.OffsetLedgerDimension        =   KGSPMIDimensionUtility::generateDynamicAccount(LedgerJournalACType::Vend, vendTable.AccountNum);
                        ledgerJournalTrans.OffsetDefaultDimension  = vendTable.DefaultDimension;
                        ledgerJournalTrans.CurrencyCode                 =   conPeek(conRecord,#ReimbursementCurrencyAlphaISE);
                        ledgerJournalEngine.accountNumModified(ledgerJournalTrans);
                        ledgerJournalEngine.accountModified(ledgerJournalTrans);
                        ledgerJournalTrans.TaxGroup      = vendTable.TaxGroup;
                        ledgerJournalTrans.PaymMode      = vendTable.PaymMode;
                        ledgerJournalTrans.Invoice                      =   conPeek(conRecord, #ReportID);
                        ledgerJournalTrans.Due       = str2Date(conPeek(conRecord, #ReportPaymentProcessingDate), 213);
                        ledgerJournalTrans.TransactionType    = LedgerTransType::GeneralJournal;
                        ledgerJournalTrans.Approved      = NoYes::Yes;
                        if(ledgerJournalTrans.validateWrite())
                        {
                            ledgerJournalTrans.insert();
                            this.createLedgerJournalTrans_Project(ledgerJournalTrans, projCategoryID,projId);
                            journalLinescnt++;
                        }
                        else
                        {
                            Throw Exception::Error;
                        }
                    }
                    else
                    {
                        throw Error(strFmt("@KGSPMI:KGSPMIVendorIDonHold",conPeek(conRecord, #EmployeeID)));
                    }
                }
                else
                {
                    throw Error(strFmt("@KGSPMI:KGSPMIVendorIDValidate",conPeek(conRecord, #EmployeeID)));
                }
            }
        }
    }
}


Controller Class


/// <summary>
/// The <c>KGSPMIConcurExpenseManualController</c> class acts as the controller for the
/// <c>KGSPMIConcurExpenseManual</c> class.
/// </summary>
class KGSPMIConcurExpenseManualController extends SysOperationServiceController
{
/// <summary>


/// Initializes a new instance of the <c>KGSPMIConcurExpenseManualController</c> class.

/// </summary>

/// <remarks>

/// The <c>SysOperationServiceController.initializeFromArgs</c> method can also be used to initialize a

/// controller. If those options for initialization are used the default values can be used in the

/// constructor.

/// </remarks>

protected void new()
{
super(classstr(KGSPMIConcurExpenseManualService),methodStr(KGSPMIConcurExpenseManualService, initiateProcess), SysOperationExecutionMode::Synchronous); }


/// <summary>

/// Gets a caption for a record based on the title fields of the record.

/// </summary>

/// <returns>

/// A caption for the specified record.

/// </returns>

public ClassDescription caption()
{ return "@KGSPMI:KGSPMIConcurExpenseImportCaption"; }



/// <summary>

/// Gets a default caption for a record based on the title fields of the record.

/// </summary>

/// <returns>

/// A caption for the specified record.

/// </returns>

protected ClassDescription defaultCaption() {

return "@KGSPMI:KGSPMIConcurExpenseImportDescription"; }
 

/// <summary>

/// Initailzes the controller, assigns parameter values and runs the SRS report.

/// </summary>

/// <param name="_args">

/// The <c>Args</c> object.

/// </param>

public static void main(Args _args) {
KGSPMIConcurExpenseManualController controller;


controller = new KGSPMIConcurExpenseManualController();

controller.startOperation(); }

}


KGSPMIIntegrationDataImportExportSettings

/// <summary>
/// Extract settings for PMI integration based on integration type.
/// </summary>
class KGSPMIIntegrationDataImportExportSettings
{
    str     outfilePath, inFilePath, successFilePath, errorFilePath;
   
    public static boolean isPMIIntegration(DMFEntityName _entity)
    {
        boolean ret;
        switch(_entity)
        {
            case tableId2PName(tableNum(KGSPMIConcurVendorsEntity)):
                ret = true;
                break;
            case tableId2PName(tableNum(KGSPMIProdMasterPriceTrackerEntity)):
                ret = true;
                break;
            case tableId2PName(tableNum(KGSPMIPriceDiscAdm)):
                ret = true;
                break;
            //Concur dimension
            case tableId2PName(tableNum(KGSPmiDimensionAttributeValueEntity)):
                ret = true;
                break;
        }
        return ret;
    }
    public static KGSPMIIntegrationType getIntegrationTypeFromDataEntity(DMFEntityName _entity)
    {
        KGSPMIIntegrationType integrationType;
        switch(_entity)
        {
            case tableId2PName(tableNum(KGSPMIConcurVendorsEntity)):
                integrationType = KGSPMIIntegrationType::ConcurVendor;
                break;
            case tableId2PName(tableNum(KGSPMIProdMasterPriceTrackerEntity)):
                integrationType = KGSPMIIntegrationType::MagentoProduct;
                break;
            case tableId2PName(tableNum(KGSPMIPriceDiscAdm)):
                integrationType = KGSPMIIntegrationType::MagentoPrice;
                break;
            //Concur dimension
            case tableId2PName(tableNum(KGSPmiDimensionAttributeValueEntity)):
                integrationType = KGSPMIIntegrationType::ConcurDimension;
                break;
            default:
                throw error(strFmt("@KGSPMI:KGSPMIIntegrationTypeNotFoundForEntity",_entity));
        }
        return integrationType;
    }
    public static KGSPMIIntegrationDataImportExportSettings construct(KGSPMIIntegrationType _integrationType)
    {
       
        KGSPMIIntegrationDataImportExportSettings  integrationDataImportExportSettings;
        integrationDataImportExportSettings         = new KGSPMIIntegrationDataImportExportSettings();
       
        switch(_integrationType)
        {
            case KGSPMIIntegrationType::CRMInvoice:
                integrationDataImportExportSettings.validateAndConstructCRMInvoiceSettings();
                break;
            case KGSPMIIntegrationType::ConcurVendor:
                integrationDataImportExportSettings.validateAndConstructConcurVendorSettings();
                break;
            case KGSPMIIntegrationType::MagentoProduct:
                integrationDataImportExportSettings.validateAndConstructMagentoProductSettings();
                break;
            case KGSPMIIntegrationType::UltiproHRM:
                integrationDataImportExportSettings.validateAndConstructUltiproHRMSettings();
                break;
            case KGSPMIIntegrationType::MagentoPrice:
                integrationDataImportExportSettings.validateAndConstructMagentoPriceSettings();
                break;
            case KGSPMIIntegrationType::UltiproGLPayroll:
                integrationDataImportExportSettings.validateAndConstructUltiproGLSettings();
                break;
            case KGSPMIIntegrationType::DonorPerfectGL:
                integrationDataImportExportSettings.validateAndConstructDonorPerfectGLSettings();
                break;
            case KGSPMIIntegrationType::CRMPayment:
                integrationDataImportExportSettings.validateAndConstructCRMPaymentSettings();
                break;
            //Concur Dimension
            case KGSPMIIntegrationType::ConcurDimension:
                integrationDataImportExportSettings.validateAndConstructconcurDimensions();
                break;
            //concur Dimension
           

            case KGSPMIIntegrationType::ConcurExpenseGL:
                integrationDataImportExportSettings.validateAndConstructConcurExpenseGLSettings();
                break;
            case KGSPMIIntegrationType::CRMRevenueRecognition:
                integrationDataImportExportSettings.validateAndConstructCRMRevenueRecognitionGLSettings();
                break;

            default:
                throw error(strFmt("@KGSPMI:KGSPMIUnableToFetchIntegrationSetup",enum2Str(_integrationType)));
        }
        return integrationDataImportExportSettings;
    }
    public str parmOutFilePath(str _outfilePath = outfilePath)
    {
        outfilePath = _outfilePath;
        return outfilePath;
    }
    public str parmInFilePath(str _inFilePath = inFilePath)
    {
        inFilePath = _inFilePath;
        return inFilePath;
    }
    public str parmSuccessFilePath(str _successFilePath = successFilePath)
    {
        successFilePath = _successFilePath;
        return successFilePath;
    }
    public str parmErrorFilePath(str _errorFilePath = errorFilePath)
    {
        errorFilePath = _errorFilePath;
        return errorFilePath;
    }
    /// <summary>
    /// Validates the KGSPMIIntegrationParameters Table record for CRMInvoiceSettings File,Success and Error.
    /// </summary>
    public void validateAndConstructCRMInvoiceSettings()
    {
        KGSPMIIntegrationParameters     integrationParametersLoc = KGSPMIIntegrationParameters::find();
        if(!integrationParametersLoc.CRMInFilePath || !integrationParametersLoc.CRMSuccessFilePath || !integrationParametersLoc.CRMErrorFilePath)
        {
            throw Error(strFmt("@KGSPMI:KGSPMIIntegrationParameterMissingTxt", enum2Str(KGSPMIIntegrationType::CRMInvoice)));
        }
        this.parmInFilePath(integrationParametersLoc.CRMInFilePath);
        this.parmSuccessFilePath(integrationParametersLoc.CRMSuccessFilePath);
        this.parmErrorFilePath(integrationParametersLoc.CRMErrorFilePath);
    }
    /// <summary>
    /// Validates the KGSPMIIntegrationParameters Table record for ConcurVendorSettings File,Success,Error.
    /// </summary>
    public void validateAndConstructConcurVendorSettings()
    {
        KGSPMIIntegrationParameters     integrationParametersLoc = KGSPMIIntegrationParameters::find();
        if(!integrationParametersLoc.ConcurVendorOutFilePath )
        {
            throw Error(strFmt("@KGSPMI:KGSPMIIntegrationParameterMissingTxt", enum2Str(KGSPMIIntegrationType::ConcurVendor)));
        }
        this.parmOutFilePath(integrationParametersLoc.ConcurVendorOutFilePath);
    }
    /// <summary>
    /// Validates the KGSPMIIntegrationParameters Table record for MagentoProductSettings File,Success,Error.
    /// </summary>
    public void validateAndConstructMagentoProductSettings()
    {
        KGSPMIIntegrationParameters     integrationParametersLoc = KGSPMIIntegrationParameters::find();
        if(!integrationParametersLoc.MagentoProdMasterOutputFilePath )
        {
            throw Error(strFmt("@KGSPMI:KGSPMIIntegrationParameterMissingTxt", enum2Str(KGSPMIIntegrationType::MagentoProduct)));
        }
        this.parmOutFilePath(integrationParametersLoc.MagentoProdMasterOutputFilePath);
    }
    /// <summary>
    /// Validates the KGSPMIIntegrationParameters Table record for UltiproHRMSettings File,Success,Error.
    /// </summary>
    public void validateAndConstructUltiproHRMSettings()
    {
        KGSPMIIntegrationParameters     integrationParametersLoc = KGSPMIIntegrationParameters::find();
        if(!integrationParametersLoc.UltiproHRInFilePath || !integrationParametersLoc.UltiproHRSuccessFilePath || !integrationParametersLoc.UltiproHRErrorFilePath)
        {
            throw Error(strFmt("@KGSPMI:KGSPMIIntegrationParameterMissingTxt", enum2Str(KGSPMIIntegrationType::UltiproHRM)));
        }
        this.parmInFilePath(integrationParametersLoc.UltiproHRInFilePath);
        this.parmSuccessFilePath(integrationParametersLoc.UltiproHRSuccessFilePath);
        this.parmErrorFilePath(integrationParametersLoc.UltiproHRErrorFilePath);
    }
    /// <summary>
    /// Validates the KGSPMIIntegrationParameters Table record for MagentoPriceSettings File,Success,Error.
    /// </summary>
    public void validateAndConstructMagentoPriceSettings()
    {
        KGSPMIIntegrationParameters     integrationParametersLoc = KGSPMIIntegrationParameters::find();
        if(!integrationParametersLoc.MagentoPriceAgreementOutputFilePath )
        {
            throw Error(strFmt("@KGSPMI:KGSPMIIntegrationParameterMissingTxt", enum2Str(KGSPMIIntegrationType::MagentoPrice)));
        }
        this.parmOutFilePath(integrationParametersLoc.MagentoPriceAgreementOutputFilePath);
    }
    /// <summary>
    /// Validates the KGSPMIIntegrationParameters Table record for UltiproGLSettings File,Success,Error.
    /// </summary>
    public void validateAndConstructUltiproGLSettings()
    {
        KGSPMIIntegrationParameters     integrationParametersLoc = KGSPMIIntegrationParameters::find();
        if(!integrationParametersLoc.UltiproGLInFilePath || !integrationParametersLoc.UltiproGLSuccessFilePath || !integrationParametersLoc.UltiproGLErrorFilePath)
        {
            throw Error("@KGSPMI:KGSPMIIntegrationParameterMissingTxt", enum2Str(KGSPMIIntegrationType::UltiproGLPayroll));
        }
        this.parmInFilePath(integrationParametersLoc.UltiproGLInFilePath);
        this.parmSuccessFilePath(integrationParametersLoc.UltiproGLSuccessFilePath);
        this.parmErrorFilePath(integrationParametersLoc.UltiproGLErrorFilePath);
    }
    /// <summary>
    /// Validates the KGSPMIIntegrationParameters Table record for DonorPerfectGLSettings File,Success,Error.
    /// </summary>
    public void validateAndConstructDonorPerfectGLSettings()
    {
        KGSPMIIntegrationParameters     integrationParametersLoc = KGSPMIIntegrationParameters::find();
        if(!integrationParametersLoc.DonorPerfectGLInFilePath || !integrationParametersLoc.DonorPerfectGLSuccessFilePath || !integrationParametersLoc.DonorPerfectGLErrorFilePath)
        {
            throw Error("@KGSPMI:KGSPMIIntegrationParameterMissingTxt", enum2Str(KGSPMIIntegrationType::DonorPerfectGL));
        }
        this.parmInFilePath(integrationParametersLoc.DonorPerfectGLInFilePath);
        this.parmSuccessFilePath(integrationParametersLoc.DonorPerfectGLSuccessFilePath);
        this.parmErrorFilePath(integrationParametersLoc.DonorPerfectGLErrorFilePath);
    }
    /// <summary>
    /// Validates the KGSPMIIntegrationParameters Table record for CRMPaymentSettings File,Success,Error.
    /// </summary>
    public void validateAndConstructCRMPaymentSettings()
    {
        KGSPMIIntegrationParameters     integrationParametersLoc = KGSPMIIntegrationParameters::find();
        if(!integrationParametersLoc.CRMPaymentInFilePath || !integrationParametersLoc.CRMPaymentSuccessFilePath || !integrationParametersLoc.CRMPaymentErrorFilePath)
        {
            throw Error(strFmt("@KGSPMI:KGSPMIIntegrationParameterMissingTxt", enum2Str(KGSPMIIntegrationType::CRMPayment)));
        }
        this.parmInFilePath(integrationParametersLoc.CRMPaymentInFilePath);
        this.parmSuccessFilePath(integrationParametersLoc.CRMPaymentSuccessFilePath);
        this.parmErrorFilePath(integrationParametersLoc.CRMPaymentErrorFilePath);
    }
    /// <summary>
    /// Validates the KGSPMIIntegrationParameters Table record for concurDimensions File,Success,Error.
    /// </summary>
    public void validateAndConstructconcurDimensions()
    {
        KGSPMIIntegrationParameters     integrationParametersLoc = KGSPMIIntegrationParameters::find();
        if(!integrationParametersLoc.ConcurDimensionOutputFilePath )
        {
            throw Error(strFmt("@KGSPMI:KGSPMIIntegrationParameterMissingTxt", enum2Str(KGSPMIIntegrationType::ConcurDimension)));
        }
        this.parmOutFilePath(integrationParametersLoc.ConcurDimensionOutputFilePath);
    }
    /// <summary>
    /// Validates the KGSPMIIntegrationParameters Table record for ConcurExpenseGLSettings File,Success,Error.
    /// </summary>
    public void validateAndConstructConcurExpenseGLSettings()
    {
        KGSPMIIntegrationParameters     integrationParametersLoc = KGSPMIIntegrationParameters::find();
        if(!integrationParametersLoc.ConcurExpensePerfectGLInFilePath || !integrationParametersLoc.ConcurExpensePerfectGLSuccessFilePath || !integrationParametersLoc.ConcurExpenseGLErrorFilePath)
        {
            throw Error(strFmt("@KGSPMI:KGSPMIIntegrationParameterMissingTxt", enum2Str(KGSPMIIntegrationType::ConcurExpenseGL)));
        }
        this.parmInFilePath(integrationParametersLoc.ConcurExpensePerfectGLInFilePath);
        this.parmSuccessFilePath(integrationParametersLoc.ConcurExpensePerfectGLSuccessFilePath);
        this.parmErrorFilePath(integrationParametersLoc.ConcurExpenseGLErrorFilePath);
    }
    /// <summary>
    /// To validate CRM revenue recognition parameter setup
    /// </summary>
    public void validateAndConstructCRMRevenueRecognitionGLSettings()
    {
        KGSPMIIntegrationParameters     integrationParametersLoc = KGSPMIIntegrationParameters::find();
        if (!integrationParametersLoc.CRMRevenueRecognitionGLInFilePath || !integrationParametersLoc.CRMRevenueRecognitionGLSuccessFilePath || !integrationParametersLoc.CRMRevenueRecognitionGLErrorFilePath)
        {
            throw Error("@KGSPMI:KGSPMIIntegrationParameterMissingTxt", enum2Str(KGSPMIIntegrationType::CRMRevenueRecognition));
        }
        this.parmInFilePath(integrationParametersLoc.CRMRevenueRecognitionGLInFilePath);
        this.parmSuccessFilePath(integrationParametersLoc.CRMRevenueRecognitionGLSuccessFilePath);
        this.parmErrorFilePath(integrationParametersLoc.CRMRevenueRecognitionGLErrorFilePath);
    }
}

KGSPMIDimensionUtility

/// <summary>
/// Utility class for Dimensions.
/// </summary>
 
class KGSPMIDimensionUtility{
public static RefRecId generateDynamicAccount(LedgerJournalACType _type, str _account)


{


DimensionDynamicAccountServiceProvider dimensionDynamicAccountServiceProvider;DimensionAttributeValueContract ledgerContract;
DimensionStorageResult dimensionStorageResult;


DimensionDynamicAccountContract contract;


contract = new DimensionDynamicAccountContract();
contract.parmAccountType(_type);
contract.parmCompany(curExt());


ledgerContract = DimensionAttributeValueContract::construct(enum2Str(_type), _account);
contract.parmPrimaryDimensionAttributeValue(ledgerContract);
dimensionDynamicAccountServiceProvider = DimensionDynamicAccountServiceProvider::newForDynamicAccountContract(contract);

dimensionStorageResult = dimensionDynamicAccountServiceProvider.resolve();


return dimensionStorageResult.parmSavedRecId();
}


public static RefRecId generateLedgerDimension(container _con)
{


LedgerAccountContract LedgerAccountContract = new LedgerAccountContract();
DimensionAttributeValueContract ValueContract;
List valueContracts = new List(Types::Class);
dimensionAttributeValueCombination dimensionAttributeValueCombination;
int counter = 1;
LedgerRecId ledgerRecId;
DimensionStorage dimStorage;
LedgerAccountContract.parmMainAccount(conPeek(_con, counter));
counter++;


while(counter <= conlen(_con))
{
ValueContract = new DimensionAttributeValueContract();

//Add to list only when dimension value is available

if(conPeek(_con, (counter + 1)))
{
ValueContract.parmName(conPeek(_con, counter));
counter++;
ValueContract.parmValue(conPeek(_con, counter));
counter++;
valueContracts.addEnd(ValueContract);
}
}
LedgerAccountContract.parmValues(valueContracts);
dimStorage = DimensionServiceProvider::buildDimensionStorageForLedgerAccount(LedgerAccountContract);

dimensionAttributeValueCombination = DimensionAttributeValueCombination::find(dimStorage.save());
ledgerRecId = dimensionAttributeValueCombination.RecId;

return ledgerRecId;
}
 

public static RefRecId generateDefaultDimension(container _con)
{
DimensionNameValueListContract dimensionNameValueListContract;

DimensionAttributeValueContract dimensionAttributeValueContract;
DimensionStorageResult dimensionStorageResult;
DimensionNameValueListServiceProvider dimensionNameValueListServiceProvider;
int counter = 1;
str name, value;
dimensionNameValueListContract = new DimensionNameValueListContract();
dimensionNameValueListContract.parmValues(new List(Types::Class));
while(counter <= conlen(_con)) {
name = conpeek(_con,counter);
counter++;
value = conpeek(_con,counter);
counter++;
dimensionAttributeValueContract = DimensionAttributeValueContract::construct(name, value); dimensionNameValueListContract.parmValues().addEnd(dimensionAttributeValueContract);
}



//resolve the dimension
dimensionNameValueListServiceProvider = DimensionNameValueListServiceProvider::newForDimensionNameValueListContract(dimensionNameValueListContract); dimensionStorageResult = dimensionNameValueListServiceProvider.resolve();
   
return dimensionStorageResult.parmSavedRecId(); }



public static str getDimensionDisplayValue(RefRecId _dimRecId) {
str displayValue;

DimensionAttributeValueSetItem dimSetItem;
while select DisplayValue from dimSetItem
order by dimSetItem.RecId
where dimSetItem.DimensionAttributeValueSet == _dimRecId {
displayValue += dimSetItem.DisplayValue + '-'; }
        return displayValue;


}
 

public static String255 getDimensionvalue(RefRecId _dimension, Name _dimName)
{
DimensionAttributeValueSetStorage dimStorage; dimStorage = DimensionAttributeValueSetStorage::find(_dimension);
return dimStorage.getDisplayValueByDimensionAttribute(DimensionAttribute::findByName(_dimName).RecId); }


public static container getLedgerDimContainerFromLedgerFormat(str _dispalyValue, DimensionDataEntityStructureType _dimensionDataEntityStructureType = DimensionDataEntityStructureType::DataEntityLedgerDimensionFormat) {
List dimensionNames;

ListEnumerator lstEnumdimensionNames;
container acctPattern, dimension;
int counter = 1;
dimensionNames = DimensionResolver::splitByDimensionIntegrationDelimiter(DimensionHierarchy::getDisplayStringDimensionIntegrationStructure(_dimensionDataEntityStructureType));
dimension = str2con_RU(_dispalyValue, '-'); acctPattern = conNull();
lstEnumdimensionNames = dimensionNames.getEnumerator();
while(lstEnumdimensionNames.moveNext()) {


if( lstEnumdimensionNames.current() == "@KGSPMI:KGSPMIMainAccount") {
acctPattern = conIns(acctPattern, 1, conPeek(dimension, counter));

}
else

{
if(conPeek(dimension, counter)) {
acctPattern = conIns(acctPattern, (conLen(acctPattern) + 1), lstEnumdimensionNames.current());


acctPattern = conIns(acctPattern, (conLen(acctPattern) + 1), conPeek(dimension, counter)); }
}
counter++;
}
return acctPattern;            }



public static boolean validateLedgerDimContainerFromLedgerFormat(str _dispalyValue, DimensionDataEntityStructureType _dimensionDataEntityStructureType = DimensionDataEntityStructureType::DataEntityLedgerDimensionFormat) {
List dimensionNames;

ListEnumerator lstEnumdimensionNames;
container dimension;
int counter = 1;
str dimensionValue;
boolean ret = true;
dimensionNames = DimensionResolver::splitByDimensionIntegrationDelimiter(DimensionHierarchy::getDisplayStringDimensionIntegrationStructure(_dimensionDataEntityStructureType));
dimension = str2con_RU(_dispalyValue, '-'); lstEnumdimensionNames = dimensionNames.getEnumerator();
while(lstEnumdimensionNames.moveNext()) {
dimensionValue = conPeek(dimension, counter);
            if(lstEnumdimensionNames.current() == "@KGSPMI:KGSPMIMainAccount")


{
if(!MainAccount::findByMainAccountId(dimensionValue)) {
                    ret = checkFailed(strfmt("@KGSPMI:KGSPMIMainAccountNotAvailable", dimensionValue)); }
}



else
{
if(conPeek(dimension, counter)) {
                    if(!DimensionAttributeValue::findByDimensionAttributeAndValue(DimensionAttribute::findByName(lstEnumdimensionNames.current()), dimensionValue)) {
                        ret = checkFailed(strfmt("@KGSPMI:KGSPMIDimensionNotInSystem", lstEnumdimensionNames.current(), dimensionValue)); }
}
}
counter++;
}
        return ret;




}
}
 
















Comments

Popular posts from this blog

Data entites method calling sequence in D365FO

How to Extend Sales Order Update Functionality to Custom Fields in D365 Finance and Operations

To generate dimension and find the account value - KGSPMIDimensionUtility