About Total MSRP & Total Amount of save(Custom receipt)

yohanJyohanJ Member Posts: 6
edited July 2018 in Tips, Tricks & How-to’s
Hello
Im struggle with getting total msrp amount .
and Trying to put on right upper of barcode
That You Saved total : (total msrp amount + promotion amount).
Im currently using default template that from official website.
Please help me thank you
Post edited by yohanJ on

13 comments

  • Adrian SamuelAdrian Samuel Moderator, Lightspeed Staff Posts: 569 moderator
    Hey @yohanJ thank you for your question!

    So the Lightspeed community can understand this question a bit better, could you draw a detailed example diagram with annotations and some examples numbers

    This will help us piece what you’re saying together :)

    Adrian Samuel

    API Integrations Consultant - Strategic Solutions

    Lightspeed HQ

  • Adrian SamuelAdrian Samuel Moderator, Lightspeed Staff Posts: 569 moderator
    Also is this for a label or receipt template?

    Adrian Samuel

    API Integrations Consultant - Strategic Solutions

    Lightspeed HQ

  • yohanJyohanJ Member Posts: 6
    Here it is
    thank you so much!

  • Adrian SamuelAdrian Samuel Moderator, Lightspeed Staff Posts: 569 moderator
    @yohanJ

    So as an example 

    Default price is $20
    MSRP is : $45
    Promotion is: $5

    so Total savings 45-20+5 = 30

    Adrian Samuel

    API Integrations Consultant - Strategic Solutions

    Lightspeed HQ

  • yohanJyohanJ Member Posts: 6
    YES!!! but not how the fomular. just sum.
  • Adrian SamuelAdrian Samuel Moderator, Lightspeed Staff Posts: 569 moderator
    edited July 2018
    Excellent, now onto my second question, how do you give promotions in Lightspeed Retail?

    is it purely using the built in discount feature or do you use price rules as well? And are there any other method of discounting/promotions you employ in the system?

    Adrian Samuel

    API Integrations Consultant - Strategic Solutions

    Lightspeed HQ

  • yohanJyohanJ Member Posts: 6
    It was made from setting -> discount -> options
  • Adrian SamuelAdrian Samuel Moderator, Lightspeed Staff Posts: 569 moderator
    edited August 2018
    I wrote a script that would handle your request. It is explained in my code if you go line by line :)


    You can copy the code snippet from here:
    
    document.addEventListener("DOMContentLoaded", function() {
    let str = window.location.href; 
     let new_num = str.replace(/[\s\S]+?([\d]+)\.html[\s\S]+/ig, "$1");  
     let radPatt = /[\s\S]+\bAccount\/\b(\d{1,})[\s\S]+/ig; 
     let RAD = str.replace(radPatt, "$1"); 
     let domain = window.location.host; 
     let thankYou =  document.querySelector('.thankyou'); 
    fetch(`https://${domain}/API/Account/${RAD}/DisplayTemplate/Sale/${new_num}.json`, {
        credentials: "same-origin"}) 
        .then((response) => response.json()) 
        .then((data) => { 
    if (typeof data.Sale.SaleLines.SaleLine.length  == "undefined") {
        let amountPaid = data.Sale.calcTotal;
         let defaultPrice = data.Sale.SaleLines.SaleLine.Item.Prices.ItemPrice[0].amount;  
         let MSRP = data.Sale.SaleLines.SaleLine.Item.Prices.ItemPrice[1].amount;
       if(amountPaid != MSRP) {
           let promotion = defaultPrice - amountPaid; 
           let savings = MSRP - defaultPrice + promotion;
           thankYou.insertAdjacentHTML('afterend', `<span style="position:absolute; left: 409px; font-size: 9pt;">YOU SAVE $${savings.toFixed(2)} TODAY!</span>`);
        } 
    }
    else {
        let itemTotal = data.Sale.SaleLines.SaleLine; 
        let savings = 0
        for(let i = 0; i < itemTotal.length; i++ ) {
        let defaultPrice = data.Sale.SaleLines.SaleLine[i].Item.Prices.ItemPrice[0].amount;
        let MSRP = data.Sale.SaleLines.SaleLine[i].Item.Prices.ItemPrice[1].amount;
        let amountPaid = data.Sale.SaleLines.SaleLine[i].calcTotal;
        if(amountPaid != MSRP) {
            let promotion = defaultPrice - amountPaid;
            savings = savings + (MSRP - defaultPrice + promotion);
        
            }
        } 
        thankYou.insertAdjacentHTML('afterend', `<span style="position:absolute; left: 409px; font-size: 9pt;">YOU SAVE $${savings.toFixed(2)} TODAY!</span>`);
    
    }
    
    });
    
    });

    To add this code to your account navigate to:

    Settings > Advanced Setup > Print Templates > add the code from here: https://github.com/merchantos/PrintTemplates/blob/master/receipt/SaleReceipt.tpl

    Then search within the template and when you find the div HTML element below as seen, insert the script tag and paste my code in.

    <div class="receiptHeader">
    
    *insert script tag and code like I have done below*
    
    <script>
    // Paste in the above.
    
    </script>

    When implemented you'll get something like my screenshot below:




    N.B. As Lightspeed does not support any custom template customisation, support and implementation for this request will have to be sought via third party developers and we would advise you to speak to our sales team to point you in the right direction.

    Buut...if you follow my instructions, you should find this works ;)


    Have a good day @yohanJ !
    Post edited by Adrian Samuel on

    Adrian Samuel

    API Integrations Consultant - Strategic Solutions

    Lightspeed HQ

  • yohanJyohanJ Member Posts: 6
    edited August 2018
    Thank you sir i reallllyyy appreciate your help
    and your hard work. i think i may be explain not exactly.
    I'm very sorry to ask this help to you.but Please help us. Thank you

  • Adrian SamuelAdrian Samuel Moderator, Lightspeed Staff Posts: 569 moderator
    edited August 2018
    No worries!

    Good spot!

    1. I didn't handle the quantities > 1, so  I've remodelled the script to take that into account now:
    document.addEventListener("DOMContentLoaded", function() {
    
    let str = window.location.href; 
     let new_num = str.replace(/[\s\S]+?([\d]+)\.html[\s\S]+/ig, "$1");  
     let radPatt = /[\s\S]+\bAccount\/\b(\d{1,})[\s\S]+/ig; 
     let RAD = str.replace(radPatt, "$1"); 
     let domain = window.location.host; 
     let thankYou =  document.querySelector('.thankyou'); 
    fetch(`https://${domain}/API/Account/${RAD}/DisplayTemplate/Sale/${new_num}.json`, {
        credentials: "same-origin"}) 
        .then((response) => response.json()) 
        .then((data) => { 
    if (typeof data.Sale.SaleLines.SaleLine.length  == "undefined") {
        let amountPaid = data.Sale.calcTotal;
         let defaultPrice = data.Sale.SaleLines.SaleLine.Item.Prices.ItemPrice[0].amount;  
         let MSRP = data.Sale.SaleLines.SaleLine.Item.Prices.ItemPrice[1].amount;
         let quantity = data.Sale.SaleLines.SaleLine.unitQuantity
       if((amountPaid/quantity) != MSRP || amountPaid/quantity) != defaultPrice) {
           let promotion = (defaultPrice * quantity) - amountPaid; 
           let savings = ((MSRP - defaultPrice )* quantity ) + promotion;
           thankYou.insertAdjacentHTML('afterend', `<span style="position:absolute; left: 409px; font-size: 9pt;">YOU SAVE $${savings.toFixed(2)} TODAY!</span>`);
        } 
    }
    else {
        let itemTotal = data.Sale.SaleLines.SaleLine; 
        let savings = 0
        for(let i = 0; i < itemTotal.length; i++ ) {
        	let quantity = data.Sale.SaleLines.SaleLine[i].unitQuantity;
    
        let defaultPrice = data.Sale.SaleLines.SaleLine[i].Item.Prices.ItemPrice[0].amount;
        let MSRP = data.Sale.SaleLines.SaleLine[i].Item.Prices.ItemPrice[1].amount;
        let amountPaid = data.Sale.SaleLines.SaleLine[i].calcTotal;
        if((amountPaid/quantity) != MSRP || amountPaid/quantity) != defaultPrice) {
    let promotion = (defaultPrice * quantity) - amountPaid; savings = savings + ((MSRP - defaultPrice) * quantity) + promotion; } } thankYou.insertAdjacentHTML('afterend', `<span style="position:absolute; left: 409px; font-size: 9pt;">YOU SAVE $${savings.toFixed(2)} TODAY!</span>`); } }); });
    Also, since your receipt has different content than mine, the code to handle the placement of the message will have to managed by yourself/third-party developer to align it for your receipt.


    Post edited by Adrian Samuel on

    Adrian Samuel

    API Integrations Consultant - Strategic Solutions

    Lightspeed HQ

  • yohanJyohanJ Member Posts: 6
    Thank you so much for your help!!
    You are such a great!

  • JenelleJenelle Member Posts: 1
    edited October 2018
    Hi Adrian 

    Could this also be applied to our stores registers receipt? Please let me know if you need any specific information for our account. I was just talking to customer service(eline) and she said we could get you to change for us in our system.


  • Adrian SamuelAdrian Samuel Moderator, Lightspeed Staff Posts: 569 moderator
    edited November 2018
    Hey @Jenelle this could, but since this custom script is not officially supported by Lightspeed,  you would need to do is apply this yourself at your own jurisdiction; I can only advise.

    Place the script placed above under the following HTML

    <div class="receiptHeader">
    <script>
    // Paste Code here
    </script>
    
    

    Please employ the help of someone that is familiar with code to do this for you.

    If any other such data such as custom fields is required, you'll need to make use of our Retail SaleTemplate API and our Item API to visualise this.

    More information about this can be found here: 

    Item API) https://developers.lightspeedhq.com/retail/endpoints/Item/


    Sales Receipt API) https://developers.lightspeedhq.com/retail/endpoints/DisplayTemplate-Sale/
    Post edited by Adrian Samuel on

    Adrian Samuel

    API Integrations Consultant - Strategic Solutions

    Lightspeed HQ

Sign In or Register to comment.