Print 'Thought for the Day' on ticket

Hello Friends,

I wanted to print a ‘Thought for the Day’ at the end of the ticket.

I could create an entity, populate it, and select one ‘Thought for the Day’ before printing the ticket.

But, that would be cumbersome.

How do I automatically attach a random entity instance to a ticket?

I even thought of creating a separate Database Table in SQL, with the ‘Thought for the Day’s, but, how do I pull one row in random from that new database table into the Ticket Template?

Does anyone know an easier way I could go about this?

Thanks & Regards…

I have got an idea!

I think I can use the new REPORT ENTITY DETAIL with a {RANDOM} fetch

I will try and let you guys know if I succeed.

Meanwhile, I would appreciate comments from the more experienced members of this community.

Regards

1 Like

Are you happy creating an array in javascript? If so, you can use automation > scripts to create your array of thoughts and then return one at random from the array using a {CALL:handler.funtionName()} tag in your ticket. If you are doing a truly random generator in the script then keep in mind the output will be different on any ticket reprints.

Thanks for the response, I was thinking of using Entities, so that the data is easier to manage for me.

I have figured out a way wherein I will create a new Entity ‘Thoughts’ with the fields Name, RowNo, TotalCount

The RowNo will be contain sequential numbers, and the TotalCount will contain total rows.

Then, I can execute a REPORT ENTITY DETAIL inside the Ticket Template with a {RANDOM} row fetch.

I am still working on the exact code to do this…

Regards,

Script would be my recommendation.
And array would be easily managed…

This is how I did it:

I created a new EntityType called FamousQuotes with only a default field called Name
I populated this Entity Types with data

Then I created a Script as below:

function getRandomQuote() {
qry = “SELECT TOP (1) [Name] FROM [dbo].[Entities] WHERE ([EntityTypeId] = 49) order by newid()”;
var fQ = sql.Query(qry).All;
return fQ[0];
}

And I call this script from the Ticket Template.

It is working beautifully.

And much easier to add and delete the data, as it can be done without getting into the script, and by using the Entities Screen.

Now, I need to figure out, how to word wrap the Thought for the Day, as the text is rather long.

Ive changed the forum category to V5 Question, as your not asking for a new feature in Samba.

Also have you searched for word wrap yet. Doing a quick search reveals a lot of results

1 Like

Yes, found a decent piece of code for word wrapping online, I added the tag to the code for it to work inside SambaPOS

 function wordwrap(long_string, max_char){

  var sum_length_of_words = function(word_array){
    var out = 0;
    if (word_array.length!=0){
      for (var i=0; i<word_array.length; i++){
        var word = word_array[i];
        out = out + word.length;
      }
    };
    return out;
  }

  var split_out = [[]];
  var split_string = long_string.split(' ');
  for (var i=0; i<split_string.length; i++){
    var word = split_string[i];
    
    if ((sum_length_of_words(split_out[split_out.length-1]) + word.length) > max_char){
      split_out = split_out.concat([[]]);
    }
    
    split_out[split_out.length-1] = split_out[split_out.length-1].concat(word);
  }
  
  for (var i=0; i<split_out.length; i++){
    split_out[i] = split_out[i].join(" ");
  }
  
  return split_out.join('\n<L00>');
};

The new <Wxy:cw1,cw2,cw3,...> Tag has the ability to do wrapping in your Template based on comma-placement. That way, you don’t need to do all that Scripting.

  • The numbers indicate a character-count/width for the column.
  • Using * in a column will expand that column automatically to use remaining characters, based on Printer character count configuration
  • Use whitespace after a number to enable wrapping.
<W00:4,4 , 17 , 10>content1|content2|content3|content4
     - -- ---- ---
     | |   ||  |||
   left|   || right
       | center
       |
    left with line break (wrap)

The whitespace after number enables left align with word wrapping. If there is no whitespace it is left align with trimming.

3 Likes

SERIOUSLY! - Wow, this is amazing, I had no idea that W tag could do this. Awesome! :open_mouth: