I know this is something very special for my setup, but I wanted to show people how to handle Tickets Tags…
I have several ticket tags…
Waiter (three sometimes more)
People sitting at the table
Dine In or To GO
So I was needing a report that could show me how much TAXA DE SERVIÇO I should pay to each Waiter at the end of the day, and wanted to know too, how much I payed at the end of the month… so I had to look into Tickets, search the TicketTag and do some calculations for TAXA DE SERVICO and DESCONTO (DIscount, that goes out of the waiter pocket, we dont do discounts, and when a discount is made, I AM THE WAITER).
Hope this helps others to see how to use TICKET TAGS in Custom Reports…
Report:
[Comisiones por Garçon:2, 1, 1, 1, 1, 1, 1]
>Garçon|Pessoas|Neto|Taxa|Desc|Ticket|Comision
@@TotalComisiones
SQL:
SELECT
min(substring(cast(TicketTags as nvarchar(4000)),
CharIndex('{"TN":"Garçon Pizzaria","TT":0,"TV":"',cast(TicketTags as nvarchar(4000)))+37,
CharIndex('"',cast(TicketTags as nvarchar(4000)),
CharIndex('{"TN":"Garçon Pizzaria","TT":0,"TV":"',cast(TicketTags as nvarchar(4000)))+37
)- CharIndex('{"TN":"Garçon Pizzaria","TT":0,"TV":"',cast(TicketTags as nvarchar(4000)))-37)
) as [Garçon],
SUM(CONVERT(INT,substring(cast(TicketTags as nvarchar(4000)),
CharIndex('{"TN":"Pessoas","TT":1,"TV":"',cast(TicketTags as nvarchar(4000)))+29,
CharIndex('"',cast(TicketTags as nvarchar(4000)),
CharIndex('{"TN":"Pessoas","TT":1,"TV":"',cast(TicketTags as nvarchar(4000)))+29
)- CharIndex('{"TN":"Pessoas","TT":1,"TV":"',cast(TicketTags as nvarchar(4000)))-29)))
as [Pessoas],
FORMAT(SUM(T.TotalAmount)-SUM(Cal.CalculationAmount),'C') as NetoTicket,
FORMAT(SUM(case
when Cal.CalculationTypeId = 4 then Cal.CalculationAmount
else 0 end),'C') as Taxa,
FORMAT(SUM(case
when Cal.CalculationTypeId = 1 then Cal.CalculationAmount
else 0 end),'C') as Desconto,
FORMAT(SUM(T.TotalAmount),'C') as TotalTicket,
FORMAT(SUM(Cal.CalculationAmount),'C') as TotalTaxa
FROM Tickets AS T
LEFT OUTER JOIN TicketEntities as TE on TE.Ticket_Id = T.Id
LEFT OUTER JOIN Calculations as Cal on Cal.TicketId = T.Id
WHERE Date > '{Start}' and Date < '{End}'
GROUP BY (substring(cast(TicketTags as nvarchar(4000)),
CharIndex('{"TN":"Garçon Pizzaria","TT":0,"TV":"',cast(TicketTags as nvarchar(4000)))+37,
CharIndex('"',cast(TicketTags as nvarchar(4000)),
CharIndex('{"TN":"Garçon Pizzaria","TT":0,"TV":"',cast(TicketTags as nvarchar(4000)))+37
)- CharIndex('{"TN":"Garçon Pizzaria","TT":0,"TV":"',cast(TicketTags as nvarchar(4000)))-37)
)
ORDER BY (substring(cast(TicketTags as nvarchar(4000)),
CharIndex('{"TN":"Garçon Pizzaria","TT":0,"TV":"',cast(TicketTags as nvarchar(4000)))+37,
CharIndex('"',cast(TicketTags as nvarchar(4000)),
CharIndex('{"TN":"Garçon Pizzaria","TT":0,"TV":"',cast(TicketTags as nvarchar(4000)))+37
)- CharIndex('{"TN":"Garçon Pizzaria","TT":0,"TV":"',cast(TicketTags as nvarchar(4000)))-37)
)
Just to make shure you all understand…
this portion of the SQL does the trick:
substring(cast(TicketTags as nvarchar(4000)), CharIndex('{"TN":"Garçon Pizzaria","TT":0,"TV":"',cast(TicketTags as nvarchar(4000)))+37
So you have to replace {"TN":"Garçon Pizzaria","TT":0,"TV":" with whatever TAG you are looking for and replace the +37 with the lenght of the string you are looking for.
Thanks!!!
G.