Custom value on printed bill

Hi community,

I am about to open a small restaurant here in Bolivia and for legal reasons I need to set a checksum code generated on the fly on the clients printed bill. The code is generated according to the total amount, date , etc … and uses some algorithms like Verhoeff, AllegedRC4, Base64 . There are no such functions in SambaPOS so I have to generate it outside of sambaPOS. The easiest way would be calling a .bat script that would generate the code and pass it to sambaPOS but after reading this post : Execute PHP Script catching return values from a script doesn’t seem to be implemented. So I am thinking about calling a php script that would generate the code and then hit the database directly to update some ProgramSetting Variable (or maybe some custom Entity) which I could then retrieve in my bill printer template. I am affraid though that there would be a timing problem because I guess SambaPOS doesn’t wait for the script (that would be launched with a ‘Start Process’ action) to finish before completing the next action so the template might use a value that might not have been set yet. Is there any trick in sambaPOS v4 to complete my requirement? I heard V5 has some nice scripting features, any chance it could help me ? Thanks.

Yes V5 can help but without knowing implementation details it will be hard to guess. Does it have a Javascript implementation?

Hi @devloic, while I am not experienced enough to discus scripting and php or editing the database outside of Samba after reading your post the only thought I had was when you refer to

If this is the case a possible basic solution which came to mind would be using an automation command delay or the background field.
I had to use a similar method with my ‘Prevent Ticket being opened on multiple terminals’ and ‘Prevent user loging in on multiple terminals at same time’ setups as they called for close ticket action on an open ticket rule and logout on login rule which caused a ‘issue’ as other things had to happen in the same process.
While im not sure if this function will solve your issue or exactly how you might utilise them. Here are the links to tutorial where I used them;
http://forum.sambapos.com/t/tutorial-prevent-ticket-being-opened-by-multiple-users-terminals/5290?u=jtrtech
http://forum.sambapos.com/t/tutorial-single-user-sessions-prevent-same-user-logging-in-on-multiple-termianls/5291?u=jtrtech

@emre I asume that you are wondering if the code verification generation could be written in javascript.
There are javascript libraries for RC4 https://gist.github.com/farhadi/2185197 , Verhoeff http://en.wikibooks.org/wiki/Algorithm_Implementation/Checksums/Verhoeff_Algorithm#JavaScript and Base64 https://github.com/dankogai/js-base64. The rest is basic javascript so the answer is yes, we could generate the checksum with javascript.

1 Like

Thanks @JTRTech for your reply. I tried to open your tutorials but I get “Sorry, you don’t have access to that topic!” on every link.

That is because he linked you v5 Beta forum threads. Silly @JTRTech he is new to the beta group so still learning the ropes of how it works, sorry for that.

Oh, sorry, didnt think about that…
If you search for automation command delay and background you should find other threads.
I would imagine the background may not help as believe its in relation to samba process que but delay might help.
Your payment processed bill printing could be ‘looped’ in that it instead of an action for the print job its an action for automation command with a delay with a separate rule to fire the print job action after the delay giving your code time to generate and save to program setting.

The background option is v5 only. But the delay is in v4. It wont be long before v5 is released. Sometime in June is the target. With v5 we can call Jscript functions and looking at some of those you linked I dont see why they wouldnt work. So v5 will definitely help you.

Knew there was a reason I put in V5 beta, sorry not quite fluent enough in V4 to remember which features are new to V5 as most of my more detailed ‘tinkering’ has been in V5 beta.

Here is a topic discussing the delay feature in general question catagory;

This should work, even in V4.

First, manually insert a row into the table [ProgramSettingValues] with the [Name] set to CHECKSUM.

Use an UPDATE query in PHP to set the value for CHECKSUM.

Set your Print Bill Rule to call the PHP script, and use a delayed Execute Automation Command Action to actually print the Bill. A delay of 1 second should suffice.

In your Printer Template, you simply read the value in SambaPOS with {SETTING:CHECKSUM}.

With V5, the process would be simplified, but I am confident you could make the above work in V4.

2 Likes

Thanks @JTRTech , @QMcKay @Jesse for guiding me to the solution. I am testing. I am still a bit worried about how to manage concurrent update of {SETTING:CHECKSUM} in case two bills get printed at the same time. I guess the best would be to set a Program Setting for each ticket number ( ex: {SETTING:CHECKSUM_00111}, {SETTING:CHECKSUM_00112} … } but is there a syntax to use dynamic variable names in the templates? something like {SETTING:CHECKSUM_{TICKET NO}} ? I guess a better solution would be to store the checksum number directly in ticket tags or ticket states via sql (with php).

If you update the setting on Ticket Closed you can use {TICKET ID} so it might look like {SETTING:CHECKSUM_{TICKET ID}}

1 Like

{TICKET ID} would be what you want not {TICKET NO} but {TICKET ID} is only generated when a ticket is closed that is why I mentioned Ticket Closed event.

Easier said than done. States and Tags are stored in JSON format in single fields in the DB tables, so parsing and reassembly would be a PITA.

Yes, you could do exactly that, but you should prefer {TICKET ID}. It is the unique [Id] field in the [Tickets] table.

Do you need to ‘archive’ the codes or can you reverse process them to get ticket if etc.

You said you were concerned about issues of two bills printed at same time, which suggests multiple terminals.
If the program setting is just to allow the generated code to be added to the printed bill could you not use ‘local program setting’ or use terminal name as the reference for your setting name?

Local = True in the Update Program Setting Action means that the value is not stored in the Database. It won’t work in this case, since the codes are not being stored by SambaPOS in the first place; instead they are being written by PHP code directly to the DB.

I really believe this could work in v4 with some experimentation, but with v5 JScript support, it will become so much easier I’m sure… if we have the libraries built-in for Verhoeff, AllegedRC4, Base64.

Another question for you @devloic: do any of these functions exist within SQL Express 2014? If not, could they possibly be implemented as Stored Procs perhaps? If we could put the code into SQL, then we could simply use the Execute Script action to fire a SQL script that generates the code and inserts it into the DB.

@JTRTech There is no way to get the ticket information from the checksum itself by reversing the algorithm or so. But it’s okay, since I am storing everything with {:CHECKSUM_{TICKET ID}} I can link a ticket to its checksum anytime.

@QMcKay Verhoeff, RC4, Base64 are available in javascript. I checked the docs of sql express, RC4 isn’t available anymore, it was deprecated. It might be possible to code the whole algorithm from scratch in T-SQL but for me it looks very complicated compared to php.

Its maybe not a bad idea to think about a good solution for that case.

Here in austria they will also make such a system mandatory by next year. You will have to send the amount and maybe other things to a smartcard which generates a hash and than safe that in your database next to the bill and also print it on the bill. (the law is not finished yet. It will be in the next month) because of the smartcard will be secure by itself there is no certification needed for the software.

From what is released now they will use the german insika System. (http://www.insika.de/en/)
Because i like SambaPOS very much i would like to use it when i need a POS System next year.
I can provide a virtual machine with a real Insika Smartcard attached for development and testing purposes if needed.
I would also pay to implement such a system when the final law is released.

And from what i know also in belgium such a system is mandatory. And other countries like germany are thinking about it. So it would not be a bad idea…

And because i didnt read it elsewhere: Will V5 have multilanguage support?? And if so think about a quickchange button(predefined 2 languages) anywhere in the POS interface so maybe the waiter can quick change between his native language and e.g. english for the guest.

@Mura thank you very much for the detailed description. We’ll support that kind of needs and open needed integration points for such devices. What you’ve described sounds like a great solution for both software developers and govs. Please let us know updates about that.

@devloic We’d like to help to solve your issue but it is hard to blind guess what you’ll need. If you have a link, document or sample code it will make things a lot easier.