| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400 |
- import { Component, ViewChild, OnInit } from "@angular/core";
- import { MatPaginator } from "@angular/material/paginator";
- import { MatSort } from "@angular/material/sort";
- import { MatTableDataSource } from "@angular/material/table";
- import Swal from "sweetalert2";
- import { CatalogsService } from "src/app/services/catalogs.service";
- import { IncomesService } from "@app/services/incomes.service";
- import { AuthService } from "@app/services/auth2.service";
- import { JwtHelperService } from "@auth0/angular-jwt";
- import { InvestmentProposal } from "@app/models/investment-proposal";
- import { from } from "rxjs";
- import { FormInvestmentProposalService } from "@app/services/form-investment-proposal.service";
- import { Router, ActivatedRoute } from "@angular/router";
- import {
- FormBuilder,
- FormGroup,
- FormControl,
- FormArray,
- Validators
- } from "@angular/forms";
- import { IAngularMyDpOptions } from "angular-mydatepicker";
- @Component({
- selector: "app-general-form-income",
- templateUrl: "./general-form.component.html",
- styleUrls: ["./general-form.component.scss"]
- })
- export class GeneralIncomeFormComponent implements OnInit {
- helper = new JwtHelperService();
- title: string = "Ingresos para depósito a plazo";
- displayedColumns: string[] = [
- "fecha_proyeccion_ingreso",
- "fecha_ingreso",
- "fecha_conciliacion",
- "capital",
- "ingreso_bruto",
- "renta"
- ];
- //displayedColumns: string[] = ['state'];
- // 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"
- };
- myDpOptions: IAngularMyDpOptions = {
- dateRange: false,
- dateFormat: "dd/mm/yyyy",
- dayLabels: this.daysLabels,
- monthLabels: this.monthsLabels
- };
- myDateInit: boolean = true;
- listProposals: InvestmentProposal[];
- dataSource = new MatTableDataSource(this.listProposals);
- resultsLength = 0;
- isLoadingResults = true;
- isRateLimitReached = false;
- userRole: any;
- @ViewChild(MatPaginator, { static: true }) paginator: MatPaginator;
- @ViewChild(MatSort, { static: true }) sort: MatSort;
- role_number: any;
- projectionID: string;
- form: FormArray;
- investmentProposalForm: FormGroup;
- proyecciones: any;
- proyeccionesProps = [];
- dataRetrieved: boolean = false;
- array1;
- array2;
- array3;
- investment: any;
- projection: any;
- projection_exists: boolean;
- instrumentCode: any;
- payment_types: any;
- funds: any;
- banks: any;
- accounts: any;
- payment_date: string = "";
- submitted: boolean;
- incomeObject: any;
- incomes: any;
- incomes_exists: boolean;
- idInversion: any;
- idInstrumentIncome: any;
- projectionDate: any;
- projectionRes: any;
- partial: boolean;
- idProjection: any;
- cantConciliate: boolean = true;
- conciliateObject: any;
- has_conciliate: boolean;
- showIncomeForm: boolean = false;
- constructor(
- private catalogService: CatalogsService,
- private incomesService: IncomesService,
- private authService: AuthService,
- private formInvestmentProposal: FormInvestmentProposalService,
- private router: Router,
- private route: ActivatedRoute,
- private formBuilder: FormBuilder
- ) {
- const decodedToken = this.helper.decodeToken(
- this.authService.getJwtToken()
- );
- this.userRole = decodedToken.groups;
- Swal.fire({
- allowOutsideClick: false,
- icon: "info",
- text: "Espere por favor..."
- });
- Swal.showLoading();
- }
- nameBankAccounts(id: string) {
- let bank;
- bank = this.banks.find(e => e.id_banco == id);
- return bank.nombre;
- }
- ngOnInit() {
- this.partial = false;
- const formDataObj = {};
- this.route.queryParams.subscribe(params => {
- // ALT
- this.idInversion = params["id_inversion"];
- this.idInstrumentIncome = params["id_proyeccion_ingreso_instrumento"];
- this.projectionDate = params["fecha_proyeccion_pago"];
- this.idProjection = params["id_proyeccion_ingreso"];
- });
- this.incomesService
- .getProjection(
- this.idInversion,
- this.idInstrumentIncome,
- this.projectionDate,
- this.idProjection
- )
- .subscribe(
- res => {
- this.projection_exists = true;
- this.projectionRes = res["result"][0];
- if (this.projectionRes.estado == "CONCILIADO") {
- this.has_conciliate = true;
- }
- if (this.projectionRes.estado == "NO CONCILIADO") {
- this.cantConciliate = false;
- }
- if (this.projectionRes.estado == "EN ESPERA") {
- // Estado
- this.showIncomeForm = true;
- }
- this.investmentProposalForm.setValue({
- capital: this.projectionRes.capital,
- ingreso_bruto: this.projectionRes.ingreso_bruto,
- renta: this.projectionRes.renta,
- ingreso_neto: this.projectionRes.ingreso_neto,
- tipo_pago: "",
- cuenta_bancaria: "",
- comentario: "",
- fecha_inicio: "",
- fecha_vencimiento: ""
- });
- Swal.close();
- },
- err => {
- Swal.fire({
- icon: "error",
- title: "Error en el servidor",
- text: err.message
- });
- }
- );
- this.catalogService.getPaymentTypes().subscribe(res => {
- this.payment_types = res;
- });
- this.catalogService.getCountries().subscribe(res => {
- this.funds = res;
- });
- this.catalogService.getCatalogInfo("bancos").subscribe(res => {
- this.banks = res;
- this.catalogService.getCatalogInfo("cuentas-bancarias").subscribe(res => {
- this.accounts = res;
- });
- //this.payment_types = res;
- });
- this.investmentProposalForm = this.formBuilder.group({
- capital: [
- "",
- [
- Validators.required,
- //Validators.pattern(/^[+]?([0-9]+(?:[\.][0-9]*)?|\.[0-9]+)$/)
- Validators.pattern("^[0-9,.]+$")
- ]
- ],
- ingreso_bruto: [
- "",
- [
- Validators.required,
- //Validators.pattern(/^[+]?([0-9]+(?:[\.][0-9]*)?|\.[0-9]+)$/)
- Validators.pattern("^[0-9,.]+$")
- ]
- ],
- renta: [
- "",
- [
- Validators.required,
- //Validators.pattern(/^[+]?([0-9]+(?:[\.][0-9]*)?|\.[0-9]+)$/)
- Validators.pattern("^[0-9,.]+$")
- ]
- ],
- ingreso_neto: [
- "",
- [
- Validators.required,
- //Validators.pattern(/^[+]?([0-9]+(?:[\.][0-9]*)?|\.[0-9]+)$/)
- Validators.pattern("^[0-9,.]+$")
- ]
- ],
- tipo_pago: ["", Validators.required],
- cuenta_bancaria: ["", Validators.required],
- //fecha_ingreso: ["", Validators.required],
- comentario: ["", Validators.required],
- fecha_inicio: [""],
- fecha_vencimiento: [""]
- });
- }
- get f() {
- return this.investmentProposalForm.controls;
- }
- toggle = () => {
- if (this.partial == false) {
- this.partial = true;
- } else {
- this.partial = false;
- }
- };
- submitIncome(form: any) {
- this.submitted = true;
- let inversionCapital = this.clearValor(form.value.capital,"decimal")
- let inversionBruto = this.clearValor(form.value.ingreso_bruto,"decimal")
- let inversionNeto = this.clearValor(form.value.ingreso_neto,"decimal")
- console.log(form);
- console.log(form.value.ingreso_bruto)
- console.log(inversionBruto)
- if (!form.valid) {
- return false;
- }
- this.incomeObject = {
- id_inversion_instrumento: this.projectionRes.id_inversion_instrumento,
- id_proyeccion_ingreso_instrumento: this.idInstrumentIncome,
- fecha_proyeccion_pago: this.projectionDate,
- capital: inversionCapital,
- ingreso_bruto: inversionBruto,
- renta: form.value.renta,
- ingreso_neto: inversionNeto,
- id_cuenta_bancaria: form.value.cuenta_bancaria,
- id_tipo_pago: form.value.tipo_pago,
- comentario: form.value.comentario
- };
- if (this.idProjection != undefined) {
- this.incomeObject["id_proyeccion_ingreso"] = this.idProjection;
- }
- if (this.partial == true) {
- this.incomeObject["fecha_inicio"] =
- form.value.fecha_inicio.singleDate.formatted;
- this.incomeObject["fecha_vencimiento"] =
- form.value.fecha_vencimiento.singleDate.formatted;
- }
- Swal.fire({
- allowOutsideClick: false,
- icon: "info",
- text: "Espere por favor..."
- });
- Swal.showLoading();
- this.incomesService.createIncome(this.incomeObject).subscribe(
- success => {
- if (success) {
- Swal.fire({
- allowOutsideClick: false,
- icon: "success",
- showCancelButton: false,
- title: "Exito",
- confirmButtonText: "El ingreso ha sido guardado"
- }).then(result => {
- Swal.close();
- this.cantConciliate = false;
- });
- }
- },
- err => {
- Swal.fire({
- icon: "error",
- title: "Error al guardar",
- text: err.message
- });
- }
- );
- }
-
- clearValor(value,tipoDato){
- value = parseFloat(value.toString().replace(",",""))
- return value;
- }
- public inputValidator(event: any) {
- //console.log(event.target.value);
- const pattern = /^[0-9]*$/;
- //let inputChar = String.fromCharCode(event.charCode)
-
- if (!pattern.test(event.target.value)) {
- event.target.value = event.target.value.replace(/[^\d,.]+/g, '');
- // invalid character, prevent input
- }
-
- }
- conciliateIncome() {
- this.conciliateObject = {
- id_inversion_instrumento: this.projectionRes.id_inversion_instrumento,
- id_proyeccion_ingreso_instrumento: this.idInstrumentIncome,
- fecha_proyeccion_pago: this.projectionDate
- };
- if (this.idProjection != undefined) {
- this.conciliateObject["id_proyeccion_ingreso"] = this.idProjection;
- }
- this.incomesService.conciliateIncome(this.conciliateObject).subscribe(
- success => {
- if (success) {
- Swal.fire({
- allowOutsideClick: false,
- icon: "success",
- showCancelButton: false,
- title: "Exito",
- confirmButtonText: "El ingreso ha sido conciliado"
- }).then(result => {
- Swal.close();
- window.location.href = "#/investment-incomes";
- });
- }
- },
- err => {
- Swal.fire({
- icon: "error",
- title: "Error al guardar",
- text: err.message
- });
- }
- );
- }
- }
|