@emre, did you miss this post by @devloic? Or are you referring to something else?
@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.
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 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.
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. 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â)}