Stripping Work Order Notes From Sales Receipt Using the Print Template

I'm trying to remove the Work Order notes from the Sales receipt. I want like the receipt to show the Work Order number only by stripping off everything after the comma on the Work Order line. This is the line of code I'm trying. I think (hope) it may be a simple syntax error. Any suggestions?
{{ Line.Note.note|noteformat|raw"|split (',') }}
<1

32 comments

  • Adrian SamuelAdrian Samuel Posts: 521Moderator, Lightspeed Staff moderator
    Hey @laurie, and for whoever else might be interested in this question...the easiest way to remove the internal notes of a Work Order on the sale is using javascript since we are able to use regular expressions.

    Templates vary per country so where we insert the code will differ.

    However, in the Retail template, you will find the following HTML

    <h1 class="receiptTypeTitle">

    Immediately after the above, write the code in the screenshot below (make sure to write this in a text editor)



    To explain the code briefly

    We are using an event listener that only executes the code inside of it once all the content on the page is loaded.

    We are then selecting all the notes on the sale (since work order details appear with a .line_note class on the sale)

    We are going to cycle through each of those "notes" and then get the words inside it and check if it contains the word "Work order". This ensures we are not running this code against notes that are not work orders (such as labour and miscellaneous charges).

    Then we use a regular expression match the characters of the text, and we replace it with the characters up to the words am or pm.

    We re-insert that replacement into the HTML containing the work order to overwrite it.

    We then target the line breaks in the HTML for those work order lines and remove it dynamically.

    I hope this helps!

    Adrian Samuel

    API Integrations Consultant - Strategic Solutions

    Lightspeed HQ

  • laurielaurie Posts: 7Member
    @Adrian Samuel, Thank you so much! I added the code then printed a basic sale Sales Receipt first to be sure that still worked and got this:


     
    Here is an expanded section of the code in my Sales Receipt Template:

    -----------snip-------------------------
    {% macro title(Sale,parameters,options) %}
    <h1 class="receiptTypeTitle">
    {# Begin LB Edit for removing notes from Work Orders #}

    document.addEventListener("DOMContentLoaded", function(event) {
        let div = document.querySelectorAll('.line_note');
        div.forEach(function(div) {
           let content = div.innerHTML;
            let search = content.includes("Work order");
        if (search === true) {
            new_str = content.replace(/([\s\S]+?\b[ap]m\b)[\s\S]+/ig, "$1");
         div.innerHTML = new_str;
         let targetBreak = document.querySelector('.line_note br');
         targetBreak.style.cssText="display: none";
    }
    });
    });

    {# End LB Edit for removing notes from Work Orders #}

    {% if Sale.calcTotal >= 0 %}
    {% if Sale.completed == 'true' %}
    {% if options.invoice_as_title and options.print_layout %}
    <span class="hide-on-print">
    {% endif %}
    {% if options.workorders_as_title and Sale.SaleLines is empty and Sale.Customer.Workorders is defined %}
    Work Orders
    {% else %}
    {% if parameters.gift_receipt %}Gift{% else %}Sales{% endif %} Receipt
    {% endif %}
    {% if options.invoice_as_title and options.print_layout %}
    </span>
    <span class="show-on-print">
    {% if options.workorders_as_title and Sale.SaleLines is empty and Sale.Customer.Workorders is defined %}
    Work Orders
    {% else %}
    Invoice
    {% endif %}
    </span>
    {% endif %}
    {% elseif Sale.voided == 'true' %}
    {% if options.invoice_as_title and options.print_layout %}
    <span class="hide-on-print">
    {% endif %}
    Receipt <large>VOIDED</large>
    {% if options.invoice_as_title and options.print_layout %}
    </span>
    <span class="show-on-print">Invoice VOIDED</span>
    {% endif %}
    {% else %}
    {% if options.quote_to_invoice %}
    Invoice
    {% else %}
    Quote
    {% endif %}
    {% if not Sale.quoteID %}
    <large>(NOT A RECEIPT)</large>
    {% endif %}
    {% endif %}
    {% else %}
    {% if options.invoice_as_title and options.print_layout %}
    <span class="hide-on-print">
    {% endif %}
    Refund Receipt
    {% if options.invoice_as_title and options.print_layout %}
    </span>
    <span class="show-on-print">Refund Invoice</span>
    {% endif %}
    {% endif %}
    </h1>
    {% endmacro %}
    -------------end snip--------------------------------

    Any suggestions?

    I appreciate your help!!
    Laurie
  • Adrian SamuelAdrian Samuel Posts: 521Moderator, Lightspeed Staff moderator
    @laurie You need to put the javascript code between a script tag :)

    so:

    <script>

    //insert code

    </script>

    Adrian Samuel

    API Integrations Consultant - Strategic Solutions

    Lightspeed HQ

  • laurielaurie Posts: 7Member
    I figured I was missing something. :)

    That fixed the html code on receipt issue but I'm still getting Work Order notes on the final Sales Receipt for completed Work Orders. The Work Order notes come across as an item. What else did I do wrong? :)

    I need the Work Order number to show on the Sales Receipt, just not the notes.

    (I really appreciate you helping me. I can't use the service module until the notes are gone.)


  • Adrian SamuelAdrian Samuel Posts: 521Moderator, Lightspeed Staff moderator
    edited July 2018
    @laurie thank you for your time and patience with me in this! Essentially the code I wrote was built to match, a different pattern. I've added the amended code (shown below) in your template and you should find it works as desired!

    new_str = content.replace(/([\s\S]+#\d{0,})[\s\S]+/ig, "$1");

    A new screenshot can be seen below:





    Post edited by Adrian Samuel on

    Adrian Samuel

    API Integrations Consultant - Strategic Solutions

    Lightspeed HQ

  • laurielaurie Posts: 7Member
    That worked! Thank you so much @Adrian Samuel . This was a tremendous help. I'm excited to start putting our work orders in LS. And thank you for explaining the code too.
  • aroundthecyclearoundthecycle Posts: 5Member
    I tried this and it works, but my current receipt simply prints out the work order number with no reference to the item itself. I'd like it to still display the Item details like description, color, size, serial, just not the actual notes field. Is there a modification in the code that can make that happen?
    Thanks for the help!

  • Adrian SamuelAdrian Samuel Posts: 521Moderator, Lightspeed Staff moderator
    @aroundthecycle so I can understand your request better could you send me a screenshot of a receipt you've printed with a circle around the information you want to retain and a cross on the information you want lose

    Adrian Samuel

    API Integrations Consultant - Strategic Solutions

    Lightspeed HQ

  • rishirishi Posts: 15Member
    edited October 2018
    Hi Adrian. This is awesome and exactly what I need. thanks! @Adrian Samuel
    Post edited by rishi on
  • rishirishi Posts: 15Member
    So while this work perfectly for printing out receipts, if it is emailed, then the customer will see all the things that were stripped after "Work order #X" including the Ready on line followed by the order notes. How can we remove this from being emailed also?
  • Adrian SamuelAdrian Samuel Posts: 521Moderator, Lightspeed Staff moderator
    @rishi it's because mail servers strip out any javascript from emails when they're sent. It's not possible to write code to handle this.

    I would suggest you make a customer feature request to better handle the messaging from the private note section from here: https://my.lightspeedpos.com/CustomerPortal_Ideas

    Adrian Samuel

    API Integrations Consultant - Strategic Solutions

    Lightspeed HQ

  • rishirishi Posts: 15Member
    @Adrian Samuel thanks for the response! On a side note, do you know how I can show the broken down line subtotal information for the workorders section on the sales receipt (i.e. 2 x $39.99/ea). I have it working on the sales receipt for items normally purchased. Also the tax is not broken out (i.e. HST 13%) it just says total tax for the workorder section. 
  • Adrian SamuelAdrian Samuel Posts: 521Moderator, Lightspeed Staff moderator
    edited October 2018
    No worries @rishi! Could you show me how the present Workorder template for you looks? My account shows the same format.

    As to the Tax, the Workorder template API doesn't have a Tax value associated with the whole order like the Sale Template API has, so if by chance you have items that are taxed differently, it wouldn't capture it unless you wrote something programmatically. Is this the case with you, or do you always have the flat rate of 13% for all your items?

    Adrian Samuel

    API Integrations Consultant - Strategic Solutions

    Lightspeed HQ

  • Scott MerrittScott Merritt Posts: 1Member
    I am trying to do the same thing. I want to remove printed notes from invoice that customer sees. I noticed that there is HTML codes however i am a little lost on where to find this and where to enter this code.  Please inform
  • Adrian SamuelAdrian Samuel Posts: 521Moderator, Lightspeed Staff moderator
    @Scott Merritt do a control/command find on your computer whilst you're on the page and look for the following HTML

    <h1 class="receiptTypeTitle">
    //Paste the code as instructed above within this
    <script>
    
    </script>

    Adrian Samuel

    API Integrations Consultant - Strategic Solutions

    Lightspeed HQ

  • rishirishi Posts: 15Member
    @Adrian Samuel sorry for my late response back to you regarding the broken down line subtotal information for the Work Orders section on the Sale Receipt (i.e. 2 x $39.99/ea). It's working on the Sales Receipt for items purchased via a regular sale, but for Work Orders this information is not there so customers cannot see the quantity of items they purchased on the Work Order. 

    Regarding the tax, that is also not broken out (i.e. HST 13%) in the Work Order section of the Sales Receipt. It just says Total Tax there. Normally everything is HST 13%, but some customer's may be a special status whereby they are PST exempt so are only charged GST 5%. Either way, it would be good for this tax to be shown versus just Total Tax. Any suggestions?

    Attached is a screenshot of our Sales Receipt. There you can see how the Work Order section is showing up. That line item is actually for two units (each at $1,527.00).


  • Adrian SamuelAdrian Samuel Posts: 521Moderator, Lightspeed Staff moderator
    @rishi I've asked you on a separate thread but do you have any programming experience? I can describe to you what you'd need to do to achieve your desired template

    Adrian Samuel

    API Integrations Consultant - Strategic Solutions

    Lightspeed HQ

  • rishirishi Posts: 15Member
    @Adrian Samuel very limited experience long ago. If you can help me with the code the best you can that'd be wonderful. I'm sure some other people could use this as well.
  • rishirishi Posts: 15Member
    @Adrian Samuel any ideas here? If you can describe to me what needs to be done maybe I can do it. This needs to be fixed ASAP as the Sales Receipts with the open orders doesn't make any sense to our customers - they do not see the quantity and unit price of what they are purchasing, just a net total.
  • Adrian SamuelAdrian Samuel Posts: 521Moderator, Lightspeed Staff moderator
    @rishi Okay, let's try that:

    Essentially, all your objects are available via the workorder template API so you'd need to basically specify the data you want.

     To get taxable amount for a given item on a 1 tax tier it would be 
    {{Workorder.WorkorderItems.WorkorderItem.SaleLine.calcTax1}}
    To get taxable amount for a given item on a 2 tax tier it would be 
    {{Workorder.WorkorderItems.WorkorderItem.SaleLine.calcTax2}}
    You can access the rest of the information including the tax rate applied to line items via the same {{Workorder.WorkorderItems.WorkorderItem.SaleLine}} object

    If you log in and put:

    https://us.lightspeedapp.com/API/Account/{{InsertYourAccountIDHere}}/DisplayTemplate/Workorder/{{InsertWorkorderNumberHere}}.json

    then you'll be able to see a json/xml view of all your data which may enable you to more effectively choose what data is useful for the workorder.

    You can see how the Sales Receipt did the break-down of the receipt on line 910 through to 920

    https://github.com/merchantos/PrintTemplates/blob/master/receipt/SaleReceipt.tpl.

    You want to use the Twig language to assist with this. You can read more about Twig here: https://twig.symfony.com/


    Adrian Samuel

    API Integrations Consultant - Strategic Solutions

    Lightspeed HQ

  • rishirishi Posts: 15Member
    @Adrian Samuel sorry for my late response back to you regarding the broken down line subtotal information for the Work Orders section on the Sale Receipt (i.e. 2 x $39.99/ea). It's working on the Sales Receipt for items purchased via a regular sale, but for Work Orders this information is not there so customers cannot see the quantity of items they purchased on the Work Order. 

    Regarding the tax, that is also not broken out (i.e. HST 13%) in the Work Order section of the Sales Receipt. It just says Total Tax there. Normally everything is HST 13%, but some customer's may be a special status whereby they are PST exempt so are only charged GST 5%. Either way, it would be good for this tax to be shown versus just Total Tax. Any suggestions?

    Attached is a screenshot of our Sales Receipt. There you can see how the Work Order section is showing up. That line item is actually for two units (each at $1,527.00).


  • jonassmetsjonassmets Posts: 16Member
    edited February 15

    Hi there,

    I'm trying todo the same thing but the notes are still showing? Could someone take a look if what I'm doing is correct?


    //maybe not the right place for this comment but a lack of "code insertion" in this forum/community is a bit strange? As a lot is about code it would be nice if there was a way to place code here with the right syntax and highlights? 

  • Adrian SamuelAdrian Samuel Posts: 521Moderator, Lightspeed Staff moderator
    edited February 15

    @jonassmets . There's most likely a bug in your template. I tested my code on a fresh template and it works, but I can't get it to work for the template that you've provided. I'd say just get a fresh template from here and re-do it: https://github.com/merchantos/PrintTemplates/blob/master/receipt/SaleReceipt.tpl


    Also all the new posts enable you to do code insertion, just not on old threads.

    Adrian Samuel

    API Integrations Consultant - Strategic Solutions

    Lightspeed HQ

  • Adrian SamuelAdrian Samuel Posts: 521Moderator, Lightspeed Staff moderator

    @rishi you want to look at getting a template developer doing this for you.

    Here is a link to one of our most recommended: https://www.lightspeedhq.com/ecommerce/customize/customize-advision/

    Adrian Samuel

    API Integrations Consultant - Strategic Solutions

    Lightspeed HQ

  • jonassmetsjonassmets Posts: 16Member

    Hi @Adrian Samuel, thanks for the comment.

    My template is a custom made template so I can not just use the blank one. But they only added code to change the email layout. The standard print code should not be changed. I'll check if I made a mistake in the implementation somehow.

    thanks.

    Jonas

  • Adrian SamuelAdrian Samuel Posts: 521Moderator, Lightspeed Staff moderator

    Hey @jonassmets, that shouldn't make a difference. There's probably an unclosed HTML tag or twig tag that's breaking the template somewhere

    Adrian Samuel

    API Integrations Consultant - Strategic Solutions

    Lightspeed HQ

  • jonassmetsjonassmets Posts: 16Member

    Hi @Adrian Samuel ,


    I got it working! Only thing is that the notes are still on the emailed receipt? Is there something I can do about that? Right now the "hide notes" is triggered by the print action I think?


    Hope you can help me with e fix!

    Kind regards,

    Jonas

  • Adrian SamuelAdrian Samuel Posts: 521Moderator, Lightspeed Staff moderator

    Hey @jonassmets,

    Correct, the notes will be on the emailed receipt because all email clients strip out javascript as a matter of security so this workaround won't work for emails.

    The only way around this is if you create a server-side application that takes the HTML from the Sale from Lightspeed and you strip out the information in the back-end using a server side templating language and then you send the HTML to the customer using the email client.

    Adrian Samuel

    API Integrations Consultant - Strategic Solutions

    Lightspeed HQ

Sign In or Register to comment.