I am working on the source code of a restaurant POS (Samba pos), and I have 2 problems how the output is formatted when printing a ticket.
The code below collects the tags of products, make headers of them, and sort the products below the header.
Problem 1: I have no influence in the order of headers so the output looks like:
Main course
Steak 22,50
Drinks
Cola 2,00
Starters
Soup 3,50
The right order should be Starters –> Main course –> Desserts –> Drinks
If I could sort the headers alphabetically I would be helped very much. I would change the group tags into: 1 Starters, 2 Maincourse etc etc
Problem 2:
The products are grouped in an earlier stage of the program. Due to choices of the programmer the grouping doesn’t work well for me. I have a long list on the ticket like:
1 x Cola 2,00
2 x Cola 4,00
Is there a way to group products here so that I will have:
3 x cola 6,00
Here is the piece of code:
if (template.GroupTemplate.Contains("{PRODUCT TAG}"))
{
var groups = lines.GroupBy(GetMenuItemTag);
var result = new List<string>();
foreach (var grp in groups)
{
var grpSep = template.GroupTemplate.Replace("{PRODUCT TAG}", grp.Key);
result.AddRange(grpSep.Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries));
result.AddRange(grp.SelectMany(x => FormatLines(template, x).Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries)));
}
return result;
}
I have to sort var groups. The problem is that the text {PRODUCT TAG} is replaced with grp.Key within the loop, so ordering var groups before the loop probably won’t work (do I need an extra loop?).
Adding the products to the headers is done on the 3 line of the loop. Is it possible to group items here?
I have dumped the whole file here:
http://pastebin.com/qFr5wN28
Edit:
This piece of code is for producing a ticket on a ticketprinter. A ticket would look like this:
BON
Datum: 2-2-2013
Tijd: 18:35
Tafel nr.: B22
Bon nr: 2
------------------------------------------
Breakfast
- 1 Toast and Jam 1,50
- 1 Egg, Bacon Cheese 3,99
- 1 Toasted Bagel Cheese 2,25
- 1 Toasted Bagel Jam 1,50
- 2 Toast and Jam 1,50
- 1 Egg, Bacon Cheese 3,99
- 1 Bacon and Cheese 3,49
- 1 Bacon and Tomato 3,49
Deserts
- 1 Rice Pudding 2,25
- 1 Fruit Danish 1,50
Main course
- 1 Chicken Garden Wrap 5,25
- 1 Chicken Caesar Wrap 5,75
- 1 Canadian Wrap 6,99
- 1 Chicken Greek Wrap 6,99
The headers are tags that I can add to products.
There are several things wrong: the headers above the articles (Deserts, Main Course) appear randomly. I would like to sort them. Not all articles are grouped, for example "toast and jam". If I could sort the headers, I would change the tags a bit. A desired output would be like this:
------------------------------------------
1 Breakfast
- 3 Toast and Jam 1,50
- 2 Egg, Bacon Cheese 3,99
- 1 Toasted Bagel Cheese 2,25
- 1 Toasted Bagel Jam 1,50
- 1 Bacon and Cheese 3,49
- 1 Bacon and Tomato 3,49
2 Main course
- 1 Chicken Garden Wrap 5,25
- 1 Chicken Caesar Wrap 5,75
- 1 Canadian Wrap 6,99
- 1 Chicken Greek Wrap 6,99
3 Deserts
- 1 Rice Pudding 2,25
- 1 Fruit Danish 1,50
You can order your lines using
OrderBylike so:You also loop through the groups and amend the value of your key. This could be done by adding a
Selectprojection to your group.EDIT:
After thinking about this I realised I was being a little dumb yesterday. I think the following will help you:
OUTPUT:
Obviously you will need to modify the datatypes, etc, but the query itself should give you what you need.