Custom value on printed bill

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

@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 (https://github.com/MegaTherion/CodigoControlV7-php ) , compiled the php code to an exe using phc-win ( 1.0.2 with supports php5 https://github.com/RDashINC/phc-win/releases ), packed everything including dll with ‘bat to exe converter’ (http://www.f2ko.de/programs.php?lang=en&pid=b2e) 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.

3 Likes

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.

4 Likes