payment-requirement.component.ts 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  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-payment-requirement",
  16. templateUrl: "./payment-requirement.component.html",
  17. styleUrls: ["./payment-requirement.component.scss"]
  18. })
  19. export class PaymentRequirementComponent implements OnInit {
  20. title: string = "Formulario de requisición de pago";
  21. // For daterange
  22. daysLabels: any = {
  23. su: "Dom",
  24. mo: "Lun",
  25. tu: "Mar",
  26. we: "Mie",
  27. th: "Jue",
  28. fr: "Vie",
  29. sa: "Sab"
  30. };
  31. monthsLabels: any = {
  32. 1: "Ene",
  33. 2: "Feb",
  34. 3: "Mar",
  35. 4: "Abr",
  36. 5: "May",
  37. 6: "Jun",
  38. 7: "Jul",
  39. 8: "Ago",
  40. 9: "Sep",
  41. 10: "Oct",
  42. 11: "Nov",
  43. 12: "Dic"
  44. };
  45. myDpOptions: IAngularMyDpOptions = {
  46. dateRange: false,
  47. dateFormat: "dd/mm/yyyy",
  48. dayLabels: this.daysLabels,
  49. monthLabels: this.monthsLabels
  50. };
  51. myDateInit: boolean = true;
  52. form: FormGroup;
  53. fileData: File = null;
  54. previewUrl: any = null;
  55. fileUploadProgress: string = null;
  56. uploadedFilePath: string = null;
  57. interval: any;
  58. indexDynamicComponent: number;
  59. investmentProposalID: string;
  60. investmentExists;
  61. monto: string = "";
  62. codigo_inversion: string = "";
  63. codigo: string = "";
  64. tipo_pago: string = "";
  65. cuenta_bancaria: string = "";
  66. fecha_pago: string = "";
  67. fecha_vencimiento: string = "";
  68. investmentProposalForm: FormGroup;
  69. submitted: boolean = false;
  70. paymentObject: Object;
  71. constructor(
  72. private http: HttpClient,
  73. private formDataService: FormInvestmentProposalService,
  74. private componentFactoryResolver: ComponentFactoryResolver,
  75. private instrumentService: InvestmentProposalWorkflowService,
  76. private loadInstrumentsService: InstrumentsService,
  77. private catalogService: CatalogsService,
  78. private route: ActivatedRoute,
  79. private investmentService: InvestmentsService,
  80. private formBuilder: FormBuilder,
  81. private investmentsService: InvestmentsService
  82. ) {}
  83. ngOnInit() {
  84. //this.formDataService
  85. //this.ads = this.loadInstrumentsService.getInstruments();
  86. this.route.params.subscribe(params => {
  87. this.investmentProposalID = params["id"];
  88. });
  89. if (this.investmentProposalID == undefined)
  90. this.investmentProposalID = this.route.snapshot.queryParamMap.get("id");
  91. this.investmentService
  92. .getPaymentInfoProposalInvestment(this.investmentProposalID)
  93. .subscribe(resp => {
  94. this.monto = resp["result"]["monto"];
  95. this.codigo_inversion =
  96. resp["result"]["id_inversion"]["codigo_inversion"];
  97. this.codigo = resp["result"]["codigo"];
  98. this.tipo_pago = resp["result"]["id_tipo_pago"]["nombre"];
  99. this.cuenta_bancaria = resp["result"]["id_cuenta_bancaria"]["nombre"];
  100. this.fecha_vencimiento = resp["result"]["fecha_vencimiento"];
  101. });
  102. this.investmentProposalForm = this.formBuilder.group({
  103. comentario: [""],
  104. fecha_pago: ["", Validators.required]
  105. });
  106. }
  107. fileProgress(fileInput: any) {
  108. this.fileData = <File>fileInput.target.files[0];
  109. this.preview();
  110. }
  111. preview() {
  112. // Show preview
  113. var mimeType = this.fileData.type;
  114. if (mimeType.match(/image\/*/) == null) {
  115. return;
  116. }
  117. var reader = new FileReader();
  118. reader.readAsDataURL(this.fileData);
  119. reader.onload = _event => {
  120. this.previewUrl = reader.result;
  121. };
  122. }
  123. get f() {
  124. return this.investmentProposalForm.controls;
  125. }
  126. onSubmit(form: any) {
  127. this.submitted = true;
  128. console.log(form);
  129. if (!form.valid) {
  130. return false;
  131. }
  132. this.paymentObject = {
  133. fecha_pago: form.value.fecha_pago.singleDate.formatted,
  134. id_inversion: this.investmentProposalID
  135. //comentario:
  136. };
  137. Swal.fire({
  138. allowOutsideClick: false,
  139. icon: "info",
  140. text: "Espere por favor..."
  141. });
  142. Swal.showLoading();
  143. const formData = new FormData();
  144. formData.append("id_inversion", this.investmentProposalID);
  145. formData.append("evidencia", this.fileData);
  146. formData.append("step", "next");
  147. formData.append("comentario", form.value.comentario);
  148. this.investmentsService
  149. .updatePaymentInfoProposalInvestment(
  150. this.investmentProposalID,
  151. this.paymentObject
  152. )
  153. .subscribe(
  154. success => {
  155. this.investmentService
  156. .sendProposalInvestmentToNextStep(formData)
  157. .subscribe(
  158. success => {
  159. if (success) {
  160. Swal.fire({
  161. allowOutsideClick: false,
  162. icon: "success",
  163. showCancelButton: false,
  164. title: "Exito",
  165. confirmButtonText: "La propuesta ha sido liquidada"
  166. }).then(result => {
  167. Swal.close();
  168. window.location.href = "#/investment-proposals";
  169. });
  170. }
  171. },
  172. err => {
  173. Swal.fire({
  174. icon: "error",
  175. title: "Error en el servidor",
  176. text: err.message
  177. });
  178. }
  179. );
  180. },
  181. err => {
  182. Swal.fire({
  183. icon: "error",
  184. title: "Error en el servidor",
  185. text: err.message
  186. });
  187. }
  188. );
  189. }
  190. }