Custom value on printed bill

@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

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);
}

2 Likes

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

http://forum.sambapos.com/t/tutorial-how-to-make-a-dynamic-weather-tile-using-weather-underground-api/4420

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 array.map(). 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 “array.map”, 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 http://jsfiddle.net/ 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.

3 Likes

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.

2 Likes

Here is the javascript code for generating the checksum. codigo_control.zip (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’)}

3 Likes