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 🙏

© 2024 – Pkg Stats / Ryan Hefner

billing

v1.0.2

Published

Billing Module Js

Downloads

1,262

Readme

billing

Billing Module JS

npm version Build status

npm install billing

Usage

Right constructor (samples/node/rightConstructor.js)

var Bill = require('billing').BillingBill;

var bill = new Bill(); //new Bill
bill.charges.new({ price: 1.2 }); //add charge

var charge = bill.charges.new({ qty: 2.5, price: 2.4}); //charge with quantity
charge.modify({ fixedValue: 1.5 }); //charge modifier

bill.charges.new({ price: 3, modifier: { percentRatio: 0.5 } }); //charge with percent modifier
bill.modifiers.new({ percentRatio: -0.1 }); //global modifier percent
bill.payments.new({ value: 1 }); //partial payment
bill.payments.new(); //pay the rest

// validations
charge = bill.charges.new({ price: -2 });
charge.isValid; // -> false
charge.errors; // -> [{ price: { greaterThan: 'must be greater than 0' } }, { finalValue: { greaterThanOrEqualTo: 'must be greater than or equal to 0' } }]
bill.isValid; // -> false
bill.errors; // -> [{ charges: { invalid: 'are invalid' } }]

Left constructor (samples/node/leftConstructor.js)

var billing = require('billing');

var Bill = billing.BillingBill;
var Charge = billing.BillingCharge;
var Modifier = billing.BillingModifier;
var Payment = billing.BillingPayment;

var bill = new Bill();
new Charge({ bill: bill, price: 1.2 });

var charge = new Charge({ bill: bill, qty: 2.5, price: 2.4});
new Modifier({ charge: charge, fixedValue: 1.5 });

new Charge({ bill: bill, price: 3, modifier: { percentRatio: 0.5 } })

new Modifier({ bill: bill, percentRatio: -0.1 });

new Payment({ bill: bill, value: 1 });
new Payment({ bill: bill });

Bill instance

bill.charges    //Charge collection
bill.modifiers  //Modifier collection
bill.payments   //Payment collection
bill.total    //The whole number or amount (charges and modifiers)
bill.balance  //Bill remainder (total - payments)
bill.toJson() //A JSON object (without circular references)

Billing collections

<item> = <collection>.new(attributes = {})  //create
boolean  <collection>.add(item)             //add
boolean  <collection>.remove(item)          //destroy

Validations

boolean <item>.isValid  // check validity
<item>.errors   // errors format [{ propertyName: { validationName: 'Human readable error' }}]

Other

<item>.state // Unused instance variable available for UI purposes

Using the nomenclature (samples/node/usingNomenclature.js)

var billing = require('../../').Billing;

billing.config({
  nomenclature: {
    taxGroups: [
      { id: 1, name: '20%', percentRatio: 0.2 },
      { id: 2, name: '9%', percentRatio: 0.09 }
    ],
    departments: [
      { id: 1, name: 'Food', taxGroupId: 1 },
      { id: 2, name: 'Accommodation', taxGroupId: 2 }
    ],
    plus: [
      { id: 1, name: 'Pizza', departmentId: 1, price: 20.5 },
      { id: 2, name: 'Steak', departmentId: 1, price: 30.2 },
      { id: 3, name: 'Room',  departmentId: 2, price: 200 }
    ],
    paymentTypes: [
      { id: 1, name: 'Cash', isCash: true, isFiscal: true },
      { id: 2, name: 'Card', isCash: false, isFiscal: true },
      { id: 3, name: 'External', isCash: false, isFiscal: false }
    ]
  }
});

var bill = billing.bills.new();

bill.charges.new({ pluId: 1 }); // -> { qty: 1, price: 20.5, name: 'Pizza', taxRatio: 0.2 }
bill.charges.new({ qty: 2, price: 150, departmentId: 2 });
bill.payments.new({ paymentTypeId: 1 }); // -> { name: 'Cash', value: 20.5, isCash: true, isFiscal: true }

bill.toJson(); // -> { 
//   charges:                                                                                                                   
//    [ { qty: 1, price: 20.5, name: 'Pizza', taxRatio: 0.2 },                                                                  
//      { qty: 2, price: 150, name: 'Accommodation', taxRatio: 0.09 } ],                                                        
//   payments: [ { name: 'Cash', value: 320.5, isCash: true, isFiscal: true } ] }

Build

`npm run build` - Generate node library. (<project>/lib/*)
`npm run dist`  - Generate browser library. (<project>/dist/billing.js)
`npm test`      - Run unit tests.