Income.js 1011 B

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