Urgent.News

What's breaking now, across hundreds of outlets.

Tech

Checking a payment run day by day: a reserve invariant, early-payment discounts and integer cents

A payment run is a list of (date, amount) outflows mixed with expected receipts. The only question that matters is whether the running balance stays above a reserve on every day. That makes it a simple invariant you can test. The data const reserve = 1_000_000n ; // $10,000.00 const opening = 3_000_000n ; const events = [ { day : 1 , amt : - 800_000n , what : 'bill A' } , { day : 3 , amt : -…

A payment run is a list of dates and amounts for outflows and expected receipts. The crucial point is that the running balance never drops below a reserve amount. To test this invariant, sort the events by day, sum the amounts for each day, and keep track of the balance. If the balance ever falls below the reserve, record the day and the shortfall. The provided code demonstrates this check.

Applying a 2% early-payment discount on bill B for paying on day 1 modifies the events. The discount is calculated as 1,200,000 * 9,800 / 10,000, resulting in 1,176,000. If the modified plan still passes the invariant check, the discount can be applied. In this case, the balance on day 1 drops to $10,240, which is above the reserve, and the discount saves $240.

Moving the receipt a week later causes the balance to drop below the reserve on day 5. With the discount taken, the shortfall is $8,760, compared to $9,000 without the discount. This number indicates the minimum acceptable balance to prevent the reserve from being breached. The same invariant is used in the Supplier Bills & Payment Run Planner, which offers a free demo.

Rewritten by urgent.news; may contain errors — check the original.

Source: dev.to

Read the original at dev.to →

Report a problem with this story

More in Tech

How to Build a Persistent 3-Step Checklist Widget in 12 Lines of Vanilla JS (No Frameworks)

Most interactive checklists on the web pull in 150 KB of React state libraries just to toggle three checkboxes. When I built a live countdown & 3-step Cyber Monday cashback tracker for shoppers trying…

  • Insert three checkboxes with class "cm-chk" and data attributes for step numbers
  • Initialize JavaScript object st from local storage or default to empty object
  • Update progress and monetary value in "cm-prog" div on checkbox state changes

Zero-Backend White-Label Demos: Personalizing Static Sites via URL Query Params in 18 Lines of JS

When pitching coupon bloggers, YouTube deal creators, and Facebook group admins a white-label web hub, the biggest conversion killer is asking them to "imagine" what their branded site would look…

  • Zero-Backend White-Label approach allows instant personalized previews with 18 lines of JS
  • Pre-rendered static HTML pages load in under 3 seconds via Vercel's edge CDN
  • URLSearchParams dynamically update header, title, and CTA based on 'brand' query parameter

More from Friday 27 November →