Allowance.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. import Format from "../Format.js";
  2. export default class Allowance{
  3. constructor(id, name, amount, isPercent, active){
  4. this._id = id;
  5. this._name = name;
  6. this._amount = amount;
  7. this._isPercent = isPercent;
  8. this._active = active;
  9. }
  10. get id(){
  11. return this._id;
  12. }
  13. get name(){
  14. return this._name;
  15. }
  16. get type(){
  17. return "Allowance";
  18. }
  19. get active(){
  20. return this._active;
  21. }
  22. amountInDollars(income){
  23. if(this._isPercent) return Format.centsToDollars(income * (this._amount / 100));
  24. return Format.centsToDollars(this._amount);
  25. }
  26. rawAmount(){
  27. if(this._isPercent) return this._amount;
  28. return Format.centsToDollars(this._amount);
  29. }
  30. static create(name, amount, isPercent){
  31. return new Allowance(
  32. crypto.randomUUID(),
  33. name,
  34. amount,
  35. isPercent,
  36. true
  37. );
  38. }
  39. static fromObject(data){
  40. return new Allowance(
  41. data.id,
  42. data.name,
  43. data.amount,
  44. data.isPercent,
  45. data.active
  46. );
  47. }
  48. serialize(){
  49. return {
  50. id: this._id,
  51. name: this._name,
  52. amount: this._amount,
  53. isPercent: this._isPercent,
  54. active: this._active
  55. };
  56. }
  57. }