| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- import Format from "../Format.js";
- export default class Allowance{
- constructor(id, name, amount, isPercent, active){
- this._id = id;
- this._name = name;
- this._amount = amount;
- this._isPercent = isPercent;
- this._active = active;
- }
- get id(){
- return this._id;
- }
- get name(){
- return this._name;
- }
- get type(){
- return "Allowance";
- }
- get active(){
- return this._active;
- }
- amountInDollars(income){
- if(this._isPercent) return Format.centsToDollars(income * (this._amount / 100));
- return Format.centsToDollars(this._amount);
- }
- rawAmount(){
- if(this._isPercent) return this._amount;
- return Format.centsToDollars(this._amount);
- }
- static create(name, amount, isPercent){
- return new Allowance(
- crypto.randomUUID(),
- name,
- amount,
- isPercent,
- true
- );
- }
- static fromObject(data){
- return new Allowance(
- data.id,
- data.name,
- data.amount,
- data.isPercent,
- data.active
- );
- }
- serialize(){
- return {
- id: this._id,
- name: this._name,
- amount: this._amount,
- isPercent: this._isPercent,
- active: this._active
- };
- }
- }
|