SambaPOS has a Printer Tag for spelling out the Ticket Total as such:
{TOTALTEXT}
or
{TOTAL TEXT}
The above produces this:
So {TOTALTEXT}
isn’t quite correct with the text all squeezed together. And neither of the above Tags are any good unless you require English and your currency is Dollars.
Add to that, if you want to output text for other numbers other than the Ticket Total, we have no method to do so.
I needed the same thing, but my requirement was for Spanish number-to-text. Using JScript in V5 we can implement this functionality for other languages, and we can apply it to any number we want, not just the Ticket Total.
I found this script (sorry to the author, it was a while ago and don’t remember where it came from), and it seems to work well for Spanish numbers …
##NumFunctions
[num]
(Script)##
Script Name: | NumFunctions |
Script Handler: | num |
Script:
var unidades = ["", "un", "dos", "tres", "cuatro", "cinco", "seis", "siete", "ocho", "nueve", "diez", "once", "doce", "trece", "catorce", "quince", "dieciséis", "diecisiete", "dieciocho", "diecinueve", "veinte", "veintiún", "veintidós", "veintitrés", "veinticuatro", "veinticinco", "veintiséis", "veintisiete", "veintiocho", "veintinueve"];
var decenas = ["", "", "", "treinta y ", "cuarenta y ", "cincuenta y ", "sesenta y ", "setenta y ", "ochenta y ", "noventa y "];
var centenas = ["", "ciento ", "doscient@s ", "trescient@s ", "cuatrocient@s ", "quinient@s ", "seiscient@s ", "setecient@s ", "ochocient@s ", "novecient@s "]
var ordenes = ["", " mil", " millones", " mil", " billones", " mil", " trillones", " mil", " cuatrillones", " mil"];
var gen = "num";
var digits = "0";
function numToSpanish(numToConvert) {
var numeral = "";
var numParts = chop(new String(numToConvert));
for (i = 0; i < numParts.length; i++)
numerator(numParts, i);
numeral += numParts.reverse().join(" ");
if (numeral.length == 0)
numeral = "cero";
if (/((llón)|(llones))\s*$/.test(numeral) && gen != "num")
numeral += " de";
if (gen == "fem")
numeral += (digits == "1 " ? " libra" : " libras");
else if (gen == "mas")
numeral += (digits == "1 " ? " dólar" : " dólares");
if (gen != "num")
digits += (gen == "fem" ? "£" : "$");
//return digits + "<br><br>" + numeral;
numeral = numeral.toUpperCase();
return numeral;
}
function numerator(numParts, pos) {
var centena, decena, unidad, numeral;
centena = numParts[pos].charAt(0);
decena = numParts[pos].charAt(1);
unidad = numParts[pos].charAt(2);
if (parseInt(decena, 10) < 3)
numeral = new String(centenas[centena] + unidades[parseInt(decena + unidad, 10)]);
else
numeral = new String(centenas[centena] + decenas[decena] + unidades[unidad]);
switch (centena + decena + unidad) {
case "000":
if (ordenes[pos] != " mil" && numParts[pos + 1] != "000")
numeral += ordenes[pos];
break;
case "001":
numeral += ordenes[pos];
numeral = numeral.replace(/^un\smil$/, "mil");
if (pos == numParts.length - 1 || (pos < numParts.length - 1 && numParts[pos + 1] == "000"))
numeral = numeral.replace(/llones$/, "llón");
if (pos == 0 && gen != "mas")
numeral = (gen == "fem" ? "una" : "uno");
break;
case "100":
numeral = "cien " + ordenes[pos];
break;
default:
numeral = numeral.replace(/@/g, ((gen == "fem" && pos < 2) ? "a" : "o"));
numeral = numeral.replace(/\sy\s$/, "");
numeral += ordenes[pos];
}
if (pos == 0 && gen != "mas") {
numeral = numeral.replace(/veintiún$/, (gen == "fem" ? "veintiuna" : "veintiuno"));
numeral = numeral.replace(/un$/, (gen == "fem" ? "una" : "uno"));
} else if (pos == 1 && gen == "fem") {
numeral = numeral.replace(/veintiún/, "veintiuna");
numeral = numeral.replace(/un\smil/, "una mil");
}
numParts[pos] = numeral;
}
function chop(numString) {
var numParts = new Array();
var numPart = 0;
var numDigits = 0;
numString = numString.replace(/\D*/g, "").replace(/^0*/, "");
if (numString == "")
numString = "0";
digits = "";
for (var i = numString.length; i > 0; i -= 3) {
numPart = numParts.push(numString.substring(i - 3, i));
digits = numParts[numPart - 1] + " " + digits;
}
numDigits = numParts[numPart - 1].length;
if (numDigits < 3)
numParts[numPart - 1] = (numDigits == 2 ? "0" : "00") + numParts[numPart - 1];
return numParts;
}
In the Printer Template we can now do a {CALL:X}
to the script as follows:
{CALL:num.numToSpanish('{TICKET TOTAL}')}
I don’t need the decimal portion, so I actually call it like this, which trims the decimal point and last 2 digits (which are always 0
on my setup) …
{CALL:num.numToSpanish('{TICKET TOTAL}'.slice(0,-3))}
This is what I end up with on my printed Ticket: