payment-info.component.ts 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386
  1. import { Component, OnInit } from "@angular/core";
  2. import { FormInvestmentProposalService } from "@app/services/form-investment-proposal.service";
  3. import { FormBuilder, FormGroup, Validators } from "@angular/forms";
  4. import { CatalogsService } from "@app/services/catalogs.service";
  5. import { IAngularMyDpOptions, IMyDateModel } from "angular-mydatepicker";
  6. import { formatDate, DatePipe } from "@angular/common";
  7. import { parse } from "date-fns";
  8. import { Router, ActivatedRoute } from "@angular/router";
  9. import { InvestmentsService } from "@app/services/investments.service";
  10. import Swal from "sweetalert2";
  11. @Component({
  12. selector: "app-payment-info",
  13. templateUrl: "./payment-info.component.html"
  14. })
  15. export class PaymentInfoComponent implements OnInit {
  16. title: string = "Formulario de información para el pago";
  17. form: any;
  18. // For daterange
  19. daysLabels: any = {
  20. su: "Dom",
  21. mo: "Lun",
  22. tu: "Mar",
  23. we: "Mie",
  24. th: "Jue",
  25. fr: "Vie",
  26. sa: "Sab"
  27. };
  28. monthsLabels: any = {
  29. 1: "Ene",
  30. 2: "Feb",
  31. 3: "Mar",
  32. 4: "Abr",
  33. 5: "May",
  34. 6: "Jun",
  35. 7: "Jul",
  36. 8: "Ago",
  37. 9: "Sep",
  38. 10: "Oct",
  39. 11: "Nov",
  40. 12: "Dic"
  41. };
  42. myDpOptions: IAngularMyDpOptions = {
  43. dateRange: false,
  44. dateFormat: "dd/mm/yyyy",
  45. dayLabels: this.daysLabels,
  46. monthLabels: this.monthsLabels
  47. };
  48. myDateInit: boolean = true;
  49. investmentProposalForm: FormGroup;
  50. submitted: boolean = false;
  51. role_number: any;
  52. markets: any;
  53. emitters: any;
  54. periodicities: any;
  55. rate_agencies: any;
  56. scores: any;
  57. investmentProposalID: string;
  58. funds: any;
  59. companies: any;
  60. format_incomes: any;
  61. operations: any;
  62. payment_terms: any;
  63. payment_types: any;
  64. inversionCode: any;
  65. paymentProposal: any;
  66. banks: any;
  67. accounts: any;
  68. paymentObject: Object;
  69. inversionAmount: any;
  70. reviewProposal: any;
  71. generated_inputs_next: any;
  72. userListNext: any;
  73. investmentService: any;
  74. payment_check: boolean;
  75. payment_transfer: boolean;
  76. accounts_destination: any;
  77. accounts_origin: any;
  78. constructor(
  79. private router: Router,
  80. private route: ActivatedRoute,
  81. private formBuilder: FormBuilder,
  82. private formDataService: FormInvestmentProposalService,
  83. private catalogService: CatalogsService,
  84. private investmentsService: InvestmentsService
  85. ) {}
  86. ngOnInit() {
  87. this.route.params.subscribe(params => {
  88. this.investmentProposalID = params["id"];
  89. });
  90. if (this.investmentProposalID == undefined)
  91. this.investmentProposalID = this.route.snapshot.queryParamMap.get("id");
  92. this.investmentsService
  93. .getAvailableUsers(this.investmentProposalID)
  94. .subscribe(res => {
  95. this.userListNext = res["usuarios_next"];
  96. this.generated_inputs_next = "";
  97. if (this.userListNext.length > 0) {
  98. for (let i = 0; i < this.userListNext.length; i++) {
  99. if (this.userListNext[i].default_email == true) {
  100. this.generated_inputs_next += `<div class='form-check form-check-inline'><input type='checkbox' class='form-check-input' id='next-${
  101. this.userListNext[i].name
  102. }' name='users' value='${this.userListNext[i].name}' checked='${
  103. this.userListNext[i].default_email == "true" ? true : false
  104. }'><label class='form-check-label' for='next-${
  105. this.userListNext[i].name
  106. }'>${this.userListNext[i].name}</label></div>`;
  107. } else {
  108. this.generated_inputs_next += `<div class='form-check form-check-inline'><input type='checkbox' class='form-check-input' id='next-${this.userListNext[i].name}' name='users' value='${this.userListNext[i].name}'><label class='form-check-label' for='next-${this.userListNext[i].name}'>${this.userListNext[i].name}</label></div>`;
  109. }
  110. }
  111. }
  112. });
  113. this.investmentsService
  114. .getProposalInvestment(this.investmentProposalID)
  115. .subscribe(
  116. res => {
  117. this.inversionCode = res["result"]["codigo_inversion"];
  118. if (
  119. res["result"]["id_inversion_instrumento"]["instrumento"][
  120. "monto_inversion"
  121. ] != undefined
  122. ) {
  123. this.inversionAmount =
  124. res["result"]["id_inversion_instrumento"]["instrumento"][
  125. "monto_inversion"
  126. ];
  127. } else if (
  128. res["result"]["id_inversion_instrumento"]["instrumento"][
  129. "total_pagar"
  130. ] != undefined
  131. ) {
  132. this.inversionAmount =
  133. res["result"]["id_inversion_instrumento"]["instrumento"][
  134. "total_pagar"
  135. ];
  136. } else if (
  137. res["result"]["id_inversion_instrumento"]["instrumento"][
  138. "monto_pagar"
  139. ] != undefined
  140. ) {
  141. this.inversionAmount =
  142. res["result"]["id_inversion_instrumento"]["instrumento"][
  143. "monto_pagar"
  144. ];
  145. }
  146. this.investmentProposalForm.setValue({
  147. monto:
  148. Math.round((this.inversionAmount + Number.EPSILON) * 100) / 100,
  149. tipo_pago: "",
  150. cuenta_bancaria: "",
  151. fecha_vencimiento: "",
  152. cuenta_bancaria_destino: "",
  153. emitir_nombre: res["result"]["emitir_a_nombre_de"]
  154. });
  155. },
  156. err => {
  157. Swal.fire({
  158. icon: "error",
  159. title: "Error en el servidor",
  160. text: err.message
  161. });
  162. }
  163. );
  164. this.catalogService
  165. .getBankAccounts("origen", this.investmentProposalID)
  166. .subscribe(res => {
  167. this.accounts_origin = res["result"];
  168. });
  169. this.catalogService
  170. .getBankAccounts("destino", this.investmentProposalID)
  171. .subscribe(res => {
  172. this.accounts_destination = res["result"];
  173. });
  174. this.catalogService.getPaymentTypes().subscribe(res => {
  175. this.payment_types = res;
  176. });
  177. this.catalogService.getCountries().subscribe(res => {
  178. this.funds = res;
  179. });
  180. /*this.catalogService.getCatalogInfo("bancos").subscribe(res => {
  181. this.banks = res;
  182. this.catalogService.getCatalogInfo("cuentas-bancarias").subscribe(res => {
  183. this.accounts = res;
  184. });
  185. //this.payment_types = res;
  186. });*/
  187. /*this.catalogService
  188. .getCatalogInfo("cuentas-bancaria-destino")
  189. .subscribe(res => {
  190. this.accounts_destination = res;
  191. });
  192. */
  193. this.investmentProposalForm = this.formBuilder.group({
  194. monto: [
  195. this.inversionAmount,
  196. [
  197. Validators.required,
  198. Validators.pattern(/^[+]?([0-9]+(?:[\.][0-9]*)?|\.[0-9]+)$/)
  199. ]
  200. ],
  201. tipo_pago: ["", Validators.required],
  202. cuenta_bancaria: ["", Validators.required],
  203. fecha_vencimiento: ["", Validators.required],
  204. cuenta_bancaria_destino: [""],
  205. emitir_nombre: [""]
  206. });
  207. }
  208. onChangePaymentType(event: any) {
  209. if (event == 2) {
  210. this.payment_check = true;
  211. this.payment_transfer = false;
  212. } else if (event == 3) {
  213. this.payment_transfer = true;
  214. this.payment_check = false;
  215. } else {
  216. this.payment_check = false;
  217. this.payment_transfer = false;
  218. }
  219. }
  220. get f() {
  221. return this.investmentProposalForm.controls;
  222. }
  223. nameBankAccounts(id: string) {
  224. let bank;
  225. bank = this.banks.find(e => e.id_banco == id);
  226. return bank.nombre;
  227. }
  228. sendPaymentInfo(form: any) {
  229. this.submitted = true;
  230. if (!form.valid) {
  231. return false;
  232. }
  233. this.reviewProposal = undefined;
  234. (async () => {
  235. Swal.fire({
  236. title: `<h3>Enviar información de pago</h3>`,
  237. icon: "info",
  238. html: `<p style="text-align:left;">Comentario:</p>`,
  239. input: "textarea",
  240. showCancelButton: true,
  241. confirmButtonText: "Siguiente",
  242. cancelButtonText: "Cancelar",
  243. showLoaderOnConfirm: true,
  244. //inputValidator: value => {
  245. // if (!value) {
  246. // return "Debe ingresar un comentario";
  247. //}
  248. //},
  249. preConfirm: comentario => {
  250. this.reviewProposal = {
  251. id_inversion: this.investmentProposalID,
  252. step: "next",
  253. comentario: comentario
  254. };
  255. },
  256. allowOutsideClick: () => !Swal.isLoading()
  257. }).then(result => {
  258. if (result.dismiss) {
  259. Swal.close();
  260. }
  261. Swal.fire({
  262. title: `<h3>Enviar información de pago</h3>`,
  263. icon: "info",
  264. html: `<div>Notificar a:</div>${this.generated_inputs_next}`,
  265. confirmButtonText: "Enviar información",
  266. showCancelButton: true,
  267. cancelButtonText: "Cancelar",
  268. showLoaderOnConfirm: true,
  269. preConfirm: () => {
  270. let array = [];
  271. for (let i = 0; i < this.userListNext.length; i++) {
  272. let html_input: HTMLInputElement = document.getElementById(
  273. "next-" + this.userListNext[i].name
  274. ) as HTMLInputElement;
  275. let html_value: string = html_input.value;
  276. if (html_input.checked == true) {
  277. array.push(html_value);
  278. }
  279. }
  280. // http://localhost:8001/api/cuentas-bancarias?tipo=origen&id_inversion=51
  281. this.reviewProposal["notificar"] = array.toString();
  282. this.paymentObject = {
  283. monto: this.inversionAmount,
  284. id_tipo_pago: +this.investmentProposalForm.value.tipo_pago,
  285. id_cuenta_bancaria: +this.investmentProposalForm.value
  286. .cuenta_bancaria,
  287. //fecha_pago: this.investmentProposalForm.value.fecha_pago.singleDate.formatted,
  288. fecha_vencimiento: this.investmentProposalForm.value
  289. .fecha_vencimiento.singleDate.formatted,
  290. emitir_nombre: this.investmentProposalForm.value.emitir_nombre,
  291. id_inversion: +this.investmentProposalID
  292. };
  293. if (+this.investmentProposalForm.value.tipo_pago == 3) {
  294. this.paymentObject["id_cuenta_bancaria_destino"] = +this
  295. .investmentProposalForm.value.cuenta_bancaria_destino;
  296. }else{
  297. this.paymentObject["id_cuenta_bancaria_destino"] = null;
  298. }
  299. }
  300. }).then(result1 => {
  301. if (result1.dismiss) {
  302. return false;
  303. }
  304. Swal.fire({
  305. allowOutsideClick: false,
  306. title: "Espere por favor...",
  307. icon: "info"
  308. });
  309. Swal.showLoading();
  310. this.investmentsService
  311. .sendPaymentInfoProposalInvestment(
  312. this.investmentProposalID,
  313. this.paymentObject
  314. )
  315. .subscribe(
  316. success => {
  317. this.investmentsService
  318. .sendProposalInvestmentToNextStep(this.reviewProposal)
  319. .subscribe(
  320. success => {
  321. if (success) {
  322. Swal.fire({
  323. allowOutsideClick: false,
  324. icon: "success",
  325. showCancelButton: false,
  326. title: "Exito",
  327. confirmButtonText:
  328. "La requisicion de pago ha sido generada"
  329. }).then(result => {
  330. Swal.close();
  331. window.location.href = "#/investment-proposals";
  332. });
  333. }
  334. },
  335. err => {
  336. Swal.fire({
  337. icon: "error",
  338. title: "Error al guardar",
  339. text: err.message
  340. });
  341. }
  342. );
  343. },
  344. err => {
  345. Swal.fire({
  346. icon: "error",
  347. title: "Error al guardar",
  348. text: err.message
  349. });
  350. }
  351. );
  352. });
  353. //window.location.reload();
  354. });
  355. })();
  356. }
  357. }