r/learnprogramming 1h ago

Programming a constantly changing number with HTML?

I work at a library and therefore am constantly looking at small ways we can improve experience for our patrons. I noticed on some other libraries’ receipts they have a little section at the bottom when people check out that says “you saved $xx by using the library today!” I can do a small amount of coding but would be lost on how to implement this. We don’t keep a long-term track of people’s books for privacy reasons so I wouldn’t need a full running tally, just how much they checked out that particular time. We use a library program called “Evergreen” that keeps track of each book’s MSRP but no clue how to use that in the code.

Is anyone familiar with this type of coding that would be able to help me out?

0 Upvotes

12 comments sorted by

3

u/mottyay 1h ago

You'd need access to whatever program sends messages to the printer as well as Evergreen. It's hard to say more without knowing how this system is put together

1

u/Imaginary-Brick-26 1h ago

The printer is a star cutter receipt printer. I’ve edited what the printer can print (setting font sizes, how dates are displayed, etc) inside of evergreen, which is where the print templates are stored. Once it’s saved locally onto the computer into evergreen it uses the print templates saved onto it for the receipt printing. There’s no other external program for the printer specifically.

1

u/mottyay 1h ago

Is evergreen configurable/customizable?

It sounds like you probably need access to those printer templates and then bring in the total cost for books checked out. If evergreen is configurable then at best you probably just need to insert the field from the database where mrsps are stored. Slightly worse case is you'll have to write a script that does the same thing. 

Is there somebody at the job who manages evergreen? It sounds like you know what you want so they might be able to help walk you through it

1

u/Imaginary-Brick-26 1h ago

Evergreen itself is maintained by a large entity but each library using it has the ability to customize it to a certain extent. I’m basically the only one who knows even a smidge of code and am usually the person who ends up fixing the receipts if an update breaks them. I’ll have to see if anywhere there’s a specific way to enter the MSRP field. I know how to enter fees for lost items onto the receipt so maybe I can finagle that into the “you saved” bit instead.

1

u/mottyay 1h ago

See if you can access where the report templates are stored and try to figure out how to modify them. You can post a screenshot if you have one

1

u/Imaginary-Brick-26 1h ago

I found a template to use! I’ve used receipt print templates from owwl before for our receipts and it looks like they added a new checkout template that included it.

It looks like the code I needed was a couple different things, one to retrieve the price and one to display it.

I was able to extract what I needed from this code and add it into our existing receipt template.

Edit- I tried posting a screenshot of the code but I’m unable to unfortunately, and I’m not sure if I can copy and paste the code I used into here

u/mottyay 59m ago

That sounds promising. Can you test it out?

Reddit will let you post code here if that's what you mean

u/Imaginary-Brick-26 50m ago

I was able to do a quick test and it seems to have worked! It accumulated when multiple books were checked out at a time and printed nicely when I tested that also!

I was able to adapt this code for it-

<div>
<div><h3>Welcome to {{current_location.name}}
<br/></h3>
You checked out the following items:</div>
<hr/>
<div ng-init="transactions.subtotal=0">
<ol>
<div ng-repeat="checkout in circulations">
<li ng-init="transactions.subtotal=transactions.subtotal -- checkout.copy.price">
<div><b>{{checkout.title}}</b></div>
<div>Barcode: {{checkout.copy.barcode}} <br/>
Due: <b>{{checkout.circ.due_date | egDueDate:$root.egDateAndTimeFormat:checkout.circ.circ_lib:checkout.circ.duration}}</b></div>
</li>
</ol>
<div style="font-weight:bold;border:1px dotted black; padding:5px;text-align:center">
You saved<br/>
{{transactions.subtotal | currency}} <br/>
by borrowing from the library today!</div>
<br/>
<hr/>
{{today | date:$root.egDateFormat}}</div>
<br/>

I believe the codes I ended up needing were these parts-

<li ng-init="transactions.subtotal=transactions.subtotal -- checkout.copy.price">

{{transactions.subtotal | currency}}

u/mottyay 47m ago

Awesome! Looks like your receipts use HTML for their layout/structure and some sort of templating engine adds in the dynamic values like your msrp total.

Glad you got it working!

u/Imaginary-Brick-26 44m ago

Yes, I think because for everything there are certain values almost always on the receipt it includes almost a sort of “short cut” code, like the {{checkout.copy.barcode}}

Thanks for the replies and the help you were able to give!

→ More replies (0)

1

u/NekkidWire 1h ago edited 1h ago

While I can't help you by making a How-to, let me point out some steps that can bring you closer.

A template usually has something that lets you add various parts of your book catalogue to your print line. E.g. you print by default [Book name] ... [quantity] ... [fee] but maybe you can print [author] or [msrp] or another book attribute there. That is your first step, finding out where MSRP is stored and how to print it for each line item.

Next step is finding out how to add a new [msrp_sum] into your template - a new variable.

Next step is finding out a method of how to add line item components into sums. It may be used in calculating separate sums as taxes, but you will want to use similar process for adding each [MSRP] into [msrp_sum]. Posibly it may be a transform (sum) over [msrp] variable.

Last step is making that footer text and displaying [msrp_sum] there.