Allowance.js 1.0 KB

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