Sorting orders in ticket printer template

OK, I feel a little stupid asking this, but I can’t quite make sense of the various posts I have read about this…

I have an order state called BookingDate which stores a string in yyyymmdd format to hold the date that someone wants to dive. Each dive is a different order and sometimes people book dives out-of order, so I was hoping I could have the ticket template sort and group everything correctly.

However, although orders do get grouped, they do NOT seem to be sorted in order…

For example, if I create the following ticket (note the dates displayed as order states)
image

I have the following setup in the ticket template (the JS call does a lot of heavy lifting to make things look nice)

[ORDERS GROUP|ORDER STATE:BookingDate]
<tr><td colspan=3>{CALL:tkt.dateHeader('{GROUP KEY}')}</td></tr>
[ORDERS]
<tr class="orderHeader">
<td><span style="font-weight:bold">{PRODUCT NAME}............
.................

I then end up with the following ticket output…
image
Interestingly, you can see that the 3rd item on the list was correctly grouped under 3-APR, but overall the order is wrong (the 2nd item for 1-APR should have appeared first)

I am not sure what I should be selecting at the top of template editor
image
[BLANK - No selection] seems to make no difference
None seems to make no difference
Order State:X seems to make no difference
Order State:BookingDate seems to make no difference, but sometimes throws an error complaining about not implementing “IComparable”

What should I be doing to have my orders displayed in the correct order?

I am still struggling to get this working…

The states that I have (in order of added to ticket are):

  • 20190403
  • 20190401
  • 20190403

I would like the orders to be sorted in alpha/numerical/chronological order:

  • 20190401
  • 20190403

If I update by [ORDERS GROUP|] then I can add a manual sort order and the output is how I would expect. (Note I am now using “Document Printer” notation for the various advantages @markjw ourlined.

[ORDERS GROUP|ORDER STATE:BookingDate:20190401,20190403]
<TableRow><TableCell Padding="0,10,0,0" ColumnSpan="3">{CALL:tkt2.dateHeader('{GROUP KEY}')}</TableCell></TableRow>

Of course I cannot manually add these numbers, so I started thinking about how I could produce the ordered list of states to feed in to the [ORDERS GROUP|] and I came up with the following:

{REPORT ORDER DETAILS:OS.BookingDate.asc:T.Id={TICKET ID}::,}

This works perfectly and will create a CSV list of BookingDates anywhere within my printer template, however when I add this CSV to the [ORDERS GROUP|] definition it seems to have now effect whatsoever.

Any ideas where I might be going wrong?

Did you try just changing the Sort Order on the Printer Template?

Set it to Order State:X. My belief is it will sort alphabetically if you don’t specify the manual sort order. Your dates for BookingDate should sort correctly with Apr 1 being first.

PS: I like your “calendar style” dates on the receipt, nice touch!

3 Likes

Well that was my thought, but setting “Order State:X” doesn’t do anything.

And yes, I figured 20190401 would be positioned before 20190403, but for some reason this is not what happens… The states are displayed in the order that they appear on the ticket, rather than being sorted.

Cheers for you comments on the calendar… We had issues where people didn’t read their tickets properly, this is why I am updating with this sorting and grouping logic, so I added the calendar to make things as clean as possible. In case it helps anyway, this is the JS I used to create the associated Document Printer content…

function dateHeader(ymd) {
	if(!/^(\d){8}$/.test(ymd)) return '';
	
	var months = ['JAN', 'FEB', 'MAR', 'APR', 'MAY', 'JUN', 'JUL', 'AUG', 'SEP', 'OCT', 'NOV', 'DEC'];
	var enDays = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
	var esDays = ['Domingo', 'Lunes', 'Martes', 'Miércoles', 'Jueves', 'Viernes', 'Sábado'];
	 
	var y        	= ymd.substring(0,4);
	var m      		= ymd.substring(4,6);
	var d         	= ymd.substring(6,8);
	var bookingDate	= new Date(y, m-1, d);
	
	var enDay			= enDays[bookingDate.getDay()];
	var esDay			= esDays[bookingDate.getDay()];
	var date			= bookingDate.getDate();
	var month			= months[bookingDate.getMonth()];
	var year			= bookingDate.getYear();


var html = ''
html += '<Table><Table.Columns><TableColumn Width="35" /><TableColumn/></Table.Columns>';
html += '<TableRowGroup>';		
html += '<TableRow>';
html += '<TableCell TextAlignment="Center">';
html += '<Paragraph Background="Black" Foreground="White"><Bold>'+ month + '</Bold></Paragraph>';
html += '<Paragraph FontSize="15" BorderThickness="0.5,0,0.5,0.5" BorderBrush="Black">'+ date + '</Paragraph>';
html += '</TableCell>';
html += '<TableCell Padding="6,0,0,0">';
html += '<Paragraph>'+ esDay + '</Paragraph>';
html += '<Paragraph FontSize="15">'+ enDay + '</Paragraph>';
html += '</TableCell>';
html += '</TableRow>';
html += '</TableRowGroup>';		
html += '</Table>';
return html;
}