DAX2012 R3 – Playing with Retail CRT

The Microsoft Dynamics AX commerce runtime (CRT) serves as the engine for a retail channel. It connects to a CRT database that stores business data for the channel.. Dynamics AX uses the CRT Architecture in the Retail ePOS, mPOS and in the Sharepoint based eCommerce solution. Also the SiteCore eCommerce solution uses the CRT as the integration to Dynamics AX.

Let’s look at some of the interesting things with CRT.

1. It is a well-documented framework supported by Microsoft. More details on it is available here.

2. It can make it easier to integrate business logics to other eCommerce solutions. Like Magento.

3. We can create CRT web-services that handles information like very advanced retail prices, on-hand shipment, check-outs etc.

4. And MUCH more. This CRT we will have almost everything we need to interact with external system. It Rocks !

Let’s take an example. I would like to utilize the CRT to calculate a sales price with discounts. Price/discounts in AX is very flexible and almost all options you can imagine. Here is a small example of the possibilities we get in Dynamics AX 2012 R3 CU 8.

Let’s say we would like to expose this price/discount structure as a web-service to external parties. Since the CRT is relying on it’s own channel database, it means that the much of the integration is actually not creating a heavy load on the Dynamics AX database. We also have the possibility to “scale out” on the architecture.

The CRT is developed in Visual Studio, and is basically just a bunch of dll’s. I have to admit, that Visual studio, Web-services and is not my strongest side. So I decided to see it I could access and use the CRT framework directly from Dynamics AX. The new call-center module in AX 2012 R3 CU8 is using this, and I wanted to create a very simple job that exemplifies how CRT operates and can be used. Basically I’m looking for this:

I use the standard AX 2012 R3 CU8 contoso demo data, but added the following quantity discount to the Houston store;

Since I know X++, I’ll use X++ job to try this. The infolog I got was the following:

Here we see that the CRT returned the sales price, discounted price, and also information like total amount. Surely it can give everything else, but I wanted to keep the example easy to understand.

I created the following job to play with the framework, and it gives you an idea of how to interact with the CRT from AX.

static void demo_CRT_GetSalesPrice(Args _args)
{
    //To test this code, use the AX 2012 R3 CU8, and use the USRT company
    Microsoft.Dynamics.Commerce.Runtime.Data.IPricingDataManagerV2                pricingManager;
    Microsoft.Dynamics.Commerce.Runtime.Services.PricingEngine.DiscountParameters priceParameters;
    Microsoft.Dynamics.Commerce.Runtime.DataModel.SalesLine                       crtSalesLine;
    Microsoft.Dynamics.Commerce.Runtime.DataModel.SalesTransaction                crtSalesTransaction;
    System.Object                                                                 roundingRule, currencyConverter;
    CLRObject                                                                     clrSalesLines, enumeratorSalesLine;
    CLRObject                                                                     clrObjectSalesLines;
    System.DateTimeOffset                                                         activeDateTimeOffset;
    System.String                                                                 lineIdString;
    System.String                                                                 customerPriceGroup = "";
    Price                                                                         price;
    Qty                                                                           qty;
    InventDim                                                                     inventdim;

    RetailStoreTable    storeTable = RetailStoreTable::find("HOUSTON");   //Lets use houston as an example here
    RetailChannelRecId  channelId = storeTable.RecId;                     //This is the recid for a retail channel. A retail store is an extension of a retail channel.
    CurrencyCode        currencyCode = storeTable.Currency;
    appl.setDefaultCompany(storeTable.company(), false);                  //Setting default company to houstons company

    //Creating a unique line ID
    lineIdString = System.Guid::NewGuid().toString();

    InventDim.InventLocationId = storeTable.inventLocation;
    InventDim.InventSiteId     = InventLocation::find(storeTable.inventLocation).InventSiteId;
    InventDim                  = InventDim::findOrCreate(InventDim);

    //Pricing manager : Encapsulates data access to pricing information.
    pricingManager          = Microsoft.Dynamics.Commerce.Headquarters.RetailProxy.AxPricingDataManager::BuildDataManager(channelId);

    //Price parameters : types of AX discounts (aka trade agreement discounts, aka not Retail Periodic Discounts) are currently activated and should be allowed on the transaction
    priceParameters         = Microsoft.Dynamics.Commerce.Runtime.Services.PricingEngine.DiscountParameters::CreateAndInitialize(pricingManager);
    roundingRule            = Microsoft.Dynamics.Commerce.Headquarters.RetailProxy.ServiceHelpers::GetRoundingMethod(currencyCode);
    currencyConverter       = Microsoft.Dynamics.Commerce.Headquarters.RetailProxy.ServiceHelpers::GetCurrencyConverter(currencyCode);
    activeDateTimeOffset    = RetailPricingEngineHelper::getSessionDateTimeInChannelTimeZone(channelId);

    //Next we create a crtSalesLine, that represents a channel agnostic sales line.
    crtSalesLine = new Microsoft.Dynamics.Commerce.Runtime.DataModel.SalesLine();

    crtSalesLine.set_ItemId("0001");        //Lets use product 0001 as our example
    crtSalesLine.set_InventoryDimensionId(InventDim.inventDimId);
    crtSalesLine.set_Quantity(10);          //Lets use quantity 10 as our example
    crtSalesLine.set_LineId(lineIdString);  //Let give this line a uniqe ID

    crtSalesLine.set_UnitOfMeasureSymbol("ea"); //Let use 'ea' as the unit

    //We then create a sales transaction, and add the salesline to this.
    crtSalesTransaction = new Microsoft.Dynamics.Commerce.Runtime.DataModel.SalesTransaction();
    clrObjectSalesLines = crtSalesTransaction.get_SalesLines();
    clrObjectSalesLines.Add(crtSalesLine);                      //This is where the we add the salesLine to the sales transaction

    //Lets calculate the prices
    Microsoft.Dynamics.Commerce.Runtime.Services.PricingEngine.PricingEngine::CalculatePricesForTransaction(
        crtSalesTransaction,
        pricingManager,
        roundingRule,
        currencyConverter,
        customerPriceGroup,
        currencyCode,
        false,
        activeDateTimeOffset);

    //Lets calculate the discounts
    Microsoft.Dynamics.Commerce.Runtime.Services.PricingEngine.PricingEngine::CalculateDiscountsForLines(
        pricingManager,
        crtSalesTransaction,
        roundingRule,
        currencyConverter,
        currencyCode,
        '',
        '',
        '',
        true,
        Microsoft.Dynamics.Commerce.Runtime.DataModel.DiscountCalculationMode::CalculateAll,
        activeDateTimeOffset);

    //And, let's show what the CRT can give us.
    qty   = crtSalesLine.get_Quantity();
    Price = crtSalesLine.get_Price();
    info(strFmt("Normal sales price is %1 when buying %2", price, qty ));

    Price = crtSalesLine.get_DiscountAmount();
    info(strFmt("Discount amount pr unit is %1, when buying %2", price/qty, qty ));

    Price = crtSalesLine.get_NetAmountPerUnit();
    info(strFmt("Net amount pr unit is %1, when buying %2", price, qty ));

    Price = crtSalesLine.get_TotalAmount();

    info(strFmt("Total amount is %1 when buying %2", price, qty ));

Maybe some of you can teach me how to expose the CRT in a web-service, so that we can easily

 

 

 

DAX 2012 end-to-end processes and APQC

With LCS (Life cycle Services), Microsoft have taken steps to introduced the APQC (American Productivity & Quality Center) Process Classification Framework as one of the business modelers.

Microsoft have also created some flowcharts to visualize the APQC processes in dynamics AX.

In some Dynamics AX implementation projects it have been decided to use the APQC model, and the participants(including me) was struggling connecting the APQC model to actual tasks and activities performed in DAX. So I started on a small mental journey to better understand how to use APQC model, and to be able to connect the dots from the classification framework into dynamics AX swim lane process maps.

First I thought that is was possible to take some level 4 APQC try to draw them. It is possible to draw the small and simple activities, but I was struggling drawing an end-to-end processes. Like order-to-cash. I quickly realized that I cannot use the LCS-APQC model to explain end-to-end DAX processes, since end-to-end processes often will involve many different departments, functions and processes.

To visualize a complex processes in an end-to-end process like order-to-cash using APQC classification model I could imagine looking something like this.

Here we see the involved processes visualized with the APQC classification. And it makes sense. But it does not tell you how to use AX in in this process, because that is described using the level 4 (or 5) in APQC. Like in 8.2.2 Invoice customers, would be a specific process, that we can visualize in Dynamics AX/LCS.

The other thing I realized was that APQC is not about implementing a ERP system, like DAX, but it’s about improving the processes you have(regardless of what systems and applications you have). Some of the activities may be handled in DAX, but many is just how to improve the actual steps the company actually does. Very often it can be the working procedure, involving many systems and internal working processes. So you don’t ask “How does this APQC process look in DAX ?”. You should rather ask “What APQC processes is involved in the selected DAX processes (like order-to-pay).

The APQC model will therefore not tell you how to use and setup Dynamics AX. It will just help you to have a common language to classify your processes and to improve them. When it comes to visualizing Dynamics AX processes in swim lane flowcharts it can be a good idea to use the APQC identifiers as process identification.

My tip when using LCS, is to understand the APQC process identification model, and use it as a repository and building blocks when you create your own processes.

By referring to APQC on your own business model you can start on process improvement project for that specific process. You will can also evaluate to implement the benchmark indicators as APQC exemplifies.

My quick summary is therefore;

1. Do I like LCS, and will use it à Yes, and I will use it for implementation and DAX process visualizations.

2. Do I like APQC à Yes, and I will use it for classification, benchmarking and process improvements.

3. Do I think that the LCS APQC processes reflect what we see at customers à No

4. What would be nice to have in LCS business modeler à More end-to-end processes, where the APQC process identifiers is used would be nice.

Happy DAX’ing !!

 

Distribution orders in a cross company scenario.

Many retail enterprises have selected Dynamics AX as their main system to handle their processes for financials, procurement, logistics, merchandising and POS/retail. They have a presents globally and is true international enterprises. We also often see that they are organized through partnerships and francizing, and to be cost efficient a lot of processes like brand, assortment and logistics have been centralized.

Dynamics AX for Retail natively supports most scenarios by providing efficient processes for the retail industry. The flow of products by using intercompany trading simplifies transactions handling.

One question that arises is how clear boundaries between the legal entities should be ? What I would like to discuss in this blogpost is how to structure legal entities in Dynamics AX, and still be efficient. Let’s say we have the following 3 level structure of the enterprise.

Here we have a central enterprise legal entity, that have the responsibility of overall finance, reporting, products, recommended retail pricing, assortments and procurement.

The next tier is the regional logistics units. They can be own operated warehouses, or outsourced to third party logistics providers. The purpose is not only to serve stores and partners, but to perform logistics processes like receiving, quality control etc.

The tier at the bottom is where all the partners and stores are located. This can be based on a franchise model, partner or own stores. At least one legal entity per partner or country.

How to handle transactions between these entities?

Keeping a good track on processes and the transactions is vital. We need to know where costs occur, and how the transactions are handled. Here I would like to discuss a bit how the transactions can be handled. Let’s start with the partners and stores.

Products are purchased through a intercompany purchase order. If products needs to be internally moved, then transfer orders are used. When the stores sell products, then POS and sales orders are used. The transaction handling clean and easy with simple transactions. Some times there may be issues with costs that will arrive later, like transportation costs. This can be handled with misc. charges as described here.

In the figure above we see how inventory costs are originating from the vendor and the costs are propagated through the intercompany chain. Also how we can add additional charges like insurance, freight, and make sure that these costs flow through the intercompany chain.

The next tier, the regional logistics warehouses/distribution centers is also very simple. All goods are purchased from a vendor. This means that the vendor will have a matching sales invoice per regional logistics center.

All sales out of a regional logistics center is a intercompany sales order. If the center is a third party logistics provider, this means that the legal entity is mostly being handled by automated transactions and by integrations. What is important, is that it is an actual legal entity and is being handled as one. By doing this, it means that there are less need for customizations in handling financials and taxes.

Then we come to processes being handled in the headquarters; Enterprise processes and functions. This is the main topic of what I wanted to write about. The idea is to be able to control both the procurement/purchase and the distribution from a central perspective. It is fully possible to do this with standard AX, but it can be a bit resource intensive. I wanted to see if it was an easier way to deal with this, without making too many customizations. The concept is the “distribution order“.

Company wide distribution orders does not exists as a concept in standard AX. A distribution order is close to the “Buyer’s push” functionality that exists in Dynamics AX, but to be able to be handled in a global intercompany scenario. It means that you from a central perspective see and plan all the purchase orders and intercompany sales orders, regardless of whish legal entity that is performing the actual transactions.

The distribution order is not linked to a legal entity, but is created and controlled by HQ. The resources doing planning and procurement, and create a distribution, and add the lines/items they want to distribute. They can also add additional purchase order lines to the distribution. In the distribution lines the distribution quantity can be fetched directly from the purchase lines, or can be manually overridden.

It is also possible to “reverse” the creation process, where the planner starts with a set of manually created distribution lines, and then create the purchase orders created in each regional warehouse/legal entity.

It is also possible to create a distribution order of the type “On-hand” and “end-of-season”, that will base the quantity of the distribution lines on the available physical.

The planner can then run the process “create suggestion”, based on a distribution key. This will create a Distribution result. It will have one line per store. The planner can then choose to make manual changes. When the result is OK, then the planner can activate the distribution order. This will make the necessary intercompany sales orders from the regional logistics companies to the partner/stores.

Since the distribution order will have visibility across legal entities, the purchase lines and the intercompany sales orders can be additional linked through inventory marking. This can then enable the possibility for cross docking scenarios, and also to add the ability for direct delivery scenario’s.

We will then have the possibility to give the buyers and planes an overall view of all inbound and outbound logistics through all regional distribution centers. Also the ability to show current status and progress.

I have done this before in AX 2009 as you can read about here. And I would love to add this feature to the free Codeplex AX 2012 Global retail package. If this is interesting for you to have, please reach out to me, and we can have a discussion on an jointed cooperation.

Dynamics AX 2012: Warming up for presales demo

To really impress potential buyers of Dynamics AX, it is important that we are capable to show that AX 2012 responds fast. We normally use the Contoso hyper-v demo environment, and our laptops have limited resources. Starting a demo on a cold system, we often see that forms takes some time to operate in optimal performance. If you already have opened a form, it is much faster the second time you open it.

So how can we give the users a view of a fast system without manually opening all the forms prior to the demo?

We can warm them up J. I use the following job-script to open and close all the forms I’m planning to use. I just traverse through the AOT, and open the form, and then I close them again.

static void WarmupRF(Args _args)
{
    //This code is for "warming" up all RF* forms and code I have in the VAR-layer
    UtilElements e;
    TreeNode treeNode;
    FormRun formRun;
    Args args = new Args();

    while select e
        where e.utilLevel  == UtilEntryLevel::var    //<-- spesify layer here
        &&    e.recordType == UtilElementType::Form  //<-- and only forms
        &&    e.name like "RF*"                      //<-- I only want the forms that starts with the prefix RF*
        {
            try
            {
                treeNode = xUtilElements::getNodeInTree(xUtilElements::parentElement(e));
                args.name(treeNode.AOTname());
                formRun = ClassFactory.formRunClass(args);
                formRun.init();
                //formRun.run();   //<-- No need to run the form, but sometimes it can load the data
                formRun.close();
            }
            catch
            {
                Infolog.clear();
                continue;
            }
        }
}

The code must be modified to suit what you want to “warm-up”, but you get the idea.

This will make you demo go much more smooth, and you truly show the potential and performance of a warm Dynamics AX system.

Happy DAX’ing

DAX 2012 R3 – Kick-back, Bonus and marked support

We often see that vendor’s use loyalty marketing in hopes of nurturing customers to be even better customers. Introducing new products in a marked can be costly, and success is often rewarded based on performance.

We often encounter requirements where vendors is compensating with kick-back, bonuses and marked support on specific products. The agreements can be formulated like; If you sell more than 1000 units per quarter, we will give you a 10% discount on purchased products for that quarter. But the transactions and invoices then may be that the original invoice is on the exact amount, and each quarter a credit note with the bonus is received. The idea behind kick-backs can be controversial, but this is not the topic her.

Having the cost price on the products determined on the actual purchase price give a very good foundation for a healthy business model, and also gives a much better insight to revenues and margins . But this “delay” in the transactions and payments introduces some issues for customers that relies on using inventory models as FIFO, FEFO etc.

  • What is the actual cost price in a scenario with kickbacks?
  • How can we calculate the actual revenue and margins?
  • Does my system support this feature?

If you have Dynamics AX 2012 R3, then you are lucky. There is a very nice way to handle kickbacks effect on product cost prices, and making sure that the cost prices is affected accordingly.

The name of the feature is charges. With charges we make adjustments of the cost prices on the right dates, and on the right transactions. The inventory closing will make sure that the cost prices are settled to the sales orders/issue inventory transactions.

The first step is to create a new charge, that will adjust the cost price on specific invoices, and also post on a selected ledger account.

Then let’s say the following received invoice from 2013 of 200 Surface Pro 128:

I see on the inventory transactions that the cost amount is 179.800 USD.

The vendor now want to give me a kick-back for my effort of managing to sell these old notepads. When they send us a credit note of 50% of the amount, and I want to post this so that the cost price changes on the inventory transactions.

When this is posted it will adjust the cost of the inventory transaction on the selected posting date:

The voucher transactions looks like this.

In AX 2012 R3 the inventory transactions will make the necessary adjustments on the issue transaction.

The next step is to receive and post the invoice from the vendor post it against the selected ledger account on the charge code, and eventually also run the inventory closing procedure.

Conclusion;

There are no need to credit post the purchase order for adding kickbacks, bonuses and marked support etc. It is supported in Dynamics AX 2012 R3.

Happy DAX’ing

 

 

 

 

DAX 2012 Remove reservations and markings from a sales order

Some friends of me have asked how to remove reservations and markings on a sales order. Going through line by line can be time consuming and they wanted to know how this could be solved by a single “click”.

 

static void Tutorial_UnreserveSalesTable(Args _args)
{
    InventTrans             inventTrans;
    InventTransOrigin       inventTransOrigin;
    SalesLine               salesLine;
    InventMovement          inventMovement;
    InventUpd_Reservation   inventUpd_Reservation ;
    SalesId                 SalesId = "001260";//<--- Send/get sales id here

    // Remove reservations and markings on a reserved salesorder
    while select inventTrans
        where inventTrans.StatusReceipt                == StatusReceipt::None
           && (inventTrans.StatusIssue                 == StatusIssue::ReservPhysical 
           ||  inventTrans.StatusIssue                 == StatusIssue::ReservOrdered)
        exists join inventTransOrigin 
            where   inventTransOrigin.RecId            == inventTrans.InventTransOrigin
        exists join salesLine 
            where   salesLine.InventTransId            == inventTransOrigin.InventTransId                    
                &&  SalesLine.SalesId                  == SalesId    
    {
            if (inventTrans.MarkingRefInventTransOrigin)
            {
                InventTransOrigin::deleteMarking(inventTrans.MarkingRefInventTransOrigin, inventTrans.InventTransOrigin, -inventTrans.Qty, true);
                InventTransOrigin::deleteMarking(inventTrans.InventTransOrigin, inventTrans.MarkingRefInventTransOrigin, inventTrans.Qty, true);
            }

            if (inventTrans.StatusIssue == StatusIssue::ReservPhysical || inventTrans.StatusIssue == StatusIssue::ReservOrdered)
            {                
                Inventmovement = inventTrans.inventmovement(true); 
                inventUpd_Reservation = InventUpd_Reservation::newInventDim(inventmovement,inventTrans.inventDim(), -1 * inventTrans.Qty, false); 
                inventUpd_Reservation.updatenow(); 
            }
    }
}

The next step would be to create a class, so that it can be performed in CIL, and some code that refreshes the sales order for the end-user.

AX2012 – How to get Retail Store specific CUE’s

In Dynamics AX, the role center may contain a lot, but some times it is wanted to show more specific and isolated information. In this blog-post I would like to show you how to create a cue that only shows number of sales and amount related to a specific retail store. This blogpost is meant to show the pattern we can use, and is not only restricted to retail. We can use this technic almost everywhere in Dynamics AX.

Here we see a CUE where I show the number of sales and the amount for a specific store. But the nice thing here, it that the values changes depending on what store the user is assigned to.

Do be able to do this we need a dynamic query, that changes the store, depending on the current user, and we need to have a place, where a user is assigned to a store. This is already available in Dynamics AX, and is a setting on the User profiles

So here, I’m assigning a user to a role, and to a store. The next thing I need to have is a way to sum up all the retail sales transactions, and for this I use the form Retail sales transactions.

I then create an advanced filter by using the CTRL-F3, and save as a CUE.

You see here that in the criteria for store number, I write (EGCurrentRetailStoreID()). This is a very nice trick in Dynamics AX. The ability to create dynamic queries. I have blogged about it before here.

The code needed to use dynamic query criteria is located in SysQueryRangeUtil is the following:

This code will return the store ID for the current user. The last step is to select the CUE in the shared role center.

Then you have a CUE, that shows the sales in your local retail store.

 

Happy DAX’ing