How to make the long orders name in 2 paragraph?

Currently my Ticket Printer Template resulting the following result :

[code]

░░░░░░░░░░░░░░░ T i c k e t ░░░░░░░░░░░░░░
Date: 14/12/2015
Time: 11:29
Server: Administrator
Table: B10
Ticket No:2

  • 1 Blueberry Cheese Cake.Slice Rp 18.000,00
    ==========================================
    Total: Rp 18.000,00
    ==========================================
    GC201512141121841200000 Balance: Rp 182.000,00
    GC201512141121841200000 18.000,00
    ==========================================
    Thank You
    Password WIFI : Testing[/code]

As you can see on the orders list it become out of print area, thus on the printed result word “- 1 Blueberry Cheese Cake.Slice Rp 18.000,00” being cutted as “- 1 Blueberry Chee Rp 18.000,00”, how to make the {orders} into 2 paragraph automatically ?. So the end result would be like these :

[code]

░░░░░░░░░░░░░░░ T i c k e t ░░░░░░░░░░░░░░
Date: 14/12/2015
Time: 11:29
Server: Administrator
Table: B10
Ticket No:2

  • 1 Blueberry
    Cheese Cake.Slice Rp 18.000,00
    ==========================================
    Total: Rp 18.000,00
    ==========================================
    GC201512141121841200000 Balance: Rp 182.000,00
    GC201512141121841200000 18.000,00
    ==========================================
    Thank You
    Password WIFI : Testing[/code]

My current Ticket Printer Template :

[LAYOUT]
-- General layout
<ec>
<BMP>C:\Users\Este\Documents\SambaPOS5\Logo.bmp
<el>
<J00>
<T>Ticket
<L00>Date: {TICKET DATE}
<L00>Time: {TIME}
<L00>Server: {USER NAME}
{ENTITIES}
<L00>Ticket No:{TICKET NO}
<F>-
{ORDERS}
<F>=
<EB>
{DISCOUNTS}
[<J10>Total Gift:| Rp {ORDER STATE TOTAL:Gift}]
{SERVICES}
<J10>Total:| Rp {TICKET TOTAL}
<F>=
<J00>{TICKET TAG:GCN}| Balance: Rp [=F(TN('{TICKET TAG:GCB}'))]
[<J00>Total FREE:| Rp {ORDER STATE TOTAL:Gift}]
[<J00>Discounts:| Rp [=F(TN('{ORDER TAG TOTAL:Discount}')+TN('{ORDER TAG TOTAL:VIP Discount}')+TN('{ORDER TAG TOTAL:HH Discount}'))]]
[<J00>TOTAL SAVINGS:| Rp [=F(-1*(TN('{ORDER TAG TOTAL:Discount}')+TN('{ORDER TAG TOTAL:VIP Discount}')+TN('{ORDER TAG TOTAL:HH Discount}'))+TN('{ORDER STATE TOTAL:Gift}'))]]
{PAYMENTS}
<DB>
<F>=
<C10>THANK YOU
<C00>Password WIFI : Testing

[DISCOUNTS]
<J00>{CALCULATION NAME} %{CALCULATION AMOUNT}|{CALCULATION TOTAL}

[SERVICES]
<J00>{CALCULATION NAME}|{CALCULATION TOTAL}

[PAYMENTS]
<J00>{PAYMENT NAME}|{PAYMENT AMOUNT}

[ORDERS]
-- Default format for orders
<J00>- {QUANTITY} {NAME}|Rp {TOTAL PRICE}
{ORDER TAGS}

[ORDERS:Gift]
-- Format for gifted orders
<J00>- {QUANTITY} {NAME}|**GIFT**
{ORDER TAGS}

[ORDERS:Void]
-- Nothing will print for void lines

[ORDER TAGS]
-- Format for order tags
<J00> * {ORDER TAG NAME} | {ORDER TAG PRICE}

[ENTITIES:Table]
-- Table entity format
<L00>Table: {ENTITY NAME}

[ENTITIES:Customer]
-- Customer entity format
<J00>Customer: {ENTITY NAME} | Phone : {ENTITY DATA:Phone}

I do not think that is possible with a simple Ticket printer. You might be able to do something with HTML printer or Document printer.

Now that I’ve said that, you might be able to work magic with {CALL:X} and some fancy JS :wink:

Damn :smile: so there is no built-in function, you cannot give me the script aren’t you?.
Pseudo code that i am thinking in my mind :

Store the full word in a global variable
create temp1,temp 2 global variable
Cut the words based on number of word
assign the cutted word into temp variable

Create a function to return temp1 string
Create a function to return temp2 string

Now the question is can you guide me on creating the script and implemented it in the report?

Current code :

function cut(fullWord,maxLength,operation)
{
   var fullLength = fullWord.length
   if (typeof(maxLength) == "undefined") { var maxLength = '30'; }
   if (maxLength == "0") { var maxLength = '30'; }
   var trimmedString1 = fullWord.substr(0, maxLength)
   trimmedString1 = trimmedString1.substr(0, Math.min(trimmedString1.length, trimmedString1.lastIndexOf(" ")));
   var trimmedString2 = fullWord.substr(Math.min(trimmedString1.length, trimmedString1.lastIndexOf(" ")), fullLength)
   trimmedString2 = trimmedString2.substr(trimmedString1.length-trimmedString1.lastIndexOf(" "), trimmedString2.length);
   if (operation == "1") { return trimmedString1; } 
   if (operation == "2") { return trimmedString2; } 
}

I am calling it like these on Ticket Printer Template :

[ORDERS]
-- Default format for orders
{CALL:tools.cut({QUANTITY}+{NAME},'42','1')}
{CALL:tools.cut({QUANTITY}+{NAME},'42','2')}| Rp {TOTAL PRICE}
{ORDER TAGS}

But no value returned and printed.

Put an Alert or 2 in your function, and use the Script Test facility to debug your code.

var fullLength = fullWord.Length // need capital L in Length
alert(fullLength);

On the Script page, use the Test button in the bottom-right, with something like:

cut('my long word stuff',10,1)

Yes passing normal variable works fine but how about automatically concatenated and passing “{QUANTITY}+{NAME}” into the function on the Ticket Template ?

Tried :

[ORDERS] -- Default format for orders {CALL:tools.cut({QUANTITY}+{NAME},'42','1')} {CALL:tools.cut({QUANTITY}+{NAME},'42','2')}| Rp {TOTAL PRICE} {ORDER TAGS}
or

[ORDERS] -- Default format for orders {CALL:tools.cut(QUANTITY+NAME,'42','1')} {CALL:tools.cut(QUANTITY+NAME,'42','2')}| Rp {TOTAL PRICE} {ORDER TAGS}
or

[ORDERS] -- Default format for orders {CALL:tools.cut($QUANTITY+$NAME,'42','1')} {CALL:tools.cut($QUANTITY+$NAME,'42','2')}| Rp {TOTAL PRICE} {ORDER TAGS}

But none of them works.

I want to achieve something like these :

------------------------------------------
- 1 Blueberry 
Cheese Cake.Slice             Rp 18.000,00
==========================================

Close… you need to figure the correct syntax - here is a hint, I use the following:

<L00>{CALL:str.pad('{QUANTITY}','right',2," ")} {CALL:str.pad('{NAME}','right',27," ")} {CALL:str.pad('{PRICE}','left',7," ")} {CALL:str.pad('{TOTAL PRICE}','left',9," ")}

Don’t forget the formatting tag, like <L00> or <J00>

1 Like

@QMcKay
Thanks you many times, managed to get it working!.
So to iterate the solution is add this to automation scripts :

Name : str Handle : str

function pad(input, pad_type, pad_length, pad_string ) {
  //  discuss at: http://phpjs.org/functions/str_pad/
  // original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
  // improved by: Michael White (http://getsprink.com)
  //    input by: Marco van Oort
  // bugfixed by: Brett Zamir (http://brett-zamir.me)
  //   example 1: str_pad('Kevin van Zonneveld', 30, '-=', 'left');
  //   returns 1: '-=-=-=-=-=-Kevin van Zonneveld'
  //   example 2: str_pad('Kevin van Zonneveld', 30, '-', 'both');
  //   returns 2: '------Kevin van Zonneveld-----'

  var half = '',
    pad_to_go;

  var str_pad_repeater = function(s, len) {
    var collect = '',
      i;

    while (collect.length < len) {
      collect += s;
    }
    collect = collect.substr(0, len);

    return collect;
  };

  input += '';
  pad_string = pad_string !== undefined ? pad_string : ' ';

  if (pad_type !== 'left' && pad_type !== 'right' && pad_type !== 'both') {
    pad_type = 'right';
  }
  if ((pad_to_go = pad_length - input.length) > 0) {
    if (pad_type === 'left') {
      input = str_pad_repeater(pad_string, pad_to_go) + input;
    } else if (pad_type === 'right') {
      input = input + str_pad_repeater(pad_string, pad_to_go);
    } else if (pad_type === 'both') {
      half = str_pad_repeater(pad_string, Math.ceil(pad_to_go / 2));
      input = half + input + half;
      input = input.substr(0, pad_length);
    }
  }

  return input;
}

function cut(fullWord,maxLength,operation)
{
   var fullLength = fullWord.Length
   if (typeof(maxLength) == "undefined") { var maxLength = '30'; }
   if (maxLength == "0") { var maxLength = '30'; }
   var trimmedString1 = fullWord.substr(0, maxLength)
   trimmedString1 = trimmedString1.substr(0, Math.min(trimmedString1.length, trimmedString1.lastIndexOf(" ")));
   var trimmedString2 = fullWord.substr(Math.min(trimmedString1.length, trimmedString1.lastIndexOf(" ")), fullLength)
   trimmedString2 = trimmedString2.substr(trimmedString1.length-trimmedString1.lastIndexOf(" "), trimmedString2.length);
   if (operation == "1") { return trimmedString1; } 
   if (operation == "2") { return trimmedString2; } 
}

For those with quite lengthy orders name can implemented solution from QMcKay in Ticket Print Template:

[ORDERS] -- Default format for orders <L00>- {CALL:str.pad('{QUANTITY}','right',2," ")} {CALL:str.pad('{NAME}','right',27," ")} $ {CALL:str.pad('{TOTAL PRICE}','left',9," ")} {ORDER TAGS}

and
ORDERS:GIFT

[ORDERS:Gift]
-- Format for gifted orders
<L00>- {CALL:str.pad('{QUANTITY}','right',2," ")} {CALL:str.pad('{NAME}','right',27," ")} **GIFT**
{ORDER TAGS}

And for those with really lengthy and wanted to make it into 2 paragraph :
[ORDERS] :

[ORDERS]
-- Default format for orders
<L00>- {CALL:str.pad('{QUANTITY}','right',2," ")} {CALL:str.cut('{NAME}','30','1')}
<J00> {CALL:str.cut('{NAME}','30','2')} | $ {CALL:str.pad('{TOTAL PRICE}','left',10," ")}
{ORDER TAGS}

ORDERS:GIFT

[ORDERS:Gift]
-- Format for gifted orders
<L00>- {CALL:str.pad('{QUANTITY}','right',2," ")} {CALL:str.cut('{NAME}','30','1')}
<J00> {CALL:str.cut('{NAME}','30','2')} | **GIFT**
{ORDER TAGS}

Example result :

                                          
░░░░░░░░░░░░░░░ T i c k e t ░░░░░░░░░░░░░░
Date: 15/12/2015
Time: 2:43
Server: Administrator
Table: B10
Ticket No:4
------------------------------------------
- 1  Blueberry Cheese
  Cake.Loyang                 $ 180.000,00
- 1  Blueberry Cheese
  Cake.Slice                      **GIFT**
- 1  Brownies Cheese
  Cake.Slice                   $ 18.000,00
- 1  Chocolate Cheese
  Cake.Slice                   $ 18.000,00
- 1  Brownies Cheese
  Cake.Loyang                     **GIFT**
==========================================
Total Gift:                   $ 198.000,00
Total:                        $ 216.000,00
==========================================
                           Balance: $ 0,00
Total FREE:                   $ 198.000,00
TOTAL SAVINGS:                $ 198.000,00
Cash                            216.000,00
==========================================
               Thank You
3 Likes

Nice! Looks good! I think people will use this… others have asked for a wrapping function previously, and this does a nice job.

2 Likes

Thank you again for guiding me thorough the thread :smile:, otherwise it won’t be possible. Hopefully it will be useful for someone and also for my own archive.

2 Likes

I love seeing other people using the advanced features of v5. Amazing things are possible.

1 Like

The linebreak has yet to come up with any of my customers but Like the padding of the quantity to align :slight_smile: bookmarked lol

Here is my str.pad() function that I use…

function pad(s,d,l,c) {

  // s : input string
  // d : direction - left or right pad
  // l : length of output string
  // c : pad character (0," ")
  
  // ensure the input is a string, not a number
  s = ''+s+'';
  
  var outstring = "";
  var padding = "";
  
  // build string padding
  padding=Array(l+1).join(c);
  
  // pad the input right or left
  if (d=='right') {
    outstring = (s+padding).substring(0,padding.length);
  } else {
    outstring = (padding+s).slice(0-padding.length);
  }
  return outstring;
}

Sample call…

{CALL:str.pad('{QUANTITY}','right',2," ")}
1 Like