| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422 |
- import { Component, OnInit, Input, ViewChild } from "@angular/core";
- import { InstrumentComponent } from "@app/components/investment-proposals/instrument/instrument.component";
- import { FormBuilder, FormGroup, Validators } from "@angular/forms";
- import { IAngularMyDpOptions, IMyDateModel } from "angular-mydatepicker";
- import { formatDate, DatePipe } from "@angular/common";
- import { Router } from "@angular/router";
- import { FormInvestmentProposalService } from "@app/services/form-investment-proposal.service";
- import { CatalogsService } from "@app/services/catalogs.service";
- import { InstrumentCalculations } from "@app/services/instrument-calculations.service";
- import Swal from "sweetalert2";
- import { GeneralInfo } from "@app/models/investment-proposal-form";
- import { parse } from "date-fns";
- import { MatTableDataSource, MatPaginator, MatSort } from "@angular/material";
- @Component({
- selector: "app-vcn",
- templateUrl: "./vcn.component.html"
- })
- export class VCN implements InstrumentComponent {
- title: string = "Valores comerciales negociables";
- @Input() data: any;
- @Input() summary: boolean;
- @Input() investmentID: string;
- form: any;
- general: GeneralInfo;
- displayedColumns: string[] = [
- "posicion",
- "plazo",
- "fecha_pago",
- "ingreso_bruto",
- "ingreso_neto",
- "costo_cedeval",
- "renta",
- "costo_transferencia",
- "costo_banco",
- "otros_costos"
- ];
- // 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"
- };
- instrument_null: boolean;
- instrument_work: any = [];
- investmentProposalForm: FormGroup;
- myDpOptions: IAngularMyDpOptions = {
- dateRange: false,
- dateFormat: "dd/mm/yyyy",
- dayLabels: this.daysLabels,
- monthLabels: this.monthsLabels
- };
- submitted: boolean;
- myDateInit: boolean = true;
- model: IMyDateModel = null;
- vcnObject: {};
- format_incomes: any;
- ingreso_bruto: number = 0.0;
- ingreso_neto: number = 0.0;
- valor_transado: number = 0.0;
- precio_porcentaje: number = 0.0;
- rendimiento_neto: number = 0.0;
- total_pagar: number = 0.0;
- comision_bolsa: number = 0.0;
- comision_casa: number = 0.0;
- plazo: number = 0;
- interes_acumulado: number = 0;
- fecha_inicio_vigencia: string;
- proyecciones: any;
- hasProjections: boolean;
- @ViewChild(MatPaginator, { static: true }) paginator: MatPaginator;
- @ViewChild(MatSort, { static: true }) sort: MatSort;
- dataSource = new MatTableDataSource(this.proyecciones);
- dataSource2 = new MatTableDataSource(this.proyecciones);
- consolidado_proyeccion = {
- total_ingreso_bruto: 0,
- total_ingreso_neto: 0,
- total_costo_cedeval: 0,
- total_renta: 0,
- total_costo_transferencia: 0,
- total_costo_banco: 0,
- total_otros_costos: 0
- };
- constructor(
- private formBuilder: FormBuilder,
- private router: Router,
- private formDataService: FormInvestmentProposalService,
- private catalogService: CatalogsService,
- private instrumentCalcService: InstrumentCalculations,
- public datepipe: DatePipe
- ) {
- this.instrument_work = this.formDataService.getWork();
- this.instrument_null = this.instrument_work == undefined;
- this.general = this.formDataService.getGeneralInfo();
- if (
- this.instrument_work != undefined &&
- this.instrument_work.valor_par == true &&
- this.instrument_work.proyecciones != undefined
- ) {
- this.hasProjections = true;
- this.dataSource2.data = this.instrument_work.proyecciones;
- this.dataSource2.paginator = this.paginator;
- this.dataSource2.sort = this.sort;
- this.consolidado_proyeccion = this.instrument_work.proyecciones.slice(
- 0,
- -1
- );
- } else {
- this.hasProjections = false;
- }
- //getIncomeFormat
- this.catalogService.getIncomeFormat().subscribe(res => {
- this.format_incomes = res;
- });
- this.investmentProposalForm = this.formBuilder.group({
- valor_par: [
- this.instrument_null || this.instrument_work.valor_par == null
- ? false
- : this.instrument_work.valor_par
- ],
- valor_nominal: [
- this.instrument_null ? "" : this.instrument_work.valor_nominal,
- [
- Validators.required,
- Validators.pattern(/^[+]?([0-9]+(?:[\.][0-9]*)?|\.[0-9]+)$/)
- ]
- ],
- otros_costos: [
- this.instrument_null || this.instrument_work.otros_costos == null
- ? 0
- : this.instrument_work.otros_costos,
- [Validators.pattern(/^[+]?([0-9]+(?:[\.][0-9]*)?|\.[0-9]+)$/)]
- ],
- renta_porcentaje: [
- this.instrument_null || this.instrument_work.renta_porcentaje == null
- ? 10
- : this.instrument_work.renta_porcentaje,
- [Validators.required]
- ],
- comision_casa_porcentaje: [
- this.instrument_null
- ? ""
- : this.instrument_work.comision_casa_porcentaje,
- [
- Validators.required,
- Validators.pattern(/^[+]?([0-9]+(?:[\.][0-9]*)?|\.[0-9]+)$/)
- ]
- ],
- comision_bolsa_porcentaje: [
- this.instrument_null
- ? ""
- : this.instrument_work.comision_bolsa_porcentaje,
- [
- Validators.required,
- Validators.pattern(/^[+]?([0-9]+(?:[\.][0-9]*)?|\.[0-9]+)$/)
- ]
- ],
- rendimiento_bruto: [
- this.instrument_null ? "" : this.instrument_work.rendimiento_bruto,
- [
- Validators.required,
- Validators.pattern(/^[+]?([0-9]+(?:[\.][0-9]*)?|\.[0-9]+)$/)
- ]
- ],
- /*formato_ingreso: [
- this.instrument_null ? "" : this.instrument_work.formato_ingreso,
- [Validators.required]
- ],*/
- fecha_liquidacion: [
- this.instrument_null
- ? ""
- : {
- isRange: false,
- singleDate: {
- jsDate: parse(
- this.instrument_work.fecha_liquidacion,
- "dd/MM/yyyy",
- new Date()
- ),
- formatted: this.instrument_work.fecha_liquidacion
- }
- },
- Validators.required
- ],
- fecha_vencimiento: [
- this.instrument_null
- ? ""
- : {
- isRange: false,
- singleDate: {
- jsDate: parse(
- this.instrument_work.fecha_vencimiento,
- "dd/MM/yyyy",
- new Date()
- ),
- formatted: this.instrument_work.fecha_vencimiento
- }
- },
- Validators.required
- ],
- fecha_operacion: [
- this.instrument_null
- ? ""
- : {
- isRange: false,
- singleDate: {
- jsDate: parse(
- this.instrument_work.fecha_operacion,
- "dd/MM/yyyy",
- new Date()
- ),
- formatted: this.instrument_work.fecha_operacion
- }
- },
- Validators.required
- ],
- fecha_ultima_cupon: [
- this.instrument_null
- ? ""
- : {
- isRange: false,
- singleDate: {
- jsDate: parse(
- this.instrument_work.fecha_ultima_cupon,
- "dd/MM/yyyy",
- new Date()
- ),
- formatted: this.instrument_work.fecha_ultima_cupon
- }
- },
- Validators.required
- ]
- });
- }
- get f() {
- return this.investmentProposalForm.controls;
- }
- save(form: any): boolean {
- if (!form.valid) {
- return false;
- }
- this.formDataService.setWork(this.vcnObject);
- return true;
- }
- getCalculations(form: any, saveForm: boolean) {
- this.submitted = true;
- if (!form.valid) {
- return false;
- }
- Swal.fire({
- allowOutsideClick: false,
- icon: "info",
- text: "Espere por favor..."
- });
- Swal.showLoading();
- this.instrumentCalcService
- .vcnCalc(
- "VCN", // Codigo del instrumento
- {
- id_tipo_base: +this.general.base_anual,
- id_periodicidad: +this.general.periodicidad,
- id_formato_ingreso: +this.general.formato_ingreso
- },
- {
- valor_par: this.f.valor_par.value,
- valor_nominal: +this.f.valor_nominal.value,
- comision_casa_porcentaje: this.f.comision_casa_porcentaje.value,
- comision_bolsa_porcentaje: this.f.comision_bolsa_porcentaje.value,
- rendimiento_bruto: this.f.rendimiento_bruto.value,
- otros_costos: this.f.otros_costos.value,
- renta_porcentaje: this.f.renta_porcentaje.value,
- //id_formato_ingreso: this.f.formato_ingreso.value,
- fecha_operacion: this.f.fecha_operacion.value.singleDate.formatted,
- fecha_liquidacion: this.f.fecha_liquidacion.value.singleDate
- .formatted,
- fecha_ultima_cupon: this.f.fecha_ultima_cupon.value.singleDate
- .formatted,
- fecha_vencimiento: this.f.fecha_vencimiento.value.singleDate.formatted
- }
- )
- .subscribe(
- ans => {
- this.ingreso_bruto = ans["result"]["ingreso_bruto"];
- this.ingreso_neto = ans["result"]["ingreso_neto"];
- this.valor_transado = ans["result"]["valor_transado"];
- this.precio_porcentaje = ans["result"]["precio_porcentaje"];
- this.rendimiento_neto = ans["result"]["rendimiento_neto"];
- this.total_pagar = ans["result"]["total_pagar"];
- this.comision_bolsa = ans["result"]["comision_bolsa"];
- this.comision_casa = ans["result"]["comision_casa"];
- this.plazo = ans["result"]["plazo"];
- this.interes_acumulado = ans["result"]["interes_acumulado"];
- this.fecha_inicio_vigencia = ans["result"]["fecha_inicio_vigencia"];
- this.proyecciones = ans["result"]["proyecciones"];
- if (this.proyecciones != undefined && this.proyecciones.length > 0) {
- this.consolidado_proyeccion = this.proyecciones.slice(0, -1);
- this.proyecciones = ans["result"]["proyecciones"];
- }
- if (this.f.valor_par.value == true) {
- this.hasProjections = true;
- } else {
- this.hasProjections = false;
- }
- this.dataSource.data = this.proyecciones;
- this.dataSource.paginator = this.paginator;
- this.dataSource.sort = this.sort;
- this.vcnObject = {
- valor_par: this.investmentProposalForm.value.valor_par,
- valor_nominal: this.investmentProposalForm.value.valor_nominal,
- renta_porcentaje: this.investmentProposalForm.value
- .renta_porcentaje,
- comision_casa_porcentaje: this.investmentProposalForm.value
- .comision_casa_porcentaje,
- comision_bolsa_porcentaje: this.investmentProposalForm.value
- .comision_bolsa_porcentaje,
- comision_casa: this.comision_casa,
- comision_bolsa: this.comision_bolsa,
- rendimiento_bruto: this.investmentProposalForm.value
- .rendimiento_bruto,
- otros_costos: this.investmentProposalForm.value.otros_costos,
- ingreso_bruto: this.ingreso_bruto,
- ingreso_neto: this.ingreso_neto,
- valor_transado: this.valor_transado,
- precio_porcentaje: this.precio_porcentaje,
- rendimiento_neto: this.rendimiento_neto,
- total_pagar: this.total_pagar,
- interes_acumulado: this.interes_acumulado,
- fecha_inicio_vigencia: this.fecha_inicio_vigencia,
- proyecciones: this.proyecciones,
- plazo: this.plazo,
- //id_formato_ingreso: this.investmentProposalForm.value.id_formato_ingreso,
- fecha_operacion: this.investmentProposalForm.value.fecha_operacion
- .singleDate.formatted,
- fecha_liquidacion:
- this.investmentProposalForm.value.fecha_liquidacion.singleDate
- .formatted || "",
- fecha_ultima_cupon:
- this.investmentProposalForm.value.fecha_ultima_cupon != undefined
- ? this.investmentProposalForm.value.fecha_ultima_cupon
- .singleDate.formatted
- : "",
- fecha_vencimiento:
- this.investmentProposalForm.value.fecha_vencimiento != undefined
- ? this.investmentProposalForm.value.fecha_vencimiento.singleDate
- .formatted
- : ""
- };
- this.formDataService.setWork(this.vcnObject);
- Swal.close();
- if (saveForm == true) {
- if (this.investmentID != undefined) {
- this.router.navigate(["/investment-proposal/complement-info"], {
- queryParams: { id: this.investmentID }
- });
- } else {
- this.router.navigate(["/investment-proposal/complement-info"]);
- }
- }
- },
- err => {
- Swal.fire({
- icon: "error",
- title: "Error en el servidor",
- text: "No su pudo obtener la informacion"
- });
- return false;
- }
- );
- }
- goToPrevious() {
- this.submitted = true;
- if (this.investmentID != undefined) {
- this.router.navigate(["/investment-proposal/general-info"], {
- queryParams: { id: this.investmentID }
- });
- } else {
- this.router.navigate(["/investment-proposal/general-info"]);
- }
- }
- goToNext(form: any) {
- this.getCalculations(form, true);
- }
- }
|