Custom value on printed bill

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. (
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.

@emre, did you miss this post by @devloic? Or are you referring to something else?

1 Like

@emre Sorry if I was not clear enough. Actually it’s not that complicated (on the paper) . To comply with the Bolivian fiscal regulation I need to print a checksum on the bill, the pseudo code for the checksum generation is more or less like this :

  • checksum = Base64(Verhoeff (RC4( ticket total, ticket date, company identification number, company authorization number, secret key)))

(for more details see the pdf of the specification in spanish attached to this post : CodigoControlV7.pdf (72.7 KB) )

In v4 it’s not possible to make those kind of calculation so for now I am following the advices of the great people of this thread who recommended me to use a “Start Process” action and use a delay. I coded the the checksum algorithm using the php sources available here for the encryption ( ) , compiled the php code to an exe using phc-win ( 1.0.2 with supports php5 ), packed everything including dll with ‘bat to exe converter’ ( and tested it in sambapos. It seems to work okay but I need to put some controls so there will never be a bill printed without a checksum on it and check the whole process works well with takeway tickets , tickets that get new orders added etc… Finally I need to deploy and test it on every terminal (tablet, server, tablet with rdp) . Since the tablet comes with windows 8.1 and the server is windows 7 I need to be sure the php compiled script runs okay (php is flexible but sometimes different dll are required according to the os/architecture/locale and sql server version) . If the Bolivian specification change for some reason I need to do all the development steps again. I’d feel so much more confident if I could try to implement something in v5 right now because it will remove a lot of plumbery. The javascript cryptografic libraries I need are available so what took me two days for now may take me 20 minutes in v5.


OK. I’ve moved topic to V5 Beta (and added @Mura to testers group) so that topic won’t confuse people.

I can add support for Base64 as it already has .net implementation. I’ll check other algorithms as well.

Edit: RC4 and Verhoeff seems like simple to implement so I’ll skip them.


This is how base46 function could be implemented.

function b64(input)
  var convert = host.type("System.Convert");
  var encoding = host.type("System.Text.Encoding");
  var inputBytes = encoding.UTF8.GetBytes(input);
  return convert.ToBase64String(inputBytes);


@emre it would certainly be useful as it is commonly used and window.btoa & window.atob doesn’t seem to be available in jscript outside of internet explorer 10.

BTW to get you started in v5 with the powerful scripting options look here for example of how we built a basic Weather Forecast into a navigation tile using {CALL:X} and Jscript.

Its not the same implementation but it shows you how its used and could give you an idea where to start.

Also keep in mind our scripting engine is compatible with ecmascript3 so Verhoeff implementation might not work as it uses some ecmascript5 features like Let me know if you encounter any issue.

After porting the checksum generator from php to jscript and passing the certification process online I am glad to announce that SambaPOS was certified by the “Servicio Nacionales de Impuestos” (SIN) of Bolivia as a valid computerized billing system. That’s pretty cool because I didn’t intend to give away food for free in my restaurant.

@emre yeah I stumbled over this one “”, I had to look for some other library. Would have been more sexy to use nodejs but I am still very happy with what I can use now. I can’t say it’s very convenient coding javascript directly in V5, I’ll have to check how well it works with the visual studio debugger. I finished coding on because I was tired of saving the script, then saving the template , going back to the main menu and back again to the scripts (otherwise sambapos wouldn’t use the modification). Preview mode is really useful though.

@Jesse yep, the weather forecast helped me to get started because at the beginning there was no magic during half an hour until I pasted the weather code and V5 started to shine.


Nice to hear you solved it. Great! Actually SambaPOS doesn’t have much IDE features but when needed visual studio debugger works fine.

Hope you’ll have free time to prepare a tutorial for other Bolivian SambaPOS users.

@emre Okay I will post the code and configuration asap.


Here is the javascript code for generating the checksum. (3.0 KB) Copy paste it inside a script:

The function that gets called in the printer templates is : getChecksum(numautorizacion,numfactura,nitcliente,fecha,monto,clave) .

Call the function inside a printer template with:
codigo de control:{CALL:codigo_control_v7.getChecksum(‘78978945645’,‘1’,‘2454897564’,‘20150511’,‘45800’,‘adza4dacq4dzada4vafaz45dza1cza4faz’)}