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();
}