I have been following @QMcKay’s tutorial on customer purchase history and used some of the examples as the basis for something I wanted to do.
Q’s version gives a reasonably detailed output on an order-by-order basis, something like this…
Item QTY Price Total
Pizza 2 10 20.00
Burger 1 5.50 5.50
Drink 2 1 2.00
This works great, but I need to ability to list on a ticket-by-ticket basis what was ordered and how it was paid for. I also use A LOT of order tags, so these also need to be included. Something like this…
>>Ticket 1 05-MAY-2018 35.00
>2 Pizza 20.00
+ Extra cheese 5.00
+ Extra meat 5.00
>1 Burger 5.50
+ Mayo 0.50
+ Bacon 4.00
== CASH -30.00
== Card -5.00
>>Ticket 25 06-MAY-2018 3.00
>2 Drink 2.00
+ Ice 1.00
== CASH -3.00
I have been able to create this report successfully using the following template. Our EnityNames are customer email addresses.
@{REPORT TICKET DETAILS:T.Id:(TEN.Customers=dave@gmail.com):,}
@{REPORT ORDER DETAILS:O.Id:T.Id=$1::,}
>>@@GetTicketDetailsFromTicketId:$1
>@@GetOrderDetailsFromOrderId:$2,$1
@@GetOrderTagDetailsFromOrderId:$2,$1
@@GetPaymentsFromTicketId:$1
This gives the result I am looking for because of the way the SambaPOS handles the looping of the $ variables. There is almost an outer-loop of the $1 and an inner-loop of the $2.
This works create when I hard-code an EntityName in to the report. However, I need to use a Custom Report Viewer Widget to display this report and pass the EntityName as a variable in to the report.
The problem I have in 5.1.61 and 5.2.3 is that it seems when I pass a variable in to the report viewer it replaces the value of the first @List
. So, I thought, OK, let me make an extra @List
at the start of the report that I don’t mind being over-written…
[Customer Purchase History:1,4,1,1,1]
@dave@gmail.com
@{REPORT TICKET DETAILS:T.Id:(TEN.Customers=$1):,}
{REPORT SQL DETAILS:SELECT Id FROM Orders Where MenuItemName != '$1' AND Ticketid = $2:F.Id::,}
The $1 in the SQL statement is not required, but I found that for me to get the results I was expecting I had to include both $1 and $2 on that line so SambaPOS would loop correctly and give me a value for $2. The above report works as expected and gives an output as follows…
101,102 -- The order IDs for Ticket 1
243 -- The order IDs for Ticket 25
So far so good, but when I then try to use these IDs as an @lsit
everything starts to go wrong…
[Customer Purchase History:1,4,1,1,1]
@dave@gmail.com
@{REPORT TICKET DETAILS:T.Id:(TEN.Customers=$1):,}
@{REPORT SQL DETAILS:SELECT Id FROM Orders Where MenuItemName != '$1' AND Ticketid = $2:F.Id::,}
$1 $2 $3
Output
dave@gmail.com 1 $3
dave@gmail.com 25 $3
So what is going on here? Why is the SQL able to successfully take the $2 variable and output the OrderIDs as expected, but when I use it as an @List
it doesn’t work.
Further investigation…
To try to debug this, I turned the SQL statement in to a script ({CALL:x.getOrderIdsByTicketId($2,$1)})
and inside this script I used a dlg.show('Finding Order IDs');
to create a popup so I could confirm the script was running. When I ran the script without using it as an @List
everything worked as expected and I saw the pop-up message. BUT, when I tried to use the script as @List
I no-longer see the pop-up, so it is as if SambaPOS is just not firing that script at all and that’s why I never see any results for the third variable $3.
Any ideas on what might be wrong, or a better way I can achieve this TicketID + OrderID looping?