Wednesday, 29 April 2020

Stack trace: Binding operation failed to allocate buffer space AX 2012

Stack trace: Binding operation failed to allocate buffer space



this.query().literals(1);
or

query().literals(1);

Monday, 2 March 2020

Update worker Default Dimensions

Update worker Default Dimensions
static void updateWorkerDIm(Args _args)
{
    #File
     Dialog         dialog;
    Filename        filename;
    DialogField     dialogFilename;
    DataAreaId      companyCode;

    HcmWorker       hcmWorker;
    HcmEmployment   hcmEmployment;
    HcmPersonnelNumberId        hcmRecId;
    container           ledgerdimensionheader;
    DimensionDefault    dimensiondefaultheader;
    Struct structHdr    = new Struct();
    boolean             first = true;

    //To filter the files while selecting
    container    conFilter = ["Comma Seperated Value .txt ", "*.csv"];
    IO                  iO;
    FilenameOpen        filenameOpen;
    Container           record;

    dialog = new dialog();
    dialog.caption("Select File to update workers");
    dialogFilename = dialog.addField(extendedTypeStr(FilenameOpen));
    //To filter the files while selecting
    dialog.filenameLookupFilter(conFilter);
    dialog.run();

      if(dialog.closedOk())
    {
        filename = dialogFileName.value();
    }

    iO = new CommaTextIo(filename,#IO_Read);
    if (! iO || iO.status() != IO_Status::Ok)
    {
        throw error("@SYS19358");
    }

     try
    {
        ttsBegin;
        while (iO.status() == IO_Status::Ok)
        {
            record = iO.read();// To read file
            if (record)
            {
                if (first)  //To skip header
                {
                    first = false;
                }
                else
                {                   
                    hcmRecId = conpeek(record, 1);
                    hcmWorker = HcmWorker::findByPersonnelNumber(hcmRecId);
                    while select forUpdate hcmEmployment order by RecId asc where hcmEmployment.Worker == hcmWorker.RecId
                        //&& hcmEmployment.EmploymentType != 1
                    {
                        structHdr.remove('Worker');
                       
                        structHdr.add('Worker', hcmWorker.PersonnelNumber);
                        ledgerDimensionHeader += structHdr.fields();
                        ledgerDimensionHeader += structHdr.fieldName(1);
                        ledgerDimensionHeader += structHdr.valueIndex(1);
                        dimensionDefaultHeader = AxdDimensionUtil::getDimensionAttributeValueSetId(ledgerDimensionHeader);
                       
                        hcmEmployment.DefaultDimension  = dimensionDefaultHeader;
                        hcmEmployment.validTimeStateUpdateMode(ValidTimeStateUpdate::Correction);
                        hcmEmployment.update();
                        ledgerDimensionHeader = conDel(ledgerDimensionHeader,1,30);
                    }

                }
            }
        }
        info('Imported successfully');
        ttsCommit;

    }
    catch(Exception::Error)
    {
        error('An Exception has occurred');
    }


}

Thursday, 20 February 2020

Create and post General Journal

Create and post General Journal

public void run()
{
    Name                        journalName;
    AmountMST                   expenseAssesableValue;

    ProjParameters              projParameters;
    ALE_PayrollRun              payrollRun,payrollRunGroup;
    ALE_PayrollCodeMappingTable payrollCodeMappingTable;
    ALE_ProjAllocationDetails   projAllocationDetails,projAllocationDetailsUpdate;
    DimensionAttributeValueCombination  ledgerDimensionvalueCombination,davc;

    AxLedgerJournalTable        journalTable; // class
    AxLedgerJournalTrans        journalTrans; // class
    LedgerJournalTrans          ledgerJournalTrans;
    LedgerJournalTrans_Project  ledgerJournalTrans_Project;

    LedgerJournalTransTaxExtensionIN    ledgerJournalTransTaxExtensionIN;
    LedgerJournalTrans_ProjectTaxExtensionIN    ledgerJournalTrans_ProjectTaxExtensionIN;
    RefRecId                    recId;
    DimensionDefault            workerDim,mergedDim;
    DimensionDefault            projDim;
    LedgerDimensionAccount      offsetLD;
    DefaultDimensionView        dimView;
    Ledger                      ledger;

    ledgerJournalCheckPost      ledgerJournalCheckPost;// table

    select JournalNameIdRevenue from projParameters;
    ttsBegin;
    try
    {
        while select projAllocationDetails group by ProjId,EmployeeId,MonthYear where projAllocationDetails.Status == '0'
        {
            while select payrollRunGroup group by EmployeeId,MonthYear where payrollRunGroup.EmployeeId == projAllocationDetails.EmployeeId
            {
                //delete_from reveueAllocationFeeTmp;
                journalTable = new AxLedgerJournalTable();
                journalTrans = new AxLedgerJournalTrans();
                //Journal Name
                journalTable.parmJournalName(projParameters.JournalNameIdRevenue);//"Genjur");
                journalName = LedgerJournalName::find(projParameters.JournalNameIdRevenue).Name + '-' + projAllocationDetails.ProjId + ' - ' + strFmt("%1",projAllocationDetails.Projdate);
                journalTable.parmName(journalName);

                journalTable.save();

                select AccountingCurrency from ledger where ledger.Name == curext();
                while select EmployeeId,ProjId,Projdate FROM projAllocationDetailsUpdate
                    join Amount,BatchType,PayrollCode from payrollRun where projAllocationDetailsUpdate.EmployeeId == projAllocationDetails.EmployeeId
                    && projAllocationDetailsUpdate.Status == '0' && projAllocationDetailsUpdate.ProjId == projAllocationDetails.ProjId
                    && payrollRun.EmployeeId == projAllocationDetailsUpdate.EmployeeId
                    && payrollRun.MonthYear == payrollRunGroup.MonthYear
                {
                    ledgerJournalTrans.clear();
                    journalTrans.parmJournalNum(journalTable.ledgerJournalTable().JournalNum);
                    journalTrans.parmTransDate(projAllocationDetailsUpdate.Projdate);
                    journalTrans.parmCurrencyCode(ledger.AccountingCurrency);


                    journalTrans.parmAccountType(LedgerJournalACType::Project);

                    select ledgerDimensionvalueCombination where ledgerDimensionvalueCombination.DisplayValue == projAllocationDetailsUpdate.ProjId;

                    if(ledgerDimensionvalueCombination.recid != 0)
                    {
                        journalTrans.parmLedgerDimension(ledgerDimensionvalueCombination.recid);
                    }
                    else
                    {
                        recId = DimensionStorage::getDynamicAccount( projAllocationDetailsUpdate.ProjId, 3, 129);

                        davc = DimensionAttributeValueCombination::find(recId);

                        journalTrans.parmLedgerDimension(davc.RecId);

                    }
                    //ledgerDim = DimensionDefaultingService::serviceCreateLedgerDimension( projDim);
                    //journalTrans.parmLedgerDimension(ledgerDim);
                    select DefaultDimension from dimView where dimView.DisplayValue == projAllocationDetailsUpdate.EmployeeId;
                    workerDim = dimView.DefaultDimension;
                   
                    projDim = ProjTable::find(projAllocationDetailsUpdate.ProjId).DefaultDimension;
                   
                    mergedDim      = DimensionDefaultingService::serviceMergeDefaultDimensions(projDim,workerDim);
                   
                    journalTrans.parmDefaultDimension(mergedDim);

                    if(ALE_PayrollCodeMappingTable::findByPayrollCode(payrollRun.PayrollCode).ALE_PayrollCodeType == 0 )
                    {
                        journalTrans.parmAmountCurDebit(abs(payrollRun.Amount));
                    }
                    else
                    {
                        journalTrans.parmAmountCurCredit(abs(payrollRun.Amount));
                    }


                    select AccountCode,CategoryId FROM  payrollCodeMappingTable where payrollCodeMappingTable.PayrollCode == payrollRun.PayrollCode;

                    ledgerDimensionvalueCombination.clear();
                    select ledgerDimensionvalueCombination where ledgerDimensionvalueCombination.MainAccount == MainAccount::findByMainAccountId( payrollCodeMappingTable.AccountCode).RecId;
                   
                    offsetLD = DimensionDefaultingService::serviceCreateLedgerDimension( ledgerDimensionvalueCombination.RecId,projDim,workerDim);


                    journalTrans.parmOffsetLedgerDimension(offsetLD);
                    journalTrans.parmOffsetAccountType(LedgerJournalACType::Ledger );

                    journalTrans.save();

                    ledgerJournalTrans = journalTrans.ledgerJournalTrans();
                    ledgerJournalTransTaxExtensionIN.LedgerJournalTrans = ledgerJournalTrans.RecId;
                    ledgerJournalTransTaxExtensionIN.insert();
                    if(ledgerJournalTrans)
                    {

                        ledgerJournalTrans_Project.ProjTransDate = systemDateGet();
                        if(ledgerJournalTrans.AmountCurDebit > 0)
                        {
                            ledgerJournalTrans_Project.CostPrice = ledgerJournalTrans.AmountCurDebit;
                            ledgerJournalTrans_Project.Qty = 1;
                        }
                        else
                        {
                            ledgerJournalTrans_Project.CostPrice = ledgerJournalTrans.AmountCurCredit;
                            ledgerJournalTrans_Project.Qty = -1;
                        }

                        ledgerJournalTrans_Project.SalesCurrencyId = ledgerJournalTrans.CurrencyCode;


                        ledgerJournalTrans_Project.LinePropertyId = "Billable";


                        ledgerJournalTrans_Project.ProjId = projAllocationDetailsUpdate.ProjId;

                        ledgerJournalTrans_Project.RefRecId = ledgerJournalTrans.RecId;
                        ledgerJournalTrans_Project.CategoryId = payrollCodeMappingTable.CategoryId;



                        ledgerJournalTrans_Project.Worker = HcmWorker::findByPersonnelNumber(projAllocationDetailsUpdate.EmployeeId).RecId;

                        ledgerJournalTrans_Project.insert();

                        ledgerJournalTrans_ProjectTaxExtensionIN.LedgerJournalTrans_Project = ledgerJournalTrans_Project.RecId;
                        expenseAssesableValue  = ledgerJournalTrans_Project.Qty * ledgerJournalTrans_Project.SalesPrice;
                        ledgerJournalTrans_ProjectTaxExtensionIN.AssessableValue = expenseAssesableValue;

                        ledgerJournalTrans_ProjectTaxExtensionIN.insert();

                        ledgerJournalTrans_Project.clear();


                    }

                }
                if(ledgerJournalTrans.RecId)
                {
                    ledgerJournalCheckPost = ledgerJournalCheckPost::newLedgerJournalTable(journalTable.ledgerJournalTable(),NoYes::Yes);
                    ledgerJournalCheckPost.run();
                }
                info(strFmt("%1",ledgerJournalTrans.JournalNum));
            }

        }

    }
    catch(Exception::Error)
    {

        error('An Exception has occurred');


    }
    ttsCommit;
}

Monday, 6 January 2020

conver amount from one currency to another currency

conver amount from one currency to another currency

 fromCurrecncy = projTable.currencyId();
        toCurrency  = Ledger::findByLegalEntity(CompanyInfo::findDataArea(curext()).RecId).AccountingCurrency;

        if(fromCurrecncy != toCurrency)
        {
            select ExchangeRate,ExchangeRateCurrencyPair from exchangeRate order by RecId desc
                join RecId,ExchangeRateDisplayFactor,ToCurrencyCode,FromCurrencyCode from exchangeRateCurrencyPair
                join RecId,Name from exchangeRateType where exchangeRate.ExchangeRateCurrencyPair == exchangeRateCurrencyPair.RecId
                    && exchangeRateType.RecId == exchangeRateCurrencyPair.ExchangeRateType
                    && exchangeRateType.Name == 'Default'
                    && exchangeRateCurrencyPair.FromCurrencyCode == fromCurrecncy
                    && exchangeRateCurrencyPair.ToCurrencyCode == toCurrency;

            conRevenueAmount = (exchangeRate.ExchangeRate * revenueAmount1)/minOne(exchangeRateCurrencyPair.ExchangeRateDisplayFactor);

            conRevAmount = strFmt("%1",conRevenueAmount);

            curExRate = strFmt("%1",exchangeRate.ExchangeRate);
        }

Thursday, 28 November 2019

Create Invoice proposal through code AX 2012

Create Invoice proposal through code AX 2012

class : ProjInvoiceProposalCreateLines

public void new()
{
}

.........................

ProjInvoiceProposalInsertLines
String30                        psaInvoiceId,invId;
/// <summary>
/// Contains the code that performs the actual job of the class.
/// </summary>
public void run()
{
    ProjFundingSourceRefId  fundingSourceRefIdPrev;
    CurrencyCode            currencyCodePrev;
    ProjInvoiceProjId       projInvoiceProjIdPrev;
    RefRecId                taxInformationRecid;
    boolean                 isInvoiceSplit_IN       = isCountryRegion_IN && ProjParameters::find().InvoiceSplit_IN;

    boolean                 ret;
    ProjProposalJour        proposalJour;
    ProjTable               projTable;
    Set                     fundingSourceRefIdPrevSet = new Set(Types::Int64);

    ALE_ProposalInvoiceTable proposalInvoiceTable;
    #OCCRetryCount

    startLengthyOperation();

    try
    {

        ttsbegin;

        this.progressInit("@SYS54552", progressTotal, #AviFormLetter);

        progress.setText("@SYS26577");

        projInvoiceProposalCreateLines.updateContractLineNum();

        tmpProjProposalTrans = projInvoiceProposalCreateLines.prepareForInvoicing();

        if (isValidateProjTable)
        {
            this.removeBlockedProjIds();
        }

        while select tmpProjProposalTrans order by ProjInvoiceProjId, FundingSourceRefId, CurrencyCode, TaxInformation_IN
        {
            if (!ProjFundingSource::isExternalFunding(tmpProjProposalTrans.FundingSourceRefId))
            {
                continue;
            }

            // <GBR>
            if (!BrazilParameters::isEnabled() || (projInvoiceProposalCreateLines.parmProposalCreateLinesParams().parmReverseMarking_BR()))
            {
                if (tmpProjProposalTrans.ProjInvoiceProjId  != projInvoiceProjIdPrev  ||
                    !fundingSourceRefIdPrevSet.in(tmpProjProposalTrans.FundingSourceRefId) ||
                    tmpProjProposalTrans.CurrencyCode       != currencyCodePrev       ||
                    ((tmpProjProposalTrans.TaxInformation_IN != taxInformationRecid) && isInvoiceSplit_IN))
                {
                    ret = this.setProjProposalJour(tmpProjProposalTrans.ProjInvoiceProjId, tmpProjProposalTrans.ProjId, tmpProjProposalTrans.FundingSourceRefId, tmpProjProposalTrans.CurrencyCode, tmpProjProposalTrans.TaxInformation_IN, tmpProjProposalTrans.FixedExchRate);
                    fundingSourceRefIdPrevSet.add(tmpProjProposalTrans.FundingSourceRefId);
                }

                projInvoiceProjIdPrev  = tmpProjProposalTrans.ProjInvoiceProjId;
                fundingSourceRefIdPrev = tmpProjProposalTrans.FundingSourceRefId;
                currencyCodePrev       = tmpProjProposalTrans.CurrencyCode;
                taxInformationRecid    = tmpProjProposalTrans.TaxInformation_IN;
            }
            // </GBR>
            else
            {
                this.setProjProposalJour_BR(tmpProjProposalTrans);
                ret = true;
            }

            if (!ret)
            {
                delete_from tmpProjProposalTrans where tmpProjProposalTrans.ProjInvoiceProjId == projInvoiceProjIdPrev && tmpProjProposalTrans.FundingSourceRefId == fundingSourceRefIdPrev && tmpProjProposalTrans.CurrencyCode == currencyCodePrev;
                continue;
            }

            select RecId from projTable
                where projTable.ProjId == tmpProjProposalTrans.ProjId &&
                      projTable.ProjInvoiceProjId  == tmpProjProposalTrans.ProjInvoiceProjId
                exists join proposalJour
                    where proposalJour.ProjInvoiceProjId == projTable.ProjInvoiceProjId &&
                          proposalJour.ProposalId == projProposalJour.ProposalId;

            if (projTable.RecId)
            {
            switch (tmpProjProposalTrans.RefTableId)
            {
                case tableNum(ProjCostTransSale) :      this.doCost(tmpProjProposalTrans.ProjInvoiceProjId, tmpProjProposalTrans.RefRecId);
                                                        break;

                case tableNum(ProjEmplTransSale) :      this.doEmpl(tmpProjProposalTrans.ProjInvoiceProjId, tmpProjProposalTrans.RefRecId);
                                                        break;

                case tableNum(ProjItemTransSale) :      this.doItem(tmpProjProposalTrans.ProjInvoiceProjId, tmpProjProposalTrans.RefRecId);
                                                        break;

                case tableNum(ProjOnAccTransSale)  :    this.doOnAccount(tmpProjProposalTrans.ProjInvoiceProjId, tmpProjProposalTrans.RefRecId);
                                                        break;

                case tableNum(ProjRevenueTransSale) :   this.doRevenue(tmpProjProposalTrans.ProjInvoiceProjId, tmpProjProposalTrans.RefRecId);
                                                        break;

                case tableNum(SalesLine) :              this.doSalesLine(tmpProjProposalTrans.ProjInvoiceProjId, tmpProjProposalTrans.RefRecId);
                                                        break;
            }

            if (isCreditNoteTrans && invoiceQty > 0)
            {
                PSAContractLineItemsServer::updateUnitsOrPercentProposal(tmpProjProposalTrans.ContractLineNum, NoYes::Yes, invoiceQty, isCreditNoteTrans);
                isCreditNoteTrans = false;
                invoiceQty = 0;
            }
            else
            {
                PSAContractLineItemsServer::updateUnitsOrPercentProposal(tmpProjProposalTrans.ContractLineNum, NoYes::Yes);
            }
                if(tmpProjProposalTrans.Selected == NoYes::No)

                {
                    select forUpdate firstOnly proposalInvoiceTable where proposalInvoiceTable.PSAInvoiceId != '';
                    proposalInvoiceTable.ProposalId = projProposalJour.ProposalId;
                    proposalInvoiceTable.update();
                }
        }
        }


        this.updateInvoiceTotal();

        this.updateEInvoiceData_NO();

        // When an invoice proposal is generated, the system will
        // automatically create retainage withholding records and/or retainage billing records at the project level.
        if (isConfigurationkeyEnabled(configurationKeyNum(PSAARRetainage)))
        {
            this.calcRetention();
        }

        ttscommit;
    }

    catch (Exception::Deadlock)
    {
        retry;
    }

    catch (Exception::UpdateConflict)
    {
        if (appl.ttsLevel() == 0)
        {
            if (xSession::currentRetryCount() >= #RetryNum)
            {
                throw Exception::UpdateConflictNotRecovered;
            }
            else
            {
                retry;
            }
        }
        else
        {
            throw Exception::UpdateConflict;
        }
    }

    catch (Exception::Error)
    {
        // Update has been canceled.
        throw error("@SYS18447");
    }

    endLengthyOperation();
}
.........................

ProjInvoiceProposalCreateLinesBase
String30                                psaInvoiceId;
/// <summary>
/// Prepares the selected records for invoicing.
/// </summary>
/// <returns>
/// A buffer of type <c>PSATmpProjProposalTrans</c>
/// </returns>
/// <remarks>
/// Deduction transactions and regular transactions are merged.
/// </remarks>
public PSATmpProjProposalTrans prepareForInvoicing()
{
    // Start added by kiran PSA AX Integration 13 Aug 2018
    PSATmpProjProposalTrans     tmpProposalTrans;
    ALE_STG_HourJournal         hourJournal;
    ALE_STG_Milestone           milestone;
    ALE_STG_ExpenseJournal      expenseJournal;
    ALE_STG_FPReveueAllocation  allocation;
    ProjEmplTrans               projEmplTrans;
    ProjEmplTransSale           projEmplTransSale;
    ProjEmplTransCost           projEmplTransCost;
    ProjOnAccTrans              projOnAccTrans;
    ProjTable                   projTable;
    ProjOnAccTransSale          projOnAccTransSale;
    ProjCostTrans               projCostTrans;
    ProjCostTransCost           projCostTransCost;
    ProjCostTransSale           projCostTransSale;
   ProjRevenueTrans             projRevenueTrans;
    ProjRevenueTransSale        projRevenueTransSale;
    ProjCostTransTaxExtensionIN projCostTransTaxExtensionIN;
    boolean                     hourBatch;

    ALE_ProposalInvoiceTable    proposalInvoiceTable;

    select proposalInvoiceTable;

    hourBatch = true;
    // End added by kiran PSA AX Integration 13 Aug 2018

    while select proposalTransCreateDeduction where proposalTransCreateDeduction.Selected == true
    {
        tmpProposalTrans.data(proposalTransCreateDeduction);
        tmpProposalTrans.insert();
        hourBatch = false;
    }

    while select proposalTransCreate where proposalTransCreate.Selected == true
    {
        tmpProposalTrans.data(proposalTransCreate);
        tmpProposalTrans.insert();
        hourBatch = false;
    }
    if(hourBatch == true)
    {
        // insert hour journal lines
        /*while select allocation
            join projRevenueTrans order by TransId asc
                join projRevenueTransSale
                where allocation.Status == 2
                 &&   projRevenueTrans.TransId == allocation.TransId
            && projRevenueTransSale.TransId == projRevenueTrans.TransId
            && allocation.PSAInvoiceId == proposalInvoiceTable.PSAInvoiceId

        {
            projTable = ProjTable::find(allocation.ProjId);

            //tmpProposalTrans.ActivityNumber     = projRevenueTrans.ActivityNumber;
            tmpProposalTrans.CategoryId         = projRevenueTrans.CategoryId;
            tmpProposalTrans.CustAccount        = projTable.CustAccount;
            tmpProposalTrans.CurrencyCode       = projRevenueTrans.CurrencyId;
            tmpProposalTrans.DefaultDimension   = projRevenueTrans.DefaultDimension;
            tmpProposalTrans.FundingType        = ProjFundingSource::find(projRevenueTransSale.FundingSource).FundingType;
            tmpProposalTrans.FundingSourceRefId = projRevenueTransSale.FundingSource;
            tmpProposalTrans.LinePropertyId     = projRevenueTrans.LinePropertyId;
            tmpProposalTrans.LineAmount         = projRevenueTransSale.LineAmount;
            tmpProposalTrans.ProjId             = projRevenueTrans.ProjId;
            tmpProposalTrans.ProjInvoiceProjId  = projTable.ProjInvoiceProjId;
            tmpProposalTrans.Qty                = projRevenueTrans.Qty;
            tmpProposalTrans.RefRecId           = projRevenueTrans.RecId;
            tmpProposalTrans.RefTableId         = tableNum(projRevenueTransSale);
            tmpProposalTrans.RefTransId         = projRevenueTrans.TransId;
            tmpProposalTrans.RefRecIdTrans      = projRevenueTrans.RecId;
            //tmpProposalTrans.Task = projEmplTrans.tas;
            tmpProposalTrans.TransactionOrigin  = projRevenueTrans.TransactionOrigin;
            tmpProposalTrans.TransDate          = projRevenueTrans.TransDate;
            //tmpProposalTrans.TransType = projEmplTrans.transty.tra;
            tmpProposalTrans.SalesPrice         = projRevenueTransSale.SalesPrice;

            tmpProposalTrans.Worker = projRevenueTrans.Worker;
            tmpProposalTrans.insert();
        }*/
        //fee
        while select allocation
            join projRevenueTrans order by TransId asc
                join projRevenueTransSale
                where allocation.Status == 3
                 &&   projRevenueTrans.TransId == allocation.TransId
            && projRevenueTransSale.TransId == projRevenueTrans.TransId
            && allocation.PSAInvoiceId == proposalInvoiceTable.PSAInvoiceId

        {
            projTable = ProjTable::find(allocation.ProjId);

            //tmpProposalTrans.ActivityNumber     = projRevenueTrans.ActivityNumber;
            tmpProposalTrans.CategoryId         = projRevenueTrans.CategoryId;
            tmpProposalTrans.CustAccount        = projTable.CustAccount;
            tmpProposalTrans.CurrencyCode       = projRevenueTrans.CurrencyId;
            tmpProposalTrans.DefaultDimension   = projRevenueTrans.DefaultDimension;
            tmpProposalTrans.FundingType        = ProjFundingSource::find(projRevenueTransSale.FundingSource).FundingType;
            tmpProposalTrans.FundingSourceRefId = projRevenueTransSale.FundingSource;
            tmpProposalTrans.LinePropertyId     = projRevenueTrans.LinePropertyId;
            tmpProposalTrans.LineAmount         = projRevenueTransSale.LineAmount;
            tmpProposalTrans.ProjId             = projRevenueTrans.ProjId;
            tmpProposalTrans.ProjInvoiceProjId  = projTable.ProjInvoiceProjId;
            tmpProposalTrans.Qty                = projRevenueTrans.Qty;
            tmpProposalTrans.RefRecId           = projRevenueTrans.RecId;
            tmpProposalTrans.RefTableId         = tableNum(projRevenueTransSale);
            tmpProposalTrans.RefTransId         = projRevenueTrans.TransId;
            tmpProposalTrans.RefRecIdTrans      = projRevenueTrans.RecId;
            //tmpProposalTrans.Task = projEmplTrans.tas;
            tmpProposalTrans.TransactionOrigin  = projRevenueTrans.TransactionOrigin;
            tmpProposalTrans.TransDate          = projRevenueTrans.TransDate;
            //tmpProposalTrans.TransType = projEmplTrans.transty.tra;
            tmpProposalTrans.SalesPrice         = projRevenueTransSale.SalesPrice;

            tmpProposalTrans.Worker = projRevenueTrans.Worker;
            tmpProposalTrans.insert();
        }
    // cost
        while select hourJournal
        join projEmplTrans order by TransId asc
            join ProjEmplTransSale
            where hourJournal.Status == 2
            &&   projEmplTrans.TransId == hourJournal.TransId
            && ProjEmplTransSale.TransId == projEmplTrans.TransId
            && hourJournal.InvoiceId == proposalInvoiceTable.PSAInvoiceId
            && hourJournal.AXInvoiceId == ''
        {
            projTable = ProjTable::find(hourJournal.ProjId);

            tmpProposalTrans.ActivityNumber     = projEmplTrans.ActivityNumber;
            tmpProposalTrans.CategoryId         = projEmplTrans.CategoryId;
            tmpProposalTrans.CustAccount        = projTable.CustAccount;
            tmpProposalTrans.CurrencyCode       = projEmplTrans.CurrencyId;
            tmpProposalTrans.DefaultDimension   = projEmplTrans.DefaultDimension;
            tmpProposalTrans.FundingType        = ProjFundingSource::find(ProjEmplTransSale.FundingSource).FundingType;
            tmpProposalTrans.FundingSourceRefId = ProjEmplTransSale.FundingSource;
            tmpProposalTrans.LinePropertyId     = projEmplTrans.LinePropertyId;
            tmpProposalTrans.LineAmount         = ProjEmplTransSale.LineAmount;
            tmpProposalTrans.ProjId             = projEmplTrans.ProjId;
            tmpProposalTrans.ProjInvoiceProjId  = ProjTable::find(projEmplTrans.ProjId).ProjInvoiceProjId;
            tmpProposalTrans.Qty                = projEmplTrans.Qty;
            tmpProposalTrans.RefRecId           = projEmplTrans.RecId;
            tmpProposalTrans.RefTransId         = projEmplTrans.TransId;
            tmpProposalTrans.RefTableId         = tableNum(ProjEmplTransSale);
            tmpProposalTrans.RefRecIdTrans      = projEmplTrans.RecId;
            //tmpProposalTrans.Task = projEmplTrans.tas;
            tmpProposalTrans.TransactionOrigin  = projEmplTrans.TransactionOrigin;
            tmpProposalTrans.TransDate          = projEmplTrans.TransDate;
            //tmpProposalTrans.TransType = projEmplTrans.transty.tra;
            tmpProposalTrans.SalesPrice         = ProjEmplTransSale.SalesPrice;

            tmpProposalTrans.Worker             = projEmplTrans.Worker;
            tmpProposalTrans.insert();
        }
        // Expense
       /* while select hourJournal
        join projCostTrans order by TransId asc
            join projCostTransCost
            where hourJournal.Status == 2
            &&   projCostTrans.TransId == hourJournal.TransId
            && projCostTransCost.TransId == projCostTrans.TransId
            && hourJournal.InvoiceId == proposalInvoiceTable.PSAInvoiceId
            && hourJournal.AXInvoiceId == ''
        {
            projTable = ProjTable::find(hourJournal.ProjId);

            tmpProposalTrans.ActivityNumber         = projCostTrans.ActivityNumber;
            tmpProposalTrans.CategoryId             = projCostTrans.CategoryId;
            tmpProposalTrans.CustAccount            = projTable.CustAccount;
            tmpProposalTrans.CurrencyCode           = projCostTrans.CurrencyId;
            tmpProposalTrans.DefaultDimension       = projCostTrans.DefaultDimension;
            tmpProposalTrans.FundingType            = ProjFundingSource::find(projCostTransCost.FundingSource).FundingType;
            tmpProposalTrans.FundingSourceRefId     = projCostTransCost.FundingSource;
            tmpProposalTrans.LinePropertyId         = projCostTrans.LinePropertyId;
            tmpProposalTrans.LineAmount             = projCostTransCost.LineAmount;
            tmpProposalTrans.ProjId                 = projCostTrans.ProjId;
            tmpProposalTrans.ProjInvoiceProjId      = projTable.ProjInvoiceProjId;
            tmpProposalTrans.Qty                    = projCostTrans.Qty;
            tmpProposalTrans.RefRecId               = projCostTrans.RecId;
            tmpProposalTrans.RefTransId             = projCostTrans.TransId;
            tmpProposalTrans.RefTableId             = tableNum(projCostTransCost);
            tmpProposalTrans.RefRecIdTrans          = projCostTrans.RecId;
            //tmpProposalTrans.Task = projEmplTrans.tas;
            tmpProposalTrans.TransactionOrigin      = projCostTrans.TransactionOrigin;
            tmpProposalTrans.TransDate              = projCostTrans.TransDate;
            //tmpProposalTrans.TransType = projEmplTrans.transty.tra;
            tmpProposalTrans.SalesPrice             = projCostTransCost.CostPrice;

            tmpProposalTrans.Worker                 = projEmplTrans.Worker;
            tmpProposalTrans.insert();
        }*/

        while select expenseJournal
        join projCostTrans order by TransId asc
            join projCostTransSale
            where expenseJournal.Status == 2
            &&   projCostTrans.TransId == expenseJournal.TransId
            && projCostTransSale.TransId == projCostTrans.TransId
            && expenseJournal.PSAInvoiceId == proposalInvoiceTable.PSAInvoiceId
            && expenseJournal.AXInvoiceId == ''
        {
            projTable = ProjTable::find(expenseJournal.ProjId);

            tmpProposalTrans.ActivityNumber     = projCostTrans.ActivityNumber;
            tmpProposalTrans.CategoryId         = projCostTrans.CategoryId;
            tmpProposalTrans.CustAccount        = projTable.CustAccount;
            tmpProposalTrans.CurrencyCode       = projCostTrans.CurrencyId;
            tmpProposalTrans.DefaultDimension   = projCostTrans.DefaultDimension;
            tmpProposalTrans.FundingType        = ProjFundingSource::find(projCostTransSale.FundingSource).FundingType;
            tmpProposalTrans.FundingSourceRefId = projCostTransSale.FundingSource;
            tmpProposalTrans.LinePropertyId     = projCostTrans.LinePropertyId;
            tmpProposalTrans.LineAmount         = projCostTransSale.LineAmount;
            tmpProposalTrans.ProjId             = projCostTrans.ProjId;
            tmpProposalTrans.ProjInvoiceProjId  = projTable.ProjInvoiceProjId;
            tmpProposalTrans.Qty                = projCostTrans.Qty;
            tmpProposalTrans.RefRecId           = projCostTrans.RecId;
            tmpProposalTrans.RefTransId             = projCostTrans.TransId;
            tmpProposalTrans.RefTableId         = tableNum(projCostTransSale);
            tmpProposalTrans.RefRecIdTrans      = projCostTrans.RecId;
            //tmpProposalTrans.Task = projEmplTrans.tas;
            tmpProposalTrans.TransactionOrigin  = projCostTrans.TransactionOrigin;
            tmpProposalTrans.TransDate          = projCostTrans.TransDate;
            //tmpProposalTrans.TransType = projEmplTrans.transty.tra;
            tmpProposalTrans.SalesPrice         = projCostTrans.TotalSalesAmountCur;

            tmpProposalTrans.Worker = projEmplTrans.Worker;
            tmpProposalTrans.insert();
        }
        // Enpense End
        // Onaccount - Milestone

        while select milestone
        join projOnAccTrans order by TransId asc
            join projOnAccTransSale
            where milestone.Status == 2
            &&   projOnAccTrans.TransId == milestone.TransId
            && projOnAccTransSale.TransId == projOnAccTrans.TransId
            && milestone.InvoiceId == proposalInvoiceTable.PSAInvoiceId
            && milestone.AXInvoiceId == ''
        {
            projTable = ProjTable::find(milestone.ProjId);

            tmpProposalTrans.ActivityNumber = projOnAccTrans.ActivityNumber;

            tmpProposalTrans.CustAccount        = projTable.CustAccount;
            tmpProposalTrans.CurrencyCode       = projOnAccTrans.CurrencyId;
            tmpProposalTrans.DefaultDimension   = projOnAccTrans.DefaultDimension;
            tmpProposalTrans.FundingSourceRefId = projOnAccTransSale.FundingSource;
            tmpProposalTrans.FundingType        = ProjFundingSource::find(projOnAccTransSale.FundingSource).FundingType;
            tmpProposalTrans.LineAmount         = projOnAccTransSale.Amount;

            tmpProposalTrans.ProjId             = projOnAccTrans.ProjId;
            tmpProposalTrans.ProjInvoiceProjId  = projTable.ProjInvoiceProjId;
            tmpProposalTrans.Qty                = projOnAccTrans.Qty;
            tmpProposalTrans.RefRecId           = projOnAccTransSale.RecId;
            tmpProposalTrans.RefTableId         = tableNum(projOnAccTransSale);
            tmpProposalTrans.RefRecIdTrans      = projOnAccTrans.RecId;
            tmpProposalTrans.RefTransId         = projOnAccTrans.TransId;
            //tmpProposalTrans.Task = projOnAccTrans.LinePropertyId;
            tmpProposalTrans.TransactionOrigin  = projOnAccTrans.TransactionOrigin;
            tmpProposalTrans.TransDate          = projOnAccTrans.TransDate;
            tmpProposalTrans.TransType          = ProjTransType::OnAccount;
            tmpProposalTrans.SalesPrice         = projOnAccTransSale.Amount;

            tmpProposalTrans.insert();
        }
    }

    return tmpProposalTrans;
}
...................................................

ProjInvoiceProposalCreateLinesParams

public void new()
{
}

..................
ProjInvoiceJournalCreate

/// <summary>
/// Initializes the journal header record.
/// </summary>
protected void initJournalHeader()
{
    ALE_ProposalInvoiceTable proposalInvoiceTable;

    if(projProposalJour.LineProperty == ProjLinePropertyCode::Invoiced)
    {
        throw error("@SYS23025");
    }

    projInvoiceTable = projProposalJour.projInvoiceTable();

    this.checkBeforePostingEinvoice();

    creditWarning = ProjParameters::find().CreditLineError;

    projInvoiceJour.clear();

    projInvoiceJour.initFromProjProposal(projProposalJour);

    if (projInvoiceJour.DeliveryPostalAddress &&
        !LogisticsPostalAddress::findRecId(projInvoiceJour.DeliveryPostalAddress,
                                           false,
                                           DateTimeUtil::minValue(),
                                           DateTimeUtil::newDateTime(projProposalJour.InvoiceDate, timeMax())).Address)
    {
        projInvoiceJour.DeliveryPostalAddress  = LogisticsLocationEntity::location2PostalAddress(
                                                 ProjFundingSource::find(projProposalJour.FundingSource).InvoiceLocation).RecId;
    }

    projInvoiceJour.ProjInvoiceId        = this.getJournalNumber();
    projInvoiceJour.LedgerVoucher        = this.getVoucher();
    projInvoiceJour.ParmId               = projInvoiceParmTable.ParmId;
    projInvoiceJour.InvoiceDate          = projInvoiceParmTable.InvoiceDate;
    // todo
    // Start - Added on 14 Aug 2019
    select forUpdate firstOnly proposalInvoiceTable where proposalInvoiceTable.PSAInvoiceId != '';
    proposalInvoiceTable.InvoiceId = projInvoiceJour.ProjInvoiceId;
    proposalInvoiceTable.update();
    // End - Added on 14 Aug 2019

    if (!projInvoiceJour.isProforma())
    {
        if (EInvoiceParameters_MX::isElectronicInvoiceEnabled())
        {
            EInvoicePost_MX::validateInvoiceIDForEInvoice_MX(projInvoiceJour.ProjInvoiceId, numberSeq.parmNumberSequenceId());
        }

        if (EInvoiceCFDIParameters_MX::isElectronicInvoiceEnabled())
        {
            EInvoicePost_MX::validateInvoiceDateForCFDI_MX(projInvoiceJour.InvoiceDate);
        }
    }


    projInvoiceJour.DocumentDate_W = projInvoiceParmTable.DocumentDate_W;
    projInvoiceJour.SalesDate_CZ = projInvoiceParmTable.SalesDate_CZ;

    if(SysCountryRegionCode::isLegalEntityInCountryRegion([#isoLT, #isoLV]))
    {
        if (projInvoiceParmTable.AutoNumbering_LT)
        {
            if (! LtInvoiceAutoNumberingTable::checkLastDate(ltDocNumberingCode, projInvoiceParmTable.DocumentDate_W, true))
            {
                throw error("@SYS18447");
            }

            projInvoiceJour.InvoiceNumberingCode_LT   = LtInvoiceAutoNumberingTable::find(ltDocNumberingCode).NumberSequenceCode;

            LtInvoiceAutoNumberingTable::updateLastDate(ltDocNumberingCode, projInvoiceParmTable.DocumentDate_W);
        }
        projInvoiceJour.InvoiceRegister_LT = LtInvoiceAutoNumberingGroups::registeringForProjInvoice(CustTable::find(projInvoiceParmTable.InvoiceAccount).CustGroup);
    }

    this.exchRateSet();
}


Tuesday, 20 August 2019

Create and post Invoice proposal through code in ax 2012 X++

Create and post Invoice proposal through code in ax 2012 X++

public class CreateInvoiceProposal extends RunBaseBatch
{

}
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

public boolean canGoBatch()
{
    return true;
}

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

protected boolean canGoBatchJournal()
{
    return true;
}

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

public boolean runsImpersonated()
{
    return true;
}

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

static ClassDescription description()
{
    return "Invocie proposal creation";
}

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

public static void main(Args args)
{
    CreateInvoiceProposal createInvoiceProposal = new  CreateInvoiceProposal();

    if (createInvoiceProposal.prompt())
    {
        createInvoiceProposal.run();
    }
}

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

public void run()
{
    ProjParameters          projParameters;
    ProjEmplTrans           projEmplTrans;
    ProjOnAccTrans          projOnAccTrans;

    ProjProposalJour        projProposalJour;           //Table which will store journal records after creating Invoice Proposal
    ProjFormLetter          projFormLetter;

    ProjOnAccTrans          objProjOnAccTrans_1;
    ALE_STG_Milestone       milestone,milestoneLines;
    ALE_STG_HourJournal     hourJournal,hourJournalLines;
    ALE_STG_ExpenseJournal  expenseJournal,expenseJournalLines;
    TransactionID           transId;

    ALE_ProposalInvoiceTable proposalInvoiceTable;

    CategoryId              categoryId;
    ProjTable               projTable;
    container               transIdCon;
    int                     i,j;

    ProjInvoiceProposalInsertLines  projInvoiceProposalInsertLines;
    ProjInvoiceProposalCreateLinesBase  projInvoiceProposalCreateLinesBase;
    ProjInvoiceProposalCreateLines      proposalCreateLines;
    ProjInvoiceProposalCreateLinesParams projInvoiceProposalCreateLinesParams;

    proposalCreateLines = new ProjInvoiceProposalCreateLines();
    projInvoiceProposalCreateLinesParams = new ProjInvoiceProposalCreateLinesParams();
    proposalCreateLines.parmProposalCreateLinesParams(projInvoiceProposalCreateLinesParams).parmInvoiceDate(today());

    projInvoiceProposalInsertLines = new ProjInvoiceProposalInsertLines(proposalCreateLines,false);

    select projParameters;
    try
    {
        while select hourJournal group by InvoiceId,CompanyId order by ProjectDate asc //ProjectDate,ProjId
            join expenseJournal
            where hourJournal.Status == 2 && hourJournal.InterCompany == NoYes::No && hourJournal.InvoiceId != '' && hourJournal.AXInvoiceId == '' && expenseJournal.PSAInvoiceId == hourJournal.InvoiceId
        {
            ttsBegin;
            changeCompany(hourJournal.CompanyId)

        // Start added by kiran PSA AX Integration 13 Aug 2019
            delete_from proposalInvoiceTable;
        // End added by kiran PSA AX Integration 13 Aug 2019
            proposalInvoiceTable.PSAInvoiceId = hourJournal.InvoiceId;
            proposalInvoiceTable.insert();

            projInvoiceProposalInsertLines.run();

            select proposalInvoiceTable;
            select forUpdate projProposalJour where projProposalJour.ProposalId == proposalInvoiceTable.ProposalId  &&
                projProposalJour.InvoiceDate == today()
                && (projProposalJour.LineProperty!=ProjLinePropertyCode::Invoiced && projProposalJour.LineProperty!=ProjLinePropertyCode::Canceled);
                {

                    //For approving Invoice proposals

                    projProposalJour.LineProperty = ProjLinePropertyCode::Approved;

                    projProposalJour.update();

                    //For Posting Invoice Proposals

                    projFormLetter = ProjFormLetter::construct(DocumentStatus::ProjectInvoice);

                    projFormLetter.createParmLine(projProposalJour);

                    projFormLetter.run();

                    //To get latest record

                    projProposalJour = projProposalJour::find(projProposalJour.ProposalId);

                    info(strFmt("Invoice ProposalId: %1 \t InvoiceId: %2",projProposalJour.ProposalId,projProposalJour.ProjInvoiceId));

                }
               select proposalInvoiceTable;
            while select forUpdate hourJournalLines order by RecId asc where hourJournalLines.InvoiceId == hourJournal.InvoiceId
                && hourJournalLines.Status == 2
                && hourJournalLines.InterCompany == NoYes::No
            {
               hourJournalLines.AXInvoiceId = proposalInvoiceTable.InvoiceId;
                hourJournalLines.Status = 3;
                hourJournalLines.update();
            }

            while select forUpdate expenseJournalLines order by RecId asc where expenseJournalLines.PSAInvoiceId == hourJournal.InvoiceId
                && expenseJournalLines.Status == 2
                && expenseJournalLines.InterCompany == NoYes::No
            {
               expenseJournalLines.AXInvoiceId = proposalInvoiceTable.InvoiceId;
                expenseJournalLines.Status = 3;
                expenseJournalLines.update();
            }

            ttsCommit;
        }
        // Onaccount - expense
        while select milestone group by InvoiceId,CompanyId order by ProjDate asc //ProjectDate,ProjId
            join expenseJournal
            where milestone.Status == 2 && milestone.InterCompany == NoYes::No && milestone.InvoiceId != '' && milestone.AXInvoiceId == '' && expenseJournal.PSAInvoiceId == milestone.InvoiceId
        {
            ttsBegin;
            changeCompany(milestone.CompanyId)

        // Start added by kiran PSA AX Integration 13 Aug 2019
            delete_from proposalInvoiceTable;
        // End added by kiran PSA AX Integration 13 Aug 2019
            proposalInvoiceTable.PSAInvoiceId = milestone.InvoiceId;
            proposalInvoiceTable.insert();

            projInvoiceProposalInsertLines.run();

            select proposalInvoiceTable;
            select forUpdate projProposalJour where projProposalJour.ProposalId == proposalInvoiceTable.ProposalId  &&
                projProposalJour.InvoiceDate == today()
                && (projProposalJour.LineProperty!=ProjLinePropertyCode::Invoiced && projProposalJour.LineProperty!=ProjLinePropertyCode::Canceled);
                {

                    //For approving Invoice proposals

                    projProposalJour.LineProperty = ProjLinePropertyCode::Approved;

                    projProposalJour.update();

                    //For Posting Invoice Proposals

                    projFormLetter = ProjFormLetter::construct(DocumentStatus::ProjectInvoice);

                    projFormLetter.createParmLine(projProposalJour);

                    projFormLetter.run();

                    //To get latest record

                    projProposalJour = projProposalJour::find(projProposalJour.ProposalId);

                    info(strFmt("Invoice ProposalId: %1 \t InvoiceId: %2",projProposalJour.ProposalId,projProposalJour.ProjInvoiceId));

                }
               select proposalInvoiceTable;
            while select forUpdate milestoneLines order by RecId asc where milestoneLines.InvoiceId == milestone.InvoiceId
                && milestoneLines.Status == 2
                && milestoneLines.InterCompany == NoYes::No
            {
               milestoneLines.AXInvoiceId = proposalInvoiceTable.InvoiceId;
                milestoneLines.Status = 3;
                milestoneLines.update();
            }

            while select forUpdate expenseJournalLines order by RecId asc where expenseJournalLines.PSAInvoiceId == milestone.InvoiceId
                && expenseJournalLines.Status == 2
                && expenseJournalLines.InterCompany == NoYes::No
            {
               expenseJournalLines.AXInvoiceId = proposalInvoiceTable.InvoiceId;
                expenseJournalLines.Status = 3;
                expenseJournalLines.update();
            }

            ttsCommit;
        }
        // On Account - expense end
        // On account alone - start

        while select milestone group by InvoiceId,CompanyId order by ProjDate asc //ProjectDate,ProjId
            where milestone.Status == 2 && milestone.InterCompany == NoYes::No && milestone.InvoiceId != '' && milestone.AXInvoiceId == ''
        {
            ttsBegin;
            changeCompany(milestone.CompanyId)

        // Start added by kiran PSA AX Integration 13 Aug 2019
            delete_from proposalInvoiceTable;
        // End added by kiran PSA AX Integration 13 Aug 2019
            proposalInvoiceTable.PSAInvoiceId = milestone.InvoiceId;
            proposalInvoiceTable.insert();

            projInvoiceProposalInsertLines.run();

            select proposalInvoiceTable;
            select forUpdate projProposalJour where projProposalJour.ProposalId == proposalInvoiceTable.ProposalId  &&
                projProposalJour.InvoiceDate == today()
                && (projProposalJour.LineProperty!=ProjLinePropertyCode::Invoiced && projProposalJour.LineProperty!=ProjLinePropertyCode::Canceled);
                {

                    //For approving Invoice proposals

                    projProposalJour.LineProperty = ProjLinePropertyCode::Approved;

                    projProposalJour.update();

                    //For Posting Invoice Proposals

                    projFormLetter = ProjFormLetter::construct(DocumentStatus::ProjectInvoice);

                    projFormLetter.createParmLine(projProposalJour);

                    projFormLetter.run();

                    //To get latest record

                    projProposalJour = projProposalJour::find(projProposalJour.ProposalId);

                    info(strFmt("Invoice ProposalId: %1 \t InvoiceId: %2",projProposalJour.ProposalId,projProposalJour.ProjInvoiceId));

                }
               select proposalInvoiceTable;
            while select forUpdate milestoneLines order by RecId asc where milestoneLines.InvoiceId == milestone.InvoiceId
                && milestoneLines.Status == 2
                && milestoneLines.InterCompany == NoYes::No
            {
               milestoneLines.AXInvoiceId = proposalInvoiceTable.InvoiceId;
                milestoneLines.Status = 3;
                milestoneLines.update();
            }
        ttsCommit;
        }

        // On account alone - end

        // Expense/Cost Invoice proposal

        while select expenseJournal group by PSAInvoiceId,CompanyId order by ProjectDate asc //ProjectDate,ProjId
            where expenseJournal.Status == 2 && expenseJournal.InterCompany == NoYes::No && expenseJournal.PSAInvoiceId != '' && expenseJournal.AXInvoiceId == ''
        {
            ttsBegin;
            changeCompany(expenseJournal.CompanyId)

        // Start added by kiran PSA AX Integration 13 Aug 2019
            delete_from proposalInvoiceTable;
        // End added by kiran PSA AX Integration 13 Aug 2019
            proposalInvoiceTable.PSAInvoiceId = expenseJournal.PSAInvoiceId;
            proposalInvoiceTable.insert();

            projInvoiceProposalInsertLines.run();

            select proposalInvoiceTable;
            select forUpdate projProposalJour where projProposalJour.ProposalId == proposalInvoiceTable.ProposalId  &&
                projProposalJour.InvoiceDate == today()
                && (projProposalJour.LineProperty!=ProjLinePropertyCode::Invoiced && projProposalJour.LineProperty!=ProjLinePropertyCode::Canceled);
                {

                    //For approving Invoice proposals

                    projProposalJour.LineProperty = ProjLinePropertyCode::Approved;

                    projProposalJour.update();

                    //For Posting Invoice Proposals

                    projFormLetter = ProjFormLetter::construct(DocumentStatus::ProjectInvoice);

                    projFormLetter.createParmLine(projProposalJour);

                    projFormLetter.run();

                    //To get latest record

                    projProposalJour = projProposalJour::find(projProposalJour.ProposalId);

                    info(strFmt("Invoice ProposalId: %1 \t InvoiceId: %2",projProposalJour.ProposalId,projProposalJour.ProjInvoiceId));

                }
            select proposalInvoiceTable;

            while select forUpdate expenseJournalLines order by RecId asc where expenseJournalLines.PSAInvoiceId == expenseJournal.PSAInvoiceId
                && expenseJournalLines.Status == 2
                && expenseJournalLines.InterCompany == NoYes::No
            {
                expenseJournalLines.AXInvoiceId = proposalInvoiceTable.InvoiceId;
                expenseJournalLines.Status = 3;
                expenseJournalLines.update();
            }

            ttsCommit;
        }
        //
        //

        while select hourJournal group by InvoiceId,CompanyId order by ProjectDate asc //ProjectDate,ProjId
            where hourJournal.Status == 2 && hourJournal.InterCompany == NoYes::No && hourJournal.InvoiceId != '' && hourJournal.AXInvoiceId == ''
        {
            ttsBegin;
            changeCompany(hourJournal.CompanyId)

        // Start added by kiran PSA AX Integration 13 Aug 2019
            delete_from proposalInvoiceTable;
        // End added by kiran PSA AX Integration 13 Aug 2019
            proposalInvoiceTable.PSAInvoiceId = hourJournal.InvoiceId;
            proposalInvoiceTable.insert();

            projInvoiceProposalInsertLines.run();

            select proposalInvoiceTable;
            select forUpdate projProposalJour where projProposalJour.ProposalId == proposalInvoiceTable.ProposalId  &&
                projProposalJour.InvoiceDate == today()
                && (projProposalJour.LineProperty!=ProjLinePropertyCode::Invoiced && projProposalJour.LineProperty!=ProjLinePropertyCode::Canceled);
                {

                    //For approving Invoice proposals

                    projProposalJour.LineProperty = ProjLinePropertyCode::Approved;

                    projProposalJour.update();

                    //For Posting Invoice Proposals

                    projFormLetter = ProjFormLetter::construct(DocumentStatus::ProjectInvoice);

                    projFormLetter.createParmLine(projProposalJour);

                    projFormLetter.run();

                    //To get latest record

                    projProposalJour = projProposalJour::find(projProposalJour.ProposalId);

                    info(strFmt("Invoice ProposalId: %1 \t InvoiceId: %2",projProposalJour.ProposalId,projProposalJour.ProjInvoiceId));

                }
            select proposalInvoiceTable;
            while select forUpdate hourJournalLines order by RecId asc where hourJournalLines.InvoiceId == hourJournal.InvoiceId
                && hourJournalLines.Status == 2
                && hourJournalLines.InterCompany == NoYes::No
            {
               hourJournalLines.AXInvoiceId = proposalInvoiceTable.InvoiceId;
                hourJournalLines.Status = 3;
                hourJournalLines.update();
            }

            ttsCommit;
        }
        //


    }
    catch(Exception::Error)
    {
        error('An Exception has occurred');
    }
}

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>