Printing the ticket line in 2 rows

For those starting out on Openbravo POS, you may have run into the problem, as i have, where very long product names wouldn’t fit onto a single row in a ticket receipt. For me, the solution was to force the printing to be on two rows.

Here’s the code to get the ticket line printed in two rows – specifically, the product name on row one and spilling over to the second row where necessary, and the unit price, units and value on the second row. Since the template is based on Velocity, Java String methods such as substring and lastIndexOf comes in handy for splitting the product name nicely.

#foreach ($ticketline in $ticket.getLines())
#if ($ticketline.printName().length() >= 32)
    <line>
        #if ($ticketline.isProductCom())
            <text align =”left” length=”32″>*${ticketline.printName().substring(0, ${ticketline.printName().lastIndexOf(‘ ‘, 32)})}</text>
        #else
            <text align =”left” length=”32″>${ticketline.printName().substring(0, ${ticketline.printName().lastIndexOf(‘ ‘, 32)})}</text>
        #end
    </line>
    <line>
        #if ($ticketline.isProductCom())
            <text align =”left” length=”17″>*${ticketline.printName().substring(${ticketline.printName().lastIndexOf(‘ ‘, 32)})}</text>
        #else
            <text align =”left” length=”17″>${ticketline.printName().substring(${ticketline.printName().lastIndexOf(‘ ‘, 32)})}</text>
        #end
        <text align =”right” length=”10″>${ticketline.printPrice()}</text>
        <text align =”right” length=”5″>x${ticketline.printMultiply()}</text>
        <text align =”right” length=”10″>${ticketline.printSubValue()}</text>
    </line>
#else
    <line>
        #if ($ticketline.isProductCom())
            <text align =”left” length=”42″>*${ticketline.printName()}</text>
        #else
            <text align =”left” length=”42″>${ticketline.printName()}</text>
        #end
    </line>
    <line>
        <text align =”right” length=”27″>${ticketline.printPrice()}</text>
        <text align =”right” length=”5″>x${ticketline.printMultiply()}</text>
        <text align =”right” length=”10″>${ticketline.printSubValue()}</text>
    </line>
#end

(Visited 276 times, 1 visits today)

Posted

in

by

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *