upload-liquidation.component.ts 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. import { Component, OnInit, ComponentFactoryResolver } from "@angular/core";
  2. import { FileUploader, FileLikeObject } from "ng2-file-upload";
  3. import { concat } from "rxjs";
  4. import { FormBuilder, FormGroup, Validators } from "@angular/forms";
  5. import { HttpClient, HttpEventType } from "@angular/common/http";
  6. import { FormInvestmentProposalService } from "@app/services/form-investment-proposal.service";
  7. import { InvestmentProposalWorkflowService } from "@app/services/investment-proposal-workflow.service";
  8. import { InstrumentsService } from "@app/services/instruments.service";
  9. import { CatalogsService } from "@app/services/catalogs.service";
  10. import { ActivatedRoute } from "@angular/router";
  11. import { InvestmentsService } from "@app/services/investments.service";
  12. import Swal from "sweetalert2";
  13. import { IAngularMyDpOptions } from "angular-mydatepicker";
  14. @Component({
  15. selector: "app-upload-liquidation",
  16. templateUrl: "./upload-liquidation.component.html",
  17. styleUrls: ["./upload-liquidation.component.scss"]
  18. })
  19. export class UploadLiquidationComponent implements OnInit {
  20. title: string = "Subir hoja de liquidación";
  21. // For daterange
  22. form: FormGroup;
  23. fileData: File = null;
  24. previewUrl: any = null;
  25. fileUploadProgress: string = null;
  26. uploadedFilePath: string = null;
  27. interval: any;
  28. indexDynamicComponent: number;
  29. investmentProposalID: string;
  30. investmentExists;
  31. codigo_inversion: string = "";
  32. empresa: string = "";
  33. estado: string = "";
  34. emisor: string = "";
  35. instrumento: string = "";
  36. investmentProposalForm: FormGroup;
  37. submitted: boolean = false;
  38. paymentObject: Object;
  39. constructor(
  40. private http: HttpClient,
  41. private formDataService: FormInvestmentProposalService,
  42. private componentFactoryResolver: ComponentFactoryResolver,
  43. private instrumentService: InvestmentProposalWorkflowService,
  44. private loadInstrumentsService: InstrumentsService,
  45. private catalogService: CatalogsService,
  46. private route: ActivatedRoute,
  47. private investmentService: InvestmentsService,
  48. private formBuilder: FormBuilder,
  49. private investmentsService: InvestmentsService
  50. ) {}
  51. ngOnInit() {
  52. //this.formDataService
  53. //this.ads = this.loadInstrumentsService.getInstruments();
  54. this.route.params.subscribe(params => {
  55. this.investmentProposalID = params["id"];
  56. });
  57. if (this.investmentProposalID == undefined)
  58. this.investmentProposalID = this.route.snapshot.queryParamMap.get("id");
  59. this.investmentService
  60. .getProposalInvestment(this.investmentProposalID)
  61. .subscribe(resp => {
  62. this.codigo_inversion = resp["result"]["codigo_inversion"];
  63. this.estado = resp["result"]["id_estado_inversion"]["nombre"];
  64. this.instrumento =
  65. resp["result"]["id_inversion_instrumento"]["id_tipo_instrumento"][
  66. "nombre"
  67. ];
  68. this.emisor = resp["result"]["id_tipo_emisor"]["nombre"];
  69. this.empresa = resp["result"]["id_empresa"]["nombre"];
  70. Swal.close();
  71. });
  72. this.investmentProposalForm = this.formBuilder.group({
  73. id_inversion: [this.investmentProposalID]
  74. });
  75. }
  76. fileProgress(fileInput: any) {
  77. this.fileData = <File>fileInput.target.files[0];
  78. this.preview();
  79. }
  80. preview() {
  81. // Show preview
  82. var mimeType = this.fileData.type;
  83. if (mimeType.match(/image\/*/) == null) {
  84. return;
  85. }
  86. var reader = new FileReader();
  87. reader.readAsDataURL(this.fileData);
  88. reader.onload = _event => {
  89. this.previewUrl = reader.result;
  90. };
  91. }
  92. get f() {
  93. return this.investmentProposalForm.controls;
  94. }
  95. onSubmit(form: any) {
  96. this.submitted = true;
  97. if (this.fileData == null) {
  98. return false;
  99. }
  100. const formData = new FormData();
  101. formData.append("id_inversion", this.investmentProposalID);
  102. formData.append("hoja_liquidacion", this.fileData);
  103. this.investmentService.sendLiquidationFile(formData).subscribe(
  104. success => {
  105. if (success) {
  106. Swal.fire({
  107. allowOutsideClick: false,
  108. icon: "success",
  109. showCancelButton: false,
  110. title: "Exito",
  111. confirmButtonText: "Se ha subido la hoja de liquidación"
  112. }).then(result => {
  113. Swal.close();
  114. window.location.href = "#/investment-proposals";
  115. });
  116. }
  117. },
  118. err => {
  119. Swal.fire({
  120. icon: "error",
  121. title: "Error en el servidor",
  122. text: err.message
  123. });
  124. }
  125. );
  126. }
  127. }