Monday 21 March 2016

Microsoft Dynamics AX Retail Modern POS | Adding Customized Content on a Modern POS Receipt

In this blog, I will take you through to add a customized content on the receipt in MPOS.
You can add custom fields in AX and bind it in the code in Modern POS.
  1. Add Custom Fields in AX. This process is same as we used to do for Enterprise POS.
Lets take example of adding barcodes for the items in the receipt. Go to Retail>Setup>Language Text>Click New>Add Barcode.


Now go to Retail>Setup>Custom Fields>Add Barcode. Select Type as Receipt.


Add Barcode in the Lines Section of the Receipt designer.


Push this to the Channel DB.
2. Now We will look upon the Retail SDK.
For any customization in MPOS where we have to get data from the database or save data into database, We need to write a Request Class,Response Class and Handler Class. For all these class code is written on CommerceRuntimeSDK(This is part of RetailSDK).
Open the sdk.SqlserverDataservice project and add classes.
For this particular customization, Request class will be like this:

Response class is like this:

Code for the Handler Class is as follows:
namespace Microsoft.Dynamics.Commerce.Runtime.DataServices
{
public class GetItemBarcodeHandler:IRequestHandler
{
public IEnumerable<Type> SupportedRequestTypes
{
get { yield return typeof(GetItemBarCodeRequest); }
}
public Response Execute(Request request)
{
if (request == null)
{
throw new ArgumentNullException(“request”);
}
Response response = null;
Type reqType = request.GetType();
if (reqType == typeof(GetItemBarCodeRequest))
{
response = GetItemBarcode((GetItemBarCodeRequest)request);
}
else
{
string message = string.Format(CultureInfo.InvariantCulture, “Request ‘{0}’ is not supported.”, reqType);
throw new NotSupportedException(message);
}
return response;
}
private GetItemBarcodeResponse GetItemBarcode(GetItemBarCodeRequest request)
{
ThrowIf.Null(request, “request”);
SqlServerDatabaseContext sqlServerDatabaseContext = new SqlServerDatabaseContext(request.RequestContext);
if (!string.IsNullOrEmpty(request.ItemId) && !string.IsNullOrEmpty(request.InventDimId))
{
return new GetItemBarcodeResponse() { ItemBarcode = GetItemBarcodeforItem(request.ItemId, request.InventDimId, sqlServerDatabaseContext).ToString() };
}
else
{
throw new ArgumentException(“Barcode not available.”);
}
}
private string GetItemBarcodeforItem(string itemId, string inventDimId, SqlServerDatabaseContext sqlServerDatabaseCon)
{
string barCode = string.Empty;
ParameterSet parameters = new ParameterSet();
parameters[“@ItemId”] = itemId;
parameters[“@InventDimId”] = inventDimId;
string selectQuery = @”DECLARE @Count INT
SET @Count=(SELECT COUNT(*) from ax.INVENTITEMBARCODE WHERE INVENTDIMID=@InventDimId and ITEMID=@ItemId)
IF(@Count!=0)
BEGIN
select ITEMBARCODE from ax.INVENTITEMBARCODE WHERE INVENTDIMID=@InventDimId and ITEMID=@ItemId
END
ELSE
BEGIN
SELECT ‘None’ AS ITEMBARCODE
END”;
var sqlQuery = new SqlQuery(selectQuery, parameters);
barCode = sqlServerDatabaseCon.ExecuteScalar<string>(sqlQuery);
Trace.Write(barCode);
return barCode;
}
}
}
Now Come to the sdk.services project and open Receipt folder. There is a class called ReceiptService.cs inside the folder.
Add the below mentioned code in the class:
private static string GetItemBarcode(string itemId, string inventDimId, RequestContext context)
{
string returnValues = string.Empty;
ChannelDataManager channelDataManager = new ChannelDataManager(context);
long ChannelId = channelDataManager.Context.GetPrincipal().ChannelId;
GetItemBarcodeHandler obj = new GetItemBarcodeHandler();
var request = new GetItemBarCodeRequest(itemId, inventDimId);
GetItemBarcodeResponse response = context.Execute<GetItemBarcodeResponse>(request);
if (response != null)
{
returnValues = response.ItemBarcode;
}
return returnValues;
}
Goto GetinfofromSalelineItem method and write below mentioned code as show in the image:

Build the project and put the dll in the retail server bin folder and Run MPOS.

Barcode shown in the Receipt.



No comments:

Wikipedia

Search results

Contact Form

Name

Email *

Message *