View source | Discuss this page | Page history | Printable version   
Toolbox
Main Page
Upload file
What links here
Recent changes
Help

PDF Books
Add page
Show collection (0 pages)
Collections help

Search

POS - Number To Words In Ticket

Code snippet

Name: POS - Number to words in Ticket
Version: POS 2.30
Author: Macumbero and Zil__



The following was translated from Spanish to English from here by ronny_g.

The following script allows using two attributes to get the amount of products with lyrics by the final total and include it in any part of ticket.


1. Create a new resource of type text named "Amount.Letter" and add the following code.

 
private static String[] _groups = 
   { "", "millon","billon","trillon"};
 
private static String[] _units = 
   {"", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"};
 
private static String[] _ten1 = 
 {"", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen"};
 
private static String[] _tens = 
 {"", "ten", "twenty", "thirty", "forty", "fifty", "sixty", "seventy", "eighty", "ninety"};
 
private static String[] _hundreds = 
 {"", "one hundred", "two hundred", "three hundred", "four hundred", "five hundred", "six hundred", "seven hundred"
, "eight hundred", "nine hundred"};
 
public static String thousandText( int n ) {
   if (n == 0)
      return "";
 
   int hundreds = n / 100;
   n = n % 100;
   int tens = n / 10;
   int units = n % 10;
    
   String suffix = "";
    
   if ( tens == 0 && units != 0 ) 
      suffix = _units[units];
    
   if ( tens == 1 && units != 0 )
      suffix = _ten1[units];
    
   if ( tens == 2 && units != 0 )
      suffix = "twenty"+_units[units];
    
   if ( units == 0) 
      suffix = _tens[tens];
    
   if ( tens > 2 && units != 0)
      suffix = _tens[tens] + " y " + _units[units];
    
   if (hundreds != 1)
      return _hundreds[hundreds] + " " + suffix;
    
   if ( units == 0 && tens == 0)
      return "hundred";
    
   return "hundred "+suffix; 
}
 
public static String aSpanishNumber( long n  ){
   String result = "";
   int group = 0;
   while ( n != 0 && group < _groups.length ) {
      long fragment = n % 1000000;
      int millarAlto = (int) (fragment / 1000);
      int underathousand = (int) (fragment % 1000);
      n = n / 1000000;
      
      String groupname = _groups[group];
      if (fragment > 1 && group > 0)
         groupname += "es";
      
      if ((millarAlto != 0) || (underathousand != 0)) {
         if (millarAlto > 1)
            result = thousandText(millarAlto) + " thousand " + 
                        thousandText(underathousand) + " " +
                        groupname + " " +
                        result;
 
         if (millarAlto == 0) 
            result = thousandText(underathousand) + " " +
                        groupname + " "+
                        result;
                      
         if (millarAlto == 1)
            result = "thousand " + thousandText(underathousand) + " " +
                        groupname + " " +
                        result;
      }
      group++;
   }
   return result;
}
 
number = ticket.getTotal(); 
number = Math.round(number*Math.pow(10,2))/Math.pow(10,2);
number_whole=(int)number;
number_decimal=(int)((number*100)-(number_whole*100));
line = ticket.getLine(0);  
if (number_decimal==0){
   value = "(".concat(aSpanishNumber(number_whole)).concat("00/100 M.N.)");
}
else{
   value = "(".concat(aSpanishNumber(number_whole)).concat(Integer.toString(number_decimal)).concat("/100 M.N.)");
}
 
if (value.length()>36){
   line.setProperty("amount", "(".concat(aSpanishNumber(number_whole)));
   if (number_decimal==0){
      line.setProperty("amount2","00/100 M.N.)");
   }
   else{
      line.setProperty("amount2", Integer.toString(number_decimal).concat("/100 M.N.)"));
   }
}
else{          
   line.setProperty("amount", value);
   line.setProperty("amount2", "");
}

2. Edit the resource "Ticket.Buttons" by adding the following line (event) after the label "<configuration>" :

<event key="ticket.close" code="Amount.Letter"/>

3. Edit the resource "Printer.Ticket" by adding the following lines where you need to print the amount in block letters:

<line>
   <text align="left" length="36">${ticket.getLine(0).getProperty("amount")}</text>
</line>
<line>
   <text align="left" length="36">${ticket.getLine(0).getProperty("amount2")}</text>
</line>

4. Exit and restart the application.


Note:

The length of text in the script is limited to 36 characters, if the quantity exceeds this point the truncated length is 2 lines.

This can be changed at the end of the script on the next line

if (value.length()>36)

36 change the number of characters needed.

Retrieved from "http://wiki.openbravo.com/wiki/POS_-_Number_To_Words_In_Ticket"

This page has been accessed 6,066 times. This page was last modified on 20 April 2010, at 02:30. Content is available under Creative Commons Attribution-ShareAlike 2.5 Spain License.