| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504 |
- import {
- Component,
- OnInit,
- OnChanges,
- ViewChild,
- ComponentRef,
- Type,
- ElementRef
- } from "@angular/core";
- import { FormBuilder, FormGroup, Validators } from "@angular/forms";
- import Swal from "sweetalert2";
- import {
- GeneralInfo,
- ComplementInfo
- } from "@app/models/investment-proposal-form";
- import { Router, ActivatedRoute } from "@angular/router";
- import { FormInvestmentProposalService } from "@app/services/form-investment-proposal.service";
- import { CatalogsService } from "@app/services/catalogs.service";
- import { IAngularMyDpOptions, IMyDateModel } from "angular-mydatepicker";
- import { InvestmentsService } from "@app/services/investments.service";
- import { DatePipe } from "@angular/common";
- import { parse } from "date-fns";
- import { IOption } from "ng-select";
- @Component({
- selector: "app-new-investment-proposal",
- templateUrl: "./general-info.component.html",
- styleUrls: ["./general-info.component.scss"]
- })
- export class InvestmentProposalGeneralInfoComponent
- implements OnInit, OnChanges {
- general: GeneralInfo;
- complement: ComplementInfo;
- instrument: {};
- form: any;
- investmentProposalID: any = undefined;
- // For daterange
- daysLabels: any = {
- su: "Dom",
- mo: "Lun",
- tu: "Mar",
- we: "Mie",
- th: "Jue",
- fr: "Vie",
- sa: "Sab"
- };
- monthsLabels: any = {
- 1: "Ene",
- 2: "Feb",
- 3: "Mar",
- 4: "Abr",
- 5: "May",
- 6: "Jun",
- 7: "Jul",
- 8: "Ago",
- 9: "Sep",
- 10: "Oct",
- 11: "Nov",
- 12: "Dic"
- };
- investmentProposalForm: FormGroup;
- myDpOptions: IAngularMyDpOptions = {
- dateRange: false,
- dateFormat: "dd/mm/yyyy",
- dayLabels: this.daysLabels,
- monthLabels: this.monthsLabels
- };
- myDateInit: boolean = true;
- model: IMyDateModel = null;
- title: string = "Formulario propuesta de inversión";
- submitted: boolean = false;
- role_number: any;
- periodicities: any;
- rates: any;
- revenues: any;
- funds: any;
- instrumentTypes: Array<IOption>;
- generalInfoDontExists: boolean;
- plazos: any;
- base_types: any;
- financials: Array<IOption>;
- format_incomes: any;
- gInfo: any;
- gInstrument: any;
- gComplement: any;
- datez: any;
- instrumentName: any;
- instrumentValue: any;
- myOptions: Array<IOption> = [
- { label: "Belgium", value: "BE" },
- { label: "Luxembourg", value: "LU" },
- { label: "Netherlands", value: "NL" }
- ];
- @ViewChild("instrumentType", { static: false })
- public instrumentType: any;
- @ViewChild("casaSelect", { static: false })
- public casaSelect: any;
- constructor(
- private formBuilder: FormBuilder,
- private router: Router,
- private route: ActivatedRoute,
- private formDataService: FormInvestmentProposalService,
- private catalogService: CatalogsService,
- private investmentsService: InvestmentsService,
- public datepipe: DatePipe
- ) {}
- ngOnInit() {
- Swal.close();
- this.route.params.subscribe(params => {
- this.investmentProposalID = params["id"];
- });
- if (this.investmentProposalID == undefined)
- this.investmentProposalID = this.route.snapshot.queryParamMap.get("id");
- if (this.investmentProposalID != undefined) {
- this.investmentsService
- .getProposalInvestment(this.investmentProposalID)
- .subscribe(
- res => {
- this.gInfo = {
- asunto: res["result"]["asunto"],
- origenes_fondo:
- res["result"]["id_origen_fondo"] == null
- ? ""
- : res["result"]["id_origen_fondo"]["id_origen_fondo"],
- name: res["result"]["nombre_inversion"],
- //date: "",
- tipo_tasa: res["result"]["id_tipo_tasa"] || "",
- tipo_renta:
- res["result"]["id_tipo_renta"] == null
- ? ""
- : res["result"]["id_tipo_renta"]["id_tipo_renta"],
- periodicidad:
- res["result"]["id_periodicidad"] == null
- ? ""
- : res["result"]["id_periodicidad"]["id_periodicidad"],
- instrumentos:
- res["result"]["id_inversion_instrumento"][
- "id_tipo_instrumento"
- ]["codigo"],
- base_anual:
- res["result"]["id_tipo_base"] == null
- ? ""
- : res["result"]["id_tipo_base"]["id_tipo_base"],
- casa:
- res["result"]["id_entidad"] == null
- ? ""
- : res["result"]["id_entidad"]["id_entidad_financiera"],
- formato_ingreso:
- res["result"]["id_formato_ingreso"] == null
- ? ""
- : res["result"]["id_formato_ingreso"]["id_formato_ingreso"]
- };
- this.gInstrument =
- res["result"]["id_inversion_instrumento"]["instrumento"];
- this.gInstrument["id_inversion_instrumento"] =
- res["result"]["id_inversion_instrumento"][
- "id_inversion_instrumento"
- ];
- this.gComplement = {
- tipo_mercado:
- res["result"]["id_tipo_mercado"] == null
- ? ""
- : res["result"]["id_tipo_mercado"]["id_tipo_mercado"],
- emisores:
- res["result"]["id_tipo_emisor"] == null
- ? ""
- : res["result"]["id_tipo_emisor"]["id_tipo_emisor"],
- empresa:
- res["result"]["id_empresa"] == null
- ? ""
- : res["result"]["id_empresa"]["id_empresa"],
- pais:
- res["result"]["id_pais"] == null
- ? ""
- : res["result"]["id_pais"]["id_pais"],
- plazo:
- res["result"]["id_plazo"] == null
- ? ""
- : res["result"]["id_plazo"]["id_plazo"],
- operaciones:
- res["result"]["id_tipo_operacion"] == null
- ? ""
- : res["result"]["id_tipo_operacion"]["id_tipo_operacion"],
- comentarios: res["result"]["comentario"],
- justificacion: res["result"]["justificacion"]
- };
- this.instrumentValue =
- res["result"]["id_inversion_instrumento"]["id_tipo_instrumento"][
- "nombre"
- ];
- // Setear objeto dinamico con valores obtenidos del endpoint
- this.general = this.formDataService.getGeneralInfo();
- // Validar que el objeto dinamico contenga valores, si no, setear con valores obtenidos del endpoint
- if (
- Object.values(this.general).every(x => x === null || x === "")
- ) {
- this.formDataService.setGeneralInfo(this.gInfo);
- this.general = this.formDataService.getGeneralInfo();
- this.generalInfoDontExists = this.general == undefined;
- this.investmentProposalForm.patchValue({
- asunto: this.gInfo.asunto,
- origenes_fondo: this.gInfo.origenes_fondo,
- name: this.gInfo.name,
- tipo_tasa: this.gInfo.tipo_tasa,
- tipo_renta: this.gInfo.tipo_renta,
- periodicidad: this.gInfo.periodicidad,
- instrumentos: this.gInfo.instrumentos,
- base_anual: this.gInfo.base_anual,
- casa: this.gInfo.casa.toString(),
- formato_ingreso: this.gInfo.formato_ingreso
- });
- if (this.gInfo.casa != "") {
- this.casaSelect.select(this.gInfo.casa.toString());
- }
- }
- this.instrument = this.formDataService.getWork();
- if (
- this.instrument == undefined ||
- Object.values(this.instrument).every(x => x === null || x === "")
- ) {
- this.formDataService.setWork(this.gInstrument);
- this.instrument = this.formDataService.getWork();
- }
- this.complement = this.formDataService.getComplementInfo();
- if (
- Object.values(this.complement).every(x => x === null || x === "")
- ) {
- this.formDataService.setComplementInfo(this.gComplement);
- }
- },
- err => {
- Swal.fire({
- icon: "error",
- title: "Error en el servidor",
- text: err.message
- });
- }
- );
- } else {
- }
- //this.datepipe.transform(new Date(), "yyyy-MM-dd");
- this.general = this.formDataService.getGeneralInfo();
- this.generalInfoDontExists = false;
- // Obtener catalogos
- this.catalogService.getPaymentTerms().subscribe(res => {
- this.plazos = res;
- });
- this.catalogService.getFinancialEntities().subscribe(res => {
- this.financials = [];
- for (let property in res) {
- this.financials.push({
- label: res[property]["nombre"],
- value: res[property]["id_entidad_financiera"].toString()
- });
- }
- });
- this.catalogService.getBaseTypes().subscribe(res => {
- this.base_types = res;
- });
- this.catalogService.getPeriodicities().subscribe(res => {
- this.periodicities = res;
- });
- this.catalogService.getRateTypes().subscribe(res => {
- this.rates = res;
- });
- this.catalogService.getRevenueTypes().subscribe(res => {
- this.revenues = res;
- });
- this.catalogService.getFundsOrigins().subscribe(res => {
- this.funds = res;
- });
- this.catalogService.getInstrumentTypes().subscribe(res => {
- res;
- this.instrumentTypes = [];
- for (let property in res) {
- this.instrumentTypes.push({
- label: res[property]["nombre"],
- value: res[property]["codigo"]
- });
- }
- if (this.generalInfoDontExists == false) {
- if (
- this.instrumentType != undefined &&
- (this.general.instrumentos != "" ||
- this.general.instrumentos != undefined)
- ) {
- this.instrumentType.select(this.general.instrumentos);
- }
- this.instrumentName = res.find(
- e => e.codigo == this.general.instrumentos
- );
- this.instrumentName =
- this.instrumentName != undefined ? this.instrumentName.nombre : "-";
- }
- });
- //getIncomeFormat
- this.catalogService.getIncomeFormat().subscribe(res => {
- this.format_incomes = res;
- });
- // Si el arreglo principal de objetos viene con todos sus elementos vacios, inicializo el formulario.
- //if (Object.values(this.general).every(x => x === null || x === "")) {
- this.callForm(this.generalInfoDontExists, this.general);
- }
- ngOnChanges() {}
- save(form: any): boolean {
- if (!form.valid) {
- return false;
- }
- this.formDataService.setGeneralInfo(this.investmentProposalForm.value);
- return true;
- }
- callForm(formExists: boolean, form: any) {
- this.investmentProposalForm = this.formBuilder.group({
- asunto: ["", Validators.required],
- origenes_fondo: ["", Validators.required],
- name: ["", Validators.required],
- //date: ["", Validators.required],
- tipo_tasa: ["", Validators.required],
- tipo_renta: ["", Validators.required],
- periodicidad: ["", Validators.required],
- base_anual: ["", Validators.required],
- casa: ["", Validators.required],
- instrumentos: ["", Validators.required],
- formato_ingreso: ["", Validators.required]
- });
- this.investmentProposalForm.setValue({
- asunto: form.asunto,
- origenes_fondo: form.origenes_fondo || "",
- name: form.name || "",
- //date: form.date.singleDate == undefined ? "" : form.date,
- tipo_tasa: form.tipo_tasa || "",
- tipo_renta: form.tipo_renta || "",
- periodicidad: form.periodicidad || "",
- instrumentos: form.instrumentos || "",
- base_anual: form.base_anual || "",
- casa: form.casa || "",
- formato_ingreso: form.formato_ingreso || ""
- });
- }
- goToNext(form: any) {
- this.submitted = true;
- if (this.save(form)) {
- // Navigate to the work page
- if (this.investmentProposalID != undefined) {
- this.router.navigate(["/investment-proposal/instrument-work"], {
- queryParams: { id: this.investmentProposalID },
- relativeTo: this.route
- });
- //this.router.navigateByUrl( `/investment-proposal/${this.investmentProposalID}/instrument-work/`);
- } else {
- this.router.navigate(["/investment-proposal/instrument-work"]);
- }
- }
- }
- get f() {
- return this.investmentProposalForm.controls;
- }
- pre_filled_fields(event: IOption) {
- const selectedInstrument = event.value;
- switch (selectedInstrument) {
- case "LETE":
- this.investmentProposalForm.patchValue({
- tipo_tasa: this.investmentProposalForm.value.tipo_tasa = 2,
- tipo_renta: this.investmentProposalForm.value.tipo_renta = 2,
- periodicidad: this.investmentProposalForm.value.periodicidad = 7,
- base_anual: 6
- });
- case "CETE":
- this.investmentProposalForm.patchValue({
- tipo_tasa: this.investmentProposalForm.value.tipo_tasa = 2,
- tipo_renta: this.investmentProposalForm.value.tipo_renta = 2,
- periodicidad: this.investmentProposalForm.value.periodicidad = 7,
- base_anual: 6
- });
- break;
- case "VCN":
- this.investmentProposalForm.patchValue({
- tipo_tasa: this.investmentProposalForm.value.tipo_tasa = 2,
- tipo_renta: this.investmentProposalForm.value.tipo_renta = 2
- });
- break;
- case "PBUR":
- this.investmentProposalForm.patchValue({
- tipo_tasa: this.investmentProposalForm.value.tipo_tasa = 2,
- tipo_renta: this.investmentProposalForm.value.tipo_renta = 2
- });
- break;
- case "DAP":
- this.investmentProposalForm.patchValue({
- tipo_tasa: this.investmentProposalForm.value.tipo_tasa = 2,
- tipo_renta: this.investmentProposalForm.value.tipo_renta = 2,
- base_anual: 8
- });
- break;
- case "BONO":
- this.investmentProposalForm.patchValue({
- tipo_tasa: this.investmentProposalForm.value.tipo_tasa = 2,
- tipo_renta: this.investmentProposalForm.value.tipo_renta = 2,
- base_anual: 7
- });
- break;
- case "EURB":
- this.investmentProposalForm.patchValue({
- tipo_tasa: this.investmentProposalForm.value.tipo_tasa = 2,
- tipo_renta: this.investmentProposalForm.value.tipo_renta = 2,
- base_anual: 6
- });
- break;
- case "CINV":
- this.investmentProposalForm.patchValue({
- tipo_tasa: this.investmentProposalForm.value.tipo_tasa = 2,
- tipo_renta: this.investmentProposalForm.value.tipo_renta = 2,
- base_anual: 7
- });
- break;
- case "TIT":
- this.investmentProposalForm.patchValue({
- tipo_tasa: this.investmentProposalForm.value.tipo_tasa = 2,
- tipo_renta: this.investmentProposalForm.value.tipo_renta = 2,
- base_anual: 7
- });
- break;
- case "FINV":
- this.investmentProposalForm.patchValue({
- tipo_tasa: this.investmentProposalForm.value.tipo_tasa = 2,
- tipo_renta: this.investmentProposalForm.value.tipo_renta = 2,
- base_anual: 7
- });
- break;
- case "OPC":
- this.investmentProposalForm.patchValue({
- tipo_tasa: this.investmentProposalForm.value.tipo_tasa = 3,
- tipo_renta: this.investmentProposalForm.value.tipo_renta = 3,
- base_anual: 7
- });
- break;
- case "FUTU":
- this.investmentProposalForm.patchValue({
- tipo_tasa: this.investmentProposalForm.value.tipo_tasa = 3,
- tipo_renta: this.investmentProposalForm.value.tipo_renta = 3,
- base_anual: 7
- });
- break;
- case "PEMP":
- this.investmentProposalForm.patchValue({
- tipo_tasa: this.investmentProposalForm.value.tipo_tasa = 2,
- tipo_renta: this.investmentProposalForm.value.tipo_renta = 2,
- base_anual: 7
- });
- break;
- case "PPER":
- this.investmentProposalForm.patchValue({
- tipo_tasa: this.investmentProposalForm.value.tipo_tasa = 2,
- tipo_renta: this.investmentProposalForm.value.tipo_renta = 2,
- base_anual: 7
- });
- break;
- }
- }
- }
|