billing
Billing Module JS
npm install billing
- Implements base billing standart.
- Data binding frameworks friendly.
- Example: BillingJs Demo (Angular2)
Usage
samples/node/rightConstructor.js)
Right constructor (var Bill = BillingBill; var bill = ; //new Billbillcharges; //add charge var charge = billcharges; //charge with quantitycharge; //charge modifier billcharges; //charge with percent modifierbillmodifiers; //global modifier percentbillpayments; //partial paymentbillpayments; //pay the rest // validationscharge = billcharges;chargeisValid; // -> falsechargeerrors; // -> [{ price: { greaterThan: 'must be greater than 0' } }, { finalValue: { greaterThanOrEqualTo: 'must be greater than or equal to 0' } }]billisValid; // -> falsebillerrors; // -> [{ charges: { invalid: 'are invalid' } }]
samples/node/leftConstructor.js)
Left constructor (var billing = ; var Bill = billingBillingBill;var Charge = billingBillingCharge;var Modifier = billingBillingModifier;var Payment = billingBillingPayment; var bill = ; bill: bill price: 12 ; var charge = bill: bill qty: 25 price: 24; charge: charge fixedValue: 15 ; bill: bill price: 3 modifier: percentRatio: 05 bill: bill percentRatio: -01 ; bill: bill value: 1 ; bill: bill ;
Bill instance
billcharges //Charge collectionbillmodifiers //Modifier collectionbillpayments //Payment collectionbilltotal //The whole number or amount (charges and modifiers)billbalance //Bill remainder (total - payments)bill //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
samples/node/usingNomenclature.js)
Using the nomenclature (var billing = Billing; billing; var bill = billingbills; billcharges; // -> { qty: 1, price: 20.5, name: 'Pizza', taxRatio: 0.2 }billcharges;billpayments; // -> { name: 'Cash', value: 20.5, isCash: true, isFiscal: true } bill; // -> { // 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.