Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to Read Itemdiscount using Simphony Extensibility C# Code

Status
Not open for further replies.

Vikram Singh

Programmer
Jan 3, 2018
39
0
6
KW
Hello everyone
I want to read the ItemDiscount using Simphony Extensibility
forTek-Tips_pgka1u.png
from OpsContext.CheckDetail[]. I’m able to read the details of the normal discount but I don’t know how to read Itemdiscount details for a particular parent item please help. Please refer to the Screenshot for a better understanding of my problem. Please help me with the required C# code.
 
Hello Abhi,
Something like this whould work:
C#:
public void ShowItemDiscounts()
        {
            foreach (var checkDetail in OpsContext.CheckDetail)
            {
                if (checkDetail.DetailType != CheckDetailType.DtlTypeDsc) continue;
                var discDtl = checkDetail as OpsDiscountDetail;
                if (!discDtl.ItmDsc) continue;
                var itemDtl = GetCheckDetailItemByDetailLink(discDtl.MenuItemDetailLinks[0]);
                OpsContext.ShowMessage($"Discount '{discDtl.DetailLink}:{discDtl.Name}' is applied to '{itemDtl?.DetailLink}:{itemDtl?.Name}'");

            }
        }

        private Micros.PosCore.Extensibility.Ops.CheckDetailItem GetCheckDetailItemByDetailLink(int dtlLink)
        {
            foreach (var checkDetail in OpsContext.CheckDetail)
                if (checkDetail.DetailLink == dtlLink)
                    return checkDetail; 
            return null;
        }

Capture3_zda6dd.png
 
Thank You Very Much codexPOSed. It is working fine. It was really a great help for me. I was stuck for more than a week[bigsmile]

I have one more problem related to the same topic.

Can you help me to add an Item Discount to an Item along with some string data and read back the same from the code you have given above
 
i don't have working sample, but you need to new up some OpsCommands and process them using OpsContext.ProcessCommand. That's like LoadKybdMacro in isl. I seem the remember some samples in this blog. Search for OpsCommand...

If you can't get it to work, post back, i'll try to pro-type a sample for you
 
Thank you for your quick response codexPOSed . Presently I'm using the below code to insert an item discount. and it is working fine for me.

var result = OpsContext.ProcessCommand(new OpsCommand(OpsCommandType.Discount) { Number = DisObjNum });
resultOk = result.IsSuccess;


My requirement is to get a code that can add a custom string to OpsDiscountDetail and retrieve back the same
custom string by using the code you have given me in your first replay .

as you advised I have searched with OpsCommand in the same blog unfortunately I can't find something similar to my requirement.

If you can give me a sample C# snippet it will be a great help.
 
Hi Abhi,
I thought you can chain the OpsCommands like we were used to be able to with LoadKybdMacro in ISL, but i think you need to create a macro, which i don't know how to do.
The commands you can use to save a reference to discount (Asssming that the discount has "Reference Entry Required" checked in EMC) :
OpsContext.ProcessCommand(new OpsCommand(OpsCommandType.AsciiData) { Text = " blah" });
OpsContext.ProcessCommand(new OpsCommand(OpsCommandType.EnterKey) );


After that, you can use the References collection on the check detail to retrieve what you have input as reference at the time you rang it up.

 
@codexPOSed
Thank you very much for the information. This information is helpful.

The idea you gave me is working fine. But I don't know how to retrieve back the value " blah"
from the code. You have asked me to use something called References collection but actually, I have no idea
what it is. If you can provide me a sample C# Script for reading the value from the item discount entry it will be a great help to me. Thank you
forTek-Tips_fupbtd.png
 
hey Abhi,
Can you please share the snippet of how you managed to ring up the reference? how did you setup the macro? I wasn't able to do that.
here's how you can get the reference entries:
Code:
public void ShowItemDiscounts()
{
          foreach (var checkDetail in OpsContext.CheckDetail)
            {
                if (checkDetail.DetailType != CheckDetailType.DtlTypeDsc) continue;
                var discDtl = checkDetail as OpsDiscountDetail;
                if (!discDtl.ItmDsc) continue;
                var itemDtl = GetCheckDetailItemByDetailLink(discDtl.MenuItemDetailLinks[0]);
                var references = "";
                foreach (var referenceEntry in discDtl.ReferenceEntries)
                    references += referenceEntry.Descriptor +", ";
                OpsContext.ShowMessage($"Discount '{discDtl.DetailLink}:{discDtl.Name}' is applied to '{itemDtl?.DetailLink}:{itemDtl?.Name}' with ref entries='{references}'");

            }
}
 
@codexPOSed Your code for reading reference is working fine [2thumbsup]. Thank you very much. You help me to resolve an issue that was a showstopper for my current integration project.


Below is the snippet you ask for. I just created a List Object of OpsConamd and use the same as ProcessCommand's Parameter. It is working fine for me. Please test the same from your side hope it will work.

Once Again thank you for your great support


Code:
[COLOR=#CC0000]
OpsCommand cmdMacro1 = new OpsCommand(OpsCommandType.Macro);
                    cmdMacro1.Data = new List<OpsCommand>();
                    ((List<OpsCommand>)cmdMacro1.Data).Add(new OpsCommand(OpsCommandType.Discount) { Number = DisObjNum });
                    ((List<OpsCommand>)cmdMacro1.Data).Add(new OpsCommand(OpsCommandType.AsciiData) { Text = "blah" });
                    ((List<OpsCommand>)cmdMacro1.Data).Add(new OpsCommand(OpsCommandType.EnterKey));
                    var result  = OpsContext.ProcessCommand(cmdMacro1); [/color]
 
you are welcome, glad it helped, and thanks for the macro implementation, that is very useful!
 
Reading check details from OpsContext.CheckDetail is not compatible with 19.2 and newer, you should consider using the GetFlattenedCheckDetail() method instead, with works with all versions of Simphony.

The CheckDetail property still exists on the OpsContext, but the underlying types have been moved to other dll's, so the runtime will through a method not found exception on 19.2
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top