Thursday 29 December 2016

Edit method in ax 2012



Edit Qty editMCGPalletTotal(boolean _set , Qty _Qty)
{
    Qty          palletQty,salesQty,totalQty,Qty;
    SalesTable   SalesTableLoc;
    SalesLine    SalesLine;
    ;

    if(_set)
    {
            ttsbegin;
            SalesTableLoc              = SalesTable::find(this.SalesId,true);
            SalesTableLoc.MCGPalletQty = _Qty;
            SalesTableLoc.update();
            ttscommit;
            Qty = SalesTableLoc.MCGPalletQty;
            return Qty;
    }
    else
    {
        this.reread();
        if (!this.MCGPalletQty)
        {
            while select SalesId,ItemId,SalesQty from SalesLine where SalesLine.SalesId == this.SalesId
            {
                palletQty  = InventTable::find(SalesLine.ItemId).standardPalletQuantity;
                salesQty   = SalesLine.SalesQty;
                totalQty   = totalQty + palletQty * salesQty;
                Qty = totalQty;

            }
        }
        else
        {
            Qty = this.MCGPalletQty;
        }

        return Qty;
    }

}

Monday 21 November 2016

job for create create addresses and role types by using customer account or vendor or prospect

job for create create addresses and role types by using customer account or vendor or prospect :


job: 


static void insertProspectAddress(Args _args)
{
    SysExcelApplication application;
    SysExcelWorkbooks   workbooks;
    SysExcelWorkbook    workbook;
    SysExcelWorksheets  worksheets;
    SysExcelWorksheet   worksheet;
    SysExcelCells       cells;
    COMVariantType      type;
    Name                name;
    FileName            filename;
    //InventPosting       InventPosting;
    int                 row =1;
    DimensionAttributeValueCombination DimensionAttributeValueCombination;

    LogisticsAddressZipCode          zipCode;
    LogisticsAddressZipCodeId        zipCodeId;
    LogisticsAddressCity             city;
    LogisticsAddressStateId          stateId;
    LogisticsAddressState            state;
    LogisticsAddresssCity            cityRecord;
    LogisticsAddressCountyName       countyName;
    LogisticsAddressCountyId         countyId;
    LogisticsAddressCounty           county;
    LogisticsAddressStreet           street;
    LogisticsAddressDistrictName     district;
    boolean                          badRecord;
    int                              i=1;
    int                              numProcessedRecords=0,numzipcodesinserted;
    LogisticsAddressCountryRegionId  _countryRegionId;
    LogisticsAddressDistrict         districtRecord;
    LogisticsAddressStreet_RU        streetRecord;
    smmBusRelAccount                 AccountNum;
    CustName                         CustName;
    MCGOneTimeAddress                MCGOneTimeAddress;
    smmBusRelTable                   smmBusRelTable;
    LogisticsLocationRoleName        LogisticsLocationRoleName;
    LogisticsLocationRoleType        LogisticsLocationRoleType;
    Phone                            phone;
    EMail                            eMail;
    TeleFax                          fax;
    URL                              url;
    ;

    application = SysExcelApplication::construct();

    workbooks = application.workbooks();

    //specify the file path that you want to read

    filename = "D:\\McLane Xpo\\Data\\Imported data\\Prospects\\AllProspectAddressJob.xlsx";//testingemail.xlsx";// //prospect addresses addresses only.xlsx";//

    try
    {
        workbooks.open(filename);
    }
    catch (Exception::Error)
    {
        throw error("File cannot be opened.");
    }


    ttsbegin;

    workbook   = workbooks.item(1);
    worksheets = workbook.worksheets();
    worksheet  = worksheets.itemFromNum(1); //Here 3 is the worksheet Number
    cells      = worksheet.cells();

    do
    {

        row++;

        CustName = cells.item(row, 1).value().bStr();
        if(CustName == "")
            CustName = int2str(cells.item(row, 1).value().double());

        _countryRegionId = cells.item(row, 2).value().bStr();

        AccountNum = cells.item(row, 3).value().bStr();
        if(AccountNum == "")
            AccountNum = int2str(cells.item(row, 3).value().double());

        LogisticsLocationRoleName = cells.item(row, 4).value().bStr();

        eMail = cells.item(row, 6).value().bStr();
        phone = cells.item(row, 7).value().bStr();
        fax   = cells.item(row, 8).value().bStr();
        url   = cells.item(row, 14).value().bStr();

        city             = cells.item(row, 9).value().bStr();

        countyId         = cells.item(row, 10).value().bStr();

        stateId          = cells.item(row, 11).value().bStr();

        street = cells.item(row, 12).value().bStr();
        if(street == "")
            street = int2str(cells.item(row, 12).value().double());

        //district         = cells.item(row, 17).value().bStr();

        zipCodeId = cells.item(row, 13).value().bStr();
        if(zipCodeId == "")
            zipCodeId = int2str(cells.item(row, 13).value().double());



        smmBusRelTable = smmBusRelTable::find(AccountNum);
        if(smmBusRelTable)
        {
            LogisticsLocationRoleType = str2enum(LogisticsLocationRoleType,LogisticsLocationRoleName);
           //MCGOneTimeAddress::CreateOneTimeAddress("","",street,city,district,countyid,stateid,zipCodeid,_countryRegionId,"","",LogisticsLocationRoleType::Payment);
            MCGOneTimeAddress::mcLaneCreateOneTimeAddress(AccountNum,CustName,"",street,city,district,countyid,stateid,zipCodeid,_countryRegionId,phone,eMail,fax,url,LogisticsLocationRoleType);

            numzipcodesinserted++;
        }

        numProcessedRecords++;

    type = cells.item(row+1, 1).value().variantType();

    }
    while (type != COMVariantType::VT_EMPTY);
         info(strFmt("zip-%1 - rec-%2",numzipcodesinserted,numProcessedRecords));
        ttsCommit;
    application.quit();

}



class: 


class MCGOneTimeAddress
{
}



public static LogisticsLocationRecId mcLaneCreateOneTimeAddress(
                                        smmBusRelAccount             smmBusRelAccount,
                                        CustName                     custName,
                                        LogisticsAddressStreetNumber streetNumber,
                                        AddressStreet                street,
                                        AddressCity                  city,
                                        LogisticsAddressDistrictName districtName,
                                        AddressCountyId              county,
                                        AddressStateId               state,
                                        AddressZipCodeId             zip,
                                        AddressCountryRegionId       country,
                                        Phone                        phone,
                                        EMail                        eMail,
                                        TeleFax                      fax,
                                        URL                          url,
                                        LogisticsLocationRoleType    logisticsLocationRoleType
                                        )
{
    boolean                     validInsert    = false;
    LogisticsPostalAddress      postalAddress;
    smmBusRelTable              smmBusRelTable;
    container                   roleContainer;
    DirPartyPostalAddressView   addressView;
    LogisticsLocation           location;
    LogisticsPostalAddressEntity postalAddressEntity;
    LogisticsPostalAddressView  logisticsPostalAddressView;
    DirPartyLocationEntity      partyLocationEntity;
    LogisticsLocationRecId      logisticsLocationRecId;

    // If there aren't any address fields, don't try to create the address.
    if (street == "" && city == "" && zip == "" && county == "" && country == "" && eMail == "" && phone == "")
    {
        return logisticsLocationRecId;
    }

    smmBusRelTable     = smmBusRelTable::find(smmBusRelAccount);
    roleContainer = [LogisticsLocationRole::findBytype(logisticsLocationRoleType).RecId];
    if (smmBusRelTable)
    {
        addressView.StreetNumber = streetNumber;
        addressView.Street = street;
        addressView.City = city;
        addressView.ZipCode = zip;
        addressView.State = state;
        addressView.County = county;
        addressView.CountryRegionId = country;
        addressView.DistrictName = districtName;
        addressView.IsPrimary = NoYes::No;
        addressView.Party = smmBusRelTable.Party;//new CustomerEntity(custTable, DirUtility::getCurrentDateTime()).getPartyRecId();

        // Create LogisticsPostalAddress and LogisticsLocation
        postalAddressEntity = LogisticsPostalAddressEntity::construct();
        logisticsPostalAddressView.initFromPartyPostalAddressView(addressView);
        postalAddress = postalAddressEntity.createPostalAddress(logisticsPostalAddressView);

        if (postalAddress.RecId > 0)
        {
            partyLocationEntity = DirPartyLocationEntity::construct(addressView.Party);
            partyLocationEntity.parmLocation(postalAddress.Location);

            // Create party links
            partyLocationEntity.createPartyLocationAssociation(roleContainer, addressView.IsPrimary, addressView.IsPrivate);
        }

        select forUpdate RecId from location where location.RecId == postalAddress.Location;
        location.Description = custName;
        location.update();

        logisticsLocationRecId = location.RecId;

        // Create LogisticsElectronicAddresses
        if (eMail != "" ||phone != "" ||fax != "" ||url != "" )
        {
            MCGOneTimeAddress::CreateLogisticsElectronicAddress(logisticsLocationRecId,  eMail,phone,fax,url);
        }

        /*
        if (eMail != "")
        {
            MCGOneTimeAddress::CreateLogisticsElectronicAddress(logisticsLocationRecId, LogisticsElectronicAddressMethodType::Email, eMail);
        }

        if (phone != "")
        {
            MCGOneTimeAddress::CreateLogisticsElectronicAddress(logisticsLocationRecId, LogisticsElectronicAddressMethodType::Phone, phone);
        }
        if (fax != "")
        {
            MCGOneTimeAddress::CreateLogisticsElectronicAddress(logisticsLocationRecId, LogisticsElectronicAddressMethodType::Fax, fax);
        }
        if (url != "")
        {
            MCGOneTimeAddress::CreateLogisticsElectronicAddress(logisticsLocationRecId, LogisticsElectronicAddressMethodType::URL, url);
        }*/
    }

    return logisticsLocationRecId;
}




public static void CreateLogisticsElectronicAddress(int64 parentLocationId,
                                        EMail                        eMail,
                                        Phone                        phone,
                                        TeleFax                      fax,
                                        URL                          url)//, LogisticsElectronicAddressMethodType methodType, LogisticsElectronicAddressLocator locator)
{
    LogisticsLocation location;
    LogisticsElectronicAddress electronicAddress;
    location.initValue();
    location.ParentLocation = parentLocationId;
    location.IsPostalAddress = NoYes::No;
    location.insert();

    if(eMail)
    {
        electronicAddress.initValue();
        electronicAddress.Type = LogisticsElectronicAddressMethodType::Email;
        electronicAddress.Location = location.RecId;
        electronicAddress.Locator = eMail;
        electronicAddress.insert();
    }
    if(phone)
    {
        electronicAddress.initValue();
        electronicAddress.Type = LogisticsElectronicAddressMethodType::Phone;
        electronicAddress.Location = location.RecId;
        electronicAddress.Locator = phone;
        electronicAddress.insert();
    }
    if(fax)
    {
        electronicAddress.initValue();
        electronicAddress.Type = LogisticsElectronicAddressMethodType::Fax;
        electronicAddress.Location = location.RecId;
        electronicAddress.Locator = fax;
        electronicAddress.insert();
    }
    if(url)
    {
        electronicAddress.initValue();
        electronicAddress.Type = LogisticsElectronicAddressMethodType::URL;
        electronicAddress.Location = location.RecId;
        electronicAddress.Locator = url;
        electronicAddress.insert();
    }

    //info(strFmt("%1 - %2 -%3",location.RecId,electronicAddress.RecId,electronicAddress,electronicAddress.Locator));
}



reference: retailordermanager class 





Friday 16 September 2016

Find LedgerAccount from Ledgerdimension

MainAccount::find(DimensionStorage::getMainAccountIdFromLedgerDimension(accountingDistributionLoc.LedgerDimension)).MainAccountId;

Wednesday 9 March 2016

Merging financial dimensions

Merging financial dimensions:


we can merge up to four differ dimension in to one fin dimension.
we need to give priority as per priprity it will merge.

for merging we can use the below class :

DimensionDefaultingService.serviceMergeDefaultDimensions(findim1,findim2,findim3,findim4)



example:

static void Update_FinDimId_PurchaseOrders(Args _args)
{
    PurchLine              PurchLine;
    //int                    length,counter = 0;
    DimensionDefault       defauleDimensionNew,defauleDimensionPurch,defauleDimensionItem,defauleDimensionVend;
    ItemId                 ItemId;
    InventTable            InventTable;

    ttsBegin;
    While select forUpdate PurchLine //where PurchLine.PurchId == "0070027820"
    {
        defauleDimensionPurch = PurchLine.DefaultDimension;
        defauleDimensionItem  = InventTable::find(PurchLine.ItemId).DefaultDimension;
        defauleDimensionVend  = vendtable::find(PurchLine.VendAccount).DefaultDimension;

        //length = strLen(PurchLine.PurchId);
        //If (Length == 8)
        //{
            defauleDimensionNew = DimensionDefaultingService::serviceMergeDefaultDimensions(defauleDimensionPurch,defauleDimensionItem,defauleDimensionVend);
            PurchLine.DefaultDimension = defauleDimensionNew;
            PurchLine.update();
            //counter++;

        //}
    }
    ttsCommit;
    //info(strFmt("%1", counter));

Tuesday 8 March 2016

create financial dimension combination create

Get combination method:


/// <summary>
/// for getting dimension id
/// </summary>
/// <param name="_dataRecord">
/// 2009 data record
/// </param>
/// <returns>
/// returns financial dimension
/// </returns>

public DimensionDefault findDefaultDimId(AxeDataRecord _dataRecord)
{

    DimensionAttributeValue             dimCostcenterVal,dimDepartmentVal,dimInternalOrderVal;
    DimensionAttribute                  dimAttrCostcenter,dimAttrDepartment,dimAttrInternalOrder;
    DimensionAttributeValueSetStorage   davss;
    boolean                             isValidDimension = true;
    DimensionDefault                    DefaultDimension;
    OMOperatingUnitNumber               omDepatmentvalue,omCostcentervalue;
    DimensionValue                      omInternalOrdervalue;
    MSDimensions                        MSDimensions;// checking the Dimension2_ value is internal order or costcenter
    NoYes                               isinternalOrder;

    davss                = DimensionAttributeValueSetStorage::find(DefaultDimension);
    dimAttrCostcenter    = DimensionAttribute::findByName('CostCenter');
    dimAttrDepartment    = DimensionAttribute::findByName('Department');
    dimAttrInternalOrder = DimensionAttribute::findByName('InternalOrder');

    select firstonly Num,mprInternal,Description,RecId from MSDimensions
       where MSDimensions.Num == _dataRecord.value('Dimension2_');
    isinternalOrder =  MSDimensions.mprInternal;

    if(_dataRecord.value('Dimension2_'))
    {
        if(isinternalOrder == NoYes::Yes)
        {
            omInternalOrdervalue = this.findorcreateInternalOrder(_dataRecord.value('Dimension2_'),MSDimensions.Description);
            dimInternalOrderVal  = DimensionAttributeValue::findByDimensionAttributeAndValueNoError(dimAttrInternalOrder, omInternalOrdervalue, false , true);
        }
        else
        {
            omCostcentervalue    = this.findorcreateCostcenter(_dataRecord.value('Dimension2_'));
            dimCostcenterVal     = DimensionAttributeValue::findByDimensionAttributeAndValueNoError(dimAttrCostcenter   , omCostcentervalue   , false , true);
        }

    }

    if(_dataRecord.value('Dimension'))
    {
        omDepatmentvalue     = this.findorcreatedepartment(_dataRecord.value('Dimension'));
        dimDepartmentVal     = DimensionAttributeValue::findByDimensionAttributeAndValueNoError(dimAttrDepartment   , omDepatmentvalue    , false , true);
    }



    if(dimInternalOrderVal )
    {
        davss.addItem(dimInternalOrderVal);
    }
    if(dimCostcenterVal )
    {
        davss.addItem(dimCostcenterVal);
    }

    if (dimDepartmentVal)
    {
        davss.addItem(dimDepartmentVal);
    }

    if(dimCostcenterVal || dimDepartmentVal || dimInternalOrderVal)
    {
        DefaultDimension =   davss.save();
        return DefaultDimension;
    }
    else
        return 0;

}



createorget inernal order , costcenter and department methods:

////////////////////////////////////////// to get or create  internal order method \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
/// <summary>
/// get the internal order value
/// </summary>
/// <param name="_DimensionValue">
/// passing internal order dimension value
/// </param>
/// <param name="_Description">
/// passing description
/// </param>
/// <returns>
/// returns internal dimesion value
/// </returns>

private DimensionValue findorcreateInternalOrder(DimensionValue  _DimensionValue,Description _Description)
{
    DimensionFinancialTag   dimensionFinancialTag;
    RefRecId                dimensionAttribute = DimensionAttribute::findByName("InternalOrder").financialTagCategory();

    ttsBegin;
    select firstOnly dimensionFinancialTag where dimensionFinancialTag.Value == _DimensionValue
    && dimensionFinancialTag.FinancialTagCategory == dimensionAttribute;
    if(!dimensionFinancialTag.RecId)
    {
        dimensionFinancialTag.initValue();
        dimensionFinancialTag.FinancialTagCategory = dimensionAttribute;
        dimensionFinancialTag.Value                = _DimensionValue;
        dimensionFinancialTag.Description          = _Description;//_DimensionValue;
        dimensionFinancialTag.insert();

    }
    ttsCommit;


    return _DimensionValue;


}



////////////////////////////////////////// to get or create  cost center method \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

private OMOperatingUnitNumber findorcreateCostcenter(OMOperatingUnitNumber               _omCostcentervalue)
{
    OMOperatingUnit OMOperatingUnit;

    select OMOperatingUnit
        where OMOperatingUnit.OMOperatingUnitNumber == _omCostcentervalue
        && OMOperatingUnit.OMOperatingUnitType == OMOperatingUnitType::OMCostCenter;
        if(!OMOperatingUnit.OMOperatingUnitNumber)
        {
            ttsBegin;
            OMOperatingUnit.OMOperatingUnitNumber = _omCostcentervalue;
            OMOperatingUnit.OMOperatingUnitType   = OMOperatingUnitType::OMCostCenter;//"Department";//
            OMOperatingUnit.Name                  = _omCostcentervalue;
            OMOperatingUnit.LanguageId            = "en-us";
            OMOperatingUnit.insert();
            ttsCommit;
            return OMOperatingUnit.OMOperatingUnitNumber;
        }
        else
        {
            return OMOperatingUnit.OMOperatingUnitNumber;
        }

}



////////////////////////////////////////// to get or create  department method \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

private OMOperatingUnitNumber findorcreatedepartment(OMOperatingUnitNumber               _omDepatmentvalue)
{
    OMOperatingUnit OMOperatingUnit;

    select OMOperatingUnit
        where OMOperatingUnit.OMOperatingUnitNumber == _omDepatmentvalue
        && OMOperatingUnit.OMOperatingUnitType == OMOperatingUnitType::OMDepartment;
        if(!OMOperatingUnit.OMOperatingUnitNumber)
        {
            ttsBegin;
            OMOperatingUnit.OMOperatingUnitNumber = _omDepatmentvalue;
            OMOperatingUnit.OMOperatingUnitType   = OMOperatingUnitType::OMDepartment;//"Department";//
            OMOperatingUnit.Name                  = _omDepatmentvalue;
            OMOperatingUnit.LanguageId            = "en-us";
            OMOperatingUnit.insert();
            ttsCommit;
            return OMOperatingUnit.OMOperatingUnitNumber;
        }
        else
        {
            return OMOperatingUnit.OMOperatingUnitNumber;
        }

}