Monday, 27 October 2025

Ssrs report using printanagement

 To run report based on the print management setting 

Refer WHSPickListShippingController

And change enum parameters in the output menu item to originalprint.

Wednesday, 1 June 2022

Shrink db logs

 

  1. Right-click the AxDB database and select Properties -> Options.
  2. Set the recovery model to Simple and exit the menu.
  3. Right-click the database again and select Tasks -> Shrink -> Files.
  4. Change the type to Log .
  5. Under Shrink action, select Release unused space and click OK.
  6. Change recovery model to Full - Properties - Options.

Monday, 21 February 2022

shrink db log

shrink db log 

ALTER DATABASE DYNAMICSXREFDB SET RECOVERY SIMPLE WITH NO_WAIT

DBCC SHRINKFILE(DYNAMICSXREFDB_log, 1000)

ALTER DATABASE DYNAMICSXREFDB SET RECOVERY FULL WITH NO_WAIT

Friday, 11 February 2022

Create default dimensions in d365fo x++

 Create default dimensions in d365fo x++


public DimensionDefault createDefaultDimension(DimensionValue _CostC,                                                       

                                                    DimensionValue _department,

                                                    DimensionValue _branchCode )

    {

        DimensionAttributeValueSetStorage   valueSetStorage = new DimensionAttributeValueSetStorage();

        DimensionDefault                    ddim;

        int                                 i;

        DimensionAttribute                  dimensionAttribute;

        DimensionAttributeValue             dimensionAttributeValue;

        

        container               conAttr = ['CostCenter','Department','BranchCode'];

        container               conValue = [_CostC, _department, _branchCode];

        str                     dimValue;

    

        for (i = 1; i <= conLen(conAttr); i++)

        {

            dimensionAttribute = dimensionAttribute::findByName(conPeek(conAttr,i));

            if (dimensionAttribute.RecId == 0)

            {

                continue;

            }

            dimValue = conPeek(conValue,i);

            if (dimValue != '')

            {

                dimensionAttributeValue = dimensionAttributeValue::findByDimensionAttributeAndValue(dimensionAttribute,dimValue,false,true);

                valueSetStorage.addItem(dimensionAttributeValue);

            }

        }

    

        ddim = valueSetStorage.save();

        return ddim;

    }


Monday, 31 January 2022

Get field Id d365fo x++ ax 2012

 Get field Id


DictTable dt; 

fieldId   fId; 

dt = new DictTable(tablenum(VendTable)); 

if (dt) 

    fId = dt.fieldName2Id("Name"); 

     print (strfmt("fId: %1", fId)); 

}

tax journal creation through code d365fo

 public void createTaxJournal(AirSalesTable _airSales, AirAmountTable _airAmount, LedgerJournalTable ljt,Amount  salesAmount,RefRecId leddim,

        Voucher _voucher,DebitCredit _debitCredit ,TaxEngineTaxJournalAccountType accountType ,SAC_IN _sacCode ,Amount _gstBaseAmount,NoYes   _gstApplicable,RefRecId _offsetLedgerDim )

    {

        TaxEngineTaxJournal             taxEngineTaxJournal;

        TaxEngineTaxJournalLine         taxEngineTaxJournalLine;

        TaxEngineTaxJournalLineTaxExtensionIN   taxEngineTaxJournalLineTaxExtensionIN;

        LedgerJournalName               ledgerJournalName;

        TradeGLSetupParameters      tradeGLParameters;

        TaxInformation_IN               taxInformation_IN;

        TaxRuntimeDocComponent          taxRuntimeDocComponent;

        TransTaxInformation             transTaxInformation;

        TaxComponentTable_IN            taxComponentTable_IN;

        TaxRuntimePostingType           taxRuntimePostingType;          

        TaxRuntimeDocTaxType            taxRuntimeDocTaxType;

        

        TaxEngineTaxJournalConstructor  taxEngineTaxJournalConstructor;


        select firstonly SalesTaxJournal,SAC from tradeGLParameters ;


        _sacCode = tradeGLParameters.SAC;


        select ledgerJournalName where ledgerJournalName.JournalName == tradeGLParameters.SalesTaxJournal

                && ledgerJournalName.DataAreaId == _airSales.CompanyCode;

        

        taxEngineTaxJournal.clear();

        taxEngineTaxJournalLine.clear();

        taxEngineTaxJournal.initValue();

        taxEngineTaxJournal.defaultRow();

        //taxEngineTaxJournal.JournalNum =  JournalTableData::newTable(taxEngineTaxJournal).nextJournalId();

        taxEngineTaxJournal.JournalNum              = TaxEngineTaxJournalUtil::getTaxJournalNum();

        taxEngineTaxJournal.insert();

            //NumberSeq::newGetNum(LedgerParameters::numRefJournalNum()).parmRefTableNum(; 

        taxEngineTaxJournalLine.TaxEngineTaxJournal = taxEngineTaxJournal.RecId;

        

        taxEngineTaxJournalLine.Purpose             =  TaxDocumentPurpose::Transaction;

        

                

        taxEngineTaxJournalLine.TransDate           = _airSales.ProcessedDate;

        taxEngineTaxJournalLine.Description         = _airSales.BookingNo;

        taxEngineTaxJournalLine.CurrencyCode        = _airSales.CurrencyCode;

        taxEngineTaxJournalLine.Triangulation       = Currency::triangulation(taxEngineTaxJournalLine.CurrencyCode);

        taxEngineTaxJournalLine.ExchRate            = ExchangeRateHelper::exchRate(taxEngineTaxJournalLine.CurrencyCode, taxEngineTaxJournalLine.TransDate, Currency::noYes2UnknownNoYes(taxEngineTaxJournalLine.Triangulation));


        taxEngineTaxJournalLine.AccountType         =  TaxEngineTaxJournalAccountType::Tax;

        

        taxEngineTaxJournalLine.LedgerDimension     =  leddim;

        


        if(_airAmount.TotalCgst != 0)

        {

            select RecId from taxRuntimeDocComponent where taxRuntimeDocComponent.Name == "CGST";

        }

        else if(_airAmount.Totaligst != 0)

        {

            select RecId from taxRuntimeDocComponent where taxRuntimeDocComponent.Name == "IGST" ;

        }

        if(_airAmount.TotalSgst != 0)

        {

            select RecId from taxRuntimeDocComponent where taxRuntimeDocComponent.Name == "SGST" ;

        }

        

        taxEngineTaxJournalLine.TaxComponent        = taxRuntimeDocComponent.RecId;

         


        select firstonly RecId from taxRuntimePostingType where taxRuntimePostingType.Name == "Tax Payable";

        

        taxEngineTaxJournalLine.TaxPostingType      = taxRuntimePostingType.RecId;

        taxEngineTaxJournalLine.OffsetAccountType   =  TaxEngineTaxJournalAccountType::Ledger;

        taxEngineTaxJournalLine.OffsetLedgerDimension = _offsetLedgerDim;

        //taxEngineTaxJournalLine.TaxMeasure = 

        //TaxEngineTaxJournalUtil::("GST", TaxEngineTaxJournalLine.OffsetTaxComponent);

        //taxEngineTaxJournalLine.    = _airSales.CompanyCode;

        //ledgerJournalTrans.ExchRate = exchRate;

        

         

        //taxEngineTaxJournalLine.LineNum++;

        //ledgerJournalTrans.Voucher = Numberseq::newGetVoucherFromCode(NumberSequenceTable::find(ledgerJournalTable.ledgerJournalName().NumberSequenceTable).NumberSequence).voucher();//bookingTable.MODocNum;

        

        //taxEngineTaxJournalLine.Voucher          = _voucher;

        

        //ledgerJournalTrans.DocumentDate = DateTimeUtil::getSystemDate(DateTimeUtil::getUserPreferredTimeZone());

        if(_debitCredit == DebitCredit::Credit)

        {

            taxEngineTaxJournalLine.AmountCurCredit = salesAmount;

        }

        else

        {

            taxEngineTaxJournalLine.AmountCurDebit = salesAmount;

        }

        

        

        taxEngineTaxJournalLine.insert();

        


        taxEngineTaxJournalConstructor = TaxEngineTaxJournalConstructor::construct(taxEngineTaxJournalLine.TaxEngineTaxJournal().JournalType);

        //taxEngineTaxJournalConstructor.(taxEngineTaxJournalLine);

        taxEngineTaxJournalLine.update();


        //taxEngineTaxJournalLineTaxExtensionIN = taxEngineTaxJournalLine.TaxEngineTaxJournal();

                        

        

        taxEngineTaxJournalLineTaxExtensionIN.TaxEngineTaxJournalLine = taxEngineTaxJournalLine.RecId;

        

        

        taxEngineTaxJournalLineTaxExtensionIN.insert();


        transTaxInformation = TransTaxInformationHelper::findOrCreateTransTaxInformationByRecord(taxEngineTaxJournalLine,true);

        transTaxInformation.ServiceAccountingCodeTable = ServiceAccountingCodeTable_IN::findByServiceAccountingCode(_sacCode);

        transTaxInformation.update();


        //TaxEngineTaxJournalUtil::postTaxJournal(taxEngineTaxJournal);


    }

Thursday, 2 September 2021

Department lookup

 Department lookup


public void lookup()
{
    Query                   query  = new Query();
    QueryBuildDataSource    qbds;
    SysTableLookup          sysTableLookup;
    sysTableLookup = sysTableLookup::newParameters(tableNum(OMOperatingUnit),this);
    sysTableLookup.addLookupfield(fieldNum(OMOperatingUnit,OMOperatingUnitNumber));
    sysTableLookup.addLookupfield(fieldNum(OMOperatingUnit,Name));
    sysTableLookup.addLookupfield(fieldNum(OMOperatingUnit,OMOperatingUnitType));
    sysTableLookup.addSelectionField(fieldNum(OMOperatingUnit,Name));
    qbds = query.addDataSource(tableNum(OMOperatingUnit));
    qbds.addSortField(fieldNum(OMOperatingUnit,OMOperatingUnitNumber));
    qbds.addRange(fieldNum(OMOperatingUnit,OMOperatingUnitType)).value(enum2str(OMOperatingUnitType::OMDepartment));
    sysTableLookup.parmQuery(query);
    sysTableLookup.performFormLookup();
}

Wednesday, 26 May 2021

Delete model from D365 FO

 Delete model from D365 FO 

CMD - Run as admin


Change path respectivly - K:\AosService\PackagesLocalDirectory\bin

ModelUtil.exe -delete -metadatastorepath="K:\AOSService\PackagesLocalDirectory" -modelname="xxxx"

Wednesday, 7 April 2021

create default dimensions ax 2012

 create default dimensions


private RefRecId createPurchDefaultDimensions(OMOperatingUnitNumber _dept, DimensionValue _vehicleDim)

{

    DimensionAttributeValueSetStorage       dimStorage;

    RefRecId                                defaultDimensionLoc;

    

    Counter                                 i;

    DimensionAttribute                      dimensionAttribute;

    DimensionAttributeValue                 dimensionAttributeValue;

    DimensionAttributeValueSetItem          dimensionAttributeValueSetItem;

    DimensionAttributeValueSetStorage       valueSetStorage = new DimensionAttributeValueSetStorage();

    DimensionDefault                        defaultDim;

    container                               conAttribute, conAttributeValue;

    DimensionValue                          deptLoc,vehicleDim;

    

    deptLoc = _dept;    

    vehicleDim = _vehicleDim;


    conAttribute        = conNull();

    conAttributeValue   = conNull();


    conAttribute        = conIns(conAttribute,1,'Department');

    conAttributeValue   = conIns(conAttributeValue, 1, deptLoc);

    conAttribute        = conIns(conAttribute,2,'Vehicles');

    conAttributeValue   = conIns(conAttributeValue, 2, vehicleDim);

    

    for (i = 1; i <= conLen(conAttribute); i++)

    {

        dimensionAttribute = dimensionAttribute::findByName(conPeek(conAttribute,i));

        if (dimensionAttribute.RecId == 0)

        {

            continue;

        }

        if (conPeek(conAttributeValue,i) != "")

        {

            dimensionAttributeValue =  dimensionAttributeValue::findByDimensionAttributeAndValue(dimensionAttribute,conPeek(conAttributeValue,i),false,true);

            valueSetStorage.addItem(dimensionAttributeValue);

        }


        defaultDimensionLoc = valueSetStorage.save();

    }

    return defaultDimensionLoc;

}

Wednesday, 11 November 2020

split default dimensions in ax 2012

 

split default dimensions in ax 2012


static void splitDimAndExport(Args _args)

{

    DimensionAttributeValueSetStorage   dimStorage;

    DimensionValue                    bu,costCenter,cust,custbu,custsow,dept,fa,fda,ir,inv,proj,purpose,rda,vend,worker;

    Counter                             i;

    ProjTable                           projTable;

     

    

    // DimensionDefault is a RecId that combines all Dimension Values

    while select projTable where projTable.ProjId == '201P000134-01'

    {

        dimStorage = DimensionAttributeValueSetStorage::find(projTable.DefaultDimension);  

 

   

        for (i= 1 ; i<= dimStorage.elements() ; i++)

        {

            

            // Change the string "CostCenter" to whatever financial dimension you want

            if(DimensionAttribute::find(dimStorage.getAttributeByIndex(i)).Name == "BusinessUnit")

            {

                bu = '';

                bu = dimStorage.getDisplayValueByIndex(i);

            }

            if(DimensionAttribute::find(dimStorage.getAttributeByIndex(i)).Name == "CostCenter")

            {

                costCenter = '';

                costCenter = dimStorage.getDisplayValueByIndex(i);

            }

            if(DimensionAttribute::find(dimStorage.getAttributeByIndex(i)).Name == "Customer")

            {

                cust = '';

                cust = dimStorage.getDisplayValueByIndex(i);

            }

            if(DimensionAttribute::find(dimStorage.getAttributeByIndex(i)).Name == "Customer_BU")

            {

                custbu = '';

                custbu = dimStorage.getDisplayValueByIndex(i);

            }

            if(DimensionAttribute::find(dimStorage.getAttributeByIndex(i)).Name == "Customer_SOW")

            {

                custsow = '';

                custsow = dimStorage.getDisplayValueByIndex(i);

            }

            if(DimensionAttribute::find(dimStorage.getAttributeByIndex(i)).Name == "Department")

            {

                dept = '';

            

                dept = dimStorage.getDisplayValueByIndex(i);

            }

            if(DimensionAttribute::find(dimStorage.getAttributeByIndex(i)).Name == "FixedAsset")

            {

                fa = '';

            

                fa = dimStorage.getDisplayValueByIndex(i);

            }

            if(DimensionAttribute::find(dimStorage.getAttributeByIndex(i)).Name == "FixedDepositAccount")

            {

                fda = '';

                fda = dimStorage.getDisplayValueByIndex(i);

            }

            if(DimensionAttribute::find(dimStorage.getAttributeByIndex(i)).Name == "InterestReceivable")

            {

                ir = '';

            

                ir = dimStorage.getDisplayValueByIndex(i);

            }

            if(DimensionAttribute::find(dimStorage.getAttributeByIndex(i)).Name == "Investors")

            {

                inv = '';

            

                inv = dimStorage.getDisplayValueByIndex(i);

            }

            if(DimensionAttribute::find(dimStorage.getAttributeByIndex(i)).Name == "Project")

            {

                proj = '';

            

                proj = dimStorage.getDisplayValueByIndex(i);

            }

            if(DimensionAttribute::find(dimStorage.getAttributeByIndex(i)).Name == "Purpose")

            {

                purpose = '';

            

                purpose = dimStorage.getDisplayValueByIndex(i);

            }

            if(DimensionAttribute::find(dimStorage.getAttributeByIndex(i)).Name == "RecurringDepositaccount")

            {

                rda = '';

            

                rda = dimStorage.getDisplayValueByIndex(i);

            }

            if(DimensionAttribute::find(dimStorage.getAttributeByIndex(i)).Name == "Vendor")

            {

                vend = '';

            

                vend = dimStorage.getDisplayValueByIndex(i);

            }

            if(DimensionAttribute::find(dimStorage.getAttributeByIndex(i)).Name == "Worker")

            {

                worker = '';

                worker = dimStorage.getDisplayValueByIndex(i);

            }

            

        }

        info(strFmt("%1 , %2 , %3 , %4 , %5 , %6 , %7 , %8 , %9 , %10 , %11 , %12, %13, %14 , %15 ",bu,costCenter,cust,custbu,custsow,dept,fa,fda,ir,inv,proj,purpose,rda,vend,worker));

    }


}

Monday, 9 November 2020

get User roles using x++


User roles

static void userRoles(Args _args)

{

     UserInfo            userInfo;

    SecurityUserRole    securityUserRole;

    SecurityRole        securityRole;

    str                 st;

       

    ;

        st = ',';

    while

    select userInfo

        join    securityUserRole

        where   securityUserRole.User == userInfo.Id

    {               

          

       

        securityRole = null;

        select securityRole

        where  securityRole.RecId == securityUserRole.SecurityRole;

       

        if (securityRole)

        {

            //info(securityRole.AotName);

            //info(securityRole.Name);   

            info(strFmt("%1 , %2 , %3",userInfo.Id,securityRole.Name,securityRole.Description)); //info(securityRole.Description);                      

        }  

    }


Wednesday, 14 October 2020

Customize class in D365 FO

 Customize class in D365 FO

1. create a extension of the standard class

2. use the expresions show 


[ExtensionOf(classStr(BusinessLogic1))] final class BusinessLogic1_Extension { str doSomething(int arg) { // Part 1 var s = next doSomething(arg + 4); // Part 2 return s; } }

Wednesday, 10 June 2020

Location Id look up

Location Id look up

public void lookup(FormControl _formControl, str _filterStr)
{
    //LogisticsLocation::locationLookup(_formControl, CustTable::find(ProjFundingSource::findCustAccount(projInvoiceTable.ProjInvoiceProjId).CustAccount).Party);
    //super(_formControl, _filterStr);

    QueryBuildDataSource            queryBuildDataSource,queryBuildDataSource1;
    Query                           query;
    SysTableLookup sysTableLookup = SysTableLookup::newParameters(tableNum(LogisticsLocation), _formControl);
    query = new Query();

    queryBuildDataSource = query.addDataSource(tableNum(LogisticsLocation));

    queryBuildDataSource = queryBuildDataSource.addDataSource(tableNum(DirPartyLocation));
    queryBuildDataSource.joinMode(JoinMode::InnerJoin);
    queryBuildDataSource.relations(true);

    queryBuildDataSource.addRange(fieldNum(DirPartyLocation,Party)).value(queryValue(CustTable::find(ProjFundingSource::findCustAccount(projInvoiceTable.ProjInvoiceProjId).CustAccount).Party));
    //queryBuildDataSource.addRange(fieldNum(DirPartyLocation,IsPostalAddress)).value(SysQuery::value(NoYes::Yes));

    //if (_roleType != LogisticsLocationRoleType::None)
    //{
        queryBuildDataSource = queryBuildDataSource.addDataSource(tableNum(DirPartyLocationRole));
        queryBuildDataSource.joinMode(JoinMode::InnerJoin);
        queryBuildDataSource.relations(true);
        queryBuildDataSource.addRange(fieldNum(DirPartyLocationRole,LocationRole)).value(SysQuery::valueNot(LogisticsLocationRoleType::None));//SysQuery::value(int642str(LogisticsLocationRole::findBytype(_roleType).RecId)));
    //}



    sysTableLookup.addLookupfield(fieldNum(LogisticsLocation, LocationId),true);
    sysTableLookup.addLookupfield(fieldNum(LogisticsLocation, Description));

     sysTableLookup.addLookupMethod(tableMethodStr(LogisticsLocation,postalAddress));

    sysTableLookup.parmQuery(query);

    sysTableLookup.performFormLookup();
}

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