npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@zenuinebit/sales-return

v0.1.0

Published

Sales returns and credit notes: quantity limits, prorated discounts, exact tax reversal, refund splits, restock movements.

Readme

@zenuinebit/sales-return

Sales returns that produce a GST credit note: quantity limits, prorated discounts, a refund amount, refund split across payment methods, and stock coming back. Builds on @zenuinebit/gst-report, @zenuinebit/money and @zenuinebit/stock-ledger. Amounts are integers in minor units; dates are "YYYY-MM-DD".

import { createReturn, returnable, splitRefund, toStockMovements } from "@zenuinebit/sales-return";
import { generateReport } from "@zenuinebit/gst-report";

const sale = {
  number: "INV-1", date: "2025-04-10", placeOfSupply: "Maharashtra",
  lines: [{ sku: "TEA", description: "Tea", hsn: "0902", quantity: 10, unitPrice: 10_000, discount: 1_000, taxRate: 5 }],
};

const ret = createReturn(
  sale,
  { number: "CN-1", date: "2025-04-15", items: [{ sku: "TEA", quantity: 4 }], reason: "Stale" },
  { supplier: "27AAPFU0939F1ZV", maxDays: 30, previous: [] },     // pass earlier returns of this sale as `previous`
);

ret.refund;          // 41_580 - what to give back, positive
ret.creditNote;      // a gst-report invoice (type "credit-note"): include it in generateReport / e-invoice / e-way flows
returnable(sale, [ret]);                                   // { TEA: 6 } still returnable

splitRefund(ret.refund, [{ method: "cash", amount: 20_000 }, { method: "card", amount: 80_000 }]);
// refund shared in proportion to what each method paid; the parts add up exactly

toStockMovements(ret, { TEA: 6_000 });                    // goods back in stock at a unit cost, for stock-ledger

Rules it enforces

  • Returning more than was sold, counting earlier returns, is refused. So is a return dated before the sale, or after maxDays.
  • The line discount comes back in proportion to the units returned; the return that finishes a line takes whatever discount is left, so the discount reverses exactly (333 + 333 + 334 on a 1,000 discount over three returns of one unit each).
  • Tax is worked out like a sale, per line. A line returned in several pieces can differ from the original tax by a minor unit because of rounding; the taxable value reverses exactly (for whole quantities).
  • Works for tax-inclusive sales too.
  • restock: false (damaged goods) leaves a line out of the stock movements. Restocking needs a unit cost for each line, because stock needs a value.

Not included: storing returns, exchanges (a return plus a new sale), refunds to a different method than the original payment, restocking fees, and e-invoice or e-way handling of the credit note (see @zenuinebit/einvoice-irn).