form-investment-proposal.service.ts 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. import { Injectable } from "@angular/core";
  2. import {
  3. InvestmentProposalForm,
  4. GeneralInfo,
  5. ComplementInfo
  6. } from "@app/models/investment-proposal-form";
  7. import { InvestmentProposalWorkflowService } from "@app/services/investment-proposal-workflow.service";
  8. import { STEPS } from "@app/models/investment-proposal-workflow";
  9. @Injectable({
  10. providedIn: "root"
  11. })
  12. export class FormInvestmentProposalService {
  13. private formData: InvestmentProposalForm = new InvestmentProposalForm();
  14. private instrumentData: any;
  15. private isGeneralInfoFormValid: boolean = false;
  16. private isWorkFormValid: boolean = false;
  17. private isComplementInfoFormValid: boolean = false;
  18. constructor(private workflowService: InvestmentProposalWorkflowService) {}
  19. getGeneralInfo(): GeneralInfo {
  20. // Return the GeneralInfo data
  21. var general_info: GeneralInfo = {
  22. asunto: this.formData.asunto,
  23. origenes_fondo: this.formData.origenes_fondo,
  24. name: this.formData.name,
  25. tipo_tasa: this.formData.tipo_tasa,
  26. tipo_renta: this.formData.tipo_renta,
  27. periodicidad: this.formData.periodicidad,
  28. instrumentos: this.formData.instrumentos,
  29. base_anual: this.formData.base_anual,
  30. casa: this.formData.casa,
  31. formato_ingreso: this.formData.formato_ingreso
  32. };
  33. return general_info;
  34. }
  35. setGeneralInfo(data: GeneralInfo) {
  36. // Update the general_info data only when the general_info Form had been validated successfully
  37. this.isGeneralInfoFormValid = true;
  38. this.formData.asunto = data.asunto;
  39. this.formData.origenes_fondo = data.origenes_fondo;
  40. this.formData.name = data.name;
  41. this.formData.tipo_tasa = data.tipo_tasa;
  42. this.formData.tipo_renta = data.tipo_renta;
  43. this.formData.periodicidad = data.periodicidad;
  44. this.formData.instrumentos = data.instrumentos;
  45. this.formData.base_anual = data.base_anual;
  46. this.formData.casa = data.casa;
  47. this.formData.formato_ingreso = data.formato_ingreso;
  48. // Validate general_info Step in Workflow
  49. this.workflowService.validateStep(STEPS.general);
  50. }
  51. getWork(): string {
  52. // Return the work type
  53. return this.instrumentData || undefined;
  54. }
  55. setWork(data: any) {
  56. // Update the work type only when the Work Form had been validated successfully
  57. this.isWorkFormValid = true;
  58. //this.formData.work = data;
  59. this.instrumentData = data;
  60. // Validate Work Step in Workflow
  61. this.workflowService.validateStep(STEPS.work);
  62. }
  63. // Return the complement info of an investment proposal
  64. getComplementInfo(): ComplementInfo {
  65. var complement_info: ComplementInfo = {
  66. tipo_mercado: this.formData.tipo_mercado,
  67. emisores: this.formData.emisores,
  68. empresa: this.formData.empresa,
  69. pais: this.formData.pais,
  70. comentarios: this.formData.comentarios,
  71. justificacion: this.formData.justificacion,
  72. plazo: this.formData.plazo,
  73. operaciones: this.formData.operaciones
  74. };
  75. return complement_info;
  76. }
  77. // Update the complement info data only when the form had been validated successfully
  78. setComplementInfo(data: ComplementInfo) {
  79. this.isComplementInfoFormValid = true;
  80. this.formData.tipo_mercado = data.tipo_mercado;
  81. this.formData.emisores = data.emisores;
  82. this.formData.empresa = data.empresa;
  83. this.formData.pais = data.pais;
  84. this.formData.plazo = data.plazo;
  85. this.formData.operaciones = data.operaciones;
  86. this.formData.comentarios = data.comentarios;
  87. this.formData.justificacion = data.justificacion;
  88. // Validate complement_info Step in Workflow
  89. this.workflowService.validateStep(STEPS.complement);
  90. }
  91. getFormData(): InvestmentProposalForm {
  92. // Return the entire Form Data
  93. return this.formData;
  94. }
  95. resetFormData(): InvestmentProposalForm {
  96. // Reset the workflow
  97. // Return the form data after all this.* members had been reset
  98. this.formData.clear();
  99. this.instrumentData = undefined;
  100. this.setWork(this.instrumentData);
  101. this.isGeneralInfoFormValid = this.isWorkFormValid = this.isComplementInfoFormValid = false;
  102. this.workflowService.resetSteps();
  103. return this.formData;
  104. }
  105. isFormValid() {
  106. // Return true if all forms had been validated successfully; otherwise, return false
  107. return (
  108. this.isGeneralInfoFormValid &&
  109. this.isWorkFormValid &&
  110. this.isComplementInfoFormValid
  111. );
  112. }
  113. }